uteval.c revision 80062
1/******************************************************************************
2 *
3 * Module Name: uteval - Object evaluation
4 *              $Revision: 28 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#define __UTEVAL_C__
118
119#include "acpi.h"
120#include "acnamesp.h"
121#include "acinterp.h"
122
123
124#define _COMPONENT          ACPI_UTILITIES
125        MODULE_NAME         ("uteval")
126
127
128/*******************************************************************************
129 *
130 * FUNCTION:    AcpiUtEvaluateNumericObject
131 *
132 * PARAMETERS:  *ObjectName         - Object name to be evaluated
133 *              DeviceNode          - Node for the device
134 *              *Address            - Where the value is returned
135 *
136 * RETURN:      Status
137 *
138 * DESCRIPTION: evaluates a numeric namespace object for a selected device
139 *              and stores results in *Address.
140 *
141 *              NOTE: Internal function, no parameter validation
142 *
143 ******************************************************************************/
144
145ACPI_STATUS
146AcpiUtEvaluateNumericObject (
147    NATIVE_CHAR             *ObjectName,
148    ACPI_NAMESPACE_NODE     *DeviceNode,
149    ACPI_INTEGER            *Address)
150{
151    ACPI_OPERAND_OBJECT     *ObjDesc;
152    ACPI_STATUS             Status;
153
154
155    FUNCTION_TRACE ("UtEvaluateNumericObject");
156
157
158    /* Execute the method */
159
160    Status = AcpiNsEvaluateRelative (DeviceNode, ObjectName, NULL, &ObjDesc);
161    if (ACPI_FAILURE (Status))
162    {
163        if (Status == AE_NOT_FOUND)
164        {
165            DEBUG_PRINTP (ACPI_INFO, ("%s on %4.4s was not found\n",
166                ObjectName, &DeviceNode->Name));
167        }
168        else
169        {
170            DEBUG_PRINTP (ACPI_ERROR, ("%s on %4.4s failed with status %s\n",
171                ObjectName, &DeviceNode->Name,
172                AcpiFormatException (Status)));
173        }
174
175        return_ACPI_STATUS (Status);
176    }
177
178
179    /* Did we get a return object? */
180
181    if (!ObjDesc)
182    {
183        DEBUG_PRINTP (ACPI_ERROR, ("No object was returned from %s\n",
184            ObjectName));
185        return_ACPI_STATUS (AE_TYPE);
186    }
187
188    /* Is the return object of the correct type? */
189
190    if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
191    {
192        Status = AE_TYPE;
193        DEBUG_PRINTP (ACPI_ERROR,
194            ("Type returned from %s was not a number: %X \n",
195            ObjectName, ObjDesc->Common.Type));
196    }
197    else
198    {
199        /*
200         * Since the structure is a union, setting any field will set all
201         * of the variables in the union
202         */
203        *Address = ObjDesc->Integer.Value;
204    }
205
206    /* On exit, we must delete the return object */
207
208    AcpiUtRemoveReference (ObjDesc);
209
210    return_ACPI_STATUS (Status);
211}
212
213
214/*******************************************************************************
215 *
216 * FUNCTION:    AcpiUtExecute_HID
217 *
218 * PARAMETERS:  DeviceNode          - Node for the device
219 *              *Hid                - Where the HID is returned
220 *
221 * RETURN:      Status
222 *
223 * DESCRIPTION: Executes the _HID control method that returns the hardware
224 *              ID of the device.
225 *
226 *              NOTE: Internal function, no parameter validation
227 *
228 ******************************************************************************/
229
230ACPI_STATUS
231AcpiUtExecute_HID (
232    ACPI_NAMESPACE_NODE     *DeviceNode,
233    ACPI_DEVICE_ID          *Hid)
234{
235    ACPI_OPERAND_OBJECT     *ObjDesc;
236    ACPI_STATUS             Status;
237
238
239    FUNCTION_TRACE ("UtExecute_HID");
240
241
242    /* Execute the method */
243
244    Status = AcpiNsEvaluateRelative (DeviceNode,
245                                     METHOD_NAME__HID, NULL, &ObjDesc);
246    if (ACPI_FAILURE (Status))
247    {
248        if (Status == AE_NOT_FOUND)
249        {
250            DEBUG_PRINTP (ACPI_INFO, ("_HID on %4.4s was not found\n",
251                &DeviceNode->Name));
252        }
253
254        else
255        {
256            DEBUG_PRINTP (ACPI_ERROR, ("_HID on %4.4s failed %s\n",
257                &DeviceNode->Name, AcpiFormatException (Status)));
258        }
259
260        return_ACPI_STATUS (Status);
261    }
262
263    /* Did we get a return object? */
264
265    if (!ObjDesc)
266    {
267        DEBUG_PRINTP (ACPI_ERROR, ("No object was returned from _HID\n"));
268        return_ACPI_STATUS (AE_TYPE);
269    }
270
271    /*
272     *  A _HID can return either a Number (32 bit compressed EISA ID) or
273     *  a string
274     */
275    if ((ObjDesc->Common.Type != ACPI_TYPE_INTEGER) &&
276        (ObjDesc->Common.Type != ACPI_TYPE_STRING))
277    {
278        Status = AE_TYPE;
279        DEBUG_PRINTP (ACPI_ERROR,
280            ("Type returned from _HID not a number or string: %s(%X) \n",
281            AcpiUtGetTypeName (ObjDesc->Common.Type), ObjDesc->Common.Type));
282    }
283
284    else
285    {
286        if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
287        {
288            /* Convert the Numeric HID to string */
289
290            AcpiExEisaIdToString ((UINT32) ObjDesc->Integer.Value, Hid->Buffer);
291        }
292
293        else
294        {
295            /* Copy the String HID from the returned object */
296
297            STRNCPY(Hid->Buffer, ObjDesc->String.Pointer, sizeof(Hid->Buffer));
298        }
299    }
300
301
302    /* On exit, we must delete the return object */
303
304    AcpiUtRemoveReference (ObjDesc);
305
306    return_ACPI_STATUS (Status);
307}
308
309
310/*******************************************************************************
311 *
312 * FUNCTION:    AcpiUtExecute_UID
313 *
314 * PARAMETERS:  DeviceNode          - Node for the device
315 *              *Uid                - Where the UID is returned
316 *
317 * RETURN:      Status
318 *
319 * DESCRIPTION: Executes the _UID control method that returns the hardware
320 *              ID of the device.
321 *
322 *              NOTE: Internal function, no parameter validation
323 *
324 ******************************************************************************/
325
326ACPI_STATUS
327AcpiUtExecute_UID (
328    ACPI_NAMESPACE_NODE     *DeviceNode,
329    ACPI_DEVICE_ID          *Uid)
330{
331    ACPI_OPERAND_OBJECT     *ObjDesc;
332    ACPI_STATUS             Status;
333
334
335    PROC_NAME ("UtExecute_UID");
336
337
338    /* Execute the method */
339
340    Status = AcpiNsEvaluateRelative (DeviceNode,
341                                     METHOD_NAME__UID, NULL, &ObjDesc);
342    if (ACPI_FAILURE (Status))
343    {
344        if (Status == AE_NOT_FOUND)
345        {
346            DEBUG_PRINTP (ACPI_INFO, ("_UID on %4.4s was not found\n",
347                &DeviceNode->Name));
348        }
349
350        else
351        {
352            DEBUG_PRINTP (ACPI_ERROR,
353                ("_UID on %4.4s failed %s\n",
354                &DeviceNode->Name, AcpiFormatException (Status)));
355        }
356
357        return (Status);
358    }
359
360    /* Did we get a return object? */
361
362    if (!ObjDesc)
363    {
364        DEBUG_PRINTP (ACPI_ERROR, ("No object was returned from _UID\n"));
365        return (AE_TYPE);
366    }
367
368    /*
369     *  A _UID can return either a Number (32 bit compressed EISA ID) or
370     *  a string
371     */
372    if ((ObjDesc->Common.Type != ACPI_TYPE_INTEGER) &&
373        (ObjDesc->Common.Type != ACPI_TYPE_STRING))
374    {
375        Status = AE_TYPE;
376        DEBUG_PRINTP (ACPI_ERROR,
377            ("Type returned from _UID was not a number or string: %X \n",
378            ObjDesc->Common.Type));
379    }
380
381    else
382    {
383        if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
384        {
385            /* Convert the Numeric UID to string */
386
387            AcpiExUnsignedIntegerToString (ObjDesc->Integer.Value, Uid->Buffer);
388        }
389
390        else
391        {
392            /* Copy the String UID from the returned object */
393
394            STRNCPY(Uid->Buffer, ObjDesc->String.Pointer, sizeof(Uid->Buffer));
395        }
396    }
397
398
399    /* On exit, we must delete the return object */
400
401    AcpiUtRemoveReference (ObjDesc);
402
403    return (Status);
404}
405
406
407/*******************************************************************************
408 *
409 * FUNCTION:    AcpiUtExecute_STA
410 *
411 * PARAMETERS:  DeviceNode          - Node for the device
412 *              *Flags              - Where the status flags are returned
413 *
414 * RETURN:      Status
415 *
416 * DESCRIPTION: Executes _STA for selected device and stores results in
417 *              *Flags.
418 *
419 *              NOTE: Internal function, no parameter validation
420 *
421 ******************************************************************************/
422
423ACPI_STATUS
424AcpiUtExecute_STA (
425    ACPI_NAMESPACE_NODE     *DeviceNode,
426    UINT32                  *Flags)
427{
428    ACPI_OPERAND_OBJECT     *ObjDesc;
429    ACPI_STATUS             Status;
430
431
432    FUNCTION_TRACE ("UtExecute_STA");
433
434
435    /* Execute the method */
436
437    Status = AcpiNsEvaluateRelative (DeviceNode,
438                                     METHOD_NAME__STA, NULL, &ObjDesc);
439    if (AE_NOT_FOUND == Status)
440    {
441        DEBUG_PRINTP (ACPI_INFO,
442            ("_STA on %4.4s was not found, assuming present.\n",
443            &DeviceNode->Name));
444
445        *Flags = 0x0F;
446        Status = AE_OK;
447    }
448
449    else if (ACPI_FAILURE (Status))
450    {
451        DEBUG_PRINTP (ACPI_ERROR, ("_STA on %4.4s failed %s\n",
452            &DeviceNode->Name,
453            AcpiFormatException (Status)));
454    }
455
456    else /* success */
457    {
458        /* Did we get a return object? */
459
460        if (!ObjDesc)
461        {
462            DEBUG_PRINTP (ACPI_ERROR, ("No object was returned from _STA\n"));
463            return_ACPI_STATUS (AE_TYPE);
464        }
465
466        /* Is the return object of the correct type? */
467
468        if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
469        {
470            Status = AE_TYPE;
471            DEBUG_PRINTP (ACPI_ERROR,
472                ("Type returned from _STA was not a number: %X \n",
473                ObjDesc->Common.Type));
474        }
475
476        else
477        {
478            /* Extract the status flags */
479
480            *Flags = (UINT32) ObjDesc->Integer.Value;
481        }
482
483        /* On exit, we must delete the return object */
484
485        AcpiUtRemoveReference (ObjDesc);
486    }
487
488    return_ACPI_STATUS (Status);
489}
490