blob: 325e103bf71e361d46a68ed0932f86a9481d0131 [file] [log] [blame]
Umang Agrawal3f4cc322019-05-27 14:28:59 +05301/* Copyright (c) 2015-2016, 2018-2019, The Linux Foundation. All rights reserved.
Aparna Mallavarapuca676882015-01-19 20:39:06 +05302 *
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>
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053032#include <platform/irqs.h>
33#include <platform/clock.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053034#include <qgic.h>
35#include <qtimer.h>
36#include <mmu.h>
37#include <arch/arm/mmu.h>
38#include <smem.h>
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053039#include <board.h>
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053040#include <boot_stats.h>
41#include <platform.h>
Unnati Gandhic74a57e2015-06-04 14:34:12 +053042#include <target/display.h>
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053043
vijay kumara0a74722015-09-04 15:45:49 +053044#define MSM8976_SOC_V11 0x10001
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053045#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
46#define APPS_SS_SIZE ((APPS_SS_END - APPS_SS_BASE)/MB)
47
48/* LK memory - cacheable, write through */
49#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
50 MMU_MEMORY_AP_READ_WRITE)
51
52/* Peripherals - non-shared device */
53#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
54 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
55
56/* IMEM memory - cacheable, write through */
57#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
58 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
59
60#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
61 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
62
63static mmu_section_t mmu_section_table[] = {
64/* Physical addr, Virtual addr, Size (in MB), Flags */
Parth Dixit23d23442015-07-30 18:47:38 +053065 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
66 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
67 { APPS_SS_BASE, APPS_SS_BASE, APPS_SS_SIZE, IOMAP_MEMORY},
68 { MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, COMMON_MEMORY},
Parth Dixit70623202016-12-21 15:45:27 +053069 { SCRATCH_ADDR, SCRATCH_ADDR, SCRATCH_SIZE, SCRATCH_MEMORY},
Vishnuvardhan Prodduturib67e4942015-12-03 22:41:45 +053070 { MIPI_FB_ADDR, MIPI_FB_ADDR, 20, COMMON_MEMORY},
Mayank Grovere73aafb2017-11-02 12:52:33 +053071 { RPMB_SND_RCV_BUF_STRT, RPMB_SND_RCV_BUF_STRT, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY},
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053072};
Aparna Mallavarapuca676882015-01-19 20:39:06 +053073
Parth Dixit70623202016-12-21 15:45:27 +053074static mmu_section_t mmu_section_table_512[] = {
75/* Physical addr, Virtual addr, Size (in MB), Flags */
76 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
77 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
78 { APPS_SS_BASE, APPS_SS_BASE, APPS_SS_SIZE, IOMAP_MEMORY},
79 { MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, COMMON_MEMORY},
80 { SCRATCH_ADDR_512, SCRATCH_ADDR_512, SCRATCH_SIZE_512, SCRATCH_MEMORY},
81 { MIPI_FB_ADDR, MIPI_FB_ADDR, 20, COMMON_MEMORY},
82 { RPMB_SND_RCV_BUF_512, RPMB_SND_RCV_BUF_512, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY},
83};
84
Aparna Mallavarapuca676882015-01-19 20:39:06 +053085void platform_early_init(void)
86{
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053087 board_init();
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053088 platform_clock_init();
Aparna Mallavarapuca676882015-01-19 20:39:06 +053089 qgic_init();
90 qtimer_init();
91 scm_init();
92}
93
94void platform_init(void)
95{
96 dprintf(INFO, "platform_init()\n");
97}
98
99void platform_uninit(void)
100{
101 qtimer_uninit();
102}
103
104uint32_t platform_get_sclk_count(void)
105{
106 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
107}
108
109addr_t get_bs_info_addr()
110{
111 return ((addr_t)BS_INFO_ADDR);
112}
113
114int platform_use_identity_mmu_mappings(void)
115{
116 /* Use only the mappings specified in this file. */
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530117 return 0;
118}
119
120/* Setup MMU mapping for this platform */
121void platform_init_mmu_mappings(void)
122{
123 uint32_t i;
124 uint32_t sections;
Parth Dixit70623202016-12-21 15:45:27 +0530125 uint32_t table_size;
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530126 uint32_t ddr_start = get_ddr_start();
127 uint32_t smem_addr = platform_get_smem_base_addr();
Parth Dixit70623202016-12-21 15:45:27 +0530128 mmu_section_t *table_addr;
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530129
130 /*Mapping the ddr start address for loading the kernel about 90 MB*/
131 sections = 90;
132 while(sections--)
133 {
Maria Yuabef1f82015-08-05 16:13:44 +0800134 arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, SCRATCH_MEMORY);
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530135 }
136
137
138 /* Mapping the SMEM addr */
139 arm_mmu_map_section(smem_addr, smem_addr, COMMON_MEMORY);
140
141 /* Configure the MMU page entries for memory read from the
142 mmu_section_table */
Parth Dixit70623202016-12-21 15:45:27 +0530143 if(smem_get_ddr_size() > 0x20000000)
144 {
145 table_addr = mmu_section_table;
146 table_size = ARRAY_SIZE(mmu_section_table);
147 }
148 else
149 {
150 table_addr = mmu_section_table_512;
151 table_size = ARRAY_SIZE(mmu_section_table_512);
152 }
153
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530154 for (i = 0; i < table_size; i++)
155 {
Parth Dixit70623202016-12-21 15:45:27 +0530156 sections = table_addr->num_of_sections;
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530157
158 while (sections--)
159 {
Parth Dixit70623202016-12-21 15:45:27 +0530160 arm_mmu_map_section(table_addr->paddress +
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530161 sections * MB,
Parth Dixit70623202016-12-21 15:45:27 +0530162 table_addr->vaddress +
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530163 sections * MB,
Parth Dixit70623202016-12-21 15:45:27 +0530164 table_addr->flags);
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530165 }
Parth Dixit70623202016-12-21 15:45:27 +0530166 table_addr++;
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530167 }
Parth Dixit70623202016-12-21 15:45:27 +0530168
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530169}
170
171addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
172{
173 /* Using 1-1 mapping on this platform. */
174 return virt_addr;
175}
176
177addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
178{
179 /* Using 1-1 mapping on this platform. */
180 return phys_addr;
181}
182
183/* DYNAMIC SMEM REGION feature enables LK to dynamically
184 * read the SMEM addr info from TCSR_TZ_WONCE register.
185 * The first word read, if indicates a MAGIC number, then
186 * Dynamic SMEM is assumed to be enabled. Read the remaining
187 * SMEM info for SMEM Size and Phy_addr from the other bytes.
188 */
189uint32_t platform_get_smem_base_addr()
190{
191 struct smem_addr_info *smem_info = NULL;
192
193 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
194 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
195 return smem_info->phy_addr;
196 else
197 return MSM_SHARED_BASE;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530198}
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530199
200uint32_t platform_get_max_periph()
201{
202 return 256;
203}
Unnati Gandhi81b77062015-05-28 14:23:39 +0530204
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530205int platform_is_msm8917()
Parth Dixit88a8ee12016-01-08 15:14:37 +0530206{
207 uint32_t platform = board_platform_id();
208 uint32_t ret = 0;
209
210 switch(platform)
211 {
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530212 case MSM8917:
Mayank Grovercd5f0ff2016-10-03 18:08:52 +0530213 case MSM8920:
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530214 case MSM8217:
215 case MSM8617:
216 case APQ8017:
lijuang412d4f02018-10-16 18:27:48 +0800217 ret = 1;
218 break;
219 default:
220 ret = 0;
221 };
222
223 return ret;
224}
225
226int platform_is_qm215()
227{
228 uint32_t platform = board_platform_id();
229 uint32_t ret = 0;
230
231 switch(platform)
232 {
lijuang80ac1182018-09-07 13:39:58 +0800233 case QM215:
Nagireddy Annem7828d8b2019-09-09 12:29:05 +0530234 case QCM2150:
Parth Dixit88a8ee12016-01-08 15:14:37 +0530235 ret = 1;
236 break;
237 default:
238 ret = 0;
239 };
240
241 return ret;
242}
243
Parth Dixit4552cba2015-10-20 01:18:59 +0530244int platform_is_msm8937()
245{
246 uint32_t platform = board_platform_id();
247 uint32_t ret = 0;
248
249 switch(platform)
250 {
251 case MSM8937:
Parth Dixit660369e2016-05-12 09:53:15 +0530252 case MSM8940:
Parth Dixit4552cba2015-10-20 01:18:59 +0530253 case APQ8037:
254 ret = 1;
255 break;
256 default:
257 ret = 0;
258 };
259
260 return ret;
261}
262
Parth Dixitdeecdcd2016-01-12 15:12:56 +0530263int platform_is_msm8952()
264{
265 uint32_t platform = board_platform_id();
266 uint32_t ret = 0;
267
268 switch(platform)
269 {
270 case MSM8952:
271 case APQ8052:
272 ret = 1;
273 break;
274 default:
275 ret = 0;
276 };
277
278 return ret;
279}
280
lijuangd18524e2018-04-04 20:22:19 +0800281int platform_is_sdm429()
282{
283 uint32_t platform = board_platform_id();
284 uint32_t ret = 0;
285
286 switch(platform)
287 {
288 case SDM429:
lijuang08f14922018-04-23 19:02:57 +0800289 case SDA429:
lijuangd18524e2018-04-04 20:22:19 +0800290 ret = 1;
291 break;
292 default:
293 ret = 0;
294 };
295
296 return ret;
297}
298
299int platform_is_sdm439()
300{
301 uint32_t platform = board_platform_id();
302 uint32_t ret = 0;
303
304 switch(platform)
305 {
306 case SDM439:
lijuang08f14922018-04-23 19:02:57 +0800307 case SDA439:
lijuangd18524e2018-04-04 20:22:19 +0800308 ret = 1;
309 break;
310 default:
311 ret = 0;
312 };
313
314 return ret;
315}
316
Umang Agrawal3f4cc322019-05-27 14:28:59 +0530317int platform_is_sdm429w()
318{
319 uint32_t platform = board_platform_id();
320 uint32_t ret = 0;
321
322 switch(platform)
323 {
324 case SDM429W:
325 ret = 1;
326 break;
327 default:
328 ret = 0;
329 };
330
331 return ret;
332}
lijuangd18524e2018-04-04 20:22:19 +0800333
Meng Jiangc86f5cb2019-10-23 15:05:25 +0800334int platform_is_sda429w()
335{
336 uint32_t platform = board_platform_id();
337 uint32_t ret = 0;
338
339 switch(platform)
340 {
341 case SDA429W:
342 ret = 1;
343 break;
344 default:
345 ret = 0;
346 };
347
348 return ret;
349}
350
Unnati Gandhi81b77062015-05-28 14:23:39 +0530351int platform_is_msm8956()
352{
353 uint32_t platform = board_platform_id();
354 uint32_t ret = 0;
355
356 switch(platform)
357 {
358 case MSM8956:
359 case APQ8056:
360 case APQ8076:
361 case MSM8976:
362 ret = 1;
363 break;
364 default:
365 ret = 0;
366 };
367
368 return ret;
369}
vijay kumara0a74722015-09-04 15:45:49 +0530370
Parth Dixit4734bd62016-01-13 11:06:28 +0530371uint32_t platform_get_tz_app_add()
372{
lijuangd18524e2018-04-04 20:22:19 +0800373 if(platform_is_msm8937() || platform_is_msm8917() ||
Meng Jiangc86f5cb2019-10-23 15:05:25 +0800374 platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w() || platform_is_sdm439() ||
lijuang412d4f02018-10-16 18:27:48 +0800375 platform_is_qm215())
Parth Dixit4734bd62016-01-13 11:06:28 +0530376 return APP_REGION_ADDR_8937;
377 else
378 return APP_REGION_ADDR_8952;
379}
380
381uint32_t platform_get_tz_app_size()
382{
lijuangd18524e2018-04-04 20:22:19 +0800383 if(platform_is_msm8937() || platform_is_msm8917() ||
Meng Jiangc86f5cb2019-10-23 15:05:25 +0800384 platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w() || platform_is_sdm439() ||
lijuang412d4f02018-10-16 18:27:48 +0800385 platform_is_qm215())
Parth Dixit4734bd62016-01-13 11:06:28 +0530386 return APP_REGION_SIZE_8937;
387 else
388 return APP_REGION_SIZE_8952;
389}
390
Parth Dixit75dc1292016-01-12 14:44:40 +0530391uint32_t platform_get_apcs_ipc_base()
392{
Meng Jiangc86f5cb2019-10-23 15:05:25 +0800393 if(platform_is_msm8917() || platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w() || platform_is_qm215())
Parth Dixit75dc1292016-01-12 14:44:40 +0530394 return APCS_ALIAS1_IPC_INTERRUPT_1;
395 else
396 return APCS_ALIAS0_IPC_INTERRUPT_2;
397}
398
vijay kumara0a74722015-09-04 15:45:49 +0530399uint32_t platform_is_msm8976_v_1_1()
400{
401 uint32_t soc_ver = board_soc_version();
402 uint32_t ret = 0;
403
404 if(soc_ver == MSM8976_SOC_V11)
405 ret = 1;
406
407 return ret;
408}
Mayank Grovere73aafb2017-11-02 12:52:33 +0530409
410void *get_rpmb_snd_rcv_buff()
411{
412 if(smem_get_ddr_size() > 0x20000000)
413 return (void *)RPMB_SND_RCV_BUF_STRT;
414 else
415 return (void *)RPMB_SND_RCV_BUF_512;
416}