blob: 1629ff914f3c6b5c0fd15a58dabb58b50115ecda [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
Naresh Solanki4ef89f72023-05-25 17:37:50 +020020static unsigned long _acpi_fill_ivrs_ioapic(unsigned long current, void *ioapic_base,
21 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 +020036unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current)
37{
38 uint32_t dte_setting = IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS |
39 IVHD_DTE_SYS_MGT_NO_TRANS | IVHD_DTE_NMI_PASS |
40 IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS;
41
42 current = _acpi_fill_ivrs_ioapic(current, VIO_APIC_VADDR,
43 SMBUS_DEVFN, dte_setting);
44 return _acpi_fill_ivrs_ioapic(current, (u8 *)GNB_IO_APIC_ADDR,
45 PCI_DEVFN(0, 1), 0);
46}
47
48static unsigned long ivhd_describe_hpet(unsigned long current, uint8_t hndl, uint16_t src_devid)
Jason Gleneskf934fae2021-07-20 02:19:58 -070049{
50 ivrs_ivhd_special_t *ivhd_hpet = (ivrs_ivhd_special_t *)current;
51
52 ivhd_hpet->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV;
53 ivhd_hpet->reserved = 0x0000;
54 ivhd_hpet->dte_setting = 0x00;
Naresh Solanki4ef89f72023-05-25 17:37:50 +020055 ivhd_hpet->handle = hndl;
56 ivhd_hpet->source_dev_id = src_devid; /* function 0 of FCH PCI device */
Jason Gleneskf934fae2021-07-20 02:19:58 -070057 ivhd_hpet->variety = IVHD_SPECIAL_DEV_HPET;
58 current += sizeof(ivrs_ivhd_special_t);
59
60 return current;
61}
62
63static unsigned long ivhd_describe_f0_device(unsigned long current,
64 uint16_t dev_id, uint8_t datasetting)
65{
Elyes Haouas68fc51f2022-07-16 09:48:27 +020066 ivrs_ivhd_f0_entry_t *ivhd_f0 = (ivrs_ivhd_f0_entry_t *)current;
Jason Gleneskf934fae2021-07-20 02:19:58 -070067
68 ivhd_f0->type = IVHD_DEV_VARIABLE;
69 ivhd_f0->dev_id = dev_id;
70 ivhd_f0->dte_setting = datasetting;
71 ivhd_f0->hardware_id[0] = 'A';
72 ivhd_f0->hardware_id[1] = 'M';
73 ivhd_f0->hardware_id[2] = 'D';
74 ivhd_f0->hardware_id[3] = 'I';
75 ivhd_f0->hardware_id[4] = '0';
76 ivhd_f0->hardware_id[5] = '0';
77 ivhd_f0->hardware_id[6] = '4';
78 ivhd_f0->hardware_id[7] = '0';
79
80 memset(ivhd_f0->compatible_id, 0, sizeof(ivhd_f0->compatible_id));
81
82 ivhd_f0->uuid_format = 0;
83 ivhd_f0->uuid_length = 0;
84
85 current += sizeof(ivrs_ivhd_f0_entry_t);
86 return current;
87}
88
89static unsigned long ivhd_dev_range(unsigned long current, uint16_t start_devid,
90 uint16_t end_devid, uint8_t setting)
91{
92 /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */
93 current = ALIGN_UP(current, 4);
94 ivrs_ivhd_generic_t *ivhd_range = (ivrs_ivhd_generic_t *)current;
95
96 /* Create the start range IVHD entry */
97 ivhd_range->type = IVHD_DEV_4_BYTE_START_RANGE;
98 ivhd_range->dev_id = start_devid;
99 ivhd_range->dte_setting = setting;
100 current += sizeof(ivrs_ivhd_generic_t);
101
102 /* Create the end range IVHD entry */
103 ivhd_range = (ivrs_ivhd_generic_t *)current;
104 ivhd_range->type = IVHD_DEV_4_BYTE_END_RANGE;
105 ivhd_range->dev_id = end_devid;
106 ivhd_range->dte_setting = setting;
107 current += sizeof(ivrs_ivhd_generic_t);
108
109 return current;
110}
111
112static unsigned long add_ivhd_dev_entry(struct device *parent, struct device *dev,
113 unsigned long *current, uint8_t type, uint8_t data)
114{
115 if (type == IVHD_DEV_4_BYTE_SELECT) {
116 /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */
117 *current = ALIGN_UP(*current, 4);
118 ivrs_ivhd_generic_t *ivhd_entry = (ivrs_ivhd_generic_t *)*current;
119
120 ivhd_entry->type = type;
121 ivhd_entry->dev_id = dev->path.pci.devfn | (dev->bus->secondary << 8);
122 ivhd_entry->dte_setting = data;
123 *current += sizeof(ivrs_ivhd_generic_t);
124 } else if (type == IVHD_DEV_8_BYTE_ALIAS_SELECT) {
125 ivrs_ivhd_alias_t *ivhd_entry = (ivrs_ivhd_alias_t *)*current;
126
127 ivhd_entry->type = type;
128 ivhd_entry->dev_id = dev->path.pci.devfn | (dev->bus->secondary << 8);
129 ivhd_entry->dte_setting = data;
130 ivhd_entry->reserved1 = 0;
131 ivhd_entry->reserved2 = 0;
132 ivhd_entry->source_dev_id = parent->path.pci.devfn |
133 (parent->bus->secondary << 8);
134 *current += sizeof(ivrs_ivhd_alias_t);
135 }
136
137 return *current;
138}
139
140static void ivrs_add_device_or_bridge(struct device *parent, struct device *dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200141 unsigned long *current)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700142{
143 unsigned int header_type, is_pcie;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700144
145 header_type = dev->hdr_type & 0x7f;
146 is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE);
147
148 if (((header_type == PCI_HEADER_TYPE_NORMAL) ||
149 (header_type == PCI_HEADER_TYPE_BRIDGE)) && is_pcie) {
150 /* Device or Bridge is PCIe */
Jason Gleneskf934fae2021-07-20 02:19:58 -0700151 add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_4_BYTE_SELECT, 0x0);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700152 } else if ((header_type == PCI_HEADER_TYPE_NORMAL) && !is_pcie) {
153 /* Device is legacy PCI or PCI-X */
Jason Gleneskf934fae2021-07-20 02:19:58 -0700154 add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_8_BYTE_ALIAS_SELECT, 0x0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200155
Jason Gleneskf934fae2021-07-20 02:19:58 -0700156 }
157}
158
159static void add_ivhd_device_entries(struct device *parent, struct device *dev,
160 unsigned int depth, int linknum, int8_t *root_level,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200161 unsigned long *current, uint16_t nb_bus)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700162{
163 struct device *sibling;
164 struct bus *link;
165
166 if (!root_level)
167 return;
168
169 if (dev->path.type == DEVICE_PATH_PCI) {
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200170 if ((dev->bus->secondary == nb_bus) &&
Jason Gleneskf934fae2021-07-20 02:19:58 -0700171 (dev->path.pci.devfn == 0x0))
172 *root_level = depth;
173
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200174 if ((*root_level != -1) && (dev->enabled))
Jason Gleneskf934fae2021-07-20 02:19:58 -0700175 if (depth != *root_level)
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200176 ivrs_add_device_or_bridge(parent, dev, current);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700177 }
178
179 for (link = dev->link_list; link; link = link->next)
180 for (sibling = link->children; sibling; sibling =
181 sibling->sibling)
182 add_ivhd_device_entries(dev, sibling, depth + 1, depth, root_level,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200183 current, nb_bus);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700184}
185
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200186static unsigned long acpi_ivhd_misc(unsigned long current, struct device *dev)
187{
188 u8 dte_setting = IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS |
189 IVHD_DTE_SYS_MGT_NO_TRANS | IVHD_DTE_NMI_PASS |
190 IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS;
191 int8_t root_level = -1;
192 struct resource *res;
193
194 /*
195 * Add all possible PCI devices in the domain that can generate transactions
196 * processed by IOMMU. Start with device <bus>:01.0
197 */
198 current = ivhd_dev_range(current, PCI_DEVFN(0, 3) | (dev->link_list->secondary << 8),
199 0xff | (dev->link_list->subordinate << 8), 0);
200
201 add_ivhd_device_entries(NULL, dev, 0, -1, &root_level,
202 &current, dev->link_list->secondary);
203
204 res = probe_resource(dev, IOMMU_IOAPIC_IDX);
205 if (res) {
206 /* Describe IOAPIC associated with the IOMMU */
207 current = _acpi_fill_ivrs_ioapic(current, (u8 *)(uintptr_t)res->base,
208 PCI_DEVFN(0, 1) | (dev->link_list->secondary << 8), 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200209 }
210
211 /* If the domain has secondary bus as zero then associate HPET & FCH IOAPIC */
212 if (dev->link_list->secondary == 0) {
213 /* Describe HPET */
214 current = ivhd_describe_hpet(current, 0x00, SMBUS_DEVFN);
215 /* Describe FCH IOAPICs */
216 current = _acpi_fill_ivrs_ioapic(current, VIO_APIC_VADDR,
217 SMBUS_DEVFN, dte_setting);
218 }
219
220 return current;
221}
222
223static unsigned long acpi_fill_ivrs40(unsigned long current, acpi_ivrs_ivhd_t *ivhd,
224 struct device *nb_dev, struct device *iommu_dev)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700225{
226 acpi_ivrs_ivhd40_t *ivhd_40;
227 unsigned long current_backup;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700228
229 memset((void *)current, 0, sizeof(acpi_ivrs_ivhd40_t));
230 ivhd_40 = (acpi_ivrs_ivhd40_t *)current;
231
232 /* Enable EFR */
233 ivhd_40->type = IVHD_BLOCK_TYPE_FULL__ACPI_HID;
234 /* For type 40h bits 6 and 7 are reserved */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200235 ivhd_40->flags = ivhd->flags & 0x3f;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700236 ivhd_40->length = sizeof(struct acpi_ivrs_ivhd_40);
237 /* BDF <bus>:00.2 */
238 ivhd_40->device_id = 0x02 | (nb_dev->bus->secondary << 8);
239 ivhd_40->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200240 ivhd_40->iommu_base_low = ivhd->iommu_base_low;
241 ivhd_40->iommu_base_high = ivhd->iommu_base_high;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700242 ivhd_40->pci_segment_group = 0x0000;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200243 ivhd_40->iommu_info = ivhd->iommu_info;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700244 /* For type 40h bits 31:28 and 12:0 are reserved */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200245 ivhd_40->iommu_attributes = ivhd->iommu_feature_info & 0xfffe000;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700246
247 if (pci_read_config32(iommu_dev, ivhd_40->capability_offset) & EFR_FEATURE_SUP) {
Arthur Heymans4c684872022-04-19 21:44:22 +0200248 ivhd_40->efr_reg_image_low = read32p(ivhd_40->iommu_base_low + 0x30);
249 ivhd_40->efr_reg_image_high = read32p(ivhd_40->iommu_base_low + 0x34);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700250 }
251
252 current += sizeof(acpi_ivrs_ivhd40_t);
253
254 /* Now repeat all the device entries from type 10h */
255 current_backup = current;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200256 current = acpi_ivhd_misc(current, nb_dev->bus->dev);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700257
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200258 if (nb_dev->bus->secondary == 0) {
259 /* Describe EMMC */
260 current = ivhd_describe_f0_device(current, PCI_DEVFN(0x13, 1),
261 IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS |
262 IVHD_DTE_SYS_MGT_TRANS | IVHD_DTE_NMI_PASS |
263 IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS);
264 }
Jason Gleneskf934fae2021-07-20 02:19:58 -0700265 ivhd_40->length += (current - current_backup);
266
267 return current;
268}
269
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200270static unsigned long acpi_fill_ivrs11(unsigned long current, acpi_ivrs_ivhd_t *ivhd,
271 struct device *nb_dev, struct device *iommu_dev)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700272{
273 acpi_ivrs_ivhd11_t *ivhd_11;
274 ivhd11_iommu_attr_t *ivhd11_attr_ptr;
275 unsigned long current_backup;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700276
277 /*
278 * In order to utilize all features, firmware should expose type 11h
279 * IVHD which supersedes the type 10h.
280 */
281 memset((void *)current, 0, sizeof(acpi_ivrs_ivhd11_t));
282 ivhd_11 = (acpi_ivrs_ivhd11_t *)current;
283
284 /* Enable EFR */
285 ivhd_11->type = IVHD_BLOCK_TYPE_FULL__FIXED;
286 /* For type 11h bits 6 and 7 are reserved */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200287 ivhd_11->flags = ivhd->flags & 0x3f;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700288 ivhd_11->length = sizeof(struct acpi_ivrs_ivhd_11);
289 /* BDF <bus>:00.2 */
290 ivhd_11->device_id = 0x02 | (nb_dev->bus->secondary << 8);
291 ivhd_11->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200292 ivhd_11->iommu_base_low = ivhd->iommu_base_low;
293 ivhd_11->iommu_base_high = ivhd->iommu_base_high;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700294 ivhd_11->pci_segment_group = 0x0000;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200295 ivhd_11->iommu_info = ivhd->iommu_info;
296 ivhd11_attr_ptr = (ivhd11_iommu_attr_t *)&ivhd->iommu_feature_info;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700297 ivhd_11->iommu_attributes.perf_counters = ivhd11_attr_ptr->perf_counters;
298 ivhd_11->iommu_attributes.perf_counter_banks = ivhd11_attr_ptr->perf_counter_banks;
299 ivhd_11->iommu_attributes.msi_num_ppr = ivhd11_attr_ptr->msi_num_ppr;
300
301 if (pci_read_config32(iommu_dev, ivhd_11->capability_offset) & EFR_FEATURE_SUP) {
Arthur Heymans4c684872022-04-19 21:44:22 +0200302 ivhd_11->efr_reg_image_low = read32p(ivhd_11->iommu_base_low + 0x30);
303 ivhd_11->efr_reg_image_high = read32p(ivhd_11->iommu_base_low + 0x34);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700304 }
305
306 current += sizeof(acpi_ivrs_ivhd11_t);
307
308 /* Now repeat all the device entries from type 10h */
309 current_backup = current;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200310 current = acpi_ivhd_misc(current, nb_dev->bus->dev);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700311 ivhd_11->length += (current - current_backup);
312
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200313 return acpi_fill_ivrs40(current, ivhd, nb_dev, iommu_dev);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700314}
315
316unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current)
317{
318 unsigned long current_backup;
319 uint64_t mmio_x30_value;
320 uint64_t mmio_x18_value;
321 uint64_t mmio_x4000_value;
322 uint32_t cap_offset_0;
323 uint32_t cap_offset_10;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200324 struct acpi_ivrs_ivhd *ivhd;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700325 struct device *iommu_dev;
326 struct device *nb_dev;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200327 struct device *dev = NULL;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700328
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200329 ivhd = &ivrs->ivhd;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700330
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200331 while ((dev = dev_find_path(dev, DEVICE_PATH_DOMAIN)) != NULL) {
Jason Gleneskf934fae2021-07-20 02:19:58 -0700332
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200333 nb_dev = pcidev_path_behind(dev->link_list, PCI_DEVFN(0, 0));
334 iommu_dev = pcidev_path_behind(dev->link_list, PCI_DEVFN(0, 2));
335 if (!nb_dev) {
336 printk(BIOS_WARNING, "%s: Northbridge device not present!\n", __func__);
337 printk(BIOS_WARNING, "%s: IVRS table not generated...\n", __func__);
338 return (unsigned long)ivrs;
339 }
Jason Gleneskf934fae2021-07-20 02:19:58 -0700340
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200341 if (!iommu_dev) {
342 printk(BIOS_WARNING, "%s: IOMMU device not found\n", __func__);
343 return (unsigned long)ivrs;
344 }
Jason Gleneskf934fae2021-07-20 02:19:58 -0700345
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200346 ivhd->type = IVHD_BLOCK_TYPE_LEGACY__FIXED;
347 ivhd->length = sizeof(struct acpi_ivrs_ivhd);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700348
349 /* BDF <bus>:00.2 */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200350 ivhd->device_id = 0x02 | (nb_dev->bus->secondary << 8);
351 ivhd->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID);
352 ivhd->iommu_base_low = pci_read_config32(iommu_dev, 0x44) & 0xffffc000;
353 ivhd->iommu_base_high = pci_read_config32(iommu_dev, 0x48);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700354
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200355 cap_offset_0 = pci_read_config32(iommu_dev, ivhd->capability_offset);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700356 cap_offset_10 = pci_read_config32(iommu_dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200357 ivhd->capability_offset + 0x10);
358 mmio_x18_value = read64p(ivhd->iommu_base_low + 0x18);
359 mmio_x30_value = read64p(ivhd->iommu_base_low + 0x30);
360 mmio_x4000_value = read64p(ivhd->iommu_base_low + 0x4000);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700361
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200362 ivhd->flags |= ((mmio_x30_value & MMIO_EXT_FEATURE_PPR_SUP) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700363 IVHD_FLAG_PPE_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200364 ivhd->flags |= ((mmio_x30_value & MMIO_EXT_FEATURE_PRE_F_SUP) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700365 IVHD_FLAG_PREF_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200366 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_COHERENT) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700367 IVHD_FLAG_COHERENT : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200368 ivhd->flags |= ((cap_offset_0 & CAP_OFFSET_0_IOTLB_SP) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700369 IVHD_FLAG_IOTLB_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200370 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_ISOC) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700371 IVHD_FLAG_ISOC : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200372 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_RES_PASS_PW) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700373 IVHD_FLAG_RES_PASS_PW : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200374 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_PASS_PW) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700375 IVHD_FLAG_PASS_PW : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200376 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_HT_TUN_EN) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700377 IVHD_FLAG_HT_TUN_EN : 0);
378
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200379 ivhd->pci_segment_group = 0x0000;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700380
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200381 ivhd->iommu_info = pci_read_config16(iommu_dev,
382 ivhd->capability_offset + 0x10) & 0x1F;
383 ivhd->iommu_info |= (pci_read_config16(iommu_dev,
384 ivhd->capability_offset + 0xC) & 0x1F) << IOMMU_INFO_UNIT_ID_SHIFT;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700385
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200386 ivhd->iommu_feature_info = 0;
387 ivhd->iommu_feature_info |= (mmio_x30_value & MMIO_EXT_FEATURE_HATS_MASK)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700388 << (IOMMU_FEATURE_HATS_SHIFT - MMIO_EXT_FEATURE_HATS_SHIFT);
389
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200390 ivhd->iommu_feature_info |= (mmio_x30_value & MMIO_EXT_FEATURE_GATS_MASK)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700391 << (IOMMU_FEATURE_GATS_SHIFT - MMIO_EXT_FEATURE_GATS_SHIFT);
392
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200393 ivhd->iommu_feature_info |= (cap_offset_10 & CAP_OFFSET_10_MSI_NUM_PPR)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700394 >> (CAP_OFFSET_10_MSI_NUM_PPR_SHIFT
395 - IOMMU_FEATURE_MSI_NUM_PPR_SHIFT);
396
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200397 ivhd->iommu_feature_info |= (mmio_x4000_value &
Jason Gleneskf934fae2021-07-20 02:19:58 -0700398 MMIO_CNT_CFG_N_COUNTER_BANKS)
399 << (IOMMU_FEATURE_PN_BANKS_SHIFT - MMIO_CNT_CFG_N_CNT_BANKS_SHIFT);
400
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200401 ivhd->iommu_feature_info |= (mmio_x4000_value & MMIO_CNT_CFG_N_COUNTER)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700402 << (IOMMU_FEATURE_PN_COUNTERS_SHIFT - MMIO_CNT_CFG_N_COUNTER_SHIFT);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200403 ivhd->iommu_feature_info |= (mmio_x30_value &
Jason Gleneskf934fae2021-07-20 02:19:58 -0700404 MMIO_EXT_FEATURE_PAS_MAX_MASK)
405 >> (MMIO_EXT_FEATURE_PAS_MAX_SHIFT - IOMMU_FEATURE_PA_SMAX_SHIFT);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200406 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_HE_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700407 ? IOMMU_FEATURE_HE_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200408 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_GA_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700409 ? IOMMU_FEATURE_GA_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200410 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_IA_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700411 ? IOMMU_FEATURE_IA_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200412 ivhd->iommu_feature_info |= (mmio_x30_value &
Jason Gleneskf934fae2021-07-20 02:19:58 -0700413 MMIO_EXT_FEATURE_GLX_SUP_MASK)
414 >> (MMIO_EXT_FEATURE_GLX_SHIFT - IOMMU_FEATURE_GLX_SHIFT);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200415 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_GT_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700416 ? IOMMU_FEATURE_GT_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200417 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_NX_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700418 ? IOMMU_FEATURE_NX_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200419 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_XT_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700420 ? IOMMU_FEATURE_XT_SUP : 0);
421
422 /* Enable EFR if supported */
423 ivrs->iv_info = pci_read_config32(iommu_dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200424 ivhd->capability_offset + 0x10) & 0x007fffe0;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700425 if (pci_read_config32(iommu_dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200426 ivhd->capability_offset) & EFR_FEATURE_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700427 ivrs->iv_info |= IVINFO_EFR_SUPPORTED;
428
Jason Gleneskf934fae2021-07-20 02:19:58 -0700429
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200430 current_backup = current;
431 current = acpi_ivhd_misc(current, dev);
432 ivhd->length += (current - current_backup);
433
434 /* If EFR is not supported, IVHD type 11h is reserved */
435 if (!(ivrs->iv_info & IVINFO_EFR_SUPPORTED))
436 return current;
437
438 current = acpi_fill_ivrs11(current, ivhd, nb_dev, iommu_dev);
439
440 ivhd = (struct acpi_ivrs_ivhd *)current;
441 current += sizeof(struct acpi_ivrs_ivhd);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700442 }
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200443 current -= sizeof(struct acpi_ivrs_ivhd);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700444
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200445 return current;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700446}