blob: 1b894b72c0f5df35a1d489def584086ebb2affe5 [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>
FUJITA Tomonori46a7fa22008-07-11 10:23:42 +090019#include <asm/iommu.h>
Andi Kleendfa46982006-09-26 10:52:30 +020020
Neil Hormanc6b48322008-01-30 13:31:25 +010021static void __init fix_hypertransport_config(int num, int slot, int func)
22{
23 u32 htcfg;
24 /*
25 * we found a hypertransport bus
26 * make sure that we are broadcasting
27 * interrupts to all cpus on the ht bus
28 * if we're using extended apic ids
29 */
30 htcfg = read_pci_config(num, slot, func, 0x68);
31 if (htcfg & (1 << 18)) {
Neil Horman7bcbc782008-01-30 13:31:26 +010032 printk(KERN_INFO "Detected use of extended apic ids "
33 "on hypertransport bus\n");
Neil Hormanc6b48322008-01-30 13:31:25 +010034 if ((htcfg & (1 << 17)) == 0) {
Neil Horman7bcbc782008-01-30 13:31:26 +010035 printk(KERN_INFO "Enabling hypertransport extended "
36 "apic interrupt broadcast\n");
37 printk(KERN_INFO "Note this is a bios bug, "
38 "please contact your hw vendor\n");
Neil Hormanc6b48322008-01-30 13:31:25 +010039 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
Yinghai Luc987d122008-06-24 22:14:09 -070050 if ((max_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
Andreas Herrmann26adcfb2008-10-14 21:01:15 +020098#if defined(CONFIG_ACPI) && defined(CONFIG_X86_IO_APIC)
99static u32 __init ati_ixp4x0_rev(int num, int slot, int func)
Andreas Herrmann33fb0e42008-10-07 00:11:22 +0200100{
101 u32 d;
102 u8 b;
103
104 b = read_pci_config_byte(num, slot, func, 0xac);
105 b &= ~(1<<5);
106 write_pci_config_byte(num, slot, func, 0xac, b);
107
108 d = read_pci_config(num, slot, func, 0x70);
109 d |= 1<<8;
110 write_pci_config(num, slot, func, 0x70, d);
111
112 d = read_pci_config(num, slot, func, 0x8);
113 d &= 0xff;
114 return d;
115}
116
117static void __init ati_bugs(int num, int slot, int func)
118{
Andreas Herrmann33fb0e42008-10-07 00:11:22 +0200119 u32 d;
120 u8 b;
121
122 if (acpi_use_timer_override)
123 return;
124
125 d = ati_ixp4x0_rev(num, slot, func);
126 if (d < 0x82)
127 acpi_skip_timer_override = 1;
128 else {
129 /* check for IRQ0 interrupt swap */
130 outb(0x72, 0xcd6); b = inb(0xcd7);
131 if (!(b & 0x2))
132 acpi_skip_timer_override = 1;
133 }
134
135 if (acpi_skip_timer_override) {
136 printk(KERN_INFO "SB4X0 revision 0x%x\n", d);
137 printk(KERN_INFO "Ignoring ACPI timer override.\n");
138 printk(KERN_INFO "If you got timer trouble "
139 "try acpi_use_timer_override\n");
140 }
Andreas Herrmann33fb0e42008-10-07 00:11:22 +0200141}
142
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200143static u32 __init ati_sbx00_rev(int num, int slot, int func)
144{
145 u32 old, d;
146
147 d = read_pci_config(num, slot, func, 0x70);
148 old = d;
149 d &= ~(1<<8);
150 write_pci_config(num, slot, func, 0x70, d);
151 d = read_pci_config(num, slot, func, 0x8);
152 d &= 0xff;
153 write_pci_config(num, slot, func, 0x70, old);
154
155 return d;
156}
157
158static void __init ati_bugs_contd(int num, int slot, int func)
159{
160 u32 d, rev;
161
162 if (acpi_use_timer_override)
163 return;
164
165 rev = ati_sbx00_rev(num, slot, func);
166 if (rev > 0x13)
167 return;
168
169 /* check for IRQ0 interrupt swap */
170 d = read_pci_config(num, slot, func, 0x64);
171 if (!(d & (1<<14)))
172 acpi_skip_timer_override = 1;
173
174 if (acpi_skip_timer_override) {
175 printk(KERN_INFO "SB600 revision 0x%x\n", rev);
176 printk(KERN_INFO "Ignoring ACPI timer override.\n");
177 printk(KERN_INFO "If you got timer trouble "
178 "try acpi_use_timer_override\n");
179 }
180}
181#else
182static void __init ati_bugs(int num, int slot, int func)
183{
184}
185
186static void __init ati_bugs_contd(int num, int slot, int func)
187{
188}
189#endif
190
Neil Hormanc6b48322008-01-30 13:31:25 +0100191#define QFLAG_APPLY_ONCE 0x1
192#define QFLAG_APPLIED 0x2
193#define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
Andi Kleendfa46982006-09-26 10:52:30 +0200194struct chipset {
Neil Hormanc6b48322008-01-30 13:31:25 +0100195 u32 vendor;
196 u32 device;
197 u32 class;
198 u32 class_mask;
199 u32 flags;
200 void (*f)(int num, int slot, int func);
Andi Kleendfa46982006-09-26 10:52:30 +0200201};
202
Andrew Mortonc993c732007-04-08 16:04:03 -0700203static struct chipset early_qrk[] __initdata = {
Neil Hormanc6b48322008-01-30 13:31:25 +0100204 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
205 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs },
206 { PCI_VENDOR_ID_VIA, PCI_ANY_ID,
207 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs },
Neil Hormanc6b48322008-01-30 13:31:25 +0100208 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
209 PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config },
Andreas Herrmann33fb0e42008-10-07 00:11:22 +0200210 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
211 PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs },
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200212 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
213 PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd },
Andi Kleendfa46982006-09-26 10:52:30 +0200214 {}
215};
216
Jesse Barnes15650a22008-06-16 15:29:45 -0700217/**
218 * check_dev_quirk - apply early quirks to a given PCI device
219 * @num: bus number
220 * @slot: slot number
221 * @func: PCI function
222 *
223 * Check the vendor & device ID against the early quirks table.
224 *
225 * If the device is single function, let early_quirks() know so we don't
226 * poke at this device again.
227 */
228static int __init check_dev_quirk(int num, int slot, int func)
Neil Horman7bcbc782008-01-30 13:31:26 +0100229{
230 u16 class;
231 u16 vendor;
232 u16 device;
233 u8 type;
234 int i;
235
236 class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE);
237
238 if (class == 0xffff)
Jesse Barnes15650a22008-06-16 15:29:45 -0700239 return -1; /* no class, treat as single function */
Neil Horman7bcbc782008-01-30 13:31:26 +0100240
241 vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID);
242
243 device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
244
245 for (i = 0; early_qrk[i].f != NULL; i++) {
246 if (((early_qrk[i].vendor == PCI_ANY_ID) ||
247 (early_qrk[i].vendor == vendor)) &&
248 ((early_qrk[i].device == PCI_ANY_ID) ||
249 (early_qrk[i].device == device)) &&
250 (!((early_qrk[i].class ^ class) &
251 early_qrk[i].class_mask))) {
252 if ((early_qrk[i].flags &
253 QFLAG_DONE) != QFLAG_DONE)
254 early_qrk[i].f(num, slot, func);
255 early_qrk[i].flags |= QFLAG_APPLIED;
256 }
257 }
258
259 type = read_pci_config_byte(num, slot, func,
260 PCI_HEADER_TYPE);
261 if (!(type & 0x80))
Jesse Barnes15650a22008-06-16 15:29:45 -0700262 return -1;
263
264 return 0;
Neil Horman7bcbc782008-01-30 13:31:26 +0100265}
266
Andi Kleendfa46982006-09-26 10:52:30 +0200267void __init early_quirks(void)
268{
269 int num, slot, func;
Andi Kleen0637a702006-09-26 10:52:41 +0200270
271 if (!early_pci_allowed())
272 return;
273
Andi Kleendfa46982006-09-26 10:52:30 +0200274 /* Poor man's PCI discovery */
Neil Horman7bcbc782008-01-30 13:31:26 +0100275 for (num = 0; num < 32; num++)
276 for (slot = 0; slot < 32; slot++)
Jesse Barnes15650a22008-06-16 15:29:45 -0700277 for (func = 0; func < 8; func++) {
278 /* Only probe function 0 on single fn devices */
279 if (check_dev_quirk(num, slot, func))
280 break;
281 }
Andi Kleendfa46982006-09-26 10:52:30 +0200282}