Sridhar Parasuram | be12c3d | 2015-01-16 13:42:26 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [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 | * |
Channagoud Kadabi | 0ffa786 | 2015-03-19 11:58:28 -0700 | [diff] [blame] | 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. |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <reg.h> |
| 31 | #include <platform/iomap.h> |
| 32 | #include <qgic.h> |
| 33 | #include <qtimer.h> |
| 34 | #include <platform/clock.h> |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 35 | #include <arch/arm/mmu.h> |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 36 | #include <mmu.h> |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 37 | #include <smem.h> |
| 38 | #include <board.h> |
Channagoud Kadabi | d2f06a2 | 2015-06-23 18:25:42 -0700 | [diff] [blame] | 39 | #include <target/display.h> |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 40 | |
| 41 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 42 | #define MSM_SHARED_SIZE 2 |
| 43 | |
Channagoud Kadabi | 45855f7 | 2015-07-07 15:06:28 -0700 | [diff] [blame] | 44 | /* LK memory - cacheable, write back */ |
| 45 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 46 | MMU_MEMORY_AP_READ_WRITE) |
| 47 | |
| 48 | /* Peripherals - non-shared device */ |
| 49 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \ |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 50 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN | MMU_MEMORY_PXN) |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 51 | |
Channagoud Kadabi | 45855f7 | 2015-07-07 15:06:28 -0700 | [diff] [blame] | 52 | /* SCRATCH memory - cacheable, write back */ |
| 53 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 54 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 55 | |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 56 | /* COMMON memory - cacheable, write through */ |
| 57 | #define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 58 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 59 | |
Channagoud Kadabi | a71f072 | 2015-08-11 16:21:40 -0700 | [diff] [blame] | 60 | /* downlaod mode memory - cacheable, write through */ |
| 61 | #define DLOAD_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 62 | MMU_MEMORY_AP_READ_ONLY | MMU_MEMORY_XN) |
| 63 | |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 64 | static uint64_t ddr_start; |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 65 | |
| 66 | static mmu_section_t default_mmu_section_table[] = |
| 67 | { |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 68 | /* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */ |
Channagoud Kadabi | d2f06a2 | 2015-06-23 18:25:42 -0700 | [diff] [blame] | 69 | { 0x00000000, 0x00000000, MMU_L2_NS_SECTION_MAPPING, 512, IOMAP_MEMORY}, |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 70 | { MEMBASE, MEMBASE, MMU_L2_NS_SECTION_MAPPING, (MEMSIZE / MB), LK_MEMORY}, |
| 71 | { SCRATCH_ADDR, SCRATCH_ADDR, MMU_L2_NS_SECTION_MAPPING, SCRATCH_SIZE, SCRATCH_MEMORY}, |
| 72 | { MSM_SHARED_BASE, MSM_SHARED_BASE, MMU_L2_NS_SECTION_MAPPING, MSM_SHARED_SIZE, COMMON_MEMORY}, |
| 73 | { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, MMU_L2_NS_SECTION_MAPPING, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY}, |
| 74 | }; |
| 75 | |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 76 | static mmu_section_t default_mmu_section_table_3gb[] = |
| 77 | { |
| 78 | /* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */ |
| 79 | { 0x40000000, 0x40000000, MMU_L1_NS_SECTION_MAPPING, 1024 , COMMON_MEMORY}, |
| 80 | { 0x80000000, 0x80000000, MMU_L2_NS_SECTION_MAPPING, 88 , COMMON_MEMORY}, |
| 81 | }; |
| 82 | |
| 83 | |
Channagoud Kadabi | a71f072 | 2015-08-11 16:21:40 -0700 | [diff] [blame] | 84 | /* Map the ddr for download mode, this region belongs to non-hlos images and pil */ |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 85 | static mmu_section_t dload_mmu_section_table[] = |
| 86 | { |
Channagoud Kadabi | a71f072 | 2015-08-11 16:21:40 -0700 | [diff] [blame] | 87 | /* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */ |
| 88 | { 0x85800000, 0x85800000, MMU_L2_NS_SECTION_MAPPING, 8, DLOAD_MEMORY}, |
| 89 | { 0x86200000, 0x86200000, MMU_L2_NS_SECTION_MAPPING, 174, DLOAD_MEMORY}, |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | void platform_early_init(void) |
| 93 | { |
| 94 | board_init(); |
| 95 | platform_clock_init(); |
| 96 | qgic_init(); |
| 97 | qtimer_init(); |
| 98 | scm_init(); |
| 99 | } |
| 100 | |
| 101 | void platform_init(void) |
| 102 | { |
| 103 | dprintf(INFO, "platform_init()\n"); |
| 104 | } |
| 105 | |
| 106 | void platform_uninit(void) |
| 107 | { |
| 108 | #if DISPLAY_SPLASH_SCREEN |
| 109 | display_shutdown(); |
| 110 | #endif |
| 111 | |
| 112 | qtimer_uninit(); |
| 113 | } |
| 114 | |
| 115 | int platform_use_identity_mmu_mappings(void) |
| 116 | { |
| 117 | /* Use only the mappings specified in this file. */ |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /* Setup memory for this platform */ |
| 122 | void platform_init_mmu_mappings(void) |
| 123 | { |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 124 | int i; |
| 125 | int table_sz = ARRAY_SIZE(default_mmu_section_table); |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 126 | mmu_section_t kernel_mmu_section_table; |
| 127 | uint64_t ddr_size = smem_get_ddr_size(); |
Channagoud Kadabi | a71f072 | 2015-08-11 16:21:40 -0700 | [diff] [blame] | 128 | uint32_t kernel_size = 0; |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 129 | |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 130 | if (ddr_size == MEM_4GB) |
| 131 | { |
| 132 | ddr_start = 0x80000000; |
Channagoud Kadabi | a71f072 | 2015-08-11 16:21:40 -0700 | [diff] [blame] | 133 | /* As per the memory map when DDR is 4GB first 88 MB is hlos memory |
| 134 | * use this for loading the kernel |
| 135 | */ |
| 136 | kernel_size = 88; |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 137 | } |
| 138 | else if (ddr_size == MEM_3GB) |
| 139 | { |
| 140 | ddr_start = 0x20000000; |
Channagoud Kadabi | a71f072 | 2015-08-11 16:21:40 -0700 | [diff] [blame] | 141 | /* As per memory map wheh DDR is 3GB the first 512 MB is assigned to hlos |
| 142 | * use this region for loading kernel |
| 143 | */ |
| 144 | kernel_size = 512; |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 145 | } |
| 146 | else |
| 147 | { |
| 148 | dprintf(CRITICAL, "Unsupported memory map\n"); |
| 149 | ASSERT(0); |
| 150 | } |
| 151 | |
| 152 | kernel_mmu_section_table.paddress = ddr_start; |
| 153 | kernel_mmu_section_table.vaddress = ddr_start; |
| 154 | kernel_mmu_section_table.type = MMU_L2_NS_SECTION_MAPPING; |
Channagoud Kadabi | a71f072 | 2015-08-11 16:21:40 -0700 | [diff] [blame] | 155 | kernel_mmu_section_table.size = kernel_size; |
| 156 | kernel_mmu_section_table.flags = SCRATCH_MEMORY; |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 157 | |
| 158 | /* Map kernel entry */ |
| 159 | arm_mmu_map_entry(&kernel_mmu_section_table); |
| 160 | |
| 161 | /* Map default memory needed for lk , scratch, rpmb & iomap */ |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 162 | for (i = 0 ; i < table_sz; i++) |
| 163 | arm_mmu_map_entry(&default_mmu_section_table[i]); |
| 164 | |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 165 | /* Map the rest of the DDR for 3GB needed for ramdump */ |
| 166 | if (ddr_size == MEM_3GB) |
| 167 | { |
| 168 | for (i = 0 ; i < (int)ARRAY_SIZE(default_mmu_section_table_3gb); i++) |
| 169 | arm_mmu_map_entry(&default_mmu_section_table_3gb[i]); |
| 170 | } |
| 171 | |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 172 | if (scm_device_enter_dload()) |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 173 | { |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 174 | /* TZ & Hyp memory can be mapped only while entering the download mode */ |
| 175 | table_sz = ARRAY_SIZE(dload_mmu_section_table); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 176 | |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 177 | for (i = 0 ; i < table_sz; i++) |
| 178 | arm_mmu_map_entry(&dload_mmu_section_table[i]); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
| 182 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 183 | { |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 184 | return virtual_to_physical_mapping(virt_addr); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 188 | { |
Channagoud Kadabi | 428a213 | 2015-06-17 17:32:01 -0700 | [diff] [blame] | 189 | return physical_to_virtual_mapping(phys_addr); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | uint32_t platform_get_sclk_count(void) |
| 193 | { |
| 194 | return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 195 | } |
Channagoud Kadabi | 99d2370 | 2015-02-02 20:52:17 -0800 | [diff] [blame] | 196 | |
| 197 | addr_t get_bs_info_addr() |
| 198 | { |
| 199 | return BS_INFO_ADDR; |
| 200 | } |
Channagoud Kadabi | 652a6f6 | 2014-11-17 17:23:23 -0800 | [diff] [blame] | 201 | |
| 202 | uint32_t platform_get_qmp_rev() |
| 203 | { |
| 204 | return readl(USB3_PHY_REVISION_ID3) << 24 | readl(USB3_PHY_REVISION_ID2) << 16 | |
| 205 | readl(USB3_PHY_REVISION_ID1) << 8 | readl(USB3_PHY_REVISION_ID0); |
| 206 | } |
Channagoud Kadabi | 1fc3c68 | 2015-03-29 19:49:11 -0700 | [diff] [blame] | 207 | |
| 208 | uint32_t platform_get_max_periph() |
| 209 | { |
| 210 | return 256; |
| 211 | } |
Channagoud Kadabi | 53a2126 | 2015-04-09 16:18:23 -0700 | [diff] [blame] | 212 | |
| 213 | int platform_is_msm8996() |
| 214 | { |
| 215 | if (board_platform_id() == MSM8996) |
| 216 | return 1; |
| 217 | else |
| 218 | return 0; |
| 219 | } |
Channagoud Kadabi | 2324bd5 | 2015-07-13 15:02:20 -0700 | [diff] [blame] | 220 | |
| 221 | uint64_t platform_get_ddr_start() |
| 222 | { |
| 223 | return ddr_start; |
| 224 | } |