0001
0002
0003 #include <linux/init.h>
0004 #include <linux/kernel.h>
0005 #include <linux/module.h>
0006 #include <linux/device.h>
0007 #include <linux/device/bus.h>
0008 #include "idxd.h"
0009
0010 extern int device_driver_attach(struct device_driver *drv, struct device *dev);
0011 extern void device_driver_detach(struct device *dev);
0012
0013 #define DRIVER_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
0014 struct driver_attribute driver_attr_##_name = \
0015 __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
0016
0017 static ssize_t unbind_store(struct device_driver *drv, const char *buf, size_t count)
0018 {
0019 struct bus_type *bus = drv->bus;
0020 struct device *dev;
0021 int rc = -ENODEV;
0022
0023 dev = bus_find_device_by_name(bus, NULL, buf);
0024 if (dev && dev->driver) {
0025 device_driver_detach(dev);
0026 rc = count;
0027 }
0028
0029 return rc;
0030 }
0031 static DRIVER_ATTR_IGNORE_LOCKDEP(unbind, 0200, NULL, unbind_store);
0032
0033 static ssize_t bind_store(struct device_driver *drv, const char *buf, size_t count)
0034 {
0035 struct bus_type *bus = drv->bus;
0036 struct device *dev;
0037 struct device_driver *alt_drv = NULL;
0038 int rc = -ENODEV;
0039 struct idxd_dev *idxd_dev;
0040
0041 dev = bus_find_device_by_name(bus, NULL, buf);
0042 if (!dev || dev->driver || drv != &dsa_drv.drv)
0043 return -ENODEV;
0044
0045 idxd_dev = confdev_to_idxd_dev(dev);
0046 if (is_idxd_dev(idxd_dev)) {
0047 alt_drv = driver_find("idxd", bus);
0048 } else if (is_idxd_wq_dev(idxd_dev)) {
0049 struct idxd_wq *wq = confdev_to_wq(dev);
0050
0051 if (is_idxd_wq_kernel(wq))
0052 alt_drv = driver_find("dmaengine", bus);
0053 else if (is_idxd_wq_user(wq))
0054 alt_drv = driver_find("user", bus);
0055 }
0056 if (!alt_drv)
0057 return -ENODEV;
0058
0059 rc = device_driver_attach(alt_drv, dev);
0060 if (rc < 0)
0061 return rc;
0062
0063 return count;
0064 }
0065 static DRIVER_ATTR_IGNORE_LOCKDEP(bind, 0200, NULL, bind_store);
0066
0067 static struct attribute *dsa_drv_compat_attrs[] = {
0068 &driver_attr_bind.attr,
0069 &driver_attr_unbind.attr,
0070 NULL,
0071 };
0072
0073 static const struct attribute_group dsa_drv_compat_attr_group = {
0074 .attrs = dsa_drv_compat_attrs,
0075 };
0076
0077 static const struct attribute_group *dsa_drv_compat_groups[] = {
0078 &dsa_drv_compat_attr_group,
0079 NULL,
0080 };
0081
0082 static int idxd_dsa_drv_probe(struct idxd_dev *idxd_dev)
0083 {
0084 return -ENODEV;
0085 }
0086
0087 static void idxd_dsa_drv_remove(struct idxd_dev *idxd_dev)
0088 {
0089 }
0090
0091 static enum idxd_dev_type dev_types[] = {
0092 IDXD_DEV_NONE,
0093 };
0094
0095 struct idxd_device_driver dsa_drv = {
0096 .name = "dsa",
0097 .probe = idxd_dsa_drv_probe,
0098 .remove = idxd_dsa_drv_remove,
0099 .type = dev_types,
0100 .drv = {
0101 .suppress_bind_attrs = true,
0102 .groups = dsa_drv_compat_groups,
0103 },
0104 };
0105
0106 module_idxd_driver(dsa_drv);
0107 MODULE_IMPORT_NS(IDXD);