blob: 5e5958baa28af199c4f03070f47dc394f8add2d3 [file] [log] [blame]
Yann Gautieree8f5422019-02-14 11:13:25 +01001/*
Yann Gautiered6515d2021-03-08 15:03:35 +01002 * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
Yann Gautieree8f5422019-02-14 11:13:25 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
Yann Gautiere97b6632019-04-19 10:48:36 +02008#include <errno.h>
Yann Gautieree8f5422019-02-14 11:13:25 +01009
10#include <platform_def.h>
11
12#include <arch_helpers.h>
13#include <common/debug.h>
Yann Gautier3d78a2e2019-02-14 11:01:20 +010014#include <drivers/st/stm32mp_clkfunc.h>
Yann Gautiered6515d2021-03-08 15:03:35 +010015#include <lib/smccc.h>
Yann Gautiera55169b2020-01-10 18:18:59 +010016#include <lib/xlat_tables/xlat_tables_v2.h>
Yann Gautieree8f5422019-02-14 11:13:25 +010017#include <plat/common/platform.h>
Yann Gautiered6515d2021-03-08 15:03:35 +010018#include <services/arm_arch_svc.h>
Yann Gautieree8f5422019-02-14 11:13:25 +010019
20uintptr_t plat_get_ns_image_entrypoint(void)
21{
22 return BL33_BASE;
23}
24
25unsigned int plat_get_syscnt_freq2(void)
26{
27 return read_cntfrq_el0();
28}
29
30static uintptr_t boot_ctx_address;
Yann Gautiercf1360d2020-08-27 18:28:57 +020031static uint16_t boot_itf_selected;
Yann Gautieree8f5422019-02-14 11:13:25 +010032
Yann Gautiera2e2a302019-02-14 11:13:39 +010033void stm32mp_save_boot_ctx_address(uintptr_t address)
Yann Gautieree8f5422019-02-14 11:13:25 +010034{
Yann Gautiercf1360d2020-08-27 18:28:57 +020035 boot_api_context_t *boot_context = (boot_api_context_t *)address;
36
Yann Gautieree8f5422019-02-14 11:13:25 +010037 boot_ctx_address = address;
Yann Gautiercf1360d2020-08-27 18:28:57 +020038 boot_itf_selected = boot_context->boot_interface_selected;
Yann Gautieree8f5422019-02-14 11:13:25 +010039}
40
Yann Gautiera2e2a302019-02-14 11:13:39 +010041uintptr_t stm32mp_get_boot_ctx_address(void)
Yann Gautieree8f5422019-02-14 11:13:25 +010042{
43 return boot_ctx_address;
44}
45
Yann Gautiercf1360d2020-08-27 18:28:57 +020046uint16_t stm32mp_get_boot_itf_selected(void)
47{
48 return boot_itf_selected;
49}
50
Yann Gautier3d78a2e2019-02-14 11:01:20 +010051uintptr_t stm32mp_ddrctrl_base(void)
52{
Yann Gautiera18f61b2020-05-05 17:58:40 +020053 return DDRCTRL_BASE;
Yann Gautier3d78a2e2019-02-14 11:01:20 +010054}
55
56uintptr_t stm32mp_ddrphyc_base(void)
57{
Yann Gautiera18f61b2020-05-05 17:58:40 +020058 return DDRPHYC_BASE;
Yann Gautier3d78a2e2019-02-14 11:01:20 +010059}
60
61uintptr_t stm32mp_pwr_base(void)
62{
Yann Gautiera18f61b2020-05-05 17:58:40 +020063 return PWR_BASE;
Yann Gautier3d78a2e2019-02-14 11:01:20 +010064}
65
66uintptr_t stm32mp_rcc_base(void)
67{
Yann Gautiera18f61b2020-05-05 17:58:40 +020068 return RCC_BASE;
Yann Gautier3d78a2e2019-02-14 11:01:20 +010069}
70
Yann Gautierf540a592019-05-22 19:13:51 +020071bool stm32mp_lock_available(void)
72{
73 const uint32_t c_m_bits = SCTLR_M_BIT | SCTLR_C_BIT;
74
75 /* The spinlocks are used only when MMU and data cache are enabled */
76 return (read_sctlr() & c_m_bits) == c_m_bits;
77}
78
Yann Gautiere97b6632019-04-19 10:48:36 +020079int stm32mp_check_header(boot_api_image_header_t *header, uintptr_t buffer)
80{
81 uint32_t i;
82 uint32_t img_checksum = 0U;
83
84 /*
85 * Check header/payload validity:
86 * - Header magic
87 * - Header version
88 * - Payload checksum
89 */
90 if (header->magic != BOOT_API_IMAGE_HEADER_MAGIC_NB) {
91 ERROR("Header magic\n");
92 return -EINVAL;
93 }
94
95 if (header->header_version != BOOT_API_HEADER_VERSION) {
96 ERROR("Header version\n");
97 return -EINVAL;
98 }
99
100 for (i = 0U; i < header->image_length; i++) {
101 img_checksum += *(uint8_t *)(buffer + i);
102 }
103
104 if (header->payload_checksum != img_checksum) {
105 ERROR("Checksum: 0x%x (awaited: 0x%x)\n", img_checksum,
106 header->payload_checksum);
107 return -EINVAL;
108 }
109
110 return 0;
111}
Yann Gautiera55169b2020-01-10 18:18:59 +0100112
113int stm32mp_map_ddr_non_cacheable(void)
114{
115 return mmap_add_dynamic_region(STM32MP_DDR_BASE, STM32MP_DDR_BASE,
116 STM32MP_DDR_MAX_SIZE,
Yann Gautierf3bd87e2020-09-04 15:55:53 +0200117 MT_NON_CACHEABLE | MT_RW | MT_SECURE);
Yann Gautiera55169b2020-01-10 18:18:59 +0100118}
119
120int stm32mp_unmap_ddr(void)
121{
122 return mmap_remove_dynamic_region(STM32MP_DDR_BASE,
123 STM32MP_DDR_MAX_SIZE);
124}
Yann Gautiered6515d2021-03-08 15:03:35 +0100125
126/*****************************************************************************
127 * plat_is_smccc_feature_available() - This function checks whether SMCCC
128 * feature is availabile for platform.
129 * @fid: SMCCC function id
130 *
131 * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and
132 * SMC_ARCH_CALL_NOT_SUPPORTED otherwise.
133 *****************************************************************************/
134int32_t plat_is_smccc_feature_available(u_register_t fid)
135{
136 switch (fid) {
137 case SMCCC_ARCH_SOC_ID:
138 return SMC_ARCH_CALL_SUCCESS;
139 default:
140 return SMC_ARCH_CALL_NOT_SUPPORTED;
141 }
142}
143
144/* Get SOC version */
145int32_t plat_get_soc_version(void)
146{
147 uint32_t chip_id = stm32mp_get_chip_dev_id();
148 uint32_t manfid = SOC_ID_SET_JEP_106(JEDEC_ST_BKID, JEDEC_ST_MFID);
149
150 return (int32_t)(manfid | (chip_id & SOC_ID_IMPL_DEF_MASK));
151}
152
153/* Get SOC revision */
154int32_t plat_get_soc_revision(void)
155{
156 return (int32_t)(stm32mp_get_chip_version() & SOC_ID_REV_MASK);
157}