utresrc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /*******************************************************************************
  2. *
  3. * Module Name: utresrc - Resource management utilities
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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. /* The absolute minimum resource template is one end_tag descriptor */
  361. if (aml_length < sizeof(struct aml_resource_end_tag)) {
  362. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  363. }
  364. /* Point to the end of the resource template buffer */
  365. end_aml = aml + aml_length;
  366. /* Walk the byte list, abort on any invalid descriptor type or length */
  367. while (aml < end_aml) {
  368. /* Validate the Resource Type and Resource Length */
  369. status =
  370. acpi_ut_validate_resource(walk_state, aml, &resource_index);
  371. if (ACPI_FAILURE(status)) {
  372. /*
  373. * Exit on failure. Cannot continue because the descriptor
  374. * length may be bogus also.
  375. */
  376. return_ACPI_STATUS(status);
  377. }
  378. /* Get the length of this descriptor */
  379. length = acpi_ut_get_descriptor_length(aml);
  380. /* Invoke the user function */
  381. if (user_function) {
  382. status =
  383. user_function(aml, length, offset, resource_index,
  384. context);
  385. if (ACPI_FAILURE(status)) {
  386. return_ACPI_STATUS(status);
  387. }
  388. }
  389. /* An end_tag descriptor terminates this resource template */
  390. if (acpi_ut_get_resource_type(aml) ==
  391. ACPI_RESOURCE_NAME_END_TAG) {
  392. /*
  393. * There must be at least one more byte in the buffer for
  394. * the 2nd byte of the end_tag
  395. */
  396. if ((aml + 1) >= end_aml) {
  397. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  398. }
  399. /* Return the pointer to the end_tag if requested */
  400. if (!user_function) {
  401. *context = aml;
  402. }
  403. /* Normal exit */
  404. return_ACPI_STATUS(AE_OK);
  405. }
  406. aml += length;
  407. offset += length;
  408. }
  409. /* Did not find an end_tag descriptor */
  410. if (user_function) {
  411. /* Insert an end_tag anyway. acpi_rs_get_list_length always leaves room */
  412. (void)acpi_ut_validate_resource(walk_state, end_tag,
  413. &resource_index);
  414. status =
  415. user_function(end_tag, 2, offset, resource_index, context);
  416. if (ACPI_FAILURE(status)) {
  417. return_ACPI_STATUS(status);
  418. }
  419. }
  420. return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
  421. }
  422. /*******************************************************************************
  423. *
  424. * FUNCTION: acpi_ut_validate_resource
  425. *
  426. * PARAMETERS: walk_state - Current walk info
  427. * aml - Pointer to the raw AML resource descriptor
  428. * return_index - Where the resource index is returned. NULL
  429. * if the index is not required.
  430. *
  431. * RETURN: Status, and optionally the Index into the global resource tables
  432. *
  433. * DESCRIPTION: Validate an AML resource descriptor by checking the Resource
  434. * Type and Resource Length. Returns an index into the global
  435. * resource information/dispatch tables for later use.
  436. *
  437. ******************************************************************************/
  438. acpi_status
  439. acpi_ut_validate_resource(struct acpi_walk_state *walk_state,
  440. void *aml, u8 *return_index)
  441. {
  442. union aml_resource *aml_resource;
  443. u8 resource_type;
  444. u8 resource_index;
  445. acpi_rs_length resource_length;
  446. acpi_rs_length minimum_resource_length;
  447. ACPI_FUNCTION_ENTRY();
  448. /*
  449. * 1) Validate the resource_type field (Byte 0)
  450. */
  451. resource_type = ACPI_GET8(aml);
  452. /*
  453. * Byte 0 contains the descriptor name (Resource Type)
  454. * Examine the large/small bit in the resource header
  455. */
  456. if (resource_type & ACPI_RESOURCE_NAME_LARGE) {
  457. /* Verify the large resource type (name) against the max */
  458. if (resource_type > ACPI_RESOURCE_NAME_LARGE_MAX) {
  459. goto invalid_resource;
  460. }
  461. /*
  462. * Large Resource Type -- bits 6:0 contain the name
  463. * Translate range 0x80-0x8B to index range 0x10-0x1B
  464. */
  465. resource_index = (u8) (resource_type - 0x70);
  466. } else {
  467. /*
  468. * Small Resource Type -- bits 6:3 contain the name
  469. * Shift range to index range 0x00-0x0F
  470. */
  471. resource_index = (u8)
  472. ((resource_type & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3);
  473. }
  474. /*
  475. * Check validity of the resource type, via acpi_gbl_resource_types.
  476. * Zero indicates an invalid resource.
  477. */
  478. if (!acpi_gbl_resource_types[resource_index]) {
  479. goto invalid_resource;
  480. }
  481. /*
  482. * Validate the resource_length field. This ensures that the length
  483. * is at least reasonable, and guarantees that it is non-zero.
  484. */
  485. resource_length = acpi_ut_get_resource_length(aml);
  486. minimum_resource_length = acpi_gbl_resource_aml_sizes[resource_index];
  487. /* Validate based upon the type of resource - fixed length or variable */
  488. switch (acpi_gbl_resource_types[resource_index]) {
  489. case ACPI_FIXED_LENGTH:
  490. /* Fixed length resource, length must match exactly */
  491. if (resource_length != minimum_resource_length) {
  492. goto bad_resource_length;
  493. }
  494. break;
  495. case ACPI_VARIABLE_LENGTH:
  496. /* Variable length resource, length must be at least the minimum */
  497. if (resource_length < minimum_resource_length) {
  498. goto bad_resource_length;
  499. }
  500. break;
  501. case ACPI_SMALL_VARIABLE_LENGTH:
  502. /* Small variable length resource, length can be (Min) or (Min-1) */
  503. if ((resource_length > minimum_resource_length) ||
  504. (resource_length < (minimum_resource_length - 1))) {
  505. goto bad_resource_length;
  506. }
  507. break;
  508. default:
  509. /* Shouldn't happen (because of validation earlier), but be sure */
  510. goto invalid_resource;
  511. }
  512. aml_resource = ACPI_CAST_PTR(union aml_resource, aml);
  513. if (resource_type == ACPI_RESOURCE_NAME_SERIAL_BUS) {
  514. /* Validate the bus_type field */
  515. if ((aml_resource->common_serial_bus.type == 0) ||
  516. (aml_resource->common_serial_bus.type >
  517. AML_RESOURCE_MAX_SERIALBUSTYPE)) {
  518. if (walk_state) {
  519. ACPI_ERROR((AE_INFO,
  520. "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X",
  521. aml_resource->common_serial_bus.
  522. type));
  523. }
  524. return (AE_AML_INVALID_RESOURCE_TYPE);
  525. }
  526. }
  527. /* Optionally return the resource table index */
  528. if (return_index) {
  529. *return_index = resource_index;
  530. }
  531. return (AE_OK);
  532. invalid_resource:
  533. if (walk_state) {
  534. ACPI_ERROR((AE_INFO,
  535. "Invalid/unsupported resource descriptor: Type 0x%2.2X",
  536. resource_type));
  537. }
  538. return (AE_AML_INVALID_RESOURCE_TYPE);
  539. bad_resource_length:
  540. if (walk_state) {
  541. ACPI_ERROR((AE_INFO,
  542. "Invalid resource descriptor length: Type "
  543. "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X",
  544. resource_type, resource_length,
  545. minimum_resource_length));
  546. }
  547. return (AE_AML_BAD_RESOURCE_LENGTH);
  548. }
  549. /*******************************************************************************
  550. *
  551. * FUNCTION: acpi_ut_get_resource_type
  552. *
  553. * PARAMETERS: aml - Pointer to the raw AML resource descriptor
  554. *
  555. * RETURN: The Resource Type with no extraneous bits (except the
  556. * Large/Small descriptor bit -- this is left alone)
  557. *
  558. * DESCRIPTION: Extract the Resource Type/Name from the first byte of
  559. * a resource descriptor.
  560. *
  561. ******************************************************************************/
  562. u8 acpi_ut_get_resource_type(void *aml)
  563. {
  564. ACPI_FUNCTION_ENTRY();
  565. /*
  566. * Byte 0 contains the descriptor name (Resource Type)
  567. * Examine the large/small bit in the resource header
  568. */
  569. if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) {
  570. /* Large Resource Type -- bits 6:0 contain the name */
  571. return (ACPI_GET8(aml));
  572. } else {
  573. /* Small Resource Type -- bits 6:3 contain the name */
  574. return ((u8) (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_SMALL_MASK));
  575. }
  576. }
  577. /*******************************************************************************
  578. *
  579. * FUNCTION: acpi_ut_get_resource_length
  580. *
  581. * PARAMETERS: aml - Pointer to the raw AML resource descriptor
  582. *
  583. * RETURN: Byte Length
  584. *
  585. * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By
  586. * definition, this does not include the size of the descriptor
  587. * header or the length field itself.
  588. *
  589. ******************************************************************************/
  590. u16 acpi_ut_get_resource_length(void *aml)
  591. {
  592. acpi_rs_length resource_length;
  593. ACPI_FUNCTION_ENTRY();
  594. /*
  595. * Byte 0 contains the descriptor name (Resource Type)
  596. * Examine the large/small bit in the resource header
  597. */
  598. if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) {
  599. /* Large Resource type -- bytes 1-2 contain the 16-bit length */
  600. ACPI_MOVE_16_TO_16(&resource_length, ACPI_ADD_PTR(u8, aml, 1));
  601. } else {
  602. /* Small Resource type -- bits 2:0 of byte 0 contain the length */
  603. resource_length = (u16) (ACPI_GET8(aml) &
  604. ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK);
  605. }
  606. return (resource_length);
  607. }
  608. /*******************************************************************************
  609. *
  610. * FUNCTION: acpi_ut_get_resource_header_length
  611. *
  612. * PARAMETERS: aml - Pointer to the raw AML resource descriptor
  613. *
  614. * RETURN: Length of the AML header (depends on large/small descriptor)
  615. *
  616. * DESCRIPTION: Get the length of the header for this resource.
  617. *
  618. ******************************************************************************/
  619. u8 acpi_ut_get_resource_header_length(void *aml)
  620. {
  621. ACPI_FUNCTION_ENTRY();
  622. /* Examine the large/small bit in the resource header */
  623. if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) {
  624. return (sizeof(struct aml_resource_large_header));
  625. } else {
  626. return (sizeof(struct aml_resource_small_header));
  627. }
  628. }
  629. /*******************************************************************************
  630. *
  631. * FUNCTION: acpi_ut_get_descriptor_length
  632. *
  633. * PARAMETERS: aml - Pointer to the raw AML resource descriptor
  634. *
  635. * RETURN: Byte length
  636. *
  637. * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the
  638. * length of the descriptor header and the length field itself.
  639. * Used to walk descriptor lists.
  640. *
  641. ******************************************************************************/
  642. u32 acpi_ut_get_descriptor_length(void *aml)
  643. {
  644. ACPI_FUNCTION_ENTRY();
  645. /*
  646. * Get the Resource Length (does not include header length) and add
  647. * the header length (depends on if this is a small or large resource)
  648. */
  649. return (acpi_ut_get_resource_length(aml) +
  650. acpi_ut_get_resource_header_length(aml));
  651. }
  652. /*******************************************************************************
  653. *
  654. * FUNCTION: acpi_ut_get_resource_end_tag
  655. *
  656. * PARAMETERS: obj_desc - The resource template buffer object
  657. * end_tag - Where the pointer to the end_tag is returned
  658. *
  659. * RETURN: Status, pointer to the end tag
  660. *
  661. * DESCRIPTION: Find the end_tag resource descriptor in an AML resource template
  662. * Note: allows a buffer length of zero.
  663. *
  664. ******************************************************************************/
  665. acpi_status
  666. acpi_ut_get_resource_end_tag(union acpi_operand_object *obj_desc, u8 **end_tag)
  667. {
  668. acpi_status status;
  669. ACPI_FUNCTION_TRACE(ut_get_resource_end_tag);
  670. /* Allow a buffer length of zero */
  671. if (!obj_desc->buffer.length) {
  672. *end_tag = obj_desc->buffer.pointer;
  673. return_ACPI_STATUS(AE_OK);
  674. }
  675. /* Validate the template and get a pointer to the end_tag */
  676. status = acpi_ut_walk_aml_resources(NULL, obj_desc->buffer.pointer,
  677. obj_desc->buffer.length, NULL,
  678. (void **)end_tag);
  679. return_ACPI_STATUS(status);
  680. }