blob: c30f60bb0fb0842903723f99315d867069b59289 [file] [log] [blame]
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +05301/* Copyright (c) 2013, 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 <reg.h>
31#include <platform/iomap.h>
32#include <qgic.h>
33#include <qtimer.h>
34#include <platform/clock.h>
35#include <mmu.h>
36#include <arch/arm/mmu.h>
37#include <smem.h>
38#include <board.h>
39#include <boot_stats.h>
40
41#define MB (1024*1024)
42
43#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
44
45/* LK memory - cacheable, write through */
46#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
47 MMU_MEMORY_AP_READ_WRITE)
48
49/* Peripherals - non-shared device */
50#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
51 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
52
53/* IMEM memory - cacheable, write through */
54#define IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
55 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
56
57static mmu_section_t mmu_section_table[] = {
58/* Physical addr, Virtual addr, Size (in MB), Flags */
59 {MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
60 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
61 /* IMEM needs a seperate entry in the table as it's length is only 0x8000. */
62 {SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY},
63};
64
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +053065/* Boot timestamps */
66#define BS_INFO_OFFSET (0x6B0)
67#define BS_INFO_ADDR_V1 (RPM_MSG_RAM_BASE + BS_INFO_OFFSET)
68#define BS_INFO_ADDR_V2 (MSM_SHARED_IMEM_BASE + BS_INFO_OFFSET)
69
70void platform_early_init(void)
71{
72 board_init();
73 platform_clock_init();
74 qgic_init();
75 qtimer_init();
76}
77
78void platform_init(void)
79{
80 dprintf(INFO, "platform_init()\n");
81}
82
83uint32_t platform_get_sclk_count(void)
84{
85 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
86}
87
88addr_t get_bs_info_addr()
89{
90 uint32_t soc_ver = board_soc_version();
91
92 if (soc_ver < BOARD_SOC_VERSION2)
93 return ((addr_t)BS_INFO_ADDR_V1);
94 else
95 return ((addr_t)BS_INFO_ADDR_V2);
96
97}
98
99void platform_uninit(void)
100{
101 qtimer_uninit();
102}
103
104int platform_use_identity_mmu_mappings(void)
105{
106 /* Use only the mappings specified in this file. */
107 return 0;
108}
109
110addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
111{
112 /* Return same address as we are using 1-1 mapping. */
113 return virt_addr;
114}
115
116addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
117{
118 /* Return same address as we are using 1-1 mapping. */
119 return phys_addr;
120}
121
122
123/* Setup memory for this platform */
124void platform_init_mmu_mappings(void)
125{
126 uint32_t i;
127 uint32_t sections;
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530128 ram_partition ptn_entry;
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530129 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530130 uint32_t len = 0;
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530131
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530132 ASSERT(smem_ram_ptable_init_v1());
133
134 len = smem_get_ram_ptable_len();
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530135
136 /* Configure the MMU page entries for SDRAM and IMEM memory read
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530137 from the smem ram table */
138 for (i = 0; i < len; i++)
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530139 {
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530140 smem_get_ram_ptable_entry(&ptn_entry, i);
141 if ((ptn_entry.type == SYS_MEMORY) &&
142 ((ptn_entry.category == SDRAM) ||
143 (ptn_entry.category == IMEM)))
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530144 {
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530145 /* Check to ensure that start address is 1MB aligned */
146 ASSERT((ptn_entry.start & (MB-1)) == 0);
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530147
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530148 sections = ptn_entry.size / MB;
149 while(sections--)
150 {
151 arm_mmu_map_section(
152 (ptn_entry.start + sections * MB),
153 (ptn_entry.start + sections * MB),
154 (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH |
155 MMU_MEMORY_AP_READ_WRITE |
156 MMU_MEMORY_XN));
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530157 }
158 }
159 }
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530160
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530161 /* Configure the MMU page entries for memory read from the
162 mmu_section_table */
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530163 for (i = 0; i < table_size; i++)
164 {
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530165 sections = mmu_section_table[i].num_of_sections;
166
V S Ramanjaneya Kumar T0bc5a2b2013-10-11 16:01:03 +0530167 while (sections--)
168 {
V S Ramanjaneya Kumar T713be572013-08-02 11:00:10 +0530169 arm_mmu_map_section(mmu_section_table[i].paddress +
170 sections * MB,
171 mmu_section_table[i].vaddress +
172 sections * MB,
173 mmu_section_table[i].flags);
174 }
175 }
176}