1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 27b96953bSKirti Wankhede /* 37b96953bSKirti Wankhede * MDEV driver 47b96953bSKirti Wankhede * 57b96953bSKirti Wankhede * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 67b96953bSKirti Wankhede * Author: Neo Jia <cjia@nvidia.com> 77b96953bSKirti Wankhede * Kirti Wankhede <kwankhede@nvidia.com> 87b96953bSKirti Wankhede */ 97b96953bSKirti Wankhede 107b96953bSKirti Wankhede #include <linux/device.h> 117b96953bSKirti Wankhede #include <linux/iommu.h> 127b96953bSKirti Wankhede #include <linux/mdev.h> 137b96953bSKirti Wankhede 147b96953bSKirti Wankhede #include "mdev_private.h" 157b96953bSKirti Wankhede 167b96953bSKirti Wankhede static int mdev_probe(struct device *dev) 177b96953bSKirti Wankhede { 1891b9969dSJason Gunthorpe struct mdev_driver *drv = 1991b9969dSJason Gunthorpe container_of(dev->driver, struct mdev_driver, driver); 207b96953bSKirti Wankhede 21*c68ea0d0SChristoph Hellwig if (!drv->probe) 22*c68ea0d0SChristoph Hellwig return 0; 23*c68ea0d0SChristoph Hellwig return drv->probe(to_mdev_device(dev)); 247b96953bSKirti Wankhede } 257b96953bSKirti Wankhede 26fc7a6209SUwe Kleine-König static void mdev_remove(struct device *dev) 277b96953bSKirti Wankhede { 2891b9969dSJason Gunthorpe struct mdev_driver *drv = 2991b9969dSJason Gunthorpe container_of(dev->driver, struct mdev_driver, driver); 307b96953bSKirti Wankhede 3191b9969dSJason Gunthorpe if (drv->remove) 32*c68ea0d0SChristoph Hellwig drv->remove(to_mdev_device(dev)); 337b96953bSKirti Wankhede } 347b96953bSKirti Wankhede 3588a21f26SJason Gunthorpe static int mdev_match(struct device *dev, struct device_driver *drv) 3688a21f26SJason Gunthorpe { 3788a21f26SJason Gunthorpe /* 3888a21f26SJason Gunthorpe * No drivers automatically match. Drivers are only bound by explicit 3988a21f26SJason Gunthorpe * device_driver_attach() 4088a21f26SJason Gunthorpe */ 4188a21f26SJason Gunthorpe return 0; 4288a21f26SJason Gunthorpe } 4388a21f26SJason Gunthorpe 447b96953bSKirti Wankhede struct bus_type mdev_bus_type = { 457b96953bSKirti Wankhede .name = "mdev", 467b96953bSKirti Wankhede .probe = mdev_probe, 477b96953bSKirti Wankhede .remove = mdev_remove, 4888a21f26SJason Gunthorpe .match = mdev_match, 497b96953bSKirti Wankhede }; 507b96953bSKirti Wankhede EXPORT_SYMBOL_GPL(mdev_bus_type); 517b96953bSKirti Wankhede 527b96953bSKirti Wankhede /** 537b96953bSKirti Wankhede * mdev_register_driver - register a new MDEV driver 547b96953bSKirti Wankhede * @drv: the driver to register 557b96953bSKirti Wankhede * 567b96953bSKirti Wankhede * Returns a negative value on error, otherwise 0. 577b96953bSKirti Wankhede **/ 5891b9969dSJason Gunthorpe int mdev_register_driver(struct mdev_driver *drv) 597b96953bSKirti Wankhede { 607b96953bSKirti Wankhede /* initialize common driver fields */ 617b96953bSKirti Wankhede drv->driver.bus = &mdev_bus_type; 627b96953bSKirti Wankhede 637b96953bSKirti Wankhede /* register with core */ 647b96953bSKirti Wankhede return driver_register(&drv->driver); 657b96953bSKirti Wankhede } 667b96953bSKirti Wankhede EXPORT_SYMBOL(mdev_register_driver); 677b96953bSKirti Wankhede 687b96953bSKirti Wankhede /* 697b96953bSKirti Wankhede * mdev_unregister_driver - unregister MDEV driver 707b96953bSKirti Wankhede * @drv: the driver to unregister 717b96953bSKirti Wankhede */ 727b96953bSKirti Wankhede void mdev_unregister_driver(struct mdev_driver *drv) 737b96953bSKirti Wankhede { 747b96953bSKirti Wankhede driver_unregister(&drv->driver); 757b96953bSKirti Wankhede } 767b96953bSKirti Wankhede EXPORT_SYMBOL(mdev_unregister_driver); 777b96953bSKirti Wankhede 787b96953bSKirti Wankhede int mdev_bus_register(void) 797b96953bSKirti Wankhede { 807b96953bSKirti Wankhede return bus_register(&mdev_bus_type); 817b96953bSKirti Wankhede } 827b96953bSKirti Wankhede 837b96953bSKirti Wankhede void mdev_bus_unregister(void) 847b96953bSKirti Wankhede { 857b96953bSKirti Wankhede bus_unregister(&mdev_bus_type); 867b96953bSKirti Wankhede } 87