rsaddr.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsaddr - Address resource descriptors (16/32/64)
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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.address.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.address.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.address.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,
  165. ACPI_RS_OFFSET(data.ext_address64.address.granularity),
  166. AML_OFFSET(ext_address64.granularity),
  167. 6}
  168. };
  169. /*******************************************************************************
  170. *
  171. * acpi_rs_convert_general_flags - Flags common to all address descriptors
  172. *
  173. ******************************************************************************/
  174. static struct acpi_rsconvert_info acpi_rs_convert_general_flags[6] = {
  175. {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.flags),
  176. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_general_flags)},
  177. /* Resource Type (Memory, Io, bus_number, etc.) */
  178. {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.address.resource_type),
  179. AML_OFFSET(address.resource_type),
  180. 1},
  181. /* General flags - Consume, Decode, min_fixed, max_fixed */
  182. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.producer_consumer),
  183. AML_OFFSET(address.flags),
  184. 0},
  185. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.decode),
  186. AML_OFFSET(address.flags),
  187. 1},
  188. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.min_address_fixed),
  189. AML_OFFSET(address.flags),
  190. 2},
  191. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.max_address_fixed),
  192. AML_OFFSET(address.flags),
  193. 3}
  194. };
  195. /*******************************************************************************
  196. *
  197. * acpi_rs_convert_mem_flags - Flags common to Memory address descriptors
  198. *
  199. ******************************************************************************/
  200. static struct acpi_rsconvert_info acpi_rs_convert_mem_flags[5] = {
  201. {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags),
  202. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_mem_flags)},
  203. /* Memory-specific flags */
  204. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.write_protect),
  205. AML_OFFSET(address.specific_flags),
  206. 0},
  207. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.caching),
  208. AML_OFFSET(address.specific_flags),
  209. 1},
  210. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.range_type),
  211. AML_OFFSET(address.specific_flags),
  212. 3},
  213. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.translation),
  214. AML_OFFSET(address.specific_flags),
  215. 5}
  216. };
  217. /*******************************************************************************
  218. *
  219. * acpi_rs_convert_io_flags - Flags common to I/O address descriptors
  220. *
  221. ******************************************************************************/
  222. static struct acpi_rsconvert_info acpi_rs_convert_io_flags[4] = {
  223. {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags),
  224. ACPI_RSC_TABLE_SIZE(acpi_rs_convert_io_flags)},
  225. /* I/O-specific flags */
  226. {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.io.range_type),
  227. AML_OFFSET(address.specific_flags),
  228. 0},
  229. {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.io.translation),
  230. AML_OFFSET(address.specific_flags),
  231. 4},
  232. {ACPI_RSC_1BITFLAG,
  233. ACPI_RS_OFFSET(data.address.info.io.translation_type),
  234. AML_OFFSET(address.specific_flags),
  235. 5}
  236. };
  237. /*******************************************************************************
  238. *
  239. * FUNCTION: acpi_rs_get_address_common
  240. *
  241. * PARAMETERS: resource - Pointer to the internal resource struct
  242. * aml - Pointer to the AML resource descriptor
  243. *
  244. * RETURN: TRUE if the resource_type field is OK, FALSE otherwise
  245. *
  246. * DESCRIPTION: Convert common flag fields from a raw AML resource descriptor
  247. * to an internal resource descriptor
  248. *
  249. ******************************************************************************/
  250. u8
  251. acpi_rs_get_address_common(struct acpi_resource *resource,
  252. union aml_resource *aml)
  253. {
  254. ACPI_FUNCTION_ENTRY();
  255. /* Validate the Resource Type */
  256. if ((aml->address.resource_type > 2)
  257. && (aml->address.resource_type < 0xC0)) {
  258. return (FALSE);
  259. }
  260. /* Get the Resource Type and General Flags */
  261. (void)acpi_rs_convert_aml_to_resource(resource, aml,
  262. acpi_rs_convert_general_flags);
  263. /* Get the Type-Specific Flags (Memory and I/O descriptors only) */
  264. if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) {
  265. (void)acpi_rs_convert_aml_to_resource(resource, aml,
  266. acpi_rs_convert_mem_flags);
  267. } else if (resource->data.address.resource_type == ACPI_IO_RANGE) {
  268. (void)acpi_rs_convert_aml_to_resource(resource, aml,
  269. acpi_rs_convert_io_flags);
  270. } else {
  271. /* Generic resource type, just grab the type_specific byte */
  272. resource->data.address.info.type_specific =
  273. aml->address.specific_flags;
  274. }
  275. return (TRUE);
  276. }
  277. /*******************************************************************************
  278. *
  279. * FUNCTION: acpi_rs_set_address_common
  280. *
  281. * PARAMETERS: aml - Pointer to the AML resource descriptor
  282. * resource - Pointer to the internal resource struct
  283. *
  284. * RETURN: None
  285. *
  286. * DESCRIPTION: Convert common flag fields from a resource descriptor to an
  287. * AML descriptor
  288. *
  289. ******************************************************************************/
  290. void
  291. acpi_rs_set_address_common(union aml_resource *aml,
  292. struct acpi_resource *resource)
  293. {
  294. ACPI_FUNCTION_ENTRY();
  295. /* Set the Resource Type and General Flags */
  296. (void)acpi_rs_convert_resource_to_aml(resource, aml,
  297. acpi_rs_convert_general_flags);
  298. /* Set the Type-Specific Flags (Memory and I/O descriptors only) */
  299. if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) {
  300. (void)acpi_rs_convert_resource_to_aml(resource, aml,
  301. acpi_rs_convert_mem_flags);
  302. } else if (resource->data.address.resource_type == ACPI_IO_RANGE) {
  303. (void)acpi_rs_convert_resource_to_aml(resource, aml,
  304. acpi_rs_convert_io_flags);
  305. } else {
  306. /* Generic resource type, just copy the type_specific byte */
  307. aml->address.specific_flags =
  308. resource->data.address.info.type_specific;
  309. }
  310. }