early-quirks.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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 <drm/i915_drm.h>
  15. #include <asm/pci-direct.h>
  16. #include <asm/dma.h>
  17. #include <asm/io_apic.h>
  18. #include <asm/apic.h>
  19. #include <asm/hpet.h>
  20. #include <asm/iommu.h>
  21. #include <asm/gart.h>
  22. #include <asm/irq_remapping.h>
  23. static void __init fix_hypertransport_config(int num, int slot, int func)
  24. {
  25. u32 htcfg;
  26. /*
  27. * we found a hypertransport bus
  28. * make sure that we are broadcasting
  29. * interrupts to all cpus on the ht bus
  30. * if we're using extended apic ids
  31. */
  32. htcfg = read_pci_config(num, slot, func, 0x68);
  33. if (htcfg & (1 << 18)) {
  34. printk(KERN_INFO "Detected use of extended apic ids "
  35. "on hypertransport bus\n");
  36. if ((htcfg & (1 << 17)) == 0) {
  37. printk(KERN_INFO "Enabling hypertransport extended "
  38. "apic interrupt broadcast\n");
  39. printk(KERN_INFO "Note this is a bios bug, "
  40. "please contact your hw vendor\n");
  41. htcfg |= (1 << 17);
  42. write_pci_config(num, slot, func, 0x68, htcfg);
  43. }
  44. }
  45. }
  46. static void __init via_bugs(int num, int slot, int func)
  47. {
  48. #ifdef CONFIG_GART_IOMMU
  49. if ((max_pfn > MAX_DMA32_PFN || force_iommu) &&
  50. !gart_iommu_aperture_allowed) {
  51. printk(KERN_INFO
  52. "Looks like a VIA chipset. Disabling IOMMU."
  53. " Override with iommu=allowed\n");
  54. gart_iommu_aperture_disabled = 1;
  55. }
  56. #endif
  57. }
  58. #ifdef CONFIG_ACPI
  59. #ifdef CONFIG_X86_IO_APIC
  60. static int __init nvidia_hpet_check(struct acpi_table_header *header)
  61. {
  62. return 0;
  63. }
  64. #endif /* CONFIG_X86_IO_APIC */
  65. #endif /* CONFIG_ACPI */
  66. static void __init nvidia_bugs(int num, int slot, int func)
  67. {
  68. #ifdef CONFIG_ACPI
  69. #ifdef CONFIG_X86_IO_APIC
  70. /*
  71. * All timer overrides on Nvidia are
  72. * wrong unless HPET is enabled.
  73. * Unfortunately that's not true on many Asus boards.
  74. * We don't know yet how to detect this automatically, but
  75. * at least allow a command line override.
  76. */
  77. if (acpi_use_timer_override)
  78. return;
  79. if (acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check)) {
  80. acpi_skip_timer_override = 1;
  81. printk(KERN_INFO "Nvidia board "
  82. "detected. Ignoring ACPI "
  83. "timer override.\n");
  84. printk(KERN_INFO "If you got timer trouble "
  85. "try acpi_use_timer_override\n");
  86. }
  87. #endif
  88. #endif
  89. /* RED-PEN skip them on mptables too? */
  90. }
  91. #if defined(CONFIG_ACPI) && defined(CONFIG_X86_IO_APIC)
  92. static u32 __init ati_ixp4x0_rev(int num, int slot, int func)
  93. {
  94. u32 d;
  95. u8 b;
  96. b = read_pci_config_byte(num, slot, func, 0xac);
  97. b &= ~(1<<5);
  98. write_pci_config_byte(num, slot, func, 0xac, b);
  99. d = read_pci_config(num, slot, func, 0x70);
  100. d |= 1<<8;
  101. write_pci_config(num, slot, func, 0x70, d);
  102. d = read_pci_config(num, slot, func, 0x8);
  103. d &= 0xff;
  104. return d;
  105. }
  106. static void __init ati_bugs(int num, int slot, int func)
  107. {
  108. u32 d;
  109. u8 b;
  110. if (acpi_use_timer_override)
  111. return;
  112. d = ati_ixp4x0_rev(num, slot, func);
  113. if (d < 0x82)
  114. acpi_skip_timer_override = 1;
  115. else {
  116. /* check for IRQ0 interrupt swap */
  117. outb(0x72, 0xcd6); b = inb(0xcd7);
  118. if (!(b & 0x2))
  119. acpi_skip_timer_override = 1;
  120. }
  121. if (acpi_skip_timer_override) {
  122. printk(KERN_INFO "SB4X0 revision 0x%x\n", d);
  123. printk(KERN_INFO "Ignoring ACPI timer override.\n");
  124. printk(KERN_INFO "If you got timer trouble "
  125. "try acpi_use_timer_override\n");
  126. }
  127. }
  128. static u32 __init ati_sbx00_rev(int num, int slot, int func)
  129. {
  130. u32 d;
  131. d = read_pci_config(num, slot, func, 0x8);
  132. d &= 0xff;
  133. return d;
  134. }
  135. static void __init ati_bugs_contd(int num, int slot, int func)
  136. {
  137. u32 d, rev;
  138. rev = ati_sbx00_rev(num, slot, func);
  139. if (rev >= 0x40)
  140. acpi_fix_pin2_polarity = 1;
  141. /*
  142. * SB600: revisions 0x11, 0x12, 0x13, 0x14, ...
  143. * SB700: revisions 0x39, 0x3a, ...
  144. * SB800: revisions 0x40, 0x41, ...
  145. */
  146. if (rev >= 0x39)
  147. return;
  148. if (acpi_use_timer_override)
  149. return;
  150. /* check for IRQ0 interrupt swap */
  151. d = read_pci_config(num, slot, func, 0x64);
  152. if (!(d & (1<<14)))
  153. acpi_skip_timer_override = 1;
  154. if (acpi_skip_timer_override) {
  155. printk(KERN_INFO "SB600 revision 0x%x\n", rev);
  156. printk(KERN_INFO "Ignoring ACPI timer override.\n");
  157. printk(KERN_INFO "If you got timer trouble "
  158. "try acpi_use_timer_override\n");
  159. }
  160. }
  161. #else
  162. static void __init ati_bugs(int num, int slot, int func)
  163. {
  164. }
  165. static void __init ati_bugs_contd(int num, int slot, int func)
  166. {
  167. }
  168. #endif
  169. static void __init intel_remapping_check(int num, int slot, int func)
  170. {
  171. u8 revision;
  172. u16 device;
  173. device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
  174. revision = read_pci_config_byte(num, slot, func, PCI_REVISION_ID);
  175. /*
  176. * Revision <= 13 of all triggering devices id in this quirk
  177. * have a problem draining interrupts when irq remapping is
  178. * enabled, and should be flagged as broken. Additionally
  179. * revision 0x22 of device id 0x3405 has this problem.
  180. */
  181. if (revision <= 0x13)
  182. set_irq_remapping_broken();
  183. else if (device == 0x3405 && revision == 0x22)
  184. set_irq_remapping_broken();
  185. }
  186. /*
  187. * Systems with Intel graphics controllers set aside memory exclusively
  188. * for gfx driver use. This memory is not marked in the E820 as reserved
  189. * or as RAM, and so is subject to overlap from E820 manipulation later
  190. * in the boot process. On some systems, MMIO space is allocated on top,
  191. * despite the efforts of the "RAM buffer" approach, which simply rounds
  192. * memory boundaries up to 64M to try to catch space that may decode
  193. * as RAM and so is not suitable for MMIO.
  194. *
  195. * And yes, so far on current devices the base addr is always under 4G.
  196. */
  197. static u32 __init intel_stolen_base(int num, int slot, int func, size_t stolen_size)
  198. {
  199. u32 base;
  200. /*
  201. * For the PCI IDs in this quirk, the stolen base is always
  202. * in 0x5c, aka the BDSM register (yes that's really what
  203. * it's called).
  204. */
  205. base = read_pci_config(num, slot, func, 0x5c);
  206. base &= ~((1<<20) - 1);
  207. return base;
  208. }
  209. #define KB(x) ((x) * 1024UL)
  210. #define MB(x) (KB (KB (x)))
  211. #define GB(x) (MB (KB (x)))
  212. static size_t __init i830_tseg_size(void)
  213. {
  214. u8 tmp = read_pci_config_byte(0, 0, 0, I830_ESMRAMC);
  215. if (!(tmp & TSEG_ENABLE))
  216. return 0;
  217. if (tmp & I830_TSEG_SIZE_1M)
  218. return MB(1);
  219. else
  220. return KB(512);
  221. }
  222. static size_t __init i845_tseg_size(void)
  223. {
  224. u8 tmp = read_pci_config_byte(0, 0, 0, I845_ESMRAMC);
  225. if (!(tmp & TSEG_ENABLE))
  226. return 0;
  227. switch (tmp & I845_TSEG_SIZE_MASK) {
  228. case I845_TSEG_SIZE_512K:
  229. return KB(512);
  230. case I845_TSEG_SIZE_1M:
  231. return MB(1);
  232. default:
  233. WARN_ON(1);
  234. return 0;
  235. }
  236. }
  237. static size_t __init i85x_tseg_size(void)
  238. {
  239. u8 tmp = read_pci_config_byte(0, 0, 0, I85X_ESMRAMC);
  240. if (!(tmp & TSEG_ENABLE))
  241. return 0;
  242. return MB(1);
  243. }
  244. static size_t __init i830_mem_size(void)
  245. {
  246. return read_pci_config_byte(0, 0, 0, I830_DRB3) * MB(32);
  247. }
  248. static size_t __init i85x_mem_size(void)
  249. {
  250. return read_pci_config_byte(0, 0, 1, I85X_DRB3) * MB(32);
  251. }
  252. /*
  253. * On 830/845/85x the stolen memory base isn't available in any
  254. * register. We need to calculate it as TOM-TSEG_SIZE-stolen_size.
  255. */
  256. static u32 __init i830_stolen_base(int num, int slot, int func, size_t stolen_size)
  257. {
  258. return i830_mem_size() - i830_tseg_size() - stolen_size;
  259. }
  260. static u32 __init i845_stolen_base(int num, int slot, int func, size_t stolen_size)
  261. {
  262. return i830_mem_size() - i845_tseg_size() - stolen_size;
  263. }
  264. static u32 __init i85x_stolen_base(int num, int slot, int func, size_t stolen_size)
  265. {
  266. return i85x_mem_size() - i85x_tseg_size() - stolen_size;
  267. }
  268. static u32 __init i865_stolen_base(int num, int slot, int func, size_t stolen_size)
  269. {
  270. /*
  271. * FIXME is the graphics stolen memory region
  272. * always at TOUD? Ie. is it always the last
  273. * one to be allocated by the BIOS?
  274. */
  275. return read_pci_config_16(0, 0, 0, I865_TOUD) << 16;
  276. }
  277. static size_t __init i830_stolen_size(int num, int slot, int func)
  278. {
  279. size_t stolen_size;
  280. u16 gmch_ctrl;
  281. gmch_ctrl = read_pci_config_16(0, 0, 0, I830_GMCH_CTRL);
  282. switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
  283. case I830_GMCH_GMS_STOLEN_512:
  284. stolen_size = KB(512);
  285. break;
  286. case I830_GMCH_GMS_STOLEN_1024:
  287. stolen_size = MB(1);
  288. break;
  289. case I830_GMCH_GMS_STOLEN_8192:
  290. stolen_size = MB(8);
  291. break;
  292. case I830_GMCH_GMS_LOCAL:
  293. /* local memory isn't part of the normal address space */
  294. stolen_size = 0;
  295. break;
  296. default:
  297. return 0;
  298. }
  299. return stolen_size;
  300. }
  301. static size_t __init gen3_stolen_size(int num, int slot, int func)
  302. {
  303. size_t stolen_size;
  304. u16 gmch_ctrl;
  305. gmch_ctrl = read_pci_config_16(0, 0, 0, I830_GMCH_CTRL);
  306. switch (gmch_ctrl & I855_GMCH_GMS_MASK) {
  307. case I855_GMCH_GMS_STOLEN_1M:
  308. stolen_size = MB(1);
  309. break;
  310. case I855_GMCH_GMS_STOLEN_4M:
  311. stolen_size = MB(4);
  312. break;
  313. case I855_GMCH_GMS_STOLEN_8M:
  314. stolen_size = MB(8);
  315. break;
  316. case I855_GMCH_GMS_STOLEN_16M:
  317. stolen_size = MB(16);
  318. break;
  319. case I855_GMCH_GMS_STOLEN_32M:
  320. stolen_size = MB(32);
  321. break;
  322. case I915_GMCH_GMS_STOLEN_48M:
  323. stolen_size = MB(48);
  324. break;
  325. case I915_GMCH_GMS_STOLEN_64M:
  326. stolen_size = MB(64);
  327. break;
  328. case G33_GMCH_GMS_STOLEN_128M:
  329. stolen_size = MB(128);
  330. break;
  331. case G33_GMCH_GMS_STOLEN_256M:
  332. stolen_size = MB(256);
  333. break;
  334. case INTEL_GMCH_GMS_STOLEN_96M:
  335. stolen_size = MB(96);
  336. break;
  337. case INTEL_GMCH_GMS_STOLEN_160M:
  338. stolen_size = MB(160);
  339. break;
  340. case INTEL_GMCH_GMS_STOLEN_224M:
  341. stolen_size = MB(224);
  342. break;
  343. case INTEL_GMCH_GMS_STOLEN_352M:
  344. stolen_size = MB(352);
  345. break;
  346. default:
  347. stolen_size = 0;
  348. break;
  349. }
  350. return stolen_size;
  351. }
  352. static size_t __init gen6_stolen_size(int num, int slot, int func)
  353. {
  354. u16 gmch_ctrl;
  355. gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL);
  356. gmch_ctrl >>= SNB_GMCH_GMS_SHIFT;
  357. gmch_ctrl &= SNB_GMCH_GMS_MASK;
  358. return gmch_ctrl << 25; /* 32 MB units */
  359. }
  360. static size_t __init gen8_stolen_size(int num, int slot, int func)
  361. {
  362. u16 gmch_ctrl;
  363. gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL);
  364. gmch_ctrl >>= BDW_GMCH_GMS_SHIFT;
  365. gmch_ctrl &= BDW_GMCH_GMS_MASK;
  366. return gmch_ctrl << 25; /* 32 MB units */
  367. }
  368. static size_t __init chv_stolen_size(int num, int slot, int func)
  369. {
  370. u16 gmch_ctrl;
  371. gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL);
  372. gmch_ctrl >>= SNB_GMCH_GMS_SHIFT;
  373. gmch_ctrl &= SNB_GMCH_GMS_MASK;
  374. /*
  375. * 0x0 to 0x10: 32MB increments starting at 0MB
  376. * 0x11 to 0x16: 4MB increments starting at 8MB
  377. * 0x17 to 0x1d: 4MB increments start at 36MB
  378. */
  379. if (gmch_ctrl < 0x11)
  380. return gmch_ctrl << 25;
  381. else if (gmch_ctrl < 0x17)
  382. return (gmch_ctrl - 0x11 + 2) << 22;
  383. else
  384. return (gmch_ctrl - 0x17 + 9) << 22;
  385. }
  386. struct intel_stolen_funcs {
  387. size_t (*size)(int num, int slot, int func);
  388. u32 (*base)(int num, int slot, int func, size_t size);
  389. };
  390. static const struct intel_stolen_funcs i830_stolen_funcs __initconst = {
  391. .base = i830_stolen_base,
  392. .size = i830_stolen_size,
  393. };
  394. static const struct intel_stolen_funcs i845_stolen_funcs __initconst = {
  395. .base = i845_stolen_base,
  396. .size = i830_stolen_size,
  397. };
  398. static const struct intel_stolen_funcs i85x_stolen_funcs __initconst = {
  399. .base = i85x_stolen_base,
  400. .size = gen3_stolen_size,
  401. };
  402. static const struct intel_stolen_funcs i865_stolen_funcs __initconst = {
  403. .base = i865_stolen_base,
  404. .size = gen3_stolen_size,
  405. };
  406. static const struct intel_stolen_funcs gen3_stolen_funcs __initconst = {
  407. .base = intel_stolen_base,
  408. .size = gen3_stolen_size,
  409. };
  410. static const struct intel_stolen_funcs gen6_stolen_funcs __initconst = {
  411. .base = intel_stolen_base,
  412. .size = gen6_stolen_size,
  413. };
  414. static const struct intel_stolen_funcs gen8_stolen_funcs __initconst = {
  415. .base = intel_stolen_base,
  416. .size = gen8_stolen_size,
  417. };
  418. static const struct intel_stolen_funcs chv_stolen_funcs __initconst = {
  419. .base = intel_stolen_base,
  420. .size = chv_stolen_size,
  421. };
  422. static const struct pci_device_id intel_stolen_ids[] __initconst = {
  423. INTEL_I830_IDS(&i830_stolen_funcs),
  424. INTEL_I845G_IDS(&i845_stolen_funcs),
  425. INTEL_I85X_IDS(&i85x_stolen_funcs),
  426. INTEL_I865G_IDS(&i865_stolen_funcs),
  427. INTEL_I915G_IDS(&gen3_stolen_funcs),
  428. INTEL_I915GM_IDS(&gen3_stolen_funcs),
  429. INTEL_I945G_IDS(&gen3_stolen_funcs),
  430. INTEL_I945GM_IDS(&gen3_stolen_funcs),
  431. INTEL_VLV_M_IDS(&gen6_stolen_funcs),
  432. INTEL_VLV_D_IDS(&gen6_stolen_funcs),
  433. INTEL_PINEVIEW_IDS(&gen3_stolen_funcs),
  434. INTEL_I965G_IDS(&gen3_stolen_funcs),
  435. INTEL_G33_IDS(&gen3_stolen_funcs),
  436. INTEL_I965GM_IDS(&gen3_stolen_funcs),
  437. INTEL_GM45_IDS(&gen3_stolen_funcs),
  438. INTEL_G45_IDS(&gen3_stolen_funcs),
  439. INTEL_IRONLAKE_D_IDS(&gen3_stolen_funcs),
  440. INTEL_IRONLAKE_M_IDS(&gen3_stolen_funcs),
  441. INTEL_SNB_D_IDS(&gen6_stolen_funcs),
  442. INTEL_SNB_M_IDS(&gen6_stolen_funcs),
  443. INTEL_IVB_M_IDS(&gen6_stolen_funcs),
  444. INTEL_IVB_D_IDS(&gen6_stolen_funcs),
  445. INTEL_HSW_D_IDS(&gen6_stolen_funcs),
  446. INTEL_HSW_M_IDS(&gen6_stolen_funcs),
  447. INTEL_BDW_M_IDS(&gen8_stolen_funcs),
  448. INTEL_BDW_D_IDS(&gen8_stolen_funcs),
  449. INTEL_CHV_IDS(&chv_stolen_funcs),
  450. };
  451. static void __init intel_graphics_stolen(int num, int slot, int func)
  452. {
  453. size_t size;
  454. int i;
  455. u32 start;
  456. u16 device, subvendor, subdevice;
  457. device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
  458. subvendor = read_pci_config_16(num, slot, func,
  459. PCI_SUBSYSTEM_VENDOR_ID);
  460. subdevice = read_pci_config_16(num, slot, func, PCI_SUBSYSTEM_ID);
  461. for (i = 0; i < ARRAY_SIZE(intel_stolen_ids); i++) {
  462. if (intel_stolen_ids[i].device == device) {
  463. const struct intel_stolen_funcs *stolen_funcs =
  464. (const struct intel_stolen_funcs *)intel_stolen_ids[i].driver_data;
  465. size = stolen_funcs->size(num, slot, func);
  466. start = stolen_funcs->base(num, slot, func, size);
  467. if (size && start) {
  468. printk(KERN_INFO "Reserving Intel graphics stolen memory at 0x%x-0x%x\n",
  469. start, start + (u32)size - 1);
  470. /* Mark this space as reserved */
  471. e820_add_region(start, size, E820_RESERVED);
  472. sanitize_e820_map(e820.map,
  473. ARRAY_SIZE(e820.map),
  474. &e820.nr_map);
  475. }
  476. return;
  477. }
  478. }
  479. }
  480. static void __init force_disable_hpet(int num, int slot, int func)
  481. {
  482. #ifdef CONFIG_HPET_TIMER
  483. boot_hpet_disable = 1;
  484. pr_info("x86/hpet: Will disable the HPET for this platform because it's not reliable\n");
  485. #endif
  486. }
  487. #define QFLAG_APPLY_ONCE 0x1
  488. #define QFLAG_APPLIED 0x2
  489. #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
  490. struct chipset {
  491. u32 vendor;
  492. u32 device;
  493. u32 class;
  494. u32 class_mask;
  495. u32 flags;
  496. void (*f)(int num, int slot, int func);
  497. };
  498. /*
  499. * Only works for devices on the root bus. If you add any devices
  500. * not on bus 0 readd another loop level in early_quirks(). But
  501. * be careful because at least the Nvidia quirk here relies on
  502. * only matching on bus 0.
  503. */
  504. static struct chipset early_qrk[] __initdata = {
  505. { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  506. PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs },
  507. { PCI_VENDOR_ID_VIA, PCI_ANY_ID,
  508. PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs },
  509. { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
  510. PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config },
  511. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
  512. PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs },
  513. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  514. PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd },
  515. { PCI_VENDOR_ID_INTEL, 0x3403, PCI_CLASS_BRIDGE_HOST,
  516. PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check },
  517. { PCI_VENDOR_ID_INTEL, 0x3405, PCI_CLASS_BRIDGE_HOST,
  518. PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check },
  519. { PCI_VENDOR_ID_INTEL, 0x3406, PCI_CLASS_BRIDGE_HOST,
  520. PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check },
  521. { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID,
  522. QFLAG_APPLY_ONCE, intel_graphics_stolen },
  523. /*
  524. * HPET on current version of Baytrail platform has accuracy
  525. * problems, disable it for now:
  526. */
  527. { PCI_VENDOR_ID_INTEL, 0x0f00,
  528. PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet},
  529. {}
  530. };
  531. /**
  532. * check_dev_quirk - apply early quirks to a given PCI device
  533. * @num: bus number
  534. * @slot: slot number
  535. * @func: PCI function
  536. *
  537. * Check the vendor & device ID against the early quirks table.
  538. *
  539. * If the device is single function, let early_quirks() know so we don't
  540. * poke at this device again.
  541. */
  542. static int __init check_dev_quirk(int num, int slot, int func)
  543. {
  544. u16 class;
  545. u16 vendor;
  546. u16 device;
  547. u8 type;
  548. int i;
  549. class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE);
  550. if (class == 0xffff)
  551. return -1; /* no class, treat as single function */
  552. vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID);
  553. device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
  554. for (i = 0; early_qrk[i].f != NULL; i++) {
  555. if (((early_qrk[i].vendor == PCI_ANY_ID) ||
  556. (early_qrk[i].vendor == vendor)) &&
  557. ((early_qrk[i].device == PCI_ANY_ID) ||
  558. (early_qrk[i].device == device)) &&
  559. (!((early_qrk[i].class ^ class) &
  560. early_qrk[i].class_mask))) {
  561. if ((early_qrk[i].flags &
  562. QFLAG_DONE) != QFLAG_DONE)
  563. early_qrk[i].f(num, slot, func);
  564. early_qrk[i].flags |= QFLAG_APPLIED;
  565. }
  566. }
  567. type = read_pci_config_byte(num, slot, func,
  568. PCI_HEADER_TYPE);
  569. if (!(type & 0x80))
  570. return -1;
  571. return 0;
  572. }
  573. void __init early_quirks(void)
  574. {
  575. int slot, func;
  576. if (!early_pci_allowed())
  577. return;
  578. /* Poor man's PCI discovery */
  579. /* Only scan the root bus */
  580. for (slot = 0; slot < 32; slot++)
  581. for (func = 0; func < 8; func++) {
  582. /* Only probe function 0 on single fn devices */
  583. if (check_dev_quirk(0, slot, func))
  584. break;
  585. }
  586. }