blob: 0911671e5c576ce953fab5e67c964bb9a0082eca [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>
Gerd Hoffmannee941b382013-06-07 16:03:44 +02007
Angel Pons816a41c2021-01-28 11:09:56 +01008#include "q35.h"
Gerd Hoffmannee941b382013-06-07 16:03:44 +02009
10static const unsigned char qemu_q35_irqs[] = {
11 10, 10, 11, 11,
12 10, 10, 11, 11,
13};
14
Elyes HAOUAS5cb876c2018-06-08 18:31:43 +020015static void qemu_nb_init(struct device *dev)
Gerd Hoffmannee941b382013-06-07 16:03:44 +020016{
17 /* Map memory at 0xc0000 - 0xfffff */
18 int i;
Angel Pons816a41c2021-01-28 11:09:56 +010019 uint8_t v = pci_read_config8(dev, D0F0_PAM(0));
Gerd Hoffmannee941b382013-06-07 16:03:44 +020020 v |= 0x30;
Angel Pons816a41c2021-01-28 11:09:56 +010021 pci_write_config8(dev, D0F0_PAM(0), v);
22 pci_write_config8(dev, D0F0_PAM(1), 0x33);
23 pci_write_config8(dev, D0F0_PAM(2), 0x33);
24 pci_write_config8(dev, D0F0_PAM(3), 0x33);
25 pci_write_config8(dev, D0F0_PAM(4), 0x33);
26 pci_write_config8(dev, D0F0_PAM(5), 0x33);
27 pci_write_config8(dev, D0F0_PAM(6), 0x33);
Gerd Hoffmannee941b382013-06-07 16:03:44 +020028
Paul Menzelfeecdc22020-06-20 23:01:37 +020029 /* This sneaked in here, because Qemu does not emulate a SuperIO chip. */
Timothy Pearson448e3862015-11-24 14:12:01 -060030 pc_keyboard_init(NO_AUX_DEVICE);
Gerd Hoffmannee941b382013-06-07 16:03:44 +020031
32 /* setup IRQ routing for pci slots */
33 for (i = 0; i < 25; i++)
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +030034 pci_assign_irqs(pcidev_on_root(i, 0), qemu_q35_irqs + (i % 4));
Gerd Hoffmannee941b382013-06-07 16:03:44 +020035 /* setup IRQ routing southbridge devices */
36 for (i = 25; i < 32; i++)
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +030037 pci_assign_irqs(pcidev_on_root(i, 0), qemu_q35_irqs);
Gerd Hoffmannee941b382013-06-07 16:03:44 +020038}
39
40static void qemu_nb_read_resources(struct device *dev)
41{
42 pci_dev_read_resources(dev);
43
44 /* reserve mmconfig */
Kyösti Mälkkib9646a22013-07-03 08:06:32 +030045 fixed_mem_resource(dev, 2, CONFIG_MMCONF_BASE_ADDRESS >> 10, 0x10000000 >> 10,
Gerd Hoffmannee941b382013-06-07 16:03:44 +020046 IORESOURCE_RESERVE);
Patrick Rudolph82e111c2021-01-07 14:12:38 +010047
48 if (CONFIG(ARCH_RAMSTAGE_X86_64)) {
49 /* Reserve page tables in DRAM. FIXME: Remove once x86_64 page tables reside in CBMEM */
50 reserved_ram_resource(dev, 0, CONFIG_ARCH_X86_64_PGTBL_LOC / KiB,
51 (6 * 0x1000) / KiB);
52 }
Gerd Hoffmannee941b382013-06-07 16:03:44 +020053}
54
55
56static struct device_operations nb_operations = {
57 .read_resources = qemu_nb_read_resources,
58 .set_resources = pci_dev_set_resources,
59 .enable_resources = pci_dev_enable_resources,
60 .init = qemu_nb_init,
Gerd Hoffmannee941b382013-06-07 16:03:44 +020061};
62
63static const struct pci_driver nb_driver __pci_driver = {
64 .ops = &nb_operations,
65 .vendor = 0x8086,
66 .device = 0x29c0,
67};