Home | History | Annotate | Line # | Download | only in utilities
utxface.c revision 1.1.1.13
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3   1.1.1.3  christos  * Module Name: utxface - External interfaces, miscellaneous utility functions
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.13  christos  * Copyright (C) 2000 - 2021, 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.13  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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.3  christos #define EXPORT_ACPI_INTERFACES
     45       1.1    jruoho 
     46       1.1    jruoho #include "acpi.h"
     47       1.1    jruoho #include "accommon.h"
     48       1.1    jruoho #include "acdebug.h"
     49       1.1    jruoho 
     50       1.1    jruoho #define _COMPONENT          ACPI_UTILITIES
     51       1.1    jruoho         ACPI_MODULE_NAME    ("utxface")
     52       1.1    jruoho 
     53       1.1    jruoho 
     54       1.1    jruoho /*******************************************************************************
     55       1.1    jruoho  *
     56       1.1    jruoho  * FUNCTION:    AcpiTerminate
     57       1.1    jruoho  *
     58       1.1    jruoho  * PARAMETERS:  None
     59       1.1    jruoho  *
     60       1.1    jruoho  * RETURN:      Status
     61       1.1    jruoho  *
     62       1.1    jruoho  * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
     63       1.1    jruoho  *
     64       1.1    jruoho  ******************************************************************************/
     65       1.1    jruoho 
     66   1.1.1.8  christos ACPI_STATUS ACPI_INIT_FUNCTION
     67       1.1    jruoho AcpiTerminate (
     68       1.1    jruoho     void)
     69       1.1    jruoho {
     70       1.1    jruoho     ACPI_STATUS         Status;
     71       1.1    jruoho 
     72       1.1    jruoho 
     73       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiTerminate);
     74       1.1    jruoho 
     75       1.1    jruoho 
     76       1.1    jruoho     /* Shutdown and free all resources */
     77       1.1    jruoho 
     78       1.1    jruoho     AcpiUtSubsystemShutdown ();
     79       1.1    jruoho 
     80       1.1    jruoho     /* Free the mutex objects */
     81       1.1    jruoho 
     82       1.1    jruoho     AcpiUtMutexTerminate ();
     83       1.1    jruoho 
     84       1.1    jruoho     /* Now we can shutdown the OS-dependent layer */
     85       1.1    jruoho 
     86       1.1    jruoho     Status = AcpiOsTerminate ();
     87       1.1    jruoho     return_ACPI_STATUS (Status);
     88       1.1    jruoho }
     89       1.1    jruoho 
     90   1.1.1.3  christos ACPI_EXPORT_SYMBOL_INIT (AcpiTerminate)
     91       1.1    jruoho 
     92       1.1    jruoho 
     93       1.1    jruoho #ifndef ACPI_ASL_COMPILER
     94       1.1    jruoho /*******************************************************************************
     95       1.1    jruoho  *
     96       1.1    jruoho  * FUNCTION:    AcpiSubsystemStatus
     97       1.1    jruoho  *
     98       1.1    jruoho  * PARAMETERS:  None
     99       1.1    jruoho  *
    100       1.1    jruoho  * RETURN:      Status of the ACPI subsystem
    101       1.1    jruoho  *
    102       1.1    jruoho  * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
    103       1.1    jruoho  *              before making any other calls, to ensure the subsystem
    104       1.1    jruoho  *              initialized successfully.
    105       1.1    jruoho  *
    106       1.1    jruoho  ******************************************************************************/
    107       1.1    jruoho 
    108       1.1    jruoho ACPI_STATUS
    109       1.1    jruoho AcpiSubsystemStatus (
    110       1.1    jruoho     void)
    111       1.1    jruoho {
    112       1.1    jruoho 
    113       1.1    jruoho     if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
    114       1.1    jruoho     {
    115       1.1    jruoho         return (AE_OK);
    116       1.1    jruoho     }
    117       1.1    jruoho     else
    118       1.1    jruoho     {
    119       1.1    jruoho         return (AE_ERROR);
    120       1.1    jruoho     }
    121       1.1    jruoho }
    122       1.1    jruoho 
    123       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
    124       1.1    jruoho 
    125       1.1    jruoho 
    126       1.1    jruoho /*******************************************************************************
    127       1.1    jruoho  *
    128       1.1    jruoho  * FUNCTION:    AcpiGetSystemInfo
    129       1.1    jruoho  *
    130       1.1    jruoho  * PARAMETERS:  OutBuffer       - A buffer to receive the resources for the
    131       1.1    jruoho  *                                device
    132       1.1    jruoho  *
    133       1.1    jruoho  * RETURN:      Status          - the status of the call
    134       1.1    jruoho  *
    135       1.1    jruoho  * DESCRIPTION: This function is called to get information about the current
    136   1.1.1.3  christos  *              state of the ACPI subsystem. It will return system information
    137       1.1    jruoho  *              in the OutBuffer.
    138       1.1    jruoho  *
    139       1.1    jruoho  *              If the function fails an appropriate status will be returned
    140       1.1    jruoho  *              and the value of OutBuffer is undefined.
    141       1.1    jruoho  *
    142       1.1    jruoho  ******************************************************************************/
    143       1.1    jruoho 
    144       1.1    jruoho ACPI_STATUS
    145       1.1    jruoho AcpiGetSystemInfo (
    146       1.1    jruoho     ACPI_BUFFER             *OutBuffer)
    147       1.1    jruoho {
    148       1.1    jruoho     ACPI_SYSTEM_INFO        *InfoPtr;
    149       1.1    jruoho     ACPI_STATUS             Status;
    150       1.1    jruoho 
    151       1.1    jruoho 
    152       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
    153       1.1    jruoho 
    154       1.1    jruoho 
    155       1.1    jruoho     /* Parameter validation */
    156       1.1    jruoho 
    157       1.1    jruoho     Status = AcpiUtValidateBuffer (OutBuffer);
    158       1.1    jruoho     if (ACPI_FAILURE (Status))
    159       1.1    jruoho     {
    160       1.1    jruoho         return_ACPI_STATUS (Status);
    161       1.1    jruoho     }
    162       1.1    jruoho 
    163       1.1    jruoho     /* Validate/Allocate/Clear caller buffer */
    164       1.1    jruoho 
    165       1.1    jruoho     Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
    166       1.1    jruoho     if (ACPI_FAILURE (Status))
    167       1.1    jruoho     {
    168       1.1    jruoho         return_ACPI_STATUS (Status);
    169       1.1    jruoho     }
    170       1.1    jruoho 
    171       1.1    jruoho     /*
    172       1.1    jruoho      * Populate the return buffer
    173       1.1    jruoho      */
    174       1.1    jruoho     InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
    175       1.1    jruoho     InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
    176       1.1    jruoho 
    177       1.1    jruoho     /* System flags (ACPI capabilities) */
    178       1.1    jruoho 
    179       1.1    jruoho     InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
    180       1.1    jruoho 
    181       1.1    jruoho     /* Timer resolution - 24 or 32 bits  */
    182       1.1    jruoho 
    183       1.1    jruoho     if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
    184       1.1    jruoho     {
    185       1.1    jruoho         InfoPtr->TimerResolution = 24;
    186       1.1    jruoho     }
    187       1.1    jruoho     else
    188       1.1    jruoho     {
    189       1.1    jruoho         InfoPtr->TimerResolution = 32;
    190       1.1    jruoho     }
    191       1.1    jruoho 
    192       1.1    jruoho     /* Clear the reserved fields */
    193       1.1    jruoho 
    194       1.1    jruoho     InfoPtr->Reserved1 = 0;
    195       1.1    jruoho     InfoPtr->Reserved2 = 0;
    196       1.1    jruoho 
    197       1.1    jruoho     /* Current debug levels */
    198       1.1    jruoho 
    199       1.1    jruoho     InfoPtr->DebugLayer = AcpiDbgLayer;
    200       1.1    jruoho     InfoPtr->DebugLevel = AcpiDbgLevel;
    201       1.1    jruoho 
    202       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    203       1.1    jruoho }
    204       1.1    jruoho 
    205       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
    206       1.1    jruoho 
    207       1.1    jruoho 
    208       1.1    jruoho /*******************************************************************************
    209       1.1    jruoho  *
    210       1.1    jruoho  * FUNCTION:    AcpiGetStatistics
    211       1.1    jruoho  *
    212       1.1    jruoho  * PARAMETERS:  Stats           - Where the statistics are returned
    213       1.1    jruoho  *
    214       1.1    jruoho  * RETURN:      Status          - the status of the call
    215       1.1    jruoho  *
    216       1.1    jruoho  * DESCRIPTION: Get the contents of the various system counters
    217       1.1    jruoho  *
    218       1.1    jruoho  ******************************************************************************/
    219       1.1    jruoho 
    220       1.1    jruoho ACPI_STATUS
    221       1.1    jruoho AcpiGetStatistics (
    222       1.1    jruoho     ACPI_STATISTICS         *Stats)
    223       1.1    jruoho {
    224       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiGetStatistics);
    225       1.1    jruoho 
    226       1.1    jruoho 
    227       1.1    jruoho     /* Parameter validation */
    228       1.1    jruoho 
    229       1.1    jruoho     if (!Stats)
    230       1.1    jruoho     {
    231       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    232       1.1    jruoho     }
    233       1.1    jruoho 
    234       1.1    jruoho     /* Various interrupt-based event counters */
    235       1.1    jruoho 
    236       1.1    jruoho     Stats->SciCount = AcpiSciCount;
    237       1.1    jruoho     Stats->GpeCount = AcpiGpeCount;
    238       1.1    jruoho 
    239   1.1.1.6  christos     memcpy (Stats->FixedEventCount, AcpiFixedEventCount,
    240       1.1    jruoho         sizeof (AcpiFixedEventCount));
    241       1.1    jruoho 
    242       1.1    jruoho     /* Other counters */
    243       1.1    jruoho 
    244       1.1    jruoho     Stats->MethodCount = AcpiMethodCount;
    245       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    246       1.1    jruoho }
    247       1.1    jruoho 
    248       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
    249       1.1    jruoho 
    250       1.1    jruoho 
    251       1.1    jruoho /*****************************************************************************
    252       1.1    jruoho  *
    253       1.1    jruoho  * FUNCTION:    AcpiInstallInitializationHandler
    254       1.1    jruoho  *
    255       1.1    jruoho  * PARAMETERS:  Handler             - Callback procedure
    256       1.1    jruoho  *              Function            - Not (currently) used, see below
    257       1.1    jruoho  *
    258       1.1    jruoho  * RETURN:      Status
    259       1.1    jruoho  *
    260       1.1    jruoho  * DESCRIPTION: Install an initialization handler
    261       1.1    jruoho  *
    262       1.1    jruoho  * TBD: When a second function is added, must save the Function also.
    263       1.1    jruoho  *
    264       1.1    jruoho  ****************************************************************************/
    265       1.1    jruoho 
    266       1.1    jruoho ACPI_STATUS
    267       1.1    jruoho AcpiInstallInitializationHandler (
    268       1.1    jruoho     ACPI_INIT_HANDLER       Handler,
    269       1.1    jruoho     UINT32                  Function)
    270       1.1    jruoho {
    271       1.1    jruoho 
    272       1.1    jruoho     if (!Handler)
    273       1.1    jruoho     {
    274       1.1    jruoho         return (AE_BAD_PARAMETER);
    275       1.1    jruoho     }
    276       1.1    jruoho 
    277       1.1    jruoho     if (AcpiGbl_InitHandler)
    278       1.1    jruoho     {
    279       1.1    jruoho         return (AE_ALREADY_EXISTS);
    280       1.1    jruoho     }
    281       1.1    jruoho 
    282       1.1    jruoho     AcpiGbl_InitHandler = Handler;
    283   1.1.1.3  christos     return (AE_OK);
    284       1.1    jruoho }
    285       1.1    jruoho 
    286       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
    287       1.1    jruoho 
    288       1.1    jruoho 
    289       1.1    jruoho /*****************************************************************************
    290       1.1    jruoho  *
    291       1.1    jruoho  * FUNCTION:    AcpiPurgeCachedObjects
    292       1.1    jruoho  *
    293       1.1    jruoho  * PARAMETERS:  None
    294       1.1    jruoho  *
    295       1.1    jruoho  * RETURN:      Status
    296       1.1    jruoho  *
    297       1.1    jruoho  * DESCRIPTION: Empty all caches (delete the cached objects)
    298       1.1    jruoho  *
    299       1.1    jruoho  ****************************************************************************/
    300       1.1    jruoho 
    301       1.1    jruoho ACPI_STATUS
    302       1.1    jruoho AcpiPurgeCachedObjects (
    303       1.1    jruoho     void)
    304       1.1    jruoho {
    305       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
    306       1.1    jruoho 
    307   1.1.1.3  christos 
    308       1.1    jruoho     (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
    309       1.1    jruoho     (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
    310       1.1    jruoho     (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
    311       1.1    jruoho     (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
    312   1.1.1.3  christos 
    313       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    314       1.1    jruoho }
    315       1.1    jruoho 
    316       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
    317       1.1    jruoho 
    318   1.1.1.2    jruoho 
    319   1.1.1.2    jruoho /*****************************************************************************
    320   1.1.1.2    jruoho  *
    321   1.1.1.2    jruoho  * FUNCTION:    AcpiInstallInterface
    322   1.1.1.2    jruoho  *
    323   1.1.1.2    jruoho  * PARAMETERS:  InterfaceName       - The interface to install
    324   1.1.1.2    jruoho  *
    325   1.1.1.2    jruoho  * RETURN:      Status
    326   1.1.1.2    jruoho  *
    327   1.1.1.2    jruoho  * DESCRIPTION: Install an _OSI interface to the global list
    328   1.1.1.2    jruoho  *
    329   1.1.1.2    jruoho  ****************************************************************************/
    330   1.1.1.2    jruoho 
    331   1.1.1.2    jruoho ACPI_STATUS
    332   1.1.1.2    jruoho AcpiInstallInterface (
    333   1.1.1.2    jruoho     ACPI_STRING             InterfaceName)
    334   1.1.1.2    jruoho {
    335   1.1.1.2    jruoho     ACPI_STATUS             Status;
    336   1.1.1.2    jruoho     ACPI_INTERFACE_INFO     *InterfaceInfo;
    337   1.1.1.2    jruoho 
    338   1.1.1.2    jruoho 
    339   1.1.1.2    jruoho     /* Parameter validation */
    340   1.1.1.2    jruoho 
    341   1.1.1.6  christos     if (!InterfaceName || (strlen (InterfaceName) == 0))
    342   1.1.1.2    jruoho     {
    343   1.1.1.2    jruoho         return (AE_BAD_PARAMETER);
    344   1.1.1.2    jruoho     }
    345   1.1.1.2    jruoho 
    346   1.1.1.3  christos     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    347   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    348   1.1.1.3  christos     {
    349   1.1.1.3  christos         return (Status);
    350   1.1.1.3  christos     }
    351   1.1.1.2    jruoho 
    352   1.1.1.2    jruoho     /* Check if the interface name is already in the global list */
    353   1.1.1.2    jruoho 
    354   1.1.1.2    jruoho     InterfaceInfo = AcpiUtGetInterface (InterfaceName);
    355   1.1.1.2    jruoho     if (InterfaceInfo)
    356   1.1.1.2    jruoho     {
    357   1.1.1.2    jruoho         /*
    358   1.1.1.2    jruoho          * The interface already exists in the list. This is OK if the
    359   1.1.1.2    jruoho          * interface has been marked invalid -- just clear the bit.
    360   1.1.1.2    jruoho          */
    361   1.1.1.2    jruoho         if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
    362   1.1.1.2    jruoho         {
    363   1.1.1.2    jruoho             InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
    364   1.1.1.2    jruoho             Status = AE_OK;
    365   1.1.1.2    jruoho         }
    366   1.1.1.2    jruoho         else
    367   1.1.1.2    jruoho         {
    368   1.1.1.2    jruoho             Status = AE_ALREADY_EXISTS;
    369   1.1.1.2    jruoho         }
    370   1.1.1.2    jruoho     }
    371   1.1.1.2    jruoho     else
    372   1.1.1.2    jruoho     {
    373   1.1.1.2    jruoho         /* New interface name, install into the global list */
    374   1.1.1.2    jruoho 
    375   1.1.1.2    jruoho         Status = AcpiUtInstallInterface (InterfaceName);
    376   1.1.1.2    jruoho     }
    377   1.1.1.2    jruoho 
    378   1.1.1.2    jruoho     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    379   1.1.1.2    jruoho     return (Status);
    380   1.1.1.2    jruoho }
    381   1.1.1.2    jruoho 
    382   1.1.1.2    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
    383   1.1.1.2    jruoho 
    384   1.1.1.2    jruoho 
    385   1.1.1.2    jruoho /*****************************************************************************
    386   1.1.1.2    jruoho  *
    387   1.1.1.2    jruoho  * FUNCTION:    AcpiRemoveInterface
    388   1.1.1.2    jruoho  *
    389   1.1.1.2    jruoho  * PARAMETERS:  InterfaceName       - The interface to remove
    390   1.1.1.2    jruoho  *
    391   1.1.1.2    jruoho  * RETURN:      Status
    392   1.1.1.2    jruoho  *
    393   1.1.1.2    jruoho  * DESCRIPTION: Remove an _OSI interface from the global list
    394   1.1.1.2    jruoho  *
    395   1.1.1.2    jruoho  ****************************************************************************/
    396   1.1.1.2    jruoho 
    397   1.1.1.2    jruoho ACPI_STATUS
    398   1.1.1.2    jruoho AcpiRemoveInterface (
    399   1.1.1.2    jruoho     ACPI_STRING             InterfaceName)
    400   1.1.1.2    jruoho {
    401   1.1.1.2    jruoho     ACPI_STATUS             Status;
    402   1.1.1.2    jruoho 
    403   1.1.1.2    jruoho 
    404   1.1.1.2    jruoho     /* Parameter validation */
    405   1.1.1.2    jruoho 
    406   1.1.1.6  christos     if (!InterfaceName || (strlen (InterfaceName) == 0))
    407   1.1.1.2    jruoho     {
    408   1.1.1.2    jruoho         return (AE_BAD_PARAMETER);
    409   1.1.1.2    jruoho     }
    410   1.1.1.2    jruoho 
    411   1.1.1.3  christos     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    412   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    413   1.1.1.3  christos     {
    414   1.1.1.3  christos         return (Status);
    415   1.1.1.3  christos     }
    416   1.1.1.2    jruoho 
    417   1.1.1.2    jruoho     Status = AcpiUtRemoveInterface (InterfaceName);
    418   1.1.1.2    jruoho 
    419   1.1.1.2    jruoho     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    420   1.1.1.2    jruoho     return (Status);
    421   1.1.1.2    jruoho }
    422   1.1.1.2    jruoho 
    423   1.1.1.2    jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
    424   1.1.1.2    jruoho 
    425   1.1.1.2    jruoho 
    426   1.1.1.2    jruoho /*****************************************************************************
    427   1.1.1.2    jruoho  *
    428   1.1.1.2    jruoho  * FUNCTION:    AcpiInstallInterfaceHandler
    429   1.1.1.2    jruoho  *
    430   1.1.1.2    jruoho  * PARAMETERS:  Handler             - The _OSI interface handler to install
    431   1.1.1.2    jruoho  *                                    NULL means "remove existing handler"
    432   1.1.1.2    jruoho  *
    433   1.1.1.2    jruoho  * RETURN:      Status
    434   1.1.1.2    jruoho  *
    435   1.1.1.2    jruoho  * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
    436   1.1.1.2    jruoho  *              invoked during execution of the internal implementation of
    437   1.1.1.2    jruoho  *              _OSI. A NULL handler simply removes any existing handler.
    438   1.1.1.2    jruoho  *
    439   1.1.1.2    jruoho  ****************************************************************************/
    440   1.1.1.2    jruoho 
    441   1.1.1.2    jruoho ACPI_STATUS
    442   1.1.1.2    jruoho AcpiInstallInterfaceHandler (
    443   1.1.1.2    jruoho     ACPI_INTERFACE_HANDLER  Handler)
    444   1.1.1.2    jruoho {
    445   1.1.1.3  christos     ACPI_STATUS             Status;
    446   1.1.1.2    jruoho 
    447   1.1.1.2    jruoho 
    448   1.1.1.3  christos     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    449   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    450   1.1.1.3  christos     {
    451   1.1.1.3  christos         return (Status);
    452   1.1.1.3  christos     }
    453   1.1.1.2    jruoho 
    454   1.1.1.2    jruoho     if (Handler && AcpiGbl_InterfaceHandler)
    455   1.1.1.2    jruoho     {
    456   1.1.1.2    jruoho         Status = AE_ALREADY_EXISTS;
    457   1.1.1.2    jruoho     }
    458   1.1.1.2    jruoho     else
    459   1.1.1.2    jruoho     {
    460   1.1.1.2    jruoho         AcpiGbl_InterfaceHandler = Handler;
    461   1.1.1.2    jruoho     }
    462   1.1.1.2    jruoho 
    463   1.1.1.2    jruoho     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    464   1.1.1.2    jruoho     return (Status);
    465   1.1.1.2    jruoho }
    466   1.1.1.2    jruoho 
    467   1.1.1.2    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
    468   1.1.1.2    jruoho 
    469   1.1.1.3  christos 
    470   1.1.1.3  christos /*****************************************************************************
    471   1.1.1.3  christos  *
    472   1.1.1.3  christos  * FUNCTION:    AcpiUpdateInterfaces
    473   1.1.1.3  christos  *
    474   1.1.1.3  christos  * PARAMETERS:  Action              - Actions to be performed during the
    475   1.1.1.3  christos  *                                    update
    476   1.1.1.3  christos  *
    477   1.1.1.3  christos  * RETURN:      Status
    478   1.1.1.3  christos  *
    479   1.1.1.3  christos  * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
    480   1.1.1.3  christos  *              string or/and feature group strings.
    481   1.1.1.3  christos  *
    482   1.1.1.3  christos  ****************************************************************************/
    483   1.1.1.3  christos 
    484   1.1.1.3  christos ACPI_STATUS
    485   1.1.1.3  christos AcpiUpdateInterfaces (
    486   1.1.1.3  christos     UINT8                   Action)
    487   1.1.1.3  christos {
    488   1.1.1.3  christos     ACPI_STATUS             Status;
    489   1.1.1.3  christos 
    490   1.1.1.3  christos 
    491   1.1.1.3  christos     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    492   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    493   1.1.1.3  christos     {
    494   1.1.1.3  christos         return (Status);
    495   1.1.1.3  christos     }
    496   1.1.1.3  christos 
    497   1.1.1.3  christos     Status = AcpiUtUpdateInterfaces (Action);
    498   1.1.1.3  christos 
    499   1.1.1.3  christos     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    500   1.1.1.3  christos     return (Status);
    501   1.1.1.3  christos }
    502   1.1.1.3  christos 
    503   1.1.1.3  christos 
    504   1.1.1.3  christos /*****************************************************************************
    505   1.1.1.3  christos  *
    506   1.1.1.3  christos  * FUNCTION:    AcpiCheckAddressRange
    507   1.1.1.3  christos  *
    508   1.1.1.3  christos  * PARAMETERS:  SpaceId             - Address space ID
    509   1.1.1.3  christos  *              Address             - Start address
    510   1.1.1.3  christos  *              Length              - Length
    511   1.1.1.3  christos  *              Warn                - TRUE if warning on overlap desired
    512   1.1.1.3  christos  *
    513   1.1.1.3  christos  * RETURN:      Count of the number of conflicts detected.
    514   1.1.1.3  christos  *
    515   1.1.1.3  christos  * DESCRIPTION: Check if the input address range overlaps any of the
    516   1.1.1.3  christos  *              ASL operation region address ranges.
    517   1.1.1.3  christos  *
    518   1.1.1.3  christos  ****************************************************************************/
    519   1.1.1.3  christos 
    520   1.1.1.3  christos UINT32
    521   1.1.1.3  christos AcpiCheckAddressRange (
    522   1.1.1.3  christos     ACPI_ADR_SPACE_TYPE     SpaceId,
    523   1.1.1.3  christos     ACPI_PHYSICAL_ADDRESS   Address,
    524   1.1.1.3  christos     ACPI_SIZE               Length,
    525   1.1.1.3  christos     BOOLEAN                 Warn)
    526   1.1.1.3  christos {
    527   1.1.1.3  christos     UINT32                  Overlaps;
    528   1.1.1.3  christos     ACPI_STATUS             Status;
    529   1.1.1.3  christos 
    530   1.1.1.3  christos 
    531   1.1.1.3  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    532   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    533   1.1.1.3  christos     {
    534   1.1.1.3  christos         return (0);
    535   1.1.1.3  christos     }
    536   1.1.1.3  christos 
    537   1.1.1.3  christos     Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
    538   1.1.1.3  christos         (UINT32) Length, Warn);
    539   1.1.1.3  christos 
    540   1.1.1.3  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    541   1.1.1.3  christos     return (Overlaps);
    542   1.1.1.3  christos }
    543   1.1.1.3  christos 
    544   1.1.1.3  christos ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
    545   1.1.1.3  christos 
    546   1.1.1.2    jruoho #endif /* !ACPI_ASL_COMPILER */
    547       1.1    jruoho 
    548   1.1.1.3  christos 
    549   1.1.1.3  christos /*******************************************************************************
    550   1.1.1.3  christos  *
    551   1.1.1.3  christos  * FUNCTION:    AcpiDecodePldBuffer
    552   1.1.1.3  christos  *
    553   1.1.1.3  christos  * PARAMETERS:  InBuffer            - Buffer returned by _PLD method
    554   1.1.1.3  christos  *              Length              - Length of the InBuffer
    555   1.1.1.3  christos  *              ReturnBuffer        - Where the decode buffer is returned
    556   1.1.1.3  christos  *
    557   1.1.1.3  christos  * RETURN:      Status and the decoded _PLD buffer. User must deallocate
    558   1.1.1.3  christos  *              the buffer via ACPI_FREE.
    559   1.1.1.3  christos  *
    560   1.1.1.3  christos  * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
    561   1.1.1.3  christos  *              a local struct that is much more useful to an ACPI driver.
    562   1.1.1.3  christos  *
    563   1.1.1.3  christos  ******************************************************************************/
    564   1.1.1.3  christos 
    565   1.1.1.3  christos ACPI_STATUS
    566   1.1.1.3  christos AcpiDecodePldBuffer (
    567   1.1.1.3  christos     UINT8                   *InBuffer,
    568   1.1.1.3  christos     ACPI_SIZE               Length,
    569   1.1.1.3  christos     ACPI_PLD_INFO           **ReturnBuffer)
    570   1.1.1.3  christos {
    571   1.1.1.3  christos     ACPI_PLD_INFO           *PldInfo;
    572   1.1.1.3  christos     UINT32                  *Buffer = ACPI_CAST_PTR (UINT32, InBuffer);
    573   1.1.1.3  christos     UINT32                  Dword;
    574   1.1.1.3  christos 
    575   1.1.1.3  christos 
    576   1.1.1.3  christos     /* Parameter validation */
    577   1.1.1.3  christos 
    578   1.1.1.7  christos     if (!InBuffer || !ReturnBuffer || (Length < ACPI_PLD_REV1_BUFFER_SIZE))
    579   1.1.1.3  christos     {
    580   1.1.1.3  christos         return (AE_BAD_PARAMETER);
    581   1.1.1.3  christos     }
    582   1.1.1.3  christos 
    583   1.1.1.3  christos     PldInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO));
    584   1.1.1.3  christos     if (!PldInfo)
    585   1.1.1.3  christos     {
    586   1.1.1.3  christos         return (AE_NO_MEMORY);
    587   1.1.1.3  christos     }
    588   1.1.1.3  christos 
    589   1.1.1.3  christos     /* First 32-bit DWord */
    590   1.1.1.3  christos 
    591   1.1.1.3  christos     ACPI_MOVE_32_TO_32 (&Dword, &Buffer[0]);
    592   1.1.1.3  christos     PldInfo->Revision =             ACPI_PLD_GET_REVISION (&Dword);
    593   1.1.1.3  christos     PldInfo->IgnoreColor =          ACPI_PLD_GET_IGNORE_COLOR (&Dword);
    594   1.1.1.5  christos     PldInfo->Red =                  ACPI_PLD_GET_RED (&Dword);
    595   1.1.1.5  christos     PldInfo->Green =                ACPI_PLD_GET_GREEN (&Dword);
    596   1.1.1.5  christos     PldInfo->Blue =                 ACPI_PLD_GET_BLUE (&Dword);
    597   1.1.1.3  christos 
    598   1.1.1.3  christos     /* Second 32-bit DWord */
    599   1.1.1.3  christos 
    600   1.1.1.3  christos     ACPI_MOVE_32_TO_32 (&Dword, &Buffer[1]);
    601   1.1.1.3  christos     PldInfo->Width =                ACPI_PLD_GET_WIDTH (&Dword);
    602   1.1.1.3  christos     PldInfo->Height =               ACPI_PLD_GET_HEIGHT(&Dword);
    603   1.1.1.3  christos 
    604   1.1.1.3  christos     /* Third 32-bit DWord */
    605   1.1.1.3  christos 
    606   1.1.1.3  christos     ACPI_MOVE_32_TO_32 (&Dword, &Buffer[2]);
    607   1.1.1.3  christos     PldInfo->UserVisible =          ACPI_PLD_GET_USER_VISIBLE (&Dword);
    608   1.1.1.3  christos     PldInfo->Dock =                 ACPI_PLD_GET_DOCK (&Dword);
    609   1.1.1.3  christos     PldInfo->Lid =                  ACPI_PLD_GET_LID (&Dword);
    610   1.1.1.3  christos     PldInfo->Panel =                ACPI_PLD_GET_PANEL (&Dword);
    611   1.1.1.3  christos     PldInfo->VerticalPosition =     ACPI_PLD_GET_VERTICAL (&Dword);
    612   1.1.1.3  christos     PldInfo->HorizontalPosition =   ACPI_PLD_GET_HORIZONTAL (&Dword);
    613   1.1.1.3  christos     PldInfo->Shape =                ACPI_PLD_GET_SHAPE (&Dword);
    614   1.1.1.3  christos     PldInfo->GroupOrientation =     ACPI_PLD_GET_ORIENTATION (&Dword);
    615   1.1.1.3  christos     PldInfo->GroupToken =           ACPI_PLD_GET_TOKEN (&Dword);
    616   1.1.1.3  christos     PldInfo->GroupPosition =        ACPI_PLD_GET_POSITION (&Dword);
    617   1.1.1.3  christos     PldInfo->Bay =                  ACPI_PLD_GET_BAY (&Dword);
    618   1.1.1.3  christos 
    619   1.1.1.3  christos     /* Fourth 32-bit DWord */
    620   1.1.1.3  christos 
    621   1.1.1.3  christos     ACPI_MOVE_32_TO_32 (&Dword, &Buffer[3]);
    622   1.1.1.3  christos     PldInfo->Ejectable =            ACPI_PLD_GET_EJECTABLE (&Dword);
    623   1.1.1.3  christos     PldInfo->OspmEjectRequired =    ACPI_PLD_GET_OSPM_EJECT (&Dword);
    624   1.1.1.3  christos     PldInfo->CabinetNumber =        ACPI_PLD_GET_CABINET (&Dword);
    625   1.1.1.3  christos     PldInfo->CardCageNumber =       ACPI_PLD_GET_CARD_CAGE (&Dword);
    626   1.1.1.3  christos     PldInfo->Reference =            ACPI_PLD_GET_REFERENCE (&Dword);
    627   1.1.1.3  christos     PldInfo->Rotation =             ACPI_PLD_GET_ROTATION (&Dword);
    628   1.1.1.3  christos     PldInfo->Order =                ACPI_PLD_GET_ORDER (&Dword);
    629   1.1.1.3  christos 
    630   1.1.1.7  christos     if (Length >= ACPI_PLD_REV2_BUFFER_SIZE)
    631   1.1.1.3  christos     {
    632   1.1.1.3  christos         /* Fifth 32-bit DWord (Revision 2 of _PLD) */
    633   1.1.1.3  christos 
    634   1.1.1.3  christos         ACPI_MOVE_32_TO_32 (&Dword, &Buffer[4]);
    635   1.1.1.3  christos         PldInfo->VerticalOffset =       ACPI_PLD_GET_VERT_OFFSET (&Dword);
    636   1.1.1.3  christos         PldInfo->HorizontalOffset =     ACPI_PLD_GET_HORIZ_OFFSET (&Dword);
    637   1.1.1.3  christos     }
    638   1.1.1.3  christos 
    639   1.1.1.3  christos     *ReturnBuffer = PldInfo;
    640   1.1.1.3  christos     return (AE_OK);
    641   1.1.1.3  christos }
    642   1.1.1.3  christos 
    643   1.1.1.3  christos ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer)
    644