77范文网 - 专业文章范例文档资料分享平台

Xilinx FPGA PCIE Linux驱动程序

来源:网络收集 时间:2018-12-01 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

// (c) Copyright 2009 聳2009 Xilinx, Inc. All rights reserved. //

// This file contains confidential and proprietary information // of Xilinx, Inc. and is protected under U.S. and

// international copyright and other intellectual property // laws. //

// DISCLAIMER

// This disclaimer is not a license and does not grant any // rights to the materials distributed herewith. Except as // otherwise provided in a valid license issued to you by // Xilinx, and to the maximum extent permitted by applicable // law: (1) THESE MATERIALS ARE MADE AVAILABLE \// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and // (2) Xilinx shall not be liable (whether in contract or tort, // including negligence, or under any other theory of

// liability) for any loss or damage of any kind or nature // related to, arising under or in connection with these // materials, including for any direct, or any indirect, // special, incidental, or consequential loss or damage

// (including loss of data, profits, goodwill, or any type of // loss or damage suffered as a result of any action brought // by a third party) even if such damage or loss was

// reasonably foreseeable or Xilinx had been advised of the // possibility of the same. //

// CRITICAL APPLICATIONS

// Xilinx products are not designed or intended to be fail- // safe, or for use in any application requiring fail-safe // performance, such as life-support or safety devices or // systems, Class III medical devices, nuclear facilities, // applications related to the deployment of airbags, or any // other applications that could lead to death, personal // injury, or severe property or environmental damage // (individually and collectively, \

// Applications\// liability of any use of Xilinx products in Critical // Applications, subject only to applicable laws and

// regulations governing limitations on product liability. //

// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS // PART OF THIS FILE AT ALL TIMES.

//-------------------------------------------------------------------------------- //-- Filename: xbmd.c //--

//-- Description: XBMD device driver. //--

//-- XBMD is an example Red Hat device driver which exercises XBMD design //-- Device driver has been tested on Red Hat Fedora FC9 2.6.15.

//--------------------------------------------------------------------------------

#include #include #include

#include #include

//#include //#include

#include/* copy_to_user */

#include\

// semaphores enum {

SEM_READ, SEM_WRITE, SEM_WRITEREG, SEM_READREG, SEM_WAITFOR, SEM_DMA, NUM_SEMS };

#define SUCCESS 0 #define CRIT_ERR -1

// Debug - define will output more info #define Verbose 1

// Max DMA Buffer Size

#define BUF_SIZE (4096 * 1024)

enum {

INITCARD, // 0 INITRST, DISPREGS, RDDCSR, RDDDMACR,

RDWDMATLPA, // 5 RDWDMATLPS, RDWDMATLPC, RDWDMATLPP, RDRDMATLPP,

RDRDMATLPA, // 10 RDRDMATLPS, RDRDMATLPC, RDWDMAPERF, RDRDMAPERF,

RDRDMASTAT, // 15 RDNRDCOMP, RDRCOMPDSIZE, RDDLWSTAT, RDDLTRSSTAT,

RDDMISCCONT, // 20

RDDMISCONT, RDDLNKC, DFCCTL, DFCPINFO,

DFCNPINFO, // 25 DFCINFO,

RDCFGREG, WRCFGREG, RDBMDREG,

WRBMDREG, // 30

WRDDMACR, WRWDMATLPS, WRWDMATLPC, WRWDMATLPP, WRRDMATLPS, WRRDMATLPC, WRRDMATLPP, WRDMISCCONT, WRDDLNKC,

NUMCOMMANDS };

//semaphores

struct semaphore gSem[NUM_SEMS];

MODULE_LICENSE(\);

// Defines the Vendor ID. Must be changed if core generated did not set the Vendor ID to the same value

#define PCI_VENDOR_ID_XILINX 0x10ee

// Defines the Device ID. Must be changed if core generated did not set the Device ID to the same value

#define PCI_DEVICE_ID_XILINX_PCIE 0x0007

// Defining

#define XBMD_REGISTER_SIZE (4*8) // There are eight registers, and each is 4 bytes wide. #define HAVE_REGION 0x01 // I/O Memory region #define HAVE_IRQ 0x02 // Interupt

//Status Flags:

// 1 = Resouce successfully acquired // 0 = Resource not acquired.

#define HAVE_REGION 0x01 // I/O Memory region #define HAVE_IRQ 0x02 // Interupt

#define HAVE_KREG 0x04 // Kernel registration

int gDrvrMajor = 241; // Major number not dynamic. unsignedint gStatFlags = 0x00; // Status flags used for cleanup.

unsignedlong gBaseHdwr; // Base register address (Hardware address) unsignedlong gBaseLen; // Base register address Length

void *gBaseVirt = NULL; // Base register address (Virtual address, for I/O). char gDrvrName[]= \; // Name of driver in proc. struct pci_dev *gDev = NULL; // PCI device structure.

int gIrq; // IRQ assigned by PCI system.

char *gBufferUnaligned = NULL; // Pointer to Unaligned DMA buffer. char *gReadBuffer = NULL; // Pointer to dword aligned DMA buffer. char *gWriteBuffer = NULL; // Pointer to dword aligned DMA buffer. dma_addr_t gReadHWAddr; dma_addr_t gWriteHWAddr; unsignedlong SA_SHIRQ = 0;

unsignedlong SA_SAMPLE_RANDOM = 0;

int pos;

// Struct Used for Writing CFG Register. Holds value and register to be written typedefstruct cfgwrite { int reg; int value; } cfgwr;

// Struct Used for Writing BMD Register. Holds value and register to be written typedefstruct bmdwrite { int reg; int value; } bmdwr;

//----------------------------------------------------------------------------- // Prototypes

//-----------------------------------------------------------------------------

void XPCIe_IRQHandler (int irq, void *dev_id, struct pt_regs *regs); u32 XPCIe_ReadReg (u32 dw_offset);

void XPCIe_WriteReg (u32 dw_offset, u32 val); void XPCIe_InitCard (void);

void XPCIe_InitiatorReset (void); u32 XPCIe_ReadCfgReg (u32 byte);

u32 XPCIe_WriteCfgReg (u32 byte, u32 value);

//--------------------------------------------------------------------------- // Name: XPCIe_Open //

// Description: Book keeping routine invoked each time the device is opened. //

// Arguments: inode : // filp : //

// Returns: 0 on success, error code on failure. //

// Modification log:

// Date Who Description //

//--------------------------------------------------------------------------- int XPCIe_Open(struct inode *inode, struct file *filp) {

printk(KERN_INFO\,gDrvrName); return SUCCESS;

}

//--------------------------------------------------------------------------- // Name: XPCIe_Release //

// Description: Book keeping routine invoked each time the device is closed. //

// Arguments: inode : // filp : //

// Returns: 0 on success, error code on failure. //

// Modification log:

// Date Who Description //

//--------------------------------------------------------------------------- int XPCIe_Release(struct inode *inode, struct file *filp) {

printk(KERN_INFO\,gDrvrName); return(SUCCESS); }

//--------------------------------------------------------------------------- // Name: XPCIe_Write //

// Description: This routine is invoked from user space to write data to // the PCIe device. //

// Arguments: filp : file pointer to opened device.

// buf : pointer to location in users space, where data is to // be acquired.

// count : Amount of data in bytes user wishes to send. //

// Returns: SUCCESS = Success

// CRIT_ERR = Critical failure //

// Modification log:

// Date Who Description //

//---------------------------------------------------------------------------

ssize_t XPCIe_Write(struct file *filp, constchar *buf, size_t count, loff_t *f_pos) {

int ret = SUCCESS;

memcpy((char *)gWriteBuffer, buf, count);

printk(KERN_INFO\, gDrvrName, count); memcpy((char *)gReadBuffer, buf, count);

printk(KERN_INFO\, gDrvrName, count); return (ret); }

//--------------------------------------------------------------------------- // Name: XPCIe_Read //

// Description: This routine is invoked from user space to read data from // the PCIe device. ***NOTE: This routine returns the entire

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Xilinx FPGA PCIE Linux驱动程序在线全文阅读。

Xilinx FPGA PCIE Linux驱动程序.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/328458.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: