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 use super::{
6     error::Error, SocIdType, Version, SMCCC_ARCH_FEATURES, SMCCC_ARCH_SOC_ID,
7     SMCCC_ARCH_WORKAROUND_1, SMCCC_ARCH_WORKAROUND_2, SMCCC_ARCH_WORKAROUND_3, SMCCC_VERSION,
8 };
9 use crate::{
10     error::{positive_or_error_32, success_or_error_32},
11     Call,
12 };
13 
14 /// Returns the implemented version of the SMC Calling Convention.
version<C: Call>() -> Result<Version, Error>15 pub fn version<C: Call>() -> Result<Version, Error> {
16     (C::call32(SMCCC_VERSION, [0; 7])[0] as i32).try_into()
17 }
18 
19 /// Returns whether the given Arm Architecture Service function is implemented, and any feature
20 /// flags specific to the function.
features<C: Call>(arch_func_id: u32) -> Result<u32, Error>21 pub fn features<C: Call>(arch_func_id: u32) -> Result<u32, Error> {
22     positive_or_error_32(C::call32(SMCCC_ARCH_FEATURES, [arch_func_id, 0, 0, 0, 0, 0, 0])[0])
23 }
24 
25 /// Returns the SiP defined SoC identification details.
soc_id<C: Call>(soc_id_type: SocIdType) -> Result<u32, Error>26 pub fn soc_id<C: Call>(soc_id_type: SocIdType) -> Result<u32, Error> {
27     positive_or_error_32(C::call32(SMCCC_ARCH_SOC_ID, [soc_id_type.into(), 0, 0, 0, 0, 0, 0])[0])
28 }
29 
30 /// Executes a firmware workaround to mitigate CVE-2017-5715.
arch_workaround_1<C: Call>() -> Result<(), Error>31 pub fn arch_workaround_1<C: Call>() -> Result<(), Error> {
32     success_or_error_32(C::call32(SMCCC_ARCH_WORKAROUND_1, [0; 7])[0])
33 }
34 
35 /// Enables or disables the mitigation for CVE-2018-3639.
arch_workaround_2<C: Call>(enable: bool) -> Result<(), Error>36 pub fn arch_workaround_2<C: Call>(enable: bool) -> Result<(), Error> {
37     success_or_error_32(C::call32(SMCCC_ARCH_WORKAROUND_2, [enable.into(), 0, 0, 0, 0, 0, 0])[0])
38 }
39 
40 /// Executes a firmware workaround to mitigate CVE-2017-5715 and CVE-2022-23960.
arch_workaround_3<C: Call>() -> Result<(), Error>41 pub fn arch_workaround_3<C: Call>() -> Result<(), Error> {
42     success_or_error_32(C::call32(SMCCC_ARCH_WORKAROUND_3, [0; 7])[0])
43 }
44