/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/pciDriver.h

  • Committer: Suren A. Chilingaryan
  • Date: 2011-02-13 02:07:11 UTC
  • Revision ID: csa@dside.dyndns.org-20110213020711-y9bjh3n4ke6p4t4n
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef PCIDRIVER_H_
 
2
#define PCIDRIVER_H_
 
3
 
 
4
/**
 
5
 * This is a full rewrite of the pciDriver.
 
6
 * New default is to support kernel 2.6, using kernel 2.6 APIs.
 
7
 * 
 
8
 * This header defines the interface to the outside world.
 
9
 * 
 
10
 * $Revision: 1.6 $
 
11
 * $Date: 2008-01-24 14:21:36 $
 
12
 * 
 
13
 */
 
14
 
 
15
/*
 
16
 * Change History:
 
17
 * 
 
18
 * $Log: not supported by cvs2svn $
 
19
 * Revision 1.5  2008-01-11 10:15:14  marcus
 
20
 * Removed unused interrupt code.
 
21
 * Added intSource to the wait interrupt call.
 
22
 *
 
23
 * Revision 1.4  2006/11/17 18:44:42  marcus
 
24
 * Type of SG list can now be selected at runtime. Added type to sglist.
 
25
 *
 
26
 * Revision 1.3  2006/11/17 16:23:02  marcus
 
27
 * Added slot number to the PCI info IOctl.
 
28
 *
 
29
 * Revision 1.2  2006/11/13 12:29:09  marcus
 
30
 * Added a IOctl call, to confiure the interrupt response. (testing pending).
 
31
 * Basic interrupts are now supported.
 
32
 *
 
33
 * Revision 1.1  2006/10/10 14:46:52  marcus
 
34
 * Initial commit of the new pciDriver for kernel 2.6
 
35
 *
 
36
 * Revision 1.7  2006/10/06 15:18:06  marcus
 
37
 * Updated PCI info and PCI cmd
 
38
 *
 
39
 * Revision 1.6  2006/09/25 16:51:07  marcus
 
40
 * Added PCI config IOctls, and implemented basic mmap functions.
 
41
 *
 
42
 * Revision 1.5  2006/09/18 17:13:12  marcus
 
43
 * backup commit.
 
44
 *
 
45
 * Revision 1.4  2006/09/15 15:44:41  marcus
 
46
 * backup commit.
 
47
 *
 
48
 * Revision 1.3  2006/08/15 11:40:02  marcus
 
49
 * backup commit.
 
50
 *
 
51
 * Revision 1.2  2006/08/12 18:28:42  marcus
 
52
 * Sync with the laptop
 
53
 *
 
54
 * Revision 1.1  2006/08/11 15:30:46  marcus
 
55
 * Sync with the laptop
 
56
 *
 
57
 */
 
58
 
 
59
#include <linux/ioctl.h>
 
60
 
 
61
/* Possible values for ioctl commands */
 
62
 
 
63
/* PCI mmap areas */
 
64
#define PCIDRIVER_BAR0          0
 
65
#define PCIDRIVER_BAR1          1
 
66
#define PCIDRIVER_BAR2          2
 
67
#define PCIDRIVER_BAR3          3
 
68
#define PCIDRIVER_BAR4          4
 
69
#define PCIDRIVER_BAR5          5
 
70
 
 
71
/* mmap mode of the device */
 
72
#define PCIDRIVER_MMAP_PCI      0
 
73
#define PCIDRIVER_MMAP_KMEM 1
 
74
 
 
75
/* Direction of a DMA operation */
 
76
#define PCIDRIVER_DMA_BIDIRECTIONAL 0
 
77
#define PCIDRIVER_DMA_TODEVICE          1
 
78
#define PCIDRIVER_DMA_FROMDEVICE        2
 
79
 
 
80
/* Possible sizes in a PCI command */
 
81
#define PCIDRIVER_PCI_CFG_SZ_BYTE  1
 
82
#define PCIDRIVER_PCI_CFG_SZ_WORD  2
 
83
#define PCIDRIVER_PCI_CFG_SZ_DWORD 3
 
84
 
 
85
/* Possible types of SG lists */
 
86
#define PCIDRIVER_SG_NONMERGED 0
 
87
#define PCIDRIVER_SG_MERGED 1
 
88
 
 
89
/* Maximum number of interrupt sources */
 
90
#define PCIDRIVER_INT_MAXSOURCES 16
 
91
 
 
92
/* Types */
 
93
typedef struct {
 
94
        unsigned long pa;
 
95
        unsigned long size;
 
96
        int handle_id;
 
97
} kmem_handle_t;
 
98
 
 
99
typedef struct {
 
100
        unsigned long addr;
 
101
        unsigned long size;
 
102
} umem_sgentry_t;
 
103
 
 
104
typedef struct {
 
105
        int handle_id;
 
106
        int type;
 
107
        int nents;
 
108
        umem_sgentry_t *sg;
 
109
} umem_sglist_t;
 
110
 
 
111
typedef struct {
 
112
        unsigned long vma;
 
113
        unsigned long size;
 
114
        int handle_id;
 
115
        int dir;
 
116
} umem_handle_t;
 
117
 
 
118
typedef struct {
 
119
        kmem_handle_t handle;
 
120
        int dir;
 
121
} kmem_sync_t;
 
122
 
 
123
 
 
124
typedef struct {
 
125
        int size;
 
126
        int addr;
 
127
        union {
 
128
                unsigned char byte;
 
129
                unsigned short word;
 
130
                unsigned int dword;     /* not strict C, but if not can have problems */
 
131
        } val;
 
132
} pci_cfg_cmd;
 
133
 
 
134
typedef struct {
 
135
        unsigned short vendor_id;
 
136
        unsigned short device_id;
 
137
        unsigned short bus;
 
138
        unsigned short slot;
 
139
        unsigned short devfn;
 
140
        unsigned char interrupt_pin;
 
141
        unsigned char interrupt_line;
 
142
        unsigned int irq;
 
143
        unsigned long bar_start[6];
 
144
        unsigned long bar_length[6];
 
145
} pci_board_info;
 
146
 
 
147
 
 
148
/* ioctl interface */
 
149
/* See documentation for a detailed usage explanation */
 
150
 
 
151
/* 
 
152
 * one of the problems of ioctl, is that requires a type definition.
 
153
 * This type is only 8-bits wide, and half-documented in 
 
154
 * <linux-src>/Documentation/ioctl-number.txt.
 
155
 * previous SHL -> 'S' definition, conflicts with several devices,
 
156
 * so I changed it to be pci -> 'p', in the range 0xA0-AF
 
157
 */
 
158
#define PCIDRIVER_IOC_MAGIC 'p'
 
159
#define PCIDRIVER_IOC_BASE  0xA0
 
160
 
 
161
#define PCIDRIVER_IOC_MMAP_MODE  _IO(  PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 0 )
 
162
#define PCIDRIVER_IOC_MMAP_AREA  _IO(  PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 1 )
 
163
#define PCIDRIVER_IOC_KMEM_ALLOC _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 2, kmem_handle_t * )
 
164
#define PCIDRIVER_IOC_KMEM_FREE  _IOW(  PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 3, kmem_handle_t * )
 
165
#define PCIDRIVER_IOC_KMEM_SYNC  _IOW(  PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 4, kmem_sync_t * )
 
166
#define PCIDRIVER_IOC_UMEM_SGMAP _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 5, umem_handle_t * )
 
167
#define PCIDRIVER_IOC_UMEM_SGUNMAP _IOW(  PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 6, umem_handle_t * )
 
168
#define PCIDRIVER_IOC_UMEM_SGGET _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 7, umem_sglist_t * )
 
169
#define PCIDRIVER_IOC_UMEM_SYNC  _IOW(  PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 8, umem_handle_t * )
 
170
#define PCIDRIVER_IOC_WAITI      _IO(   PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 9 )
 
171
 
 
172
/* And now, the methods to access the PCI configuration area */
 
173
#define PCIDRIVER_IOC_PCI_CFG_RD  _IOWR(  PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 10, pci_cfg_cmd * )
 
174
#define PCIDRIVER_IOC_PCI_CFG_WR  _IOWR(  PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 11, pci_cfg_cmd * )
 
175
#define PCIDRIVER_IOC_PCI_INFO    _IOWR(  PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 12, pci_board_info * )
 
176
 
 
177
/* Clear interrupt queues */
 
178
#define PCIDRIVER_IOC_CLEAR_IOQ   _IO(   PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 13 )
 
179
 
 
180
#endif