1 /* 2 * SPDX-License-Identifier: BSD-3-Clause 3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. 4 */ 5 6 #ifndef DEV_ASSIGN_STRUCTS_H 7 #define DEV_ASSIGN_STRUCTS_H 8 9 #include <smc-rmi.h> 10 #include <stdbool.h> 11 #include <stddef.h> 12 #include <stdint.h> 13 14 #define DEV_ASSIGN_STATUS_SUCCESS (0) 15 #define DEV_ASSIGN_STATUS_ERROR (-1) 16 #define DEV_ASSIGN_STATUS_COMM_BLOCKED (1) 17 18 #define DEV_OBJ_DIGEST_MAX U(64) 19 20 /* 21 * App function for initialization. This needs to be invoked for every 22 * new instance of the app. App uses heap available via tpidrro_el0. 23 * 24 * arg0 == Size of Heap in num of 4K pages. 25 * 26 * Shared app buf == `struct dev_assign_params` 27 * 28 * ret0 == DEV_ASSIGN_STATUS_SUCCESS if initialization is successful. 29 * DEV_ASSIGN_STATUS_ERROR if error on initialization. 30 */ 31 #define DEVICE_ASSIGN_APP_FUNC_ID_INIT 1 32 33 /* 34 * RMM maintains digest of device object if its cached by NS host. This device 35 * object could be device certificate or device measurement or device interface 36 * report 37 */ 38 struct dev_obj_digest { 39 uint8_t value[DEV_OBJ_DIGEST_MAX]; 40 size_t len; 41 }; 42 43 struct dev_assign_params { 44 /* RMI device handle */ 45 void *dev_handle; 46 /* Algorithm used to generate device digests. */ 47 uint8_t rmi_hash_algo; 48 /* SPDM certificate slot ID */ 49 uint8_t cert_slot_id; 50 bool has_ide; 51 /* Identify the root complex (RC). */ 52 uint64_t ecam_addr; 53 /* Identify the RP within the RC. RootPort PCI BDF */ 54 uint16_t rp_id; 55 /* IDE stream ID */ 56 uint64_t ide_sid; 57 }; 58 59 /* Shared structure on the app heap for SPDM comms */ 60 struct dev_assign_spdm_shared { 61 uint8_t sendrecv_buf[GRANULE_SIZE]; 62 }; 63 64 /* 65 * The structure that dev_assign_dev_communicate can use to get data from app 66 * shared memory on return 67 */ 68 struct dev_comm_exit_shared { 69 struct rmi_dev_comm_exit rmi_dev_comm_exit; 70 71 struct dev_obj_digest cached_digest; 72 }; 73 74 /* 75 * Get measurements operation related parameters passed when command is 76 * RDEV_GET_MEASUREMENTS 77 */ 78 struct dev_meas_params { 79 /* Get all measurements */ 80 bool all; 81 82 /* Get signed measurement */ 83 bool sign; 84 85 /* Get measurement in a raw bitstream */ 86 bool raw; 87 88 /* Bitmap of measurement indices to get when 'all=false' */ 89 unsigned char indices[32]; 90 91 /* nonce value used in get measurement, when 'sign=true' */ 92 unsigned char nonce[32]; 93 }; 94 95 /* 96 * App functions for device communication. App uses heap available via tpidrro_el0. 97 * The function execution can yield and return back to RMM. In this case 98 * the return would be via APP_YIELD_CALL svc. Callers need to check 99 * `app_data->exit_flag` for APP_EXIT_SVC_YIELD_FLAG. The `rmi_dev_comm_enter` 100 * is expected to be populated in shared buf for entry into app and 101 * `rmm_dev_comm_exit` is expected to be populated for exit from app. 102 * These entry and exit data is expected to be populated in the yield case 103 * as well. 104 * 105 * Shared app buf == `struct dev_assign_comm_params` 106 * 107 * ret0 == DEV_ASSIGN_STATUS_SUCCESS if connection is successful. 108 * DEV_ASSIGN_STATUS_ERROR if error on connection. 109 * NA if app is yielded. 110 * 111 */ 112 #define DEVICE_ASSIGN_APP_FUNC_ID_CONNECT_INIT 2 113 114 /* 115 * Pseudo App function ID for device communication resume. App uses heap available via 116 * tpidrro_el0. The cmd should only be issued to dev_assign_dev_communicate() if the 117 * app was yeilded. The `rmi_dev_comm_enter` is expected to be populated in shared 118 * buf for entry into app and `rmm_dev_comm_exit` is expected to be populated for 119 * exit from app. The app can yeild again and callers need to check `app_data->exit_flag` 120 * for APP_EXIT_SVC_YIELD_FLAG. 121 * 122 * Note that this function ID is not passed to the app but used in stub to handle 123 * resume after a yield (and hence pseudo). 124 * 125 * Shared app buf == `struct dev_assign_comm_params` 126 * 127 * ret0 == DEV_ASSIGN_STATUS_SUCCESS if connection is successful. 128 * DEV_ASSIGN_STATUS_ERROR if error on connection. 129 * NA if app is yielded. 130 */ 131 #define DEVICE_ASSIGN_APP_FUNC_ID_RESUME 10 132 133 /* 134 * App function to store a public key in the app's keystore. 135 * 136 * Shared app buf == `struct rmi_public_key_params` 137 * 138 * ret0 == DEV_ASSIGN_STATUS_SUCCESS if the public key is successfully set. 139 * DEV_ASSIGN_STATUS_ERROR if error occurred during key loading. 140 */ 141 #define DEVICE_ASSIGN_APP_FUNC_SET_PUBLIC_KEY 3 142 143 /* 144 * App function ID to de-initialise. App uses heap available via 145 * tpidrro_el0. 146 * 147 * ret0 == DEV_ASSIGN_STATUS_SUCCESS 148 */ 149 #define DEVICE_ASSIGN_APP_FUNC_ID_DEINIT 4 150 151 /* 152 * App function ID to start a libspdm session 153 * 154 * ret0 == DEV_ASSIGN_STATUS_SUCCESS if the session is started successfully. 155 * DEV_ASSIGN_STATUS_ERROR if libspdm returned error. 156 */ 157 #define DEVICE_ASSIGN_APP_FUNC_ID_SECURE_SESSION 11 158 159 /* 160 * App function ID to get measurements from the device 161 * 162 * ret0 == DEV_ASSIGN_STATUS_SUCCESS if the mesurements were retrieved 163 * successfully. 164 * DEV_ASSIGN_STATUS_ERROR if libspdm returned error. 165 */ 166 #define DEVICE_ASSIGN_APP_FUNC_ID_GET_MEASUREMENTS 12 167 168 /* 169 * App function ID to stop the libspdm session that is associated with this app 170 * instance. 171 * 172 * ret0 == DEV_ASSIGN_STATUS_SUCCESS if the session is stopped successfully. 173 * DEV_ASSIGN_STATUS_ERROR if libspdm returned error. 174 */ 175 #define DEVICE_ASSIGN_APP_FUNC_ID_STOP_CONNECTION 0x80 176 177 #endif /* DEV_ASSIGN_STRUCTS_H */ 178