aarch64defs/
smccc.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Definitions for the SMC Calling Convention (SMCCC), including PSCI.
5
6use bitfield_struct::bitfield;
7use open_enum::open_enum;
8
9open_enum! {
10    pub enum Service: u8 {
11        SMCCC = 0,
12        PSCI = 4,
13        VENDOR_HYP = 6,
14    }
15}
16
17impl Service {
18    const fn from_bits(bits: u8) -> Self {
19        Self(bits)
20    }
21
22    const fn into_bits(self) -> u8 {
23        self.0
24    }
25}
26
27#[bitfield(u32)]
28#[derive(PartialEq, Eq, Ord, PartialOrd, Hash)]
29pub struct FastCall {
30    pub number: u16,
31    pub hint: bool,
32    #[bits(7)]
33    pub mbz: u8,
34    #[bits(6)]
35    pub service: Service,
36    pub smc64: bool,
37    pub fast: bool,
38}
39
40open_enum! {
41    pub enum SmcCall: FastCall {
42        SMCCC_VERSION = FastCall(0x8000_0000),
43        SMCCC_ARCH_FEATURES = FastCall(0x8000_0001),
44
45        PSCI_VERSION = FastCall(0x8400_0000),
46        CPU_SUSPEND = FastCall(0x8400_0001),
47        CPU_OFF = FastCall(0x8400_0002),
48        CPU_ON = FastCall(0x8400_0003),
49        AFFINITY_INFO = FastCall(0x8400_0004),
50        MIGRATE = FastCall(0x8400_0005),
51        MIGRATE_INFO_TYPE = FastCall(0x8400_0006),
52        MIGRATE_INFO_UP_CPU = FastCall(0x8400_0007),
53        SYSTEM_OFF = FastCall(0x8400_0008),
54        SYSTEM_OFF2 = FastCall(0x8400_0015),
55        SYSTEM_RESET = FastCall(0x8400_0009),
56        SYSTEM_RESET2 = FastCall(0x8400_0012),
57        MEM_PROTECT = FastCall(0x8400_0013),
58        MEM_PROTECT_CHECK_RANGE = FastCall(0x8400_0014),
59        PSCI_FEATURES = FastCall(0x8400_000a),
60        CPU_FREEZE = FastCall(0x8400_000b),
61        CPU_DEFAULT_SUSPEND = FastCall(0x8400_000c),
62        NODE_HW_STATE = FastCall(0x8400_000d),
63        SYSTEM_SUSPEND = FastCall(0x8400_000e),
64        PSCI_SET_SUSPEND_MODE = FastCall(0x8400_000f),
65        PSCI_STAT_RESIDENCY = FastCall(0x8400_0010),
66        PSCI_STAT_COUNT = FastCall(0x8400_0011),
67
68        VENDOR_HYP_UID = FastCall(0x8600_FF01),
69    }
70}
71
72open_enum! {
73    pub enum PsciError: i32 {
74        SUCCESS = 0,
75        NOT_SUPPORTED = -1,
76        INVALID_PARAMETERS = -2,
77        DENIED = -3,
78        ALREADY_ON = -4,
79        ON_PENDING = -5,
80        INTERNAL_FAILURE = -6,
81        NOT_PRESENT = -7,
82        DISABLED = -8,
83        INVALID_ADDRESS = -9,
84    }
85}