1 /******************************************************************************
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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 #define __EXCONFIG_C__
56 #define _COMPONENT ACPI_EXECUTER
57 ACPI_MODULE_NAME ("exconfig")
59 /* Local prototypes */
64 ACPI_NAMESPACE_NODE
*ParentNode
,
65 ACPI_OPERAND_OBJECT
**DdbHandle
);
69 ACPI_OPERAND_OBJECT
*ObjDesc
,
74 /*******************************************************************************
76 * FUNCTION: AcpiExAddTable
78 * PARAMETERS: Table - Pointer to raw table
79 * ParentNode - Where to load the table (scope)
80 * DdbHandle - Where to return the table handle.
84 * DESCRIPTION: Common function to Install and Load an ACPI table with a
85 * returned table handle.
87 ******************************************************************************/
92 ACPI_NAMESPACE_NODE
*ParentNode
,
93 ACPI_OPERAND_OBJECT
**DdbHandle
)
95 ACPI_OPERAND_OBJECT
*ObjDesc
;
97 ACPI_OWNER_ID OwnerId
;
100 ACPI_FUNCTION_TRACE (ExAddTable
);
103 /* Create an object to be the table handle */
105 ObjDesc
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE
);
108 return_ACPI_STATUS (AE_NO_MEMORY
);
111 /* Init the table handle */
113 ObjDesc
->Common
.Flags
|= AOPOBJ_DATA_VALID
;
114 ObjDesc
->Reference
.Class
= ACPI_REFCLASS_TABLE
;
115 *DdbHandle
= ObjDesc
;
117 /* Install the new table into the local data structures */
119 ObjDesc
->Reference
.Value
= TableIndex
;
121 /* Add the table to the namespace */
123 Status
= AcpiNsLoadTable (TableIndex
, ParentNode
);
124 if (ACPI_FAILURE (Status
))
126 AcpiUtRemoveReference (ObjDesc
);
128 return_ACPI_STATUS (Status
);
131 /* Execute any module-level code that was found in the table */
133 AcpiExExitInterpreter ();
134 AcpiNsExecModuleCodeList ();
135 AcpiExEnterInterpreter ();
138 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
139 * responsible for discovering any new wake GPEs by running _PRW methods
140 * that may have been loaded by this table.
142 Status
= AcpiTbGetOwnerId (TableIndex
, &OwnerId
);
143 if (ACPI_SUCCESS (Status
))
145 AcpiEvUpdateGpes (OwnerId
);
148 return_ACPI_STATUS (AE_OK
);
152 /*******************************************************************************
154 * FUNCTION: AcpiExLoadTableOp
156 * PARAMETERS: WalkState - Current state with operands
157 * ReturnDesc - Where to store the return object
161 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
163 ******************************************************************************/
167 ACPI_WALK_STATE
*WalkState
,
168 ACPI_OPERAND_OBJECT
**ReturnDesc
)
171 ACPI_OPERAND_OBJECT
**Operand
= &WalkState
->Operands
[0];
172 ACPI_NAMESPACE_NODE
*ParentNode
;
173 ACPI_NAMESPACE_NODE
*StartNode
;
174 ACPI_NAMESPACE_NODE
*ParameterNode
= NULL
;
175 ACPI_OPERAND_OBJECT
*DdbHandle
;
176 ACPI_TABLE_HEADER
*Table
;
180 ACPI_FUNCTION_TRACE (ExLoadTableOp
);
183 /* Validate lengths for the Signature, OemId, and OemTableId strings */
185 if ((Operand
[0]->String
.Length
> ACPI_NAME_SIZE
) ||
186 (Operand
[1]->String
.Length
> ACPI_OEM_ID_SIZE
) ||
187 (Operand
[2]->String
.Length
> ACPI_OEM_TABLE_ID_SIZE
))
189 return_ACPI_STATUS (AE_AML_STRING_LIMIT
);
192 /* Find the ACPI table in the RSDT/XSDT */
194 Status
= AcpiTbFindTable (
195 Operand
[0]->String
.Pointer
,
196 Operand
[1]->String
.Pointer
,
197 Operand
[2]->String
.Pointer
, &TableIndex
);
198 if (ACPI_FAILURE (Status
))
200 if (Status
!= AE_NOT_FOUND
)
202 return_ACPI_STATUS (Status
);
205 /* Table not found, return an Integer=0 and AE_OK */
207 DdbHandle
= AcpiUtCreateIntegerObject ((UINT64
) 0);
210 return_ACPI_STATUS (AE_NO_MEMORY
);
213 *ReturnDesc
= DdbHandle
;
214 return_ACPI_STATUS (AE_OK
);
219 StartNode
= WalkState
->ScopeInfo
->Scope
.Node
;
220 ParentNode
= AcpiGbl_RootNode
;
222 /* RootPath (optional parameter) */
224 if (Operand
[3]->String
.Length
> 0)
227 * Find the node referenced by the RootPathString. This is the
228 * location within the namespace where the table will be loaded.
230 Status
= AcpiNsGetNode (StartNode
, Operand
[3]->String
.Pointer
,
231 ACPI_NS_SEARCH_PARENT
, &ParentNode
);
232 if (ACPI_FAILURE (Status
))
234 return_ACPI_STATUS (Status
);
238 /* ParameterPath (optional parameter) */
240 if (Operand
[4]->String
.Length
> 0)
242 if ((Operand
[4]->String
.Pointer
[0] != AML_ROOT_PREFIX
) &&
243 (Operand
[4]->String
.Pointer
[0] != AML_PARENT_PREFIX
))
246 * Path is not absolute, so it will be relative to the node
247 * referenced by the RootPathString (or the NS root if omitted)
249 StartNode
= ParentNode
;
252 /* Find the node referenced by the ParameterPathString */
254 Status
= AcpiNsGetNode (StartNode
, Operand
[4]->String
.Pointer
,
255 ACPI_NS_SEARCH_PARENT
, &ParameterNode
);
256 if (ACPI_FAILURE (Status
))
258 return_ACPI_STATUS (Status
);
262 /* Load the table into the namespace */
264 Status
= AcpiExAddTable (TableIndex
, ParentNode
, &DdbHandle
);
265 if (ACPI_FAILURE (Status
))
267 return_ACPI_STATUS (Status
);
270 /* Parameter Data (optional) */
274 /* Store the parameter data into the optional parameter object */
276 Status
= AcpiExStore (Operand
[5],
277 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT
, ParameterNode
),
279 if (ACPI_FAILURE (Status
))
281 (void) AcpiExUnloadTable (DdbHandle
);
283 AcpiUtRemoveReference (DdbHandle
);
284 return_ACPI_STATUS (Status
);
288 Status
= AcpiGetTableByIndex (TableIndex
, &Table
);
289 if (ACPI_SUCCESS (Status
))
291 ACPI_INFO ((AE_INFO
, "Dynamic OEM Table Load:"));
292 AcpiTbPrintTableHeader (0, Table
);
295 /* Invoke table handler if present */
297 if (AcpiGbl_TableHandler
)
299 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD
, Table
,
300 AcpiGbl_TableHandlerContext
);
303 *ReturnDesc
= DdbHandle
;
304 return_ACPI_STATUS (Status
);
308 /*******************************************************************************
310 * FUNCTION: AcpiExRegionRead
312 * PARAMETERS: ObjDesc - Region descriptor
313 * Length - Number of bytes to read
314 * Buffer - Pointer to where to put the data
318 * DESCRIPTION: Read data from an operation region. The read starts from the
319 * beginning of the region.
321 ******************************************************************************/
325 ACPI_OPERAND_OBJECT
*ObjDesc
,
331 UINT32 RegionOffset
= 0;
337 for (i
= 0; i
< Length
; i
++)
339 Status
= AcpiEvAddressSpaceDispatch (ObjDesc
, NULL
, ACPI_READ
,
340 RegionOffset
, 8, &Value
);
341 if (ACPI_FAILURE (Status
))
346 *Buffer
= (UINT8
) Value
;
355 /*******************************************************************************
357 * FUNCTION: AcpiExLoadOp
359 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
361 * Target - Where a handle to the table will be stored
362 * WalkState - Current state
366 * DESCRIPTION: Load an ACPI table from a field or operation region
368 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
369 * objects before this code is reached.
371 * If source is an operation region, it must refer to SystemMemory, as
372 * per the ACPI specification.
374 ******************************************************************************/
378 ACPI_OPERAND_OBJECT
*ObjDesc
,
379 ACPI_OPERAND_OBJECT
*Target
,
380 ACPI_WALK_STATE
*WalkState
)
382 ACPI_OPERAND_OBJECT
*DdbHandle
;
383 ACPI_TABLE_HEADER
*Table
;
384 ACPI_TABLE_DESC TableDesc
;
390 ACPI_FUNCTION_TRACE (ExLoadOp
);
393 ACPI_MEMSET (&TableDesc
, 0, sizeof (ACPI_TABLE_DESC
));
395 /* Source Object can be either an OpRegion or a Buffer/Field */
397 switch (ObjDesc
->Common
.Type
)
399 case ACPI_TYPE_REGION
:
401 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
402 "Load table from Region %p\n", ObjDesc
));
404 /* Region must be SystemMemory (from ACPI spec) */
406 if (ObjDesc
->Region
.SpaceId
!= ACPI_ADR_SPACE_SYSTEM_MEMORY
)
408 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
412 * If the Region Address and Length have not been previously evaluated,
413 * evaluate them now and save the results.
415 if (!(ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
417 Status
= AcpiDsGetRegionArguments (ObjDesc
);
418 if (ACPI_FAILURE (Status
))
420 return_ACPI_STATUS (Status
);
424 /* Get the table header first so we can get the table length */
426 Table
= ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER
));
429 return_ACPI_STATUS (AE_NO_MEMORY
);
432 Status
= AcpiExRegionRead (ObjDesc
, sizeof (ACPI_TABLE_HEADER
),
433 ACPI_CAST_PTR (UINT8
, Table
));
434 Length
= Table
->Length
;
437 if (ACPI_FAILURE (Status
))
439 return_ACPI_STATUS (Status
);
442 /* Must have at least an ACPI table header */
444 if (Length
< sizeof (ACPI_TABLE_HEADER
))
446 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
450 * The original implementation simply mapped the table, with no copy.
451 * However, the memory region is not guaranteed to remain stable and
452 * we must copy the table to a local buffer. For example, the memory
453 * region is corrupted after suspend on some machines. Dynamically
454 * loaded tables are usually small, so this overhead is minimal.
456 * The latest implementation (5/2009) does not use a mapping at all.
457 * We use the low-level operation region interface to read the table
458 * instead of the obvious optimization of using a direct mapping.
459 * This maintains a consistent use of operation regions across the
460 * entire subsystem. This is important if additional processing must
461 * be performed in the (possibly user-installed) operation region
462 * handler. For example, AcpiExec and ASLTS depend on this.
465 /* Allocate a buffer for the table */
467 TableDesc
.Pointer
= ACPI_ALLOCATE (Length
);
468 if (!TableDesc
.Pointer
)
470 return_ACPI_STATUS (AE_NO_MEMORY
);
473 /* Read the entire table */
475 Status
= AcpiExRegionRead (ObjDesc
, Length
,
476 ACPI_CAST_PTR (UINT8
, TableDesc
.Pointer
));
477 if (ACPI_FAILURE (Status
))
479 ACPI_FREE (TableDesc
.Pointer
);
480 return_ACPI_STATUS (Status
);
483 TableDesc
.Address
= ObjDesc
->Region
.Address
;
486 case ACPI_TYPE_BUFFER
: /* Buffer or resolved RegionField */
488 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
489 "Load table from Buffer or Field %p\n", ObjDesc
));
491 /* Must have at least an ACPI table header */
493 if (ObjDesc
->Buffer
.Length
< sizeof (ACPI_TABLE_HEADER
))
495 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
498 /* Get the actual table length from the table header */
500 Table
= ACPI_CAST_PTR (ACPI_TABLE_HEADER
, ObjDesc
->Buffer
.Pointer
);
501 Length
= Table
->Length
;
503 /* Table cannot extend beyond the buffer */
505 if (Length
> ObjDesc
->Buffer
.Length
)
507 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT
);
509 if (Length
< sizeof (ACPI_TABLE_HEADER
))
511 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
515 * Copy the table from the buffer because the buffer could be modified
516 * or even deleted in the future
518 TableDesc
.Pointer
= ACPI_ALLOCATE (Length
);
519 if (!TableDesc
.Pointer
)
521 return_ACPI_STATUS (AE_NO_MEMORY
);
524 ACPI_MEMCPY (TableDesc
.Pointer
, Table
, Length
);
525 TableDesc
.Address
= ACPI_TO_INTEGER (TableDesc
.Pointer
);
530 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
533 /* Validate table checksum (will not get validated in TbAddTable) */
535 Status
= AcpiTbVerifyChecksum (TableDesc
.Pointer
, Length
);
536 if (ACPI_FAILURE (Status
))
538 ACPI_FREE (TableDesc
.Pointer
);
539 return_ACPI_STATUS (Status
);
542 /* Complete the table descriptor */
544 TableDesc
.Length
= Length
;
545 TableDesc
.Flags
= ACPI_TABLE_ORIGIN_ALLOCATED
;
547 /* Install the new table into the local data structures */
549 Status
= AcpiTbAddTable (&TableDesc
, &TableIndex
);
550 if (ACPI_FAILURE (Status
))
552 /* Delete allocated table buffer */
554 AcpiTbDeleteTable (&TableDesc
);
555 return_ACPI_STATUS (Status
);
559 * Add the table to the namespace.
561 * Note: Load the table objects relative to the root of the namespace.
562 * This appears to go against the ACPI specification, but we do it for
563 * compatibility with other ACPI implementations.
565 Status
= AcpiExAddTable (TableIndex
, AcpiGbl_RootNode
, &DdbHandle
);
566 if (ACPI_FAILURE (Status
))
568 /* On error, TablePtr was deallocated above */
570 return_ACPI_STATUS (Status
);
573 /* Store the DdbHandle into the Target operand */
575 Status
= AcpiExStore (DdbHandle
, Target
, WalkState
);
576 if (ACPI_FAILURE (Status
))
578 (void) AcpiExUnloadTable (DdbHandle
);
580 /* TablePtr was deallocated above */
582 AcpiUtRemoveReference (DdbHandle
);
583 return_ACPI_STATUS (Status
);
586 ACPI_INFO ((AE_INFO
, "Dynamic OEM Table Load:"));
587 AcpiTbPrintTableHeader (0, TableDesc
.Pointer
);
589 /* Remove the reference by added by AcpiExStore above */
591 AcpiUtRemoveReference (DdbHandle
);
593 /* Invoke table handler if present */
595 if (AcpiGbl_TableHandler
)
597 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD
, TableDesc
.Pointer
,
598 AcpiGbl_TableHandlerContext
);
601 return_ACPI_STATUS (Status
);
605 /*******************************************************************************
607 * FUNCTION: AcpiExUnloadTable
609 * PARAMETERS: DdbHandle - Handle to a previously loaded table
613 * DESCRIPTION: Unload an ACPI table
615 ******************************************************************************/
619 ACPI_OPERAND_OBJECT
*DdbHandle
)
621 ACPI_STATUS Status
= AE_OK
;
622 ACPI_OPERAND_OBJECT
*TableDesc
= DdbHandle
;
624 ACPI_TABLE_HEADER
*Table
;
627 ACPI_FUNCTION_TRACE (ExUnloadTable
);
631 * Validate the handle
632 * Although the handle is partially validated in AcpiExReconfiguration()
633 * when it calls AcpiExResolveOperands(), the handle is more completely
636 * Handle must be a valid operand object of type reference. Also, the
637 * DdbHandle must still be marked valid (table has not been previously
641 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle
) != ACPI_DESC_TYPE_OPERAND
) ||
642 (DdbHandle
->Common
.Type
!= ACPI_TYPE_LOCAL_REFERENCE
) ||
643 (!(DdbHandle
->Common
.Flags
& AOPOBJ_DATA_VALID
)))
645 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
648 /* Get the table index from the DdbHandle */
650 TableIndex
= TableDesc
->Reference
.Value
;
652 /* Ensure the table is still loaded */
654 if (!AcpiTbIsTableLoaded (TableIndex
))
656 return_ACPI_STATUS (AE_NOT_EXIST
);
659 /* Invoke table handler if present */
661 if (AcpiGbl_TableHandler
)
663 Status
= AcpiGetTableByIndex (TableIndex
, &Table
);
664 if (ACPI_SUCCESS (Status
))
666 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD
, Table
,
667 AcpiGbl_TableHandlerContext
);
671 /* Delete the portion of the namespace owned by this table */
673 Status
= AcpiTbDeleteNamespaceByOwner (TableIndex
);
674 if (ACPI_FAILURE (Status
))
676 return_ACPI_STATUS (Status
);
679 (void) AcpiTbReleaseOwnerId (TableIndex
);
680 AcpiTbSetTableLoadedFlag (TableIndex
, FALSE
);
683 * Invalidate the handle. We do this because the handle may be stored
684 * in a named object and may not be actually deleted until much later.
686 DdbHandle
->Common
.Flags
&= ~AOPOBJ_DATA_VALID
;
687 return_ACPI_STATUS (AE_OK
);