Path: blob/main/sys/contrib/dev/acpica/components/resources/rsaddr.c
48406 views
/*******************************************************************************1*2* Module Name: rsaddr - Address resource descriptors (16/32/64)3*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#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acresrc.h>154155#define _COMPONENT ACPI_RESOURCES156ACPI_MODULE_NAME ("rsaddr")157158159/*******************************************************************************160*161* AcpiRsConvertAddress16 - All WORD (16-bit) address resources162*163******************************************************************************/164165ACPI_RSCONVERT_INFO AcpiRsConvertAddress16[5] =166{167{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS16,168ACPI_RS_SIZE (ACPI_RESOURCE_ADDRESS16),169ACPI_RSC_TABLE_SIZE (AcpiRsConvertAddress16)},170171{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS16,172sizeof (AML_RESOURCE_ADDRESS16),1730},174175/* Resource Type, General Flags, and Type-Specific Flags */176177{ACPI_RSC_ADDRESS, 0, 0, 0},178179/*180* These fields are contiguous in both the source and destination:181* Address Granularity182* Address Range Minimum183* Address Range Maximum184* Address Translation Offset185* Address Length186*/187{ACPI_RSC_MOVE16, ACPI_RS_OFFSET (Data.Address16.Address.Granularity),188AML_OFFSET (Address16.Granularity),1895},190191/* Optional ResourceSource (Index and String) */192193{ACPI_RSC_SOURCE, ACPI_RS_OFFSET (Data.Address16.ResourceSource),1940,195sizeof (AML_RESOURCE_ADDRESS16)}196};197198199/*******************************************************************************200*201* AcpiRsConvertAddress32 - All DWORD (32-bit) address resources202*203******************************************************************************/204205ACPI_RSCONVERT_INFO AcpiRsConvertAddress32[5] =206{207{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS32,208ACPI_RS_SIZE (ACPI_RESOURCE_ADDRESS32),209ACPI_RSC_TABLE_SIZE (AcpiRsConvertAddress32)},210211{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS32,212sizeof (AML_RESOURCE_ADDRESS32),2130},214215/* Resource Type, General Flags, and Type-Specific Flags */216217{ACPI_RSC_ADDRESS, 0, 0, 0},218219/*220* These fields are contiguous in both the source and destination:221* Address Granularity222* Address Range Minimum223* Address Range Maximum224* Address Translation Offset225* Address Length226*/227{ACPI_RSC_MOVE32, ACPI_RS_OFFSET (Data.Address32.Address.Granularity),228AML_OFFSET (Address32.Granularity),2295},230231/* Optional ResourceSource (Index and String) */232233{ACPI_RSC_SOURCE, ACPI_RS_OFFSET (Data.Address32.ResourceSource),2340,235sizeof (AML_RESOURCE_ADDRESS32)}236};237238239/*******************************************************************************240*241* AcpiRsConvertAddress64 - All QWORD (64-bit) address resources242*243******************************************************************************/244245ACPI_RSCONVERT_INFO AcpiRsConvertAddress64[5] =246{247{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS64,248ACPI_RS_SIZE (ACPI_RESOURCE_ADDRESS64),249ACPI_RSC_TABLE_SIZE (AcpiRsConvertAddress64)},250251{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS64,252sizeof (AML_RESOURCE_ADDRESS64),2530},254255/* Resource Type, General Flags, and Type-Specific Flags */256257{ACPI_RSC_ADDRESS, 0, 0, 0},258259/*260* These fields are contiguous in both the source and destination:261* Address Granularity262* Address Range Minimum263* Address Range Maximum264* Address Translation Offset265* Address Length266*/267{ACPI_RSC_MOVE64, ACPI_RS_OFFSET (Data.Address64.Address.Granularity),268AML_OFFSET (Address64.Granularity),2695},270271/* Optional ResourceSource (Index and String) */272273{ACPI_RSC_SOURCE, ACPI_RS_OFFSET (Data.Address64.ResourceSource),2740,275sizeof (AML_RESOURCE_ADDRESS64)}276};277278279/*******************************************************************************280*281* AcpiRsConvertExtAddress64 - All Extended (64-bit) address resources282*283******************************************************************************/284285ACPI_RSCONVERT_INFO AcpiRsConvertExtAddress64[5] =286{287{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64,288ACPI_RS_SIZE (ACPI_RESOURCE_EXTENDED_ADDRESS64),289ACPI_RSC_TABLE_SIZE (AcpiRsConvertExtAddress64)},290291{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64,292sizeof (AML_RESOURCE_EXTENDED_ADDRESS64),2930},294295/* Resource Type, General Flags, and Type-Specific Flags */296297{ACPI_RSC_ADDRESS, 0, 0, 0},298299/* Revision ID */300301{ACPI_RSC_MOVE8, ACPI_RS_OFFSET (Data.ExtAddress64.RevisionID),302AML_OFFSET (ExtAddress64.RevisionID),3031},304/*305* These fields are contiguous in both the source and destination:306* Address Granularity307* Address Range Minimum308* Address Range Maximum309* Address Translation Offset310* Address Length311* Type-Specific Attribute312*/313{ACPI_RSC_MOVE64, ACPI_RS_OFFSET (Data.ExtAddress64.Address.Granularity),314AML_OFFSET (ExtAddress64.Granularity),3156}316};317318319/*******************************************************************************320*321* AcpiRsConvertGeneralFlags - Flags common to all address descriptors322*323******************************************************************************/324325static ACPI_RSCONVERT_INFO AcpiRsConvertGeneralFlags[6] =326{327{ACPI_RSC_FLAGINIT, 0, AML_OFFSET (Address.Flags),328ACPI_RSC_TABLE_SIZE (AcpiRsConvertGeneralFlags)},329330/* Resource Type (Memory, Io, BusNumber, etc.) */331332{ACPI_RSC_MOVE8, ACPI_RS_OFFSET (Data.Address.ResourceType),333AML_OFFSET (Address.ResourceType),3341},335336/* General Flags - Consume, Decode, MinFixed, MaxFixed */337338{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.ProducerConsumer),339AML_OFFSET (Address.Flags),3400},341342{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Decode),343AML_OFFSET (Address.Flags),3441},345346{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.MinAddressFixed),347AML_OFFSET (Address.Flags),3482},349350{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.MaxAddressFixed),351AML_OFFSET (Address.Flags),3523}353};354355356/*******************************************************************************357*358* AcpiRsConvertMemFlags - Flags common to Memory address descriptors359*360******************************************************************************/361362static ACPI_RSCONVERT_INFO AcpiRsConvertMemFlags[5] =363{364{ACPI_RSC_FLAGINIT, 0, AML_OFFSET (Address.SpecificFlags),365ACPI_RSC_TABLE_SIZE (AcpiRsConvertMemFlags)},366367/* Memory-specific flags */368369{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Mem.WriteProtect),370AML_OFFSET (Address.SpecificFlags),3710},372373{ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Mem.Caching),374AML_OFFSET (Address.SpecificFlags),3751},376377{ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Mem.RangeType),378AML_OFFSET (Address.SpecificFlags),3793},380381{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Mem.Translation),382AML_OFFSET (Address.SpecificFlags),3835}384};385386387/*******************************************************************************388*389* AcpiRsConvertIoFlags - Flags common to I/O address descriptors390*391******************************************************************************/392393static ACPI_RSCONVERT_INFO AcpiRsConvertIoFlags[4] =394{395{ACPI_RSC_FLAGINIT, 0, AML_OFFSET (Address.SpecificFlags),396ACPI_RSC_TABLE_SIZE (AcpiRsConvertIoFlags)},397398/* I/O-specific flags */399400{ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Io.RangeType),401AML_OFFSET (Address.SpecificFlags),4020},403404{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Io.Translation),405AML_OFFSET (Address.SpecificFlags),4064},407408{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Io.TranslationType),409AML_OFFSET (Address.SpecificFlags),4105}411};412413414/*******************************************************************************415*416* FUNCTION: AcpiRsGetAddressCommon417*418* PARAMETERS: Resource - Pointer to the internal resource struct419* Aml - Pointer to the AML resource descriptor420*421* RETURN: TRUE if the ResourceType field is OK, FALSE otherwise422*423* DESCRIPTION: Convert common flag fields from a raw AML resource descriptor424* to an internal resource descriptor425*426******************************************************************************/427428BOOLEAN429AcpiRsGetAddressCommon (430ACPI_RESOURCE *Resource,431AML_RESOURCE *Aml)432{433ACPI_FUNCTION_ENTRY();434435/* Validate the Resource Type */436437if ((Aml->Address.ResourceType > 2) &&438(Aml->Address.ResourceType < 0xC0) &&439(Aml->Address.ResourceType != 0x0A))440{441return (FALSE);442}443444/* Get the Resource Type and General Flags */445446(void) AcpiRsConvertAmlToResource (447Resource, Aml, AcpiRsConvertGeneralFlags);448449/* Get the Type-Specific Flags (Memory and I/O descriptors only) */450451if (Resource->Data.Address.ResourceType == ACPI_MEMORY_RANGE)452{453(void) AcpiRsConvertAmlToResource (454Resource, Aml, AcpiRsConvertMemFlags);455}456else if (Resource->Data.Address.ResourceType == ACPI_IO_RANGE)457{458(void) AcpiRsConvertAmlToResource (459Resource, Aml, AcpiRsConvertIoFlags);460}461else462{463/* Generic resource type, just grab the TypeSpecific byte */464465Resource->Data.Address.Info.TypeSpecific =466Aml->Address.SpecificFlags;467}468469return (TRUE);470}471472473/*******************************************************************************474*475* FUNCTION: AcpiRsSetAddressCommon476*477* PARAMETERS: Aml - Pointer to the AML resource descriptor478* Resource - Pointer to the internal resource struct479*480* RETURN: None481*482* DESCRIPTION: Convert common flag fields from a resource descriptor to an483* AML descriptor484*485******************************************************************************/486487void488AcpiRsSetAddressCommon (489AML_RESOURCE *Aml,490ACPI_RESOURCE *Resource)491{492ACPI_FUNCTION_ENTRY ();493494/* Set the Resource Type and General Flags */495496(void) AcpiRsConvertResourceToAml (497Resource, Aml, AcpiRsConvertGeneralFlags);498499/* Set the Type-Specific Flags (Memory and I/O descriptors only) */500501if (Resource->Data.Address.ResourceType == ACPI_MEMORY_RANGE)502{503(void) AcpiRsConvertResourceToAml (504Resource, Aml, AcpiRsConvertMemFlags);505}506else if (Resource->Data.Address.ResourceType == ACPI_IO_RANGE)507{508(void) AcpiRsConvertResourceToAml (509Resource, Aml, AcpiRsConvertIoFlags);510}511else512{513/* Generic resource type, just copy the TypeSpecific byte */514515Aml->Address.SpecificFlags =516Resource->Data.Address.Info.TypeSpecific;517}518}519520521