blob: f8204ffbc3849641849edb118afcf8e6c19d2185 [file] [log] [blame]
Raul E Rangel789aefc2020-05-11 16:26:35 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
Furquan Shaikh0c707d42020-07-08 16:54:40 -07003#include <acpi/acpi_device.h>
Felix Helddba3fe72021-02-13 01:05:56 +01004#include <amdblocks/data_fabric.h>
Raul E Rangel789aefc2020-05-11 16:26:35 -06005#include <console/console.h>
6#include <cpu/x86/lapic_def.h>
Furquan Shaikh0c707d42020-07-08 16:54:40 -07007#include <device/device.h>
8#include <device/pci.h>
9#include <device/pci_ids.h>
Raul E Rangel789aefc2020-05-11 16:26:35 -060010#include <soc/data_fabric.h>
11#include <soc/iomap.h>
Felix Heldbf90b142020-09-15 16:19:54 +020012#include <types.h>
Raul E Rangel789aefc2020-05-11 16:26:35 -060013
Raul E Rangel789aefc2020-05-11 16:26:35 -060014void data_fabric_set_mmio_np(void)
15{
16 /*
17 * Mark region from HPET-LAPIC or 0xfed00000-0xfee00000-1 as NP.
18 *
19 * AGESA has already programmed the NB MMIO routing, however nothing
20 * is yet marked as non-posted.
21 *
22 * If there exists an overlapping routing base/limit pair, trim its
23 * base or limit to avoid the new NP region. If any pair exists
24 * completely within HPET-LAPIC range, remove it. If any pair surrounds
25 * HPET-LAPIC, it must be split into two regions.
26 *
27 * TODO(b/156296146): Remove the settings from AGESA and allow coreboot
28 * to own everything. If not practical, consider erasing all settings
29 * and have coreboot reprogram them. At that time, make the source
30 * below more flexible.
31 * * Note that the code relies on the granularity of the HPET and
32 * LAPIC addresses being sufficiently large that the shifted limits
33 * +/-1 are always equivalent to the non-shifted values +/-1.
34 */
35
36 unsigned int i;
37 int reg;
38 uint32_t base, limit, ctrl;
39 const uint32_t np_bot = HPET_BASE_ADDRESS >> D18F0_MMIO_SHIFT;
Kyösti Mälkkidea42e02021-05-31 20:26:16 +030040 const uint32_t np_top = (LAPIC_DEFAULT_BASE - 1) >> D18F0_MMIO_SHIFT;
Raul E Rangel789aefc2020-05-11 16:26:35 -060041
Felix Held906f9be2021-02-13 20:38:08 +010042 data_fabric_print_mmio_conf();
43
Raul E Rangel789aefc2020-05-11 16:26:35 -060044 for (i = 0; i < NUM_NB_MMIO_REGS; i++) {
45 /* Adjust all registers that overlap */
Felix Held0a149132021-02-13 01:22:39 +010046 ctrl = data_fabric_broadcast_read32(0, NB_MMIO_CONTROL(i));
Felix Heldd560ad62021-11-24 11:44:50 +010047 if (!(ctrl & (DF_MMIO_WE | DF_MMIO_RE)))
Raul E Rangel789aefc2020-05-11 16:26:35 -060048 continue; /* not enabled */
49
Felix Held0a149132021-02-13 01:22:39 +010050 base = data_fabric_broadcast_read32(0, NB_MMIO_BASE(i));
51 limit = data_fabric_broadcast_read32(0, NB_MMIO_LIMIT(i));
Raul E Rangel789aefc2020-05-11 16:26:35 -060052
53 if (base > np_top || limit < np_bot)
54 continue; /* no overlap at all */
55
56 if (base >= np_bot && limit <= np_top) {
Felix Held602f93e2021-02-13 21:10:08 +010057 data_fabric_disable_mmio_reg(i); /* 100% within, so remove */
Raul E Rangel789aefc2020-05-11 16:26:35 -060058 continue;
59 }
60
61 if (base < np_bot && limit > np_top) {
62 /* Split the configured region */
Felix Held0a149132021-02-13 01:22:39 +010063 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(i), np_bot - 1);
Felix Held602f93e2021-02-13 21:10:08 +010064 reg = data_fabric_find_unused_mmio_reg();
Raul E Rangel789aefc2020-05-11 16:26:35 -060065 if (reg < 0) {
66 /* Although a pair could be freed later, this condition is
67 * very unusual and deserves analysis. Flag an error and
68 * leave the topmost part unconfigured. */
Julius Wernere9665952022-01-21 17:06:20 -080069 printk(BIOS_ERR, "Not enough NB MMIO routing registers\n");
Raul E Rangel789aefc2020-05-11 16:26:35 -060070 continue;
71 }
Felix Held0a149132021-02-13 01:22:39 +010072 data_fabric_broadcast_write32(0, NB_MMIO_BASE(reg), np_top + 1);
73 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(reg), limit);
74 data_fabric_broadcast_write32(0, NB_MMIO_CONTROL(reg), ctrl);
Raul E Rangel789aefc2020-05-11 16:26:35 -060075 continue;
76 }
77
78 /* If still here, adjust only the base or limit */
79 if (base <= np_bot)
Felix Held0a149132021-02-13 01:22:39 +010080 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(i), np_bot - 1);
Raul E Rangel789aefc2020-05-11 16:26:35 -060081 else
Felix Held0a149132021-02-13 01:22:39 +010082 data_fabric_broadcast_write32(0, NB_MMIO_BASE(i), np_top + 1);
Raul E Rangel789aefc2020-05-11 16:26:35 -060083 }
84
Felix Held602f93e2021-02-13 21:10:08 +010085 reg = data_fabric_find_unused_mmio_reg();
Raul E Rangel789aefc2020-05-11 16:26:35 -060086 if (reg < 0) {
Julius Wernere9665952022-01-21 17:06:20 -080087 printk(BIOS_ERR, "cannot configure region as NP\n");
Raul E Rangel789aefc2020-05-11 16:26:35 -060088 return;
89 }
90
Felix Held0a149132021-02-13 01:22:39 +010091 data_fabric_broadcast_write32(0, NB_MMIO_BASE(reg), np_bot);
92 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(reg), np_top);
93 data_fabric_broadcast_write32(0, NB_MMIO_CONTROL(reg),
Felix Heldd560ad62021-11-24 11:44:50 +010094 (IOMS0_FABRIC_ID << DF_MMIO_DST_FABRIC_ID_SHIFT) | DF_MMIO_NP
95 | DF_MMIO_WE | DF_MMIO_RE);
Felix Held906f9be2021-02-13 20:38:08 +010096
97 data_fabric_print_mmio_conf();
Raul E Rangel789aefc2020-05-11 16:26:35 -060098}
Furquan Shaikh0c707d42020-07-08 16:54:40 -070099
100static const char *data_fabric_acpi_name(const struct device *dev)
101{
102 switch (dev->device) {
Felix Held0e5dde5d2020-11-17 14:57:40 +0100103 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF0:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700104 return "DFD0";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100105 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF1:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700106 return "DFD1";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100107 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF2:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700108 return "DFD2";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100109 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF3:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700110 return "DFD3";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100111 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF4:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700112 return "DFD4";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100113 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF5:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700114 return "DFD5";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100115 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF6:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700116 return "DFD6";
Felix Held0151b462021-02-23 17:08:44 +0100117 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF7:
118 return "DFD7";
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700119 default:
120 printk(BIOS_ERR, "%s: Unhandled device id 0x%x\n", __func__, dev->device);
121 }
122
123 return NULL;
124}
125
126static struct device_operations data_fabric_ops = {
127 .read_resources = noop_read_resources,
128 .set_resources = noop_set_resources,
129 .acpi_name = data_fabric_acpi_name,
130 .acpi_fill_ssdt = acpi_device_write_pci_dev,
131};
132
133static const unsigned short pci_device_ids[] = {
Felix Held0e5dde5d2020-11-17 14:57:40 +0100134 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF0,
135 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF1,
136 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF2,
137 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF3,
138 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF4,
139 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF5,
140 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF6,
Felix Held0151b462021-02-23 17:08:44 +0100141 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF7,
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700142 0
143};
144
145static const struct pci_driver data_fabric_driver __pci_driver = {
146 .ops = &data_fabric_ops,
147 .vendor = PCI_VENDOR_ID_AMD,
148 .devices = pci_device_ids,
149};