at v6.3 104 lines 3.0 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * Copyright (C) 2021 Intel Corporation 4 * Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES 5 */ 6#ifndef __LINUX_IOMMUFD_H 7#define __LINUX_IOMMUFD_H 8 9#include <linux/types.h> 10#include <linux/errno.h> 11#include <linux/err.h> 12 13struct device; 14struct iommufd_device; 15struct page; 16struct iommufd_ctx; 17struct iommufd_access; 18struct file; 19 20struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, 21 struct device *dev, u32 *id); 22void iommufd_device_unbind(struct iommufd_device *idev); 23 24int iommufd_device_attach(struct iommufd_device *idev, u32 *pt_id); 25void iommufd_device_detach(struct iommufd_device *idev); 26 27struct iommufd_access_ops { 28 u8 needs_pin_pages : 1; 29 void (*unmap)(void *data, unsigned long iova, unsigned long length); 30}; 31 32enum { 33 IOMMUFD_ACCESS_RW_READ = 0, 34 IOMMUFD_ACCESS_RW_WRITE = 1 << 0, 35 /* Set if the caller is in a kthread then rw will use kthread_use_mm() */ 36 IOMMUFD_ACCESS_RW_KTHREAD = 1 << 1, 37 38 /* Only for use by selftest */ 39 __IOMMUFD_ACCESS_RW_SLOW_PATH = 1 << 2, 40}; 41 42struct iommufd_access * 43iommufd_access_create(struct iommufd_ctx *ictx, u32 ioas_id, 44 const struct iommufd_access_ops *ops, void *data); 45void iommufd_access_destroy(struct iommufd_access *access); 46 47void iommufd_ctx_get(struct iommufd_ctx *ictx); 48 49#if IS_ENABLED(CONFIG_IOMMUFD) 50struct iommufd_ctx *iommufd_ctx_from_file(struct file *file); 51void iommufd_ctx_put(struct iommufd_ctx *ictx); 52 53int iommufd_access_pin_pages(struct iommufd_access *access, unsigned long iova, 54 unsigned long length, struct page **out_pages, 55 unsigned int flags); 56void iommufd_access_unpin_pages(struct iommufd_access *access, 57 unsigned long iova, unsigned long length); 58int iommufd_access_rw(struct iommufd_access *access, unsigned long iova, 59 void *data, size_t len, unsigned int flags); 60int iommufd_vfio_compat_ioas_get_id(struct iommufd_ctx *ictx, u32 *out_ioas_id); 61int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx); 62int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx); 63#else /* !CONFIG_IOMMUFD */ 64static inline struct iommufd_ctx *iommufd_ctx_from_file(struct file *file) 65{ 66 return ERR_PTR(-EOPNOTSUPP); 67} 68 69static inline void iommufd_ctx_put(struct iommufd_ctx *ictx) 70{ 71} 72 73static inline int iommufd_access_pin_pages(struct iommufd_access *access, 74 unsigned long iova, 75 unsigned long length, 76 struct page **out_pages, 77 unsigned int flags) 78{ 79 return -EOPNOTSUPP; 80} 81 82static inline void iommufd_access_unpin_pages(struct iommufd_access *access, 83 unsigned long iova, 84 unsigned long length) 85{ 86} 87 88static inline int iommufd_access_rw(struct iommufd_access *access, unsigned long iova, 89 void *data, size_t len, unsigned int flags) 90{ 91 return -EOPNOTSUPP; 92} 93 94static inline int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx) 95{ 96 return -EOPNOTSUPP; 97} 98 99static inline int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx) 100{ 101 return -EOPNOTSUPP; 102} 103#endif /* CONFIG_IOMMUFD */ 104#endif