blob: a367985afe535b6e64f7b7cebd8125584f5d6d2f [file] [log] [blame]
Aparna Mallavarapu9e014372013-10-19 15:04:58 +05301/* Copyright (c) 2014, 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 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>
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080042
43#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053044#define A53_SS_SIZE ((A53_SS_END - A53_SS_BASE)/MB)
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080045
46/* LK memory - cacheable, write through */
47#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
48 MMU_MEMORY_AP_READ_WRITE)
49
50/* Peripherals - non-shared device */
51#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
52 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
53
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053054/* IMEM memory - cacheable, write through */
Aparna Mallavarapu428168a2014-06-16 21:25:06 +053055#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053056 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
57
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080058static mmu_section_t mmu_section_table[] = {
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053059/* Physical addr, Virtual addr, Size (in MB), Flags */
60 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
61 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
62 { A53_SS_BASE, A53_SS_BASE, A53_SS_SIZE, IOMAP_MEMORY},
Aparna Mallavarapu428168a2014-06-16 21:25:06 +053063 { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, COMMON_MEMORY},
64 { MSM_SHARED_BASE, MSM_SHARED_BASE, 1, COMMON_MEMORY},
65 { BASE_ADDR, BASE_ADDR, 90, COMMON_MEMORY},
66 { SCRATCH_ADDR, SCRATCH_ADDR, 256, COMMON_MEMORY},
vijay kumar0da32062014-10-21 15:48:11 +053067 { BASE_ADDR_1, BASE_ADDR_1, 1024, COMMON_MEMORY},
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080068};
69
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053070
Unnati Gandhiad17b722014-06-11 23:04:54 +053071int platform_is_msm8939();
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053072
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053073void platform_early_init(void)
74{
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080075 board_init();
76 platform_clock_init();
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053077 qgic_init();
78 qtimer_init();
Unnati Gandhia1f8b472014-10-08 13:56:57 +053079 scm_init();
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053080}
81
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053082int qtmr_irq()
83{
84 if (platform_is_msm8939())
85 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39;
86 else
87 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16;
88}
89
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053090void platform_init(void)
91{
92 dprintf(INFO, "platform_init()\n");
93}
94
95void platform_uninit(void)
96{
97 qtimer_uninit();
98}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080099
100uint32_t platform_get_sclk_count(void)
101{
102 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
103}
104
105addr_t get_bs_info_addr()
106{
107 return ((addr_t)BS_INFO_ADDR);
108}
109
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530110int platform_use_identity_mmu_mappings(void)
111{
112 /* Use only the mappings specified in this file. */
113 return 0;
114}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800115/* Setup memory for this platform */
116void platform_init_mmu_mappings(void)
117{
118 uint32_t i;
119 uint32_t sections;
120 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800121
122 /* Configure the MMU page entries for memory read from the
123 mmu_section_table */
124 for (i = 0; i < table_size; i++)
125 {
126 sections = mmu_section_table[i].num_of_sections;
127
128 while (sections--)
129 {
130 arm_mmu_map_section(mmu_section_table[i].paddress +
131 sections * MB,
132 mmu_section_table[i].vaddress +
133 sections * MB,
134 mmu_section_table[i].flags);
135 }
136 }
137}
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530138
139addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
140{
141 /* Using 1-1 mapping on this platform. */
142 return virt_addr;
143}
144
145addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
146{
147 /* Using 1-1 mapping on this platform. */
148 return phys_addr;
149}
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530150
Unnati Gandhiad17b722014-06-11 23:04:54 +0530151int platform_is_msm8939()
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530152{
153 uint32_t platform = board_platform_id();
154 uint32_t ret = 0;
155
156 switch(platform)
157 {
158 case MSM8939:
159 case APQ8036:
160 case APQ8039:
161 case MSM8236:
162 case MSM8636:
Unnati Gandhiad17b722014-06-11 23:04:54 +0530163 case MSM8936:
Aparna Mallavarapu36cae9d2014-08-04 12:51:10 +0530164 case MSM8239:
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530165 ret = 1;
166 break;
167 default:
168 ret = 0;
169 };
170
171 return ret;
172}
Aparna Mallavarapude688ea2014-05-12 17:26:11 +0530173
174/* DYNAMIC SMEM REGION feature enables LK to dynamically
175 * read the SMEM addr info from TCSR_TZ_WONCE register.
176 * The first word read, if indicates a MAGIC number, then
177 * Dynamic SMEM is assumed to be enabled. Read the remaining
178 * SMEM info for SMEM Size and Phy_addr from the other bytes.
179 */
180uint32_t platform_get_smem_base_addr()
181{
182 struct smem_addr_info *smem_info = NULL;
183
184 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
185 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
186 return smem_info->phy_addr;
187 else
188 return MSM_SHARED_BASE;
189}
Aparna Mallavarapu324cfbd2014-08-12 12:03:48 +0530190uint32_t get_ddr_start()
191{
192 uint32_t i;
193 ram_partition ptn_entry;
194 uint32_t len = 0;
195
196 ASSERT(smem_ram_ptable_init_v1());
197
198 len = smem_get_ram_ptable_len();
199
200 /* Determine the Start addr of the DDR RAM */
201 for(i = 0; i < len; i++)
202 {
203 smem_get_ram_ptable_entry(&ptn_entry, i);
204 if(ptn_entry.type == SYS_MEMORY)
205 {
206 if((ptn_entry.category == SDRAM) ||
207 (ptn_entry.category == IMEM))
208 {
209 /* Check to ensure that start address is 1MB aligned */
210 ASSERT((ptn_entry.start & (MB-1)) == 0);
211 return ptn_entry.start;
212 }
213 }
214 }
215 ASSERT("DDR Start Mem Not found\n");
216}