2021-09-24 23:56:59 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc. All rights reserved.
|
|
|
|
* Author: Alex Williamson <alex.williamson@redhat.com>
|
|
|
|
*/
|
2022-09-23 03:20:19 +08:00
|
|
|
#ifndef __VFIO_VFIO_H__
|
|
|
|
#define __VFIO_VFIO_H__
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
struct iommu_group;
|
2021-09-24 23:56:59 +08:00
|
|
|
|
2021-09-24 23:57:01 +08:00
|
|
|
enum vfio_group_type {
|
|
|
|
/*
|
|
|
|
* Physical device with IOMMU backing.
|
|
|
|
*/
|
|
|
|
VFIO_IOMMU,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Virtual device without IOMMU backing. The VFIO core fakes up an
|
|
|
|
* iommu_group as the iommu_group sysfs interface is part of the
|
|
|
|
* userspace ABI. The user of these devices must not be able to
|
|
|
|
* directly trigger unmediated DMA.
|
|
|
|
*/
|
|
|
|
VFIO_EMULATED_IOMMU,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Physical device without IOMMU backing. The VFIO core fakes up an
|
|
|
|
* iommu_group as the iommu_group sysfs interface is part of the
|
|
|
|
* userspace ABI. Users can trigger unmediated DMA by the device,
|
|
|
|
* usage is highly dangerous, requires an explicit opt-in and will
|
|
|
|
* taint the kernel.
|
|
|
|
*/
|
|
|
|
VFIO_NO_IOMMU,
|
|
|
|
};
|
|
|
|
|
2021-09-24 23:56:59 +08:00
|
|
|
/* events for the backend driver notify callback */
|
|
|
|
enum vfio_iommu_notify_type {
|
|
|
|
VFIO_IOMMU_CONTAINER_CLOSE = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
long (*ioctl)(void *iommu_data, unsigned int cmd,
|
|
|
|
unsigned long arg);
|
|
|
|
int (*attach_group)(void *iommu_data,
|
2021-09-24 23:57:01 +08:00
|
|
|
struct iommu_group *group,
|
|
|
|
enum vfio_group_type);
|
2021-09-24 23:56:59 +08:00
|
|
|
void (*detach_group)(void *iommu_data,
|
|
|
|
struct iommu_group *group);
|
|
|
|
int (*pin_pages)(void *iommu_data,
|
|
|
|
struct iommu_group *group,
|
2022-07-23 10:02:51 +08:00
|
|
|
dma_addr_t user_iova,
|
2021-09-24 23:56:59 +08:00
|
|
|
int npage, int prot,
|
2022-07-23 10:02:56 +08:00
|
|
|
struct page **pages);
|
2022-07-23 10:02:47 +08:00
|
|
|
void (*unpin_pages)(void *iommu_data,
|
2022-07-23 10:02:51 +08:00
|
|
|
dma_addr_t user_iova, int npage);
|
2022-07-20 08:02:49 +08:00
|
|
|
void (*register_device)(void *iommu_data,
|
|
|
|
struct vfio_device *vdev);
|
|
|
|
void (*unregister_device)(void *iommu_data,
|
|
|
|
struct vfio_device *vdev);
|
2021-09-24 23:56:59 +08:00
|
|
|
int (*dma_rw)(void *iommu_data, dma_addr_t user_iova,
|
|
|
|
void *data, size_t count, bool write);
|
|
|
|
struct iommu_domain *(*group_iommu_domain)(void *iommu_data,
|
|
|
|
struct iommu_group *group);
|
|
|
|
void (*notify)(void *iommu_data,
|
|
|
|
enum vfio_iommu_notify_type event);
|
|
|
|
};
|
|
|
|
|
|
|
|
int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
|
|
|
|
void vfio_unregister_iommu_driver(const struct vfio_iommu_driver_ops *ops);
|
2022-09-23 03:20:19 +08:00
|
|
|
|
|
|
|
#endif
|