Matthew Qin | f3638b9 | 2015-02-03 18:08:14 +0800 | [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> |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 42 | |
| 43 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 44 | #define A53_SS_SIZE ((A53_SS_END - A53_SS_BASE)/MB) |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 45 | |
| 46 | /* LK memory - cacheable, write through */ |
Matthew Qin | f3638b9 | 2015-02-03 18:08:14 +0800 | [diff] [blame^] | 47 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 48 | MMU_MEMORY_AP_READ_WRITE) |
| 49 | |
| 50 | /* Peripherals - non-shared device */ |
| 51 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \ |
| 52 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 53 | |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 54 | /* IMEM memory - cacheable, write through */ |
Aparna Mallavarapu | 428168a | 2014-06-16 21:25:06 +0530 | [diff] [blame] | 55 | #define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 56 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 57 | |
Matthew Qin | f3638b9 | 2015-02-03 18:08:14 +0800 | [diff] [blame^] | 58 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
| 59 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 60 | |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 61 | static mmu_section_t mmu_section_table[] = { |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 62 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
| 63 | { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY}, |
| 64 | { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
| 65 | { A53_SS_BASE, A53_SS_BASE, A53_SS_SIZE, IOMAP_MEMORY}, |
Aparna Mallavarapu | 428168a | 2014-06-16 21:25:06 +0530 | [diff] [blame] | 66 | { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, COMMON_MEMORY}, |
| 67 | { MSM_SHARED_BASE, MSM_SHARED_BASE, 1, COMMON_MEMORY}, |
| 68 | { BASE_ADDR, BASE_ADDR, 90, COMMON_MEMORY}, |
Matthew Qin | f3638b9 | 2015-02-03 18:08:14 +0800 | [diff] [blame^] | 69 | { SCRATCH_ADDR, SCRATCH_ADDR, 256, SCRATCH_MEMORY}, |
vijay kumar | 0da3206 | 2014-10-21 15:48:11 +0530 | [diff] [blame] | 70 | { BASE_ADDR_1, BASE_ADDR_1, 1024, 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(); |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 75 | |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 76 | void platform_early_init(void) |
| 77 | { |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 78 | board_init(); |
| 79 | platform_clock_init(); |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 80 | qgic_init(); |
| 81 | qtimer_init(); |
Unnati Gandhi | a1f8b47 | 2014-10-08 13:56:57 +0530 | [diff] [blame] | 82 | scm_init(); |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 83 | } |
| 84 | |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 85 | int qtmr_irq() |
| 86 | { |
| 87 | if (platform_is_msm8939()) |
| 88 | return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39; |
| 89 | else |
| 90 | return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16; |
| 91 | } |
| 92 | |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 93 | void platform_init(void) |
| 94 | { |
| 95 | dprintf(INFO, "platform_init()\n"); |
| 96 | } |
| 97 | |
| 98 | void platform_uninit(void) |
| 99 | { |
| 100 | qtimer_uninit(); |
| 101 | } |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 102 | |
| 103 | uint32_t platform_get_sclk_count(void) |
| 104 | { |
| 105 | return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 106 | } |
| 107 | |
| 108 | addr_t get_bs_info_addr() |
| 109 | { |
| 110 | return ((addr_t)BS_INFO_ADDR); |
| 111 | } |
| 112 | |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 113 | int platform_use_identity_mmu_mappings(void) |
| 114 | { |
| 115 | /* Use only the mappings specified in this file. */ |
| 116 | return 0; |
| 117 | } |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 118 | /* Setup memory for this platform */ |
| 119 | void platform_init_mmu_mappings(void) |
| 120 | { |
| 121 | uint32_t i; |
| 122 | uint32_t sections; |
| 123 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 124 | |
| 125 | /* Configure the MMU page entries for memory read from the |
| 126 | mmu_section_table */ |
| 127 | for (i = 0; i < table_size; i++) |
| 128 | { |
| 129 | sections = mmu_section_table[i].num_of_sections; |
| 130 | |
| 131 | while (sections--) |
| 132 | { |
| 133 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 134 | sections * MB, |
| 135 | mmu_section_table[i].vaddress + |
| 136 | sections * MB, |
| 137 | mmu_section_table[i].flags); |
| 138 | } |
| 139 | } |
| 140 | } |
Aparna Mallavarapu | 6b9ee0c | 2014-04-17 13:58:43 +0530 | [diff] [blame] | 141 | |
| 142 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 143 | { |
| 144 | /* Using 1-1 mapping on this platform. */ |
| 145 | return virt_addr; |
| 146 | } |
| 147 | |
| 148 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 149 | { |
| 150 | /* Using 1-1 mapping on this platform. */ |
| 151 | return phys_addr; |
| 152 | } |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 153 | |
Unnati Gandhi | ad17b72 | 2014-06-11 23:04:54 +0530 | [diff] [blame] | 154 | int platform_is_msm8939() |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 155 | { |
| 156 | uint32_t platform = board_platform_id(); |
| 157 | uint32_t ret = 0; |
| 158 | |
| 159 | switch(platform) |
| 160 | { |
| 161 | case MSM8939: |
| 162 | case APQ8036: |
| 163 | case APQ8039: |
| 164 | case MSM8236: |
| 165 | case MSM8636: |
Unnati Gandhi | ad17b72 | 2014-06-11 23:04:54 +0530 | [diff] [blame] | 166 | case MSM8936: |
Aparna Mallavarapu | 36cae9d | 2014-08-04 12:51:10 +0530 | [diff] [blame] | 167 | case MSM8239: |
Unnati Gandhi | 5d1f5c2 | 2014-04-25 19:24:00 +0530 | [diff] [blame] | 168 | ret = 1; |
| 169 | break; |
| 170 | default: |
| 171 | ret = 0; |
| 172 | }; |
| 173 | |
| 174 | return ret; |
| 175 | } |
Aparna Mallavarapu | de688ea | 2014-05-12 17:26:11 +0530 | [diff] [blame] | 176 | |
| 177 | /* DYNAMIC SMEM REGION feature enables LK to dynamically |
| 178 | * read the SMEM addr info from TCSR_TZ_WONCE register. |
| 179 | * The first word read, if indicates a MAGIC number, then |
| 180 | * Dynamic SMEM is assumed to be enabled. Read the remaining |
| 181 | * SMEM info for SMEM Size and Phy_addr from the other bytes. |
| 182 | */ |
| 183 | uint32_t platform_get_smem_base_addr() |
| 184 | { |
| 185 | struct smem_addr_info *smem_info = NULL; |
| 186 | |
| 187 | smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE); |
| 188 | if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER)) |
| 189 | return smem_info->phy_addr; |
| 190 | else |
| 191 | return MSM_SHARED_BASE; |
| 192 | } |
Aparna Mallavarapu | 324cfbd | 2014-08-12 12:03:48 +0530 | [diff] [blame] | 193 | uint32_t get_ddr_start() |
| 194 | { |
| 195 | uint32_t i; |
| 196 | ram_partition ptn_entry; |
| 197 | uint32_t len = 0; |
| 198 | |
| 199 | ASSERT(smem_ram_ptable_init_v1()); |
| 200 | |
| 201 | len = smem_get_ram_ptable_len(); |
| 202 | |
| 203 | /* Determine the Start addr of the DDR RAM */ |
| 204 | for(i = 0; i < len; i++) |
| 205 | { |
| 206 | smem_get_ram_ptable_entry(&ptn_entry, i); |
| 207 | if(ptn_entry.type == SYS_MEMORY) |
| 208 | { |
| 209 | if((ptn_entry.category == SDRAM) || |
| 210 | (ptn_entry.category == IMEM)) |
| 211 | { |
| 212 | /* Check to ensure that start address is 1MB aligned */ |
| 213 | ASSERT((ptn_entry.start & (MB-1)) == 0); |
| 214 | return ptn_entry.start; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | ASSERT("DDR Start Mem Not found\n"); |
| 219 | } |