[PATCH] Minor 32bit compatibility fix for /dev/rtc
[linux-2.6/history.git] / arch / x86_64 / pci / common.c
blob8a189e818ef180656a525640940bcd61fe5f2bd2
1 /*
2 * Low-Level PCI Support for PC
4 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
6 Note: on x86-64 there is no PCI BIOS so there is no way to sort in the
7 same order as 32bit Linux. This could cause grief for dualbooting because
8 devices may wander. May want to use ACPI for sorting eventually.
12 #include <linux/sched.h>
13 #include <linux/pci.h>
14 #include <linux/init.h>
15 #include <linux/ioport.h>
17 #include <asm/segment.h>
18 #include <asm/io.h>
19 #include <asm/smp.h>
20 #include <asm/cache.h>
22 #include "pci.h"
24 unsigned int pci_probe = PCI_PROBE_CONF1 | PCI_PROBE_CONF2;
26 int pcibios_last_bus = 0xff; /* XXX */
27 struct pci_bus *pci_root_bus = NULL;
28 struct pci_ops *pci_root_ops = NULL;
30 int (*pci_config_read)(int seg, int bus, int dev, int fn, int reg, int len, u32 *value) = NULL;
31 int (*pci_config_write)(int seg, int bus, int dev, int fn, int reg, int len, u32 value) = NULL;
34 * legacy, numa, and acpi all want to call pcibios_scan_root
35 * from their initcalls. This flag prevents that.
37 int pcibios_scanned;
40 * This interrupt-safe spinlock protects all accesses to PCI
41 * configuration space.
43 spinlock_t pci_config_lock = SPIN_LOCK_UNLOCKED;
46 * Several buggy motherboards address only 16 devices and mirror
47 * them to next 16 IDs. We try to detect this `feature' on all
48 * primary buses (those containing host bridges as they are
49 * expected to be unique) and remove the ghost devices.
52 static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
54 struct list_head *ln, *mn;
55 struct pci_dev *d, *e;
56 int mirror = PCI_DEVFN(16,0);
57 int seen_host_bridge = 0;
58 int i;
60 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
61 for (ln=b->devices.next; ln != &b->devices; ln=ln->next) {
62 d = pci_dev_b(ln);
63 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
64 seen_host_bridge++;
65 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
66 e = pci_dev_b(mn);
67 if (e->devfn != d->devfn + mirror ||
68 e->vendor != d->vendor ||
69 e->device != d->device ||
70 e->class != d->class)
71 continue;
72 for(i=0; i<PCI_NUM_RESOURCES; i++)
73 if (e->resource[i].start != d->resource[i].start ||
74 e->resource[i].end != d->resource[i].end ||
75 e->resource[i].flags != d->resource[i].flags)
76 continue;
77 break;
79 if (mn == &b->devices)
80 return;
82 if (!seen_host_bridge)
83 return;
84 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
86 ln = &b->devices;
87 while (ln->next != &b->devices) {
88 d = pci_dev_b(ln->next);
89 if (d->devfn >= mirror) {
90 list_del(&d->global_list);
91 list_del(&d->bus_list);
92 kfree(d);
93 } else
94 ln = ln->next;
98 struct pbus_set_ranges_data;
100 void __devinit
101 pcibios_fixup_pbus_ranges (struct pci_bus *bus, struct pbus_set_ranges_data *ranges)
106 * Called after each bus is probed, but before its children
107 * are examined.
110 void __devinit pcibios_fixup_bus(struct pci_bus *b)
112 pcibios_fixup_ghosts(b);
113 pci_read_bridge_bases(b);
117 struct pci_bus * __devinit pcibios_scan_root(int busnum)
119 struct list_head *list;
120 struct pci_bus *bus;
122 list_for_each(list, &pci_root_buses) {
123 bus = pci_bus_b(list);
124 if (bus->number == busnum) {
125 /* Already scanned */
126 return bus;
130 printk("PCI: Probing PCI hardware (bus %02x)\n", busnum);
132 return pci_scan_bus(busnum, pci_root_ops, NULL);
135 extern u8 pci_cache_line_size;
137 static int __init pcibios_init(void)
139 if (!pci_root_ops) {
140 printk("PCI: System does not support PCI\n");
141 return 0;
144 pci_cache_line_size = boot_cpu_data.x86_clflush_size >> 2;
146 pcibios_resource_survey();
148 #ifdef CONFIG_GART_IOMMU
149 pci_iommu_init();
150 #endif
152 /* may eventually need to do ACPI sort here. */
153 return 0;
156 subsys_initcall(pcibios_init);
158 char * __devinit pcibios_setup(char *str)
160 if (!strcmp(str, "off")) {
161 pci_probe = 0;
162 return NULL;
164 #ifdef CONFIG_PCI_DIRECT
165 else if (!strcmp(str, "conf1")) {
166 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
167 return NULL;
169 else if (!strcmp(str, "conf2")) {
170 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
171 return NULL;
173 #endif
174 #ifdef CONFIG_ACPI_PCI
175 else if (!strcmp(str, "noacpi")) {
176 pci_probe |= PCI_NO_ACPI_ROUTING;
177 return NULL;
179 #endif
180 else if (!strcmp(str, "rom")) {
181 pci_probe |= PCI_ASSIGN_ROMS;
182 return NULL;
183 } else if (!strcmp(str, "assign-busses")) {
184 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
185 return NULL;
186 } else if (!strcmp(str, "usepirqmask")) {
187 pci_probe |= PCI_USE_PIRQ_MASK;
188 return NULL;
189 } else if (!strncmp(str, "irqmask=", 8)) {
190 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
191 return NULL;
192 } else if (!strncmp(str, "lastbus=", 8)) {
193 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
194 return NULL;
196 return str;
199 unsigned int pcibios_assign_all_busses(void)
201 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
204 int pcibios_enable_device(struct pci_dev *dev, int mask)
206 int err;
208 if ((err = pcibios_enable_resources(dev, mask)) < 0)
209 return err;
211 return pcibios_enable_irq(dev);