Angel Pons | 6e5aabd | 2020-03-23 23:44:42 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 2 | |
| 3 | #include <types.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 4 | #include <console/console.h> |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 5 | #include <commonlib/helpers.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 6 | #include <acpi/acpi.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 7 | #include <device/device.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 8 | #include <device/pci_ops.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 9 | #include "sandybridge.h" |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 10 | #include <southbridge/intel/bd82x6x/pch.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 11 | |
| 12 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 13 | { |
Angel Pons | 10f9b83 | 2021-01-20 14:58:32 +0100 | [diff] [blame] | 14 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
| 15 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, CONFIG_MMCONF_BUS_NUMBER - 1); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 16 | |
| 17 | return current; |
| 18 | } |
| 19 | |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 20 | static unsigned long acpi_create_igfx_rmrr(const unsigned long current) |
| 21 | { |
| 22 | const u32 base_mask = ~(u32)(MiB - 1); |
| 23 | |
Kyösti Mälkki | 19bad30 | 2019-02-08 18:42:19 +0200 | [diff] [blame] | 24 | struct device *const host = pcidev_on_root(0, 0); |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 25 | if (!host) |
| 26 | return 0; |
| 27 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 28 | const u32 bgsm = pci_read_config32(host, BGSM) & base_mask; |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 29 | const u32 tolud = pci_read_config32(host, TOLUD) & base_mask; |
| 30 | if (!bgsm || !tolud) |
| 31 | return 0; |
| 32 | |
| 33 | return acpi_create_dmar_rmrr(current, 0, bgsm, tolud - 1); |
| 34 | } |
| 35 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 36 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 37 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 38 | const struct device *const igfx = pcidev_on_root(2, 0); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 39 | |
Angel Pons | 9dfd615 | 2020-08-03 12:02:20 +0200 | [diff] [blame] | 40 | /* First, add DRHD entries */ |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 41 | if (igfx && igfx->enabled) { |
Angel Pons | 9dfd615 | 2020-08-03 12:02:20 +0200 | [diff] [blame] | 42 | const unsigned long tmp = current; |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 43 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 44 | current += acpi_create_dmar_drhd(current, 0, 0, GFXVT_BASE); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 45 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 46 | acpi_dmar_drhd_fixup(tmp, current); |
Angel Pons | 9dfd615 | 2020-08-03 12:02:20 +0200 | [diff] [blame] | 47 | } |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 48 | |
Angel Pons | 9dfd615 | 2020-08-03 12:02:20 +0200 | [diff] [blame] | 49 | { |
| 50 | const unsigned long tmp = current; |
| 51 | current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, VTVC0_BASE); |
| 52 | |
| 53 | current += acpi_create_dmar_ds_ioapic(current, 2, PCH_IOAPIC_PCI_BUS, |
| 54 | PCH_IOAPIC_PCI_SLOT, 0); |
| 55 | |
| 56 | size_t i; |
| 57 | for (i = 0; i < 8; ++i) |
| 58 | current += acpi_create_dmar_ds_msi_hpet(current, 0, PCH_HPET_PCI_BUS, |
| 59 | PCH_HPET_PCI_SLOT, i); |
| 60 | |
| 61 | acpi_dmar_drhd_fixup(tmp, current); |
| 62 | } |
| 63 | |
| 64 | /* Then, add RMRR entries after all DRHD entries */ |
| 65 | if (igfx && igfx->enabled) { |
| 66 | const unsigned long tmp = current; |
| 67 | |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 68 | current += acpi_create_igfx_rmrr(current); |
| 69 | if (current != tmp) { |
| 70 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
Nico Huber | b323474 | 2018-11-17 14:09:25 +0100 | [diff] [blame] | 71 | acpi_dmar_rmrr_fixup(tmp, current); |
| 72 | } |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 75 | return current; |
| 76 | } |
| 77 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 78 | unsigned long northbridge_write_acpi_tables(const struct device *const dev, |
| 79 | unsigned long current, |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 80 | struct acpi_rsdp *const rsdp) |
| 81 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 82 | const u32 capid0_a = pci_read_config32(dev, CAPID0_A); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 83 | if (capid0_a & (1 << 23)) |
| 84 | return current; |
| 85 | |
| 86 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 87 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 88 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 89 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 90 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 91 | current += dmar->header.length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 92 | current = acpi_align_current(current); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 93 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 94 | acpi_add_table(rsdp, dmar); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 95 | current = acpi_align_current(current); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 96 | |
| 97 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 98 | |
| 99 | return current; |
| 100 | } |