rsaddr.c 12 KB

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