goto exit; } exit:
return ret; }
ssize_t XPCIe_WriteMem(constchar *buf, size_t count) {
int ret = 0;
dma_addr_t dma_addr;
if ( (count % 4) != 0 ) {
printk(\,gDrvrName); ret = -1; return ret; //goto exit; }
// Now it is safe to copy the data from user space. if ( copy_from_user(gWriteBuffer, buf, count) ) {
ret = -1;
printk(\,gDrvrName); return ret; //goto exit; }
//set DMA semaphore if in loopback down(&gSem[SEM_DMA]);
// pci_map_single return the physical address corresponding to // the virtual address passed to it as the 2nd parameter
dma_addr = pci_map_single(gDev, gWriteBuffer, BUF_SIZE, PCI_DMA_FROMDEVICE); if ( 0 == dma_addr ) {
printk(\,gDrvrName); ret = -1;
up(&gSem[SEM_DMA]); return ret;
//goto exit; // return 之前要释放互斥量,不能直接return }
// Now pass the physical address to the device hardware. This is now // the source physical address for the DMA and hence the to be // put on Memory Transactions
// Do DMA transfer here....
// 直接调用read write 函数进行传输? // 宋宝华第页流程图
printk(\, gDrvrName, (unsignedint)gReadBuffer, (unsignedint)dma_addr);
// Unmap the DMA buffer so it is safe for normal access again.
pci_unmap_single(gDev, dma_addr, BUF_SIZE, PCI_DMA_FROMDEVICE);
up(&gSem[SEM_DMA]);
exit:
return (ret); }
u32 XPCIe_ReadCfgReg (u32 byte) {
u32 pciReg;
if (pci_read_config_dword(gDev, byte, &pciReg) < 0) {
printk(\,gDrvrName); return (-1); }
return (pciReg); }
u32 XPCIe_WriteCfgReg (u32 byte, u32 val) {
if (pci_write_config_dword(gDev, byte, val) < 0) {
printk(\,gDrvrName); return (-1); } return 1; }
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Xilinx FPGA PCIE Linux驱动程序(4)在线全文阅读。
相关推荐: