Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[deliverable/linux.git] / include / linux / vfio.h
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
14
15 #include <linux/iommu.h>
16 #include <linux/mm.h>
17 #include <uapi/linux/vfio.h>
18
19 /**
20 * struct vfio_device_ops - VFIO bus driver device callbacks
21 *
22 * @open: Called when userspace creates new file descriptor for device
23 * @release: Called when userspace releases file descriptor for device
24 * @read: Perform read(2) on device file descriptor
25 * @write: Perform write(2) on device file descriptor
26 * @ioctl: Perform ioctl(2) on device file descriptor, supporting VFIO_DEVICE_*
27 * operations documented below
28 * @mmap: Perform mmap(2) on a region of the device file descriptor
29 * @request: Request for the bus driver to release the device
30 */
31 struct vfio_device_ops {
32 char *name;
33 int (*open)(void *device_data);
34 void (*release)(void *device_data);
35 ssize_t (*read)(void *device_data, char __user *buf,
36 size_t count, loff_t *ppos);
37 ssize_t (*write)(void *device_data, const char __user *buf,
38 size_t count, loff_t *size);
39 long (*ioctl)(void *device_data, unsigned int cmd,
40 unsigned long arg);
41 int (*mmap)(void *device_data, struct vm_area_struct *vma);
42 void (*request)(void *device_data, unsigned int count);
43 };
44
45 extern int vfio_add_group_dev(struct device *dev,
46 const struct vfio_device_ops *ops,
47 void *device_data);
48
49 extern void *vfio_del_group_dev(struct device *dev);
50 extern struct vfio_device *vfio_device_get_from_dev(struct device *dev);
51 extern void vfio_device_put(struct vfio_device *device);
52 extern void *vfio_device_data(struct vfio_device *device);
53
54 /**
55 * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks
56 */
57 struct vfio_iommu_driver_ops {
58 char *name;
59 struct module *owner;
60 void *(*open)(unsigned long arg);
61 void (*release)(void *iommu_data);
62 ssize_t (*read)(void *iommu_data, char __user *buf,
63 size_t count, loff_t *ppos);
64 ssize_t (*write)(void *iommu_data, const char __user *buf,
65 size_t count, loff_t *size);
66 long (*ioctl)(void *iommu_data, unsigned int cmd,
67 unsigned long arg);
68 int (*mmap)(void *iommu_data, struct vm_area_struct *vma);
69 int (*attach_group)(void *iommu_data,
70 struct iommu_group *group);
71 void (*detach_group)(void *iommu_data,
72 struct iommu_group *group);
73
74 };
75
76 extern int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
77
78 extern void vfio_unregister_iommu_driver(
79 const struct vfio_iommu_driver_ops *ops);
80
81 /*
82 * External user API
83 */
84 extern struct vfio_group *vfio_group_get_external_user(struct file *filep);
85 extern void vfio_group_put_external_user(struct vfio_group *group);
86 extern int vfio_external_user_iommu_id(struct vfio_group *group);
87 extern long vfio_external_check_extension(struct vfio_group *group,
88 unsigned long arg);
89
90 struct pci_dev;
91 #ifdef CONFIG_EEH
92 extern void vfio_spapr_pci_eeh_open(struct pci_dev *pdev);
93 extern void vfio_spapr_pci_eeh_release(struct pci_dev *pdev);
94 extern long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
95 unsigned int cmd,
96 unsigned long arg);
97 #else
98 static inline void vfio_spapr_pci_eeh_open(struct pci_dev *pdev)
99 {
100 }
101
102 static inline void vfio_spapr_pci_eeh_release(struct pci_dev *pdev)
103 {
104 }
105
106 static inline long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
107 unsigned int cmd,
108 unsigned long arg)
109 {
110 return -ENOTTY;
111 }
112 #endif /* CONFIG_EEH */
113 #endif /* VFIO_H */
This page took 0.050343 seconds and 5 git commands to generate.