blob: 96b5dc5e74a04d1428072c903cc7c75b728f7c3d [file] [log] [blame]
Joonwoo Park451dca32014-04-02 11:47:03 -07001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
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 <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_WRITE_THROUGH | \
51 MMU_MEMORY_AP_READ_WRITE)
52/* Scratch memory - Strongly ordered, non-executable */
Channagoud Kadabi1b69e482014-09-23 15:20:22 -070053#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
Joonwoo Park451dca32014-04-02 11:47:03 -070054 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
Joonwoo Park451dca32014-04-02 11:47:03 -070059/* Map all the accesssible memory according to the following rules:
60 * 1. Map 1MB from MSM_SHARED_BASE with 1 -1 mapping.
61 * 2. Map MEMBASE - MEMSIZE with 1 -1 mapping.
62 * 3. Map all the scratch regions immediately after Appsbl memory.
63 * Virtual addresses start right after Appsbl Virtual address.
64 * 4. Map all the IOMAP space with 1 - 1 mapping.
65 * 5. Map all the rest of the SDRAM/ IMEM regions as 1 -1.
66 */
67mmu_section_t mmu_section_table[] = {
68/* Physical addr, Virtual addr, Size (in MB), Flags */
69 {MSM_SHARED_BASE, MSM_SHARED_BASE, 1, SCRATCH_MEMORY},
70 {MEMBASE, MEMBASE, MEMSIZE / MB, LK_MEMORY},
71 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
Channagoud Kadabi1b69e482014-09-23 15:20:22 -070072 {SCRATCH_REGION1, SCRATCH_REGION1, SCRATCH_REGION1_SIZE / MB, SCRATCH_MEMORY},
73 {SCRATCH_REGION2, SCRATCH_REGION2, SCRATCH_REGION2_SIZE / MB, SCRATCH_MEMORY},
74 {KERNEL_REGION, KERNEL_REGION, KERNEL_REGION_SIZE / MB, SCRATCH_MEMORY},
Joonwoo Park451dca32014-04-02 11:47:03 -070075};
76
77void platform_early_init(void)
78{
79 /* Initialize board identifier data */
80 board_init();
81
82 /* Initialize clock driver */
83 platform_clock_init();
84
85 /* Initialize interrupt controller */
86 qgic_init();
87
88 /* timer */
89 qtimer_init();
90}
91
92void platform_init(void)
93{
94 dprintf(INFO, "platform_init()\n");
95}
96
97void platform_uninit(void)
98{
99 qtimer_uninit();
100 if (!platform_boot_dev_isemmc())
101 qpic_nand_uninit();
102}
103
104/* Do not use default identitiy mappings. */
105int platform_use_identity_mmu_mappings(void)
106{
107 return 0;
108}
109
110uint32_t platform_get_sclk_count(void)
111{
112 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
113}
114
115addr_t get_bs_info_addr()
116{
117 return ((addr_t)BS_INFO_ADDR);
118}
119
120/* Setup memory for this platform */
121void platform_init_mmu_mappings(void)
122{
123 uint32_t i;
124 uint32_t sections;
Joonwoo Park451dca32014-04-02 11:47:03 -0700125 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
Joonwoo Park451dca32014-04-02 11:47:03 -0700126
127 /* Configure the MMU page entries for memory read from the
128 mmu_section_table */
129 for (i = 0; i < table_size; i++)
130 {
131 sections = mmu_section_table[i].num_of_sections;
132
133 while (sections--)
134 {
135 arm_mmu_map_section(mmu_section_table[i].paddress +
136 sections * MB,
137 mmu_section_table[i].vaddress +
138 sections * MB,
139 mmu_section_table[i].flags);
140 }
141 }
142}
143
144addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
145{
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700146 /* Fixed 1-1 mapping */
147 return virt_addr;
Joonwoo Park451dca32014-04-02 11:47:03 -0700148}
149
150addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
151{
Channagoud Kadabi1b69e482014-09-23 15:20:22 -0700152 /* Fixed 1-1 mapping */
153 return phys_addr;
Joonwoo Park451dca32014-04-02 11:47:03 -0700154}