1*3446Smrj /******************************************************************************
2*3446Smrj  *
3*3446Smrj  * Module Name: uteval - Object evaluation
4*3446Smrj  *              $Revision: 1.70 $
5*3446Smrj  *
6*3446Smrj  *****************************************************************************/
7*3446Smrj 
8*3446Smrj /******************************************************************************
9*3446Smrj  *
10*3446Smrj  * 1. Copyright Notice
11*3446Smrj  *
12*3446Smrj  * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13*3446Smrj  * All rights reserved.
14*3446Smrj  *
15*3446Smrj  * 2. License
16*3446Smrj  *
17*3446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
18*3446Smrj  * rights.  You may have additional license terms from the party that provided
19*3446Smrj  * you this software, covering your right to use that party's intellectual
20*3446Smrj  * property rights.
21*3446Smrj  *
22*3446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23*3446Smrj  * copy of the source code appearing in this file ("Covered Code") an
24*3446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25*3446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
26*3446Smrj  * make derivatives, distribute, use and display any portion of the Covered
27*3446Smrj  * Code in any form, with the right to sublicense such rights; and
28*3446Smrj  *
29*3446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30*3446Smrj  * license (with the right to sublicense), under only those claims of Intel
31*3446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
32*3446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
33*3446Smrj  * solely to the minimum extent necessary to exercise the above copyright
34*3446Smrj  * license, and in no event shall the patent license extend to any additions
35*3446Smrj  * to or modifications of the Original Intel Code.  No other license or right
36*3446Smrj  * is granted directly or by implication, estoppel or otherwise;
37*3446Smrj  *
38*3446Smrj  * The above copyright and patent license is granted only if the following
39*3446Smrj  * conditions are met:
40*3446Smrj  *
41*3446Smrj  * 3. Conditions
42*3446Smrj  *
43*3446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44*3446Smrj  * Redistribution of source code of any substantial portion of the Covered
45*3446Smrj  * Code or modification with rights to further distribute source must include
46*3446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
47*3446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
48*3446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
49*3446Smrj  * contain a file documenting the changes Licensee made to create that Covered
50*3446Smrj  * Code and the date of any change.  Licensee must include in that file the
51*3446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
52*3446Smrj  * must include a prominent statement that the modification is derived,
53*3446Smrj  * directly or indirectly, from Original Intel Code.
54*3446Smrj  *
55*3446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56*3446Smrj  * Redistribution of source code of any substantial portion of the Covered
57*3446Smrj  * Code or modification without rights to further distribute source must
58*3446Smrj  * include the following Disclaimer and Export Compliance provision in the
59*3446Smrj  * documentation and/or other materials provided with distribution.  In
60*3446Smrj  * addition, Licensee may not authorize further sublicense of source of any
61*3446Smrj  * portion of the Covered Code, and must include terms to the effect that the
62*3446Smrj  * license from Licensee to its licensee is limited to the intellectual
63*3446Smrj  * property embodied in the software Licensee provides to its licensee, and
64*3446Smrj  * not to intellectual property embodied in modifications its licensee may
65*3446Smrj  * make.
66*3446Smrj  *
67*3446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68*3446Smrj  * substantial portion of the Covered Code or modification must reproduce the
69*3446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
70*3446Smrj  * provision in the documentation and/or other materials provided with the
71*3446Smrj  * distribution.
72*3446Smrj  *
73*3446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
74*3446Smrj  * Intel Code.
75*3446Smrj  *
76*3446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77*3446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
78*3446Smrj  * other dealings in products derived from or relating to the Covered Code
79*3446Smrj  * without prior written authorization from Intel.
80*3446Smrj  *
81*3446Smrj  * 4. Disclaimer and Export Compliance
82*3446Smrj  *
83*3446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84*3446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85*3446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86*3446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87*3446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88*3446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89*3446Smrj  * PARTICULAR PURPOSE.
90*3446Smrj  *
91*3446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92*3446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93*3446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94*3446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95*3446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96*3446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97*3446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98*3446Smrj  * LIMITED REMEDY.
99*3446Smrj  *
100*3446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101*3446Smrj  * software or system incorporating such software without first obtaining any
102*3446Smrj  * required license or other approval from the U. S. Department of Commerce or
103*3446Smrj  * any other agency or department of the United States Government.  In the
104*3446Smrj  * event Licensee exports any such software from the United States or
105*3446Smrj  * re-exports any such software from a foreign destination, Licensee shall
106*3446Smrj  * ensure that the distribution and export/re-export of the software is in
107*3446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
108*3446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109*3446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
110*3446Smrj  * software, or service, directly or indirectly, to any country for which the
111*3446Smrj  * United States government or any agency thereof requires an export license,
112*3446Smrj  * other governmental approval, or letter of assurance, without first obtaining
113*3446Smrj  * such license, approval or letter.
114*3446Smrj  *
115*3446Smrj  *****************************************************************************/
116*3446Smrj 
117*3446Smrj #define __UTEVAL_C__
118*3446Smrj 
119*3446Smrj #include "acpi.h"
120*3446Smrj #include "acnamesp.h"
121*3446Smrj #include "acinterp.h"
122*3446Smrj 
123*3446Smrj 
124*3446Smrj #define _COMPONENT          ACPI_UTILITIES
125*3446Smrj         ACPI_MODULE_NAME    ("uteval")
126*3446Smrj 
127*3446Smrj /* Local prototypes */
128*3446Smrj 
129*3446Smrj static void
130*3446Smrj AcpiUtCopyIdString (
131*3446Smrj     char                    *Destination,
132*3446Smrj     char                    *Source,
133*3446Smrj     ACPI_SIZE               MaxLength);
134*3446Smrj 
135*3446Smrj static ACPI_STATUS
136*3446Smrj AcpiUtTranslateOneCid (
137*3446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc,
138*3446Smrj     ACPI_COMPATIBLE_ID      *OneCid);
139*3446Smrj 
140*3446Smrj 
141*3446Smrj /*
142*3446Smrj  * Strings supported by the _OSI predefined (internal) method.
143*3446Smrj  */
144*3446Smrj static const char               *AcpiInterfacesSupported[] =
145*3446Smrj {
146*3446Smrj     /* Operating System Vendor Strings */
147*3446Smrj 
148*3446Smrj     "Linux",
149*3446Smrj     "Windows 2000",
150*3446Smrj     "Windows 2001",
151*3446Smrj     "Windows 2001 SP0",
152*3446Smrj     "Windows 2001 SP1",
153*3446Smrj     "Windows 2001 SP2",
154*3446Smrj     "Windows 2001 SP3",
155*3446Smrj     "Windows 2001 SP4",
156*3446Smrj     "Windows 2001.1",
157*3446Smrj     "Windows 2001.1 SP1",   /* Added 03/2006 */
158*3446Smrj     "Windows 2006",         /* Added 03/2006 */
159*3446Smrj 
160*3446Smrj     /* Feature Group Strings */
161*3446Smrj 
162*3446Smrj     "Extended Address Space Descriptor"
163*3446Smrj 
164*3446Smrj     /*
165*3446Smrj      * All "optional" feature group strings (features that are implemented
166*3446Smrj      * by the host) should be implemented in the host version of
167*3446Smrj      * AcpiOsValidateInterface and should not be added here.
168*3446Smrj      */
169*3446Smrj };
170*3446Smrj 
171*3446Smrj 
172*3446Smrj /*******************************************************************************
173*3446Smrj  *
174*3446Smrj  * FUNCTION:    AcpiUtOsiImplementation
175*3446Smrj  *
176*3446Smrj  * PARAMETERS:  WalkState           - Current walk state
177*3446Smrj  *
178*3446Smrj  * RETURN:      Status
179*3446Smrj  *
180*3446Smrj  * DESCRIPTION: Implementation of the _OSI predefined control method
181*3446Smrj  *
182*3446Smrj  ******************************************************************************/
183*3446Smrj 
184*3446Smrj ACPI_STATUS
185*3446Smrj AcpiUtOsiImplementation (
186*3446Smrj     ACPI_WALK_STATE         *WalkState)
187*3446Smrj {
188*3446Smrj     ACPI_STATUS             Status;
189*3446Smrj     ACPI_OPERAND_OBJECT     *StringDesc;
190*3446Smrj     ACPI_OPERAND_OBJECT     *ReturnDesc;
191*3446Smrj     ACPI_NATIVE_UINT        i;
192*3446Smrj 
193*3446Smrj 
194*3446Smrj     ACPI_FUNCTION_TRACE (UtOsiImplementation);
195*3446Smrj 
196*3446Smrj 
197*3446Smrj     /* Validate the string input argument */
198*3446Smrj 
199*3446Smrj     StringDesc = WalkState->Arguments[0].Object;
200*3446Smrj     if (!StringDesc || (StringDesc->Common.Type != ACPI_TYPE_STRING))
201*3446Smrj     {
202*3446Smrj         return_ACPI_STATUS (AE_TYPE);
203*3446Smrj     }
204*3446Smrj 
205*3446Smrj     /* Create a return object */
206*3446Smrj 
207*3446Smrj     ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
208*3446Smrj     if (!ReturnDesc)
209*3446Smrj     {
210*3446Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
211*3446Smrj     }
212*3446Smrj 
213*3446Smrj     /* Default return value is SUPPORTED */
214*3446Smrj 
215*3446Smrj     ReturnDesc->Integer.Value = ACPI_UINT32_MAX;
216*3446Smrj     WalkState->ReturnDesc = ReturnDesc;
217*3446Smrj 
218*3446Smrj     /* Compare input string to static table of supported interfaces */
219*3446Smrj 
220*3446Smrj     for (i = 0; i < ACPI_ARRAY_LENGTH (AcpiInterfacesSupported); i++)
221*3446Smrj     {
222*3446Smrj         if (!ACPI_STRCMP (StringDesc->String.Pointer, AcpiInterfacesSupported[i]))
223*3446Smrj         {
224*3446Smrj             /* The interface is supported */
225*3446Smrj 
226*3446Smrj             return_ACPI_STATUS (AE_CTRL_TERMINATE);
227*3446Smrj         }
228*3446Smrj     }
229*3446Smrj 
230*3446Smrj     /*
231*3446Smrj      * Did not match the string in the static table, call the host OSL to
232*3446Smrj      * check for a match with one of the optional strings (such as
233*3446Smrj      * "Module Device", "3.0 Thermal Model", etc.)
234*3446Smrj      */
235*3446Smrj     Status = AcpiOsValidateInterface (StringDesc->String.Pointer);
236*3446Smrj     if (ACPI_SUCCESS (Status))
237*3446Smrj     {
238*3446Smrj         /* The interface is supported */
239*3446Smrj 
240*3446Smrj         return_ACPI_STATUS (AE_CTRL_TERMINATE);
241*3446Smrj     }
242*3446Smrj 
243*3446Smrj     /* The interface is not supported */
244*3446Smrj 
245*3446Smrj     ReturnDesc->Integer.Value = 0;
246*3446Smrj     return_ACPI_STATUS (AE_CTRL_TERMINATE);
247*3446Smrj }
248*3446Smrj 
249*3446Smrj 
250*3446Smrj /*******************************************************************************
251*3446Smrj  *
252*3446Smrj  * FUNCTION:    AcpiUtEvaluateObject
253*3446Smrj  *
254*3446Smrj  * PARAMETERS:  PrefixNode          - Starting node
255*3446Smrj  *              Path                - Path to object from starting node
256*3446Smrj  *              ExpectedReturnTypes - Bitmap of allowed return types
257*3446Smrj  *              ReturnDesc          - Where a return value is stored
258*3446Smrj  *
259*3446Smrj  * RETURN:      Status
260*3446Smrj  *
261*3446Smrj  * DESCRIPTION: Evaluates a namespace object and verifies the type of the
262*3446Smrj  *              return object.  Common code that simplifies accessing objects
263*3446Smrj  *              that have required return objects of fixed types.
264*3446Smrj  *
265*3446Smrj  *              NOTE: Internal function, no parameter validation
266*3446Smrj  *
267*3446Smrj  ******************************************************************************/
268*3446Smrj 
269*3446Smrj ACPI_STATUS
270*3446Smrj AcpiUtEvaluateObject (
271*3446Smrj     ACPI_NAMESPACE_NODE     *PrefixNode,
272*3446Smrj     char                    *Path,
273*3446Smrj     UINT32                  ExpectedReturnBtypes,
274*3446Smrj     ACPI_OPERAND_OBJECT     **ReturnDesc)
275*3446Smrj {
276*3446Smrj     ACPI_EVALUATE_INFO      *Info;
277*3446Smrj     ACPI_STATUS             Status;
278*3446Smrj     UINT32                  ReturnBtype;
279*3446Smrj 
280*3446Smrj 
281*3446Smrj     ACPI_FUNCTION_TRACE (UtEvaluateObject);
282*3446Smrj 
283*3446Smrj 
284*3446Smrj     /* Allocate the evaluation information block */
285*3446Smrj 
286*3446Smrj     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
287*3446Smrj     if (!Info)
288*3446Smrj     {
289*3446Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
290*3446Smrj     }
291*3446Smrj 
292*3446Smrj     Info->PrefixNode = PrefixNode;
293*3446Smrj     Info->Pathname = Path;
294*3446Smrj     Info->ParameterType = ACPI_PARAM_ARGS;
295*3446Smrj 
296*3446Smrj     /* Evaluate the object/method */
297*3446Smrj 
298*3446Smrj     Status = AcpiNsEvaluate (Info);
299*3446Smrj     if (ACPI_FAILURE (Status))
300*3446Smrj     {
301*3446Smrj         if (Status == AE_NOT_FOUND)
302*3446Smrj         {
303*3446Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
304*3446Smrj                 AcpiUtGetNodeName (PrefixNode), Path));
305*3446Smrj         }
306*3446Smrj         else
307*3446Smrj         {
308*3446Smrj             ACPI_ERROR_METHOD ("Method execution failed",
309*3446Smrj                 PrefixNode, Path, Status);
310*3446Smrj         }
311*3446Smrj 
312*3446Smrj         goto Cleanup;
313*3446Smrj     }
314*3446Smrj 
315*3446Smrj     /* Did we get a return object? */
316*3446Smrj 
317*3446Smrj     if (!Info->ReturnObject)
318*3446Smrj     {
319*3446Smrj         if (ExpectedReturnBtypes)
320*3446Smrj         {
321*3446Smrj             ACPI_ERROR_METHOD ("No object was returned from",
322*3446Smrj                 PrefixNode, Path, AE_NOT_EXIST);
323*3446Smrj 
324*3446Smrj             Status = AE_NOT_EXIST;
325*3446Smrj         }
326*3446Smrj 
327*3446Smrj         goto Cleanup;
328*3446Smrj     }
329*3446Smrj 
330*3446Smrj     /* Map the return object type to the bitmapped type */
331*3446Smrj 
332*3446Smrj     switch (ACPI_GET_OBJECT_TYPE (Info->ReturnObject))
333*3446Smrj     {
334*3446Smrj     case ACPI_TYPE_INTEGER:
335*3446Smrj         ReturnBtype = ACPI_BTYPE_INTEGER;
336*3446Smrj         break;
337*3446Smrj 
338*3446Smrj     case ACPI_TYPE_BUFFER:
339*3446Smrj         ReturnBtype = ACPI_BTYPE_BUFFER;
340*3446Smrj         break;
341*3446Smrj 
342*3446Smrj     case ACPI_TYPE_STRING:
343*3446Smrj         ReturnBtype = ACPI_BTYPE_STRING;
344*3446Smrj         break;
345*3446Smrj 
346*3446Smrj     case ACPI_TYPE_PACKAGE:
347*3446Smrj         ReturnBtype = ACPI_BTYPE_PACKAGE;
348*3446Smrj         break;
349*3446Smrj 
350*3446Smrj     default:
351*3446Smrj         ReturnBtype = 0;
352*3446Smrj         break;
353*3446Smrj     }
354*3446Smrj 
355*3446Smrj     if ((AcpiGbl_EnableInterpreterSlack) &&
356*3446Smrj         (!ExpectedReturnBtypes))
357*3446Smrj     {
358*3446Smrj         /*
359*3446Smrj          * We received a return object, but one was not expected.  This can
360*3446Smrj          * happen frequently if the "implicit return" feature is enabled.
361*3446Smrj          * Just delete the return object and return AE_OK.
362*3446Smrj          */
363*3446Smrj         AcpiUtRemoveReference (Info->ReturnObject);
364*3446Smrj         goto Cleanup;
365*3446Smrj     }
366*3446Smrj 
367*3446Smrj     /* Is the return object one of the expected types? */
368*3446Smrj 
369*3446Smrj     if (!(ExpectedReturnBtypes & ReturnBtype))
370*3446Smrj     {
371*3446Smrj         ACPI_ERROR_METHOD ("Return object type is incorrect",
372*3446Smrj             PrefixNode, Path, AE_TYPE);
373*3446Smrj 
374*3446Smrj         ACPI_ERROR ((AE_INFO,
375*3446Smrj             "Type returned from %s was incorrect: %s, expected Btypes: %X",
376*3446Smrj             Path, AcpiUtGetObjectTypeName (Info->ReturnObject),
377*3446Smrj             ExpectedReturnBtypes));
378*3446Smrj 
379*3446Smrj         /* On error exit, we must delete the return object */
380*3446Smrj 
381*3446Smrj         AcpiUtRemoveReference (Info->ReturnObject);
382*3446Smrj         Status = AE_TYPE;
383*3446Smrj         goto Cleanup;
384*3446Smrj     }
385*3446Smrj 
386*3446Smrj     /* Object type is OK, return it */
387*3446Smrj 
388*3446Smrj     *ReturnDesc = Info->ReturnObject;
389*3446Smrj 
390*3446Smrj Cleanup:
391*3446Smrj     ACPI_FREE (Info);
392*3446Smrj     return_ACPI_STATUS (Status);
393*3446Smrj }
394*3446Smrj 
395*3446Smrj 
396*3446Smrj /*******************************************************************************
397*3446Smrj  *
398*3446Smrj  * FUNCTION:    AcpiUtEvaluateNumericObject
399*3446Smrj  *
400*3446Smrj  * PARAMETERS:  ObjectName          - Object name to be evaluated
401*3446Smrj  *              DeviceNode          - Node for the device
402*3446Smrj  *              Address             - Where the value is returned
403*3446Smrj  *
404*3446Smrj  * RETURN:      Status
405*3446Smrj  *
406*3446Smrj  * DESCRIPTION: Evaluates a numeric namespace object for a selected device
407*3446Smrj  *              and stores result in *Address.
408*3446Smrj  *
409*3446Smrj  *              NOTE: Internal function, no parameter validation
410*3446Smrj  *
411*3446Smrj  ******************************************************************************/
412*3446Smrj 
413*3446Smrj ACPI_STATUS
414*3446Smrj AcpiUtEvaluateNumericObject (
415*3446Smrj     char                    *ObjectName,
416*3446Smrj     ACPI_NAMESPACE_NODE     *DeviceNode,
417*3446Smrj     ACPI_INTEGER            *Address)
418*3446Smrj {
419*3446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
420*3446Smrj     ACPI_STATUS             Status;
421*3446Smrj 
422*3446Smrj 
423*3446Smrj     ACPI_FUNCTION_TRACE (UtEvaluateNumericObject);
424*3446Smrj 
425*3446Smrj 
426*3446Smrj     Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,
427*3446Smrj                 ACPI_BTYPE_INTEGER, &ObjDesc);
428*3446Smrj     if (ACPI_FAILURE (Status))
429*3446Smrj     {
430*3446Smrj         return_ACPI_STATUS (Status);
431*3446Smrj     }
432*3446Smrj 
433*3446Smrj     /* Get the returned Integer */
434*3446Smrj 
435*3446Smrj     *Address = ObjDesc->Integer.Value;
436*3446Smrj 
437*3446Smrj     /* On exit, we must delete the return object */
438*3446Smrj 
439*3446Smrj     AcpiUtRemoveReference (ObjDesc);
440*3446Smrj     return_ACPI_STATUS (Status);
441*3446Smrj }
442*3446Smrj 
443*3446Smrj 
444*3446Smrj /*******************************************************************************
445*3446Smrj  *
446*3446Smrj  * FUNCTION:    AcpiUtCopyIdString
447*3446Smrj  *
448*3446Smrj  * PARAMETERS:  Destination         - Where to copy the string
449*3446Smrj  *              Source              - Source string
450*3446Smrj  *              MaxLength           - Length of the destination buffer
451*3446Smrj  *
452*3446Smrj  * RETURN:      None
453*3446Smrj  *
454*3446Smrj  * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
455*3446Smrj  *              Performs removal of a leading asterisk if present -- workaround
456*3446Smrj  *              for a known issue on a bunch of machines.
457*3446Smrj  *
458*3446Smrj  ******************************************************************************/
459*3446Smrj 
460*3446Smrj static void
461*3446Smrj AcpiUtCopyIdString (
462*3446Smrj     char                    *Destination,
463*3446Smrj     char                    *Source,
464*3446Smrj     ACPI_SIZE               MaxLength)
465*3446Smrj {
466*3446Smrj 
467*3446Smrj     /*
468*3446Smrj      * Workaround for ID strings that have a leading asterisk. This construct
469*3446Smrj      * is not allowed by the ACPI specification  (ID strings must be
470*3446Smrj      * alphanumeric), but enough existing machines have this embedded in their
471*3446Smrj      * ID strings that the following code is useful.
472*3446Smrj      */
473*3446Smrj     if (*Source == '*')
474*3446Smrj     {
475*3446Smrj         Source++;
476*3446Smrj     }
477*3446Smrj 
478*3446Smrj     /* Do the actual copy */
479*3446Smrj 
480*3446Smrj     ACPI_STRNCPY (Destination, Source, MaxLength);
481*3446Smrj }
482*3446Smrj 
483*3446Smrj 
484*3446Smrj /*******************************************************************************
485*3446Smrj  *
486*3446Smrj  * FUNCTION:    AcpiUtExecute_HID
487*3446Smrj  *
488*3446Smrj  * PARAMETERS:  DeviceNode          - Node for the device
489*3446Smrj  *              Hid                 - Where the HID is returned
490*3446Smrj  *
491*3446Smrj  * RETURN:      Status
492*3446Smrj  *
493*3446Smrj  * DESCRIPTION: Executes the _HID control method that returns the hardware
494*3446Smrj  *              ID of the device.
495*3446Smrj  *
496*3446Smrj  *              NOTE: Internal function, no parameter validation
497*3446Smrj  *
498*3446Smrj  ******************************************************************************/
499*3446Smrj 
500*3446Smrj ACPI_STATUS
501*3446Smrj AcpiUtExecute_HID (
502*3446Smrj     ACPI_NAMESPACE_NODE     *DeviceNode,
503*3446Smrj     ACPI_DEVICE_ID          *Hid)
504*3446Smrj {
505*3446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
506*3446Smrj     ACPI_STATUS             Status;
507*3446Smrj 
508*3446Smrj 
509*3446Smrj     ACPI_FUNCTION_TRACE (UtExecute_HID);
510*3446Smrj 
511*3446Smrj 
512*3446Smrj     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
513*3446Smrj                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
514*3446Smrj     if (ACPI_FAILURE (Status))
515*3446Smrj     {
516*3446Smrj         return_ACPI_STATUS (Status);
517*3446Smrj     }
518*3446Smrj 
519*3446Smrj     if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
520*3446Smrj     {
521*3446Smrj         /* Convert the Numeric HID to string */
522*3446Smrj 
523*3446Smrj         AcpiExEisaIdToString ((UINT32) ObjDesc->Integer.Value, Hid->Value);
524*3446Smrj     }
525*3446Smrj     else
526*3446Smrj     {
527*3446Smrj         /* Copy the String HID from the returned object */
528*3446Smrj 
529*3446Smrj         AcpiUtCopyIdString (Hid->Value, ObjDesc->String.Pointer,
530*3446Smrj                 sizeof (Hid->Value));
531*3446Smrj     }
532*3446Smrj 
533*3446Smrj     /* On exit, we must delete the return object */
534*3446Smrj 
535*3446Smrj     AcpiUtRemoveReference (ObjDesc);
536*3446Smrj     return_ACPI_STATUS (Status);
537*3446Smrj }
538*3446Smrj 
539*3446Smrj 
540*3446Smrj /*******************************************************************************
541*3446Smrj  *
542*3446Smrj  * FUNCTION:    AcpiUtTranslateOneCid
543*3446Smrj  *
544*3446Smrj  * PARAMETERS:  ObjDesc             - _CID object, must be integer or string
545*3446Smrj  *              OneCid              - Where the CID string is returned
546*3446Smrj  *
547*3446Smrj  * RETURN:      Status
548*3446Smrj  *
549*3446Smrj  * DESCRIPTION: Return a numeric or string _CID value as a string.
550*3446Smrj  *              (Compatible ID)
551*3446Smrj  *
552*3446Smrj  *              NOTE:  Assumes a maximum _CID string length of
553*3446Smrj  *                     ACPI_MAX_CID_LENGTH.
554*3446Smrj  *
555*3446Smrj  ******************************************************************************/
556*3446Smrj 
557*3446Smrj static ACPI_STATUS
558*3446Smrj AcpiUtTranslateOneCid (
559*3446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc,
560*3446Smrj     ACPI_COMPATIBLE_ID      *OneCid)
561*3446Smrj {
562*3446Smrj 
563*3446Smrj 
564*3446Smrj     switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
565*3446Smrj     {
566*3446Smrj     case ACPI_TYPE_INTEGER:
567*3446Smrj 
568*3446Smrj         /* Convert the Numeric CID to string */
569*3446Smrj 
570*3446Smrj         AcpiExEisaIdToString ((UINT32) ObjDesc->Integer.Value, OneCid->Value);
571*3446Smrj         return (AE_OK);
572*3446Smrj 
573*3446Smrj     case ACPI_TYPE_STRING:
574*3446Smrj 
575*3446Smrj         if (ObjDesc->String.Length > ACPI_MAX_CID_LENGTH)
576*3446Smrj         {
577*3446Smrj             return (AE_AML_STRING_LIMIT);
578*3446Smrj         }
579*3446Smrj 
580*3446Smrj         /* Copy the String CID from the returned object */
581*3446Smrj 
582*3446Smrj         AcpiUtCopyIdString (OneCid->Value, ObjDesc->String.Pointer,
583*3446Smrj                 ACPI_MAX_CID_LENGTH);
584*3446Smrj         return (AE_OK);
585*3446Smrj 
586*3446Smrj     default:
587*3446Smrj 
588*3446Smrj         return (AE_TYPE);
589*3446Smrj     }
590*3446Smrj }
591*3446Smrj 
592*3446Smrj 
593*3446Smrj /*******************************************************************************
594*3446Smrj  *
595*3446Smrj  * FUNCTION:    AcpiUtExecute_CID
596*3446Smrj  *
597*3446Smrj  * PARAMETERS:  DeviceNode          - Node for the device
598*3446Smrj  *              ReturnCidList       - Where the CID list is returned
599*3446Smrj  *
600*3446Smrj  * RETURN:      Status
601*3446Smrj  *
602*3446Smrj  * DESCRIPTION: Executes the _CID control method that returns one or more
603*3446Smrj  *              compatible hardware IDs for the device.
604*3446Smrj  *
605*3446Smrj  *              NOTE: Internal function, no parameter validation
606*3446Smrj  *
607*3446Smrj  ******************************************************************************/
608*3446Smrj 
609*3446Smrj ACPI_STATUS
610*3446Smrj AcpiUtExecute_CID (
611*3446Smrj     ACPI_NAMESPACE_NODE     *DeviceNode,
612*3446Smrj     ACPI_COMPATIBLE_ID_LIST **ReturnCidList)
613*3446Smrj {
614*3446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
615*3446Smrj     ACPI_STATUS             Status;
616*3446Smrj     UINT32                  Count;
617*3446Smrj     UINT32                  Size;
618*3446Smrj     ACPI_COMPATIBLE_ID_LIST *CidList;
619*3446Smrj     ACPI_NATIVE_UINT        i;
620*3446Smrj 
621*3446Smrj 
622*3446Smrj     ACPI_FUNCTION_TRACE (UtExecute_CID);
623*3446Smrj 
624*3446Smrj 
625*3446Smrj     /* Evaluate the _CID method for this device */
626*3446Smrj 
627*3446Smrj     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
628*3446Smrj                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
629*3446Smrj                 &ObjDesc);
630*3446Smrj     if (ACPI_FAILURE (Status))
631*3446Smrj     {
632*3446Smrj         return_ACPI_STATUS (Status);
633*3446Smrj     }
634*3446Smrj 
635*3446Smrj     /* Get the number of _CIDs returned */
636*3446Smrj 
637*3446Smrj     Count = 1;
638*3446Smrj     if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_PACKAGE)
639*3446Smrj     {
640*3446Smrj         Count = ObjDesc->Package.Count;
641*3446Smrj     }
642*3446Smrj 
643*3446Smrj     /* Allocate a worst-case buffer for the _CIDs */
644*3446Smrj 
645*3446Smrj     Size = (((Count - 1) * sizeof (ACPI_COMPATIBLE_ID)) +
646*3446Smrj                            sizeof (ACPI_COMPATIBLE_ID_LIST));
647*3446Smrj 
648*3446Smrj     CidList = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) Size);
649*3446Smrj     if (!CidList)
650*3446Smrj     {
651*3446Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
652*3446Smrj     }
653*3446Smrj 
654*3446Smrj     /* Init CID list */
655*3446Smrj 
656*3446Smrj     CidList->Count = Count;
657*3446Smrj     CidList->Size  = Size;
658*3446Smrj 
659*3446Smrj     /*
660*3446Smrj      *  A _CID can return either a single compatible ID or a package of
661*3446Smrj      *  compatible IDs.  Each compatible ID can be one of the following:
662*3446Smrj      *  1) Integer (32 bit compressed EISA ID) or
663*3446Smrj      *  2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
664*3446Smrj      */
665*3446Smrj 
666*3446Smrj     /* The _CID object can be either a single CID or a package (list) of CIDs */
667*3446Smrj 
668*3446Smrj     if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_PACKAGE)
669*3446Smrj     {
670*3446Smrj         /* Translate each package element */
671*3446Smrj 
672*3446Smrj         for (i = 0; i < Count; i++)
673*3446Smrj         {
674*3446Smrj             Status = AcpiUtTranslateOneCid (ObjDesc->Package.Elements[i],
675*3446Smrj                             &CidList->Id[i]);
676*3446Smrj             if (ACPI_FAILURE (Status))
677*3446Smrj             {
678*3446Smrj                 break;
679*3446Smrj             }
680*3446Smrj         }
681*3446Smrj     }
682*3446Smrj     else
683*3446Smrj     {
684*3446Smrj         /* Only one CID, translate to a string */
685*3446Smrj 
686*3446Smrj         Status = AcpiUtTranslateOneCid (ObjDesc, CidList->Id);
687*3446Smrj     }
688*3446Smrj 
689*3446Smrj     /* Cleanup on error */
690*3446Smrj 
691*3446Smrj     if (ACPI_FAILURE (Status))
692*3446Smrj     {
693*3446Smrj         ACPI_FREE (CidList);
694*3446Smrj     }
695*3446Smrj     else
696*3446Smrj     {
697*3446Smrj         *ReturnCidList = CidList;
698*3446Smrj     }
699*3446Smrj 
700*3446Smrj     /* On exit, we must delete the _CID return object */
701*3446Smrj 
702*3446Smrj     AcpiUtRemoveReference (ObjDesc);
703*3446Smrj     return_ACPI_STATUS (Status);
704*3446Smrj }
705*3446Smrj 
706*3446Smrj 
707*3446Smrj /*******************************************************************************
708*3446Smrj  *
709*3446Smrj  * FUNCTION:    AcpiUtExecute_UID
710*3446Smrj  *
711*3446Smrj  * PARAMETERS:  DeviceNode          - Node for the device
712*3446Smrj  *              Uid                 - Where the UID is returned
713*3446Smrj  *
714*3446Smrj  * RETURN:      Status
715*3446Smrj  *
716*3446Smrj  * DESCRIPTION: Executes the _UID control method that returns the hardware
717*3446Smrj  *              ID of the device.
718*3446Smrj  *
719*3446Smrj  *              NOTE: Internal function, no parameter validation
720*3446Smrj  *
721*3446Smrj  ******************************************************************************/
722*3446Smrj 
723*3446Smrj ACPI_STATUS
724*3446Smrj AcpiUtExecute_UID (
725*3446Smrj     ACPI_NAMESPACE_NODE     *DeviceNode,
726*3446Smrj     ACPI_DEVICE_ID          *Uid)
727*3446Smrj {
728*3446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
729*3446Smrj     ACPI_STATUS             Status;
730*3446Smrj 
731*3446Smrj 
732*3446Smrj     ACPI_FUNCTION_TRACE (UtExecute_UID);
733*3446Smrj 
734*3446Smrj 
735*3446Smrj     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
736*3446Smrj                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
737*3446Smrj     if (ACPI_FAILURE (Status))
738*3446Smrj     {
739*3446Smrj         return_ACPI_STATUS (Status);
740*3446Smrj     }
741*3446Smrj 
742*3446Smrj     if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
743*3446Smrj     {
744*3446Smrj         /* Convert the Numeric UID to string */
745*3446Smrj 
746*3446Smrj         AcpiExUnsignedIntegerToString (ObjDesc->Integer.Value, Uid->Value);
747*3446Smrj     }
748*3446Smrj     else
749*3446Smrj     {
750*3446Smrj         /* Copy the String UID from the returned object */
751*3446Smrj 
752*3446Smrj         AcpiUtCopyIdString (Uid->Value, ObjDesc->String.Pointer,
753*3446Smrj                 sizeof (Uid->Value));
754*3446Smrj     }
755*3446Smrj 
756*3446Smrj     /* On exit, we must delete the return object */
757*3446Smrj 
758*3446Smrj     AcpiUtRemoveReference (ObjDesc);
759*3446Smrj     return_ACPI_STATUS (Status);
760*3446Smrj }
761*3446Smrj 
762*3446Smrj 
763*3446Smrj /*******************************************************************************
764*3446Smrj  *
765*3446Smrj  * FUNCTION:    AcpiUtExecute_STA
766*3446Smrj  *
767*3446Smrj  * PARAMETERS:  DeviceNode          - Node for the device
768*3446Smrj  *              Flags               - Where the status flags are returned
769*3446Smrj  *
770*3446Smrj  * RETURN:      Status
771*3446Smrj  *
772*3446Smrj  * DESCRIPTION: Executes _STA for selected device and stores results in
773*3446Smrj  *              *Flags.
774*3446Smrj  *
775*3446Smrj  *              NOTE: Internal function, no parameter validation
776*3446Smrj  *
777*3446Smrj  ******************************************************************************/
778*3446Smrj 
779*3446Smrj ACPI_STATUS
780*3446Smrj AcpiUtExecute_STA (
781*3446Smrj     ACPI_NAMESPACE_NODE     *DeviceNode,
782*3446Smrj     UINT32                  *Flags)
783*3446Smrj {
784*3446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
785*3446Smrj     ACPI_STATUS             Status;
786*3446Smrj 
787*3446Smrj 
788*3446Smrj     ACPI_FUNCTION_TRACE (UtExecute_STA);
789*3446Smrj 
790*3446Smrj 
791*3446Smrj     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,
792*3446Smrj                 ACPI_BTYPE_INTEGER, &ObjDesc);
793*3446Smrj     if (ACPI_FAILURE (Status))
794*3446Smrj     {
795*3446Smrj         if (AE_NOT_FOUND == Status)
796*3446Smrj         {
797*3446Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
798*3446Smrj                 "_STA on %4.4s was not found, assuming device is present\n",
799*3446Smrj                 AcpiUtGetNodeName (DeviceNode)));
800*3446Smrj 
801*3446Smrj             *Flags = ACPI_UINT32_MAX;
802*3446Smrj             Status = AE_OK;
803*3446Smrj         }
804*3446Smrj 
805*3446Smrj         return_ACPI_STATUS (Status);
806*3446Smrj     }
807*3446Smrj 
808*3446Smrj     /* Extract the status flags */
809*3446Smrj 
810*3446Smrj     *Flags = (UINT32) ObjDesc->Integer.Value;
811*3446Smrj 
812*3446Smrj     /* On exit, we must delete the return object */
813*3446Smrj 
814*3446Smrj     AcpiUtRemoveReference (ObjDesc);
815*3446Smrj     return_ACPI_STATUS (Status);
816*3446Smrj }
817*3446Smrj 
818*3446Smrj 
819*3446Smrj /*******************************************************************************
820*3446Smrj  *
821*3446Smrj  * FUNCTION:    AcpiUtExecute_Sxds
822*3446Smrj  *
823*3446Smrj  * PARAMETERS:  DeviceNode          - Node for the device
824*3446Smrj  *              Flags               - Where the status flags are returned
825*3446Smrj  *
826*3446Smrj  * RETURN:      Status
827*3446Smrj  *
828*3446Smrj  * DESCRIPTION: Executes _STA for selected device and stores results in
829*3446Smrj  *              *Flags.
830*3446Smrj  *
831*3446Smrj  *              NOTE: Internal function, no parameter validation
832*3446Smrj  *
833*3446Smrj  ******************************************************************************/
834*3446Smrj 
835*3446Smrj ACPI_STATUS
836*3446Smrj AcpiUtExecute_Sxds (
837*3446Smrj     ACPI_NAMESPACE_NODE     *DeviceNode,
838*3446Smrj     UINT8                   *Highest)
839*3446Smrj {
840*3446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
841*3446Smrj     ACPI_STATUS             Status;
842*3446Smrj     UINT32                  i;
843*3446Smrj 
844*3446Smrj 
845*3446Smrj     ACPI_FUNCTION_TRACE (UtExecute_Sxds);
846*3446Smrj 
847*3446Smrj 
848*3446Smrj     for (i = 0; i < 4; i++)
849*3446Smrj     {
850*3446Smrj         Highest[i] = 0xFF;
851*3446Smrj         Status = AcpiUtEvaluateObject (DeviceNode,
852*3446Smrj                     ACPI_CAST_PTR (char, AcpiGbl_HighestDstateNames[i]),
853*3446Smrj                     ACPI_BTYPE_INTEGER, &ObjDesc);
854*3446Smrj         if (ACPI_FAILURE (Status))
855*3446Smrj         {
856*3446Smrj             if (Status != AE_NOT_FOUND)
857*3446Smrj             {
858*3446Smrj                 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
859*3446Smrj                     "%s on Device %4.4s, %s\n",
860*3446Smrj                     ACPI_CAST_PTR (char, AcpiGbl_HighestDstateNames[i]),
861*3446Smrj                     AcpiUtGetNodeName (DeviceNode),
862*3446Smrj                     AcpiFormatException (Status)));
863*3446Smrj 
864*3446Smrj                 return_ACPI_STATUS (Status);
865*3446Smrj             }
866*3446Smrj         }
867*3446Smrj         else
868*3446Smrj         {
869*3446Smrj             /* Extract the Dstate value */
870*3446Smrj 
871*3446Smrj             Highest[i] = (UINT8) ObjDesc->Integer.Value;
872*3446Smrj 
873*3446Smrj             /* Delete the return object */
874*3446Smrj 
875*3446Smrj             AcpiUtRemoveReference (ObjDesc);
876*3446Smrj         }
877*3446Smrj     }
878*3446Smrj 
879*3446Smrj     return_ACPI_STATUS (AE_OK);
880*3446Smrj }
881