xref: /openbmc/linux/drivers/iommu/iommu-sva.h (revision 2a12187d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * SVA library for IOMMU drivers
4  */
5 #ifndef _IOMMU_SVA_H
6 #define _IOMMU_SVA_H
7 
8 #include <linux/ioasid.h>
9 #include <linux/mm_types.h>
10 
11 int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max);
12 struct mm_struct *iommu_sva_find(ioasid_t pasid);
13 
14 /* I/O Page fault */
15 struct device;
16 struct iommu_fault;
17 struct iopf_queue;
18 
19 #ifdef CONFIG_IOMMU_SVA
20 int iommu_queue_iopf(struct iommu_fault *fault, void *cookie);
21 
22 int iopf_queue_add_device(struct iopf_queue *queue, struct device *dev);
23 int iopf_queue_remove_device(struct iopf_queue *queue,
24 			     struct device *dev);
25 int iopf_queue_flush_dev(struct device *dev);
26 struct iopf_queue *iopf_queue_alloc(const char *name);
27 void iopf_queue_free(struct iopf_queue *queue);
28 int iopf_queue_discard_partial(struct iopf_queue *queue);
29 enum iommu_page_response_code
30 iommu_sva_handle_iopf(struct iommu_fault *fault, void *data);
31 
32 #else /* CONFIG_IOMMU_SVA */
33 static inline int iommu_queue_iopf(struct iommu_fault *fault, void *cookie)
34 {
35 	return -ENODEV;
36 }
37 
38 static inline int iopf_queue_add_device(struct iopf_queue *queue,
39 					struct device *dev)
40 {
41 	return -ENODEV;
42 }
43 
44 static inline int iopf_queue_remove_device(struct iopf_queue *queue,
45 					   struct device *dev)
46 {
47 	return -ENODEV;
48 }
49 
50 static inline int iopf_queue_flush_dev(struct device *dev)
51 {
52 	return -ENODEV;
53 }
54 
55 static inline struct iopf_queue *iopf_queue_alloc(const char *name)
56 {
57 	return NULL;
58 }
59 
60 static inline void iopf_queue_free(struct iopf_queue *queue)
61 {
62 }
63 
64 static inline int iopf_queue_discard_partial(struct iopf_queue *queue)
65 {
66 	return -ENODEV;
67 }
68 
69 static inline enum iommu_page_response_code
70 iommu_sva_handle_iopf(struct iommu_fault *fault, void *data)
71 {
72 	return IOMMU_PAGE_RESP_INVALID;
73 }
74 #endif /* CONFIG_IOMMU_SVA */
75 #endif /* _IOMMU_SVA_H */
76