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