47 #include <linux/types.h>
48 #include <linux/kernel.h>
49 #include <linux/pci.h>
52 #include <linux/slab.h>
66 #define DBG(x...) printk(x)
85 #define is_card_dino(id) ((id)->hw_type == HPHW_A_DMA)
86 #define is_cujo(id) ((id)->hversion == 0x682)
88 #define DINO_IAR0 0x004
89 #define DINO_IODC_ADDR 0x008
90 #define DINO_IODC_DATA_0 0x008
91 #define DINO_IODC_DATA_1 0x008
92 #define DINO_IRR0 0x00C
93 #define DINO_IAR1 0x010
94 #define DINO_IRR1 0x014
95 #define DINO_IMR 0x018
96 #define DINO_IPR 0x01C
97 #define DINO_TOC_ADDR 0x020
98 #define DINO_ICR 0x024
99 #define DINO_ILR 0x028
100 #define DINO_IO_COMMAND 0x030
101 #define DINO_IO_STATUS 0x034
102 #define DINO_IO_CONTROL 0x038
103 #define DINO_IO_GSC_ERR_RESP 0x040
104 #define DINO_IO_ERR_INFO 0x044
105 #define DINO_IO_PCI_ERR_RESP 0x048
106 #define DINO_IO_FBB_EN 0x05c
107 #define DINO_IO_ADDR_EN 0x060
108 #define DINO_PCI_ADDR 0x064
109 #define DINO_CONFIG_DATA 0x068
110 #define DINO_IO_DATA 0x06c
111 #define DINO_MEM_DATA 0x070
112 #define DINO_GSC2X_CONFIG 0x7b4
113 #define DINO_GMASK 0x800
114 #define DINO_PAMR 0x804
115 #define DINO_PAPR 0x808
116 #define DINO_DAMODE 0x80c
117 #define DINO_PCICMD 0x810
118 #define DINO_PCISTS 0x814
119 #define DINO_MLTIM 0x81c
120 #define DINO_BRDG_FEAT 0x820
121 #define DINO_PCIROR 0x824
122 #define DINO_PCIWOR 0x828
123 #define DINO_TLTIM 0x830
126 #define DINO_IRR_MASK 0x5ff
127 #define DINO_LOCAL_IRQS (DINO_IRQS+1)
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
141 #define RS232INT 0x400
152 unsigned int dino_irr0;
157 #define DINO_DEV(d) ((struct dino_device *) d)
164 #define DINO_CFG_TOK(bus,dfn,pos) ((u32) ((bus)<<16 | (dfn)<<8 | (pos)))
171 static int dino_current_bus = 0;
173 static int dino_cfg_read(
struct pci_bus *
bus,
unsigned int devfn,
int where,
182 DBG(
"%s: %p, %d, %d, %d\n", __func__, base_addr, devfn, where,
192 }
else if (size == 2) {
194 }
else if (size == 4) {
208 static int dino_cfg_write(
struct pci_bus *
bus,
unsigned int devfn,
int where,
217 DBG(
"%s: %p, %d, %d, %d\n", __func__, base_addr, devfn, where,
230 }
else if (size == 2) {
232 }
else if (size == 4) {
240 static struct pci_ops dino_cfg_ops = {
241 .read = dino_cfg_read,
242 .write = dino_cfg_write,
255 #define DINO_PORT_IN(type, size, mask) \
256 static u##size dino_in##size (struct pci_hba_data *d, u16 addr) \
259 unsigned long flags; \
260 spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \
262 __raw_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \
264 v = read##type(d->base_addr+DINO_IO_DATA+(addr&mask)); \
265 spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \
273 #define DINO_PORT_OUT(type, size, mask) \
274 static void dino_out##size (struct pci_hba_data *d, u16 addr, u##size val) \
276 unsigned long flags; \
277 spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \
279 __raw_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \
281 write##type(val, d->base_addr+DINO_IO_DATA+(addr&mask)); \
282 spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \
298 static void dino_mask_irq(
struct irq_data *d)
300 struct dino_device *dino_dev = irq_data_get_irq_chip_data(d);
310 static void dino_unmask_irq(
struct irq_data *d)
312 struct dino_device *dino_dev = irq_data_get_irq_chip_data(d);
347 static struct irq_chip dino_interrupt_type = {
349 .irq_unmask = dino_unmask_irq,
350 .irq_mask = dino_mask_irq,
360 static irqreturn_t dino_isr(
int irq,
void *intr_dev)
368 dino_dev->dino_irr0 =
377 int local_irq =
__ffs(mask);
380 __func__, irq, intr_dev, mask);
382 mask &= ~(1 << local_irq);
397 dino_dev->
hba.base_addr, mask);
403 static void dino_assign_irq(
struct dino_device *dino,
int local_irq,
int *irqp)
418 switch (dev->
id.sversion) {
419 case 0x00084: irq = 8;
break;
420 case 0x0008c: irq = 10;
break;
421 case 0x00096: irq = 8;
break;
425 dino_assign_irq(dino, irq, &dev->
irq);
435 u8 new_irq = dev->
irq - 1;
436 printk(
KERN_INFO "PCI: Cirrus Cardbus IRQ fixup for %s, from %d to %d\n",
437 pci_name(dev), dev->
irq, new_irq);
446 DBG(
"dino_bios_init\n");
456 #define _8MB 0x00800000UL
466 res = &dino_dev->
hba.lmmio_space;
468 size =
scnprintf(name,
sizeof(name),
"Dino LMMIO (%s)",
474 res->
name = dino_dev->
hba.lmmio_space.name;
495 for (i = 1; i < 31; i++) {
499 DBG(
"DINO GSC WRITE i=%d, start=%lx, dino addr = %p\n",
505 dino_card_fixup(
struct pci_dev *dev)
515 panic(
"Card-Mode Dino: PCI-PCI Bridge not supported\n");
522 dino_cfg_write(dev->
bus, dev->
devfn,
544 #define DINO_BRIDGE_ALIGN 0x100000
548 dino_fixup_bus(
struct pci_bus *bus)
555 bus->
bridge->platform_data);
559 dino_card_setup(bus, dino_dev->
hba.base_addr);
567 if((bus->
self->resource[i].flags &
583 DBG(
"DEBUG %s assigning %d [0x%lx,0x%lx]\n",
584 dev_name(&bus->
self->dev), i,
585 bus->
self->resource[i].start,
586 bus->
self->resource[i].end);
588 DBG(
"DEBUG %s after assign %d [0x%lx,0x%lx]\n",
589 dev_name(&bus->
self->dev), i,
590 bus->
self->resource[i].start,
591 bus->
self->resource[i].end);
598 dino_card_fixup(dev);
612 if(dev->
irq == 255) {
614 #define DINO_FIX_UNASSIGNED_INTERRUPTS
615 #ifdef DINO_FIX_UNASSIGNED_INTERRUPTS
629 "setting to %d\n", pci_name(dev), irq_pin);
630 dino_cfg_write(dev->
bus, dev->
devfn,
632 dino_assign_irq(dino_dev, irq_pin, &dev->
irq);
639 dino_assign_irq(dino_dev, dev->
irq, &dev->
irq);
646 .init = dino_bios_init,
647 .fixup_bus = dino_fixup_bus
657 u32 brdg_feat = 0x00784e05;
661 if (status & 0x0000ff80) {
733 res = &dino_dev->
hba.lmmio_space;
734 for (i = 0; i < 32; i++) {
737 if((io_addr & (1 << i)) == 0)
740 start =
F_EXTEND(0xf0000000UL) | (i << 23);
741 end = start + 8 * 1024 * 1024 - 1;
743 DBG(
"DINO RANGE %d is at 0x%lx-0x%lx\n", count,
746 if(prevres && prevres->
end + 1 == start) {
750 printk(
KERN_ERR "%s is out of resource windows for range %d (0x%lx-0x%lx)\n", name, count, start, end);
766 res = &dino_dev->
hba.lmmio_space;
769 if(res[i].flags == 0)
775 "space %d (0x%lx-0x%lx)!\n", name, i,
776 (
unsigned long)res[i].start, (
unsigned long)res[i].end);
844 res = &dino_dev->
hba.io_space;
846 res->
name =
"Dino I/O Port";
848 res->
name =
"Cujo I/O Port";
855 "0x%lx/%lx (hpa 0x%p)\n",
856 name, (
unsigned long)res->
start, (
unsigned long)res->
end,
857 dino_dev->
hba.base_addr);
864 #define CUJO_RAVEN_ADDR F_EXTEND(0xf1000000UL)
865 #define CUJO_FIREHAWK_ADDR F_EXTEND(0xf1604000UL)
866 #define CUJO_RAVEN_BADPAGE 0x01003000UL
867 #define CUJO_FIREHAWK_BADPAGE 0x01607000UL
869 static const char *dino_vers[] = {
876 static const char *cujo_vers[] = {
891 const char *
version =
"unknown";
896 unsigned long hpa = dev->
hpa.start;
901 version =
"3.x (card mode)";
904 if (dev->
id.hversion_rev < 4) {
905 version = dino_vers[dev->
id.hversion_rev];
910 if (dev->
id.hversion_rev < 2) {
911 version = cujo_vers[dev->
id.hversion_rev];
916 printk(
"%s version %s found at 0x%lx\n", name, version, hpa);
919 printk(
KERN_ERR "DINO: Hey! Someone took my MMIO space (0x%ld)!\n",
925 if (is_cujo && dev->
id.hversion_rev == 1) {
926 #ifdef CONFIG_IOMMU_CCIO
933 printk(
"Don't recognise Cujo at address 0x%lx, not enabling workaround\n", hpa);
937 dev->
id.hversion_rev < 3) {
939 "The GSCtoPCI (Dino hrev %d) bus converter found may exhibit\n"
940 "data corruption. See Service Note Numbers: A4190A-01, A4191A-01.\n"
941 "Systems shipped after Aug 20, 1997 will not exhibit this problem.\n"
942 "Models affected: C180, C160, C160L, B160L, and B132L workstations.\n\n",
943 dev->
id.hversion_rev);
951 printk(
"dino_init_chip - couldn't alloc dino_device\n");
957 dino_dev->
hba.lmmio_space_offset = 0;
962 dino_card_init(dino_dev);
964 dino_bridge_init(dino_dev, name);
967 if (dino_common_init(dev, dino_dev, name))
970 dev->
dev.platform_data = dino_dev;
974 if (dino_dev->
hba.lmmio_space.flags)
976 dino_dev->
hba.lmmio_space_offset);
977 if (dino_dev->
hba.elmmio_space.flags)
979 dino_dev->
hba.lmmio_space_offset);
980 if (dino_dev->
hba.gmmio_space.flags)
983 dino_dev->
hba.bus_num.start = dino_current_bus;
984 dino_dev->
hba.bus_num.end = 255;
994 printk(
KERN_ERR "ERROR: failed to scan PCI bus on %s (duplicate bus number %d?)\n",
995 dev_name(&dev->
dev), dino_current_bus);
1008 dino_current_bus = max + 1;
1034 .id_table = dino_tbl,
1035 .probe = dino_probe,