blob: 8d127e94677f560545d584b7420ddd03214ed934 [file] [log] [blame]
Jason Gleneskf934fae2021-07-20 02:19:58 -07001/* 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 Held96fa6a22022-12-06 01:25:13 +01008#include <arch/ioapic.h>
Jason Gleneskf934fae2021-07-20 02:19:58 -07009#include <console/console.h>
10#include <cpu/amd/cpuid.h>
Jason Gleneskf934fae2021-07-20 02:19:58 -070011#include <device/device.h>
Elyes Haouas8823ba12022-12-05 08:48:50 +010012#include <device/mmio.h>
Jason Gleneskf934fae2021-07-20 02:19:58 -070013#include <device/pci_def.h>
14#include <device/pci_ops.h>
15#include <soc/acpi.h>
16#include <soc/data_fabric.h>
Felix Held96fa6a22022-12-06 01:25:13 +010017#include <soc/iomap.h>
Jason Gleneskf934fae2021-07-20 02:19:58 -070018#include <soc/pci_devs.h>
Jason Gleneskf934fae2021-07-20 02:19:58 -070019
Arthur Heymansf9ee87f2023-06-07 15:29:02 +020020static unsigned long acpi_fill_ivrs_ioapic(unsigned long current, void *ioapic_base,
Naresh Solanki4ef89f72023-05-25 17:37:50 +020021 uint16_t src_devid, uint8_t dte_setting)
Jason Gleneskf934fae2021-07-20 02:19:58 -070022{
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 Solanki4ef89f72023-05-25 17:37:50 +020027 ivhd_ioapic->dte_setting = dte_setting;
28 ivhd_ioapic->handle = get_ioapic_id(ioapic_base);
29 ivhd_ioapic->source_dev_id = src_devid;
Jason Gleneskf934fae2021-07-20 02:19:58 -070030 ivhd_ioapic->variety = IVHD_SPECIAL_DEV_IOAPIC;
31 current += sizeof(ivrs_ivhd_special_t);
32
33 return current;
34}
35
Naresh Solanki4ef89f72023-05-25 17:37:50 +020036static unsigned long ivhd_describe_hpet(unsigned long current, uint8_t hndl, uint16_t src_devid)
Jason Gleneskf934fae2021-07-20 02:19:58 -070037{
38 ivrs_ivhd_special_t *ivhd_hpet = (ivrs_ivhd_special_t *)current;
39
40 ivhd_hpet->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV;
41 ivhd_hpet->reserved = 0x0000;
42 ivhd_hpet->dte_setting = 0x00;
Naresh Solanki4ef89f72023-05-25 17:37:50 +020043 ivhd_hpet->handle = hndl;
44 ivhd_hpet->source_dev_id = src_devid; /* function 0 of FCH PCI device */
Jason Gleneskf934fae2021-07-20 02:19:58 -070045 ivhd_hpet->variety = IVHD_SPECIAL_DEV_HPET;
46 current += sizeof(ivrs_ivhd_special_t);
47
48 return current;
49}
50
51static unsigned long ivhd_describe_f0_device(unsigned long current,
52 uint16_t dev_id, uint8_t datasetting)
53{
Elyes Haouas68fc51f2022-07-16 09:48:27 +020054 ivrs_ivhd_f0_entry_t *ivhd_f0 = (ivrs_ivhd_f0_entry_t *)current;
Felix Held63a4e6bd2023-06-22 23:04:19 +020055 memset(ivhd_f0, 0, sizeof(*ivhd_f0));
Jason Gleneskf934fae2021-07-20 02:19:58 -070056
57 ivhd_f0->type = IVHD_DEV_VARIABLE;
58 ivhd_f0->dev_id = dev_id;
59 ivhd_f0->dte_setting = datasetting;
60 ivhd_f0->hardware_id[0] = 'A';
61 ivhd_f0->hardware_id[1] = 'M';
62 ivhd_f0->hardware_id[2] = 'D';
63 ivhd_f0->hardware_id[3] = 'I';
64 ivhd_f0->hardware_id[4] = '0';
65 ivhd_f0->hardware_id[5] = '0';
66 ivhd_f0->hardware_id[6] = '4';
67 ivhd_f0->hardware_id[7] = '0';
68
Jason Gleneskf934fae2021-07-20 02:19:58 -070069 current += sizeof(ivrs_ivhd_f0_entry_t);
70 return current;
71}
72
73static unsigned long ivhd_dev_range(unsigned long current, uint16_t start_devid,
74 uint16_t end_devid, uint8_t setting)
75{
76 /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */
77 current = ALIGN_UP(current, 4);
78 ivrs_ivhd_generic_t *ivhd_range = (ivrs_ivhd_generic_t *)current;
79
80 /* Create the start range IVHD entry */
81 ivhd_range->type = IVHD_DEV_4_BYTE_START_RANGE;
82 ivhd_range->dev_id = start_devid;
83 ivhd_range->dte_setting = setting;
84 current += sizeof(ivrs_ivhd_generic_t);
85
86 /* Create the end range IVHD entry */
87 ivhd_range = (ivrs_ivhd_generic_t *)current;
88 ivhd_range->type = IVHD_DEV_4_BYTE_END_RANGE;
89 ivhd_range->dev_id = end_devid;
90 ivhd_range->dte_setting = setting;
91 current += sizeof(ivrs_ivhd_generic_t);
92
93 return current;
94}
95
96static unsigned long add_ivhd_dev_entry(struct device *parent, struct device *dev,
97 unsigned long *current, uint8_t type, uint8_t data)
98{
99 if (type == IVHD_DEV_4_BYTE_SELECT) {
100 /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */
101 *current = ALIGN_UP(*current, 4);
102 ivrs_ivhd_generic_t *ivhd_entry = (ivrs_ivhd_generic_t *)*current;
103
104 ivhd_entry->type = type;
105 ivhd_entry->dev_id = dev->path.pci.devfn | (dev->bus->secondary << 8);
106 ivhd_entry->dte_setting = data;
107 *current += sizeof(ivrs_ivhd_generic_t);
108 } else if (type == IVHD_DEV_8_BYTE_ALIAS_SELECT) {
109 ivrs_ivhd_alias_t *ivhd_entry = (ivrs_ivhd_alias_t *)*current;
110
111 ivhd_entry->type = type;
112 ivhd_entry->dev_id = dev->path.pci.devfn | (dev->bus->secondary << 8);
113 ivhd_entry->dte_setting = data;
114 ivhd_entry->reserved1 = 0;
115 ivhd_entry->reserved2 = 0;
116 ivhd_entry->source_dev_id = parent->path.pci.devfn |
117 (parent->bus->secondary << 8);
118 *current += sizeof(ivrs_ivhd_alias_t);
119 }
120
121 return *current;
122}
123
124static void ivrs_add_device_or_bridge(struct device *parent, struct device *dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200125 unsigned long *current)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700126{
127 unsigned int header_type, is_pcie;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700128
129 header_type = dev->hdr_type & 0x7f;
130 is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE);
131
132 if (((header_type == PCI_HEADER_TYPE_NORMAL) ||
133 (header_type == PCI_HEADER_TYPE_BRIDGE)) && is_pcie) {
134 /* Device or Bridge is PCIe */
Jason Gleneskf934fae2021-07-20 02:19:58 -0700135 add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_4_BYTE_SELECT, 0x0);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700136 } else if ((header_type == PCI_HEADER_TYPE_NORMAL) && !is_pcie) {
137 /* Device is legacy PCI or PCI-X */
Jason Gleneskf934fae2021-07-20 02:19:58 -0700138 add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_8_BYTE_ALIAS_SELECT, 0x0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200139
Jason Gleneskf934fae2021-07-20 02:19:58 -0700140 }
141}
142
143static void add_ivhd_device_entries(struct device *parent, struct device *dev,
144 unsigned int depth, int linknum, int8_t *root_level,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200145 unsigned long *current, uint16_t nb_bus)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700146{
147 struct device *sibling;
148 struct bus *link;
149
150 if (!root_level)
151 return;
152
153 if (dev->path.type == DEVICE_PATH_PCI) {
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200154 if ((dev->bus->secondary == nb_bus) &&
Jason Gleneskf934fae2021-07-20 02:19:58 -0700155 (dev->path.pci.devfn == 0x0))
156 *root_level = depth;
157
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200158 if ((*root_level != -1) && (dev->enabled))
Jason Gleneskf934fae2021-07-20 02:19:58 -0700159 if (depth != *root_level)
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200160 ivrs_add_device_or_bridge(parent, dev, current);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700161 }
162
163 for (link = dev->link_list; link; link = link->next)
164 for (sibling = link->children; sibling; sibling =
165 sibling->sibling)
166 add_ivhd_device_entries(dev, sibling, depth + 1, depth, root_level,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200167 current, nb_bus);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700168}
169
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200170static unsigned long acpi_ivhd_misc(unsigned long current, struct device *dev)
171{
172 u8 dte_setting = IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS |
173 IVHD_DTE_SYS_MGT_NO_TRANS | IVHD_DTE_NMI_PASS |
174 IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS;
175 int8_t root_level = -1;
176 struct resource *res;
177
178 /*
179 * Add all possible PCI devices in the domain that can generate transactions
180 * processed by IOMMU. Start with device <bus>:01.0
181 */
182 current = ivhd_dev_range(current, PCI_DEVFN(0, 3) | (dev->link_list->secondary << 8),
183 0xff | (dev->link_list->subordinate << 8), 0);
184
185 add_ivhd_device_entries(NULL, dev, 0, -1, &root_level,
186 &current, dev->link_list->secondary);
187
188 res = probe_resource(dev, IOMMU_IOAPIC_IDX);
189 if (res) {
190 /* Describe IOAPIC associated with the IOMMU */
Arthur Heymansf9ee87f2023-06-07 15:29:02 +0200191 current = acpi_fill_ivrs_ioapic(current, (u8 *)(uintptr_t)res->base,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200192 PCI_DEVFN(0, 1) | (dev->link_list->secondary << 8), 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200193 }
194
195 /* If the domain has secondary bus as zero then associate HPET & FCH IOAPIC */
196 if (dev->link_list->secondary == 0) {
197 /* Describe HPET */
198 current = ivhd_describe_hpet(current, 0x00, SMBUS_DEVFN);
199 /* Describe FCH IOAPICs */
Arthur Heymansf9ee87f2023-06-07 15:29:02 +0200200 current = acpi_fill_ivrs_ioapic(current, VIO_APIC_VADDR,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200201 SMBUS_DEVFN, dte_setting);
202 }
203
204 return current;
205}
206
207static unsigned long acpi_fill_ivrs40(unsigned long current, acpi_ivrs_ivhd_t *ivhd,
208 struct device *nb_dev, struct device *iommu_dev)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700209{
210 acpi_ivrs_ivhd40_t *ivhd_40;
211 unsigned long current_backup;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700212
213 memset((void *)current, 0, sizeof(acpi_ivrs_ivhd40_t));
214 ivhd_40 = (acpi_ivrs_ivhd40_t *)current;
215
216 /* Enable EFR */
217 ivhd_40->type = IVHD_BLOCK_TYPE_FULL__ACPI_HID;
218 /* For type 40h bits 6 and 7 are reserved */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200219 ivhd_40->flags = ivhd->flags & 0x3f;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700220 ivhd_40->length = sizeof(struct acpi_ivrs_ivhd_40);
221 /* BDF <bus>:00.2 */
222 ivhd_40->device_id = 0x02 | (nb_dev->bus->secondary << 8);
223 ivhd_40->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200224 ivhd_40->iommu_base_low = ivhd->iommu_base_low;
225 ivhd_40->iommu_base_high = ivhd->iommu_base_high;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700226 ivhd_40->pci_segment_group = 0x0000;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200227 ivhd_40->iommu_info = ivhd->iommu_info;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700228 /* For type 40h bits 31:28 and 12:0 are reserved */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200229 ivhd_40->iommu_attributes = ivhd->iommu_feature_info & 0xfffe000;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700230
231 if (pci_read_config32(iommu_dev, ivhd_40->capability_offset) & EFR_FEATURE_SUP) {
Arthur Heymans4c684872022-04-19 21:44:22 +0200232 ivhd_40->efr_reg_image_low = read32p(ivhd_40->iommu_base_low + 0x30);
233 ivhd_40->efr_reg_image_high = read32p(ivhd_40->iommu_base_low + 0x34);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700234 }
235
236 current += sizeof(acpi_ivrs_ivhd40_t);
237
238 /* Now repeat all the device entries from type 10h */
239 current_backup = current;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200240 current = acpi_ivhd_misc(current, nb_dev->bus->dev);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700241
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200242 if (nb_dev->bus->secondary == 0) {
243 /* Describe EMMC */
Felix Held47ed2712023-06-20 19:17:43 +0200244 if (CONFIG(SOC_AMD_COMMON_BLOCK_EMMC)) {
245 /* PCI_DEVFN(0x13, 1) doesn't exist in the hardware, but it's what the
246 * reference code uses. Maybe to have a unique PCI device to put into
247 * the field that doesn't collide with any existing device? */
248 current = ivhd_describe_f0_device(current, PCI_DEVFN(0x13, 1),
249 IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS |
250 IVHD_DTE_SYS_MGT_TRANS | IVHD_DTE_NMI_PASS |
251 IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS);
252 }
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200253 }
Jason Gleneskf934fae2021-07-20 02:19:58 -0700254 ivhd_40->length += (current - current_backup);
255
256 return current;
257}
258
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200259static unsigned long acpi_fill_ivrs11(unsigned long current, acpi_ivrs_ivhd_t *ivhd,
260 struct device *nb_dev, struct device *iommu_dev)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700261{
262 acpi_ivrs_ivhd11_t *ivhd_11;
263 ivhd11_iommu_attr_t *ivhd11_attr_ptr;
264 unsigned long current_backup;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700265
266 /*
267 * In order to utilize all features, firmware should expose type 11h
268 * IVHD which supersedes the type 10h.
269 */
270 memset((void *)current, 0, sizeof(acpi_ivrs_ivhd11_t));
271 ivhd_11 = (acpi_ivrs_ivhd11_t *)current;
272
273 /* Enable EFR */
274 ivhd_11->type = IVHD_BLOCK_TYPE_FULL__FIXED;
275 /* For type 11h bits 6 and 7 are reserved */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200276 ivhd_11->flags = ivhd->flags & 0x3f;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700277 ivhd_11->length = sizeof(struct acpi_ivrs_ivhd_11);
278 /* BDF <bus>:00.2 */
279 ivhd_11->device_id = 0x02 | (nb_dev->bus->secondary << 8);
280 ivhd_11->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200281 ivhd_11->iommu_base_low = ivhd->iommu_base_low;
282 ivhd_11->iommu_base_high = ivhd->iommu_base_high;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700283 ivhd_11->pci_segment_group = 0x0000;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200284 ivhd_11->iommu_info = ivhd->iommu_info;
285 ivhd11_attr_ptr = (ivhd11_iommu_attr_t *)&ivhd->iommu_feature_info;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700286 ivhd_11->iommu_attributes.perf_counters = ivhd11_attr_ptr->perf_counters;
287 ivhd_11->iommu_attributes.perf_counter_banks = ivhd11_attr_ptr->perf_counter_banks;
288 ivhd_11->iommu_attributes.msi_num_ppr = ivhd11_attr_ptr->msi_num_ppr;
289
290 if (pci_read_config32(iommu_dev, ivhd_11->capability_offset) & EFR_FEATURE_SUP) {
Arthur Heymans4c684872022-04-19 21:44:22 +0200291 ivhd_11->efr_reg_image_low = read32p(ivhd_11->iommu_base_low + 0x30);
292 ivhd_11->efr_reg_image_high = read32p(ivhd_11->iommu_base_low + 0x34);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700293 }
294
295 current += sizeof(acpi_ivrs_ivhd11_t);
296
297 /* Now repeat all the device entries from type 10h */
298 current_backup = current;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200299 current = acpi_ivhd_misc(current, nb_dev->bus->dev);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700300 ivhd_11->length += (current - current_backup);
301
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200302 return acpi_fill_ivrs40(current, ivhd, nb_dev, iommu_dev);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700303}
304
305unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current)
306{
307 unsigned long current_backup;
308 uint64_t mmio_x30_value;
309 uint64_t mmio_x18_value;
310 uint64_t mmio_x4000_value;
311 uint32_t cap_offset_0;
312 uint32_t cap_offset_10;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200313 struct acpi_ivrs_ivhd *ivhd;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700314 struct device *iommu_dev;
315 struct device *nb_dev;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200316 struct device *dev = NULL;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700317
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200318 ivhd = &ivrs->ivhd;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700319
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200320 while ((dev = dev_find_path(dev, DEVICE_PATH_DOMAIN)) != NULL) {
Jason Gleneskf934fae2021-07-20 02:19:58 -0700321
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200322 nb_dev = pcidev_path_behind(dev->link_list, PCI_DEVFN(0, 0));
323 iommu_dev = pcidev_path_behind(dev->link_list, PCI_DEVFN(0, 2));
324 if (!nb_dev) {
325 printk(BIOS_WARNING, "%s: Northbridge device not present!\n", __func__);
326 printk(BIOS_WARNING, "%s: IVRS table not generated...\n", __func__);
327 return (unsigned long)ivrs;
328 }
Jason Gleneskf934fae2021-07-20 02:19:58 -0700329
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200330 if (!iommu_dev) {
331 printk(BIOS_WARNING, "%s: IOMMU device not found\n", __func__);
332 return (unsigned long)ivrs;
333 }
Jason Gleneskf934fae2021-07-20 02:19:58 -0700334
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200335 ivhd->type = IVHD_BLOCK_TYPE_LEGACY__FIXED;
336 ivhd->length = sizeof(struct acpi_ivrs_ivhd);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700337
338 /* BDF <bus>:00.2 */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200339 ivhd->device_id = 0x02 | (nb_dev->bus->secondary << 8);
340 ivhd->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID);
341 ivhd->iommu_base_low = pci_read_config32(iommu_dev, 0x44) & 0xffffc000;
342 ivhd->iommu_base_high = pci_read_config32(iommu_dev, 0x48);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700343
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200344 cap_offset_0 = pci_read_config32(iommu_dev, ivhd->capability_offset);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700345 cap_offset_10 = pci_read_config32(iommu_dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200346 ivhd->capability_offset + 0x10);
347 mmio_x18_value = read64p(ivhd->iommu_base_low + 0x18);
348 mmio_x30_value = read64p(ivhd->iommu_base_low + 0x30);
349 mmio_x4000_value = read64p(ivhd->iommu_base_low + 0x4000);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700350
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200351 ivhd->flags |= ((mmio_x30_value & MMIO_EXT_FEATURE_PPR_SUP) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700352 IVHD_FLAG_PPE_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200353 ivhd->flags |= ((mmio_x30_value & MMIO_EXT_FEATURE_PRE_F_SUP) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700354 IVHD_FLAG_PREF_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200355 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_COHERENT) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700356 IVHD_FLAG_COHERENT : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200357 ivhd->flags |= ((cap_offset_0 & CAP_OFFSET_0_IOTLB_SP) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700358 IVHD_FLAG_IOTLB_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200359 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_ISOC) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700360 IVHD_FLAG_ISOC : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200361 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_RES_PASS_PW) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700362 IVHD_FLAG_RES_PASS_PW : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200363 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_PASS_PW) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700364 IVHD_FLAG_PASS_PW : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200365 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_HT_TUN_EN) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700366 IVHD_FLAG_HT_TUN_EN : 0);
367
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200368 ivhd->pci_segment_group = 0x0000;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700369
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200370 ivhd->iommu_info = pci_read_config16(iommu_dev,
371 ivhd->capability_offset + 0x10) & 0x1F;
372 ivhd->iommu_info |= (pci_read_config16(iommu_dev,
373 ivhd->capability_offset + 0xC) & 0x1F) << IOMMU_INFO_UNIT_ID_SHIFT;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700374
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200375 ivhd->iommu_feature_info = 0;
376 ivhd->iommu_feature_info |= (mmio_x30_value & MMIO_EXT_FEATURE_HATS_MASK)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700377 << (IOMMU_FEATURE_HATS_SHIFT - MMIO_EXT_FEATURE_HATS_SHIFT);
378
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200379 ivhd->iommu_feature_info |= (mmio_x30_value & MMIO_EXT_FEATURE_GATS_MASK)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700380 << (IOMMU_FEATURE_GATS_SHIFT - MMIO_EXT_FEATURE_GATS_SHIFT);
381
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200382 ivhd->iommu_feature_info |= (cap_offset_10 & CAP_OFFSET_10_MSI_NUM_PPR)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700383 >> (CAP_OFFSET_10_MSI_NUM_PPR_SHIFT
384 - IOMMU_FEATURE_MSI_NUM_PPR_SHIFT);
385
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200386 ivhd->iommu_feature_info |= (mmio_x4000_value &
Jason Gleneskf934fae2021-07-20 02:19:58 -0700387 MMIO_CNT_CFG_N_COUNTER_BANKS)
388 << (IOMMU_FEATURE_PN_BANKS_SHIFT - MMIO_CNT_CFG_N_CNT_BANKS_SHIFT);
389
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200390 ivhd->iommu_feature_info |= (mmio_x4000_value & MMIO_CNT_CFG_N_COUNTER)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700391 << (IOMMU_FEATURE_PN_COUNTERS_SHIFT - MMIO_CNT_CFG_N_COUNTER_SHIFT);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200392 ivhd->iommu_feature_info |= (mmio_x30_value &
Jason Gleneskf934fae2021-07-20 02:19:58 -0700393 MMIO_EXT_FEATURE_PAS_MAX_MASK)
394 >> (MMIO_EXT_FEATURE_PAS_MAX_SHIFT - IOMMU_FEATURE_PA_SMAX_SHIFT);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200395 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_HE_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700396 ? IOMMU_FEATURE_HE_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200397 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_GA_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700398 ? IOMMU_FEATURE_GA_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200399 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_IA_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700400 ? IOMMU_FEATURE_IA_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200401 ivhd->iommu_feature_info |= (mmio_x30_value &
Jason Gleneskf934fae2021-07-20 02:19:58 -0700402 MMIO_EXT_FEATURE_GLX_SUP_MASK)
403 >> (MMIO_EXT_FEATURE_GLX_SHIFT - IOMMU_FEATURE_GLX_SHIFT);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200404 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_GT_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700405 ? IOMMU_FEATURE_GT_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200406 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_NX_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700407 ? IOMMU_FEATURE_NX_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200408 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_XT_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700409 ? IOMMU_FEATURE_XT_SUP : 0);
410
411 /* Enable EFR if supported */
412 ivrs->iv_info = pci_read_config32(iommu_dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200413 ivhd->capability_offset + 0x10) & 0x007fffe0;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700414 if (pci_read_config32(iommu_dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200415 ivhd->capability_offset) & EFR_FEATURE_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700416 ivrs->iv_info |= IVINFO_EFR_SUPPORTED;
417
Jason Gleneskf934fae2021-07-20 02:19:58 -0700418
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200419 current_backup = current;
420 current = acpi_ivhd_misc(current, dev);
421 ivhd->length += (current - current_backup);
422
423 /* If EFR is not supported, IVHD type 11h is reserved */
424 if (!(ivrs->iv_info & IVINFO_EFR_SUPPORTED))
425 return current;
426
427 current = acpi_fill_ivrs11(current, ivhd, nb_dev, iommu_dev);
428
429 ivhd = (struct acpi_ivrs_ivhd *)current;
430 current += sizeof(struct acpi_ivrs_ivhd);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700431 }
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200432 current -= sizeof(struct acpi_ivrs_ivhd);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700433
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200434 return current;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700435}