blob: a0e11c0cc872f03b1ca9b85fd9521f19fa8a3269 [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)) {
Neil Horman7bcbc782008-01-30 13:31:26 +010035 printk(KERN_INFO "Detected use of extended apic ids "
36 "on hypertransport bus\n");
Neil Hormanc6b48322008-01-30 13:31:25 +010037 if ((htcfg & (1 << 17)) == 0) {
Neil Horman7bcbc782008-01-30 13:31:26 +010038 printk(KERN_INFO "Enabling hypertransport extended "
39 "apic interrupt broadcast\n");
40 printk(KERN_INFO "Note this is a bios bug, "
41 "please contact your hw vendor\n");
Neil Hormanc6b48322008-01-30 13:31:25 +010042 htcfg |= (1 << 17);
43 write_pci_config(num, slot, func, 0x68, htcfg);
44 }
45 }
46
47
48}
49
50static void __init via_bugs(int num, int slot, int func)
Andi Kleendfa46982006-09-26 10:52:30 +020051{
Joerg Roedel966396d2007-10-24 12:49:48 +020052#ifdef CONFIG_GART_IOMMU
Yinghai Luc987d122008-06-24 22:14:09 -070053 if ((max_pfn > MAX_DMA32_PFN || force_iommu) &&
Joerg Roedel0440d4c2007-10-24 12:49:50 +020054 !gart_iommu_aperture_allowed) {
Andi Kleendfa46982006-09-26 10:52:30 +020055 printk(KERN_INFO
Andi Kleen54ef3402007-10-19 20:35:03 +020056 "Looks like a VIA chipset. Disabling IOMMU."
57 " Override with iommu=allowed\n");
Joerg Roedel0440d4c2007-10-24 12:49:50 +020058 gart_iommu_aperture_disabled = 1;
Andi Kleendfa46982006-09-26 10:52:30 +020059 }
60#endif
61}
62
63#ifdef CONFIG_ACPI
Jeff Garzik03d0d202007-10-27 20:57:43 +020064#ifdef CONFIG_X86_IO_APIC
Andi Kleendfa46982006-09-26 10:52:30 +020065
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +030066static int __init nvidia_hpet_check(struct acpi_table_header *header)
Andi Kleendfa46982006-09-26 10:52:30 +020067{
Andi Kleendfa46982006-09-26 10:52:30 +020068 return 0;
69}
Jeff Garzik03d0d202007-10-27 20:57:43 +020070#endif /* CONFIG_X86_IO_APIC */
71#endif /* CONFIG_ACPI */
Andi Kleendfa46982006-09-26 10:52:30 +020072
Neil Hormanc6b48322008-01-30 13:31:25 +010073static void __init nvidia_bugs(int num, int slot, int func)
Andi Kleendfa46982006-09-26 10:52:30 +020074{
75#ifdef CONFIG_ACPI
Andi Kleen54ef3402007-10-19 20:35:03 +020076#ifdef CONFIG_X86_IO_APIC
Andi Kleendfa46982006-09-26 10:52:30 +020077 /*
78 * All timer overrides on Nvidia are
79 * wrong unless HPET is enabled.
Andi Kleenfa18f472006-11-14 16:57:46 +010080 * Unfortunately that's not true on many Asus boards.
81 * We don't know yet how to detect this automatically, but
82 * at least allow a command line override.
Andi Kleendfa46982006-09-26 10:52:30 +020083 */
Andi Kleenfa18f472006-11-14 16:57:46 +010084 if (acpi_use_timer_override)
85 return;
86
Len Brownfe699332007-03-08 18:28:32 -050087 if (acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check)) {
Andi Kleendfa46982006-09-26 10:52:30 +020088 acpi_skip_timer_override = 1;
89 printk(KERN_INFO "Nvidia board "
90 "detected. Ignoring ACPI "
91 "timer override.\n");
Andi Kleenfa18f472006-11-14 16:57:46 +010092 printk(KERN_INFO "If you got timer trouble "
93 "try acpi_use_timer_override\n");
Andi Kleendfa46982006-09-26 10:52:30 +020094 }
95#endif
Andi Kleen54ef3402007-10-19 20:35:03 +020096#endif
Andi Kleendfa46982006-09-26 10:52:30 +020097 /* RED-PEN skip them on mptables too? */
98
99}
100
Neil Hormanc6b48322008-01-30 13:31:25 +0100101#define QFLAG_APPLY_ONCE 0x1
102#define QFLAG_APPLIED 0x2
103#define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
Andi Kleendfa46982006-09-26 10:52:30 +0200104struct chipset {
Neil Hormanc6b48322008-01-30 13:31:25 +0100105 u32 vendor;
106 u32 device;
107 u32 class;
108 u32 class_mask;
109 u32 flags;
110 void (*f)(int num, int slot, int func);
Andi Kleendfa46982006-09-26 10:52:30 +0200111};
112
Andrew Mortonc993c732007-04-08 16:04:03 -0700113static struct chipset early_qrk[] __initdata = {
Neil Hormanc6b48322008-01-30 13:31:25 +0100114 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
115 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs },
116 { PCI_VENDOR_ID_VIA, PCI_ANY_ID,
117 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs },
Neil Hormanc6b48322008-01-30 13:31:25 +0100118 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
119 PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config },
Andi Kleendfa46982006-09-26 10:52:30 +0200120 {}
121};
122
Jesse Barnes15650a22008-06-16 15:29:45 -0700123/**
124 * check_dev_quirk - apply early quirks to a given PCI device
125 * @num: bus number
126 * @slot: slot number
127 * @func: PCI function
128 *
129 * Check the vendor & device ID against the early quirks table.
130 *
131 * If the device is single function, let early_quirks() know so we don't
132 * poke at this device again.
133 */
134static int __init check_dev_quirk(int num, int slot, int func)
Neil Horman7bcbc782008-01-30 13:31:26 +0100135{
136 u16 class;
137 u16 vendor;
138 u16 device;
139 u8 type;
140 int i;
141
142 class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE);
143
144 if (class == 0xffff)
Jesse Barnes15650a22008-06-16 15:29:45 -0700145 return -1; /* no class, treat as single function */
Neil Horman7bcbc782008-01-30 13:31:26 +0100146
147 vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID);
148
149 device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
150
151 for (i = 0; early_qrk[i].f != NULL; i++) {
152 if (((early_qrk[i].vendor == PCI_ANY_ID) ||
153 (early_qrk[i].vendor == vendor)) &&
154 ((early_qrk[i].device == PCI_ANY_ID) ||
155 (early_qrk[i].device == device)) &&
156 (!((early_qrk[i].class ^ class) &
157 early_qrk[i].class_mask))) {
158 if ((early_qrk[i].flags &
159 QFLAG_DONE) != QFLAG_DONE)
160 early_qrk[i].f(num, slot, func);
161 early_qrk[i].flags |= QFLAG_APPLIED;
162 }
163 }
164
165 type = read_pci_config_byte(num, slot, func,
166 PCI_HEADER_TYPE);
167 if (!(type & 0x80))
Jesse Barnes15650a22008-06-16 15:29:45 -0700168 return -1;
169
170 return 0;
Neil Horman7bcbc782008-01-30 13:31:26 +0100171}
172
Andi Kleendfa46982006-09-26 10:52:30 +0200173void __init early_quirks(void)
174{
175 int num, slot, func;
Andi Kleen0637a702006-09-26 10:52:41 +0200176
177 if (!early_pci_allowed())
178 return;
179
Andi Kleendfa46982006-09-26 10:52:30 +0200180 /* Poor man's PCI discovery */
Neil Horman7bcbc782008-01-30 13:31:26 +0100181 for (num = 0; num < 32; num++)
182 for (slot = 0; slot < 32; slot++)
Jesse Barnes15650a22008-06-16 15:29:45 -0700183 for (func = 0; func < 8; func++) {
184 /* Only probe function 0 on single fn devices */
185 if (check_dev_quirk(num, slot, func))
186 break;
187 }
Andi Kleendfa46982006-09-26 10:52:30 +0200188}