compat.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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>
  8. #include "idxd.h"
  9. extern int device_driver_attach(struct device_driver *drv, struct device *dev);
  10. extern void device_driver_detach(struct device *dev);
  11. #define DRIVER_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
  12. struct driver_attribute driver_attr_##_name = \
  13. __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
  14. static ssize_t unbind_store(struct device_driver *drv, const char *buf, size_t count)
  15. {
  16. struct bus_type *bus = drv->bus;
  17. struct device *dev;
  18. int rc = -ENODEV;
  19. dev = bus_find_device_by_name(bus, NULL, buf);
  20. if (dev && dev->driver) {
  21. device_driver_detach(dev);
  22. rc = count;
  23. }
  24. return rc;
  25. }
  26. static DRIVER_ATTR_IGNORE_LOCKDEP(unbind, 0200, NULL, unbind_store);
  27. static ssize_t bind_store(struct device_driver *drv, const char *buf, size_t count)
  28. {
  29. struct bus_type *bus = drv->bus;
  30. struct device *dev;
  31. struct device_driver *alt_drv = NULL;
  32. int rc = -ENODEV;
  33. struct idxd_dev *idxd_dev;
  34. dev = bus_find_device_by_name(bus, NULL, buf);
  35. if (!dev || dev->driver || drv != &dsa_drv.drv)
  36. return -ENODEV;
  37. idxd_dev = confdev_to_idxd_dev(dev);
  38. if (is_idxd_dev(idxd_dev)) {
  39. alt_drv = driver_find("idxd", bus);
  40. } else if (is_idxd_wq_dev(idxd_dev)) {
  41. struct idxd_wq *wq = confdev_to_wq(dev);
  42. if (is_idxd_wq_kernel(wq))
  43. alt_drv = driver_find("dmaengine", bus);
  44. else if (is_idxd_wq_user(wq))
  45. alt_drv = driver_find("user", bus);
  46. }
  47. if (!alt_drv)
  48. return -ENODEV;
  49. rc = device_driver_attach(alt_drv, dev);
  50. if (rc < 0)
  51. return rc;
  52. return count;
  53. }
  54. static DRIVER_ATTR_IGNORE_LOCKDEP(bind, 0200, NULL, bind_store);
  55. static struct attribute *dsa_drv_compat_attrs[] = {
  56. &driver_attr_bind.attr,
  57. &driver_attr_unbind.attr,
  58. NULL,
  59. };
  60. static const struct attribute_group dsa_drv_compat_attr_group = {
  61. .attrs = dsa_drv_compat_attrs,
  62. };
  63. static const struct attribute_group *dsa_drv_compat_groups[] = {
  64. &dsa_drv_compat_attr_group,
  65. NULL,
  66. };
  67. static int idxd_dsa_drv_probe(struct idxd_dev *idxd_dev)
  68. {
  69. return -ENODEV;
  70. }
  71. static void idxd_dsa_drv_remove(struct idxd_dev *idxd_dev)
  72. {
  73. }
  74. static enum idxd_dev_type dev_types[] = {
  75. IDXD_DEV_NONE,
  76. };
  77. struct idxd_device_driver dsa_drv = {
  78. .name = "dsa",
  79. .probe = idxd_dsa_drv_probe,
  80. .remove = idxd_dsa_drv_remove,
  81. .type = dev_types,
  82. .drv = {
  83. .suppress_bind_attrs = true,
  84. .groups = dsa_drv_compat_groups,
  85. },
  86. };
  87. module_idxd_driver(dsa_drv);
  88. MODULE_IMPORT_NS(IDXD);