rsirq.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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_irq_resource
  49. *
  50. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  51. * stream
  52. * bytes_consumed - Pointer to where the number of bytes
  53. * consumed the byte_stream_buffer is
  54. * returned
  55. * output_buffer - Pointer to the return data buffer
  56. * structure_size - Pointer to where the number of bytes
  57. * in the return data struct is returned
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  62. * structure pointed to by the output_buffer. Return the
  63. * number of bytes consumed from the byte stream.
  64. *
  65. ******************************************************************************/
  66. acpi_status
  67. acpi_rs_irq_resource(u8 * byte_stream_buffer,
  68. acpi_size * bytes_consumed,
  69. u8 ** output_buffer, acpi_size * structure_size)
  70. {
  71. u8 *buffer = byte_stream_buffer;
  72. struct acpi_resource *output_struct = (void *)*output_buffer;
  73. u16 temp16 = 0;
  74. u8 temp8 = 0;
  75. u8 index;
  76. u8 i;
  77. acpi_size struct_size = ACPI_SIZEOF_RESOURCE(struct acpi_resource_irq);
  78. ACPI_FUNCTION_TRACE("rs_irq_resource");
  79. /*
  80. * The number of bytes consumed are contained in the descriptor
  81. * (Bits:0-1)
  82. */
  83. temp8 = *buffer;
  84. *bytes_consumed = (temp8 & 0x03) + 1;
  85. output_struct->id = ACPI_RSTYPE_IRQ;
  86. /* Point to the 16-bits of Bytes 1 and 2 */
  87. buffer += 1;
  88. ACPI_MOVE_16_TO_16(&temp16, buffer);
  89. output_struct->data.irq.number_of_interrupts = 0;
  90. /* Decode the IRQ bits */
  91. for (i = 0, index = 0; index < 16; index++) {
  92. if ((temp16 >> index) & 0x01) {
  93. output_struct->data.irq.interrupts[i] = index;
  94. i++;
  95. }
  96. }
  97. /* Zero interrupts is valid */
  98. output_struct->data.irq.number_of_interrupts = i;
  99. if (i > 0) {
  100. /* Calculate the structure size based upon the number of interrupts */
  101. struct_size += ((acpi_size) i - 1) * 4;
  102. }
  103. /* Point to Byte 3 if it is used */
  104. if (4 == *bytes_consumed) {
  105. buffer += 2;
  106. temp8 = *buffer;
  107. /* Check for HE, LL interrupts */
  108. switch (temp8 & 0x09) {
  109. case 0x01: /* HE */
  110. output_struct->data.irq.edge_level =
  111. ACPI_EDGE_SENSITIVE;
  112. output_struct->data.irq.active_high_low =
  113. ACPI_ACTIVE_HIGH;
  114. break;
  115. case 0x08: /* LL */
  116. output_struct->data.irq.edge_level =
  117. ACPI_LEVEL_SENSITIVE;
  118. output_struct->data.irq.active_high_low =
  119. ACPI_ACTIVE_LOW;
  120. break;
  121. default:
  122. /*
  123. * Only _LL and _HE polarity/trigger interrupts
  124. * are allowed (ACPI spec, section "IRQ Format")
  125. * so 0x00 and 0x09 are illegal.
  126. */
  127. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  128. "Invalid interrupt polarity/trigger in resource list, %X\n",
  129. temp8));
  130. return_ACPI_STATUS(AE_BAD_DATA);
  131. }
  132. /* Check for sharable */
  133. output_struct->data.irq.shared_exclusive = (temp8 >> 3) & 0x01;
  134. } else {
  135. /*
  136. * Assume Edge Sensitive, Active High, Non-Sharable
  137. * per ACPI Specification
  138. */
  139. output_struct->data.irq.edge_level = ACPI_EDGE_SENSITIVE;
  140. output_struct->data.irq.active_high_low = ACPI_ACTIVE_HIGH;
  141. output_struct->data.irq.shared_exclusive = ACPI_EXCLUSIVE;
  142. }
  143. /* Set the Length parameter */
  144. output_struct->length = (u32) struct_size;
  145. /* Return the final size of the structure */
  146. *structure_size = struct_size;
  147. return_ACPI_STATUS(AE_OK);
  148. }
  149. /*******************************************************************************
  150. *
  151. * FUNCTION: acpi_rs_irq_stream
  152. *
  153. * PARAMETERS: linked_list - Pointer to the resource linked list
  154. * output_buffer - Pointer to the user's return buffer
  155. * bytes_consumed - Pointer to where the number of bytes
  156. * used in the output_buffer is returned
  157. *
  158. * RETURN: Status
  159. *
  160. * DESCRIPTION: Take the linked list resource structure and fills in the
  161. * the appropriate bytes in a byte stream
  162. *
  163. ******************************************************************************/
  164. acpi_status
  165. acpi_rs_irq_stream(struct acpi_resource *linked_list,
  166. u8 ** output_buffer, acpi_size * bytes_consumed)
  167. {
  168. u8 *buffer = *output_buffer;
  169. u16 temp16 = 0;
  170. u8 temp8 = 0;
  171. u8 index;
  172. u8 IRqinfo_byte_needed;
  173. ACPI_FUNCTION_TRACE("rs_irq_stream");
  174. /*
  175. * The descriptor field is set based upon whether a third byte is
  176. * needed to contain the IRQ Information.
  177. */
  178. if (ACPI_EDGE_SENSITIVE == linked_list->data.irq.edge_level &&
  179. ACPI_ACTIVE_HIGH == linked_list->data.irq.active_high_low &&
  180. ACPI_EXCLUSIVE == linked_list->data.irq.shared_exclusive) {
  181. *buffer = 0x22;
  182. IRqinfo_byte_needed = FALSE;
  183. } else {
  184. *buffer = 0x23;
  185. IRqinfo_byte_needed = TRUE;
  186. }
  187. buffer += 1;
  188. temp16 = 0;
  189. /* Loop through all of the interrupts and set the mask bits */
  190. for (index = 0;
  191. index < linked_list->data.irq.number_of_interrupts; index++) {
  192. temp8 = (u8) linked_list->data.irq.interrupts[index];
  193. temp16 |= 0x1 << temp8;
  194. }
  195. ACPI_MOVE_16_TO_16(buffer, &temp16);
  196. buffer += 2;
  197. /* Set the IRQ Info byte if needed. */
  198. if (IRqinfo_byte_needed) {
  199. temp8 = 0;
  200. temp8 = (u8) ((linked_list->data.irq.shared_exclusive &
  201. 0x01) << 4);
  202. if (ACPI_LEVEL_SENSITIVE == linked_list->data.irq.edge_level &&
  203. ACPI_ACTIVE_LOW == linked_list->data.irq.active_high_low) {
  204. temp8 |= 0x08;
  205. } else {
  206. temp8 |= 0x01;
  207. }
  208. *buffer = temp8;
  209. buffer += 1;
  210. }
  211. /* Return the number of bytes consumed in this operation */
  212. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  213. return_ACPI_STATUS(AE_OK);
  214. }
  215. /*******************************************************************************
  216. *
  217. * FUNCTION: acpi_rs_extended_irq_resource
  218. *
  219. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  220. * stream
  221. * bytes_consumed - Pointer to where the number of bytes
  222. * consumed the byte_stream_buffer is
  223. * returned
  224. * output_buffer - Pointer to the return data buffer
  225. * structure_size - Pointer to where the number of bytes
  226. * in the return data struct is returned
  227. *
  228. * RETURN: Status
  229. *
  230. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  231. * structure pointed to by the output_buffer. Return the
  232. * number of bytes consumed from the byte stream.
  233. *
  234. ******************************************************************************/
  235. acpi_status
  236. acpi_rs_extended_irq_resource(u8 * byte_stream_buffer,
  237. acpi_size * bytes_consumed,
  238. u8 ** output_buffer, acpi_size * structure_size)
  239. {
  240. u8 *buffer = byte_stream_buffer;
  241. struct acpi_resource *output_struct = (void *)*output_buffer;
  242. u16 temp16 = 0;
  243. u8 temp8 = 0;
  244. u8 *temp_ptr;
  245. u8 index;
  246. acpi_size struct_size =
  247. ACPI_SIZEOF_RESOURCE(struct acpi_resource_ext_irq);
  248. ACPI_FUNCTION_TRACE("rs_extended_irq_resource");
  249. /* Get the Descriptor Length field */
  250. buffer += 1;
  251. ACPI_MOVE_16_TO_16(&temp16, buffer);
  252. /* Validate minimum descriptor length */
  253. if (temp16 < 6) {
  254. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
  255. }
  256. *bytes_consumed = temp16 + 3;
  257. output_struct->id = ACPI_RSTYPE_EXT_IRQ;
  258. /* Point to the Byte3 */
  259. buffer += 2;
  260. temp8 = *buffer;
  261. output_struct->data.extended_irq.producer_consumer = temp8 & 0x01;
  262. /*
  263. * Check for Interrupt Mode
  264. *
  265. * The definition of an Extended IRQ changed between ACPI spec v1.0b
  266. * and ACPI spec 2.0 (section 6.4.3.6 in both).
  267. *
  268. * - Edge/Level are defined opposite in the table vs the headers
  269. */
  270. output_struct->data.extended_irq.edge_level =
  271. (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE;
  272. /* Check Interrupt Polarity */
  273. output_struct->data.extended_irq.active_high_low = (temp8 >> 2) & 0x1;
  274. /* Check for sharable */
  275. output_struct->data.extended_irq.shared_exclusive = (temp8 >> 3) & 0x01;
  276. /* Point to Byte4 (IRQ Table length) */
  277. buffer += 1;
  278. temp8 = *buffer;
  279. /* Must have at least one IRQ */
  280. if (temp8 < 1) {
  281. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
  282. }
  283. output_struct->data.extended_irq.number_of_interrupts = temp8;
  284. /*
  285. * Add any additional structure size to properly calculate
  286. * the next pointer at the end of this function
  287. */
  288. struct_size += (temp8 - 1) * 4;
  289. /* Point to Byte5 (First IRQ Number) */
  290. buffer += 1;
  291. /* Cycle through every IRQ in the table */
  292. for (index = 0; index < temp8; index++) {
  293. ACPI_MOVE_32_TO_32(&output_struct->data.extended_irq.
  294. interrupts[index], buffer);
  295. /* Point to the next IRQ */
  296. buffer += 4;
  297. }
  298. /*
  299. * This will leave us pointing to the Resource Source Index
  300. * If it is present, then save it off and calculate the
  301. * pointer to where the null terminated string goes:
  302. * Each Interrupt takes 32-bits + the 5 bytes of the
  303. * stream that are default.
  304. *
  305. * Note: Some resource descriptors will have an additional null, so
  306. * we add 1 to the length.
  307. */
  308. if (*bytes_consumed >
  309. ((acpi_size) output_struct->data.extended_irq.number_of_interrupts *
  310. 4) + (5 + 1)) {
  311. /* Dereference the Index */
  312. temp8 = *buffer;
  313. output_struct->data.extended_irq.resource_source.index =
  314. (u32) temp8;
  315. /* Point to the String */
  316. buffer += 1;
  317. /* Point the String pointer to the end of this structure. */
  318. output_struct->data.extended_irq.resource_source.string_ptr =
  319. (char *)((char *)output_struct + struct_size);
  320. temp_ptr = (u8 *)
  321. output_struct->data.extended_irq.resource_source.string_ptr;
  322. /* Copy the string into the buffer */
  323. index = 0;
  324. while (*buffer) {
  325. *temp_ptr = *buffer;
  326. temp_ptr += 1;
  327. buffer += 1;
  328. index += 1;
  329. }
  330. /* Add the terminating null */
  331. *temp_ptr = 0;
  332. output_struct->data.extended_irq.resource_source.string_length =
  333. index + 1;
  334. /*
  335. * In order for the struct_size to fall on a 32-bit boundary,
  336. * calculate the length of the string and expand the
  337. * struct_size to the next 32-bit boundary.
  338. */
  339. temp8 = (u8) (index + 1);
  340. struct_size += ACPI_ROUND_UP_to_32_bITS(temp8);
  341. } else {
  342. output_struct->data.extended_irq.resource_source.index = 0;
  343. output_struct->data.extended_irq.resource_source.string_length =
  344. 0;
  345. output_struct->data.extended_irq.resource_source.string_ptr =
  346. NULL;
  347. }
  348. /* Set the Length parameter */
  349. output_struct->length = (u32) struct_size;
  350. /* Return the final size of the structure */
  351. *structure_size = struct_size;
  352. return_ACPI_STATUS(AE_OK);
  353. }
  354. /*******************************************************************************
  355. *
  356. * FUNCTION: acpi_rs_extended_irq_stream
  357. *
  358. * PARAMETERS: linked_list - Pointer to the resource linked list
  359. * output_buffer - Pointer to the user's return buffer
  360. * bytes_consumed - Pointer to where the number of bytes
  361. * used in the output_buffer is returned
  362. *
  363. * RETURN: Status
  364. *
  365. * DESCRIPTION: Take the linked list resource structure and fills in the
  366. * the appropriate bytes in a byte stream
  367. *
  368. ******************************************************************************/
  369. acpi_status
  370. acpi_rs_extended_irq_stream(struct acpi_resource *linked_list,
  371. u8 ** output_buffer, acpi_size * bytes_consumed)
  372. {
  373. u8 *buffer = *output_buffer;
  374. u16 *length_field;
  375. u8 temp8 = 0;
  376. u8 index;
  377. ACPI_FUNCTION_TRACE("rs_extended_irq_stream");
  378. /* Set the Descriptor Type field */
  379. *buffer = ACPI_RDESC_TYPE_EXTENDED_XRUPT;
  380. buffer += 1;
  381. /* Save a pointer to the Length field - to be filled in later */
  382. length_field = ACPI_CAST_PTR(u16, buffer);
  383. buffer += 2;
  384. /* Set the Interrupt vector flags */
  385. temp8 = (u8) (linked_list->data.extended_irq.producer_consumer & 0x01);
  386. temp8 |=
  387. ((linked_list->data.extended_irq.shared_exclusive & 0x01) << 3);
  388. /*
  389. * Set the Interrupt Mode
  390. *
  391. * The definition of an Extended IRQ changed between ACPI spec v1.0b
  392. * and ACPI spec 2.0 (section 6.4.3.6 in both). This code does not
  393. * implement the more restrictive definition of 1.0b
  394. *
  395. * - Edge/Level are defined opposite in the table vs the headers
  396. */
  397. if (ACPI_EDGE_SENSITIVE == linked_list->data.extended_irq.edge_level) {
  398. temp8 |= 0x2;
  399. }
  400. /* Set the Interrupt Polarity */
  401. temp8 |= ((linked_list->data.extended_irq.active_high_low & 0x1) << 2);
  402. *buffer = temp8;
  403. buffer += 1;
  404. /* Set the Interrupt table length */
  405. temp8 = (u8) linked_list->data.extended_irq.number_of_interrupts;
  406. *buffer = temp8;
  407. buffer += 1;
  408. for (index = 0;
  409. index < linked_list->data.extended_irq.number_of_interrupts;
  410. index++) {
  411. ACPI_MOVE_32_TO_32(buffer,
  412. &linked_list->data.extended_irq.
  413. interrupts[index]);
  414. buffer += 4;
  415. }
  416. /* Resource Source Index and Resource Source are optional */
  417. if (0 != linked_list->data.extended_irq.resource_source.string_length) {
  418. *buffer =
  419. (u8) linked_list->data.extended_irq.resource_source.index;
  420. buffer += 1;
  421. /* Copy the string */
  422. ACPI_STRCPY((char *)buffer,
  423. linked_list->data.extended_irq.resource_source.
  424. string_ptr);
  425. /*
  426. * Buffer needs to be set to the length of the string + one for the
  427. * terminating null
  428. */
  429. buffer +=
  430. (acpi_size) (ACPI_STRLEN
  431. (linked_list->data.extended_irq.
  432. resource_source.string_ptr) + 1);
  433. }
  434. /* Return the number of bytes consumed in this operation */
  435. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  436. /*
  437. * Set the length field to the number of bytes consumed
  438. * minus the header size (3 bytes)
  439. */
  440. *length_field = (u16) (*bytes_consumed - 3);
  441. return_ACPI_STATUS(AE_OK);
  442. }