pci.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. DECLARE_GLOBAL_DATA_PTR;
  10. void board_pci_setup_hose(struct pci_controller *hose)
  11. {
  12. hose->first_busno = 0;
  13. hose->last_busno = 0;
  14. /* PCI memory space */
  15. pci_set_region(hose->regions + 0,
  16. CONFIG_PCI_MEM_BUS,
  17. CONFIG_PCI_MEM_PHYS,
  18. CONFIG_PCI_MEM_SIZE,
  19. PCI_REGION_MEM);
  20. /* PCI IO space */
  21. pci_set_region(hose->regions + 1,
  22. CONFIG_PCI_IO_BUS,
  23. CONFIG_PCI_IO_PHYS,
  24. CONFIG_PCI_IO_SIZE,
  25. PCI_REGION_IO);
  26. pci_set_region(hose->regions + 2,
  27. CONFIG_PCI_PREF_BUS,
  28. CONFIG_PCI_PREF_PHYS,
  29. CONFIG_PCI_PREF_SIZE,
  30. PCI_REGION_PREFETCH);
  31. pci_set_region(hose->regions + 3,
  32. 0,
  33. 0,
  34. gd->ram_size,
  35. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  36. hose->region_count = 4;
  37. }
  38. int board_pci_post_scan(struct pci_controller *hose)
  39. {
  40. int ret = 0;
  41. ulong start;
  42. pci_dev_t bdf;
  43. struct pci_device_id graphic_card[] = { { 0x1234, 0x1111 } };
  44. /*
  45. * QEMU emulated graphic card shows in the PCI configuration space with
  46. * PCI vendor id and device id as an artificial pair 0x1234:0x1111.
  47. * It is on PCI bus 0, function 0, but device number is not consistent
  48. * for the two x86 targets it supports. For i440FX and PIIX chipset
  49. * board, it shows as device 2, while for Q35 and ICH9 chipset board,
  50. * it shows as device 1. Here we locate its bdf at run-time based on
  51. * its vendor id and device id pair so we can support both boards.
  52. */
  53. bdf = pci_find_devices(graphic_card, 0);
  54. if (bdf != -1) {
  55. start = get_timer(0);
  56. ret = pci_run_vga_bios(bdf, NULL, PCI_ROM_USE_NATIVE);
  57. debug("BIOS ran in %lums\n", get_timer(start));
  58. }
  59. return ret;
  60. }