utxface.c revision 80062
1285431Szbb/******************************************************************************
2285431Szbb *
3285431Szbb * Module Name: utxface - External interfaces for "global" ACPI functions
4285431Szbb *              $Revision: 76 $
5285431Szbb *
6285431Szbb *****************************************************************************/
7285431Szbb
8285431Szbb/******************************************************************************
9285431Szbb *
10285431Szbb * 1. Copyright Notice
11285431Szbb *
12285431Szbb * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13285431Szbb * All rights reserved.
14285431Szbb *
15285431Szbb * 2. License
16285431Szbb *
17285431Szbb * 2.1. This is your license from Intel Corp. under its intellectual property
18285431Szbb * rights.  You may have additional license terms from the party that provided
19285431Szbb * you this software, covering your right to use that party's intellectual
20285431Szbb * property rights.
21285431Szbb *
22285431Szbb * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23285431Szbb * copy of the source code appearing in this file ("Covered Code") an
24285431Szbb * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25285431Szbb * base code distributed originally by Intel ("Original Intel Code") to copy,
26285431Szbb * make derivatives, distribute, use and display any portion of the Covered
27285431Szbb * Code in any form, with the right to sublicense such rights; and
28285431Szbb *
29285431Szbb * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30285431Szbb * license (with the right to sublicense), under only those claims of Intel
31285431Szbb * patents that are infringed by the Original Intel Code, to make, use, sell,
32285431Szbb * offer to sell, and import the Covered Code and derivative works thereof
33285431Szbb * solely to the minimum extent necessary to exercise the above copyright
34285431Szbb * license, and in no event shall the patent license extend to any additions
35285431Szbb * to or modifications of the Original Intel Code.  No other license or right
36285431Szbb * is granted directly or by implication, estoppel or otherwise;
37285431Szbb *
38285431Szbb * The above copyright and patent license is granted only if the following
39285431Szbb * conditions are met:
40285431Szbb *
41285431Szbb * 3. Conditions
42285431Szbb *
43285431Szbb * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44285431Szbb * Redistribution of source code of any substantial portion of the Covered
45285431Szbb * Code or modification with rights to further distribute source must include
46285431Szbb * the above Copyright Notice, the above License, this list of Conditions,
47285431Szbb * and the following Disclaimer and Export Compliance provision.  In addition,
48285431Szbb * Licensee must cause all Covered Code to which Licensee contributes to
49285431Szbb * contain a file documenting the changes Licensee made to create that Covered
50285431Szbb * Code and the date of any change.  Licensee must include in that file the
51285431Szbb * documentation of any changes made by any predecessor Licensee.  Licensee
52285431Szbb * must include a prominent statement that the modification is derived,
53285431Szbb * directly or indirectly, from Original Intel Code.
54285431Szbb *
55285431Szbb * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56285431Szbb * Redistribution of source code of any substantial portion of the Covered
57285431Szbb * Code or modification without rights to further distribute source must
58285431Szbb * include the following Disclaimer and Export Compliance provision in the
59285431Szbb * documentation and/or other materials provided with distribution.  In
60285431Szbb * addition, Licensee may not authorize further sublicense of source of any
61285431Szbb * portion of the Covered Code, and must include terms to the effect that the
62285431Szbb * license from Licensee to its licensee is limited to the intellectual
63285431Szbb * property embodied in the software Licensee provides to its licensee, and
64285431Szbb * not to intellectual property embodied in modifications its licensee may
65285431Szbb * make.
66285431Szbb *
67285431Szbb * 3.3. Redistribution of Executable. Redistribution in executable form of any
68285431Szbb * substantial portion of the Covered Code or modification must reproduce the
69285431Szbb * above Copyright Notice, and the following Disclaimer and Export Compliance
70285431Szbb * provision in the documentation and/or other materials provided with the
71285431Szbb * distribution.
72285431Szbb *
73285431Szbb * 3.4. Intel retains all right, title, and interest in and to the Original
74285431Szbb * Intel Code.
75285431Szbb *
76285431Szbb * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77285431Szbb * Intel shall be used in advertising or otherwise to promote the sale, use or
78285431Szbb * other dealings in products derived from or relating to the Covered Code
79285431Szbb * without prior written authorization from Intel.
80285431Szbb *
81285431Szbb * 4. Disclaimer and Export Compliance
82285431Szbb *
83285431Szbb * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84285431Szbb * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85285431Szbb * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86285431Szbb * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87285431Szbb * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88285431Szbb * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89285431Szbb * PARTICULAR PURPOSE.
90285431Szbb *
91285431Szbb * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92285431Szbb * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93285431Szbb * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94285431Szbb * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95285431Szbb * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96285431Szbb * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97285431Szbb * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98285431Szbb * LIMITED REMEDY.
99285431Szbb *
100285431Szbb * 4.3. Licensee shall not export, either directly or indirectly, any of this
101285431Szbb * software or system incorporating such software without first obtaining any
102285431Szbb * required license or other approval from the U. S. Department of Commerce or
103285431Szbb * any other agency or department of the United States Government.  In the
104285431Szbb * event Licensee exports any such software from the United States or
105285431Szbb * re-exports any such software from a foreign destination, Licensee shall
106285431Szbb * ensure that the distribution and export/re-export of the software is in
107285431Szbb * compliance with all laws, regulations, orders, or other restrictions of the
108285431Szbb * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109285431Szbb * any of its subsidiaries will export/re-export any technical data, process,
110285431Szbb * software, or service, directly or indirectly, to any country for which the
111285431Szbb * United States government or any agency thereof requires an export license,
112285431Szbb * other governmental approval, or letter of assurance, without first obtaining
113285431Szbb * such license, approval or letter.
114285431Szbb *
115285431Szbb *****************************************************************************/
116285431Szbb
117285431Szbb
118285431Szbb#define __UTXFACE_C__
119285431Szbb
120285431Szbb#include "acpi.h"
121285431Szbb#include "acevents.h"
122285431Szbb#include "achware.h"
123285431Szbb#include "acnamesp.h"
124285431Szbb#include "acinterp.h"
125285431Szbb#include "amlcode.h"
126285431Szbb#include "acdebug.h"
127285431Szbb#include "acexcep.h"
128285431Szbb
129285431Szbb
130285431Szbb#define _COMPONENT          ACPI_UTILITIES
131285431Szbb        MODULE_NAME         ("utxface")
132285431Szbb
133285431Szbb
134285431Szbb/*******************************************************************************
135285431Szbb *
136285431Szbb * FUNCTION:    AcpiInitializeSubsystem
137285431Szbb *
138285431Szbb * PARAMETERS:  None
139285431Szbb *
140285431Szbb * RETURN:      Status
141285431Szbb *
142285431Szbb * DESCRIPTION: Initializes all global variables.  This is the first function
143285431Szbb *              called, so any early initialization belongs here.
144285431Szbb *
145285431Szbb ******************************************************************************/
146285431Szbb
147285431SzbbACPI_STATUS
148285431SzbbAcpiInitializeSubsystem (
149285431Szbb    void)
150285431Szbb{
151285431Szbb    ACPI_STATUS             Status;
152285431Szbb
153285431Szbb    FUNCTION_TRACE ("AcpiInitializeSubsystem");
154285431Szbb
155285431Szbb
156285431Szbb    /* Initialize all globals used by the subsystem */
157285431Szbb
158285431Szbb    AcpiUtInitGlobals ();
159285431Szbb
160285431Szbb    /* Initialize the OS-Dependent layer */
161285431Szbb
162285431Szbb    Status = AcpiOsInitialize ();
163285431Szbb    if (ACPI_FAILURE (Status))
164285431Szbb    {
165285431Szbb        REPORT_ERROR (("OSD failed to initialize, %s\n",
166285431Szbb            AcpiFormatException (Status)));
167285431Szbb        return_ACPI_STATUS (Status);
168285431Szbb    }
169285431Szbb
170285431Szbb    /* Create the default mutex objects */
171285431Szbb
172285431Szbb    Status = AcpiUtMutexInitialize ();
173285431Szbb    if (ACPI_FAILURE (Status))
174285431Szbb    {
175285431Szbb        REPORT_ERROR (("Global mutex creation failure, %s\n",
176285431Szbb            AcpiFormatException (Status)));
177285431Szbb        return_ACPI_STATUS (Status);
178285431Szbb    }
179285431Szbb
180285431Szbb    /*
181285431Szbb     * Initialize the namespace manager and
182285431Szbb     * the root of the namespace tree
183285431Szbb     */
184285431Szbb
185285431Szbb    Status = AcpiNsRootInitialize ();
186285431Szbb    if (ACPI_FAILURE (Status))
187285431Szbb    {
188285431Szbb        REPORT_ERROR (("Namespace initialization failure, %s\n",
189285431Szbb            AcpiFormatException (Status)));
190285431Szbb        return_ACPI_STATUS (Status);
191285431Szbb    }
192285431Szbb
193285431Szbb
194285431Szbb    /* If configured, initialize the AML debugger */
195285431Szbb
196285431Szbb    DEBUGGER_EXEC (AcpiDbInitialize ());
197285431Szbb
198285431Szbb    return_ACPI_STATUS (Status);
199285431Szbb}
200285431Szbb
201285431Szbb
202285431Szbb/*******************************************************************************
203285431Szbb *
204285431Szbb * FUNCTION:    AcpiEnableSubsystem
205285431Szbb *
206285431Szbb * PARAMETERS:  Flags           - Init/enable Options
207285431Szbb *
208285431Szbb * RETURN:      Status
209285431Szbb *
210285431Szbb * DESCRIPTION: Completes the subsystem initialization including hardware.
211285431Szbb *              Puts system into ACPI mode if it isn't already.
212285431Szbb *
213285431Szbb ******************************************************************************/
214285431Szbb
215285431SzbbACPI_STATUS
216285431SzbbAcpiEnableSubsystem (
217285431Szbb    UINT32                  Flags)
218285431Szbb{
219285431Szbb    ACPI_STATUS             Status = AE_OK;
220285431Szbb
221285431Szbb
222285431Szbb    FUNCTION_TRACE ("AcpiEnableSubsystem");
223285431Szbb
224285431Szbb
225285431Szbb    /* Sanity check the FADT for valid values */
226285431Szbb
227285431Szbb    Status = AcpiUtValidateFadt ();
228285431Szbb    if (ACPI_FAILURE (Status))
229285431Szbb    {
230285431Szbb        return_ACPI_STATUS (Status);
231285431Szbb    }
232285431Szbb
233285431Szbb    /*
234285431Szbb     * Install the default OpRegion handlers.  These are
235285431Szbb     * installed unless other handlers have already been
236285431Szbb     * installed via the InstallAddressSpaceHandler interface
237285431Szbb     */
238285431Szbb
239285431Szbb    if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
240285431Szbb    {
241285431Szbb        DEBUG_PRINT (TRACE_EXEC, ("[Init] Installing default address space handlers\n"));
242285431Szbb
243285431Szbb        Status = AcpiEvInstallDefaultAddressSpaceHandlers ();
244285431Szbb        if (ACPI_FAILURE (Status))
245285431Szbb        {
246285431Szbb            return_ACPI_STATUS (Status);
247285431Szbb        }
248285431Szbb    }
249285431Szbb
250285431Szbb    /*
251285431Szbb     * We must initialize the hardware before we can enable ACPI.
252285431Szbb     */
253285431Szbb
254285431Szbb    if (!(Flags & ACPI_NO_HARDWARE_INIT))
255285431Szbb    {
256285431Szbb        DEBUG_PRINT (TRACE_EXEC, ("[Init] Initializing ACPI hardware\n"));
257285431Szbb
258285431Szbb        Status = AcpiHwInitialize ();
259285431Szbb        if (ACPI_FAILURE (Status))
260285431Szbb        {
261285431Szbb            return_ACPI_STATUS (Status);
262285431Szbb        }
263285431Szbb    }
264285431Szbb
265285431Szbb    /*
266285431Szbb     * Enable ACPI on this platform
267285431Szbb     */
268285431Szbb
269285431Szbb    if (!(Flags & ACPI_NO_ACPI_ENABLE))
270285431Szbb    {
271285431Szbb        DEBUG_PRINT (TRACE_EXEC, ("[Init] Going into ACPI mode\n"));
272285431Szbb
273285431Szbb        Status = AcpiEnable ();
274285431Szbb        if (ACPI_FAILURE (Status))
275285431Szbb        {
276285431Szbb            DEBUG_PRINT(ACPI_WARN, ("AcpiEnable failed.\n"));
277285431Szbb            return_ACPI_STATUS (Status);
278285431Szbb        }
279285431Szbb    }
280285431Szbb
281285431Szbb    /*
282285431Szbb     * Note:
283285431Szbb     * We must have the hardware AND events initialized before we can execute
284285431Szbb     * ANY control methods SAFELY.  Any control method can require ACPI hardware
285285431Szbb     * support, so the hardware MUST be initialized before execution!
286285431Szbb     */
287285431Szbb
288285431Szbb    if (!(Flags & ACPI_NO_EVENT_INIT))
289285431Szbb    {
290285431Szbb        DEBUG_PRINT (TRACE_EXEC, ("[Init] Initializing ACPI events\n"));
291285431Szbb
292285431Szbb        Status = AcpiEvInitialize ();
293285431Szbb        if (ACPI_FAILURE (Status))
294285431Szbb        {
295285431Szbb            return_ACPI_STATUS (Status);
296285431Szbb        }
297285431Szbb    }
298285431Szbb
299285431Szbb
300285431Szbb    /*
301285431Szbb     * Initialize all device objects in the namespace
302285431Szbb     * This runs the _STA and _INI methods.
303285431Szbb     */
304285431Szbb
305285431Szbb    if (!(Flags & ACPI_NO_DEVICE_INIT))
306285431Szbb    {
307285431Szbb        DEBUG_PRINT (TRACE_EXEC, ("[Init] Initializing ACPI Devices\n"));
308285431Szbb
309285431Szbb        Status = AcpiNsInitializeDevices ();
310285431Szbb        if (ACPI_FAILURE (Status))
311285431Szbb        {
312285431Szbb            return_ACPI_STATUS (Status);
313285431Szbb        }
314285431Szbb    }
315
316
317    /*
318     * Initialize the objects that remain uninitialized.  This
319     * runs the executable AML that is part of the declaration of OpRegions
320     * and Fields.
321     */
322
323    if (!(Flags & ACPI_NO_OBJECT_INIT))
324    {
325        DEBUG_PRINT (TRACE_EXEC, ("[Init] Initializing ACPI Objects\n"));
326
327        Status = AcpiNsInitializeObjects ();
328        if (ACPI_FAILURE (Status))
329        {
330            return_ACPI_STATUS (Status);
331        }
332    }
333
334    AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
335
336    return_ACPI_STATUS (Status);
337}
338
339
340/*******************************************************************************
341 *
342 * FUNCTION:    AcpiTerminate
343 *
344 * PARAMETERS:  None
345 *
346 * RETURN:      Status
347 *
348 * DESCRIPTION: Shutdown the ACPI subsystem.  Release all resources.
349 *
350 ******************************************************************************/
351
352ACPI_STATUS
353AcpiTerminate (void)
354{
355    ACPI_STATUS             Status;
356
357
358    FUNCTION_TRACE ("AcpiTerminate");
359
360
361    /* Ensure that ACPI has been initialized */
362
363    ACPI_IS_INITIALIZATION_COMPLETE (Status);
364    if (ACPI_FAILURE (Status))
365    {
366        return_ACPI_STATUS (Status);
367    }
368
369    /* Terminate the AML Debugger if present */
370
371    DEBUGGER_EXEC(AcpiGbl_DbTerminateThreads = TRUE);
372
373    /* TBD: [Investigate] This is no longer needed?*/
374/*    AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY); */
375
376
377    /* Shutdown and free all resources */
378
379    AcpiUtSubsystemShutdown ();
380
381
382    /* Free the mutex objects */
383
384    AcpiUtMutexTerminate ();
385
386
387    /* Now we can shutdown the OS-dependent layer */
388
389    AcpiOsTerminate ();
390
391    return_ACPI_STATUS (AE_OK);
392}
393
394
395/*****************************************************************************
396 *
397 * FUNCTION:    AcpiSubsystemStatus
398 *
399 * PARAMETERS:  None
400 *
401 * RETURN:      Status of the ACPI subsystem
402 *
403 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
404 *              before making any other calls, to ensure the subsystem initial-
405 *              ized successfully.
406 *
407 ****************************************************************************/
408
409ACPI_STATUS
410AcpiSubsystemStatus (void)
411{
412    if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
413    {
414        return (AE_OK);
415    }
416    else
417    {
418        return (AE_ERROR);
419    }
420}
421
422
423/******************************************************************************
424 *
425 * FUNCTION:    AcpiGetSystemInfo
426 *
427 * PARAMETERS:  OutBuffer       - a pointer to a buffer to receive the
428 *                                resources for the device
429 *              BufferLength    - the number of bytes available in the buffer
430 *
431 * RETURN:      Status          - the status of the call
432 *
433 * DESCRIPTION: This function is called to get information about the current
434 *              state of the ACPI subsystem.  It will return system information
435 *              in the OutBuffer.
436 *
437 *              If the function fails an appropriate status will be returned
438 *              and the value of OutBuffer is undefined.
439 *
440 ******************************************************************************/
441
442ACPI_STATUS
443AcpiGetSystemInfo (
444    ACPI_BUFFER             *OutBuffer)
445{
446    ACPI_SYSTEM_INFO        *InfoPtr;
447    UINT32                  i;
448    ACPI_STATUS             Status;
449
450
451    FUNCTION_TRACE ("AcpiGetSystemInfo");
452
453
454    /* Ensure that ACPI has been initialized */
455
456    ACPI_IS_INITIALIZATION_COMPLETE (Status);
457    if (ACPI_FAILURE (Status))
458    {
459        return_ACPI_STATUS (Status);
460    }
461
462    /*
463     *  Must have a valid buffer
464     */
465    if ((!OutBuffer)          ||
466        (!OutBuffer->Pointer))
467    {
468        return_ACPI_STATUS (AE_BAD_PARAMETER);
469    }
470
471    if (OutBuffer->Length < sizeof (ACPI_SYSTEM_INFO))
472    {
473        /*
474         *  Caller's buffer is too small
475         */
476        OutBuffer->Length = sizeof (ACPI_SYSTEM_INFO);
477
478        return_ACPI_STATUS (AE_BUFFER_OVERFLOW);
479    }
480
481
482    /*
483     *  Set return length and get data
484     */
485    OutBuffer->Length = sizeof (ACPI_SYSTEM_INFO);
486    InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
487
488    InfoPtr->AcpiCaVersion      = ACPI_CA_VERSION;
489
490    /* System flags (ACPI capabilities) */
491
492    InfoPtr->Flags              = AcpiGbl_SystemFlags;
493
494    /* Timer resolution - 24 or 32 bits  */
495    if (!AcpiGbl_FADT)
496    {
497        InfoPtr->TimerResolution = 0;
498    }
499    else if (AcpiGbl_FADT->TmrValExt == 0)
500    {
501        InfoPtr->TimerResolution = 24;
502    }
503    else
504    {
505        InfoPtr->TimerResolution = 32;
506    }
507
508    /* Clear the reserved fields */
509
510    InfoPtr->Reserved1          = 0;
511    InfoPtr->Reserved2          = 0;
512
513    /* Current debug levels */
514
515    InfoPtr->DebugLayer         = AcpiDbgLayer;
516    InfoPtr->DebugLevel         = AcpiDbgLevel;
517
518    /* Current status of the ACPI tables, per table type */
519
520    InfoPtr->NumTableTypes = NUM_ACPI_TABLES;
521    for (i = 0; i < NUM_ACPI_TABLES; i++)
522    {
523        InfoPtr->TableInfo[i].Count = AcpiGbl_AcpiTables[i].Count;
524    }
525
526    return_ACPI_STATUS (AE_OK);
527}
528
529
530