compat.c 2.5 KB

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