xref: /freebsd/sys/dev/psci/psci.h (revision 5477372324b92240a96310ef2d45fa44ce8d0a93)
1 /*-
2  * Copyright (c) 2013, 2014 Robin Randhawa
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef	_MACHINE_PSCI_H_
30 #define	_MACHINE_PSCI_H_
31 
32 #include <sys/types.h>
33 
34 typedef int (*psci_initfn_t)(device_t dev);
35 typedef int (*psci_callfn_t)(register_t, register_t, register_t, register_t);
36 
37 extern int psci_present;
38 
39 void	psci_reset(void);
40 int	psci_cpu_on(unsigned long, unsigned long, unsigned long);
41 int	psci_hvc_despatch(register_t, register_t, register_t, register_t);
42 int	psci_smc_despatch(register_t, register_t, register_t, register_t);
43 
44 
45 /*
46  * PSCI return codes.
47  */
48 #define	PSCI_RETVAL_SUCCESS		0
49 #define	PSCI_RETVAL_NOT_SUPPORTED	-1
50 #define	PSCI_RETVAL_INVALID_PARAMS	-2
51 #define	PSCI_RETVAL_DENIED		-3
52 #define	PSCI_RETVAL_ALREADY_ON		-4
53 #define	PSCI_RETVAL_ON_PENDING		-5
54 #define	PSCI_RETVAL_INTERNAL_FAILURE	-6
55 #define	PSCI_RETVAL_NOT_PRESENT		-7
56 #define	PSCI_RETVAL_DISABLED		-8
57 /*
58  * Used to signal PSCI is not available, e.g. to start a CPU.
59  */
60 #define	PSCI_MISSING			1
61 
62 /*
63  * PSCI function codes (as per PSCI v0.2).
64  */
65 #ifdef __aarch64__
66 #define	PSCI_FNID_VERSION		0x84000000
67 #define	PSCI_FNID_CPU_SUSPEND		0xc4000001
68 #define	PSCI_FNID_CPU_OFF		0x84000002
69 #define	PSCI_FNID_CPU_ON		0xc4000003
70 #define	PSCI_FNID_AFFINITY_INFO		0xc4000004
71 #define	PSCI_FNID_MIGRATE		0xc4000005
72 #define	PSCI_FNID_MIGRATE_INFO_TYPE	0x84000006
73 #define	PSCI_FNID_MIGRATE_INFO_UP_CPU	0xc4000007
74 #define	PSCI_FNID_SYSTEM_OFF		0x84000008
75 #define	PSCI_FNID_SYSTEM_RESET		0x84000009
76 #else
77 #define	PSCI_FNID_VERSION		0x84000000
78 #define	PSCI_FNID_CPU_SUSPEND		0x84000001
79 #define	PSCI_FNID_CPU_OFF		0x84000002
80 #define	PSCI_FNID_CPU_ON		0x84000003
81 #define	PSCI_FNID_AFFINITY_INFO		0x84000004
82 #define	PSCI_FNID_MIGRATE		0x84000005
83 #define	PSCI_FNID_MIGRATE_INFO_TYPE	0x84000006
84 #define	PSCI_FNID_MIGRATE_INFO_UP_CPU	0x84000007
85 #define	PSCI_FNID_SYSTEM_OFF		0x84000008
86 #define	PSCI_FNID_SYSTEM_RESET		0x84000009
87 #endif
88 
89 #define	PSCI_VER_MAJOR(v)		(((v) >> 16) & 0xFF)
90 #define	PSCI_VER_MINOR(v)		((v) & 0xFF)
91 
92 enum psci_fn {
93 	PSCI_FN_VERSION,
94 	PSCI_FN_CPU_SUSPEND,
95 	PSCI_FN_CPU_OFF,
96 	PSCI_FN_CPU_ON,
97 	PSCI_FN_AFFINITY_INFO,
98 	PSCI_FN_MIGRATE,
99 	PSCI_FN_MIGRATE_INFO_TYPE,
100 	PSCI_FN_MIGRATE_INFO_UP_CPU,
101 	PSCI_FN_SYSTEM_OFF,
102 	PSCI_FN_SYSTEM_RESET,
103 	PSCI_FN_MAX
104 };
105 
106 #endif /* _MACHINE_PSCI_H_ */
107