Mayank Grover | dc6da17 | 2018-04-17 15:10:31 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +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> |
P.V. Phani Kumar | 40fa135 | 2015-08-13 18:15:03 +0530 | [diff] [blame] | 32 | #include <platform/irqs.h> |
| 33 | #include <platform/clock.h> |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +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> |
P.V. Phani Kumar | 40fa135 | 2015-08-13 18:15:03 +0530 | [diff] [blame] | 39 | #include <board.h> |
| 40 | #include <boot_stats.h> |
| 41 | #include <platform.h> |
Jayant Shekhar | bd6a516 | 2016-01-19 12:50:49 +0530 | [diff] [blame] | 42 | #include <target/display.h> |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 43 | |
| 44 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 45 | #define APPS_SS_SIZE ((APPS_SS_END - APPS_SS_BASE)/MB) |
| 46 | |
| 47 | /* LK memory - cacheable, write through */ |
Mayank Grover | dc6da17 | 2018-04-17 15:10:31 +0530 | [diff] [blame] | 48 | #ifdef SECURE_CODE_MEM |
| 49 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
| 50 | MMU_MEMORY_AP_READ_ONLY |\ |
| 51 | MMU_MEMORY_APX_READ_ONLY) |
| 52 | |
| 53 | #define LK_MEMORY_RW (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
| 54 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 55 | #else |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 56 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
| 57 | MMU_MEMORY_AP_READ_WRITE) |
Mayank Grover | dc6da17 | 2018-04-17 15:10:31 +0530 | [diff] [blame] | 58 | #endif |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 59 | /* Peripherals - non-shared device */ |
| 60 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \ |
| 61 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 62 | |
| 63 | /* IMEM memory - cacheable, write through */ |
| 64 | #define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 65 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 66 | |
| 67 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
| 68 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 69 | |
| 70 | static mmu_section_t mmu_section_table[] = { |
| 71 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
Mayank Grover | dc6da17 | 2018-04-17 15:10:31 +0530 | [diff] [blame] | 72 | #ifdef SECURE_CODE_MEM |
| 73 | { MEMBASE, MEMBASE, 1, LK_MEMORY}, |
| 74 | { MEMRWOFF, MEMRWOFF, (MEMSIZE / MB) - 1, LK_MEMORY_RW}, |
| 75 | #else |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 76 | { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY}, |
Mayank Grover | dc6da17 | 2018-04-17 15:10:31 +0530 | [diff] [blame] | 77 | #endif |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 78 | { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
| 79 | { APPS_SS_BASE, APPS_SS_BASE, APPS_SS_SIZE, IOMAP_MEMORY}, |
| 80 | { MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, COMMON_MEMORY}, |
Mayank Grover | 35617eb | 2018-01-11 17:18:29 +0530 | [diff] [blame] | 81 | { SCRATCH_ADDR, SCRATCH_ADDR, SCRATCH_SIZE, SCRATCH_MEMORY}, |
Jayant Shekhar | bd6a516 | 2016-01-19 12:50:49 +0530 | [diff] [blame] | 82 | { MIPI_FB_ADDR, MIPI_FB_ADDR, 20, COMMON_MEMORY}, |
P.V. Phani Kumar | 9451ebe | 2015-12-26 16:31:18 +0530 | [diff] [blame] | 83 | { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY}, |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 84 | }; |
| 85 | |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 86 | void platform_early_init(void) |
| 87 | { |
P.V. Phani Kumar | 40fa135 | 2015-08-13 18:15:03 +0530 | [diff] [blame] | 88 | board_init(); |
| 89 | platform_clock_init(); |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 90 | qgic_init(); |
| 91 | qtimer_init(); |
| 92 | scm_init(); |
| 93 | } |
| 94 | |
| 95 | void platform_init(void) |
| 96 | { |
| 97 | dprintf(INFO, "platform_init()\n"); |
| 98 | } |
| 99 | |
| 100 | void platform_uninit(void) |
| 101 | { |
| 102 | qtimer_uninit(); |
| 103 | } |
| 104 | |
| 105 | uint32_t platform_get_sclk_count(void) |
| 106 | { |
| 107 | return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 108 | } |
| 109 | |
| 110 | addr_t get_bs_info_addr() |
| 111 | { |
| 112 | return ((addr_t)BS_INFO_ADDR); |
| 113 | } |
| 114 | |
| 115 | int platform_use_identity_mmu_mappings(void) |
| 116 | { |
| 117 | /* Use only the mappings specified in this file. */ |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /* Setup MMU mapping for this platform */ |
| 122 | void platform_init_mmu_mappings(void) |
| 123 | { |
| 124 | uint32_t i; |
| 125 | uint32_t sections; |
| 126 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
lijuang | 6e6aec5 | 2016-01-14 15:37:55 +0800 | [diff] [blame] | 127 | uint32_t ddr_start = DDR_START; |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 128 | uint32_t smem_addr = platform_get_smem_base_addr(); |
| 129 | |
| 130 | /*Mapping the ddr start address for loading the kernel about 90 MB*/ |
| 131 | sections = 90; |
| 132 | while(sections--) |
| 133 | { |
| 134 | arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, COMMON_MEMORY); |
| 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 */ |
| 143 | for (i = 0; i < table_size; i++) |
| 144 | { |
| 145 | sections = mmu_section_table[i].num_of_sections; |
| 146 | |
| 147 | while (sections--) |
| 148 | { |
| 149 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 150 | sections * MB, |
| 151 | mmu_section_table[i].vaddress + |
| 152 | sections * MB, |
| 153 | mmu_section_table[i].flags); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 159 | { |
| 160 | /* Using 1-1 mapping on this platform. */ |
| 161 | return virt_addr; |
| 162 | } |
| 163 | |
| 164 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 165 | { |
| 166 | /* Using 1-1 mapping on this platform. */ |
| 167 | return phys_addr; |
| 168 | } |
| 169 | |
Wufeng | c1c91ee | 2016-04-15 19:11:36 +0800 | [diff] [blame] | 170 | uint32_t platform_get_max_periph() |
| 171 | { |
| 172 | return 256; |
| 173 | } |
| 174 | |
P.V. Phani Kumar | a053a32 | 2015-08-13 18:36:05 +0530 | [diff] [blame] | 175 | /* DYNAMIC SMEM REGION feature enables LK to dynamically |
| 176 | * read the SMEM addr info from TCSR_TZ_WONCE register. |
| 177 | * The first word read, if indicates a MAGIC number, then |
| 178 | * Dynamic SMEM is assumed to be enabled. Read the remaining |
| 179 | * SMEM info for SMEM Size and Phy_addr from the other bytes. |
| 180 | */ |
| 181 | uint32_t platform_get_smem_base_addr() |
| 182 | { |
| 183 | struct smem_addr_info *smem_info = NULL; |
| 184 | |
| 185 | smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE); |
| 186 | if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER)) |
| 187 | return smem_info->phy_addr; |
| 188 | else |
| 189 | return MSM_SHARED_BASE; |
Aparna Mallavarapu | 01fc00a | 2015-06-01 20:37:05 +0530 | [diff] [blame] | 190 | } |
P.V. Phani Kumar | 9451ebe | 2015-12-26 16:31:18 +0530 | [diff] [blame] | 191 | |
Gaurav Nebhwani | 4157b05 | 2016-03-09 15:45:55 +0530 | [diff] [blame] | 192 | int platform_is_msm8953() |
| 193 | { |
| 194 | uint32_t platform = board_platform_id(); |
| 195 | |
Mayank Grover | 60ee8b8 | 2017-12-26 12:46:14 +0530 | [diff] [blame] | 196 | switch (platform) |
| 197 | { |
| 198 | case MSM8953: |
| 199 | case APQ8053: |
| 200 | case SDM450: |
| 201 | case SDA450: |
lijuang | 199f97d | 2018-01-02 10:11:59 +0800 | [diff] [blame] | 202 | case SDM632: |
| 203 | case SDA632: |
Mayank Grover | 60ee8b8 | 2017-12-26 12:46:14 +0530 | [diff] [blame] | 204 | return 1; |
| 205 | break; |
| 206 | default: |
| 207 | return 0; |
| 208 | } |
Gaurav Nebhwani | 4157b05 | 2016-03-09 15:45:55 +0530 | [diff] [blame] | 209 | } |
| 210 | |
P.V. Phani Kumar | 9451ebe | 2015-12-26 16:31:18 +0530 | [diff] [blame] | 211 | uint32_t platform_get_qmp_rev() |
| 212 | { |
| 213 | return readl(USB3_PHY_REVISION_ID3) << 24 | readl(USB3_PHY_REVISION_ID2) << 16 | |
| 214 | readl(USB3_PHY_REVISION_ID1) << 8 | readl(USB3_PHY_REVISION_ID0); |
| 215 | } |