qemu.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/irq.h>
  8. #include <asm/pci.h>
  9. #include <asm/post.h>
  10. #include <asm/processor.h>
  11. #include <asm/arch/device.h>
  12. #include <asm/arch/qemu.h>
  13. static bool i440fx;
  14. static void qemu_chipset_init(void)
  15. {
  16. u16 device, xbcs;
  17. int pam, i;
  18. /*
  19. * i440FX and Q35 chipset have different PAM register offset, but with
  20. * the same bitfield layout. Here we determine the offset based on its
  21. * PCI device ID.
  22. */
  23. device = x86_pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID);
  24. i440fx = (device == PCI_DEVICE_ID_INTEL_82441);
  25. pam = i440fx ? I440FX_PAM : Q35_PAM;
  26. /*
  27. * Initialize Programmable Attribute Map (PAM) Registers
  28. *
  29. * Configure legacy segments C/D/E/F to system RAM
  30. */
  31. for (i = 0; i < PAM_NUM; i++)
  32. x86_pci_write_config8(PCI_BDF(0, 0, 0), pam + i, PAM_RW);
  33. if (i440fx) {
  34. /*
  35. * Enable legacy IDE I/O ports decode
  36. *
  37. * Note: QEMU always decode legacy IDE I/O port on PIIX chipset.
  38. * However Linux ata_piix driver does sanity check on these two
  39. * registers to see whether legacy ports decode is turned on.
  40. * This is to make Linux ata_piix driver happy.
  41. */
  42. x86_pci_write_config16(PIIX_IDE, IDE0_TIM, IDE_DECODE_EN);
  43. x86_pci_write_config16(PIIX_IDE, IDE1_TIM, IDE_DECODE_EN);
  44. /* Enable I/O APIC */
  45. xbcs = x86_pci_read_config16(PIIX_ISA, XBCS);
  46. xbcs |= APIC_EN;
  47. x86_pci_write_config16(PIIX_ISA, XBCS, xbcs);
  48. } else {
  49. /* Configure PCIe ECAM base address */
  50. x86_pci_write_config32(PCI_BDF(0, 0, 0), PCIEX_BAR,
  51. CONFIG_PCIE_ECAM_BASE | BAR_EN);
  52. }
  53. }
  54. int arch_cpu_init(void)
  55. {
  56. int ret;
  57. post_code(POST_CPU_INIT);
  58. #ifdef CONFIG_SYS_X86_TSC_TIMER
  59. timer_set_base(rdtsc());
  60. #endif
  61. ret = x86_cpu_init_f();
  62. if (ret)
  63. return ret;
  64. return 0;
  65. }
  66. #ifndef CONFIG_EFI_STUB
  67. int print_cpuinfo(void)
  68. {
  69. post_code(POST_CPU_INFO);
  70. return default_print_cpuinfo();
  71. }
  72. #endif
  73. void reset_cpu(ulong addr)
  74. {
  75. /* cold reset */
  76. x86_full_reset();
  77. }
  78. int arch_early_init_r(void)
  79. {
  80. qemu_chipset_init();
  81. return 0;
  82. }
  83. int arch_misc_init(void)
  84. {
  85. return pirq_init();
  86. }
  87. #ifdef CONFIG_GENERATE_MP_TABLE
  88. int mp_determine_pci_dstirq(int bus, int dev, int func, int pirq)
  89. {
  90. u8 irq;
  91. if (i440fx) {
  92. /*
  93. * Not like most x86 platforms, the PIRQ[A-D] on PIIX3 are not
  94. * connected to I/O APIC INTPIN#16-19. Instead they are routed
  95. * to an irq number controled by the PIRQ routing register.
  96. */
  97. irq = x86_pci_read_config8(PCI_BDF(bus, dev, func),
  98. PCI_INTERRUPT_LINE);
  99. } else {
  100. /*
  101. * ICH9's PIRQ[A-H] are not consecutive numbers from 0 to 7.
  102. * PIRQ[A-D] still maps to [0-3] but PIRQ[E-H] maps to [8-11].
  103. */
  104. irq = pirq < 8 ? pirq + 16 : pirq + 12;
  105. }
  106. return irq;
  107. }
  108. #endif