blob: 464863853e28475f1533352ce6a4f83c90e1c196 [file] [log] [blame]
Aparna Mallavarapuca676882015-01-19 20:39:06 +05301/* Copyright (c) 2015, 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 "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF 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 <mmu.h>
35#include <arch/arm/mmu.h>
36#include <smem.h>
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053037#include <board.h>
38
39#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
40#define APPS_SS_SIZE ((APPS_SS_END - APPS_SS_BASE)/MB)
41
42/* LK memory - cacheable, write through */
43#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
44 MMU_MEMORY_AP_READ_WRITE)
45
46/* Peripherals - non-shared device */
47#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
48 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
49
50/* IMEM memory - cacheable, write through */
51#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
52 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
53
54#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
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 { APPS_SS_BASE, APPS_SS_BASE, APPS_SS_SIZE, IOMAP_MEMORY},
62 { MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, COMMON_MEMORY},
63 { SCRATCH_ADDR, SCRATCH_ADDR, 256, SCRATCH_MEMORY},
64};
Aparna Mallavarapuca676882015-01-19 20:39:06 +053065
66void platform_early_init(void)
67{
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053068 board_init();
Aparna Mallavarapuca676882015-01-19 20:39:06 +053069 qgic_init();
70 qtimer_init();
71 scm_init();
72}
73
74void platform_init(void)
75{
76 dprintf(INFO, "platform_init()\n");
77}
78
79void platform_uninit(void)
80{
81 qtimer_uninit();
82}
83
84uint32_t platform_get_sclk_count(void)
85{
86 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
87}
88
89addr_t get_bs_info_addr()
90{
91 return ((addr_t)BS_INFO_ADDR);
92}
93
94int platform_use_identity_mmu_mappings(void)
95{
96 /* Use only the mappings specified in this file. */
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053097 return 0;
98}
99
100/* Setup MMU mapping for this platform */
101void platform_init_mmu_mappings(void)
102{
103 uint32_t i;
104 uint32_t sections;
105 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
106 uint32_t ddr_start = get_ddr_start();
107 uint32_t smem_addr = platform_get_smem_base_addr();
108
109 /*Mapping the ddr start address for loading the kernel about 90 MB*/
110 sections = 90;
111 while(sections--)
112 {
113 arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, COMMON_MEMORY);
114 }
115
116
117 /* Mapping the SMEM addr */
118 arm_mmu_map_section(smem_addr, smem_addr, COMMON_MEMORY);
119
120 /* Configure the MMU page entries for memory read from the
121 mmu_section_table */
122 for (i = 0; i < table_size; i++)
123 {
124 sections = mmu_section_table[i].num_of_sections;
125
126 while (sections--)
127 {
128 arm_mmu_map_section(mmu_section_table[i].paddress +
129 sections * MB,
130 mmu_section_table[i].vaddress +
131 sections * MB,
132 mmu_section_table[i].flags);
133 }
134 }
135}
136
137addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
138{
139 /* Using 1-1 mapping on this platform. */
140 return virt_addr;
141}
142
143addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
144{
145 /* Using 1-1 mapping on this platform. */
146 return phys_addr;
147}
148
149/* DYNAMIC SMEM REGION feature enables LK to dynamically
150 * read the SMEM addr info from TCSR_TZ_WONCE register.
151 * The first word read, if indicates a MAGIC number, then
152 * Dynamic SMEM is assumed to be enabled. Read the remaining
153 * SMEM info for SMEM Size and Phy_addr from the other bytes.
154 */
155uint32_t platform_get_smem_base_addr()
156{
157 struct smem_addr_info *smem_info = NULL;
158
159 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
160 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
161 return smem_info->phy_addr;
162 else
163 return MSM_SHARED_BASE;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530164}