Xenomai API  2.6.5
mite.h
Go to the documentation of this file.
1 
21 #ifndef __ANALOGY_NI_MITE_H__
22 #define __ANALOGY_NI_MITE_H__
23 
24 #include <linux/pci.h>
25 
26 #include <analogy/analogy_driver.h>
27 
28 #define PCI_VENDOR_ID_NATINST 0x1093
29 #define PCI_MITE_SIZE 4096
30 #define PCI_DAQ_SIZE 4096
31 #define PCI_DAQ_SIZE_660X 8192
32 #define PCIMIO_COMPAT
33 #define MAX_MITE_DMA_CHANNELS 8
34 
35 #define TOP_OF_PAGE(x) ((x)|(~(PAGE_MASK)))
36 
37 struct mite_dma_descriptor {
38  u32 count;
39  u32 addr;
40  u32 next;
41  u32 dar;
42 };
43 
44 struct mite_dma_descriptor_ring {
45  struct pci_dev *pcidev;
46  u32 n_links;
47  struct mite_dma_descriptor *descriptors;
48  dma_addr_t descriptors_dma_addr;
49 };
50 
51 struct mite_channel {
52  struct mite_struct *mite;
53  u32 channel;
54  u32 dir;
55  u32 done;
56  struct mite_dma_descriptor_ring *ring;
57 };
58 
59 struct mite_struct {
60  struct list_head list;
61  a4l_lock_t lock;
62  u32 used;
63  u32 num_channels;
64 
65  struct mite_channel channels[MAX_MITE_DMA_CHANNELS];
66  u32 channel_allocated[MAX_MITE_DMA_CHANNELS];
67 
68  struct pci_dev *pcidev;
69  resource_size_t mite_phys_addr;
70  void *mite_io_addr;
71  resource_size_t daq_phys_addr;
72  void *daq_io_addr;
73 };
74 
75 static inline
76 struct mite_dma_descriptor_ring *mite_alloc_ring(struct mite_struct *mite)
77 {
78  struct mite_dma_descriptor_ring *ring =
79  kmalloc(sizeof(struct mite_dma_descriptor_ring), GFP_DMA);
80 
81  if (ring == NULL)
82  return ring;
83 
84  memset(ring, 0, sizeof(struct mite_dma_descriptor_ring));
85 
86  ring->pcidev = mite->pcidev;
87  if (ring->pcidev == NULL) {
88  kfree(ring);
89  return NULL;
90  }
91 
92  return ring;
93 };
94 
95 static inline void mite_free_ring(struct mite_dma_descriptor_ring *ring)
96 {
97  if (ring) {
98  if (ring->descriptors) {
99  pci_free_consistent(
100  ring->pcidev,
101  ring->n_links *
102  sizeof(struct mite_dma_descriptor),
103  ring->descriptors, ring->descriptors_dma_addr);
104  }
105  kfree(ring);
106  }
107 };
108 
109 static inline unsigned int mite_irq(struct mite_struct *mite)
110 {
111  return mite->pcidev->irq;
112 };
113 static inline unsigned int mite_device_id(struct mite_struct *mite)
114 {
115  return mite->pcidev->device;
116 };
117 
118 int a4l_mite_setup(struct mite_struct *mite, int use_iodwbsr_1);
119 void a4l_mite_unsetup(struct mite_struct *mite);
120 void a4l_mite_list_devices(void);
121 struct mite_struct * a4l_mite_find_device(int bus,
122  int slot, unsigned short device_id);
123 struct mite_channel *
124 a4l_mite_request_channel_in_range(struct mite_struct *mite,
125  struct mite_dma_descriptor_ring *ring,
126  unsigned min_channel, unsigned max_channel);
127 static inline struct mite_channel *mite_request_channel(struct mite_struct
128  *mite, struct mite_dma_descriptor_ring *ring)
129 {
130  return a4l_mite_request_channel_in_range(mite, ring, 0,
131  mite->num_channels - 1);
132 }
133 void a4l_mite_release_channel(struct mite_channel *mite_chan);
134 
135 void a4l_mite_dma_arm(struct mite_channel *mite_chan);
136 void a4l_mite_dma_disarm(struct mite_channel *mite_chan);
137 int a4l_mite_sync_input_dma(struct mite_channel *mite_chan, a4l_subd_t *subd);
138 int a4l_mite_sync_output_dma(struct mite_channel *mite_chan, a4l_subd_t *subd);
139 u32 a4l_mite_bytes_written_to_memory_lb(struct mite_channel *mite_chan);
140 u32 a4l_mite_bytes_written_to_memory_ub(struct mite_channel *mite_chan);
141 u32 a4l_mite_bytes_read_from_memory_lb(struct mite_channel *mite_chan);
142 u32 a4l_mite_bytes_read_from_memory_ub(struct mite_channel *mite_chan);
143 u32 a4l_mite_bytes_in_transit(struct mite_channel *mite_chan);
144 u32 a4l_mite_get_status(struct mite_channel *mite_chan);
145 int a4l_mite_done(struct mite_channel *mite_chan);
146 void a4l_mite_prep_dma(struct mite_channel *mite_chan,
147  unsigned int num_device_bits, unsigned int num_memory_bits);
148 int a4l_mite_buf_change(struct mite_dma_descriptor_ring *ring, a4l_subd_t *subd);
149 
150 #ifdef CONFIG_DEBUG_MITE
151 void mite_print_chsr(unsigned int chsr);
152 void a4l_mite_dump_regs(struct mite_channel *mite_chan);
153 #endif
154 
155 static inline int CHAN_OFFSET(int channel)
156 {
157  return 0x500 + 0x100 * channel;
158 };
159 
160 enum mite_registers {
161  /* The bits 0x90180700 in MITE_UNKNOWN_DMA_BURST_REG can be
162  written and read back. The bits 0x1f always read as 1.
163  The rest always read as zero. */
164  MITE_UNKNOWN_DMA_BURST_REG = 0x28,
165  MITE_IODWBSR = 0xc0, //IO Device Window Base Size Register
166  MITE_IODWBSR_1 = 0xc4, // IO Device Window Base Size Register 1
167  MITE_IODWCR_1 = 0xf4,
168  MITE_PCI_CONFIG_OFFSET = 0x300,
169  MITE_CSIGR = 0x460 //chip signature
170 };
171 static inline int MITE_CHOR(int channel) // channel operation
172 {
173  return CHAN_OFFSET(channel) + 0x0;
174 };
175 static inline int MITE_CHCR(int channel) // channel control
176 {
177  return CHAN_OFFSET(channel) + 0x4;
178 };
179 static inline int MITE_TCR(int channel) // transfer count
180 {
181  return CHAN_OFFSET(channel) + 0x8;
182 };
183 static inline int MITE_MCR(int channel) // memory configuration
184 {
185  return CHAN_OFFSET(channel) + 0xc;
186 };
187 static inline int MITE_MAR(int channel) // memory address
188 {
189  return CHAN_OFFSET(channel) + 0x10;
190 };
191 static inline int MITE_DCR(int channel) // device configuration
192 {
193  return CHAN_OFFSET(channel) + 0x14;
194 };
195 static inline int MITE_DAR(int channel) // device address
196 {
197  return CHAN_OFFSET(channel) + 0x18;
198 };
199 static inline int MITE_LKCR(int channel) // link configuration
200 {
201  return CHAN_OFFSET(channel) + 0x1c;
202 };
203 static inline int MITE_LKAR(int channel) // link address
204 {
205  return CHAN_OFFSET(channel) + 0x20;
206 };
207 static inline int MITE_LLKAR(int channel) // see mite section of tnt5002 manual
208 {
209  return CHAN_OFFSET(channel) + 0x24;
210 };
211 static inline int MITE_BAR(int channel) // base address
212 {
213  return CHAN_OFFSET(channel) + 0x28;
214 };
215 static inline int MITE_BCR(int channel) // base count
216 {
217  return CHAN_OFFSET(channel) + 0x2c;
218 };
219 static inline int MITE_SAR(int channel) // ? address
220 {
221  return CHAN_OFFSET(channel) + 0x30;
222 };
223 static inline int MITE_WSCR(int channel) // ?
224 {
225  return CHAN_OFFSET(channel) + 0x34;
226 };
227 static inline int MITE_WSER(int channel) // ?
228 {
229  return CHAN_OFFSET(channel) + 0x38;
230 };
231 static inline int MITE_CHSR(int channel) // channel status
232 {
233  return CHAN_OFFSET(channel) + 0x3c;
234 };
235 static inline int MITE_FCR(int channel) // fifo count
236 {
237  return CHAN_OFFSET(channel) + 0x40;
238 };
239 
240 enum MITE_IODWBSR_bits {
241  WENAB = 0x80, // window enable
242 };
243 
244 static inline unsigned MITE_IODWBSR_1_WSIZE_bits(unsigned size)
245 {
246  unsigned order = 0;
247  while (size >>= 1)
248  ++order;
249  BUG_ON(order < 1);
250  return (order - 1) & 0x1f;
251 }
252 
253 enum MITE_UNKNOWN_DMA_BURST_bits {
254  UNKNOWN_DMA_BURST_ENABLE_BITS = 0x600
255 };
256 
257 static inline int mite_csigr_version(u32 csigr_bits)
258 {
259  return csigr_bits & 0xf;
260 };
261 static inline int mite_csigr_type(u32 csigr_bits)
262 { // original mite = 0, minimite = 1
263  return (csigr_bits >> 4) & 0xf;
264 };
265 static inline int mite_csigr_mmode(u32 csigr_bits)
266 { // mite mode, minimite = 1
267  return (csigr_bits >> 8) & 0x3;
268 };
269 static inline int mite_csigr_imode(u32 csigr_bits)
270 { // cpu port interface mode, pci = 0x3
271  return (csigr_bits >> 12) & 0x3;
272 };
273 static inline int mite_csigr_dmac(u32 csigr_bits)
274 { // number of dma channels
275  return (csigr_bits >> 16) & 0xf;
276 };
277 static inline int mite_csigr_wpdep(u32 csigr_bits)
278 { // write post fifo depth
279  unsigned int wpdep_bits = (csigr_bits >> 20) & 0x7;
280  if (wpdep_bits == 0)
281  return 0;
282  else
283  return 1 << (wpdep_bits - 1);
284 };
285 static inline int mite_csigr_wins(u32 csigr_bits)
286 {
287  return (csigr_bits >> 24) & 0x1f;
288 };
289 static inline int mite_csigr_iowins(u32 csigr_bits)
290 { // number of io windows
291  return (csigr_bits >> 29) & 0x7;
292 };
293 
294 enum MITE_MCR_bits {
295  MCRPON = 0,
296 };
297 
298 enum MITE_DCR_bits {
299  DCR_NORMAL = (1 << 29),
300  DCRPON = 0,
301 };
302 
303 enum MITE_CHOR_bits {
304  CHOR_DMARESET = (1 << 31),
305  CHOR_SET_SEND_TC = (1 << 11),
306  CHOR_CLR_SEND_TC = (1 << 10),
307  CHOR_SET_LPAUSE = (1 << 9),
308  CHOR_CLR_LPAUSE = (1 << 8),
309  CHOR_CLRDONE = (1 << 7),
310  CHOR_CLRRB = (1 << 6),
311  CHOR_CLRLC = (1 << 5),
312  CHOR_FRESET = (1 << 4),
313  CHOR_ABORT = (1 << 3), /* stop without emptying fifo */
314  CHOR_STOP = (1 << 2), /* stop after emptying fifo */
315  CHOR_CONT = (1 << 1),
316  CHOR_START = (1 << 0),
317  CHOR_PON = (CHOR_CLR_SEND_TC | CHOR_CLR_LPAUSE),
318 };
319 
320 enum MITE_CHCR_bits {
321  CHCR_SET_DMA_IE = (1 << 31),
322  CHCR_CLR_DMA_IE = (1 << 30),
323  CHCR_SET_LINKP_IE = (1 << 29),
324  CHCR_CLR_LINKP_IE = (1 << 28),
325  CHCR_SET_SAR_IE = (1 << 27),
326  CHCR_CLR_SAR_IE = (1 << 26),
327  CHCR_SET_DONE_IE = (1 << 25),
328  CHCR_CLR_DONE_IE = (1 << 24),
329  CHCR_SET_MRDY_IE = (1 << 23),
330  CHCR_CLR_MRDY_IE = (1 << 22),
331  CHCR_SET_DRDY_IE = (1 << 21),
332  CHCR_CLR_DRDY_IE = (1 << 20),
333  CHCR_SET_LC_IE = (1 << 19),
334  CHCR_CLR_LC_IE = (1 << 18),
335  CHCR_SET_CONT_RB_IE = (1 << 17),
336  CHCR_CLR_CONT_RB_IE = (1 << 16),
337  CHCR_FIFODIS = (1 << 15),
338  CHCR_FIFO_ON = 0,
339  CHCR_BURSTEN = (1 << 14),
340  CHCR_NO_BURSTEN = 0,
341  CHCR_BYTE_SWAP_DEVICE = (1 << 6),
342  CHCR_BYTE_SWAP_MEMORY = (1 << 4),
343  CHCR_DIR = (1 << 3),
344  CHCR_DEV_TO_MEM = CHCR_DIR,
345  CHCR_MEM_TO_DEV = 0,
346  CHCR_NORMAL = (0 << 0),
347  CHCR_CONTINUE = (1 << 0),
348  CHCR_RINGBUFF = (2 << 0),
349  CHCR_LINKSHORT = (4 << 0),
350  CHCR_LINKLONG = (5 << 0),
351  CHCRPON =
352  (CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE | CHCR_CLR_SAR_IE |
353  CHCR_CLR_DONE_IE | CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE |
354  CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE),
355 };
356 
357 enum ConfigRegister_bits {
358  CR_REQS_MASK = 0x7 << 16,
359  CR_ASEQDONT = 0x0 << 10,
360  CR_ASEQUP = 0x1 << 10,
361  CR_ASEQDOWN = 0x2 << 10,
362  CR_ASEQ_MASK = 0x3 << 10,
363  CR_PSIZE8 = (1 << 8),
364  CR_PSIZE16 = (2 << 8),
365  CR_PSIZE32 = (3 << 8),
366  CR_PORTCPU = (0 << 6),
367  CR_PORTIO = (1 << 6),
368  CR_PORTVXI = (2 << 6),
369  CR_PORTMXI = (3 << 6),
370  CR_AMDEVICE = (1 << 0),
371 };
372 static inline int CR_REQS(int source)
373 {
374  return (source & 0x7) << 16;
375 };
376 static inline int CR_REQSDRQ(unsigned drq_line)
377 {
378  /* This also works on m-series when
379  using channels (drq_line) 4 or 5. */
380  return CR_REQS((drq_line & 0x3) | 0x4);
381 }
382 static inline int CR_RL(unsigned int retry_limit)
383 {
384  int value = 0;
385 
386  while (retry_limit) {
387  retry_limit >>= 1;
388  value++;
389  }
390  if (value > 0x7)
391  __a4l_err("bug! retry_limit too large\n");
392 
393  return (value & 0x7) << 21;
394 }
395 
396 enum CHSR_bits {
397  CHSR_INT = (1 << 31),
398  CHSR_LPAUSES = (1 << 29),
399  CHSR_SARS = (1 << 27),
400  CHSR_DONE = (1 << 25),
401  CHSR_MRDY = (1 << 23),
402  CHSR_DRDY = (1 << 21),
403  CHSR_LINKC = (1 << 19),
404  CHSR_CONTS_RB = (1 << 17),
405  CHSR_ERROR = (1 << 15),
406  CHSR_SABORT = (1 << 14),
407  CHSR_HABORT = (1 << 13),
408  CHSR_STOPS = (1 << 12),
409  CHSR_OPERR_mask = (3 << 10),
410  CHSR_OPERR_NOERROR = (0 << 10),
411  CHSR_OPERR_FIFOERROR = (1 << 10),
412  CHSR_OPERR_LINKERROR = (1 << 10), /* ??? */
413  CHSR_XFERR = (1 << 9),
414  CHSR_END = (1 << 8),
415  CHSR_DRQ1 = (1 << 7),
416  CHSR_DRQ0 = (1 << 6),
417  CHSR_LxERR_mask = (3 << 4),
418  CHSR_LBERR = (1 << 4),
419  CHSR_LRERR = (2 << 4),
420  CHSR_LOERR = (3 << 4),
421  CHSR_MxERR_mask = (3 << 2),
422  CHSR_MBERR = (1 << 2),
423  CHSR_MRERR = (2 << 2),
424  CHSR_MOERR = (3 << 2),
425  CHSR_DxERR_mask = (3 << 0),
426  CHSR_DBERR = (1 << 0),
427  CHSR_DRERR = (2 << 0),
428  CHSR_DOERR = (3 << 0),
429 };
430 
431 static inline void mite_dma_reset(struct mite_channel *mite_chan)
432 {
433  writel(CHOR_DMARESET | CHOR_FRESET,
434  mite_chan->mite->mite_io_addr + MITE_CHOR(mite_chan->channel));
435 };
436 
437 #endif /* !__ANALOGY_NI_MITE_H__ */
Analogy for Linux, driver facilities.
Structure describing the subdevice.
Definition: subdevice.h:180