blob: 16d0c0eb0d19670692aedf958a05b381ee47b7c1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Low-Level PCI Support for SGI Visual Workstation
3 *
4 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
5 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8#include <linux/pci.h>
9#include <linux/init.h>
10
Ingo Molnar5548ed12008-07-10 16:53:21 +020011#include <asm/setup.h>
Jaswinder Singh Rajput82487712008-12-27 18:32:28 +053012#include <asm/pci_x86.h>
Ingo Molnarb4b86412008-07-10 15:25:21 +020013#include <asm/visws/cobalt.h>
14#include <asm/visws/lithium.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static int pci_visws_enable_irq(struct pci_dev *dev) { return 0; }
Tom Duffy46bdac92005-08-07 09:42:23 -070017static void pci_visws_disable_irq(struct pci_dev *dev) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Ingo Molnar22d5c672008-07-10 16:29:28 +020019/* int (*pcibios_enable_irq)(struct pci_dev *dev) = &pci_visws_enable_irq; */
20/* void (*pcibios_disable_irq)(struct pci_dev *dev) = &pci_visws_disable_irq; */
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Ingo Molnar22d5c672008-07-10 16:29:28 +020022/* void __init pcibios_penalize_isa_irq(int irq, int active) {} */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24
25unsigned int pci_bus0, pci_bus1;
26
27static inline u8 bridge_swizzle(u8 pin, u8 slot)
28{
29 return (((pin - 1) + slot) % 4) + 1;
30}
31
32static u8 __init visws_swizzle(struct pci_dev *dev, u8 *pinp)
33{
34 u8 pin = *pinp;
35
36 while (dev->bus->self) { /* Move up the chain of bridges. */
37 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
38 dev = dev->bus->self;
39 }
40 *pinp = pin;
41
42 return PCI_SLOT(dev->devfn);
43}
44
45static int __init visws_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
46{
47 int irq, bus = dev->bus->number;
48
49 pin--;
50
51 /* Nothing useful at PIIX4 pin 1 */
52 if (bus == pci_bus0 && slot == 4 && pin == 0)
53 return -1;
54
55 /* PIIX4 USB is on Bus 0, Slot 4, Line 3 */
56 if (bus == pci_bus0 && slot == 4 && pin == 3) {
57 irq = CO_IRQ(CO_APIC_PIIX4_USB);
58 goto out;
59 }
60
61 /* First pin spread down 1 APIC entry per slot */
62 if (pin == 0) {
63 irq = CO_IRQ((bus == pci_bus0 ? CO_APIC_PCIB_BASE0 :
64 CO_APIC_PCIA_BASE0) + slot);
65 goto out;
66 }
67
68 /* lines 1,2,3 from any slot is shared in this twirly pattern */
69 if (bus == pci_bus1) {
70 /* lines 1-3 from devices 0 1 rotate over 2 apic entries */
71 irq = CO_IRQ(CO_APIC_PCIA_BASE123 + ((slot + (pin - 1)) % 2));
72 } else { /* bus == pci_bus0 */
73 /* lines 1-3 from devices 0-3 rotate over 3 apic entries */
74 if (slot == 0)
75 slot = 3; /* same pattern */
76 irq = CO_IRQ(CO_APIC_PCIA_BASE123 + ((3 - slot) + (pin - 1) % 3));
77 }
78out:
79 printk(KERN_DEBUG "PCI: Bus %d Slot %d Line %d -> IRQ %d\n", bus, slot, pin, irq);
80 return irq;
81}
82
83void __init pcibios_update_irq(struct pci_dev *dev, int irq)
84{
85 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
86}
87
Robert Richter3cabf372008-07-11 12:26:59 +020088int __init pci_visws_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Robert Richter3cabf372008-07-11 12:26:59 +020090 if (!is_visws_box())
91 return -1;
92
93 pcibios_enable_irq = &pci_visws_enable_irq;
94 pcibios_disable_irq = &pci_visws_disable_irq;
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 /* The VISWS supports configuration access type 1 only */
97 pci_probe = (pci_probe | PCI_PROBE_CONF1) &
98 ~(PCI_PROBE_BIOS | PCI_PROBE_CONF2);
99
100 pci_bus0 = li_pcib_read16(LI_PCI_BUSNUM) & 0xff;
101 pci_bus1 = li_pcia_read16(LI_PCI_BUSNUM) & 0xff;
102
103 printk(KERN_INFO "PCI: Lithium bridge A bus: %u, "
104 "bridge B (PIIX4) bus: %u\n", pci_bus1, pci_bus0);
105
106 raw_pci_ops = &pci_direct_conf1;
Muli Ben-Yehuda73c59af2007-08-10 13:01:19 -0700107 pci_scan_bus_with_sysdata(pci_bus0);
108 pci_scan_bus_with_sysdata(pci_bus1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 pci_fixup_irqs(visws_swizzle, visws_map_irq);
110 pcibios_resource_survey();
111 return 0;
112}