Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

847 lines
24 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. resource.c
  5. Abstract:
  6. WinDbg Extension Api for interpretting ACPI data structures
  7. Author:
  8. Stephane Plante (splante) 21-Mar-1997
  9. Based on Code by:
  10. Peter Wieland (peterwie) 16-Oct-1995
  11. Environment:
  12. User Mode.
  13. Revision History:
  14. --*/
  15. #include "pch.h"
  16. VOID
  17. dumpPnPResources(
  18. IN ULONG_PTR Address
  19. )
  20. /*++
  21. Routine Description:
  22. This routine processes the ACPI version of a PnP resource list given
  23. the address that it starts at
  24. Arguments:
  25. Address - The Starting address
  26. Return Value:
  27. NULL
  28. --*/
  29. {
  30. BOOL success;
  31. PUCHAR dataBuffer = NULL;
  32. UCHAR currentTag;
  33. ULONG_PTR currentAddress = Address;
  34. ULONG i;
  35. ULONG indentLevel = 0;
  36. ULONG returnLength;
  37. ULONG tagCount = 0;
  38. USHORT increment;
  39. //
  40. // repeat forever
  41. //
  42. while (1) {
  43. //
  44. // Allow a way to end this
  45. //
  46. if (CheckControlC()) {
  47. break;
  48. }
  49. //
  50. // Read the current tag
  51. //
  52. success = ReadMemory(
  53. currentAddress,
  54. &currentTag,
  55. sizeof(UCHAR),
  56. &returnLength
  57. );
  58. if (!success || returnLength != sizeof(UCHAR)) {
  59. dprintf(
  60. "dumpPnPResources: could not read tag at 0x%08lx\n",
  61. currentAddress
  62. );
  63. return;
  64. }
  65. //
  66. // Determine what we are looking at
  67. //
  68. if ( !(currentTag & LARGE_RESOURCE_TAG)) {
  69. //
  70. // We are looking at a small tag
  71. //
  72. increment = (USHORT) (currentTag & SMALL_TAG_SIZE_MASK) + 1;
  73. currentTag &= SMALL_TAG_MASK;
  74. } else {
  75. //
  76. // We are looking at a large Tag. We must read the length as
  77. // the next short in memory
  78. //
  79. success = ReadMemory(
  80. currentAddress + 1,
  81. &increment,
  82. sizeof(USHORT),
  83. &returnLength
  84. );
  85. if (!success || returnLength != sizeof(USHORT)) {
  86. dprintf(
  87. "dumpPnPResources: could not read increment at 0x%08lx\n",
  88. currentAddress + 1
  89. );
  90. break;
  91. }
  92. //
  93. // Account for the increment
  94. //
  95. increment += 3;
  96. }
  97. //
  98. // Allocate space for the buffer
  99. //
  100. if (increment > 1) {
  101. dataBuffer = LocalAlloc( LPTR, increment);
  102. if (dataBuffer == NULL) {
  103. dprintf(
  104. "dumpPnPResources: could not allocate 0x%x bytes\n",
  105. (increment - 1)
  106. );
  107. }
  108. //
  109. // Read the data into the buffer
  110. //
  111. success = ReadMemory(
  112. currentAddress,
  113. dataBuffer,
  114. increment,
  115. &returnLength
  116. );
  117. if (!success || returnLength != (ULONG) increment) {
  118. dprintf(
  119. "dumpPnPResources: read buffer at 0x%08lx (0x%x)\n",
  120. currentAddress,
  121. increment
  122. );
  123. LocalFree( dataBuffer );
  124. return;
  125. }
  126. }
  127. //
  128. // Indent the tag
  129. //
  130. for (i = 0; i < indentLevel; i++) {
  131. dprintf("| ");
  132. }
  133. //
  134. // What tag are we looking at
  135. //
  136. switch (currentTag) {
  137. case TAG_IRQ: {
  138. PPNP_IRQ_DESCRIPTOR res = (PPNP_IRQ_DESCRIPTOR) dataBuffer;
  139. if (res) {
  140. USHORT mask = res->IrqMask;
  141. USHORT interrupt = 0;
  142. dprintf("%d - TAG_IRQ -", tagCount );
  143. for( ;mask; interrupt++, mask >>= 1) {
  144. if (mask & 1) {
  145. dprintf(" %d", interrupt );
  146. }
  147. }
  148. if ( (res->Tag & SMALL_TAG_SIZE_MASK) == 3) {
  149. if (res->Information & PNP_IRQ_LATCHED) {
  150. dprintf(" Lat");
  151. }
  152. if (res->Information & PNP_IRQ_LEVEL) {
  153. dprintf(" Lvl");
  154. }
  155. if (res->Information & PNP_IRQ_SHARED) {
  156. dprintf(" Shr");
  157. } else {
  158. dprintf(" Exc");
  159. }
  160. } else {
  161. dprintf(" Edg Sha");
  162. }
  163. dprintf("\n");
  164. }
  165. break;
  166. }
  167. case TAG_EXTENDED_IRQ: {
  168. PPNP_EXTENDED_IRQ_DESCRIPTOR res =
  169. (PPNP_EXTENDED_IRQ_DESCRIPTOR) dataBuffer;
  170. UCHAR tableCount = 0;
  171. UCHAR tableSize = res->TableSize;
  172. dprintf("%d - TAG_EXTENDED_IRQ -", tagCount );
  173. for (; tableCount < tableSize; tableCount++) {
  174. dprintf(" %d", res->Table[tableCount] );
  175. }
  176. if (res->Flags & PNP_EXTENDED_IRQ_MODE) {
  177. dprintf(" Lat");
  178. }
  179. if (res->Flags & PNP_EXTENDED_IRQ_POLARITY ) {
  180. dprintf(" Edg");
  181. }
  182. if (res->Flags & PNP_EXTENDED_IRQ_SHARED) {
  183. dprintf(" Shr");
  184. } else {
  185. dprintf(" Exc");
  186. }
  187. if (res->Flags & PNP_EXTENDED_IRQ_RESOURCE_CONSUMER_ONLY) {
  188. dprintf(" Con");
  189. } else {
  190. dprintf(" Prod Con");
  191. }
  192. dprintf("\n");
  193. break;
  194. }
  195. case TAG_DMA: {
  196. PPNP_DMA_DESCRIPTOR res = (PPNP_DMA_DESCRIPTOR) dataBuffer;
  197. UCHAR channel = 0;
  198. UCHAR mask = res->ChannelMask;
  199. dprintf("%d - TAG_DMA -", tagCount );
  200. for (; mask; channel++, mask >>= 1) {
  201. if (mask & 1) {
  202. dprintf(" %d", channel);
  203. }
  204. }
  205. switch( (res->Flags & PNP_DMA_SIZE_MASK) ) {
  206. case PNP_DMA_SIZE_8:
  207. dprintf(" 8bit");
  208. break;
  209. case PNP_DMA_SIZE_8_AND_16:
  210. dprintf(" 8-16bit");
  211. break;
  212. case PNP_DMA_SIZE_16:
  213. dprintf(" 16bit");
  214. break;
  215. case PNP_DMA_SIZE_RESERVED:
  216. default:
  217. dprintf(" ??bit");
  218. break;
  219. }
  220. if (res->Flags & PNP_DMA_BUS_MASTER) {
  221. dprintf(" BM");
  222. }
  223. switch( (res->Flags & PNP_DMA_TYPE_MASK) ) {
  224. default:
  225. case PNP_DMA_TYPE_COMPATIBLE:
  226. dprintf(" Com");
  227. break;
  228. case PNP_DMA_TYPE_A:
  229. dprintf(" A");
  230. break;
  231. case PNP_DMA_TYPE_B:
  232. dprintf(" B");
  233. break;
  234. case PNP_DMA_TYPE_F:
  235. dprintf(" F");
  236. }
  237. dprintf("\n");
  238. break;
  239. }
  240. case TAG_START_DEPEND:
  241. indentLevel++;
  242. dprintf("%d - TAG_START_DEPEND\n", tagCount);
  243. break;
  244. case TAG_END_DEPEND:
  245. indentLevel = 0;
  246. dprintf("%d - TAG_END_DEPEND\n", tagCount);
  247. break;
  248. case TAG_IO: {
  249. PPNP_PORT_DESCRIPTOR res = (PPNP_PORT_DESCRIPTOR) dataBuffer;
  250. dprintf(
  251. "%d - TAG_IO - 0x%x-0x%x A:0x%x L:0x%x",
  252. tagCount,
  253. res->MinimumAddress,
  254. res->MaximumAddress,
  255. res->Alignment,
  256. res->Length
  257. );
  258. switch (res->Information & PNP_PORT_DECODE_MASK) {
  259. default:
  260. case PNP_PORT_10_BIT_DECODE:
  261. dprintf(" 10bit");
  262. break;
  263. case PNP_PORT_16_BIT_DECODE:
  264. dprintf(" 16bit");
  265. break;
  266. }
  267. dprintf("\n");
  268. break;
  269. }
  270. case TAG_IO_FIXED: {
  271. PPNP_FIXED_PORT_DESCRIPTOR res =
  272. (PPNP_FIXED_PORT_DESCRIPTOR) dataBuffer;
  273. dprintf(
  274. "%d - TAG_FIXED_IO - 0x%x L:0x%x\n",
  275. tagCount,
  276. res->MinimumAddress,
  277. res->Length
  278. );
  279. break;
  280. }
  281. case TAG_MEMORY: {
  282. PPNP_MEMORY_DESCRIPTOR res =
  283. (PPNP_MEMORY_DESCRIPTOR) dataBuffer;
  284. dprintf(
  285. "%d - TAG_MEMORY24 - 0x%x-0x%x A:0x%x L:0x%x",
  286. tagCount,
  287. res->MinimumAddress,
  288. res->MaximumAddress,
  289. res->Alignment,
  290. res->MemorySize
  291. );
  292. if (res->Information & PNP_MEMORY_READ_WRITE) {
  293. dprintf(" RW");
  294. } else {
  295. dprintf(" R");
  296. }
  297. break;
  298. }
  299. case TAG_MEMORY32: {
  300. PPNP_MEMORY32_DESCRIPTOR res =
  301. (PPNP_MEMORY32_DESCRIPTOR) dataBuffer;
  302. dprintf(
  303. "%d - TAG_MEMORY32 - 0x%x-0x%x A:0x%x L:0x%x",
  304. tagCount,
  305. res->MinimumAddress,
  306. res->MaximumAddress,
  307. res->Alignment,
  308. res->MemorySize
  309. );
  310. if (res->Information & PNP_MEMORY_READ_WRITE) {
  311. dprintf(" RW");
  312. } else {
  313. dprintf(" R");
  314. }
  315. break;
  316. }
  317. case TAG_MEMORY32_FIXED: {
  318. PPNP_FIXED_MEMORY32_DESCRIPTOR res =
  319. (PPNP_FIXED_MEMORY32_DESCRIPTOR) dataBuffer;
  320. dprintf(
  321. "%d - TAG_FIXED_MEMORY32 - 0x%x L:0x%x",
  322. tagCount,
  323. res->BaseAddress,
  324. res->MemorySize
  325. );
  326. if (res->Information & PNP_MEMORY_READ_WRITE) {
  327. dprintf(" RW");
  328. } else {
  329. dprintf(" R");
  330. }
  331. break;
  332. }
  333. case TAG_WORD_ADDRESS: {
  334. PPNP_WORD_ADDRESS_DESCRIPTOR res =
  335. (PPNP_WORD_ADDRESS_DESCRIPTOR) dataBuffer;
  336. dprintf("%d - TAG_WORD_ADDRESS -", tagCount);
  337. switch (res->RFlag) {
  338. case 0:
  339. //
  340. // Memory range
  341. //
  342. dprintf(
  343. "Mem 0x%x-0x%x A:0x%x T:0x%x L:0x%x",
  344. res->MinimumAddress,
  345. res->MaximumAddress,
  346. res->Granularity,
  347. res->TranslationAddress,
  348. res->AddressLength
  349. );
  350. if (res->TFlag & PNP_ADDRESS_TYPE_MEMORY_READ_WRITE) {
  351. dprintf(" RW");
  352. } else {
  353. dprintf(" R");
  354. }
  355. switch (res->TFlag & PNP_ADDRESS_TYPE_MEMORY_MASK) {
  356. default:
  357. case PNP_ADDRESS_TYPE_MEMORY_NONCACHEABLE:
  358. dprintf(" NC");
  359. break;
  360. case PNP_ADDRESS_TYPE_MEMORY_CACHEABLE:
  361. dprintf(" C");
  362. break;
  363. case PNP_ADDRESS_TYPE_MEMORY_WRITE_COMBINE:
  364. dprintf(" WC");
  365. break;
  366. case PNP_ADDRESS_TYPE_MEMORY_PREFETCHABLE:
  367. dprintf(" PC");
  368. break;
  369. }
  370. break;
  371. case 1:
  372. //
  373. // IO range
  374. //
  375. dprintf(
  376. "IO 0x%x-0x%x A:0x%x T:0x%x L:0x%x",
  377. res->MinimumAddress,
  378. res->MaximumAddress,
  379. res->Granularity,
  380. res->TranslationAddress,
  381. res->AddressLength
  382. );
  383. if (res->TFlag & PNP_ADDRESS_TYPE_IO_ISA_RANGE) {
  384. dprintf(" ISA");
  385. }
  386. if (res->TFlag & PNP_ADDRESS_TYPE_IO_NON_ISA_RANGE) {
  387. dprintf(" Non-ISA");
  388. }
  389. break;
  390. case 2:
  391. dprintf(
  392. "Bus 0x%x-0x%x A:0x%x T:0x%x L:0x%x",
  393. res->MinimumAddress,
  394. res->MaximumAddress,
  395. res->Granularity,
  396. res->TranslationAddress,
  397. res->AddressLength
  398. );
  399. break;
  400. } // switch( buffer->RFlag )
  401. //
  402. // Global Flags
  403. //
  404. if (res->GFlag & PNP_ADDRESS_FLAG_CONSUMED_ONLY) {
  405. dprintf(" Consumed");
  406. }
  407. if (res->GFlag & PNP_ADDRESS_FLAG_SUBTRACTIVE_DECODE) {
  408. dprintf(" Subtractive");
  409. }
  410. if (res->GFlag & PNP_ADDRESS_FLAG_MINIMUM_FIXED) {
  411. dprintf(" MinFixed");
  412. }
  413. if (res->GFlag & PNP_ADDRESS_FLAG_MAXIMUM_FIXED) {
  414. dprintf(" MaxFixed");
  415. }
  416. if (increment > sizeof(PNP_WORD_ADDRESS_DESCRIPTOR) + 1) {
  417. dprintf(
  418. " %d<-%s",
  419. dataBuffer[sizeof(PNP_WORD_ADDRESS_DESCRIPTOR)],
  420. &(dataBuffer[sizeof(PNP_WORD_ADDRESS_DESCRIPTOR)+1])
  421. );
  422. }
  423. dprintf("\n");
  424. break;
  425. }
  426. case TAG_DOUBLE_ADDRESS: {
  427. PPNP_DWORD_ADDRESS_DESCRIPTOR res =
  428. (PPNP_DWORD_ADDRESS_DESCRIPTOR) dataBuffer;
  429. dprintf("%d - TAG_DWORD_ADDRESS -", tagCount);
  430. switch (res->RFlag) {
  431. case 0:
  432. //
  433. // Memory range
  434. //
  435. dprintf(
  436. "Mem 0x%x-0x%x A:0x%x T:0x%x L:0x%x",
  437. res->MinimumAddress,
  438. res->MaximumAddress,
  439. res->Granularity,
  440. res->TranslationAddress,
  441. res->AddressLength
  442. );
  443. if (res->TFlag & PNP_ADDRESS_TYPE_MEMORY_READ_WRITE) {
  444. dprintf(" RW");
  445. } else {
  446. dprintf(" R");
  447. }
  448. switch (res->TFlag & PNP_ADDRESS_TYPE_MEMORY_MASK) {
  449. default:
  450. case PNP_ADDRESS_TYPE_MEMORY_NONCACHEABLE:
  451. dprintf(" NC");
  452. break;
  453. case PNP_ADDRESS_TYPE_MEMORY_CACHEABLE:
  454. dprintf(" C");
  455. break;
  456. case PNP_ADDRESS_TYPE_MEMORY_WRITE_COMBINE:
  457. dprintf(" WC");
  458. break;
  459. case PNP_ADDRESS_TYPE_MEMORY_PREFETCHABLE:
  460. dprintf(" PC");
  461. break;
  462. }
  463. break;
  464. case 1:
  465. //
  466. // IO range
  467. //
  468. dprintf(
  469. "IO 0x%x-0x%x A:0x%x T:0x%x L:0x%x",
  470. res->MinimumAddress,
  471. res->MaximumAddress,
  472. res->Granularity,
  473. res->TranslationAddress,
  474. res->AddressLength
  475. );
  476. if (res->TFlag & PNP_ADDRESS_TYPE_IO_ISA_RANGE) {
  477. dprintf(" ISA");
  478. }
  479. if (res->TFlag & PNP_ADDRESS_TYPE_IO_NON_ISA_RANGE) {
  480. dprintf(" Non-ISA");
  481. }
  482. break;
  483. case 2:
  484. dprintf(
  485. "Bus 0x%x-0x%x A:0x%x T:0x%x L:0x%x",
  486. res->MinimumAddress,
  487. res->MaximumAddress,
  488. res->Granularity,
  489. res->TranslationAddress,
  490. res->AddressLength
  491. );
  492. break;
  493. } // switch( buffer->RFlag )
  494. //
  495. // Global Flags
  496. //
  497. if (res->GFlag & PNP_ADDRESS_FLAG_CONSUMED_ONLY) {
  498. dprintf(" Consumed");
  499. }
  500. if (res->GFlag & PNP_ADDRESS_FLAG_SUBTRACTIVE_DECODE) {
  501. dprintf(" Subtractive");
  502. }
  503. if (res->GFlag & PNP_ADDRESS_FLAG_MINIMUM_FIXED) {
  504. dprintf(" MinFixed");
  505. }
  506. if (res->GFlag & PNP_ADDRESS_FLAG_MAXIMUM_FIXED) {
  507. dprintf(" MaxFixed");
  508. }
  509. if (increment > sizeof(PNP_DWORD_ADDRESS_DESCRIPTOR) + 1) {
  510. dprintf(
  511. " %d<-%s",
  512. (UCHAR) dataBuffer[sizeof(PNP_DWORD_ADDRESS_DESCRIPTOR)],
  513. &(dataBuffer[sizeof(PNP_DWORD_ADDRESS_DESCRIPTOR)+1])
  514. );
  515. }
  516. dprintf("\n");
  517. break;
  518. }
  519. case TAG_QUAD_ADDRESS: {
  520. PPNP_QWORD_ADDRESS_DESCRIPTOR res =
  521. (PPNP_QWORD_ADDRESS_DESCRIPTOR) dataBuffer;
  522. dprintf("%d - TAG_QWORD_ADDRESS -", tagCount);
  523. switch (res->RFlag) {
  524. case 0:
  525. //
  526. // Memory range
  527. //
  528. dprintf(
  529. "Mem 0x%x-0x%x A:0x%x T:0x%x L:0x%x",
  530. res->MinimumAddress,
  531. res->MaximumAddress,
  532. res->Granularity,
  533. res->TranslationAddress,
  534. res->AddressLength
  535. );
  536. if (res->TFlag & PNP_ADDRESS_TYPE_MEMORY_READ_WRITE) {
  537. dprintf(" RW");
  538. } else {
  539. dprintf(" R");
  540. }
  541. switch (res->TFlag & PNP_ADDRESS_TYPE_MEMORY_MASK) {
  542. default:
  543. case PNP_ADDRESS_TYPE_MEMORY_NONCACHEABLE:
  544. dprintf(" NC");
  545. break;
  546. case PNP_ADDRESS_TYPE_MEMORY_CACHEABLE:
  547. dprintf(" C");
  548. break;
  549. case PNP_ADDRESS_TYPE_MEMORY_WRITE_COMBINE:
  550. dprintf(" WC");
  551. break;
  552. case PNP_ADDRESS_TYPE_MEMORY_PREFETCHABLE:
  553. dprintf(" PC");
  554. break;
  555. }
  556. break;
  557. case 1:
  558. //
  559. // IO range
  560. //
  561. dprintf(
  562. "IO 0x%x-0x%x A:0x%x T:0x%x L:0x%x",
  563. res->MinimumAddress,
  564. res->MaximumAddress,
  565. res->Granularity,
  566. res->TranslationAddress,
  567. res->AddressLength
  568. );
  569. if (res->TFlag & PNP_ADDRESS_TYPE_IO_ISA_RANGE) {
  570. dprintf(" ISA");
  571. }
  572. if (res->TFlag & PNP_ADDRESS_TYPE_IO_NON_ISA_RANGE) {
  573. dprintf(" Non-ISA");
  574. }
  575. break;
  576. case 2:
  577. dprintf(
  578. "Bus 0x%x-0x%x A:0x%x T:0x%x L:0x%x",
  579. res->MinimumAddress,
  580. res->MaximumAddress,
  581. res->Granularity,
  582. res->TranslationAddress,
  583. res->AddressLength
  584. );
  585. break;
  586. } // switch( buffer->RFlag )
  587. //
  588. // Global Flags
  589. //
  590. if (res->GFlag & PNP_ADDRESS_FLAG_CONSUMED_ONLY) {
  591. dprintf(" Consumed");
  592. }
  593. if (res->GFlag & PNP_ADDRESS_FLAG_SUBTRACTIVE_DECODE) {
  594. dprintf(" Subtractive");
  595. }
  596. if (res->GFlag & PNP_ADDRESS_FLAG_MINIMUM_FIXED) {
  597. dprintf(" MinFixed");
  598. }
  599. if (res->GFlag & PNP_ADDRESS_FLAG_MAXIMUM_FIXED) {
  600. dprintf(" MaxFixed");
  601. }
  602. if (increment > sizeof(PNP_QWORD_ADDRESS_DESCRIPTOR) + 1) {
  603. dprintf(
  604. " %d<-%s",
  605. (UCHAR) dataBuffer[sizeof(PNP_QWORD_ADDRESS_DESCRIPTOR)],
  606. &(dataBuffer[sizeof(PNP_QWORD_ADDRESS_DESCRIPTOR)+1])
  607. );
  608. }
  609. dprintf("\n");
  610. break;
  611. }
  612. case TAG_END:
  613. dprintf("%d - TAG_END\n", tagCount);
  614. if (dataBuffer) {
  615. LocalFree(dataBuffer );
  616. }
  617. return;
  618. default:
  619. dprintf("%d - TAG_UNKNOWN %d\n", tagCount, currentTag );
  620. break;
  621. } // switch
  622. //
  623. // Free the buffer if it was allocated
  624. //
  625. if (dataBuffer != NULL) {
  626. LocalFree( dataBuffer );
  627. dataBuffer = NULL;
  628. }
  629. //
  630. // Update the current address and tag number
  631. //
  632. tagCount++;
  633. currentAddress += increment;
  634. } // while
  635. }