Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 1 | /* |
Jamie Fox | d4c3c74 | 2020-02-17 16:08:40 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, Arm Limited. All rights reserved. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 8 | #include <arm_cmse.h> |
| 9 | |
Ken Liu | 1f345b0 | 2020-05-30 21:11:05 +0800 | [diff] [blame] | 10 | #include "tfm/tfm_core_svc.h" |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 11 | #include "tfm_secure_api.h" |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 12 | #include "tfm_internal.h" |
Mingyang Sun | 67a1c0e | 2020-06-04 17:18:16 +0800 | [diff] [blame] | 13 | #include "tfm/tfm_spm_services_api.h" |
Ken Liu | 1f345b0 | 2020-05-30 21:11:05 +0800 | [diff] [blame] | 14 | #include "tfm/spm_api.h" |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 15 | #include "psa/service.h" |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 16 | |
Summer Qin | e304f96 | 2020-02-20 11:03:55 +0800 | [diff] [blame] | 17 | #ifndef TFM_PSA_API |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 18 | nsfptr_t ns_entry; |
| 19 | |
| 20 | void jump_to_ns_code(void) |
| 21 | { |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 22 | /* Calls the non-secure Reset_Handler to jump to the non-secure binary */ |
| 23 | ns_entry(); |
| 24 | } |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 25 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 26 | __attribute__((naked)) |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 27 | int32_t tfm_core_get_caller_client_id(int32_t *caller_client_id) |
| 28 | { |
Antonio de Angelis | f2dea5b | 2019-04-16 14:50:50 +0100 | [diff] [blame] | 29 | __ASM volatile( |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 30 | "SVC %0\n" |
| 31 | "BX LR\n" |
| 32 | : : "I" (TFM_SVC_GET_CALLER_CLIENT_ID)); |
| 33 | } |
| 34 | |
| 35 | __attribute__((naked)) |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 36 | int32_t tfm_core_validate_secure_caller(void) |
Miklos Balint | 4d48762 | 2018-10-03 14:04:54 +0200 | [diff] [blame] | 37 | { |
Antonio de Angelis | f2dea5b | 2019-04-16 14:50:50 +0100 | [diff] [blame] | 38 | __ASM volatile( |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 39 | "SVC %0\n" |
| 40 | "BX lr\n" |
| 41 | : : "I" (TFM_SVC_VALIDATE_SECURE_CALLER)); |
Miklos Balint | 4d48762 | 2018-10-03 14:04:54 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 44 | #endif |
| 45 | |
Miklos Balint | 4d48762 | 2018-10-03 14:04:54 +0200 | [diff] [blame] | 46 | __attribute__((naked)) |
| 47 | int32_t tfm_spm_request(void) |
| 48 | { |
Antonio de Angelis | f2dea5b | 2019-04-16 14:50:50 +0100 | [diff] [blame] | 49 | __ASM volatile( |
Miklos Balint | 4d48762 | 2018-10-03 14:04:54 +0200 | [diff] [blame] | 50 | "SVC %0\n" |
| 51 | "BX lr\n" |
| 52 | : : "I" (TFM_SVC_SPM_REQUEST)); |
| 53 | } |
| 54 | |
| 55 | __attribute__((naked)) |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 56 | int32_t tfm_spm_request_reset_vote(void) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 57 | { |
Antonio de Angelis | f2dea5b | 2019-04-16 14:50:50 +0100 | [diff] [blame] | 58 | __ASM volatile( |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 59 | "MOVS R0, %0\n" |
| 60 | "B tfm_spm_request\n" |
| 61 | : : "I" (TFM_SPM_REQUEST_RESET_VOTE)); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Tamas Ban | 9ff535b | 2018-09-18 08:15:18 +0100 | [diff] [blame] | 64 | __attribute__((naked)) |
Tamas Ban | a24ce04 | 2019-02-20 11:50:22 +0000 | [diff] [blame] | 65 | int32_t tfm_core_get_boot_data(uint8_t major_type, |
| 66 | struct tfm_boot_data *boot_status, |
| 67 | uint32_t len) |
Tamas Ban | 9ff535b | 2018-09-18 08:15:18 +0100 | [diff] [blame] | 68 | { |
Antonio de Angelis | f2dea5b | 2019-04-16 14:50:50 +0100 | [diff] [blame] | 69 | __ASM volatile( |
Tamas Ban | 9ff535b | 2018-09-18 08:15:18 +0100 | [diff] [blame] | 70 | "SVC %0\n" |
| 71 | "BX lr\n" |
| 72 | : : "I" (TFM_SVC_GET_BOOT_DATA)); |
| 73 | } |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 74 | |
| 75 | __attribute__((naked)) |
| 76 | void tfm_enable_irq(psa_signal_t irq_signal) |
| 77 | { |
| 78 | __ASM("SVC %0\n" |
| 79 | "BX LR\n" |
| 80 | : : "I" (TFM_SVC_ENABLE_IRQ)); |
| 81 | } |
| 82 | |
| 83 | __attribute__((naked)) |
| 84 | void tfm_disable_irq(psa_signal_t irq_signal) |
| 85 | { |
| 86 | __ASM("SVC %0\n" |
| 87 | "BX LR\n" |
| 88 | : : "I" (TFM_SVC_DISABLE_IRQ)); |
| 89 | } |
| 90 | |
| 91 | #ifndef TFM_PSA_API |
| 92 | |
| 93 | __attribute__((naked)) |
| 94 | static psa_signal_t psa_wait_internal(psa_signal_t signal_mask, |
| 95 | uint32_t timeout) |
| 96 | { |
| 97 | __ASM("SVC %0\n" |
| 98 | "BX LR\n" |
| 99 | : : "I" (TFM_SVC_PSA_WAIT)); |
| 100 | } |
| 101 | |
| 102 | psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout) |
| 103 | { |
| 104 | /* FIXME: By using the 'WFI' instruction this function blocks until an |
| 105 | * interrupt happens. It is necessary to do this here as tfm_core_psa_wait |
| 106 | * runs with the priority of the SVC, so it cannot be interrupted, so |
| 107 | * waiting in it for the required interrupt to happen is not an option. |
| 108 | */ |
| 109 | psa_signal_t actual_signal_mask; |
| 110 | |
| 111 | while (1) { |
| 112 | actual_signal_mask = psa_wait_internal(signal_mask, timeout); |
| 113 | if ((actual_signal_mask & signal_mask) != 0) { |
| 114 | return actual_signal_mask; |
| 115 | } |
| 116 | __WFI(); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | __attribute__((naked)) |
| 121 | void psa_eoi(psa_signal_t irq_signal) |
| 122 | { |
| 123 | __ASM("SVC %0\n" |
| 124 | "BX LR\n" |
| 125 | : : "I" (TFM_SVC_PSA_EOI)); |
| 126 | } |
| 127 | |
| 128 | #endif |