/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to driver/common.h

  • Committer: Suren A. Chilingaryan
  • Date: 2016-03-02 18:37:30 UTC
  • Revision ID: csa@suren.me-20160302183730-nlrgi7h3yuizcizc
Restructure driver headers

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef _PCIDRIVER_COMMON_H
2
 
#define _PCIDRIVER_COMMON_H
3
 
 
4
 
#include "../pcilib/kmem.h"
5
 
/*************************************************************************/
6
 
/* Private data types and structures */
7
 
 
8
 
 
9
 
/* Define an entry in the kmem list (this list is per device) */
10
 
/* This list keeps references to the allocated kernel buffers */
11
 
typedef struct {
12
 
    int id;
13
 
    enum dma_data_direction direction;
14
 
 
15
 
    struct list_head list;
16
 
    dma_addr_t dma_handle;
17
 
    unsigned long cpua;
18
 
    unsigned long size;
19
 
    unsigned long type;
20
 
    unsigned long align;
21
 
 
22
 
    unsigned long use;
23
 
    unsigned long item;
24
 
 
25
 
    spinlock_t lock;
26
 
    unsigned long mode;
27
 
    unsigned long refs;
28
 
 
29
 
    struct class_device_attribute sysfs_attr;   /* initialized when adding the entry */
30
 
} pcidriver_kmem_entry_t;
31
 
 
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 */
34
 
typedef struct {
35
 
    int id;
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;
43
 
 
44
 
/* Hold the driver private data */
45
 
typedef struct  {
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 */
53
 
 
54
 
#ifdef ENABLE_IRQ
55
 
    int irq_enabled;                            /* Non-zero if IRQ is enabled */
56
 
    int irq_count;                                      /* Just an IRQ counter */
57
 
 
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 */
61
 
#endif
62
 
 
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 */
67
 
 
68
 
    int kmem_cur_id;                            /* Currently selected kmem buffer, for mmap */
69
 
 
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 */
73
 
 
74
 
    int msi_mode;                                       /* Flag specifying if interrupt have been initialized in MSI mode */
75
 
    atomic_t refs;                                      /* Reference counter */
76
 
} pcidriver_privdata_t;
77
 
 
78
 
 
79
 
void pcidriver_module_get(pcidriver_privdata_t *privdata);
80
 
void pcidriver_module_put(pcidriver_privdata_t *privdata);
81
 
 
82
 
pcidriver_privdata_t *pcidriver_get_privdata(int devid);
83
 
void pcidriver_put_privdata(pcidriver_privdata_t *privdata);
84
 
 
85
 
 
86
 
/*************************************************************************/
87
 
/* Some nice defines that make code more readable */
88
 
/* This is to print nice info in the log */
89
 
 
90
 
#ifdef DEBUG
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)
97
 
#else
98
 
#define mod_info( args... ) \
99
 
    do { printk( KERN_INFO "%s: ", MODNAME );\
100
 
    printk( args ); } while(0)
101
 
#define mod_info_dbg( args... )
102
 
#endif
103
 
 
104
 
#define mod_crit( args... ) \
105
 
    do { printk( KERN_CRIT "%s: ", MODNAME );\
106
 
    printk( args ); } while(0)
107
 
 
108
 
#define MIN(a, b) ((a) < (b) ? (a) : (b))
109
 
 
110
 
#endif