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