1 /* $OpenBSD: dsdt.h,v 1.59 2011/06/03 03:54:19 jordan 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 *, int); 53 void aml_walkroot(void); 54 void aml_walktree(struct aml_node *); 55 56 int 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_evalname(struct acpi_softc *, struct aml_node *, 67 const char *, int, struct aml_value *, 68 struct aml_value *); 69 int aml_evalinteger(struct acpi_softc *, struct aml_node *, 70 const char *, int, struct aml_value *, int64_t *); 71 72 void aml_create_defaultobjects(void); 73 74 const char *aml_nodename(struct aml_node *); 75 76 #define SRT_IRQ2 0x22 77 #define SRT_IRQ3 0x23 78 #define SRT_DMA 0x2A 79 #define SRT_STARTDEP0 0x30 80 #define SRT_STARTDEP1 0x31 81 #define SRT_ENDDEP 0x38 82 #define SRT_IOPORT 0x47 83 #define SRT_FIXEDPORT 0x4B 84 #define SRT_ENDTAG 0x78 85 86 #define SR_IRQ 0x04 87 #define SR_DMA 0x05 88 #define SR_STARTDEP 0x06 89 #define SR_ENDDEP 0x07 90 #define SR_IOPORT 0x08 91 #define SR_FIXEDPORT 0x09 92 #define SR_ENDTAG 0x0F 93 94 #define LR_24BIT 0x81 95 #define LR_GENREGISTER 0x82 96 #define LR_32BIT 0x85 97 #define LR_32BITFIXED 0x86 98 #define LR_DWORD 0x87 99 #define LR_WORD 0x88 100 #define LR_EXTIRQ 0x89 101 #define LR_QWORD 0x8A 102 103 #define __amlflagbit(v,s,l) 104 union acpi_resource { 105 struct { 106 uint8_t typecode; 107 uint16_t length; 108 } __packed hdr; 109 110 /* Small resource structures 111 * format of typecode is: tttttlll, t = type, l = length 112 */ 113 struct { 114 uint8_t typecode; 115 uint16_t irq_mask; 116 uint8_t irq_flags; 117 #define SR_IRQ_SHR (1L << 4) 118 #define SR_IRQ_POLARITY (1L << 3) 119 #define SR_IRQ_MODE (1L << 0) 120 } __packed sr_irq; 121 struct { 122 uint8_t typecode; 123 uint8_t channel; 124 uint8_t flags; 125 #define SR_DMA_TYP_MASK 0x3 126 #define SR_DMA_TYP_SHIFT 5 127 #define SR_DMA_BM (1L << 2) 128 #define SR_DMA_SIZE_MASK 0x3 129 #define SR_DMA_SIZE_SHIFT 0 130 } __packed sr_dma; 131 struct { 132 uint8_t typecode; 133 uint8_t flags; 134 #define SR_IOPORT_DEC (1L << 0) 135 uint16_t _min; 136 uint16_t _max; 137 uint8_t _aln; 138 uint8_t _len; 139 } __packed sr_ioport; 140 struct { 141 uint8_t typecode; 142 uint16_t _bas; 143 uint8_t _len; 144 } __packed sr_fioport; 145 146 /* Large resource structures */ 147 struct { 148 uint8_t typecode; 149 uint16_t length; 150 uint8_t _info; 151 uint16_t _min; 152 uint16_t _max; 153 uint16_t _aln; 154 uint16_t _len; 155 } __packed lr_m24; 156 struct { 157 uint8_t typecode; 158 uint16_t length; 159 uint8_t _info; 160 uint32_t _min; 161 uint32_t _max; 162 uint32_t _aln; 163 uint32_t _len; 164 } __packed lr_m32; 165 struct { 166 uint8_t typecode; 167 uint16_t length; 168 uint8_t flags; 169 uint8_t irq_count; 170 uint32_t irq[1]; 171 } __packed lr_extirq; 172 struct { 173 uint8_t typecode; 174 uint16_t length; 175 uint8_t type; 176 uint8_t flags; 177 uint8_t tflags; 178 uint16_t _gra; 179 uint16_t _min; 180 uint16_t _max; 181 uint16_t _tra; 182 uint16_t _len; 183 uint8_t src_index; 184 char src[1]; 185 } __packed lr_word; 186 struct { 187 uint8_t typecode; 188 uint16_t length; 189 uint8_t type; 190 uint8_t flags; 191 uint8_t tflags; 192 uint32_t _gra; 193 uint32_t _min; 194 uint32_t _max; 195 uint32_t _tra; 196 uint32_t _len; 197 uint8_t src_index; 198 char src[1]; 199 } __packed lr_dword; 200 struct { 201 uint8_t typecode; 202 uint16_t length; 203 uint8_t type; 204 uint8_t flags; 205 uint8_t tflags; 206 uint64_t _gra; 207 uint64_t _min; 208 uint64_t _max; 209 uint64_t _tra; 210 uint64_t _len; 211 uint8_t src_index; 212 char src[1]; 213 } __packed lr_qword; 214 uint8_t pad[64]; 215 } __packed; 216 217 #define AML_CRSTYPE(x) ((x)->hdr.typecode & 0x80 ? \ 218 (x)->hdr.typecode : (x)->hdr.typecode >> 3) 219 #define AML_CRSLEN(x) ((x)->hdr.typecode & 0x80 ? \ 220 3+(x)->hdr.length : 1+((x)->hdr.typecode & 0x7)) 221 222 int aml_print_resource(union acpi_resource *, void *); 223 int aml_parse_resource(struct aml_value *, 224 int (*)(union acpi_resource *, void *), void *); 225 226 #define ACPI_E_NOERROR 0x00 227 #define ACPI_E_BADVALUE 0x01 228 229 #define AML_MAX_ARG 7 230 #define AML_MAX_LOCAL 8 231 232 #define AML_WALK_PRE 0x00 233 #define AML_WALK_POST 0x01 234 235 void aml_walknodes(struct aml_node *, int, 236 int (*)(struct aml_node *, void *), void *); 237 238 void aml_postparse(void); 239 240 void aml_hashopcodes(void); 241 242 void aml_foreachpkg(struct aml_value *, int, 243 void (*fn)(struct aml_value *, void *), void *); 244 245 const char *aml_val_to_string(const struct aml_value *); 246 247 void aml_disasm(struct aml_scope *scope, int lvl, 248 void (*dbprintf)(void *, const char *, ...), 249 void *arg); 250 int aml_getpci(struct aml_node *, int64_t *); 251 int aml_evalhid(struct aml_node *, struct aml_value *); 252 253 int acpi_walkmem(int, const char *); 254 255 #define aml_get8(p) *(uint8_t *)(p) 256 #define aml_get16(p) *(uint16_t *)(p) 257 #define aml_get32(p) *(uint32_t *)(p) 258 #define aml_get64(p) *(uint64_t *)(p) 259 260 union amlpci_t { 261 uint64_t addr; 262 struct { 263 uint16_t reg; 264 uint16_t fun; 265 uint16_t dev; 266 uint16_t bus; 267 }; 268 }; 269 int aml_rdpciaddr(struct aml_node *pcidev, 270 union amlpci_t *); 271 272 #ifndef SMALL_KERNEL 273 void acpi_getdevlist(struct acpi_devlist_head *, 274 struct aml_node *, struct aml_value *, int); 275 void aml_notify_dev(const char *, int); 276 #endif 277 278 void acpi_freedevlist(struct acpi_devlist_head *); 279 280 #endif /* __DEV_ACPI_DSDT_H__ */ 281