early-quirks.c 20 KB

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