1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2021 Intel Corporation. All rights rsvd. */
3 #include <linux/init.h>
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/device.h>
7 #include <linux/device/bus.h>
10 extern int device_driver_attach(struct device_driver *drv, struct device *dev);
11 extern void device_driver_detach(struct device *dev);
13 #define DRIVER_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
14 struct driver_attribute driver_attr_##_name = \
15 __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
17 static ssize_t unbind_store(struct device_driver *drv, const char *buf, size_t count)
19 const struct bus_type *bus = drv->bus;
23 dev = bus_find_device_by_name(bus, NULL, buf);
24 if (dev && dev->driver) {
25 device_driver_detach(dev);
31 static DRIVER_ATTR_IGNORE_LOCKDEP(unbind, 0200, NULL, unbind_store);
33 static ssize_t bind_store(struct device_driver *drv, const char *buf, size_t count)
35 const struct bus_type *bus = drv->bus;
37 struct device_driver *alt_drv = NULL;
39 struct idxd_dev *idxd_dev;
41 dev = bus_find_device_by_name(bus, NULL, buf);
42 if (!dev || dev->driver || drv != &dsa_drv.drv)
45 idxd_dev = confdev_to_idxd_dev(dev);
46 if (is_idxd_dev(idxd_dev)) {
47 alt_drv = driver_find("idxd", bus);
48 } else if (is_idxd_wq_dev(idxd_dev)) {
49 struct idxd_wq *wq = confdev_to_wq(dev);
51 if (is_idxd_wq_kernel(wq))
52 alt_drv = driver_find("dmaengine", bus);
53 else if (is_idxd_wq_user(wq))
54 alt_drv = driver_find("user", bus);
59 rc = device_driver_attach(alt_drv, dev);
65 static DRIVER_ATTR_IGNORE_LOCKDEP(bind, 0200, NULL, bind_store);
67 static struct attribute *dsa_drv_compat_attrs[] = {
68 &driver_attr_bind.attr,
69 &driver_attr_unbind.attr,
73 static const struct attribute_group dsa_drv_compat_attr_group = {
74 .attrs = dsa_drv_compat_attrs,
77 static const struct attribute_group *dsa_drv_compat_groups[] = {
78 &dsa_drv_compat_attr_group,
82 static int idxd_dsa_drv_probe(struct idxd_dev *idxd_dev)
87 static void idxd_dsa_drv_remove(struct idxd_dev *idxd_dev)
91 static enum idxd_dev_type dev_types[] = {
95 struct idxd_device_driver dsa_drv = {
97 .probe = idxd_dsa_drv_probe,
98 .remove = idxd_dsa_drv_remove,
101 .suppress_bind_attrs = true,
102 .groups = dsa_drv_compat_groups,
106 module_idxd_driver(dsa_drv);
107 MODULE_IMPORT_NS(IDXD);