• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 the authors.
2 // This project is dual-licensed under Apache 2.0 and MIT terms.
3 // See LICENSE-APACHE and LICENSE-MIT for details.
4 
5 //! Error codes for standard Arm Architecture SMCCC calls.
6 
7 pub use crate::smccc::error::SUCCESS;
8 use core::fmt::{self, Display, Formatter};
9 
10 pub const NOT_SUPPORTED: i32 = -1;
11 pub const NOT_REQUIRED: i32 = -2;
12 pub const INVALID_PARAMETER: i32 = -3;
13 
14 /// Errors for standard Arm Architecture calls.
15 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
16 pub enum Error {
17     /// The call is not supported by the implementation.
18     NotSupported,
19     /// The call is deemed not required by the implementation.
20     NotRequired,
21     /// One of the call parameters has a non-supported value.
22     InvalidParameter,
23     /// There was an unexpected return value.
24     Unknown(i32),
25 }
26 
27 impl From<Error> for i32 {
from(error: Error) -> i3228     fn from(error: Error) -> i32 {
29         match error {
30             Error::NotSupported => NOT_SUPPORTED,
31             Error::NotRequired => NOT_REQUIRED,
32             Error::InvalidParameter => INVALID_PARAMETER,
33             Error::Unknown(value) => value,
34         }
35     }
36 }
37 
38 impl From<i32> for Error {
from(value: i32) -> Self39     fn from(value: i32) -> Self {
40         match value {
41             NOT_SUPPORTED => Error::NotSupported,
42             NOT_REQUIRED => Error::NotRequired,
43             INVALID_PARAMETER => Error::InvalidParameter,
44             _ => Error::Unknown(value),
45         }
46     }
47 }
48 
49 impl Display for Error {
fmt(&self, f: &mut Formatter) -> fmt::Result50     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
51         match self {
52             Self::NotSupported => write!(f, "SMCCC call not supported"),
53             Self::NotRequired => write!(f, "SMCCC call not required"),
54             Self::InvalidParameter => write!(f, "SMCCC call received non-supported value"),
55             Self::Unknown(e) => write!(f, "Unknown SMCCC return value {} ({0:#x})", e),
56         }
57     }
58 }
59