blob: b55258e49208f5ba979d111b17a2f8a1ff2cda37 [file] [log] [blame]
Andi Kleendfa46982006-09-26 10:52:30 +02001/* Various workarounds for chipset bugs.
2 This code runs very early and can't use the regular PCI subsystem
3 The entries are keyed to PCI bridges which usually identify chipsets
4 uniquely.
5 This is only for whole classes of chipsets with specific problems which
6 need early invasive action (e.g. before the timers are initialized).
7 Most PCI device specific workarounds can be done later and should be
8 in standard PCI quirks
9 Mainboard specific bugs should be handled by DMI entries.
10 CPU specific bugs in setup.c */
11
12#include <linux/pci.h>
13#include <linux/acpi.h>
14#include <linux/pci_ids.h>
15#include <asm/pci-direct.h>
Andi Kleendfa46982006-09-26 10:52:30 +020016#include <asm/dma.h>
Andi Kleen54ef3402007-10-19 20:35:03 +020017#include <asm/io_apic.h>
18#include <asm/apic.h>
19
Joerg Roedel966396d2007-10-24 12:49:48 +020020#ifdef CONFIG_GART_IOMMU
Joerg Roedel395624f2007-10-24 12:49:47 +020021#include <asm/gart.h>
Andi Kleen54ef3402007-10-19 20:35:03 +020022#endif
Andi Kleendfa46982006-09-26 10:52:30 +020023
Neil Hormanc6b48322008-01-30 13:31:25 +010024static void __init fix_hypertransport_config(int num, int slot, int func)
25{
26 u32 htcfg;
27 /*
28 * we found a hypertransport bus
29 * make sure that we are broadcasting
30 * interrupts to all cpus on the ht bus
31 * if we're using extended apic ids
32 */
33 htcfg = read_pci_config(num, slot, func, 0x68);
34 if (htcfg & (1 << 18)) {
35 printk(KERN_INFO "Detected use of extended apic ids on hypertransport bus\n");
36 if ((htcfg & (1 << 17)) == 0) {
37 printk(KERN_INFO "Enabling hypertransport extended apic interrupt broadcast\n");
38 printk(KERN_INFO "Note this is a bios bug, please contact your hw vendor\n");
39 htcfg |= (1 << 17);
40 write_pci_config(num, slot, func, 0x68, htcfg);
41 }
42 }
43
44
45}
46
47static void __init via_bugs(int num, int slot, int func)
Andi Kleendfa46982006-09-26 10:52:30 +020048{
Joerg Roedel966396d2007-10-24 12:49:48 +020049#ifdef CONFIG_GART_IOMMU
Andi Kleendfa46982006-09-26 10:52:30 +020050 if ((end_pfn > MAX_DMA32_PFN || force_iommu) &&
Joerg Roedel0440d4c2007-10-24 12:49:50 +020051 !gart_iommu_aperture_allowed) {
Andi Kleendfa46982006-09-26 10:52:30 +020052 printk(KERN_INFO
Andi Kleen54ef3402007-10-19 20:35:03 +020053 "Looks like a VIA chipset. Disabling IOMMU."
54 " Override with iommu=allowed\n");
Joerg Roedel0440d4c2007-10-24 12:49:50 +020055 gart_iommu_aperture_disabled = 1;
Andi Kleendfa46982006-09-26 10:52:30 +020056 }
57#endif
58}
59
60#ifdef CONFIG_ACPI
Jeff Garzik03d0d202007-10-27 20:57:43 +020061#ifdef CONFIG_X86_IO_APIC
Andi Kleendfa46982006-09-26 10:52:30 +020062
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +030063static int __init nvidia_hpet_check(struct acpi_table_header *header)
Andi Kleendfa46982006-09-26 10:52:30 +020064{
Andi Kleendfa46982006-09-26 10:52:30 +020065 return 0;
66}
Jeff Garzik03d0d202007-10-27 20:57:43 +020067#endif /* CONFIG_X86_IO_APIC */
68#endif /* CONFIG_ACPI */
Andi Kleendfa46982006-09-26 10:52:30 +020069
Neil Hormanc6b48322008-01-30 13:31:25 +010070static void __init nvidia_bugs(int num, int slot, int func)
Andi Kleendfa46982006-09-26 10:52:30 +020071{
72#ifdef CONFIG_ACPI
Andi Kleen54ef3402007-10-19 20:35:03 +020073#ifdef CONFIG_X86_IO_APIC
Andi Kleendfa46982006-09-26 10:52:30 +020074 /*
75 * All timer overrides on Nvidia are
76 * wrong unless HPET is enabled.
Andi Kleenfa18f472006-11-14 16:57:46 +010077 * Unfortunately that's not true on many Asus boards.
78 * We don't know yet how to detect this automatically, but
79 * at least allow a command line override.
Andi Kleendfa46982006-09-26 10:52:30 +020080 */
Andi Kleenfa18f472006-11-14 16:57:46 +010081 if (acpi_use_timer_override)
82 return;
83
Len Brownfe699332007-03-08 18:28:32 -050084 if (acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check)) {
Andi Kleendfa46982006-09-26 10:52:30 +020085 acpi_skip_timer_override = 1;
86 printk(KERN_INFO "Nvidia board "
87 "detected. Ignoring ACPI "
88 "timer override.\n");
Andi Kleenfa18f472006-11-14 16:57:46 +010089 printk(KERN_INFO "If you got timer trouble "
90 "try acpi_use_timer_override\n");
Andi Kleendfa46982006-09-26 10:52:30 +020091 }
92#endif
Andi Kleen54ef3402007-10-19 20:35:03 +020093#endif
Andi Kleendfa46982006-09-26 10:52:30 +020094 /* RED-PEN skip them on mptables too? */
95
96}
97
Neil Hormanc6b48322008-01-30 13:31:25 +010098static void __init ati_bugs(int num, int slot, int func)
Andi Kleendfa46982006-09-26 10:52:30 +020099{
Andi Kleen54ef3402007-10-19 20:35:03 +0200100#ifdef CONFIG_X86_IO_APIC
Linus Torvaldsfea5f1e2007-01-08 15:04:46 -0800101 if (timer_over_8254 == 1) {
102 timer_over_8254 = 0;
103 printk(KERN_INFO
Andi Kleen54ef3402007-10-19 20:35:03 +0200104 "ATI board detected. Disabling timer routing over 8254.\n");
Linus Torvaldsfea5f1e2007-01-08 15:04:46 -0800105 }
Andi Kleen54ef3402007-10-19 20:35:03 +0200106#endif
Andi Kleendfa46982006-09-26 10:52:30 +0200107}
108
Neil Hormanc6b48322008-01-30 13:31:25 +0100109#define QFLAG_APPLY_ONCE 0x1
110#define QFLAG_APPLIED 0x2
111#define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
Andi Kleendfa46982006-09-26 10:52:30 +0200112struct chipset {
Neil Hormanc6b48322008-01-30 13:31:25 +0100113 u32 vendor;
114 u32 device;
115 u32 class;
116 u32 class_mask;
117 u32 flags;
118 void (*f)(int num, int slot, int func);
Andi Kleendfa46982006-09-26 10:52:30 +0200119};
120
Andrew Mortonc993c732007-04-08 16:04:03 -0700121static struct chipset early_qrk[] __initdata = {
Neil Hormanc6b48322008-01-30 13:31:25 +0100122 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
123 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs },
124 { PCI_VENDOR_ID_VIA, PCI_ANY_ID,
125 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs },
126 { PCI_VENDOR_ID_ATI, PCI_ANY_ID,
127 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, ati_bugs },
128 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
129 PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config },
Andi Kleendfa46982006-09-26 10:52:30 +0200130 {}
131};
132
133void __init early_quirks(void)
134{
135 int num, slot, func;
Andi Kleen0637a702006-09-26 10:52:41 +0200136
137 if (!early_pci_allowed())
138 return;
139
Andi Kleendfa46982006-09-26 10:52:30 +0200140 /* Poor man's PCI discovery */
141 for (num = 0; num < 32; num++) {
142 for (slot = 0; slot < 32; slot++) {
143 for (func = 0; func < 8; func++) {
Neil Hormanc6b48322008-01-30 13:31:25 +0100144 u16 class;
145 u16 vendor;
146 u16 device;
Andi Kleendfa46982006-09-26 10:52:30 +0200147 u8 type;
148 int i;
Neil Hormanc6b48322008-01-30 13:31:25 +0100149
150 class = read_pci_config_16(num,slot,func,
Andi Kleendfa46982006-09-26 10:52:30 +0200151 PCI_CLASS_REVISION);
Neil Hormanc6b48322008-01-30 13:31:25 +0100152 if (class == 0xffff)
Andi Kleendfa46982006-09-26 10:52:30 +0200153 break;
154
Neil Hormanc6b48322008-01-30 13:31:25 +0100155 vendor = read_pci_config_16(num, slot, func,
Andi Kleendfa46982006-09-26 10:52:30 +0200156 PCI_VENDOR_ID);
Andi Kleendfa46982006-09-26 10:52:30 +0200157
Neil Hormanc6b48322008-01-30 13:31:25 +0100158 device = read_pci_config_16(num, slot, func,
159 PCI_DEVICE_ID);
160
161 for(i=0;early_qrk[i].f != NULL;i++) {
162 if (((early_qrk[i].vendor == PCI_ANY_ID) ||
163 (early_qrk[i].vendor == vendor)) &&
164 ((early_qrk[i].device == PCI_ANY_ID) ||
165 (early_qrk[i].device == device)) &&
166 (!((early_qrk[i].class ^ class) &
167 early_qrk[i].class_mask))) {
168 if ((early_qrk[i].flags & QFLAG_DONE) != QFLAG_DONE)
169 early_qrk[i].f(num, slot, func);
170 early_qrk[i].flags |= QFLAG_APPLIED;
171
Andi Kleendfa46982006-09-26 10:52:30 +0200172 }
Neil Hormanc6b48322008-01-30 13:31:25 +0100173 }
Andi Kleendfa46982006-09-26 10:52:30 +0200174
175 type = read_pci_config_byte(num, slot, func,
176 PCI_HEADER_TYPE);
177 if (!(type & 0x80))
178 break;
179 }
180 }
181 }
182}