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.

680 lines
21 KiB

  1. #include "pch.h"
  2. #include "cmdata.h"
  3. BOOL
  4. SoftPCI_GetNextResourceDescriptorData(
  5. IN OUT PRES_DES ResourceDescriptor,
  6. OUT PCM_RES_DATA CmResData
  7. );
  8. VOID
  9. SoftPCI_FreeResourceDescriptorData(
  10. IN PCM_RES_DATA CmResData
  11. );
  12. VOID
  13. SoftPCI_DumpCmResData(
  14. IN PCM_RES_DATA CmResData,
  15. OUT PWCHAR Buffer
  16. );
  17. VOID
  18. SoftPCI_EnableDisableDeviceNode(
  19. IN DEVNODE DeviceNode,
  20. IN BOOL EnableDevice
  21. )
  22. {
  23. if (EnableDevice) {
  24. CM_Enable_DevNode(DeviceNode, 0);
  25. }else{
  26. if ((MessageBox(g_SoftPCIMainWnd,
  27. L"This option will disable and unloaded the driver for this device. HW remains physically present.",
  28. L"WARNING", MB_OKCANCEL)) == IDOK){
  29. CM_Disable_DevNode(DeviceNode, 0);
  30. }
  31. }
  32. }
  33. BOOL
  34. SoftPCI_GetDeviceNodeProblem(
  35. IN DEVNODE DeviceNode,
  36. OUT PULONG DeviceProblem
  37. )
  38. {
  39. CONFIGRET cr;
  40. ULONG dnStatus;
  41. cr = CM_Get_DevNode_Status(&dnStatus, DeviceProblem, DeviceNode, 0);
  42. if (cr == CR_SUCCESS &&
  43. ((dnStatus & DN_HAS_PROBLEM) != 0)) {
  44. //
  45. // We have a problem, if it that we are disabled then return TRUE
  46. //
  47. return TRUE;
  48. }
  49. return FALSE;
  50. }
  51. BOOL
  52. SoftPCI_GetBusDevFuncFromDevnode(
  53. IN DEVNODE Dn,
  54. OUT PULONG Bus,
  55. OUT PSOFTPCI_SLOT Slot
  56. )
  57. /*--
  58. Routine Description:
  59. This function takes a devnode and works out the devices Bus, Device, and Function
  60. numbers.
  61. Arguments:
  62. Dn - DeviceNode to get location info for
  63. Bus - retrieved bus number
  64. Dev - retrieved device number
  65. Func - retrieved function number
  66. Return Value:
  67. TRUE if successful, FALSE otherwise
  68. --*/
  69. {
  70. WCHAR locationinfo[MAX_PATH];
  71. ULONG length = MAX_PATH;
  72. ULONG device = 0, function = 0;
  73. //
  74. // Get the Location info of the device via the registry api
  75. //
  76. if ((CM_Get_DevNode_Registry_Property(Dn,
  77. CM_DRP_LOCATION_INFORMATION,
  78. NULL,
  79. &locationinfo,
  80. &length,
  81. 0
  82. ))==CR_SUCCESS){
  83. //
  84. // Now scan the returned information for the numbers we are after.
  85. //
  86. // Note: This is dependant on the format of the loaction information
  87. // taken from the registry and if it should ever change this will break.
  88. // Should probably look into better solution.
  89. //
  90. if (swscanf(locationinfo,
  91. L"PCI bus %d, device %d, function %d",
  92. Bus, &device, &function)) {
  93. Slot->Device = (UCHAR)device;
  94. Slot->Function = (UCHAR)function;
  95. SoftPCI_Debug(SoftPciDevice,
  96. L"Bus 0x%02x, Device 0x%02x, Function 0x%02x\n",
  97. *Bus, device, function);
  98. return TRUE;
  99. }
  100. }
  101. SoftPCI_Debug(SoftPciDevice, L"Failed to get Bus Dev Func for devnode 0x%x\n", Dn);
  102. return FALSE;
  103. }
  104. BOOL
  105. SoftPCI_GetFriendlyNameFromDevNode(
  106. IN DEVNODE Dn,
  107. IN PWCHAR Buffer
  108. )
  109. {
  110. ULONG length = MAX_PATH;
  111. //
  112. // Get the FriendlyName of the device
  113. //
  114. if ((CM_Get_DevNode_Registry_Property(Dn,
  115. CM_DRP_DEVICEDESC,
  116. NULL,
  117. Buffer,
  118. &length,
  119. 0
  120. )) != CR_SUCCESS){
  121. SoftPCI_Debug(SoftPciDevice, L"Failed to get friendly name for devnode 0x%x\n", Dn);
  122. return FALSE;
  123. }
  124. return TRUE;
  125. }
  126. BOOL
  127. SoftPCI_GetPciRootBusNumber(
  128. IN DEVNODE Dn,
  129. OUT PULONG Bus
  130. )
  131. {
  132. DEVNODE child = 0;
  133. ULONG length = sizeof(ULONG);
  134. *Bus = 0xFFFFFFFF;
  135. if ((CM_Get_Child(&child, Dn, 0)==CR_SUCCESS)){
  136. if ((CM_Get_DevNode_Registry_Property(child,
  137. CM_DRP_BUSNUMBER,
  138. NULL,
  139. Bus,
  140. &length,
  141. 0
  142. ))!=CR_SUCCESS){
  143. SoftPCI_Debug(SoftPciDevice, L"Failed to get bus number from child 0x%x for devnode 0x%x\n",
  144. child, Dn);
  145. return FALSE;
  146. }
  147. }
  148. return TRUE;
  149. }
  150. BOOL
  151. SoftPCI_GetNextResourceDescriptorData(
  152. IN OUT PRES_DES ResourceDescriptor,
  153. OUT PCM_RES_DATA CmResData
  154. )
  155. {
  156. RES_DES resDes;
  157. ULONG resSize = 0;
  158. PULONG resBuf = NULL;
  159. RESOURCEID resID;
  160. CONFIGRET cr = CR_SUCCESS;
  161. if (CmResData->ResourceDescriptor) {
  162. free(CmResData->ResourceDescriptor);
  163. CmResData->ResourceDescriptor = NULL;
  164. }
  165. //
  166. // Stash away the current RES_DES handle so we dont lose it and leak mem
  167. //
  168. resDes = *ResourceDescriptor;
  169. if ((CM_Get_Next_Res_Des(ResourceDescriptor,
  170. *ResourceDescriptor,
  171. ResType_All,
  172. &resID,
  173. 0
  174. )==CR_SUCCESS)){
  175. if ((CM_Get_Res_Des_Data_Size(&resSize, *ResourceDescriptor, 0)) == CR_SUCCESS){
  176. resBuf = (PULONG) calloc(1, resSize);
  177. if (resBuf == NULL) {
  178. return FALSE;
  179. }
  180. CmResData->ResourceId = resID;
  181. CmResData->DescriptorSize = resSize;
  182. CmResData->ResourceDescriptor = resBuf;
  183. SoftPCI_Debug(SoftPciCmData, L"GetNextResourceDescriptorData - ResourceId = 0x%x\n", resID);
  184. SoftPCI_Debug(SoftPciCmData, L"GetNextResourceDescriptorData - DescriptorSize = 0x%x\n", resSize);
  185. if ((cr = CM_Get_Res_Des_Data(*ResourceDescriptor, resBuf, resSize, 0)) == CR_SUCCESS){
  186. SoftPCI_Debug(SoftPciCmData, L"GetNextResourceDescriptorData - ResourceDescriptor = 0x%x\n", resBuf);
  187. //
  188. // Free out last handle
  189. //
  190. CM_Free_Res_Des_Handle(resDes);
  191. return TRUE;
  192. }else{
  193. SoftPCI_Debug(SoftPciCmData, L"GetNextResourceDescriptorData - failed to get ResData. (%s)\n", SoftPCI_CmResultTable[cr]);
  194. }
  195. }
  196. }
  197. if (CmResData->ResourceDescriptor) {
  198. free(CmResData->ResourceDescriptor);
  199. CmResData->ResourceDescriptor = NULL;
  200. }
  201. return FALSE;
  202. }
  203. VOID
  204. SoftPCI_FreeResourceDescriptorData(
  205. IN PCM_RES_DATA CmResData
  206. )
  207. {
  208. if (CmResData->ResourceDescriptor) {
  209. free(CmResData->ResourceDescriptor);
  210. CmResData->ResourceDescriptor = NULL;
  211. }
  212. }
  213. BOOL
  214. SoftPCI_GetResources(
  215. PPCI_DN Pdn,
  216. PWCHAR Buffer,
  217. ULONG ConfigType
  218. )
  219. {
  220. BOOL result = FALSE;
  221. LOG_CONF logConf;
  222. RES_DES resDes;
  223. CM_RES_DATA cmResData;
  224. RtlZeroMemory(&cmResData, sizeof(CM_RES_DATA));
  225. //
  226. // First get the logconf.
  227. // Next get the first resource descrpitor.
  228. //
  229. if ((CM_Get_First_Log_Conf(&logConf, Pdn->DevNode, ConfigType)) == CR_SUCCESS){
  230. resDes = (RES_DES)logConf;
  231. while (SoftPCI_GetNextResourceDescriptorData((PRES_DES)&resDes,
  232. &cmResData)) {
  233. SoftPCI_Debug(SoftPciCmData, L"GetCurrentResources - Success!\n");
  234. SoftPCI_DumpCmResData(&cmResData, Buffer);
  235. SoftPCI_FreeResourceDescriptorData(&cmResData);
  236. result = TRUE;
  237. }
  238. //
  239. // Free out remaining RES_DES handle and then release the logconf handle
  240. //
  241. CM_Free_Res_Des_Handle(resDes);
  242. CM_Free_Log_Conf_Handle(logConf);
  243. }
  244. return result;
  245. }
  246. VOID
  247. SoftPCI_DumpCmResData(
  248. IN PCM_RES_DATA CmResData,
  249. OUT PWCHAR Buffer
  250. )
  251. {
  252. PMEM_DES memDes;
  253. PIO_DES ioDes;
  254. PDMA_DES dmaDes;
  255. PIRQ_DES irqDes;
  256. PBUSNUMBER_DES busDes;
  257. //PMEM_RANGE memRange;
  258. //PIO_RANGE ioRange;
  259. //PDMA_RANGE dmaRange;
  260. //PIRQ_RANGE irqRange;
  261. INT i = 0;
  262. UCHAR busNum;
  263. switch (CmResData->ResourceId){
  264. case ResType_Mem:
  265. memDes = (PMEM_DES) CmResData->ResourceDescriptor;
  266. if (CmResData->DescriptorSize < sizeof(MEM_DES)) {
  267. SoftPCI_Debug(SoftPciCmData, L"MEM No information available\n");
  268. break;
  269. }
  270. wsprintf(Buffer + wcslen(Buffer),
  271. L" MEM \tStart: 0x%08X\tEnd: 0x%08X\r\n",
  272. //L"\tMEM \t0x%08x - 0x%08x\r\n",
  273. (DWORD)memDes->MD_Alloc_Base,
  274. (DWORD)memDes->MD_Alloc_End
  275. );
  276. SoftPCI_Debug(SoftPciCmData,
  277. L"MEM Count:%08x Type: %08x Bas:%08x End:%08x Flags:%04x\n",
  278. memDes->MD_Count,
  279. memDes->MD_Type,
  280. (DWORD)memDes->MD_Alloc_Base,
  281. (DWORD)memDes->MD_Alloc_End,
  282. memDes->MD_Flags
  283. );
  284. #if 0
  285. memRange = (PMEM_RANGE)((LPBYTE)memDes + sizeof(MEM_DES));
  286. for (i = 0; i < (INT)(memDes->MD_Count); i++){
  287. SoftPCI_Debug(SoftPciCmData,
  288. L" Align:%08lx Bytes:%08lx Min:%08lx Max:%08lx Flags:%04x\n",
  289. (DWORD)memRange->MR_Align,
  290. memRange->MR_nBytes,
  291. (DWORD)memRange->MR_Min,
  292. (DWORD)memRange->MR_Max,
  293. memRange->MR_Flags
  294. );
  295. memRange++;
  296. }
  297. #endif
  298. break;
  299. case ResType_IO:
  300. ioDes = (PIO_DES) CmResData->ResourceDescriptor;
  301. if (CmResData->DescriptorSize < sizeof(IO_DES)) {
  302. SoftPCI_Debug(SoftPciCmData, L"IO No information available\n");
  303. break;
  304. }
  305. wsprintf(Buffer + wcslen(Buffer),
  306. L" IO \tStart: 0x%08X\tEnd: 0x%08X\r\n",
  307. //L"\tIO \t0x%08x - 0x%08x\r\n",
  308. (DWORD)ioDes->IOD_Alloc_Base,
  309. (DWORD)ioDes->IOD_Alloc_End
  310. );
  311. SoftPCI_Debug(SoftPciCmData,
  312. L"IO Count:%08x Type: %08x Bas:%08x End:%08x Flags:%04x %s\n",
  313. ioDes->IOD_Count,
  314. ioDes->IOD_Type,
  315. (DWORD)ioDes->IOD_Alloc_Base,
  316. (DWORD)ioDes->IOD_Alloc_End,
  317. ioDes->IOD_DesFlags,
  318. ((ioDes->IOD_DesFlags & fIOD_PortType)==fIOD_Memory) ? L"(memory)" : L""
  319. );
  320. break;
  321. case ResType_IRQ:
  322. irqDes = (PIRQ_DES) CmResData->ResourceDescriptor;
  323. if (CmResData->DescriptorSize < sizeof(IRQ_DES)) {
  324. SoftPCI_Debug(SoftPciCmData, L"IRQ No information available\n");
  325. break;
  326. }
  327. wsprintf(Buffer + wcslen(Buffer),
  328. L" IRQ \tStart: 0x%08X\tEnd: 0x%08X\r\n",
  329. //L"\tIRQ \t0x%08\r\n",
  330. irqDes->IRQD_Alloc_Num,
  331. irqDes->IRQD_Alloc_Num
  332. );
  333. SoftPCI_Debug(SoftPciCmData,
  334. L"IRQ Count:%04X Type:%04X Channel:%04X Affinity:%0Xx Flags:%04x\n",
  335. irqDes->IRQD_Count,
  336. irqDes->IRQD_Type,
  337. irqDes->IRQD_Alloc_Num,
  338. irqDes->IRQD_Affinity,
  339. irqDes->IRQD_Flags);
  340. break;
  341. case ResType_BusNumber:
  342. busDes = (PBUSNUMBER_DES) CmResData->ResourceDescriptor;
  343. if (CmResData->DescriptorSize < sizeof(BUSNUMBER_DES)) {
  344. SoftPCI_Debug(SoftPciCmData, L"BUS No information available\n");
  345. break;
  346. }
  347. wsprintf(Buffer + wcslen(Buffer),
  348. L" BUS \tStart: 0x%08X\tEnd: 0x%08X\r\n",
  349. busDes->BUSD_Alloc_Base,
  350. busDes->BUSD_Alloc_End
  351. );
  352. break;
  353. case ResType_DMA:
  354. dmaDes = (PDMA_DES) CmResData->ResourceDescriptor;
  355. if (CmResData->DescriptorSize < sizeof(DMA_DES)) {
  356. SoftPCI_Debug(SoftPciCmData, L"DMA No information available\n");
  357. break;
  358. }
  359. wsprintf(Buffer + wcslen(Buffer),
  360. L" DMA \tStart: 0x%08X\t End: 0x%08X\r\n",
  361. dmaDes->DD_Alloc_Chan,
  362. dmaDes->DD_Alloc_Chan
  363. );
  364. SoftPCI_Debug(SoftPciCmData,
  365. L"DMA Count:%04x Type:%04x Channel:%04x Flags:%04x\n",
  366. dmaDes->DD_Count,
  367. dmaDes->DD_Type,
  368. dmaDes->DD_Alloc_Chan,
  369. dmaDes->DD_Flags
  370. );
  371. break;
  372. default:
  373. SoftPCI_Debug(SoftPciCmData, L"ResourceId 0x%x not handled!\n", CmResData->ResourceId);
  374. break;
  375. }
  376. }
  377. #if 0
  378. // Display the header information on one line.
  379. wsprintf(szBuf, TEXT("MEM Count:%08x Type: %08x Bas:%08x End:%08x Flags:%04x ("),
  380. lpMemDes->MD_Count,
  381. lpMemDes->MD_Type,
  382. (DWORD)lpMemDes->MD_Alloc_Base,
  383. (DWORD)lpMemDes->MD_Alloc_End,
  384. lpMemDes->MD_Flags );
  385. PrintMemFlags(lpMemDes->MD_Flags, szBuf+lstrlen(szBuf)) ;
  386. lstrcat(szBuf, TEXT(")\r\n")) ;
  387. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  388. lpMemRange = (MEM_RANGE *)((LPBYTE)lpMemDes+sizeof(MEM_DES));
  389. for (iX = 0; iX < (int)(lpMemDes->MD_Count); iX++ )
  390. {
  391. wsprintf(szBuf, TEXT(" Align:%08lx Bytes:%08lx Min:%08lx Max:%08lx Flags:%04x ("),
  392. (DWORD)lpMemRange->MR_Align,
  393. lpMemRange->MR_nBytes,
  394. (DWORD)lpMemRange->MR_Min,
  395. (DWORD)lpMemRange->MR_Max,
  396. lpMemRange->MR_Flags
  397. );
  398. PrintMemFlags(lpMemRange->MR_Flags, szBuf+lstrlen(szBuf)) ;
  399. lstrcat(szBuf, TEXT(")\r\n")) ;
  400. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  401. lpMemRange++;
  402. }
  403. break;
  404. case ResType_IO:
  405. lpIODes = (IO_DES *) lpbConfig;
  406. if (dwSize<sizeof(IO_DES)) {
  407. wsprintf(szBuf, TEXT("IO No information available\r\n"));
  408. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  409. break;
  410. }
  411. wsprintf(szBuf, TEXT("IO Count:%08x Type: %08x Bas:%08x End:%08x Flags:%04x %s\r\n"),
  412. lpIODes->IOD_Count,
  413. lpIODes->IOD_Type,
  414. (DWORD)lpIODes->IOD_Alloc_Base,
  415. (DWORD)lpIODes->IOD_Alloc_End,
  416. lpIODes->IOD_DesFlags,
  417. ((lpIODes->IOD_DesFlags&fIOD_PortType)==fIOD_Memory) ? TEXT("(memory)") : TEXT("")
  418. );
  419. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  420. lpIORange = (IO_RANGE *)((LPBYTE)lpIODes+sizeof(IO_DES));
  421. for (iX = 0; iX < (int)(lpIODes->IOD_Count); iX++ )
  422. {
  423. nAliasType=GetAliasType((DWORD)lpIORange->IOR_Alias) ;
  424. wsprintf(szBuf, TEXT(" Align:%08x Ports:%08x Min:%08x Max:%08x Flags:%04x %sAls:%02x (%s)\r\n"),
  425. (DWORD)lpIORange->IOR_Align,
  426. lpIORange->IOR_nPorts,
  427. (DWORD)lpIORange->IOR_Min,
  428. (DWORD)lpIORange->IOR_Max,
  429. lpIORange->IOR_RangeFlags,
  430. ((lpIORange->IOR_RangeFlags&fIOD_PortType)==fIOD_Memory) ? TEXT("(memory) ") : TEXT(""),
  431. (DWORD)lpIORange->IOR_Alias,
  432. lpszAliasNames[nAliasType]);
  433. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  434. lpIORange++;
  435. }
  436. break;
  437. case ResType_DMA:
  438. lpDMADes = (DMA_DES *) lpbConfig;
  439. if (dwSize<sizeof(DMA_DES)) {
  440. wsprintf(szBuf, TEXT("DMA No information available\r\n"));
  441. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  442. break;
  443. }
  444. wsprintf(szBuf, TEXT("DMA Count:%04x Type:%04x Channel:%04x Flags:%04x ("),
  445. lpDMADes->DD_Count,
  446. lpDMADes->DD_Type,
  447. lpDMADes->DD_Alloc_Chan,
  448. lpDMADes->DD_Flags);
  449. PrintDmaFlags(lpDMADes->DD_Flags, szBuf+lstrlen(szBuf)) ;
  450. lstrcat(szBuf, TEXT(")\r\n")) ;
  451. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  452. lpDMARange = (DMA_RANGE *)((LPBYTE)lpDMADes+sizeof(DMA_DES));
  453. for (iX = 0; iX < (int)(lpDMADes->DD_Count); iX++)
  454. {
  455. wsprintf(szBuf, TEXT(" Min:%04x Max:%04x Flags:%04x ("),
  456. lpDMARange->DR_Min,
  457. lpDMARange->DR_Max,
  458. lpDMARange->DR_Flags);
  459. PrintDmaFlags(lpDMARange->DR_Flags, szBuf+lstrlen(szBuf)) ;
  460. lstrcat(szBuf, TEXT(")\r\n")) ;
  461. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  462. lpDMARange++;
  463. }
  464. break;
  465. case ResType_IRQ:
  466. lpIRQDes = (IRQ_DES *) lpbConfig;
  467. if (dwSize<sizeof(IRQ_DES)) {
  468. wsprintf(szBuf, TEXT("IRQ No information available\r\n"));
  469. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  470. break;
  471. }
  472. wsprintf(szBuf, TEXT("IRQ Count:%04x Type:%04x Channel:%04x Affinity:%08x Flags:%04x ("),
  473. lpIRQDes->IRQD_Count,
  474. lpIRQDes->IRQD_Type,
  475. lpIRQDes->IRQD_Alloc_Num,
  476. lpIRQDes->IRQD_Affinity,
  477. lpIRQDes->IRQD_Flags);
  478. PrintIrqFlags(lpIRQDes->IRQD_Flags, szBuf+lstrlen(szBuf)) ;
  479. lstrcat(szBuf, TEXT(")\r\n")) ;
  480. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  481. lpIRQRange = (IRQ_RANGE *)((LPBYTE)lpIRQDes+sizeof(IRQ_DES));
  482. for (iX = 0; iX < (int)(lpIRQDes->IRQD_Count); iX++)
  483. {
  484. wsprintf(szBuf, TEXT(" Min:%04x Max:%04x Flags:%04x ("),
  485. lpIRQRange->IRQR_Min,
  486. lpIRQRange->IRQR_Max,
  487. lpIRQRange->IRQR_Flags);
  488. PrintIrqFlags(lpIRQRange->IRQR_Flags, szBuf+lstrlen(szBuf)) ;
  489. lstrcat(szBuf, TEXT(")\r\n")) ;
  490. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  491. lpIRQRange++;
  492. }
  493. break;
  494. case 0x43:
  495. bBus = *lpbConfig;
  496. if (dwSize<sizeof(*lpbConfig)) {
  497. wsprintf(szBuf, TEXT("BUS No information available\r\n"));
  498. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  499. break;
  500. }
  501. wsprintf(szBuf, TEXT("BUS %02x\r\n"), bBus);
  502. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  503. break;
  504. default:
  505. wsprintf(szBuf, TEXT("UKN Unknown resource %04x\r\n"), ridCurResType);
  506. lstrcat(lpszBuf+lstrlen(lpszBuf), szBuf);
  507. break;
  508. }
  509. lpbConfig+=dwSize;
  510. }
  511. }
  512. #endif