1 /*
2 * Copyright (c) 2022 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <soc_secure.h>
8 #include <errno.h>
9
10 #include "nrf.h"
11
12 #include "tfm_platform_api.h"
13 #include "tfm_ioctl_api.h"
14
15 #if NRF_GPIO_HAS_SEL
soc_secure_gpio_pin_mcu_select(uint32_t pin_number,nrf_gpio_pin_sel_t mcu)16 void soc_secure_gpio_pin_mcu_select(uint32_t pin_number, nrf_gpio_pin_sel_t mcu)
17 {
18 uint32_t result;
19 enum tfm_platform_err_t err;
20
21 err = tfm_platform_gpio_pin_mcu_select(pin_number, mcu, &result);
22 __ASSERT(err == TFM_PLATFORM_ERR_SUCCESS, "TFM platform error (%d)", err);
23 __ASSERT(result == 0, "GPIO service error (%d)", result);
24 }
25 #endif /* NRF_GPIO_HAS_SEL */
26
soc_secure_mem_read(void * dst,void * src,size_t len)27 int soc_secure_mem_read(void *dst, void *src, size_t len)
28 {
29 enum tfm_platform_err_t status;
30 uint32_t result;
31
32 status = tfm_platform_mem_read(dst, (uintptr_t)src, len, &result);
33
34 switch (status) {
35 case TFM_PLATFORM_ERR_INVALID_PARAM:
36 return -EINVAL;
37 case TFM_PLATFORM_ERR_NOT_SUPPORTED:
38 return -ENOTSUP;
39 case TFM_PLATFORM_ERR_SUCCESS:
40 if (result == 0) {
41 return 0;
42 }
43 /* Fallthrough */
44 default:
45 return -EPERM;
46 }
47 }
48