xref: /openbsd-src/sys/dev/acpi/dsdt.h (revision 2b0358df1d88d06ef4139321dd05bd5e05d91eaf)
1 /* $OpenBSD: dsdt.h,v 1.43 2009/03/10 20:36:10 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_vallist {
22 	struct aml_value *obj;
23 	int nobj;
24 	struct aml_vallist *next;
25 };
26 
27 struct aml_scope {
28 	struct acpi_softc	*sc;
29 	uint8_t			*pos;
30 	uint8_t			*end;
31 	struct aml_node		*node;
32 	struct aml_vallist	*tmpvals;
33 	struct aml_scope	*parent;
34 	struct aml_value	*locals;
35 	struct aml_value	*args;
36 	int			nargs;
37 	int			flags;
38 	struct aml_value	*retv;
39 	uint8_t			*start;
40 	int			type;
41 };
42 
43 
44 struct aml_opcode {
45 	u_int32_t		opcode;
46 	const char		*mnem;
47 	const char		*args;
48 };
49 
50 const char		*aml_eisaid(u_int32_t);
51 const char		*aml_mnem(int, uint8_t *);
52 int64_t			aml_val2int(struct aml_value *);
53 struct aml_node		*aml_searchname(struct aml_node *, const void *);
54 struct aml_node		*aml_searchrel(struct aml_node *, const void *);
55 
56 struct aml_value 	*aml_getstack(struct aml_scope *, int);
57 struct aml_value	*aml_allocint(uint64_t);
58 struct aml_value	*aml_allocstr(const char *);
59 struct aml_value	*aml_allocvalue(int, int64_t, const void *);
60 void			aml_freevalue(struct aml_value *);
61 void			aml_notify(struct aml_node *, int);
62 void			aml_notify_dev(const char *, int);
63 void			aml_showvalue(struct aml_value *, int);
64 void			aml_walkroot(void);
65 void			aml_walktree(struct aml_node *);
66 
67 int			aml_find_node(struct aml_node *, const char *,
68 			    int (*)(struct aml_node *, void *), void *);
69 int			acpi_parse_aml(struct acpi_softc *, u_int8_t *,
70 			    u_int32_t);
71 int			aml_eval_object(struct acpi_softc *, struct aml_node *,
72 			    struct aml_value *, int, struct aml_value *);
73 void			aml_register_notify(struct aml_node *, const char *,
74 			    int (*)(struct aml_node *, int, void *), void *,
75 			    int);
76 
77 u_int64_t		aml_getpciaddr(struct acpi_softc *, struct aml_node *);
78 
79 int			aml_evalnode(struct acpi_softc *, struct aml_node *,
80 			    int , struct aml_value *, struct aml_value *);
81 int			aml_evalname(struct acpi_softc *, struct aml_node *,
82 			    const char *, int, struct aml_value *,
83 			    struct aml_value *);
84 int			aml_evalinteger(struct acpi_softc *, struct aml_node *,
85                             const char *, int, struct aml_value *, int64_t *);
86 
87 void			aml_fixup_dsdt(u_int8_t *, u_int8_t *, int);
88 void			aml_create_defaultobjects(void);
89 
90 int			acpi_mutex_acquire(struct aml_value *, int);
91 void			acpi_mutex_release(struct aml_value *);
92 
93 const char		*aml_nodename(struct aml_node *);
94 
95 #define SR_IRQ			0x04
96 #define SR_DMA			0x05
97 #define SR_STARTDEP		0x06
98 #define SR_ENDDEP		0x07
99 #define SR_IOPORT		0x08
100 #define SR_FIXEDPORT		0x09
101 #define SR_ENDTAG		0x0F
102 
103 #define LR_24BIT		0x81
104 #define LR_GENREGISTER		0x82
105 #define LR_32BIT		0x85
106 #define LR_32BITFIXED		0x86
107 #define LR_DWORD		0x87
108 #define LR_WORD			0x88
109 #define LR_EXTIRQ		0x89
110 #define LR_QWORD		0x8A
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 	}  __packed sr_irq;
127 	struct {
128 		uint8_t  typecode;
129 		uint8_t  channel;
130 		uint8_t  flags;
131 	}  __packed sr_dma;
132 	struct {
133 		uint8_t  typecode;
134 		uint8_t  flags;
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(int, uint8_t *,
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 /* XXX: endian macros */
233 #define aml_letohost16(x) letoh16(x)
234 #define aml_letohost32(x) letoh32(x)
235 #define aml_letohost64(x) letoh64(x)
236 
237 #define AML_WALK_PRE 0x00
238 #define AML_WALK_POST 0x01
239 
240 void			aml_walknodes(struct aml_node *, int,
241 			    int (*)(struct aml_node *, void *), void *);
242 
243 void			aml_postparse(void);
244 void			acpi_poll_notify(void);
245 
246 void			aml_hashopcodes(void);
247 
248 void	aml_foreachpkg(struct aml_value *, int,
249 	    void (*fn)(struct aml_value *, void *), void *);
250 
251 const char *aml_val_to_string(const struct aml_value *);
252 
253 int valid_acpihdr(void *, int, const char *);
254 void aml_disasm(struct aml_scope *scope, int lvl,
255         void (*dbprintf)(void *, const char *, ...),
256     	void *arg);
257 int aml_xgetpci(struct aml_node *, int64_t *);
258 
259 int acpi_walkmem(int, const char *);
260 
261 #define aml_get8(p)    *(uint8_t *)(p)
262 #define aml_get16(p)   *(uint16_t *)(p)
263 #define aml_get32(p)   *(uint32_t *)(p)
264 #define aml_get64(p)   *(uint64_t *)(p)
265 
266 #endif /* __DEV_ACPI_DSDT_H__ */
267