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