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
;
18 void board_pci_setup_hose(struct pci_controller
*hose
)
20 hose
->first_busno
= 0;
23 /* PCI memory space */
24 pci_set_region(hose
->regions
+ 0,
31 pci_set_region(hose
->regions
+ 1,
37 pci_set_region(hose
->regions
+ 2,
43 pci_set_region(hose
->regions
+ 3,
47 PCI_REGION_MEM
| PCI_REGION_SYS_MEMORY
);
49 hose
->region_count
= 4;
52 int board_pci_post_scan(struct pci_controller
*hose
)
61 * i440FX and Q35 chipset have different PAM register offset, but with
62 * the same bitfield layout. Here we determine the offset based on its
65 device
= x86_pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID
);
66 i440fx
= (device
== PCI_DEVICE_ID_INTEL_82441
);
67 pam
= i440fx
? I440FX_PAM
: Q35_PAM
;
70 * Initialize Programmable Attribute Map (PAM) Registers
72 * Configure legacy segments C/D/E/F to system RAM
74 for (i
= 0; i
< PAM_NUM
; i
++)
75 x86_pci_write_config8(PCI_BDF(0, 0, 0), pam
+ i
, PAM_RW
);
79 * Enable legacy IDE I/O ports decode
81 * Note: QEMU always decode legacy IDE I/O port on PIIX chipset.
82 * However Linux ata_piix driver does sanity check on these two
83 * registers to see whether legacy ports decode is turned on.
84 * This is to make Linux ata_piix driver happy.
86 x86_pci_write_config16(PIIX_IDE
, IDE0_TIM
, IDE_DECODE_EN
);
87 x86_pci_write_config16(PIIX_IDE
, IDE1_TIM
, IDE_DECODE_EN
);
90 xbcs
= x86_pci_read_config16(PIIX_ISA
, XBCS
);
92 x86_pci_write_config16(PIIX_ISA
, XBCS
, xbcs
);
96 * QEMU emulated graphic card shows in the PCI configuration space with
97 * PCI vendor id and device id as an artificial pair 0x1234:0x1111.
98 * It is on PCI bus 0, function 0, but device number is not consistent
99 * for the two x86 targets it supports. For i440FX and PIIX chipset
100 * board, it shows as device 2, while for Q35 and ICH9 chipset board,
101 * it shows as device 1.
103 vga
= i440fx
? I440FX_VGA
: Q35_VGA
;
104 start
= get_timer(0);
105 ret
= pci_run_vga_bios(vga
, NULL
, PCI_ROM_USE_NATIVE
);
106 debug("BIOS ran in %lums\n", get_timer(start
));
111 #ifdef CONFIG_GENERATE_MP_TABLE
112 int mp_determine_pci_dstirq(int bus
, int dev
, int func
, int pirq
)
118 * Not like most x86 platforms, the PIRQ[A-D] on PIIX3 are not
119 * connected to I/O APIC INTPIN#16-19. Instead they are routed
120 * to an irq number controled by the PIRQ routing register.
122 irq
= x86_pci_read_config8(PCI_BDF(bus
, dev
, func
),
126 * ICH9's PIRQ[A-H] are not consecutive numbers from 0 to 7.
127 * PIRQ[A-D] still maps to [0-3] but PIRQ[E-H] maps to [8-11].
129 irq
= pirq
< 8 ? pirq
+ 16 : pirq
+ 12;