Alex Williamson | cba3345 | 2012-07-31 08:16:22 -0600 | [diff] [blame] | 1 | /* |
| 2 | * VFIO API definition |
| 3 | * |
| 4 | * Copyright (C) 2012 Red Hat, Inc. All rights reserved. |
| 5 | * Author: Alex Williamson <alex.williamson@redhat.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #ifndef VFIO_H |
| 12 | #define VFIO_H |
| 13 | |
Alex Williamson | cba3345 | 2012-07-31 08:16:22 -0600 | [diff] [blame] | 14 | |
| 15 | #include <linux/iommu.h> |
| 16 | #include <linux/mm.h> |
Antonios Motakis | 7e992d6 | 2015-03-16 14:08:54 -0600 | [diff] [blame] | 17 | #include <linux/workqueue.h> |
| 18 | #include <linux/poll.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 19 | #include <uapi/linux/vfio.h> |
Alex Williamson | cba3345 | 2012-07-31 08:16:22 -0600 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * struct vfio_device_ops - VFIO bus driver device callbacks |
| 23 | * |
| 24 | * @open: Called when userspace creates new file descriptor for device |
| 25 | * @release: Called when userspace releases file descriptor for device |
| 26 | * @read: Perform read(2) on device file descriptor |
| 27 | * @write: Perform write(2) on device file descriptor |
| 28 | * @ioctl: Perform ioctl(2) on device file descriptor, supporting VFIO_DEVICE_* |
| 29 | * operations documented below |
| 30 | * @mmap: Perform mmap(2) on a region of the device file descriptor |
Alex Williamson | 13060b6 | 2015-02-06 15:05:07 -0700 | [diff] [blame] | 31 | * @request: Request for the bus driver to release the device |
Alex Williamson | cba3345 | 2012-07-31 08:16:22 -0600 | [diff] [blame] | 32 | */ |
| 33 | struct vfio_device_ops { |
| 34 | char *name; |
| 35 | int (*open)(void *device_data); |
| 36 | void (*release)(void *device_data); |
| 37 | ssize_t (*read)(void *device_data, char __user *buf, |
| 38 | size_t count, loff_t *ppos); |
| 39 | ssize_t (*write)(void *device_data, const char __user *buf, |
| 40 | size_t count, loff_t *size); |
| 41 | long (*ioctl)(void *device_data, unsigned int cmd, |
| 42 | unsigned long arg); |
| 43 | int (*mmap)(void *device_data, struct vm_area_struct *vma); |
Alex Williamson | 13060b6 | 2015-02-06 15:05:07 -0700 | [diff] [blame] | 44 | void (*request)(void *device_data, unsigned int count); |
Alex Williamson | cba3345 | 2012-07-31 08:16:22 -0600 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | extern int vfio_add_group_dev(struct device *dev, |
| 48 | const struct vfio_device_ops *ops, |
| 49 | void *device_data); |
| 50 | |
| 51 | extern void *vfio_del_group_dev(struct device *dev); |
Vijay Mohan Pandarathil | 44f5071 | 2013-03-11 09:28:44 -0600 | [diff] [blame] | 52 | extern struct vfio_device *vfio_device_get_from_dev(struct device *dev); |
| 53 | extern void vfio_device_put(struct vfio_device *device); |
| 54 | extern void *vfio_device_data(struct vfio_device *device); |
Alex Williamson | cba3345 | 2012-07-31 08:16:22 -0600 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks |
| 58 | */ |
| 59 | struct vfio_iommu_driver_ops { |
| 60 | char *name; |
| 61 | struct module *owner; |
| 62 | void *(*open)(unsigned long arg); |
| 63 | void (*release)(void *iommu_data); |
| 64 | ssize_t (*read)(void *iommu_data, char __user *buf, |
| 65 | size_t count, loff_t *ppos); |
| 66 | ssize_t (*write)(void *iommu_data, const char __user *buf, |
| 67 | size_t count, loff_t *size); |
| 68 | long (*ioctl)(void *iommu_data, unsigned int cmd, |
| 69 | unsigned long arg); |
| 70 | int (*mmap)(void *iommu_data, struct vm_area_struct *vma); |
| 71 | int (*attach_group)(void *iommu_data, |
| 72 | struct iommu_group *group); |
| 73 | void (*detach_group)(void *iommu_data, |
| 74 | struct iommu_group *group); |
| 75 | |
| 76 | }; |
| 77 | |
| 78 | extern int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops); |
| 79 | |
| 80 | extern void vfio_unregister_iommu_driver( |
| 81 | const struct vfio_iommu_driver_ops *ops); |
| 82 | |
Alexey Kardashevskiy | 6cdd978 | 2013-08-05 10:52:36 -0600 | [diff] [blame] | 83 | /* |
| 84 | * External user API |
| 85 | */ |
| 86 | extern struct vfio_group *vfio_group_get_external_user(struct file *filep); |
| 87 | extern void vfio_group_put_external_user(struct vfio_group *group); |
| 88 | extern int vfio_external_user_iommu_id(struct vfio_group *group); |
Alex Williamson | 88d7ab8 | 2014-02-26 11:38:39 -0700 | [diff] [blame] | 89 | extern long vfio_external_check_extension(struct vfio_group *group, |
| 90 | unsigned long arg); |
Alexey Kardashevskiy | 6cdd978 | 2013-08-05 10:52:36 -0600 | [diff] [blame] | 91 | |
Gavin Shan | 92d18a6 | 2014-08-08 10:36:20 -0600 | [diff] [blame] | 92 | struct pci_dev; |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 93 | #ifdef CONFIG_EEH |
Alexey Kardashevskiy | 9b936c9 | 2014-08-08 10:39:16 -0600 | [diff] [blame] | 94 | extern void vfio_spapr_pci_eeh_open(struct pci_dev *pdev); |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 95 | extern void vfio_spapr_pci_eeh_release(struct pci_dev *pdev); |
| 96 | extern long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, |
| 97 | unsigned int cmd, |
| 98 | unsigned long arg); |
| 99 | #else |
Alexey Kardashevskiy | 9b936c9 | 2014-08-08 10:39:16 -0600 | [diff] [blame] | 100 | static inline void vfio_spapr_pci_eeh_open(struct pci_dev *pdev) |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 101 | { |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static inline void vfio_spapr_pci_eeh_release(struct pci_dev *pdev) |
| 105 | { |
| 106 | } |
| 107 | |
| 108 | static inline long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, |
| 109 | unsigned int cmd, |
| 110 | unsigned long arg) |
| 111 | { |
| 112 | return -ENOTTY; |
| 113 | } |
| 114 | #endif /* CONFIG_EEH */ |
Antonios Motakis | 7e992d6 | 2015-03-16 14:08:54 -0600 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * IRQfd - generic |
| 118 | */ |
| 119 | struct virqfd { |
| 120 | void *opaque; |
| 121 | struct eventfd_ctx *eventfd; |
| 122 | int (*handler)(void *, void *); |
| 123 | void (*thread)(void *, void *); |
| 124 | void *data; |
| 125 | struct work_struct inject; |
| 126 | wait_queue_t wait; |
| 127 | poll_table pt; |
| 128 | struct work_struct shutdown; |
| 129 | struct virqfd **pvirqfd; |
| 130 | }; |
| 131 | |
Antonios Motakis | 7e992d6 | 2015-03-16 14:08:54 -0600 | [diff] [blame] | 132 | extern int vfio_virqfd_enable(void *opaque, |
| 133 | int (*handler)(void *, void *), |
| 134 | void (*thread)(void *, void *), |
| 135 | void *data, struct virqfd **pvirqfd, int fd); |
| 136 | extern void vfio_virqfd_disable(struct virqfd **pvirqfd); |
| 137 | |
Alex Williamson | cba3345 | 2012-07-31 08:16:22 -0600 | [diff] [blame] | 138 | #endif /* VFIO_H */ |