Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | /* TODO: Check if this is still correct */ |
| 4 | |
| 5 | #include <acpi/acpi_device.h> |
| 6 | #include <amdblocks/data_fabric.h> |
Felix Held | 4b2464f | 2022-02-23 17:54:20 +0100 | [diff] [blame] | 7 | #include <arch/hpet.h> |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 8 | #include <console/console.h> |
| 9 | #include <cpu/x86/lapic_def.h> |
| 10 | #include <device/device.h> |
| 11 | #include <device/pci.h> |
| 12 | #include <device/pci_ids.h> |
| 13 | #include <soc/data_fabric.h> |
| 14 | #include <soc/iomap.h> |
| 15 | #include <types.h> |
| 16 | |
| 17 | void data_fabric_set_mmio_np(void) |
| 18 | { |
| 19 | /* |
| 20 | * Mark region from HPET-LAPIC or 0xfed00000-0xfee00000-1 as NP. |
| 21 | * |
| 22 | * AGESA has already programmed the NB MMIO routing, however nothing |
| 23 | * is yet marked as non-posted. |
| 24 | * |
| 25 | * If there exists an overlapping routing base/limit pair, trim its |
| 26 | * base or limit to avoid the new NP region. If any pair exists |
| 27 | * completely within HPET-LAPIC range, remove it. If any pair surrounds |
| 28 | * HPET-LAPIC, it must be split into two regions. |
| 29 | * |
| 30 | * TODO(b/156296146): Remove the settings from AGESA and allow coreboot |
| 31 | * to own everything. If not practical, consider erasing all settings |
| 32 | * and have coreboot reprogram them. At that time, make the source |
| 33 | * below more flexible. |
| 34 | * * Note that the code relies on the granularity of the HPET and |
| 35 | * LAPIC addresses being sufficiently large that the shifted limits |
| 36 | * +/-1 are always equivalent to the non-shifted values +/-1. |
| 37 | */ |
| 38 | |
| 39 | unsigned int i; |
| 40 | int reg; |
| 41 | uint32_t base, limit, ctrl; |
| 42 | const uint32_t np_bot = HPET_BASE_ADDRESS >> D18F0_MMIO_SHIFT; |
| 43 | const uint32_t np_top = (LAPIC_DEFAULT_BASE - 1) >> D18F0_MMIO_SHIFT; |
| 44 | |
| 45 | data_fabric_print_mmio_conf(); |
| 46 | |
| 47 | for (i = 0; i < NUM_NB_MMIO_REGS; i++) { |
| 48 | /* Adjust all registers that overlap */ |
| 49 | ctrl = data_fabric_broadcast_read32(0, NB_MMIO_CONTROL(i)); |
| 50 | if (!(ctrl & (DF_MMIO_WE | DF_MMIO_RE))) |
| 51 | continue; /* not enabled */ |
| 52 | |
| 53 | base = data_fabric_broadcast_read32(0, NB_MMIO_BASE(i)); |
| 54 | limit = data_fabric_broadcast_read32(0, NB_MMIO_LIMIT(i)); |
| 55 | |
| 56 | if (base > np_top || limit < np_bot) |
| 57 | continue; /* no overlap at all */ |
| 58 | |
| 59 | if (base >= np_bot && limit <= np_top) { |
| 60 | data_fabric_disable_mmio_reg(i); /* 100% within, so remove */ |
| 61 | continue; |
| 62 | } |
| 63 | |
| 64 | if (base < np_bot && limit > np_top) { |
| 65 | /* Split the configured region */ |
| 66 | data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(i), np_bot - 1); |
| 67 | reg = data_fabric_find_unused_mmio_reg(); |
| 68 | if (reg < 0) { |
| 69 | /* Although a pair could be freed later, this condition is |
| 70 | * very unusual and deserves analysis. Flag an error and |
| 71 | * leave the topmost part unconfigured. */ |
| 72 | printk(BIOS_ERR, |
| 73 | "Error: Not enough NB MMIO routing registers\n"); |
| 74 | continue; |
| 75 | } |
| 76 | data_fabric_broadcast_write32(0, NB_MMIO_BASE(reg), np_top + 1); |
| 77 | data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(reg), limit); |
| 78 | data_fabric_broadcast_write32(0, NB_MMIO_CONTROL(reg), ctrl); |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | /* If still here, adjust only the base or limit */ |
| 83 | if (base <= np_bot) |
| 84 | data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(i), np_bot - 1); |
| 85 | else |
| 86 | data_fabric_broadcast_write32(0, NB_MMIO_BASE(i), np_top + 1); |
| 87 | } |
| 88 | |
| 89 | reg = data_fabric_find_unused_mmio_reg(); |
| 90 | if (reg < 0) { |
| 91 | printk(BIOS_ERR, "Error: cannot configure region as NP\n"); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | data_fabric_broadcast_write32(0, NB_MMIO_BASE(reg), np_bot); |
| 96 | data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(reg), np_top); |
| 97 | data_fabric_broadcast_write32(0, NB_MMIO_CONTROL(reg), |
| 98 | (IOMS0_FABRIC_ID << DF_MMIO_DST_FABRIC_ID_SHIFT) | DF_MMIO_NP |
| 99 | | DF_MMIO_WE | DF_MMIO_RE); |
| 100 | |
| 101 | data_fabric_print_mmio_conf(); |
| 102 | } |
| 103 | |
| 104 | static const char *data_fabric_acpi_name(const struct device *dev) |
| 105 | { |
| 106 | switch (dev->device) { |
Felix Held | af356d3 | 2022-01-11 16:39:44 +0100 | [diff] [blame] | 107 | case PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF0: |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 108 | return "DFD0"; |
Felix Held | af356d3 | 2022-01-11 16:39:44 +0100 | [diff] [blame] | 109 | case PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF1: |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 110 | return "DFD1"; |
Felix Held | af356d3 | 2022-01-11 16:39:44 +0100 | [diff] [blame] | 111 | case PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF2: |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 112 | return "DFD2"; |
Felix Held | af356d3 | 2022-01-11 16:39:44 +0100 | [diff] [blame] | 113 | case PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF3: |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 114 | return "DFD3"; |
Felix Held | af356d3 | 2022-01-11 16:39:44 +0100 | [diff] [blame] | 115 | case PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF4: |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 116 | return "DFD4"; |
Felix Held | af356d3 | 2022-01-11 16:39:44 +0100 | [diff] [blame] | 117 | case PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF5: |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 118 | return "DFD5"; |
Felix Held | af356d3 | 2022-01-11 16:39:44 +0100 | [diff] [blame] | 119 | case PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF6: |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 120 | return "DFD6"; |
Felix Held | af356d3 | 2022-01-11 16:39:44 +0100 | [diff] [blame] | 121 | case PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF7: |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 122 | return "DFD7"; |
| 123 | default: |
| 124 | printk(BIOS_ERR, "%s: Unhandled device id 0x%x\n", __func__, dev->device); |
| 125 | } |
| 126 | |
| 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | static struct device_operations data_fabric_ops = { |
| 131 | .read_resources = noop_read_resources, |
| 132 | .set_resources = noop_set_resources, |
| 133 | .acpi_name = data_fabric_acpi_name, |
| 134 | .acpi_fill_ssdt = acpi_device_write_pci_dev, |
| 135 | }; |
| 136 | |
| 137 | static const unsigned short pci_device_ids[] = { |
Felix Held | af356d3 | 2022-01-11 16:39:44 +0100 | [diff] [blame] | 138 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF0, |
| 139 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF1, |
| 140 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF2, |
| 141 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF3, |
| 142 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF4, |
| 143 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF5, |
| 144 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF6, |
| 145 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_DF7, |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 146 | 0 |
| 147 | }; |
| 148 | |
| 149 | static const struct pci_driver data_fabric_driver __pci_driver = { |
| 150 | .ops = &data_fabric_ops, |
| 151 | .vendor = PCI_VENDOR_ID_AMD, |
| 152 | .devices = pci_device_ids, |
| 153 | }; |