rsmisc.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:17k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*******************************************************************************
  2.  *
  3.  * Module Name: rsmisc - Miscellaneous resource descriptors
  4.  *              $Revision: 16 $
  5.  *
  6.  ******************************************************************************/
  7. /*
  8.  *  Copyright (C) 2000, 2001 R. Byron Moore
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23.  */
  24. #include "acpi.h"
  25. #include "acresrc.h"
  26. #define _COMPONENT          ACPI_RESOURCES
  27.  MODULE_NAME         ("rsmisc")
  28. /*******************************************************************************
  29.  *
  30.  * FUNCTION:    Acpi_rs_end_tag_resource
  31.  *
  32.  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
  33.  *                                        stream
  34.  *              Bytes_consumed          - u32 pointer that is filled with
  35.  *                                        the number of bytes consumed from
  36.  *                                        the Byte_stream_buffer
  37.  *              Output_buffer           - Pointer to the user's return buffer
  38.  *              Structure_size          - u32 pointer that is filled with
  39.  *                                        the number of bytes in the filled
  40.  *                                        in structure
  41.  *
  42.  * RETURN:      Status
  43.  *
  44.  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  45.  *              structure pointed to by the Output_buffer. Return the
  46.  *              number of bytes consumed from the byte stream.
  47.  *
  48.  ******************************************************************************/
  49. acpi_status
  50. acpi_rs_end_tag_resource (
  51. u8                      *byte_stream_buffer,
  52. u32                     *bytes_consumed,
  53. u8                      **output_buffer,
  54. u32                     *structure_size)
  55. {
  56. acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
  57. u32                     struct_size = ACPI_RESOURCE_LENGTH;
  58. FUNCTION_TRACE ("Rs_end_tag_resource");
  59. /*
  60.  * The number of bytes consumed is static
  61.  */
  62. *bytes_consumed = 2;
  63. /*
  64.  *  Fill out the structure
  65.  */
  66. output_struct->id = ACPI_RSTYPE_END_TAG;
  67. /*
  68.  * Set the Length parameter
  69.  */
  70. output_struct->length = 0;
  71. /*
  72.  * Return the final size of the structure
  73.  */
  74. *structure_size = struct_size;
  75. return_ACPI_STATUS (AE_OK);
  76. }
  77. /*******************************************************************************
  78.  *
  79.  * FUNCTION:    Acpi_rs_end_tag_stream
  80.  *
  81.  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
  82.  *              Output_buffer           - Pointer to the user's return buffer
  83.  *              Bytes_consumed          - u32 pointer that is filled with
  84.  *                                        the number of bytes of the
  85.  *                                        Output_buffer used
  86.  *
  87.  * RETURN:      Status
  88.  *
  89.  * DESCRIPTION: Take the linked list resource structure and fills in the
  90.  *              the appropriate bytes in a byte stream
  91.  *
  92.  ******************************************************************************/
  93. acpi_status
  94. acpi_rs_end_tag_stream (
  95. acpi_resource           *linked_list,
  96. u8                      **output_buffer,
  97. u32                     *bytes_consumed)
  98. {
  99. u8                      *buffer = *output_buffer;
  100. u8                      temp8 = 0;
  101. FUNCTION_TRACE ("Rs_end_tag_stream");
  102. /*
  103.  * The descriptor field is static
  104.  */
  105. *buffer = 0x79;
  106. buffer += 1;
  107. /*
  108.  * Set the Checksum - zero means that the resource data is treated as if
  109.  * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
  110.  */
  111. temp8 = 0;
  112. *buffer = temp8;
  113. buffer += 1;
  114. /*
  115.  * Return the number of bytes consumed in this operation
  116.  */
  117. *bytes_consumed = POINTER_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          - u32 pointer that is filled with
  127.  *                                        the number of bytes consumed from
  128.  *                                        the Byte_stream_buffer
  129.  *              Output_buffer           - Pointer to the user's return buffer
  130.  *              Structure_size          - u32 pointer that is filled with
  131.  *                                        the number of bytes in the filled
  132.  *                                        in structure
  133.  *
  134.  * RETURN:      Status
  135.  *
  136.  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  137.  *              structure pointed to by the Output_buffer. Return the
  138.  *              number of bytes consumed from the byte stream.
  139.  *
  140.  ******************************************************************************/
  141. acpi_status
  142. acpi_rs_vendor_resource (
  143. u8                      *byte_stream_buffer,
  144. u32                     *bytes_consumed,
  145. u8                      **output_buffer,
  146. u32                     *structure_size)
  147. {
  148. u8                      *buffer = byte_stream_buffer;
  149. acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
  150. u16                     temp16 = 0;
  151. u8                      temp8 = 0;
  152. u8                      index;
  153. u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_vendor);
  154. FUNCTION_TRACE ("Rs_vendor_resource");
  155. /*
  156.  * Dereference the Descriptor to find if this is a large or small item.
  157.  */
  158. temp8 = *buffer;
  159. if (temp8 & 0x80) {
  160. /*
  161.  * Large Item
  162.  * Point to the length field
  163.  */
  164. buffer += 1;
  165. /* Dereference */
  166. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  167. /* Calculate bytes consumed */
  168. *bytes_consumed = temp16 + 3;
  169. /* Point to the first vendor byte */
  170. buffer += 2;
  171. }
  172. else {
  173. /*
  174.  * Small Item
  175.  * Dereference the size
  176.  */
  177. temp16 = (u8)(*buffer & 0x07);
  178. /* Calculate bytes consumed */
  179. *bytes_consumed = temp16 + 1;
  180. /* Point to the first vendor byte */
  181. buffer += 1;
  182. }
  183. output_struct->id = ACPI_RSTYPE_VENDOR;
  184. output_struct->data.vendor_specific.length = temp16;
  185. for (index = 0; index < temp16; index++) {
  186. output_struct->data.vendor_specific.reserved[index] = *buffer;
  187. buffer += 1;
  188. }
  189. /*
  190.  * In order for the Struct_size to fall on a 32-bit boundary,
  191.  * calculate the length of the vendor string and expand the
  192.  * Struct_size to the next 32-bit boundary.
  193.  */
  194. struct_size += ROUND_UP_TO_32_bITS (temp16);
  195. /*
  196.  * Set the Length parameter
  197.  */
  198. output_struct->length = struct_size;
  199. /*
  200.  * Return the final size of the structure
  201.  */
  202. *structure_size = struct_size;
  203. return_ACPI_STATUS (AE_OK);
  204. }
  205. /*******************************************************************************
  206.  *
  207.  * FUNCTION:    Acpi_rs_vendor_stream
  208.  *
  209.  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
  210.  *              Output_buffer           - Pointer to the user's return buffer
  211.  *              Bytes_consumed          - u32 pointer that is filled with
  212.  *                                        the number of bytes of the
  213.  *                                        Output_buffer used
  214.  *
  215.  * RETURN:      Status
  216.  *
  217.  * DESCRIPTION: Take the linked list resource structure and fills in the
  218.  *              the appropriate bytes in a byte stream
  219.  *
  220.  ******************************************************************************/
  221. acpi_status
  222. acpi_rs_vendor_stream (
  223. acpi_resource           *linked_list,
  224. u8                      **output_buffer,
  225. u32                     *bytes_consumed)
  226. {
  227. u8                      *buffer = *output_buffer;
  228. u16                     temp16 = 0;
  229. u8                      temp8 = 0;
  230. u8                      index;
  231. FUNCTION_TRACE ("Rs_vendor_stream");
  232. /*
  233.  * Dereference the length to find if this is a large or small item.
  234.  */
  235. if(linked_list->data.vendor_specific.length > 7) {
  236. /*
  237.  * Large Item
  238.  * Set the descriptor field and length bytes
  239.  */
  240. *buffer = 0x84;
  241. buffer += 1;
  242. temp16 = (u16) linked_list->data.vendor_specific.length;
  243. MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
  244. buffer += 2;
  245. }
  246. else {
  247. /*
  248.  * Small Item
  249.  * Set the descriptor field
  250.  */
  251. temp8 = 0x70;
  252. temp8 |= linked_list->data.vendor_specific.length;
  253. *buffer = temp8;
  254. buffer += 1;
  255. }
  256. /*
  257.  * Loop through all of the Vendor Specific fields
  258.  */
  259. for (index = 0; index < linked_list->data.vendor_specific.length; index++) {
  260. temp8 = linked_list->data.vendor_specific.reserved[index];
  261. *buffer = temp8;
  262. buffer += 1;
  263. }
  264. /*
  265.  * Return the number of bytes consumed in this operation
  266.  */
  267. *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
  268. return_ACPI_STATUS (AE_OK);
  269. }
  270. /*******************************************************************************
  271.  *
  272.  * FUNCTION:    Acpi_rs_start_dependent_functions_resource
  273.  *
  274.  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
  275.  *                                        stream
  276.  *              Bytes_consumed          - u32 pointer that is filled with
  277.  *                                        the number of bytes consumed from
  278.  *                                        the Byte_stream_buffer
  279.  *              Output_buffer           - Pointer to the user's return buffer
  280.  *              Structure_size          - u32 pointer that is filled with
  281.  *                                        the number of bytes in the filled
  282.  *                                        in structure
  283.  *
  284.  * RETURN:      Status
  285.  *
  286.  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  287.  *              structure pointed to by the Output_buffer. Return the
  288.  *              number of bytes consumed from the byte stream.
  289.  *
  290.  ******************************************************************************/
  291. acpi_status
  292. acpi_rs_start_dependent_functions_resource (
  293. u8                      *byte_stream_buffer,
  294. u32                     *bytes_consumed,
  295. u8                      **output_buffer,
  296. u32                     *structure_size)
  297. {
  298. u8                      *buffer = byte_stream_buffer;
  299. acpi_resource          *output_struct = (acpi_resource *) *output_buffer;
  300. u8                      temp8 = 0;
  301. u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_start_dpf);
  302. FUNCTION_TRACE ("Rs_start_dependent_functions_resource");
  303. /*
  304.  * The number of bytes consumed are contained in the descriptor (Bits:0-1)
  305.  */
  306. temp8 = *buffer;
  307. *bytes_consumed = (temp8 & 0x01) + 1;
  308. output_struct->id = ACPI_RSTYPE_START_DPF;
  309. /*
  310.  * Point to Byte 1 if it is used
  311.  */
  312. if (2 == *bytes_consumed) {
  313. buffer += 1;
  314. temp8 = *buffer;
  315. /*
  316.  * Check Compatibility priority
  317.  */
  318. output_struct->data.start_dpf.compatibility_priority = temp8 & 0x03;
  319. if (3 == output_struct->data.start_dpf.compatibility_priority) {
  320. return_ACPI_STATUS (AE_AML_ERROR);
  321. }
  322. /*
  323.  * Check Performance/Robustness preference
  324.  */
  325. output_struct->data.start_dpf.performance_robustness = (temp8 >> 2) & 0x03;
  326. if (3 == output_struct->data.start_dpf.performance_robustness) {
  327. return_ACPI_STATUS (AE_AML_ERROR);
  328. }
  329. }
  330. else {
  331. output_struct->data.start_dpf.compatibility_priority =
  332. ACCEPTABLE_CONFIGURATION;
  333. output_struct->data.start_dpf.performance_robustness =
  334. ACCEPTABLE_CONFIGURATION;
  335. }
  336. /*
  337.  * Set the Length parameter
  338.  */
  339. output_struct->length = struct_size;
  340. /*
  341.  * Return the final size of the structure
  342.  */
  343. *structure_size = struct_size;
  344. return_ACPI_STATUS (AE_OK);
  345. }
  346. /*******************************************************************************
  347.  *
  348.  * FUNCTION:    Acpi_rs_end_dependent_functions_resource
  349.  *
  350.  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
  351.  *                                        stream
  352.  *              Bytes_consumed          - u32 pointer that is filled with
  353.  *                                        the number of bytes consumed from
  354.  *                                        the Byte_stream_buffer
  355.  *              Output_buffer           - Pointer to the user's return buffer
  356.  *              Structure_size          - u32 pointer that is filled with
  357.  *                                        the number of bytes in the filled
  358.  *                                        in structure
  359.  *
  360.  * RETURN:      Status
  361.  *
  362.  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  363.  *              structure pointed to by the Output_buffer. Return the
  364.  *              number of bytes consumed from the byte stream.
  365.  *
  366.  ******************************************************************************/
  367. acpi_status
  368. acpi_rs_end_dependent_functions_resource (
  369. u8                      *byte_stream_buffer,
  370. u32                     *bytes_consumed,
  371. u8                      **output_buffer,
  372. u32                     *structure_size)
  373. {
  374. acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
  375. u32                     struct_size = ACPI_RESOURCE_LENGTH;
  376. FUNCTION_TRACE ("Rs_end_dependent_functions_resource");
  377. /*
  378.  * The number of bytes consumed is static
  379.  */
  380. *bytes_consumed = 1;
  381. /*
  382.  *  Fill out the structure
  383.  */
  384. output_struct->id = ACPI_RSTYPE_END_DPF;
  385. /*
  386.  * Set the Length parameter
  387.  */
  388. output_struct->length = struct_size;
  389. /*
  390.  * Return the final size of the structure
  391.  */
  392. *structure_size = struct_size;
  393. return_ACPI_STATUS (AE_OK);
  394. }
  395. /*******************************************************************************
  396.  *
  397.  * FUNCTION:    Acpi_rs_start_dependent_functions_stream
  398.  *
  399.  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
  400.  *              Output_buffer           - Pointer to the user's return buffer
  401.  *              Bytes_consumed          - u32 pointer that is filled with
  402.  *                                        the number of bytes of the
  403.  *                                        Output_buffer used
  404.  *
  405.  * RETURN:      Status
  406.  *
  407.  * DESCRIPTION: Take the linked list resource structure and fills in the
  408.  *              the appropriate bytes in a byte stream
  409.  *
  410.  ******************************************************************************/
  411. acpi_status
  412. acpi_rs_start_dependent_functions_stream (
  413. acpi_resource           *linked_list,
  414. u8                      **output_buffer,
  415. u32                     *bytes_consumed)
  416. {
  417. u8                      *buffer = *output_buffer;
  418. u8                      temp8 = 0;
  419. FUNCTION_TRACE ("Rs_start_dependent_functions_stream");
  420. /*
  421.  * The descriptor field is set based upon whether a byte is needed
  422.  * to contain Priority data.
  423.  */
  424. if (ACCEPTABLE_CONFIGURATION ==
  425. linked_list->data.start_dpf.compatibility_priority &&
  426. ACCEPTABLE_CONFIGURATION ==
  427. linked_list->data.start_dpf.performance_robustness) {
  428. *buffer = 0x30;
  429. }
  430. else {
  431. *buffer = 0x31;
  432. buffer += 1;
  433. /*
  434.  * Set the Priority Byte Definition
  435.  */
  436. temp8 = 0;
  437. temp8 = (u8) ((linked_list->data.start_dpf.performance_robustness &
  438.    0x03) << 2);
  439. temp8 |= (linked_list->data.start_dpf.compatibility_priority &
  440.    0x03);
  441. *buffer = temp8;
  442. }
  443. buffer += 1;
  444. /*
  445.  * Return the number of bytes consumed in this operation
  446.  */
  447. *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
  448. return_ACPI_STATUS (AE_OK);
  449. }
  450. /*******************************************************************************
  451.  *
  452.  * FUNCTION:    Acpi_rs_end_dependent_functions_stream
  453.  *
  454.  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
  455.  *              Output_buffer           - Pointer to the user's return buffer
  456.  *              Bytes_consumed          - u32 pointer that is filled with
  457.  *                                        the number of bytes of the
  458.  *                                        Output_buffer used
  459.  *
  460.  * RETURN:      Status
  461.  *
  462.  * DESCRIPTION: Take the linked list resource structure and fills in the
  463.  *              the appropriate bytes in a byte stream
  464.  *
  465.  ******************************************************************************/
  466. acpi_status
  467. acpi_rs_end_dependent_functions_stream (
  468. acpi_resource           *linked_list,
  469. u8                      **output_buffer,
  470. u32                     *bytes_consumed
  471. )
  472. {
  473. u8                      *buffer = *output_buffer;
  474. FUNCTION_TRACE ("Rs_end_dependent_functions_stream");
  475. /*
  476.  * The descriptor field is static
  477.  */
  478. *buffer = 0x38;
  479. buffer += 1;
  480. /*
  481.  * Return the number of bytes consumed in this operation
  482.  */
  483. *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
  484. return_ACPI_STATUS (AE_OK);
  485. }