diff options
author | Vijay Mohan Pandarathil <vijaymohan.pandarathil@hp.com> | 2013-03-11 11:28:44 -0400 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2013-03-11 11:28:44 -0400 |
commit | 44f507163d9e51238458ee6904b4d71fb0723723 (patch) | |
tree | ddd48ebd567813495ddeb718d7d54524f16f313f /drivers/vfio | |
parent | f6161aa153581da4a3867a2d1a7caf4be19b6ec9 (diff) |
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>
Diffstat (limited to 'drivers/vfio')
-rw-r--r-- | drivers/vfio/vfio.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index fcc12f3e60a3..21eddd9e0f26 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c | |||
@@ -392,12 +392,13 @@ static void vfio_device_release(struct kref *kref) | |||
392 | } | 392 | } |
393 | 393 | ||
394 | /* Device reference always implies a group reference */ | 394 | /* Device reference always implies a group reference */ |
395 | static void vfio_device_put(struct vfio_device *device) | 395 | void vfio_device_put(struct vfio_device *device) |
396 | { | 396 | { |
397 | struct vfio_group *group = device->group; | 397 | struct vfio_group *group = device->group; |
398 | kref_put_mutex(&device->kref, vfio_device_release, &group->device_lock); | 398 | kref_put_mutex(&device->kref, vfio_device_release, &group->device_lock); |
399 | vfio_group_put(group); | 399 | vfio_group_put(group); |
400 | } | 400 | } |
401 | EXPORT_SYMBOL_GPL(vfio_device_put); | ||
401 | 402 | ||
402 | static void vfio_device_get(struct vfio_device *device) | 403 | static void vfio_device_get(struct vfio_device *device) |
403 | { | 404 | { |
@@ -627,6 +628,33 @@ int vfio_add_group_dev(struct device *dev, | |||
627 | } | 628 | } |
628 | EXPORT_SYMBOL_GPL(vfio_add_group_dev); | 629 | EXPORT_SYMBOL_GPL(vfio_add_group_dev); |
629 | 630 | ||
631 | /** | ||
632 | * Get a reference to the vfio_device for a device that is known to | ||
633 | * be bound to a vfio driver. The driver implicitly holds a | ||
634 | * vfio_device reference between vfio_add_group_dev and | ||
635 | * vfio_del_group_dev. We can therefore use drvdata to increment | ||
636 | * that reference from the struct device. This additional | ||
637 | * reference must be released by calling vfio_device_put. | ||
638 | */ | ||
639 | struct vfio_device *vfio_device_get_from_dev(struct device *dev) | ||
640 | { | ||
641 | struct vfio_device *device = dev_get_drvdata(dev); | ||
642 | |||
643 | vfio_device_get(device); | ||
644 | |||
645 | return device; | ||
646 | } | ||
647 | EXPORT_SYMBOL_GPL(vfio_device_get_from_dev); | ||
648 | |||
649 | /* | ||
650 | * Caller must hold a reference to the vfio_device | ||
651 | */ | ||
652 | void *vfio_device_data(struct vfio_device *device) | ||
653 | { | ||
654 | return device->device_data; | ||
655 | } | ||
656 | EXPORT_SYMBOL_GPL(vfio_device_data); | ||
657 | |||
630 | /* Given a referenced group, check if it contains the device */ | 658 | /* Given a referenced group, check if it contains the device */ |
631 | static bool vfio_dev_present(struct vfio_group *group, struct device *dev) | 659 | static bool vfio_dev_present(struct vfio_group *group, struct device *dev) |
632 | { | 660 | { |