blob: 5a7b92944a21501edd10b99824cb2eab337e0da1 [file] [log] [blame]
Bin Meng2229c4c2015-05-07 21:34:08 +08001/*
2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Bin Mengef37e7b2015-06-03 09:20:06 +08008#include <asm/irq.h>
Bin Menge456f2b2015-11-06 02:04:49 -08009#include <asm/pci.h>
Bin Meng2229c4c2015-05-07 21:34:08 +080010#include <asm/post.h>
11#include <asm/processor.h>
Bin Menge456f2b2015-11-06 02:04:49 -080012#include <asm/arch/device.h>
13#include <asm/arch/qemu.h>
Miao Yan58a3ce22016-01-07 01:32:00 -080014#include <asm/fw_cfg.h>
Bin Menge456f2b2015-11-06 02:04:49 -080015
16static bool i440fx;
17
18static void qemu_chipset_init(void)
19{
20 u16 device, xbcs;
21 int pam, i;
22
23 /*
24 * i440FX and Q35 chipset have different PAM register offset, but with
25 * the same bitfield layout. Here we determine the offset based on its
26 * PCI device ID.
27 */
28 device = x86_pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID);
29 i440fx = (device == PCI_DEVICE_ID_INTEL_82441);
30 pam = i440fx ? I440FX_PAM : Q35_PAM;
31
32 /*
33 * Initialize Programmable Attribute Map (PAM) Registers
34 *
35 * Configure legacy segments C/D/E/F to system RAM
36 */
37 for (i = 0; i < PAM_NUM; i++)
38 x86_pci_write_config8(PCI_BDF(0, 0, 0), pam + i, PAM_RW);
39
40 if (i440fx) {
41 /*
42 * Enable legacy IDE I/O ports decode
43 *
44 * Note: QEMU always decode legacy IDE I/O port on PIIX chipset.
45 * However Linux ata_piix driver does sanity check on these two
46 * registers to see whether legacy ports decode is turned on.
47 * This is to make Linux ata_piix driver happy.
48 */
49 x86_pci_write_config16(PIIX_IDE, IDE0_TIM, IDE_DECODE_EN);
50 x86_pci_write_config16(PIIX_IDE, IDE1_TIM, IDE_DECODE_EN);
51
52 /* Enable I/O APIC */
53 xbcs = x86_pci_read_config16(PIIX_ISA, XBCS);
54 xbcs |= APIC_EN;
55 x86_pci_write_config16(PIIX_ISA, XBCS, xbcs);
56 } else {
57 /* Configure PCIe ECAM base address */
58 x86_pci_write_config32(PCI_BDF(0, 0, 0), PCIEX_BAR,
59 CONFIG_PCIE_ECAM_BASE | BAR_EN);
60 }
Miao Yan58a3ce22016-01-07 01:32:00 -080061
62 qemu_fwcfg_init();
Bin Menge456f2b2015-11-06 02:04:49 -080063}
Bin Meng2229c4c2015-05-07 21:34:08 +080064
65int arch_cpu_init(void)
66{
67 int ret;
68
69 post_code(POST_CPU_INIT);
Bin Meng2229c4c2015-05-07 21:34:08 +080070
71 ret = x86_cpu_init_f();
72 if (ret)
73 return ret;
74
75 return 0;
76}
77
Simon Glass752f9762015-08-04 12:34:03 -060078#ifndef CONFIG_EFI_STUB
Bin Meng2229c4c2015-05-07 21:34:08 +080079int print_cpuinfo(void)
80{
81 post_code(POST_CPU_INFO);
82 return default_print_cpuinfo();
83}
Simon Glass752f9762015-08-04 12:34:03 -060084#endif
Bin Meng2229c4c2015-05-07 21:34:08 +080085
86void reset_cpu(ulong addr)
87{
88 /* cold reset */
89 x86_full_reset();
90}
Bin Mengef37e7b2015-06-03 09:20:06 +080091
Bin Menge456f2b2015-11-06 02:04:49 -080092int arch_early_init_r(void)
93{
94 qemu_chipset_init();
95
96 return 0;
97}
98
Bin Menge456f2b2015-11-06 02:04:49 -080099#ifdef CONFIG_GENERATE_MP_TABLE
100int mp_determine_pci_dstirq(int bus, int dev, int func, int pirq)
101{
102 u8 irq;
103
104 if (i440fx) {
105 /*
106 * Not like most x86 platforms, the PIRQ[A-D] on PIIX3 are not
107 * connected to I/O APIC INTPIN#16-19. Instead they are routed
108 * to an irq number controled by the PIRQ routing register.
109 */
110 irq = x86_pci_read_config8(PCI_BDF(bus, dev, func),
111 PCI_INTERRUPT_LINE);
112 } else {
113 /*
114 * ICH9's PIRQ[A-H] are not consecutive numbers from 0 to 7.
115 * PIRQ[A-D] still maps to [0-3] but PIRQ[E-H] maps to [8-11].
116 */
117 irq = pirq < 8 ? pirq + 16 : pirq + 12;
118 }
119
120 return irq;
121}
122#endif