1 /******************************************************************************
3 * Module Name: utxface - External interfaces, miscellaneous utility functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
46 #define EXPORT_ACPI_INTERFACES
52 #define _COMPONENT ACPI_UTILITIES
53 ACPI_MODULE_NAME ("utxface")
56 /*******************************************************************************
58 * FUNCTION: AcpiTerminate
64 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
66 ******************************************************************************/
75 ACPI_FUNCTION_TRACE (AcpiTerminate
);
78 /* Just exit if subsystem is already shutdown */
82 ACPI_ERROR ((AE_INFO
, "ACPI Subsystem is already terminated"));
83 return_ACPI_STATUS (AE_OK
);
86 /* Subsystem appears active, go ahead and shut it down */
88 AcpiGbl_Shutdown
= TRUE
;
89 AcpiGbl_StartupFlags
= 0;
90 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "Shutting down ACPI Subsystem\n"));
92 /* Terminate the AML Debugger if present */
94 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads
= TRUE
);
96 /* Shutdown and free all resources */
98 AcpiUtSubsystemShutdown ();
100 /* Free the mutex objects */
102 AcpiUtMutexTerminate ();
107 /* Shut down the debugger */
112 /* Now we can shutdown the OS-dependent layer */
114 Status
= AcpiOsTerminate ();
115 return_ACPI_STATUS (Status
);
118 ACPI_EXPORT_SYMBOL_INIT (AcpiTerminate
)
121 #ifndef ACPI_ASL_COMPILER
122 /*******************************************************************************
124 * FUNCTION: AcpiSubsystemStatus
128 * RETURN: Status of the ACPI subsystem
130 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
131 * before making any other calls, to ensure the subsystem
132 * initialized successfully.
134 ******************************************************************************/
137 AcpiSubsystemStatus (
141 if (AcpiGbl_StartupFlags
& ACPI_INITIALIZED_OK
)
151 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus
)
154 /*******************************************************************************
156 * FUNCTION: AcpiGetSystemInfo
158 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
161 * RETURN: Status - the status of the call
163 * DESCRIPTION: This function is called to get information about the current
164 * state of the ACPI subsystem. It will return system information
167 * If the function fails an appropriate status will be returned
168 * and the value of OutBuffer is undefined.
170 ******************************************************************************/
174 ACPI_BUFFER
*OutBuffer
)
176 ACPI_SYSTEM_INFO
*InfoPtr
;
180 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo
);
183 /* Parameter validation */
185 Status
= AcpiUtValidateBuffer (OutBuffer
);
186 if (ACPI_FAILURE (Status
))
188 return_ACPI_STATUS (Status
);
191 /* Validate/Allocate/Clear caller buffer */
193 Status
= AcpiUtInitializeBuffer (OutBuffer
, sizeof (ACPI_SYSTEM_INFO
));
194 if (ACPI_FAILURE (Status
))
196 return_ACPI_STATUS (Status
);
200 * Populate the return buffer
202 InfoPtr
= (ACPI_SYSTEM_INFO
*) OutBuffer
->Pointer
;
204 InfoPtr
->AcpiCaVersion
= ACPI_CA_VERSION
;
206 /* System flags (ACPI capabilities) */
208 InfoPtr
->Flags
= ACPI_SYS_MODE_ACPI
;
210 /* Timer resolution - 24 or 32 bits */
212 if (AcpiGbl_FADT
.Flags
& ACPI_FADT_32BIT_TIMER
)
214 InfoPtr
->TimerResolution
= 24;
218 InfoPtr
->TimerResolution
= 32;
221 /* Clear the reserved fields */
223 InfoPtr
->Reserved1
= 0;
224 InfoPtr
->Reserved2
= 0;
226 /* Current debug levels */
228 InfoPtr
->DebugLayer
= AcpiDbgLayer
;
229 InfoPtr
->DebugLevel
= AcpiDbgLevel
;
231 return_ACPI_STATUS (AE_OK
);
234 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo
)
237 /*******************************************************************************
239 * FUNCTION: AcpiGetStatistics
241 * PARAMETERS: Stats - Where the statistics are returned
243 * RETURN: Status - the status of the call
245 * DESCRIPTION: Get the contents of the various system counters
247 ******************************************************************************/
251 ACPI_STATISTICS
*Stats
)
253 ACPI_FUNCTION_TRACE (AcpiGetStatistics
);
256 /* Parameter validation */
260 return_ACPI_STATUS (AE_BAD_PARAMETER
);
263 /* Various interrupt-based event counters */
265 Stats
->SciCount
= AcpiSciCount
;
266 Stats
->GpeCount
= AcpiGpeCount
;
268 ACPI_MEMCPY (Stats
->FixedEventCount
, AcpiFixedEventCount
,
269 sizeof (AcpiFixedEventCount
));
274 Stats
->MethodCount
= AcpiMethodCount
;
276 return_ACPI_STATUS (AE_OK
);
279 ACPI_EXPORT_SYMBOL (AcpiGetStatistics
)
282 /*****************************************************************************
284 * FUNCTION: AcpiInstallInitializationHandler
286 * PARAMETERS: Handler - Callback procedure
287 * Function - Not (currently) used, see below
291 * DESCRIPTION: Install an initialization handler
293 * TBD: When a second function is added, must save the Function also.
295 ****************************************************************************/
298 AcpiInstallInitializationHandler (
299 ACPI_INIT_HANDLER Handler
,
305 return (AE_BAD_PARAMETER
);
308 if (AcpiGbl_InitHandler
)
310 return (AE_ALREADY_EXISTS
);
313 AcpiGbl_InitHandler
= Handler
;
317 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler
)
320 /*****************************************************************************
322 * FUNCTION: AcpiPurgeCachedObjects
328 * DESCRIPTION: Empty all caches (delete the cached objects)
330 ****************************************************************************/
333 AcpiPurgeCachedObjects (
336 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects
);
339 (void) AcpiOsPurgeCache (AcpiGbl_StateCache
);
340 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache
);
341 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache
);
342 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache
);
344 return_ACPI_STATUS (AE_OK
);
347 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects
)
350 /*****************************************************************************
352 * FUNCTION: AcpiInstallInterface
354 * PARAMETERS: InterfaceName - The interface to install
358 * DESCRIPTION: Install an _OSI interface to the global list
360 ****************************************************************************/
363 AcpiInstallInterface (
364 ACPI_STRING InterfaceName
)
367 ACPI_INTERFACE_INFO
*InterfaceInfo
;
370 /* Parameter validation */
372 if (!InterfaceName
|| (ACPI_STRLEN (InterfaceName
) == 0))
374 return (AE_BAD_PARAMETER
);
377 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
378 if (ACPI_FAILURE (Status
))
383 /* Check if the interface name is already in the global list */
385 InterfaceInfo
= AcpiUtGetInterface (InterfaceName
);
389 * The interface already exists in the list. This is OK if the
390 * interface has been marked invalid -- just clear the bit.
392 if (InterfaceInfo
->Flags
& ACPI_OSI_INVALID
)
394 InterfaceInfo
->Flags
&= ~ACPI_OSI_INVALID
;
399 Status
= AE_ALREADY_EXISTS
;
404 /* New interface name, install into the global list */
406 Status
= AcpiUtInstallInterface (InterfaceName
);
409 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
413 ACPI_EXPORT_SYMBOL (AcpiInstallInterface
)
416 /*****************************************************************************
418 * FUNCTION: AcpiRemoveInterface
420 * PARAMETERS: InterfaceName - The interface to remove
424 * DESCRIPTION: Remove an _OSI interface from the global list
426 ****************************************************************************/
429 AcpiRemoveInterface (
430 ACPI_STRING InterfaceName
)
435 /* Parameter validation */
437 if (!InterfaceName
|| (ACPI_STRLEN (InterfaceName
) == 0))
439 return (AE_BAD_PARAMETER
);
442 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
443 if (ACPI_FAILURE (Status
))
448 Status
= AcpiUtRemoveInterface (InterfaceName
);
450 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
454 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface
)
457 /*****************************************************************************
459 * FUNCTION: AcpiInstallInterfaceHandler
461 * PARAMETERS: Handler - The _OSI interface handler to install
462 * NULL means "remove existing handler"
466 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
467 * invoked during execution of the internal implementation of
468 * _OSI. A NULL handler simply removes any existing handler.
470 ****************************************************************************/
473 AcpiInstallInterfaceHandler (
474 ACPI_INTERFACE_HANDLER Handler
)
479 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
480 if (ACPI_FAILURE (Status
))
485 if (Handler
&& AcpiGbl_InterfaceHandler
)
487 Status
= AE_ALREADY_EXISTS
;
491 AcpiGbl_InterfaceHandler
= Handler
;
494 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
498 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler
)
501 /*****************************************************************************
503 * FUNCTION: AcpiUpdateInterfaces
505 * PARAMETERS: Action - Actions to be performed during the
510 * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
511 * string or/and feature group strings.
513 ****************************************************************************/
516 AcpiUpdateInterfaces (
522 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
523 if (ACPI_FAILURE (Status
))
528 Status
= AcpiUtUpdateInterfaces (Action
);
530 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
535 /*****************************************************************************
537 * FUNCTION: AcpiCheckAddressRange
539 * PARAMETERS: SpaceId - Address space ID
540 * Address - Start address
542 * Warn - TRUE if warning on overlap desired
544 * RETURN: Count of the number of conflicts detected.
546 * DESCRIPTION: Check if the input address range overlaps any of the
547 * ASL operation region address ranges.
549 ****************************************************************************/
552 AcpiCheckAddressRange (
553 ACPI_ADR_SPACE_TYPE SpaceId
,
554 ACPI_PHYSICAL_ADDRESS Address
,
562 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
563 if (ACPI_FAILURE (Status
))
568 Overlaps
= AcpiUtCheckAddressRange (SpaceId
, Address
,
569 (UINT32
) Length
, Warn
);
571 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
575 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange
)
577 #endif /* !ACPI_ASL_COMPILER */
580 /*******************************************************************************
582 * FUNCTION: AcpiDecodePldBuffer
584 * PARAMETERS: InBuffer - Buffer returned by _PLD method
585 * Length - Length of the InBuffer
586 * ReturnBuffer - Where the decode buffer is returned
588 * RETURN: Status and the decoded _PLD buffer. User must deallocate
589 * the buffer via ACPI_FREE.
591 * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
592 * a local struct that is much more useful to an ACPI driver.
594 ******************************************************************************/
597 AcpiDecodePldBuffer (
600 ACPI_PLD_INFO
**ReturnBuffer
)
602 ACPI_PLD_INFO
*PldInfo
;
603 UINT32
*Buffer
= ACPI_CAST_PTR (UINT32
, InBuffer
);
607 /* Parameter validation */
609 if (!InBuffer
|| !ReturnBuffer
|| (Length
< 16))
611 return (AE_BAD_PARAMETER
);
614 PldInfo
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO
));
617 return (AE_NO_MEMORY
);
620 /* First 32-bit DWord */
622 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[0]);
623 PldInfo
->Revision
= ACPI_PLD_GET_REVISION (&Dword
);
624 PldInfo
->IgnoreColor
= ACPI_PLD_GET_IGNORE_COLOR (&Dword
);
625 PldInfo
->Color
= ACPI_PLD_GET_COLOR (&Dword
);
627 /* Second 32-bit DWord */
629 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[1]);
630 PldInfo
->Width
= ACPI_PLD_GET_WIDTH (&Dword
);
631 PldInfo
->Height
= ACPI_PLD_GET_HEIGHT(&Dword
);
633 /* Third 32-bit DWord */
635 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[2]);
636 PldInfo
->UserVisible
= ACPI_PLD_GET_USER_VISIBLE (&Dword
);
637 PldInfo
->Dock
= ACPI_PLD_GET_DOCK (&Dword
);
638 PldInfo
->Lid
= ACPI_PLD_GET_LID (&Dword
);
639 PldInfo
->Panel
= ACPI_PLD_GET_PANEL (&Dword
);
640 PldInfo
->VerticalPosition
= ACPI_PLD_GET_VERTICAL (&Dword
);
641 PldInfo
->HorizontalPosition
= ACPI_PLD_GET_HORIZONTAL (&Dword
);
642 PldInfo
->Shape
= ACPI_PLD_GET_SHAPE (&Dword
);
643 PldInfo
->GroupOrientation
= ACPI_PLD_GET_ORIENTATION (&Dword
);
644 PldInfo
->GroupToken
= ACPI_PLD_GET_TOKEN (&Dword
);
645 PldInfo
->GroupPosition
= ACPI_PLD_GET_POSITION (&Dword
);
646 PldInfo
->Bay
= ACPI_PLD_GET_BAY (&Dword
);
648 /* Fourth 32-bit DWord */
650 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[3]);
651 PldInfo
->Ejectable
= ACPI_PLD_GET_EJECTABLE (&Dword
);
652 PldInfo
->OspmEjectRequired
= ACPI_PLD_GET_OSPM_EJECT (&Dword
);
653 PldInfo
->CabinetNumber
= ACPI_PLD_GET_CABINET (&Dword
);
654 PldInfo
->CardCageNumber
= ACPI_PLD_GET_CARD_CAGE (&Dword
);
655 PldInfo
->Reference
= ACPI_PLD_GET_REFERENCE (&Dword
);
656 PldInfo
->Rotation
= ACPI_PLD_GET_ROTATION (&Dword
);
657 PldInfo
->Order
= ACPI_PLD_GET_ORDER (&Dword
);
659 if (Length
>= ACPI_PLD_BUFFER_SIZE
)
661 /* Fifth 32-bit DWord (Revision 2 of _PLD) */
663 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[4]);
664 PldInfo
->VerticalOffset
= ACPI_PLD_GET_VERT_OFFSET (&Dword
);
665 PldInfo
->HorizontalOffset
= ACPI_PLD_GET_HORIZ_OFFSET (&Dword
);
668 *ReturnBuffer
= PldInfo
;
672 ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer
)