4 ** (c) Copyright 1999 Red Hat Software
5 ** (c) Copyright 1999 SuSE GmbH
6 ** (c) Copyright 1999,2000 Hewlett-Packard Company
7 ** (c) Copyright 2000 Grant Grundler
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
14 ** This module provides access to Dino PCI bus (config/IOport spaces)
15 ** and helps manage Dino IRQ lines.
17 ** Dino interrupt handling is a bit complicated.
18 ** Dino always writes to the broadcast EIR via irr0 for now.
19 ** (BIG WARNING: using broadcast EIR is a really bad thing for SMP!)
20 ** Only one processor interrupt is used for the 11 IRQ line
23 ** The different between Built-in Dino and Card-Mode
24 ** dino is in chip initialization and pci device initialization.
26 ** Linux drivers can only use Card-Mode Dino if pci devices I/O port
27 ** BARs are configured and used by the driver. Programming MMIO address
28 ** requires substantial knowledge of available Host I/O address ranges
29 ** is currently not supported. Port/Config accessor functions are the
30 ** same. "BIOS" differences are handled within the existing routines.
34 ** 2001-06-14 : Clement Moyroud (moyroudc@esiee.fr)
35 ** - added support for the integrated RS232.
39 ** TODO: create a virtual address for each Dino HPA.
40 ** GSC code might be able to do this since IODC data tells us
41 ** how many pages are used. PCI subsystem could (must?) do this
42 ** for PCI drivers devices which implement/use MMIO registers.
45 #include <linux/config.h>
46 #include <linux/delay.h>
47 #include <linux/types.h>
48 #include <linux/kernel.h>
49 #include <linux/pci.h>
50 #include <linux/init.h>
51 #include <linux/ioport.h>
52 #include <linux/slab.h>
53 #include <linux/interrupt.h> /* for struct irqaction */
54 #include <linux/spinlock.h> /* for spinlock_t and prototypes */
58 #include <asm/system.h>
61 #include <asm/hardware.h>
68 #define DBG(x...) printk(x)
74 ** Config accessor functions only pass in the 8-bit bus number
75 ** and not the 8-bit "PCI Segment" number. Each Dino will be
76 ** assigned a PCI bus number based on "when" it's discovered.
78 ** The "secondary" bus number is set to this before calling
79 ** pci_scan_bus(). If any PPB's are present, the scan will
80 ** discover them and update the "secondary" and "subordinate"
81 ** fields in Dino's pci_bus structure.
83 ** Changes in the configuration *will* result in a different
84 ** bus number for each dino.
87 #define is_card_dino(id) ((id)->hw_type == HPHW_A_DMA)
89 #define DINO_IAR0 0x004
90 #define DINO_IODC_ADDR 0x008
91 #define DINO_IODC_DATA_0 0x008
92 #define DINO_IODC_DATA_1 0x008
93 #define DINO_IRR0 0x00C
94 #define DINO_IAR1 0x010
95 #define DINO_IRR1 0x014
96 #define DINO_IMR 0x018
97 #define DINO_IPR 0x01C
98 #define DINO_TOC_ADDR 0x020
99 #define DINO_ICR 0x024
100 #define DINO_ILR 0x028
101 #define DINO_IO_COMMAND 0x030
102 #define DINO_IO_STATUS 0x034
103 #define DINO_IO_CONTROL 0x038
104 #define DINO_IO_GSC_ERR_RESP 0x040
105 #define DINO_IO_ERR_INFO 0x044
106 #define DINO_IO_PCI_ERR_RESP 0x048
107 #define DINO_IO_FBB_EN 0x05c
108 #define DINO_IO_ADDR_EN 0x060
109 #define DINO_PCI_ADDR 0x064
110 #define DINO_CONFIG_DATA 0x068
111 #define DINO_IO_DATA 0x06c
112 #define DINO_MEM_DATA 0x070 /* Dino 3.x only */
113 #define DINO_GSC2X_CONFIG 0x7b4
114 #define DINO_GMASK 0x800
115 #define DINO_PAMR 0x804
116 #define DINO_PAPR 0x808
117 #define DINO_DAMODE 0x80c
118 #define DINO_PCICMD 0x810
119 #define DINO_PCISTS 0x814
120 #define DINO_MLTIM 0x81c
121 #define DINO_BRDG_FEAT 0x820
122 #define DINO_PCIROR 0x824
123 #define DINO_PCIWOR 0x828
124 #define DINO_TLTIM 0x830
126 #define DINO_IRQS 11 /* bits 0-10 are architected */
127 #define DINO_IRR_MASK 0x5ff /* only 10 bits are implemented */
129 #define DINO_MASK_IRQ(x) (1<<(x))
131 #define PCIINTA 0x001
132 #define PCIINTB 0x002
133 #define PCIINTC 0x004
134 #define PCIINTD 0x008
135 #define PCIINTE 0x010
136 #define PCIINTF 0x020
137 #define GSCEXTINT 0x040
138 /* #define xxx 0x080 - bit 7 is "default" */
139 /* #define xxx 0x100 - bit 8 not used */
140 /* #define xxx 0x200 - bit 9 not used */
141 #define RS232INT 0x400
145 struct pci_hba_data hba
; /* 'C' inheritance - must be first */
146 spinlock_t dinosaur_pen
;
147 unsigned long txn_addr
; /* EIR addr to generate interrupt */
148 u32 txn_data
; /* EIR data assign to each dino */
149 int irq
; /* Virtual IRQ dino uses */
150 struct irq_region
*dino_region
; /* region for this Dino */
152 u32 imr
; /* IRQ's which are enabled */
154 unsigned int dino_irr0
; /* save most recent IRQ line stat */
158 /* Looks nice and keeps the compiler happy */
159 #define DINO_DEV(d) ((struct dino_device *) d)
163 * Dino Configuration Space Accessor Functions
166 #define DINO_CFG_TOK(bus,dfn,pos) ((u32) ((bus)<<16 | (dfn)<<8 | (pos)))
168 static int dino_cfg_read(struct pci_bus
*bus
, unsigned int devfn
, int where
,
171 struct dino_device
*d
= DINO_DEV(parisc_walk_tree(bus
->dev
));
172 u32 local_bus
= (bus
->parent
== NULL
) ? 0 : bus
->secondary
;
173 u32 v
= DINO_CFG_TOK(local_bus
, devfn
, where
& ~3);
174 unsigned long base_addr
= d
->hba
.base_addr
;
177 spin_lock_irqsave(&d
->dinosaur_pen
, flags
);
179 /* tell HW which CFG address */
180 gsc_writel(v
, base_addr
+ DINO_PCI_ADDR
);
182 /* generate cfg read cycle */
184 *val
= gsc_readb(base_addr
+ DINO_CONFIG_DATA
+ (where
& 3));
185 } else if (size
== 2) {
186 *val
= le16_to_cpu(gsc_readw(base_addr
+
187 DINO_CONFIG_DATA
+ (where
& 2)));
188 } else if (size
== 4) {
189 *val
= le32_to_cpu(gsc_readl(base_addr
+ DINO_CONFIG_DATA
));
192 spin_unlock_irqrestore(&d
->dinosaur_pen
, flags
);
197 * Dino address stepping "feature":
198 * When address stepping, Dino attempts to drive the bus one cycle too soon
199 * even though the type of cycle (config vs. MMIO) might be different.
200 * The read of Ven/Prod ID is harmless and avoids Dino's address stepping.
202 static int dino_cfg_write(struct pci_bus
*bus
, unsigned int devfn
, int where
,
205 struct dino_device
*d
= DINO_DEV(parisc_walk_tree(bus
->dev
));
206 u32 local_bus
= (bus
->parent
== NULL
) ? 0 : bus
->secondary
;
207 u32 v
= DINO_CFG_TOK(local_bus
, devfn
, where
& ~3);
208 unsigned long base_addr
= d
->hba
.base_addr
;
211 spin_lock_irqsave(&d
->dinosaur_pen
, flags
);
213 /* avoid address stepping feature */
214 gsc_writel(v
& 0xffffff00, base_addr
+ DINO_PCI_ADDR
);
215 gsc_readl(base_addr
+ DINO_CONFIG_DATA
);
217 /* tell HW which CFG address */
218 gsc_writel(v
, base_addr
+ DINO_PCI_ADDR
);
219 /* generate cfg read cycle */
221 gsc_writeb(val
, base_addr
+ DINO_CONFIG_DATA
+ (where
& 3));
222 } else if (size
== 2) {
223 gsc_writew(cpu_to_le16(val
),
224 base_addr
+ DINO_CONFIG_DATA
+ (where
& 2));
225 } else if (size
== 4) {
226 gsc_writel(cpu_to_le32(val
), base_addr
+ DINO_CONFIG_DATA
);
229 spin_unlock_irqrestore(&d
->dinosaur_pen
, flags
);
233 static struct pci_ops dino_cfg_ops
= {
234 .read
= dino_cfg_read
,
235 .write
= dino_cfg_write
,
240 * Dino "I/O Port" Space Accessor Functions
242 * Many PCI devices don't require use of I/O port space (eg Tulip,
243 * NCR720) since they export the same registers to both MMIO and
244 * I/O port space. Performance is going to stink if drivers use
245 * I/O port instead of MMIO.
248 #define cpu_to_le8(x) (x)
249 #define le8_to_cpu(x) (x)
251 #define DINO_PORT_IN(type, size, mask) \
252 static u##size dino_in##size (struct pci_hba_data *d, u16 addr) \
255 unsigned long flags; \
256 spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \
257 /* tell HW which IO Port address */ \
258 gsc_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \
259 /* generate I/O PORT read cycle */ \
260 v = gsc_read##type(d->base_addr+DINO_IO_DATA+(addr&mask)); \
261 spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \
262 return le##size##_to_cpu(v); \
265 DINO_PORT_IN(b
, 8, 3)
266 DINO_PORT_IN(w
, 16, 2)
267 DINO_PORT_IN(l
, 32, 0)
269 #define DINO_PORT_OUT(type, size, mask) \
270 static void dino_out##size (struct pci_hba_data *d, u16 addr, u##size val) \
272 unsigned long flags; \
273 spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \
274 /* tell HW which IO port address */ \
275 gsc_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \
276 /* generate cfg write cycle */ \
277 gsc_write##type(cpu_to_le##size(val), d->base_addr+DINO_IO_DATA+(addr&mask)); \
278 spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \
281 DINO_PORT_OUT(b
, 8, 3)
282 DINO_PORT_OUT(w
, 16, 2)
283 DINO_PORT_OUT(l
, 32, 0)
285 struct pci_port_ops dino_port_ops
= {
295 dino_mask_irq(void *irq_dev
, int irq
)
297 struct dino_device
*dino_dev
= DINO_DEV(irq_dev
);
299 DBG(KERN_WARNING
"%s(0x%p, %d)\n", __FUNCTION__
, irq_dev
, irq
);
301 if (NULL
== irq_dev
|| irq
> DINO_IRQS
|| irq
< 0) {
302 printk(KERN_WARNING
"%s(0x%lx, %d) - not a dino irq?\n",
303 __FUNCTION__
, (long) irq_dev
, irq
);
307 ** Clear the matching bit in the IMR register
309 dino_dev
->imr
&= ~(DINO_MASK_IRQ(irq
));
310 gsc_writel(dino_dev
->imr
, dino_dev
->hba
.base_addr
+DINO_IMR
);
316 dino_unmask_irq(void *irq_dev
, int irq
)
318 struct dino_device
*dino_dev
= DINO_DEV(irq_dev
);
321 DBG(KERN_WARNING
"%s(0x%p, %d)\n", __FUNCTION__
, irq_dev
, irq
);
323 if (NULL
== irq_dev
|| irq
> DINO_IRQS
) {
324 printk(KERN_WARNING
"%s(): %d not a dino irq?\n",
330 /* set the matching bit in the IMR register */
331 dino_dev
->imr
|= DINO_MASK_IRQ(irq
); /* used in dino_isr() */
332 gsc_writel( dino_dev
->imr
, dino_dev
->hba
.base_addr
+DINO_IMR
);
334 /* Emulate "Level Triggered" Interrupt
335 ** Basically, a driver is blowing it if the IRQ line is asserted
336 ** while the IRQ is disabled. But tulip.c seems to do that....
337 ** Give 'em a kluge award and a nice round of applause!
339 ** The gsc_write will generate an interrupt which invokes dino_isr().
340 ** dino_isr() will read IPR and find nothing. But then catch this
341 ** when it also checks ILR.
343 tmp
= gsc_readl(dino_dev
->hba
.base_addr
+DINO_ILR
);
344 if (tmp
& DINO_MASK_IRQ(irq
)) {
345 DBG(KERN_WARNING
"%s(): IRQ asserted! (ILR 0x%x)\n",
347 gsc_writel(dino_dev
->txn_data
, dino_dev
->txn_addr
);
354 dino_enable_irq(void *irq_dev
, int irq
)
356 struct dino_device
*dino_dev
= DINO_DEV(irq_dev
);
359 ** clear pending IRQ bits
361 ** This does NOT change ILR state!
362 ** See comments in dino_unmask_irq() for ILR usage.
364 gsc_readl(dino_dev
->hba
.base_addr
+DINO_IPR
);
366 dino_unmask_irq(irq_dev
, irq
);
370 static struct irq_region_ops dino_irq_ops
= {
371 .disable_irq
= dino_mask_irq
, /* ??? */
372 .enable_irq
= dino_enable_irq
,
373 .mask_irq
= dino_mask_irq
,
374 .unmask_irq
= dino_unmask_irq
379 * Handle a Processor interrupt generated by Dino.
381 * ilr_loop counter is a kluge to prevent a "stuck" IRQ line from
382 * wedging the CPU. Could be removed or made optional at some point.
385 dino_isr(int irq
, void *intr_dev
, struct pt_regs
*regs
)
387 struct dino_device
*dino_dev
= DINO_DEV(intr_dev
);
390 extern void do_irq(struct irqaction
*a
, int i
, struct pt_regs
*p
);
393 /* read and acknowledge pending interrupts */
395 dino_dev
->dino_irr0
=
397 mask
= gsc_readl(dino_dev
->hba
.base_addr
+DINO_IRR0
) & DINO_IRR_MASK
;
408 DBG(KERN_WARNING
"%s(%x, %p) mask %0x\n",
409 __FUNCTION__
, irq
, intr_dev
, mask
);
410 do_irq(&dino_dev
->dino_region
->action
[irq
],
411 dino_dev
->dino_region
->data
.irqbase
+ irq
,
416 /* Support for level triggered IRQ lines.
418 ** Dropping this support would make this routine *much* faster.
419 ** But since PCI requires level triggered IRQ line to share lines...
420 ** device drivers may assume lines are level triggered (and not
421 ** edge triggered like EISA/ISA can be).
423 mask
= gsc_readl(dino_dev
->hba
.base_addr
+DINO_ILR
) & dino_dev
->imr
;
427 printk(KERN_ERR
"Dino %lx: stuck interrupt %d\n", dino_dev
->hba
.base_addr
, mask
);
433 static int dino_choose_irq(struct parisc_device
*dev
)
437 switch (dev
->id
.sversion
) {
438 case 0x00084: irq
= 8; break; /* PS/2 */
439 case 0x0008c: irq
= 10; break; /* RS232 */
440 case 0x00096: irq
= 8; break; /* PS/2 */
449 DBG("dino_bios_init\n");
453 * dino_card_setup - Set up the memory space for a Dino in card mode.
454 * @bus: the bus under this dino
456 * Claim an 8MB chunk of unused IO space and call the generic PCI routines
457 * to set up the addresses of the devices on this bus.
459 #define _8MB 0x00800000UL
461 dino_card_setup(struct pci_bus
*bus
, unsigned long base_addr
)
464 struct dino_device
*dino_dev
= DINO_DEV(parisc_walk_tree(bus
->dev
));
465 struct resource
*res
;
469 res
= &dino_dev
->hba
.lmmio_space
;
470 res
->flags
= IORESOURCE_MEM
;
471 size
= snprintf(name
, sizeof(name
), "Dino LMMIO (%s)", bus
->dev
->bus_id
);
472 res
->name
= kmalloc(size
+1, GFP_KERNEL
);
474 strcpy((char *)res
->name
, name
);
476 res
->name
= dino_dev
->hba
.lmmio_space
.name
;
479 if (ccio_allocate_resource(dino_dev
->hba
.dev
, res
, _8MB
,
480 F_EXTEND(0xf0000000UL
) | _8MB
,
481 F_EXTEND(0xffffffffUL
) &~ _8MB
, _8MB
,
483 struct list_head
*ln
, *tmp_ln
;
485 printk(KERN_ERR
"Dino: cannot attach bus %s\n",
487 /* kill the bus, we can't do anything with it */
488 list_for_each_safe(ln
, tmp_ln
, &bus
->devices
) {
489 struct pci_dev
*dev
= pci_dev_b(ln
);
491 list_del(&dev
->global_list
);
492 list_del(&dev
->bus_list
);
497 bus
->resource
[1] = res
;
498 bus
->resource
[0] = &(dino_dev
->hba
.io_space
);
500 /* Now tell dino what range it has */
501 for (i
= 1; i
< 31; i
++) {
502 if (res
->start
== F_EXTEND(0xf0000000UL
| (i
* _8MB
)))
505 DBG("DINO GSC WRITE i=%d, start=%lx, dino addr = %lx\n",
506 i
, res
->start
, base_addr
+ DINO_IO_ADDR_EN
);
507 gsc_writel(1 << i
, base_addr
+ DINO_IO_ADDR_EN
);
509 pci_bus_assign_resources(bus
);
513 dino_card_fixup(struct pci_dev
*dev
)
518 ** REVISIT: card-mode PCI-PCI expansion chassis do exist.
519 ** Not sure they were ever productized.
520 ** Die here since we'll die later in dino_inb() anyway.
522 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
) {
523 panic("Card-Mode Dino: PCI-PCI Bridge not supported\n");
527 ** Set Latency Timer to 0xff (not a shared bus)
528 ** Set CACHELINE_SIZE.
530 dino_cfg_write(dev
->bus
, dev
->devfn
, PCI_CACHE_LINE_SIZE
, 2, 0xff00 | L1_CACHE_BYTES
/4);
533 ** Program INT_LINE for card-mode devices.
534 ** The cards are hardwired according to this algorithm.
535 ** And it doesn't matter if PPB's are present or not since
536 ** the IRQ lines bypass the PPB.
538 ** "-1" converts INTA-D (1-4) to PCIINTA-D (0-3) range.
539 ** The additional "-1" adjusts for skewing the IRQ<->slot.
541 dino_cfg_read(dev
->bus
, dev
->devfn
, PCI_INTERRUPT_PIN
, 1, &irq_pin
);
542 dev
->irq
= (irq_pin
+ PCI_SLOT(dev
->devfn
) - 1) % 4 ;
544 /* Shouldn't really need to do this but it's in case someone tries
545 ** to bypass PCI services and look at the card themselves.
547 dino_cfg_write(dev
->bus
, dev
->devfn
, PCI_INTERRUPT_LINE
, 1, dev
->irq
);
552 dino_fixup_bus(struct pci_bus
*bus
)
554 struct list_head
*ln
;
556 struct dino_device
*dino_dev
= DINO_DEV(parisc_walk_tree(bus
->dev
));
557 int port_base
= HBA_PORT_BASE(dino_dev
->hba
.hba_num
);
559 DBG(KERN_WARNING
"%s(0x%p) bus %d sysdata 0x%p\n",
560 __FUNCTION__
, bus
, bus
->secondary
, bus
->dev
->platform_data
);
562 /* Firmware doesn't set up card-mode dino, so we have to */
563 if (is_card_dino(&dino_dev
->hba
.dev
->id
))
564 dino_card_setup(bus
, dino_dev
->hba
.base_addr
);
566 /* If this is a PCI-PCI Bridge, read the window registers etc */
568 pci_read_bridge_bases(bus
);
570 list_for_each(ln
, &bus
->devices
) {
574 if (is_card_dino(&dino_dev
->hba
.dev
->id
))
575 dino_card_fixup(dev
);
578 ** P2PB's only have 2 BARs, no IRQs.
579 ** I'd like to just ignore them for now.
581 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
)
584 /* Adjust the I/O Port space addresses */
585 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++) {
586 struct resource
*res
= &dev
->resource
[i
];
587 if (res
->flags
& IORESOURCE_IO
) {
588 res
->start
|= port_base
;
589 res
->end
|= port_base
;
592 /* Sign Extend MMIO addresses */
593 else if (res
->flags
& IORESOURCE_MEM
) {
594 res
->start
|= F_EXTEND(0UL);
595 res
->end
|= F_EXTEND(0UL);
600 /* Adjust INT_LINE for that busses region */
601 dev
->irq
= dino_dev
->dino_region
->data
.irqbase
+ dev
->irq
;
606 struct pci_bios_ops dino_bios_ops
= {
607 .init
= dino_bios_init
,
608 .fixup_bus
= dino_fixup_bus
613 * Initialise a DINO controller chip
616 dino_card_init(struct dino_device
*dino_dev
)
618 u32 brdg_feat
= 0x00784e05;
620 gsc_writel(0x00000000, dino_dev
->hba
.base_addr
+DINO_GMASK
);
621 gsc_writel(0x00000001, dino_dev
->hba
.base_addr
+DINO_IO_FBB_EN
);
622 gsc_writel(0x00000000, dino_dev
->hba
.base_addr
+DINO_ICR
);
625 /* REVISIT - should be a runtime check (eg if (CPU_IS_PCX_L) ...) */
627 ** PCX-L processors don't support XQL like Dino wants it.
628 ** PCX-L2 ignore XQL signal and it doesn't matter.
630 brdg_feat
&= ~0x4; /* UXQL */
632 gsc_writel( brdg_feat
, dino_dev
->hba
.base_addr
+DINO_BRDG_FEAT
);
635 ** Don't enable address decoding until we know which I/O range
636 ** currently is available from the host. Only affects MMIO
637 ** and not I/O port space.
639 gsc_writel(0x00000000, dino_dev
->hba
.base_addr
+DINO_IO_ADDR_EN
);
641 gsc_writel(0x00000000, dino_dev
->hba
.base_addr
+DINO_DAMODE
);
642 gsc_writel(0x00222222, dino_dev
->hba
.base_addr
+DINO_PCIROR
);
643 gsc_writel(0x00222222, dino_dev
->hba
.base_addr
+DINO_PCIWOR
);
645 gsc_writel(0x00000040, dino_dev
->hba
.base_addr
+DINO_MLTIM
);
646 gsc_writel(0x00000080, dino_dev
->hba
.base_addr
+DINO_IO_CONTROL
);
647 gsc_writel(0x0000008c, dino_dev
->hba
.base_addr
+DINO_TLTIM
);
649 /* Disable PAMR before writing PAPR */
650 gsc_writel(0x0000007e, dino_dev
->hba
.base_addr
+DINO_PAMR
);
651 gsc_writel(0x0000007f, dino_dev
->hba
.base_addr
+DINO_PAPR
);
652 gsc_writel(0x00000000, dino_dev
->hba
.base_addr
+DINO_PAMR
);
655 ** Dino ERS encourages enabling FBB (0x6f).
656 ** We can't until we know *all* devices below us can support it.
657 ** (Something in device configuration header tells us).
659 gsc_writel(0x0000004f, dino_dev
->hba
.base_addr
+DINO_PCICMD
);
661 /* Somewhere, the PCI spec says give devices 1 second
662 ** to recover from the #RESET being de-asserted.
663 ** Experience shows most devices only need 10ms.
664 ** This short-cut speeds up booting significantly.
666 mdelay(pci_post_reset_delay
);
670 dino_bridge_init(struct dino_device
*dino_dev
, const char *name
)
672 unsigned long io_addr
, bpos
;
674 struct resource
*res
;
676 * Decoding IO_ADDR_EN only works for Built-in Dino
677 * since PDC has already initialized this.
680 io_addr
= gsc_readl(dino_dev
->hba
.base_addr
+ DINO_IO_ADDR_EN
);
682 printk(KERN_WARNING
"%s: No PCI devices enabled.\n", name
);
686 for (bpos
= 0; (io_addr
& (1 << bpos
)) == 0; bpos
++)
689 res
= &dino_dev
->hba
.lmmio_space
;
690 res
->flags
= IORESOURCE_MEM
;
692 res
->start
= (unsigned long)(signed int)(0xf0000000 | (bpos
<< 23));
693 res
->end
= res
->start
+ 8 * 1024 * 1024 - 1;
695 result
= ccio_request_resource(dino_dev
->hba
.dev
, res
);
697 printk(KERN_ERR
"%s: failed to claim PCI Bus address space!\n", name
);
704 static int __init
dino_common_init(struct parisc_device
*dev
,
705 struct dino_device
*dino_dev
, const char *name
)
709 struct gsc_irq gsc_irq
;
710 struct resource
*res
;
712 pcibios_register_hba(&dino_dev
->hba
);
714 pci_bios
= &dino_bios_ops
; /* used by pci_scan_bus() */
715 pci_port
= &dino_port_ops
;
718 ** Note: SMP systems can make use of IRR1/IAR1 registers
719 ** But it won't buy much performance except in very
720 ** specific applications/configurations. Note Dino
721 ** still only has 11 IRQ input lines - just map some of them
722 ** to a different processor.
724 dino_dev
->irq
= gsc_alloc_irq(&gsc_irq
);
725 dino_dev
->txn_addr
= gsc_irq
.txn_addr
;
726 dino_dev
->txn_data
= gsc_irq
.txn_data
;
727 eim
= ((u32
) gsc_irq
.txn_addr
) | gsc_irq
.txn_data
;
730 ** Dino needs a PA "IRQ" to get a processor's attention.
731 ** arch/parisc/kernel/irq.c returns an EIRR bit.
733 if (dino_dev
->irq
< 0) {
734 printk(KERN_WARNING
"%s: gsc_alloc_irq() failed\n", name
);
738 status
= request_irq(dino_dev
->irq
, dino_isr
, 0, name
, dino_dev
);
740 printk(KERN_WARNING
"%s: request_irq() failed with %d\n",
746 ** Tell generic interrupt support we have 11 bits which need
747 ** be checked in the interrupt handler.
749 dino_dev
->dino_region
= alloc_irq_region(DINO_IRQS
, &dino_irq_ops
,
752 if (NULL
== dino_dev
->dino_region
) {
753 printk(KERN_WARNING
"%s: alloc_irq_region() failed\n", name
);
757 /* Support the serial port which is sometimes attached on built-in
761 fixup_child_irqs(dev
, dino_dev
->dino_region
->data
.irqbase
,
765 ** This enables DINO to generate interrupts when it sees
766 ** any of its inputs *change*. Just asserting an IRQ
767 ** before it's enabled (ie unmasked) isn't good enough.
769 gsc_writel(eim
, dino_dev
->hba
.base_addr
+DINO_IAR0
);
772 ** Some platforms don't clear Dino's IRR0 register at boot time.
773 ** Reading will clear it now.
775 gsc_readl(dino_dev
->hba
.base_addr
+DINO_IRR0
);
777 /* allocate I/O Port resource region */
778 res
= &dino_dev
->hba
.io_space
;
779 if (dev
->id
.hversion
== 0x680 || is_card_dino(&dev
->id
)) {
780 res
->name
= "Dino I/O Port";
781 dino_dev
->hba
.lmmio_space
.name
= "Dino LMMIO";
783 res
->name
= "Cujo I/O Port";
784 dino_dev
->hba
.lmmio_space
.name
= "Cujo LMMIO";
786 res
->start
= HBA_PORT_BASE(dino_dev
->hba
.hba_num
);
787 res
->end
= res
->start
+ (HBA_PORT_SPACE_SIZE
- 1);
788 res
->flags
= IORESOURCE_IO
; /* do not mark it busy ! */
789 if (request_resource(&ioport_resource
, res
) < 0) {
790 printk(KERN_ERR
"%s: request I/O Port region failed 0x%lx/%lx (hpa 0x%lx)\n",
791 name
, res
->start
, res
->end
, dino_dev
->hba
.base_addr
);
798 #define CUJO_RAVEN_ADDR F_EXTEND(0xf1000000UL)
799 #define CUJO_FIREHAWK_ADDR F_EXTEND(0xf1604000UL)
800 #define CUJO_RAVEN_BADPAGE 0x01003000UL
801 #define CUJO_FIREHAWK_BADPAGE 0x01607000UL
803 static const char *dino_vers
[] = {
810 static const char *cujo_vers
[] = {
815 void ccio_cujo20_fixup(struct parisc_device
*dev
, u32 iovp
);
818 ** Determine if dino should claim this chip (return 0) or not (return 1).
819 ** If so, initialize the chip appropriately (card-mode vs bridge mode).
820 ** Much of the initialization is common though.
823 dino_driver_callback(struct parisc_device
*dev
)
825 struct dino_device
*dino_dev
; // Dino specific control struct
826 const char *version
= "unknown";
827 const int name_len
= 32;
831 name
= kmalloc(name_len
, GFP_KERNEL
);
833 snprintf(name
, name_len
, "Dino %s", dev
->dev
.bus_id
);
837 if (is_card_dino(&dev
->id
)) {
838 version
= "3.x (card mode)";
840 if(dev
->id
.hversion
== 0x680) {
841 if (dev
->id
.hversion_rev
< 4) {
842 version
= dino_vers
[dev
->id
.hversion_rev
];
847 if (dev
->id
.hversion_rev
< 2) {
848 version
= cujo_vers
[dev
->id
.hversion_rev
];
853 printk("%s version %s found at 0x%lx\n", name
, version
, dev
->hpa
);
855 if (!request_mem_region(dev
->hpa
, PAGE_SIZE
, name
)) {
856 printk(KERN_ERR
"DINO: Hey! Someone took my MMIO space (0x%ld)!\n",
862 if (is_cujo
&& dev
->id
.hversion_rev
== 1) {
863 #ifdef CONFIG_IOMMU_CCIO
864 printk(KERN_WARNING
"Enabling Cujo 2.0 bug workaround\n");
865 if (dev
->hpa
== (unsigned long)CUJO_RAVEN_ADDR
) {
866 ccio_cujo20_fixup(dev
->parent
, CUJO_RAVEN_BADPAGE
);
867 } else if (dev
->hpa
== (unsigned long)CUJO_FIREHAWK_ADDR
) {
868 ccio_cujo20_fixup(dev
->parent
, CUJO_FIREHAWK_BADPAGE
);
870 printk("Don't recognise Cujo at address 0x%lx, not enabling workaround\n", dev
->hpa
);
873 } else if (!is_cujo
&& !is_card_dino(&dev
->id
) &&
874 dev
->id
.hversion_rev
< 3) {
876 "The GSCtoPCI (Dino hrev %d) bus converter found may exhibit\n"
877 "data corruption. See Service Note Numbers: A4190A-01, A4191A-01.\n"
878 "Systems shipped after Aug 20, 1997 will not exhibit this problem.\n"
879 "Models affected: C180, C160, C160L, B160L, and B132L workstations.\n\n",
880 dev
->id
.hversion_rev
);
881 /* REVISIT: why are C200/C240 listed in the README table but not
882 ** "Models affected"? Could be an omission in the original literature.
886 dino_dev
= kmalloc(sizeof(struct dino_device
), GFP_KERNEL
);
888 printk("dino_init_chip - couldn't alloc dino_device\n");
892 memset(dino_dev
, 0, sizeof(struct dino_device
));
894 dino_dev
->hba
.dev
= dev
;
895 dino_dev
->hba
.base_addr
= dev
->hpa
; /* faster access */
896 dino_dev
->hba
.lmmio_space_offset
= 0; /* CPU addrs == bus addrs */
897 dino_dev
->dinosaur_pen
= SPIN_LOCK_UNLOCKED
;
898 dino_dev
->hba
.iommu
= ccio_get_iommu(dev
);
900 if (is_card_dino(&dev
->id
)) {
901 dino_card_init(dino_dev
);
903 dino_bridge_init(dino_dev
, name
);
906 if (dino_common_init(dev
, dino_dev
, name
))
909 dev
->dev
.platform_data
= dino_dev
;
912 ** It's not used to avoid chicken/egg problems
913 ** with configuration accessor functions.
915 dino_dev
->hba
.hba_bus
=
916 pci_scan_bus_parented(&dev
->dev
, dino_dev
->hba
.hba_num
,
917 &dino_cfg_ops
, NULL
);
922 * Normally, we would just test sversion. But the Elroy PCI adapter has
923 * the same sversion as Dino, so we have to check hversion as well.
924 * Unfortunately, the J2240 PDC reports the wrong hversion for the first
925 * Dino, so we have to test for Dino, Cujo and Dino-in-a-J2240.
927 static struct parisc_device_id dino_tbl
[] = {
928 { HPHW_A_DMA
, HVERSION_REV_ANY_ID
, 0x004, 0x0009D }, /* Card-mode Dino. */
929 { HPHW_A_DMA
, HVERSION_REV_ANY_ID
, 0x444, 0x08080 }, /* Same card in a 715. Bug? */
930 { HPHW_BRIDGE
, HVERSION_REV_ANY_ID
, 0x680, 0xa }, /* Bridge-mode Dino */
931 { HPHW_BRIDGE
, HVERSION_REV_ANY_ID
, 0x682, 0xa }, /* Bridge-mode Cujo */
932 { HPHW_BRIDGE
, HVERSION_REV_ANY_ID
, 0x05d, 0xa }, /* Dino in a J2240 */
936 static struct parisc_driver dino_driver
= {
938 .id_table
= dino_tbl
,
939 .probe
= dino_driver_callback
,
943 * One time initialization to let the world know Dino is here.
944 * This is the only routine which is NOT static.
945 * Must be called exactly once before pci_init().
947 int __init
dino_init(void)
949 register_parisc_driver(&dino_driver
);