quirks.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * This file contains work-arounds for x86 and x86_64 platform bugs.
  3. */
  4. #include <linux/pci.h>
  5. #include <linux/irq.h>
  6. #include <asm/hpet.h>
  7. #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_SMP) && defined(CONFIG_PCI)
  8. static void __devinit quirk_intel_irqbalance(struct pci_dev *dev)
  9. {
  10. u8 config, rev;
  11. u32 word;
  12. /* BIOS may enable hardware IRQ balancing for
  13. * E7520/E7320/E7525(revision ID 0x9 and below)
  14. * based platforms.
  15. * Disable SW irqbalance/affinity on those platforms.
  16. */
  17. pci_read_config_byte(dev, PCI_CLASS_REVISION, &rev);
  18. if (rev > 0x9)
  19. return;
  20. /* enable access to config space*/
  21. pci_read_config_byte(dev, 0xf4, &config);
  22. pci_write_config_byte(dev, 0xf4, config|0x2);
  23. /* read xTPR register */
  24. raw_pci_ops->read(0, 0, 0x40, 0x4c, 2, &word);
  25. if (!(word & (1 << 13))) {
  26. printk(KERN_INFO "Intel E7520/7320/7525 detected. "
  27. "Disabling irq balancing and affinity\n");
  28. #ifdef CONFIG_IRQBALANCE
  29. irqbalance_disable("");
  30. #endif
  31. noirqdebug_setup("");
  32. #ifdef CONFIG_PROC_FS
  33. no_irq_affinity = 1;
  34. #endif
  35. }
  36. /* put back the original value for config space*/
  37. if (!(config & 0x2))
  38. pci_write_config_byte(dev, 0xf4, config);
  39. }
  40. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7320_MCH, quirk_intel_irqbalance);
  41. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7525_MCH, quirk_intel_irqbalance);
  42. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7520_MCH, quirk_intel_irqbalance);
  43. #endif
  44. #if defined(CONFIG_HPET_TIMER)
  45. unsigned long force_hpet_address;
  46. static enum {
  47. NONE_FORCE_HPET_RESUME,
  48. OLD_ICH_FORCE_HPET_RESUME,
  49. ICH_FORCE_HPET_RESUME
  50. } force_hpet_resume_type;
  51. static void __iomem *rcba_base;
  52. static void ich_force_hpet_resume(void)
  53. {
  54. u32 val;
  55. if (!force_hpet_address)
  56. return;
  57. if (rcba_base == NULL)
  58. BUG();
  59. /* read the Function Disable register, dword mode only */
  60. val = readl(rcba_base + 0x3404);
  61. if (!(val & 0x80)) {
  62. /* HPET disabled in HPTC. Trying to enable */
  63. writel(val | 0x80, rcba_base + 0x3404);
  64. }
  65. val = readl(rcba_base + 0x3404);
  66. if (!(val & 0x80))
  67. BUG();
  68. else
  69. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  70. return;
  71. }
  72. static void ich_force_enable_hpet(struct pci_dev *dev)
  73. {
  74. u32 val;
  75. u32 uninitialized_var(rcba);
  76. int err = 0;
  77. if (hpet_address || force_hpet_address)
  78. return;
  79. pci_read_config_dword(dev, 0xF0, &rcba);
  80. rcba &= 0xFFFFC000;
  81. if (rcba == 0) {
  82. printk(KERN_DEBUG "RCBA disabled. Cannot force enable HPET\n");
  83. return;
  84. }
  85. /* use bits 31:14, 16 kB aligned */
  86. rcba_base = ioremap_nocache(rcba, 0x4000);
  87. if (rcba_base == NULL) {
  88. printk(KERN_DEBUG "ioremap failed. Cannot force enable HPET\n");
  89. return;
  90. }
  91. /* read the Function Disable register, dword mode only */
  92. val = readl(rcba_base + 0x3404);
  93. if (val & 0x80) {
  94. /* HPET is enabled in HPTC. Just not reported by BIOS */
  95. val = val & 0x3;
  96. force_hpet_address = 0xFED00000 | (val << 12);
  97. printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
  98. force_hpet_address);
  99. iounmap(rcba_base);
  100. return;
  101. }
  102. /* HPET disabled in HPTC. Trying to enable */
  103. writel(val | 0x80, rcba_base + 0x3404);
  104. val = readl(rcba_base + 0x3404);
  105. if (!(val & 0x80)) {
  106. err = 1;
  107. } else {
  108. val = val & 0x3;
  109. force_hpet_address = 0xFED00000 | (val << 12);
  110. }
  111. if (err) {
  112. force_hpet_address = 0;
  113. iounmap(rcba_base);
  114. printk(KERN_DEBUG "Failed to force enable HPET\n");
  115. } else {
  116. force_hpet_resume_type = ICH_FORCE_HPET_RESUME;
  117. printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
  118. force_hpet_address);
  119. }
  120. }
  121. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0,
  122. ich_force_enable_hpet);
  123. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1,
  124. ich_force_enable_hpet);
  125. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0,
  126. ich_force_enable_hpet);
  127. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1,
  128. ich_force_enable_hpet);
  129. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31,
  130. ich_force_enable_hpet);
  131. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_1,
  132. ich_force_enable_hpet);
  133. static struct pci_dev *cached_dev;
  134. static void old_ich_force_hpet_resume(void)
  135. {
  136. u32 val;
  137. u32 uninitialized_var(gen_cntl);
  138. if (!force_hpet_address || !cached_dev)
  139. return;
  140. pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
  141. gen_cntl &= (~(0x7 << 15));
  142. gen_cntl |= (0x4 << 15);
  143. pci_write_config_dword(cached_dev, 0xD0, gen_cntl);
  144. pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
  145. val = gen_cntl >> 15;
  146. val &= 0x7;
  147. if (val == 0x4)
  148. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  149. else
  150. BUG();
  151. }
  152. static void old_ich_force_enable_hpet(struct pci_dev *dev)
  153. {
  154. u32 val;
  155. u32 uninitialized_var(gen_cntl);
  156. if (hpet_address || force_hpet_address)
  157. return;
  158. pci_read_config_dword(dev, 0xD0, &gen_cntl);
  159. /*
  160. * Bit 17 is HPET enable bit.
  161. * Bit 16:15 control the HPET base address.
  162. */
  163. val = gen_cntl >> 15;
  164. val &= 0x7;
  165. if (val & 0x4) {
  166. val &= 0x3;
  167. force_hpet_address = 0xFED00000 | (val << 12);
  168. printk(KERN_DEBUG "HPET at base address 0x%lx\n",
  169. force_hpet_address);
  170. return;
  171. }
  172. /*
  173. * HPET is disabled. Trying enabling at FED00000 and check
  174. * whether it sticks
  175. */
  176. gen_cntl &= (~(0x7 << 15));
  177. gen_cntl |= (0x4 << 15);
  178. pci_write_config_dword(dev, 0xD0, gen_cntl);
  179. pci_read_config_dword(dev, 0xD0, &gen_cntl);
  180. val = gen_cntl >> 15;
  181. val &= 0x7;
  182. if (val & 0x4) {
  183. /* HPET is enabled in HPTC. Just not reported by BIOS */
  184. val &= 0x3;
  185. force_hpet_address = 0xFED00000 | (val << 12);
  186. printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
  187. force_hpet_address);
  188. cached_dev = dev;
  189. force_hpet_resume_type = OLD_ICH_FORCE_HPET_RESUME;
  190. return;
  191. }
  192. printk(KERN_DEBUG "Failed to force enable HPET\n");
  193. }
  194. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
  195. old_ich_force_enable_hpet);
  196. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_12,
  197. old_ich_force_enable_hpet);
  198. void force_hpet_resume(void)
  199. {
  200. switch (force_hpet_resume_type) {
  201. case ICH_FORCE_HPET_RESUME:
  202. return ich_force_hpet_resume();
  203. case OLD_ICH_FORCE_HPET_RESUME:
  204. return old_ich_force_hpet_resume();
  205. default:
  206. break;
  207. }
  208. }
  209. #endif