blob: 02062861f36d076f1c98a8b8058255559793bd9f [file] [log] [blame]
Dan Handleyb4315302015-03-19 18:58:55 +00001/*
Vikram Kanigiri65cb1c42015-11-12 18:52:34 +00002 * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
Dan Handleyb4315302015-03-19 18:58:55 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30#include <arch.h>
31#include <arch_helpers.h>
32#include <cci.h>
33#include <mmio.h>
34#include <plat_arm.h>
Soby Mathewc1bb8a02015-10-12 17:32:29 +010035#include <platform_def.h>
Dan Handleyb4315302015-03-19 18:58:55 +000036#include <xlat_tables.h>
37
Vikram Kanigiri65cb1c42015-11-12 18:52:34 +000038extern const mmap_region_t plat_arm_mmap[];
Dan Handleyb4315302015-03-19 18:58:55 +000039
40static const int cci_map[] = {
41 PLAT_ARM_CCI_CLUSTER0_SL_IFACE_IX,
42 PLAT_ARM_CCI_CLUSTER1_SL_IFACE_IX
43};
44
45/* Weak definitions may be overridden in specific ARM standard platform */
46#pragma weak plat_get_ns_image_entrypoint
Vikram Kanigiri65cb1c42015-11-12 18:52:34 +000047#pragma weak plat_arm_get_mmap
Dan Handleyb4315302015-03-19 18:58:55 +000048
49
50/*******************************************************************************
51 * Macro generating the code for the function setting up the pagetables as per
52 * the platform memory map & initialize the mmu, for the given exception level
53 ******************************************************************************/
54#if USE_COHERENT_MEM
55#define DEFINE_CONFIGURE_MMU_EL(_el) \
56 void arm_configure_mmu_el##_el(unsigned long total_base, \
57 unsigned long total_size, \
58 unsigned long ro_start, \
59 unsigned long ro_limit, \
60 unsigned long coh_start, \
61 unsigned long coh_limit) \
62 { \
63 mmap_add_region(total_base, total_base, \
64 total_size, \
65 MT_MEMORY | MT_RW | MT_SECURE); \
66 mmap_add_region(ro_start, ro_start, \
67 ro_limit - ro_start, \
68 MT_MEMORY | MT_RO | MT_SECURE); \
69 mmap_add_region(coh_start, coh_start, \
70 coh_limit - coh_start, \
71 MT_DEVICE | MT_RW | MT_SECURE); \
Vikram Kanigiri65cb1c42015-11-12 18:52:34 +000072 mmap_add(plat_arm_get_mmap()); \
Dan Handleyb4315302015-03-19 18:58:55 +000073 init_xlat_tables(); \
74 \
75 enable_mmu_el##_el(0); \
76 }
77#else
78#define DEFINE_CONFIGURE_MMU_EL(_el) \
79 void arm_configure_mmu_el##_el(unsigned long total_base, \
80 unsigned long total_size, \
81 unsigned long ro_start, \
82 unsigned long ro_limit) \
83 { \
84 mmap_add_region(total_base, total_base, \
85 total_size, \
86 MT_MEMORY | MT_RW | MT_SECURE); \
87 mmap_add_region(ro_start, ro_start, \
88 ro_limit - ro_start, \
89 MT_MEMORY | MT_RO | MT_SECURE); \
Vikram Kanigiri65cb1c42015-11-12 18:52:34 +000090 mmap_add(plat_arm_get_mmap()); \
Dan Handleyb4315302015-03-19 18:58:55 +000091 init_xlat_tables(); \
92 \
93 enable_mmu_el##_el(0); \
94 }
95#endif
96
97/* Define EL1 and EL3 variants of the function initialising the MMU */
98DEFINE_CONFIGURE_MMU_EL(1)
99DEFINE_CONFIGURE_MMU_EL(3)
100
101
102unsigned long plat_get_ns_image_entrypoint(void)
103{
104 return PLAT_ARM_NS_IMAGE_OFFSET;
105}
106
107/*******************************************************************************
108 * Gets SPSR for BL32 entry
109 ******************************************************************************/
110uint32_t arm_get_spsr_for_bl32_entry(void)
111{
112 /*
113 * The Secure Payload Dispatcher service is responsible for
Juan Castillod1786372015-12-14 09:35:25 +0000114 * setting the SPSR prior to entry into the BL32 image.
Dan Handleyb4315302015-03-19 18:58:55 +0000115 */
116 return 0;
117}
118
119/*******************************************************************************
120 * Gets SPSR for BL33 entry
121 ******************************************************************************/
122uint32_t arm_get_spsr_for_bl33_entry(void)
123{
124 unsigned long el_status;
125 unsigned int mode;
126 uint32_t spsr;
127
128 /* Figure out what mode we enter the non-secure world in */
129 el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
130 el_status &= ID_AA64PFR0_ELX_MASK;
131
132 mode = (el_status) ? MODE_EL2 : MODE_EL1;
133
134 /*
135 * TODO: Consider the possibility of specifying the SPSR in
136 * the FIP ToC and allowing the platform to have a say as
137 * well.
138 */
139 spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
140 return spsr;
141}
142
143
144void arm_cci_init(void)
145{
146 cci_init(PLAT_ARM_CCI_BASE, cci_map, ARRAY_SIZE(cci_map));
147}
Soby Mathewc1bb8a02015-10-12 17:32:29 +0100148
149/*******************************************************************************
150 * Configures access to the system counter timer module.
151 ******************************************************************************/
152void arm_configure_sys_timer(void)
153{
154 unsigned int reg_val;
155
Juan Castillo0e5dcdd2015-11-06 16:02:32 +0000156#if ARM_CONFIG_CNTACR
Soby Mathewc1bb8a02015-10-12 17:32:29 +0100157 reg_val = (1 << CNTACR_RPCT_SHIFT) | (1 << CNTACR_RVCT_SHIFT);
158 reg_val |= (1 << CNTACR_RFRQ_SHIFT) | (1 << CNTACR_RVOFF_SHIFT);
159 reg_val |= (1 << CNTACR_RWVT_SHIFT) | (1 << CNTACR_RWPT_SHIFT);
160 mmio_write_32(ARM_SYS_TIMCTL_BASE + CNTACR_BASE(PLAT_ARM_NSTIMER_FRAME_ID), reg_val);
Juan Castillo0e5dcdd2015-11-06 16:02:32 +0000161#endif /* ARM_CONFIG_CNTACR */
Soby Mathewc1bb8a02015-10-12 17:32:29 +0100162
163 reg_val = (1 << CNTNSAR_NS_SHIFT(PLAT_ARM_NSTIMER_FRAME_ID));
164 mmio_write_32(ARM_SYS_TIMCTL_BASE + CNTNSAR, reg_val);
165}
Vikram Kanigiri65cb1c42015-11-12 18:52:34 +0000166
167/*******************************************************************************
168 * Returns ARM platform specific memory map regions.
169 ******************************************************************************/
170const mmap_region_t *plat_arm_get_mmap(void)
171{
172 return plat_arm_mmap;
173}