]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/i386/pci/common.c
Merge branch 'master'
[mirror_ubuntu-artful-kernel.git] / arch / i386 / pci / common.c
CommitLineData
1da177e4
LT
1/*
2 * Low-Level PCI Support for PC
3 *
4 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
5 */
6
7#include <linux/sched.h>
8#include <linux/pci.h>
9#include <linux/ioport.h>
10#include <linux/init.h>
11
12#include <asm/acpi.h>
13#include <asm/segment.h>
14#include <asm/io.h>
15#include <asm/smp.h>
16
17#include "pci.h"
18
19#ifdef CONFIG_PCI_BIOS
20extern void pcibios_sort(void);
21#endif
22
23unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
24 PCI_PROBE_MMCONF;
25
26int pci_routeirq;
27int pcibios_last_bus = -1;
120bb424 28unsigned long pirq_table_addr;
29struct pci_bus *pci_root_bus;
1da177e4
LT
30struct pci_raw_ops *raw_pci_ops;
31
32static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
33{
34 return raw_pci_ops->read(0, bus->number, devfn, where, size, value);
35}
36
37static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
38{
39 return raw_pci_ops->write(0, bus->number, devfn, where, size, value);
40}
41
42struct pci_ops pci_root_ops = {
43 .read = pci_read,
44 .write = pci_write,
45};
46
47/*
48 * legacy, numa, and acpi all want to call pcibios_scan_root
49 * from their initcalls. This flag prevents that.
50 */
51int pcibios_scanned;
52
53/*
54 * This interrupt-safe spinlock protects all accesses to PCI
55 * configuration space.
56 */
57DEFINE_SPINLOCK(pci_config_lock);
58
59/*
60 * Several buggy motherboards address only 16 devices and mirror
61 * them to next 16 IDs. We try to detect this `feature' on all
62 * primary buses (those containing host bridges as they are
63 * expected to be unique) and remove the ghost devices.
64 */
65
66static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
67{
68 struct list_head *ln, *mn;
69 struct pci_dev *d, *e;
70 int mirror = PCI_DEVFN(16,0);
71 int seen_host_bridge = 0;
72 int i;
73
74 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
75 list_for_each(ln, &b->devices) {
76 d = pci_dev_b(ln);
77 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
78 seen_host_bridge++;
79 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
80 e = pci_dev_b(mn);
81 if (e->devfn != d->devfn + mirror ||
82 e->vendor != d->vendor ||
83 e->device != d->device ||
84 e->class != d->class)
85 continue;
86 for(i=0; i<PCI_NUM_RESOURCES; i++)
87 if (e->resource[i].start != d->resource[i].start ||
88 e->resource[i].end != d->resource[i].end ||
89 e->resource[i].flags != d->resource[i].flags)
90 continue;
91 break;
92 }
93 if (mn == &b->devices)
94 return;
95 }
96 if (!seen_host_bridge)
97 return;
98 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
99
100 ln = &b->devices;
101 while (ln->next != &b->devices) {
102 d = pci_dev_b(ln->next);
103 if (d->devfn >= mirror) {
104 list_del(&d->global_list);
105 list_del(&d->bus_list);
106 kfree(d);
107 } else
108 ln = ln->next;
109 }
110}
111
112/*
113 * Called after each bus is probed, but before its children
114 * are examined.
115 */
116
117void __devinit pcibios_fixup_bus(struct pci_bus *b)
118{
119 pcibios_fixup_ghosts(b);
120 pci_read_bridge_bases(b);
121}
122
123
124struct pci_bus * __devinit pcibios_scan_root(int busnum)
125{
126 struct pci_bus *bus = NULL;
127
128 while ((bus = pci_find_next_bus(bus)) != NULL) {
129 if (bus->number == busnum) {
130 /* Already scanned */
131 return bus;
132 }
133 }
134