2 * Support for the Tundra TSI148 VME-PCI Bridge Chip
4 * Author: Martyn Welch <martyn.welch@ge.com>
5 * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
7 * Based on work by Tom Armistead and Ajit Prem
8 * Copyright 2004 Motorola Inc.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
19 #include <linux/types.h>
20 #include <linux/errno.h>
21 #include <linux/proc_fs.h>
22 #include <linux/pci.h>
23 #include <linux/poll.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/interrupt.h>
26 #include <linux/spinlock.h>
27 #include <linux/sched.h>
28 #include <linux/slab.h>
29 #include <linux/time.h>
31 #include <linux/uaccess.h>
32 #include <linux/byteorder/generic.h>
33 #include <linux/vme.h>
35 #include "../vme_bridge.h"
36 #include "vme_tsi148.h"
38 static int tsi148_probe(struct pci_dev *, const struct pci_device_id *);
39 static void tsi148_remove(struct pci_dev *);
42 /* Module parameter */
46 static const char driver_name[] = "vme_tsi148";
48 static const struct pci_device_id tsi148_ids[] = {
49 { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_TSI148) },
53 MODULE_DEVICE_TABLE(pci, tsi148_ids);
55 static struct pci_driver tsi148_driver = {
57 .id_table = tsi148_ids,
58 .probe = tsi148_probe,
59 .remove = tsi148_remove,
62 static void reg_join(unsigned int high, unsigned int low,
63 unsigned long long *variable)
65 *variable = (unsigned long long)high << 32;
66 *variable |= (unsigned long long)low;
69 static void reg_split(unsigned long long variable, unsigned int *high,
72 *low = (unsigned int)variable & 0xFFFFFFFF;
73 *high = (unsigned int)(variable >> 32);
79 static u32 tsi148_DMA_irqhandler(struct tsi148_driver *bridge,
84 if (channel_mask & TSI148_LCSR_INTS_DMA0S) {
85 wake_up(&bridge->dma_queue[0]);
86 serviced |= TSI148_LCSR_INTC_DMA0C;
88 if (channel_mask & TSI148_LCSR_INTS_DMA1S) {
89 wake_up(&bridge->dma_queue[1]);
90 serviced |= TSI148_LCSR_INTC_DMA1C;
97 * Wake up location monitor queue
99 static u32 tsi148_LM_irqhandler(struct tsi148_driver *bridge, u32 stat)
104 for (i = 0; i < 4; i++) {
105 if (stat & TSI148_LCSR_INTS_LMS[i]) {
106 /* We only enable interrupts if the callback is set */
107 bridge->lm_callback[i](bridge->lm_data[i]);
108 serviced |= TSI148_LCSR_INTC_LMC[i];
116 * Wake up mail box queue.
118 * XXX This functionality is not exposed up though API.
120 static u32 tsi148_MB_irqhandler(struct vme_bridge *tsi148_bridge, u32 stat)
125 struct tsi148_driver *bridge;
127 bridge = tsi148_bridge->driver_priv;
129 for (i = 0; i < 4; i++) {
130 if (stat & TSI148_LCSR_INTS_MBS[i]) {
131 val = ioread32be(bridge->base + TSI148_GCSR_MBOX[i]);
132 dev_err(tsi148_bridge->parent, "VME Mailbox %d received"
134 serviced |= TSI148_LCSR_INTC_MBC[i];
142 * Display error & status message when PERR (PCI) exception interrupt occurs.
144 static u32 tsi148_PERR_irqhandler(struct vme_bridge *tsi148_bridge)
146 struct tsi148_driver *bridge;
148 bridge = tsi148_bridge->driver_priv;
150 dev_err(tsi148_bridge->parent, "PCI Exception at address: 0x%08x:%08x, "
151 "attributes: %08x\n",
152 ioread32be(bridge->base + TSI148_LCSR_EDPAU),
153 ioread32be(bridge->base + TSI148_LCSR_EDPAL),
154 ioread32be(bridge->base + TSI148_LCSR_EDPAT));
156 dev_err(tsi148_bridge->parent, "PCI-X attribute reg: %08x, PCI-X split "
157 "completion reg: %08x\n",
158 ioread32be(bridge->base + TSI148_LCSR_EDPXA),
159 ioread32be(bridge->base + TSI148_LCSR_EDPXS));
161 iowrite32be(TSI148_LCSR_EDPAT_EDPCL, bridge->base + TSI148_LCSR_EDPAT);
163 return TSI148_LCSR_INTC_PERRC;
167 * Save address and status when VME error interrupt occurs.
169 static u32 tsi148_VERR_irqhandler(struct vme_bridge *tsi148_bridge)
171 unsigned int error_addr_high, error_addr_low;
172 unsigned long long error_addr;
175 struct tsi148_driver *bridge;
177 bridge = tsi148_bridge->driver_priv;
179 error_addr_high = ioread32be(bridge->base + TSI148_LCSR_VEAU);
180 error_addr_low = ioread32be(bridge->base + TSI148_LCSR_VEAL);
181 error_attrib = ioread32be(bridge->base + TSI148_LCSR_VEAT);
182 error_am = (error_attrib & TSI148_LCSR_VEAT_AM_M) >> 8;
184 reg_join(error_addr_high, error_addr_low, &error_addr);
186 /* Check for exception register overflow (we have lost error data) */
187 if (error_attrib & TSI148_LCSR_VEAT_VEOF) {
188 dev_err(tsi148_bridge->parent, "VME Bus Exception Overflow "
193 vme_bus_error_handler(tsi148_bridge, error_addr, error_am);
195 dev_err(tsi148_bridge->parent,
196 "VME Bus Error at address: 0x%llx, attributes: %08x\n",
197 error_addr, error_attrib);
200 iowrite32be(TSI148_LCSR_VEAT_VESCL, bridge->base + TSI148_LCSR_VEAT);
202 return TSI148_LCSR_INTC_VERRC;
206 * Wake up IACK queue.
208 static u32 tsi148_IACK_irqhandler(struct tsi148_driver *bridge)
210 wake_up(&bridge->iack_queue);
212 return TSI148_LCSR_INTC_IACKC;
216 * Calling VME bus interrupt callback if provided.
218 static u32 tsi148_VIRQ_irqhandler(struct vme_bridge *tsi148_bridge,
221 int vec, i, serviced = 0;
222 struct tsi148_driver *bridge;
224 bridge = tsi148_bridge->driver_priv;
226 for (i = 7; i > 0; i--) {
227 if (stat & (1 << i)) {
229 * Note: Even though the registers are defined as
230 * 32-bits in the spec, we only want to issue 8-bit
231 * IACK cycles on the bus, read from offset 3.
233 vec = ioread8(bridge->base + TSI148_LCSR_VIACK[i] + 3);
235 vme_irq_handler(tsi148_bridge, i, vec);
237 serviced |= (1 << i);
245 * Top level interrupt handler. Clears appropriate interrupt status bits and
246 * then calls appropriate sub handler(s).
248 static irqreturn_t tsi148_irqhandler(int irq, void *ptr)
250 u32 stat, enable, serviced = 0;
251 struct vme_bridge *tsi148_bridge;
252 struct tsi148_driver *bridge;
256 bridge = tsi148_bridge->driver_priv;
258 /* Determine which interrupts are unmasked and set */
259 enable = ioread32be(bridge->base + TSI148_LCSR_INTEO);
260 stat = ioread32be(bridge->base + TSI148_LCSR_INTS);
262 /* Only look at unmasked interrupts */
268 /* Call subhandlers as appropriate */
270 if (stat & (TSI148_LCSR_INTS_DMA1S | TSI148_LCSR_INTS_DMA0S))
271 serviced |= tsi148_DMA_irqhandler(bridge, stat);
273 /* Location monitor irqs */
274 if (stat & (TSI148_LCSR_INTS_LM3S | TSI148_LCSR_INTS_LM2S |
275 TSI148_LCSR_INTS_LM1S | TSI148_LCSR_INTS_LM0S))
276 serviced |= tsi148_LM_irqhandler(bridge, stat);
279 if (stat & (TSI148_LCSR_INTS_MB3S | TSI148_LCSR_INTS_MB2S |
280 TSI148_LCSR_INTS_MB1S | TSI148_LCSR_INTS_MB0S))
281 serviced |= tsi148_MB_irqhandler(tsi148_bridge, stat);
284 if (stat & TSI148_LCSR_INTS_PERRS)
285 serviced |= tsi148_PERR_irqhandler(tsi148_bridge);
288 if (stat & TSI148_LCSR_INTS_VERRS)
289 serviced |= tsi148_VERR_irqhandler(tsi148_bridge);
292 if (stat & TSI148_LCSR_INTS_IACKS)
293 serviced |= tsi148_IACK_irqhandler(bridge);
296 if (stat & (TSI148_LCSR_INTS_IRQ7S | TSI148_LCSR_INTS_IRQ6S |
297 TSI148_LCSR_INTS_IRQ5S | TSI148_LCSR_INTS_IRQ4S |
298 TSI148_LCSR_INTS_IRQ3S | TSI148_LCSR_INTS_IRQ2S |
299 TSI148_LCSR_INTS_IRQ1S))
300 serviced |= tsi148_VIRQ_irqhandler(tsi148_bridge, stat);
302 /* Clear serviced interrupts */
303 iowrite32be(serviced, bridge->base + TSI148_LCSR_INTC);
308 static int tsi148_irq_init(struct vme_bridge *tsi148_bridge)
312 struct pci_dev *pdev;
313 struct tsi148_driver *bridge;
315 pdev = to_pci_dev(tsi148_bridge->parent);
317 bridge = tsi148_bridge->driver_priv;
319 result = request_irq(pdev->irq,
322 driver_name, tsi148_bridge);
324 dev_err(tsi148_bridge->parent, "Can't get assigned pci irq "
325 "vector %02X\n", pdev->irq);
329 /* Enable and unmask interrupts */
330 tmp = TSI148_LCSR_INTEO_DMA1EO | TSI148_LCSR_INTEO_DMA0EO |
331 TSI148_LCSR_INTEO_MB3EO | TSI148_LCSR_INTEO_MB2EO |
332 TSI148_LCSR_INTEO_MB1EO | TSI148_LCSR_INTEO_MB0EO |
333 TSI148_LCSR_INTEO_PERREO | TSI148_LCSR_INTEO_VERREO |
334 TSI148_LCSR_INTEO_IACKEO;
336 /* This leaves the following interrupts masked.
337 * TSI148_LCSR_INTEO_VIEEO
338 * TSI148_LCSR_INTEO_SYSFLEO
339 * TSI148_LCSR_INTEO_ACFLEO
342 /* Don't enable Location Monitor interrupts here - they will be
343 * enabled when the location monitors are properly configured and
344 * a callback has been attached.
345 * TSI148_LCSR_INTEO_LM0EO
346 * TSI148_LCSR_INTEO_LM1EO
347 * TSI148_LCSR_INTEO_LM2EO
348 * TSI148_LCSR_INTEO_LM3EO
351 /* Don't enable VME interrupts until we add a handler, else the board
352 * will respond to it and we don't want that unless it knows how to
353 * properly deal with it.
354 * TSI148_LCSR_INTEO_IRQ7EO
355 * TSI148_LCSR_INTEO_IRQ6EO
356 * TSI148_LCSR_INTEO_IRQ5EO
357 * TSI148_LCSR_INTEO_IRQ4EO
358 * TSI148_LCSR_INTEO_IRQ3EO
359 * TSI148_LCSR_INTEO_IRQ2EO
360 * TSI148_LCSR_INTEO_IRQ1EO
363 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
364 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN);
369 static void tsi148_irq_exit(struct vme_bridge *tsi148_bridge,
370 struct pci_dev *pdev)
372 struct tsi148_driver *bridge = tsi148_bridge->driver_priv;
374 /* Turn off interrupts */
375 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEO);
376 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEN);
378 /* Clear all interrupts */
379 iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_INTC);
381 /* Detach interrupt handler */
382 free_irq(pdev->irq, tsi148_bridge);
386 * Check to see if an IACk has been received, return true (1) or false (0).
388 static int tsi148_iack_received(struct tsi148_driver *bridge)
392 tmp = ioread32be(bridge->base + TSI148_LCSR_VICR);
394 if (tmp & TSI148_LCSR_VICR_IRQS)
401 * Configure VME interrupt
403 static void tsi148_irq_set(struct vme_bridge *tsi148_bridge, int level,
406 struct pci_dev *pdev;
408 struct tsi148_driver *bridge;
410 bridge = tsi148_bridge->driver_priv;
412 /* We need to do the ordering differently for enabling and disabling */
414 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEN);
415 tmp &= ~TSI148_LCSR_INTEN_IRQEN[level - 1];
416 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN);
418 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO);
419 tmp &= ~TSI148_LCSR_INTEO_IRQEO[level - 1];
420 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
423 pdev = to_pci_dev(tsi148_bridge->parent);
424 synchronize_irq(pdev->irq);
427 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO);
428 tmp |= TSI148_LCSR_INTEO_IRQEO[level - 1];
429 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
431 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEN);
432 tmp |= TSI148_LCSR_INTEN_IRQEN[level - 1];
433 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN);
438 * Generate a VME bus interrupt at the requested level & vector. Wait for
439 * interrupt to be acked.
441 static int tsi148_irq_generate(struct vme_bridge *tsi148_bridge, int level,
445 struct tsi148_driver *bridge;
447 bridge = tsi148_bridge->driver_priv;
449 mutex_lock(&bridge->vme_int);
451 /* Read VICR register */
452 tmp = ioread32be(bridge->base + TSI148_LCSR_VICR);
455 tmp = (tmp & ~TSI148_LCSR_VICR_STID_M) |
456 (statid & TSI148_LCSR_VICR_STID_M);
457 iowrite32be(tmp, bridge->base + TSI148_LCSR_VICR);
459 /* Assert VMEbus IRQ */
460 tmp = tmp | TSI148_LCSR_VICR_IRQL[level];
461 iowrite32be(tmp, bridge->base + TSI148_LCSR_VICR);
463 /* XXX Consider implementing a timeout? */
464 wait_event_interruptible(bridge->iack_queue,
465 tsi148_iack_received(bridge));
467 mutex_unlock(&bridge->vme_int);
473 * Initialize a slave window with the requested attributes.
475 static int tsi148_slave_set(struct vme_slave_resource *image, int enabled,
476 unsigned long long vme_base, unsigned long long size,
477 dma_addr_t pci_base, u32 aspace, u32 cycle)
479 unsigned int i, addr = 0, granularity = 0;
480 unsigned int temp_ctl = 0;
481 unsigned int vme_base_low, vme_base_high;
482 unsigned int vme_bound_low, vme_bound_high;
483 unsigned int pci_offset_low, pci_offset_high;
484 unsigned long long vme_bound, pci_offset;
485 struct vme_bridge *tsi148_bridge;
486 struct tsi148_driver *bridge;
488 tsi148_bridge = image->parent;
489 bridge = tsi148_bridge->driver_priv;
496 addr |= TSI148_LCSR_ITAT_AS_A16;
499 granularity = 0x1000;
500 addr |= TSI148_LCSR_ITAT_AS_A24;
503 granularity = 0x10000;
504 addr |= TSI148_LCSR_ITAT_AS_A32;
507 granularity = 0x10000;
508 addr |= TSI148_LCSR_ITAT_AS_A64;
511 dev_err(tsi148_bridge->parent, "Invalid address space\n");
516 /* Convert 64-bit variables to 2x 32-bit variables */
517 reg_split(vme_base, &vme_base_high, &vme_base_low);
520 * Bound address is a valid address for the window, adjust
523 vme_bound = vme_base + size - granularity;
524 reg_split(vme_bound, &vme_bound_high, &vme_bound_low);
525 pci_offset = (unsigned long long)pci_base - vme_base;
526 reg_split(pci_offset, &pci_offset_high, &pci_offset_low);
528 if (vme_base_low & (granularity - 1)) {
529 dev_err(tsi148_bridge->parent, "Invalid VME base alignment\n");
532 if (vme_bound_low & (granularity - 1)) {
533 dev_err(tsi148_bridge->parent, "Invalid VME bound alignment\n");
536 if (pci_offset_low & (granularity - 1)) {
537 dev_err(tsi148_bridge->parent, "Invalid PCI Offset "
542 /* Disable while we are mucking around */
543 temp_ctl = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
544 TSI148_LCSR_OFFSET_ITAT);
545 temp_ctl &= ~TSI148_LCSR_ITAT_EN;
546 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_IT[i] +
547 TSI148_LCSR_OFFSET_ITAT);
550 iowrite32be(vme_base_high, bridge->base + TSI148_LCSR_IT[i] +
551 TSI148_LCSR_OFFSET_ITSAU);
552 iowrite32be(vme_base_low, bridge->base + TSI148_LCSR_IT[i] +
553 TSI148_LCSR_OFFSET_ITSAL);
554 iowrite32be(vme_bound_high, bridge->base + TSI148_LCSR_IT[i] +
555 TSI148_LCSR_OFFSET_ITEAU);
556 iowrite32be(vme_bound_low, bridge->base + TSI148_LCSR_IT[i] +
557 TSI148_LCSR_OFFSET_ITEAL);
558 iowrite32be(pci_offset_high, bridge->base + TSI148_LCSR_IT[i] +
559 TSI148_LCSR_OFFSET_ITOFU);
560 iowrite32be(pci_offset_low, bridge->base + TSI148_LCSR_IT[i] +
561 TSI148_LCSR_OFFSET_ITOFL);
563 /* Setup 2eSST speeds */
564 temp_ctl &= ~TSI148_LCSR_ITAT_2eSSTM_M;
565 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
567 temp_ctl |= TSI148_LCSR_ITAT_2eSSTM_160;
570 temp_ctl |= TSI148_LCSR_ITAT_2eSSTM_267;
573 temp_ctl |= TSI148_LCSR_ITAT_2eSSTM_320;
577 /* Setup cycle types */
578 temp_ctl &= ~(0x1F << 7);
580 temp_ctl |= TSI148_LCSR_ITAT_BLT;
581 if (cycle & VME_MBLT)
582 temp_ctl |= TSI148_LCSR_ITAT_MBLT;
583 if (cycle & VME_2eVME)
584 temp_ctl |= TSI148_LCSR_ITAT_2eVME;
585 if (cycle & VME_2eSST)
586 temp_ctl |= TSI148_LCSR_ITAT_2eSST;
587 if (cycle & VME_2eSSTB)
588 temp_ctl |= TSI148_LCSR_ITAT_2eSSTB;
590 /* Setup address space */
591 temp_ctl &= ~TSI148_LCSR_ITAT_AS_M;
595 if (cycle & VME_SUPER)
596 temp_ctl |= TSI148_LCSR_ITAT_SUPR ;
597 if (cycle & VME_USER)
598 temp_ctl |= TSI148_LCSR_ITAT_NPRIV;
599 if (cycle & VME_PROG)
600 temp_ctl |= TSI148_LCSR_ITAT_PGM;
601 if (cycle & VME_DATA)
602 temp_ctl |= TSI148_LCSR_ITAT_DATA;
604 /* Write ctl reg without enable */
605 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_IT[i] +
606 TSI148_LCSR_OFFSET_ITAT);
609 temp_ctl |= TSI148_LCSR_ITAT_EN;
611 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_IT[i] +
612 TSI148_LCSR_OFFSET_ITAT);
618 * Get slave window configuration.
620 static int tsi148_slave_get(struct vme_slave_resource *image, int *enabled,
621 unsigned long long *vme_base, unsigned long long *size,
622 dma_addr_t *pci_base, u32 *aspace, u32 *cycle)
624 unsigned int i, granularity = 0, ctl = 0;
625 unsigned int vme_base_low, vme_base_high;
626 unsigned int vme_bound_low, vme_bound_high;
627 unsigned int pci_offset_low, pci_offset_high;
628 unsigned long long vme_bound, pci_offset;
629 struct tsi148_driver *bridge;
631 bridge = image->parent->driver_priv;
636 ctl = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
637 TSI148_LCSR_OFFSET_ITAT);
639 vme_base_high = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
640 TSI148_LCSR_OFFSET_ITSAU);
641 vme_base_low = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
642 TSI148_LCSR_OFFSET_ITSAL);
643 vme_bound_high = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
644 TSI148_LCSR_OFFSET_ITEAU);
645 vme_bound_low = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
646 TSI148_LCSR_OFFSET_ITEAL);
647 pci_offset_high = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
648 TSI148_LCSR_OFFSET_ITOFU);
649 pci_offset_low = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
650 TSI148_LCSR_OFFSET_ITOFL);
652 /* Convert 64-bit variables to 2x 32-bit variables */
653 reg_join(vme_base_high, vme_base_low, vme_base);
654 reg_join(vme_bound_high, vme_bound_low, &vme_bound);
655 reg_join(pci_offset_high, pci_offset_low, &pci_offset);
657 *pci_base = (dma_addr_t)(*vme_base + pci_offset);
663 if (ctl & TSI148_LCSR_ITAT_EN)
666 if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A16) {
670 if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A24) {
671 granularity = 0x1000;
674 if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A32) {
675 granularity = 0x10000;
678 if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A64) {
679 granularity = 0x10000;
683 /* Need granularity before we set the size */
684 *size = (unsigned long long)((vme_bound - *vme_base) + granularity);
687 if ((ctl & TSI148_LCSR_ITAT_2eSSTM_M) == TSI148_LCSR_ITAT_2eSSTM_160)
688 *cycle |= VME_2eSST160;
689 if ((ctl & TSI148_LCSR_ITAT_2eSSTM_M) == TSI148_LCSR_ITAT_2eSSTM_267)
690 *cycle |= VME_2eSST267;
691 if ((ctl & TSI148_LCSR_ITAT_2eSSTM_M) == TSI148_LCSR_ITAT_2eSSTM_320)
692 *cycle |= VME_2eSST320;
694 if (ctl & TSI148_LCSR_ITAT_BLT)
696 if (ctl & TSI148_LCSR_ITAT_MBLT)
698 if (ctl & TSI148_LCSR_ITAT_2eVME)
700 if (ctl & TSI148_LCSR_ITAT_2eSST)
702 if (ctl & TSI148_LCSR_ITAT_2eSSTB)
703 *cycle |= VME_2eSSTB;
705 if (ctl & TSI148_LCSR_ITAT_SUPR)
707 if (ctl & TSI148_LCSR_ITAT_NPRIV)
709 if (ctl & TSI148_LCSR_ITAT_PGM)
711 if (ctl & TSI148_LCSR_ITAT_DATA)
718 * Allocate and map PCI Resource
720 static int tsi148_alloc_resource(struct vme_master_resource *image,
721 unsigned long long size)
723 unsigned long long existing_size;
725 struct pci_dev *pdev;
726 struct vme_bridge *tsi148_bridge;
728 tsi148_bridge = image->parent;
730 pdev = to_pci_dev(tsi148_bridge->parent);
732 existing_size = (unsigned long long)(image->bus_resource.end -
733 image->bus_resource.start);
735 /* If the existing size is OK, return */
736 if ((size != 0) && (existing_size == (size - 1)))
739 if (existing_size != 0) {
740 iounmap(image->kern_base);
741 image->kern_base = NULL;
742 kfree(image->bus_resource.name);
743 release_resource(&image->bus_resource);
744 memset(&image->bus_resource, 0, sizeof(image->bus_resource));
747 /* Exit here if size is zero */
751 if (!image->bus_resource.name) {
752 image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC);
753 if (!image->bus_resource.name) {
759 sprintf((char *)image->bus_resource.name, "%s.%d", tsi148_bridge->name,
762 image->bus_resource.start = 0;
763 image->bus_resource.end = (unsigned long)size;
764 image->bus_resource.flags = IORESOURCE_MEM;
766 retval = pci_bus_alloc_resource(pdev->bus,
767 &image->bus_resource, size, 0x10000, PCIBIOS_MIN_MEM,
770 dev_err(tsi148_bridge->parent, "Failed to allocate mem "
771 "resource for window %d size 0x%lx start 0x%lx\n",
772 image->number, (unsigned long)size,
773 (unsigned long)image->bus_resource.start);
777 image->kern_base = ioremap_nocache(
778 image->bus_resource.start, size);
779 if (!image->kern_base) {
780 dev_err(tsi148_bridge->parent, "Failed to remap resource\n");
788 release_resource(&image->bus_resource);
790 kfree(image->bus_resource.name);
791 memset(&image->bus_resource, 0, sizeof(image->bus_resource));
797 * Free and unmap PCI Resource
799 static void tsi148_free_resource(struct vme_master_resource *image)
801 iounmap(image->kern_base);
802 image->kern_base = NULL;
803 release_resource(&image->bus_resource);
804 kfree(image->bus_resource.name);
805 memset(&image->bus_resource, 0, sizeof(image->bus_resource));
809 * Set the attributes of an outbound window.
811 static int tsi148_master_set(struct vme_master_resource *image, int enabled,
812 unsigned long long vme_base, unsigned long long size, u32 aspace,
813 u32 cycle, u32 dwidth)
817 unsigned int temp_ctl = 0;
818 unsigned int pci_base_low, pci_base_high;
819 unsigned int pci_bound_low, pci_bound_high;
820 unsigned int vme_offset_low, vme_offset_high;
821 unsigned long long pci_bound, vme_offset, pci_base;
822 struct vme_bridge *tsi148_bridge;
823 struct tsi148_driver *bridge;
824 struct pci_bus_region region;
825 struct pci_dev *pdev;
827 tsi148_bridge = image->parent;
829 bridge = tsi148_bridge->driver_priv;
831 pdev = to_pci_dev(tsi148_bridge->parent);
833 /* Verify input data */
834 if (vme_base & 0xFFFF) {
835 dev_err(tsi148_bridge->parent, "Invalid VME Window "
841 if ((size == 0) && (enabled != 0)) {
842 dev_err(tsi148_bridge->parent, "Size must be non-zero for "
843 "enabled windows\n");
848 spin_lock(&image->lock);
850 /* Let's allocate the resource here rather than further up the stack as
851 * it avoids pushing loads of bus dependent stuff up the stack. If size
852 * is zero, any existing resource will be freed.
854 retval = tsi148_alloc_resource(image, size);
856 spin_unlock(&image->lock);
857 dev_err(tsi148_bridge->parent, "Unable to allocate memory for "
867 pcibios_resource_to_bus(pdev->bus, ®ion,
868 &image->bus_resource);
869 pci_base = region.start;
872 * Bound address is a valid address for the window, adjust
873 * according to window granularity.
875 pci_bound = pci_base + (size - 0x10000);
876 vme_offset = vme_base - pci_base;
879 /* Convert 64-bit variables to 2x 32-bit variables */
880 reg_split(pci_base, &pci_base_high, &pci_base_low);
881 reg_split(pci_bound, &pci_bound_high, &pci_bound_low);
882 reg_split(vme_offset, &vme_offset_high, &vme_offset_low);
884 if (pci_base_low & 0xFFFF) {
885 spin_unlock(&image->lock);
886 dev_err(tsi148_bridge->parent, "Invalid PCI base alignment\n");
890 if (pci_bound_low & 0xFFFF) {
891 spin_unlock(&image->lock);
892 dev_err(tsi148_bridge->parent, "Invalid PCI bound alignment\n");
896 if (vme_offset_low & 0xFFFF) {
897 spin_unlock(&image->lock);
898 dev_err(tsi148_bridge->parent, "Invalid VME Offset "
906 /* Disable while we are mucking around */
907 temp_ctl = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
908 TSI148_LCSR_OFFSET_OTAT);
909 temp_ctl &= ~TSI148_LCSR_OTAT_EN;
910 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] +
911 TSI148_LCSR_OFFSET_OTAT);
913 /* Setup 2eSST speeds */
914 temp_ctl &= ~TSI148_LCSR_OTAT_2eSSTM_M;
915 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
917 temp_ctl |= TSI148_LCSR_OTAT_2eSSTM_160;
920 temp_ctl |= TSI148_LCSR_OTAT_2eSSTM_267;
923 temp_ctl |= TSI148_LCSR_OTAT_2eSSTM_320;
927 /* Setup cycle types */
928 if (cycle & VME_BLT) {
929 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
930 temp_ctl |= TSI148_LCSR_OTAT_TM_BLT;
932 if (cycle & VME_MBLT) {
933 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
934 temp_ctl |= TSI148_LCSR_OTAT_TM_MBLT;
936 if (cycle & VME_2eVME) {
937 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
938 temp_ctl |= TSI148_LCSR_OTAT_TM_2eVME;
940 if (cycle & VME_2eSST) {
941 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
942 temp_ctl |= TSI148_LCSR_OTAT_TM_2eSST;
944 if (cycle & VME_2eSSTB) {
945 dev_warn(tsi148_bridge->parent, "Currently not setting "
946 "Broadcast Select Registers\n");
947 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
948 temp_ctl |= TSI148_LCSR_OTAT_TM_2eSSTB;
951 /* Setup data width */
952 temp_ctl &= ~TSI148_LCSR_OTAT_DBW_M;
955 temp_ctl |= TSI148_LCSR_OTAT_DBW_16;
958 temp_ctl |= TSI148_LCSR_OTAT_DBW_32;
961 spin_unlock(&image->lock);
962 dev_err(tsi148_bridge->parent, "Invalid data width\n");
967 /* Setup address space */
968 temp_ctl &= ~TSI148_LCSR_OTAT_AMODE_M;
971 temp_ctl |= TSI148_LCSR_OTAT_AMODE_A16;
974 temp_ctl |= TSI148_LCSR_OTAT_AMODE_A24;
977 temp_ctl |= TSI148_LCSR_OTAT_AMODE_A32;
980 temp_ctl |= TSI148_LCSR_OTAT_AMODE_A64;
983 temp_ctl |= TSI148_LCSR_OTAT_AMODE_CRCSR;
986 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER1;
989 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER2;
992 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER3;
995 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER4;
998 spin_unlock(&image->lock);
999 dev_err(tsi148_bridge->parent, "Invalid address space\n");
1005 temp_ctl &= ~(3<<4);
1006 if (cycle & VME_SUPER)
1007 temp_ctl |= TSI148_LCSR_OTAT_SUP;
1008 if (cycle & VME_PROG)
1009 temp_ctl |= TSI148_LCSR_OTAT_PGM;
1012 iowrite32be(pci_base_high, bridge->base + TSI148_LCSR_OT[i] +
1013 TSI148_LCSR_OFFSET_OTSAU);
1014 iowrite32be(pci_base_low, bridge->base + TSI148_LCSR_OT[i] +
1015 TSI148_LCSR_OFFSET_OTSAL);
1016 iowrite32be(pci_bound_high, bridge->base + TSI148_LCSR_OT[i] +
1017 TSI148_LCSR_OFFSET_OTEAU);
1018 iowrite32be(pci_bound_low, bridge->base + TSI148_LCSR_OT[i] +
1019 TSI148_LCSR_OFFSET_OTEAL);
1020 iowrite32be(vme_offset_high, bridge->base + TSI148_LCSR_OT[i] +
1021 TSI148_LCSR_OFFSET_OTOFU);
1022 iowrite32be(vme_offset_low, bridge->base + TSI148_LCSR_OT[i] +
1023 TSI148_LCSR_OFFSET_OTOFL);
1025 /* Write ctl reg without enable */
1026 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] +
1027 TSI148_LCSR_OFFSET_OTAT);
1030 temp_ctl |= TSI148_LCSR_OTAT_EN;
1032 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] +
1033 TSI148_LCSR_OFFSET_OTAT);
1035 spin_unlock(&image->lock);
1041 tsi148_free_resource(image);
1049 * Set the attributes of an outbound window.
1051 * XXX Not parsing prefetch information.
1053 static int __tsi148_master_get(struct vme_master_resource *image, int *enabled,
1054 unsigned long long *vme_base, unsigned long long *size, u32 *aspace,
1055 u32 *cycle, u32 *dwidth)
1057 unsigned int i, ctl;
1058 unsigned int pci_base_low, pci_base_high;
1059 unsigned int pci_bound_low, pci_bound_high;
1060 unsigned int vme_offset_low, vme_offset_high;
1062 unsigned long long pci_base, pci_bound, vme_offset;
1063 struct tsi148_driver *bridge;
1065 bridge = image->parent->driver_priv;
1069 ctl = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1070 TSI148_LCSR_OFFSET_OTAT);
1072 pci_base_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1073 TSI148_LCSR_OFFSET_OTSAU);
1074 pci_base_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1075 TSI148_LCSR_OFFSET_OTSAL);
1076 pci_bound_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1077 TSI148_LCSR_OFFSET_OTEAU);
1078 pci_bound_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1079 TSI148_LCSR_OFFSET_OTEAL);
1080 vme_offset_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1081 TSI148_LCSR_OFFSET_OTOFU);
1082 vme_offset_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1083 TSI148_LCSR_OFFSET_OTOFL);
1085 /* Convert 64-bit variables to 2x 32-bit variables */
1086 reg_join(pci_base_high, pci_base_low, &pci_base);
1087 reg_join(pci_bound_high, pci_bound_low, &pci_bound);
1088 reg_join(vme_offset_high, vme_offset_low, &vme_offset);
1090 *vme_base = pci_base + vme_offset;
1091 *size = (unsigned long long)(pci_bound - pci_base) + 0x10000;
1098 if (ctl & TSI148_LCSR_OTAT_EN)
1101 /* Setup address space */
1102 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A16)
1104 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A24)
1106 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A32)
1108 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A64)
1110 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_CRCSR)
1111 *aspace |= VME_CRCSR;
1112 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER1)
1113 *aspace |= VME_USER1;
1114 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER2)
1115 *aspace |= VME_USER2;
1116 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER3)
1117 *aspace |= VME_USER3;
1118 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER4)
1119 *aspace |= VME_USER4;
1121 /* Setup 2eSST speeds */
1122 if ((ctl & TSI148_LCSR_OTAT_2eSSTM_M) == TSI148_LCSR_OTAT_2eSSTM_160)
1123 *cycle |= VME_2eSST160;
1124 if ((ctl & TSI148_LCSR_OTAT_2eSSTM_M) == TSI148_LCSR_OTAT_2eSSTM_267)
1125 *cycle |= VME_2eSST267;
1126 if ((ctl & TSI148_LCSR_OTAT_2eSSTM_M) == TSI148_LCSR_OTAT_2eSSTM_320)
1127 *cycle |= VME_2eSST320;
1129 /* Setup cycle types */
1130 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_SCT)
1132 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_BLT)
1134 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_MBLT)
1136 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_2eVME)
1137 *cycle |= VME_2eVME;
1138 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_2eSST)
1139 *cycle |= VME_2eSST;
1140 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_2eSSTB)
1141 *cycle |= VME_2eSSTB;
1143 if (ctl & TSI148_LCSR_OTAT_SUP)
1144 *cycle |= VME_SUPER;
1148 if (ctl & TSI148_LCSR_OTAT_PGM)
1153 /* Setup data width */
1154 if ((ctl & TSI148_LCSR_OTAT_DBW_M) == TSI148_LCSR_OTAT_DBW_16)
1156 if ((ctl & TSI148_LCSR_OTAT_DBW_M) == TSI148_LCSR_OTAT_DBW_32)
1163 static int tsi148_master_get(struct vme_master_resource *image, int *enabled,
1164 unsigned long long *vme_base, unsigned long long *size, u32 *aspace,
1165 u32 *cycle, u32 *dwidth)
1169 spin_lock(&image->lock);
1171 retval = __tsi148_master_get(image, enabled, vme_base, size, aspace,
1174 spin_unlock(&image->lock);
1179 static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf,
1180 size_t count, loff_t offset)
1182 int retval, enabled;
1183 unsigned long long vme_base, size;
1184 u32 aspace, cycle, dwidth;
1185 struct vme_error_handler *handler = NULL;
1186 struct vme_bridge *tsi148_bridge;
1187 void __iomem *addr = image->kern_base + offset;
1188 unsigned int done = 0;
1189 unsigned int count32;
1191 tsi148_bridge = image->parent;
1193 spin_lock(&image->lock);
1196 __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace,
1198 handler = vme_register_error_handler(tsi148_bridge, aspace,
1199 vme_base + offset, count);
1201 spin_unlock(&image->lock);
1206 /* The following code handles VME address alignment. We cannot use
1207 * memcpy_xxx here because it may cut data transfers in to 8-bit
1208 * cycles when D16 or D32 cycles are required on the VME bus.
1209 * On the other hand, the bridge itself assures that the maximum data
1210 * cycle configured for the transfer is used and splits it
1211 * automatically for non-aligned addresses, so we don't want the
1212 * overhead of needlessly forcing small transfers for the entire cycle.
1214 if ((uintptr_t)addr & 0x1) {
1215 *(u8 *)buf = ioread8(addr);
1220 if ((uintptr_t)(addr + done) & 0x2) {
1221 if ((count - done) < 2) {
1222 *(u8 *)(buf + done) = ioread8(addr + done);
1226 *(u16 *)(buf + done) = ioread16(addr + done);
1231 count32 = (count - done) & ~0x3;
1232 while (done < count32) {
1233 *(u32 *)(buf + done) = ioread32(addr + done);
1237 if ((count - done) & 0x2) {
1238 *(u16 *)(buf + done) = ioread16(addr + done);
1241 if ((count - done) & 0x1) {
1242 *(u8 *)(buf + done) = ioread8(addr + done);
1250 if (handler->num_errors) {
1251 dev_err(image->parent->parent,
1252 "First VME read error detected an at address 0x%llx\n",
1253 handler->first_error);
1254 retval = handler->first_error - (vme_base + offset);
1256 vme_unregister_error_handler(handler);
1259 spin_unlock(&image->lock);
1265 static ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf,
1266 size_t count, loff_t offset)
1268 int retval = 0, enabled;
1269 unsigned long long vme_base, size;
1270 u32 aspace, cycle, dwidth;
1271 void __iomem *addr = image->kern_base + offset;
1272 unsigned int done = 0;
1273 unsigned int count32;
1275 struct vme_error_handler *handler = NULL;
1276 struct vme_bridge *tsi148_bridge;
1277 struct tsi148_driver *bridge;
1279 tsi148_bridge = image->parent;
1281 bridge = tsi148_bridge->driver_priv;
1283 spin_lock(&image->lock);
1286 __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace,
1288 handler = vme_register_error_handler(tsi148_bridge, aspace,
1289 vme_base + offset, count);
1291 spin_unlock(&image->lock);
1296 /* Here we apply for the same strategy we do in master_read
1297 * function in order to assure the correct cycles.
1299 if ((uintptr_t)addr & 0x1) {
1300 iowrite8(*(u8 *)buf, addr);
1305 if ((uintptr_t)(addr + done) & 0x2) {
1306 if ((count - done) < 2) {
1307 iowrite8(*(u8 *)(buf + done), addr + done);
1311 iowrite16(*(u16 *)(buf + done), addr + done);
1316 count32 = (count - done) & ~0x3;
1317 while (done < count32) {
1318 iowrite32(*(u32 *)(buf + done), addr + done);
1322 if ((count - done) & 0x2) {
1323 iowrite16(*(u16 *)(buf + done), addr + done);
1326 if ((count - done) & 0x1) {
1327 iowrite8(*(u8 *)(buf + done), addr + done);
1335 * Writes are posted. We need to do a read on the VME bus to flush out
1336 * all of the writes before we check for errors. We can't guarantee
1337 * that reading the data we have just written is safe. It is believed
1338 * that there isn't any read, write re-ordering, so we can read any
1339 * location in VME space, so lets read the Device ID from the tsi148's
1340 * own registers as mapped into CR/CSR space.
1342 * We check for saved errors in the written address range/space.
1346 ioread16(bridge->flush_image->kern_base + 0x7F000);
1348 if (handler->num_errors) {
1349 dev_warn(tsi148_bridge->parent,
1350 "First VME write error detected an at address 0x%llx\n",
1351 handler->first_error);
1352 retval = handler->first_error - (vme_base + offset);
1354 vme_unregister_error_handler(handler);
1357 spin_unlock(&image->lock);
1363 * Perform an RMW cycle on the VME bus.
1365 * Requires a previously configured master window, returns final value.
1367 static unsigned int tsi148_master_rmw(struct vme_master_resource *image,
1368 unsigned int mask, unsigned int compare, unsigned int swap,
1371 unsigned long long pci_addr;
1372 unsigned int pci_addr_high, pci_addr_low;
1375 struct tsi148_driver *bridge;
1377 bridge = image->parent->driver_priv;
1379 /* Find the PCI address that maps to the desired VME address */
1382 /* Locking as we can only do one of these at a time */
1383 mutex_lock(&bridge->vme_rmw);
1386 spin_lock(&image->lock);
1388 pci_addr_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1389 TSI148_LCSR_OFFSET_OTSAU);
1390 pci_addr_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1391 TSI148_LCSR_OFFSET_OTSAL);
1393 reg_join(pci_addr_high, pci_addr_low, &pci_addr);
1394 reg_split(pci_addr + offset, &pci_addr_high, &pci_addr_low);
1396 /* Configure registers */
1397 iowrite32be(mask, bridge->base + TSI148_LCSR_RMWEN);
1398 iowrite32be(compare, bridge->base + TSI148_LCSR_RMWC);
1399 iowrite32be(swap, bridge->base + TSI148_LCSR_RMWS);
1400 iowrite32be(pci_addr_high, bridge->base + TSI148_LCSR_RMWAU);
1401 iowrite32be(pci_addr_low, bridge->base + TSI148_LCSR_RMWAL);
1404 tmp = ioread32be(bridge->base + TSI148_LCSR_VMCTRL);
1405 tmp |= TSI148_LCSR_VMCTRL_RMWEN;
1406 iowrite32be(tmp, bridge->base + TSI148_LCSR_VMCTRL);
1408 /* Kick process off with a read to the required address. */
1409 result = ioread32be(image->kern_base + offset);
1412 tmp = ioread32be(bridge->base + TSI148_LCSR_VMCTRL);
1413 tmp &= ~TSI148_LCSR_VMCTRL_RMWEN;
1414 iowrite32be(tmp, bridge->base + TSI148_LCSR_VMCTRL);
1416 spin_unlock(&image->lock);
1418 mutex_unlock(&bridge->vme_rmw);
1423 static int tsi148_dma_set_vme_src_attributes(struct device *dev, __be32 *attr,
1424 u32 aspace, u32 cycle, u32 dwidth)
1428 val = be32_to_cpu(*attr);
1430 /* Setup 2eSST speeds */
1431 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
1433 val |= TSI148_LCSR_DSAT_2eSSTM_160;
1436 val |= TSI148_LCSR_DSAT_2eSSTM_267;
1439 val |= TSI148_LCSR_DSAT_2eSSTM_320;
1443 /* Setup cycle types */
1444 if (cycle & VME_SCT)
1445 val |= TSI148_LCSR_DSAT_TM_SCT;
1447 if (cycle & VME_BLT)
1448 val |= TSI148_LCSR_DSAT_TM_BLT;
1450 if (cycle & VME_MBLT)
1451 val |= TSI148_LCSR_DSAT_TM_MBLT;
1453 if (cycle & VME_2eVME)
1454 val |= TSI148_LCSR_DSAT_TM_2eVME;
1456 if (cycle & VME_2eSST)
1457 val |= TSI148_LCSR_DSAT_TM_2eSST;
1459 if (cycle & VME_2eSSTB) {
1460 dev_err(dev, "Currently not setting Broadcast Select "
1462 val |= TSI148_LCSR_DSAT_TM_2eSSTB;
1465 /* Setup data width */
1468 val |= TSI148_LCSR_DSAT_DBW_16;
1471 val |= TSI148_LCSR_DSAT_DBW_32;
1474 dev_err(dev, "Invalid data width\n");
1478 /* Setup address space */
1481 val |= TSI148_LCSR_DSAT_AMODE_A16;
1484 val |= TSI148_LCSR_DSAT_AMODE_A24;
1487 val |= TSI148_LCSR_DSAT_AMODE_A32;
1490 val |= TSI148_LCSR_DSAT_AMODE_A64;
1493 val |= TSI148_LCSR_DSAT_AMODE_CRCSR;
1496 val |= TSI148_LCSR_DSAT_AMODE_USER1;
1499 val |= TSI148_LCSR_DSAT_AMODE_USER2;
1502 val |= TSI148_LCSR_DSAT_AMODE_USER3;
1505 val |= TSI148_LCSR_DSAT_AMODE_USER4;
1508 dev_err(dev, "Invalid address space\n");
1513 if (cycle & VME_SUPER)
1514 val |= TSI148_LCSR_DSAT_SUP;
1515 if (cycle & VME_PROG)
1516 val |= TSI148_LCSR_DSAT_PGM;
1518 *attr = cpu_to_be32(val);
1523 static int tsi148_dma_set_vme_dest_attributes(struct device *dev, __be32 *attr,
1524 u32 aspace, u32 cycle, u32 dwidth)
1528 val = be32_to_cpu(*attr);
1530 /* Setup 2eSST speeds */
1531 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
1533 val |= TSI148_LCSR_DDAT_2eSSTM_160;
1536 val |= TSI148_LCSR_DDAT_2eSSTM_267;
1539 val |= TSI148_LCSR_DDAT_2eSSTM_320;
1543 /* Setup cycle types */
1544 if (cycle & VME_SCT)
1545 val |= TSI148_LCSR_DDAT_TM_SCT;
1547 if (cycle & VME_BLT)
1548 val |= TSI148_LCSR_DDAT_TM_BLT;
1550 if (cycle & VME_MBLT)
1551 val |= TSI148_LCSR_DDAT_TM_MBLT;
1553 if (cycle & VME_2eVME)
1554 val |= TSI148_LCSR_DDAT_TM_2eVME;
1556 if (cycle & VME_2eSST)
1557 val |= TSI148_LCSR_DDAT_TM_2eSST;
1559 if (cycle & VME_2eSSTB) {
1560 dev_err(dev, "Currently not setting Broadcast Select "
1562 val |= TSI148_LCSR_DDAT_TM_2eSSTB;
1565 /* Setup data width */
1568 val |= TSI148_LCSR_DDAT_DBW_16;
1571 val |= TSI148_LCSR_DDAT_DBW_32;
1574 dev_err(dev, "Invalid data width\n");
1578 /* Setup address space */
1581 val |= TSI148_LCSR_DDAT_AMODE_A16;
1584 val |= TSI148_LCSR_DDAT_AMODE_A24;
1587 val |= TSI148_LCSR_DDAT_AMODE_A32;
1590 val |= TSI148_LCSR_DDAT_AMODE_A64;
1593 val |= TSI148_LCSR_DDAT_AMODE_CRCSR;
1596 val |= TSI148_LCSR_DDAT_AMODE_USER1;
1599 val |= TSI148_LCSR_DDAT_AMODE_USER2;
1602 val |= TSI148_LCSR_DDAT_AMODE_USER3;
1605 val |= TSI148_LCSR_DDAT_AMODE_USER4;
1608 dev_err(dev, "Invalid address space\n");
1613 if (cycle & VME_SUPER)
1614 val |= TSI148_LCSR_DDAT_SUP;
1615 if (cycle & VME_PROG)
1616 val |= TSI148_LCSR_DDAT_PGM;
1618 *attr = cpu_to_be32(val);
1624 * Add a link list descriptor to the list
1626 * Note: DMA engine expects the DMA descriptor to be big endian.
1628 static int tsi148_dma_list_add(struct vme_dma_list *list,
1629 struct vme_dma_attr *src, struct vme_dma_attr *dest, size_t count)
1631 struct tsi148_dma_entry *entry, *prev;
1632 u32 address_high, address_low, val;
1633 struct vme_dma_pattern *pattern_attr;
1634 struct vme_dma_pci *pci_attr;
1635 struct vme_dma_vme *vme_attr;
1637 struct vme_bridge *tsi148_bridge;
1639 tsi148_bridge = list->parent->parent;
1641 /* Descriptor must be aligned on 64-bit boundaries */
1642 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1648 /* Test descriptor alignment */
1649 if ((unsigned long)&entry->descriptor & 0x7) {
1650 dev_err(tsi148_bridge->parent, "Descriptor not aligned to 8 "
1651 "byte boundary as required: %p\n",
1652 &entry->descriptor);
1657 /* Given we are going to fill out the structure, we probably don't
1658 * need to zero it, but better safe than sorry for now.
1660 memset(&entry->descriptor, 0, sizeof(entry->descriptor));
1662 /* Fill out source part */
1663 switch (src->type) {
1664 case VME_DMA_PATTERN:
1665 pattern_attr = src->private;
1667 entry->descriptor.dsal = cpu_to_be32(pattern_attr->pattern);
1669 val = TSI148_LCSR_DSAT_TYP_PAT;
1671 /* Default behaviour is 32 bit pattern */
1672 if (pattern_attr->type & VME_DMA_PATTERN_BYTE)
1673 val |= TSI148_LCSR_DSAT_PSZ;
1675 /* It seems that the default behaviour is to increment */
1676 if ((pattern_attr->type & VME_DMA_PATTERN_INCREMENT) == 0)
1677 val |= TSI148_LCSR_DSAT_NIN;
1678 entry->descriptor.dsat = cpu_to_be32(val);
1681 pci_attr = src->private;
1683 reg_split((unsigned long long)pci_attr->address, &address_high,
1685 entry->descriptor.dsau = cpu_to_be32(address_high);
1686 entry->descriptor.dsal = cpu_to_be32(address_low);
1687 entry->descriptor.dsat = cpu_to_be32(TSI148_LCSR_DSAT_TYP_PCI);
1690 vme_attr = src->private;
1692 reg_split((unsigned long long)vme_attr->address, &address_high,
1694 entry->descriptor.dsau = cpu_to_be32(address_high);
1695 entry->descriptor.dsal = cpu_to_be32(address_low);
1696 entry->descriptor.dsat = cpu_to_be32(TSI148_LCSR_DSAT_TYP_VME);
1698 retval = tsi148_dma_set_vme_src_attributes(
1699 tsi148_bridge->parent, &entry->descriptor.dsat,
1700 vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth);
1705 dev_err(tsi148_bridge->parent, "Invalid source type\n");
1711 /* Assume last link - this will be over-written by adding another */
1712 entry->descriptor.dnlau = cpu_to_be32(0);
1713 entry->descriptor.dnlal = cpu_to_be32(TSI148_LCSR_DNLAL_LLA);
1715 /* Fill out destination part */
1716 switch (dest->type) {
1718 pci_attr = dest->private;
1720 reg_split((unsigned long long)pci_attr->address, &address_high,
1722 entry->descriptor.ddau = cpu_to_be32(address_high);
1723 entry->descriptor.ddal = cpu_to_be32(address_low);
1724 entry->descriptor.ddat = cpu_to_be32(TSI148_LCSR_DDAT_TYP_PCI);
1727 vme_attr = dest->private;
1729 reg_split((unsigned long long)vme_attr->address, &address_high,
1731 entry->descriptor.ddau = cpu_to_be32(address_high);
1732 entry->descriptor.ddal = cpu_to_be32(address_low);
1733 entry->descriptor.ddat = cpu_to_be32(TSI148_LCSR_DDAT_TYP_VME);
1735 retval = tsi148_dma_set_vme_dest_attributes(
1736 tsi148_bridge->parent, &entry->descriptor.ddat,
1737 vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth);
1742 dev_err(tsi148_bridge->parent, "Invalid destination type\n");
1748 /* Fill out count */
1749 entry->descriptor.dcnt = cpu_to_be32((u32)count);
1752 list_add_tail(&entry->list, &list->entries);
1754 entry->dma_handle = dma_map_single(tsi148_bridge->parent,
1756 sizeof(entry->descriptor),
1758 if (dma_mapping_error(tsi148_bridge->parent, entry->dma_handle)) {
1759 dev_err(tsi148_bridge->parent, "DMA mapping error\n");
1764 /* Fill out previous descriptors "Next Address" */
1765 if (entry->list.prev != &list->entries) {
1766 reg_split((unsigned long long)entry->dma_handle, &address_high,
1768 prev = list_entry(entry->list.prev, struct tsi148_dma_entry,
1770 prev->descriptor.dnlau = cpu_to_be32(address_high);
1771 prev->descriptor.dnlal = cpu_to_be32(address_low);
1787 * Check to see if the provided DMA channel is busy.
1789 static int tsi148_dma_busy(struct vme_bridge *tsi148_bridge, int channel)
1792 struct tsi148_driver *bridge;
1794 bridge = tsi148_bridge->driver_priv;
1796 tmp = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] +
1797 TSI148_LCSR_OFFSET_DSTA);
1799 if (tmp & TSI148_LCSR_DSTA_BSY)
1807 * Execute a previously generated link list
1809 * XXX Need to provide control register configuration.
1811 static int tsi148_dma_list_exec(struct vme_dma_list *list)
1813 struct vme_dma_resource *ctrlr;
1814 int channel, retval;
1815 struct tsi148_dma_entry *entry;
1816 u32 bus_addr_high, bus_addr_low;
1817 u32 val, dctlreg = 0;
1818 struct vme_bridge *tsi148_bridge;
1819 struct tsi148_driver *bridge;
1821 ctrlr = list->parent;
1823 tsi148_bridge = ctrlr->parent;
1825 bridge = tsi148_bridge->driver_priv;
1827 mutex_lock(&ctrlr->mtx);
1829 channel = ctrlr->number;
1831 if (!list_empty(&ctrlr->running)) {
1833 * XXX We have an active DMA transfer and currently haven't
1834 * sorted out the mechanism for "pending" DMA transfers.
1837 /* Need to add to pending here */
1838 mutex_unlock(&ctrlr->mtx);
1841 list_add(&list->list, &ctrlr->running);
1844 /* Get first bus address and write into registers */
1845 entry = list_first_entry(&list->entries, struct tsi148_dma_entry,
1848 mutex_unlock(&ctrlr->mtx);
1850 reg_split(entry->dma_handle, &bus_addr_high, &bus_addr_low);
1852 iowrite32be(bus_addr_high, bridge->base +
1853 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAU);
1854 iowrite32be(bus_addr_low, bridge->base +
1855 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAL);
1857 dctlreg = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] +
1858 TSI148_LCSR_OFFSET_DCTL);
1860 /* Start the operation */
1861 iowrite32be(dctlreg | TSI148_LCSR_DCTL_DGO, bridge->base +
1862 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DCTL);
1864 retval = wait_event_interruptible(bridge->dma_queue[channel],
1865 tsi148_dma_busy(ctrlr->parent, channel));
1868 iowrite32be(dctlreg | TSI148_LCSR_DCTL_ABT, bridge->base +
1869 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DCTL);
1870 /* Wait for the operation to abort */
1871 wait_event(bridge->dma_queue[channel],
1872 tsi148_dma_busy(ctrlr->parent, channel));
1878 * Read status register, this register is valid until we kick off a
1881 val = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] +
1882 TSI148_LCSR_OFFSET_DSTA);
1884 if (val & TSI148_LCSR_DSTA_VBE) {
1885 dev_err(tsi148_bridge->parent, "DMA Error. DSTA=%08X\n", val);
1890 /* Remove list from running list */
1891 mutex_lock(&ctrlr->mtx);
1892 list_del(&list->list);
1893 mutex_unlock(&ctrlr->mtx);
1899 * Clean up a previously generated link list
1901 * We have a separate function, don't assume that the chain can't be reused.
1903 static int tsi148_dma_list_empty(struct vme_dma_list *list)
1905 struct list_head *pos, *temp;
1906 struct tsi148_dma_entry *entry;
1908 struct vme_bridge *tsi148_bridge = list->parent->parent;
1910 /* detach and free each entry */
1911 list_for_each_safe(pos, temp, &list->entries) {
1913 entry = list_entry(pos, struct tsi148_dma_entry, list);
1915 dma_unmap_single(tsi148_bridge->parent, entry->dma_handle,
1916 sizeof(struct tsi148_dma_descriptor), DMA_TO_DEVICE);
1924 * All 4 location monitors reside at the same base - this is therefore a
1925 * system wide configuration.
1927 * This does not enable the LM monitor - that should be done when the first
1928 * callback is attached and disabled when the last callback is removed.
1930 static int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1931 u32 aspace, u32 cycle)
1933 u32 lm_base_high, lm_base_low, lm_ctl = 0;
1935 struct vme_bridge *tsi148_bridge;
1936 struct tsi148_driver *bridge;
1938 tsi148_bridge = lm->parent;
1940 bridge = tsi148_bridge->driver_priv;
1942 mutex_lock(&lm->mtx);
1944 /* If we already have a callback attached, we can't move it! */
1945 for (i = 0; i < lm->monitors; i++) {
1946 if (bridge->lm_callback[i]) {
1947 mutex_unlock(&lm->mtx);
1948 dev_err(tsi148_bridge->parent, "Location monitor "
1949 "callback attached, can't reset\n");
1956 lm_ctl |= TSI148_LCSR_LMAT_AS_A16;
1959 lm_ctl |= TSI148_LCSR_LMAT_AS_A24;
1962 lm_ctl |= TSI148_LCSR_LMAT_AS_A32;
1965 lm_ctl |= TSI148_LCSR_LMAT_AS_A64;
1968 mutex_unlock(&lm->mtx);
1969 dev_err(tsi148_bridge->parent, "Invalid address space\n");
1974 if (cycle & VME_SUPER)
1975 lm_ctl |= TSI148_LCSR_LMAT_SUPR ;
1976 if (cycle & VME_USER)
1977 lm_ctl |= TSI148_LCSR_LMAT_NPRIV;
1978 if (cycle & VME_PROG)
1979 lm_ctl |= TSI148_LCSR_LMAT_PGM;
1980 if (cycle & VME_DATA)
1981 lm_ctl |= TSI148_LCSR_LMAT_DATA;
1983 reg_split(lm_base, &lm_base_high, &lm_base_low);
1985 iowrite32be(lm_base_high, bridge->base + TSI148_LCSR_LMBAU);
1986 iowrite32be(lm_base_low, bridge->base + TSI148_LCSR_LMBAL);
1987 iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT);
1989 mutex_unlock(&lm->mtx);
1994 /* Get configuration of the callback monitor and return whether it is enabled
1997 static int tsi148_lm_get(struct vme_lm_resource *lm,
1998 unsigned long long *lm_base, u32 *aspace, u32 *cycle)
2000 u32 lm_base_high, lm_base_low, lm_ctl, enabled = 0;
2001 struct tsi148_driver *bridge;
2003 bridge = lm->parent->driver_priv;
2005 mutex_lock(&lm->mtx);
2007 lm_base_high = ioread32be(bridge->base + TSI148_LCSR_LMBAU);
2008 lm_base_low = ioread32be(bridge->base + TSI148_LCSR_LMBAL);
2009 lm_ctl = ioread32be(bridge->base + TSI148_LCSR_LMAT);
2011 reg_join(lm_base_high, lm_base_low, lm_base);
2013 if (lm_ctl & TSI148_LCSR_LMAT_EN)
2016 if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A16)
2019 if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A24)
2022 if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A32)
2025 if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A64)
2029 if (lm_ctl & TSI148_LCSR_LMAT_SUPR)
2030 *cycle |= VME_SUPER;
2031 if (lm_ctl & TSI148_LCSR_LMAT_NPRIV)
2033 if (lm_ctl & TSI148_LCSR_LMAT_PGM)
2035 if (lm_ctl & TSI148_LCSR_LMAT_DATA)
2038 mutex_unlock(&lm->mtx);
2044 * Attach a callback to a specific location monitor.
2046 * Callback will be passed the monitor triggered.
2048 static int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor,
2049 void (*callback)(void *), void *data)
2052 struct vme_bridge *tsi148_bridge;
2053 struct tsi148_driver *bridge;
2055 tsi148_bridge = lm->parent;
2057 bridge = tsi148_bridge->driver_priv;
2059 mutex_lock(&lm->mtx);
2061 /* Ensure that the location monitor is configured - need PGM or DATA */
2062 lm_ctl = ioread32be(bridge->base + TSI148_LCSR_LMAT);
2063 if ((lm_ctl & (TSI148_LCSR_LMAT_PGM | TSI148_LCSR_LMAT_DATA)) == 0) {
2064 mutex_unlock(&lm->mtx);
2065 dev_err(tsi148_bridge->parent, "Location monitor not properly "
2070 /* Check that a callback isn't already attached */
2071 if (bridge->lm_callback[monitor]) {
2072 mutex_unlock(&lm->mtx);
2073 dev_err(tsi148_bridge->parent, "Existing callback attached\n");
2077 /* Attach callback */
2078 bridge->lm_callback[monitor] = callback;
2079 bridge->lm_data[monitor] = data;
2081 /* Enable Location Monitor interrupt */
2082 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEN);
2083 tmp |= TSI148_LCSR_INTEN_LMEN[monitor];
2084 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN);
2086 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO);
2087 tmp |= TSI148_LCSR_INTEO_LMEO[monitor];
2088 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
2090 /* Ensure that global Location Monitor Enable set */
2091 if ((lm_ctl & TSI148_LCSR_LMAT_EN) == 0) {
2092 lm_ctl |= TSI148_LCSR_LMAT_EN;
2093 iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT);
2096 mutex_unlock(&lm->mtx);
2102 * Detach a callback function forn a specific location monitor.
2104 static int tsi148_lm_detach(struct vme_lm_resource *lm, int monitor)
2107 struct tsi148_driver *bridge;
2109 bridge = lm->parent->driver_priv;
2111 mutex_lock(&lm->mtx);
2113 /* Disable Location Monitor and ensure previous interrupts are clear */
2114 lm_en = ioread32be(bridge->base + TSI148_LCSR_INTEN);
2115 lm_en &= ~TSI148_LCSR_INTEN_LMEN[monitor];
2116 iowrite32be(lm_en, bridge->base + TSI148_LCSR_INTEN);
2118 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO);
2119 tmp &= ~TSI148_LCSR_INTEO_LMEO[monitor];
2120 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
2122 iowrite32be(TSI148_LCSR_INTC_LMC[monitor],
2123 bridge->base + TSI148_LCSR_INTC);
2125 /* Detach callback */
2126 bridge->lm_callback[monitor] = NULL;
2127 bridge->lm_data[monitor] = NULL;
2129 /* If all location monitors disabled, disable global Location Monitor */
2130 if ((lm_en & (TSI148_LCSR_INTS_LM0S | TSI148_LCSR_INTS_LM1S |
2131 TSI148_LCSR_INTS_LM2S | TSI148_LCSR_INTS_LM3S)) == 0) {
2132 tmp = ioread32be(bridge->base + TSI148_LCSR_LMAT);
2133 tmp &= ~TSI148_LCSR_LMAT_EN;
2134 iowrite32be(tmp, bridge->base + TSI148_LCSR_LMAT);
2137 mutex_unlock(&lm->mtx);
2143 * Determine Geographical Addressing
2145 static int tsi148_slot_get(struct vme_bridge *tsi148_bridge)
2148 struct tsi148_driver *bridge;
2150 bridge = tsi148_bridge->driver_priv;
2153 slot = ioread32be(bridge->base + TSI148_LCSR_VSTAT);
2154 slot = slot & TSI148_LCSR_VSTAT_GA_M;
2161 static void *tsi148_alloc_consistent(struct device *parent, size_t size,
2164 struct pci_dev *pdev;
2166 /* Find pci_dev container of dev */
2167 pdev = to_pci_dev(parent);
2169 return pci_alloc_consistent(pdev, size, dma);
2172 static void tsi148_free_consistent(struct device *parent, size_t size,
2173 void *vaddr, dma_addr_t dma)
2175 struct pci_dev *pdev;
2177 /* Find pci_dev container of dev */
2178 pdev = to_pci_dev(parent);
2180 pci_free_consistent(pdev, size, vaddr, dma);
2184 * Configure CR/CSR space
2186 * Access to the CR/CSR can be configured at power-up. The location of the
2187 * CR/CSR registers in the CR/CSR address space is determined by the boards
2188 * Auto-ID or Geographic address. This function ensures that the window is
2189 * enabled at an offset consistent with the boards geopgraphic address.
2191 * Each board has a 512kB window, with the highest 4kB being used for the
2192 * boards registers, this means there is a fix length 508kB window which must
2193 * be mapped onto PCI memory.
2195 static int tsi148_crcsr_init(struct vme_bridge *tsi148_bridge,
2196 struct pci_dev *pdev)
2198 u32 cbar, crat, vstat;
2199 u32 crcsr_bus_high, crcsr_bus_low;
2201 struct tsi148_driver *bridge;
2203 bridge = tsi148_bridge->driver_priv;
2205 /* Allocate mem for CR/CSR image */
2206 bridge->crcsr_kernel = pci_zalloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
2207 &bridge->crcsr_bus);
2208 if (!bridge->crcsr_kernel) {
2209 dev_err(tsi148_bridge->parent, "Failed to allocate memory for "
2214 reg_split(bridge->crcsr_bus, &crcsr_bus_high, &crcsr_bus_low);
2216 iowrite32be(crcsr_bus_high, bridge->base + TSI148_LCSR_CROU);
2217 iowrite32be(crcsr_bus_low, bridge->base + TSI148_LCSR_CROL);
2219 /* Ensure that the CR/CSR is configured at the correct offset */
2220 cbar = ioread32be(bridge->base + TSI148_CBAR);
2221 cbar = (cbar & TSI148_CRCSR_CBAR_M)>>3;
2223 vstat = tsi148_slot_get(tsi148_bridge);
2225 if (cbar != vstat) {
2227 dev_info(tsi148_bridge->parent, "Setting CR/CSR offset\n");
2228 iowrite32be(cbar<<3, bridge->base + TSI148_CBAR);
2230 dev_info(tsi148_bridge->parent, "CR/CSR Offset: %d\n", cbar);
2232 crat = ioread32be(bridge->base + TSI148_LCSR_CRAT);
2233 if (crat & TSI148_LCSR_CRAT_EN)
2234 dev_info(tsi148_bridge->parent, "CR/CSR already enabled\n");
2236 dev_info(tsi148_bridge->parent, "Enabling CR/CSR space\n");
2237 iowrite32be(crat | TSI148_LCSR_CRAT_EN,
2238 bridge->base + TSI148_LCSR_CRAT);
2241 /* If we want flushed, error-checked writes, set up a window
2242 * over the CR/CSR registers. We read from here to safely flush
2243 * through VME writes.
2246 retval = tsi148_master_set(bridge->flush_image, 1,
2247 (vstat * 0x80000), 0x80000, VME_CRCSR, VME_SCT,
2250 dev_err(tsi148_bridge->parent, "Configuring flush image"
2258 static void tsi148_crcsr_exit(struct vme_bridge *tsi148_bridge,
2259 struct pci_dev *pdev)
2262 struct tsi148_driver *bridge;
2264 bridge = tsi148_bridge->driver_priv;
2266 /* Turn off CR/CSR space */
2267 crat = ioread32be(bridge->base + TSI148_LCSR_CRAT);
2268 iowrite32be(crat & ~TSI148_LCSR_CRAT_EN,
2269 bridge->base + TSI148_LCSR_CRAT);
2272 iowrite32be(0, bridge->base + TSI148_LCSR_CROU);
2273 iowrite32be(0, bridge->base + TSI148_LCSR_CROL);
2275 pci_free_consistent(pdev, VME_CRCSR_BUF_SIZE, bridge->crcsr_kernel,
2279 static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2281 int retval, i, master_num;
2283 struct list_head *pos = NULL, *n;
2284 struct vme_bridge *tsi148_bridge;
2285 struct tsi148_driver *tsi148_device;
2286 struct vme_master_resource *master_image;
2287 struct vme_slave_resource *slave_image;
2288 struct vme_dma_resource *dma_ctrlr;
2289 struct vme_lm_resource *lm;
2291 /* If we want to support more than one of each bridge, we need to
2292 * dynamically generate this so we get one per device
2294 tsi148_bridge = kzalloc(sizeof(*tsi148_bridge), GFP_KERNEL);
2295 if (!tsi148_bridge) {
2299 vme_init_bridge(tsi148_bridge);
2301 tsi148_device = kzalloc(sizeof(*tsi148_device), GFP_KERNEL);
2302 if (!tsi148_device) {
2307 tsi148_bridge->driver_priv = tsi148_device;
2309 /* Enable the device */
2310 retval = pci_enable_device(pdev);
2312 dev_err(&pdev->dev, "Unable to enable device\n");
2317 retval = pci_request_regions(pdev, driver_name);
2319 dev_err(&pdev->dev, "Unable to reserve resources\n");
2323 /* map registers in BAR 0 */
2324 tsi148_device->base = ioremap_nocache(pci_resource_start(pdev, 0),
2326 if (!tsi148_device->base) {
2327 dev_err(&pdev->dev, "Unable to remap CRG region\n");
2332 /* Check to see if the mapping worked out */
2333 data = ioread32(tsi148_device->base + TSI148_PCFS_ID) & 0x0000FFFF;
2334 if (data != PCI_VENDOR_ID_TUNDRA) {
2335 dev_err(&pdev->dev, "CRG region check failed\n");
2340 /* Initialize wait queues & mutual exclusion flags */
2341 init_waitqueue_head(&tsi148_device->dma_queue[0]);
2342 init_waitqueue_head(&tsi148_device->dma_queue[1]);
2343 init_waitqueue_head(&tsi148_device->iack_queue);
2344 mutex_init(&tsi148_device->vme_int);
2345 mutex_init(&tsi148_device->vme_rmw);
2347 tsi148_bridge->parent = &pdev->dev;
2348 strcpy(tsi148_bridge->name, driver_name);
2351 retval = tsi148_irq_init(tsi148_bridge);
2353 dev_err(&pdev->dev, "Chip Initialization failed.\n");
2357 /* If we are going to flush writes, we need to read from the VME bus.
2358 * We need to do this safely, thus we read the devices own CR/CSR
2359 * register. To do this we must set up a window in CR/CSR space and
2360 * hence have one less master window resource available.
2362 master_num = TSI148_MAX_MASTER;
2366 tsi148_device->flush_image =
2367 kmalloc(sizeof(*tsi148_device->flush_image),
2369 if (!tsi148_device->flush_image) {
2373 tsi148_device->flush_image->parent = tsi148_bridge;
2374 spin_lock_init(&tsi148_device->flush_image->lock);
2375 tsi148_device->flush_image->locked = 1;
2376 tsi148_device->flush_image->number = master_num;
2377 memset(&tsi148_device->flush_image->bus_resource, 0,
2378 sizeof(tsi148_device->flush_image->bus_resource));
2379 tsi148_device->flush_image->kern_base = NULL;
2382 /* Add master windows to list */
2383 for (i = 0; i < master_num; i++) {
2384 master_image = kmalloc(sizeof(*master_image), GFP_KERNEL);
2385 if (!master_image) {
2389 master_image->parent = tsi148_bridge;
2390 spin_lock_init(&master_image->lock);
2391 master_image->locked = 0;
2392 master_image->number = i;
2393 master_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
2394 VME_A64 | VME_CRCSR | VME_USER1 | VME_USER2 |
2395 VME_USER3 | VME_USER4;
2396 master_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
2397 VME_2eVME | VME_2eSST | VME_2eSSTB | VME_2eSST160 |
2398 VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER |
2399 VME_PROG | VME_DATA;
2400 master_image->width_attr = VME_D16 | VME_D32;
2401 memset(&master_image->bus_resource, 0,
2402 sizeof(master_image->bus_resource));
2403 master_image->kern_base = NULL;
2404 list_add_tail(&master_image->list,
2405 &tsi148_bridge->master_resources);
2408 /* Add slave windows to list */
2409 for (i = 0; i < TSI148_MAX_SLAVE; i++) {
2410 slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL);
2415 slave_image->parent = tsi148_bridge;
2416 mutex_init(&slave_image->mtx);
2417 slave_image->locked = 0;
2418 slave_image->number = i;
2419 slave_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
2421 slave_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
2422 VME_2eVME | VME_2eSST | VME_2eSSTB | VME_2eSST160 |
2423 VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER |
2424 VME_PROG | VME_DATA;
2425 list_add_tail(&slave_image->list,
2426 &tsi148_bridge->slave_resources);
2429 /* Add dma engines to list */
2430 for (i = 0; i < TSI148_MAX_DMA; i++) {
2431 dma_ctrlr = kmalloc(sizeof(*dma_ctrlr), GFP_KERNEL);
2436 dma_ctrlr->parent = tsi148_bridge;
2437 mutex_init(&dma_ctrlr->mtx);
2438 dma_ctrlr->locked = 0;
2439 dma_ctrlr->number = i;
2440 dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM |
2441 VME_DMA_MEM_TO_VME | VME_DMA_VME_TO_VME |
2442 VME_DMA_MEM_TO_MEM | VME_DMA_PATTERN_TO_VME |
2443 VME_DMA_PATTERN_TO_MEM;
2444 INIT_LIST_HEAD(&dma_ctrlr->pending);
2445 INIT_LIST_HEAD(&dma_ctrlr->running);
2446 list_add_tail(&dma_ctrlr->list,
2447 &tsi148_bridge->dma_resources);
2450 /* Add location monitor to list */
2451 lm = kmalloc(sizeof(*lm), GFP_KERNEL);
2456 lm->parent = tsi148_bridge;
2457 mutex_init(&lm->mtx);
2461 list_add_tail(&lm->list, &tsi148_bridge->lm_resources);
2463 tsi148_bridge->slave_get = tsi148_slave_get;
2464 tsi148_bridge->slave_set = tsi148_slave_set;
2465 tsi148_bridge->master_get = tsi148_master_get;
2466 tsi148_bridge->master_set = tsi148_master_set;
2467 tsi148_bridge->master_read = tsi148_master_read;
2468 tsi148_bridge->master_write = tsi148_master_write;
2469 tsi148_bridge->master_rmw = tsi148_master_rmw;
2470 tsi148_bridge->dma_list_add = tsi148_dma_list_add;
2471 tsi148_bridge->dma_list_exec = tsi148_dma_list_exec;
2472 tsi148_bridge->dma_list_empty = tsi148_dma_list_empty;
2473 tsi148_bridge->irq_set = tsi148_irq_set;
2474 tsi148_bridge->irq_generate = tsi148_irq_generate;
2475 tsi148_bridge->lm_set = tsi148_lm_set;
2476 tsi148_bridge->lm_get = tsi148_lm_get;
2477 tsi148_bridge->lm_attach = tsi148_lm_attach;
2478 tsi148_bridge->lm_detach = tsi148_lm_detach;
2479 tsi148_bridge->slot_get = tsi148_slot_get;
2480 tsi148_bridge->alloc_consistent = tsi148_alloc_consistent;
2481 tsi148_bridge->free_consistent = tsi148_free_consistent;
2483 data = ioread32be(tsi148_device->base + TSI148_LCSR_VSTAT);
2484 dev_info(&pdev->dev, "Board is%s the VME system controller\n",
2485 (data & TSI148_LCSR_VSTAT_SCONS) ? "" : " not");
2487 dev_info(&pdev->dev, "VME geographical address is %d\n",
2488 data & TSI148_LCSR_VSTAT_GA_M);
2490 dev_info(&pdev->dev, "VME geographical address is set to %d\n",
2493 dev_info(&pdev->dev, "VME Write and flush and error check is %s\n",
2494 err_chk ? "enabled" : "disabled");
2496 retval = tsi148_crcsr_init(tsi148_bridge, pdev);
2498 dev_err(&pdev->dev, "CR/CSR configuration failed.\n");
2502 retval = vme_register_bridge(tsi148_bridge);
2504 dev_err(&pdev->dev, "Chip Registration failed.\n");
2508 pci_set_drvdata(pdev, tsi148_bridge);
2510 /* Clear VME bus "board fail", and "power-up reset" lines */
2511 data = ioread32be(tsi148_device->base + TSI148_LCSR_VSTAT);
2512 data &= ~TSI148_LCSR_VSTAT_BRDFL;
2513 data |= TSI148_LCSR_VSTAT_CPURST;
2514 iowrite32be(data, tsi148_device->base + TSI148_LCSR_VSTAT);
2519 tsi148_crcsr_exit(tsi148_bridge, pdev);
2522 /* resources are stored in link list */
2523 list_for_each_safe(pos, n, &tsi148_bridge->lm_resources) {
2524 lm = list_entry(pos, struct vme_lm_resource, list);
2529 /* resources are stored in link list */
2530 list_for_each_safe(pos, n, &tsi148_bridge->dma_resources) {
2531 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
2536 /* resources are stored in link list */
2537 list_for_each_safe(pos, n, &tsi148_bridge->slave_resources) {
2538 slave_image = list_entry(pos, struct vme_slave_resource, list);
2543 /* resources are stored in link list */
2544 list_for_each_safe(pos, n, &tsi148_bridge->master_resources) {
2545 master_image = list_entry(pos, struct vme_master_resource,
2548 kfree(master_image);
2551 tsi148_irq_exit(tsi148_bridge, pdev);
2554 iounmap(tsi148_device->base);
2556 pci_release_regions(pdev);
2558 pci_disable_device(pdev);
2560 kfree(tsi148_device);
2562 kfree(tsi148_bridge);
2568 static void tsi148_remove(struct pci_dev *pdev)
2570 struct list_head *pos = NULL;
2571 struct list_head *tmplist;
2572 struct vme_master_resource *master_image;
2573 struct vme_slave_resource *slave_image;
2574 struct vme_dma_resource *dma_ctrlr;
2576 struct tsi148_driver *bridge;
2577 struct vme_bridge *tsi148_bridge = pci_get_drvdata(pdev);
2579 bridge = tsi148_bridge->driver_priv;
2582 dev_dbg(&pdev->dev, "Driver is being unloaded.\n");
2585 * Shutdown all inbound and outbound windows.
2587 for (i = 0; i < 8; i++) {
2588 iowrite32be(0, bridge->base + TSI148_LCSR_IT[i] +
2589 TSI148_LCSR_OFFSET_ITAT);
2590 iowrite32be(0, bridge->base + TSI148_LCSR_OT[i] +
2591 TSI148_LCSR_OFFSET_OTAT);
2595 * Shutdown Location monitor.
2597 iowrite32be(0, bridge->base + TSI148_LCSR_LMAT);
2602 iowrite32be(0, bridge->base + TSI148_LCSR_CSRAT);
2605 * Clear error status.
2607 iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_EDPAT);
2608 iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_VEAT);
2609 iowrite32be(0x07000700, bridge->base + TSI148_LCSR_PSTAT);
2612 * Remove VIRQ interrupt (if any)
2614 if (ioread32be(bridge->base + TSI148_LCSR_VICR) & 0x800)
2615 iowrite32be(0x8000, bridge->base + TSI148_LCSR_VICR);
2618 * Map all Interrupts to PCI INTA
2620 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM1);
2621 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM2);
2623 tsi148_irq_exit(tsi148_bridge, pdev);
2625 vme_unregister_bridge(tsi148_bridge);
2627 tsi148_crcsr_exit(tsi148_bridge, pdev);
2629 /* resources are stored in link list */
2630 list_for_each_safe(pos, tmplist, &tsi148_bridge->dma_resources) {
2631 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
2636 /* resources are stored in link list */
2637 list_for_each_safe(pos, tmplist, &tsi148_bridge->slave_resources) {
2638 slave_image = list_entry(pos, struct vme_slave_resource, list);
2643 /* resources are stored in link list */
2644 list_for_each_safe(pos, tmplist, &tsi148_bridge->master_resources) {
2645 master_image = list_entry(pos, struct vme_master_resource,
2648 kfree(master_image);
2651 iounmap(bridge->base);
2653 pci_release_regions(pdev);
2655 pci_disable_device(pdev);
2657 kfree(tsi148_bridge->driver_priv);
2659 kfree(tsi148_bridge);
2662 module_pci_driver(tsi148_driver);
2664 MODULE_PARM_DESC(err_chk, "Check for VME errors on reads and writes");
2665 module_param(err_chk, bool, 0);
2667 MODULE_PARM_DESC(geoid, "Override geographical addressing");
2668 module_param(geoid, int, 0);
2670 MODULE_DESCRIPTION("VME driver for the Tundra Tempe VME bridge");
2671 MODULE_LICENSE("GPL");