rsio.c 15 KB

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