Path: blob/main/sys/contrib/dev/acpica/components/resources/rsirq.c
48406 views
/*******************************************************************************1*2* Module Name: rsirq - IRQ resource descriptors3*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 ("rsirq")157158159/*******************************************************************************160*161* AcpiRsGetIrq162*163******************************************************************************/164165ACPI_RSCONVERT_INFO AcpiRsGetIrq[9] =166{167{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_IRQ,168ACPI_RS_SIZE (ACPI_RESOURCE_IRQ),169ACPI_RSC_TABLE_SIZE (AcpiRsGetIrq)},170171/* Get the IRQ mask (bytes 1:2) */172173{ACPI_RSC_BITMASK16,ACPI_RS_OFFSET (Data.Irq.Interrupts[0]),174AML_OFFSET (Irq.IrqMask),175ACPI_RS_OFFSET (Data.Irq.InterruptCount)},176177/* Set default flags (others are zero) */178179{ACPI_RSC_SET8, ACPI_RS_OFFSET (Data.Irq.Triggering),180ACPI_EDGE_SENSITIVE,1811},182183/* Get the descriptor length (2 or 3 for IRQ descriptor) */184185{ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Irq.DescriptorLength),186AML_OFFSET (Irq.DescriptorType),1870},188189/* All done if no flag byte present in descriptor */190191{ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_AML_LENGTH, 0, 3},192193/* Get flags: Triggering[0], Polarity[3], Sharing[4], Wake[5] */194195{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Triggering),196AML_OFFSET (Irq.Flags),1970},198199{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Polarity),200AML_OFFSET (Irq.Flags),2013},202203{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Shareable),204AML_OFFSET (Irq.Flags),2054},206207{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.WakeCapable),208AML_OFFSET (Irq.Flags),2095}210};211212213/*******************************************************************************214*215* AcpiRsSetIrq216*217******************************************************************************/218219ACPI_RSCONVERT_INFO AcpiRsSetIrq[14] =220{221/* Start with a default descriptor of length 3 */222223{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_IRQ,224sizeof (AML_RESOURCE_IRQ),225ACPI_RSC_TABLE_SIZE (AcpiRsSetIrq)},226227/* Convert interrupt list to 16-bit IRQ bitmask */228229{ACPI_RSC_BITMASK16,ACPI_RS_OFFSET (Data.Irq.Interrupts[0]),230AML_OFFSET (Irq.IrqMask),231ACPI_RS_OFFSET (Data.Irq.InterruptCount)},232233/* Set flags: Triggering[0], Polarity[3], Sharing[4], Wake[5] */234235{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Triggering),236AML_OFFSET (Irq.Flags),2370},238239{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Polarity),240AML_OFFSET (Irq.Flags),2413},242243{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Shareable),244AML_OFFSET (Irq.Flags),2454},246247{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.WakeCapable),248AML_OFFSET (Irq.Flags),2495},250251/*252* All done if the output descriptor length is required to be 3253* (i.e., optimization to 2 bytes cannot be attempted)254*/255{ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,256ACPI_RS_OFFSET(Data.Irq.DescriptorLength),2573},258259/* Set length to 2 bytes (no flags byte) */260261{ACPI_RSC_LENGTH, 0, 0, sizeof (AML_RESOURCE_IRQ_NOFLAGS)},262263/*264* All done if the output descriptor length is required to be 2.265*266* TBD: Perhaps we should check for error if input flags are not267* compatible with a 2-byte descriptor.268*/269{ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,270ACPI_RS_OFFSET(Data.Irq.DescriptorLength),2712},272273/* Reset length to 3 bytes (descriptor with flags byte) */274275{ACPI_RSC_LENGTH, 0, 0, sizeof (AML_RESOURCE_IRQ)},276277/*278* Check if the flags byte is necessary. Not needed if the flags are:279* ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_HIGH, ACPI_EXCLUSIVE280*/281{ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE,282ACPI_RS_OFFSET (Data.Irq.Triggering),283ACPI_EDGE_SENSITIVE},284285{ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE,286ACPI_RS_OFFSET (Data.Irq.Polarity),287ACPI_ACTIVE_HIGH},288289{ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE,290ACPI_RS_OFFSET (Data.Irq.Shareable),291ACPI_EXCLUSIVE},292293/* We can optimize to a 2-byte IrqNoFlags() descriptor */294295{ACPI_RSC_LENGTH, 0, 0, sizeof (AML_RESOURCE_IRQ_NOFLAGS)}296};297298299/*******************************************************************************300*301* AcpiRsConvertExtIrq302*303******************************************************************************/304305ACPI_RSCONVERT_INFO AcpiRsConvertExtIrq[10] =306{307{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_EXTENDED_IRQ,308ACPI_RS_SIZE (ACPI_RESOURCE_EXTENDED_IRQ),309ACPI_RSC_TABLE_SIZE (AcpiRsConvertExtIrq)},310311{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_EXTENDED_IRQ,312sizeof (AML_RESOURCE_EXTENDED_IRQ),3130},314315/*316* Flags: Producer/Consumer[0], Triggering[1], Polarity[2],317* Sharing[3], Wake[4]318*/319{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.ProducerConsumer),320AML_OFFSET (ExtendedIrq.Flags),3210},322323{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.Triggering),324AML_OFFSET (ExtendedIrq.Flags),3251},326327{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.Polarity),328AML_OFFSET (ExtendedIrq.Flags),3292},330331{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.Shareable),332AML_OFFSET (ExtendedIrq.Flags),3333},334335{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.WakeCapable),336AML_OFFSET (ExtendedIrq.Flags),3374},338339/* IRQ Table length (Byte4) */340341{ACPI_RSC_COUNT, ACPI_RS_OFFSET (Data.ExtendedIrq.InterruptCount),342AML_OFFSET (ExtendedIrq.InterruptCount),343sizeof (UINT32)},344345/* Copy every IRQ in the table, each is 32 bits */346347{ACPI_RSC_MOVE32, ACPI_RS_OFFSET (Data.ExtendedIrq.Interrupts[0]),348AML_OFFSET (ExtendedIrq.Interrupts[0]),3490},350351/* Optional ResourceSource (Index and String) */352353{ACPI_RSC_SOURCEX, ACPI_RS_OFFSET (Data.ExtendedIrq.ResourceSource),354ACPI_RS_OFFSET (Data.ExtendedIrq.Interrupts[0]),355sizeof (AML_RESOURCE_EXTENDED_IRQ)}356};357358359/*******************************************************************************360*361* AcpiRsConvertDma362*363******************************************************************************/364365ACPI_RSCONVERT_INFO AcpiRsConvertDma[6] =366{367{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_DMA,368ACPI_RS_SIZE (ACPI_RESOURCE_DMA),369ACPI_RSC_TABLE_SIZE (AcpiRsConvertDma)},370371{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_DMA,372sizeof (AML_RESOURCE_DMA),3730},374375/* Flags: transfer preference, bus mastering, channel speed */376377{ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Dma.Transfer),378AML_OFFSET (Dma.Flags),3790},380381{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Dma.BusMaster),382AML_OFFSET (Dma.Flags),3832},384385{ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Dma.Type),386AML_OFFSET (Dma.Flags),3875},388389/* DMA channel mask bits */390391{ACPI_RSC_BITMASK, ACPI_RS_OFFSET (Data.Dma.Channels[0]),392AML_OFFSET (Dma.DmaChannelMask),393ACPI_RS_OFFSET (Data.Dma.ChannelCount)}394};395396397/*******************************************************************************398*399* AcpiRsConvertFixedDma400*401******************************************************************************/402403ACPI_RSCONVERT_INFO AcpiRsConvertFixedDma[4] =404{405{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_FIXED_DMA,406ACPI_RS_SIZE (ACPI_RESOURCE_FIXED_DMA),407ACPI_RSC_TABLE_SIZE (AcpiRsConvertFixedDma)},408409{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_FIXED_DMA,410sizeof (AML_RESOURCE_FIXED_DMA),4110},412413/*414* These fields are contiguous in both the source and destination:415* RequestLines416* Channels417*/418{ACPI_RSC_MOVE16, ACPI_RS_OFFSET (Data.FixedDma.RequestLines),419AML_OFFSET (FixedDma.RequestLines),4202},421422{ACPI_RSC_MOVE8, ACPI_RS_OFFSET (Data.FixedDma.Width),423AML_OFFSET (FixedDma.Width),4241},425};426427428