2 * BK Id: SCCS/s.chrp_pci.c 1.39 01/11/03 17:52:07 benh
8 #include <linux/config.h>
9 #include <linux/kernel.h>
10 #include <linux/pci.h>
11 #include <linux/delay.h>
12 #include <linux/string.h>
13 #include <linux/init.h>
14 #include <linux/ide.h>
15 #include <linux/bootmem.h>
18 #include <asm/pgtable.h>
20 #include <asm/hydra.h>
23 #include <asm/machdep.h>
24 #include <asm/sections.h>
25 #include <asm/pci-bridge.h>
26 #include <asm/open_pic.h>
29 unsigned long gg2_pci_config_base __chrpdata;
31 #define pci_config_addr(dev, offset) \
32 (gg2_pci_config_base | ((dev->bus->number)<<16) | ((dev->devfn)<<8) | (offset))
34 volatile struct Hydra *Hydra __chrpdata = NULL;
37 extern int chrp_is_briq;
40 * The VLSI Golden Gate II has only 512K of PCI configuration space, so we
41 * limit the bus number to 3 bits
44 #define cfg_read(val, addr, type, op) *val = op((type)(addr))
45 #define cfg_write(val, addr, type, op) op((type *)(addr), (val))
47 #define cfg_read_bad(val, size) *val = bad_##size;
48 #define cfg_write_bad(val, size)
51 #define bad_word 0xffff
52 #define bad_dword 0xffffffffU
54 #define GG2_PCI_OP(rw, size, type, op) \
55 int __chrp gg2_##rw##_config_##size(struct pci_dev *dev, int off, type val) \
57 if (dev->bus->number > 7) { \
58 cfg_##rw##_bad(val, size) \
59 return PCIBIOS_DEVICE_NOT_FOUND; \
61 cfg_##rw(val, pci_config_addr(dev, off), type, op); \
62 return PCIBIOS_SUCCESSFUL; \
65 GG2_PCI_OP(read, byte, u8 *, in_8)
66 GG2_PCI_OP(read, word, u16 *, in_le16)
67 GG2_PCI_OP(read, dword, u32 *, in_le32)
68 GG2_PCI_OP(write, byte, u8, out_8)
69 GG2_PCI_OP(write, word, u16, out_le16)
70 GG2_PCI_OP(write, dword, u32, out_le32)
72 static struct pci_ops gg2_pci_ops __chrpdata =
76 gg2_read_config_dword,
77 gg2_write_config_byte,
78 gg2_write_config_word,
79 gg2_write_config_dword
83 * Access functions for PCI config space on IBM "python" host bridges.
85 #define PYTHON_CFA(b, d, o) (0x80 | ((b) << 8) | ((d) << 16) \
88 #define PYTHON_PCI_OP(rw, size, type, op, mask) \
90 python_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
92 struct pci_controller *hose = dev->sysdata; \
94 out_be32(hose->cfg_addr, \
95 PYTHON_CFA(dev->bus->number, dev->devfn, offset)); \
96 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
97 return PCIBIOS_SUCCESSFUL; \
100 PYTHON_PCI_OP(read, byte, u8 *, in_8, 3)
101 PYTHON_PCI_OP(read, word, u16 *, in_le16, 2)
102 PYTHON_PCI_OP(read, dword, u32 *, in_le32, 0)
103 PYTHON_PCI_OP(write, byte, u8, out_8, 3)
104 PYTHON_PCI_OP(write, word, u16, out_le16, 2)
105 PYTHON_PCI_OP(write, dword, u32, out_le32, 0)
107 static struct pci_ops python_pci_ops __chrpdata =
109 python_read_config_byte,
110 python_read_config_word,
111 python_read_config_dword,
112 python_write_config_byte,
113 python_write_config_word,
114 python_write_config_dword
118 * Access functions for PCI config space using RTAS calls.
120 #define RTAS_PCI_READ_OP(size, type, nbytes) \
122 rtas_read_config_##size(struct pci_dev *dev, int offset, type val) \
124 unsigned long addr = (offset & 0xff) | ((dev->devfn & 0xff) << 8) \
125 | ((dev->bus->number & 0xff) << 16); \
126 unsigned long ret = ~0UL; \
129 rval = call_rtas("read-pci-config", 2, 2, &ret, addr, nbytes); \
131 return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL; \
134 #define RTAS_PCI_WRITE_OP(size, type, nbytes) \
136 rtas_write_config_##size(struct pci_dev *dev, int offset, type val) \
138 unsigned long addr = (offset & 0xff) | ((dev->devfn & 0xff) << 8) \
139 | ((dev->bus->number & 0xff) << 16); \
142 rval = call_rtas("write-pci-config", 3, 1, NULL, \
143 addr, nbytes, (ulong)val); \
144 return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL; \
147 RTAS_PCI_READ_OP(byte, u8 *, 1)
148 RTAS_PCI_READ_OP(word, u16 *, 2)
149 RTAS_PCI_READ_OP(dword, u32 *, 4)
150 RTAS_PCI_WRITE_OP(byte, u8, 1)
151 RTAS_PCI_WRITE_OP(word, u16, 2)
152 RTAS_PCI_WRITE_OP(dword, u32, 4)
154 static struct pci_ops rtas_pci_ops __chrpdata =
156 rtas_read_config_byte,
157 rtas_read_config_word,
158 rtas_read_config_dword,
159 rtas_write_config_byte,
160 rtas_write_config_word,
161 rtas_write_config_dword
167 struct device_node *np;
169 np = find_devices("mac-io");
170 if (np == NULL || np->n_addrs == 0)
172 Hydra = ioremap(np->addrs[0].address, np->addrs[0].size);
173 printk("Hydra Mac I/O at %x\n", np->addrs[0].address);
174 printk("Hydra Feature_Control was %x",
175 in_le32(&Hydra->Feature_Control));
176 out_le32(&Hydra->Feature_Control, (HYDRA_FC_SCC_CELL_EN |
177 HYDRA_FC_SCSI_CELL_EN |
178 HYDRA_FC_SCCA_ENABLE |
179 HYDRA_FC_SCCB_ENABLE |
180 HYDRA_FC_ARB_BYPASS |
181 HYDRA_FC_MPIC_ENABLE |
182 HYDRA_FC_SLOW_SCC_PCLK |
183 HYDRA_FC_MPIC_IS_MASTER));
184 printk(", now %x\n", in_le32(&Hydra->Feature_Control));
189 chrp_pcibios_fixup(void)
192 struct device_node *np;
194 /* PCI interrupts are controlled by the OpenPIC */
195 pci_for_each_dev(dev) {
196 np = pci_device_to_OF_node(dev);
197 if ((np != 0) && (np->n_intrs > 0) && (np->intrs[0].line != 0))
198 dev->irq = np->intrs[0].line;
199 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
203 /* W83C553 IDE Interrupt Routing Control Register */
204 #define W83C553_IDEIRCR 0x43
206 /* SL82C105 IDE Control/Status Register */
207 #define SL82C105_IDECSR 0x40
210 longtrail_pcibios_fixup(void)
212 struct pci_dev *w83c553, *sl82c105;
215 chrp_pcibios_fixup();
218 * Open Firmware may have left the SL82C105 IDE interface in the
219 * W83C553 PCI/ISA bridge in legacy mode
221 if ((w83c553 = pci_find_device(PCI_VENDOR_ID_WINBOND,
222 PCI_DEVICE_ID_WINBOND_83C553, 0)) &&
223 (sl82c105 = pci_find_device(PCI_VENDOR_ID_WINBOND,
224 PCI_DEVICE_ID_WINBOND_82C105,
226 (sl82c105->class & 5) != 5) {
227 printk("W83C553: Switching SL82C105 IDE to PCI native mode\n");
228 /* Enable W83C553 legacy interrupt internal routing to INTC#, */
229 /* which is connected to HYDRA_INT_EXT5 */
230 pci_write_config_byte(w83c553, W83C553_IDEIRCR, 0x00);
231 /* Enable SL82C105 PCI native IDE mode */
232 pci_read_config_byte(sl82c105, PCI_CLASS_PROG, &progif);
233 pci_write_config_byte(sl82c105, PCI_CLASS_PROG, progif | 0x05);
234 sl82c105->class |= 0x05;
235 /* Enable SL82C105 legacy interrupts & both channels */
236 pci_write_config_word(sl82c105, SL82C105_IDECSR, 0x0833);
241 briq_pcibios_fixup(void)
243 struct pci_dev *w83c553, *sl82c105;
246 chrp_pcibios_fixup();
249 * Open Firmware may have left the SL82C105 IDE interface in the
250 * W83C553 PCI/ISA bridge in legacy mode
252 if ((w83c553 = pci_find_device(PCI_VENDOR_ID_WINBOND,
253 PCI_DEVICE_ID_WINBOND_83C553, 0)) &&
254 (sl82c105 = pci_find_device(PCI_VENDOR_ID_WINBOND,
255 PCI_DEVICE_ID_WINBOND_82C105,
257 (sl82c105->class & 5) != 5) {
258 printk("W83C553: Switching SL82C105 IDE to PCI native mode\n");
259 /* Enable SL82C105 PCI native IDE mode */
260 pci_read_config_byte(sl82c105, PCI_CLASS_PROG, &progif);
261 pci_write_config_byte(sl82c105, PCI_CLASS_PROG, progif | 0x05);
262 sl82c105->class |= 0x05;
263 /* Disable SL82C105 second port */
264 pci_write_config_word(sl82c105, SL82C105_IDECSR, 0x0003);
268 #define PRG_CL_RESET_VALID 0x00010000
271 setup_python(struct pci_controller *hose, struct device_node *dev)
274 volatile unsigned char *cfg;
276 hose->ops = &python_pci_ops;
277 cfg = ioremap(dev->addrs[0].address + 0xf8000, 0x20);
278 hose->cfg_addr = (volatile unsigned int *) cfg;
279 hose->cfg_data = cfg + 0x10;
281 /* Clear the magic go-slow bit */
282 reg = (u32 *) ioremap(dev->addrs[0].address + 0xf6000, 0x40);
283 val = in_be32(®[12]);
284 if (val & PRG_CL_RESET_VALID) {
285 out_be32(®[12], val & ~PRG_CL_RESET_VALID);
292 chrp_find_bridges(void)
294 struct device_node *dev;
297 struct pci_controller *hose;
299 char *model, *machine;
300 int is_longtrail = 0, is_mot = 0;
301 struct device_node *root = find_path_device("/");
304 * The PCI host bridge nodes on some machines don't have
305 * properties to adequately identify them, so we have to
306 * look at what sort of machine this is as well.
308 machine = get_property(root, "model", NULL);
309 if (machine != NULL) {
310 is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0;
311 is_mot = strncmp(machine, "MOT", 3) == 0;
313 for (dev = root->child; dev != NULL; dev = dev->sibling) {
314 if (dev->type == NULL || strcmp(dev->type, "pci") != 0)
317 /* The GG2 bridge on the LongTrail doesn't have an address */
318 if (dev->n_addrs < 1 && !is_longtrail) {
319 printk(KERN_WARNING "Can't use %s: no address\n",
323 bus_range = (int *) get_property(dev, "bus-range", &len);
324 if (bus_range == NULL || len < 2 * sizeof(int)) {
325 printk(KERN_WARNING "Can't get bus-range for %s\n",
329 if (bus_range[1] == bus_range[0])
330 printk(KERN_INFO "PCI bus %d", bus_range[0]);
332 printk(KERN_INFO "PCI buses %d..%d",
333 bus_range[0], bus_range[1]);
334 printk(" controlled by %s", dev->type);
335 if (dev->n_addrs > 0)
336 printk(" at %x", dev->addrs[0].address);
339 hose = pcibios_alloc_controller();
341 printk("Can't allocate PCI controller structure for %s\n",
345 hose->arch_data = dev;
346 hose->first_busno = bus_range[0];
347 hose->last_busno = bus_range[1];
349 model = get_property(dev, "model", NULL);
352 if (device_is_compatible(dev, "IBM,python")) {
353 setup_python(hose, dev);
355 || strncmp(model, "Motorola, Grackle", 17) == 0) {
357 } else if (is_longtrail) {
358 hose->ops = &gg2_pci_ops;
359 gg2_pci_config_base = (unsigned long)
360 ioremap(GG2_PCI_CONFIG_BASE, 0x80000);
361 } else if (!strncmp(model, "IBM,CPC710", 10)) {
362 setup_indirect_pci(hose,
363 dev->addrs[0].address + 0x000f8000,
364 dev->addrs[0].address + 0x000f8010);
366 dma = (unsigned int *)
367 get_property(dev, "system-dma-base", &len);
368 if (dma && len >= sizeof(*dma)) {
369 dma = (unsigned int *)(((unsigned long)dma) +
371 pci_dram_offset = *dma;
375 printk("No methods for %s (model %s), using RTAS\n",
376 dev->full_name, model);
377 hose->ops = &rtas_pci_ops;
380 pci_process_bridge_OF_ranges(hose, dev, index == 0);
382 /* check the first bridge for a property that we can
383 use to set pci_dram_offset */
384 dma = (unsigned int *)
385 get_property(dev, "ibm,dma-ranges", &len);
386 if (index == 0 && dma != NULL && len >= 6 * sizeof(*dma)) {
387 pci_dram_offset = dma[2] - dma[3];
388 printk("pci_dram_offset = %lx\n", pci_dram_offset);
393 ppc_md.pcibios_fixup = longtrail_pcibios_fixup;
394 else if (chrp_is_briq)
395 ppc_md.pcibios_fixup = briq_pcibios_fixup;
397 ppc_md.pcibios_fixup = chrp_pcibios_fixup;