1 /* 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
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
9 Mainboard specific bugs should be handled by DMI entries.
10 CPU specific bugs in setup.c */
12 #include <linux/pci.h>
13 #include <linux/acpi.h>
14 #include <linux/pci_ids.h>
15 #include <asm/pci-direct.h>
17 #include <asm/io_apic.h>
19 #include <asm/iommu.h>
21 static void __init
fix_hypertransport_config(int num
, int slot
, int func
)
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
30 htcfg
= read_pci_config(num
, slot
, func
, 0x68);
31 if (htcfg
& (1 << 18)) {
32 printk(KERN_INFO
"Detected use of extended apic ids "
33 "on hypertransport bus\n");
34 if ((htcfg
& (1 << 17)) == 0) {
35 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");
40 write_pci_config(num
, slot
, func
, 0x68, htcfg
);
47 static void __init
via_bugs(int num
, int slot
, int func
)
49 #ifdef CONFIG_GART_IOMMU
50 if ((max_pfn
> MAX_DMA32_PFN
|| force_iommu
) &&
51 !gart_iommu_aperture_allowed
) {
53 "Looks like a VIA chipset. Disabling IOMMU."
54 " Override with iommu=allowed\n");
55 gart_iommu_aperture_disabled
= 1;
61 #ifdef CONFIG_X86_IO_APIC
63 static int __init
nvidia_hpet_check(struct acpi_table_header
*header
)
67 #endif /* CONFIG_X86_IO_APIC */
68 #endif /* CONFIG_ACPI */
70 static void __init
nvidia_bugs(int num
, int slot
, int func
)
73 #ifdef CONFIG_X86_IO_APIC
75 * All timer overrides on Nvidia are
76 * wrong unless HPET is enabled.
77 * 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.
81 if (acpi_use_timer_override
)
84 if (acpi_table_parse(ACPI_SIG_HPET
, nvidia_hpet_check
)) {
85 acpi_skip_timer_override
= 1;
86 printk(KERN_INFO
"Nvidia board "
87 "detected. Ignoring ACPI "
89 printk(KERN_INFO
"If you got timer trouble "
90 "try acpi_use_timer_override\n");
94 /* RED-PEN skip them on mptables too? */
98 #if defined(CONFIG_ACPI) && defined(CONFIG_X86_IO_APIC)
99 static u32 __init
ati_ixp4x0_rev(int num
, int slot
, int func
)
104 b
= read_pci_config_byte(num
, slot
, func
, 0xac);
106 write_pci_config_byte(num
, slot
, func
, 0xac, b
);
108 d
= read_pci_config(num
, slot
, func
, 0x70);
110 write_pci_config(num
, slot
, func
, 0x70, d
);
112 d
= read_pci_config(num
, slot
, func
, 0x8);
117 static void __init
ati_bugs(int num
, int slot
, int func
)
122 if (acpi_use_timer_override
)
125 d
= ati_ixp4x0_rev(num
, slot
, func
);
127 acpi_skip_timer_override
= 1;
129 /* check for IRQ0 interrupt swap */
130 outb(0x72, 0xcd6); b
= inb(0xcd7);
132 acpi_skip_timer_override
= 1;
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");
143 static u32 __init
ati_sbx00_rev(int num
, int slot
, int func
)
147 d
= read_pci_config(num
, slot
, func
, 0x70);
150 write_pci_config(num
, slot
, func
, 0x70, d
);
151 d
= read_pci_config(num
, slot
, func
, 0x8);
153 write_pci_config(num
, slot
, func
, 0x70, old
);
158 static void __init
ati_bugs_contd(int num
, int slot
, int func
)
162 if (acpi_use_timer_override
)
165 rev
= ati_sbx00_rev(num
, slot
, func
);
169 /* check for IRQ0 interrupt swap */
170 d
= read_pci_config(num
, slot
, func
, 0x64);
172 acpi_skip_timer_override
= 1;
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");
182 static void __init
ati_bugs(int num
, int slot
, int func
)
186 static void __init
ati_bugs_contd(int num
, int slot
, int func
)
191 #define QFLAG_APPLY_ONCE 0x1
192 #define QFLAG_APPLIED 0x2
193 #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
200 void (*f
)(int num
, int slot
, int func
);
203 static struct chipset early_qrk
[] __initdata
= {
204 { 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
},
208 { PCI_VENDOR_ID_AMD
, PCI_DEVICE_ID_AMD_K8_NB
,
209 PCI_CLASS_BRIDGE_HOST
, PCI_ANY_ID
, 0, fix_hypertransport_config
},
210 { PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_IXP400_SMBUS
,
211 PCI_CLASS_SERIAL_SMBUS
, PCI_ANY_ID
, 0, ati_bugs
},
212 { PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_SBX00_SMBUS
,
213 PCI_CLASS_SERIAL_SMBUS
, PCI_ANY_ID
, 0, ati_bugs_contd
},
218 * check_dev_quirk - apply early quirks to a given PCI device
221 * @func: PCI function
223 * Check the vendor & device ID against the early quirks table.
225 * If the device is single function, let early_quirks() know so we don't
226 * poke at this device again.
228 static int __init
check_dev_quirk(int num
, int slot
, int func
)
236 class = read_pci_config_16(num
, slot
, func
, PCI_CLASS_DEVICE
);
239 return -1; /* no class, treat as single function */
241 vendor
= read_pci_config_16(num
, slot
, func
, PCI_VENDOR_ID
);
243 device
= read_pci_config_16(num
, slot
, func
, PCI_DEVICE_ID
);
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
;
259 type
= read_pci_config_byte(num
, slot
, func
,
267 void __init
early_quirks(void)
271 if (!early_pci_allowed())
274 /* Poor man's PCI discovery */
275 for (num
= 0; num
< 32; num
++)
276 for (slot
= 0; slot
< 32; slot
++)
277 for (func
= 0; func
< 8; func
++) {
278 /* Only probe function 0 on single fn devices */
279 if (check_dev_quirk(num
, slot
, func
))