blob: d07555a43720e5e45e2920c1047bbb69ac6494f6 [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;
40 const uint32_t np_top = (LOCAL_APIC_ADDR - 1) >> D18F0_MMIO_SHIFT;
41
42 for (i = 0; i < NUM_NB_MMIO_REGS; i++) {
43 /* Adjust all registers that overlap */
Felix Held0a149132021-02-13 01:22:39 +010044 ctrl = data_fabric_broadcast_read32(0, NB_MMIO_CONTROL(i));
Raul E Rangel789aefc2020-05-11 16:26:35 -060045 if (!(ctrl & (MMIO_WE | MMIO_RE)))
46 continue; /* not enabled */
47
Felix Held0a149132021-02-13 01:22:39 +010048 base = data_fabric_broadcast_read32(0, NB_MMIO_BASE(i));
49 limit = data_fabric_broadcast_read32(0, NB_MMIO_LIMIT(i));
Raul E Rangel789aefc2020-05-11 16:26:35 -060050
51 if (base > np_top || limit < np_bot)
52 continue; /* no overlap at all */
53
54 if (base >= np_bot && limit <= np_top) {
Felix Held602f93e2021-02-13 21:10:08 +010055 data_fabric_disable_mmio_reg(i); /* 100% within, so remove */
Raul E Rangel789aefc2020-05-11 16:26:35 -060056 continue;
57 }
58
59 if (base < np_bot && limit > np_top) {
60 /* Split the configured region */
Felix Held0a149132021-02-13 01:22:39 +010061 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(i), np_bot - 1);
Felix Held602f93e2021-02-13 21:10:08 +010062 reg = data_fabric_find_unused_mmio_reg();
Raul E Rangel789aefc2020-05-11 16:26:35 -060063 if (reg < 0) {
64 /* Although a pair could be freed later, this condition is
65 * very unusual and deserves analysis. Flag an error and
66 * leave the topmost part unconfigured. */
67 printk(BIOS_ERR,
68 "Error: Not enough NB MMIO routing registers\n");
69 continue;
70 }
Felix Held0a149132021-02-13 01:22:39 +010071 data_fabric_broadcast_write32(0, NB_MMIO_BASE(reg), np_top + 1);
72 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(reg), limit);
73 data_fabric_broadcast_write32(0, NB_MMIO_CONTROL(reg), ctrl);
Raul E Rangel789aefc2020-05-11 16:26:35 -060074 continue;
75 }
76
77 /* If still here, adjust only the base or limit */
78 if (base <= np_bot)
Felix Held0a149132021-02-13 01:22:39 +010079 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(i), np_bot - 1);
Raul E Rangel789aefc2020-05-11 16:26:35 -060080 else
Felix Held0a149132021-02-13 01:22:39 +010081 data_fabric_broadcast_write32(0, NB_MMIO_BASE(i), np_top + 1);
Raul E Rangel789aefc2020-05-11 16:26:35 -060082 }
83
Felix Held602f93e2021-02-13 21:10:08 +010084 reg = data_fabric_find_unused_mmio_reg();
Raul E Rangel789aefc2020-05-11 16:26:35 -060085 if (reg < 0) {
86 printk(BIOS_ERR, "Error: cannot configure region as NP\n");
87 return;
88 }
89
Felix Held0a149132021-02-13 01:22:39 +010090 data_fabric_broadcast_write32(0, NB_MMIO_BASE(reg), np_bot);
91 data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(reg), np_top);
92 data_fabric_broadcast_write32(0, NB_MMIO_CONTROL(reg),
Raul E Rangel789aefc2020-05-11 16:26:35 -060093 (IOMS0_FABRIC_ID << MMIO_DST_FABRIC_ID_SHIFT) | MMIO_NP | MMIO_WE
94 | MMIO_RE);
95}
Furquan Shaikh0c707d42020-07-08 16:54:40 -070096
97static const char *data_fabric_acpi_name(const struct device *dev)
98{
99 switch (dev->device) {
Felix Held0e5dde5d2020-11-17 14:57:40 +0100100 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF0:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700101 return "DFD0";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100102 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF1:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700103 return "DFD1";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100104 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF2:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700105 return "DFD2";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100106 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF3:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700107 return "DFD3";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100108 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF4:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700109 return "DFD4";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100110 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF5:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700111 return "DFD5";
Felix Held0e5dde5d2020-11-17 14:57:40 +0100112 case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF6:
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700113 return "DFD6";
114 default:
115 printk(BIOS_ERR, "%s: Unhandled device id 0x%x\n", __func__, dev->device);
116 }
117
118 return NULL;
119}
120
121static struct device_operations data_fabric_ops = {
122 .read_resources = noop_read_resources,
123 .set_resources = noop_set_resources,
124 .acpi_name = data_fabric_acpi_name,
125 .acpi_fill_ssdt = acpi_device_write_pci_dev,
126};
127
128static const unsigned short pci_device_ids[] = {
Felix Held0e5dde5d2020-11-17 14:57:40 +0100129 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF0,
130 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF1,
131 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF2,
132 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF3,
133 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF4,
134 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF5,
135 PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF6,
Furquan Shaikh0c707d42020-07-08 16:54:40 -0700136 0
137};
138
139static const struct pci_driver data_fabric_driver __pci_driver = {
140 .ops = &data_fabric_ops,
141 .vendor = PCI_VENDOR_ID_AMD,
142 .devices = pci_device_ids,
143};