76 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2/*3 * MDEV driver4 *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 15static 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 25static 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 34static int mdev_match(struct device *dev, const struct device_driver *drv)35{36 /*37 * No drivers automatically match. Drivers are only bound by explicit38 * device_driver_attach()39 */40 return 0;41}42 43const 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 driver52 * @drv: the driver to register53 *54 * Returns a negative value on error, otherwise 0.55 **/56int 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}65EXPORT_SYMBOL(mdev_register_driver);66 67/*68 * mdev_unregister_driver - unregister MDEV driver69 * @drv: the driver to unregister70 */71void mdev_unregister_driver(struct mdev_driver *drv)72{73 driver_unregister(&drv->driver);74}75EXPORT_SYMBOL(mdev_unregister_driver);76