Amol Jadi | d3d7cdc | 2013-01-16 17:02:01 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
Deepa Dinamani | 1733831 | 2012-10-18 11:29:54 -0700 | [diff] [blame] | 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. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 15 | * |
Deepa Dinamani | 1733831 | 2012-10-18 11:29:54 -0700 | [diff] [blame] | 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. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <reg.h> |
| 31 | #include <platform/iomap.h> |
| 32 | #include <qgic.h> |
Deepa Dinamani | 81eddd5 | 2012-05-31 11:18:50 -0700 | [diff] [blame] | 33 | #include <qtimer.h> |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 34 | #include <platform/clock.h> |
Neeti Desai | 13e688d | 2012-08-22 16:30:55 -0700 | [diff] [blame] | 35 | #include <mmu.h> |
| 36 | #include <arch/arm/mmu.h> |
| 37 | #include <smem.h> |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 38 | |
Neeti Desai | 13e688d | 2012-08-22 16:30:55 -0700 | [diff] [blame] | 39 | #define MB (1024*1024) |
| 40 | |
| 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 | |
Deepa Dinamani | 1733831 | 2012-10-18 11:29:54 -0700 | [diff] [blame] | 51 | static mmu_section_t mmu_section_table[] = { |
Neeti Desai | 13e688d | 2012-08-22 16:30:55 -0700 | [diff] [blame] | 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 | }; |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 56 | |
Deepa Dinamani | 1733831 | 2012-10-18 11:29:54 -0700 | [diff] [blame] | 57 | static struct smem_ram_ptable ram_ptable; |
| 58 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 59 | void platform_early_init(void) |
| 60 | { |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 61 | board_init(); |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 62 | platform_clock_init(); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 63 | qgic_init(); |
Deepa Dinamani | 81eddd5 | 2012-05-31 11:18:50 -0700 | [diff] [blame] | 64 | qtimer_init(); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void platform_init(void) |
| 68 | { |
| 69 | dprintf(INFO, "platform_init()\n"); |
| 70 | } |
| 71 | |
Joel King | 46d2a45 | 2013-02-13 18:35:21 -0800 | [diff] [blame] | 72 | static void platform_print_sclk(void) |
| 73 | { |
| 74 | uint32_t count; |
| 75 | |
| 76 | count = readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 77 | |
| 78 | dprintf(INFO, "mpm sclk=(%lu)\n", count); |
| 79 | } |
| 80 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 81 | void platform_uninit(void) |
| 82 | { |
Joel King | 46d2a45 | 2013-02-13 18:35:21 -0800 | [diff] [blame] | 83 | platform_print_sclk(); |
| 84 | |
Siddhartha Agrawal | 7ac6d51 | 2013-01-22 18:39:50 -0800 | [diff] [blame] | 85 | #if DISPLAY_SPLASH_SCREEN |
| 86 | display_shutdown(); |
| 87 | #endif |
| 88 | |
Deepa Dinamani | 81eddd5 | 2012-05-31 11:18:50 -0700 | [diff] [blame] | 89 | qtimer_uninit(); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 90 | } |
Neeti Desai | 13e688d | 2012-08-22 16:30:55 -0700 | [diff] [blame] | 91 | |
| 92 | /* Setup memory for this platform */ |
| 93 | void platform_init_mmu_mappings(void) |
| 94 | { |
Neeti Desai | 13e688d | 2012-08-22 16:30:55 -0700 | [diff] [blame] | 95 | uint32_t i; |
| 96 | uint32_t sections; |
| 97 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
| 98 | |
| 99 | ASSERT(smem_ram_ptable_init(&ram_ptable)); |
| 100 | |
| 101 | /* Configure the MMU page entries for SDRAM and IMEM memory read |
| 102 | from the smem ram table*/ |
| 103 | for(i = 0; i < ram_ptable.len; i++) |
Amol Jadi | d3d7cdc | 2013-01-16 17:02:01 -0800 | [diff] [blame] | 104 | { |
| 105 | if(ram_ptable.parts[i].type == SYS_MEMORY) |
Neeti Desai | 13e688d | 2012-08-22 16:30:55 -0700 | [diff] [blame] | 106 | { |
Amol Jadi | d3d7cdc | 2013-01-16 17:02:01 -0800 | [diff] [blame] | 107 | if((ram_ptable.parts[i].category == SDRAM) || |
| 108 | (ram_ptable.parts[i].category == IMEM)) |
| 109 | { |
| 110 | /* Check to ensure that start address is 1MB aligned */ |
| 111 | ASSERT((ram_ptable.parts[i].start & 0xFFFFF) == 0); |
Neeti Desai | 13e688d | 2012-08-22 16:30:55 -0700 | [diff] [blame] | 112 | |
Amol Jadi | d3d7cdc | 2013-01-16 17:02:01 -0800 | [diff] [blame] | 113 | sections = (ram_ptable.parts[i].size) / MB; |
| 114 | while(sections--) { |
| 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 | } |
Neeti Desai | 13e688d | 2012-08-22 16:30:55 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 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 | sections = mmu_section_table[i].num_of_sections; |
| 129 | |
| 130 | while (sections--) { |
| 131 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 132 | sections * MB, |
| 133 | mmu_section_table[i].vaddress + |
| 134 | sections * MB, |
| 135 | mmu_section_table[i].flags); |
| 136 | } |
| 137 | } |
| 138 | } |