This source file includes following definitions.
- kfd_interrupt_init
- kfd_interrupt_exit
- enqueue_ih_ring_entry
- dequeue_ih_ring_entry
- interrupt_wq
- interrupt_is_wanted
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 #include <linux/slab.h>
44 #include <linux/device.h>
45 #include <linux/kfifo.h>
46 #include "kfd_priv.h"
47
48 #define KFD_IH_NUM_ENTRIES 8192
49
50 static void interrupt_wq(struct work_struct *);
51
52 int kfd_interrupt_init(struct kfd_dev *kfd)
53 {
54 int r;
55
56 r = kfifo_alloc(&kfd->ih_fifo,
57 KFD_IH_NUM_ENTRIES * kfd->device_info->ih_ring_entry_size,
58 GFP_KERNEL);
59 if (r) {
60 dev_err(kfd_chardev(), "Failed to allocate IH fifo\n");
61 return r;
62 }
63
64 kfd->ih_wq = alloc_workqueue("KFD IH", WQ_HIGHPRI, 1);
65 if (unlikely(!kfd->ih_wq)) {
66 kfifo_free(&kfd->ih_fifo);
67 dev_err(kfd_chardev(), "Failed to allocate KFD IH workqueue\n");
68 return -ENOMEM;
69 }
70 spin_lock_init(&kfd->interrupt_lock);
71
72 INIT_WORK(&kfd->interrupt_work, interrupt_wq);
73
74 kfd->interrupts_active = true;
75
76
77
78
79
80
81 smp_wmb();
82
83 return 0;
84 }
85
86 void kfd_interrupt_exit(struct kfd_dev *kfd)
87 {
88
89
90
91
92
93 unsigned long flags;
94
95 spin_lock_irqsave(&kfd->interrupt_lock, flags);
96 kfd->interrupts_active = false;
97 spin_unlock_irqrestore(&kfd->interrupt_lock, flags);
98
99
100
101
102
103
104 flush_workqueue(kfd->ih_wq);
105
106 kfifo_free(&kfd->ih_fifo);
107 }
108
109
110
111
112 bool enqueue_ih_ring_entry(struct kfd_dev *kfd, const void *ih_ring_entry)
113 {
114 int count;
115
116 count = kfifo_in(&kfd->ih_fifo, ih_ring_entry,
117 kfd->device_info->ih_ring_entry_size);
118 if (count != kfd->device_info->ih_ring_entry_size) {
119 dev_err_ratelimited(kfd_chardev(),
120 "Interrupt ring overflow, dropping interrupt %d\n",
121 count);
122 return false;
123 }
124
125 return true;
126 }
127
128
129
130
131 static bool dequeue_ih_ring_entry(struct kfd_dev *kfd, void *ih_ring_entry)
132 {
133 int count;
134
135 count = kfifo_out(&kfd->ih_fifo, ih_ring_entry,
136 kfd->device_info->ih_ring_entry_size);
137
138 WARN_ON(count && count != kfd->device_info->ih_ring_entry_size);
139
140 return count == kfd->device_info->ih_ring_entry_size;
141 }
142
143 static void interrupt_wq(struct work_struct *work)
144 {
145 struct kfd_dev *dev = container_of(work, struct kfd_dev,
146 interrupt_work);
147 uint32_t ih_ring_entry[KFD_MAX_RING_ENTRY_SIZE];
148
149 if (dev->device_info->ih_ring_entry_size > sizeof(ih_ring_entry)) {
150 dev_err_once(kfd_chardev(), "Ring entry too small\n");
151 return;
152 }
153
154 while (dequeue_ih_ring_entry(dev, ih_ring_entry))
155 dev->device_info->event_interrupt_class->interrupt_wq(dev,
156 ih_ring_entry);
157 }
158
159 bool interrupt_is_wanted(struct kfd_dev *dev,
160 const uint32_t *ih_ring_entry,
161 uint32_t *patched_ihre, bool *flag)
162 {
163
164 unsigned int wanted = 0;
165
166 wanted |= dev->device_info->event_interrupt_class->interrupt_isr(dev,
167 ih_ring_entry, patched_ihre, flag);
168
169 return wanted != 0;
170 }