rsirq.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsirq - IRQ resource descriptors
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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[9] = {
  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], Wake[5] */
  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. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.wake_capable),
  81. AML_OFFSET(irq.flags),
  82. 5}
  83. };
  84. /*******************************************************************************
  85. *
  86. * acpi_rs_set_irq
  87. *
  88. ******************************************************************************/
  89. struct acpi_rsconvert_info acpi_rs_set_irq[14] = {
  90. /* Start with a default descriptor of length 3 */
  91. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_IRQ,
  92. sizeof(struct aml_resource_irq),
  93. ACPI_RSC_TABLE_SIZE(acpi_rs_set_irq)},
  94. /* Convert interrupt list to 16-bit IRQ bitmask */
  95. {ACPI_RSC_BITMASK16, ACPI_RS_OFFSET(data.irq.interrupts[0]),
  96. AML_OFFSET(irq.irq_mask),
  97. ACPI_RS_OFFSET(data.irq.interrupt_count)},
  98. /* Set flags: Triggering[0], Polarity[3], Sharing[4], Wake[5] */
  99. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.triggering),
  100. AML_OFFSET(irq.flags),
  101. 0},
  102. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.polarity),
  103. AML_OFFSET(irq.flags),
  104. 3},
  105. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.sharable),
  106. AML_OFFSET(irq.flags),
  107. 4},
  108. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.wake_capable),
  109. AML_OFFSET(irq.flags),
  110. 5},
  111. /*
  112. * All done if the output descriptor length is required to be 3
  113. * (i.e., optimization to 2 bytes cannot be attempted)
  114. */
  115. {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,
  116. ACPI_RS_OFFSET(data.irq.descriptor_length),
  117. 3},
  118. /* Set length to 2 bytes (no flags byte) */
  119. {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq_noflags)},
  120. /*
  121. * All done if the output descriptor length is required to be 2.
  122. *
  123. * TBD: Perhaps we should check for error if input flags are not
  124. * compatible with a 2-byte descriptor.
  125. */
  126. {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,
  127. ACPI_RS_OFFSET(data.irq.descriptor_length),
  128. 2},
  129. /* Reset length to 3 bytes (descriptor with flags byte) */
  130. {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq)},
  131. /*
  132. * Check if the flags byte is necessary. Not needed if the flags are:
  133. * ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_HIGH, ACPI_EXCLUSIVE
  134. */
  135. {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE,
  136. ACPI_RS_OFFSET(data.irq.triggering),
  137. ACPI_EDGE_SENSITIVE},
  138. {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE,
  139. ACPI_RS_OFFSET(data.irq.polarity),
  140. ACPI_ACTIVE_HIGH},
  141. {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE,
  142. ACPI_RS_OFFSET(data.irq.sharable),
  143. ACPI_EXCLUSIVE},
  144. /* We can optimize to a 2-byte irq_no_flags() descriptor */
  145. {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq_noflags)}
  146. };
  147. /*******************************************************************************
  148. *
  149. * acpi_rs_convert_ext_irq
  150. *
  151. ******************************************************************************/
  152. struct acpi_rsconvert_info acpi_rs_convert_ext_irq[10] = {
  153. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_EXTENDED_IRQ,
  154. ACPI_RS_SIZE(struct acpi_resource_extended_irq),
  155. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_ext_irq)},
  156. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_EXTENDED_IRQ,
  157. sizeof(struct aml_resource_extended_irq),
  158. 0},
  159. /*
  160. * Flags: Producer/Consumer[0], Triggering[1], Polarity[2],
  161. * Sharing[3], Wake[4]
  162. */
  163. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.extended_irq.producer_consumer),
  164. AML_OFFSET(extended_irq.flags),
  165. 0},
  166. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.extended_irq.triggering),
  167. AML_OFFSET(extended_irq.flags),
  168. 1},
  169. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.extended_irq.polarity),
  170. AML_OFFSET(extended_irq.flags),
  171. 2},
  172. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.extended_irq.sharable),
  173. AML_OFFSET(extended_irq.flags),
  174. 3},
  175. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.extended_irq.wake_capable),
  176. AML_OFFSET(extended_irq.flags),
  177. 4},
  178. /* IRQ Table length (Byte4) */
  179. {ACPI_RSC_COUNT, ACPI_RS_OFFSET(data.extended_irq.interrupt_count),
  180. AML_OFFSET(extended_irq.interrupt_count),
  181. sizeof(u32)},
  182. /* Copy every IRQ in the table, each is 32 bits */
  183. {ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.extended_irq.interrupts[0]),
  184. AML_OFFSET(extended_irq.interrupts[0]),
  185. 0},
  186. /* Optional resource_source (Index and String) */
  187. {ACPI_RSC_SOURCEX, ACPI_RS_OFFSET(data.extended_irq.resource_source),
  188. ACPI_RS_OFFSET(data.extended_irq.interrupts[0]),
  189. sizeof(struct aml_resource_extended_irq)}
  190. };
  191. /*******************************************************************************
  192. *
  193. * acpi_rs_convert_dma
  194. *
  195. ******************************************************************************/
  196. struct acpi_rsconvert_info acpi_rs_convert_dma[6] = {
  197. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_DMA,
  198. ACPI_RS_SIZE(struct acpi_resource_dma),
  199. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_dma)},
  200. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_DMA,
  201. sizeof(struct aml_resource_dma),
  202. 0},
  203. /* Flags: transfer preference, bus mastering, channel speed */
  204. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.dma.transfer),
  205. AML_OFFSET(dma.flags),
  206. 0},
  207. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.dma.bus_master),
  208. AML_OFFSET(dma.flags),
  209. 2},
  210. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.dma.type),
  211. AML_OFFSET(dma.flags),
  212. 5},
  213. /* DMA channel mask bits */
  214. {ACPI_RSC_BITMASK, ACPI_RS_OFFSET(data.dma.channels[0]),
  215. AML_OFFSET(dma.dma_channel_mask),
  216. ACPI_RS_OFFSET(data.dma.channel_count)}
  217. };
  218. /*******************************************************************************
  219. *
  220. * acpi_rs_convert_fixed_dma
  221. *
  222. ******************************************************************************/
  223. struct acpi_rsconvert_info acpi_rs_convert_fixed_dma[4] = {
  224. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_FIXED_DMA,
  225. ACPI_RS_SIZE(struct acpi_resource_fixed_dma),
  226. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_fixed_dma)},
  227. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_FIXED_DMA,
  228. sizeof(struct aml_resource_fixed_dma),
  229. 0},
  230. /*
  231. * These fields are contiguous in both the source and destination:
  232. * request_lines
  233. * Channels
  234. */
  235. {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.fixed_dma.request_lines),
  236. AML_OFFSET(fixed_dma.request_lines),
  237. 2},
  238. {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.fixed_dma.width),
  239. AML_OFFSET(fixed_dma.width),
  240. 1},
  241. };