blob: ec5a1d8189a50469df5dd1f77279c3f41dfc2bb9 [file] [log] [blame]
Aparna Mallavarapuca676882015-01-19 20:39:06 +05301/* Copyright (c) 2015, 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 "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053032#include <platform/irqs.h>
33#include <platform/clock.h>
Aparna Mallavarapuca676882015-01-19 20:39:06 +053034#include <qgic.h>
35#include <qtimer.h>
36#include <mmu.h>
37#include <arch/arm/mmu.h>
38#include <smem.h>
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053039#include <board.h>
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053040#include <boot_stats.h>
41#include <platform.h>
Unnati Gandhic74a57e2015-06-04 14:34:12 +053042#include <target/display.h>
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053043
44#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
45#define APPS_SS_SIZE ((APPS_SS_END - APPS_SS_BASE)/MB)
46
47/* LK memory - cacheable, write through */
48#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
49 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
55/* IMEM memory - cacheable, write through */
56#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
57 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
58
59#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
60 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
61
62static mmu_section_t mmu_section_table[] = {
63/* 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 { APPS_SS_BASE, APPS_SS_BASE, APPS_SS_SIZE, IOMAP_MEMORY},
67 { MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, COMMON_MEMORY},
Aparna Mallavarapudb938b62015-04-09 01:00:55 +053068 { SCRATCH_ADDR, SCRATCH_ADDR, 512, SCRATCH_MEMORY},
Aparna Mallavarapu9026dda2015-06-15 14:46:25 +053069 { MIPI_FB_ADDR, MIPI_FB_ADDR, 42, COMMON_MEMORY},
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053070};
Aparna Mallavarapuca676882015-01-19 20:39:06 +053071
72void platform_early_init(void)
73{
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053074 board_init();
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053075 platform_clock_init();
Aparna Mallavarapuca676882015-01-19 20:39:06 +053076 qgic_init();
77 qtimer_init();
78 scm_init();
79}
80
81void platform_init(void)
82{
83 dprintf(INFO, "platform_init()\n");
84}
85
86void platform_uninit(void)
87{
88 qtimer_uninit();
89}
90
91uint32_t platform_get_sclk_count(void)
92{
93 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
94}
95
96addr_t get_bs_info_addr()
97{
98 return ((addr_t)BS_INFO_ADDR);
99}
100
101int platform_use_identity_mmu_mappings(void)
102{
103 /* Use only the mappings specified in this file. */
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530104 return 0;
105}
106
107/* Setup MMU mapping for this platform */
108void platform_init_mmu_mappings(void)
109{
110 uint32_t i;
111 uint32_t sections;
112 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
113 uint32_t ddr_start = get_ddr_start();
114 uint32_t smem_addr = platform_get_smem_base_addr();
115
116 /*Mapping the ddr start address for loading the kernel about 90 MB*/
117 sections = 90;
118 while(sections--)
119 {
Maria Yuabef1f82015-08-05 16:13:44 +0800120 arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, SCRATCH_MEMORY);
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530121 }
122
123
124 /* Mapping the SMEM addr */
125 arm_mmu_map_section(smem_addr, smem_addr, COMMON_MEMORY);
126
127 /* Configure the MMU page entries for memory read from the
128 mmu_section_table */
129 for (i = 0; i < table_size; i++)
130 {
131 sections = mmu_section_table[i].num_of_sections;
132
133 while (sections--)
134 {
135 arm_mmu_map_section(mmu_section_table[i].paddress +
136 sections * MB,
137 mmu_section_table[i].vaddress +
138 sections * MB,
139 mmu_section_table[i].flags);
140 }
141 }
142}
143
144addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
145{
146 /* Using 1-1 mapping on this platform. */
147 return virt_addr;
148}
149
150addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
151{
152 /* Using 1-1 mapping on this platform. */
153 return phys_addr;
154}
155
156/* DYNAMIC SMEM REGION feature enables LK to dynamically
157 * read the SMEM addr info from TCSR_TZ_WONCE register.
158 * The first word read, if indicates a MAGIC number, then
159 * Dynamic SMEM is assumed to be enabled. Read the remaining
160 * SMEM info for SMEM Size and Phy_addr from the other bytes.
161 */
162uint32_t platform_get_smem_base_addr()
163{
164 struct smem_addr_info *smem_info = NULL;
165
166 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
167 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
168 return smem_info->phy_addr;
169 else
170 return MSM_SHARED_BASE;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530171}
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530172
173uint32_t platform_get_max_periph()
174{
175 return 256;
176}
Unnati Gandhi81b77062015-05-28 14:23:39 +0530177
178int platform_is_msm8956()
179{
180 uint32_t platform = board_platform_id();
181 uint32_t ret = 0;
182
183 switch(platform)
184 {
185 case MSM8956:
186 case APQ8056:
187 case APQ8076:
188 case MSM8976:
189 ret = 1;
190 break;
191 default:
192 ret = 0;
193 };
194
195 return ret;
196}