1 /******************************************************************************
3 * Module Name: utxface - External interfaces, miscellaneous utility functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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.
44 #define EXPORT_ACPI_INTERFACES
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acdebug.h>
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("utxface")
54 /*******************************************************************************
56 * FUNCTION: AcpiTerminate
62 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
64 ******************************************************************************/
73 ACPI_FUNCTION_TRACE (AcpiTerminate);
76 /* Just exit if subsystem is already shutdown */
80 ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
81 return_ACPI_STATUS (AE_OK);
84 /* Subsystem appears active, go ahead and shut it down */
86 AcpiGbl_Shutdown = TRUE;
87 AcpiGbl_StartupFlags = 0;
88 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
90 /* Terminate the AML Debugger if present */
92 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = TRUE);
94 /* Shutdown and free all resources */
96 AcpiUtSubsystemShutdown ();
98 /* Free the mutex objects */
100 AcpiUtMutexTerminate ();
105 /* Shut down the debugger */
110 /* Now we can shutdown the OS-dependent layer */
112 Status = AcpiOsTerminate ();
113 return_ACPI_STATUS (Status);
116 ACPI_EXPORT_SYMBOL_INIT (AcpiTerminate)
119 #ifndef ACPI_ASL_COMPILER
120 /*******************************************************************************
122 * FUNCTION: AcpiSubsystemStatus
126 * RETURN: Status of the ACPI subsystem
128 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
129 * before making any other calls, to ensure the subsystem
130 * initialized successfully.
132 ******************************************************************************/
135 AcpiSubsystemStatus (
139 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
149 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
152 /*******************************************************************************
154 * FUNCTION: AcpiGetSystemInfo
156 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
159 * RETURN: Status - the status of the call
161 * DESCRIPTION: This function is called to get information about the current
162 * state of the ACPI subsystem. It will return system information
165 * If the function fails an appropriate status will be returned
166 * and the value of OutBuffer is undefined.
168 ******************************************************************************/
172 ACPI_BUFFER *OutBuffer)
174 ACPI_SYSTEM_INFO *InfoPtr;
178 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
181 /* Parameter validation */
183 Status = AcpiUtValidateBuffer (OutBuffer);
184 if (ACPI_FAILURE (Status))
186 return_ACPI_STATUS (Status);
189 /* Validate/Allocate/Clear caller buffer */
191 Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
192 if (ACPI_FAILURE (Status))
194 return_ACPI_STATUS (Status);
198 * Populate the return buffer
200 InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
202 InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
204 /* System flags (ACPI capabilities) */
206 InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
208 /* Timer resolution - 24 or 32 bits */
210 if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
212 InfoPtr->TimerResolution = 24;
216 InfoPtr->TimerResolution = 32;
219 /* Clear the reserved fields */
221 InfoPtr->Reserved1 = 0;
222 InfoPtr->Reserved2 = 0;
224 /* Current debug levels */
226 InfoPtr->DebugLayer = AcpiDbgLayer;
227 InfoPtr->DebugLevel = AcpiDbgLevel;
229 return_ACPI_STATUS (AE_OK);
232 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
235 /*******************************************************************************
237 * FUNCTION: AcpiGetStatistics
239 * PARAMETERS: Stats - Where the statistics are returned
241 * RETURN: Status - the status of the call
243 * DESCRIPTION: Get the contents of the various system counters
245 ******************************************************************************/
249 ACPI_STATISTICS *Stats)
251 ACPI_FUNCTION_TRACE (AcpiGetStatistics);
254 /* Parameter validation */
258 return_ACPI_STATUS (AE_BAD_PARAMETER);
261 /* Various interrupt-based event counters */
263 Stats->SciCount = AcpiSciCount;
264 Stats->GpeCount = AcpiGpeCount;
266 ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount,
267 sizeof (AcpiFixedEventCount));
272 Stats->MethodCount = AcpiMethodCount;
274 return_ACPI_STATUS (AE_OK);
277 ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
280 /*****************************************************************************
282 * FUNCTION: AcpiInstallInitializationHandler
284 * PARAMETERS: Handler - Callback procedure
285 * Function - Not (currently) used, see below
289 * DESCRIPTION: Install an initialization handler
291 * TBD: When a second function is added, must save the Function also.
293 ****************************************************************************/
296 AcpiInstallInitializationHandler (
297 ACPI_INIT_HANDLER Handler,
303 return (AE_BAD_PARAMETER);
306 if (AcpiGbl_InitHandler)
308 return (AE_ALREADY_EXISTS);
311 AcpiGbl_InitHandler = Handler;
315 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
318 /*****************************************************************************
320 * FUNCTION: AcpiPurgeCachedObjects
326 * DESCRIPTION: Empty all caches (delete the cached objects)
328 ****************************************************************************/
331 AcpiPurgeCachedObjects (
334 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
337 (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
338 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
339 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
340 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
342 return_ACPI_STATUS (AE_OK);
345 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
348 /*****************************************************************************
350 * FUNCTION: AcpiInstallInterface
352 * PARAMETERS: InterfaceName - The interface to install
356 * DESCRIPTION: Install an _OSI interface to the global list
358 ****************************************************************************/
361 AcpiInstallInterface (
362 ACPI_STRING InterfaceName)
365 ACPI_INTERFACE_INFO *InterfaceInfo;
368 /* Parameter validation */
370 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
372 return (AE_BAD_PARAMETER);
375 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
376 if (ACPI_FAILURE (Status))
381 /* Check if the interface name is already in the global list */
383 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
387 * The interface already exists in the list. This is OK if the
388 * interface has been marked invalid -- just clear the bit.
390 if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
392 InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
397 Status = AE_ALREADY_EXISTS;
402 /* New interface name, install into the global list */
404 Status = AcpiUtInstallInterface (InterfaceName);
407 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
411 ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
414 /*****************************************************************************
416 * FUNCTION: AcpiRemoveInterface
418 * PARAMETERS: InterfaceName - The interface to remove
422 * DESCRIPTION: Remove an _OSI interface from the global list
424 ****************************************************************************/
427 AcpiRemoveInterface (
428 ACPI_STRING InterfaceName)
433 /* Parameter validation */
435 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
437 return (AE_BAD_PARAMETER);
440 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
441 if (ACPI_FAILURE (Status))
446 Status = AcpiUtRemoveInterface (InterfaceName);
448 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
452 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
455 /*****************************************************************************
457 * FUNCTION: AcpiInstallInterfaceHandler
459 * PARAMETERS: Handler - The _OSI interface handler to install
460 * NULL means "remove existing handler"
464 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
465 * invoked during execution of the internal implementation of
466 * _OSI. A NULL handler simply removes any existing handler.
468 ****************************************************************************/
471 AcpiInstallInterfaceHandler (
472 ACPI_INTERFACE_HANDLER Handler)
477 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
478 if (ACPI_FAILURE (Status))
483 if (Handler && AcpiGbl_InterfaceHandler)
485 Status = AE_ALREADY_EXISTS;
489 AcpiGbl_InterfaceHandler = Handler;
492 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
496 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
499 /*****************************************************************************
501 * FUNCTION: AcpiUpdateInterfaces
503 * PARAMETERS: Action - Actions to be performed during the
508 * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
509 * string or/and feature group strings.
511 ****************************************************************************/
514 AcpiUpdateInterfaces (
520 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
521 if (ACPI_FAILURE (Status))
526 Status = AcpiUtUpdateInterfaces (Action);
528 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
533 /*****************************************************************************
535 * FUNCTION: AcpiCheckAddressRange
537 * PARAMETERS: SpaceId - Address space ID
538 * Address - Start address
540 * Warn - TRUE if warning on overlap desired
542 * RETURN: Count of the number of conflicts detected.
544 * DESCRIPTION: Check if the input address range overlaps any of the
545 * ASL operation region address ranges.
547 ****************************************************************************/
550 AcpiCheckAddressRange (
551 ACPI_ADR_SPACE_TYPE SpaceId,
552 ACPI_PHYSICAL_ADDRESS Address,
560 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
561 if (ACPI_FAILURE (Status))
566 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
567 (UINT32) Length, Warn);
569 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
573 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
575 #endif /* !ACPI_ASL_COMPILER */
578 /*******************************************************************************
580 * FUNCTION: AcpiDecodePldBuffer
582 * PARAMETERS: InBuffer - Buffer returned by _PLD method
583 * Length - Length of the InBuffer
584 * ReturnBuffer - Where the decode buffer is returned
586 * RETURN: Status and the decoded _PLD buffer. User must deallocate
587 * the buffer via ACPI_FREE.
589 * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
590 * a local struct that is much more useful to an ACPI driver.
592 ******************************************************************************/
595 AcpiDecodePldBuffer (
598 ACPI_PLD_INFO **ReturnBuffer)
600 ACPI_PLD_INFO *PldInfo;
601 UINT32 *Buffer = ACPI_CAST_PTR (UINT32, InBuffer);
605 /* Parameter validation */
607 if (!InBuffer || !ReturnBuffer || (Length < 16))
609 return (AE_BAD_PARAMETER);
612 PldInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO));
615 return (AE_NO_MEMORY);
618 /* First 32-bit DWord */
620 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[0]);
621 PldInfo->Revision = ACPI_PLD_GET_REVISION (&Dword);
622 PldInfo->IgnoreColor = ACPI_PLD_GET_IGNORE_COLOR (&Dword);
623 PldInfo->Red = ACPI_PLD_GET_RED (&Dword);
624 PldInfo->Green = ACPI_PLD_GET_GREEN (&Dword);
625 PldInfo->Blue = ACPI_PLD_GET_BLUE (&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)