1 /*
2  * Copyright (c) 2022 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <dev/power/psci.h>
9 
10 #if WITH_LIB_CONSOLE
11 #include <lk/console_cmd.h>
12 #include <stdio.h>
13 #endif
14 
15 #define PSCI_VERSION  0x84000000
16 #define SYSTEM_OFF    0x84000008
17 #define SYSTEM_RESET  0x84000009
18 
19 #if ARCH_ARM
20 #define CPU_ON        0x84000003
21 #endif
22 
23 #if ARCH_ARM64
24 #define CPU_ON        0xC4000003
25 #endif
26 
27 /* low level ASM routine to make the raw PSCI call */
28 int psci_call(ulong arg0, ulong arg1, ulong arg2, ulong arg3);
29 
psci_version(void)30 uint32_t psci_version(void) {
31   return psci_call(PSCI_VERSION, 0, 0, 0);
32 }
33 
psci_cpu_on(int corenr,ulong entrypoint)34 int psci_cpu_on(int corenr, ulong entrypoint) {
35   return psci_call(CPU_ON, corenr, entrypoint, corenr);
36 }
37 
psci_system_off(void)38 void psci_system_off(void) {
39   psci_call(SYSTEM_OFF, 0, 0, 0);
40 }
41 
psci_system_reset(void)42 void psci_system_reset(void) {
43   psci_call(SYSTEM_RESET, 0, 0, 0);
44 }
45 
46 #if WITH_LIB_CONSOLE
47 
cmd_psci_version(int argc,const console_cmd_args * argv)48 static int cmd_psci_version(int argc, const console_cmd_args *argv) {
49   int ret = psci_version();
50   printf("PSCI VERSION: 0x%x\n", ret);
51   return 0;
52 }
53 
54 STATIC_COMMAND_START
55 STATIC_COMMAND("psci_version", "show psci version", &cmd_psci_version)
56 STATIC_COMMAND_END(psci);
57 #endif
58