1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2026 Arm Ltd 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #ifndef _MACHINE_RSI_H_ 29 #define _MACHINE_RSI_H_ 30 31 extern uint64_t prot_ns_shared; 32 33 bool in_realm(void); 34 35 void arm64_rsi_setup_memory(void); 36 37 /* 38 * The major version number of the RSI implementation. This is increased when 39 * the binary format or semantics of the SMC calls change. 40 */ 41 #define RSI_ABI_VERSION_MAJOR UL(1) 42 43 /* 44 * The minor version number of the RSI implementation. This is increased when 45 * a bug is fixed, or a feature is added without breaking binary compatibility. 46 */ 47 #define RSI_ABI_VERSION_MINOR UL(0) 48 49 #define RSI_ABI_VERSION ((RSI_ABI_VERSION_MAJOR << 16) | \ 50 RSI_ABI_VERSION_MINOR) 51 52 #define RSI_ABI_VERSION_GET_MAJOR(_version) ((_version) >> 16) 53 #define RSI_ABI_VERSION_GET_MINOR(_version) ((_version) & 0xFFFF) 54 55 #define RSI_SUCCESS UL(0) 56 #define RSI_ERROR_INPUT UL(1) 57 #define RSI_ERROR_STATE UL(2) 58 #define RSI_INCOMPLETE UL(3) 59 #define RSI_ERROR_UNKNOWN UL(4) 60 61 #define SMC_RSI_FID(n) SMCCC_FUNC_ID(SMCCC_FAST_CALL, \ 62 SMCCC_64BIT_CALL, \ 63 SMCCC_STD_SECURE_SERVICE_CALLS, \ 64 n) 65 66 /* 67 * Returns RSI version. 68 * 69 * arg1 == Requested interface revision 70 * ret0 == Status / error 71 * ret1 == Lower implemented interface revision 72 * ret2 == Higher implemented interface revision 73 */ 74 #define SMC_RSI_ABI_VERSION SMC_RSI_FID(0x190) 75 76 /* 77 * Read configuration for the current Realm. 78 * 79 * arg1 == struct realm_config addr 80 * ret0 == Status / error 81 */ 82 #define SMC_RSI_REALM_CONFIG SMC_RSI_FID(0x196) 83 84 struct realm_config { 85 union { 86 struct { 87 unsigned long ipa_bits; /* Width of IPA in bits */ 88 unsigned long hash_algo; /* Hash algorithm */ 89 }; 90 uint8_t pad[0x200]; 91 }; 92 union { 93 uint8_t rpv[64]; /* Realm Personalization Value */ 94 uint8_t pad2[0xe00]; 95 }; 96 /* 97 * The RMM requires the configuration structure to be aligned to a 4k 98 * boundary, ensure this happens by aligning this structure. 99 */ 100 } __aligned(0x1000); 101 102 /* 103 * Request RIPAS of a target IPA range to be changed to a specified value. 104 * 105 * arg1 == Base IPA address of target region 106 * arg2 == Top of the region 107 * arg3 == RIPAS value 108 * arg4 == flags 109 * ret0 == Status / error 110 * ret1 == Top of modified IPA range 111 * ret2 == Whether the Host accepted or rejected the request 112 */ 113 #define SMC_RSI_IPA_STATE_SET SMC_RSI_FID(0x197) 114 115 #define RSI_NO_CHANGE_DESTROYED UL(0) 116 #define RSI_CHANGE_DESTROYED UL(1) 117 118 #define RSI_ACCEPT UL(0) 119 #define RSI_REJECT UL(1) 120 121 enum ripas { 122 RSI_RIPAS_EMPTY = 0, 123 RSI_RIPAS_RAM 124 }; 125 126 unsigned long rsi_set_addr_range_state(vm_paddr_t start, vm_paddr_t end, 127 enum ripas state, unsigned long flags, vm_paddr_t *top); 128 129 #endif /* !_MACHINE_RSI_H_ */ 130