📄 testutil.cpp
字号:
linBAR[0] = (DWORD)PCIDPMemory[comemID]; //FXN
//DWORD returnCode = comemCopyBarPtrL(linBAR, comemID); //FXN
DWORD returnCode = NO_ERROR; //FXN
if (returnCode != NO_ERROR)
{
printf("Error creating BAR pointers.");
return (returnCode);
}
DWORD SMtstBlkBase = linBAR[0];
// Determine size and offset for Shared Memory area
DWORD SMtstBlkSz;
DWORD SMoffset;
if (chipType() == CHIP3041)
{
SMtstBlkSz = 512; // For 3041, in bytes.
SMoffset = 0x0; // Offset from BAR0 for 3041, in DWORDS.
}
else
{
SMtstBlkSz = 0x4000; // For 3042, in bytes.
SMoffset = SM_OFFSET; // Offset from BAR0 for 3042, in DWORDS.
}
returnCode = 0;
printf ("Running Write Address test.\n"); // Write address pattern
if (errorCnt = testMemAddr(SMtstBlkBase, SMoffset, SMtstBlkSz))
printf ("Address test failed for %d addresses.\n", errorCnt);
else
printf ("Address test passed.\n");
returnCode += errorCnt;
printf ("Running Write Address Complement test.\n"); // test complement (check for stuck bits).
if (errorCnt = testMemAddrComp(SMtstBlkBase, SMoffset, SMtstBlkSz))
printf ("Address Complement test failed for %d addresses.\n", errorCnt);
else
printf ("Address Complement test passed.\n");
returnCode += errorCnt;
printf ("Running Byte Write test.\n"); // Write rotating byte pattern
if (errorCnt = testMemWriteBytes(SMtstBlkBase, SMoffset, SMtstBlkSz))
printf ("Byte Write test failed for %d addresses.\n", errorCnt);
else
printf ("Byte Write test passed.\n");
returnCode += errorCnt;
printf ("Running All Ones, then all Zeros test.\n"); // Write Ones then Zeros
if (errorCnt = testMemOneZero(SMtstBlkBase, SMoffset, SMtstBlkSz))
printf ("Ones, Zeros test failed for %d addresses.\n", errorCnt);
else
printf ("Ones, Zeros test passed.\n");
returnCode += errorCnt;
_flushall();
return (returnCode);
} // end testSharedMem
//
// initSharedMem
//
// Params:
// patternStart = start address from the start of the Shared Mem
// patternLen = length in bytes
// patternType = (always ADDR_PATTERN for now)
// comemID = unique designator of which 3042
//
DWORD initSharedMem (DWORD patternStart, DWORD patternLen, DWORD patternType, DWORD comemID)
{
// Pattern numbers
#define ADDR_PATTERN 1
#define FILL_PATTERN 2
int SMtstBlkSz;
DWORD SMoffset;
int errorCnt = 0;
if (chipType() == CHIP3041)
{
SMtstBlkSz = 512; // For 3041, in bytes.
SMoffset = 0x0; // Offset from BAR0 for 3041, in bytes.
}
else
{
if (patternLen == 0)
SMtstBlkSz = 0x4000; // If 0 bytes specified, use the whole Shared Mem.
else
SMtstBlkSz = patternLen; // else, use the size specified in the call.
SMoffset = SM_OFFSET + patternStart/4; // in DWORDS
}
// Get a pointer to the Shared Memory area (BAR 0)
DWORD linBAR[COMEM_MAX_BARS];
linBAR[0] = (DWORD)PCIDPMemory[comemID]; //FXN
//DWORD returnCode = comemCopyBarPtrL(linBAR, comemID); //FXN
DWORD returnCode = NO_ERROR; //FXN
if (returnCode != NO_ERROR)
{
printf("Error creating BAR pointers.");
errorCnt++;
}
printf ("Initializing Shared Mem at: 0x%08x patternLen: 0x%x pattern=%s\n",
(linBAR[0] + SM_OFFSET*4), patternLen,
(patternType == ADDR_PATTERN) ? "ADDR_PATTERN" : "FILL_PATTERN (=0xAA55AA55)");
long dRead;
DWORD SMtstBlkBase = linBAR[0];
if(patternType == ADDR_PATTERN)
{
int i;
for (i = 0; i < SMtstBlkSz/4; i++) // Write address pattern
((long *) SMtstBlkBase + SMoffset)[i] = i;
for (i = 0; i < SMtstBlkSz/4; i++) // Read and check address pattern
{
dRead = ((long *) SMtstBlkBase + SMoffset)[i];
if ( dRead != i)
{
errorCnt++;
printf ("ERROR: PCIAddr=%08x LocalAddr=%08x Wrote=%08x Read=%08x\n",
(long *) SMtstBlkBase+SMoffset+i, i*4, i, dRead);
}
//else
//{
// printf ("PCIAddr=%08x LocalAddr=%08x Wrote=%08x Read=%08x\n",
// (long *) SMtstBlkBase+SMoffset+i, i*4, i, dRead);
//}
}
}
else //use FILL_PATTERN
{
int i;
for (i = 0; i < SMtstBlkSz/4; i++) // Write address pattern
((long *) linBAR[0] + SMoffset)[i] = 0xAA55AA55;
for (i = 0; i < SMtstBlkSz/4; i++) // Read and check address pattern
if (((long *) linBAR[0] + SMoffset)[i] != 0xAA55AA55)
errorCnt++;
}
return (errorCnt);
} // end initSharedMem
DWORD checkSharedMem (DWORD patternStart, DWORD patternLen, DWORD patternType, DWORD comemID)
{
int SMtstBlkSz;
DWORD SMoffset;
int errorCnt = 0;
if (chipType() == CHIP3041)
{
SMtstBlkSz = 512; // For 3041, in bytes.
SMoffset = 0x0; // Offset from BAR0 for 3041, in bytes.
}
else
{
if (patternLen == 0)
SMtstBlkSz = 0x4000; // If 0 bytes specified, use the whole Shared Mem.
else
SMtstBlkSz = patternLen; // else, use the size specified in the call.
SMoffset = SM_OFFSET + patternStart/4; // in DWORDS
}
// Get a pointer to the Shared Memory area (BAR 0)
DWORD linBAR[COMEM_MAX_BARS];
linBAR[0] = (DWORD)PCIDPMemory[comemID]; //FXN
//DWORD returnCode = comemCopyBarPtrL(linBAR, comemID); //FXN
DWORD returnCode = NO_ERROR; //FXN
if (returnCode != NO_ERROR)
{
printf("Error creating BAR pointers.");
errorCnt++;
}
volatile DWORD dRead;
volatile DWORD SMtstBlkBase = linBAR[0];
if(patternType == ADDR_PATTERN)
{
DWORD i;
for (i = 0; i < (DWORD)(SMtstBlkSz/4); i++) // Read and check address pattern
{
dRead = ((long *) SMtstBlkBase + SMoffset)[i];
if ( dRead != i)
{
if(errorCnt++ < 8) // only report first 8 errors
{
printf ("ERROR:: PCIAddr=%08x LocalAddr=%08x Wrote=%08x Read=%08x\n",
(long *) SMtstBlkBase+SMoffset+i, i*4, i, dRead);
}
}
}
}
else //use FILL_PATTERN
{
int i;
for (i = 0; i < SMtstBlkSz/4; i++) // Read and check address pattern
if (((long *) linBAR[0] + SMoffset)[i] != 0xAA55AA55)
errorCnt++;
}
return (errorCnt);
} // end checkSharedMem
//
// testOpRegs
// 1. Obtain pointers to the BARs (Base Address Registers).
// 2. Read the initial contents of thr Operation Registers.
// 3. Attempt to write all 1's to each register. Some bits, i.e. status, are cleared by writing 1.
// 4. Read register back to verify that all writable bits (as defined by mask) are set.
// 5. Write all zeroes to each register.
// 6. Read register back to verify that all writable bits are set to zero.
// 7. Write back the original contents of all registers.
// 8. Verify that writable bits (i.e. not status) have been restored.
// 9. See definition of opRegs3042 to view masks.
//
DWORD testOpRegs (DWORD comemID)
{
int errorCnt = 0;
printf ("Testing Op Regs...\n");
// Get the BARs.
DWORD linBAR[COMEM_MAX_BARS];
linBAR[0] = (DWORD)PCIDPMemory[comemID]; //FXN
//DWORD returnCode = comemCopyBarPtrL(linBAR, comemID); //FXN
DWORD returnCode = NO_ERROR; //FXN
if (returnCode != NO_ERROR)
{
printf("Error creating BAR pointers.");
errorCnt++;
}
printf("testOpRegs: linBAR[0]=%08x\n", linBAR[0]);
DWORD * regs = (DWORD *) linBAR[0]; // BAR 0 for OpRegs on 3042
for (DWORD i = 0 ; i < NUMopr3042 ; i++)
{
DWORD temp, orig;
volatile DWORD * theReg; // TPM: MUST make volitile for release version
DWORD theMask = opRegs3042[i].mask; // Do this to make the code more readable.
char * theText = opRegs3042[i].text;
theReg = regs + (opRegs3042[i].offset/4); // The /4 is to convert from byte offset
// (as coded in opRegs3042 table)
// to a DWORD offset.
orig = *theReg; // Get original.
printf ("Read original contents from: %s at:%08x = %08x\n", theText, theReg, orig);
*theReg = 0xFFFFFFFF; // Attempt to write all ones.
temp = *theReg; // Read it back.
if(!strcmp(theText, "hint ") || !strcmp(theText, "lint "))
temp &= theMask; //account for stat bits (can't set from host)
if (temp != theMask)
{
errorCnt++;
printf (" Bad %s: WR 0xFFFFFFFF RD %08x Should RD %08x Errs %d\n",
theText, temp, theMask, errorCnt);
}
*theReg = 0; // Attempt to write all zeros.
temp = *theReg; // Read it back.
temp &= theMask;
if (temp != 0)
{
errorCnt++;
printf (" Bad %s: WR 0x00000000 RD %08x Should RD 00000000 Errs %d\n",
theText, temp, errorCnt);
}
*theReg = orig; // Attempt to restore original.
temp = *theReg; // Read it back.
if(!strcmp(theText, "hint ") || !strcmp(theText, "lint "))
{
orig &= 0xFFFFFC00; //account for stat bits (which were cleared)
temp &= 0xFFFFFC00; //account for stat bits (which were cleared)
}
if (temp != orig)
{
errorCnt++;
printf (" Bad %s: WR %08x RD %08x Should RD %08x Errs %d\n",
theText, orig, temp, orig, errorCnt);
}
} // end for each record in opRegs3042 table
return (errorCnt);
}
DWORD closeDriver(DWORD comemID)
{
//DWORD returnCode = comemDestroyBarPtrL(comemID); //FXN
DWORD returnCode = UnMapBaseRegister(PCIDPHandle[comemID], PCIDPMemory[comemID]); //FXN
if (returnCode != NO_ERROR)
reportErrorCode(returnCode, "destroying linear pointers to BARs.");
//comemCloseDriverL(comemID);
return (returnCode);
}
//////////////////////////////////////////////////////////////////////
// In order for the co-mem device to operate properly, it must be
// configured correctly by the system BIOS. If it is not configured
// correctly, this routine attempts to reconfigure it.
//////////////////////////////////////////////////////////////////////
DWORD verifyComemConfig(DWORD comemID)
{
DWORD returnCode;
//PCI_CONFIG_HEADER_0 pciCfg; //FXN
PCIDP_CONFIG pciCfg;
//returnCode = comemGetPCIInfoL(&pciCfg, comemID);
returnCode = GetPCIConfigurationSpace(PCIDPHandle[comemID], &pciCfg); //FXN
if (returnCode != NO_ERROR)
{
reportErrorCodeL(returnCode, "while reading PCI configuration.");
return returnCode;
}
if (pciCfg.LatencyTimer < 0x10)
report_errorL("Warning: Latency Timer is less than 16!");
// If the PCI host has disabled our memory, we cannot perform any functions.
// This is not a recoverable error, since we have no idea where to locate
// ourselves in memory space if the BIOS doesn't do it for us.
if (!(pciCfg.Command & 0x2))
{
report_errorL("Memory is disabled!! PCI-DP will not work.!");
exit(1);
}
if (!(pciCfg.Command & 0x8))
{
report_errorL("Bus mastering not enabled by BIOS. PCI-DP requires bus master capability, so is about to be enabled by driver.");
pciCfg.Command |= 0x8;
//comemSetPCIInfoL(&(pciCfg), comemID); //FXN
SetPCIConfigurationSpace(PCIDPHandle[comemID], &pciCfg); //FXN
}
// The SERR bit controls the reporting of parity errors by our device during
// other device's address cycles. Since we have seen some PCI devices generate
// incorrect parity, we disable this bit to prevent the co-mem from stopping
// the system on an address parity error.
while (pciCfg.Command & 0x100)
{
int old = pciCfg.Command;
pciCfg.Command &= ~0x100;
pciCfg.Status = 0;
//comemSetPCIInfoL(&(pciCfg), comemID); //FXN
SetPCIConfigurationSpace(PCIDPHandle[comemID], &pciCfg); //FXN
// Use the dialog box to ensure that we wait a while before reading the regs
//comemGetPCIInfoL(&(pciCfg), comemID);
GetPCIConfigurationSpace(PCIDPHandle[comemID], &pciCfg);
report_errorL("SERR was enabled. It has been disabled. (Command reg %04x, ==>%04x)", old, pciCfg.Command);
}
return NO_ERROR;
}
int InitDriver(DWORD comemID)
{
unsigned long returnCode;
unsigned long IOMemory;
unsigned long IOSpace;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -