blob: e54082df7f9654c94d20436c63bc1d8b274c7a87 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng2229c4c2015-05-07 21:34:08 +08002/*
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
Bin Meng2229c4c2015-05-07 21:34:08 +08004 */
5
6#include <common.h>
Simon Glass1fa70f82019-11-14 12:57:34 -07007#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Bin Meng5fecada2016-02-01 01:40:56 -08009#include <pci.h>
Miao Yan92106272016-05-22 19:37:17 -070010#include <qfw.h>
Asherah Connor4ffa95d2021-03-19 18:21:40 +110011#include <dm/platdata.h>
Bin Mengef37e7b2015-06-03 09:20:06 +080012#include <asm/irq.h>
Bin Meng2229c4c2015-05-07 21:34:08 +080013#include <asm/post.h>
14#include <asm/processor.h>
Bin Menge456f2b2015-11-06 02:04:49 -080015#include <asm/arch/device.h>
16#include <asm/arch/qemu.h>
17
18static bool i440fx;
19
Asherah Connor4ffa95d2021-03-19 18:21:40 +110020#if CONFIG_IS_ENABLED(QFW_PIO)
21U_BOOT_DRVINFO(x86_qfw_pio) = {
22 .name = "qfw_pio",
Miao Yan8a153832016-05-22 19:37:15 -070023};
24#endif
25
Miao Yan35603ff2016-01-20 01:57:05 -080026static void enable_pm_piix(void)
27{
28 u8 en;
29 u16 cmd;
30
31 /* Set the PM I/O base */
Bin Meng5fecada2016-02-01 01:40:56 -080032 pci_write_config32(PIIX_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
Miao Yan35603ff2016-01-20 01:57:05 -080033
34 /* Enable access to the PM I/O space */
Bin Meng5fecada2016-02-01 01:40:56 -080035 pci_read_config16(PIIX_PM, PCI_COMMAND, &cmd);
Miao Yan35603ff2016-01-20 01:57:05 -080036 cmd |= PCI_COMMAND_IO;
Bin Meng5fecada2016-02-01 01:40:56 -080037 pci_write_config16(PIIX_PM, PCI_COMMAND, cmd);
Miao Yan35603ff2016-01-20 01:57:05 -080038
39 /* PM I/O Space Enable (PMIOSE) */
Bin Meng5fecada2016-02-01 01:40:56 -080040 pci_read_config8(PIIX_PM, PMREGMISC, &en);
Miao Yan35603ff2016-01-20 01:57:05 -080041 en |= PMIOSE;
Bin Meng5fecada2016-02-01 01:40:56 -080042 pci_write_config8(PIIX_PM, PMREGMISC, en);
Miao Yan35603ff2016-01-20 01:57:05 -080043}
44
45static void enable_pm_ich9(void)
46{
47 /* Set the PM I/O base */
Bin Meng5fecada2016-02-01 01:40:56 -080048 pci_write_config32(ICH9_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
Miao Yan35603ff2016-01-20 01:57:05 -080049}
50
Bin Menge456f2b2015-11-06 02:04:49 -080051static void qemu_chipset_init(void)
52{
53 u16 device, xbcs;
54 int pam, i;
55
56 /*
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
59 * PCI device ID.
60 */
Bin Meng5fecada2016-02-01 01:40:56 -080061 pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID, &device);
Bin Menge456f2b2015-11-06 02:04:49 -080062 i440fx = (device == PCI_DEVICE_ID_INTEL_82441);
63 pam = i440fx ? I440FX_PAM : Q35_PAM;
64
65 /*
66 * Initialize Programmable Attribute Map (PAM) Registers
67 *
68 * Configure legacy segments C/D/E/F to system RAM
69 */
70 for (i = 0; i < PAM_NUM; i++)
Bin Meng5fecada2016-02-01 01:40:56 -080071 pci_write_config8(PCI_BDF(0, 0, 0), pam + i, PAM_RW);
Bin Menge456f2b2015-11-06 02:04:49 -080072
73 if (i440fx) {
74 /*
75 * Enable legacy IDE I/O ports decode
76 *
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.
81 */
Bin Meng5fecada2016-02-01 01:40:56 -080082 pci_write_config16(PIIX_IDE, IDE0_TIM, IDE_DECODE_EN);
83 pci_write_config16(PIIX_IDE, IDE1_TIM, IDE_DECODE_EN);
Bin Menge456f2b2015-11-06 02:04:49 -080084
85 /* Enable I/O APIC */
Bin Meng5fecada2016-02-01 01:40:56 -080086 pci_read_config16(PIIX_ISA, XBCS, &xbcs);
Bin Menge456f2b2015-11-06 02:04:49 -080087 xbcs |= APIC_EN;
Bin Meng5fecada2016-02-01 01:40:56 -080088 pci_write_config16(PIIX_ISA, XBCS, xbcs);
Miao Yan35603ff2016-01-20 01:57:05 -080089
90 enable_pm_piix();
Bin Menge456f2b2015-11-06 02:04:49 -080091 } else {
92 /* Configure PCIe ECAM base address */
Bin Meng5fecada2016-02-01 01:40:56 -080093 pci_write_config32(PCI_BDF(0, 0, 0), PCIEX_BAR,
94 CONFIG_PCIE_ECAM_BASE | BAR_EN);
Miao Yan35603ff2016-01-20 01:57:05 -080095
96 enable_pm_ich9();
Bin Menge456f2b2015-11-06 02:04:49 -080097 }
98}
Bin Meng2229c4c2015-05-07 21:34:08 +080099
Bin Meng7172c0a2017-01-18 03:32:55 -0800100#if !CONFIG_IS_ENABLED(SPL_X86_32BIT_INIT)
Bin Meng2229c4c2015-05-07 21:34:08 +0800101int arch_cpu_init(void)
102{
Bin Meng2229c4c2015-05-07 21:34:08 +0800103 post_code(POST_CPU_INIT);
Bin Meng2229c4c2015-05-07 21:34:08 +0800104
Masahiro Yamada17103212016-09-06 22:17:36 +0900105 return x86_cpu_init_f();
Bin Meng2229c4c2015-05-07 21:34:08 +0800106}
Simon Glassee7c36f2017-03-28 10:27:30 -0600107
108int checkcpu(void)
109{
110 return 0;
111}
112
Bin Meng2229c4c2015-05-07 21:34:08 +0800113int print_cpuinfo(void)
114{
115 post_code(POST_CPU_INFO);
116 return default_print_cpuinfo();
117}
Simon Glass752f9762015-08-04 12:34:03 -0600118#endif
Bin Meng2229c4c2015-05-07 21:34:08 +0800119
Bin Menge456f2b2015-11-06 02:04:49 -0800120int arch_early_init_r(void)
121{
122 qemu_chipset_init();
123
124 return 0;
125}
126
Bin Menge456f2b2015-11-06 02:04:49 -0800127#ifdef CONFIG_GENERATE_MP_TABLE
128int mp_determine_pci_dstirq(int bus, int dev, int func, int pirq)
129{
130 u8 irq;
131
132 if (i440fx) {
133 /*
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.
137 */
Bin Meng5fecada2016-02-01 01:40:56 -0800138 pci_read_config8(PCI_BDF(bus, dev, func),
139 PCI_INTERRUPT_LINE, &irq);
Bin Menge456f2b2015-11-06 02:04:49 -0800140 } else {
141 /*
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].
144 */
145 irq = pirq < 8 ? pirq + 16 : pirq + 12;
146 }
147
148 return irq;
149}
150#endif