rscalc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /*******************************************************************************
  2. *
  3. * Module Name: rscalc - Calculate stream and list lengths
  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. #include <acpi/amlcode.h>
  45. #include <acpi/acnamesp.h>
  46. #define _COMPONENT ACPI_RESOURCES
  47. ACPI_MODULE_NAME("rscalc")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_rs_get_byte_stream_length
  51. *
  52. * PARAMETERS: linked_list - Pointer to the resource linked list
  53. * size_needed - u32 pointer of the size buffer needed
  54. * to properly return the parsed data
  55. *
  56. * RETURN: Status
  57. *
  58. * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
  59. * the size buffer needed to hold the linked list that conveys
  60. * the resource data.
  61. *
  62. ******************************************************************************/
  63. acpi_status
  64. acpi_rs_get_byte_stream_length(struct acpi_resource *linked_list,
  65. acpi_size * size_needed)
  66. {
  67. acpi_size byte_stream_size_needed = 0;
  68. acpi_size segment_size;
  69. u8 done = FALSE;
  70. ACPI_FUNCTION_TRACE("rs_get_byte_stream_length");
  71. while (!done) {
  72. /* Init the variable that will hold the size to add to the total. */
  73. segment_size = 0;
  74. switch (linked_list->id) {
  75. case ACPI_RSTYPE_IRQ:
  76. /*
  77. * IRQ Resource
  78. * For an IRQ Resource, Byte 3, although optional, will always be
  79. * created - it holds IRQ information.
  80. */
  81. segment_size = 4;
  82. break;
  83. case ACPI_RSTYPE_DMA:
  84. /*
  85. * DMA Resource
  86. * For this resource the size is static
  87. */
  88. segment_size = 3;
  89. break;
  90. case ACPI_RSTYPE_START_DPF:
  91. /*
  92. * Start Dependent Functions Resource
  93. * For a start_dependent_functions Resource, Byte 1, although
  94. * optional, will always be created.
  95. */
  96. segment_size = 2;
  97. break;
  98. case ACPI_RSTYPE_END_DPF:
  99. /*
  100. * End Dependent Functions Resource
  101. * For this resource the size is static
  102. */
  103. segment_size = 1;
  104. break;
  105. case ACPI_RSTYPE_IO:
  106. /*
  107. * IO Port Resource
  108. * For this resource the size is static
  109. */
  110. segment_size = 8;
  111. break;
  112. case ACPI_RSTYPE_FIXED_IO:
  113. /*
  114. * Fixed IO Port Resource
  115. * For this resource the size is static
  116. */
  117. segment_size = 4;
  118. break;
  119. case ACPI_RSTYPE_VENDOR:
  120. /*
  121. * Vendor Defined Resource
  122. * For a Vendor Specific resource, if the Length is between 1 and 7
  123. * it will be created as a Small Resource data type, otherwise it
  124. * is a Large Resource data type.
  125. */
  126. if (linked_list->data.vendor_specific.length > 7) {
  127. segment_size = 3;
  128. } else {
  129. segment_size = 1;
  130. }
  131. segment_size +=
  132. linked_list->data.vendor_specific.length;
  133. break;
  134. case ACPI_RSTYPE_END_TAG:
  135. /*
  136. * End Tag
  137. * For this resource the size is static
  138. */
  139. segment_size = 2;
  140. done = TRUE;
  141. break;
  142. case ACPI_RSTYPE_MEM24:
  143. /*
  144. * 24-Bit Memory Resource
  145. * For this resource the size is static
  146. */
  147. segment_size = 12;
  148. break;
  149. case ACPI_RSTYPE_MEM32:
  150. /*
  151. * 32-Bit Memory Range Resource
  152. * For this resource the size is static
  153. */
  154. segment_size = 20;
  155. break;
  156. case ACPI_RSTYPE_FIXED_MEM32:
  157. /*
  158. * 32-Bit Fixed Memory Resource
  159. * For this resource the size is static
  160. */
  161. segment_size = 12;
  162. break;
  163. case ACPI_RSTYPE_ADDRESS16:
  164. /*
  165. * 16-Bit Address Resource
  166. * The base size of this byte stream is 16. If a Resource Source
  167. * string is not NULL, add 1 for the Index + the length of the null
  168. * terminated string Resource Source + 1 for the null.
  169. */
  170. segment_size = 16;
  171. if (linked_list->data.address16.resource_source.
  172. string_ptr) {
  173. segment_size +=
  174. linked_list->data.address16.resource_source.
  175. string_length;
  176. segment_size++;
  177. }
  178. break;
  179. case ACPI_RSTYPE_ADDRESS32:
  180. /*
  181. * 32-Bit Address Resource
  182. * The base size of this byte stream is 26. If a Resource
  183. * Source string is not NULL, add 1 for the Index + the
  184. * length of the null terminated string Resource Source +
  185. * 1 for the null.
  186. */
  187. segment_size = 26;
  188. if (linked_list->data.address32.resource_source.
  189. string_ptr) {
  190. segment_size +=
  191. linked_list->data.address32.resource_source.
  192. string_length;
  193. segment_size++;
  194. }
  195. break;
  196. case ACPI_RSTYPE_ADDRESS64:
  197. /*
  198. * 64-Bit Address Resource
  199. * The base size of this byte stream is 46. If a resource_source
  200. * string is not NULL, add 1 for the Index + the length of the null
  201. * terminated string Resource Source + 1 for the null.
  202. */
  203. segment_size = 46;
  204. if (linked_list->data.address64.resource_source.
  205. string_ptr) {
  206. segment_size +=
  207. linked_list->data.address64.resource_source.
  208. string_length;
  209. segment_size++;
  210. }
  211. break;
  212. case ACPI_RSTYPE_EXT_IRQ:
  213. /*
  214. * Extended IRQ Resource
  215. * The base size of this byte stream is 9. This is for an Interrupt
  216. * table length of 1. For each additional interrupt, add 4.
  217. * If a Resource Source string is not NULL, add 1 for the
  218. * Index + the length of the null terminated string
  219. * Resource Source + 1 for the null.
  220. */
  221. segment_size = 9 + (((acpi_size)
  222. linked_list->data.extended_irq.
  223. number_of_interrupts - 1) * 4);
  224. if (linked_list->data.extended_irq.resource_source.
  225. string_ptr) {
  226. segment_size +=
  227. linked_list->data.extended_irq.
  228. resource_source.string_length;
  229. segment_size++;
  230. }
  231. break;
  232. default:
  233. /* If we get here, everything is out of sync, exit with error */
  234. return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
  235. } /* switch (linked_list->Id) */
  236. /* Update the total */
  237. byte_stream_size_needed += segment_size;
  238. /* Point to the next object */
  239. linked_list = ACPI_PTR_ADD(struct acpi_resource,
  240. linked_list, linked_list->length);
  241. }
  242. /* This is the data the caller needs */
  243. *size_needed = byte_stream_size_needed;
  244. return_ACPI_STATUS(AE_OK);
  245. }
  246. /*******************************************************************************
  247. *
  248. * FUNCTION: acpi_rs_get_list_length
  249. *
  250. * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream
  251. * byte_stream_buffer_length - Size of byte_stream_buffer
  252. * size_needed - u32 pointer of the size buffer
  253. * needed to properly return the
  254. * parsed data
  255. *
  256. * RETURN: Status
  257. *
  258. * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
  259. * the size buffer needed to hold the linked list that conveys
  260. * the resource data.
  261. *
  262. ******************************************************************************/
  263. acpi_status
  264. acpi_rs_get_list_length(u8 * byte_stream_buffer,
  265. u32 byte_stream_buffer_length, acpi_size * size_needed)
  266. {
  267. u32 buffer_size = 0;
  268. u32 bytes_parsed = 0;
  269. u8 number_of_interrupts = 0;
  270. u8 number_of_channels = 0;
  271. u8 resource_type;
  272. u32 structure_size;
  273. u32 bytes_consumed;
  274. u8 *buffer;
  275. u8 temp8;
  276. u16 temp16;
  277. u8 index;
  278. u8 additional_bytes;
  279. ACPI_FUNCTION_TRACE("rs_get_list_length");
  280. while (bytes_parsed < byte_stream_buffer_length) {
  281. /* The next byte in the stream is the resource type */
  282. resource_type = acpi_rs_get_resource_type(*byte_stream_buffer);
  283. switch (resource_type) {
  284. case ACPI_RDESC_TYPE_MEMORY_24:
  285. /*
  286. * 24-Bit Memory Resource
  287. */
  288. bytes_consumed = 12;
  289. structure_size =
  290. ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem24);
  291. break;
  292. case ACPI_RDESC_TYPE_LARGE_VENDOR:
  293. /*
  294. * Vendor Defined Resource
  295. */
  296. buffer = byte_stream_buffer;
  297. ++buffer;
  298. ACPI_MOVE_16_TO_16(&temp16, buffer);
  299. bytes_consumed = temp16 + 3;
  300. /* Ensure a 32-bit boundary for the structure */
  301. temp16 = (u16) ACPI_ROUND_UP_to_32_bITS(temp16);
  302. structure_size =
  303. ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) +
  304. (temp16 * sizeof(u8));
  305. break;
  306. case ACPI_RDESC_TYPE_MEMORY_32:
  307. /*
  308. * 32-Bit Memory Range Resource
  309. */
  310. bytes_consumed = 20;
  311. structure_size =
  312. ACPI_SIZEOF_RESOURCE(struct acpi_resource_mem32);
  313. break;
  314. case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
  315. /*
  316. * 32-Bit Fixed Memory Resource
  317. */
  318. bytes_consumed = 12;
  319. structure_size =
  320. ACPI_SIZEOF_RESOURCE(struct
  321. acpi_resource_fixed_mem32);
  322. break;
  323. case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE:
  324. /*
  325. * 64-Bit Address Resource
  326. */
  327. buffer = byte_stream_buffer;
  328. ++buffer;
  329. ACPI_MOVE_16_TO_16(&temp16, buffer);
  330. bytes_consumed = temp16 + 3;
  331. structure_size =
  332. ACPI_SIZEOF_RESOURCE(struct
  333. acpi_resource_address64);
  334. break;
  335. case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
  336. /*
  337. * 64-Bit Address Resource
  338. */
  339. buffer = byte_stream_buffer;
  340. ++buffer;
  341. ACPI_MOVE_16_TO_16(&temp16, buffer);
  342. bytes_consumed = temp16 + 3;
  343. /*
  344. * Resource Source Index and Resource Source are optional elements.
  345. * Check the length of the Bytestream. If it is greater than 43,
  346. * that means that an Index exists and is followed by a null
  347. * terminated string. Therefore, set the temp variable to the
  348. * length minus the minimum byte stream length plus the byte for
  349. * the Index to determine the size of the NULL terminated string.
  350. */
  351. if (43 < temp16) {
  352. temp8 = (u8) (temp16 - 44);
  353. } else {
  354. temp8 = 0;
  355. }
  356. /* Ensure a 64-bit boundary for the structure */
  357. temp8 = (u8) ACPI_ROUND_UP_to_64_bITS(temp8);
  358. structure_size =
  359. ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64)
  360. + (temp8 * sizeof(u8));
  361. break;
  362. case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
  363. /*
  364. * 32-Bit Address Resource
  365. */
  366. buffer = byte_stream_buffer;
  367. ++buffer;
  368. ACPI_MOVE_16_TO_16(&temp16, buffer);
  369. bytes_consumed = temp16 + 3;
  370. /*
  371. * Resource Source Index and Resource Source are optional elements.
  372. * Check the length of the Bytestream. If it is greater than 23,
  373. * that means that an Index exists and is followed by a null
  374. * terminated string. Therefore, set the temp variable to the
  375. * length minus the minimum byte stream length plus the byte for
  376. * the Index to determine the size of the NULL terminated string.
  377. */
  378. if (23 < temp16) {
  379. temp8 = (u8) (temp16 - 24);
  380. } else {
  381. temp8 = 0;
  382. }
  383. /* Ensure a 32-bit boundary for the structure */
  384. temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8);
  385. structure_size =
  386. ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32)
  387. + (temp8 * sizeof(u8));
  388. break;
  389. case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
  390. /*
  391. * 16-Bit Address Resource
  392. */
  393. buffer = byte_stream_buffer;
  394. ++buffer;
  395. ACPI_MOVE_16_TO_16(&temp16, buffer);
  396. bytes_consumed = temp16 + 3;
  397. /*
  398. * Resource Source Index and Resource Source are optional elements.
  399. * Check the length of the Bytestream. If it is greater than 13,
  400. * that means that an Index exists and is followed by a null
  401. * terminated string. Therefore, set the temp variable to the
  402. * length minus the minimum byte stream length plus the byte for
  403. * the Index to determine the size of the NULL terminated string.
  404. */
  405. if (13 < temp16) {
  406. temp8 = (u8) (temp16 - 14);
  407. } else {
  408. temp8 = 0;
  409. }
  410. /* Ensure a 32-bit boundary for the structure */
  411. temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8);
  412. structure_size =
  413. ACPI_SIZEOF_RESOURCE(struct acpi_resource_address16)
  414. + (temp8 * sizeof(u8));
  415. break;
  416. case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
  417. /*
  418. * Extended IRQ
  419. */
  420. buffer = byte_stream_buffer;
  421. ++buffer;
  422. ACPI_MOVE_16_TO_16(&temp16, buffer);
  423. bytes_consumed = temp16 + 3;
  424. /*
  425. * Point past the length field and the Interrupt vector flags to
  426. * save off the Interrupt table length to the Temp8 variable.
  427. */
  428. buffer += 3;
  429. temp8 = *buffer;
  430. /*
  431. * To compensate for multiple interrupt numbers, add 4 bytes for
  432. * each additional interrupts greater than 1
  433. */
  434. additional_bytes = (u8) ((temp8 - 1) * 4);
  435. /*
  436. * Resource Source Index and Resource Source are optional elements.
  437. * Check the length of the Bytestream. If it is greater than 9,
  438. * that means that an Index exists and is followed by a null
  439. * terminated string. Therefore, set the temp variable to the
  440. * length minus the minimum byte stream length plus the byte for
  441. * the Index to determine the size of the NULL terminated string.
  442. */
  443. if (9 + additional_bytes < temp16) {
  444. temp8 = (u8) (temp16 - (9 + additional_bytes));
  445. } else {
  446. temp8 = 0;
  447. }
  448. /* Ensure a 32-bit boundary for the structure */
  449. temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8);
  450. structure_size =
  451. ACPI_SIZEOF_RESOURCE(struct acpi_resource_ext_irq) +
  452. (additional_bytes * sizeof(u8)) +
  453. (temp8 * sizeof(u8));
  454. break;
  455. case ACPI_RDESC_TYPE_IRQ_FORMAT:
  456. /*
  457. * IRQ Resource.
  458. * Determine if it there are two or three trailing bytes
  459. */
  460. buffer = byte_stream_buffer;
  461. temp8 = *buffer;
  462. if (temp8 & 0x01) {
  463. bytes_consumed = 4;
  464. } else {
  465. bytes_consumed = 3;
  466. }
  467. /* Point past the descriptor */
  468. ++buffer;
  469. /* Look at the number of bits set */
  470. ACPI_MOVE_16_TO_16(&temp16, buffer);
  471. for (index = 0; index < 16; index++) {
  472. if (temp16 & 0x1) {
  473. ++number_of_interrupts;
  474. }
  475. temp16 >>= 1;
  476. }
  477. structure_size =
  478. ACPI_SIZEOF_RESOURCE(struct acpi_resource_io) +
  479. (number_of_interrupts * sizeof(u32));
  480. break;
  481. case ACPI_RDESC_TYPE_DMA_FORMAT:
  482. /*
  483. * DMA Resource
  484. */
  485. buffer = byte_stream_buffer;
  486. bytes_consumed = 3;
  487. /* Point past the descriptor */
  488. ++buffer;
  489. /* Look at the number of bits set */
  490. temp8 = *buffer;
  491. for (index = 0; index < 8; index++) {
  492. if (temp8 & 0x1) {
  493. ++number_of_channels;
  494. }
  495. temp8 >>= 1;
  496. }
  497. structure_size =
  498. ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma) +
  499. (number_of_channels * sizeof(u32));
  500. break;
  501. case ACPI_RDESC_TYPE_START_DEPENDENT:
  502. /*
  503. * Start Dependent Functions Resource
  504. * Determine if it there are two or three trailing bytes
  505. */
  506. buffer = byte_stream_buffer;
  507. temp8 = *buffer;
  508. if (temp8 & 0x01) {
  509. bytes_consumed = 2;
  510. } else {
  511. bytes_consumed = 1;
  512. }
  513. structure_size =
  514. ACPI_SIZEOF_RESOURCE(struct
  515. acpi_resource_start_dpf);
  516. break;
  517. case ACPI_RDESC_TYPE_END_DEPENDENT:
  518. /*
  519. * End Dependent Functions Resource
  520. */
  521. bytes_consumed = 1;
  522. structure_size = ACPI_RESOURCE_LENGTH;
  523. break;
  524. case ACPI_RDESC_TYPE_IO_PORT:
  525. /*
  526. * IO Port Resource
  527. */
  528. bytes_consumed = 8;
  529. structure_size =
  530. ACPI_SIZEOF_RESOURCE(struct acpi_resource_io);
  531. break;
  532. case ACPI_RDESC_TYPE_FIXED_IO_PORT:
  533. /*
  534. * Fixed IO Port Resource
  535. */
  536. bytes_consumed = 4;
  537. structure_size =
  538. ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io);
  539. break;
  540. case ACPI_RDESC_TYPE_SMALL_VENDOR:
  541. /*
  542. * Vendor Specific Resource
  543. */
  544. buffer = byte_stream_buffer;
  545. temp8 = *buffer;
  546. temp8 = (u8) (temp8 & 0x7);
  547. bytes_consumed = temp8 + 1;
  548. /* Ensure a 32-bit boundary for the structure */
  549. temp8 = (u8) ACPI_ROUND_UP_to_32_bITS(temp8);
  550. structure_size =
  551. ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) +
  552. (temp8 * sizeof(u8));
  553. break;
  554. case ACPI_RDESC_TYPE_END_TAG:
  555. /*
  556. * End Tag
  557. */
  558. bytes_consumed = 2;
  559. structure_size = ACPI_RESOURCE_LENGTH;
  560. byte_stream_buffer_length = bytes_parsed;
  561. break;
  562. default:
  563. /*
  564. * If we get here, everything is out of sync,
  565. * exit with an error
  566. */
  567. return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
  568. }
  569. /* Update the return value and counter */
  570. buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE(structure_size);
  571. bytes_parsed += bytes_consumed;
  572. /* Set the byte stream to point to the next resource */
  573. byte_stream_buffer += bytes_consumed;
  574. }
  575. /* This is the data the caller needs */
  576. *size_needed = buffer_size;
  577. return_ACPI_STATUS(AE_OK);
  578. }
  579. /*******************************************************************************
  580. *
  581. * FUNCTION: acpi_rs_get_pci_routing_table_length
  582. *
  583. * PARAMETERS: package_object - Pointer to the package object
  584. * buffer_size_needed - u32 pointer of the size buffer
  585. * needed to properly return the
  586. * parsed data
  587. *
  588. * RETURN: Status
  589. *
  590. * DESCRIPTION: Given a package representing a PCI routing table, this
  591. * calculates the size of the corresponding linked list of
  592. * descriptions.
  593. *
  594. ******************************************************************************/
  595. acpi_status
  596. acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
  597. acpi_size * buffer_size_needed)
  598. {
  599. u32 number_of_elements;
  600. acpi_size temp_size_needed = 0;
  601. union acpi_operand_object **top_object_list;
  602. u32 index;
  603. union acpi_operand_object *package_element;
  604. union acpi_operand_object **sub_object_list;
  605. u8 name_found;
  606. u32 table_index;
  607. ACPI_FUNCTION_TRACE("rs_get_pci_routing_table_length");
  608. number_of_elements = package_object->package.count;
  609. /*
  610. * Calculate the size of the return buffer.
  611. * The base size is the number of elements * the sizes of the
  612. * structures. Additional space for the strings is added below.
  613. * The minus one is to subtract the size of the u8 Source[1]
  614. * member because it is added below.
  615. *
  616. * But each PRT_ENTRY structure has a pointer to a string and
  617. * the size of that string must be found.
  618. */
  619. top_object_list = package_object->package.elements;
  620. for (index = 0; index < number_of_elements; index++) {
  621. /* Dereference the sub-package */
  622. package_element = *top_object_list;
  623. /*
  624. * The sub_object_list will now point to an array of the
  625. * four IRQ elements: Address, Pin, Source and source_index
  626. */
  627. sub_object_list = package_element->package.elements;
  628. /* Scan the irq_table_elements for the Source Name String */
  629. name_found = FALSE;
  630. for (table_index = 0; table_index < 4 && !name_found;
  631. table_index++) {
  632. if ((ACPI_TYPE_STRING ==
  633. ACPI_GET_OBJECT_TYPE(*sub_object_list))
  634. ||
  635. ((ACPI_TYPE_LOCAL_REFERENCE ==
  636. ACPI_GET_OBJECT_TYPE(*sub_object_list))
  637. && ((*sub_object_list)->reference.opcode ==
  638. AML_INT_NAMEPATH_OP))) {
  639. name_found = TRUE;
  640. } else {
  641. /* Look at the next element */
  642. sub_object_list++;
  643. }
  644. }
  645. temp_size_needed += (sizeof(struct acpi_pci_routing_table) - 4);
  646. /* Was a String type found? */
  647. if (name_found) {
  648. if (ACPI_GET_OBJECT_TYPE(*sub_object_list) ==
  649. ACPI_TYPE_STRING) {
  650. /*
  651. * The length String.Length field does not include the
  652. * terminating NULL, add 1
  653. */
  654. temp_size_needed += ((acpi_size)
  655. (*sub_object_list)->string.
  656. length + 1);
  657. } else {
  658. temp_size_needed += acpi_ns_get_pathname_length((*sub_object_list)->reference.node);
  659. }
  660. } else {
  661. /*
  662. * If no name was found, then this is a NULL, which is
  663. * translated as a u32 zero.
  664. */
  665. temp_size_needed += sizeof(u32);
  666. }
  667. /* Round up the size since each element must be aligned */
  668. temp_size_needed = ACPI_ROUND_UP_to_64_bITS(temp_size_needed);
  669. /* Point to the next union acpi_operand_object */
  670. top_object_list++;
  671. }
  672. /*
  673. * Adding an extra element to the end of the list, essentially a
  674. * NULL terminator
  675. */
  676. *buffer_size_needed =
  677. temp_size_needed + sizeof(struct acpi_pci_routing_table);
  678. return_ACPI_STATUS(AE_OK);
  679. }