utosi.c revision 1.1.1.18       1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: utosi - Support for the _OSI predefined control method
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7       1.1    jruoho /*
      8  1.1.1.17  christos  * Copyright (C) 2000 - 2023, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11       1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.1    jruoho  * modification, are permitted provided that the following conditions
     13       1.1    jruoho  * are met:
     14       1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.1    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.1    jruoho  *    without modification.
     17       1.1    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1    jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.1    jruoho  *    binary redistribution.
     22       1.1    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1    jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.1    jruoho  *    from this software without specific prior written permission.
     25       1.1    jruoho  *
     26       1.1    jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.1    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1    jruoho  * Software Foundation.
     29       1.1    jruoho  *
     30       1.1    jruoho  * NO WARRANTY
     31       1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.14  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34       1.1    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho 
     47       1.1    jruoho 
     48       1.1    jruoho #define _COMPONENT          ACPI_UTILITIES
     49       1.1    jruoho         ACPI_MODULE_NAME    ("utosi")
     50       1.1    jruoho 
     51   1.1.1.3  christos 
     52   1.1.1.3  christos /******************************************************************************
     53   1.1.1.3  christos  *
     54   1.1.1.3  christos  * ACPICA policy for new _OSI strings:
     55   1.1.1.3  christos  *
     56   1.1.1.3  christos  * It is the stated policy of ACPICA that new _OSI strings will be integrated
     57   1.1.1.3  christos  * into this module as soon as possible after they are defined. It is strongly
     58   1.1.1.3  christos  * recommended that all ACPICA hosts mirror this policy and integrate any
     59   1.1.1.3  christos  * changes to this module as soon as possible. There are several historical
     60   1.1.1.3  christos  * reasons behind this policy:
     61   1.1.1.3  christos  *
     62   1.1.1.3  christos  * 1) New BIOSs tend to test only the case where the host responds TRUE to
     63   1.1.1.3  christos  *    the latest version of Windows, which would respond to the latest/newest
     64   1.1.1.3  christos  *    _OSI string. Not responding TRUE to the latest version of Windows will
     65   1.1.1.3  christos  *    risk executing untested code paths throughout the DSDT and SSDTs.
     66   1.1.1.3  christos  *
     67   1.1.1.3  christos  * 2) If a new _OSI string is recognized only after a significant delay, this
     68   1.1.1.3  christos  *    has the potential to cause problems on existing working machines because
     69   1.1.1.3  christos  *    of the possibility that a new and different path through the ASL code
     70   1.1.1.3  christos  *    will be executed.
     71   1.1.1.3  christos  *
     72   1.1.1.3  christos  * 3) New _OSI strings are tending to come out about once per year. A delay
     73   1.1.1.3  christos  *    in recognizing a new string for a significant amount of time risks the
     74   1.1.1.3  christos  *    release of another string which only compounds the initial problem.
     75   1.1.1.3  christos  *
     76   1.1.1.3  christos  *****************************************************************************/
     77   1.1.1.3  christos 
     78   1.1.1.3  christos 
     79       1.1    jruoho /*
     80       1.1    jruoho  * Strings supported by the _OSI predefined control method (which is
     81       1.1    jruoho  * implemented internally within this module.)
     82       1.1    jruoho  *
     83       1.1    jruoho  * March 2009: Removed "Linux" as this host no longer wants to respond true
     84       1.1    jruoho  * for this string. Basically, the only safe OS strings are windows-related
     85       1.1    jruoho  * and in many or most cases represent the only test path within the
     86       1.1    jruoho  * BIOS-provided ASL code.
     87       1.1    jruoho  *
     88       1.1    jruoho  * The last element of each entry is used to track the newest version of
     89       1.1    jruoho  * Windows that the BIOS has requested.
     90       1.1    jruoho  */
     91       1.1    jruoho static ACPI_INTERFACE_INFO    AcpiDefaultSupportedInterfaces[] =
     92       1.1    jruoho {
     93       1.1    jruoho     /* Operating System Vendor Strings */
     94       1.1    jruoho 
     95       1.1    jruoho     {"Windows 2000",        NULL, 0, ACPI_OSI_WIN_2000},         /* Windows 2000 */
     96       1.1    jruoho     {"Windows 2001",        NULL, 0, ACPI_OSI_WIN_XP},           /* Windows XP */
     97       1.1    jruoho     {"Windows 2001 SP1",    NULL, 0, ACPI_OSI_WIN_XP_SP1},       /* Windows XP SP1 */
     98       1.1    jruoho     {"Windows 2001.1",      NULL, 0, ACPI_OSI_WINSRV_2003},      /* Windows Server 2003 */
     99       1.1    jruoho     {"Windows 2001 SP2",    NULL, 0, ACPI_OSI_WIN_XP_SP2},       /* Windows XP SP2 */
    100       1.1    jruoho     {"Windows 2001.1 SP1",  NULL, 0, ACPI_OSI_WINSRV_2003_SP1},  /* Windows Server 2003 SP1 - Added 03/2006 */
    101       1.1    jruoho     {"Windows 2006",        NULL, 0, ACPI_OSI_WIN_VISTA},        /* Windows Vista - Added 03/2006 */
    102       1.1    jruoho     {"Windows 2006.1",      NULL, 0, ACPI_OSI_WINSRV_2008},      /* Windows Server 2008 - Added 09/2009 */
    103       1.1    jruoho     {"Windows 2006 SP1",    NULL, 0, ACPI_OSI_WIN_VISTA_SP1},    /* Windows Vista SP1 - Added 09/2009 */
    104       1.1    jruoho     {"Windows 2006 SP2",    NULL, 0, ACPI_OSI_WIN_VISTA_SP2},    /* Windows Vista SP2 - Added 09/2010 */
    105       1.1    jruoho     {"Windows 2009",        NULL, 0, ACPI_OSI_WIN_7},            /* Windows 7 and Server 2008 R2 - Added 09/2009 */
    106   1.1.1.2  christos     {"Windows 2012",        NULL, 0, ACPI_OSI_WIN_8},            /* Windows 8 and Server 2012 - Added 08/2012 */
    107  1.1.1.12  christos     {"Windows 2013",        NULL, 0, ACPI_OSI_WIN_8_1},          /* Windows 8.1 and Server 2012 R2 - Added 01/2014 */
    108   1.1.1.4  christos     {"Windows 2015",        NULL, 0, ACPI_OSI_WIN_10},           /* Windows 10 - Added 03/2015 */
    109   1.1.1.9  christos     {"Windows 2016",        NULL, 0, ACPI_OSI_WIN_10_RS1},       /* Windows 10 version 1607 - Added 12/2017 */
    110   1.1.1.9  christos     {"Windows 2017",        NULL, 0, ACPI_OSI_WIN_10_RS2},       /* Windows 10 version 1703 - Added 12/2017 */
    111   1.1.1.9  christos     {"Windows 2017.2",      NULL, 0, ACPI_OSI_WIN_10_RS3},       /* Windows 10 version 1709 - Added 02/2018 */
    112  1.1.1.10  christos     {"Windows 2018",        NULL, 0, ACPI_OSI_WIN_10_RS4},       /* Windows 10 version 1803 - Added 11/2018 */
    113  1.1.1.10  christos     {"Windows 2018.2",      NULL, 0, ACPI_OSI_WIN_10_RS5},       /* Windows 10 version 1809 - Added 11/2018 */
    114  1.1.1.12  christos     {"Windows 2019",        NULL, 0, ACPI_OSI_WIN_10_19H1},      /* Windows 10 version 1903 - Added 08/2019 */
    115  1.1.1.15  christos     {"Windows 2020",        NULL, 0, ACPI_OSI_WIN_10_20H1},      /* Windows 10 version 2004 - Added 08/2021 */
    116  1.1.1.16  christos     {"Windows 2021",        NULL, 0, ACPI_OSI_WIN_11},           /* Windows 11 - Added 01/2022 */
    117  1.1.1.18  christos     {"Windows 2022",        NULL, 0, ACPI_OSI_WIN_11_22H2},      /* Windows 11 version 22H2 - Added 04/2024 */
    118       1.1    jruoho 
    119       1.1    jruoho     /* Feature Group Strings */
    120       1.1    jruoho 
    121   1.1.1.2  christos     {"Extended Address Space Descriptor", NULL, ACPI_OSI_FEATURE, 0},
    122       1.1    jruoho 
    123       1.1    jruoho     /*
    124       1.1    jruoho      * All "optional" feature group strings (features that are implemented
    125   1.1.1.2  christos      * by the host) should be dynamically modified to VALID by the host via
    126   1.1.1.2  christos      * AcpiInstallInterface or AcpiUpdateInterfaces. Such optional feature
    127   1.1.1.2  christos      * group strings are set as INVALID by default here.
    128       1.1    jruoho      */
    129   1.1.1.2  christos 
    130   1.1.1.2  christos     {"Module Device",               NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
    131   1.1.1.2  christos     {"Processor Device",            NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
    132   1.1.1.2  christos     {"3.0 Thermal Model",           NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
    133   1.1.1.2  christos     {"3.0 _SCP Extensions",         NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
    134   1.1.1.2  christos     {"Processor Aggregator Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}
    135       1.1    jruoho };
    136       1.1    jruoho 
    137       1.1    jruoho 
    138       1.1    jruoho /*******************************************************************************
    139       1.1    jruoho  *
    140       1.1    jruoho  * FUNCTION:    AcpiUtInitializeInterfaces
    141       1.1    jruoho  *
    142       1.1    jruoho  * PARAMETERS:  None
    143       1.1    jruoho  *
    144       1.1    jruoho  * RETURN:      Status
    145       1.1    jruoho  *
    146       1.1    jruoho  * DESCRIPTION: Initialize the global _OSI supported interfaces list
    147       1.1    jruoho  *
    148       1.1    jruoho  ******************************************************************************/
    149       1.1    jruoho 
    150       1.1    jruoho ACPI_STATUS
    151       1.1    jruoho AcpiUtInitializeInterfaces (
    152       1.1    jruoho     void)
    153       1.1    jruoho {
    154   1.1.1.2  christos     ACPI_STATUS             Status;
    155       1.1    jruoho     UINT32                  i;
    156       1.1    jruoho 
    157       1.1    jruoho 
    158   1.1.1.2  christos     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    159   1.1.1.2  christos     if (ACPI_FAILURE (Status))
    160   1.1.1.2  christos     {
    161   1.1.1.2  christos         return (Status);
    162   1.1.1.2  christos     }
    163   1.1.1.2  christos 
    164       1.1    jruoho     AcpiGbl_SupportedInterfaces = AcpiDefaultSupportedInterfaces;
    165       1.1    jruoho 
    166       1.1    jruoho     /* Link the static list of supported interfaces */
    167       1.1    jruoho 
    168   1.1.1.6  christos     for (i = 0;
    169   1.1.1.6  christos         i < (ACPI_ARRAY_LENGTH (AcpiDefaultSupportedInterfaces) - 1);
    170   1.1.1.6  christos         i++)
    171       1.1    jruoho     {
    172       1.1    jruoho         AcpiDefaultSupportedInterfaces[i].Next =
    173       1.1    jruoho             &AcpiDefaultSupportedInterfaces[(ACPI_SIZE) i + 1];
    174       1.1    jruoho     }
    175       1.1    jruoho 
    176       1.1    jruoho     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    177       1.1    jruoho     return (AE_OK);
    178       1.1    jruoho }
    179       1.1    jruoho 
    180       1.1    jruoho 
    181       1.1    jruoho /*******************************************************************************
    182       1.1    jruoho  *
    183       1.1    jruoho  * FUNCTION:    AcpiUtInterfaceTerminate
    184       1.1    jruoho  *
    185       1.1    jruoho  * PARAMETERS:  None
    186       1.1    jruoho  *
    187   1.1.1.2  christos  * RETURN:      Status
    188       1.1    jruoho  *
    189       1.1    jruoho  * DESCRIPTION: Delete all interfaces in the global list. Sets
    190       1.1    jruoho  *              AcpiGbl_SupportedInterfaces to NULL.
    191       1.1    jruoho  *
    192       1.1    jruoho  ******************************************************************************/
    193       1.1    jruoho 
    194   1.1.1.2  christos ACPI_STATUS
    195       1.1    jruoho AcpiUtInterfaceTerminate (
    196       1.1    jruoho     void)
    197       1.1    jruoho {
    198   1.1.1.2  christos     ACPI_STATUS             Status;
    199       1.1    jruoho     ACPI_INTERFACE_INFO     *NextInterface;
    200       1.1    jruoho 
    201       1.1    jruoho 
    202   1.1.1.2  christos     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    203   1.1.1.2  christos     if (ACPI_FAILURE (Status))
    204   1.1.1.2  christos     {
    205   1.1.1.2  christos         return (Status);
    206   1.1.1.2  christos     }
    207       1.1    jruoho 
    208   1.1.1.2  christos     NextInterface = AcpiGbl_SupportedInterfaces;
    209       1.1    jruoho     while (NextInterface)
    210       1.1    jruoho     {
    211       1.1    jruoho         AcpiGbl_SupportedInterfaces = NextInterface->Next;
    212       1.1    jruoho 
    213       1.1    jruoho         if (NextInterface->Flags & ACPI_OSI_DYNAMIC)
    214       1.1    jruoho         {
    215   1.1.1.2  christos             /* Only interfaces added at runtime can be freed */
    216   1.1.1.2  christos 
    217       1.1    jruoho             ACPI_FREE (NextInterface->Name);
    218       1.1    jruoho             ACPI_FREE (NextInterface);
    219       1.1    jruoho         }
    220   1.1.1.2  christos         else
    221   1.1.1.2  christos         {
    222   1.1.1.2  christos             /* Interface is in static list. Reset it to invalid or valid. */
    223   1.1.1.2  christos 
    224   1.1.1.2  christos             if (NextInterface->Flags & ACPI_OSI_DEFAULT_INVALID)
    225   1.1.1.2  christos             {
    226   1.1.1.2  christos                 NextInterface->Flags |= ACPI_OSI_INVALID;
    227   1.1.1.2  christos             }
    228   1.1.1.2  christos             else
    229   1.1.1.2  christos             {
    230   1.1.1.2  christos                 NextInterface->Flags &= ~ACPI_OSI_INVALID;
    231   1.1.1.2  christos             }
    232   1.1.1.2  christos         }
    233       1.1    jruoho 
    234       1.1    jruoho         NextInterface = AcpiGbl_SupportedInterfaces;
    235       1.1    jruoho     }
    236       1.1    jruoho 
    237       1.1    jruoho     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    238   1.1.1.2  christos     return (AE_OK);
    239       1.1    jruoho }
    240       1.1    jruoho 
    241       1.1    jruoho 
    242       1.1    jruoho /*******************************************************************************
    243       1.1    jruoho  *
    244       1.1    jruoho  * FUNCTION:    AcpiUtInstallInterface
    245       1.1    jruoho  *
    246       1.1    jruoho  * PARAMETERS:  InterfaceName       - The interface to install
    247       1.1    jruoho  *
    248       1.1    jruoho  * RETURN:      Status
    249       1.1    jruoho  *
    250       1.1    jruoho  * DESCRIPTION: Install the interface into the global interface list.
    251       1.1    jruoho  *              Caller MUST hold AcpiGbl_OsiMutex
    252       1.1    jruoho  *
    253       1.1    jruoho  ******************************************************************************/
    254       1.1    jruoho 
    255       1.1    jruoho ACPI_STATUS
    256       1.1    jruoho AcpiUtInstallInterface (
    257       1.1    jruoho     ACPI_STRING             InterfaceName)
    258       1.1    jruoho {
    259       1.1    jruoho     ACPI_INTERFACE_INFO     *InterfaceInfo;
    260       1.1    jruoho 
    261       1.1    jruoho 
    262       1.1    jruoho     /* Allocate info block and space for the name string */
    263       1.1    jruoho 
    264       1.1    jruoho     InterfaceInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_INTERFACE_INFO));
    265       1.1    jruoho     if (!InterfaceInfo)
    266       1.1    jruoho     {
    267       1.1    jruoho         return (AE_NO_MEMORY);
    268       1.1    jruoho     }
    269       1.1    jruoho 
    270   1.1.1.5  christos     InterfaceInfo->Name = ACPI_ALLOCATE_ZEROED (strlen (InterfaceName) + 1);
    271       1.1    jruoho     if (!InterfaceInfo->Name)
    272       1.1    jruoho     {
    273       1.1    jruoho         ACPI_FREE (InterfaceInfo);
    274       1.1    jruoho         return (AE_NO_MEMORY);
    275       1.1    jruoho     }
    276       1.1    jruoho 
    277       1.1    jruoho     /* Initialize new info and insert at the head of the global list */
    278       1.1    jruoho 
    279   1.1.1.5  christos     strcpy (InterfaceInfo->Name, InterfaceName);
    280       1.1    jruoho     InterfaceInfo->Flags = ACPI_OSI_DYNAMIC;
    281       1.1    jruoho     InterfaceInfo->Next = AcpiGbl_SupportedInterfaces;
    282       1.1    jruoho 
    283       1.1    jruoho     AcpiGbl_SupportedInterfaces = InterfaceInfo;
    284       1.1    jruoho     return (AE_OK);
    285       1.1    jruoho }
    286       1.1    jruoho 
    287       1.1    jruoho 
    288       1.1    jruoho /*******************************************************************************
    289       1.1    jruoho  *
    290       1.1    jruoho  * FUNCTION:    AcpiUtRemoveInterface
    291       1.1    jruoho  *
    292       1.1    jruoho  * PARAMETERS:  InterfaceName       - The interface to remove
    293       1.1    jruoho  *
    294       1.1    jruoho  * RETURN:      Status
    295       1.1    jruoho  *
    296       1.1    jruoho  * DESCRIPTION: Remove the interface from the global interface list.
    297       1.1    jruoho  *              Caller MUST hold AcpiGbl_OsiMutex
    298       1.1    jruoho  *
    299       1.1    jruoho  ******************************************************************************/
    300       1.1    jruoho 
    301       1.1    jruoho ACPI_STATUS
    302       1.1    jruoho AcpiUtRemoveInterface (
    303       1.1    jruoho     ACPI_STRING             InterfaceName)
    304       1.1    jruoho {
    305       1.1    jruoho     ACPI_INTERFACE_INFO     *PreviousInterface;
    306       1.1    jruoho     ACPI_INTERFACE_INFO     *NextInterface;
    307       1.1    jruoho 
    308       1.1    jruoho 
    309       1.1    jruoho     PreviousInterface = NextInterface = AcpiGbl_SupportedInterfaces;
    310       1.1    jruoho     while (NextInterface)
    311       1.1    jruoho     {
    312   1.1.1.5  christos         if (!strcmp (InterfaceName, NextInterface->Name))
    313       1.1    jruoho         {
    314   1.1.1.6  christos             /*
    315   1.1.1.6  christos              * Found: name is in either the static list
    316   1.1.1.6  christos              * or was added at runtime
    317   1.1.1.6  christos              */
    318       1.1    jruoho             if (NextInterface->Flags & ACPI_OSI_DYNAMIC)
    319       1.1    jruoho             {
    320       1.1    jruoho                 /* Interface was added dynamically, remove and free it */
    321       1.1    jruoho 
    322       1.1    jruoho                 if (PreviousInterface == NextInterface)
    323       1.1    jruoho                 {
    324       1.1    jruoho                     AcpiGbl_SupportedInterfaces = NextInterface->Next;
    325       1.1    jruoho                 }
    326       1.1    jruoho                 else
    327       1.1    jruoho                 {
    328       1.1    jruoho                     PreviousInterface->Next = NextInterface->Next;
    329       1.1    jruoho                 }
    330       1.1    jruoho 
    331       1.1    jruoho                 ACPI_FREE (NextInterface->Name);
    332       1.1    jruoho                 ACPI_FREE (NextInterface);
    333       1.1    jruoho             }
    334       1.1    jruoho             else
    335       1.1    jruoho             {
    336       1.1    jruoho                 /*
    337   1.1.1.6  christos                  * Interface is in static list. If marked invalid, then
    338   1.1.1.6  christos                  * it does not actually exist. Else, mark it invalid.
    339       1.1    jruoho                  */
    340       1.1    jruoho                 if (NextInterface->Flags & ACPI_OSI_INVALID)
    341       1.1    jruoho                 {
    342       1.1    jruoho                     return (AE_NOT_EXIST);
    343       1.1    jruoho                 }
    344       1.1    jruoho 
    345       1.1    jruoho                 NextInterface->Flags |= ACPI_OSI_INVALID;
    346       1.1    jruoho             }
    347       1.1    jruoho 
    348       1.1    jruoho             return (AE_OK);
    349       1.1    jruoho         }
    350       1.1    jruoho 
    351       1.1    jruoho         PreviousInterface = NextInterface;
    352       1.1    jruoho         NextInterface = NextInterface->Next;
    353       1.1    jruoho     }
    354       1.1    jruoho 
    355       1.1    jruoho     /* Interface was not found */
    356       1.1    jruoho 
    357       1.1    jruoho     return (AE_NOT_EXIST);
    358       1.1    jruoho }
    359       1.1    jruoho 
    360       1.1    jruoho 
    361       1.1    jruoho /*******************************************************************************
    362       1.1    jruoho  *
    363   1.1.1.2  christos  * FUNCTION:    AcpiUtUpdateInterfaces
    364   1.1.1.2  christos  *
    365   1.1.1.2  christos  * PARAMETERS:  Action              - Actions to be performed during the
    366   1.1.1.2  christos  *                                    update
    367   1.1.1.2  christos  *
    368   1.1.1.2  christos  * RETURN:      Status
    369   1.1.1.2  christos  *
    370   1.1.1.2  christos  * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
    371   1.1.1.2  christos  *              strings or/and feature group strings.
    372   1.1.1.2  christos  *              Caller MUST hold AcpiGbl_OsiMutex
    373   1.1.1.2  christos  *
    374   1.1.1.2  christos  ******************************************************************************/
    375   1.1.1.2  christos 
    376   1.1.1.2  christos ACPI_STATUS
    377   1.1.1.2  christos AcpiUtUpdateInterfaces (
    378   1.1.1.2  christos     UINT8                   Action)
    379   1.1.1.2  christos {
    380   1.1.1.2  christos     ACPI_INTERFACE_INFO     *NextInterface;
    381   1.1.1.2  christos 
    382   1.1.1.2  christos 
    383   1.1.1.2  christos     NextInterface = AcpiGbl_SupportedInterfaces;
    384   1.1.1.2  christos     while (NextInterface)
    385   1.1.1.2  christos     {
    386   1.1.1.2  christos         if (((NextInterface->Flags & ACPI_OSI_FEATURE) &&
    387   1.1.1.2  christos              (Action & ACPI_FEATURE_STRINGS)) ||
    388   1.1.1.2  christos             (!(NextInterface->Flags & ACPI_OSI_FEATURE) &&
    389   1.1.1.2  christos              (Action & ACPI_VENDOR_STRINGS)))
    390   1.1.1.2  christos         {
    391   1.1.1.2  christos             if (Action & ACPI_DISABLE_INTERFACES)
    392   1.1.1.2  christos             {
    393   1.1.1.2  christos                 /* Mark the interfaces as invalid */
    394   1.1.1.2  christos 
    395   1.1.1.2  christos                 NextInterface->Flags |= ACPI_OSI_INVALID;
    396   1.1.1.2  christos             }
    397   1.1.1.2  christos             else
    398   1.1.1.2  christos             {
    399   1.1.1.2  christos                 /* Mark the interfaces as valid */
    400   1.1.1.2  christos 
    401   1.1.1.2  christos                 NextInterface->Flags &= ~ACPI_OSI_INVALID;
    402   1.1.1.2  christos             }
    403   1.1.1.2  christos         }
    404   1.1.1.2  christos 
    405   1.1.1.2  christos         NextInterface = NextInterface->Next;
    406   1.1.1.2  christos     }
    407   1.1.1.2  christos 
    408   1.1.1.2  christos     return (AE_OK);
    409   1.1.1.2  christos }
    410   1.1.1.2  christos 
    411   1.1.1.2  christos 
    412   1.1.1.2  christos /*******************************************************************************
    413   1.1.1.2  christos  *
    414       1.1    jruoho  * FUNCTION:    AcpiUtGetInterface
    415       1.1    jruoho  *
    416       1.1    jruoho  * PARAMETERS:  InterfaceName       - The interface to find
    417       1.1    jruoho  *
    418       1.1    jruoho  * RETURN:      ACPI_INTERFACE_INFO if found. NULL if not found.
    419       1.1    jruoho  *
    420       1.1    jruoho  * DESCRIPTION: Search for the specified interface name in the global list.
    421       1.1    jruoho  *              Caller MUST hold AcpiGbl_OsiMutex
    422       1.1    jruoho  *
    423       1.1    jruoho  ******************************************************************************/
    424       1.1    jruoho 
    425       1.1    jruoho ACPI_INTERFACE_INFO *
    426       1.1    jruoho AcpiUtGetInterface (
    427       1.1    jruoho     ACPI_STRING             InterfaceName)
    428       1.1    jruoho {
    429       1.1    jruoho     ACPI_INTERFACE_INFO     *NextInterface;
    430       1.1    jruoho 
    431       1.1    jruoho 
    432       1.1    jruoho     NextInterface = AcpiGbl_SupportedInterfaces;
    433       1.1    jruoho     while (NextInterface)
    434       1.1    jruoho     {
    435   1.1.1.5  christos         if (!strcmp (InterfaceName, NextInterface->Name))
    436       1.1    jruoho         {
    437       1.1    jruoho             return (NextInterface);
    438       1.1    jruoho         }
    439       1.1    jruoho 
    440       1.1    jruoho         NextInterface = NextInterface->Next;
    441       1.1    jruoho     }
    442       1.1    jruoho 
    443       1.1    jruoho     return (NULL);
    444       1.1    jruoho }
    445       1.1    jruoho 
    446       1.1    jruoho 
    447       1.1    jruoho /*******************************************************************************
    448       1.1    jruoho  *
    449       1.1    jruoho  * FUNCTION:    AcpiUtOsiImplementation
    450       1.1    jruoho  *
    451       1.1    jruoho  * PARAMETERS:  WalkState           - Current walk state
    452       1.1    jruoho  *
    453       1.1    jruoho  * RETURN:      Status
    454   1.1.1.7  christos  *              Integer: TRUE (0) if input string is matched
    455   1.1.1.7  christos  *                       FALSE (-1) if string is not matched
    456       1.1    jruoho  *
    457       1.1    jruoho  * DESCRIPTION: Implementation of the _OSI predefined control method. When
    458       1.1    jruoho  *              an invocation of _OSI is encountered in the system AML,
    459       1.1    jruoho  *              control is transferred to this function.
    460       1.1    jruoho  *
    461   1.1.1.7  christos  * (August 2016)
    462   1.1.1.7  christos  * Note:  _OSI is now defined to return "Ones" to indicate a match, for
    463   1.1.1.7  christos  * compatibility with other ACPI implementations. On a 32-bit DSDT, Ones
    464   1.1.1.7  christos  * is 0xFFFFFFFF. On a 64-bit DSDT, Ones is 0xFFFFFFFFFFFFFFFF
    465   1.1.1.7  christos  * (ACPI_UINT64_MAX).
    466   1.1.1.7  christos  *
    467   1.1.1.7  christos  * This function always returns ACPI_UINT64_MAX for TRUE, and later code
    468   1.1.1.7  christos  * will truncate this to 32 bits if necessary.
    469   1.1.1.7  christos  *
    470       1.1    jruoho  ******************************************************************************/
    471       1.1    jruoho 
    472       1.1    jruoho ACPI_STATUS
    473       1.1    jruoho AcpiUtOsiImplementation (
    474       1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    475       1.1    jruoho {
    476       1.1    jruoho     ACPI_OPERAND_OBJECT     *StringDesc;
    477       1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc;
    478       1.1    jruoho     ACPI_INTERFACE_INFO     *InterfaceInfo;
    479       1.1    jruoho     ACPI_INTERFACE_HANDLER  InterfaceHandler;
    480   1.1.1.2  christos     ACPI_STATUS             Status;
    481   1.1.1.7  christos     UINT64                  ReturnValue;
    482       1.1    jruoho 
    483       1.1    jruoho 
    484       1.1    jruoho     ACPI_FUNCTION_TRACE (UtOsiImplementation);
    485       1.1    jruoho 
    486       1.1    jruoho 
    487       1.1    jruoho     /* Validate the string input argument (from the AML caller) */
    488       1.1    jruoho 
    489       1.1    jruoho     StringDesc = WalkState->Arguments[0].Object;
    490       1.1    jruoho     if (!StringDesc ||
    491       1.1    jruoho         (StringDesc->Common.Type != ACPI_TYPE_STRING))
    492       1.1    jruoho     {
    493       1.1    jruoho         return_ACPI_STATUS (AE_TYPE);
    494       1.1    jruoho     }
    495       1.1    jruoho 
    496       1.1    jruoho     /* Create a return object */
    497       1.1    jruoho 
    498       1.1    jruoho     ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
    499       1.1    jruoho     if (!ReturnDesc)
    500       1.1    jruoho     {
    501       1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    502       1.1    jruoho     }
    503       1.1    jruoho 
    504       1.1    jruoho     /* Default return value is 0, NOT SUPPORTED */
    505       1.1    jruoho 
    506       1.1    jruoho     ReturnValue = 0;
    507   1.1.1.2  christos     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    508   1.1.1.2  christos     if (ACPI_FAILURE (Status))
    509   1.1.1.2  christos     {
    510   1.1.1.2  christos         AcpiUtRemoveReference (ReturnDesc);
    511   1.1.1.2  christos         return_ACPI_STATUS (Status);
    512   1.1.1.2  christos     }
    513       1.1    jruoho 
    514       1.1    jruoho     /* Lookup the interface in the global _OSI list */
    515       1.1    jruoho 
    516       1.1    jruoho     InterfaceInfo = AcpiUtGetInterface (StringDesc->String.Pointer);
    517       1.1    jruoho     if (InterfaceInfo &&
    518       1.1    jruoho         !(InterfaceInfo->Flags & ACPI_OSI_INVALID))
    519       1.1    jruoho     {
    520       1.1    jruoho         /*
    521       1.1    jruoho          * The interface is supported.
    522       1.1    jruoho          * Update the OsiData if necessary. We keep track of the latest
    523       1.1    jruoho          * version of Windows that has been requested by the BIOS.
    524       1.1    jruoho          */
    525       1.1    jruoho         if (InterfaceInfo->Value > AcpiGbl_OsiData)
    526       1.1    jruoho         {
    527       1.1    jruoho             AcpiGbl_OsiData = InterfaceInfo->Value;
    528       1.1    jruoho         }
    529       1.1    jruoho 
    530   1.1.1.7  christos         ReturnValue = ACPI_UINT64_MAX;
    531       1.1    jruoho     }
    532       1.1    jruoho 
    533       1.1    jruoho     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    534       1.1    jruoho 
    535       1.1    jruoho     /*
    536       1.1    jruoho      * Invoke an optional _OSI interface handler. The host OS may wish
    537       1.1    jruoho      * to do some interface-specific handling. For example, warn about
    538       1.1    jruoho      * certain interfaces or override the true/false support value.
    539       1.1    jruoho      */
    540       1.1    jruoho     InterfaceHandler = AcpiGbl_InterfaceHandler;
    541       1.1    jruoho     if (InterfaceHandler)
    542       1.1    jruoho     {
    543   1.1.1.7  christos         if (InterfaceHandler (
    544   1.1.1.7  christos             StringDesc->String.Pointer, (UINT32) ReturnValue))
    545   1.1.1.7  christos         {
    546   1.1.1.7  christos             ReturnValue = ACPI_UINT64_MAX;
    547   1.1.1.7  christos         }
    548       1.1    jruoho     }
    549       1.1    jruoho 
    550       1.1    jruoho     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
    551       1.1    jruoho         "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
    552       1.1    jruoho         StringDesc->String.Pointer, ReturnValue == 0 ? "not " : ""));
    553       1.1    jruoho 
    554       1.1    jruoho     /* Complete the return object */
    555       1.1    jruoho 
    556       1.1    jruoho     ReturnDesc->Integer.Value = ReturnValue;
    557       1.1    jruoho     WalkState->ReturnDesc = ReturnDesc;
    558       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    559       1.1    jruoho }
    560