blob: e53404d55c40ae616438d20c5991912f4411bd84 [file] [log] [blame]
Angel Pons585495e2020-04-03 01:21:38 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Gerd Hoffmannee941b382013-06-07 16:03:44 +02002
3#include <device/device.h>
4#include <device/pci.h>
Gerd Hoffmannee941b382013-06-07 16:03:44 +02005#include <device/pci_ops.h>
6#include <pc80/keyboard.h>
Patrick Rudolphd12f0302021-02-03 17:33:40 +01007#include <cpu/x86/smm.h>
Gerd Hoffmannee941b382013-06-07 16:03:44 +02008
Angel Pons816a41c2021-01-28 11:09:56 +01009#include "q35.h"
Gerd Hoffmannee941b382013-06-07 16:03:44 +020010
11static const unsigned char qemu_q35_irqs[] = {
12 10, 10, 11, 11,
13 10, 10, 11, 11,
14};
15
Elyes HAOUAS5cb876c2018-06-08 18:31:43 +020016static void qemu_nb_init(struct device *dev)
Gerd Hoffmannee941b382013-06-07 16:03:44 +020017{
18 /* Map memory at 0xc0000 - 0xfffff */
19 int i;
Angel Pons816a41c2021-01-28 11:09:56 +010020 uint8_t v = pci_read_config8(dev, D0F0_PAM(0));
Gerd Hoffmannee941b382013-06-07 16:03:44 +020021 v |= 0x30;
Angel Pons816a41c2021-01-28 11:09:56 +010022 pci_write_config8(dev, D0F0_PAM(0), v);
23 pci_write_config8(dev, D0F0_PAM(1), 0x33);
24 pci_write_config8(dev, D0F0_PAM(2), 0x33);
25 pci_write_config8(dev, D0F0_PAM(3), 0x33);
26 pci_write_config8(dev, D0F0_PAM(4), 0x33);
27 pci_write_config8(dev, D0F0_PAM(5), 0x33);
28 pci_write_config8(dev, D0F0_PAM(6), 0x33);
Gerd Hoffmannee941b382013-06-07 16:03:44 +020029
Paul Menzelfeecdc22020-06-20 23:01:37 +020030 /* This sneaked in here, because Qemu does not emulate a SuperIO chip. */
Timothy Pearson448e3862015-11-24 14:12:01 -060031 pc_keyboard_init(NO_AUX_DEVICE);
Gerd Hoffmannee941b382013-06-07 16:03:44 +020032
33 /* setup IRQ routing for pci slots */
34 for (i = 0; i < 25; i++)
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +030035 pci_assign_irqs(pcidev_on_root(i, 0), qemu_q35_irqs + (i % 4));
Gerd Hoffmannee941b382013-06-07 16:03:44 +020036 /* setup IRQ routing southbridge devices */
37 for (i = 25; i < 32; i++)
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +030038 pci_assign_irqs(pcidev_on_root(i, 0), qemu_q35_irqs);
Gerd Hoffmannee941b382013-06-07 16:03:44 +020039}
40
41static void qemu_nb_read_resources(struct device *dev)
42{
Patrick Rudolphd12f0302021-02-03 17:33:40 +010043 size_t tseg_size;
44 uintptr_t tseg_base;
45
Gerd Hoffmannee941b382013-06-07 16:03:44 +020046 pci_dev_read_resources(dev);
47
Angel Ponscba669c2021-01-28 11:56:45 +010048 mmconf_resource(dev, 2);
Patrick Rudolph82e111c2021-01-07 14:12:38 +010049
50 if (CONFIG(ARCH_RAMSTAGE_X86_64)) {
51 /* Reserve page tables in DRAM. FIXME: Remove once x86_64 page tables reside in CBMEM */
52 reserved_ram_resource(dev, 0, CONFIG_ARCH_X86_64_PGTBL_LOC / KiB,
53 (6 * 0x1000) / KiB);
54 }
Patrick Rudolphd12f0302021-02-03 17:33:40 +010055
56 smm_region(&tseg_base, &tseg_size);
57 reserved_ram_resource(dev, ESMRAMC, tseg_base / 1024, tseg_size / 1024);
Gerd Hoffmannee941b382013-06-07 16:03:44 +020058}
59
60
61static struct device_operations nb_operations = {
62 .read_resources = qemu_nb_read_resources,
63 .set_resources = pci_dev_set_resources,
64 .enable_resources = pci_dev_enable_resources,
65 .init = qemu_nb_init,
Gerd Hoffmannee941b382013-06-07 16:03:44 +020066};
67
68static const struct pci_driver nb_driver __pci_driver = {
69 .ops = &nb_operations,
70 .vendor = 0x8086,
71 .device = 0x29c0,
72};