1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Support for the Tundra TSI148 VME-PCI Bridge Chip
5 * Author: Martyn Welch <martyn.welch@ge.com>
6 * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
8 * Based on work by Tom Armistead and Ajit Prem
9 * Copyright 2004 Motorola Inc.
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
15 #include <linux/types.h>
16 #include <linux/errno.h>
17 #include <linux/proc_fs.h>
18 #include <linux/pci.h>
19 #include <linux/poll.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/interrupt.h>
22 #include <linux/spinlock.h>
23 #include <linux/sched.h>
24 #include <linux/slab.h>
25 #include <linux/time.h>
27 #include <linux/uaccess.h>
28 #include <linux/byteorder/generic.h>
31 #include "vme_bridge.h"
32 #include "vme_tsi148.h"
34 static int tsi148_probe(struct pci_dev *, const struct pci_device_id *);
35 static void tsi148_remove(struct pci_dev *);
38 /* Module parameter */
42 static const char driver_name[] = "vme_tsi148";
44 static const struct pci_device_id tsi148_ids[] = {
45 { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_TSI148) },
49 MODULE_DEVICE_TABLE(pci, tsi148_ids);
51 static struct pci_driver tsi148_driver = {
53 .id_table = tsi148_ids,
54 .probe = tsi148_probe,
55 .remove = tsi148_remove,
58 static void reg_join(unsigned int high, unsigned int low,
59 unsigned long long *variable)
61 *variable = (unsigned long long)high << 32;
62 *variable |= (unsigned long long)low;
65 static void reg_split(unsigned long long variable, unsigned int *high,
68 *low = (unsigned int)variable & 0xFFFFFFFF;
69 *high = (unsigned int)(variable >> 32);
75 static u32 tsi148_DMA_irqhandler(struct tsi148_driver *bridge,
80 if (channel_mask & TSI148_LCSR_INTS_DMA0S) {
81 wake_up(&bridge->dma_queue[0]);
82 serviced |= TSI148_LCSR_INTC_DMA0C;
84 if (channel_mask & TSI148_LCSR_INTS_DMA1S) {
85 wake_up(&bridge->dma_queue[1]);
86 serviced |= TSI148_LCSR_INTC_DMA1C;
93 * Wake up location monitor queue
95 static u32 tsi148_LM_irqhandler(struct tsi148_driver *bridge, u32 stat)
100 for (i = 0; i < 4; i++) {
101 if (stat & TSI148_LCSR_INTS_LMS[i]) {
102 /* We only enable interrupts if the callback is set */
103 bridge->lm_callback[i](bridge->lm_data[i]);
104 serviced |= TSI148_LCSR_INTC_LMC[i];
112 * Wake up mail box queue.
114 * XXX This functionality is not exposed up though API.
116 static u32 tsi148_MB_irqhandler(struct vme_bridge *tsi148_bridge, u32 stat)
121 struct tsi148_driver *bridge;
123 bridge = tsi148_bridge->driver_priv;
125 for (i = 0; i < 4; i++) {
126 if (stat & TSI148_LCSR_INTS_MBS[i]) {
127 val = ioread32be(bridge->base + TSI148_GCSR_MBOX[i]);
128 dev_err(tsi148_bridge->parent, "VME Mailbox %d received: 0x%x\n",
130 serviced |= TSI148_LCSR_INTC_MBC[i];
138 * Display error & status message when PERR (PCI) exception interrupt occurs.
140 static u32 tsi148_PERR_irqhandler(struct vme_bridge *tsi148_bridge)
142 struct tsi148_driver *bridge;
144 bridge = tsi148_bridge->driver_priv;
146 dev_err(tsi148_bridge->parent, "PCI Exception at address: 0x%08x:%08x, attributes: %08x\n",
147 ioread32be(bridge->base + TSI148_LCSR_EDPAU),
148 ioread32be(bridge->base + TSI148_LCSR_EDPAL),
149 ioread32be(bridge->base + TSI148_LCSR_EDPAT));
151 dev_err(tsi148_bridge->parent, "PCI-X attribute reg: %08x, PCI-X split completion reg: %08x\n",
152 ioread32be(bridge->base + TSI148_LCSR_EDPXA),
153 ioread32be(bridge->base + TSI148_LCSR_EDPXS));
155 iowrite32be(TSI148_LCSR_EDPAT_EDPCL, bridge->base + TSI148_LCSR_EDPAT);
157 return TSI148_LCSR_INTC_PERRC;
161 * Save address and status when VME error interrupt occurs.
163 static u32 tsi148_VERR_irqhandler(struct vme_bridge *tsi148_bridge)
165 unsigned int error_addr_high, error_addr_low;
166 unsigned long long error_addr;
169 struct tsi148_driver *bridge;
171 bridge = tsi148_bridge->driver_priv;
173 error_addr_high = ioread32be(bridge->base + TSI148_LCSR_VEAU);
174 error_addr_low = ioread32be(bridge->base + TSI148_LCSR_VEAL);
175 error_attrib = ioread32be(bridge->base + TSI148_LCSR_VEAT);
176 error_am = (error_attrib & TSI148_LCSR_VEAT_AM_M) >> 8;
178 reg_join(error_addr_high, error_addr_low, &error_addr);
180 /* Check for exception register overflow (we have lost error data) */
181 if (error_attrib & TSI148_LCSR_VEAT_VEOF)
182 dev_err(tsi148_bridge->parent, "VME Bus Exception Overflow Occurred\n");
185 vme_bus_error_handler(tsi148_bridge, error_addr, error_am);
187 dev_err(tsi148_bridge->parent,
188 "VME Bus Error at address: 0x%llx, attributes: %08x\n",
189 error_addr, error_attrib);
192 iowrite32be(TSI148_LCSR_VEAT_VESCL, bridge->base + TSI148_LCSR_VEAT);
194 return TSI148_LCSR_INTC_VERRC;
198 * Wake up IACK queue.
200 static u32 tsi148_IACK_irqhandler(struct tsi148_driver *bridge)
202 wake_up(&bridge->iack_queue);
204 return TSI148_LCSR_INTC_IACKC;
208 * Calling VME bus interrupt callback if provided.
210 static u32 tsi148_VIRQ_irqhandler(struct vme_bridge *tsi148_bridge,
213 int vec, i, serviced = 0;
214 struct tsi148_driver *bridge;
216 bridge = tsi148_bridge->driver_priv;
218 for (i = 7; i > 0; i--) {
219 if (stat & (1 << i)) {
221 * Note: Even though the registers are defined as
222 * 32-bits in the spec, we only want to issue 8-bit
223 * IACK cycles on the bus, read from offset 3.
225 vec = ioread8(bridge->base + TSI148_LCSR_VIACK[i] + 3);
227 vme_irq_handler(tsi148_bridge, i, vec);
229 serviced |= (1 << i);
237 * Top level interrupt handler. Clears appropriate interrupt status bits and
238 * then calls appropriate sub handler(s).
240 static irqreturn_t tsi148_irqhandler(int irq, void *ptr)
242 u32 stat, enable, serviced = 0;
243 struct vme_bridge *tsi148_bridge;
244 struct tsi148_driver *bridge;
248 bridge = tsi148_bridge->driver_priv;
250 /* Determine which interrupts are unmasked and set */
251 enable = ioread32be(bridge->base + TSI148_LCSR_INTEO);
252 stat = ioread32be(bridge->base + TSI148_LCSR_INTS);
254 /* Only look at unmasked interrupts */
260 /* Call subhandlers as appropriate */
262 if (stat & (TSI148_LCSR_INTS_DMA1S | TSI148_LCSR_INTS_DMA0S))
263 serviced |= tsi148_DMA_irqhandler(bridge, stat);
265 /* Location monitor irqs */
266 if (stat & (TSI148_LCSR_INTS_LM3S | TSI148_LCSR_INTS_LM2S |
267 TSI148_LCSR_INTS_LM1S | TSI148_LCSR_INTS_LM0S))
268 serviced |= tsi148_LM_irqhandler(bridge, stat);
271 if (stat & (TSI148_LCSR_INTS_MB3S | TSI148_LCSR_INTS_MB2S |
272 TSI148_LCSR_INTS_MB1S | TSI148_LCSR_INTS_MB0S))
273 serviced |= tsi148_MB_irqhandler(tsi148_bridge, stat);
276 if (stat & TSI148_LCSR_INTS_PERRS)
277 serviced |= tsi148_PERR_irqhandler(tsi148_bridge);
280 if (stat & TSI148_LCSR_INTS_VERRS)
281 serviced |= tsi148_VERR_irqhandler(tsi148_bridge);
284 if (stat & TSI148_LCSR_INTS_IACKS)
285 serviced |= tsi148_IACK_irqhandler(bridge);
288 if (stat & (TSI148_LCSR_INTS_IRQ7S | TSI148_LCSR_INTS_IRQ6S |
289 TSI148_LCSR_INTS_IRQ5S | TSI148_LCSR_INTS_IRQ4S |
290 TSI148_LCSR_INTS_IRQ3S | TSI148_LCSR_INTS_IRQ2S |
291 TSI148_LCSR_INTS_IRQ1S))
292 serviced |= tsi148_VIRQ_irqhandler(tsi148_bridge, stat);
294 /* Clear serviced interrupts */
295 iowrite32be(serviced, bridge->base + TSI148_LCSR_INTC);
300 static int tsi148_irq_init(struct vme_bridge *tsi148_bridge)
304 struct pci_dev *pdev;
305 struct tsi148_driver *bridge;
307 pdev = to_pci_dev(tsi148_bridge->parent);
309 bridge = tsi148_bridge->driver_priv;
311 result = request_irq(pdev->irq,
314 driver_name, tsi148_bridge);
316 dev_err(tsi148_bridge->parent, "Can't get assigned pci irq vector %02X\n",
321 /* Enable and unmask interrupts */
322 tmp = TSI148_LCSR_INTEO_DMA1EO | TSI148_LCSR_INTEO_DMA0EO |
323 TSI148_LCSR_INTEO_MB3EO | TSI148_LCSR_INTEO_MB2EO |
324 TSI148_LCSR_INTEO_MB1EO | TSI148_LCSR_INTEO_MB0EO |
325 TSI148_LCSR_INTEO_PERREO | TSI148_LCSR_INTEO_VERREO |
326 TSI148_LCSR_INTEO_IACKEO;
328 /* This leaves the following interrupts masked.
329 * TSI148_LCSR_INTEO_VIEEO
330 * TSI148_LCSR_INTEO_SYSFLEO
331 * TSI148_LCSR_INTEO_ACFLEO
334 /* Don't enable Location Monitor interrupts here - they will be
335 * enabled when the location monitors are properly configured and
336 * a callback has been attached.
337 * TSI148_LCSR_INTEO_LM0EO
338 * TSI148_LCSR_INTEO_LM1EO
339 * TSI148_LCSR_INTEO_LM2EO
340 * TSI148_LCSR_INTEO_LM3EO
343 /* Don't enable VME interrupts until we add a handler, else the board
344 * will respond to it and we don't want that unless it knows how to
345 * properly deal with it.
346 * TSI148_LCSR_INTEO_IRQ7EO
347 * TSI148_LCSR_INTEO_IRQ6EO
348 * TSI148_LCSR_INTEO_IRQ5EO
349 * TSI148_LCSR_INTEO_IRQ4EO
350 * TSI148_LCSR_INTEO_IRQ3EO
351 * TSI148_LCSR_INTEO_IRQ2EO
352 * TSI148_LCSR_INTEO_IRQ1EO
355 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
356 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN);
361 static void tsi148_irq_exit(struct vme_bridge *tsi148_bridge,
362 struct pci_dev *pdev)
364 struct tsi148_driver *bridge = tsi148_bridge->driver_priv;
366 /* Turn off interrupts */
367 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEO);
368 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEN);
370 /* Clear all interrupts */
371 iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_INTC);
373 /* Detach interrupt handler */
374 free_irq(pdev->irq, tsi148_bridge);
378 * Check to see if an IACk has been received, return true (1) or false (0).
380 static int tsi148_iack_received(struct tsi148_driver *bridge)
384 tmp = ioread32be(bridge->base + TSI148_LCSR_VICR);
386 if (tmp & TSI148_LCSR_VICR_IRQS)
393 * Configure VME interrupt
395 static void tsi148_irq_set(struct vme_bridge *tsi148_bridge, int level,
398 struct pci_dev *pdev;
400 struct tsi148_driver *bridge;
402 bridge = tsi148_bridge->driver_priv;
404 /* We need to do the ordering differently for enabling and disabling */
406 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEN);
407 tmp &= ~TSI148_LCSR_INTEN_IRQEN[level - 1];
408 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN);
410 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO);
411 tmp &= ~TSI148_LCSR_INTEO_IRQEO[level - 1];
412 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
415 pdev = to_pci_dev(tsi148_bridge->parent);
416 synchronize_irq(pdev->irq);
419 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO);
420 tmp |= TSI148_LCSR_INTEO_IRQEO[level - 1];
421 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
423 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEN);
424 tmp |= TSI148_LCSR_INTEN_IRQEN[level - 1];
425 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN);
430 * Generate a VME bus interrupt at the requested level & vector. Wait for
431 * interrupt to be acked.
433 static int tsi148_irq_generate(struct vme_bridge *tsi148_bridge, int level,
437 struct tsi148_driver *bridge;
439 bridge = tsi148_bridge->driver_priv;
441 mutex_lock(&bridge->vme_int);
443 /* Read VICR register */
444 tmp = ioread32be(bridge->base + TSI148_LCSR_VICR);
447 tmp = (tmp & ~TSI148_LCSR_VICR_STID_M) |
448 (statid & TSI148_LCSR_VICR_STID_M);
449 iowrite32be(tmp, bridge->base + TSI148_LCSR_VICR);
451 /* Assert VMEbus IRQ */
452 tmp = tmp | TSI148_LCSR_VICR_IRQL[level];
453 iowrite32be(tmp, bridge->base + TSI148_LCSR_VICR);
455 /* XXX Consider implementing a timeout? */
456 wait_event_interruptible(bridge->iack_queue,
457 tsi148_iack_received(bridge));
459 mutex_unlock(&bridge->vme_int);
465 * Initialize a slave window with the requested attributes.
467 static int tsi148_slave_set(struct vme_slave_resource *image, int enabled,
468 unsigned long long vme_base, unsigned long long size,
469 dma_addr_t pci_base, u32 aspace, u32 cycle)
471 unsigned int i, addr = 0, granularity = 0;
472 unsigned int temp_ctl = 0;
473 unsigned int vme_base_low, vme_base_high;
474 unsigned int vme_bound_low, vme_bound_high;
475 unsigned int pci_offset_low, pci_offset_high;
476 unsigned long long vme_bound, pci_offset;
477 struct vme_bridge *tsi148_bridge;
478 struct tsi148_driver *bridge;
480 tsi148_bridge = image->parent;
481 bridge = tsi148_bridge->driver_priv;
488 addr |= TSI148_LCSR_ITAT_AS_A16;
491 granularity = 0x1000;
492 addr |= TSI148_LCSR_ITAT_AS_A24;
495 granularity = 0x10000;
496 addr |= TSI148_LCSR_ITAT_AS_A32;
499 granularity = 0x10000;
500 addr |= TSI148_LCSR_ITAT_AS_A64;
503 dev_err(tsi148_bridge->parent, "Invalid address space\n");
507 /* Convert 64-bit variables to 2x 32-bit variables */
508 reg_split(vme_base, &vme_base_high, &vme_base_low);
511 * Bound address is a valid address for the window, adjust
514 vme_bound = vme_base + size - granularity;
515 reg_split(vme_bound, &vme_bound_high, &vme_bound_low);
516 pci_offset = (unsigned long long)pci_base - vme_base;
517 reg_split(pci_offset, &pci_offset_high, &pci_offset_low);
519 if (vme_base_low & (granularity - 1)) {
520 dev_err(tsi148_bridge->parent, "Invalid VME base alignment\n");
523 if (vme_bound_low & (granularity - 1)) {
524 dev_err(tsi148_bridge->parent, "Invalid VME bound alignment\n");
527 if (pci_offset_low & (granularity - 1)) {
528 dev_err(tsi148_bridge->parent, "Invalid PCI Offset alignment\n");
532 /* Disable while we are mucking around */
533 temp_ctl = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
534 TSI148_LCSR_OFFSET_ITAT);
535 temp_ctl &= ~TSI148_LCSR_ITAT_EN;
536 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_IT[i] +
537 TSI148_LCSR_OFFSET_ITAT);
540 iowrite32be(vme_base_high, bridge->base + TSI148_LCSR_IT[i] +
541 TSI148_LCSR_OFFSET_ITSAU);
542 iowrite32be(vme_base_low, bridge->base + TSI148_LCSR_IT[i] +
543 TSI148_LCSR_OFFSET_ITSAL);
544 iowrite32be(vme_bound_high, bridge->base + TSI148_LCSR_IT[i] +
545 TSI148_LCSR_OFFSET_ITEAU);
546 iowrite32be(vme_bound_low, bridge->base + TSI148_LCSR_IT[i] +
547 TSI148_LCSR_OFFSET_ITEAL);
548 iowrite32be(pci_offset_high, bridge->base + TSI148_LCSR_IT[i] +
549 TSI148_LCSR_OFFSET_ITOFU);
550 iowrite32be(pci_offset_low, bridge->base + TSI148_LCSR_IT[i] +
551 TSI148_LCSR_OFFSET_ITOFL);
553 /* Setup 2eSST speeds */
554 temp_ctl &= ~TSI148_LCSR_ITAT_2eSSTM_M;
555 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
557 temp_ctl |= TSI148_LCSR_ITAT_2eSSTM_160;
560 temp_ctl |= TSI148_LCSR_ITAT_2eSSTM_267;
563 temp_ctl |= TSI148_LCSR_ITAT_2eSSTM_320;
567 /* Setup cycle types */
568 temp_ctl &= ~(0x1F << 7);
570 temp_ctl |= TSI148_LCSR_ITAT_BLT;
571 if (cycle & VME_MBLT)
572 temp_ctl |= TSI148_LCSR_ITAT_MBLT;
573 if (cycle & VME_2eVME)
574 temp_ctl |= TSI148_LCSR_ITAT_2eVME;
575 if (cycle & VME_2eSST)
576 temp_ctl |= TSI148_LCSR_ITAT_2eSST;
577 if (cycle & VME_2eSSTB)
578 temp_ctl |= TSI148_LCSR_ITAT_2eSSTB;
580 /* Setup address space */
581 temp_ctl &= ~TSI148_LCSR_ITAT_AS_M;
585 if (cycle & VME_SUPER)
586 temp_ctl |= TSI148_LCSR_ITAT_SUPR;
587 if (cycle & VME_USER)
588 temp_ctl |= TSI148_LCSR_ITAT_NPRIV;
589 if (cycle & VME_PROG)
590 temp_ctl |= TSI148_LCSR_ITAT_PGM;
591 if (cycle & VME_DATA)
592 temp_ctl |= TSI148_LCSR_ITAT_DATA;
594 /* Write ctl reg without enable */
595 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_IT[i] +
596 TSI148_LCSR_OFFSET_ITAT);
599 temp_ctl |= TSI148_LCSR_ITAT_EN;
601 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_IT[i] +
602 TSI148_LCSR_OFFSET_ITAT);
608 * Get slave window configuration.
610 static int tsi148_slave_get(struct vme_slave_resource *image, int *enabled,
611 unsigned long long *vme_base, unsigned long long *size,
612 dma_addr_t *pci_base, u32 *aspace, u32 *cycle)
614 unsigned int i, granularity = 0, ctl = 0;
615 unsigned int vme_base_low, vme_base_high;
616 unsigned int vme_bound_low, vme_bound_high;
617 unsigned int pci_offset_low, pci_offset_high;
618 unsigned long long vme_bound, pci_offset;
619 struct tsi148_driver *bridge;
621 bridge = image->parent->driver_priv;
626 ctl = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
627 TSI148_LCSR_OFFSET_ITAT);
629 vme_base_high = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
630 TSI148_LCSR_OFFSET_ITSAU);
631 vme_base_low = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
632 TSI148_LCSR_OFFSET_ITSAL);
633 vme_bound_high = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
634 TSI148_LCSR_OFFSET_ITEAU);
635 vme_bound_low = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
636 TSI148_LCSR_OFFSET_ITEAL);
637 pci_offset_high = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
638 TSI148_LCSR_OFFSET_ITOFU);
639 pci_offset_low = ioread32be(bridge->base + TSI148_LCSR_IT[i] +
640 TSI148_LCSR_OFFSET_ITOFL);
642 /* Convert 64-bit variables to 2x 32-bit variables */
643 reg_join(vme_base_high, vme_base_low, vme_base);
644 reg_join(vme_bound_high, vme_bound_low, &vme_bound);
645 reg_join(pci_offset_high, pci_offset_low, &pci_offset);
647 *pci_base = (dma_addr_t)(*vme_base + pci_offset);
653 if (ctl & TSI148_LCSR_ITAT_EN)
656 if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A16) {
660 if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A24) {
661 granularity = 0x1000;
664 if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A32) {
665 granularity = 0x10000;
668 if ((ctl & TSI148_LCSR_ITAT_AS_M) == TSI148_LCSR_ITAT_AS_A64) {
669 granularity = 0x10000;
673 /* Need granularity before we set the size */
674 *size = (unsigned long long)((vme_bound - *vme_base) + granularity);
677 if ((ctl & TSI148_LCSR_ITAT_2eSSTM_M) == TSI148_LCSR_ITAT_2eSSTM_160)
678 *cycle |= VME_2eSST160;
679 if ((ctl & TSI148_LCSR_ITAT_2eSSTM_M) == TSI148_LCSR_ITAT_2eSSTM_267)
680 *cycle |= VME_2eSST267;
681 if ((ctl & TSI148_LCSR_ITAT_2eSSTM_M) == TSI148_LCSR_ITAT_2eSSTM_320)
682 *cycle |= VME_2eSST320;
684 if (ctl & TSI148_LCSR_ITAT_BLT)
686 if (ctl & TSI148_LCSR_ITAT_MBLT)
688 if (ctl & TSI148_LCSR_ITAT_2eVME)
690 if (ctl & TSI148_LCSR_ITAT_2eSST)
692 if (ctl & TSI148_LCSR_ITAT_2eSSTB)
693 *cycle |= VME_2eSSTB;
695 if (ctl & TSI148_LCSR_ITAT_SUPR)
697 if (ctl & TSI148_LCSR_ITAT_NPRIV)
699 if (ctl & TSI148_LCSR_ITAT_PGM)
701 if (ctl & TSI148_LCSR_ITAT_DATA)
708 * Allocate and map PCI Resource
710 static int tsi148_alloc_resource(struct vme_master_resource *image,
711 unsigned long long size)
713 unsigned long long existing_size;
715 struct pci_dev *pdev;
716 struct vme_bridge *tsi148_bridge;
718 tsi148_bridge = image->parent;
720 pdev = to_pci_dev(tsi148_bridge->parent);
722 existing_size = (unsigned long long)(image->bus_resource.end -
723 image->bus_resource.start);
725 /* If the existing size is OK, return */
726 if ((size != 0) && (existing_size == (size - 1)))
729 if (existing_size != 0) {
730 iounmap(image->kern_base);
731 image->kern_base = NULL;
732 kfree(image->bus_resource.name);
733 release_resource(&image->bus_resource);
734 memset(&image->bus_resource, 0, sizeof(image->bus_resource));
737 /* Exit here if size is zero */
741 if (!image->bus_resource.name) {
742 image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC);
743 if (!image->bus_resource.name) {
749 sprintf((char *)image->bus_resource.name, "%s.%d", tsi148_bridge->name,
752 image->bus_resource.start = 0;
753 image->bus_resource.end = (unsigned long)size;
754 image->bus_resource.flags = IORESOURCE_MEM;
756 retval = pci_bus_alloc_resource(pdev->bus,
757 &image->bus_resource, size, 0x10000, PCIBIOS_MIN_MEM,
760 dev_err(tsi148_bridge->parent, "Failed to allocate mem resource for window %d size 0x%lx start 0x%lx\n",
761 image->number, (unsigned long)size,
762 (unsigned long)image->bus_resource.start);
766 image->kern_base = ioremap(
767 image->bus_resource.start, size);
768 if (!image->kern_base) {
769 dev_err(tsi148_bridge->parent, "Failed to remap resource\n");
777 release_resource(&image->bus_resource);
779 kfree(image->bus_resource.name);
780 memset(&image->bus_resource, 0, sizeof(image->bus_resource));
786 * Free and unmap PCI Resource
788 static void tsi148_free_resource(struct vme_master_resource *image)
790 iounmap(image->kern_base);
791 image->kern_base = NULL;
792 release_resource(&image->bus_resource);
793 kfree(image->bus_resource.name);
794 memset(&image->bus_resource, 0, sizeof(image->bus_resource));
798 * Set the attributes of an outbound window.
800 static int tsi148_master_set(struct vme_master_resource *image, int enabled,
801 unsigned long long vme_base, unsigned long long size, u32 aspace,
802 u32 cycle, u32 dwidth)
806 unsigned int temp_ctl = 0;
807 unsigned int pci_base_low, pci_base_high;
808 unsigned int pci_bound_low, pci_bound_high;
809 unsigned int vme_offset_low, vme_offset_high;
810 unsigned long long pci_bound, vme_offset, pci_base;
811 struct vme_bridge *tsi148_bridge;
812 struct tsi148_driver *bridge;
813 struct pci_bus_region region;
814 struct pci_dev *pdev;
816 tsi148_bridge = image->parent;
818 bridge = tsi148_bridge->driver_priv;
820 pdev = to_pci_dev(tsi148_bridge->parent);
822 /* Verify input data */
823 if (vme_base & 0xFFFF) {
824 dev_err(tsi148_bridge->parent, "Invalid VME Window alignment\n");
829 if ((size == 0) && (enabled != 0)) {
830 dev_err(tsi148_bridge->parent, "Size must be non-zero for enabled windows\n");
835 spin_lock(&image->lock);
837 /* Let's allocate the resource here rather than further up the stack as
838 * it avoids pushing loads of bus dependent stuff up the stack. If size
839 * is zero, any existing resource will be freed.
841 retval = tsi148_alloc_resource(image, size);
843 spin_unlock(&image->lock);
844 dev_err(tsi148_bridge->parent, "Unable to allocate memory for resource\n");
853 pcibios_resource_to_bus(pdev->bus, ®ion,
854 &image->bus_resource);
855 pci_base = region.start;
858 * Bound address is a valid address for the window, adjust
859 * according to window granularity.
861 pci_bound = pci_base + (size - 0x10000);
862 vme_offset = vme_base - pci_base;
865 /* Convert 64-bit variables to 2x 32-bit variables */
866 reg_split(pci_base, &pci_base_high, &pci_base_low);
867 reg_split(pci_bound, &pci_bound_high, &pci_bound_low);
868 reg_split(vme_offset, &vme_offset_high, &vme_offset_low);
870 if (pci_base_low & 0xFFFF) {
871 spin_unlock(&image->lock);
872 dev_err(tsi148_bridge->parent, "Invalid PCI base alignment\n");
876 if (pci_bound_low & 0xFFFF) {
877 spin_unlock(&image->lock);
878 dev_err(tsi148_bridge->parent, "Invalid PCI bound alignment\n");
882 if (vme_offset_low & 0xFFFF) {
883 spin_unlock(&image->lock);
884 dev_err(tsi148_bridge->parent, "Invalid VME Offset alignment\n");
891 /* Disable while we are mucking around */
892 temp_ctl = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
893 TSI148_LCSR_OFFSET_OTAT);
894 temp_ctl &= ~TSI148_LCSR_OTAT_EN;
895 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] +
896 TSI148_LCSR_OFFSET_OTAT);
898 /* Setup 2eSST speeds */
899 temp_ctl &= ~TSI148_LCSR_OTAT_2eSSTM_M;
900 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
902 temp_ctl |= TSI148_LCSR_OTAT_2eSSTM_160;
905 temp_ctl |= TSI148_LCSR_OTAT_2eSSTM_267;
908 temp_ctl |= TSI148_LCSR_OTAT_2eSSTM_320;
912 /* Setup cycle types */
913 if (cycle & VME_BLT) {
914 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
915 temp_ctl |= TSI148_LCSR_OTAT_TM_BLT;
917 if (cycle & VME_MBLT) {
918 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
919 temp_ctl |= TSI148_LCSR_OTAT_TM_MBLT;
921 if (cycle & VME_2eVME) {
922 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
923 temp_ctl |= TSI148_LCSR_OTAT_TM_2eVME;
925 if (cycle & VME_2eSST) {
926 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
927 temp_ctl |= TSI148_LCSR_OTAT_TM_2eSST;
929 if (cycle & VME_2eSSTB) {
930 dev_warn(tsi148_bridge->parent, "Currently not setting Broadcast Select Registers\n");
931 temp_ctl &= ~TSI148_LCSR_OTAT_TM_M;
932 temp_ctl |= TSI148_LCSR_OTAT_TM_2eSSTB;
935 /* Setup data width */
936 temp_ctl &= ~TSI148_LCSR_OTAT_DBW_M;
939 temp_ctl |= TSI148_LCSR_OTAT_DBW_16;
942 temp_ctl |= TSI148_LCSR_OTAT_DBW_32;
945 spin_unlock(&image->lock);
946 dev_err(tsi148_bridge->parent, "Invalid data width\n");
951 /* Setup address space */
952 temp_ctl &= ~TSI148_LCSR_OTAT_AMODE_M;
955 temp_ctl |= TSI148_LCSR_OTAT_AMODE_A16;
958 temp_ctl |= TSI148_LCSR_OTAT_AMODE_A24;
961 temp_ctl |= TSI148_LCSR_OTAT_AMODE_A32;
964 temp_ctl |= TSI148_LCSR_OTAT_AMODE_A64;
967 temp_ctl |= TSI148_LCSR_OTAT_AMODE_CRCSR;
970 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER1;
973 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER2;
976 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER3;
979 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER4;
982 spin_unlock(&image->lock);
983 dev_err(tsi148_bridge->parent, "Invalid address space\n");
989 if (cycle & VME_SUPER)
990 temp_ctl |= TSI148_LCSR_OTAT_SUP;
991 if (cycle & VME_PROG)
992 temp_ctl |= TSI148_LCSR_OTAT_PGM;
995 iowrite32be(pci_base_high, bridge->base + TSI148_LCSR_OT[i] +
996 TSI148_LCSR_OFFSET_OTSAU);
997 iowrite32be(pci_base_low, bridge->base + TSI148_LCSR_OT[i] +
998 TSI148_LCSR_OFFSET_OTSAL);
999 iowrite32be(pci_bound_high, bridge->base + TSI148_LCSR_OT[i] +
1000 TSI148_LCSR_OFFSET_OTEAU);
1001 iowrite32be(pci_bound_low, bridge->base + TSI148_LCSR_OT[i] +
1002 TSI148_LCSR_OFFSET_OTEAL);
1003 iowrite32be(vme_offset_high, bridge->base + TSI148_LCSR_OT[i] +
1004 TSI148_LCSR_OFFSET_OTOFU);
1005 iowrite32be(vme_offset_low, bridge->base + TSI148_LCSR_OT[i] +
1006 TSI148_LCSR_OFFSET_OTOFL);
1008 /* Write ctl reg without enable */
1009 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] +
1010 TSI148_LCSR_OFFSET_OTAT);
1013 temp_ctl |= TSI148_LCSR_OTAT_EN;
1015 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] +
1016 TSI148_LCSR_OFFSET_OTAT);
1018 spin_unlock(&image->lock);
1024 tsi148_free_resource(image);
1032 * Set the attributes of an outbound window.
1034 * XXX Not parsing prefetch information.
1036 static int __tsi148_master_get(struct vme_master_resource *image, int *enabled,
1037 unsigned long long *vme_base, unsigned long long *size, u32 *aspace,
1038 u32 *cycle, u32 *dwidth)
1040 unsigned int i, ctl;
1041 unsigned int pci_base_low, pci_base_high;
1042 unsigned int pci_bound_low, pci_bound_high;
1043 unsigned int vme_offset_low, vme_offset_high;
1045 unsigned long long pci_base, pci_bound, vme_offset;
1046 struct tsi148_driver *bridge;
1048 bridge = image->parent->driver_priv;
1052 ctl = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1053 TSI148_LCSR_OFFSET_OTAT);
1055 pci_base_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1056 TSI148_LCSR_OFFSET_OTSAU);
1057 pci_base_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1058 TSI148_LCSR_OFFSET_OTSAL);
1059 pci_bound_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1060 TSI148_LCSR_OFFSET_OTEAU);
1061 pci_bound_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1062 TSI148_LCSR_OFFSET_OTEAL);
1063 vme_offset_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1064 TSI148_LCSR_OFFSET_OTOFU);
1065 vme_offset_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1066 TSI148_LCSR_OFFSET_OTOFL);
1068 /* Convert 64-bit variables to 2x 32-bit variables */
1069 reg_join(pci_base_high, pci_base_low, &pci_base);
1070 reg_join(pci_bound_high, pci_bound_low, &pci_bound);
1071 reg_join(vme_offset_high, vme_offset_low, &vme_offset);
1073 *vme_base = pci_base + vme_offset;
1074 *size = (unsigned long long)(pci_bound - pci_base) + 0x10000;
1081 if (ctl & TSI148_LCSR_OTAT_EN)
1084 /* Setup address space */
1085 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A16)
1087 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A24)
1089 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A32)
1091 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_A64)
1093 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_CRCSR)
1094 *aspace |= VME_CRCSR;
1095 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER1)
1096 *aspace |= VME_USER1;
1097 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER2)
1098 *aspace |= VME_USER2;
1099 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER3)
1100 *aspace |= VME_USER3;
1101 if ((ctl & TSI148_LCSR_OTAT_AMODE_M) == TSI148_LCSR_OTAT_AMODE_USER4)
1102 *aspace |= VME_USER4;
1104 /* Setup 2eSST speeds */
1105 if ((ctl & TSI148_LCSR_OTAT_2eSSTM_M) == TSI148_LCSR_OTAT_2eSSTM_160)
1106 *cycle |= VME_2eSST160;
1107 if ((ctl & TSI148_LCSR_OTAT_2eSSTM_M) == TSI148_LCSR_OTAT_2eSSTM_267)
1108 *cycle |= VME_2eSST267;
1109 if ((ctl & TSI148_LCSR_OTAT_2eSSTM_M) == TSI148_LCSR_OTAT_2eSSTM_320)
1110 *cycle |= VME_2eSST320;
1112 /* Setup cycle types */
1113 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_SCT)
1115 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_BLT)
1117 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_MBLT)
1119 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_2eVME)
1120 *cycle |= VME_2eVME;
1121 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_2eSST)
1122 *cycle |= VME_2eSST;
1123 if ((ctl & TSI148_LCSR_OTAT_TM_M) == TSI148_LCSR_OTAT_TM_2eSSTB)
1124 *cycle |= VME_2eSSTB;
1126 if (ctl & TSI148_LCSR_OTAT_SUP)
1127 *cycle |= VME_SUPER;
1131 if (ctl & TSI148_LCSR_OTAT_PGM)
1136 /* Setup data width */
1137 if ((ctl & TSI148_LCSR_OTAT_DBW_M) == TSI148_LCSR_OTAT_DBW_16)
1139 if ((ctl & TSI148_LCSR_OTAT_DBW_M) == TSI148_LCSR_OTAT_DBW_32)
1146 static int tsi148_master_get(struct vme_master_resource *image, int *enabled,
1147 unsigned long long *vme_base, unsigned long long *size, u32 *aspace,
1148 u32 *cycle, u32 *dwidth)
1152 spin_lock(&image->lock);
1154 retval = __tsi148_master_get(image, enabled, vme_base, size, aspace,
1157 spin_unlock(&image->lock);
1162 static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf,
1163 size_t count, loff_t offset)
1165 int retval, enabled;
1166 unsigned long long vme_base, size;
1167 u32 aspace, cycle, dwidth;
1168 struct vme_error_handler *handler = NULL;
1169 struct vme_bridge *tsi148_bridge;
1170 void __iomem *addr = image->kern_base + offset;
1171 unsigned int done = 0;
1172 unsigned int count32;
1174 tsi148_bridge = image->parent;
1176 spin_lock(&image->lock);
1179 __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace,
1181 handler = vme_register_error_handler(tsi148_bridge, aspace,
1182 vme_base + offset, count);
1184 spin_unlock(&image->lock);
1189 /* The following code handles VME address alignment. We cannot use
1190 * memcpy_xxx here because it may cut data transfers in to 8-bit
1191 * cycles when D16 or D32 cycles are required on the VME bus.
1192 * On the other hand, the bridge itself assures that the maximum data
1193 * cycle configured for the transfer is used and splits it
1194 * automatically for non-aligned addresses, so we don't want the
1195 * overhead of needlessly forcing small transfers for the entire cycle.
1197 if ((uintptr_t)addr & 0x1) {
1198 *(u8 *)buf = ioread8(addr);
1203 if ((uintptr_t)(addr + done) & 0x2) {
1204 if ((count - done) < 2) {
1205 *(u8 *)(buf + done) = ioread8(addr + done);
1209 *(u16 *)(buf + done) = ioread16(addr + done);
1214 count32 = (count - done) & ~0x3;
1215 while (done < count32) {
1216 *(u32 *)(buf + done) = ioread32(addr + done);
1220 if ((count - done) & 0x2) {
1221 *(u16 *)(buf + done) = ioread16(addr + done);
1224 if ((count - done) & 0x1) {
1225 *(u8 *)(buf + done) = ioread8(addr + done);
1233 if (handler->num_errors) {
1234 dev_err(image->parent->parent,
1235 "First VME read error detected an at address 0x%llx\n",
1236 handler->first_error);
1237 retval = handler->first_error - (vme_base + offset);
1239 vme_unregister_error_handler(handler);
1242 spin_unlock(&image->lock);
1248 static ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf,
1249 size_t count, loff_t offset)
1251 int retval = 0, enabled;
1252 unsigned long long vme_base, size;
1253 u32 aspace, cycle, dwidth;
1254 void __iomem *addr = image->kern_base + offset;
1255 unsigned int done = 0;
1256 unsigned int count32;
1258 struct vme_error_handler *handler = NULL;
1259 struct vme_bridge *tsi148_bridge;
1260 struct tsi148_driver *bridge;
1262 tsi148_bridge = image->parent;
1264 bridge = tsi148_bridge->driver_priv;
1266 spin_lock(&image->lock);
1269 __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace,
1271 handler = vme_register_error_handler(tsi148_bridge, aspace,
1272 vme_base + offset, count);
1274 spin_unlock(&image->lock);
1279 /* Here we apply for the same strategy we do in master_read
1280 * function in order to assure the correct cycles.
1282 if ((uintptr_t)addr & 0x1) {
1283 iowrite8(*(u8 *)buf, addr);
1288 if ((uintptr_t)(addr + done) & 0x2) {
1289 if ((count - done) < 2) {
1290 iowrite8(*(u8 *)(buf + done), addr + done);
1294 iowrite16(*(u16 *)(buf + done), addr + done);
1299 count32 = (count - done) & ~0x3;
1300 while (done < count32) {
1301 iowrite32(*(u32 *)(buf + done), addr + done);
1305 if ((count - done) & 0x2) {
1306 iowrite16(*(u16 *)(buf + done), addr + done);
1309 if ((count - done) & 0x1) {
1310 iowrite8(*(u8 *)(buf + done), addr + done);
1318 * Writes are posted. We need to do a read on the VME bus to flush out
1319 * all of the writes before we check for errors. We can't guarantee
1320 * that reading the data we have just written is safe. It is believed
1321 * that there isn't any read, write re-ordering, so we can read any
1322 * location in VME space, so lets read the Device ID from the tsi148's
1323 * own registers as mapped into CR/CSR space.
1325 * We check for saved errors in the written address range/space.
1329 ioread16(bridge->flush_image->kern_base + 0x7F000);
1331 if (handler->num_errors) {
1332 dev_warn(tsi148_bridge->parent,
1333 "First VME write error detected an at address 0x%llx\n",
1334 handler->first_error);
1335 retval = handler->first_error - (vme_base + offset);
1337 vme_unregister_error_handler(handler);
1340 spin_unlock(&image->lock);
1346 * Perform an RMW cycle on the VME bus.
1348 * Requires a previously configured master window, returns final value.
1350 static unsigned int tsi148_master_rmw(struct vme_master_resource *image,
1351 unsigned int mask, unsigned int compare, unsigned int swap,
1354 unsigned long long pci_addr;
1355 unsigned int pci_addr_high, pci_addr_low;
1358 struct tsi148_driver *bridge;
1360 bridge = image->parent->driver_priv;
1362 /* Find the PCI address that maps to the desired VME address */
1365 /* Locking as we can only do one of these at a time */
1366 mutex_lock(&bridge->vme_rmw);
1369 spin_lock(&image->lock);
1371 pci_addr_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1372 TSI148_LCSR_OFFSET_OTSAU);
1373 pci_addr_low = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1374 TSI148_LCSR_OFFSET_OTSAL);
1376 reg_join(pci_addr_high, pci_addr_low, &pci_addr);
1377 reg_split(pci_addr + offset, &pci_addr_high, &pci_addr_low);
1379 /* Configure registers */
1380 iowrite32be(mask, bridge->base + TSI148_LCSR_RMWEN);
1381 iowrite32be(compare, bridge->base + TSI148_LCSR_RMWC);
1382 iowrite32be(swap, bridge->base + TSI148_LCSR_RMWS);
1383 iowrite32be(pci_addr_high, bridge->base + TSI148_LCSR_RMWAU);
1384 iowrite32be(pci_addr_low, bridge->base + TSI148_LCSR_RMWAL);
1387 tmp = ioread32be(bridge->base + TSI148_LCSR_VMCTRL);
1388 tmp |= TSI148_LCSR_VMCTRL_RMWEN;
1389 iowrite32be(tmp, bridge->base + TSI148_LCSR_VMCTRL);
1391 /* Kick process off with a read to the required address. */
1392 result = ioread32be(image->kern_base + offset);
1395 tmp = ioread32be(bridge->base + TSI148_LCSR_VMCTRL);
1396 tmp &= ~TSI148_LCSR_VMCTRL_RMWEN;
1397 iowrite32be(tmp, bridge->base + TSI148_LCSR_VMCTRL);
1399 spin_unlock(&image->lock);
1401 mutex_unlock(&bridge->vme_rmw);
1406 static int tsi148_dma_set_vme_src_attributes(struct device *dev, __be32 *attr,
1407 u32 aspace, u32 cycle, u32 dwidth)
1411 val = be32_to_cpu(*attr);
1413 /* Setup 2eSST speeds */
1414 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
1416 val |= TSI148_LCSR_DSAT_2eSSTM_160;
1419 val |= TSI148_LCSR_DSAT_2eSSTM_267;
1422 val |= TSI148_LCSR_DSAT_2eSSTM_320;
1426 /* Setup cycle types */
1427 if (cycle & VME_SCT)
1428 val |= TSI148_LCSR_DSAT_TM_SCT;
1430 if (cycle & VME_BLT)
1431 val |= TSI148_LCSR_DSAT_TM_BLT;
1433 if (cycle & VME_MBLT)
1434 val |= TSI148_LCSR_DSAT_TM_MBLT;
1436 if (cycle & VME_2eVME)
1437 val |= TSI148_LCSR_DSAT_TM_2eVME;
1439 if (cycle & VME_2eSST)
1440 val |= TSI148_LCSR_DSAT_TM_2eSST;
1442 if (cycle & VME_2eSSTB) {
1443 dev_err(dev, "Currently not setting Broadcast Select Registers\n");
1444 val |= TSI148_LCSR_DSAT_TM_2eSSTB;
1447 /* Setup data width */
1450 val |= TSI148_LCSR_DSAT_DBW_16;
1453 val |= TSI148_LCSR_DSAT_DBW_32;
1456 dev_err(dev, "Invalid data width\n");
1460 /* Setup address space */
1463 val |= TSI148_LCSR_DSAT_AMODE_A16;
1466 val |= TSI148_LCSR_DSAT_AMODE_A24;
1469 val |= TSI148_LCSR_DSAT_AMODE_A32;
1472 val |= TSI148_LCSR_DSAT_AMODE_A64;
1475 val |= TSI148_LCSR_DSAT_AMODE_CRCSR;
1478 val |= TSI148_LCSR_DSAT_AMODE_USER1;
1481 val |= TSI148_LCSR_DSAT_AMODE_USER2;
1484 val |= TSI148_LCSR_DSAT_AMODE_USER3;
1487 val |= TSI148_LCSR_DSAT_AMODE_USER4;
1490 dev_err(dev, "Invalid address space\n");
1494 if (cycle & VME_SUPER)
1495 val |= TSI148_LCSR_DSAT_SUP;
1496 if (cycle & VME_PROG)
1497 val |= TSI148_LCSR_DSAT_PGM;
1499 *attr = cpu_to_be32(val);
1504 static int tsi148_dma_set_vme_dest_attributes(struct device *dev, __be32 *attr,
1505 u32 aspace, u32 cycle, u32 dwidth)
1509 val = be32_to_cpu(*attr);
1511 /* Setup 2eSST speeds */
1512 switch (cycle & (VME_2eSST160 | VME_2eSST267 | VME_2eSST320)) {
1514 val |= TSI148_LCSR_DDAT_2eSSTM_160;
1517 val |= TSI148_LCSR_DDAT_2eSSTM_267;
1520 val |= TSI148_LCSR_DDAT_2eSSTM_320;
1524 /* Setup cycle types */
1525 if (cycle & VME_SCT)
1526 val |= TSI148_LCSR_DDAT_TM_SCT;
1528 if (cycle & VME_BLT)
1529 val |= TSI148_LCSR_DDAT_TM_BLT;
1531 if (cycle & VME_MBLT)
1532 val |= TSI148_LCSR_DDAT_TM_MBLT;
1534 if (cycle & VME_2eVME)
1535 val |= TSI148_LCSR_DDAT_TM_2eVME;
1537 if (cycle & VME_2eSST)
1538 val |= TSI148_LCSR_DDAT_TM_2eSST;
1540 if (cycle & VME_2eSSTB) {
1541 dev_err(dev, "Currently not setting Broadcast Select Registers\n");
1542 val |= TSI148_LCSR_DDAT_TM_2eSSTB;
1545 /* Setup data width */
1548 val |= TSI148_LCSR_DDAT_DBW_16;
1551 val |= TSI148_LCSR_DDAT_DBW_32;
1554 dev_err(dev, "Invalid data width\n");
1558 /* Setup address space */
1561 val |= TSI148_LCSR_DDAT_AMODE_A16;
1564 val |= TSI148_LCSR_DDAT_AMODE_A24;
1567 val |= TSI148_LCSR_DDAT_AMODE_A32;
1570 val |= TSI148_LCSR_DDAT_AMODE_A64;
1573 val |= TSI148_LCSR_DDAT_AMODE_CRCSR;
1576 val |= TSI148_LCSR_DDAT_AMODE_USER1;
1579 val |= TSI148_LCSR_DDAT_AMODE_USER2;
1582 val |= TSI148_LCSR_DDAT_AMODE_USER3;
1585 val |= TSI148_LCSR_DDAT_AMODE_USER4;
1588 dev_err(dev, "Invalid address space\n");
1592 if (cycle & VME_SUPER)
1593 val |= TSI148_LCSR_DDAT_SUP;
1594 if (cycle & VME_PROG)
1595 val |= TSI148_LCSR_DDAT_PGM;
1597 *attr = cpu_to_be32(val);
1603 * Add a link list descriptor to the list
1605 * Note: DMA engine expects the DMA descriptor to be big endian.
1607 static int tsi148_dma_list_add(struct vme_dma_list *list,
1608 struct vme_dma_attr *src, struct vme_dma_attr *dest, size_t count)
1610 struct tsi148_dma_entry *entry, *prev;
1611 u32 address_high, address_low, val;
1612 struct vme_dma_pattern *pattern_attr;
1613 struct vme_dma_pci *pci_attr;
1614 struct vme_dma_vme *vme_attr;
1616 struct vme_bridge *tsi148_bridge;
1618 tsi148_bridge = list->parent->parent;
1620 /* Descriptor must be aligned on 64-bit boundaries */
1621 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1627 /* Test descriptor alignment */
1628 if ((unsigned long)&entry->descriptor & 0x7) {
1629 dev_err(tsi148_bridge->parent, "Descriptor not aligned to 8 byte boundary as required: %p\n",
1630 &entry->descriptor);
1635 /* Given we are going to fill out the structure, we probably don't
1636 * need to zero it, but better safe than sorry for now.
1638 memset(&entry->descriptor, 0, sizeof(entry->descriptor));
1640 /* Fill out source part */
1641 switch (src->type) {
1642 case VME_DMA_PATTERN:
1643 pattern_attr = src->private;
1645 entry->descriptor.dsal = cpu_to_be32(pattern_attr->pattern);
1647 val = TSI148_LCSR_DSAT_TYP_PAT;
1649 /* Default behaviour is 32 bit pattern */
1650 if (pattern_attr->type & VME_DMA_PATTERN_BYTE)
1651 val |= TSI148_LCSR_DSAT_PSZ;
1653 /* It seems that the default behaviour is to increment */
1654 if ((pattern_attr->type & VME_DMA_PATTERN_INCREMENT) == 0)
1655 val |= TSI148_LCSR_DSAT_NIN;
1656 entry->descriptor.dsat = cpu_to_be32(val);
1659 pci_attr = src->private;
1661 reg_split((unsigned long long)pci_attr->address, &address_high,
1663 entry->descriptor.dsau = cpu_to_be32(address_high);
1664 entry->descriptor.dsal = cpu_to_be32(address_low);
1665 entry->descriptor.dsat = cpu_to_be32(TSI148_LCSR_DSAT_TYP_PCI);
1668 vme_attr = src->private;
1670 reg_split((unsigned long long)vme_attr->address, &address_high,
1672 entry->descriptor.dsau = cpu_to_be32(address_high);
1673 entry->descriptor.dsal = cpu_to_be32(address_low);
1674 entry->descriptor.dsat = cpu_to_be32(TSI148_LCSR_DSAT_TYP_VME);
1676 retval = tsi148_dma_set_vme_src_attributes(
1677 tsi148_bridge->parent, &entry->descriptor.dsat,
1678 vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth);
1683 dev_err(tsi148_bridge->parent, "Invalid source type\n");
1688 /* Assume last link - this will be over-written by adding another */
1689 entry->descriptor.dnlau = cpu_to_be32(0);
1690 entry->descriptor.dnlal = cpu_to_be32(TSI148_LCSR_DNLAL_LLA);
1692 /* Fill out destination part */
1693 switch (dest->type) {
1695 pci_attr = dest->private;
1697 reg_split((unsigned long long)pci_attr->address, &address_high,
1699 entry->descriptor.ddau = cpu_to_be32(address_high);
1700 entry->descriptor.ddal = cpu_to_be32(address_low);
1701 entry->descriptor.ddat = cpu_to_be32(TSI148_LCSR_DDAT_TYP_PCI);
1704 vme_attr = dest->private;
1706 reg_split((unsigned long long)vme_attr->address, &address_high,
1708 entry->descriptor.ddau = cpu_to_be32(address_high);
1709 entry->descriptor.ddal = cpu_to_be32(address_low);
1710 entry->descriptor.ddat = cpu_to_be32(TSI148_LCSR_DDAT_TYP_VME);
1712 retval = tsi148_dma_set_vme_dest_attributes(
1713 tsi148_bridge->parent, &entry->descriptor.ddat,
1714 vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth);
1719 dev_err(tsi148_bridge->parent, "Invalid destination type\n");
1724 /* Fill out count */
1725 entry->descriptor.dcnt = cpu_to_be32((u32)count);
1728 list_add_tail(&entry->list, &list->entries);
1730 entry->dma_handle = dma_map_single(tsi148_bridge->parent,
1732 sizeof(entry->descriptor),
1734 if (dma_mapping_error(tsi148_bridge->parent, entry->dma_handle)) {
1735 dev_err(tsi148_bridge->parent, "DMA mapping error\n");
1740 /* Fill out previous descriptors "Next Address" */
1741 if (entry->list.prev != &list->entries) {
1742 reg_split((unsigned long long)entry->dma_handle, &address_high,
1744 prev = list_entry(entry->list.prev, struct tsi148_dma_entry,
1746 prev->descriptor.dnlau = cpu_to_be32(address_high);
1747 prev->descriptor.dnlal = cpu_to_be32(address_low);
1754 list_del(&entry->list);
1764 * Check to see if the provided DMA channel is busy.
1766 static int tsi148_dma_busy(struct vme_bridge *tsi148_bridge, int channel)
1769 struct tsi148_driver *bridge;
1771 bridge = tsi148_bridge->driver_priv;
1773 tmp = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] +
1774 TSI148_LCSR_OFFSET_DSTA);
1776 if (tmp & TSI148_LCSR_DSTA_BSY)
1784 * Execute a previously generated link list
1786 * XXX Need to provide control register configuration.
1788 static int tsi148_dma_list_exec(struct vme_dma_list *list)
1790 struct vme_dma_resource *ctrlr;
1791 int channel, retval;
1792 struct tsi148_dma_entry *entry;
1793 u32 bus_addr_high, bus_addr_low;
1794 u32 val, dctlreg = 0;
1795 struct vme_bridge *tsi148_bridge;
1796 struct tsi148_driver *bridge;
1798 ctrlr = list->parent;
1800 tsi148_bridge = ctrlr->parent;
1802 bridge = tsi148_bridge->driver_priv;
1804 mutex_lock(&ctrlr->mtx);
1806 channel = ctrlr->number;
1808 if (!list_empty(&ctrlr->running)) {
1810 * XXX We have an active DMA transfer and currently haven't
1811 * sorted out the mechanism for "pending" DMA transfers.
1814 /* Need to add to pending here */
1815 mutex_unlock(&ctrlr->mtx);
1819 list_add(&list->list, &ctrlr->running);
1821 /* Get first bus address and write into registers */
1822 entry = list_first_entry(&list->entries, struct tsi148_dma_entry,
1825 mutex_unlock(&ctrlr->mtx);
1827 reg_split(entry->dma_handle, &bus_addr_high, &bus_addr_low);
1829 iowrite32be(bus_addr_high, bridge->base +
1830 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAU);
1831 iowrite32be(bus_addr_low, bridge->base +
1832 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DNLAL);
1834 dctlreg = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] +
1835 TSI148_LCSR_OFFSET_DCTL);
1837 /* Start the operation */
1838 iowrite32be(dctlreg | TSI148_LCSR_DCTL_DGO, bridge->base +
1839 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DCTL);
1841 retval = wait_event_interruptible(bridge->dma_queue[channel],
1842 tsi148_dma_busy(ctrlr->parent, channel));
1845 iowrite32be(dctlreg | TSI148_LCSR_DCTL_ABT, bridge->base +
1846 TSI148_LCSR_DMA[channel] + TSI148_LCSR_OFFSET_DCTL);
1847 /* Wait for the operation to abort */
1848 wait_event(bridge->dma_queue[channel],
1849 tsi148_dma_busy(ctrlr->parent, channel));
1855 * Read status register, this register is valid until we kick off a
1858 val = ioread32be(bridge->base + TSI148_LCSR_DMA[channel] +
1859 TSI148_LCSR_OFFSET_DSTA);
1861 if (val & TSI148_LCSR_DSTA_VBE) {
1862 dev_err(tsi148_bridge->parent, "DMA Error. DSTA=%08X\n", val);
1867 /* Remove list from running list */
1868 mutex_lock(&ctrlr->mtx);
1869 list_del(&list->list);
1870 mutex_unlock(&ctrlr->mtx);
1876 * Clean up a previously generated link list
1878 * We have a separate function, don't assume that the chain can't be reused.
1880 static int tsi148_dma_list_empty(struct vme_dma_list *list)
1882 struct list_head *pos, *temp;
1883 struct tsi148_dma_entry *entry;
1885 struct vme_bridge *tsi148_bridge = list->parent->parent;
1887 /* detach and free each entry */
1888 list_for_each_safe(pos, temp, &list->entries) {
1890 entry = list_entry(pos, struct tsi148_dma_entry, list);
1892 dma_unmap_single(tsi148_bridge->parent, entry->dma_handle,
1893 sizeof(struct tsi148_dma_descriptor), DMA_TO_DEVICE);
1901 * All 4 location monitors reside at the same base - this is therefore a
1902 * system wide configuration.
1904 * This does not enable the LM monitor - that should be done when the first
1905 * callback is attached and disabled when the last callback is removed.
1907 static int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1908 u32 aspace, u32 cycle)
1910 u32 lm_base_high, lm_base_low, lm_ctl = 0;
1912 struct vme_bridge *tsi148_bridge;
1913 struct tsi148_driver *bridge;
1915 tsi148_bridge = lm->parent;
1917 bridge = tsi148_bridge->driver_priv;
1919 mutex_lock(&lm->mtx);
1921 /* If we already have a callback attached, we can't move it! */
1922 for (i = 0; i < lm->monitors; i++) {
1923 if (bridge->lm_callback[i]) {
1924 mutex_unlock(&lm->mtx);
1925 dev_err(tsi148_bridge->parent, "Location monitor callback attached, can't reset\n");
1932 lm_ctl |= TSI148_LCSR_LMAT_AS_A16;
1935 lm_ctl |= TSI148_LCSR_LMAT_AS_A24;
1938 lm_ctl |= TSI148_LCSR_LMAT_AS_A32;
1941 lm_ctl |= TSI148_LCSR_LMAT_AS_A64;
1944 mutex_unlock(&lm->mtx);
1945 dev_err(tsi148_bridge->parent, "Invalid address space\n");
1949 if (cycle & VME_SUPER)
1950 lm_ctl |= TSI148_LCSR_LMAT_SUPR;
1951 if (cycle & VME_USER)
1952 lm_ctl |= TSI148_LCSR_LMAT_NPRIV;
1953 if (cycle & VME_PROG)
1954 lm_ctl |= TSI148_LCSR_LMAT_PGM;
1955 if (cycle & VME_DATA)
1956 lm_ctl |= TSI148_LCSR_LMAT_DATA;
1958 reg_split(lm_base, &lm_base_high, &lm_base_low);
1960 iowrite32be(lm_base_high, bridge->base + TSI148_LCSR_LMBAU);
1961 iowrite32be(lm_base_low, bridge->base + TSI148_LCSR_LMBAL);
1962 iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT);
1964 mutex_unlock(&lm->mtx);
1969 /* Get configuration of the callback monitor and return whether it is enabled
1972 static int tsi148_lm_get(struct vme_lm_resource *lm,
1973 unsigned long long *lm_base, u32 *aspace, u32 *cycle)
1975 u32 lm_base_high, lm_base_low, lm_ctl, enabled = 0;
1976 struct tsi148_driver *bridge;
1978 bridge = lm->parent->driver_priv;
1980 mutex_lock(&lm->mtx);
1982 lm_base_high = ioread32be(bridge->base + TSI148_LCSR_LMBAU);
1983 lm_base_low = ioread32be(bridge->base + TSI148_LCSR_LMBAL);
1984 lm_ctl = ioread32be(bridge->base + TSI148_LCSR_LMAT);
1986 reg_join(lm_base_high, lm_base_low, lm_base);
1988 if (lm_ctl & TSI148_LCSR_LMAT_EN)
1991 if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A16)
1994 if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A24)
1997 if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A32)
2000 if ((lm_ctl & TSI148_LCSR_LMAT_AS_M) == TSI148_LCSR_LMAT_AS_A64)
2004 if (lm_ctl & TSI148_LCSR_LMAT_SUPR)
2005 *cycle |= VME_SUPER;
2006 if (lm_ctl & TSI148_LCSR_LMAT_NPRIV)
2008 if (lm_ctl & TSI148_LCSR_LMAT_PGM)
2010 if (lm_ctl & TSI148_LCSR_LMAT_DATA)
2013 mutex_unlock(&lm->mtx);
2019 * Attach a callback to a specific location monitor.
2021 * Callback will be passed the monitor triggered.
2023 static int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor,
2024 void (*callback)(void *), void *data)
2027 struct vme_bridge *tsi148_bridge;
2028 struct tsi148_driver *bridge;
2030 tsi148_bridge = lm->parent;
2032 bridge = tsi148_bridge->driver_priv;
2034 mutex_lock(&lm->mtx);
2036 /* Ensure that the location monitor is configured - need PGM or DATA */
2037 lm_ctl = ioread32be(bridge->base + TSI148_LCSR_LMAT);
2038 if ((lm_ctl & (TSI148_LCSR_LMAT_PGM | TSI148_LCSR_LMAT_DATA)) == 0) {
2039 mutex_unlock(&lm->mtx);
2040 dev_err(tsi148_bridge->parent, "Location monitor not properly configured\n");
2044 /* Check that a callback isn't already attached */
2045 if (bridge->lm_callback[monitor]) {
2046 mutex_unlock(&lm->mtx);
2047 dev_err(tsi148_bridge->parent, "Existing callback attached\n");
2051 /* Attach callback */
2052 bridge->lm_callback[monitor] = callback;
2053 bridge->lm_data[monitor] = data;
2055 /* Enable Location Monitor interrupt */
2056 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEN);
2057 tmp |= TSI148_LCSR_INTEN_LMEN[monitor];
2058 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEN);
2060 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO);
2061 tmp |= TSI148_LCSR_INTEO_LMEO[monitor];
2062 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
2064 /* Ensure that global Location Monitor Enable set */
2065 if ((lm_ctl & TSI148_LCSR_LMAT_EN) == 0) {
2066 lm_ctl |= TSI148_LCSR_LMAT_EN;
2067 iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT);
2070 mutex_unlock(&lm->mtx);
2076 * Detach a callback function forn a specific location monitor.
2078 static int tsi148_lm_detach(struct vme_lm_resource *lm, int monitor)
2081 struct tsi148_driver *bridge;
2083 bridge = lm->parent->driver_priv;
2085 mutex_lock(&lm->mtx);
2087 /* Disable Location Monitor and ensure previous interrupts are clear */
2088 lm_en = ioread32be(bridge->base + TSI148_LCSR_INTEN);
2089 lm_en &= ~TSI148_LCSR_INTEN_LMEN[monitor];
2090 iowrite32be(lm_en, bridge->base + TSI148_LCSR_INTEN);
2092 tmp = ioread32be(bridge->base + TSI148_LCSR_INTEO);
2093 tmp &= ~TSI148_LCSR_INTEO_LMEO[monitor];
2094 iowrite32be(tmp, bridge->base + TSI148_LCSR_INTEO);
2096 iowrite32be(TSI148_LCSR_INTC_LMC[monitor],
2097 bridge->base + TSI148_LCSR_INTC);
2099 /* Detach callback */
2100 bridge->lm_callback[monitor] = NULL;
2101 bridge->lm_data[monitor] = NULL;
2103 /* If all location monitors disabled, disable global Location Monitor */
2104 if ((lm_en & (TSI148_LCSR_INTS_LM0S | TSI148_LCSR_INTS_LM1S |
2105 TSI148_LCSR_INTS_LM2S | TSI148_LCSR_INTS_LM3S)) == 0) {
2106 tmp = ioread32be(bridge->base + TSI148_LCSR_LMAT);
2107 tmp &= ~TSI148_LCSR_LMAT_EN;
2108 iowrite32be(tmp, bridge->base + TSI148_LCSR_LMAT);
2111 mutex_unlock(&lm->mtx);
2117 * Determine Geographical Addressing
2119 static int tsi148_slot_get(struct vme_bridge *tsi148_bridge)
2122 struct tsi148_driver *bridge;
2124 bridge = tsi148_bridge->driver_priv;
2127 slot = ioread32be(bridge->base + TSI148_LCSR_VSTAT);
2128 slot = slot & TSI148_LCSR_VSTAT_GA_M;
2135 static void *tsi148_alloc_consistent(struct device *parent, size_t size,
2138 struct pci_dev *pdev;
2140 /* Find pci_dev container of dev */
2141 pdev = to_pci_dev(parent);
2143 return dma_alloc_coherent(&pdev->dev, size, dma, GFP_KERNEL);
2146 static void tsi148_free_consistent(struct device *parent, size_t size,
2147 void *vaddr, dma_addr_t dma)
2149 struct pci_dev *pdev;
2151 /* Find pci_dev container of dev */
2152 pdev = to_pci_dev(parent);
2154 dma_free_coherent(&pdev->dev, size, vaddr, dma);
2158 * Configure CR/CSR space
2160 * Access to the CR/CSR can be configured at power-up. The location of the
2161 * CR/CSR registers in the CR/CSR address space is determined by the boards
2162 * Auto-ID or Geographic address. This function ensures that the window is
2163 * enabled at an offset consistent with the boards geopgraphic address.
2165 * Each board has a 512kB window, with the highest 4kB being used for the
2166 * boards registers, this means there is a fix length 508kB window which must
2167 * be mapped onto PCI memory.
2169 static int tsi148_crcsr_init(struct vme_bridge *tsi148_bridge,
2170 struct pci_dev *pdev)
2172 u32 cbar, crat, vstat;
2173 u32 crcsr_bus_high, crcsr_bus_low;
2175 struct tsi148_driver *bridge;
2177 bridge = tsi148_bridge->driver_priv;
2179 /* Allocate mem for CR/CSR image */
2180 bridge->crcsr_kernel = dma_alloc_coherent(&pdev->dev,
2182 &bridge->crcsr_bus, GFP_KERNEL);
2183 if (!bridge->crcsr_kernel) {
2184 dev_err(tsi148_bridge->parent, "Failed to allocate memory for CR/CSR image\n");
2188 reg_split(bridge->crcsr_bus, &crcsr_bus_high, &crcsr_bus_low);
2190 iowrite32be(crcsr_bus_high, bridge->base + TSI148_LCSR_CROU);
2191 iowrite32be(crcsr_bus_low, bridge->base + TSI148_LCSR_CROL);
2193 /* Ensure that the CR/CSR is configured at the correct offset */
2194 cbar = ioread32be(bridge->base + TSI148_CBAR);
2195 cbar = (cbar & TSI148_CRCSR_CBAR_M)>>3;
2197 vstat = tsi148_slot_get(tsi148_bridge);
2199 if (cbar != vstat) {
2201 dev_info(tsi148_bridge->parent, "Setting CR/CSR offset\n");
2202 iowrite32be(cbar<<3, bridge->base + TSI148_CBAR);
2204 dev_info(tsi148_bridge->parent, "CR/CSR Offset: %d\n", cbar);
2206 crat = ioread32be(bridge->base + TSI148_LCSR_CRAT);
2207 if (crat & TSI148_LCSR_CRAT_EN)
2208 dev_info(tsi148_bridge->parent, "CR/CSR already enabled\n");
2210 dev_info(tsi148_bridge->parent, "Enabling CR/CSR space\n");
2211 iowrite32be(crat | TSI148_LCSR_CRAT_EN,
2212 bridge->base + TSI148_LCSR_CRAT);
2215 /* If we want flushed, error-checked writes, set up a window
2216 * over the CR/CSR registers. We read from here to safely flush
2217 * through VME writes.
2220 retval = tsi148_master_set(bridge->flush_image, 1,
2221 (vstat * 0x80000), 0x80000, VME_CRCSR, VME_SCT,
2224 dev_err(tsi148_bridge->parent, "Configuring flush image failed\n");
2231 static void tsi148_crcsr_exit(struct vme_bridge *tsi148_bridge,
2232 struct pci_dev *pdev)
2235 struct tsi148_driver *bridge;
2237 bridge = tsi148_bridge->driver_priv;
2239 /* Turn off CR/CSR space */
2240 crat = ioread32be(bridge->base + TSI148_LCSR_CRAT);
2241 iowrite32be(crat & ~TSI148_LCSR_CRAT_EN,
2242 bridge->base + TSI148_LCSR_CRAT);
2245 iowrite32be(0, bridge->base + TSI148_LCSR_CROU);
2246 iowrite32be(0, bridge->base + TSI148_LCSR_CROL);
2248 dma_free_coherent(&pdev->dev, VME_CRCSR_BUF_SIZE,
2249 bridge->crcsr_kernel, bridge->crcsr_bus);
2252 static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2254 int retval, i, master_num;
2256 struct list_head *pos = NULL, *n;
2257 struct vme_bridge *tsi148_bridge;
2258 struct tsi148_driver *tsi148_device;
2259 struct vme_master_resource *master_image;
2260 struct vme_slave_resource *slave_image;
2261 struct vme_dma_resource *dma_ctrlr;
2262 struct vme_lm_resource *lm;
2264 /* If we want to support more than one of each bridge, we need to
2265 * dynamically generate this so we get one per device
2267 tsi148_bridge = kzalloc(sizeof(*tsi148_bridge), GFP_KERNEL);
2268 if (!tsi148_bridge) {
2272 vme_init_bridge(tsi148_bridge);
2274 tsi148_device = kzalloc(sizeof(*tsi148_device), GFP_KERNEL);
2275 if (!tsi148_device) {
2280 tsi148_bridge->driver_priv = tsi148_device;
2282 /* Enable the device */
2283 retval = pci_enable_device(pdev);
2285 dev_err(&pdev->dev, "Unable to enable device\n");
2290 retval = pci_request_regions(pdev, driver_name);
2292 dev_err(&pdev->dev, "Unable to reserve resources\n");
2296 /* map registers in BAR 0 */
2297 tsi148_device->base = ioremap(pci_resource_start(pdev, 0),
2299 if (!tsi148_device->base) {
2300 dev_err(&pdev->dev, "Unable to remap CRG region\n");
2305 /* Check to see if the mapping worked out */
2306 data = ioread32(tsi148_device->base + TSI148_PCFS_ID) & 0x0000FFFF;
2307 if (data != PCI_VENDOR_ID_TUNDRA) {
2308 dev_err(&pdev->dev, "CRG region check failed\n");
2313 /* Initialize wait queues & mutual exclusion flags */
2314 init_waitqueue_head(&tsi148_device->dma_queue[0]);
2315 init_waitqueue_head(&tsi148_device->dma_queue[1]);
2316 init_waitqueue_head(&tsi148_device->iack_queue);
2317 mutex_init(&tsi148_device->vme_int);
2318 mutex_init(&tsi148_device->vme_rmw);
2320 tsi148_bridge->parent = &pdev->dev;
2321 strcpy(tsi148_bridge->name, driver_name);
2324 retval = tsi148_irq_init(tsi148_bridge);
2326 dev_err(&pdev->dev, "Chip Initialization failed.\n");
2330 /* If we are going to flush writes, we need to read from the VME bus.
2331 * We need to do this safely, thus we read the devices own CR/CSR
2332 * register. To do this we must set up a window in CR/CSR space and
2333 * hence have one less master window resource available.
2335 master_num = TSI148_MAX_MASTER;
2339 tsi148_device->flush_image =
2340 kmalloc(sizeof(*tsi148_device->flush_image),
2342 if (!tsi148_device->flush_image) {
2346 tsi148_device->flush_image->parent = tsi148_bridge;
2347 spin_lock_init(&tsi148_device->flush_image->lock);
2348 tsi148_device->flush_image->locked = 1;
2349 tsi148_device->flush_image->number = master_num;
2350 memset(&tsi148_device->flush_image->bus_resource, 0,
2351 sizeof(tsi148_device->flush_image->bus_resource));
2352 tsi148_device->flush_image->kern_base = NULL;
2355 /* Add master windows to list */
2356 for (i = 0; i < master_num; i++) {
2357 master_image = kmalloc(sizeof(*master_image), GFP_KERNEL);
2358 if (!master_image) {
2362 master_image->parent = tsi148_bridge;
2363 spin_lock_init(&master_image->lock);
2364 master_image->locked = 0;
2365 master_image->number = i;
2366 master_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
2367 VME_A64 | VME_CRCSR | VME_USER1 | VME_USER2 |
2368 VME_USER3 | VME_USER4;
2369 master_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
2370 VME_2eVME | VME_2eSST | VME_2eSSTB | VME_2eSST160 |
2371 VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER |
2372 VME_PROG | VME_DATA;
2373 master_image->width_attr = VME_D16 | VME_D32;
2374 memset(&master_image->bus_resource, 0,
2375 sizeof(master_image->bus_resource));
2376 master_image->kern_base = NULL;
2377 list_add_tail(&master_image->list,
2378 &tsi148_bridge->master_resources);
2381 /* Add slave windows to list */
2382 for (i = 0; i < TSI148_MAX_SLAVE; i++) {
2383 slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL);
2388 slave_image->parent = tsi148_bridge;
2389 mutex_init(&slave_image->mtx);
2390 slave_image->locked = 0;
2391 slave_image->number = i;
2392 slave_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
2394 slave_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
2395 VME_2eVME | VME_2eSST | VME_2eSSTB | VME_2eSST160 |
2396 VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER |
2397 VME_PROG | VME_DATA;
2398 list_add_tail(&slave_image->list,
2399 &tsi148_bridge->slave_resources);
2402 /* Add dma engines to list */
2403 for (i = 0; i < TSI148_MAX_DMA; i++) {
2404 dma_ctrlr = kmalloc(sizeof(*dma_ctrlr), GFP_KERNEL);
2409 dma_ctrlr->parent = tsi148_bridge;
2410 mutex_init(&dma_ctrlr->mtx);
2411 dma_ctrlr->locked = 0;
2412 dma_ctrlr->number = i;
2413 dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM |
2414 VME_DMA_MEM_TO_VME | VME_DMA_VME_TO_VME |
2415 VME_DMA_MEM_TO_MEM | VME_DMA_PATTERN_TO_VME |
2416 VME_DMA_PATTERN_TO_MEM;
2417 INIT_LIST_HEAD(&dma_ctrlr->pending);
2418 INIT_LIST_HEAD(&dma_ctrlr->running);
2419 list_add_tail(&dma_ctrlr->list,
2420 &tsi148_bridge->dma_resources);
2423 /* Add location monitor to list */
2424 lm = kmalloc(sizeof(*lm), GFP_KERNEL);
2429 lm->parent = tsi148_bridge;
2430 mutex_init(&lm->mtx);
2434 list_add_tail(&lm->list, &tsi148_bridge->lm_resources);
2436 tsi148_bridge->slave_get = tsi148_slave_get;
2437 tsi148_bridge->slave_set = tsi148_slave_set;
2438 tsi148_bridge->master_get = tsi148_master_get;
2439 tsi148_bridge->master_set = tsi148_master_set;
2440 tsi148_bridge->master_read = tsi148_master_read;
2441 tsi148_bridge->master_write = tsi148_master_write;
2442 tsi148_bridge->master_rmw = tsi148_master_rmw;
2443 tsi148_bridge->dma_list_add = tsi148_dma_list_add;
2444 tsi148_bridge->dma_list_exec = tsi148_dma_list_exec;
2445 tsi148_bridge->dma_list_empty = tsi148_dma_list_empty;
2446 tsi148_bridge->irq_set = tsi148_irq_set;
2447 tsi148_bridge->irq_generate = tsi148_irq_generate;
2448 tsi148_bridge->lm_set = tsi148_lm_set;
2449 tsi148_bridge->lm_get = tsi148_lm_get;
2450 tsi148_bridge->lm_attach = tsi148_lm_attach;
2451 tsi148_bridge->lm_detach = tsi148_lm_detach;
2452 tsi148_bridge->slot_get = tsi148_slot_get;
2453 tsi148_bridge->alloc_consistent = tsi148_alloc_consistent;
2454 tsi148_bridge->free_consistent = tsi148_free_consistent;
2456 data = ioread32be(tsi148_device->base + TSI148_LCSR_VSTAT);
2457 dev_info(&pdev->dev, "Board is%s the VME system controller\n",
2458 (data & TSI148_LCSR_VSTAT_SCONS) ? "" : " not");
2460 dev_info(&pdev->dev, "VME geographical address is %d\n",
2461 data & TSI148_LCSR_VSTAT_GA_M);
2463 dev_info(&pdev->dev, "VME geographical address is set to %d\n",
2466 dev_info(&pdev->dev, "VME Write and flush and error check is %s\n",
2467 err_chk ? "enabled" : "disabled");
2469 retval = tsi148_crcsr_init(tsi148_bridge, pdev);
2471 dev_err(&pdev->dev, "CR/CSR configuration failed.\n");
2475 retval = vme_register_bridge(tsi148_bridge);
2477 dev_err(&pdev->dev, "Chip Registration failed.\n");
2481 pci_set_drvdata(pdev, tsi148_bridge);
2483 /* Clear VME bus "board fail", and "power-up reset" lines */
2484 data = ioread32be(tsi148_device->base + TSI148_LCSR_VSTAT);
2485 data &= ~TSI148_LCSR_VSTAT_BRDFL;
2486 data |= TSI148_LCSR_VSTAT_CPURST;
2487 iowrite32be(data, tsi148_device->base + TSI148_LCSR_VSTAT);
2492 tsi148_crcsr_exit(tsi148_bridge, pdev);
2495 /* resources are stored in link list */
2496 list_for_each_safe(pos, n, &tsi148_bridge->lm_resources) {
2497 lm = list_entry(pos, struct vme_lm_resource, list);
2502 /* resources are stored in link list */
2503 list_for_each_safe(pos, n, &tsi148_bridge->dma_resources) {
2504 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
2509 /* resources are stored in link list */
2510 list_for_each_safe(pos, n, &tsi148_bridge->slave_resources) {
2511 slave_image = list_entry(pos, struct vme_slave_resource, list);
2516 /* resources are stored in link list */
2517 list_for_each_safe(pos, n, &tsi148_bridge->master_resources) {
2518 master_image = list_entry(pos, struct vme_master_resource,
2521 kfree(master_image);
2524 tsi148_irq_exit(tsi148_bridge, pdev);
2527 iounmap(tsi148_device->base);
2529 pci_release_regions(pdev);
2531 pci_disable_device(pdev);
2533 kfree(tsi148_device);
2535 kfree(tsi148_bridge);
2541 static void tsi148_remove(struct pci_dev *pdev)
2543 struct list_head *pos = NULL;
2544 struct list_head *tmplist;
2545 struct vme_master_resource *master_image;
2546 struct vme_slave_resource *slave_image;
2547 struct vme_dma_resource *dma_ctrlr;
2549 struct tsi148_driver *bridge;
2550 struct vme_bridge *tsi148_bridge = pci_get_drvdata(pdev);
2552 bridge = tsi148_bridge->driver_priv;
2555 dev_dbg(&pdev->dev, "Driver is being unloaded.\n");
2558 * Shutdown all inbound and outbound windows.
2560 for (i = 0; i < 8; i++) {
2561 iowrite32be(0, bridge->base + TSI148_LCSR_IT[i] +
2562 TSI148_LCSR_OFFSET_ITAT);
2563 iowrite32be(0, bridge->base + TSI148_LCSR_OT[i] +
2564 TSI148_LCSR_OFFSET_OTAT);
2568 * Shutdown Location monitor.
2570 iowrite32be(0, bridge->base + TSI148_LCSR_LMAT);
2575 iowrite32be(0, bridge->base + TSI148_LCSR_CSRAT);
2578 * Clear error status.
2580 iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_EDPAT);
2581 iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_VEAT);
2582 iowrite32be(0x07000700, bridge->base + TSI148_LCSR_PSTAT);
2585 * Remove VIRQ interrupt (if any)
2587 if (ioread32be(bridge->base + TSI148_LCSR_VICR) & 0x800)
2588 iowrite32be(0x8000, bridge->base + TSI148_LCSR_VICR);
2591 * Map all Interrupts to PCI INTA
2593 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM1);
2594 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM2);
2596 tsi148_irq_exit(tsi148_bridge, pdev);
2598 vme_unregister_bridge(tsi148_bridge);
2600 tsi148_crcsr_exit(tsi148_bridge, pdev);
2602 /* resources are stored in link list */
2603 list_for_each_safe(pos, tmplist, &tsi148_bridge->dma_resources) {
2604 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
2609 /* resources are stored in link list */
2610 list_for_each_safe(pos, tmplist, &tsi148_bridge->slave_resources) {
2611 slave_image = list_entry(pos, struct vme_slave_resource, list);
2616 /* resources are stored in link list */
2617 list_for_each_safe(pos, tmplist, &tsi148_bridge->master_resources) {
2618 master_image = list_entry(pos, struct vme_master_resource,
2621 kfree(master_image);
2624 iounmap(bridge->base);
2626 pci_release_regions(pdev);
2628 pci_disable_device(pdev);
2630 kfree(tsi148_bridge->driver_priv);
2632 kfree(tsi148_bridge);
2635 module_pci_driver(tsi148_driver);
2637 MODULE_PARM_DESC(err_chk, "Check for VME errors on reads and writes");
2638 module_param(err_chk, bool, 0);
2640 MODULE_PARM_DESC(geoid, "Override geographical addressing");
2641 module_param(geoid, int, 0);
2643 MODULE_DESCRIPTION("VME driver for the Tundra Tempe VME bridge");
2644 MODULE_LICENSE("GPL");