Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_ivrs.h> |
| 4 | #include <amdblocks/acpi.h> |
| 5 | #include <amdblocks/cpu.h> |
| 6 | #include <amdblocks/data_fabric.h> |
| 7 | #include <amdblocks/ioapic.h> |
Felix Held | 96fa6a2 | 2022-12-06 01:25:13 +0100 | [diff] [blame] | 8 | #include <arch/ioapic.h> |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 9 | #include <console/console.h> |
| 10 | #include <cpu/amd/cpuid.h> |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 11 | #include <device/device.h> |
Elyes Haouas | 8823ba1 | 2022-12-05 08:48:50 +0100 | [diff] [blame] | 12 | #include <device/mmio.h> |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 13 | #include <device/pci_def.h> |
| 14 | #include <device/pci_ops.h> |
| 15 | #include <soc/acpi.h> |
| 16 | #include <soc/data_fabric.h> |
Felix Held | 96fa6a2 | 2022-12-06 01:25:13 +0100 | [diff] [blame] | 17 | #include <soc/iomap.h> |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 18 | #include <soc/pci_devs.h> |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 19 | |
Arthur Heymans | f9ee87f | 2023-06-07 15:29:02 +0200 | [diff] [blame] | 20 | static unsigned long acpi_fill_ivrs_ioapic(unsigned long current, void *ioapic_base, |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 21 | uint16_t src_devid, uint8_t dte_setting) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 22 | { |
| 23 | ivrs_ivhd_special_t *ivhd_ioapic = (ivrs_ivhd_special_t *)current; |
| 24 | memset(ivhd_ioapic, 0, sizeof(*ivhd_ioapic)); |
| 25 | |
| 26 | ivhd_ioapic->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV; |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 27 | ivhd_ioapic->dte_setting = dte_setting; |
| 28 | ivhd_ioapic->handle = get_ioapic_id(ioapic_base); |
| 29 | ivhd_ioapic->source_dev_id = src_devid; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 30 | ivhd_ioapic->variety = IVHD_SPECIAL_DEV_IOAPIC; |
| 31 | current += sizeof(ivrs_ivhd_special_t); |
| 32 | |
| 33 | return current; |
| 34 | } |
| 35 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 36 | static unsigned long ivhd_describe_hpet(unsigned long current, uint8_t hndl, uint16_t src_devid) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 37 | { |
| 38 | ivrs_ivhd_special_t *ivhd_hpet = (ivrs_ivhd_special_t *)current; |
Felix Held | 56167c5 | 2023-06-22 23:22:19 +0200 | [diff] [blame] | 39 | memset(ivhd_hpet, 0, sizeof(*ivhd_hpet)); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 40 | |
| 41 | ivhd_hpet->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV; |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 42 | ivhd_hpet->handle = hndl; |
| 43 | ivhd_hpet->source_dev_id = src_devid; /* function 0 of FCH PCI device */ |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 44 | ivhd_hpet->variety = IVHD_SPECIAL_DEV_HPET; |
| 45 | current += sizeof(ivrs_ivhd_special_t); |
| 46 | |
| 47 | return current; |
| 48 | } |
| 49 | |
Felix Held | 534cce3 | 2023-06-22 23:09:23 +0200 | [diff] [blame] | 50 | static unsigned long ivhd_describe_f0_device(unsigned long current, uint16_t dev_id, |
| 51 | const char acpi_hid[8], uint8_t datasetting) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 52 | { |
Elyes Haouas | 68fc51f | 2022-07-16 09:48:27 +0200 | [diff] [blame] | 53 | ivrs_ivhd_f0_entry_t *ivhd_f0 = (ivrs_ivhd_f0_entry_t *)current; |
Felix Held | 63a4e6bd | 2023-06-22 23:04:19 +0200 | [diff] [blame] | 54 | memset(ivhd_f0, 0, sizeof(*ivhd_f0)); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 55 | |
| 56 | ivhd_f0->type = IVHD_DEV_VARIABLE; |
| 57 | ivhd_f0->dev_id = dev_id; |
| 58 | ivhd_f0->dte_setting = datasetting; |
Felix Held | 534cce3 | 2023-06-22 23:09:23 +0200 | [diff] [blame] | 59 | |
| 60 | memcpy(ivhd_f0->hardware_id, acpi_hid, sizeof(ivhd_f0->hardware_id)); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 61 | |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 62 | current += sizeof(ivrs_ivhd_f0_entry_t); |
| 63 | return current; |
| 64 | } |
| 65 | |
| 66 | static unsigned long ivhd_dev_range(unsigned long current, uint16_t start_devid, |
| 67 | uint16_t end_devid, uint8_t setting) |
| 68 | { |
| 69 | /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */ |
| 70 | current = ALIGN_UP(current, 4); |
| 71 | ivrs_ivhd_generic_t *ivhd_range = (ivrs_ivhd_generic_t *)current; |
Felix Held | fe242ce | 2023-06-23 19:03:57 +0200 | [diff] [blame] | 72 | memset(ivhd_range, 0, sizeof(*ivhd_range)); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 73 | |
| 74 | /* Create the start range IVHD entry */ |
| 75 | ivhd_range->type = IVHD_DEV_4_BYTE_START_RANGE; |
| 76 | ivhd_range->dev_id = start_devid; |
| 77 | ivhd_range->dte_setting = setting; |
| 78 | current += sizeof(ivrs_ivhd_generic_t); |
| 79 | |
| 80 | /* Create the end range IVHD entry */ |
| 81 | ivhd_range = (ivrs_ivhd_generic_t *)current; |
| 82 | ivhd_range->type = IVHD_DEV_4_BYTE_END_RANGE; |
| 83 | ivhd_range->dev_id = end_devid; |
| 84 | ivhd_range->dte_setting = setting; |
| 85 | current += sizeof(ivrs_ivhd_generic_t); |
| 86 | |
| 87 | return current; |
| 88 | } |
| 89 | |
| 90 | static unsigned long add_ivhd_dev_entry(struct device *parent, struct device *dev, |
| 91 | unsigned long *current, uint8_t type, uint8_t data) |
| 92 | { |
| 93 | if (type == IVHD_DEV_4_BYTE_SELECT) { |
| 94 | /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */ |
| 95 | *current = ALIGN_UP(*current, 4); |
| 96 | ivrs_ivhd_generic_t *ivhd_entry = (ivrs_ivhd_generic_t *)*current; |
Felix Held | fe242ce | 2023-06-23 19:03:57 +0200 | [diff] [blame] | 97 | memset(ivhd_entry, 0, sizeof(*ivhd_entry)); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 98 | |
| 99 | ivhd_entry->type = type; |
| 100 | ivhd_entry->dev_id = dev->path.pci.devfn | (dev->bus->secondary << 8); |
| 101 | ivhd_entry->dte_setting = data; |
| 102 | *current += sizeof(ivrs_ivhd_generic_t); |
| 103 | } else if (type == IVHD_DEV_8_BYTE_ALIAS_SELECT) { |
| 104 | ivrs_ivhd_alias_t *ivhd_entry = (ivrs_ivhd_alias_t *)*current; |
Felix Held | fe242ce | 2023-06-23 19:03:57 +0200 | [diff] [blame] | 105 | memset(ivhd_entry, 0, sizeof(*ivhd_entry)); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 106 | |
| 107 | ivhd_entry->type = type; |
| 108 | ivhd_entry->dev_id = dev->path.pci.devfn | (dev->bus->secondary << 8); |
| 109 | ivhd_entry->dte_setting = data; |
| 110 | ivhd_entry->reserved1 = 0; |
| 111 | ivhd_entry->reserved2 = 0; |
| 112 | ivhd_entry->source_dev_id = parent->path.pci.devfn | |
| 113 | (parent->bus->secondary << 8); |
| 114 | *current += sizeof(ivrs_ivhd_alias_t); |
| 115 | } |
| 116 | |
| 117 | return *current; |
| 118 | } |
| 119 | |
| 120 | static void ivrs_add_device_or_bridge(struct device *parent, struct device *dev, |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 121 | unsigned long *current) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 122 | { |
| 123 | unsigned int header_type, is_pcie; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 124 | |
| 125 | header_type = dev->hdr_type & 0x7f; |
| 126 | is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE); |
| 127 | |
| 128 | if (((header_type == PCI_HEADER_TYPE_NORMAL) || |
| 129 | (header_type == PCI_HEADER_TYPE_BRIDGE)) && is_pcie) { |
| 130 | /* Device or Bridge is PCIe */ |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 131 | add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_4_BYTE_SELECT, 0x0); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 132 | } else if ((header_type == PCI_HEADER_TYPE_NORMAL) && !is_pcie) { |
| 133 | /* Device is legacy PCI or PCI-X */ |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 134 | add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_8_BYTE_ALIAS_SELECT, 0x0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 135 | |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | static void add_ivhd_device_entries(struct device *parent, struct device *dev, |
| 140 | unsigned int depth, int linknum, int8_t *root_level, |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 141 | unsigned long *current, uint16_t nb_bus) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 142 | { |
| 143 | struct device *sibling; |
| 144 | struct bus *link; |
| 145 | |
| 146 | if (!root_level) |
| 147 | return; |
| 148 | |
| 149 | if (dev->path.type == DEVICE_PATH_PCI) { |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 150 | if ((dev->bus->secondary == nb_bus) && |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 151 | (dev->path.pci.devfn == 0x0)) |
| 152 | *root_level = depth; |
| 153 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 154 | if ((*root_level != -1) && (dev->enabled)) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 155 | if (depth != *root_level) |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 156 | ivrs_add_device_or_bridge(parent, dev, current); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | for (link = dev->link_list; link; link = link->next) |
| 160 | for (sibling = link->children; sibling; sibling = |
| 161 | sibling->sibling) |
| 162 | add_ivhd_device_entries(dev, sibling, depth + 1, depth, root_level, |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 163 | current, nb_bus); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 166 | static unsigned long acpi_ivhd_misc(unsigned long current, struct device *dev) |
| 167 | { |
| 168 | u8 dte_setting = IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS | |
| 169 | IVHD_DTE_SYS_MGT_NO_TRANS | IVHD_DTE_NMI_PASS | |
| 170 | IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS; |
| 171 | int8_t root_level = -1; |
| 172 | struct resource *res; |
| 173 | |
| 174 | /* |
| 175 | * Add all possible PCI devices in the domain that can generate transactions |
| 176 | * processed by IOMMU. Start with device <bus>:01.0 |
| 177 | */ |
| 178 | current = ivhd_dev_range(current, PCI_DEVFN(0, 3) | (dev->link_list->secondary << 8), |
| 179 | 0xff | (dev->link_list->subordinate << 8), 0); |
| 180 | |
| 181 | add_ivhd_device_entries(NULL, dev, 0, -1, &root_level, |
| 182 | ¤t, dev->link_list->secondary); |
| 183 | |
| 184 | res = probe_resource(dev, IOMMU_IOAPIC_IDX); |
| 185 | if (res) { |
| 186 | /* Describe IOAPIC associated with the IOMMU */ |
Arthur Heymans | f9ee87f | 2023-06-07 15:29:02 +0200 | [diff] [blame] | 187 | current = acpi_fill_ivrs_ioapic(current, (u8 *)(uintptr_t)res->base, |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 188 | PCI_DEVFN(0, 1) | (dev->link_list->secondary << 8), 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* If the domain has secondary bus as zero then associate HPET & FCH IOAPIC */ |
| 192 | if (dev->link_list->secondary == 0) { |
| 193 | /* Describe HPET */ |
| 194 | current = ivhd_describe_hpet(current, 0x00, SMBUS_DEVFN); |
| 195 | /* Describe FCH IOAPICs */ |
Arthur Heymans | f9ee87f | 2023-06-07 15:29:02 +0200 | [diff] [blame] | 196 | current = acpi_fill_ivrs_ioapic(current, VIO_APIC_VADDR, |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 197 | SMBUS_DEVFN, dte_setting); |
| 198 | } |
| 199 | |
| 200 | return current; |
| 201 | } |
| 202 | |
| 203 | static unsigned long acpi_fill_ivrs40(unsigned long current, acpi_ivrs_ivhd_t *ivhd, |
| 204 | struct device *nb_dev, struct device *iommu_dev) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 205 | { |
Felix Held | 50cbb93 | 2023-06-23 18:49:26 +0200 | [diff] [blame] | 206 | acpi_ivrs_ivhd40_t *ivhd_40 = (acpi_ivrs_ivhd40_t *)current; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 207 | unsigned long current_backup; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 208 | |
Felix Held | 8cbafe8 | 2023-06-23 18:55:34 +0200 | [diff] [blame] | 209 | memset(ivhd_40, 0, sizeof(*ivhd_40)); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 210 | |
| 211 | /* Enable EFR */ |
| 212 | ivhd_40->type = IVHD_BLOCK_TYPE_FULL__ACPI_HID; |
| 213 | /* For type 40h bits 6 and 7 are reserved */ |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 214 | ivhd_40->flags = ivhd->flags & 0x3f; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 215 | ivhd_40->length = sizeof(struct acpi_ivrs_ivhd_40); |
| 216 | /* BDF <bus>:00.2 */ |
| 217 | ivhd_40->device_id = 0x02 | (nb_dev->bus->secondary << 8); |
| 218 | ivhd_40->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 219 | ivhd_40->iommu_base_low = ivhd->iommu_base_low; |
| 220 | ivhd_40->iommu_base_high = ivhd->iommu_base_high; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 221 | ivhd_40->pci_segment_group = 0x0000; |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 222 | ivhd_40->iommu_info = ivhd->iommu_info; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 223 | /* For type 40h bits 31:28 and 12:0 are reserved */ |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 224 | ivhd_40->iommu_attributes = ivhd->iommu_feature_info & 0xfffe000; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 225 | |
| 226 | if (pci_read_config32(iommu_dev, ivhd_40->capability_offset) & EFR_FEATURE_SUP) { |
Arthur Heymans | 4c68487 | 2022-04-19 21:44:22 +0200 | [diff] [blame] | 227 | ivhd_40->efr_reg_image_low = read32p(ivhd_40->iommu_base_low + 0x30); |
| 228 | ivhd_40->efr_reg_image_high = read32p(ivhd_40->iommu_base_low + 0x34); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | current += sizeof(acpi_ivrs_ivhd40_t); |
| 232 | |
| 233 | /* Now repeat all the device entries from type 10h */ |
| 234 | current_backup = current; |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 235 | current = acpi_ivhd_misc(current, nb_dev->bus->dev); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 236 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 237 | if (nb_dev->bus->secondary == 0) { |
| 238 | /* Describe EMMC */ |
Felix Held | 47ed271 | 2023-06-20 19:17:43 +0200 | [diff] [blame] | 239 | if (CONFIG(SOC_AMD_COMMON_BLOCK_EMMC)) { |
| 240 | /* PCI_DEVFN(0x13, 1) doesn't exist in the hardware, but it's what the |
| 241 | * reference code uses. Maybe to have a unique PCI device to put into |
| 242 | * the field that doesn't collide with any existing device? */ |
| 243 | current = ivhd_describe_f0_device(current, PCI_DEVFN(0x13, 1), |
Felix Held | 534cce3 | 2023-06-22 23:09:23 +0200 | [diff] [blame] | 244 | "AMDI0040", |
Felix Held | 47ed271 | 2023-06-20 19:17:43 +0200 | [diff] [blame] | 245 | IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS | |
| 246 | IVHD_DTE_SYS_MGT_TRANS | IVHD_DTE_NMI_PASS | |
| 247 | IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS); |
| 248 | } |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 249 | } |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 250 | ivhd_40->length += (current - current_backup); |
| 251 | |
| 252 | return current; |
| 253 | } |
| 254 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 255 | static unsigned long acpi_fill_ivrs11(unsigned long current, acpi_ivrs_ivhd_t *ivhd, |
| 256 | struct device *nb_dev, struct device *iommu_dev) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 257 | { |
Felix Held | 50cbb93 | 2023-06-23 18:49:26 +0200 | [diff] [blame] | 258 | acpi_ivrs_ivhd11_t *ivhd_11 = (acpi_ivrs_ivhd11_t *)current; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 259 | ivhd11_iommu_attr_t *ivhd11_attr_ptr; |
| 260 | unsigned long current_backup; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * In order to utilize all features, firmware should expose type 11h |
| 264 | * IVHD which supersedes the type 10h. |
| 265 | */ |
Felix Held | 8cbafe8 | 2023-06-23 18:55:34 +0200 | [diff] [blame] | 266 | memset(ivhd_11, 0, sizeof(*ivhd_11)); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 267 | |
| 268 | /* Enable EFR */ |
| 269 | ivhd_11->type = IVHD_BLOCK_TYPE_FULL__FIXED; |
| 270 | /* For type 11h bits 6 and 7 are reserved */ |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 271 | ivhd_11->flags = ivhd->flags & 0x3f; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 272 | ivhd_11->length = sizeof(struct acpi_ivrs_ivhd_11); |
| 273 | /* BDF <bus>:00.2 */ |
| 274 | ivhd_11->device_id = 0x02 | (nb_dev->bus->secondary << 8); |
| 275 | ivhd_11->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 276 | ivhd_11->iommu_base_low = ivhd->iommu_base_low; |
| 277 | ivhd_11->iommu_base_high = ivhd->iommu_base_high; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 278 | ivhd_11->pci_segment_group = 0x0000; |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 279 | ivhd_11->iommu_info = ivhd->iommu_info; |
| 280 | ivhd11_attr_ptr = (ivhd11_iommu_attr_t *)&ivhd->iommu_feature_info; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 281 | ivhd_11->iommu_attributes.perf_counters = ivhd11_attr_ptr->perf_counters; |
| 282 | ivhd_11->iommu_attributes.perf_counter_banks = ivhd11_attr_ptr->perf_counter_banks; |
| 283 | ivhd_11->iommu_attributes.msi_num_ppr = ivhd11_attr_ptr->msi_num_ppr; |
| 284 | |
| 285 | if (pci_read_config32(iommu_dev, ivhd_11->capability_offset) & EFR_FEATURE_SUP) { |
Arthur Heymans | 4c68487 | 2022-04-19 21:44:22 +0200 | [diff] [blame] | 286 | ivhd_11->efr_reg_image_low = read32p(ivhd_11->iommu_base_low + 0x30); |
| 287 | ivhd_11->efr_reg_image_high = read32p(ivhd_11->iommu_base_low + 0x34); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | current += sizeof(acpi_ivrs_ivhd11_t); |
| 291 | |
| 292 | /* Now repeat all the device entries from type 10h */ |
| 293 | current_backup = current; |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 294 | current = acpi_ivhd_misc(current, nb_dev->bus->dev); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 295 | ivhd_11->length += (current - current_backup); |
| 296 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 297 | return acpi_fill_ivrs40(current, ivhd, nb_dev, iommu_dev); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current) |
| 301 | { |
| 302 | unsigned long current_backup; |
| 303 | uint64_t mmio_x30_value; |
| 304 | uint64_t mmio_x18_value; |
| 305 | uint64_t mmio_x4000_value; |
| 306 | uint32_t cap_offset_0; |
| 307 | uint32_t cap_offset_10; |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 308 | struct acpi_ivrs_ivhd *ivhd; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 309 | struct device *iommu_dev; |
| 310 | struct device *nb_dev; |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 311 | struct device *dev = NULL; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 312 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 313 | ivhd = &ivrs->ivhd; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 314 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 315 | while ((dev = dev_find_path(dev, DEVICE_PATH_DOMAIN)) != NULL) { |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 316 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 317 | nb_dev = pcidev_path_behind(dev->link_list, PCI_DEVFN(0, 0)); |
| 318 | iommu_dev = pcidev_path_behind(dev->link_list, PCI_DEVFN(0, 2)); |
| 319 | if (!nb_dev) { |
| 320 | printk(BIOS_WARNING, "%s: Northbridge device not present!\n", __func__); |
| 321 | printk(BIOS_WARNING, "%s: IVRS table not generated...\n", __func__); |
| 322 | return (unsigned long)ivrs; |
| 323 | } |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 324 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 325 | if (!iommu_dev) { |
| 326 | printk(BIOS_WARNING, "%s: IOMMU device not found\n", __func__); |
| 327 | return (unsigned long)ivrs; |
| 328 | } |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 329 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 330 | ivhd->type = IVHD_BLOCK_TYPE_LEGACY__FIXED; |
| 331 | ivhd->length = sizeof(struct acpi_ivrs_ivhd); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 332 | |
| 333 | /* BDF <bus>:00.2 */ |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 334 | ivhd->device_id = 0x02 | (nb_dev->bus->secondary << 8); |
| 335 | ivhd->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID); |
| 336 | ivhd->iommu_base_low = pci_read_config32(iommu_dev, 0x44) & 0xffffc000; |
| 337 | ivhd->iommu_base_high = pci_read_config32(iommu_dev, 0x48); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 338 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 339 | cap_offset_0 = pci_read_config32(iommu_dev, ivhd->capability_offset); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 340 | cap_offset_10 = pci_read_config32(iommu_dev, |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 341 | ivhd->capability_offset + 0x10); |
| 342 | mmio_x18_value = read64p(ivhd->iommu_base_low + 0x18); |
| 343 | mmio_x30_value = read64p(ivhd->iommu_base_low + 0x30); |
| 344 | mmio_x4000_value = read64p(ivhd->iommu_base_low + 0x4000); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 345 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 346 | ivhd->flags |= ((mmio_x30_value & MMIO_EXT_FEATURE_PPR_SUP) ? |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 347 | IVHD_FLAG_PPE_SUP : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 348 | ivhd->flags |= ((mmio_x30_value & MMIO_EXT_FEATURE_PRE_F_SUP) ? |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 349 | IVHD_FLAG_PREF_SUP : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 350 | ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_COHERENT) ? |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 351 | IVHD_FLAG_COHERENT : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 352 | ivhd->flags |= ((cap_offset_0 & CAP_OFFSET_0_IOTLB_SP) ? |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 353 | IVHD_FLAG_IOTLB_SUP : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 354 | ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_ISOC) ? |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 355 | IVHD_FLAG_ISOC : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 356 | ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_RES_PASS_PW) ? |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 357 | IVHD_FLAG_RES_PASS_PW : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 358 | ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_PASS_PW) ? |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 359 | IVHD_FLAG_PASS_PW : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 360 | ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_HT_TUN_EN) ? |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 361 | IVHD_FLAG_HT_TUN_EN : 0); |
| 362 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 363 | ivhd->pci_segment_group = 0x0000; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 364 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 365 | ivhd->iommu_info = pci_read_config16(iommu_dev, |
| 366 | ivhd->capability_offset + 0x10) & 0x1F; |
| 367 | ivhd->iommu_info |= (pci_read_config16(iommu_dev, |
| 368 | ivhd->capability_offset + 0xC) & 0x1F) << IOMMU_INFO_UNIT_ID_SHIFT; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 369 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 370 | ivhd->iommu_feature_info = 0; |
| 371 | ivhd->iommu_feature_info |= (mmio_x30_value & MMIO_EXT_FEATURE_HATS_MASK) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 372 | << (IOMMU_FEATURE_HATS_SHIFT - MMIO_EXT_FEATURE_HATS_SHIFT); |
| 373 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 374 | ivhd->iommu_feature_info |= (mmio_x30_value & MMIO_EXT_FEATURE_GATS_MASK) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 375 | << (IOMMU_FEATURE_GATS_SHIFT - MMIO_EXT_FEATURE_GATS_SHIFT); |
| 376 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 377 | ivhd->iommu_feature_info |= (cap_offset_10 & CAP_OFFSET_10_MSI_NUM_PPR) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 378 | >> (CAP_OFFSET_10_MSI_NUM_PPR_SHIFT |
| 379 | - IOMMU_FEATURE_MSI_NUM_PPR_SHIFT); |
| 380 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 381 | ivhd->iommu_feature_info |= (mmio_x4000_value & |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 382 | MMIO_CNT_CFG_N_COUNTER_BANKS) |
| 383 | << (IOMMU_FEATURE_PN_BANKS_SHIFT - MMIO_CNT_CFG_N_CNT_BANKS_SHIFT); |
| 384 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 385 | ivhd->iommu_feature_info |= (mmio_x4000_value & MMIO_CNT_CFG_N_COUNTER) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 386 | << (IOMMU_FEATURE_PN_COUNTERS_SHIFT - MMIO_CNT_CFG_N_COUNTER_SHIFT); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 387 | ivhd->iommu_feature_info |= (mmio_x30_value & |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 388 | MMIO_EXT_FEATURE_PAS_MAX_MASK) |
| 389 | >> (MMIO_EXT_FEATURE_PAS_MAX_SHIFT - IOMMU_FEATURE_PA_SMAX_SHIFT); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 390 | ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_HE_SUP) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 391 | ? IOMMU_FEATURE_HE_SUP : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 392 | ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_GA_SUP) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 393 | ? IOMMU_FEATURE_GA_SUP : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 394 | ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_IA_SUP) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 395 | ? IOMMU_FEATURE_IA_SUP : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 396 | ivhd->iommu_feature_info |= (mmio_x30_value & |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 397 | MMIO_EXT_FEATURE_GLX_SUP_MASK) |
| 398 | >> (MMIO_EXT_FEATURE_GLX_SHIFT - IOMMU_FEATURE_GLX_SHIFT); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 399 | ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_GT_SUP) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 400 | ? IOMMU_FEATURE_GT_SUP : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 401 | ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_NX_SUP) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 402 | ? IOMMU_FEATURE_NX_SUP : 0); |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 403 | ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_XT_SUP) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 404 | ? IOMMU_FEATURE_XT_SUP : 0); |
| 405 | |
| 406 | /* Enable EFR if supported */ |
| 407 | ivrs->iv_info = pci_read_config32(iommu_dev, |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 408 | ivhd->capability_offset + 0x10) & 0x007fffe0; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 409 | if (pci_read_config32(iommu_dev, |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 410 | ivhd->capability_offset) & EFR_FEATURE_SUP) |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 411 | ivrs->iv_info |= IVINFO_EFR_SUPPORTED; |
| 412 | |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 413 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 414 | current_backup = current; |
| 415 | current = acpi_ivhd_misc(current, dev); |
| 416 | ivhd->length += (current - current_backup); |
| 417 | |
| 418 | /* If EFR is not supported, IVHD type 11h is reserved */ |
| 419 | if (!(ivrs->iv_info & IVINFO_EFR_SUPPORTED)) |
| 420 | return current; |
| 421 | |
| 422 | current = acpi_fill_ivrs11(current, ivhd, nb_dev, iommu_dev); |
| 423 | |
| 424 | ivhd = (struct acpi_ivrs_ivhd *)current; |
| 425 | current += sizeof(struct acpi_ivrs_ivhd); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 426 | } |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 427 | current -= sizeof(struct acpi_ivrs_ivhd); |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 428 | |
Naresh Solanki | 4ef89f7 | 2023-05-25 17:37:50 +0200 | [diff] [blame] | 429 | return current; |
Jason Glenesk | f934fae | 2021-07-20 02:19:58 -0700 | [diff] [blame] | 430 | } |