📄 wdc_diag_lib.c
字号:
case WDC_SIZE_32:
if (WDC_READ == direction)
dwStatus = fPciCfg ? WDC_PciReadCfg32(hDev, pReg->dwOffset, &u32Data) :
WDC_ReadAddr32(hDev, pReg->dwAddrSpace, pReg->dwOffset, &u32Data);
else
dwStatus = fPciCfg ? WDC_PciWriteCfg32(hDev, pReg->dwOffset, u32Data) :
WDC_WriteAddr32(hDev, pReg->dwAddrSpace, pReg->dwOffset, u32Data);
if (WD_STATUS_SUCCESS == dwStatus)
{
printf("%s 0x%X %s register %s\n", (WDC_READ == direction) ? "Read" : "Wrote",
u32Data, (WDC_READ == direction) ? "from" : "to", pReg->sName);
}
break;
case WDC_SIZE_64:
if (WDC_READ == direction)
dwStatus = fPciCfg ? WDC_PciReadCfg64(hDev, pReg->dwOffset, &u64Data) :
WDC_ReadAddr64(hDev, pReg->dwAddrSpace, pReg->dwOffset, &u64Data);
else
dwStatus = fPciCfg ? WDC_PciWriteCfg64(hDev, pReg->dwOffset, u64Data) :
WDC_WriteAddr64(hDev, pReg->dwAddrSpace, pReg->dwOffset, u64Data);
if (WD_STATUS_SUCCESS == dwStatus)
{
printf("%s 0x%"PRI64"X %s register %s\n", (WDC_READ == direction) ? "Read" : "Wrote",
u64Data, (WDC_READ == direction) ? "from" : "to", pReg->sName);
}
break;
default:
printf("Invalid register size (%ld)\n", pReg->dwSize);
return;
}
if (WD_STATUS_SUCCESS != dwStatus)
{
printf("Failed %s %s. Error 0x%lx - %s\n",
(WDC_READ == direction) ? "reading data from" : "writing data to",
pReg->sName, dwStatus, Stat2Str(dwStatus));
}
Exit:
printf("\n");
printf("Press ENTER to continue\n");
fgets(gsInput, sizeof(gsInput), stdin);
}
/* -----------------------------------------------
PCI
----------------------------------------------- */
/* Print PCI device location information */
void WDC_DIAG_PciSlotPrint(WD_PCI_SLOT *pPciSlot)
{
WDC_DIAG_PciSlotPrintFile(pPciSlot, stdout);
}
/* Print PCI device location information to file */
void WDC_DIAG_PciSlotPrintFile(WD_PCI_SLOT *pPciSlot, FILE *fp)
{
if (!pPciSlot)
{
WDC_DIAG_ERR("WDC_DIAG_PciSlotPrint: Error - NULL PCI slot pointer\n");
return;
}
fprintf(fp, "Bus 0x%lx, Slot 0x%lx, Function 0x%lx\n",
pPciSlot->dwBus, pPciSlot->dwSlot, pPciSlot->dwFunction);
}
/* Print PCI device location and resources information */
void WDC_DIAG_PciDeviceInfoPrint(WD_PCI_SLOT *pPciSlot, BOOL dump_cfg)
{
WDC_DIAG_PciDeviceInfoPrintFile(pPciSlot, stdout, dump_cfg);
}
/* Print PCI device location and resources information to file */
void WDC_DIAG_PciDeviceInfoPrintFile(WD_PCI_SLOT *pPciSlot, FILE *fp,
BOOL dump_cfg)
{
DWORD dwStatus;
WD_PCI_CARD_INFO deviceInfo;
if (!pPciSlot)
{
WDC_DIAG_ERR("WDC_DIAG_PciDeviceInfoPrint: Error - NULL PCI slot "
"pointer\n");
return;
}
fprintf(fp, " Location: ");
WDC_DIAG_PciSlotPrintFile(pPciSlot, fp);
if (dump_cfg)
{
UINT32 config;
DWORD dwOffset=0;
for (dwOffset=0; dwOffset<256; dwOffset+=sizeof(UINT32))
{
dwStatus = WDC_PciReadCfgBySlot32(pPciSlot, dwOffset, &config);
if (dwStatus)
{
WDC_DIAG_ERR(" Failed reading PCI configuration space.\n"
" Error 0x%lx - %s\n", dwStatus, Stat2Str(dwStatus));
return;
}
if ((dwOffset/4) % 8 == 0)
fprintf(fp, "%02lx ", dwOffset);
fprintf(fp, "%08x ", config);
if ((dwOffset/4) % 8 == 7)
fprintf(fp, "\n");
}
}
BZERO(deviceInfo);
deviceInfo.pciSlot = *pPciSlot;
dwStatus = WDC_PciGetDeviceInfo(&deviceInfo);
if ((WD_NO_RESOURCES_ON_DEVICE != dwStatus) &&
(WD_STATUS_SUCCESS != dwStatus))
{
WDC_DIAG_ERR(" Failed retrieving PCI resources information.\n"
" Error 0x%lx - %s\n", dwStatus, Stat2Str(dwStatus));
return;
}
WDC_DIAG_DeviceResourcesPrint(&deviceInfo.Card, 0, fp);
}
/* Print location and resources information for all connected PCI devices */
void WDC_DIAG_PciDevicesInfoPrintAll(BOOL dump_cfg)
{
WDC_DIAG_PciDevicesInfoPrintAllFile(stdout, dump_cfg);
}
/* Print location and resources information for all connected PCI devices to
* file */
void WDC_DIAG_PciDevicesInfoPrintAllFile(FILE *fp, BOOL dump_cfg)
{
DWORD dwStatus;
DWORD i, dwNumDevices;
WDC_PCI_SCAN_RESULT scanResult;
BZERO(scanResult);
dwStatus = WDC_PciScanDevices(0, 0, &scanResult);
if (WD_STATUS_SUCCESS != dwStatus)
{
fprintf(fp,"Failed scanning PCI bus. Error 0x%lx - %s\n",
dwStatus, Stat2Str(dwStatus));
return;
}
dwNumDevices = scanResult.dwNumDevices;
if (!dwNumDevices)
{
fprintf(fp,"No devices were found on the PCI bus\n");
return;
}
fprintf(fp,"\n");
fprintf(fp,"Found %ld devices on the PCI bus:\n", dwNumDevices);
fprintf(fp,"---------------------------------\n");
for (i = 0; i < dwNumDevices; i++)
{
fprintf(fp,"%2ld. Vendor ID: 0x%lX, Device ID: 0x%lX\n",
i + 1,
scanResult.deviceId[i].dwVendorId,
scanResult.deviceId[i].dwDeviceId);
WDC_DIAG_PciDeviceInfoPrintFile(&scanResult.deviceSlot[i], fp,
dump_cfg);
if (fp == stdout)
{
printf("Press ENTER to proceed to next device");
fgets(gsInput, sizeof(gsInput), stdin);
}
fprintf(fp, "\n");
}
}
/* -----------------------------------------------
PCMCIA
----------------------------------------------- */
/* Print PCMCIA device location information */
void WDC_DIAG_PcmciaSlotPrint(const WD_PCMCIA_SLOT *pPcmciaSlot)
{
if (!pPcmciaSlot)
{
WDC_DIAG_ERR("WDC_DIAG_PcmciaSlotPrint: Error - NULL PCMCIA slot pointer\n");
return;
}
printf("Bus 0x%x, Slot 0x%x, Function 0x%x\n",
(UINT32)pPcmciaSlot->uBus, (UINT32)pPcmciaSlot->uSocket,
(UINT32)pPcmciaSlot->uFunction);
}
/* Print PCMCIA device location and resources information */
void WDC_DIAG_PcmciaDeviceInfoPrint(const WD_PCMCIA_SLOT *pPcmciaSlot)
{
DWORD dwStatus;
WD_PCMCIA_CARD_INFO deviceInfo;
if (!pPcmciaSlot)
{
WDC_DIAG_ERR("WDC_DIAG_PcmciaDeviceInfoPrint: Error - NULL PCMCIA slot pointer\n");
return;
}
printf(" Location: ");
WDC_DIAG_PcmciaSlotPrint(pPcmciaSlot);
BZERO(deviceInfo);
deviceInfo.pcmciaSlot = *pPcmciaSlot;
dwStatus = WDC_PcmciaGetDeviceInfo(&deviceInfo);
if (WD_STATUS_SUCCESS != dwStatus)
{
WDC_DIAG_ERR(" Failed retrieving PCMCIA resources information.\n"
" Error 0x%lx - %s\n", dwStatus, Stat2Str(dwStatus));
return;
}
WDC_DIAG_DeviceResourcesPrint(&deviceInfo.Card, 0, stdout);
}
/* Print location and resources information for all connected PCMCIA devices */
void WDC_DIAG_PcmciaDevicesInfoPrintAll(void)
{
DWORD dwStatus;
DWORD i, dwNumDevices;
WDC_PCMCIA_SCAN_RESULT scanResult;
BZERO(scanResult);
dwStatus = WDC_PcmciaScanDevices(0, 0, &scanResult);
if (WD_STATUS_SUCCESS != dwStatus)
{
printf("Failed scanning PCMCIA bus. Error 0x%lx - %s\n",
dwStatus, Stat2Str(dwStatus));
return;
}
dwNumDevices = scanResult.dwNumDevices;
if (!dwNumDevices)
{
printf("No devices were found on the PCMCIA bus\n");
return;
}
printf("Found %ld devices on the PCMCIA bus:\n", dwNumDevices);
printf("-------------------------------------\n");
for (i = 0; i < dwNumDevices; i++)
{
printf("%2ld. Manufacturer ID: 0x%hX, Device ID: 0x%hX\n",
i + 1,
scanResult.deviceId[i].wManufacturerId,
scanResult.deviceId[i].wCardId);
WDC_DIAG_PcmciaDeviceInfoPrint(&scanResult.deviceSlot[i]);
printf("Press ENTER to proceed to next device\n");
fgets(gsInput, sizeof(gsInput), stdin);
}
}
/* Print tuple information for all tuples found in the PCMCIA attribute space */
void WDC_DIAG_PcmciaTuplesPrintAll(WDC_DEVICE_HANDLE hDev, BOOL fDumpData)
{
DWORD dwStatus;
DWORD dwOffset = 0;
BYTE header[2]; /* header[0] - tuple code; header[1] - tuple's data size */
if (!hDev)
{
WDC_DIAG_ERR("WDC_DIAG_PcmciaTuplesPrintAll: Error - NULL WDC device handle\n");
return;
}
while (1)
{
dwStatus = WDC_PcmciaReadAttribSpace(hDev, dwOffset, header, sizeof(header));
if (WD_STATUS_SUCCESS != dwStatus)
{
WDC_DIAG_ERR("Failed to read from offset 0x%lX of the PCMCIA atribute space.\n"
"Error 0x%lx - %s\n", dwOffset, dwStatus, Stat2Str(dwStatus));
return;
}
if (CISTPL_END == header[0])
return;
if (CISTPL_NULL == header[0])
{
dwOffset++;
continue;
}
printf("Tuple code (ID): 0x%02x, Data size: %2d bytes, Offset: 0x%02x\n",
(UINT32)header[0], (UINT32)header[1], (UINT32)dwOffset);
dwOffset += 2;
if (fDumpData)
{
if (header[1])
{
BYTE buf[0xFF];
BZERO(buf);
dwStatus = WDC_PcmciaReadAttribSpace(hDev, dwOffset, buf, header[1]);
if (WD_STATUS_SUCCESS == dwStatus)
{
printf("Data (hex format):\n");
DIAG_PrintHexBuffer(buf, header[1], FALSE);
}
else
{
printf("Failed to read tuple's data. Error 0x%lx - %s\n",
dwStatus, Stat2Str(dwStatus));
}
}
else
printf("Empty buffer (size 0)\n");
printf("-----------------------------------------------------------\n");
}
dwOffset += header[1];
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -