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