quirks.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x3a16, /* ICH10 */
  149. ich_force_enable_hpet);
  150. static struct pci_dev *cached_dev;
  151. static void hpet_print_force_info(void)
  152. {
  153. printk(KERN_INFO "HPET not enabled in BIOS. "
  154. "You might try hpet=force boot option\n");
  155. }
  156. static void old_ich_force_hpet_resume(void)
  157. {
  158. u32 val;
  159. u32 uninitialized_var(gen_cntl);
  160. if (!force_hpet_address || !cached_dev)
  161. return;
  162. pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
  163. gen_cntl &= (~(0x7 << 15));
  164. gen_cntl |= (0x4 << 15);
  165. pci_write_config_dword(cached_dev, 0xD0, gen_cntl);
  166. pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
  167. val = gen_cntl >> 15;
  168. val &= 0x7;
  169. if (val == 0x4)
  170. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  171. else
  172. BUG();
  173. }
  174. static void old_ich_force_enable_hpet(struct pci_dev *dev)
  175. {
  176. u32 val;
  177. u32 uninitialized_var(gen_cntl);
  178. if (hpet_address || force_hpet_address)
  179. return;
  180. pci_read_config_dword(dev, 0xD0, &gen_cntl);
  181. /*
  182. * Bit 17 is HPET enable bit.
  183. * Bit 16:15 control the HPET base address.
  184. */
  185. val = gen_cntl >> 15;
  186. val &= 0x7;
  187. if (val & 0x4) {
  188. val &= 0x3;
  189. force_hpet_address = 0xFED00000 | (val << 12);
  190. dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
  191. force_hpet_address);
  192. return;
  193. }
  194. /*
  195. * HPET is disabled. Trying enabling at FED00000 and check
  196. * whether it sticks
  197. */
  198. gen_cntl &= (~(0x7 << 15));
  199. gen_cntl |= (0x4 << 15);
  200. pci_write_config_dword(dev, 0xD0, gen_cntl);
  201. pci_read_config_dword(dev, 0xD0, &gen_cntl);
  202. val = gen_cntl >> 15;
  203. val &= 0x7;
  204. if (val & 0x4) {
  205. /* HPET is enabled in HPTC. Just not reported by BIOS */
  206. val &= 0x3;
  207. force_hpet_address = 0xFED00000 | (val << 12);
  208. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
  209. "0x%lx\n", force_hpet_address);
  210. cached_dev = dev;
  211. force_hpet_resume_type = OLD_ICH_FORCE_HPET_RESUME;
  212. return;
  213. }
  214. dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
  215. }
  216. /*
  217. * Undocumented chipset features. Make sure that the user enforced
  218. * this.
  219. */
  220. static void old_ich_force_enable_hpet_user(struct pci_dev *dev)
  221. {
  222. if (hpet_force_user)
  223. old_ich_force_enable_hpet(dev);
  224. else
  225. hpet_print_force_info();
  226. }
  227. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1,
  228. old_ich_force_enable_hpet_user);
  229. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
  230. old_ich_force_enable_hpet_user);
  231. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12,
  232. old_ich_force_enable_hpet_user);
  233. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
  234. old_ich_force_enable_hpet_user);
  235. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12,
  236. old_ich_force_enable_hpet_user);
  237. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
  238. old_ich_force_enable_hpet);
  239. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_12,
  240. old_ich_force_enable_hpet);
  241. static void vt8237_force_hpet_resume(void)
  242. {
  243. u32 val;
  244. if (!force_hpet_address || !cached_dev)
  245. return;
  246. val = 0xfed00000 | 0x80;
  247. pci_write_config_dword(cached_dev, 0x68, val);
  248. pci_read_config_dword(cached_dev, 0x68, &val);
  249. if (val & 0x80)
  250. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  251. else
  252. BUG();
  253. }
  254. static void vt8237_force_enable_hpet(struct pci_dev *dev)
  255. {
  256. u32 uninitialized_var(val);
  257. if (hpet_address || force_hpet_address)
  258. return;
  259. if (!hpet_force_user) {
  260. hpet_print_force_info();
  261. return;
  262. }
  263. pci_read_config_dword(dev, 0x68, &val);
  264. /*
  265. * Bit 7 is HPET enable bit.
  266. * Bit 31:10 is HPET base address (contrary to what datasheet claims)
  267. */
  268. if (val & 0x80) {
  269. force_hpet_address = (val & ~0x3ff);
  270. dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
  271. force_hpet_address);
  272. return;
  273. }
  274. /*
  275. * HPET is disabled. Trying enabling at FED00000 and check
  276. * whether it sticks
  277. */
  278. val = 0xfed00000 | 0x80;
  279. pci_write_config_dword(dev, 0x68, val);
  280. pci_read_config_dword(dev, 0x68, &val);
  281. if (val & 0x80) {
  282. force_hpet_address = (val & ~0x3ff);
  283. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
  284. "0x%lx\n", force_hpet_address);
  285. cached_dev = dev;
  286. force_hpet_resume_type = VT8237_FORCE_HPET_RESUME;
  287. return;
  288. }
  289. dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
  290. }
  291. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235,
  292. vt8237_force_enable_hpet);
  293. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237,
  294. vt8237_force_enable_hpet);
  295. static void ati_force_hpet_resume(void)
  296. {
  297. pci_write_config_dword(cached_dev, 0x14, 0xfed00000);
  298. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  299. }
  300. static u32 ati_ixp4x0_rev(struct pci_dev *dev)
  301. {
  302. u32 d;
  303. u8 b;
  304. pci_read_config_byte(dev, 0xac, &b);
  305. b &= ~(1<<5);
  306. pci_write_config_byte(dev, 0xac, b);
  307. pci_read_config_dword(dev, 0x70, &d);
  308. d |= 1<<8;
  309. pci_write_config_dword(dev, 0x70, d);
  310. pci_read_config_dword(dev, 0x8, &d);
  311. d &= 0xff;
  312. dev_printk(KERN_DEBUG, &dev->dev, "SB4X0 revision 0x%x\n", d);
  313. return d;
  314. }
  315. static void ati_force_enable_hpet(struct pci_dev *dev)
  316. {
  317. u32 d, val;
  318. u8 b;
  319. if (hpet_address || force_hpet_address)
  320. return;
  321. if (!hpet_force_user) {
  322. hpet_print_force_info();
  323. return;
  324. }
  325. d = ati_ixp4x0_rev(dev);
  326. if (d < 0x82)
  327. return;
  328. /* base address */
  329. pci_write_config_dword(dev, 0x14, 0xfed00000);
  330. pci_read_config_dword(dev, 0x14, &val);
  331. /* enable interrupt */
  332. outb(0x72, 0xcd6); b = inb(0xcd7);
  333. b |= 0x1;
  334. outb(0x72, 0xcd6); outb(b, 0xcd7);
  335. outb(0x72, 0xcd6); b = inb(0xcd7);
  336. if (!(b & 0x1))
  337. return;
  338. pci_read_config_dword(dev, 0x64, &d);
  339. d |= (1<<10);
  340. pci_write_config_dword(dev, 0x64, d);
  341. pci_read_config_dword(dev, 0x64, &d);
  342. if (!(d & (1<<10)))
  343. return;
  344. force_hpet_address = val;
  345. force_hpet_resume_type = ATI_FORCE_HPET_RESUME;
  346. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at 0x%lx\n",
  347. force_hpet_address);
  348. cached_dev = dev;
  349. }
  350. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
  351. ati_force_enable_hpet);
  352. /*
  353. * Undocumented chipset feature taken from LinuxBIOS.
  354. */
  355. static void nvidia_force_hpet_resume(void)
  356. {
  357. pci_write_config_dword(cached_dev, 0x44, 0xfed00001);
  358. printk(KERN_DEBUG "Force enabled HPET at resume\n");
  359. }
  360. static void nvidia_force_enable_hpet(struct pci_dev *dev)
  361. {
  362. u32 uninitialized_var(val);
  363. if (hpet_address || force_hpet_address)
  364. return;
  365. if (!hpet_force_user) {
  366. hpet_print_force_info();
  367. return;
  368. }
  369. pci_write_config_dword(dev, 0x44, 0xfed00001);
  370. pci_read_config_dword(dev, 0x44, &val);
  371. force_hpet_address = val & 0xfffffffe;
  372. force_hpet_resume_type = NVIDIA_FORCE_HPET_RESUME;
  373. dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at 0x%lx\n",
  374. force_hpet_address);
  375. cached_dev = dev;
  376. return;
  377. }
  378. /* ISA Bridges */
  379. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0050,
  380. nvidia_force_enable_hpet);
  381. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0051,
  382. nvidia_force_enable_hpet);
  383. /* LPC bridges */
  384. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0260,
  385. nvidia_force_enable_hpet);
  386. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0360,
  387. nvidia_force_enable_hpet);
  388. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0361,
  389. nvidia_force_enable_hpet);
  390. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0362,
  391. nvidia_force_enable_hpet);
  392. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0363,
  393. nvidia_force_enable_hpet);
  394. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0364,
  395. nvidia_force_enable_hpet);
  396. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0365,
  397. nvidia_force_enable_hpet);
  398. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0366,
  399. nvidia_force_enable_hpet);
  400. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0367,
  401. nvidia_force_enable_hpet);
  402. void force_hpet_resume(void)
  403. {
  404. switch (force_hpet_resume_type) {
  405. case ICH_FORCE_HPET_RESUME:
  406. ich_force_hpet_resume();
  407. return;
  408. case OLD_ICH_FORCE_HPET_RESUME:
  409. old_ich_force_hpet_resume();
  410. return;
  411. case VT8237_FORCE_HPET_RESUME:
  412. vt8237_force_hpet_resume();
  413. return;
  414. case NVIDIA_FORCE_HPET_RESUME:
  415. nvidia_force_hpet_resume();
  416. return;
  417. case ATI_FORCE_HPET_RESUME:
  418. ati_force_hpet_resume();
  419. return;
  420. default:
  421. break;
  422. }
  423. }
  424. #endif