1 /******************************************************************************
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
54 #define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exconfig")
57 /* Local prototypes */
62 ACPI_NAMESPACE_NODE *ParentNode,
63 ACPI_OPERAND_OBJECT **DdbHandle);
67 ACPI_OPERAND_OBJECT *ObjDesc,
72 /*******************************************************************************
74 * FUNCTION: AcpiExAddTable
76 * PARAMETERS: Table - Pointer to raw table
77 * ParentNode - Where to load the table (scope)
78 * DdbHandle - Where to return the table handle.
82 * DESCRIPTION: Common function to Install and Load an ACPI table with a
83 * returned table handle.
85 ******************************************************************************/
90 ACPI_NAMESPACE_NODE *ParentNode,
91 ACPI_OPERAND_OBJECT **DdbHandle)
93 ACPI_OPERAND_OBJECT *ObjDesc;
95 ACPI_OWNER_ID OwnerId;
98 ACPI_FUNCTION_TRACE (ExAddTable);
101 /* Create an object to be the table handle */
103 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
106 return_ACPI_STATUS (AE_NO_MEMORY);
109 /* Init the table handle */
111 ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
112 ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
113 *DdbHandle = ObjDesc;
115 /* Install the new table into the local data structures */
117 ObjDesc->Reference.Value = TableIndex;
119 /* Add the table to the namespace */
121 Status = AcpiNsLoadTable (TableIndex, ParentNode);
122 if (ACPI_FAILURE (Status))
124 AcpiUtRemoveReference (ObjDesc);
126 return_ACPI_STATUS (Status);
129 /* Execute any module-level code that was found in the table */
131 AcpiExExitInterpreter ();
132 AcpiNsExecModuleCodeList ();
133 AcpiExEnterInterpreter ();
136 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
137 * responsible for discovering any new wake GPEs by running _PRW methods
138 * that may have been loaded by this table.
140 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
141 if (ACPI_SUCCESS (Status))
143 AcpiEvUpdateGpes (OwnerId);
146 return_ACPI_STATUS (AE_OK);
150 /*******************************************************************************
152 * FUNCTION: AcpiExLoadTableOp
154 * PARAMETERS: WalkState - Current state with operands
155 * ReturnDesc - Where to store the return object
159 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
161 ******************************************************************************/
165 ACPI_WALK_STATE *WalkState,
166 ACPI_OPERAND_OBJECT **ReturnDesc)
169 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
170 ACPI_NAMESPACE_NODE *ParentNode;
171 ACPI_NAMESPACE_NODE *StartNode;
172 ACPI_NAMESPACE_NODE *ParameterNode = NULL;
173 ACPI_OPERAND_OBJECT *DdbHandle;
174 ACPI_TABLE_HEADER *Table;
178 ACPI_FUNCTION_TRACE (ExLoadTableOp);
181 /* Find the ACPI table in the RSDT/XSDT */
183 Status = AcpiTbFindTable (
184 Operand[0]->String.Pointer,
185 Operand[1]->String.Pointer,
186 Operand[2]->String.Pointer, &TableIndex);
187 if (ACPI_FAILURE (Status))
189 if (Status != AE_NOT_FOUND)
191 return_ACPI_STATUS (Status);
194 /* Table not found, return an Integer=0 and AE_OK */
196 DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0);
199 return_ACPI_STATUS (AE_NO_MEMORY);
202 *ReturnDesc = DdbHandle;
203 return_ACPI_STATUS (AE_OK);
208 StartNode = WalkState->ScopeInfo->Scope.Node;
209 ParentNode = AcpiGbl_RootNode;
211 /* RootPath (optional parameter) */
213 if (Operand[3]->String.Length > 0)
216 * Find the node referenced by the RootPathString. This is the
217 * location within the namespace where the table will be loaded.
219 Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer,
220 ACPI_NS_SEARCH_PARENT, &ParentNode);
221 if (ACPI_FAILURE (Status))
223 return_ACPI_STATUS (Status);
227 /* ParameterPath (optional parameter) */
229 if (Operand[4]->String.Length > 0)
231 if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
232 (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
235 * Path is not absolute, so it will be relative to the node
236 * referenced by the RootPathString (or the NS root if omitted)
238 StartNode = ParentNode;
241 /* Find the node referenced by the ParameterPathString */
243 Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer,
244 ACPI_NS_SEARCH_PARENT, &ParameterNode);
245 if (ACPI_FAILURE (Status))
247 return_ACPI_STATUS (Status);
251 /* Load the table into the namespace */
253 Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle);
254 if (ACPI_FAILURE (Status))
256 return_ACPI_STATUS (Status);
259 /* Parameter Data (optional) */
263 /* Store the parameter data into the optional parameter object */
265 Status = AcpiExStore (Operand[5],
266 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
267 if (ACPI_FAILURE (Status))
269 (void) AcpiExUnloadTable (DdbHandle);
271 AcpiUtRemoveReference (DdbHandle);
272 return_ACPI_STATUS (Status);
276 Status = AcpiGetTableByIndex (TableIndex, &Table);
277 if (ACPI_SUCCESS (Status))
279 ACPI_INFO ((AE_INFO, "Dynamic OEM Table Load:"));
280 AcpiTbPrintTableHeader (0, Table);
283 /* Invoke table handler if present */
285 if (AcpiGbl_TableHandler)
287 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
288 AcpiGbl_TableHandlerContext);
291 *ReturnDesc = DdbHandle;
292 return_ACPI_STATUS (Status);
296 /*******************************************************************************
298 * FUNCTION: AcpiExRegionRead
300 * PARAMETERS: ObjDesc - Region descriptor
301 * Length - Number of bytes to read
302 * Buffer - Pointer to where to put the data
306 * DESCRIPTION: Read data from an operation region. The read starts from the
307 * beginning of the region.
309 ******************************************************************************/
313 ACPI_OPERAND_OBJECT *ObjDesc,
319 UINT32 RegionOffset = 0;
325 for (i = 0; i < Length; i++)
327 Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
328 RegionOffset, 8, &Value);
329 if (ACPI_FAILURE (Status))
334 *Buffer = (UINT8) Value;
343 /*******************************************************************************
345 * FUNCTION: AcpiExLoadOp
347 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
349 * Target - Where a handle to the table will be stored
350 * WalkState - Current state
354 * DESCRIPTION: Load an ACPI table from a field or operation region
356 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
357 * objects before this code is reached.
359 * If source is an operation region, it must refer to SystemMemory, as
360 * per the ACPI specification.
362 ******************************************************************************/
366 ACPI_OPERAND_OBJECT *ObjDesc,
367 ACPI_OPERAND_OBJECT *Target,
368 ACPI_WALK_STATE *WalkState)
370 ACPI_OPERAND_OBJECT *DdbHandle;
371 ACPI_TABLE_HEADER *TableHeader;
372 ACPI_TABLE_HEADER *Table;
378 ACPI_FUNCTION_TRACE (ExLoadOp);
381 /* Source Object can be either an OpRegion or a Buffer/Field */
383 switch (ObjDesc->Common.Type)
385 case ACPI_TYPE_REGION:
387 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
388 "Load table from Region %p\n", ObjDesc));
390 /* Region must be SystemMemory (from ACPI spec) */
392 if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
394 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
398 * If the Region Address and Length have not been previously
399 * evaluated, evaluate them now and save the results.
401 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
403 Status = AcpiDsGetRegionArguments (ObjDesc);
404 if (ACPI_FAILURE (Status))
406 return_ACPI_STATUS (Status);
410 /* Get the table header first so we can get the table length */
412 TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
415 return_ACPI_STATUS (AE_NO_MEMORY);
418 Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
419 ACPI_CAST_PTR (UINT8, TableHeader));
420 Length = TableHeader->Length;
421 ACPI_FREE (TableHeader);
423 if (ACPI_FAILURE (Status))
425 return_ACPI_STATUS (Status);
428 /* Must have at least an ACPI table header */
430 if (Length < sizeof (ACPI_TABLE_HEADER))
432 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
436 * The original implementation simply mapped the table, with no copy.
437 * However, the memory region is not guaranteed to remain stable and
438 * we must copy the table to a local buffer. For example, the memory
439 * region is corrupted after suspend on some machines. Dynamically
440 * loaded tables are usually small, so this overhead is minimal.
442 * The latest implementation (5/2009) does not use a mapping at all.
443 * We use the low-level operation region interface to read the table
444 * instead of the obvious optimization of using a direct mapping.
445 * This maintains a consistent use of operation regions across the
446 * entire subsystem. This is important if additional processing must
447 * be performed in the (possibly user-installed) operation region
448 * handler. For example, AcpiExec and ASLTS depend on this.
451 /* Allocate a buffer for the table */
453 Table = ACPI_ALLOCATE (Length);
456 return_ACPI_STATUS (AE_NO_MEMORY);
459 /* Read the entire table */
461 Status = AcpiExRegionRead (ObjDesc, Length,
462 ACPI_CAST_PTR (UINT8, Table));
463 if (ACPI_FAILURE (Status))
466 return_ACPI_STATUS (Status);
470 case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
472 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
473 "Load table from Buffer or Field %p\n", ObjDesc));
475 /* Must have at least an ACPI table header */
477 if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
479 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
482 /* Get the actual table length from the table header */
484 TableHeader = ACPI_CAST_PTR (
485 ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
486 Length = TableHeader->Length;
488 /* Table cannot extend beyond the buffer */
490 if (Length > ObjDesc->Buffer.Length)
492 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
494 if (Length < sizeof (ACPI_TABLE_HEADER))
496 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
500 * Copy the table from the buffer because the buffer could be
501 * modified or even deleted in the future
503 Table = ACPI_ALLOCATE (Length);
506 return_ACPI_STATUS (AE_NO_MEMORY);
509 memcpy (Table, TableHeader, Length);
514 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
517 /* Install the new table into the local data structures */
519 ACPI_INFO ((AE_INFO, "Dynamic OEM Table Load:"));
520 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
522 Status = AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table),
523 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, TRUE, TRUE,
526 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
527 if (ACPI_FAILURE (Status))
529 /* Delete allocated table buffer */
532 return_ACPI_STATUS (Status);
536 * Note: Now table is "INSTALLED", it must be validated before
539 Status = AcpiTbValidateTable (
540 &AcpiGbl_RootTableList.Tables[TableIndex]);
541 if (ACPI_FAILURE (Status))
543 return_ACPI_STATUS (Status);
547 * Add the table to the namespace.
549 * Note: Load the table objects relative to the root of the namespace.
550 * This appears to go against the ACPI specification, but we do it for
551 * compatibility with other ACPI implementations.
553 Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle);
554 if (ACPI_FAILURE (Status))
556 /* On error, TablePtr was deallocated above */
558 return_ACPI_STATUS (Status);
561 /* Store the DdbHandle into the Target operand */
563 Status = AcpiExStore (DdbHandle, Target, WalkState);
564 if (ACPI_FAILURE (Status))
566 (void) AcpiExUnloadTable (DdbHandle);
568 /* TablePtr was deallocated above */
570 AcpiUtRemoveReference (DdbHandle);
571 return_ACPI_STATUS (Status);
574 /* Remove the reference by added by AcpiExStore above */
576 AcpiUtRemoveReference (DdbHandle);
578 /* Invoke table handler if present */
580 if (AcpiGbl_TableHandler)
582 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
583 AcpiGbl_TableHandlerContext);
586 return_ACPI_STATUS (Status);
590 /*******************************************************************************
592 * FUNCTION: AcpiExUnloadTable
594 * PARAMETERS: DdbHandle - Handle to a previously loaded table
598 * DESCRIPTION: Unload an ACPI table
600 ******************************************************************************/
604 ACPI_OPERAND_OBJECT *DdbHandle)
606 ACPI_STATUS Status = AE_OK;
607 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
609 ACPI_TABLE_HEADER *Table;
612 ACPI_FUNCTION_TRACE (ExUnloadTable);
616 * Temporarily emit a warning so that the ASL for the machine can be
617 * hopefully obtained. This is to say that the Unload() operator is
618 * extremely rare if not completely unused.
620 ACPI_WARNING ((AE_INFO,
621 "Received request to unload an ACPI table"));
624 * Validate the handle
625 * Although the handle is partially validated in AcpiExReconfiguration()
626 * when it calls AcpiExResolveOperands(), the handle is more completely
629 * Handle must be a valid operand object of type reference. Also, the
630 * DdbHandle must still be marked valid (table has not been previously
634 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
635 (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
636 (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
638 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
641 /* Get the table index from the DdbHandle */
643 TableIndex = TableDesc->Reference.Value;
645 /* Ensure the table is still loaded */
647 if (!AcpiTbIsTableLoaded (TableIndex))
649 return_ACPI_STATUS (AE_NOT_EXIST);
652 /* Invoke table handler if present */
654 if (AcpiGbl_TableHandler)
656 Status = AcpiGetTableByIndex (TableIndex, &Table);
657 if (ACPI_SUCCESS (Status))
659 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table,
660 AcpiGbl_TableHandlerContext);
664 /* Delete the portion of the namespace owned by this table */
666 Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
667 if (ACPI_FAILURE (Status))
669 return_ACPI_STATUS (Status);
672 (void) AcpiTbReleaseOwnerId (TableIndex);
673 AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
676 * Invalidate the handle. We do this because the handle may be stored
677 * in a named object and may not be actually deleted until much later.
679 DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
680 return_ACPI_STATUS (AE_OK);