1
#ifndef _PCIDRIVER_COMMON_H
2
#define _PCIDRIVER_COMMON_H
4
#include "../pcilib/kmem.h"
5
/*************************************************************************/
6
/* Private data types and structures */
9
/* Define an entry in the kmem list (this list is per device) */
10
/* This list keeps references to the allocated kernel buffers */
13
enum dma_data_direction direction;
15
struct list_head list;
16
dma_addr_t dma_handle;
29
struct class_device_attribute sysfs_attr; /* initialized when adding the entry */
30
} pcidriver_kmem_entry_t;
32
/* Define an entry in the umem list (this list is per device) */
33
/* This list keeps references to the SG lists for each mapped userspace region */
36
struct list_head list;
37
unsigned int nr_pages; /* number of pages for this user memeory area */
38
struct page **pages; /* list of pointers to the pages */
39
unsigned int nents; /* actual entries in the scatter/gatter list (NOT nents for the map function, but the result) */
40
struct scatterlist *sg; /* list of sg entries */
41
struct class_device_attribute sysfs_attr; /* initialized when adding the entry */
42
} pcidriver_umem_entry_t;
44
/* Hold the driver private data */
46
int devid; /* the device id */
47
dev_t devno; /* device number (major and minor) */
48
struct pci_dev *pdev; /* PCI device */
49
struct class_device *class_dev; /* Class device */
50
struct cdev cdev; /* char device struct */
51
int mmap_mode; /* current mmap mode */
52
int mmap_area; /* current PCI mmap area */
55
int irq_enabled; /* Non-zero if IRQ is enabled */
56
int irq_count; /* Just an IRQ counter */
58
wait_queue_head_t irq_queues[ PCIDRIVER_INT_MAXSOURCES ]; /* One queue per interrupt source */
59
atomic_t irq_outstanding[ PCIDRIVER_INT_MAXSOURCES ]; /* Outstanding interrupts per queue */
60
volatile unsigned int *bars_kmapped[6]; /* PCI BARs mmapped in kernel space */
63
spinlock_t kmemlist_lock; /* Spinlock to lock kmem list operations */
64
struct list_head kmem_list; /* List of 'kmem_list_entry's associated with this device */
65
pcidriver_kmem_entry_t *kmem_last_sync; /* Last accessed kmem entry */
66
atomic_t kmem_count; /* id for next kmem entry */
68
int kmem_cur_id; /* Currently selected kmem buffer, for mmap */
70
spinlock_t umemlist_lock; /* Spinlock to lock umem list operations */
71
struct list_head umem_list; /* List of 'umem_list_entry's associated with this device */
72
atomic_t umem_count; /* id for next umem entry */
74
int msi_mode; /* Flag specifying if interrupt have been initialized in MSI mode */
75
atomic_t refs; /* Reference counter */
76
} pcidriver_privdata_t;
79
void pcidriver_module_get(pcidriver_privdata_t *privdata);
80
void pcidriver_module_put(pcidriver_privdata_t *privdata);
82
pcidriver_privdata_t *pcidriver_get_privdata(int devid);
83
void pcidriver_put_privdata(pcidriver_privdata_t *privdata);
86
/*************************************************************************/
87
/* Some nice defines that make code more readable */
88
/* This is to print nice info in the log */
91
#define mod_info( args... ) \
92
do { printk( KERN_INFO "%s - %s : ", MODNAME , __FUNCTION__ );\
93
printk( args ); } while(0)
94
#define mod_info_dbg( args... ) \
95
do { printk( KERN_INFO "%s - %s : ", MODNAME , __FUNCTION__ );\
96
printk( args ); } while(0)
98
#define mod_info( args... ) \
99
do { printk( KERN_INFO "%s: ", MODNAME );\
100
printk( args ); } while(0)
101
#define mod_info_dbg( args... )
104
#define mod_crit( args... ) \
105
do { printk( KERN_CRIT "%s: ", MODNAME );\
106
printk( args ); } while(0)
108
#define MIN(a, b) ((a) < (b) ? (a) : (b))