rsio.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:14k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*******************************************************************************
  2.  *
  3.  * Module Name: rsio - IO and DMA resource descriptors
  4.  *              $Revision: 14 $
  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         ("rsio")
  28. /*******************************************************************************
  29.  *
  30.  * FUNCTION:    Acpi_rs_io_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_io_resource (
  51. u8                      *byte_stream_buffer,
  52. u32                     *bytes_consumed,
  53. u8                      **output_buffer,
  54. u32                     *structure_size)
  55. {
  56. u8                      *buffer = byte_stream_buffer;
  57. acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
  58. u16                     temp16 = 0;
  59. u8                      temp8 = 0;
  60. u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_io);
  61. FUNCTION_TRACE ("Rs_io_resource");
  62. /*
  63.  * The number of bytes consumed are Constant
  64.  */
  65. *bytes_consumed = 8;
  66. output_struct->id = ACPI_RSTYPE_IO;
  67. /*
  68.  * Check Decode
  69.  */
  70. buffer += 1;
  71. temp8 = *buffer;
  72. output_struct->data.io.io_decode = temp8 & 0x01;
  73. /*
  74.  * Check Min_base Address
  75.  */
  76. buffer += 1;
  77. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  78. output_struct->data.io.min_base_address = temp16;
  79. /*
  80.  * Check Max_base Address
  81.  */
  82. buffer += 2;
  83. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  84. output_struct->data.io.max_base_address = temp16;
  85. /*
  86.  * Check Base alignment
  87.  */
  88. buffer += 2;
  89. temp8 = *buffer;
  90. output_struct->data.io.alignment = temp8;
  91. /*
  92.  * Check Range_length
  93.  */
  94. buffer += 1;
  95. temp8 = *buffer;
  96. output_struct->data.io.range_length = temp8;
  97. /*
  98.  * Set the Length parameter
  99.  */
  100. output_struct->length = struct_size;
  101. /*
  102.  * Return the final size of the structure
  103.  */
  104. *structure_size = struct_size;
  105. return_ACPI_STATUS (AE_OK);
  106. }
  107. /*******************************************************************************
  108.  *
  109.  * FUNCTION:    Acpi_rs_fixed_io_resource
  110.  *
  111.  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
  112.  *                                        stream
  113.  *              Bytes_consumed          - u32 pointer that is filled with
  114.  *                                        the number of bytes consumed from
  115.  *                                        the Byte_stream_buffer
  116.  *              Output_buffer           - Pointer to the user's return buffer
  117.  *              Structure_size          - u32 pointer that is filled with
  118.  *                                        the number of bytes in the filled
  119.  *                                        in structure
  120.  *
  121.  * RETURN:      Status
  122.  *
  123.  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  124.  *              structure pointed to by the Output_buffer. Return the
  125.  *              number of bytes consumed from the byte stream.
  126.  *
  127.  ******************************************************************************/
  128. acpi_status
  129. acpi_rs_fixed_io_resource (
  130. u8                      *byte_stream_buffer,
  131. u32                     *bytes_consumed,
  132. u8                      **output_buffer,
  133. u32                     *structure_size)
  134. {
  135. u8                      *buffer = byte_stream_buffer;
  136. acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
  137. u16                     temp16 = 0;
  138. u8                      temp8 = 0;
  139. u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_fixed_io);
  140. FUNCTION_TRACE ("Rs_fixed_io_resource");
  141. /*
  142.  * The number of bytes consumed are Constant
  143.  */
  144. *bytes_consumed = 4;
  145. output_struct->id = ACPI_RSTYPE_FIXED_IO;
  146. /*
  147.  * Check Range Base Address
  148.  */
  149. buffer += 1;
  150. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  151. output_struct->data.fixed_io.base_address = temp16;
  152. /*
  153.  * Check Range_length
  154.  */
  155. buffer += 2;
  156. temp8 = *buffer;
  157. output_struct->data.fixed_io.range_length = temp8;
  158. /*
  159.  * Set the Length parameter
  160.  */
  161. output_struct->length = struct_size;
  162. /*
  163.  * Return the final size of the structure
  164.  */
  165. *structure_size = struct_size;
  166. return_ACPI_STATUS (AE_OK);
  167. }
  168. /*******************************************************************************
  169.  *
  170.  * FUNCTION:    Acpi_rs_io_stream
  171.  *
  172.  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
  173.  *              Output_buffer           - Pointer to the user's return buffer
  174.  *              Bytes_consumed          - u32 pointer that is filled with
  175.  *                                        the number of bytes of the
  176.  *                                        Output_buffer used
  177.  *
  178.  * RETURN:      Status
  179.  *
  180.  * DESCRIPTION: Take the linked list resource structure and fills in the
  181.  *              the appropriate bytes in a byte stream
  182.  *
  183.  ******************************************************************************/
  184. acpi_status
  185. acpi_rs_io_stream (
  186. acpi_resource           *linked_list,
  187. u8                      **output_buffer,
  188. u32                     *bytes_consumed)
  189. {
  190. u8                      *buffer = *output_buffer;
  191. u16                     temp16 = 0;
  192. u8                      temp8 = 0;
  193. FUNCTION_TRACE ("Rs_io_stream");
  194. /*
  195.  * The descriptor field is static
  196.  */
  197. *buffer = 0x47;
  198. buffer += 1;
  199. /*
  200.  * Io Information Byte
  201.  */
  202. temp8 = (u8) (linked_list->data.io.io_decode & 0x01);
  203. *buffer = temp8;
  204. buffer += 1;
  205. /*
  206.  * Set the Range minimum base address
  207.  */
  208. temp16 = (u16) linked_list->data.io.min_base_address;
  209. MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
  210. buffer += 2;
  211. /*
  212.  * Set the Range maximum base address
  213.  */
  214. temp16 = (u16) linked_list->data.io.max_base_address;
  215. MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
  216. buffer += 2;
  217. /*
  218.  * Set the base alignment
  219.  */
  220. temp8 = (u8) linked_list->data.io.alignment;
  221. *buffer = temp8;
  222. buffer += 1;
  223. /*
  224.  * Set the range length
  225.  */
  226. temp8 = (u8) linked_list->data.io.range_length;
  227. *buffer = temp8;
  228. buffer += 1;
  229. /*
  230.  * Return the number of bytes consumed in this operation
  231.  */
  232. *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
  233. return_ACPI_STATUS (AE_OK);
  234. }
  235. /*******************************************************************************
  236.  *
  237.  * FUNCTION:    Acpi_rs_fixed_io_stream
  238.  *
  239.  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
  240.  *              Output_buffer           - Pointer to the user's return buffer
  241.  *              Bytes_consumed          - u32 pointer that is filled with
  242.  *                                        the number of bytes of the
  243.  *                                        Output_buffer used
  244.  *
  245.  * RETURN:      Status
  246.  *
  247.  * DESCRIPTION: Take the linked list resource structure and fills in the
  248.  *              the appropriate bytes in a byte stream
  249.  *
  250.  ******************************************************************************/
  251. acpi_status
  252. acpi_rs_fixed_io_stream (
  253. acpi_resource           *linked_list,
  254. u8                      **output_buffer,
  255. u32                     *bytes_consumed)
  256. {
  257. u8                      *buffer = *output_buffer;
  258. u16                     temp16 = 0;
  259. u8                      temp8 = 0;
  260. FUNCTION_TRACE ("Rs_fixed_io_stream");
  261. /*
  262.  * The descriptor field is static
  263.  */
  264. *buffer = 0x4B;
  265. buffer += 1;
  266. /*
  267.  * Set the Range base address
  268.  */
  269. temp16 = (u16) linked_list->data.fixed_io.base_address;
  270. MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
  271. buffer += 2;
  272. /*
  273.  * Set the range length
  274.  */
  275. temp8 = (u8) linked_list->data.fixed_io.range_length;
  276. *buffer = temp8;
  277. buffer += 1;
  278. /*
  279.  * Return the number of bytes consumed in this operation
  280.  */
  281. *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
  282. return_ACPI_STATUS (AE_OK);
  283. }
  284. /*******************************************************************************
  285.  *
  286.  * FUNCTION:    Acpi_rs_dma_resource
  287.  *
  288.  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
  289.  *                                        stream
  290.  *              Bytes_consumed          - u32 pointer that is filled with
  291.  *                                        the number of bytes consumed from
  292.  *                                        the Byte_stream_buffer
  293.  *              Output_buffer           - Pointer to the user's return buffer
  294.  *              Structure_size          - u32 pointer that is filled with
  295.  *                                        the number of bytes in the filled
  296.  *                                        in structure
  297.  *
  298.  * RETURN:      Status
  299.  *
  300.  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  301.  *              structure pointed to by the Output_buffer. Return the
  302.  *              number of bytes consumed from the byte stream.
  303.  *
  304.  ******************************************************************************/
  305. acpi_status
  306. acpi_rs_dma_resource (
  307. u8                      *byte_stream_buffer,
  308. u32                     *bytes_consumed,
  309. u8                      **output_buffer,
  310. u32                     *structure_size)
  311. {
  312. u8                      *buffer = byte_stream_buffer;
  313. acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
  314. u8                      temp8 = 0;
  315. u8                      index;
  316. u8                      i;
  317. u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_dma);
  318. FUNCTION_TRACE ("Rs_dma_resource");
  319. /*
  320.  * The number of bytes consumed are Constant
  321.  */
  322. *bytes_consumed = 3;
  323. output_struct->id = ACPI_RSTYPE_DMA;
  324. /*
  325.  * Point to the 8-bits of Byte 1
  326.  */
  327. buffer += 1;
  328. temp8 = *buffer;
  329. /* Decode the IRQ bits */
  330. for (i = 0, index = 0; index < 8; index++) {
  331. if ((temp8 >> index) & 0x01) {
  332. output_struct->data.dma.channels[i] = index;
  333. i++;
  334. }
  335. }
  336. output_struct->data.dma.number_of_channels = i;
  337. /*
  338.  * Calculate the structure size based upon the number of interrupts
  339.  */
  340. struct_size += (output_struct->data.dma.number_of_channels - 1) * 4;
  341. /*
  342.  * Point to Byte 2
  343.  */
  344. buffer += 1;
  345. temp8 = *buffer;
  346. /*
  347.  * Check for transfer preference (Bits[1:0])
  348.  */
  349. output_struct->data.dma.transfer = temp8 & 0x03;
  350. if (0x03 == output_struct->data.dma.transfer) {
  351. return_ACPI_STATUS (AE_BAD_DATA);
  352. }
  353. /*
  354.  * Get bus master preference (Bit[2])
  355.  */
  356. output_struct->data.dma.bus_master = (temp8 >> 2) & 0x01;
  357. /*
  358.  * Get channel speed support (Bits[6:5])
  359.  */
  360. output_struct->data.dma.type = (temp8 >> 5) & 0x03;
  361. /*
  362.  * Set the Length parameter
  363.  */
  364. output_struct->length = struct_size;
  365. /*
  366.  * Return the final size of the structure
  367.  */
  368. *structure_size = struct_size;
  369. return_ACPI_STATUS (AE_OK);
  370. }
  371. /*******************************************************************************
  372.  *
  373.  * FUNCTION:    Acpi_rs_dma_stream
  374.  *
  375.  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
  376.  *              Output_buffer           - Pointer to the user's return buffer
  377.  *              Bytes_consumed          - u32 pointer that is filled with
  378.  *                                        the number of bytes of the
  379.  *                                        Output_buffer used
  380.  *
  381.  * RETURN:      Status
  382.  *
  383.  * DESCRIPTION: Take the linked list resource structure and fills in the
  384.  *              the appropriate bytes in a byte stream
  385.  *
  386.  ******************************************************************************/
  387. acpi_status
  388. acpi_rs_dma_stream (
  389. acpi_resource           *linked_list,
  390. u8                      **output_buffer,
  391. u32                     *bytes_consumed)
  392. {
  393. u8                      *buffer = *output_buffer;
  394. u16                     temp16 = 0;
  395. u8                      temp8 = 0;
  396. u8                      index;
  397. FUNCTION_TRACE ("Rs_dma_stream");
  398. /*
  399.  * The descriptor field is static
  400.  */
  401. *buffer = 0x2A;
  402. buffer += 1;
  403. temp8 = 0;
  404. /*
  405.  * Loop through all of the Channels and set the mask bits
  406.  */
  407. for (index = 0;
  408.  index < linked_list->data.dma.number_of_channels;
  409.  index++) {
  410. temp16 = (u16) linked_list->data.dma.channels[index];
  411. temp8 |= 0x1 << temp16;
  412. }
  413. *buffer = temp8;
  414. buffer += 1;
  415. /*
  416.  * Set the DMA Info
  417.  */
  418. temp8 = (u8) ((linked_list->data.dma.type & 0x03) << 5);
  419. temp8 |= ((linked_list->data.dma.bus_master & 0x01) << 2);
  420. temp8 |= (linked_list->data.dma.transfer & 0x03);
  421. *buffer = temp8;
  422. buffer += 1;
  423. /*
  424.  * Return the number of bytes consumed in this operation
  425.  */
  426. *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
  427. return_ACPI_STATUS (AE_OK);
  428. }