1 /* 2 * Copyright (c) 2021-2023, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __SVC_NUM_H__ 9 #define __SVC_NUM_H__ 10 11 /* 12 * The SVC number field descriptions. 13 * 14 * Bit assignments: 15 * +-------+----------+--------------+-----+-------+ 16 * | Bit | 7 | 6 | 5 | 4:0 | 17 * --------+----------+--------------+-----+-------+ 18 * | | Platform | Handler Mode | PSA | Index | 19 * +-------+----------+--------------+-----+-------+ 20 * 21 * Platform, bit [7] 22 * Whether it's a platform SVC that should be handled by platform codes. 23 * 1 - The SVC should be left to platform to handle 24 * 0 - The SVC should be handled by TF-M 25 * 26 * Handler Mode, bit [6]: 27 * Whether the SVC should be called from Handler mode. 28 * 1 - The SVC can be only called from Handler mode 29 * 0 - The SVC can be only called from Thread mode 30 * 31 * PSA, bit [5]: 32 * Whether it's PSA API or TF-M SPM SVC requests. 33 * Ignored when Bit [7] is 1. 34 * 1 - PSA API requests 35 * 0 - TF-M SPM SVC requests 36 * 37 * Index, bits [4:0]: 38 * The SVC number index 39 */ 40 41 #define TFM_SVC_NUM_PLATFORM_POS 7U 42 #define TFM_SVC_NUM_PLATFORM_MSK (1U << TFM_SVC_NUM_PLATFORM_POS) 43 44 #define TFM_SVC_NUM_HANDLER_MODE_POS 6U 45 #define TFM_SVC_NUM_HANDLER_MODE_MSK (1U << TFM_SVC_NUM_HANDLER_MODE_POS) 46 47 #define TFM_SVC_NUM_PSA_API_POS 5U 48 #define TFM_SVC_NUM_PSA_API_MSK (1U << TFM_SVC_NUM_PSA_API_POS) 49 50 #define TFM_SVC_NUM_INDEX_MSK (0x1FU) 51 52 /* SVC number constructors */ 53 54 /* SPM SVC from Thread mode */ 55 #define TFM_SVC_NUM_SPM_THREAD(index) ((index) & TFM_SVC_NUM_INDEX_MSK) 56 /* SPM SVC from Handler mode */ 57 #define TFM_SVC_NUM_SPM_HANDLER(index) (TFM_SVC_NUM_HANDLER_MODE_MSK | \ 58 ((index) & TFM_SVC_NUM_INDEX_MSK)) 59 /* PSA API SVC from Thread mode (from Handler mode is not supported) */ 60 #define TFM_SVC_NUM_PSA_API_THREAD(index) (TFM_SVC_NUM_PSA_API_MSK | \ 61 ((index) & TFM_SVC_NUM_INDEX_MSK)) 62 /* Platform SVC from Thread mode */ 63 #define TFM_SVC_NUM_PLATFORM_THREAD(index) (TFM_SVC_NUM_PLATFORM_MSK | \ 64 ((index) & TFM_SVC_NUM_INDEX_MSK)) 65 /* Platform SVC from Handler mode */ 66 #define TFM_SVC_NUM_PLATFORM_HANDLER(index) (TFM_SVC_NUM_PLATFORM_MSK | \ 67 TFM_SVC_NUM_HANDLER_MODE_MSK |\ 68 ((index) & TFM_SVC_NUM_INDEX_MSK)) 69 70 /* TF-M SPM and for Thread mode */ 71 #define TFM_SVC_SPM_INIT TFM_SVC_NUM_SPM_THREAD(0) 72 #define TFM_SVC_FLIH_FUNC_RETURN TFM_SVC_NUM_SPM_THREAD(1) 73 #define TFM_SVC_OUTPUT_UNPRIV_STRING TFM_SVC_NUM_SPM_THREAD(2) 74 #define TFM_SVC_GET_BOOT_DATA TFM_SVC_NUM_SPM_THREAD(3) 75 #define TFM_SVC_THREAD_MODE_SPM_RETURN TFM_SVC_NUM_SPM_THREAD(4) 76 77 /* TF-M SPM and for Handler mode */ 78 #define TFM_SVC_PREPARE_DEPRIV_FLIH TFM_SVC_NUM_SPM_HANDLER(0) 79 80 /* PSA API (from Thread mode, Handler mode is not supported */ 81 /* PSA Client APIs */ 82 #define TFM_SVC_PSA_FRAMEWORK_VERSION TFM_SVC_NUM_PSA_API_THREAD(0) 83 #define TFM_SVC_PSA_VERSION TFM_SVC_NUM_PSA_API_THREAD(1) 84 #define TFM_SVC_PSA_CALL TFM_SVC_NUM_PSA_API_THREAD(2) 85 #define TFM_SVC_PSA_CONNECT TFM_SVC_NUM_PSA_API_THREAD(3) 86 #define TFM_SVC_PSA_CLOSE TFM_SVC_NUM_PSA_API_THREAD(4) 87 /* PSA Secure Partition APIs */ 88 #define TFM_SVC_PSA_WAIT TFM_SVC_NUM_PSA_API_THREAD(5) 89 #define TFM_SVC_PSA_GET TFM_SVC_NUM_PSA_API_THREAD(6) 90 #define TFM_SVC_PSA_SET_RHANDLE TFM_SVC_NUM_PSA_API_THREAD(7) 91 #define TFM_SVC_PSA_READ TFM_SVC_NUM_PSA_API_THREAD(8) 92 #define TFM_SVC_PSA_SKIP TFM_SVC_NUM_PSA_API_THREAD(9) 93 #define TFM_SVC_PSA_WRITE TFM_SVC_NUM_PSA_API_THREAD(10) 94 #define TFM_SVC_PSA_REPLY TFM_SVC_NUM_PSA_API_THREAD(11) 95 #define TFM_SVC_PSA_NOTIFY TFM_SVC_NUM_PSA_API_THREAD(12) 96 #define TFM_SVC_PSA_CLEAR TFM_SVC_NUM_PSA_API_THREAD(13) 97 #define TFM_SVC_PSA_EOI TFM_SVC_NUM_PSA_API_THREAD(14) 98 #define TFM_SVC_PSA_PANIC TFM_SVC_NUM_PSA_API_THREAD(15) 99 #define TFM_SVC_PSA_LIFECYCLE TFM_SVC_NUM_PSA_API_THREAD(16) 100 #define TFM_SVC_PSA_IRQ_ENABLE TFM_SVC_NUM_PSA_API_THREAD(17) 101 #define TFM_SVC_PSA_IRQ_DISABLE TFM_SVC_NUM_PSA_API_THREAD(18) 102 #define TFM_SVC_PSA_RESET_SIGNAL TFM_SVC_NUM_PSA_API_THREAD(19) 103 #define TFM_SVC_AGENT_PSA_CALL TFM_SVC_NUM_PSA_API_THREAD(20) 104 #define TFM_SVC_AGENT_PSA_CONNECT TFM_SVC_NUM_PSA_API_THREAD(21) 105 106 #define TFM_SVC_IS_PLATFORM(svc_num) (!!((svc_num) & TFM_SVC_NUM_PLATFORM_MSK)) 107 #define TFM_SVC_IS_HANDLER_MODE(svc_num) (!!((svc_num) & TFM_SVC_NUM_HANDLER_MODE_MSK)) 108 #define TFM_SVC_IS_PSA_API(svc_num) (((svc_num) & (TFM_SVC_NUM_PLATFORM_MSK | \ 109 TFM_SVC_NUM_PSA_API_MSK)) \ 110 == TFM_SVC_NUM_PSA_API_MSK) 111 #define TFM_SVC_IS_SPM(svc_num) (((svc_num) & (TFM_SVC_NUM_PLATFORM_MSK | \ 112 TFM_SVC_NUM_PSA_API_MSK)) == 0) 113 114 #endif /* __SVC_NUM_H__ */ 115