rsdump.c 14 KB

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