blob: e865b30e7306663b2ddfc14f505b50a4282e1733 [file] [log] [blame]
lijuangd18524e2018-04-04 20:22:19 +08001/* Copyright (c) 2015-2016, 2018, 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:
lijuang80ac1182018-09-07 13:39:58 +0800217 case QM215:
Parth Dixit88a8ee12016-01-08 15:14:37 +0530218 ret = 1;
219 break;
220 default:
221 ret = 0;
222 };
223
224 return ret;
225}
226
Parth Dixit4552cba2015-10-20 01:18:59 +0530227int platform_is_msm8937()
228{
229 uint32_t platform = board_platform_id();
230 uint32_t ret = 0;
231
232 switch(platform)
233 {
234 case MSM8937:
Parth Dixit660369e2016-05-12 09:53:15 +0530235 case MSM8940:
Parth Dixit4552cba2015-10-20 01:18:59 +0530236 case APQ8037:
237 ret = 1;
238 break;
239 default:
240 ret = 0;
241 };
242
243 return ret;
244}
245
Parth Dixitdeecdcd2016-01-12 15:12:56 +0530246int platform_is_msm8952()
247{
248 uint32_t platform = board_platform_id();
249 uint32_t ret = 0;
250
251 switch(platform)
252 {
253 case MSM8952:
254 case APQ8052:
255 ret = 1;
256 break;
257 default:
258 ret = 0;
259 };
260
261 return ret;
262}
263
lijuangd18524e2018-04-04 20:22:19 +0800264int platform_is_sdm429()
265{
266 uint32_t platform = board_platform_id();
267 uint32_t ret = 0;
268
269 switch(platform)
270 {
271 case SDM429:
lijuang08f14922018-04-23 19:02:57 +0800272 case SDA429:
lijuangd18524e2018-04-04 20:22:19 +0800273 ret = 1;
274 break;
275 default:
276 ret = 0;
277 };
278
279 return ret;
280}
281
282int platform_is_sdm439()
283{
284 uint32_t platform = board_platform_id();
285 uint32_t ret = 0;
286
287 switch(platform)
288 {
289 case SDM439:
lijuang08f14922018-04-23 19:02:57 +0800290 case SDA439:
lijuangd18524e2018-04-04 20:22:19 +0800291 ret = 1;
292 break;
293 default:
294 ret = 0;
295 };
296
297 return ret;
298}
299
300
Unnati Gandhi81b77062015-05-28 14:23:39 +0530301int platform_is_msm8956()
302{
303 uint32_t platform = board_platform_id();
304 uint32_t ret = 0;
305
306 switch(platform)
307 {
308 case MSM8956:
309 case APQ8056:
310 case APQ8076:
311 case MSM8976:
312 ret = 1;
313 break;
314 default:
315 ret = 0;
316 };
317
318 return ret;
319}
vijay kumara0a74722015-09-04 15:45:49 +0530320
Parth Dixit4734bd62016-01-13 11:06:28 +0530321uint32_t platform_get_tz_app_add()
322{
lijuangd18524e2018-04-04 20:22:19 +0800323 if(platform_is_msm8937() || platform_is_msm8917() ||
324 platform_is_sdm429() || platform_is_sdm439())
Parth Dixit4734bd62016-01-13 11:06:28 +0530325 return APP_REGION_ADDR_8937;
326 else
327 return APP_REGION_ADDR_8952;
328}
329
330uint32_t platform_get_tz_app_size()
331{
lijuangd18524e2018-04-04 20:22:19 +0800332 if(platform_is_msm8937() || platform_is_msm8917() ||
333 platform_is_sdm429() || platform_is_sdm439())
Parth Dixit4734bd62016-01-13 11:06:28 +0530334 return APP_REGION_SIZE_8937;
335 else
336 return APP_REGION_SIZE_8952;
337}
338
Parth Dixit75dc1292016-01-12 14:44:40 +0530339uint32_t platform_get_apcs_ipc_base()
340{
lijuangd18524e2018-04-04 20:22:19 +0800341 if(platform_is_msm8917() || platform_is_sdm429())
Parth Dixit75dc1292016-01-12 14:44:40 +0530342 return APCS_ALIAS1_IPC_INTERRUPT_1;
343 else
344 return APCS_ALIAS0_IPC_INTERRUPT_2;
345}
346
vijay kumara0a74722015-09-04 15:45:49 +0530347uint32_t platform_is_msm8976_v_1_1()
348{
349 uint32_t soc_ver = board_soc_version();
350 uint32_t ret = 0;
351
352 if(soc_ver == MSM8976_SOC_V11)
353 ret = 1;
354
355 return ret;
356}
Mayank Grovere73aafb2017-11-02 12:52:33 +0530357
358void *get_rpmb_snd_rcv_buff()
359{
360 if(smem_get_ddr_size() > 0x20000000)
361 return (void *)RPMB_SND_RCV_BUF_STRT;
362 else
363 return (void *)RPMB_SND_RCV_BUF_512;
364}