diff options
author | Shawn Shan <Shawn.Shan@arm.com> | 2021-08-23 16:09:23 +0800 |
---|---|---|
committer | Shawn Shan <Shawn.Shan@arm.com> | 2021-09-17 10:12:17 +0800 |
commit | a0787c298c8b40adaca6b9d96d8771295da6f165 (patch) | |
tree | eeb91c375e12ba12358fa679c93f21b4098cfe4c | |
parent | e92ab1ceb899d4280942258319db8554665734a3 (diff) | |
download | trusted-firmware-m-a0787c298c8b40adaca6b9d96d8771295da6f165.tar.gz |
Platform: PSOC64: Introduce platform binding HAL
This API (tfm_hal_bind_boundaries) binds partition with platform by
a p_boundaries handle, to let platform records partition info and apply
specific settings. Check the API comment for details.
The patch also changes the boundary update HAL API.
Change-Id: I76e981d23d25c99518ae6c97a83f2506d28b9cf3
Signed-off-by: Shawn Shan <Shawn.Shan@arm.com>
-rw-r--r-- | platform/ext/target/cypress/psoc64/mmio_defs.h | 37 | ||||
-rw-r--r-- | platform/ext/target/cypress/psoc64/spm_hal.c | 13 | ||||
-rw-r--r-- | platform/ext/target/cypress/psoc64/tfm_hal_isolation.c | 75 | ||||
-rw-r--r-- | platform/ext/target/cypress/psoc64/tfm_peripherals_def.h | 2 |
4 files changed, 112 insertions, 15 deletions
diff --git a/platform/ext/target/cypress/psoc64/mmio_defs.h b/platform/ext/target/cypress/psoc64/mmio_defs.h new file mode 100644 index 0000000000..e6108b8c2c --- /dev/null +++ b/platform/ext/target/cypress/psoc64/mmio_defs.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#ifndef __MMIO_DEFS_H__ +#define __MMIO_DEFS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> +#include "tfm_peripherals_def.h" + +/* Boundary handle binding macros. */ +#define HANDLE_PER_ATTR_BITS (0x4) +#define HANDLE_ATTR_PRIV_MASK ((1 << HANDLE_PER_ATTR_BITS) - 1) + +/* Allowed named MMIO of this platform */ +const uintptr_t partition_named_mmio_list[] = { + (uintptr_t)TFM_PERIPHERAL_TIMER0, + (uintptr_t)TFM_PERIPHERAL_STD_UART, +}; + +/* + * Platform PSOC64 only has named MMIO. + * If the platform has numbered MMIO, define them in another list. + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __MMIO_DEFS_H__ */ diff --git a/platform/ext/target/cypress/psoc64/spm_hal.c b/platform/ext/target/cypress/psoc64/spm_hal.c index d7f9549bcd..fb912cc312 100644 --- a/platform/ext/target/cypress/psoc64/spm_hal.c +++ b/platform/ext/target/cypress/psoc64/spm_hal.c @@ -48,19 +48,6 @@ static enum tfm_plat_err_t handle_boot_wdt(void) return TFM_PLAT_ERR_SUCCESS; } -enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation( - bool privileged, - const struct platform_data_t *platform_data) -{ - (void) privileged; /* Unused parameter */ - if (!platform_data) { - return TFM_PLAT_ERR_INVALID_INPUT; - } - /* TBD */ - - return TFM_PLAT_ERR_SUCCESS; -} - uint32_t tfm_spm_hal_get_ns_VTOR(void) { return memory_regions.non_secure_code_start; diff --git a/platform/ext/target/cypress/psoc64/tfm_hal_isolation.c b/platform/ext/target/cypress/psoc64/tfm_hal_isolation.c index 992ea30745..098e639a27 100644 --- a/platform/ext/target/cypress/psoc64/tfm_hal_isolation.c +++ b/platform/ext/target/cypress/psoc64/tfm_hal_isolation.c @@ -5,12 +5,17 @@ * */ +#include "array.h" #include "cy_device.h" +#include "mmio_defs.h" #include "target_cfg.h" #include "tfm_api.h" #include "tfm_hal_defs.h" #include "tfm_multi_core.h" #include "tfm_plat_defs.h" +#include "tfm_peripherals_def.h" +#include "load/asset_defs.h" +#include "load/spm_load_api.h" enum tfm_hal_status_t tfm_hal_set_up_static_boundaries(void) { @@ -44,3 +49,73 @@ enum tfm_hal_status_t tfm_hal_memory_has_access(uintptr_t base, return TFM_HAL_SUCCESS; } + +/* + * Implementation of tfm_hal_bind_boundaries() on PSOC64: + * + * The API encodes some attributes into a handle and returns it to SPM. + * The attributes include isolation boundaries, privilege, and MMIO information. + * When scheduler switches running partitions, SPM compares the handle between + * partitions to know if boundary update is necessary. If update is required, + * SPM passes the handle to platform to do platform settings and update + * isolation boundaries. + */ +enum tfm_hal_status_t tfm_hal_bind_boundaries( + const struct partition_load_info_t *p_ldinf, + void **pp_boundaries) +{ + uint32_t i, j; + bool privileged; + const struct asset_desc_t *p_asset; + + if (!p_ldinf || !pp_boundaries) { + return TFM_HAL_ERROR_GENERIC; + } + +#if TFM_LVL == 1 + privileged = true; +#else + privileged = !!(p_ldinf->flags & SPM_PART_FLAG_PSA_ROT); +#endif + + p_asset = (const struct asset_desc_t *)LOAD_INFO_ASSET(p_ldinf); + + /* + * Validate if the named MMIO of partition is allowed by the platform. + * Otherwise, skip validation. + * + * NOTE: Need to add validation of numbered MMIO if platform requires. + */ + for (i = 0; i < p_ldinf->nassets; i++) { + if (!(p_asset[i].attr & ASSET_ATTR_NAMED_MMIO)) { + continue; + } + for (j = 0; j < ARRAY_SIZE(partition_named_mmio_list); j++) { + if (p_asset[i].dev.dev_ref == partition_named_mmio_list[j]) { + break; + } + } + + if (j == ARRAY_SIZE(partition_named_mmio_list)) { + return TFM_HAL_ERROR_GENERIC; + } + } + *pp_boundaries = (void *)(((uint32_t)privileged) & HANDLE_ATTR_PRIV_MASK); + + return TFM_HAL_SUCCESS; +} + +enum tfm_hal_status_t tfm_hal_update_boundaries( + const struct partition_load_info_t *p_ldinf, + void *p_boundaries) +{ + CONTROL_Type ctrl; + bool privileged = !!((uint32_t)p_boundaries & HANDLE_ATTR_PRIV_MASK); + + /* Privileged level is required to be set always */ + ctrl.w = __get_CONTROL(); + ctrl.b.nPRIV = privileged ? 0 : 1; + __set_CONTROL(ctrl.w); + + return TFM_HAL_SUCCESS; +} diff --git a/platform/ext/target/cypress/psoc64/tfm_peripherals_def.h b/platform/ext/target/cypress/psoc64/tfm_peripherals_def.h index b19882562c..7327f203f0 100644 --- a/platform/ext/target/cypress/psoc64/tfm_peripherals_def.h +++ b/platform/ext/target/cypress/psoc64/tfm_peripherals_def.h @@ -21,11 +21,9 @@ extern "C" { struct platform_data_t; extern struct platform_data_t tfm_peripheral_std_uart; -extern struct platform_data_t tfm_peripheral_uart1; extern struct platform_data_t tfm_peripheral_timer0; #define TFM_PERIPHERAL_STD_UART (&tfm_peripheral_std_uart) -#define TFM_PERIPHERAL_UART1 (&tfm_peripheral_uart1) #define TFM_PERIPHERAL_TIMER0 (&tfm_peripheral_timer0) #ifdef __cplusplus |