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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*******************************************************************************
  2.  *
  3.  * Module Name: rsmem24 - Memory 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         ("rsmemory")
  28. /*******************************************************************************
  29.  *
  30.  * FUNCTION:    Acpi_rs_memory24_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_memory24_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_mem24);
  61. FUNCTION_TRACE ("Rs_memory24_resource");
  62. /*
  63.  * Point past the Descriptor to get the number of bytes consumed
  64.  */
  65. buffer += 1;
  66. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  67. buffer += 2;
  68. *bytes_consumed = temp16 + 3;
  69. output_struct->id = ACPI_RSTYPE_MEM24;
  70. /*
  71.  * Check Byte 3 the Read/Write bit
  72.  */
  73. temp8 = *buffer;
  74. buffer += 1;
  75. output_struct->data.memory24.read_write_attribute = temp8 & 0x01;
  76. /*
  77.  * Get Min_base_address (Bytes 4-5)
  78.  */
  79. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  80. buffer += 2;
  81. output_struct->data.memory24.min_base_address = temp16;
  82. /*
  83.  * Get Max_base_address (Bytes 6-7)
  84.  */
  85. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  86. buffer += 2;
  87. output_struct->data.memory24.max_base_address = temp16;
  88. /*
  89.  * Get Alignment (Bytes 8-9)
  90.  */
  91. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  92. buffer += 2;
  93. output_struct->data.memory24.alignment = temp16;
  94. /*
  95.  * Get Range_length (Bytes 10-11)
  96.  */
  97. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  98. output_struct->data.memory24.range_length = temp16;
  99. /*
  100.  * Set the Length parameter
  101.  */
  102. output_struct->length = struct_size;
  103. /*
  104.  * Return the final size of the structure
  105.  */
  106. *structure_size = struct_size;
  107. return_ACPI_STATUS (AE_OK);
  108. }
  109. /*******************************************************************************
  110.  *
  111.  * FUNCTION:    Acpi_rs_memory24_stream
  112.  *
  113.  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
  114.  *              Output_buffer           - Pointer to the user's return buffer
  115.  *              Bytes_consumed          - u32 pointer that is filled with
  116.  *                                        the number of bytes of the
  117.  *                                        Output_buffer used
  118.  *
  119.  * RETURN:      Status
  120.  *
  121.  * DESCRIPTION: Take the linked list resource structure and fills in the
  122.  *              the appropriate bytes in a byte stream
  123.  *
  124.  ******************************************************************************/
  125. acpi_status
  126. acpi_rs_memory24_stream (
  127. acpi_resource           *linked_list,
  128. u8                      **output_buffer,
  129. u32                     *bytes_consumed)
  130. {
  131. u8                      *buffer = *output_buffer;
  132. u16                     temp16 = 0;
  133. u8                      temp8 = 0;
  134. FUNCTION_TRACE ("Rs_memory24_stream");
  135. /*
  136.  * The descriptor field is static
  137.  */
  138. *buffer = 0x81;
  139. buffer += 1;
  140. /*
  141.  * The length field is static
  142.  */
  143. temp16 = 0x09;
  144. MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
  145. buffer += 2;
  146. /*
  147.  * Set the Information Byte
  148.  */
  149. temp8 = (u8) (linked_list->data.memory24.read_write_attribute & 0x01);
  150. *buffer = temp8;
  151. buffer += 1;
  152. /*
  153.  * Set the Range minimum base address
  154.  */
  155. MOVE_UNALIGNED16_TO_16 (buffer, &linked_list->data.memory24.min_base_address);
  156. buffer += 2;
  157. /*
  158.  * Set the Range maximum base address
  159.  */
  160. MOVE_UNALIGNED16_TO_16 (buffer, &linked_list->data.memory24.max_base_address);
  161. buffer += 2;
  162. /*
  163.  * Set the base alignment
  164.  */
  165. MOVE_UNALIGNED16_TO_16 (buffer, &linked_list->data.memory24.alignment);
  166. buffer += 2;
  167. /*
  168.  * Set the range length
  169.  */
  170. MOVE_UNALIGNED16_TO_16 (buffer, &linked_list->data.memory24.range_length);
  171. buffer += 2;
  172. /*
  173.  * Return the number of bytes consumed in this operation
  174.  */
  175. *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
  176. return_ACPI_STATUS (AE_OK);
  177. }
  178. /*******************************************************************************
  179.  *
  180.  * FUNCTION:    Acpi_rs_memory32_range_resource
  181.  *
  182.  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
  183.  *                                        stream
  184.  *              Bytes_consumed          - u32 pointer that is filled with
  185.  *                                        the number of bytes consumed from
  186.  *                                        the Byte_stream_buffer
  187.  *              Output_buffer           - Pointer to the user's return buffer
  188.  *              Structure_size          - u32 pointer that is filled with
  189.  *                                        the number of bytes in the filled
  190.  *                                        in structure
  191.  *
  192.  * RETURN:      Status
  193.  *
  194.  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  195.  *              structure pointed to by the Output_buffer. Return the
  196.  *              number of bytes consumed from the byte stream.
  197.  *
  198.  ******************************************************************************/
  199. acpi_status
  200. acpi_rs_memory32_range_resource (
  201. u8                      *byte_stream_buffer,
  202. u32                     *bytes_consumed,
  203. u8                      **output_buffer,
  204. u32                     *structure_size)
  205. {
  206. u8                      *buffer = byte_stream_buffer;
  207. acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
  208. u16                     temp16 = 0;
  209. u8                      temp8 = 0;
  210. u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_mem32);
  211. FUNCTION_TRACE ("Rs_memory32_range_resource");
  212. /*
  213.  * Point past the Descriptor to get the number of bytes consumed
  214.  */
  215. buffer += 1;
  216. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  217. buffer += 2;
  218. *bytes_consumed = temp16 + 3;
  219. output_struct->id = ACPI_RSTYPE_MEM32;
  220. /*
  221.  *  Point to the place in the output buffer where the data portion will
  222.  *  begin.
  223.  *  1. Set the RESOURCE_DATA * Data to point to it's own address, then
  224.  *  2. Set the pointer to the next address.
  225.  *
  226.  *  NOTE: Output_struct->Data is cast to u8, otherwise, this addition adds
  227.  *  4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
  228.  */
  229. /*
  230.  * Check Byte 3 the Read/Write bit
  231.  */
  232. temp8 = *buffer;
  233. buffer += 1;
  234. output_struct->data.memory32.read_write_attribute = temp8 & 0x01;
  235. /*
  236.  * Get Min_base_address (Bytes 4-7)
  237.  */
  238. MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.min_base_address,
  239.  buffer);
  240. buffer += 4;
  241. /*
  242.  * Get Max_base_address (Bytes 8-11)
  243.  */
  244. MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.max_base_address,
  245.  buffer);
  246. buffer += 4;
  247. /*
  248.  * Get Alignment (Bytes 12-15)
  249.  */
  250. MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.alignment, buffer);
  251. buffer += 4;
  252. /*
  253.  * Get Range_length (Bytes 16-19)
  254.  */
  255. MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.range_length, buffer);
  256. /*
  257.  * Set the Length parameter
  258.  */
  259. output_struct->length = struct_size;
  260. /*
  261.  * Return the final size of the structure
  262.  */
  263. *structure_size = struct_size;
  264. return_ACPI_STATUS (AE_OK);
  265. }
  266. /*******************************************************************************
  267.  *
  268.  * FUNCTION:    Acpi_rs_fixed_memory32_resource
  269.  *
  270.  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
  271.  *                                        stream
  272.  *              Bytes_consumed          - u32 pointer that is filled with
  273.  *                                        the number of bytes consumed from
  274.  *                                        the Byte_stream_buffer
  275.  *              Output_buffer           - Pointer to the user's return buffer
  276.  *              Structure_size          - u32 pointer that is filled with
  277.  *                                        the number of bytes in the filled
  278.  *                                        in structure
  279.  *
  280.  * RETURN:      Status
  281.  *
  282.  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  283.  *              structure pointed to by the Output_buffer. Return the
  284.  *              number of bytes consumed from the byte stream.
  285.  *
  286.  ******************************************************************************/
  287. acpi_status
  288. acpi_rs_fixed_memory32_resource (
  289. u8                      *byte_stream_buffer,
  290. u32                     *bytes_consumed,
  291. u8                      **output_buffer,
  292. u32                     *structure_size)
  293. {
  294. u8                      *buffer = byte_stream_buffer;
  295. acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
  296. u16                     temp16 = 0;
  297. u8                      temp8 = 0;
  298. u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_fixed_mem32);
  299. FUNCTION_TRACE ("Rs_fixed_memory32_resource");
  300. /*
  301.  * Point past the Descriptor to get the number of bytes consumed
  302.  */
  303. buffer += 1;
  304. MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
  305. buffer += 2;
  306. *bytes_consumed = temp16 + 3;
  307. output_struct->id = ACPI_RSTYPE_FIXED_MEM32;
  308. /*
  309.  * Check Byte 3 the Read/Write bit
  310.  */
  311. temp8 = *buffer;
  312. buffer += 1;
  313. output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01;
  314. /*
  315.  * Get Range_base_address (Bytes 4-7)
  316.  */
  317. MOVE_UNALIGNED32_TO_32 (&output_struct->data.fixed_memory32.range_base_address,
  318.  buffer);
  319. buffer += 4;
  320. /*
  321.  * Get Range_length (Bytes 8-11)
  322.  */
  323. MOVE_UNALIGNED32_TO_32 (&output_struct->data.fixed_memory32.range_length,
  324.  buffer);
  325. /*
  326.  * Set the Length parameter
  327.  */
  328. output_struct->length = struct_size;
  329. /*
  330.  * Return the final size of the structure
  331.  */
  332. *structure_size = struct_size;
  333. return_ACPI_STATUS (AE_OK);
  334. }
  335. /*******************************************************************************
  336.  *
  337.  * FUNCTION:    Acpi_rs_memory32_range_stream
  338.  *
  339.  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
  340.  *              Output_buffer           - Pointer to the user's return buffer
  341.  *              Bytes_consumed          - u32 pointer that is filled with
  342.  *                                        the number of bytes of the
  343.  *                                        Output_buffer used
  344.  *
  345.  * RETURN:      Status
  346.  *
  347.  * DESCRIPTION: Take the linked list resource structure and fills in the
  348.  *              the appropriate bytes in a byte stream
  349.  *
  350.  ******************************************************************************/
  351. acpi_status
  352. acpi_rs_memory32_range_stream (
  353. acpi_resource           *linked_list,
  354. u8                      **output_buffer,
  355. u32                     *bytes_consumed)
  356. {
  357. u8                      *buffer = *output_buffer;
  358. u16                     temp16 = 0;
  359. u8                      temp8 = 0;
  360. FUNCTION_TRACE ("Rs_memory32_range_stream");
  361. /*
  362.  * The descriptor field is static
  363.  */
  364. *buffer = 0x85;
  365. buffer += 1;
  366. /*
  367.  * The length field is static
  368.  */
  369. temp16 = 0x11;
  370. MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
  371. buffer += 2;
  372. /*
  373.  * Set the Information Byte
  374.  */
  375. temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01);
  376. *buffer = temp8;
  377. buffer += 1;
  378. /*
  379.  * Set the Range minimum base address
  380.  */
  381. MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.min_base_address);
  382. buffer += 4;
  383. /*
  384.  * Set the Range maximum base address
  385.  */
  386. MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.max_base_address);
  387. buffer += 4;
  388. /*
  389.  * Set the base alignment
  390.  */
  391. MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.alignment);
  392. buffer += 4;
  393. /*
  394.  * Set the range length
  395.  */
  396. MOVE_UNALIGNED32_TO_32 (buffer, &linked_list->data.memory32.range_length);
  397. buffer += 4;
  398. /*
  399.  * Return the number of bytes consumed in this operation
  400.  */
  401. *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
  402. return_ACPI_STATUS (AE_OK);
  403. }
  404. /*******************************************************************************
  405.  *
  406.  * FUNCTION:    Acpi_rs_fixed_memory32_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          - u32 pointer that is filled with
  411.  *                                        the number of bytes of the
  412.  *                                        Output_buffer used
  413.  *
  414.  * RETURN:      Status
  415.  *
  416.  * DESCRIPTION: Take the linked list resource structure and fills in the
  417.  *              the appropriate bytes in a byte stream
  418.  *
  419.  ******************************************************************************/
  420. acpi_status
  421. acpi_rs_fixed_memory32_stream (
  422. acpi_resource           *linked_list,
  423. u8                      **output_buffer,
  424. u32                     *bytes_consumed)
  425. {
  426. u8                      *buffer = *output_buffer;
  427. u16                     temp16 = 0;
  428. u8                      temp8 = 0;
  429. FUNCTION_TRACE ("Rs_fixed_memory32_stream");
  430. /*
  431.  * The descriptor field is static
  432.  */
  433. *buffer = 0x86;
  434. buffer += 1;
  435. /*
  436.  * The length field is static
  437.  */
  438. temp16 = 0x09;
  439. MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
  440. buffer += 2;
  441. /*
  442.  * Set the Information Byte
  443.  */
  444. temp8 = (u8) (linked_list->data.fixed_memory32.read_write_attribute & 0x01);
  445. *buffer = temp8;
  446. buffer += 1;
  447. /*
  448.  * Set the Range base address
  449.  */
  450. MOVE_UNALIGNED32_TO_32 (buffer,
  451.  &linked_list->data.fixed_memory32.range_base_address);
  452. buffer += 4;
  453. /*
  454.  * Set the range length
  455.  */
  456. MOVE_UNALIGNED32_TO_32 (buffer,
  457.  &linked_list->data.fixed_memory32.range_length);
  458. buffer += 4;
  459. /*
  460.  * Return the number of bytes consumed in this operation
  461.  */
  462. *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
  463. return_ACPI_STATUS (AE_OK);
  464. }