1 /******************************************************************************
3 * Module Name: utxface - External interfaces, miscellaneous utility functions
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #define EXPORT_ACPI_INTERFACES
119 #include "accommon.h"
122 #define _COMPONENT ACPI_UTILITIES
123 ACPI_MODULE_NAME ("utxface")
126 /*******************************************************************************
128 * FUNCTION: AcpiTerminate
134 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
136 ******************************************************************************/
145 ACPI_FUNCTION_TRACE (AcpiTerminate
);
148 /* Shutdown and free all resources */
150 AcpiUtSubsystemShutdown ();
152 /* Free the mutex objects */
154 AcpiUtMutexTerminate ();
156 /* Now we can shutdown the OS-dependent layer */
158 Status
= AcpiOsTerminate ();
159 return_ACPI_STATUS (Status
);
162 ACPI_EXPORT_SYMBOL_INIT (AcpiTerminate
)
165 #ifndef ACPI_ASL_COMPILER
166 /*******************************************************************************
168 * FUNCTION: AcpiSubsystemStatus
172 * RETURN: Status of the ACPI subsystem
174 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
175 * before making any other calls, to ensure the subsystem
176 * initialized successfully.
178 ******************************************************************************/
181 AcpiSubsystemStatus (
185 if (AcpiGbl_StartupFlags
& ACPI_INITIALIZED_OK
)
195 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus
)
198 /*******************************************************************************
200 * FUNCTION: AcpiGetSystemInfo
202 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
205 * RETURN: Status - the status of the call
207 * DESCRIPTION: This function is called to get information about the current
208 * state of the ACPI subsystem. It will return system information
211 * If the function fails an appropriate status will be returned
212 * and the value of OutBuffer is undefined.
214 ******************************************************************************/
218 ACPI_BUFFER
*OutBuffer
)
220 ACPI_SYSTEM_INFO
*InfoPtr
;
224 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo
);
227 /* Parameter validation */
229 Status
= AcpiUtValidateBuffer (OutBuffer
);
230 if (ACPI_FAILURE (Status
))
232 return_ACPI_STATUS (Status
);
235 /* Validate/Allocate/Clear caller buffer */
237 Status
= AcpiUtInitializeBuffer (OutBuffer
, sizeof (ACPI_SYSTEM_INFO
));
238 if (ACPI_FAILURE (Status
))
240 return_ACPI_STATUS (Status
);
244 * Populate the return buffer
246 InfoPtr
= (ACPI_SYSTEM_INFO
*) OutBuffer
->Pointer
;
247 InfoPtr
->AcpiCaVersion
= ACPI_CA_VERSION
;
249 /* System flags (ACPI capabilities) */
251 InfoPtr
->Flags
= ACPI_SYS_MODE_ACPI
;
253 /* Timer resolution - 24 or 32 bits */
255 if (AcpiGbl_FADT
.Flags
& ACPI_FADT_32BIT_TIMER
)
257 InfoPtr
->TimerResolution
= 24;
261 InfoPtr
->TimerResolution
= 32;
264 /* Clear the reserved fields */
266 InfoPtr
->Reserved1
= 0;
267 InfoPtr
->Reserved2
= 0;
269 /* Current debug levels */
271 InfoPtr
->DebugLayer
= AcpiDbgLayer
;
272 InfoPtr
->DebugLevel
= AcpiDbgLevel
;
274 return_ACPI_STATUS (AE_OK
);
277 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo
)
280 /*******************************************************************************
282 * FUNCTION: AcpiGetStatistics
284 * PARAMETERS: Stats - Where the statistics are returned
286 * RETURN: Status - the status of the call
288 * DESCRIPTION: Get the contents of the various system counters
290 ******************************************************************************/
294 ACPI_STATISTICS
*Stats
)
296 ACPI_FUNCTION_TRACE (AcpiGetStatistics
);
299 /* Parameter validation */
303 return_ACPI_STATUS (AE_BAD_PARAMETER
);
306 /* Various interrupt-based event counters */
308 Stats
->SciCount
= AcpiSciCount
;
309 Stats
->GpeCount
= AcpiGpeCount
;
311 memcpy (Stats
->FixedEventCount
, AcpiFixedEventCount
,
312 sizeof (AcpiFixedEventCount
));
316 Stats
->MethodCount
= AcpiMethodCount
;
317 return_ACPI_STATUS (AE_OK
);
320 ACPI_EXPORT_SYMBOL (AcpiGetStatistics
)
323 /*****************************************************************************
325 * FUNCTION: AcpiInstallInitializationHandler
327 * PARAMETERS: Handler - Callback procedure
328 * Function - Not (currently) used, see below
332 * DESCRIPTION: Install an initialization handler
334 * TBD: When a second function is added, must save the Function also.
336 ****************************************************************************/
339 AcpiInstallInitializationHandler (
340 ACPI_INIT_HANDLER Handler
,
346 return (AE_BAD_PARAMETER
);
349 if (AcpiGbl_InitHandler
)
351 return (AE_ALREADY_EXISTS
);
354 AcpiGbl_InitHandler
= Handler
;
358 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler
)
361 /*****************************************************************************
363 * FUNCTION: AcpiPurgeCachedObjects
369 * DESCRIPTION: Empty all caches (delete the cached objects)
371 ****************************************************************************/
374 AcpiPurgeCachedObjects (
377 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects
);
380 (void) AcpiOsPurgeCache (AcpiGbl_StateCache
);
381 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache
);
382 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache
);
383 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache
);
385 return_ACPI_STATUS (AE_OK
);
388 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects
)
391 /*****************************************************************************
393 * FUNCTION: AcpiInstallInterface
395 * PARAMETERS: InterfaceName - The interface to install
399 * DESCRIPTION: Install an _OSI interface to the global list
401 ****************************************************************************/
404 AcpiInstallInterface (
405 ACPI_STRING InterfaceName
)
408 ACPI_INTERFACE_INFO
*InterfaceInfo
;
411 /* Parameter validation */
413 if (!InterfaceName
|| (strlen (InterfaceName
) == 0))
415 return (AE_BAD_PARAMETER
);
418 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
419 if (ACPI_FAILURE (Status
))
424 /* Check if the interface name is already in the global list */
426 InterfaceInfo
= AcpiUtGetInterface (InterfaceName
);
430 * The interface already exists in the list. This is OK if the
431 * interface has been marked invalid -- just clear the bit.
433 if (InterfaceInfo
->Flags
& ACPI_OSI_INVALID
)
435 InterfaceInfo
->Flags
&= ~ACPI_OSI_INVALID
;
440 Status
= AE_ALREADY_EXISTS
;
445 /* New interface name, install into the global list */
447 Status
= AcpiUtInstallInterface (InterfaceName
);
450 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
454 ACPI_EXPORT_SYMBOL (AcpiInstallInterface
)
457 /*****************************************************************************
459 * FUNCTION: AcpiRemoveInterface
461 * PARAMETERS: InterfaceName - The interface to remove
465 * DESCRIPTION: Remove an _OSI interface from the global list
467 ****************************************************************************/
470 AcpiRemoveInterface (
471 ACPI_STRING InterfaceName
)
476 /* Parameter validation */
478 if (!InterfaceName
|| (strlen (InterfaceName
) == 0))
480 return (AE_BAD_PARAMETER
);
483 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
484 if (ACPI_FAILURE (Status
))
489 Status
= AcpiUtRemoveInterface (InterfaceName
);
491 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
495 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface
)
498 /*****************************************************************************
500 * FUNCTION: AcpiInstallInterfaceHandler
502 * PARAMETERS: Handler - The _OSI interface handler to install
503 * NULL means "remove existing handler"
507 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
508 * invoked during execution of the internal implementation of
509 * _OSI. A NULL handler simply removes any existing handler.
511 ****************************************************************************/
514 AcpiInstallInterfaceHandler (
515 ACPI_INTERFACE_HANDLER Handler
)
520 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
521 if (ACPI_FAILURE (Status
))
526 if (Handler
&& AcpiGbl_InterfaceHandler
)
528 Status
= AE_ALREADY_EXISTS
;
532 AcpiGbl_InterfaceHandler
= Handler
;
535 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
539 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler
)
542 /*****************************************************************************
544 * FUNCTION: AcpiUpdateInterfaces
546 * PARAMETERS: Action - Actions to be performed during the
551 * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
552 * string or/and feature group strings.
554 ****************************************************************************/
557 AcpiUpdateInterfaces (
563 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
564 if (ACPI_FAILURE (Status
))
569 Status
= AcpiUtUpdateInterfaces (Action
);
571 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
576 /*****************************************************************************
578 * FUNCTION: AcpiCheckAddressRange
580 * PARAMETERS: SpaceId - Address space ID
581 * Address - Start address
583 * Warn - TRUE if warning on overlap desired
585 * RETURN: Count of the number of conflicts detected.
587 * DESCRIPTION: Check if the input address range overlaps any of the
588 * ASL operation region address ranges.
590 ****************************************************************************/
593 AcpiCheckAddressRange (
594 ACPI_ADR_SPACE_TYPE SpaceId
,
595 ACPI_PHYSICAL_ADDRESS Address
,
603 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
604 if (ACPI_FAILURE (Status
))
609 Overlaps
= AcpiUtCheckAddressRange (SpaceId
, Address
,
610 (UINT32
) Length
, Warn
);
612 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
616 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange
)
618 #endif /* !ACPI_ASL_COMPILER */
621 /*******************************************************************************
623 * FUNCTION: AcpiDecodePldBuffer
625 * PARAMETERS: InBuffer - Buffer returned by _PLD method
626 * Length - Length of the InBuffer
627 * ReturnBuffer - Where the decode buffer is returned
629 * RETURN: Status and the decoded _PLD buffer. User must deallocate
630 * the buffer via ACPI_FREE.
632 * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
633 * a local struct that is much more useful to an ACPI driver.
635 ******************************************************************************/
638 AcpiDecodePldBuffer (
641 ACPI_PLD_INFO
**ReturnBuffer
)
643 ACPI_PLD_INFO
*PldInfo
;
644 UINT32
*Buffer
= ACPI_CAST_PTR (UINT32
, InBuffer
);
648 /* Parameter validation */
650 if (!InBuffer
|| !ReturnBuffer
|| (Length
< ACPI_PLD_REV1_BUFFER_SIZE
))
652 return (AE_BAD_PARAMETER
);
655 PldInfo
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO
));
658 return (AE_NO_MEMORY
);
661 /* First 32-bit DWord */
663 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[0]);
664 PldInfo
->Revision
= ACPI_PLD_GET_REVISION (&Dword
);
665 PldInfo
->IgnoreColor
= ACPI_PLD_GET_IGNORE_COLOR (&Dword
);
666 PldInfo
->Red
= ACPI_PLD_GET_RED (&Dword
);
667 PldInfo
->Green
= ACPI_PLD_GET_GREEN (&Dword
);
668 PldInfo
->Blue
= ACPI_PLD_GET_BLUE (&Dword
);
670 /* Second 32-bit DWord */
672 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[1]);
673 PldInfo
->Width
= ACPI_PLD_GET_WIDTH (&Dword
);
674 PldInfo
->Height
= ACPI_PLD_GET_HEIGHT(&Dword
);
676 /* Third 32-bit DWord */
678 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[2]);
679 PldInfo
->UserVisible
= ACPI_PLD_GET_USER_VISIBLE (&Dword
);
680 PldInfo
->Dock
= ACPI_PLD_GET_DOCK (&Dword
);
681 PldInfo
->Lid
= ACPI_PLD_GET_LID (&Dword
);
682 PldInfo
->Panel
= ACPI_PLD_GET_PANEL (&Dword
);
683 PldInfo
->VerticalPosition
= ACPI_PLD_GET_VERTICAL (&Dword
);
684 PldInfo
->HorizontalPosition
= ACPI_PLD_GET_HORIZONTAL (&Dword
);
685 PldInfo
->Shape
= ACPI_PLD_GET_SHAPE (&Dword
);
686 PldInfo
->GroupOrientation
= ACPI_PLD_GET_ORIENTATION (&Dword
);
687 PldInfo
->GroupToken
= ACPI_PLD_GET_TOKEN (&Dword
);
688 PldInfo
->GroupPosition
= ACPI_PLD_GET_POSITION (&Dword
);
689 PldInfo
->Bay
= ACPI_PLD_GET_BAY (&Dword
);
691 /* Fourth 32-bit DWord */
693 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[3]);
694 PldInfo
->Ejectable
= ACPI_PLD_GET_EJECTABLE (&Dword
);
695 PldInfo
->OspmEjectRequired
= ACPI_PLD_GET_OSPM_EJECT (&Dword
);
696 PldInfo
->CabinetNumber
= ACPI_PLD_GET_CABINET (&Dword
);
697 PldInfo
->CardCageNumber
= ACPI_PLD_GET_CARD_CAGE (&Dword
);
698 PldInfo
->Reference
= ACPI_PLD_GET_REFERENCE (&Dword
);
699 PldInfo
->Rotation
= ACPI_PLD_GET_ROTATION (&Dword
);
700 PldInfo
->Order
= ACPI_PLD_GET_ORDER (&Dword
);
702 if (Length
>= ACPI_PLD_REV2_BUFFER_SIZE
)
704 /* Fifth 32-bit DWord (Revision 2 of _PLD) */
706 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[4]);
707 PldInfo
->VerticalOffset
= ACPI_PLD_GET_VERT_OFFSET (&Dword
);
708 PldInfo
->HorizontalOffset
= ACPI_PLD_GET_HORIZ_OFFSET (&Dword
);
711 *ReturnBuffer
= PldInfo
;
715 ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer
)