/** @file

Copyright (c) 2013-2015 Intel Corporation.

SPDX-License-Identifier: BSD-2-Clause-Patent

**/


// Interrupts can be DEB8=all except 13,8,6,2,1,0

#ifndef PCIIRQ_ASI
#define PCIIRQ_ASI

OperationRegion(PRR0, PCI_Config, 0x60, 0x08)
Field(PRR0, ANYACC, NOLOCK, PRESERVE)
{
    PIRA, 8,
    PIRB, 8,
    PIRC, 8,
    PIRD, 8,
    PIRE, 8,
    PIRF, 8,
    PIRG, 8,
    PIRH, 8
}

Device(LNKA)            // PCI IRQ link A
{
    Name(_HID,EISAID("PNP0C0F"))

    Name(_UID, 1)

    Method(_STA,0,NotSerialized)
    {
        If(And(PIRA, 0x80))
        {
          Return(0x9)
        }
        Else
        {
          Return(0xB)
        }    // Don't display
    }

    Method(_DIS,0,NotSerialized)
    {
        Or(PIRA, 0x80, PIRA)
    }

    Method(_CRS,0,Serialized)
    {
        Name(BUF0,
            ResourceTemplate()
            {IRQ(Level,ActiveLow,Shared){0}})

                                // Define references to buffer elements
        CreateWordField (BUF0, 0x01, IRQW)  // IRQ low
                                // Write current settings into IRQ descriptor
        If (And(PIRA, 0x80))
        {
            Store(Zero, Local0)
        }
        Else
        {
            Store(One,Local0)
        }
                                                    // Shift 1 by value in register 70
        ShiftLeft(Local0,And(PIRA,0x0F),IRQW)       // Save in buffer
        Return(BUF0)                                // Return Buf0
    }                                               // End of _CRS method

    Name(_PRS,
        ResourceTemplate()
        {IRQ(Level,ActiveLow,Shared){12,11,10,9,7,5,4,3}})

    Method(_SRS,1,NotSerialized)
    {
        CreateWordField (ARG0, 0x01, IRQW)  // IRQ low

        FindSetRightBit(IRQW,Local0)          // Set IRQ
        If (LNotEqual(IRQW,Zero))
        {
            And(Local0, 0x7F,Local0)
            Decrement(Local0)
        }
        Else
        {
            Or(Local0, 0x80,Local0)
        }
        store(Local0, PIRA)
    }                                                  // End of _SRS Method
}

Device(LNKB)            // PCI IRQ link B
{
    Name(_HID,EISAID("PNP0C0F"))

    Name(_UID, 2)

    Method(_STA,0,NotSerialized)
    {
        If(And(PIRB, 0x80))
        {
          Return(0x9)
        }
        Else
        {
          Return(0xB)
        }    // Don't display
    }

    Method(_DIS,0,NotSerialized)
    {
        Or(PIRB, 0x80,PIRB)
    }

    Method(_CRS,0,Serialized)
    {
        Name(BUF0,
            ResourceTemplate()
            {IRQ(Level,ActiveLow,Shared){0}})
                                            // Define references to buffer elements
        CreateWordField (BUF0, 0x01, IRQW)  // IRQ low
                                            // Write current settings into IRQ descriptor
        If (And(PIRB, 0x80))
        {
            Store(Zero, Local0)
        }
        Else
        {
                Store(One,Local0)
        }
                                               // Shift 1 by value in register 70
        ShiftLeft(Local0,And(PIRB,0x0F),IRQW)  // Save in buffer
        Return(BUF0)                           // Return Buf0
    }                                          // End of _CRS method

    Name(_PRS,
        ResourceTemplate()
        {IRQ(Level,ActiveLow,Shared){12,11,10,9,7,5,4,3}})

    Method(_SRS,1,NotSerialized)
    {
        CreateWordField (ARG0, 0x01, IRQW)      // IRQ low

        FindSetRightBit(IRQW,Local0)            // Set IRQ
        If (LNotEqual(IRQW,Zero))
        {
            And(Local0, 0x7F,Local0)
            Decrement(Local0)
        }
        Else
        {
            Or(Local0, 0x80,Local0)
        }
        Store(Local0, PIRB)
    }                                           // End of _SRS Method
}

Device(LNKC)                                    // PCI IRQ link C
{
    Name(_HID,EISAID("PNP0C0F"))

    Name(_UID, 3)

    Method(_STA,0,NotSerialized)
    {
        If(And(PIRC, 0x80))
        {
          Return(0x9)
        }
        Else
        {
          Return(0xB)
        }    // Don't display
    }

    Method(_DIS,0,NotSerialized)
    {
        Or(PIRC, 0x80,PIRC)
    }

    Method(_CRS,0,Serialized)
    {
        Name(BUF0,
            ResourceTemplate()
            {IRQ(Level,ActiveLow,Shared){0}})
                                            // Define references to buffer elements
        CreateWordField (BUF0, 0x01, IRQW)  // IRQ low
                                            // Write current settings into IRQ descriptor
        If (And(PIRC, 0x80))
        {
            Store(Zero, Local0)
        }
        Else
        {
            Store(One,Local0)
        }                                      // Shift 1 by value in register 70
        ShiftLeft(Local0,And(PIRC,0x0F),IRQW)  // Save in buffer
        Return(BUF0)                           // Return Buf0
    }                                          // End of _CRS method

    Name(_PRS,
        ResourceTemplate()
        {IRQ(Level,ActiveLow,Shared){12,11,10,9,7,5,4,3}})

    Method(_SRS,1,NotSerialized)
    {
        CreateWordField (ARG0, 0x01, IRQW)  // IRQ low

        FindSetRightBit(IRQW,Local0)        // Set IRQ
        If (LNotEqual(IRQW,Zero))
        {
            And(Local0, 0x7F,Local0)
            Decrement(Local0)
        }
        Else {
            Or(Local0, 0x80,Local0)
        }
        Store(Local0, PIRC)
    }                                               // End of _SRS Method
}

Device(LNKD)                                        // PCI IRQ link D
{
    Name(_HID,EISAID("PNP0C0F"))

    Name(_UID, 4)

    Method(_STA,0,NotSerialized)
    {
        If(And(PIRD, 0x80))
        {
          Return(0x9)
        }
        Else
        {
          Return(0xB)
        }    // Don't display
    }

    Method(_DIS,0,NotSerialized)
    {
        Or(PIRD, 0x80,PIRD)
    }

    Method(_CRS,0,Serialized)
    {
        Name(BUF0,
            ResourceTemplate()
            {IRQ(Level,ActiveLow,Shared){0}})
        // Define references to buffer elements
        CreateWordField (BUF0, 0x01, IRQW)  // IRQ low
        // Write current settings into IRQ descriptor
        If (And(PIRD, 0x80))
        {
            Store(Zero, Local0)
        }
        Else
        {
            Store(One,Local0)
        }  // Shift 1 by value in register 70
        ShiftLeft(Local0,And(PIRD,0x0F),IRQW)  // Save in buffer
        Return(BUF0)        // Return Buf0
    }                  // End of _CRS method

    Name(_PRS,
        ResourceTemplate()
        {IRQ(Level,ActiveLow,Shared){12,11,10,9,7,5,4,3}})

    Method(_SRS,1,NotSerialized)
    {
        CreateWordField (ARG0, 0x01, IRQW)  // IRQ low

        FindSetRightBit(IRQW,Local0)// Set IRQ
        If (LNotEqual(IRQW,Zero))
        {
            And(Local0, 0x7F,Local0)
            Decrement(Local0)
        }
        Else
        {
            Or(Local0, 0x80,Local0)
        }
        Store(Local0, PIRD)
    }                  // End of _SRS Method
}

Device(LNKE)           // PCI IRQ link E
{
    Name(_HID,EISAID("PNP0C0F"))

    Name(_UID, 5)

    Method(_STA,0,NotSerialized)
    {
        If(And(PIRE, 0x80))
        {
          Return(0x9)
        }
        Else
        {
          Return(0xB)
        }    // Don't display
    }

    Method(_DIS,0,NotSerialized)
    {
        Or(PIRE, 0x80, PIRE)
    }

    Method(_CRS,0,Serialized)
    {
        Name(BUF0,
            ResourceTemplate()
            {IRQ(Level,ActiveLow,Shared){0}})

                                // Define references to buffer elements
        CreateWordField (BUF0, 0x01, IRQW)  // IRQ low
                                // Write current settings into IRQ descriptor
        If (And(PIRE, 0x80))
        {
            Store(Zero, Local0)
        }
        Else
        {
            Store(One,Local0)
        }
                                                    // Shift 1 by value in register 70
        ShiftLeft(Local0,And(PIRE,0x0F),IRQW)       // Save in buffer
        Return(BUF0)                                // Return Buf0
    }                                               // End of _CRS method

    Name(_PRS,
        ResourceTemplate()
        {IRQ(Level,ActiveLow,Shared){12,11,10,9,7,5,4,3}})

    Method(_SRS,1,NotSerialized)
    {
        CreateWordField (ARG0, 0x01, IRQW)  // IRQ low

        FindSetRightBit(IRQW,Local0)          // Set IRQ
        If (LNotEqual(IRQW,Zero))
        {
            And(Local0, 0x7F,Local0)
            Decrement(Local0)
        }
        Else
        {
            Or(Local0, 0x80,Local0)
        }
        store(Local0, PIRE)
    }                                                  // End of _SRS Method
}

Device(LNKF)            // PCI IRQ link F
{
    Name(_HID,EISAID("PNP0C0F"))

    Name(_UID, 6)

    Method(_STA,0,NotSerialized)
    {
        If(And(PIRF, 0x80))
        {
          Return(0x9)
        }
        Else
        {
          Return(0xB)
        }    // Don't display
    }

    Method(_DIS,0,NotSerialized)
    {
        Or(PIRB, 0x80,PIRF)
    }

    Method(_CRS,0,Serialized)
    {
        Name(BUF0,
            ResourceTemplate()
            {IRQ(Level,ActiveLow,Shared){0}})
                                            // Define references to buffer elements
        CreateWordField (BUF0, 0x01, IRQW)  // IRQ low
                                            // Write current settings into IRQ descriptor
        If (And(PIRF, 0x80))
        {
            Store(Zero, Local0)
        }
        Else
        {
                Store(One,Local0)
        }
                                               // Shift 1 by value in register 70
        ShiftLeft(Local0,And(PIRF,0x0F),IRQW)  // Save in buffer
        Return(BUF0)                           // Return Buf0
    }                                          // End of _CRS method

    Name(_PRS,
        ResourceTemplate()
        {IRQ(Level,ActiveLow,Shared){12,11,10,9,7,5,4,3}})

    Method(_SRS,1,NotSerialized)
    {
        CreateWordField (ARG0, 0x01, IRQW)      // IRQ low

        FindSetRightBit(IRQW,Local0)            // Set IRQ
        If (LNotEqual(IRQW,Zero))
        {
            And(Local0, 0x7F,Local0)
            Decrement(Local0)
        }
        Else
        {
            Or(Local0, 0x80,Local0)
        }
        Store(Local0, PIRF)
    }                                                   // End of _SRS Method
}

Device(LNKG)                                            // PCI IRQ link G
{
    Name(_HID,EISAID("PNP0C0F"))

    Name(_UID, 7)

    Method(_STA,0,NotSerialized)
    {
        If(And(PIRG, 0x80))
        {
          Return(0x9)
        }
        Else
        {
          Return(0xB)
        }    // Don't display
    }

    Method(_DIS,0,NotSerialized)
    {
        Or(PIRG, 0x80,PIRG)
    }

    Method(_CRS,0,Serialized)
    {
        Name(BUF0,
            ResourceTemplate()
            {IRQ(Level,ActiveLow,Shared){0}})
                                            // Define references to buffer elements
        CreateWordField (BUF0, 0x01, IRQW)  // IRQ low
                                            // Write current settings into IRQ descriptor
        If (And(PIRG, 0x80))
        {
            Store(Zero, Local0)
        }
        Else
        {
            Store(One,Local0)
        }                                      // Shift 1 by value in register 70
        ShiftLeft(Local0,And(PIRG,0x0F),IRQW)  // Save in buffer
        Return(BUF0)                           // Return Buf0
    }                                          // End of _CRS method

    Name(_PRS,
        ResourceTemplate()
        {IRQ(Level,ActiveLow,Shared){12,11,10,9,7,5,4,3}})

    Method(_SRS,1,NotSerialized)
    {
        CreateWordField (ARG0, 0x01, IRQW)  // IRQ low

        FindSetRightBit(IRQW,Local0)          // Set IRQ
        If (LNotEqual(IRQW,Zero))
        {
            And(Local0, 0x7F,Local0)
            Decrement(Local0)
        }
        Else {
            Or(Local0, 0x80,Local0)
        }
        Store(Local0, PIRG)
    }                                               // End of _SRS Method
}

Device(LNKH)                                        // PCI IRQ link H
{
    Name(_HID,EISAID("PNP0C0F"))

    Name(_UID, 8)

    Method(_STA,0,NotSerialized)
    {
        If(And(PIRH, 0x80))
        {
          Return(0x9)
        }
        Else
        {
          Return(0xB)
        }    // Don't display
    }

    Method(_DIS,0,NotSerialized)
    {
        Or(PIRH, 0x80,PIRH)
    }

    Method(_CRS,0,Serialized)
    {
        Name(BUF0,
            ResourceTemplate()
            {IRQ(Level,ActiveLow,Shared){0}})
        // Define references to buffer elements
        CreateWordField (BUF0, 0x01, IRQW)  // IRQ low
        // Write current settings into IRQ descriptor
        If (And(PIRH, 0x80))
        {
            Store(Zero, Local0)
        }
        Else
        {
            Store(One,Local0)
        }  // Shift 1 by value in register 70
        ShiftLeft(Local0,And(PIRH,0x0F),IRQW)  // Save in buffer
        Return(BUF0)   // Return Buf0
    }                  // End of _CRS method

    Name(_PRS,
        ResourceTemplate()
        {IRQ(Level,ActiveLow,Shared){12,11,10,9,7,5,4,3}})

    Method(_SRS,1,NotSerialized)
    {
        CreateWordField (ARG0, 0x01, IRQW)  // IRQ low

        FindSetRightBit(IRQW,Local0)// Set IRQ
        If (LNotEqual(IRQW,Zero))
        {
            And(Local0, 0x7F,Local0)
            Decrement(Local0)
        }
        Else
        {
            Or(Local0, 0x80,Local0)
        }
        Store(Local0, PIRH)
    }                  // End of _SRS Method
}

#endif
