git: 9805e5b071a1 - main - amdiommu: short-circuit all amdiommu_find_unit() functions

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 09 Nov 2024 22:32:56 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=9805e5b071a10711cfcd3c7a750ac4a4d14b6e3f

commit 9805e5b071a10711cfcd3c7a750ac4a4d14b6e3f
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-11-09 22:29:20 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-11-09 22:32:37 +0000

    amdiommu: short-circuit all amdiommu_find_unit() functions
    
    for the case where amdiommu is not enabled.  In this case, it does not
    matter if IVHD does not describe some device.  Similarly, no unit can be
    found for a device, because units are not instantiated, but it does not
    matter.
    
    Reported by:    mav
    Sponsored by:   Advanced Micro Devices (AMD)
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
---
 sys/x86/iommu/amd_drv.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sys/x86/iommu/amd_drv.c b/sys/x86/iommu/amd_drv.c
index d8f3c25fcae0..d35c6c8dddc8 100644
--- a/sys/x86/iommu/amd_drv.c
+++ b/sys/x86/iommu/amd_drv.c
@@ -879,6 +879,9 @@ amdiommu_find_unit(device_t dev, struct amdiommu_unit **unitp, uint16_t *ridp,
 	int error, flags;
 	bool res;
 
+	if (!amdiommu_enable)
+		return (ENXIO);
+
 	if (device_get_devclass(device_get_parent(dev)) !=
 	    devclass_find("pci"))
 		return (ENXIO);
@@ -943,6 +946,9 @@ amdiommu_find_unit_for_ioapic(int apic_id, struct amdiommu_unit **unitp,
 	device_t apic_dev;
 	bool res;
 
+	if (!amdiommu_enable)
+		return (ENXIO);
+
 	bzero(&ifu, sizeof(ifu));
 	ifu.type = IFU_DEV_IOAPIC;
 	ifu.devno = apic_id;
@@ -992,6 +998,9 @@ amdiommu_find_unit_for_hpet(device_t hpet, struct amdiommu_unit **unitp,
 	int hpet_no;
 	bool res;
 
+	if (!amdiommu_enable)
+		return (ENXIO);
+
 	hpet_no = hpet_get_uid(hpet);
 	bzero(&ifu, sizeof(ifu));
 	ifu.type = IFU_DEV_HPET;
@@ -1042,7 +1051,7 @@ amdiommu_find_method(device_t dev, bool verbose)
 
 	error = amdiommu_find_unit(dev, &unit, &rid, &dte, &edte, verbose);
 	if (error != 0) {
-		if (verbose)
+		if (verbose && amdiommu_enable)
 			device_printf(dev,
 			    "cannot find amdiommu unit, error %d\n",
 			    error);