Debian Codegraph @

source/components/executer/exconfig.c

raw symbols SCIP
1 /******************************************************************************
2 *
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2026, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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 MERCHANTABILITY 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.
42 */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acinterp.h"
47 #include "acnamesp.h"
48 #include "actables.h"
49 #include "acdispat.h"
50 #include "acevents.h"
51 #include "amlcode.h"
52
53
54 #define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exconfig")
56
57 /* Local prototypes */
58
59 static ACPI_STATUS
60 AcpiExAddTable (
61 UINT32 TableIndex,
62 ACPI_OPERAND_OBJECT **DdbHandle);
63
64 static ACPI_STATUS
65 AcpiExRegionRead (
66 ACPI_OPERAND_OBJECT *ObjDesc,
67 UINT32 Length,
68 UINT8 *Buffer);
69
70
71 /*******************************************************************************
72 *
73 * FUNCTION: AcpiExAddTable
74 *
75 * PARAMETERS: Table - Pointer to raw table
76 * ParentNode - Where to load the table (scope)
77 * DdbHandle - Where to return the table handle.
78 *
79 * RETURN: Status
80 *
81 * DESCRIPTION: Common function to Install and Load an ACPI table with a
82 * returned table handle.
83 *
84 ******************************************************************************/
85
86 static ACPI_STATUS
87 AcpiExAddTable (
88 UINT32 TableIndex,
89 ACPI_OPERAND_OBJECT **DdbHandle)
90 {
91 ACPI_OPERAND_OBJECT *ObjDesc;
92
93
94 ACPI_FUNCTION_TRACE (ExAddTable);
95
96
97 /* Create an object to be the table handle */
98
99 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
100 if (!ObjDesc)
101 {
102 return_ACPI_STATUS (AE_NO_MEMORY);
103 }
104
105 /* Init the table handle */
106
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);
112 }
113
114
115 /*******************************************************************************
116 *
117 * FUNCTION: AcpiExLoadTableOp
118 *
119 * PARAMETERS: WalkState - Current state with operands
120 * ReturnDesc - Where to store the return object
121 *
122 * RETURN: Status
123 *
124 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
125 *
126 ******************************************************************************/
127
128 ACPI_STATUS
129 AcpiExLoadTableOp (
130 ACPI_WALK_STATE *WalkState,
131 ACPI_OPERAND_OBJECT **ReturnDesc)
132 {
133 ACPI_STATUS Status;
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 *ReturnObj;
139 ACPI_OPERAND_OBJECT *DdbHandle;
140 UINT32 TableIndex;
141 char OemId[ACPI_OEM_ID_SIZE + 1];
142 char OemTableId[ACPI_OEM_TABLE_ID_SIZE + 1];
143
144
145 ACPI_FUNCTION_TRACE (ExLoadTableOp);
146
147
148 /* Create the return object */
149
150 ReturnObj = AcpiUtCreateIntegerObject ((UINT64) 0);
151 if (!ReturnObj)
152 {
153 return_ACPI_STATUS (AE_NO_MEMORY);
154 }
155
156 *ReturnDesc = ReturnObj;
157
158 /*
159 * Validate OEM ID and OEM Table ID string lengths.
160 * AcpiTbFindTable expects strings that can safely read
161 * ACPI_OEM_ID_SIZE and ACPI_OEM_TABLE_ID_SIZE bytes.
162 */
163 if ((Operand[1]->String.Length > ACPI_OEM_ID_SIZE) ||
164 (Operand[2]->String.Length > ACPI_OEM_TABLE_ID_SIZE))
165 {
166 return_ACPI_STATUS (AE_AML_STRING_LIMIT);
167 }
168
169 /*
170 * Copy OEM strings to local buffers with guaranteed null-termination.
171 * This prevents heap-buffer-overflow when AcpiTbFindTable reads
172 * ACPI_OEM_ID_SIZE/ACPI_OEM_TABLE_ID_SIZE bytes.
173 */
174 memcpy (OemId, Operand[1]->String.Pointer, Operand[1]->String.Length);
175 OemId[Operand[1]->String.Length] = 0;
176 memcpy (OemTableId, Operand[2]->String.Pointer, Operand[2]->String.Length);
177 OemTableId[Operand[2]->String.Length] = 0;
178
179 /* Find the ACPI table in the RSDT/XSDT */
180
181 AcpiExExitInterpreter ();
182 Status = AcpiTbFindTable (
183 Operand[0]->String.Pointer,
184 OemId,
185 OemTableId, &TableIndex);
186 AcpiExEnterInterpreter ();
187 if (ACPI_FAILURE (Status))
188 {
189 if (Status != AE_NOT_FOUND)
190 {
191 return_ACPI_STATUS (Status);
192 }
193
194 /* Table not found, return an Integer=0 and AE_OK */
195
196 return_ACPI_STATUS (AE_OK);
197 }
198
199 /* Default nodes */
200
201 StartNode = WalkState->ScopeInfo->Scope.Node;
202 ParentNode = AcpiGbl_RootNode;
203
204 /* RootPath (optional parameter) */
205
206 if (Operand[3]->String.Length > 0)
207 {
208 /*
209 * Find the node referenced by the RootPathString. This is the
210 * location within the namespace where the table will be loaded.
211 */
212 Status = AcpiNsGetNodeUnlocked (StartNode,
213 Operand[3]->String.Pointer, ACPI_NS_SEARCH_PARENT,
214 &ParentNode);
215 if (ACPI_FAILURE (Status))
216 {
217 return_ACPI_STATUS (Status);
218 }
219 }
220
221 /* ParameterPath (optional parameter) */
222
223 if (Operand[4]->String.Length > 0)
224 {
225 if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
226 (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
227 {
228 /*
229 * Path is not absolute, so it will be relative to the node
230 * referenced by the RootPathString (or the NS root if omitted)
231 */
232 StartNode = ParentNode;
233 }
234
235 /* Find the node referenced by the ParameterPathString */
236
237 Status = AcpiNsGetNodeUnlocked (StartNode,
238 Operand[4]->String.Pointer, ACPI_NS_SEARCH_PARENT,
239 &ParameterNode);
240 if (ACPI_FAILURE (Status))
241 {
242 return_ACPI_STATUS (Status);
243 }
244 }
245
246 /* Load the table into the namespace */
247
248 ACPI_INFO (("Dynamic OEM Table Load:"));
249 AcpiExExitInterpreter ();
250 Status = AcpiTbLoadTable (TableIndex, ParentNode);
251 AcpiExEnterInterpreter ();
252 if (ACPI_FAILURE (Status))
253 {
254 return_ACPI_STATUS (Status);
255 }
256
257 Status = AcpiExAddTable (TableIndex, &DdbHandle);
258 if (ACPI_FAILURE (Status))
259 {
260 return_ACPI_STATUS (Status);
261 }
262
263 /* Complete the initialization/resolution of new objects */
264
265 AcpiExExitInterpreter();
266 AcpiNsInitializeObjects();
267 AcpiExEnterInterpreter();
268
269 /* Parameter Data (optional) */
270
271 if (ParameterNode)
272 {
273 /* Store the parameter data into the optional parameter object */
274
275 Status = AcpiExStore (Operand[5],
276 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
277 if (ACPI_FAILURE (Status))
278 {
279 (void) AcpiExUnloadTable (DdbHandle);
280
281 AcpiUtRemoveReference (DdbHandle);
282 return_ACPI_STATUS (Status);
283 }
284 }
285
286 /* Remove the reference to DdbHandle created by AcpiExAddTable above */
287
288 AcpiUtRemoveReference (DdbHandle);
289
290 /* Return -1 (non-zero) indicates success */
291
292 ReturnObj->Integer.Value = 0xFFFFFFFFFFFFFFFF;
293 return_ACPI_STATUS (Status);
294 }
295
296
297 /*******************************************************************************
298 *
299 * FUNCTION: AcpiExRegionRead
300 *
301 * PARAMETERS: ObjDesc - Region descriptor
302 * Length - Number of bytes to read
303 * Buffer - Pointer to where to put the data
304 *
305 * RETURN: Status
306 *
307 * DESCRIPTION: Read data from an operation region. The read starts from the
308 * beginning of the region.
309 *
310 ******************************************************************************/
311
312 static ACPI_STATUS
313 AcpiExRegionRead (
314 ACPI_OPERAND_OBJECT *ObjDesc,
315 UINT32 Length,
316 UINT8 *Buffer)
317 {
318 ACPI_STATUS Status;
319 UINT64 Value;
320 UINT32 RegionOffset = 0;
321 UINT32 i;
322
323
324 /* Bytewise reads */
325
326 for (i = 0; i < Length; i++)
327 {
328 Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
329 RegionOffset, 8, &Value);
330 if (ACPI_FAILURE (Status))
331 {
332 return (Status);
333 }
334
335 *Buffer = (UINT8) Value;
336 Buffer++;
337 RegionOffset++;
338 }
339
340 return (AE_OK);
341 }
342
343
344 /*******************************************************************************
345 *
346 * FUNCTION: AcpiExLoadOp
347 *
348 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
349 * obtained
350 * Target - Where the status of the load will be stored
351 * WalkState - Current state
352 *
353 * RETURN: Status
354 *
355 * DESCRIPTION: Load an ACPI table from a field or operation region
356 *
357 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
358 * objects before this code is reached.
359 *
360 * If source is an operation region, it must refer to SystemMemory, as
361 * per the ACPI specification.
362 *
363 ******************************************************************************/
364
365 ACPI_STATUS
366 AcpiExLoadOp (
367 ACPI_OPERAND_OBJECT *ObjDesc,
368 ACPI_OPERAND_OBJECT *Target,
369 ACPI_WALK_STATE *WalkState)
370 {
371 ACPI_OPERAND_OBJECT *DdbHandle;
372 ACPI_TABLE_HEADER *TableHeader;
373 ACPI_TABLE_HEADER *Table;
374 UINT32 TableIndex;
375 ACPI_STATUS Status;
376 UINT32 Length;
377
378
379 ACPI_FUNCTION_TRACE (ExLoadOp);
380
381
382 if (Target->Common.DescriptorType == ACPI_DESC_TYPE_NAMED)
383 {
384 Target = AcpiNsGetAttachedObject (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Target));
385 }
386 if (Target->Common.Type != ACPI_TYPE_INTEGER)
387 {
388 ACPI_ERROR ((AE_INFO, "Type not integer: %X", Target->Common.Type));
389 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
390 }
391
392 Target->Integer.Value = 0;
393
394 /* Source Object can be either an OpRegion or a Buffer/Field */
395
396 switch (ObjDesc->Common.Type)
397 {
398 case ACPI_TYPE_REGION:
399
400 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
401 "Load table from Region %p\n", ObjDesc));
402
403 /* Region must be SystemMemory (from ACPI spec) */
404
405 if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
406 {
407 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
408 }
409
410 /*
411 * If the Region Address and Length have not been previously
412 * evaluated, evaluate them now and save the results.
413 */
414 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
415 {
416 Status = AcpiDsGetRegionArguments (ObjDesc);
417 if (ACPI_FAILURE (Status))
418 {
419 return_ACPI_STATUS (Status);
420 }
421 }
422
423 /* Get the table header first so we can get the table length */
424
425 TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
426 if (!TableHeader)
427 {
428 return_ACPI_STATUS (AE_NO_MEMORY);
429 }
430
431 Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
432 ACPI_CAST_PTR (UINT8, TableHeader));
433 Length = TableHeader->Length;
434 ACPI_FREE (TableHeader);
435
436 if (ACPI_FAILURE (Status))
437 {
438 return_ACPI_STATUS (Status);
439 }
440
441 /* Must have at least an ACPI table header */
442
443 if (Length < sizeof (ACPI_TABLE_HEADER))
444 {
445 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
446 }
447
448 /*
449 * The original implementation simply mapped the table, with no copy.
450 * However, the memory region is not guaranteed to remain stable and
451 * we must copy the table to a local buffer. For example, the memory
452 * region is corrupted after suspend on some machines. Dynamically
453 * loaded tables are usually small, so this overhead is minimal.
454 *
455 * The latest implementation (5/2009) does not use a mapping at all.
456 * We use the low-level operation region interface to read the table
457 * instead of the obvious optimization of using a direct mapping.
458 * This maintains a consistent use of operation regions across the
459 * entire subsystem. This is important if additional processing must
460 * be performed in the (possibly user-installed) operation region
461 * handler. For example, AcpiExec and ASLTS depend on this.
462 */
463
464 /* Allocate a buffer for the table */
465
466 Table = ACPI_ALLOCATE (Length);
467 if (!Table)
468 {
469 return_ACPI_STATUS (AE_NO_MEMORY);
470 }
471
472 /* Read the entire table */
473
474 Status = AcpiExRegionRead (ObjDesc, Length,
475 ACPI_CAST_PTR (UINT8, Table));
476 if (ACPI_FAILURE (Status))
477 {
478 ACPI_FREE (Table);
479 return_ACPI_STATUS (Status);
480 }
481 break;
482
483 case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
484
485 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
486 "Load table from Buffer or Field %p\n", ObjDesc));
487
488 /* Must have at least an ACPI table header */
489
490 if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
491 {
492 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
493 }
494
495 /* Get the actual table length from the table header */
496
497 TableHeader = ACPI_CAST_PTR (
498 ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
499 Length = TableHeader->Length;
500
501 /* Table cannot extend beyond the buffer */
502
503 if (Length > ObjDesc->Buffer.Length)
504 {
505 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
506 }
507 if (Length < sizeof (ACPI_TABLE_HEADER))
508 {
509 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
510 }
511
512 /*
513 * Copy the table from the buffer because the buffer could be
514 * modified or even deleted in the future
515 */
516 Table = ACPI_ALLOCATE (Length);
517 if (!Table)
518 {
519 return_ACPI_STATUS (AE_NO_MEMORY);
520 }
521
522 memcpy (Table, TableHeader, Length);
523 break;
524
525 default:
526
527 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
528 }
529
530 /* Install the new table into the local data structures */
531
532 ACPI_INFO (("Dynamic OEM Table Load:"));
533 AcpiExExitInterpreter ();
534 Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
535 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table, TRUE, &TableIndex);
536 AcpiExEnterInterpreter ();
537 if (ACPI_FAILURE (Status))
538 {
539 /* Delete allocated table buffer */
540
541 ACPI_FREE (Table);
542 return_ACPI_STATUS (Status);
543 }
544
545 /*
546 * Add the table to the namespace.
547 *
548 * Note: Load the table objects relative to the root of the namespace.
549 * This appears to go against the ACPI specification, but we do it for
550 * compatibility with other ACPI implementations.
551 */
552 Status = AcpiExAddTable (TableIndex, &DdbHandle);
553 if (ACPI_FAILURE (Status))
554 {
555 return_ACPI_STATUS (Status);
556 }
557
558 /* Complete the initialization/resolution of new objects */
559
560 AcpiExExitInterpreter ();
561 AcpiNsInitializeObjects ();
562 AcpiExEnterInterpreter ();
563
564 /* Remove the reference to DdbHandle created by AcpiExAddTable above */
565
566 AcpiUtRemoveReference (DdbHandle);
567
568 /* Return -1 (non-zero) indicates success */
569
570 Target->Integer.Value = 0xFFFFFFFFFFFFFFFF;
571 return_ACPI_STATUS (Status);
572 }
573
574
575 /*******************************************************************************
576 *
577 * FUNCTION: AcpiExUnloadTable
578 *
579 * PARAMETERS: DdbHandle - Handle to a previously loaded table
580 *
581 * RETURN: Status
582 *
583 * DESCRIPTION: Unload an ACPI table
584 *
585 ******************************************************************************/
586
587 ACPI_STATUS
588 AcpiExUnloadTable (
589 ACPI_OPERAND_OBJECT *DdbHandle)
590 {
591 ACPI_STATUS Status = AE_OK;
592 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
593 UINT32 TableIndex;
594
595
596 ACPI_FUNCTION_TRACE (ExUnloadTable);
597
598
599 /*
600 * Temporarily emit a warning so that the ASL for the machine can be
601 * hopefully obtained. This is to say that the Unload() operator is
602 * extremely rare if not completely unused.
603 */
604 ACPI_WARNING ((AE_INFO,
605 "Received request to unload an ACPI table"));
606
607 /*
608 * May 2018: Unload is no longer supported for the following reasons:
609 * 1) A correct implementation on some hosts may not be possible.
610 * 2) Other ACPI implementations do not correctly/fully support it.
611 * 3) It requires host device driver support which does not exist.
612 * (To properly support namespace unload out from underneath.)
613 * 4) This AML operator has never been seen in the field.
614 */
615 ACPI_EXCEPTION ((AE_INFO, AE_NOT_IMPLEMENTED,
616 "AML Unload operator is not supported"));
617
618 /*
619 * Validate the handle
620 * Although the handle is partially validated in AcpiExReconfiguration()
621 * when it calls AcpiExResolveOperands(), the handle is more completely
622 * validated here.
623 *
624 * Handle must be a valid operand object of type reference. Also, the
625 * DdbHandle must still be marked valid (table has not been previously
626 * unloaded)
627 */
628 if ((!DdbHandle) ||
629 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
630 (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
631 (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
632 {
633 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
634 }
635
636 /* Get the table index from the DdbHandle */
637
638 TableIndex = TableDesc->Reference.Value;
639
640 /*
641 * Release the interpreter lock so that the table lock won't have
642 * strict order requirement against it.
643 */
644 AcpiExExitInterpreter ();
645 Status = AcpiTbUnloadTable (TableIndex);
646 AcpiExEnterInterpreter ();
647
648 /*
649 * Invalidate the handle. We do this because the handle may be stored
650 * in a named object and may not be actually deleted until much later.
651 */
652 if (ACPI_SUCCESS (Status))
653 {
654 DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
655 }
656 return_ACPI_STATUS (Status);
657 }