xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/utilities/utxface.c (revision 6c4a44e36ba846c54467103f884d65dfa13e7fcb)
1 /******************************************************************************
2  *
3  * Module Name: utxface - External interfaces for "global" ACPI functions
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2012, 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 
117 #define __UTXFACE_C__
118 
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acevents.h"
122 #include "acnamesp.h"
123 #include "acdebug.h"
124 #include "actables.h"
125 
126 #define _COMPONENT          ACPI_UTILITIES
127         ACPI_MODULE_NAME    ("utxface")
128 
129 
130 #ifndef ACPI_ASL_COMPILER
131 /*******************************************************************************
132  *
133  * FUNCTION:    AcpiInitializeSubsystem
134  *
135  * PARAMETERS:  None
136  *
137  * RETURN:      Status
138  *
139  * DESCRIPTION: Initializes all global variables.  This is the first function
140  *              called, so any early initialization belongs here.
141  *
142  ******************************************************************************/
143 
144 ACPI_STATUS
145 AcpiInitializeSubsystem (
146     void)
147 {
148     ACPI_STATUS             Status;
149 
150 
151     ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem);
152 
153 
154     AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE;
155     ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ());
156 
157     /* Initialize the OS-Dependent layer */
158 
159     Status = AcpiOsInitialize ();
160     if (ACPI_FAILURE (Status))
161     {
162         ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization"));
163         return_ACPI_STATUS (Status);
164     }
165 
166     /* Initialize all globals used by the subsystem */
167 
168     Status = AcpiUtInitGlobals ();
169     if (ACPI_FAILURE (Status))
170     {
171         ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals"));
172         return_ACPI_STATUS (Status);
173     }
174 
175     /* Create the default mutex objects */
176 
177     Status = AcpiUtMutexInitialize ();
178     if (ACPI_FAILURE (Status))
179     {
180         ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation"));
181         return_ACPI_STATUS (Status);
182     }
183 
184     /*
185      * Initialize the namespace manager and
186      * the root of the namespace tree
187      */
188     Status = AcpiNsRootInitialize ();
189     if (ACPI_FAILURE (Status))
190     {
191         ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization"));
192         return_ACPI_STATUS (Status);
193     }
194 
195     /* Initialize the global OSI interfaces list with the static names */
196 
197     Status = AcpiUtInitializeInterfaces ();
198     if (ACPI_FAILURE (Status))
199     {
200         ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization"));
201         return_ACPI_STATUS (Status);
202     }
203 
204     /* If configured, initialize the AML debugger */
205 
206     ACPI_DEBUGGER_EXEC (Status = AcpiDbInitialize ());
207     return_ACPI_STATUS (Status);
208 }
209 
210 ACPI_EXPORT_SYMBOL (AcpiInitializeSubsystem)
211 
212 
213 /*******************************************************************************
214  *
215  * FUNCTION:    AcpiEnableSubsystem
216  *
217  * PARAMETERS:  Flags           - Init/enable Options
218  *
219  * RETURN:      Status
220  *
221  * DESCRIPTION: Completes the subsystem initialization including hardware.
222  *              Puts system into ACPI mode if it isn't already.
223  *
224  ******************************************************************************/
225 
226 ACPI_STATUS
227 AcpiEnableSubsystem (
228     UINT32                  Flags)
229 {
230     ACPI_STATUS             Status = AE_OK;
231 
232 
233     ACPI_FUNCTION_TRACE (AcpiEnableSubsystem);
234 
235 
236 #if (!ACPI_REDUCED_HARDWARE)
237 
238     /* Enable ACPI mode */
239 
240     if (!(Flags & ACPI_NO_ACPI_ENABLE))
241     {
242         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n"));
243 
244         AcpiGbl_OriginalMode = AcpiHwGetMode();
245 
246         Status = AcpiEnable ();
247         if (ACPI_FAILURE (Status))
248         {
249             ACPI_WARNING ((AE_INFO, "AcpiEnable failed"));
250             return_ACPI_STATUS (Status);
251         }
252     }
253 
254     /*
255      * Obtain a permanent mapping for the FACS. This is required for the
256      * Global Lock and the Firmware Waking Vector
257      */
258     Status = AcpiTbInitializeFacs ();
259     if (ACPI_FAILURE (Status))
260     {
261         ACPI_WARNING ((AE_INFO, "Could not map the FACS table"));
262         return_ACPI_STATUS (Status);
263     }
264 
265 #endif /* !ACPI_REDUCED_HARDWARE */
266 
267     /*
268      * Install the default OpRegion handlers.  These are installed unless
269      * other handlers have already been installed via the
270      * InstallAddressSpaceHandler interface.
271      */
272     if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
273     {
274         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
275             "[Init] Installing default address space handlers\n"));
276 
277         Status = AcpiEvInstallRegionHandlers ();
278         if (ACPI_FAILURE (Status))
279         {
280             return_ACPI_STATUS (Status);
281         }
282     }
283 
284 #if (!ACPI_REDUCED_HARDWARE)
285     /*
286      * Initialize ACPI Event handling (Fixed and General Purpose)
287      *
288      * Note1: We must have the hardware and events initialized before we can
289      * execute any control methods safely. Any control method can require
290      * ACPI hardware support, so the hardware must be fully initialized before
291      * any method execution!
292      *
293      * Note2: Fixed events are initialized and enabled here. GPEs are
294      * initialized, but cannot be enabled until after the hardware is
295      * completely initialized (SCI and GlobalLock activated) and the various
296      * initialization control methods are run (_REG, _STA, _INI) on the
297      * entire namespace.
298      */
299     if (!(Flags & ACPI_NO_EVENT_INIT))
300     {
301         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
302             "[Init] Initializing ACPI events\n"));
303 
304         Status = AcpiEvInitializeEvents ();
305         if (ACPI_FAILURE (Status))
306         {
307             return_ACPI_STATUS (Status);
308         }
309     }
310 
311     /*
312      * Install the SCI handler and Global Lock handler. This completes the
313      * hardware initialization.
314      */
315     if (!(Flags & ACPI_NO_HANDLER_INIT))
316     {
317         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
318             "[Init] Installing SCI/GL handlers\n"));
319 
320         Status = AcpiEvInstallXruptHandlers ();
321         if (ACPI_FAILURE (Status))
322         {
323             return_ACPI_STATUS (Status);
324         }
325     }
326 
327 #endif /* !ACPI_REDUCED_HARDWARE */
328 
329     return_ACPI_STATUS (Status);
330 }
331 
332 ACPI_EXPORT_SYMBOL (AcpiEnableSubsystem)
333 
334 
335 /*******************************************************************************
336  *
337  * FUNCTION:    AcpiInitializeObjects
338  *
339  * PARAMETERS:  Flags           - Init/enable Options
340  *
341  * RETURN:      Status
342  *
343  * DESCRIPTION: Completes namespace initialization by initializing device
344  *              objects and executing AML code for Regions, buffers, etc.
345  *
346  ******************************************************************************/
347 
348 ACPI_STATUS
349 AcpiInitializeObjects (
350     UINT32                  Flags)
351 {
352     ACPI_STATUS             Status = AE_OK;
353 
354 
355     ACPI_FUNCTION_TRACE (AcpiInitializeObjects);
356 
357 
358     /*
359      * Run all _REG methods
360      *
361      * Note: Any objects accessed by the _REG methods will be automatically
362      * initialized, even if they contain executable AML (see the call to
363      * AcpiNsInitializeObjects below).
364      */
365     if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
366     {
367         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
368             "[Init] Executing _REG OpRegion methods\n"));
369 
370         Status = AcpiEvInitializeOpRegions ();
371         if (ACPI_FAILURE (Status))
372         {
373             return_ACPI_STATUS (Status);
374         }
375     }
376 
377     /*
378      * Execute any module-level code that was detected during the table load
379      * phase. Although illegal since ACPI 2.0, there are many machines that
380      * contain this type of code. Each block of detected executable AML code
381      * outside of any control method is wrapped with a temporary control
382      * method object and placed on a global list. The methods on this list
383      * are executed below.
384      */
385     AcpiNsExecModuleCodeList ();
386 
387     /*
388      * Initialize the objects that remain uninitialized. This runs the
389      * executable AML that may be part of the declaration of these objects:
390      * OperationRegions, BufferFields, Buffers, and Packages.
391      */
392     if (!(Flags & ACPI_NO_OBJECT_INIT))
393     {
394         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
395             "[Init] Completing Initialization of ACPI Objects\n"));
396 
397         Status = AcpiNsInitializeObjects ();
398         if (ACPI_FAILURE (Status))
399         {
400             return_ACPI_STATUS (Status);
401         }
402     }
403 
404     /*
405      * Initialize all device objects in the namespace. This runs the device
406      * _STA and _INI methods.
407      */
408     if (!(Flags & ACPI_NO_DEVICE_INIT))
409     {
410         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
411             "[Init] Initializing ACPI Devices\n"));
412 
413         Status = AcpiNsInitializeDevices ();
414         if (ACPI_FAILURE (Status))
415         {
416             return_ACPI_STATUS (Status);
417         }
418     }
419 
420     /*
421      * Empty the caches (delete the cached objects) on the assumption that
422      * the table load filled them up more than they will be at runtime --
423      * thus wasting non-paged memory.
424      */
425     Status = AcpiPurgeCachedObjects ();
426 
427     AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
428     return_ACPI_STATUS (Status);
429 }
430 
431 ACPI_EXPORT_SYMBOL (AcpiInitializeObjects)
432 
433 
434 #endif
435 
436 /*******************************************************************************
437  *
438  * FUNCTION:    AcpiTerminate
439  *
440  * PARAMETERS:  None
441  *
442  * RETURN:      Status
443  *
444  * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
445  *
446  ******************************************************************************/
447 
448 ACPI_STATUS
449 AcpiTerminate (
450     void)
451 {
452     ACPI_STATUS         Status;
453 
454 
455     ACPI_FUNCTION_TRACE (AcpiTerminate);
456 
457 
458     /* Just exit if subsystem is already shutdown */
459 
460     if (AcpiGbl_Shutdown)
461     {
462         ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
463         return_ACPI_STATUS (AE_OK);
464     }
465 
466     /* Subsystem appears active, go ahead and shut it down */
467 
468     AcpiGbl_Shutdown = TRUE;
469     AcpiGbl_StartupFlags = 0;
470     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
471 
472     /* Terminate the AML Debugger if present */
473 
474     ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = TRUE);
475 
476     /* Shutdown and free all resources */
477 
478     AcpiUtSubsystemShutdown ();
479 
480     /* Free the mutex objects */
481 
482     AcpiUtMutexTerminate ();
483 
484 
485 #ifdef ACPI_DEBUGGER
486 
487     /* Shut down the debugger */
488 
489     AcpiDbTerminate ();
490 #endif
491 
492     /* Now we can shutdown the OS-dependent layer */
493 
494     Status = AcpiOsTerminate ();
495     return_ACPI_STATUS (Status);
496 }
497 
498 ACPI_EXPORT_SYMBOL (AcpiTerminate)
499 
500 
501 #ifndef ACPI_ASL_COMPILER
502 /*******************************************************************************
503  *
504  * FUNCTION:    AcpiSubsystemStatus
505  *
506  * PARAMETERS:  None
507  *
508  * RETURN:      Status of the ACPI subsystem
509  *
510  * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
511  *              before making any other calls, to ensure the subsystem
512  *              initialized successfully.
513  *
514  ******************************************************************************/
515 
516 ACPI_STATUS
517 AcpiSubsystemStatus (
518     void)
519 {
520 
521     if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
522     {
523         return (AE_OK);
524     }
525     else
526     {
527         return (AE_ERROR);
528     }
529 }
530 
531 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
532 
533 
534 /*******************************************************************************
535  *
536  * FUNCTION:    AcpiGetSystemInfo
537  *
538  * PARAMETERS:  OutBuffer       - A buffer to receive the resources for the
539  *                                device
540  *
541  * RETURN:      Status          - the status of the call
542  *
543  * DESCRIPTION: This function is called to get information about the current
544  *              state of the ACPI subsystem.  It will return system information
545  *              in the OutBuffer.
546  *
547  *              If the function fails an appropriate status will be returned
548  *              and the value of OutBuffer is undefined.
549  *
550  ******************************************************************************/
551 
552 ACPI_STATUS
553 AcpiGetSystemInfo (
554     ACPI_BUFFER             *OutBuffer)
555 {
556     ACPI_SYSTEM_INFO        *InfoPtr;
557     ACPI_STATUS             Status;
558 
559 
560     ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
561 
562 
563     /* Parameter validation */
564 
565     Status = AcpiUtValidateBuffer (OutBuffer);
566     if (ACPI_FAILURE (Status))
567     {
568         return_ACPI_STATUS (Status);
569     }
570 
571     /* Validate/Allocate/Clear caller buffer */
572 
573     Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
574     if (ACPI_FAILURE (Status))
575     {
576         return_ACPI_STATUS (Status);
577     }
578 
579     /*
580      * Populate the return buffer
581      */
582     InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
583 
584     InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
585 
586     /* System flags (ACPI capabilities) */
587 
588     InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
589 
590     /* Timer resolution - 24 or 32 bits  */
591 
592     if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
593     {
594         InfoPtr->TimerResolution = 24;
595     }
596     else
597     {
598         InfoPtr->TimerResolution = 32;
599     }
600 
601     /* Clear the reserved fields */
602 
603     InfoPtr->Reserved1 = 0;
604     InfoPtr->Reserved2 = 0;
605 
606     /* Current debug levels */
607 
608     InfoPtr->DebugLayer = AcpiDbgLayer;
609     InfoPtr->DebugLevel = AcpiDbgLevel;
610 
611     return_ACPI_STATUS (AE_OK);
612 }
613 
614 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
615 
616 
617 /*******************************************************************************
618  *
619  * FUNCTION:    AcpiGetStatistics
620  *
621  * PARAMETERS:  Stats           - Where the statistics are returned
622  *
623  * RETURN:      Status          - the status of the call
624  *
625  * DESCRIPTION: Get the contents of the various system counters
626  *
627  ******************************************************************************/
628 
629 ACPI_STATUS
630 AcpiGetStatistics (
631     ACPI_STATISTICS         *Stats)
632 {
633     ACPI_FUNCTION_TRACE (AcpiGetStatistics);
634 
635 
636     /* Parameter validation */
637 
638     if (!Stats)
639     {
640         return_ACPI_STATUS (AE_BAD_PARAMETER);
641     }
642 
643     /* Various interrupt-based event counters */
644 
645     Stats->SciCount = AcpiSciCount;
646     Stats->GpeCount = AcpiGpeCount;
647 
648     ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount,
649         sizeof (AcpiFixedEventCount));
650 
651 
652     /* Other counters */
653 
654     Stats->MethodCount = AcpiMethodCount;
655 
656     return_ACPI_STATUS (AE_OK);
657 }
658 
659 ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
660 
661 
662 /*****************************************************************************
663  *
664  * FUNCTION:    AcpiInstallInitializationHandler
665  *
666  * PARAMETERS:  Handler             - Callback procedure
667  *              Function            - Not (currently) used, see below
668  *
669  * RETURN:      Status
670  *
671  * DESCRIPTION: Install an initialization handler
672  *
673  * TBD: When a second function is added, must save the Function also.
674  *
675  ****************************************************************************/
676 
677 ACPI_STATUS
678 AcpiInstallInitializationHandler (
679     ACPI_INIT_HANDLER       Handler,
680     UINT32                  Function)
681 {
682 
683     if (!Handler)
684     {
685         return (AE_BAD_PARAMETER);
686     }
687 
688     if (AcpiGbl_InitHandler)
689     {
690         return (AE_ALREADY_EXISTS);
691     }
692 
693     AcpiGbl_InitHandler = Handler;
694     return AE_OK;
695 }
696 
697 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
698 
699 
700 /*****************************************************************************
701  *
702  * FUNCTION:    AcpiPurgeCachedObjects
703  *
704  * PARAMETERS:  None
705  *
706  * RETURN:      Status
707  *
708  * DESCRIPTION: Empty all caches (delete the cached objects)
709  *
710  ****************************************************************************/
711 
712 ACPI_STATUS
713 AcpiPurgeCachedObjects (
714     void)
715 {
716     ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
717 
718     (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
719     (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
720     (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
721     (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
722     return_ACPI_STATUS (AE_OK);
723 }
724 
725 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
726 
727 
728 /*****************************************************************************
729  *
730  * FUNCTION:    AcpiInstallInterface
731  *
732  * PARAMETERS:  InterfaceName       - The interface to install
733  *
734  * RETURN:      Status
735  *
736  * DESCRIPTION: Install an _OSI interface to the global list
737  *
738  ****************************************************************************/
739 
740 ACPI_STATUS
741 AcpiInstallInterface (
742     ACPI_STRING             InterfaceName)
743 {
744     ACPI_STATUS             Status;
745     ACPI_INTERFACE_INFO     *InterfaceInfo;
746 
747 
748     /* Parameter validation */
749 
750     if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
751     {
752         return (AE_BAD_PARAMETER);
753     }
754 
755     (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
756 
757     /* Check if the interface name is already in the global list */
758 
759     InterfaceInfo = AcpiUtGetInterface (InterfaceName);
760     if (InterfaceInfo)
761     {
762         /*
763          * The interface already exists in the list. This is OK if the
764          * interface has been marked invalid -- just clear the bit.
765          */
766         if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
767         {
768             InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
769             Status = AE_OK;
770         }
771         else
772         {
773             Status = AE_ALREADY_EXISTS;
774         }
775     }
776     else
777     {
778         /* New interface name, install into the global list */
779 
780         Status = AcpiUtInstallInterface (InterfaceName);
781     }
782 
783     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
784     return (Status);
785 }
786 
787 ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
788 
789 
790 /*****************************************************************************
791  *
792  * FUNCTION:    AcpiRemoveInterface
793  *
794  * PARAMETERS:  InterfaceName       - The interface to remove
795  *
796  * RETURN:      Status
797  *
798  * DESCRIPTION: Remove an _OSI interface from the global list
799  *
800  ****************************************************************************/
801 
802 ACPI_STATUS
803 AcpiRemoveInterface (
804     ACPI_STRING             InterfaceName)
805 {
806     ACPI_STATUS             Status;
807 
808 
809     /* Parameter validation */
810 
811     if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
812     {
813         return (AE_BAD_PARAMETER);
814     }
815 
816     (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
817 
818     Status = AcpiUtRemoveInterface (InterfaceName);
819 
820     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
821     return (Status);
822 }
823 
824 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
825 
826 
827 /*****************************************************************************
828  *
829  * FUNCTION:    AcpiInstallInterfaceHandler
830  *
831  * PARAMETERS:  Handler             - The _OSI interface handler to install
832  *                                    NULL means "remove existing handler"
833  *
834  * RETURN:      Status
835  *
836  * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
837  *              invoked during execution of the internal implementation of
838  *              _OSI. A NULL handler simply removes any existing handler.
839  *
840  ****************************************************************************/
841 
842 ACPI_STATUS
843 AcpiInstallInterfaceHandler (
844     ACPI_INTERFACE_HANDLER  Handler)
845 {
846     ACPI_STATUS             Status = AE_OK;
847 
848 
849     (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
850 
851     if (Handler && AcpiGbl_InterfaceHandler)
852     {
853         Status = AE_ALREADY_EXISTS;
854     }
855     else
856     {
857         AcpiGbl_InterfaceHandler = Handler;
858     }
859 
860     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
861     return (Status);
862 }
863 
864 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
865 
866 
867 /*****************************************************************************
868  *
869  * FUNCTION:    AcpiCheckAddressRange
870  *
871  * PARAMETERS:  SpaceId             - Address space ID
872  *              Address             - Start address
873  *              Length              - Length
874  *              Warn                - TRUE if warning on overlap desired
875  *
876  * RETURN:      Count of the number of conflicts detected.
877  *
878  * DESCRIPTION: Check if the input address range overlaps any of the
879  *              ASL operation region address ranges.
880  *
881  ****************************************************************************/
882 
883 UINT32
884 AcpiCheckAddressRange (
885     ACPI_ADR_SPACE_TYPE     SpaceId,
886     ACPI_PHYSICAL_ADDRESS   Address,
887     ACPI_SIZE               Length,
888     BOOLEAN                 Warn)
889 {
890     UINT32                  Overlaps;
891     ACPI_STATUS             Status;
892 
893 
894     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
895     if (ACPI_FAILURE (Status))
896     {
897         return (0);
898     }
899 
900     Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
901         (UINT32) Length, Warn);
902 
903     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
904     return (Overlaps);
905 }
906 
907 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
908 
909 #endif /* !ACPI_ASL_COMPILER */
910