blob: 1eb97490138eb82764e09aa92fe7c3a6cc73721a [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 */
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},
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080067};
68
69static struct smem_ram_ptable ram_ptable;
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053070
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053071static int platform_is_msm8939();
72
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();
79}
80
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053081int qtmr_irq()
82{
83 if (platform_is_msm8939())
84 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39;
85 else
86 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16;
87}
88
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053089void platform_init(void)
90{
91 dprintf(INFO, "platform_init()\n");
92}
93
94void platform_uninit(void)
95{
96 qtimer_uninit();
97}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080098
99uint32_t platform_get_sclk_count(void)
100{
101 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
102}
103
104addr_t get_bs_info_addr()
105{
106 return ((addr_t)BS_INFO_ADDR);
107}
108
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530109int platform_use_identity_mmu_mappings(void)
110{
111 /* Use only the mappings specified in this file. */
112 return 0;
113}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800114/* Setup memory for this platform */
115void platform_init_mmu_mappings(void)
116{
117 uint32_t i;
118 uint32_t sections;
119 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800120
121 /* Configure the MMU page entries for memory read from the
122 mmu_section_table */
123 for (i = 0; i < table_size; i++)
124 {
125 sections = mmu_section_table[i].num_of_sections;
126
127 while (sections--)
128 {
129 arm_mmu_map_section(mmu_section_table[i].paddress +
130 sections * MB,
131 mmu_section_table[i].vaddress +
132 sections * MB,
133 mmu_section_table[i].flags);
134 }
135 }
136}
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530137
138addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
139{
140 /* Using 1-1 mapping on this platform. */
141 return virt_addr;
142}
143
144addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
145{
146 /* Using 1-1 mapping on this platform. */
147 return phys_addr;
148}
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530149
150static int platform_is_msm8939()
151{
152 uint32_t platform = board_platform_id();
153 uint32_t ret = 0;
154
155 switch(platform)
156 {
157 case MSM8939:
158 case APQ8036:
159 case APQ8039:
160 case MSM8236:
161 case MSM8636:
162 ret = 1;
163 break;
164 default:
165 ret = 0;
166 };
167
168 return ret;
169}
Aparna Mallavarapude688ea2014-05-12 17:26:11 +0530170
171/* DYNAMIC SMEM REGION feature enables LK to dynamically
172 * read the SMEM addr info from TCSR_TZ_WONCE register.
173 * The first word read, if indicates a MAGIC number, then
174 * Dynamic SMEM is assumed to be enabled. Read the remaining
175 * SMEM info for SMEM Size and Phy_addr from the other bytes.
176 */
177uint32_t platform_get_smem_base_addr()
178{
179 struct smem_addr_info *smem_info = NULL;
180
181 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
182 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
183 return smem_info->phy_addr;
184 else
185 return MSM_SHARED_BASE;
186}