blob: e5ebf795bbadca4a72a387ffe0ee6a3f2d03edd4 [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>
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053033#include <qgic.h>
34#include <qtimer.h>
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080035#include <mmu.h>
36#include <arch/arm/mmu.h>
37#include <smem.h>
38#include <board.h>
39#include <boot_stats.h>
40
41#define MB (1024*1024)
42
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 */
55#define IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
56 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},
63 { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY},
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080064};
65
66static struct smem_ram_ptable ram_ptable;
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053067
Unnati Gandhiad17b722014-06-11 23:04:54 +053068int platform_is_msm8939();
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053069
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053070void platform_early_init(void)
71{
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080072 board_init();
73 platform_clock_init();
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053074 qgic_init();
75 qtimer_init();
Unnati Gandhia1f8b472014-10-08 13:56:57 +053076 scm_init();
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053077}
78
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053079int qtmr_irq()
80{
81 if (platform_is_msm8939())
82 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39;
83 else
84 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16;
85}
86
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053087void platform_init(void)
88{
89 dprintf(INFO, "platform_init()\n");
90}
91
92void platform_uninit(void)
93{
94 qtimer_uninit();
95}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080096
97uint32_t platform_get_sclk_count(void)
98{
99 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
100}
101
102addr_t get_bs_info_addr()
103{
104 return ((addr_t)BS_INFO_ADDR);
105}
106
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530107int platform_use_identity_mmu_mappings(void)
108{
109 /* Use only the mappings specified in this file. */
110 return 0;
111}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800112/* Setup memory for this platform */
113void platform_init_mmu_mappings(void)
114{
115 uint32_t i;
116 uint32_t sections;
117 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
118 ram_partition ptn_entry;
119 uint32_t len = 0;
120
121 ASSERT(smem_ram_ptable_init_v1());
122
123 len = smem_get_ram_ptable_len();
124
125 /* Configure the MMU page entries for SDRAM and IMEM memory read
126 from the smem ram table*/
127 for(i = 0; i < len; i++)
128 {
129 smem_get_ram_ptable_entry(&ptn_entry, i);
130 if(ptn_entry.type == SYS_MEMORY)
131 {
132 if((ptn_entry.category == SDRAM) ||
133 (ptn_entry.category == IMEM))
134 {
135 /* Check to ensure that start address is 1MB aligned */
136 ASSERT((ptn_entry.start & (MB-1)) == 0);
137
138 sections = (ptn_entry.size) / MB;
139 while(sections--)
140 {
141 arm_mmu_map_section(ptn_entry.start +
142 sections * MB,
143 ptn_entry.start +
144 sections * MB,
145 (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
146 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
147 }
148 }
149 }
150 }
151
152 /* Configure the MMU page entries for memory read from the
153 mmu_section_table */
154 for (i = 0; i < table_size; i++)
155 {
156 sections = mmu_section_table[i].num_of_sections;
157
158 while (sections--)
159 {
160 arm_mmu_map_section(mmu_section_table[i].paddress +
161 sections * MB,
162 mmu_section_table[i].vaddress +
163 sections * MB,
164 mmu_section_table[i].flags);
165 }
166 }
167}
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530168
169addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
170{
171 /* Using 1-1 mapping on this platform. */
172 return virt_addr;
173}
174
175addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
176{
177 /* Using 1-1 mapping on this platform. */
178 return phys_addr;
179}
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530180
Unnati Gandhiad17b722014-06-11 23:04:54 +0530181int platform_is_msm8939()
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530182{
183 uint32_t platform = board_platform_id();
184 uint32_t ret = 0;
185
186 switch(platform)
187 {
188 case MSM8939:
189 case APQ8036:
190 case APQ8039:
191 case MSM8236:
192 case MSM8636:
Unnati Gandhiad17b722014-06-11 23:04:54 +0530193 case MSM8936:
Aparna Mallavarapu36cae9d2014-08-04 12:51:10 +0530194 case MSM8239:
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530195 ret = 1;
196 break;
197 default:
198 ret = 0;
199 };
200
201 return ret;
202}
Aparna Mallavarapude688ea2014-05-12 17:26:11 +0530203
204/* DYNAMIC SMEM REGION feature enables LK to dynamically
205 * read the SMEM addr info from TCSR_TZ_WONCE register.
206 * The first word read, if indicates a MAGIC number, then
207 * Dynamic SMEM is assumed to be enabled. Read the remaining
208 * SMEM info for SMEM Size and Phy_addr from the other bytes.
209 */
210uint32_t platform_get_smem_base_addr()
211{
212 struct smem_addr_info *smem_info = NULL;
213
214 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
215 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
216 return smem_info->phy_addr;
217 else
218 return MSM_SHARED_BASE;
219}