Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 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> |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 32 | #include <platform/irqs.h> |
| 33 | #include <platform/clock.h> |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +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> |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 39 | #include <board.h> |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 40 | #include <boot_stats.h> |
| 41 | #include <platform.h> |
Unnati Gandhi | c74a57e | 2015-06-04 14:34:12 +0530 | [diff] [blame] | 42 | #include <target/display.h> |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +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 */ |
| 48 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
| 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 | |
| 55 | /* IMEM memory - cacheable, write through */ |
| 56 | #define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 57 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 58 | |
| 59 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
| 60 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 61 | |
| 62 | static mmu_section_t mmu_section_table[] = { |
| 63 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
Parth Dixit | 23d2344 | 2015-07-30 18:47:38 +0530 | [diff] [blame] | 64 | { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY}, |
| 65 | { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
| 66 | { APPS_SS_BASE, APPS_SS_BASE, APPS_SS_SIZE, IOMAP_MEMORY}, |
| 67 | { MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, COMMON_MEMORY}, |
| 68 | { SCRATCH_ADDR, SCRATCH_ADDR, 512, SCRATCH_MEMORY}, |
| 69 | { MIPI_FB_ADDR, MIPI_FB_ADDR, 42, COMMON_MEMORY}, |
| 70 | { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY}, |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 71 | }; |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 72 | |
| 73 | void platform_early_init(void) |
| 74 | { |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 75 | board_init(); |
Aparna Mallavarapu | 7b638e6 | 2015-03-26 05:51:57 +0530 | [diff] [blame] | 76 | platform_clock_init(); |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 77 | qgic_init(); |
| 78 | qtimer_init(); |
| 79 | scm_init(); |
| 80 | } |
| 81 | |
| 82 | void platform_init(void) |
| 83 | { |
| 84 | dprintf(INFO, "platform_init()\n"); |
| 85 | } |
| 86 | |
| 87 | void platform_uninit(void) |
| 88 | { |
| 89 | qtimer_uninit(); |
| 90 | } |
| 91 | |
| 92 | uint32_t platform_get_sclk_count(void) |
| 93 | { |
| 94 | return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 95 | } |
| 96 | |
| 97 | addr_t get_bs_info_addr() |
| 98 | { |
| 99 | return ((addr_t)BS_INFO_ADDR); |
| 100 | } |
| 101 | |
| 102 | int platform_use_identity_mmu_mappings(void) |
| 103 | { |
| 104 | /* Use only the mappings specified in this file. */ |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | /* Setup MMU mapping for this platform */ |
| 109 | void platform_init_mmu_mappings(void) |
| 110 | { |
| 111 | uint32_t i; |
| 112 | uint32_t sections; |
| 113 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
| 114 | uint32_t ddr_start = get_ddr_start(); |
| 115 | uint32_t smem_addr = platform_get_smem_base_addr(); |
| 116 | |
| 117 | /*Mapping the ddr start address for loading the kernel about 90 MB*/ |
| 118 | sections = 90; |
| 119 | while(sections--) |
| 120 | { |
Maria Yu | abef1f8 | 2015-08-05 16:13:44 +0800 | [diff] [blame] | 121 | arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, SCRATCH_MEMORY); |
Aparna Mallavarapu | e9bdacd | 2015-03-15 14:24:21 +0530 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | |
| 125 | /* Mapping the SMEM addr */ |
| 126 | arm_mmu_map_section(smem_addr, smem_addr, COMMON_MEMORY); |
| 127 | |
| 128 | /* Configure the MMU page entries for memory read from the |
| 129 | mmu_section_table */ |
| 130 | for (i = 0; i < table_size; i++) |
| 131 | { |
| 132 | sections = mmu_section_table[i].num_of_sections; |
| 133 | |
| 134 | while (sections--) |
| 135 | { |
| 136 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 137 | sections * MB, |
| 138 | mmu_section_table[i].vaddress + |
| 139 | sections * MB, |
| 140 | mmu_section_table[i].flags); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 146 | { |
| 147 | /* Using 1-1 mapping on this platform. */ |
| 148 | return virt_addr; |
| 149 | } |
| 150 | |
| 151 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 152 | { |
| 153 | /* Using 1-1 mapping on this platform. */ |
| 154 | return phys_addr; |
| 155 | } |
| 156 | |
| 157 | /* DYNAMIC SMEM REGION feature enables LK to dynamically |
| 158 | * read the SMEM addr info from TCSR_TZ_WONCE register. |
| 159 | * The first word read, if indicates a MAGIC number, then |
| 160 | * Dynamic SMEM is assumed to be enabled. Read the remaining |
| 161 | * SMEM info for SMEM Size and Phy_addr from the other bytes. |
| 162 | */ |
| 163 | uint32_t platform_get_smem_base_addr() |
| 164 | { |
| 165 | struct smem_addr_info *smem_info = NULL; |
| 166 | |
| 167 | smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE); |
| 168 | if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER)) |
| 169 | return smem_info->phy_addr; |
| 170 | else |
| 171 | return MSM_SHARED_BASE; |
Aparna Mallavarapu | ca67688 | 2015-01-19 20:39:06 +0530 | [diff] [blame] | 172 | } |
Aparna Mallavarapu | fa5f8a7 | 2015-03-31 06:21:36 +0530 | [diff] [blame] | 173 | |
| 174 | uint32_t platform_get_max_periph() |
| 175 | { |
| 176 | return 256; |
| 177 | } |
Unnati Gandhi | 81b7706 | 2015-05-28 14:23:39 +0530 | [diff] [blame] | 178 | |
Parth Dixit | 4552cba | 2015-10-20 01:18:59 +0530 | [diff] [blame^] | 179 | int platform_is_msm8937() |
| 180 | { |
| 181 | uint32_t platform = board_platform_id(); |
| 182 | uint32_t ret = 0; |
| 183 | |
| 184 | switch(platform) |
| 185 | { |
| 186 | case MSM8937: |
| 187 | case APQ8037: |
| 188 | ret = 1; |
| 189 | break; |
| 190 | default: |
| 191 | ret = 0; |
| 192 | }; |
| 193 | |
| 194 | return ret; |
| 195 | } |
| 196 | |
Unnati Gandhi | 81b7706 | 2015-05-28 14:23:39 +0530 | [diff] [blame] | 197 | int platform_is_msm8956() |
| 198 | { |
| 199 | uint32_t platform = board_platform_id(); |
| 200 | uint32_t ret = 0; |
| 201 | |
| 202 | switch(platform) |
| 203 | { |
| 204 | case MSM8956: |
| 205 | case APQ8056: |
| 206 | case APQ8076: |
| 207 | case MSM8976: |
| 208 | ret = 1; |
| 209 | break; |
| 210 | default: |
| 211 | ret = 0; |
| 212 | }; |
| 213 | |
| 214 | return ret; |
| 215 | } |