utresrc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. /*******************************************************************************
  2. *
  3. * Module Name: utresrc - Resource management utilities
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2017, Intel Corp.
  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 "accommon.h"
  44. #include "acresrc.h"
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME("utresrc")
  47. #if defined(ACPI_DEBUG_OUTPUT) || defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER)
  48. /*
  49. * Strings used to decode resource descriptors.
  50. * Used by both the disassembler and the debugger resource dump routines
  51. */
  52. const char *acpi_gbl_bm_decode[] = {
  53. "NotBusMaster",
  54. "BusMaster"
  55. };
  56. const char *acpi_gbl_config_decode[] = {
  57. "0 - Good Configuration",
  58. "1 - Acceptable Configuration",
  59. "2 - Suboptimal Configuration",
  60. "3 - ***Invalid Configuration***",
  61. };
  62. const char *acpi_gbl_consume_decode[] = {
  63. "ResourceProducer",
  64. "ResourceConsumer"
  65. };
  66. const char *acpi_gbl_dec_decode[] = {
  67. "PosDecode",
  68. "SubDecode"
  69. };
  70. const char *acpi_gbl_he_decode[] = {
  71. "Level",
  72. "Edge"
  73. };
  74. const char *acpi_gbl_io_decode[] = {
  75. "Decode10",
  76. "Decode16"
  77. };
  78. const char *acpi_gbl_ll_decode[] = {
  79. "ActiveHigh",
  80. "ActiveLow",
  81. "ActiveBoth",
  82. "Reserved"
  83. };
  84. const char *acpi_gbl_max_decode[] = {
  85. "MaxNotFixed",
  86. "MaxFixed"
  87. };
  88. const char *acpi_gbl_mem_decode[] = {
  89. "NonCacheable",
  90. "Cacheable",
  91. "WriteCombining",
  92. "Prefetchable"
  93. };
  94. const char *acpi_gbl_min_decode[] = {
  95. "MinNotFixed",
  96. "MinFixed"
  97. };
  98. const char *acpi_gbl_mtp_decode[] = {
  99. "AddressRangeMemory",
  100. "AddressRangeReserved",
  101. "AddressRangeACPI",
  102. "AddressRangeNVS"
  103. };
  104. const char *acpi_gbl_rng_decode[] = {
  105. "InvalidRanges",
  106. "NonISAOnlyRanges",
  107. "ISAOnlyRanges",
  108. "EntireRange"
  109. };
  110. const char *acpi_gbl_rw_decode[] = {
  111. "ReadOnly",
  112. "ReadWrite"
  113. };
  114. const char *acpi_gbl_shr_decode[] = {
  115. "Exclusive",
  116. "Shared",
  117. "ExclusiveAndWake", /* ACPI 5.0 */
  118. "SharedAndWake" /* ACPI 5.0 */
  119. };
  120. const char *acpi_gbl_siz_decode[] = {
  121. "Transfer8",
  122. "Transfer8_16",
  123. "Transfer16",
  124. "InvalidSize"
  125. };
  126. const char *acpi_gbl_trs_decode[] = {
  127. "DenseTranslation",
  128. "SparseTranslation"
  129. };
  130. const char *acpi_gbl_ttp_decode[] = {
  131. "TypeStatic",
  132. "TypeTranslation"
  133. };
  134. const char *acpi_gbl_typ_decode[] = {
  135. "Compatibility",
  136. "TypeA",
  137. "TypeB",
  138. "TypeF"
  139. };
  140. const char *acpi_gbl_ppc_decode[] = {
  141. "PullDefault",
  142. "PullUp",
  143. "PullDown",
  144. "PullNone"
  145. };
  146. const char *acpi_gbl_ior_decode[] = {
  147. "IoRestrictionNone",
  148. "IoRestrictionInputOnly",
  149. "IoRestrictionOutputOnly",
  150. "IoRestrictionNoneAndPreserve"
  151. };
  152. const char *acpi_gbl_dts_decode[] = {
  153. "Width8bit",
  154. "Width16bit",
  155. "Width32bit",
  156. "Width64bit",
  157. "Width128bit",
  158. "Width256bit",
  159. };
  160. /* GPIO connection type */
  161. const char *acpi_gbl_ct_decode[] = {
  162. "Interrupt",
  163. "I/O"
  164. };
  165. /* Serial bus type */
  166. const char *acpi_gbl_sbt_decode[] = {
  167. "/* UNKNOWN serial bus type */",
  168. "I2C",
  169. "SPI",
  170. "UART"
  171. };
  172. /* I2C serial bus access mode */
  173. const char *acpi_gbl_am_decode[] = {
  174. "AddressingMode7Bit",
  175. "AddressingMode10Bit"
  176. };
  177. /* I2C serial bus slave mode */
  178. const char *acpi_gbl_sm_decode[] = {
  179. "ControllerInitiated",
  180. "DeviceInitiated"
  181. };
  182. /* SPI serial bus wire mode */
  183. const char *acpi_gbl_wm_decode[] = {
  184. "FourWireMode",
  185. "ThreeWireMode"
  186. };
  187. /* SPI serial clock phase */
  188. const char *acpi_gbl_cph_decode[] = {
  189. "ClockPhaseFirst",
  190. "ClockPhaseSecond"
  191. };
  192. /* SPI serial bus clock polarity */
  193. const char *acpi_gbl_cpo_decode[] = {
  194. "ClockPolarityLow",
  195. "ClockPolarityHigh"
  196. };
  197. /* SPI serial bus device polarity */
  198. const char *acpi_gbl_dp_decode[] = {
  199. "PolarityLow",
  200. "PolarityHigh"
  201. };
  202. /* UART serial bus endian */
  203. const char *acpi_gbl_ed_decode[] = {
  204. "LittleEndian",
  205. "BigEndian"
  206. };
  207. /* UART serial bus bits per byte */
  208. const char *acpi_gbl_bpb_decode[] = {
  209. "DataBitsFive",
  210. "DataBitsSix",
  211. "DataBitsSeven",
  212. "DataBitsEight",
  213. "DataBitsNine",
  214. "/* UNKNOWN Bits per byte */",
  215. "/* UNKNOWN Bits per byte */",
  216. "/* UNKNOWN Bits per byte */"
  217. };
  218. /* UART serial bus stop bits */
  219. const char *acpi_gbl_sb_decode[] = {
  220. "StopBitsZero",
  221. "StopBitsOne",
  222. "StopBitsOnePlusHalf",
  223. "StopBitsTwo"
  224. };
  225. /* UART serial bus flow control */
  226. const char *acpi_gbl_fc_decode[] = {
  227. "FlowControlNone",
  228. "FlowControlHardware",
  229. "FlowControlXON",
  230. "/* UNKNOWN flow control keyword */"
  231. };
  232. /* UART serial bus parity type */
  233. const char *acpi_gbl_pt_decode[] = {
  234. "ParityTypeNone",
  235. "ParityTypeEven",
  236. "ParityTypeOdd",
  237. "ParityTypeMark",
  238. "ParityTypeSpace",
  239. "/* UNKNOWN parity keyword */",
  240. "/* UNKNOWN parity keyword */",
  241. "/* UNKNOWN parity keyword */"
  242. };
  243. #endif
  244. /*
  245. * Base sizes of the raw AML resource descriptors, indexed by resource type.
  246. * Zero indicates a reserved (and therefore invalid) resource type.
  247. */
  248. const u8 acpi_gbl_resource_aml_sizes[] = {
  249. /* Small descriptors */
  250. 0,
  251. 0,
  252. 0,
  253. 0,
  254. ACPI_AML_SIZE_SMALL(struct aml_resource_irq),
  255. ACPI_AML_SIZE_SMALL(struct aml_resource_dma),
  256. ACPI_AML_SIZE_SMALL(struct aml_resource_start_dependent),
  257. ACPI_AML_SIZE_SMALL(struct aml_resource_end_dependent),
  258. ACPI_AML_SIZE_SMALL(struct aml_resource_io),
  259. ACPI_AML_SIZE_SMALL(struct aml_resource_fixed_io),
  260. ACPI_AML_SIZE_SMALL(struct aml_resource_fixed_dma),
  261. 0,
  262. 0,
  263. 0,
  264. ACPI_AML_SIZE_SMALL(struct aml_resource_vendor_small),
  265. ACPI_AML_SIZE_SMALL(struct aml_resource_end_tag),
  266. /* Large descriptors */
  267. 0,
  268. ACPI_AML_SIZE_LARGE(struct aml_resource_memory24),
  269. ACPI_AML_SIZE_LARGE(struct aml_resource_generic_register),
  270. 0,
  271. ACPI_AML_SIZE_LARGE(struct aml_resource_vendor_large),
  272. ACPI_AML_SIZE_LARGE(struct aml_resource_memory32),
  273. ACPI_AML_SIZE_LARGE(struct aml_resource_fixed_memory32),
  274. ACPI_AML_SIZE_LARGE(struct aml_resource_address32),
  275. ACPI_AML_SIZE_LARGE(struct aml_resource_address16),
  276. ACPI_AML_SIZE_LARGE(struct aml_resource_extended_irq),
  277. ACPI_AML_SIZE_LARGE(struct aml_resource_address64),
  278. ACPI_AML_SIZE_LARGE(struct aml_resource_extended_address64),
  279. ACPI_AML_SIZE_LARGE(struct aml_resource_gpio),
  280. 0,
  281. ACPI_AML_SIZE_LARGE(struct aml_resource_common_serialbus),
  282. };
  283. const u8 acpi_gbl_resource_aml_serial_bus_sizes[] = {
  284. 0,
  285. ACPI_AML_SIZE_LARGE(struct aml_resource_i2c_serialbus),
  286. ACPI_AML_SIZE_LARGE(struct aml_resource_spi_serialbus),
  287. ACPI_AML_SIZE_LARGE(struct aml_resource_uart_serialbus),
  288. };
  289. /*
  290. * Resource types, used to validate the resource length field.
  291. * The length of fixed-length types must match exactly, variable
  292. * lengths must meet the minimum required length, etc.
  293. * Zero indicates a reserved (and therefore invalid) resource type.
  294. */
  295. static const u8 acpi_gbl_resource_types[] = {
  296. /* Small descriptors */
  297. 0,
  298. 0,
  299. 0,
  300. 0,
  301. ACPI_SMALL_VARIABLE_LENGTH, /* 04 IRQ */
  302. ACPI_FIXED_LENGTH, /* 05 DMA */
  303. ACPI_SMALL_VARIABLE_LENGTH, /* 06 start_dependent_functions */
  304. ACPI_FIXED_LENGTH, /* 07 end_dependent_functions */
  305. ACPI_FIXED_LENGTH, /* 08 IO */
  306. ACPI_FIXED_LENGTH, /* 09 fixed_IO */
  307. ACPI_FIXED_LENGTH, /* 0A fixed_DMA */
  308. 0,
  309. 0,
  310. 0,
  311. ACPI_VARIABLE_LENGTH, /* 0E vendor_short */
  312. ACPI_FIXED_LENGTH, /* 0F end_tag */
  313. /* Large descriptors */
  314. 0,
  315. ACPI_FIXED_LENGTH, /* 01 Memory24 */
  316. ACPI_FIXED_LENGTH, /* 02 generic_register */
  317. 0,
  318. ACPI_VARIABLE_LENGTH, /* 04 vendor_long */
  319. ACPI_FIXED_LENGTH, /* 05 Memory32 */
  320. ACPI_FIXED_LENGTH, /* 06 memory32_fixed */
  321. ACPI_VARIABLE_LENGTH, /* 07 Dword* address */
  322. ACPI_VARIABLE_LENGTH, /* 08 Word* address */
  323. ACPI_VARIABLE_LENGTH, /* 09 extended_IRQ */
  324. ACPI_VARIABLE_LENGTH, /* 0A Qword* address */
  325. ACPI_FIXED_LENGTH, /* 0B Extended* address */
  326. ACPI_VARIABLE_LENGTH, /* 0C Gpio* */
  327. 0,
  328. ACPI_VARIABLE_LENGTH /* 0E *serial_bus */
  329. };
  330. /*******************************************************************************
  331. *
  332. * FUNCTION: acpi_ut_walk_aml_resources
  333. *
  334. * PARAMETERS: walk_state - Current walk info
  335. * PARAMETERS: aml - Pointer to the raw AML resource template
  336. * aml_length - Length of the entire template
  337. * user_function - Called once for each descriptor found. If
  338. * NULL, a pointer to the end_tag is returned
  339. * context - Passed to user_function
  340. *
  341. * RETURN: Status
  342. *
  343. * DESCRIPTION: Walk a raw AML resource list(buffer). User function called
  344. * once for each resource found.
  345. *
  346. ******************************************************************************/
  347. acpi_status
  348. acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state,
  349. u8 *aml,
  350. acpi_size aml_length,
  351. acpi_walk_aml_callback user_function, void **context)
  352. {
  353. acpi_status status;
  354. u8 *end_aml;
  355. u8 resource_index;
  356. u32 length;
  357. u32 offset = 0;
  358. u8 end_tag[2] = { 0x79, 0x00 };
  359. ACPI_FUNCTION_TRACE(ut_walk_aml_resources);
  360. /*
  361. * The absolute minimum resource template is one end_tag descriptor.
  362. * However, we will treat a lone end_tag as just a simple buffer.
  363. */
  364. if (aml_length < sizeof(struct aml_resource_end_tag)) {
  365. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  366. }
  367. /* Point to the end of the resource template buffer */
  368. end_aml = aml + aml_length;
  369. /* Walk the byte list, abort on any invalid descriptor type or length */
  370. while (aml < end_aml) {
  371. /* Validate the Resource Type and Resource Length */
  372. status =
  373. acpi_ut_validate_resource(walk_state, aml, &resource_index);
  374. if (ACPI_FAILURE(status)) {
  375. /*
  376. * Exit on failure. Cannot continue because the descriptor
  377. * length may be bogus also.
  378. */
  379. return_ACPI_STATUS(status);
  380. }
  381. /* Get the length of this descriptor */
  382. length = acpi_ut_get_descriptor_length(aml);
  383. /* Invoke the user function */
  384. if (user_function) {
  385. status = user_function(aml, length, offset,
  386. resource_index, context);
  387. if (ACPI_FAILURE(status)) {
  388. return_ACPI_STATUS(status);
  389. }
  390. }
  391. /* An end_tag descriptor terminates this resource template */
  392. if (acpi_ut_get_resource_type(aml) ==
  393. ACPI_RESOURCE_NAME_END_TAG) {
  394. /*
  395. * There must be at least one more byte in the buffer for
  396. * the 2nd byte of the end_tag
  397. */
  398. if ((aml + 1) >= end_aml) {
  399. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  400. }
  401. /* Return the pointer to the end_tag if requested */
  402. if (!user_function) {
  403. *context = aml;
  404. }
  405. /* Check if buffer is defined to be longer than the resource length */
  406. if (aml_length > (offset + length)) {
  407. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  408. }
  409. /* Normal exit */
  410. return_ACPI_STATUS(AE_OK);
  411. }
  412. aml += length;
  413. offset += length;
  414. }
  415. /* Did not find an end_tag descriptor */
  416. if (user_function) {
  417. /* Insert an end_tag anyway. acpi_rs_get_list_length always leaves room */
  418. (void)acpi_ut_validate_resource(walk_state, end_tag,
  419. &resource_index);
  420. status =
  421. user_function(end_tag, 2, offset, resource_index, context);
  422. if (ACPI_FAILURE(status)) {
  423. return_ACPI_STATUS(status);
  424. }
  425. }
  426. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  427. }
  428. /*******************************************************************************
  429. *
  430. * FUNCTION: acpi_ut_validate_resource
  431. *
  432. * PARAMETERS: walk_state - Current walk info
  433. * aml - Pointer to the raw AML resource descriptor
  434. * return_index - Where the resource index is returned. NULL
  435. * if the index is not required.
  436. *
  437. * RETURN: Status, and optionally the Index into the global resource tables
  438. *
  439. * DESCRIPTION: Validate an AML resource descriptor by checking the Resource
  440. * Type and Resource Length. Returns an index into the global
  441. * resource information/dispatch tables for later use.
  442. *
  443. ******************************************************************************/
  444. acpi_status
  445. acpi_ut_validate_resource(struct acpi_walk_state *walk_state,
  446. void *aml, u8 *return_index)
  447. {
  448. union aml_resource *aml_resource;
  449. u8 resource_type;
  450. u8 resource_index;
  451. acpi_rs_length resource_length;
  452. acpi_rs_length minimum_resource_length;
  453. ACPI_FUNCTION_ENTRY();
  454. /*
  455. * 1) Validate the resource_type field (Byte 0)
  456. */
  457. resource_type = ACPI_GET8(aml);
  458. /*
  459. * Byte 0 contains the descriptor name (Resource Type)
  460. * Examine the large/small bit in the resource header
  461. */
  462. if (resource_type & ACPI_RESOURCE_NAME_LARGE) {
  463. /* Verify the large resource type (name) against the max */
  464. if (resource_type > ACPI_RESOURCE_NAME_LARGE_MAX) {
  465. goto invalid_resource;
  466. }
  467. /*
  468. * Large Resource Type -- bits 6:0 contain the name
  469. * Translate range 0x80-0x8B to index range 0x10-0x1B
  470. */
  471. resource_index = (u8) (resource_type - 0x70);
  472. } else {
  473. /*
  474. * Small Resource Type -- bits 6:3 contain the name
  475. * Shift range to index range 0x00-0x0F
  476. */
  477. resource_index = (u8)
  478. ((resource_type & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3);
  479. }
  480. /*
  481. * Check validity of the resource type, via acpi_gbl_resource_types.
  482. * Zero indicates an invalid resource.
  483. */
  484. if (!acpi_gbl_resource_types[resource_index]) {
  485. goto invalid_resource;
  486. }
  487. /*
  488. * Validate the resource_length field. This ensures that the length
  489. * is at least reasonable, and guarantees that it is non-zero.
  490. */
  491. resource_length = acpi_ut_get_resource_length(aml);
  492. minimum_resource_length = acpi_gbl_resource_aml_sizes[resource_index];
  493. /* Validate based upon the type of resource - fixed length or variable */
  494. switch (acpi_gbl_resource_types[resource_index]) {
  495. case ACPI_FIXED_LENGTH:
  496. /* Fixed length resource, length must match exactly */
  497. if (resource_length != minimum_resource_length) {
  498. goto bad_resource_length;
  499. }
  500. break;
  501. case ACPI_VARIABLE_LENGTH:
  502. /* Variable length resource, length must be at least the minimum */
  503. if (resource_length < minimum_resource_length) {
  504. goto bad_resource_length;
  505. }
  506. break;
  507. case ACPI_SMALL_VARIABLE_LENGTH:
  508. /* Small variable length resource, length can be (Min) or (Min-1) */
  509. if ((resource_length > minimum_resource_length) ||
  510. (resource_length < (minimum_resource_length - 1))) {
  511. goto bad_resource_length;
  512. }
  513. break;
  514. default:
  515. /* Shouldn't happen (because of validation earlier), but be sure */
  516. goto invalid_resource;
  517. }
  518. aml_resource = ACPI_CAST_PTR(union aml_resource, aml);
  519. if (resource_type == ACPI_RESOURCE_NAME_SERIAL_BUS) {
  520. /* Validate the bus_type field */
  521. if ((aml_resource->common_serial_bus.type == 0) ||
  522. (aml_resource->common_serial_bus.type >
  523. AML_RESOURCE_MAX_SERIALBUSTYPE)) {
  524. if (walk_state) {
  525. ACPI_ERROR((AE_INFO,
  526. "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X",
  527. aml_resource->common_serial_bus.
  528. type));
  529. }
  530. return (AE_AML_INVALID_RESOURCE_TYPE);
  531. }
  532. }
  533. /* Optionally return the resource table index */
  534. if (return_index) {
  535. *return_index = resource_index;
  536. }
  537. return (AE_OK);
  538. invalid_resource:
  539. if (walk_state) {
  540. ACPI_ERROR((AE_INFO,
  541. "Invalid/unsupported resource descriptor: Type 0x%2.2X",
  542. resource_type));
  543. }
  544. return (AE_AML_INVALID_RESOURCE_TYPE);
  545. bad_resource_length:
  546. if (walk_state) {
  547. ACPI_ERROR((AE_INFO,
  548. "Invalid resource descriptor length: Type "
  549. "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X",
  550. resource_type, resource_length,
  551. minimum_resource_length));
  552. }
  553. return (AE_AML_BAD_RESOURCE_LENGTH);
  554. }
  555. /*******************************************************************************
  556. *
  557. * FUNCTION: acpi_ut_get_resource_type
  558. *
  559. * PARAMETERS: aml - Pointer to the raw AML resource descriptor
  560. *
  561. * RETURN: The Resource Type with no extraneous bits (except the
  562. * Large/Small descriptor bit -- this is left alone)
  563. *
  564. * DESCRIPTION: Extract the Resource Type/Name from the first byte of
  565. * a resource descriptor.
  566. *
  567. ******************************************************************************/
  568. u8 acpi_ut_get_resource_type(void *aml)
  569. {
  570. ACPI_FUNCTION_ENTRY();
  571. /*
  572. * Byte 0 contains the descriptor name (Resource Type)
  573. * Examine the large/small bit in the resource header
  574. */
  575. if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) {
  576. /* Large Resource Type -- bits 6:0 contain the name */
  577. return (ACPI_GET8(aml));
  578. } else {
  579. /* Small Resource Type -- bits 6:3 contain the name */
  580. return ((u8) (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_SMALL_MASK));
  581. }
  582. }
  583. /*******************************************************************************
  584. *
  585. * FUNCTION: acpi_ut_get_resource_length
  586. *
  587. * PARAMETERS: aml - Pointer to the raw AML resource descriptor
  588. *
  589. * RETURN: Byte Length
  590. *
  591. * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By
  592. * definition, this does not include the size of the descriptor
  593. * header or the length field itself.
  594. *
  595. ******************************************************************************/
  596. u16 acpi_ut_get_resource_length(void *aml)
  597. {
  598. acpi_rs_length resource_length;
  599. ACPI_FUNCTION_ENTRY();
  600. /*
  601. * Byte 0 contains the descriptor name (Resource Type)
  602. * Examine the large/small bit in the resource header
  603. */
  604. if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) {
  605. /* Large Resource type -- bytes 1-2 contain the 16-bit length */
  606. ACPI_MOVE_16_TO_16(&resource_length, ACPI_ADD_PTR(u8, aml, 1));
  607. } else {
  608. /* Small Resource type -- bits 2:0 of byte 0 contain the length */
  609. resource_length = (u16) (ACPI_GET8(aml) &
  610. ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK);
  611. }
  612. return (resource_length);
  613. }
  614. /*******************************************************************************
  615. *
  616. * FUNCTION: acpi_ut_get_resource_header_length
  617. *
  618. * PARAMETERS: aml - Pointer to the raw AML resource descriptor
  619. *
  620. * RETURN: Length of the AML header (depends on large/small descriptor)
  621. *
  622. * DESCRIPTION: Get the length of the header for this resource.
  623. *
  624. ******************************************************************************/
  625. u8 acpi_ut_get_resource_header_length(void *aml)
  626. {
  627. ACPI_FUNCTION_ENTRY();
  628. /* Examine the large/small bit in the resource header */
  629. if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) {
  630. return (sizeof(struct aml_resource_large_header));
  631. } else {
  632. return (sizeof(struct aml_resource_small_header));
  633. }
  634. }
  635. /*******************************************************************************
  636. *
  637. * FUNCTION: acpi_ut_get_descriptor_length
  638. *
  639. * PARAMETERS: aml - Pointer to the raw AML resource descriptor
  640. *
  641. * RETURN: Byte length
  642. *
  643. * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the
  644. * length of the descriptor header and the length field itself.
  645. * Used to walk descriptor lists.
  646. *
  647. ******************************************************************************/
  648. u32 acpi_ut_get_descriptor_length(void *aml)
  649. {
  650. ACPI_FUNCTION_ENTRY();
  651. /*
  652. * Get the Resource Length (does not include header length) and add
  653. * the header length (depends on if this is a small or large resource)
  654. */
  655. return (acpi_ut_get_resource_length(aml) +
  656. acpi_ut_get_resource_header_length(aml));
  657. }
  658. /*******************************************************************************
  659. *
  660. * FUNCTION: acpi_ut_get_resource_end_tag
  661. *
  662. * PARAMETERS: obj_desc - The resource template buffer object
  663. * end_tag - Where the pointer to the end_tag is returned
  664. *
  665. * RETURN: Status, pointer to the end tag
  666. *
  667. * DESCRIPTION: Find the end_tag resource descriptor in an AML resource template
  668. * Note: allows a buffer length of zero.
  669. *
  670. ******************************************************************************/
  671. acpi_status
  672. acpi_ut_get_resource_end_tag(union acpi_operand_object *obj_desc, u8 **end_tag)
  673. {
  674. acpi_status status;
  675. ACPI_FUNCTION_TRACE(ut_get_resource_end_tag);
  676. /* Allow a buffer length of zero */
  677. if (!obj_desc->buffer.length) {
  678. *end_tag = obj_desc->buffer.pointer;
  679. return_ACPI_STATUS(AE_OK);
  680. }
  681. /* Validate the template and get a pointer to the end_tag */
  682. status = acpi_ut_walk_aml_resources(NULL, obj_desc->buffer.pointer,
  683. obj_desc->buffer.length, NULL,
  684. (void **)end_tag);
  685. return_ACPI_STATUS(status);
  686. }