video: rockchip: iep: add drm support
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / iep / iep_iommu_ops.h
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 #ifdef CONFIG_ION
92 void iep_iommu_ion_set_ops(struct iep_iommu_info *iommu_info);
93 #endif
94
95 struct iep_iommu_info *iep_iommu_info_create(struct device *dev,
96                                              struct device *mmu_dev,
97                                              int alloc_type);
98 int iep_iommu_info_destroy(struct iep_iommu_info *iommu_info);
99
100 int iep_iommu_create(struct iep_iommu_info *iommu_info);
101 int iep_iommu_import(struct iep_iommu_info *iommu_info,
102                      struct iep_session *session, int fd);
103 int iep_iommu_free(struct iep_iommu_info *iommu_info,
104                    struct iep_session *session, int idx);
105 int iep_iommu_free_fd(struct iep_iommu_info *iommu_info,
106                       struct iep_session *session, int fd);
107 int iep_iommu_map_iommu(struct iep_iommu_info *iommu_info,
108                         struct iep_session *session,
109                         int idx,
110                         unsigned long *iova,
111                         unsigned long *size);
112 int iep_iommu_unmap_iommu(struct iep_iommu_info *iommu_info,
113                           struct iep_session *session,
114                           int idx);
115 int iep_iommu_destroy(struct iep_iommu_info *iommu_info);
116 void iep_iommu_dump(struct iep_iommu_info *iommu_info,
117                     struct iep_session *session);
118 void iep_iommu_clear(struct iep_iommu_info *iommu_info,
119                      struct iep_session *session);
120
121 int iep_iommu_attach(struct iep_iommu_info *iommu_info);
122 void iep_iommu_detach(struct iep_iommu_info *iommu_info);
123
124 #endif