summaryrefslogtreecommitdiff
path: root/sys/man/2/aml
blob: 3bd6468e65f8d11d6ce1e1d70a6d7003f959de25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
.TH AML 2
.SH NAME
amltag, amlval, amlint, amllen, amlnew, amlinit, amlexit, amlload, amlwalk, amleval, amlenum, amltake, amldrop - ACPI machine language interpreter
.SH SYNOPSIS
.\" .ta 0.75i 1.5i 2.25i 3i 3.75i 4.5i
.ta 0.7i +0.7i +0.7i +0.7i +0.7i +0.7i +0.7i
.EX
#include <u.h>
#include <libc.h>
#include <aml.h>

int	amltag(void *);
void*	amlval(void *);
uvlong	amlint(void *);
int	amllen(void *);

void*	amlnew(char tag, int len);

void	amlinit(void);
void	amlexit(void);

int	amlload(uchar *data, int len);
void*	amlwalk(void *dot, char *name);
int	amleval(void *dot, char *fmt, ...);
void	amlenum(void *dot, char *seg, int (*proc)(void *, void *), void *arg);

void	amltake(void *);
void	amldrop(void *);

void*	amlroot;
int	amldebug;
uvlong	amlintmask;
.EE
.SH DESCRIPTION
The aml library implements an interpreter for the ACPI machine language
byte code.
.TP
\f5amlinit() \f5amlexit()
The interpreter runtime state is initialized by calling
.I amlinit
and frees all the resources when
.I amlexit
is called.
The runtime state consists of objects organized in a global
namespace. The name object referred to by
.I amlroot
is the root of that namespace.
.PP
The width of integers is defined by the global variable
.IR amlintmask ,
which should be initialized to 0xFFFFFFFF for
.B DSDT
revision <= 1 or 0xFFFFFFFFFFFFFFFF for
revision >= 2.
.TP
.BI amlload( data , len )
.I Amlload
populates the namespace with objects parsed from the
definition block of 
.I len
byte size read from
.IR data .
The pc kernel provides access to the ACPI tables through the
.B /dev/acpitbls
file (see
.IR arch (3)
for further details).
.TP
.BI amltag( p )
Objects are dynamically allocated and typed and are passed as
.B void*
pointers. The type tag of an object can be determined with the
.I amltag
function. The following table shows the defined tags and ther
underlying type:
.EX
/*
 *	b	uchar*	buffer		amllen() returns number of bytes
 *	s	char*	string		amllen() is strlen()
 *	n	char*	undefined name	amllen() is strlen()
 *	i	uvlong*	integer
 *	p	void**	package		amllen() is # of elements
 *	r	void*	region
 *	f	void*	field
 *	u	void*	bufferfield
 *	N	void*	name
 *	R	void*	reference
 */
.EE
.TP
.BI amlwalk( dot , name )
.I Amlwalk
takes a path string (relative to
.IR dot )
in
.I name
and returns the final name object of the walk; or
.B nil
if not found.
.TP
\f5amlenum(\fIdot\f5,\fIseg\f5,\fIproc\f5,\fIarg\f5)
.I Amlenum
recursively enumerates all child name objects of
.I dot
that have
.I seg
as name; or any name if
.I seg
is
.BR nil ;
calling
.I proc
for each one passing
.IR dot .
When
.I proc
returns zero, enumeration will continue recursively down
for the current dot.
.TP
.BI amlval( p )
.I Amlval
returns the value of a name, reference or field object.
Calling
.I amlval
on any other object yields the same object.
.TP
.BI amllen( p )
.I Amllen
is defined for variable length objects like buffers, strings and packages.
For strings, the number of characters (not including the terminating null byte)
is returned. For buffers, the size of the buffer in bytes is returned.
For packages (arrays), the number of elements is returned. For any other
object types, the return value is undefined.
.TP
.BI amlint( p )
.I Amlint
returns the integer value of an object. For strings, the string is interpreted
as an hexadecimal number. For buffers and buffer fields, the binary value is returned.
Integers just return their value. Any other object types yield zero.
.TP
.BI amlnew( tag , len )
Integer, buffer, string and package objects can be created with the
.I amlnew
function. The 
.I tag
specific definition of the
.I len
parameter is the same as in
.I amllen
(see above).
.TP
\f5amleval(\fIdot\f5,\fIfmt\f5,\fI...\f5)
.I Amleval
evaluates the name object
.IR dot .
For method evaluation, the
.I fmt
string parameter describes the arguments passed to the evaluated
method. Each character in
.I fmt
represents a tag for an method argument taken from the
variable argument list of
.I amleval
and passed to the method.
The fmt tags
.BR I ,
.B i
and
.B s
take
.BR uvlong ,
.B int
and
.B char*
from the variable argument list and create object copies to
be passed.
The tags
.BR b ,
.B p
and
.B *
take
.B void*
from the variable argument list and pass them as objects
by reference (without conversion or copies).
The last variable argument is a pointer to the result
object location. When the last parameter is
.B nil
the result is discarded.
.TP
\f5amltake(\fIp\f5) \f5amldrop(\fIp\f5)
Objects returned by
.IR amlval ,
.I amleval
and
.I amlnew
are subject to garbage collection during method evaluation
unless previously maked to be excluded from collection with
.IR amltake .
To remark an object for collection,
.I amldrop
needs be called.
Objects stay valid as long as they are reachable from
.IR amlroot .
.bp
.PP
The aml library can be linked into userspace programs
and the kernel which have different means of hardware access
and memory constraints.
.PP
The
.I Amlio
data structure defines access to a hardware space.
.EX

enum {
	MemSpace	= 0x00,
	IoSpace		= 0x01,
	PcicfgSpace	= 0x02,
	EbctlSpace	= 0x03,
	SmbusSpace	= 0x04,
	CmosSpace	= 0x05,
	PcibarSpace	= 0x06,
	IpmiSpace	= 0x07,
};

typedef struct Amlio Amlio;
struct Amlio
{
	int	space;
	uvlong	off;
	uvlong	len;
	void	*name;
	uchar	*va;

	void	*aux;
	int	(*read)(Amlio *io, void *data, int len, int off);
	int	(*write)(Amlio *io, void *data, int len, int off);
};

.EE
The
members
.IR space ,
.IR off ,
.I len
and
.I name
are initialized by the interpreter and describe the I/O region
it needs access to. For memory regions,
.I va
can to be set to the virtual address mapping base by the
mapping function.
The interpreter will call the
.I read
and
.I write
function pointers with a relative offset to the regions
base offset.
The
.I aux
pointer can be used freely by the map function to attach its own
resources to the I/O region and allows it to free these resources
on
.IR amlunmapio .
.TP
\f5amlmapio(\fIio\f5) \f5amlunmapio(\fIio\f5)
The interpreter calls
.I amlmapio
with a
.I Amlio
data structure that is to be filled out. When finished, the
interpreter calls
.I amlunmapio
with the same data structure to allow freeing resources.
.TP
.BI amldelay( µs )
.I Amldelay
is called by the interpreter with the number of microseconds
to sleep.
.TP
\f5amlalloc(\fIn\f5) \f5amlfree(\fIp\f5)
.I Amlalloc
and
.I amlfree
can be optionally defined to control dynamic memory allocation 
providing a way to limit or pool the memory allocated by acpi.
If not provided, the library will use the functions
defined in
.IR malloc (2)
for dynamic allocation.
.SH SOURCE
.B /sys/src/libaml
.SH "SEE ALSO"
.IR arch (3)