Angel Pons | 6e5aabd | 2020-03-23 23:44:42 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 3 | |
| 4 | #include <types.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 5 | #include <console/console.h> |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 6 | #include <commonlib/helpers.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame^] | 7 | #include <acpi/acpi.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 8 | #include <device/device.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 9 | #include <device/pci_ops.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 10 | #include "sandybridge.h" |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 11 | #include <southbridge/intel/bd82x6x/pch.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 12 | |
| 13 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 14 | { |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 15 | u32 pciexbar = 0; |
| 16 | u32 pciexbar_reg; |
| 17 | int max_buses; |
| 18 | |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 19 | struct device *const dev = pcidev_on_root(0, 0); |
Vagiz Trakhanov | e200c1c | 2017-09-28 15:01:06 +0000 | [diff] [blame] | 20 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 21 | if (!dev) |
| 22 | return current; |
| 23 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 24 | pciexbar_reg = pci_read_config32(dev, PCIEXBAR); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 25 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 26 | /* MMCFG not supported or not enabled */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 27 | if (!(pciexbar_reg & (1 << 0))) |
| 28 | return current; |
| 29 | |
| 30 | switch ((pciexbar_reg >> 1) & 3) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 31 | case 0: /* 256MB */ |
| 32 | pciexbar = pciexbar_reg & (0xffffffffULL << 28); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 33 | max_buses = 256; |
| 34 | break; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 35 | case 1: /* 128M */ |
| 36 | pciexbar = pciexbar_reg & (0xffffffffULL << 27); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 37 | max_buses = 128; |
| 38 | break; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 39 | case 2: /* 64M */ |
| 40 | pciexbar = pciexbar_reg & (0xffffffffULL << 26); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 41 | max_buses = 64; |
| 42 | break; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 43 | default: /* RSVD */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 44 | return current; |
| 45 | } |
| 46 | |
| 47 | if (!pciexbar) |
| 48 | return current; |
| 49 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 50 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, pciexbar, 0, 0, |
| 51 | max_buses - 1); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 52 | |
| 53 | return current; |
| 54 | } |
| 55 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 56 | |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 57 | static unsigned long acpi_create_igfx_rmrr(const unsigned long current) |
| 58 | { |
| 59 | const u32 base_mask = ~(u32)(MiB - 1); |
| 60 | |
Kyösti Mälkki | 19bad30 | 2019-02-08 18:42:19 +0200 | [diff] [blame] | 61 | struct device *const host = pcidev_on_root(0, 0); |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 62 | if (!host) |
| 63 | return 0; |
| 64 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 65 | const u32 bgsm = pci_read_config32(host, BGSM) & base_mask; |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 66 | const u32 tolud = pci_read_config32(host, TOLUD) & base_mask; |
| 67 | if (!bgsm || !tolud) |
| 68 | return 0; |
| 69 | |
| 70 | return acpi_create_dmar_rmrr(current, 0, bgsm, tolud - 1); |
| 71 | } |
| 72 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 73 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 74 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 75 | const struct device *const igfx = pcidev_on_root(2, 0); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 76 | |
| 77 | if (igfx && igfx->enabled) { |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 78 | unsigned long tmp; |
| 79 | |
| 80 | tmp = current; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 81 | current += acpi_create_dmar_drhd(current, 0, 0, GFXVT_BASE); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 82 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
| 83 | current += acpi_create_dmar_ds_pci(current, 0, 2, 1); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 84 | acpi_dmar_drhd_fixup(tmp, current); |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 85 | |
| 86 | tmp = current; |
| 87 | current += acpi_create_igfx_rmrr(current); |
| 88 | if (current != tmp) { |
| 89 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
| 90 | current += acpi_create_dmar_ds_pci(current, 0, 2, 1); |
| 91 | acpi_dmar_rmrr_fixup(tmp, current); |
| 92 | } |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | const unsigned long tmp = current; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 96 | current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, VTVC0_BASE); |
| 97 | |
| 98 | current += acpi_create_dmar_ds_ioapic(current, 2, PCH_IOAPIC_PCI_BUS, |
| 99 | PCH_IOAPIC_PCI_SLOT, 0); |
| 100 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 101 | size_t i; |
| 102 | for (i = 0; i < 8; ++i) |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 103 | current += acpi_create_dmar_ds_msi_hpet(current, 0, PCH_HPET_PCI_BUS, |
| 104 | PCH_HPET_PCI_SLOT, i); |
| 105 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 106 | acpi_dmar_drhd_fixup(tmp, current); |
| 107 | |
| 108 | return current; |
| 109 | } |
| 110 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 111 | unsigned long northbridge_write_acpi_tables(const struct device *const dev, |
| 112 | unsigned long current, |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 113 | struct acpi_rsdp *const rsdp) |
| 114 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 115 | const u32 capid0_a = pci_read_config32(dev, CAPID0_A); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 116 | if (capid0_a & (1 << 23)) |
| 117 | return current; |
| 118 | |
| 119 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 120 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 121 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 122 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 123 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 124 | current += dmar->header.length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 125 | current = acpi_align_current(current); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 126 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 127 | acpi_add_table(rsdp, dmar); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 128 | current = acpi_align_current(current); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 129 | |
| 130 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 131 | |
| 132 | return current; |
| 133 | } |