blob: 83d0b3bbf4dbc11edd3dbe3bc82accae5303655f [file] [log] [blame]
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +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>
P.V. Phani Kumar40fa1352015-08-13 18:15:03 +053032#include <platform/irqs.h>
33#include <platform/clock.h>
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053034#include <qgic.h>
35#include <qtimer.h>
36#include <mmu.h>
37#include <arch/arm/mmu.h>
38#include <smem.h>
P.V. Phani Kumar40fa1352015-08-13 18:15:03 +053039#include <board.h>
40#include <boot_stats.h>
41#include <platform.h>
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053042
P.V. Phani Kumara053a322015-08-13 18:36:05 +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},
68 { SCRATCH_ADDR, SCRATCH_ADDR, 512, SCRATCH_MEMORY},
P.V. Phani Kumar9451ebe2015-12-26 16:31:18 +053069 { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY},
P.V. Phani Kumara053a322015-08-13 18:36:05 +053070};
71
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +053072void platform_early_init(void)
73{
P.V. Phani Kumar40fa1352015-08-13 18:15:03 +053074 board_init();
75 platform_clock_init();
Aparna Mallavarapu01fc00a2015-06-01 20:37:05 +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. */
P.V. Phani Kumara053a322015-08-13 18:36:05 +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 {
120 arm_mmu_map_section(ddr_start + sections * MB, ddr_start + sections* MB, COMMON_MEMORY);
121 }
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 Mallavarapu01fc00a2015-06-01 20:37:05 +0530171}
P.V. Phani Kumar9451ebe2015-12-26 16:31:18 +0530172
173uint32_t platform_get_qmp_rev()
174{
175 return readl(USB3_PHY_REVISION_ID3) << 24 | readl(USB3_PHY_REVISION_ID2) << 16 |
176 readl(USB3_PHY_REVISION_ID1) << 8 | readl(USB3_PHY_REVISION_ID0);
177}