1 /******************************************************************************
3 * Module Name: tbdata - Table manager data structure functions
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp.
12 * All rights reserved.
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
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
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;
37 * The above copyright and patent license is granted only if the following
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.
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
80 * 4. Disclaimer and Export Compliance
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 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
153 #include "accommon.h"
154 #include "acnamesp.h"
155 #include "actables.h"
156 #include "acevents.h"
158 #define _COMPONENT ACPI_TABLES
159 ACPI_MODULE_NAME ("tbdata")
161 /* Local prototypes */
164 AcpiTbCheckDuplication (
165 ACPI_TABLE_DESC *TableDesc,
169 AcpiTbCompareTables (
170 ACPI_TABLE_DESC *TableDesc,
174 /*******************************************************************************
176 * FUNCTION: AcpiTbCompareTables
178 * PARAMETERS: TableDesc - Table 1 descriptor to be compared
179 * TableIndex - Index of table 2 to be compared
181 * RETURN: TRUE if both tables are identical.
183 * DESCRIPTION: This function compares a table with another table that has
184 * already been installed in the root table list.
186 ******************************************************************************/
189 AcpiTbCompareTables (
190 ACPI_TABLE_DESC *TableDesc,
193 ACPI_STATUS Status = AE_OK;
195 ACPI_TABLE_HEADER *Table;
200 Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex],
201 &Table, &TableLength, &TableFlags);
202 if (ACPI_FAILURE (Status))
208 * Check for a table match on the entire table length,
209 * not just the header.
211 IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength ||
212 memcmp (TableDesc->Pointer, Table, TableLength)) ?
215 /* Release the acquired table */
217 AcpiTbReleaseTable (Table, TableLength, TableFlags);
218 return (IsIdentical);
222 /*******************************************************************************
224 * FUNCTION: AcpiTbInitTableDescriptor
226 * PARAMETERS: TableDesc - Table descriptor
227 * Address - Physical address of the table
228 * Flags - Allocation flags of the table
229 * Table - Pointer to the table
233 * DESCRIPTION: Initialize a new table descriptor
235 ******************************************************************************/
238 AcpiTbInitTableDescriptor (
239 ACPI_TABLE_DESC *TableDesc,
240 ACPI_PHYSICAL_ADDRESS Address,
242 ACPI_TABLE_HEADER *Table)
246 * Initialize the table descriptor. Set the pointer to NULL, since the
247 * table is not fully mapped at this time.
249 memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
250 TableDesc->Address = Address;
251 TableDesc->Length = Table->Length;
252 TableDesc->Flags = Flags;
253 ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
257 /*******************************************************************************
259 * FUNCTION: AcpiTbAcquireTable
261 * PARAMETERS: TableDesc - Table descriptor
262 * TablePtr - Where table is returned
263 * TableLength - Where table length is returned
264 * TableFlags - Where table allocation flags are returned
268 * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
269 * maintained in the AcpiGbl_RootTableList.
271 ******************************************************************************/
275 ACPI_TABLE_DESC *TableDesc,
276 ACPI_TABLE_HEADER **TablePtr,
280 ACPI_TABLE_HEADER *Table = NULL;
283 switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
285 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
287 Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
290 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
291 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
293 Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
294 ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
302 /* Table is not valid yet */
306 return (AE_NO_MEMORY);
309 /* Fill the return values */
312 *TableLength = TableDesc->Length;
313 *TableFlags = TableDesc->Flags;
318 /*******************************************************************************
320 * FUNCTION: AcpiTbReleaseTable
322 * PARAMETERS: Table - Pointer for the table
323 * TableLength - Length for the table
324 * TableFlags - Allocation flags for the table
328 * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
330 ******************************************************************************/
334 ACPI_TABLE_HEADER *Table,
339 switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
341 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
343 AcpiOsUnmapMemory (Table, TableLength);
346 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
347 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
355 /*******************************************************************************
357 * FUNCTION: AcpiTbAcquireTempTable
359 * PARAMETERS: TableDesc - Table descriptor to be acquired
360 * Address - Address of the table
361 * Flags - Allocation flags of the table
365 * DESCRIPTION: This function validates the table header to obtain the length
366 * of a table and fills the table descriptor to make its state as
367 * "INSTALLED". Such a table descriptor is only used for verified
370 ******************************************************************************/
373 AcpiTbAcquireTempTable (
374 ACPI_TABLE_DESC *TableDesc,
375 ACPI_PHYSICAL_ADDRESS Address,
378 ACPI_TABLE_HEADER *TableHeader;
381 switch (Flags & ACPI_TABLE_ORIGIN_MASK)
383 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
385 /* Get the length of the full table from the header */
387 TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
390 return (AE_NO_MEMORY);
393 AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
394 AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
397 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
398 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
400 TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
401 ACPI_PHYSADDR_TO_PTR (Address));
404 return (AE_NO_MEMORY);
407 AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
415 /* Table is not valid yet */
417 return (AE_NO_MEMORY);
421 /*******************************************************************************
423 * FUNCTION: AcpiTbReleaseTempTable
425 * PARAMETERS: TableDesc - Table descriptor to be released
429 * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
431 *****************************************************************************/
434 AcpiTbReleaseTempTable (
435 ACPI_TABLE_DESC *TableDesc)
439 * Note that the .Address is maintained by the callers of
440 * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
441 * where .Address will be freed.
443 AcpiTbInvalidateTable (TableDesc);
447 /******************************************************************************
449 * FUNCTION: AcpiTbValidateTable
451 * PARAMETERS: TableDesc - Table descriptor
455 * DESCRIPTION: This function is called to validate the table, the returned
456 * table descriptor is in "VALIDATED" state.
458 *****************************************************************************/
461 AcpiTbValidateTable (
462 ACPI_TABLE_DESC *TableDesc)
464 ACPI_STATUS Status = AE_OK;
467 ACPI_FUNCTION_TRACE (TbValidateTable);
470 /* Validate the table if necessary */
472 if (!TableDesc->Pointer)
474 Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
475 &TableDesc->Length, &TableDesc->Flags);
476 if (!TableDesc->Pointer)
478 Status = AE_NO_MEMORY;
482 return_ACPI_STATUS (Status);
486 /*******************************************************************************
488 * FUNCTION: AcpiTbInvalidateTable
490 * PARAMETERS: TableDesc - Table descriptor
494 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
495 * AcpiTbValidateTable().
497 ******************************************************************************/
500 AcpiTbInvalidateTable (
501 ACPI_TABLE_DESC *TableDesc)
504 ACPI_FUNCTION_TRACE (TbInvalidateTable);
507 /* Table must be validated */
509 if (!TableDesc->Pointer)
514 AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
516 TableDesc->Pointer = NULL;
522 /******************************************************************************
524 * FUNCTION: AcpiTbValidateTempTable
526 * PARAMETERS: TableDesc - Table descriptor
530 * DESCRIPTION: This function is called to validate the table, the returned
531 * table descriptor is in "VALIDATED" state.
533 *****************************************************************************/
536 AcpiTbValidateTempTable (
537 ACPI_TABLE_DESC *TableDesc)
540 if (!TableDesc->Pointer && !AcpiGbl_EnableTableValidation)
543 * Only validates the header of the table.
544 * Note that Length contains the size of the mapping after invoking
545 * this work around, this value is required by
546 * AcpiTbReleaseTempTable().
547 * We can do this because in AcpiInitTableDescriptor(), the Length
548 * field of the installed descriptor is filled with the actual
549 * table length obtaining from the table header.
551 TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
554 return (AcpiTbValidateTable (TableDesc));
558 /*******************************************************************************
560 * FUNCTION: AcpiTbCheckDuplication
562 * PARAMETERS: TableDesc - Table descriptor
563 * TableIndex - Where the table index is returned
567 * DESCRIPTION: Avoid installing duplicated tables. However table override and
568 * user aided dynamic table load is allowed, thus comparing the
569 * address of the table is not sufficient, and checking the entire
570 * table content is required.
572 ******************************************************************************/
575 AcpiTbCheckDuplication (
576 ACPI_TABLE_DESC *TableDesc,
582 ACPI_FUNCTION_TRACE (TbCheckDuplication);
585 /* Check if table is already registered */
587 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
589 /* Do not compare with unverified tables */
591 if (!(AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_VERIFIED))
597 * Check for a table match on the entire table length,
598 * not just the header.
600 if (!AcpiTbCompareTables (TableDesc, i))
606 * Note: the current mechanism does not unregister a table if it is
607 * dynamically unloaded. The related namespace entries are deleted,
608 * but the table remains in the root table list.
610 * The assumption here is that the number of different tables that
611 * will be loaded is actually small, and there is minimal overhead
612 * in just keeping the table in case it is needed again.
614 * If this assumption changes in the future (perhaps on large
615 * machines with many table load/unload operations), tables will
616 * need to be unregistered when they are unloaded, and slots in the
617 * root table list should be reused when empty.
619 if (AcpiGbl_RootTableList.Tables[i].Flags &
620 ACPI_TABLE_IS_LOADED)
622 /* Table is still loaded, this is an error */
624 return_ACPI_STATUS (AE_ALREADY_EXISTS);
629 return_ACPI_STATUS (AE_CTRL_TERMINATE);
633 /* Indicate no duplication to the caller */
635 return_ACPI_STATUS (AE_OK);
639 /******************************************************************************
641 * FUNCTION: AcpiTbVerifyTempTable
643 * PARAMETERS: TableDesc - Table descriptor
644 * Signature - Table signature to verify
645 * TableIndex - Where the table index is returned
649 * DESCRIPTION: This function is called to validate and verify the table, the
650 * returned table descriptor is in "VALIDATED" state.
651 * Note that 'TableIndex' is required to be set to !NULL to
652 * enable duplication check.
654 *****************************************************************************/
657 AcpiTbVerifyTempTable (
658 ACPI_TABLE_DESC *TableDesc,
662 ACPI_STATUS Status = AE_OK;
665 ACPI_FUNCTION_TRACE (TbVerifyTempTable);
668 /* Validate the table */
670 Status = AcpiTbValidateTempTable (TableDesc);
671 if (ACPI_FAILURE (Status))
673 return_ACPI_STATUS (AE_NO_MEMORY);
676 /* If a particular signature is expected (DSDT/FACS), it must match */
679 !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
681 ACPI_BIOS_ERROR ((AE_INFO,
682 "Invalid signature 0x%X for ACPI table, expected [%s]",
683 TableDesc->Signature.Integer, Signature));
684 Status = AE_BAD_SIGNATURE;
685 goto InvalidateAndExit;
688 if (AcpiGbl_EnableTableValidation)
690 /* Verify the checksum */
692 Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
693 if (ACPI_FAILURE (Status))
695 ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
697 " Attempted table install failed",
698 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
699 TableDesc->Signature.Ascii : "????",
700 ACPI_FORMAT_UINT64 (TableDesc->Address)));
702 goto InvalidateAndExit;
705 /* Avoid duplications */
709 Status = AcpiTbCheckDuplication (TableDesc, TableIndex);
710 if (ACPI_FAILURE (Status))
712 if (Status != AE_CTRL_TERMINATE)
714 ACPI_EXCEPTION ((AE_INFO, Status,
716 " Table is already loaded",
717 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
718 TableDesc->Signature.Ascii : "????",
719 ACPI_FORMAT_UINT64 (TableDesc->Address)));
722 goto InvalidateAndExit;
726 TableDesc->Flags |= ACPI_TABLE_IS_VERIFIED;
729 return_ACPI_STATUS (Status);
732 AcpiTbInvalidateTable (TableDesc);
733 return_ACPI_STATUS (Status);
737 /*******************************************************************************
739 * FUNCTION: AcpiTbResizeRootTableList
745 * DESCRIPTION: Expand the size of global table array
747 ******************************************************************************/
750 AcpiTbResizeRootTableList (
753 ACPI_TABLE_DESC *Tables;
755 UINT32 CurrentTableCount, MaxTableCount;
759 ACPI_FUNCTION_TRACE (TbResizeRootTableList);
762 /* AllowResize flag is a parameter to AcpiInitializeTables */
764 if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
766 ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
767 return_ACPI_STATUS (AE_SUPPORT);
770 /* Increase the Table Array size */
772 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
774 TableCount = AcpiGbl_RootTableList.MaxTableCount;
778 TableCount = AcpiGbl_RootTableList.CurrentTableCount;
781 MaxTableCount = TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
782 Tables = ACPI_ALLOCATE_ZEROED (
783 ((ACPI_SIZE) MaxTableCount) * sizeof (ACPI_TABLE_DESC));
786 ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
787 return_ACPI_STATUS (AE_NO_MEMORY);
790 /* Copy and free the previous table array */
792 CurrentTableCount = 0;
793 if (AcpiGbl_RootTableList.Tables)
795 for (i = 0; i < TableCount; i++)
797 if (AcpiGbl_RootTableList.Tables[i].Address)
799 memcpy (Tables + CurrentTableCount,
800 AcpiGbl_RootTableList.Tables + i,
801 sizeof (ACPI_TABLE_DESC));
806 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
808 ACPI_FREE (AcpiGbl_RootTableList.Tables);
812 AcpiGbl_RootTableList.Tables = Tables;
813 AcpiGbl_RootTableList.MaxTableCount = MaxTableCount;
814 AcpiGbl_RootTableList.CurrentTableCount = CurrentTableCount;
815 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
817 return_ACPI_STATUS (AE_OK);
821 /*******************************************************************************
823 * FUNCTION: AcpiTbGetNextTableDescriptor
825 * PARAMETERS: TableIndex - Where table index is returned
826 * TableDesc - Where table descriptor is returned
828 * RETURN: Status and table index/descriptor.
830 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
832 ******************************************************************************/
835 AcpiTbGetNextTableDescriptor (
837 ACPI_TABLE_DESC **TableDesc)
843 /* Ensure that there is room for the table in the Root Table List */
845 if (AcpiGbl_RootTableList.CurrentTableCount >=
846 AcpiGbl_RootTableList.MaxTableCount)
848 Status = AcpiTbResizeRootTableList();
849 if (ACPI_FAILURE (Status))
855 i = AcpiGbl_RootTableList.CurrentTableCount;
856 AcpiGbl_RootTableList.CurrentTableCount++;
864 *TableDesc = &AcpiGbl_RootTableList.Tables[i];
871 /*******************************************************************************
873 * FUNCTION: AcpiTbTerminate
879 * DESCRIPTION: Delete all internal ACPI tables
881 ******************************************************************************/
890 ACPI_FUNCTION_TRACE (TbTerminate);
893 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
895 /* Delete the individual tables */
897 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
899 AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
903 * Delete the root table array if allocated locally. Array cannot be
904 * mapped, so we don't need to check for that flag.
906 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
908 ACPI_FREE (AcpiGbl_RootTableList.Tables);
911 AcpiGbl_RootTableList.Tables = NULL;
912 AcpiGbl_RootTableList.Flags = 0;
913 AcpiGbl_RootTableList.CurrentTableCount = 0;
915 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
917 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
922 /*******************************************************************************
924 * FUNCTION: AcpiTbDeleteNamespaceByOwner
926 * PARAMETERS: TableIndex - Table index
930 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
932 ******************************************************************************/
935 AcpiTbDeleteNamespaceByOwner (
938 ACPI_OWNER_ID OwnerId;
942 ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
945 Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
946 if (ACPI_FAILURE (Status))
948 return_ACPI_STATUS (Status);
951 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
953 /* The table index does not exist */
955 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
956 return_ACPI_STATUS (AE_NOT_EXIST);
959 /* Get the owner ID for this table, used to delete namespace nodes */
961 OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
962 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
965 * Need to acquire the namespace writer lock to prevent interference
966 * with any concurrent namespace walks. The interpreter must be
967 * released during the deletion since the acquisition of the deletion
968 * lock may block, and also since the execution of a namespace walk
969 * must be allowed to use the interpreter.
971 Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
972 if (ACPI_FAILURE (Status))
974 return_ACPI_STATUS (Status);
976 AcpiNsDeleteNamespaceByOwner (OwnerId);
977 AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
978 return_ACPI_STATUS (Status);
982 /*******************************************************************************
984 * FUNCTION: AcpiTbAllocateOwnerId
986 * PARAMETERS: TableIndex - Table index
990 * DESCRIPTION: Allocates OwnerId in TableDesc
992 ******************************************************************************/
995 AcpiTbAllocateOwnerId (
998 ACPI_STATUS Status = AE_BAD_PARAMETER;
1001 ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
1004 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1005 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1007 Status = AcpiUtAllocateOwnerId (
1008 &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
1011 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1012 return_ACPI_STATUS (Status);
1016 /*******************************************************************************
1018 * FUNCTION: AcpiTbReleaseOwnerId
1020 * PARAMETERS: TableIndex - Table index
1024 * DESCRIPTION: Releases OwnerId in TableDesc
1026 ******************************************************************************/
1029 AcpiTbReleaseOwnerId (
1032 ACPI_STATUS Status = AE_BAD_PARAMETER;
1035 ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
1038 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1039 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1041 AcpiUtReleaseOwnerId (
1042 &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
1046 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1047 return_ACPI_STATUS (Status);
1051 /*******************************************************************************
1053 * FUNCTION: AcpiTbGetOwnerId
1055 * PARAMETERS: TableIndex - Table index
1056 * OwnerId - Where the table OwnerId is returned
1060 * DESCRIPTION: returns OwnerId for the ACPI table
1062 ******************************************************************************/
1067 ACPI_OWNER_ID *OwnerId)
1069 ACPI_STATUS Status = AE_BAD_PARAMETER;
1072 ACPI_FUNCTION_TRACE (TbGetOwnerId);
1075 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1076 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1078 *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
1082 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1083 return_ACPI_STATUS (Status);
1087 /*******************************************************************************
1089 * FUNCTION: AcpiTbIsTableLoaded
1091 * PARAMETERS: TableIndex - Index into the root table
1093 * RETURN: Table Loaded Flag
1095 ******************************************************************************/
1098 AcpiTbIsTableLoaded (
1101 BOOLEAN IsLoaded = FALSE;
1104 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1105 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1107 IsLoaded = (BOOLEAN)
1108 (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
1109 ACPI_TABLE_IS_LOADED);
1112 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1117 /*******************************************************************************
1119 * FUNCTION: AcpiTbSetTableLoadedFlag
1121 * PARAMETERS: TableIndex - Table index
1122 * IsLoaded - TRUE if table is loaded, FALSE otherwise
1126 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
1128 ******************************************************************************/
1131 AcpiTbSetTableLoadedFlag (
1136 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1137 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1141 AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
1142 ACPI_TABLE_IS_LOADED;
1146 AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
1147 ~ACPI_TABLE_IS_LOADED;
1151 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1155 /*******************************************************************************
1157 * FUNCTION: AcpiTbLoadTable
1159 * PARAMETERS: TableIndex - Table index
1160 * ParentNode - Where table index is returned
1164 * DESCRIPTION: Load an ACPI table
1166 ******************************************************************************/
1171 ACPI_NAMESPACE_NODE *ParentNode)
1173 ACPI_TABLE_HEADER *Table;
1175 ACPI_OWNER_ID OwnerId;
1178 ACPI_FUNCTION_TRACE (TbLoadTable);
1182 * Note: Now table is "INSTALLED", it must be validated before
1185 Status = AcpiGetTableByIndex (TableIndex, &Table);
1186 if (ACPI_FAILURE (Status))
1188 return_ACPI_STATUS (Status);
1191 Status = AcpiNsLoadTable (TableIndex, ParentNode);
1194 * This case handles the legacy option that groups all module-level
1195 * code blocks together and defers execution until all of the tables
1196 * are loaded. Execute all of these blocks at this time.
1197 * Execute any module-level code that was detected during the table
1200 * Note: this option is deprecated and will be eliminated in the
1201 * future. Use of this option can cause problems with AML code that
1202 * depends upon in-order immediate execution of module-level code.
1204 AcpiNsExecModuleCodeList ();
1207 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
1208 * responsible for discovering any new wake GPEs by running _PRW methods
1209 * that may have been loaded by this table.
1211 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
1212 if (ACPI_SUCCESS (Status))
1214 AcpiEvUpdateGpes (OwnerId);
1217 /* Invoke table handler */
1219 AcpiTbNotifyTable (ACPI_TABLE_EVENT_LOAD, Table);
1220 return_ACPI_STATUS (Status);
1224 /*******************************************************************************
1226 * FUNCTION: AcpiTbInstallAndLoadTable
1228 * PARAMETERS: Address - Physical address of the table
1229 * Flags - Allocation flags of the table
1230 * Override - Whether override should be performed
1231 * TableIndex - Where table index is returned
1235 * DESCRIPTION: Install and load an ACPI table
1237 ******************************************************************************/
1240 AcpiTbInstallAndLoadTable (
1241 ACPI_PHYSICAL_ADDRESS Address,
1250 ACPI_FUNCTION_TRACE (TbInstallAndLoadTable);
1253 /* Install the table and load it into the namespace */
1255 Status = AcpiTbInstallStandardTable (Address, Flags, TRUE,
1257 if (ACPI_FAILURE (Status))
1262 Status = AcpiTbLoadTable (i, AcpiGbl_RootNode);
1266 return_ACPI_STATUS (Status);
1270 /*******************************************************************************
1272 * FUNCTION: AcpiTbUnloadTable
1274 * PARAMETERS: TableIndex - Table index
1278 * DESCRIPTION: Unload an ACPI table
1280 ******************************************************************************/
1286 ACPI_STATUS Status = AE_OK;
1287 ACPI_TABLE_HEADER *Table;
1290 ACPI_FUNCTION_TRACE (TbUnloadTable);
1293 /* Ensure the table is still loaded */
1295 if (!AcpiTbIsTableLoaded (TableIndex))
1297 return_ACPI_STATUS (AE_NOT_EXIST);
1300 /* Invoke table handler */
1302 Status = AcpiGetTableByIndex (TableIndex, &Table);
1303 if (ACPI_SUCCESS (Status))
1305 AcpiTbNotifyTable (ACPI_TABLE_EVENT_UNLOAD, Table);
1308 /* Delete the portion of the namespace owned by this table */
1310 Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
1311 if (ACPI_FAILURE (Status))
1313 return_ACPI_STATUS (Status);
1316 (void) AcpiTbReleaseOwnerId (TableIndex);
1317 AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
1318 return_ACPI_STATUS (Status);
1322 /*******************************************************************************
1324 * FUNCTION: AcpiTbNotifyTable
1326 * PARAMETERS: Event - Table event
1327 * Table - Validated table pointer
1331 * DESCRIPTION: Notify a table event to the users.
1333 ******************************************************************************/
1340 /* Invoke table handler if present */
1342 if (AcpiGbl_TableHandler)
1344 (void) AcpiGbl_TableHandler (Event, Table,
1345 AcpiGbl_TableHandlerContext);