Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <types.h> |
| 18 | #include <string.h> |
| 19 | #include <console/console.h> |
| 20 | #include <arch/acpi.h> |
| 21 | #include <arch/acpigen.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 25 | #include <cbmem.h> |
| 26 | #include <arch/acpigen.h> |
| 27 | #include <cpu/cpu.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 28 | #include "gm45.h" |
| 29 | |
| 30 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 31 | { |
| 32 | device_t dev; |
| 33 | u32 pciexbar = 0; |
| 34 | u32 pciexbar_reg; |
| 35 | int max_buses; |
| 36 | |
| 37 | dev = dev_find_device(0x8086, 0x2a40, 0); |
| 38 | if (!dev) |
| 39 | return current; |
| 40 | |
| 41 | pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO); |
| 42 | |
| 43 | // MMCFG not supported or not enabled. |
| 44 | if (!(pciexbar_reg & (1 << 0))) |
| 45 | return current; |
| 46 | |
| 47 | switch ((pciexbar_reg >> 1) & 3) { |
| 48 | case 0: // 256MB |
| 49 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)); |
| 50 | max_buses = 256; |
| 51 | break; |
| 52 | case 1: // 128M |
| 53 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); |
| 54 | max_buses = 128; |
| 55 | break; |
| 56 | case 2: // 64M |
| 57 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26)); |
| 58 | max_buses = 64; |
| 59 | break; |
| 60 | default: // RSVD |
| 61 | return current; |
| 62 | } |
| 63 | |
| 64 | if (!pciexbar) |
| 65 | return current; |
| 66 | |
| 67 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, |
| 68 | pciexbar, 0x0, 0x0, max_buses - 1); |
| 69 | |
| 70 | return current; |
| 71 | } |
| 72 | |
Vladimir Serbinenko | 8d70e94 | 2014-11-09 13:22:27 +0100 | [diff] [blame] | 73 | static unsigned long acpi_fill_dmar(unsigned long current) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 74 | { |
Damien Zammit | 88af372 | 2016-08-27 00:35:48 +1000 | [diff] [blame^] | 75 | int me_active = (dev_find_slot(0, PCI_DEVFN(3, 0)) != NULL) && |
| 76 | (pci_read_config8(dev_find_slot(0, PCI_DEVFN(3, 0)), PCI_CLASS_REVISION) != 0xff); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 77 | int stepping = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), PCI_CLASS_REVISION); |
| 78 | |
| 79 | unsigned long tmp = current; |
| 80 | current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1); |
| 81 | current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x1b, 0); |
| 82 | acpi_dmar_drhd_fixup(tmp, current); |
| 83 | |
| 84 | if (stepping != STEPPING_B2) { |
| 85 | tmp = current; |
| 86 | current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE2); |
| 87 | current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x2, 0); |
| 88 | current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x2, 1); |
| 89 | acpi_dmar_drhd_fixup(tmp, current); |
| 90 | } |
| 91 | |
| 92 | if (me_active) { |
| 93 | tmp = current; |
| 94 | current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE3); |
| 95 | current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 0); |
| 96 | current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 1); |
| 97 | current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 2); |
| 98 | current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 3); |
| 99 | acpi_dmar_drhd_fixup(tmp, current); |
| 100 | } |
| 101 | |
| 102 | current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE4); |
| 103 | |
| 104 | /* TODO: reserve GTT for 0.2.0 and 0.2.1? */ |
| 105 | return current; |
| 106 | } |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 107 | |
Alexander Couzens | 83fc32f | 2015-04-12 22:28:37 +0200 | [diff] [blame] | 108 | unsigned long northbridge_write_acpi_tables(device_t device, |
| 109 | unsigned long start, |
| 110 | struct acpi_rsdp *rsdp) |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 111 | { |
| 112 | unsigned long current; |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 113 | acpi_dmar_t *dmar; |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 114 | |
| 115 | current = start; |
| 116 | |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 117 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 118 | dmar = (acpi_dmar_t *) current; |
Nico Huber | e561f35 | 2015-10-26 11:51:25 +0100 | [diff] [blame] | 119 | acpi_create_dmar(dmar, 0, acpi_fill_dmar); |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 120 | current += dmar->header.length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 121 | current = acpi_align_current(current); |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 122 | acpi_add_table(rsdp, dmar); |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 123 | |
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 | |
| 126 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 127 | |
| 128 | return current; |
| 129 | } |