xref: /openbsd/sys/dev/acpi/dsdt.h (revision 0f9e9ec2)
1 /* $OpenBSD: dsdt.h,v 1.82 2024/05/13 01:15:50 jsg Exp $ */
2 /*
3  * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef __DEV_ACPI_DSDT_H__
19 #define __DEV_ACPI_DSDT_H__
20 
21 struct aml_scope {
22 	struct acpi_softc	*sc;
23 	uint8_t			*pos;
24 	uint8_t			*start;
25 	uint8_t			*end;
26 	struct aml_node		*node;
27 	struct aml_scope	*parent;
28 	struct aml_value	*locals;
29 	struct aml_value	*args;
30 	struct aml_value	*retv;
31 	int			type;
32 	int			depth;
33 };
34 
35 
36 struct aml_opcode {
37 	uint32_t		opcode;
38 	const char		*mnem;
39 	const char		*args;
40 };
41 
42 const char		*aml_eisaid(uint32_t);
43 const char		*aml_mnem(int, uint8_t *);
44 int64_t			aml_val2int(struct aml_value *);
45 struct aml_node		*aml_searchname(struct aml_node *, const void *);
46 struct aml_node		*aml_searchrel(struct aml_node *, const void *);
47 const char		*aml_getname(const char *);
48 
49 struct aml_value	*aml_getstack(struct aml_scope *, int);
50 struct aml_value	*aml_allocvalue(int, int64_t, const void *);
51 void			aml_freevalue(struct aml_value *);
52 void			aml_notify(struct aml_node *, int);
53 void			aml_showvalue(struct aml_value *);
54 
55 void			aml_find_node(struct aml_node *, const char *,
56 			    int (*)(struct aml_node *, void *), void *);
57 int			acpi_parse_aml(struct acpi_softc *, const char *,
58 			    u_int8_t *, uint32_t);
59 void			aml_register_notify(struct aml_node *, const char *,
60 			    int (*)(struct aml_node *, int, void *), void *,
61 			    int);
62 void			aml_register_regionspace(struct aml_node *, int, void *,
63 			    int (*)(void *, int, uint64_t, int, uint64_t *));
64 
65 int			aml_evalnode(struct acpi_softc *, struct aml_node *,
66 			    int, struct aml_value *, struct aml_value *);
67 int			aml_node_setval(struct acpi_softc *, struct aml_node *,
68 			    int64_t);
69 int			aml_evalname(struct acpi_softc *, struct aml_node *,
70 			    const char *, int, struct aml_value *,
71 			    struct aml_value *);
72 int			aml_evalinteger(struct acpi_softc *, struct aml_node *,
73                             const char *, int, struct aml_value *, int64_t *);
74 
75 void			aml_create_defaultobjects(void);
76 
77 const char		*aml_nodename(struct aml_node *);
78 
79 #define SRT_IRQ2		0x22
80 #define SRT_IRQ3		0x23
81 #define SRT_DMA			0x2A
82 #define SRT_STARTDEP0		0x30
83 #define SRT_STARTDEP1		0x31
84 #define SRT_ENDDEP		0x38
85 #define SRT_IOPORT		0x47
86 #define SRT_FIXEDPORT		0x4B
87 #define SRT_ENDTAG		0x79
88 
89 #define SR_IRQ			0x04
90 #define SR_DMA			0x05
91 #define SR_STARTDEP		0x06
92 #define SR_ENDDEP		0x07
93 #define SR_IOPORT		0x08
94 #define SR_FIXEDPORT		0x09
95 #define SR_ENDTAG		0x0F
96 /* byte zero of small resources combines the tag above a length [1..7] */
97 #define	SR_TAG(tag,len)		((tag << 3) + (len))
98 
99 #define LR_MEM24		0x81
100 #define LR_GENREGISTER		0x82
101 #define LR_MEM32		0x85
102 #define LR_MEM32FIXED		0x86
103 #define LR_DWORD		0x87
104 #define LR_WORD			0x88
105 #define LR_EXTIRQ		0x89
106 #define LR_QWORD		0x8A
107 #define LR_GPIO			0x8C
108 #define LR_SERBUS		0x8E
109 
110 #define __amlflagbit(v,s,l)
111 union acpi_resource {
112 	struct {
113 		uint8_t  typecode;
114 		uint16_t length;
115 	}  __packed hdr;
116 
117 	/* Small resource structures
118 	 * format of typecode is: tttttlll, t = type, l = length
119 	 */
120 	struct {
121 		uint8_t  typecode;
122 		uint16_t irq_mask;
123 		uint8_t  irq_flags;
124 #define SR_IRQ_SHR		(1L << 4)
125 #define SR_IRQ_POLARITY		(1L << 3)
126 #define SR_IRQ_MODE		(1L << 0)
127 	}  __packed sr_irq;
128 	struct {
129 		uint8_t  typecode;
130 		uint8_t  channel;
131 		uint8_t  flags;
132 #define SR_DMA_TYP_MASK		0x3
133 #define SR_DMA_TYP_SHIFT 	5
134 #define SR_DMA_BM		(1L << 2)
135 #define SR_DMA_SIZE_MASK	0x3
136 #define SR_DMA_SIZE_SHIFT	0
137 	}  __packed sr_dma;
138 	struct {
139 		uint8_t  typecode;
140 		uint8_t  flags;
141 #define SR_IOPORT_DEC		(1L << 0)
142 		uint16_t _min;
143 		uint16_t _max;
144 		uint8_t  _aln;
145 		uint8_t  _len;
146 	}  __packed sr_ioport;
147 	struct {
148 		uint8_t  typecode;
149 		uint16_t _bas;
150 		uint8_t  _len;
151 	}  __packed sr_fioport;
152 
153 	/* Large resource structures */
154 	struct {
155 		uint8_t  typecode;
156 		uint16_t length;
157 		uint8_t  _info;
158 		uint16_t _min;
159 		uint16_t _max;
160 		uint16_t _aln;
161 		uint16_t _len;
162 	}  __packed lr_m24;
163 	struct {
164 		uint8_t  typecode;
165 		uint16_t length;
166 		uint8_t  _info;
167 		uint32_t _min;
168 		uint32_t _max;
169 		uint32_t _aln;
170 		uint32_t _len;
171 	}  __packed lr_m32;
172 	struct {
173 		uint8_t  typecode;
174 		uint16_t length;
175 		uint8_t  _info;
176 		uint32_t _bas;
177 		uint32_t _len;
178 	}  __packed lr_m32fixed;
179 	struct {
180 		uint8_t  typecode;
181 		uint16_t length;
182 		uint8_t  flags;
183 #define LR_EXTIRQ_SHR		(1L << 3)
184 #define LR_EXTIRQ_POLARITY	(1L << 2)
185 #define LR_EXTIRQ_MODE		(1L << 1)
186 		uint8_t  irq_count;
187 		uint32_t irq[1];
188 	} __packed lr_extirq;
189 	struct {
190 		uint8_t		typecode;
191 		uint16_t	length;
192 		uint8_t		type;
193 #define LR_TYPE_MEMORY		0
194 #define LR_TYPE_IO		1
195 #define LR_TYPE_BUS		2
196 		uint8_t		flags;
197 		uint8_t		tflags;
198 #define LR_MEMORY_TTP		(1L << 5)
199 #define LR_IO_TTP		(1L << 4)
200 		uint16_t	_gra;
201 		uint16_t	_min;
202 		uint16_t	_max;
203 		uint16_t	_tra;
204 		uint16_t	_len;
205 		uint8_t		src_index;
206 		char		src[1];
207 	} __packed lr_word;
208 	struct {
209 		uint8_t		typecode;
210 		uint16_t	length;
211 		uint8_t		type;
212 		uint8_t		flags;
213 		uint8_t		tflags;
214 		uint32_t	_gra;
215 		uint32_t	_min;
216 		uint32_t	_max;
217 		uint32_t	_tra;
218 		uint32_t	_len;
219 		uint8_t		src_index;
220 		char		src[1];
221 	} __packed lr_dword;
222 	struct {
223 		uint8_t		typecode;
224 		uint16_t	length;
225 		uint8_t		type;
226 		uint8_t		flags;
227 		uint8_t		tflags;
228 		uint64_t	_gra;
229 		uint64_t	_min;
230 		uint64_t	_max;
231 		uint64_t	_tra;
232 		uint64_t	_len;
233 		uint8_t		src_index;
234 		char		src[1];
235 	} __packed lr_qword;
236 	struct {
237 		uint8_t		typecode;
238 		uint16_t	length;
239 		uint8_t		revid;
240 		uint8_t		type;
241 #define LR_GPIO_INT	0x00
242 #define LR_GPIO_IO	0x01
243 		uint16_t	flags;
244 		uint16_t	tflags;
245 #define LR_GPIO_SHR		(3L << 3)
246 #define LR_GPIO_POLARITY	(3L << 1)
247 #define  LR_GPIO_ACTHI		(0L << 1)
248 #define  LR_GPIO_ACTLO		(1L << 1)
249 #define  LR_GPIO_ACTBOTH	(2L << 1)
250 #define LR_GPIO_MODE		(1L << 0)
251 #define  LR_GPIO_LEVEL		(0L << 0)
252 #define  LR_GPIO_EDGE		(1L << 0)
253 		uint8_t		_ppi;
254 		uint16_t	_drs;
255 		uint16_t	_dbt;
256 		uint16_t	pin_off;
257 		uint8_t		residx;
258 		uint16_t	res_off;
259 		uint16_t	vd_off;
260 		uint16_t	vd_len;
261 	} __packed lr_gpio;
262 	struct {
263 		uint8_t		typecode;
264 		uint16_t	length;
265 		uint8_t		revid;
266 		uint8_t		residx;
267 		uint8_t		type;
268 #define LR_SERBUS_I2C	1
269 		uint8_t		flags;
270 		uint16_t	tflags;
271 		uint8_t		trevid;
272 		uint16_t	tlength;
273 		uint8_t		tdata[1];
274 	} __packed lr_serbus;
275 	struct {
276 		uint8_t		typecode;
277 		uint16_t	length;
278 		uint8_t		revid;
279 		uint8_t		residx;
280 		uint8_t		type;
281 		uint8_t		flags;
282 		uint16_t	tflags;
283 		uint8_t		trevid;
284 		uint16_t	tlength;
285 		uint32_t	_spe;
286 		uint16_t	_adr;
287 		uint8_t		vdata[1];
288 	} __packed lr_i2cbus;
289 	uint8_t		pad[64];
290 } __packed;
291 
292 #define AML_CRSTYPE(x)	((x)->hdr.typecode & 0x80 ? \
293 			    (x)->hdr.typecode : (x)->hdr.typecode >> 3)
294 #define AML_CRSLEN(x)	((x)->hdr.typecode & 0x80 ? \
295 			    3+(x)->hdr.length : 1+((x)->hdr.typecode & 0x7))
296 
297 int			aml_print_resource(union acpi_resource *, void *);
298 int			aml_parse_resource(struct aml_value *,
299 			    int (*)(int, union acpi_resource *, void *),
300 			    void *);
301 
302 #define ACPI_E_NOERROR   0x00
303 #define ACPI_E_BADVALUE  0x01
304 
305 #define AML_MAX_ARG	 7
306 #define AML_MAX_LOCAL	 8
307 
308 #define AML_WALK_PRE 0x00
309 #define AML_WALK_POST 0x01
310 
311 void			aml_walknodes(struct aml_node *, int,
312 			    int (*)(struct aml_node *, void *), void *);
313 
314 void			aml_postparse(void);
315 
316 void			aml_hashopcodes(void);
317 
318 void			aml_foreachpkg(struct aml_value *, int,
319 			    void (*fn)(struct aml_value *, void *), void *);
320 
321 const char		*aml_val_to_string(const struct aml_value *);
322 
323 void			aml_disasm(struct aml_scope *scope, int lvl,
324 			    void (*dbprintf)(void *, const char *, ...),
325 			    void *arg);
326 int			aml_evalhid(struct aml_node *, struct aml_value *);
327 
328 int			acpi_walkmem(int, const char *);
329 
330 #define aml_get8(p)    *(uint8_t *)(p)
331 #define aml_get16(p)   *(uint16_t *)(p)
332 #define aml_get32(p)   *(uint32_t *)(p)
333 #define aml_get64(p)   *(uint64_t *)(p)
334 
335 union amlpci_t {
336 	uint64_t addr;
337 	struct {
338 		uint16_t reg;
339 		uint16_t fun;
340 		uint8_t dev;
341 		uint8_t bus;
342 		uint16_t seg;
343 	};
344 };
345 int			aml_rdpciaddr(struct aml_node *pcidev,
346 			    union amlpci_t *);
347 
348 #ifndef SMALL_KERNEL
349 void			acpi_getdevlist(struct acpi_devlist_head *,
350 			    struct aml_node *, struct aml_value *, int);
351 #endif
352 void			aml_notify_dev(const char *, int);
353 
354 void			acpi_freedevlist(struct acpi_devlist_head *);
355 
356 void			acpi_glk_enter(void);
357 void			acpi_glk_leave(void);
358 
359 /* https://docs.microsoft.com/en-us/windows-hardware/drivers/acpi/winacpi-osi */
360 
361 enum acpi_osi {
362 	OSI_UNKNOWN = -1,
363 	OSI_WIN_2000,
364 	OSI_WIN_XP,
365 	OSI_WIN_2003,
366 	OSI_WIN_2003_SP1,
367 	OSI_WIN_XP_SP0,
368 	OSI_WIN_XP_SP1,
369 	OSI_WIN_XP_SP2,
370 	OSI_WIN_XP_SP3,
371 	OSI_WIN_XP_SP4,
372 	OSI_WIN_VISTA,
373 	OSI_WIN_2008,
374 	OSI_WIN_VISTA_SP1,
375 	OSI_WIN_VISTA_SP2,
376 	OSI_WIN_7,
377 	OSI_WIN_8,
378 	OSI_WIN_8_1,
379 	OSI_WIN_10,
380 	OSI_WIN_10_1607,
381 	OSI_WIN_10_1703,
382 	OSI_WIN_10_1709,
383 	OSI_WIN_10_1803,
384 	OSI_WIN_10_1809,
385 	OSI_WIN_10_1903,
386 	OSI_WIN_10_2004,
387 	OSI_WIN_11,
388 	OSI_WIN_11_22H2
389 };
390 
391 #define AML_VALID_OSI		\
392 	"Windows 2000",		\
393 	"Windows 2001",		\
394 	"Windows 2001.1",	\
395 	"Windows 2001.1 SP1",	\
396 	"Windows 2001 SP0",	\
397 	"Windows 2001 SP1",	\
398 	"Windows 2001 SP2",	\
399 	"Windows 2001 SP3",	\
400 	"Windows 2001 SP4",	\
401 	"Windows 2006",		\
402 	"Windows 2006.1",	\
403 	"Windows 2006 SP1",	\
404 	"Windows 2006 SP2",	\
405 	"Windows 2009",		\
406 	"Windows 2012",		\
407 	"Windows 2013",		\
408 	"Windows 2015",		\
409 	"Windows 2016",		\
410 	"Windows 2017",		\
411 	"Windows 2017.2",	\
412 	"Windows 2018",		\
413 	"Windows 2018.2",	\
414 	"Windows 2019",		\
415 	"Windows 2020",		\
416 	"Windows 2021",		\
417 	"Windows 2022"
418 
419 extern enum acpi_osi acpi_max_osi;	/* most recent Win version FW knows */
420 
421 #endif /* __DEV_ACPI_DSDT_H__ */
422