This source file includes following definitions.
- amdgpu_amdkfd_fence_create
- to_amdgpu_amdkfd_fence
- amdkfd_fence_get_driver_name
- amdkfd_fence_get_timeline_name
- amdkfd_fence_enable_signaling
- amdkfd_fence_release
- amdkfd_fence_check_mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include <linux/dma-fence.h>
24 #include <linux/spinlock.h>
25 #include <linux/atomic.h>
26 #include <linux/stacktrace.h>
27 #include <linux/sched.h>
28 #include <linux/slab.h>
29 #include <linux/sched/mm.h>
30 #include "amdgpu_amdkfd.h"
31
32 static const struct dma_fence_ops amdkfd_fence_ops;
33 static atomic_t fence_seq = ATOMIC_INIT(0);
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 struct amdgpu_amdkfd_fence *amdgpu_amdkfd_fence_create(u64 context,
63 struct mm_struct *mm)
64 {
65 struct amdgpu_amdkfd_fence *fence;
66
67 fence = kzalloc(sizeof(*fence), GFP_KERNEL);
68 if (fence == NULL)
69 return NULL;
70
71
72 mmgrab(mm);
73 fence->mm = mm;
74 get_task_comm(fence->timeline_name, current);
75 spin_lock_init(&fence->lock);
76
77 dma_fence_init(&fence->base, &amdkfd_fence_ops, &fence->lock,
78 context, atomic_inc_return(&fence_seq));
79
80 return fence;
81 }
82
83 struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f)
84 {
85 struct amdgpu_amdkfd_fence *fence;
86
87 if (!f)
88 return NULL;
89
90 fence = container_of(f, struct amdgpu_amdkfd_fence, base);
91 if (fence && f->ops == &amdkfd_fence_ops)
92 return fence;
93
94 return NULL;
95 }
96
97 static const char *amdkfd_fence_get_driver_name(struct dma_fence *f)
98 {
99 return "amdgpu_amdkfd_fence";
100 }
101
102 static const char *amdkfd_fence_get_timeline_name(struct dma_fence *f)
103 {
104 struct amdgpu_amdkfd_fence *fence = to_amdgpu_amdkfd_fence(f);
105
106 return fence->timeline_name;
107 }
108
109
110
111
112
113
114
115 static bool amdkfd_fence_enable_signaling(struct dma_fence *f)
116 {
117 struct amdgpu_amdkfd_fence *fence = to_amdgpu_amdkfd_fence(f);
118
119 if (!fence)
120 return false;
121
122 if (dma_fence_is_signaled(f))
123 return true;
124
125 if (!kgd2kfd_schedule_evict_and_restore_process(fence->mm, f))
126 return true;
127
128 return false;
129 }
130
131
132
133
134
135
136
137
138
139 static void amdkfd_fence_release(struct dma_fence *f)
140 {
141 struct amdgpu_amdkfd_fence *fence = to_amdgpu_amdkfd_fence(f);
142
143
144
145
146 if (WARN_ON(!fence))
147 return;
148
149 mmdrop(fence->mm);
150 kfree_rcu(f, rcu);
151 }
152
153
154
155
156
157
158
159
160 bool amdkfd_fence_check_mm(struct dma_fence *f, struct mm_struct *mm)
161 {
162 struct amdgpu_amdkfd_fence *fence = to_amdgpu_amdkfd_fence(f);
163
164 if (!fence)
165 return false;
166 else if (fence->mm == mm)
167 return true;
168
169 return false;
170 }
171
172 static const struct dma_fence_ops amdkfd_fence_ops = {
173 .get_driver_name = amdkfd_fence_get_driver_name,
174 .get_timeline_name = amdkfd_fence_get_timeline_name,
175 .enable_signaling = amdkfd_fence_enable_signaling,
176 .release = amdkfd_fence_release,
177 };