Home | History | Annotate | Line # | Download | only in examples
examples.c revision 1.1.1.8
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3  1.1.1.4  christos  * Module Name: examples - Example ACPICA initialization and execution code
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.7  christos  * Copyright (C) 2000 - 2016, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11  1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13  1.1.1.2    jruoho  * are met:
     14  1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2    jruoho  *    without modification.
     17  1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2    jruoho  *    binary redistribution.
     22  1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25  1.1.1.2    jruoho  *
     26  1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2    jruoho  * Software Foundation.
     29  1.1.1.2    jruoho  *
     30  1.1.1.2    jruoho  * NO WARRANTY
     31  1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2    jruoho  */
     43      1.1    jruoho 
     44  1.1.1.4  christos #include "examples.h"
     45      1.1    jruoho 
     46      1.1    jruoho #define _COMPONENT          ACPI_EXAMPLE
     47      1.1    jruoho         ACPI_MODULE_NAME    ("examples")
     48      1.1    jruoho 
     49      1.1    jruoho 
     50      1.1    jruoho /******************************************************************************
     51      1.1    jruoho  *
     52      1.1    jruoho  * ACPICA Example Code
     53      1.1    jruoho  *
     54      1.1    jruoho  * This module contains examples of how the host OS should interface to the
     55      1.1    jruoho  * ACPICA subsystem.
     56      1.1    jruoho  *
     57      1.1    jruoho  * 1) How to use the platform/acenv.h file and how to set configuration
     58      1.1    jruoho  *      options.
     59      1.1    jruoho  *
     60      1.1    jruoho  * 2) main - using the debug output mechanism and the error/warning output
     61      1.1    jruoho  *      macros.
     62      1.1    jruoho  *
     63      1.1    jruoho  * 3) Two examples of the ACPICA initialization sequence. The first is a
     64      1.1    jruoho  *      initialization with no "early" ACPI table access. The second shows
     65      1.1    jruoho  *      how to use ACPICA to obtain the tables very early during kernel
     66      1.1    jruoho  *      initialization, even before dynamic memory is available.
     67      1.1    jruoho  *
     68      1.1    jruoho  * 4) How to invoke a control method, including argument setup and how to
     69      1.1    jruoho  *      access the return value.
     70      1.1    jruoho  *
     71      1.1    jruoho  *****************************************************************************/
     72      1.1    jruoho 
     73      1.1    jruoho 
     74      1.1    jruoho /* Local Prototypes */
     75      1.1    jruoho 
     76  1.1.1.4  christos static ACPI_STATUS
     77  1.1.1.4  christos InitializeFullAcpica (void);
     78      1.1    jruoho 
     79  1.1.1.4  christos static ACPI_STATUS
     80      1.1    jruoho InstallHandlers (void);
     81      1.1    jruoho 
     82  1.1.1.4  christos static void
     83  1.1.1.4  christos NotifyHandler (
     84  1.1.1.4  christos     ACPI_HANDLE             Device,
     85  1.1.1.4  christos     UINT32                  Value,
     86  1.1.1.4  christos     void                    *Context);
     87  1.1.1.4  christos 
     88  1.1.1.5  christos static ACPI_STATUS
     89  1.1.1.5  christos RegionHandler (
     90  1.1.1.5  christos     UINT32                  Function,
     91  1.1.1.5  christos     ACPI_PHYSICAL_ADDRESS   Address,
     92  1.1.1.5  christos     UINT32                  BitWidth,
     93  1.1.1.5  christos     UINT64                  *Value,
     94  1.1.1.5  christos     void                    *HandlerContext,
     95  1.1.1.5  christos     void                    *RegionContext);
     96  1.1.1.5  christos 
     97  1.1.1.5  christos static ACPI_STATUS
     98  1.1.1.5  christos RegionInit (
     99  1.1.1.5  christos     ACPI_HANDLE             RegionHandle,
    100  1.1.1.5  christos     UINT32                  Function,
    101  1.1.1.5  christos     void                    *HandlerContext,
    102  1.1.1.5  christos     void                    **RegionContext);
    103  1.1.1.5  christos 
    104  1.1.1.4  christos static void
    105  1.1.1.4  christos ExecuteMAIN (void);
    106  1.1.1.4  christos 
    107  1.1.1.4  christos static void
    108      1.1    jruoho ExecuteOSI (void);
    109      1.1    jruoho 
    110  1.1.1.4  christos ACPI_STATUS
    111  1.1.1.4  christos InitializeAcpiTables (
    112  1.1.1.4  christos     void);
    113  1.1.1.4  christos 
    114  1.1.1.4  christos ACPI_STATUS
    115  1.1.1.4  christos InitializeAcpi (
    116  1.1.1.4  christos     void);
    117  1.1.1.4  christos 
    118      1.1    jruoho 
    119      1.1    jruoho /******************************************************************************
    120      1.1    jruoho  *
    121      1.1    jruoho  * FUNCTION:    main
    122      1.1    jruoho  *
    123      1.1    jruoho  * PARAMETERS:  argc, argv
    124      1.1    jruoho  *
    125      1.1    jruoho  * RETURN:      Status
    126      1.1    jruoho  *
    127      1.1    jruoho  * DESCRIPTION: Main routine. Shows the use of the various output macros, as
    128      1.1    jruoho  *              well as the use of the debug layer/level globals.
    129      1.1    jruoho  *
    130      1.1    jruoho  *****************************************************************************/
    131      1.1    jruoho 
    132      1.1    jruoho int ACPI_SYSTEM_XFACE
    133      1.1    jruoho main (
    134      1.1    jruoho     int                     argc,
    135      1.1    jruoho     char                    **argv)
    136      1.1    jruoho {
    137      1.1    jruoho 
    138  1.1.1.4  christos     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
    139  1.1.1.4  christos 
    140  1.1.1.4  christos     printf (ACPI_COMMON_SIGNON ("ACPI Example Code"));
    141      1.1    jruoho 
    142  1.1.1.4  christos     /* Initialize the local ACPI tables (RSDP/RSDT/XSDT/FADT/DSDT/FACS) */
    143      1.1    jruoho 
    144  1.1.1.4  christos     ExInitializeAcpiTables ();
    145      1.1    jruoho 
    146  1.1.1.4  christos     /* Initialize the ACPICA subsystem */
    147  1.1.1.4  christos 
    148  1.1.1.4  christos     InitializeFullAcpica ();
    149      1.1    jruoho 
    150      1.1    jruoho     /* Example warning and error output */
    151      1.1    jruoho 
    152  1.1.1.8  christos     ACPI_INFO        (("Example ACPICA info message"));
    153  1.1.1.4  christos     ACPI_WARNING     ((AE_INFO, "Example ACPICA warning message"));
    154  1.1.1.4  christos     ACPI_ERROR       ((AE_INFO, "Example ACPICA error message"));
    155  1.1.1.7  christos     ACPI_EXCEPTION   ((AE_INFO, AE_AML_OPERAND_TYPE,
    156  1.1.1.7  christos         "Example ACPICA exception message"));
    157      1.1    jruoho 
    158      1.1    jruoho     ExecuteOSI ();
    159  1.1.1.4  christos     ExecuteMAIN ();
    160      1.1    jruoho     return (0);
    161      1.1    jruoho }
    162      1.1    jruoho 
    163      1.1    jruoho 
    164      1.1    jruoho /******************************************************************************
    165      1.1    jruoho  *
    166      1.1    jruoho  * Example ACPICA initialization code. This shows a full initialization with
    167      1.1    jruoho  * no early ACPI table access.
    168      1.1    jruoho  *
    169      1.1    jruoho  *****************************************************************************/
    170      1.1    jruoho 
    171  1.1.1.4  christos static ACPI_STATUS
    172  1.1.1.4  christos InitializeFullAcpica (void)
    173      1.1    jruoho {
    174      1.1    jruoho     ACPI_STATUS             Status;
    175      1.1    jruoho 
    176      1.1    jruoho 
    177      1.1    jruoho     /* Initialize the ACPICA subsystem */
    178      1.1    jruoho 
    179      1.1    jruoho     Status = AcpiInitializeSubsystem ();
    180      1.1    jruoho     if (ACPI_FAILURE (Status))
    181      1.1    jruoho     {
    182      1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "While initializing ACPICA"));
    183      1.1    jruoho         return (Status);
    184      1.1    jruoho     }
    185      1.1    jruoho 
    186      1.1    jruoho     /* Initialize the ACPICA Table Manager and get all ACPI tables */
    187      1.1    jruoho 
    188  1.1.1.8  christos     ACPI_INFO (("Loading ACPI tables"));
    189  1.1.1.4  christos 
    190      1.1    jruoho     Status = AcpiInitializeTables (NULL, 16, FALSE);
    191      1.1    jruoho     if (ACPI_FAILURE (Status))
    192      1.1    jruoho     {
    193      1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "While initializing Table Manager"));
    194      1.1    jruoho         return (Status);
    195      1.1    jruoho     }
    196      1.1    jruoho 
    197      1.1    jruoho     /* Install local handlers */
    198      1.1    jruoho 
    199      1.1    jruoho     Status = InstallHandlers ();
    200      1.1    jruoho     if (ACPI_FAILURE (Status))
    201      1.1    jruoho     {
    202      1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "While installing handlers"));
    203      1.1    jruoho         return (Status);
    204      1.1    jruoho     }
    205      1.1    jruoho 
    206      1.1    jruoho     /* Initialize the ACPI hardware */
    207      1.1    jruoho 
    208      1.1    jruoho     Status = AcpiEnableSubsystem (ACPI_FULL_INITIALIZATION);
    209      1.1    jruoho     if (ACPI_FAILURE (Status))
    210      1.1    jruoho     {
    211      1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "While enabling ACPICA"));
    212      1.1    jruoho         return (Status);
    213      1.1    jruoho     }
    214      1.1    jruoho 
    215  1.1.1.7  christos     /* Create the ACPI namespace from ACPI tables */
    216  1.1.1.7  christos 
    217  1.1.1.7  christos     Status = AcpiLoadTables ();
    218  1.1.1.7  christos     if (ACPI_FAILURE (Status))
    219  1.1.1.7  christos     {
    220  1.1.1.7  christos         ACPI_EXCEPTION ((AE_INFO, Status, "While loading ACPI tables"));
    221  1.1.1.7  christos         return (Status);
    222  1.1.1.7  christos     }
    223  1.1.1.7  christos 
    224      1.1    jruoho     /* Complete the ACPI namespace object initialization */
    225      1.1    jruoho 
    226      1.1    jruoho     Status = AcpiInitializeObjects (ACPI_FULL_INITIALIZATION);
    227      1.1    jruoho     if (ACPI_FAILURE (Status))
    228      1.1    jruoho     {
    229      1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "While initializing ACPICA objects"));
    230      1.1    jruoho         return (Status);
    231      1.1    jruoho     }
    232      1.1    jruoho 
    233      1.1    jruoho     return (AE_OK);
    234      1.1    jruoho }
    235      1.1    jruoho 
    236      1.1    jruoho 
    237      1.1    jruoho /******************************************************************************
    238      1.1    jruoho  *
    239      1.1    jruoho  * Example ACPICA initialization code with early ACPI table access. This shows
    240      1.1    jruoho  * an initialization that requires early access to ACPI tables (before
    241      1.1    jruoho  * kernel dynamic memory is available)
    242      1.1    jruoho  *
    243      1.1    jruoho  *****************************************************************************/
    244      1.1    jruoho 
    245      1.1    jruoho /*
    246      1.1    jruoho  * The purpose of this static table array is to avoid the use of kernel
    247      1.1    jruoho  * dynamic memory which may not be available during early ACPI table
    248      1.1    jruoho  * access.
    249      1.1    jruoho  */
    250      1.1    jruoho #define ACPI_MAX_INIT_TABLES    16
    251      1.1    jruoho static ACPI_TABLE_DESC      TableArray[ACPI_MAX_INIT_TABLES];
    252      1.1    jruoho 
    253      1.1    jruoho 
    254      1.1    jruoho /*
    255      1.1    jruoho  * This function would be called early in kernel initialization. After this
    256      1.1    jruoho  * is called, all ACPI tables are available to the host.
    257      1.1    jruoho  */
    258      1.1    jruoho ACPI_STATUS
    259  1.1.1.4  christos InitializeAcpiTables (
    260  1.1.1.4  christos     void)
    261      1.1    jruoho {
    262      1.1    jruoho     ACPI_STATUS             Status;
    263      1.1    jruoho 
    264      1.1    jruoho 
    265      1.1    jruoho     /* Initialize the ACPICA Table Manager and get all ACPI tables */
    266      1.1    jruoho 
    267      1.1    jruoho     Status = AcpiInitializeTables (TableArray, ACPI_MAX_INIT_TABLES, TRUE);
    268      1.1    jruoho     return (Status);
    269      1.1    jruoho }
    270      1.1    jruoho 
    271      1.1    jruoho 
    272      1.1    jruoho /*
    273      1.1    jruoho  * This function would be called after the kernel is initialized and
    274      1.1    jruoho  * dynamic/virtual memory is available. It completes the initialization of
    275      1.1    jruoho  * the ACPICA subsystem.
    276      1.1    jruoho  */
    277      1.1    jruoho ACPI_STATUS
    278  1.1.1.4  christos InitializeAcpi (
    279  1.1.1.4  christos     void)
    280      1.1    jruoho {
    281      1.1    jruoho     ACPI_STATUS             Status;
    282      1.1    jruoho 
    283      1.1    jruoho 
    284      1.1    jruoho     /* Initialize the ACPICA subsystem */
    285      1.1    jruoho 
    286      1.1    jruoho     Status = AcpiInitializeSubsystem ();
    287      1.1    jruoho     if (ACPI_FAILURE (Status))
    288      1.1    jruoho     {
    289      1.1    jruoho         return (Status);
    290      1.1    jruoho     }
    291      1.1    jruoho 
    292      1.1    jruoho     /* Copy the root table list to dynamic memory */
    293      1.1    jruoho 
    294      1.1    jruoho     Status = AcpiReallocateRootTable ();
    295      1.1    jruoho     if (ACPI_FAILURE (Status))
    296      1.1    jruoho     {
    297      1.1    jruoho         return (Status);
    298      1.1    jruoho     }
    299      1.1    jruoho 
    300  1.1.1.7  christos     /* Install local handlers */
    301      1.1    jruoho 
    302  1.1.1.7  christos     Status = InstallHandlers ();
    303      1.1    jruoho     if (ACPI_FAILURE (Status))
    304      1.1    jruoho     {
    305  1.1.1.7  christos         ACPI_EXCEPTION ((AE_INFO, Status, "While installing handlers"));
    306      1.1    jruoho         return (Status);
    307      1.1    jruoho     }
    308      1.1    jruoho 
    309  1.1.1.7  christos     /* Initialize the ACPI hardware */
    310      1.1    jruoho 
    311  1.1.1.7  christos     Status = AcpiEnableSubsystem (ACPI_FULL_INITIALIZATION);
    312      1.1    jruoho     if (ACPI_FAILURE (Status))
    313      1.1    jruoho     {
    314      1.1    jruoho         return (Status);
    315      1.1    jruoho     }
    316      1.1    jruoho 
    317  1.1.1.7  christos     /* Create the ACPI namespace from ACPI tables */
    318      1.1    jruoho 
    319  1.1.1.7  christos     Status = AcpiLoadTables ();
    320      1.1    jruoho     if (ACPI_FAILURE (Status))
    321      1.1    jruoho     {
    322      1.1    jruoho         return (Status);
    323      1.1    jruoho     }
    324      1.1    jruoho 
    325      1.1    jruoho     /* Complete the ACPI namespace object initialization */
    326      1.1    jruoho 
    327      1.1    jruoho     Status = AcpiInitializeObjects (ACPI_FULL_INITIALIZATION);
    328      1.1    jruoho     if (ACPI_FAILURE (Status))
    329      1.1    jruoho     {
    330      1.1    jruoho         return (Status);
    331      1.1    jruoho     }
    332      1.1    jruoho 
    333      1.1    jruoho     return (AE_OK);
    334      1.1    jruoho }
    335      1.1    jruoho 
    336      1.1    jruoho 
    337      1.1    jruoho /******************************************************************************
    338      1.1    jruoho  *
    339      1.1    jruoho  * Example ACPICA handler and handler installation
    340      1.1    jruoho  *
    341      1.1    jruoho  *****************************************************************************/
    342      1.1    jruoho 
    343  1.1.1.4  christos static void
    344      1.1    jruoho NotifyHandler (
    345      1.1    jruoho     ACPI_HANDLE                 Device,
    346      1.1    jruoho     UINT32                      Value,
    347      1.1    jruoho     void                        *Context)
    348      1.1    jruoho {
    349      1.1    jruoho 
    350  1.1.1.8  christos     ACPI_INFO (("Received a notify 0x%X", Value));
    351      1.1    jruoho }
    352      1.1    jruoho 
    353      1.1    jruoho 
    354  1.1.1.4  christos static ACPI_STATUS
    355  1.1.1.5  christos RegionInit (
    356  1.1.1.5  christos     ACPI_HANDLE                 RegionHandle,
    357  1.1.1.5  christos     UINT32                      Function,
    358  1.1.1.5  christos     void                        *HandlerContext,
    359  1.1.1.5  christos     void                        **RegionContext)
    360  1.1.1.5  christos {
    361  1.1.1.5  christos 
    362  1.1.1.5  christos     if (Function == ACPI_REGION_DEACTIVATE)
    363  1.1.1.5  christos     {
    364  1.1.1.5  christos         *RegionContext = NULL;
    365  1.1.1.5  christos     }
    366  1.1.1.5  christos     else
    367  1.1.1.5  christos     {
    368  1.1.1.5  christos         *RegionContext = RegionHandle;
    369  1.1.1.5  christos     }
    370  1.1.1.5  christos 
    371  1.1.1.5  christos     return (AE_OK);
    372  1.1.1.5  christos }
    373  1.1.1.5  christos 
    374  1.1.1.5  christos 
    375  1.1.1.5  christos static ACPI_STATUS
    376  1.1.1.5  christos RegionHandler (
    377  1.1.1.5  christos     UINT32                      Function,
    378  1.1.1.5  christos     ACPI_PHYSICAL_ADDRESS       Address,
    379  1.1.1.5  christos     UINT32                      BitWidth,
    380  1.1.1.5  christos     UINT64                      *Value,
    381  1.1.1.5  christos     void                        *HandlerContext,
    382  1.1.1.5  christos     void                        *RegionContext)
    383  1.1.1.5  christos {
    384  1.1.1.5  christos 
    385  1.1.1.8  christos     ACPI_INFO (("Received a region access"));
    386  1.1.1.5  christos 
    387  1.1.1.5  christos     return (AE_OK);
    388  1.1.1.5  christos }
    389  1.1.1.5  christos 
    390  1.1.1.5  christos 
    391  1.1.1.5  christos static ACPI_STATUS
    392      1.1    jruoho InstallHandlers (void)
    393      1.1    jruoho {
    394      1.1    jruoho     ACPI_STATUS             Status;
    395      1.1    jruoho 
    396      1.1    jruoho 
    397      1.1    jruoho     /* Install global notify handler */
    398      1.1    jruoho 
    399  1.1.1.7  christos     Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT,
    400  1.1.1.7  christos         ACPI_SYSTEM_NOTIFY, NotifyHandler, NULL);
    401      1.1    jruoho     if (ACPI_FAILURE (Status))
    402      1.1    jruoho     {
    403      1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "While installing Notify handler"));
    404      1.1    jruoho         return (Status);
    405      1.1    jruoho     }
    406      1.1    jruoho 
    407  1.1.1.7  christos     Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
    408  1.1.1.7  christos         ACPI_ADR_SPACE_SYSTEM_MEMORY, RegionHandler, RegionInit, NULL);
    409  1.1.1.5  christos     if (ACPI_FAILURE (Status))
    410  1.1.1.5  christos     {
    411  1.1.1.5  christos         ACPI_EXCEPTION ((AE_INFO, Status, "While installing an OpRegion handler"));
    412  1.1.1.5  christos         return (Status);
    413  1.1.1.5  christos     }
    414  1.1.1.5  christos 
    415      1.1    jruoho     return (AE_OK);
    416      1.1    jruoho }
    417      1.1    jruoho 
    418      1.1    jruoho 
    419      1.1    jruoho /******************************************************************************
    420      1.1    jruoho  *
    421  1.1.1.4  christos  * Examples of control method execution.
    422      1.1    jruoho  *
    423      1.1    jruoho  * _OSI is a predefined method that is implemented internally within ACPICA.
    424      1.1    jruoho  *
    425      1.1    jruoho  * Shows the following elements:
    426      1.1    jruoho  *
    427      1.1    jruoho  * 1) How to setup a control method argument and argument list
    428      1.1    jruoho  * 2) How to setup the return value object
    429      1.1    jruoho  * 3) How to invoke AcpiEvaluateObject
    430      1.1    jruoho  * 4) How to check the returned ACPI_STATUS
    431      1.1    jruoho  * 5) How to analyze the return value
    432      1.1    jruoho  *
    433      1.1    jruoho  *****************************************************************************/
    434      1.1    jruoho 
    435  1.1.1.4  christos static void
    436      1.1    jruoho ExecuteOSI (void)
    437      1.1    jruoho {
    438      1.1    jruoho     ACPI_STATUS             Status;
    439      1.1    jruoho     ACPI_OBJECT_LIST        ArgList;
    440      1.1    jruoho     ACPI_OBJECT             Arg[1];
    441      1.1    jruoho     ACPI_BUFFER             ReturnValue;
    442      1.1    jruoho     ACPI_OBJECT             *Object;
    443      1.1    jruoho 
    444      1.1    jruoho 
    445  1.1.1.8  christos     ACPI_INFO (("Executing _OSI reserved method"));
    446      1.1    jruoho 
    447      1.1    jruoho     /* Setup input argument */
    448      1.1    jruoho 
    449      1.1    jruoho     ArgList.Count = 1;
    450      1.1    jruoho     ArgList.Pointer = Arg;
    451      1.1    jruoho 
    452      1.1    jruoho     Arg[0].Type = ACPI_TYPE_STRING;
    453      1.1    jruoho     Arg[0].String.Pointer = "Windows 2001";
    454      1.1    jruoho     Arg[0].String.Length = strlen (Arg[0].String.Pointer);
    455      1.1    jruoho 
    456      1.1    jruoho     /* Ask ACPICA to allocate space for the return object */
    457      1.1    jruoho 
    458      1.1    jruoho     ReturnValue.Length = ACPI_ALLOCATE_BUFFER;
    459      1.1    jruoho 
    460      1.1    jruoho     Status = AcpiEvaluateObject (NULL, "\\_OSI", &ArgList, &ReturnValue);
    461      1.1    jruoho     if (ACPI_FAILURE (Status))
    462      1.1    jruoho     {
    463      1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "While executing _OSI"));
    464      1.1    jruoho         return;
    465      1.1    jruoho     }
    466      1.1    jruoho 
    467      1.1    jruoho     /* Ensure that the return object is large enough */
    468      1.1    jruoho 
    469      1.1    jruoho     if (ReturnValue.Length < sizeof (ACPI_OBJECT))
    470      1.1    jruoho     {
    471      1.1    jruoho         AcpiOsPrintf ("Return value from _OSI method too small, %.8X\n",
    472      1.1    jruoho             ReturnValue.Length);
    473  1.1.1.4  christos         goto ErrorExit;
    474      1.1    jruoho     }
    475      1.1    jruoho 
    476      1.1    jruoho     /* Expect an integer return value from execution of _OSI */
    477      1.1    jruoho 
    478      1.1    jruoho     Object = ReturnValue.Pointer;
    479      1.1    jruoho     if (Object->Type != ACPI_TYPE_INTEGER)
    480      1.1    jruoho     {
    481      1.1    jruoho         AcpiOsPrintf ("Invalid return type from _OSI, %.2X\n", Object->Type);
    482      1.1    jruoho     }
    483      1.1    jruoho 
    484  1.1.1.8  christos     ACPI_INFO (("_OSI returned 0x%8.8X",
    485  1.1.1.7  christos         (UINT32) Object->Integer.Value));
    486  1.1.1.4  christos 
    487  1.1.1.4  christos 
    488  1.1.1.4  christos ErrorExit:
    489  1.1.1.4  christos 
    490  1.1.1.4  christos     /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
    491  1.1.1.4  christos 
    492  1.1.1.4  christos     AcpiOsFree (ReturnValue.Pointer);
    493      1.1    jruoho }
    494      1.1    jruoho 
    495      1.1    jruoho 
    496      1.1    jruoho /******************************************************************************
    497      1.1    jruoho  *
    498  1.1.1.4  christos  * Execute an actual control method in the DSDT (MAIN)
    499      1.1    jruoho  *
    500      1.1    jruoho  *****************************************************************************/
    501      1.1    jruoho 
    502  1.1.1.4  christos static void
    503  1.1.1.4  christos ExecuteMAIN (void)
    504      1.1    jruoho {
    505  1.1.1.4  christos     ACPI_STATUS             Status;
    506  1.1.1.4  christos     ACPI_OBJECT_LIST        ArgList;
    507  1.1.1.4  christos     ACPI_OBJECT             Arg[1];
    508  1.1.1.4  christos     ACPI_BUFFER             ReturnValue;
    509  1.1.1.4  christos     ACPI_OBJECT             *Object;
    510      1.1    jruoho 
    511      1.1    jruoho 
    512  1.1.1.8  christos     ACPI_INFO (("Executing MAIN method"));
    513  1.1.1.3    jruoho 
    514  1.1.1.4  christos     /* Setup input argument */
    515  1.1.1.4  christos 
    516  1.1.1.4  christos     ArgList.Count = 1;
    517  1.1.1.4  christos     ArgList.Pointer = Arg;
    518  1.1.1.4  christos 
    519  1.1.1.4  christos     Arg[0].Type = ACPI_TYPE_STRING;
    520  1.1.1.4  christos     Arg[0].String.Pointer = "Method [MAIN] is executing";
    521  1.1.1.4  christos     Arg[0].String.Length = strlen (Arg[0].String.Pointer);
    522  1.1.1.4  christos 
    523  1.1.1.4  christos     /* Ask ACPICA to allocate space for the return object */
    524  1.1.1.4  christos 
    525  1.1.1.4  christos     ReturnValue.Length = ACPI_ALLOCATE_BUFFER;
    526  1.1.1.4  christos 
    527  1.1.1.4  christos     Status = AcpiEvaluateObject (NULL, "\\MAIN", &ArgList, &ReturnValue);
    528  1.1.1.4  christos     if (ACPI_FAILURE (Status))
    529  1.1.1.4  christos     {
    530  1.1.1.4  christos         ACPI_EXCEPTION ((AE_INFO, Status, "While executing MAIN"));
    531  1.1.1.4  christos         return;
    532  1.1.1.4  christos     }
    533  1.1.1.4  christos 
    534  1.1.1.4  christos     if (ReturnValue.Pointer)
    535  1.1.1.4  christos     {
    536  1.1.1.4  christos         /* Obtain and validate the returned ACPI_OBJECT */
    537  1.1.1.4  christos 
    538  1.1.1.4  christos         Object = ReturnValue.Pointer;
    539  1.1.1.4  christos         if (Object->Type == ACPI_TYPE_STRING)
    540  1.1.1.4  christos         {
    541  1.1.1.7  christos             AcpiOsPrintf ("Method [MAIN] returned: \"%s\"\n",
    542  1.1.1.7  christos                 Object->String.Pointer);
    543  1.1.1.4  christos         }
    544  1.1.1.4  christos 
    545  1.1.1.4  christos         ACPI_FREE (ReturnValue.Pointer);
    546  1.1.1.4  christos     }
    547  1.1.1.3    jruoho }
    548