cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

mdev_driver.c (1674B)


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