Deepa Dinamani | 554b062 | 2013-05-16 15:00:30 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2013, 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 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 | |
Sundarajan Srinivasan | 0f21b77 | 2013-08-29 13:19:15 -0700 | [diff] [blame] | 40 | #define MB (1024*1024) |
| 41 | |
| 42 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 43 | |
| 44 | /* LK memory - cacheable, write through */ |
| 45 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 46 | MMU_MEMORY_AP_READ_WRITE) |
| 47 | |
| 48 | /* Peripherals - non-shared device */ |
| 49 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \ |
| 50 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 51 | |
| 52 | /* IMEM memory - cacheable, write through */ |
| 53 | #define IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 54 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 55 | |
| 56 | static mmu_section_t mmu_section_table[] = { |
| 57 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
| 58 | { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY}, |
| 59 | { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
| 60 | /* IMEM needs a seperate entry in the table as it's length is only 0x8000. */ |
| 61 | { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY}, |
| 62 | }; |
| 63 | |
Deepa Dinamani | 554b062 | 2013-05-16 15:00:30 -0700 | [diff] [blame] | 64 | void platform_early_init(void) |
| 65 | { |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 66 | board_init(); |
Deepa Dinamani | 554b062 | 2013-05-16 15:00:30 -0700 | [diff] [blame] | 67 | platform_clock_init(); |
| 68 | qgic_init(); |
| 69 | qtimer_init(); |
| 70 | } |
| 71 | |
| 72 | void platform_init(void) |
| 73 | { |
| 74 | dprintf(INFO, "platform_init()\n"); |
| 75 | } |
| 76 | |
| 77 | void platform_uninit(void) |
| 78 | { |
| 79 | #if DISPLAY_SPLASH_SCREEN |
| 80 | display_shutdown(); |
| 81 | #endif |
| 82 | |
| 83 | qtimer_uninit(); |
| 84 | } |
Sundarajan Srinivasan | 0f21b77 | 2013-08-29 13:19:15 -0700 | [diff] [blame] | 85 | |
| 86 | int platform_use_identity_mmu_mappings(void) |
| 87 | { |
| 88 | /* Use only the mappings specified in this file. */ |
| 89 | return 0; |
| 90 | } |
| 91 | |
Sundarajan Srinivasan | 1feb8b9 | 2013-12-11 12:28:32 -0800 | [diff] [blame] | 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 | |
Sundarajan Srinivasan | 0f21b77 | 2013-08-29 13:19:15 -0700 | [diff] [blame] | 102 | /* Setup memory for this platform */ |
| 103 | void platform_init_mmu_mappings(void) |
| 104 | { |
| 105 | uint32_t i; |
| 106 | uint32_t sections; |
| 107 | ram_partition ptn_entry; |
| 108 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
| 109 | uint32_t len = 0; |
| 110 | |
| 111 | ASSERT(smem_ram_ptable_init_v1()); |
| 112 | |
| 113 | len = smem_get_ram_ptable_len(); |
| 114 | |
| 115 | /* Configure the MMU page entries for SDRAM and IMEM memory read |
| 116 | from the smem ram table*/ |
| 117 | for(i = 0; i < len; i++) |
| 118 | { |
| 119 | smem_get_ram_ptable_entry(&ptn_entry, i); |
| 120 | if(ptn_entry.type == SYS_MEMORY) |
| 121 | { |
| 122 | if((ptn_entry.category == SDRAM) || |
| 123 | (ptn_entry.category == IMEM)) |
| 124 | { |
| 125 | /* Check to ensure that start address is 1MB aligned */ |
| 126 | ASSERT((ptn_entry.start & (MB-1)) == 0); |
| 127 | |
| 128 | sections = (ptn_entry.size) / MB; |
| 129 | while(sections--) |
| 130 | { |
| 131 | arm_mmu_map_section(ptn_entry.start + |
| 132 | sections * MB, |
| 133 | ptn_entry.start + |
| 134 | sections * MB, |
| 135 | (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 136 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /* Configure the MMU page entries for memory read from the |
| 143 | mmu_section_table */ |
| 144 | for (i = 0; i < table_size; i++) |
| 145 | { |
| 146 | sections = mmu_section_table[i].num_of_sections; |
| 147 | |
| 148 | while (sections--) |
| 149 | { |
| 150 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 151 | sections * MB, |
| 152 | mmu_section_table[i].vaddress + |
| 153 | sections * MB, |
| 154 | mmu_section_table[i].flags); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 160 | { |
| 161 | /* Using 1-1 mapping on this platform. */ |
| 162 | return virt_addr; |
| 163 | } |
| 164 | |
| 165 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 166 | { |
| 167 | /* Using 1-1 mapping on this platform. */ |
| 168 | return phys_addr; |
| 169 | } |