📄 bsl_pdev.c
字号:
//==============================================================================
// Opens a PCI Board according to its Vendor and Device ID and its ordinal
// number.
//
// parameters:
// vendorAndDeviceID Vendor and Device ID of the PCI device to be opened.
// The PDEV_PCI_BOARD_RTD_x macros should be used.
// (The 0th register in the Configuration Space.)
// ordinal Ordinal number of the PCI device within the
// set of the same Vendor and Device ID devices.
// Must be at least 1.
// pDeviceObj Pointer to the PCI device descriptor to be filled
// up.
//
// returns:
// PDEV_DEVICE_HAS_ALREADY_OPENED The requested PCI device has already
// been opened. It is opened currently.
// PDEV_TOO_MANY_OPENED_DEVICE There is no more room to maintain a new
// opened PCI device.
// PDEV_DEVICE_OPEN_SUCCESSFUL The requested PCI device has been found
// and opened. All right.
// PDEV_DEVICE_NOT_FOUND No error, but the device has not been
// found.
// PDEV_PCI_CONFIG_ERROR PCI configuration cycle error has
// occured.
//==============================================================================
Uint32 PDEV_openPCIDevice(Uint32 vendorAndDeviceID, Uint32 ordinal,
PDEV_DeviceObj * pDeviceObj)
{
Uint32 newdev;
Uint32 err;
// check whether the PCI device has already opened or not
if( PDEV_isOpened(vendorAndDeviceID, ordinal) )
return PDEV_DEVICE_HAS_ALREADY_OPENED;
// check whether the program can maintain a new PCI device or not
if( (newdev = PDEV_canBeOpened()) > PDEV_MAX_OPENED_PCI_DEVICES )
return PDEV_TOO_MANY_OPENED_DEVICE;
// attempt to find the given device
if( (err = PDEV_findDevice(vendorAndDeviceID, ordinal, pDeviceObj))
== PDEV_DEVICE_FOUND )
{
// PDEV_findDevice has already filled up the some members of the deviceObj
// structure, but not all ones.
pDeviceObj->vendorAndDeviceID = vendorAndDeviceID;
pDeviceObj->ordinal = ordinal;
// record the opened device's parameters
_PDEV_openedDevices[newdev].vendorAndDeviceID = vendorAndDeviceID;
_PDEV_openedDevices[newdev].ordinal = ordinal;
return PDEV_DEVICE_OPEN_SUCCESSFUL;
}
return err;
}
//==============================================================================
// Closes a previously opened PCI device and remove it from the maintain.
//
// parameters:
// pDeviceObj Pointer to the pDeviceObj of the opened PCI device to be
// closed.
//
// returns:
// TRUE All right.
// FALSE The specified PCI device is not opened currently.
//==============================================================================
BOOL PDEV_closePCIDevice(PDEV_DeviceObj * pDeviceObj)
{
Uint32 dev;
Uint32 vendorAndDeviceID;
Uint32 ordinal;
vendorAndDeviceID = pDeviceObj->vendorAndDeviceID;
ordinal = pDeviceObj->ordinal;
for( dev = 0; dev < PDEV_MAX_OPENED_PCI_DEVICES; dev++)
{
if( (_PDEV_openedDevices[dev].vendorAndDeviceID == vendorAndDeviceID)
&& (_PDEV_openedDevices[dev].ordinal == ordinal) )
{
// clear maintaining data of the closed PCI device
_PDEV_openedDevices[dev].vendorAndDeviceID = 0;
_PDEV_openedDevices[dev].ordinal = 0;
return TRUE;
}
}
// device is not opened currently
return FALSE;
}
//==============================================================================
// Reads a PCI peripheral register of a DSP chip with integrated PCI interface.
// This function can be used for C6416 and C6205.
//
// parameters:
// pDeviceObj Pointer to the PCI device descriptor of an opened PCI
// device. (PDEV_openPCIdevice fills it up.)
// pciRegOffs Direct BAR1 offset to select the appropriate register.
// Use PDEV_SPM6?XX_PCI_REG_? macros to reach HSR, HDCR,
// or DSPP register.
// pValue pointer to Uint32-type variable that will contain the
// read value of the selected register
//
// returns:
// Returns after the necessary PCI data trasfers only.
// Gives TRUE, if all right, and pValue is filled up. Otherwise, FALSE.
//==============================================================================
BOOL PDEV_read_PciReg(PDEV_DeviceObj *pDeviceObj,
Uint32 pciRegOffs, Uint32 *pValue)
{
Uint32 reg;
if( PCIBUS_read( ®,
PDEV_PCI_ADDRESS(pDeviceObj, BAR1, pciRegOffs), 1)
!= PCIBUS_TOE_NO_ERROR) return FALSE;
*pValue = reg;
return TRUE;
}
//==============================================================================
// Writes a PCI peripheral register of a DSP chip with integrated PCI interface.
// This function can be used for C6416 and C6205.
//
// parameters:
// pDeviceObj Pointer to the PCI device descriptor of an opened PCI
// device. (PDEV_openPCIdevice fills it up.)
// pciRegOffs Direct BAR1 offset to select the appropriate register.
// Use PDEV_SPM6?XX_PCI_REG_? macros to reach HSR, HDCR,
// or DSPP register.
// value 32-bit value to be written into the selected register
//
// returns:
// Returns after the necessary PCI data trasfers only.
// Gives TRUE, if all right. Otherwise, FALSE.
//==============================================================================
BOOL PDEV_write_PciReg(PDEV_DeviceObj *pDeviceObj,
Uint32 pciRegOffs, Uint32 value)
{
Uint32 reg;
reg = value;
if( PCIBUS_write( ®,
PDEV_PCI_ADDRESS(pDeviceObj, BAR1, pciRegOffs), 1)
!= PCIBUS_TOE_NO_ERROR) return FALSE;
return TRUE;
}
//==============================================================================
// Reads a memory block from an opened SPM64xx dspModule board.
//
// parameters:
// pDeviceObj Pointer to the PCI device descriptor of the opened
// SPM64xx board. (PDEV_openPCIdevice fills it up.)
// pBuf Pointer to the buffer to be filled up with the read
// 32-bit words.
// addrInDev Starting byte address of the transfer within the opened
// board's 4-GB address space.
// Must be aligned to 32-bit word boundary.
// numOf32bWs Number of the 32-bit words to be read.
// Must be up to 65535.
//
// returns:
// Returns after the necessary PCI data trasfers only.
// Gives TRUE, if all right. Otherwise, FALSE.
//==============================================================================
BOOL PDEV_SPM64xx_read(PDEV_DeviceObj *pDeviceObj,
Uint32 *pBuf, Uint32 addrInDev, Uint16 numOf32bWs)
{
// write DSPP reg. to set location of the 4-MB window for BAR0
if( !PDEV_write_PciReg(pDeviceObj,
PDEV_SPM64XX_PCI_REG_DSPP,
PDEV_DSP_PCI_PAGE_NUMBER(addrInDev)) ) return FALSE;
// read memory block from BAR0
if( PCIBUS_read( pBuf,
PDEV_PCI_ADDRESS(pDeviceObj, BAR0,
PDEV_DSP_PCI_PAGE_OFFSET(addrInDev)), numOf32bWs)
!= PCIBUS_TOE_NO_ERROR) return FALSE;
return TRUE;
}
//==============================================================================
// Writes a memory block into the memory space of an opened SPM64xx dspModule
// board.
//
// parameters:
// pDeviceObj Pointer to the PCI device descriptor of the opened
// SPM64xx board. (PDEV_openPCIdevice fills it up.)
// pBuf Pointer to the buffer to get 32-bit words to be written
// into the memory space of the SPM64xx board.
// addrInDev Starting byte address of the transfer within the opened
// board's 4-GB address space.
// Must be aligned to 32-bit word boundary.
// numOf32bWs Number of the 32-bit words to be read.
// Must be up to 65535.
//
// returns:
// Returns after the necessary PCI data trasfers only.
// Gives TRUE, if all right. Otherwise, FALSE.
//==============================================================================
BOOL PDEV_SPM64xx_write(PDEV_DeviceObj *pDeviceObj,
Uint32 *pBuf, Uint32 addrInDev, Uint16 numOf32bWs)
{
// write DSPP reg. to set location of the 4-MB window for BAR0
if( !PDEV_write_PciReg(pDeviceObj,
PDEV_SPM64XX_PCI_REG_DSPP,
PDEV_DSP_PCI_PAGE_NUMBER(addrInDev)) ) return FALSE;
// read memory block from BAR0
if( PCIBUS_write( pBuf,
PDEV_PCI_ADDRESS(pDeviceObj, BAR0,
PDEV_DSP_PCI_PAGE_OFFSET(addrInDev)), numOf32bWs)
!= PCIBUS_TOE_NO_ERROR) return FALSE;
return TRUE;
}
//==============================================================================
// Reads a memory block from an opened SPM62xx dspModule board.
//
// parameters:
// pDeviceObj Pointer to the PCI device descriptor of the opened
// SPM62xx board. (PDEV_openPCIdevice fills it up.)
// pBuf Pointer to the buffer to be filled up with the read
// 32-bit words.
// addrInDev Starting byte address of the transfer within the opened
// board's 4-GB address space.
// Must be aligned to 32-bit word boundary.
// numOf32bWs Number of the 32-bit words to be read.
// Must be up to 65535.
//
// returns:
// Returns after the necessary PCI data trasfers only.
// Gives TRUE, if all right. Otherwise, FALSE.
//==============================================================================
BOOL PDEV_SPM62xx_read(PDEV_DeviceObj *pDeviceObj,
Uint32 *pBuf, Uint32 addrInDev, Uint16 numOf32bWs)
{
Uint32 regXBISA;
// write XBISA register to set the starting address of the data transfer
// XBISA is at offset 0x0C of LAS1
regXBISA = addrInDev & 0xFFFFFFFC; // address autoincrement enabled
if( PCIBUS_write(®XBISA, PDEV_PCI_ADDRESS(pDeviceObj, LAS1, 0x0C), 1)
!= PCIBUS_TOE_NO_ERROR) return FALSE;
// read memory block from LAS0
if( PCIBUS_read( pBuf, PDEV_PCI_ADDRESS(pDeviceObj, LAS0, 0), numOf32bWs)
!= PCIBUS_TOE_NO_ERROR) return FALSE;
return TRUE;
}
//==============================================================================
// Writes a memory block into the memory space of an opened SPM62xx dspModule
// board.
//
// parameters:
// pDeviceObj Pointer to the PCI device descriptor of the opened
// SPM62xx board. (PDEV_openPCIdevice fills it up.)
// pBuf Pointer to the buffer to get 32-bit words to be written
// into the memory space of the SPM62xx board.
// addrInDev Starting byte address of the transfer within the opened
// board's 4-GB address space.
// Must be aligned to 32-bit word boundary.
// numOf32bWs Number of the 32-bit words to be read.
// Must be up to 65535.
//
// returns:
// Returns after the necessary PCI data trasfers only.
// Gives TRUE, if all right. Otherwise, FALSE.
//==============================================================================
BOOL PDEV_SPM62xx_write(PDEV_DeviceObj *pDeviceObj,
Uint32 *pBuf, Uint32 addrInDev, Uint16 numOf32bWs)
{
Uint32 regXBISA;
// write XBISA register to set the starting address of the data transfer
// XBISA is at offset 0x0C of LAS1
regXBISA = addrInDev & 0xFFFFFFFC; // address autoincrement enabled
if( PCIBUS_write(®XBISA, PDEV_PCI_ADDRESS(pDeviceObj, LAS1, 0x0C), 1)
!= PCIBUS_TOE_NO_ERROR) return FALSE;
// read memory block from LAS0
if( PCIBUS_write( pBuf, PDEV_PCI_ADDRESS(pDeviceObj, LAS0, 0), numOf32bWs)
!= PCIBUS_TOE_NO_ERROR) return FALSE;
return TRUE;
}
#endif /* BSL_PDEV_SUPPORT */
/******************************************************************************\
* End of bsl_pdev.c
\******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -