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}, |
| 69 | { SCRATCH_ADDR, SCRATCH_ADDR, 512, SCRATCH_MEMORY}, |
Vishnuvardhan Prodduturi | b67e494 | 2015-12-03 22:41:45 +0530 | [diff] [blame] | 70 | { MIPI_FB_ADDR, MIPI_FB_ADDR, 20, COMMON_MEMORY}, |
Parth Dixit | 23d2344 | 2015-07-30 18:47:38 +0530 | [diff] [blame] | 71 | { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, 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 | |
| 74 | void platform_early_init(void) |
| 75 | { |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 76 | board_init(); |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 77 | platform_clock_init(); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 78 | qgic_init(); |
| 79 | qtimer_init(); |
| 80 | scm_init(); |
| 81 | } |
| 82 | |
| 83 | void platform_init(void) |
| 84 | { |
| 85 | dprintf(INFO, "platform_init()\n"); |
| 86 | } |
| 87 | |
| 88 | void platform_uninit(void) |
| 89 | { |
| 90 | qtimer_uninit(); |
| 91 | } |
| 92 | |
| 93 | uint32_t platform_get_sclk_count(void) |
| 94 | { |
| 95 | return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 96 | } |
| 97 | |
| 98 | addr_t get_bs_info_addr() |
| 99 | { |
| 100 | return ((addr_t)BS_INFO_ADDR); |
| 101 | } |
| 102 | |
| 103 | int platform_use_identity_mmu_mappings(void) |
| 104 | { |
| 105 | /* Use only the mappings specified in this file. */ |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | /* Setup MMU mapping for this platform */ |
| 110 | void platform_init_mmu_mappings(void) |
| 111 | { |
| 112 | uint32_t i; |
| 113 | uint32_t sections; |
| 114 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
| 115 | uint32_t ddr_start = get_ddr_start(); |
| 116 | uint32_t smem_addr = platform_get_smem_base_addr(); |
| 117 | |
| 118 | /*Mapping the ddr start address for loading the kernel about 90 MB*/ |
| 119 | sections = 90; |
| 120 | while(sections--) |
| 121 | { |
Maria Yu | abef1f8 | 2015-08-05 16:13:44 +0800 | [diff] [blame] | 122 | 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] | 123 | } |
| 124 | |
| 125 | |
| 126 | /* Mapping the SMEM addr */ |
| 127 | arm_mmu_map_section(smem_addr, smem_addr, COMMON_MEMORY); |
| 128 | |
| 129 | /* Configure the MMU page entries for memory read from the |
| 130 | mmu_section_table */ |
| 131 | for (i = 0; i < table_size; i++) |
| 132 | { |
| 133 | sections = mmu_section_table[i].num_of_sections; |
| 134 | |
| 135 | while (sections--) |
| 136 | { |
| 137 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 138 | sections * MB, |
| 139 | mmu_section_table[i].vaddress + |
| 140 | sections * MB, |
| 141 | mmu_section_table[i].flags); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 147 | { |
| 148 | /* Using 1-1 mapping on this platform. */ |
| 149 | return virt_addr; |
| 150 | } |
| 151 | |
| 152 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 153 | { |
| 154 | /* Using 1-1 mapping on this platform. */ |
| 155 | return phys_addr; |
| 156 | } |
| 157 | |
| 158 | /* DYNAMIC SMEM REGION feature enables LK to dynamically |
| 159 | * read the SMEM addr info from TCSR_TZ_WONCE register. |
| 160 | * The first word read, if indicates a MAGIC number, then |
| 161 | * Dynamic SMEM is assumed to be enabled. Read the remaining |
| 162 | * SMEM info for SMEM Size and Phy_addr from the other bytes. |
| 163 | */ |
| 164 | uint32_t platform_get_smem_base_addr() |
| 165 | { |
| 166 | struct smem_addr_info *smem_info = NULL; |
| 167 | |
| 168 | smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE); |
| 169 | if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER)) |
| 170 | return smem_info->phy_addr; |
| 171 | else |
| 172 | return MSM_SHARED_BASE; |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 173 | } |
Aparna Mallavarapu | fa5f8a7 | 2015-03-31 06:21:36 +0530 | [diff] [blame] | 174 | |
| 175 | uint32_t platform_get_max_periph() |
| 176 | { |
| 177 | return 256; |
| 178 | } |
Unnati Gandhi | 81b7706 | 2015-05-28 14:23:39 +0530 | [diff] [blame] | 179 | |
Parth Dixit | 88a8ee1 | 2016-01-08 15:14:37 +0530 | [diff] [blame] | 180 | int platform_is_msmgold() |
| 181 | { |
| 182 | uint32_t platform = board_platform_id(); |
| 183 | uint32_t ret = 0; |
| 184 | |
| 185 | switch(platform) |
| 186 | { |
| 187 | case MSMGOLD: |
| 188 | case MSMGOLD2: |
| 189 | case MSMGOLD3: |
| 190 | case APQGOLD: |
| 191 | ret = 1; |
| 192 | break; |
| 193 | default: |
| 194 | ret = 0; |
| 195 | }; |
| 196 | |
| 197 | return ret; |
| 198 | } |
| 199 | |
Parth Dixit | 4552cba | 2015-10-20 01:18:59 +0530 | [diff] [blame] | 200 | int platform_is_msm8937() |
| 201 | { |
| 202 | uint32_t platform = board_platform_id(); |
| 203 | uint32_t ret = 0; |
| 204 | |
| 205 | switch(platform) |
| 206 | { |
| 207 | case MSM8937: |
| 208 | case APQ8037: |
| 209 | ret = 1; |
| 210 | break; |
| 211 | default: |
| 212 | ret = 0; |
| 213 | }; |
| 214 | |
| 215 | return ret; |
| 216 | } |
| 217 | |
Unnati Gandhi | 81b7706 | 2015-05-28 14:23:39 +0530 | [diff] [blame] | 218 | int platform_is_msm8956() |
| 219 | { |
| 220 | uint32_t platform = board_platform_id(); |
| 221 | uint32_t ret = 0; |
| 222 | |
| 223 | switch(platform) |
| 224 | { |
| 225 | case MSM8956: |
| 226 | case APQ8056: |
| 227 | case APQ8076: |
| 228 | case MSM8976: |
| 229 | ret = 1; |
| 230 | break; |
| 231 | default: |
| 232 | ret = 0; |
| 233 | }; |
| 234 | |
| 235 | return ret; |
| 236 | } |
vijay kumar | a0a7472 | 2015-09-04 15:45:49 +0530 | [diff] [blame] | 237 | |
| 238 | uint32_t platform_is_msm8976_v_1_1() |
| 239 | { |
| 240 | uint32_t soc_ver = board_soc_version(); |
| 241 | uint32_t ret = 0; |
| 242 | |
| 243 | if(soc_ver == MSM8976_SOC_V11) |
| 244 | ret = 1; |
| 245 | |
| 246 | return ret; |
| 247 | } |