xref: /freebsd/sys/contrib/dev/acpica/components/tables/tbxface.c (revision 4f52dfbb8d6c4d446500c5b097e3806ec219fbd4)
1 /******************************************************************************
2  *
3  * Module Name: tbxface - ACPI table-oriented external interfaces
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
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
97  * LIMITED REMEDY.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
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.
133  *
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.
145  *
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.
149  *
150  *****************************************************************************/
151 
152 #define EXPORT_ACPI_INTERFACES
153 
154 #include <contrib/dev/acpica/include/acpi.h>
155 #include <contrib/dev/acpica/include/accommon.h>
156 #include <contrib/dev/acpica/include/actables.h>
157 
158 #define _COMPONENT          ACPI_TABLES
159         ACPI_MODULE_NAME    ("tbxface")
160 
161 
162 /*******************************************************************************
163  *
164  * FUNCTION:    AcpiAllocateRootTable
165  *
166  * PARAMETERS:  InitialTableCount   - Size of InitialTableArray, in number of
167  *                                    ACPI_TABLE_DESC structures
168  *
169  * RETURN:      Status
170  *
171  * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
172  *              AcpiInitializeTables.
173  *
174  ******************************************************************************/
175 
176 ACPI_STATUS
177 AcpiAllocateRootTable (
178     UINT32                  InitialTableCount)
179 {
180 
181     AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
182     AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE;
183 
184     return (AcpiTbResizeRootTableList ());
185 }
186 
187 
188 /*******************************************************************************
189  *
190  * FUNCTION:    AcpiInitializeTables
191  *
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.
200  *
201  * RETURN:      Status
202  *
203  * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
204  *
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.
208  *
209  *              If the host OS memory managers are initialized, use NULL for
210  *              InitialTableArray, and the table will be dynamically allocated.
211  *
212  ******************************************************************************/
213 
214 ACPI_STATUS ACPI_INIT_FUNCTION
215 AcpiInitializeTables (
216     ACPI_TABLE_DESC         *InitialTableArray,
217     UINT32                  InitialTableCount,
218     BOOLEAN                 AllowResize)
219 {
220     ACPI_PHYSICAL_ADDRESS   RsdpAddress;
221     ACPI_STATUS             Status;
222 
223 
224     ACPI_FUNCTION_TRACE (AcpiInitializeTables);
225 
226 
227     /*
228      * Setup the Root Table Array and allocate the table array
229      * if requested
230      */
231     if (!InitialTableArray)
232     {
233         Status = AcpiAllocateRootTable (InitialTableCount);
234         if (ACPI_FAILURE (Status))
235         {
236             return_ACPI_STATUS (Status);
237         }
238     }
239     else
240     {
241         /* Root Table Array has been statically allocated by the host */
242 
243         memset (InitialTableArray, 0,
244             (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC));
245 
246         AcpiGbl_RootTableList.Tables = InitialTableArray;
247         AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
248         AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN;
249         if (AllowResize)
250         {
251             AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
252         }
253     }
254 
255     /* Get the address of the RSDP */
256 
257     RsdpAddress = AcpiOsGetRootPointer ();
258     if (!RsdpAddress)
259     {
260         return_ACPI_STATUS (AE_NOT_FOUND);
261     }
262 
263     /*
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.
267      */
268     Status = AcpiTbParseRootTable (RsdpAddress);
269     return_ACPI_STATUS (Status);
270 }
271 
272 ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeTables)
273 
274 
275 /*******************************************************************************
276  *
277  * FUNCTION:    AcpiReallocateRootTable
278  *
279  * PARAMETERS:  None
280  *
281  * RETURN:      Status
282  *
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
286  *              kernel.
287  *
288  ******************************************************************************/
289 
290 ACPI_STATUS ACPI_INIT_FUNCTION
291 AcpiReallocateRootTable (
292     void)
293 {
294     ACPI_STATUS             Status;
295     ACPI_TABLE_DESC         *TableDesc;
296     UINT32                  i, j;
297 
298 
299     ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
300 
301 
302     /*
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().
307      */
308     if ((AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) &&
309         AcpiGbl_EnableTableValidation)
310     {
311         return_ACPI_STATUS (AE_SUPPORT);
312     }
313 
314     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
315 
316     /*
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
320      * early stage.
321      */
322     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
323     {
324         TableDesc = &AcpiGbl_RootTableList.Tables[i];
325         if (TableDesc->Pointer)
326         {
327             ACPI_ERROR ((AE_INFO,
328                 "Table [%4.4s] is not invalidated during early boot stage",
329                 TableDesc->Signature.Ascii));
330         }
331     }
332 
333     if (!AcpiGbl_EnableTableValidation)
334     {
335         /*
336          * Now it's safe to do full table validation. We can do deferred
337          * table initilization here once the flag is set.
338          */
339         AcpiGbl_EnableTableValidation = TRUE;
340         for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
341         {
342             TableDesc = &AcpiGbl_RootTableList.Tables[i];
343             if (!(TableDesc->Flags & ACPI_TABLE_IS_VERIFIED))
344             {
345                 Status = AcpiTbVerifyTempTable (TableDesc, NULL, &j);
346                 if (ACPI_FAILURE (Status))
347                 {
348                     AcpiTbUninstallTable (TableDesc);
349                 }
350             }
351         }
352     }
353 
354     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
355     Status = AcpiTbResizeRootTableList ();
356     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
357 
358     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
359     return_ACPI_STATUS (Status);
360 }
361 
362 ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable)
363 
364 
365 /*******************************************************************************
366  *
367  * FUNCTION:    AcpiGetTableHeader
368  *
369  * PARAMETERS:  Signature           - ACPI signature of needed table
370  *              Instance            - Which instance (for SSDTs)
371  *              OutTableHeader      - The pointer to the table header to fill
372  *
373  * RETURN:      Status and pointer to mapped table header
374  *
375  * DESCRIPTION: Finds an ACPI table header.
376  *
377  * NOTE:        Caller is responsible in unmapping the header with
378  *              AcpiOsUnmapMemory
379  *
380  ******************************************************************************/
381 
382 ACPI_STATUS
383 AcpiGetTableHeader (
384     char                    *Signature,
385     UINT32                  Instance,
386     ACPI_TABLE_HEADER       *OutTableHeader)
387 {
388     UINT32                  i;
389     UINT32                  j;
390     ACPI_TABLE_HEADER       *Header;
391 
392 
393     /* Parameter validation */
394 
395     if (!Signature || !OutTableHeader)
396     {
397         return (AE_BAD_PARAMETER);
398     }
399 
400     /* Walk the root table list */
401 
402     for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
403     {
404         if (!ACPI_COMPARE_NAME (
405                 &(AcpiGbl_RootTableList.Tables[i].Signature), Signature))
406         {
407             continue;
408         }
409 
410         if (++j < Instance)
411         {
412             continue;
413         }
414 
415         if (!AcpiGbl_RootTableList.Tables[i].Pointer)
416         {
417             if ((AcpiGbl_RootTableList.Tables[i].Flags &
418                     ACPI_TABLE_ORIGIN_MASK) ==
419                 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL)
420             {
421                 Header = AcpiOsMapMemory (
422                     AcpiGbl_RootTableList.Tables[i].Address,
423                     sizeof (ACPI_TABLE_HEADER));
424                 if (!Header)
425                 {
426                     return (AE_NO_MEMORY);
427                 }
428 
429                 memcpy (OutTableHeader, Header, sizeof (ACPI_TABLE_HEADER));
430                 AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
431             }
432             else
433             {
434                 return (AE_NOT_FOUND);
435             }
436         }
437         else
438         {
439             memcpy (OutTableHeader,
440                 AcpiGbl_RootTableList.Tables[i].Pointer,
441                 sizeof (ACPI_TABLE_HEADER));
442         }
443 
444         return (AE_OK);
445     }
446 
447     return (AE_NOT_FOUND);
448 }
449 
450 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
451 
452 
453 /*******************************************************************************
454  *
455  * FUNCTION:    AcpiGetTable
456  *
457  * PARAMETERS:  Signature           - ACPI signature of needed table
458  *              Instance            - Which instance (for SSDTs)
459  *              OutTable            - Where the pointer to the table is returned
460  *
461  * RETURN:      Status and pointer to the requested table
462  *
463  * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
464  *              RSDT/XSDT.
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.
470  *
471  ******************************************************************************/
472 
473 ACPI_STATUS
474 AcpiGetTable (
475     char                    *Signature,
476     UINT32                  Instance,
477     ACPI_TABLE_HEADER       **OutTable)
478 {
479     UINT32                  i;
480     UINT32                  j;
481     ACPI_STATUS             Status = AE_NOT_FOUND;
482     ACPI_TABLE_DESC         *TableDesc;
483 
484 
485     /* Parameter validation */
486 
487     if (!Signature || !OutTable)
488     {
489         return (AE_BAD_PARAMETER);
490     }
491 
492     /*
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.
496      */
497     *OutTable = NULL;
498 
499     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
500 
501     /* Walk the root table list */
502 
503     for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
504     {
505         TableDesc = &AcpiGbl_RootTableList.Tables[i];
506 
507         if (!ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
508         {
509             continue;
510         }
511 
512         if (++j < Instance)
513         {
514             continue;
515         }
516 
517         Status = AcpiTbGetTable (TableDesc, OutTable);
518         break;
519     }
520 
521     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
522     return (Status);
523 }
524 
525 ACPI_EXPORT_SYMBOL (AcpiGetTable)
526 
527 
528 /*******************************************************************************
529  *
530  * FUNCTION:    AcpiPutTable
531  *
532  * PARAMETERS:  Table               - The pointer to the table
533  *
534  * RETURN:      None
535  *
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
540  *              situations.
541  *
542  ******************************************************************************/
543 
544 void
545 AcpiPutTable (
546     ACPI_TABLE_HEADER       *Table)
547 {
548     UINT32                  i;
549     ACPI_TABLE_DESC         *TableDesc;
550 
551 
552     ACPI_FUNCTION_TRACE (AcpiPutTable);
553 
554 
555     if (!Table)
556     {
557         return_VOID;
558     }
559 
560     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
561 
562     /* Walk the root table list */
563 
564     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
565     {
566         TableDesc = &AcpiGbl_RootTableList.Tables[i];
567 
568         if (TableDesc->Pointer != Table)
569         {
570             continue;
571         }
572 
573         AcpiTbPutTable (TableDesc);
574         break;
575     }
576 
577     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
578     return_VOID;
579 }
580 
581 ACPI_EXPORT_SYMBOL (AcpiPutTable)
582 
583 
584 /*******************************************************************************
585  *
586  * FUNCTION:    AcpiGetTableByIndex
587  *
588  * PARAMETERS:  TableIndex          - Table index
589  *              OutTable            - Where the pointer to the table is returned
590  *
591  * RETURN:      Status and pointer to the requested table
592  *
593  * DESCRIPTION: Obtain a table by an index into the global table list. Used
594  *              internally also.
595  *
596  ******************************************************************************/
597 
598 ACPI_STATUS
599 AcpiGetTableByIndex (
600     UINT32                  TableIndex,
601     ACPI_TABLE_HEADER       **OutTable)
602 {
603     ACPI_STATUS             Status;
604 
605 
606     ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
607 
608 
609     /* Parameter validation */
610 
611     if (!OutTable)
612     {
613         return_ACPI_STATUS (AE_BAD_PARAMETER);
614     }
615 
616     /*
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.
620      */
621     *OutTable = NULL;
622 
623     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
624 
625     /* Validate index */
626 
627     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
628     {
629         Status = AE_BAD_PARAMETER;
630         goto UnlockAndExit;
631     }
632 
633     Status = AcpiTbGetTable (
634         &AcpiGbl_RootTableList.Tables[TableIndex], OutTable);
635 
636 UnlockAndExit:
637     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
638     return_ACPI_STATUS (Status);
639 }
640 
641 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
642 
643 
644 /*******************************************************************************
645  *
646  * FUNCTION:    AcpiInstallTableHandler
647  *
648  * PARAMETERS:  Handler         - Table event handler
649  *              Context         - Value passed to the handler on each event
650  *
651  * RETURN:      Status
652  *
653  * DESCRIPTION: Install a global table event handler.
654  *
655  ******************************************************************************/
656 
657 ACPI_STATUS
658 AcpiInstallTableHandler (
659     ACPI_TABLE_HANDLER      Handler,
660     void                    *Context)
661 {
662     ACPI_STATUS             Status;
663 
664 
665     ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
666 
667 
668     if (!Handler)
669     {
670         return_ACPI_STATUS (AE_BAD_PARAMETER);
671     }
672 
673     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
674     if (ACPI_FAILURE (Status))
675     {
676         return_ACPI_STATUS (Status);
677     }
678 
679     /* Don't allow more than one handler */
680 
681     if (AcpiGbl_TableHandler)
682     {
683         Status = AE_ALREADY_EXISTS;
684         goto Cleanup;
685     }
686 
687     /* Install the handler */
688 
689     AcpiGbl_TableHandler = Handler;
690     AcpiGbl_TableHandlerContext = Context;
691 
692 Cleanup:
693     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
694     return_ACPI_STATUS (Status);
695 }
696 
697 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
698 
699 
700 /*******************************************************************************
701  *
702  * FUNCTION:    AcpiRemoveTableHandler
703  *
704  * PARAMETERS:  Handler         - Table event handler that was installed
705  *                                previously.
706  *
707  * RETURN:      Status
708  *
709  * DESCRIPTION: Remove a table event handler
710  *
711  ******************************************************************************/
712 
713 ACPI_STATUS
714 AcpiRemoveTableHandler (
715     ACPI_TABLE_HANDLER      Handler)
716 {
717     ACPI_STATUS             Status;
718 
719 
720     ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
721 
722 
723     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
724     if (ACPI_FAILURE (Status))
725     {
726         return_ACPI_STATUS (Status);
727     }
728 
729     /* Make sure that the installed handler is the same */
730 
731     if (!Handler ||
732         Handler != AcpiGbl_TableHandler)
733     {
734         Status = AE_BAD_PARAMETER;
735         goto Cleanup;
736     }
737 
738     /* Remove the handler */
739 
740     AcpiGbl_TableHandler = NULL;
741 
742 Cleanup:
743     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
744     return_ACPI_STATUS (Status);
745 }
746 
747 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)
748