2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-11-17 04:46:13 +08:00
|
|
|
/*
|
|
|
|
* MDEV driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
* Author: Neo Jia <cjia@nvidia.com>
|
|
|
|
* Kirti Wankhede <kwankhede@nvidia.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/iommu.h>
|
|
|
|
#include <linux/mdev.h>
|
|
|
|
|
|
|
|
#include "mdev_private.h"
|
|
|
|
|
|
|
|
static int mdev_probe(struct device *dev)
|
|
|
|
{
|
2021-04-07 03:40:27 +08:00
|
|
|
struct mdev_driver *drv =
|
|
|
|
container_of(dev->driver, struct mdev_driver, driver);
|
2016-11-17 04:46:13 +08:00
|
|
|
|
2021-09-24 23:56:57 +08:00
|
|
|
if (!drv->probe)
|
|
|
|
return 0;
|
|
|
|
return drv->probe(to_mdev_device(dev));
|
2016-11-17 04:46:13 +08:00
|
|
|
}
|
|
|
|
|
2021-07-14 03:35:22 +08:00
|
|
|
static void mdev_remove(struct device *dev)
|
2016-11-17 04:46:13 +08:00
|
|
|
{
|
2021-04-07 03:40:27 +08:00
|
|
|
struct mdev_driver *drv =
|
|
|
|
container_of(dev->driver, struct mdev_driver, driver);
|
2016-11-17 04:46:13 +08:00
|
|
|
|
2021-04-07 03:40:27 +08:00
|
|
|
if (drv->remove)
|
2021-09-24 23:56:57 +08:00
|
|
|
drv->remove(to_mdev_device(dev));
|
2016-11-17 04:46:13 +08:00
|
|
|
}
|
|
|
|
|
2021-06-17 22:22:15 +08:00
|
|
|
static int mdev_match(struct device *dev, struct device_driver *drv)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No drivers automatically match. Drivers are only bound by explicit
|
|
|
|
* device_driver_attach()
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-17 04:46:13 +08:00
|
|
|
struct bus_type mdev_bus_type = {
|
|
|
|
.name = "mdev",
|
|
|
|
.probe = mdev_probe,
|
|
|
|
.remove = mdev_remove,
|
2021-06-17 22:22:15 +08:00
|
|
|
.match = mdev_match,
|
2016-11-17 04:46:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mdev_register_driver - register a new MDEV driver
|
|
|
|
* @drv: the driver to register
|
|
|
|
*
|
|
|
|
* Returns a negative value on error, otherwise 0.
|
|
|
|
**/
|
2021-04-07 03:40:27 +08:00
|
|
|
int mdev_register_driver(struct mdev_driver *drv)
|
2016-11-17 04:46:13 +08:00
|
|
|
{
|
2022-09-23 17:26:51 +08:00
|
|
|
if (!drv->device_api)
|
2022-09-23 17:26:43 +08:00
|
|
|
return -EINVAL;
|
2022-09-23 17:26:48 +08:00
|
|
|
|
|
|
|
/* initialize common driver fields */
|
2016-11-17 04:46:13 +08:00
|
|
|
drv->driver.bus = &mdev_bus_type;
|
|
|
|
return driver_register(&drv->driver);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mdev_register_driver);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mdev_unregister_driver - unregister MDEV driver
|
|
|
|
* @drv: the driver to unregister
|
|
|
|
*/
|
|
|
|
void mdev_unregister_driver(struct mdev_driver *drv)
|
|
|
|
{
|
|
|
|
driver_unregister(&drv->driver);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mdev_unregister_driver);
|