1 #include <kernel/thread.h>
2 #include <sm/sm.h>
3 #include <stdint.h>
4 
5 #define PSCI_VERSION_0_2		U(0x00000002)
6 #define PSCI_VERSION_1_0		U(0x00010000)
7 #define PSCI_VERSION_1_1		U(0x00010001)
8 #define PSCI_VERSION			U(0x84000000)
9 #define PSCI_CPU_SUSPEND		U(0x84000001)
10 #define PSCI_CPU_OFF			U(0x84000002)
11 #define PSCI_CPU_ON			U(0x84000003)
12 #define PSCI_CPU_ON_SMC64		(PSCI_CPU_ON | U(0x40000000))
13 #define PSCI_AFFINITY_INFO		U(0x84000004)
14 #define PSCI_MIGRATE			U(0x84000005)
15 #define PSCI_MIGRATE_INFO_TYPE		U(0x84000006)
16 #define PSCI_MIGRATE_INFO_UP_CPU	U(0x84000007)
17 #define PSCI_SYSTEM_OFF			U(0x84000008)
18 #define PSCI_SYSTEM_RESET		U(0x84000009)
19 #define PSCI_PSCI_FEATURES		U(0x8400000a)
20 #define PSCI_CPU_FREEZE			U(0x8400000b)
21 #define PSCI_CPU_DEFAULT_SUSPEND	U(0x8400000c)
22 #define PSCI_NODE_HW_STATE		U(0x8400000d)
23 #define PSCI_SYSTEM_SUSPEND		U(0x8400000e)
24 #define PSCI_PSCI_SET_SUSPEND_MODE	U(0x8400000f)
25 #define PSCI_FN_STAT_RESIDENCY		U(0x84000010)
26 #define PSCI_FN_STAT_COUNT		U(0x84000011)
27 #define PSCI_SYSTEM_RESET2		U(0x84000012)
28 #define PSCI_MEM_PROTECT		U(0x84000013)
29 #define PSCI_MEM_PROTECT_CHECK_RANGE	U(0x84000014)
30 
31 #define PSCI_NUM_CALLS			U(21)
32 
33 #define PSCI_AFFINITY_LEVEL_ON		U(0)
34 #define PSCI_AFFINITY_LEVEL_OFF		U(1)
35 #define PSCI_AFFINITY_LEVEL_ON_PENDING	U(2)
36 
37 #define PSCI_POWER_STATE_ID_MASK	U(0xffff)
38 #define PSCI_POWER_STATE_ID_SHIFT	U(0)
39 #define PSCI_POWER_STATE_TYPE_SHIFT	U(16)
40 #define PSCI_POWER_STATE_TYPE_MASK	BIT32(PSCI_POWER_STATE_TYPE_SHIFT)
41 #define PSCI_POWER_STATE_AFFL_SHIFT	U(24)
42 #define PSCI_POWER_STATE_AFFL_MASK	SHIFT_U32(0x3, \
43 						  PSCI_POWER_STATE_AFFL_SHIFT)
44 
45 #define PSCI_POWER_STATE_TYPE_STANDBY		U(0)
46 #define PSCI_POWER_STATE_TYPE_POWER_DOWN	U(1)
47 
48 #define PSCI_RET_SUCCESS		(0)
49 #define PSCI_RET_NOT_SUPPORTED		(-1)
50 #define PSCI_RET_INVALID_PARAMETERS	(-2)
51 #define PSCI_RET_DENIED			(-3)
52 #define PSCI_RET_ALREADY_ON		(-4)
53 #define PSCI_RET_ON_PENDING		(-5)
54 #define PSCI_RET_INTERNAL_FAILURE	(-6)
55 #define PSCI_RET_NOT_PRESENT		(-7)
56 #define PSCI_RET_DISABLED		(-8)
57 #define PSCI_RET_INVALID_ADDRESS	(-9)
58 
59 uint32_t psci_version(void);
60 int psci_cpu_suspend(uint32_t power_state, uintptr_t entry,
61 		     uint32_t context_id, struct sm_nsec_ctx *nsec);
62 int psci_cpu_off(void);
63 int psci_cpu_on(uint32_t cpu_id, uint32_t entry, uint32_t context_id);
64 int psci_affinity_info(uint32_t affinity, uint32_t lowest_affnity_level);
65 int psci_migrate(uint32_t cpu_id);
66 int psci_migrate_info_type(void);
67 int psci_migrate_info_up_cpu(void);
68 void psci_system_off(void);
69 void psci_system_reset(void);
70 int psci_features(uint32_t psci_fid);
71 int psci_system_reset2(uint32_t reset_type, uint32_t cookie);
72 int psci_mem_protect(uint32_t enable);
73 int psci_mem_chk_range(paddr_t base, size_t length);
74 int psci_node_hw_state(uint32_t cpu_id, uint32_t power_level);
75 int psci_system_suspend(uintptr_t entry, uint32_t context_id,
76 			struct sm_nsec_ctx *nsec);
77 int psci_stat_residency(uint32_t cpu_id, uint32_t power_state);
78 int psci_stat_count(uint32_t cpu_id, uint32_t power_state);
79 void tee_psci_handler(struct thread_smc_args *args, struct sm_nsec_ctx *nsec);
80 
81 void psci_armv7_cpu_off(void);
82