blob: 3604205e7ae90b4750d5b9ed5bf9df0f949e3d18 [file] [log] [blame]
Sundarajan Srinivasan749d2602013-12-11 17:12:11 -08001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Sundarajan Srinivasan4bbce722013-07-03 11:13:31 -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.
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 <platform.h>
31#include <qgic.h>
32#include <qtimer.h>
33#include <board.h>
34#include <mmu.h>
35#include <arch/arm/mmu.h>
36#include <platform/iomap.h>
37#include <smem.h>
38#include <reg.h>
39#include <board.h>
40#include <qpic_nand.h>
41#include <target.h>
42
43extern struct smem_ram_ptable* target_smem_ram_ptable_init();
44
45#define MB (1024*1024)
46
47#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
48
49/* LK memory - Strongly ordered, executable */
50#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL | \
51 MMU_MEMORY_AP_READ_WRITE)
52/* Scratch memory - Strongly ordered, non-executable */
53#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL | \
54 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
55/* Peripherals - shared device */
56#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
57 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
58
Sundarajan Srinivasan5278e762013-11-19 14:03:58 -080059#define SCRATCH_REGION1_VIRT_START SCRATCH_REGION1
60#define SCRATCH_REGION2_VIRT_START SCRATCH_REGION2
Sundarajan Srinivasan4bbce722013-07-03 11:13:31 -070061
62#define SDRAM_BANK0_LAST_FIXED_ADDR (SCRATCH_REGION2 + SCRATCH_REGION2_SIZE)
63
64/* Map all the accesssible memory according to the following rules:
65 * 1. Map 1MB from MSM_SHARED_BASE with 1 -1 mapping.
66 * 2. Map MEMBASE - MEMSIZE with 1 -1 mapping.
67 * 3. Map all the scratch regions immediately after Appsbl memory.
68 * Virtual addresses start right after Appsbl Virtual address.
69 * 4. Map all the IOMAP space with 1 - 1 mapping.
70 * 5. Map all the rest of the SDRAM/ IMEM regions as 1 -1.
71 */
72mmu_section_t mmu_section_table[] = {
73/* Physical addr, Virtual addr, Size (in MB), Flags */
74 {MSM_SHARED_BASE, MSM_SHARED_BASE, 1, SCRATCH_MEMORY},
75 {MEMBASE, MEMBASE, MEMSIZE / MB, LK_MEMORY},
76 {SCRATCH_REGION1, SCRATCH_REGION1_VIRT_START, SCRATCH_REGION1_SIZE / MB, SCRATCH_MEMORY},
77 {SCRATCH_REGION2, SCRATCH_REGION2_VIRT_START, SCRATCH_REGION2_SIZE / MB, SCRATCH_MEMORY},
78 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
79};
80
81void platform_early_init(void)
82{
83 /* Initialize board identifier data */
84 board_init();
85
86 /* Initialize clock driver */
87 platform_clock_init();
88
89 /* Initialize interrupt controller */
90 qgic_init();
91
92 /* timer */
93 qtimer_init();
94}
95
96void platform_init(void)
97{
98 dprintf(INFO, "platform_init()\n");
99}
100
101void platform_uninit(void)
102{
103 qtimer_uninit();
104 qpic_nand_uninit();
105}
106
107/* Do not use default identitiy mappings. */
108int platform_use_identity_mmu_mappings(void)
109{
110 return 0;
111}
112
Sundarajan Srinivasan749d2602013-12-11 17:12:11 -0800113uint32_t platform_get_sclk_count(void)
114{
115 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
116}
117
118addr_t get_bs_info_addr()
119{
120 return ((addr_t)BS_INFO_ADDR);
121}
122
Sundarajan Srinivasan4bbce722013-07-03 11:13:31 -0700123void platform_init_mmu_mappings(void)
124{
125 struct smem_ram_ptable *ram_ptable;
126 uint32_t i;
127 uint32_t sections;
128 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
129 uint32_t last_fixed_addr = SDRAM_BANK0_LAST_FIXED_ADDR;
130
131 ram_ptable = target_smem_ram_ptable_init();
132
133 /* Configure the MMU page entries for SDRAM and IMEM memory read
134 from the smem ram table*/
135 for(i = 0; i < ram_ptable->len; i++)
136 {
137 if((ram_ptable->parts[i].category == IMEM) || (ram_ptable->parts[i].category == SDRAM))
138 {
139 /* First bank info is added according to the static table - mmu_section_table. */
140 if((ram_ptable->parts[i].start <= last_fixed_addr) &&
141 ((ram_ptable->parts[i].start + ram_ptable->parts[i].size) >= last_fixed_addr))
142 continue;
143
144 /* Check to ensure that start address is 1MB aligned */
145 ASSERT((ram_ptable->parts[i].start & 0xFFFFF) == 0);
146
147 sections = (ram_ptable->parts[i].size) / MB;
148
149 while(sections--)
150 {
151 arm_mmu_map_section(ram_ptable->parts[i].start + sections * MB,
152 ram_ptable->parts[i].start + sections * MB,
153 SCRATCH_MEMORY);
154 }
155 }
156 }
157
158 /* Configure the MMU page entries for memory read from the
159 mmu_section_table */
160 for (i = 0; i < table_size; i++)
161 {
162 sections = mmu_section_table[i].num_of_sections;
163
164 while (sections--)
165 {
166 arm_mmu_map_section(mmu_section_table[i].paddress + sections * MB,
167 mmu_section_table[i].vaddress + sections * MB,
168 mmu_section_table[i].flags);
169 }
170 }
171}
172
173addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
174{
175 uint32_t paddr;
176 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
177 uint32_t limit;
178
179 for (uint32_t i = 0; i < table_size; i++)
180 {
181 limit = (mmu_section_table[i].num_of_sections * MB) - 0x1;
182
183 if (virt_addr >= mmu_section_table[i].vaddress &&
184 virt_addr <= (mmu_section_table[i].vaddress + limit))
185 {
186 paddr = mmu_section_table[i].paddress + (virt_addr - mmu_section_table[i].vaddress);
187 return paddr;
188 }
189 }
190 /* No special mapping found.
191 * Assume 1-1 mapping.
192 */
193 paddr = virt_addr;
194 return paddr;
195}
196
197addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
198{
199 uint32_t vaddr;
200 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
201 uint32_t limit;
202
203 for (uint32_t i = 0; i < table_size; i++)
204 {
205 limit = (mmu_section_table[i].num_of_sections * MB) - 0x1;
206
207 if (phys_addr >= mmu_section_table[i].paddress &&
208 phys_addr <= (mmu_section_table[i].paddress + limit))
209 {
210 vaddr = mmu_section_table[i].vaddress + (phys_addr - mmu_section_table[i].paddress);
211 return vaddr;
212 }
213 }
214
215 /* No special mapping found.
216 * Assume 1-1 mapping.
217 */
218 vaddr = phys_addr;
219
220 return vaddr;
221}