1 /******************************************************************************
3 * Module Name: tbdata - Table manager data structure functions
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2021, 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 for external
247 * tables, since the 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);
255 switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
257 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
258 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
260 TableDesc->Pointer = Table;
263 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
271 /*******************************************************************************
273 * FUNCTION: AcpiTbAcquireTable
275 * PARAMETERS: TableDesc - Table descriptor
276 * TablePtr - Where table is returned
277 * TableLength - Where table length is returned
278 * TableFlags - Where table allocation flags are returned
282 * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
283 * maintained in the AcpiGbl_RootTableList.
285 ******************************************************************************/
289 ACPI_TABLE_DESC *TableDesc,
290 ACPI_TABLE_HEADER **TablePtr,
294 ACPI_TABLE_HEADER *Table = NULL;
297 switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
299 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
301 Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
304 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
305 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
307 Table = TableDesc->Pointer;
315 /* Table is not valid yet */
319 return (AE_NO_MEMORY);
322 /* Fill the return values */
325 *TableLength = TableDesc->Length;
326 *TableFlags = TableDesc->Flags;
331 /*******************************************************************************
333 * FUNCTION: AcpiTbReleaseTable
335 * PARAMETERS: Table - Pointer for the table
336 * TableLength - Length for the table
337 * TableFlags - Allocation flags for the table
341 * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
343 ******************************************************************************/
347 ACPI_TABLE_HEADER *Table,
352 switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
354 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
356 AcpiOsUnmapMemory (Table, TableLength);
359 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
360 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
368 /*******************************************************************************
370 * FUNCTION: AcpiTbAcquireTempTable
372 * PARAMETERS: TableDesc - Table descriptor to be acquired
373 * Address - Address of the table
374 * Flags - Allocation flags of the table
375 * Table - Pointer to the table (required for virtual
376 * origins, optional for physical)
380 * DESCRIPTION: This function validates the table header to obtain the length
381 * of a table and fills the table descriptor to make its state as
382 * "INSTALLED". Such a table descriptor is only used for verified
385 ******************************************************************************/
388 AcpiTbAcquireTempTable (
389 ACPI_TABLE_DESC *TableDesc,
390 ACPI_PHYSICAL_ADDRESS Address,
392 ACPI_TABLE_HEADER *Table)
394 BOOLEAN MappedTable = FALSE;
397 switch (Flags & ACPI_TABLE_ORIGIN_MASK)
399 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
401 /* Get the length of the full table from the header */
405 Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
408 return (AE_NO_MEMORY);
416 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
417 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
421 return (AE_BAD_PARAMETER);
428 /* Table is not valid yet */
430 return (AE_NO_MEMORY);
433 AcpiTbInitTableDescriptor (TableDesc, Address, Flags, Table);
436 AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));
443 /*******************************************************************************
445 * FUNCTION: AcpiTbReleaseTempTable
447 * PARAMETERS: TableDesc - Table descriptor to be released
451 * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
453 *****************************************************************************/
456 AcpiTbReleaseTempTable (
457 ACPI_TABLE_DESC *TableDesc)
461 * Note that the .Address is maintained by the callers of
462 * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
463 * where .Address will be freed.
465 AcpiTbInvalidateTable (TableDesc);
469 /******************************************************************************
471 * FUNCTION: AcpiTbValidateTable
473 * PARAMETERS: TableDesc - Table descriptor
477 * DESCRIPTION: This function is called to validate the table, the returned
478 * table descriptor is in "VALIDATED" state.
480 *****************************************************************************/
483 AcpiTbValidateTable (
484 ACPI_TABLE_DESC *TableDesc)
486 ACPI_STATUS Status = AE_OK;
489 ACPI_FUNCTION_TRACE (TbValidateTable);
492 /* Validate the table if necessary */
494 if (!TableDesc->Pointer)
496 Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
497 &TableDesc->Length, &TableDesc->Flags);
498 if (!TableDesc->Pointer)
500 Status = AE_NO_MEMORY;
504 return_ACPI_STATUS (Status);
508 /*******************************************************************************
510 * FUNCTION: AcpiTbInvalidateTable
512 * PARAMETERS: TableDesc - Table descriptor
516 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
517 * AcpiTbValidateTable().
519 ******************************************************************************/
522 AcpiTbInvalidateTable (
523 ACPI_TABLE_DESC *TableDesc)
526 ACPI_FUNCTION_TRACE (TbInvalidateTable);
529 /* Table must be validated */
531 if (!TableDesc->Pointer)
536 AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
539 switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
541 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
543 TableDesc->Pointer = NULL;
546 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
547 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
557 /******************************************************************************
559 * FUNCTION: AcpiTbValidateTempTable
561 * PARAMETERS: TableDesc - Table descriptor
565 * DESCRIPTION: This function is called to validate the table, the returned
566 * table descriptor is in "VALIDATED" state.
568 *****************************************************************************/
571 AcpiTbValidateTempTable (
572 ACPI_TABLE_DESC *TableDesc)
575 if (!TableDesc->Pointer && !AcpiGbl_EnableTableValidation)
578 * Only validates the header of the table.
579 * Note that Length contains the size of the mapping after invoking
580 * this work around, this value is required by
581 * AcpiTbReleaseTempTable().
582 * We can do this because in AcpiInitTableDescriptor(), the Length
583 * field of the installed descriptor is filled with the actual
584 * table length obtaining from the table header.
586 TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
589 return (AcpiTbValidateTable (TableDesc));
593 /*******************************************************************************
595 * FUNCTION: AcpiTbCheckDuplication
597 * PARAMETERS: TableDesc - Table descriptor
598 * TableIndex - Where the table index is returned
602 * DESCRIPTION: Avoid installing duplicated tables. However table override and
603 * user aided dynamic table load is allowed, thus comparing the
604 * address of the table is not sufficient, and checking the entire
605 * table content is required.
607 ******************************************************************************/
610 AcpiTbCheckDuplication (
611 ACPI_TABLE_DESC *TableDesc,
617 ACPI_FUNCTION_TRACE (TbCheckDuplication);
620 /* Check if table is already registered */
622 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
624 /* Do not compare with unverified tables */
626 if (!(AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_VERIFIED))
632 * Check for a table match on the entire table length,
633 * not just the header.
635 if (!AcpiTbCompareTables (TableDesc, i))
641 * Note: the current mechanism does not unregister a table if it is
642 * dynamically unloaded. The related namespace entries are deleted,
643 * but the table remains in the root table list.
645 * The assumption here is that the number of different tables that
646 * will be loaded is actually small, and there is minimal overhead
647 * in just keeping the table in case it is needed again.
649 * If this assumption changes in the future (perhaps on large
650 * machines with many table load/unload operations), tables will
651 * need to be unregistered when they are unloaded, and slots in the
652 * root table list should be reused when empty.
654 if (AcpiGbl_RootTableList.Tables[i].Flags &
655 ACPI_TABLE_IS_LOADED)
657 /* Table is still loaded, this is an error */
659 return_ACPI_STATUS (AE_ALREADY_EXISTS);
664 return_ACPI_STATUS (AE_CTRL_TERMINATE);
668 /* Indicate no duplication to the caller */
670 return_ACPI_STATUS (AE_OK);
674 /******************************************************************************
676 * FUNCTION: AcpiTbVerifyTempTable
678 * PARAMETERS: TableDesc - Table descriptor
679 * Signature - Table signature to verify
680 * TableIndex - Where the table index is returned
684 * DESCRIPTION: This function is called to validate and verify the table, the
685 * returned table descriptor is in "VALIDATED" state.
686 * Note that 'TableIndex' is required to be set to !NULL to
687 * enable duplication check.
689 *****************************************************************************/
692 AcpiTbVerifyTempTable (
693 ACPI_TABLE_DESC *TableDesc,
697 ACPI_STATUS Status = AE_OK;
700 ACPI_FUNCTION_TRACE (TbVerifyTempTable);
703 /* Validate the table */
705 Status = AcpiTbValidateTempTable (TableDesc);
706 if (ACPI_FAILURE (Status))
708 return_ACPI_STATUS (AE_NO_MEMORY);
711 /* If a particular signature is expected (DSDT/FACS), it must match */
714 !ACPI_COMPARE_NAMESEG (&TableDesc->Signature, Signature))
716 ACPI_BIOS_ERROR ((AE_INFO,
717 "Invalid signature 0x%X for ACPI table, expected [%s]",
718 TableDesc->Signature.Integer, Signature));
719 Status = AE_BAD_SIGNATURE;
720 goto InvalidateAndExit;
723 if (AcpiGbl_EnableTableValidation)
725 /* Verify the checksum */
727 Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
728 if (ACPI_FAILURE (Status))
730 ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
732 " Attempted table install failed",
733 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
734 TableDesc->Signature.Ascii : "????",
735 ACPI_FORMAT_UINT64 (TableDesc->Address)));
737 goto InvalidateAndExit;
740 /* Avoid duplications */
744 Status = AcpiTbCheckDuplication (TableDesc, TableIndex);
745 if (ACPI_FAILURE (Status))
747 if (Status != AE_CTRL_TERMINATE)
749 ACPI_EXCEPTION ((AE_INFO, Status,
751 " Table is already loaded",
752 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
753 TableDesc->Signature.Ascii : "????",
754 ACPI_FORMAT_UINT64 (TableDesc->Address)));
757 goto InvalidateAndExit;
761 TableDesc->Flags |= ACPI_TABLE_IS_VERIFIED;
764 return_ACPI_STATUS (Status);
767 AcpiTbInvalidateTable (TableDesc);
768 return_ACPI_STATUS (Status);
772 /*******************************************************************************
774 * FUNCTION: AcpiTbResizeRootTableList
780 * DESCRIPTION: Expand the size of global table array
782 ******************************************************************************/
785 AcpiTbResizeRootTableList (
788 ACPI_TABLE_DESC *Tables;
790 UINT32 CurrentTableCount, MaxTableCount;
794 ACPI_FUNCTION_TRACE (TbResizeRootTableList);
797 /* AllowResize flag is a parameter to AcpiInitializeTables */
799 if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
801 ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
802 return_ACPI_STATUS (AE_SUPPORT);
805 /* Increase the Table Array size */
807 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
809 TableCount = AcpiGbl_RootTableList.MaxTableCount;
813 TableCount = AcpiGbl_RootTableList.CurrentTableCount;
816 MaxTableCount = TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
817 Tables = ACPI_ALLOCATE_ZEROED (
818 ((ACPI_SIZE) MaxTableCount) * sizeof (ACPI_TABLE_DESC));
821 ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
822 return_ACPI_STATUS (AE_NO_MEMORY);
825 /* Copy and free the previous table array */
827 CurrentTableCount = 0;
828 if (AcpiGbl_RootTableList.Tables)
830 for (i = 0; i < TableCount; i++)
832 if (AcpiGbl_RootTableList.Tables[i].Address)
834 memcpy (Tables + CurrentTableCount,
835 AcpiGbl_RootTableList.Tables + i,
836 sizeof (ACPI_TABLE_DESC));
841 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
843 ACPI_FREE (AcpiGbl_RootTableList.Tables);
847 AcpiGbl_RootTableList.Tables = Tables;
848 AcpiGbl_RootTableList.MaxTableCount = MaxTableCount;
849 AcpiGbl_RootTableList.CurrentTableCount = CurrentTableCount;
850 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
852 return_ACPI_STATUS (AE_OK);
856 /*******************************************************************************
858 * FUNCTION: AcpiTbGetNextTableDescriptor
860 * PARAMETERS: TableIndex - Where table index is returned
861 * TableDesc - Where table descriptor is returned
863 * RETURN: Status and table index/descriptor.
865 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
867 ******************************************************************************/
870 AcpiTbGetNextTableDescriptor (
872 ACPI_TABLE_DESC **TableDesc)
878 /* Ensure that there is room for the table in the Root Table List */
880 if (AcpiGbl_RootTableList.CurrentTableCount >=
881 AcpiGbl_RootTableList.MaxTableCount)
883 Status = AcpiTbResizeRootTableList();
884 if (ACPI_FAILURE (Status))
890 i = AcpiGbl_RootTableList.CurrentTableCount;
891 AcpiGbl_RootTableList.CurrentTableCount++;
899 *TableDesc = &AcpiGbl_RootTableList.Tables[i];
906 /*******************************************************************************
908 * FUNCTION: AcpiTbTerminate
914 * DESCRIPTION: Delete all internal ACPI tables
916 ******************************************************************************/
925 ACPI_FUNCTION_TRACE (TbTerminate);
928 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
930 /* Delete the individual tables */
932 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
934 AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
938 * Delete the root table array if allocated locally. Array cannot be
939 * mapped, so we don't need to check for that flag.
941 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
943 ACPI_FREE (AcpiGbl_RootTableList.Tables);
946 AcpiGbl_RootTableList.Tables = NULL;
947 AcpiGbl_RootTableList.Flags = 0;
948 AcpiGbl_RootTableList.CurrentTableCount = 0;
950 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
952 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
957 /*******************************************************************************
959 * FUNCTION: AcpiTbDeleteNamespaceByOwner
961 * PARAMETERS: TableIndex - Table index
965 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
967 ******************************************************************************/
970 AcpiTbDeleteNamespaceByOwner (
973 ACPI_OWNER_ID OwnerId;
977 ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
980 Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
981 if (ACPI_FAILURE (Status))
983 return_ACPI_STATUS (Status);
986 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
988 /* The table index does not exist */
990 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
991 return_ACPI_STATUS (AE_NOT_EXIST);
994 /* Get the owner ID for this table, used to delete namespace nodes */
996 OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
997 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1000 * Need to acquire the namespace writer lock to prevent interference
1001 * with any concurrent namespace walks. The interpreter must be
1002 * released during the deletion since the acquisition of the deletion
1003 * lock may block, and also since the execution of a namespace walk
1004 * must be allowed to use the interpreter.
1006 Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
1007 if (ACPI_FAILURE (Status))
1009 return_ACPI_STATUS (Status);
1012 AcpiNsDeleteNamespaceByOwner (OwnerId);
1013 AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
1014 return_ACPI_STATUS (Status);
1018 /*******************************************************************************
1020 * FUNCTION: AcpiTbAllocateOwnerId
1022 * PARAMETERS: TableIndex - Table index
1026 * DESCRIPTION: Allocates OwnerId in TableDesc
1028 ******************************************************************************/
1031 AcpiTbAllocateOwnerId (
1034 ACPI_STATUS Status = AE_BAD_PARAMETER;
1037 ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
1040 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1041 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1043 Status = AcpiUtAllocateOwnerId (
1044 &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
1047 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1048 return_ACPI_STATUS (Status);
1052 /*******************************************************************************
1054 * FUNCTION: AcpiTbReleaseOwnerId
1056 * PARAMETERS: TableIndex - Table index
1060 * DESCRIPTION: Releases OwnerId in TableDesc
1062 ******************************************************************************/
1065 AcpiTbReleaseOwnerId (
1068 ACPI_STATUS Status = AE_BAD_PARAMETER;
1071 ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
1074 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1075 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1077 AcpiUtReleaseOwnerId (
1078 &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
1082 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1083 return_ACPI_STATUS (Status);
1087 /*******************************************************************************
1089 * FUNCTION: AcpiTbGetOwnerId
1091 * PARAMETERS: TableIndex - Table index
1092 * OwnerId - Where the table OwnerId is returned
1096 * DESCRIPTION: returns OwnerId for the ACPI table
1098 ******************************************************************************/
1103 ACPI_OWNER_ID *OwnerId)
1105 ACPI_STATUS Status = AE_BAD_PARAMETER;
1108 ACPI_FUNCTION_TRACE (TbGetOwnerId);
1111 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1112 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1114 *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
1118 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1119 return_ACPI_STATUS (Status);
1123 /*******************************************************************************
1125 * FUNCTION: AcpiTbIsTableLoaded
1127 * PARAMETERS: TableIndex - Index into the root table
1129 * RETURN: Table Loaded Flag
1131 ******************************************************************************/
1134 AcpiTbIsTableLoaded (
1137 BOOLEAN IsLoaded = FALSE;
1140 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1141 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1143 IsLoaded = (BOOLEAN)
1144 (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
1145 ACPI_TABLE_IS_LOADED);
1148 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1153 /*******************************************************************************
1155 * FUNCTION: AcpiTbSetTableLoadedFlag
1157 * PARAMETERS: TableIndex - Table index
1158 * IsLoaded - TRUE if table is loaded, FALSE otherwise
1162 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
1164 ******************************************************************************/
1167 AcpiTbSetTableLoadedFlag (
1172 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1173 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1177 AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
1178 ACPI_TABLE_IS_LOADED;
1182 AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
1183 ~ACPI_TABLE_IS_LOADED;
1187 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1191 /*******************************************************************************
1193 * FUNCTION: AcpiTbLoadTable
1195 * PARAMETERS: TableIndex - Table index
1196 * ParentNode - Where table index is returned
1200 * DESCRIPTION: Load an ACPI table
1202 ******************************************************************************/
1207 ACPI_NAMESPACE_NODE *ParentNode)
1209 ACPI_TABLE_HEADER *Table;
1211 ACPI_OWNER_ID OwnerId;
1214 ACPI_FUNCTION_TRACE (TbLoadTable);
1218 * Note: Now table is "INSTALLED", it must be validated before
1221 Status = AcpiGetTableByIndex (TableIndex, &Table);
1222 if (ACPI_FAILURE (Status))
1224 return_ACPI_STATUS (Status);
1227 Status = AcpiNsLoadTable (TableIndex, ParentNode);
1228 if (ACPI_FAILURE (Status))
1230 return_ACPI_STATUS (Status);
1234 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
1235 * responsible for discovering any new wake GPEs by running _PRW methods
1236 * that may have been loaded by this table.
1238 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
1239 if (ACPI_SUCCESS (Status))
1241 AcpiEvUpdateGpes (OwnerId);
1244 /* Invoke table handler */
1246 AcpiTbNotifyTable (ACPI_TABLE_EVENT_LOAD, Table);
1247 return_ACPI_STATUS (Status);
1251 /*******************************************************************************
1253 * FUNCTION: AcpiTbInstallAndLoadTable
1255 * PARAMETERS: Address - Physical address of the table
1256 * Flags - Allocation flags of the table
1257 * Table - Pointer to the table (required for
1258 * virtual origins, optional for
1260 * Override - Whether override should be performed
1261 * TableIndex - Where table index is returned
1265 * DESCRIPTION: Install and load an ACPI table
1267 ******************************************************************************/
1270 AcpiTbInstallAndLoadTable (
1271 ACPI_PHYSICAL_ADDRESS Address,
1273 ACPI_TABLE_HEADER *Table,
1281 ACPI_FUNCTION_TRACE (TbInstallAndLoadTable);
1284 /* Install the table and load it into the namespace */
1286 Status = AcpiTbInstallStandardTable (Address, Flags, Table, TRUE,
1288 if (ACPI_FAILURE (Status))
1293 Status = AcpiTbLoadTable (i, AcpiGbl_RootNode);
1297 return_ACPI_STATUS (Status);
1301 /*******************************************************************************
1303 * FUNCTION: AcpiTbUnloadTable
1305 * PARAMETERS: TableIndex - Table index
1309 * DESCRIPTION: Unload an ACPI table
1311 ******************************************************************************/
1317 ACPI_STATUS Status = AE_OK;
1318 ACPI_TABLE_HEADER *Table;
1321 ACPI_FUNCTION_TRACE (TbUnloadTable);
1324 /* Ensure the table is still loaded */
1326 if (!AcpiTbIsTableLoaded (TableIndex))
1328 return_ACPI_STATUS (AE_NOT_EXIST);
1331 /* Invoke table handler */
1333 Status = AcpiGetTableByIndex (TableIndex, &Table);
1334 if (ACPI_SUCCESS (Status))
1336 AcpiTbNotifyTable (ACPI_TABLE_EVENT_UNLOAD, Table);
1339 /* Delete the portion of the namespace owned by this table */
1341 Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
1342 if (ACPI_FAILURE (Status))
1344 return_ACPI_STATUS (Status);
1347 (void) AcpiTbReleaseOwnerId (TableIndex);
1348 AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
1349 return_ACPI_STATUS (Status);
1353 /*******************************************************************************
1355 * FUNCTION: AcpiTbNotifyTable
1357 * PARAMETERS: Event - Table event
1358 * Table - Validated table pointer
1362 * DESCRIPTION: Notify a table event to the users.
1364 ******************************************************************************/
1371 /* Invoke table handler if present */
1373 if (AcpiGbl_TableHandler)
1375 (void) AcpiGbl_TableHandler (Event, Table,
1376 AcpiGbl_TableHandlerContext);