rsirq.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsirq - IRQ resource descriptors
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <acpi/acresrc.h>
  44. #define _COMPONENT ACPI_RESOURCES
  45. ACPI_MODULE_NAME("rsirq")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_rs_get_irq
  49. *
  50. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  51. * aml_resource_length - Length of the resource from the AML header
  52. * Resource - Where the internal resource is returned
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  57. * internal resource descriptor, simplifying bitflags and handling
  58. * alignment and endian issues if necessary.
  59. *
  60. ******************************************************************************/
  61. acpi_status
  62. acpi_rs_get_irq(union aml_resource *aml,
  63. u16 aml_resource_length, struct acpi_resource *resource)
  64. {
  65. u16 temp16 = 0;
  66. u32 interrupt_count = 0;
  67. u32 i;
  68. u32 resource_length;
  69. ACPI_FUNCTION_TRACE("rs_get_irq");
  70. /* Get the IRQ mask (bytes 1:2) */
  71. ACPI_MOVE_16_TO_16(&temp16, &aml->irq.irq_mask);
  72. /* Decode the IRQ bits (up to 16 possible) */
  73. for (i = 0; i < 16; i++) {
  74. if ((temp16 >> i) & 0x01) {
  75. resource->data.irq.interrupts[interrupt_count] = i;
  76. interrupt_count++;
  77. }
  78. }
  79. /* Zero interrupts is valid */
  80. resource_length = 0;
  81. resource->data.irq.interrupt_count = interrupt_count;
  82. if (interrupt_count > 0) {
  83. /* Calculate the structure size based upon the number of interrupts */
  84. resource_length = (u32) (interrupt_count - 1) * 4;
  85. }
  86. /* Get Flags (Byte 3) if it is used */
  87. if (aml_resource_length == 3) {
  88. /* Check for HE, LL interrupts */
  89. switch (aml->irq.flags & 0x09) {
  90. case 0x01: /* HE */
  91. resource->data.irq.triggering = ACPI_EDGE_SENSITIVE;
  92. resource->data.irq.polarity = ACPI_ACTIVE_HIGH;
  93. break;
  94. case 0x08: /* LL */
  95. resource->data.irq.triggering = ACPI_LEVEL_SENSITIVE;
  96. resource->data.irq.polarity = ACPI_ACTIVE_LOW;
  97. break;
  98. default:
  99. /*
  100. * Only _LL and _HE polarity/trigger interrupts
  101. * are allowed (ACPI spec, section "IRQ Format")
  102. * so 0x00 and 0x09 are illegal.
  103. */
  104. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  105. "Invalid interrupt polarity/trigger in resource list, %X\n",
  106. aml->irq.flags));
  107. return_ACPI_STATUS(AE_BAD_DATA);
  108. }
  109. /* Get Sharing flag */
  110. resource->data.irq.sharable = (aml->irq.flags >> 3) & 0x01;
  111. } else {
  112. /*
  113. * Default configuration: assume Edge Sensitive, Active High,
  114. * Non-Sharable as per the ACPI Specification
  115. */
  116. resource->data.irq.triggering = ACPI_EDGE_SENSITIVE;
  117. resource->data.irq.polarity = ACPI_ACTIVE_HIGH;
  118. resource->data.irq.sharable = ACPI_EXCLUSIVE;
  119. }
  120. /* Complete the resource header */
  121. resource->type = ACPI_RESOURCE_TYPE_IRQ;
  122. resource->length =
  123. resource_length + ACPI_SIZEOF_RESOURCE(struct acpi_resource_irq);
  124. return_ACPI_STATUS(AE_OK);
  125. }
  126. /*******************************************************************************
  127. *
  128. * FUNCTION: acpi_rs_set_irq
  129. *
  130. * PARAMETERS: Resource - Pointer to the resource descriptor
  131. * Aml - Where the AML descriptor is returned
  132. *
  133. * RETURN: Status
  134. *
  135. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  136. * external AML resource descriptor.
  137. *
  138. ******************************************************************************/
  139. acpi_status
  140. acpi_rs_set_irq(struct acpi_resource *resource, union aml_resource *aml)
  141. {
  142. acpi_size descriptor_length;
  143. u16 irq_mask;
  144. u8 i;
  145. ACPI_FUNCTION_TRACE("rs_set_irq");
  146. /* Convert interrupt list to 16-bit IRQ bitmask */
  147. irq_mask = 0;
  148. for (i = 0; i < resource->data.irq.interrupt_count; i++) {
  149. irq_mask |= (1 << resource->data.irq.interrupts[i]);
  150. }
  151. /* Set the interrupt mask */
  152. ACPI_MOVE_16_TO_16(&aml->irq.irq_mask, &irq_mask);
  153. /*
  154. * The descriptor field is set based upon whether a third byte is
  155. * needed to contain the IRQ Information.
  156. */
  157. if ((resource->data.irq.triggering == ACPI_EDGE_SENSITIVE) &&
  158. (resource->data.irq.polarity == ACPI_ACTIVE_HIGH) &&
  159. (resource->data.irq.sharable == ACPI_EXCLUSIVE)) {
  160. /* irq_no_flags() descriptor can be used */
  161. descriptor_length = sizeof(struct aml_resource_irq_noflags);
  162. } else {
  163. /* Irq() descriptor must be used */
  164. descriptor_length = sizeof(struct aml_resource_irq);
  165. /* Set the IRQ Info byte */
  166. aml->irq.flags = (u8)
  167. ((resource->data.irq.sharable & 0x01) << 4);
  168. if (ACPI_LEVEL_SENSITIVE == resource->data.irq.triggering &&
  169. ACPI_ACTIVE_LOW == resource->data.irq.polarity) {
  170. aml->irq.flags |= 0x08;
  171. } else {
  172. aml->irq.flags |= 0x01;
  173. }
  174. }
  175. /* Complete the AML descriptor header */
  176. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_IRQ, descriptor_length,
  177. aml);
  178. return_ACPI_STATUS(AE_OK);
  179. }
  180. /*******************************************************************************
  181. *
  182. * FUNCTION: acpi_rs_get_ext_irq
  183. *
  184. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  185. * aml_resource_length - Length of the resource from the AML header
  186. * Resource - Where the internal resource is returned
  187. *
  188. * RETURN: Status
  189. *
  190. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  191. * internal resource descriptor, simplifying bitflags and handling
  192. * alignment and endian issues if necessary.
  193. *
  194. ******************************************************************************/
  195. acpi_status
  196. acpi_rs_get_ext_irq(union aml_resource *aml,
  197. u16 aml_resource_length, struct acpi_resource *resource)
  198. {
  199. char *out_resource_string;
  200. u8 temp8;
  201. ACPI_FUNCTION_TRACE("rs_get_ext_irq");
  202. /* Get the flag bits */
  203. temp8 = aml->extended_irq.flags;
  204. resource->data.extended_irq.producer_consumer = temp8 & 0x01;
  205. resource->data.extended_irq.polarity = (temp8 >> 2) & 0x01;
  206. resource->data.extended_irq.sharable = (temp8 >> 3) & 0x01;
  207. /*
  208. * Check for Interrupt Mode
  209. *
  210. * The definition of an Extended IRQ changed between ACPI spec v1.0b
  211. * and ACPI spec 2.0 (section 6.4.3.6 in both).
  212. *
  213. * - Edge/Level are defined opposite in the table vs the headers
  214. */
  215. resource->data.extended_irq.triggering =
  216. (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE;
  217. /* Get the IRQ Table length (Byte4) */
  218. temp8 = aml->extended_irq.table_length;
  219. resource->data.extended_irq.interrupt_count = temp8;
  220. if (temp8 < 1) {
  221. /* Must have at least one IRQ */
  222. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
  223. }
  224. /*
  225. * Add any additional structure size to properly calculate
  226. * the next pointer at the end of this function
  227. */
  228. resource->length = (temp8 - 1) * 4;
  229. out_resource_string = ACPI_CAST_PTR(char,
  230. (&resource->data.extended_irq.
  231. interrupts[0] + temp8));
  232. /* Get every IRQ in the table, each is 32 bits */
  233. acpi_rs_move_data(resource->data.extended_irq.interrupts,
  234. aml->extended_irq.interrupt_number,
  235. (u16) temp8, ACPI_MOVE_TYPE_32_TO_32);
  236. /* Get the optional resource_source (index and string) */
  237. resource->length +=
  238. acpi_rs_get_resource_source(aml_resource_length,
  239. (acpi_size) resource->length +
  240. sizeof(struct
  241. aml_resource_extended_irq),
  242. &resource->data.extended_irq.
  243. resource_source, aml,
  244. out_resource_string);
  245. /* Complete the resource header */
  246. resource->type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
  247. resource->length +=
  248. ACPI_SIZEOF_RESOURCE(struct acpi_resource_extended_irq);
  249. return_ACPI_STATUS(AE_OK);
  250. }
  251. /*******************************************************************************
  252. *
  253. * FUNCTION: acpi_rs_set_ext_irq
  254. *
  255. * PARAMETERS: Resource - Pointer to the resource descriptor
  256. * Aml - Where the AML descriptor is returned
  257. *
  258. * RETURN: Status
  259. *
  260. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  261. * external AML resource descriptor.
  262. *
  263. ******************************************************************************/
  264. acpi_status
  265. acpi_rs_set_ext_irq(struct acpi_resource *resource, union aml_resource *aml)
  266. {
  267. acpi_size descriptor_length;
  268. ACPI_FUNCTION_TRACE("rs_set_ext_irq");
  269. /* Set the Interrupt vector flags */
  270. aml->extended_irq.flags = (u8)
  271. ((resource->data.extended_irq.producer_consumer & 0x01) |
  272. ((resource->data.extended_irq.sharable & 0x01) << 3) |
  273. ((resource->data.extended_irq.polarity & 0x1) << 2));
  274. /*
  275. * Set the Interrupt Mode
  276. *
  277. * The definition of an Extended IRQ changed between ACPI spec v1.0b
  278. * and ACPI spec 2.0 (section 6.4.3.6 in both). This code does not
  279. * implement the more restrictive definition of 1.0b
  280. *
  281. * - Edge/Level are defined opposite in the table vs the headers
  282. */
  283. if (resource->data.extended_irq.triggering == ACPI_EDGE_SENSITIVE) {
  284. aml->extended_irq.flags |= 0x02;
  285. }
  286. /* Set the Interrupt table length */
  287. aml->extended_irq.table_length = (u8)
  288. resource->data.extended_irq.interrupt_count;
  289. descriptor_length = (sizeof(struct aml_resource_extended_irq) - 4) +
  290. ((acpi_size) resource->data.extended_irq.interrupt_count *
  291. sizeof(u32));
  292. /* Set each interrupt value */
  293. acpi_rs_move_data(aml->extended_irq.interrupt_number,
  294. resource->data.extended_irq.interrupts,
  295. (u16) resource->data.extended_irq.interrupt_count,
  296. ACPI_MOVE_TYPE_32_TO_32);
  297. /* Resource Source Index and Resource Source are optional */
  298. descriptor_length = acpi_rs_set_resource_source(aml, descriptor_length,
  299. &resource->data.
  300. extended_irq.
  301. resource_source);
  302. /* Complete the AML descriptor header */
  303. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_EXTENDED_IRQ,
  304. descriptor_length, aml);
  305. return_ACPI_STATUS(AE_OK);
  306. }