git: 3f0289ea7f66 - main - dmar: set acpi ivar domain on identify()

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 26 Nov 2024 22:00:35 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=3f0289ea7f66c82656a43edf6527055fd27d225d

commit 3f0289ea7f66c82656a43edf6527055fd27d225d
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-10-25 05:38:25 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-11-26 21:56:45 +0000

    dmar: set acpi ivar domain on identify()
    
    Reviewed by:    jhb
    Sponsored by:   Advanced Micro Devices (AMD)
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D47291
---
 sys/x86/iommu/intel_drv.c | 60 ++++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/sys/x86/iommu/intel_drv.c b/sys/x86/iommu/intel_drv.c
index b21c8460e830..dd2a3d1a631f 100644
--- a/sys/x86/iommu/intel_drv.c
+++ b/sys/x86/iommu/intel_drv.c
@@ -160,6 +160,27 @@ dmar_count_iter(ACPI_DMAR_HEADER *dmarh, void *arg)
 	return (1);
 }
 
+/* Remapping Hardware Static Affinity Structure lookup */
+struct rhsa_iter_arg {
+	uint64_t base;
+	u_int proxim_dom;
+};
+
+static int
+dmar_rhsa_iter(ACPI_DMAR_HEADER *dmarh, void *arg)
+{
+	struct rhsa_iter_arg *ria;
+	ACPI_DMAR_RHSA *adr;
+
+	if (dmarh->Type == ACPI_DMAR_TYPE_HARDWARE_AFFINITY) {
+		ria = arg;
+		adr = (ACPI_DMAR_RHSA *)dmarh;
+		if (adr->BaseAddress == ria->base)
+			ria->proxim_dom = adr->ProximityDomain;
+	}
+	return (1);
+}
+
 int dmar_rmrr_enable = 1;
 
 static int dmar_enable = 0;
@@ -168,6 +189,7 @@ dmar_identify(driver_t *driver, device_t parent)
 {
 	ACPI_TABLE_DMAR *dmartbl;
 	ACPI_DMAR_HARDWARE_UNIT *dmarh;
+	struct rhsa_iter_arg ria;
 	ACPI_STATUS status;
 	int i, error;
 
@@ -217,7 +239,15 @@ dmar_identify(driver_t *driver, device_t parent)
 			    i, (uintmax_t)dmarh->Address, error);
 			device_delete_child(parent, dmar_devs[i]);
 			dmar_devs[i] = NULL;
+			continue;
 		}
+
+		ria.base = dmarh->Address;
+		ria.proxim_dom = -1;
+		dmar_iterate_tbl(dmar_rhsa_iter, &ria);
+		acpi_set_domain(dmar_devs[i], ria.proxim_dom == -1 ?
+		    ACPI_DEV_DOMAIN_UNKNOWN :
+		    acpi_map_pxm_to_vm_domainid(ria.proxim_dom));
 	}
 }
 
@@ -326,34 +356,12 @@ dmar_print_caps(device_t dev, struct dmar_unit *unit,
 	    DMAR_ECAP_IRO(unit->hw_ecap));
 }
 
-/* Remapping Hardware Static Affinity Structure lookup */
-struct rhsa_iter_arg {
-	uint64_t base;
-	u_int proxim_dom;
-};
-
-static int
-dmar_rhsa_iter(ACPI_DMAR_HEADER *dmarh, void *arg)
-{
-	struct rhsa_iter_arg *ria;
-	ACPI_DMAR_RHSA *adr;
-
-	if (dmarh->Type == ACPI_DMAR_TYPE_HARDWARE_AFFINITY) {
-		ria = arg;
-		adr = (ACPI_DMAR_RHSA *)dmarh;
-		if (adr->BaseAddress == ria->base)
-			ria->proxim_dom = adr->ProximityDomain;
-	}
-	return (1);
-}
-
 static int
 dmar_attach(device_t dev)
 {
 	struct dmar_unit *unit;
 	ACPI_DMAR_HARDWARE_UNIT *dmaru;
 	struct iommu_msi_data *dmd;
-	struct rhsa_iter_arg ria;
 	uint64_t timeout;
 	int disable_pmr;
 	int i, error;
@@ -381,13 +389,7 @@ dmar_attach(device_t dev)
 	if (bootverbose)
 		dmar_print_caps(dev, unit, dmaru);
 	dmar_quirks_post_ident(unit);
-	unit->memdomain = -1;
-	ria.base = unit->base;
-	ria.proxim_dom = -1;
-	dmar_iterate_tbl(dmar_rhsa_iter, &ria);
-	if (ria.proxim_dom != -1)
-		unit->memdomain = acpi_map_pxm_to_vm_domainid(ria.proxim_dom);
-
+	unit->memdomain = acpi_get_domain(dev);
 	timeout = dmar_get_timeout();
 	TUNABLE_UINT64_FETCH("hw.iommu.dmar.timeout", &timeout);
 	dmar_update_timeout(timeout);