blob: a18516925cdd3eeab62ae19f92e270521f5a3f3b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2003 Christoph Hellwig (hch@lst.de)
7 * Copyright (C) 1999, 2000, 04 Ralf Baechle (ralf@linux-mips.org)
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 */
10#include <linux/init.h>
11#include <linux/kernel.h>
12#include <linux/pci.h>
13#include <asm/sn/arch.h>
14#include <asm/pci/bridge.h>
15#include <asm/paccess.h>
16#include <asm/sn/intr.h>
17#include <asm/sn/sn0/hub.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*
20 * Max #PCI busses we can handle; ie, max #PCI bridges.
21 */
22#define MAX_PCI_BUSSES 40
23
24/*
25 * Max #PCI devices (like scsi controllers) we handle on a bus.
26 */
27#define MAX_DEVICES_PER_PCIBUS 8
28
29/*
30 * XXX: No kmalloc available when we do our crosstalk scan,
31 * we should try to move it later in the boot process.
32 */
33static struct bridge_controller bridges[MAX_PCI_BUSSES];
34
35/*
36 * Translate from irq to software PCI bus number and PCI slot.
37 */
38struct bridge_controller *irq_to_bridge[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
39int irq_to_slot[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
40
Ralf Baechle9e0c7af2006-06-17 00:55:45 +010041extern struct pci_ops bridge_pci_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Ralf Baechle234fcd12008-03-08 09:56:28 +000043int __cpuinit bridge_probe(nasid_t nasid, int widget_id, int masterwid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
45 unsigned long offset = NODE_OFFSET(nasid);
46 struct bridge_controller *bc;
47 static int num_bridges = 0;
48 bridge_t *bridge;
49 int slot;
Thomas Bogendoerfer96173a62008-04-17 22:07:42 +020050 extern int pci_probe_only;
51
52 pci_probe_only = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 printk("a bridge\n");
55
56 /* XXX: kludge alert.. */
57 if (!num_bridges)
58 ioport_resource.end = ~0UL;
59
60 bc = &bridges[num_bridges];
61
62 bc->pc.pci_ops = &bridge_pci_ops;
63 bc->pc.mem_resource = &bc->mem;
64 bc->pc.io_resource = &bc->io;
65
66 bc->pc.index = num_bridges;
67
68 bc->mem.name = "Bridge PCI MEM";
69 bc->pc.mem_offset = offset;
70 bc->mem.start = 0;
71 bc->mem.end = ~0UL;
72 bc->mem.flags = IORESOURCE_MEM;
73
74 bc->io.name = "Bridge IO MEM";
75 bc->pc.io_offset = offset;
76 bc->io.start = 0UL;
77 bc->io.end = ~0UL;
78 bc->io.flags = IORESOURCE_IO;
79
80 bc->irq_cpu = smp_processor_id();
81 bc->widget_id = widget_id;
82 bc->nasid = nasid;
83
Ralf Baechle3a115452006-06-17 00:46:27 +010084 bc->baddr = (u64)masterwid << 60 | PCI64_ATTR_BAR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 /*
87 * point to this bridge
88 */
89 bridge = (bridge_t *) RAW_NODE_SWIN_BASE(nasid, widget_id);
90
91 /*
Ralf Baechlea3dddd52006-03-11 08:18:41 +000092 * Clear all pending interrupts.
93 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 bridge->b_int_rst_stat = BRIDGE_IRR_ALL_CLR;
95
96 /*
Ralf Baechlea3dddd52006-03-11 08:18:41 +000097 * Until otherwise set up, assume all interrupts are from slot 0
98 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 bridge->b_int_device = 0x0;
100
101 /*
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000102 * swap pio's to pci mem and io space (big windows)
103 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 bridge->b_wid_control |= BRIDGE_CTRL_IO_SWAP |
105 BRIDGE_CTRL_MEM_SWAP;
Thomas Bogendoerfer96173a62008-04-17 22:07:42 +0200106#ifdef CONFIG_PAGE_SIZE_4KB
107 bridge->b_wid_control &= ~BRIDGE_CTRL_PAGE_SIZE;
108#else /* 16kB or larger */
109 bridge->b_wid_control |= BRIDGE_CTRL_PAGE_SIZE;
110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112 /*
113 * Hmm... IRIX sets additional bits in the address which
114 * are documented as reserved in the bridge docs.
115 */
116 bridge->b_wid_int_upper = 0x8000 | (masterwid << 16);
117 bridge->b_wid_int_lower = 0x01800090; /* PI_INT_PEND_MOD off*/
118 bridge->b_dir_map = (masterwid << 20); /* DMA */
119 bridge->b_int_enable = 0;
120
121 for (slot = 0; slot < 8; slot ++) {
122 bridge->b_device[slot].reg |= BRIDGE_DEV_SWAP_DIR;
123 bc->pci_int[slot] = -1;
124 }
125 bridge->b_wid_tflush; /* wait until Bridge PIO complete */
126
127 bc->base = bridge;
128
129 register_pci_controller(&bc->pc);
130
131 num_bridges++;
132
133 return 0;
134}
135
136/*
137 * All observed requests have pin == 1. We could have a global here, that
138 * gets incremented and returned every time - unfortunately, pci_map_irq
139 * may be called on the same device over and over, and need to return the
140 * same value. On O2000, pin can be 0 or 1, and PCI slots can be [0..7].
141 *
142 * A given PCI device, in general, should be able to intr any of the cpus
143 * on any one of the hubs connected to its xbow.
144 */
Ralf Baechle19df0d12007-07-10 17:33:00 +0100145int __devinit pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 struct bridge_controller *bc = BRIDGE_CONTROLLER(dev->bus);
148 int irq = bc->pci_int[slot];
149
150 if (irq == -1) {
151 irq = bc->pci_int[slot] = request_bridge_irq(bc);
152 if (irq < 0)
153 panic("Can't allocate interrupt for PCI device %s\n",
154 pci_name(dev));
155 }
156
157 irq_to_bridge[irq] = bc;
158 irq_to_slot[irq] = slot;
159
160 return irq;
161}
162
163/* Do platform specific device initialization at pci_enable_device() time */
164int pcibios_plat_dev_init(struct pci_dev *dev)
165{
166 return 0;
167}
168
169/*
170 * Device might live on a subordinate PCI bus. XXX Walk up the chain of buses
171 * to find the slot number in sense of the bridge device register.
172 * XXX This also means multiple devices might rely on conflicting bridge
173 * settings.
174 */
175
176static inline void pci_disable_swapping(struct pci_dev *dev)
177{
178 struct bridge_controller *bc = BRIDGE_CONTROLLER(dev->bus);
179 bridge_t *bridge = bc->base;
180 int slot = PCI_SLOT(dev->devfn);
181
182 /* Turn off byte swapping */
183 bridge->b_device[slot].reg &= ~BRIDGE_DEV_SWAP_DIR;
184 bridge->b_widget.w_tflush; /* Flush */
185}
186
187static inline void pci_enable_swapping(struct pci_dev *dev)
188{
189 struct bridge_controller *bc = BRIDGE_CONTROLLER(dev->bus);
190 bridge_t *bridge = bc->base;
191 int slot = PCI_SLOT(dev->devfn);
192
193 /* Turn on byte swapping */
194 bridge->b_device[slot].reg |= BRIDGE_DEV_SWAP_DIR;
195 bridge->b_widget.w_tflush; /* Flush */
196}
197
198static void __init pci_fixup_ioc3(struct pci_dev *d)
199{
200 pci_disable_swapping(d);
201}
202
Ralf Baechle9dbdfce2005-09-15 08:52:34 +0000203int pcibus_to_node(struct pci_bus *bus)
204{
205 struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
206
207 return bc->nasid;
208}
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3,
211 pci_fixup_ioc3);