quirks.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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. u16 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. /*
  24. * read xTPR register. We may not have a pci_dev for device 8
  25. * because it might be hidden until the above write.
  26. */
  27. pci_bus_read_config_word(dev->bus, PCI_DEVFN(8, 0), 0x4c, &word);
  28. if (!(word & (1 << 13))) {
  29. dev_info(&dev->dev, "Intel E7520/7320/7525 detected; "
  30. "disabling irq balancing and affinity\n");
  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,
  41. quirk_intel_irqbalance);
  42. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7525_MCH,
  43. quirk_intel_irqbalance);
  44. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7520_MCH,
  45. quirk_intel_irqbalance);
  46. #endif
  47. #if defined(CONFIG_HPET_TIMER)
  48. unsigned long force_hpet_address;
  49. static enum {
  50. NONE_FORCE_HPET_RESUME,
  51. OLD_ICH_FORCE_HPET_RESUME,
  52. ICH_FORCE_HPET_RESUME,
  53. VT8237_FORCE_HPET_RESUME,
  54. NVIDIA_FORCE_HPET_RESUME,
  55. ATI_FORCE_HPET_RESUME,
  56. } force_hpet_resume_type;
  57. static void __iomem *rcba_base;
  58. static void ich_force_hpet_resume(void)
  59. {
  60. u32 val;
  61. if (!force_hpet_address)
  62. return;
  63. if (rcba_base == NULL)
  64. BUG();
  65. /* read the Function Disable register, dword mode only */
  66. val = readl(rcba_base + 0x3404);
  67. if (!(val & 0x80)) {
  68. /* HPET disabled in HPTC. Trying to enable */
  69. writel(val | 0x80, rcba_base + 0x3404);
  70. }
  71. val = readl(rcba_base + 0x3404);
  72. if (!(val & 0x80))
  73. BUG();
  74. else
  75. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  76. return;
  77. }
  78. static void ich_force_enable_hpet(struct pci_dev *dev)
  79. {
  80. u32 val;
  81. u32 uninitialized_var(rcba);
  82. int err = 0;
  83. if (hpet_address || force_hpet_address)
  84. return;
  85. pci_read_config_dword(dev, 0xF0, &rcba);
  86. rcba &= 0xFFFFC000;
  87. if (rcba == 0) {
  88. dev_printk(KERN_DEBUG, &dev->dev, "RCBA disabled; "
  89. "cannot force enable HPET\n");
  90. return;
  91. }
  92. /* use bits 31:14, 16 kB aligned */
  93. rcba_base = ioremap_nocache(rcba, 0x4000);
  94. if (rcba_base == NULL) {
  95. dev_printk(KERN_DEBUG, &dev->dev, "ioremap failed; "
  96. "cannot force enable HPET\n");
  97. return;
  98. }
  99. /* read the Function Disable register, dword mode only */
  100. val = readl(rcba_base + 0x3404);
  101. if (val & 0x80) {
  102. /* HPET is enabled in HPTC. Just not reported by BIOS */
  103. val = val & 0x3;
  104. force_hpet_address = 0xFED00000 | (val << 12);
  105. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
  106. "0x%lx\n", force_hpet_address);
  107. iounmap(rcba_base);
  108. return;
  109. }
  110. /* HPET disabled in HPTC. Trying to enable */
  111. writel(val | 0x80, rcba_base + 0x3404);
  112. val = readl(rcba_base + 0x3404);
  113. if (!(val & 0x80)) {
  114. err = 1;
  115. } else {
  116. val = val & 0x3;
  117. force_hpet_address = 0xFED00000 | (val << 12);
  118. }
  119. if (err) {
  120. force_hpet_address = 0;
  121. iounmap(rcba_base);
  122. dev_printk(KERN_DEBUG, &dev->dev,
  123. "Failed to force enable HPET\n");
  124. } else {
  125. force_hpet_resume_type = ICH_FORCE_HPET_RESUME;
  126. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
  127. "0x%lx\n", force_hpet_address);
  128. }
  129. }
  130. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0,
  131. ich_force_enable_hpet);
  132. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0,
  133. ich_force_enable_hpet);
  134. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1,
  135. ich_force_enable_hpet);
  136. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0,
  137. ich_force_enable_hpet);
  138. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1,
  139. ich_force_enable_hpet);
  140. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31,
  141. ich_force_enable_hpet);
  142. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_1,
  143. ich_force_enable_hpet);
  144. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_4,
  145. ich_force_enable_hpet);
  146. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_7,
  147. ich_force_enable_hpet);
  148. static struct pci_dev *cached_dev;
  149. static void hpet_print_force_info(void)
  150. {
  151. printk(KERN_INFO "HPET not enabled in BIOS. "
  152. "You might try hpet=force boot option\n");
  153. }
  154. static void old_ich_force_hpet_resume(void)
  155. {
  156. u32 val;
  157. u32 uninitialized_var(gen_cntl);
  158. if (!force_hpet_address || !cached_dev)
  159. return;
  160. pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
  161. gen_cntl &= (~(0x7 << 15));
  162. gen_cntl |= (0x4 << 15);
  163. pci_write_config_dword(cached_dev, 0xD0, gen_cntl);
  164. pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
  165. val = gen_cntl >> 15;
  166. val &= 0x7;
  167. if (val == 0x4)
  168. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  169. else
  170. BUG();
  171. }
  172. static void old_ich_force_enable_hpet(struct pci_dev *dev)
  173. {
  174. u32 val;
  175. u32 uninitialized_var(gen_cntl);
  176. if (hpet_address || force_hpet_address)
  177. return;
  178. pci_read_config_dword(dev, 0xD0, &gen_cntl);
  179. /*
  180. * Bit 17 is HPET enable bit.
  181. * Bit 16:15 control the HPET base address.
  182. */
  183. val = gen_cntl >> 15;
  184. val &= 0x7;
  185. if (val & 0x4) {
  186. val &= 0x3;
  187. force_hpet_address = 0xFED00000 | (val << 12);
  188. dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
  189. force_hpet_address);
  190. return;
  191. }
  192. /*
  193. * HPET is disabled. Trying enabling at FED00000 and check
  194. * whether it sticks
  195. */
  196. gen_cntl &= (~(0x7 << 15));
  197. gen_cntl |= (0x4 << 15);
  198. pci_write_config_dword(dev, 0xD0, gen_cntl);
  199. pci_read_config_dword(dev, 0xD0, &gen_cntl);
  200. val = gen_cntl >> 15;
  201. val &= 0x7;
  202. if (val & 0x4) {
  203. /* HPET is enabled in HPTC. Just not reported by BIOS */
  204. val &= 0x3;
  205. force_hpet_address = 0xFED00000 | (val << 12);
  206. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
  207. "0x%lx\n", force_hpet_address);
  208. cached_dev = dev;
  209. force_hpet_resume_type = OLD_ICH_FORCE_HPET_RESUME;
  210. return;
  211. }
  212. dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
  213. }
  214. /*
  215. * Undocumented chipset features. Make sure that the user enforced
  216. * this.
  217. */
  218. static void old_ich_force_enable_hpet_user(struct pci_dev *dev)
  219. {
  220. if (hpet_force_user)
  221. old_ich_force_enable_hpet(dev);
  222. else
  223. hpet_print_force_info();
  224. }
  225. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1,
  226. old_ich_force_enable_hpet_user);
  227. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
  228. old_ich_force_enable_hpet_user);
  229. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12,
  230. old_ich_force_enable_hpet_user);
  231. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
  232. old_ich_force_enable_hpet_user);
  233. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12,
  234. old_ich_force_enable_hpet_user);
  235. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
  236. old_ich_force_enable_hpet);
  237. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_12,
  238. old_ich_force_enable_hpet);
  239. static void vt8237_force_hpet_resume(void)
  240. {
  241. u32 val;
  242. if (!force_hpet_address || !cached_dev)
  243. return;
  244. val = 0xfed00000 | 0x80;
  245. pci_write_config_dword(cached_dev, 0x68, val);
  246. pci_read_config_dword(cached_dev, 0x68, &val);
  247. if (val & 0x80)
  248. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  249. else
  250. BUG();
  251. }
  252. static void vt8237_force_enable_hpet(struct pci_dev *dev)
  253. {
  254. u32 uninitialized_var(val);
  255. if (hpet_address || force_hpet_address)
  256. return;
  257. if (!hpet_force_user) {
  258. hpet_print_force_info();
  259. return;
  260. }
  261. pci_read_config_dword(dev, 0x68, &val);
  262. /*
  263. * Bit 7 is HPET enable bit.
  264. * Bit 31:10 is HPET base address (contrary to what datasheet claims)
  265. */
  266. if (val & 0x80) {
  267. force_hpet_address = (val & ~0x3ff);
  268. dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
  269. force_hpet_address);
  270. return;
  271. }
  272. /*
  273. * HPET is disabled. Trying enabling at FED00000 and check
  274. * whether it sticks
  275. */
  276. val = 0xfed00000 | 0x80;
  277. pci_write_config_dword(dev, 0x68, val);
  278. pci_read_config_dword(dev, 0x68, &val);
  279. if (val & 0x80) {
  280. force_hpet_address = (val & ~0x3ff);
  281. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
  282. "0x%lx\n", force_hpet_address);
  283. cached_dev = dev;
  284. force_hpet_resume_type = VT8237_FORCE_HPET_RESUME;
  285. return;
  286. }
  287. dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
  288. }
  289. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235,
  290. vt8237_force_enable_hpet);
  291. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237,
  292. vt8237_force_enable_hpet);
  293. static void ati_force_hpet_resume(void)
  294. {
  295. pci_write_config_dword(cached_dev, 0x14, 0xfed00000);
  296. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  297. }
  298. static u32 ati_ixp4x0_rev(struct pci_dev *dev)
  299. {
  300. u32 d;
  301. u8 b;
  302. pci_read_config_byte(dev, 0xac, &b);
  303. b &= ~(1<<5);
  304. pci_write_config_byte(dev, 0xac, b);
  305. pci_read_config_dword(dev, 0x70, &d);
  306. d |= 1<<8;
  307. pci_write_config_dword(dev, 0x70, d);
  308. pci_read_config_dword(dev, 0x8, &d);
  309. d &= 0xff;
  310. dev_printk(KERN_DEBUG, &dev->dev, "SB4X0 revision 0x%x\n", d);
  311. return d;
  312. }
  313. static void ati_force_enable_hpet(struct pci_dev *dev)
  314. {
  315. u32 d, val;
  316. u8 b;
  317. if (hpet_address || force_hpet_address)
  318. return;
  319. if (!hpet_force_user) {
  320. hpet_print_force_info();
  321. return;
  322. }
  323. d = ati_ixp4x0_rev(dev);
  324. if (d < 0x82)
  325. return;
  326. /* base address */
  327. pci_write_config_dword(dev, 0x14, 0xfed00000);
  328. pci_read_config_dword(dev, 0x14, &val);
  329. /* enable interrupt */
  330. outb(0x72, 0xcd6); b = inb(0xcd7);
  331. b |= 0x1;
  332. outb(0x72, 0xcd6); outb(b, 0xcd7);
  333. outb(0x72, 0xcd6); b = inb(0xcd7);
  334. if (!(b & 0x1))
  335. return;
  336. pci_read_config_dword(dev, 0x64, &d);
  337. d |= (1<<10);
  338. pci_write_config_dword(dev, 0x64, d);
  339. pci_read_config_dword(dev, 0x64, &d);
  340. if (!(d & (1<<10)))
  341. return;
  342. force_hpet_address = val;
  343. force_hpet_resume_type = ATI_FORCE_HPET_RESUME;
  344. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at 0x%lx\n",
  345. force_hpet_address);
  346. cached_dev = dev;
  347. }
  348. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
  349. ati_force_enable_hpet);
  350. /*
  351. * Undocumented chipset feature taken from LinuxBIOS.
  352. */
  353. static void nvidia_force_hpet_resume(void)
  354. {
  355. pci_write_config_dword(cached_dev, 0x44, 0xfed00001);
  356. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  357. }
  358. static void nvidia_force_enable_hpet(struct pci_dev *dev)
  359. {
  360. u32 uninitialized_var(val);
  361. if (hpet_address || force_hpet_address)
  362. return;
  363. if (!hpet_force_user) {
  364. hpet_print_force_info();
  365. return;
  366. }
  367. pci_write_config_dword(dev, 0x44, 0xfed00001);
  368. pci_read_config_dword(dev, 0x44, &val);
  369. force_hpet_address = val & 0xfffffffe;
  370. force_hpet_resume_type = NVIDIA_FORCE_HPET_RESUME;
  371. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at 0x%lx\n",
  372. force_hpet_address);
  373. cached_dev = dev;
  374. return;
  375. }
  376. /* ISA Bridges */
  377. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0050,
  378. nvidia_force_enable_hpet);
  379. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0051,
  380. nvidia_force_enable_hpet);
  381. /* LPC bridges */
  382. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0260,
  383. nvidia_force_enable_hpet);
  384. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0360,
  385. nvidia_force_enable_hpet);
  386. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0361,
  387. nvidia_force_enable_hpet);
  388. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0362,
  389. nvidia_force_enable_hpet);
  390. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0363,
  391. nvidia_force_enable_hpet);
  392. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0364,
  393. nvidia_force_enable_hpet);
  394. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0365,
  395. nvidia_force_enable_hpet);
  396. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0366,
  397. nvidia_force_enable_hpet);
  398. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0367,
  399. nvidia_force_enable_hpet);
  400. void force_hpet_resume(void)
  401. {
  402. switch (force_hpet_resume_type) {
  403. case ICH_FORCE_HPET_RESUME:
  404. ich_force_hpet_resume();
  405. return;
  406. case OLD_ICH_FORCE_HPET_RESUME:
  407. old_ich_force_hpet_resume();
  408. return;
  409. case VT8237_FORCE_HPET_RESUME:
  410. vt8237_force_hpet_resume();
  411. return;
  412. case NVIDIA_FORCE_HPET_RESUME:
  413. nvidia_force_hpet_resume();
  414. return;
  415. case ATI_FORCE_HPET_RESUME:
  416. ati_force_hpet_resume();
  417. return;
  418. default:
  419. break;
  420. }
  421. }
  422. #endif