blob: 9a22f173bf240ff27ecd9c7d1860ecc0841beba8 [file] [log] [blame]
Matthew Qinf3638b92015-02-03 18:08:14 +08001/* 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>
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 */
Matthew Qinf3638b92015-02-03 18:08:14 +080047#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080048 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
Matthew Qinf3638b92015-02-03 18:08:14 +080058#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
59 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
60
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080061static mmu_section_t mmu_section_table[] = {
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053062/* Physical addr, Virtual addr, Size (in MB), Flags */
63 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
64 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
65 { A53_SS_BASE, A53_SS_BASE, A53_SS_SIZE, IOMAP_MEMORY},
Aparna Mallavarapu428168a2014-06-16 21:25:06 +053066 { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, COMMON_MEMORY},
67 { MSM_SHARED_BASE, MSM_SHARED_BASE, 1, COMMON_MEMORY},
68 { BASE_ADDR, BASE_ADDR, 90, COMMON_MEMORY},
Matthew Qinf3638b92015-02-03 18:08:14 +080069 { SCRATCH_ADDR, SCRATCH_ADDR, 256, SCRATCH_MEMORY},
vijay kumar0da32062014-10-21 15:48:11 +053070 { BASE_ADDR_1, BASE_ADDR_1, 1024, 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();
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053075
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053076void platform_early_init(void)
77{
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080078 board_init();
79 platform_clock_init();
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053080 qgic_init();
81 qtimer_init();
Unnati Gandhia1f8b472014-10-08 13:56:57 +053082 scm_init();
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053083}
84
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053085int qtmr_irq()
86{
87 if (platform_is_msm8939())
88 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39;
89 else
90 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16;
91}
92
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053093void platform_init(void)
94{
95 dprintf(INFO, "platform_init()\n");
96}
97
98void platform_uninit(void)
99{
100 qtimer_uninit();
101}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800102
103uint32_t platform_get_sclk_count(void)
104{
105 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
106}
107
108addr_t get_bs_info_addr()
109{
110 return ((addr_t)BS_INFO_ADDR);
111}
112
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530113int platform_use_identity_mmu_mappings(void)
114{
115 /* Use only the mappings specified in this file. */
116 return 0;
117}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800118/* Setup memory for this platform */
119void platform_init_mmu_mappings(void)
120{
121 uint32_t i;
122 uint32_t sections;
123 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800124
125 /* Configure the MMU page entries for memory read from the
126 mmu_section_table */
127 for (i = 0; i < table_size; i++)
128 {
129 sections = mmu_section_table[i].num_of_sections;
130
131 while (sections--)
132 {
133 arm_mmu_map_section(mmu_section_table[i].paddress +
134 sections * MB,
135 mmu_section_table[i].vaddress +
136 sections * MB,
137 mmu_section_table[i].flags);
138 }
139 }
140}
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530141
142addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
143{
144 /* Using 1-1 mapping on this platform. */
145 return virt_addr;
146}
147
148addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
149{
150 /* Using 1-1 mapping on this platform. */
151 return phys_addr;
152}
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530153
Unnati Gandhiad17b722014-06-11 23:04:54 +0530154int platform_is_msm8939()
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530155{
156 uint32_t platform = board_platform_id();
157 uint32_t ret = 0;
158
159 switch(platform)
160 {
161 case MSM8939:
162 case APQ8036:
163 case APQ8039:
164 case MSM8236:
165 case MSM8636:
Unnati Gandhiad17b722014-06-11 23:04:54 +0530166 case MSM8936:
Aparna Mallavarapu36cae9d2014-08-04 12:51:10 +0530167 case MSM8239:
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530168 ret = 1;
169 break;
170 default:
171 ret = 0;
172 };
173
174 return ret;
175}
Aparna Mallavarapude688ea2014-05-12 17:26:11 +0530176
177/* DYNAMIC SMEM REGION feature enables LK to dynamically
178 * read the SMEM addr info from TCSR_TZ_WONCE register.
179 * The first word read, if indicates a MAGIC number, then
180 * Dynamic SMEM is assumed to be enabled. Read the remaining
181 * SMEM info for SMEM Size and Phy_addr from the other bytes.
182 */
183uint32_t platform_get_smem_base_addr()
184{
185 struct smem_addr_info *smem_info = NULL;
186
187 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
188 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
189 return smem_info->phy_addr;
190 else
191 return MSM_SHARED_BASE;
192}
Aparna Mallavarapu324cfbd2014-08-12 12:03:48 +0530193uint32_t get_ddr_start()
194{
195 uint32_t i;
196 ram_partition ptn_entry;
197 uint32_t len = 0;
198
199 ASSERT(smem_ram_ptable_init_v1());
200
201 len = smem_get_ram_ptable_len();
202
203 /* Determine the Start addr of the DDR RAM */
204 for(i = 0; i < len; i++)
205 {
206 smem_get_ram_ptable_entry(&ptn_entry, i);
207 if(ptn_entry.type == SYS_MEMORY)
208 {
209 if((ptn_entry.category == SDRAM) ||
210 (ptn_entry.category == IMEM))
211 {
212 /* Check to ensure that start address is 1MB aligned */
213 ASSERT((ptn_entry.start & (MB-1)) == 0);
214 return ptn_entry.start;
215 }
216 }
217 }
218 ASSERT("DDR Start Mem Not found\n");
219}