00001
00021 #ifndef __ANALOGY_NI_MITE_H__
00022 #define __ANALOGY_NI_MITE_H__
00023
00024 #include <linux/pci.h>
00025
00026 #include <analogy/analogy_driver.h>
00027
00028 #define PCI_VENDOR_ID_NATINST 0x1093
00029 #define PCI_MITE_SIZE 4096
00030 #define PCI_DAQ_SIZE 4096
00031 #define PCI_DAQ_SIZE_660X 8192
00032 #define PCIMIO_COMPAT
00033 #define MAX_MITE_DMA_CHANNELS 8
00034
00035 #define TOP_OF_PAGE(x) ((x)|(~(PAGE_MASK)))
00036
00037 struct mite_dma_descriptor {
00038 u32 count;
00039 u32 addr;
00040 u32 next;
00041 u32 dar;
00042 };
00043
00044 struct mite_dma_descriptor_ring {
00045 struct pci_dev *pcidev;
00046 u32 n_links;
00047 struct mite_dma_descriptor *descriptors;
00048 dma_addr_t descriptors_dma_addr;
00049 };
00050
00051 struct mite_channel {
00052 struct mite_struct *mite;
00053 u32 channel;
00054 u32 dir;
00055 u32 done;
00056 struct mite_dma_descriptor_ring *ring;
00057 };
00058
00059 struct mite_struct {
00060 struct list_head list;
00061 a4l_lock_t lock;
00062 u32 used;
00063 u32 num_channels;
00064
00065 struct mite_channel channels[MAX_MITE_DMA_CHANNELS];
00066 u32 channel_allocated[MAX_MITE_DMA_CHANNELS];
00067
00068 struct pci_dev *pcidev;
00069 resource_size_t mite_phys_addr;
00070 void *mite_io_addr;
00071 resource_size_t daq_phys_addr;
00072 void *daq_io_addr;
00073 };
00074
00075 static inline
00076 struct mite_dma_descriptor_ring *mite_alloc_ring(struct mite_struct *mite)
00077 {
00078 struct mite_dma_descriptor_ring *ring =
00079 kmalloc(sizeof(struct mite_dma_descriptor_ring), GFP_DMA);
00080
00081 if (ring == NULL)
00082 return ring;
00083
00084 memset(ring, 0, sizeof(struct mite_dma_descriptor_ring));
00085
00086 ring->pcidev = mite->pcidev;
00087 if (ring->pcidev == NULL) {
00088 kfree(ring);
00089 return NULL;
00090 }
00091
00092 return ring;
00093 };
00094
00095 static inline void mite_free_ring(struct mite_dma_descriptor_ring *ring)
00096 {
00097 if (ring) {
00098 if (ring->descriptors) {
00099 pci_free_consistent(
00100 ring->pcidev,
00101 ring->n_links *
00102 sizeof(struct mite_dma_descriptor),
00103 ring->descriptors, ring->descriptors_dma_addr);
00104 }
00105 kfree(ring);
00106 }
00107 };
00108
00109 static inline unsigned int mite_irq(struct mite_struct *mite)
00110 {
00111 return mite->pcidev->irq;
00112 };
00113 static inline unsigned int mite_device_id(struct mite_struct *mite)
00114 {
00115 return mite->pcidev->device;
00116 };
00117
00118 int mite_setup(struct mite_struct *mite, int use_iodwbsr_1);
00119 void mite_unsetup(struct mite_struct *mite);
00120 void mite_list_devices(void);
00121 struct mite_struct * mite_find_device(int bus,
00122 int slot, unsigned short device_id);
00123 struct mite_channel *mite_request_channel_in_range(struct mite_struct *mite,
00124 struct mite_dma_descriptor_ring *ring, unsigned min_channel,
00125 unsigned max_channel);
00126 static inline struct mite_channel *mite_request_channel(struct mite_struct
00127 *mite, struct mite_dma_descriptor_ring *ring)
00128 {
00129 return mite_request_channel_in_range(mite, ring, 0,
00130 mite->num_channels - 1);
00131 }
00132 void mite_release_channel(struct mite_channel *mite_chan);
00133
00134 void mite_dma_arm(struct mite_channel *mite_chan);
00135 void mite_dma_disarm(struct mite_channel *mite_chan);
00136 int mite_sync_input_dma(struct mite_channel *mite_chan, a4l_subd_t *subd);
00137 int mite_sync_output_dma(struct mite_channel *mite_chan, a4l_subd_t *subd);
00138 u32 mite_bytes_written_to_memory_lb(struct mite_channel *mite_chan);
00139 u32 mite_bytes_written_to_memory_ub(struct mite_channel *mite_chan);
00140 u32 mite_bytes_read_from_memory_lb(struct mite_channel *mite_chan);
00141 u32 mite_bytes_read_from_memory_ub(struct mite_channel *mite_chan);
00142 u32 mite_bytes_in_transit(struct mite_channel *mite_chan);
00143 u32 mite_get_status(struct mite_channel *mite_chan);
00144 int mite_done(struct mite_channel *mite_chan);
00145 void mite_prep_dma(struct mite_channel *mite_chan,
00146 unsigned int num_device_bits, unsigned int num_memory_bits);
00147 int mite_buf_change(struct mite_dma_descriptor_ring *ring, a4l_subd_t *subd);
00148
00149 #ifdef CONFIG_DEBUG_MITE
00150 void mite_print_chsr(unsigned int chsr);
00151 void mite_dump_regs(struct mite_channel *mite_chan);
00152 #endif
00153
00154 static inline int CHAN_OFFSET(int channel)
00155 {
00156 return 0x500 + 0x100 * channel;
00157 };
00158
00159 enum mite_registers {
00160
00161
00162
00163 MITE_UNKNOWN_DMA_BURST_REG = 0x28,
00164 MITE_IODWBSR = 0xc0,
00165 MITE_IODWBSR_1 = 0xc4,
00166 MITE_IODWCR_1 = 0xf4,
00167 MITE_PCI_CONFIG_OFFSET = 0x300,
00168 MITE_CSIGR = 0x460
00169 };
00170 static inline int MITE_CHOR(int channel)
00171 {
00172 return CHAN_OFFSET(channel) + 0x0;
00173 };
00174 static inline int MITE_CHCR(int channel)
00175 {
00176 return CHAN_OFFSET(channel) + 0x4;
00177 };
00178 static inline int MITE_TCR(int channel)
00179 {
00180 return CHAN_OFFSET(channel) + 0x8;
00181 };
00182 static inline int MITE_MCR(int channel)
00183 {
00184 return CHAN_OFFSET(channel) + 0xc;
00185 };
00186 static inline int MITE_MAR(int channel)
00187 {
00188 return CHAN_OFFSET(channel) + 0x10;
00189 };
00190 static inline int MITE_DCR(int channel)
00191 {
00192 return CHAN_OFFSET(channel) + 0x14;
00193 };
00194 static inline int MITE_DAR(int channel)
00195 {
00196 return CHAN_OFFSET(channel) + 0x18;
00197 };
00198 static inline int MITE_LKCR(int channel)
00199 {
00200 return CHAN_OFFSET(channel) + 0x1c;
00201 };
00202 static inline int MITE_LKAR(int channel)
00203 {
00204 return CHAN_OFFSET(channel) + 0x20;
00205 };
00206 static inline int MITE_LLKAR(int channel)
00207 {
00208 return CHAN_OFFSET(channel) + 0x24;
00209 };
00210 static inline int MITE_BAR(int channel)
00211 {
00212 return CHAN_OFFSET(channel) + 0x28;
00213 };
00214 static inline int MITE_BCR(int channel)
00215 {
00216 return CHAN_OFFSET(channel) + 0x2c;
00217 };
00218 static inline int MITE_SAR(int channel)
00219 {
00220 return CHAN_OFFSET(channel) + 0x30;
00221 };
00222 static inline int MITE_WSCR(int channel)
00223 {
00224 return CHAN_OFFSET(channel) + 0x34;
00225 };
00226 static inline int MITE_WSER(int channel)
00227 {
00228 return CHAN_OFFSET(channel) + 0x38;
00229 };
00230 static inline int MITE_CHSR(int channel)
00231 {
00232 return CHAN_OFFSET(channel) + 0x3c;
00233 };
00234 static inline int MITE_FCR(int channel)
00235 {
00236 return CHAN_OFFSET(channel) + 0x40;
00237 };
00238
00239 enum MITE_IODWBSR_bits {
00240 WENAB = 0x80,
00241 };
00242
00243 static inline unsigned MITE_IODWBSR_1_WSIZE_bits(unsigned size)
00244 {
00245 unsigned order = 0;
00246 while (size >>= 1)
00247 ++order;
00248 BUG_ON(order < 1);
00249 return (order - 1) & 0x1f;
00250 }
00251
00252 enum MITE_UNKNOWN_DMA_BURST_bits {
00253 UNKNOWN_DMA_BURST_ENABLE_BITS = 0x600
00254 };
00255
00256 static inline int mite_csigr_version(u32 csigr_bits)
00257 {
00258 return csigr_bits & 0xf;
00259 };
00260 static inline int mite_csigr_type(u32 csigr_bits)
00261 {
00262 return (csigr_bits >> 4) & 0xf;
00263 };
00264 static inline int mite_csigr_mmode(u32 csigr_bits)
00265 {
00266 return (csigr_bits >> 8) & 0x3;
00267 };
00268 static inline int mite_csigr_imode(u32 csigr_bits)
00269 {
00270 return (csigr_bits >> 12) & 0x3;
00271 };
00272 static inline int mite_csigr_dmac(u32 csigr_bits)
00273 {
00274 return (csigr_bits >> 16) & 0xf;
00275 };
00276 static inline int mite_csigr_wpdep(u32 csigr_bits)
00277 {
00278 unsigned int wpdep_bits = (csigr_bits >> 20) & 0x7;
00279 if (wpdep_bits == 0)
00280 return 0;
00281 else
00282 return 1 << (wpdep_bits - 1);
00283 };
00284 static inline int mite_csigr_wins(u32 csigr_bits)
00285 {
00286 return (csigr_bits >> 24) & 0x1f;
00287 };
00288 static inline int mite_csigr_iowins(u32 csigr_bits)
00289 {
00290 return (csigr_bits >> 29) & 0x7;
00291 };
00292
00293 enum MITE_MCR_bits {
00294 MCRPON = 0,
00295 };
00296
00297 enum MITE_DCR_bits {
00298 DCR_NORMAL = (1 << 29),
00299 DCRPON = 0,
00300 };
00301
00302 enum MITE_CHOR_bits {
00303 CHOR_DMARESET = (1 << 31),
00304 CHOR_SET_SEND_TC = (1 << 11),
00305 CHOR_CLR_SEND_TC = (1 << 10),
00306 CHOR_SET_LPAUSE = (1 << 9),
00307 CHOR_CLR_LPAUSE = (1 << 8),
00308 CHOR_CLRDONE = (1 << 7),
00309 CHOR_CLRRB = (1 << 6),
00310 CHOR_CLRLC = (1 << 5),
00311 CHOR_FRESET = (1 << 4),
00312 CHOR_ABORT = (1 << 3),
00313 CHOR_STOP = (1 << 2),
00314 CHOR_CONT = (1 << 1),
00315 CHOR_START = (1 << 0),
00316 CHOR_PON = (CHOR_CLR_SEND_TC | CHOR_CLR_LPAUSE),
00317 };
00318
00319 enum MITE_CHCR_bits {
00320 CHCR_SET_DMA_IE = (1 << 31),
00321 CHCR_CLR_DMA_IE = (1 << 30),
00322 CHCR_SET_LINKP_IE = (1 << 29),
00323 CHCR_CLR_LINKP_IE = (1 << 28),
00324 CHCR_SET_SAR_IE = (1 << 27),
00325 CHCR_CLR_SAR_IE = (1 << 26),
00326 CHCR_SET_DONE_IE = (1 << 25),
00327 CHCR_CLR_DONE_IE = (1 << 24),
00328 CHCR_SET_MRDY_IE = (1 << 23),
00329 CHCR_CLR_MRDY_IE = (1 << 22),
00330 CHCR_SET_DRDY_IE = (1 << 21),
00331 CHCR_CLR_DRDY_IE = (1 << 20),
00332 CHCR_SET_LC_IE = (1 << 19),
00333 CHCR_CLR_LC_IE = (1 << 18),
00334 CHCR_SET_CONT_RB_IE = (1 << 17),
00335 CHCR_CLR_CONT_RB_IE = (1 << 16),
00336 CHCR_FIFODIS = (1 << 15),
00337 CHCR_FIFO_ON = 0,
00338 CHCR_BURSTEN = (1 << 14),
00339 CHCR_NO_BURSTEN = 0,
00340 CHCR_BYTE_SWAP_DEVICE = (1 << 6),
00341 CHCR_BYTE_SWAP_MEMORY = (1 << 4),
00342 CHCR_DIR = (1 << 3),
00343 CHCR_DEV_TO_MEM = CHCR_DIR,
00344 CHCR_MEM_TO_DEV = 0,
00345 CHCR_NORMAL = (0 << 0),
00346 CHCR_CONTINUE = (1 << 0),
00347 CHCR_RINGBUFF = (2 << 0),
00348 CHCR_LINKSHORT = (4 << 0),
00349 CHCR_LINKLONG = (5 << 0),
00350 CHCRPON =
00351 (CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE | CHCR_CLR_SAR_IE |
00352 CHCR_CLR_DONE_IE | CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE |
00353 CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE),
00354 };
00355
00356 enum ConfigRegister_bits {
00357 CR_REQS_MASK = 0x7 << 16,
00358 CR_ASEQDONT = 0x0 << 10,
00359 CR_ASEQUP = 0x1 << 10,
00360 CR_ASEQDOWN = 0x2 << 10,
00361 CR_ASEQ_MASK = 0x3 << 10,
00362 CR_PSIZE8 = (1 << 8),
00363 CR_PSIZE16 = (2 << 8),
00364 CR_PSIZE32 = (3 << 8),
00365 CR_PORTCPU = (0 << 6),
00366 CR_PORTIO = (1 << 6),
00367 CR_PORTVXI = (2 << 6),
00368 CR_PORTMXI = (3 << 6),
00369 CR_AMDEVICE = (1 << 0),
00370 };
00371 static inline int CR_REQS(int source)
00372 {
00373 return (source & 0x7) << 16;
00374 };
00375 static inline int CR_REQSDRQ(unsigned drq_line)
00376 {
00377
00378
00379 return CR_REQS((drq_line & 0x3) | 0x4);
00380 }
00381 static inline int CR_RL(unsigned int retry_limit)
00382 {
00383 int value = 0;
00384
00385 while (retry_limit) {
00386 retry_limit >>= 1;
00387 value++;
00388 }
00389 if (value > 0x7)
00390 __a4l_err("bug! retry_limit too large\n");
00391
00392 return (value & 0x7) << 21;
00393 }
00394
00395 enum CHSR_bits {
00396 CHSR_INT = (1 << 31),
00397 CHSR_LPAUSES = (1 << 29),
00398 CHSR_SARS = (1 << 27),
00399 CHSR_DONE = (1 << 25),
00400 CHSR_MRDY = (1 << 23),
00401 CHSR_DRDY = (1 << 21),
00402 CHSR_LINKC = (1 << 19),
00403 CHSR_CONTS_RB = (1 << 17),
00404 CHSR_ERROR = (1 << 15),
00405 CHSR_SABORT = (1 << 14),
00406 CHSR_HABORT = (1 << 13),
00407 CHSR_STOPS = (1 << 12),
00408 CHSR_OPERR_mask = (3 << 10),
00409 CHSR_OPERR_NOERROR = (0 << 10),
00410 CHSR_OPERR_FIFOERROR = (1 << 10),
00411 CHSR_OPERR_LINKERROR = (1 << 10),
00412 CHSR_XFERR = (1 << 9),
00413 CHSR_END = (1 << 8),
00414 CHSR_DRQ1 = (1 << 7),
00415 CHSR_DRQ0 = (1 << 6),
00416 CHSR_LxERR_mask = (3 << 4),
00417 CHSR_LBERR = (1 << 4),
00418 CHSR_LRERR = (2 << 4),
00419 CHSR_LOERR = (3 << 4),
00420 CHSR_MxERR_mask = (3 << 2),
00421 CHSR_MBERR = (1 << 2),
00422 CHSR_MRERR = (2 << 2),
00423 CHSR_MOERR = (3 << 2),
00424 CHSR_DxERR_mask = (3 << 0),
00425 CHSR_DBERR = (1 << 0),
00426 CHSR_DRERR = (2 << 0),
00427 CHSR_DOERR = (3 << 0),
00428 };
00429
00430 static inline void mite_dma_reset(struct mite_channel *mite_chan)
00431 {
00432 writel(CHOR_DMARESET | CHOR_FRESET,
00433 mite_chan->mite->mite_io_addr + MITE_CHOR(mite_chan->channel));
00434 };
00435
00436 #endif