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
This commit is contained in:
Konstantin Belousov 2024-11-10 00:29:20 +02:00
parent edab5a280e
commit 9805e5b071

View File

@ -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);