xref: /freebsd/sys/powerpc/powernv/opal.h (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
1 /*-
2  * Copyright (c) 2015 Nathan Whitehorn
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 _POWERNV_OPAL_H
30 #define _POWERNV_OPAL_H
31 
32 #include <sys/cdefs.h>
33 #include <sys/types.h>
34 #include <sys/_eventhandler.h>
35 
36 /* Check if OPAL is correctly instantiated. Will try to instantiate it. */
37 int opal_check(void);
38 
39 /* Call an OPAL method. Any pointers passed must be real-mode accessible! */
40 int opal_call(uint64_t token, ...);
41 
42 #define OPAL_CONSOLE_WRITE		1
43 #define OPAL_CONSOLE_READ		2
44 #define OPAL_RTC_READ			3
45 #define OPAL_RTC_WRITE			4
46 #define	OPAL_CEC_POWER_DOWN		5
47 #define	OPAL_CEC_REBOOT			6
48 #define	OPAL_READ_NVRAM			7
49 #define	OPAL_WRITE_NVRAM		8
50 #define	OPAL_HANDLE_INTERRUPT		9
51 #define	OPAL_POLL_EVENTS		10
52 #define	OPAL_PCI_CONFIG_READ_BYTE	13
53 #define	OPAL_PCI_CONFIG_READ_HALF_WORD	14
54 #define	OPAL_PCI_CONFIG_READ_WORD	15
55 #define	OPAL_PCI_CONFIG_WRITE_BYTE	16
56 #define	OPAL_PCI_CONFIG_WRITE_HALF_WORD	17
57 #define	OPAL_PCI_CONFIG_WRITE_WORD	18
58 #define	OPAL_PCI_EEH_FREEZE_STATUS	23
59 #define OPAL_CONSOLE_WRITE_BUFFER_SPACE 25
60 #define	OPAL_PCI_EEH_FREEZE_CLEAR	26
61 #define	OPAL_PCI_PHB_MMIO_ENABLE	27
62 #define	OPAL_PCI_SET_PHB_MEM_WINDOW	28
63 #define	OPAL_PCI_MAP_PE_MMIO_WINDOW	29
64 #define	OPAL_PCI_SET_XIVE_PE		37
65 #define	OPAL_PCI_RESET			49
66 #define	OPAL_PCI_POLL			62
67 #define	OPAL_SET_XIVE           	19
68 #define	OPAL_GET_XIVE           	20
69 #define	OPAL_PCI_SET_PE			31
70 #define	OPAL_GET_MSI_32			39
71 #define	OPAL_GET_MSI_64			40
72 #define	OPAL_PCI_MSI_EOI		63
73 #define	OPAL_PCI_GET_PHB_DIAG_DATA2	64
74 #define	OPAL_START_CPU			41
75 #define	OPAL_PCI_MAP_PE_DMA_WINDOW	44
76 #define	OPAL_PCI_MAP_PE_DMA_WINDOW_REAL	45
77 #define	OPAL_RETURN_CPU			69
78 #define	OPAL_REINIT_CPUS		70
79 #define	OPAL_CHECK_TOKEN		80
80 #define	OPAL_GET_MSG			85
81 #define	OPAL_CHECK_ASYNC_COMPLETION	86
82 #define	OPAL_SENSOR_READ		88
83 #define	OPAL_HANDLE_HMI			98
84 #define	OPAL_IPMI_SEND			107
85 #define	OPAL_IPMI_RECV			108
86 #define	OPAL_I2C_REQUEST		109
87 #define	OPAL_FLASH_READ			110
88 #define	OPAL_FLASH_WRITE		111
89 #define	OPAL_FLASH_ERASE		112
90 #define	OPAL_INT_GET_XIRR		122
91 #define	OPAL_INT_SET_CPPR		123
92 #define	OPAL_INT_EOI			124
93 #define	OPAL_INT_SET_MFRR		125
94 #define	OPAL_PCI_TCE_KILL		126
95 #define	OPAL_NMMU_SET_PTCR		127
96 #define	OPAL_XIVE_RESET			128
97 #define	OPAL_XIVE_GET_IRQ_INFO		129
98 #define	OPAL_XIVE_GET_IRQ_CONFIG	130
99 #define	OPAL_XIVE_SET_IRQ_CONFIG	131
100 #define	OPAL_XIVE_GET_QUEUE_INFO	132
101 #define	OPAL_XIVE_SET_QUEUE_INFO	133
102 #define	OPAL_XIVE_DONATE_PAGE		134
103 #define	OPAL_XIVE_ALLOCATE_VP_BLOCK	135
104 #define	OPAL_XIVE_FREE_VP_BLOCK		136
105 #define	OPAL_XIVE_GET_VP_INFO		137
106 #define	OPAL_XIVE_SET_VP_INFO		138
107 #define	OPAL_XIVE_ALLOCATE_IRQ		139
108 #define	OPAL_XIVE_FREE_IRQ		140
109 #define	OPAL_XIVE_SYNC			141
110 #define	OPAL_XIVE_DUMP			142
111 #define	OPAL_SENSOR_GROUP_CLEAR		156
112 #define	OPAL_SENSOR_READ_U64		162
113 #define	OPAL_SENSOR_GROUP_ENABLE	163
114 #define	OPAL_HANDLE_HMI2		166
115 
116 /* For OPAL_PCI_SET_PE */
117 #define	OPAL_UNMAP_PE			0
118 #define OPAL_MAP_PE			1
119 
120 #define	OPAL_PCI_BUS_ANY		0
121 #define	OPAL_PCI_BUS_3BITS		2
122 #define	OPAL_PCI_BUS_4BITS		3
123 #define	OPAL_PCI_BUS_5BITS		4
124 #define	OPAL_PCI_BUS_6BITS		5
125 #define	OPAL_PCI_BUS_7BITS		6
126 #define	OPAL_PCI_BUS_ALL		7 /* Match bus number exactly */
127 
128 #define	OPAL_IGNORE_RID_DEVICE_NUMBER	0
129 #define	OPAL_COMPARE_RID_DEVICE_NUMBER	1
130 
131 #define	OPAL_IGNORE_RID_FUNC_NUMBER	0
132 #define	OPAL_COMPARE_RID_FUNC_NUMBER	1
133 
134 /* For OPAL_PCI_TCE_KILL */
135 #define	OPAL_PCI_TCE_KILL_PAGE		0
136 #define	OPAL_PCI_TCE_KILL_PE		1
137 #define	OPAL_PCI_TCE_KILL_ALL		2
138 
139 #define	OPAL_SUCCESS			0
140 #define	OPAL_PARAMETER			-1
141 #define	OPAL_BUSY			-2
142 #define OPAL_PARTIAL			-3
143 #define OPAL_CONSTRAINED		-4
144 #define	OPAL_CLOSED			-5
145 #define	OPAL_HARDWARE			-6
146 #define	OPAL_UNSUPPORTED		-7
147 #define OPAL_PERMISSION			-8
148 #define OPAL_NO_MEM			-9
149 #define	OPAL_RESOURCE			-10
150 #define OPAL_INTERNAL_ERROR		-11
151 #define	OPAL_BUSY_EVENT			-12
152 #define OPAL_HARDWARE_FROZEN		-13
153 #define OPAL_WRONG_STATE		-14
154 #define	OPAL_ASYNC_COMPLETION		-15
155 #define	OPAL_EMPTY			-16
156 #define OPAL_I2C_TIMEOUT		-17
157 #define OPAL_I2C_INVALID_CMD		-18
158 #define OPAL_I2C_LBUS_PARITY		-19
159 #define OPAL_I2C_BKEND_OVERRUN		-20
160 #define OPAL_I2C_BKEND_ACCESS		-21
161 #define OPAL_I2C_ARBT_LOST		-22
162 #define OPAL_I2C_NACK_RCVD		-23
163 #define OPAL_I2C_STOP_ERR		-24
164 #define OPAL_XSCOM_PARTIAL_GOOD		-25
165 #define OPAL_XSCOM_ADDR_ERROR		-26
166 #define OPAL_XSCOM_CLOCK_ERROR		-27
167 #define OPAL_XSCOM_PARITY_ERROR		-28
168 #define OPAL_XSCOM_TIMEOUT		-29
169 #define OPAL_XSCOM_CTR_OFFLINED		-30
170 #define	OPAL_XIVE_PROVISIONING		-31
171 #define	OPAL_XIVE_FREE_ACTIVE		-32
172 #define OPAL_TIMEOUT			-33
173 
174 #define	OPAL_TOKEN_ABSENT		0
175 #define	OPAL_TOKEN_PRESENT		1
176 
177 #define	OPAL_EVENT_OPAL_INTERNAL	0x1
178 #define	OPAL_EVENT_NVRAM		0x2
179 #define	OPAL_EVENT_RTC			0x4
180 #define	OPAL_EVENT_CONSOLE_INPUT	0x8
181 #define	OPAL_EVENT_CONSOLE_OUTPUT	0x10
182 #define	OPAL_EVENT_ERROR_LOG_AVAIL	0x20
183 #define	OPAL_EVENT_ERROR_LOG		0x40
184 #define	OPAL_EVENT_EPOW			0x80
185 #define	OPAL_EVENT_LED_STATUS		0x100
186 #define	OPAL_EVENT_PCI_ERROR		0x200
187 #define	OPAL_EVENT_DUMP_AVAIL		0x400
188 #define	OPAL_EVENT_MSG_PENDING		0x800
189 
190 #define	OPAL_HMI_FLAGS_TB_RESYNC	(1ull << 0)
191 #define	OPAL_HMI_FLAGS_DEC_LOST		(1ull << 1)
192 #define	OPAL_HMI_FLAGS_HDEC_LOST	(1ull << 2)
193 #define	OPAL_HMI_FLAGS_TOD_TB_FAIL	(1ull << 3)
194 #define	OPAL_HMI_FLAGS_NEW_EVENT	(1ull << 63)
195 
196 #define	OPAL_XIVE_XICS_MODE_EMU	0
197 #define	OPAL_XIVE_XICS_MODE_EXP	1
198 
199 #define	OPAL_XIVE_SYNC_EAS		0x00000001
200 #define	OPAL_XIVE_SYNC_QUEUE		0x00000002
201 
202 #define	OPAL_XIVE_VP_ENABLED		0x00000001
203 #define	OPAL_XIVE_VP_SINGLE_ESCALATION	0x00000002
204 
205 #define	OPAL_XIVE_EQ_ENABLED		0x00000001
206 #define	OPAL_XIVE_EQ_ALWAYS_NOTIFY	0x00000002
207 #define	OPAL_XIVE_EQ_ESCALATE		0x00000004
208 
209 struct opal_msg {
210 	uint32_t msg_type;
211 	uint32_t reserved;
212 	uint64_t params[8];
213 };
214 
215 enum opal_msg_type {
216 	OPAL_MSG_ASYNC_COMP	= 0,
217 	OPAL_MSG_MEM_ERR	= 1,
218 	OPAL_MSG_EPOW		= 2,
219 	OPAL_MSG_SHUTDOWN	= 3,
220 	OPAL_MSG_HMI_EVT	= 4,
221 	OPAL_MSG_DPO		= 5,
222 	OPAL_MSG_PRD		= 6,
223 	OPAL_MSG_OCC		= 7,
224 	OPAL_MSG_TYPE_MAX,
225 };
226 
227 #define	OPAL_IPMI_MSG_FORMAT_VERSION_1	1
228 
229 struct opal_ipmi_msg {
230 	uint8_t version;
231 	uint8_t netfn;
232 	uint8_t cmd;
233 	uint8_t data[];
234 };
235 
236 int	opal_init_async_tokens(int);
237 int	opal_alloc_async_token(void);
238 void	opal_free_async_token(int);
239 int	opal_wait_completion(void *, uint64_t, int);
240 
241 typedef void (*opal_msg_handler_fn)(void *, struct opal_msg *);
242 EVENTHANDLER_DECLARE(OPAL_ASYNC_COMP, opal_msg_handler_fn);
243 EVENTHANDLER_DECLARE(OPAL_EPOW, opal_msg_handler_fn);
244 EVENTHANDLER_DECLARE(OPAL_SHUTDOWN, opal_msg_handler_fn);
245 EVENTHANDLER_DECLARE(OPAL_HMI_EVT, opal_msg_handler_fn);
246 EVENTHANDLER_DECLARE(OPAL_DPO, opal_msg_handler_fn);
247 EVENTHANDLER_DECLARE(OPAL_OCC, opal_msg_handler_fn);
248 EVENTHANDLER_LIST_DECLARE(OPAL_ASYNC_COMP);
249 EVENTHANDLER_LIST_DECLARE(OPAL_EPOW);
250 EVENTHANDLER_LIST_DECLARE(OPAL_SHUTDOWN);
251 EVENTHANDLER_LIST_DECLARE(OPAL_HMI_EVT);
252 EVENTHANDLER_LIST_DECLARE(OPAL_DPO);
253 EVENTHANDLER_LIST_DECLARE(OPAL_OCC);
254 #endif
255