rsmisc.c 18 KB

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