1 /******************************************************************************
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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 if (AcpiGbl_GroupModuleLevelCode
)
134 AcpiNsExecModuleCodeList ();
136 AcpiExEnterInterpreter ();
139 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
140 * responsible for discovering any new wake GPEs by running _PRW methods
141 * that may have been loaded by this table.
143 Status
= AcpiTbGetOwnerId (TableIndex
, &OwnerId
);
144 if (ACPI_SUCCESS (Status
))
146 AcpiEvUpdateGpes (OwnerId
);
149 return_ACPI_STATUS (AE_OK
);
153 /*******************************************************************************
155 * FUNCTION: AcpiExLoadTableOp
157 * PARAMETERS: WalkState - Current state with operands
158 * ReturnDesc - Where to store the return object
162 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
164 ******************************************************************************/
168 ACPI_WALK_STATE
*WalkState
,
169 ACPI_OPERAND_OBJECT
**ReturnDesc
)
172 ACPI_OPERAND_OBJECT
**Operand
= &WalkState
->Operands
[0];
173 ACPI_NAMESPACE_NODE
*ParentNode
;
174 ACPI_NAMESPACE_NODE
*StartNode
;
175 ACPI_NAMESPACE_NODE
*ParameterNode
= NULL
;
176 ACPI_OPERAND_OBJECT
*DdbHandle
;
177 ACPI_TABLE_HEADER
*Table
;
181 ACPI_FUNCTION_TRACE (ExLoadTableOp
);
184 /* Find the ACPI table in the RSDT/XSDT */
186 Status
= AcpiTbFindTable (
187 Operand
[0]->String
.Pointer
,
188 Operand
[1]->String
.Pointer
,
189 Operand
[2]->String
.Pointer
, &TableIndex
);
190 if (ACPI_FAILURE (Status
))
192 if (Status
!= AE_NOT_FOUND
)
194 return_ACPI_STATUS (Status
);
197 /* Table not found, return an Integer=0 and AE_OK */
199 DdbHandle
= AcpiUtCreateIntegerObject ((UINT64
) 0);
202 return_ACPI_STATUS (AE_NO_MEMORY
);
205 *ReturnDesc
= DdbHandle
;
206 return_ACPI_STATUS (AE_OK
);
211 StartNode
= WalkState
->ScopeInfo
->Scope
.Node
;
212 ParentNode
= AcpiGbl_RootNode
;
214 /* RootPath (optional parameter) */
216 if (Operand
[3]->String
.Length
> 0)
219 * Find the node referenced by the RootPathString. This is the
220 * location within the namespace where the table will be loaded.
222 Status
= AcpiNsGetNode (StartNode
, Operand
[3]->String
.Pointer
,
223 ACPI_NS_SEARCH_PARENT
, &ParentNode
);
224 if (ACPI_FAILURE (Status
))
226 return_ACPI_STATUS (Status
);
230 /* ParameterPath (optional parameter) */
232 if (Operand
[4]->String
.Length
> 0)
234 if ((Operand
[4]->String
.Pointer
[0] != AML_ROOT_PREFIX
) &&
235 (Operand
[4]->String
.Pointer
[0] != AML_PARENT_PREFIX
))
238 * Path is not absolute, so it will be relative to the node
239 * referenced by the RootPathString (or the NS root if omitted)
241 StartNode
= ParentNode
;
244 /* Find the node referenced by the ParameterPathString */
246 Status
= AcpiNsGetNode (StartNode
, Operand
[4]->String
.Pointer
,
247 ACPI_NS_SEARCH_PARENT
, &ParameterNode
);
248 if (ACPI_FAILURE (Status
))
250 return_ACPI_STATUS (Status
);
254 /* Load the table into the namespace */
256 Status
= AcpiExAddTable (TableIndex
, ParentNode
, &DdbHandle
);
257 if (ACPI_FAILURE (Status
))
259 return_ACPI_STATUS (Status
);
262 /* Parameter Data (optional) */
266 /* Store the parameter data into the optional parameter object */
268 Status
= AcpiExStore (Operand
[5],
269 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT
, ParameterNode
), WalkState
);
270 if (ACPI_FAILURE (Status
))
272 (void) AcpiExUnloadTable (DdbHandle
);
274 AcpiUtRemoveReference (DdbHandle
);
275 return_ACPI_STATUS (Status
);
279 Status
= AcpiGetTableByIndex (TableIndex
, &Table
);
280 if (ACPI_SUCCESS (Status
))
282 ACPI_INFO (("Dynamic OEM Table Load:"));
283 AcpiTbPrintTableHeader (0, Table
);
286 /* Invoke table handler if present */
288 if (AcpiGbl_TableHandler
)
290 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD
, Table
,
291 AcpiGbl_TableHandlerContext
);
294 *ReturnDesc
= DdbHandle
;
295 return_ACPI_STATUS (Status
);
299 /*******************************************************************************
301 * FUNCTION: AcpiExRegionRead
303 * PARAMETERS: ObjDesc - Region descriptor
304 * Length - Number of bytes to read
305 * Buffer - Pointer to where to put the data
309 * DESCRIPTION: Read data from an operation region. The read starts from the
310 * beginning of the region.
312 ******************************************************************************/
316 ACPI_OPERAND_OBJECT
*ObjDesc
,
322 UINT32 RegionOffset
= 0;
328 for (i
= 0; i
< Length
; i
++)
330 Status
= AcpiEvAddressSpaceDispatch (ObjDesc
, NULL
, ACPI_READ
,
331 RegionOffset
, 8, &Value
);
332 if (ACPI_FAILURE (Status
))
337 *Buffer
= (UINT8
) Value
;
346 /*******************************************************************************
348 * FUNCTION: AcpiExLoadOp
350 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
352 * Target - Where a handle to the table will be stored
353 * WalkState - Current state
357 * DESCRIPTION: Load an ACPI table from a field or operation region
359 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
360 * objects before this code is reached.
362 * If source is an operation region, it must refer to SystemMemory, as
363 * per the ACPI specification.
365 ******************************************************************************/
369 ACPI_OPERAND_OBJECT
*ObjDesc
,
370 ACPI_OPERAND_OBJECT
*Target
,
371 ACPI_WALK_STATE
*WalkState
)
373 ACPI_OPERAND_OBJECT
*DdbHandle
;
374 ACPI_TABLE_HEADER
*TableHeader
;
375 ACPI_TABLE_HEADER
*Table
;
381 ACPI_FUNCTION_TRACE (ExLoadOp
);
384 /* Source Object can be either an OpRegion or a Buffer/Field */
386 switch (ObjDesc
->Common
.Type
)
388 case ACPI_TYPE_REGION
:
390 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
391 "Load table from Region %p\n", ObjDesc
));
393 /* Region must be SystemMemory (from ACPI spec) */
395 if (ObjDesc
->Region
.SpaceId
!= ACPI_ADR_SPACE_SYSTEM_MEMORY
)
397 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
401 * If the Region Address and Length have not been previously
402 * evaluated, evaluate them now and save the results.
404 if (!(ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
406 Status
= AcpiDsGetRegionArguments (ObjDesc
);
407 if (ACPI_FAILURE (Status
))
409 return_ACPI_STATUS (Status
);
413 /* Get the table header first so we can get the table length */
415 TableHeader
= ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER
));
418 return_ACPI_STATUS (AE_NO_MEMORY
);
421 Status
= AcpiExRegionRead (ObjDesc
, sizeof (ACPI_TABLE_HEADER
),
422 ACPI_CAST_PTR (UINT8
, TableHeader
));
423 Length
= TableHeader
->Length
;
424 ACPI_FREE (TableHeader
);
426 if (ACPI_FAILURE (Status
))
428 return_ACPI_STATUS (Status
);
431 /* Must have at least an ACPI table header */
433 if (Length
< sizeof (ACPI_TABLE_HEADER
))
435 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
439 * The original implementation simply mapped the table, with no copy.
440 * However, the memory region is not guaranteed to remain stable and
441 * we must copy the table to a local buffer. For example, the memory
442 * region is corrupted after suspend on some machines. Dynamically
443 * loaded tables are usually small, so this overhead is minimal.
445 * The latest implementation (5/2009) does not use a mapping at all.
446 * We use the low-level operation region interface to read the table
447 * instead of the obvious optimization of using a direct mapping.
448 * This maintains a consistent use of operation regions across the
449 * entire subsystem. This is important if additional processing must
450 * be performed in the (possibly user-installed) operation region
451 * handler. For example, AcpiExec and ASLTS depend on this.
454 /* Allocate a buffer for the table */
456 Table
= ACPI_ALLOCATE (Length
);
459 return_ACPI_STATUS (AE_NO_MEMORY
);
462 /* Read the entire table */
464 Status
= AcpiExRegionRead (ObjDesc
, Length
,
465 ACPI_CAST_PTR (UINT8
, Table
));
466 if (ACPI_FAILURE (Status
))
469 return_ACPI_STATUS (Status
);
473 case ACPI_TYPE_BUFFER
: /* Buffer or resolved RegionField */
475 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
476 "Load table from Buffer or Field %p\n", ObjDesc
));
478 /* Must have at least an ACPI table header */
480 if (ObjDesc
->Buffer
.Length
< sizeof (ACPI_TABLE_HEADER
))
482 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
485 /* Get the actual table length from the table header */
487 TableHeader
= ACPI_CAST_PTR (
488 ACPI_TABLE_HEADER
, ObjDesc
->Buffer
.Pointer
);
489 Length
= TableHeader
->Length
;
491 /* Table cannot extend beyond the buffer */
493 if (Length
> ObjDesc
->Buffer
.Length
)
495 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT
);
497 if (Length
< sizeof (ACPI_TABLE_HEADER
))
499 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
503 * Copy the table from the buffer because the buffer could be
504 * modified or even deleted in the future
506 Table
= ACPI_ALLOCATE (Length
);
509 return_ACPI_STATUS (AE_NO_MEMORY
);
512 memcpy (Table
, TableHeader
, Length
);
517 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
520 /* Install the new table into the local data structures */
522 ACPI_INFO (("Dynamic OEM Table Load:"));
523 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
525 Status
= AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table
),
526 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
, TRUE
, TRUE
,
529 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
530 if (ACPI_FAILURE (Status
))
532 /* Delete allocated table buffer */
535 return_ACPI_STATUS (Status
);
539 * Note: Now table is "INSTALLED", it must be validated before
542 Status
= AcpiTbValidateTable (
543 &AcpiGbl_RootTableList
.Tables
[TableIndex
]);
544 if (ACPI_FAILURE (Status
))
546 return_ACPI_STATUS (Status
);
550 * Add the table to the namespace.
552 * Note: Load the table objects relative to the root of the namespace.
553 * This appears to go against the ACPI specification, but we do it for
554 * compatibility with other ACPI implementations.
556 Status
= AcpiExAddTable (TableIndex
, AcpiGbl_RootNode
, &DdbHandle
);
557 if (ACPI_FAILURE (Status
))
559 /* On error, TablePtr was deallocated above */
561 return_ACPI_STATUS (Status
);
564 /* Store the DdbHandle into the Target operand */
566 Status
= AcpiExStore (DdbHandle
, Target
, WalkState
);
567 if (ACPI_FAILURE (Status
))
569 (void) AcpiExUnloadTable (DdbHandle
);
571 /* TablePtr was deallocated above */
573 AcpiUtRemoveReference (DdbHandle
);
574 return_ACPI_STATUS (Status
);
577 /* Remove the reference by added by AcpiExStore above */
579 AcpiUtRemoveReference (DdbHandle
);
581 /* Invoke table handler if present */
583 if (AcpiGbl_TableHandler
)
585 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD
, Table
,
586 AcpiGbl_TableHandlerContext
);
589 return_ACPI_STATUS (Status
);
593 /*******************************************************************************
595 * FUNCTION: AcpiExUnloadTable
597 * PARAMETERS: DdbHandle - Handle to a previously loaded table
601 * DESCRIPTION: Unload an ACPI table
603 ******************************************************************************/
607 ACPI_OPERAND_OBJECT
*DdbHandle
)
609 ACPI_STATUS Status
= AE_OK
;
610 ACPI_OPERAND_OBJECT
*TableDesc
= DdbHandle
;
612 ACPI_TABLE_HEADER
*Table
;
615 ACPI_FUNCTION_TRACE (ExUnloadTable
);
619 * Temporarily emit a warning so that the ASL for the machine can be
620 * hopefully obtained. This is to say that the Unload() operator is
621 * extremely rare if not completely unused.
623 ACPI_WARNING ((AE_INFO
,
624 "Received request to unload an ACPI table"));
627 * Validate the handle
628 * Although the handle is partially validated in AcpiExReconfiguration()
629 * when it calls AcpiExResolveOperands(), the handle is more completely
632 * Handle must be a valid operand object of type reference. Also, the
633 * DdbHandle must still be marked valid (table has not been previously
637 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle
) != ACPI_DESC_TYPE_OPERAND
) ||
638 (DdbHandle
->Common
.Type
!= ACPI_TYPE_LOCAL_REFERENCE
) ||
639 (!(DdbHandle
->Common
.Flags
& AOPOBJ_DATA_VALID
)))
641 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
644 /* Get the table index from the DdbHandle */
646 TableIndex
= TableDesc
->Reference
.Value
;
648 /* Ensure the table is still loaded */
650 if (!AcpiTbIsTableLoaded (TableIndex
))
652 return_ACPI_STATUS (AE_NOT_EXIST
);
655 /* Invoke table handler if present */
657 if (AcpiGbl_TableHandler
)
659 Status
= AcpiGetTableByIndex (TableIndex
, &Table
);
660 if (ACPI_SUCCESS (Status
))
662 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD
, Table
,
663 AcpiGbl_TableHandlerContext
);
667 /* Delete the portion of the namespace owned by this table */
669 Status
= AcpiTbDeleteNamespaceByOwner (TableIndex
);
670 if (ACPI_FAILURE (Status
))
672 return_ACPI_STATUS (Status
);
675 (void) AcpiTbReleaseOwnerId (TableIndex
);
676 AcpiTbSetTableLoadedFlag (TableIndex
, FALSE
);
679 * Invalidate the handle. We do this because the handle may be stored
680 * in a named object and may not be actually deleted until much later.
682 DdbHandle
->Common
.Flags
&= ~AOPOBJ_DATA_VALID
;
683 return_ACPI_STATUS (AE_OK
);