xref: /titanic_50/usr/src/uts/intel/io/acpica/utilities/uteval.c (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
1ae115bc7Smrj /******************************************************************************
2ae115bc7Smrj  *
3ae115bc7Smrj  * Module Name: uteval - Object evaluation
4ae115bc7Smrj  *
5ae115bc7Smrj  *****************************************************************************/
6ae115bc7Smrj 
726f3cdf0SGordon Ross /*
8*385cc6b4SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9ae115bc7Smrj  * All rights reserved.
10ae115bc7Smrj  *
1126f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross  * are met:
1426f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross  *    without modification.
1726f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross  *    binary redistribution.
2226f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross  *    from this software without specific prior written permission.
25ae115bc7Smrj  *
2626f3cdf0SGordon Ross  * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross  * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross  * Software Foundation.
29ae115bc7Smrj  *
3026f3cdf0SGordon Ross  * NO WARRANTY
3126f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross  * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross  */
43ae115bc7Smrj 
44ae115bc7Smrj #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46ae115bc7Smrj #include "acnamesp.h"
47ae115bc7Smrj 
48ae115bc7Smrj 
49ae115bc7Smrj #define _COMPONENT          ACPI_UTILITIES
50ae115bc7Smrj         ACPI_MODULE_NAME    ("uteval")
51ae115bc7Smrj 
52ae115bc7Smrj 
53ae115bc7Smrj /*******************************************************************************
54ae115bc7Smrj  *
55ae115bc7Smrj  * FUNCTION:    AcpiUtEvaluateObject
56ae115bc7Smrj  *
57ae115bc7Smrj  * PARAMETERS:  PrefixNode          - Starting node
58ae115bc7Smrj  *              Path                - Path to object from starting node
59ae115bc7Smrj  *              ExpectedReturnTypes - Bitmap of allowed return types
60ae115bc7Smrj  *              ReturnDesc          - Where a return value is stored
61ae115bc7Smrj  *
62ae115bc7Smrj  * RETURN:      Status
63ae115bc7Smrj  *
64ae115bc7Smrj  * DESCRIPTION: Evaluates a namespace object and verifies the type of the
65ae115bc7Smrj  *              return object. Common code that simplifies accessing objects
66ae115bc7Smrj  *              that have required return objects of fixed types.
67ae115bc7Smrj  *
68ae115bc7Smrj  *              NOTE: Internal function, no parameter validation
69ae115bc7Smrj  *
70ae115bc7Smrj  ******************************************************************************/
71ae115bc7Smrj 
72ae115bc7Smrj ACPI_STATUS
AcpiUtEvaluateObject(ACPI_NAMESPACE_NODE * PrefixNode,const char * Path,UINT32 ExpectedReturnBtypes,ACPI_OPERAND_OBJECT ** ReturnDesc)73ae115bc7Smrj AcpiUtEvaluateObject (
74ae115bc7Smrj     ACPI_NAMESPACE_NODE     *PrefixNode,
75*385cc6b4SJerry Jelinek     const char              *Path,
76ae115bc7Smrj     UINT32                  ExpectedReturnBtypes,
77ae115bc7Smrj     ACPI_OPERAND_OBJECT     **ReturnDesc)
78ae115bc7Smrj {
79ae115bc7Smrj     ACPI_EVALUATE_INFO      *Info;
80ae115bc7Smrj     ACPI_STATUS             Status;
81ae115bc7Smrj     UINT32                  ReturnBtype;
82ae115bc7Smrj 
83ae115bc7Smrj 
84ae115bc7Smrj     ACPI_FUNCTION_TRACE (UtEvaluateObject);
85ae115bc7Smrj 
86ae115bc7Smrj 
87ae115bc7Smrj     /* Allocate the evaluation information block */
88ae115bc7Smrj 
89ae115bc7Smrj     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
90ae115bc7Smrj     if (!Info)
91ae115bc7Smrj     {
92ae115bc7Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
93ae115bc7Smrj     }
94ae115bc7Smrj 
95ae115bc7Smrj     Info->PrefixNode = PrefixNode;
96*385cc6b4SJerry Jelinek     Info->RelativePathname = Path;
97ae115bc7Smrj 
98ae115bc7Smrj     /* Evaluate the object/method */
99ae115bc7Smrj 
100ae115bc7Smrj     Status = AcpiNsEvaluate (Info);
101ae115bc7Smrj     if (ACPI_FAILURE (Status))
102ae115bc7Smrj     {
103ae115bc7Smrj         if (Status == AE_NOT_FOUND)
104ae115bc7Smrj         {
105ae115bc7Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
106ae115bc7Smrj                 AcpiUtGetNodeName (PrefixNode), Path));
107ae115bc7Smrj         }
108ae115bc7Smrj         else
109ae115bc7Smrj         {
110ae115bc7Smrj             ACPI_ERROR_METHOD ("Method execution failed",
111ae115bc7Smrj                 PrefixNode, Path, Status);
112ae115bc7Smrj         }
113ae115bc7Smrj 
114ae115bc7Smrj         goto Cleanup;
115ae115bc7Smrj     }
116ae115bc7Smrj 
117ae115bc7Smrj     /* Did we get a return object? */
118ae115bc7Smrj 
119ae115bc7Smrj     if (!Info->ReturnObject)
120ae115bc7Smrj     {
121ae115bc7Smrj         if (ExpectedReturnBtypes)
122ae115bc7Smrj         {
123ae115bc7Smrj             ACPI_ERROR_METHOD ("No object was returned from",
124ae115bc7Smrj                 PrefixNode, Path, AE_NOT_EXIST);
125ae115bc7Smrj 
126ae115bc7Smrj             Status = AE_NOT_EXIST;
127ae115bc7Smrj         }
128ae115bc7Smrj 
129ae115bc7Smrj         goto Cleanup;
130ae115bc7Smrj     }
131ae115bc7Smrj 
132ae115bc7Smrj     /* Map the return object type to the bitmapped type */
133ae115bc7Smrj 
134aa2aa9a6SDana Myers     switch ((Info->ReturnObject)->Common.Type)
135ae115bc7Smrj     {
136ae115bc7Smrj     case ACPI_TYPE_INTEGER:
137*385cc6b4SJerry Jelinek 
138ae115bc7Smrj         ReturnBtype = ACPI_BTYPE_INTEGER;
139ae115bc7Smrj         break;
140ae115bc7Smrj 
141ae115bc7Smrj     case ACPI_TYPE_BUFFER:
142*385cc6b4SJerry Jelinek 
143ae115bc7Smrj         ReturnBtype = ACPI_BTYPE_BUFFER;
144ae115bc7Smrj         break;
145ae115bc7Smrj 
146ae115bc7Smrj     case ACPI_TYPE_STRING:
147*385cc6b4SJerry Jelinek 
148ae115bc7Smrj         ReturnBtype = ACPI_BTYPE_STRING;
149ae115bc7Smrj         break;
150ae115bc7Smrj 
151ae115bc7Smrj     case ACPI_TYPE_PACKAGE:
152*385cc6b4SJerry Jelinek 
153ae115bc7Smrj         ReturnBtype = ACPI_BTYPE_PACKAGE;
154ae115bc7Smrj         break;
155ae115bc7Smrj 
156ae115bc7Smrj     default:
157*385cc6b4SJerry Jelinek 
158ae115bc7Smrj         ReturnBtype = 0;
159ae115bc7Smrj         break;
160ae115bc7Smrj     }
161ae115bc7Smrj 
162ae115bc7Smrj     if ((AcpiGbl_EnableInterpreterSlack) &&
163ae115bc7Smrj         (!ExpectedReturnBtypes))
164ae115bc7Smrj     {
165ae115bc7Smrj         /*
166ae115bc7Smrj          * We received a return object, but one was not expected. This can
167ae115bc7Smrj          * happen frequently if the "implicit return" feature is enabled.
168ae115bc7Smrj          * Just delete the return object and return AE_OK.
169ae115bc7Smrj          */
170ae115bc7Smrj         AcpiUtRemoveReference (Info->ReturnObject);
171ae115bc7Smrj         goto Cleanup;
172ae115bc7Smrj     }
173ae115bc7Smrj 
174ae115bc7Smrj     /* Is the return object one of the expected types? */
175ae115bc7Smrj 
176ae115bc7Smrj     if (!(ExpectedReturnBtypes & ReturnBtype))
177ae115bc7Smrj     {
178ae115bc7Smrj         ACPI_ERROR_METHOD ("Return object type is incorrect",
179ae115bc7Smrj             PrefixNode, Path, AE_TYPE);
180ae115bc7Smrj 
181ae115bc7Smrj         ACPI_ERROR ((AE_INFO,
18226f3cdf0SGordon Ross             "Type returned from %s was incorrect: %s, expected Btypes: 0x%X",
183ae115bc7Smrj             Path, AcpiUtGetObjectTypeName (Info->ReturnObject),
184ae115bc7Smrj             ExpectedReturnBtypes));
185ae115bc7Smrj 
186ae115bc7Smrj         /* On error exit, we must delete the return object */
187ae115bc7Smrj 
188ae115bc7Smrj         AcpiUtRemoveReference (Info->ReturnObject);
189ae115bc7Smrj         Status = AE_TYPE;
190ae115bc7Smrj         goto Cleanup;
191ae115bc7Smrj     }
192ae115bc7Smrj 
193ae115bc7Smrj     /* Object type is OK, return it */
194ae115bc7Smrj 
195ae115bc7Smrj     *ReturnDesc = Info->ReturnObject;
196ae115bc7Smrj 
197ae115bc7Smrj Cleanup:
198ae115bc7Smrj     ACPI_FREE (Info);
199ae115bc7Smrj     return_ACPI_STATUS (Status);
200ae115bc7Smrj }
201ae115bc7Smrj 
202ae115bc7Smrj 
203ae115bc7Smrj /*******************************************************************************
204ae115bc7Smrj  *
205ae115bc7Smrj  * FUNCTION:    AcpiUtEvaluateNumericObject
206ae115bc7Smrj  *
207ae115bc7Smrj  * PARAMETERS:  ObjectName          - Object name to be evaluated
208ae115bc7Smrj  *              DeviceNode          - Node for the device
20957190917SDana Myers  *              Value               - Where the value is returned
210ae115bc7Smrj  *
211ae115bc7Smrj  * RETURN:      Status
212ae115bc7Smrj  *
213ae115bc7Smrj  * DESCRIPTION: Evaluates a numeric namespace object for a selected device
21457190917SDana Myers  *              and stores result in *Value.
215ae115bc7Smrj  *
216ae115bc7Smrj  *              NOTE: Internal function, no parameter validation
217ae115bc7Smrj  *
218ae115bc7Smrj  ******************************************************************************/
219ae115bc7Smrj 
220ae115bc7Smrj ACPI_STATUS
AcpiUtEvaluateNumericObject(const char * ObjectName,ACPI_NAMESPACE_NODE * DeviceNode,UINT64 * Value)221ae115bc7Smrj AcpiUtEvaluateNumericObject (
222*385cc6b4SJerry Jelinek     const char              *ObjectName,
223ae115bc7Smrj     ACPI_NAMESPACE_NODE     *DeviceNode,
22426f3cdf0SGordon Ross     UINT64                  *Value)
225ae115bc7Smrj {
226ae115bc7Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
227ae115bc7Smrj     ACPI_STATUS             Status;
228ae115bc7Smrj 
229ae115bc7Smrj 
230ae115bc7Smrj     ACPI_FUNCTION_TRACE (UtEvaluateNumericObject);
231ae115bc7Smrj 
232ae115bc7Smrj 
233ae115bc7Smrj     Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,
234ae115bc7Smrj         ACPI_BTYPE_INTEGER, &ObjDesc);
235ae115bc7Smrj     if (ACPI_FAILURE (Status))
236ae115bc7Smrj     {
237ae115bc7Smrj         return_ACPI_STATUS (Status);
238ae115bc7Smrj     }
239ae115bc7Smrj 
240ae115bc7Smrj     /* Get the returned Integer */
241ae115bc7Smrj 
24257190917SDana Myers     *Value = ObjDesc->Integer.Value;
243ae115bc7Smrj 
244ae115bc7Smrj     /* On exit, we must delete the return object */
245ae115bc7Smrj 
246ae115bc7Smrj     AcpiUtRemoveReference (ObjDesc);
247ae115bc7Smrj     return_ACPI_STATUS (Status);
248ae115bc7Smrj }
249ae115bc7Smrj 
250ae115bc7Smrj 
251ae115bc7Smrj /*******************************************************************************
252ae115bc7Smrj  *
253ae115bc7Smrj  * FUNCTION:    AcpiUtExecute_STA
254ae115bc7Smrj  *
255ae115bc7Smrj  * PARAMETERS:  DeviceNode          - Node for the device
256ae115bc7Smrj  *              Flags               - Where the status flags are returned
257ae115bc7Smrj  *
258ae115bc7Smrj  * RETURN:      Status
259ae115bc7Smrj  *
260ae115bc7Smrj  * DESCRIPTION: Executes _STA for selected device and stores results in
261*385cc6b4SJerry Jelinek  *              *Flags. If _STA does not exist, then the device is assumed
262*385cc6b4SJerry Jelinek  *              to be present/functional/enabled (as per the ACPI spec).
263ae115bc7Smrj  *
264ae115bc7Smrj  *              NOTE: Internal function, no parameter validation
265ae115bc7Smrj  *
266ae115bc7Smrj  ******************************************************************************/
267ae115bc7Smrj 
268ae115bc7Smrj ACPI_STATUS
AcpiUtExecute_STA(ACPI_NAMESPACE_NODE * DeviceNode,UINT32 * Flags)269ae115bc7Smrj AcpiUtExecute_STA (
270ae115bc7Smrj     ACPI_NAMESPACE_NODE     *DeviceNode,
271ae115bc7Smrj     UINT32                  *Flags)
272ae115bc7Smrj {
273ae115bc7Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
274ae115bc7Smrj     ACPI_STATUS             Status;
275ae115bc7Smrj 
276ae115bc7Smrj 
277ae115bc7Smrj     ACPI_FUNCTION_TRACE (UtExecute_STA);
278ae115bc7Smrj 
279ae115bc7Smrj 
280ae115bc7Smrj     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,
281ae115bc7Smrj         ACPI_BTYPE_INTEGER, &ObjDesc);
282ae115bc7Smrj     if (ACPI_FAILURE (Status))
283ae115bc7Smrj     {
284ae115bc7Smrj         if (AE_NOT_FOUND == Status)
285ae115bc7Smrj         {
286*385cc6b4SJerry Jelinek             /*
287*385cc6b4SJerry Jelinek              * if _STA does not exist, then (as per the ACPI specification),
288*385cc6b4SJerry Jelinek              * the returned flags will indicate that the device is present,
289*385cc6b4SJerry Jelinek              * functional, and enabled.
290*385cc6b4SJerry Jelinek              */
291ae115bc7Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
292ae115bc7Smrj                 "_STA on %4.4s was not found, assuming device is present\n",
293ae115bc7Smrj                 AcpiUtGetNodeName (DeviceNode)));
294ae115bc7Smrj 
295ae115bc7Smrj             *Flags = ACPI_UINT32_MAX;
296ae115bc7Smrj             Status = AE_OK;
297ae115bc7Smrj         }
298ae115bc7Smrj 
299ae115bc7Smrj         return_ACPI_STATUS (Status);
300ae115bc7Smrj     }
301ae115bc7Smrj 
302ae115bc7Smrj     /* Extract the status flags */
303ae115bc7Smrj 
304ae115bc7Smrj     *Flags = (UINT32) ObjDesc->Integer.Value;
305ae115bc7Smrj 
306ae115bc7Smrj     /* On exit, we must delete the return object */
307ae115bc7Smrj 
308ae115bc7Smrj     AcpiUtRemoveReference (ObjDesc);
309ae115bc7Smrj     return_ACPI_STATUS (Status);
310ae115bc7Smrj }
311ae115bc7Smrj 
312ae115bc7Smrj 
313ae115bc7Smrj /*******************************************************************************
314ae115bc7Smrj  *
31557190917SDana Myers  * FUNCTION:    AcpiUtExecutePowerMethods
316ae115bc7Smrj  *
317ae115bc7Smrj  * PARAMETERS:  DeviceNode          - Node for the device
31857190917SDana Myers  *              MethodNames         - Array of power method names
31957190917SDana Myers  *              MethodCount         - Number of methods to execute
32057190917SDana Myers  *              OutValues           - Where the power method values are returned
321ae115bc7Smrj  *
32257190917SDana Myers  * RETURN:      Status, OutValues
323ae115bc7Smrj  *
32457190917SDana Myers  * DESCRIPTION: Executes the specified power methods for the device and returns
32557190917SDana Myers  *              the result(s).
326ae115bc7Smrj  *
327ae115bc7Smrj  *              NOTE: Internal function, no parameter validation
328ae115bc7Smrj  *
329ae115bc7Smrj  ******************************************************************************/
330ae115bc7Smrj 
331ae115bc7Smrj ACPI_STATUS
AcpiUtExecutePowerMethods(ACPI_NAMESPACE_NODE * DeviceNode,const char ** MethodNames,UINT8 MethodCount,UINT8 * OutValues)33257190917SDana Myers AcpiUtExecutePowerMethods (
333ae115bc7Smrj     ACPI_NAMESPACE_NODE     *DeviceNode,
33457190917SDana Myers     const char              **MethodNames,
33557190917SDana Myers     UINT8                   MethodCount,
33657190917SDana Myers     UINT8                   *OutValues)
337ae115bc7Smrj {
338ae115bc7Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
339ae115bc7Smrj     ACPI_STATUS             Status;
34057190917SDana Myers     ACPI_STATUS             FinalStatus = AE_NOT_FOUND;
341ae115bc7Smrj     UINT32                  i;
342ae115bc7Smrj 
343ae115bc7Smrj 
34457190917SDana Myers     ACPI_FUNCTION_TRACE (UtExecutePowerMethods);
345ae115bc7Smrj 
346ae115bc7Smrj 
34757190917SDana Myers     for (i = 0; i < MethodCount; i++)
348ae115bc7Smrj     {
34957190917SDana Myers         /*
35057190917SDana Myers          * Execute the power method (_SxD or _SxW). The only allowable
35157190917SDana Myers          * return type is an Integer.
35257190917SDana Myers          */
353ae115bc7Smrj         Status = AcpiUtEvaluateObject (DeviceNode,
35457190917SDana Myers             ACPI_CAST_PTR (char, MethodNames[i]),
355ae115bc7Smrj             ACPI_BTYPE_INTEGER, &ObjDesc);
35657190917SDana Myers         if (ACPI_SUCCESS (Status))
357ae115bc7Smrj         {
35857190917SDana Myers             OutValues[i] = (UINT8) ObjDesc->Integer.Value;
359ae115bc7Smrj 
360ae115bc7Smrj             /* Delete the return object */
361ae115bc7Smrj 
362ae115bc7Smrj             AcpiUtRemoveReference (ObjDesc);
36357190917SDana Myers             FinalStatus = AE_OK;            /* At least one value is valid */
36457190917SDana Myers             continue;
365ae115bc7Smrj         }
366ae115bc7Smrj 
36757190917SDana Myers         OutValues[i] = ACPI_UINT8_MAX;
36857190917SDana Myers         if (Status == AE_NOT_FOUND)
36957190917SDana Myers         {
37057190917SDana Myers             continue; /* Ignore if not found */
37157190917SDana Myers         }
37257190917SDana Myers 
37357190917SDana Myers         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Failed %s on Device %4.4s, %s\n",
37457190917SDana Myers             ACPI_CAST_PTR (char, MethodNames[i]),
37557190917SDana Myers             AcpiUtGetNodeName (DeviceNode), AcpiFormatException (Status)));
37657190917SDana Myers     }
37757190917SDana Myers 
37857190917SDana Myers     return_ACPI_STATUS (FinalStatus);
379ae115bc7Smrj }
380