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.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acinterp.h>
47 #include <contrib/dev/acpica/include/acnamesp.h>
48 #include <contrib/dev/acpica/include/actables.h>
49 #include <contrib/dev/acpica/include/acdispat.h>
50 #include <contrib/dev/acpica/include/acevents.h>
51 #include <contrib/dev/acpica/include/amlcode.h>
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 /* Validate lengths for the Signature, OemId, and OemTableId strings */
183 if ((Operand[0]->String.Length > ACPI_NAME_SIZE) ||
184 (Operand[1]->String.Length > ACPI_OEM_ID_SIZE) ||
185 (Operand[2]->String.Length > ACPI_OEM_TABLE_ID_SIZE))
187 return_ACPI_STATUS (AE_AML_STRING_LIMIT);
190 /* Find the ACPI table in the RSDT/XSDT */
192 Status = AcpiTbFindTable (
193 Operand[0]->String.Pointer,
194 Operand[1]->String.Pointer,
195 Operand[2]->String.Pointer, &TableIndex);
196 if (ACPI_FAILURE (Status))
198 if (Status != AE_NOT_FOUND)
200 return_ACPI_STATUS (Status);
203 /* Table not found, return an Integer=0 and AE_OK */
205 DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0);
208 return_ACPI_STATUS (AE_NO_MEMORY);
211 *ReturnDesc = DdbHandle;
212 return_ACPI_STATUS (AE_OK);
217 StartNode = WalkState->ScopeInfo->Scope.Node;
218 ParentNode = AcpiGbl_RootNode;
220 /* RootPath (optional parameter) */
222 if (Operand[3]->String.Length > 0)
225 * Find the node referenced by the RootPathString. This is the
226 * location within the namespace where the table will be loaded.
228 Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer,
229 ACPI_NS_SEARCH_PARENT, &ParentNode);
230 if (ACPI_FAILURE (Status))
232 return_ACPI_STATUS (Status);
236 /* ParameterPath (optional parameter) */
238 if (Operand[4]->String.Length > 0)
240 if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
241 (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
244 * Path is not absolute, so it will be relative to the node
245 * referenced by the RootPathString (or the NS root if omitted)
247 StartNode = ParentNode;
250 /* Find the node referenced by the ParameterPathString */
252 Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer,
253 ACPI_NS_SEARCH_PARENT, &ParameterNode);
254 if (ACPI_FAILURE (Status))
256 return_ACPI_STATUS (Status);
260 /* Load the table into the namespace */
262 Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle);
263 if (ACPI_FAILURE (Status))
265 return_ACPI_STATUS (Status);
268 /* Parameter Data (optional) */
272 /* Store the parameter data into the optional parameter object */
274 Status = AcpiExStore (Operand[5],
275 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode),
277 if (ACPI_FAILURE (Status))
279 (void) AcpiExUnloadTable (DdbHandle);
281 AcpiUtRemoveReference (DdbHandle);
282 return_ACPI_STATUS (Status);
286 Status = AcpiGetTableByIndex (TableIndex, &Table);
287 if (ACPI_SUCCESS (Status))
289 ACPI_INFO ((AE_INFO, "Dynamic OEM Table Load:"));
290 AcpiTbPrintTableHeader (0, Table);
293 /* Invoke table handler if present */
295 if (AcpiGbl_TableHandler)
297 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
298 AcpiGbl_TableHandlerContext);
301 *ReturnDesc = DdbHandle;
302 return_ACPI_STATUS (Status);
306 /*******************************************************************************
308 * FUNCTION: AcpiExRegionRead
310 * PARAMETERS: ObjDesc - Region descriptor
311 * Length - Number of bytes to read
312 * Buffer - Pointer to where to put the data
316 * DESCRIPTION: Read data from an operation region. The read starts from the
317 * beginning of the region.
319 ******************************************************************************/
323 ACPI_OPERAND_OBJECT *ObjDesc,
329 UINT32 RegionOffset = 0;
335 for (i = 0; i < Length; i++)
337 Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
338 RegionOffset, 8, &Value);
339 if (ACPI_FAILURE (Status))
344 *Buffer = (UINT8) Value;
353 /*******************************************************************************
355 * FUNCTION: AcpiExLoadOp
357 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
359 * Target - Where a handle to the table will be stored
360 * WalkState - Current state
364 * DESCRIPTION: Load an ACPI table from a field or operation region
366 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
367 * objects before this code is reached.
369 * If source is an operation region, it must refer to SystemMemory, as
370 * per the ACPI specification.
372 ******************************************************************************/
376 ACPI_OPERAND_OBJECT *ObjDesc,
377 ACPI_OPERAND_OBJECT *Target,
378 ACPI_WALK_STATE *WalkState)
380 ACPI_OPERAND_OBJECT *DdbHandle;
381 ACPI_TABLE_HEADER *TableHeader;
382 ACPI_TABLE_HEADER *Table;
388 ACPI_FUNCTION_TRACE (ExLoadOp);
391 /* Source Object can be either an OpRegion or a Buffer/Field */
393 switch (ObjDesc->Common.Type)
395 case ACPI_TYPE_REGION:
397 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
398 "Load table from Region %p\n", ObjDesc));
400 /* Region must be SystemMemory (from ACPI spec) */
402 if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
404 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
408 * If the Region Address and Length have not been previously evaluated,
409 * evaluate them now and save the results.
411 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
413 Status = AcpiDsGetRegionArguments (ObjDesc);
414 if (ACPI_FAILURE (Status))
416 return_ACPI_STATUS (Status);
420 /* Get the table header first so we can get the table length */
422 TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
425 return_ACPI_STATUS (AE_NO_MEMORY);
428 Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
429 ACPI_CAST_PTR (UINT8, TableHeader));
430 Length = TableHeader->Length;
431 ACPI_FREE (TableHeader);
433 if (ACPI_FAILURE (Status))
435 return_ACPI_STATUS (Status);
438 /* Must have at least an ACPI table header */
440 if (Length < sizeof (ACPI_TABLE_HEADER))
442 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
446 * The original implementation simply mapped the table, with no copy.
447 * However, the memory region is not guaranteed to remain stable and
448 * we must copy the table to a local buffer. For example, the memory
449 * region is corrupted after suspend on some machines. Dynamically
450 * loaded tables are usually small, so this overhead is minimal.
452 * The latest implementation (5/2009) does not use a mapping at all.
453 * We use the low-level operation region interface to read the table
454 * instead of the obvious optimization of using a direct mapping.
455 * This maintains a consistent use of operation regions across the
456 * entire subsystem. This is important if additional processing must
457 * be performed in the (possibly user-installed) operation region
458 * handler. For example, AcpiExec and ASLTS depend on this.
461 /* Allocate a buffer for the table */
463 Table = ACPI_ALLOCATE (Length);
466 return_ACPI_STATUS (AE_NO_MEMORY);
469 /* Read the entire table */
471 Status = AcpiExRegionRead (ObjDesc, Length,
472 ACPI_CAST_PTR (UINT8, Table));
473 if (ACPI_FAILURE (Status))
476 return_ACPI_STATUS (Status);
480 case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
482 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
483 "Load table from Buffer or Field %p\n", ObjDesc));
485 /* Must have at least an ACPI table header */
487 if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
489 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
492 /* Get the actual table length from the table header */
494 TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
495 Length = TableHeader->Length;
497 /* Table cannot extend beyond the buffer */
499 if (Length > ObjDesc->Buffer.Length)
501 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
503 if (Length < sizeof (ACPI_TABLE_HEADER))
505 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
509 * Copy the table from the buffer because the buffer could be modified
510 * or even deleted in the future
512 Table = ACPI_ALLOCATE (Length);
515 return_ACPI_STATUS (AE_NO_MEMORY);
518 ACPI_MEMCPY (Table, TableHeader, Length);
523 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
526 /* Install the new table into the local data structures */
528 ACPI_INFO ((AE_INFO, "Dynamic OEM Table Load:"));
529 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
531 Status = AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table),
532 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, TRUE, TRUE,
535 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
536 if (ACPI_FAILURE (Status))
538 /* Delete allocated table buffer */
541 return_ACPI_STATUS (Status);
545 * Note: Now table is "INSTALLED", it must be validated before
548 Status = AcpiTbValidateTable (&AcpiGbl_RootTableList.Tables[TableIndex]);
549 if (ACPI_FAILURE (Status))
551 return_ACPI_STATUS (Status);
555 * Add the table to the namespace.
557 * Note: Load the table objects relative to the root of the namespace.
558 * This appears to go against the ACPI specification, but we do it for
559 * compatibility with other ACPI implementations.
561 Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle);
562 if (ACPI_FAILURE (Status))
564 /* On error, TablePtr was deallocated above */
566 return_ACPI_STATUS (Status);
569 /* Store the DdbHandle into the Target operand */
571 Status = AcpiExStore (DdbHandle, Target, WalkState);
572 if (ACPI_FAILURE (Status))
574 (void) AcpiExUnloadTable (DdbHandle);
576 /* TablePtr was deallocated above */
578 AcpiUtRemoveReference (DdbHandle);
579 return_ACPI_STATUS (Status);
582 /* Remove the reference by added by AcpiExStore above */
584 AcpiUtRemoveReference (DdbHandle);
586 /* Invoke table handler if present */
588 if (AcpiGbl_TableHandler)
590 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
591 AcpiGbl_TableHandlerContext);
594 return_ACPI_STATUS (Status);
598 /*******************************************************************************
600 * FUNCTION: AcpiExUnloadTable
602 * PARAMETERS: DdbHandle - Handle to a previously loaded table
606 * DESCRIPTION: Unload an ACPI table
608 ******************************************************************************/
612 ACPI_OPERAND_OBJECT *DdbHandle)
614 ACPI_STATUS Status = AE_OK;
615 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
617 ACPI_TABLE_HEADER *Table;
620 ACPI_FUNCTION_TRACE (ExUnloadTable);
624 * Temporarily emit a warning so that the ASL for the machine can be
625 * hopefully obtained. This is to say that the Unload() operator is
626 * extremely rare if not completely unused.
628 ACPI_WARNING ((AE_INFO,
629 "Received request to unload an ACPI table"));
632 * Validate the handle
633 * Although the handle is partially validated in AcpiExReconfiguration()
634 * when it calls AcpiExResolveOperands(), the handle is more completely
637 * Handle must be a valid operand object of type reference. Also, the
638 * DdbHandle must still be marked valid (table has not been previously
642 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
643 (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
644 (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
646 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
649 /* Get the table index from the DdbHandle */
651 TableIndex = TableDesc->Reference.Value;
653 /* Ensure the table is still loaded */
655 if (!AcpiTbIsTableLoaded (TableIndex))
657 return_ACPI_STATUS (AE_NOT_EXIST);
660 /* Invoke table handler if present */
662 if (AcpiGbl_TableHandler)
664 Status = AcpiGetTableByIndex (TableIndex, &Table);
665 if (ACPI_SUCCESS (Status))
667 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table,
668 AcpiGbl_TableHandlerContext);
672 /* Delete the portion of the namespace owned by this table */
674 Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
675 if (ACPI_FAILURE (Status))
677 return_ACPI_STATUS (Status);
680 (void) AcpiTbReleaseOwnerId (TableIndex);
681 AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
684 * Invalidate the handle. We do this because the handle may be stored
685 * in a named object and may not be actually deleted until much later.
687 DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
688 return_ACPI_STATUS (AE_OK);