kernel: kill proc with bogus ipc address
[minix.git] / drivers / acpi / executer / exresolv.c
blobf965293c788d8634f87cc7d7f9aa219b10ebdc6e
2 /******************************************************************************
4 * Module Name: exresolv - AML Interpreter object resolution
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13 * All rights reserved.
15 * 2. License
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.
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
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;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
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.
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.
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.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
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.
81 * 4. Disclaimer and Export Compliance
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.
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.
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.
115 *****************************************************************************/
117 #define __EXRESOLV_C__
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "amlcode.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
127 #define _COMPONENT ACPI_EXECUTER
128 ACPI_MODULE_NAME ("exresolv")
130 /* Local prototypes */
132 static ACPI_STATUS
133 AcpiExResolveObjectToValue (
134 ACPI_OPERAND_OBJECT **StackPtr,
135 ACPI_WALK_STATE *WalkState);
138 /*******************************************************************************
140 * FUNCTION: AcpiExResolveToValue
142 * PARAMETERS: **StackPtr - Points to entry on ObjStack, which can
143 * be either an (ACPI_OPERAND_OBJECT *)
144 * or an ACPI_HANDLE.
145 * WalkState - Current method state
147 * RETURN: Status
149 * DESCRIPTION: Convert Reference objects to values
151 ******************************************************************************/
153 ACPI_STATUS
154 AcpiExResolveToValue (
155 ACPI_OPERAND_OBJECT **StackPtr,
156 ACPI_WALK_STATE *WalkState)
158 ACPI_STATUS Status;
161 ACPI_FUNCTION_TRACE_PTR (ExResolveToValue, StackPtr);
164 if (!StackPtr || !*StackPtr)
166 ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
167 return_ACPI_STATUS (AE_AML_NO_OPERAND);
171 * The entity pointed to by the StackPtr can be either
172 * 1) A valid ACPI_OPERAND_OBJECT, or
173 * 2) A ACPI_NAMESPACE_NODE (NamedObj)
175 if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_OPERAND)
177 Status = AcpiExResolveObjectToValue (StackPtr, WalkState);
178 if (ACPI_FAILURE (Status))
180 return_ACPI_STATUS (Status);
183 if (!*StackPtr)
185 ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
186 return_ACPI_STATUS (AE_AML_NO_OPERAND);
191 * Object on the stack may have changed if AcpiExResolveObjectToValue()
192 * was called (i.e., we can't use an _else_ here.)
194 if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_NAMED)
196 Status = AcpiExResolveNodeToValue (
197 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, StackPtr),
198 WalkState);
199 if (ACPI_FAILURE (Status))
201 return_ACPI_STATUS (Status);
205 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Resolved object %p\n", *StackPtr));
206 return_ACPI_STATUS (AE_OK);
210 /*******************************************************************************
212 * FUNCTION: AcpiExResolveObjectToValue
214 * PARAMETERS: StackPtr - Pointer to an internal object
215 * WalkState - Current method state
217 * RETURN: Status
219 * DESCRIPTION: Retrieve the value from an internal object. The Reference type
220 * uses the associated AML opcode to determine the value.
222 ******************************************************************************/
224 static ACPI_STATUS
225 AcpiExResolveObjectToValue (
226 ACPI_OPERAND_OBJECT **StackPtr,
227 ACPI_WALK_STATE *WalkState)
229 ACPI_STATUS Status = AE_OK;
230 ACPI_OPERAND_OBJECT *StackDesc;
231 ACPI_OPERAND_OBJECT *ObjDesc = NULL;
232 UINT8 RefType;
235 ACPI_FUNCTION_TRACE (ExResolveObjectToValue);
238 StackDesc = *StackPtr;
240 /* This is an ACPI_OPERAND_OBJECT */
242 switch (StackDesc->Common.Type)
244 case ACPI_TYPE_LOCAL_REFERENCE:
246 RefType = StackDesc->Reference.Class;
248 switch (RefType)
250 case ACPI_REFCLASS_LOCAL:
251 case ACPI_REFCLASS_ARG:
254 * Get the local from the method's state info
255 * Note: this increments the local's object reference count
257 Status = AcpiDsMethodDataGetValue (RefType,
258 StackDesc->Reference.Value, WalkState, &ObjDesc);
259 if (ACPI_FAILURE (Status))
261 return_ACPI_STATUS (Status);
264 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %X] ValueObj is %p\n",
265 StackDesc->Reference.Value, ObjDesc));
268 * Now we can delete the original Reference Object and
269 * replace it with the resolved value
271 AcpiUtRemoveReference (StackDesc);
272 *StackPtr = ObjDesc;
273 break;
276 case ACPI_REFCLASS_INDEX:
278 switch (StackDesc->Reference.TargetType)
280 case ACPI_TYPE_BUFFER_FIELD:
282 /* Just return - do not dereference */
283 break;
286 case ACPI_TYPE_PACKAGE:
288 /* If method call or CopyObject - do not dereference */
290 if ((WalkState->Opcode == AML_INT_METHODCALL_OP) ||
291 (WalkState->Opcode == AML_COPY_OP))
293 break;
296 /* Otherwise, dereference the PackageIndex to a package element */
298 ObjDesc = *StackDesc->Reference.Where;
299 if (ObjDesc)
302 * Valid object descriptor, copy pointer to return value
303 * (i.e., dereference the package index)
304 * Delete the ref object, increment the returned object
306 AcpiUtRemoveReference (StackDesc);
307 AcpiUtAddReference (ObjDesc);
308 *StackPtr = ObjDesc;
310 else
313 * A NULL object descriptor means an uninitialized element of
314 * the package, can't dereference it
316 ACPI_ERROR ((AE_INFO,
317 "Attempt to dereference an Index to NULL package element Idx=%p",
318 StackDesc));
319 Status = AE_AML_UNINITIALIZED_ELEMENT;
321 break;
324 default:
326 /* Invalid reference object */
328 ACPI_ERROR ((AE_INFO,
329 "Unknown TargetType 0x%X in Index/Reference object %p",
330 StackDesc->Reference.TargetType, StackDesc));
331 Status = AE_AML_INTERNAL;
332 break;
334 break;
337 case ACPI_REFCLASS_REFOF:
338 case ACPI_REFCLASS_DEBUG:
339 case ACPI_REFCLASS_TABLE:
341 /* Just leave the object as-is, do not dereference */
343 break;
345 case ACPI_REFCLASS_NAME: /* Reference to a named object */
347 /* Dereference the name */
349 if ((StackDesc->Reference.Node->Type == ACPI_TYPE_DEVICE) ||
350 (StackDesc->Reference.Node->Type == ACPI_TYPE_THERMAL))
352 /* These node types do not have 'real' subobjects */
354 *StackPtr = (void *) StackDesc->Reference.Node;
356 else
358 /* Get the object pointed to by the namespace node */
360 *StackPtr = (StackDesc->Reference.Node)->Object;
361 AcpiUtAddReference (*StackPtr);
364 AcpiUtRemoveReference (StackDesc);
365 break;
367 default:
369 ACPI_ERROR ((AE_INFO,
370 "Unknown Reference type 0x%X in %p", RefType, StackDesc));
371 Status = AE_AML_INTERNAL;
372 break;
374 break;
377 case ACPI_TYPE_BUFFER:
379 Status = AcpiDsGetBufferArguments (StackDesc);
380 break;
383 case ACPI_TYPE_PACKAGE:
385 Status = AcpiDsGetPackageArguments (StackDesc);
386 break;
389 case ACPI_TYPE_BUFFER_FIELD:
390 case ACPI_TYPE_LOCAL_REGION_FIELD:
391 case ACPI_TYPE_LOCAL_BANK_FIELD:
392 case ACPI_TYPE_LOCAL_INDEX_FIELD:
394 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "FieldRead SourceDesc=%p Type=%X\n",
395 StackDesc, StackDesc->Common.Type));
397 Status = AcpiExReadDataFromField (WalkState, StackDesc, &ObjDesc);
399 /* Remove a reference to the original operand, then override */
401 AcpiUtRemoveReference (*StackPtr);
402 *StackPtr = (void *) ObjDesc;
403 break;
405 default:
406 break;
409 return_ACPI_STATUS (Status);
413 /*******************************************************************************
415 * FUNCTION: AcpiExResolveMultiple
417 * PARAMETERS: WalkState - Current state (contains AML opcode)
418 * Operand - Starting point for resolution
419 * ReturnType - Where the object type is returned
420 * ReturnDesc - Where the resolved object is returned
422 * RETURN: Status
424 * DESCRIPTION: Return the base object and type. Traverse a reference list if
425 * necessary to get to the base object.
427 ******************************************************************************/
429 ACPI_STATUS
430 AcpiExResolveMultiple (
431 ACPI_WALK_STATE *WalkState,
432 ACPI_OPERAND_OBJECT *Operand,
433 ACPI_OBJECT_TYPE *ReturnType,
434 ACPI_OPERAND_OBJECT **ReturnDesc)
436 ACPI_OPERAND_OBJECT *ObjDesc = (void *) Operand;
437 ACPI_NAMESPACE_NODE *Node;
438 ACPI_OBJECT_TYPE Type;
439 ACPI_STATUS Status;
442 ACPI_FUNCTION_TRACE (AcpiExResolveMultiple);
445 /* Operand can be either a namespace node or an operand descriptor */
447 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
449 case ACPI_DESC_TYPE_OPERAND:
450 Type = ObjDesc->Common.Type;
451 break;
453 case ACPI_DESC_TYPE_NAMED:
454 Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
455 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
457 /* If we had an Alias node, use the attached object for type info */
459 if (Type == ACPI_TYPE_LOCAL_ALIAS)
461 Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
462 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
464 break;
466 default:
467 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
470 /* If type is anything other than a reference, we are done */
472 if (Type != ACPI_TYPE_LOCAL_REFERENCE)
474 goto Exit;
478 * For reference objects created via the RefOf, Index, or Load/LoadTable
479 * operators, we need to get to the base object (as per the ACPI
480 * specification of the ObjectType and SizeOf operators). This means
481 * traversing the list of possibly many nested references.
483 while (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
485 switch (ObjDesc->Reference.Class)
487 case ACPI_REFCLASS_REFOF:
488 case ACPI_REFCLASS_NAME:
490 /* Dereference the reference pointer */
492 if (ObjDesc->Reference.Class == ACPI_REFCLASS_REFOF)
494 Node = ObjDesc->Reference.Object;
496 else /* AML_INT_NAMEPATH_OP */
498 Node = ObjDesc->Reference.Node;
501 /* All "References" point to a NS node */
503 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
505 ACPI_ERROR ((AE_INFO,
506 "Not a namespace node %p [%s]",
507 Node, AcpiUtGetDescriptorName (Node)));
508 return_ACPI_STATUS (AE_AML_INTERNAL);
511 /* Get the attached object */
513 ObjDesc = AcpiNsGetAttachedObject (Node);
514 if (!ObjDesc)
516 /* No object, use the NS node type */
518 Type = AcpiNsGetType (Node);
519 goto Exit;
522 /* Check for circular references */
524 if (ObjDesc == Operand)
526 return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
528 break;
531 case ACPI_REFCLASS_INDEX:
533 /* Get the type of this reference (index into another object) */
535 Type = ObjDesc->Reference.TargetType;
536 if (Type != ACPI_TYPE_PACKAGE)
538 goto Exit;
542 * The main object is a package, we want to get the type
543 * of the individual package element that is referenced by
544 * the index.
546 * This could of course in turn be another reference object.
548 ObjDesc = *(ObjDesc->Reference.Where);
549 if (!ObjDesc)
551 /* NULL package elements are allowed */
553 Type = 0; /* Uninitialized */
554 goto Exit;
556 break;
559 case ACPI_REFCLASS_TABLE:
561 Type = ACPI_TYPE_DDB_HANDLE;
562 goto Exit;
565 case ACPI_REFCLASS_LOCAL:
566 case ACPI_REFCLASS_ARG:
568 if (ReturnDesc)
570 Status = AcpiDsMethodDataGetValue (ObjDesc->Reference.Class,
571 ObjDesc->Reference.Value, WalkState, &ObjDesc);
572 if (ACPI_FAILURE (Status))
574 return_ACPI_STATUS (Status);
576 AcpiUtRemoveReference (ObjDesc);
578 else
580 Status = AcpiDsMethodDataGetNode (ObjDesc->Reference.Class,
581 ObjDesc->Reference.Value, WalkState, &Node);
582 if (ACPI_FAILURE (Status))
584 return_ACPI_STATUS (Status);
587 ObjDesc = AcpiNsGetAttachedObject (Node);
588 if (!ObjDesc)
590 Type = ACPI_TYPE_ANY;
591 goto Exit;
594 break;
597 case ACPI_REFCLASS_DEBUG:
599 /* The Debug Object is of type "DebugObject" */
601 Type = ACPI_TYPE_DEBUG_OBJECT;
602 goto Exit;
605 default:
607 ACPI_ERROR ((AE_INFO,
608 "Unknown Reference Class 0x%2.2X", ObjDesc->Reference.Class));
609 return_ACPI_STATUS (AE_AML_INTERNAL);
614 * Now we are guaranteed to have an object that has not been created
615 * via the RefOf or Index operators.
617 Type = ObjDesc->Common.Type;
620 Exit:
621 /* Convert internal types to external types */
623 switch (Type)
625 case ACPI_TYPE_LOCAL_REGION_FIELD:
626 case ACPI_TYPE_LOCAL_BANK_FIELD:
627 case ACPI_TYPE_LOCAL_INDEX_FIELD:
629 Type = ACPI_TYPE_FIELD_UNIT;
630 break;
632 case ACPI_TYPE_LOCAL_SCOPE:
634 /* Per ACPI Specification, Scope is untyped */
636 Type = ACPI_TYPE_ANY;
637 break;
639 default:
640 /* No change to Type required */
641 break;
644 *ReturnType = Type;
645 if (ReturnDesc)
647 *ReturnDesc = ObjDesc;
649 return_ACPI_STATUS (AE_OK);