1 /******************************************************************************
3 * Module Name: utxface - External interfaces, miscellaneous utility functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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
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 /* Shutdown and free all resources */
78 AcpiUtSubsystemShutdown ();
80 /* Free the mutex objects */
82 AcpiUtMutexTerminate ();
84 /* Now we can shutdown the OS-dependent layer */
86 Status
= AcpiOsTerminate ();
87 return_ACPI_STATUS (Status
);
90 ACPI_EXPORT_SYMBOL_INIT (AcpiTerminate
)
93 #ifndef ACPI_ASL_COMPILER
94 /*******************************************************************************
96 * FUNCTION: AcpiSubsystemStatus
100 * RETURN: Status of the ACPI subsystem
102 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
103 * before making any other calls, to ensure the subsystem
104 * initialized successfully.
106 ******************************************************************************/
109 AcpiSubsystemStatus (
113 if (AcpiGbl_StartupFlags
& ACPI_INITIALIZED_OK
)
123 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus
)
126 /*******************************************************************************
128 * FUNCTION: AcpiGetSystemInfo
130 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
133 * RETURN: Status - the status of the call
135 * DESCRIPTION: This function is called to get information about the current
136 * state of the ACPI subsystem. It will return system information
139 * If the function fails an appropriate status will be returned
140 * and the value of OutBuffer is undefined.
142 ******************************************************************************/
146 ACPI_BUFFER
*OutBuffer
)
148 ACPI_SYSTEM_INFO
*InfoPtr
;
152 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo
);
155 /* Parameter validation */
157 Status
= AcpiUtValidateBuffer (OutBuffer
);
158 if (ACPI_FAILURE (Status
))
160 return_ACPI_STATUS (Status
);
163 /* Validate/Allocate/Clear caller buffer */
165 Status
= AcpiUtInitializeBuffer (OutBuffer
, sizeof (ACPI_SYSTEM_INFO
));
166 if (ACPI_FAILURE (Status
))
168 return_ACPI_STATUS (Status
);
172 * Populate the return buffer
174 InfoPtr
= (ACPI_SYSTEM_INFO
*) OutBuffer
->Pointer
;
175 InfoPtr
->AcpiCaVersion
= ACPI_CA_VERSION
;
177 /* System flags (ACPI capabilities) */
179 InfoPtr
->Flags
= ACPI_SYS_MODE_ACPI
;
181 /* Timer resolution - 24 or 32 bits */
183 if (AcpiGbl_FADT
.Flags
& ACPI_FADT_32BIT_TIMER
)
185 InfoPtr
->TimerResolution
= 24;
189 InfoPtr
->TimerResolution
= 32;
192 /* Clear the reserved fields */
194 InfoPtr
->Reserved1
= 0;
195 InfoPtr
->Reserved2
= 0;
197 /* Current debug levels */
199 InfoPtr
->DebugLayer
= AcpiDbgLayer
;
200 InfoPtr
->DebugLevel
= AcpiDbgLevel
;
202 return_ACPI_STATUS (AE_OK
);
205 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo
)
208 /*******************************************************************************
210 * FUNCTION: AcpiGetStatistics
212 * PARAMETERS: Stats - Where the statistics are returned
214 * RETURN: Status - the status of the call
216 * DESCRIPTION: Get the contents of the various system counters
218 ******************************************************************************/
222 ACPI_STATISTICS
*Stats
)
224 ACPI_FUNCTION_TRACE (AcpiGetStatistics
);
227 /* Parameter validation */
231 return_ACPI_STATUS (AE_BAD_PARAMETER
);
234 /* Various interrupt-based event counters */
236 Stats
->SciCount
= AcpiSciCount
;
237 Stats
->GpeCount
= AcpiGpeCount
;
239 memcpy (Stats
->FixedEventCount
, AcpiFixedEventCount
,
240 sizeof (AcpiFixedEventCount
));
244 Stats
->MethodCount
= AcpiMethodCount
;
245 return_ACPI_STATUS (AE_OK
);
248 ACPI_EXPORT_SYMBOL (AcpiGetStatistics
)
251 /*****************************************************************************
253 * FUNCTION: AcpiInstallInitializationHandler
255 * PARAMETERS: Handler - Callback procedure
256 * Function - Not (currently) used, see below
260 * DESCRIPTION: Install an initialization handler
262 * TBD: When a second function is added, must save the Function also.
264 ****************************************************************************/
267 AcpiInstallInitializationHandler (
268 ACPI_INIT_HANDLER Handler
,
274 return (AE_BAD_PARAMETER
);
277 if (AcpiGbl_InitHandler
)
279 return (AE_ALREADY_EXISTS
);
282 AcpiGbl_InitHandler
= Handler
;
286 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler
)
289 /*****************************************************************************
291 * FUNCTION: AcpiPurgeCachedObjects
297 * DESCRIPTION: Empty all caches (delete the cached objects)
299 ****************************************************************************/
302 AcpiPurgeCachedObjects (
305 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects
);
308 (void) AcpiOsPurgeCache (AcpiGbl_StateCache
);
309 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache
);
310 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache
);
311 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache
);
313 return_ACPI_STATUS (AE_OK
);
316 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects
)
319 /*****************************************************************************
321 * FUNCTION: AcpiInstallInterface
323 * PARAMETERS: InterfaceName - The interface to install
327 * DESCRIPTION: Install an _OSI interface to the global list
329 ****************************************************************************/
332 AcpiInstallInterface (
333 ACPI_STRING InterfaceName
)
336 ACPI_INTERFACE_INFO
*InterfaceInfo
;
339 /* Parameter validation */
341 if (!InterfaceName
|| (strlen (InterfaceName
) == 0))
343 return (AE_BAD_PARAMETER
);
346 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
347 if (ACPI_FAILURE (Status
))
352 /* Check if the interface name is already in the global list */
354 InterfaceInfo
= AcpiUtGetInterface (InterfaceName
);
358 * The interface already exists in the list. This is OK if the
359 * interface has been marked invalid -- just clear the bit.
361 if (InterfaceInfo
->Flags
& ACPI_OSI_INVALID
)
363 InterfaceInfo
->Flags
&= ~ACPI_OSI_INVALID
;
368 Status
= AE_ALREADY_EXISTS
;
373 /* New interface name, install into the global list */
375 Status
= AcpiUtInstallInterface (InterfaceName
);
378 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
382 ACPI_EXPORT_SYMBOL (AcpiInstallInterface
)
385 /*****************************************************************************
387 * FUNCTION: AcpiRemoveInterface
389 * PARAMETERS: InterfaceName - The interface to remove
393 * DESCRIPTION: Remove an _OSI interface from the global list
395 ****************************************************************************/
398 AcpiRemoveInterface (
399 ACPI_STRING InterfaceName
)
404 /* Parameter validation */
406 if (!InterfaceName
|| (strlen (InterfaceName
) == 0))
408 return (AE_BAD_PARAMETER
);
411 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
412 if (ACPI_FAILURE (Status
))
417 Status
= AcpiUtRemoveInterface (InterfaceName
);
419 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
423 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface
)
426 /*****************************************************************************
428 * FUNCTION: AcpiInstallInterfaceHandler
430 * PARAMETERS: Handler - The _OSI interface handler to install
431 * NULL means "remove existing handler"
435 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
436 * invoked during execution of the internal implementation of
437 * _OSI. A NULL handler simply removes any existing handler.
439 ****************************************************************************/
442 AcpiInstallInterfaceHandler (
443 ACPI_INTERFACE_HANDLER Handler
)
448 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
449 if (ACPI_FAILURE (Status
))
454 if (Handler
&& AcpiGbl_InterfaceHandler
)
456 Status
= AE_ALREADY_EXISTS
;
460 AcpiGbl_InterfaceHandler
= Handler
;
463 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
467 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler
)
470 /*****************************************************************************
472 * FUNCTION: AcpiUpdateInterfaces
474 * PARAMETERS: Action - Actions to be performed during the
479 * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
480 * string or/and feature group strings.
482 ****************************************************************************/
485 AcpiUpdateInterfaces (
491 Status
= AcpiOsAcquireMutex (AcpiGbl_OsiMutex
, ACPI_WAIT_FOREVER
);
492 if (ACPI_FAILURE (Status
))
497 Status
= AcpiUtUpdateInterfaces (Action
);
499 AcpiOsReleaseMutex (AcpiGbl_OsiMutex
);
504 /*****************************************************************************
506 * FUNCTION: AcpiCheckAddressRange
508 * PARAMETERS: SpaceId - Address space ID
509 * Address - Start address
511 * Warn - TRUE if warning on overlap desired
513 * RETURN: Count of the number of conflicts detected.
515 * DESCRIPTION: Check if the input address range overlaps any of the
516 * ASL operation region address ranges.
518 ****************************************************************************/
521 AcpiCheckAddressRange (
522 ACPI_ADR_SPACE_TYPE SpaceId
,
523 ACPI_PHYSICAL_ADDRESS Address
,
531 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
532 if (ACPI_FAILURE (Status
))
537 Overlaps
= AcpiUtCheckAddressRange (SpaceId
, Address
,
538 (UINT32
) Length
, Warn
);
540 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
544 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange
)
546 #endif /* !ACPI_ASL_COMPILER */
549 /*******************************************************************************
551 * FUNCTION: AcpiDecodePldBuffer
553 * PARAMETERS: InBuffer - Buffer returned by _PLD method
554 * Length - Length of the InBuffer
555 * ReturnBuffer - Where the decode buffer is returned
557 * RETURN: Status and the decoded _PLD buffer. User must deallocate
558 * the buffer via ACPI_FREE.
560 * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
561 * a local struct that is much more useful to an ACPI driver.
563 ******************************************************************************/
566 AcpiDecodePldBuffer (
569 ACPI_PLD_INFO
**ReturnBuffer
)
571 ACPI_PLD_INFO
*PldInfo
;
572 UINT32
*Buffer
= ACPI_CAST_PTR (UINT32
, InBuffer
);
576 /* Parameter validation */
578 if (!InBuffer
|| !ReturnBuffer
|| (Length
< ACPI_PLD_REV1_BUFFER_SIZE
))
580 return (AE_BAD_PARAMETER
);
583 PldInfo
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO
));
586 return (AE_NO_MEMORY
);
589 /* First 32-bit DWord */
591 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[0]);
592 PldInfo
->Revision
= ACPI_PLD_GET_REVISION (&Dword
);
593 PldInfo
->IgnoreColor
= ACPI_PLD_GET_IGNORE_COLOR (&Dword
);
594 PldInfo
->Red
= ACPI_PLD_GET_RED (&Dword
);
595 PldInfo
->Green
= ACPI_PLD_GET_GREEN (&Dword
);
596 PldInfo
->Blue
= ACPI_PLD_GET_BLUE (&Dword
);
598 /* Second 32-bit DWord */
600 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[1]);
601 PldInfo
->Width
= ACPI_PLD_GET_WIDTH (&Dword
);
602 PldInfo
->Height
= ACPI_PLD_GET_HEIGHT(&Dword
);
604 /* Third 32-bit DWord */
606 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[2]);
607 PldInfo
->UserVisible
= ACPI_PLD_GET_USER_VISIBLE (&Dword
);
608 PldInfo
->Dock
= ACPI_PLD_GET_DOCK (&Dword
);
609 PldInfo
->Lid
= ACPI_PLD_GET_LID (&Dword
);
610 PldInfo
->Panel
= ACPI_PLD_GET_PANEL (&Dword
);
611 PldInfo
->VerticalPosition
= ACPI_PLD_GET_VERTICAL (&Dword
);
612 PldInfo
->HorizontalPosition
= ACPI_PLD_GET_HORIZONTAL (&Dword
);
613 PldInfo
->Shape
= ACPI_PLD_GET_SHAPE (&Dword
);
614 PldInfo
->GroupOrientation
= ACPI_PLD_GET_ORIENTATION (&Dword
);
615 PldInfo
->GroupToken
= ACPI_PLD_GET_TOKEN (&Dword
);
616 PldInfo
->GroupPosition
= ACPI_PLD_GET_POSITION (&Dword
);
617 PldInfo
->Bay
= ACPI_PLD_GET_BAY (&Dword
);
619 /* Fourth 32-bit DWord */
621 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[3]);
622 PldInfo
->Ejectable
= ACPI_PLD_GET_EJECTABLE (&Dword
);
623 PldInfo
->OspmEjectRequired
= ACPI_PLD_GET_OSPM_EJECT (&Dword
);
624 PldInfo
->CabinetNumber
= ACPI_PLD_GET_CABINET (&Dword
);
625 PldInfo
->CardCageNumber
= ACPI_PLD_GET_CARD_CAGE (&Dword
);
626 PldInfo
->Reference
= ACPI_PLD_GET_REFERENCE (&Dword
);
627 PldInfo
->Rotation
= ACPI_PLD_GET_ROTATION (&Dword
);
628 PldInfo
->Order
= ACPI_PLD_GET_ORDER (&Dword
);
630 if (Length
>= ACPI_PLD_REV2_BUFFER_SIZE
)
632 /* Fifth 32-bit DWord (Revision 2 of _PLD) */
634 ACPI_MOVE_32_TO_32 (&Dword
, &Buffer
[4]);
635 PldInfo
->VerticalOffset
= ACPI_PLD_GET_VERT_OFFSET (&Dword
);
636 PldInfo
->HorizontalOffset
= ACPI_PLD_GET_HORIZ_OFFSET (&Dword
);
639 *ReturnBuffer
= PldInfo
;
643 ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer
)