blob: 9ebf5d67dd5dae620a23aa2869860f0c9522f082 [file] [log] [blame]
Aparna Mallavarapu7800c8c2013-06-28 07:30:22 -07001/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
32#include <qgic.h>
33#include <qtimer.h>
Aparna Mallavarapucb9ee4d2013-11-21 21:18:53 +053034#include <mmu.h>
35#include <arch/arm/mmu.h>
36#include <smem.h>
37#include <board.h>
38
39#define MB (1024*1024)
40
41#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
42/* LK memory - cacheable, write through */
43#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
44 MMU_MEMORY_AP_READ_WRITE)
45
46/* Peripherals - non-shared device */
47#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
48 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
49
50/* IMEM memory - cacheable, write through */
51#define IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
52 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
53
54/* Kernel region - cacheable, write through */
55#define KERNEL_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
56 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
57
58/* Scratch region - cacheable, write through */
59#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
60 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
61
62static mmu_section_t mmu_section_table[] = {
63 /* Physical addr, Virtual addr, Size (in MB), Flags */
64 {MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
65 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
66 {BASE_ADDR, BASE_ADDR, 44, KERNEL_MEMORY},
67 {SCRATCH_ADDR, SCRATCH_ADDR, 512, SCRATCH_MEMORY},
68 /* IMEM needs a seperate entry in the table as it's length is only 0x8000. */
69 {SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY},
70};
Aparna Mallavarapu7800c8c2013-06-28 07:30:22 -070071
72void platform_early_init(void)
73{
Aparna Mallavarapucb9ee4d2013-11-21 21:18:53 +053074 board_init();
Aparna Mallavarapu6dcdd2f2013-11-02 14:44:44 +053075 platform_clock_init();
Aparna Mallavarapu7800c8c2013-06-28 07:30:22 -070076 qgic_init();
77 qtimer_init();
78}
79
80void platform_init(void)
81{
82 dprintf(INFO, "platform_init()\n");
83}
84
85void platform_uninit(void)
86{
87 qtimer_uninit();
88}
Aparna Mallavarapucb9ee4d2013-11-21 21:18:53 +053089
90int platform_use_identity_mmu_mappings(void)
91{
92 /* Use only the mappings specified in this file. */
93 return 0;
94}
95
96/* Setup memory for this platform */
97void platform_init_mmu_mappings(void)
98{
99 uint32_t i;
100 uint32_t sections;
101 ram_partition ptn_entry;
102 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
103 uint32_t len = 0;
104
105 ASSERT(smem_ram_ptable_init_v1());
106
107 len = smem_get_ram_ptable_len();
108
109 /* Configure the MMU page entries for SDRAM and IMEM memory read
110 from the smem ram table*/
111 for(i = 0; i < len; i++)
112 {
113 smem_get_ram_ptable_entry(&ptn_entry, i);
114 if(ptn_entry.type == SYS_MEMORY)
115 {
116 if((ptn_entry.category == SDRAM) ||
117 (ptn_entry.category == IMEM))
118 {
119 /* Check to ensure that start address is 1MB aligned */
120 ASSERT((ptn_entry.start & (MB-1)) == 0);
121
122 sections = (ptn_entry.size) / MB;
123 while(sections--)
124 {
125 arm_mmu_map_section(ptn_entry.start +
126 sections * MB,
127 ptn_entry.start + sections * MB,
128 (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
129 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
130 }
131 }
132 }
133 }
134
135 /* Configure the MMU page entries for memory read from the
136 mmu_section_table */
137 for (i = 0; i < table_size; i++)
138 {
139 sections = mmu_section_table[i].num_of_sections;
140 while (sections--)
141 {
142 arm_mmu_map_section(mmu_section_table[i].paddress +
143 sections * MB,
144 mmu_section_table[i].vaddress +
145 sections * MB,
146 mmu_section_table[i].flags);
147 }
148 }
149}
150
151addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
152{
153 /* Using 1-1 mapping on this platform. */
154 return virt_addr;
155}
156
157addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
158{
159 /* Using 1-1 mapping on this platform. */
160 return phys_addr;
161}