aml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. .TH AML 2
  2. .SH NAME
  3. amltag, amlval, amlint, amllen, amlnew, amlinit, amlexit, amlload, amlwalk, amleval, amlenum, amltake, amldrop - ACPI machine language interpreter
  4. .SH SYNOPSIS
  5. .\" .ta 0.75i 1.5i 2.25i 3i 3.75i 4.5i
  6. .ta 0.7i +0.7i +0.7i +0.7i +0.7i +0.7i +0.7i
  7. .EX
  8. #include <u.h>
  9. #include <libc.h>
  10. #include <aml.h>
  11. int amltag(void *);
  12. void* amlval(void *);
  13. uvlong amlint(void *);
  14. int amllen(void *);
  15. void* amlnew(char tag, int len);
  16. void amlinit(void);
  17. void amlexit(void);
  18. int amlload(uchar *data, int len);
  19. void* amlwalk(void *dot, char *name);
  20. int amleval(void *dot, char *fmt, ...);
  21. void amlenum(void *dot, char *seg, int (*proc)(void *, void *), void *arg);
  22. void amltake(void *);
  23. void amldrop(void *);
  24. void* amlroot;
  25. int amldebug;
  26. .EE
  27. .SH DESCRIPTION
  28. The aml library implements an interpreter for the ACPI machine language
  29. byte code.
  30. .TP
  31. \f5amlinit() \f5amlexit()
  32. The interpreter runtime state is initialized by calling
  33. .I amlinit
  34. and frees all the resources when
  35. .I amlexit
  36. is called.
  37. The runtime state consists of objects organized in a global
  38. namespace. The name object referred to by
  39. .I amlroot
  40. is the root of that namespace.
  41. .TP
  42. .BI amlload( data , len )
  43. .I Amlload
  44. populates the namespace with objects parsed from the
  45. definition block of
  46. .I len
  47. byte size read from
  48. .IR data .
  49. The pc kernel provides access to the ACPI tables through the
  50. .B /dev/acpitbls
  51. file (see
  52. .IR arch (3)
  53. for further details).
  54. .TP
  55. .BI amltag( p )
  56. Objects are dynamically allocated and typed and are passed as
  57. .B void*
  58. pointers. The type tag of an object can be determined with the
  59. .I amltag
  60. function. The following table shows the defined tags and ther
  61. underlying type:
  62. .EX
  63. /*
  64. * b uchar* buffer amllen() returns number of bytes
  65. * s char* string amllen() is strlen()
  66. * n char* undefined name amllen() is strlen()
  67. * i uvlong* integer
  68. * p void** package amllen() is # of elements
  69. * r void* region
  70. * f void* field
  71. * u void* bufferfield
  72. * N void* name
  73. * R void* reference
  74. */
  75. .EE
  76. .TP
  77. .BI amlwalk( dot , name )
  78. .I Amlwalk
  79. takes a path string (relative to
  80. .IR dot )
  81. in
  82. .I name
  83. and returns the final name object of the walk; or
  84. .B nil
  85. if not found.
  86. .TP
  87. \f5amlenum(\fIdot\f5,\fIseg\f5,\fIproc\f5,\fIarg\f5)
  88. .I Amlenum
  89. recursively enumerates all child name objects of
  90. .I dot
  91. that have
  92. .I seg
  93. as name; or any name if
  94. .I seg
  95. is
  96. .BR nil ;
  97. calling
  98. .I proc
  99. for each one passing
  100. .IR dot .
  101. When
  102. .I proc
  103. returns zero, enumeration will continue recursively down
  104. for the current dot.
  105. .TP
  106. .BI amlval( p )
  107. .I Amlval
  108. returns the value of a name, reference or field object.
  109. Calling
  110. .I amlval
  111. on any other object yields the same object.
  112. .TP
  113. .BI amllen( p )
  114. .I Amllen
  115. is defined for variable length objects like buffers, strings and packages.
  116. For strings, the number of characters (not including the terminating null byte)
  117. is returned. For buffers, the size of the buffer in bytes is returned.
  118. For packages (arrays), the number of elements is returned. For any other
  119. object types, the return value is undefined.
  120. .TP
  121. .BI amlint( p )
  122. .I Amlint
  123. returns the integer value of an object. For strings, the string is interpreted
  124. as an hexadecimal number. For buffers and buffer fields, the binary value is returned.
  125. Integers just return their value. Any other object types yield zero.
  126. .TP
  127. .BI amlnew( tag , len )
  128. Integer, buffer, string and package objects can be created with the
  129. .I amlnew
  130. function. The
  131. .I tag
  132. specific definition of the
  133. .I len
  134. parameter is the same as in
  135. .I amllen
  136. (see above).
  137. .TP
  138. \f5amleval(\fIdot\f5,\fIfmt\f5,\fI...\f5)
  139. .I Amleval
  140. evaluates the name object
  141. .IR dot .
  142. For method evaluation, the
  143. .I fmt
  144. string parameter describes the arguments passed to the evaluated
  145. method. Each character in
  146. .I fmt
  147. represents a tag for an method argument taken from the
  148. variable argument list of
  149. .I amleval
  150. and passed to the method.
  151. The fmt tags
  152. .BR I ,
  153. .B i
  154. and
  155. .B s
  156. take
  157. .BR uvlong ,
  158. .B int
  159. and
  160. .B char*
  161. from the variable argument list and create object copies to
  162. be passed.
  163. The tags
  164. .BR b ,
  165. .B p
  166. and
  167. .B *
  168. take
  169. .B void*
  170. from the variable argument list and pass them as objects
  171. by reference (without conversion or copies).
  172. The last variable argument is a pointer to the result
  173. object location. When the last parameter is
  174. .B nil
  175. the result is discarded.
  176. .TP
  177. \f5amltake(\fIp\f5) \f5amldrop(\fIp\f5)
  178. Objects returned by
  179. .IR amlval ,
  180. .I amleval
  181. and
  182. .I amlnew
  183. are subject to garbage collection during method evaluation
  184. unless previously maked to be excluded from collection with
  185. .IR amltake .
  186. To remark an object for collection,
  187. .I amldrop
  188. needs be called.
  189. Objects stay valid as long as they are reachable from
  190. .IR amlroot .
  191. .bp
  192. .PP
  193. The aml library can be linked into userspace programs
  194. and the kernel which have different means of hardware access
  195. and memory constraints.
  196. .PP
  197. The
  198. .I Amlio
  199. data structure defines access to a hardware space.
  200. .EX
  201. enum {
  202. MemSpace = 0x00,
  203. IoSpace = 0x01,
  204. PcicfgSpace = 0x02,
  205. EbctlSpace = 0x03,
  206. SmbusSpace = 0x04,
  207. CmosSpace = 0x05,
  208. PcibarSpace = 0x06,
  209. IpmiSpace = 0x07,
  210. };
  211. typedef struct Amlio Amlio;
  212. struct Amlio
  213. {
  214. int space;
  215. uvlong off;
  216. uvlong len;
  217. void *name;
  218. uchar *va;
  219. void *aux;
  220. int (*read)(Amlio *io, void *data, int len, int off);
  221. int (*write)(Amlio *io, void *data, int len, int off);
  222. };
  223. .EE
  224. The
  225. members
  226. .IR space ,
  227. .IR off ,
  228. .I len
  229. and
  230. .I name
  231. are initialized by the interpreter and describe the I/O region
  232. it needs access to. For memory regions,
  233. .I va
  234. can to be set to the virtual address mapping base by the
  235. mapping function.
  236. The interpreter will call the
  237. .I read
  238. and
  239. .I write
  240. function pointers with a relative offset to the regions
  241. base offset.
  242. The
  243. .I aux
  244. pointer can be used freely by the map function to attach its own
  245. resources to the I/O region and allows it to free these resources
  246. on
  247. .IR amlunmapio .
  248. .TP
  249. \f5amlmapio(\fIio\f5) \f5amlunmapio(\fIio\f5)
  250. The interpreter calls
  251. .I amlmapio
  252. with a
  253. .I Amlio
  254. data structure that is to be filled out. When finished, the
  255. interpreter calls
  256. .I amlunmapio
  257. with the same data structure to allow freeing resources.
  258. .TP
  259. .BI amldelay( µs )
  260. .I Amldelay
  261. is called by the interpreter with the number of microseconds
  262. to sleep.
  263. .TP
  264. \f5amlalloc(\fIn\f5) \f5amlfree(\fIp\f5)
  265. .I Amlalloc
  266. and
  267. .I amlfree
  268. can be optionally defined to control dynamic memory allocation
  269. providing a way to limit or pool the memory allocated by acpi.
  270. If not provided, the library will use the functions
  271. defined in
  272. .IR malloc (2)
  273. for dynamic allocation.
  274. .SH SOURCE
  275. .B /sys/src/libaml
  276. .SH "SEE ALSO"
  277. .IR arch (3)