Sundarajan Srinivasan | c4e1a99 | 2014-03-28 16:45:21 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -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> |
Deepa Dinamani | d1260ed | 2013-03-06 14:24:01 -0800 | [diff] [blame] | 34 | #include <platform/clock.h> |
| 35 | #include <mmu.h> |
| 36 | #include <arch/arm/mmu.h> |
| 37 | #include <smem.h> |
| 38 | #include <board.h> |
sundarajan srinivasan | 432010b | 2013-05-10 14:24:53 -0700 | [diff] [blame] | 39 | #include <boot_stats.h> |
Deepa Dinamani | d1260ed | 2013-03-06 14:24:01 -0800 | [diff] [blame] | 40 | |
Deepa Dinamani | d1260ed | 2013-03-06 14:24:01 -0800 | [diff] [blame] | 41 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 42 | |
| 43 | /* LK memory - cacheable, write through */ |
| 44 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 45 | MMU_MEMORY_AP_READ_WRITE) |
| 46 | |
| 47 | /* Peripherals - non-shared device */ |
| 48 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \ |
| 49 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 50 | |
| 51 | static mmu_section_t mmu_section_table[] = { |
| 52 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
| 53 | { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY}, |
| 54 | { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
| 55 | }; |
| 56 | |
| 57 | static struct smem_ram_ptable ram_ptable; |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 58 | |
| 59 | void platform_early_init(void) |
| 60 | { |
aiquny | b7f1cb1 | 2013-03-02 11:40:05 -0800 | [diff] [blame] | 61 | board_init(); |
Deepa Dinamani | eb18237 | 2013-02-04 15:53:58 -0800 | [diff] [blame] | 62 | platform_clock_init(); |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 63 | qgic_init(); |
| 64 | qtimer_init(); |
| 65 | } |
| 66 | |
| 67 | void platform_init(void) |
| 68 | { |
| 69 | dprintf(INFO, "platform_init()\n"); |
| 70 | } |
| 71 | |
| 72 | void platform_uninit(void) |
| 73 | { |
Aravind Venkateswaran | 93f6231 | 2013-06-19 15:32:22 -0700 | [diff] [blame] | 74 | #if DISPLAY_SPLASH_SCREEN |
| 75 | display_shutdown(); |
| 76 | #endif |
| 77 | |
Deepa Dinamani | 645e9b1 | 2012-12-21 14:23:40 -0800 | [diff] [blame] | 78 | qtimer_uninit(); |
| 79 | } |
Deepa Dinamani | d1260ed | 2013-03-06 14:24:01 -0800 | [diff] [blame] | 80 | |
sundarajan srinivasan | 432010b | 2013-05-10 14:24:53 -0700 | [diff] [blame] | 81 | uint32_t platform_get_sclk_count(void) |
| 82 | { |
| 83 | return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 84 | } |
| 85 | |
| 86 | addr_t get_bs_info_addr() |
| 87 | { |
| 88 | return ((addr_t)BS_INFO_ADDR); |
| 89 | } |
| 90 | |
Deepa Dinamani | d1260ed | 2013-03-06 14:24:01 -0800 | [diff] [blame] | 91 | /* Setup memory for this platform */ |
| 92 | void platform_init_mmu_mappings(void) |
| 93 | { |
| 94 | uint32_t i; |
| 95 | uint32_t sections; |
| 96 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
| 97 | |
| 98 | ASSERT(smem_ram_ptable_init(&ram_ptable)); |
| 99 | |
| 100 | /* Configure the MMU page entries for SDRAM and IMEM memory read |
| 101 | from the smem ram table*/ |
| 102 | for(i = 0; i < ram_ptable.len; i++) |
| 103 | { |
| 104 | if(ram_ptable.parts[i].type == SYS_MEMORY) |
| 105 | { |
| 106 | if((ram_ptable.parts[i].category == SDRAM) || |
| 107 | (ram_ptable.parts[i].category == IMEM)) |
| 108 | { |
| 109 | /* Check to ensure that start address is 1MB aligned */ |
| 110 | ASSERT((ram_ptable.parts[i].start & 0xFFFFF) == 0); |
| 111 | |
| 112 | sections = (ram_ptable.parts[i].size) / MB; |
| 113 | while(sections--) |
| 114 | { |
| 115 | arm_mmu_map_section(ram_ptable.parts[i].start + |
| 116 | sections * MB, |
| 117 | ram_ptable.parts[i].start + |
| 118 | sections * MB, |
| 119 | (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 120 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /* Configure the MMU page entries for memory read from the |
| 127 | mmu_section_table */ |
| 128 | for (i = 0; i < table_size; i++) |
| 129 | { |
| 130 | sections = mmu_section_table[i].num_of_sections; |
| 131 | |
| 132 | while (sections--) |
| 133 | { |
| 134 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 135 | sections * MB, |
| 136 | mmu_section_table[i].vaddress + |
| 137 | sections * MB, |
| 138 | mmu_section_table[i].flags); |
| 139 | } |
| 140 | } |
| 141 | } |
Sundarajan Srinivasan | c4e1a99 | 2014-03-28 16:45:21 -0700 | [diff] [blame] | 142 | |
| 143 | /* DYNAMIC SMEM REGION feature enables LK to dynamically read the SMEM address from MSM_DYNAMIC_SHARED_BASE. |
| 144 | * If the feature is enabled(by reading the MAGIC as mentioned below) then the SMEM address is read from |
| 145 | * MSM_DYNAMIC_SHARED_BASE otherwise revert to the older way of getting SMEM address - MSM_SHARED_BASE */ |
| 146 | |
| 147 | uint32_t platform_get_smem_base_addr() |
| 148 | { |
| 149 | uint32_t smem_addr = 0; |
| 150 | |
| 151 | if(readl(SMEM_TARGET_INFO_ADDR) == SMEM_TARGET_INFO_IDENTIFIER) |
| 152 | smem_addr = readl(MSM_DYNAMIC_SHARED_BASE); |
| 153 | else |
| 154 | smem_addr = MSM_SHARED_BASE; |
| 155 | |
| 156 | return smem_addr; |
| 157 | } |