rsdump.c 15 KB

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