blob: bdd0ed08228d9b2d625e17f11ed405bee9150108 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Patrick Georgi2efc8802012-11-06 11:03:53 +01003
4#include <types.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01005#include <console/console.h>
6#include <arch/acpi.h>
7#include <arch/acpigen.h>
8#include <device/device.h>
Elyes HAOUAS748caed2019-12-19 17:02:08 +01009#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020010#include <device/pci_ops.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010011
Patrick Georgi2efc8802012-11-06 11:03:53 +010012#include "gm45.h"
13
14unsigned long acpi_fill_mcfg(unsigned long current)
15{
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +010016 struct device *dev;
Patrick Georgi2efc8802012-11-06 11:03:53 +010017 u32 pciexbar = 0;
18 u32 pciexbar_reg;
19 int max_buses;
20
21 dev = dev_find_device(0x8086, 0x2a40, 0);
22 if (!dev)
23 return current;
24
25 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
26
27 // MMCFG not supported or not enabled.
28 if (!(pciexbar_reg & (1 << 0)))
29 return current;
30
31 switch ((pciexbar_reg >> 1) & 3) {
32 case 0: // 256MB
33 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
34 max_buses = 256;
35 break;
36 case 1: // 128M
37 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
38 max_buses = 128;
39 break;
40 case 2: // 64M
41 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
42 max_buses = 64;
43 break;
44 default: // RSVD
45 return current;
46 }
47
48 if (!pciexbar)
49 return current;
50
51 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
52 pciexbar, 0x0, 0x0, max_buses - 1);
53
54 return current;
55}
56
Vladimir Serbinenko8d70e942014-11-09 13:22:27 +010057static unsigned long acpi_fill_dmar(unsigned long current)
Patrick Georgi2efc8802012-11-06 11:03:53 +010058{
Arthur Heymans15063e82019-08-12 09:41:42 +020059 const struct device *dev;
60
61 dev = pcidev_on_root(3, 0);
62 int me_active = dev && dev->enabled;
63
Arthur Heymans08456362019-08-12 09:21:30 +020064 dev = pcidev_on_root(2, 0);
65 int igd_active = dev && dev->enabled;
66
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030067 int stepping = pci_read_config8(pcidev_on_root(0, 0),
68 PCI_CLASS_REVISION);
Patrick Georgi2efc8802012-11-06 11:03:53 +010069
70 unsigned long tmp = current;
71 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1);
Matt DeVillier7866d492018-03-29 14:59:57 +020072 current += acpi_create_dmar_ds_pci(current, 0, 0x1b, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010073 acpi_dmar_drhd_fixup(tmp, current);
74
Arthur Heymans08456362019-08-12 09:21:30 +020075 if (stepping != STEPPING_B2 && igd_active) {
Patrick Georgi2efc8802012-11-06 11:03:53 +010076 tmp = current;
77 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE2);
Matt DeVillier7866d492018-03-29 14:59:57 +020078 current += acpi_create_dmar_ds_pci(current, 0, 0x2, 0);
79 current += acpi_create_dmar_ds_pci(current, 0, 0x2, 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +010080 acpi_dmar_drhd_fixup(tmp, current);
81 }
82
83 if (me_active) {
84 tmp = current;
85 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE3);
Matt DeVillier7866d492018-03-29 14:59:57 +020086 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 0);
87 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 1);
88 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 2);
89 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 3);
Patrick Georgi2efc8802012-11-06 11:03:53 +010090 acpi_dmar_drhd_fixup(tmp, current);
91 }
92
93 current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE4);
94
95 /* TODO: reserve GTT for 0.2.0 and 0.2.1? */
96 return current;
97}
Vladimir Serbinenko33769a52014-08-30 22:39:20 +020098
Furquan Shaikh0f007d82020-04-24 06:41:18 -070099unsigned long northbridge_write_acpi_tables(const struct device *device,
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200100 unsigned long start,
101 struct acpi_rsdp *rsdp)
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200102{
103 unsigned long current;
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200104 acpi_dmar_t *dmar;
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200105
106 current = start;
107
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200108 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
109 dmar = (acpi_dmar_t *) current;
Nico Hubere561f352015-10-26 11:51:25 +0100110 acpi_create_dmar(dmar, 0, acpi_fill_dmar);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200111 current += dmar->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600112 current = acpi_align_current(current);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200113 acpi_add_table(rsdp, dmar);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200114
Aaron Durbin07a1b282015-12-10 17:07:38 -0600115 current = acpi_align_current(current);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200116
117 printk(BIOS_DEBUG, "current = %lx\n", current);
118
119 return current;
120}