utosi.c revision 249112
1/******************************************************************************
2 *
3 * Module Name: utosi - Support for the _OSI predefined control method
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, 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#define __UTOSI_C__
45
46#include <contrib/dev/acpica/include/acpi.h>
47#include <contrib/dev/acpica/include/accommon.h>
48
49
50#define _COMPONENT          ACPI_UTILITIES
51        ACPI_MODULE_NAME    ("utosi")
52
53/*
54 * Strings supported by the _OSI predefined control method (which is
55 * implemented internally within this module.)
56 *
57 * March 2009: Removed "Linux" as this host no longer wants to respond true
58 * for this string. Basically, the only safe OS strings are windows-related
59 * and in many or most cases represent the only test path within the
60 * BIOS-provided ASL code.
61 *
62 * The last element of each entry is used to track the newest version of
63 * Windows that the BIOS has requested.
64 */
65static ACPI_INTERFACE_INFO    AcpiDefaultSupportedInterfaces[] =
66{
67    /* Operating System Vendor Strings */
68
69    {"Windows 2000",        NULL, 0, ACPI_OSI_WIN_2000},         /* Windows 2000 */
70    {"Windows 2001",        NULL, 0, ACPI_OSI_WIN_XP},           /* Windows XP */
71    {"Windows 2001 SP1",    NULL, 0, ACPI_OSI_WIN_XP_SP1},       /* Windows XP SP1 */
72    {"Windows 2001.1",      NULL, 0, ACPI_OSI_WINSRV_2003},      /* Windows Server 2003 */
73    {"Windows 2001 SP2",    NULL, 0, ACPI_OSI_WIN_XP_SP2},       /* Windows XP SP2 */
74    {"Windows 2001.1 SP1",  NULL, 0, ACPI_OSI_WINSRV_2003_SP1},  /* Windows Server 2003 SP1 - Added 03/2006 */
75    {"Windows 2006",        NULL, 0, ACPI_OSI_WIN_VISTA},        /* Windows Vista - Added 03/2006 */
76    {"Windows 2006.1",      NULL, 0, ACPI_OSI_WINSRV_2008},      /* Windows Server 2008 - Added 09/2009 */
77    {"Windows 2006 SP1",    NULL, 0, ACPI_OSI_WIN_VISTA_SP1},    /* Windows Vista SP1 - Added 09/2009 */
78    {"Windows 2006 SP2",    NULL, 0, ACPI_OSI_WIN_VISTA_SP2},    /* Windows Vista SP2 - Added 09/2010 */
79    {"Windows 2009",        NULL, 0, ACPI_OSI_WIN_7},            /* Windows 7 and Server 2008 R2 - Added 09/2009 */
80    {"Windows 2012",        NULL, 0, ACPI_OSI_WIN_8},            /* Windows 8 and Server 2012 - Added 08/2012 */
81
82    /* Feature Group Strings */
83
84    {"Extended Address Space Descriptor", NULL, 0, 0}
85
86    /*
87     * All "optional" feature group strings (features that are implemented
88     * by the host) should be dynamically added by the host via
89     * AcpiInstallInterface and should not be manually added here.
90     *
91     * Examples of optional feature group strings:
92     *
93     * "Module Device"
94     * "Processor Device"
95     * "3.0 Thermal Model"
96     * "3.0 _SCP Extensions"
97     * "Processor Aggregator Device"
98     */
99};
100
101
102/*******************************************************************************
103 *
104 * FUNCTION:    AcpiUtInitializeInterfaces
105 *
106 * PARAMETERS:  None
107 *
108 * RETURN:      Status
109 *
110 * DESCRIPTION: Initialize the global _OSI supported interfaces list
111 *
112 ******************************************************************************/
113
114ACPI_STATUS
115AcpiUtInitializeInterfaces (
116    void)
117{
118    ACPI_STATUS             Status;
119    UINT32                  i;
120
121
122    Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
123    if (ACPI_FAILURE (Status))
124    {
125        return (Status);
126    }
127
128    AcpiGbl_SupportedInterfaces = AcpiDefaultSupportedInterfaces;
129
130    /* Link the static list of supported interfaces */
131
132    for (i = 0; i < (ACPI_ARRAY_LENGTH (AcpiDefaultSupportedInterfaces) - 1); i++)
133    {
134        AcpiDefaultSupportedInterfaces[i].Next =
135            &AcpiDefaultSupportedInterfaces[(ACPI_SIZE) i + 1];
136    }
137
138    AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
139    return (AE_OK);
140}
141
142
143/*******************************************************************************
144 *
145 * FUNCTION:    AcpiUtInterfaceTerminate
146 *
147 * PARAMETERS:  None
148 *
149 * RETURN:      Status
150 *
151 * DESCRIPTION: Delete all interfaces in the global list. Sets
152 *              AcpiGbl_SupportedInterfaces to NULL.
153 *
154 ******************************************************************************/
155
156ACPI_STATUS
157AcpiUtInterfaceTerminate (
158    void)
159{
160    ACPI_STATUS             Status;
161    ACPI_INTERFACE_INFO     *NextInterface;
162
163
164    Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
165    if (ACPI_FAILURE (Status))
166    {
167        return (Status);
168    }
169
170    NextInterface = AcpiGbl_SupportedInterfaces;
171    while (NextInterface)
172    {
173        AcpiGbl_SupportedInterfaces = NextInterface->Next;
174
175        /* Only interfaces added at runtime can be freed */
176
177        if (NextInterface->Flags & ACPI_OSI_DYNAMIC)
178        {
179            ACPI_FREE (NextInterface->Name);
180            ACPI_FREE (NextInterface);
181        }
182
183        NextInterface = AcpiGbl_SupportedInterfaces;
184    }
185
186    AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
187    return (AE_OK);
188}
189
190
191/*******************************************************************************
192 *
193 * FUNCTION:    AcpiUtInstallInterface
194 *
195 * PARAMETERS:  InterfaceName       - The interface to install
196 *
197 * RETURN:      Status
198 *
199 * DESCRIPTION: Install the interface into the global interface list.
200 *              Caller MUST hold AcpiGbl_OsiMutex
201 *
202 ******************************************************************************/
203
204ACPI_STATUS
205AcpiUtInstallInterface (
206    ACPI_STRING             InterfaceName)
207{
208    ACPI_INTERFACE_INFO     *InterfaceInfo;
209
210
211    /* Allocate info block and space for the name string */
212
213    InterfaceInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_INTERFACE_INFO));
214    if (!InterfaceInfo)
215    {
216        return (AE_NO_MEMORY);
217    }
218
219    InterfaceInfo->Name = ACPI_ALLOCATE_ZEROED (ACPI_STRLEN (InterfaceName) + 1);
220    if (!InterfaceInfo->Name)
221    {
222        ACPI_FREE (InterfaceInfo);
223        return (AE_NO_MEMORY);
224    }
225
226    /* Initialize new info and insert at the head of the global list */
227
228    ACPI_STRCPY (InterfaceInfo->Name, InterfaceName);
229    InterfaceInfo->Flags = ACPI_OSI_DYNAMIC;
230    InterfaceInfo->Next = AcpiGbl_SupportedInterfaces;
231
232    AcpiGbl_SupportedInterfaces = InterfaceInfo;
233    return (AE_OK);
234}
235
236
237/*******************************************************************************
238 *
239 * FUNCTION:    AcpiUtRemoveInterface
240 *
241 * PARAMETERS:  InterfaceName       - The interface to remove
242 *
243 * RETURN:      Status
244 *
245 * DESCRIPTION: Remove the interface from the global interface list.
246 *              Caller MUST hold AcpiGbl_OsiMutex
247 *
248 ******************************************************************************/
249
250ACPI_STATUS
251AcpiUtRemoveInterface (
252    ACPI_STRING             InterfaceName)
253{
254    ACPI_INTERFACE_INFO     *PreviousInterface;
255    ACPI_INTERFACE_INFO     *NextInterface;
256
257
258    PreviousInterface = NextInterface = AcpiGbl_SupportedInterfaces;
259    while (NextInterface)
260    {
261        if (!ACPI_STRCMP (InterfaceName, NextInterface->Name))
262        {
263            /* Found: name is in either the static list or was added at runtime */
264
265            if (NextInterface->Flags & ACPI_OSI_DYNAMIC)
266            {
267                /* Interface was added dynamically, remove and free it */
268
269                if (PreviousInterface == NextInterface)
270                {
271                    AcpiGbl_SupportedInterfaces = NextInterface->Next;
272                }
273                else
274                {
275                    PreviousInterface->Next = NextInterface->Next;
276                }
277
278                ACPI_FREE (NextInterface->Name);
279                ACPI_FREE (NextInterface);
280            }
281            else
282            {
283                /*
284                 * Interface is in static list. If marked invalid, then it
285                 * does not actually exist. Else, mark it invalid.
286                 */
287                if (NextInterface->Flags & ACPI_OSI_INVALID)
288                {
289                    return (AE_NOT_EXIST);
290                }
291
292                NextInterface->Flags |= ACPI_OSI_INVALID;
293            }
294
295            return (AE_OK);
296        }
297
298        PreviousInterface = NextInterface;
299        NextInterface = NextInterface->Next;
300    }
301
302    /* Interface was not found */
303
304    return (AE_NOT_EXIST);
305}
306
307
308/*******************************************************************************
309 *
310 * FUNCTION:    AcpiUtGetInterface
311 *
312 * PARAMETERS:  InterfaceName       - The interface to find
313 *
314 * RETURN:      ACPI_INTERFACE_INFO if found. NULL if not found.
315 *
316 * DESCRIPTION: Search for the specified interface name in the global list.
317 *              Caller MUST hold AcpiGbl_OsiMutex
318 *
319 ******************************************************************************/
320
321ACPI_INTERFACE_INFO *
322AcpiUtGetInterface (
323    ACPI_STRING             InterfaceName)
324{
325    ACPI_INTERFACE_INFO     *NextInterface;
326
327
328    NextInterface = AcpiGbl_SupportedInterfaces;
329    while (NextInterface)
330    {
331        if (!ACPI_STRCMP (InterfaceName, NextInterface->Name))
332        {
333            return (NextInterface);
334        }
335
336        NextInterface = NextInterface->Next;
337    }
338
339    return (NULL);
340}
341
342
343/*******************************************************************************
344 *
345 * FUNCTION:    AcpiUtOsiImplementation
346 *
347 * PARAMETERS:  WalkState           - Current walk state
348 *
349 * RETURN:      Status
350 *
351 * DESCRIPTION: Implementation of the _OSI predefined control method. When
352 *              an invocation of _OSI is encountered in the system AML,
353 *              control is transferred to this function.
354 *
355 ******************************************************************************/
356
357ACPI_STATUS
358AcpiUtOsiImplementation (
359    ACPI_WALK_STATE         *WalkState)
360{
361    ACPI_OPERAND_OBJECT     *StringDesc;
362    ACPI_OPERAND_OBJECT     *ReturnDesc;
363    ACPI_INTERFACE_INFO     *InterfaceInfo;
364    ACPI_INTERFACE_HANDLER  InterfaceHandler;
365    ACPI_STATUS             Status;
366    UINT32                  ReturnValue;
367
368
369    ACPI_FUNCTION_TRACE (UtOsiImplementation);
370
371
372    /* Validate the string input argument (from the AML caller) */
373
374    StringDesc = WalkState->Arguments[0].Object;
375    if (!StringDesc ||
376        (StringDesc->Common.Type != ACPI_TYPE_STRING))
377    {
378        return_ACPI_STATUS (AE_TYPE);
379    }
380
381    /* Create a return object */
382
383    ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
384    if (!ReturnDesc)
385    {
386        return_ACPI_STATUS (AE_NO_MEMORY);
387    }
388
389    /* Default return value is 0, NOT SUPPORTED */
390
391    ReturnValue = 0;
392    Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
393    if (ACPI_FAILURE (Status))
394    {
395        AcpiUtDeleteObjectDesc (ReturnDesc);
396        return_ACPI_STATUS (Status);
397    }
398
399    /* Lookup the interface in the global _OSI list */
400
401    InterfaceInfo = AcpiUtGetInterface (StringDesc->String.Pointer);
402    if (InterfaceInfo &&
403        !(InterfaceInfo->Flags & ACPI_OSI_INVALID))
404    {
405        /*
406         * The interface is supported.
407         * Update the OsiData if necessary. We keep track of the latest
408         * version of Windows that has been requested by the BIOS.
409         */
410        if (InterfaceInfo->Value > AcpiGbl_OsiData)
411        {
412            AcpiGbl_OsiData = InterfaceInfo->Value;
413        }
414
415        ReturnValue = ACPI_UINT32_MAX;
416    }
417
418    AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
419
420    /*
421     * Invoke an optional _OSI interface handler. The host OS may wish
422     * to do some interface-specific handling. For example, warn about
423     * certain interfaces or override the true/false support value.
424     */
425    InterfaceHandler = AcpiGbl_InterfaceHandler;
426    if (InterfaceHandler)
427    {
428        ReturnValue = InterfaceHandler (
429            StringDesc->String.Pointer, ReturnValue);
430    }
431
432    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
433        "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
434        StringDesc->String.Pointer, ReturnValue == 0 ? "not " : ""));
435
436    /* Complete the return object */
437
438    ReturnDesc->Integer.Value = ReturnValue;
439    WalkState->ReturnDesc = ReturnDesc;
440    return_ACPI_STATUS (AE_OK);
441}
442