rsio.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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_get_io
  49. *
  50. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  51. * aml_resource_length - Length of the resource from the AML header
  52. * Resource - Where the internal resource is returned
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  57. * internal resource descriptor, simplifying bitflags and handling
  58. * alignment and endian issues if necessary.
  59. *
  60. ******************************************************************************/
  61. acpi_status
  62. acpi_rs_get_io(union aml_resource *aml,
  63. u16 aml_resource_length, struct acpi_resource *resource)
  64. {
  65. ACPI_FUNCTION_TRACE("rs_get_io");
  66. /* Get the Decode flag */
  67. resource->data.io.io_decode = aml->io.information & 0x01;
  68. /*
  69. * Get the following contiguous fields from the AML descriptor:
  70. * Minimum Base Address
  71. * Maximum Base Address
  72. * Address Alignment
  73. * Length
  74. */
  75. ACPI_MOVE_16_TO_32(&resource->data.io.minimum, &aml->io.minimum);
  76. ACPI_MOVE_16_TO_32(&resource->data.io.maximum, &aml->io.maximum);
  77. resource->data.io.alignment = aml->io.alignment;
  78. resource->data.io.address_length = aml->io.address_length;
  79. /* Complete the resource header */
  80. resource->type = ACPI_RESOURCE_TYPE_IO;
  81. resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_io);
  82. return_ACPI_STATUS(AE_OK);
  83. }
  84. /*******************************************************************************
  85. *
  86. * FUNCTION: acpi_rs_set_io
  87. *
  88. * PARAMETERS: Resource - Pointer to the resource descriptor
  89. * Aml - Where the AML descriptor is returned
  90. *
  91. * RETURN: Status
  92. *
  93. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  94. * external AML resource descriptor.
  95. *
  96. ******************************************************************************/
  97. acpi_status
  98. acpi_rs_set_io(struct acpi_resource *resource, union aml_resource *aml)
  99. {
  100. ACPI_FUNCTION_TRACE("rs_set_io");
  101. /* I/O Information Byte */
  102. aml->io.information = (u8) (resource->data.io.io_decode & 0x01);
  103. /*
  104. * Set the following contiguous fields in the AML descriptor:
  105. * Minimum Base Address
  106. * Maximum Base Address
  107. * Address Alignment
  108. * Length
  109. */
  110. ACPI_MOVE_32_TO_16(&aml->io.minimum, &resource->data.io.minimum);
  111. ACPI_MOVE_32_TO_16(&aml->io.maximum, &resource->data.io.maximum);
  112. aml->io.alignment = (u8) resource->data.io.alignment;
  113. aml->io.address_length = (u8) resource->data.io.address_length;
  114. /* Complete the AML descriptor header */
  115. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_IO,
  116. sizeof(struct aml_resource_io), aml);
  117. return_ACPI_STATUS(AE_OK);
  118. }
  119. /*******************************************************************************
  120. *
  121. * FUNCTION: acpi_rs_get_fixed_io
  122. *
  123. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  124. * aml_resource_length - Length of the resource from the AML header
  125. * Resource - Where the internal resource is returned
  126. *
  127. * RETURN: Status
  128. *
  129. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  130. * internal resource descriptor, simplifying bitflags and handling
  131. * alignment and endian issues if necessary.
  132. *
  133. ******************************************************************************/
  134. acpi_status
  135. acpi_rs_get_fixed_io(union aml_resource *aml,
  136. u16 aml_resource_length, struct acpi_resource *resource)
  137. {
  138. ACPI_FUNCTION_TRACE("rs_get_fixed_io");
  139. /*
  140. * Get the following contiguous fields from the AML descriptor:
  141. * Base Address
  142. * Length
  143. */
  144. ACPI_MOVE_16_TO_32(&resource->data.fixed_io.address,
  145. &aml->fixed_io.address);
  146. resource->data.fixed_io.address_length = aml->fixed_io.address_length;
  147. /* Complete the resource header */
  148. resource->type = ACPI_RESOURCE_TYPE_FIXED_IO;
  149. resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_fixed_io);
  150. return_ACPI_STATUS(AE_OK);
  151. }
  152. /*******************************************************************************
  153. *
  154. * FUNCTION: acpi_rs_set_fixed_io
  155. *
  156. * PARAMETERS: Resource - Pointer to the resource descriptor
  157. * Aml - Where the AML descriptor is returned
  158. *
  159. * RETURN: Status
  160. *
  161. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  162. * external AML resource descriptor.
  163. *
  164. ******************************************************************************/
  165. acpi_status
  166. acpi_rs_set_fixed_io(struct acpi_resource *resource, union aml_resource *aml)
  167. {
  168. ACPI_FUNCTION_TRACE("rs_set_fixed_io");
  169. /*
  170. * Set the following contiguous fields in the AML descriptor:
  171. * Base Address
  172. * Length
  173. */
  174. ACPI_MOVE_32_TO_16(&aml->fixed_io.address,
  175. &resource->data.fixed_io.address);
  176. aml->fixed_io.address_length =
  177. (u8) resource->data.fixed_io.address_length;
  178. /* Complete the AML descriptor header */
  179. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_FIXED_IO,
  180. sizeof(struct aml_resource_fixed_io), aml);
  181. return_ACPI_STATUS(AE_OK);
  182. }
  183. /*******************************************************************************
  184. *
  185. * FUNCTION: acpi_rs_get_dma
  186. *
  187. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  188. * aml_resource_length - Length of the resource from the AML header
  189. * Resource - Where the internal resource is returned
  190. *
  191. * RETURN: Status
  192. *
  193. * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
  194. * internal resource descriptor, simplifying bitflags and handling
  195. * alignment and endian issues if necessary.
  196. *
  197. ******************************************************************************/
  198. acpi_status
  199. acpi_rs_get_dma(union aml_resource *aml,
  200. u16 aml_resource_length, struct acpi_resource *resource)
  201. {
  202. u32 channel_count = 0;
  203. u32 i;
  204. u8 temp8;
  205. ACPI_FUNCTION_TRACE("rs_get_dma");
  206. /* Decode the DMA channel bits */
  207. for (i = 0; i < 8; i++) {
  208. if ((aml->dma.dma_channel_mask >> i) & 0x01) {
  209. resource->data.dma.channels[channel_count] = i;
  210. channel_count++;
  211. }
  212. }
  213. resource->length = 0;
  214. resource->data.dma.channel_count = channel_count;
  215. /*
  216. * Calculate the structure size based upon the number of channels
  217. * Note: Zero DMA channels is valid
  218. */
  219. if (channel_count > 0) {
  220. resource->length = (u32) (channel_count - 1) * 4;
  221. }
  222. /* Get the flags: transfer preference, bus mastering, channel speed */
  223. temp8 = aml->dma.flags;
  224. resource->data.dma.transfer = temp8 & 0x03;
  225. resource->data.dma.bus_master = (temp8 >> 2) & 0x01;
  226. resource->data.dma.type = (temp8 >> 5) & 0x03;
  227. if (resource->data.dma.transfer == 0x03) {
  228. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  229. "Invalid DMA.Transfer preference (3)\n"));
  230. return_ACPI_STATUS(AE_BAD_DATA);
  231. }
  232. /* Complete the resource header */
  233. resource->type = ACPI_RESOURCE_TYPE_DMA;
  234. resource->length += ACPI_SIZEOF_RESOURCE(struct acpi_resource_dma);
  235. return_ACPI_STATUS(AE_OK);
  236. }
  237. /*******************************************************************************
  238. *
  239. * FUNCTION: acpi_rs_set_dma
  240. *
  241. * PARAMETERS: Resource - Pointer to the resource descriptor
  242. * Aml - Where the AML descriptor is returned
  243. *
  244. * RETURN: Status
  245. *
  246. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  247. * external AML resource descriptor.
  248. *
  249. ******************************************************************************/
  250. acpi_status
  251. acpi_rs_set_dma(struct acpi_resource *resource, union aml_resource *aml)
  252. {
  253. u8 i;
  254. ACPI_FUNCTION_TRACE("rs_set_dma");
  255. /* Convert channel list to 8-bit DMA channel bitmask */
  256. aml->dma.dma_channel_mask = 0;
  257. for (i = 0; i < resource->data.dma.channel_count; i++) {
  258. aml->dma.dma_channel_mask |=
  259. (1 << resource->data.dma.channels[i]);
  260. }
  261. /* Set the DMA Flag bits */
  262. aml->dma.flags = (u8)
  263. (((resource->data.dma.type & 0x03) << 5) |
  264. ((resource->data.dma.bus_master & 0x01) << 2) |
  265. (resource->data.dma.transfer & 0x03));
  266. /* Complete the AML descriptor header */
  267. acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_DMA,
  268. sizeof(struct aml_resource_dma), aml);
  269. return_ACPI_STATUS(AE_OK);
  270. }