Parth Dixit | 88a8ee1 | 2016-01-08 15:14:37 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 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> |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 32 | #include <platform/irqs.h> |
| 33 | #include <platform/clock.h> |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 34 | #include <qgic.h> |
| 35 | #include <qtimer.h> |
| 36 | #include <mmu.h> |
| 37 | #include <arch/arm/mmu.h> |
| 38 | #include <smem.h> |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 39 | #include <board.h> |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 40 | #include <boot_stats.h> |
| 41 | #include <platform.h> |
Unnati Gandhi | c74a57e | 2015-06-04 14:34:12 +0530 | [diff] [blame] | 42 | #include <target/display.h> |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 43 | |
vijay kumar | a0a7472 | 2015-09-04 15:45:49 +0530 | [diff] [blame] | 44 | #define MSM8976_SOC_V11 0x10001 |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 45 | #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 | |
| 63 | static mmu_section_t mmu_section_table[] = { |
| 64 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
Parth Dixit | 23d2344 | 2015-07-30 18:47:38 +0530 | [diff] [blame] | 65 | { 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 Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 69 | { SCRATCH_ADDR, SCRATCH_ADDR, SCRATCH_SIZE, SCRATCH_MEMORY}, |
Vishnuvardhan Prodduturi | b67e494 | 2015-12-03 22:41:45 +0530 | [diff] [blame] | 70 | { MIPI_FB_ADDR, MIPI_FB_ADDR, 20, COMMON_MEMORY}, |
Mayank Grover | e73aafb | 2017-11-02 12:52:33 +0530 | [diff] [blame] | 71 | { RPMB_SND_RCV_BUF_STRT, RPMB_SND_RCV_BUF_STRT, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY}, |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 72 | }; |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 73 | |
Parth Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 74 | static 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 Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 85 | void platform_early_init(void) |
| 86 | { |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 87 | board_init(); |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 88 | platform_clock_init(); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 89 | qgic_init(); |
| 90 | qtimer_init(); |
| 91 | scm_init(); |
| 92 | } |
| 93 | |
| 94 | void platform_init(void) |
| 95 | { |
| 96 | dprintf(INFO, "platform_init()\n"); |
| 97 | } |
| 98 | |
| 99 | void platform_uninit(void) |
| 100 | { |
| 101 | qtimer_uninit(); |
| 102 | } |
| 103 | |
| 104 | uint32_t platform_get_sclk_count(void) |
| 105 | { |
| 106 | return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 107 | } |
| 108 | |
| 109 | addr_t get_bs_info_addr() |
| 110 | { |
| 111 | return ((addr_t)BS_INFO_ADDR); |
| 112 | } |
| 113 | |
| 114 | int platform_use_identity_mmu_mappings(void) |
| 115 | { |
| 116 | /* Use only the mappings specified in this file. */ |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | /* Setup MMU mapping for this platform */ |
| 121 | void platform_init_mmu_mappings(void) |
| 122 | { |
| 123 | uint32_t i; |
| 124 | uint32_t sections; |
Parth Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 125 | uint32_t table_size; |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 126 | uint32_t ddr_start = get_ddr_start(); |
| 127 | uint32_t smem_addr = platform_get_smem_base_addr(); |
Parth Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 128 | mmu_section_t *table_addr; |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 129 | |
| 130 | /*Mapping the ddr start address for loading the kernel about 90 MB*/ |
| 131 | sections = 90; |
| 132 | while(sections--) |
| 133 | { |
Maria Yu | abef1f8 | 2015-08-05 16:13:44 +0800 | [diff] [blame] | 134 | arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, SCRATCH_MEMORY); |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 135 | } |
| 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 Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 143 | 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 Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 154 | for (i = 0; i < table_size; i++) |
| 155 | { |
Parth Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 156 | sections = table_addr->num_of_sections; |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 157 | |
| 158 | while (sections--) |
| 159 | { |
Parth Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 160 | arm_mmu_map_section(table_addr->paddress + |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 161 | sections * MB, |
Parth Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 162 | table_addr->vaddress + |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 163 | sections * MB, |
Parth Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 164 | table_addr->flags); |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 165 | } |
Parth Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 166 | table_addr++; |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 167 | } |
Parth Dixit | 7062320 | 2016-12-21 15:45:27 +0530 | [diff] [blame] | 168 | |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | addr_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 | |
| 177 | addr_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 | */ |
| 189 | uint32_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 Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 198 | } |
Aparna Mallavarapu | fa5f8a7 | 2015-03-31 06:21:36 +0530 | [diff] [blame] | 199 | |
| 200 | uint32_t platform_get_max_periph() |
| 201 | { |
| 202 | return 256; |
| 203 | } |
Unnati Gandhi | 81b7706 | 2015-05-28 14:23:39 +0530 | [diff] [blame] | 204 | |
Parth Dixit | 05f3c9f | 2016-03-18 17:14:57 +0530 | [diff] [blame] | 205 | int platform_is_msm8917() |
Parth Dixit | 88a8ee1 | 2016-01-08 15:14:37 +0530 | [diff] [blame] | 206 | { |
| 207 | uint32_t platform = board_platform_id(); |
| 208 | uint32_t ret = 0; |
| 209 | |
| 210 | switch(platform) |
| 211 | { |
Parth Dixit | 05f3c9f | 2016-03-18 17:14:57 +0530 | [diff] [blame] | 212 | case MSM8917: |
Mayank Grover | cd5f0ff | 2016-10-03 18:08:52 +0530 | [diff] [blame] | 213 | case MSM8920: |
Parth Dixit | 05f3c9f | 2016-03-18 17:14:57 +0530 | [diff] [blame] | 214 | case MSM8217: |
| 215 | case MSM8617: |
| 216 | case APQ8017: |
Parth Dixit | 88a8ee1 | 2016-01-08 15:14:37 +0530 | [diff] [blame] | 217 | ret = 1; |
| 218 | break; |
| 219 | default: |
| 220 | ret = 0; |
| 221 | }; |
| 222 | |
| 223 | return ret; |
| 224 | } |
| 225 | |
Parth Dixit | 4552cba | 2015-10-20 01:18:59 +0530 | [diff] [blame] | 226 | int 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 Dixit | 660369e | 2016-05-12 09:53:15 +0530 | [diff] [blame] | 234 | case MSM8940: |
Parth Dixit | 4552cba | 2015-10-20 01:18:59 +0530 | [diff] [blame] | 235 | case APQ8037: |
| 236 | ret = 1; |
| 237 | break; |
| 238 | default: |
| 239 | ret = 0; |
| 240 | }; |
| 241 | |
| 242 | return ret; |
| 243 | } |
| 244 | |
Parth Dixit | deecdcd | 2016-01-12 15:12:56 +0530 | [diff] [blame] | 245 | int 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 | |
Unnati Gandhi | 81b7706 | 2015-05-28 14:23:39 +0530 | [diff] [blame] | 263 | int platform_is_msm8956() |
| 264 | { |
| 265 | uint32_t platform = board_platform_id(); |
| 266 | uint32_t ret = 0; |
| 267 | |
| 268 | switch(platform) |
| 269 | { |
| 270 | case MSM8956: |
| 271 | case APQ8056: |
| 272 | case APQ8076: |
| 273 | case MSM8976: |
| 274 | ret = 1; |
| 275 | break; |
| 276 | default: |
| 277 | ret = 0; |
| 278 | }; |
| 279 | |
| 280 | return ret; |
| 281 | } |
vijay kumar | a0a7472 | 2015-09-04 15:45:49 +0530 | [diff] [blame] | 282 | |
Parth Dixit | 4734bd6 | 2016-01-13 11:06:28 +0530 | [diff] [blame] | 283 | uint32_t platform_get_tz_app_add() |
| 284 | { |
Parth Dixit | 05f3c9f | 2016-03-18 17:14:57 +0530 | [diff] [blame] | 285 | if(platform_is_msm8937() || platform_is_msm8917()) |
Parth Dixit | 4734bd6 | 2016-01-13 11:06:28 +0530 | [diff] [blame] | 286 | return APP_REGION_ADDR_8937; |
| 287 | else |
| 288 | return APP_REGION_ADDR_8952; |
| 289 | } |
| 290 | |
| 291 | uint32_t platform_get_tz_app_size() |
| 292 | { |
Parth Dixit | 05f3c9f | 2016-03-18 17:14:57 +0530 | [diff] [blame] | 293 | if(platform_is_msm8937() || platform_is_msm8917()) |
Parth Dixit | 4734bd6 | 2016-01-13 11:06:28 +0530 | [diff] [blame] | 294 | return APP_REGION_SIZE_8937; |
| 295 | else |
| 296 | return APP_REGION_SIZE_8952; |
| 297 | } |
| 298 | |
Parth Dixit | 75dc129 | 2016-01-12 14:44:40 +0530 | [diff] [blame] | 299 | uint32_t platform_get_apcs_ipc_base() |
| 300 | { |
Parth Dixit | 05f3c9f | 2016-03-18 17:14:57 +0530 | [diff] [blame] | 301 | if(platform_is_msm8917()) |
Parth Dixit | 75dc129 | 2016-01-12 14:44:40 +0530 | [diff] [blame] | 302 | return APCS_ALIAS1_IPC_INTERRUPT_1; |
| 303 | else |
| 304 | return APCS_ALIAS0_IPC_INTERRUPT_2; |
| 305 | } |
| 306 | |
vijay kumar | a0a7472 | 2015-09-04 15:45:49 +0530 | [diff] [blame] | 307 | uint32_t platform_is_msm8976_v_1_1() |
| 308 | { |
| 309 | uint32_t soc_ver = board_soc_version(); |
| 310 | uint32_t ret = 0; |
| 311 | |
| 312 | if(soc_ver == MSM8976_SOC_V11) |
| 313 | ret = 1; |
| 314 | |
| 315 | return ret; |
| 316 | } |
Mayank Grover | e73aafb | 2017-11-02 12:52:33 +0530 | [diff] [blame] | 317 | |
| 318 | void *get_rpmb_snd_rcv_buff() |
| 319 | { |
| 320 | if(smem_get_ddr_size() > 0x20000000) |
| 321 | return (void *)RPMB_SND_RCV_BUF_STRT; |
| 322 | else |
| 323 | return (void *)RPMB_SND_RCV_BUF_512; |
| 324 | } |