rsirq.c 17 KB

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