Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 1 | // SPDX-FileCopyrightText: Copyright 2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 2 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| 3 | |
| 4 | #![cfg_attr(not(test), no_std)] |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 5 | #![deny(clippy::undocumented_unsafe_blocks)] |
| 6 | #![deny(unsafe_op_in_unsafe_fn)] |
| 7 | #![doc = include_str!("../README.md")] |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 8 | |
Andrew Walbran | 19970ba | 2024-11-25 15:35:00 +0000 | [diff] [blame] | 9 | use core::fmt::{self, Debug, Display, Formatter}; |
Andrew Walbran | 44029a0 | 2024-11-25 15:34:31 +0000 | [diff] [blame] | 10 | use num_enum::{IntoPrimitive, TryFromPrimitive}; |
| 11 | use thiserror::Error; |
Imre Kis | c0b062c | 2025-05-26 19:31:00 +0200 | [diff] [blame] | 12 | pub use uuid::Uuid; |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 13 | use zerocopy::{transmute, FromBytes, Immutable, IntoBytes}; |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 14 | |
| 15 | pub mod boot_info; |
Balint Dobszay | b2ff2bc | 2024-12-19 18:59:38 +0100 | [diff] [blame] | 16 | mod ffa_v1_1; |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 17 | mod ffa_v1_2; |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 18 | pub mod memory_management; |
| 19 | pub mod partition_info; |
| 20 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 21 | /// Constant for 4K page size. On many occasions the FF-A spec defines memory size as count of 4K |
| 22 | /// pages, regardless of the current translation granule. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 23 | pub const FFA_PAGE_SIZE_4K: usize = 4096; |
| 24 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 25 | /// Rich error types returned by this module. Should be converted to [`crate::FfaError`] when used |
| 26 | /// with the `FFA_ERROR` interface. |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 27 | #[derive(Debug, Error, PartialEq)] |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 28 | pub enum Error { |
| 29 | #[error("Unrecognised FF-A function ID {0}")] |
| 30 | UnrecognisedFunctionId(u32), |
| 31 | #[error("Unrecognised FF-A feature ID {0}")] |
| 32 | UnrecognisedFeatureId(u8), |
| 33 | #[error("Unrecognised FF-A error code {0}")] |
| 34 | UnrecognisedErrorCode(i32), |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 35 | #[error("Unrecognised FF-A Framework Message {0}")] |
| 36 | UnrecognisedFwkMsg(u32), |
Tomás González | 092202a | 2025-03-05 11:56:45 +0000 | [diff] [blame] | 37 | #[error("Invalid FF-A Msg Wait Flag {0}")] |
| 38 | InvalidMsgWaitFlag(u32), |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 39 | #[error("Unrecognised VM availability status {0}")] |
| 40 | UnrecognisedVmAvailabilityStatus(i32), |
| 41 | #[error("Unrecognised FF-A Warm Boot Type {0}")] |
| 42 | UnrecognisedWarmBootType(u32), |
| 43 | #[error("Invalid version {0}")] |
| 44 | InvalidVersion(u32), |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 45 | #[error("Invalid Information Tag {0}")] |
| 46 | InvalidInformationTag(u16), |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 47 | #[error("Invalid Flag for Notification Set")] |
| 48 | InvalidNotificationSetFlag(u32), |
| 49 | #[error("Invalid Vm ID")] |
| 50 | InvalidVmId(u32), |
Imre Kis | e295adb | 2025-04-10 13:26:28 +0200 | [diff] [blame] | 51 | #[error("Invalid FF-A Partition Info Get Flag {0}")] |
| 52 | InvalidPartitionInfoGetFlag(u32), |
Imre Kis | 839eaef | 2025-04-11 17:38:36 +0200 | [diff] [blame] | 53 | #[error("Invalid success argument variant")] |
| 54 | InvalidSuccessArgsVariant, |
Imre Kis | 787c500 | 2025-04-10 14:25:51 +0200 | [diff] [blame] | 55 | #[error("Invalid notification count")] |
| 56 | InvalidNotificationCount, |
Imre Kis | 92b663e | 2025-04-10 14:15:05 +0200 | [diff] [blame] | 57 | #[error("Invalid Partition Info Get Regs response")] |
| 58 | InvalidPartitionInfoGetRegsResponse, |
Balint Dobszay | 82c71dd | 2025-04-15 10:16:44 +0200 | [diff] [blame] | 59 | #[error("Invalid FF-A version {0} for function ID {1:?}")] |
| 60 | InvalidVersionForFunctionId(Version, FuncId), |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 61 | #[error("Invalid character count {0}")] |
| 62 | InvalidCharacterCount(u8), |
Imre Kis | dcb7df2 | 2025-06-06 15:24:40 +0200 | [diff] [blame] | 63 | #[error("Memory management error")] |
| 64 | MemoryManagementError(#[from] memory_management::Error), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | impl From<Error> for FfaError { |
| 68 | fn from(value: Error) -> Self { |
| 69 | match value { |
Balint Dobszay | 82c71dd | 2025-04-15 10:16:44 +0200 | [diff] [blame] | 70 | Error::UnrecognisedFunctionId(_) |
| 71 | | Error::UnrecognisedFeatureId(_) |
| 72 | | Error::InvalidVersionForFunctionId(..) => Self::NotSupported, |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 73 | Error::InvalidInformationTag(_) => Self::Retry, |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 74 | Error::UnrecognisedErrorCode(_) |
| 75 | | Error::UnrecognisedFwkMsg(_) |
| 76 | | Error::InvalidVersion(_) |
Tomás González | 092202a | 2025-03-05 11:56:45 +0000 | [diff] [blame] | 77 | | Error::InvalidMsgWaitFlag(_) |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 78 | | Error::UnrecognisedVmAvailabilityStatus(_) |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 79 | | Error::InvalidNotificationSetFlag(_) |
| 80 | | Error::InvalidVmId(_) |
Imre Kis | e295adb | 2025-04-10 13:26:28 +0200 | [diff] [blame] | 81 | | Error::UnrecognisedWarmBootType(_) |
Imre Kis | 839eaef | 2025-04-11 17:38:36 +0200 | [diff] [blame] | 82 | | Error::InvalidPartitionInfoGetFlag(_) |
Imre Kis | 787c500 | 2025-04-10 14:25:51 +0200 | [diff] [blame] | 83 | | Error::InvalidSuccessArgsVariant |
Imre Kis | 92b663e | 2025-04-10 14:15:05 +0200 | [diff] [blame] | 84 | | Error::InvalidNotificationCount |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 85 | | Error::InvalidPartitionInfoGetRegsResponse |
Imre Kis | dcb7df2 | 2025-06-06 15:24:40 +0200 | [diff] [blame] | 86 | | Error::InvalidCharacterCount(_) |
| 87 | | Error::MemoryManagementError(_) => Self::InvalidParameters, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | } |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 91 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 92 | /// An FF-A instance is a valid combination of two FF-A components at an exception level boundary. |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 93 | #[derive(PartialEq, Clone, Copy)] |
| 94 | pub enum Instance { |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 95 | /// The instance between the SPMC and SPMD. |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 96 | SecurePhysical, |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 97 | /// The instance between the SPMC and a physical SP (contains the SP's endpoint ID). |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 98 | SecureVirtual(u16), |
| 99 | } |
| 100 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 101 | /// Function IDs of the various FF-A interfaces. |
Andrew Walbran | 969b925 | 2024-11-25 15:35:42 +0000 | [diff] [blame] | 102 | #[derive(Clone, Copy, Debug, Eq, IntoPrimitive, PartialEq, TryFromPrimitive)] |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 103 | #[num_enum(error_type(name = Error, constructor = Error::UnrecognisedFunctionId))] |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 104 | #[repr(u32)] |
| 105 | pub enum FuncId { |
| 106 | Error = 0x84000060, |
| 107 | Success32 = 0x84000061, |
| 108 | Success64 = 0xc4000061, |
| 109 | Interrupt = 0x84000062, |
| 110 | Version = 0x84000063, |
| 111 | Features = 0x84000064, |
| 112 | RxAcquire = 0x84000084, |
| 113 | RxRelease = 0x84000065, |
| 114 | RxTxMap32 = 0x84000066, |
| 115 | RxTxMap64 = 0xc4000066, |
| 116 | RxTxUnmap = 0x84000067, |
| 117 | PartitionInfoGet = 0x84000068, |
Balint Dobszay | e6aa486 | 2025-02-28 16:37:56 +0100 | [diff] [blame] | 118 | PartitionInfoGetRegs = 0xc400008b, |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 119 | IdGet = 0x84000069, |
| 120 | SpmIdGet = 0x84000085, |
Balint Dobszay | e6aa486 | 2025-02-28 16:37:56 +0100 | [diff] [blame] | 121 | ConsoleLog32 = 0x8400008a, |
| 122 | ConsoleLog64 = 0xc400008a, |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 123 | MsgWait = 0x8400006b, |
| 124 | Yield = 0x8400006c, |
| 125 | Run = 0x8400006d, |
| 126 | NormalWorldResume = 0x8400007c, |
| 127 | MsgSend2 = 0x84000086, |
| 128 | MsgSendDirectReq32 = 0x8400006f, |
| 129 | MsgSendDirectReq64 = 0xc400006f, |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 130 | MsgSendDirectReq64_2 = 0xc400008d, |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 131 | MsgSendDirectResp32 = 0x84000070, |
| 132 | MsgSendDirectResp64 = 0xc4000070, |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 133 | MsgSendDirectResp64_2 = 0xc400008e, |
Balint Dobszay | e6aa486 | 2025-02-28 16:37:56 +0100 | [diff] [blame] | 134 | NotificationBitmapCreate = 0x8400007d, |
| 135 | NotificationBitmapDestroy = 0x8400007e, |
| 136 | NotificationBind = 0x8400007f, |
| 137 | NotificationUnbind = 0x84000080, |
| 138 | NotificationSet = 0x84000081, |
| 139 | NotificationGet = 0x84000082, |
| 140 | NotificationInfoGet32 = 0x84000083, |
| 141 | NotificationInfoGet64 = 0xc4000083, |
| 142 | El3IntrHandle = 0x8400008c, |
Tomás González | 17b9244 | 2025-03-10 16:45:04 +0000 | [diff] [blame] | 143 | SecondaryEpRegister32 = 0x84000087, |
| 144 | SecondaryEpRegister64 = 0xc4000087, |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 145 | MemDonate32 = 0x84000071, |
| 146 | MemDonate64 = 0xc4000071, |
| 147 | MemLend32 = 0x84000072, |
| 148 | MemLend64 = 0xc4000072, |
| 149 | MemShare32 = 0x84000073, |
| 150 | MemShare64 = 0xc4000073, |
| 151 | MemRetrieveReq32 = 0x84000074, |
| 152 | MemRetrieveReq64 = 0xc4000074, |
| 153 | MemRetrieveResp = 0x84000075, |
| 154 | MemRelinquish = 0x84000076, |
| 155 | MemReclaim = 0x84000077, |
| 156 | MemPermGet32 = 0x84000088, |
| 157 | MemPermGet64 = 0xc4000088, |
| 158 | MemPermSet32 = 0x84000089, |
| 159 | MemPermSet64 = 0xc4000089, |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 162 | impl FuncId { |
| 163 | /// Returns true if this is a 32-bit call, or false if it is a 64-bit call. |
| 164 | pub fn is_32bit(&self) -> bool { |
Tomás González | 6ccba0a | 2025-04-09 13:31:29 +0100 | [diff] [blame] | 165 | u32::from(*self) & (1 << 30) == 0 |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 166 | } |
Balint Dobszay | 82c71dd | 2025-04-15 10:16:44 +0200 | [diff] [blame] | 167 | |
| 168 | /// Returns the FF-A version that has introduced the function ID. |
| 169 | pub fn minimum_ffa_version(&self) -> Version { |
| 170 | match self { |
| 171 | FuncId::Error |
| 172 | | FuncId::Success32 |
| 173 | | FuncId::Success64 |
| 174 | | FuncId::Interrupt |
| 175 | | FuncId::Version |
| 176 | | FuncId::Features |
| 177 | | FuncId::RxRelease |
| 178 | | FuncId::RxTxMap32 |
| 179 | | FuncId::RxTxMap64 |
| 180 | | FuncId::RxTxUnmap |
| 181 | | FuncId::PartitionInfoGet |
| 182 | | FuncId::IdGet |
| 183 | | FuncId::MsgWait |
| 184 | | FuncId::Yield |
| 185 | | FuncId::Run |
| 186 | | FuncId::NormalWorldResume |
| 187 | | FuncId::MsgSendDirectReq32 |
| 188 | | FuncId::MsgSendDirectReq64 |
| 189 | | FuncId::MsgSendDirectResp32 |
| 190 | | FuncId::MsgSendDirectResp64 |
| 191 | | FuncId::MemDonate32 |
| 192 | | FuncId::MemDonate64 |
| 193 | | FuncId::MemLend32 |
| 194 | | FuncId::MemLend64 |
| 195 | | FuncId::MemShare32 |
| 196 | | FuncId::MemShare64 |
| 197 | | FuncId::MemRetrieveReq32 |
| 198 | | FuncId::MemRetrieveReq64 |
| 199 | | FuncId::MemRetrieveResp |
| 200 | | FuncId::MemRelinquish |
| 201 | | FuncId::MemReclaim => Version(1, 0), |
| 202 | |
| 203 | FuncId::RxAcquire |
| 204 | | FuncId::SpmIdGet |
| 205 | | FuncId::MsgSend2 |
| 206 | | FuncId::MemPermGet32 |
| 207 | | FuncId::MemPermGet64 |
| 208 | | FuncId::MemPermSet32 |
| 209 | | FuncId::MemPermSet64 |
| 210 | | FuncId::NotificationBitmapCreate |
| 211 | | FuncId::NotificationBitmapDestroy |
| 212 | | FuncId::NotificationBind |
| 213 | | FuncId::NotificationUnbind |
| 214 | | FuncId::NotificationSet |
| 215 | | FuncId::NotificationGet |
| 216 | | FuncId::NotificationInfoGet32 |
| 217 | | FuncId::NotificationInfoGet64 |
| 218 | | FuncId::SecondaryEpRegister32 |
| 219 | | FuncId::SecondaryEpRegister64 => Version(1, 1), |
| 220 | |
| 221 | FuncId::PartitionInfoGetRegs |
| 222 | | FuncId::ConsoleLog32 |
| 223 | | FuncId::ConsoleLog64 |
| 224 | | FuncId::MsgSendDirectReq64_2 |
| 225 | | FuncId::MsgSendDirectResp64_2 |
| 226 | | FuncId::El3IntrHandle => Version(1, 2), |
| 227 | } |
| 228 | } |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 231 | /// Error status codes used by the `FFA_ERROR` interface. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 232 | #[derive(Clone, Copy, Debug, Eq, Error, IntoPrimitive, PartialEq, TryFromPrimitive)] |
| 233 | #[num_enum(error_type(name = Error, constructor = Error::UnrecognisedErrorCode))] |
| 234 | #[repr(i32)] |
| 235 | pub enum FfaError { |
| 236 | #[error("Not supported")] |
| 237 | NotSupported = -1, |
| 238 | #[error("Invalid parameters")] |
| 239 | InvalidParameters = -2, |
| 240 | #[error("No memory")] |
| 241 | NoMemory = -3, |
| 242 | #[error("Busy")] |
| 243 | Busy = -4, |
| 244 | #[error("Interrupted")] |
| 245 | Interrupted = -5, |
| 246 | #[error("Denied")] |
| 247 | Denied = -6, |
| 248 | #[error("Retry")] |
| 249 | Retry = -7, |
| 250 | #[error("Aborted")] |
| 251 | Aborted = -8, |
| 252 | #[error("No data")] |
| 253 | NoData = -9, |
| 254 | } |
| 255 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 256 | /// Endpoint ID and vCPU ID pair, used by `FFA_ERROR`, `FFA_INTERRUPT` and `FFA_RUN` interfaces. |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 257 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 258 | pub struct TargetInfo { |
| 259 | pub endpoint_id: u16, |
| 260 | pub vcpu_id: u16, |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 263 | impl From<u32> for TargetInfo { |
| 264 | fn from(value: u32) -> Self { |
| 265 | Self { |
| 266 | endpoint_id: (value >> 16) as u16, |
| 267 | vcpu_id: value as u16, |
| 268 | } |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 272 | impl From<TargetInfo> for u32 { |
| 273 | fn from(value: TargetInfo) -> Self { |
Balint Dobszay | e9a3e76 | 2025-02-26 17:29:57 +0100 | [diff] [blame] | 274 | ((value.endpoint_id as u32) << 16) | value.vcpu_id as u32 |
Andrew Walbran | 0d31581 | 2024-11-25 15:36:36 +0000 | [diff] [blame] | 275 | } |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 276 | } |
Andrew Walbran | 0d31581 | 2024-11-25 15:36:36 +0000 | [diff] [blame] | 277 | |
Imre Kis | 839eaef | 2025-04-11 17:38:36 +0200 | [diff] [blame] | 278 | /// Generic arguments of the `FFA_SUCCESS` interface. The interpretation of the arguments depends on |
| 279 | /// the interface that initiated the request. The application code has knowledge of the request, so |
| 280 | /// it has to convert `SuccessArgs` into/from a specific success args structure that matches the |
| 281 | /// request. |
Imre Kis | 4e9d8bc | 2025-04-10 13:48:26 +0200 | [diff] [blame] | 282 | /// |
| 283 | /// The current specialized success arguments types are: |
| 284 | /// * `FFA_FEATURES` - [`SuccessArgsFeatures`] |
Imre Kis | bbef287 | 2025-04-10 14:11:29 +0200 | [diff] [blame] | 285 | /// * `FFA_ID_GET` - [`SuccessArgsIdGet`] |
| 286 | /// * `FFA_SPM_ID_GET` - [`SuccessArgsSpmIdGet`] |
Imre Kis | 61c3409 | 2025-04-10 14:14:38 +0200 | [diff] [blame] | 287 | /// * `FFA_PARTITION_INFO_GET` - [`partition_info::SuccessArgsPartitionInfoGet`] |
Imre Kis | 92b663e | 2025-04-10 14:15:05 +0200 | [diff] [blame] | 288 | /// * `FFA_PARTITION_INFO_GET_REGS` - [`partition_info::SuccessArgsPartitionInfoGetRegs`] |
Imre Kis | 9959e06 | 2025-04-10 14:16:10 +0200 | [diff] [blame] | 289 | /// * `FFA_NOTIFICATION_GET` - [`SuccessArgsNotificationGet`] |
Imre Kis | 787c500 | 2025-04-10 14:25:51 +0200 | [diff] [blame] | 290 | /// * `FFA_NOTIFICATION_INFO_GET_32` - [`SuccessArgsNotificationInfoGet32`] |
| 291 | /// * `FFA_NOTIFICATION_INFO_GET_64` - [`SuccessArgsNotificationInfoGet64`] |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 292 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 293 | pub enum SuccessArgs { |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 294 | Args32([u32; 6]), |
| 295 | Args64([u64; 6]), |
| 296 | Args64_2([u64; 16]), |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 297 | } |
| 298 | |
Imre Kis | 839eaef | 2025-04-11 17:38:36 +0200 | [diff] [blame] | 299 | impl SuccessArgs { |
| 300 | fn try_get_args32(self) -> Result<[u32; 6], Error> { |
| 301 | match self { |
| 302 | SuccessArgs::Args32(args) => Ok(args), |
| 303 | SuccessArgs::Args64(_) | SuccessArgs::Args64_2(_) => { |
| 304 | Err(Error::InvalidSuccessArgsVariant) |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | fn try_get_args64(self) -> Result<[u64; 6], Error> { |
| 310 | match self { |
| 311 | SuccessArgs::Args64(args) => Ok(args), |
| 312 | SuccessArgs::Args32(_) | SuccessArgs::Args64_2(_) => { |
| 313 | Err(Error::InvalidSuccessArgsVariant) |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | fn try_get_args64_2(self) -> Result<[u64; 16], Error> { |
| 319 | match self { |
| 320 | SuccessArgs::Args64_2(args) => Ok(args), |
| 321 | SuccessArgs::Args32(_) | SuccessArgs::Args64(_) => { |
| 322 | Err(Error::InvalidSuccessArgsVariant) |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
Tomás González | 17b9244 | 2025-03-10 16:45:04 +0000 | [diff] [blame] | 328 | /// Entrypoint address argument for `FFA_SECONDARY_EP_REGISTER` interface. |
| 329 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 330 | pub enum SecondaryEpRegisterAddr { |
| 331 | Addr32(u32), |
| 332 | Addr64(u64), |
| 333 | } |
| 334 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 335 | /// Version number of the FF-A implementation, `.0` is the major, `.1` is minor the version. |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 336 | #[derive(Clone, Copy, Eq, PartialEq, PartialOrd, Ord)] |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 337 | pub struct Version(pub u16, pub u16); |
| 338 | |
Tomás González | 1f79435 | 2025-03-03 16:47:06 +0000 | [diff] [blame] | 339 | impl Version { |
Tomás González | 83146af | 2025-03-04 11:32:41 +0000 | [diff] [blame] | 340 | // The FF-A spec mandates that bit[31] of a version number must be 0 |
| 341 | const MBZ_BITS: u32 = 1 << 31; |
| 342 | |
Tomás González | 1f79435 | 2025-03-03 16:47:06 +0000 | [diff] [blame] | 343 | /// Returns whether the caller's version (self) is compatible with the callee's version (input |
| 344 | /// parameter) |
| 345 | pub fn is_compatible_to(&self, callee_version: &Version) -> bool { |
| 346 | self.0 == callee_version.0 && self.1 <= callee_version.1 |
| 347 | } |
Balint Dobszay | 5ded592 | 2025-06-13 12:06:53 +0200 | [diff] [blame^] | 348 | |
| 349 | /// Returns true if the specified FF-A version uses 18 registers for calls, false if it uses 8. |
| 350 | pub fn needs_18_regs(&self) -> bool { |
| 351 | *self >= Version(1, 2) |
| 352 | } |
Tomás González | 1f79435 | 2025-03-03 16:47:06 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Tomás González | 83146af | 2025-03-04 11:32:41 +0000 | [diff] [blame] | 355 | impl TryFrom<u32> for Version { |
| 356 | type Error = Error; |
| 357 | |
| 358 | fn try_from(val: u32) -> Result<Self, Self::Error> { |
| 359 | if (val & Self::MBZ_BITS) != 0 { |
| 360 | Err(Error::InvalidVersion(val)) |
| 361 | } else { |
| 362 | Ok(Self((val >> 16) as u16, val as u16)) |
| 363 | } |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
| 367 | impl From<Version> for u32 { |
| 368 | fn from(v: Version) -> Self { |
Tomás González | 83146af | 2025-03-04 11:32:41 +0000 | [diff] [blame] | 369 | let v_u32 = ((v.0 as u32) << 16) | v.1 as u32; |
| 370 | assert!(v_u32 & Version::MBZ_BITS == 0); |
| 371 | v_u32 |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
Andrew Walbran | 19970ba | 2024-11-25 15:35:00 +0000 | [diff] [blame] | 375 | impl Display for Version { |
| 376 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { |
| 377 | write!(f, "{}.{}", self.0, self.1) |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | impl Debug for Version { |
| 382 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { |
| 383 | Display::fmt(self, f) |
| 384 | } |
| 385 | } |
| 386 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 387 | /// Feature IDs used by the `FFA_FEATURES` interface. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 388 | #[derive(Clone, Copy, Debug, Eq, IntoPrimitive, PartialEq, TryFromPrimitive)] |
| 389 | #[num_enum(error_type(name = Error, constructor = Error::UnrecognisedFeatureId))] |
| 390 | #[repr(u8)] |
| 391 | pub enum FeatureId { |
| 392 | NotificationPendingInterrupt = 0x1, |
| 393 | ScheduleReceiverInterrupt = 0x2, |
| 394 | ManagedExitInterrupt = 0x3, |
| 395 | } |
Balint Dobszay | c880249 | 2025-01-15 18:11:39 +0100 | [diff] [blame] | 396 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 397 | /// Arguments for the `FFA_FEATURES` interface. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 398 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 399 | pub enum Feature { |
| 400 | FuncId(FuncId), |
| 401 | FeatureId(FeatureId), |
Balint Dobszay | c31e0b9 | 2025-03-03 20:16:56 +0100 | [diff] [blame] | 402 | Unknown(u32), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 403 | } |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 404 | |
Balint Dobszay | c31e0b9 | 2025-03-03 20:16:56 +0100 | [diff] [blame] | 405 | impl From<u32> for Feature { |
| 406 | fn from(value: u32) -> Self { |
| 407 | // Bit[31] is set for all valid FF-A function IDs so we don't have to check it separately |
| 408 | if let Ok(func_id) = value.try_into() { |
| 409 | Self::FuncId(func_id) |
| 410 | } else if let Ok(feat_id) = (value as u8).try_into() { |
| 411 | Self::FeatureId(feat_id) |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 412 | } else { |
Balint Dobszay | c31e0b9 | 2025-03-03 20:16:56 +0100 | [diff] [blame] | 413 | Self::Unknown(value) |
| 414 | } |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
| 418 | impl From<Feature> for u32 { |
| 419 | fn from(value: Feature) -> Self { |
| 420 | match value { |
| 421 | Feature::FuncId(func_id) => (1 << 31) | func_id as u32, |
| 422 | Feature::FeatureId(feature_id) => feature_id as u32, |
Imre Kis | 29c8ace | 2025-04-11 13:49:58 +0200 | [diff] [blame] | 423 | Feature::Unknown(id) => id, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
Imre Kis | 4e9d8bc | 2025-04-10 13:48:26 +0200 | [diff] [blame] | 428 | /// `FFA_FEATURES` specific success argument structure. This type needs further specialization based |
| 429 | /// on 'FF-A function ID or Feature ID' field of the preceeding `FFA_FEATURES` request. |
| 430 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 431 | pub struct SuccessArgsFeatures { |
| 432 | pub properties: [u32; 2], |
| 433 | } |
| 434 | |
| 435 | impl From<SuccessArgsFeatures> for SuccessArgs { |
| 436 | fn from(value: SuccessArgsFeatures) -> Self { |
| 437 | Self::Args32([value.properties[0], value.properties[1], 0, 0, 0, 0]) |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | impl TryFrom<SuccessArgs> for SuccessArgsFeatures { |
| 442 | type Error = Error; |
| 443 | |
| 444 | fn try_from(value: SuccessArgs) -> Result<Self, Self::Error> { |
| 445 | let args = value.try_get_args32()?; |
| 446 | |
| 447 | Ok(Self { |
| 448 | properties: [args[0], args[1]], |
| 449 | }) |
| 450 | } |
| 451 | } |
| 452 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 453 | /// RXTX buffer descriptor, used by `FFA_RXTX_MAP`. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 454 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 455 | pub enum RxTxAddr { |
| 456 | Addr32 { rx: u32, tx: u32 }, |
| 457 | Addr64 { rx: u64, tx: u64 }, |
| 458 | } |
| 459 | |
Imre Kis | bbef287 | 2025-04-10 14:11:29 +0200 | [diff] [blame] | 460 | /// `FFA_ID_GET` specific success argument structure. |
| 461 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 462 | pub struct SuccessArgsIdGet { |
| 463 | pub id: u16, |
| 464 | } |
| 465 | |
| 466 | impl From<SuccessArgsIdGet> for SuccessArgs { |
| 467 | fn from(value: SuccessArgsIdGet) -> Self { |
| 468 | SuccessArgs::Args32([value.id as u32, 0, 0, 0, 0, 0]) |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | impl TryFrom<SuccessArgs> for SuccessArgsIdGet { |
| 473 | type Error = Error; |
| 474 | |
| 475 | fn try_from(value: SuccessArgs) -> Result<Self, Self::Error> { |
| 476 | let args = value.try_get_args32()?; |
| 477 | Ok(Self { id: args[0] as u16 }) |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | /// `FFA_SPM_ID_GET` specific success argument structure. |
| 482 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 483 | pub struct SuccessArgsSpmIdGet { |
| 484 | pub id: u16, |
| 485 | } |
| 486 | |
| 487 | impl From<SuccessArgsSpmIdGet> for SuccessArgs { |
| 488 | fn from(value: SuccessArgsSpmIdGet) -> Self { |
| 489 | SuccessArgs::Args32([value.id as u32, 0, 0, 0, 0, 0]) |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | impl TryFrom<SuccessArgs> for SuccessArgsSpmIdGet { |
| 494 | type Error = Error; |
| 495 | |
| 496 | fn try_from(value: SuccessArgs) -> Result<Self, Self::Error> { |
| 497 | let args = value.try_get_args32()?; |
| 498 | Ok(Self { id: args[0] as u16 }) |
| 499 | } |
| 500 | } |
| 501 | |
Imre Kis | e295adb | 2025-04-10 13:26:28 +0200 | [diff] [blame] | 502 | /// Flags of the `FFA_PARTITION_INFO_GET` interface. |
| 503 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 504 | pub struct PartitionInfoGetFlags { |
| 505 | pub count_only: bool, |
| 506 | } |
| 507 | |
| 508 | impl PartitionInfoGetFlags { |
| 509 | const RETURN_INFORMATION_TYPE_FLAG: u32 = 1 << 0; |
| 510 | const MBZ_BITS: u32 = 0xffff_fffe; |
| 511 | } |
| 512 | |
| 513 | impl TryFrom<u32> for PartitionInfoGetFlags { |
| 514 | type Error = Error; |
| 515 | |
| 516 | fn try_from(val: u32) -> Result<Self, Self::Error> { |
| 517 | if (val & Self::MBZ_BITS) != 0 { |
| 518 | Err(Error::InvalidPartitionInfoGetFlag(val)) |
| 519 | } else { |
| 520 | Ok(Self { |
| 521 | count_only: val & Self::RETURN_INFORMATION_TYPE_FLAG != 0, |
| 522 | }) |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | impl From<PartitionInfoGetFlags> for u32 { |
| 528 | fn from(flags: PartitionInfoGetFlags) -> Self { |
| 529 | let mut bits: u32 = 0; |
| 530 | if flags.count_only { |
| 531 | bits |= PartitionInfoGetFlags::RETURN_INFORMATION_TYPE_FLAG; |
| 532 | } |
| 533 | bits |
| 534 | } |
| 535 | } |
| 536 | |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 537 | /// Composite type for capturing success and error return codes for the VM availability messages. |
| 538 | /// |
| 539 | /// Error codes are handled by the `FfaError` type. Having a separate type for errors helps using |
| 540 | /// `Result<(), FfaError>`. If a single type would include both success and error values, |
| 541 | /// then `Err(FfaError::Success)` would be incomprehensible. |
| 542 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 543 | pub enum VmAvailabilityStatus { |
| 544 | Success, |
| 545 | Error(FfaError), |
| 546 | } |
| 547 | |
| 548 | impl TryFrom<i32> for VmAvailabilityStatus { |
| 549 | type Error = Error; |
| 550 | fn try_from(value: i32) -> Result<Self, <Self as TryFrom<i32>>::Error> { |
| 551 | Ok(match value { |
| 552 | 0 => Self::Success, |
| 553 | error_code => Self::Error(FfaError::try_from(error_code)?), |
| 554 | }) |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | impl From<VmAvailabilityStatus> for i32 { |
| 559 | fn from(value: VmAvailabilityStatus) -> Self { |
| 560 | match value { |
| 561 | VmAvailabilityStatus::Success => 0, |
| 562 | VmAvailabilityStatus::Error(error_code) => error_code.into(), |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | /// Arguments for the Power Warm Boot `FFA_MSG_SEND_DIRECT_REQ` interface. |
| 568 | #[derive(Clone, Copy, Debug, Eq, IntoPrimitive, PartialEq, TryFromPrimitive)] |
| 569 | #[num_enum(error_type(name = Error, constructor = Error::UnrecognisedWarmBootType))] |
| 570 | #[repr(u32)] |
| 571 | pub enum WarmBootType { |
| 572 | ExitFromSuspend = 0, |
| 573 | ExitFromLowPower = 1, |
| 574 | } |
| 575 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 576 | /// Arguments for the `FFA_MSG_SEND_DIRECT_{REQ,RESP}` interfaces. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 577 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 578 | pub enum DirectMsgArgs { |
| 579 | Args32([u32; 5]), |
| 580 | Args64([u64; 5]), |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 581 | /// Message for forwarding FFA_VERSION call from Normal world to the SPMC |
| 582 | VersionReq { |
| 583 | version: Version, |
| 584 | }, |
| 585 | /// Response message to forwarded FFA_VERSION call from the Normal world |
| 586 | /// Contains the version returned by the SPMC or None |
| 587 | VersionResp { |
| 588 | version: Option<Version>, |
| 589 | }, |
| 590 | /// Message for a power management operation initiated by a PSCI function |
| 591 | PowerPsciReq32 { |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 592 | // params[i]: Input parameter in w[i] in PSCI function invocation at EL3. |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 593 | // params[0]: Function ID. |
| 594 | params: [u32; 4], |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 595 | }, |
| 596 | /// Message for a power management operation initiated by a PSCI function |
| 597 | PowerPsciReq64 { |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 598 | // params[i]: Input parameter in x[i] in PSCI function invocation at EL3. |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 599 | // params[0]: Function ID. |
| 600 | params: [u64; 4], |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 601 | }, |
| 602 | /// Message for a warm boot |
| 603 | PowerWarmBootReq { |
| 604 | boot_type: WarmBootType, |
| 605 | }, |
| 606 | /// Response message to indicate return status of the last power management request message |
| 607 | /// Return error code SUCCESS or DENIED as defined in PSCI spec. Caller is left to do the |
| 608 | /// parsing of the return status. |
| 609 | PowerPsciResp { |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 610 | psci_status: i32, |
| 611 | }, |
| 612 | /// Message to signal creation of a VM |
| 613 | VmCreated { |
| 614 | // Globally unique Handle to identify a memory region that contains IMPLEMENTATION DEFINED |
| 615 | // information associated with the created VM. |
| 616 | // The invalid memory region handle must be specified by the Hypervisor if this field is not |
| 617 | // used. |
| 618 | handle: memory_management::Handle, |
| 619 | vm_id: u16, |
| 620 | }, |
| 621 | /// Message to acknowledge creation of a VM |
| 622 | VmCreatedAck { |
| 623 | sp_status: VmAvailabilityStatus, |
| 624 | }, |
| 625 | /// Message to signal destruction of a VM |
| 626 | VmDestructed { |
| 627 | // Globally unique Handle to identify a memory region that contains IMPLEMENTATION DEFINED |
| 628 | // information associated with the created VM. |
| 629 | // The invalid memory region handle must be specified by the Hypervisor if this field is not |
| 630 | // used. |
| 631 | handle: memory_management::Handle, |
| 632 | vm_id: u16, |
| 633 | }, |
| 634 | /// Message to acknowledge destruction of a VM |
| 635 | VmDestructedAck { |
| 636 | sp_status: VmAvailabilityStatus, |
| 637 | }, |
| 638 | } |
| 639 | |
| 640 | impl DirectMsgArgs { |
| 641 | // Flags for the `FFA_MSG_SEND_DIRECT_{REQ,RESP}` interfaces. |
| 642 | |
| 643 | const FWK_MSG_BITS: u32 = 1 << 31; |
| 644 | const VERSION_REQ: u32 = DirectMsgArgs::FWK_MSG_BITS | 0b1000; |
| 645 | const VERSION_RESP: u32 = DirectMsgArgs::FWK_MSG_BITS | 0b1001; |
| 646 | const POWER_PSCI_REQ: u32 = DirectMsgArgs::FWK_MSG_BITS; |
| 647 | const POWER_WARM_BOOT_REQ: u32 = DirectMsgArgs::FWK_MSG_BITS | 0b0001; |
| 648 | const POWER_PSCI_RESP: u32 = DirectMsgArgs::FWK_MSG_BITS | 0b0010; |
| 649 | const VM_CREATED: u32 = DirectMsgArgs::FWK_MSG_BITS | 0b0100; |
| 650 | const VM_CREATED_ACK: u32 = DirectMsgArgs::FWK_MSG_BITS | 0b0101; |
| 651 | const VM_DESTRUCTED: u32 = DirectMsgArgs::FWK_MSG_BITS | 0b0110; |
| 652 | const VM_DESTRUCTED_ACK: u32 = DirectMsgArgs::FWK_MSG_BITS | 0b0111; |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 653 | } |
| 654 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 655 | /// Arguments for the `FFA_MSG_SEND_DIRECT_{REQ,RESP}2` interfaces. |
| 656 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
Imre Kis | c739e0e | 2025-05-30 11:49:25 +0200 | [diff] [blame] | 657 | pub struct DirectMsg2Args(pub [u64; 14]); |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 658 | |
Tomás González | 092202a | 2025-03-05 11:56:45 +0000 | [diff] [blame] | 659 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 660 | pub struct MsgWaitFlags { |
Imre Kis | c739e0e | 2025-05-30 11:49:25 +0200 | [diff] [blame] | 661 | pub retain_rx_buffer: bool, |
Tomás González | 092202a | 2025-03-05 11:56:45 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | impl MsgWaitFlags { |
| 665 | const RETAIN_RX_BUFFER: u32 = 0x01; |
| 666 | const MBZ_BITS: u32 = 0xfffe; |
| 667 | } |
| 668 | |
| 669 | impl TryFrom<u32> for MsgWaitFlags { |
| 670 | type Error = Error; |
| 671 | |
| 672 | fn try_from(val: u32) -> Result<Self, Self::Error> { |
| 673 | if (val & Self::MBZ_BITS) != 0 { |
| 674 | Err(Error::InvalidMsgWaitFlag(val)) |
| 675 | } else { |
| 676 | Ok(MsgWaitFlags { |
| 677 | retain_rx_buffer: val & Self::RETAIN_RX_BUFFER != 0, |
| 678 | }) |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | impl From<MsgWaitFlags> for u32 { |
| 684 | fn from(flags: MsgWaitFlags) -> Self { |
| 685 | let mut bits: u32 = 0; |
| 686 | if flags.retain_rx_buffer { |
| 687 | bits |= MsgWaitFlags::RETAIN_RX_BUFFER; |
| 688 | } |
| 689 | bits |
| 690 | } |
| 691 | } |
| 692 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 693 | /// Descriptor for a dynamically allocated memory buffer that contains the memory transaction |
Tomás González | f268e32 | 2025-03-05 11:18:11 +0000 | [diff] [blame] | 694 | /// descriptor. |
| 695 | /// |
| 696 | /// Used by `FFA_MEM_{DONATE,LEND,SHARE,RETRIEVE_REQ}` interfaces, only when the TX buffer is not |
| 697 | /// used to transmit the transaction descriptor. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 698 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 699 | pub enum MemOpBuf { |
| 700 | Buf32 { addr: u32, page_cnt: u32 }, |
| 701 | Buf64 { addr: u64, page_cnt: u32 }, |
| 702 | } |
| 703 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 704 | /// Memory address argument for `FFA_MEM_PERM_{GET,SET}` interfaces. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 705 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 706 | pub enum MemAddr { |
| 707 | Addr32(u32), |
| 708 | Addr64(u64), |
| 709 | } |
| 710 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 711 | /// Argument for the `FFA_CONSOLE_LOG` interface. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 712 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 713 | pub enum ConsoleLogChars { |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 714 | Chars32(ConsoleLogChars32), |
| 715 | Chars64(ConsoleLogChars64), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 716 | } |
| 717 | |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 718 | /// Generic type for storing `FFA_CONSOLE_LOG` character payload and its length in bytes. |
| 719 | #[derive(Debug, Default, Eq, PartialEq, Clone, Copy)] |
| 720 | pub struct LogChars<T> |
| 721 | where |
| 722 | T: IntoBytes + FromBytes + Immutable, |
| 723 | { |
| 724 | char_cnt: u8, |
| 725 | char_lists: T, |
| 726 | } |
| 727 | |
| 728 | impl<T> LogChars<T> |
| 729 | where |
| 730 | T: IntoBytes + FromBytes + Immutable, |
| 731 | { |
| 732 | const MAX_LENGTH: u8 = core::mem::size_of::<T>() as u8; |
| 733 | |
| 734 | /// Returns true if there are no characters in the structure. |
| 735 | pub fn empty(&self) -> bool { |
| 736 | self.char_cnt == 0 |
| 737 | } |
| 738 | |
| 739 | /// Returns true if the structure is full. |
| 740 | pub fn full(&self) -> bool { |
| 741 | self.char_cnt as usize >= core::mem::size_of::<T>() |
| 742 | } |
| 743 | |
| 744 | /// Returns the payload bytes. |
| 745 | pub fn bytes(&self) -> &[u8] { |
| 746 | &self.char_lists.as_bytes()[..self.char_cnt as usize] |
| 747 | } |
| 748 | |
| 749 | /// Append byte slice to the end of the characters. |
| 750 | pub fn push(&mut self, source: &[u8]) -> usize { |
| 751 | let empty_area = &mut self.char_lists.as_mut_bytes()[self.char_cnt.into()..]; |
| 752 | let len = empty_area.len().min(source.len()); |
| 753 | |
| 754 | empty_area[..len].copy_from_slice(&source[..len]); |
| 755 | self.char_cnt += len as u8; |
| 756 | |
| 757 | len |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | /// Specialized type for 32-bit `FFA_CONSOLE_LOG` payload. |
| 762 | pub type ConsoleLogChars32 = LogChars<[u32; 6]>; |
| 763 | |
| 764 | /// Specialized type for 64-bit `FFA_CONSOLE_LOG` payload. |
| 765 | pub type ConsoleLogChars64 = LogChars<[u64; 16]>; |
| 766 | |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 767 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 768 | pub struct NotificationBindFlags { |
Imre Kis | c739e0e | 2025-05-30 11:49:25 +0200 | [diff] [blame] | 769 | pub per_vcpu_notification: bool, |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | impl NotificationBindFlags { |
| 773 | const PER_VCPU_NOTIFICATION: u32 = 1; |
| 774 | } |
| 775 | |
| 776 | impl From<NotificationBindFlags> for u32 { |
| 777 | fn from(flags: NotificationBindFlags) -> Self { |
| 778 | let mut bits: u32 = 0; |
| 779 | if flags.per_vcpu_notification { |
| 780 | bits |= NotificationBindFlags::PER_VCPU_NOTIFICATION; |
| 781 | } |
| 782 | bits |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | impl From<u32> for NotificationBindFlags { |
| 787 | fn from(flags: u32) -> Self { |
| 788 | Self { |
| 789 | per_vcpu_notification: flags & Self::PER_VCPU_NOTIFICATION != 0, |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 795 | pub struct NotificationSetFlags { |
Imre Kis | c739e0e | 2025-05-30 11:49:25 +0200 | [diff] [blame] | 796 | pub delay_schedule_receiver: bool, |
| 797 | pub vcpu_id: Option<u16>, |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | impl NotificationSetFlags { |
| 801 | const PER_VCP_NOTIFICATION: u32 = 1 << 0; |
| 802 | const DELAY_SCHEDULE_RECEIVER: u32 = 1 << 1; |
| 803 | const VCPU_ID_SHIFT: u32 = 16; |
| 804 | |
| 805 | const MBZ_BITS: u32 = 0xfffc; |
| 806 | } |
| 807 | |
| 808 | impl From<NotificationSetFlags> for u32 { |
| 809 | fn from(flags: NotificationSetFlags) -> Self { |
| 810 | let mut bits: u32 = 0; |
| 811 | |
| 812 | if flags.delay_schedule_receiver { |
| 813 | bits |= NotificationSetFlags::DELAY_SCHEDULE_RECEIVER; |
| 814 | } |
| 815 | if let Some(vcpu_id) = flags.vcpu_id { |
| 816 | bits |= NotificationSetFlags::PER_VCP_NOTIFICATION; |
| 817 | bits |= u32::from(vcpu_id) << NotificationSetFlags::VCPU_ID_SHIFT; |
| 818 | } |
| 819 | |
| 820 | bits |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | impl TryFrom<u32> for NotificationSetFlags { |
| 825 | type Error = Error; |
| 826 | |
| 827 | fn try_from(flags: u32) -> Result<Self, Self::Error> { |
| 828 | if (flags & Self::MBZ_BITS) != 0 { |
| 829 | return Err(Error::InvalidNotificationSetFlag(flags)); |
| 830 | } |
| 831 | |
| 832 | let tentative_vcpu_id = (flags >> Self::VCPU_ID_SHIFT) as u16; |
| 833 | |
| 834 | let vcpu_id = if (flags & Self::PER_VCP_NOTIFICATION) != 0 { |
| 835 | Some(tentative_vcpu_id) |
| 836 | } else { |
| 837 | if tentative_vcpu_id != 0 { |
| 838 | return Err(Error::InvalidNotificationSetFlag(flags)); |
| 839 | } |
| 840 | None |
| 841 | }; |
| 842 | |
| 843 | Ok(Self { |
| 844 | delay_schedule_receiver: (flags & Self::DELAY_SCHEDULE_RECEIVER) != 0, |
| 845 | vcpu_id, |
| 846 | }) |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 851 | pub struct NotificationGetFlags { |
Imre Kis | c739e0e | 2025-05-30 11:49:25 +0200 | [diff] [blame] | 852 | pub sp_bitmap_id: bool, |
| 853 | pub vm_bitmap_id: bool, |
| 854 | pub spm_bitmap_id: bool, |
| 855 | pub hyp_bitmap_id: bool, |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | impl NotificationGetFlags { |
| 859 | const SP_BITMAP_ID: u32 = 1; |
| 860 | const VM_BITMAP_ID: u32 = 1 << 1; |
| 861 | const SPM_BITMAP_ID: u32 = 1 << 2; |
| 862 | const HYP_BITMAP_ID: u32 = 1 << 3; |
| 863 | } |
| 864 | |
| 865 | impl From<NotificationGetFlags> for u32 { |
| 866 | fn from(flags: NotificationGetFlags) -> Self { |
| 867 | let mut bits: u32 = 0; |
| 868 | if flags.sp_bitmap_id { |
| 869 | bits |= NotificationGetFlags::SP_BITMAP_ID; |
| 870 | } |
| 871 | if flags.vm_bitmap_id { |
| 872 | bits |= NotificationGetFlags::VM_BITMAP_ID; |
| 873 | } |
| 874 | if flags.spm_bitmap_id { |
| 875 | bits |= NotificationGetFlags::SPM_BITMAP_ID; |
| 876 | } |
| 877 | if flags.hyp_bitmap_id { |
| 878 | bits |= NotificationGetFlags::HYP_BITMAP_ID; |
| 879 | } |
| 880 | bits |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | impl From<u32> for NotificationGetFlags { |
| 885 | // This is a "from" instead of a "try_from" because Reserved Bits are SBZ, *not* MBZ. |
| 886 | fn from(flags: u32) -> Self { |
| 887 | Self { |
| 888 | sp_bitmap_id: (flags & Self::SP_BITMAP_ID) != 0, |
| 889 | vm_bitmap_id: (flags & Self::VM_BITMAP_ID) != 0, |
| 890 | spm_bitmap_id: (flags & Self::SPM_BITMAP_ID) != 0, |
| 891 | hyp_bitmap_id: (flags & Self::HYP_BITMAP_ID) != 0, |
| 892 | } |
| 893 | } |
| 894 | } |
| 895 | |
Imre Kis | 9959e06 | 2025-04-10 14:16:10 +0200 | [diff] [blame] | 896 | /// `FFA_NOTIFICATION_GET` specific success argument structure. |
| 897 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 898 | pub struct SuccessArgsNotificationGet { |
| 899 | pub sp_notifications: Option<u64>, |
| 900 | pub vm_notifications: Option<u64>, |
| 901 | pub spm_notifications: Option<u32>, |
| 902 | pub hypervisor_notifications: Option<u32>, |
| 903 | } |
| 904 | |
| 905 | impl From<SuccessArgsNotificationGet> for SuccessArgs { |
| 906 | fn from(value: SuccessArgsNotificationGet) -> Self { |
| 907 | let mut args = [0; 6]; |
| 908 | |
| 909 | if let Some(bitmap) = value.sp_notifications { |
| 910 | args[0] = bitmap as u32; |
| 911 | args[1] = (bitmap >> 32) as u32; |
| 912 | } |
| 913 | |
| 914 | if let Some(bitmap) = value.vm_notifications { |
| 915 | args[2] = bitmap as u32; |
| 916 | args[3] = (bitmap >> 32) as u32; |
| 917 | } |
| 918 | |
| 919 | if let Some(bitmap) = value.spm_notifications { |
| 920 | args[4] = bitmap; |
| 921 | } |
| 922 | |
| 923 | if let Some(bitmap) = value.hypervisor_notifications { |
| 924 | args[5] = bitmap; |
| 925 | } |
| 926 | |
| 927 | Self::Args32(args) |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | impl TryFrom<(NotificationGetFlags, SuccessArgs)> for SuccessArgsNotificationGet { |
| 932 | type Error = Error; |
| 933 | |
| 934 | fn try_from(value: (NotificationGetFlags, SuccessArgs)) -> Result<Self, Self::Error> { |
| 935 | let (flags, value) = value; |
| 936 | let args = value.try_get_args32()?; |
| 937 | |
| 938 | let sp_notifications = if flags.sp_bitmap_id { |
| 939 | Some(u64::from(args[0]) | (u64::from(args[1]) << 32)) |
| 940 | } else { |
| 941 | None |
| 942 | }; |
| 943 | |
| 944 | let vm_notifications = if flags.vm_bitmap_id { |
| 945 | Some(u64::from(args[2]) | (u64::from(args[3]) << 32)) |
| 946 | } else { |
| 947 | None |
| 948 | }; |
| 949 | |
| 950 | let spm_notifications = if flags.spm_bitmap_id { |
| 951 | Some(args[4]) |
| 952 | } else { |
| 953 | None |
| 954 | }; |
| 955 | |
| 956 | let hypervisor_notifications = if flags.hyp_bitmap_id { |
| 957 | Some(args[5]) |
| 958 | } else { |
| 959 | None |
| 960 | }; |
| 961 | |
| 962 | Ok(Self { |
| 963 | sp_notifications, |
| 964 | vm_notifications, |
| 965 | spm_notifications, |
| 966 | hypervisor_notifications, |
| 967 | }) |
| 968 | } |
| 969 | } |
Imre Kis | 787c500 | 2025-04-10 14:25:51 +0200 | [diff] [blame] | 970 | |
| 971 | /// `FFA_NOTIFICATION_INFO_GET` specific success argument structure. The `MAX_COUNT` parameter |
| 972 | /// depends on the 32-bit or 64-bit packing. |
| 973 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 974 | pub struct SuccessArgsNotificationInfoGet<const MAX_COUNT: usize> { |
| 975 | pub more_pending_notifications: bool, |
| 976 | list_count: usize, |
| 977 | id_counts: [u8; MAX_COUNT], |
| 978 | ids: [u16; MAX_COUNT], |
| 979 | } |
| 980 | |
| 981 | impl<const MAX_COUNT: usize> Default for SuccessArgsNotificationInfoGet<MAX_COUNT> { |
| 982 | fn default() -> Self { |
| 983 | Self { |
| 984 | more_pending_notifications: false, |
| 985 | list_count: 0, |
| 986 | id_counts: [0; MAX_COUNT], |
| 987 | ids: [0; MAX_COUNT], |
| 988 | } |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | impl<const MAX_COUNT: usize> SuccessArgsNotificationInfoGet<MAX_COUNT> { |
| 993 | const MORE_PENDING_NOTIFICATIONS_FLAG: u64 = 1 << 0; |
| 994 | const LIST_COUNT_SHIFT: usize = 7; |
| 995 | const LIST_COUNT_MASK: u64 = 0x1f; |
| 996 | const ID_COUNT_SHIFT: usize = 12; |
| 997 | const ID_COUNT_MASK: u64 = 0x03; |
| 998 | const ID_COUNT_BITS: usize = 2; |
| 999 | |
| 1000 | pub fn add_list(&mut self, endpoint: u16, vcpu_ids: &[u16]) -> Result<(), Error> { |
| 1001 | if self.list_count >= MAX_COUNT || vcpu_ids.len() > Self::ID_COUNT_MASK as usize { |
| 1002 | return Err(Error::InvalidNotificationCount); |
| 1003 | } |
| 1004 | |
| 1005 | // Each list contains at least one ID: the partition ID, followed by vCPU IDs. The number |
| 1006 | // of vCPU IDs is recorded in `id_counts`. |
| 1007 | let mut current_id_index = self.list_count + self.id_counts.iter().sum::<u8>() as usize; |
| 1008 | if current_id_index + 1 + vcpu_ids.len() > MAX_COUNT { |
| 1009 | // The new list does not fit into the available space for IDs. |
| 1010 | return Err(Error::InvalidNotificationCount); |
| 1011 | } |
| 1012 | |
| 1013 | self.id_counts[self.list_count] = vcpu_ids.len() as u8; |
| 1014 | self.list_count += 1; |
| 1015 | |
| 1016 | // The first ID is the endpoint ID. |
| 1017 | self.ids[current_id_index] = endpoint; |
| 1018 | current_id_index += 1; |
| 1019 | |
| 1020 | // Insert the vCPU IDs. |
| 1021 | self.ids[current_id_index..current_id_index + vcpu_ids.len()].copy_from_slice(vcpu_ids); |
| 1022 | |
| 1023 | Ok(()) |
| 1024 | } |
| 1025 | |
| 1026 | pub fn iter(&self) -> NotificationInfoGetIterator<'_> { |
| 1027 | NotificationInfoGetIterator { |
| 1028 | list_index: 0, |
| 1029 | id_index: 0, |
| 1030 | id_count: &self.id_counts[0..self.list_count], |
| 1031 | ids: &self.ids, |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | /// Pack flags field and IDs. |
| 1036 | fn pack(self) -> (u64, [u16; MAX_COUNT]) { |
| 1037 | let mut flags = if self.more_pending_notifications { |
| 1038 | Self::MORE_PENDING_NOTIFICATIONS_FLAG |
| 1039 | } else { |
| 1040 | 0 |
| 1041 | }; |
| 1042 | |
| 1043 | flags |= (self.list_count as u64) << Self::LIST_COUNT_SHIFT; |
| 1044 | for (count, shift) in self.id_counts.iter().take(self.list_count).zip( |
| 1045 | (Self::ID_COUNT_SHIFT..Self::ID_COUNT_SHIFT + Self::ID_COUNT_BITS * MAX_COUNT) |
| 1046 | .step_by(Self::ID_COUNT_BITS), |
| 1047 | ) { |
| 1048 | flags |= u64::from(*count) << shift; |
| 1049 | } |
| 1050 | |
| 1051 | (flags, self.ids) |
| 1052 | } |
| 1053 | |
| 1054 | /// Unpack flags field and IDs. |
| 1055 | fn unpack(flags: u64, ids: [u16; MAX_COUNT]) -> Result<Self, Error> { |
| 1056 | let count_of_lists = ((flags >> Self::LIST_COUNT_SHIFT) & Self::LIST_COUNT_MASK) as usize; |
| 1057 | |
| 1058 | if count_of_lists > MAX_COUNT { |
| 1059 | return Err(Error::InvalidNotificationCount); |
| 1060 | } |
| 1061 | |
| 1062 | let mut count_of_ids = [0; MAX_COUNT]; |
| 1063 | let mut count_of_ids_bits = flags >> Self::ID_COUNT_SHIFT; |
| 1064 | |
| 1065 | for id in count_of_ids.iter_mut().take(count_of_lists) { |
| 1066 | *id = (count_of_ids_bits & Self::ID_COUNT_MASK) as u8; |
| 1067 | count_of_ids_bits >>= Self::ID_COUNT_BITS; |
| 1068 | } |
| 1069 | |
Imre Kis | 7846c9f | 2025-04-15 09:45:00 +0200 | [diff] [blame] | 1070 | let id_field_count = count_of_lists + count_of_ids.iter().sum::<u8>() as usize; |
| 1071 | if id_field_count > MAX_COUNT { |
| 1072 | return Err(Error::InvalidNotificationCount); |
| 1073 | } |
| 1074 | |
Imre Kis | 787c500 | 2025-04-10 14:25:51 +0200 | [diff] [blame] | 1075 | Ok(Self { |
| 1076 | more_pending_notifications: (flags & Self::MORE_PENDING_NOTIFICATIONS_FLAG) != 0, |
| 1077 | list_count: count_of_lists, |
| 1078 | id_counts: count_of_ids, |
| 1079 | ids, |
| 1080 | }) |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | /// `FFA_NOTIFICATION_INFO_GET_32` specific success argument structure. |
| 1085 | pub type SuccessArgsNotificationInfoGet32 = SuccessArgsNotificationInfoGet<10>; |
| 1086 | |
| 1087 | impl From<SuccessArgsNotificationInfoGet32> for SuccessArgs { |
| 1088 | fn from(value: SuccessArgsNotificationInfoGet32) -> Self { |
| 1089 | let (flags, ids) = value.pack(); |
| 1090 | let id_regs: [u32; 5] = transmute!(ids); |
| 1091 | |
| 1092 | let mut args = [0; 6]; |
| 1093 | args[0] = flags as u32; |
| 1094 | args[1..6].copy_from_slice(&id_regs); |
| 1095 | |
| 1096 | SuccessArgs::Args32(args) |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | impl TryFrom<SuccessArgs> for SuccessArgsNotificationInfoGet32 { |
| 1101 | type Error = Error; |
| 1102 | |
| 1103 | fn try_from(value: SuccessArgs) -> Result<Self, Self::Error> { |
| 1104 | let args = value.try_get_args32()?; |
| 1105 | let flags = args[0].into(); |
| 1106 | let id_regs: [u32; 5] = args[1..6].try_into().unwrap(); |
| 1107 | Self::unpack(flags, transmute!(id_regs)) |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | /// `FFA_NOTIFICATION_INFO_GET_64` specific success argument structure. |
| 1112 | pub type SuccessArgsNotificationInfoGet64 = SuccessArgsNotificationInfoGet<20>; |
| 1113 | |
| 1114 | impl From<SuccessArgsNotificationInfoGet64> for SuccessArgs { |
| 1115 | fn from(value: SuccessArgsNotificationInfoGet64) -> Self { |
| 1116 | let (flags, ids) = value.pack(); |
| 1117 | let id_regs: [u64; 5] = transmute!(ids); |
| 1118 | |
| 1119 | let mut args = [0; 6]; |
| 1120 | args[0] = flags; |
| 1121 | args[1..6].copy_from_slice(&id_regs); |
| 1122 | |
| 1123 | SuccessArgs::Args64(args) |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | impl TryFrom<SuccessArgs> for SuccessArgsNotificationInfoGet64 { |
| 1128 | type Error = Error; |
| 1129 | |
| 1130 | fn try_from(value: SuccessArgs) -> Result<Self, Self::Error> { |
| 1131 | let args = value.try_get_args64()?; |
| 1132 | let flags = args[0]; |
| 1133 | let id_regs: [u64; 5] = args[1..6].try_into().unwrap(); |
| 1134 | Self::unpack(flags, transmute!(id_regs)) |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | pub struct NotificationInfoGetIterator<'a> { |
| 1139 | list_index: usize, |
| 1140 | id_index: usize, |
| 1141 | id_count: &'a [u8], |
| 1142 | ids: &'a [u16], |
| 1143 | } |
| 1144 | |
| 1145 | impl<'a> Iterator for NotificationInfoGetIterator<'a> { |
| 1146 | type Item = (u16, &'a [u16]); |
| 1147 | |
| 1148 | fn next(&mut self) -> Option<Self::Item> { |
| 1149 | if self.list_index < self.id_count.len() { |
| 1150 | let partition_id = self.ids[self.id_index]; |
| 1151 | let id_range = |
| 1152 | (self.id_index + 1)..=(self.id_index + self.id_count[self.list_index] as usize); |
| 1153 | |
| 1154 | self.id_index += 1 + self.id_count[self.list_index] as usize; |
| 1155 | self.list_index += 1; |
| 1156 | |
| 1157 | Some((partition_id, &self.ids[id_range])) |
| 1158 | } else { |
| 1159 | None |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | |
Tomás González | f268e32 | 2025-03-05 11:18:11 +0000 | [diff] [blame] | 1164 | /// FF-A "message types", the terminology used by the spec is "interfaces". |
| 1165 | /// |
| 1166 | /// The interfaces are used by FF-A components for communication at an FF-A instance. The spec also |
| 1167 | /// describes the valid FF-A instances and conduits for each interface. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1168 | #[derive(Debug, Eq, PartialEq, Clone, Copy)] |
| 1169 | pub enum Interface { |
| 1170 | Error { |
| 1171 | target_info: TargetInfo, |
| 1172 | error_code: FfaError, |
Balint Dobszay | b727aab | 2025-04-07 10:24:59 +0200 | [diff] [blame] | 1173 | error_arg: u32, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1174 | }, |
| 1175 | Success { |
| 1176 | target_info: u32, |
| 1177 | args: SuccessArgs, |
| 1178 | }, |
| 1179 | Interrupt { |
| 1180 | target_info: TargetInfo, |
| 1181 | interrupt_id: u32, |
| 1182 | }, |
| 1183 | Version { |
| 1184 | input_version: Version, |
| 1185 | }, |
| 1186 | VersionOut { |
| 1187 | output_version: Version, |
| 1188 | }, |
| 1189 | Features { |
| 1190 | feat_id: Feature, |
| 1191 | input_properties: u32, |
| 1192 | }, |
| 1193 | RxAcquire { |
| 1194 | vm_id: u16, |
| 1195 | }, |
| 1196 | RxRelease { |
| 1197 | vm_id: u16, |
| 1198 | }, |
| 1199 | RxTxMap { |
| 1200 | addr: RxTxAddr, |
| 1201 | page_cnt: u32, |
| 1202 | }, |
| 1203 | RxTxUnmap { |
| 1204 | id: u16, |
| 1205 | }, |
| 1206 | PartitionInfoGet { |
| 1207 | uuid: Uuid, |
Imre Kis | e295adb | 2025-04-10 13:26:28 +0200 | [diff] [blame] | 1208 | flags: PartitionInfoGetFlags, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1209 | }, |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 1210 | PartitionInfoGetRegs { |
| 1211 | uuid: Uuid, |
| 1212 | start_index: u16, |
| 1213 | info_tag: u16, |
| 1214 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1215 | IdGet, |
| 1216 | SpmIdGet, |
Tomás González | 092202a | 2025-03-05 11:56:45 +0000 | [diff] [blame] | 1217 | MsgWait { |
| 1218 | flags: Option<MsgWaitFlags>, |
| 1219 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1220 | Yield, |
| 1221 | Run { |
| 1222 | target_info: TargetInfo, |
| 1223 | }, |
| 1224 | NormalWorldResume, |
Tomás González | 17b9244 | 2025-03-10 16:45:04 +0000 | [diff] [blame] | 1225 | SecondaryEpRegister { |
| 1226 | entrypoint: SecondaryEpRegisterAddr, |
| 1227 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1228 | MsgSend2 { |
| 1229 | sender_vm_id: u16, |
| 1230 | flags: u32, |
| 1231 | }, |
| 1232 | MsgSendDirectReq { |
| 1233 | src_id: u16, |
| 1234 | dst_id: u16, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1235 | args: DirectMsgArgs, |
| 1236 | }, |
| 1237 | MsgSendDirectResp { |
| 1238 | src_id: u16, |
| 1239 | dst_id: u16, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1240 | args: DirectMsgArgs, |
| 1241 | }, |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1242 | MsgSendDirectReq2 { |
| 1243 | src_id: u16, |
| 1244 | dst_id: u16, |
| 1245 | uuid: Uuid, |
| 1246 | args: DirectMsg2Args, |
| 1247 | }, |
| 1248 | MsgSendDirectResp2 { |
| 1249 | src_id: u16, |
| 1250 | dst_id: u16, |
| 1251 | args: DirectMsg2Args, |
| 1252 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1253 | MemDonate { |
| 1254 | total_len: u32, |
| 1255 | frag_len: u32, |
| 1256 | buf: Option<MemOpBuf>, |
| 1257 | }, |
| 1258 | MemLend { |
| 1259 | total_len: u32, |
| 1260 | frag_len: u32, |
| 1261 | buf: Option<MemOpBuf>, |
| 1262 | }, |
| 1263 | MemShare { |
| 1264 | total_len: u32, |
| 1265 | frag_len: u32, |
| 1266 | buf: Option<MemOpBuf>, |
| 1267 | }, |
| 1268 | MemRetrieveReq { |
| 1269 | total_len: u32, |
| 1270 | frag_len: u32, |
| 1271 | buf: Option<MemOpBuf>, |
| 1272 | }, |
| 1273 | MemRetrieveResp { |
| 1274 | total_len: u32, |
| 1275 | frag_len: u32, |
| 1276 | }, |
| 1277 | MemRelinquish, |
| 1278 | MemReclaim { |
| 1279 | handle: memory_management::Handle, |
| 1280 | flags: u32, |
| 1281 | }, |
| 1282 | MemPermGet { |
| 1283 | addr: MemAddr, |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1284 | page_cnt: Option<u32>, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1285 | }, |
| 1286 | MemPermSet { |
| 1287 | addr: MemAddr, |
| 1288 | page_cnt: u32, |
Imre Kis | dcb7df2 | 2025-06-06 15:24:40 +0200 | [diff] [blame] | 1289 | mem_perm: memory_management::MemPermissionsGetSet, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1290 | }, |
| 1291 | ConsoleLog { |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 1292 | chars: ConsoleLogChars, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1293 | }, |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 1294 | NotificationBitmapCreate { |
| 1295 | vm_id: u16, |
| 1296 | vcpu_cnt: u32, |
| 1297 | }, |
| 1298 | NotificationBitmapDestroy { |
| 1299 | vm_id: u16, |
| 1300 | }, |
| 1301 | NotificationBind { |
| 1302 | sender_id: u16, |
| 1303 | receiver_id: u16, |
| 1304 | flags: NotificationBindFlags, |
| 1305 | bitmap: u64, |
| 1306 | }, |
Imre Kis | 3571f2c | 2025-05-26 19:29:23 +0200 | [diff] [blame] | 1307 | NotificationUnbind { |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 1308 | sender_id: u16, |
| 1309 | receiver_id: u16, |
| 1310 | bitmap: u64, |
| 1311 | }, |
| 1312 | NotificationSet { |
| 1313 | sender_id: u16, |
| 1314 | receiver_id: u16, |
| 1315 | flags: NotificationSetFlags, |
| 1316 | bitmap: u64, |
| 1317 | }, |
| 1318 | NotificationGet { |
| 1319 | vcpu_id: u16, |
| 1320 | endpoint_id: u16, |
| 1321 | flags: NotificationGetFlags, |
| 1322 | }, |
| 1323 | NotificationInfoGet { |
| 1324 | is_32bit: bool, |
| 1325 | }, |
Tomás González | e6fe75f | 2025-04-04 09:46:50 +0100 | [diff] [blame] | 1326 | El3IntrHandle, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1327 | } |
| 1328 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1329 | impl Interface { |
| 1330 | /// Returns the function ID for the call, if it has one. |
| 1331 | pub fn function_id(&self) -> Option<FuncId> { |
| 1332 | match self { |
| 1333 | Interface::Error { .. } => Some(FuncId::Error), |
| 1334 | Interface::Success { args, .. } => match args { |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 1335 | SuccessArgs::Args32(..) => Some(FuncId::Success32), |
| 1336 | SuccessArgs::Args64(..) | SuccessArgs::Args64_2(..) => Some(FuncId::Success64), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1337 | }, |
| 1338 | Interface::Interrupt { .. } => Some(FuncId::Interrupt), |
| 1339 | Interface::Version { .. } => Some(FuncId::Version), |
| 1340 | Interface::VersionOut { .. } => None, |
| 1341 | Interface::Features { .. } => Some(FuncId::Features), |
| 1342 | Interface::RxAcquire { .. } => Some(FuncId::RxAcquire), |
| 1343 | Interface::RxRelease { .. } => Some(FuncId::RxRelease), |
| 1344 | Interface::RxTxMap { addr, .. } => match addr { |
| 1345 | RxTxAddr::Addr32 { .. } => Some(FuncId::RxTxMap32), |
| 1346 | RxTxAddr::Addr64 { .. } => Some(FuncId::RxTxMap64), |
| 1347 | }, |
| 1348 | Interface::RxTxUnmap { .. } => Some(FuncId::RxTxUnmap), |
| 1349 | Interface::PartitionInfoGet { .. } => Some(FuncId::PartitionInfoGet), |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 1350 | Interface::PartitionInfoGetRegs { .. } => Some(FuncId::PartitionInfoGetRegs), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1351 | Interface::IdGet => Some(FuncId::IdGet), |
| 1352 | Interface::SpmIdGet => Some(FuncId::SpmIdGet), |
Tomás González | 092202a | 2025-03-05 11:56:45 +0000 | [diff] [blame] | 1353 | Interface::MsgWait { .. } => Some(FuncId::MsgWait), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1354 | Interface::Yield => Some(FuncId::Yield), |
| 1355 | Interface::Run { .. } => Some(FuncId::Run), |
| 1356 | Interface::NormalWorldResume => Some(FuncId::NormalWorldResume), |
Tomás González | 17b9244 | 2025-03-10 16:45:04 +0000 | [diff] [blame] | 1357 | Interface::SecondaryEpRegister { entrypoint } => match entrypoint { |
| 1358 | SecondaryEpRegisterAddr::Addr32 { .. } => Some(FuncId::SecondaryEpRegister32), |
| 1359 | SecondaryEpRegisterAddr::Addr64 { .. } => Some(FuncId::SecondaryEpRegister64), |
| 1360 | }, |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1361 | Interface::MsgSend2 { .. } => Some(FuncId::MsgSend2), |
| 1362 | Interface::MsgSendDirectReq { args, .. } => match args { |
| 1363 | DirectMsgArgs::Args32(_) => Some(FuncId::MsgSendDirectReq32), |
| 1364 | DirectMsgArgs::Args64(_) => Some(FuncId::MsgSendDirectReq64), |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 1365 | DirectMsgArgs::VersionReq { .. } => Some(FuncId::MsgSendDirectReq32), |
| 1366 | DirectMsgArgs::PowerPsciReq32 { .. } => Some(FuncId::MsgSendDirectReq32), |
| 1367 | DirectMsgArgs::PowerPsciReq64 { .. } => Some(FuncId::MsgSendDirectReq64), |
| 1368 | DirectMsgArgs::PowerWarmBootReq { .. } => Some(FuncId::MsgSendDirectReq32), |
| 1369 | DirectMsgArgs::VmCreated { .. } => Some(FuncId::MsgSendDirectReq32), |
| 1370 | DirectMsgArgs::VmDestructed { .. } => Some(FuncId::MsgSendDirectReq32), |
Balint Dobszay | 3c1c89a | 2025-04-25 17:36:46 +0200 | [diff] [blame] | 1371 | _ => panic!("Invalid direct request arguments: {:#?}", args), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1372 | }, |
| 1373 | Interface::MsgSendDirectResp { args, .. } => match args { |
| 1374 | DirectMsgArgs::Args32(_) => Some(FuncId::MsgSendDirectResp32), |
| 1375 | DirectMsgArgs::Args64(_) => Some(FuncId::MsgSendDirectResp64), |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 1376 | DirectMsgArgs::VersionResp { .. } => Some(FuncId::MsgSendDirectResp32), |
| 1377 | DirectMsgArgs::PowerPsciResp { .. } => Some(FuncId::MsgSendDirectResp32), |
| 1378 | DirectMsgArgs::VmCreatedAck { .. } => Some(FuncId::MsgSendDirectResp32), |
| 1379 | DirectMsgArgs::VmDestructedAck { .. } => Some(FuncId::MsgSendDirectResp32), |
Balint Dobszay | 3c1c89a | 2025-04-25 17:36:46 +0200 | [diff] [blame] | 1380 | _ => panic!("Invalid direct response arguments: {:#?}", args), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1381 | }, |
| 1382 | Interface::MsgSendDirectReq2 { .. } => Some(FuncId::MsgSendDirectReq64_2), |
| 1383 | Interface::MsgSendDirectResp2 { .. } => Some(FuncId::MsgSendDirectResp64_2), |
| 1384 | Interface::MemDonate { buf, .. } => match buf { |
| 1385 | Some(MemOpBuf::Buf64 { .. }) => Some(FuncId::MemDonate64), |
| 1386 | _ => Some(FuncId::MemDonate32), |
| 1387 | }, |
| 1388 | Interface::MemLend { buf, .. } => match buf { |
| 1389 | Some(MemOpBuf::Buf64 { .. }) => Some(FuncId::MemLend64), |
| 1390 | _ => Some(FuncId::MemLend32), |
| 1391 | }, |
| 1392 | Interface::MemShare { buf, .. } => match buf { |
| 1393 | Some(MemOpBuf::Buf64 { .. }) => Some(FuncId::MemShare64), |
| 1394 | _ => Some(FuncId::MemShare32), |
| 1395 | }, |
| 1396 | Interface::MemRetrieveReq { buf, .. } => match buf { |
| 1397 | Some(MemOpBuf::Buf64 { .. }) => Some(FuncId::MemRetrieveReq64), |
| 1398 | _ => Some(FuncId::MemRetrieveReq32), |
| 1399 | }, |
| 1400 | Interface::MemRetrieveResp { .. } => Some(FuncId::MemRetrieveResp), |
| 1401 | Interface::MemRelinquish => Some(FuncId::MemRelinquish), |
| 1402 | Interface::MemReclaim { .. } => Some(FuncId::MemReclaim), |
| 1403 | Interface::MemPermGet { addr, .. } => match addr { |
| 1404 | MemAddr::Addr32(_) => Some(FuncId::MemPermGet32), |
| 1405 | MemAddr::Addr64(_) => Some(FuncId::MemPermGet64), |
| 1406 | }, |
| 1407 | Interface::MemPermSet { addr, .. } => match addr { |
| 1408 | MemAddr::Addr32(_) => Some(FuncId::MemPermSet32), |
| 1409 | MemAddr::Addr64(_) => Some(FuncId::MemPermSet64), |
| 1410 | }, |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 1411 | Interface::ConsoleLog { chars, .. } => match chars { |
| 1412 | ConsoleLogChars::Chars32(_) => Some(FuncId::ConsoleLog32), |
| 1413 | ConsoleLogChars::Chars64(_) => Some(FuncId::ConsoleLog64), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1414 | }, |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 1415 | Interface::NotificationBitmapCreate { .. } => Some(FuncId::NotificationBitmapCreate), |
| 1416 | Interface::NotificationBitmapDestroy { .. } => Some(FuncId::NotificationBitmapDestroy), |
| 1417 | Interface::NotificationBind { .. } => Some(FuncId::NotificationBind), |
Imre Kis | 3571f2c | 2025-05-26 19:29:23 +0200 | [diff] [blame] | 1418 | Interface::NotificationUnbind { .. } => Some(FuncId::NotificationUnbind), |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 1419 | Interface::NotificationSet { .. } => Some(FuncId::NotificationSet), |
| 1420 | Interface::NotificationGet { .. } => Some(FuncId::NotificationGet), |
| 1421 | Interface::NotificationInfoGet { is_32bit } => match is_32bit { |
| 1422 | true => Some(FuncId::NotificationInfoGet32), |
| 1423 | false => Some(FuncId::NotificationInfoGet64), |
| 1424 | }, |
Tomás González | e6fe75f | 2025-04-04 09:46:50 +0100 | [diff] [blame] | 1425 | Interface::El3IntrHandle => Some(FuncId::El3IntrHandle), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1426 | } |
| 1427 | } |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1428 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1429 | /// Returns true if this is a 32-bit call, or false if it is a 64-bit call. |
| 1430 | pub fn is_32bit(&self) -> bool { |
Balint Dobszay | 3c1c89a | 2025-04-25 17:36:46 +0200 | [diff] [blame] | 1431 | if matches!(self, Self::VersionOut { .. }) { |
| 1432 | return true; |
| 1433 | } |
| 1434 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1435 | self.function_id().unwrap().is_32bit() |
| 1436 | } |
| 1437 | |
Balint Dobszay | 82c71dd | 2025-04-15 10:16:44 +0200 | [diff] [blame] | 1438 | /// Returns the FF-A version that has introduced the function ID. |
| 1439 | pub fn minimum_ffa_version(&self) -> Version { |
Balint Dobszay | 3c1c89a | 2025-04-25 17:36:46 +0200 | [diff] [blame] | 1440 | if matches!(self, Self::VersionOut { .. }) { |
| 1441 | return Version(1, 0); |
| 1442 | } |
| 1443 | |
Balint Dobszay | 82c71dd | 2025-04-15 10:16:44 +0200 | [diff] [blame] | 1444 | self.function_id().unwrap().minimum_ffa_version() |
| 1445 | } |
| 1446 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1447 | /// Parse interface from register contents. The caller must ensure that the `regs` argument has |
| 1448 | /// the correct length: 8 registers for FF-A v1.1 and lower, 18 registers for v1.2 and higher. |
| 1449 | pub fn from_regs(version: Version, regs: &[u64]) -> Result<Self, Error> { |
Balint Dobszay | 82c71dd | 2025-04-15 10:16:44 +0200 | [diff] [blame] | 1450 | let func_id = FuncId::try_from(regs[0] as u32)?; |
| 1451 | if version < func_id.minimum_ffa_version() { |
| 1452 | return Err(Error::InvalidVersionForFunctionId(version, func_id)); |
| 1453 | } |
| 1454 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1455 | let reg_cnt = regs.len(); |
| 1456 | |
| 1457 | let msg = match reg_cnt { |
| 1458 | 8 => { |
| 1459 | assert!(version <= Version(1, 1)); |
| 1460 | Interface::unpack_regs8(version, regs.try_into().unwrap())? |
| 1461 | } |
| 1462 | 18 => { |
| 1463 | assert!(version >= Version(1, 2)); |
Balint Dobszay | 82c71dd | 2025-04-15 10:16:44 +0200 | [diff] [blame] | 1464 | match func_id { |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1465 | FuncId::ConsoleLog64 |
| 1466 | | FuncId::Success64 |
| 1467 | | FuncId::MsgSendDirectReq64_2 |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 1468 | | FuncId::MsgSendDirectResp64_2 |
| 1469 | | FuncId::PartitionInfoGetRegs => { |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1470 | Interface::unpack_regs18(version, regs.try_into().unwrap())? |
| 1471 | } |
| 1472 | _ => Interface::unpack_regs8(version, regs[..8].try_into().unwrap())?, |
| 1473 | } |
| 1474 | } |
| 1475 | _ => panic!( |
| 1476 | "Invalid number of registers ({}) for FF-A version {}", |
| 1477 | reg_cnt, version |
| 1478 | ), |
| 1479 | }; |
| 1480 | |
| 1481 | Ok(msg) |
| 1482 | } |
| 1483 | |
| 1484 | fn unpack_regs8(version: Version, regs: &[u64; 8]) -> Result<Self, Error> { |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1485 | let fid = FuncId::try_from(regs[0] as u32)?; |
| 1486 | |
| 1487 | let msg = match fid { |
| 1488 | FuncId::Error => Self::Error { |
| 1489 | target_info: (regs[1] as u32).into(), |
| 1490 | error_code: FfaError::try_from(regs[2] as i32)?, |
Balint Dobszay | b727aab | 2025-04-07 10:24:59 +0200 | [diff] [blame] | 1491 | error_arg: regs[3] as u32, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1492 | }, |
| 1493 | FuncId::Success32 => Self::Success { |
| 1494 | target_info: regs[1] as u32, |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 1495 | args: SuccessArgs::Args32([ |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1496 | regs[2] as u32, |
| 1497 | regs[3] as u32, |
| 1498 | regs[4] as u32, |
| 1499 | regs[5] as u32, |
| 1500 | regs[6] as u32, |
| 1501 | regs[7] as u32, |
| 1502 | ]), |
| 1503 | }, |
| 1504 | FuncId::Success64 => Self::Success { |
| 1505 | target_info: regs[1] as u32, |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 1506 | args: SuccessArgs::Args64([regs[2], regs[3], regs[4], regs[5], regs[6], regs[7]]), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1507 | }, |
| 1508 | FuncId::Interrupt => Self::Interrupt { |
| 1509 | target_info: (regs[1] as u32).into(), |
| 1510 | interrupt_id: regs[2] as u32, |
| 1511 | }, |
| 1512 | FuncId::Version => Self::Version { |
Tomás González | 83146af | 2025-03-04 11:32:41 +0000 | [diff] [blame] | 1513 | input_version: (regs[1] as u32).try_into()?, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1514 | }, |
| 1515 | FuncId::Features => Self::Features { |
Balint Dobszay | c31e0b9 | 2025-03-03 20:16:56 +0100 | [diff] [blame] | 1516 | feat_id: (regs[1] as u32).into(), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1517 | input_properties: regs[2] as u32, |
| 1518 | }, |
| 1519 | FuncId::RxAcquire => Self::RxAcquire { |
| 1520 | vm_id: regs[1] as u16, |
| 1521 | }, |
| 1522 | FuncId::RxRelease => Self::RxRelease { |
| 1523 | vm_id: regs[1] as u16, |
| 1524 | }, |
| 1525 | FuncId::RxTxMap32 => { |
| 1526 | let addr = RxTxAddr::Addr32 { |
| 1527 | rx: regs[2] as u32, |
| 1528 | tx: regs[1] as u32, |
| 1529 | }; |
| 1530 | let page_cnt = regs[3] as u32; |
| 1531 | |
| 1532 | Self::RxTxMap { addr, page_cnt } |
| 1533 | } |
| 1534 | FuncId::RxTxMap64 => { |
| 1535 | let addr = RxTxAddr::Addr64 { |
| 1536 | rx: regs[2], |
| 1537 | tx: regs[1], |
| 1538 | }; |
| 1539 | let page_cnt = regs[3] as u32; |
| 1540 | |
| 1541 | Self::RxTxMap { addr, page_cnt } |
| 1542 | } |
| 1543 | FuncId::RxTxUnmap => Self::RxTxUnmap { id: regs[1] as u16 }, |
| 1544 | FuncId::PartitionInfoGet => { |
| 1545 | let uuid_words = [ |
| 1546 | regs[1] as u32, |
| 1547 | regs[2] as u32, |
| 1548 | regs[3] as u32, |
| 1549 | regs[4] as u32, |
| 1550 | ]; |
| 1551 | let mut bytes: [u8; 16] = [0; 16]; |
| 1552 | for (i, b) in uuid_words.iter().flat_map(|w| w.to_le_bytes()).enumerate() { |
| 1553 | bytes[i] = b; |
| 1554 | } |
| 1555 | Self::PartitionInfoGet { |
| 1556 | uuid: Uuid::from_bytes(bytes), |
Imre Kis | e295adb | 2025-04-10 13:26:28 +0200 | [diff] [blame] | 1557 | flags: PartitionInfoGetFlags::try_from(regs[5] as u32)?, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1558 | } |
| 1559 | } |
| 1560 | FuncId::IdGet => Self::IdGet, |
| 1561 | FuncId::SpmIdGet => Self::SpmIdGet, |
Tomás González | 092202a | 2025-03-05 11:56:45 +0000 | [diff] [blame] | 1562 | FuncId::MsgWait => Self::MsgWait { |
| 1563 | flags: if version >= Version(1, 2) { |
| 1564 | Some(MsgWaitFlags::try_from(regs[2] as u32)?) |
| 1565 | } else { |
| 1566 | None |
| 1567 | }, |
| 1568 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1569 | FuncId::Yield => Self::Yield, |
| 1570 | FuncId::Run => Self::Run { |
| 1571 | target_info: (regs[1] as u32).into(), |
| 1572 | }, |
| 1573 | FuncId::NormalWorldResume => Self::NormalWorldResume, |
Tomás González | 17b9244 | 2025-03-10 16:45:04 +0000 | [diff] [blame] | 1574 | FuncId::SecondaryEpRegister32 => Self::SecondaryEpRegister { |
| 1575 | entrypoint: SecondaryEpRegisterAddr::Addr32(regs[1] as u32), |
| 1576 | }, |
| 1577 | FuncId::SecondaryEpRegister64 => Self::SecondaryEpRegister { |
| 1578 | entrypoint: SecondaryEpRegisterAddr::Addr64(regs[1]), |
| 1579 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1580 | FuncId::MsgSend2 => Self::MsgSend2 { |
| 1581 | sender_vm_id: regs[1] as u16, |
| 1582 | flags: regs[2] as u32, |
| 1583 | }, |
| 1584 | FuncId::MsgSendDirectReq32 => Self::MsgSendDirectReq { |
| 1585 | src_id: (regs[1] >> 16) as u16, |
| 1586 | dst_id: regs[1] as u16, |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 1587 | args: if (regs[2] as u32 & DirectMsgArgs::FWK_MSG_BITS) != 0 { |
| 1588 | match regs[2] as u32 { |
| 1589 | DirectMsgArgs::VERSION_REQ => DirectMsgArgs::VersionReq { |
| 1590 | version: Version::try_from(regs[3] as u32)?, |
| 1591 | }, |
| 1592 | DirectMsgArgs::POWER_PSCI_REQ => DirectMsgArgs::PowerPsciReq32 { |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 1593 | params: [ |
| 1594 | regs[3] as u32, |
| 1595 | regs[4] as u32, |
| 1596 | regs[5] as u32, |
| 1597 | regs[6] as u32, |
| 1598 | ], |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 1599 | }, |
| 1600 | DirectMsgArgs::POWER_WARM_BOOT_REQ => DirectMsgArgs::PowerWarmBootReq { |
| 1601 | boot_type: WarmBootType::try_from(regs[3] as u32)?, |
| 1602 | }, |
| 1603 | DirectMsgArgs::VM_CREATED => DirectMsgArgs::VmCreated { |
| 1604 | handle: memory_management::Handle::from([ |
| 1605 | regs[3] as u32, |
| 1606 | regs[4] as u32, |
| 1607 | ]), |
| 1608 | vm_id: regs[5] as u16, |
| 1609 | }, |
| 1610 | DirectMsgArgs::VM_DESTRUCTED => DirectMsgArgs::VmDestructed { |
| 1611 | handle: memory_management::Handle::from([ |
| 1612 | regs[3] as u32, |
| 1613 | regs[4] as u32, |
| 1614 | ]), |
| 1615 | vm_id: regs[5] as u16, |
| 1616 | }, |
| 1617 | _ => return Err(Error::UnrecognisedFwkMsg(regs[2] as u32)), |
| 1618 | } |
| 1619 | } else { |
| 1620 | DirectMsgArgs::Args32([ |
| 1621 | regs[3] as u32, |
| 1622 | regs[4] as u32, |
| 1623 | regs[5] as u32, |
| 1624 | regs[6] as u32, |
| 1625 | regs[7] as u32, |
| 1626 | ]) |
| 1627 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1628 | }, |
| 1629 | FuncId::MsgSendDirectReq64 => Self::MsgSendDirectReq { |
| 1630 | src_id: (regs[1] >> 16) as u16, |
| 1631 | dst_id: regs[1] as u16, |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 1632 | args: if (regs[2] & DirectMsgArgs::FWK_MSG_BITS as u64) != 0 { |
| 1633 | match regs[2] as u32 { |
| 1634 | DirectMsgArgs::POWER_PSCI_REQ => DirectMsgArgs::PowerPsciReq64 { |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 1635 | params: [regs[3], regs[4], regs[5], regs[6]], |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 1636 | }, |
| 1637 | _ => return Err(Error::UnrecognisedFwkMsg(regs[2] as u32)), |
| 1638 | } |
| 1639 | } else { |
| 1640 | DirectMsgArgs::Args64([regs[3], regs[4], regs[5], regs[6], regs[7]]) |
| 1641 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1642 | }, |
| 1643 | FuncId::MsgSendDirectResp32 => Self::MsgSendDirectResp { |
| 1644 | src_id: (regs[1] >> 16) as u16, |
| 1645 | dst_id: regs[1] as u16, |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 1646 | args: if (regs[2] as u32 & DirectMsgArgs::FWK_MSG_BITS) != 0 { |
| 1647 | match regs[2] as u32 { |
| 1648 | DirectMsgArgs::VERSION_RESP => { |
| 1649 | if regs[3] as i32 == FfaError::NotSupported.into() { |
| 1650 | DirectMsgArgs::VersionResp { version: None } |
| 1651 | } else { |
| 1652 | DirectMsgArgs::VersionResp { |
| 1653 | version: Some(Version::try_from(regs[3] as u32)?), |
| 1654 | } |
| 1655 | } |
| 1656 | } |
| 1657 | DirectMsgArgs::POWER_PSCI_RESP => DirectMsgArgs::PowerPsciResp { |
| 1658 | psci_status: regs[3] as i32, |
| 1659 | }, |
| 1660 | DirectMsgArgs::VM_CREATED_ACK => DirectMsgArgs::VmCreatedAck { |
| 1661 | sp_status: (regs[3] as i32).try_into()?, |
| 1662 | }, |
| 1663 | DirectMsgArgs::VM_DESTRUCTED_ACK => DirectMsgArgs::VmDestructedAck { |
| 1664 | sp_status: (regs[3] as i32).try_into()?, |
| 1665 | }, |
| 1666 | _ => return Err(Error::UnrecognisedFwkMsg(regs[2] as u32)), |
| 1667 | } |
| 1668 | } else { |
| 1669 | DirectMsgArgs::Args32([ |
| 1670 | regs[3] as u32, |
| 1671 | regs[4] as u32, |
| 1672 | regs[5] as u32, |
| 1673 | regs[6] as u32, |
| 1674 | regs[7] as u32, |
| 1675 | ]) |
| 1676 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1677 | }, |
| 1678 | FuncId::MsgSendDirectResp64 => Self::MsgSendDirectResp { |
| 1679 | src_id: (regs[1] >> 16) as u16, |
| 1680 | dst_id: regs[1] as u16, |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 1681 | args: if (regs[2] & DirectMsgArgs::FWK_MSG_BITS as u64) != 0 { |
| 1682 | return Err(Error::UnrecognisedFwkMsg(regs[2] as u32)); |
| 1683 | } else { |
| 1684 | DirectMsgArgs::Args64([regs[3], regs[4], regs[5], regs[6], regs[7]]) |
| 1685 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1686 | }, |
| 1687 | FuncId::MemDonate32 => Self::MemDonate { |
| 1688 | total_len: regs[1] as u32, |
| 1689 | frag_len: regs[2] as u32, |
| 1690 | buf: if regs[3] != 0 && regs[4] != 0 { |
| 1691 | Some(MemOpBuf::Buf32 { |
| 1692 | addr: regs[3] as u32, |
| 1693 | page_cnt: regs[4] as u32, |
| 1694 | }) |
| 1695 | } else { |
| 1696 | None |
| 1697 | }, |
| 1698 | }, |
| 1699 | FuncId::MemDonate64 => Self::MemDonate { |
| 1700 | total_len: regs[1] as u32, |
| 1701 | frag_len: regs[2] as u32, |
| 1702 | buf: if regs[3] != 0 && regs[4] != 0 { |
| 1703 | Some(MemOpBuf::Buf64 { |
| 1704 | addr: regs[3], |
| 1705 | page_cnt: regs[4] as u32, |
| 1706 | }) |
| 1707 | } else { |
| 1708 | None |
| 1709 | }, |
| 1710 | }, |
| 1711 | FuncId::MemLend32 => Self::MemLend { |
| 1712 | total_len: regs[1] as u32, |
| 1713 | frag_len: regs[2] as u32, |
| 1714 | buf: if regs[3] != 0 && regs[4] != 0 { |
| 1715 | Some(MemOpBuf::Buf32 { |
| 1716 | addr: regs[3] as u32, |
| 1717 | page_cnt: regs[4] as u32, |
| 1718 | }) |
| 1719 | } else { |
| 1720 | None |
| 1721 | }, |
| 1722 | }, |
| 1723 | FuncId::MemLend64 => Self::MemLend { |
| 1724 | total_len: regs[1] as u32, |
| 1725 | frag_len: regs[2] as u32, |
| 1726 | buf: if regs[3] != 0 && regs[4] != 0 { |
| 1727 | Some(MemOpBuf::Buf64 { |
| 1728 | addr: regs[3], |
| 1729 | page_cnt: regs[4] as u32, |
| 1730 | }) |
| 1731 | } else { |
| 1732 | None |
| 1733 | }, |
| 1734 | }, |
| 1735 | FuncId::MemShare32 => Self::MemShare { |
| 1736 | total_len: regs[1] as u32, |
| 1737 | frag_len: regs[2] as u32, |
| 1738 | buf: if regs[3] != 0 && regs[4] != 0 { |
| 1739 | Some(MemOpBuf::Buf32 { |
| 1740 | addr: regs[3] as u32, |
| 1741 | page_cnt: regs[4] as u32, |
| 1742 | }) |
| 1743 | } else { |
| 1744 | None |
| 1745 | }, |
| 1746 | }, |
| 1747 | FuncId::MemShare64 => Self::MemShare { |
| 1748 | total_len: regs[1] as u32, |
| 1749 | frag_len: regs[2] as u32, |
| 1750 | buf: if regs[3] != 0 && regs[4] != 0 { |
| 1751 | Some(MemOpBuf::Buf64 { |
| 1752 | addr: regs[3], |
| 1753 | page_cnt: regs[4] as u32, |
| 1754 | }) |
| 1755 | } else { |
| 1756 | None |
| 1757 | }, |
| 1758 | }, |
| 1759 | FuncId::MemRetrieveReq32 => Self::MemRetrieveReq { |
| 1760 | total_len: regs[1] as u32, |
| 1761 | frag_len: regs[2] as u32, |
| 1762 | buf: if regs[3] != 0 && regs[4] != 0 { |
| 1763 | Some(MemOpBuf::Buf32 { |
| 1764 | addr: regs[3] as u32, |
| 1765 | page_cnt: regs[4] as u32, |
| 1766 | }) |
| 1767 | } else { |
| 1768 | None |
| 1769 | }, |
| 1770 | }, |
| 1771 | FuncId::MemRetrieveReq64 => Self::MemRetrieveReq { |
| 1772 | total_len: regs[1] as u32, |
| 1773 | frag_len: regs[2] as u32, |
| 1774 | buf: if regs[3] != 0 && regs[4] != 0 { |
| 1775 | Some(MemOpBuf::Buf64 { |
| 1776 | addr: regs[3], |
| 1777 | page_cnt: regs[4] as u32, |
| 1778 | }) |
| 1779 | } else { |
| 1780 | None |
| 1781 | }, |
| 1782 | }, |
| 1783 | FuncId::MemRetrieveResp => Self::MemRetrieveResp { |
| 1784 | total_len: regs[1] as u32, |
| 1785 | frag_len: regs[2] as u32, |
| 1786 | }, |
| 1787 | FuncId::MemRelinquish => Self::MemRelinquish, |
| 1788 | FuncId::MemReclaim => Self::MemReclaim { |
| 1789 | handle: memory_management::Handle::from([regs[1] as u32, regs[2] as u32]), |
| 1790 | flags: regs[3] as u32, |
| 1791 | }, |
| 1792 | FuncId::MemPermGet32 => Self::MemPermGet { |
| 1793 | addr: MemAddr::Addr32(regs[1] as u32), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1794 | page_cnt: if version >= Version(1, 3) { |
| 1795 | Some(regs[2] as u32) |
| 1796 | } else { |
| 1797 | None |
| 1798 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1799 | }, |
| 1800 | FuncId::MemPermGet64 => Self::MemPermGet { |
| 1801 | addr: MemAddr::Addr64(regs[1]), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1802 | page_cnt: if version >= Version(1, 3) { |
| 1803 | Some(regs[2] as u32) |
| 1804 | } else { |
| 1805 | None |
| 1806 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1807 | }, |
| 1808 | FuncId::MemPermSet32 => Self::MemPermSet { |
| 1809 | addr: MemAddr::Addr32(regs[1] as u32), |
| 1810 | page_cnt: regs[2] as u32, |
Imre Kis | dcb7df2 | 2025-06-06 15:24:40 +0200 | [diff] [blame] | 1811 | mem_perm: (regs[3] as u32).try_into()?, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1812 | }, |
| 1813 | FuncId::MemPermSet64 => Self::MemPermSet { |
| 1814 | addr: MemAddr::Addr64(regs[1]), |
| 1815 | page_cnt: regs[2] as u32, |
Imre Kis | dcb7df2 | 2025-06-06 15:24:40 +0200 | [diff] [blame] | 1816 | mem_perm: (regs[3] as u32).try_into()?, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1817 | }, |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 1818 | FuncId::ConsoleLog32 => { |
| 1819 | let char_cnt = regs[1] as u8; |
| 1820 | if char_cnt > ConsoleLogChars32::MAX_LENGTH { |
| 1821 | return Err(Error::InvalidCharacterCount(char_cnt)); |
| 1822 | } |
| 1823 | |
| 1824 | Self::ConsoleLog { |
| 1825 | chars: ConsoleLogChars::Chars32(ConsoleLogChars32 { |
| 1826 | char_cnt, |
| 1827 | char_lists: [ |
| 1828 | regs[2] as u32, |
| 1829 | regs[3] as u32, |
| 1830 | regs[4] as u32, |
| 1831 | regs[5] as u32, |
| 1832 | regs[6] as u32, |
| 1833 | regs[7] as u32, |
| 1834 | ], |
| 1835 | }), |
| 1836 | } |
| 1837 | } |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 1838 | FuncId::NotificationBitmapCreate => { |
| 1839 | let tentative_vm_id = regs[1] as u32; |
| 1840 | if (tentative_vm_id >> 16) != 0 { |
| 1841 | return Err(Error::InvalidVmId(tentative_vm_id)); |
| 1842 | } |
| 1843 | Self::NotificationBitmapCreate { |
| 1844 | vm_id: tentative_vm_id as u16, |
| 1845 | vcpu_cnt: regs[2] as u32, |
| 1846 | } |
| 1847 | } |
| 1848 | FuncId::NotificationBitmapDestroy => { |
| 1849 | let tentative_vm_id = regs[1] as u32; |
| 1850 | if (tentative_vm_id >> 16) != 0 { |
| 1851 | return Err(Error::InvalidVmId(tentative_vm_id)); |
| 1852 | } |
| 1853 | Self::NotificationBitmapDestroy { |
| 1854 | vm_id: tentative_vm_id as u16, |
| 1855 | } |
| 1856 | } |
| 1857 | FuncId::NotificationBind => Self::NotificationBind { |
| 1858 | sender_id: (regs[1] >> 16) as u16, |
| 1859 | receiver_id: regs[1] as u16, |
| 1860 | flags: (regs[2] as u32).into(), |
| 1861 | bitmap: (regs[4] << 32) | (regs[3] & 0xffff_ffff), |
| 1862 | }, |
Imre Kis | 3571f2c | 2025-05-26 19:29:23 +0200 | [diff] [blame] | 1863 | FuncId::NotificationUnbind => Self::NotificationUnbind { |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 1864 | sender_id: (regs[1] >> 16) as u16, |
| 1865 | receiver_id: regs[1] as u16, |
| 1866 | bitmap: (regs[4] << 32) | (regs[3] & 0xffff_ffff), |
| 1867 | }, |
| 1868 | FuncId::NotificationSet => Self::NotificationSet { |
| 1869 | sender_id: (regs[1] >> 16) as u16, |
| 1870 | receiver_id: regs[1] as u16, |
| 1871 | flags: (regs[2] as u32).try_into()?, |
| 1872 | bitmap: (regs[4] << 32) | (regs[3] & 0xffff_ffff), |
| 1873 | }, |
| 1874 | FuncId::NotificationGet => Self::NotificationGet { |
| 1875 | vcpu_id: (regs[1] >> 16) as u16, |
| 1876 | endpoint_id: regs[1] as u16, |
| 1877 | flags: (regs[2] as u32).into(), |
| 1878 | }, |
| 1879 | FuncId::NotificationInfoGet32 => Self::NotificationInfoGet { is_32bit: true }, |
| 1880 | FuncId::NotificationInfoGet64 => Self::NotificationInfoGet { is_32bit: false }, |
Tomás González | e6fe75f | 2025-04-04 09:46:50 +0100 | [diff] [blame] | 1881 | FuncId::El3IntrHandle => Self::El3IntrHandle, |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1882 | _ => panic!("Invalid number of registers (8) for function {:#x?}", fid), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1883 | }; |
| 1884 | |
| 1885 | Ok(msg) |
| 1886 | } |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1887 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1888 | fn unpack_regs18(version: Version, regs: &[u64; 18]) -> Result<Self, Error> { |
| 1889 | assert!(version >= Version(1, 2)); |
Balint Dobszay | 5bf492f | 2024-07-29 17:21:32 +0200 | [diff] [blame] | 1890 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1891 | let fid = FuncId::try_from(regs[0] as u32)?; |
| 1892 | |
| 1893 | let msg = match fid { |
| 1894 | FuncId::Success64 => Self::Success { |
| 1895 | target_info: regs[1] as u32, |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 1896 | args: SuccessArgs::Args64_2(regs[2..18].try_into().unwrap()), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1897 | }, |
| 1898 | FuncId::MsgSendDirectReq64_2 => Self::MsgSendDirectReq2 { |
| 1899 | src_id: (regs[1] >> 16) as u16, |
| 1900 | dst_id: regs[1] as u16, |
Tomás González | ce3bc22 | 2025-03-25 14:30:42 +0000 | [diff] [blame] | 1901 | uuid: Uuid::from_u64_pair(regs[2].swap_bytes(), regs[3].swap_bytes()), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1902 | args: DirectMsg2Args(regs[4..18].try_into().unwrap()), |
| 1903 | }, |
| 1904 | FuncId::MsgSendDirectResp64_2 => Self::MsgSendDirectResp2 { |
| 1905 | src_id: (regs[1] >> 16) as u16, |
| 1906 | dst_id: regs[1] as u16, |
| 1907 | args: DirectMsg2Args(regs[4..18].try_into().unwrap()), |
| 1908 | }, |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 1909 | FuncId::ConsoleLog64 => { |
| 1910 | let char_cnt = regs[1] as u8; |
| 1911 | if char_cnt > ConsoleLogChars64::MAX_LENGTH { |
| 1912 | return Err(Error::InvalidCharacterCount(char_cnt)); |
| 1913 | } |
| 1914 | |
| 1915 | Self::ConsoleLog { |
| 1916 | chars: ConsoleLogChars::Chars64(ConsoleLogChars64 { |
| 1917 | char_cnt, |
| 1918 | char_lists: regs[2..18].try_into().unwrap(), |
| 1919 | }), |
| 1920 | } |
| 1921 | } |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 1922 | FuncId::PartitionInfoGetRegs => { |
| 1923 | // Bits[15:0]: Start index |
| 1924 | let start_index = (regs[3] & 0xffff) as u16; |
| 1925 | let info_tag = ((regs[3] >> 16) & 0xffff) as u16; |
| 1926 | Self::PartitionInfoGetRegs { |
| 1927 | uuid: Uuid::from_u64_pair(regs[1].swap_bytes(), regs[2].swap_bytes()), |
| 1928 | start_index, |
| 1929 | info_tag: if start_index == 0 && info_tag != 0 { |
| 1930 | return Err(Error::InvalidInformationTag(info_tag)); |
| 1931 | } else { |
| 1932 | info_tag |
| 1933 | }, |
| 1934 | } |
| 1935 | } |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1936 | _ => panic!("Invalid number of registers (18) for function {:#x?}", fid), |
| 1937 | }; |
| 1938 | |
| 1939 | Ok(msg) |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1940 | } |
| 1941 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 1942 | /// Create register contents for an interface. |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1943 | pub fn to_regs(&self, version: Version, regs: &mut [u64]) { |
Balint Dobszay | 82c71dd | 2025-04-15 10:16:44 +0200 | [diff] [blame] | 1944 | assert!(self.minimum_ffa_version() <= version); |
| 1945 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1946 | let reg_cnt = regs.len(); |
| 1947 | |
| 1948 | match reg_cnt { |
| 1949 | 8 => { |
| 1950 | assert!(version <= Version(1, 1)); |
Balint Dobszay | 91bea9b | 2025-04-09 13:16:06 +0200 | [diff] [blame] | 1951 | regs.fill(0); |
| 1952 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1953 | self.pack_regs8(version, (&mut regs[..8]).try_into().unwrap()); |
| 1954 | } |
| 1955 | 18 => { |
| 1956 | assert!(version >= Version(1, 2)); |
Balint Dobszay | 91bea9b | 2025-04-09 13:16:06 +0200 | [diff] [blame] | 1957 | regs.fill(0); |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1958 | |
| 1959 | match self { |
| 1960 | Interface::ConsoleLog { |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 1961 | chars: ConsoleLogChars::Chars64(_), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1962 | .. |
| 1963 | } |
| 1964 | | Interface::Success { |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 1965 | args: SuccessArgs::Args64_2(_), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1966 | .. |
| 1967 | } |
| 1968 | | Interface::MsgSendDirectReq2 { .. } |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 1969 | | Interface::MsgSendDirectResp2 { .. } |
| 1970 | | Interface::PartitionInfoGetRegs { .. } => { |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 1971 | self.pack_regs18(version, regs.try_into().unwrap()); |
| 1972 | } |
| 1973 | _ => { |
| 1974 | self.pack_regs8(version, (&mut regs[..8]).try_into().unwrap()); |
| 1975 | } |
| 1976 | } |
| 1977 | } |
| 1978 | _ => panic!("Invalid number of registers {}", reg_cnt), |
| 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | fn pack_regs8(&self, version: Version, a: &mut [u64; 8]) { |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1983 | if let Some(function_id) = self.function_id() { |
| 1984 | a[0] = function_id as u64; |
| 1985 | } |
| 1986 | |
| 1987 | match *self { |
| 1988 | Interface::Error { |
| 1989 | target_info, |
| 1990 | error_code, |
Balint Dobszay | b727aab | 2025-04-07 10:24:59 +0200 | [diff] [blame] | 1991 | error_arg, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1992 | } => { |
| 1993 | a[1] = u32::from(target_info).into(); |
| 1994 | a[2] = (error_code as u32).into(); |
Balint Dobszay | b727aab | 2025-04-07 10:24:59 +0200 | [diff] [blame] | 1995 | a[3] = error_arg.into(); |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 1996 | } |
| 1997 | Interface::Success { target_info, args } => { |
| 1998 | a[1] = target_info.into(); |
| 1999 | match args { |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 2000 | SuccessArgs::Args32(regs) => { |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2001 | a[2] = regs[0].into(); |
| 2002 | a[3] = regs[1].into(); |
| 2003 | a[4] = regs[2].into(); |
| 2004 | a[5] = regs[3].into(); |
| 2005 | a[6] = regs[4].into(); |
| 2006 | a[7] = regs[5].into(); |
| 2007 | } |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 2008 | SuccessArgs::Args64(regs) => { |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2009 | a[2] = regs[0]; |
| 2010 | a[3] = regs[1]; |
| 2011 | a[4] = regs[2]; |
| 2012 | a[5] = regs[3]; |
| 2013 | a[6] = regs[4]; |
| 2014 | a[7] = regs[5]; |
| 2015 | } |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 2016 | _ => panic!("{:#x?} requires 18 registers", args), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2017 | } |
| 2018 | } |
| 2019 | Interface::Interrupt { |
| 2020 | target_info, |
| 2021 | interrupt_id, |
| 2022 | } => { |
| 2023 | a[1] = u32::from(target_info).into(); |
| 2024 | a[2] = interrupt_id.into(); |
| 2025 | } |
| 2026 | Interface::Version { input_version } => { |
| 2027 | a[1] = u32::from(input_version).into(); |
| 2028 | } |
| 2029 | Interface::VersionOut { output_version } => { |
| 2030 | a[0] = u32::from(output_version).into(); |
| 2031 | } |
| 2032 | Interface::Features { |
| 2033 | feat_id, |
| 2034 | input_properties, |
| 2035 | } => { |
| 2036 | a[1] = u32::from(feat_id).into(); |
| 2037 | a[2] = input_properties.into(); |
| 2038 | } |
| 2039 | Interface::RxAcquire { vm_id } => { |
| 2040 | a[1] = vm_id.into(); |
| 2041 | } |
| 2042 | Interface::RxRelease { vm_id } => { |
| 2043 | a[1] = vm_id.into(); |
| 2044 | } |
| 2045 | Interface::RxTxMap { addr, page_cnt } => { |
| 2046 | match addr { |
| 2047 | RxTxAddr::Addr32 { rx, tx } => { |
| 2048 | a[1] = tx.into(); |
| 2049 | a[2] = rx.into(); |
| 2050 | } |
| 2051 | RxTxAddr::Addr64 { rx, tx } => { |
| 2052 | a[1] = tx; |
| 2053 | a[2] = rx; |
| 2054 | } |
| 2055 | } |
| 2056 | a[3] = page_cnt.into(); |
| 2057 | } |
| 2058 | Interface::RxTxUnmap { id } => { |
| 2059 | a[1] = id.into(); |
| 2060 | } |
| 2061 | Interface::PartitionInfoGet { uuid, flags } => { |
| 2062 | let bytes = uuid.into_bytes(); |
| 2063 | a[1] = u32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]).into(); |
| 2064 | a[2] = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]).into(); |
| 2065 | a[3] = u32::from_le_bytes([bytes[8], bytes[9], bytes[10], bytes[11]]).into(); |
| 2066 | a[4] = u32::from_le_bytes([bytes[12], bytes[13], bytes[14], bytes[15]]).into(); |
Imre Kis | e295adb | 2025-04-10 13:26:28 +0200 | [diff] [blame] | 2067 | a[5] = u32::from(flags).into(); |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2068 | } |
Tomás González | 092202a | 2025-03-05 11:56:45 +0000 | [diff] [blame] | 2069 | Interface::MsgWait { flags } => { |
| 2070 | if version >= Version(1, 2) { |
| 2071 | if let Some(flags) = flags { |
| 2072 | a[2] = u32::from(flags).into(); |
| 2073 | } |
| 2074 | } |
| 2075 | } |
| 2076 | Interface::IdGet | Interface::SpmIdGet | Interface::Yield => {} |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2077 | Interface::Run { target_info } => { |
| 2078 | a[1] = u32::from(target_info).into(); |
| 2079 | } |
| 2080 | Interface::NormalWorldResume => {} |
Tomás González | 17b9244 | 2025-03-10 16:45:04 +0000 | [diff] [blame] | 2081 | Interface::SecondaryEpRegister { entrypoint } => match entrypoint { |
| 2082 | SecondaryEpRegisterAddr::Addr32(addr) => a[1] = addr as u64, |
| 2083 | SecondaryEpRegisterAddr::Addr64(addr) => a[1] = addr, |
| 2084 | }, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2085 | Interface::MsgSend2 { |
| 2086 | sender_vm_id, |
| 2087 | flags, |
| 2088 | } => { |
| 2089 | a[1] = sender_vm_id.into(); |
| 2090 | a[2] = flags.into(); |
| 2091 | } |
| 2092 | Interface::MsgSendDirectReq { |
| 2093 | src_id, |
| 2094 | dst_id, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2095 | args, |
| 2096 | } => { |
Balint Dobszay | e9a3e76 | 2025-02-26 17:29:57 +0100 | [diff] [blame] | 2097 | a[1] = ((src_id as u64) << 16) | dst_id as u64; |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2098 | match args { |
| 2099 | DirectMsgArgs::Args32(args) => { |
| 2100 | a[3] = args[0].into(); |
| 2101 | a[4] = args[1].into(); |
| 2102 | a[5] = args[2].into(); |
| 2103 | a[6] = args[3].into(); |
| 2104 | a[7] = args[4].into(); |
| 2105 | } |
| 2106 | DirectMsgArgs::Args64(args) => { |
| 2107 | a[3] = args[0]; |
| 2108 | a[4] = args[1]; |
| 2109 | a[5] = args[2]; |
| 2110 | a[6] = args[3]; |
| 2111 | a[7] = args[4]; |
| 2112 | } |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2113 | DirectMsgArgs::VersionReq { version } => { |
| 2114 | a[2] = DirectMsgArgs::VERSION_REQ.into(); |
| 2115 | a[3] = u32::from(version).into(); |
| 2116 | } |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 2117 | DirectMsgArgs::PowerPsciReq32 { params } => { |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2118 | a[2] = DirectMsgArgs::POWER_PSCI_REQ.into(); |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 2119 | a[3] = params[0].into(); |
| 2120 | a[4] = params[1].into(); |
| 2121 | a[5] = params[2].into(); |
| 2122 | a[6] = params[3].into(); |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2123 | } |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 2124 | DirectMsgArgs::PowerPsciReq64 { params } => { |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2125 | a[2] = DirectMsgArgs::POWER_PSCI_REQ.into(); |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 2126 | a[3] = params[0]; |
| 2127 | a[4] = params[1]; |
| 2128 | a[5] = params[2]; |
| 2129 | a[6] = params[3]; |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2130 | } |
| 2131 | DirectMsgArgs::PowerWarmBootReq { boot_type } => { |
| 2132 | a[2] = DirectMsgArgs::POWER_WARM_BOOT_REQ.into(); |
| 2133 | a[3] = u32::from(boot_type).into(); |
| 2134 | } |
| 2135 | DirectMsgArgs::VmCreated { handle, vm_id } => { |
| 2136 | a[2] = DirectMsgArgs::VM_CREATED.into(); |
| 2137 | let handle_regs: [u32; 2] = handle.into(); |
| 2138 | a[3] = handle_regs[0].into(); |
| 2139 | a[4] = handle_regs[1].into(); |
| 2140 | a[5] = vm_id.into(); |
| 2141 | } |
| 2142 | DirectMsgArgs::VmDestructed { handle, vm_id } => { |
| 2143 | a[2] = DirectMsgArgs::VM_DESTRUCTED.into(); |
| 2144 | let handle_regs: [u32; 2] = handle.into(); |
| 2145 | a[3] = handle_regs[0].into(); |
| 2146 | a[4] = handle_regs[1].into(); |
| 2147 | a[5] = vm_id.into(); |
| 2148 | } |
| 2149 | _ => panic!("Malformed MsgSendDirectReq interface"), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2150 | } |
| 2151 | } |
| 2152 | Interface::MsgSendDirectResp { |
| 2153 | src_id, |
| 2154 | dst_id, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2155 | args, |
| 2156 | } => { |
Balint Dobszay | e9a3e76 | 2025-02-26 17:29:57 +0100 | [diff] [blame] | 2157 | a[1] = ((src_id as u64) << 16) | dst_id as u64; |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2158 | match args { |
| 2159 | DirectMsgArgs::Args32(args) => { |
| 2160 | a[3] = args[0].into(); |
| 2161 | a[4] = args[1].into(); |
| 2162 | a[5] = args[2].into(); |
| 2163 | a[6] = args[3].into(); |
| 2164 | a[7] = args[4].into(); |
| 2165 | } |
| 2166 | DirectMsgArgs::Args64(args) => { |
| 2167 | a[3] = args[0]; |
| 2168 | a[4] = args[1]; |
| 2169 | a[5] = args[2]; |
| 2170 | a[6] = args[3]; |
| 2171 | a[7] = args[4]; |
| 2172 | } |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2173 | DirectMsgArgs::VersionResp { version } => { |
| 2174 | a[2] = DirectMsgArgs::VERSION_RESP.into(); |
| 2175 | match version { |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 2176 | None => a[3] = (i32::from(FfaError::NotSupported) as u32).into(), |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2177 | Some(ver) => a[3] = u32::from(ver).into(), |
| 2178 | } |
| 2179 | } |
| 2180 | DirectMsgArgs::PowerPsciResp { psci_status } => { |
| 2181 | a[2] = DirectMsgArgs::POWER_PSCI_RESP.into(); |
Imre Kis | b2d3c88 | 2025-04-11 14:19:35 +0200 | [diff] [blame] | 2182 | a[3] = (psci_status as u32).into(); |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2183 | } |
| 2184 | DirectMsgArgs::VmCreatedAck { sp_status } => { |
| 2185 | a[2] = DirectMsgArgs::VM_CREATED_ACK.into(); |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 2186 | a[3] = (i32::from(sp_status) as u32).into(); |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2187 | } |
| 2188 | DirectMsgArgs::VmDestructedAck { sp_status } => { |
| 2189 | a[2] = DirectMsgArgs::VM_DESTRUCTED_ACK.into(); |
Tomás González | 67f92c7 | 2025-03-20 16:50:42 +0000 | [diff] [blame] | 2190 | a[3] = (i32::from(sp_status) as u32).into(); |
Tomás González | 4d5b0ba | 2025-03-03 17:15:55 +0000 | [diff] [blame] | 2191 | } |
| 2192 | _ => panic!("Malformed MsgSendDirectResp interface"), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2193 | } |
| 2194 | } |
| 2195 | Interface::MemDonate { |
| 2196 | total_len, |
| 2197 | frag_len, |
| 2198 | buf, |
| 2199 | } => { |
| 2200 | a[1] = total_len.into(); |
| 2201 | a[2] = frag_len.into(); |
| 2202 | (a[3], a[4]) = match buf { |
| 2203 | Some(MemOpBuf::Buf32 { addr, page_cnt }) => (addr.into(), page_cnt.into()), |
| 2204 | Some(MemOpBuf::Buf64 { addr, page_cnt }) => (addr, page_cnt.into()), |
| 2205 | None => (0, 0), |
| 2206 | }; |
| 2207 | } |
| 2208 | Interface::MemLend { |
| 2209 | total_len, |
| 2210 | frag_len, |
| 2211 | buf, |
| 2212 | } => { |
| 2213 | a[1] = total_len.into(); |
| 2214 | a[2] = frag_len.into(); |
| 2215 | (a[3], a[4]) = match buf { |
| 2216 | Some(MemOpBuf::Buf32 { addr, page_cnt }) => (addr.into(), page_cnt.into()), |
| 2217 | Some(MemOpBuf::Buf64 { addr, page_cnt }) => (addr, page_cnt.into()), |
| 2218 | None => (0, 0), |
| 2219 | }; |
| 2220 | } |
| 2221 | Interface::MemShare { |
| 2222 | total_len, |
| 2223 | frag_len, |
| 2224 | buf, |
| 2225 | } => { |
| 2226 | a[1] = total_len.into(); |
| 2227 | a[2] = frag_len.into(); |
| 2228 | (a[3], a[4]) = match buf { |
| 2229 | Some(MemOpBuf::Buf32 { addr, page_cnt }) => (addr.into(), page_cnt.into()), |
| 2230 | Some(MemOpBuf::Buf64 { addr, page_cnt }) => (addr, page_cnt.into()), |
| 2231 | None => (0, 0), |
| 2232 | }; |
| 2233 | } |
| 2234 | Interface::MemRetrieveReq { |
| 2235 | total_len, |
| 2236 | frag_len, |
| 2237 | buf, |
| 2238 | } => { |
| 2239 | a[1] = total_len.into(); |
| 2240 | a[2] = frag_len.into(); |
| 2241 | (a[3], a[4]) = match buf { |
| 2242 | Some(MemOpBuf::Buf32 { addr, page_cnt }) => (addr.into(), page_cnt.into()), |
| 2243 | Some(MemOpBuf::Buf64 { addr, page_cnt }) => (addr, page_cnt.into()), |
| 2244 | None => (0, 0), |
| 2245 | }; |
| 2246 | } |
| 2247 | Interface::MemRetrieveResp { |
| 2248 | total_len, |
| 2249 | frag_len, |
| 2250 | } => { |
| 2251 | a[1] = total_len.into(); |
| 2252 | a[2] = frag_len.into(); |
| 2253 | } |
| 2254 | Interface::MemRelinquish => {} |
| 2255 | Interface::MemReclaim { handle, flags } => { |
| 2256 | let handle_regs: [u32; 2] = handle.into(); |
| 2257 | a[1] = handle_regs[0].into(); |
| 2258 | a[2] = handle_regs[1].into(); |
| 2259 | a[3] = flags.into(); |
| 2260 | } |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 2261 | Interface::MemPermGet { addr, page_cnt } => { |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2262 | a[1] = match addr { |
| 2263 | MemAddr::Addr32(addr) => addr.into(), |
| 2264 | MemAddr::Addr64(addr) => addr, |
| 2265 | }; |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 2266 | a[2] = if version >= Version(1, 3) { |
| 2267 | page_cnt.unwrap().into() |
| 2268 | } else { |
| 2269 | assert!(page_cnt.is_none()); |
| 2270 | 0 |
| 2271 | } |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2272 | } |
| 2273 | Interface::MemPermSet { |
| 2274 | addr, |
| 2275 | page_cnt, |
| 2276 | mem_perm, |
| 2277 | } => { |
| 2278 | a[1] = match addr { |
| 2279 | MemAddr::Addr32(addr) => addr.into(), |
| 2280 | MemAddr::Addr64(addr) => addr, |
| 2281 | }; |
| 2282 | a[2] = page_cnt.into(); |
Imre Kis | dcb7df2 | 2025-06-06 15:24:40 +0200 | [diff] [blame] | 2283 | a[3] = u32::from(mem_perm).into(); |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2284 | } |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 2285 | Interface::ConsoleLog { chars } => match chars { |
| 2286 | ConsoleLogChars::Chars32(ConsoleLogChars32 { |
| 2287 | char_cnt, |
| 2288 | char_lists, |
| 2289 | }) => { |
| 2290 | a[1] = char_cnt.into(); |
| 2291 | a[2] = char_lists[0].into(); |
| 2292 | a[3] = char_lists[1].into(); |
| 2293 | a[4] = char_lists[2].into(); |
| 2294 | a[5] = char_lists[3].into(); |
| 2295 | a[6] = char_lists[4].into(); |
| 2296 | a[7] = char_lists[5].into(); |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2297 | } |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 2298 | _ => panic!("{:#x?} requires 18 registers", chars), |
| 2299 | }, |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 2300 | Interface::NotificationBitmapCreate { vm_id, vcpu_cnt } => { |
| 2301 | a[1] = vm_id.into(); |
| 2302 | a[2] = vcpu_cnt.into(); |
| 2303 | } |
| 2304 | Interface::NotificationBitmapDestroy { vm_id } => { |
| 2305 | a[1] = vm_id.into(); |
| 2306 | } |
| 2307 | Interface::NotificationBind { |
| 2308 | sender_id, |
| 2309 | receiver_id, |
| 2310 | flags, |
| 2311 | bitmap, |
| 2312 | } => { |
| 2313 | a[1] = (u64::from(sender_id) << 16) | u64::from(receiver_id); |
| 2314 | a[2] = u32::from(flags).into(); |
| 2315 | a[3] = bitmap & 0xffff_ffff; |
| 2316 | a[4] = bitmap >> 32; |
| 2317 | } |
Imre Kis | 3571f2c | 2025-05-26 19:29:23 +0200 | [diff] [blame] | 2318 | Interface::NotificationUnbind { |
Tomás González | 7ffb613 | 2025-04-03 12:28:58 +0100 | [diff] [blame] | 2319 | sender_id, |
| 2320 | receiver_id, |
| 2321 | bitmap, |
| 2322 | } => { |
| 2323 | a[1] = (u64::from(sender_id) << 16) | u64::from(receiver_id); |
| 2324 | a[3] = bitmap & 0xffff_ffff; |
| 2325 | a[4] = bitmap >> 32; |
| 2326 | } |
| 2327 | Interface::NotificationSet { |
| 2328 | sender_id, |
| 2329 | receiver_id, |
| 2330 | flags, |
| 2331 | bitmap, |
| 2332 | } => { |
| 2333 | a[1] = (u64::from(sender_id) << 16) | u64::from(receiver_id); |
| 2334 | a[2] = u32::from(flags).into(); |
| 2335 | a[3] = bitmap & 0xffff_ffff; |
| 2336 | a[4] = bitmap >> 32; |
| 2337 | } |
| 2338 | Interface::NotificationGet { |
| 2339 | vcpu_id, |
| 2340 | endpoint_id, |
| 2341 | flags, |
| 2342 | } => { |
| 2343 | a[1] = (u64::from(vcpu_id) << 16) | u64::from(endpoint_id); |
| 2344 | a[2] = u32::from(flags).into(); |
| 2345 | } |
| 2346 | Interface::NotificationInfoGet { .. } => {} |
Tomás González | e6fe75f | 2025-04-04 09:46:50 +0100 | [diff] [blame] | 2347 | Interface::El3IntrHandle => {} |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 2348 | _ => panic!("{:#x?} requires 18 registers", self), |
| 2349 | } |
| 2350 | } |
| 2351 | |
| 2352 | fn pack_regs18(&self, version: Version, a: &mut [u64; 18]) { |
| 2353 | assert!(version >= Version(1, 2)); |
| 2354 | |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 2355 | if let Some(function_id) = self.function_id() { |
| 2356 | a[0] = function_id as u64; |
| 2357 | } |
| 2358 | |
| 2359 | match *self { |
| 2360 | Interface::Success { target_info, args } => { |
| 2361 | a[1] = target_info.into(); |
| 2362 | match args { |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 2363 | SuccessArgs::Args64_2(regs) => a[2..18].copy_from_slice(®s[..16]), |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 2364 | _ => panic!("{:#x?} requires 8 registers", args), |
| 2365 | } |
| 2366 | } |
| 2367 | Interface::MsgSendDirectReq2 { |
| 2368 | src_id, |
| 2369 | dst_id, |
| 2370 | uuid, |
| 2371 | args, |
| 2372 | } => { |
| 2373 | a[1] = ((src_id as u64) << 16) | dst_id as u64; |
Tomás González | ce3bc22 | 2025-03-25 14:30:42 +0000 | [diff] [blame] | 2374 | let (uuid_msb, uuid_lsb) = uuid.as_u64_pair(); |
| 2375 | (a[2], a[3]) = (uuid_msb.swap_bytes(), uuid_lsb.swap_bytes()); |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 2376 | a[4..18].copy_from_slice(&args.0[..14]); |
| 2377 | } |
| 2378 | Interface::MsgSendDirectResp2 { |
| 2379 | src_id, |
| 2380 | dst_id, |
| 2381 | args, |
| 2382 | } => { |
| 2383 | a[1] = ((src_id as u64) << 16) | dst_id as u64; |
| 2384 | a[2] = 0; |
| 2385 | a[3] = 0; |
| 2386 | a[4..18].copy_from_slice(&args.0[..14]); |
| 2387 | } |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 2388 | Interface::ConsoleLog { chars: char_lists } => match char_lists { |
| 2389 | ConsoleLogChars::Chars64(ConsoleLogChars64 { |
| 2390 | char_cnt, |
| 2391 | char_lists, |
| 2392 | }) => { |
| 2393 | a[1] = char_cnt.into(); |
| 2394 | a[2..18].copy_from_slice(&char_lists[..16]) |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 2395 | } |
Imre Kis | 189f18c | 2025-05-26 19:33:05 +0200 | [diff] [blame] | 2396 | _ => panic!("{:#x?} requires 8 registers", char_lists), |
| 2397 | }, |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 2398 | Interface::PartitionInfoGetRegs { |
| 2399 | uuid, |
| 2400 | start_index, |
| 2401 | info_tag, |
| 2402 | } => { |
| 2403 | if start_index == 0 && info_tag != 0 { |
| 2404 | panic!("Information Tag MBZ if start index is 0: {:#x?}", self); |
| 2405 | } |
| 2406 | let (uuid_msb, uuid_lsb) = uuid.as_u64_pair(); |
| 2407 | (a[1], a[2]) = (uuid_msb.swap_bytes(), uuid_lsb.swap_bytes()); |
| 2408 | a[3] = (u64::from(info_tag) << 16) | u64::from(start_index); |
| 2409 | } |
Balint Dobszay | de0dc80 | 2025-02-28 14:16:52 +0100 | [diff] [blame] | 2410 | _ => panic!("{:#x?} requires 8 registers", self), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2411 | } |
| 2412 | } |
| 2413 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 2414 | /// Helper function to create an `FFA_SUCCESS` interface without any arguments. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2415 | pub fn success32_noargs() -> Self { |
| 2416 | Self::Success { |
| 2417 | target_info: 0, |
Imre Kis | 54773b6 | 2025-04-10 13:47:39 +0200 | [diff] [blame] | 2418 | args: SuccessArgs::Args32([0; 6]), |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2419 | } |
| 2420 | } |
| 2421 | |
Balint Dobszay | a584685 | 2025-02-26 15:38:53 +0100 | [diff] [blame] | 2422 | /// Helper function to create an `FFA_ERROR` interface with an error code. |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2423 | pub fn error(error_code: FfaError) -> Self { |
| 2424 | Self::Error { |
| 2425 | target_info: TargetInfo { |
| 2426 | endpoint_id: 0, |
| 2427 | vcpu_id: 0, |
| 2428 | }, |
| 2429 | error_code, |
Balint Dobszay | b727aab | 2025-04-07 10:24:59 +0200 | [diff] [blame] | 2430 | error_arg: 0, |
Balint Dobszay | 3aad957 | 2025-01-17 16:54:11 +0100 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | } |
| 2434 | |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 2435 | #[cfg(test)] |
| 2436 | mod tests { |
| 2437 | use super::*; |
| 2438 | |
| 2439 | #[test] |
Balint Dobszay | 5ded592 | 2025-06-13 12:06:53 +0200 | [diff] [blame^] | 2440 | fn version_reg_count() { |
| 2441 | assert!(!Version(1, 1).needs_18_regs()); |
| 2442 | assert!(Version(1, 2).needs_18_regs()) |
| 2443 | } |
| 2444 | |
| 2445 | #[test] |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 2446 | fn part_info_get_regs() { |
| 2447 | let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8").unwrap(); |
| 2448 | let uuid_bytes = uuid.as_bytes(); |
| 2449 | let test_info_tag = 0b1101_1101; |
| 2450 | let test_start_index = 0b1101; |
| 2451 | let start_index_and_tag = (test_info_tag << 16) | test_start_index; |
| 2452 | let version = Version(1, 2); |
| 2453 | |
| 2454 | // From spec: |
| 2455 | // Bytes[0...7] of UUID with byte 0 in the low-order bits. |
Balint Dobszay | b2e9bed | 2025-04-15 12:57:36 +0200 | [diff] [blame] | 2456 | let reg_x1 = ((uuid_bytes[7] as u64) << 56) |
| 2457 | | ((uuid_bytes[6] as u64) << 48) |
| 2458 | | ((uuid_bytes[5] as u64) << 40) |
| 2459 | | ((uuid_bytes[4] as u64) << 32) |
| 2460 | | ((uuid_bytes[3] as u64) << 24) |
| 2461 | | ((uuid_bytes[2] as u64) << 16) |
| 2462 | | ((uuid_bytes[1] as u64) << 8) |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 2463 | | (uuid_bytes[0] as u64); |
| 2464 | |
| 2465 | // From spec: |
| 2466 | // Bytes[8...15] of UUID with byte 8 in the low-order bits. |
Balint Dobszay | b2e9bed | 2025-04-15 12:57:36 +0200 | [diff] [blame] | 2467 | let reg_x2 = ((uuid_bytes[15] as u64) << 56) |
| 2468 | | ((uuid_bytes[14] as u64) << 48) |
| 2469 | | ((uuid_bytes[13] as u64) << 40) |
| 2470 | | ((uuid_bytes[12] as u64) << 32) |
| 2471 | | ((uuid_bytes[11] as u64) << 24) |
| 2472 | | ((uuid_bytes[10] as u64) << 16) |
| 2473 | | ((uuid_bytes[9] as u64) << 8) |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 2474 | | (uuid_bytes[8] as u64); |
| 2475 | |
| 2476 | // First, test for wrong tag: |
| 2477 | { |
| 2478 | let mut regs = [0u64; 18]; |
| 2479 | regs[0] = FuncId::PartitionInfoGetRegs as u64; |
| 2480 | regs[1] = reg_x1; |
| 2481 | regs[2] = reg_x2; |
| 2482 | regs[3] = test_info_tag << 16; |
| 2483 | |
| 2484 | assert!(Interface::from_regs(version, ®s).is_err_and( |
| 2485 | |e| e == Error::InvalidInformationTag(test_info_tag.try_into().unwrap()) |
| 2486 | )); |
| 2487 | } |
| 2488 | |
| 2489 | // Test for regs -> Interface -> regs |
| 2490 | { |
| 2491 | let mut orig_regs = [0u64; 18]; |
| 2492 | orig_regs[0] = FuncId::PartitionInfoGetRegs as u64; |
| 2493 | orig_regs[1] = reg_x1; |
| 2494 | orig_regs[2] = reg_x2; |
| 2495 | orig_regs[3] = start_index_and_tag; |
| 2496 | |
Balint Dobszay | b2e9bed | 2025-04-15 12:57:36 +0200 | [diff] [blame] | 2497 | let mut test_regs = orig_regs; |
| 2498 | let interface = Interface::from_regs(version, &test_regs).unwrap(); |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 2499 | match &interface { |
| 2500 | Interface::PartitionInfoGetRegs { |
| 2501 | info_tag, |
| 2502 | start_index, |
| 2503 | uuid: int_uuid, |
| 2504 | } => { |
| 2505 | assert_eq!(u64::from(*info_tag), test_info_tag); |
| 2506 | assert_eq!(u64::from(*start_index), test_start_index); |
| 2507 | assert_eq!(*int_uuid, uuid); |
| 2508 | } |
| 2509 | _ => panic!("Expecting Interface::PartitionInfoGetRegs!"), |
| 2510 | } |
| 2511 | test_regs.fill(0); |
| 2512 | interface.to_regs(version, &mut test_regs); |
| 2513 | assert_eq!(orig_regs, test_regs); |
| 2514 | } |
| 2515 | |
| 2516 | // Test for Interface -> regs -> Interface |
| 2517 | { |
| 2518 | let interface = Interface::PartitionInfoGetRegs { |
| 2519 | info_tag: test_info_tag.try_into().unwrap(), |
| 2520 | start_index: test_start_index.try_into().unwrap(), |
| 2521 | uuid, |
| 2522 | }; |
| 2523 | |
| 2524 | let mut regs: [u64; 18] = [0; 18]; |
| 2525 | interface.to_regs(version, &mut regs); |
| 2526 | |
| 2527 | assert_eq!(Some(FuncId::PartitionInfoGetRegs), interface.function_id()); |
| 2528 | assert_eq!(regs[0], interface.function_id().unwrap() as u64); |
| 2529 | assert_eq!(regs[1], reg_x1); |
| 2530 | assert_eq!(regs[2], reg_x2); |
| 2531 | assert_eq!(regs[3], (test_info_tag << 16) | test_start_index); |
| 2532 | |
| 2533 | assert_eq!(Interface::from_regs(version, ®s).unwrap(), interface); |
| 2534 | } |
| 2535 | } |
Tomás González | ce3bc22 | 2025-03-25 14:30:42 +0000 | [diff] [blame] | 2536 | |
| 2537 | #[test] |
| 2538 | fn msg_send_direct_req2() { |
| 2539 | let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8").unwrap(); |
| 2540 | let uuid_bytes = uuid.as_bytes(); |
| 2541 | |
| 2542 | // From spec: |
| 2543 | // Bytes[0...7] of UUID with byte 0 in the low-order bits. |
Balint Dobszay | b2e9bed | 2025-04-15 12:57:36 +0200 | [diff] [blame] | 2544 | let reg_x2 = ((uuid_bytes[7] as u64) << 56) |
| 2545 | | ((uuid_bytes[6] as u64) << 48) |
| 2546 | | ((uuid_bytes[5] as u64) << 40) |
| 2547 | | ((uuid_bytes[4] as u64) << 32) |
| 2548 | | ((uuid_bytes[3] as u64) << 24) |
| 2549 | | ((uuid_bytes[2] as u64) << 16) |
| 2550 | | ((uuid_bytes[1] as u64) << 8) |
Tomás González | ce3bc22 | 2025-03-25 14:30:42 +0000 | [diff] [blame] | 2551 | | (uuid_bytes[0] as u64); |
| 2552 | |
| 2553 | // From spec: |
| 2554 | // Bytes[8...15] of UUID with byte 8 in the low-order bits. |
Balint Dobszay | b2e9bed | 2025-04-15 12:57:36 +0200 | [diff] [blame] | 2555 | let reg_x3 = ((uuid_bytes[15] as u64) << 56) |
| 2556 | | ((uuid_bytes[14] as u64) << 48) |
| 2557 | | ((uuid_bytes[13] as u64) << 40) |
| 2558 | | ((uuid_bytes[12] as u64) << 32) |
| 2559 | | ((uuid_bytes[11] as u64) << 24) |
| 2560 | | ((uuid_bytes[10] as u64) << 16) |
| 2561 | | ((uuid_bytes[9] as u64) << 8) |
Tomás González | ce3bc22 | 2025-03-25 14:30:42 +0000 | [diff] [blame] | 2562 | | (uuid_bytes[8] as u64); |
| 2563 | |
| 2564 | let test_sender = 0b1101_1101; |
| 2565 | let test_receiver = 0b1101; |
| 2566 | let test_sender_receiver = (test_sender << 16) | test_receiver; |
| 2567 | let version = Version(1, 2); |
| 2568 | |
| 2569 | // Test for regs -> Interface -> regs |
| 2570 | { |
| 2571 | let mut orig_regs = [0u64; 18]; |
| 2572 | orig_regs[0] = FuncId::MsgSendDirectReq64_2 as u64; |
| 2573 | orig_regs[1] = test_sender_receiver; |
| 2574 | orig_regs[2] = reg_x2; |
| 2575 | orig_regs[3] = reg_x3; |
| 2576 | |
Balint Dobszay | b2e9bed | 2025-04-15 12:57:36 +0200 | [diff] [blame] | 2577 | let mut test_regs = orig_regs; |
| 2578 | let interface = Interface::from_regs(version, &test_regs).unwrap(); |
Tomás González | ce3bc22 | 2025-03-25 14:30:42 +0000 | [diff] [blame] | 2579 | match &interface { |
| 2580 | Interface::MsgSendDirectReq2 { |
| 2581 | dst_id, |
| 2582 | src_id, |
| 2583 | args: _, |
| 2584 | uuid: int_uuid, |
| 2585 | } => { |
| 2586 | assert_eq!(u64::from(*src_id), test_sender); |
| 2587 | assert_eq!(u64::from(*dst_id), test_receiver); |
| 2588 | assert_eq!(*int_uuid, uuid); |
| 2589 | } |
| 2590 | _ => panic!("Expecting Interface::MsgSendDirectReq2!"), |
| 2591 | } |
| 2592 | test_regs.fill(0); |
| 2593 | interface.to_regs(version, &mut test_regs); |
| 2594 | assert_eq!(orig_regs, test_regs); |
| 2595 | } |
| 2596 | |
| 2597 | // Test for Interface -> regs -> Interface |
| 2598 | { |
| 2599 | let rest_of_regs: [u64; 14] = [0; 14]; |
| 2600 | |
| 2601 | let interface = Interface::MsgSendDirectReq2 { |
| 2602 | src_id: test_sender.try_into().unwrap(), |
| 2603 | dst_id: test_receiver.try_into().unwrap(), |
| 2604 | uuid, |
| 2605 | args: DirectMsg2Args(rest_of_regs), |
| 2606 | }; |
| 2607 | |
| 2608 | let mut regs: [u64; 18] = [0; 18]; |
| 2609 | interface.to_regs(version, &mut regs); |
| 2610 | |
| 2611 | assert_eq!(Some(FuncId::MsgSendDirectReq64_2), interface.function_id()); |
| 2612 | assert_eq!(regs[0], interface.function_id().unwrap() as u64); |
| 2613 | assert_eq!(regs[1], test_sender_receiver); |
| 2614 | assert_eq!(regs[2], reg_x2); |
| 2615 | assert_eq!(regs[3], reg_x3); |
| 2616 | assert_eq!(regs[4], 0); |
| 2617 | |
| 2618 | assert_eq!(Interface::from_regs(version, ®s).unwrap(), interface); |
| 2619 | } |
| 2620 | } |
Tomás González | 6ccba0a | 2025-04-09 13:31:29 +0100 | [diff] [blame] | 2621 | |
| 2622 | #[test] |
| 2623 | fn is_32bit() { |
| 2624 | let interface_64 = Interface::MsgSendDirectReq { |
| 2625 | src_id: 0, |
| 2626 | dst_id: 1, |
| 2627 | args: DirectMsgArgs::Args64([0, 0, 0, 0, 0]), |
| 2628 | }; |
| 2629 | assert!(!interface_64.is_32bit()); |
| 2630 | |
| 2631 | let interface_32 = Interface::MsgSendDirectReq { |
| 2632 | src_id: 0, |
| 2633 | dst_id: 1, |
| 2634 | args: DirectMsgArgs::Args32([0, 0, 0, 0, 0]), |
| 2635 | }; |
| 2636 | assert!(interface_32.is_32bit()); |
| 2637 | } |
Imre Kis | 787c500 | 2025-04-10 14:25:51 +0200 | [diff] [blame] | 2638 | |
| 2639 | #[test] |
| 2640 | fn success_args_notification_info_get32() { |
| 2641 | let mut notifications = SuccessArgsNotificationInfoGet32::default(); |
| 2642 | |
| 2643 | // 16.7.1.1 Example usage |
| 2644 | notifications.add_list(0x0000, &[0, 2, 3]).unwrap(); |
| 2645 | notifications.add_list(0x0000, &[4, 6]).unwrap(); |
| 2646 | notifications.add_list(0x0002, &[]).unwrap(); |
| 2647 | notifications.add_list(0x0003, &[1]).unwrap(); |
| 2648 | |
| 2649 | let args: SuccessArgs = notifications.into(); |
| 2650 | assert_eq!( |
| 2651 | SuccessArgs::Args32([ |
| 2652 | 0x0004_b200, |
| 2653 | 0x0000_0000, |
| 2654 | 0x0003_0002, |
| 2655 | 0x0004_0000, |
| 2656 | 0x0002_0006, |
| 2657 | 0x0001_0003 |
| 2658 | ]), |
| 2659 | args |
| 2660 | ); |
| 2661 | |
| 2662 | let notifications = SuccessArgsNotificationInfoGet32::try_from(args).unwrap(); |
| 2663 | let mut iter = notifications.iter(); |
| 2664 | assert_eq!(Some((0x0000, &[0, 2, 3][..])), iter.next()); |
| 2665 | assert_eq!(Some((0x0000, &[4, 6][..])), iter.next()); |
| 2666 | assert_eq!(Some((0x0002, &[][..])), iter.next()); |
| 2667 | assert_eq!(Some((0x0003, &[1][..])), iter.next()); |
| 2668 | } |
| 2669 | |
| 2670 | #[test] |
| 2671 | fn success_args_notification_info_get64() { |
| 2672 | let mut notifications = SuccessArgsNotificationInfoGet64::default(); |
| 2673 | |
| 2674 | // 16.7.1.1 Example usage |
| 2675 | notifications.add_list(0x0000, &[0, 2, 3]).unwrap(); |
| 2676 | notifications.add_list(0x0000, &[4, 6]).unwrap(); |
| 2677 | notifications.add_list(0x0002, &[]).unwrap(); |
| 2678 | notifications.add_list(0x0003, &[1]).unwrap(); |
| 2679 | |
| 2680 | let args: SuccessArgs = notifications.into(); |
| 2681 | assert_eq!( |
| 2682 | SuccessArgs::Args64([ |
| 2683 | 0x0004_b200, |
| 2684 | 0x0003_0002_0000_0000, |
| 2685 | 0x0002_0006_0004_0000, |
| 2686 | 0x0000_0000_0001_0003, |
| 2687 | 0x0000_0000_0000_0000, |
| 2688 | 0x0000_0000_0000_0000, |
| 2689 | ]), |
| 2690 | args |
| 2691 | ); |
| 2692 | |
| 2693 | let notifications = SuccessArgsNotificationInfoGet64::try_from(args).unwrap(); |
| 2694 | let mut iter = notifications.iter(); |
| 2695 | assert_eq!(Some((0x0000, &[0, 2, 3][..])), iter.next()); |
| 2696 | assert_eq!(Some((0x0000, &[4, 6][..])), iter.next()); |
| 2697 | assert_eq!(Some((0x0002, &[][..])), iter.next()); |
| 2698 | assert_eq!(Some((0x0003, &[1][..])), iter.next()); |
| 2699 | } |
Tomás González | 0a058bc | 2025-03-11 11:20:55 +0000 | [diff] [blame] | 2700 | } |