blob: 184f5e27675a0685d9a1681da95ab67891e9bd93 [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:
Parth Dixit88a8ee12016-01-08 15:14:37 +0530217 ret = 1;
218 break;
219 default:
220 ret = 0;
221 };
222
223 return ret;
224}
225
Parth Dixit4552cba2015-10-20 01:18:59 +0530226int platform_is_msm8937()
227{
228 uint32_t platform = board_platform_id();
229 uint32_t ret = 0;
230
231 switch(platform)
232 {
233 case MSM8937:
Parth Dixit660369e2016-05-12 09:53:15 +0530234 case MSM8940:
Parth Dixit4552cba2015-10-20 01:18:59 +0530235 case APQ8037:
236 ret = 1;
237 break;
238 default:
239 ret = 0;
240 };
241
242 return ret;
243}
244
Parth Dixitdeecdcd2016-01-12 15:12:56 +0530245int platform_is_msm8952()
246{
247 uint32_t platform = board_platform_id();
248 uint32_t ret = 0;
249
250 switch(platform)
251 {
252 case MSM8952:
253 case APQ8052:
254 ret = 1;
255 break;
256 default:
257 ret = 0;
258 };
259
260 return ret;
261}
262
lijuangd18524e2018-04-04 20:22:19 +0800263int platform_is_sdm429()
264{
265 uint32_t platform = board_platform_id();
266 uint32_t ret = 0;
267
268 switch(platform)
269 {
270 case SDM429:
lijuang08f14922018-04-23 19:02:57 +0800271 case SDA429:
lijuangd18524e2018-04-04 20:22:19 +0800272 ret = 1;
273 break;
274 default:
275 ret = 0;
276 };
277
278 return ret;
279}
280
281int platform_is_sdm439()
282{
283 uint32_t platform = board_platform_id();
284 uint32_t ret = 0;
285
286 switch(platform)
287 {
288 case SDM439:
lijuang08f14922018-04-23 19:02:57 +0800289 case SDA439:
lijuangd18524e2018-04-04 20:22:19 +0800290 ret = 1;
291 break;
292 default:
293 ret = 0;
294 };
295
296 return ret;
297}
298
299
Unnati Gandhi81b77062015-05-28 14:23:39 +0530300int platform_is_msm8956()
301{
302 uint32_t platform = board_platform_id();
303 uint32_t ret = 0;
304
305 switch(platform)
306 {
307 case MSM8956:
308 case APQ8056:
309 case APQ8076:
310 case MSM8976:
311 ret = 1;
312 break;
313 default:
314 ret = 0;
315 };
316
317 return ret;
318}
vijay kumara0a74722015-09-04 15:45:49 +0530319
Parth Dixit4734bd62016-01-13 11:06:28 +0530320uint32_t platform_get_tz_app_add()
321{
lijuangd18524e2018-04-04 20:22:19 +0800322 if(platform_is_msm8937() || platform_is_msm8917() ||
323 platform_is_sdm429() || platform_is_sdm439())
Parth Dixit4734bd62016-01-13 11:06:28 +0530324 return APP_REGION_ADDR_8937;
325 else
326 return APP_REGION_ADDR_8952;
327}
328
329uint32_t platform_get_tz_app_size()
330{
lijuangd18524e2018-04-04 20:22:19 +0800331 if(platform_is_msm8937() || platform_is_msm8917() ||
332 platform_is_sdm429() || platform_is_sdm439())
Parth Dixit4734bd62016-01-13 11:06:28 +0530333 return APP_REGION_SIZE_8937;
334 else
335 return APP_REGION_SIZE_8952;
336}
337
Parth Dixit75dc1292016-01-12 14:44:40 +0530338uint32_t platform_get_apcs_ipc_base()
339{
lijuangd18524e2018-04-04 20:22:19 +0800340 if(platform_is_msm8917() || platform_is_sdm429())
Parth Dixit75dc1292016-01-12 14:44:40 +0530341 return APCS_ALIAS1_IPC_INTERRUPT_1;
342 else
343 return APCS_ALIAS0_IPC_INTERRUPT_2;
344}
345
vijay kumara0a74722015-09-04 15:45:49 +0530346uint32_t platform_is_msm8976_v_1_1()
347{
348 uint32_t soc_ver = board_soc_version();
349 uint32_t ret = 0;
350
351 if(soc_ver == MSM8976_SOC_V11)
352 ret = 1;
353
354 return ret;
355}
Mayank Grovere73aafb2017-11-02 12:52:33 +0530356
357void *get_rpmb_snd_rcv_buff()
358{
359 if(smem_get_ddr_size() > 0x20000000)
360 return (void *)RPMB_SND_RCV_BUF_STRT;
361 else
362 return (void *)RPMB_SND_RCV_BUF_512;
363}