1 // Copyright 2017 The Fuchsia Authors
2 // Copyright (c) 2016, Google, Inc. All rights reserved
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 #pragma once
9 
10 #include <arch.h>
11 #include <arch/arm64/mp.h>
12 #include <dev/power.h>
13 
14 #define PSCI64_PSCI_VERSION                 (0x84000000)
15 #define PSCI64_CPU_SUSPEND                  (0xC4000001)
16 #define PSCI64_CPU_OFF                      (0x84000002)
17 #define PSCI64_CPU_ON                       (0xC4000003)
18 #define PSCI64_AFFINITY_INFO                (0xC4000004)
19 #define PSCI64_MIGRATE                      (0xC4000005)
20 #define PSCI64_MIGRATE_INFO_TYPE            (0x84000006)
21 #define PSCI64_MIGRATE_INFO_UP_CPU          (0xC4000007)
22 #define PSCI64_SYSTEM_OFF                   (0x84000008)
23 #define PSCI64_SYSTEM_RESET                 (0x84000009)
24 #define PSCI64_PSCI_FEATURES                (0x8400000A)
25 #define PSCI64_CPU_FREEZE                   (0x8400000B)
26 #define PSCI64_CPU_DEFAULT_SUSPEND          (0xC400000C)
27 #define PSCI64_NODE_HW_STATE                (0xC400000D)
28 #define PSCI64_SYSTEM_SUSPEND               (0xC400000E)
29 #define PSCI64_PSCI_SET_SUSPEND_MODE        (0x8400000F)
30 #define PSCI64_PSCI_STAT_RESIDENCY          (0xC4000010)
31 #define PSCI64_PSCI_STAT_COUNT              (0xC4000011)
32 
33 #define PSCI_SUCCESS                        0
34 #define PSCI_NOT_SUPPORTED                  -1
35 #define PSCI_INVALID_PARAMETERS             -2
36 #define PSCI_DENIED                         -3
37 #define PSCI_ALREADY_ON                     -4
38 #define PSCI_ON_PENDING                     -5
39 #define PSCI_INTERNAL_FAILURE               -6
40 #define PSCI_NOT_PRESENT                    -7
41 #define PSCI_DISABLED                       -8
42 #define PSCI_INVALID_ADDRESS                -9
43 
44 __BEGIN_CDECLS
45 
46 /* TODO NOTE: - currently these routines assume cpu topologies that are described only in AFF0 and AFF1.
47             If a system is architected such that AFF2 or AFF3 are non-zero then this code will need
48             to be revisited
49 */
50 
51 typedef uint64_t (*psci_call_proc)(uint32_t function, uint64_t arg0, uint64_t arg1, uint64_t arg2);
52 
53 extern psci_call_proc do_psci_call;
54 
psci_get_version(void)55 static inline uint32_t psci_get_version(void) {
56 
57     return (uint32_t)do_psci_call(PSCI64_PSCI_VERSION,0,0,0);
58 }
59 
60 /* powers down the calling cpu - only returns if call fails */
psci_cpu_off(void)61 static inline uint32_t psci_cpu_off(void) {
62 
63     return (uint32_t)do_psci_call(PSCI64_CPU_OFF,0,0,0);
64 }
65 
psci_cpu_on(uint64_t cluster,uint64_t cpuid,paddr_t entry)66 static inline uint32_t psci_cpu_on(uint64_t cluster, uint64_t cpuid, paddr_t entry) {
67 
68     return (uint32_t)do_psci_call(PSCI64_CPU_ON, ARM64_MPID(cluster, cpuid), entry, 0);
69 }
70 
psci_get_affinity_info(uint64_t cluster,uint64_t cpuid)71 static inline uint32_t psci_get_affinity_info(uint64_t cluster, uint64_t cpuid) {
72 
73     return (uint32_t)do_psci_call(PSCI64_AFFINITY_INFO, ARM64_MPID(cluster, cpuid), 0, 0);
74 }
75 
76 void psci_system_off(void);
77 
78 void psci_system_reset(enum reboot_flags flags);
79 
80 __END_CDECLS
81