2 * Support for the Tundra Universe I/II VME-PCI Bridge Chips
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 * Derived from ca91c042.c by Michael Wyrick
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/errno.h>
22 #include <linux/pci.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/poll.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>
34 #include "../vme_bridge.h"
35 #include "vme_ca91cx42.h"
37 static int __init ca91cx42_init(void);
38 static int ca91cx42_probe(struct pci_dev *, const struct pci_device_id *);
39 static void ca91cx42_remove(struct pci_dev *);
40 static void __exit ca91cx42_exit(void);
42 /* Module parameters */
45 static char driver_name[] = "vme_ca91cx42";
47 static const struct pci_device_id ca91cx42_ids[] = {
48 { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_CA91C142) },
52 static struct pci_driver ca91cx42_driver = {
54 .id_table = ca91cx42_ids,
55 .probe = ca91cx42_probe,
56 .remove = ca91cx42_remove,
59 static u32 ca91cx42_DMA_irqhandler(struct ca91cx42_driver *bridge)
61 wake_up(&(bridge->dma_queue));
63 return CA91CX42_LINT_DMA;
66 static u32 ca91cx42_LM_irqhandler(struct ca91cx42_driver *bridge, u32 stat)
71 for (i = 0; i < 4; i++) {
72 if (stat & CA91CX42_LINT_LM[i]) {
73 /* We only enable interrupts if the callback is set */
74 bridge->lm_callback[i](i);
75 serviced |= CA91CX42_LINT_LM[i];
82 /* XXX This needs to be split into 4 queues */
83 static u32 ca91cx42_MB_irqhandler(struct ca91cx42_driver *bridge, int mbox_mask)
85 wake_up(&(bridge->mbox_queue));
87 return CA91CX42_LINT_MBOX;
90 static u32 ca91cx42_IACK_irqhandler(struct ca91cx42_driver *bridge)
92 wake_up(&(bridge->iack_queue));
94 return CA91CX42_LINT_SW_IACK;
97 static u32 ca91cx42_VERR_irqhandler(struct vme_bridge *ca91cx42_bridge)
100 struct ca91cx42_driver *bridge;
102 bridge = ca91cx42_bridge->driver_priv;
104 val = ioread32(bridge->base + DGCS);
106 if (!(val & 0x00000800)) {
107 dev_err(ca91cx42_bridge->parent, "ca91cx42_VERR_irqhandler DMA "
108 "Read Error DGCS=%08X\n", val);
111 return CA91CX42_LINT_VERR;
114 static u32 ca91cx42_LERR_irqhandler(struct vme_bridge *ca91cx42_bridge)
117 struct ca91cx42_driver *bridge;
119 bridge = ca91cx42_bridge->driver_priv;
121 val = ioread32(bridge->base + DGCS);
123 if (!(val & 0x00000800))
124 dev_err(ca91cx42_bridge->parent, "ca91cx42_LERR_irqhandler DMA "
125 "Read Error DGCS=%08X\n", val);
127 return CA91CX42_LINT_LERR;
131 static u32 ca91cx42_VIRQ_irqhandler(struct vme_bridge *ca91cx42_bridge,
134 int vec, i, serviced = 0;
135 struct ca91cx42_driver *bridge;
137 bridge = ca91cx42_bridge->driver_priv;
140 for (i = 7; i > 0; i--) {
141 if (stat & (1 << i)) {
142 vec = ioread32(bridge->base +
143 CA91CX42_V_STATID[i]) & 0xff;
145 vme_irq_handler(ca91cx42_bridge, i, vec);
147 serviced |= (1 << i);
154 static irqreturn_t ca91cx42_irqhandler(int irq, void *ptr)
156 u32 stat, enable, serviced = 0;
157 struct vme_bridge *ca91cx42_bridge;
158 struct ca91cx42_driver *bridge;
160 ca91cx42_bridge = ptr;
162 bridge = ca91cx42_bridge->driver_priv;
164 enable = ioread32(bridge->base + LINT_EN);
165 stat = ioread32(bridge->base + LINT_STAT);
167 /* Only look at unmasked interrupts */
173 if (stat & CA91CX42_LINT_DMA)
174 serviced |= ca91cx42_DMA_irqhandler(bridge);
175 if (stat & (CA91CX42_LINT_LM0 | CA91CX42_LINT_LM1 | CA91CX42_LINT_LM2 |
177 serviced |= ca91cx42_LM_irqhandler(bridge, stat);
178 if (stat & CA91CX42_LINT_MBOX)
179 serviced |= ca91cx42_MB_irqhandler(bridge, stat);
180 if (stat & CA91CX42_LINT_SW_IACK)
181 serviced |= ca91cx42_IACK_irqhandler(bridge);
182 if (stat & CA91CX42_LINT_VERR)
183 serviced |= ca91cx42_VERR_irqhandler(ca91cx42_bridge);
184 if (stat & CA91CX42_LINT_LERR)
185 serviced |= ca91cx42_LERR_irqhandler(ca91cx42_bridge);
186 if (stat & (CA91CX42_LINT_VIRQ1 | CA91CX42_LINT_VIRQ2 |
187 CA91CX42_LINT_VIRQ3 | CA91CX42_LINT_VIRQ4 |
188 CA91CX42_LINT_VIRQ5 | CA91CX42_LINT_VIRQ6 |
189 CA91CX42_LINT_VIRQ7))
190 serviced |= ca91cx42_VIRQ_irqhandler(ca91cx42_bridge, stat);
192 /* Clear serviced interrupts */
193 iowrite32(stat, bridge->base + LINT_STAT);
198 static int ca91cx42_irq_init(struct vme_bridge *ca91cx42_bridge)
201 struct pci_dev *pdev;
202 struct ca91cx42_driver *bridge;
204 bridge = ca91cx42_bridge->driver_priv;
207 pdev = container_of(ca91cx42_bridge->parent, struct pci_dev, dev);
209 /* Initialise list for VME bus errors */
210 INIT_LIST_HEAD(&(ca91cx42_bridge->vme_errors));
212 mutex_init(&(ca91cx42_bridge->irq_mtx));
214 /* Disable interrupts from PCI to VME */
215 iowrite32(0, bridge->base + VINT_EN);
217 /* Disable PCI interrupts */
218 iowrite32(0, bridge->base + LINT_EN);
219 /* Clear Any Pending PCI Interrupts */
220 iowrite32(0x00FFFFFF, bridge->base + LINT_STAT);
222 result = request_irq(pdev->irq, ca91cx42_irqhandler, IRQF_SHARED,
223 driver_name, ca91cx42_bridge);
225 dev_err(&pdev->dev, "Can't get assigned pci irq vector %02X\n",
230 /* Ensure all interrupts are mapped to PCI Interrupt 0 */
231 iowrite32(0, bridge->base + LINT_MAP0);
232 iowrite32(0, bridge->base + LINT_MAP1);
233 iowrite32(0, bridge->base + LINT_MAP2);
235 /* Enable DMA, mailbox & LM Interrupts */
236 tmp = CA91CX42_LINT_MBOX3 | CA91CX42_LINT_MBOX2 | CA91CX42_LINT_MBOX1 |
237 CA91CX42_LINT_MBOX0 | CA91CX42_LINT_SW_IACK |
238 CA91CX42_LINT_VERR | CA91CX42_LINT_LERR | CA91CX42_LINT_DMA;
240 iowrite32(tmp, bridge->base + LINT_EN);
245 static void ca91cx42_irq_exit(struct ca91cx42_driver *bridge,
246 struct pci_dev *pdev)
248 /* Disable interrupts from PCI to VME */
249 iowrite32(0, bridge->base + VINT_EN);
251 /* Disable PCI interrupts */
252 iowrite32(0, bridge->base + LINT_EN);
253 /* Clear Any Pending PCI Interrupts */
254 iowrite32(0x00FFFFFF, bridge->base + LINT_STAT);
256 free_irq(pdev->irq, pdev);
260 * Set up an VME interrupt
262 void ca91cx42_irq_set(struct vme_bridge *ca91cx42_bridge, int level, int state,
266 struct pci_dev *pdev;
268 struct ca91cx42_driver *bridge;
270 bridge = ca91cx42_bridge->driver_priv;
272 /* Enable IRQ level */
273 tmp = ioread32(bridge->base + LINT_EN);
276 tmp &= ~CA91CX42_LINT_VIRQ[level];
278 tmp |= CA91CX42_LINT_VIRQ[level];
280 iowrite32(tmp, bridge->base + LINT_EN);
282 if ((state == 0) && (sync != 0)) {
283 pdev = container_of(ca91cx42_bridge->parent, struct pci_dev,
286 synchronize_irq(pdev->irq);
290 int ca91cx42_irq_generate(struct vme_bridge *ca91cx42_bridge, int level,
294 struct ca91cx42_driver *bridge;
296 bridge = ca91cx42_bridge->driver_priv;
298 /* Universe can only generate even vectors */
302 mutex_lock(&(bridge->vme_int));
304 tmp = ioread32(bridge->base + VINT_EN);
307 iowrite32(statid << 24, bridge->base + STATID);
309 /* Assert VMEbus IRQ */
310 tmp = tmp | (1 << (level + 24));
311 iowrite32(tmp, bridge->base + VINT_EN);
314 wait_event_interruptible(bridge->iack_queue, 0);
316 /* Return interrupt to low state */
317 tmp = ioread32(bridge->base + VINT_EN);
318 tmp = tmp & ~(1 << (level + 24));
319 iowrite32(tmp, bridge->base + VINT_EN);
321 mutex_unlock(&(bridge->vme_int));
326 int ca91cx42_slave_set(struct vme_slave_resource *image, int enabled,
327 unsigned long long vme_base, unsigned long long size,
328 dma_addr_t pci_base, vme_address_t aspace, vme_cycle_t cycle)
330 unsigned int i, addr = 0, granularity;
331 unsigned int temp_ctl = 0;
332 unsigned int vme_bound, pci_offset;
333 struct vme_bridge *ca91cx42_bridge;
334 struct ca91cx42_driver *bridge;
336 ca91cx42_bridge = image->parent;
338 bridge = ca91cx42_bridge->driver_priv;
344 addr |= CA91CX42_VSI_CTL_VAS_A16;
347 addr |= CA91CX42_VSI_CTL_VAS_A24;
350 addr |= CA91CX42_VSI_CTL_VAS_A32;
353 addr |= CA91CX42_VSI_CTL_VAS_USER1;
356 addr |= CA91CX42_VSI_CTL_VAS_USER2;
363 dev_err(ca91cx42_bridge->parent, "Invalid address space\n");
369 * Bound address is a valid address for the window, adjust
372 vme_bound = vme_base + size;
373 pci_offset = pci_base - vme_base;
375 if ((i == 0) || (i == 4))
376 granularity = 0x1000;
378 granularity = 0x10000;
380 if (vme_base & (granularity - 1)) {
381 dev_err(ca91cx42_bridge->parent, "Invalid VME base "
385 if (vme_bound & (granularity - 1)) {
386 dev_err(ca91cx42_bridge->parent, "Invalid VME bound "
390 if (pci_offset & (granularity - 1)) {
391 dev_err(ca91cx42_bridge->parent, "Invalid PCI Offset "
396 /* Disable while we are mucking around */
397 temp_ctl = ioread32(bridge->base + CA91CX42_VSI_CTL[i]);
398 temp_ctl &= ~CA91CX42_VSI_CTL_EN;
399 iowrite32(temp_ctl, bridge->base + CA91CX42_VSI_CTL[i]);
402 iowrite32(vme_base, bridge->base + CA91CX42_VSI_BS[i]);
403 iowrite32(vme_bound, bridge->base + CA91CX42_VSI_BD[i]);
404 iowrite32(pci_offset, bridge->base + CA91CX42_VSI_TO[i]);
406 /* Setup address space */
407 temp_ctl &= ~CA91CX42_VSI_CTL_VAS_M;
410 /* Setup cycle types */
411 temp_ctl &= ~(CA91CX42_VSI_CTL_PGM_M | CA91CX42_VSI_CTL_SUPER_M);
412 if (cycle & VME_SUPER)
413 temp_ctl |= CA91CX42_VSI_CTL_SUPER_SUPR;
414 if (cycle & VME_USER)
415 temp_ctl |= CA91CX42_VSI_CTL_SUPER_NPRIV;
416 if (cycle & VME_PROG)
417 temp_ctl |= CA91CX42_VSI_CTL_PGM_PGM;
418 if (cycle & VME_DATA)
419 temp_ctl |= CA91CX42_VSI_CTL_PGM_DATA;
421 /* Write ctl reg without enable */
422 iowrite32(temp_ctl, bridge->base + CA91CX42_VSI_CTL[i]);
425 temp_ctl |= CA91CX42_VSI_CTL_EN;
427 iowrite32(temp_ctl, bridge->base + CA91CX42_VSI_CTL[i]);
432 int ca91cx42_slave_get(struct vme_slave_resource *image, int *enabled,
433 unsigned long long *vme_base, unsigned long long *size,
434 dma_addr_t *pci_base, vme_address_t *aspace, vme_cycle_t *cycle)
436 unsigned int i, granularity = 0, ctl = 0;
437 unsigned long long vme_bound, pci_offset;
438 struct ca91cx42_driver *bridge;
440 bridge = image->parent->driver_priv;
444 if ((i == 0) || (i == 4))
445 granularity = 0x1000;
447 granularity = 0x10000;
450 ctl = ioread32(bridge->base + CA91CX42_VSI_CTL[i]);
452 *vme_base = ioread32(bridge->base + CA91CX42_VSI_BS[i]);
453 vme_bound = ioread32(bridge->base + CA91CX42_VSI_BD[i]);
454 pci_offset = ioread32(bridge->base + CA91CX42_VSI_TO[i]);
456 *pci_base = (dma_addr_t)vme_base + pci_offset;
457 *size = (unsigned long long)((vme_bound - *vme_base) + granularity);
463 if (ctl & CA91CX42_VSI_CTL_EN)
466 if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_A16)
468 if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_A24)
470 if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_A32)
472 if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_USER1)
474 if ((ctl & CA91CX42_VSI_CTL_VAS_M) == CA91CX42_VSI_CTL_VAS_USER2)
477 if (ctl & CA91CX42_VSI_CTL_SUPER_SUPR)
479 if (ctl & CA91CX42_VSI_CTL_SUPER_NPRIV)
481 if (ctl & CA91CX42_VSI_CTL_PGM_PGM)
483 if (ctl & CA91CX42_VSI_CTL_PGM_DATA)
490 * Allocate and map PCI Resource
492 static int ca91cx42_alloc_resource(struct vme_master_resource *image,
493 unsigned long long size)
495 unsigned long long existing_size;
497 struct pci_dev *pdev;
498 struct vme_bridge *ca91cx42_bridge;
500 ca91cx42_bridge = image->parent;
502 /* Find pci_dev container of dev */
503 if (ca91cx42_bridge->parent == NULL) {
504 dev_err(ca91cx42_bridge->parent, "Dev entry NULL\n");
507 pdev = container_of(ca91cx42_bridge->parent, struct pci_dev, dev);
509 existing_size = (unsigned long long)(image->bus_resource.end -
510 image->bus_resource.start);
512 /* If the existing size is OK, return */
513 if (existing_size == (size - 1))
516 if (existing_size != 0) {
517 iounmap(image->kern_base);
518 image->kern_base = NULL;
519 if (image->bus_resource.name != NULL)
520 kfree(image->bus_resource.name);
521 release_resource(&(image->bus_resource));
522 memset(&(image->bus_resource), 0, sizeof(struct resource));
525 if (image->bus_resource.name == NULL) {
526 image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC);
527 if (image->bus_resource.name == NULL) {
528 dev_err(ca91cx42_bridge->parent, "Unable to allocate "
529 "memory for resource name\n");
535 sprintf((char *)image->bus_resource.name, "%s.%d",
536 ca91cx42_bridge->name, image->number);
538 image->bus_resource.start = 0;
539 image->bus_resource.end = (unsigned long)size;
540 image->bus_resource.flags = IORESOURCE_MEM;
542 retval = pci_bus_alloc_resource(pdev->bus,
543 &(image->bus_resource), size, size, PCIBIOS_MIN_MEM,
546 dev_err(ca91cx42_bridge->parent, "Failed to allocate mem "
547 "resource for window %d size 0x%lx start 0x%lx\n",
548 image->number, (unsigned long)size,
549 (unsigned long)image->bus_resource.start);
553 image->kern_base = ioremap_nocache(
554 image->bus_resource.start, size);
555 if (image->kern_base == NULL) {
556 dev_err(ca91cx42_bridge->parent, "Failed to remap resource\n");
563 iounmap(image->kern_base);
564 image->kern_base = NULL;
566 release_resource(&(image->bus_resource));
568 kfree(image->bus_resource.name);
569 memset(&(image->bus_resource), 0, sizeof(struct resource));
575 * Free and unmap PCI Resource
577 static void ca91cx42_free_resource(struct vme_master_resource *image)
579 iounmap(image->kern_base);
580 image->kern_base = NULL;
581 release_resource(&(image->bus_resource));
582 kfree(image->bus_resource.name);
583 memset(&(image->bus_resource), 0, sizeof(struct resource));
587 int ca91cx42_master_set(struct vme_master_resource *image, int enabled,
588 unsigned long long vme_base, unsigned long long size,
589 vme_address_t aspace, vme_cycle_t cycle, vme_width_t dwidth)
592 unsigned int i, granularity = 0;
593 unsigned int temp_ctl = 0;
594 unsigned long long pci_bound, vme_offset, pci_base;
595 struct vme_bridge *ca91cx42_bridge;
596 struct ca91cx42_driver *bridge;
598 ca91cx42_bridge = image->parent;
600 bridge = ca91cx42_bridge->driver_priv;
604 if ((i == 0) || (i == 4))
605 granularity = 0x1000;
607 granularity = 0x10000;
609 /* Verify input data */
610 if (vme_base & (granularity - 1)) {
611 dev_err(ca91cx42_bridge->parent, "Invalid VME Window "
616 if (size & (granularity - 1)) {
617 dev_err(ca91cx42_bridge->parent, "Invalid VME Window "
623 spin_lock(&(image->lock));
626 * Let's allocate the resource here rather than further up the stack as
627 * it avoids pushing loads of bus dependant stuff up the stack
629 retval = ca91cx42_alloc_resource(image, size);
631 spin_unlock(&(image->lock));
632 dev_err(ca91cx42_bridge->parent, "Unable to allocate memory "
633 "for resource name\n");
638 pci_base = (unsigned long long)image->bus_resource.start;
641 * Bound address is a valid address for the window, adjust
642 * according to window granularity.
644 pci_bound = pci_base + size;
645 vme_offset = vme_base - pci_base;
647 /* Disable while we are mucking around */
648 temp_ctl = ioread32(bridge->base + CA91CX42_LSI_CTL[i]);
649 temp_ctl &= ~CA91CX42_LSI_CTL_EN;
650 iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
652 /* Setup cycle types */
653 temp_ctl &= ~CA91CX42_LSI_CTL_VCT_M;
655 temp_ctl |= CA91CX42_LSI_CTL_VCT_BLT;
656 if (cycle & VME_MBLT)
657 temp_ctl |= CA91CX42_LSI_CTL_VCT_MBLT;
659 /* Setup data width */
660 temp_ctl &= ~CA91CX42_LSI_CTL_VDW_M;
663 temp_ctl |= CA91CX42_LSI_CTL_VDW_D8;
666 temp_ctl |= CA91CX42_LSI_CTL_VDW_D16;
669 temp_ctl |= CA91CX42_LSI_CTL_VDW_D32;
672 temp_ctl |= CA91CX42_LSI_CTL_VDW_D64;
675 spin_unlock(&(image->lock));
676 dev_err(ca91cx42_bridge->parent, "Invalid data width\n");
682 /* Setup address space */
683 temp_ctl &= ~CA91CX42_LSI_CTL_VAS_M;
686 temp_ctl |= CA91CX42_LSI_CTL_VAS_A16;
689 temp_ctl |= CA91CX42_LSI_CTL_VAS_A24;
692 temp_ctl |= CA91CX42_LSI_CTL_VAS_A32;
695 temp_ctl |= CA91CX42_LSI_CTL_VAS_CRCSR;
698 temp_ctl |= CA91CX42_LSI_CTL_VAS_USER1;
701 temp_ctl |= CA91CX42_LSI_CTL_VAS_USER2;
707 spin_unlock(&(image->lock));
708 dev_err(ca91cx42_bridge->parent, "Invalid address space\n");
714 temp_ctl &= ~(CA91CX42_LSI_CTL_PGM_M | CA91CX42_LSI_CTL_SUPER_M);
715 if (cycle & VME_SUPER)
716 temp_ctl |= CA91CX42_LSI_CTL_SUPER_SUPR;
717 if (cycle & VME_PROG)
718 temp_ctl |= CA91CX42_LSI_CTL_PGM_PGM;
721 iowrite32(pci_base, bridge->base + CA91CX42_LSI_BS[i]);
722 iowrite32(pci_bound, bridge->base + CA91CX42_LSI_BD[i]);
723 iowrite32(vme_offset, bridge->base + CA91CX42_LSI_TO[i]);
725 /* Write ctl reg without enable */
726 iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
729 temp_ctl |= CA91CX42_LSI_CTL_EN;
731 iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
733 spin_unlock(&(image->lock));
738 ca91cx42_free_resource(image);
744 int __ca91cx42_master_get(struct vme_master_resource *image, int *enabled,
745 unsigned long long *vme_base, unsigned long long *size,
746 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth)
749 unsigned long long pci_base, pci_bound, vme_offset;
750 struct ca91cx42_driver *bridge;
752 bridge = image->parent->driver_priv;
756 ctl = ioread32(bridge->base + CA91CX42_LSI_CTL[i]);
758 pci_base = ioread32(bridge->base + CA91CX42_LSI_BS[i]);
759 vme_offset = ioread32(bridge->base + CA91CX42_LSI_TO[i]);
760 pci_bound = ioread32(bridge->base + CA91CX42_LSI_BD[i]);
762 *vme_base = pci_base + vme_offset;
763 *size = (unsigned long long)(pci_bound - pci_base);
770 if (ctl & CA91CX42_LSI_CTL_EN)
773 /* Setup address space */
774 switch (ctl & CA91CX42_LSI_CTL_VAS_M) {
775 case CA91CX42_LSI_CTL_VAS_A16:
778 case CA91CX42_LSI_CTL_VAS_A24:
781 case CA91CX42_LSI_CTL_VAS_A32:
784 case CA91CX42_LSI_CTL_VAS_CRCSR:
787 case CA91CX42_LSI_CTL_VAS_USER1:
790 case CA91CX42_LSI_CTL_VAS_USER2:
795 /* XXX Not sure howto check for MBLT */
796 /* Setup cycle types */
797 if (ctl & CA91CX42_LSI_CTL_VCT_BLT)
802 if (ctl & CA91CX42_LSI_CTL_SUPER_SUPR)
807 if (ctl & CA91CX42_LSI_CTL_PGM_PGM)
812 /* Setup data width */
813 switch (ctl & CA91CX42_LSI_CTL_VDW_M) {
814 case CA91CX42_LSI_CTL_VDW_D8:
817 case CA91CX42_LSI_CTL_VDW_D16:
820 case CA91CX42_LSI_CTL_VDW_D32:
823 case CA91CX42_LSI_CTL_VDW_D64:
831 int ca91cx42_master_get(struct vme_master_resource *image, int *enabled,
832 unsigned long long *vme_base, unsigned long long *size,
833 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth)
837 spin_lock(&(image->lock));
839 retval = __ca91cx42_master_get(image, enabled, vme_base, size, aspace,
842 spin_unlock(&(image->lock));
847 ssize_t ca91cx42_master_read(struct vme_master_resource *image, void *buf,
848 size_t count, loff_t offset)
851 void *addr = image->kern_base + offset;
852 unsigned int done = 0;
853 unsigned int count32;
858 spin_lock(&(image->lock));
860 /* The following code handles VME address alignment problem
861 * in order to assure the maximal data width cycle.
862 * We cannot use memcpy_xxx directly here because it
863 * may cut data transfer in 8-bits cycles, thus making
864 * D16 cycle impossible.
865 * From the other hand, the bridge itself assures that
866 * maximal configured data cycle is used and splits it
867 * automatically for non-aligned addresses.
869 if ((int)addr & 0x1) {
870 *(u8 *)buf = ioread8(addr);
875 if ((int)addr & 0x2) {
876 if ((count - done) < 2) {
877 *(u8 *)(buf + done) = ioread8(addr + done);
881 *(u16 *)(buf + done) = ioread16(addr + done);
886 count32 = (count - done) & ~0x3;
888 memcpy_fromio(buf + done, addr + done, (unsigned int)count);
892 if ((count - done) & 0x2) {
893 *(u16 *)(buf + done) = ioread16(addr + done);
896 if ((count - done) & 0x1) {
897 *(u8 *)(buf + done) = ioread8(addr + done);
902 spin_unlock(&(image->lock));
907 ssize_t ca91cx42_master_write(struct vme_master_resource *image, void *buf,
908 size_t count, loff_t offset)
911 void *addr = image->kern_base + offset;
912 unsigned int done = 0;
913 unsigned int count32;
918 spin_lock(&(image->lock));
920 /* Here we apply for the same strategy we do in master_read
921 * function in order to assure D16 cycle when required.
923 if ((int)addr & 0x1) {
924 iowrite8(*(u8 *)buf, addr);
929 if ((int)addr & 0x2) {
930 if ((count - done) < 2) {
931 iowrite8(*(u8 *)(buf + done), addr + done);
935 iowrite16(*(u16 *)(buf + done), addr + done);
940 count32 = (count - done) & ~0x3;
942 memcpy_toio(addr + done, buf + done, count32);
946 if ((count - done) & 0x2) {
947 iowrite16(*(u16 *)(buf + done), addr + done);
950 if ((count - done) & 0x1) {
951 iowrite8(*(u8 *)(buf + done), addr + done);
957 spin_unlock(&(image->lock));
961 unsigned int ca91cx42_master_rmw(struct vme_master_resource *image,
962 unsigned int mask, unsigned int compare, unsigned int swap,
965 u32 pci_addr, result;
967 struct ca91cx42_driver *bridge;
970 bridge = image->parent->driver_priv;
971 dev = image->parent->parent;
973 /* Find the PCI address that maps to the desired VME address */
976 /* Locking as we can only do one of these at a time */
977 mutex_lock(&(bridge->vme_rmw));
980 spin_lock(&(image->lock));
982 pci_addr = (u32)image->kern_base + offset;
984 /* Address must be 4-byte aligned */
985 if (pci_addr & 0x3) {
986 dev_err(dev, "RMW Address not 4-byte aligned\n");
991 /* Ensure RMW Disabled whilst configuring */
992 iowrite32(0, bridge->base + SCYC_CTL);
994 /* Configure registers */
995 iowrite32(mask, bridge->base + SCYC_EN);
996 iowrite32(compare, bridge->base + SCYC_CMP);
997 iowrite32(swap, bridge->base + SCYC_SWP);
998 iowrite32(pci_addr, bridge->base + SCYC_ADDR);
1001 iowrite32(CA91CX42_SCYC_CTL_CYC_RMW, bridge->base + SCYC_CTL);
1003 /* Kick process off with a read to the required address. */
1004 result = ioread32(image->kern_base + offset);
1007 iowrite32(0, bridge->base + SCYC_CTL);
1010 spin_unlock(&(image->lock));
1012 mutex_unlock(&(bridge->vme_rmw));
1017 int ca91cx42_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
1018 struct vme_dma_attr *dest, size_t count)
1020 struct ca91cx42_dma_entry *entry, *prev;
1021 struct vme_dma_pci *pci_attr;
1022 struct vme_dma_vme *vme_attr;
1023 dma_addr_t desc_ptr;
1027 dev = list->parent->parent->parent;
1029 /* XXX descriptor must be aligned on 64-bit boundaries */
1030 entry = kmalloc(sizeof(struct ca91cx42_dma_entry), GFP_KERNEL);
1031 if (entry == NULL) {
1032 dev_err(dev, "Failed to allocate memory for dma resource "
1038 /* Test descriptor alignment */
1039 if ((unsigned long)&(entry->descriptor) & CA91CX42_DCPP_M) {
1040 dev_err(dev, "Descriptor not aligned to 16 byte boundary as "
1041 "required: %p\n", &(entry->descriptor));
1046 memset(&(entry->descriptor), 0, sizeof(struct ca91cx42_dma_descriptor));
1048 if (dest->type == VME_DMA_VME) {
1049 entry->descriptor.dctl |= CA91CX42_DCTL_L2V;
1050 vme_attr = dest->private;
1051 pci_attr = src->private;
1053 vme_attr = src->private;
1054 pci_attr = dest->private;
1057 /* Check we can do fullfill required attributes */
1058 if ((vme_attr->aspace & ~(VME_A16 | VME_A24 | VME_A32 | VME_USER1 |
1061 dev_err(dev, "Unsupported cycle type\n");
1066 if ((vme_attr->cycle & ~(VME_SCT | VME_BLT | VME_SUPER | VME_USER |
1067 VME_PROG | VME_DATA)) != 0) {
1069 dev_err(dev, "Unsupported cycle type\n");
1074 /* Check to see if we can fullfill source and destination */
1075 if (!(((src->type == VME_DMA_PCI) && (dest->type == VME_DMA_VME)) ||
1076 ((src->type == VME_DMA_VME) && (dest->type == VME_DMA_PCI)))) {
1078 dev_err(dev, "Cannot perform transfer with this "
1079 "source-destination combination\n");
1084 /* Setup cycle types */
1085 if (vme_attr->cycle & VME_BLT)
1086 entry->descriptor.dctl |= CA91CX42_DCTL_VCT_BLT;
1088 /* Setup data width */
1089 switch (vme_attr->dwidth) {
1091 entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D8;
1094 entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D16;
1097 entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D32;
1100 entry->descriptor.dctl |= CA91CX42_DCTL_VDW_D64;
1103 dev_err(dev, "Invalid data width\n");
1107 /* Setup address space */
1108 switch (vme_attr->aspace) {
1110 entry->descriptor.dctl |= CA91CX42_DCTL_VAS_A16;
1113 entry->descriptor.dctl |= CA91CX42_DCTL_VAS_A24;
1116 entry->descriptor.dctl |= CA91CX42_DCTL_VAS_A32;
1119 entry->descriptor.dctl |= CA91CX42_DCTL_VAS_USER1;
1122 entry->descriptor.dctl |= CA91CX42_DCTL_VAS_USER2;
1125 dev_err(dev, "Invalid address space\n");
1130 if (vme_attr->cycle & VME_SUPER)
1131 entry->descriptor.dctl |= CA91CX42_DCTL_SUPER_SUPR;
1132 if (vme_attr->cycle & VME_PROG)
1133 entry->descriptor.dctl |= CA91CX42_DCTL_PGM_PGM;
1135 entry->descriptor.dtbc = count;
1136 entry->descriptor.dla = pci_attr->address;
1137 entry->descriptor.dva = vme_attr->address;
1138 entry->descriptor.dcpp = CA91CX42_DCPP_NULL;
1141 list_add_tail(&(entry->list), &(list->entries));
1143 /* Fill out previous descriptors "Next Address" */
1144 if (entry->list.prev != &(list->entries)) {
1145 prev = list_entry(entry->list.prev, struct ca91cx42_dma_entry,
1147 /* We need the bus address for the pointer */
1148 desc_ptr = virt_to_bus(&(entry->descriptor));
1149 prev->descriptor.dcpp = desc_ptr & ~CA91CX42_DCPP_M;
1163 static int ca91cx42_dma_busy(struct vme_bridge *ca91cx42_bridge)
1166 struct ca91cx42_driver *bridge;
1168 bridge = ca91cx42_bridge->driver_priv;
1170 tmp = ioread32(bridge->base + DGCS);
1172 if (tmp & CA91CX42_DGCS_ACT)
1178 int ca91cx42_dma_list_exec(struct vme_dma_list *list)
1180 struct vme_dma_resource *ctrlr;
1181 struct ca91cx42_dma_entry *entry;
1183 dma_addr_t bus_addr;
1186 struct ca91cx42_driver *bridge;
1188 ctrlr = list->parent;
1190 bridge = ctrlr->parent->driver_priv;
1191 dev = ctrlr->parent->parent;
1193 mutex_lock(&(ctrlr->mtx));
1195 if (!(list_empty(&(ctrlr->running)))) {
1197 * XXX We have an active DMA transfer and currently haven't
1198 * sorted out the mechanism for "pending" DMA transfers.
1201 /* Need to add to pending here */
1202 mutex_unlock(&(ctrlr->mtx));
1205 list_add(&(list->list), &(ctrlr->running));
1208 /* Get first bus address and write into registers */
1209 entry = list_first_entry(&(list->entries), struct ca91cx42_dma_entry,
1212 bus_addr = virt_to_bus(&(entry->descriptor));
1214 mutex_unlock(&(ctrlr->mtx));
1216 iowrite32(0, bridge->base + DTBC);
1217 iowrite32(bus_addr & ~CA91CX42_DCPP_M, bridge->base + DCPP);
1219 /* Start the operation */
1220 val = ioread32(bridge->base + DGCS);
1222 /* XXX Could set VMEbus On and Off Counters here */
1223 val &= (CA91CX42_DGCS_VON_M | CA91CX42_DGCS_VOFF_M);
1225 val |= (CA91CX42_DGCS_CHAIN | CA91CX42_DGCS_STOP | CA91CX42_DGCS_HALT |
1226 CA91CX42_DGCS_DONE | CA91CX42_DGCS_LERR | CA91CX42_DGCS_VERR |
1227 CA91CX42_DGCS_PERR);
1229 iowrite32(val, bridge->base + DGCS);
1231 val |= CA91CX42_DGCS_GO;
1233 iowrite32(val, bridge->base + DGCS);
1235 wait_event_interruptible(bridge->dma_queue,
1236 ca91cx42_dma_busy(ctrlr->parent));
1239 * Read status register, this register is valid until we kick off a
1242 val = ioread32(bridge->base + DGCS);
1244 if (val & (CA91CX42_DGCS_LERR | CA91CX42_DGCS_VERR |
1245 CA91CX42_DGCS_PERR)) {
1247 dev_err(dev, "ca91c042: DMA Error. DGCS=%08X\n", val);
1248 val = ioread32(bridge->base + DCTL);
1251 /* Remove list from running list */
1252 mutex_lock(&(ctrlr->mtx));
1253 list_del(&(list->list));
1254 mutex_unlock(&(ctrlr->mtx));
1260 int ca91cx42_dma_list_empty(struct vme_dma_list *list)
1262 struct list_head *pos, *temp;
1263 struct ca91cx42_dma_entry *entry;
1265 /* detach and free each entry */
1266 list_for_each_safe(pos, temp, &(list->entries)) {
1268 entry = list_entry(pos, struct ca91cx42_dma_entry, list);
1276 * All 4 location monitors reside at the same base - this is therefore a
1277 * system wide configuration.
1279 * This does not enable the LM monitor - that should be done when the first
1280 * callback is attached and disabled when the last callback is removed.
1282 int ca91cx42_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1283 vme_address_t aspace, vme_cycle_t cycle)
1285 u32 temp_base, lm_ctl = 0;
1287 struct ca91cx42_driver *bridge;
1290 bridge = lm->parent->driver_priv;
1291 dev = lm->parent->parent;
1293 /* Check the alignment of the location monitor */
1294 temp_base = (u32)lm_base;
1295 if (temp_base & 0xffff) {
1296 dev_err(dev, "Location monitor must be aligned to 64KB "
1301 mutex_lock(&(lm->mtx));
1303 /* If we already have a callback attached, we can't move it! */
1304 for (i = 0; i < lm->monitors; i++) {
1305 if (bridge->lm_callback[i] != NULL) {
1306 mutex_unlock(&(lm->mtx));
1307 dev_err(dev, "Location monitor callback attached, "
1315 lm_ctl |= CA91CX42_LM_CTL_AS_A16;
1318 lm_ctl |= CA91CX42_LM_CTL_AS_A24;
1321 lm_ctl |= CA91CX42_LM_CTL_AS_A32;
1324 mutex_unlock(&(lm->mtx));
1325 dev_err(dev, "Invalid address space\n");
1330 if (cycle & VME_SUPER)
1331 lm_ctl |= CA91CX42_LM_CTL_SUPR;
1332 if (cycle & VME_USER)
1333 lm_ctl |= CA91CX42_LM_CTL_NPRIV;
1334 if (cycle & VME_PROG)
1335 lm_ctl |= CA91CX42_LM_CTL_PGM;
1336 if (cycle & VME_DATA)
1337 lm_ctl |= CA91CX42_LM_CTL_DATA;
1339 iowrite32(lm_base, bridge->base + LM_BS);
1340 iowrite32(lm_ctl, bridge->base + LM_CTL);
1342 mutex_unlock(&(lm->mtx));
1347 /* Get configuration of the callback monitor and return whether it is enabled
1350 int ca91cx42_lm_get(struct vme_lm_resource *lm, unsigned long long *lm_base,
1351 vme_address_t *aspace, vme_cycle_t *cycle)
1353 u32 lm_ctl, enabled = 0;
1354 struct ca91cx42_driver *bridge;
1356 bridge = lm->parent->driver_priv;
1358 mutex_lock(&(lm->mtx));
1360 *lm_base = (unsigned long long)ioread32(bridge->base + LM_BS);
1361 lm_ctl = ioread32(bridge->base + LM_CTL);
1363 if (lm_ctl & CA91CX42_LM_CTL_EN)
1366 if ((lm_ctl & CA91CX42_LM_CTL_AS_M) == CA91CX42_LM_CTL_AS_A16)
1368 if ((lm_ctl & CA91CX42_LM_CTL_AS_M) == CA91CX42_LM_CTL_AS_A24)
1370 if ((lm_ctl & CA91CX42_LM_CTL_AS_M) == CA91CX42_LM_CTL_AS_A32)
1374 if (lm_ctl & CA91CX42_LM_CTL_SUPR)
1375 *cycle |= VME_SUPER;
1376 if (lm_ctl & CA91CX42_LM_CTL_NPRIV)
1378 if (lm_ctl & CA91CX42_LM_CTL_PGM)
1380 if (lm_ctl & CA91CX42_LM_CTL_DATA)
1383 mutex_unlock(&(lm->mtx));
1389 * Attach a callback to a specific location monitor.
1391 * Callback will be passed the monitor triggered.
1393 int ca91cx42_lm_attach(struct vme_lm_resource *lm, int monitor,
1394 void (*callback)(int))
1397 struct ca91cx42_driver *bridge;
1400 bridge = lm->parent->driver_priv;
1401 dev = lm->parent->parent;
1403 mutex_lock(&(lm->mtx));
1405 /* Ensure that the location monitor is configured - need PGM or DATA */
1406 lm_ctl = ioread32(bridge->base + LM_CTL);
1407 if ((lm_ctl & (CA91CX42_LM_CTL_PGM | CA91CX42_LM_CTL_DATA)) == 0) {
1408 mutex_unlock(&(lm->mtx));
1409 dev_err(dev, "Location monitor not properly configured\n");
1413 /* Check that a callback isn't already attached */
1414 if (bridge->lm_callback[monitor] != NULL) {
1415 mutex_unlock(&(lm->mtx));
1416 dev_err(dev, "Existing callback attached\n");
1420 /* Attach callback */
1421 bridge->lm_callback[monitor] = callback;
1423 /* Enable Location Monitor interrupt */
1424 tmp = ioread32(bridge->base + LINT_EN);
1425 tmp |= CA91CX42_LINT_LM[monitor];
1426 iowrite32(tmp, bridge->base + LINT_EN);
1428 /* Ensure that global Location Monitor Enable set */
1429 if ((lm_ctl & CA91CX42_LM_CTL_EN) == 0) {
1430 lm_ctl |= CA91CX42_LM_CTL_EN;
1431 iowrite32(lm_ctl, bridge->base + LM_CTL);
1434 mutex_unlock(&(lm->mtx));
1440 * Detach a callback function forn a specific location monitor.
1442 int ca91cx42_lm_detach(struct vme_lm_resource *lm, int monitor)
1445 struct ca91cx42_driver *bridge;
1447 bridge = lm->parent->driver_priv;
1449 mutex_lock(&(lm->mtx));
1451 /* Disable Location Monitor and ensure previous interrupts are clear */
1452 tmp = ioread32(bridge->base + LINT_EN);
1453 tmp &= ~CA91CX42_LINT_LM[monitor];
1454 iowrite32(tmp, bridge->base + LINT_EN);
1456 iowrite32(CA91CX42_LINT_LM[monitor],
1457 bridge->base + LINT_STAT);
1459 /* Detach callback */
1460 bridge->lm_callback[monitor] = NULL;
1462 /* If all location monitors disabled, disable global Location Monitor */
1463 if ((tmp & (CA91CX42_LINT_LM0 | CA91CX42_LINT_LM1 | CA91CX42_LINT_LM2 |
1464 CA91CX42_LINT_LM3)) == 0) {
1465 tmp = ioread32(bridge->base + LM_CTL);
1466 tmp &= ~CA91CX42_LM_CTL_EN;
1467 iowrite32(tmp, bridge->base + LM_CTL);
1470 mutex_unlock(&(lm->mtx));
1475 int ca91cx42_slot_get(struct vme_bridge *ca91cx42_bridge)
1478 struct ca91cx42_driver *bridge;
1480 bridge = ca91cx42_bridge->driver_priv;
1483 slot = ioread32(bridge->base + VCSR_BS);
1484 slot = ((slot & CA91CX42_VCSR_BS_SLOT_M) >> 27);
1492 static int __init ca91cx42_init(void)
1494 return pci_register_driver(&ca91cx42_driver);
1498 * Configure CR/CSR space
1500 * Access to the CR/CSR can be configured at power-up. The location of the
1501 * CR/CSR registers in the CR/CSR address space is determined by the boards
1502 * Auto-ID or Geographic address. This function ensures that the window is
1503 * enabled at an offset consistent with the boards geopgraphic address.
1505 static int ca91cx42_crcsr_init(struct vme_bridge *ca91cx42_bridge,
1506 struct pci_dev *pdev)
1508 unsigned int crcsr_addr;
1510 struct ca91cx42_driver *bridge;
1512 bridge = ca91cx42_bridge->driver_priv;
1514 slot = ca91cx42_slot_get(ca91cx42_bridge);
1516 /* Write CSR Base Address if slot ID is supplied as a module param */
1518 iowrite32(geoid << 27, bridge->base + VCSR_BS);
1520 dev_info(&pdev->dev, "CR/CSR Offset: %d\n", slot);
1522 dev_err(&pdev->dev, "Slot number is unset, not configuring "
1527 /* Allocate mem for CR/CSR image */
1528 bridge->crcsr_kernel = pci_alloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
1529 &(bridge->crcsr_bus));
1530 if (bridge->crcsr_kernel == NULL) {
1531 dev_err(&pdev->dev, "Failed to allocate memory for CR/CSR "
1536 memset(bridge->crcsr_kernel, 0, VME_CRCSR_BUF_SIZE);
1538 crcsr_addr = slot * (512 * 1024);
1539 iowrite32(bridge->crcsr_bus - crcsr_addr, bridge->base + VCSR_TO);
1541 tmp = ioread32(bridge->base + VCSR_CTL);
1542 tmp |= CA91CX42_VCSR_CTL_EN;
1543 iowrite32(tmp, bridge->base + VCSR_CTL);
1548 static void ca91cx42_crcsr_exit(struct vme_bridge *ca91cx42_bridge,
1549 struct pci_dev *pdev)
1552 struct ca91cx42_driver *bridge;
1554 bridge = ca91cx42_bridge->driver_priv;
1556 /* Turn off CR/CSR space */
1557 tmp = ioread32(bridge->base + VCSR_CTL);
1558 tmp &= ~CA91CX42_VCSR_CTL_EN;
1559 iowrite32(tmp, bridge->base + VCSR_CTL);
1562 iowrite32(0, bridge->base + VCSR_TO);
1564 pci_free_consistent(pdev, VME_CRCSR_BUF_SIZE, bridge->crcsr_kernel,
1568 static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1572 struct list_head *pos = NULL;
1573 struct vme_bridge *ca91cx42_bridge;
1574 struct ca91cx42_driver *ca91cx42_device;
1575 struct vme_master_resource *master_image;
1576 struct vme_slave_resource *slave_image;
1577 struct vme_dma_resource *dma_ctrlr;
1578 struct vme_lm_resource *lm;
1580 /* We want to support more than one of each bridge so we need to
1581 * dynamically allocate the bridge structure
1583 ca91cx42_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL);
1585 if (ca91cx42_bridge == NULL) {
1586 dev_err(&pdev->dev, "Failed to allocate memory for device "
1592 ca91cx42_device = kzalloc(sizeof(struct ca91cx42_driver), GFP_KERNEL);
1594 if (ca91cx42_device == NULL) {
1595 dev_err(&pdev->dev, "Failed to allocate memory for device "
1601 ca91cx42_bridge->driver_priv = ca91cx42_device;
1603 /* Enable the device */
1604 retval = pci_enable_device(pdev);
1606 dev_err(&pdev->dev, "Unable to enable device\n");
1611 retval = pci_request_regions(pdev, driver_name);
1613 dev_err(&pdev->dev, "Unable to reserve resources\n");
1617 /* map registers in BAR 0 */
1618 ca91cx42_device->base = ioremap_nocache(pci_resource_start(pdev, 0),
1620 if (!ca91cx42_device->base) {
1621 dev_err(&pdev->dev, "Unable to remap CRG region\n");
1626 /* Check to see if the mapping worked out */
1627 data = ioread32(ca91cx42_device->base + CA91CX42_PCI_ID) & 0x0000FFFF;
1628 if (data != PCI_VENDOR_ID_TUNDRA) {
1629 dev_err(&pdev->dev, "PCI_ID check failed\n");
1634 /* Initialize wait queues & mutual exclusion flags */
1635 init_waitqueue_head(&(ca91cx42_device->dma_queue));
1636 init_waitqueue_head(&(ca91cx42_device->iack_queue));
1637 mutex_init(&(ca91cx42_device->vme_int));
1638 mutex_init(&(ca91cx42_device->vme_rmw));
1640 ca91cx42_bridge->parent = &(pdev->dev);
1641 strcpy(ca91cx42_bridge->name, driver_name);
1644 retval = ca91cx42_irq_init(ca91cx42_bridge);
1646 dev_err(&pdev->dev, "Chip Initialization failed.\n");
1650 /* Add master windows to list */
1651 INIT_LIST_HEAD(&(ca91cx42_bridge->master_resources));
1652 for (i = 0; i < CA91C142_MAX_MASTER; i++) {
1653 master_image = kmalloc(sizeof(struct vme_master_resource),
1655 if (master_image == NULL) {
1656 dev_err(&pdev->dev, "Failed to allocate memory for "
1657 "master resource structure\n");
1661 master_image->parent = ca91cx42_bridge;
1662 spin_lock_init(&(master_image->lock));
1663 master_image->locked = 0;
1664 master_image->number = i;
1665 master_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
1666 VME_CRCSR | VME_USER1 | VME_USER2;
1667 master_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
1668 VME_SUPER | VME_USER | VME_PROG | VME_DATA;
1669 master_image->width_attr = VME_D8 | VME_D16 | VME_D32 | VME_D64;
1670 memset(&(master_image->bus_resource), 0,
1671 sizeof(struct resource));
1672 master_image->kern_base = NULL;
1673 list_add_tail(&(master_image->list),
1674 &(ca91cx42_bridge->master_resources));
1677 /* Add slave windows to list */
1678 INIT_LIST_HEAD(&(ca91cx42_bridge->slave_resources));
1679 for (i = 0; i < CA91C142_MAX_SLAVE; i++) {
1680 slave_image = kmalloc(sizeof(struct vme_slave_resource),
1682 if (slave_image == NULL) {
1683 dev_err(&pdev->dev, "Failed to allocate memory for "
1684 "slave resource structure\n");
1688 slave_image->parent = ca91cx42_bridge;
1689 mutex_init(&(slave_image->mtx));
1690 slave_image->locked = 0;
1691 slave_image->number = i;
1692 slave_image->address_attr = VME_A24 | VME_A32 | VME_USER1 |
1695 /* Only windows 0 and 4 support A16 */
1696 if (i == 0 || i == 4)
1697 slave_image->address_attr |= VME_A16;
1699 slave_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
1700 VME_SUPER | VME_USER | VME_PROG | VME_DATA;
1701 list_add_tail(&(slave_image->list),
1702 &(ca91cx42_bridge->slave_resources));
1705 /* Add dma engines to list */
1706 INIT_LIST_HEAD(&(ca91cx42_bridge->dma_resources));
1707 for (i = 0; i < CA91C142_MAX_DMA; i++) {
1708 dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource),
1710 if (dma_ctrlr == NULL) {
1711 dev_err(&pdev->dev, "Failed to allocate memory for "
1712 "dma resource structure\n");
1716 dma_ctrlr->parent = ca91cx42_bridge;
1717 mutex_init(&(dma_ctrlr->mtx));
1718 dma_ctrlr->locked = 0;
1719 dma_ctrlr->number = i;
1720 dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM |
1722 INIT_LIST_HEAD(&(dma_ctrlr->pending));
1723 INIT_LIST_HEAD(&(dma_ctrlr->running));
1724 list_add_tail(&(dma_ctrlr->list),
1725 &(ca91cx42_bridge->dma_resources));
1728 /* Add location monitor to list */
1729 INIT_LIST_HEAD(&(ca91cx42_bridge->lm_resources));
1730 lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL);
1732 dev_err(&pdev->dev, "Failed to allocate memory for "
1733 "location monitor resource structure\n");
1737 lm->parent = ca91cx42_bridge;
1738 mutex_init(&(lm->mtx));
1742 list_add_tail(&(lm->list), &(ca91cx42_bridge->lm_resources));
1744 ca91cx42_bridge->slave_get = ca91cx42_slave_get;
1745 ca91cx42_bridge->slave_set = ca91cx42_slave_set;
1746 ca91cx42_bridge->master_get = ca91cx42_master_get;
1747 ca91cx42_bridge->master_set = ca91cx42_master_set;
1748 ca91cx42_bridge->master_read = ca91cx42_master_read;
1749 ca91cx42_bridge->master_write = ca91cx42_master_write;
1750 ca91cx42_bridge->master_rmw = ca91cx42_master_rmw;
1751 ca91cx42_bridge->dma_list_add = ca91cx42_dma_list_add;
1752 ca91cx42_bridge->dma_list_exec = ca91cx42_dma_list_exec;
1753 ca91cx42_bridge->dma_list_empty = ca91cx42_dma_list_empty;
1754 ca91cx42_bridge->irq_set = ca91cx42_irq_set;
1755 ca91cx42_bridge->irq_generate = ca91cx42_irq_generate;
1756 ca91cx42_bridge->lm_set = ca91cx42_lm_set;
1757 ca91cx42_bridge->lm_get = ca91cx42_lm_get;
1758 ca91cx42_bridge->lm_attach = ca91cx42_lm_attach;
1759 ca91cx42_bridge->lm_detach = ca91cx42_lm_detach;
1760 ca91cx42_bridge->slot_get = ca91cx42_slot_get;
1762 data = ioread32(ca91cx42_device->base + MISC_CTL);
1763 dev_info(&pdev->dev, "Board is%s the VME system controller\n",
1764 (data & CA91CX42_MISC_CTL_SYSCON) ? "" : " not");
1765 dev_info(&pdev->dev, "Slot ID is %d\n",
1766 ca91cx42_slot_get(ca91cx42_bridge));
1768 if (ca91cx42_crcsr_init(ca91cx42_bridge, pdev))
1769 dev_err(&pdev->dev, "CR/CSR configuration failed.\n");
1771 /* Need to save ca91cx42_bridge pointer locally in link list for use in
1774 retval = vme_register_bridge(ca91cx42_bridge);
1776 dev_err(&pdev->dev, "Chip Registration failed.\n");
1780 pci_set_drvdata(pdev, ca91cx42_bridge);
1784 vme_unregister_bridge(ca91cx42_bridge);
1786 ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
1788 /* resources are stored in link list */
1789 list_for_each(pos, &(ca91cx42_bridge->lm_resources)) {
1790 lm = list_entry(pos, struct vme_lm_resource, list);
1795 /* resources are stored in link list */
1796 list_for_each(pos, &(ca91cx42_bridge->dma_resources)) {
1797 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
1802 /* resources are stored in link list */
1803 list_for_each(pos, &(ca91cx42_bridge->slave_resources)) {
1804 slave_image = list_entry(pos, struct vme_slave_resource, list);
1809 /* resources are stored in link list */
1810 list_for_each(pos, &(ca91cx42_bridge->master_resources)) {
1811 master_image = list_entry(pos, struct vme_master_resource,
1814 kfree(master_image);
1817 ca91cx42_irq_exit(ca91cx42_device, pdev);
1820 iounmap(ca91cx42_device->base);
1822 pci_release_regions(pdev);
1824 pci_disable_device(pdev);
1826 kfree(ca91cx42_device);
1828 kfree(ca91cx42_bridge);
1834 void ca91cx42_remove(struct pci_dev *pdev)
1836 struct list_head *pos = NULL;
1837 struct vme_master_resource *master_image;
1838 struct vme_slave_resource *slave_image;
1839 struct vme_dma_resource *dma_ctrlr;
1840 struct vme_lm_resource *lm;
1841 struct ca91cx42_driver *bridge;
1842 struct vme_bridge *ca91cx42_bridge = pci_get_drvdata(pdev);
1844 bridge = ca91cx42_bridge->driver_priv;
1848 iowrite32(0, bridge->base + LINT_EN);
1850 /* Turn off the windows */
1851 iowrite32(0x00800000, bridge->base + LSI0_CTL);
1852 iowrite32(0x00800000, bridge->base + LSI1_CTL);
1853 iowrite32(0x00800000, bridge->base + LSI2_CTL);
1854 iowrite32(0x00800000, bridge->base + LSI3_CTL);
1855 iowrite32(0x00800000, bridge->base + LSI4_CTL);
1856 iowrite32(0x00800000, bridge->base + LSI5_CTL);
1857 iowrite32(0x00800000, bridge->base + LSI6_CTL);
1858 iowrite32(0x00800000, bridge->base + LSI7_CTL);
1859 iowrite32(0x00F00000, bridge->base + VSI0_CTL);
1860 iowrite32(0x00F00000, bridge->base + VSI1_CTL);
1861 iowrite32(0x00F00000, bridge->base + VSI2_CTL);
1862 iowrite32(0x00F00000, bridge->base + VSI3_CTL);
1863 iowrite32(0x00F00000, bridge->base + VSI4_CTL);
1864 iowrite32(0x00F00000, bridge->base + VSI5_CTL);
1865 iowrite32(0x00F00000, bridge->base + VSI6_CTL);
1866 iowrite32(0x00F00000, bridge->base + VSI7_CTL);
1868 vme_unregister_bridge(ca91cx42_bridge);
1870 ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
1872 /* resources are stored in link list */
1873 list_for_each(pos, &(ca91cx42_bridge->lm_resources)) {
1874 lm = list_entry(pos, struct vme_lm_resource, list);
1879 /* resources are stored in link list */
1880 list_for_each(pos, &(ca91cx42_bridge->dma_resources)) {
1881 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
1886 /* resources are stored in link list */
1887 list_for_each(pos, &(ca91cx42_bridge->slave_resources)) {
1888 slave_image = list_entry(pos, struct vme_slave_resource, list);
1893 /* resources are stored in link list */
1894 list_for_each(pos, &(ca91cx42_bridge->master_resources)) {
1895 master_image = list_entry(pos, struct vme_master_resource,
1898 kfree(master_image);
1901 ca91cx42_irq_exit(bridge, pdev);
1903 iounmap(bridge->base);
1905 pci_release_regions(pdev);
1907 pci_disable_device(pdev);
1909 kfree(ca91cx42_bridge);
1912 static void __exit ca91cx42_exit(void)
1914 pci_unregister_driver(&ca91cx42_driver);
1917 MODULE_PARM_DESC(geoid, "Override geographical addressing");
1918 module_param(geoid, int, 0);
1920 MODULE_DESCRIPTION("VME driver for the Tundra Universe II VME bridge");
1921 MODULE_LICENSE("GPL");
1923 module_init(ca91cx42_init);
1924 module_exit(ca91cx42_exit);