You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
vfio: Type1 IOMMU implementation
This VFIO IOMMU backend is designed primarily for AMD-Vi and Intel VT-d hardware, but is potentially usable by anything supporting similar mapping functionality. We arbitrarily call this a Type1 backend for lack of a better name. This backend has no IOVA or host memory mapping restrictions for the user and is optimized for relatively static mappings. Mapped areas are pinned into system memory. Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
config VFIO_IOMMU_TYPE1
|
||||
tristate
|
||||
depends on VFIO
|
||||
default n
|
||||
|
||||
menuconfig VFIO
|
||||
tristate "VFIO Non-Privileged userspace driver framework"
|
||||
depends on IOMMU_API
|
||||
select VFIO_IOMMU_TYPE1 if X86
|
||||
help
|
||||
VFIO provides a framework for secure userspace device drivers.
|
||||
See Documentation/vfio.txt for more details.
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
obj-$(CONFIG_VFIO) += vfio.o
|
||||
obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o
|
||||
obj-$(CONFIG_VFIO_PCI) += pci/
|
||||
|
||||
@@ -1376,6 +1376,13 @@ static int __init vfio_init(void)
|
||||
|
||||
pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
|
||||
|
||||
/*
|
||||
* Attempt to load known iommu-drivers. This gives us a working
|
||||
* environment without the user needing to explicitly load iommu
|
||||
* drivers.
|
||||
*/
|
||||
request_module_nowait("vfio_iommu_type1");
|
||||
|
||||
return 0;
|
||||
|
||||
err_groups_cdev:
|
||||
|
||||
753
drivers/vfio/vfio_iommu_type1.c
Normal file
753
drivers/vfio/vfio_iommu_type1.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -98,7 +98,7 @@ extern void vfio_unregister_iommu_driver(
|
||||
|
||||
/* Extensions */
|
||||
|
||||
/* None yet */
|
||||
#define VFIO_TYPE1_IOMMU 1
|
||||
|
||||
/*
|
||||
* The IOCTL interface is designed for extensibility by embedding the
|
||||
@@ -364,4 +364,56 @@ struct vfio_irq_set {
|
||||
*/
|
||||
#define VFIO_DEVICE_RESET _IO(VFIO_TYPE, VFIO_BASE + 11)
|
||||
|
||||
/* -------- API for Type1 VFIO IOMMU -------- */
|
||||
|
||||
/**
|
||||
* VFIO_IOMMU_GET_INFO - _IOR(VFIO_TYPE, VFIO_BASE + 12, struct vfio_iommu_info)
|
||||
*
|
||||
* Retrieve information about the IOMMU object. Fills in provided
|
||||
* struct vfio_iommu_info. Caller sets argsz.
|
||||
*
|
||||
* XXX Should we do these by CHECK_EXTENSION too?
|
||||
*/
|
||||
struct vfio_iommu_type1_info {
|
||||
__u32 argsz;
|
||||
__u32 flags;
|
||||
#define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */
|
||||
__u64 iova_pgsizes; /* Bitmap of supported page sizes */
|
||||
};
|
||||
|
||||
#define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
|
||||
|
||||
/**
|
||||
* VFIO_IOMMU_MAP_DMA - _IOW(VFIO_TYPE, VFIO_BASE + 13, struct vfio_dma_map)
|
||||
*
|
||||
* Map process virtual addresses to IO virtual addresses using the
|
||||
* provided struct vfio_dma_map. Caller sets argsz. READ &/ WRITE required.
|
||||
*/
|
||||
struct vfio_iommu_type1_dma_map {
|
||||
__u32 argsz;
|
||||
__u32 flags;
|
||||
#define VFIO_DMA_MAP_FLAG_READ (1 << 0) /* readable from device */
|
||||
#define VFIO_DMA_MAP_FLAG_WRITE (1 << 1) /* writable from device */
|
||||
__u64 vaddr; /* Process virtual address */
|
||||
__u64 iova; /* IO virtual address */
|
||||
__u64 size; /* Size of mapping (bytes) */
|
||||
};
|
||||
|
||||
#define VFIO_IOMMU_MAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 13)
|
||||
|
||||
/**
|
||||
* VFIO_IOMMU_UNMAP_DMA - _IOW(VFIO_TYPE, VFIO_BASE + 14, struct vfio_dma_unmap)
|
||||
*
|
||||
* Unmap IO virtual addresses using the provided struct vfio_dma_unmap.
|
||||
* Caller sets argsz.
|
||||
*/
|
||||
struct vfio_iommu_type1_dma_unmap {
|
||||
__u32 argsz;
|
||||
__u32 flags;
|
||||
__u64 iova; /* IO virtual address */
|
||||
__u64 size; /* Size of mapping (bytes) */
|
||||
};
|
||||
|
||||
#define VFIO_IOMMU_UNMAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 14)
|
||||
|
||||
#endif /* VFIO_H */
|
||||
|
||||
Reference in New Issue
Block a user