From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id E070A10E3D8 for ; Mon, 20 Nov 2023 14:15:20 +0000 (UTC) From: Lukasz Laguna To: igt-dev@lists.freedesktop.org Date: Mon, 20 Nov 2023 15:14:54 +0100 Message-Id: <20231120141459.7445-4-lukasz.laguna@intel.com> In-Reply-To: <20231120141459.7445-1-lukasz.laguna@intel.com> References: <20231120141459.7445-1-lukasz.laguna@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH i-g-t 3/8] lib/igt_sriov_device: add helper for checking if VF DRM driver is probed List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: From: Daniel Mrzyglod Probe check is based on existence of the DRM subsystem attribute in sysfs. Cc: Marcin Bernatowicz Cc: Michal Wajdeczko Signed-off-by: Daniel Mrzyglod Signed-off-by: Lukasz Laguna --- lib/igt_sriov_device.c | 29 +++++++++++++++++++++++++++++ lib/igt_sriov_device.h | 1 + 2 files changed, 30 insertions(+) diff --git a/lib/igt_sriov_device.c b/lib/igt_sriov_device.c index cd00c7c5d..315de353a 100644 --- a/lib/igt_sriov_device.c +++ b/lib/igt_sriov_device.c @@ -258,3 +258,32 @@ int igt_sriov_open_vf_drm_device(int pf, unsigned int vf_num) return drm_open_device(dev_name, DRIVER_ANY); } + +/** + * igt_sriov_is_vf_drm_driver_probed - Check if VF DRM driver is probed + * @pf: PF device file descriptor + * @vf_num: VF number (1-based to identify single VF) + * + * Verify if DRM driver is bound to VF device. Probe check is based on + * existence of the DRM subsystem attribute in sysfs. + * + * Returns: + * True if VF has DRM driver loaded, false if not. + */ +bool igt_sriov_is_vf_drm_driver_probed(int pf, unsigned int vf_num) +{ + char path[PATH_MAX]; + int sysfs; + bool ret; + + igt_assert(vf_num > 0); + + sysfs = igt_sysfs_open(pf); + igt_assert_fd(sysfs); + /* vf_num is 1-based, but virtfn is 0-based */ + snprintf(path, sizeof(path), "device/virtfn%u/drm", vf_num - 1); + ret = igt_sysfs_has_attr(sysfs, path); + close(sysfs); + + return ret; +} diff --git a/lib/igt_sriov_device.h b/lib/igt_sriov_device.h index 4e57f0dcb..84f033f52 100644 --- a/lib/igt_sriov_device.h +++ b/lib/igt_sriov_device.h @@ -26,5 +26,6 @@ bool igt_sriov_is_driver_autoprobe_enabled(int pf); void igt_sriov_enable_driver_autoprobe(int pf); void igt_sriov_disable_driver_autoprobe(int pf); int igt_sriov_open_vf_drm_device(int pf, unsigned int vf_num); +bool igt_sriov_is_vf_drm_driver_probed(int pf, unsigned int vf_num); #endif /* __IGT_SRIOV_DEVICE_H__ */ -- 2.40.0