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