2012-07-31 22:16:22 +08:00
|
|
|
/*
|
|
|
|
* VFIO API definition
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc. All rights reserved.
|
|
|
|
* Author: Alex Williamson <alex.williamson@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#ifndef VFIO_H
|
|
|
|
#define VFIO_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <linux/iommu.h>
|
|
|
|
#include <linux/mm.h>
|
2012-10-13 17:46:48 +08:00
|
|
|
#include <uapi/linux/vfio.h>
|
2012-07-31 22:16:22 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct vfio_device_ops - VFIO bus driver device callbacks
|
|
|
|
*
|
|
|
|
* @open: Called when userspace creates new file descriptor for device
|
|
|
|
* @release: Called when userspace releases file descriptor for device
|
|
|
|
* @read: Perform read(2) on device file descriptor
|
|
|
|
* @write: Perform write(2) on device file descriptor
|
|
|
|
* @ioctl: Perform ioctl(2) on device file descriptor, supporting VFIO_DEVICE_*
|
|
|
|
* operations documented below
|
|
|
|
* @mmap: Perform mmap(2) on a region of the device file descriptor
|
2015-02-07 06:05:07 +08:00
|
|
|
* @request: Request for the bus driver to release the device
|
2012-07-31 22:16:22 +08:00
|
|
|
*/
|
|
|
|
struct vfio_device_ops {
|
|
|
|
char *name;
|
|
|
|
int (*open)(void *device_data);
|
|
|
|
void (*release)(void *device_data);
|
|
|
|
ssize_t (*read)(void *device_data, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos);
|
|
|
|
ssize_t (*write)(void *device_data, const char __user *buf,
|
|
|
|
size_t count, loff_t *size);
|
|
|
|
long (*ioctl)(void *device_data, unsigned int cmd,
|
|
|
|
unsigned long arg);
|
|
|
|
int (*mmap)(void *device_data, struct vm_area_struct *vma);
|
2015-02-07 06:05:07 +08:00
|
|
|
void (*request)(void *device_data, unsigned int count);
|
2012-07-31 22:16:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int vfio_add_group_dev(struct device *dev,
|
|
|
|
const struct vfio_device_ops *ops,
|
|
|
|
void *device_data);
|
|
|
|
|
|
|
|
extern void *vfio_del_group_dev(struct device *dev);
|
2013-03-11 23:28:44 +08:00
|
|
|
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);
|
2012-07-31 22:16:22 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks
|
|
|
|
*/
|
|
|
|
struct vfio_iommu_driver_ops {
|
|
|
|
char *name;
|
|
|
|
struct module *owner;
|
|
|
|
void *(*open)(unsigned long arg);
|
|
|
|
void (*release)(void *iommu_data);
|
|
|
|
ssize_t (*read)(void *iommu_data, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos);
|
|
|
|
ssize_t (*write)(void *iommu_data, const char __user *buf,
|
|
|
|
size_t count, loff_t *size);
|
|
|
|
long (*ioctl)(void *iommu_data, unsigned int cmd,
|
|
|
|
unsigned long arg);
|
|
|
|
int (*mmap)(void *iommu_data, struct vm_area_struct *vma);
|
|
|
|
int (*attach_group)(void *iommu_data,
|
|
|
|
struct iommu_group *group);
|
|
|
|
void (*detach_group)(void *iommu_data,
|
|
|
|
struct iommu_group *group);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
extern int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
|
|
|
|
|
|
|
|
extern void vfio_unregister_iommu_driver(
|
|
|
|
const struct vfio_iommu_driver_ops *ops);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* offsetofend(TYPE, MEMBER)
|
|
|
|
*
|
|
|
|
* @TYPE: The type of the structure
|
|
|
|
* @MEMBER: The member within the structure to get the end offset of
|
|
|
|
*
|
|
|
|
* Simple helper macro for dealing with variable sized structures passed
|
|
|
|
* from user space. This allows us to easily determine if the provided
|
|
|
|
* structure is sized to include various fields.
|
|
|
|
*/
|
2014-05-31 01:35:54 +08:00
|
|
|
#define offsetofend(TYPE, MEMBER) \
|
|
|
|
(offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER))
|
2012-07-31 22:16:22 +08:00
|
|
|
|
2013-08-06 00:52:36 +08:00
|
|
|
/*
|
|
|
|
* External user API
|
|
|
|
*/
|
|
|
|
extern struct vfio_group *vfio_group_get_external_user(struct file *filep);
|
|
|
|
extern void vfio_group_put_external_user(struct vfio_group *group);
|
|
|
|
extern int vfio_external_user_iommu_id(struct vfio_group *group);
|
2014-02-27 02:38:39 +08:00
|
|
|
extern long vfio_external_check_extension(struct vfio_group *group,
|
|
|
|
unsigned long arg);
|
2013-08-06 00:52:36 +08:00
|
|
|
|
2014-08-09 00:36:20 +08:00
|
|
|
struct pci_dev;
|
2014-06-10 09:41:57 +08:00
|
|
|
#ifdef CONFIG_EEH
|
2014-08-09 00:39:16 +08:00
|
|
|
extern void vfio_spapr_pci_eeh_open(struct pci_dev *pdev);
|
2014-06-10 09:41:57 +08:00
|
|
|
extern void vfio_spapr_pci_eeh_release(struct pci_dev *pdev);
|
|
|
|
extern long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
|
|
|
|
unsigned int cmd,
|
|
|
|
unsigned long arg);
|
|
|
|
#else
|
2014-08-09 00:39:16 +08:00
|
|
|
static inline void vfio_spapr_pci_eeh_open(struct pci_dev *pdev)
|
2014-06-10 09:41:57 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void vfio_spapr_pci_eeh_release(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
|
|
|
|
unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_EEH */
|
2012-07-31 22:16:22 +08:00
|
|
|
#endif /* VFIO_H */
|