xref: /openbsd/sys/dev/acpi/dsdt.h (revision e5dd7070)
1 /* $OpenBSD: dsdt.h,v 1.77 2018/08/19 08:23:47 kettenis 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 
48 struct aml_value	*aml_getstack(struct aml_scope *, int);
49 struct aml_value	*aml_allocvalue(int, int64_t, const void *);
50 void			aml_freevalue(struct aml_value *);
51 void			aml_notify(struct aml_node *, int);
52 void			aml_showvalue(struct aml_value *);
53 void			aml_walkroot(void);
54 void			aml_walktree(struct aml_node *);
55 
56 void			aml_find_node(struct aml_node *, const char *,
57 			    int (*)(struct aml_node *, void *), void *);
58 int			acpi_parse_aml(struct acpi_softc *, u_int8_t *,
59 			    uint32_t);
60 void			aml_register_notify(struct aml_node *, const char *,
61 			    int (*)(struct aml_node *, int, void *), void *,
62 			    int);
63 void			aml_register_regionspace(struct aml_node *, int, void *,
64 			    int (*)(void *, int, uint64_t, int, uint64_t *));
65 
66 int			aml_evalnode(struct acpi_softc *, struct aml_node *,
67 			    int, struct aml_value *, struct aml_value *);
68 int			aml_node_setval(struct acpi_softc *, struct aml_node *,
69 			    int64_t);
70 int			aml_evalname(struct acpi_softc *, struct aml_node *,
71 			    const char *, int, struct aml_value *,
72 			    struct aml_value *);
73 int			aml_evalinteger(struct acpi_softc *, struct aml_node *,
74                             const char *, int, struct aml_value *, int64_t *);
75 
76 void			aml_create_defaultobjects(void);
77 
78 const char		*aml_nodename(struct aml_node *);
79 
80 #define SRT_IRQ2		0x22
81 #define SRT_IRQ3		0x23
82 #define SRT_DMA			0x2A
83 #define SRT_STARTDEP0		0x30
84 #define SRT_STARTDEP1		0x31
85 #define SRT_ENDDEP		0x38
86 #define SRT_IOPORT		0x47
87 #define SRT_FIXEDPORT		0x4B
88 #define SRT_ENDTAG		0x79
89 
90 #define SR_IRQ			0x04
91 #define SR_DMA			0x05
92 #define SR_STARTDEP		0x06
93 #define SR_ENDDEP		0x07
94 #define SR_IOPORT		0x08
95 #define SR_FIXEDPORT		0x09
96 #define SR_ENDTAG		0x0F
97 /* byte zero of small resources combines the tag above a length [1..7] */
98 #define	SR_TAG(tag,len)		((tag << 3) + (len))
99 
100 #define LR_MEM24		0x81
101 #define LR_GENREGISTER		0x82
102 #define LR_MEM32		0x85
103 #define LR_MEM32FIXED		0x86
104 #define LR_DWORD		0x87
105 #define LR_WORD			0x88
106 #define LR_EXTIRQ		0x89
107 #define LR_QWORD		0x8A
108 #define LR_GPIO			0x8C
109 #define LR_SERBUS		0x8E
110 
111 #define __amlflagbit(v,s,l)
112 union acpi_resource {
113 	struct {
114 		uint8_t  typecode;
115 		uint16_t length;
116 	}  __packed hdr;
117 
118 	/* Small resource structures
119 	 * format of typecode is: tttttlll, t = type, l = length
120 	 */
121 	struct {
122 		uint8_t  typecode;
123 		uint16_t irq_mask;
124 		uint8_t  irq_flags;
125 #define SR_IRQ_SHR		(1L << 4)
126 #define SR_IRQ_POLARITY		(1L << 3)
127 #define SR_IRQ_MODE		(1L << 0)
128 	}  __packed sr_irq;
129 	struct {
130 		uint8_t  typecode;
131 		uint8_t  channel;
132 		uint8_t  flags;
133 #define SR_DMA_TYP_MASK		0x3
134 #define SR_DMA_TYP_SHIFT 	5
135 #define SR_DMA_BM		(1L << 2)
136 #define SR_DMA_SIZE_MASK	0x3
137 #define SR_DMA_SIZE_SHIFT	0
138 	}  __packed sr_dma;
139 	struct {
140 		uint8_t  typecode;
141 		uint8_t  flags;
142 #define SR_IOPORT_DEC		(1L << 0)
143 		uint16_t _min;
144 		uint16_t _max;
145 		uint8_t  _aln;
146 		uint8_t  _len;
147 	}  __packed sr_ioport;
148 	struct {
149 		uint8_t  typecode;
150 		uint16_t _bas;
151 		uint8_t  _len;
152 	}  __packed sr_fioport;
153 
154 	/* Large resource structures */
155 	struct {
156 		uint8_t  typecode;
157 		uint16_t length;
158 		uint8_t  _info;
159 		uint16_t _min;
160 		uint16_t _max;
161 		uint16_t _aln;
162 		uint16_t _len;
163 	}  __packed lr_m24;
164 	struct {
165 		uint8_t  typecode;
166 		uint16_t length;
167 		uint8_t  _info;
168 		uint32_t _min;
169 		uint32_t _max;
170 		uint32_t _aln;
171 		uint32_t _len;
172 	}  __packed lr_m32;
173 	struct {
174 		uint8_t  typecode;
175 		uint16_t length;
176 		uint8_t  _info;
177 		uint32_t _bas;
178 		uint32_t _len;
179 	}  __packed lr_m32fixed;
180 	struct {
181 		uint8_t  typecode;
182 		uint16_t length;
183 		uint8_t  flags;
184 #define LR_EXTIRQ_SHR		(1L << 3)
185 #define LR_EXTIRQ_POLARITY	(1L << 2)
186 #define LR_EXTIRQ_MODE		(1L << 1)
187 		uint8_t  irq_count;
188 		uint32_t irq[1];
189 	} __packed lr_extirq;
190 	struct {
191 		uint8_t		typecode;
192 		uint16_t	length;
193 		uint8_t		type;
194 #define LR_TYPE_MEMORY		0
195 #define LR_TYPE_IO		1
196 #define LR_TYPE_BUS		2
197 		uint8_t		flags;
198 		uint8_t		tflags;
199 #define LR_MEMORY_TTP		(1L << 5)
200 #define LR_IO_TTP		(1L << 4)
201 		uint16_t	_gra;
202 		uint16_t	_min;
203 		uint16_t	_max;
204 		uint16_t	_tra;
205 		uint16_t	_len;
206 		uint8_t		src_index;
207 		char		src[1];
208 	} __packed lr_word;
209 	struct {
210 		uint8_t		typecode;
211 		uint16_t	length;
212 		uint8_t		type;
213 		uint8_t		flags;
214 		uint8_t		tflags;
215 		uint32_t	_gra;
216 		uint32_t	_min;
217 		uint32_t	_max;
218 		uint32_t	_tra;
219 		uint32_t	_len;
220 		uint8_t		src_index;
221 		char		src[1];
222 	} __packed lr_dword;
223 	struct {
224 		uint8_t		typecode;
225 		uint16_t	length;
226 		uint8_t		type;
227 		uint8_t		flags;
228 		uint8_t		tflags;
229 		uint64_t	_gra;
230 		uint64_t	_min;
231 		uint64_t	_max;
232 		uint64_t	_tra;
233 		uint64_t	_len;
234 		uint8_t		src_index;
235 		char		src[1];
236 	} __packed lr_qword;
237 	struct {
238 		uint8_t		typecode;
239 		uint16_t	length;
240 		uint8_t		revid;
241 		uint8_t		type;
242 #define LR_GPIO_INT	0x00
243 #define LR_GPIO_IO	0x01
244 		uint16_t	flags;
245 		uint16_t	tflags;
246 #define LR_GPIO_SHR		(3L << 3)
247 #define LR_GPIO_POLARITY	(3L << 1)
248 #define  LR_GPIO_ACTHI		(0L << 1)
249 #define  LR_GPIO_ACTLO		(1L << 1)
250 #define  LR_GPIO_ACTBOTH	(2L << 1)
251 #define LR_GPIO_MODE		(1L << 0)
252 #define  LR_GPIO_LEVEL		(0L << 0)
253 #define  LR_GPIO_EDGE		(1L << 0)
254 		uint8_t		_ppi;
255 		uint16_t	_drs;
256 		uint16_t	_dbt;
257 		uint16_t	pin_off;
258 		uint8_t		residx;
259 		uint16_t	res_off;
260 		uint16_t	vd_off;
261 		uint16_t	vd_len;
262 	} __packed lr_gpio;
263 	struct {
264 		uint8_t		typecode;
265 		uint16_t	length;
266 		uint8_t		revid;
267 		uint8_t		residx;
268 		uint8_t		type;
269 #define LR_SERBUS_I2C	1
270 		uint8_t		flags;
271 		uint16_t	tflags;
272 		uint8_t		trevid;
273 		uint16_t	tlength;
274 		uint8_t		tdata[1];
275 	} __packed lr_serbus;
276 	struct {
277 		uint8_t		typecode;
278 		uint16_t	length;
279 		uint8_t		revid;
280 		uint8_t		residx;
281 		uint8_t		type;
282 		uint8_t		flags;
283 		uint16_t	tflags;
284 		uint8_t		trevid;
285 		uint16_t	tlength;
286 		uint32_t	_spe;
287 		uint16_t	_adr;
288 		uint8_t		vdata[1];
289 	} __packed lr_i2cbus;
290 	uint8_t		pad[64];
291 } __packed;
292 
293 #define AML_CRSTYPE(x)	((x)->hdr.typecode & 0x80 ? \
294 			    (x)->hdr.typecode : (x)->hdr.typecode >> 3)
295 #define AML_CRSLEN(x)	((x)->hdr.typecode & 0x80 ? \
296 			    3+(x)->hdr.length : 1+((x)->hdr.typecode & 0x7))
297 
298 int			aml_print_resource(union acpi_resource *, void *);
299 int			aml_parse_resource(struct aml_value *,
300 			    int (*)(int, union acpi_resource *, void *),
301 			    void *);
302 
303 #define ACPI_E_NOERROR   0x00
304 #define ACPI_E_BADVALUE  0x01
305 
306 #define AML_MAX_ARG	 7
307 #define AML_MAX_LOCAL	 8
308 
309 #define AML_WALK_PRE 0x00
310 #define AML_WALK_POST 0x01
311 
312 void			aml_walknodes(struct aml_node *, int,
313 			    int (*)(struct aml_node *, void *), void *);
314 
315 void			aml_postparse(void);
316 
317 void			aml_hashopcodes(void);
318 
319 void			aml_foreachpkg(struct aml_value *, int,
320 			    void (*fn)(struct aml_value *, void *), void *);
321 
322 const char		*aml_val_to_string(const struct aml_value *);
323 
324 void			aml_disasm(struct aml_scope *scope, int lvl,
325 			    void (*dbprintf)(void *, const char *, ...),
326 			    void *arg);
327 int			aml_getpci(struct aml_node *, int64_t *);
328 int			aml_evalhid(struct aml_node *, struct aml_value *);
329 
330 int			acpi_walkmem(int, const char *);
331 
332 #define aml_get8(p)    *(uint8_t *)(p)
333 #define aml_get16(p)   *(uint16_t *)(p)
334 #define aml_get32(p)   *(uint32_t *)(p)
335 #define aml_get64(p)   *(uint64_t *)(p)
336 
337 union amlpci_t {
338 	uint64_t addr;
339 	struct {
340 		uint16_t reg;
341 		uint16_t fun;
342 		uint8_t dev;
343 		uint8_t bus;
344 		uint16_t seg;
345 	};
346 };
347 int			aml_rdpciaddr(struct aml_node *pcidev,
348 			    union amlpci_t *);
349 
350 #ifndef SMALL_KERNEL
351 void			acpi_getdevlist(struct acpi_devlist_head *,
352 			    struct aml_node *, struct aml_value *, int);
353 #endif
354 void			aml_notify_dev(const char *, int);
355 
356 void			acpi_freedevlist(struct acpi_devlist_head *);
357 
358 void			acpi_glk_enter(void);
359 void			acpi_glk_leave(void);
360 
361 #endif /* __DEV_ACPI_DSDT_H__ */
362