bus.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "idxd.h"
  8. int __idxd_driver_register(struct idxd_device_driver *idxd_drv, struct module *owner,
  9. const char *mod_name)
  10. {
  11. struct device_driver *drv = &idxd_drv->drv;
  12. if (!idxd_drv->type) {
  13. pr_debug("driver type not set (%ps)\n", __builtin_return_address(0));
  14. return -EINVAL;
  15. }
  16. drv->name = idxd_drv->name;
  17. drv->bus = &dsa_bus_type;
  18. drv->owner = owner;
  19. drv->mod_name = mod_name;
  20. return driver_register(drv);
  21. }
  22. EXPORT_SYMBOL_GPL(__idxd_driver_register);
  23. void idxd_driver_unregister(struct idxd_device_driver *idxd_drv)
  24. {
  25. driver_unregister(&idxd_drv->drv);
  26. }
  27. EXPORT_SYMBOL_GPL(idxd_driver_unregister);
  28. static int idxd_config_bus_match(struct device *dev,
  29. struct device_driver *drv)
  30. {
  31. struct idxd_device_driver *idxd_drv =
  32. container_of(drv, struct idxd_device_driver, drv);
  33. struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
  34. int i = 0;
  35. while (idxd_drv->type[i] != IDXD_DEV_NONE) {
  36. if (idxd_dev->type == idxd_drv->type[i])
  37. return 1;
  38. i++;
  39. }
  40. return 0;
  41. }
  42. static int idxd_config_bus_probe(struct device *dev)
  43. {
  44. struct idxd_device_driver *idxd_drv =
  45. container_of(dev->driver, struct idxd_device_driver, drv);
  46. struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
  47. return idxd_drv->probe(idxd_dev);
  48. }
  49. static void idxd_config_bus_remove(struct device *dev)
  50. {
  51. struct idxd_device_driver *idxd_drv =
  52. container_of(dev->driver, struct idxd_device_driver, drv);
  53. struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
  54. idxd_drv->remove(idxd_dev);
  55. }
  56. struct bus_type dsa_bus_type = {
  57. .name = "dsa",
  58. .match = idxd_config_bus_match,
  59. .probe = idxd_config_bus_probe,
  60. .remove = idxd_config_bus_remove,
  61. };
  62. EXPORT_SYMBOL_GPL(dsa_bus_type);
  63. static int __init dsa_bus_init(void)
  64. {
  65. return bus_register(&dsa_bus_type);
  66. }
  67. module_init(dsa_bus_init);
  68. static void __exit dsa_bus_exit(void)
  69. {
  70. bus_unregister(&dsa_bus_type);
  71. }
  72. module_exit(dsa_bus_exit);
  73. MODULE_DESCRIPTION("IDXD driver dsa_bus_type driver");
  74. MODULE_LICENSE("GPL v2");