1*5dfee228Sschwarze.\" $OpenBSD: aml_evalnode.9,v 1.11 2015/09/14 15:14:55 schwarze Exp $ 24be60abbSmk.\" 34be60abbSmk.\" Copyright (c) 2007 Michael Knudsen <mk@openbsd.org> 44be60abbSmk.\" 54be60abbSmk.\" Permission to use, copy, modify, and distribute this software for any 64be60abbSmk.\" purpose with or without fee is hereby granted, provided that the above 74be60abbSmk.\" copyright notice and this permission notice appear in all copies. 84be60abbSmk.\" 94be60abbSmk.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 104be60abbSmk.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 114be60abbSmk.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 124be60abbSmk.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 134be60abbSmk.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 144be60abbSmk.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 154be60abbSmk.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 164be60abbSmk.\" 17*5dfee228Sschwarze.Dd $Mdocdate: September 14 2015 $ 184be60abbSmk.Dt AML_EVALNODE 9 194be60abbSmk.Os 204be60abbSmk.Sh NAME 214be60abbSmk.Nm aml_evalnode , 224be60abbSmk.Nm aml_evalname , 23f3af9fedSmk.Nm aml_find_node , 24cb0e5d97Sjmc.Nm aml_freevalue , 25cb0e5d97Sjmc.Nm aml_val2int 264be60abbSmk.Nd AML API 274be60abbSmk.Sh SYNOPSIS 28dddd2645Sschwarze.In dev/acpi/acpireg.h 29dddd2645Sschwarze.In dev/acpi/acpivar.h 30dddd2645Sschwarze.In dev/acpi/acpidev.h 31dddd2645Sschwarze.In dev/acpi/amltypes.h 32dddd2645Sschwarze.In dev/acpi/dsdt.h 334be60abbSmk.Ft int 34*5dfee228Sschwarze.Fn aml_evalnode "struct acpi_softc *sc" "struct aml_node *node" \ 354be60abbSmk"int argc" "struct aml_value *argv" "struct aml_value *res" 364be60abbSmk.Ft int 37*5dfee228Sschwarze.Fn aml_evalname "struct acpi_softc *sc" "struct aml_node *parent" \ 384be60abbSmk"const char *name" "int argc" "struct aml_value *argv" \ 394be60abbSmk"struct aml_value *res" 40f3af9fedSmk.Ft int 41*5dfee228Sschwarze.Fn aml_find_node "struct aml_node *node" "const char *name" \ 420116fe2cSweingart"int (*cbproc)(struct aml_node *, void *arg)" "void *arg" 434be60abbSmk.Ft void 44*5dfee228Sschwarze.Fn aml_freevalue "struct aml_value *val" 4559ff0ce8Smk.Ft int64_t 46*5dfee228Sschwarze.Fn aml_val2int "struct aml_value *rval" 474be60abbSmk.Sh DESCRIPTION 484be60abbSmkThe AML API handles decoding and evaluation of the AML 494be60abbSmkcode embedded in a machine's ACPI tables. 504be60abbSmkThis code is used to implement configuration and control mechanisms for 514be60abbSmkmachines. 524be60abbSmk.Pp 534be60abbSmk.Fn aml_evalnode 544be60abbSmkevaluates the AML node 554be60abbSmk.Fa node 564be60abbSmklocated in the ACPI table specified by 574be60abbSmk.Fa sc . 584be60abbSmkParameters may be passed using the 594be60abbSmk.Fa argv 604be60abbSmkparameters with the parameter 614be60abbSmk.Fa argc 624be60abbSmkspecifying the number of parameters passed. 634be60abbSmkIf there are no arguments, 644be60abbSmka value of 0 is used for 654be60abbSmk.Fa argc 664be60abbSmkand 674be60abbSmk.Fa argv 684be60abbSmkshould be 694be60abbSmk.Dv NULL . 704be60abbSmkIf evaluating the node produces any result, for example a string with a device 714be60abbSmkname reference, this result is stored in the 724be60abbSmk.Fa res 734be60abbSmkparameter unless it is 744be60abbSmk.Dv NULL . 754be60abbSmk.Fa res 764be60abbSmkis cleared before storing the result. 774be60abbSmkIf 78369bef3aSschwarze.Fa node 794be60abbSmkdoes not exist, 804be60abbSmk.Fn aml_evalnode 814be60abbSmkreturns 824be60abbSmk.Dv ACPI_E_BADVALUE , 834be60abbSmkotherwise it returns 0. 844be60abbSmk.Pp 854be60abbSmk.Fn aml_evalname 864be60abbSmkis similar to 874be60abbSmk.Fn aml_evalnode 884be60abbSmkbut differs in that it searches for a subnode of 89369bef3aSschwarze.Fa parent 904be60abbSmkwith the name 91369bef3aSschwarze.Fa name . 924be60abbSmkIf such a node is found, it is evaluated using 934be60abbSmk.Fn aml_evalnode , 944be60abbSmkpassing whatever parameters were passed to itself. 954be60abbSmk.Fn aml_evalname 964be60abbSmkreturns the return value of 974be60abbSmk.Fn aml_evalnode . 984be60abbSmk.Pp 99f3af9fedSmk.Fn aml_find_node 100f3af9fedSmkis used to find all subnodes of 101369bef3aSschwarze.Fa parent 102f3af9fedSmkwith a name of 103369bef3aSschwarze.Fa name . 104f3af9fedSmkFor each node found, the function specified as the 105369bef3aSschwarze.Fa cbproc 106f3af9fedSmkparameter is called with the node and 107369bef3aSschwarze.Fa arg 108cb0e5d97Sjmcas the first and second parameters, respectively. 109f3af9fedSmkThe function specified as the 110369bef3aSschwarze.Fa cbproc 1110116fe2cSweingartparameter returns a value that specifies if the tree walk 1120116fe2cSweingartshould be terminated (!0) or continued (0) with the children. 113f3af9fedSmk.Fn aml_find_node 114f3af9fedSmkalways returns 0. 115f3af9fedSmk.Pp 1164be60abbSmk.Fn aml_freevalue 1174be60abbSmkis used to free up the result returned from 1184be60abbSmk.Fn aml_evalnode 1194be60abbSmkor the other AML evaluation functions. 1204be60abbSmkNote that no attempt is made to free the 121369bef3aSschwarze.Vt struct aml_value 1224be60abbSmkitself so it is safe to allocate this on the stack. 1234be60abbSmkAlso, calling 1244be60abbSmk.Fn aml_freevalue 1254be60abbSmkwith a parameter of 1264be60abbSmk.Dv NULL 1274be60abbSmkis not an error. 12859ff0ce8Smk.Pp 12959ff0ce8Smk.Fn aml_val2int 13059ff0ce8Smkis used to convert the 131369bef3aSschwarze.Vt struct aml_value 13259ff0ce8Smkpointed to by the 133369bef3aSschwarze.Fa rval 13459ff0ce8Smkparameter to a signed 64-bit integer value. 13559ff0ce8SmkMultiple types exist for 136369bef3aSschwarze.Vt struct aml_value , 13759ff0ce8Smkand the conversion value depends on the type 13859ff0ce8Smkof the value object as follows. 139cb0e5d97SjmcFor objects of type 14059ff0ce8Smk.Dv AML_OBJTYPE_INTEGER 14159ff0ce8Smkand 14259ff0ce8Smk.Dv AML_OBJTYPE_STATICINT , 14359ff0ce8Smkthe return value is simply the integer value stored in the object. 144cb0e5d97SjmcFor objects of type 14559ff0ce8Smk.Dv AML_OBJTYPE_BUFFER , 14659ff0ce8Smkthe return value is the integer interpretation of the buffer contents. 147cb0e5d97SjmcFor objects of type 14859ff0ce8Smk.Dv AML_OBJTYPE_STRING , 14959ff0ce8Smkthe return value is the integer value represented as a string in base 10 15059ff0ce8Smkor, if prefixed by 15159ff0ce8Smk.Dq 0x , 15259ff0ce8Smkin base 16. 15359ff0ce8SmkIf 154369bef3aSschwarze.Fa rval 15559ff0ce8Smkis 15659ff0ce8Smk.Dv NULL 15759ff0ce8Smkor not of one of the types mentioned above, 15859ff0ce8Smk.Fn aml_val2int 15959ff0ce8Smkreturns 0. 16059ff0ce8Smk.Sh EXAMPLES 16159ff0ce8SmkUsing 16259ff0ce8Smk.Fn aml_evalname 16359ff0ce8Smkto invoke the 16459ff0ce8Smk.Dq _STA 16559ff0ce8Smkmethod on a node 166369bef3aSschwarze.Fa node 16759ff0ce8Smkshould be done like the following: 16859ff0ce8Smk.Bd -literal -offset indent 16959ff0ce8Smkstruct acpi_softc *sc 170369bef3aSschwarzestruct aml_node *node; 17159ff0ce8Smkstruct aml_value res; 17259ff0ce8Smk 173369bef3aSschwarzeif (aml_evalname(sc->sc_acpi, node, "_STA", 0, NULL, &res) != 0) { 174e1665715Sjmc dnprintf(10, "%s: no _STA\en", DEVNAME(sc)); 17559ff0ce8Smk return; 17659ff0ce8Smk} 17759ff0ce8Smk.Ed 17859ff0ce8Smk.Pp 17959ff0ce8SmkUsing the 180369bef3aSschwarze.Vt struct aml_value 18159ff0ce8Smkobtained from the 18259ff0ce8Smk.Dq _STA 18359ff0ce8Smkcall to determine if the device is a battery is done as follows: 18459ff0ce8Smk.Bd -literal -offset indent 18559ff0ce8Smkif ((aml_val2int(&res) & STA_BATTERY) == 0) { 186e1665715Sjmc dnprintf(10, %s: no battery present\en", DEVNAME(sc)); 18759ff0ce8Smk return; 18859ff0ce8Smk.Ed 18959ff0ce8Smk.Pp 19059ff0ce8SmkFinally, when the result stored in 191369bef3aSschwarze.Fa res 19259ff0ce8Smkis no longer needed, free it using 19359ff0ce8Smk.Fn aml_freevalue : 19459ff0ce8Smk.Bd -literal -offset indent 19559ff0ce8Smkaml_freevalue(&res); 19659ff0ce8Smk.Ed 1974be60abbSmk.Sh SEE ALSO 1984be60abbSmk.Xr acpi 4 , 1994be60abbSmk.Xr acpidump 8 2004be60abbSmk.Sh HISTORY 2014be60abbSmkThe AML API was written by 202f0641c22Sschwarze.An Jordan Hargrave Aq Mt jordan@openbsd.org . 203