blob: 26dee27011f1774515f4e231a2ecfb91ae8e1c67 [file] [log] [blame]
Jayant Shekharbd6a5162016-01-19 12:50:49 +05301/* Copyright (c) 2015-2016, 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 */
48#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
49 MMU_MEMORY_AP_READ_WRITE)
50
51/* Peripherals - non-shared device */
52#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
53 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
54
55/* IMEM memory - cacheable, write through */
56#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
57 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
58
59#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
60 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
61
62static mmu_section_t mmu_section_table[] = {
63/* Physical addr, Virtual addr, Size (in MB), Flags */
64 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
65 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
66 { APPS_SS_BASE, APPS_SS_BASE, APPS_SS_SIZE, IOMAP_MEMORY},
67 { MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, COMMON_MEMORY},
68 { SCRATCH_ADDR, SCRATCH_ADDR, 512, SCRATCH_MEMORY},
Jayant Shekharbd6a5162016-01-19 12:50:49 +053069 { MIPI_FB_ADDR, MIPI_FB_ADDR, 20, COMMON_MEMORY},
P.V. Phani Kumar9451ebe2015-12-26 16:31:18 +053070 { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY},
P.V. Phani Kumara053a322015-08-13 18:36:05 +053071};
72
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053073void platform_early_init(void)
74{
P.V. Phani Kumar40fa1352015-08-13 18:15:03 +053075 board_init();
76 platform_clock_init();
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053077 qgic_init();
78 qtimer_init();
79 scm_init();
80}
81
82void platform_init(void)
83{
84 dprintf(INFO, "platform_init()\n");
85}
86
87void platform_uninit(void)
88{
89 qtimer_uninit();
90}
91
92uint32_t platform_get_sclk_count(void)
93{
94 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
95}
96
97addr_t get_bs_info_addr()
98{
99 return ((addr_t)BS_INFO_ADDR);
100}
101
102int platform_use_identity_mmu_mappings(void)
103{
104 /* Use only the mappings specified in this file. */
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530105 return 0;
106}
107
108/* Setup MMU mapping for this platform */
109void platform_init_mmu_mappings(void)
110{
111 uint32_t i;
112 uint32_t sections;
113 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
lijuang6e6aec52016-01-14 15:37:55 +0800114 uint32_t ddr_start = DDR_START;
P.V. Phani Kumara053a322015-08-13 18:36:05 +0530115 uint32_t smem_addr = platform_get_smem_base_addr();
116
117 /*Mapping the ddr start address for loading the kernel about 90 MB*/
118 sections = 90;
119 while(sections--)
120 {
121 arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, COMMON_MEMORY);
122 }
123
124
125 /* Mapping the SMEM addr */
126 arm_mmu_map_section(smem_addr, smem_addr, COMMON_MEMORY);
127
128 /* Configure the MMU page entries for memory read from the
129 mmu_section_table */
130 for (i = 0; i < table_size; i++)
131 {
132 sections = mmu_section_table[i].num_of_sections;
133
134 while (sections--)
135 {
136 arm_mmu_map_section(mmu_section_table[i].paddress +
137 sections * MB,
138 mmu_section_table[i].vaddress +
139 sections * MB,
140 mmu_section_table[i].flags);
141 }
142 }
143}
144
145addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
146{
147 /* Using 1-1 mapping on this platform. */
148 return virt_addr;
149}
150
151addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
152{
153 /* Using 1-1 mapping on this platform. */
154 return phys_addr;
155}
156
157/* DYNAMIC SMEM REGION feature enables LK to dynamically
158 * read the SMEM addr info from TCSR_TZ_WONCE register.
159 * The first word read, if indicates a MAGIC number, then
160 * Dynamic SMEM is assumed to be enabled. Read the remaining
161 * SMEM info for SMEM Size and Phy_addr from the other bytes.
162 */
163uint32_t platform_get_smem_base_addr()
164{
165 struct smem_addr_info *smem_info = NULL;
166
167 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
168 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
169 return smem_info->phy_addr;
170 else
171 return MSM_SHARED_BASE;
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +0530172}
P.V. Phani Kumar9451ebe2015-12-26 16:31:18 +0530173
174uint32_t platform_get_qmp_rev()
175{
176 return readl(USB3_PHY_REVISION_ID3) << 24 | readl(USB3_PHY_REVISION_ID2) << 16 |
177 readl(USB3_PHY_REVISION_ID1) << 8 | readl(USB3_PHY_REVISION_ID0);
178}