blob: 8d0f0339c3d600171d63db31cc4433d488d8e157 [file] [log] [blame]
vijay kumardd51c592015-01-05 12:46:28 +05301/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
Aparna Mallavarapu9e014372013-10-19 15:04:58 +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 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>
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053032#include <platform/irqs.h>
Unnati Gandhibd9dbea2014-07-17 14:30:29 +053033#include <platform/clock.h>
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053034#include <qgic.h>
35#include <qtimer.h>
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080036#include <mmu.h>
37#include <arch/arm/mmu.h>
38#include <smem.h>
39#include <board.h>
40#include <boot_stats.h>
Unnati Gandhibd9dbea2014-07-17 14:30:29 +053041#include <platform.h>
vijay kumarb641d0d2015-02-26 18:42:26 +053042#include <target/display.h>
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080043
44#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053045#define A53_SS_SIZE ((A53_SS_END - A53_SS_BASE)/MB)
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080046
47/* LK memory - cacheable, write through */
Matthew Qinf3638b92015-02-03 18:08:14 +080048#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080049 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
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053055/* IMEM memory - cacheable, write through */
Aparna Mallavarapu428168a2014-06-16 21:25:06 +053056#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053057 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
58
Matthew Qinf3638b92015-02-03 18:08:14 +080059#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
60 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
61
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080062static mmu_section_t mmu_section_table[] = {
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053063/* 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 { A53_SS_BASE, A53_SS_BASE, A53_SS_SIZE, IOMAP_MEMORY},
Aparna Mallavarapu428168a2014-06-16 21:25:06 +053067 { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, COMMON_MEMORY},
68 { MSM_SHARED_BASE, MSM_SHARED_BASE, 1, COMMON_MEMORY},
Matthew Qin68dabfe2015-04-09 02:19:14 -040069 { SCRATCH_ADDR, SCRATCH_ADDR, 256, SCRATCH_MEMORY},
vijay kumarb641d0d2015-02-26 18:42:26 +053070 { MIPI_FB_ADDR, MIPI_FB_ADDR, 10, COMMON_MEMORY},
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080071};
72
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053073
Unnati Gandhiad17b722014-06-11 23:04:54 +053074int platform_is_msm8939();
vijay kumardd51c592015-01-05 12:46:28 +053075int platform_is_msm8929();
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053076
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053077void platform_early_init(void)
78{
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080079 board_init();
80 platform_clock_init();
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053081 qgic_init();
82 qtimer_init();
Unnati Gandhia1f8b472014-10-08 13:56:57 +053083 scm_init();
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053084}
85
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053086int qtmr_irq()
87{
vijay kumardd51c592015-01-05 12:46:28 +053088 if (platform_is_msm8939() || platform_is_msm8929())
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053089 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39;
90 else
91 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16;
92}
93
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053094void platform_init(void)
95{
96 dprintf(INFO, "platform_init()\n");
97}
98
99void platform_uninit(void)
100{
101 qtimer_uninit();
102}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800103
104uint32_t platform_get_sclk_count(void)
105{
106 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
107}
108
109addr_t get_bs_info_addr()
110{
111 return ((addr_t)BS_INFO_ADDR);
112}
113
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530114int platform_use_identity_mmu_mappings(void)
115{
116 /* Use only the mappings specified in this file. */
117 return 0;
118}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800119/* Setup memory for this platform */
120void platform_init_mmu_mappings(void)
121{
122 uint32_t i;
123 uint32_t sections;
124 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
vijay kumarb641d0d2015-02-26 18:42:26 +0530125 uint32_t ddr_start = get_ddr_start();
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800126
vijay kumarb641d0d2015-02-26 18:42:26 +0530127 /*Mapping the ddr start address for loading the kernel about 90 MB*/
128 sections = 90;
129 while(sections--)
130 {
131 arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, COMMON_MEMORY);
132 }
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800133 /* Configure the MMU page entries for memory read from the
134 mmu_section_table */
135 for (i = 0; i < table_size; i++)
136 {
137 sections = mmu_section_table[i].num_of_sections;
138
139 while (sections--)
140 {
141 arm_mmu_map_section(mmu_section_table[i].paddress +
142 sections * MB,
143 mmu_section_table[i].vaddress +
144 sections * MB,
145 mmu_section_table[i].flags);
146 }
147 }
148}
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530149
150addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
151{
152 /* Using 1-1 mapping on this platform. */
153 return virt_addr;
154}
155
156addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
157{
158 /* Using 1-1 mapping on this platform. */
159 return phys_addr;
160}
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530161
Unnati Gandhiad17b722014-06-11 23:04:54 +0530162int platform_is_msm8939()
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530163{
164 uint32_t platform = board_platform_id();
165 uint32_t ret = 0;
166
167 switch(platform)
168 {
169 case MSM8939:
170 case APQ8036:
171 case APQ8039:
172 case MSM8236:
173 case MSM8636:
Unnati Gandhiad17b722014-06-11 23:04:54 +0530174 case MSM8936:
Aparna Mallavarapu36cae9d2014-08-04 12:51:10 +0530175 case MSM8239:
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530176 ret = 1;
177 break;
178 default:
179 ret = 0;
180 };
181
182 return ret;
183}
Aparna Mallavarapude688ea2014-05-12 17:26:11 +0530184
vijay kumardd51c592015-01-05 12:46:28 +0530185int platform_is_msm8929()
186{
187 uint32_t platform = board_platform_id();
188 uint32_t ret = 0;
189
190 switch(platform)
191 {
192 case MSM8929:
193 case MSM8629:
194 case MSM8229:
195 case APQ8029:
196 ret = 1;
197 break;
198 default:
199 ret = 0;
200 };
201
202 return ret;
203}
204
Vineet Bajaj3b1811b2015-04-29 17:11:57 +0530205int platform_is_apq8016()
206{
207 return board_platform_id() == APQ8016 ? 1 : 0;
208}
209
Aparna Mallavarapude688ea2014-05-12 17:26:11 +0530210/* DYNAMIC SMEM REGION feature enables LK to dynamically
211 * read the SMEM addr info from TCSR_TZ_WONCE register.
212 * The first word read, if indicates a MAGIC number, then
213 * Dynamic SMEM is assumed to be enabled. Read the remaining
214 * SMEM info for SMEM Size and Phy_addr from the other bytes.
215 */
216uint32_t platform_get_smem_base_addr()
217{
218 struct smem_addr_info *smem_info = NULL;
219
220 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
221 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
222 return smem_info->phy_addr;
223 else
224 return MSM_SHARED_BASE;
225}