1 /******************************************************************************
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * 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
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
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 __EXCONFIG_C__
119 #include <contrib/dev/acpica/include/acpi.h>
120 #include <contrib/dev/acpica/include/accommon.h>
121 #include <contrib/dev/acpica/include/acinterp.h>
122 #include <contrib/dev/acpica/include/acnamesp.h>
123 #include <contrib/dev/acpica/include/actables.h>
124 #include <contrib/dev/acpica/include/acdispat.h>
125 #include <contrib/dev/acpica/include/acevents.h>
128 #define _COMPONENT ACPI_EXECUTER
129 ACPI_MODULE_NAME ("exconfig")
131 /* Local prototypes */
136 ACPI_NAMESPACE_NODE *ParentNode,
137 ACPI_OPERAND_OBJECT **DdbHandle);
141 ACPI_OPERAND_OBJECT *ObjDesc,
146 /*******************************************************************************
148 * FUNCTION: AcpiExAddTable
150 * PARAMETERS: Table - Pointer to raw table
151 * ParentNode - Where to load the table (scope)
152 * DdbHandle - Where to return the table handle.
156 * DESCRIPTION: Common function to Install and Load an ACPI table with a
157 * returned table handle.
159 ******************************************************************************/
164 ACPI_NAMESPACE_NODE *ParentNode,
165 ACPI_OPERAND_OBJECT **DdbHandle)
168 ACPI_OPERAND_OBJECT *ObjDesc;
171 ACPI_FUNCTION_TRACE (ExAddTable);
174 /* Create an object to be the table handle */
176 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
179 return_ACPI_STATUS (AE_NO_MEMORY);
182 /* Init the table handle */
184 ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
185 ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
186 *DdbHandle = ObjDesc;
188 /* Install the new table into the local data structures */
190 ObjDesc->Reference.Value = TableIndex;
192 /* Add the table to the namespace */
194 Status = AcpiNsLoadTable (TableIndex, ParentNode);
195 if (ACPI_FAILURE (Status))
197 AcpiUtRemoveReference (ObjDesc);
199 return_ACPI_STATUS (Status);
202 /* Execute any module-level code that was found in the table */
204 AcpiExExitInterpreter ();
205 AcpiNsExecModuleCodeList ();
206 AcpiExEnterInterpreter ();
208 return_ACPI_STATUS (Status);
212 /*******************************************************************************
214 * FUNCTION: AcpiExLoadTableOp
216 * PARAMETERS: WalkState - Current state with operands
217 * ReturnDesc - Where to store the return object
221 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
223 ******************************************************************************/
227 ACPI_WALK_STATE *WalkState,
228 ACPI_OPERAND_OBJECT **ReturnDesc)
231 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
232 ACPI_NAMESPACE_NODE *ParentNode;
233 ACPI_NAMESPACE_NODE *StartNode;
234 ACPI_NAMESPACE_NODE *ParameterNode = NULL;
235 ACPI_OPERAND_OBJECT *DdbHandle;
236 ACPI_TABLE_HEADER *Table;
240 ACPI_FUNCTION_TRACE (ExLoadTableOp);
243 /* Validate lengths for the SignatureString, OEMIDString, OEMTableID */
245 if ((Operand[0]->String.Length > ACPI_NAME_SIZE) ||
246 (Operand[1]->String.Length > ACPI_OEM_ID_SIZE) ||
247 (Operand[2]->String.Length > ACPI_OEM_TABLE_ID_SIZE))
249 return_ACPI_STATUS (AE_BAD_PARAMETER);
252 /* Find the ACPI table in the RSDT/XSDT */
254 Status = AcpiTbFindTable (Operand[0]->String.Pointer,
255 Operand[1]->String.Pointer,
256 Operand[2]->String.Pointer, &TableIndex);
257 if (ACPI_FAILURE (Status))
259 if (Status != AE_NOT_FOUND)
261 return_ACPI_STATUS (Status);
264 /* Table not found, return an Integer=0 and AE_OK */
266 DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0);
269 return_ACPI_STATUS (AE_NO_MEMORY);
272 *ReturnDesc = DdbHandle;
273 return_ACPI_STATUS (AE_OK);
278 StartNode = WalkState->ScopeInfo->Scope.Node;
279 ParentNode = AcpiGbl_RootNode;
281 /* RootPath (optional parameter) */
283 if (Operand[3]->String.Length > 0)
286 * Find the node referenced by the RootPathString. This is the
287 * location within the namespace where the table will be loaded.
289 Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer,
290 ACPI_NS_SEARCH_PARENT, &ParentNode);
291 if (ACPI_FAILURE (Status))
293 return_ACPI_STATUS (Status);
297 /* ParameterPath (optional parameter) */
299 if (Operand[4]->String.Length > 0)
301 if ((Operand[4]->String.Pointer[0] != '\\') &&
302 (Operand[4]->String.Pointer[0] != '^'))
305 * Path is not absolute, so it will be relative to the node
306 * referenced by the RootPathString (or the NS root if omitted)
308 StartNode = ParentNode;
311 /* Find the node referenced by the ParameterPathString */
313 Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer,
314 ACPI_NS_SEARCH_PARENT, &ParameterNode);
315 if (ACPI_FAILURE (Status))
317 return_ACPI_STATUS (Status);
321 /* Load the table into the namespace */
323 Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle);
324 if (ACPI_FAILURE (Status))
326 return_ACPI_STATUS (Status);
329 /* Parameter Data (optional) */
333 /* Store the parameter data into the optional parameter object */
335 Status = AcpiExStore (Operand[5],
336 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode),
338 if (ACPI_FAILURE (Status))
340 (void) AcpiExUnloadTable (DdbHandle);
342 AcpiUtRemoveReference (DdbHandle);
343 return_ACPI_STATUS (Status);
347 Status = AcpiGetTableByIndex (TableIndex, &Table);
348 if (ACPI_SUCCESS (Status))
351 "Dynamic OEM Table Load - [%.4s] OemId [%.6s] OemTableId [%.8s]",
352 Table->Signature, Table->OemId, Table->OemTableId));
355 /* Invoke table handler if present */
357 if (AcpiGbl_TableHandler)
359 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
360 AcpiGbl_TableHandlerContext);
363 *ReturnDesc = DdbHandle;
364 return_ACPI_STATUS (Status);
368 /*******************************************************************************
370 * FUNCTION: AcpiExRegionRead
372 * PARAMETERS: ObjDesc - Region descriptor
373 * Length - Number of bytes to read
374 * Buffer - Pointer to where to put the data
378 * DESCRIPTION: Read data from an operation region. The read starts from the
379 * beginning of the region.
381 ******************************************************************************/
385 ACPI_OPERAND_OBJECT *ObjDesc,
391 UINT32 RegionOffset = 0;
397 for (i = 0; i < Length; i++)
399 Status = AcpiEvAddressSpaceDispatch (ObjDesc, ACPI_READ,
400 RegionOffset, 8, &Value);
401 if (ACPI_FAILURE (Status))
406 *Buffer = (UINT8) Value;
415 /*******************************************************************************
417 * FUNCTION: AcpiExLoadOp
419 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
421 * Target - Where a handle to the table will be stored
422 * WalkState - Current state
426 * DESCRIPTION: Load an ACPI table from a field or operation region
428 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
429 * objects before this code is reached.
431 * If source is an operation region, it must refer to SystemMemory, as
432 * per the ACPI specification.
434 ******************************************************************************/
438 ACPI_OPERAND_OBJECT *ObjDesc,
439 ACPI_OPERAND_OBJECT *Target,
440 ACPI_WALK_STATE *WalkState)
442 ACPI_OPERAND_OBJECT *DdbHandle;
443 ACPI_TABLE_HEADER *Table;
444 ACPI_TABLE_DESC TableDesc;
450 ACPI_FUNCTION_TRACE (ExLoadOp);
453 ACPI_MEMSET (&TableDesc, 0, sizeof (ACPI_TABLE_DESC));
455 /* Source Object can be either an OpRegion or a Buffer/Field */
457 switch (ObjDesc->Common.Type)
459 case ACPI_TYPE_REGION:
461 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
462 "Load table from Region %p\n", ObjDesc));
464 /* Region must be SystemMemory (from ACPI spec) */
466 if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
468 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
472 * If the Region Address and Length have not been previously evaluated,
473 * evaluate them now and save the results.
475 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
477 Status = AcpiDsGetRegionArguments (ObjDesc);
478 if (ACPI_FAILURE (Status))
480 return_ACPI_STATUS (Status);
484 /* Get the table header first so we can get the table length */
486 Table = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
489 return_ACPI_STATUS (AE_NO_MEMORY);
492 Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
493 ACPI_CAST_PTR (UINT8, Table));
494 Length = Table->Length;
497 if (ACPI_FAILURE (Status))
499 return_ACPI_STATUS (Status);
502 /* Must have at least an ACPI table header */
504 if (Length < sizeof (ACPI_TABLE_HEADER))
506 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
510 * The original implementation simply mapped the table, with no copy.
511 * However, the memory region is not guaranteed to remain stable and
512 * we must copy the table to a local buffer. For example, the memory
513 * region is corrupted after suspend on some machines. Dynamically
514 * loaded tables are usually small, so this overhead is minimal.
516 * The latest implementation (5/2009) does not use a mapping at all.
517 * We use the low-level operation region interface to read the table
518 * instead of the obvious optimization of using a direct mapping.
519 * This maintains a consistent use of operation regions across the
520 * entire subsystem. This is important if additional processing must
521 * be performed in the (possibly user-installed) operation region
522 * handler. For example, AcpiExec and ASLTS depend on this.
525 /* Allocate a buffer for the table */
527 TableDesc.Pointer = ACPI_ALLOCATE (Length);
528 if (!TableDesc.Pointer)
530 return_ACPI_STATUS (AE_NO_MEMORY);
533 /* Read the entire table */
535 Status = AcpiExRegionRead (ObjDesc, Length,
536 ACPI_CAST_PTR (UINT8, TableDesc.Pointer));
537 if (ACPI_FAILURE (Status))
539 ACPI_FREE (TableDesc.Pointer);
540 return_ACPI_STATUS (Status);
543 TableDesc.Address = ObjDesc->Region.Address;
547 case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
549 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
550 "Load table from Buffer or Field %p\n", ObjDesc));
552 /* Must have at least an ACPI table header */
554 if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
556 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
559 /* Get the actual table length from the table header */
561 Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
562 Length = Table->Length;
564 /* Table cannot extend beyond the buffer */
566 if (Length > ObjDesc->Buffer.Length)
568 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
570 if (Length < sizeof (ACPI_TABLE_HEADER))
572 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
576 * Copy the table from the buffer because the buffer could be modified
577 * or even deleted in the future
579 TableDesc.Pointer = ACPI_ALLOCATE (Length);
580 if (!TableDesc.Pointer)
582 return_ACPI_STATUS (AE_NO_MEMORY);
585 ACPI_MEMCPY (TableDesc.Pointer, Table, Length);
586 TableDesc.Address = ACPI_TO_INTEGER (TableDesc.Pointer);
591 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
594 /* Validate table checksum (will not get validated in TbAddTable) */
596 Status = AcpiTbVerifyChecksum (TableDesc.Pointer, Length);
597 if (ACPI_FAILURE (Status))
599 ACPI_FREE (TableDesc.Pointer);
600 return_ACPI_STATUS (Status);
603 /* Complete the table descriptor */
605 TableDesc.Length = Length;
606 TableDesc.Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
608 /* Install the new table into the local data structures */
610 Status = AcpiTbAddTable (&TableDesc, &TableIndex);
611 if (ACPI_FAILURE (Status))
613 /* Delete allocated table buffer */
615 AcpiTbDeleteTable (&TableDesc);
616 return_ACPI_STATUS (Status);
620 * Add the table to the namespace.
622 * Note: Load the table objects relative to the root of the namespace.
623 * This appears to go against the ACPI specification, but we do it for
624 * compatibility with other ACPI implementations.
626 Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle);
627 if (ACPI_FAILURE (Status))
629 /* On error, TablePtr was deallocated above */
631 return_ACPI_STATUS (Status);
634 /* Store the DdbHandle into the Target operand */
636 Status = AcpiExStore (DdbHandle, Target, WalkState);
637 if (ACPI_FAILURE (Status))
639 (void) AcpiExUnloadTable (DdbHandle);
641 /* TablePtr was deallocated above */
643 AcpiUtRemoveReference (DdbHandle);
644 return_ACPI_STATUS (Status);
647 /* Remove the reference by added by AcpiExStore above */
649 AcpiUtRemoveReference (DdbHandle);
651 /* Invoke table handler if present */
653 if (AcpiGbl_TableHandler)
655 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, TableDesc.Pointer,
656 AcpiGbl_TableHandlerContext);
659 return_ACPI_STATUS (Status);
663 /*******************************************************************************
665 * FUNCTION: AcpiExUnloadTable
667 * PARAMETERS: DdbHandle - Handle to a previously loaded table
671 * DESCRIPTION: Unload an ACPI table
673 ******************************************************************************/
677 ACPI_OPERAND_OBJECT *DdbHandle)
679 ACPI_STATUS Status = AE_OK;
680 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
682 ACPI_TABLE_HEADER *Table;
685 ACPI_FUNCTION_TRACE (ExUnloadTable);
689 * Validate the handle
690 * Although the handle is partially validated in AcpiExReconfiguration()
691 * when it calls AcpiExResolveOperands(), the handle is more completely
694 * Handle must be a valid operand object of type reference. Also, the
695 * DdbHandle must still be marked valid (table has not been previously
699 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
700 (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
701 (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
703 return_ACPI_STATUS (AE_BAD_PARAMETER);
706 /* Get the table index from the DdbHandle */
708 TableIndex = TableDesc->Reference.Value;
710 /* Ensure the table is still loaded */
712 if (!AcpiTbIsTableLoaded (TableIndex))
714 return_ACPI_STATUS (AE_NOT_EXIST);
717 /* Invoke table handler if present */
719 if (AcpiGbl_TableHandler)
721 Status = AcpiGetTableByIndex (TableIndex, &Table);
722 if (ACPI_SUCCESS (Status))
724 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table,
725 AcpiGbl_TableHandlerContext);
729 /* Delete the portion of the namespace owned by this table */
731 Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
732 if (ACPI_FAILURE (Status))
734 return_ACPI_STATUS (Status);
737 (void) AcpiTbReleaseOwnerId (TableIndex);
738 AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
741 * Invalidate the handle. We do this because the handle may be stored
742 * in a named object and may not be actually deleted until much later.
744 DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
745 return_ACPI_STATUS (AE_OK);