Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [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. |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <types.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 17 | #include <console/console.h> |
| 18 | #include <arch/acpi.h> |
| 19 | #include <arch/acpigen.h> |
| 20 | #include <device/device.h> |
Elyes HAOUAS | 748caed | 2019-12-19 17:02:08 +0100 | [diff] [blame] | 21 | #include <device/pci_def.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 22 | #include <device/pci_ops.h> |
Elyes HAOUAS | a1e22b8 | 2019-03-18 22:49:36 +0100 | [diff] [blame] | 23 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 24 | #include "gm45.h" |
| 25 | |
| 26 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 27 | { |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 28 | struct device *dev; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 29 | u32 pciexbar = 0; |
| 30 | u32 pciexbar_reg; |
| 31 | int max_buses; |
| 32 | |
| 33 | dev = dev_find_device(0x8086, 0x2a40, 0); |
| 34 | if (!dev) |
| 35 | return current; |
| 36 | |
| 37 | pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO); |
| 38 | |
| 39 | // MMCFG not supported or not enabled. |
| 40 | if (!(pciexbar_reg & (1 << 0))) |
| 41 | return current; |
| 42 | |
| 43 | switch ((pciexbar_reg >> 1) & 3) { |
| 44 | case 0: // 256MB |
| 45 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)); |
| 46 | max_buses = 256; |
| 47 | break; |
| 48 | case 1: // 128M |
| 49 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); |
| 50 | max_buses = 128; |
| 51 | break; |
| 52 | case 2: // 64M |
| 53 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26)); |
| 54 | max_buses = 64; |
| 55 | break; |
| 56 | default: // RSVD |
| 57 | return current; |
| 58 | } |
| 59 | |
| 60 | if (!pciexbar) |
| 61 | return current; |
| 62 | |
| 63 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, |
| 64 | pciexbar, 0x0, 0x0, max_buses - 1); |
| 65 | |
| 66 | return current; |
| 67 | } |
| 68 | |
Vladimir Serbinenko | 8d70e94 | 2014-11-09 13:22:27 +0100 | [diff] [blame] | 69 | static unsigned long acpi_fill_dmar(unsigned long current) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 70 | { |
Arthur Heymans | 15063e8 | 2019-08-12 09:41:42 +0200 | [diff] [blame] | 71 | const struct device *dev; |
| 72 | |
| 73 | dev = pcidev_on_root(3, 0); |
| 74 | int me_active = dev && dev->enabled; |
| 75 | |
Arthur Heymans | 0845636 | 2019-08-12 09:21:30 +0200 | [diff] [blame] | 76 | dev = pcidev_on_root(2, 0); |
| 77 | int igd_active = dev && dev->enabled; |
| 78 | |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 79 | int stepping = pci_read_config8(pcidev_on_root(0, 0), |
| 80 | PCI_CLASS_REVISION); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 81 | |
| 82 | unsigned long tmp = current; |
| 83 | current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 84 | current += acpi_create_dmar_ds_pci(current, 0, 0x1b, 0); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 85 | acpi_dmar_drhd_fixup(tmp, current); |
| 86 | |
Arthur Heymans | 0845636 | 2019-08-12 09:21:30 +0200 | [diff] [blame] | 87 | if (stepping != STEPPING_B2 && igd_active) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 88 | tmp = current; |
| 89 | current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE2); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 90 | current += acpi_create_dmar_ds_pci(current, 0, 0x2, 0); |
| 91 | current += acpi_create_dmar_ds_pci(current, 0, 0x2, 1); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 92 | acpi_dmar_drhd_fixup(tmp, current); |
| 93 | } |
| 94 | |
| 95 | if (me_active) { |
| 96 | tmp = current; |
| 97 | current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE3); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 98 | current += acpi_create_dmar_ds_pci(current, 0, 0x3, 0); |
| 99 | current += acpi_create_dmar_ds_pci(current, 0, 0x3, 1); |
| 100 | current += acpi_create_dmar_ds_pci(current, 0, 0x3, 2); |
| 101 | current += acpi_create_dmar_ds_pci(current, 0, 0x3, 3); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 102 | acpi_dmar_drhd_fixup(tmp, current); |
| 103 | } |
| 104 | |
| 105 | current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE4); |
| 106 | |
| 107 | /* TODO: reserve GTT for 0.2.0 and 0.2.1? */ |
| 108 | return current; |
| 109 | } |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 110 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 111 | unsigned long northbridge_write_acpi_tables(struct device *device, |
Alexander Couzens | 83fc32f | 2015-04-12 22:28:37 +0200 | [diff] [blame] | 112 | unsigned long start, |
| 113 | struct acpi_rsdp *rsdp) |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 114 | { |
| 115 | unsigned long current; |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 116 | acpi_dmar_t *dmar; |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 117 | |
| 118 | current = start; |
| 119 | |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 120 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 121 | dmar = (acpi_dmar_t *) current; |
Nico Huber | e561f35 | 2015-10-26 11:51:25 +0100 | [diff] [blame] | 122 | acpi_create_dmar(dmar, 0, acpi_fill_dmar); |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 123 | current += dmar->header.length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 124 | current = acpi_align_current(current); |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 125 | acpi_add_table(rsdp, dmar); |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 126 | |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 127 | current = acpi_align_current(current); |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 128 | |
| 129 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 130 | |
| 131 | return current; |
| 132 | } |