blob: 776cb5e916d14aa52da4217135e6769e4bbc72ad [file] [log] [blame]
Deepa Dinamani7e15e0b2013-02-07 13:05:38 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Amol Jadi42d7b5a2012-05-04 14:50:32 -07002 *
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.
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070012 * * Neither the name of The Linux Foundation nor the names of its
Amol Jadi42d7b5a2012-05-04 14:50:32 -070013 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
Amol Jadib726c3b2012-09-13 13:51:23 -070016 * 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.
Amol Jadi42d7b5a2012-05-04 14:50:32 -070027 */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070028
Amol Jadi42d7b5a2012-05-04 14:50:32 -070029#include <debug.h>
30#include <platform.h>
31#include <qgic.h>
32#include <qtimer.h>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070033#include <board.h>
Deepa Dinamani87feab82012-10-04 14:28:05 -070034#include <qpic_nand.h>
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -070035#include <mmu.h>
36#include <arch/arm/mmu.h>
37#include <platform/iomap.h>
38#include <target.h>
39#include <smem.h>
40#include <reg.h>
Amol Jadifd507d52013-03-18 15:17:36 -070041#include <board.h>
42#include <boot_stats.h>
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -070043
44extern struct smem_ram_ptable* target_smem_ram_ptable_init();
45
46#define MB (1024*1024)
47
48#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
49
50/* LK memory - Strongly ordered, executable */
Deepa Dinamani7e15e0b2013-02-07 13:05:38 -080051#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL | \
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -070052 MMU_MEMORY_AP_READ_WRITE)
53/* Scratch memory - Strongly ordered, non-executable */
Deepa Dinamani7e15e0b2013-02-07 13:05:38 -080054#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL | \
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -070055 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
56/* Peripherals - shared device */
57#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
58 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
59
Sundarajan Srinivasan950dedc2013-08-08 12:36:43 -070060#define SCRATCH_REGION1_VIRT_START SCRATCH_REGION1
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -070061#define SCRATCH_REGION2_VIRT_START (SCRATCH_REGION1_VIRT_START + \
62 (SCRATCH_REGION1_SIZE))
63
64#define SDRAM_BANK0_LAST_FIXED_ADDR (SCRATCH_REGION2 + SCRATCH_REGION2_SIZE)
65
66/* Map all the accesssible memory according to the following rules:
67 * 1. Map 1MB from MSM_SHARED_BASE with 1 -1 mapping.
68 * 2. Map MEMBASE - MEMSIZE with 1 -1 mapping.
69 * 3. Map all the scratch regions immediately after Appsbl memory.
70 * Virtual addresses start right after Appsbl Virtual address.
71 * 4. Map all the IOMAP space with 1 - 1 mapping.
72 * 5. Map all the rest of the SDRAM/ IMEM regions as 1 -1.
73 */
74mmu_section_t mmu_section_table[] = {
75/* Physical addr, Virtual addr, Size (in MB), Flags */
76 {MSM_SHARED_BASE, MSM_SHARED_BASE, 1, SCRATCH_MEMORY},
77 {MEMBASE, MEMBASE, MEMSIZE / MB, LK_MEMORY},
78 {SCRATCH_REGION1, SCRATCH_REGION1_VIRT_START, SCRATCH_REGION1_SIZE / MB, SCRATCH_MEMORY},
79 {SCRATCH_REGION2, SCRATCH_REGION2_VIRT_START, SCRATCH_REGION2_SIZE / MB, SCRATCH_MEMORY},
80 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
81};
Amol Jadi42d7b5a2012-05-04 14:50:32 -070082
Amol Jadifd507d52013-03-18 15:17:36 -070083/* Boot timestamps */
84#define BS_INFO_OFFSET (0x6B0)
85#define BS_INFO_ADDR_V1 (MSM_SHARED_IMEM_BASE + BS_INFO_OFFSET)
86#define BS_INFO_ADDR_V2 (MSM_SHARED_IMEM_BASE_V2 + BS_INFO_OFFSET)
87
Amol Jadi42d7b5a2012-05-04 14:50:32 -070088void platform_early_init(void)
89{
90 /* Initialize board identifier data */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070091 board_init();
Amol Jadi42d7b5a2012-05-04 14:50:32 -070092
Amol Jadib726c3b2012-09-13 13:51:23 -070093 /* Initialize clock driver */
94 platform_clock_init();
95
Amol Jadi42d7b5a2012-05-04 14:50:32 -070096 /* Initialize interrupt controller */
97 qgic_init();
98
99 /* timer */
100 qtimer_init();
101}
102
103void platform_init(void)
104{
105 dprintf(INFO, "platform_init()\n");
106}
107
Sundarajan Srinivasan3907eb82013-06-11 11:54:38 -0700108uint32_t platform_get_sclk_count(void)
Amol Jadifd507d52013-03-18 15:17:36 -0700109{
110 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
111}
112
Sundarajan Srinivasan3907eb82013-06-11 11:54:38 -0700113addr_t get_bs_info_addr()
Amol Jadifd507d52013-03-18 15:17:36 -0700114{
Amol Jadifd507d52013-03-18 15:17:36 -0700115 uint32_t soc_ver = board_soc_version();
116
Amol Jadifd507d52013-03-18 15:17:36 -0700117 if (soc_ver < BOARD_SOC_VERSION2)
Sundarajan Srinivasan3907eb82013-06-11 11:54:38 -0700118 return ((addr_t)BS_INFO_ADDR_V1);
Amol Jadifd507d52013-03-18 15:17:36 -0700119 else
Sundarajan Srinivasan3907eb82013-06-11 11:54:38 -0700120 return ((addr_t)BS_INFO_ADDR_V2);
Amol Jadifd507d52013-03-18 15:17:36 -0700121
Amol Jadifd507d52013-03-18 15:17:36 -0700122}
123
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700124void platform_uninit(void)
125{
126 qtimer_uninit();
Deepa Dinamani87feab82012-10-04 14:28:05 -0700127 qpic_nand_uninit();
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700128}
Deepa Dinamani61e3a0c2012-10-19 14:33:37 -0700129
130void platform_init_mmu_mappings(void)
131{
132 struct smem_ram_ptable *ram_ptable;
133 uint32_t i;
134 uint32_t sections;
135 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
136 uint32_t last_fixed_addr = SDRAM_BANK0_LAST_FIXED_ADDR;
137
138 ram_ptable = target_smem_ram_ptable_init();
139
140 /* Configure the MMU page entries for SDRAM and IMEM memory read
141 from the smem ram table*/
142 for(i = 0; i < ram_ptable->len; i++)
143 {
144 if((ram_ptable->parts[i].category == IMEM) || (ram_ptable->parts[i].category == SDRAM))
145 {
146 /* First bank info is added according to the static table - mmu_section_table. */
147 if((ram_ptable->parts[i].start <= last_fixed_addr) &&
148 ((ram_ptable->parts[i].start + ram_ptable->parts[i].size) >= last_fixed_addr))
149 continue;
150
151 /* Check to ensure that start address is 1MB aligned */
152 ASSERT((ram_ptable->parts[i].start & 0xFFFFF) == 0);
153
154 sections = (ram_ptable->parts[i].size) / MB;
155
156 while(sections--)
157 {
158 arm_mmu_map_section(ram_ptable->parts[i].start + sections * MB,
159 ram_ptable->parts[i].start + sections * MB,
160 SCRATCH_MEMORY);
161 }
162 }
163 }
164
165 /* Configure the MMU page entries for memory read from the
166 mmu_section_table */
167 for (i = 0; i < table_size; i++)
168 {
169 sections = mmu_section_table[i].num_of_sections;
170
171 while (sections--)
172 {
173 arm_mmu_map_section(mmu_section_table[i].paddress + sections * MB,
174 mmu_section_table[i].vaddress + sections * MB,
175 mmu_section_table[i].flags);
176 }
177 }
178}
179
180addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
181{
182 uint32_t paddr;
183 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
184 uint32_t limit;
185
186 for (uint32_t i = 0; i < table_size; i++)
187 {
188 limit = (mmu_section_table[i].num_of_sections * MB) - 0x1;
189
190 if (virt_addr >= mmu_section_table[i].vaddress &&
191 virt_addr <= (mmu_section_table[i].vaddress + limit))
192 {
193 paddr = mmu_section_table[i].paddress + (virt_addr - mmu_section_table[i].vaddress);
194 return paddr;
195 }
196 }
197 /* No special mapping found.
198 * Assume 1-1 mapping.
199 */
200 paddr = virt_addr;
201
202 return paddr;
203}
204
205addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
206{
207 uint32_t vaddr;
208 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
209 uint32_t limit;
210
211 for (uint32_t i = 0; i < table_size; i++)
212 {
213 limit = (mmu_section_table[i].num_of_sections * MB) - 0x1;
214
215 if (phys_addr >= mmu_section_table[i].paddress &&
216 phys_addr <= (mmu_section_table[i].paddress + limit))
217 {
218 vaddr = mmu_section_table[i].vaddress + (phys_addr - mmu_section_table[i].paddress);
219 return vaddr;
220 }
221 }
222
223 /* No special mapping found.
224 * Assume 1-1 mapping.
225 */
226 vaddr = phys_addr;
227
228 return vaddr;
229}
230
231/* Do not use default identitiy mappings. */
232int platform_use_identity_mmu_mappings(void)
233{
234 return 0;
235}
236