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