rscalc.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Module Name: rscalc - Calculate stream and list lengths
  5. *
  6. ******************************************************************************/
  7. #include <acpi/acpi.h>
  8. #include "accommon.h"
  9. #include "acresrc.h"
  10. #include "acnamesp.h"
  11. #define _COMPONENT ACPI_RESOURCES
  12. ACPI_MODULE_NAME("rscalc")
  13. /* Local prototypes */
  14. static u8 acpi_rs_count_set_bits(u16 bit_field);
  15. static acpi_rs_length
  16. acpi_rs_struct_option_length(struct acpi_resource_source *resource_source);
  17. static u32
  18. acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length);
  19. /*******************************************************************************
  20. *
  21. * FUNCTION: acpi_rs_count_set_bits
  22. *
  23. * PARAMETERS: bit_field - Field in which to count bits
  24. *
  25. * RETURN: Number of bits set within the field
  26. *
  27. * DESCRIPTION: Count the number of bits set in a resource field. Used for
  28. * (Short descriptor) interrupt and DMA lists.
  29. *
  30. ******************************************************************************/
  31. static u8 acpi_rs_count_set_bits(u16 bit_field)
  32. {
  33. u8 bits_set;
  34. ACPI_FUNCTION_ENTRY();
  35. for (bits_set = 0; bit_field; bits_set++) {
  36. /* Zero the least significant bit that is set */
  37. bit_field &= (u16) (bit_field - 1);
  38. }
  39. return (bits_set);
  40. }
  41. /*******************************************************************************
  42. *
  43. * FUNCTION: acpi_rs_struct_option_length
  44. *
  45. * PARAMETERS: resource_source - Pointer to optional descriptor field
  46. *
  47. * RETURN: Status
  48. *
  49. * DESCRIPTION: Common code to handle optional resource_source_index and
  50. * resource_source fields in some Large descriptors. Used during
  51. * list-to-stream conversion
  52. *
  53. ******************************************************************************/
  54. static acpi_rs_length
  55. acpi_rs_struct_option_length(struct acpi_resource_source *resource_source)
  56. {
  57. ACPI_FUNCTION_ENTRY();
  58. /*
  59. * If the resource_source string is valid, return the size of the string
  60. * (string_length includes the NULL terminator) plus the size of the
  61. * resource_source_index (1).
  62. */
  63. if (resource_source->string_ptr) {
  64. return ((acpi_rs_length)(resource_source->string_length + 1));
  65. }
  66. return (0);
  67. }
  68. /*******************************************************************************
  69. *
  70. * FUNCTION: acpi_rs_stream_option_length
  71. *
  72. * PARAMETERS: resource_length - Length from the resource header
  73. * minimum_total_length - Minimum length of this resource, before
  74. * any optional fields. Includes header size
  75. *
  76. * RETURN: Length of optional string (0 if no string present)
  77. *
  78. * DESCRIPTION: Common code to handle optional resource_source_index and
  79. * resource_source fields in some Large descriptors. Used during
  80. * stream-to-list conversion
  81. *
  82. ******************************************************************************/
  83. static u32
  84. acpi_rs_stream_option_length(u32 resource_length,
  85. u32 minimum_aml_resource_length)
  86. {
  87. u32 string_length = 0;
  88. ACPI_FUNCTION_ENTRY();
  89. /*
  90. * The resource_source_index and resource_source are optional elements of
  91. * some Large-type resource descriptors.
  92. */
  93. /*
  94. * If the length of the actual resource descriptor is greater than the
  95. * ACPI spec-defined minimum length, it means that a resource_source_index
  96. * exists and is followed by a (required) null terminated string. The
  97. * string length (including the null terminator) is the resource length
  98. * minus the minimum length, minus one byte for the resource_source_index
  99. * itself.
  100. */
  101. if (resource_length > minimum_aml_resource_length) {
  102. /* Compute the length of the optional string */
  103. string_length =
  104. resource_length - minimum_aml_resource_length - 1;
  105. }
  106. /*
  107. * Round the length up to a multiple of the native word in order to
  108. * guarantee that the entire resource descriptor is native word aligned
  109. */
  110. return ((u32) ACPI_ROUND_UP_TO_NATIVE_WORD(string_length));
  111. }
  112. /*******************************************************************************
  113. *
  114. * FUNCTION: acpi_rs_get_aml_length
  115. *
  116. * PARAMETERS: resource - Pointer to the resource linked list
  117. * resource_list_size - Size of the resource linked list
  118. * size_needed - Where the required size is returned
  119. *
  120. * RETURN: Status
  121. *
  122. * DESCRIPTION: Takes a linked list of internal resource descriptors and
  123. * calculates the size buffer needed to hold the corresponding
  124. * external resource byte stream.
  125. *
  126. ******************************************************************************/
  127. acpi_status
  128. acpi_rs_get_aml_length(struct acpi_resource *resource,
  129. acpi_size resource_list_size, acpi_size *size_needed)
  130. {
  131. acpi_size aml_size_needed = 0;
  132. struct acpi_resource *resource_end;
  133. acpi_rs_length total_size;
  134. ACPI_FUNCTION_TRACE(rs_get_aml_length);
  135. /* Traverse entire list of internal resource descriptors */
  136. resource_end =
  137. ACPI_ADD_PTR(struct acpi_resource, resource, resource_list_size);
  138. while (resource < resource_end) {
  139. /* Validate the descriptor type */
  140. if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
  141. return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
  142. }
  143. /* Sanity check the length. It must not be zero, or we loop forever */
  144. if (!resource->length) {
  145. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
  146. }
  147. /* Get the base size of the (external stream) resource descriptor */
  148. total_size = acpi_gbl_aml_resource_sizes[resource->type];
  149. /*
  150. * Augment the base size for descriptors with optional and/or
  151. * variable-length fields
  152. */
  153. switch (resource->type) {
  154. case ACPI_RESOURCE_TYPE_IRQ:
  155. /* Length can be 3 or 2 */
  156. if (resource->data.irq.descriptor_length == 2) {
  157. total_size--;
  158. }
  159. break;
  160. case ACPI_RESOURCE_TYPE_START_DEPENDENT:
  161. /* Length can be 1 or 0 */
  162. if (resource->data.irq.descriptor_length == 0) {
  163. total_size--;
  164. }
  165. break;
  166. case ACPI_RESOURCE_TYPE_VENDOR:
  167. /*
  168. * Vendor Defined Resource:
  169. * For a Vendor Specific resource, if the Length is between 1 and 7
  170. * it will be created as a Small Resource data type, otherwise it
  171. * is a Large Resource data type.
  172. */
  173. if (resource->data.vendor.byte_length > 7) {
  174. /* Base size of a Large resource descriptor */
  175. total_size =
  176. sizeof(struct aml_resource_large_header);
  177. }
  178. /* Add the size of the vendor-specific data */
  179. total_size = (acpi_rs_length)
  180. (total_size + resource->data.vendor.byte_length);
  181. break;
  182. case ACPI_RESOURCE_TYPE_END_TAG:
  183. /*
  184. * End Tag:
  185. * We are done -- return the accumulated total size.
  186. */
  187. *size_needed = aml_size_needed + total_size;
  188. /* Normal exit */
  189. return_ACPI_STATUS(AE_OK);
  190. case ACPI_RESOURCE_TYPE_ADDRESS16:
  191. /*
  192. * 16-Bit Address Resource:
  193. * Add the size of the optional resource_source info
  194. */
  195. total_size = (acpi_rs_length)(total_size +
  196. acpi_rs_struct_option_length
  197. (&resource->data.
  198. address16.
  199. resource_source));
  200. break;
  201. case ACPI_RESOURCE_TYPE_ADDRESS32:
  202. /*
  203. * 32-Bit Address Resource:
  204. * Add the size of the optional resource_source info
  205. */
  206. total_size = (acpi_rs_length)(total_size +
  207. acpi_rs_struct_option_length
  208. (&resource->data.
  209. address32.
  210. resource_source));
  211. break;
  212. case ACPI_RESOURCE_TYPE_ADDRESS64:
  213. /*
  214. * 64-Bit Address Resource:
  215. * Add the size of the optional resource_source info
  216. */
  217. total_size = (acpi_rs_length)(total_size +
  218. acpi_rs_struct_option_length
  219. (&resource->data.
  220. address64.
  221. resource_source));
  222. break;
  223. case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
  224. /*
  225. * Extended IRQ Resource:
  226. * Add the size of each additional optional interrupt beyond the
  227. * required 1 (4 bytes for each u32 interrupt number)
  228. */
  229. total_size = (acpi_rs_length)(total_size +
  230. ((resource->data.
  231. extended_irq.
  232. interrupt_count -
  233. 1) * 4) +
  234. /* Add the size of the optional resource_source info */
  235. acpi_rs_struct_option_length
  236. (&resource->data.
  237. extended_irq.
  238. resource_source));
  239. break;
  240. case ACPI_RESOURCE_TYPE_GPIO:
  241. total_size = (acpi_rs_length)(total_size +
  242. (resource->data.gpio.
  243. pin_table_length * 2) +
  244. resource->data.gpio.
  245. resource_source.
  246. string_length +
  247. resource->data.gpio.
  248. vendor_length);
  249. break;
  250. case ACPI_RESOURCE_TYPE_PIN_FUNCTION:
  251. total_size = (acpi_rs_length)(total_size +
  252. (resource->data.
  253. pin_function.
  254. pin_table_length * 2) +
  255. resource->data.
  256. pin_function.
  257. resource_source.
  258. string_length +
  259. resource->data.
  260. pin_function.
  261. vendor_length);
  262. break;
  263. case ACPI_RESOURCE_TYPE_SERIAL_BUS:
  264. total_size =
  265. acpi_gbl_aml_resource_serial_bus_sizes[resource->
  266. data.
  267. common_serial_bus.
  268. type];
  269. total_size = (acpi_rs_length)(total_size +
  270. resource->data.
  271. i2c_serial_bus.
  272. resource_source.
  273. string_length +
  274. resource->data.
  275. i2c_serial_bus.
  276. vendor_length);
  277. break;
  278. case ACPI_RESOURCE_TYPE_PIN_CONFIG:
  279. total_size = (acpi_rs_length)(total_size +
  280. (resource->data.
  281. pin_config.
  282. pin_table_length * 2) +
  283. resource->data.pin_config.
  284. resource_source.
  285. string_length +
  286. resource->data.pin_config.
  287. vendor_length);
  288. break;
  289. case ACPI_RESOURCE_TYPE_PIN_GROUP:
  290. total_size = (acpi_rs_length)(total_size +
  291. (resource->data.pin_group.
  292. pin_table_length * 2) +
  293. resource->data.pin_group.
  294. resource_label.
  295. string_length +
  296. resource->data.pin_group.
  297. vendor_length);
  298. break;
  299. case ACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION:
  300. total_size = (acpi_rs_length)(total_size +
  301. resource->data.
  302. pin_group_function.
  303. resource_source.
  304. string_length +
  305. resource->data.
  306. pin_group_function.
  307. resource_source_label.
  308. string_length +
  309. resource->data.
  310. pin_group_function.
  311. vendor_length);
  312. break;
  313. case ACPI_RESOURCE_TYPE_PIN_GROUP_CONFIG:
  314. total_size = (acpi_rs_length)(total_size +
  315. resource->data.
  316. pin_group_config.
  317. resource_source.
  318. string_length +
  319. resource->data.
  320. pin_group_config.
  321. resource_source_label.
  322. string_length +
  323. resource->data.
  324. pin_group_config.
  325. vendor_length);
  326. break;
  327. default:
  328. break;
  329. }
  330. /* Update the total */
  331. aml_size_needed += total_size;
  332. /* Point to the next object */
  333. resource =
  334. ACPI_ADD_PTR(struct acpi_resource, resource,
  335. resource->length);
  336. }
  337. /* Did not find an end_tag resource descriptor */
  338. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  339. }
  340. /*******************************************************************************
  341. *
  342. * FUNCTION: acpi_rs_get_list_length
  343. *
  344. * PARAMETERS: aml_buffer - Pointer to the resource byte stream
  345. * aml_buffer_length - Size of aml_buffer
  346. * size_needed - Where the size needed is returned
  347. *
  348. * RETURN: Status
  349. *
  350. * DESCRIPTION: Takes an external resource byte stream and calculates the size
  351. * buffer needed to hold the corresponding internal resource
  352. * descriptor linked list.
  353. *
  354. ******************************************************************************/
  355. acpi_status
  356. acpi_rs_get_list_length(u8 *aml_buffer,
  357. u32 aml_buffer_length, acpi_size *size_needed)
  358. {
  359. acpi_status status;
  360. u8 *end_aml;
  361. u8 *buffer;
  362. u32 buffer_size;
  363. u16 temp16;
  364. u16 resource_length;
  365. u32 extra_struct_bytes;
  366. u8 resource_index;
  367. u8 minimum_aml_resource_length;
  368. union aml_resource *aml_resource;
  369. ACPI_FUNCTION_TRACE(rs_get_list_length);
  370. *size_needed = ACPI_RS_SIZE_MIN; /* Minimum size is one end_tag */
  371. end_aml = aml_buffer + aml_buffer_length;
  372. /* Walk the list of AML resource descriptors */
  373. while (aml_buffer < end_aml) {
  374. /* Validate the Resource Type and Resource Length */
  375. status =
  376. acpi_ut_validate_resource(NULL, aml_buffer,
  377. &resource_index);
  378. if (ACPI_FAILURE(status)) {
  379. /*
  380. * Exit on failure. Cannot continue because the descriptor length
  381. * may be bogus also.
  382. */
  383. return_ACPI_STATUS(status);
  384. }
  385. aml_resource = (void *)aml_buffer;
  386. /* Get the resource length and base (minimum) AML size */
  387. resource_length = acpi_ut_get_resource_length(aml_buffer);
  388. minimum_aml_resource_length =
  389. acpi_gbl_resource_aml_sizes[resource_index];
  390. /*
  391. * Augment the size for descriptors with optional
  392. * and/or variable length fields
  393. */
  394. extra_struct_bytes = 0;
  395. buffer =
  396. aml_buffer + acpi_ut_get_resource_header_length(aml_buffer);
  397. switch (acpi_ut_get_resource_type(aml_buffer)) {
  398. case ACPI_RESOURCE_NAME_IRQ:
  399. /*
  400. * IRQ Resource:
  401. * Get the number of bits set in the 16-bit IRQ mask
  402. */
  403. ACPI_MOVE_16_TO_16(&temp16, buffer);
  404. extra_struct_bytes = acpi_rs_count_set_bits(temp16);
  405. break;
  406. case ACPI_RESOURCE_NAME_DMA:
  407. /*
  408. * DMA Resource:
  409. * Get the number of bits set in the 8-bit DMA mask
  410. */
  411. extra_struct_bytes = acpi_rs_count_set_bits(*buffer);
  412. break;
  413. case ACPI_RESOURCE_NAME_VENDOR_SMALL:
  414. case ACPI_RESOURCE_NAME_VENDOR_LARGE:
  415. /*
  416. * Vendor Resource:
  417. * Get the number of vendor data bytes
  418. */
  419. extra_struct_bytes = resource_length;
  420. /*
  421. * There is already one byte included in the minimum
  422. * descriptor size. If there are extra struct bytes,
  423. * subtract one from the count.
  424. */
  425. if (extra_struct_bytes) {
  426. extra_struct_bytes--;
  427. }
  428. break;
  429. case ACPI_RESOURCE_NAME_END_TAG:
  430. /*
  431. * End Tag: This is the normal exit
  432. */
  433. return_ACPI_STATUS(AE_OK);
  434. case ACPI_RESOURCE_NAME_ADDRESS32:
  435. case ACPI_RESOURCE_NAME_ADDRESS16:
  436. case ACPI_RESOURCE_NAME_ADDRESS64:
  437. /*
  438. * Address Resource:
  439. * Add the size of the optional resource_source
  440. */
  441. extra_struct_bytes =
  442. acpi_rs_stream_option_length(resource_length,
  443. minimum_aml_resource_length);
  444. break;
  445. case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
  446. /*
  447. * Extended IRQ Resource:
  448. * Using the interrupt_table_length, add 4 bytes for each additional
  449. * interrupt. Note: at least one interrupt is required and is
  450. * included in the minimum descriptor size (reason for the -1)
  451. */
  452. extra_struct_bytes = (buffer[1] - 1) * sizeof(u32);
  453. /* Add the size of the optional resource_source */
  454. extra_struct_bytes +=
  455. acpi_rs_stream_option_length(resource_length -
  456. extra_struct_bytes,
  457. minimum_aml_resource_length);
  458. break;
  459. case ACPI_RESOURCE_NAME_GPIO:
  460. /* Vendor data is optional */
  461. if (aml_resource->gpio.vendor_length) {
  462. extra_struct_bytes +=
  463. aml_resource->gpio.vendor_offset -
  464. aml_resource->gpio.pin_table_offset +
  465. aml_resource->gpio.vendor_length;
  466. } else {
  467. extra_struct_bytes +=
  468. aml_resource->large_header.resource_length +
  469. sizeof(struct aml_resource_large_header) -
  470. aml_resource->gpio.pin_table_offset;
  471. }
  472. break;
  473. case ACPI_RESOURCE_NAME_PIN_FUNCTION:
  474. /* Vendor data is optional */
  475. if (aml_resource->pin_function.vendor_length) {
  476. extra_struct_bytes +=
  477. aml_resource->pin_function.vendor_offset -
  478. aml_resource->pin_function.
  479. pin_table_offset +
  480. aml_resource->pin_function.vendor_length;
  481. } else {
  482. extra_struct_bytes +=
  483. aml_resource->large_header.resource_length +
  484. sizeof(struct aml_resource_large_header) -
  485. aml_resource->pin_function.pin_table_offset;
  486. }
  487. break;
  488. case ACPI_RESOURCE_NAME_SERIAL_BUS:
  489. minimum_aml_resource_length =
  490. acpi_gbl_resource_aml_serial_bus_sizes
  491. [aml_resource->common_serial_bus.type];
  492. extra_struct_bytes +=
  493. aml_resource->common_serial_bus.resource_length -
  494. minimum_aml_resource_length;
  495. break;
  496. case ACPI_RESOURCE_NAME_PIN_CONFIG:
  497. /* Vendor data is optional */
  498. if (aml_resource->pin_config.vendor_length) {
  499. extra_struct_bytes +=
  500. aml_resource->pin_config.vendor_offset -
  501. aml_resource->pin_config.pin_table_offset +
  502. aml_resource->pin_config.vendor_length;
  503. } else {
  504. extra_struct_bytes +=
  505. aml_resource->large_header.resource_length +
  506. sizeof(struct aml_resource_large_header) -
  507. aml_resource->pin_config.pin_table_offset;
  508. }
  509. break;
  510. case ACPI_RESOURCE_NAME_PIN_GROUP:
  511. extra_struct_bytes +=
  512. aml_resource->pin_group.vendor_offset -
  513. aml_resource->pin_group.pin_table_offset +
  514. aml_resource->pin_group.vendor_length;
  515. break;
  516. case ACPI_RESOURCE_NAME_PIN_GROUP_FUNCTION:
  517. extra_struct_bytes +=
  518. aml_resource->pin_group_function.vendor_offset -
  519. aml_resource->pin_group_function.res_source_offset +
  520. aml_resource->pin_group_function.vendor_length;
  521. break;
  522. case ACPI_RESOURCE_NAME_PIN_GROUP_CONFIG:
  523. extra_struct_bytes +=
  524. aml_resource->pin_group_config.vendor_offset -
  525. aml_resource->pin_group_config.res_source_offset +
  526. aml_resource->pin_group_config.vendor_length;
  527. break;
  528. default:
  529. break;
  530. }
  531. /*
  532. * Update the required buffer size for the internal descriptor structs
  533. *
  534. * Important: Round the size up for the appropriate alignment. This
  535. * is a requirement on IA64.
  536. */
  537. if (acpi_ut_get_resource_type(aml_buffer) ==
  538. ACPI_RESOURCE_NAME_SERIAL_BUS) {
  539. buffer_size =
  540. acpi_gbl_resource_struct_serial_bus_sizes
  541. [aml_resource->common_serial_bus.type] +
  542. extra_struct_bytes;
  543. } else {
  544. buffer_size =
  545. acpi_gbl_resource_struct_sizes[resource_index] +
  546. extra_struct_bytes;
  547. }
  548. buffer_size = (u32)ACPI_ROUND_UP_TO_NATIVE_WORD(buffer_size);
  549. *size_needed += buffer_size;
  550. ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
  551. "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
  552. acpi_ut_get_resource_type(aml_buffer),
  553. acpi_ut_get_descriptor_length(aml_buffer),
  554. buffer_size));
  555. /*
  556. * Point to the next resource within the AML stream using the length
  557. * contained in the resource descriptor header
  558. */
  559. aml_buffer += acpi_ut_get_descriptor_length(aml_buffer);
  560. }
  561. /* Did not find an end_tag resource descriptor */
  562. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  563. }
  564. /*******************************************************************************
  565. *
  566. * FUNCTION: acpi_rs_get_pci_routing_table_length
  567. *
  568. * PARAMETERS: package_object - Pointer to the package object
  569. * buffer_size_needed - u32 pointer of the size buffer
  570. * needed to properly return the
  571. * parsed data
  572. *
  573. * RETURN: Status
  574. *
  575. * DESCRIPTION: Given a package representing a PCI routing table, this
  576. * calculates the size of the corresponding linked list of
  577. * descriptions.
  578. *
  579. ******************************************************************************/
  580. acpi_status
  581. acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
  582. acpi_size *buffer_size_needed)
  583. {
  584. u32 number_of_elements;
  585. acpi_size temp_size_needed = 0;
  586. union acpi_operand_object **top_object_list;
  587. u32 index;
  588. union acpi_operand_object *package_element;
  589. union acpi_operand_object **sub_object_list;
  590. u8 name_found;
  591. u32 table_index;
  592. ACPI_FUNCTION_TRACE(rs_get_pci_routing_table_length);
  593. number_of_elements = package_object->package.count;
  594. /*
  595. * Calculate the size of the return buffer.
  596. * The base size is the number of elements * the sizes of the
  597. * structures. Additional space for the strings is added below.
  598. * The minus one is to subtract the size of the u8 Source[1]
  599. * member because it is added below.
  600. *
  601. * But each PRT_ENTRY structure has a pointer to a string and
  602. * the size of that string must be found.
  603. */
  604. top_object_list = package_object->package.elements;
  605. for (index = 0; index < number_of_elements; index++) {
  606. /* Dereference the subpackage */
  607. package_element = *top_object_list;
  608. /* We must have a valid Package object */
  609. if (!package_element ||
  610. (package_element->common.type != ACPI_TYPE_PACKAGE)) {
  611. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  612. }
  613. /*
  614. * The sub_object_list will now point to an array of the
  615. * four IRQ elements: Address, Pin, Source and source_index
  616. */
  617. sub_object_list = package_element->package.elements;
  618. /* Scan the irq_table_elements for the Source Name String */
  619. name_found = FALSE;
  620. for (table_index = 0;
  621. table_index < package_element->package.count
  622. && !name_found; table_index++) {
  623. if (*sub_object_list && /* Null object allowed */
  624. ((ACPI_TYPE_STRING ==
  625. (*sub_object_list)->common.type) ||
  626. ((ACPI_TYPE_LOCAL_REFERENCE ==
  627. (*sub_object_list)->common.type) &&
  628. ((*sub_object_list)->reference.class ==
  629. ACPI_REFCLASS_NAME)))) {
  630. name_found = TRUE;
  631. } else {
  632. /* Look at the next element */
  633. sub_object_list++;
  634. }
  635. }
  636. temp_size_needed += (sizeof(struct acpi_pci_routing_table) - 4);
  637. /* Was a String type found? */
  638. if (name_found) {
  639. if ((*sub_object_list)->common.type == ACPI_TYPE_STRING) {
  640. /*
  641. * The length String.Length field does not include the
  642. * terminating NULL, add 1
  643. */
  644. temp_size_needed += ((acpi_size)
  645. (*sub_object_list)->string.
  646. length + 1);
  647. } else {
  648. temp_size_needed += acpi_ns_get_pathname_length((*sub_object_list)->reference.node);
  649. }
  650. } else {
  651. /*
  652. * If no name was found, then this is a NULL, which is
  653. * translated as a u32 zero.
  654. */
  655. temp_size_needed += sizeof(u32);
  656. }
  657. /* Round up the size since each element must be aligned */
  658. temp_size_needed = ACPI_ROUND_UP_TO_64BIT(temp_size_needed);
  659. /* Point to the next union acpi_operand_object */
  660. top_object_list++;
  661. }
  662. /*
  663. * Add an extra element to the end of the list, essentially a
  664. * NULL terminator
  665. */
  666. *buffer_size_needed =
  667. temp_size_needed + sizeof(struct acpi_pci_routing_table);
  668. return_ACPI_STATUS(AE_OK);
  669. }