blob: 1be8698c9b33e1b50e6d630a6a1a3bf32d4bb452 [file] [log] [blame]
vijay kumarca1672a2015-04-09 16:45:40 +05301/* Copyright (c) 2015, 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 "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF 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>
34#include <mmu.h>
35#include <arch/arm/mmu.h>
36#include <smem.h>
37
vijay kumar689fc9e2015-08-24 15:37:38 +053038#define MB (1024 *1024)
39
40#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
41
42#define A7_SS_SIZE ((A7_SS_END - A7_SS_BASE)/MB)
43
44/* LK memory */
45#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
46 MMU_MEMORY_AP_READ_WRITE)
47/* Scratch memory - Strongly ordered, non-executable */
48#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
49 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
50/* Peripherals - shared device */
51#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
52 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
vijay kumar65143242015-11-17 17:43:35 +053053#define SCRATCH_REGION1_VIRT_START_128 0x88000000
54#define SCRATCH_REGION2_VIRT_START_128 (SCRATCH_REGION1_VIRT_START_128 + SCRATCH_REGION1_SIZE_128)
vijay kumar689fc9e2015-08-24 15:37:38 +053055
vijay kumar65143242015-11-17 17:43:35 +053056static void ddr_based_mmu_mappings(mmu_section_t *table, uint32_t table_size);
57static uint64_t ddr_size;
58static void board_ddr_detect();
vijay kumar689fc9e2015-08-24 15:37:38 +053059
60/* Map all the accesssible memory according to the following rules:
61 * 1. Map 1MB from MSM_SHARED_BASE with 1 -1 mapping.
62 * 2. Map MEMBASE - MEMSIZE with 1 -1 mapping.
63 * 3. Map all the scratch regions immediately after Appsbl memory.
64 * Virtual addresses start right after Appsbl Virtual address.
65 * 4. Map all the IOMAP space with 1 - 1 mapping.
66 * 5. Map all the rest of the SDRAM/ IMEM regions as 1 -1.
67 */
68mmu_section_t mmu_section_table[] = {
69/* Physical addr, Virtual addr, Size (in MB), Flags */
70 {MSM_SHARED_BASE, MSM_SHARED_BASE, 1, SCRATCH_MEMORY},
71 {MEMBASE, MEMBASE, MEMSIZE / MB, LK_MEMORY},
72 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
73 {A7_SS_BASE, A7_SS_BASE, A7_SS_SIZE, IOMAP_MEMORY},
74 {MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, IOMAP_MEMORY},
vijay kumar689fc9e2015-08-24 15:37:38 +053075};
76
vijay kumar65143242015-11-17 17:43:35 +053077mmu_section_t mmu_section_table_128[] = {
78 {SCRATCH_REGION1_128, SCRATCH_REGION1_VIRT_START_128, SCRATCH_REGION1_SIZE_128/ MB, SCRATCH_MEMORY},
79 {SCRATCH_REGION2_128, SCRATCH_REGION2_VIRT_START_128, SCRATCH_REGION2_SIZE_128/ MB, SCRATCH_MEMORY},
80};
81
82mmu_section_t mmu_section_table_256[] = {
83 {SCRATCH_REGION_256, SCRATCH_REGION_256, SCRATCH_REGION_SIZE_256/ MB, SCRATCH_MEMORY},
84 {KERNEL_REGION, KERNEL_REGION, KERNEL_REGION_SIZE/ MB, SCRATCH_MEMORY},
85};
86
87static void board_ddr_detect()
88{
89 ddr_size = smem_get_ddr_size();
90 /*128MB DDR*/
91 if(ddr_size == 0x8000000)
92 ddr_based_mmu_mappings(mmu_section_table_128, ARRAY_SIZE(mmu_section_table_128));
93 else
94 ddr_based_mmu_mappings(mmu_section_table_256, ARRAY_SIZE(mmu_section_table_256));
95}
96
vijay kumarca1672a2015-04-09 16:45:40 +053097void platform_early_init(void)
98{
vijay kumarec490942015-07-23 12:43:54 +053099 board_init();
100 platform_clock_init();
vijay kumarca1672a2015-04-09 16:45:40 +0530101 qgic_init();
102 qtimer_init();
vijay kumarec490942015-07-23 12:43:54 +0530103 scm_init();
vijay kumar65143242015-11-17 17:43:35 +0530104 board_ddr_detect();
vijay kumarca1672a2015-04-09 16:45:40 +0530105}
106
107void platform_init(void)
108{
109 dprintf(INFO, "platform_init()\n");
110}
111
112void platform_uninit(void)
113{
114 qtimer_uninit();
vijay kumarec490942015-07-23 12:43:54 +0530115 qpic_nand_uninit();
vijay kumarca1672a2015-04-09 16:45:40 +0530116}
117
118uint32_t platform_get_sclk_count(void)
119{
120 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
121}
122
123addr_t get_bs_info_addr()
124{
125 return ((addr_t)BS_INFO_ADDR);
126}
127
vijay kumar689fc9e2015-08-24 15:37:38 +0530128addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
129{
vijay kumar65143242015-11-17 17:43:35 +0530130 uint32_t paddr;
131 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
132 uint32_t limit;
133
134 for (uint32_t i = 0; i < table_size; i++)
135 {
136 limit = (mmu_section_table[i].num_of_sections * MB) - 0x1;
137
138 if (virt_addr >= mmu_section_table[i].vaddress &&
139 virt_addr <= (mmu_section_table[i].vaddress + limit))
140 {
141 paddr = mmu_section_table[i].paddress + (virt_addr - mmu_section_table[i].vaddress);
142 return paddr;
143 }
144 }
145 if(ddr_size == 0x8000000)
146 {
147 table_size = ARRAY_SIZE(mmu_section_table_128);
148 for (uint32_t i = 0; i < table_size; i++)
149 {
150 limit = (mmu_section_table_128[i].num_of_sections * MB) - 0x1;
151
152 if (virt_addr >= mmu_section_table_128[i].vaddress &&
153 virt_addr <= (mmu_section_table_128[i].vaddress + limit))
154 {
155 paddr = mmu_section_table_128[i].paddress + (virt_addr - mmu_section_table_128[i].vaddress);
156 return paddr;
157 }
158 }
159 }
160 else
161 {
162 /* Any DDR > 256MB would be mapped here & LK would use only first 256 MB */
163 table_size = ARRAY_SIZE(mmu_section_table_256);
164 for (uint32_t i = 0; i < table_size; i++)
165 {
166 limit = (mmu_section_table_256[i].num_of_sections * MB) - 0x1;
167
168 if (virt_addr >= mmu_section_table_256[i].vaddress &&
169 virt_addr <= (mmu_section_table_256[i].vaddress + limit))
170 {
171 paddr = mmu_section_table_256[i].paddress + (virt_addr - mmu_section_table_256[i].vaddress);
172 return paddr;
173 }
174 }
175 }
176 /* No special mapping found.
177 * Assume 1-1 mapping.
178 */
179 paddr = virt_addr;
180 return paddr;
181
vijay kumar689fc9e2015-08-24 15:37:38 +0530182}
183
184addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
185{
vijay kumar65143242015-11-17 17:43:35 +0530186 uint32_t vaddr;
187 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
188 uint32_t limit;
189
190 for (uint32_t i = 0; i < table_size; i++)
191 {
192 limit = (mmu_section_table[i].num_of_sections * MB) - 0x1;
193
194 if (phys_addr >= mmu_section_table[i].paddress &&
195 phys_addr <= (mmu_section_table[i].paddress + limit))
196 {
197 vaddr = mmu_section_table[i].vaddress + (phys_addr - mmu_section_table[i].paddress);
198 return vaddr;
199 }
200 }
201 if(ddr_size == 0x8000000)
202 {
203 table_size = ARRAY_SIZE(mmu_section_table_128);
204 for (uint32_t i = 0; i < table_size; i++)
205 {
206 limit = (mmu_section_table_128[i].num_of_sections * MB) - 0x1;
207
208 if (phys_addr >= mmu_section_table_128[i].paddress &&
209 phys_addr <= (mmu_section_table_128[i].paddress + limit))
210 {
211 vaddr = mmu_section_table_128[i].vaddress + (phys_addr - mmu_section_table_128[i].paddress);
212 return vaddr;
213 }
214 }
215 }
216 else
217 {
218 /* Any DDR > 256MB would be mapped here & LK would use only first 256 MB */
219 table_size = ARRAY_SIZE(mmu_section_table_256);
220 for (uint32_t i = 0; i < table_size; i++)
221 {
222 limit = (mmu_section_table_256[i].num_of_sections * MB) - 0x1;
223
224 if (phys_addr >= mmu_section_table_256[i].paddress &&
225 phys_addr <= (mmu_section_table_256[i].paddress + limit))
226 {
227 vaddr = mmu_section_table_256[i].vaddress + (phys_addr - mmu_section_table_256[i].paddress);
228 return vaddr;
229 }
230 }
231 }
232
233 /* No special mapping found.
234 * Assume 1-1 mapping.
235 */
236 vaddr = phys_addr;
237
238 return vaddr;
vijay kumar689fc9e2015-08-24 15:37:38 +0530239}
240
241/* Setup memory for this platform */
242void platform_init_mmu_mappings(void)
243{
244 uint32_t i;
245 uint32_t sections;
246 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
247
248 /* Configure the MMU page entries for memory read from the
249 mmu_section_table */
250 for (i = 0; i < table_size; i++)
251 {
252 sections = mmu_section_table[i].num_of_sections;
253
254 while (sections--)
255 {
256 arm_mmu_map_section(mmu_section_table[i].paddress +
257 sections * MB,
258 mmu_section_table[i].vaddress +
259 sections * MB,
260 mmu_section_table[i].flags);
261 }
262 }
263}
vijay kumar65143242015-11-17 17:43:35 +0530264
265/* Setup memory for this platform */
266static void ddr_based_mmu_mappings(mmu_section_t *table,uint32_t table_size)
267{
268 uint32_t i;
269 uint32_t sections;
270
271 /* Configure the MMU page entries for memory read from the
272 mmu_section_table */
273 for (i = 0; i < table_size; i++)
274 {
275 sections = table->num_of_sections;
276
277 while (sections--)
278 {
279 arm_mmu_map_section(table->paddress +
280 sections * MB,
281 table->vaddress +
282 sections * MB,
283 table->flags);
284 }
285 table++;
286 }
287}
288
vijay kumarca1672a2015-04-09 16:45:40 +0530289int platform_use_identity_mmu_mappings(void)
290{
291 /* Use only the mappings specified in this file. */
vijay kumar689fc9e2015-08-24 15:37:38 +0530292 return 0;
vijay kumarca1672a2015-04-09 16:45:40 +0530293}
Mayank Grover42664672017-03-06 17:57:26 +0530294
295bool platform_is_mdm9206()
296{
297 uint32_t platform_id = board_platform_id();
298 bool ret;
299
300 switch(platform_id)
301 {
302 case MDM9206:
303 ret = true;
304 break;
305 default:
306 ret = false;
307 }
308
309 return ret;
310}