Add Unknown variant to Feature type
Add a new variant to the Feature type which represents an unrecognised
feature or function ID. This is required to ensure that an FFA_FEATURES
call can always be successfully converted into an Interface, even if the
queried feature or function ID is currently not recognised by this
library. This variant should only be used to parse incoming FFA_FEATURES
calls. Creating an FFA_FEATURES interface with the Unknown variant is
not supported and will panic.
Signed-off-by: Balint Dobszay <balint.dobszay@arm.com>
Change-Id: Iec8ecd80c84c6d6c55fa7a9ec3f28340f69dc0b6
diff --git a/src/lib.rs b/src/lib.rs
index eb04ee5..50b641f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -217,19 +217,19 @@
pub enum Feature {
FuncId(FuncId),
FeatureId(FeatureId),
+ Unknown(u32),
}
-impl TryFrom<u32> for Feature {
- type Error = Error;
-
- fn try_from(value: u32) -> Result<Self, Self::Error> {
- let res = if (value >> 31) & 1 == 1 {
- Self::FuncId(value.try_into()?)
+impl From<u32> for Feature {
+ fn from(value: u32) -> Self {
+ // Bit[31] is set for all valid FF-A function IDs so we don't have to check it separately
+ if let Ok(func_id) = value.try_into() {
+ Self::FuncId(func_id)
+ } else if let Ok(feat_id) = (value as u8).try_into() {
+ Self::FeatureId(feat_id)
} else {
- Self::FeatureId((value as u8).try_into()?)
- };
-
- Ok(res)
+ Self::Unknown(value)
+ }
}
}
@@ -238,6 +238,7 @@
match value {
Feature::FuncId(func_id) => (1 << 31) | func_id as u32,
Feature::FeatureId(feature_id) => feature_id as u32,
+ Feature::Unknown(id) => panic!("Unknown feature or function ID {:#x?}", id),
}
}
}
@@ -546,7 +547,7 @@
input_version: (regs[1] as u32).into(),
},
FuncId::Features => Self::Features {
- feat_id: (regs[1] as u32).try_into()?,
+ feat_id: (regs[1] as u32).into(),
input_properties: regs[2] as u32,
},
FuncId::RxAcquire => Self::RxAcquire {