rsmisc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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_end_tag_resource
  49. *
  50. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  51. * stream
  52. * bytes_consumed - Pointer to where the number of bytes
  53. * consumed the byte_stream_buffer is
  54. * returned
  55. * output_buffer - Pointer to the return data buffer
  56. * structure_size - Pointer to where the number of bytes
  57. * in the return data struct is returned
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  62. * structure pointed to by the output_buffer. Return the
  63. * number of bytes consumed from the byte stream.
  64. *
  65. ******************************************************************************/
  66. acpi_status
  67. acpi_rs_end_tag_resource(u8 * byte_stream_buffer,
  68. acpi_size * bytes_consumed,
  69. u8 ** output_buffer, acpi_size * structure_size)
  70. {
  71. struct acpi_resource *output_struct = (void *)*output_buffer;
  72. acpi_size struct_size = ACPI_RESOURCE_LENGTH;
  73. ACPI_FUNCTION_TRACE("rs_end_tag_resource");
  74. /* The number of bytes consumed is static */
  75. *bytes_consumed = 2;
  76. /* Fill out the structure */
  77. output_struct->id = ACPI_RSTYPE_END_TAG;
  78. /* Set the Length parameter */
  79. output_struct->length = 0;
  80. /* Return the final size of the structure */
  81. *structure_size = struct_size;
  82. return_ACPI_STATUS(AE_OK);
  83. }
  84. /*******************************************************************************
  85. *
  86. * FUNCTION: acpi_rs_end_tag_stream
  87. *
  88. * PARAMETERS: linked_list - Pointer to the resource linked list
  89. * output_buffer - Pointer to the user's return buffer
  90. * bytes_consumed - Pointer to where the number of bytes
  91. * used in the output_buffer is returned
  92. *
  93. * RETURN: Status
  94. *
  95. * DESCRIPTION: Take the linked list resource structure and fills in the
  96. * the appropriate bytes in a byte stream
  97. *
  98. ******************************************************************************/
  99. acpi_status
  100. acpi_rs_end_tag_stream(struct acpi_resource *linked_list,
  101. u8 ** output_buffer, acpi_size * bytes_consumed)
  102. {
  103. u8 *buffer = *output_buffer;
  104. u8 temp8 = 0;
  105. ACPI_FUNCTION_TRACE("rs_end_tag_stream");
  106. /* The descriptor field is static */
  107. *buffer = 0x79;
  108. buffer += 1;
  109. /*
  110. * Set the Checksum - zero means that the resource data is treated as if
  111. * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
  112. */
  113. temp8 = 0;
  114. *buffer = temp8;
  115. buffer += 1;
  116. /* Return the number of bytes consumed in this operation */
  117. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  118. return_ACPI_STATUS(AE_OK);
  119. }
  120. /*******************************************************************************
  121. *
  122. * FUNCTION: acpi_rs_vendor_resource
  123. *
  124. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  125. * stream
  126. * bytes_consumed - Pointer to where the number of bytes
  127. * consumed the byte_stream_buffer is
  128. * returned
  129. * output_buffer - Pointer to the return data buffer
  130. * structure_size - Pointer to where the number of bytes
  131. * in the return data struct is returned
  132. *
  133. * RETURN: Status
  134. *
  135. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  136. * structure pointed to by the output_buffer. Return the
  137. * number of bytes consumed from the byte stream.
  138. *
  139. ******************************************************************************/
  140. acpi_status
  141. acpi_rs_vendor_resource(u8 * byte_stream_buffer,
  142. acpi_size * bytes_consumed,
  143. u8 ** output_buffer, acpi_size * structure_size)
  144. {
  145. u8 *buffer = byte_stream_buffer;
  146. struct acpi_resource *output_struct = (void *)*output_buffer;
  147. u16 temp16 = 0;
  148. u8 temp8 = 0;
  149. u8 index;
  150. acpi_size struct_size =
  151. ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor);
  152. ACPI_FUNCTION_TRACE("rs_vendor_resource");
  153. /* Dereference the Descriptor to find if this is a large or small item. */
  154. temp8 = *buffer;
  155. if (temp8 & 0x80) {
  156. /* Large Item, point to the length field */
  157. buffer += 1;
  158. /* Dereference */
  159. ACPI_MOVE_16_TO_16(&temp16, buffer);
  160. /* Calculate bytes consumed */
  161. *bytes_consumed = (acpi_size) temp16 + 3;
  162. /* Point to the first vendor byte */
  163. buffer += 2;
  164. } else {
  165. /* Small Item, dereference the size */
  166. temp16 = (u8) (*buffer & 0x07);
  167. /* Calculate bytes consumed */
  168. *bytes_consumed = (acpi_size) temp16 + 1;
  169. /* Point to the first vendor byte */
  170. buffer += 1;
  171. }
  172. output_struct->id = ACPI_RSTYPE_VENDOR;
  173. output_struct->data.vendor_specific.length = temp16;
  174. for (index = 0; index < temp16; index++) {
  175. output_struct->data.vendor_specific.reserved[index] = *buffer;
  176. buffer += 1;
  177. }
  178. /*
  179. * In order for the struct_size to fall on a 32-bit boundary,
  180. * calculate the length of the vendor string and expand the
  181. * struct_size to the next 32-bit boundary.
  182. */
  183. struct_size += ACPI_ROUND_UP_to_32_bITS(temp16);
  184. /* Set the Length parameter */
  185. output_struct->length = (u32) struct_size;
  186. /* Return the final size of the structure */
  187. *structure_size = struct_size;
  188. return_ACPI_STATUS(AE_OK);
  189. }
  190. /*******************************************************************************
  191. *
  192. * FUNCTION: acpi_rs_vendor_stream
  193. *
  194. * PARAMETERS: linked_list - Pointer to the resource linked list
  195. * output_buffer - Pointer to the user's return buffer
  196. * bytes_consumed - Pointer to where the number of bytes
  197. * used in the output_buffer is returned
  198. *
  199. * RETURN: Status
  200. *
  201. * DESCRIPTION: Take the linked list resource structure and fills in the
  202. * the appropriate bytes in a byte stream
  203. *
  204. ******************************************************************************/
  205. acpi_status
  206. acpi_rs_vendor_stream(struct acpi_resource *linked_list,
  207. u8 ** output_buffer, acpi_size * bytes_consumed)
  208. {
  209. u8 *buffer = *output_buffer;
  210. u16 temp16 = 0;
  211. u8 temp8 = 0;
  212. u8 index;
  213. ACPI_FUNCTION_TRACE("rs_vendor_stream");
  214. /* Dereference the length to find if this is a large or small item. */
  215. if (linked_list->data.vendor_specific.length > 7) {
  216. /* Large Item, Set the descriptor field and length bytes */
  217. *buffer = 0x84;
  218. buffer += 1;
  219. temp16 = (u16) linked_list->data.vendor_specific.length;
  220. ACPI_MOVE_16_TO_16(buffer, &temp16);
  221. buffer += 2;
  222. } else {
  223. /* Small Item, Set the descriptor field */
  224. temp8 = 0x70;
  225. temp8 |= (u8) linked_list->data.vendor_specific.length;
  226. *buffer = temp8;
  227. buffer += 1;
  228. }
  229. /* Loop through all of the Vendor Specific fields */
  230. for (index = 0; index < linked_list->data.vendor_specific.length;
  231. index++) {
  232. temp8 = linked_list->data.vendor_specific.reserved[index];
  233. *buffer = temp8;
  234. buffer += 1;
  235. }
  236. /* Return the number of bytes consumed in this operation */
  237. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  238. return_ACPI_STATUS(AE_OK);
  239. }
  240. /*******************************************************************************
  241. *
  242. * FUNCTION: acpi_rs_start_depend_fns_resource
  243. *
  244. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  245. * stream
  246. * bytes_consumed - Pointer to where the number of bytes
  247. * consumed the byte_stream_buffer is
  248. * returned
  249. * output_buffer - Pointer to the return data buffer
  250. * structure_size - Pointer to where the number of bytes
  251. * in the return data struct is returned
  252. *
  253. * RETURN: Status
  254. *
  255. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  256. * structure pointed to by the output_buffer. Return the
  257. * number of bytes consumed from the byte stream.
  258. *
  259. ******************************************************************************/
  260. acpi_status
  261. acpi_rs_start_depend_fns_resource(u8 * byte_stream_buffer,
  262. acpi_size * bytes_consumed,
  263. u8 ** output_buffer,
  264. acpi_size * structure_size)
  265. {
  266. u8 *buffer = byte_stream_buffer;
  267. struct acpi_resource *output_struct = (void *)*output_buffer;
  268. u8 temp8 = 0;
  269. acpi_size struct_size =
  270. ACPI_SIZEOF_RESOURCE(struct acpi_resource_start_dpf);
  271. ACPI_FUNCTION_TRACE("rs_start_depend_fns_resource");
  272. /* The number of bytes consumed are found in the descriptor (Bits:0-1) */
  273. temp8 = *buffer;
  274. *bytes_consumed = (temp8 & 0x01) + 1;
  275. output_struct->id = ACPI_RSTYPE_START_DPF;
  276. /* Point to Byte 1 if it is used */
  277. if (2 == *bytes_consumed) {
  278. buffer += 1;
  279. temp8 = *buffer;
  280. /* Check Compatibility priority */
  281. output_struct->data.start_dpf.compatibility_priority =
  282. temp8 & 0x03;
  283. if (3 == output_struct->data.start_dpf.compatibility_priority) {
  284. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
  285. }
  286. /* Check Performance/Robustness preference */
  287. output_struct->data.start_dpf.performance_robustness =
  288. (temp8 >> 2) & 0x03;
  289. if (3 == output_struct->data.start_dpf.performance_robustness) {
  290. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
  291. }
  292. } else {
  293. output_struct->data.start_dpf.compatibility_priority =
  294. ACPI_ACCEPTABLE_CONFIGURATION;
  295. output_struct->data.start_dpf.performance_robustness =
  296. ACPI_ACCEPTABLE_CONFIGURATION;
  297. }
  298. /* Set the Length parameter */
  299. output_struct->length = (u32) struct_size;
  300. /* Return the final size of the structure */
  301. *structure_size = struct_size;
  302. return_ACPI_STATUS(AE_OK);
  303. }
  304. /*******************************************************************************
  305. *
  306. * FUNCTION: acpi_rs_end_depend_fns_resource
  307. *
  308. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  309. * stream
  310. * bytes_consumed - Pointer to where the number of bytes
  311. * consumed the byte_stream_buffer is
  312. * returned
  313. * output_buffer - Pointer to the return data buffer
  314. * structure_size - Pointer to where the number of bytes
  315. * in the return data struct is returned
  316. *
  317. * RETURN: Status
  318. *
  319. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  320. * structure pointed to by the output_buffer. Return the
  321. * number of bytes consumed from the byte stream.
  322. *
  323. ******************************************************************************/
  324. acpi_status
  325. acpi_rs_end_depend_fns_resource(u8 * byte_stream_buffer,
  326. acpi_size * bytes_consumed,
  327. u8 ** output_buffer, acpi_size * structure_size)
  328. {
  329. struct acpi_resource *output_struct = (void *)*output_buffer;
  330. acpi_size struct_size = ACPI_RESOURCE_LENGTH;
  331. ACPI_FUNCTION_TRACE("rs_end_depend_fns_resource");
  332. /* The number of bytes consumed is static */
  333. *bytes_consumed = 1;
  334. /* Fill out the structure */
  335. output_struct->id = ACPI_RSTYPE_END_DPF;
  336. /* Set the Length parameter */
  337. output_struct->length = (u32) struct_size;
  338. /* Return the final size of the structure */
  339. *structure_size = struct_size;
  340. return_ACPI_STATUS(AE_OK);
  341. }
  342. /*******************************************************************************
  343. *
  344. * FUNCTION: acpi_rs_start_depend_fns_stream
  345. *
  346. * PARAMETERS: linked_list - Pointer to the resource linked list
  347. * output_buffer - Pointer to the user's return buffer
  348. * bytes_consumed - u32 pointer that is filled with
  349. * the number of bytes of the
  350. * output_buffer used
  351. *
  352. * RETURN: Status
  353. *
  354. * DESCRIPTION: Take the linked list resource structure and fills in the
  355. * the appropriate bytes in a byte stream
  356. *
  357. ******************************************************************************/
  358. acpi_status
  359. acpi_rs_start_depend_fns_stream(struct acpi_resource *linked_list,
  360. u8 ** output_buffer, acpi_size * bytes_consumed)
  361. {
  362. u8 *buffer = *output_buffer;
  363. u8 temp8 = 0;
  364. ACPI_FUNCTION_TRACE("rs_start_depend_fns_stream");
  365. /*
  366. * The descriptor field is set based upon whether a byte is needed
  367. * to contain Priority data.
  368. */
  369. if (ACPI_ACCEPTABLE_CONFIGURATION ==
  370. linked_list->data.start_dpf.compatibility_priority &&
  371. ACPI_ACCEPTABLE_CONFIGURATION ==
  372. linked_list->data.start_dpf.performance_robustness) {
  373. *buffer = 0x30;
  374. } else {
  375. *buffer = 0x31;
  376. buffer += 1;
  377. /* Set the Priority Byte Definition */
  378. temp8 = 0;
  379. temp8 =
  380. (u8) ((linked_list->data.start_dpf.
  381. performance_robustness & 0x03) << 2);
  382. temp8 |=
  383. (linked_list->data.start_dpf.compatibility_priority & 0x03);
  384. *buffer = temp8;
  385. }
  386. buffer += 1;
  387. /* Return the number of bytes consumed in this operation */
  388. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  389. return_ACPI_STATUS(AE_OK);
  390. }
  391. /*******************************************************************************
  392. *
  393. * FUNCTION: acpi_rs_end_depend_fns_stream
  394. *
  395. * PARAMETERS: linked_list - Pointer to the resource linked list
  396. * output_buffer - Pointer to the user's return buffer
  397. * bytes_consumed - Pointer to where the number of bytes
  398. * used in the output_buffer is returned
  399. *
  400. * RETURN: Status
  401. *
  402. * DESCRIPTION: Take the linked list resource structure and fills in the
  403. * the appropriate bytes in a byte stream
  404. *
  405. ******************************************************************************/
  406. acpi_status
  407. acpi_rs_end_depend_fns_stream(struct acpi_resource *linked_list,
  408. u8 ** output_buffer, acpi_size * bytes_consumed)
  409. {
  410. u8 *buffer = *output_buffer;
  411. ACPI_FUNCTION_TRACE("rs_end_depend_fns_stream");
  412. /* The descriptor field is static */
  413. *buffer = 0x38;
  414. buffer += 1;
  415. /* Return the number of bytes consumed in this operation */
  416. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  417. return_ACPI_STATUS(AE_OK);
  418. }