1 /* $OpenBSD: amltypes.h,v 1.30 2008/06/08 02:51:55 deraadt 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 #define AML_STATIC 0x8000 161 162 /* Defined types for ObjectType() */ 163 enum aml_objecttype { 164 AML_OBJTYPE_UNINITIALIZED = 0, 165 AML_OBJTYPE_INTEGER, 166 AML_OBJTYPE_STRING, 167 AML_OBJTYPE_BUFFER, 168 AML_OBJTYPE_PACKAGE, 169 AML_OBJTYPE_FIELDUNIT, 170 AML_OBJTYPE_DEVICE, 171 AML_OBJTYPE_EVENT, 172 AML_OBJTYPE_METHOD, 173 AML_OBJTYPE_MUTEX, 174 AML_OBJTYPE_OPREGION, 175 AML_OBJTYPE_POWERRSRC, 176 AML_OBJTYPE_PROCESSOR, 177 AML_OBJTYPE_THERMZONE, 178 AML_OBJTYPE_BUFFERFIELD, 179 AML_OBJTYPE_DDBHANDLE, 180 AML_OBJTYPE_DEBUGOBJ, 181 182 AML_OBJTYPE_NAMEREF = 0x100, 183 AML_OBJTYPE_OBJREF, 184 AML_OBJTYPE_SCOPE, 185 AML_OBJTYPE_NOTARGET, 186 AML_OBJTYPE_STATICINT = AML_OBJTYPE_INTEGER|AML_STATIC, 187 }; 188 189 /* AML Opcode Arguments */ 190 #define AML_ARG_INTEGER 'i' 191 #define AML_ARG_BYTE 'b' 192 #define AML_ARG_WORD 'w' 193 #define AML_ARG_DWORD 'd' 194 #define AML_ARG_QWORD 'q' 195 #define AML_ARG_IMPBYTE '!' 196 #define AML_ARG_OBJLEN 'p' 197 #define AML_ARG_STRING 'a' 198 #define AML_ARG_BYTELIST 'B' 199 #define AML_ARG_REVISION 'R' 200 201 #define AML_ARG_METHOD 'M' 202 #define AML_ARG_NAMESTRING 'N' 203 #define AML_ARG_NAMEREF 'n' 204 #define AML_ARG_FIELDLIST 'F' 205 #define AML_ARG_FLAG 'f' 206 207 #define AML_ARG_DATAOBJLIST 'O' 208 #define AML_ARG_DATAOBJ 'o' 209 210 #define AML_ARG_SIMPLENAME 's' 211 #define AML_ARG_SUPERNAME 'S' 212 213 #define AML_ARG_TERMOBJLIST 'T' 214 #define AML_ARG_TERMOBJ 't' 215 216 #define AML_ARG_IFELSE 'I' 217 #define AML_ARG_WHILE 'W' 218 #define AML_ARG_BUFFER 'B' 219 #define AML_ARG_SEARCHNAME 'n' 220 #define AML_ARG_CREATENAME 'N' 221 #define AML_ARG_STKARG 'A' 222 #define AML_ARG_STKLOCAL 'L' 223 #define AML_ARG_DEBUG 'D' 224 #define AML_ARG_CONST 'c' 225 #define AML_ARG_TARGET 'r' 226 227 #define AML_METHOD_ARGCOUNT(v) (((v) >> 0) & 0x7) 228 #define AML_METHOD_SERIALIZED(v) (((v) >> 3) & 0x1) 229 #define AML_METHOD_SYNCLEVEL(v) (((v) >> 4) & 0xF) 230 231 #define AML_FIELD_ACCESSMASK 0x0F 232 #define AML_FIELD_SETATTR(f,t,a) (((f) & 0xF0) | ((t) & 0xF) | ((a)<<8)) 233 #define AML_FIELD_ACCESS(v) (((v) >> 0) & 0xF) 234 # define AML_FIELD_ANYACC 0x0 235 # define AML_FIELD_BYTEACC 0x1 236 # define AML_FIELD_WORDACC 0x2 237 # define AML_FIELD_DWORDACC 0x3 238 # define AML_FIELD_QWORDACC 0x4 239 # define AML_FIELD_BUFFERACC 0x5 240 #define AML_FIELD_LOCK(v) (((v) >> 4) & 0x1) 241 # define AML_FIELD_LOCK_OFF 0x0 242 # define AML_FIELD_LOCK_ON 0x1 243 #define AML_FIELD_UPDATE(v) (((v) >> 5) & 0x3) 244 # define AML_FIELD_PRESERVE 0x0 245 # define AML_FIELD_WRITEASONES 0x1 246 # define AML_FIELD_WRITEASZEROES 0x2 247 #define AML_FIELD_ATTR(v) ((v) >> 8) 248 #define AML_FIELD_RESERVED 0x00 249 /* XXX fix this name */ 250 #define AML_FIELD_ATTR__ 0x01 251 252 struct aml_scope; 253 struct aml_node; 254 255 struct aml_waitq { 256 struct aml_scope *scope; 257 SIMPLEQ_ENTRY(aml_waitq) link; 258 }; 259 SIMPLEQ_HEAD(aml_waitq_head, aml_waitq); 260 261 /* AML Object Value */ 262 struct aml_value { 263 int type; 264 int length; 265 int refcnt; 266 int stack; 267 struct aml_node *node; 268 union { 269 int64_t vinteger; 270 char *vstring; 271 u_int8_t *vbuffer; 272 struct aml_value **vpackage; 273 struct { 274 u_int8_t iospace; 275 u_int64_t iobase; 276 u_int32_t iolen; 277 int flag; 278 } vopregion; 279 struct { 280 int flags; 281 u_int8_t *start; 282 u_int8_t *end; 283 struct aml_value *(*fneval)(struct aml_scope *, struct aml_value *); 284 u_int8_t *base; 285 } vmethod; 286 struct { 287 u_int16_t type; 288 u_int16_t flags; 289 u_int32_t bitpos; 290 u_int32_t bitlen; 291 struct aml_value *ref1; 292 struct aml_value *ref2; 293 int ref3; 294 } vfield; 295 struct { 296 u_int8_t proc_id; 297 u_int32_t proc_addr; 298 u_int8_t proc_len; 299 } vprocessor; 300 struct { 301 int type; 302 int index; 303 struct aml_value *ref; 304 } vobjref; 305 struct { 306 u_int8_t pwr_level; 307 u_int16_t pwr_order; 308 } vpowerrsrc; 309 struct acpi_mutex *vmutex; 310 struct { 311 u_int8_t *name; 312 struct aml_node *node; 313 } vnameref; 314 struct { 315 int synclvl; 316 int savelvl; 317 int count; 318 char ownername[5]; 319 struct aml_scope *owner; 320 struct aml_waitq_head waiters; 321 } Vmutex; 322 struct { 323 int state; 324 struct aml_waitq_head waiters; 325 } Vevent; 326 } _; 327 }; 328 329 #define v_nameref _.vbuffer 330 #define v_objref _.vobjref 331 #define v_integer _.vinteger 332 #define v_string _.vstring 333 #define v_buffer _.vbuffer 334 #define v_package _.vpackage 335 #define v_field _.vfield 336 #define v_opregion _.vopregion 337 #define v_method _.vmethod 338 #define v_processor _.vprocessor 339 #define v_powerrsrc _.vpowerrsrc 340 #define v_mutex _.vmutex 341 #define v_mtx _.Vmutex 342 #define v_evt _.Vevent 343 344 #define xaml_intval(v) ((v)->v_integer) 345 #define aml_strlen(v) ((v)->length) 346 #define aml_strval(v) ((v)->v_string ? (v)->v_string : "bad string") 347 #define aml_buflen(v) ((v)->length) 348 #define aml_bufval(v) ((v)->v_buffer) 349 #define aml_pkglen(v) ((v)->length) 350 #define aml_pkgval(v,i) (&(v)->v_package[(i)]) 351 352 struct aml_node { 353 struct aml_node *parent; 354 struct aml_node *child; 355 struct aml_node *sibling; 356 357 char name[5]; 358 u_int16_t opcode; 359 u_int8_t *start; 360 u_int8_t *end; 361 // const char *name; 362 // const char *mnem; 363 364 struct aml_value *value; 365 366 int depth; 367 }; 368 369 #define aml_bitmask(n) (1L << ((n) & 0x7)) 370 #define aml_bitpos(n) ((n)&0x7) 371 #define aml_bytepos(n) ((n)>>3) 372 #define aml_bytelen(n) (((n)+7)>>3) 373 #define aml_bytealigned(x) !((x)&0x7) 374 375 #endif /* __DEV_ACPI_AMLTYPES_H__ */ 376