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>
32 #include <linux/vme.h>
34 #include "../vme_bridge.h"
35 #include "vme_ca91cx42.h"
37 static int ca91cx42_probe(struct pci_dev
*, const struct pci_device_id
*);
38 static void ca91cx42_remove(struct pci_dev
*);
40 /* Module parameters */
43 static const char driver_name
[] = "vme_ca91cx42";
45 static DEFINE_PCI_DEVICE_TABLE(ca91cx42_ids
) = {
46 { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA
, PCI_DEVICE_ID_TUNDRA_CA91C142
) },
50 static struct pci_driver ca91cx42_driver
= {
52 .id_table
= ca91cx42_ids
,
53 .probe
= ca91cx42_probe
,
54 .remove
= ca91cx42_remove
,
57 static u32
ca91cx42_DMA_irqhandler(struct ca91cx42_driver
*bridge
)
59 wake_up(&bridge
->dma_queue
);
61 return CA91CX42_LINT_DMA
;
64 static u32
ca91cx42_LM_irqhandler(struct ca91cx42_driver
*bridge
, u32 stat
)
69 for (i
= 0; i
< 4; i
++) {
70 if (stat
& CA91CX42_LINT_LM
[i
]) {
71 /* We only enable interrupts if the callback is set */
72 bridge
->lm_callback
[i
](i
);
73 serviced
|= CA91CX42_LINT_LM
[i
];
80 /* XXX This needs to be split into 4 queues */
81 static u32
ca91cx42_MB_irqhandler(struct ca91cx42_driver
*bridge
, int mbox_mask
)
83 wake_up(&bridge
->mbox_queue
);
85 return CA91CX42_LINT_MBOX
;
88 static u32
ca91cx42_IACK_irqhandler(struct ca91cx42_driver
*bridge
)
90 wake_up(&bridge
->iack_queue
);
92 return CA91CX42_LINT_SW_IACK
;
95 static u32
ca91cx42_VERR_irqhandler(struct vme_bridge
*ca91cx42_bridge
)
98 struct ca91cx42_driver
*bridge
;
100 bridge
= ca91cx42_bridge
->driver_priv
;
102 val
= ioread32(bridge
->base
+ DGCS
);
104 if (!(val
& 0x00000800)) {
105 dev_err(ca91cx42_bridge
->parent
, "ca91cx42_VERR_irqhandler DMA "
106 "Read Error DGCS=%08X\n", val
);
109 return CA91CX42_LINT_VERR
;
112 static u32
ca91cx42_LERR_irqhandler(struct vme_bridge
*ca91cx42_bridge
)
115 struct ca91cx42_driver
*bridge
;
117 bridge
= ca91cx42_bridge
->driver_priv
;
119 val
= ioread32(bridge
->base
+ DGCS
);
121 if (!(val
& 0x00000800))
122 dev_err(ca91cx42_bridge
->parent
, "ca91cx42_LERR_irqhandler DMA "
123 "Read Error DGCS=%08X\n", val
);
125 return CA91CX42_LINT_LERR
;
129 static u32
ca91cx42_VIRQ_irqhandler(struct vme_bridge
*ca91cx42_bridge
,
132 int vec
, i
, serviced
= 0;
133 struct ca91cx42_driver
*bridge
;
135 bridge
= ca91cx42_bridge
->driver_priv
;
138 for (i
= 7; i
> 0; i
--) {
139 if (stat
& (1 << i
)) {
140 vec
= ioread32(bridge
->base
+
141 CA91CX42_V_STATID
[i
]) & 0xff;
143 vme_irq_handler(ca91cx42_bridge
, i
, vec
);
145 serviced
|= (1 << i
);
152 static irqreturn_t
ca91cx42_irqhandler(int irq
, void *ptr
)
154 u32 stat
, enable
, serviced
= 0;
155 struct vme_bridge
*ca91cx42_bridge
;
156 struct ca91cx42_driver
*bridge
;
158 ca91cx42_bridge
= ptr
;
160 bridge
= ca91cx42_bridge
->driver_priv
;
162 enable
= ioread32(bridge
->base
+ LINT_EN
);
163 stat
= ioread32(bridge
->base
+ LINT_STAT
);
165 /* Only look at unmasked interrupts */
171 if (stat
& CA91CX42_LINT_DMA
)
172 serviced
|= ca91cx42_DMA_irqhandler(bridge
);
173 if (stat
& (CA91CX42_LINT_LM0
| CA91CX42_LINT_LM1
| CA91CX42_LINT_LM2
|
175 serviced
|= ca91cx42_LM_irqhandler(bridge
, stat
);
176 if (stat
& CA91CX42_LINT_MBOX
)
177 serviced
|= ca91cx42_MB_irqhandler(bridge
, stat
);
178 if (stat
& CA91CX42_LINT_SW_IACK
)
179 serviced
|= ca91cx42_IACK_irqhandler(bridge
);
180 if (stat
& CA91CX42_LINT_VERR
)
181 serviced
|= ca91cx42_VERR_irqhandler(ca91cx42_bridge
);
182 if (stat
& CA91CX42_LINT_LERR
)
183 serviced
|= ca91cx42_LERR_irqhandler(ca91cx42_bridge
);
184 if (stat
& (CA91CX42_LINT_VIRQ1
| CA91CX42_LINT_VIRQ2
|
185 CA91CX42_LINT_VIRQ3
| CA91CX42_LINT_VIRQ4
|
186 CA91CX42_LINT_VIRQ5
| CA91CX42_LINT_VIRQ6
|
187 CA91CX42_LINT_VIRQ7
))
188 serviced
|= ca91cx42_VIRQ_irqhandler(ca91cx42_bridge
, stat
);
190 /* Clear serviced interrupts */
191 iowrite32(serviced
, bridge
->base
+ LINT_STAT
);
196 static int ca91cx42_irq_init(struct vme_bridge
*ca91cx42_bridge
)
199 struct pci_dev
*pdev
;
200 struct ca91cx42_driver
*bridge
;
202 bridge
= ca91cx42_bridge
->driver_priv
;
205 pdev
= container_of(ca91cx42_bridge
->parent
, struct pci_dev
, dev
);
207 /* Initialise list for VME bus errors */
208 INIT_LIST_HEAD(&ca91cx42_bridge
->vme_errors
);
210 mutex_init(&ca91cx42_bridge
->irq_mtx
);
212 /* Disable interrupts from PCI to VME */
213 iowrite32(0, bridge
->base
+ VINT_EN
);
215 /* Disable PCI interrupts */
216 iowrite32(0, bridge
->base
+ LINT_EN
);
217 /* Clear Any Pending PCI Interrupts */
218 iowrite32(0x00FFFFFF, bridge
->base
+ LINT_STAT
);
220 result
= request_irq(pdev
->irq
, ca91cx42_irqhandler
, IRQF_SHARED
,
221 driver_name
, ca91cx42_bridge
);
223 dev_err(&pdev
->dev
, "Can't get assigned pci irq vector %02X\n",
228 /* Ensure all interrupts are mapped to PCI Interrupt 0 */
229 iowrite32(0, bridge
->base
+ LINT_MAP0
);
230 iowrite32(0, bridge
->base
+ LINT_MAP1
);
231 iowrite32(0, bridge
->base
+ LINT_MAP2
);
233 /* Enable DMA, mailbox & LM Interrupts */
234 tmp
= CA91CX42_LINT_MBOX3
| CA91CX42_LINT_MBOX2
| CA91CX42_LINT_MBOX1
|
235 CA91CX42_LINT_MBOX0
| CA91CX42_LINT_SW_IACK
|
236 CA91CX42_LINT_VERR
| CA91CX42_LINT_LERR
| CA91CX42_LINT_DMA
;
238 iowrite32(tmp
, bridge
->base
+ LINT_EN
);
243 static void ca91cx42_irq_exit(struct ca91cx42_driver
*bridge
,
244 struct pci_dev
*pdev
)
246 /* Disable interrupts from PCI to VME */
247 iowrite32(0, bridge
->base
+ VINT_EN
);
249 /* Disable PCI interrupts */
250 iowrite32(0, bridge
->base
+ LINT_EN
);
251 /* Clear Any Pending PCI Interrupts */
252 iowrite32(0x00FFFFFF, bridge
->base
+ LINT_STAT
);
254 free_irq(pdev
->irq
, pdev
);
257 static int ca91cx42_iack_received(struct ca91cx42_driver
*bridge
, int level
)
261 tmp
= ioread32(bridge
->base
+ LINT_STAT
);
263 if (tmp
& (1 << level
))
270 * Set up an VME interrupt
272 static void ca91cx42_irq_set(struct vme_bridge
*ca91cx42_bridge
, int level
,
276 struct pci_dev
*pdev
;
278 struct ca91cx42_driver
*bridge
;
280 bridge
= ca91cx42_bridge
->driver_priv
;
282 /* Enable IRQ level */
283 tmp
= ioread32(bridge
->base
+ LINT_EN
);
286 tmp
&= ~CA91CX42_LINT_VIRQ
[level
];
288 tmp
|= CA91CX42_LINT_VIRQ
[level
];
290 iowrite32(tmp
, bridge
->base
+ LINT_EN
);
292 if ((state
== 0) && (sync
!= 0)) {
293 pdev
= container_of(ca91cx42_bridge
->parent
, struct pci_dev
,
296 synchronize_irq(pdev
->irq
);
300 static int ca91cx42_irq_generate(struct vme_bridge
*ca91cx42_bridge
, int level
,
304 struct ca91cx42_driver
*bridge
;
306 bridge
= ca91cx42_bridge
->driver_priv
;
308 /* Universe can only generate even vectors */
312 mutex_lock(&bridge
->vme_int
);
314 tmp
= ioread32(bridge
->base
+ VINT_EN
);
317 iowrite32(statid
<< 24, bridge
->base
+ STATID
);
319 /* Assert VMEbus IRQ */
320 tmp
= tmp
| (1 << (level
+ 24));
321 iowrite32(tmp
, bridge
->base
+ VINT_EN
);
324 wait_event_interruptible(bridge
->iack_queue
,
325 ca91cx42_iack_received(bridge
, level
));
327 /* Return interrupt to low state */
328 tmp
= ioread32(bridge
->base
+ VINT_EN
);
329 tmp
= tmp
& ~(1 << (level
+ 24));
330 iowrite32(tmp
, bridge
->base
+ VINT_EN
);
332 mutex_unlock(&bridge
->vme_int
);
337 static int ca91cx42_slave_set(struct vme_slave_resource
*image
, int enabled
,
338 unsigned long long vme_base
, unsigned long long size
,
339 dma_addr_t pci_base
, u32 aspace
, u32 cycle
)
341 unsigned int i
, addr
= 0, granularity
;
342 unsigned int temp_ctl
= 0;
343 unsigned int vme_bound
, pci_offset
;
344 struct vme_bridge
*ca91cx42_bridge
;
345 struct ca91cx42_driver
*bridge
;
347 ca91cx42_bridge
= image
->parent
;
349 bridge
= ca91cx42_bridge
->driver_priv
;
355 addr
|= CA91CX42_VSI_CTL_VAS_A16
;
358 addr
|= CA91CX42_VSI_CTL_VAS_A24
;
361 addr
|= CA91CX42_VSI_CTL_VAS_A32
;
364 addr
|= CA91CX42_VSI_CTL_VAS_USER1
;
367 addr
|= CA91CX42_VSI_CTL_VAS_USER2
;
374 dev_err(ca91cx42_bridge
->parent
, "Invalid address space\n");
380 * Bound address is a valid address for the window, adjust
383 vme_bound
= vme_base
+ size
;
384 pci_offset
= pci_base
- vme_base
;
386 if ((i
== 0) || (i
== 4))
387 granularity
= 0x1000;
389 granularity
= 0x10000;
391 if (vme_base
& (granularity
- 1)) {
392 dev_err(ca91cx42_bridge
->parent
, "Invalid VME base "
396 if (vme_bound
& (granularity
- 1)) {
397 dev_err(ca91cx42_bridge
->parent
, "Invalid VME bound "
401 if (pci_offset
& (granularity
- 1)) {
402 dev_err(ca91cx42_bridge
->parent
, "Invalid PCI Offset "
407 /* Disable while we are mucking around */
408 temp_ctl
= ioread32(bridge
->base
+ CA91CX42_VSI_CTL
[i
]);
409 temp_ctl
&= ~CA91CX42_VSI_CTL_EN
;
410 iowrite32(temp_ctl
, bridge
->base
+ CA91CX42_VSI_CTL
[i
]);
413 iowrite32(vme_base
, bridge
->base
+ CA91CX42_VSI_BS
[i
]);
414 iowrite32(vme_bound
, bridge
->base
+ CA91CX42_VSI_BD
[i
]);
415 iowrite32(pci_offset
, bridge
->base
+ CA91CX42_VSI_TO
[i
]);
417 /* Setup address space */
418 temp_ctl
&= ~CA91CX42_VSI_CTL_VAS_M
;
421 /* Setup cycle types */
422 temp_ctl
&= ~(CA91CX42_VSI_CTL_PGM_M
| CA91CX42_VSI_CTL_SUPER_M
);
423 if (cycle
& VME_SUPER
)
424 temp_ctl
|= CA91CX42_VSI_CTL_SUPER_SUPR
;
425 if (cycle
& VME_USER
)
426 temp_ctl
|= CA91CX42_VSI_CTL_SUPER_NPRIV
;
427 if (cycle
& VME_PROG
)
428 temp_ctl
|= CA91CX42_VSI_CTL_PGM_PGM
;
429 if (cycle
& VME_DATA
)
430 temp_ctl
|= CA91CX42_VSI_CTL_PGM_DATA
;
432 /* Write ctl reg without enable */
433 iowrite32(temp_ctl
, bridge
->base
+ CA91CX42_VSI_CTL
[i
]);
436 temp_ctl
|= CA91CX42_VSI_CTL_EN
;
438 iowrite32(temp_ctl
, bridge
->base
+ CA91CX42_VSI_CTL
[i
]);
443 static int ca91cx42_slave_get(struct vme_slave_resource
*image
, int *enabled
,
444 unsigned long long *vme_base
, unsigned long long *size
,
445 dma_addr_t
*pci_base
, u32
*aspace
, u32
*cycle
)
447 unsigned int i
, granularity
= 0, ctl
= 0;
448 unsigned long long vme_bound
, pci_offset
;
449 struct ca91cx42_driver
*bridge
;
451 bridge
= image
->parent
->driver_priv
;
455 if ((i
== 0) || (i
== 4))
456 granularity
= 0x1000;
458 granularity
= 0x10000;
461 ctl
= ioread32(bridge
->base
+ CA91CX42_VSI_CTL
[i
]);
463 *vme_base
= ioread32(bridge
->base
+ CA91CX42_VSI_BS
[i
]);
464 vme_bound
= ioread32(bridge
->base
+ CA91CX42_VSI_BD
[i
]);
465 pci_offset
= ioread32(bridge
->base
+ CA91CX42_VSI_TO
[i
]);
467 *pci_base
= (dma_addr_t
)vme_base
+ pci_offset
;
468 *size
= (unsigned long long)((vme_bound
- *vme_base
) + granularity
);
474 if (ctl
& CA91CX42_VSI_CTL_EN
)
477 if ((ctl
& CA91CX42_VSI_CTL_VAS_M
) == CA91CX42_VSI_CTL_VAS_A16
)
479 if ((ctl
& CA91CX42_VSI_CTL_VAS_M
) == CA91CX42_VSI_CTL_VAS_A24
)
481 if ((ctl
& CA91CX42_VSI_CTL_VAS_M
) == CA91CX42_VSI_CTL_VAS_A32
)
483 if ((ctl
& CA91CX42_VSI_CTL_VAS_M
) == CA91CX42_VSI_CTL_VAS_USER1
)
485 if ((ctl
& CA91CX42_VSI_CTL_VAS_M
) == CA91CX42_VSI_CTL_VAS_USER2
)
488 if (ctl
& CA91CX42_VSI_CTL_SUPER_SUPR
)
490 if (ctl
& CA91CX42_VSI_CTL_SUPER_NPRIV
)
492 if (ctl
& CA91CX42_VSI_CTL_PGM_PGM
)
494 if (ctl
& CA91CX42_VSI_CTL_PGM_DATA
)
501 * Allocate and map PCI Resource
503 static int ca91cx42_alloc_resource(struct vme_master_resource
*image
,
504 unsigned long long size
)
506 unsigned long long existing_size
;
508 struct pci_dev
*pdev
;
509 struct vme_bridge
*ca91cx42_bridge
;
511 ca91cx42_bridge
= image
->parent
;
513 /* Find pci_dev container of dev */
514 if (ca91cx42_bridge
->parent
== NULL
) {
515 dev_err(ca91cx42_bridge
->parent
, "Dev entry NULL\n");
518 pdev
= container_of(ca91cx42_bridge
->parent
, struct pci_dev
, dev
);
520 existing_size
= (unsigned long long)(image
->bus_resource
.end
-
521 image
->bus_resource
.start
);
523 /* If the existing size is OK, return */
524 if (existing_size
== (size
- 1))
527 if (existing_size
!= 0) {
528 iounmap(image
->kern_base
);
529 image
->kern_base
= NULL
;
530 kfree(image
->bus_resource
.name
);
531 release_resource(&image
->bus_resource
);
532 memset(&image
->bus_resource
, 0, sizeof(struct resource
));
535 if (image
->bus_resource
.name
== NULL
) {
536 image
->bus_resource
.name
= kmalloc(VMENAMSIZ
+3, GFP_ATOMIC
);
537 if (image
->bus_resource
.name
== NULL
) {
538 dev_err(ca91cx42_bridge
->parent
, "Unable to allocate "
539 "memory for resource name\n");
545 sprintf((char *)image
->bus_resource
.name
, "%s.%d",
546 ca91cx42_bridge
->name
, image
->number
);
548 image
->bus_resource
.start
= 0;
549 image
->bus_resource
.end
= (unsigned long)size
;
550 image
->bus_resource
.flags
= IORESOURCE_MEM
;
552 retval
= pci_bus_alloc_resource(pdev
->bus
,
553 &image
->bus_resource
, size
, size
, PCIBIOS_MIN_MEM
,
556 dev_err(ca91cx42_bridge
->parent
, "Failed to allocate mem "
557 "resource for window %d size 0x%lx start 0x%lx\n",
558 image
->number
, (unsigned long)size
,
559 (unsigned long)image
->bus_resource
.start
);
563 image
->kern_base
= ioremap_nocache(
564 image
->bus_resource
.start
, size
);
565 if (image
->kern_base
== NULL
) {
566 dev_err(ca91cx42_bridge
->parent
, "Failed to remap resource\n");
574 release_resource(&image
->bus_resource
);
576 kfree(image
->bus_resource
.name
);
577 memset(&image
->bus_resource
, 0, sizeof(struct resource
));
583 * Free and unmap PCI Resource
585 static void ca91cx42_free_resource(struct vme_master_resource
*image
)
587 iounmap(image
->kern_base
);
588 image
->kern_base
= NULL
;
589 release_resource(&image
->bus_resource
);
590 kfree(image
->bus_resource
.name
);
591 memset(&image
->bus_resource
, 0, sizeof(struct resource
));
595 static int ca91cx42_master_set(struct vme_master_resource
*image
, int enabled
,
596 unsigned long long vme_base
, unsigned long long size
, u32 aspace
,
597 u32 cycle
, u32 dwidth
)
600 unsigned int i
, granularity
= 0;
601 unsigned int temp_ctl
= 0;
602 unsigned long long pci_bound
, vme_offset
, pci_base
;
603 struct vme_bridge
*ca91cx42_bridge
;
604 struct ca91cx42_driver
*bridge
;
606 ca91cx42_bridge
= image
->parent
;
608 bridge
= ca91cx42_bridge
->driver_priv
;
612 if ((i
== 0) || (i
== 4))
613 granularity
= 0x1000;
615 granularity
= 0x10000;
617 /* Verify input data */
618 if (vme_base
& (granularity
- 1)) {
619 dev_err(ca91cx42_bridge
->parent
, "Invalid VME Window "
624 if (size
& (granularity
- 1)) {
625 dev_err(ca91cx42_bridge
->parent
, "Invalid VME Window "
631 spin_lock(&image
->lock
);
634 * Let's allocate the resource here rather than further up the stack as
635 * it avoids pushing loads of bus dependent stuff up the stack
637 retval
= ca91cx42_alloc_resource(image
, size
);
639 spin_unlock(&image
->lock
);
640 dev_err(ca91cx42_bridge
->parent
, "Unable to allocate memory "
641 "for resource name\n");
646 pci_base
= (unsigned long long)image
->bus_resource
.start
;
649 * Bound address is a valid address for the window, adjust
650 * according to window granularity.
652 pci_bound
= pci_base
+ size
;
653 vme_offset
= vme_base
- pci_base
;
655 /* Disable while we are mucking around */
656 temp_ctl
= ioread32(bridge
->base
+ CA91CX42_LSI_CTL
[i
]);
657 temp_ctl
&= ~CA91CX42_LSI_CTL_EN
;
658 iowrite32(temp_ctl
, bridge
->base
+ CA91CX42_LSI_CTL
[i
]);
660 /* Setup cycle types */
661 temp_ctl
&= ~CA91CX42_LSI_CTL_VCT_M
;
663 temp_ctl
|= CA91CX42_LSI_CTL_VCT_BLT
;
664 if (cycle
& VME_MBLT
)
665 temp_ctl
|= CA91CX42_LSI_CTL_VCT_MBLT
;
667 /* Setup data width */
668 temp_ctl
&= ~CA91CX42_LSI_CTL_VDW_M
;
671 temp_ctl
|= CA91CX42_LSI_CTL_VDW_D8
;
674 temp_ctl
|= CA91CX42_LSI_CTL_VDW_D16
;
677 temp_ctl
|= CA91CX42_LSI_CTL_VDW_D32
;
680 temp_ctl
|= CA91CX42_LSI_CTL_VDW_D64
;
683 spin_unlock(&image
->lock
);
684 dev_err(ca91cx42_bridge
->parent
, "Invalid data width\n");
690 /* Setup address space */
691 temp_ctl
&= ~CA91CX42_LSI_CTL_VAS_M
;
694 temp_ctl
|= CA91CX42_LSI_CTL_VAS_A16
;
697 temp_ctl
|= CA91CX42_LSI_CTL_VAS_A24
;
700 temp_ctl
|= CA91CX42_LSI_CTL_VAS_A32
;
703 temp_ctl
|= CA91CX42_LSI_CTL_VAS_CRCSR
;
706 temp_ctl
|= CA91CX42_LSI_CTL_VAS_USER1
;
709 temp_ctl
|= CA91CX42_LSI_CTL_VAS_USER2
;
715 spin_unlock(&image
->lock
);
716 dev_err(ca91cx42_bridge
->parent
, "Invalid address space\n");
722 temp_ctl
&= ~(CA91CX42_LSI_CTL_PGM_M
| CA91CX42_LSI_CTL_SUPER_M
);
723 if (cycle
& VME_SUPER
)
724 temp_ctl
|= CA91CX42_LSI_CTL_SUPER_SUPR
;
725 if (cycle
& VME_PROG
)
726 temp_ctl
|= CA91CX42_LSI_CTL_PGM_PGM
;
729 iowrite32(pci_base
, bridge
->base
+ CA91CX42_LSI_BS
[i
]);
730 iowrite32(pci_bound
, bridge
->base
+ CA91CX42_LSI_BD
[i
]);
731 iowrite32(vme_offset
, bridge
->base
+ CA91CX42_LSI_TO
[i
]);
733 /* Write ctl reg without enable */
734 iowrite32(temp_ctl
, bridge
->base
+ CA91CX42_LSI_CTL
[i
]);
737 temp_ctl
|= CA91CX42_LSI_CTL_EN
;
739 iowrite32(temp_ctl
, bridge
->base
+ CA91CX42_LSI_CTL
[i
]);
741 spin_unlock(&image
->lock
);
746 ca91cx42_free_resource(image
);
752 static int __ca91cx42_master_get(struct vme_master_resource
*image
,
753 int *enabled
, unsigned long long *vme_base
, unsigned long long *size
,
754 u32
*aspace
, u32
*cycle
, u32
*dwidth
)
757 unsigned long long pci_base
, pci_bound
, vme_offset
;
758 struct ca91cx42_driver
*bridge
;
760 bridge
= image
->parent
->driver_priv
;
764 ctl
= ioread32(bridge
->base
+ CA91CX42_LSI_CTL
[i
]);
766 pci_base
= ioread32(bridge
->base
+ CA91CX42_LSI_BS
[i
]);
767 vme_offset
= ioread32(bridge
->base
+ CA91CX42_LSI_TO
[i
]);
768 pci_bound
= ioread32(bridge
->base
+ CA91CX42_LSI_BD
[i
]);
770 *vme_base
= pci_base
+ vme_offset
;
771 *size
= (unsigned long long)(pci_bound
- pci_base
);
778 if (ctl
& CA91CX42_LSI_CTL_EN
)
781 /* Setup address space */
782 switch (ctl
& CA91CX42_LSI_CTL_VAS_M
) {
783 case CA91CX42_LSI_CTL_VAS_A16
:
786 case CA91CX42_LSI_CTL_VAS_A24
:
789 case CA91CX42_LSI_CTL_VAS_A32
:
792 case CA91CX42_LSI_CTL_VAS_CRCSR
:
795 case CA91CX42_LSI_CTL_VAS_USER1
:
798 case CA91CX42_LSI_CTL_VAS_USER2
:
803 /* XXX Not sure howto check for MBLT */
804 /* Setup cycle types */
805 if (ctl
& CA91CX42_LSI_CTL_VCT_BLT
)
810 if (ctl
& CA91CX42_LSI_CTL_SUPER_SUPR
)
815 if (ctl
& CA91CX42_LSI_CTL_PGM_PGM
)
820 /* Setup data width */
821 switch (ctl
& CA91CX42_LSI_CTL_VDW_M
) {
822 case CA91CX42_LSI_CTL_VDW_D8
:
825 case CA91CX42_LSI_CTL_VDW_D16
:
828 case CA91CX42_LSI_CTL_VDW_D32
:
831 case CA91CX42_LSI_CTL_VDW_D64
:
839 static int ca91cx42_master_get(struct vme_master_resource
*image
, int *enabled
,
840 unsigned long long *vme_base
, unsigned long long *size
, u32
*aspace
,
841 u32
*cycle
, u32
*dwidth
)
845 spin_lock(&image
->lock
);
847 retval
= __ca91cx42_master_get(image
, enabled
, vme_base
, size
, aspace
,
850 spin_unlock(&image
->lock
);
855 static ssize_t
ca91cx42_master_read(struct vme_master_resource
*image
,
856 void *buf
, size_t count
, loff_t offset
)
859 void *addr
= image
->kern_base
+ offset
;
860 unsigned int done
= 0;
861 unsigned int count32
;
866 spin_lock(&image
->lock
);
868 /* The following code handles VME address alignment problem
869 * in order to assure the maximal data width cycle.
870 * We cannot use memcpy_xxx directly here because it
871 * may cut data transfer in 8-bits cycles, thus making
872 * D16 cycle impossible.
873 * From the other hand, the bridge itself assures that
874 * maximal configured data cycle is used and splits it
875 * automatically for non-aligned addresses.
877 if ((uintptr_t)addr
& 0x1) {
878 *(u8
*)buf
= ioread8(addr
);
883 if ((uintptr_t)addr
& 0x2) {
884 if ((count
- done
) < 2) {
885 *(u8
*)(buf
+ done
) = ioread8(addr
+ done
);
889 *(u16
*)(buf
+ done
) = ioread16(addr
+ done
);
894 count32
= (count
- done
) & ~0x3;
896 memcpy_fromio(buf
+ done
, addr
+ done
, (unsigned int)count
);
900 if ((count
- done
) & 0x2) {
901 *(u16
*)(buf
+ done
) = ioread16(addr
+ done
);
904 if ((count
- done
) & 0x1) {
905 *(u8
*)(buf
+ done
) = ioread8(addr
+ done
);
910 spin_unlock(&image
->lock
);
915 static ssize_t
ca91cx42_master_write(struct vme_master_resource
*image
,
916 void *buf
, size_t count
, loff_t offset
)
919 void *addr
= image
->kern_base
+ offset
;
920 unsigned int done
= 0;
921 unsigned int count32
;
926 spin_lock(&image
->lock
);
928 /* Here we apply for the same strategy we do in master_read
929 * function in order to assure D16 cycle when required.
931 if ((uintptr_t)addr
& 0x1) {
932 iowrite8(*(u8
*)buf
, addr
);
937 if ((uintptr_t)addr
& 0x2) {
938 if ((count
- done
) < 2) {
939 iowrite8(*(u8
*)(buf
+ done
), addr
+ done
);
943 iowrite16(*(u16
*)(buf
+ done
), addr
+ done
);
948 count32
= (count
- done
) & ~0x3;
950 memcpy_toio(addr
+ done
, buf
+ done
, count32
);
954 if ((count
- done
) & 0x2) {
955 iowrite16(*(u16
*)(buf
+ done
), addr
+ done
);
958 if ((count
- done
) & 0x1) {
959 iowrite8(*(u8
*)(buf
+ done
), addr
+ done
);
965 spin_unlock(&image
->lock
);
970 static unsigned int ca91cx42_master_rmw(struct vme_master_resource
*image
,
971 unsigned int mask
, unsigned int compare
, unsigned int swap
,
977 struct ca91cx42_driver
*bridge
;
980 bridge
= image
->parent
->driver_priv
;
981 dev
= image
->parent
->parent
;
983 /* Find the PCI address that maps to the desired VME address */
986 /* Locking as we can only do one of these at a time */
987 mutex_lock(&bridge
->vme_rmw
);
990 spin_lock(&image
->lock
);
992 pci_addr
= (uintptr_t)image
->kern_base
+ offset
;
994 /* Address must be 4-byte aligned */
995 if (pci_addr
& 0x3) {
996 dev_err(dev
, "RMW Address not 4-byte aligned\n");
1001 /* Ensure RMW Disabled whilst configuring */
1002 iowrite32(0, bridge
->base
+ SCYC_CTL
);
1004 /* Configure registers */
1005 iowrite32(mask
, bridge
->base
+ SCYC_EN
);
1006 iowrite32(compare
, bridge
->base
+ SCYC_CMP
);
1007 iowrite32(swap
, bridge
->base
+ SCYC_SWP
);
1008 iowrite32(pci_addr
, bridge
->base
+ SCYC_ADDR
);
1011 iowrite32(CA91CX42_SCYC_CTL_CYC_RMW
, bridge
->base
+ SCYC_CTL
);
1013 /* Kick process off with a read to the required address. */
1014 result
= ioread32(image
->kern_base
+ offset
);
1017 iowrite32(0, bridge
->base
+ SCYC_CTL
);
1020 spin_unlock(&image
->lock
);
1022 mutex_unlock(&bridge
->vme_rmw
);
1027 static int ca91cx42_dma_list_add(struct vme_dma_list
*list
,
1028 struct vme_dma_attr
*src
, struct vme_dma_attr
*dest
, size_t count
)
1030 struct ca91cx42_dma_entry
*entry
, *prev
;
1031 struct vme_dma_pci
*pci_attr
;
1032 struct vme_dma_vme
*vme_attr
;
1033 dma_addr_t desc_ptr
;
1037 dev
= list
->parent
->parent
->parent
;
1039 /* XXX descriptor must be aligned on 64-bit boundaries */
1040 entry
= kmalloc(sizeof(struct ca91cx42_dma_entry
), GFP_KERNEL
);
1041 if (entry
== NULL
) {
1042 dev_err(dev
, "Failed to allocate memory for dma resource "
1048 /* Test descriptor alignment */
1049 if ((unsigned long)&entry
->descriptor
& CA91CX42_DCPP_M
) {
1050 dev_err(dev
, "Descriptor not aligned to 16 byte boundary as "
1051 "required: %p\n", &entry
->descriptor
);
1056 memset(&entry
->descriptor
, 0, sizeof(struct ca91cx42_dma_descriptor
));
1058 if (dest
->type
== VME_DMA_VME
) {
1059 entry
->descriptor
.dctl
|= CA91CX42_DCTL_L2V
;
1060 vme_attr
= dest
->private;
1061 pci_attr
= src
->private;
1063 vme_attr
= src
->private;
1064 pci_attr
= dest
->private;
1067 /* Check we can do fulfill required attributes */
1068 if ((vme_attr
->aspace
& ~(VME_A16
| VME_A24
| VME_A32
| VME_USER1
|
1071 dev_err(dev
, "Unsupported cycle type\n");
1076 if ((vme_attr
->cycle
& ~(VME_SCT
| VME_BLT
| VME_SUPER
| VME_USER
|
1077 VME_PROG
| VME_DATA
)) != 0) {
1079 dev_err(dev
, "Unsupported cycle type\n");
1084 /* Check to see if we can fulfill source and destination */
1085 if (!(((src
->type
== VME_DMA_PCI
) && (dest
->type
== VME_DMA_VME
)) ||
1086 ((src
->type
== VME_DMA_VME
) && (dest
->type
== VME_DMA_PCI
)))) {
1088 dev_err(dev
, "Cannot perform transfer with this "
1089 "source-destination combination\n");
1094 /* Setup cycle types */
1095 if (vme_attr
->cycle
& VME_BLT
)
1096 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VCT_BLT
;
1098 /* Setup data width */
1099 switch (vme_attr
->dwidth
) {
1101 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VDW_D8
;
1104 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VDW_D16
;
1107 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VDW_D32
;
1110 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VDW_D64
;
1113 dev_err(dev
, "Invalid data width\n");
1117 /* Setup address space */
1118 switch (vme_attr
->aspace
) {
1120 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VAS_A16
;
1123 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VAS_A24
;
1126 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VAS_A32
;
1129 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VAS_USER1
;
1132 entry
->descriptor
.dctl
|= CA91CX42_DCTL_VAS_USER2
;
1135 dev_err(dev
, "Invalid address space\n");
1140 if (vme_attr
->cycle
& VME_SUPER
)
1141 entry
->descriptor
.dctl
|= CA91CX42_DCTL_SUPER_SUPR
;
1142 if (vme_attr
->cycle
& VME_PROG
)
1143 entry
->descriptor
.dctl
|= CA91CX42_DCTL_PGM_PGM
;
1145 entry
->descriptor
.dtbc
= count
;
1146 entry
->descriptor
.dla
= pci_attr
->address
;
1147 entry
->descriptor
.dva
= vme_attr
->address
;
1148 entry
->descriptor
.dcpp
= CA91CX42_DCPP_NULL
;
1151 list_add_tail(&entry
->list
, &list
->entries
);
1153 /* Fill out previous descriptors "Next Address" */
1154 if (entry
->list
.prev
!= &list
->entries
) {
1155 prev
= list_entry(entry
->list
.prev
, struct ca91cx42_dma_entry
,
1157 /* We need the bus address for the pointer */
1158 desc_ptr
= virt_to_bus(&entry
->descriptor
);
1159 prev
->descriptor
.dcpp
= desc_ptr
& ~CA91CX42_DCPP_M
;
1173 static int ca91cx42_dma_busy(struct vme_bridge
*ca91cx42_bridge
)
1176 struct ca91cx42_driver
*bridge
;
1178 bridge
= ca91cx42_bridge
->driver_priv
;
1180 tmp
= ioread32(bridge
->base
+ DGCS
);
1182 if (tmp
& CA91CX42_DGCS_ACT
)
1188 static int ca91cx42_dma_list_exec(struct vme_dma_list
*list
)
1190 struct vme_dma_resource
*ctrlr
;
1191 struct ca91cx42_dma_entry
*entry
;
1193 dma_addr_t bus_addr
;
1196 struct ca91cx42_driver
*bridge
;
1198 ctrlr
= list
->parent
;
1200 bridge
= ctrlr
->parent
->driver_priv
;
1201 dev
= ctrlr
->parent
->parent
;
1203 mutex_lock(&ctrlr
->mtx
);
1205 if (!(list_empty(&ctrlr
->running
))) {
1207 * XXX We have an active DMA transfer and currently haven't
1208 * sorted out the mechanism for "pending" DMA transfers.
1211 /* Need to add to pending here */
1212 mutex_unlock(&ctrlr
->mtx
);
1215 list_add(&list
->list
, &ctrlr
->running
);
1218 /* Get first bus address and write into registers */
1219 entry
= list_first_entry(&list
->entries
, struct ca91cx42_dma_entry
,
1222 bus_addr
= virt_to_bus(&entry
->descriptor
);
1224 mutex_unlock(&ctrlr
->mtx
);
1226 iowrite32(0, bridge
->base
+ DTBC
);
1227 iowrite32(bus_addr
& ~CA91CX42_DCPP_M
, bridge
->base
+ DCPP
);
1229 /* Start the operation */
1230 val
= ioread32(bridge
->base
+ DGCS
);
1232 /* XXX Could set VMEbus On and Off Counters here */
1233 val
&= (CA91CX42_DGCS_VON_M
| CA91CX42_DGCS_VOFF_M
);
1235 val
|= (CA91CX42_DGCS_CHAIN
| CA91CX42_DGCS_STOP
| CA91CX42_DGCS_HALT
|
1236 CA91CX42_DGCS_DONE
| CA91CX42_DGCS_LERR
| CA91CX42_DGCS_VERR
|
1237 CA91CX42_DGCS_PERR
);
1239 iowrite32(val
, bridge
->base
+ DGCS
);
1241 val
|= CA91CX42_DGCS_GO
;
1243 iowrite32(val
, bridge
->base
+ DGCS
);
1245 wait_event_interruptible(bridge
->dma_queue
,
1246 ca91cx42_dma_busy(ctrlr
->parent
));
1249 * Read status register, this register is valid until we kick off a
1252 val
= ioread32(bridge
->base
+ DGCS
);
1254 if (val
& (CA91CX42_DGCS_LERR
| CA91CX42_DGCS_VERR
|
1255 CA91CX42_DGCS_PERR
)) {
1257 dev_err(dev
, "ca91c042: DMA Error. DGCS=%08X\n", val
);
1258 val
= ioread32(bridge
->base
+ DCTL
);
1261 /* Remove list from running list */
1262 mutex_lock(&ctrlr
->mtx
);
1263 list_del(&list
->list
);
1264 mutex_unlock(&ctrlr
->mtx
);
1270 static int ca91cx42_dma_list_empty(struct vme_dma_list
*list
)
1272 struct list_head
*pos
, *temp
;
1273 struct ca91cx42_dma_entry
*entry
;
1275 /* detach and free each entry */
1276 list_for_each_safe(pos
, temp
, &list
->entries
) {
1278 entry
= list_entry(pos
, struct ca91cx42_dma_entry
, list
);
1286 * All 4 location monitors reside at the same base - this is therefore a
1287 * system wide configuration.
1289 * This does not enable the LM monitor - that should be done when the first
1290 * callback is attached and disabled when the last callback is removed.
1292 static int ca91cx42_lm_set(struct vme_lm_resource
*lm
,
1293 unsigned long long lm_base
, u32 aspace
, u32 cycle
)
1295 u32 temp_base
, lm_ctl
= 0;
1297 struct ca91cx42_driver
*bridge
;
1300 bridge
= lm
->parent
->driver_priv
;
1301 dev
= lm
->parent
->parent
;
1303 /* Check the alignment of the location monitor */
1304 temp_base
= (u32
)lm_base
;
1305 if (temp_base
& 0xffff) {
1306 dev_err(dev
, "Location monitor must be aligned to 64KB "
1311 mutex_lock(&lm
->mtx
);
1313 /* If we already have a callback attached, we can't move it! */
1314 for (i
= 0; i
< lm
->monitors
; i
++) {
1315 if (bridge
->lm_callback
[i
] != NULL
) {
1316 mutex_unlock(&lm
->mtx
);
1317 dev_err(dev
, "Location monitor callback attached, "
1325 lm_ctl
|= CA91CX42_LM_CTL_AS_A16
;
1328 lm_ctl
|= CA91CX42_LM_CTL_AS_A24
;
1331 lm_ctl
|= CA91CX42_LM_CTL_AS_A32
;
1334 mutex_unlock(&lm
->mtx
);
1335 dev_err(dev
, "Invalid address space\n");
1340 if (cycle
& VME_SUPER
)
1341 lm_ctl
|= CA91CX42_LM_CTL_SUPR
;
1342 if (cycle
& VME_USER
)
1343 lm_ctl
|= CA91CX42_LM_CTL_NPRIV
;
1344 if (cycle
& VME_PROG
)
1345 lm_ctl
|= CA91CX42_LM_CTL_PGM
;
1346 if (cycle
& VME_DATA
)
1347 lm_ctl
|= CA91CX42_LM_CTL_DATA
;
1349 iowrite32(lm_base
, bridge
->base
+ LM_BS
);
1350 iowrite32(lm_ctl
, bridge
->base
+ LM_CTL
);
1352 mutex_unlock(&lm
->mtx
);
1357 /* Get configuration of the callback monitor and return whether it is enabled
1360 static int ca91cx42_lm_get(struct vme_lm_resource
*lm
,
1361 unsigned long long *lm_base
, u32
*aspace
, u32
*cycle
)
1363 u32 lm_ctl
, enabled
= 0;
1364 struct ca91cx42_driver
*bridge
;
1366 bridge
= lm
->parent
->driver_priv
;
1368 mutex_lock(&lm
->mtx
);
1370 *lm_base
= (unsigned long long)ioread32(bridge
->base
+ LM_BS
);
1371 lm_ctl
= ioread32(bridge
->base
+ LM_CTL
);
1373 if (lm_ctl
& CA91CX42_LM_CTL_EN
)
1376 if ((lm_ctl
& CA91CX42_LM_CTL_AS_M
) == CA91CX42_LM_CTL_AS_A16
)
1378 if ((lm_ctl
& CA91CX42_LM_CTL_AS_M
) == CA91CX42_LM_CTL_AS_A24
)
1380 if ((lm_ctl
& CA91CX42_LM_CTL_AS_M
) == CA91CX42_LM_CTL_AS_A32
)
1384 if (lm_ctl
& CA91CX42_LM_CTL_SUPR
)
1385 *cycle
|= VME_SUPER
;
1386 if (lm_ctl
& CA91CX42_LM_CTL_NPRIV
)
1388 if (lm_ctl
& CA91CX42_LM_CTL_PGM
)
1390 if (lm_ctl
& CA91CX42_LM_CTL_DATA
)
1393 mutex_unlock(&lm
->mtx
);
1399 * Attach a callback to a specific location monitor.
1401 * Callback will be passed the monitor triggered.
1403 static int ca91cx42_lm_attach(struct vme_lm_resource
*lm
, int monitor
,
1404 void (*callback
)(int))
1407 struct ca91cx42_driver
*bridge
;
1410 bridge
= lm
->parent
->driver_priv
;
1411 dev
= lm
->parent
->parent
;
1413 mutex_lock(&lm
->mtx
);
1415 /* Ensure that the location monitor is configured - need PGM or DATA */
1416 lm_ctl
= ioread32(bridge
->base
+ LM_CTL
);
1417 if ((lm_ctl
& (CA91CX42_LM_CTL_PGM
| CA91CX42_LM_CTL_DATA
)) == 0) {
1418 mutex_unlock(&lm
->mtx
);
1419 dev_err(dev
, "Location monitor not properly configured\n");
1423 /* Check that a callback isn't already attached */
1424 if (bridge
->lm_callback
[monitor
] != NULL
) {
1425 mutex_unlock(&lm
->mtx
);
1426 dev_err(dev
, "Existing callback attached\n");
1430 /* Attach callback */
1431 bridge
->lm_callback
[monitor
] = callback
;
1433 /* Enable Location Monitor interrupt */
1434 tmp
= ioread32(bridge
->base
+ LINT_EN
);
1435 tmp
|= CA91CX42_LINT_LM
[monitor
];
1436 iowrite32(tmp
, bridge
->base
+ LINT_EN
);
1438 /* Ensure that global Location Monitor Enable set */
1439 if ((lm_ctl
& CA91CX42_LM_CTL_EN
) == 0) {
1440 lm_ctl
|= CA91CX42_LM_CTL_EN
;
1441 iowrite32(lm_ctl
, bridge
->base
+ LM_CTL
);
1444 mutex_unlock(&lm
->mtx
);
1450 * Detach a callback function forn a specific location monitor.
1452 static int ca91cx42_lm_detach(struct vme_lm_resource
*lm
, int monitor
)
1455 struct ca91cx42_driver
*bridge
;
1457 bridge
= lm
->parent
->driver_priv
;
1459 mutex_lock(&lm
->mtx
);
1461 /* Disable Location Monitor and ensure previous interrupts are clear */
1462 tmp
= ioread32(bridge
->base
+ LINT_EN
);
1463 tmp
&= ~CA91CX42_LINT_LM
[monitor
];
1464 iowrite32(tmp
, bridge
->base
+ LINT_EN
);
1466 iowrite32(CA91CX42_LINT_LM
[monitor
],
1467 bridge
->base
+ LINT_STAT
);
1469 /* Detach callback */
1470 bridge
->lm_callback
[monitor
] = NULL
;
1472 /* If all location monitors disabled, disable global Location Monitor */
1473 if ((tmp
& (CA91CX42_LINT_LM0
| CA91CX42_LINT_LM1
| CA91CX42_LINT_LM2
|
1474 CA91CX42_LINT_LM3
)) == 0) {
1475 tmp
= ioread32(bridge
->base
+ LM_CTL
);
1476 tmp
&= ~CA91CX42_LM_CTL_EN
;
1477 iowrite32(tmp
, bridge
->base
+ LM_CTL
);
1480 mutex_unlock(&lm
->mtx
);
1485 static int ca91cx42_slot_get(struct vme_bridge
*ca91cx42_bridge
)
1488 struct ca91cx42_driver
*bridge
;
1490 bridge
= ca91cx42_bridge
->driver_priv
;
1493 slot
= ioread32(bridge
->base
+ VCSR_BS
);
1494 slot
= ((slot
& CA91CX42_VCSR_BS_SLOT_M
) >> 27);
1502 static void *ca91cx42_alloc_consistent(struct device
*parent
, size_t size
,
1505 struct pci_dev
*pdev
;
1507 /* Find pci_dev container of dev */
1508 pdev
= container_of(parent
, struct pci_dev
, dev
);
1510 return pci_alloc_consistent(pdev
, size
, dma
);
1513 static void ca91cx42_free_consistent(struct device
*parent
, size_t size
,
1514 void *vaddr
, dma_addr_t dma
)
1516 struct pci_dev
*pdev
;
1518 /* Find pci_dev container of dev */
1519 pdev
= container_of(parent
, struct pci_dev
, dev
);
1521 pci_free_consistent(pdev
, size
, vaddr
, dma
);
1525 * Configure CR/CSR space
1527 * Access to the CR/CSR can be configured at power-up. The location of the
1528 * CR/CSR registers in the CR/CSR address space is determined by the boards
1529 * Auto-ID or Geographic address. This function ensures that the window is
1530 * enabled at an offset consistent with the boards geopgraphic address.
1532 static int ca91cx42_crcsr_init(struct vme_bridge
*ca91cx42_bridge
,
1533 struct pci_dev
*pdev
)
1535 unsigned int crcsr_addr
;
1537 struct ca91cx42_driver
*bridge
;
1539 bridge
= ca91cx42_bridge
->driver_priv
;
1541 slot
= ca91cx42_slot_get(ca91cx42_bridge
);
1543 /* Write CSR Base Address if slot ID is supplied as a module param */
1545 iowrite32(geoid
<< 27, bridge
->base
+ VCSR_BS
);
1547 dev_info(&pdev
->dev
, "CR/CSR Offset: %d\n", slot
);
1549 dev_err(&pdev
->dev
, "Slot number is unset, not configuring "
1554 /* Allocate mem for CR/CSR image */
1555 bridge
->crcsr_kernel
= pci_alloc_consistent(pdev
, VME_CRCSR_BUF_SIZE
,
1556 &bridge
->crcsr_bus
);
1557 if (bridge
->crcsr_kernel
== NULL
) {
1558 dev_err(&pdev
->dev
, "Failed to allocate memory for CR/CSR "
1563 memset(bridge
->crcsr_kernel
, 0, VME_CRCSR_BUF_SIZE
);
1565 crcsr_addr
= slot
* (512 * 1024);
1566 iowrite32(bridge
->crcsr_bus
- crcsr_addr
, bridge
->base
+ VCSR_TO
);
1568 tmp
= ioread32(bridge
->base
+ VCSR_CTL
);
1569 tmp
|= CA91CX42_VCSR_CTL_EN
;
1570 iowrite32(tmp
, bridge
->base
+ VCSR_CTL
);
1575 static void ca91cx42_crcsr_exit(struct vme_bridge
*ca91cx42_bridge
,
1576 struct pci_dev
*pdev
)
1579 struct ca91cx42_driver
*bridge
;
1581 bridge
= ca91cx42_bridge
->driver_priv
;
1583 /* Turn off CR/CSR space */
1584 tmp
= ioread32(bridge
->base
+ VCSR_CTL
);
1585 tmp
&= ~CA91CX42_VCSR_CTL_EN
;
1586 iowrite32(tmp
, bridge
->base
+ VCSR_CTL
);
1589 iowrite32(0, bridge
->base
+ VCSR_TO
);
1591 pci_free_consistent(pdev
, VME_CRCSR_BUF_SIZE
, bridge
->crcsr_kernel
,
1595 static int ca91cx42_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1599 struct list_head
*pos
= NULL
, *n
;
1600 struct vme_bridge
*ca91cx42_bridge
;
1601 struct ca91cx42_driver
*ca91cx42_device
;
1602 struct vme_master_resource
*master_image
;
1603 struct vme_slave_resource
*slave_image
;
1604 struct vme_dma_resource
*dma_ctrlr
;
1605 struct vme_lm_resource
*lm
;
1607 /* We want to support more than one of each bridge so we need to
1608 * dynamically allocate the bridge structure
1610 ca91cx42_bridge
= kzalloc(sizeof(struct vme_bridge
), GFP_KERNEL
);
1612 if (ca91cx42_bridge
== NULL
) {
1613 dev_err(&pdev
->dev
, "Failed to allocate memory for device "
1619 ca91cx42_device
= kzalloc(sizeof(struct ca91cx42_driver
), GFP_KERNEL
);
1621 if (ca91cx42_device
== NULL
) {
1622 dev_err(&pdev
->dev
, "Failed to allocate memory for device "
1628 ca91cx42_bridge
->driver_priv
= ca91cx42_device
;
1630 /* Enable the device */
1631 retval
= pci_enable_device(pdev
);
1633 dev_err(&pdev
->dev
, "Unable to enable device\n");
1638 retval
= pci_request_regions(pdev
, driver_name
);
1640 dev_err(&pdev
->dev
, "Unable to reserve resources\n");
1644 /* map registers in BAR 0 */
1645 ca91cx42_device
->base
= ioremap_nocache(pci_resource_start(pdev
, 0),
1647 if (!ca91cx42_device
->base
) {
1648 dev_err(&pdev
->dev
, "Unable to remap CRG region\n");
1653 /* Check to see if the mapping worked out */
1654 data
= ioread32(ca91cx42_device
->base
+ CA91CX42_PCI_ID
) & 0x0000FFFF;
1655 if (data
!= PCI_VENDOR_ID_TUNDRA
) {
1656 dev_err(&pdev
->dev
, "PCI_ID check failed\n");
1661 /* Initialize wait queues & mutual exclusion flags */
1662 init_waitqueue_head(&ca91cx42_device
->dma_queue
);
1663 init_waitqueue_head(&ca91cx42_device
->iack_queue
);
1664 mutex_init(&ca91cx42_device
->vme_int
);
1665 mutex_init(&ca91cx42_device
->vme_rmw
);
1667 ca91cx42_bridge
->parent
= &pdev
->dev
;
1668 strcpy(ca91cx42_bridge
->name
, driver_name
);
1671 retval
= ca91cx42_irq_init(ca91cx42_bridge
);
1673 dev_err(&pdev
->dev
, "Chip Initialization failed.\n");
1677 /* Add master windows to list */
1678 INIT_LIST_HEAD(&ca91cx42_bridge
->master_resources
);
1679 for (i
= 0; i
< CA91C142_MAX_MASTER
; i
++) {
1680 master_image
= kmalloc(sizeof(struct vme_master_resource
),
1682 if (master_image
== NULL
) {
1683 dev_err(&pdev
->dev
, "Failed to allocate memory for "
1684 "master resource structure\n");
1688 master_image
->parent
= ca91cx42_bridge
;
1689 spin_lock_init(&master_image
->lock
);
1690 master_image
->locked
= 0;
1691 master_image
->number
= i
;
1692 master_image
->address_attr
= VME_A16
| VME_A24
| VME_A32
|
1693 VME_CRCSR
| VME_USER1
| VME_USER2
;
1694 master_image
->cycle_attr
= VME_SCT
| VME_BLT
| VME_MBLT
|
1695 VME_SUPER
| VME_USER
| VME_PROG
| VME_DATA
;
1696 master_image
->width_attr
= VME_D8
| VME_D16
| VME_D32
| VME_D64
;
1697 memset(&master_image
->bus_resource
, 0,
1698 sizeof(struct resource
));
1699 master_image
->kern_base
= NULL
;
1700 list_add_tail(&master_image
->list
,
1701 &ca91cx42_bridge
->master_resources
);
1704 /* Add slave windows to list */
1705 INIT_LIST_HEAD(&ca91cx42_bridge
->slave_resources
);
1706 for (i
= 0; i
< CA91C142_MAX_SLAVE
; i
++) {
1707 slave_image
= kmalloc(sizeof(struct vme_slave_resource
),
1709 if (slave_image
== NULL
) {
1710 dev_err(&pdev
->dev
, "Failed to allocate memory for "
1711 "slave resource structure\n");
1715 slave_image
->parent
= ca91cx42_bridge
;
1716 mutex_init(&slave_image
->mtx
);
1717 slave_image
->locked
= 0;
1718 slave_image
->number
= i
;
1719 slave_image
->address_attr
= VME_A24
| VME_A32
| VME_USER1
|
1722 /* Only windows 0 and 4 support A16 */
1723 if (i
== 0 || i
== 4)
1724 slave_image
->address_attr
|= VME_A16
;
1726 slave_image
->cycle_attr
= VME_SCT
| VME_BLT
| VME_MBLT
|
1727 VME_SUPER
| VME_USER
| VME_PROG
| VME_DATA
;
1728 list_add_tail(&slave_image
->list
,
1729 &ca91cx42_bridge
->slave_resources
);
1732 /* Add dma engines to list */
1733 INIT_LIST_HEAD(&ca91cx42_bridge
->dma_resources
);
1734 for (i
= 0; i
< CA91C142_MAX_DMA
; i
++) {
1735 dma_ctrlr
= kmalloc(sizeof(struct vme_dma_resource
),
1737 if (dma_ctrlr
== NULL
) {
1738 dev_err(&pdev
->dev
, "Failed to allocate memory for "
1739 "dma resource structure\n");
1743 dma_ctrlr
->parent
= ca91cx42_bridge
;
1744 mutex_init(&dma_ctrlr
->mtx
);
1745 dma_ctrlr
->locked
= 0;
1746 dma_ctrlr
->number
= i
;
1747 dma_ctrlr
->route_attr
= VME_DMA_VME_TO_MEM
|
1749 INIT_LIST_HEAD(&dma_ctrlr
->pending
);
1750 INIT_LIST_HEAD(&dma_ctrlr
->running
);
1751 list_add_tail(&dma_ctrlr
->list
,
1752 &ca91cx42_bridge
->dma_resources
);
1755 /* Add location monitor to list */
1756 INIT_LIST_HEAD(&ca91cx42_bridge
->lm_resources
);
1757 lm
= kmalloc(sizeof(struct vme_lm_resource
), GFP_KERNEL
);
1759 dev_err(&pdev
->dev
, "Failed to allocate memory for "
1760 "location monitor resource structure\n");
1764 lm
->parent
= ca91cx42_bridge
;
1765 mutex_init(&lm
->mtx
);
1769 list_add_tail(&lm
->list
, &ca91cx42_bridge
->lm_resources
);
1771 ca91cx42_bridge
->slave_get
= ca91cx42_slave_get
;
1772 ca91cx42_bridge
->slave_set
= ca91cx42_slave_set
;
1773 ca91cx42_bridge
->master_get
= ca91cx42_master_get
;
1774 ca91cx42_bridge
->master_set
= ca91cx42_master_set
;
1775 ca91cx42_bridge
->master_read
= ca91cx42_master_read
;
1776 ca91cx42_bridge
->master_write
= ca91cx42_master_write
;
1777 ca91cx42_bridge
->master_rmw
= ca91cx42_master_rmw
;
1778 ca91cx42_bridge
->dma_list_add
= ca91cx42_dma_list_add
;
1779 ca91cx42_bridge
->dma_list_exec
= ca91cx42_dma_list_exec
;
1780 ca91cx42_bridge
->dma_list_empty
= ca91cx42_dma_list_empty
;
1781 ca91cx42_bridge
->irq_set
= ca91cx42_irq_set
;
1782 ca91cx42_bridge
->irq_generate
= ca91cx42_irq_generate
;
1783 ca91cx42_bridge
->lm_set
= ca91cx42_lm_set
;
1784 ca91cx42_bridge
->lm_get
= ca91cx42_lm_get
;
1785 ca91cx42_bridge
->lm_attach
= ca91cx42_lm_attach
;
1786 ca91cx42_bridge
->lm_detach
= ca91cx42_lm_detach
;
1787 ca91cx42_bridge
->slot_get
= ca91cx42_slot_get
;
1788 ca91cx42_bridge
->alloc_consistent
= ca91cx42_alloc_consistent
;
1789 ca91cx42_bridge
->free_consistent
= ca91cx42_free_consistent
;
1791 data
= ioread32(ca91cx42_device
->base
+ MISC_CTL
);
1792 dev_info(&pdev
->dev
, "Board is%s the VME system controller\n",
1793 (data
& CA91CX42_MISC_CTL_SYSCON
) ? "" : " not");
1794 dev_info(&pdev
->dev
, "Slot ID is %d\n",
1795 ca91cx42_slot_get(ca91cx42_bridge
));
1797 if (ca91cx42_crcsr_init(ca91cx42_bridge
, pdev
))
1798 dev_err(&pdev
->dev
, "CR/CSR configuration failed.\n");
1800 /* Need to save ca91cx42_bridge pointer locally in link list for use in
1803 retval
= vme_register_bridge(ca91cx42_bridge
);
1805 dev_err(&pdev
->dev
, "Chip Registration failed.\n");
1809 pci_set_drvdata(pdev
, ca91cx42_bridge
);
1814 ca91cx42_crcsr_exit(ca91cx42_bridge
, pdev
);
1816 /* resources are stored in link list */
1817 list_for_each_safe(pos
, n
, &ca91cx42_bridge
->lm_resources
) {
1818 lm
= list_entry(pos
, struct vme_lm_resource
, list
);
1823 /* resources are stored in link list */
1824 list_for_each_safe(pos
, n
, &ca91cx42_bridge
->dma_resources
) {
1825 dma_ctrlr
= list_entry(pos
, struct vme_dma_resource
, list
);
1830 /* resources are stored in link list */
1831 list_for_each_safe(pos
, n
, &ca91cx42_bridge
->slave_resources
) {
1832 slave_image
= list_entry(pos
, struct vme_slave_resource
, list
);
1837 /* resources are stored in link list */
1838 list_for_each_safe(pos
, n
, &ca91cx42_bridge
->master_resources
) {
1839 master_image
= list_entry(pos
, struct vme_master_resource
,
1842 kfree(master_image
);
1845 ca91cx42_irq_exit(ca91cx42_device
, pdev
);
1848 iounmap(ca91cx42_device
->base
);
1850 pci_release_regions(pdev
);
1852 pci_disable_device(pdev
);
1854 kfree(ca91cx42_device
);
1856 kfree(ca91cx42_bridge
);
1862 static void ca91cx42_remove(struct pci_dev
*pdev
)
1864 struct list_head
*pos
= NULL
, *n
;
1865 struct vme_master_resource
*master_image
;
1866 struct vme_slave_resource
*slave_image
;
1867 struct vme_dma_resource
*dma_ctrlr
;
1868 struct vme_lm_resource
*lm
;
1869 struct ca91cx42_driver
*bridge
;
1870 struct vme_bridge
*ca91cx42_bridge
= pci_get_drvdata(pdev
);
1872 bridge
= ca91cx42_bridge
->driver_priv
;
1876 iowrite32(0, bridge
->base
+ LINT_EN
);
1878 /* Turn off the windows */
1879 iowrite32(0x00800000, bridge
->base
+ LSI0_CTL
);
1880 iowrite32(0x00800000, bridge
->base
+ LSI1_CTL
);
1881 iowrite32(0x00800000, bridge
->base
+ LSI2_CTL
);
1882 iowrite32(0x00800000, bridge
->base
+ LSI3_CTL
);
1883 iowrite32(0x00800000, bridge
->base
+ LSI4_CTL
);
1884 iowrite32(0x00800000, bridge
->base
+ LSI5_CTL
);
1885 iowrite32(0x00800000, bridge
->base
+ LSI6_CTL
);
1886 iowrite32(0x00800000, bridge
->base
+ LSI7_CTL
);
1887 iowrite32(0x00F00000, bridge
->base
+ VSI0_CTL
);
1888 iowrite32(0x00F00000, bridge
->base
+ VSI1_CTL
);
1889 iowrite32(0x00F00000, bridge
->base
+ VSI2_CTL
);
1890 iowrite32(0x00F00000, bridge
->base
+ VSI3_CTL
);
1891 iowrite32(0x00F00000, bridge
->base
+ VSI4_CTL
);
1892 iowrite32(0x00F00000, bridge
->base
+ VSI5_CTL
);
1893 iowrite32(0x00F00000, bridge
->base
+ VSI6_CTL
);
1894 iowrite32(0x00F00000, bridge
->base
+ VSI7_CTL
);
1896 vme_unregister_bridge(ca91cx42_bridge
);
1898 ca91cx42_crcsr_exit(ca91cx42_bridge
, pdev
);
1900 /* resources are stored in link list */
1901 list_for_each_safe(pos
, n
, &ca91cx42_bridge
->lm_resources
) {
1902 lm
= list_entry(pos
, struct vme_lm_resource
, list
);
1907 /* resources are stored in link list */
1908 list_for_each_safe(pos
, n
, &ca91cx42_bridge
->dma_resources
) {
1909 dma_ctrlr
= list_entry(pos
, struct vme_dma_resource
, list
);
1914 /* resources are stored in link list */
1915 list_for_each_safe(pos
, n
, &ca91cx42_bridge
->slave_resources
) {
1916 slave_image
= list_entry(pos
, struct vme_slave_resource
, list
);
1921 /* resources are stored in link list */
1922 list_for_each_safe(pos
, n
, &ca91cx42_bridge
->master_resources
) {
1923 master_image
= list_entry(pos
, struct vme_master_resource
,
1926 kfree(master_image
);
1929 ca91cx42_irq_exit(bridge
, pdev
);
1931 iounmap(bridge
->base
);
1933 pci_release_regions(pdev
);
1935 pci_disable_device(pdev
);
1937 kfree(ca91cx42_bridge
);
1940 module_pci_driver(ca91cx42_driver
);
1942 MODULE_PARM_DESC(geoid
, "Override geographical addressing");
1943 module_param(geoid
, int, 0);
1945 MODULE_DESCRIPTION("VME driver for the Tundra Universe II VME bridge");
1946 MODULE_LICENSE("GPL");