Path: blob/main/sys/contrib/dev/acpica/components/utilities/utxface.c
48406 views
/******************************************************************************1*2* Module Name: utxface - External interfaces, miscellaneous utility functions3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#define EXPORT_ACPI_INTERFACES152153#include <contrib/dev/acpica/include/acpi.h>154#include <contrib/dev/acpica/include/accommon.h>155#include <contrib/dev/acpica/include/acdebug.h>156157#define _COMPONENT ACPI_UTILITIES158ACPI_MODULE_NAME ("utxface")159160161/*******************************************************************************162*163* FUNCTION: AcpiTerminate164*165* PARAMETERS: None166*167* RETURN: Status168*169* DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.170*171******************************************************************************/172173ACPI_STATUS ACPI_INIT_FUNCTION174AcpiTerminate (175void)176{177ACPI_STATUS Status;178179180ACPI_FUNCTION_TRACE (AcpiTerminate);181182183/* Shutdown and free all resources */184185AcpiUtSubsystemShutdown ();186187/* Free the mutex objects */188189AcpiUtMutexTerminate ();190191/* Now we can shutdown the OS-dependent layer */192193Status = AcpiOsTerminate ();194return_ACPI_STATUS (Status);195}196197ACPI_EXPORT_SYMBOL_INIT (AcpiTerminate)198199200#ifndef ACPI_ASL_COMPILER201/*******************************************************************************202*203* FUNCTION: AcpiSubsystemStatus204*205* PARAMETERS: None206*207* RETURN: Status of the ACPI subsystem208*209* DESCRIPTION: Other drivers that use the ACPI subsystem should call this210* before making any other calls, to ensure the subsystem211* initialized successfully.212*213******************************************************************************/214215ACPI_STATUS216AcpiSubsystemStatus (217void)218{219220if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)221{222return (AE_OK);223}224else225{226return (AE_ERROR);227}228}229230ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)231232233/*******************************************************************************234*235* FUNCTION: AcpiGetSystemInfo236*237* PARAMETERS: OutBuffer - A buffer to receive the resources for the238* device239*240* RETURN: Status - the status of the call241*242* DESCRIPTION: This function is called to get information about the current243* state of the ACPI subsystem. It will return system information244* in the OutBuffer.245*246* If the function fails an appropriate status will be returned247* and the value of OutBuffer is undefined.248*249******************************************************************************/250251ACPI_STATUS252AcpiGetSystemInfo (253ACPI_BUFFER *OutBuffer)254{255ACPI_SYSTEM_INFO *InfoPtr;256ACPI_STATUS Status;257258259ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);260261262/* Parameter validation */263264Status = AcpiUtValidateBuffer (OutBuffer);265if (ACPI_FAILURE (Status))266{267return_ACPI_STATUS (Status);268}269270/* Validate/Allocate/Clear caller buffer */271272Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));273if (ACPI_FAILURE (Status))274{275return_ACPI_STATUS (Status);276}277278/*279* Populate the return buffer280*/281InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;282InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;283284/* System flags (ACPI capabilities) */285286InfoPtr->Flags = ACPI_SYS_MODE_ACPI;287288/* Timer resolution - 24 or 32 bits */289290if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)291{292InfoPtr->TimerResolution = 24;293}294else295{296InfoPtr->TimerResolution = 32;297}298299/* Clear the reserved fields */300301InfoPtr->Reserved1 = 0;302InfoPtr->Reserved2 = 0;303304/* Current debug levels */305306InfoPtr->DebugLayer = AcpiDbgLayer;307InfoPtr->DebugLevel = AcpiDbgLevel;308309return_ACPI_STATUS (AE_OK);310}311312ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)313314315/*******************************************************************************316*317* FUNCTION: AcpiGetStatistics318*319* PARAMETERS: Stats - Where the statistics are returned320*321* RETURN: Status - the status of the call322*323* DESCRIPTION: Get the contents of the various system counters324*325******************************************************************************/326327ACPI_STATUS328AcpiGetStatistics (329ACPI_STATISTICS *Stats)330{331ACPI_FUNCTION_TRACE (AcpiGetStatistics);332333334/* Parameter validation */335336if (!Stats)337{338return_ACPI_STATUS (AE_BAD_PARAMETER);339}340341/* Various interrupt-based event counters */342343Stats->SciCount = AcpiSciCount;344Stats->GpeCount = AcpiGpeCount;345346memcpy (Stats->FixedEventCount, AcpiFixedEventCount,347sizeof (AcpiFixedEventCount));348349/* Other counters */350351Stats->MethodCount = AcpiMethodCount;352return_ACPI_STATUS (AE_OK);353}354355ACPI_EXPORT_SYMBOL (AcpiGetStatistics)356357358/*****************************************************************************359*360* FUNCTION: AcpiInstallInitializationHandler361*362* PARAMETERS: Handler - Callback procedure363* Function - Not (currently) used, see below364*365* RETURN: Status366*367* DESCRIPTION: Install an initialization handler368*369* TBD: When a second function is added, must save the Function also.370*371****************************************************************************/372373ACPI_STATUS374AcpiInstallInitializationHandler (375ACPI_INIT_HANDLER Handler,376UINT32 Function)377{378379if (!Handler)380{381return (AE_BAD_PARAMETER);382}383384if (AcpiGbl_InitHandler)385{386return (AE_ALREADY_EXISTS);387}388389AcpiGbl_InitHandler = Handler;390return (AE_OK);391}392393ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)394395396/*****************************************************************************397*398* FUNCTION: AcpiPurgeCachedObjects399*400* PARAMETERS: None401*402* RETURN: Status403*404* DESCRIPTION: Empty all caches (delete the cached objects)405*406****************************************************************************/407408ACPI_STATUS409AcpiPurgeCachedObjects (410void)411{412ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);413414415(void) AcpiOsPurgeCache (AcpiGbl_StateCache);416(void) AcpiOsPurgeCache (AcpiGbl_OperandCache);417(void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);418(void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);419420return_ACPI_STATUS (AE_OK);421}422423ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)424425426/*****************************************************************************427*428* FUNCTION: AcpiInstallInterface429*430* PARAMETERS: InterfaceName - The interface to install431*432* RETURN: Status433*434* DESCRIPTION: Install an _OSI interface to the global list435*436****************************************************************************/437438ACPI_STATUS439AcpiInstallInterface (440ACPI_STRING InterfaceName)441{442ACPI_STATUS Status;443ACPI_INTERFACE_INFO *InterfaceInfo;444445446/* Parameter validation */447448if (!InterfaceName || (strlen (InterfaceName) == 0))449{450return (AE_BAD_PARAMETER);451}452453Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);454if (ACPI_FAILURE (Status))455{456return (Status);457}458459/* Check if the interface name is already in the global list */460461InterfaceInfo = AcpiUtGetInterface (InterfaceName);462if (InterfaceInfo)463{464/*465* The interface already exists in the list. This is OK if the466* interface has been marked invalid -- just clear the bit.467*/468if (InterfaceInfo->Flags & ACPI_OSI_INVALID)469{470InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;471Status = AE_OK;472}473else474{475Status = AE_ALREADY_EXISTS;476}477}478else479{480/* New interface name, install into the global list */481482Status = AcpiUtInstallInterface (InterfaceName);483}484485AcpiOsReleaseMutex (AcpiGbl_OsiMutex);486return (Status);487}488489ACPI_EXPORT_SYMBOL (AcpiInstallInterface)490491492/*****************************************************************************493*494* FUNCTION: AcpiRemoveInterface495*496* PARAMETERS: InterfaceName - The interface to remove497*498* RETURN: Status499*500* DESCRIPTION: Remove an _OSI interface from the global list501*502****************************************************************************/503504ACPI_STATUS505AcpiRemoveInterface (506ACPI_STRING InterfaceName)507{508ACPI_STATUS Status;509510511/* Parameter validation */512513if (!InterfaceName || (strlen (InterfaceName) == 0))514{515return (AE_BAD_PARAMETER);516}517518Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);519if (ACPI_FAILURE (Status))520{521return (Status);522}523524Status = AcpiUtRemoveInterface (InterfaceName);525526AcpiOsReleaseMutex (AcpiGbl_OsiMutex);527return (Status);528}529530ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)531532533/*****************************************************************************534*535* FUNCTION: AcpiInstallInterfaceHandler536*537* PARAMETERS: Handler - The _OSI interface handler to install538* NULL means "remove existing handler"539*540* RETURN: Status541*542* DESCRIPTION: Install a handler for the predefined _OSI ACPI method.543* invoked during execution of the internal implementation of544* _OSI. A NULL handler simply removes any existing handler.545*546****************************************************************************/547548ACPI_STATUS549AcpiInstallInterfaceHandler (550ACPI_INTERFACE_HANDLER Handler)551{552ACPI_STATUS Status;553554555Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);556if (ACPI_FAILURE (Status))557{558return (Status);559}560561if (Handler && AcpiGbl_InterfaceHandler)562{563Status = AE_ALREADY_EXISTS;564}565else566{567AcpiGbl_InterfaceHandler = Handler;568}569570AcpiOsReleaseMutex (AcpiGbl_OsiMutex);571return (Status);572}573574ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)575576577/*****************************************************************************578*579* FUNCTION: AcpiUpdateInterfaces580*581* PARAMETERS: Action - Actions to be performed during the582* update583*584* RETURN: Status585*586* DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor587* string or/and feature group strings.588*589****************************************************************************/590591ACPI_STATUS592AcpiUpdateInterfaces (593UINT8 Action)594{595ACPI_STATUS Status;596597598Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);599if (ACPI_FAILURE (Status))600{601return (Status);602}603604Status = AcpiUtUpdateInterfaces (Action);605606AcpiOsReleaseMutex (AcpiGbl_OsiMutex);607return (Status);608}609610611/*****************************************************************************612*613* FUNCTION: AcpiCheckAddressRange614*615* PARAMETERS: SpaceId - Address space ID616* Address - Start address617* Length - Length618* Warn - TRUE if warning on overlap desired619*620* RETURN: Count of the number of conflicts detected.621*622* DESCRIPTION: Check if the input address range overlaps any of the623* ASL operation region address ranges.624*625****************************************************************************/626627UINT32628AcpiCheckAddressRange (629ACPI_ADR_SPACE_TYPE SpaceId,630ACPI_PHYSICAL_ADDRESS Address,631ACPI_SIZE Length,632BOOLEAN Warn)633{634UINT32 Overlaps;635ACPI_STATUS Status;636637638Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);639if (ACPI_FAILURE (Status))640{641return (0);642}643644Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,645(UINT32) Length, Warn);646647(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);648return (Overlaps);649}650651ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)652653#endif /* !ACPI_ASL_COMPILER */654655656/*******************************************************************************657*658* FUNCTION: AcpiDecodePldBuffer659*660* PARAMETERS: InBuffer - Buffer returned by _PLD method661* Length - Length of the InBuffer662* ReturnBuffer - Where the decode buffer is returned663*664* RETURN: Status and the decoded _PLD buffer. User must deallocate665* the buffer via ACPI_FREE.666*667* DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into668* a local struct that is much more useful to an ACPI driver.669*670******************************************************************************/671672ACPI_STATUS673AcpiDecodePldBuffer (674UINT8 *InBuffer,675ACPI_SIZE Length,676ACPI_PLD_INFO **ReturnBuffer)677{678ACPI_PLD_INFO *PldInfo;679UINT32 *Buffer = ACPI_CAST_PTR (UINT32, InBuffer);680UINT32 Dword;681682683/* Parameter validation */684685if (!InBuffer || !ReturnBuffer || (Length < ACPI_PLD_REV1_BUFFER_SIZE))686{687return (AE_BAD_PARAMETER);688}689690PldInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO));691if (!PldInfo)692{693return (AE_NO_MEMORY);694}695696/* First 32-bit DWord */697698ACPI_MOVE_32_TO_32 (&Dword, &Buffer[0]);699PldInfo->Revision = ACPI_PLD_GET_REVISION (&Dword);700PldInfo->IgnoreColor = ACPI_PLD_GET_IGNORE_COLOR (&Dword);701PldInfo->Red = ACPI_PLD_GET_RED (&Dword);702PldInfo->Green = ACPI_PLD_GET_GREEN (&Dword);703PldInfo->Blue = ACPI_PLD_GET_BLUE (&Dword);704705/* Second 32-bit DWord */706707ACPI_MOVE_32_TO_32 (&Dword, &Buffer[1]);708PldInfo->Width = ACPI_PLD_GET_WIDTH (&Dword);709PldInfo->Height = ACPI_PLD_GET_HEIGHT(&Dword);710711/* Third 32-bit DWord */712713ACPI_MOVE_32_TO_32 (&Dword, &Buffer[2]);714PldInfo->UserVisible = ACPI_PLD_GET_USER_VISIBLE (&Dword);715PldInfo->Dock = ACPI_PLD_GET_DOCK (&Dword);716PldInfo->Lid = ACPI_PLD_GET_LID (&Dword);717PldInfo->Panel = ACPI_PLD_GET_PANEL (&Dword);718PldInfo->VerticalPosition = ACPI_PLD_GET_VERTICAL (&Dword);719PldInfo->HorizontalPosition = ACPI_PLD_GET_HORIZONTAL (&Dword);720PldInfo->Shape = ACPI_PLD_GET_SHAPE (&Dword);721PldInfo->GroupOrientation = ACPI_PLD_GET_ORIENTATION (&Dword);722PldInfo->GroupToken = ACPI_PLD_GET_TOKEN (&Dword);723PldInfo->GroupPosition = ACPI_PLD_GET_POSITION (&Dword);724PldInfo->Bay = ACPI_PLD_GET_BAY (&Dword);725726/* Fourth 32-bit DWord */727728ACPI_MOVE_32_TO_32 (&Dword, &Buffer[3]);729PldInfo->Ejectable = ACPI_PLD_GET_EJECTABLE (&Dword);730PldInfo->OspmEjectRequired = ACPI_PLD_GET_OSPM_EJECT (&Dword);731PldInfo->CabinetNumber = ACPI_PLD_GET_CABINET (&Dword);732PldInfo->CardCageNumber = ACPI_PLD_GET_CARD_CAGE (&Dword);733PldInfo->Reference = ACPI_PLD_GET_REFERENCE (&Dword);734PldInfo->Rotation = ACPI_PLD_GET_ROTATION (&Dword);735PldInfo->Order = ACPI_PLD_GET_ORDER (&Dword);736737if (Length >= ACPI_PLD_REV2_BUFFER_SIZE)738{739/* Fifth 32-bit DWord (Revision 2 of _PLD) */740741ACPI_MOVE_32_TO_32 (&Dword, &Buffer[4]);742PldInfo->VerticalOffset = ACPI_PLD_GET_VERT_OFFSET (&Dword);743PldInfo->HorizontalOffset = ACPI_PLD_GET_HORIZ_OFFSET (&Dword);744}745746*ReturnBuffer = PldInfo;747return (AE_OK);748}749750ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer)751752753