rsmisc.c 18 KB

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