rsaddr.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsaddr - Address resource descriptors (16/32/64)
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, 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("rsaddr")
  46. /*******************************************************************************
  47. *
  48. * acpi_rs_convert_address16 - All WORD (16-bit) address resources
  49. *
  50. ******************************************************************************/
  51. struct acpi_rsconvert_info acpi_rs_convert_address16[5] = {
  52. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS16,
  53. ACPI_RS_SIZE(struct acpi_resource_address16),
  54. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address16)},
  55. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS16,
  56. sizeof(struct aml_resource_address16),
  57. 0},
  58. /* Resource Type, General Flags, and Type-Specific Flags */
  59. {ACPI_RSC_ADDRESS, 0, 0, 0},
  60. /*
  61. * These fields are contiguous in both the source and destination:
  62. * Address Granularity
  63. * Address Range Minimum
  64. * Address Range Maximum
  65. * Address Translation Offset
  66. * Address Length
  67. */
  68. {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.address16.granularity),
  69. AML_OFFSET(address16.granularity),
  70. 5},
  71. /* Optional resource_source (Index and String) */
  72. {ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address16.resource_source),
  73. 0,
  74. sizeof(struct aml_resource_address16)}
  75. };
  76. /*******************************************************************************
  77. *
  78. * acpi_rs_convert_address32 - All DWORD (32-bit) address resources
  79. *
  80. ******************************************************************************/
  81. struct acpi_rsconvert_info acpi_rs_convert_address32[5] = {
  82. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS32,
  83. ACPI_RS_SIZE(struct acpi_resource_address32),
  84. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address32)},
  85. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS32,
  86. sizeof(struct aml_resource_address32),
  87. 0},
  88. /* Resource Type, General Flags, and Type-Specific Flags */
  89. {ACPI_RSC_ADDRESS, 0, 0, 0},
  90. /*
  91. * These fields are contiguous in both the source and destination:
  92. * Address Granularity
  93. * Address Range Minimum
  94. * Address Range Maximum
  95. * Address Translation Offset
  96. * Address Length
  97. */
  98. {ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.address32.granularity),
  99. AML_OFFSET(address32.granularity),
  100. 5},
  101. /* Optional resource_source (Index and String) */
  102. {ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address32.resource_source),
  103. 0,
  104. sizeof(struct aml_resource_address32)}
  105. };
  106. /*******************************************************************************
  107. *
  108. * acpi_rs_convert_address64 - All QWORD (64-bit) address resources
  109. *
  110. ******************************************************************************/
  111. struct acpi_rsconvert_info acpi_rs_convert_address64[5] = {
  112. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS64,
  113. ACPI_RS_SIZE(struct acpi_resource_address64),
  114. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address64)},
  115. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS64,
  116. sizeof(struct aml_resource_address64),
  117. 0},
  118. /* Resource Type, General Flags, and Type-Specific Flags */
  119. {ACPI_RSC_ADDRESS, 0, 0, 0},
  120. /*
  121. * These fields are contiguous in both the source and destination:
  122. * Address Granularity
  123. * Address Range Minimum
  124. * Address Range Maximum
  125. * Address Translation Offset
  126. * Address Length
  127. */
  128. {ACPI_RSC_MOVE64, ACPI_RS_OFFSET(data.address64.granularity),
  129. AML_OFFSET(address64.granularity),
  130. 5},
  131. /* Optional resource_source (Index and String) */
  132. {ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address64.resource_source),
  133. 0,
  134. sizeof(struct aml_resource_address64)}
  135. };
  136. /*******************************************************************************
  137. *
  138. * acpi_rs_convert_ext_address64 - All Extended (64-bit) address resources
  139. *
  140. ******************************************************************************/
  141. struct acpi_rsconvert_info acpi_rs_convert_ext_address64[5] = {
  142. {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64,
  143. ACPI_RS_SIZE(struct acpi_resource_extended_address64),
  144. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_ext_address64)},
  145. {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64,
  146. sizeof(struct aml_resource_extended_address64),
  147. 0},
  148. /* Resource Type, General Flags, and Type-Specific Flags */
  149. {ACPI_RSC_ADDRESS, 0, 0, 0},
  150. /* Revision ID */
  151. {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.ext_address64.revision_iD),
  152. AML_OFFSET(ext_address64.revision_iD),
  153. 1},
  154. /*
  155. * These fields are contiguous in both the source and destination:
  156. * Address Granularity
  157. * Address Range Minimum
  158. * Address Range Maximum
  159. * Address Translation Offset
  160. * Address Length
  161. * Type-Specific Attribute
  162. */
  163. {ACPI_RSC_MOVE64, ACPI_RS_OFFSET(data.ext_address64.granularity),
  164. AML_OFFSET(ext_address64.granularity),
  165. 6}
  166. };
  167. /*******************************************************************************
  168. *
  169. * acpi_rs_convert_general_flags - Flags common to all address descriptors
  170. *
  171. ******************************************************************************/
  172. static struct acpi_rsconvert_info acpi_rs_convert_general_flags[6] = {
  173. {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.flags),
  174. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_general_flags)},
  175. /* Resource Type (Memory, Io, bus_number, etc.) */
  176. {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.address.resource_type),
  177. AML_OFFSET(address.resource_type),
  178. 1},
  179. /* General Flags - Consume, Decode, min_fixed, max_fixed */
  180. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.producer_consumer),
  181. AML_OFFSET(address.flags),
  182. 0},
  183. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.decode),
  184. AML_OFFSET(address.flags),
  185. 1},
  186. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.min_address_fixed),
  187. AML_OFFSET(address.flags),
  188. 2},
  189. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.max_address_fixed),
  190. AML_OFFSET(address.flags),
  191. 3}
  192. };
  193. /*******************************************************************************
  194. *
  195. * acpi_rs_convert_mem_flags - Flags common to Memory address descriptors
  196. *
  197. ******************************************************************************/
  198. static struct acpi_rsconvert_info acpi_rs_convert_mem_flags[5] = {
  199. {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags),
  200. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_mem_flags)},
  201. /* Memory-specific flags */
  202. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.write_protect),
  203. AML_OFFSET(address.specific_flags),
  204. 0},
  205. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.caching),
  206. AML_OFFSET(address.specific_flags),
  207. 1},
  208. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.range_type),
  209. AML_OFFSET(address.specific_flags),
  210. 3},
  211. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.translation),
  212. AML_OFFSET(address.specific_flags),
  213. 5}
  214. };
  215. /*******************************************************************************
  216. *
  217. * acpi_rs_convert_io_flags - Flags common to I/O address descriptors
  218. *
  219. ******************************************************************************/
  220. static struct acpi_rsconvert_info acpi_rs_convert_io_flags[4] = {
  221. {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags),
  222. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_io_flags)},
  223. /* I/O-specific flags */
  224. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.io.range_type),
  225. AML_OFFSET(address.specific_flags),
  226. 0},
  227. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.io.translation),
  228. AML_OFFSET(address.specific_flags),
  229. 4},
  230. {ACPI_RSC_1BITFLAG,
  231. ACPI_RS_OFFSET(data.address.info.io.translation_type),
  232. AML_OFFSET(address.specific_flags),
  233. 5}
  234. };
  235. /*******************************************************************************
  236. *
  237. * FUNCTION: acpi_rs_get_address_common
  238. *
  239. * PARAMETERS: Resource - Pointer to the internal resource struct
  240. * Aml - Pointer to the AML resource descriptor
  241. *
  242. * RETURN: TRUE if the resource_type field is OK, FALSE otherwise
  243. *
  244. * DESCRIPTION: Convert common flag fields from a raw AML resource descriptor
  245. * to an internal resource descriptor
  246. *
  247. ******************************************************************************/
  248. u8
  249. acpi_rs_get_address_common(struct acpi_resource *resource,
  250. union aml_resource *aml)
  251. {
  252. ACPI_FUNCTION_ENTRY();
  253. /* Validate the Resource Type */
  254. if ((aml->address.resource_type > 2)
  255. && (aml->address.resource_type < 0xC0)) {
  256. return (FALSE);
  257. }
  258. /* Get the Resource Type and General Flags */
  259. (void)acpi_rs_convert_aml_to_resource(resource, aml,
  260. acpi_rs_convert_general_flags);
  261. /* Get the Type-Specific Flags (Memory and I/O descriptors only) */
  262. if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) {
  263. (void)acpi_rs_convert_aml_to_resource(resource, aml,
  264. acpi_rs_convert_mem_flags);
  265. } else if (resource->data.address.resource_type == ACPI_IO_RANGE) {
  266. (void)acpi_rs_convert_aml_to_resource(resource, aml,
  267. acpi_rs_convert_io_flags);
  268. } else {
  269. /* Generic resource type, just grab the type_specific byte */
  270. resource->data.address.info.type_specific =
  271. aml->address.specific_flags;
  272. }
  273. return (TRUE);
  274. }
  275. /*******************************************************************************
  276. *
  277. * FUNCTION: acpi_rs_set_address_common
  278. *
  279. * PARAMETERS: Aml - Pointer to the AML resource descriptor
  280. * Resource - Pointer to the internal resource struct
  281. *
  282. * RETURN: None
  283. *
  284. * DESCRIPTION: Convert common flag fields from a resource descriptor to an
  285. * AML descriptor
  286. *
  287. ******************************************************************************/
  288. void
  289. acpi_rs_set_address_common(union aml_resource *aml,
  290. struct acpi_resource *resource)
  291. {
  292. ACPI_FUNCTION_ENTRY();
  293. /* Set the Resource Type and General Flags */
  294. (void)acpi_rs_convert_resource_to_aml(resource, aml,
  295. acpi_rs_convert_general_flags);
  296. /* Set the Type-Specific Flags (Memory and I/O descriptors only) */
  297. if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) {
  298. (void)acpi_rs_convert_resource_to_aml(resource, aml,
  299. acpi_rs_convert_mem_flags);
  300. } else if (resource->data.address.resource_type == ACPI_IO_RANGE) {
  301. (void)acpi_rs_convert_resource_to_aml(resource, aml,
  302. acpi_rs_convert_io_flags);
  303. } else {
  304. /* Generic resource type, just copy the type_specific byte */
  305. aml->address.specific_flags =
  306. resource->data.address.info.type_specific;
  307. }
  308. }