1 /*
2  * Copyright 2020 Carlo Caione <ccaione@baylibre.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_PSCI_PSCI_H_
8 #define ZEPHYR_DRIVERS_PSCI_PSCI_H_
9 
10 #include <drivers/pm_cpu_ops/psci.h>
11 
12 #ifdef CONFIG_64BIT
13 #define PSCI_FN_NATIVE(version, name)		PSCI_##version##_FN64_##name
14 #else
15 #define PSCI_FN_NATIVE(version, name)		PSCI_##version##_FN_##name
16 #endif
17 
18 /* PSCI v0.2 interface */
19 #define PSCI_0_2_FN_BASE			0x84000000
20 #define PSCI_0_2_FN(n)				(PSCI_0_2_FN_BASE + (n))
21 #define PSCI_0_2_64BIT				0x40000000
22 #define PSCI_0_2_FN64_BASE			\
23 					(PSCI_0_2_FN_BASE + PSCI_0_2_64BIT)
24 #define PSCI_0_2_FN64(n)			(PSCI_0_2_FN64_BASE + (n))
25 
26 #define PSCI_0_2_FN_PSCI_VERSION		PSCI_0_2_FN(0)
27 #define PSCI_0_2_FN_CPU_SUSPEND			PSCI_0_2_FN(1)
28 #define PSCI_0_2_FN_CPU_OFF			PSCI_0_2_FN(2)
29 #define PSCI_0_2_FN_CPU_ON			PSCI_0_2_FN(3)
30 #define PSCI_0_2_FN_AFFINITY_INFO		PSCI_0_2_FN(4)
31 #define PSCI_0_2_FN_MIGRATE			PSCI_0_2_FN(5)
32 #define PSCI_0_2_FN_MIGRATE_INFO_TYPE		PSCI_0_2_FN(6)
33 #define PSCI_0_2_FN_MIGRATE_INFO_UP_CPU		PSCI_0_2_FN(7)
34 #define PSCI_0_2_FN_SYSTEM_OFF			PSCI_0_2_FN(8)
35 #define PSCI_0_2_FN_SYSTEM_RESET		PSCI_0_2_FN(9)
36 
37 #define PSCI_0_2_FN64_CPU_SUSPEND		PSCI_0_2_FN64(1)
38 #define PSCI_0_2_FN64_CPU_ON			PSCI_0_2_FN64(3)
39 #define PSCI_0_2_FN64_AFFINITY_INFO		PSCI_0_2_FN64(4)
40 #define PSCI_0_2_FN64_MIGRATE			PSCI_0_2_FN64(5)
41 #define PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU	PSCI_0_2_FN64(7)
42 
43 /* PSCI return values (inclusive of all PSCI versions) */
44 #define PSCI_RET_SUCCESS			0
45 #define PSCI_RET_NOT_SUPPORTED			-1
46 #define PSCI_RET_INVALID_PARAMS			-2
47 #define PSCI_RET_DENIED				-3
48 #define PSCI_RET_ALREADY_ON			-4
49 #define PSCI_RET_ON_PENDING			-5
50 #define PSCI_RET_INTERNAL_FAILURE		-6
51 #define PSCI_RET_NOT_PRESENT			-7
52 #define PSCI_RET_DISABLED			-8
53 #define PSCI_RET_INVALID_ADDRESS		-9
54 
55 typedef unsigned long (psci_fn)(unsigned long, unsigned long,
56 				unsigned long, unsigned long);
57 
58 struct psci {
59 	enum arm_smccc_conduit conduit;
60 	psci_fn *invoke_psci_fn;
61 	uint32_t ver;
62 };
63 
64 #endif /* ZEPHYR_DRIVERS_PSCI_PSCI_H_ */
65