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