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>
29 #include <linux/vme.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"
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, "
147 "attributes: %08x\n",
148 ioread32be(bridge
->base
+ TSI148_LCSR_EDPAU
),
149 ioread32be(bridge
->base
+ TSI148_LCSR_EDPAL
),
150 ioread32be(bridge
->base
+ TSI148_LCSR_EDPAT
));
152 dev_err(tsi148_bridge
->parent
, "PCI-X attribute reg: %08x, PCI-X split "
153 "completion reg: %08x\n",
154 ioread32be(bridge
->base
+ TSI148_LCSR_EDPXA
),
155 ioread32be(bridge
->base
+ TSI148_LCSR_EDPXS
));
157 iowrite32be(TSI148_LCSR_EDPAT_EDPCL
, bridge
->base
+ TSI148_LCSR_EDPAT
);
159 return TSI148_LCSR_INTC_PERRC
;
163 * Save address and status when VME error interrupt occurs.
165 static u32
tsi148_VERR_irqhandler(struct vme_bridge
*tsi148_bridge
)
167 unsigned int error_addr_high
, error_addr_low
;
168 unsigned long long error_addr
;
171 struct tsi148_driver
*bridge
;
173 bridge
= tsi148_bridge
->driver_priv
;
175 error_addr_high
= ioread32be(bridge
->base
+ TSI148_LCSR_VEAU
);
176 error_addr_low
= ioread32be(bridge
->base
+ TSI148_LCSR_VEAL
);
177 error_attrib
= ioread32be(bridge
->base
+ TSI148_LCSR_VEAT
);
178 error_am
= (error_attrib
& TSI148_LCSR_VEAT_AM_M
) >> 8;
180 reg_join(error_addr_high
, error_addr_low
, &error_addr
);
182 /* Check for exception register overflow (we have lost error data) */
183 if (error_attrib
& TSI148_LCSR_VEAT_VEOF
) {
184 dev_err(tsi148_bridge
->parent
, "VME Bus Exception Overflow "
189 vme_bus_error_handler(tsi148_bridge
, error_addr
, error_am
);
191 dev_err(tsi148_bridge
->parent
,
192 "VME Bus Error at address: 0x%llx, attributes: %08x\n",
193 error_addr
, error_attrib
);
196 iowrite32be(TSI148_LCSR_VEAT_VESCL
, bridge
->base
+ TSI148_LCSR_VEAT
);
198 return TSI148_LCSR_INTC_VERRC
;
202 * Wake up IACK queue.
204 static u32
tsi148_IACK_irqhandler(struct tsi148_driver
*bridge
)
206 wake_up(&bridge
->iack_queue
);
208 return TSI148_LCSR_INTC_IACKC
;
212 * Calling VME bus interrupt callback if provided.
214 static u32
tsi148_VIRQ_irqhandler(struct vme_bridge
*tsi148_bridge
,
217 int vec
, i
, serviced
= 0;
218 struct tsi148_driver
*bridge
;
220 bridge
= tsi148_bridge
->driver_priv
;
222 for (i
= 7; i
> 0; i
--) {
223 if (stat
& (1 << i
)) {
225 * Note: Even though the registers are defined as
226 * 32-bits in the spec, we only want to issue 8-bit
227 * IACK cycles on the bus, read from offset 3.
229 vec
= ioread8(bridge
->base
+ TSI148_LCSR_VIACK
[i
] + 3);
231 vme_irq_handler(tsi148_bridge
, i
, vec
);
233 serviced
|= (1 << i
);
241 * Top level interrupt handler. Clears appropriate interrupt status bits and
242 * then calls appropriate sub handler(s).
244 static irqreturn_t
tsi148_irqhandler(int irq
, void *ptr
)
246 u32 stat
, enable
, serviced
= 0;
247 struct vme_bridge
*tsi148_bridge
;
248 struct tsi148_driver
*bridge
;
252 bridge
= tsi148_bridge
->driver_priv
;
254 /* Determine which interrupts are unmasked and set */
255 enable
= ioread32be(bridge
->base
+ TSI148_LCSR_INTEO
);
256 stat
= ioread32be(bridge
->base
+ TSI148_LCSR_INTS
);
258 /* Only look at unmasked interrupts */
264 /* Call subhandlers as appropriate */
266 if (stat
& (TSI148_LCSR_INTS_DMA1S
| TSI148_LCSR_INTS_DMA0S
))
267 serviced
|= tsi148_DMA_irqhandler(bridge
, stat
);
269 /* Location monitor irqs */
270 if (stat
& (TSI148_LCSR_INTS_LM3S
| TSI148_LCSR_INTS_LM2S
|
271 TSI148_LCSR_INTS_LM1S
| TSI148_LCSR_INTS_LM0S
))
272 serviced
|= tsi148_LM_irqhandler(bridge
, stat
);
275 if (stat
& (TSI148_LCSR_INTS_MB3S
| TSI148_LCSR_INTS_MB2S
|
276 TSI148_LCSR_INTS_MB1S
| TSI148_LCSR_INTS_MB0S
))
277 serviced
|= tsi148_MB_irqhandler(tsi148_bridge
, stat
);
280 if (stat
& TSI148_LCSR_INTS_PERRS
)
281 serviced
|= tsi148_PERR_irqhandler(tsi148_bridge
);
284 if (stat
& TSI148_LCSR_INTS_VERRS
)
285 serviced
|= tsi148_VERR_irqhandler(tsi148_bridge
);
288 if (stat
& TSI148_LCSR_INTS_IACKS
)
289 serviced
|= tsi148_IACK_irqhandler(bridge
);
292 if (stat
& (TSI148_LCSR_INTS_IRQ7S
| TSI148_LCSR_INTS_IRQ6S
|
293 TSI148_LCSR_INTS_IRQ5S
| TSI148_LCSR_INTS_IRQ4S
|
294 TSI148_LCSR_INTS_IRQ3S
| TSI148_LCSR_INTS_IRQ2S
|
295 TSI148_LCSR_INTS_IRQ1S
))
296 serviced
|= tsi148_VIRQ_irqhandler(tsi148_bridge
, stat
);
298 /* Clear serviced interrupts */
299 iowrite32be(serviced
, bridge
->base
+ TSI148_LCSR_INTC
);
304 static int tsi148_irq_init(struct vme_bridge
*tsi148_bridge
)
308 struct pci_dev
*pdev
;
309 struct tsi148_driver
*bridge
;
311 pdev
= to_pci_dev(tsi148_bridge
->parent
);
313 bridge
= tsi148_bridge
->driver_priv
;
315 result
= request_irq(pdev
->irq
,
318 driver_name
, tsi148_bridge
);
320 dev_err(tsi148_bridge
->parent
, "Can't get assigned pci irq "
321 "vector %02X\n", pdev
->irq
);
325 /* Enable and unmask interrupts */
326 tmp
= TSI148_LCSR_INTEO_DMA1EO
| TSI148_LCSR_INTEO_DMA0EO
|
327 TSI148_LCSR_INTEO_MB3EO
| TSI148_LCSR_INTEO_MB2EO
|
328 TSI148_LCSR_INTEO_MB1EO
| TSI148_LCSR_INTEO_MB0EO
|
329 TSI148_LCSR_INTEO_PERREO
| TSI148_LCSR_INTEO_VERREO
|
330 TSI148_LCSR_INTEO_IACKEO
;
332 /* This leaves the following interrupts masked.
333 * TSI148_LCSR_INTEO_VIEEO
334 * TSI148_LCSR_INTEO_SYSFLEO
335 * TSI148_LCSR_INTEO_ACFLEO
338 /* Don't enable Location Monitor interrupts here - they will be
339 * enabled when the location monitors are properly configured and
340 * a callback has been attached.
341 * TSI148_LCSR_INTEO_LM0EO
342 * TSI148_LCSR_INTEO_LM1EO
343 * TSI148_LCSR_INTEO_LM2EO
344 * TSI148_LCSR_INTEO_LM3EO
347 /* Don't enable VME interrupts until we add a handler, else the board
348 * will respond to it and we don't want that unless it knows how to
349 * properly deal with it.
350 * TSI148_LCSR_INTEO_IRQ7EO
351 * TSI148_LCSR_INTEO_IRQ6EO
352 * TSI148_LCSR_INTEO_IRQ5EO
353 * TSI148_LCSR_INTEO_IRQ4EO
354 * TSI148_LCSR_INTEO_IRQ3EO
355 * TSI148_LCSR_INTEO_IRQ2EO
356 * TSI148_LCSR_INTEO_IRQ1EO
359 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_INTEO
);
360 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_INTEN
);
365 static void tsi148_irq_exit(struct vme_bridge
*tsi148_bridge
,
366 struct pci_dev
*pdev
)
368 struct tsi148_driver
*bridge
= tsi148_bridge
->driver_priv
;
370 /* Turn off interrupts */
371 iowrite32be(0x0, bridge
->base
+ TSI148_LCSR_INTEO
);
372 iowrite32be(0x0, bridge
->base
+ TSI148_LCSR_INTEN
);
374 /* Clear all interrupts */
375 iowrite32be(0xFFFFFFFF, bridge
->base
+ TSI148_LCSR_INTC
);
377 /* Detach interrupt handler */
378 free_irq(pdev
->irq
, tsi148_bridge
);
382 * Check to see if an IACk has been received, return true (1) or false (0).
384 static int tsi148_iack_received(struct tsi148_driver
*bridge
)
388 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_VICR
);
390 if (tmp
& TSI148_LCSR_VICR_IRQS
)
397 * Configure VME interrupt
399 static void tsi148_irq_set(struct vme_bridge
*tsi148_bridge
, int level
,
402 struct pci_dev
*pdev
;
404 struct tsi148_driver
*bridge
;
406 bridge
= tsi148_bridge
->driver_priv
;
408 /* We need to do the ordering differently for enabling and disabling */
410 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_INTEN
);
411 tmp
&= ~TSI148_LCSR_INTEN_IRQEN
[level
- 1];
412 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_INTEN
);
414 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_INTEO
);
415 tmp
&= ~TSI148_LCSR_INTEO_IRQEO
[level
- 1];
416 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_INTEO
);
419 pdev
= to_pci_dev(tsi148_bridge
->parent
);
420 synchronize_irq(pdev
->irq
);
423 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_INTEO
);
424 tmp
|= TSI148_LCSR_INTEO_IRQEO
[level
- 1];
425 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_INTEO
);
427 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_INTEN
);
428 tmp
|= TSI148_LCSR_INTEN_IRQEN
[level
- 1];
429 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_INTEN
);
434 * Generate a VME bus interrupt at the requested level & vector. Wait for
435 * interrupt to be acked.
437 static int tsi148_irq_generate(struct vme_bridge
*tsi148_bridge
, int level
,
441 struct tsi148_driver
*bridge
;
443 bridge
= tsi148_bridge
->driver_priv
;
445 mutex_lock(&bridge
->vme_int
);
447 /* Read VICR register */
448 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_VICR
);
451 tmp
= (tmp
& ~TSI148_LCSR_VICR_STID_M
) |
452 (statid
& TSI148_LCSR_VICR_STID_M
);
453 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_VICR
);
455 /* Assert VMEbus IRQ */
456 tmp
= tmp
| TSI148_LCSR_VICR_IRQL
[level
];
457 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_VICR
);
459 /* XXX Consider implementing a timeout? */
460 wait_event_interruptible(bridge
->iack_queue
,
461 tsi148_iack_received(bridge
));
463 mutex_unlock(&bridge
->vme_int
);
469 * Initialize a slave window with the requested attributes.
471 static int tsi148_slave_set(struct vme_slave_resource
*image
, int enabled
,
472 unsigned long long vme_base
, unsigned long long size
,
473 dma_addr_t pci_base
, u32 aspace
, u32 cycle
)
475 unsigned int i
, addr
= 0, granularity
= 0;
476 unsigned int temp_ctl
= 0;
477 unsigned int vme_base_low
, vme_base_high
;
478 unsigned int vme_bound_low
, vme_bound_high
;
479 unsigned int pci_offset_low
, pci_offset_high
;
480 unsigned long long vme_bound
, pci_offset
;
481 struct vme_bridge
*tsi148_bridge
;
482 struct tsi148_driver
*bridge
;
484 tsi148_bridge
= image
->parent
;
485 bridge
= tsi148_bridge
->driver_priv
;
492 addr
|= TSI148_LCSR_ITAT_AS_A16
;
495 granularity
= 0x1000;
496 addr
|= TSI148_LCSR_ITAT_AS_A24
;
499 granularity
= 0x10000;
500 addr
|= TSI148_LCSR_ITAT_AS_A32
;
503 granularity
= 0x10000;
504 addr
|= TSI148_LCSR_ITAT_AS_A64
;
507 dev_err(tsi148_bridge
->parent
, "Invalid address space\n");
511 /* Convert 64-bit variables to 2x 32-bit variables */
512 reg_split(vme_base
, &vme_base_high
, &vme_base_low
);
515 * Bound address is a valid address for the window, adjust
518 vme_bound
= vme_base
+ size
- granularity
;
519 reg_split(vme_bound
, &vme_bound_high
, &vme_bound_low
);
520 pci_offset
= (unsigned long long)pci_base
- vme_base
;
521 reg_split(pci_offset
, &pci_offset_high
, &pci_offset_low
);
523 if (vme_base_low
& (granularity
- 1)) {
524 dev_err(tsi148_bridge
->parent
, "Invalid VME base alignment\n");
527 if (vme_bound_low
& (granularity
- 1)) {
528 dev_err(tsi148_bridge
->parent
, "Invalid VME bound alignment\n");
531 if (pci_offset_low
& (granularity
- 1)) {
532 dev_err(tsi148_bridge
->parent
, "Invalid PCI Offset "
537 /* Disable while we are mucking around */
538 temp_ctl
= ioread32be(bridge
->base
+ TSI148_LCSR_IT
[i
] +
539 TSI148_LCSR_OFFSET_ITAT
);
540 temp_ctl
&= ~TSI148_LCSR_ITAT_EN
;
541 iowrite32be(temp_ctl
, bridge
->base
+ TSI148_LCSR_IT
[i
] +
542 TSI148_LCSR_OFFSET_ITAT
);
545 iowrite32be(vme_base_high
, bridge
->base
+ TSI148_LCSR_IT
[i
] +
546 TSI148_LCSR_OFFSET_ITSAU
);
547 iowrite32be(vme_base_low
, bridge
->base
+ TSI148_LCSR_IT
[i
] +
548 TSI148_LCSR_OFFSET_ITSAL
);
549 iowrite32be(vme_bound_high
, bridge
->base
+ TSI148_LCSR_IT
[i
] +
550 TSI148_LCSR_OFFSET_ITEAU
);
551 iowrite32be(vme_bound_low
, bridge
->base
+ TSI148_LCSR_IT
[i
] +
552 TSI148_LCSR_OFFSET_ITEAL
);
553 iowrite32be(pci_offset_high
, bridge
->base
+ TSI148_LCSR_IT
[i
] +
554 TSI148_LCSR_OFFSET_ITOFU
);
555 iowrite32be(pci_offset_low
, bridge
->base
+ TSI148_LCSR_IT
[i
] +
556 TSI148_LCSR_OFFSET_ITOFL
);
558 /* Setup 2eSST speeds */
559 temp_ctl
&= ~TSI148_LCSR_ITAT_2eSSTM_M
;
560 switch (cycle
& (VME_2eSST160
| VME_2eSST267
| VME_2eSST320
)) {
562 temp_ctl
|= TSI148_LCSR_ITAT_2eSSTM_160
;
565 temp_ctl
|= TSI148_LCSR_ITAT_2eSSTM_267
;
568 temp_ctl
|= TSI148_LCSR_ITAT_2eSSTM_320
;
572 /* Setup cycle types */
573 temp_ctl
&= ~(0x1F << 7);
575 temp_ctl
|= TSI148_LCSR_ITAT_BLT
;
576 if (cycle
& VME_MBLT
)
577 temp_ctl
|= TSI148_LCSR_ITAT_MBLT
;
578 if (cycle
& VME_2eVME
)
579 temp_ctl
|= TSI148_LCSR_ITAT_2eVME
;
580 if (cycle
& VME_2eSST
)
581 temp_ctl
|= TSI148_LCSR_ITAT_2eSST
;
582 if (cycle
& VME_2eSSTB
)
583 temp_ctl
|= TSI148_LCSR_ITAT_2eSSTB
;
585 /* Setup address space */
586 temp_ctl
&= ~TSI148_LCSR_ITAT_AS_M
;
590 if (cycle
& VME_SUPER
)
591 temp_ctl
|= TSI148_LCSR_ITAT_SUPR
;
592 if (cycle
& VME_USER
)
593 temp_ctl
|= TSI148_LCSR_ITAT_NPRIV
;
594 if (cycle
& VME_PROG
)
595 temp_ctl
|= TSI148_LCSR_ITAT_PGM
;
596 if (cycle
& VME_DATA
)
597 temp_ctl
|= TSI148_LCSR_ITAT_DATA
;
599 /* Write ctl reg without enable */
600 iowrite32be(temp_ctl
, bridge
->base
+ TSI148_LCSR_IT
[i
] +
601 TSI148_LCSR_OFFSET_ITAT
);
604 temp_ctl
|= TSI148_LCSR_ITAT_EN
;
606 iowrite32be(temp_ctl
, bridge
->base
+ TSI148_LCSR_IT
[i
] +
607 TSI148_LCSR_OFFSET_ITAT
);
613 * Get slave window configuration.
615 static int tsi148_slave_get(struct vme_slave_resource
*image
, int *enabled
,
616 unsigned long long *vme_base
, unsigned long long *size
,
617 dma_addr_t
*pci_base
, u32
*aspace
, u32
*cycle
)
619 unsigned int i
, granularity
= 0, ctl
= 0;
620 unsigned int vme_base_low
, vme_base_high
;
621 unsigned int vme_bound_low
, vme_bound_high
;
622 unsigned int pci_offset_low
, pci_offset_high
;
623 unsigned long long vme_bound
, pci_offset
;
624 struct tsi148_driver
*bridge
;
626 bridge
= image
->parent
->driver_priv
;
631 ctl
= ioread32be(bridge
->base
+ TSI148_LCSR_IT
[i
] +
632 TSI148_LCSR_OFFSET_ITAT
);
634 vme_base_high
= ioread32be(bridge
->base
+ TSI148_LCSR_IT
[i
] +
635 TSI148_LCSR_OFFSET_ITSAU
);
636 vme_base_low
= ioread32be(bridge
->base
+ TSI148_LCSR_IT
[i
] +
637 TSI148_LCSR_OFFSET_ITSAL
);
638 vme_bound_high
= ioread32be(bridge
->base
+ TSI148_LCSR_IT
[i
] +
639 TSI148_LCSR_OFFSET_ITEAU
);
640 vme_bound_low
= ioread32be(bridge
->base
+ TSI148_LCSR_IT
[i
] +
641 TSI148_LCSR_OFFSET_ITEAL
);
642 pci_offset_high
= ioread32be(bridge
->base
+ TSI148_LCSR_IT
[i
] +
643 TSI148_LCSR_OFFSET_ITOFU
);
644 pci_offset_low
= ioread32be(bridge
->base
+ TSI148_LCSR_IT
[i
] +
645 TSI148_LCSR_OFFSET_ITOFL
);
647 /* Convert 64-bit variables to 2x 32-bit variables */
648 reg_join(vme_base_high
, vme_base_low
, vme_base
);
649 reg_join(vme_bound_high
, vme_bound_low
, &vme_bound
);
650 reg_join(pci_offset_high
, pci_offset_low
, &pci_offset
);
652 *pci_base
= (dma_addr_t
)(*vme_base
+ pci_offset
);
658 if (ctl
& TSI148_LCSR_ITAT_EN
)
661 if ((ctl
& TSI148_LCSR_ITAT_AS_M
) == TSI148_LCSR_ITAT_AS_A16
) {
665 if ((ctl
& TSI148_LCSR_ITAT_AS_M
) == TSI148_LCSR_ITAT_AS_A24
) {
666 granularity
= 0x1000;
669 if ((ctl
& TSI148_LCSR_ITAT_AS_M
) == TSI148_LCSR_ITAT_AS_A32
) {
670 granularity
= 0x10000;
673 if ((ctl
& TSI148_LCSR_ITAT_AS_M
) == TSI148_LCSR_ITAT_AS_A64
) {
674 granularity
= 0x10000;
678 /* Need granularity before we set the size */
679 *size
= (unsigned long long)((vme_bound
- *vme_base
) + granularity
);
682 if ((ctl
& TSI148_LCSR_ITAT_2eSSTM_M
) == TSI148_LCSR_ITAT_2eSSTM_160
)
683 *cycle
|= VME_2eSST160
;
684 if ((ctl
& TSI148_LCSR_ITAT_2eSSTM_M
) == TSI148_LCSR_ITAT_2eSSTM_267
)
685 *cycle
|= VME_2eSST267
;
686 if ((ctl
& TSI148_LCSR_ITAT_2eSSTM_M
) == TSI148_LCSR_ITAT_2eSSTM_320
)
687 *cycle
|= VME_2eSST320
;
689 if (ctl
& TSI148_LCSR_ITAT_BLT
)
691 if (ctl
& TSI148_LCSR_ITAT_MBLT
)
693 if (ctl
& TSI148_LCSR_ITAT_2eVME
)
695 if (ctl
& TSI148_LCSR_ITAT_2eSST
)
697 if (ctl
& TSI148_LCSR_ITAT_2eSSTB
)
698 *cycle
|= VME_2eSSTB
;
700 if (ctl
& TSI148_LCSR_ITAT_SUPR
)
702 if (ctl
& TSI148_LCSR_ITAT_NPRIV
)
704 if (ctl
& TSI148_LCSR_ITAT_PGM
)
706 if (ctl
& TSI148_LCSR_ITAT_DATA
)
713 * Allocate and map PCI Resource
715 static int tsi148_alloc_resource(struct vme_master_resource
*image
,
716 unsigned long long size
)
718 unsigned long long existing_size
;
720 struct pci_dev
*pdev
;
721 struct vme_bridge
*tsi148_bridge
;
723 tsi148_bridge
= image
->parent
;
725 pdev
= to_pci_dev(tsi148_bridge
->parent
);
727 existing_size
= (unsigned long long)(image
->bus_resource
.end
-
728 image
->bus_resource
.start
);
730 /* If the existing size is OK, return */
731 if ((size
!= 0) && (existing_size
== (size
- 1)))
734 if (existing_size
!= 0) {
735 iounmap(image
->kern_base
);
736 image
->kern_base
= NULL
;
737 kfree(image
->bus_resource
.name
);
738 release_resource(&image
->bus_resource
);
739 memset(&image
->bus_resource
, 0, sizeof(image
->bus_resource
));
742 /* Exit here if size is zero */
746 if (!image
->bus_resource
.name
) {
747 image
->bus_resource
.name
= kmalloc(VMENAMSIZ
+3, GFP_ATOMIC
);
748 if (!image
->bus_resource
.name
) {
754 sprintf((char *)image
->bus_resource
.name
, "%s.%d", tsi148_bridge
->name
,
757 image
->bus_resource
.start
= 0;
758 image
->bus_resource
.end
= (unsigned long)size
;
759 image
->bus_resource
.flags
= IORESOURCE_MEM
;
761 retval
= pci_bus_alloc_resource(pdev
->bus
,
762 &image
->bus_resource
, size
, 0x10000, PCIBIOS_MIN_MEM
,
765 dev_err(tsi148_bridge
->parent
, "Failed to allocate mem "
766 "resource for window %d size 0x%lx start 0x%lx\n",
767 image
->number
, (unsigned long)size
,
768 (unsigned long)image
->bus_resource
.start
);
772 image
->kern_base
= ioremap(
773 image
->bus_resource
.start
, size
);
774 if (!image
->kern_base
) {
775 dev_err(tsi148_bridge
->parent
, "Failed to remap resource\n");
783 release_resource(&image
->bus_resource
);
785 kfree(image
->bus_resource
.name
);
786 memset(&image
->bus_resource
, 0, sizeof(image
->bus_resource
));
792 * Free and unmap PCI Resource
794 static void tsi148_free_resource(struct vme_master_resource
*image
)
796 iounmap(image
->kern_base
);
797 image
->kern_base
= NULL
;
798 release_resource(&image
->bus_resource
);
799 kfree(image
->bus_resource
.name
);
800 memset(&image
->bus_resource
, 0, sizeof(image
->bus_resource
));
804 * Set the attributes of an outbound window.
806 static int tsi148_master_set(struct vme_master_resource
*image
, int enabled
,
807 unsigned long long vme_base
, unsigned long long size
, u32 aspace
,
808 u32 cycle
, u32 dwidth
)
812 unsigned int temp_ctl
= 0;
813 unsigned int pci_base_low
, pci_base_high
;
814 unsigned int pci_bound_low
, pci_bound_high
;
815 unsigned int vme_offset_low
, vme_offset_high
;
816 unsigned long long pci_bound
, vme_offset
, pci_base
;
817 struct vme_bridge
*tsi148_bridge
;
818 struct tsi148_driver
*bridge
;
819 struct pci_bus_region region
;
820 struct pci_dev
*pdev
;
822 tsi148_bridge
= image
->parent
;
824 bridge
= tsi148_bridge
->driver_priv
;
826 pdev
= to_pci_dev(tsi148_bridge
->parent
);
828 /* Verify input data */
829 if (vme_base
& 0xFFFF) {
830 dev_err(tsi148_bridge
->parent
, "Invalid VME Window "
836 if ((size
== 0) && (enabled
!= 0)) {
837 dev_err(tsi148_bridge
->parent
, "Size must be non-zero for "
838 "enabled windows\n");
843 spin_lock(&image
->lock
);
845 /* Let's allocate the resource here rather than further up the stack as
846 * it avoids pushing loads of bus dependent stuff up the stack. If size
847 * is zero, any existing resource will be freed.
849 retval
= tsi148_alloc_resource(image
, size
);
851 spin_unlock(&image
->lock
);
852 dev_err(tsi148_bridge
->parent
, "Unable to allocate memory for "
862 pcibios_resource_to_bus(pdev
->bus
, ®ion
,
863 &image
->bus_resource
);
864 pci_base
= region
.start
;
867 * Bound address is a valid address for the window, adjust
868 * according to window granularity.
870 pci_bound
= pci_base
+ (size
- 0x10000);
871 vme_offset
= vme_base
- pci_base
;
874 /* Convert 64-bit variables to 2x 32-bit variables */
875 reg_split(pci_base
, &pci_base_high
, &pci_base_low
);
876 reg_split(pci_bound
, &pci_bound_high
, &pci_bound_low
);
877 reg_split(vme_offset
, &vme_offset_high
, &vme_offset_low
);
879 if (pci_base_low
& 0xFFFF) {
880 spin_unlock(&image
->lock
);
881 dev_err(tsi148_bridge
->parent
, "Invalid PCI base alignment\n");
885 if (pci_bound_low
& 0xFFFF) {
886 spin_unlock(&image
->lock
);
887 dev_err(tsi148_bridge
->parent
, "Invalid PCI bound alignment\n");
891 if (vme_offset_low
& 0xFFFF) {
892 spin_unlock(&image
->lock
);
893 dev_err(tsi148_bridge
->parent
, "Invalid VME Offset "
901 /* Disable while we are mucking around */
902 temp_ctl
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
903 TSI148_LCSR_OFFSET_OTAT
);
904 temp_ctl
&= ~TSI148_LCSR_OTAT_EN
;
905 iowrite32be(temp_ctl
, bridge
->base
+ TSI148_LCSR_OT
[i
] +
906 TSI148_LCSR_OFFSET_OTAT
);
908 /* Setup 2eSST speeds */
909 temp_ctl
&= ~TSI148_LCSR_OTAT_2eSSTM_M
;
910 switch (cycle
& (VME_2eSST160
| VME_2eSST267
| VME_2eSST320
)) {
912 temp_ctl
|= TSI148_LCSR_OTAT_2eSSTM_160
;
915 temp_ctl
|= TSI148_LCSR_OTAT_2eSSTM_267
;
918 temp_ctl
|= TSI148_LCSR_OTAT_2eSSTM_320
;
922 /* Setup cycle types */
923 if (cycle
& VME_BLT
) {
924 temp_ctl
&= ~TSI148_LCSR_OTAT_TM_M
;
925 temp_ctl
|= TSI148_LCSR_OTAT_TM_BLT
;
927 if (cycle
& VME_MBLT
) {
928 temp_ctl
&= ~TSI148_LCSR_OTAT_TM_M
;
929 temp_ctl
|= TSI148_LCSR_OTAT_TM_MBLT
;
931 if (cycle
& VME_2eVME
) {
932 temp_ctl
&= ~TSI148_LCSR_OTAT_TM_M
;
933 temp_ctl
|= TSI148_LCSR_OTAT_TM_2eVME
;
935 if (cycle
& VME_2eSST
) {
936 temp_ctl
&= ~TSI148_LCSR_OTAT_TM_M
;
937 temp_ctl
|= TSI148_LCSR_OTAT_TM_2eSST
;
939 if (cycle
& VME_2eSSTB
) {
940 dev_warn(tsi148_bridge
->parent
, "Currently not setting "
941 "Broadcast Select Registers\n");
942 temp_ctl
&= ~TSI148_LCSR_OTAT_TM_M
;
943 temp_ctl
|= TSI148_LCSR_OTAT_TM_2eSSTB
;
946 /* Setup data width */
947 temp_ctl
&= ~TSI148_LCSR_OTAT_DBW_M
;
950 temp_ctl
|= TSI148_LCSR_OTAT_DBW_16
;
953 temp_ctl
|= TSI148_LCSR_OTAT_DBW_32
;
956 spin_unlock(&image
->lock
);
957 dev_err(tsi148_bridge
->parent
, "Invalid data width\n");
962 /* Setup address space */
963 temp_ctl
&= ~TSI148_LCSR_OTAT_AMODE_M
;
966 temp_ctl
|= TSI148_LCSR_OTAT_AMODE_A16
;
969 temp_ctl
|= TSI148_LCSR_OTAT_AMODE_A24
;
972 temp_ctl
|= TSI148_LCSR_OTAT_AMODE_A32
;
975 temp_ctl
|= TSI148_LCSR_OTAT_AMODE_A64
;
978 temp_ctl
|= TSI148_LCSR_OTAT_AMODE_CRCSR
;
981 temp_ctl
|= TSI148_LCSR_OTAT_AMODE_USER1
;
984 temp_ctl
|= TSI148_LCSR_OTAT_AMODE_USER2
;
987 temp_ctl
|= TSI148_LCSR_OTAT_AMODE_USER3
;
990 temp_ctl
|= TSI148_LCSR_OTAT_AMODE_USER4
;
993 spin_unlock(&image
->lock
);
994 dev_err(tsi148_bridge
->parent
, "Invalid address space\n");
1000 if (cycle
& VME_SUPER
)
1001 temp_ctl
|= TSI148_LCSR_OTAT_SUP
;
1002 if (cycle
& VME_PROG
)
1003 temp_ctl
|= TSI148_LCSR_OTAT_PGM
;
1006 iowrite32be(pci_base_high
, bridge
->base
+ TSI148_LCSR_OT
[i
] +
1007 TSI148_LCSR_OFFSET_OTSAU
);
1008 iowrite32be(pci_base_low
, bridge
->base
+ TSI148_LCSR_OT
[i
] +
1009 TSI148_LCSR_OFFSET_OTSAL
);
1010 iowrite32be(pci_bound_high
, bridge
->base
+ TSI148_LCSR_OT
[i
] +
1011 TSI148_LCSR_OFFSET_OTEAU
);
1012 iowrite32be(pci_bound_low
, bridge
->base
+ TSI148_LCSR_OT
[i
] +
1013 TSI148_LCSR_OFFSET_OTEAL
);
1014 iowrite32be(vme_offset_high
, bridge
->base
+ TSI148_LCSR_OT
[i
] +
1015 TSI148_LCSR_OFFSET_OTOFU
);
1016 iowrite32be(vme_offset_low
, bridge
->base
+ TSI148_LCSR_OT
[i
] +
1017 TSI148_LCSR_OFFSET_OTOFL
);
1019 /* Write ctl reg without enable */
1020 iowrite32be(temp_ctl
, bridge
->base
+ TSI148_LCSR_OT
[i
] +
1021 TSI148_LCSR_OFFSET_OTAT
);
1024 temp_ctl
|= TSI148_LCSR_OTAT_EN
;
1026 iowrite32be(temp_ctl
, bridge
->base
+ TSI148_LCSR_OT
[i
] +
1027 TSI148_LCSR_OFFSET_OTAT
);
1029 spin_unlock(&image
->lock
);
1035 tsi148_free_resource(image
);
1043 * Set the attributes of an outbound window.
1045 * XXX Not parsing prefetch information.
1047 static int __tsi148_master_get(struct vme_master_resource
*image
, int *enabled
,
1048 unsigned long long *vme_base
, unsigned long long *size
, u32
*aspace
,
1049 u32
*cycle
, u32
*dwidth
)
1051 unsigned int i
, ctl
;
1052 unsigned int pci_base_low
, pci_base_high
;
1053 unsigned int pci_bound_low
, pci_bound_high
;
1054 unsigned int vme_offset_low
, vme_offset_high
;
1056 unsigned long long pci_base
, pci_bound
, vme_offset
;
1057 struct tsi148_driver
*bridge
;
1059 bridge
= image
->parent
->driver_priv
;
1063 ctl
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
1064 TSI148_LCSR_OFFSET_OTAT
);
1066 pci_base_high
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
1067 TSI148_LCSR_OFFSET_OTSAU
);
1068 pci_base_low
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
1069 TSI148_LCSR_OFFSET_OTSAL
);
1070 pci_bound_high
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
1071 TSI148_LCSR_OFFSET_OTEAU
);
1072 pci_bound_low
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
1073 TSI148_LCSR_OFFSET_OTEAL
);
1074 vme_offset_high
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
1075 TSI148_LCSR_OFFSET_OTOFU
);
1076 vme_offset_low
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
1077 TSI148_LCSR_OFFSET_OTOFL
);
1079 /* Convert 64-bit variables to 2x 32-bit variables */
1080 reg_join(pci_base_high
, pci_base_low
, &pci_base
);
1081 reg_join(pci_bound_high
, pci_bound_low
, &pci_bound
);
1082 reg_join(vme_offset_high
, vme_offset_low
, &vme_offset
);
1084 *vme_base
= pci_base
+ vme_offset
;
1085 *size
= (unsigned long long)(pci_bound
- pci_base
) + 0x10000;
1092 if (ctl
& TSI148_LCSR_OTAT_EN
)
1095 /* Setup address space */
1096 if ((ctl
& TSI148_LCSR_OTAT_AMODE_M
) == TSI148_LCSR_OTAT_AMODE_A16
)
1098 if ((ctl
& TSI148_LCSR_OTAT_AMODE_M
) == TSI148_LCSR_OTAT_AMODE_A24
)
1100 if ((ctl
& TSI148_LCSR_OTAT_AMODE_M
) == TSI148_LCSR_OTAT_AMODE_A32
)
1102 if ((ctl
& TSI148_LCSR_OTAT_AMODE_M
) == TSI148_LCSR_OTAT_AMODE_A64
)
1104 if ((ctl
& TSI148_LCSR_OTAT_AMODE_M
) == TSI148_LCSR_OTAT_AMODE_CRCSR
)
1105 *aspace
|= VME_CRCSR
;
1106 if ((ctl
& TSI148_LCSR_OTAT_AMODE_M
) == TSI148_LCSR_OTAT_AMODE_USER1
)
1107 *aspace
|= VME_USER1
;
1108 if ((ctl
& TSI148_LCSR_OTAT_AMODE_M
) == TSI148_LCSR_OTAT_AMODE_USER2
)
1109 *aspace
|= VME_USER2
;
1110 if ((ctl
& TSI148_LCSR_OTAT_AMODE_M
) == TSI148_LCSR_OTAT_AMODE_USER3
)
1111 *aspace
|= VME_USER3
;
1112 if ((ctl
& TSI148_LCSR_OTAT_AMODE_M
) == TSI148_LCSR_OTAT_AMODE_USER4
)
1113 *aspace
|= VME_USER4
;
1115 /* Setup 2eSST speeds */
1116 if ((ctl
& TSI148_LCSR_OTAT_2eSSTM_M
) == TSI148_LCSR_OTAT_2eSSTM_160
)
1117 *cycle
|= VME_2eSST160
;
1118 if ((ctl
& TSI148_LCSR_OTAT_2eSSTM_M
) == TSI148_LCSR_OTAT_2eSSTM_267
)
1119 *cycle
|= VME_2eSST267
;
1120 if ((ctl
& TSI148_LCSR_OTAT_2eSSTM_M
) == TSI148_LCSR_OTAT_2eSSTM_320
)
1121 *cycle
|= VME_2eSST320
;
1123 /* Setup cycle types */
1124 if ((ctl
& TSI148_LCSR_OTAT_TM_M
) == TSI148_LCSR_OTAT_TM_SCT
)
1126 if ((ctl
& TSI148_LCSR_OTAT_TM_M
) == TSI148_LCSR_OTAT_TM_BLT
)
1128 if ((ctl
& TSI148_LCSR_OTAT_TM_M
) == TSI148_LCSR_OTAT_TM_MBLT
)
1130 if ((ctl
& TSI148_LCSR_OTAT_TM_M
) == TSI148_LCSR_OTAT_TM_2eVME
)
1131 *cycle
|= VME_2eVME
;
1132 if ((ctl
& TSI148_LCSR_OTAT_TM_M
) == TSI148_LCSR_OTAT_TM_2eSST
)
1133 *cycle
|= VME_2eSST
;
1134 if ((ctl
& TSI148_LCSR_OTAT_TM_M
) == TSI148_LCSR_OTAT_TM_2eSSTB
)
1135 *cycle
|= VME_2eSSTB
;
1137 if (ctl
& TSI148_LCSR_OTAT_SUP
)
1138 *cycle
|= VME_SUPER
;
1142 if (ctl
& TSI148_LCSR_OTAT_PGM
)
1147 /* Setup data width */
1148 if ((ctl
& TSI148_LCSR_OTAT_DBW_M
) == TSI148_LCSR_OTAT_DBW_16
)
1150 if ((ctl
& TSI148_LCSR_OTAT_DBW_M
) == TSI148_LCSR_OTAT_DBW_32
)
1157 static int tsi148_master_get(struct vme_master_resource
*image
, int *enabled
,
1158 unsigned long long *vme_base
, unsigned long long *size
, u32
*aspace
,
1159 u32
*cycle
, u32
*dwidth
)
1163 spin_lock(&image
->lock
);
1165 retval
= __tsi148_master_get(image
, enabled
, vme_base
, size
, aspace
,
1168 spin_unlock(&image
->lock
);
1173 static ssize_t
tsi148_master_read(struct vme_master_resource
*image
, void *buf
,
1174 size_t count
, loff_t offset
)
1176 int retval
, enabled
;
1177 unsigned long long vme_base
, size
;
1178 u32 aspace
, cycle
, dwidth
;
1179 struct vme_error_handler
*handler
= NULL
;
1180 struct vme_bridge
*tsi148_bridge
;
1181 void __iomem
*addr
= image
->kern_base
+ offset
;
1182 unsigned int done
= 0;
1183 unsigned int count32
;
1185 tsi148_bridge
= image
->parent
;
1187 spin_lock(&image
->lock
);
1190 __tsi148_master_get(image
, &enabled
, &vme_base
, &size
, &aspace
,
1192 handler
= vme_register_error_handler(tsi148_bridge
, aspace
,
1193 vme_base
+ offset
, count
);
1195 spin_unlock(&image
->lock
);
1200 /* The following code handles VME address alignment. We cannot use
1201 * memcpy_xxx here because it may cut data transfers in to 8-bit
1202 * cycles when D16 or D32 cycles are required on the VME bus.
1203 * On the other hand, the bridge itself assures that the maximum data
1204 * cycle configured for the transfer is used and splits it
1205 * automatically for non-aligned addresses, so we don't want the
1206 * overhead of needlessly forcing small transfers for the entire cycle.
1208 if ((uintptr_t)addr
& 0x1) {
1209 *(u8
*)buf
= ioread8(addr
);
1214 if ((uintptr_t)(addr
+ done
) & 0x2) {
1215 if ((count
- done
) < 2) {
1216 *(u8
*)(buf
+ done
) = ioread8(addr
+ done
);
1220 *(u16
*)(buf
+ done
) = ioread16(addr
+ done
);
1225 count32
= (count
- done
) & ~0x3;
1226 while (done
< count32
) {
1227 *(u32
*)(buf
+ done
) = ioread32(addr
+ done
);
1231 if ((count
- done
) & 0x2) {
1232 *(u16
*)(buf
+ done
) = ioread16(addr
+ done
);
1235 if ((count
- done
) & 0x1) {
1236 *(u8
*)(buf
+ done
) = ioread8(addr
+ done
);
1244 if (handler
->num_errors
) {
1245 dev_err(image
->parent
->parent
,
1246 "First VME read error detected an at address 0x%llx\n",
1247 handler
->first_error
);
1248 retval
= handler
->first_error
- (vme_base
+ offset
);
1250 vme_unregister_error_handler(handler
);
1253 spin_unlock(&image
->lock
);
1259 static ssize_t
tsi148_master_write(struct vme_master_resource
*image
, void *buf
,
1260 size_t count
, loff_t offset
)
1262 int retval
= 0, enabled
;
1263 unsigned long long vme_base
, size
;
1264 u32 aspace
, cycle
, dwidth
;
1265 void __iomem
*addr
= image
->kern_base
+ offset
;
1266 unsigned int done
= 0;
1267 unsigned int count32
;
1269 struct vme_error_handler
*handler
= NULL
;
1270 struct vme_bridge
*tsi148_bridge
;
1271 struct tsi148_driver
*bridge
;
1273 tsi148_bridge
= image
->parent
;
1275 bridge
= tsi148_bridge
->driver_priv
;
1277 spin_lock(&image
->lock
);
1280 __tsi148_master_get(image
, &enabled
, &vme_base
, &size
, &aspace
,
1282 handler
= vme_register_error_handler(tsi148_bridge
, aspace
,
1283 vme_base
+ offset
, count
);
1285 spin_unlock(&image
->lock
);
1290 /* Here we apply for the same strategy we do in master_read
1291 * function in order to assure the correct cycles.
1293 if ((uintptr_t)addr
& 0x1) {
1294 iowrite8(*(u8
*)buf
, addr
);
1299 if ((uintptr_t)(addr
+ done
) & 0x2) {
1300 if ((count
- done
) < 2) {
1301 iowrite8(*(u8
*)(buf
+ done
), addr
+ done
);
1305 iowrite16(*(u16
*)(buf
+ done
), addr
+ done
);
1310 count32
= (count
- done
) & ~0x3;
1311 while (done
< count32
) {
1312 iowrite32(*(u32
*)(buf
+ done
), addr
+ done
);
1316 if ((count
- done
) & 0x2) {
1317 iowrite16(*(u16
*)(buf
+ done
), addr
+ done
);
1320 if ((count
- done
) & 0x1) {
1321 iowrite8(*(u8
*)(buf
+ done
), addr
+ done
);
1329 * Writes are posted. We need to do a read on the VME bus to flush out
1330 * all of the writes before we check for errors. We can't guarantee
1331 * that reading the data we have just written is safe. It is believed
1332 * that there isn't any read, write re-ordering, so we can read any
1333 * location in VME space, so lets read the Device ID from the tsi148's
1334 * own registers as mapped into CR/CSR space.
1336 * We check for saved errors in the written address range/space.
1340 ioread16(bridge
->flush_image
->kern_base
+ 0x7F000);
1342 if (handler
->num_errors
) {
1343 dev_warn(tsi148_bridge
->parent
,
1344 "First VME write error detected an at address 0x%llx\n",
1345 handler
->first_error
);
1346 retval
= handler
->first_error
- (vme_base
+ offset
);
1348 vme_unregister_error_handler(handler
);
1351 spin_unlock(&image
->lock
);
1357 * Perform an RMW cycle on the VME bus.
1359 * Requires a previously configured master window, returns final value.
1361 static unsigned int tsi148_master_rmw(struct vme_master_resource
*image
,
1362 unsigned int mask
, unsigned int compare
, unsigned int swap
,
1365 unsigned long long pci_addr
;
1366 unsigned int pci_addr_high
, pci_addr_low
;
1369 struct tsi148_driver
*bridge
;
1371 bridge
= image
->parent
->driver_priv
;
1373 /* Find the PCI address that maps to the desired VME address */
1376 /* Locking as we can only do one of these at a time */
1377 mutex_lock(&bridge
->vme_rmw
);
1380 spin_lock(&image
->lock
);
1382 pci_addr_high
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
1383 TSI148_LCSR_OFFSET_OTSAU
);
1384 pci_addr_low
= ioread32be(bridge
->base
+ TSI148_LCSR_OT
[i
] +
1385 TSI148_LCSR_OFFSET_OTSAL
);
1387 reg_join(pci_addr_high
, pci_addr_low
, &pci_addr
);
1388 reg_split(pci_addr
+ offset
, &pci_addr_high
, &pci_addr_low
);
1390 /* Configure registers */
1391 iowrite32be(mask
, bridge
->base
+ TSI148_LCSR_RMWEN
);
1392 iowrite32be(compare
, bridge
->base
+ TSI148_LCSR_RMWC
);
1393 iowrite32be(swap
, bridge
->base
+ TSI148_LCSR_RMWS
);
1394 iowrite32be(pci_addr_high
, bridge
->base
+ TSI148_LCSR_RMWAU
);
1395 iowrite32be(pci_addr_low
, bridge
->base
+ TSI148_LCSR_RMWAL
);
1398 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_VMCTRL
);
1399 tmp
|= TSI148_LCSR_VMCTRL_RMWEN
;
1400 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_VMCTRL
);
1402 /* Kick process off with a read to the required address. */
1403 result
= ioread32be(image
->kern_base
+ offset
);
1406 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_VMCTRL
);
1407 tmp
&= ~TSI148_LCSR_VMCTRL_RMWEN
;
1408 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_VMCTRL
);
1410 spin_unlock(&image
->lock
);
1412 mutex_unlock(&bridge
->vme_rmw
);
1417 static int tsi148_dma_set_vme_src_attributes(struct device
*dev
, __be32
*attr
,
1418 u32 aspace
, u32 cycle
, u32 dwidth
)
1422 val
= be32_to_cpu(*attr
);
1424 /* Setup 2eSST speeds */
1425 switch (cycle
& (VME_2eSST160
| VME_2eSST267
| VME_2eSST320
)) {
1427 val
|= TSI148_LCSR_DSAT_2eSSTM_160
;
1430 val
|= TSI148_LCSR_DSAT_2eSSTM_267
;
1433 val
|= TSI148_LCSR_DSAT_2eSSTM_320
;
1437 /* Setup cycle types */
1438 if (cycle
& VME_SCT
)
1439 val
|= TSI148_LCSR_DSAT_TM_SCT
;
1441 if (cycle
& VME_BLT
)
1442 val
|= TSI148_LCSR_DSAT_TM_BLT
;
1444 if (cycle
& VME_MBLT
)
1445 val
|= TSI148_LCSR_DSAT_TM_MBLT
;
1447 if (cycle
& VME_2eVME
)
1448 val
|= TSI148_LCSR_DSAT_TM_2eVME
;
1450 if (cycle
& VME_2eSST
)
1451 val
|= TSI148_LCSR_DSAT_TM_2eSST
;
1453 if (cycle
& VME_2eSSTB
) {
1454 dev_err(dev
, "Currently not setting Broadcast Select "
1456 val
|= TSI148_LCSR_DSAT_TM_2eSSTB
;
1459 /* Setup data width */
1462 val
|= TSI148_LCSR_DSAT_DBW_16
;
1465 val
|= TSI148_LCSR_DSAT_DBW_32
;
1468 dev_err(dev
, "Invalid data width\n");
1472 /* Setup address space */
1475 val
|= TSI148_LCSR_DSAT_AMODE_A16
;
1478 val
|= TSI148_LCSR_DSAT_AMODE_A24
;
1481 val
|= TSI148_LCSR_DSAT_AMODE_A32
;
1484 val
|= TSI148_LCSR_DSAT_AMODE_A64
;
1487 val
|= TSI148_LCSR_DSAT_AMODE_CRCSR
;
1490 val
|= TSI148_LCSR_DSAT_AMODE_USER1
;
1493 val
|= TSI148_LCSR_DSAT_AMODE_USER2
;
1496 val
|= TSI148_LCSR_DSAT_AMODE_USER3
;
1499 val
|= TSI148_LCSR_DSAT_AMODE_USER4
;
1502 dev_err(dev
, "Invalid address space\n");
1506 if (cycle
& VME_SUPER
)
1507 val
|= TSI148_LCSR_DSAT_SUP
;
1508 if (cycle
& VME_PROG
)
1509 val
|= TSI148_LCSR_DSAT_PGM
;
1511 *attr
= cpu_to_be32(val
);
1516 static int tsi148_dma_set_vme_dest_attributes(struct device
*dev
, __be32
*attr
,
1517 u32 aspace
, u32 cycle
, u32 dwidth
)
1521 val
= be32_to_cpu(*attr
);
1523 /* Setup 2eSST speeds */
1524 switch (cycle
& (VME_2eSST160
| VME_2eSST267
| VME_2eSST320
)) {
1526 val
|= TSI148_LCSR_DDAT_2eSSTM_160
;
1529 val
|= TSI148_LCSR_DDAT_2eSSTM_267
;
1532 val
|= TSI148_LCSR_DDAT_2eSSTM_320
;
1536 /* Setup cycle types */
1537 if (cycle
& VME_SCT
)
1538 val
|= TSI148_LCSR_DDAT_TM_SCT
;
1540 if (cycle
& VME_BLT
)
1541 val
|= TSI148_LCSR_DDAT_TM_BLT
;
1543 if (cycle
& VME_MBLT
)
1544 val
|= TSI148_LCSR_DDAT_TM_MBLT
;
1546 if (cycle
& VME_2eVME
)
1547 val
|= TSI148_LCSR_DDAT_TM_2eVME
;
1549 if (cycle
& VME_2eSST
)
1550 val
|= TSI148_LCSR_DDAT_TM_2eSST
;
1552 if (cycle
& VME_2eSSTB
) {
1553 dev_err(dev
, "Currently not setting Broadcast Select "
1555 val
|= TSI148_LCSR_DDAT_TM_2eSSTB
;
1558 /* Setup data width */
1561 val
|= TSI148_LCSR_DDAT_DBW_16
;
1564 val
|= TSI148_LCSR_DDAT_DBW_32
;
1567 dev_err(dev
, "Invalid data width\n");
1571 /* Setup address space */
1574 val
|= TSI148_LCSR_DDAT_AMODE_A16
;
1577 val
|= TSI148_LCSR_DDAT_AMODE_A24
;
1580 val
|= TSI148_LCSR_DDAT_AMODE_A32
;
1583 val
|= TSI148_LCSR_DDAT_AMODE_A64
;
1586 val
|= TSI148_LCSR_DDAT_AMODE_CRCSR
;
1589 val
|= TSI148_LCSR_DDAT_AMODE_USER1
;
1592 val
|= TSI148_LCSR_DDAT_AMODE_USER2
;
1595 val
|= TSI148_LCSR_DDAT_AMODE_USER3
;
1598 val
|= TSI148_LCSR_DDAT_AMODE_USER4
;
1601 dev_err(dev
, "Invalid address space\n");
1605 if (cycle
& VME_SUPER
)
1606 val
|= TSI148_LCSR_DDAT_SUP
;
1607 if (cycle
& VME_PROG
)
1608 val
|= TSI148_LCSR_DDAT_PGM
;
1610 *attr
= cpu_to_be32(val
);
1616 * Add a link list descriptor to the list
1618 * Note: DMA engine expects the DMA descriptor to be big endian.
1620 static int tsi148_dma_list_add(struct vme_dma_list
*list
,
1621 struct vme_dma_attr
*src
, struct vme_dma_attr
*dest
, size_t count
)
1623 struct tsi148_dma_entry
*entry
, *prev
;
1624 u32 address_high
, address_low
, val
;
1625 struct vme_dma_pattern
*pattern_attr
;
1626 struct vme_dma_pci
*pci_attr
;
1627 struct vme_dma_vme
*vme_attr
;
1629 struct vme_bridge
*tsi148_bridge
;
1631 tsi148_bridge
= list
->parent
->parent
;
1633 /* Descriptor must be aligned on 64-bit boundaries */
1634 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
1640 /* Test descriptor alignment */
1641 if ((unsigned long)&entry
->descriptor
& 0x7) {
1642 dev_err(tsi148_bridge
->parent
, "Descriptor not aligned to 8 "
1643 "byte boundary as required: %p\n",
1644 &entry
->descriptor
);
1649 /* Given we are going to fill out the structure, we probably don't
1650 * need to zero it, but better safe than sorry for now.
1652 memset(&entry
->descriptor
, 0, sizeof(entry
->descriptor
));
1654 /* Fill out source part */
1655 switch (src
->type
) {
1656 case VME_DMA_PATTERN
:
1657 pattern_attr
= src
->private;
1659 entry
->descriptor
.dsal
= cpu_to_be32(pattern_attr
->pattern
);
1661 val
= TSI148_LCSR_DSAT_TYP_PAT
;
1663 /* Default behaviour is 32 bit pattern */
1664 if (pattern_attr
->type
& VME_DMA_PATTERN_BYTE
)
1665 val
|= TSI148_LCSR_DSAT_PSZ
;
1667 /* It seems that the default behaviour is to increment */
1668 if ((pattern_attr
->type
& VME_DMA_PATTERN_INCREMENT
) == 0)
1669 val
|= TSI148_LCSR_DSAT_NIN
;
1670 entry
->descriptor
.dsat
= cpu_to_be32(val
);
1673 pci_attr
= src
->private;
1675 reg_split((unsigned long long)pci_attr
->address
, &address_high
,
1677 entry
->descriptor
.dsau
= cpu_to_be32(address_high
);
1678 entry
->descriptor
.dsal
= cpu_to_be32(address_low
);
1679 entry
->descriptor
.dsat
= cpu_to_be32(TSI148_LCSR_DSAT_TYP_PCI
);
1682 vme_attr
= src
->private;
1684 reg_split((unsigned long long)vme_attr
->address
, &address_high
,
1686 entry
->descriptor
.dsau
= cpu_to_be32(address_high
);
1687 entry
->descriptor
.dsal
= cpu_to_be32(address_low
);
1688 entry
->descriptor
.dsat
= cpu_to_be32(TSI148_LCSR_DSAT_TYP_VME
);
1690 retval
= tsi148_dma_set_vme_src_attributes(
1691 tsi148_bridge
->parent
, &entry
->descriptor
.dsat
,
1692 vme_attr
->aspace
, vme_attr
->cycle
, vme_attr
->dwidth
);
1697 dev_err(tsi148_bridge
->parent
, "Invalid source type\n");
1702 /* Assume last link - this will be over-written by adding another */
1703 entry
->descriptor
.dnlau
= cpu_to_be32(0);
1704 entry
->descriptor
.dnlal
= cpu_to_be32(TSI148_LCSR_DNLAL_LLA
);
1706 /* Fill out destination part */
1707 switch (dest
->type
) {
1709 pci_attr
= dest
->private;
1711 reg_split((unsigned long long)pci_attr
->address
, &address_high
,
1713 entry
->descriptor
.ddau
= cpu_to_be32(address_high
);
1714 entry
->descriptor
.ddal
= cpu_to_be32(address_low
);
1715 entry
->descriptor
.ddat
= cpu_to_be32(TSI148_LCSR_DDAT_TYP_PCI
);
1718 vme_attr
= dest
->private;
1720 reg_split((unsigned long long)vme_attr
->address
, &address_high
,
1722 entry
->descriptor
.ddau
= cpu_to_be32(address_high
);
1723 entry
->descriptor
.ddal
= cpu_to_be32(address_low
);
1724 entry
->descriptor
.ddat
= cpu_to_be32(TSI148_LCSR_DDAT_TYP_VME
);
1726 retval
= tsi148_dma_set_vme_dest_attributes(
1727 tsi148_bridge
->parent
, &entry
->descriptor
.ddat
,
1728 vme_attr
->aspace
, vme_attr
->cycle
, vme_attr
->dwidth
);
1733 dev_err(tsi148_bridge
->parent
, "Invalid destination type\n");
1738 /* Fill out count */
1739 entry
->descriptor
.dcnt
= cpu_to_be32((u32
)count
);
1742 list_add_tail(&entry
->list
, &list
->entries
);
1744 entry
->dma_handle
= dma_map_single(tsi148_bridge
->parent
,
1746 sizeof(entry
->descriptor
),
1748 if (dma_mapping_error(tsi148_bridge
->parent
, entry
->dma_handle
)) {
1749 dev_err(tsi148_bridge
->parent
, "DMA mapping error\n");
1754 /* Fill out previous descriptors "Next Address" */
1755 if (entry
->list
.prev
!= &list
->entries
) {
1756 reg_split((unsigned long long)entry
->dma_handle
, &address_high
,
1758 prev
= list_entry(entry
->list
.prev
, struct tsi148_dma_entry
,
1760 prev
->descriptor
.dnlau
= cpu_to_be32(address_high
);
1761 prev
->descriptor
.dnlal
= cpu_to_be32(address_low
);
1777 * Check to see if the provided DMA channel is busy.
1779 static int tsi148_dma_busy(struct vme_bridge
*tsi148_bridge
, int channel
)
1782 struct tsi148_driver
*bridge
;
1784 bridge
= tsi148_bridge
->driver_priv
;
1786 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_DMA
[channel
] +
1787 TSI148_LCSR_OFFSET_DSTA
);
1789 if (tmp
& TSI148_LCSR_DSTA_BSY
)
1797 * Execute a previously generated link list
1799 * XXX Need to provide control register configuration.
1801 static int tsi148_dma_list_exec(struct vme_dma_list
*list
)
1803 struct vme_dma_resource
*ctrlr
;
1804 int channel
, retval
;
1805 struct tsi148_dma_entry
*entry
;
1806 u32 bus_addr_high
, bus_addr_low
;
1807 u32 val
, dctlreg
= 0;
1808 struct vme_bridge
*tsi148_bridge
;
1809 struct tsi148_driver
*bridge
;
1811 ctrlr
= list
->parent
;
1813 tsi148_bridge
= ctrlr
->parent
;
1815 bridge
= tsi148_bridge
->driver_priv
;
1817 mutex_lock(&ctrlr
->mtx
);
1819 channel
= ctrlr
->number
;
1821 if (!list_empty(&ctrlr
->running
)) {
1823 * XXX We have an active DMA transfer and currently haven't
1824 * sorted out the mechanism for "pending" DMA transfers.
1827 /* Need to add to pending here */
1828 mutex_unlock(&ctrlr
->mtx
);
1831 list_add(&list
->list
, &ctrlr
->running
);
1834 /* Get first bus address and write into registers */
1835 entry
= list_first_entry(&list
->entries
, struct tsi148_dma_entry
,
1838 mutex_unlock(&ctrlr
->mtx
);
1840 reg_split(entry
->dma_handle
, &bus_addr_high
, &bus_addr_low
);
1842 iowrite32be(bus_addr_high
, bridge
->base
+
1843 TSI148_LCSR_DMA
[channel
] + TSI148_LCSR_OFFSET_DNLAU
);
1844 iowrite32be(bus_addr_low
, bridge
->base
+
1845 TSI148_LCSR_DMA
[channel
] + TSI148_LCSR_OFFSET_DNLAL
);
1847 dctlreg
= ioread32be(bridge
->base
+ TSI148_LCSR_DMA
[channel
] +
1848 TSI148_LCSR_OFFSET_DCTL
);
1850 /* Start the operation */
1851 iowrite32be(dctlreg
| TSI148_LCSR_DCTL_DGO
, bridge
->base
+
1852 TSI148_LCSR_DMA
[channel
] + TSI148_LCSR_OFFSET_DCTL
);
1854 retval
= wait_event_interruptible(bridge
->dma_queue
[channel
],
1855 tsi148_dma_busy(ctrlr
->parent
, channel
));
1858 iowrite32be(dctlreg
| TSI148_LCSR_DCTL_ABT
, bridge
->base
+
1859 TSI148_LCSR_DMA
[channel
] + TSI148_LCSR_OFFSET_DCTL
);
1860 /* Wait for the operation to abort */
1861 wait_event(bridge
->dma_queue
[channel
],
1862 tsi148_dma_busy(ctrlr
->parent
, channel
));
1868 * Read status register, this register is valid until we kick off a
1871 val
= ioread32be(bridge
->base
+ TSI148_LCSR_DMA
[channel
] +
1872 TSI148_LCSR_OFFSET_DSTA
);
1874 if (val
& TSI148_LCSR_DSTA_VBE
) {
1875 dev_err(tsi148_bridge
->parent
, "DMA Error. DSTA=%08X\n", val
);
1880 /* Remove list from running list */
1881 mutex_lock(&ctrlr
->mtx
);
1882 list_del(&list
->list
);
1883 mutex_unlock(&ctrlr
->mtx
);
1889 * Clean up a previously generated link list
1891 * We have a separate function, don't assume that the chain can't be reused.
1893 static int tsi148_dma_list_empty(struct vme_dma_list
*list
)
1895 struct list_head
*pos
, *temp
;
1896 struct tsi148_dma_entry
*entry
;
1898 struct vme_bridge
*tsi148_bridge
= list
->parent
->parent
;
1900 /* detach and free each entry */
1901 list_for_each_safe(pos
, temp
, &list
->entries
) {
1903 entry
= list_entry(pos
, struct tsi148_dma_entry
, list
);
1905 dma_unmap_single(tsi148_bridge
->parent
, entry
->dma_handle
,
1906 sizeof(struct tsi148_dma_descriptor
), DMA_TO_DEVICE
);
1914 * All 4 location monitors reside at the same base - this is therefore a
1915 * system wide configuration.
1917 * This does not enable the LM monitor - that should be done when the first
1918 * callback is attached and disabled when the last callback is removed.
1920 static int tsi148_lm_set(struct vme_lm_resource
*lm
, unsigned long long lm_base
,
1921 u32 aspace
, u32 cycle
)
1923 u32 lm_base_high
, lm_base_low
, lm_ctl
= 0;
1925 struct vme_bridge
*tsi148_bridge
;
1926 struct tsi148_driver
*bridge
;
1928 tsi148_bridge
= lm
->parent
;
1930 bridge
= tsi148_bridge
->driver_priv
;
1932 mutex_lock(&lm
->mtx
);
1934 /* If we already have a callback attached, we can't move it! */
1935 for (i
= 0; i
< lm
->monitors
; i
++) {
1936 if (bridge
->lm_callback
[i
]) {
1937 mutex_unlock(&lm
->mtx
);
1938 dev_err(tsi148_bridge
->parent
, "Location monitor "
1939 "callback attached, can't reset\n");
1946 lm_ctl
|= TSI148_LCSR_LMAT_AS_A16
;
1949 lm_ctl
|= TSI148_LCSR_LMAT_AS_A24
;
1952 lm_ctl
|= TSI148_LCSR_LMAT_AS_A32
;
1955 lm_ctl
|= TSI148_LCSR_LMAT_AS_A64
;
1958 mutex_unlock(&lm
->mtx
);
1959 dev_err(tsi148_bridge
->parent
, "Invalid address space\n");
1963 if (cycle
& VME_SUPER
)
1964 lm_ctl
|= TSI148_LCSR_LMAT_SUPR
;
1965 if (cycle
& VME_USER
)
1966 lm_ctl
|= TSI148_LCSR_LMAT_NPRIV
;
1967 if (cycle
& VME_PROG
)
1968 lm_ctl
|= TSI148_LCSR_LMAT_PGM
;
1969 if (cycle
& VME_DATA
)
1970 lm_ctl
|= TSI148_LCSR_LMAT_DATA
;
1972 reg_split(lm_base
, &lm_base_high
, &lm_base_low
);
1974 iowrite32be(lm_base_high
, bridge
->base
+ TSI148_LCSR_LMBAU
);
1975 iowrite32be(lm_base_low
, bridge
->base
+ TSI148_LCSR_LMBAL
);
1976 iowrite32be(lm_ctl
, bridge
->base
+ TSI148_LCSR_LMAT
);
1978 mutex_unlock(&lm
->mtx
);
1983 /* Get configuration of the callback monitor and return whether it is enabled
1986 static int tsi148_lm_get(struct vme_lm_resource
*lm
,
1987 unsigned long long *lm_base
, u32
*aspace
, u32
*cycle
)
1989 u32 lm_base_high
, lm_base_low
, lm_ctl
, enabled
= 0;
1990 struct tsi148_driver
*bridge
;
1992 bridge
= lm
->parent
->driver_priv
;
1994 mutex_lock(&lm
->mtx
);
1996 lm_base_high
= ioread32be(bridge
->base
+ TSI148_LCSR_LMBAU
);
1997 lm_base_low
= ioread32be(bridge
->base
+ TSI148_LCSR_LMBAL
);
1998 lm_ctl
= ioread32be(bridge
->base
+ TSI148_LCSR_LMAT
);
2000 reg_join(lm_base_high
, lm_base_low
, lm_base
);
2002 if (lm_ctl
& TSI148_LCSR_LMAT_EN
)
2005 if ((lm_ctl
& TSI148_LCSR_LMAT_AS_M
) == TSI148_LCSR_LMAT_AS_A16
)
2008 if ((lm_ctl
& TSI148_LCSR_LMAT_AS_M
) == TSI148_LCSR_LMAT_AS_A24
)
2011 if ((lm_ctl
& TSI148_LCSR_LMAT_AS_M
) == TSI148_LCSR_LMAT_AS_A32
)
2014 if ((lm_ctl
& TSI148_LCSR_LMAT_AS_M
) == TSI148_LCSR_LMAT_AS_A64
)
2018 if (lm_ctl
& TSI148_LCSR_LMAT_SUPR
)
2019 *cycle
|= VME_SUPER
;
2020 if (lm_ctl
& TSI148_LCSR_LMAT_NPRIV
)
2022 if (lm_ctl
& TSI148_LCSR_LMAT_PGM
)
2024 if (lm_ctl
& TSI148_LCSR_LMAT_DATA
)
2027 mutex_unlock(&lm
->mtx
);
2033 * Attach a callback to a specific location monitor.
2035 * Callback will be passed the monitor triggered.
2037 static int tsi148_lm_attach(struct vme_lm_resource
*lm
, int monitor
,
2038 void (*callback
)(void *), void *data
)
2041 struct vme_bridge
*tsi148_bridge
;
2042 struct tsi148_driver
*bridge
;
2044 tsi148_bridge
= lm
->parent
;
2046 bridge
= tsi148_bridge
->driver_priv
;
2048 mutex_lock(&lm
->mtx
);
2050 /* Ensure that the location monitor is configured - need PGM or DATA */
2051 lm_ctl
= ioread32be(bridge
->base
+ TSI148_LCSR_LMAT
);
2052 if ((lm_ctl
& (TSI148_LCSR_LMAT_PGM
| TSI148_LCSR_LMAT_DATA
)) == 0) {
2053 mutex_unlock(&lm
->mtx
);
2054 dev_err(tsi148_bridge
->parent
, "Location monitor not properly "
2059 /* Check that a callback isn't already attached */
2060 if (bridge
->lm_callback
[monitor
]) {
2061 mutex_unlock(&lm
->mtx
);
2062 dev_err(tsi148_bridge
->parent
, "Existing callback attached\n");
2066 /* Attach callback */
2067 bridge
->lm_callback
[monitor
] = callback
;
2068 bridge
->lm_data
[monitor
] = data
;
2070 /* Enable Location Monitor interrupt */
2071 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_INTEN
);
2072 tmp
|= TSI148_LCSR_INTEN_LMEN
[monitor
];
2073 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_INTEN
);
2075 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_INTEO
);
2076 tmp
|= TSI148_LCSR_INTEO_LMEO
[monitor
];
2077 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_INTEO
);
2079 /* Ensure that global Location Monitor Enable set */
2080 if ((lm_ctl
& TSI148_LCSR_LMAT_EN
) == 0) {
2081 lm_ctl
|= TSI148_LCSR_LMAT_EN
;
2082 iowrite32be(lm_ctl
, bridge
->base
+ TSI148_LCSR_LMAT
);
2085 mutex_unlock(&lm
->mtx
);
2091 * Detach a callback function forn a specific location monitor.
2093 static int tsi148_lm_detach(struct vme_lm_resource
*lm
, int monitor
)
2096 struct tsi148_driver
*bridge
;
2098 bridge
= lm
->parent
->driver_priv
;
2100 mutex_lock(&lm
->mtx
);
2102 /* Disable Location Monitor and ensure previous interrupts are clear */
2103 lm_en
= ioread32be(bridge
->base
+ TSI148_LCSR_INTEN
);
2104 lm_en
&= ~TSI148_LCSR_INTEN_LMEN
[monitor
];
2105 iowrite32be(lm_en
, bridge
->base
+ TSI148_LCSR_INTEN
);
2107 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_INTEO
);
2108 tmp
&= ~TSI148_LCSR_INTEO_LMEO
[monitor
];
2109 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_INTEO
);
2111 iowrite32be(TSI148_LCSR_INTC_LMC
[monitor
],
2112 bridge
->base
+ TSI148_LCSR_INTC
);
2114 /* Detach callback */
2115 bridge
->lm_callback
[monitor
] = NULL
;
2116 bridge
->lm_data
[monitor
] = NULL
;
2118 /* If all location monitors disabled, disable global Location Monitor */
2119 if ((lm_en
& (TSI148_LCSR_INTS_LM0S
| TSI148_LCSR_INTS_LM1S
|
2120 TSI148_LCSR_INTS_LM2S
| TSI148_LCSR_INTS_LM3S
)) == 0) {
2121 tmp
= ioread32be(bridge
->base
+ TSI148_LCSR_LMAT
);
2122 tmp
&= ~TSI148_LCSR_LMAT_EN
;
2123 iowrite32be(tmp
, bridge
->base
+ TSI148_LCSR_LMAT
);
2126 mutex_unlock(&lm
->mtx
);
2132 * Determine Geographical Addressing
2134 static int tsi148_slot_get(struct vme_bridge
*tsi148_bridge
)
2137 struct tsi148_driver
*bridge
;
2139 bridge
= tsi148_bridge
->driver_priv
;
2142 slot
= ioread32be(bridge
->base
+ TSI148_LCSR_VSTAT
);
2143 slot
= slot
& TSI148_LCSR_VSTAT_GA_M
;
2150 static void *tsi148_alloc_consistent(struct device
*parent
, size_t size
,
2153 struct pci_dev
*pdev
;
2155 /* Find pci_dev container of dev */
2156 pdev
= to_pci_dev(parent
);
2158 return dma_alloc_coherent(&pdev
->dev
, size
, dma
, GFP_KERNEL
);
2161 static void tsi148_free_consistent(struct device
*parent
, size_t size
,
2162 void *vaddr
, dma_addr_t dma
)
2164 struct pci_dev
*pdev
;
2166 /* Find pci_dev container of dev */
2167 pdev
= to_pci_dev(parent
);
2169 dma_free_coherent(&pdev
->dev
, size
, vaddr
, dma
);
2173 * Configure CR/CSR space
2175 * Access to the CR/CSR can be configured at power-up. The location of the
2176 * CR/CSR registers in the CR/CSR address space is determined by the boards
2177 * Auto-ID or Geographic address. This function ensures that the window is
2178 * enabled at an offset consistent with the boards geopgraphic address.
2180 * Each board has a 512kB window, with the highest 4kB being used for the
2181 * boards registers, this means there is a fix length 508kB window which must
2182 * be mapped onto PCI memory.
2184 static int tsi148_crcsr_init(struct vme_bridge
*tsi148_bridge
,
2185 struct pci_dev
*pdev
)
2187 u32 cbar
, crat
, vstat
;
2188 u32 crcsr_bus_high
, crcsr_bus_low
;
2190 struct tsi148_driver
*bridge
;
2192 bridge
= tsi148_bridge
->driver_priv
;
2194 /* Allocate mem for CR/CSR image */
2195 bridge
->crcsr_kernel
= dma_alloc_coherent(&pdev
->dev
,
2197 &bridge
->crcsr_bus
, GFP_KERNEL
);
2198 if (!bridge
->crcsr_kernel
) {
2199 dev_err(tsi148_bridge
->parent
, "Failed to allocate memory for "
2204 reg_split(bridge
->crcsr_bus
, &crcsr_bus_high
, &crcsr_bus_low
);
2206 iowrite32be(crcsr_bus_high
, bridge
->base
+ TSI148_LCSR_CROU
);
2207 iowrite32be(crcsr_bus_low
, bridge
->base
+ TSI148_LCSR_CROL
);
2209 /* Ensure that the CR/CSR is configured at the correct offset */
2210 cbar
= ioread32be(bridge
->base
+ TSI148_CBAR
);
2211 cbar
= (cbar
& TSI148_CRCSR_CBAR_M
)>>3;
2213 vstat
= tsi148_slot_get(tsi148_bridge
);
2215 if (cbar
!= vstat
) {
2217 dev_info(tsi148_bridge
->parent
, "Setting CR/CSR offset\n");
2218 iowrite32be(cbar
<<3, bridge
->base
+ TSI148_CBAR
);
2220 dev_info(tsi148_bridge
->parent
, "CR/CSR Offset: %d\n", cbar
);
2222 crat
= ioread32be(bridge
->base
+ TSI148_LCSR_CRAT
);
2223 if (crat
& TSI148_LCSR_CRAT_EN
)
2224 dev_info(tsi148_bridge
->parent
, "CR/CSR already enabled\n");
2226 dev_info(tsi148_bridge
->parent
, "Enabling CR/CSR space\n");
2227 iowrite32be(crat
| TSI148_LCSR_CRAT_EN
,
2228 bridge
->base
+ TSI148_LCSR_CRAT
);
2231 /* If we want flushed, error-checked writes, set up a window
2232 * over the CR/CSR registers. We read from here to safely flush
2233 * through VME writes.
2236 retval
= tsi148_master_set(bridge
->flush_image
, 1,
2237 (vstat
* 0x80000), 0x80000, VME_CRCSR
, VME_SCT
,
2240 dev_err(tsi148_bridge
->parent
, "Configuring flush image"
2248 static void tsi148_crcsr_exit(struct vme_bridge
*tsi148_bridge
,
2249 struct pci_dev
*pdev
)
2252 struct tsi148_driver
*bridge
;
2254 bridge
= tsi148_bridge
->driver_priv
;
2256 /* Turn off CR/CSR space */
2257 crat
= ioread32be(bridge
->base
+ TSI148_LCSR_CRAT
);
2258 iowrite32be(crat
& ~TSI148_LCSR_CRAT_EN
,
2259 bridge
->base
+ TSI148_LCSR_CRAT
);
2262 iowrite32be(0, bridge
->base
+ TSI148_LCSR_CROU
);
2263 iowrite32be(0, bridge
->base
+ TSI148_LCSR_CROL
);
2265 dma_free_coherent(&pdev
->dev
, VME_CRCSR_BUF_SIZE
,
2266 bridge
->crcsr_kernel
, bridge
->crcsr_bus
);
2269 static int tsi148_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2271 int retval
, i
, master_num
;
2273 struct list_head
*pos
= NULL
, *n
;
2274 struct vme_bridge
*tsi148_bridge
;
2275 struct tsi148_driver
*tsi148_device
;
2276 struct vme_master_resource
*master_image
;
2277 struct vme_slave_resource
*slave_image
;
2278 struct vme_dma_resource
*dma_ctrlr
;
2279 struct vme_lm_resource
*lm
;
2281 /* If we want to support more than one of each bridge, we need to
2282 * dynamically generate this so we get one per device
2284 tsi148_bridge
= kzalloc(sizeof(*tsi148_bridge
), GFP_KERNEL
);
2285 if (!tsi148_bridge
) {
2289 vme_init_bridge(tsi148_bridge
);
2291 tsi148_device
= kzalloc(sizeof(*tsi148_device
), GFP_KERNEL
);
2292 if (!tsi148_device
) {
2297 tsi148_bridge
->driver_priv
= tsi148_device
;
2299 /* Enable the device */
2300 retval
= pci_enable_device(pdev
);
2302 dev_err(&pdev
->dev
, "Unable to enable device\n");
2307 retval
= pci_request_regions(pdev
, driver_name
);
2309 dev_err(&pdev
->dev
, "Unable to reserve resources\n");
2313 /* map registers in BAR 0 */
2314 tsi148_device
->base
= ioremap(pci_resource_start(pdev
, 0),
2316 if (!tsi148_device
->base
) {
2317 dev_err(&pdev
->dev
, "Unable to remap CRG region\n");
2322 /* Check to see if the mapping worked out */
2323 data
= ioread32(tsi148_device
->base
+ TSI148_PCFS_ID
) & 0x0000FFFF;
2324 if (data
!= PCI_VENDOR_ID_TUNDRA
) {
2325 dev_err(&pdev
->dev
, "CRG region check failed\n");
2330 /* Initialize wait queues & mutual exclusion flags */
2331 init_waitqueue_head(&tsi148_device
->dma_queue
[0]);
2332 init_waitqueue_head(&tsi148_device
->dma_queue
[1]);
2333 init_waitqueue_head(&tsi148_device
->iack_queue
);
2334 mutex_init(&tsi148_device
->vme_int
);
2335 mutex_init(&tsi148_device
->vme_rmw
);
2337 tsi148_bridge
->parent
= &pdev
->dev
;
2338 strcpy(tsi148_bridge
->name
, driver_name
);
2341 retval
= tsi148_irq_init(tsi148_bridge
);
2343 dev_err(&pdev
->dev
, "Chip Initialization failed.\n");
2347 /* If we are going to flush writes, we need to read from the VME bus.
2348 * We need to do this safely, thus we read the devices own CR/CSR
2349 * register. To do this we must set up a window in CR/CSR space and
2350 * hence have one less master window resource available.
2352 master_num
= TSI148_MAX_MASTER
;
2356 tsi148_device
->flush_image
=
2357 kmalloc(sizeof(*tsi148_device
->flush_image
),
2359 if (!tsi148_device
->flush_image
) {
2363 tsi148_device
->flush_image
->parent
= tsi148_bridge
;
2364 spin_lock_init(&tsi148_device
->flush_image
->lock
);
2365 tsi148_device
->flush_image
->locked
= 1;
2366 tsi148_device
->flush_image
->number
= master_num
;
2367 memset(&tsi148_device
->flush_image
->bus_resource
, 0,
2368 sizeof(tsi148_device
->flush_image
->bus_resource
));
2369 tsi148_device
->flush_image
->kern_base
= NULL
;
2372 /* Add master windows to list */
2373 for (i
= 0; i
< master_num
; i
++) {
2374 master_image
= kmalloc(sizeof(*master_image
), GFP_KERNEL
);
2375 if (!master_image
) {
2379 master_image
->parent
= tsi148_bridge
;
2380 spin_lock_init(&master_image
->lock
);
2381 master_image
->locked
= 0;
2382 master_image
->number
= i
;
2383 master_image
->address_attr
= VME_A16
| VME_A24
| VME_A32
|
2384 VME_A64
| VME_CRCSR
| VME_USER1
| VME_USER2
|
2385 VME_USER3
| VME_USER4
;
2386 master_image
->cycle_attr
= VME_SCT
| VME_BLT
| VME_MBLT
|
2387 VME_2eVME
| VME_2eSST
| VME_2eSSTB
| VME_2eSST160
|
2388 VME_2eSST267
| VME_2eSST320
| VME_SUPER
| VME_USER
|
2389 VME_PROG
| VME_DATA
;
2390 master_image
->width_attr
= VME_D16
| VME_D32
;
2391 memset(&master_image
->bus_resource
, 0,
2392 sizeof(master_image
->bus_resource
));
2393 master_image
->kern_base
= NULL
;
2394 list_add_tail(&master_image
->list
,
2395 &tsi148_bridge
->master_resources
);
2398 /* Add slave windows to list */
2399 for (i
= 0; i
< TSI148_MAX_SLAVE
; i
++) {
2400 slave_image
= kmalloc(sizeof(*slave_image
), GFP_KERNEL
);
2405 slave_image
->parent
= tsi148_bridge
;
2406 mutex_init(&slave_image
->mtx
);
2407 slave_image
->locked
= 0;
2408 slave_image
->number
= i
;
2409 slave_image
->address_attr
= VME_A16
| VME_A24
| VME_A32
|
2411 slave_image
->cycle_attr
= VME_SCT
| VME_BLT
| VME_MBLT
|
2412 VME_2eVME
| VME_2eSST
| VME_2eSSTB
| VME_2eSST160
|
2413 VME_2eSST267
| VME_2eSST320
| VME_SUPER
| VME_USER
|
2414 VME_PROG
| VME_DATA
;
2415 list_add_tail(&slave_image
->list
,
2416 &tsi148_bridge
->slave_resources
);
2419 /* Add dma engines to list */
2420 for (i
= 0; i
< TSI148_MAX_DMA
; i
++) {
2421 dma_ctrlr
= kmalloc(sizeof(*dma_ctrlr
), GFP_KERNEL
);
2426 dma_ctrlr
->parent
= tsi148_bridge
;
2427 mutex_init(&dma_ctrlr
->mtx
);
2428 dma_ctrlr
->locked
= 0;
2429 dma_ctrlr
->number
= i
;
2430 dma_ctrlr
->route_attr
= VME_DMA_VME_TO_MEM
|
2431 VME_DMA_MEM_TO_VME
| VME_DMA_VME_TO_VME
|
2432 VME_DMA_MEM_TO_MEM
| VME_DMA_PATTERN_TO_VME
|
2433 VME_DMA_PATTERN_TO_MEM
;
2434 INIT_LIST_HEAD(&dma_ctrlr
->pending
);
2435 INIT_LIST_HEAD(&dma_ctrlr
->running
);
2436 list_add_tail(&dma_ctrlr
->list
,
2437 &tsi148_bridge
->dma_resources
);
2440 /* Add location monitor to list */
2441 lm
= kmalloc(sizeof(*lm
), GFP_KERNEL
);
2446 lm
->parent
= tsi148_bridge
;
2447 mutex_init(&lm
->mtx
);
2451 list_add_tail(&lm
->list
, &tsi148_bridge
->lm_resources
);
2453 tsi148_bridge
->slave_get
= tsi148_slave_get
;
2454 tsi148_bridge
->slave_set
= tsi148_slave_set
;
2455 tsi148_bridge
->master_get
= tsi148_master_get
;
2456 tsi148_bridge
->master_set
= tsi148_master_set
;
2457 tsi148_bridge
->master_read
= tsi148_master_read
;
2458 tsi148_bridge
->master_write
= tsi148_master_write
;
2459 tsi148_bridge
->master_rmw
= tsi148_master_rmw
;
2460 tsi148_bridge
->dma_list_add
= tsi148_dma_list_add
;
2461 tsi148_bridge
->dma_list_exec
= tsi148_dma_list_exec
;
2462 tsi148_bridge
->dma_list_empty
= tsi148_dma_list_empty
;
2463 tsi148_bridge
->irq_set
= tsi148_irq_set
;
2464 tsi148_bridge
->irq_generate
= tsi148_irq_generate
;
2465 tsi148_bridge
->lm_set
= tsi148_lm_set
;
2466 tsi148_bridge
->lm_get
= tsi148_lm_get
;
2467 tsi148_bridge
->lm_attach
= tsi148_lm_attach
;
2468 tsi148_bridge
->lm_detach
= tsi148_lm_detach
;
2469 tsi148_bridge
->slot_get
= tsi148_slot_get
;
2470 tsi148_bridge
->alloc_consistent
= tsi148_alloc_consistent
;
2471 tsi148_bridge
->free_consistent
= tsi148_free_consistent
;
2473 data
= ioread32be(tsi148_device
->base
+ TSI148_LCSR_VSTAT
);
2474 dev_info(&pdev
->dev
, "Board is%s the VME system controller\n",
2475 (data
& TSI148_LCSR_VSTAT_SCONS
) ? "" : " not");
2477 dev_info(&pdev
->dev
, "VME geographical address is %d\n",
2478 data
& TSI148_LCSR_VSTAT_GA_M
);
2480 dev_info(&pdev
->dev
, "VME geographical address is set to %d\n",
2483 dev_info(&pdev
->dev
, "VME Write and flush and error check is %s\n",
2484 err_chk
? "enabled" : "disabled");
2486 retval
= tsi148_crcsr_init(tsi148_bridge
, pdev
);
2488 dev_err(&pdev
->dev
, "CR/CSR configuration failed.\n");
2492 retval
= vme_register_bridge(tsi148_bridge
);
2494 dev_err(&pdev
->dev
, "Chip Registration failed.\n");
2498 pci_set_drvdata(pdev
, tsi148_bridge
);
2500 /* Clear VME bus "board fail", and "power-up reset" lines */
2501 data
= ioread32be(tsi148_device
->base
+ TSI148_LCSR_VSTAT
);
2502 data
&= ~TSI148_LCSR_VSTAT_BRDFL
;
2503 data
|= TSI148_LCSR_VSTAT_CPURST
;
2504 iowrite32be(data
, tsi148_device
->base
+ TSI148_LCSR_VSTAT
);
2509 tsi148_crcsr_exit(tsi148_bridge
, pdev
);
2512 /* resources are stored in link list */
2513 list_for_each_safe(pos
, n
, &tsi148_bridge
->lm_resources
) {
2514 lm
= list_entry(pos
, struct vme_lm_resource
, list
);
2519 /* resources are stored in link list */
2520 list_for_each_safe(pos
, n
, &tsi148_bridge
->dma_resources
) {
2521 dma_ctrlr
= list_entry(pos
, struct vme_dma_resource
, list
);
2526 /* resources are stored in link list */
2527 list_for_each_safe(pos
, n
, &tsi148_bridge
->slave_resources
) {
2528 slave_image
= list_entry(pos
, struct vme_slave_resource
, list
);
2533 /* resources are stored in link list */
2534 list_for_each_safe(pos
, n
, &tsi148_bridge
->master_resources
) {
2535 master_image
= list_entry(pos
, struct vme_master_resource
,
2538 kfree(master_image
);
2541 tsi148_irq_exit(tsi148_bridge
, pdev
);
2544 iounmap(tsi148_device
->base
);
2546 pci_release_regions(pdev
);
2548 pci_disable_device(pdev
);
2550 kfree(tsi148_device
);
2552 kfree(tsi148_bridge
);
2558 static void tsi148_remove(struct pci_dev
*pdev
)
2560 struct list_head
*pos
= NULL
;
2561 struct list_head
*tmplist
;
2562 struct vme_master_resource
*master_image
;
2563 struct vme_slave_resource
*slave_image
;
2564 struct vme_dma_resource
*dma_ctrlr
;
2566 struct tsi148_driver
*bridge
;
2567 struct vme_bridge
*tsi148_bridge
= pci_get_drvdata(pdev
);
2569 bridge
= tsi148_bridge
->driver_priv
;
2572 dev_dbg(&pdev
->dev
, "Driver is being unloaded.\n");
2575 * Shutdown all inbound and outbound windows.
2577 for (i
= 0; i
< 8; i
++) {
2578 iowrite32be(0, bridge
->base
+ TSI148_LCSR_IT
[i
] +
2579 TSI148_LCSR_OFFSET_ITAT
);
2580 iowrite32be(0, bridge
->base
+ TSI148_LCSR_OT
[i
] +
2581 TSI148_LCSR_OFFSET_OTAT
);
2585 * Shutdown Location monitor.
2587 iowrite32be(0, bridge
->base
+ TSI148_LCSR_LMAT
);
2592 iowrite32be(0, bridge
->base
+ TSI148_LCSR_CSRAT
);
2595 * Clear error status.
2597 iowrite32be(0xFFFFFFFF, bridge
->base
+ TSI148_LCSR_EDPAT
);
2598 iowrite32be(0xFFFFFFFF, bridge
->base
+ TSI148_LCSR_VEAT
);
2599 iowrite32be(0x07000700, bridge
->base
+ TSI148_LCSR_PSTAT
);
2602 * Remove VIRQ interrupt (if any)
2604 if (ioread32be(bridge
->base
+ TSI148_LCSR_VICR
) & 0x800)
2605 iowrite32be(0x8000, bridge
->base
+ TSI148_LCSR_VICR
);
2608 * Map all Interrupts to PCI INTA
2610 iowrite32be(0x0, bridge
->base
+ TSI148_LCSR_INTM1
);
2611 iowrite32be(0x0, bridge
->base
+ TSI148_LCSR_INTM2
);
2613 tsi148_irq_exit(tsi148_bridge
, pdev
);
2615 vme_unregister_bridge(tsi148_bridge
);
2617 tsi148_crcsr_exit(tsi148_bridge
, pdev
);
2619 /* resources are stored in link list */
2620 list_for_each_safe(pos
, tmplist
, &tsi148_bridge
->dma_resources
) {
2621 dma_ctrlr
= list_entry(pos
, struct vme_dma_resource
, list
);
2626 /* resources are stored in link list */
2627 list_for_each_safe(pos
, tmplist
, &tsi148_bridge
->slave_resources
) {
2628 slave_image
= list_entry(pos
, struct vme_slave_resource
, list
);
2633 /* resources are stored in link list */
2634 list_for_each_safe(pos
, tmplist
, &tsi148_bridge
->master_resources
) {
2635 master_image
= list_entry(pos
, struct vme_master_resource
,
2638 kfree(master_image
);
2641 iounmap(bridge
->base
);
2643 pci_release_regions(pdev
);
2645 pci_disable_device(pdev
);
2647 kfree(tsi148_bridge
->driver_priv
);
2649 kfree(tsi148_bridge
);
2652 module_pci_driver(tsi148_driver
);
2654 MODULE_PARM_DESC(err_chk
, "Check for VME errors on reads and writes");
2655 module_param(err_chk
, bool, 0);
2657 MODULE_PARM_DESC(geoid
, "Override geographical addressing");
2658 module_param(geoid
, int, 0);
2660 MODULE_DESCRIPTION("VME driver for the Tundra Tempe VME bridge");
2661 MODULE_LICENSE("GPL");