utresrc.c 21 KB

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