1 /******************************************************************************
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2019, 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_OPERAND_OBJECT
**DdbHandle
);
66 ACPI_OPERAND_OBJECT
*ObjDesc
,
71 /*******************************************************************************
73 * FUNCTION: AcpiExAddTable
75 * PARAMETERS: Table - Pointer to raw table
76 * ParentNode - Where to load the table (scope)
77 * DdbHandle - Where to return the table handle.
81 * DESCRIPTION: Common function to Install and Load an ACPI table with a
82 * returned table handle.
84 ******************************************************************************/
89 ACPI_OPERAND_OBJECT
**DdbHandle
)
91 ACPI_OPERAND_OBJECT
*ObjDesc
;
94 ACPI_FUNCTION_TRACE (ExAddTable
);
97 /* Create an object to be the table handle */
99 ObjDesc
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE
);
102 return_ACPI_STATUS (AE_NO_MEMORY
);
105 /* Init the table handle */
107 ObjDesc
->Common
.Flags
|= AOPOBJ_DATA_VALID
;
108 ObjDesc
->Reference
.Class
= ACPI_REFCLASS_TABLE
;
109 ObjDesc
->Reference
.Value
= TableIndex
;
110 *DdbHandle
= ObjDesc
;
111 return_ACPI_STATUS (AE_OK
);
115 /*******************************************************************************
117 * FUNCTION: AcpiExLoadTableOp
119 * PARAMETERS: WalkState - Current state with operands
120 * ReturnDesc - Where to store the return object
124 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
126 ******************************************************************************/
130 ACPI_WALK_STATE
*WalkState
,
131 ACPI_OPERAND_OBJECT
**ReturnDesc
)
134 ACPI_OPERAND_OBJECT
**Operand
= &WalkState
->Operands
[0];
135 ACPI_NAMESPACE_NODE
*ParentNode
;
136 ACPI_NAMESPACE_NODE
*StartNode
;
137 ACPI_NAMESPACE_NODE
*ParameterNode
= NULL
;
138 ACPI_OPERAND_OBJECT
*DdbHandle
;
142 ACPI_FUNCTION_TRACE (ExLoadTableOp
);
145 /* Find the ACPI table in the RSDT/XSDT */
147 AcpiExExitInterpreter ();
148 Status
= AcpiTbFindTable (
149 Operand
[0]->String
.Pointer
,
150 Operand
[1]->String
.Pointer
,
151 Operand
[2]->String
.Pointer
, &TableIndex
);
152 AcpiExEnterInterpreter ();
153 if (ACPI_FAILURE (Status
))
155 if (Status
!= AE_NOT_FOUND
)
157 return_ACPI_STATUS (Status
);
160 /* Table not found, return an Integer=0 and AE_OK */
162 DdbHandle
= AcpiUtCreateIntegerObject ((UINT64
) 0);
165 return_ACPI_STATUS (AE_NO_MEMORY
);
168 *ReturnDesc
= DdbHandle
;
169 return_ACPI_STATUS (AE_OK
);
174 StartNode
= WalkState
->ScopeInfo
->Scope
.Node
;
175 ParentNode
= AcpiGbl_RootNode
;
177 /* RootPath (optional parameter) */
179 if (Operand
[3]->String
.Length
> 0)
182 * Find the node referenced by the RootPathString. This is the
183 * location within the namespace where the table will be loaded.
185 Status
= AcpiNsGetNodeUnlocked (StartNode
,
186 Operand
[3]->String
.Pointer
, ACPI_NS_SEARCH_PARENT
,
188 if (ACPI_FAILURE (Status
))
190 return_ACPI_STATUS (Status
);
194 /* ParameterPath (optional parameter) */
196 if (Operand
[4]->String
.Length
> 0)
198 if ((Operand
[4]->String
.Pointer
[0] != AML_ROOT_PREFIX
) &&
199 (Operand
[4]->String
.Pointer
[0] != AML_PARENT_PREFIX
))
202 * Path is not absolute, so it will be relative to the node
203 * referenced by the RootPathString (or the NS root if omitted)
205 StartNode
= ParentNode
;
208 /* Find the node referenced by the ParameterPathString */
210 Status
= AcpiNsGetNodeUnlocked (StartNode
,
211 Operand
[4]->String
.Pointer
, ACPI_NS_SEARCH_PARENT
,
213 if (ACPI_FAILURE (Status
))
215 return_ACPI_STATUS (Status
);
219 /* Load the table into the namespace */
221 ACPI_INFO (("Dynamic OEM Table Load:"));
222 AcpiExExitInterpreter ();
223 Status
= AcpiTbLoadTable (TableIndex
, ParentNode
);
224 AcpiExEnterInterpreter ();
225 if (ACPI_FAILURE (Status
))
227 return_ACPI_STATUS (Status
);
230 Status
= AcpiExAddTable (TableIndex
, &DdbHandle
);
231 if (ACPI_FAILURE (Status
))
233 return_ACPI_STATUS (Status
);
236 /* Complete the initialization/resolution of new objects */
238 AcpiExExitInterpreter();
239 AcpiNsInitializeObjects();
240 AcpiExEnterInterpreter();
242 /* Parameter Data (optional) */
246 /* Store the parameter data into the optional parameter object */
248 Status
= AcpiExStore (Operand
[5],
249 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT
, ParameterNode
), WalkState
);
250 if (ACPI_FAILURE (Status
))
252 (void) AcpiExUnloadTable (DdbHandle
);
254 AcpiUtRemoveReference (DdbHandle
);
255 return_ACPI_STATUS (Status
);
259 *ReturnDesc
= DdbHandle
;
260 return_ACPI_STATUS (Status
);
264 /*******************************************************************************
266 * FUNCTION: AcpiExRegionRead
268 * PARAMETERS: ObjDesc - Region descriptor
269 * Length - Number of bytes to read
270 * Buffer - Pointer to where to put the data
274 * DESCRIPTION: Read data from an operation region. The read starts from the
275 * beginning of the region.
277 ******************************************************************************/
281 ACPI_OPERAND_OBJECT
*ObjDesc
,
287 UINT32 RegionOffset
= 0;
293 for (i
= 0; i
< Length
; i
++)
295 Status
= AcpiEvAddressSpaceDispatch (ObjDesc
, NULL
, ACPI_READ
,
296 RegionOffset
, 8, &Value
);
297 if (ACPI_FAILURE (Status
))
302 *Buffer
= (UINT8
) Value
;
311 /*******************************************************************************
313 * FUNCTION: AcpiExLoadOp
315 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
317 * Target - Where a handle to the table will be stored
318 * WalkState - Current state
322 * DESCRIPTION: Load an ACPI table from a field or operation region
324 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
325 * objects before this code is reached.
327 * If source is an operation region, it must refer to SystemMemory, as
328 * per the ACPI specification.
330 ******************************************************************************/
334 ACPI_OPERAND_OBJECT
*ObjDesc
,
335 ACPI_OPERAND_OBJECT
*Target
,
336 ACPI_WALK_STATE
*WalkState
)
338 ACPI_OPERAND_OBJECT
*DdbHandle
;
339 ACPI_TABLE_HEADER
*TableHeader
;
340 ACPI_TABLE_HEADER
*Table
;
346 ACPI_FUNCTION_TRACE (ExLoadOp
);
349 /* Source Object can be either an OpRegion or a Buffer/Field */
351 switch (ObjDesc
->Common
.Type
)
353 case ACPI_TYPE_REGION
:
355 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
356 "Load table from Region %p\n", ObjDesc
));
358 /* Region must be SystemMemory (from ACPI spec) */
360 if (ObjDesc
->Region
.SpaceId
!= ACPI_ADR_SPACE_SYSTEM_MEMORY
)
362 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
366 * If the Region Address and Length have not been previously
367 * evaluated, evaluate them now and save the results.
369 if (!(ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
))
371 Status
= AcpiDsGetRegionArguments (ObjDesc
);
372 if (ACPI_FAILURE (Status
))
374 return_ACPI_STATUS (Status
);
378 /* Get the table header first so we can get the table length */
380 TableHeader
= ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER
));
383 return_ACPI_STATUS (AE_NO_MEMORY
);
386 Status
= AcpiExRegionRead (ObjDesc
, sizeof (ACPI_TABLE_HEADER
),
387 ACPI_CAST_PTR (UINT8
, TableHeader
));
388 Length
= TableHeader
->Length
;
389 ACPI_FREE (TableHeader
);
391 if (ACPI_FAILURE (Status
))
393 return_ACPI_STATUS (Status
);
396 /* Must have at least an ACPI table header */
398 if (Length
< sizeof (ACPI_TABLE_HEADER
))
400 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
404 * The original implementation simply mapped the table, with no copy.
405 * However, the memory region is not guaranteed to remain stable and
406 * we must copy the table to a local buffer. For example, the memory
407 * region is corrupted after suspend on some machines. Dynamically
408 * loaded tables are usually small, so this overhead is minimal.
410 * The latest implementation (5/2009) does not use a mapping at all.
411 * We use the low-level operation region interface to read the table
412 * instead of the obvious optimization of using a direct mapping.
413 * This maintains a consistent use of operation regions across the
414 * entire subsystem. This is important if additional processing must
415 * be performed in the (possibly user-installed) operation region
416 * handler. For example, AcpiExec and ASLTS depend on this.
419 /* Allocate a buffer for the table */
421 Table
= ACPI_ALLOCATE (Length
);
424 return_ACPI_STATUS (AE_NO_MEMORY
);
427 /* Read the entire table */
429 Status
= AcpiExRegionRead (ObjDesc
, Length
,
430 ACPI_CAST_PTR (UINT8
, Table
));
431 if (ACPI_FAILURE (Status
))
434 return_ACPI_STATUS (Status
);
438 case ACPI_TYPE_BUFFER
: /* Buffer or resolved RegionField */
440 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
441 "Load table from Buffer or Field %p\n", ObjDesc
));
443 /* Must have at least an ACPI table header */
445 if (ObjDesc
->Buffer
.Length
< sizeof (ACPI_TABLE_HEADER
))
447 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
450 /* Get the actual table length from the table header */
452 TableHeader
= ACPI_CAST_PTR (
453 ACPI_TABLE_HEADER
, ObjDesc
->Buffer
.Pointer
);
454 Length
= TableHeader
->Length
;
456 /* Table cannot extend beyond the buffer */
458 if (Length
> ObjDesc
->Buffer
.Length
)
460 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT
);
462 if (Length
< sizeof (ACPI_TABLE_HEADER
))
464 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
468 * Copy the table from the buffer because the buffer could be
469 * modified or even deleted in the future
471 Table
= ACPI_ALLOCATE (Length
);
474 return_ACPI_STATUS (AE_NO_MEMORY
);
477 memcpy (Table
, TableHeader
, Length
);
482 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
485 /* Install the new table into the local data structures */
487 ACPI_INFO (("Dynamic OEM Table Load:"));
488 AcpiExExitInterpreter ();
489 Status
= AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table
),
490 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
, TRUE
, &TableIndex
);
491 AcpiExEnterInterpreter ();
492 if (ACPI_FAILURE (Status
))
494 /* Delete allocated table buffer */
497 return_ACPI_STATUS (Status
);
501 * Add the table to the namespace.
503 * Note: Load the table objects relative to the root of the namespace.
504 * This appears to go against the ACPI specification, but we do it for
505 * compatibility with other ACPI implementations.
507 Status
= AcpiExAddTable (TableIndex
, &DdbHandle
);
508 if (ACPI_FAILURE (Status
))
510 /* On error, TablePtr was deallocated above */
512 return_ACPI_STATUS (Status
);
515 /* Complete the initialization/resolution of new objects */
517 AcpiExExitInterpreter ();
518 AcpiNsInitializeObjects ();
519 AcpiExEnterInterpreter ();
521 /* Store the DdbHandle into the Target operand */
523 Status
= AcpiExStore (DdbHandle
, Target
, WalkState
);
524 if (ACPI_FAILURE (Status
))
526 (void) AcpiExUnloadTable (DdbHandle
);
528 /* TablePtr was deallocated above */
530 AcpiUtRemoveReference (DdbHandle
);
531 return_ACPI_STATUS (Status
);
534 /* Remove the reference by added by AcpiExStore above */
536 AcpiUtRemoveReference (DdbHandle
);
537 return_ACPI_STATUS (Status
);
541 /*******************************************************************************
543 * FUNCTION: AcpiExUnloadTable
545 * PARAMETERS: DdbHandle - Handle to a previously loaded table
549 * DESCRIPTION: Unload an ACPI table
551 ******************************************************************************/
555 ACPI_OPERAND_OBJECT
*DdbHandle
)
557 ACPI_STATUS Status
= AE_OK
;
558 ACPI_OPERAND_OBJECT
*TableDesc
= DdbHandle
;
562 ACPI_FUNCTION_TRACE (ExUnloadTable
);
566 * Temporarily emit a warning so that the ASL for the machine can be
567 * hopefully obtained. This is to say that the Unload() operator is
568 * extremely rare if not completely unused.
570 ACPI_WARNING ((AE_INFO
,
571 "Received request to unload an ACPI table"));
574 * May 2018: Unload is no longer supported for the following reasons:
575 * 1) A correct implementation on some hosts may not be possible.
576 * 2) Other ACPI implementations do not correctly/fully support it.
577 * 3) It requires host device driver support which does not exist.
578 * (To properly support namespace unload out from underneath.)
579 * 4) This AML operator has never been seen in the field.
581 ACPI_EXCEPTION ((AE_INFO
, AE_NOT_IMPLEMENTED
,
582 "AML Unload operator is not supported"));
585 * Validate the handle
586 * Although the handle is partially validated in AcpiExReconfiguration()
587 * when it calls AcpiExResolveOperands(), the handle is more completely
590 * Handle must be a valid operand object of type reference. Also, the
591 * DdbHandle must still be marked valid (table has not been previously
595 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle
) != ACPI_DESC_TYPE_OPERAND
) ||
596 (DdbHandle
->Common
.Type
!= ACPI_TYPE_LOCAL_REFERENCE
) ||
597 (!(DdbHandle
->Common
.Flags
& AOPOBJ_DATA_VALID
)))
599 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
602 /* Get the table index from the DdbHandle */
604 TableIndex
= TableDesc
->Reference
.Value
;
607 * Release the interpreter lock so that the table lock won't have
608 * strict order requirement against it.
610 AcpiExExitInterpreter ();
611 Status
= AcpiTbUnloadTable (TableIndex
);
612 AcpiExEnterInterpreter ();
615 * Invalidate the handle. We do this because the handle may be stored
616 * in a named object and may not be actually deleted until much later.
618 if (ACPI_SUCCESS (Status
))
620 DdbHandle
->Common
.Flags
&= ~AOPOBJ_DATA_VALID
;
622 return_ACPI_STATUS (Status
);