vijay kumar | dd51c59 | 2015-01-05 12:46:28 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <reg.h> |
| 31 | #include <platform/iomap.h> |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 32 | #include <platform/irqs.h> |
Unnati Gandhi | bd9dbea | 2014-07-17 14:30:29 +0530 | [diff] [blame] | 33 | #include <platform/clock.h> |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 34 | #include <qgic.h> |
| 35 | #include <qtimer.h> |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 36 | #include <mmu.h> |
| 37 | #include <arch/arm/mmu.h> |
| 38 | #include <smem.h> |
| 39 | #include <board.h> |
| 40 | #include <boot_stats.h> |
Unnati Gandhi | bd9dbea | 2014-07-17 14:30:29 +0530 | [diff] [blame] | 41 | #include <platform.h> |
vijay kumar | b641d0d | 2015-02-26 18:42:26 +0530 | [diff] [blame] | 42 | #include <target/display.h> |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 43 | |
| 44 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 45 | #define A53_SS_SIZE ((A53_SS_END - A53_SS_BASE)/MB) |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 46 | |
| 47 | /* LK memory - cacheable, write through */ |
Matthew Qin | f3638b9 | 2015-02-03 18:08:14 +0800 | [diff] [blame] | 48 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 49 | MMU_MEMORY_AP_READ_WRITE) |
| 50 | |
| 51 | /* Peripherals - non-shared device */ |
| 52 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \ |
| 53 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 54 | |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 55 | /* IMEM memory - cacheable, write through */ |
Aparna Mallavarapu | 428168a | 2014-06-16 21:25:06 +0530 | [diff] [blame] | 56 | #define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 57 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 58 | |
Matthew Qin | f3638b9 | 2015-02-03 18:08:14 +0800 | [diff] [blame] | 59 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
| 60 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 61 | |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 62 | static mmu_section_t mmu_section_table[] = { |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 63 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
| 64 | { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY}, |
| 65 | { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
| 66 | { A53_SS_BASE, A53_SS_BASE, A53_SS_SIZE, IOMAP_MEMORY}, |
Aparna Mallavarapu | 428168a | 2014-06-16 21:25:06 +0530 | [diff] [blame] | 67 | { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, COMMON_MEMORY}, |
| 68 | { MSM_SHARED_BASE, MSM_SHARED_BASE, 1, COMMON_MEMORY}, |
Matthew Qin | 68dabfe | 2015-04-09 02:19:14 -0400 | [diff] [blame] | 69 | { SCRATCH_ADDR, SCRATCH_ADDR, 256, SCRATCH_MEMORY}, |
vijay kumar | b641d0d | 2015-02-26 18:42:26 +0530 | [diff] [blame] | 70 | { MIPI_FB_ADDR, MIPI_FB_ADDR, 10, COMMON_MEMORY}, |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 73 | |
Unnati Gandhi | ad17b72 | 2014-06-11 23:04:54 +0530 | [diff] [blame] | 74 | int platform_is_msm8939(); |
vijay kumar | dd51c59 | 2015-01-05 12:46:28 +0530 | [diff] [blame] | 75 | int platform_is_msm8929(); |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 76 | |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 77 | void platform_early_init(void) |
| 78 | { |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 79 | board_init(); |
| 80 | platform_clock_init(); |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 81 | qgic_init(); |
| 82 | qtimer_init(); |
Unnati Gandhi | a1f8b47 | 2014-10-08 13:56:57 +0530 | [diff] [blame] | 83 | scm_init(); |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 84 | } |
| 85 | |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 86 | int qtmr_irq() |
| 87 | { |
vijay kumar | dd51c59 | 2015-01-05 12:46:28 +0530 | [diff] [blame] | 88 | if (platform_is_msm8939() || platform_is_msm8929()) |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 89 | return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39; |
| 90 | else |
| 91 | return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16; |
| 92 | } |
| 93 | |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 94 | void platform_init(void) |
| 95 | { |
| 96 | dprintf(INFO, "platform_init()\n"); |
| 97 | } |
| 98 | |
| 99 | void platform_uninit(void) |
| 100 | { |
| 101 | qtimer_uninit(); |
| 102 | } |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 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 | |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 114 | int platform_use_identity_mmu_mappings(void) |
| 115 | { |
| 116 | /* Use only the mappings specified in this file. */ |
| 117 | return 0; |
| 118 | } |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 119 | /* Setup memory for this platform */ |
| 120 | void platform_init_mmu_mappings(void) |
| 121 | { |
| 122 | uint32_t i; |
| 123 | uint32_t sections; |
| 124 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
vijay kumar | b641d0d | 2015-02-26 18:42:26 +0530 | [diff] [blame] | 125 | uint32_t ddr_start = get_ddr_start(); |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 126 | |
vijay kumar | b641d0d | 2015-02-26 18:42:26 +0530 | [diff] [blame] | 127 | /*Mapping the ddr start address for loading the kernel about 90 MB*/ |
| 128 | sections = 90; |
| 129 | while(sections--) |
| 130 | { |
| 131 | arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, COMMON_MEMORY); |
| 132 | } |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 133 | /* Configure the MMU page entries for memory read from the |
| 134 | mmu_section_table */ |
| 135 | for (i = 0; i < table_size; i++) |
| 136 | { |
| 137 | sections = mmu_section_table[i].num_of_sections; |
| 138 | |
| 139 | while (sections--) |
| 140 | { |
| 141 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 142 | sections * MB, |
| 143 | mmu_section_table[i].vaddress + |
| 144 | sections * MB, |
| 145 | mmu_section_table[i].flags); |
| 146 | } |
| 147 | } |
| 148 | } |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 149 | |
| 150 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 151 | { |
| 152 | /* Using 1-1 mapping on this platform. */ |
| 153 | return virt_addr; |
| 154 | } |
| 155 | |
| 156 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 157 | { |
| 158 | /* Using 1-1 mapping on this platform. */ |
| 159 | return phys_addr; |
| 160 | } |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 161 | |
Unnati Gandhi | ad17b72 | 2014-06-11 23:04:54 +0530 | [diff] [blame] | 162 | int platform_is_msm8939() |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 163 | { |
| 164 | uint32_t platform = board_platform_id(); |
| 165 | uint32_t ret = 0; |
| 166 | |
| 167 | switch(platform) |
| 168 | { |
| 169 | case MSM8939: |
| 170 | case APQ8036: |
| 171 | case APQ8039: |
| 172 | case MSM8236: |
| 173 | case MSM8636: |
Unnati Gandhi | ad17b72 | 2014-06-11 23:04:54 +0530 | [diff] [blame] | 174 | case MSM8936: |
Aparna Mallavarapu | 36cae9d | 2014-08-04 12:51:10 +0530 | [diff] [blame] | 175 | case MSM8239: |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 176 | ret = 1; |
| 177 | break; |
| 178 | default: |
| 179 | ret = 0; |
| 180 | }; |
| 181 | |
| 182 | return ret; |
| 183 | } |
Aparna Mallavarapu | de688ea | 2014-05-12 17:26:11 +0530 | [diff] [blame] | 184 | |
vijay kumar | dd51c59 | 2015-01-05 12:46:28 +0530 | [diff] [blame] | 185 | int platform_is_msm8929() |
| 186 | { |
| 187 | uint32_t platform = board_platform_id(); |
| 188 | uint32_t ret = 0; |
| 189 | |
| 190 | switch(platform) |
| 191 | { |
| 192 | case MSM8929: |
| 193 | case MSM8629: |
| 194 | case MSM8229: |
| 195 | case APQ8029: |
| 196 | ret = 1; |
| 197 | break; |
| 198 | default: |
| 199 | ret = 0; |
| 200 | }; |
| 201 | |
| 202 | return ret; |
| 203 | } |
| 204 | |
Vineet Bajaj | 3b1811b | 2015-04-29 17:11:57 +0530 | [diff] [blame] | 205 | int platform_is_apq8016() |
| 206 | { |
| 207 | return board_platform_id() == APQ8016 ? 1 : 0; |
| 208 | } |
| 209 | |
Aparna Mallavarapu | de688ea | 2014-05-12 17:26:11 +0530 | [diff] [blame] | 210 | /* DYNAMIC SMEM REGION feature enables LK to dynamically |
| 211 | * read the SMEM addr info from TCSR_TZ_WONCE register. |
| 212 | * The first word read, if indicates a MAGIC number, then |
| 213 | * Dynamic SMEM is assumed to be enabled. Read the remaining |
| 214 | * SMEM info for SMEM Size and Phy_addr from the other bytes. |
| 215 | */ |
| 216 | uint32_t platform_get_smem_base_addr() |
| 217 | { |
| 218 | struct smem_addr_info *smem_info = NULL; |
| 219 | |
| 220 | smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE); |
| 221 | if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER)) |
| 222 | return smem_info->phy_addr; |
| 223 | else |
| 224 | return MSM_SHARED_BASE; |
| 225 | } |