1 /*******************************************************************************
   2  *
   3  * Module Name: rsirq - IRQ resource descriptors
   4  *
   5  ******************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2014, Intel Corp.
   9  * All rights reserved.
  10  *
  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.
  25  *
  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.
  29  *
  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.
  42  */
  43 
  44 #define __RSIRQ_C__
  45 
  46 #include "acpi.h"
  47 #include "accommon.h"
  48 #include "acresrc.h"
  49 
  50 #define _COMPONENT          ACPI_RESOURCES
  51         ACPI_MODULE_NAME    ("rsirq")
  52 
  53 
  54 /*******************************************************************************
  55  *
  56  * AcpiRsGetIrq
  57  *
  58  ******************************************************************************/
  59 
  60 ACPI_RSCONVERT_INFO     AcpiRsGetIrq[9] =
  61 {
  62     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_IRQ,
  63                         ACPI_RS_SIZE (ACPI_RESOURCE_IRQ),
  64                         ACPI_RSC_TABLE_SIZE (AcpiRsGetIrq)},
  65 
  66     /* Get the IRQ mask (bytes 1:2) */
  67 
  68     {ACPI_RSC_BITMASK16,ACPI_RS_OFFSET (Data.Irq.Interrupts[0]),
  69                         AML_OFFSET (Irq.IrqMask),
  70                         ACPI_RS_OFFSET (Data.Irq.InterruptCount)},
  71 
  72     /* Set default flags (others are zero) */
  73 
  74     {ACPI_RSC_SET8,     ACPI_RS_OFFSET (Data.Irq.Triggering),
  75                         ACPI_EDGE_SENSITIVE,
  76                         1},
  77 
  78     /* Get the descriptor length (2 or 3 for IRQ descriptor) */
  79 
  80     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Irq.DescriptorLength),
  81                         AML_OFFSET (Irq.DescriptorType),
  82                         0},
  83 
  84     /* All done if no flag byte present in descriptor */
  85 
  86     {ACPI_RSC_EXIT_NE,  ACPI_RSC_COMPARE_AML_LENGTH, 0, 3},
  87 
  88     /* Get flags: Triggering[0], Polarity[3], Sharing[4], Wake[5] */
  89 
  90     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Triggering),
  91                         AML_OFFSET (Irq.Flags),
  92                         0},
  93 
  94     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Polarity),
  95                         AML_OFFSET (Irq.Flags),
  96                         3},
  97 
  98     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Sharable),
  99                         AML_OFFSET (Irq.Flags),
 100                         4},
 101 
 102     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.WakeCapable),
 103                         AML_OFFSET (Irq.Flags),
 104                         5}
 105 };
 106 
 107 
 108 /*******************************************************************************
 109  *
 110  * AcpiRsSetIrq
 111  *
 112  ******************************************************************************/
 113 
 114 ACPI_RSCONVERT_INFO     AcpiRsSetIrq[14] =
 115 {
 116     /* Start with a default descriptor of length 3 */
 117 
 118     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_IRQ,
 119                         sizeof (AML_RESOURCE_IRQ),
 120                         ACPI_RSC_TABLE_SIZE (AcpiRsSetIrq)},
 121 
 122     /* Convert interrupt list to 16-bit IRQ bitmask */
 123 
 124     {ACPI_RSC_BITMASK16,ACPI_RS_OFFSET (Data.Irq.Interrupts[0]),
 125                         AML_OFFSET (Irq.IrqMask),
 126                         ACPI_RS_OFFSET (Data.Irq.InterruptCount)},
 127 
 128     /* Set flags: Triggering[0], Polarity[3], Sharing[4], Wake[5] */
 129 
 130     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Triggering),
 131                         AML_OFFSET (Irq.Flags),
 132                         0},
 133 
 134     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Polarity),
 135                         AML_OFFSET (Irq.Flags),
 136                         3},
 137 
 138     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.Sharable),
 139                         AML_OFFSET (Irq.Flags),
 140                         4},
 141 
 142     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Irq.WakeCapable),
 143                         AML_OFFSET (Irq.Flags),
 144                         5},
 145 
 146     /*
 147      * All done if the output descriptor length is required to be 3
 148      * (i.e., optimization to 2 bytes cannot be attempted)
 149      */
 150     {ACPI_RSC_EXIT_EQ,  ACPI_RSC_COMPARE_VALUE,
 151                         ACPI_RS_OFFSET(Data.Irq.DescriptorLength),
 152                         3},
 153 
 154     /* Set length to 2 bytes (no flags byte) */
 155 
 156     {ACPI_RSC_LENGTH,   0, 0, sizeof (AML_RESOURCE_IRQ_NOFLAGS)},
 157 
 158     /*
 159      * All done if the output descriptor length is required to be 2.
 160      *
 161      * TBD: Perhaps we should check for error if input flags are not
 162      * compatible with a 2-byte descriptor.
 163      */
 164     {ACPI_RSC_EXIT_EQ,  ACPI_RSC_COMPARE_VALUE,
 165                         ACPI_RS_OFFSET(Data.Irq.DescriptorLength),
 166                         2},
 167 
 168     /* Reset length to 3 bytes (descriptor with flags byte) */
 169 
 170     {ACPI_RSC_LENGTH,   0, 0, sizeof (AML_RESOURCE_IRQ)},
 171 
 172     /*
 173      * Check if the flags byte is necessary. Not needed if the flags are:
 174      * ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_HIGH, ACPI_EXCLUSIVE
 175      */
 176     {ACPI_RSC_EXIT_NE,  ACPI_RSC_COMPARE_VALUE,
 177                         ACPI_RS_OFFSET (Data.Irq.Triggering),
 178                         ACPI_EDGE_SENSITIVE},
 179 
 180     {ACPI_RSC_EXIT_NE,  ACPI_RSC_COMPARE_VALUE,
 181                         ACPI_RS_OFFSET (Data.Irq.Polarity),
 182                         ACPI_ACTIVE_HIGH},
 183 
 184     {ACPI_RSC_EXIT_NE,  ACPI_RSC_COMPARE_VALUE,
 185                         ACPI_RS_OFFSET (Data.Irq.Sharable),
 186                         ACPI_EXCLUSIVE},
 187 
 188     /* We can optimize to a 2-byte IrqNoFlags() descriptor */
 189 
 190     {ACPI_RSC_LENGTH,   0, 0, sizeof (AML_RESOURCE_IRQ_NOFLAGS)}
 191 };
 192 
 193 
 194 /*******************************************************************************
 195  *
 196  * AcpiRsConvertExtIrq
 197  *
 198  ******************************************************************************/
 199 
 200 ACPI_RSCONVERT_INFO     AcpiRsConvertExtIrq[10] =
 201 {
 202     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_EXTENDED_IRQ,
 203                         ACPI_RS_SIZE (ACPI_RESOURCE_EXTENDED_IRQ),
 204                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertExtIrq)},
 205 
 206     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_EXTENDED_IRQ,
 207                         sizeof (AML_RESOURCE_EXTENDED_IRQ),
 208                         0},
 209 
 210     /*
 211      * Flags: Producer/Consumer[0], Triggering[1], Polarity[2],
 212      *        Sharing[3], Wake[4]
 213      */
 214     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.ProducerConsumer),
 215                         AML_OFFSET (ExtendedIrq.Flags),
 216                         0},
 217 
 218     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.Triggering),
 219                         AML_OFFSET (ExtendedIrq.Flags),
 220                         1},
 221 
 222     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.Polarity),
 223                         AML_OFFSET (ExtendedIrq.Flags),
 224                         2},
 225 
 226     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.Sharable),
 227                         AML_OFFSET (ExtendedIrq.Flags),
 228                         3},
 229 
 230     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.ExtendedIrq.WakeCapable),
 231                         AML_OFFSET (ExtendedIrq.Flags),
 232                         4},
 233 
 234     /* IRQ Table length (Byte4) */
 235 
 236     {ACPI_RSC_COUNT,    ACPI_RS_OFFSET (Data.ExtendedIrq.InterruptCount),
 237                         AML_OFFSET (ExtendedIrq.InterruptCount),
 238                         sizeof (UINT32)},
 239 
 240     /* Copy every IRQ in the table, each is 32 bits */
 241 
 242     {ACPI_RSC_MOVE32,   ACPI_RS_OFFSET (Data.ExtendedIrq.Interrupts[0]),
 243                         AML_OFFSET (ExtendedIrq.Interrupts[0]),
 244                         0},
 245 
 246     /* Optional ResourceSource (Index and String) */
 247 
 248     {ACPI_RSC_SOURCEX,  ACPI_RS_OFFSET (Data.ExtendedIrq.ResourceSource),
 249                         ACPI_RS_OFFSET (Data.ExtendedIrq.Interrupts[0]),
 250                         sizeof (AML_RESOURCE_EXTENDED_IRQ)}
 251 };
 252 
 253 
 254 /*******************************************************************************
 255  *
 256  * AcpiRsConvertDma
 257  *
 258  ******************************************************************************/
 259 
 260 ACPI_RSCONVERT_INFO     AcpiRsConvertDma[6] =
 261 {
 262     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_DMA,
 263                         ACPI_RS_SIZE (ACPI_RESOURCE_DMA),
 264                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertDma)},
 265 
 266     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_DMA,
 267                         sizeof (AML_RESOURCE_DMA),
 268                         0},
 269 
 270     /* Flags: transfer preference, bus mastering, channel speed */
 271 
 272     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Dma.Transfer),
 273                         AML_OFFSET (Dma.Flags),
 274                         0},
 275 
 276     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Dma.BusMaster),
 277                         AML_OFFSET (Dma.Flags),
 278                         2},
 279 
 280     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Dma.Type),
 281                         AML_OFFSET (Dma.Flags),
 282                         5},
 283 
 284     /* DMA channel mask bits */
 285 
 286     {ACPI_RSC_BITMASK,  ACPI_RS_OFFSET (Data.Dma.Channels[0]),
 287                         AML_OFFSET (Dma.DmaChannelMask),
 288                         ACPI_RS_OFFSET (Data.Dma.ChannelCount)}
 289 };
 290 
 291 
 292 /*******************************************************************************
 293  *
 294  * AcpiRsConvertFixedDma
 295  *
 296  ******************************************************************************/
 297 
 298 ACPI_RSCONVERT_INFO     AcpiRsConvertFixedDma[4] =
 299 {
 300     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_FIXED_DMA,
 301                         ACPI_RS_SIZE (ACPI_RESOURCE_FIXED_DMA),
 302                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertFixedDma)},
 303 
 304     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_FIXED_DMA,
 305                         sizeof (AML_RESOURCE_FIXED_DMA),
 306                         0},
 307 
 308     /*
 309      * These fields are contiguous in both the source and destination:
 310      * RequestLines
 311      * Channels
 312      */
 313     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.FixedDma.RequestLines),
 314                         AML_OFFSET (FixedDma.RequestLines),
 315                         2},
 316 
 317     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.FixedDma.Width),
 318                         AML_OFFSET (FixedDma.Width),
 319                         1},
 320 };