xref: /titanic_41/usr/src/uts/intel/io/acpica/utilities/utxface.c (revision cde2885fdf538266ee2a3b08dee2d5075ce8fa2b)
1 /******************************************************************************
2  *
3  * Module Name: utxface - External interfaces for "global" ACPI functions
4  *              $Revision: 1.128 $
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 
118 #define __UTXFACE_C__
119 
120 #include "acpi.h"
121 #include "acevents.h"
122 #include "acnamesp.h"
123 #include "acdebug.h"
124 
125 #define _COMPONENT          ACPI_UTILITIES
126         ACPI_MODULE_NAME    ("utxface")
127 
128 
129 #ifndef ACPI_ASL_COMPILER
130 
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     /* If configured, initialize the AML debugger */
196 
197     ACPI_DEBUGGER_EXEC (Status = AcpiDbInitialize ());
198     return_ACPI_STATUS (Status);
199 }
200 
201 ACPI_EXPORT_SYMBOL (AcpiInitializeSubsystem)
202 
203 
204 /*******************************************************************************
205  *
206  * FUNCTION:    AcpiEnableSubsystem
207  *
208  * PARAMETERS:  Flags           - Init/enable Options
209  *
210  * RETURN:      Status
211  *
212  * DESCRIPTION: Completes the subsystem initialization including hardware.
213  *              Puts system into ACPI mode if it isn't already.
214  *
215  ******************************************************************************/
216 
217 ACPI_STATUS
218 AcpiEnableSubsystem (
219     UINT32                  Flags)
220 {
221     ACPI_STATUS             Status = AE_OK;
222 
223 
224     ACPI_FUNCTION_TRACE (AcpiEnableSubsystem);
225 
226 
227     /* Enable ACPI mode */
228 
229     if (!(Flags & ACPI_NO_ACPI_ENABLE))
230     {
231         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n"));
232 
233         AcpiGbl_OriginalMode = AcpiHwGetMode();
234 
235         Status = AcpiEnable ();
236         if (ACPI_FAILURE (Status))
237         {
238             ACPI_WARNING ((AE_INFO, "AcpiEnable failed"));
239             return_ACPI_STATUS (Status);
240         }
241     }
242 
243     /*
244      * Install the default OpRegion handlers.  These are installed unless
245      * other handlers have already been installed via the
246      * InstallAddressSpaceHandler interface.
247      */
248     if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
249     {
250         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
251             "[Init] Installing default address space handlers\n"));
252 
253         Status = AcpiEvInstallRegionHandlers ();
254         if (ACPI_FAILURE (Status))
255         {
256             return_ACPI_STATUS (Status);
257         }
258     }
259 
260     /*
261      * Initialize ACPI Event handling (Fixed and General Purpose)
262      *
263      * Note1: We must have the hardware and events initialized before we can
264      * execute any control methods safely. Any control method can require
265      * ACPI hardware support, so the hardware must be fully initialized before
266      * any method execution!
267      *
268      * Note2: Fixed events are initialized and enabled here. GPEs are
269      * initialized, but cannot be enabled until after the hardware is
270      * completely initialized (SCI and GlobalLock activated) and the various
271      * initialization control methods are run (_REG, _STA, _INI) on the
272      * entire namespace.
273      */
274     if (!(Flags & ACPI_NO_EVENT_INIT))
275     {
276         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
277             "[Init] Initializing ACPI events\n"));
278 
279         Status = AcpiEvInitializeEvents ();
280         if (ACPI_FAILURE (Status))
281         {
282             return_ACPI_STATUS (Status);
283         }
284     }
285 
286     /*
287      * Install the SCI handler and Global Lock handler. This completes the
288      * hardware initialization.
289      */
290     if (!(Flags & ACPI_NO_HANDLER_INIT))
291     {
292         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
293             "[Init] Installing SCI/GL handlers\n"));
294 
295         Status = AcpiEvInstallXruptHandlers ();
296         if (ACPI_FAILURE (Status))
297         {
298             return_ACPI_STATUS (Status);
299         }
300     }
301 
302     return_ACPI_STATUS (Status);
303 }
304 
305 ACPI_EXPORT_SYMBOL (AcpiEnableSubsystem)
306 
307 
308 /*******************************************************************************
309  *
310  * FUNCTION:    AcpiInitializeObjects
311  *
312  * PARAMETERS:  Flags           - Init/enable Options
313  *
314  * RETURN:      Status
315  *
316  * DESCRIPTION: Completes namespace initialization by initializing device
317  *              objects and executing AML code for Regions, buffers, etc.
318  *
319  ******************************************************************************/
320 
321 ACPI_STATUS
322 AcpiInitializeObjects (
323     UINT32                  Flags)
324 {
325     ACPI_STATUS             Status = AE_OK;
326 
327 
328     ACPI_FUNCTION_TRACE (AcpiInitializeObjects);
329 
330 
331     /*
332      * Run all _REG methods
333      *
334      * Note: Any objects accessed by the _REG methods will be automatically
335      * initialized, even if they contain executable AML (see the call to
336      * AcpiNsInitializeObjects below).
337      */
338     if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
339     {
340         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
341             "[Init] Executing _REG OpRegion methods\n"));
342 
343         Status = AcpiEvInitializeOpRegions ();
344         if (ACPI_FAILURE (Status))
345         {
346             return_ACPI_STATUS (Status);
347         }
348     }
349 
350     /*
351      * Initialize the objects that remain uninitialized. This runs the
352      * executable AML that may be part of the declaration of these objects:
353      * OperationRegions, BufferFields, Buffers, and Packages.
354      */
355     if (!(Flags & ACPI_NO_OBJECT_INIT))
356     {
357         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
358             "[Init] Completing Initialization of ACPI Objects\n"));
359 
360         Status = AcpiNsInitializeObjects ();
361         if (ACPI_FAILURE (Status))
362         {
363             return_ACPI_STATUS (Status);
364         }
365     }
366 
367     /*
368      * Initialize all device objects in the namespace. This runs the device
369      * _STA and _INI methods.
370      */
371     if (!(Flags & ACPI_NO_DEVICE_INIT))
372     {
373         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
374             "[Init] Initializing ACPI Devices\n"));
375 
376         Status = AcpiNsInitializeDevices ();
377         if (ACPI_FAILURE (Status))
378         {
379             return_ACPI_STATUS (Status);
380         }
381     }
382 
383     /*
384      * Initialize the GPE blocks defined in the FADT (GPE block 0 and 1).
385      * The runtime GPEs are enabled here.
386      *
387      * This is where the _PRW methods are executed for the GPEs. These
388      * methods can only be executed after the SCI and Global Lock handlers are
389      * installed and initialized.
390      *
391      * GPEs can only be enabled after the _REG, _STA, and _INI methods have
392      * been run. This ensures that all Operation Regions and all Devices have
393      * been initialized and are ready.
394      */
395     if (!(Flags & ACPI_NO_EVENT_INIT))
396     {
397         Status = AcpiEvInstallFadtGpes ();
398         if (ACPI_FAILURE (Status))
399         {
400             return (Status);
401         }
402     }
403 
404     /*
405      * Empty the caches (delete the cached objects) on the assumption that
406      * the table load filled them up more than they will be at runtime --
407      * thus wasting non-paged memory.
408      */
409     Status = AcpiPurgeCachedObjects ();
410 
411     AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
412     return_ACPI_STATUS (Status);
413 }
414 
415 ACPI_EXPORT_SYMBOL (AcpiInitializeObjects)
416 
417 
418 #endif
419 
420 /*******************************************************************************
421  *
422  * FUNCTION:    AcpiTerminate
423  *
424  * PARAMETERS:  None
425  *
426  * RETURN:      Status
427  *
428  * DESCRIPTION: Shutdown the ACPI subsystem.  Release all resources.
429  *
430  ******************************************************************************/
431 
432 ACPI_STATUS
433 AcpiTerminate (
434     void)
435 {
436     ACPI_STATUS         Status;
437 
438 
439     ACPI_FUNCTION_TRACE (AcpiTerminate);
440 
441 
442     /* Terminate the AML Debugger if present */
443 
444     ACPI_DEBUGGER_EXEC(AcpiGbl_DbTerminateThreads = TRUE);
445 
446     /* Shutdown and free all resources */
447 
448     AcpiUtSubsystemShutdown ();
449 
450 
451     /* Free the mutex objects */
452 
453     AcpiUtMutexTerminate ();
454 
455 
456 #ifdef ACPI_DEBUGGER
457 
458     /* Shut down the debugger */
459 
460     AcpiDbTerminate ();
461 #endif
462 
463     /* Now we can shutdown the OS-dependent layer */
464 
465     Status = AcpiOsTerminate ();
466     return_ACPI_STATUS (Status);
467 }
468 
469 ACPI_EXPORT_SYMBOL (AcpiTerminate)
470 
471 #ifndef ACPI_ASL_COMPILER
472 
473 /*******************************************************************************
474  *
475  * FUNCTION:    AcpiSubsystemStatus
476  *
477  * PARAMETERS:  None
478  *
479  * RETURN:      Status of the ACPI subsystem
480  *
481  * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
482  *              before making any other calls, to ensure the subsystem
483  *              initialized successfully.
484  *
485  ******************************************************************************/
486 
487 ACPI_STATUS
488 AcpiSubsystemStatus (
489     void)
490 {
491 
492     if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
493     {
494         return (AE_OK);
495     }
496     else
497     {
498         return (AE_ERROR);
499     }
500 }
501 
502 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
503 
504 
505 /*******************************************************************************
506  *
507  * FUNCTION:    AcpiGetSystemInfo
508  *
509  * PARAMETERS:  OutBuffer       - A buffer to receive the resources for the
510  *                                device
511  *
512  * RETURN:      Status          - the status of the call
513  *
514  * DESCRIPTION: This function is called to get information about the current
515  *              state of the ACPI subsystem.  It will return system information
516  *              in the OutBuffer.
517  *
518  *              If the function fails an appropriate status will be returned
519  *              and the value of OutBuffer is undefined.
520  *
521  ******************************************************************************/
522 
523 ACPI_STATUS
524 AcpiGetSystemInfo (
525     ACPI_BUFFER             *OutBuffer)
526 {
527     ACPI_SYSTEM_INFO        *InfoPtr;
528     ACPI_STATUS             Status;
529 
530 
531     ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
532 
533 
534     /* Parameter validation */
535 
536     Status = AcpiUtValidateBuffer (OutBuffer);
537     if (ACPI_FAILURE (Status))
538     {
539         return_ACPI_STATUS (Status);
540     }
541 
542     /* Validate/Allocate/Clear caller buffer */
543 
544     Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
545     if (ACPI_FAILURE (Status))
546     {
547         return_ACPI_STATUS (Status);
548     }
549 
550     /*
551      * Populate the return buffer
552      */
553     InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
554 
555     InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
556 
557     /* System flags (ACPI capabilities) */
558 
559     InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
560 
561     /* Timer resolution - 24 or 32 bits  */
562 
563     if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
564     {
565         InfoPtr->TimerResolution = 24;
566     }
567     else
568     {
569         InfoPtr->TimerResolution = 32;
570     }
571 
572     /* Clear the reserved fields */
573 
574     InfoPtr->Reserved1 = 0;
575     InfoPtr->Reserved2 = 0;
576 
577     /* Current debug levels */
578 
579     InfoPtr->DebugLayer = AcpiDbgLayer;
580     InfoPtr->DebugLevel = AcpiDbgLevel;
581 
582     return_ACPI_STATUS (AE_OK);
583 }
584 
585 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
586 
587 
588 /*******************************************************************************
589  *
590  * FUNCTION:    AcpiGetStatistics
591  *
592  * PARAMETERS:  Stats           - Where the statistics are returned
593  *
594  * RETURN:      Status          - the status of the call
595  *
596  * DESCRIPTION: Get the contents of the various system counters
597  *
598  ******************************************************************************/
599 
600 ACPI_STATUS
601 AcpiGetStatistics (
602     ACPI_STATISTICS         *Stats)
603 {
604     ACPI_FUNCTION_TRACE (AcpiGetStatistics);
605 
606 
607     /* Parameter validation */
608 
609     if (!Stats)
610     {
611         return_ACPI_STATUS (AE_BAD_PARAMETER);
612     }
613 
614     /* Various interrupt-based event counters */
615 
616     Stats->SciCount = AcpiSciCount;
617     Stats->GpeCount = AcpiGpeCount;
618 
619     ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount,
620         sizeof (AcpiFixedEventCount));
621 
622 
623     /* Other counters */
624 
625     Stats->MethodCount = AcpiMethodCount;
626 
627     return_ACPI_STATUS (AE_OK);
628 }
629 
630 ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
631 
632 
633 /*****************************************************************************
634  *
635  * FUNCTION:    AcpiInstallInitializationHandler
636  *
637  * PARAMETERS:  Handler             - Callback procedure
638  *              Function            - Not (currently) used, see below
639  *
640  * RETURN:      Status
641  *
642  * DESCRIPTION: Install an initialization handler
643  *
644  * TBD: When a second function is added, must save the Function also.
645  *
646  ****************************************************************************/
647 
648 ACPI_STATUS
649 AcpiInstallInitializationHandler (
650     ACPI_INIT_HANDLER       Handler,
651     UINT32                  Function)
652 {
653 
654     if (!Handler)
655     {
656         return (AE_BAD_PARAMETER);
657     }
658 
659     if (AcpiGbl_InitHandler)
660     {
661         return (AE_ALREADY_EXISTS);
662     }
663 
664     AcpiGbl_InitHandler = Handler;
665     return AE_OK;
666 }
667 
668 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
669 
670 
671 /*****************************************************************************
672  *
673  * FUNCTION:    AcpiPurgeCachedObjects
674  *
675  * PARAMETERS:  None
676  *
677  * RETURN:      Status
678  *
679  * DESCRIPTION: Empty all caches (delete the cached objects)
680  *
681  ****************************************************************************/
682 
683 ACPI_STATUS
684 AcpiPurgeCachedObjects (
685     void)
686 {
687     ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
688 
689     (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
690     (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
691     (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
692     (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
693     return_ACPI_STATUS (AE_OK);
694 }
695 
696 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
697 
698 #endif
699