blob: d5a409f2eb3c662d1dbdf17d32e23328b991260d [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;
Felix Held56167c52023-06-22 23:22:19 +020039 memset(ivhd_hpet, 0, sizeof(*ivhd_hpet));
Jason Gleneskf934fae2021-07-20 02:19:58 -070040
41 ivhd_hpet->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV;
Naresh Solanki4ef89f72023-05-25 17:37:50 +020042 ivhd_hpet->handle = hndl;
43 ivhd_hpet->source_dev_id = src_devid; /* function 0 of FCH PCI device */
Jason Gleneskf934fae2021-07-20 02:19:58 -070044 ivhd_hpet->variety = IVHD_SPECIAL_DEV_HPET;
45 current += sizeof(ivrs_ivhd_special_t);
46
47 return current;
48}
49
Felix Held534cce32023-06-22 23:09:23 +020050static unsigned long ivhd_describe_f0_device(unsigned long current, uint16_t dev_id,
51 const char acpi_hid[8], uint8_t datasetting)
Jason Gleneskf934fae2021-07-20 02:19:58 -070052{
Elyes Haouas68fc51f2022-07-16 09:48:27 +020053 ivrs_ivhd_f0_entry_t *ivhd_f0 = (ivrs_ivhd_f0_entry_t *)current;
Felix Held63a4e6bd2023-06-22 23:04:19 +020054 memset(ivhd_f0, 0, sizeof(*ivhd_f0));
Jason Gleneskf934fae2021-07-20 02:19:58 -070055
56 ivhd_f0->type = IVHD_DEV_VARIABLE;
57 ivhd_f0->dev_id = dev_id;
58 ivhd_f0->dte_setting = datasetting;
Felix Held534cce32023-06-22 23:09:23 +020059
60 memcpy(ivhd_f0->hardware_id, acpi_hid, sizeof(ivhd_f0->hardware_id));
Jason Gleneskf934fae2021-07-20 02:19:58 -070061
Jason Gleneskf934fae2021-07-20 02:19:58 -070062 current += sizeof(ivrs_ivhd_f0_entry_t);
63 return current;
64}
65
66static 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;
72
73 /* Create the start range IVHD entry */
74 ivhd_range->type = IVHD_DEV_4_BYTE_START_RANGE;
75 ivhd_range->dev_id = start_devid;
76 ivhd_range->dte_setting = setting;
77 current += sizeof(ivrs_ivhd_generic_t);
78
79 /* Create the end range IVHD entry */
80 ivhd_range = (ivrs_ivhd_generic_t *)current;
81 ivhd_range->type = IVHD_DEV_4_BYTE_END_RANGE;
82 ivhd_range->dev_id = end_devid;
83 ivhd_range->dte_setting = setting;
84 current += sizeof(ivrs_ivhd_generic_t);
85
86 return current;
87}
88
89static unsigned long add_ivhd_dev_entry(struct device *parent, struct device *dev,
90 unsigned long *current, uint8_t type, uint8_t data)
91{
92 if (type == IVHD_DEV_4_BYTE_SELECT) {
93 /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */
94 *current = ALIGN_UP(*current, 4);
95 ivrs_ivhd_generic_t *ivhd_entry = (ivrs_ivhd_generic_t *)*current;
96
97 ivhd_entry->type = type;
98 ivhd_entry->dev_id = dev->path.pci.devfn | (dev->bus->secondary << 8);
99 ivhd_entry->dte_setting = data;
100 *current += sizeof(ivrs_ivhd_generic_t);
101 } else if (type == IVHD_DEV_8_BYTE_ALIAS_SELECT) {
102 ivrs_ivhd_alias_t *ivhd_entry = (ivrs_ivhd_alias_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 ivhd_entry->reserved1 = 0;
108 ivhd_entry->reserved2 = 0;
109 ivhd_entry->source_dev_id = parent->path.pci.devfn |
110 (parent->bus->secondary << 8);
111 *current += sizeof(ivrs_ivhd_alias_t);
112 }
113
114 return *current;
115}
116
117static void ivrs_add_device_or_bridge(struct device *parent, struct device *dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200118 unsigned long *current)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700119{
120 unsigned int header_type, is_pcie;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700121
122 header_type = dev->hdr_type & 0x7f;
123 is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE);
124
125 if (((header_type == PCI_HEADER_TYPE_NORMAL) ||
126 (header_type == PCI_HEADER_TYPE_BRIDGE)) && is_pcie) {
127 /* Device or Bridge is PCIe */
Jason Gleneskf934fae2021-07-20 02:19:58 -0700128 add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_4_BYTE_SELECT, 0x0);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700129 } else if ((header_type == PCI_HEADER_TYPE_NORMAL) && !is_pcie) {
130 /* Device is legacy PCI or PCI-X */
Jason Gleneskf934fae2021-07-20 02:19:58 -0700131 add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_8_BYTE_ALIAS_SELECT, 0x0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200132
Jason Gleneskf934fae2021-07-20 02:19:58 -0700133 }
134}
135
136static void add_ivhd_device_entries(struct device *parent, struct device *dev,
137 unsigned int depth, int linknum, int8_t *root_level,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200138 unsigned long *current, uint16_t nb_bus)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700139{
140 struct device *sibling;
141 struct bus *link;
142
143 if (!root_level)
144 return;
145
146 if (dev->path.type == DEVICE_PATH_PCI) {
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200147 if ((dev->bus->secondary == nb_bus) &&
Jason Gleneskf934fae2021-07-20 02:19:58 -0700148 (dev->path.pci.devfn == 0x0))
149 *root_level = depth;
150
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200151 if ((*root_level != -1) && (dev->enabled))
Jason Gleneskf934fae2021-07-20 02:19:58 -0700152 if (depth != *root_level)
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200153 ivrs_add_device_or_bridge(parent, dev, current);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700154 }
155
156 for (link = dev->link_list; link; link = link->next)
157 for (sibling = link->children; sibling; sibling =
158 sibling->sibling)
159 add_ivhd_device_entries(dev, sibling, depth + 1, depth, root_level,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200160 current, nb_bus);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700161}
162
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200163static unsigned long acpi_ivhd_misc(unsigned long current, struct device *dev)
164{
165 u8 dte_setting = IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS |
166 IVHD_DTE_SYS_MGT_NO_TRANS | IVHD_DTE_NMI_PASS |
167 IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS;
168 int8_t root_level = -1;
169 struct resource *res;
170
171 /*
172 * Add all possible PCI devices in the domain that can generate transactions
173 * processed by IOMMU. Start with device <bus>:01.0
174 */
175 current = ivhd_dev_range(current, PCI_DEVFN(0, 3) | (dev->link_list->secondary << 8),
176 0xff | (dev->link_list->subordinate << 8), 0);
177
178 add_ivhd_device_entries(NULL, dev, 0, -1, &root_level,
179 &current, dev->link_list->secondary);
180
181 res = probe_resource(dev, IOMMU_IOAPIC_IDX);
182 if (res) {
183 /* Describe IOAPIC associated with the IOMMU */
Arthur Heymansf9ee87f2023-06-07 15:29:02 +0200184 current = acpi_fill_ivrs_ioapic(current, (u8 *)(uintptr_t)res->base,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200185 PCI_DEVFN(0, 1) | (dev->link_list->secondary << 8), 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200186 }
187
188 /* If the domain has secondary bus as zero then associate HPET & FCH IOAPIC */
189 if (dev->link_list->secondary == 0) {
190 /* Describe HPET */
191 current = ivhd_describe_hpet(current, 0x00, SMBUS_DEVFN);
192 /* Describe FCH IOAPICs */
Arthur Heymansf9ee87f2023-06-07 15:29:02 +0200193 current = acpi_fill_ivrs_ioapic(current, VIO_APIC_VADDR,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200194 SMBUS_DEVFN, dte_setting);
195 }
196
197 return current;
198}
199
200static unsigned long acpi_fill_ivrs40(unsigned long current, acpi_ivrs_ivhd_t *ivhd,
201 struct device *nb_dev, struct device *iommu_dev)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700202{
Felix Held50cbb932023-06-23 18:49:26 +0200203 acpi_ivrs_ivhd40_t *ivhd_40 = (acpi_ivrs_ivhd40_t *)current;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700204 unsigned long current_backup;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700205
Felix Held50cbb932023-06-23 18:49:26 +0200206 memset(ivhd_40, 0, sizeof(acpi_ivrs_ivhd40_t));
Jason Gleneskf934fae2021-07-20 02:19:58 -0700207
208 /* Enable EFR */
209 ivhd_40->type = IVHD_BLOCK_TYPE_FULL__ACPI_HID;
210 /* For type 40h bits 6 and 7 are reserved */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200211 ivhd_40->flags = ivhd->flags & 0x3f;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700212 ivhd_40->length = sizeof(struct acpi_ivrs_ivhd_40);
213 /* BDF <bus>:00.2 */
214 ivhd_40->device_id = 0x02 | (nb_dev->bus->secondary << 8);
215 ivhd_40->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200216 ivhd_40->iommu_base_low = ivhd->iommu_base_low;
217 ivhd_40->iommu_base_high = ivhd->iommu_base_high;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700218 ivhd_40->pci_segment_group = 0x0000;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200219 ivhd_40->iommu_info = ivhd->iommu_info;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700220 /* For type 40h bits 31:28 and 12:0 are reserved */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200221 ivhd_40->iommu_attributes = ivhd->iommu_feature_info & 0xfffe000;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700222
223 if (pci_read_config32(iommu_dev, ivhd_40->capability_offset) & EFR_FEATURE_SUP) {
Arthur Heymans4c684872022-04-19 21:44:22 +0200224 ivhd_40->efr_reg_image_low = read32p(ivhd_40->iommu_base_low + 0x30);
225 ivhd_40->efr_reg_image_high = read32p(ivhd_40->iommu_base_low + 0x34);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700226 }
227
228 current += sizeof(acpi_ivrs_ivhd40_t);
229
230 /* Now repeat all the device entries from type 10h */
231 current_backup = current;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200232 current = acpi_ivhd_misc(current, nb_dev->bus->dev);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700233
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200234 if (nb_dev->bus->secondary == 0) {
235 /* Describe EMMC */
Felix Held47ed2712023-06-20 19:17:43 +0200236 if (CONFIG(SOC_AMD_COMMON_BLOCK_EMMC)) {
237 /* PCI_DEVFN(0x13, 1) doesn't exist in the hardware, but it's what the
238 * reference code uses. Maybe to have a unique PCI device to put into
239 * the field that doesn't collide with any existing device? */
240 current = ivhd_describe_f0_device(current, PCI_DEVFN(0x13, 1),
Felix Held534cce32023-06-22 23:09:23 +0200241 "AMDI0040",
Felix Held47ed2712023-06-20 19:17:43 +0200242 IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS |
243 IVHD_DTE_SYS_MGT_TRANS | IVHD_DTE_NMI_PASS |
244 IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS);
245 }
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200246 }
Jason Gleneskf934fae2021-07-20 02:19:58 -0700247 ivhd_40->length += (current - current_backup);
248
249 return current;
250}
251
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200252static unsigned long acpi_fill_ivrs11(unsigned long current, acpi_ivrs_ivhd_t *ivhd,
253 struct device *nb_dev, struct device *iommu_dev)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700254{
Felix Held50cbb932023-06-23 18:49:26 +0200255 acpi_ivrs_ivhd11_t *ivhd_11 = (acpi_ivrs_ivhd11_t *)current;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700256 ivhd11_iommu_attr_t *ivhd11_attr_ptr;
257 unsigned long current_backup;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700258
259 /*
260 * In order to utilize all features, firmware should expose type 11h
261 * IVHD which supersedes the type 10h.
262 */
Felix Held50cbb932023-06-23 18:49:26 +0200263 memset(ivhd_11, 0, sizeof(acpi_ivrs_ivhd11_t));
Jason Gleneskf934fae2021-07-20 02:19:58 -0700264
265 /* Enable EFR */
266 ivhd_11->type = IVHD_BLOCK_TYPE_FULL__FIXED;
267 /* For type 11h bits 6 and 7 are reserved */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200268 ivhd_11->flags = ivhd->flags & 0x3f;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700269 ivhd_11->length = sizeof(struct acpi_ivrs_ivhd_11);
270 /* BDF <bus>:00.2 */
271 ivhd_11->device_id = 0x02 | (nb_dev->bus->secondary << 8);
272 ivhd_11->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200273 ivhd_11->iommu_base_low = ivhd->iommu_base_low;
274 ivhd_11->iommu_base_high = ivhd->iommu_base_high;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700275 ivhd_11->pci_segment_group = 0x0000;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200276 ivhd_11->iommu_info = ivhd->iommu_info;
277 ivhd11_attr_ptr = (ivhd11_iommu_attr_t *)&ivhd->iommu_feature_info;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700278 ivhd_11->iommu_attributes.perf_counters = ivhd11_attr_ptr->perf_counters;
279 ivhd_11->iommu_attributes.perf_counter_banks = ivhd11_attr_ptr->perf_counter_banks;
280 ivhd_11->iommu_attributes.msi_num_ppr = ivhd11_attr_ptr->msi_num_ppr;
281
282 if (pci_read_config32(iommu_dev, ivhd_11->capability_offset) & EFR_FEATURE_SUP) {
Arthur Heymans4c684872022-04-19 21:44:22 +0200283 ivhd_11->efr_reg_image_low = read32p(ivhd_11->iommu_base_low + 0x30);
284 ivhd_11->efr_reg_image_high = read32p(ivhd_11->iommu_base_low + 0x34);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700285 }
286
287 current += sizeof(acpi_ivrs_ivhd11_t);
288
289 /* Now repeat all the device entries from type 10h */
290 current_backup = current;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200291 current = acpi_ivhd_misc(current, nb_dev->bus->dev);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700292 ivhd_11->length += (current - current_backup);
293
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200294 return acpi_fill_ivrs40(current, ivhd, nb_dev, iommu_dev);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700295}
296
297unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current)
298{
299 unsigned long current_backup;
300 uint64_t mmio_x30_value;
301 uint64_t mmio_x18_value;
302 uint64_t mmio_x4000_value;
303 uint32_t cap_offset_0;
304 uint32_t cap_offset_10;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200305 struct acpi_ivrs_ivhd *ivhd;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700306 struct device *iommu_dev;
307 struct device *nb_dev;
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200308 struct device *dev = NULL;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700309
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200310 ivhd = &ivrs->ivhd;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700311
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200312 while ((dev = dev_find_path(dev, DEVICE_PATH_DOMAIN)) != NULL) {
Jason Gleneskf934fae2021-07-20 02:19:58 -0700313
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200314 nb_dev = pcidev_path_behind(dev->link_list, PCI_DEVFN(0, 0));
315 iommu_dev = pcidev_path_behind(dev->link_list, PCI_DEVFN(0, 2));
316 if (!nb_dev) {
317 printk(BIOS_WARNING, "%s: Northbridge device not present!\n", __func__);
318 printk(BIOS_WARNING, "%s: IVRS table not generated...\n", __func__);
319 return (unsigned long)ivrs;
320 }
Jason Gleneskf934fae2021-07-20 02:19:58 -0700321
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200322 if (!iommu_dev) {
323 printk(BIOS_WARNING, "%s: IOMMU device not found\n", __func__);
324 return (unsigned long)ivrs;
325 }
Jason Gleneskf934fae2021-07-20 02:19:58 -0700326
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200327 ivhd->type = IVHD_BLOCK_TYPE_LEGACY__FIXED;
328 ivhd->length = sizeof(struct acpi_ivrs_ivhd);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700329
330 /* BDF <bus>:00.2 */
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200331 ivhd->device_id = 0x02 | (nb_dev->bus->secondary << 8);
332 ivhd->capability_offset = pci_find_capability(iommu_dev, IOMMU_CAP_ID);
333 ivhd->iommu_base_low = pci_read_config32(iommu_dev, 0x44) & 0xffffc000;
334 ivhd->iommu_base_high = pci_read_config32(iommu_dev, 0x48);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700335
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200336 cap_offset_0 = pci_read_config32(iommu_dev, ivhd->capability_offset);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700337 cap_offset_10 = pci_read_config32(iommu_dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200338 ivhd->capability_offset + 0x10);
339 mmio_x18_value = read64p(ivhd->iommu_base_low + 0x18);
340 mmio_x30_value = read64p(ivhd->iommu_base_low + 0x30);
341 mmio_x4000_value = read64p(ivhd->iommu_base_low + 0x4000);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700342
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200343 ivhd->flags |= ((mmio_x30_value & MMIO_EXT_FEATURE_PPR_SUP) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700344 IVHD_FLAG_PPE_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200345 ivhd->flags |= ((mmio_x30_value & MMIO_EXT_FEATURE_PRE_F_SUP) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700346 IVHD_FLAG_PREF_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200347 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_COHERENT) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700348 IVHD_FLAG_COHERENT : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200349 ivhd->flags |= ((cap_offset_0 & CAP_OFFSET_0_IOTLB_SP) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700350 IVHD_FLAG_IOTLB_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200351 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_ISOC) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700352 IVHD_FLAG_ISOC : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200353 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_RES_PASS_PW) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700354 IVHD_FLAG_RES_PASS_PW : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200355 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_PASS_PW) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700356 IVHD_FLAG_PASS_PW : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200357 ivhd->flags |= ((mmio_x18_value & MMIO_CTRL_HT_TUN_EN) ?
Jason Gleneskf934fae2021-07-20 02:19:58 -0700358 IVHD_FLAG_HT_TUN_EN : 0);
359
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200360 ivhd->pci_segment_group = 0x0000;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700361
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200362 ivhd->iommu_info = pci_read_config16(iommu_dev,
363 ivhd->capability_offset + 0x10) & 0x1F;
364 ivhd->iommu_info |= (pci_read_config16(iommu_dev,
365 ivhd->capability_offset + 0xC) & 0x1F) << IOMMU_INFO_UNIT_ID_SHIFT;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700366
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200367 ivhd->iommu_feature_info = 0;
368 ivhd->iommu_feature_info |= (mmio_x30_value & MMIO_EXT_FEATURE_HATS_MASK)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700369 << (IOMMU_FEATURE_HATS_SHIFT - MMIO_EXT_FEATURE_HATS_SHIFT);
370
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200371 ivhd->iommu_feature_info |= (mmio_x30_value & MMIO_EXT_FEATURE_GATS_MASK)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700372 << (IOMMU_FEATURE_GATS_SHIFT - MMIO_EXT_FEATURE_GATS_SHIFT);
373
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200374 ivhd->iommu_feature_info |= (cap_offset_10 & CAP_OFFSET_10_MSI_NUM_PPR)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700375 >> (CAP_OFFSET_10_MSI_NUM_PPR_SHIFT
376 - IOMMU_FEATURE_MSI_NUM_PPR_SHIFT);
377
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200378 ivhd->iommu_feature_info |= (mmio_x4000_value &
Jason Gleneskf934fae2021-07-20 02:19:58 -0700379 MMIO_CNT_CFG_N_COUNTER_BANKS)
380 << (IOMMU_FEATURE_PN_BANKS_SHIFT - MMIO_CNT_CFG_N_CNT_BANKS_SHIFT);
381
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200382 ivhd->iommu_feature_info |= (mmio_x4000_value & MMIO_CNT_CFG_N_COUNTER)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700383 << (IOMMU_FEATURE_PN_COUNTERS_SHIFT - MMIO_CNT_CFG_N_COUNTER_SHIFT);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200384 ivhd->iommu_feature_info |= (mmio_x30_value &
Jason Gleneskf934fae2021-07-20 02:19:58 -0700385 MMIO_EXT_FEATURE_PAS_MAX_MASK)
386 >> (MMIO_EXT_FEATURE_PAS_MAX_SHIFT - IOMMU_FEATURE_PA_SMAX_SHIFT);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200387 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_HE_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700388 ? IOMMU_FEATURE_HE_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200389 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_GA_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700390 ? IOMMU_FEATURE_GA_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200391 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_IA_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700392 ? IOMMU_FEATURE_IA_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200393 ivhd->iommu_feature_info |= (mmio_x30_value &
Jason Gleneskf934fae2021-07-20 02:19:58 -0700394 MMIO_EXT_FEATURE_GLX_SUP_MASK)
395 >> (MMIO_EXT_FEATURE_GLX_SHIFT - IOMMU_FEATURE_GLX_SHIFT);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200396 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_GT_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700397 ? IOMMU_FEATURE_GT_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200398 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_NX_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700399 ? IOMMU_FEATURE_NX_SUP : 0);
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200400 ivhd->iommu_feature_info |= ((mmio_x30_value & MMIO_EXT_FEATURE_XT_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700401 ? IOMMU_FEATURE_XT_SUP : 0);
402
403 /* Enable EFR if supported */
404 ivrs->iv_info = pci_read_config32(iommu_dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200405 ivhd->capability_offset + 0x10) & 0x007fffe0;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700406 if (pci_read_config32(iommu_dev,
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200407 ivhd->capability_offset) & EFR_FEATURE_SUP)
Jason Gleneskf934fae2021-07-20 02:19:58 -0700408 ivrs->iv_info |= IVINFO_EFR_SUPPORTED;
409
Jason Gleneskf934fae2021-07-20 02:19:58 -0700410
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200411 current_backup = current;
412 current = acpi_ivhd_misc(current, dev);
413 ivhd->length += (current - current_backup);
414
415 /* If EFR is not supported, IVHD type 11h is reserved */
416 if (!(ivrs->iv_info & IVINFO_EFR_SUPPORTED))
417 return current;
418
419 current = acpi_fill_ivrs11(current, ivhd, nb_dev, iommu_dev);
420
421 ivhd = (struct acpi_ivrs_ivhd *)current;
422 current += sizeof(struct acpi_ivrs_ivhd);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700423 }
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200424 current -= sizeof(struct acpi_ivrs_ivhd);
Jason Gleneskf934fae2021-07-20 02:19:58 -0700425
Naresh Solanki4ef89f72023-05-25 17:37:50 +0200426 return current;
Jason Gleneskf934fae2021-07-20 02:19:58 -0700427}