Source code of Windows XP (NT5)
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.

461 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. registry.c
  5. Abstract:
  6. This module contains the code that dumps pccard info from the registry
  7. Author:
  8. Neil Sandlin (neilsa) 11 Feb 1999
  9. Environment:
  10. User mode
  11. Revision History :
  12. --*/
  13. #include "pch.h"
  14. #define PCMCIA_REGISTRY_CONTROLLER_TYPE "OtherController"
  15. VOID
  16. DumpIrqMap(
  17. PUCHAR IRQMap
  18. )
  19. {
  20. ULONG i;
  21. ULONG usable = 0, crossed = 0;
  22. for (i = 1; i < 16; i++) {
  23. if (IRQMap[i] == i) {
  24. usable++;
  25. } else if (IRQMap[i] != 0) {
  26. crossed++;
  27. }
  28. }
  29. if (usable == 0) {
  30. printf("NO usable IRQs found!\n");
  31. } else {
  32. if (usable == 1) {
  33. printf("1 usable IRQ found: ");
  34. } else {
  35. printf("%d usable IRQs found: ", usable);
  36. }
  37. for (i = 1; (i < 16) && usable; i++) {
  38. if (IRQMap[i] == i) {
  39. printf("%X", i);
  40. if (--usable != 0) {
  41. printf(",");
  42. }
  43. }
  44. }
  45. printf("\n");
  46. }
  47. if (crossed) {
  48. printf("Crosswired IRQs found!\n");
  49. for (i = 1; (i < 16) && crossed; i++) {
  50. if (IRQMap[i] && (IRQMap[i] != i)) {
  51. printf(" %X ==> %X\n", i, IRQMap[i]);
  52. crossed--;
  53. }
  54. }
  55. }
  56. printf("\n");
  57. }
  58. VOID
  59. DumpDetectedIrqMaskData(
  60. PVOID pArgData,
  61. ULONG DataSize
  62. )
  63. {
  64. static PUCHAR ErrorStrings[] = {
  65. "Unknown",
  66. "Scan Disabled",
  67. "Map Zero",
  68. "No Timer",
  69. "No Pic",
  70. "No Legacy Base",
  71. "Dup Legacy Base",
  72. "No Controllers"
  73. };
  74. #define MAX_ERROR_CODE 7
  75. if (DataSize == sizeof(CM_PCCARD_DEVICE_DATA)) {
  76. PCM_PCCARD_DEVICE_DATA pData = (PCM_PCCARD_DEVICE_DATA) pArgData;
  77. printf("Version 1.0 Data\n");
  78. if (pData->Flags & PCCARD_MAP_ERROR) {
  79. UCHAR ec = pData->ErrorCode;
  80. if (ec > MAX_ERROR_CODE) {
  81. ec = 0;
  82. }
  83. printf("\n*** Detection error: %s\n\n", ErrorStrings[ec]);
  84. }
  85. if (pData->Flags & PCCARD_DEVICE_PCI) {
  86. printf("Device is PCI enumerated\n");
  87. } else {
  88. printf("Device is legacy detected\n");
  89. }
  90. printf("DeviceId = %X\n", pData->DeviceId);
  91. printf("LegacyBase = %X\n", pData->LegacyBaseAddress);
  92. DumpIrqMap(pData->IRQMap);
  93. } else if (DataSize == sizeof(OLD_PCCARD_DEVICE_DATA)) {
  94. POLD_PCCARD_DEVICE_DATA pData = (POLD_PCCARD_DEVICE_DATA) pArgData;
  95. printf("Version 0.9 Data\n");
  96. printf("DeviceId = %X\n", pData->DeviceId);
  97. printf("LegacyBase = %X\n", pData->LegacyBaseAddress);
  98. DumpIrqMap(pData->IRQMap);
  99. } else {
  100. printf("Error: unrecognized data size\n");
  101. }
  102. }
  103. VOID
  104. DumpPcCardKey(
  105. HKEY handlePcCard
  106. )
  107. /*++
  108. Routine Description:
  109. This routine looks through the OtherController key for pccard entries
  110. created by NTDETECT. For each entry, the IRQ scan data is read in and
  111. saved for later.
  112. Arguments:
  113. handlePcCard - open handle to "OtherController" key in registry at
  114. HARDWARE\Description\System\MultifunctionAdapter\<ISA>
  115. Return value:
  116. status
  117. --*/
  118. {
  119. #define VALUE2_BUFFER_SIZE sizeof(CM_PCCARD_DEVICE_DATA) + sizeof(CM_FULL_RESOURCE_DESCRIPTOR)
  120. UCHAR valueInfo[VALUE2_BUFFER_SIZE];
  121. ULONG valueInfoSize;
  122. ULONG DataType;
  123. LONG status;
  124. LPTSTR subKeyInfo;
  125. HKEY handleSubKey = NULL;
  126. ULONG subKeyInfoSize;
  127. ULONG index;
  128. ULONG resultLength;
  129. DWORD SubKeys;
  130. BOOLEAN FoundPcCard = FALSE;
  131. status = RegQueryInfoKey(handlePcCard,
  132. NULL, NULL, 0,
  133. &SubKeys,
  134. &subKeyInfoSize,
  135. NULL, NULL, NULL, NULL, NULL, NULL);
  136. if ((status != ERROR_SUCCESS) &&
  137. (status != ERROR_MORE_DATA) &&
  138. (status != ERROR_INSUFFICIENT_BUFFER)) {
  139. printf("Error: unable to query info on PcCardKey\n");
  140. goto cleanup;
  141. }
  142. subKeyInfo = malloc(subKeyInfoSize+1);
  143. if (!subKeyInfo) {
  144. printf("Error: unable to malloc subKeyInfo (%d)\n", subKeyInfoSize+1);
  145. goto cleanup;
  146. }
  147. for (index=0; index < SubKeys; index++) {
  148. //
  149. // Loop through the children of the PcCardController key
  150. //
  151. status = RegEnumKey(handlePcCard,
  152. index,
  153. subKeyInfo,
  154. subKeyInfoSize+1);
  155. if (status != NO_ERROR) {
  156. if (!FoundPcCard) {
  157. printf("\nError: unable to find pccard detection key\n\n");
  158. }
  159. goto cleanup;
  160. }
  161. if (handleSubKey) {
  162. // close handle from previous iteration
  163. RegCloseKey(handleSubKey);
  164. handleSubKey = NULL;
  165. }
  166. status = RegOpenKeyEx(handlePcCard,
  167. subKeyInfo,
  168. 0,
  169. KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE,
  170. &handleSubKey);
  171. if (status != NO_ERROR) {
  172. printf("Error: unable to open enumerated key %s (%d)\n", subKeyInfo, status);
  173. goto cleanup;
  174. }
  175. //
  176. // Get the value of "Identifier"
  177. //
  178. valueInfoSize = VALUE2_BUFFER_SIZE;
  179. status = RegQueryValueEx(handleSubKey,
  180. "Identifier",
  181. 0,
  182. &DataType,
  183. valueInfo,
  184. &valueInfoSize
  185. );
  186. if (status == NO_ERROR) {
  187. if ((valueInfoSize == 17) &&
  188. (valueInfo[0] == 'P') &&
  189. (valueInfo[1] == 'c') &&
  190. (valueInfo[2] == 'C') &&
  191. (valueInfo[3] == 'a') &&
  192. (valueInfo[4] == 'r') &&
  193. (valueInfo[5] == 'd')) {
  194. FoundPcCard = TRUE;
  195. //
  196. // Get the IRQ detection data
  197. //
  198. valueInfoSize = VALUE2_BUFFER_SIZE;
  199. status = RegQueryValueEx(handleSubKey,
  200. "Configuration Data",
  201. 0,
  202. &DataType,
  203. valueInfo,
  204. &valueInfoSize
  205. );
  206. if (status == NO_ERROR) {
  207. PCM_FULL_RESOURCE_DESCRIPTOR pFullDesc = (PCM_FULL_RESOURCE_DESCRIPTOR) valueInfo;
  208. PCM_PARTIAL_RESOURCE_DESCRIPTOR pPartialDesc = (PCM_PARTIAL_RESOURCE_DESCRIPTOR) pFullDesc->PartialResourceList.PartialDescriptors;
  209. if (pPartialDesc->Type == CmResourceTypeDeviceSpecific) {
  210. printf("\n*** PcCard Irq Detection Data:%s ***\n\n", subKeyInfo);
  211. DumpDetectedIrqMaskData((PVOID)((ULONG_PTR)&pPartialDesc->u.DeviceSpecificData + 3*sizeof(ULONG)),
  212. pPartialDesc->u.DeviceSpecificData.DataSize);
  213. }
  214. }
  215. }
  216. }
  217. }
  218. cleanup:
  219. if (handleSubKey) {
  220. RegCloseKey(handleSubKey);
  221. }
  222. if (subKeyInfo) {
  223. free(subKeyInfo);
  224. }
  225. return;
  226. }
  227. VOID
  228. DumpIrqScanInfo(
  229. VOID
  230. )
  231. /*++
  232. Routine Description:
  233. This routine finds the "OtherController" entry in
  234. HARDWARE\Description\System\MultifunctionAdapter\<ISA>. This is
  235. where NTDETECT stores irq scan results.
  236. Arguments:
  237. Return value:
  238. status
  239. --*/
  240. {
  241. #define VALUE_BUFFER_SIZE 4
  242. UCHAR valueInfo[VALUE_BUFFER_SIZE];
  243. ULONG valueInfoSize;
  244. HKEY handleRoot = NULL;
  245. HKEY handleSubKey = NULL;
  246. HKEY handlePcCard = NULL;
  247. LPTSTR subKeyInfo = NULL;
  248. ULONG subKeyInfoSize;
  249. LONG status;
  250. ULONG resultLength;
  251. ULONG index;
  252. ULONG DataType;
  253. DWORD SubKeys;
  254. BOOLEAN FoundIsa = FALSE;
  255. //
  256. // Get a handle to the MultifunctionAdapter key
  257. //
  258. status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  259. "HARDWARE\\DESCRIPTION\\System\\MultiFunctionAdapter",
  260. 0,
  261. KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE,
  262. &handleRoot);
  263. if (status != NO_ERROR) {
  264. printf("Error: unable to open MultiFunctionAdapter key (%d)\n", status);
  265. goto cleanup;
  266. }
  267. status = RegQueryInfoKey(handleRoot,
  268. NULL, NULL, 0,
  269. &SubKeys,
  270. &subKeyInfoSize,
  271. NULL, NULL, NULL, NULL, NULL, NULL);
  272. if ((status != ERROR_SUCCESS) &&
  273. (status != ERROR_MORE_DATA) &&
  274. (status != ERROR_INSUFFICIENT_BUFFER)) {
  275. printf("Error: unable to query info on MultiFunctionAdapter key (%d)\n", status);
  276. goto cleanup;
  277. }
  278. subKeyInfo = malloc(subKeyInfoSize+1);
  279. if (!subKeyInfo) {
  280. printf("Error: unable to malloc subKeyInfo (%d)\n", subKeyInfoSize+1);
  281. goto cleanup;
  282. }
  283. for (index=0; index < SubKeys; index++) {
  284. //
  285. // Loop through the children of "MultifunctionAdapter"
  286. //
  287. status = RegEnumKey(handleRoot,
  288. index,
  289. subKeyInfo,
  290. subKeyInfoSize+1);
  291. if (status != NO_ERROR) {
  292. if (!FoundIsa) {
  293. printf("Error: ISA key not found (%d)\n", status);
  294. }
  295. goto cleanup;
  296. }
  297. if (handleSubKey) {
  298. // close handle from previous iteration
  299. RegCloseKey(handleSubKey);
  300. handleSubKey = NULL;
  301. }
  302. status = RegOpenKeyEx(handleRoot,
  303. subKeyInfo,
  304. 0,
  305. KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE,
  306. &handleSubKey);
  307. if (status != NO_ERROR) {
  308. printf("Error: unable to open enumerated key %s (%d)\n", subKeyInfo, status);
  309. goto cleanup;
  310. }
  311. //
  312. // Get the value of "Identifier"
  313. //
  314. valueInfoSize = VALUE_BUFFER_SIZE;
  315. status = RegQueryValueEx(handleSubKey,
  316. "Identifier",
  317. 0,
  318. &DataType,
  319. valueInfo,
  320. &valueInfoSize
  321. );
  322. if (status == NO_ERROR) {
  323. if ((valueInfoSize == 4) &&
  324. (valueInfo[0] == 'I') &&
  325. (valueInfo[1] == 'S') &&
  326. (valueInfo[2] == 'A') &&
  327. (valueInfo[3] == 0)) {
  328. FoundIsa = TRUE;
  329. status = RegOpenKeyEx(handleSubKey,
  330. PCMCIA_REGISTRY_CONTROLLER_TYPE,
  331. 0,
  332. KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE,
  333. &handlePcCard);
  334. if (status == NO_ERROR) {
  335. DumpPcCardKey(handlePcCard);
  336. RegCloseKey(handlePcCard);
  337. } else {
  338. printf("\nError: unable to find pccard detection data\n\n");
  339. }
  340. }
  341. }
  342. }
  343. cleanup:
  344. if (handleRoot) {
  345. RegCloseKey(handleRoot);
  346. }
  347. if (handleSubKey) {
  348. RegCloseKey(handleSubKey);
  349. }
  350. if (subKeyInfo) {
  351. free(subKeyInfo);
  352. }
  353. }