rsirq.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsirq - IRQ resource descriptors
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acresrc.h"
  45. #define _COMPONENT ACPI_RESOURCES
  46. ACPI_MODULE_NAME("rsirq")
  47. /*******************************************************************************
  48. *
  49. * acpi_rs_get_irq
  50. *
  51. ******************************************************************************/
  52. struct acpi_rsconvert_info acpi_rs_get_irq[8] = {
  53. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_IRQ,
  54. ACPI_RS_SIZE(struct acpi_resource_irq),
  55. ACPI_RSC_TABLE_SIZE(acpi_rs_get_irq)},
  56. /* Get the IRQ mask (bytes 1:2) */
  57. {ACPI_RSC_BITMASK16, ACPI_RS_OFFSET(data.irq.interrupts[0]),
  58. AML_OFFSET(irq.irq_mask),
  59. ACPI_RS_OFFSET(data.irq.interrupt_count)},
  60. /* Set default flags (others are zero) */
  61. {ACPI_RSC_SET8, ACPI_RS_OFFSET(data.irq.triggering),
  62. ACPI_EDGE_SENSITIVE,
  63. 1},
  64. /* Get the descriptor length (2 or 3 for IRQ descriptor) */
  65. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.irq.descriptor_length),
  66. AML_OFFSET(irq.descriptor_type),
  67. 0},
  68. /* All done if no flag byte present in descriptor */
  69. {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_AML_LENGTH, 0, 3},
  70. /* Get flags: Triggering[0], Polarity[3], Sharing[4] */
  71. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.triggering),
  72. AML_OFFSET(irq.flags),
  73. 0},
  74. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.polarity),
  75. AML_OFFSET(irq.flags),
  76. 3},
  77. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.sharable),
  78. AML_OFFSET(irq.flags),
  79. 4}
  80. };
  81. /*******************************************************************************
  82. *
  83. * acpi_rs_set_irq
  84. *
  85. ******************************************************************************/
  86. struct acpi_rsconvert_info acpi_rs_set_irq[13] = {
  87. /* Start with a default descriptor of length 3 */
  88. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_IRQ,
  89. sizeof(struct aml_resource_irq),
  90. ACPI_RSC_TABLE_SIZE(acpi_rs_set_irq)},
  91. /* Convert interrupt list to 16-bit IRQ bitmask */
  92. {ACPI_RSC_BITMASK16, ACPI_RS_OFFSET(data.irq.interrupts[0]),
  93. AML_OFFSET(irq.irq_mask),
  94. ACPI_RS_OFFSET(data.irq.interrupt_count)},
  95. /* Set the flags byte */
  96. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.triggering),
  97. AML_OFFSET(irq.flags),
  98. 0},
  99. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.polarity),
  100. AML_OFFSET(irq.flags),
  101. 3},
  102. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.sharable),
  103. AML_OFFSET(irq.flags),
  104. 4},
  105. /*
  106. * All done if the output descriptor length is required to be 3
  107. * (i.e., optimization to 2 bytes cannot be attempted)
  108. */
  109. {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,
  110. ACPI_RS_OFFSET(data.irq.descriptor_length),
  111. 3},
  112. /* Set length to 2 bytes (no flags byte) */
  113. {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq_noflags)},
  114. /*
  115. * All done if the output descriptor length is required to be 2.
  116. *
  117. * TBD: Perhaps we should check for error if input flags are not
  118. * compatible with a 2-byte descriptor.
  119. */
  120. {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,
  121. ACPI_RS_OFFSET(data.irq.descriptor_length),
  122. 2},
  123. /* Reset length to 3 bytes (descriptor with flags byte) */
  124. {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq)},
  125. /*
  126. * Check if the flags byte is necessary. Not needed if the flags are:
  127. * ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_HIGH, ACPI_EXCLUSIVE
  128. */
  129. {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE,
  130. ACPI_RS_OFFSET(data.irq.triggering),
  131. ACPI_EDGE_SENSITIVE},
  132. {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE,
  133. ACPI_RS_OFFSET(data.irq.polarity),
  134. ACPI_ACTIVE_HIGH},
  135. {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE,
  136. ACPI_RS_OFFSET(data.irq.sharable),
  137. ACPI_EXCLUSIVE},
  138. /* We can optimize to a 2-byte irq_no_flags() descriptor */
  139. {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq_noflags)}
  140. };
  141. /*******************************************************************************
  142. *
  143. * acpi_rs_convert_ext_irq
  144. *
  145. ******************************************************************************/
  146. struct acpi_rsconvert_info acpi_rs_convert_ext_irq[9] = {
  147. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_EXTENDED_IRQ,
  148. ACPI_RS_SIZE(struct acpi_resource_extended_irq),
  149. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_ext_irq)},
  150. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_EXTENDED_IRQ,
  151. sizeof(struct aml_resource_extended_irq),
  152. 0},
  153. /* Flag bits */
  154. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.extended_irq.producer_consumer),
  155. AML_OFFSET(extended_irq.flags),
  156. 0},
  157. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.extended_irq.triggering),
  158. AML_OFFSET(extended_irq.flags),
  159. 1},
  160. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.extended_irq.polarity),
  161. AML_OFFSET(extended_irq.flags),
  162. 2},
  163. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.extended_irq.sharable),
  164. AML_OFFSET(extended_irq.flags),
  165. 3},
  166. /* IRQ Table length (Byte4) */
  167. {ACPI_RSC_COUNT, ACPI_RS_OFFSET(data.extended_irq.interrupt_count),
  168. AML_OFFSET(extended_irq.interrupt_count),
  169. sizeof(u32)}
  170. ,
  171. /* Copy every IRQ in the table, each is 32 bits */
  172. {ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.extended_irq.interrupts[0]),
  173. AML_OFFSET(extended_irq.interrupts[0]),
  174. 0}
  175. ,
  176. /* Optional resource_source (Index and String) */
  177. {ACPI_RSC_SOURCEX, ACPI_RS_OFFSET(data.extended_irq.resource_source),
  178. ACPI_RS_OFFSET(data.extended_irq.interrupts[0]),
  179. sizeof(struct aml_resource_extended_irq)}
  180. };
  181. /*******************************************************************************
  182. *
  183. * acpi_rs_convert_dma
  184. *
  185. ******************************************************************************/
  186. struct acpi_rsconvert_info acpi_rs_convert_dma[6] = {
  187. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_DMA,
  188. ACPI_RS_SIZE(struct acpi_resource_dma),
  189. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_dma)},
  190. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_DMA,
  191. sizeof(struct aml_resource_dma),
  192. 0},
  193. /* Flags: transfer preference, bus mastering, channel speed */
  194. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.dma.transfer),
  195. AML_OFFSET(dma.flags),
  196. 0},
  197. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.dma.bus_master),
  198. AML_OFFSET(dma.flags),
  199. 2},
  200. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.dma.type),
  201. AML_OFFSET(dma.flags),
  202. 5},
  203. /* DMA channel mask bits */
  204. {ACPI_RSC_BITMASK, ACPI_RS_OFFSET(data.dma.channels[0]),
  205. AML_OFFSET(dma.dma_channel_mask),
  206. ACPI_RS_OFFSET(data.dma.channel_count)}
  207. };
  208. /*******************************************************************************
  209. *
  210. * acpi_rs_convert_fixed_dma
  211. *
  212. ******************************************************************************/
  213. struct acpi_rsconvert_info acpi_rs_convert_fixed_dma[4] = {
  214. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_FIXED_DMA,
  215. ACPI_RS_SIZE(struct acpi_resource_fixed_dma),
  216. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_fixed_dma)},
  217. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_FIXED_DMA,
  218. sizeof(struct aml_resource_fixed_dma),
  219. 0},
  220. /*
  221. * These fields are contiguous in both the source and destination:
  222. * request_lines
  223. * Channels
  224. */
  225. {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.fixed_dma.request_lines),
  226. AML_OFFSET(fixed_dma.request_lines),
  227. 2},
  228. {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.fixed_dma.width),
  229. AML_OFFSET(fixed_dma.width),
  230. 1},
  231. };