1 /******************************************************************************
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
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
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
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
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
73 * 3.4. Intel retains all right, title, and interest in and to the Original
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
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
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 <contrib/dev/acpica/acpi.h>
121 #include <contrib/dev/acpica/acinterp.h>
122 #include <contrib/dev/acpica/amlcode.h>
123 #include <contrib/dev/acpica/acnamesp.h>
124 #include <contrib/dev/acpica/acevents.h>
125 #include <contrib/dev/acpica/actables.h>
126 #include <contrib/dev/acpica/acdispat.h>
129 #define _COMPONENT ACPI_EXECUTER
130 ACPI_MODULE_NAME ("exconfig")
132 /* Local prototypes */
136 ACPI_TABLE_HEADER *Table,
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.
151 * DESCRIPTION: Common function to Install and Load an ACPI table with a
152 * returned table handle.
154 ******************************************************************************/
158 ACPI_TABLE_HEADER *Table,
159 ACPI_NAMESPACE_NODE *ParentNode,
160 ACPI_OPERAND_OBJECT **DdbHandle)
163 ACPI_TABLE_DESC TableInfo;
164 ACPI_OPERAND_OBJECT *ObjDesc;
167 ACPI_FUNCTION_TRACE ("ExAddTable");
170 /* Create an object to be the table handle */
172 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
175 return_ACPI_STATUS (AE_NO_MEMORY);
178 /* Init the table handle */
180 ObjDesc->Reference.Opcode = AML_LOAD_OP;
181 *DdbHandle = ObjDesc;
183 /* Install the new table into the local data structures */
185 ACPI_MEMSET (&TableInfo, 0, sizeof (ACPI_TABLE_DESC));
187 TableInfo.Type = ACPI_TABLE_SSDT;
188 TableInfo.Pointer = Table;
189 TableInfo.Length = (ACPI_SIZE) Table->Length;
190 TableInfo.Allocation = ACPI_MEM_ALLOCATED;
192 Status = AcpiTbInstallTable (&TableInfo);
193 ObjDesc->Reference.Object = TableInfo.InstalledDesc;
195 if (ACPI_FAILURE (Status))
197 if (Status == AE_ALREADY_EXISTS)
199 /* Table already exists, just return the handle */
201 return_ACPI_STATUS (AE_OK);
206 /* Add the table to the namespace */
208 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, ParentNode);
209 if (ACPI_FAILURE (Status))
211 /* Uninstall table on error */
213 (void) AcpiTbUninstallTable (TableInfo.InstalledDesc);
217 return_ACPI_STATUS (AE_OK);
221 AcpiUtRemoveReference (ObjDesc);
223 return_ACPI_STATUS (Status);
227 /*******************************************************************************
229 * FUNCTION: AcpiExLoadTableOp
231 * PARAMETERS: WalkState - Current state with operands
232 * ReturnDesc - Where to store the return object
236 * DESCRIPTION: Load an ACPI table
238 ******************************************************************************/
242 ACPI_WALK_STATE *WalkState,
243 ACPI_OPERAND_OBJECT **ReturnDesc)
246 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
247 ACPI_TABLE_HEADER *Table;
248 ACPI_NAMESPACE_NODE *ParentNode;
249 ACPI_NAMESPACE_NODE *StartNode;
250 ACPI_NAMESPACE_NODE *ParameterNode = NULL;
251 ACPI_OPERAND_OBJECT *DdbHandle;
254 ACPI_FUNCTION_TRACE ("ExLoadTableOp");
259 * Make sure that the signature does not match one of the tables that
262 Status = AcpiTbMatchSignature (Operand[0]->String.Pointer, NULL);
265 /* Signature matched -- don't allow override */
267 return_ACPI_STATUS (AE_ALREADY_EXISTS);
271 /* Find the ACPI table */
273 Status = AcpiTbFindTable (Operand[0]->String.Pointer,
274 Operand[1]->String.Pointer,
275 Operand[2]->String.Pointer, &Table);
276 if (ACPI_FAILURE (Status))
278 if (Status != AE_NOT_FOUND)
280 return_ACPI_STATUS (Status);
283 /* Table not found, return an Integer=0 and AE_OK */
285 DdbHandle = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
288 return_ACPI_STATUS (AE_NO_MEMORY);
291 DdbHandle->Integer.Value = 0;
292 *ReturnDesc = DdbHandle;
294 return_ACPI_STATUS (AE_OK);
299 StartNode = WalkState->ScopeInfo->Scope.Node;
300 ParentNode = AcpiGbl_RootNode;
302 /* RootPath (optional parameter) */
304 if (Operand[3]->String.Length > 0)
307 * Find the node referenced by the RootPathString. This is the
308 * location within the namespace where the table will be loaded.
310 Status = AcpiNsGetNodeByPath (Operand[3]->String.Pointer, StartNode,
311 ACPI_NS_SEARCH_PARENT, &ParentNode);
312 if (ACPI_FAILURE (Status))
314 return_ACPI_STATUS (Status);
318 /* ParameterPath (optional parameter) */
320 if (Operand[4]->String.Length > 0)
322 if ((Operand[4]->String.Pointer[0] != '\\') &&
323 (Operand[4]->String.Pointer[0] != '^'))
326 * Path is not absolute, so it will be relative to the node
327 * referenced by the RootPathString (or the NS root if omitted)
329 StartNode = ParentNode;
332 /* Find the node referenced by the ParameterPathString */
334 Status = AcpiNsGetNodeByPath (Operand[4]->String.Pointer, StartNode,
335 ACPI_NS_SEARCH_PARENT, &ParameterNode);
336 if (ACPI_FAILURE (Status))
338 return_ACPI_STATUS (Status);
342 /* Load the table into the namespace */
344 Status = AcpiExAddTable (Table, ParentNode, &DdbHandle);
345 if (ACPI_FAILURE (Status))
347 return_ACPI_STATUS (Status);
350 /* Parameter Data (optional) */
354 /* Store the parameter data into the optional parameter object */
356 Status = AcpiExStore (Operand[5],
357 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode),
359 if (ACPI_FAILURE (Status))
361 (void) AcpiExUnloadTable (DdbHandle);
362 return_ACPI_STATUS (Status);
366 *ReturnDesc = DdbHandle;
367 return_ACPI_STATUS (Status);
371 /*******************************************************************************
373 * FUNCTION: AcpiExLoadOp
375 * PARAMETERS: ObjDesc - Region or Field where the table will be
377 * Target - Where a handle to the table will be stored
378 * WalkState - Current state
382 * DESCRIPTION: Load an ACPI table from a field or operation region
384 ******************************************************************************/
388 ACPI_OPERAND_OBJECT *ObjDesc,
389 ACPI_OPERAND_OBJECT *Target,
390 ACPI_WALK_STATE *WalkState)
393 ACPI_OPERAND_OBJECT *DdbHandle;
394 ACPI_OPERAND_OBJECT *BufferDesc = NULL;
395 ACPI_TABLE_HEADER *TablePtr = NULL;
396 ACPI_PHYSICAL_ADDRESS Address;
397 ACPI_TABLE_HEADER TableHeader;
400 ACPI_FUNCTION_TRACE ("ExLoadOp");
403 /* Object can be either an OpRegion or a Field */
405 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
407 case ACPI_TYPE_REGION:
409 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Region %p %s\n",
410 ObjDesc, AcpiUtGetObjectTypeName (ObjDesc)));
413 * If the Region Address and Length have not been previously evaluated,
414 * evaluate them now and save the results.
416 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
418 Status = AcpiDsGetRegionArguments (ObjDesc);
419 if (ACPI_FAILURE (Status))
421 return_ACPI_STATUS (Status);
425 /* Get the base physical address of the region */
427 Address = ObjDesc->Region.Address;
429 /* Get the table length from the table header */
431 TableHeader.Length = 0;
432 for (i = 0; i < 8; i++)
434 Status = AcpiEvAddressSpaceDispatch (ObjDesc, ACPI_READ,
435 (ACPI_PHYSICAL_ADDRESS) (i + Address), 8,
436 ((UINT8 *) &TableHeader) + i);
437 if (ACPI_FAILURE (Status))
439 return_ACPI_STATUS (Status);
443 /* Sanity check the table length */
445 if (TableHeader.Length < sizeof (ACPI_TABLE_HEADER))
447 return_ACPI_STATUS (AE_BAD_HEADER);
450 /* Allocate a buffer for the entire table */
452 TablePtr = ACPI_MEM_ALLOCATE (TableHeader.Length);
455 return_ACPI_STATUS (AE_NO_MEMORY);
458 /* Get the entire table from the op region */
460 for (i = 0; i < TableHeader.Length; i++)
462 Status = AcpiEvAddressSpaceDispatch (ObjDesc, ACPI_READ,
463 (ACPI_PHYSICAL_ADDRESS) (i + Address), 8,
464 ((UINT8 *) TablePtr + i));
465 if (ACPI_FAILURE (Status))
473 case ACPI_TYPE_LOCAL_REGION_FIELD:
474 case ACPI_TYPE_LOCAL_BANK_FIELD:
475 case ACPI_TYPE_LOCAL_INDEX_FIELD:
477 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Field %p %s\n",
478 ObjDesc, AcpiUtGetObjectTypeName (ObjDesc)));
481 * The length of the field must be at least as large as the table.
482 * Read the entire field and thus the entire table. Buffer is
483 * allocated during the read.
485 Status = AcpiExReadDataFromField (WalkState, ObjDesc, &BufferDesc);
486 if (ACPI_FAILURE (Status))
488 return_ACPI_STATUS (Status);
491 TablePtr = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
492 BufferDesc->Buffer.Pointer);
494 /* All done with the BufferDesc, delete it */
496 BufferDesc->Buffer.Pointer = NULL;
497 AcpiUtRemoveReference (BufferDesc);
499 /* Sanity check the table length */
501 if (TablePtr->Length < sizeof (ACPI_TABLE_HEADER))
503 Status = AE_BAD_HEADER;
510 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
513 /* The table must be either an SSDT or a PSDT */
515 if ((!ACPI_STRNCMP (TablePtr->Signature,
516 AcpiGbl_TableData[ACPI_TABLE_PSDT].Signature,
517 AcpiGbl_TableData[ACPI_TABLE_PSDT].SigLength)) &&
518 (!ACPI_STRNCMP (TablePtr->Signature,
519 AcpiGbl_TableData[ACPI_TABLE_SSDT].Signature,
520 AcpiGbl_TableData[ACPI_TABLE_SSDT].SigLength)))
522 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
523 "Table has invalid signature [%4.4s], must be SSDT or PSDT\n",
524 TablePtr->Signature));
525 Status = AE_BAD_SIGNATURE;
529 /* Install the new table into the local data structures */
531 Status = AcpiExAddTable (TablePtr, AcpiGbl_RootNode, &DdbHandle);
532 if (ACPI_FAILURE (Status))
534 /* On error, TablePtr was deallocated above */
536 return_ACPI_STATUS (Status);
539 /* Store the DdbHandle into the Target operand */
541 Status = AcpiExStore (DdbHandle, Target, WalkState);
542 if (ACPI_FAILURE (Status))
544 (void) AcpiExUnloadTable (DdbHandle);
546 /* TablePtr was deallocated above */
548 return_ACPI_STATUS (Status);
552 if (ACPI_FAILURE (Status))
554 ACPI_MEM_FREE (TablePtr);
556 return_ACPI_STATUS (Status);
560 /*******************************************************************************
562 * FUNCTION: AcpiExUnloadTable
564 * PARAMETERS: DdbHandle - Handle to a previously loaded table
568 * DESCRIPTION: Unload an ACPI table
570 ******************************************************************************/
574 ACPI_OPERAND_OBJECT *DdbHandle)
576 ACPI_STATUS Status = AE_OK;
577 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
578 ACPI_TABLE_DESC *TableInfo;
581 ACPI_FUNCTION_TRACE ("ExUnloadTable");
585 * Validate the handle
586 * Although the handle is partially validated in AcpiExReconfiguration(),
587 * when it calls AcpiExResolveOperands(), the handle is more completely
591 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
592 (ACPI_GET_OBJECT_TYPE (DdbHandle) != ACPI_TYPE_LOCAL_REFERENCE))
594 return_ACPI_STATUS (AE_BAD_PARAMETER);
597 /* Get the actual table descriptor from the DdbHandle */
599 TableInfo = (ACPI_TABLE_DESC *) TableDesc->Reference.Object;
602 * Delete the entire namespace under this table Node
603 * (Offset contains the TableId)
605 AcpiNsDeleteNamespaceByOwner (TableInfo->OwnerId);
606 AcpiUtReleaseOwnerId (&TableInfo->OwnerId);
608 /* Delete the table itself */
610 (void) AcpiTbUninstallTable (TableInfo->InstalledDesc);
612 /* Delete the table descriptor (DdbHandle) */
614 AcpiUtRemoveReference (TableDesc);
615 return_ACPI_STATUS (Status);