Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 1 | /* |
Yann Gautier | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2020, 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 | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 15 | #include <lib/xlat_tables/xlat_tables_v2.h> |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 16 | #include <plat/common/platform.h> |
| 17 | |
| 18 | uintptr_t plat_get_ns_image_entrypoint(void) |
| 19 | { |
| 20 | return BL33_BASE; |
| 21 | } |
| 22 | |
| 23 | unsigned int plat_get_syscnt_freq2(void) |
| 24 | { |
| 25 | return read_cntfrq_el0(); |
| 26 | } |
| 27 | |
| 28 | static uintptr_t boot_ctx_address; |
| 29 | |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 30 | void stm32mp_save_boot_ctx_address(uintptr_t address) |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 31 | { |
| 32 | boot_ctx_address = address; |
| 33 | } |
| 34 | |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 35 | uintptr_t stm32mp_get_boot_ctx_address(void) |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 36 | { |
| 37 | return boot_ctx_address; |
| 38 | } |
| 39 | |
Yann Gautier | 3d78a2e | 2019-02-14 11:01:20 +0100 | [diff] [blame] | 40 | uintptr_t stm32mp_ddrctrl_base(void) |
| 41 | { |
| 42 | static uintptr_t ddrctrl_base; |
| 43 | |
| 44 | if (ddrctrl_base == 0) { |
| 45 | ddrctrl_base = dt_get_ddrctrl_base(); |
| 46 | |
| 47 | assert(ddrctrl_base == DDRCTRL_BASE); |
| 48 | } |
| 49 | |
| 50 | return ddrctrl_base; |
| 51 | } |
| 52 | |
| 53 | uintptr_t stm32mp_ddrphyc_base(void) |
| 54 | { |
| 55 | static uintptr_t ddrphyc_base; |
| 56 | |
| 57 | if (ddrphyc_base == 0) { |
| 58 | ddrphyc_base = dt_get_ddrphyc_base(); |
| 59 | |
| 60 | assert(ddrphyc_base == DDRPHYC_BASE); |
| 61 | } |
| 62 | |
| 63 | return ddrphyc_base; |
| 64 | } |
| 65 | |
| 66 | uintptr_t stm32mp_pwr_base(void) |
| 67 | { |
| 68 | static uintptr_t pwr_base; |
| 69 | |
| 70 | if (pwr_base == 0) { |
| 71 | pwr_base = dt_get_pwr_base(); |
| 72 | |
| 73 | assert(pwr_base == PWR_BASE); |
| 74 | } |
| 75 | |
| 76 | return pwr_base; |
| 77 | } |
| 78 | |
| 79 | uintptr_t stm32mp_rcc_base(void) |
| 80 | { |
| 81 | static uintptr_t rcc_base; |
| 82 | |
| 83 | if (rcc_base == 0) { |
| 84 | rcc_base = fdt_rcc_read_addr(); |
| 85 | |
| 86 | assert(rcc_base == RCC_BASE); |
| 87 | } |
| 88 | |
| 89 | return rcc_base; |
| 90 | } |
| 91 | |
Yann Gautier | f540a59 | 2019-05-22 19:13:51 +0200 | [diff] [blame] | 92 | bool stm32mp_lock_available(void) |
| 93 | { |
| 94 | const uint32_t c_m_bits = SCTLR_M_BIT | SCTLR_C_BIT; |
| 95 | |
| 96 | /* The spinlocks are used only when MMU and data cache are enabled */ |
| 97 | return (read_sctlr() & c_m_bits) == c_m_bits; |
| 98 | } |
| 99 | |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 100 | uintptr_t stm32_get_gpio_bank_base(unsigned int bank) |
| 101 | { |
| 102 | if (bank == GPIO_BANK_Z) { |
| 103 | return GPIOZ_BASE; |
| 104 | } |
| 105 | |
| 106 | assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K); |
| 107 | |
| 108 | return GPIOA_BASE + (bank * GPIO_BANK_OFFSET); |
| 109 | } |
| 110 | |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 111 | uint32_t stm32_get_gpio_bank_offset(unsigned int bank) |
| 112 | { |
| 113 | if (bank == GPIO_BANK_Z) { |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K); |
| 118 | |
| 119 | return bank * GPIO_BANK_OFFSET; |
| 120 | } |
Yann Gautier | e97b663 | 2019-04-19 10:48:36 +0200 | [diff] [blame] | 121 | |
| 122 | int stm32mp_check_header(boot_api_image_header_t *header, uintptr_t buffer) |
| 123 | { |
| 124 | uint32_t i; |
| 125 | uint32_t img_checksum = 0U; |
| 126 | |
| 127 | /* |
| 128 | * Check header/payload validity: |
| 129 | * - Header magic |
| 130 | * - Header version |
| 131 | * - Payload checksum |
| 132 | */ |
| 133 | if (header->magic != BOOT_API_IMAGE_HEADER_MAGIC_NB) { |
| 134 | ERROR("Header magic\n"); |
| 135 | return -EINVAL; |
| 136 | } |
| 137 | |
| 138 | if (header->header_version != BOOT_API_HEADER_VERSION) { |
| 139 | ERROR("Header version\n"); |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | |
| 143 | for (i = 0U; i < header->image_length; i++) { |
| 144 | img_checksum += *(uint8_t *)(buffer + i); |
| 145 | } |
| 146 | |
| 147 | if (header->payload_checksum != img_checksum) { |
| 148 | ERROR("Checksum: 0x%x (awaited: 0x%x)\n", img_checksum, |
| 149 | header->payload_checksum); |
| 150 | return -EINVAL; |
| 151 | } |
| 152 | |
| 153 | return 0; |
| 154 | } |
Yann Gautier | a55169b | 2020-01-10 18:18:59 +0100 | [diff] [blame] | 155 | |
| 156 | int stm32mp_map_ddr_non_cacheable(void) |
| 157 | { |
| 158 | return mmap_add_dynamic_region(STM32MP_DDR_BASE, STM32MP_DDR_BASE, |
| 159 | STM32MP_DDR_MAX_SIZE, |
| 160 | MT_NON_CACHEABLE | MT_RW | MT_NS); |
| 161 | } |
| 162 | |
| 163 | int stm32mp_unmap_ddr(void) |
| 164 | { |
| 165 | return mmap_remove_dynamic_region(STM32MP_DDR_BASE, |
| 166 | STM32MP_DDR_MAX_SIZE); |
| 167 | } |