nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 1 | /* |
AlexeiFedorov | 3d3dea2 | 2023-04-06 15:36:27 +0100 | [diff] [blame] | 2 | * Copyright (c) 2022-2023, Arm Limited. All rights reserved. |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef REALM_RSI_H |
| 9 | #define REALM_RSI_H |
| 10 | |
| 11 | #include <stdint.h> |
AlexeiFedorov | 2f30f10 | 2023-03-13 19:37:46 +0000 | [diff] [blame] | 12 | #include <host_shared_data.h> |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 13 | #include <tftf_lib.h> |
| 14 | |
| 15 | #define SMC_RSI_CALL_BASE 0xC4000190 |
| 16 | #define SMC_RSI_FID(_x) (SMC_RSI_CALL_BASE + (_x)) |
| 17 | /* |
| 18 | * This file describes the Realm Services Interface (RSI) Application Binary |
| 19 | * Interface (ABI) for SMC calls made from within the Realm to the RMM and |
| 20 | * serviced by the RMM. |
| 21 | * |
| 22 | * See doc/rmm_interface.md for more details. |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * The major version number of the RSI implementation. Increase this whenever |
| 27 | * the binary format or semantics of the SMC calls change. |
| 28 | */ |
Shruti Gupta | 40de8ec | 2023-10-12 21:45:12 +0100 | [diff] [blame] | 29 | #define RSI_ABI_VERSION_MAJOR 1U |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * The minor version number of the RSI implementation. Increase this when |
| 33 | * a bug is fixed, or a feature is added without breaking binary compatibility. |
| 34 | */ |
| 35 | #define RSI_ABI_VERSION_MINOR 0U |
| 36 | |
| 37 | #define RSI_ABI_VERSION_VAL ((RSI_ABI_VERSION_MAJOR << 16U) | \ |
| 38 | RSI_ABI_VERSION_MINOR) |
| 39 | |
| 40 | #define RSI_ABI_VERSION_GET_MAJOR(_version) ((_version) >> 16U) |
| 41 | #define RSI_ABI_VERSION_GET_MINOR(_version) ((_version) & 0xFFFFU) |
| 42 | |
| 43 | |
| 44 | /* RSI Status code enumeration as per Section D4.3.6 of the RMM Spec */ |
| 45 | typedef enum { |
| 46 | /* Command completed successfully */ |
| 47 | RSI_SUCCESS = 0U, |
| 48 | |
| 49 | /* |
| 50 | * The value of a command input value |
| 51 | * caused the command to fail |
| 52 | */ |
| 53 | RSI_ERROR_INPUT = 1U, |
| 54 | |
| 55 | /* |
| 56 | * The state of the current Realm or current REC |
| 57 | * does not match the state expected by the command |
| 58 | */ |
| 59 | RSI_ERROR_STATE = 2U, |
| 60 | |
| 61 | /* The operation requested by the command is not complete */ |
| 62 | RSI_INCOMPLETE = 3U, |
| 63 | |
| 64 | RSI_ERROR_COUNT |
| 65 | } rsi_status_t; |
| 66 | |
AlexeiFedorov | dff904b | 2024-08-05 17:11:18 +0100 | [diff] [blame^] | 67 | /* Size of Realm Personalization Value */ |
| 68 | #define RSI_RPV_SIZE 64U |
| 69 | |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 70 | struct rsi_realm_config { |
| 71 | /* IPA width in bits */ |
AlexeiFedorov | dff904b | 2024-08-05 17:11:18 +0100 | [diff] [blame^] | 72 | SET_MEMBER(unsigned long ipa_width, 0, 8); /* Offset 0 */ |
| 73 | /* Hash algorithm */ |
| 74 | SET_MEMBER(unsigned long algorithm, 8, 0x200); /* Offset 8 */ |
| 75 | /* Realm Personalization Value */ |
| 76 | SET_MEMBER(unsigned char rpv[RSI_RPV_SIZE], 0x200, 0x1000); /* Offset 0x200 */ |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /* |
| 80 | * arg0 == IPA address of target region |
| 81 | * arg1 == Size of target region in bytes |
| 82 | * arg2 == RIPAS value |
| 83 | * ret0 == Status / error |
| 84 | * ret1 == Top of modified IPA range |
| 85 | */ |
| 86 | |
AlexeiFedorov | 3d3dea2 | 2023-04-06 15:36:27 +0100 | [diff] [blame] | 87 | #define RSI_HOST_CALL_NR_GPRS 31U |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 88 | |
| 89 | struct rsi_host_call { |
| 90 | SET_MEMBER(struct { |
| 91 | /* Immediate value */ |
| 92 | unsigned int imm; /* Offset 0 */ |
| 93 | /* Registers */ |
| 94 | unsigned long gprs[RSI_HOST_CALL_NR_GPRS]; |
| 95 | }, 0, 0x100); |
| 96 | }; |
| 97 | |
| 98 | /* |
AlexeiFedorov | 3d3dea2 | 2023-04-06 15:36:27 +0100 | [diff] [blame] | 99 | * arg0 == struct rsi_host_call address |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 100 | */ |
| 101 | #define RSI_HOST_CALL SMC_RSI_FID(9U) |
| 102 | |
| 103 | |
Shruti Gupta | 40de8ec | 2023-10-12 21:45:12 +0100 | [diff] [blame] | 104 | #define RSI_VERSION SMC_RSI_FID(0U) |
AlexeiFedorov | 2f30f10 | 2023-03-13 19:37:46 +0000 | [diff] [blame] | 105 | |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 106 | /* |
| 107 | * arg0 == struct rsi_realm_config address |
| 108 | */ |
| 109 | #define RSI_REALM_CONFIG SMC_RSI_FID(6U) |
Shruti Gupta | bb77219 | 2023-10-09 16:08:28 +0100 | [diff] [blame] | 110 | #define RSI_IPA_STATE_SET SMC_RSI_FID(7U) |
| 111 | #define RSI_IPA_STATE_GET SMC_RSI_FID(8U) |
| 112 | |
| 113 | typedef enum { |
| 114 | RSI_EMPTY = 0U, |
| 115 | RSI_RAM, |
AlexeiFedorov | dff904b | 2024-08-05 17:11:18 +0100 | [diff] [blame^] | 116 | RSI_DESTROYED, |
| 117 | RSI_DEV |
Shruti Gupta | bb77219 | 2023-10-09 16:08:28 +0100 | [diff] [blame] | 118 | } rsi_ripas_type; |
| 119 | |
| 120 | typedef enum { |
| 121 | RSI_ACCEPT = 0U, |
| 122 | RSI_REJECT |
| 123 | } rsi_ripas_respose_type; |
| 124 | |
| 125 | #define RSI_NO_CHANGE_DESTROYED 0UL |
| 126 | #define RSI_CHANGE_DESTROYED 1UL |
| 127 | |
| 128 | /* Request RIPAS of a target IPA range to be changed to a specified value. */ |
| 129 | u_register_t rsi_ipa_state_set(u_register_t base, |
| 130 | u_register_t top, |
| 131 | rsi_ripas_type ripas, |
| 132 | u_register_t flag, |
| 133 | u_register_t *new_base, |
| 134 | rsi_ripas_respose_type *response); |
| 135 | |
| 136 | /* Request RIPAS of a target IPA */ |
| 137 | u_register_t rsi_ipa_state_get(u_register_t adr, rsi_ripas_type *ripas); |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 138 | |
| 139 | /* This function return RSI_ABI_VERSION */ |
Shruti Gupta | 40de8ec | 2023-10-12 21:45:12 +0100 | [diff] [blame] | 140 | u_register_t rsi_get_version(u_register_t req_ver); |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 141 | |
| 142 | /* This function will call the Host to request IPA of the NS shared buffer */ |
| 143 | u_register_t rsi_get_ns_buffer(void); |
| 144 | |
| 145 | /* This function call Host and request to exit Realm with proper exit code */ |
| 146 | void rsi_exit_to_host(enum host_call_cmd exit_code); |
| 147 | |
| 148 | #endif /* REALM_RSI_H */ |