[PATCH i-g-t] SRIOV: lib/igt_sriov_device: Cache xe device at open

Marcin Bernatowicz marcin.bernatowicz at linux.intel.com
Wed Mar 13 11:59:11 UTC 2024


Be consistent with other drm_open_xxx functions.

Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz at linux.intel.com>
---
 lib/igt_sriov_device.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/igt_sriov_device.c b/lib/igt_sriov_device.c
index f20761669..f425a5ecf 100644
--- a/lib/igt_sriov_device.c
+++ b/lib/igt_sriov_device.c
@@ -12,6 +12,7 @@
 #include "igt_device.h"
 #include "igt_sriov_device.h"
 #include "igt_sysfs.h"
+#include "xe/xe_query.h"
 
 /**
  * igt_sriov_is_pf - Check if device is PF
@@ -232,6 +233,7 @@ int igt_sriov_open_vf_drm_device(int pf, unsigned int vf_num)
 	DIR *dir;
 	struct dirent *de;
 	bool found = false;
+	int fd;
 
 	if (!vf_num)
 		return -1;
@@ -258,7 +260,11 @@ int igt_sriov_open_vf_drm_device(int pf, unsigned int vf_num)
 	if (!found)
 		return -1;
 
-	return __drm_open_device(dev_name, DRIVER_ANY);
+	fd = __drm_open_device(dev_name, DRIVER_ANY);
+	if (fd >= 0 && is_xe_device(fd))
+		xe_device_get(fd);
+
+	return fd;
 }
 
 /**
-- 
2.31.1



More information about the igt-dev mailing list