6f25a7715a973ae07a6d1f71bdb15d638a56e7aa
[tsi148vmebridge.git] / driver / vmebus.h
1 /**
2  * \file vmebus.h
3  * \brief PCI-VME public API
4  * \author Sébastien Dugué
5  * \date 04/02/2009
6  *
7  *  This API presents in fact 2 APIs with some common definitions. One for
8  * drivers and one for user applications. User applications cannot use the
9  * driver specific parts enclosed in \#ifdef __KERNEL__ sections.
10  *
11  * Copyright (c) 2009 \em Sébastien \em Dugué
12  *
13  * \par License:
14  *      This program is free software; you can redistribute  it and/or
15  *      modify it under  the terms of  the GNU General  Public License as
16  *      published by the Free Software Foundation;  either version 2 of the
17  *      License, or (at your option) any later version.
18  *
19  */
20
21 #ifndef _VME_H
22 #define _VME_H
23
24 /*
25  * VME window attributes
26  */
27
28 /**
29  * \brief Read prefetch size
30  */
31 enum vme_read_prefetch_size {
32         VME_PREFETCH_2  = 0,
33         VME_PREFETCH_4,
34         VME_PREFETCH_8,
35         VME_PREFETCH_16
36 };
37
38 /**
39  * \brief Data width
40  */
41 enum vme_data_width {
42         VME_D8  = 8,
43         VME_D16 = 16,
44         VME_D32 = 32,
45         VME_D64 = 64
46 };
47
48 /**
49  * \brief 2eSST data transfer speed
50  */
51 enum vme_2esst_mode {
52         VME_SST160      = 0,
53         VME_SST267,
54         VME_SST320
55 };
56
57 /**
58  * \brief Address modifiers
59  */
60 enum vme_address_modifier {
61         VME_A64_MBLT            = 0,    /* 0x00 */
62         VME_A64_SCT,                    /* 0x01 */
63         VME_A64_BLT             = 3,    /* 0x03 */
64         VME_A64_LCK,                    /* 0x04 */
65         VME_A32_LCK,                    /* 0x05 */
66         VME_A32_USER_MBLT       = 8,    /* 0x08 */
67         VME_A32_USER_DATA_SCT,          /* 0x09 */
68         VME_A32_USER_PRG_SCT,           /* 0x0a */
69         VME_A32_USER_BLT,               /* 0x0b */
70         VME_A32_SUP_MBLT,               /* 0x0c */
71         VME_A32_SUP_DATA_SCT,           /* 0x0d */
72         VME_A32_SUP_PRG_SCT,            /* 0x0e */
73         VME_A32_SUP_BLT,                /* 0x0f */
74         VME_2e6U                = 0x20, /* 0x20 */
75         VME_2e3U,                       /* 0x21 */
76         VME_A16_USER            = 0x29, /* 0x29 */
77         VME_A16_LCK             = 0x2c, /* 0x2c */
78         VME_A16_SUP             = 0x2d, /* 0x2d */
79         VME_CR_CSR              = 0x2f, /* 0x2f */
80         VME_A40_SCT             = 0x34, /* 0x34 */
81         VME_A40_LCK,                    /* 0x35 */
82         VME_A40_BLT             = 0x37, /* 0x37 */
83         VME_A24_USER_MBLT,              /* 0x38 */
84         VME_A24_USER_DATA_SCT,          /* 0x39 */
85         VME_A24_USER_PRG_SCT,           /* 0x3a */
86         VME_A24_USER_BLT,               /* 0x3b */
87         VME_A24_SUP_MBLT,               /* 0x3c */
88         VME_A24_SUP_DATA_SCT,           /* 0x3d */
89         VME_A24_SUP_PRG_SCT,            /* 0x3e */
90         VME_A24_SUP_BLT,                /* 0x3f */
91 };
92
93
94
95 /**
96  * \brief PCI-VME mapping descriptor
97  * \param window_num Hardware window number
98  * \param kernel_va Kernel virtual address of the mapping for use by drivers
99  * \param user_va User virtual address of the mapping for use by applications
100  * \param fd User file descriptor for this mapping
101  * \param window_enabled State of the hardware window
102  * \param data_width VME data width
103  * \param am VME address modifier
104  * \param read_prefetch_enabled PCI read prefetch enabled state
105  * \param read_prefetch_size PCI read prefetch size (in cache lines)
106  * \param v2esst_mode VME 2eSST transfer speed
107  * \param bcast_select VME 2eSST broadcast select
108  * \param pci_addru PCI bus start address upper 32 bits
109  * \param pci_addrl PCI bus start address lower 32 bits
110  * \param sizeu Window size upper 32 bits
111  * \param sizel Window size lower 32 bits
112  * \param vme_addru VME bus start address upper 32 bits
113  * \param vme_addrl VME bus start address lower 32 bits
114  *
115  * This data structure is used for describing both a hardware window
116  * and a logical mapping on top of a hardware window. Therefore some of
117  * the fields are only relevant to one of those two entities.
118  */
119 struct vme_mapping {
120         int     window_num;
121
122         /* Reserved for kernel use */
123         void    *kernel_va;
124
125         /* Reserved for userspace */
126         void    *user_va;
127         int     fd;
128
129         /* Window settings */
130         int                             window_enabled;
131         enum vme_data_width             data_width;
132         enum vme_address_modifier       am;
133         int                             read_prefetch_enabled;
134         enum vme_read_prefetch_size     read_prefetch_size;
135         enum vme_2esst_mode             v2esst_mode;
136         int                             bcast_select;
137         unsigned int                    pci_addru;
138         unsigned int                    pci_addrl;
139         unsigned int                    sizeu;
140         unsigned int                    sizel;
141         unsigned int                    vme_addru;
142         unsigned int                    vme_addrl;
143 };
144
145 /**
146  * \brief VME RMW descriptor
147  * \param vme_addru VME address for the RMW cycle upper 32 bits
148  * \param vme_addrl VME address for the RMW cycle lower 32 bits
149  * \param am VME address modifier
150  * \param enable_mask Bitmask of the bit
151  * \param compare_data
152  * \param swap_data
153  *
154  */
155 struct vme_rmw {
156         unsigned int vme_addru;
157         unsigned int vme_addrl;
158         enum vme_address_modifier am;
159         unsigned int enable_mask;
160         unsigned int compare_data;
161         unsigned int swap_data;
162 };
163
164 /**
165  * \brief DMA endpoint attributes
166  * \param data_width VME data width (only used if endpoint is on the VME bus)
167  * \param am VME address modifier (ditto)
168  * \param v2esst_mode VME 2eSST transfer speed (ditto)
169  * \param bcast_select VME 2eSST broadcast select (ditto)
170  * \param addru Address upper 32 bits
171  * \param addrl Address lower 32 bits
172  *
173  *  This data structure is used for describing the attributes of a DMA endpoint.
174  * All the field excepted for the address are only relevant for an endpoint
175  * on the VME bus.
176  */
177 struct vme_dma_attr {
178         enum vme_data_width             data_width;
179         enum vme_address_modifier       am;
180         enum vme_2esst_mode             v2esst_mode;
181         unsigned int                    bcast_select;
182         unsigned int                    addru;
183         unsigned int                    addrl;
184 };
185
186 /** \brief DMA block size on the PCI or VME bus */
187 enum vme_dma_block_size {
188         VME_DMA_BSIZE_32 = 0,
189         VME_DMA_BSIZE_64,
190         VME_DMA_BSIZE_128,
191         VME_DMA_BSIZE_256,
192         VME_DMA_BSIZE_512,
193         VME_DMA_BSIZE_1024,
194         VME_DMA_BSIZE_2048,
195         VME_DMA_BSIZE_4096
196 };
197
198 /** \brief DMA backoff time (us) on the PCI or VME bus */
199 enum vme_dma_backoff {
200         VME_DMA_BACKOFF_0 = 0,
201         VME_DMA_BACKOFF_1,
202         VME_DMA_BACKOFF_2,
203         VME_DMA_BACKOFF_4,
204         VME_DMA_BACKOFF_8,
205         VME_DMA_BACKOFF_16,
206         VME_DMA_BACKOFF_32,
207         VME_DMA_BACKOFF_64
208 };
209
210 /**
211  * \brief DMA control
212  * \param vme_block_size VME bus block size when the source is VME
213  * \param vme_backoff_time VME bus backoff time when the source is VME
214  * \param pci_block_size PCI/X bus block size when the source is PCI
215  * \param pci_backoff_time PCI bus backoff time when the source is PCI
216  *
217  */
218 struct vme_dma_ctrl {
219         enum vme_dma_block_size vme_block_size;
220         enum vme_dma_backoff    vme_backoff_time;
221         enum vme_dma_block_size pci_block_size;
222         enum vme_dma_backoff    pci_backoff_time;
223 };
224
225 /** \brief DMA transfer direction */
226 enum vme_dma_dir {
227         VME_DMA_TO_DEVICE = 1,
228         VME_DMA_FROM_DEVICE
229 };
230
231 /**
232  * \brief VME DMA transfer descriptor
233  * \param status Transfer status
234  * \param length Transfer size in bytes
235  * \param novmeinc Must be set to 1 when accessing a FIFO like device on the VME
236  * \param dir Transfer direction
237  * \param src Transfer source attributes
238  * \param dst Transfer destination attributes
239  * \param opt Transfer control
240  *
241  */
242 struct vme_dma {
243         unsigned int            status;
244         unsigned int            length;
245         unsigned int            novmeinc;
246         enum vme_dma_dir        dir;
247
248         struct vme_dma_attr     src;
249         struct vme_dma_attr     dst;
250
251         struct vme_dma_ctrl     ctrl;
252 };
253
254
255
256 /*! @name VME single access swapping policy
257  *@{
258  */
259 #define SINGLE_NO_SWAP          0
260 #define SINGLE_AUTO_SWAP        1
261 #define SINGLE_WORD_SWAP        2
262 #define SINGLE_BYTEWORD_SWAP    3
263 /*@}*/
264
265
266 /*! @name page qualifier
267  *
268  *@{
269  */
270 #define VME_PG_SHARED  0x00
271 #define VME_PG_PRIVATE 0x02
272 /*@}*/
273
274
275 /**
276  * \brief VME mapping attributes
277  * \param iack VME IACK 0 -> IACK pages
278  * \param rdpref VME read prefetch option 0 -> Disable
279  * \param wrpost VME write posting option
280  * \param swap VME swap options
281  * \param sgmin page descriptor number returned by find_controller
282  * \param dum -- dum[0] page qualifier (shared/private), dum[1] XPC ADP-type
283  *               dum[2] - reserved, _must_ be 0.
284  *
285  * This structure is used for the find_controller() and return_controller()
286  * LynxOS CES driver emulation.
287  */
288 struct pdparam_master
289 {
290         unsigned long iack;
291         unsigned long rdpref;
292         unsigned long wrpost;
293         unsigned long swap;
294         unsigned long sgmin;
295         unsigned long dum[3];
296 };
297
298
299
300 /**
301  * \name Window management ioctl numbers
302  * \{
303  */
304 /** Get a physical window attributes */
305 #define VME_IOCTL_GET_WINDOW_ATTR       _IOWR('V', 0, struct vme_mapping)
306 /** Create a physical window */
307 #define VME_IOCTL_CREATE_WINDOW         _IOW( 'V', 1, struct vme_mapping)
308 /** Destroy a physical window */
309 #define VME_IOCTL_DESTROY_WINDOW        _IOW( 'V', 2, int)
310 /** Create a mapping over a physical window */
311 #define VME_IOCTL_FIND_MAPPING          _IOWR('V', 3, struct vme_mapping)
312 /** Remove a mapping */
313 #define VME_IOCTL_RELEASE_MAPPING       _IOW( 'V', 4, struct vme_mapping)
314 /** Get the create on find failed flag */
315 #define VME_IOCTL_GET_CREATE_ON_FIND_FAIL       _IOR( 'V', 5, unsigned int)
316 /** Set the create on find failed flag */
317 #define VME_IOCTL_SET_CREATE_ON_FIND_FAIL       _IOW( 'V', 6, unsigned int)
318 /** Get the destroy on remove flag */
319 #define VME_IOCTL_GET_DESTROY_ON_REMOVE _IOR( 'V', 7, unsigned int)
320 /** Set the destroy on remove flag */
321 #define VME_IOCTL_SET_DESTROY_ON_REMOVE _IOW( 'V', 8, unsigned int)
322 /** Get bus error status */
323 #define VME_IOCTL_GET_BUS_ERROR         _IOR( 'V', 9, unsigned int)
324 /* \}*/
325
326 /**
327  * DMA ioctls
328  * \{
329  */
330 /** Start a DMA transfer */
331 #define VME_IOCTL_START_DMA             _IOWR('V', 10, struct vme_dma)
332 /* \}*/
333
334
335 #ifdef __KERNEL__
336
337 /*
338  * Those definitions are for drivers only and are not visible to userspace.
339  */
340
341 /* API for new drivers */
342 extern int vme_request_irq(unsigned int, int (*)(void *),
343                            void *, const char *);
344 extern int vme_free_irq(unsigned int );
345 extern int vme_generate_interrupt(int, int, signed long);
346
347 extern struct vme_mapping* find_vme_mapping_from_addr(unsigned);
348 extern int vme_get_window_attr(struct vme_mapping *);
349 extern int vme_create_window(struct vme_mapping *);
350 extern int vme_destroy_window(int);
351 extern int vme_find_mapping(struct vme_mapping *, int);
352 extern int vme_release_mapping(struct vme_mapping *, int);
353
354 extern int vme_do_dma(struct vme_dma *);
355
356
357 extern int vme_bus_error_check(int);
358
359 /* API providing an emulation of the CES VME driver for legacy drivers */
360 extern unsigned long find_controller(unsigned long, unsigned long,
361                                      unsigned long, unsigned long,
362                                      unsigned long, struct pdparam_master *);
363 extern unsigned long return_controller(unsigned, unsigned);
364 extern int vme_intset(int, int (*)(void *), void *, void *);
365 extern int vme_intclr(int, void *);
366
367
368 #endif /* __KERNEL__ */
369
370
371 #endif /* _VME_H */