Mayank Grover | 7e35183 | 2017-04-21 15:03:58 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015, 2017, The Linux Foundation. All rights reserved. |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +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> |
| 32 | #include <qgic.h> |
| 33 | #include <qtimer.h> |
| 34 | #include <mmu.h> |
| 35 | #include <arch/arm/mmu.h> |
| 36 | #include <smem.h> |
Unnati Gandhi | abb73ec | 2015-06-23 13:07:36 +0530 | [diff] [blame] | 37 | #include <target/display.h> |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +0530 | [diff] [blame] | 38 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 39 | #define MB (1024*1024) |
| 40 | |
| 41 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 42 | #define A7_SS_SIZE ((A7_SS_END - A7_SS_BASE)/MB) |
| 43 | |
Matthew Qin | fab78c3 | 2015-04-28 03:05:24 -0400 | [diff] [blame] | 44 | /* LK memory - cacheable, write back */ |
| 45 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 46 | MMU_MEMORY_AP_READ_WRITE) |
| 47 | |
Matthew Qin | fab78c3 | 2015-04-28 03:05:24 -0400 | [diff] [blame] | 48 | |
| 49 | #define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 50 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 51 | |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 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 IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 58 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 59 | |
| 60 | static mmu_section_t mmu_section_table[] = { |
| 61 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
| 62 | { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY}, |
| 63 | { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
| 64 | { A7_SS_BASE, A7_SS_BASE, A7_SS_SIZE, IOMAP_MEMORY}, |
| 65 | { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY}, |
Matthew Qin | fab78c3 | 2015-04-28 03:05:24 -0400 | [diff] [blame] | 66 | { MSM_SHARED_BASE, MSM_SHARED_BASE, 1, COMMON_MEMORY}, |
Unnati Gandhi | abb73ec | 2015-06-23 13:07:36 +0530 | [diff] [blame] | 67 | { MIPI_FB_ADDR, MIPI_FB_ADDR, 10, COMMON_MEMORY}, |
Mayank Grover | 7e35183 | 2017-04-21 15:03:58 +0530 | [diff] [blame] | 68 | { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY}, |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | static struct smem_ram_ptable ram_ptable; |
| 72 | |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +0530 | [diff] [blame] | 73 | void platform_early_init(void) |
| 74 | { |
Unnati Gandhi | a556a4d | 2014-08-12 10:42:21 +0530 | [diff] [blame] | 75 | board_init(); |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 76 | platform_clock_init(); |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +0530 | [diff] [blame] | 77 | qgic_init(); |
| 78 | qtimer_init(); |
| 79 | } |
| 80 | |
| 81 | void platform_init(void) |
| 82 | { |
| 83 | dprintf(INFO, "platform_init()\n"); |
| 84 | } |
| 85 | |
| 86 | void platform_uninit(void) |
| 87 | { |
| 88 | qtimer_uninit(); |
Unnati Gandhi | c43a280 | 2014-09-19 17:27:25 +0530 | [diff] [blame] | 89 | if (!platform_boot_dev_isemmc()) |
| 90 | qpic_nand_uninit(); |
Unnati Gandhi | b3820bc | 2014-07-04 16:56:27 +0530 | [diff] [blame] | 91 | } |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 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. */ |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | /* Setup memory 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 | ram_partition ptn_entry; |
| 116 | uint32_t len = 0; |
| 117 | |
| 118 | ASSERT(smem_ram_ptable_init_v1()); |
| 119 | |
| 120 | len = smem_get_ram_ptable_len(); |
| 121 | |
| 122 | /* Configure the MMU page entries for SDRAM and IMEM memory read |
| 123 | from the smem ram table*/ |
| 124 | for(i = 0; i < len; i++) |
| 125 | { |
| 126 | smem_get_ram_ptable_entry(&ptn_entry, i); |
| 127 | if(ptn_entry.type == SYS_MEMORY) |
| 128 | { |
| 129 | if((ptn_entry.category == SDRAM) || |
| 130 | (ptn_entry.category == IMEM)) |
| 131 | { |
| 132 | /* Check to ensure that start address is 1MB aligned */ |
| 133 | ASSERT((ptn_entry.start & (MB-1)) == 0); |
| 134 | |
| 135 | sections = (ptn_entry.size) / MB; |
| 136 | while(sections--) |
| 137 | { |
| 138 | arm_mmu_map_section(ptn_entry.start + |
| 139 | sections * MB, |
| 140 | ptn_entry.start + |
| 141 | sections * MB, |
Matthew Qin | fab78c3 | 2015-04-28 03:05:24 -0400 | [diff] [blame] | 142 | (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
Unnati Gandhi | f4cb662 | 2014-08-28 13:54:56 +0530 | [diff] [blame] | 143 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /* Configure the MMU page entries for memory read from the |
| 150 | mmu_section_table */ |
| 151 | for (i = 0; i < table_size; i++) |
| 152 | { |
| 153 | sections = mmu_section_table[i].num_of_sections; |
| 154 | |
| 155 | while (sections--) |
| 156 | { |
| 157 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 158 | sections * MB, |
| 159 | mmu_section_table[i].vaddress + |
| 160 | sections * MB, |
| 161 | mmu_section_table[i].flags); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 167 | { |
| 168 | /* Using 1-1 mapping on this platform. */ |
| 169 | return virt_addr; |
| 170 | } |
| 171 | |
| 172 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 173 | { |
| 174 | /* Using 1-1 mapping on this platform. */ |
| 175 | return phys_addr; |
| 176 | } |
| 177 | |
| 178 | /* DYNAMIC SMEM REGION feature enables LK to dynamically |
| 179 | * read the SMEM addr info from TCSR_TZ_WONCE register. |
| 180 | * The first word read, if indicates a MAGIC number, then |
| 181 | * Dynamic SMEM is assumed to be enabled. Read the remaining |
| 182 | * SMEM info for SMEM Size and Phy_addr from the other bytes. |
| 183 | */ |
| 184 | uint32_t platform_get_smem_base_addr() |
| 185 | { |
| 186 | struct smem_addr_info *smem_info = NULL; |
| 187 | |
| 188 | smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE); |
| 189 | if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER)) |
| 190 | return smem_info->phy_addr; |
| 191 | else |
| 192 | return MSM_SHARED_BASE; |
| 193 | } |
| 194 | |
Unnati Gandhi | 6c92a4f | 2014-11-18 18:01:51 +0530 | [diff] [blame] | 195 | int platform_is_msm8909() |
| 196 | { |
| 197 | uint32_t platform = board_platform_id(); |
| 198 | uint32_t ret = 0; |
| 199 | |
| 200 | switch(platform) |
| 201 | { |
| 202 | case MSM8909: |
| 203 | case MSM8209: |
| 204 | case MSM8208: |
| 205 | case APQ8009: |
Unnati Gandhi | 917c861 | 2015-02-06 16:50:32 +0530 | [diff] [blame] | 206 | case MSM8609: |
Unnati Gandhi | 6c92a4f | 2014-11-18 18:01:51 +0530 | [diff] [blame] | 207 | ret = 1; |
| 208 | break; |
| 209 | default: |
| 210 | ret = 0; |
| 211 | }; |
| 212 | |
| 213 | return ret; |
| 214 | } |
| 215 | |
| 216 | int boot_device_mask(int val) |
| 217 | { |
| 218 | return ((val & 0x0E) >> 1); |
| 219 | } |
Unnati Gandhi | 2488505 | 2014-11-27 16:57:49 +0530 | [diff] [blame] | 220 | |
| 221 | uint32_t platform_detect_panel() |
| 222 | { |
| 223 | uint32_t panel; |
| 224 | |
| 225 | /* Bits 28:29 of this register are read to know |
| 226 | the panel config, and pick up DT accordingly. |
| 227 | |
| 228 | 00 -no limit, suport HD |
| 229 | 01 - limit to 720P |
| 230 | 10- limit to qHD |
| 231 | 11- limit to fWVGA |
| 232 | |
| 233 | */ |
| 234 | panel = readl(SECURITY_CONTROL_CORE_FEATURE_CONFIG0); |
| 235 | panel = (panel & 0x30000000) >> 28; |
| 236 | |
| 237 | return panel; |
| 238 | } |