mdev_driver.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * MDEV driver
  4. *
  5. * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  6. * Author: Neo Jia <[email protected]>
  7. * Kirti Wankhede <[email protected]>
  8. */
  9. #include <linux/iommu.h>
  10. #include <linux/mdev.h>
  11. #include "mdev_private.h"
  12. static int mdev_probe(struct device *dev)
  13. {
  14. struct mdev_driver *drv =
  15. container_of(dev->driver, struct mdev_driver, driver);
  16. if (!drv->probe)
  17. return 0;
  18. return drv->probe(to_mdev_device(dev));
  19. }
  20. static void mdev_remove(struct device *dev)
  21. {
  22. struct mdev_driver *drv =
  23. container_of(dev->driver, struct mdev_driver, driver);
  24. if (drv->remove)
  25. drv->remove(to_mdev_device(dev));
  26. }
  27. static int mdev_match(struct device *dev, struct device_driver *drv)
  28. {
  29. /*
  30. * No drivers automatically match. Drivers are only bound by explicit
  31. * device_driver_attach()
  32. */
  33. return 0;
  34. }
  35. struct bus_type mdev_bus_type = {
  36. .name = "mdev",
  37. .probe = mdev_probe,
  38. .remove = mdev_remove,
  39. .match = mdev_match,
  40. };
  41. /**
  42. * mdev_register_driver - register a new MDEV driver
  43. * @drv: the driver to register
  44. *
  45. * Returns a negative value on error, otherwise 0.
  46. **/
  47. int mdev_register_driver(struct mdev_driver *drv)
  48. {
  49. if (!drv->device_api)
  50. return -EINVAL;
  51. /* initialize common driver fields */
  52. drv->driver.bus = &mdev_bus_type;
  53. return driver_register(&drv->driver);
  54. }
  55. EXPORT_SYMBOL(mdev_register_driver);
  56. /*
  57. * mdev_unregister_driver - unregister MDEV driver
  58. * @drv: the driver to unregister
  59. */
  60. void mdev_unregister_driver(struct mdev_driver *drv)
  61. {
  62. driver_unregister(&drv->driver);
  63. }
  64. EXPORT_SYMBOL(mdev_unregister_driver);