2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/arch/device.h>
12 #include <asm/arch/qemu.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 void board_pci_setup_hose(struct pci_controller *hose)
18 hose->first_busno = 0;
21 /* PCI memory space */
22 pci_set_region(hose->regions + 0,
29 pci_set_region(hose->regions + 1,
35 pci_set_region(hose->regions + 2,
41 pci_set_region(hose->regions + 3,
45 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
47 hose->region_count = 4;
50 int board_pci_post_scan(struct pci_controller *hose)
55 struct pci_device_id graphic_card[] = { { 0x1234, 0x1111 } };
60 * QEMU emulated graphic card shows in the PCI configuration space with
61 * PCI vendor id and device id as an artificial pair 0x1234:0x1111.
62 * It is on PCI bus 0, function 0, but device number is not consistent
63 * for the two x86 targets it supports. For i440FX and PIIX chipset
64 * board, it shows as device 2, while for Q35 and ICH9 chipset board,
65 * it shows as device 1. Here we locate its bdf at run-time based on
66 * its vendor id and device id pair so we can support both boards.
68 bdf = pci_find_devices(graphic_card, 0);
71 ret = pci_run_vga_bios(bdf, NULL, PCI_ROM_USE_NATIVE);
72 debug("BIOS ran in %lums\n", get_timer(start));
76 * i440FX and Q35 chipset have different PAM register offset, but with
77 * the same bitfield layout. Here we determine the offset based on its
80 device = x86_pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID);
81 pam = (device == PCI_DEVICE_ID_INTEL_82441) ? I440FX_PAM : Q35_PAM;
84 * Initialize Programmable Attribute Map (PAM) Registers
86 * Configure legacy segments C/D/E/F to system RAM
88 for (i = 0; i < PAM_NUM; i++)
89 x86_pci_write_config8(PCI_BDF(0, 0, 0), pam + i, PAM_RW);
91 if (device == PCI_DEVICE_ID_INTEL_82441) {
93 * Enable legacy IDE I/O ports decode
95 * Note: QEMU always decode legacy IDE I/O port on PIIX chipset.
96 * However Linux ata_piix driver does sanity check on these two
97 * registers to see whether legacy ports decode is turned on.
98 * This is to make Linux ata_piix driver happy.
100 x86_pci_write_config16(PIIX_IDE, IDE0_TIM, IDE_DECODE_EN);
101 x86_pci_write_config16(PIIX_IDE, IDE1_TIM, IDE_DECODE_EN);