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