intel: Skip ioctls for querying device info when hardware is unsupported

While enumerating devices on a system with multiple implementations,
unnecessary ioctls will be issued before a driver checks if it supports a
given device.
This patch makes the driver fail early based on a intel_device_info.ver
check with 2 new parameters added to intel_get_device_info_from_fd.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27166>
This commit is contained in:
Tranquillity Codes
2024-01-19 06:02:13 +01:00
committed by Marge Bot
parent 96504d51a2
commit 3fd44345c4
12 changed files with 18 additions and 12 deletions

View File

@@ -724,7 +724,7 @@ crocus_screen_create(int fd, const struct pipe_screen_config *config)
if (!screen)
return NULL;
if (!intel_get_device_info_from_fd(fd, &screen->devinfo))
if (!intel_get_device_info_from_fd(fd, &screen->devinfo, 4, 8))
return NULL;
screen->pci_id = screen->devinfo.pci_device_id;

View File

@@ -2478,7 +2478,7 @@ iris_bufmgr_get_for_fd(int fd, bool bo_reuse)
}
}
if (!intel_get_device_info_from_fd(fd, &devinfo))
if (!intel_get_device_info_from_fd(fd, &devinfo, 8, -1))
return NULL;
if (devinfo.ver < 8 || devinfo.platform == INTEL_PLATFORM_CHV)

View File

@@ -195,7 +195,7 @@ mi_builder_test::SetUp()
ASSERT_TRUE(intel_gem_get_param(fd, I915_PARAM_CHIPSET_ID, &device_id))
<< strerror(errno);
ASSERT_TRUE(intel_get_device_info_from_fd(fd, &devinfo));
ASSERT_TRUE(intel_get_device_info_from_fd(fd, &devinfo, -1, -1));
if (devinfo.ver != GFX_VER ||
(devinfo.platform == INTEL_PLATFORM_HSW) != (GFX_VERx10 == 75)) {
close(fd);

View File

@@ -249,7 +249,7 @@ main(int argc, char *argv[])
if (fd < 0)
continue;
bool success = intel_get_device_info_from_fd(fd, &devinfo);
bool success = intel_get_device_info_from_fd(fd, &devinfo, -1, -1);
close(fd);
if (!success)

View File

@@ -1618,7 +1618,7 @@ intel_device_info_calc_engine_prefetch(const struct intel_device_info *devinfo,
}
bool
intel_get_device_info_from_fd(int fd, struct intel_device_info *devinfo)
intel_get_device_info_from_fd(int fd, struct intel_device_info *devinfo, int min_ver, int max_ver)
{
/* Get PCI info.
*
@@ -1639,6 +1639,12 @@ intel_get_device_info_from_fd(int fd, struct intel_device_info *devinfo)
drmFreeDevice(&drmdev);
return false;
}
if ((min_ver > 0 && devinfo->ver < min_ver) || (max_ver > 0 && devinfo->ver > max_ver)) {
drmFreeDevice(&drmdev);
return false;
}
devinfo->pci_domain = drmdev->businfo.pci->domain;
devinfo->pci_bus = drmdev->businfo.pci->bus;
devinfo->pci_dev = drmdev->businfo.pci->dev;

View File

@@ -641,7 +641,7 @@ intel_vram_all_mappable(const struct intel_device_info *devinfo)
return devinfo->mem.vram.unmappable.size == 0;
}
bool intel_get_device_info_from_fd(int fh, struct intel_device_info *devinfo);
bool intel_get_device_info_from_fd(int fh, struct intel_device_info *devinfo, int min_ver, int max_ver);
bool intel_get_device_info_from_pci_id(int pci_id,
struct intel_device_info *devinfo);

View File

@@ -62,7 +62,7 @@ main(int argc, char *argv[])
if (fd < 0)
continue;
bool success = intel_get_device_info_from_fd(fd, &devinfo);
bool success = intel_get_device_info_from_fd(fd, &devinfo, -1, -1);
close(fd);
if (!success)

View File

@@ -25,7 +25,7 @@ IntelPerf::IntelPerf(const int drm_fd)
{
assert(drm_fd >= 0 && "DRM fd is not valid");
if (!intel_get_device_info_from_fd(drm_fd, &devinfo)) {
if (!intel_get_device_info_from_fd(drm_fd, &devinfo, -1, -1)) {
PPS_LOG_FATAL("Failed to get devinfo");
}

View File

@@ -118,7 +118,7 @@ ensure_device_info(int fd)
{
/* We can't do this at open time as we're not yet authenticated. */
if (device == 0) {
fail_if(!intel_get_device_info_from_fd(fd, &devinfo),
fail_if(!intel_get_device_info_from_fd(fd, &devinfo, -1, -1),
"failed to identify chipset.\n");
device = devinfo.pci_device_id;
} else if (devinfo.ver == 0) {

View File

@@ -139,7 +139,7 @@ get_drm_device(struct intel_device_info *devinfo)
if (fd < 0)
continue;
if (!intel_get_device_info_from_fd(fd, devinfo) ||
if (!intel_get_device_info_from_fd(fd, devinfo, -1, -1) ||
devinfo->ver < 8) {
close(fd);
fd = -1;

View File

@@ -2131,7 +2131,7 @@ anv_physical_device_try_create(struct vk_instance *vk_instance,
}
struct intel_device_info devinfo;
if (!intel_get_device_info_from_fd(fd, &devinfo)) {
if (!intel_get_device_info_from_fd(fd, &devinfo, 9, -1)) {
result = vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
goto fail_fd;
}

View File

@@ -989,7 +989,7 @@ anv_physical_device_try_create(struct vk_instance *vk_instance,
}
struct intel_device_info devinfo;
if (!intel_get_device_info_from_fd(fd, &devinfo)) {
if (!intel_get_device_info_from_fd(fd, &devinfo, 7, 8)) {
result = vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
goto fail_fd;
}