1
#ifndef _PCIDRIVER_COMMON_H
2
#define _PCIDRIVER_COMMON_H
4
#include "pcilib_types.h"
6
/*************************************************************************/
7
/* Private data types and structures */
10
/* Define an entry in the kmem list (this list is per device) */
11
/* This list keeps references to the allocated kernel buffers */
14
enum dma_data_direction direction;
16
struct list_head list;
17
dma_addr_t dma_handle;
30
struct class_device_attribute sysfs_attr; /* initialized when adding the entry */
31
} pcidriver_kmem_entry_t;
33
/* Define an entry in the umem list (this list is per device) */
34
/* This list keeps references to the SG lists for each mapped userspace region */
37
struct list_head list;
38
unsigned int nr_pages; /* number of pages for this user memeory area */
39
struct page **pages; /* list of pointers to the pages */
40
unsigned int nents; /* actual entries in the scatter/gatter list (NOT nents for the map function, but the result) */
41
struct scatterlist *sg; /* list of sg entries */
42
struct class_device_attribute sysfs_attr; /* initialized when adding the entry */
43
} pcidriver_umem_entry_t;
45
/* Hold the driver private data */
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 ];
59
/* One queue per interrupt source */
60
atomic_t irq_outstanding[ PCIDRIVER_INT_MAXSOURCES ];
61
/* Outstanding interrupts per queue */
62
volatile unsigned int *bars_kmapped[6]; /* PCI BARs mmapped in kernel space */
66
spinlock_t kmemlist_lock; /* Spinlock to lock kmem list operations */
67
struct list_head kmem_list; /* List of 'kmem_list_entry's associated with this device */
68
atomic_t kmem_count; /* id for next kmem entry */
70
int kmem_cur_id; /* Currently selected kmem buffer, for mmap */
72
spinlock_t umemlist_lock; /* Spinlock to lock umem list operations */
73
struct list_head umem_list; /* List of 'umem_list_entry's associated with this device */
74
atomic_t umem_count; /* id for next umem entry */
76
int msi_mode; /* Flag specifying if interrupt have been initialized in MSI mode */
77
atomic_t refs; /* Reference counter */
78
} pcidriver_privdata_t;
81
void pcidriver_module_get(pcidriver_privdata_t *privdata);
82
void pcidriver_module_put(pcidriver_privdata_t *privdata);
84
/*************************************************************************/
85
/* Some nice defines that make code more readable */
86
/* This is to print nice info in the log */
89
#define mod_info( args... ) \
90
do { printk( KERN_INFO "%s - %s : ", MODNAME , __FUNCTION__ );\
91
printk( args ); } while(0)
92
#define mod_info_dbg( args... ) \
93
do { printk( KERN_INFO "%s - %s : ", MODNAME , __FUNCTION__ );\
94
printk( args ); } while(0)
96
#define mod_info( args... ) \
97
do { printk( KERN_INFO "%s: ", MODNAME );\
98
printk( args ); } while(0)
99
#define mod_info_dbg( args... )
102
#define mod_crit( args... ) \
103
do { printk( KERN_CRIT "%s: ", MODNAME );\
104
printk( args ); } while(0)
106
#define MIN(a, b) ((a) < (b) ? (a) : (b))