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 <cjia@nvidia.com>
7 * Kirti Wankhede <kwankhede@nvidia.com>
8 */
9
10 #include <linux/iommu.h>
11 #include <linux/mdev.h>
12
13 #include "mdev_private.h"
14
mdev_probe(struct device * dev)15 static int mdev_probe(struct device *dev)
16 {
17 struct mdev_driver *drv =
18 container_of(dev->driver, struct mdev_driver, driver);
19
20 if (!drv->probe)
21 return 0;
22 return drv->probe(to_mdev_device(dev));
23 }
24
mdev_remove(struct device * dev)25 static void mdev_remove(struct device *dev)
26 {
27 struct mdev_driver *drv =
28 container_of(dev->driver, struct mdev_driver, driver);
29
30 if (drv->remove)
31 drv->remove(to_mdev_device(dev));
32 }
33
mdev_match(struct device * dev,struct device_driver * drv)34 static int mdev_match(struct device *dev, struct device_driver *drv)
35 {
36 /*
37 * No drivers automatically match. Drivers are only bound by explicit
38 * device_driver_attach()
39 */
40 return 0;
41 }
42
43 struct bus_type mdev_bus_type = {
44 .name = "mdev",
45 .probe = mdev_probe,
46 .remove = mdev_remove,
47 .match = mdev_match,
48 };
49
50 /**
51 * mdev_register_driver - register a new MDEV driver
52 * @drv: the driver to register
53 *
54 * Returns a negative value on error, otherwise 0.
55 **/
mdev_register_driver(struct mdev_driver * drv)56 int mdev_register_driver(struct mdev_driver *drv)
57 {
58 if (!drv->device_api)
59 return -EINVAL;
60
61 /* initialize common driver fields */
62 drv->driver.bus = &mdev_bus_type;
63 return driver_register(&drv->driver);
64 }
65 EXPORT_SYMBOL(mdev_register_driver);
66
67 /*
68 * mdev_unregister_driver - unregister MDEV driver
69 * @drv: the driver to unregister
70 */
mdev_unregister_driver(struct mdev_driver * drv)71 void mdev_unregister_driver(struct mdev_driver *drv)
72 {
73 driver_unregister(&drv->driver);
74 }
75 EXPORT_SYMBOL(mdev_unregister_driver);
76