blob: 700327504cb62f3b737f2320e53d1649e8bd8a7c [file] [log] [blame]
Mayank Grover7e351832017-04-21 15:03:58 +05301/* Copyright (c) 2014-2015, 2017, The Linux Foundation. All rights reserved.
Unnati Gandhib3820bc2014-07-04 16:56:27 +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>
32#include <qgic.h>
33#include <qtimer.h>
34#include <mmu.h>
35#include <arch/arm/mmu.h>
36#include <smem.h>
Unnati Gandhiabb73ec2015-06-23 13:07:36 +053037#include <target/display.h>
Unnati Gandhib3820bc2014-07-04 16:56:27 +053038
Unnati Gandhif4cb6622014-08-28 13:54:56 +053039#define MB (1024*1024)
40
41#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
42#define A7_SS_SIZE ((A7_SS_END - A7_SS_BASE)/MB)
43
Matthew Qinfab78c32015-04-28 03:05:24 -040044/* LK memory - cacheable, write back */
45#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
Unnati Gandhif4cb6622014-08-28 13:54:56 +053046 MMU_MEMORY_AP_READ_WRITE)
47
Matthew Qinfab78c32015-04-28 03:05:24 -040048
49#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
50 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
51
Unnati Gandhif4cb6622014-08-28 13:54:56 +053052/* Peripherals - non-shared device */
53#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
54 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
55
56/* IMEM memory - cacheable, write through */
57#define IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
58 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
59
60static mmu_section_t mmu_section_table[] = {
61/* Physical addr, Virtual addr, Size (in MB), Flags */
62 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
63 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
64 { A7_SS_BASE, A7_SS_BASE, A7_SS_SIZE, IOMAP_MEMORY},
65 { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY},
Matthew Qinfab78c32015-04-28 03:05:24 -040066 { MSM_SHARED_BASE, MSM_SHARED_BASE, 1, COMMON_MEMORY},
Unnati Gandhiabb73ec2015-06-23 13:07:36 +053067 { MIPI_FB_ADDR, MIPI_FB_ADDR, 10, COMMON_MEMORY},
Mayank Grover7e351832017-04-21 15:03:58 +053068 { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY},
Unnati Gandhif4cb6622014-08-28 13:54:56 +053069};
70
71static struct smem_ram_ptable ram_ptable;
72
Unnati Gandhib3820bc2014-07-04 16:56:27 +053073void platform_early_init(void)
74{
Unnati Gandhia556a4d2014-08-12 10:42:21 +053075 board_init();
Unnati Gandhif4cb6622014-08-28 13:54:56 +053076 platform_clock_init();
Unnati Gandhib3820bc2014-07-04 16:56:27 +053077 qgic_init();
78 qtimer_init();
79}
80
81void platform_init(void)
82{
83 dprintf(INFO, "platform_init()\n");
84}
85
86void platform_uninit(void)
87{
88 qtimer_uninit();
Unnati Gandhic43a2802014-09-19 17:27:25 +053089 if (!platform_boot_dev_isemmc())
90 qpic_nand_uninit();
Unnati Gandhib3820bc2014-07-04 16:56:27 +053091}
Unnati Gandhif4cb6622014-08-28 13:54:56 +053092
93uint32_t platform_get_sclk_count(void)
94{
95 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
96}
97
98addr_t get_bs_info_addr()
99{
100 return ((addr_t)BS_INFO_ADDR);
101}
102
103int platform_use_identity_mmu_mappings(void)
104{
105 /* Use only the mappings specified in this file. */
106 return 0;
107}
108
109/* Setup memory for this platform */
110void platform_init_mmu_mappings(void)
111{
112 uint32_t i;
113 uint32_t sections;
114 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
115 ram_partition ptn_entry;
116 uint32_t len = 0;
117
118 ASSERT(smem_ram_ptable_init_v1());
119
120 len = smem_get_ram_ptable_len();
121
122 /* Configure the MMU page entries for SDRAM and IMEM memory read
123 from the smem ram table*/
124 for(i = 0; i < len; i++)
125 {
126 smem_get_ram_ptable_entry(&ptn_entry, i);
127 if(ptn_entry.type == SYS_MEMORY)
128 {
129 if((ptn_entry.category == SDRAM) ||
130 (ptn_entry.category == IMEM))
131 {
132 /* Check to ensure that start address is 1MB aligned */
133 ASSERT((ptn_entry.start & (MB-1)) == 0);
134
135 sections = (ptn_entry.size) / MB;
136 while(sections--)
137 {
138 arm_mmu_map_section(ptn_entry.start +
139 sections * MB,
140 ptn_entry.start +
141 sections * MB,
Matthew Qinfab78c32015-04-28 03:05:24 -0400142 (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530143 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
144 }
145 }
146 }
147 }
148
149 /* Configure the MMU page entries for memory read from the
150 mmu_section_table */
151 for (i = 0; i < table_size; i++)
152 {
153 sections = mmu_section_table[i].num_of_sections;
154
155 while (sections--)
156 {
157 arm_mmu_map_section(mmu_section_table[i].paddress +
158 sections * MB,
159 mmu_section_table[i].vaddress +
160 sections * MB,
161 mmu_section_table[i].flags);
162 }
163 }
164}
165
166addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
167{
168 /* Using 1-1 mapping on this platform. */
169 return virt_addr;
170}
171
172addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
173{
174 /* Using 1-1 mapping on this platform. */
175 return phys_addr;
176}
177
178/* DYNAMIC SMEM REGION feature enables LK to dynamically
179 * read the SMEM addr info from TCSR_TZ_WONCE register.
180 * The first word read, if indicates a MAGIC number, then
181 * Dynamic SMEM is assumed to be enabled. Read the remaining
182 * SMEM info for SMEM Size and Phy_addr from the other bytes.
183 */
184uint32_t platform_get_smem_base_addr()
185{
186 struct smem_addr_info *smem_info = NULL;
187
188 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
189 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
190 return smem_info->phy_addr;
191 else
192 return MSM_SHARED_BASE;
193}
194
Unnati Gandhi6c92a4f2014-11-18 18:01:51 +0530195int platform_is_msm8909()
196{
197 uint32_t platform = board_platform_id();
198 uint32_t ret = 0;
199
200 switch(platform)
201 {
202 case MSM8909:
203 case MSM8209:
204 case MSM8208:
205 case APQ8009:
Unnati Gandhi917c8612015-02-06 16:50:32 +0530206 case MSM8609:
Unnati Gandhi6c92a4f2014-11-18 18:01:51 +0530207 ret = 1;
208 break;
209 default:
210 ret = 0;
211 };
212
213 return ret;
214}
215
216int boot_device_mask(int val)
217{
218 return ((val & 0x0E) >> 1);
219}
Unnati Gandhi24885052014-11-27 16:57:49 +0530220
221uint32_t platform_detect_panel()
222{
223 uint32_t panel;
224
225 /* Bits 28:29 of this register are read to know
226 the panel config, and pick up DT accordingly.
227
228 00 -no limit, suport HD
229 01 - limit to 720P
230 10- limit to qHD
231 11- limit to fWVGA
232
233 */
234 panel = readl(SECURITY_CONTROL_CORE_FEATURE_CONFIG0);
235 panel = (panel & 0x30000000) >> 28;
236
237 return panel;
238}