1 /******************************************************************************
3 * Module Name: utxface - External interfaces, miscellaneous utility functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
45 #define EXPORT_ACPI_INTERFACES
51 #define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("utxface")
55 /*******************************************************************************
57 * FUNCTION: AcpiTerminate
63 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
65 ******************************************************************************/
74 ACPI_FUNCTION_TRACE (AcpiTerminate);
77 /* Just exit if subsystem is already shutdown */
81 ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
82 return_ACPI_STATUS (AE_OK);
85 /* Subsystem appears active, go ahead and shut it down */
87 AcpiGbl_Shutdown = TRUE;
88 AcpiGbl_StartupFlags = 0;
89 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
91 /* Terminate the AML Debugger if present */
93 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = TRUE);
95 /* Shutdown and free all resources */
97 AcpiUtSubsystemShutdown ();
99 /* Free the mutex objects */
101 AcpiUtMutexTerminate ();
106 /* Shut down the debugger */
111 /* Now we can shutdown the OS-dependent layer */
113 Status = AcpiOsTerminate ();
114 return_ACPI_STATUS (Status);
117 ACPI_EXPORT_SYMBOL_INIT (AcpiTerminate)
120 #ifndef ACPI_ASL_COMPILER
121 /*******************************************************************************
123 * FUNCTION: AcpiSubsystemStatus
127 * RETURN: Status of the ACPI subsystem
129 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
130 * before making any other calls, to ensure the subsystem
131 * initialized successfully.
133 ******************************************************************************/
136 AcpiSubsystemStatus (
140 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
150 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
153 /*******************************************************************************
155 * FUNCTION: AcpiGetSystemInfo
157 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
160 * RETURN: Status - the status of the call
162 * DESCRIPTION: This function is called to get information about the current
163 * state of the ACPI subsystem. It will return system information
166 * If the function fails an appropriate status will be returned
167 * and the value of OutBuffer is undefined.
169 ******************************************************************************/
173 ACPI_BUFFER *OutBuffer)
175 ACPI_SYSTEM_INFO *InfoPtr;
179 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
182 /* Parameter validation */
184 Status = AcpiUtValidateBuffer (OutBuffer);
185 if (ACPI_FAILURE (Status))
187 return_ACPI_STATUS (Status);
190 /* Validate/Allocate/Clear caller buffer */
192 Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
193 if (ACPI_FAILURE (Status))
195 return_ACPI_STATUS (Status);
199 * Populate the return buffer
201 InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
203 InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
205 /* System flags (ACPI capabilities) */
207 InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
209 /* Timer resolution - 24 or 32 bits */
211 if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
213 InfoPtr->TimerResolution = 24;
217 InfoPtr->TimerResolution = 32;
220 /* Clear the reserved fields */
222 InfoPtr->Reserved1 = 0;
223 InfoPtr->Reserved2 = 0;
225 /* Current debug levels */
227 InfoPtr->DebugLayer = AcpiDbgLayer;
228 InfoPtr->DebugLevel = AcpiDbgLevel;
230 return_ACPI_STATUS (AE_OK);
233 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
236 /*******************************************************************************
238 * FUNCTION: AcpiGetStatistics
240 * PARAMETERS: Stats - Where the statistics are returned
242 * RETURN: Status - the status of the call
244 * DESCRIPTION: Get the contents of the various system counters
246 ******************************************************************************/
250 ACPI_STATISTICS *Stats)
252 ACPI_FUNCTION_TRACE (AcpiGetStatistics);
255 /* Parameter validation */
259 return_ACPI_STATUS (AE_BAD_PARAMETER);
262 /* Various interrupt-based event counters */
264 Stats->SciCount = AcpiSciCount;
265 Stats->GpeCount = AcpiGpeCount;
267 ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount,
268 sizeof (AcpiFixedEventCount));
273 Stats->MethodCount = AcpiMethodCount;
275 return_ACPI_STATUS (AE_OK);
278 ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
281 /*****************************************************************************
283 * FUNCTION: AcpiInstallInitializationHandler
285 * PARAMETERS: Handler - Callback procedure
286 * Function - Not (currently) used, see below
290 * DESCRIPTION: Install an initialization handler
292 * TBD: When a second function is added, must save the Function also.
294 ****************************************************************************/
297 AcpiInstallInitializationHandler (
298 ACPI_INIT_HANDLER Handler,
304 return (AE_BAD_PARAMETER);
307 if (AcpiGbl_InitHandler)
309 return (AE_ALREADY_EXISTS);
312 AcpiGbl_InitHandler = Handler;
316 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
319 /*****************************************************************************
321 * FUNCTION: AcpiPurgeCachedObjects
327 * DESCRIPTION: Empty all caches (delete the cached objects)
329 ****************************************************************************/
332 AcpiPurgeCachedObjects (
335 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
338 (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
339 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
340 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
341 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
343 return_ACPI_STATUS (AE_OK);
346 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
349 /*****************************************************************************
351 * FUNCTION: AcpiInstallInterface
353 * PARAMETERS: InterfaceName - The interface to install
357 * DESCRIPTION: Install an _OSI interface to the global list
359 ****************************************************************************/
362 AcpiInstallInterface (
363 ACPI_STRING InterfaceName)
366 ACPI_INTERFACE_INFO *InterfaceInfo;
369 /* Parameter validation */
371 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
373 return (AE_BAD_PARAMETER);
376 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
377 if (ACPI_FAILURE (Status))
382 /* Check if the interface name is already in the global list */
384 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
388 * The interface already exists in the list. This is OK if the
389 * interface has been marked invalid -- just clear the bit.
391 if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
393 InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
398 Status = AE_ALREADY_EXISTS;
403 /* New interface name, install into the global list */
405 Status = AcpiUtInstallInterface (InterfaceName);
408 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
412 ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
415 /*****************************************************************************
417 * FUNCTION: AcpiRemoveInterface
419 * PARAMETERS: InterfaceName - The interface to remove
423 * DESCRIPTION: Remove an _OSI interface from the global list
425 ****************************************************************************/
428 AcpiRemoveInterface (
429 ACPI_STRING InterfaceName)
434 /* Parameter validation */
436 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
438 return (AE_BAD_PARAMETER);
441 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
442 if (ACPI_FAILURE (Status))
447 Status = AcpiUtRemoveInterface (InterfaceName);
449 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
453 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
456 /*****************************************************************************
458 * FUNCTION: AcpiInstallInterfaceHandler
460 * PARAMETERS: Handler - The _OSI interface handler to install
461 * NULL means "remove existing handler"
465 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
466 * invoked during execution of the internal implementation of
467 * _OSI. A NULL handler simply removes any existing handler.
469 ****************************************************************************/
472 AcpiInstallInterfaceHandler (
473 ACPI_INTERFACE_HANDLER Handler)
478 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
479 if (ACPI_FAILURE (Status))
484 if (Handler && AcpiGbl_InterfaceHandler)
486 Status = AE_ALREADY_EXISTS;
490 AcpiGbl_InterfaceHandler = Handler;
493 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
497 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
500 /*****************************************************************************
502 * FUNCTION: AcpiUpdateInterfaces
504 * PARAMETERS: Action - Actions to be performed during the
509 * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
510 * string or/and feature group strings.
512 ****************************************************************************/
515 AcpiUpdateInterfaces (
521 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
522 if (ACPI_FAILURE (Status))
527 Status = AcpiUtUpdateInterfaces (Action);
529 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
534 /*****************************************************************************
536 * FUNCTION: AcpiCheckAddressRange
538 * PARAMETERS: SpaceId - Address space ID
539 * Address - Start address
541 * Warn - TRUE if warning on overlap desired
543 * RETURN: Count of the number of conflicts detected.
545 * DESCRIPTION: Check if the input address range overlaps any of the
546 * ASL operation region address ranges.
548 ****************************************************************************/
551 AcpiCheckAddressRange (
552 ACPI_ADR_SPACE_TYPE SpaceId,
553 ACPI_PHYSICAL_ADDRESS Address,
561 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
562 if (ACPI_FAILURE (Status))
567 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
568 (UINT32) Length, Warn);
570 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
574 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
576 #endif /* !ACPI_ASL_COMPILER */
579 /*******************************************************************************
581 * FUNCTION: AcpiDecodePldBuffer
583 * PARAMETERS: InBuffer - Buffer returned by _PLD method
584 * Length - Length of the InBuffer
585 * ReturnBuffer - Where the decode buffer is returned
587 * RETURN: Status and the decoded _PLD buffer. User must deallocate
588 * the buffer via ACPI_FREE.
590 * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
591 * a local struct that is much more useful to an ACPI driver.
593 ******************************************************************************/
596 AcpiDecodePldBuffer (
599 ACPI_PLD_INFO **ReturnBuffer)
601 ACPI_PLD_INFO *PldInfo;
602 UINT32 *Buffer = ACPI_CAST_PTR (UINT32, InBuffer);
606 /* Parameter validation */
608 if (!InBuffer || !ReturnBuffer || (Length < 16))
610 return (AE_BAD_PARAMETER);
613 PldInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO));
616 return (AE_NO_MEMORY);
619 /* First 32-bit DWord */
621 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[0]);
622 PldInfo->Revision = ACPI_PLD_GET_REVISION (&Dword);
623 PldInfo->IgnoreColor = ACPI_PLD_GET_IGNORE_COLOR (&Dword);
624 PldInfo->Color = ACPI_PLD_GET_COLOR (&Dword);
626 /* Second 32-bit DWord */
628 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[1]);
629 PldInfo->Width = ACPI_PLD_GET_WIDTH (&Dword);
630 PldInfo->Height = ACPI_PLD_GET_HEIGHT(&Dword);
632 /* Third 32-bit DWord */
634 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[2]);
635 PldInfo->UserVisible = ACPI_PLD_GET_USER_VISIBLE (&Dword);
636 PldInfo->Dock = ACPI_PLD_GET_DOCK (&Dword);
637 PldInfo->Lid = ACPI_PLD_GET_LID (&Dword);
638 PldInfo->Panel = ACPI_PLD_GET_PANEL (&Dword);
639 PldInfo->VerticalPosition = ACPI_PLD_GET_VERTICAL (&Dword);
640 PldInfo->HorizontalPosition = ACPI_PLD_GET_HORIZONTAL (&Dword);
641 PldInfo->Shape = ACPI_PLD_GET_SHAPE (&Dword);
642 PldInfo->GroupOrientation = ACPI_PLD_GET_ORIENTATION (&Dword);
643 PldInfo->GroupToken = ACPI_PLD_GET_TOKEN (&Dword);
644 PldInfo->GroupPosition = ACPI_PLD_GET_POSITION (&Dword);
645 PldInfo->Bay = ACPI_PLD_GET_BAY (&Dword);
647 /* Fourth 32-bit DWord */
649 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[3]);
650 PldInfo->Ejectable = ACPI_PLD_GET_EJECTABLE (&Dword);
651 PldInfo->OspmEjectRequired = ACPI_PLD_GET_OSPM_EJECT (&Dword);
652 PldInfo->CabinetNumber = ACPI_PLD_GET_CABINET (&Dword);
653 PldInfo->CardCageNumber = ACPI_PLD_GET_CARD_CAGE (&Dword);
654 PldInfo->Reference = ACPI_PLD_GET_REFERENCE (&Dword);
655 PldInfo->Rotation = ACPI_PLD_GET_ROTATION (&Dword);
656 PldInfo->Order = ACPI_PLD_GET_ORDER (&Dword);
658 if (Length >= ACPI_PLD_BUFFER_SIZE)
660 /* Fifth 32-bit DWord (Revision 2 of _PLD) */
662 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[4]);
663 PldInfo->VerticalOffset = ACPI_PLD_GET_VERT_OFFSET (&Dword);
664 PldInfo->HorizontalOffset = ACPI_PLD_GET_HORIZ_OFFSET (&Dword);
667 *ReturnBuffer = PldInfo;
671 ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer)