Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
Felix Held | dba3fe7 | 2021-02-13 01:05:56 +0100 | [diff] [blame] | 4 | #include <amdblocks/data_fabric.h> |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <cpu/x86/lapic_def.h> |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 7 | #include <device/device.h> |
| 8 | #include <device/pci.h> |
| 9 | #include <device/pci_ids.h> |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 10 | #include <soc/data_fabric.h> |
| 11 | #include <soc/iomap.h> |
Felix Held | bf90b14 | 2020-09-15 16:19:54 +0200 | [diff] [blame] | 12 | #include <types.h> |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 13 | |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 14 | void 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 | |
Felix Held | 906f9be | 2021-02-13 20:38:08 +0100 | [diff] [blame] | 42 | data_fabric_print_mmio_conf(); |
| 43 | |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 44 | for (i = 0; i < NUM_NB_MMIO_REGS; i++) { |
| 45 | /* Adjust all registers that overlap */ |
Felix Held | 0a14913 | 2021-02-13 01:22:39 +0100 | [diff] [blame] | 46 | ctrl = data_fabric_broadcast_read32(0, NB_MMIO_CONTROL(i)); |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 47 | if (!(ctrl & (MMIO_WE | MMIO_RE))) |
| 48 | continue; /* not enabled */ |
| 49 | |
Felix Held | 0a14913 | 2021-02-13 01:22:39 +0100 | [diff] [blame] | 50 | base = data_fabric_broadcast_read32(0, NB_MMIO_BASE(i)); |
| 51 | limit = data_fabric_broadcast_read32(0, NB_MMIO_LIMIT(i)); |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 52 | |
| 53 | if (base > np_top || limit < np_bot) |
| 54 | continue; /* no overlap at all */ |
| 55 | |
| 56 | if (base >= np_bot && limit <= np_top) { |
Felix Held | 602f93e | 2021-02-13 21:10:08 +0100 | [diff] [blame] | 57 | data_fabric_disable_mmio_reg(i); /* 100% within, so remove */ |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 58 | continue; |
| 59 | } |
| 60 | |
| 61 | if (base < np_bot && limit > np_top) { |
| 62 | /* Split the configured region */ |
Felix Held | 0a14913 | 2021-02-13 01:22:39 +0100 | [diff] [blame] | 63 | data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(i), np_bot - 1); |
Felix Held | 602f93e | 2021-02-13 21:10:08 +0100 | [diff] [blame] | 64 | reg = data_fabric_find_unused_mmio_reg(); |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 65 | 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 Held | 0a14913 | 2021-02-13 01:22:39 +0100 | [diff] [blame] | 73 | 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 Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 76 | continue; |
| 77 | } |
| 78 | |
| 79 | /* If still here, adjust only the base or limit */ |
| 80 | if (base <= np_bot) |
Felix Held | 0a14913 | 2021-02-13 01:22:39 +0100 | [diff] [blame] | 81 | data_fabric_broadcast_write32(0, NB_MMIO_LIMIT(i), np_bot - 1); |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 82 | else |
Felix Held | 0a14913 | 2021-02-13 01:22:39 +0100 | [diff] [blame] | 83 | data_fabric_broadcast_write32(0, NB_MMIO_BASE(i), np_top + 1); |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 84 | } |
| 85 | |
Felix Held | 602f93e | 2021-02-13 21:10:08 +0100 | [diff] [blame] | 86 | reg = data_fabric_find_unused_mmio_reg(); |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 87 | if (reg < 0) { |
| 88 | printk(BIOS_ERR, "Error: cannot configure region as NP\n"); |
| 89 | return; |
| 90 | } |
| 91 | |
Felix Held | 0a14913 | 2021-02-13 01:22:39 +0100 | [diff] [blame] | 92 | 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), |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 95 | (IOMS0_FABRIC_ID << MMIO_DST_FABRIC_ID_SHIFT) | MMIO_NP | MMIO_WE |
| 96 | | MMIO_RE); |
Felix Held | 906f9be | 2021-02-13 20:38:08 +0100 | [diff] [blame] | 97 | |
| 98 | data_fabric_print_mmio_conf(); |
Raul E Rangel | 789aefc | 2020-05-11 16:26:35 -0600 | [diff] [blame] | 99 | } |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 100 | |
| 101 | static const char *data_fabric_acpi_name(const struct device *dev) |
| 102 | { |
| 103 | switch (dev->device) { |
Felix Held | 0e5dde5d | 2020-11-17 14:57:40 +0100 | [diff] [blame] | 104 | case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF0: |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 105 | return "DFD0"; |
Felix Held | 0e5dde5d | 2020-11-17 14:57:40 +0100 | [diff] [blame] | 106 | case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF1: |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 107 | return "DFD1"; |
Felix Held | 0e5dde5d | 2020-11-17 14:57:40 +0100 | [diff] [blame] | 108 | case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF2: |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 109 | return "DFD2"; |
Felix Held | 0e5dde5d | 2020-11-17 14:57:40 +0100 | [diff] [blame] | 110 | case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF3: |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 111 | return "DFD3"; |
Felix Held | 0e5dde5d | 2020-11-17 14:57:40 +0100 | [diff] [blame] | 112 | case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF4: |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 113 | return "DFD4"; |
Felix Held | 0e5dde5d | 2020-11-17 14:57:40 +0100 | [diff] [blame] | 114 | case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF5: |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 115 | return "DFD5"; |
Felix Held | 0e5dde5d | 2020-11-17 14:57:40 +0100 | [diff] [blame] | 116 | case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF6: |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 117 | return "DFD6"; |
Felix Held | 0151b46 | 2021-02-23 17:08:44 +0100 | [diff] [blame^] | 118 | case PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF7: |
| 119 | return "DFD7"; |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 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 = { |
| 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 | |
| 134 | static const unsigned short pci_device_ids[] = { |
Felix Held | 0e5dde5d | 2020-11-17 14:57:40 +0100 | [diff] [blame] | 135 | 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 Held | 0151b46 | 2021-02-23 17:08:44 +0100 | [diff] [blame^] | 142 | PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_DF7, |
Furquan Shaikh | 0c707d4 | 2020-07-08 16:54:40 -0700 | [diff] [blame] | 143 | 0 |
| 144 | }; |
| 145 | |
| 146 | static 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 | }; |