qemu.c 2.6 KB

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