1 /******************************************************************************
3 * Module Name: tbxface - ACPI table-oriented external interfaces
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2017, 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 *****************************************************************************/
152 #define EXPORT_ACPI_INTERFACES
155 #include "accommon.h"
156 #include "actables.h"
158 #define _COMPONENT ACPI_TABLES
159 ACPI_MODULE_NAME ("tbxface")
162 /*******************************************************************************
164 * FUNCTION: AcpiAllocateRootTable
166 * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of
167 * ACPI_TABLE_DESC structures
171 * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
172 * AcpiInitializeTables.
174 ******************************************************************************/
177 AcpiAllocateRootTable (
178 UINT32 InitialTableCount
)
181 AcpiGbl_RootTableList
.MaxTableCount
= InitialTableCount
;
182 AcpiGbl_RootTableList
.Flags
= ACPI_ROOT_ALLOW_RESIZE
;
184 return (AcpiTbResizeRootTableList ());
188 /*******************************************************************************
190 * FUNCTION: AcpiInitializeTables
192 * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated
193 * ACPI_TABLE_DESC structures. If NULL, the
194 * array is dynamically allocated.
195 * InitialTableCount - Size of InitialTableArray, in number of
196 * ACPI_TABLE_DESC structures
197 * AllowResize - Flag to tell Table Manager if resize of
198 * pre-allocated array is allowed. Ignored
199 * if InitialTableArray is NULL.
203 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
205 * NOTE: Allows static allocation of the initial table array in order
206 * to avoid the use of dynamic memory in confined environments
207 * such as the kernel boot sequence where it may not be available.
209 * If the host OS memory managers are initialized, use NULL for
210 * InitialTableArray, and the table will be dynamically allocated.
212 ******************************************************************************/
214 ACPI_STATUS ACPI_INIT_FUNCTION
215 AcpiInitializeTables (
216 ACPI_TABLE_DESC
*InitialTableArray
,
217 UINT32 InitialTableCount
,
220 ACPI_PHYSICAL_ADDRESS RsdpAddress
;
224 ACPI_FUNCTION_TRACE (AcpiInitializeTables
);
228 * Setup the Root Table Array and allocate the table array
231 if (!InitialTableArray
)
233 Status
= AcpiAllocateRootTable (InitialTableCount
);
234 if (ACPI_FAILURE (Status
))
236 return_ACPI_STATUS (Status
);
241 /* Root Table Array has been statically allocated by the host */
243 memset (InitialTableArray
, 0,
244 (ACPI_SIZE
) InitialTableCount
* sizeof (ACPI_TABLE_DESC
));
246 AcpiGbl_RootTableList
.Tables
= InitialTableArray
;
247 AcpiGbl_RootTableList
.MaxTableCount
= InitialTableCount
;
248 AcpiGbl_RootTableList
.Flags
= ACPI_ROOT_ORIGIN_UNKNOWN
;
251 AcpiGbl_RootTableList
.Flags
|= ACPI_ROOT_ALLOW_RESIZE
;
255 /* Get the address of the RSDP */
257 RsdpAddress
= AcpiOsGetRootPointer ();
260 return_ACPI_STATUS (AE_NOT_FOUND
);
264 * Get the root table (RSDT or XSDT) and extract all entries to the local
265 * Root Table Array. This array contains the information of the RSDT/XSDT
266 * in a common, more useable format.
268 Status
= AcpiTbParseRootTable (RsdpAddress
);
269 return_ACPI_STATUS (Status
);
272 ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeTables
)
275 /*******************************************************************************
277 * FUNCTION: AcpiReallocateRootTable
283 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
284 * root list from the previously provided scratch area. Should
285 * be called once dynamic memory allocation is available in the
288 ******************************************************************************/
290 ACPI_STATUS ACPI_INIT_FUNCTION
291 AcpiReallocateRootTable (
295 ACPI_TABLE_DESC
*TableDesc
;
299 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable
);
303 * If there are tables unverified, it is required to reallocate the
304 * root table list to clean up invalid table entries. Otherwise only
305 * reallocate the root table list if the host provided a static buffer
306 * for the table array in the call to AcpiInitializeTables().
308 if ((AcpiGbl_RootTableList
.Flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) &&
309 AcpiGbl_EnableTableValidation
)
311 return_ACPI_STATUS (AE_SUPPORT
);
314 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
317 * Ensure OS early boot logic, which is required by some hosts. If the
318 * table state is reported to be wrong, developers should fix the
319 * issue by invoking AcpiPutTable() for the reported table during the
322 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
324 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
325 if (TableDesc
->Pointer
)
327 ACPI_ERROR ((AE_INFO
,
328 "Table [%4.4s] is not invalidated during early boot stage",
329 TableDesc
->Signature
.Ascii
));
333 if (!AcpiGbl_EnableTableValidation
)
336 * Now it's safe to do full table validation. We can do deferred
337 * table initilization here once the flag is set.
339 AcpiGbl_EnableTableValidation
= TRUE
;
340 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
342 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
343 if (!(TableDesc
->Flags
& ACPI_TABLE_IS_VERIFIED
))
345 Status
= AcpiTbVerifyTempTable (TableDesc
, NULL
, &j
);
346 if (ACPI_FAILURE (Status
))
348 AcpiTbUninstallTable (TableDesc
);
354 AcpiGbl_RootTableList
.Flags
|= ACPI_ROOT_ALLOW_RESIZE
;
355 Status
= AcpiTbResizeRootTableList ();
356 AcpiGbl_RootTableList
.Flags
|= ACPI_ROOT_ORIGIN_ALLOCATED
;
358 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
359 return_ACPI_STATUS (Status
);
362 ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable
)
365 /*******************************************************************************
367 * FUNCTION: AcpiGetTableHeader
369 * PARAMETERS: Signature - ACPI signature of needed table
370 * Instance - Which instance (for SSDTs)
371 * OutTableHeader - The pointer to the table header to fill
373 * RETURN: Status and pointer to mapped table header
375 * DESCRIPTION: Finds an ACPI table header.
377 * NOTE: Caller is responsible in unmapping the header with
380 ******************************************************************************/
386 ACPI_TABLE_HEADER
*OutTableHeader
)
390 ACPI_TABLE_HEADER
*Header
;
393 /* Parameter validation */
395 if (!Signature
|| !OutTableHeader
)
397 return (AE_BAD_PARAMETER
);
400 /* Walk the root table list */
402 for (i
= 0, j
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
404 if (!ACPI_COMPARE_NAME (
405 &(AcpiGbl_RootTableList
.Tables
[i
].Signature
), Signature
))
415 if (!AcpiGbl_RootTableList
.Tables
[i
].Pointer
)
417 if ((AcpiGbl_RootTableList
.Tables
[i
].Flags
&
418 ACPI_TABLE_ORIGIN_MASK
) ==
419 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
)
421 Header
= AcpiOsMapMemory (
422 AcpiGbl_RootTableList
.Tables
[i
].Address
,
423 sizeof (ACPI_TABLE_HEADER
));
426 return (AE_NO_MEMORY
);
429 memcpy (OutTableHeader
, Header
, sizeof (ACPI_TABLE_HEADER
));
430 AcpiOsUnmapMemory (Header
, sizeof (ACPI_TABLE_HEADER
));
434 return (AE_NOT_FOUND
);
439 memcpy (OutTableHeader
,
440 AcpiGbl_RootTableList
.Tables
[i
].Pointer
,
441 sizeof (ACPI_TABLE_HEADER
));
447 return (AE_NOT_FOUND
);
450 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader
)
453 /*******************************************************************************
455 * FUNCTION: AcpiGetTable
457 * PARAMETERS: Signature - ACPI signature of needed table
458 * Instance - Which instance (for SSDTs)
459 * OutTable - Where the pointer to the table is returned
461 * RETURN: Status and pointer to the requested table
463 * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
465 * Note that an early stage AcpiGetTable() call must be paired
466 * with an early stage AcpiPutTable() call. otherwise the table
467 * pointer mapped by the early stage mapping implementation may be
468 * erroneously unmapped by the late stage unmapping implementation
469 * in an AcpiPutTable() invoked during the late stage.
471 ******************************************************************************/
477 ACPI_TABLE_HEADER
**OutTable
)
481 ACPI_STATUS Status
= AE_NOT_FOUND
;
482 ACPI_TABLE_DESC
*TableDesc
;
485 /* Parameter validation */
487 if (!Signature
|| !OutTable
)
489 return (AE_BAD_PARAMETER
);
493 * Note that the following line is required by some OSPMs, they only
494 * check if the returned table is NULL instead of the returned status
495 * to determined if this function is succeeded.
499 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
501 /* Walk the root table list */
503 for (i
= 0, j
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
505 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
507 if (!ACPI_COMPARE_NAME (&TableDesc
->Signature
, Signature
))
517 Status
= AcpiTbGetTable (TableDesc
, OutTable
);
521 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
525 ACPI_EXPORT_SYMBOL (AcpiGetTable
)
528 /*******************************************************************************
530 * FUNCTION: AcpiPutTable
532 * PARAMETERS: Table - The pointer to the table
536 * DESCRIPTION: Release a table returned by AcpiGetTable() and its clones.
537 * Note that it is not safe if this function was invoked after an
538 * uninstallation happened to the original table descriptor.
539 * Currently there is no OSPMs' requirement to handle such
542 ******************************************************************************/
546 ACPI_TABLE_HEADER
*Table
)
549 ACPI_TABLE_DESC
*TableDesc
;
552 ACPI_FUNCTION_TRACE (AcpiPutTable
);
560 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
562 /* Walk the root table list */
564 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
566 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
568 if (TableDesc
->Pointer
!= Table
)
573 AcpiTbPutTable (TableDesc
);
577 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
581 ACPI_EXPORT_SYMBOL (AcpiPutTable
)
584 /*******************************************************************************
586 * FUNCTION: AcpiGetTableByIndex
588 * PARAMETERS: TableIndex - Table index
589 * OutTable - Where the pointer to the table is returned
591 * RETURN: Status and pointer to the requested table
593 * DESCRIPTION: Obtain a table by an index into the global table list. Used
596 ******************************************************************************/
599 AcpiGetTableByIndex (
601 ACPI_TABLE_HEADER
**OutTable
)
606 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex
);
609 /* Parameter validation */
613 return_ACPI_STATUS (AE_BAD_PARAMETER
);
617 * Note that the following line is required by some OSPMs, they only
618 * check if the returned table is NULL instead of the returned status
619 * to determined if this function is succeeded.
623 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
627 if (TableIndex
>= AcpiGbl_RootTableList
.CurrentTableCount
)
629 Status
= AE_BAD_PARAMETER
;
633 Status
= AcpiTbGetTable (
634 &AcpiGbl_RootTableList
.Tables
[TableIndex
], OutTable
);
637 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
638 return_ACPI_STATUS (Status
);
641 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex
)
644 /*******************************************************************************
646 * FUNCTION: AcpiInstallTableHandler
648 * PARAMETERS: Handler - Table event handler
649 * Context - Value passed to the handler on each event
653 * DESCRIPTION: Install a global table event handler.
655 ******************************************************************************/
658 AcpiInstallTableHandler (
659 ACPI_TABLE_HANDLER Handler
,
665 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler
);
670 return_ACPI_STATUS (AE_BAD_PARAMETER
);
673 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
674 if (ACPI_FAILURE (Status
))
676 return_ACPI_STATUS (Status
);
679 /* Don't allow more than one handler */
681 if (AcpiGbl_TableHandler
)
683 Status
= AE_ALREADY_EXISTS
;
687 /* Install the handler */
689 AcpiGbl_TableHandler
= Handler
;
690 AcpiGbl_TableHandlerContext
= Context
;
693 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
694 return_ACPI_STATUS (Status
);
697 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler
)
700 /*******************************************************************************
702 * FUNCTION: AcpiRemoveTableHandler
704 * PARAMETERS: Handler - Table event handler that was installed
709 * DESCRIPTION: Remove a table event handler
711 ******************************************************************************/
714 AcpiRemoveTableHandler (
715 ACPI_TABLE_HANDLER Handler
)
720 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler
);
723 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
724 if (ACPI_FAILURE (Status
))
726 return_ACPI_STATUS (Status
);
729 /* Make sure that the installed handler is the same */
732 Handler
!= AcpiGbl_TableHandler
)
734 Status
= AE_BAD_PARAMETER
;
738 /* Remove the handler */
740 AcpiGbl_TableHandler
= NULL
;
743 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
744 return_ACPI_STATUS (Status
);
747 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler
)