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> |
| 20 | #include <arch/acpi.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pci_ids.h> |
| 24 | #include "sandybridge.h" |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 25 | #include <southbridge/intel/bd82x6x/pch.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 26 | |
| 27 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 28 | { |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 29 | u32 pciexbar = 0; |
| 30 | u32 pciexbar_reg; |
| 31 | int max_buses; |
| 32 | |
Vagiz Trakhanov | e200c1c | 2017-09-28 15:01:06 +0000 | [diff] [blame] | 33 | struct device *const dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 34 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 35 | if (!dev) |
| 36 | return current; |
| 37 | |
| 38 | pciexbar_reg=pci_read_config32(dev, PCIEXBAR); |
| 39 | |
| 40 | // MMCFG not supported or not enabled. |
| 41 | if (!(pciexbar_reg & (1 << 0))) |
| 42 | return current; |
| 43 | |
| 44 | switch ((pciexbar_reg >> 1) & 3) { |
| 45 | case 0: // 256MB |
| 46 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)); |
| 47 | max_buses = 256; |
| 48 | break; |
| 49 | case 1: // 128M |
| 50 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); |
| 51 | max_buses = 128; |
| 52 | break; |
| 53 | case 2: // 64M |
| 54 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26)); |
| 55 | max_buses = 64; |
| 56 | break; |
| 57 | default: // RSVD |
| 58 | return current; |
| 59 | } |
| 60 | |
| 61 | if (!pciexbar) |
| 62 | return current; |
| 63 | |
| 64 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, |
| 65 | pciexbar, 0x0, 0x0, max_buses - 1); |
| 66 | |
| 67 | return current; |
| 68 | } |
| 69 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 70 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 71 | { |
| 72 | const struct device *const igfx = dev_find_slot(0, PCI_DEVFN(2, 0)); |
| 73 | |
| 74 | if (igfx && igfx->enabled) { |
| 75 | const unsigned long tmp = current; |
| 76 | current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame^] | 77 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
| 78 | current += acpi_create_dmar_ds_pci(current, 0, 2, 1); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 79 | acpi_dmar_drhd_fixup(tmp, current); |
| 80 | } |
| 81 | |
| 82 | const unsigned long tmp = current; |
| 83 | current += acpi_create_dmar_drhd(current, |
| 84 | DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE2); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame^] | 85 | current += acpi_create_dmar_ds_ioapic(current, |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 86 | 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0); |
| 87 | size_t i; |
| 88 | for (i = 0; i < 8; ++i) |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame^] | 89 | current += acpi_create_dmar_ds_msi_hpet(current, |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 90 | 0, PCH_HPET_PCI_BUS, PCH_HPET_PCI_SLOT, i); |
| 91 | acpi_dmar_drhd_fixup(tmp, current); |
| 92 | |
| 93 | return current; |
| 94 | } |
| 95 | |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 96 | unsigned long northbridge_write_acpi_tables(struct device *const dev, |
| 97 | unsigned long current, |
| 98 | struct acpi_rsdp *const rsdp) |
| 99 | { |
| 100 | const u32 capid0_a = pci_read_config32(dev, 0xe4); |
| 101 | if (capid0_a & (1 << 23)) |
| 102 | return current; |
| 103 | |
| 104 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 105 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 106 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 107 | current += dmar->header.length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 108 | current = acpi_align_current(current); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 109 | acpi_add_table(rsdp, dmar); |
| 110 | |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 111 | current = acpi_align_current(current); |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 112 | |
| 113 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 114 | |
| 115 | return current; |
| 116 | } |