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
154 #include <contrib/dev/acpica/include/acpi.h>
155 #include <contrib/dev/acpica/include/accommon.h>
156 #include <contrib/dev/acpica/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 (
298 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
302 * Only reallocate the root table if the host provided a static buffer
303 * for the table array in the call to AcpiInitializeTables.
305 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
307 return_ACPI_STATUS (AE_SUPPORT);
311 * Ensure OS early boot logic, which is required by some hosts. If the
312 * table state is reported to be wrong, developers should fix the
313 * issue by invoking AcpiPutTable() for the reported table during the
316 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
318 if (AcpiGbl_RootTableList.Tables[i].Pointer)
320 ACPI_ERROR ((AE_INFO,
321 "Table [%4.4s] is not invalidated during early boot stage",
322 AcpiGbl_RootTableList.Tables[i].Signature.Ascii));
326 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
328 Status = AcpiTbResizeRootTableList ();
329 return_ACPI_STATUS (Status);
332 ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable)
335 /*******************************************************************************
337 * FUNCTION: AcpiGetTableHeader
339 * PARAMETERS: Signature - ACPI signature of needed table
340 * Instance - Which instance (for SSDTs)
341 * OutTableHeader - The pointer to the table header to fill
343 * RETURN: Status and pointer to mapped table header
345 * DESCRIPTION: Finds an ACPI table header.
347 * NOTE: Caller is responsible in unmapping the header with
350 ******************************************************************************/
356 ACPI_TABLE_HEADER *OutTableHeader)
360 ACPI_TABLE_HEADER *Header;
363 /* Parameter validation */
365 if (!Signature || !OutTableHeader)
367 return (AE_BAD_PARAMETER);
370 /* Walk the root table list */
372 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
374 if (!ACPI_COMPARE_NAME (
375 &(AcpiGbl_RootTableList.Tables[i].Signature), Signature))
385 if (!AcpiGbl_RootTableList.Tables[i].Pointer)
387 if ((AcpiGbl_RootTableList.Tables[i].Flags &
388 ACPI_TABLE_ORIGIN_MASK) ==
389 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL)
391 Header = AcpiOsMapMemory (
392 AcpiGbl_RootTableList.Tables[i].Address,
393 sizeof (ACPI_TABLE_HEADER));
396 return (AE_NO_MEMORY);
399 memcpy (OutTableHeader, Header, sizeof (ACPI_TABLE_HEADER));
400 AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
404 return (AE_NOT_FOUND);
409 memcpy (OutTableHeader,
410 AcpiGbl_RootTableList.Tables[i].Pointer,
411 sizeof (ACPI_TABLE_HEADER));
417 return (AE_NOT_FOUND);
420 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
423 /*******************************************************************************
425 * FUNCTION: AcpiGetTable
427 * PARAMETERS: Signature - ACPI signature of needed table
428 * Instance - Which instance (for SSDTs)
429 * OutTable - Where the pointer to the table is returned
431 * RETURN: Status and pointer to the requested table
433 * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
435 * Note that an early stage AcpiGetTable() call must be paired
436 * with an early stage AcpiPutTable() call. otherwise the table
437 * pointer mapped by the early stage mapping implementation may be
438 * erroneously unmapped by the late stage unmapping implementation
439 * in an AcpiPutTable() invoked during the late stage.
441 ******************************************************************************/
447 ACPI_TABLE_HEADER **OutTable)
451 ACPI_STATUS Status = AE_NOT_FOUND;
452 ACPI_TABLE_DESC *TableDesc;
455 /* Parameter validation */
457 if (!Signature || !OutTable)
459 return (AE_BAD_PARAMETER);
463 * Note that the following line is required by some OSPMs, they only
464 * check if the returned table is NULL instead of the returned status
465 * to determined if this function is succeeded.
469 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
471 /* Walk the root table list */
473 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
475 TableDesc = &AcpiGbl_RootTableList.Tables[i];
477 if (!ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
487 Status = AcpiTbGetTable (TableDesc, OutTable);
491 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
495 ACPI_EXPORT_SYMBOL (AcpiGetTable)
498 /*******************************************************************************
500 * FUNCTION: AcpiPutTable
502 * PARAMETERS: Table - The pointer to the table
506 * DESCRIPTION: Release a table returned by AcpiGetTable() and its clones.
507 * Note that it is not safe if this function was invoked after an
508 * uninstallation happened to the original table descriptor.
509 * Currently there is no OSPMs' requirement to handle such
512 ******************************************************************************/
516 ACPI_TABLE_HEADER *Table)
519 ACPI_TABLE_DESC *TableDesc;
522 ACPI_FUNCTION_TRACE (AcpiPutTable);
525 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
527 /* Walk the root table list */
529 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
531 TableDesc = &AcpiGbl_RootTableList.Tables[i];
533 if (TableDesc->Pointer != Table)
538 AcpiTbPutTable (TableDesc);
542 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
546 ACPI_EXPORT_SYMBOL (AcpiPutTable)
549 /*******************************************************************************
551 * FUNCTION: AcpiGetTableByIndex
553 * PARAMETERS: TableIndex - Table index
554 * OutTable - Where the pointer to the table is returned
556 * RETURN: Status and pointer to the requested table
558 * DESCRIPTION: Obtain a table by an index into the global table list. Used
561 ******************************************************************************/
564 AcpiGetTableByIndex (
566 ACPI_TABLE_HEADER **OutTable)
571 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
574 /* Parameter validation */
578 return_ACPI_STATUS (AE_BAD_PARAMETER);
582 * Note that the following line is required by some OSPMs, they only
583 * check if the returned table is NULL instead of the returned status
584 * to determined if this function is succeeded.
588 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
592 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
594 Status = AE_BAD_PARAMETER;
598 Status = AcpiTbGetTable (
599 &AcpiGbl_RootTableList.Tables[TableIndex], OutTable);
602 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
603 return_ACPI_STATUS (Status);
606 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
609 /*******************************************************************************
611 * FUNCTION: AcpiInstallTableHandler
613 * PARAMETERS: Handler - Table event handler
614 * Context - Value passed to the handler on each event
618 * DESCRIPTION: Install a global table event handler.
620 ******************************************************************************/
623 AcpiInstallTableHandler (
624 ACPI_TABLE_HANDLER Handler,
630 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
635 return_ACPI_STATUS (AE_BAD_PARAMETER);
638 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
639 if (ACPI_FAILURE (Status))
641 return_ACPI_STATUS (Status);
644 /* Don't allow more than one handler */
646 if (AcpiGbl_TableHandler)
648 Status = AE_ALREADY_EXISTS;
652 /* Install the handler */
654 AcpiGbl_TableHandler = Handler;
655 AcpiGbl_TableHandlerContext = Context;
658 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
659 return_ACPI_STATUS (Status);
662 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
665 /*******************************************************************************
667 * FUNCTION: AcpiRemoveTableHandler
669 * PARAMETERS: Handler - Table event handler that was installed
674 * DESCRIPTION: Remove a table event handler
676 ******************************************************************************/
679 AcpiRemoveTableHandler (
680 ACPI_TABLE_HANDLER Handler)
685 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
688 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
689 if (ACPI_FAILURE (Status))
691 return_ACPI_STATUS (Status);
694 /* Make sure that the installed handler is the same */
697 Handler != AcpiGbl_TableHandler)
699 Status = AE_BAD_PARAMETER;
703 /* Remove the handler */
705 AcpiGbl_TableHandler = NULL;
708 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
709 return_ACPI_STATUS (Status);
712 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)