blob: 87d45f3636478c2c6dcf8d21932609557a5d9566 [file] [log] [blame]
Mayank Groverdc6da172018-04-17 15:10:31 +05301/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +05302 *
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>
P.V. Phani Kumar40fa1352015-08-13 18:15:03 +053032#include <platform/irqs.h>
33#include <platform/clock.h>
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053034#include <qgic.h>
35#include <qtimer.h>
36#include <mmu.h>
37#include <arch/arm/mmu.h>
38#include <smem.h>
P.V. Phani Kumar40fa1352015-08-13 18:15:03 +053039#include <board.h>
40#include <boot_stats.h>
41#include <platform.h>
Jayant Shekharbd6a5162016-01-19 12:50:49 +053042#include <target/display.h>
P.V. Phani Kumara053a322015-08-13 18:36:05 +053043
44#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
45#define APPS_SS_SIZE ((APPS_SS_END - APPS_SS_BASE)/MB)
46
47/* LK memory - cacheable, write through */
Mayank Groverdc6da172018-04-17 15:10:31 +053048#ifdef SECURE_CODE_MEM
49#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
50 MMU_MEMORY_AP_READ_ONLY |\
51 MMU_MEMORY_APX_READ_ONLY)
52
53#define LK_MEMORY_RW (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
54 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
55#else
P.V. Phani Kumara053a322015-08-13 18:36:05 +053056#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
57 MMU_MEMORY_AP_READ_WRITE)
Mayank Groverdc6da172018-04-17 15:10:31 +053058#endif
P.V. Phani Kumara053a322015-08-13 18:36:05 +053059/* Peripherals - non-shared device */
60#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
61 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
62
63/* IMEM memory - cacheable, write through */
64#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
65 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
66
67#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
68 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
69
70static mmu_section_t mmu_section_table[] = {
71/* Physical addr, Virtual addr, Size (in MB), Flags */
Mayank Groverdc6da172018-04-17 15:10:31 +053072#ifdef SECURE_CODE_MEM
73 { MEMBASE, MEMBASE, 1, LK_MEMORY},
74 { MEMRWOFF, MEMRWOFF, (MEMSIZE / MB) - 1, LK_MEMORY_RW},
75#else
P.V. Phani Kumara053a322015-08-13 18:36:05 +053076 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
Mayank Groverdc6da172018-04-17 15:10:31 +053077#endif
P.V. Phani Kumara053a322015-08-13 18:36:05 +053078 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
79 { APPS_SS_BASE, APPS_SS_BASE, APPS_SS_SIZE, IOMAP_MEMORY},
80 { MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, COMMON_MEMORY},
Mayank Grover35617eb2018-01-11 17:18:29 +053081 { SCRATCH_ADDR, SCRATCH_ADDR, SCRATCH_SIZE, SCRATCH_MEMORY},
Jayant Shekharbd6a5162016-01-19 12:50:49 +053082 { MIPI_FB_ADDR, MIPI_FB_ADDR, 20, COMMON_MEMORY},
P.V. Phani Kumar9451ebe2015-12-26 16:31:18 +053083 { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY},
P.V. Phani Kumara053a322015-08-13 18:36:05 +053084};
85
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053086void platform_early_init(void)
87{
P.V. Phani Kumar40fa1352015-08-13 18:15:03 +053088 board_init();
89 platform_clock_init();
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053090 qgic_init();
91 qtimer_init();
92 scm_init();
93}
94
95void platform_init(void)
96{
97 dprintf(INFO, "platform_init()\n");
98}
99
100void platform_uninit(void)
101{
102 qtimer_uninit();
103}
104
105uint32_t platform_get_sclk_count(void)
106{
107 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
108}
109
110addr_t get_bs_info_addr()
111{
112 return ((addr_t)BS_INFO_ADDR);
113}
114
115int platform_use_identity_mmu_mappings(void)
116{
117 /* Use only the mappings specified in this file. */
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530118 return 0;
119}
120
121/* Setup MMU mapping for this platform */
122void platform_init_mmu_mappings(void)
123{
124 uint32_t i;
125 uint32_t sections;
126 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
lijuang6e6aec52016-01-14 15:37:55 +0800127 uint32_t ddr_start = DDR_START;
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530128 uint32_t smem_addr = platform_get_smem_base_addr();
129
130 /*Mapping the ddr start address for loading the kernel about 90 MB*/
131 sections = 90;
132 while(sections--)
133 {
134 arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, COMMON_MEMORY);
135 }
136
137
138 /* Mapping the SMEM addr */
139 arm_mmu_map_section(smem_addr, smem_addr, COMMON_MEMORY);
140
141 /* Configure the MMU page entries for memory read from the
142 mmu_section_table */
143 for (i = 0; i < table_size; i++)
144 {
145 sections = mmu_section_table[i].num_of_sections;
146
147 while (sections--)
148 {
149 arm_mmu_map_section(mmu_section_table[i].paddress +
150 sections * MB,
151 mmu_section_table[i].vaddress +
152 sections * MB,
153 mmu_section_table[i].flags);
154 }
155 }
156}
157
158addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
159{
160 /* Using 1-1 mapping on this platform. */
161 return virt_addr;
162}
163
164addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
165{
166 /* Using 1-1 mapping on this platform. */
167 return phys_addr;
168}
169
Wufengc1c91ee2016-04-15 19:11:36 +0800170uint32_t platform_get_max_periph()
171{
172 return 256;
173}
174
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530175/* DYNAMIC SMEM REGION feature enables LK to dynamically
176 * read the SMEM addr info from TCSR_TZ_WONCE register.
177 * The first word read, if indicates a MAGIC number, then
178 * Dynamic SMEM is assumed to be enabled. Read the remaining
179 * SMEM info for SMEM Size and Phy_addr from the other bytes.
180 */
181uint32_t platform_get_smem_base_addr()
182{
183 struct smem_addr_info *smem_info = NULL;
184
185 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
186 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
187 return smem_info->phy_addr;
188 else
189 return MSM_SHARED_BASE;
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530190}
P.V. Phani Kumar9451ebe2015-12-26 16:31:18 +0530191
Gaurav Nebhwani4157b052016-03-09 15:45:55 +0530192int platform_is_msm8953()
193{
194 uint32_t platform = board_platform_id();
195
Mayank Grover60ee8b82017-12-26 12:46:14 +0530196 switch (platform)
197 {
198 case MSM8953:
199 case APQ8053:
200 case SDM450:
201 case SDA450:
lijuang199f97d2018-01-02 10:11:59 +0800202 case SDM632:
203 case SDA632:
Mayank Grover60ee8b82017-12-26 12:46:14 +0530204 return 1;
205 break;
206 default:
207 return 0;
208 }
Gaurav Nebhwani4157b052016-03-09 15:45:55 +0530209}
210
P.V. Phani Kumar9451ebe2015-12-26 16:31:18 +0530211uint32_t platform_get_qmp_rev()
212{
213 return readl(USB3_PHY_REVISION_ID3) << 24 | readl(USB3_PHY_REVISION_ID2) << 16 |
214 readl(USB3_PHY_REVISION_ID1) << 8 | readl(USB3_PHY_REVISION_ID0);
215}