rsdump.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /*******************************************************************************
  2. *
  3. * Module Name: rsdump - AML debugger support for resource structures.
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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("rsdump")
  47. /*
  48. * All functions in this module are used by the AML Debugger only
  49. */
  50. /* Local prototypes */
  51. static void acpi_rs_out_string(const char *title, const char *value);
  52. static void acpi_rs_out_integer8(const char *title, u8 value);
  53. static void acpi_rs_out_integer16(const char *title, u16 value);
  54. static void acpi_rs_out_integer32(const char *title, u32 value);
  55. static void acpi_rs_out_integer64(const char *title, u64 value);
  56. static void acpi_rs_out_title(const char *title);
  57. static void acpi_rs_dump_byte_list(u16 length, u8 *data);
  58. static void acpi_rs_dump_word_list(u16 length, u16 *data);
  59. static void acpi_rs_dump_dword_list(u8 length, u32 *data);
  60. static void acpi_rs_dump_short_byte_list(u8 length, u8 *data);
  61. static void
  62. acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source);
  63. static void acpi_rs_dump_address_common(union acpi_resource_data *resource);
  64. static void
  65. acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table);
  66. /*******************************************************************************
  67. *
  68. * FUNCTION: acpi_rs_dump_resource_list
  69. *
  70. * PARAMETERS: resource_list - Pointer to a resource descriptor list
  71. *
  72. * RETURN: None
  73. *
  74. * DESCRIPTION: Dispatches the structure to the correct dump routine.
  75. *
  76. ******************************************************************************/
  77. void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
  78. {
  79. u32 count = 0;
  80. u32 type;
  81. ACPI_FUNCTION_ENTRY();
  82. /* Check if debug output enabled */
  83. if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
  84. return;
  85. }
  86. /* Walk list and dump all resource descriptors (END_TAG terminates) */
  87. do {
  88. acpi_os_printf("\n[%02X] ", count);
  89. count++;
  90. /* Validate Type before dispatch */
  91. type = resource_list->type;
  92. if (type > ACPI_RESOURCE_TYPE_MAX) {
  93. acpi_os_printf
  94. ("Invalid descriptor type (%X) in resource list\n",
  95. resource_list->type);
  96. return;
  97. }
  98. /* Sanity check the length. It must not be zero, or we loop forever */
  99. if (!resource_list->length) {
  100. acpi_os_printf
  101. ("Invalid zero length descriptor in resource list\n");
  102. return;
  103. }
  104. /* Dump the resource descriptor */
  105. if (type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
  106. acpi_rs_dump_descriptor(&resource_list->data,
  107. acpi_gbl_dump_serial_bus_dispatch
  108. [resource_list->data.
  109. common_serial_bus.type]);
  110. } else {
  111. acpi_rs_dump_descriptor(&resource_list->data,
  112. acpi_gbl_dump_resource_dispatch
  113. [type]);
  114. }
  115. /* Point to the next resource structure */
  116. resource_list = ACPI_NEXT_RESOURCE(resource_list);
  117. /* Exit when END_TAG descriptor is reached */
  118. } while (type != ACPI_RESOURCE_TYPE_END_TAG);
  119. }
  120. /*******************************************************************************
  121. *
  122. * FUNCTION: acpi_rs_dump_irq_list
  123. *
  124. * PARAMETERS: route_table - Pointer to the routing table to dump.
  125. *
  126. * RETURN: None
  127. *
  128. * DESCRIPTION: Print IRQ routing table
  129. *
  130. ******************************************************************************/
  131. void acpi_rs_dump_irq_list(u8 *route_table)
  132. {
  133. struct acpi_pci_routing_table *prt_element;
  134. u8 count;
  135. ACPI_FUNCTION_ENTRY();
  136. /* Check if debug output enabled */
  137. if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
  138. return;
  139. }
  140. prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
  141. /* Dump all table elements, Exit on zero length element */
  142. for (count = 0; prt_element->length; count++) {
  143. acpi_os_printf("\n[%02X] PCI IRQ Routing Table Package\n",
  144. count);
  145. acpi_rs_dump_descriptor(prt_element, acpi_rs_dump_prt);
  146. prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
  147. prt_element, prt_element->length);
  148. }
  149. }
  150. /*******************************************************************************
  151. *
  152. * FUNCTION: acpi_rs_dump_descriptor
  153. *
  154. * PARAMETERS: resource - Buffer containing the resource
  155. * table - Table entry to decode the resource
  156. *
  157. * RETURN: None
  158. *
  159. * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
  160. *
  161. ******************************************************************************/
  162. static void
  163. acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
  164. {
  165. u8 *target = NULL;
  166. u8 *previous_target;
  167. const char *name;
  168. u8 count;
  169. /* First table entry must contain the table length (# of table entries) */
  170. count = table->offset;
  171. while (count) {
  172. previous_target = target;
  173. target = ACPI_ADD_PTR(u8, resource, table->offset);
  174. name = table->name;
  175. switch (table->opcode) {
  176. case ACPI_RSD_TITLE:
  177. /*
  178. * Optional resource title
  179. */
  180. if (table->name) {
  181. acpi_os_printf("%s Resource\n", name);
  182. }
  183. break;
  184. /* Strings */
  185. case ACPI_RSD_LITERAL:
  186. acpi_rs_out_string(name,
  187. ACPI_CAST_PTR(char, table->pointer));
  188. break;
  189. case ACPI_RSD_STRING:
  190. acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
  191. break;
  192. /* Data items, 8/16/32/64 bit */
  193. case ACPI_RSD_UINT8:
  194. if (table->pointer) {
  195. acpi_rs_out_string(name,
  196. table->pointer[*target]);
  197. } else {
  198. acpi_rs_out_integer8(name, ACPI_GET8(target));
  199. }
  200. break;
  201. case ACPI_RSD_UINT16:
  202. acpi_rs_out_integer16(name, ACPI_GET16(target));
  203. break;
  204. case ACPI_RSD_UINT32:
  205. acpi_rs_out_integer32(name, ACPI_GET32(target));
  206. break;
  207. case ACPI_RSD_UINT64:
  208. acpi_rs_out_integer64(name, ACPI_GET64(target));
  209. break;
  210. /* Flags: 1-bit and 2-bit flags supported */
  211. case ACPI_RSD_1BITFLAG:
  212. acpi_rs_out_string(name,
  213. table->pointer[*target & 0x01]);
  214. break;
  215. case ACPI_RSD_2BITFLAG:
  216. acpi_rs_out_string(name,
  217. table->pointer[*target & 0x03]);
  218. break;
  219. case ACPI_RSD_3BITFLAG:
  220. acpi_rs_out_string(name,
  221. table->pointer[*target & 0x07]);
  222. break;
  223. case ACPI_RSD_SHORTLIST:
  224. /*
  225. * Short byte list (single line output) for DMA and IRQ resources
  226. * Note: The list length is obtained from the previous table entry
  227. */
  228. if (previous_target) {
  229. acpi_rs_out_title(name);
  230. acpi_rs_dump_short_byte_list(*previous_target,
  231. target);
  232. }
  233. break;
  234. case ACPI_RSD_SHORTLISTX:
  235. /*
  236. * Short byte list (single line output) for GPIO vendor data
  237. * Note: The list length is obtained from the previous table entry
  238. */
  239. if (previous_target) {
  240. acpi_rs_out_title(name);
  241. acpi_rs_dump_short_byte_list(*previous_target,
  242. *
  243. (ACPI_CAST_INDIRECT_PTR
  244. (u8, target)));
  245. }
  246. break;
  247. case ACPI_RSD_LONGLIST:
  248. /*
  249. * Long byte list for Vendor resource data
  250. * Note: The list length is obtained from the previous table entry
  251. */
  252. if (previous_target) {
  253. acpi_rs_dump_byte_list(ACPI_GET16
  254. (previous_target),
  255. target);
  256. }
  257. break;
  258. case ACPI_RSD_DWORDLIST:
  259. /*
  260. * Dword list for Extended Interrupt resources
  261. * Note: The list length is obtained from the previous table entry
  262. */
  263. if (previous_target) {
  264. acpi_rs_dump_dword_list(*previous_target,
  265. ACPI_CAST_PTR(u32,
  266. target));
  267. }
  268. break;
  269. case ACPI_RSD_WORDLIST:
  270. /*
  271. * Word list for GPIO Pin Table
  272. * Note: The list length is obtained from the previous table entry
  273. */
  274. if (previous_target) {
  275. acpi_rs_dump_word_list(*previous_target,
  276. *(ACPI_CAST_INDIRECT_PTR
  277. (u16, target)));
  278. }
  279. break;
  280. case ACPI_RSD_ADDRESS:
  281. /*
  282. * Common flags for all Address resources
  283. */
  284. acpi_rs_dump_address_common(ACPI_CAST_PTR
  285. (union acpi_resource_data,
  286. target));
  287. break;
  288. case ACPI_RSD_SOURCE:
  289. /*
  290. * Optional resource_source for Address resources
  291. */
  292. acpi_rs_dump_resource_source(ACPI_CAST_PTR
  293. (struct
  294. acpi_resource_source,
  295. target));
  296. break;
  297. default:
  298. acpi_os_printf("**** Invalid table opcode [%X] ****\n",
  299. table->opcode);
  300. return;
  301. }
  302. table++;
  303. count--;
  304. }
  305. }
  306. /*******************************************************************************
  307. *
  308. * FUNCTION: acpi_rs_dump_resource_source
  309. *
  310. * PARAMETERS: resource_source - Pointer to a Resource Source struct
  311. *
  312. * RETURN: None
  313. *
  314. * DESCRIPTION: Common routine for dumping the optional resource_source and the
  315. * corresponding resource_source_index.
  316. *
  317. ******************************************************************************/
  318. static void
  319. acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
  320. {
  321. ACPI_FUNCTION_ENTRY();
  322. if (resource_source->index == 0xFF) {
  323. return;
  324. }
  325. acpi_rs_out_integer8("Resource Source Index", resource_source->index);
  326. acpi_rs_out_string("Resource Source",
  327. resource_source->string_ptr ?
  328. resource_source->string_ptr : "[Not Specified]");
  329. }
  330. /*******************************************************************************
  331. *
  332. * FUNCTION: acpi_rs_dump_address_common
  333. *
  334. * PARAMETERS: resource - Pointer to an internal resource descriptor
  335. *
  336. * RETURN: None
  337. *
  338. * DESCRIPTION: Dump the fields that are common to all Address resource
  339. * descriptors
  340. *
  341. ******************************************************************************/
  342. static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
  343. {
  344. ACPI_FUNCTION_ENTRY();
  345. /* Decode the type-specific flags */
  346. switch (resource->address.resource_type) {
  347. case ACPI_MEMORY_RANGE:
  348. acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
  349. break;
  350. case ACPI_IO_RANGE:
  351. acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
  352. break;
  353. case ACPI_BUS_NUMBER_RANGE:
  354. acpi_rs_out_string("Resource Type", "Bus Number Range");
  355. break;
  356. default:
  357. acpi_rs_out_integer8("Resource Type",
  358. (u8) resource->address.resource_type);
  359. break;
  360. }
  361. /* Decode the general flags */
  362. acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
  363. }
  364. /*******************************************************************************
  365. *
  366. * FUNCTION: acpi_rs_out*
  367. *
  368. * PARAMETERS: title - Name of the resource field
  369. * value - Value of the resource field
  370. *
  371. * RETURN: None
  372. *
  373. * DESCRIPTION: Miscellaneous helper functions to consistently format the
  374. * output of the resource dump routines
  375. *
  376. ******************************************************************************/
  377. static void acpi_rs_out_string(const char *title, const char *value)
  378. {
  379. acpi_os_printf("%27s : %s", title, value);
  380. if (!*value) {
  381. acpi_os_printf("[NULL NAMESTRING]");
  382. }
  383. acpi_os_printf("\n");
  384. }
  385. static void acpi_rs_out_integer8(const char *title, u8 value)
  386. {
  387. acpi_os_printf("%27s : %2.2X\n", title, value);
  388. }
  389. static void acpi_rs_out_integer16(const char *title, u16 value)
  390. {
  391. acpi_os_printf("%27s : %4.4X\n", title, value);
  392. }
  393. static void acpi_rs_out_integer32(const char *title, u32 value)
  394. {
  395. acpi_os_printf("%27s : %8.8X\n", title, value);
  396. }
  397. static void acpi_rs_out_integer64(const char *title, u64 value)
  398. {
  399. acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
  400. }
  401. static void acpi_rs_out_title(const char *title)
  402. {
  403. acpi_os_printf("%27s : ", title);
  404. }
  405. /*******************************************************************************
  406. *
  407. * FUNCTION: acpi_rs_dump*List
  408. *
  409. * PARAMETERS: length - Number of elements in the list
  410. * data - Start of the list
  411. *
  412. * RETURN: None
  413. *
  414. * DESCRIPTION: Miscellaneous functions to dump lists of raw data
  415. *
  416. ******************************************************************************/
  417. static void acpi_rs_dump_byte_list(u16 length, u8 * data)
  418. {
  419. u8 i;
  420. for (i = 0; i < length; i++) {
  421. acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
  422. }
  423. }
  424. static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
  425. {
  426. u8 i;
  427. for (i = 0; i < length; i++) {
  428. acpi_os_printf("%X ", data[i]);
  429. }
  430. acpi_os_printf("\n");
  431. }
  432. static void acpi_rs_dump_dword_list(u8 length, u32 * data)
  433. {
  434. u8 i;
  435. for (i = 0; i < length; i++) {
  436. acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
  437. }
  438. }
  439. static void acpi_rs_dump_word_list(u16 length, u16 *data)
  440. {
  441. u16 i;
  442. for (i = 0; i < length; i++) {
  443. acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);
  444. }
  445. }