xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/executer/exconfig.c (revision e6eaad8615c4734498b9b800847d18bbe62782fa)
1 /******************************************************************************
2  *
3  * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2013, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government. In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 #define __EXCONFIG_C__
118 
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acinterp.h"
122 #include "acnamesp.h"
123 #include "actables.h"
124 #include "acdispat.h"
125 #include "acevents.h"
126 #include "amlcode.h"
127 
128 
129 #define _COMPONENT          ACPI_EXECUTER
130         ACPI_MODULE_NAME    ("exconfig")
131 
132 /* Local prototypes */
133 
134 static ACPI_STATUS
135 AcpiExAddTable (
136     UINT32                  TableIndex,
137     ACPI_NAMESPACE_NODE     *ParentNode,
138     ACPI_OPERAND_OBJECT     **DdbHandle);
139 
140 static ACPI_STATUS
141 AcpiExRegionRead (
142     ACPI_OPERAND_OBJECT     *ObjDesc,
143     UINT32                  Length,
144     UINT8                   *Buffer);
145 
146 
147 /*******************************************************************************
148  *
149  * FUNCTION:    AcpiExAddTable
150  *
151  * PARAMETERS:  Table               - Pointer to raw table
152  *              ParentNode          - Where to load the table (scope)
153  *              DdbHandle           - Where to return the table handle.
154  *
155  * RETURN:      Status
156  *
157  * DESCRIPTION: Common function to Install and Load an ACPI table with a
158  *              returned table handle.
159  *
160  ******************************************************************************/
161 
162 static ACPI_STATUS
163 AcpiExAddTable (
164     UINT32                  TableIndex,
165     ACPI_NAMESPACE_NODE     *ParentNode,
166     ACPI_OPERAND_OBJECT     **DdbHandle)
167 {
168     ACPI_OPERAND_OBJECT     *ObjDesc;
169     ACPI_STATUS             Status;
170     ACPI_OWNER_ID           OwnerId;
171 
172 
173     ACPI_FUNCTION_TRACE (ExAddTable);
174 
175 
176     /* Create an object to be the table handle */
177 
178     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
179     if (!ObjDesc)
180     {
181         return_ACPI_STATUS (AE_NO_MEMORY);
182     }
183 
184     /* Init the table handle */
185 
186     ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
187     ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
188     *DdbHandle = ObjDesc;
189 
190     /* Install the new table into the local data structures */
191 
192     ObjDesc->Reference.Value = TableIndex;
193 
194     /* Add the table to the namespace */
195 
196     Status = AcpiNsLoadTable (TableIndex, ParentNode);
197     if (ACPI_FAILURE (Status))
198     {
199         AcpiUtRemoveReference (ObjDesc);
200         *DdbHandle = NULL;
201         return_ACPI_STATUS (Status);
202     }
203 
204     /* Execute any module-level code that was found in the table */
205 
206     AcpiExExitInterpreter ();
207     AcpiNsExecModuleCodeList ();
208     AcpiExEnterInterpreter ();
209 
210     /*
211      * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
212      * responsible for discovering any new wake GPEs by running _PRW methods
213      * that may have been loaded by this table.
214      */
215     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
216     if (ACPI_SUCCESS (Status))
217     {
218         AcpiEvUpdateGpes (OwnerId);
219     }
220 
221     return_ACPI_STATUS (AE_OK);
222 }
223 
224 
225 /*******************************************************************************
226  *
227  * FUNCTION:    AcpiExLoadTableOp
228  *
229  * PARAMETERS:  WalkState           - Current state with operands
230  *              ReturnDesc          - Where to store the return object
231  *
232  * RETURN:      Status
233  *
234  * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
235  *
236  ******************************************************************************/
237 
238 ACPI_STATUS
239 AcpiExLoadTableOp (
240     ACPI_WALK_STATE         *WalkState,
241     ACPI_OPERAND_OBJECT     **ReturnDesc)
242 {
243     ACPI_STATUS             Status;
244     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
245     ACPI_NAMESPACE_NODE     *ParentNode;
246     ACPI_NAMESPACE_NODE     *StartNode;
247     ACPI_NAMESPACE_NODE     *ParameterNode = NULL;
248     ACPI_OPERAND_OBJECT     *DdbHandle;
249     ACPI_TABLE_HEADER       *Table;
250     UINT32                  TableIndex;
251 
252 
253     ACPI_FUNCTION_TRACE (ExLoadTableOp);
254 
255 
256     /* Validate lengths for the Signature, OemId, and OemTableId strings */
257 
258     if ((Operand[0]->String.Length > ACPI_NAME_SIZE) ||
259         (Operand[1]->String.Length > ACPI_OEM_ID_SIZE) ||
260         (Operand[2]->String.Length > ACPI_OEM_TABLE_ID_SIZE))
261     {
262         return_ACPI_STATUS (AE_AML_STRING_LIMIT);
263     }
264 
265     /* Find the ACPI table in the RSDT/XSDT */
266 
267     Status = AcpiTbFindTable (
268                 Operand[0]->String.Pointer,
269                 Operand[1]->String.Pointer,
270                 Operand[2]->String.Pointer, &TableIndex);
271     if (ACPI_FAILURE (Status))
272     {
273         if (Status != AE_NOT_FOUND)
274         {
275             return_ACPI_STATUS (Status);
276         }
277 
278         /* Table not found, return an Integer=0 and AE_OK */
279 
280         DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0);
281         if (!DdbHandle)
282         {
283             return_ACPI_STATUS (AE_NO_MEMORY);
284         }
285 
286         *ReturnDesc = DdbHandle;
287         return_ACPI_STATUS (AE_OK);
288     }
289 
290     /* Default nodes */
291 
292     StartNode = WalkState->ScopeInfo->Scope.Node;
293     ParentNode = AcpiGbl_RootNode;
294 
295     /* RootPath (optional parameter) */
296 
297     if (Operand[3]->String.Length > 0)
298     {
299         /*
300          * Find the node referenced by the RootPathString. This is the
301          * location within the namespace where the table will be loaded.
302          */
303         Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer,
304                     ACPI_NS_SEARCH_PARENT, &ParentNode);
305         if (ACPI_FAILURE (Status))
306         {
307             return_ACPI_STATUS (Status);
308         }
309     }
310 
311     /* ParameterPath (optional parameter) */
312 
313     if (Operand[4]->String.Length > 0)
314     {
315         if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
316             (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
317         {
318             /*
319              * Path is not absolute, so it will be relative to the node
320              * referenced by the RootPathString (or the NS root if omitted)
321              */
322             StartNode = ParentNode;
323         }
324 
325         /* Find the node referenced by the ParameterPathString */
326 
327         Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer,
328                     ACPI_NS_SEARCH_PARENT, &ParameterNode);
329         if (ACPI_FAILURE (Status))
330         {
331             return_ACPI_STATUS (Status);
332         }
333     }
334 
335     /* Load the table into the namespace */
336 
337     Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle);
338     if (ACPI_FAILURE (Status))
339     {
340         return_ACPI_STATUS (Status);
341     }
342 
343     /* Parameter Data (optional) */
344 
345     if (ParameterNode)
346     {
347         /* Store the parameter data into the optional parameter object */
348 
349         Status = AcpiExStore (Operand[5],
350                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode),
351                     WalkState);
352         if (ACPI_FAILURE (Status))
353         {
354             (void) AcpiExUnloadTable (DdbHandle);
355 
356             AcpiUtRemoveReference (DdbHandle);
357             return_ACPI_STATUS (Status);
358         }
359     }
360 
361     Status = AcpiGetTableByIndex (TableIndex, &Table);
362     if (ACPI_SUCCESS (Status))
363     {
364         ACPI_INFO ((AE_INFO, "Dynamic OEM Table Load:"));
365         AcpiTbPrintTableHeader (0, Table);
366     }
367 
368     /* Invoke table handler if present */
369 
370     if (AcpiGbl_TableHandler)
371     {
372         (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
373                     AcpiGbl_TableHandlerContext);
374     }
375 
376     *ReturnDesc = DdbHandle;
377     return_ACPI_STATUS (Status);
378 }
379 
380 
381 /*******************************************************************************
382  *
383  * FUNCTION:    AcpiExRegionRead
384  *
385  * PARAMETERS:  ObjDesc         - Region descriptor
386  *              Length          - Number of bytes to read
387  *              Buffer          - Pointer to where to put the data
388  *
389  * RETURN:      Status
390  *
391  * DESCRIPTION: Read data from an operation region. The read starts from the
392  *              beginning of the region.
393  *
394  ******************************************************************************/
395 
396 static ACPI_STATUS
397 AcpiExRegionRead (
398     ACPI_OPERAND_OBJECT     *ObjDesc,
399     UINT32                  Length,
400     UINT8                   *Buffer)
401 {
402     ACPI_STATUS             Status;
403     UINT64                  Value;
404     UINT32                  RegionOffset = 0;
405     UINT32                  i;
406 
407 
408     /* Bytewise reads */
409 
410     for (i = 0; i < Length; i++)
411     {
412         Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
413                     RegionOffset, 8, &Value);
414         if (ACPI_FAILURE (Status))
415         {
416             return (Status);
417         }
418 
419         *Buffer = (UINT8) Value;
420         Buffer++;
421         RegionOffset++;
422     }
423 
424     return (AE_OK);
425 }
426 
427 
428 /*******************************************************************************
429  *
430  * FUNCTION:    AcpiExLoadOp
431  *
432  * PARAMETERS:  ObjDesc         - Region or Buffer/Field where the table will be
433  *                                obtained
434  *              Target          - Where a handle to the table will be stored
435  *              WalkState       - Current state
436  *
437  * RETURN:      Status
438  *
439  * DESCRIPTION: Load an ACPI table from a field or operation region
440  *
441  * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
442  *       objects before this code is reached.
443  *
444  *       If source is an operation region, it must refer to SystemMemory, as
445  *       per the ACPI specification.
446  *
447  ******************************************************************************/
448 
449 ACPI_STATUS
450 AcpiExLoadOp (
451     ACPI_OPERAND_OBJECT     *ObjDesc,
452     ACPI_OPERAND_OBJECT     *Target,
453     ACPI_WALK_STATE         *WalkState)
454 {
455     ACPI_OPERAND_OBJECT     *DdbHandle;
456     ACPI_TABLE_HEADER       *Table;
457     ACPI_TABLE_DESC         TableDesc;
458     UINT32                  TableIndex;
459     ACPI_STATUS             Status;
460     UINT32                  Length;
461 
462 
463     ACPI_FUNCTION_TRACE (ExLoadOp);
464 
465 
466     ACPI_MEMSET (&TableDesc, 0, sizeof (ACPI_TABLE_DESC));
467 
468     /* Source Object can be either an OpRegion or a Buffer/Field */
469 
470     switch (ObjDesc->Common.Type)
471     {
472     case ACPI_TYPE_REGION:
473 
474         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
475             "Load table from Region %p\n", ObjDesc));
476 
477         /* Region must be SystemMemory (from ACPI spec) */
478 
479         if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
480         {
481             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
482         }
483 
484         /*
485          * If the Region Address and Length have not been previously evaluated,
486          * evaluate them now and save the results.
487          */
488         if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
489         {
490             Status = AcpiDsGetRegionArguments (ObjDesc);
491             if (ACPI_FAILURE (Status))
492             {
493                 return_ACPI_STATUS (Status);
494             }
495         }
496 
497         /* Get the table header first so we can get the table length */
498 
499         Table = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
500         if (!Table)
501         {
502             return_ACPI_STATUS (AE_NO_MEMORY);
503         }
504 
505         Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
506                     ACPI_CAST_PTR (UINT8, Table));
507         Length = Table->Length;
508         ACPI_FREE (Table);
509 
510         if (ACPI_FAILURE (Status))
511         {
512             return_ACPI_STATUS (Status);
513         }
514 
515         /* Must have at least an ACPI table header */
516 
517         if (Length < sizeof (ACPI_TABLE_HEADER))
518         {
519             return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
520         }
521 
522         /*
523          * The original implementation simply mapped the table, with no copy.
524          * However, the memory region is not guaranteed to remain stable and
525          * we must copy the table to a local buffer. For example, the memory
526          * region is corrupted after suspend on some machines. Dynamically
527          * loaded tables are usually small, so this overhead is minimal.
528          *
529          * The latest implementation (5/2009) does not use a mapping at all.
530          * We use the low-level operation region interface to read the table
531          * instead of the obvious optimization of using a direct mapping.
532          * This maintains a consistent use of operation regions across the
533          * entire subsystem. This is important if additional processing must
534          * be performed in the (possibly user-installed) operation region
535          * handler. For example, AcpiExec and ASLTS depend on this.
536          */
537 
538         /* Allocate a buffer for the table */
539 
540         TableDesc.Pointer = ACPI_ALLOCATE (Length);
541         if (!TableDesc.Pointer)
542         {
543             return_ACPI_STATUS (AE_NO_MEMORY);
544         }
545 
546         /* Read the entire table */
547 
548         Status = AcpiExRegionRead (ObjDesc, Length,
549                     ACPI_CAST_PTR (UINT8, TableDesc.Pointer));
550         if (ACPI_FAILURE (Status))
551         {
552             ACPI_FREE (TableDesc.Pointer);
553             return_ACPI_STATUS (Status);
554         }
555 
556         TableDesc.Address = ObjDesc->Region.Address;
557         break;
558 
559     case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
560 
561         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
562             "Load table from Buffer or Field %p\n", ObjDesc));
563 
564         /* Must have at least an ACPI table header */
565 
566         if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
567         {
568             return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
569         }
570 
571         /* Get the actual table length from the table header */
572 
573         Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
574         Length = Table->Length;
575 
576         /* Table cannot extend beyond the buffer */
577 
578         if (Length > ObjDesc->Buffer.Length)
579         {
580             return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
581         }
582         if (Length < sizeof (ACPI_TABLE_HEADER))
583         {
584             return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
585         }
586 
587         /*
588          * Copy the table from the buffer because the buffer could be modified
589          * or even deleted in the future
590          */
591         TableDesc.Pointer = ACPI_ALLOCATE (Length);
592         if (!TableDesc.Pointer)
593         {
594             return_ACPI_STATUS (AE_NO_MEMORY);
595         }
596 
597         ACPI_MEMCPY (TableDesc.Pointer, Table, Length);
598         TableDesc.Address = ACPI_TO_INTEGER (TableDesc.Pointer);
599         break;
600 
601     default:
602 
603         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
604     }
605 
606     /* Validate table checksum (will not get validated in TbAddTable) */
607 
608     Status = AcpiTbVerifyChecksum (TableDesc.Pointer, Length);
609     if (ACPI_FAILURE (Status))
610     {
611         ACPI_FREE (TableDesc.Pointer);
612         return_ACPI_STATUS (Status);
613     }
614 
615     /* Complete the table descriptor */
616 
617     TableDesc.Length = Length;
618     TableDesc.Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
619 
620     /* Install the new table into the local data structures */
621 
622     Status = AcpiTbAddTable (&TableDesc, &TableIndex);
623     if (ACPI_FAILURE (Status))
624     {
625         /* Delete allocated table buffer */
626 
627         AcpiTbDeleteTable (&TableDesc);
628         return_ACPI_STATUS (Status);
629     }
630 
631     /*
632      * Add the table to the namespace.
633      *
634      * Note: Load the table objects relative to the root of the namespace.
635      * This appears to go against the ACPI specification, but we do it for
636      * compatibility with other ACPI implementations.
637      */
638     Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle);
639     if (ACPI_FAILURE (Status))
640     {
641         /* On error, TablePtr was deallocated above */
642 
643         return_ACPI_STATUS (Status);
644     }
645 
646     /* Store the DdbHandle into the Target operand */
647 
648     Status = AcpiExStore (DdbHandle, Target, WalkState);
649     if (ACPI_FAILURE (Status))
650     {
651         (void) AcpiExUnloadTable (DdbHandle);
652 
653         /* TablePtr was deallocated above */
654 
655         AcpiUtRemoveReference (DdbHandle);
656         return_ACPI_STATUS (Status);
657     }
658 
659     ACPI_INFO ((AE_INFO, "Dynamic OEM Table Load:"));
660     AcpiTbPrintTableHeader (0, TableDesc.Pointer);
661 
662     /* Remove the reference by added by AcpiExStore above */
663 
664     AcpiUtRemoveReference (DdbHandle);
665 
666     /* Invoke table handler if present */
667 
668     if (AcpiGbl_TableHandler)
669     {
670         (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, TableDesc.Pointer,
671                     AcpiGbl_TableHandlerContext);
672     }
673 
674     return_ACPI_STATUS (Status);
675 }
676 
677 
678 /*******************************************************************************
679  *
680  * FUNCTION:    AcpiExUnloadTable
681  *
682  * PARAMETERS:  DdbHandle           - Handle to a previously loaded table
683  *
684  * RETURN:      Status
685  *
686  * DESCRIPTION: Unload an ACPI table
687  *
688  ******************************************************************************/
689 
690 ACPI_STATUS
691 AcpiExUnloadTable (
692     ACPI_OPERAND_OBJECT     *DdbHandle)
693 {
694     ACPI_STATUS             Status = AE_OK;
695     ACPI_OPERAND_OBJECT     *TableDesc = DdbHandle;
696     UINT32                  TableIndex;
697     ACPI_TABLE_HEADER       *Table;
698 
699 
700     ACPI_FUNCTION_TRACE (ExUnloadTable);
701 
702 
703     /*
704      * Validate the handle
705      * Although the handle is partially validated in AcpiExReconfiguration()
706      * when it calls AcpiExResolveOperands(), the handle is more completely
707      * validated here.
708      *
709      * Handle must be a valid operand object of type reference. Also, the
710      * DdbHandle must still be marked valid (table has not been previously
711      * unloaded)
712      */
713     if ((!DdbHandle) ||
714         (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
715         (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
716         (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
717     {
718         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
719     }
720 
721     /* Get the table index from the DdbHandle */
722 
723     TableIndex = TableDesc->Reference.Value;
724 
725     /* Ensure the table is still loaded */
726 
727     if (!AcpiTbIsTableLoaded (TableIndex))
728     {
729         return_ACPI_STATUS (AE_NOT_EXIST);
730     }
731 
732     /* Invoke table handler if present */
733 
734     if (AcpiGbl_TableHandler)
735     {
736         Status = AcpiGetTableByIndex (TableIndex, &Table);
737         if (ACPI_SUCCESS (Status))
738         {
739             (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table,
740                         AcpiGbl_TableHandlerContext);
741         }
742     }
743 
744     /* Delete the portion of the namespace owned by this table */
745 
746     Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
747     if (ACPI_FAILURE (Status))
748     {
749         return_ACPI_STATUS (Status);
750     }
751 
752     (void) AcpiTbReleaseOwnerId (TableIndex);
753     AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
754 
755     /*
756      * Invalidate the handle. We do this because the handle may be stored
757      * in a named object and may not be actually deleted until much later.
758      */
759     DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
760     return_ACPI_STATUS (AE_OK);
761 }
762