Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
vijay kumar | 47cb1d2 | 2015-04-06 15:33:00 +0530 | [diff] [blame] | 5 | * Copyright (c) 2009-2011,2015 The Linux Foundation. All rights reserved. |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google, Inc. nor the names of its contributors |
| 17 | * may be used to endorse or promote products derived from this |
| 18 | * software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | */ |
| 33 | |
| 34 | #include <reg.h> |
| 35 | #include <debug.h> |
| 36 | #include <kernel/thread.h> |
| 37 | #include <platform/debug.h> |
vijay kumar | 47cb1d2 | 2015-04-06 15:33:00 +0530 | [diff] [blame] | 38 | #include <arch/arm/mmu.h> |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 39 | #include <platform/iomap.h> |
| 40 | #include <smem.h> |
vijay kumar | 47cb1d2 | 2015-04-06 15:33:00 +0530 | [diff] [blame] | 41 | #include <mmu.h> |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 42 | #include <qgic.h> |
| 43 | |
vijay kumar | 47cb1d2 | 2015-04-06 15:33:00 +0530 | [diff] [blame] | 44 | #define MB (1024*1024) |
| 45 | |
| 46 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 47 | |
| 48 | /* LK memory - Strongly ordered, executable */ |
| 49 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL | \ |
| 50 | MMU_MEMORY_AP_READ_WRITE) |
| 51 | /* Scratch memory - Strongly ordered, non-executable */ |
| 52 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL | \ |
| 53 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 54 | /* Peripherals - shared device */ |
| 55 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \ |
| 56 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 57 | |
| 58 | #define SCRATCH_REGION1_VIRT_START SCRATCH_REGION1 |
| 59 | #define SCRATCH_REGION2_VIRT_START (SCRATCH_REGION1_VIRT_START + \ |
| 60 | (SCRATCH_REGION1_SIZE)) |
| 61 | |
| 62 | |
| 63 | /* Map all the accesssible memory according to the following rules: |
| 64 | * 1. Map 1MB from MSM_SHARED_BASE with 1 -1 mapping. |
| 65 | * 2. Map MEMBASE - MEMSIZE with 1 -1 mapping. |
| 66 | * 3. Map all the scratch regions immediately after Appsbl memory. |
| 67 | * Virtual addresses start right after Appsbl Virtual address. |
| 68 | * 4. Map all the IOMAP space with 1 - 1 mapping. |
| 69 | * 5. Map all the rest of the SDRAM/ IMEM regions as 1 -1. |
| 70 | */ |
| 71 | mmu_section_t mmu_section_table[] = { |
| 72 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
| 73 | {MSM_SHARED_BASE, MSM_SHARED_BASE, 1, SCRATCH_MEMORY}, |
| 74 | {MEMBASE, MEMBASE, MEMSIZE / MB, LK_MEMORY}, |
| 75 | {SCRATCH_REGION1, SCRATCH_REGION1_VIRT_START, SCRATCH_REGION1_SIZE / MB, SCRATCH_MEMORY}, |
| 76 | {SCRATCH_REGION2, SCRATCH_REGION2_VIRT_START, SCRATCH_REGION2_SIZE / MB, SCRATCH_MEMORY}, |
| 77 | }; |
| 78 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 79 | static uint32_t ticks_per_sec = 0; |
| 80 | |
| 81 | extern void platform_uninit_timer(void); |
| 82 | |
| 83 | void platform_init_timer(); |
| 84 | |
| 85 | void platform_early_init(void) |
| 86 | { |
| 87 | uint8_t cfg_bid = 0x1; |
| 88 | uint8_t cfg_pid = 0x1; |
Amol Jadi | a63aaff | 2012-02-01 15:51:50 -0800 | [diff] [blame] | 89 | uint8_t gsbi_id = target_uart_gsbi(); |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 90 | |
Amol Jadi | a63aaff | 2012-02-01 15:51:50 -0800 | [diff] [blame] | 91 | uart_dm_init(gsbi_id, GSBI_BASE(gsbi_id), GSBI_UART_DM_BASE(gsbi_id)); |
| 92 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 93 | /* Timers - QGIC Config */ |
| 94 | writel((cfg_bid << 7 | cfg_pid << 10), APCS_GLB_QGIC_CFG); |
| 95 | qgic_init(); |
| 96 | platform_init_timer(); |
| 97 | } |
| 98 | |
| 99 | void platform_init(void) |
| 100 | { |
| 101 | dprintf(INFO, "platform_init()\n"); |
| 102 | acpu_clock_init(); |
| 103 | } |
| 104 | |
| 105 | void platform_uninit(void) |
| 106 | { |
| 107 | platform_uninit_timer(); |
| 108 | } |
| 109 | |
vijay kumar | 47cb1d2 | 2015-04-06 15:33:00 +0530 | [diff] [blame] | 110 | void platform_init_mmu_mappings(void) |
| 111 | { |
| 112 | struct smem_ram_ptable *ram_ptable; |
| 113 | uint32_t i; |
| 114 | uint32_t sections; |
| 115 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
| 116 | |
| 117 | /* Configure the MMU page entries for memory read from the |
| 118 | mmu_section_table */ |
| 119 | for (i = 0; i < table_size; i++) |
| 120 | { |
| 121 | sections = mmu_section_table[i].num_of_sections; |
| 122 | |
| 123 | while (sections--) |
| 124 | { |
| 125 | arm_mmu_map_section(mmu_section_table[i].paddress + sections * MB, |
| 126 | mmu_section_table[i].vaddress + sections * MB, |
| 127 | mmu_section_table[i].flags); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 133 | /* Initialize DGT timer */ |
| 134 | void platform_init_timer(void) |
| 135 | { |
| 136 | /* disable timer */ |
| 137 | writel(0, DGT_ENABLE); |
| 138 | |
Venkatesh Yadav Abbarapu | 3402bce | 2013-12-19 11:13:43 +0530 | [diff] [blame] | 139 | /* DGT uses CXO source which is 19.2MHz. |
| 140 | * Set clock divider to 4. |
| 141 | */ |
| 142 | writel(3, DGT_CLK_CTL); |
| 143 | |
| 144 | ticks_per_sec = 4800000; /* (19.2MHz/4) */ |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* Returns timer ticks per sec */ |
| 148 | uint32_t platform_tick_rate(void) |
| 149 | { |
| 150 | return ticks_per_sec; |
| 151 | } |
vijay kumar | 47cb1d2 | 2015-04-06 15:33:00 +0530 | [diff] [blame] | 152 | |
| 153 | /* Do not use default identitiy mappings. */ |
| 154 | int platform_use_identity_mmu_mappings(void) |
| 155 | { |
| 156 | return 0; |
| 157 | } |