pci.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <pci.h>
  8. #include <pci_rom.h>
  9. #include <asm/pci.h>
  10. #include <asm/arch/device.h>
  11. #include <asm/arch/qemu.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. void board_pci_setup_hose(struct pci_controller *hose)
  14. {
  15. hose->first_busno = 0;
  16. hose->last_busno = 0;
  17. /* PCI memory space */
  18. pci_set_region(hose->regions + 0,
  19. CONFIG_PCI_MEM_BUS,
  20. CONFIG_PCI_MEM_PHYS,
  21. CONFIG_PCI_MEM_SIZE,
  22. PCI_REGION_MEM);
  23. /* PCI IO space */
  24. pci_set_region(hose->regions + 1,
  25. CONFIG_PCI_IO_BUS,
  26. CONFIG_PCI_IO_PHYS,
  27. CONFIG_PCI_IO_SIZE,
  28. PCI_REGION_IO);
  29. pci_set_region(hose->regions + 2,
  30. CONFIG_PCI_PREF_BUS,
  31. CONFIG_PCI_PREF_PHYS,
  32. CONFIG_PCI_PREF_SIZE,
  33. PCI_REGION_PREFETCH);
  34. pci_set_region(hose->regions + 3,
  35. 0,
  36. 0,
  37. gd->ram_size,
  38. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  39. hose->region_count = 4;
  40. }
  41. int board_pci_post_scan(struct pci_controller *hose)
  42. {
  43. int ret = 0;
  44. ulong start;
  45. pci_dev_t bdf;
  46. struct pci_device_id graphic_card[] = { { 0x1234, 0x1111 } };
  47. u16 device;
  48. int pam, i;
  49. /*
  50. * QEMU emulated graphic card shows in the PCI configuration space with
  51. * PCI vendor id and device id as an artificial pair 0x1234:0x1111.
  52. * It is on PCI bus 0, function 0, but device number is not consistent
  53. * for the two x86 targets it supports. For i440FX and PIIX chipset
  54. * board, it shows as device 2, while for Q35 and ICH9 chipset board,
  55. * it shows as device 1. Here we locate its bdf at run-time based on
  56. * its vendor id and device id pair so we can support both boards.
  57. */
  58. bdf = pci_find_devices(graphic_card, 0);
  59. if (bdf != -1) {
  60. start = get_timer(0);
  61. ret = pci_run_vga_bios(bdf, NULL, PCI_ROM_USE_NATIVE);
  62. debug("BIOS ran in %lums\n", get_timer(start));
  63. }
  64. /*
  65. * i440FX and Q35 chipset have different PAM register offset, but with
  66. * the same bitfield layout. Here we determine the offset based on its
  67. * PCI device ID.
  68. */
  69. device = x86_pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID);
  70. pam = (device == PCI_DEVICE_ID_INTEL_82441) ? I440FX_PAM : Q35_PAM;
  71. /*
  72. * Initialize Programmable Attribute Map (PAM) Registers
  73. *
  74. * Configure legacy segments C/D/E/F to system RAM
  75. */
  76. for (i = 0; i < PAM_NUM; i++)
  77. x86_pci_write_config8(PCI_BDF(0, 0, 0), pam + i, PAM_RW);
  78. if (device == PCI_DEVICE_ID_INTEL_82441) {
  79. /*
  80. * Enable legacy IDE I/O ports decode
  81. *
  82. * Note: QEMU always decode legacy IDE I/O port on PIIX chipset.
  83. * However Linux ata_piix driver does sanity check on these two
  84. * registers to see whether legacy ports decode is turned on.
  85. * This is to make Linux ata_piix driver happy.
  86. */
  87. x86_pci_write_config16(PIIX_IDE, IDE0_TIM, IDE_DECODE_EN);
  88. x86_pci_write_config16(PIIX_IDE, IDE1_TIM, IDE_DECODE_EN);
  89. }
  90. return ret;
  91. }