early-quirks.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #ifdef CONFIG_DMAR
  88. static void __init intel_g33_dmar(int num, int slot, int func)
  89. {
  90. struct acpi_table_header *dmar_tbl;
  91. acpi_status status;
  92. status = acpi_get_table(ACPI_SIG_DMAR, 0, &dmar_tbl);
  93. if (ACPI_SUCCESS(status)) {
  94. printk(KERN_INFO "BIOS BUG: DMAR advertised on Intel G31/G33 chipset -- ignoring\n");
  95. dmar_disabled = 1;
  96. }
  97. }
  98. #endif
  99. #define QFLAG_APPLY_ONCE 0x1
  100. #define QFLAG_APPLIED 0x2
  101. #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
  102. struct chipset {
  103. u32 vendor;
  104. u32 device;
  105. u32 class;
  106. u32 class_mask;
  107. u32 flags;
  108. void (*f)(int num, int slot, int func);
  109. };
  110. static struct chipset early_qrk[] __initdata = {
  111. { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  112. PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs },
  113. { PCI_VENDOR_ID_VIA, PCI_ANY_ID,
  114. PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs },
  115. { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
  116. PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config },
  117. #ifdef CONFIG_DMAR
  118. { PCI_VENDOR_ID_INTEL, 0x29c0,
  119. PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, intel_g33_dmar },
  120. #endif
  121. {}
  122. };
  123. /**
  124. * check_dev_quirk - apply early quirks to a given PCI device
  125. * @num: bus number
  126. * @slot: slot number
  127. * @func: PCI function
  128. *
  129. * Check the vendor & device ID against the early quirks table.
  130. *
  131. * If the device is single function, let early_quirks() know so we don't
  132. * poke at this device again.
  133. */
  134. static int __init check_dev_quirk(int num, int slot, int func)
  135. {
  136. u16 class;
  137. u16 vendor;
  138. u16 device;
  139. u8 type;
  140. int i;
  141. class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE);
  142. if (class == 0xffff)
  143. return -1; /* no class, treat as single function */
  144. vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID);
  145. device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
  146. for (i = 0; early_qrk[i].f != NULL; i++) {
  147. if (((early_qrk[i].vendor == PCI_ANY_ID) ||
  148. (early_qrk[i].vendor == vendor)) &&
  149. ((early_qrk[i].device == PCI_ANY_ID) ||
  150. (early_qrk[i].device == device)) &&
  151. (!((early_qrk[i].class ^ class) &
  152. early_qrk[i].class_mask))) {
  153. if ((early_qrk[i].flags &
  154. QFLAG_DONE) != QFLAG_DONE)
  155. early_qrk[i].f(num, slot, func);
  156. early_qrk[i].flags |= QFLAG_APPLIED;
  157. }
  158. }
  159. type = read_pci_config_byte(num, slot, func,
  160. PCI_HEADER_TYPE);
  161. if (!(type & 0x80))
  162. return -1;
  163. return 0;
  164. }
  165. void __init early_quirks(void)
  166. {
  167. int num, slot, func;
  168. if (!early_pci_allowed())
  169. return;
  170. /* Poor man's PCI discovery */
  171. for (num = 0; num < 32; num++)
  172. for (slot = 0; slot < 32; slot++)
  173. for (func = 0; func < 8; func++) {
  174. /* Only probe function 0 on single fn devices */
  175. if (check_dev_quirk(num, slot, func))
  176. break;
  177. }
  178. }