rsdump.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. /* Local prototypes */
  51. static void acpi_rs_out_string(char *title, char *value);
  52. static void acpi_rs_out_integer8(char *title, u8 value);
  53. static void acpi_rs_out_integer16(char *title, u16 value);
  54. static void acpi_rs_out_integer32(char *title, u32 value);
  55. static void acpi_rs_out_integer64(char *title, u64 value);
  56. static void acpi_rs_out_title(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. 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, ACPI_CAST_PTR(char,
  196. table->
  197. pointer
  198. [*target]));
  199. } else {
  200. acpi_rs_out_integer8(name, ACPI_GET8(target));
  201. }
  202. break;
  203. case ACPI_RSD_UINT16:
  204. acpi_rs_out_integer16(name, ACPI_GET16(target));
  205. break;
  206. case ACPI_RSD_UINT32:
  207. acpi_rs_out_integer32(name, ACPI_GET32(target));
  208. break;
  209. case ACPI_RSD_UINT64:
  210. acpi_rs_out_integer64(name, ACPI_GET64(target));
  211. break;
  212. /* Flags: 1-bit and 2-bit flags supported */
  213. case ACPI_RSD_1BITFLAG:
  214. acpi_rs_out_string(name, ACPI_CAST_PTR(char,
  215. table->
  216. pointer[*target &
  217. 0x01]));
  218. break;
  219. case ACPI_RSD_2BITFLAG:
  220. acpi_rs_out_string(name, ACPI_CAST_PTR(char,
  221. table->
  222. pointer[*target &
  223. 0x03]));
  224. break;
  225. case ACPI_RSD_3BITFLAG:
  226. acpi_rs_out_string(name, ACPI_CAST_PTR(char,
  227. table->
  228. pointer[*target &
  229. 0x07]));
  230. break;
  231. case ACPI_RSD_SHORTLIST:
  232. /*
  233. * Short byte list (single line output) for DMA and IRQ resources
  234. * Note: The list length is obtained from the previous table entry
  235. */
  236. if (previous_target) {
  237. acpi_rs_out_title(name);
  238. acpi_rs_dump_short_byte_list(*previous_target,
  239. target);
  240. }
  241. break;
  242. case ACPI_RSD_SHORTLISTX:
  243. /*
  244. * Short byte list (single line output) for GPIO vendor data
  245. * Note: The list length is obtained from the previous table entry
  246. */
  247. if (previous_target) {
  248. acpi_rs_out_title(name);
  249. acpi_rs_dump_short_byte_list(*previous_target,
  250. *
  251. (ACPI_CAST_INDIRECT_PTR
  252. (u8, target)));
  253. }
  254. break;
  255. case ACPI_RSD_LONGLIST:
  256. /*
  257. * Long byte list for Vendor resource data
  258. * Note: The list length is obtained from the previous table entry
  259. */
  260. if (previous_target) {
  261. acpi_rs_dump_byte_list(ACPI_GET16
  262. (previous_target),
  263. target);
  264. }
  265. break;
  266. case ACPI_RSD_DWORDLIST:
  267. /*
  268. * Dword list for Extended Interrupt resources
  269. * Note: The list length is obtained from the previous table entry
  270. */
  271. if (previous_target) {
  272. acpi_rs_dump_dword_list(*previous_target,
  273. ACPI_CAST_PTR(u32,
  274. target));
  275. }
  276. break;
  277. case ACPI_RSD_WORDLIST:
  278. /*
  279. * Word list for GPIO Pin Table
  280. * Note: The list length is obtained from the previous table entry
  281. */
  282. if (previous_target) {
  283. acpi_rs_dump_word_list(*previous_target,
  284. *(ACPI_CAST_INDIRECT_PTR
  285. (u16, target)));
  286. }
  287. break;
  288. case ACPI_RSD_ADDRESS:
  289. /*
  290. * Common flags for all Address resources
  291. */
  292. acpi_rs_dump_address_common(ACPI_CAST_PTR
  293. (union acpi_resource_data,
  294. target));
  295. break;
  296. case ACPI_RSD_SOURCE:
  297. /*
  298. * Optional resource_source for Address resources
  299. */
  300. acpi_rs_dump_resource_source(ACPI_CAST_PTR
  301. (struct
  302. acpi_resource_source,
  303. target));
  304. break;
  305. default:
  306. acpi_os_printf("**** Invalid table opcode [%X] ****\n",
  307. table->opcode);
  308. return;
  309. }
  310. table++;
  311. count--;
  312. }
  313. }
  314. /*******************************************************************************
  315. *
  316. * FUNCTION: acpi_rs_dump_resource_source
  317. *
  318. * PARAMETERS: resource_source - Pointer to a Resource Source struct
  319. *
  320. * RETURN: None
  321. *
  322. * DESCRIPTION: Common routine for dumping the optional resource_source and the
  323. * corresponding resource_source_index.
  324. *
  325. ******************************************************************************/
  326. static void
  327. acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
  328. {
  329. ACPI_FUNCTION_ENTRY();
  330. if (resource_source->index == 0xFF) {
  331. return;
  332. }
  333. acpi_rs_out_integer8("Resource Source Index", resource_source->index);
  334. acpi_rs_out_string("Resource Source",
  335. resource_source->string_ptr ?
  336. resource_source->string_ptr : "[Not Specified]");
  337. }
  338. /*******************************************************************************
  339. *
  340. * FUNCTION: acpi_rs_dump_address_common
  341. *
  342. * PARAMETERS: resource - Pointer to an internal resource descriptor
  343. *
  344. * RETURN: None
  345. *
  346. * DESCRIPTION: Dump the fields that are common to all Address resource
  347. * descriptors
  348. *
  349. ******************************************************************************/
  350. static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
  351. {
  352. ACPI_FUNCTION_ENTRY();
  353. /* Decode the type-specific flags */
  354. switch (resource->address.resource_type) {
  355. case ACPI_MEMORY_RANGE:
  356. acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
  357. break;
  358. case ACPI_IO_RANGE:
  359. acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
  360. break;
  361. case ACPI_BUS_NUMBER_RANGE:
  362. acpi_rs_out_string("Resource Type", "Bus Number Range");
  363. break;
  364. default:
  365. acpi_rs_out_integer8("Resource Type",
  366. (u8) resource->address.resource_type);
  367. break;
  368. }
  369. /* Decode the general flags */
  370. acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
  371. }
  372. /*******************************************************************************
  373. *
  374. * FUNCTION: acpi_rs_out*
  375. *
  376. * PARAMETERS: title - Name of the resource field
  377. * value - Value of the resource field
  378. *
  379. * RETURN: None
  380. *
  381. * DESCRIPTION: Miscellaneous helper functions to consistently format the
  382. * output of the resource dump routines
  383. *
  384. ******************************************************************************/
  385. static void acpi_rs_out_string(char *title, char *value)
  386. {
  387. acpi_os_printf("%27s : %s", title, value);
  388. if (!*value) {
  389. acpi_os_printf("[NULL NAMESTRING]");
  390. }
  391. acpi_os_printf("\n");
  392. }
  393. static void acpi_rs_out_integer8(char *title, u8 value)
  394. {
  395. acpi_os_printf("%27s : %2.2X\n", title, value);
  396. }
  397. static void acpi_rs_out_integer16(char *title, u16 value)
  398. {
  399. acpi_os_printf("%27s : %4.4X\n", title, value);
  400. }
  401. static void acpi_rs_out_integer32(char *title, u32 value)
  402. {
  403. acpi_os_printf("%27s : %8.8X\n", title, value);
  404. }
  405. static void acpi_rs_out_integer64(char *title, u64 value)
  406. {
  407. acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
  408. }
  409. static void acpi_rs_out_title(char *title)
  410. {
  411. acpi_os_printf("%27s : ", title);
  412. }
  413. /*******************************************************************************
  414. *
  415. * FUNCTION: acpi_rs_dump*List
  416. *
  417. * PARAMETERS: length - Number of elements in the list
  418. * data - Start of the list
  419. *
  420. * RETURN: None
  421. *
  422. * DESCRIPTION: Miscellaneous functions to dump lists of raw data
  423. *
  424. ******************************************************************************/
  425. static void acpi_rs_dump_byte_list(u16 length, u8 * data)
  426. {
  427. u8 i;
  428. for (i = 0; i < length; i++) {
  429. acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
  430. }
  431. }
  432. static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
  433. {
  434. u8 i;
  435. for (i = 0; i < length; i++) {
  436. acpi_os_printf("%X ", data[i]);
  437. }
  438. acpi_os_printf("\n");
  439. }
  440. static void acpi_rs_dump_dword_list(u8 length, u32 * data)
  441. {
  442. u8 i;
  443. for (i = 0; i < length; i++) {
  444. acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
  445. }
  446. }
  447. static void acpi_rs_dump_word_list(u16 length, u16 *data)
  448. {
  449. u16 i;
  450. for (i = 0; i < length; i++) {
  451. acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);
  452. }
  453. }