1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
11 #include <dm/platdata.h>
14 #include <asm/processor.h>
15 #include <asm/arch/device.h>
16 #include <asm/arch/qemu.h>
20 #if CONFIG_IS_ENABLED(QFW_PIO)
21 U_BOOT_DRVINFO(x86_qfw_pio) = {
26 static void enable_pm_piix(void)
31 /* Set the PM I/O base */
32 pci_write_config32(PIIX_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
34 /* Enable access to the PM I/O space */
35 pci_read_config16(PIIX_PM, PCI_COMMAND, &cmd);
36 cmd |= PCI_COMMAND_IO;
37 pci_write_config16(PIIX_PM, PCI_COMMAND, cmd);
39 /* PM I/O Space Enable (PMIOSE) */
40 pci_read_config8(PIIX_PM, PMREGMISC, &en);
42 pci_write_config8(PIIX_PM, PMREGMISC, en);
45 static void enable_pm_ich9(void)
47 /* Set the PM I/O base */
48 pci_write_config32(ICH9_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
51 void qemu_chipset_init(void)
57 * i440FX and Q35 chipset have different PAM register offset, but with
58 * the same bitfield layout. Here we determine the offset based on its
61 pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID, &device);
62 i440fx = (device == PCI_DEVICE_ID_INTEL_82441);
63 pam = i440fx ? I440FX_PAM : Q35_PAM;
66 * Initialize Programmable Attribute Map (PAM) Registers
68 * Configure legacy segments C/D/E/F to system RAM
70 for (i = 0; i < PAM_NUM; i++)
71 pci_write_config8(PCI_BDF(0, 0, 0), pam + i, PAM_RW);
75 * Enable legacy IDE I/O ports decode
77 * Note: QEMU always decode legacy IDE I/O port on PIIX chipset.
78 * However Linux ata_piix driver does sanity check on these two
79 * registers to see whether legacy ports decode is turned on.
80 * This is to make Linux ata_piix driver happy.
82 pci_write_config16(PIIX_IDE, IDE0_TIM, IDE_DECODE_EN);
83 pci_write_config16(PIIX_IDE, IDE1_TIM, IDE_DECODE_EN);
86 pci_read_config16(PIIX_ISA, XBCS, &xbcs);
88 pci_write_config16(PIIX_ISA, XBCS, xbcs);
92 /* Configure PCIe ECAM base address */
93 pci_write_config32(PCI_BDF(0, 0, 0), PCIEX_BAR,
94 CONFIG_PCIE_ECAM_BASE | BAR_EN);
100 #if CONFIG_IS_ENABLED(X86_32BIT_INIT)
101 int arch_cpu_init(void)
103 post_code(POST_CPU_INIT);
105 return x86_cpu_init_f();
113 int print_cpuinfo(void)
115 post_code(POST_CPU_INFO);
116 return default_print_cpuinfo();
120 int arch_early_init_r(void)
127 #ifdef CONFIG_GENERATE_MP_TABLE
128 int mp_determine_pci_dstirq(int bus, int dev, int func, int pirq)
134 * Not like most x86 platforms, the PIRQ[A-D] on PIIX3 are not
135 * connected to I/O APIC INTPIN#16-19. Instead they are routed
136 * to an irq number controled by the PIRQ routing register.
138 pci_read_config8(PCI_BDF(bus, dev, func),
139 PCI_INTERRUPT_LINE, &irq);
142 * ICH9's PIRQ[A-H] are not consecutive numbers from 0 to 7.
143 * PIRQ[A-D] still maps to [0-3] but PIRQ[E-H] maps to [8-11].
145 irq = pirq < 8 ? pirq + 16 : pirq + 12;