PCI Express设备驱动 (1)
Virtex®-5 FPGA Integrated Endpoint Block for PCI Express® designs.(the integrated Endpoint block embedded in Virtex-5 devices.)
//头文件card.h
#include <linux/module.h>
#include <linux/init.h> //指定初始化和清楚函数
#include <linux/fs.h> //文件系统相关的函数和头文件
#include <linux/cdev.h>
#include <linux/pci.h>
#include <linux/interrupt.h> // request_irq()
#include <linux/sched.h> // #define TASK_INTERRUPTIBLE 1
/* interruptible_sleep_on / wait_event_interruptible
interruptible_sleep_on_timeout / wait_event_interruptible_timeout
wake_up_interruptible(x) */
#include <linux/wait.h>
// void writel (unsigned char data , unsigned short addr )
#include <asm/io.h>
// copy_from_user / copy_to_user
#include <asm/uaccess.h>
/* DMA Register Locations (byte offset from BAR 0) */
// EP DDR2 memory address for DMA write operation.
#define WRITE_DDR2_SA_OFFSET 0x0
// Lower 32-bit address of system memory buffer for DMA write operation.
#define WRITE_HOST_DA_L_OFFSET 0x4
// Upper 32-bit address of system memory buffer for DMA write operation.
#define WRITE_HOST_DA_U_OFFSET 0x8
// Lower 32-bit address of system memory buffer for DMA READ operation.
#define READ_HOST_SA_L_OFFSET 0xC
// Upper 32-bit address of system memory buffer for DMA READ operation.
#define READ_HOST_SA_U_OFFSET 0x10
// EP DDR2 memory address for DMA READ operation.
#define READ_DDR2_DA_OFFSET 0x14
// Write DMA TLP Size Register(from DDR2 to mm).
#define WRITE_SIZE_OFFSET 0x18
// Read DMA TLP Size Register(from mm to DDR2).
#define READ_SIZE_OFFSET 0x1C
// DMA Control and Status Register
#define DMA_CST_OFFSET 0x28
#define WRITE_DMA_COUNTER_OFFSET 0x30 // Write DMA Number of Completions Register
#define READ_DMA_COUNTER_OFFSET 0x34 // Read DMA Number of Completions Register
#define PCI_DEVICE_ID_EP_PIPE 0x0007 // Device ID
#define DEV_NAME "card007"
static int card_probe(struct pci_dev *pdev, const struct pci_device_id *id);
static void card_remove(struct pci_dev *pdev);
static int card_open(struct inode *inode, struct file *filp);
static int card_release(struct inode *inode, struct file *filp);
static ssize_t card_read(struct file *file, char __user *buf, size_t count, loff_t *f_pos);
static ssize_t card_write(struct file *file, const char __user *buf, size_t count, loff_t *f_pos);
//static irqreturn_t card_interrupt(int irq, void * dev);