blob: dc903b02f29a12f5fbe3eb6bafbf32b456acea2e [file] [log] [blame]
Deepa Dinamani7e15e0b2013-02-07 13:05:38 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Amol Jadi42d7b5a2012-05-04 14:50:32 -07002 *
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.
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070012 * * Neither the name of The Linux Foundation nor the names of its
Amol Jadi42d7b5a2012-05-04 14:50:32 -070013 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
Amol Jadib726c3b2012-09-13 13:51:23 -070016 * 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.
Amol Jadi42d7b5a2012-05-04 14:50:32 -070027 */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070028
Amol Jadi42d7b5a2012-05-04 14:50:32 -070029#include <debug.h>
30#include <platform.h>
31#include <qgic.h>
32#include <qtimer.h>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070033#include <board.h>
Deepa Dinamani87feab82012-10-04 14:28:05 -070034#include <qpic_nand.h>
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -070035#include <mmu.h>
36#include <arch/arm/mmu.h>
37#include <platform/iomap.h>
38#include <target.h>
39#include <smem.h>
40#include <reg.h>
41
42extern struct smem_ram_ptable* target_smem_ram_ptable_init();
43
44#define MB (1024*1024)
45
46#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
47
48/* LK memory - Strongly ordered, executable */
Deepa Dinamani7e15e0b2013-02-07 13:05:38 -080049#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL | \
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -070050 MMU_MEMORY_AP_READ_WRITE)
51/* Scratch memory - Strongly ordered, non-executable */
Deepa Dinamani7e15e0b2013-02-07 13:05:38 -080052#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL | \
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -070053 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
54/* Peripherals - shared device */
55#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
56 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
57
58#define SCRATCH_REGION1_VIRT_START (MEMBASE + MEMSIZE)
59#define SCRATCH_REGION2_VIRT_START (SCRATCH_REGION1_VIRT_START + \
60 (SCRATCH_REGION1_SIZE))
61
62#define SDRAM_BANK0_LAST_FIXED_ADDR (SCRATCH_REGION2 + SCRATCH_REGION2_SIZE)
63
64/* Map all the accesssible memory according to the following rules:
65 * 1. Map 1MB from MSM_SHARED_BASE with 1 -1 mapping.
66 * 2. Map MEMBASE - MEMSIZE with 1 -1 mapping.
67 * 3. Map all the scratch regions immediately after Appsbl memory.
68 * Virtual addresses start right after Appsbl Virtual address.
69 * 4. Map all the IOMAP space with 1 - 1 mapping.
70 * 5. Map all the rest of the SDRAM/ IMEM regions as 1 -1.
71 */
72mmu_section_t mmu_section_table[] = {
73/* Physical addr, Virtual addr, Size (in MB), Flags */
74 {MSM_SHARED_BASE, MSM_SHARED_BASE, 1, SCRATCH_MEMORY},
75 {MEMBASE, MEMBASE, MEMSIZE / MB, LK_MEMORY},
76 {SCRATCH_REGION1, SCRATCH_REGION1_VIRT_START, SCRATCH_REGION1_SIZE / MB, SCRATCH_MEMORY},
77 {SCRATCH_REGION2, SCRATCH_REGION2_VIRT_START, SCRATCH_REGION2_SIZE / MB, SCRATCH_MEMORY},
78 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
79};
Amol Jadi42d7b5a2012-05-04 14:50:32 -070080
81void platform_early_init(void)
82{
83 /* Initialize board identifier data */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070084 board_init();
Amol Jadi42d7b5a2012-05-04 14:50:32 -070085
Amol Jadib726c3b2012-09-13 13:51:23 -070086 /* Initialize clock driver */
87 platform_clock_init();
88
Amol Jadi42d7b5a2012-05-04 14:50:32 -070089 /* Initialize interrupt controller */
90 qgic_init();
91
92 /* timer */
93 qtimer_init();
94}
95
96void platform_init(void)
97{
98 dprintf(INFO, "platform_init()\n");
99}
100
101void platform_uninit(void)
102{
103 qtimer_uninit();
Deepa Dinamani87feab82012-10-04 14:28:05 -0700104 qpic_nand_uninit();
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700105}
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -0700106
107void platform_init_mmu_mappings(void)
108{
109 struct smem_ram_ptable *ram_ptable;
110 uint32_t i;
111 uint32_t sections;
112 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
113 uint32_t last_fixed_addr = SDRAM_BANK0_LAST_FIXED_ADDR;
114
115 ram_ptable = target_smem_ram_ptable_init();
116
117 /* Configure the MMU page entries for SDRAM and IMEM memory read
118 from the smem ram table*/
119 for(i = 0; i < ram_ptable->len; i++)
120 {
121 if((ram_ptable->parts[i].category == IMEM) || (ram_ptable->parts[i].category == SDRAM))
122 {
123 /* First bank info is added according to the static table - mmu_section_table. */
124 if((ram_ptable->parts[i].start <= last_fixed_addr) &&
125 ((ram_ptable->parts[i].start + ram_ptable->parts[i].size) >= last_fixed_addr))
126 continue;
127
128 /* Check to ensure that start address is 1MB aligned */
129 ASSERT((ram_ptable->parts[i].start & 0xFFFFF) == 0);
130
131 sections = (ram_ptable->parts[i].size) / MB;
132
133 while(sections--)
134 {
135 arm_mmu_map_section(ram_ptable->parts[i].start + sections * MB,
136 ram_ptable->parts[i].start + sections * MB,
137 SCRATCH_MEMORY);
138 }
139 }
140 }
141
142 /* Configure the MMU page entries for memory read from the
143 mmu_section_table */
144 for (i = 0; i < table_size; i++)
145 {
146 sections = mmu_section_table[i].num_of_sections;
147
148 while (sections--)
149 {
150 arm_mmu_map_section(mmu_section_table[i].paddress + sections * MB,
151 mmu_section_table[i].vaddress + sections * MB,
152 mmu_section_table[i].flags);
153 }
154 }
155}
156
157addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
158{
159 uint32_t paddr;
160 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
161 uint32_t limit;
162
163 for (uint32_t i = 0; i < table_size; i++)
164 {
165 limit = (mmu_section_table[i].num_of_sections * MB) - 0x1;
166
167 if (virt_addr >= mmu_section_table[i].vaddress &&
168 virt_addr <= (mmu_section_table[i].vaddress + limit))
169 {
170 paddr = mmu_section_table[i].paddress + (virt_addr - mmu_section_table[i].vaddress);
171 return paddr;
172 }
173 }
174 /* No special mapping found.
175 * Assume 1-1 mapping.
176 */
177 paddr = virt_addr;
178
179 return paddr;
180}
181
182addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
183{
184 uint32_t vaddr;
185 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
186 uint32_t limit;
187
188 for (uint32_t i = 0; i < table_size; i++)
189 {
190 limit = (mmu_section_table[i].num_of_sections * MB) - 0x1;
191
192 if (phys_addr >= mmu_section_table[i].paddress &&
193 phys_addr <= (mmu_section_table[i].paddress + limit))
194 {
195 vaddr = mmu_section_table[i].vaddress + (phys_addr - mmu_section_table[i].paddress);
196 return vaddr;
197 }
198 }
199
200 /* No special mapping found.
201 * Assume 1-1 mapping.
202 */
203 vaddr = phys_addr;
204
205 return vaddr;
206}
207
208/* Do not use default identitiy mappings. */
209int platform_use_identity_mmu_mappings(void)
210{
211 return 0;
212}
213