mdev_driver.c (ffb1e76f4f32d2b8ea4189df0484980370476395) | mdev_driver.c (c68ea0d00ad82428154aed890ec9f793e460fa1c) |
---|---|
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 | 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_attach_iommu(struct mdev_device *mdev) 17{ 18 int ret; 19 struct iommu_group *group; 20 21 group = iommu_group_alloc(); 22 if (IS_ERR(group)) 23 return PTR_ERR(group); 24 25 ret = iommu_group_add_device(group, &mdev->dev); 26 if (!ret) 27 dev_info(&mdev->dev, "MDEV: group_id = %d\n", 28 iommu_group_id(group)); 29 30 iommu_group_put(group); 31 return ret; 32} 33 34static void mdev_detach_iommu(struct mdev_device *mdev) 35{ 36 iommu_group_remove_device(&mdev->dev); 37 dev_info(&mdev->dev, "MDEV: detaching iommu\n"); 38} 39 | |
40static int mdev_probe(struct device *dev) 41{ 42 struct mdev_driver *drv = 43 container_of(dev->driver, struct mdev_driver, driver); | 16static int mdev_probe(struct device *dev) 17{ 18 struct mdev_driver *drv = 19 container_of(dev->driver, struct mdev_driver, driver); |
44 struct mdev_device *mdev = to_mdev_device(dev); 45 int ret; | |
46 | 20 |
47 ret = mdev_attach_iommu(mdev); 48 if (ret) 49 return ret; 50 51 if (drv->probe) { 52 ret = drv->probe(mdev); 53 if (ret) 54 mdev_detach_iommu(mdev); 55 } 56 57 return ret; | 21 if (!drv->probe) 22 return 0; 23 return drv->probe(to_mdev_device(dev)); |
58} 59 60static void mdev_remove(struct device *dev) 61{ 62 struct mdev_driver *drv = 63 container_of(dev->driver, struct mdev_driver, driver); | 24} 25 26static void mdev_remove(struct device *dev) 27{ 28 struct mdev_driver *drv = 29 container_of(dev->driver, struct mdev_driver, driver); |
64 struct mdev_device *mdev = to_mdev_device(dev); | |
65 66 if (drv->remove) | 30 31 if (drv->remove) |
67 drv->remove(mdev); 68 69 mdev_detach_iommu(mdev); | 32 drv->remove(to_mdev_device(dev)); |
70} 71 72static int mdev_match(struct device *dev, struct device_driver *drv) 73{ 74 /* 75 * No drivers automatically match. Drivers are only bound by explicit 76 * device_driver_attach() 77 */ --- 46 unchanged lines hidden --- | 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 */ --- 46 unchanged lines hidden --- |