rsdump.c 14 KB

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