Angel Pons | 585495e | 2020-04-03 01:21:38 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 2 | |
| 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
| 6 | #include <pc80/keyboard.h> |
Patrick Rudolph | d12f030 | 2021-02-03 17:33:40 +0100 | [diff] [blame] | 7 | #include <cpu/x86/smm.h> |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 8 | |
Angel Pons | 816a41c | 2021-01-28 11:09:56 +0100 | [diff] [blame] | 9 | #include "q35.h" |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 10 | |
| 11 | static const unsigned char qemu_q35_irqs[] = { |
| 12 | 10, 10, 11, 11, |
| 13 | 10, 10, 11, 11, |
| 14 | }; |
| 15 | |
Elyes HAOUAS | 5cb876c | 2018-06-08 18:31:43 +0200 | [diff] [blame] | 16 | static void qemu_nb_init(struct device *dev) |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 17 | { |
| 18 | /* Map memory at 0xc0000 - 0xfffff */ |
| 19 | int i; |
Angel Pons | 816a41c | 2021-01-28 11:09:56 +0100 | [diff] [blame] | 20 | uint8_t v = pci_read_config8(dev, D0F0_PAM(0)); |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 21 | v |= 0x30; |
Angel Pons | 816a41c | 2021-01-28 11:09:56 +0100 | [diff] [blame] | 22 | 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 Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 29 | |
Paul Menzel | feecdc2 | 2020-06-20 23:01:37 +0200 | [diff] [blame] | 30 | /* This sneaked in here, because Qemu does not emulate a SuperIO chip. */ |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 31 | pc_keyboard_init(NO_AUX_DEVICE); |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 32 | |
| 33 | /* setup IRQ routing for pci slots */ |
| 34 | for (i = 0; i < 25; i++) |
Kyösti Mälkki | c19d6a6 | 2019-07-04 21:39:28 +0300 | [diff] [blame] | 35 | pci_assign_irqs(pcidev_on_root(i, 0), qemu_q35_irqs + (i % 4)); |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 36 | /* setup IRQ routing southbridge devices */ |
| 37 | for (i = 25; i < 32; i++) |
Kyösti Mälkki | c19d6a6 | 2019-07-04 21:39:28 +0300 | [diff] [blame] | 38 | pci_assign_irqs(pcidev_on_root(i, 0), qemu_q35_irqs); |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | static void qemu_nb_read_resources(struct device *dev) |
| 42 | { |
Patrick Rudolph | d12f030 | 2021-02-03 17:33:40 +0100 | [diff] [blame] | 43 | size_t tseg_size; |
| 44 | uintptr_t tseg_base; |
| 45 | |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 46 | pci_dev_read_resources(dev); |
| 47 | |
Angel Pons | cba669c | 2021-01-28 11:56:45 +0100 | [diff] [blame] | 48 | mmconf_resource(dev, 2); |
Patrick Rudolph | 82e111c | 2021-01-07 14:12:38 +0100 | [diff] [blame] | 49 | |
| 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 Rudolph | d12f030 | 2021-02-03 17:33:40 +0100 | [diff] [blame] | 55 | |
| 56 | smm_region(&tseg_base, &tseg_size); |
| 57 | reserved_ram_resource(dev, ESMRAMC, tseg_base / 1024, tseg_size / 1024); |
Gerd Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | |
| 61 | static 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 Hoffmann | ee941b38 | 2013-06-07 16:03:44 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static const struct pci_driver nb_driver __pci_driver = { |
| 69 | .ops = &nb_operations, |
| 70 | .vendor = 0x8086, |
| 71 | .device = 0x29c0, |
| 72 | }; |