blob: aec8a9e626cf965db8675e2f45ad69c2d3bce03b [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. */
69 printk(BIOS_ERR,
70 "Error: Not enough NB MMIO routing registers\n");
71 continue;
72 }
Felix Held0a149132021-02-13 01:22:39 +010073 data_fabric_broadcast_write32(0, NB_MMIO_BASE(reg), np_top + 1);
74 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(reg), limit);
75 data_fabric_broadcast_write32(0, NB_MMIO_CONTROL(reg), ctrl);
Raul E Rangel789aefc2020-05-11 16:26:35 -060076 continue;
77 }
78
79 /* If still here, adjust only the base or limit */
80 if (base <= np_bot)
Felix Held0a149132021-02-13 01:22:39 +010081 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(i), np_bot - 1);
Raul E Rangel789aefc2020-05-11 16:26:35 -060082 else
Felix Held0a149132021-02-13 01:22:39 +010083 data_fabric_broadcast_write32(0, NB_MMIO_BASE(i), np_top + 1);
Raul E Rangel789aefc2020-05-11 16:26:35 -060084 }
85
Felix Held602f93e2021-02-13 21:10:08 +010086 reg = data_fabric_find_unused_mmio_reg();
Raul E Rangel789aefc2020-05-11 16:26:35 -060087 if (reg < 0) {
88 printk(BIOS_ERR, "Error: cannot configure region as NP\n");
89 return;
90 }
91
Felix Held0a149132021-02-13 01:22:39 +010092 data_fabric_broadcast_write32(0, NB_MMIO_BASE(reg), np_bot);
93 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(reg), np_top);
94 data_fabric_broadcast_write32(0, NB_MMIO_CONTROL(reg),
Felix Heldd560ad62021-11-24 11:44:50 +010095 (IOMS0_FABRIC_ID << DF_MMIO_DST_FABRIC_ID_SHIFT) | DF_MMIO_NP
96 | DF_MMIO_WE | DF_MMIO_RE);
Felix Held906f9be2021-02-13 20:38:08 +010097
98 data_fabric_print_mmio_conf();
Raul E Rangel789aefc2020-05-11 16:26:35 -060099}
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700100
101static const char *data_fabric_acpi_name(const struct device *dev)
102{
103 switch (dev->device) {
Felix Held0e5dde5d2020-11-17 14:57:40 +0100104 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF0:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700105 return "DFD0";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100106 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF1:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700107 return "DFD1";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100108 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF2:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700109 return "DFD2";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100110 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF3:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700111 return "DFD3";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100112 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF4:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700113 return "DFD4";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100114 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF5:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700115 return "DFD5";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100116 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF6:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700117 return "DFD6";
Felix Held0151b462021-02-23 17:08:44 +0100118 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF7:
119 return "DFD7";
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700120 default:
121 printk(BIOS_ERR, "%s: Unhandled device id 0x%x\n", __func__, dev->device);
122 }
123
124 return NULL;
125}
126
127static struct device_operations data_fabric_ops = {
128 .read_resources = noop_read_resources,
129 .set_resources = noop_set_resources,
130 .acpi_name = data_fabric_acpi_name,
131 .acpi_fill_ssdt = acpi_device_write_pci_dev,
132};
133
134static const unsigned short pci_device_ids[] = {
Felix Held0e5dde5d2020-11-17 14:57:40 +0100135 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF0,
136 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF1,
137 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF2,
138 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF3,
139 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF4,
140 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF5,
141 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF6,
Felix Held0151b462021-02-23 17:08:44 +0100142 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF7,
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700143 0
144};
145
146static const struct pci_driver data_fabric_driver __pci_driver = {
147 .ops = &data_fabric_ops,
148 .vendor = PCI_VENDOR_ID_AMD,
149 .devices = pci_device_ids,
150};