early-quirks.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. #include <linux/pci.h>
  12. #include <linux/acpi.h>
  13. #include <linux/pci_ids.h>
  14. #include <asm/pci-direct.h>
  15. #include <asm/dma.h>
  16. #include <asm/io_apic.h>
  17. #include <asm/apic.h>
  18. #include <asm/iommu.h>
  19. static void __init fix_hypertransport_config(int num, int slot, int func)
  20. {
  21. u32 htcfg;
  22. /*
  23. * we found a hypertransport bus
  24. * make sure that we are broadcasting
  25. * interrupts to all cpus on the ht bus
  26. * if we're using extended apic ids
  27. */
  28. htcfg = read_pci_config(num, slot, func, 0x68);
  29. if (htcfg & (1 << 18)) {
  30. printk(KERN_INFO "Detected use of extended apic ids "
  31. "on hypertransport bus\n");
  32. if ((htcfg & (1 << 17)) == 0) {
  33. printk(KERN_INFO "Enabling hypertransport extended "
  34. "apic interrupt broadcast\n");
  35. printk(KERN_INFO "Note this is a bios bug, "
  36. "please contact your hw vendor\n");
  37. htcfg |= (1 << 17);
  38. write_pci_config(num, slot, func, 0x68, htcfg);
  39. }
  40. }
  41. }
  42. static void __init via_bugs(int num, int slot, int func)
  43. {
  44. #ifdef CONFIG_GART_IOMMU
  45. if ((max_pfn > MAX_DMA32_PFN || force_iommu) &&
  46. !gart_iommu_aperture_allowed) {
  47. printk(KERN_INFO
  48. "Looks like a VIA chipset. Disabling IOMMU."
  49. " Override with iommu=allowed\n");
  50. gart_iommu_aperture_disabled = 1;
  51. }
  52. #endif
  53. }
  54. #ifdef CONFIG_ACPI
  55. #ifdef CONFIG_X86_IO_APIC
  56. static int __init nvidia_hpet_check(struct acpi_table_header *header)
  57. {
  58. return 0;
  59. }
  60. #endif /* CONFIG_X86_IO_APIC */
  61. #endif /* CONFIG_ACPI */
  62. static void __init nvidia_bugs(int num, int slot, int func)
  63. {
  64. #ifdef CONFIG_ACPI
  65. #ifdef CONFIG_X86_IO_APIC
  66. /*
  67. * All timer overrides on Nvidia are
  68. * wrong unless HPET is enabled.
  69. * Unfortunately that's not true on many Asus boards.
  70. * We don't know yet how to detect this automatically, but
  71. * at least allow a command line override.
  72. */
  73. if (acpi_use_timer_override)
  74. return;
  75. if (acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check)) {
  76. acpi_skip_timer_override = 1;
  77. printk(KERN_INFO "Nvidia board "
  78. "detected. Ignoring ACPI "
  79. "timer override.\n");
  80. printk(KERN_INFO "If you got timer trouble "
  81. "try acpi_use_timer_override\n");
  82. }
  83. #endif
  84. #endif
  85. /* RED-PEN skip them on mptables too? */
  86. }
  87. #if defined(CONFIG_ACPI) && defined(CONFIG_X86_IO_APIC)
  88. static u32 __init ati_ixp4x0_rev(int num, int slot, int func)
  89. {
  90. u32 d;
  91. u8 b;
  92. b = read_pci_config_byte(num, slot, func, 0xac);
  93. b &= ~(1<<5);
  94. write_pci_config_byte(num, slot, func, 0xac, b);
  95. d = read_pci_config(num, slot, func, 0x70);
  96. d |= 1<<8;
  97. write_pci_config(num, slot, func, 0x70, d);
  98. d = read_pci_config(num, slot, func, 0x8);
  99. d &= 0xff;
  100. return d;
  101. }
  102. static void __init ati_bugs(int num, int slot, int func)
  103. {
  104. u32 d;
  105. u8 b;
  106. if (acpi_use_timer_override)
  107. return;
  108. d = ati_ixp4x0_rev(num, slot, func);
  109. if (d < 0x82)
  110. acpi_skip_timer_override = 1;
  111. else {
  112. /* check for IRQ0 interrupt swap */
  113. outb(0x72, 0xcd6); b = inb(0xcd7);
  114. if (!(b & 0x2))
  115. acpi_skip_timer_override = 1;
  116. }
  117. if (acpi_skip_timer_override) {
  118. printk(KERN_INFO "SB4X0 revision 0x%x\n", d);
  119. printk(KERN_INFO "Ignoring ACPI timer override.\n");
  120. printk(KERN_INFO "If you got timer trouble "
  121. "try acpi_use_timer_override\n");
  122. }
  123. }
  124. static u32 __init ati_sbx00_rev(int num, int slot, int func)
  125. {
  126. u32 old, d;
  127. d = read_pci_config(num, slot, func, 0x70);
  128. old = d;
  129. d &= ~(1<<8);
  130. write_pci_config(num, slot, func, 0x70, d);
  131. d = read_pci_config(num, slot, func, 0x8);
  132. d &= 0xff;
  133. write_pci_config(num, slot, func, 0x70, old);
  134. return d;
  135. }
  136. static void __init ati_bugs_contd(int num, int slot, int func)
  137. {
  138. u32 d, rev;
  139. if (acpi_use_timer_override)
  140. return;
  141. rev = ati_sbx00_rev(num, slot, func);
  142. if (rev > 0x13)
  143. return;
  144. /* check for IRQ0 interrupt swap */
  145. d = read_pci_config(num, slot, func, 0x64);
  146. if (!(d & (1<<14)))
  147. acpi_skip_timer_override = 1;
  148. if (acpi_skip_timer_override) {
  149. printk(KERN_INFO "SB600 revision 0x%x\n", rev);
  150. printk(KERN_INFO "Ignoring ACPI timer override.\n");
  151. printk(KERN_INFO "If you got timer trouble "
  152. "try acpi_use_timer_override\n");
  153. }
  154. }
  155. #else
  156. static void __init ati_bugs(int num, int slot, int func)
  157. {
  158. }
  159. static void __init ati_bugs_contd(int num, int slot, int func)
  160. {
  161. }
  162. #endif
  163. #define QFLAG_APPLY_ONCE 0x1
  164. #define QFLAG_APPLIED 0x2
  165. #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
  166. struct chipset {
  167. u32 vendor;
  168. u32 device;
  169. u32 class;
  170. u32 class_mask;
  171. u32 flags;
  172. void (*f)(int num, int slot, int func);
  173. };
  174. static struct chipset early_qrk[] __initdata = {
  175. { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  176. PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs },
  177. { PCI_VENDOR_ID_VIA, PCI_ANY_ID,
  178. PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs },
  179. { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
  180. PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config },
  181. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
  182. PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs },
  183. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  184. PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd },
  185. {}
  186. };
  187. /**
  188. * check_dev_quirk - apply early quirks to a given PCI device
  189. * @num: bus number
  190. * @slot: slot number
  191. * @func: PCI function
  192. *
  193. * Check the vendor & device ID against the early quirks table.
  194. *
  195. * If the device is single function, let early_quirks() know so we don't
  196. * poke at this device again.
  197. */
  198. static int __init check_dev_quirk(int num, int slot, int func)
  199. {
  200. u16 class;
  201. u16 vendor;
  202. u16 device;
  203. u8 type;
  204. int i;
  205. class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE);
  206. if (class == 0xffff)
  207. return -1; /* no class, treat as single function */
  208. vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID);
  209. device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
  210. for (i = 0; early_qrk[i].f != NULL; i++) {
  211. if (((early_qrk[i].vendor == PCI_ANY_ID) ||
  212. (early_qrk[i].vendor == vendor)) &&
  213. ((early_qrk[i].device == PCI_ANY_ID) ||
  214. (early_qrk[i].device == device)) &&
  215. (!((early_qrk[i].class ^ class) &
  216. early_qrk[i].class_mask))) {
  217. if ((early_qrk[i].flags &
  218. QFLAG_DONE) != QFLAG_DONE)
  219. early_qrk[i].f(num, slot, func);
  220. early_qrk[i].flags |= QFLAG_APPLIED;
  221. }
  222. }
  223. type = read_pci_config_byte(num, slot, func,
  224. PCI_HEADER_TYPE);
  225. if (!(type & 0x80))
  226. return -1;
  227. return 0;
  228. }
  229. void __init early_quirks(void)
  230. {
  231. int num, slot, func;
  232. if (!early_pci_allowed())
  233. return;
  234. /* Poor man's PCI discovery */
  235. for (num = 0; num < 32; num++)
  236. for (slot = 0; slot < 32; slot++)
  237. for (func = 0; func < 8; func++) {
  238. /* Only probe function 0 on single fn devices */
  239. if (check_dev_quirk(num, slot, func))
  240. break;
  241. }
  242. }