1 // Copyright 2022, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 //! PSCI calls.
16
17 const PSCI_SYSTEM_OFF: u32 = 0x84000008;
18 const PSCI_SYSTEM_RESET: u32 = 0x84000009;
19 const PSCI_SYSTEM_RESET2: u32 = 0x84000012;
20
system_off() -> u3221 pub fn system_off() -> u32 {
22 hvc32(PSCI_SYSTEM_OFF, 0, 0, 0, 0, 0, 0, 0)[0]
23 }
24
system_reset() -> u3225 pub fn system_reset() -> u32 {
26 hvc32(PSCI_SYSTEM_RESET, 0, 0, 0, 0, 0, 0, 0)[0]
27 }
28
29 #[allow(unused)]
system_reset2(reset_type: u32, cookie: u32) -> u3230 pub fn system_reset2(reset_type: u32, cookie: u32) -> u32 {
31 hvc32(PSCI_SYSTEM_RESET2, reset_type, cookie, 0, 0, 0, 0, 0)[0]
32 }
33
34 /// Make an HVC32 call to the hypervisor, following the SMC Calling Convention version 1.3.
35 #[inline(always)]
36 #[allow(clippy::too_many_arguments)]
hvc32( function: u32, arg1: u32, arg2: u32, arg3: u32, arg4: u32, arg5: u32, arg6: u32, arg7: u32, ) -> [u32; 8]37 fn hvc32(
38 function: u32,
39 arg1: u32,
40 arg2: u32,
41 arg3: u32,
42 arg4: u32,
43 arg5: u32,
44 arg6: u32,
45 arg7: u32,
46 ) -> [u32; 8] {
47 let mut ret = [0; 8];
48
49 #[cfg(target_arch = "aarch64")]
50 unsafe {
51 core::arch::asm!(
52 "hvc #0",
53 inout("w0") function => ret[0],
54 inout("w1") arg1 => ret[1],
55 inout("w2") arg2 => ret[2],
56 inout("w3") arg3 => ret[3],
57 inout("w4") arg4 => ret[4],
58 inout("w5") arg5 => ret[5],
59 inout("w6") arg6 => ret[6],
60 inout("w7") arg7 => ret[7],
61 options(nomem, nostack)
62 )
63 }
64
65 #[cfg(not(target_arch = "aarch64"))]
66 unimplemented!();
67
68 ret
69 }
70