1 /******************************************************************************
3 * Module Name: utxface - External interfaces, miscellaneous utility functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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.
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acdebug.h>
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 (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);
337 (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
338 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
339 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
340 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
341 return_ACPI_STATUS (AE_OK);
344 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
347 /*****************************************************************************
349 * FUNCTION: AcpiInstallInterface
351 * PARAMETERS: InterfaceName - The interface to install
355 * DESCRIPTION: Install an _OSI interface to the global list
357 ****************************************************************************/
360 AcpiInstallInterface (
361 ACPI_STRING InterfaceName)
364 ACPI_INTERFACE_INFO *InterfaceInfo;
367 /* Parameter validation */
369 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
371 return (AE_BAD_PARAMETER);
374 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
376 /* Check if the interface name is already in the global list */
378 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
382 * The interface already exists in the list. This is OK if the
383 * interface has been marked invalid -- just clear the bit.
385 if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
387 InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
392 Status = AE_ALREADY_EXISTS;
397 /* New interface name, install into the global list */
399 Status = AcpiUtInstallInterface (InterfaceName);
402 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
406 ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
409 /*****************************************************************************
411 * FUNCTION: AcpiRemoveInterface
413 * PARAMETERS: InterfaceName - The interface to remove
417 * DESCRIPTION: Remove an _OSI interface from the global list
419 ****************************************************************************/
422 AcpiRemoveInterface (
423 ACPI_STRING InterfaceName)
428 /* Parameter validation */
430 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
432 return (AE_BAD_PARAMETER);
435 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
437 Status = AcpiUtRemoveInterface (InterfaceName);
439 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
443 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
446 /*****************************************************************************
448 * FUNCTION: AcpiInstallInterfaceHandler
450 * PARAMETERS: Handler - The _OSI interface handler to install
451 * NULL means "remove existing handler"
455 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
456 * invoked during execution of the internal implementation of
457 * _OSI. A NULL handler simply removes any existing handler.
459 ****************************************************************************/
462 AcpiInstallInterfaceHandler (
463 ACPI_INTERFACE_HANDLER Handler)
465 ACPI_STATUS Status = AE_OK;
468 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
470 if (Handler && AcpiGbl_InterfaceHandler)
472 Status = AE_ALREADY_EXISTS;
476 AcpiGbl_InterfaceHandler = Handler;
479 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
483 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
486 /*****************************************************************************
488 * FUNCTION: AcpiCheckAddressRange
490 * PARAMETERS: SpaceId - Address space ID
491 * Address - Start address
493 * Warn - TRUE if warning on overlap desired
495 * RETURN: Count of the number of conflicts detected.
497 * DESCRIPTION: Check if the input address range overlaps any of the
498 * ASL operation region address ranges.
500 ****************************************************************************/
503 AcpiCheckAddressRange (
504 ACPI_ADR_SPACE_TYPE SpaceId,
505 ACPI_PHYSICAL_ADDRESS Address,
513 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
514 if (ACPI_FAILURE (Status))
519 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
520 (UINT32) Length, Warn);
522 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
526 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
528 #endif /* !ACPI_ASL_COMPILER */
531 /*******************************************************************************
533 * FUNCTION: AcpiDecodePldBuffer
535 * PARAMETERS: InBuffer - Buffer returned by _PLD method
536 * Length - Length of the InBuffer
537 * ReturnBuffer - Where the decode buffer is returned
539 * RETURN: Status and the decoded _PLD buffer. User must deallocate
540 * the buffer via ACPI_FREE.
542 * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
543 * a local struct that is much more useful to an ACPI driver.
545 ******************************************************************************/
548 AcpiDecodePldBuffer (
551 ACPI_PLD_INFO **ReturnBuffer)
553 ACPI_PLD_INFO *PldInfo;
554 UINT32 *Buffer = ACPI_CAST_PTR (UINT32, InBuffer);
558 /* Parameter validation */
560 if (!InBuffer || !ReturnBuffer || (Length < 16))
562 return (AE_BAD_PARAMETER);
565 PldInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO));
568 return (AE_NO_MEMORY);
571 /* First 32-bit DWord */
573 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[0]);
574 PldInfo->Revision = ACPI_PLD_GET_REVISION (&Dword);
575 PldInfo->IgnoreColor = ACPI_PLD_GET_IGNORE_COLOR (&Dword);
576 PldInfo->Color = ACPI_PLD_GET_COLOR (&Dword);
578 /* Second 32-bit DWord */
580 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[1]);
581 PldInfo->Width = ACPI_PLD_GET_WIDTH (&Dword);
582 PldInfo->Height = ACPI_PLD_GET_HEIGHT(&Dword);
584 /* Third 32-bit DWord */
586 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[2]);
587 PldInfo->UserVisible = ACPI_PLD_GET_USER_VISIBLE (&Dword);
588 PldInfo->Dock = ACPI_PLD_GET_DOCK (&Dword);
589 PldInfo->Lid = ACPI_PLD_GET_LID (&Dword);
590 PldInfo->Panel = ACPI_PLD_GET_PANEL (&Dword);
591 PldInfo->VerticalPosition = ACPI_PLD_GET_VERTICAL (&Dword);
592 PldInfo->HorizontalPosition = ACPI_PLD_GET_HORIZONTAL (&Dword);
593 PldInfo->Shape = ACPI_PLD_GET_SHAPE (&Dword);
594 PldInfo->GroupOrientation = ACPI_PLD_GET_ORIENTATION (&Dword);
595 PldInfo->GroupToken = ACPI_PLD_GET_TOKEN (&Dword);
596 PldInfo->GroupPosition = ACPI_PLD_GET_POSITION (&Dword);
597 PldInfo->Bay = ACPI_PLD_GET_BAY (&Dword);
599 /* Fourth 32-bit DWord */
601 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[3]);
602 PldInfo->Ejectable = ACPI_PLD_GET_EJECTABLE (&Dword);
603 PldInfo->OspmEjectRequired = ACPI_PLD_GET_OSPM_EJECT (&Dword);
604 PldInfo->CabinetNumber = ACPI_PLD_GET_CABINET (&Dword);
605 PldInfo->CardCageNumber = ACPI_PLD_GET_CARD_CAGE (&Dword);
606 PldInfo->Reference = ACPI_PLD_GET_REFERENCE (&Dword);
607 PldInfo->Rotation = ACPI_PLD_GET_ROTATION (&Dword);
608 PldInfo->Order = ACPI_PLD_GET_ORDER (&Dword);
610 if (Length >= ACPI_PLD_BUFFER_SIZE)
612 /* Fifth 32-bit DWord (Revision 2 of _PLD) */
614 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[4]);
615 PldInfo->VerticalOffset = ACPI_PLD_GET_VERT_OFFSET (&Dword);
616 PldInfo->HorizontalOffset = ACPI_PLD_GET_HORIZ_OFFSET (&Dword);
619 *ReturnBuffer = PldInfo;
623 ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer)