rsmisc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsmisc - Miscellaneous resource descriptors
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <acpi/acresrc.h>
  44. #define _COMPONENT ACPI_RESOURCES
  45. ACPI_MODULE_NAME("rsmisc")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_rs_get_generic_reg
  49. *
  50. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  51. * aml_resource_length - Length of the resource from the AML header
  52. * Resource - Where the internal resource is returned
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  57. * internal resource descriptor, simplifying bitflags and handling
  58. * alignment and endian issues if necessary.
  59. *
  60. ******************************************************************************/
  61. acpi_status
  62. acpi_rs_get_generic_reg(union aml_resource *aml,
  63. u16 aml_resource_length, struct acpi_resource *resource)
  64. {
  65. ACPI_FUNCTION_TRACE("rs_get_generic_reg");
  66. /*
  67. * Get the following fields from the AML descriptor:
  68. * Address Space ID
  69. * Register Bit Width
  70. * Register Bit Offset
  71. * Access Size
  72. * Register Address
  73. */
  74. resource->data.generic_reg.space_id = aml->generic_reg.address_space_id;
  75. resource->data.generic_reg.bit_width = aml->generic_reg.bit_width;
  76. resource->data.generic_reg.bit_offset = aml->generic_reg.bit_offset;
  77. resource->data.generic_reg.access_size = aml->generic_reg.access_size;
  78. ACPI_MOVE_64_TO_64(&resource->data.generic_reg.address,
  79. &aml->generic_reg.address);
  80. /* Complete the resource header */
  81. resource->type = ACPI_RESOURCE_TYPE_GENERIC_REGISTER;
  82. resource->length =
  83. ACPI_SIZEOF_RESOURCE(struct acpi_resource_generic_register);
  84. return_ACPI_STATUS(AE_OK);
  85. }
  86. /*******************************************************************************
  87. *
  88. * FUNCTION: acpi_rs_set_generic_reg
  89. *
  90. * PARAMETERS: Resource - Pointer to the resource descriptor
  91. * Aml - Where the AML descriptor is returned
  92. *
  93. * RETURN: Status
  94. *
  95. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  96. * external AML resource descriptor.
  97. *
  98. ******************************************************************************/
  99. acpi_status
  100. acpi_rs_set_generic_reg(struct acpi_resource *resource, union aml_resource *aml)
  101. {
  102. ACPI_FUNCTION_TRACE("rs_set_generic_reg");
  103. /*
  104. * Set the following fields in the AML descriptor:
  105. * Address Space ID
  106. * Register Bit Width
  107. * Register Bit Offset
  108. * Access Size
  109. * Register Address
  110. */
  111. aml->generic_reg.address_space_id =
  112. (u8) resource->data.generic_reg.space_id;
  113. aml->generic_reg.bit_width = (u8) resource->data.generic_reg.bit_width;
  114. aml->generic_reg.bit_offset =
  115. (u8) resource->data.generic_reg.bit_offset;
  116. aml->generic_reg.access_size =
  117. (u8) resource->data.generic_reg.access_size;
  118. ACPI_MOVE_64_TO_64(&aml->generic_reg.address,
  119. &resource->data.generic_reg.address);
  120. /* Complete the AML descriptor header */
  121. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_GENERIC_REGISTER,
  122. sizeof(struct
  123. aml_resource_generic_register), aml);
  124. return_ACPI_STATUS(AE_OK);
  125. }
  126. /*******************************************************************************
  127. *
  128. * FUNCTION: acpi_rs_get_vendor
  129. *
  130. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  131. * aml_resource_length - Length of the resource from the AML header
  132. * Resource - Where the internal resource is returned
  133. *
  134. * RETURN: Status
  135. *
  136. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  137. * internal resource descriptor, simplifying bitflags and handling
  138. * alignment and endian issues if necessary.
  139. *
  140. ******************************************************************************/
  141. acpi_status
  142. acpi_rs_get_vendor(union aml_resource *aml,
  143. u16 aml_resource_length, struct acpi_resource *resource)
  144. {
  145. u8 *aml_byte_data;
  146. ACPI_FUNCTION_TRACE("rs_get_vendor");
  147. /* Determine if this is a large or small vendor specific item */
  148. if (aml->large_header.descriptor_type & ACPI_RESOURCE_NAME_LARGE) {
  149. /* Large item, Point to the first vendor byte */
  150. aml_byte_data =
  151. ((u8 *) aml) + sizeof(struct aml_resource_large_header);
  152. } else {
  153. /* Small item, Point to the first vendor byte */
  154. aml_byte_data =
  155. ((u8 *) aml) + sizeof(struct aml_resource_small_header);
  156. }
  157. /* Copy the vendor-specific bytes */
  158. ACPI_MEMCPY(resource->data.vendor.byte_data,
  159. aml_byte_data, aml_resource_length);
  160. resource->data.vendor.byte_length = aml_resource_length;
  161. /*
  162. * In order for the struct_size to fall on a 32-bit boundary,
  163. * calculate the length of the vendor string and expand the
  164. * struct_size to the next 32-bit boundary.
  165. */
  166. resource->type = ACPI_RESOURCE_TYPE_VENDOR;
  167. resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) +
  168. ACPI_ROUND_UP_to_32_bITS(aml_resource_length);
  169. return_ACPI_STATUS(AE_OK);
  170. }
  171. /*******************************************************************************
  172. *
  173. * FUNCTION: acpi_rs_set_vendor
  174. *
  175. * PARAMETERS: Resource - Pointer to the resource descriptor
  176. * Aml - Where the AML descriptor is returned
  177. *
  178. * RETURN: Status
  179. *
  180. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  181. * external AML resource descriptor.
  182. *
  183. ******************************************************************************/
  184. acpi_status
  185. acpi_rs_set_vendor(struct acpi_resource *resource, union aml_resource *aml)
  186. {
  187. u32 resource_length;
  188. u8 *source;
  189. u8 *destination;
  190. ACPI_FUNCTION_TRACE("rs_set_vendor");
  191. resource_length = resource->data.vendor.byte_length;
  192. source = ACPI_CAST_PTR(u8, resource->data.vendor.byte_data);
  193. /* Length determines if this is a large or small resource */
  194. if (resource_length > 7) {
  195. /* Large item, get pointer to the data part of the descriptor */
  196. destination =
  197. ((u8 *) aml) + sizeof(struct aml_resource_large_header);
  198. /* Complete the AML descriptor header */
  199. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_VENDOR_LARGE,
  200. (u32) (resource_length +
  201. sizeof(struct
  202. aml_resource_large_header)),
  203. aml);
  204. } else {
  205. /* Small item, get pointer to the data part of the descriptor */
  206. destination =
  207. ((u8 *) aml) + sizeof(struct aml_resource_small_header);
  208. /* Complete the AML descriptor header */
  209. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_VENDOR_SMALL,
  210. (u32) (resource_length +
  211. sizeof(struct
  212. aml_resource_small_header)),
  213. aml);
  214. }
  215. /* Copy the vendor-specific bytes */
  216. ACPI_MEMCPY(destination, source, resource_length);
  217. return_ACPI_STATUS(AE_OK);
  218. }
  219. /*******************************************************************************
  220. *
  221. * FUNCTION: acpi_rs_get_start_dpf
  222. *
  223. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  224. * aml_resource_length - Length of the resource from the AML header
  225. * Resource - Where the internal resource is returned
  226. *
  227. * RETURN: Status
  228. *
  229. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  230. * internal resource descriptor, simplifying bitflags and handling
  231. * alignment and endian issues if necessary.
  232. *
  233. ******************************************************************************/
  234. acpi_status
  235. acpi_rs_get_start_dpf(union aml_resource *aml,
  236. u16 aml_resource_length, struct acpi_resource *resource)
  237. {
  238. ACPI_FUNCTION_TRACE("rs_get_start_dpf");
  239. /* Get the flags byte if present */
  240. if (aml_resource_length == 1) {
  241. /* Get the Compatibility priority */
  242. resource->data.start_dpf.compatibility_priority =
  243. (aml->start_dpf.flags & 0x03);
  244. if (resource->data.start_dpf.compatibility_priority >= 3) {
  245. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
  246. }
  247. /* Get the Performance/Robustness preference */
  248. resource->data.start_dpf.performance_robustness =
  249. ((aml->start_dpf.flags >> 2) & 0x03);
  250. if (resource->data.start_dpf.performance_robustness >= 3) {
  251. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
  252. }
  253. } else {
  254. /* start_dependent_no_pri(), no flags byte, set defaults */
  255. resource->data.start_dpf.compatibility_priority =
  256. ACPI_ACCEPTABLE_CONFIGURATION;
  257. resource->data.start_dpf.performance_robustness =
  258. ACPI_ACCEPTABLE_CONFIGURATION;
  259. }
  260. /* Complete the resource header */
  261. resource->type = ACPI_RESOURCE_TYPE_START_DEPENDENT;
  262. resource->length =
  263. ACPI_SIZEOF_RESOURCE(struct acpi_resource_start_dependent);
  264. return_ACPI_STATUS(AE_OK);
  265. }
  266. /*******************************************************************************
  267. *
  268. * FUNCTION: acpi_rs_set_start_dpf
  269. *
  270. * PARAMETERS: Resource - Pointer to the resource descriptor
  271. * Aml - Where the AML descriptor is returned
  272. *
  273. * RETURN: Status
  274. *
  275. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  276. * external AML resource descriptor.
  277. *
  278. ******************************************************************************/
  279. acpi_status
  280. acpi_rs_set_start_dpf(struct acpi_resource *resource, union aml_resource *aml)
  281. {
  282. ACPI_FUNCTION_TRACE("rs_set_start_dpf");
  283. /*
  284. * The descriptor type field is set based upon whether a byte is needed
  285. * to contain Priority data.
  286. */
  287. if (ACPI_ACCEPTABLE_CONFIGURATION ==
  288. resource->data.start_dpf.compatibility_priority &&
  289. ACPI_ACCEPTABLE_CONFIGURATION ==
  290. resource->data.start_dpf.performance_robustness) {
  291. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_START_DEPENDENT,
  292. sizeof(struct
  293. aml_resource_start_dependent_noprio),
  294. aml);
  295. } else {
  296. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_START_DEPENDENT,
  297. sizeof(struct
  298. aml_resource_start_dependent),
  299. aml);
  300. /* Set the Flags byte */
  301. aml->start_dpf.flags = (u8)
  302. (((resource->data.start_dpf.
  303. performance_robustness & 0x03) << 2) | (resource->data.
  304. start_dpf.
  305. compatibility_priority
  306. & 0x03));
  307. }
  308. return_ACPI_STATUS(AE_OK);
  309. }
  310. /*******************************************************************************
  311. *
  312. * FUNCTION: acpi_rs_get_end_dpf
  313. *
  314. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  315. * aml_resource_length - Length of the resource from the AML header
  316. * Resource - Where the internal resource is returned
  317. *
  318. * RETURN: Status
  319. *
  320. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  321. * internal resource descriptor, simplifying bitflags and handling
  322. * alignment and endian issues if necessary.
  323. *
  324. ******************************************************************************/
  325. acpi_status
  326. acpi_rs_get_end_dpf(union aml_resource *aml,
  327. u16 aml_resource_length, struct acpi_resource *resource)
  328. {
  329. ACPI_FUNCTION_TRACE("rs_get_end_dpf");
  330. /* Complete the resource header */
  331. resource->type = ACPI_RESOURCE_TYPE_END_DEPENDENT;
  332. resource->length = (u32) ACPI_RESOURCE_LENGTH;
  333. return_ACPI_STATUS(AE_OK);
  334. }
  335. /*******************************************************************************
  336. *
  337. * FUNCTION: acpi_rs_set_end_dpf
  338. *
  339. * PARAMETERS: Resource - Pointer to the resource descriptor
  340. * Aml - Where the AML descriptor is returned
  341. *
  342. * RETURN: Status
  343. *
  344. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  345. * external AML resource descriptor.
  346. *
  347. ******************************************************************************/
  348. acpi_status
  349. acpi_rs_set_end_dpf(struct acpi_resource *resource, union aml_resource *aml)
  350. {
  351. ACPI_FUNCTION_TRACE("rs_set_end_dpf");
  352. /* Complete the AML descriptor header */
  353. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_END_DEPENDENT,
  354. sizeof(struct aml_resource_end_dependent),
  355. aml);
  356. return_ACPI_STATUS(AE_OK);
  357. }
  358. /*******************************************************************************
  359. *
  360. * FUNCTION: acpi_rs_get_end_tag
  361. *
  362. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  363. * aml_resource_length - Length of the resource from the AML header
  364. * Resource - Where the internal resource is returned
  365. *
  366. * RETURN: Status
  367. *
  368. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  369. * internal resource descriptor, simplifying bitflags and handling
  370. * alignment and endian issues if necessary.
  371. *
  372. ******************************************************************************/
  373. acpi_status
  374. acpi_rs_get_end_tag(union aml_resource *aml,
  375. u16 aml_resource_length, struct acpi_resource *resource)
  376. {
  377. ACPI_FUNCTION_TRACE("rs_get_end_tag");
  378. /* Complete the resource header */
  379. resource->type = ACPI_RESOURCE_TYPE_END_TAG;
  380. resource->length = ACPI_RESOURCE_LENGTH;
  381. return_ACPI_STATUS(AE_OK);
  382. }
  383. /*******************************************************************************
  384. *
  385. * FUNCTION: acpi_rs_set_end_tag
  386. *
  387. * PARAMETERS: Resource - Pointer to the resource descriptor
  388. * Aml - Where the AML descriptor is returned
  389. *
  390. * RETURN: Status
  391. *
  392. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  393. * external AML resource descriptor.
  394. *
  395. ******************************************************************************/
  396. acpi_status
  397. acpi_rs_set_end_tag(struct acpi_resource *resource, union aml_resource *aml)
  398. {
  399. ACPI_FUNCTION_TRACE("rs_set_end_tag");
  400. /*
  401. * Set the Checksum - zero means that the resource data is treated as if
  402. * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
  403. */
  404. aml->end_tag.checksum = 0;
  405. /* Complete the AML descriptor header */
  406. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_END_TAG,
  407. sizeof(struct aml_resource_end_tag), aml);
  408. return_ACPI_STATUS(AE_OK);
  409. }