1 /* $OpenBSD: dsdt.h,v 1.79 2021/03/10 21:49:55 patrick 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 void aml_walkroot(void); 55 void aml_walktree(struct aml_node *); 56 57 void aml_find_node(struct aml_node *, const char *, 58 int (*)(struct aml_node *, void *), void *); 59 int acpi_parse_aml(struct acpi_softc *, u_int8_t *, 60 uint32_t); 61 void aml_register_notify(struct aml_node *, const char *, 62 int (*)(struct aml_node *, int, void *), void *, 63 int); 64 void aml_register_regionspace(struct aml_node *, int, void *, 65 int (*)(void *, int, uint64_t, int, uint64_t *)); 66 67 int aml_evalnode(struct acpi_softc *, struct aml_node *, 68 int, struct aml_value *, struct aml_value *); 69 int aml_node_setval(struct acpi_softc *, struct aml_node *, 70 int64_t); 71 int aml_evalname(struct acpi_softc *, struct aml_node *, 72 const char *, int, struct aml_value *, 73 struct aml_value *); 74 int aml_evalinteger(struct acpi_softc *, struct aml_node *, 75 const char *, int, struct aml_value *, int64_t *); 76 77 void aml_create_defaultobjects(void); 78 79 const char *aml_nodename(struct aml_node *); 80 81 #define SRT_IRQ2 0x22 82 #define SRT_IRQ3 0x23 83 #define SRT_DMA 0x2A 84 #define SRT_STARTDEP0 0x30 85 #define SRT_STARTDEP1 0x31 86 #define SRT_ENDDEP 0x38 87 #define SRT_IOPORT 0x47 88 #define SRT_FIXEDPORT 0x4B 89 #define SRT_ENDTAG 0x79 90 91 #define SR_IRQ 0x04 92 #define SR_DMA 0x05 93 #define SR_STARTDEP 0x06 94 #define SR_ENDDEP 0x07 95 #define SR_IOPORT 0x08 96 #define SR_FIXEDPORT 0x09 97 #define SR_ENDTAG 0x0F 98 /* byte zero of small resources combines the tag above a length [1..7] */ 99 #define SR_TAG(tag,len) ((tag << 3) + (len)) 100 101 #define LR_MEM24 0x81 102 #define LR_GENREGISTER 0x82 103 #define LR_MEM32 0x85 104 #define LR_MEM32FIXED 0x86 105 #define LR_DWORD 0x87 106 #define LR_WORD 0x88 107 #define LR_EXTIRQ 0x89 108 #define LR_QWORD 0x8A 109 #define LR_GPIO 0x8C 110 #define LR_SERBUS 0x8E 111 112 #define __amlflagbit(v,s,l) 113 union acpi_resource { 114 struct { 115 uint8_t typecode; 116 uint16_t length; 117 } __packed hdr; 118 119 /* Small resource structures 120 * format of typecode is: tttttlll, t = type, l = length 121 */ 122 struct { 123 uint8_t typecode; 124 uint16_t irq_mask; 125 uint8_t irq_flags; 126 #define SR_IRQ_SHR (1L << 4) 127 #define SR_IRQ_POLARITY (1L << 3) 128 #define SR_IRQ_MODE (1L << 0) 129 } __packed sr_irq; 130 struct { 131 uint8_t typecode; 132 uint8_t channel; 133 uint8_t flags; 134 #define SR_DMA_TYP_MASK 0x3 135 #define SR_DMA_TYP_SHIFT 5 136 #define SR_DMA_BM (1L << 2) 137 #define SR_DMA_SIZE_MASK 0x3 138 #define SR_DMA_SIZE_SHIFT 0 139 } __packed sr_dma; 140 struct { 141 uint8_t typecode; 142 uint8_t flags; 143 #define SR_IOPORT_DEC (1L << 0) 144 uint16_t _min; 145 uint16_t _max; 146 uint8_t _aln; 147 uint8_t _len; 148 } __packed sr_ioport; 149 struct { 150 uint8_t typecode; 151 uint16_t _bas; 152 uint8_t _len; 153 } __packed sr_fioport; 154 155 /* Large resource structures */ 156 struct { 157 uint8_t typecode; 158 uint16_t length; 159 uint8_t _info; 160 uint16_t _min; 161 uint16_t _max; 162 uint16_t _aln; 163 uint16_t _len; 164 } __packed lr_m24; 165 struct { 166 uint8_t typecode; 167 uint16_t length; 168 uint8_t _info; 169 uint32_t _min; 170 uint32_t _max; 171 uint32_t _aln; 172 uint32_t _len; 173 } __packed lr_m32; 174 struct { 175 uint8_t typecode; 176 uint16_t length; 177 uint8_t _info; 178 uint32_t _bas; 179 uint32_t _len; 180 } __packed lr_m32fixed; 181 struct { 182 uint8_t typecode; 183 uint16_t length; 184 uint8_t flags; 185 #define LR_EXTIRQ_SHR (1L << 3) 186 #define LR_EXTIRQ_POLARITY (1L << 2) 187 #define LR_EXTIRQ_MODE (1L << 1) 188 uint8_t irq_count; 189 uint32_t irq[1]; 190 } __packed lr_extirq; 191 struct { 192 uint8_t typecode; 193 uint16_t length; 194 uint8_t type; 195 #define LR_TYPE_MEMORY 0 196 #define LR_TYPE_IO 1 197 #define LR_TYPE_BUS 2 198 uint8_t flags; 199 uint8_t tflags; 200 #define LR_MEMORY_TTP (1L << 5) 201 #define LR_IO_TTP (1L << 4) 202 uint16_t _gra; 203 uint16_t _min; 204 uint16_t _max; 205 uint16_t _tra; 206 uint16_t _len; 207 uint8_t src_index; 208 char src[1]; 209 } __packed lr_word; 210 struct { 211 uint8_t typecode; 212 uint16_t length; 213 uint8_t type; 214 uint8_t flags; 215 uint8_t tflags; 216 uint32_t _gra; 217 uint32_t _min; 218 uint32_t _max; 219 uint32_t _tra; 220 uint32_t _len; 221 uint8_t src_index; 222 char src[1]; 223 } __packed lr_dword; 224 struct { 225 uint8_t typecode; 226 uint16_t length; 227 uint8_t type; 228 uint8_t flags; 229 uint8_t tflags; 230 uint64_t _gra; 231 uint64_t _min; 232 uint64_t _max; 233 uint64_t _tra; 234 uint64_t _len; 235 uint8_t src_index; 236 char src[1]; 237 } __packed lr_qword; 238 struct { 239 uint8_t typecode; 240 uint16_t length; 241 uint8_t revid; 242 uint8_t type; 243 #define LR_GPIO_INT 0x00 244 #define LR_GPIO_IO 0x01 245 uint16_t flags; 246 uint16_t tflags; 247 #define LR_GPIO_SHR (3L << 3) 248 #define LR_GPIO_POLARITY (3L << 1) 249 #define LR_GPIO_ACTHI (0L << 1) 250 #define LR_GPIO_ACTLO (1L << 1) 251 #define LR_GPIO_ACTBOTH (2L << 1) 252 #define LR_GPIO_MODE (1L << 0) 253 #define LR_GPIO_LEVEL (0L << 0) 254 #define LR_GPIO_EDGE (1L << 0) 255 uint8_t _ppi; 256 uint16_t _drs; 257 uint16_t _dbt; 258 uint16_t pin_off; 259 uint8_t residx; 260 uint16_t res_off; 261 uint16_t vd_off; 262 uint16_t vd_len; 263 } __packed lr_gpio; 264 struct { 265 uint8_t typecode; 266 uint16_t length; 267 uint8_t revid; 268 uint8_t residx; 269 uint8_t type; 270 #define LR_SERBUS_I2C 1 271 uint8_t flags; 272 uint16_t tflags; 273 uint8_t trevid; 274 uint16_t tlength; 275 uint8_t tdata[1]; 276 } __packed lr_serbus; 277 struct { 278 uint8_t typecode; 279 uint16_t length; 280 uint8_t revid; 281 uint8_t residx; 282 uint8_t type; 283 uint8_t flags; 284 uint16_t tflags; 285 uint8_t trevid; 286 uint16_t tlength; 287 uint32_t _spe; 288 uint16_t _adr; 289 uint8_t vdata[1]; 290 } __packed lr_i2cbus; 291 uint8_t pad[64]; 292 } __packed; 293 294 #define AML_CRSTYPE(x) ((x)->hdr.typecode & 0x80 ? \ 295 (x)->hdr.typecode : (x)->hdr.typecode >> 3) 296 #define AML_CRSLEN(x) ((x)->hdr.typecode & 0x80 ? \ 297 3+(x)->hdr.length : 1+((x)->hdr.typecode & 0x7)) 298 299 int aml_print_resource(union acpi_resource *, void *); 300 int aml_parse_resource(struct aml_value *, 301 int (*)(int, union acpi_resource *, void *), 302 void *); 303 304 #define ACPI_E_NOERROR 0x00 305 #define ACPI_E_BADVALUE 0x01 306 307 #define AML_MAX_ARG 7 308 #define AML_MAX_LOCAL 8 309 310 #define AML_WALK_PRE 0x00 311 #define AML_WALK_POST 0x01 312 313 void aml_walknodes(struct aml_node *, int, 314 int (*)(struct aml_node *, void *), void *); 315 316 void aml_postparse(void); 317 318 void aml_hashopcodes(void); 319 320 void aml_foreachpkg(struct aml_value *, int, 321 void (*fn)(struct aml_value *, void *), void *); 322 323 const char *aml_val_to_string(const struct aml_value *); 324 325 void aml_disasm(struct aml_scope *scope, int lvl, 326 void (*dbprintf)(void *, const char *, ...), 327 void *arg); 328 int aml_getpci(struct aml_node *, int64_t *); 329 int aml_evalhid(struct aml_node *, struct aml_value *); 330 331 int acpi_walkmem(int, const char *); 332 333 #define aml_get8(p) *(uint8_t *)(p) 334 #define aml_get16(p) *(uint16_t *)(p) 335 #define aml_get32(p) *(uint32_t *)(p) 336 #define aml_get64(p) *(uint64_t *)(p) 337 338 union amlpci_t { 339 uint64_t addr; 340 struct { 341 uint16_t reg; 342 uint16_t fun; 343 uint8_t dev; 344 uint8_t bus; 345 uint16_t seg; 346 }; 347 }; 348 int aml_rdpciaddr(struct aml_node *pcidev, 349 union amlpci_t *); 350 351 #ifndef SMALL_KERNEL 352 void acpi_getdevlist(struct acpi_devlist_head *, 353 struct aml_node *, struct aml_value *, int); 354 #endif 355 void aml_notify_dev(const char *, int); 356 357 void acpi_freedevlist(struct acpi_devlist_head *); 358 359 void acpi_glk_enter(void); 360 void acpi_glk_leave(void); 361 362 /* https://docs.microsoft.com/en-us/windows-hardware/drivers/acpi/winacpi-osi */ 363 364 enum acpi_osi { 365 OSI_UNKNOWN = -1, 366 OSI_WIN_2000, 367 OSI_WIN_XP, 368 OSI_WIN_2003, 369 OSI_WIN_2003_SP1, 370 OSI_WIN_XP_SP0, 371 OSI_WIN_XP_SP1, 372 OSI_WIN_XP_SP2, 373 OSI_WIN_XP_SP3, 374 OSI_WIN_XP_SP4, 375 OSI_WIN_VISTA, 376 OSI_WIN_2008, 377 OSI_WIN_VISTA_SP1, 378 OSI_WIN_VISTA_SP2, 379 OSI_WIN_7, 380 OSI_WIN_8, 381 OSI_WIN_8_1, 382 OSI_WIN_10, 383 OSI_WIN_10_1607, 384 OSI_WIN_10_1703, 385 OSI_WIN_10_1709, 386 OSI_WIN_10_1803, 387 OSI_WIN_10_1809, 388 OSI_WIN_10_1903, 389 OSI_WIN_10_2004, 390 }; 391 392 #define AML_VALID_OSI \ 393 "Windows 2000", \ 394 "Windows 2001", \ 395 "Windows 2001.1", \ 396 "Windows 2001.1 SP1", \ 397 "Windows 2001 SP0", \ 398 "Windows 2001 SP1", \ 399 "Windows 2001 SP2", \ 400 "Windows 2001 SP3", \ 401 "Windows 2001 SP4", \ 402 "Windows 2006", \ 403 "Windows 2006.1", \ 404 "Windows 2006 SP1", \ 405 "Windows 2006 SP2", \ 406 "Windows 2009", \ 407 "Windows 2012", \ 408 "Windows 2013", \ 409 "Windows 2015", \ 410 "Windows 2016", \ 411 "Windows 2017", \ 412 "Windows 2017.2", \ 413 "Windows 2018", \ 414 "Windows 2018.2", \ 415 "Windows 2019", \ 416 "Windows 2020" 417 418 extern enum acpi_osi acpi_max_osi; /* most recent Win version FW knows */ 419 420 #endif /* __DEV_ACPI_DSDT_H__ */ 421