Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 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 |
| 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 Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 16 | #include <asm/dma.h> |
Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 17 | #include <asm/io_apic.h> |
| 18 | #include <asm/apic.h> |
FUJITA Tomonori | 46a7fa2 | 2008-07-11 10:23:42 +0900 | [diff] [blame] | 19 | #include <asm/iommu.h> |
Joerg Roedel | 1d9b16d | 2008-11-27 18:39:15 +0100 | [diff] [blame] | 20 | #include <asm/gart.h> |
Thomas Gleixner | 08be979 | 2010-07-14 21:36:27 +0200 | [diff] [blame] | 21 | #include <asm/hpet.h> |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 22 | |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 23 | static void __init fix_hypertransport_config(int num, int slot, int func) |
| 24 | { |
| 25 | u32 htcfg; |
| 26 | /* |
| 27 | * we found a hypertransport bus |
| 28 | * make sure that we are broadcasting |
| 29 | * interrupts to all cpus on the ht bus |
| 30 | * if we're using extended apic ids |
| 31 | */ |
| 32 | htcfg = read_pci_config(num, slot, func, 0x68); |
| 33 | if (htcfg & (1 << 18)) { |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 34 | printk(KERN_INFO "Detected use of extended apic ids " |
| 35 | "on hypertransport bus\n"); |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 36 | if ((htcfg & (1 << 17)) == 0) { |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 37 | printk(KERN_INFO "Enabling hypertransport extended " |
| 38 | "apic interrupt broadcast\n"); |
| 39 | printk(KERN_INFO "Note this is a bios bug, " |
| 40 | "please contact your hw vendor\n"); |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 41 | htcfg |= (1 << 17); |
| 42 | write_pci_config(num, slot, func, 0x68, htcfg); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | |
| 47 | } |
| 48 | |
| 49 | static void __init via_bugs(int num, int slot, int func) |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 50 | { |
Joerg Roedel | 966396d | 2007-10-24 12:49:48 +0200 | [diff] [blame] | 51 | #ifdef CONFIG_GART_IOMMU |
Yinghai Lu | c987d12 | 2008-06-24 22:14:09 -0700 | [diff] [blame] | 52 | if ((max_pfn > MAX_DMA32_PFN || force_iommu) && |
Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 53 | !gart_iommu_aperture_allowed) { |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 54 | printk(KERN_INFO |
Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 55 | "Looks like a VIA chipset. Disabling IOMMU." |
| 56 | " Override with iommu=allowed\n"); |
Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 57 | gart_iommu_aperture_disabled = 1; |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 58 | } |
| 59 | #endif |
| 60 | } |
| 61 | |
| 62 | #ifdef CONFIG_ACPI |
Jeff Garzik | 03d0d20 | 2007-10-27 20:57:43 +0200 | [diff] [blame] | 63 | #ifdef CONFIG_X86_IO_APIC |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 64 | |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 65 | static int __init nvidia_hpet_check(struct acpi_table_header *header) |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 66 | { |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 67 | return 0; |
| 68 | } |
Jeff Garzik | 03d0d20 | 2007-10-27 20:57:43 +0200 | [diff] [blame] | 69 | #endif /* CONFIG_X86_IO_APIC */ |
| 70 | #endif /* CONFIG_ACPI */ |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 71 | |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 72 | static void __init nvidia_bugs(int num, int slot, int func) |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 73 | { |
| 74 | #ifdef CONFIG_ACPI |
Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 75 | #ifdef CONFIG_X86_IO_APIC |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 76 | /* |
| 77 | * All timer overrides on Nvidia are |
| 78 | * wrong unless HPET is enabled. |
Andi Kleen | fa18f47 | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 79 | * Unfortunately that's not true on many Asus boards. |
| 80 | * We don't know yet how to detect this automatically, but |
| 81 | * at least allow a command line override. |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 82 | */ |
Andi Kleen | fa18f47 | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 83 | if (acpi_use_timer_override) |
| 84 | return; |
| 85 | |
Len Brown | fe69933 | 2007-03-08 18:28:32 -0500 | [diff] [blame] | 86 | if (acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check)) { |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 87 | acpi_skip_timer_override = 1; |
| 88 | printk(KERN_INFO "Nvidia board " |
| 89 | "detected. Ignoring ACPI " |
| 90 | "timer override.\n"); |
Andi Kleen | fa18f47 | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 91 | printk(KERN_INFO "If you got timer trouble " |
| 92 | "try acpi_use_timer_override\n"); |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 93 | } |
| 94 | #endif |
Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 95 | #endif |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 96 | /* RED-PEN skip them on mptables too? */ |
| 97 | |
| 98 | } |
| 99 | |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 100 | #if defined(CONFIG_ACPI) && defined(CONFIG_X86_IO_APIC) |
Ingo Molnar | a59dacf | 2008-10-17 14:38:08 +0200 | [diff] [blame] | 101 | #if defined(CONFIG_ACPI) && defined(CONFIG_X86_IO_APIC) |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 102 | static u32 __init ati_ixp4x0_rev(int num, int slot, int func) |
Andreas Herrmann | 33fb0e4 | 2008-10-07 00:11:22 +0200 | [diff] [blame] | 103 | { |
| 104 | u32 d; |
| 105 | u8 b; |
| 106 | |
| 107 | b = read_pci_config_byte(num, slot, func, 0xac); |
| 108 | b &= ~(1<<5); |
| 109 | write_pci_config_byte(num, slot, func, 0xac, b); |
| 110 | |
| 111 | d = read_pci_config(num, slot, func, 0x70); |
| 112 | d |= 1<<8; |
| 113 | write_pci_config(num, slot, func, 0x70, d); |
| 114 | |
| 115 | d = read_pci_config(num, slot, func, 0x8); |
| 116 | d &= 0xff; |
| 117 | return d; |
| 118 | } |
Ingo Molnar | a59dacf | 2008-10-17 14:38:08 +0200 | [diff] [blame] | 119 | #endif |
Andreas Herrmann | 33fb0e4 | 2008-10-07 00:11:22 +0200 | [diff] [blame] | 120 | |
| 121 | static void __init ati_bugs(int num, int slot, int func) |
| 122 | { |
Andreas Herrmann | 33fb0e4 | 2008-10-07 00:11:22 +0200 | [diff] [blame] | 123 | u32 d; |
| 124 | u8 b; |
| 125 | |
| 126 | if (acpi_use_timer_override) |
| 127 | return; |
| 128 | |
| 129 | d = ati_ixp4x0_rev(num, slot, func); |
| 130 | if (d < 0x82) |
| 131 | acpi_skip_timer_override = 1; |
| 132 | else { |
| 133 | /* check for IRQ0 interrupt swap */ |
| 134 | outb(0x72, 0xcd6); b = inb(0xcd7); |
| 135 | if (!(b & 0x2)) |
| 136 | acpi_skip_timer_override = 1; |
| 137 | } |
| 138 | |
| 139 | if (acpi_skip_timer_override) { |
| 140 | printk(KERN_INFO "SB4X0 revision 0x%x\n", d); |
| 141 | printk(KERN_INFO "Ignoring ACPI timer override.\n"); |
| 142 | printk(KERN_INFO "If you got timer trouble " |
| 143 | "try acpi_use_timer_override\n"); |
| 144 | } |
Andreas Herrmann | 33fb0e4 | 2008-10-07 00:11:22 +0200 | [diff] [blame] | 145 | } |
| 146 | |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 147 | static u32 __init ati_sbx00_rev(int num, int slot, int func) |
| 148 | { |
| 149 | u32 old, d; |
| 150 | |
| 151 | d = read_pci_config(num, slot, func, 0x70); |
| 152 | old = d; |
| 153 | d &= ~(1<<8); |
| 154 | write_pci_config(num, slot, func, 0x70, d); |
| 155 | d = read_pci_config(num, slot, func, 0x8); |
| 156 | d &= 0xff; |
| 157 | write_pci_config(num, slot, func, 0x70, old); |
| 158 | |
| 159 | return d; |
| 160 | } |
| 161 | |
| 162 | static void __init ati_bugs_contd(int num, int slot, int func) |
| 163 | { |
| 164 | u32 d, rev; |
| 165 | |
| 166 | if (acpi_use_timer_override) |
| 167 | return; |
| 168 | |
| 169 | rev = ati_sbx00_rev(num, slot, func); |
| 170 | if (rev > 0x13) |
| 171 | return; |
| 172 | |
| 173 | /* check for IRQ0 interrupt swap */ |
| 174 | d = read_pci_config(num, slot, func, 0x64); |
| 175 | if (!(d & (1<<14))) |
| 176 | acpi_skip_timer_override = 1; |
| 177 | |
| 178 | if (acpi_skip_timer_override) { |
| 179 | printk(KERN_INFO "SB600 revision 0x%x\n", rev); |
| 180 | printk(KERN_INFO "Ignoring ACPI timer override.\n"); |
| 181 | printk(KERN_INFO "If you got timer trouble " |
| 182 | "try acpi_use_timer_override\n"); |
| 183 | } |
| 184 | } |
| 185 | #else |
| 186 | static void __init ati_bugs(int num, int slot, int func) |
| 187 | { |
| 188 | } |
| 189 | |
| 190 | static void __init ati_bugs_contd(int num, int slot, int func) |
| 191 | { |
| 192 | } |
| 193 | #endif |
| 194 | |
Thomas Gleixner | 08be979 | 2010-07-14 21:36:27 +0200 | [diff] [blame] | 195 | /* |
| 196 | * Force the read back of the CMP register in hpet_next_event() |
| 197 | * to work around the problem that the CMP register write seems to be |
| 198 | * delayed. See hpet_next_event() for details. |
| 199 | * |
| 200 | * We do this on all SMBUS incarnations for now until we have more |
| 201 | * information about the affected chipsets. |
| 202 | */ |
| 203 | static void __init ati_hpet_bugs(int num, int slot, int func) |
| 204 | { |
| 205 | #ifdef CONFIG_HPET_TIMER |
| 206 | hpet_readback_cmp = 1; |
| 207 | #endif |
| 208 | } |
| 209 | |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 210 | #define QFLAG_APPLY_ONCE 0x1 |
| 211 | #define QFLAG_APPLIED 0x2 |
| 212 | #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED) |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 213 | struct chipset { |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 214 | u32 vendor; |
| 215 | u32 device; |
| 216 | u32 class; |
| 217 | u32 class_mask; |
| 218 | u32 flags; |
| 219 | void (*f)(int num, int slot, int func); |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 220 | }; |
| 221 | |
Andi Kleen | 8659c40 | 2009-01-09 12:17:39 -0800 | [diff] [blame] | 222 | /* |
| 223 | * Only works for devices on the root bus. If you add any devices |
| 224 | * not on bus 0 readd another loop level in early_quirks(). But |
| 225 | * be careful because at least the Nvidia quirk here relies on |
| 226 | * only matching on bus 0. |
| 227 | */ |
Andrew Morton | c993c73 | 2007-04-08 16:04:03 -0700 | [diff] [blame] | 228 | static struct chipset early_qrk[] __initdata = { |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 229 | { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, |
| 230 | PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs }, |
| 231 | { PCI_VENDOR_ID_VIA, PCI_ANY_ID, |
| 232 | PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs }, |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 233 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB, |
| 234 | PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config }, |
Andreas Herrmann | 33fb0e4 | 2008-10-07 00:11:22 +0200 | [diff] [blame] | 235 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS, |
| 236 | PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs }, |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 237 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS, |
| 238 | PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd }, |
Thomas Gleixner | 08be979 | 2010-07-14 21:36:27 +0200 | [diff] [blame] | 239 | { PCI_VENDOR_ID_ATI, PCI_ANY_ID, |
| 240 | PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_hpet_bugs }, |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 241 | {} |
| 242 | }; |
| 243 | |
Jesse Barnes | 15650a2 | 2008-06-16 15:29:45 -0700 | [diff] [blame] | 244 | /** |
| 245 | * check_dev_quirk - apply early quirks to a given PCI device |
| 246 | * @num: bus number |
| 247 | * @slot: slot number |
| 248 | * @func: PCI function |
| 249 | * |
| 250 | * Check the vendor & device ID against the early quirks table. |
| 251 | * |
| 252 | * If the device is single function, let early_quirks() know so we don't |
| 253 | * poke at this device again. |
| 254 | */ |
| 255 | static int __init check_dev_quirk(int num, int slot, int func) |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 256 | { |
| 257 | u16 class; |
| 258 | u16 vendor; |
| 259 | u16 device; |
| 260 | u8 type; |
| 261 | int i; |
| 262 | |
| 263 | class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE); |
| 264 | |
| 265 | if (class == 0xffff) |
Jesse Barnes | 15650a2 | 2008-06-16 15:29:45 -0700 | [diff] [blame] | 266 | return -1; /* no class, treat as single function */ |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 267 | |
| 268 | vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID); |
| 269 | |
| 270 | device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); |
| 271 | |
| 272 | for (i = 0; early_qrk[i].f != NULL; i++) { |
| 273 | if (((early_qrk[i].vendor == PCI_ANY_ID) || |
| 274 | (early_qrk[i].vendor == vendor)) && |
| 275 | ((early_qrk[i].device == PCI_ANY_ID) || |
| 276 | (early_qrk[i].device == device)) && |
| 277 | (!((early_qrk[i].class ^ class) & |
| 278 | early_qrk[i].class_mask))) { |
| 279 | if ((early_qrk[i].flags & |
| 280 | QFLAG_DONE) != QFLAG_DONE) |
| 281 | early_qrk[i].f(num, slot, func); |
| 282 | early_qrk[i].flags |= QFLAG_APPLIED; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | type = read_pci_config_byte(num, slot, func, |
| 287 | PCI_HEADER_TYPE); |
| 288 | if (!(type & 0x80)) |
Jesse Barnes | 15650a2 | 2008-06-16 15:29:45 -0700 | [diff] [blame] | 289 | return -1; |
| 290 | |
| 291 | return 0; |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 292 | } |
| 293 | |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 294 | void __init early_quirks(void) |
| 295 | { |
Andi Kleen | 8659c40 | 2009-01-09 12:17:39 -0800 | [diff] [blame] | 296 | int slot, func; |
Andi Kleen | 0637a70 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 297 | |
| 298 | if (!early_pci_allowed()) |
| 299 | return; |
| 300 | |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 301 | /* Poor man's PCI discovery */ |
Andi Kleen | 8659c40 | 2009-01-09 12:17:39 -0800 | [diff] [blame] | 302 | /* Only scan the root bus */ |
| 303 | for (slot = 0; slot < 32; slot++) |
| 304 | for (func = 0; func < 8; func++) { |
| 305 | /* Only probe function 0 on single fn devices */ |
| 306 | if (check_dev_quirk(0, slot, func)) |
| 307 | break; |
| 308 | } |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 309 | } |