blob: 996d60346cc7139b4ee53d5514e45c7de4464780 [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>
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053042
43#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
44#define APPS_SS_SIZE ((APPS_SS_END - APPS_SS_BASE)/MB)
45
46/* LK memory - cacheable, write through */
47#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
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
54/* IMEM memory - cacheable, write through */
55#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
56 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
57
58#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
59 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
60
61static mmu_section_t mmu_section_table[] = {
62/* 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 { APPS_SS_BASE, APPS_SS_BASE, APPS_SS_SIZE, IOMAP_MEMORY},
66 { MSM_SHARED_IMEM_BASE, MSM_SHARED_IMEM_BASE, 1, COMMON_MEMORY},
Aparna Mallavarapudb938b62015-04-09 01:00:55 +053067 { SCRATCH_ADDR, SCRATCH_ADDR, 512, SCRATCH_MEMORY},
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053068};
Aparna Mallavarapuca676882015-01-19 20:39:06 +053069
70void platform_early_init(void)
71{
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +053072 board_init();
Aparna Mallavarapu7b638e62015-03-26 05:51:57 +053073 platform_clock_init();
Aparna Mallavarapuca676882015-01-19 20:39:06 +053074 qgic_init();
75 qtimer_init();
76 scm_init();
77}
78
79void platform_init(void)
80{
81 dprintf(INFO, "platform_init()\n");
82}
83
84void platform_uninit(void)
85{
86 qtimer_uninit();
87}
88
89uint32_t platform_get_sclk_count(void)
90{
91 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
92}
93
94addr_t get_bs_info_addr()
95{
96 return ((addr_t)BS_INFO_ADDR);
97}
98
99int platform_use_identity_mmu_mappings(void)
100{
101 /* Use only the mappings specified in this file. */
Aparna Mallavarapue9bdacd2015-03-15 14:24:21 +0530102 return 0;
103}
104
105/* Setup MMU mapping for this platform */
106void platform_init_mmu_mappings(void)
107{
108 uint32_t i;
109 uint32_t sections;
110 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
111 uint32_t ddr_start = get_ddr_start();
112 uint32_t smem_addr = platform_get_smem_base_addr();
113
114 /*Mapping the ddr start address for loading the kernel about 90 MB*/
115 sections = 90;
116 while(sections--)
117 {
118 arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, COMMON_MEMORY);
119 }
120
121
122 /* Mapping the SMEM addr */
123 arm_mmu_map_section(smem_addr, smem_addr, COMMON_MEMORY);
124
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}
141
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}
153
154/* DYNAMIC SMEM REGION feature enables LK to dynamically
155 * read the SMEM addr info from TCSR_TZ_WONCE register.
156 * The first word read, if indicates a MAGIC number, then
157 * Dynamic SMEM is assumed to be enabled. Read the remaining
158 * SMEM info for SMEM Size and Phy_addr from the other bytes.
159 */
160uint32_t platform_get_smem_base_addr()
161{
162 struct smem_addr_info *smem_info = NULL;
163
164 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
165 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
166 return smem_info->phy_addr;
167 else
168 return MSM_SHARED_BASE;
Aparna Mallavarapuca676882015-01-19 20:39:06 +0530169}
Aparna Mallavarapufa5f8a72015-03-31 06:21:36 +0530170
171uint32_t platform_get_max_periph()
172{
173 return 256;
174}