Home | History | Annotate | Line # | Download | only in utilities
utosi.c revision 1.16
      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 
    116     /* Feature Group Strings */
    117 
    118     {"Extended Address Space Descriptor", NULL, ACPI_OSI_FEATURE, 0},
    119 
    120     /*
    121      * All "optional" feature group strings (features that are implemented
    122      * by the host) should be dynamically modified to VALID by the host via
    123      * AcpiInstallInterface or AcpiUpdateInterfaces. Such optional feature
    124      * group strings are set as INVALID by default here.
    125      */
    126 
    127     {"Module Device",               NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
    128     {"Processor Device",            NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
    129     {"3.0 Thermal Model",           NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
    130     {"3.0 _SCP Extensions",         NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
    131     {"Processor Aggregator Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}
    132 };
    133 
    134 
    135 /*******************************************************************************
    136  *
    137  * FUNCTION:    AcpiUtInitializeInterfaces
    138  *
    139  * PARAMETERS:  None
    140  *
    141  * RETURN:      Status
    142  *
    143  * DESCRIPTION: Initialize the global _OSI supported interfaces list
    144  *
    145  ******************************************************************************/
    146 
    147 ACPI_STATUS
    148 AcpiUtInitializeInterfaces (
    149     void)
    150 {
    151     ACPI_STATUS             Status;
    152     UINT32                  i;
    153 
    154 
    155     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    156     if (ACPI_FAILURE (Status))
    157     {
    158         return (Status);
    159     }
    160 
    161     AcpiGbl_SupportedInterfaces = AcpiDefaultSupportedInterfaces;
    162 
    163     /* Link the static list of supported interfaces */
    164 
    165     for (i = 0;
    166         i < (ACPI_ARRAY_LENGTH (AcpiDefaultSupportedInterfaces) - 1);
    167         i++)
    168     {
    169         AcpiDefaultSupportedInterfaces[i].Next =
    170             &AcpiDefaultSupportedInterfaces[(ACPI_SIZE) i + 1];
    171     }
    172 
    173     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    174     return (AE_OK);
    175 }
    176 
    177 
    178 /*******************************************************************************
    179  *
    180  * FUNCTION:    AcpiUtInterfaceTerminate
    181  *
    182  * PARAMETERS:  None
    183  *
    184  * RETURN:      Status
    185  *
    186  * DESCRIPTION: Delete all interfaces in the global list. Sets
    187  *              AcpiGbl_SupportedInterfaces to NULL.
    188  *
    189  ******************************************************************************/
    190 
    191 ACPI_STATUS
    192 AcpiUtInterfaceTerminate (
    193     void)
    194 {
    195     ACPI_STATUS             Status;
    196     ACPI_INTERFACE_INFO     *NextInterface;
    197 
    198 
    199     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    200     if (ACPI_FAILURE (Status))
    201     {
    202         return (Status);
    203     }
    204 
    205     NextInterface = AcpiGbl_SupportedInterfaces;
    206     while (NextInterface)
    207     {
    208         AcpiGbl_SupportedInterfaces = NextInterface->Next;
    209 
    210         if (NextInterface->Flags & ACPI_OSI_DYNAMIC)
    211         {
    212             /* Only interfaces added at runtime can be freed */
    213 
    214             ACPI_FREE (__UNCONST(NextInterface->Name));
    215             ACPI_FREE (NextInterface);
    216         }
    217         else
    218         {
    219             /* Interface is in static list. Reset it to invalid or valid. */
    220 
    221             if (NextInterface->Flags & ACPI_OSI_DEFAULT_INVALID)
    222             {
    223                 NextInterface->Flags |= ACPI_OSI_INVALID;
    224             }
    225             else
    226             {
    227                 NextInterface->Flags &= ~ACPI_OSI_INVALID;
    228             }
    229         }
    230 
    231         NextInterface = AcpiGbl_SupportedInterfaces;
    232     }
    233 
    234     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    235     return (AE_OK);
    236 }
    237 
    238 
    239 /*******************************************************************************
    240  *
    241  * FUNCTION:    AcpiUtInstallInterface
    242  *
    243  * PARAMETERS:  InterfaceName       - The interface to install
    244  *
    245  * RETURN:      Status
    246  *
    247  * DESCRIPTION: Install the interface into the global interface list.
    248  *              Caller MUST hold AcpiGbl_OsiMutex
    249  *
    250  ******************************************************************************/
    251 
    252 ACPI_STATUS
    253 AcpiUtInstallInterface (
    254     ACPI_STRING             InterfaceName)
    255 {
    256     ACPI_INTERFACE_INFO     *InterfaceInfo;
    257 
    258 
    259     /* Allocate info block and space for the name string */
    260 
    261     InterfaceInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_INTERFACE_INFO));
    262     if (!InterfaceInfo)
    263     {
    264         return (AE_NO_MEMORY);
    265     }
    266 
    267     InterfaceInfo->Name = ACPI_ALLOCATE_ZEROED (strlen (InterfaceName) + 1);
    268     if (!InterfaceInfo->Name)
    269     {
    270         ACPI_FREE (InterfaceInfo);
    271         return (AE_NO_MEMORY);
    272     }
    273 
    274     /* Initialize new info and insert at the head of the global list */
    275 
    276     strcpy (__UNCONST(InterfaceInfo->Name), InterfaceName);
    277     InterfaceInfo->Flags = ACPI_OSI_DYNAMIC;
    278     InterfaceInfo->Next = AcpiGbl_SupportedInterfaces;
    279 
    280     AcpiGbl_SupportedInterfaces = InterfaceInfo;
    281     return (AE_OK);
    282 }
    283 
    284 
    285 /*******************************************************************************
    286  *
    287  * FUNCTION:    AcpiUtRemoveInterface
    288  *
    289  * PARAMETERS:  InterfaceName       - The interface to remove
    290  *
    291  * RETURN:      Status
    292  *
    293  * DESCRIPTION: Remove the interface from the global interface list.
    294  *              Caller MUST hold AcpiGbl_OsiMutex
    295  *
    296  ******************************************************************************/
    297 
    298 ACPI_STATUS
    299 AcpiUtRemoveInterface (
    300     ACPI_STRING             InterfaceName)
    301 {
    302     ACPI_INTERFACE_INFO     *PreviousInterface;
    303     ACPI_INTERFACE_INFO     *NextInterface;
    304 
    305 
    306     PreviousInterface = NextInterface = AcpiGbl_SupportedInterfaces;
    307     while (NextInterface)
    308     {
    309         if (!strcmp (InterfaceName, NextInterface->Name))
    310         {
    311             /*
    312              * Found: name is in either the static list
    313              * or was added at runtime
    314              */
    315             if (NextInterface->Flags & ACPI_OSI_DYNAMIC)
    316             {
    317                 /* Interface was added dynamically, remove and free it */
    318 
    319                 if (PreviousInterface == NextInterface)
    320                 {
    321                     AcpiGbl_SupportedInterfaces = NextInterface->Next;
    322                 }
    323                 else
    324                 {
    325                     PreviousInterface->Next = NextInterface->Next;
    326                 }
    327 
    328                 ACPI_FREE (__UNCONST(NextInterface->Name));
    329                 ACPI_FREE (NextInterface);
    330             }
    331             else
    332             {
    333                 /*
    334                  * Interface is in static list. If marked invalid, then
    335                  * it does not actually exist. Else, mark it invalid.
    336                  */
    337                 if (NextInterface->Flags & ACPI_OSI_INVALID)
    338                 {
    339                     return (AE_NOT_EXIST);
    340                 }
    341 
    342                 NextInterface->Flags |= ACPI_OSI_INVALID;
    343             }
    344 
    345             return (AE_OK);
    346         }
    347 
    348         PreviousInterface = NextInterface;
    349         NextInterface = NextInterface->Next;
    350     }
    351 
    352     /* Interface was not found */
    353 
    354     return (AE_NOT_EXIST);
    355 }
    356 
    357 
    358 /*******************************************************************************
    359  *
    360  * FUNCTION:    AcpiUtUpdateInterfaces
    361  *
    362  * PARAMETERS:  Action              - Actions to be performed during the
    363  *                                    update
    364  *
    365  * RETURN:      Status
    366  *
    367  * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
    368  *              strings or/and feature group strings.
    369  *              Caller MUST hold AcpiGbl_OsiMutex
    370  *
    371  ******************************************************************************/
    372 
    373 ACPI_STATUS
    374 AcpiUtUpdateInterfaces (
    375     UINT8                   Action)
    376 {
    377     ACPI_INTERFACE_INFO     *NextInterface;
    378 
    379 
    380     NextInterface = AcpiGbl_SupportedInterfaces;
    381     while (NextInterface)
    382     {
    383         if (((NextInterface->Flags & ACPI_OSI_FEATURE) &&
    384              (Action & ACPI_FEATURE_STRINGS)) ||
    385             (!(NextInterface->Flags & ACPI_OSI_FEATURE) &&
    386              (Action & ACPI_VENDOR_STRINGS)))
    387         {
    388             if (Action & ACPI_DISABLE_INTERFACES)
    389             {
    390                 /* Mark the interfaces as invalid */
    391 
    392                 NextInterface->Flags |= ACPI_OSI_INVALID;
    393             }
    394             else
    395             {
    396                 /* Mark the interfaces as valid */
    397 
    398                 NextInterface->Flags &= ~ACPI_OSI_INVALID;
    399             }
    400         }
    401 
    402         NextInterface = NextInterface->Next;
    403     }
    404 
    405     return (AE_OK);
    406 }
    407 
    408 
    409 /*******************************************************************************
    410  *
    411  * FUNCTION:    AcpiUtGetInterface
    412  *
    413  * PARAMETERS:  InterfaceName       - The interface to find
    414  *
    415  * RETURN:      ACPI_INTERFACE_INFO if found. NULL if not found.
    416  *
    417  * DESCRIPTION: Search for the specified interface name in the global list.
    418  *              Caller MUST hold AcpiGbl_OsiMutex
    419  *
    420  ******************************************************************************/
    421 
    422 ACPI_INTERFACE_INFO *
    423 AcpiUtGetInterface (
    424     ACPI_STRING             InterfaceName)
    425 {
    426     ACPI_INTERFACE_INFO     *NextInterface;
    427 
    428 
    429     NextInterface = AcpiGbl_SupportedInterfaces;
    430     while (NextInterface)
    431     {
    432         if (!strcmp (InterfaceName, NextInterface->Name))
    433         {
    434             return (NextInterface);
    435         }
    436 
    437         NextInterface = NextInterface->Next;
    438     }
    439 
    440     return (NULL);
    441 }
    442 
    443 
    444 /*******************************************************************************
    445  *
    446  * FUNCTION:    AcpiUtOsiImplementation
    447  *
    448  * PARAMETERS:  WalkState           - Current walk state
    449  *
    450  * RETURN:      Status
    451  *              Integer: TRUE (0) if input string is matched
    452  *                       FALSE (-1) if string is not matched
    453  *
    454  * DESCRIPTION: Implementation of the _OSI predefined control method. When
    455  *              an invocation of _OSI is encountered in the system AML,
    456  *              control is transferred to this function.
    457  *
    458  * (August 2016)
    459  * Note:  _OSI is now defined to return "Ones" to indicate a match, for
    460  * compatibility with other ACPI implementations. On a 32-bit DSDT, Ones
    461  * is 0xFFFFFFFF. On a 64-bit DSDT, Ones is 0xFFFFFFFFFFFFFFFF
    462  * (ACPI_UINT64_MAX).
    463  *
    464  * This function always returns ACPI_UINT64_MAX for TRUE, and later code
    465  * will truncate this to 32 bits if necessary.
    466  *
    467  ******************************************************************************/
    468 
    469 ACPI_STATUS
    470 AcpiUtOsiImplementation (
    471     ACPI_WALK_STATE         *WalkState)
    472 {
    473     ACPI_OPERAND_OBJECT     *StringDesc;
    474     ACPI_OPERAND_OBJECT     *ReturnDesc;
    475     ACPI_INTERFACE_INFO     *InterfaceInfo;
    476     ACPI_INTERFACE_HANDLER  InterfaceHandler;
    477     ACPI_STATUS             Status;
    478     UINT64                  ReturnValue;
    479 
    480 
    481     ACPI_FUNCTION_TRACE (UtOsiImplementation);
    482 
    483 
    484     /* Validate the string input argument (from the AML caller) */
    485 
    486     StringDesc = WalkState->Arguments[0].Object;
    487     if (!StringDesc ||
    488         (StringDesc->Common.Type != ACPI_TYPE_STRING))
    489     {
    490         return_ACPI_STATUS (AE_TYPE);
    491     }
    492 
    493     /* Create a return object */
    494 
    495     ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
    496     if (!ReturnDesc)
    497     {
    498         return_ACPI_STATUS (AE_NO_MEMORY);
    499     }
    500 
    501     /* Default return value is 0, NOT SUPPORTED */
    502 
    503     ReturnValue = 0;
    504     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
    505     if (ACPI_FAILURE (Status))
    506     {
    507         AcpiUtRemoveReference (ReturnDesc);
    508         return_ACPI_STATUS (Status);
    509     }
    510 
    511     /* Lookup the interface in the global _OSI list */
    512 
    513     InterfaceInfo = AcpiUtGetInterface (StringDesc->String.Pointer);
    514     if (InterfaceInfo &&
    515         !(InterfaceInfo->Flags & ACPI_OSI_INVALID))
    516     {
    517         /*
    518          * The interface is supported.
    519          * Update the OsiData if necessary. We keep track of the latest
    520          * version of Windows that has been requested by the BIOS.
    521          */
    522         if (InterfaceInfo->Value > AcpiGbl_OsiData)
    523         {
    524             AcpiGbl_OsiData = InterfaceInfo->Value;
    525         }
    526 
    527         ReturnValue = ACPI_UINT64_MAX;
    528     }
    529 
    530     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
    531 
    532     /*
    533      * Invoke an optional _OSI interface handler. The host OS may wish
    534      * to do some interface-specific handling. For example, warn about
    535      * certain interfaces or override the true/false support value.
    536      */
    537     InterfaceHandler = AcpiGbl_InterfaceHandler;
    538     if (InterfaceHandler)
    539     {
    540         if (InterfaceHandler (
    541             StringDesc->String.Pointer, (UINT32) ReturnValue))
    542         {
    543             ReturnValue = ACPI_UINT64_MAX;
    544         }
    545     }
    546 
    547     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
    548         "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
    549         StringDesc->String.Pointer, ReturnValue == 0 ? "not " : ""));
    550 
    551     /* Complete the return object */
    552 
    553     ReturnDesc->Integer.Value = ReturnValue;
    554     WalkState->ReturnDesc = ReturnDesc;
    555     return_ACPI_STATUS (AE_OK);
    556 }
    557