📄 i80312pcilib.c
字号:
** RETURNS: N/A*/void pciBusScan (void) { UINT32 regVal; PCI_CFG_ADDR cfgAddr; int busNo, ebusNo; int device; int function; int maxFuncNum; UINT8 rotary = I80310_ROT_STAT_REG_RD(); if (rotary != 0x7) /* rotary switch NOT in position 7 - stand-alone backplane */ { /* Start with the Primary Bus */ busNo = i80312PciChkBusNumbers(i80312_BusNumbers[PRIMARY_BUS_INDEX]); ebusNo = busNo + 2; } else { /* Start with the Secondary Bus */ busNo = i80312PciChkBusNumbers(i80312_BusNumbers[SECONDARY_BUS_INDEX]); ebusNo = busNo + 1; } for(; busNo <= ebusNo; busNo++) { printf ("PCI SCAN: bus %d\n", busNo); taskDelay(10); for (device = 0; device < 32; device++) { /* check if device is there */ if(busNo <= i80312_BusNumbers[SECONDARY_BUS_INDEX]) cfgAddr.u.whole=CONFIG_WORD_PACK (PCI_CFG_TYP0,PCI_CFG_HEADER_TYPE, 0,device,busNo,PCI_BYTE_ACCESS); else cfgAddr.u.whole=CONFIG_WORD_PACK (PCI_CFG_TYP1,PCI_CFG_HEADER_TYPE, 0,device,busNo,PCI_BYTE_ACCESS); maxFuncNum = i80312PciDeviceProbe (busNo,cfgAddr); for (function = 0; function < maxFuncNum; function++) { taskDelay(2); if(busNo <= i80312_BusNumbers[SECONDARY_BUS_INDEX]) cfgAddr.u.whole=CONFIG_WORD_PACK(PCI_CFG_TYP0,PCI_CFG_VENDOR_ID, function,device,busNo,PCI_UINT32_ACCESS); else cfgAddr.u.whole=CONFIG_WORD_PACK(PCI_CFG_TYP1,PCI_CFG_VENDOR_ID, function,device,busNo,PCI_UINT32_ACCESS); if (i80312PciCfgRd((int)busNo, cfgAddr, (UINT32 *)®Val) == OK) printf ("PCI SCAN: Dev %x found in slot %d\n", regVal, device); } /* function loop */ } /* device loop */ } /* bridge loop */ }/* Configuration Utilities *//********************************************************************************* pciDeviceFind - find the nth device with the given device & vendor ID** This routine finds the nth device with the given device & vendor ID.** RETURNS: OK, or ERROR if the device ID and vendor ID didn't match.*/STATUS pciDeviceFind ( int vendorId, /* vender ID */ int deviceId, /* device ID */ int index, /* desired instance of device */ int * pBusNo, /* bus number */ int * pDeviceNo, /* device number */ int * pFuncNo /* function number */ ) { if (i80312PciFindDevice (vendorId,deviceId,index,(UINT32 *)pBusNo,(UINT32 *)pDeviceNo,(UINT32 *)pFuncNo) == OK ) { return (OK); } return (ERROR); }/********************************************************************************* pciConfigInWord - read one word from the PCI configuration space** This routine reads one word from the PCI configuration space** This function needs to added another passing paramter to indicate* which PCI interface(Primary or Second) to access. For the compatibility* issue, the function remains as it is. So bus number greater than 1 will* be assumed to access the primary Bus interface since the second Bus can not* convert configuration type 1 to type 0.** RETURNS: OK, or ERROR if this library is not initialized.*/STATUS pciConfigInWord ( int busNo, /* bus number */ int deviceNo, /* device number */ int funcNo, /* function number */ int address, /* address of the configuration space */ short * pData /* data read from the address */ ) { STATUS status; UINT32 retval = 0; PCI_CFG_ADDR cfgAddr; if(busNo <= i80312_BusNumbers[SECONDARY_BUS_INDEX]) cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP0,address,funcNo,deviceNo, busNo,PCI_UINT16_ACCESS); else cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP1,address,funcNo,deviceNo, busNo,PCI_UINT16_ACCESS); status = i80312PciCfgRd (busNo,cfgAddr,(UINT32 *)&retval); if(status == OK) { *pData = (UINT16)retval; return (OK); }else{ *pData = (UINT16)0; return (NO_DEVICE); } }/********************************************************************************* pciConfigInByte - read one byte from the PCI configuration space** This routine reads one byte from the PCI configuration space** RETURNS: OK, or ERROR if this library is not initialized.*/STATUS pciConfigInByte ( int busNo, /* bus number */ int deviceNo, /* device number */ int funcNo, /* function number */ int address, /* address of the configuration space */ char * pData /* data read from the address */ ) { STATUS status; UINT32 retval = 0; PCI_CFG_ADDR cfgAddr; if(busNo <= i80312_BusNumbers[SECONDARY_BUS_INDEX]) cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP0,address,funcNo,deviceNo, busNo,PCI_BYTE_ACCESS); else cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP1,address,funcNo,deviceNo, busNo,PCI_BYTE_ACCESS); status = i80312PciCfgRd (busNo,cfgAddr,(UINT32 *)&retval); if(status == OK) { *pData = (UINT8)retval; return (OK); }else{ *pData = (UINT8)0; return (NO_DEVICE); } }/********************************************************************************* pciConfigInLong - read one longword from the PCI configuration space** This routine reads one longword from the PCI configuration space** RETURNS: OK, or ERROR if this library is not initialized.*/STATUS pciConfigInLong ( int busNo, /* bus number */ int deviceNo, /* device number */ int funcNo, /* function number */ int address, /* address of the configuration space */ int * pData /* data read from the address */ ) { STATUS status; UINT32 retval = 0; PCI_CFG_ADDR cfgAddr; if(busNo <= i80312_BusNumbers[SECONDARY_BUS_INDEX]) cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP0,address,funcNo,deviceNo, busNo,PCI_UINT32_ACCESS); else cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP1,address,funcNo,deviceNo, busNo,PCI_UINT32_ACCESS); status = i80312PciCfgRd (busNo,cfgAddr,(UINT32 *)&retval); if(status == OK) { *pData = retval; return (OK); }else{ *pData = 0; return (NO_DEVICE); } }/********************************************************************************* pciConfigOutByte - write one byte to the PCI configuration space** This routine writes one byte to the PCI configuration space** RETURNS: OK, or ERROR if this library is not initialized.*/STATUS pciConfigOutByte ( int busNo, /* bus number */ int deviceNo, /* device number */ int funcNo, /* function number */ int address, /* address of the configuration space */ char Data /* data written to the address */ ) { STATUS status; PCI_CFG_ADDR cfgAddr; if(busNo <= i80312_BusNumbers[SECONDARY_BUS_INDEX]) cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP0,address,funcNo,deviceNo, busNo,PCI_BYTE_ACCESS); else cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP1,address,funcNo,deviceNo, busNo,PCI_BYTE_ACCESS); status = i80312PciCfgWr (busNo,cfgAddr,Data); return(status); }/********************************************************************************* pciConfigOutWord - read one word from the PCI configuration space** This routine reads one word from the PCI configuration space** This function needs to added another passing paramter to indicate* which PCI interface(Primary or Second) to access. For the compatibility* issue, the function remains as it is. So bus number greater than 1 will* be assumed to access the primary Bus interface since the second Bus can not* convert configuration type 1 to type 0.** RETURNS: OK, or ERROR if this library is not initialized.*/STATUS pciConfigOutWord ( int busNo, /* bus number */ int deviceNo, /* device number */ int funcNo, /* function number */ int address, /* address of the configuration space */ short Data /* data written to the address */ ) { STATUS status; PCI_CFG_ADDR cfgAddr; if(busNo <= i80312_BusNumbers[SECONDARY_BUS_INDEX]) cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP0,address,funcNo,deviceNo, busNo,PCI_UINT16_ACCESS); else cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP1,address,funcNo,deviceNo, busNo,PCI_UINT16_ACCESS); status = i80312PciCfgWr (busNo,cfgAddr,Data); return(status); }/********************************************************************************* pciConfigOutLong - read one longword from the PCI configuration space** This routine reads one longword from the PCI configuration space** RETURNS: OK, or ERROR if this library is not initialized.*/STATUS pciConfigOutLong ( int busNo, /* bus number */ int deviceNo, /* device number */ int funcNo, /* function number */ int address, /* address of the configuration space */ int Data /* data written to the address */ ) { STATUS status; PCI_CFG_ADDR cfgAddr; if(busNo <= i80312_BusNumbers[SECONDARY_BUS_INDEX]) cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP0,address,funcNo,deviceNo, busNo,PCI_UINT32_ACCESS); else cfgAddr.u.whole = CONFIG_WORD_PACK(PCI_CFG_TYP1,address,funcNo,deviceNo, busNo,PCI_UINT32_ACCESS); status = i80312PciCfgWr (busNo,cfgAddr,Data); return(status); }/********************************************************************************* pciConfigQuery - Get a Pci devices configureation requirement for a given register** RETURNS: n/a**/void pciConfigQuery(int busNo, PCI_CFG_ADDR cfgAddr, UINT32 *rtnval) { /* Make sure some bios hasn't changed the bus on us */ busNo = i80312PciChkBusNumbers(busNo); /* When all ones written, read will be mem requirement */ i80312PciCfgWr(busNo, cfgAddr, 0xFFFFFFFF); /* Read requirement. */ i80312PciCfgRd(busNo, cfgAddr, rtnval); }/********************************************************************************* i80312PciChkBusNumbers - See if Pci bus numbers have been changed.** If Pci Bus numbers have been changed then reset BusNumber fields**/STATUS i80312PciChkBusNumbers(UINT32 busNo) { UINT32 ix; volatile I80312_CFG_SPACE * pBrCfg = (I80312_CFG_SPACE *)I80312_BRIDGE_CFG_BASE; for(ix = 0; ix < 4; ix++) { if(i80312_BusNumbers[ix] == busNo) break; } if(ix == 4) ix = SECONDARY_BUS_INDEX; /* Check Bus numbers */ if ( i80312_PriBusNumber != pBrCfg->PCI_Primary_Bus_Number || i80312_SecBusNumber != pBrCfg->PCI_Secondary_Bus_Number || i80312_SubBusNumber != pBrCfg->PCI_Subordinate_Bus_Number) { i80312_PriBusNumber = pBrCfg->PCI_Primary_Bus_Number; i80312_SecBusNumber = pBrCfg->PCI_Secondary_Bus_Number; i80312_SubBusNumber = i80312_SecBusNumber + 1; i80312_BusNumbers[0] = i80312_PriBusNumber; i80312_BusNumbers[1] = i80312_SecBusNumber; i80312_BusNumbers[2] = i80312_SubBusNumber; i80312_BusNumbers[3] = i80312_SubBusNumber; DRV_LOG("Pci Bus Numbers Changed to: %d %d %d\n" , i80312_PriBusNumber , i80312_SecBusNumber , i80312_SubBusNumber , 0, 0, 0); } return(i80312_BusNumbers[ix]); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -