Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / components / utilities / utxface.c
bloba093ec69df470a2fe3adecce3d1833a748e9aac2
1 /******************************************************************************
3 * Module Name: utxface - External interfaces, miscellaneous utility functions
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 __UTXFACE_C__
46 #define EXPORT_ACPI_INTERFACES
48 #include "acpi.h"
49 #include "accommon.h"
50 #include "acdebug.h"
52 #define _COMPONENT ACPI_UTILITIES
53 ACPI_MODULE_NAME ("utxface")
56 /*******************************************************************************
58 * FUNCTION: AcpiTerminate
60 * PARAMETERS: None
62 * RETURN: Status
64 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
66 ******************************************************************************/
68 ACPI_STATUS
69 AcpiTerminate (
70 void)
72 ACPI_STATUS Status;
75 ACPI_FUNCTION_TRACE (AcpiTerminate);
78 /* Just exit if subsystem is already shutdown */
80 if (AcpiGbl_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 ();
105 #ifdef ACPI_DEBUGGER
107 /* Shut down the debugger */
109 AcpiDbTerminate ();
110 #endif
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
126 * PARAMETERS: None
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 ******************************************************************************/
136 ACPI_STATUS
137 AcpiSubsystemStatus (
138 void)
141 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
143 return (AE_OK);
145 else
147 return (AE_ERROR);
151 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
154 /*******************************************************************************
156 * FUNCTION: AcpiGetSystemInfo
158 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
159 * device
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
165 * in the OutBuffer.
167 * If the function fails an appropriate status will be returned
168 * and the value of OutBuffer is undefined.
170 ******************************************************************************/
172 ACPI_STATUS
173 AcpiGetSystemInfo (
174 ACPI_BUFFER *OutBuffer)
176 ACPI_SYSTEM_INFO *InfoPtr;
177 ACPI_STATUS Status;
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;
216 else
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 ******************************************************************************/
249 ACPI_STATUS
250 AcpiGetStatistics (
251 ACPI_STATISTICS *Stats)
253 ACPI_FUNCTION_TRACE (AcpiGetStatistics);
256 /* Parameter validation */
258 if (!Stats)
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));
272 /* Other counters */
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
289 * RETURN: Status
291 * DESCRIPTION: Install an initialization handler
293 * TBD: When a second function is added, must save the Function also.
295 ****************************************************************************/
297 ACPI_STATUS
298 AcpiInstallInitializationHandler (
299 ACPI_INIT_HANDLER Handler,
300 UINT32 Function)
303 if (!Handler)
305 return (AE_BAD_PARAMETER);
308 if (AcpiGbl_InitHandler)
310 return (AE_ALREADY_EXISTS);
313 AcpiGbl_InitHandler = Handler;
314 return (AE_OK);
317 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
320 /*****************************************************************************
322 * FUNCTION: AcpiPurgeCachedObjects
324 * PARAMETERS: None
326 * RETURN: Status
328 * DESCRIPTION: Empty all caches (delete the cached objects)
330 ****************************************************************************/
332 ACPI_STATUS
333 AcpiPurgeCachedObjects (
334 void)
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
356 * RETURN: Status
358 * DESCRIPTION: Install an _OSI interface to the global list
360 ****************************************************************************/
362 ACPI_STATUS
363 AcpiInstallInterface (
364 ACPI_STRING InterfaceName)
366 ACPI_STATUS Status;
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))
380 return (Status);
383 /* Check if the interface name is already in the global list */
385 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
386 if (InterfaceInfo)
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;
395 Status = AE_OK;
397 else
399 Status = AE_ALREADY_EXISTS;
402 else
404 /* New interface name, install into the global list */
406 Status = AcpiUtInstallInterface (InterfaceName);
409 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
410 return (Status);
413 ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
416 /*****************************************************************************
418 * FUNCTION: AcpiRemoveInterface
420 * PARAMETERS: InterfaceName - The interface to remove
422 * RETURN: Status
424 * DESCRIPTION: Remove an _OSI interface from the global list
426 ****************************************************************************/
428 ACPI_STATUS
429 AcpiRemoveInterface (
430 ACPI_STRING InterfaceName)
432 ACPI_STATUS Status;
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))
445 return (Status);
448 Status = AcpiUtRemoveInterface (InterfaceName);
450 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
451 return (Status);
454 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
457 /*****************************************************************************
459 * FUNCTION: AcpiInstallInterfaceHandler
461 * PARAMETERS: Handler - The _OSI interface handler to install
462 * NULL means "remove existing handler"
464 * RETURN: Status
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 ****************************************************************************/
472 ACPI_STATUS
473 AcpiInstallInterfaceHandler (
474 ACPI_INTERFACE_HANDLER Handler)
476 ACPI_STATUS Status;
479 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
480 if (ACPI_FAILURE (Status))
482 return (Status);
485 if (Handler && AcpiGbl_InterfaceHandler)
487 Status = AE_ALREADY_EXISTS;
489 else
491 AcpiGbl_InterfaceHandler = Handler;
494 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
495 return (Status);
498 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
501 /*****************************************************************************
503 * FUNCTION: AcpiUpdateInterfaces
505 * PARAMETERS: Action - Actions to be performed during the
506 * update
508 * RETURN: Status
510 * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
511 * string or/and feature group strings.
513 ****************************************************************************/
515 ACPI_STATUS
516 AcpiUpdateInterfaces (
517 UINT8 Action)
519 ACPI_STATUS Status;
522 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
523 if (ACPI_FAILURE (Status))
525 return (Status);
528 Status = AcpiUtUpdateInterfaces (Action);
530 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
531 return (Status);
535 /*****************************************************************************
537 * FUNCTION: AcpiCheckAddressRange
539 * PARAMETERS: SpaceId - Address space ID
540 * Address - Start address
541 * Length - Length
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 ****************************************************************************/
551 UINT32
552 AcpiCheckAddressRange (
553 ACPI_ADR_SPACE_TYPE SpaceId,
554 ACPI_PHYSICAL_ADDRESS Address,
555 ACPI_SIZE Length,
556 BOOLEAN Warn)
558 UINT32 Overlaps;
559 ACPI_STATUS Status;
562 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
563 if (ACPI_FAILURE (Status))
565 return (0);
568 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
569 (UINT32) Length, Warn);
571 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
572 return (Overlaps);
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 ******************************************************************************/
596 ACPI_STATUS
597 AcpiDecodePldBuffer (
598 UINT8 *InBuffer,
599 ACPI_SIZE Length,
600 ACPI_PLD_INFO **ReturnBuffer)
602 ACPI_PLD_INFO *PldInfo;
603 UINT32 *Buffer = ACPI_CAST_PTR (UINT32, InBuffer);
604 UINT32 Dword;
607 /* Parameter validation */
609 if (!InBuffer || !ReturnBuffer || (Length < 16))
611 return (AE_BAD_PARAMETER);
614 PldInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO));
615 if (!PldInfo)
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;
669 return (AE_OK);
672 ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer)