rsmisc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsmisc - Miscellaneous resource descriptors
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, 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("rsmisc")
  47. #define INIT_RESOURCE_TYPE(i) i->resource_offset
  48. #define INIT_RESOURCE_LENGTH(i) i->aml_offset
  49. #define INIT_TABLE_LENGTH(i) i->value
  50. #define COMPARE_OPCODE(i) i->resource_offset
  51. #define COMPARE_TARGET(i) i->aml_offset
  52. #define COMPARE_VALUE(i) i->value
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_rs_convert_aml_to_resource
  56. *
  57. * PARAMETERS: Resource - Pointer to the resource descriptor
  58. * Aml - Where the AML descriptor is returned
  59. * Info - Pointer to appropriate conversion table
  60. *
  61. * RETURN: Status
  62. *
  63. * DESCRIPTION: Convert an external AML resource descriptor to the corresponding
  64. * internal resource descriptor
  65. *
  66. ******************************************************************************/
  67. acpi_status
  68. acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
  69. union aml_resource *aml,
  70. struct acpi_rsconvert_info *info)
  71. {
  72. acpi_rs_length aml_resource_length;
  73. void *source;
  74. void *destination;
  75. char *target;
  76. u8 count;
  77. u8 flags_mode = FALSE;
  78. u16 item_count = 0;
  79. u16 temp16 = 0;
  80. ACPI_FUNCTION_TRACE(rs_convert_aml_to_resource);
  81. if (((acpi_size) resource) & 0x3) {
  82. /* Each internal resource struct is expected to be 32-bit aligned */
  83. ACPI_WARNING((AE_INFO,
  84. "Misaligned resource pointer (get): %p Type 0x%2.2X Length %u",
  85. resource, resource->type, resource->length));
  86. }
  87. /* Extract the resource Length field (does not include header length) */
  88. aml_resource_length = acpi_ut_get_resource_length(aml);
  89. /*
  90. * First table entry must be ACPI_RSC_INITxxx and must contain the
  91. * table length (# of table entries)
  92. */
  93. count = INIT_TABLE_LENGTH(info);
  94. while (count) {
  95. /*
  96. * Source is the external AML byte stream buffer,
  97. * destination is the internal resource descriptor
  98. */
  99. source = ACPI_ADD_PTR(void, aml, info->aml_offset);
  100. destination =
  101. ACPI_ADD_PTR(void, resource, info->resource_offset);
  102. switch (info->opcode) {
  103. case ACPI_RSC_INITGET:
  104. /*
  105. * Get the resource type and the initial (minimum) length
  106. */
  107. ACPI_MEMSET(resource, 0, INIT_RESOURCE_LENGTH(info));
  108. resource->type = INIT_RESOURCE_TYPE(info);
  109. resource->length = INIT_RESOURCE_LENGTH(info);
  110. break;
  111. case ACPI_RSC_INITSET:
  112. break;
  113. case ACPI_RSC_FLAGINIT:
  114. flags_mode = TRUE;
  115. break;
  116. case ACPI_RSC_1BITFLAG:
  117. /*
  118. * Mask and shift the flag bit
  119. */
  120. ACPI_SET8(destination) = (u8)
  121. ((ACPI_GET8(source) >> info->value) & 0x01);
  122. break;
  123. case ACPI_RSC_2BITFLAG:
  124. /*
  125. * Mask and shift the flag bits
  126. */
  127. ACPI_SET8(destination) = (u8)
  128. ((ACPI_GET8(source) >> info->value) & 0x03);
  129. break;
  130. case ACPI_RSC_COUNT:
  131. item_count = ACPI_GET8(source);
  132. ACPI_SET8(destination) = (u8) item_count;
  133. resource->length = resource->length +
  134. (info->value * (item_count - 1));
  135. break;
  136. case ACPI_RSC_COUNT16:
  137. item_count = aml_resource_length;
  138. ACPI_SET16(destination) = item_count;
  139. resource->length = resource->length +
  140. (info->value * (item_count - 1));
  141. break;
  142. case ACPI_RSC_LENGTH:
  143. resource->length = resource->length + info->value;
  144. break;
  145. case ACPI_RSC_MOVE8:
  146. case ACPI_RSC_MOVE16:
  147. case ACPI_RSC_MOVE32:
  148. case ACPI_RSC_MOVE64:
  149. /*
  150. * Raw data move. Use the Info value field unless item_count has
  151. * been previously initialized via a COUNT opcode
  152. */
  153. if (info->value) {
  154. item_count = info->value;
  155. }
  156. acpi_rs_move_data(destination, source, item_count,
  157. info->opcode);
  158. break;
  159. case ACPI_RSC_SET8:
  160. ACPI_MEMSET(destination, info->aml_offset, info->value);
  161. break;
  162. case ACPI_RSC_DATA8:
  163. target = ACPI_ADD_PTR(char, resource, info->value);
  164. ACPI_MEMCPY(destination, source, ACPI_GET16(target));
  165. break;
  166. case ACPI_RSC_ADDRESS:
  167. /*
  168. * Common handler for address descriptor flags
  169. */
  170. if (!acpi_rs_get_address_common(resource, aml)) {
  171. return_ACPI_STATUS
  172. (AE_AML_INVALID_RESOURCE_TYPE);
  173. }
  174. break;
  175. case ACPI_RSC_SOURCE:
  176. /*
  177. * Optional resource_source (Index and String)
  178. */
  179. resource->length +=
  180. acpi_rs_get_resource_source(aml_resource_length,
  181. info->value,
  182. destination, aml, NULL);
  183. break;
  184. case ACPI_RSC_SOURCEX:
  185. /*
  186. * Optional resource_source (Index and String). This is the more
  187. * complicated case used by the Interrupt() macro
  188. */
  189. target =
  190. ACPI_ADD_PTR(char, resource,
  191. info->aml_offset + (item_count * 4));
  192. resource->length +=
  193. acpi_rs_get_resource_source(aml_resource_length,
  194. (acpi_rs_length) (((item_count - 1) * sizeof(u32)) + info->value), destination, aml, target);
  195. break;
  196. case ACPI_RSC_BITMASK:
  197. /*
  198. * 8-bit encoded bitmask (DMA macro)
  199. */
  200. item_count =
  201. acpi_rs_decode_bitmask(ACPI_GET8(source),
  202. destination);
  203. if (item_count) {
  204. resource->length += (item_count - 1);
  205. }
  206. target = ACPI_ADD_PTR(char, resource, info->value);
  207. ACPI_SET8(target) = (u8) item_count;
  208. break;
  209. case ACPI_RSC_BITMASK16:
  210. /*
  211. * 16-bit encoded bitmask (IRQ macro)
  212. */
  213. ACPI_MOVE_16_TO_16(&temp16, source);
  214. item_count =
  215. acpi_rs_decode_bitmask(temp16, destination);
  216. if (item_count) {
  217. resource->length += (item_count - 1);
  218. }
  219. target = ACPI_ADD_PTR(char, resource, info->value);
  220. ACPI_SET8(target) = (u8) item_count;
  221. break;
  222. case ACPI_RSC_EXIT_NE:
  223. /*
  224. * Control - Exit conversion if not equal
  225. */
  226. switch (info->resource_offset) {
  227. case ACPI_RSC_COMPARE_AML_LENGTH:
  228. if (aml_resource_length != info->value) {
  229. goto exit;
  230. }
  231. break;
  232. case ACPI_RSC_COMPARE_VALUE:
  233. if (ACPI_GET8(source) != info->value) {
  234. goto exit;
  235. }
  236. break;
  237. default:
  238. ACPI_ERROR((AE_INFO,
  239. "Invalid conversion sub-opcode"));
  240. return_ACPI_STATUS(AE_BAD_PARAMETER);
  241. }
  242. break;
  243. default:
  244. ACPI_ERROR((AE_INFO, "Invalid conversion opcode"));
  245. return_ACPI_STATUS(AE_BAD_PARAMETER);
  246. }
  247. count--;
  248. info++;
  249. }
  250. exit:
  251. if (!flags_mode) {
  252. /* Round the resource struct length up to the next boundary (32 or 64) */
  253. resource->length =
  254. (u32) ACPI_ROUND_UP_TO_NATIVE_WORD(resource->length);
  255. }
  256. return_ACPI_STATUS(AE_OK);
  257. }
  258. /*******************************************************************************
  259. *
  260. * FUNCTION: acpi_rs_convert_resource_to_aml
  261. *
  262. * PARAMETERS: Resource - Pointer to the resource descriptor
  263. * Aml - Where the AML descriptor is returned
  264. * Info - Pointer to appropriate conversion table
  265. *
  266. * RETURN: Status
  267. *
  268. * DESCRIPTION: Convert an internal resource descriptor to the corresponding
  269. * external AML resource descriptor.
  270. *
  271. ******************************************************************************/
  272. acpi_status
  273. acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
  274. union aml_resource *aml,
  275. struct acpi_rsconvert_info *info)
  276. {
  277. void *source = NULL;
  278. void *destination;
  279. acpi_rsdesc_size aml_length = 0;
  280. u8 count;
  281. u16 temp16 = 0;
  282. u16 item_count = 0;
  283. ACPI_FUNCTION_TRACE(rs_convert_resource_to_aml);
  284. /*
  285. * First table entry must be ACPI_RSC_INITxxx and must contain the
  286. * table length (# of table entries)
  287. */
  288. count = INIT_TABLE_LENGTH(info);
  289. while (count) {
  290. /*
  291. * Source is the internal resource descriptor,
  292. * destination is the external AML byte stream buffer
  293. */
  294. source = ACPI_ADD_PTR(void, resource, info->resource_offset);
  295. destination = ACPI_ADD_PTR(void, aml, info->aml_offset);
  296. switch (info->opcode) {
  297. case ACPI_RSC_INITSET:
  298. ACPI_MEMSET(aml, 0, INIT_RESOURCE_LENGTH(info));
  299. aml_length = INIT_RESOURCE_LENGTH(info);
  300. acpi_rs_set_resource_header(INIT_RESOURCE_TYPE(info),
  301. aml_length, aml);
  302. break;
  303. case ACPI_RSC_INITGET:
  304. break;
  305. case ACPI_RSC_FLAGINIT:
  306. /*
  307. * Clear the flag byte
  308. */
  309. ACPI_SET8(destination) = 0;
  310. break;
  311. case ACPI_RSC_1BITFLAG:
  312. /*
  313. * Mask and shift the flag bit
  314. */
  315. ACPI_SET8(destination) |= (u8)
  316. ((ACPI_GET8(source) & 0x01) << info->value);
  317. break;
  318. case ACPI_RSC_2BITFLAG:
  319. /*
  320. * Mask and shift the flag bits
  321. */
  322. ACPI_SET8(destination) |= (u8)
  323. ((ACPI_GET8(source) & 0x03) << info->value);
  324. break;
  325. case ACPI_RSC_COUNT:
  326. item_count = ACPI_GET8(source);
  327. ACPI_SET8(destination) = (u8) item_count;
  328. aml_length =
  329. (u16) (aml_length +
  330. (info->value * (item_count - 1)));
  331. break;
  332. case ACPI_RSC_COUNT16:
  333. item_count = ACPI_GET16(source);
  334. aml_length = (u16) (aml_length + item_count);
  335. acpi_rs_set_resource_length(aml_length, aml);
  336. break;
  337. case ACPI_RSC_LENGTH:
  338. acpi_rs_set_resource_length(info->value, aml);
  339. break;
  340. case ACPI_RSC_MOVE8:
  341. case ACPI_RSC_MOVE16:
  342. case ACPI_RSC_MOVE32:
  343. case ACPI_RSC_MOVE64:
  344. if (info->value) {
  345. item_count = info->value;
  346. }
  347. acpi_rs_move_data(destination, source, item_count,
  348. info->opcode);
  349. break;
  350. case ACPI_RSC_ADDRESS:
  351. /* Set the Resource Type, General Flags, and Type-Specific Flags */
  352. acpi_rs_set_address_common(aml, resource);
  353. break;
  354. case ACPI_RSC_SOURCEX:
  355. /*
  356. * Optional resource_source (Index and String)
  357. */
  358. aml_length =
  359. acpi_rs_set_resource_source(aml, (acpi_rs_length)
  360. aml_length, source);
  361. acpi_rs_set_resource_length(aml_length, aml);
  362. break;
  363. case ACPI_RSC_SOURCE:
  364. /*
  365. * Optional resource_source (Index and String). This is the more
  366. * complicated case used by the Interrupt() macro
  367. */
  368. aml_length =
  369. acpi_rs_set_resource_source(aml, info->value,
  370. source);
  371. acpi_rs_set_resource_length(aml_length, aml);
  372. break;
  373. case ACPI_RSC_BITMASK:
  374. /*
  375. * 8-bit encoded bitmask (DMA macro)
  376. */
  377. ACPI_SET8(destination) = (u8)
  378. acpi_rs_encode_bitmask(source,
  379. *ACPI_ADD_PTR(u8, resource,
  380. info->value));
  381. break;
  382. case ACPI_RSC_BITMASK16:
  383. /*
  384. * 16-bit encoded bitmask (IRQ macro)
  385. */
  386. temp16 = acpi_rs_encode_bitmask(source,
  387. *ACPI_ADD_PTR(u8,
  388. resource,
  389. info->
  390. value));
  391. ACPI_MOVE_16_TO_16(destination, &temp16);
  392. break;
  393. case ACPI_RSC_EXIT_LE:
  394. /*
  395. * Control - Exit conversion if less than or equal
  396. */
  397. if (item_count <= info->value) {
  398. goto exit;
  399. }
  400. break;
  401. case ACPI_RSC_EXIT_NE:
  402. /*
  403. * Control - Exit conversion if not equal
  404. */
  405. switch (COMPARE_OPCODE(info)) {
  406. case ACPI_RSC_COMPARE_VALUE:
  407. if (*ACPI_ADD_PTR(u8, resource,
  408. COMPARE_TARGET(info)) !=
  409. COMPARE_VALUE(info)) {
  410. goto exit;
  411. }
  412. break;
  413. default:
  414. ACPI_ERROR((AE_INFO,
  415. "Invalid conversion sub-opcode"));
  416. return_ACPI_STATUS(AE_BAD_PARAMETER);
  417. }
  418. break;
  419. case ACPI_RSC_EXIT_EQ:
  420. /*
  421. * Control - Exit conversion if equal
  422. */
  423. if (*ACPI_ADD_PTR(u8, resource,
  424. COMPARE_TARGET(info)) ==
  425. COMPARE_VALUE(info)) {
  426. goto exit;
  427. }
  428. break;
  429. default:
  430. ACPI_ERROR((AE_INFO, "Invalid conversion opcode"));
  431. return_ACPI_STATUS(AE_BAD_PARAMETER);
  432. }
  433. count--;
  434. info++;
  435. }
  436. exit:
  437. return_ACPI_STATUS(AE_OK);
  438. }
  439. #if 0
  440. /* Previous resource validations */
  441. if (aml->ext_address64.revision_iD != AML_RESOURCE_EXTENDED_ADDRESS_REVISION) {
  442. return_ACPI_STATUS(AE_SUPPORT);
  443. }
  444. if (resource->data.start_dpf.performance_robustness >= 3) {
  445. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
  446. }
  447. if (((aml->irq.flags & 0x09) == 0x00) || ((aml->irq.flags & 0x09) == 0x09)) {
  448. /*
  449. * Only [active_high, edge_sensitive] or [active_low, level_sensitive]
  450. * polarity/trigger interrupts are allowed (ACPI spec, section
  451. * "IRQ Format"), so 0x00 and 0x09 are illegal.
  452. */
  453. ACPI_ERROR((AE_INFO,
  454. "Invalid interrupt polarity/trigger in resource list, 0x%X",
  455. aml->irq.flags));
  456. return_ACPI_STATUS(AE_BAD_DATA);
  457. }
  458. resource->data.extended_irq.interrupt_count = temp8;
  459. if (temp8 < 1) {
  460. /* Must have at least one IRQ */
  461. return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
  462. }
  463. if (resource->data.dma.transfer == 0x03) {
  464. ACPI_ERROR((AE_INFO, "Invalid DMA.Transfer preference (3)"));
  465. return_ACPI_STATUS(AE_BAD_DATA);
  466. }
  467. #endif