Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 1 | /* |
Yann Gautier | ed6515d | 2021-03-08 15:03:35 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved. |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Yann Gautier | e97b663 | 2019-04-19 10:48:36 +0200 | [diff] [blame] | 8 | #include <errno.h> |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 9 | |
| 10 | #include <platform_def.h> |
| 11 | |
| 12 | #include <arch_helpers.h> |
| 13 | #include <common/debug.h> |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 14 | #include <drivers/st/stm32mp_clkfunc.h> |
Yann Gautier | ed6515d | 2021-03-08 15:03:35 +0100 | [diff] [blame] | 15 | #include <lib/smccc.h> |
Yann Gautier | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 16 | #include <lib/xlat_tables/xlat_tables_v2.h> |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 17 | #include <plat/common/platform.h> |
Yann Gautier | ed6515d | 2021-03-08 15:03:35 +0100 | [diff] [blame] | 18 | #include <services/arm_arch_svc.h> |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 19 | |
| 20 | uintptr_t plat_get_ns_image_entrypoint(void) |
| 21 | { |
| 22 | return BL33_BASE; |
| 23 | } |
| 24 | |
| 25 | unsigned int plat_get_syscnt_freq2(void) |
| 26 | { |
| 27 | return read_cntfrq_el0(); |
| 28 | } |
| 29 | |
| 30 | static uintptr_t boot_ctx_address; |
Yann Gautier | cf1360d | 2020-08-27 18:28:57 +0200 | [diff] [blame] | 31 | static uint16_t boot_itf_selected; |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 32 | |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 33 | void stm32mp_save_boot_ctx_address(uintptr_t address) |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 34 | { |
Yann Gautier | cf1360d | 2020-08-27 18:28:57 +0200 | [diff] [blame] | 35 | boot_api_context_t *boot_context = (boot_api_context_t *)address; |
| 36 | |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 37 | boot_ctx_address = address; |
Yann Gautier | cf1360d | 2020-08-27 18:28:57 +0200 | [diff] [blame] | 38 | boot_itf_selected = boot_context->boot_interface_selected; |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 41 | uintptr_t stm32mp_get_boot_ctx_address(void) |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 42 | { |
| 43 | return boot_ctx_address; |
| 44 | } |
| 45 | |
Yann Gautier | cf1360d | 2020-08-27 18:28:57 +0200 | [diff] [blame] | 46 | uint16_t stm32mp_get_boot_itf_selected(void) |
| 47 | { |
| 48 | return boot_itf_selected; |
| 49 | } |
| 50 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 51 | uintptr_t stm32mp_ddrctrl_base(void) |
| 52 | { |
Yann Gautier | a18f61b | 2020-05-05 17:58:40 +0200 | [diff] [blame] | 53 | return DDRCTRL_BASE; |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | uintptr_t stm32mp_ddrphyc_base(void) |
| 57 | { |
Yann Gautier | a18f61b | 2020-05-05 17:58:40 +0200 | [diff] [blame] | 58 | return DDRPHYC_BASE; |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | uintptr_t stm32mp_pwr_base(void) |
| 62 | { |
Yann Gautier | a18f61b | 2020-05-05 17:58:40 +0200 | [diff] [blame] | 63 | return PWR_BASE; |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | uintptr_t stm32mp_rcc_base(void) |
| 67 | { |
Yann Gautier | a18f61b | 2020-05-05 17:58:40 +0200 | [diff] [blame] | 68 | return RCC_BASE; |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Yann Gautier | f540a59 | 2019-05-22 19:13:51 +0200 | [diff] [blame] | 71 | bool 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 Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 79 | #if STM32MP_USE_STM32IMAGE |
Yann Gautier | e97b663 | 2019-04-19 10:48:36 +0200 | [diff] [blame] | 80 | int stm32mp_check_header(boot_api_image_header_t *header, uintptr_t buffer) |
| 81 | { |
| 82 | uint32_t i; |
| 83 | uint32_t img_checksum = 0U; |
| 84 | |
| 85 | /* |
| 86 | * Check header/payload validity: |
| 87 | * - Header magic |
| 88 | * - Header version |
| 89 | * - Payload checksum |
| 90 | */ |
| 91 | if (header->magic != BOOT_API_IMAGE_HEADER_MAGIC_NB) { |
| 92 | ERROR("Header magic\n"); |
| 93 | return -EINVAL; |
| 94 | } |
| 95 | |
| 96 | if (header->header_version != BOOT_API_HEADER_VERSION) { |
| 97 | ERROR("Header version\n"); |
| 98 | return -EINVAL; |
| 99 | } |
| 100 | |
| 101 | for (i = 0U; i < header->image_length; i++) { |
| 102 | img_checksum += *(uint8_t *)(buffer + i); |
| 103 | } |
| 104 | |
| 105 | if (header->payload_checksum != img_checksum) { |
| 106 | ERROR("Checksum: 0x%x (awaited: 0x%x)\n", img_checksum, |
| 107 | header->payload_checksum); |
| 108 | return -EINVAL; |
| 109 | } |
| 110 | |
| 111 | return 0; |
| 112 | } |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 113 | #endif /* STM32MP_USE_STM32IMAGE */ |
Yann Gautier | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 114 | |
| 115 | int stm32mp_map_ddr_non_cacheable(void) |
| 116 | { |
| 117 | return mmap_add_dynamic_region(STM32MP_DDR_BASE, STM32MP_DDR_BASE, |
| 118 | STM32MP_DDR_MAX_SIZE, |
Yann Gautier | f3bd87e | 2020-09-04 15:55:53 +0200 | [diff] [blame] | 119 | MT_NON_CACHEABLE | MT_RW | MT_SECURE); |
Yann Gautier | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | int stm32mp_unmap_ddr(void) |
| 123 | { |
| 124 | return mmap_remove_dynamic_region(STM32MP_DDR_BASE, |
| 125 | STM32MP_DDR_MAX_SIZE); |
| 126 | } |
Yann Gautier | ed6515d | 2021-03-08 15:03:35 +0100 | [diff] [blame] | 127 | |
| 128 | /***************************************************************************** |
| 129 | * plat_is_smccc_feature_available() - This function checks whether SMCCC |
| 130 | * feature is availabile for platform. |
| 131 | * @fid: SMCCC function id |
| 132 | * |
| 133 | * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and |
| 134 | * SMC_ARCH_CALL_NOT_SUPPORTED otherwise. |
| 135 | *****************************************************************************/ |
| 136 | int32_t plat_is_smccc_feature_available(u_register_t fid) |
| 137 | { |
| 138 | switch (fid) { |
| 139 | case SMCCC_ARCH_SOC_ID: |
| 140 | return SMC_ARCH_CALL_SUCCESS; |
| 141 | default: |
| 142 | return SMC_ARCH_CALL_NOT_SUPPORTED; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /* Get SOC version */ |
| 147 | int32_t plat_get_soc_version(void) |
| 148 | { |
| 149 | uint32_t chip_id = stm32mp_get_chip_dev_id(); |
| 150 | uint32_t manfid = SOC_ID_SET_JEP_106(JEDEC_ST_BKID, JEDEC_ST_MFID); |
| 151 | |
| 152 | return (int32_t)(manfid | (chip_id & SOC_ID_IMPL_DEF_MASK)); |
| 153 | } |
| 154 | |
| 155 | /* Get SOC revision */ |
| 156 | int32_t plat_get_soc_revision(void) |
| 157 | { |
| 158 | return (int32_t)(stm32mp_get_chip_version() & SOC_ID_REV_MASK); |
| 159 | } |