2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-15 08:44:14 +08:00

VFIO: Wrapper for getting reference to vfio_device

- Added vfio_device_get_from_dev() as wrapper to get
  reference to vfio_device from struct device.

- Added vfio_device_data() as a wrapper to get device_data from
  vfio_device.

Signed-off-by: Vijay Mohan Pandarathil <vijaymohan.pandarathil@hp.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
Vijay Mohan Pandarathil 2013-03-11 09:28:44 -06:00 committed by Alex Williamson
parent f6161aa153
commit 44f507163d
2 changed files with 32 additions and 1 deletions
drivers/vfio
include/linux

View File

@ -392,12 +392,13 @@ static void vfio_device_release(struct kref *kref)
}
/* Device reference always implies a group reference */
static void vfio_device_put(struct vfio_device *device)
void vfio_device_put(struct vfio_device *device)
{
struct vfio_group *group = device->group;
kref_put_mutex(&device->kref, vfio_device_release, &group->device_lock);
vfio_group_put(group);
}
EXPORT_SYMBOL_GPL(vfio_device_put);
static void vfio_device_get(struct vfio_device *device)
{
@ -627,6 +628,33 @@ int vfio_add_group_dev(struct device *dev,
}
EXPORT_SYMBOL_GPL(vfio_add_group_dev);
/**
* Get a reference to the vfio_device for a device that is known to
* be bound to a vfio driver. The driver implicitly holds a
* vfio_device reference between vfio_add_group_dev and
* vfio_del_group_dev. We can therefore use drvdata to increment
* that reference from the struct device. This additional
* reference must be released by calling vfio_device_put.
*/
struct vfio_device *vfio_device_get_from_dev(struct device *dev)
{
struct vfio_device *device = dev_get_drvdata(dev);
vfio_device_get(device);
return device;
}
EXPORT_SYMBOL_GPL(vfio_device_get_from_dev);
/*
* Caller must hold a reference to the vfio_device
*/
void *vfio_device_data(struct vfio_device *device)
{
return device->device_data;
}
EXPORT_SYMBOL_GPL(vfio_device_data);
/* Given a referenced group, check if it contains the device */
static bool vfio_dev_present(struct vfio_group *group, struct device *dev)
{

View File

@ -45,6 +45,9 @@ extern int vfio_add_group_dev(struct device *dev,
void *device_data);
extern void *vfio_del_group_dev(struct device *dev);
extern struct vfio_device *vfio_device_get_from_dev(struct device *dev);
extern void vfio_device_put(struct vfio_device *device);
extern void *vfio_device_data(struct vfio_device *device);
/**
* struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks