Import acpica-unix-20061109 from Intel.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / interpreter / executer / exconfig.c
blobf7a46deeef8367ac005d79cc6701382324d6ce2c
1 /******************************************************************************
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4 * $Revision: 1.102 $
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2006, 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
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
118 #define __EXCONFIG_C__
120 #include "acpi.h"
121 #include "acinterp.h"
122 #include "amlcode.h"
123 #include "acnamesp.h"
124 #include "acevents.h"
125 #include "actables.h"
126 #include "acdispat.h"
129 #define _COMPONENT ACPI_EXECUTER
130 ACPI_MODULE_NAME ("exconfig")
132 /* Local prototypes */
134 static ACPI_STATUS
135 AcpiExAddTable (
136 ACPI_NATIVE_UINT TableIndex,
137 ACPI_NAMESPACE_NODE *ParentNode,
138 ACPI_OPERAND_OBJECT **DdbHandle);
141 /*******************************************************************************
143 * FUNCTION: AcpiExAddTable
145 * PARAMETERS: Table - Pointer to raw table
146 * ParentNode - Where to load the table (scope)
147 * DdbHandle - Where to return the table handle.
149 * RETURN: Status
151 * DESCRIPTION: Common function to Install and Load an ACPI table with a
152 * returned table handle.
154 ******************************************************************************/
156 static ACPI_STATUS
157 AcpiExAddTable (
158 ACPI_NATIVE_UINT TableIndex,
159 ACPI_NAMESPACE_NODE *ParentNode,
160 ACPI_OPERAND_OBJECT **DdbHandle)
162 ACPI_STATUS Status;
163 ACPI_OPERAND_OBJECT *ObjDesc;
166 ACPI_FUNCTION_TRACE (ExAddTable);
169 /* Create an object to be the table handle */
171 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
172 if (!ObjDesc)
174 return_ACPI_STATUS (AE_NO_MEMORY);
177 /* Init the table handle */
179 ObjDesc->Reference.Opcode = AML_LOAD_OP;
180 *DdbHandle = ObjDesc;
182 /* Install the new table into the local data structures */
184 ObjDesc->Reference.Object = ACPI_CAST_PTR (void, TableIndex);
186 /* Add the table to the namespace */
188 Status = AcpiNsLoadTable (TableIndex, ParentNode);
189 if (ACPI_FAILURE (Status))
191 AcpiUtRemoveReference (ObjDesc);
192 *DdbHandle = NULL;
195 return_ACPI_STATUS (Status);
199 /*******************************************************************************
201 * FUNCTION: AcpiExLoadTableOp
203 * PARAMETERS: WalkState - Current state with operands
204 * ReturnDesc - Where to store the return object
206 * RETURN: Status
208 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
210 ******************************************************************************/
212 ACPI_STATUS
213 AcpiExLoadTableOp (
214 ACPI_WALK_STATE *WalkState,
215 ACPI_OPERAND_OBJECT **ReturnDesc)
217 ACPI_STATUS Status;
218 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
219 ACPI_NATIVE_UINT TableIndex;
220 ACPI_NAMESPACE_NODE *ParentNode;
221 ACPI_NAMESPACE_NODE *StartNode;
222 ACPI_NAMESPACE_NODE *ParameterNode = NULL;
223 ACPI_OPERAND_OBJECT *DdbHandle;
224 ACPI_TABLE_HEADER *Table;
227 ACPI_FUNCTION_TRACE (ExLoadTableOp);
230 /* Find the ACPI table in the RSDT/XSDT */
232 Status = AcpiTbFindTable (Operand[0]->String.Pointer,
233 Operand[1]->String.Pointer,
234 Operand[2]->String.Pointer, &TableIndex);
235 if (ACPI_FAILURE (Status))
237 if (Status != AE_NOT_FOUND)
239 return_ACPI_STATUS (Status);
242 /* Table not found, return an Integer=0 and AE_OK */
244 DdbHandle = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
245 if (!DdbHandle)
247 return_ACPI_STATUS (AE_NO_MEMORY);
250 DdbHandle->Integer.Value = 0;
251 *ReturnDesc = DdbHandle;
253 return_ACPI_STATUS (AE_OK);
256 /* Default nodes */
258 StartNode = WalkState->ScopeInfo->Scope.Node;
259 ParentNode = AcpiGbl_RootNode;
261 /* RootPath (optional parameter) */
263 if (Operand[3]->String.Length > 0)
266 * Find the node referenced by the RootPathString. This is the
267 * location within the namespace where the table will be loaded.
269 Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer,
270 ACPI_NS_SEARCH_PARENT, &ParentNode);
271 if (ACPI_FAILURE (Status))
273 return_ACPI_STATUS (Status);
277 /* ParameterPath (optional parameter) */
279 if (Operand[4]->String.Length > 0)
281 if ((Operand[4]->String.Pointer[0] != '\\') &&
282 (Operand[4]->String.Pointer[0] != '^'))
285 * Path is not absolute, so it will be relative to the node
286 * referenced by the RootPathString (or the NS root if omitted)
288 StartNode = ParentNode;
291 /* Find the node referenced by the ParameterPathString */
293 Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer,
294 ACPI_NS_SEARCH_PARENT, &ParameterNode);
295 if (ACPI_FAILURE (Status))
297 return_ACPI_STATUS (Status);
301 /* Load the table into the namespace */
303 Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle);
304 if (ACPI_FAILURE (Status))
306 return_ACPI_STATUS (Status);
309 /* Parameter Data (optional) */
311 if (ParameterNode)
313 /* Store the parameter data into the optional parameter object */
315 Status = AcpiExStore (Operand[5],
316 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode),
317 WalkState);
318 if (ACPI_FAILURE (Status))
320 (void) AcpiExUnloadTable (DdbHandle);
321 return_ACPI_STATUS (Status);
325 Status = AcpiGetTableByIndex (TableIndex, &Table);
326 if (ACPI_SUCCESS (Status))
328 ACPI_INFO ((AE_INFO,
329 "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]",
330 Table->Signature, Table->OemId, Table->OemTableId));
333 *ReturnDesc = DdbHandle;
334 return_ACPI_STATUS (Status);
338 /*******************************************************************************
340 * FUNCTION: AcpiExLoadOp
342 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
343 * obtained
344 * Target - Where a handle to the table will be stored
345 * WalkState - Current state
347 * RETURN: Status
349 * DESCRIPTION: Load an ACPI table from a field or operation region
351 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
352 * objects before this code is reached.
354 * If source is an operation region, it must refer to SystemMemory, as
355 * per the ACPI specification.
357 ******************************************************************************/
359 ACPI_STATUS
360 AcpiExLoadOp (
361 ACPI_OPERAND_OBJECT *ObjDesc,
362 ACPI_OPERAND_OBJECT *Target,
363 ACPI_WALK_STATE *WalkState)
365 ACPI_OPERAND_OBJECT *DdbHandle;
366 ACPI_TABLE_DESC TableDesc;
367 ACPI_NATIVE_UINT TableIndex;
368 ACPI_STATUS Status;
371 ACPI_FUNCTION_TRACE (ExLoadOp);
374 ACPI_MEMSET (&TableDesc, 0, sizeof (ACPI_TABLE_DESC));
375 TableDesc.Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
377 /* Source Object can be either an OpRegion or a Buffer/Field */
379 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
381 case ACPI_TYPE_REGION:
383 /* Region must be SystemMemory (from ACPI spec) */
385 if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
387 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
390 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Region %p %s\n",
391 ObjDesc, AcpiUtGetObjectTypeName (ObjDesc)));
394 * If the Region Address and Length have not been previously evaluated,
395 * evaluate them now and save the results.
397 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
399 Status = AcpiDsGetRegionArguments (ObjDesc);
400 if (ACPI_FAILURE (Status))
402 return_ACPI_STATUS (Status);
406 TableDesc.Address = ObjDesc->Region.Address;
407 TableDesc.Length = ObjDesc->Region.Length;
408 TableDesc.Flags = ACPI_TABLE_ORIGIN_MAPPED;
409 break;
411 case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
413 /* Simply extract the buffer from the buffer object */
415 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Buffer or Field %p %s\n",
416 ObjDesc, AcpiUtGetObjectTypeName (ObjDesc)));
418 TableDesc.Pointer = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
419 ObjDesc->Buffer.Pointer);
420 TableDesc.Length = TableDesc.Pointer->Length;
421 TableDesc.Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
423 ObjDesc->Buffer.Pointer = NULL;
424 break;
426 default:
427 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
431 * Install the new table into the local data structures
433 Status = AcpiTbAddTable (&TableDesc, &TableIndex);
434 if (ACPI_FAILURE (Status))
436 goto Cleanup;
439 Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle);
440 if (ACPI_FAILURE (Status))
442 /* On error, TablePtr was deallocated above */
444 return_ACPI_STATUS (Status);
447 /* Store the DdbHandle into the Target operand */
449 Status = AcpiExStore (DdbHandle, Target, WalkState);
450 if (ACPI_FAILURE (Status))
452 (void) AcpiExUnloadTable (DdbHandle);
454 /* TablePtr was deallocated above */
456 return_ACPI_STATUS (Status);
459 Cleanup:
460 if (ACPI_FAILURE (Status))
462 AcpiTbDeleteTable (&TableDesc);
464 return_ACPI_STATUS (Status);
468 /*******************************************************************************
470 * FUNCTION: AcpiExUnloadTable
472 * PARAMETERS: DdbHandle - Handle to a previously loaded table
474 * RETURN: Status
476 * DESCRIPTION: Unload an ACPI table
478 ******************************************************************************/
480 ACPI_STATUS
481 AcpiExUnloadTable (
482 ACPI_OPERAND_OBJECT *DdbHandle)
484 ACPI_STATUS Status = AE_OK;
485 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
486 ACPI_NATIVE_UINT TableIndex;
489 ACPI_FUNCTION_TRACE (ExUnloadTable);
493 * Validate the handle
494 * Although the handle is partially validated in AcpiExReconfiguration(),
495 * when it calls AcpiExResolveOperands(), the handle is more completely
496 * validated here.
498 if ((!DdbHandle) ||
499 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
500 (ACPI_GET_OBJECT_TYPE (DdbHandle) != ACPI_TYPE_LOCAL_REFERENCE))
502 return_ACPI_STATUS (AE_BAD_PARAMETER);
505 /* Get the table index from the DdbHandle */
507 TableIndex = (ACPI_NATIVE_UINT) TableDesc->Reference.Object;
510 * Delete the entire namespace under this table Node
511 * (Offset contains the TableId)
513 AcpiTbDeleteNamespaceByOwner (TableIndex);
514 AcpiTbReleaseOwnerId (TableIndex);
516 AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
518 /* Delete the table descriptor (DdbHandle) */
520 AcpiUtRemoveReference (TableDesc);
521 return_ACPI_STATUS (Status);