dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / uts / intel / io / acpica / utilities / utxface.c
bloba8452c32955b685dee0b020fe9b5332d05fa4f47
1 /******************************************************************************
3 * Module Name: utxface - External interfaces, miscellaneous utility functions
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, 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.
44 #define EXPORT_ACPI_INTERFACES
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acdebug.h"
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("utxface")
54 /*******************************************************************************
56 * FUNCTION: AcpiTerminate
58 * PARAMETERS: None
60 * RETURN: Status
62 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
64 ******************************************************************************/
66 ACPI_STATUS
67 AcpiTerminate (
68 void)
70 ACPI_STATUS Status;
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
98 * PARAMETERS: None
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 ******************************************************************************/
108 ACPI_STATUS
109 AcpiSubsystemStatus (
110 void)
113 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
115 return (AE_OK);
117 else
119 return (AE_ERROR);
123 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
126 /*******************************************************************************
128 * FUNCTION: AcpiGetSystemInfo
130 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
131 * device
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
137 * in the OutBuffer.
139 * If the function fails an appropriate status will be returned
140 * and the value of OutBuffer is undefined.
142 ******************************************************************************/
144 ACPI_STATUS
145 AcpiGetSystemInfo (
146 ACPI_BUFFER *OutBuffer)
148 ACPI_SYSTEM_INFO *InfoPtr;
149 ACPI_STATUS Status;
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;
187 else
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 ******************************************************************************/
220 ACPI_STATUS
221 AcpiGetStatistics (
222 ACPI_STATISTICS *Stats)
224 ACPI_FUNCTION_TRACE (AcpiGetStatistics);
227 /* Parameter validation */
229 if (!Stats)
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));
242 /* Other counters */
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
258 * RETURN: Status
260 * DESCRIPTION: Install an initialization handler
262 * TBD: When a second function is added, must save the Function also.
264 ****************************************************************************/
266 ACPI_STATUS
267 AcpiInstallInitializationHandler (
268 ACPI_INIT_HANDLER Handler,
269 UINT32 Function)
272 if (!Handler)
274 return (AE_BAD_PARAMETER);
277 if (AcpiGbl_InitHandler)
279 return (AE_ALREADY_EXISTS);
282 AcpiGbl_InitHandler = Handler;
283 return (AE_OK);
286 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
289 /*****************************************************************************
291 * FUNCTION: AcpiPurgeCachedObjects
293 * PARAMETERS: None
295 * RETURN: Status
297 * DESCRIPTION: Empty all caches (delete the cached objects)
299 ****************************************************************************/
301 ACPI_STATUS
302 AcpiPurgeCachedObjects (
303 void)
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
325 * RETURN: Status
327 * DESCRIPTION: Install an _OSI interface to the global list
329 ****************************************************************************/
331 ACPI_STATUS
332 AcpiInstallInterface (
333 ACPI_STRING InterfaceName)
335 ACPI_STATUS Status;
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))
349 return (Status);
352 /* Check if the interface name is already in the global list */
354 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
355 if (InterfaceInfo)
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;
364 Status = AE_OK;
366 else
368 Status = AE_ALREADY_EXISTS;
371 else
373 /* New interface name, install into the global list */
375 Status = AcpiUtInstallInterface (InterfaceName);
378 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
379 return (Status);
382 ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
385 /*****************************************************************************
387 * FUNCTION: AcpiRemoveInterface
389 * PARAMETERS: InterfaceName - The interface to remove
391 * RETURN: Status
393 * DESCRIPTION: Remove an _OSI interface from the global list
395 ****************************************************************************/
397 ACPI_STATUS
398 AcpiRemoveInterface (
399 ACPI_STRING InterfaceName)
401 ACPI_STATUS Status;
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))
414 return (Status);
417 Status = AcpiUtRemoveInterface (InterfaceName);
419 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
420 return (Status);
423 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
426 /*****************************************************************************
428 * FUNCTION: AcpiInstallInterfaceHandler
430 * PARAMETERS: Handler - The _OSI interface handler to install
431 * NULL means "remove existing handler"
433 * RETURN: Status
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 ****************************************************************************/
441 ACPI_STATUS
442 AcpiInstallInterfaceHandler (
443 ACPI_INTERFACE_HANDLER Handler)
445 ACPI_STATUS Status;
448 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
449 if (ACPI_FAILURE (Status))
451 return (Status);
454 if (Handler && AcpiGbl_InterfaceHandler)
456 Status = AE_ALREADY_EXISTS;
458 else
460 AcpiGbl_InterfaceHandler = Handler;
463 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
464 return (Status);
467 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
470 /*****************************************************************************
472 * FUNCTION: AcpiUpdateInterfaces
474 * PARAMETERS: Action - Actions to be performed during the
475 * update
477 * RETURN: Status
479 * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
480 * string or/and feature group strings.
482 ****************************************************************************/
484 ACPI_STATUS
485 AcpiUpdateInterfaces (
486 UINT8 Action)
488 ACPI_STATUS Status;
491 Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
492 if (ACPI_FAILURE (Status))
494 return (Status);
497 Status = AcpiUtUpdateInterfaces (Action);
499 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
500 return (Status);
504 /*****************************************************************************
506 * FUNCTION: AcpiCheckAddressRange
508 * PARAMETERS: SpaceId - Address space ID
509 * Address - Start address
510 * Length - Length
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 ****************************************************************************/
520 UINT32
521 AcpiCheckAddressRange (
522 ACPI_ADR_SPACE_TYPE SpaceId,
523 ACPI_PHYSICAL_ADDRESS Address,
524 ACPI_SIZE Length,
525 BOOLEAN Warn)
527 UINT32 Overlaps;
528 ACPI_STATUS Status;
531 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
532 if (ACPI_FAILURE (Status))
534 return (0);
537 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
538 (UINT32) Length, Warn);
540 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
541 return (Overlaps);
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 ******************************************************************************/
565 ACPI_STATUS
566 AcpiDecodePldBuffer (
567 UINT8 *InBuffer,
568 ACPI_SIZE Length,
569 ACPI_PLD_INFO **ReturnBuffer)
571 ACPI_PLD_INFO *PldInfo;
572 UINT32 *Buffer = ACPI_CAST_PTR (UINT32, InBuffer);
573 UINT32 Dword;
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));
584 if (!PldInfo)
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;
640 return (AE_OK);
643 ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer)