Jeevan Shriram | 8d5e5ee | 2015-01-07 11:35:55 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [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> |
| 32 | #include <qgic.h> |
| 33 | #include <qtimer.h> |
| 34 | #include <platform/clock.h> |
| 35 | #include <mmu.h> |
| 36 | #include <arch/arm/mmu.h> |
| 37 | #include <smem.h> |
| 38 | #include <board.h> |
| 39 | |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 40 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 41 | |
Channagoud Kadabi | 92d5018 | 2014-06-18 12:13:15 -0700 | [diff] [blame] | 42 | #define HLOS_MEMORY_START 0x0 |
| 43 | #define HLOS_MEMORY_SIZE 0x63 |
| 44 | |
Sridhar Parasuram | 113229a | 2015-06-01 09:31:58 -0700 | [diff] [blame] | 45 | /* LK memory - cacheable, write back */ |
Channagoud Kadabi | b1aafbb | 2015-02-13 20:08:51 -0800 | [diff] [blame] | 46 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 47 | MMU_MEMORY_AP_READ_WRITE) |
| 48 | |
| 49 | /* Peripherals - non-shared device */ |
| 50 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \ |
| 51 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 52 | |
| 53 | /* IMEM memory - cacheable, write through */ |
Channagoud Kadabi | 92d5018 | 2014-06-18 12:13:15 -0700 | [diff] [blame] | 54 | #define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 55 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 56 | |
Sridhar Parasuram | 113229a | 2015-06-01 09:31:58 -0700 | [diff] [blame] | 57 | /* Scratch memory - cacheable, write back */ |
| 58 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ |
| 59 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 60 | |
| 61 | |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 62 | static mmu_section_t mmu_section_table[] = { |
Channagoud Kadabi | 92d5018 | 2014-06-18 12:13:15 -0700 | [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 | { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, COMMON_MEMORY}, |
| 67 | { MSM_SHARED_BASE, MSM_SHARED_BASE, 2, COMMON_MEMORY}, |
| 68 | { HLOS_MEMORY_START, HLOS_MEMORY_START, HLOS_MEMORY_SIZE, COMMON_MEMORY}, |
Sridhar Parasuram | 113229a | 2015-06-01 09:31:58 -0700 | [diff] [blame] | 69 | { SCRATCH_ADDR, SCRATCH_ADDR, (SCRATCH_SIZE / MB), SCRATCH_MEMORY}, |
Sridhar Parasuram | 8d925a0 | 2015-05-21 21:28:32 -0700 | [diff] [blame] | 70 | { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY}, |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | void platform_early_init(void) |
| 74 | { |
| 75 | board_init(); |
| 76 | platform_clock_init(); |
| 77 | qgic_init(); |
| 78 | qtimer_init(); |
Channagoud Kadabi | c7eb569 | 2014-08-19 15:45:00 -0700 | [diff] [blame] | 79 | scm_init(); |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void platform_init(void) |
| 83 | { |
| 84 | dprintf(INFO, "platform_init()\n"); |
Channagoud Kadabi | dc627c0 | 2014-06-26 14:45:34 -0700 | [diff] [blame] | 85 | #if ENABLE_XPU_VIOLATION |
| 86 | scm_xpu_err_fatal_init(); |
| 87 | #endif |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void platform_uninit(void) |
| 91 | { |
| 92 | #if DISPLAY_SPLASH_SCREEN |
| 93 | display_shutdown(); |
| 94 | #endif |
| 95 | |
| 96 | qtimer_uninit(); |
| 97 | } |
| 98 | |
| 99 | int platform_use_identity_mmu_mappings(void) |
| 100 | { |
| 101 | /* Use only the mappings specified in this file. */ |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | /* Setup memory for this platform */ |
| 106 | void platform_init_mmu_mappings(void) |
| 107 | { |
| 108 | uint32_t i; |
| 109 | uint32_t sections; |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 110 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 111 | |
| 112 | /* Configure the MMU page entries for memory read from the |
| 113 | mmu_section_table */ |
| 114 | for (i = 0; i < table_size; i++) |
| 115 | { |
| 116 | sections = mmu_section_table[i].num_of_sections; |
| 117 | |
| 118 | while (sections--) |
| 119 | { |
| 120 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 121 | sections * MB, |
| 122 | mmu_section_table[i].vaddress + |
| 123 | sections * MB, |
| 124 | mmu_section_table[i].flags); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 130 | { |
| 131 | /* Using 1-1 mapping on this platform. */ |
| 132 | return virt_addr; |
| 133 | } |
| 134 | |
| 135 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 136 | { |
| 137 | /* Using 1-1 mapping on this platform. */ |
| 138 | return phys_addr; |
| 139 | } |
| 140 | |
| 141 | uint32_t platform_get_sclk_count(void) |
| 142 | { |
| 143 | return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 144 | } |
| 145 | |
Sridhar Parasuram | 39419a3 | 2014-09-12 18:11:05 -0700 | [diff] [blame] | 146 | int platform_is_msm8994() |
| 147 | { |
| 148 | uint32_t platform = board_platform_id(); |
| 149 | if ((platform == APQ8094) || (platform == MSM8994)) |
| 150 | return 1; |
| 151 | else |
| 152 | return 0; |
| 153 | } |
| 154 | |
Jeevan Shriram | 8d5e5ee | 2015-01-07 11:35:55 -0800 | [diff] [blame] | 155 | int platform_is_msm8992() |
| 156 | { |
| 157 | int ret; |
| 158 | |
| 159 | uint32_t platform = board_platform_id(); |
| 160 | switch (platform) { |
| 161 | case MSM8992: |
| 162 | case APQ8092: |
| 163 | ret = 1; |
| 164 | break; |
| 165 | default: |
| 166 | ret = 0; |
| 167 | } |
| 168 | |
| 169 | return ret; |
| 170 | } |
| 171 | |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 172 | addr_t get_bs_info_addr() |
| 173 | { |
Sridhar Parasuram | 39419a3 | 2014-09-12 18:11:05 -0700 | [diff] [blame] | 174 | if (platform_is_msm8994()) |
| 175 | return ((addr_t)BS_INFO_ADDR); |
| 176 | else |
| 177 | return ((addr_t)BS_INFO_ADDR2); |
Channagoud Kadabi | 123c972 | 2014-02-06 13:22:50 -0800 | [diff] [blame] | 178 | } |