rsio.c 15 KB

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