coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
data_fabric.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi_device.h>
5 #include <arch/hpet.h>
6 #include <console/console.h>
7 #include <cpu/x86/lapic_def.h>
8 #include <device/device.h>
9 #include <device/pci.h>
10 #include <device/pci_ids.h>
11 #include <soc/data_fabric.h>
12 #include <soc/iomap.h>
13 #include <types.h>
14 
16 {
17  /*
18  * Mark region from HPET-LAPIC or 0xfed00000-0xfee00000-1 as NP.
19  *
20  * AGESA has already programmed the NB MMIO routing, however nothing
21  * is yet marked as non-posted.
22  *
23  * If there exists an overlapping routing base/limit pair, trim its
24  * base or limit to avoid the new NP region. If any pair exists
25  * completely within HPET-LAPIC range, remove it. If any pair surrounds
26  * HPET-LAPIC, it must be split into two regions.
27  *
28  * TODO(b/156296146): Remove the settings from AGESA and allow coreboot
29  * to own everything. If not practical, consider erasing all settings
30  * and have coreboot reprogram them. At that time, make the source
31  * below more flexible.
32  * * Note that the code relies on the granularity of the HPET and
33  * LAPIC addresses being sufficiently large that the shifted limits
34  * +/-1 are always equivalent to the non-shifted values +/-1.
35  */
36 
37  unsigned int i;
38  int reg;
39  uint32_t base, limit, ctrl;
41  const uint32_t np_top = (LAPIC_DEFAULT_BASE - 1) >> D18F0_MMIO_SHIFT;
42 
44 
45  for (i = 0; i < NUM_NB_MMIO_REGS; i++) {
46  /* Adjust all registers that overlap */
48  if (!(ctrl & (DF_MMIO_WE | DF_MMIO_RE)))
49  continue; /* not enabled */
50 
53 
54  if (base > np_top || limit < np_bot)
55  continue; /* no overlap at all */
56 
57  if (base >= np_bot && limit <= np_top) {
58  data_fabric_disable_mmio_reg(i); /* 100% within, so remove */
59  continue;
60  }
61 
62  if (base < np_bot && limit > np_top) {
63  /* Split the configured region */
66  if (reg < 0) {
67  /* Although a pair could be freed later, this condition is
68  * very unusual and deserves analysis. Flag an error and
69  * leave the topmost part unconfigured. */
70  printk(BIOS_ERR, "Not enough NB MMIO routing registers\n");
71  continue;
72  }
73  data_fabric_broadcast_write32(0, NB_MMIO_BASE(reg), np_top + 1);
76  continue;
77  }
78 
79  /* If still here, adjust only the base or limit */
80  if (base <= np_bot)
82  else
84  }
85 
87  if (reg < 0) {
88  printk(BIOS_ERR, "cannot configure region as NP\n");
89  return;
90  }
91 
97 
99 }
100 
101 static const char *data_fabric_acpi_name(const struct device *dev)
102 {
103  switch (dev->device) {
105  return "DFD0";
107  return "DFD1";
109  return "DFD2";
111  return "DFD3";
113  return "DFD4";
115  return "DFD5";
117  return "DFD6";
119  return "DFD7";
120  default:
121  printk(BIOS_ERR, "%s: Unhandled device id 0x%x\n", __func__, dev->device);
122  }
123 
124  return NULL;
125 }
126 
127 static struct device_operations data_fabric_ops = {
129  .set_resources = noop_set_resources,
130  .acpi_name = data_fabric_acpi_name,
131  .acpi_fill_ssdt = acpi_device_write_pci_dev,
132 };
133 
134 static const unsigned short pci_device_ids[] = {
143  0
144 };
145 
146 static const struct pci_driver data_fabric_driver __pci_driver = {
147  .ops = &data_fabric_ops,
148  .vendor = PCI_VID_AMD,
149  .devices = pci_device_ids,
150 };
void acpi_device_write_pci_dev(const struct device *dev)
Definition: device.c:1168
#define HPET_BASE_ADDRESS
Definition: hpet.h:6
void data_fabric_set_mmio_np(void)
Definition: data_fabric.c:15
#define DF_MMIO_NP
Definition: data_fabric.h:9
#define NUM_NB_MMIO_REGS
Definition: data_fabric.h:13
#define IOMS0_FABRIC_ID
Definition: data_fabric.h:11
#define NB_MMIO_CONTROL(reg)
Definition: data_fabric.h:26
#define D18F0_MMIO_SHIFT
Definition: data_fabric.h:16
#define NB_MMIO_BASE(reg)
Definition: data_fabric.h:24
static __always_inline uint32_t data_fabric_broadcast_read32(uint8_t function, uint16_t reg)
Definition: data_fabric.h:32
static __always_inline void data_fabric_broadcast_write32(uint8_t function, uint16_t reg, uint32_t data)
Definition: data_fabric.h:39
#define DF_MMIO_DST_FABRIC_ID_SHIFT
Definition: data_fabric.h:19
#define DF_MMIO_RE
Definition: data_fabric.h:21
#define DF_MMIO_WE
Definition: data_fabric.h:20
#define NB_MMIO_LIMIT(reg)
Definition: data_fabric.h:25
#define printk(level,...)
Definition: stdlib.h:16
void data_fabric_print_mmio_conf(void)
void data_fabric_disable_mmio_reg(unsigned int reg)
int data_fabric_find_unused_mmio_reg(void)
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
#define LAPIC_DEFAULT_BASE
Definition: lapic_def.h:12
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define PCI_VID_AMD
Definition: pci_ids.h:496
#define PCI_DID_AMD_FAM17H_MODEL18H_DF1
Definition: pci_ids.h:604
#define PCI_DID_AMD_FAM17H_MODEL18H_DF6
Definition: pci_ids.h:609
#define PCI_DID_AMD_FAM17H_MODEL18H_DF5
Definition: pci_ids.h:608
#define PCI_DID_AMD_FAM17H_MODEL18H_DF3
Definition: pci_ids.h:606
#define PCI_DID_AMD_FAM17H_MODEL18H_DF2
Definition: pci_ids.h:605
#define PCI_DID_AMD_FAM17H_MODEL18H_DF0
Definition: pci_ids.h:603
#define PCI_DID_AMD_FAM17H_MODEL18H_DF7
Definition: pci_ids.h:610
#define PCI_DID_AMD_FAM17H_MODEL18H_DF4
Definition: pci_ids.h:607
static const struct pci_driver data_fabric_driver __pci_driver
Definition: data_fabric.c:146
static const char * data_fabric_acpi_name(const struct device *dev)
Definition: data_fabric.c:101
static struct device_operations data_fabric_ops
Definition: data_fabric.c:127
static const unsigned short pci_device_ids[]
Definition: data_fabric.c:134
uintptr_t base
Definition: uart.c:17
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
unsigned int device
Definition: device.h:117