Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>,
	Francois Dugast <francois.dugast@intel.com>
Subject: [PATCH i-g-t 05/10] lib/igt_kmod: Add igt_kmod_bind()
Date: Thu, 10 Apr 2025 15:48:34 -0700	[thread overview]
Message-ID: <20250410-lib-kmod-v1-5-84b1ad0b8075@intel.com> (raw)
In-Reply-To: <20250410-lib-kmod-v1-0-84b1ad0b8075@intel.com>

Like the unbind/rebind, this can be easily implemented by the
driver_set_device() helper.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
 lib/igt_kmod.c | 32 +++++++++++++++++++++++++++++---
 lib/igt_kmod.h |  2 ++
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 3f5f93f37..14b6b957a 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -598,9 +598,7 @@ int __igt_intel_driver_unload(char **who, const char *driver)
 }
 
 /**
- * igt_kmod_unbind:
- *
- * Unbind driver from devices. Currently supports only PCI bus
+ * igt_kmod_unbind: Unbind driver from devices. Currently supports only PCI bus
  * @mod_name: name of the module to unbind
  * @pci_device: if provided, unbind only this device, otherwise unbind all devices
  */
@@ -639,6 +637,34 @@ int igt_kmod_unbind(const char *mod_name, const char *pci_device)
 	return 0;
 }
 
+/**
+ * igt_kmod_bind: Bind driver to device
+ * @mod_name: name of the module to rebind
+ * @pci_device: device to bind
+ *
+ * Module should already be loaded
+ */
+int igt_kmod_bind(const char *mod_name, const char *pci_device)
+{
+	char path[PATH_MAX];
+	int dirlen, dirfd;
+	int ret;
+
+	dirlen = snprintf(path, sizeof(path), "/sys/module/%s/drivers/pci:%s/",
+			  mod_name, mod_name);
+	igt_assert(dirlen < sizeof(path));
+
+	dirfd = open(path, O_RDONLY | O_CLOEXEC);
+	if (dirfd < 0)
+		return dirfd;
+
+	ret = igt_sysfs_set(dirfd, "bind", pci_device);
+
+	close(dirfd);
+
+	return ret;
+}
+
 /**
  * igt_intel_driver_unload:
  *
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index 170a8df9d..e3a4ce671 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -37,6 +37,8 @@ int igt_kmod_load(const char *mod_name, const char *opts);
 int igt_kmod_unload(const char *mod_name);
 
 int igt_kmod_unbind(const char *mod_name, const char *pci_device);
+__attribute__((nonnull)) int igt_kmod_bind(const char *mod_name,
+					   const char *pci_device);
 
 int igt_audio_driver_unload(char **whom);
 

-- 
2.49.0


  parent reply	other threads:[~2025-04-10 22:48 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10 22:47 [PATCH i-g-t 00/10] lib/kmod: unbind, bind, rebind Lucas De Marchi
2025-04-10 22:48 ` [PATCH i-g-t 01/10] lib/igt_kmod: Fix leaking dir Lucas De Marchi
2025-04-11  7:26   ` Riana Tauro
2025-04-10 22:48 ` [PATCH i-g-t 02/10] lib/igt_kmod: Fix comment about unbound devices Lucas De Marchi
2025-04-14 10:56   ` Francois Dugast
2025-04-10 22:48 ` [PATCH i-g-t 03/10] lib/igt_kmod: Simplify igt_kmod_unbind() Lucas De Marchi
2025-04-14 10:59   ` Francois Dugast
2025-04-10 22:48 ` [PATCH i-g-t 04/10] lib/igt_kmod: Use igt_kmod_unbind() to kick snd_hda_intel Lucas De Marchi
2025-04-14 18:04   ` Kamil Konieczny
2025-04-10 22:48 ` Lucas De Marchi [this message]
2025-04-14 18:06   ` [PATCH i-g-t 05/10] lib/igt_kmod: Add igt_kmod_bind() Kamil Konieczny
2025-04-15  5:34   ` Riana Tauro
2025-04-10 22:48 ` [PATCH i-g-t 06/10] tests/intel/xe_fault_injection: Use igt_kmod_bind() Lucas De Marchi
2025-04-14 11:00   ` Francois Dugast
2025-04-10 22:48 ` [PATCH i-g-t 07/10] lib/igt_kmod: Add rebind abstraction Lucas De Marchi
2025-04-14 18:07   ` Kamil Konieczny
2025-04-14 21:36     ` Lucas De Marchi
2025-04-28 11:27       ` Kamil Konieczny
2025-04-15  5:49   ` Riana Tauro
2025-04-17  3:38     ` Lucas De Marchi
2025-04-10 22:48 ` [PATCH i-g-t 08/10] tests/intel/xe_fault_injection: Drop XE_SYSFS_DRIVER_TRY_BIND usage Lucas De Marchi
2025-04-14 11:01   ` Francois Dugast
2025-04-10 22:48 ` [PATCH i-g-t 09/10] tests/intel/xe_wedged: Drop XE_SYSFS_DRIVER_REBIND usage Lucas De Marchi
2025-04-14 11:02   ` Francois Dugast
2025-04-10 22:49 ` [PATCH i-g-t 10/10] lib/igt_sysfs: Drop xe_sysfs_driver_do() Lucas De Marchi
2025-04-14 11:03   ` Francois Dugast
2025-04-10 23:59 ` ✓ i915.CI.BAT: success for lib/kmod: unbind, bind, rebind Patchwork
2025-04-11  0:18 ` ✓ Xe.CI.BAT: " Patchwork
2025-04-11  4:34 ` ✗ i915.CI.Full: failure " Patchwork
2025-04-11  5:09 ` ✓ Xe.CI.Full: success " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250410-lib-kmod-v1-5-84b1ad0b8075@intel.com \
    --to=lucas.demarchi@intel.com \
    --cc=francois.dugast@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox