2022-11-29 16:29:29 -04:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Intel Corporation
|
|
|
|
* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES
|
|
|
|
*/
|
|
|
|
#ifndef __LINUX_IOMMUFD_H
|
|
|
|
#define __LINUX_IOMMUFD_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/err.h>
|
2022-11-29 16:29:36 -04:00
|
|
|
#include <linux/device.h>
|
2022-11-29 16:29:29 -04:00
|
|
|
|
2022-11-29 16:29:36 -04:00
|
|
|
struct iommufd_device;
|
2022-11-29 16:29:29 -04:00
|
|
|
struct iommufd_ctx;
|
|
|
|
struct file;
|
|
|
|
|
2022-11-29 16:29:36 -04:00
|
|
|
struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx,
|
|
|
|
struct device *dev, u32 *id);
|
|
|
|
void iommufd_device_unbind(struct iommufd_device *idev);
|
|
|
|
|
|
|
|
int iommufd_device_attach(struct iommufd_device *idev, u32 *pt_id);
|
|
|
|
void iommufd_device_detach(struct iommufd_device *idev);
|
|
|
|
|
2022-11-29 16:29:31 -04:00
|
|
|
enum {
|
|
|
|
IOMMUFD_ACCESS_RW_READ = 0,
|
|
|
|
IOMMUFD_ACCESS_RW_WRITE = 1 << 0,
|
|
|
|
/* Set if the caller is in a kthread then rw will use kthread_use_mm() */
|
|
|
|
IOMMUFD_ACCESS_RW_KTHREAD = 1 << 1,
|
|
|
|
};
|
|
|
|
|
2022-11-29 16:29:29 -04:00
|
|
|
void iommufd_ctx_get(struct iommufd_ctx *ictx);
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_IOMMUFD)
|
|
|
|
struct iommufd_ctx *iommufd_ctx_from_file(struct file *file);
|
|
|
|
void iommufd_ctx_put(struct iommufd_ctx *ictx);
|
|
|
|
#else /* !CONFIG_IOMMUFD */
|
|
|
|
static inline struct iommufd_ctx *iommufd_ctx_from_file(struct file *file)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void iommufd_ctx_put(struct iommufd_ctx *ictx)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IOMMUFD */
|
|
|
|
#endif
|