utresrc.c 21 KB

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