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