Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * MDEV driver
0004  *
0005  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
0006  *     Author: Neo Jia <cjia@nvidia.com>
0007  *             Kirti Wankhede <kwankhede@nvidia.com>
0008  */
0009 
0010 #include <linux/device.h>
0011 #include <linux/iommu.h>
0012 #include <linux/mdev.h>
0013 
0014 #include "mdev_private.h"
0015 
0016 static int mdev_probe(struct device *dev)
0017 {
0018     struct mdev_driver *drv =
0019         container_of(dev->driver, struct mdev_driver, driver);
0020 
0021     if (!drv->probe)
0022         return 0;
0023     return drv->probe(to_mdev_device(dev));
0024 }
0025 
0026 static void mdev_remove(struct device *dev)
0027 {
0028     struct mdev_driver *drv =
0029         container_of(dev->driver, struct mdev_driver, driver);
0030 
0031     if (drv->remove)
0032         drv->remove(to_mdev_device(dev));
0033 }
0034 
0035 static int mdev_match(struct device *dev, struct device_driver *drv)
0036 {
0037     /*
0038      * No drivers automatically match. Drivers are only bound by explicit
0039      * device_driver_attach()
0040      */
0041     return 0;
0042 }
0043 
0044 struct bus_type mdev_bus_type = {
0045     .name       = "mdev",
0046     .probe      = mdev_probe,
0047     .remove     = mdev_remove,
0048     .match      = mdev_match,
0049 };
0050 EXPORT_SYMBOL_GPL(mdev_bus_type);
0051 
0052 /**
0053  * mdev_register_driver - register a new MDEV driver
0054  * @drv: the driver to register
0055  *
0056  * Returns a negative value on error, otherwise 0.
0057  **/
0058 int mdev_register_driver(struct mdev_driver *drv)
0059 {
0060     /* initialize common driver fields */
0061     drv->driver.bus = &mdev_bus_type;
0062 
0063     /* register with core */
0064     return driver_register(&drv->driver);
0065 }
0066 EXPORT_SYMBOL(mdev_register_driver);
0067 
0068 /*
0069  * mdev_unregister_driver - unregister MDEV driver
0070  * @drv: the driver to unregister
0071  */
0072 void mdev_unregister_driver(struct mdev_driver *drv)
0073 {
0074     driver_unregister(&drv->driver);
0075 }
0076 EXPORT_SYMBOL(mdev_unregister_driver);