rsio.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsio - IO and DMA 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("rsio")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_rs_io_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_io_resource(u8 * byte_stream_buffer,
  68. acpi_size * bytes_consumed,
  69. u8 ** output_buffer, acpi_size * structure_size)
  70. {
  71. u8 *buffer = byte_stream_buffer;
  72. struct acpi_resource *output_struct = (void *)*output_buffer;
  73. u16 temp16 = 0;
  74. u8 temp8 = 0;
  75. acpi_size struct_size = ACPI_SIZEOF_RESOURCE(struct acpi_resource_io);
  76. ACPI_FUNCTION_TRACE("rs_io_resource");
  77. /* The number of bytes consumed are Constant */
  78. *bytes_consumed = 8;
  79. output_struct->id = ACPI_RSTYPE_IO;
  80. /* Check Decode */
  81. buffer += 1;
  82. temp8 = *buffer;
  83. output_struct->data.io.io_decode = temp8 & 0x01;
  84. /* Check min_base Address */
  85. buffer += 1;
  86. ACPI_MOVE_16_TO_16(&temp16, buffer);
  87. output_struct->data.io.min_base_address = temp16;
  88. /* Check max_base Address */
  89. buffer += 2;
  90. ACPI_MOVE_16_TO_16(&temp16, buffer);
  91. output_struct->data.io.max_base_address = temp16;
  92. /* Check Base alignment */
  93. buffer += 2;
  94. temp8 = *buffer;
  95. output_struct->data.io.alignment = temp8;
  96. /* Check range_length */
  97. buffer += 1;
  98. temp8 = *buffer;
  99. output_struct->data.io.range_length = temp8;
  100. /* Set the Length parameter */
  101. output_struct->length = (u32) struct_size;
  102. /* Return the final size of the structure */
  103. *structure_size = struct_size;
  104. return_ACPI_STATUS(AE_OK);
  105. }
  106. /*******************************************************************************
  107. *
  108. * FUNCTION: acpi_rs_fixed_io_resource
  109. *
  110. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  111. * stream
  112. * bytes_consumed - Pointer to where the number of bytes
  113. * consumed the byte_stream_buffer is
  114. * returned
  115. * output_buffer - Pointer to the return data buffer
  116. * structure_size - Pointer to where the number of bytes
  117. * in the return data struct is returned
  118. *
  119. * RETURN: Status
  120. *
  121. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  122. * structure pointed to by the output_buffer. Return the
  123. * number of bytes consumed from the byte stream.
  124. *
  125. ******************************************************************************/
  126. acpi_status
  127. acpi_rs_fixed_io_resource(u8 * byte_stream_buffer,
  128. acpi_size * bytes_consumed,
  129. u8 ** output_buffer, acpi_size * structure_size)
  130. {
  131. u8 *buffer = byte_stream_buffer;
  132. struct acpi_resource *output_struct = (void *)*output_buffer;
  133. u16 temp16 = 0;
  134. u8 temp8 = 0;
  135. acpi_size struct_size =
  136. ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io);
  137. ACPI_FUNCTION_TRACE("rs_fixed_io_resource");
  138. /* The number of bytes consumed are Constant */
  139. *bytes_consumed = 4;
  140. output_struct->id = ACPI_RSTYPE_FIXED_IO;
  141. /* Check Range Base Address */
  142. buffer += 1;
  143. ACPI_MOVE_16_TO_16(&temp16, buffer);
  144. output_struct->data.fixed_io.base_address = temp16;
  145. /* Check range_length */
  146. buffer += 2;
  147. temp8 = *buffer;
  148. output_struct->data.fixed_io.range_length = temp8;
  149. /* Set the Length parameter */
  150. output_struct->length = (u32) struct_size;
  151. /* Return the final size of the structure */
  152. *structure_size = struct_size;
  153. return_ACPI_STATUS(AE_OK);
  154. }
  155. /*******************************************************************************
  156. *
  157. * FUNCTION: acpi_rs_io_stream
  158. *
  159. * PARAMETERS: linked_list - Pointer to the resource linked list
  160. * output_buffer - Pointer to the user's return buffer
  161. * bytes_consumed - Pointer to where the number of bytes
  162. * used in the output_buffer is returned
  163. *
  164. * RETURN: Status
  165. *
  166. * DESCRIPTION: Take the linked list resource structure and fills in the
  167. * the appropriate bytes in a byte stream
  168. *
  169. ******************************************************************************/
  170. acpi_status
  171. acpi_rs_io_stream(struct acpi_resource *linked_list,
  172. u8 ** output_buffer, acpi_size * bytes_consumed)
  173. {
  174. u8 *buffer = *output_buffer;
  175. u16 temp16 = 0;
  176. u8 temp8 = 0;
  177. ACPI_FUNCTION_TRACE("rs_io_stream");
  178. /* The descriptor field is static */
  179. *buffer = 0x47;
  180. buffer += 1;
  181. /* Io Information Byte */
  182. temp8 = (u8) (linked_list->data.io.io_decode & 0x01);
  183. *buffer = temp8;
  184. buffer += 1;
  185. /* Set the Range minimum base address */
  186. temp16 = (u16) linked_list->data.io.min_base_address;
  187. ACPI_MOVE_16_TO_16(buffer, &temp16);
  188. buffer += 2;
  189. /* Set the Range maximum base address */
  190. temp16 = (u16) linked_list->data.io.max_base_address;
  191. ACPI_MOVE_16_TO_16(buffer, &temp16);
  192. buffer += 2;
  193. /* Set the base alignment */
  194. temp8 = (u8) linked_list->data.io.alignment;
  195. *buffer = temp8;
  196. buffer += 1;
  197. /* Set the range length */
  198. temp8 = (u8) linked_list->data.io.range_length;
  199. *buffer = temp8;
  200. buffer += 1;
  201. /* Return the number of bytes consumed in this operation */
  202. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  203. return_ACPI_STATUS(AE_OK);
  204. }
  205. /*******************************************************************************
  206. *
  207. * FUNCTION: acpi_rs_fixed_io_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 - Pointer to where the number of bytes
  212. * used in the output_buffer is returned
  213. *
  214. * RETURN: Status
  215. *
  216. * DESCRIPTION: Take the linked list resource structure and fills in the
  217. * the appropriate bytes in a byte stream
  218. *
  219. ******************************************************************************/
  220. acpi_status
  221. acpi_rs_fixed_io_stream(struct acpi_resource *linked_list,
  222. u8 ** output_buffer, acpi_size * bytes_consumed)
  223. {
  224. u8 *buffer = *output_buffer;
  225. u16 temp16 = 0;
  226. u8 temp8 = 0;
  227. ACPI_FUNCTION_TRACE("rs_fixed_io_stream");
  228. /* The descriptor field is static */
  229. *buffer = 0x4B;
  230. buffer += 1;
  231. /* Set the Range base address */
  232. temp16 = (u16) linked_list->data.fixed_io.base_address;
  233. ACPI_MOVE_16_TO_16(buffer, &temp16);
  234. buffer += 2;
  235. /* Set the range length */
  236. temp8 = (u8) linked_list->data.fixed_io.range_length;
  237. *buffer = temp8;
  238. buffer += 1;
  239. /* Return the number of bytes consumed in this operation */
  240. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  241. return_ACPI_STATUS(AE_OK);
  242. }
  243. /*******************************************************************************
  244. *
  245. * FUNCTION: acpi_rs_dma_resource
  246. *
  247. * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
  248. * stream
  249. * bytes_consumed - Pointer to where the number of bytes
  250. * consumed the byte_stream_buffer is
  251. * returned
  252. * output_buffer - Pointer to the return data buffer
  253. * structure_size - Pointer to where the number of bytes
  254. * in the return data struct is returned
  255. *
  256. * RETURN: Status
  257. *
  258. * DESCRIPTION: Take the resource byte stream and fill out the appropriate
  259. * structure pointed to by the output_buffer. Return the
  260. * number of bytes consumed from the byte stream.
  261. *
  262. ******************************************************************************/
  263. acpi_status
  264. acpi_rs_dma_resource(u8 * byte_stream_buffer,
  265. acpi_size * bytes_consumed,
  266. u8 ** output_buffer, acpi_size * structure_size)
  267. {
  268. u8 *buffer = byte_stream_buffer;
  269. struct acpi_resource *output_struct = (void *)*output_buffer;
  270. u8 temp8 = 0;
  271. u8 index;
  272. u8 i;
  273. acpi_size struct_size = ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma);
  274. ACPI_FUNCTION_TRACE("rs_dma_resource");
  275. /* The number of bytes consumed are Constant */
  276. *bytes_consumed = 3;
  277. output_struct->id = ACPI_RSTYPE_DMA;
  278. /* Point to the 8-bits of Byte 1 */
  279. buffer += 1;
  280. temp8 = *buffer;
  281. /* Decode the DMA channel bits */
  282. for (i = 0, index = 0; index < 8; index++) {
  283. if ((temp8 >> index) & 0x01) {
  284. output_struct->data.dma.channels[i] = index;
  285. i++;
  286. }
  287. }
  288. /* Zero DMA channels is valid */
  289. output_struct->data.dma.number_of_channels = i;
  290. if (i > 0) {
  291. /* Calculate the structure size based upon the number of interrupts */
  292. struct_size += ((acpi_size) i - 1) * 4;
  293. }
  294. /* Point to Byte 2 */
  295. buffer += 1;
  296. temp8 = *buffer;
  297. /* Check for transfer preference (Bits[1:0]) */
  298. output_struct->data.dma.transfer = temp8 & 0x03;
  299. if (0x03 == output_struct->data.dma.transfer) {
  300. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  301. "Invalid DMA.Transfer preference (3)\n"));
  302. return_ACPI_STATUS(AE_BAD_DATA);
  303. }
  304. /* Get bus master preference (Bit[2]) */
  305. output_struct->data.dma.bus_master = (temp8 >> 2) & 0x01;
  306. /* Get channel speed support (Bits[6:5]) */
  307. output_struct->data.dma.type = (temp8 >> 5) & 0x03;
  308. /* Set the Length parameter */
  309. output_struct->length = (u32) struct_size;
  310. /* Return the final size of the structure */
  311. *structure_size = struct_size;
  312. return_ACPI_STATUS(AE_OK);
  313. }
  314. /*******************************************************************************
  315. *
  316. * FUNCTION: acpi_rs_dma_stream
  317. *
  318. * PARAMETERS: linked_list - Pointer to the resource linked list
  319. * output_buffer - Pointer to the user's return buffer
  320. * bytes_consumed - Pointer to where the number of bytes
  321. * used in the output_buffer is returned
  322. *
  323. * RETURN: Status
  324. *
  325. * DESCRIPTION: Take the linked list resource structure and fills in the
  326. * the appropriate bytes in a byte stream
  327. *
  328. ******************************************************************************/
  329. acpi_status
  330. acpi_rs_dma_stream(struct acpi_resource *linked_list,
  331. u8 ** output_buffer, acpi_size * bytes_consumed)
  332. {
  333. u8 *buffer = *output_buffer;
  334. u16 temp16 = 0;
  335. u8 temp8 = 0;
  336. u8 index;
  337. ACPI_FUNCTION_TRACE("rs_dma_stream");
  338. /* The descriptor field is static */
  339. *buffer = 0x2A;
  340. buffer += 1;
  341. temp8 = 0;
  342. /* Loop through all of the Channels and set the mask bits */
  343. for (index = 0;
  344. index < linked_list->data.dma.number_of_channels; index++) {
  345. temp16 = (u16) linked_list->data.dma.channels[index];
  346. temp8 |= 0x1 << temp16;
  347. }
  348. *buffer = temp8;
  349. buffer += 1;
  350. /* Set the DMA Info */
  351. temp8 = (u8) ((linked_list->data.dma.type & 0x03) << 5);
  352. temp8 |= ((linked_list->data.dma.bus_master & 0x01) << 2);
  353. temp8 |= (linked_list->data.dma.transfer & 0x03);
  354. *buffer = temp8;
  355. buffer += 1;
  356. /* Return the number of bytes consumed in this operation */
  357. *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
  358. return_ACPI_STATUS(AE_OK);
  359. }