1 /* pci-vdk.c: MB93090-MB00 (VDK) PCI support
3 * Copyright (C) 2003, 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/pci.h>
16 #include <linux/init.h>
17 #include <linux/ioport.h>
18 #include <linux/delay.h>
19 #include <linux/slab.h>
21 #include <asm/segment.h>
23 #include <asm/mb-regs.h>
24 #include <asm/mb86943a.h>
27 unsigned int __nongpreldata pci_probe = 1;
29 int __nongpreldata pcibios_last_bus = -1;
30 struct pci_bus *__nongpreldata pci_root_bus;
31 struct pci_ops *__nongpreldata pci_root_ops;
34 * Functions for accessing PCI configuration space
37 #define CONFIG_CMD(bus, dev, where) \
38 (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3))
40 #define __set_PciCfgAddr(A) writel((A), (volatile void __iomem *) __region_CS1 + 0x80)
42 #define __get_PciCfgDataB(A) readb((volatile void __iomem *) __region_CS1 + 0x88 + ((A) & 3))
43 #define __get_PciCfgDataW(A) readw((volatile void __iomem *) __region_CS1 + 0x88 + ((A) & 2))
44 #define __get_PciCfgDataL(A) readl((volatile void __iomem *) __region_CS1 + 0x88)
46 #define __set_PciCfgDataB(A,V) \
47 writeb((V), (volatile void __iomem *) __region_CS1 + 0x88 + (3 - ((A) & 3)))
49 #define __set_PciCfgDataW(A,V) \
50 writew((V), (volatile void __iomem *) __region_CS1 + 0x88 + (2 - ((A) & 2)))
52 #define __set_PciCfgDataL(A,V) \
53 writel((V), (volatile void __iomem *) __region_CS1 + 0x88)
55 #define __get_PciBridgeDataB(A) readb((volatile void __iomem *) __region_CS1 + 0x800 + (A))
56 #define __get_PciBridgeDataW(A) readw((volatile void __iomem *) __region_CS1 + 0x800 + (A))
57 #define __get_PciBridgeDataL(A) readl((volatile void __iomem *) __region_CS1 + 0x800 + (A))
59 #define __set_PciBridgeDataB(A,V) writeb((V), (volatile void __iomem *) __region_CS1 + 0x800 + (A))
60 #define __set_PciBridgeDataW(A,V) writew((V), (volatile void __iomem *) __region_CS1 + 0x800 + (A))
61 #define __set_PciBridgeDataL(A,V) writel((V), (volatile void __iomem *) __region_CS1 + 0x800 + (A))
63 static inline int __query(const struct pci_dev *dev)
65 // return dev->bus->number==0 && (dev->devfn==PCI_DEVFN(0,0));
66 // return dev->bus->number==1;
67 // return dev->bus->number==0 &&
68 // (dev->devfn==PCI_DEVFN(2,0) || dev->devfn==PCI_DEVFN(3,0));
72 /*****************************************************************************/
76 static int pci_frv_read_config(struct pci_bus *bus, unsigned int devfn, int where, int size,
81 if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
82 _value = __get_PciBridgeDataL(where & ~3);
85 __set_PciCfgAddr(CONFIG_CMD(bus, devfn, where));
86 _value = __get_PciCfgDataL(where & ~3);
91 _value = _value >> ((where & 3) * 8);
95 _value = _value >> ((where & 2) * 8);
106 return PCIBIOS_SUCCESSFUL;
109 static int pci_frv_write_config(struct pci_bus *bus, unsigned int devfn, int where, int size,
114 if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
115 __set_PciBridgeDataB(where, value);
118 __set_PciCfgAddr(CONFIG_CMD(bus, devfn, where));
119 __set_PciCfgDataB(where, value);
124 if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
125 __set_PciBridgeDataW(where, value);
128 __set_PciCfgAddr(CONFIG_CMD(bus, devfn, where));
129 __set_PciCfgDataW(where, value);
134 if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
135 __set_PciBridgeDataL(where, value);
138 __set_PciCfgAddr(CONFIG_CMD(bus, devfn, where));
139 __set_PciCfgDataL(where, value);
147 return PCIBIOS_SUCCESSFUL;
150 static struct pci_ops pci_direct_frv = {
152 pci_frv_write_config,
156 * Before we decide to use direct hardware access mechanisms, we try to do some
157 * trivial checks to ensure it at least _seems_ to be working -- we just test
158 * whether bus 00 contains a host bridge (this is similar to checking
159 * techniques used in XFree86, but ours should be more reliable since we
160 * attempt to make use of direct access hints provided by the PCI BIOS).
162 * This should be close to trivial, but it isn't, because there are buggy
163 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
165 static int __init pci_sanity_check(struct pci_ops *o)
167 struct pci_bus bus; /* Fake bus and device */
172 if (o->read(&bus, 0, PCI_VENDOR_ID, 4, &id) == PCIBIOS_SUCCESSFUL) {
173 printk("PCI: VDK Bridge device:vendor: %08x\n", id);
174 if (id == 0x200e10cf)
178 printk("PCI: VDK Bridge: Sanity check failed\n");
182 static struct pci_ops * __init pci_check_direct(void)
186 local_irq_save(flags);
188 /* check if access works */
189 if (pci_sanity_check(&pci_direct_frv)) {
190 local_irq_restore(flags);
191 printk("PCI: Using configuration frv\n");
192 // request_mem_region(0xBE040000, 256, "FRV bridge");
193 // request_mem_region(0xBFFFFFF4, 12, "PCI frv");
194 return &pci_direct_frv;
197 local_irq_restore(flags);
202 * Discover remaining PCI buses in case there are peer host bridges.
203 * We use the number of last PCI bus provided by the PCI BIOS.
205 static void __init pcibios_fixup_peer_bridges(void)
212 if (pcibios_last_bus <= 0 || pcibios_last_bus >= 0xff)
214 printk("PCI: Peer bridge fixup\n");
215 for (n=0; n <= pcibios_last_bus; n++) {
216 if (pci_find_bus(0, n))
219 bus.ops = pci_root_ops;
221 for(dev.devfn=0; dev.devfn<256; dev.devfn += 8)
222 if (!pci_read_config_word(&dev, PCI_VENDOR_ID, &l) &&
223 l != 0x0000 && l != 0xffff) {
224 printk("Found device at %02x:%02x [%04x]\n", n, dev.devfn, l);
225 printk("PCI: Discovered peer bus %02x\n", n);
226 pci_scan_bus(n, pci_root_ops, NULL);
233 * Exceptions for specific devices. Usually work-arounds for fatal design flaws.
236 static void __init pci_fixup_umc_ide(struct pci_dev *d)
239 * UM8886BF IDE controller sets region type bits incorrectly,
240 * therefore they look like memory despite of them being I/O.
244 printk("PCI: Fixing base address flags for device %s\n", pci_name(d));
246 d->resource[i].flags |= PCI_BASE_ADDRESS_SPACE_IO;
249 static void __init pci_fixup_ide_bases(struct pci_dev *d)
254 * PCI IDE controllers use non-standard I/O port decoding, respect it.
256 if ((d->class >> 8) != PCI_CLASS_STORAGE_IDE)
258 printk("PCI: IDE base address fixup for %s\n", pci_name(d));
260 struct resource *r = &d->resource[i];
261 if ((r->start & ~0x80) == 0x374) {
268 static void __init pci_fixup_ide_trash(struct pci_dev *d)
273 * There exist PCI IDE controllers which have utter garbage
274 * in first four base registers. Ignore that.
276 printk("PCI: IDE base address trash cleared for %s\n", pci_name(d));
278 d->resource[i].start = d->resource[i].end = d->resource[i].flags = 0;
281 static void __devinit pci_fixup_latency(struct pci_dev *d)
284 * SiS 5597 and 5598 chipsets require latency timer set to
285 * at most 32 to avoid lockups.
287 DBG("PCI: Setting max latency to 32\n");
288 pcibios_max_latency = 32;
291 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF, pci_fixup_umc_ide);
292 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5513, pci_fixup_ide_trash);
293 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5597, pci_fixup_latency);
294 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5598, pci_fixup_latency);
295 DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_ide_bases);
298 * Called after each bus is probed, but before its children
302 void __init pcibios_fixup_bus(struct pci_bus *bus)
305 printk("### PCIBIOS_FIXUP_BUS(%d)\n",bus->number);
307 pci_read_bridge_bases(bus);
309 if (bus->number == 0) {
310 struct list_head *ln;
312 for (ln=bus->devices.next; ln != &bus->devices; ln=ln->next) {
314 if (dev->devfn == 0) {
315 dev->resource[0].start = 0;
316 dev->resource[0].end = 0;
323 * Initialization. Try all known PCI access methods. Note that we support
324 * using both PCI BIOS and direct access: in such cases, we use I/O ports
325 * to access config space, but we still keep BIOS order of cards to be
326 * compatible with 2.0.X. This should go away some day.
329 int __init pcibios_init(void)
331 struct pci_ops *dir = NULL;
333 if (!mb93090_mb00_detected)
336 __reg_MB86943_sl_ctl |= MB86943_SL_CTL_DRCT_MASTER_SWAP | MB86943_SL_CTL_DRCT_SLAVE_SWAP;
338 __reg_MB86943_ecs_base(1) = ((__region_CS2 + 0x01000000) >> 9) | 0x08000000;
339 __reg_MB86943_ecs_base(2) = ((__region_CS2 + 0x00000000) >> 9) | 0x08000000;
341 *(volatile uint32_t *) (__region_CS1 + 0x848) = 0xe0000000;
342 *(volatile uint32_t *) (__region_CS1 + 0x8b8) = 0x00000000;
344 __reg_MB86943_sl_pci_io_base = (__region_CS2 + 0x04000000) >> 9;
345 __reg_MB86943_sl_pci_mem_base = (__region_CS2 + 0x08000000) >> 9;
346 __reg_MB86943_pci_sl_io_base = __region_CS2 + 0x04000000;
347 __reg_MB86943_pci_sl_mem_base = __region_CS2 + 0x08000000;
350 /* enable PCI arbitration */
351 __reg_MB86943_pci_arbiter = MB86943_PCIARB_EN;
353 ioport_resource.start = (__reg_MB86943_sl_pci_io_base << 9) & 0xfffffc00;
354 ioport_resource.end = (__reg_MB86943_sl_pci_io_range << 9) | 0x3ff;
355 ioport_resource.end += ioport_resource.start;
357 printk("PCI IO window: %08llx-%08llx\n",
358 (unsigned long long) ioport_resource.start,
359 (unsigned long long) ioport_resource.end);
361 iomem_resource.start = (__reg_MB86943_sl_pci_mem_base << 9) & 0xfffffc00;
363 /* Reserve somewhere to write to flush posted writes. */
364 iomem_resource.start += 0x400;
366 iomem_resource.end = (__reg_MB86943_sl_pci_mem_range << 9) | 0x3ff;
367 iomem_resource.end += iomem_resource.start;
369 printk("PCI MEM window: %08llx-%08llx\n",
370 (unsigned long long) iomem_resource.start,
371 (unsigned long long) iomem_resource.end);
372 printk("PCI DMA memory: %08lx-%08lx\n",
373 dma_coherent_mem_start, dma_coherent_mem_end);
378 dir = pci_check_direct();
382 printk("PCI: No PCI bus detected\n");
386 printk("PCI: Probing PCI hardware\n");
387 pci_root_bus = pci_scan_bus(0, pci_root_ops, NULL);
390 pcibios_fixup_peer_bridges();
391 pcibios_fixup_irqs();
392 pcibios_resource_survey();
397 arch_initcall(pcibios_init);
399 char * __init pcibios_setup(char *str)
401 if (!strcmp(str, "off")) {
404 } else if (!strncmp(str, "lastbus=", 8)) {
405 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
411 int pcibios_enable_device(struct pci_dev *dev, int mask)
415 if ((err = pci_enable_resources(dev, mask)) < 0)
417 if (!dev->msi_enabled)
418 pcibios_enable_irq(dev);