tnc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <dm/device-internal.h>
  9. #include <pci.h>
  10. #include <asm/io.h>
  11. #include <asm/irq.h>
  12. #include <asm/post.h>
  13. #include <asm/arch/device.h>
  14. #include <asm/arch/tnc.h>
  15. #include <asm/fsp/fsp_support.h>
  16. #include <asm/processor.h>
  17. static int __maybe_unused disable_igd(void)
  18. {
  19. struct udevice *igd, *sdvo;
  20. int ret;
  21. ret = dm_pci_bus_find_bdf(TNC_IGD, &igd);
  22. if (ret)
  23. return ret;
  24. if (!igd)
  25. return 0;
  26. ret = dm_pci_bus_find_bdf(TNC_SDVO, &sdvo);
  27. if (ret)
  28. return ret;
  29. if (!sdvo)
  30. return 0;
  31. /*
  32. * According to Atom E6xx datasheet, setting VGA Disable (bit17)
  33. * of Graphics Controller register (offset 0x50) prevents IGD
  34. * (D2:F0) from reporting itself as a VGA display controller
  35. * class in the PCI configuration space, and should also prevent
  36. * it from responding to VGA legacy memory range and I/O addresses.
  37. *
  38. * However test result shows that with just VGA Disable bit set and
  39. * a PCIe graphics card connected to one of the PCIe controllers on
  40. * the E6xx, accessing the VGA legacy space still causes system hang.
  41. * After a number of attempts, it turns out besides VGA Disable bit,
  42. * the SDVO (D3:F0) device should be disabled to make it work.
  43. *
  44. * To simplify, use the Function Disable register (offset 0xc4)
  45. * to disable both IGD (D2:F0) and SDVO (D3:F0) devices. Now these
  46. * two devices will be completely disabled (invisible in the PCI
  47. * configuration space) unless a system reset is performed.
  48. */
  49. dm_pci_write_config32(igd, IGD_FD, FUNC_DISABLE);
  50. dm_pci_write_config32(sdvo, IGD_FD, FUNC_DISABLE);
  51. /*
  52. * After setting the function disable bit, IGD and SDVO devices will
  53. * disappear in the PCI configuration space. This however creates an
  54. * inconsistent state from a driver model PCI controller point of view,
  55. * as these two PCI devices are still attached to its parent's child
  56. * device list as maintained by the driver model. Some driver model PCI
  57. * APIs like dm_pci_find_class(), are referring to the list to speed up
  58. * the finding process instead of re-enumerating the whole PCI bus, so
  59. * it gets the stale cached data which is wrong.
  60. *
  61. * Note x86 PCI enueration normally happens twice, in pre-relocation
  62. * phase and post-relocation. One option might be to call disable_igd()
  63. * in one of the pre-relocation initialization hooks so that it gets
  64. * disabled in the first round, and when it comes to the second round
  65. * driver model PCI will construct a correct list. Unfortunately this
  66. * does not work as Intel FSP is used on this platform to perform low
  67. * level initialization, and fsp_init_phase_pci() is called only once
  68. * in the post-relocation phase. If we disable IGD and SDVO devices,
  69. * fsp_init_phase_pci() simply hangs and never returns.
  70. *
  71. * So the only option we have is to manually remove these two devices.
  72. */
  73. ret = device_remove(igd);
  74. if (ret)
  75. return ret;
  76. ret = device_unbind(igd);
  77. if (ret)
  78. return ret;
  79. ret = device_remove(sdvo);
  80. if (ret)
  81. return ret;
  82. ret = device_unbind(sdvo);
  83. if (ret)
  84. return ret;
  85. return 0;
  86. }
  87. int arch_cpu_init(void)
  88. {
  89. post_code(POST_CPU_INIT);
  90. return x86_cpu_init_f();
  91. }
  92. int arch_early_init_r(void)
  93. {
  94. int ret = 0;
  95. #ifdef CONFIG_DISABLE_IGD
  96. ret = disable_igd();
  97. #endif
  98. return ret;
  99. }