xref: /openbsd-src/sys/dev/acpi/amltypes.h (revision 43003dfe3ad45d1698bed8a37f2b0f5b14f20d4f)
1 /* $OpenBSD: amltypes.h,v 1.33 2009/07/17 21:44:48 jordan Exp $ */
2 /*
3  * Copyright (c) 2005 Jordan Hargrave <jordan@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_AMLTYPES_H__
19 #define __DEV_ACPI_AMLTYPES_H__
20 
21 /* AML Opcodes */
22 #define AMLOP_ZERO		0x00
23 #define AMLOP_ONE		0x01
24 #define AMLOP_ALIAS		0x06
25 #define AMLOP_NAME		0x08
26 #define AMLOP_BYTEPREFIX	0x0A
27 #define AMLOP_WORDPREFIX	0x0B
28 #define AMLOP_DWORDPREFIX	0x0C
29 #define AMLOP_STRINGPREFIX	0x0D
30 #define AMLOP_QWORDPREFIX	0x0E
31 #define AMLOP_SCOPE		0x10
32 #define AMLOP_BUFFER		0x11
33 #define AMLOP_PACKAGE		0x12
34 #define AMLOP_VARPACKAGE	0x13
35 #define AMLOP_METHOD		0x14
36 #define AMLOP_DUALNAMEPREFIX	0x2E
37 #define AMLOP_MULTINAMEPREFIX	0x2F
38 #define AMLOP_EXTPREFIX		0x5B
39 #define AMLOP_MUTEX		0x5B01
40 #define AMLOP_EVENT		0x5B02
41 #define AMLOP_CONDREFOF		0x5B12
42 #define AMLOP_CREATEFIELD	0x5B13
43 #define AMLOP_LOADTABLE		0x5B1F
44 #define AMLOP_LOAD		0x5B20
45 #define AMLOP_STALL		0x5B21
46 #define AMLOP_SLEEP		0x5B22
47 #define AMLOP_ACQUIRE		0x5B23
48 #define AMLOP_SIGNAL		0x5B24
49 #define AMLOP_WAIT		0x5B25
50 #define AMLOP_RESET		0x5B26
51 #define AMLOP_RELEASE		0x5B27
52 #define AMLOP_FROMBCD		0x5B28
53 #define AMLOP_TOBCD		0x5B29
54 #define AMLOP_UNLOAD		0x5B2A
55 #define AMLOP_REVISION		0x5B30
56 #define AMLOP_DEBUG		0x5B31
57 #define AMLOP_FATAL		0x5B32
58 #define AMLOP_TIMER		0x5B33
59 #define AMLOP_OPREGION		0x5B80
60 #define AMLOP_FIELD		0x5B81
61 #define AMLOP_DEVICE		0x5B82
62 #define AMLOP_PROCESSOR		0x5B83
63 #define AMLOP_POWERRSRC		0x5B84
64 #define AMLOP_THERMALZONE	0x5B85
65 #define AMLOP_INDEXFIELD	0x5B86
66 #define AMLOP_BANKFIELD		0x5B87
67 #define AMLOP_DATAREGION	0x5B88
68 #define AMLOP_ROOTCHAR		0x5C
69 #define AMLOP_PARENTPREFIX	0x5E
70 #define AMLOP_NAMECHAR		0x5F
71 #define AMLOP_LOCAL0		0x60
72 #define AMLOP_LOCAL1		0x61
73 #define AMLOP_LOCAL2		0x62
74 #define AMLOP_LOCAL3		0x63
75 #define AMLOP_LOCAL4		0x64
76 #define AMLOP_LOCAL5		0x65
77 #define AMLOP_LOCAL6		0x66
78 #define AMLOP_LOCAL7		0x67
79 #define AMLOP_ARG0		0x68
80 #define AMLOP_ARG1		0x69
81 #define AMLOP_ARG2		0x6A
82 #define AMLOP_ARG3		0x6B
83 #define AMLOP_ARG4		0x6C
84 #define AMLOP_ARG5		0x6D
85 #define AMLOP_ARG6		0x6E
86 #define AMLOP_STORE		0x70
87 #define AMLOP_REFOF		0x71
88 #define AMLOP_ADD		0x72
89 #define AMLOP_CONCAT		0x73
90 #define AMLOP_SUBTRACT		0x74
91 #define AMLOP_INCREMENT		0x75
92 #define AMLOP_DECREMENT		0x76
93 #define AMLOP_MULTIPLY		0x77
94 #define AMLOP_DIVIDE		0x78
95 #define AMLOP_SHL		0x79
96 #define AMLOP_SHR		0x7A
97 #define AMLOP_AND		0x7B
98 #define AMLOP_NAND		0x7C
99 #define AMLOP_OR		0x7D
100 #define AMLOP_NOR		0x7E
101 #define AMLOP_XOR		0x7F
102 #define AMLOP_NOT		0x80
103 #define AMLOP_FINDSETLEFTBIT	0x81
104 #define AMLOP_FINDSETRIGHTBIT	0x82
105 #define AMLOP_DEREFOF		0x83
106 #define AMLOP_CONCATRES		0x84
107 #define AMLOP_MOD		0x85
108 #define AMLOP_NOTIFY		0x86
109 #define AMLOP_SIZEOF		0x87
110 #define AMLOP_INDEX		0x88
111 #define AMLOP_DEREFOF		0x83
112 #define AMLOP_MATCH		0x89
113 #define AMLOP_CREATEDWORDFIELD	0x8A
114 #define AMLOP_CREATEWORDFIELD	0x8B
115 #define AMLOP_CREATEBYTEFIELD	0x8C
116 #define AMLOP_CREATEBITFIELD	0x8D
117 #define AMLOP_OBJECTTYPE	0x8E
118 #define AMLOP_CREATEQWORDFIELD	0x8F
119 #define AMLOP_LAND		0x90
120 #define AMLOP_LOR		0x91
121 #define AMLOP_LNOT		0x92
122 #define AMLOP_LNOTEQUAL		0x9293
123 #define AMLOP_LLESSEQUAL	0x9294
124 #define AMLOP_LGREATEREQUAL	0x9295
125 #define AMLOP_LEQUAL		0x93
126 #define AMLOP_LGREATER		0x94
127 #define AMLOP_LLESS		0x95
128 #define AMLOP_TOBUFFER		0x96
129 #define AMLOP_TODECSTRING	0x97
130 #define AMLOP_TOHEXSTRING	0x98
131 #define AMLOP_TOINTEGER		0x99
132 #define AMLOP_TOSTRING		0x9C
133 #define AMLOP_COPYOBJECT	0x9D
134 #define AMLOP_MID		0x9E
135 #define AMLOP_CONTINUE		0x9F
136 #define AMLOP_IF		0xA0
137 #define AMLOP_ELSE		0xA1
138 #define AMLOP_WHILE		0xA2
139 #define AMLOP_NOP		0xA3
140 #define AMLOP_RETURN		0xA4
141 #define AMLOP_BREAK		0xA5
142 #define AMLOP_BREAKPOINT	0xCC
143 #define AMLOP_ONES		0xFF
144 
145 #define AMLOP_FIELDUNIT		0xFE00
146 #define AML_ANYINT		0xFF00
147 
148 /*
149  * Comparison types for Match()
150  *
151  *  true,==,<=,<,>=,>
152  */
153 #define AML_MATCH_TR		0
154 #define AML_MATCH_EQ		1
155 #define AML_MATCH_LE		2
156 #define AML_MATCH_LT		3
157 #define AML_MATCH_GE		4
158 #define AML_MATCH_GT		5
159 
160 /* Defined types for ObjectType() */
161 enum aml_objecttype {
162 	AML_OBJTYPE_UNINITIALIZED = 0,
163 	AML_OBJTYPE_INTEGER,
164 	AML_OBJTYPE_STRING,
165 	AML_OBJTYPE_BUFFER,
166 	AML_OBJTYPE_PACKAGE,
167 	AML_OBJTYPE_FIELDUNIT,
168 	AML_OBJTYPE_DEVICE,
169 	AML_OBJTYPE_EVENT,
170 	AML_OBJTYPE_METHOD,
171 	AML_OBJTYPE_MUTEX,
172 	AML_OBJTYPE_OPREGION,
173 	AML_OBJTYPE_POWERRSRC,
174 	AML_OBJTYPE_PROCESSOR,
175 	AML_OBJTYPE_THERMZONE,
176 	AML_OBJTYPE_BUFFERFIELD,
177 	AML_OBJTYPE_DDBHANDLE,
178 	AML_OBJTYPE_DEBUGOBJ,
179 
180 	AML_OBJTYPE_NAMEREF = 0x100,
181 	AML_OBJTYPE_OBJREF,
182 	AML_OBJTYPE_SCOPE,
183 	AML_OBJTYPE_NOTARGET,
184 	AML_OBJTYPE_HEXSTRING,
185 	AML_OBJTYPE_DECSTRING,
186 };
187 
188 /* AML Opcode Arguments */
189 #define AML_ARG_INTEGER		'i'
190 #define AML_ARG_BYTE		'b'
191 #define AML_ARG_WORD		'w'
192 #define AML_ARG_DWORD		'd'
193 #define AML_ARG_QWORD		'q'
194 #define AML_ARG_IMPBYTE		'!'
195 #define AML_ARG_OBJLEN		'p'
196 #define AML_ARG_STRING		'a'
197 #define AML_ARG_BYTELIST	'B'
198 #define AML_ARG_REVISION	'R'
199 
200 #define AML_ARG_METHOD		'M'
201 #define AML_ARG_NAMESTRING	'N'
202 #define AML_ARG_NAMEREF		'n'
203 #define AML_ARG_FIELDLIST	'F'
204 #define AML_ARG_FLAG		'f'
205 
206 #define AML_ARG_DATAOBJLIST	'O'
207 #define AML_ARG_DATAOBJ		'o'
208 
209 #define AML_ARG_SIMPLENAME	's'
210 #define AML_ARG_SUPERNAME	'S'
211 
212 #define AML_ARG_TERMOBJLIST	'T'
213 #define AML_ARG_TERMOBJ		't'
214 
215 #define AML_ARG_IFELSE          'I'
216 #define AML_ARG_BUFFER          'B'
217 #define AML_ARG_SEARCHNAME      'n'
218 #define AML_ARG_CREATENAME      'N'
219 #define AML_ARG_STKARG          'A'
220 #define AML_ARG_STKLOCAL        'L'
221 #define AML_ARG_DEBUG           'D'
222 #define AML_ARG_CONST           'c'
223 #define AML_ARG_TARGET          'r'
224 
225 #define AML_METHOD_ARGCOUNT(v)	 (((v) >> 0) & 0x7)
226 #define AML_METHOD_SERIALIZED(v) (((v) >> 3) & 0x1)
227 #define AML_METHOD_SYNCLEVEL(v)	 (((v) >> 4) & 0xF)
228 
229 #define AML_FIELD_ACCESSMASK	0x0F
230 #define AML_FIELD_SETATTR(f,t,a) (((f) & 0xF0) | ((t) & 0xF) | ((a)<<8))
231 #define AML_FIELD_ACCESS(v)	(((v) >> 0) & 0xF)
232 # define AML_FIELD_ANYACC	0x0
233 # define AML_FIELD_BYTEACC	0x1
234 # define AML_FIELD_WORDACC	0x2
235 # define AML_FIELD_DWORDACC	0x3
236 # define AML_FIELD_QWORDACC	0x4
237 # define AML_FIELD_BUFFERACC	0x5
238 #define AML_FIELD_LOCK(v)	(((v) >> 4) & 0x1)
239 # define AML_FIELD_LOCK_OFF	0x0
240 # define AML_FIELD_LOCK_ON	0x1
241 #define AML_FIELD_UPDATE(v)	(((v) >> 5) & 0x3)
242 # define AML_FIELD_PRESERVE	0x0
243 # define AML_FIELD_WRITEASONES	0x1
244 # define AML_FIELD_WRITEASZEROES 0x2
245 #define AML_FIELD_ATTR(v)	((v) >> 8)
246 #define AML_FIELD_RESERVED	0x00
247 /* XXX fix this name */
248 #define AML_FIELD_ATTR__		0x01
249 
250 struct aml_scope;
251 struct aml_node;
252 
253 struct aml_waitq {
254 	struct aml_scope          *scope;
255 	SIMPLEQ_ENTRY(aml_waitq)   link;
256 };
257 SIMPLEQ_HEAD(aml_waitq_head, aml_waitq);
258 
259 /* AML Object Value */
260 struct aml_value {
261 	int	type;
262 	int	length;
263 	int	refcnt;
264 	int	stack;
265 	struct aml_node *node;
266 	union {
267 		int64_t		vinteger;
268 		char		*vstring;
269 		u_int8_t	*vbuffer;
270 		struct aml_value **vpackage;
271 		struct {
272 			u_int8_t	iospace;
273 			u_int64_t	iobase;
274 			u_int32_t	iolen;
275 			int		flag;
276 		} vopregion;
277 		struct {
278 			int		flags;
279 			u_int8_t	*start;
280 			u_int8_t	*end;
281 			struct aml_value *(*fneval)(struct aml_scope *, struct aml_value *);
282 			u_int8_t        *base;
283 		} vmethod;
284 		struct {
285 			u_int16_t	 type;
286 			u_int16_t	 flags;
287 			u_int32_t	 bitpos;
288 			u_int32_t	 bitlen;
289 			struct aml_value *ref1;
290 			struct aml_value *ref2;
291 			int		 ref3;
292 		} vfield;
293 		struct {
294 			u_int8_t	proc_id;
295 			u_int32_t	proc_addr;
296 			u_int8_t	proc_len;
297 		} vprocessor;
298 		struct {
299 			int		type;
300 			int		index;
301 			struct aml_value *ref;
302 		} vobjref;
303 		struct {
304 			u_int8_t	pwr_level;
305 			u_int16_t	pwr_order;
306 		} vpowerrsrc;
307 		struct acpi_mutex	*vmutex;
308 		struct {
309 			u_int8_t         *name;
310 			struct aml_node  *node;
311 		} vnameref;
312 		struct {
313 			int               synclvl;
314 			int               savelvl;
315 			int               count;
316 		  	char              ownername[5];
317 			struct aml_scope *owner;
318 			struct aml_waitq_head    waiters;
319 		} Vmutex;
320 		struct {
321 			int               state;
322 			struct aml_waitq_head    waiters;
323 		} Vevent;
324 	} _;
325 };
326 
327 #define v_nameref		_.vbuffer
328 #define v_objref		_.vobjref
329 #define v_integer		_.vinteger
330 #define v_string		_.vstring
331 #define v_buffer		_.vbuffer
332 #define v_package		_.vpackage
333 #define v_field			_.vfield
334 #define v_opregion		_.vopregion
335 #define v_method		_.vmethod
336 #define v_processor		_.vprocessor
337 #define v_powerrsrc		_.vpowerrsrc
338 #define v_mutex			_.vmutex
339 #define v_mtx                   _.Vmutex
340 #define v_evt                   _.Vevent
341 
342 #define xaml_intval(v)		((v)->v_integer)
343 #define aml_strlen(v)		((v)->length)
344 #define aml_strval(v)		((v)->v_string ? (v)->v_string : "bad string")
345 #define aml_buflen(v)		((v)->length)
346 #define aml_bufval(v)		((v)->v_buffer)
347 #define aml_pkglen(v)		((v)->length)
348 #define aml_pkgval(v,i)		(&(v)->v_package[(i)])
349 
350 struct aml_node {
351 	struct aml_node *parent;
352 	struct aml_node *child;
353 	struct aml_node *sibling;
354 
355 	char		name[5];
356 	u_int16_t	opcode;
357 	u_int8_t	*start;
358 	u_int8_t	*end;
359   //	const char	*name;
360   //	const char	*mnem;
361 
362 	struct aml_value *value;
363 
364 	int		depth;
365 };
366 
367 #define aml_bitmask(n)		(1L << ((n) & 0x7))
368 #define aml_bitpos(n)		((n)&0x7)
369 #define aml_bytepos(n)		((n)>>3)
370 #define aml_bytelen(n)		(((n)+7)>>3)
371 #define aml_bytealigned(x)	!((x)&0x7)
372 
373 #endif /* __DEV_ACPI_AMLTYPES_H__ */
374