rsirq.c 17 KB

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