xref: /OK3568_Linux_fs/kernel/drivers/video/rockchip/iep/iep_iommu_ops.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /**
2  * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd
3  * author: Jung Zhao jung.zhao@rock-chips.com
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15 
16 #ifndef __IEP_IOMMU_OPS_H__
17 #define __IEP_IOMMU_OPS_H__
18 
19 #include <linux/platform_device.h>
20 #include "iep_drv.h"
21 
22 #define BUFFER_LIST_MAX_NUMS	30
23 
24 #define ALLOCATOR_USE_ION		0x00000000
25 #define ALLOCATOR_USE_DRM		0x00000001
26 
27 #define DEBUG_IOMMU_OPS_DUMP	0x00020000
28 #define DEBUG_IOMMU_NORMAL	0x00040000
29 
30 #define vpu_iommu_debug_func(debug_level, type, fmt, args...)	\
31 	do {							\
32 		if (unlikely(debug_level & type)) {		\
33 			pr_info("%s:%d: " fmt,			\
34 				 __func__, __LINE__, ##args);	\
35 		}						\
36 	} while (0)
37 #define vpu_iommu_debug(debug_level, type, fmt, args...)	\
38 	do {							\
39 		if (unlikely(debug_level & type)) {		\
40 			pr_info(fmt, ##args);			\
41 		}						\
42 	} while (0)
43 
44 struct iep_iommu_info;
45 struct iep_iommu_session_info;
46 
47 struct iep_iommu_ops {
48 	int (*create)(struct iep_iommu_info *iommu_info);
49 	int (*import)(struct iep_iommu_session_info *session_info, int fd);
50 	int (*free)(struct iep_iommu_session_info *session_info, int idx);
51 	int (*free_fd)(struct iep_iommu_session_info *session_info, int fd);
52 	int (*map_iommu)(struct iep_iommu_session_info *session_info,
53 			 int idx,
54 			 unsigned long *iova, unsigned long *size);
55 	int (*unmap_iommu)(struct iep_iommu_session_info *session_info,
56 			   int idx);
57 	int (*destroy)(struct iep_iommu_info *iommu_info);
58 	void (*dump)(struct iep_iommu_session_info *session_info);
59 	int (*attach)(struct iep_iommu_info *iommu_info);
60 	void (*detach)(struct iep_iommu_info *iommu_info);
61 	void (*clear)(struct iep_iommu_session_info *session_info);
62 };
63 
64 struct iep_iommu_session_info {
65 	struct list_head head;
66 	struct iep_session *session;
67 	int buffer_nums;
68 	struct list_head buffer_list;
69 	struct mutex list_mutex;
70 	int max_idx;
71 	struct device *dev;
72 	struct device *mmu_dev;
73 	struct iep_iommu_info *iommu_info;
74 	int debug_level;
75 };
76 
77 struct iep_iommu_info {
78 	struct list_head session_list;
79 	struct mutex list_mutex;
80 	struct mutex iommu_mutex;
81 	struct device *dev;
82 	struct device *mmu_dev;
83 	struct iep_iommu_ops *ops;
84 	int debug_level;
85 	void *private;
86 };
87 
88 #ifdef CONFIG_DRM
89 void iep_iommu_drm_set_ops(struct iep_iommu_info *iommu_info);
90 #endif
91 
92 struct iep_iommu_info *iep_iommu_info_create(struct device *dev,
93 					     struct device *mmu_dev,
94 					     int alloc_type);
95 int iep_iommu_info_destroy(struct iep_iommu_info *iommu_info);
96 
97 int iep_iommu_create(struct iep_iommu_info *iommu_info);
98 int iep_iommu_import(struct iep_iommu_info *iommu_info,
99 		     struct iep_session *session, int fd);
100 int iep_iommu_free(struct iep_iommu_info *iommu_info,
101 		   struct iep_session *session, int idx);
102 int iep_iommu_free_fd(struct iep_iommu_info *iommu_info,
103 		      struct iep_session *session, int fd);
104 int iep_iommu_map_iommu(struct iep_iommu_info *iommu_info,
105 			struct iep_session *session,
106 			int idx,
107 			unsigned long *iova,
108 			unsigned long *size);
109 int iep_iommu_unmap_iommu(struct iep_iommu_info *iommu_info,
110 			  struct iep_session *session,
111 			  int idx);
112 int iep_iommu_destroy(struct iep_iommu_info *iommu_info);
113 void iep_iommu_dump(struct iep_iommu_info *iommu_info,
114 		    struct iep_session *session);
115 void iep_iommu_clear(struct iep_iommu_info *iommu_info,
116 		     struct iep_session *session);
117 
118 int iep_iommu_attach(struct iep_iommu_info *iommu_info);
119 void iep_iommu_detach(struct iep_iommu_info *iommu_info);
120 
121 #endif
122