| 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> | 
 | 19 |  | 
| Joerg Roedel | 966396d | 2007-10-24 12:49:48 +0200 | [diff] [blame] | 20 | #ifdef CONFIG_GART_IOMMU | 
| Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 21 | #include <asm/gart.h> | 
| Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 22 | #endif | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 23 |  | 
| Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 24 | static 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 Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 35 | 		printk(KERN_INFO "Detected use of extended apic ids " | 
 | 36 | 				 "on hypertransport bus\n"); | 
| Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 37 | 		if ((htcfg & (1 << 17)) == 0) { | 
| Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 38 | 			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 Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 42 | 			htcfg |= (1 << 17); | 
 | 43 | 			write_pci_config(num, slot, func, 0x68, htcfg); | 
 | 44 | 		} | 
 | 45 | 	} | 
 | 46 |  | 
 | 47 |  | 
 | 48 | } | 
 | 49 |  | 
 | 50 | static void __init via_bugs(int  num, int slot, int func) | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 51 | { | 
| Joerg Roedel | 966396d | 2007-10-24 12:49:48 +0200 | [diff] [blame] | 52 | #ifdef CONFIG_GART_IOMMU | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 53 | 	if ((end_pfn > MAX_DMA32_PFN ||  force_iommu) && | 
| Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 54 | 	    !gart_iommu_aperture_allowed) { | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 55 | 		printk(KERN_INFO | 
| Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 56 | 		       "Looks like a VIA chipset. Disabling IOMMU." | 
 | 57 | 		       " Override with iommu=allowed\n"); | 
| Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 58 | 		gart_iommu_aperture_disabled = 1; | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 59 | 	} | 
 | 60 | #endif | 
 | 61 | } | 
 | 62 |  | 
 | 63 | #ifdef CONFIG_ACPI | 
| Jeff Garzik | 03d0d20 | 2007-10-27 20:57:43 +0200 | [diff] [blame] | 64 | #ifdef CONFIG_X86_IO_APIC | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 65 |  | 
| Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 66 | static int __init nvidia_hpet_check(struct acpi_table_header *header) | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 67 | { | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 68 | 	return 0; | 
 | 69 | } | 
| Jeff Garzik | 03d0d20 | 2007-10-27 20:57:43 +0200 | [diff] [blame] | 70 | #endif /* CONFIG_X86_IO_APIC */ | 
 | 71 | #endif /* CONFIG_ACPI */ | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 72 |  | 
| Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 73 | static void __init nvidia_bugs(int num, int slot, int func) | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 74 | { | 
 | 75 | #ifdef CONFIG_ACPI | 
| Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 76 | #ifdef CONFIG_X86_IO_APIC | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 77 | 	/* | 
 | 78 | 	 * All timer overrides on Nvidia are | 
 | 79 | 	 * wrong unless HPET is enabled. | 
| Andi Kleen | fa18f47 | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 80 | 	 * 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 Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 83 | 	 */ | 
| Andi Kleen | fa18f47 | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 84 | 	if (acpi_use_timer_override) | 
 | 85 | 		return; | 
 | 86 |  | 
| Len Brown | fe69933 | 2007-03-08 18:28:32 -0500 | [diff] [blame] | 87 | 	if (acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check)) { | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 88 | 		acpi_skip_timer_override = 1; | 
 | 89 | 		printk(KERN_INFO "Nvidia board " | 
 | 90 | 		       "detected. Ignoring ACPI " | 
 | 91 | 		       "timer override.\n"); | 
| Andi Kleen | fa18f47 | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 92 | 		printk(KERN_INFO "If you got timer trouble " | 
 | 93 | 			"try acpi_use_timer_override\n"); | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 94 | 	} | 
 | 95 | #endif | 
| Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 96 | #endif | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 97 | 	/* RED-PEN skip them on mptables too? */ | 
 | 98 |  | 
 | 99 | } | 
 | 100 |  | 
| Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 101 | static void __init ati_bugs(int num, int slot, int func) | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 102 | { | 
| Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 103 | #ifdef CONFIG_X86_IO_APIC | 
| Linus Torvalds | fea5f1e | 2007-01-08 15:04:46 -0800 | [diff] [blame] | 104 | 	if (timer_over_8254 == 1) { | 
 | 105 | 		timer_over_8254 = 0; | 
 | 106 | 		printk(KERN_INFO | 
| Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 107 | 		"ATI board detected. Disabling timer routing over 8254.\n"); | 
| Linus Torvalds | fea5f1e | 2007-01-08 15:04:46 -0800 | [diff] [blame] | 108 | 	} | 
| Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 109 | #endif | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 110 | } | 
 | 111 |  | 
| Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 112 | #define QFLAG_APPLY_ONCE 	0x1 | 
 | 113 | #define QFLAG_APPLIED		0x2 | 
 | 114 | #define QFLAG_DONE		(QFLAG_APPLY_ONCE|QFLAG_APPLIED) | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 115 | struct chipset { | 
| Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 116 | 	u32 vendor; | 
 | 117 | 	u32 device; | 
 | 118 | 	u32 class; | 
 | 119 | 	u32 class_mask; | 
 | 120 | 	u32 flags; | 
 | 121 | 	void (*f)(int num, int slot, int func); | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 122 | }; | 
 | 123 |  | 
| Andrew Morton | c993c73 | 2007-04-08 16:04:03 -0700 | [diff] [blame] | 124 | static struct chipset early_qrk[] __initdata = { | 
| Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 125 | 	{ PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, | 
 | 126 | 	  PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs }, | 
 | 127 | 	{ PCI_VENDOR_ID_VIA, PCI_ANY_ID, | 
 | 128 | 	  PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs }, | 
 | 129 | 	{ PCI_VENDOR_ID_ATI, PCI_ANY_ID, | 
 | 130 | 	  PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, ati_bugs }, | 
 | 131 | 	{ PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB, | 
 | 132 | 	  PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config }, | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 133 | 	{} | 
 | 134 | }; | 
 | 135 |  | 
| Sam Ravnborg | 85b74d6 | 2008-01-30 13:33:37 +0100 | [diff] [blame] | 136 | static void __init check_dev_quirk(int num, int slot, int func) | 
| Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 137 | { | 
 | 138 | 	u16 class; | 
 | 139 | 	u16 vendor; | 
 | 140 | 	u16 device; | 
 | 141 | 	u8 type; | 
 | 142 | 	int i; | 
 | 143 |  | 
 | 144 | 	class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE); | 
 | 145 |  | 
 | 146 | 	if (class == 0xffff) | 
 | 147 | 		return; | 
 | 148 |  | 
 | 149 | 	vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID); | 
 | 150 |  | 
 | 151 | 	device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); | 
 | 152 |  | 
 | 153 | 	for (i = 0; early_qrk[i].f != NULL; i++) { | 
 | 154 | 		if (((early_qrk[i].vendor == PCI_ANY_ID) || | 
 | 155 | 			(early_qrk[i].vendor == vendor)) && | 
 | 156 | 			((early_qrk[i].device == PCI_ANY_ID) || | 
 | 157 | 			(early_qrk[i].device == device)) && | 
 | 158 | 			(!((early_qrk[i].class ^ class) & | 
 | 159 | 			    early_qrk[i].class_mask))) { | 
 | 160 | 				if ((early_qrk[i].flags & | 
 | 161 | 				     QFLAG_DONE) != QFLAG_DONE) | 
 | 162 | 					early_qrk[i].f(num, slot, func); | 
 | 163 | 				early_qrk[i].flags |= QFLAG_APPLIED; | 
 | 164 | 			} | 
 | 165 | 	} | 
 | 166 |  | 
 | 167 | 	type = read_pci_config_byte(num, slot, func, | 
 | 168 | 				    PCI_HEADER_TYPE); | 
 | 169 | 	if (!(type & 0x80)) | 
 | 170 | 		return; | 
 | 171 | } | 
 | 172 |  | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 173 | void __init early_quirks(void) | 
 | 174 | { | 
 | 175 | 	int num, slot, func; | 
| Andi Kleen | 0637a70 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 176 |  | 
 | 177 | 	if (!early_pci_allowed()) | 
 | 178 | 		return; | 
 | 179 |  | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 180 | 	/* Poor man's PCI discovery */ | 
| Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 181 | 	for (num = 0; num < 32; num++) | 
 | 182 | 		for (slot = 0; slot < 32; slot++) | 
 | 183 | 			for (func = 0; func < 8; func++) | 
 | 184 | 				check_dev_quirk(num, slot, func); | 
| Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 185 | } |