Commit | Line | Data |
---|---|---|
4a488a7a OG |
1 | /* |
2 | * Copyright 2014 Advanced Micro Devices, Inc. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
20 | * OTHER DEALINGS IN THE SOFTWARE. | |
21 | */ | |
22 | ||
23 | #ifndef KFD_PRIV_H_INCLUDED | |
24 | #define KFD_PRIV_H_INCLUDED | |
25 | ||
26 | #include <linux/hashtable.h> | |
27 | #include <linux/mmu_notifier.h> | |
28 | #include <linux/mutex.h> | |
29 | #include <linux/types.h> | |
30 | #include <linux/atomic.h> | |
31 | #include <linux/workqueue.h> | |
32 | #include <linux/spinlock.h> | |
19f6d2a6 | 33 | #include <linux/kfd_ioctl.h> |
4a488a7a OG |
34 | #include <kgd_kfd_interface.h> |
35 | ||
5b5c4e40 EP |
36 | #define KFD_SYSFS_FILE_MODE 0444 |
37 | ||
f3a39818 AL |
38 | #define KFD_MMAP_DOORBELL_MASK 0x8000000000000 |
39 | #define KFD_MMAP_EVENTS_MASK 0x4000000000000 | |
40 | ||
ed6e6a34 BG |
41 | /* |
42 | * When working with cp scheduler we should assign the HIQ manually or via | |
43 | * the radeon driver to a fixed hqd slot, here are the fixed HIQ hqd slot | |
44 | * definitions for Kaveri. In Kaveri only the first ME queues participates | |
45 | * in the cp scheduling taking that in mind we set the HIQ slot in the | |
46 | * second ME. | |
47 | */ | |
48 | #define KFD_CIK_HIQ_PIPE 4 | |
49 | #define KFD_CIK_HIQ_QUEUE 0 | |
50 | ||
5b5c4e40 EP |
51 | /* GPU ID hash width in bits */ |
52 | #define KFD_GPU_ID_HASH_WIDTH 16 | |
53 | ||
54 | /* Macro for allocating structures */ | |
55 | #define kfd_alloc_struct(ptr_to_struct) \ | |
56 | ((typeof(ptr_to_struct)) kzalloc(sizeof(*ptr_to_struct), GFP_KERNEL)) | |
57 | ||
19f6d2a6 | 58 | #define KFD_MAX_NUM_OF_PROCESSES 512 |
b8cbab04 | 59 | #define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024 |
19f6d2a6 OG |
60 | |
61 | /* | |
b8cbab04 OG |
62 | * Kernel module parameter to specify maximum number of supported queues per |
63 | * device | |
19f6d2a6 | 64 | */ |
b8cbab04 | 65 | extern int max_num_of_queues_per_device; |
19f6d2a6 | 66 | |
b8cbab04 OG |
67 | #define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT 4096 |
68 | #define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE \ | |
69 | (KFD_MAX_NUM_OF_PROCESSES * \ | |
70 | KFD_MAX_NUM_OF_QUEUES_PER_PROCESS) | |
19f6d2a6 | 71 | |
ed6e6a34 BG |
72 | #define KFD_KERNEL_QUEUE_SIZE 2048 |
73 | ||
31c21fec BG |
74 | /* Kernel module parameter to specify the scheduling policy */ |
75 | extern int sched_policy; | |
76 | ||
81663016 OG |
77 | /* |
78 | * Kernel module parameter to specify whether to send sigterm to HSA process on | |
79 | * unhandled exception | |
80 | */ | |
81 | extern int send_sigterm; | |
82 | ||
31c21fec BG |
83 | /** |
84 | * enum kfd_sched_policy | |
85 | * | |
86 | * @KFD_SCHED_POLICY_HWS: H/W scheduling policy known as command processor (cp) | |
87 | * scheduling. In this scheduling mode we're using the firmware code to | |
88 | * schedule the user mode queues and kernel queues such as HIQ and DIQ. | |
89 | * the HIQ queue is used as a special queue that dispatches the configuration | |
90 | * to the cp and the user mode queues list that are currently running. | |
91 | * the DIQ queue is a debugging queue that dispatches debugging commands to the | |
92 | * firmware. | |
93 | * in this scheduling mode user mode queues over subscription feature is | |
94 | * enabled. | |
95 | * | |
96 | * @KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION: The same as above but the over | |
97 | * subscription feature disabled. | |
98 | * | |
99 | * @KFD_SCHED_POLICY_NO_HWS: no H/W scheduling policy is a mode which directly | |
100 | * set the command processor registers and sets the queues "manually". This | |
101 | * mode is used *ONLY* for debugging proposes. | |
102 | * | |
103 | */ | |
104 | enum kfd_sched_policy { | |
105 | KFD_SCHED_POLICY_HWS = 0, | |
106 | KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION, | |
107 | KFD_SCHED_POLICY_NO_HWS | |
108 | }; | |
109 | ||
ed6e6a34 BG |
110 | enum cache_policy { |
111 | cache_policy_coherent, | |
112 | cache_policy_noncoherent | |
113 | }; | |
114 | ||
0da7558c BG |
115 | enum asic_family_type { |
116 | CHIP_KAVERI = 0, | |
117 | CHIP_CARRIZO | |
118 | }; | |
119 | ||
f3a39818 AL |
120 | struct kfd_event_interrupt_class { |
121 | bool (*interrupt_isr)(struct kfd_dev *dev, | |
122 | const uint32_t *ih_ring_entry); | |
123 | void (*interrupt_wq)(struct kfd_dev *dev, | |
124 | const uint32_t *ih_ring_entry); | |
125 | }; | |
126 | ||
4a488a7a | 127 | struct kfd_device_info { |
0da7558c | 128 | unsigned int asic_family; |
f3a39818 | 129 | const struct kfd_event_interrupt_class *event_interrupt_class; |
4a488a7a | 130 | unsigned int max_pasid_bits; |
992839ad | 131 | unsigned int max_no_of_hqd; |
4a488a7a | 132 | size_t ih_ring_entry_size; |
f7c826ad | 133 | uint8_t num_of_watch_points; |
19f6d2a6 | 134 | uint16_t mqd_size_aligned; |
4a488a7a OG |
135 | }; |
136 | ||
36b5c08f OG |
137 | struct kfd_mem_obj { |
138 | uint32_t range_start; | |
139 | uint32_t range_end; | |
140 | uint64_t gpu_addr; | |
141 | uint32_t *cpu_ptr; | |
142 | }; | |
143 | ||
4a488a7a OG |
144 | struct kfd_dev { |
145 | struct kgd_dev *kgd; | |
146 | ||
147 | const struct kfd_device_info *device_info; | |
148 | struct pci_dev *pdev; | |
149 | ||
150 | unsigned int id; /* topology stub index */ | |
151 | ||
19f6d2a6 OG |
152 | phys_addr_t doorbell_base; /* Start of actual doorbells used by |
153 | * KFD. It is aligned for mapping | |
154 | * into user mode | |
155 | */ | |
156 | size_t doorbell_id_offset; /* Doorbell offset (from KFD doorbell | |
157 | * to HW doorbell, GFX reserved some | |
158 | * at the start) | |
159 | */ | |
19f6d2a6 OG |
160 | u32 __iomem *doorbell_kernel_ptr; /* This is a pointer for a doorbells |
161 | * page used by kernel queue | |
162 | */ | |
163 | ||
4a488a7a OG |
164 | struct kgd2kfd_shared_resources shared_resources; |
165 | ||
cea405b1 XZ |
166 | const struct kfd2kgd_calls *kfd2kgd; |
167 | struct mutex doorbell_mutex; | |
f761d8bd JP |
168 | DECLARE_BITMAP(doorbell_available_index, |
169 | KFD_MAX_NUM_OF_QUEUES_PER_PROCESS); | |
cea405b1 | 170 | |
36b5c08f OG |
171 | void *gtt_mem; |
172 | uint64_t gtt_start_gpu_addr; | |
173 | void *gtt_start_cpu_ptr; | |
174 | void *gtt_sa_bitmap; | |
175 | struct mutex gtt_sa_lock; | |
176 | unsigned int gtt_sa_chunk_size; | |
177 | unsigned int gtt_sa_num_of_chunks; | |
178 | ||
2249d558 AL |
179 | /* Interrupts */ |
180 | void *interrupt_ring; | |
181 | size_t interrupt_ring_size; | |
182 | atomic_t interrupt_ring_rptr; | |
183 | atomic_t interrupt_ring_wptr; | |
184 | struct work_struct interrupt_work; | |
185 | spinlock_t interrupt_lock; | |
186 | ||
ed6e6a34 BG |
187 | /* QCM Device instance */ |
188 | struct device_queue_manager *dqm; | |
4a488a7a | 189 | |
ed6e6a34 | 190 | bool init_complete; |
2249d558 AL |
191 | /* |
192 | * Interrupts of interest to KFD are copied | |
193 | * from the HW ring into a SW ring. | |
194 | */ | |
195 | bool interrupts_active; | |
fbeb661b YS |
196 | |
197 | /* Debug manager */ | |
198 | struct kfd_dbgmgr *dbgmgr; | |
4a488a7a OG |
199 | }; |
200 | ||
201 | /* KGD2KFD callbacks */ | |
202 | void kgd2kfd_exit(void); | |
cea405b1 XZ |
203 | struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, |
204 | struct pci_dev *pdev, const struct kfd2kgd_calls *f2g); | |
4a488a7a | 205 | bool kgd2kfd_device_init(struct kfd_dev *kfd, |
cea405b1 | 206 | const struct kgd2kfd_shared_resources *gpu_resources); |
4a488a7a OG |
207 | void kgd2kfd_device_exit(struct kfd_dev *kfd); |
208 | ||
19f6d2a6 OG |
209 | enum kfd_mempool { |
210 | KFD_MEMPOOL_SYSTEM_CACHEABLE = 1, | |
211 | KFD_MEMPOOL_SYSTEM_WRITECOMBINE = 2, | |
212 | KFD_MEMPOOL_FRAMEBUFFER = 3, | |
213 | }; | |
214 | ||
4a488a7a OG |
215 | /* Character device interface */ |
216 | int kfd_chardev_init(void); | |
217 | void kfd_chardev_exit(void); | |
218 | struct device *kfd_chardev(void); | |
219 | ||
241f24f8 BG |
220 | /** |
221 | * enum kfd_preempt_type_filter | |
222 | * | |
223 | * @KFD_PREEMPT_TYPE_FILTER_SINGLE_QUEUE: Preempts single queue. | |
224 | * | |
225 | * @KFD_PRERMPT_TYPE_FILTER_ALL_QUEUES: Preempts all queues in the | |
226 | * running queues list. | |
227 | * | |
228 | * @KFD_PRERMPT_TYPE_FILTER_BY_PASID: Preempts queues that belongs to | |
229 | * specific process. | |
230 | * | |
231 | */ | |
232 | enum kfd_preempt_type_filter { | |
233 | KFD_PREEMPT_TYPE_FILTER_SINGLE_QUEUE, | |
234 | KFD_PREEMPT_TYPE_FILTER_ALL_QUEUES, | |
992839ad | 235 | KFD_PREEMPT_TYPE_FILTER_DYNAMIC_QUEUES, |
241f24f8 BG |
236 | KFD_PREEMPT_TYPE_FILTER_BY_PASID |
237 | }; | |
19f6d2a6 | 238 | |
ed8aab45 BG |
239 | /** |
240 | * enum kfd_queue_type | |
241 | * | |
242 | * @KFD_QUEUE_TYPE_COMPUTE: Regular user mode queue type. | |
243 | * | |
244 | * @KFD_QUEUE_TYPE_SDMA: Sdma user mode queue type. | |
245 | * | |
246 | * @KFD_QUEUE_TYPE_HIQ: HIQ queue type. | |
247 | * | |
248 | * @KFD_QUEUE_TYPE_DIQ: DIQ queue type. | |
249 | */ | |
250 | enum kfd_queue_type { | |
251 | KFD_QUEUE_TYPE_COMPUTE, | |
252 | KFD_QUEUE_TYPE_SDMA, | |
253 | KFD_QUEUE_TYPE_HIQ, | |
254 | KFD_QUEUE_TYPE_DIQ | |
255 | }; | |
256 | ||
6e99df57 BG |
257 | enum kfd_queue_format { |
258 | KFD_QUEUE_FORMAT_PM4, | |
259 | KFD_QUEUE_FORMAT_AQL | |
260 | }; | |
261 | ||
ed8aab45 BG |
262 | /** |
263 | * struct queue_properties | |
264 | * | |
265 | * @type: The queue type. | |
266 | * | |
267 | * @queue_id: Queue identifier. | |
268 | * | |
269 | * @queue_address: Queue ring buffer address. | |
270 | * | |
271 | * @queue_size: Queue ring buffer size. | |
272 | * | |
273 | * @priority: Defines the queue priority relative to other queues in the | |
274 | * process. | |
275 | * This is just an indication and HW scheduling may override the priority as | |
276 | * necessary while keeping the relative prioritization. | |
277 | * the priority granularity is from 0 to f which f is the highest priority. | |
278 | * currently all queues are initialized with the highest priority. | |
279 | * | |
280 | * @queue_percent: This field is partially implemented and currently a zero in | |
281 | * this field defines that the queue is non active. | |
282 | * | |
283 | * @read_ptr: User space address which points to the number of dwords the | |
284 | * cp read from the ring buffer. This field updates automatically by the H/W. | |
285 | * | |
286 | * @write_ptr: Defines the number of dwords written to the ring buffer. | |
287 | * | |
288 | * @doorbell_ptr: This field aim is to notify the H/W of new packet written to | |
8eabaf54 KR |
289 | * the queue ring buffer. This field should be similar to write_ptr and the |
290 | * user should update this field after he updated the write_ptr. | |
ed8aab45 BG |
291 | * |
292 | * @doorbell_off: The doorbell offset in the doorbell pci-bar. | |
293 | * | |
8eabaf54 KR |
294 | * @is_interop: Defines if this is a interop queue. Interop queue means that |
295 | * the queue can access both graphics and compute resources. | |
ed8aab45 BG |
296 | * |
297 | * @is_active: Defines if the queue is active or not. | |
298 | * | |
299 | * @vmid: If the scheduling mode is no cp scheduling the field defines the vmid | |
300 | * of the queue. | |
301 | * | |
302 | * This structure represents the queue properties for each queue no matter if | |
303 | * it's user mode or kernel mode queue. | |
304 | * | |
305 | */ | |
306 | struct queue_properties { | |
307 | enum kfd_queue_type type; | |
6e99df57 | 308 | enum kfd_queue_format format; |
ed8aab45 BG |
309 | unsigned int queue_id; |
310 | uint64_t queue_address; | |
311 | uint64_t queue_size; | |
312 | uint32_t priority; | |
313 | uint32_t queue_percent; | |
314 | uint32_t *read_ptr; | |
315 | uint32_t *write_ptr; | |
5cd78de5 | 316 | uint32_t __iomem *doorbell_ptr; |
ed8aab45 BG |
317 | uint32_t doorbell_off; |
318 | bool is_interop; | |
319 | bool is_active; | |
320 | /* Not relevant for user mode queues in cp scheduling */ | |
321 | unsigned int vmid; | |
77669eb8 BG |
322 | /* Relevant only for sdma queues*/ |
323 | uint32_t sdma_engine_id; | |
324 | uint32_t sdma_queue_id; | |
325 | uint32_t sdma_vm_addr; | |
ff3d04a1 BG |
326 | /* Relevant only for VI */ |
327 | uint64_t eop_ring_buffer_address; | |
328 | uint32_t eop_ring_buffer_size; | |
329 | uint64_t ctx_save_restore_area_address; | |
330 | uint32_t ctx_save_restore_area_size; | |
ed8aab45 BG |
331 | }; |
332 | ||
333 | /** | |
334 | * struct queue | |
335 | * | |
336 | * @list: Queue linked list. | |
337 | * | |
338 | * @mqd: The queue MQD. | |
339 | * | |
340 | * @mqd_mem_obj: The MQD local gpu memory object. | |
341 | * | |
342 | * @gart_mqd_addr: The MQD gart mc address. | |
343 | * | |
344 | * @properties: The queue properties. | |
345 | * | |
346 | * @mec: Used only in no cp scheduling mode and identifies to micro engine id | |
8eabaf54 | 347 | * that the queue should be execute on. |
ed8aab45 | 348 | * |
8eabaf54 KR |
349 | * @pipe: Used only in no cp scheduling mode and identifies the queue's pipe |
350 | * id. | |
ed8aab45 BG |
351 | * |
352 | * @queue: Used only in no cp scheduliong mode and identifies the queue's slot. | |
353 | * | |
354 | * @process: The kfd process that created this queue. | |
355 | * | |
356 | * @device: The kfd device that created this queue. | |
357 | * | |
358 | * This structure represents user mode compute queues. | |
359 | * It contains all the necessary data to handle such queues. | |
360 | * | |
361 | */ | |
362 | ||
363 | struct queue { | |
364 | struct list_head list; | |
365 | void *mqd; | |
366 | struct kfd_mem_obj *mqd_mem_obj; | |
367 | uint64_t gart_mqd_addr; | |
368 | struct queue_properties properties; | |
369 | ||
370 | uint32_t mec; | |
371 | uint32_t pipe; | |
372 | uint32_t queue; | |
373 | ||
77669eb8 BG |
374 | unsigned int sdma_id; |
375 | ||
ed8aab45 BG |
376 | struct kfd_process *process; |
377 | struct kfd_dev *device; | |
378 | }; | |
379 | ||
6e99df57 BG |
380 | /* |
381 | * Please read the kfd_mqd_manager.h description. | |
382 | */ | |
383 | enum KFD_MQD_TYPE { | |
85d258f9 BG |
384 | KFD_MQD_TYPE_COMPUTE = 0, /* for no cp scheduling */ |
385 | KFD_MQD_TYPE_HIQ, /* for hiq */ | |
386 | KFD_MQD_TYPE_CP, /* for cp queues and diq */ | |
387 | KFD_MQD_TYPE_SDMA, /* for sdma queues */ | |
6e99df57 BG |
388 | KFD_MQD_TYPE_MAX |
389 | }; | |
390 | ||
241f24f8 BG |
391 | struct scheduling_resources { |
392 | unsigned int vmid_mask; | |
393 | enum kfd_queue_type type; | |
394 | uint64_t queue_mask; | |
395 | uint64_t gws_mask; | |
396 | uint32_t oac_mask; | |
397 | uint32_t gds_heap_base; | |
398 | uint32_t gds_heap_size; | |
399 | }; | |
400 | ||
401 | struct process_queue_manager { | |
402 | /* data */ | |
403 | struct kfd_process *process; | |
404 | unsigned int num_concurrent_processes; | |
405 | struct list_head queues; | |
406 | unsigned long *queue_slot_bitmap; | |
407 | }; | |
408 | ||
409 | struct qcm_process_device { | |
410 | /* The Device Queue Manager that owns this data */ | |
411 | struct device_queue_manager *dqm; | |
412 | struct process_queue_manager *pqm; | |
241f24f8 BG |
413 | /* Queues list */ |
414 | struct list_head queues_list; | |
415 | struct list_head priv_queue_list; | |
416 | ||
417 | unsigned int queue_count; | |
418 | unsigned int vmid; | |
419 | bool is_debug; | |
420 | /* | |
421 | * All the memory management data should be here too | |
422 | */ | |
423 | uint64_t gds_context_area; | |
424 | uint32_t sh_mem_config; | |
425 | uint32_t sh_mem_bases; | |
426 | uint32_t sh_mem_ape1_base; | |
427 | uint32_t sh_mem_ape1_limit; | |
428 | uint32_t page_table_base; | |
429 | uint32_t gds_size; | |
430 | uint32_t num_gws; | |
431 | uint32_t num_oac; | |
6a1c9510 | 432 | uint32_t sh_hidden_private_base; |
241f24f8 BG |
433 | }; |
434 | ||
19f6d2a6 OG |
435 | /* Data that is per-process-per device. */ |
436 | struct kfd_process_device { | |
437 | /* | |
438 | * List of all per-device data for a process. | |
439 | * Starts from kfd_process.per_device_data. | |
440 | */ | |
441 | struct list_head per_device_list; | |
442 | ||
443 | /* The device that owns this data. */ | |
444 | struct kfd_dev *dev; | |
445 | ||
446 | ||
45102048 BG |
447 | /* per-process-per device QCM data structure */ |
448 | struct qcm_process_device qpd; | |
449 | ||
19f6d2a6 OG |
450 | /*Apertures*/ |
451 | uint64_t lds_base; | |
452 | uint64_t lds_limit; | |
453 | uint64_t gpuvm_base; | |
454 | uint64_t gpuvm_limit; | |
455 | uint64_t scratch_base; | |
456 | uint64_t scratch_limit; | |
457 | ||
458 | /* Is this process/pasid bound to this device? (amd_iommu_bind_pasid) */ | |
459 | bool bound; | |
a82918f1 BG |
460 | |
461 | /* This flag tells if we should reset all | |
462 | * wavefronts on process termination | |
463 | */ | |
464 | bool reset_wavefronts; | |
19f6d2a6 OG |
465 | }; |
466 | ||
52a5fdce AS |
467 | #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd) |
468 | ||
4a488a7a OG |
469 | /* Process data */ |
470 | struct kfd_process { | |
19f6d2a6 OG |
471 | /* |
472 | * kfd_process are stored in an mm_struct*->kfd_process* | |
473 | * hash table (kfd_processes in kfd_process.c) | |
474 | */ | |
475 | struct hlist_node kfd_processes; | |
476 | ||
477 | struct mm_struct *mm; | |
478 | ||
479 | struct mutex mutex; | |
480 | ||
481 | /* | |
482 | * In any process, the thread that started main() is the lead | |
483 | * thread and outlives the rest. | |
484 | * It is here because amd_iommu_bind_pasid wants a task_struct. | |
485 | */ | |
486 | struct task_struct *lead_thread; | |
487 | ||
488 | /* We want to receive a notification when the mm_struct is destroyed */ | |
489 | struct mmu_notifier mmu_notifier; | |
490 | ||
491 | /* Use for delayed freeing of kfd_process structure */ | |
492 | struct rcu_head rcu; | |
493 | ||
494 | unsigned int pasid; | |
a91e70e3 | 495 | unsigned int doorbell_index; |
19f6d2a6 OG |
496 | |
497 | /* | |
498 | * List of kfd_process_device structures, | |
499 | * one for each device the process is using. | |
500 | */ | |
501 | struct list_head per_device_data; | |
502 | ||
45102048 BG |
503 | struct process_queue_manager pqm; |
504 | ||
19f6d2a6 OG |
505 | /* The process's queues. */ |
506 | size_t queue_array_size; | |
507 | ||
508 | /* Size is queue_array_size, up to MAX_PROCESS_QUEUES. */ | |
509 | struct kfd_queue **queues; | |
510 | ||
19f6d2a6 OG |
511 | /*Is the user space process 32 bit?*/ |
512 | bool is_32bit_user_mode; | |
f3a39818 AL |
513 | |
514 | /* Event-related data */ | |
515 | struct mutex event_mutex; | |
516 | /* All events in process hashed by ID, linked on kfd_event.events. */ | |
517 | DECLARE_HASHTABLE(events, 4); | |
8eabaf54 KR |
518 | /* struct slot_page_header.event_pages */ |
519 | struct list_head signal_event_pages; | |
f3a39818 AL |
520 | u32 next_nonsignal_event_id; |
521 | size_t signal_event_count; | |
c986169f | 522 | bool signal_event_limit_reached; |
4a488a7a OG |
523 | }; |
524 | ||
76baee6c OG |
525 | /** |
526 | * Ioctl function type. | |
527 | * | |
528 | * \param filep pointer to file structure. | |
529 | * \param p amdkfd process pointer. | |
530 | * \param data pointer to arg that was copied from user. | |
531 | */ | |
532 | typedef int amdkfd_ioctl_t(struct file *filep, struct kfd_process *p, | |
533 | void *data); | |
534 | ||
535 | struct amdkfd_ioctl_desc { | |
536 | unsigned int cmd; | |
537 | int flags; | |
538 | amdkfd_ioctl_t *func; | |
539 | unsigned int cmd_drv; | |
540 | const char *name; | |
541 | }; | |
542 | ||
19f6d2a6 OG |
543 | void kfd_process_create_wq(void); |
544 | void kfd_process_destroy_wq(void); | |
545 | struct kfd_process *kfd_create_process(const struct task_struct *); | |
546 | struct kfd_process *kfd_get_process(const struct task_struct *); | |
f3a39818 | 547 | struct kfd_process *kfd_lookup_process_by_pasid(unsigned int pasid); |
19f6d2a6 | 548 | |
64c7f8cf BG |
549 | struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev, |
550 | struct kfd_process *p); | |
b17f068a | 551 | void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid); |
19f6d2a6 | 552 | struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev, |
093c7d8c AS |
553 | struct kfd_process *p); |
554 | struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev, | |
555 | struct kfd_process *p); | |
19f6d2a6 | 556 | |
775921ed | 557 | /* Process device data iterator */ |
8eabaf54 KR |
558 | struct kfd_process_device *kfd_get_first_process_device_data( |
559 | struct kfd_process *p); | |
560 | struct kfd_process_device *kfd_get_next_process_device_data( | |
561 | struct kfd_process *p, | |
775921ed AS |
562 | struct kfd_process_device *pdd); |
563 | bool kfd_has_process_device_data(struct kfd_process *p); | |
564 | ||
19f6d2a6 OG |
565 | /* PASIDs */ |
566 | int kfd_pasid_init(void); | |
567 | void kfd_pasid_exit(void); | |
568 | bool kfd_set_pasid_limit(unsigned int new_limit); | |
569 | unsigned int kfd_get_pasid_limit(void); | |
570 | unsigned int kfd_pasid_alloc(void); | |
571 | void kfd_pasid_free(unsigned int pasid); | |
572 | ||
573 | /* Doorbells */ | |
735df2ba FK |
574 | int kfd_doorbell_init(struct kfd_dev *kfd); |
575 | void kfd_doorbell_fini(struct kfd_dev *kfd); | |
19f6d2a6 OG |
576 | int kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma); |
577 | u32 __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd, | |
578 | unsigned int *doorbell_off); | |
579 | void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr); | |
580 | u32 read_kernel_doorbell(u32 __iomem *db); | |
581 | void write_kernel_doorbell(u32 __iomem *db, u32 value); | |
582 | unsigned int kfd_queue_id_to_doorbell(struct kfd_dev *kfd, | |
583 | struct kfd_process *process, | |
584 | unsigned int queue_id); | |
a91e70e3 FK |
585 | phys_addr_t kfd_get_process_doorbells(struct kfd_dev *dev, |
586 | struct kfd_process *process); | |
587 | int kfd_alloc_process_doorbells(struct kfd_process *process); | |
588 | void kfd_free_process_doorbells(struct kfd_process *process); | |
19f6d2a6 | 589 | |
6e81090b OG |
590 | /* GTT Sub-Allocator */ |
591 | ||
592 | int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size, | |
593 | struct kfd_mem_obj **mem_obj); | |
594 | ||
595 | int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj); | |
596 | ||
4a488a7a OG |
597 | extern struct device *kfd_device; |
598 | ||
5b5c4e40 EP |
599 | /* Topology */ |
600 | int kfd_topology_init(void); | |
601 | void kfd_topology_shutdown(void); | |
602 | int kfd_topology_add_device(struct kfd_dev *gpu); | |
603 | int kfd_topology_remove_device(struct kfd_dev *gpu); | |
604 | struct kfd_dev *kfd_device_by_id(uint32_t gpu_id); | |
605 | struct kfd_dev *kfd_device_by_pci_dev(const struct pci_dev *pdev); | |
606 | struct kfd_dev *kfd_topology_enum_kfd_devices(uint8_t idx); | |
607 | ||
4a488a7a | 608 | /* Interrupts */ |
2249d558 AL |
609 | int kfd_interrupt_init(struct kfd_dev *dev); |
610 | void kfd_interrupt_exit(struct kfd_dev *dev); | |
b3f5e6b4 | 611 | void kgd2kfd_interrupt(struct kfd_dev *kfd, const void *ih_ring_entry); |
2249d558 AL |
612 | bool enqueue_ih_ring_entry(struct kfd_dev *kfd, const void *ih_ring_entry); |
613 | bool interrupt_is_wanted(struct kfd_dev *dev, const uint32_t *ih_ring_entry); | |
4a488a7a OG |
614 | |
615 | /* Power Management */ | |
b3f5e6b4 AL |
616 | void kgd2kfd_suspend(struct kfd_dev *kfd); |
617 | int kgd2kfd_resume(struct kfd_dev *kfd); | |
4a488a7a | 618 | |
19f6d2a6 OG |
619 | /* amdkfd Apertures */ |
620 | int kfd_init_apertures(struct kfd_process *process); | |
621 | ||
ed6e6a34 | 622 | /* Queue Context Management */ |
77669eb8 | 623 | struct cik_sdma_rlc_registers *get_sdma_mqd(void *mqd); |
241f24f8 | 624 | |
e88a614c | 625 | int init_queue(struct queue **q, const struct queue_properties *properties); |
ed6e6a34 | 626 | void uninit_queue(struct queue *q); |
45102048 | 627 | void print_queue_properties(struct queue_properties *q); |
ed6e6a34 BG |
628 | void print_queue(struct queue *q); |
629 | ||
64c7f8cf BG |
630 | struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type, |
631 | struct kfd_dev *dev); | |
4b8f589b BG |
632 | struct mqd_manager *mqd_manager_init_cik(enum KFD_MQD_TYPE type, |
633 | struct kfd_dev *dev); | |
634 | struct mqd_manager *mqd_manager_init_vi(enum KFD_MQD_TYPE type, | |
635 | struct kfd_dev *dev); | |
64c7f8cf BG |
636 | struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev); |
637 | void device_queue_manager_uninit(struct device_queue_manager *dqm); | |
241f24f8 BG |
638 | struct kernel_queue *kernel_queue_init(struct kfd_dev *dev, |
639 | enum kfd_queue_type type); | |
640 | void kernel_queue_uninit(struct kernel_queue *kq); | |
641 | ||
45102048 BG |
642 | /* Process Queue Manager */ |
643 | struct process_queue_node { | |
644 | struct queue *q; | |
645 | struct kernel_queue *kq; | |
646 | struct list_head process_queue_list; | |
647 | }; | |
648 | ||
649 | int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p); | |
650 | void pqm_uninit(struct process_queue_manager *pqm); | |
651 | int pqm_create_queue(struct process_queue_manager *pqm, | |
652 | struct kfd_dev *dev, | |
653 | struct file *f, | |
654 | struct queue_properties *properties, | |
655 | unsigned int flags, | |
656 | enum kfd_queue_type type, | |
657 | unsigned int *qid); | |
658 | int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid); | |
659 | int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid, | |
660 | struct queue_properties *p); | |
fbeb661b YS |
661 | struct kernel_queue *pqm_get_kernel_queue(struct process_queue_manager *pqm, |
662 | unsigned int qid); | |
45102048 | 663 | |
788bf83d YS |
664 | int amdkfd_fence_wait_timeout(unsigned int *fence_addr, |
665 | unsigned int fence_value, | |
666 | unsigned long timeout); | |
667 | ||
ed6e6a34 BG |
668 | /* Packet Manager */ |
669 | ||
241f24f8 BG |
670 | #define KFD_HIQ_TIMEOUT (500) |
671 | ||
64c7f8cf BG |
672 | #define KFD_FENCE_COMPLETED (100) |
673 | #define KFD_FENCE_INIT (10) | |
241f24f8 BG |
674 | #define KFD_UNMAP_LATENCY (150) |
675 | ||
ed6e6a34 BG |
676 | struct packet_manager { |
677 | struct device_queue_manager *dqm; | |
678 | struct kernel_queue *priv_queue; | |
679 | struct mutex lock; | |
680 | bool allocated; | |
681 | struct kfd_mem_obj *ib_buffer_obj; | |
682 | }; | |
683 | ||
64c7f8cf BG |
684 | int pm_init(struct packet_manager *pm, struct device_queue_manager *dqm); |
685 | void pm_uninit(struct packet_manager *pm); | |
686 | int pm_send_set_resources(struct packet_manager *pm, | |
687 | struct scheduling_resources *res); | |
688 | int pm_send_runlist(struct packet_manager *pm, struct list_head *dqm_queues); | |
689 | int pm_send_query_status(struct packet_manager *pm, uint64_t fence_address, | |
690 | uint32_t fence_value); | |
691 | ||
692 | int pm_send_unmap_queue(struct packet_manager *pm, enum kfd_queue_type type, | |
693 | enum kfd_preempt_type_filter mode, | |
694 | uint32_t filter_param, bool reset, | |
695 | unsigned int sdma_engine); | |
696 | ||
241f24f8 BG |
697 | void pm_release_ib(struct packet_manager *pm); |
698 | ||
19f6d2a6 | 699 | uint64_t kfd_get_number_elems(struct kfd_dev *kfd); |
19f6d2a6 | 700 | |
f3a39818 AL |
701 | /* Events */ |
702 | extern const struct kfd_event_interrupt_class event_interrupt_class_cik; | |
930c5ff4 | 703 | extern const struct kfd_device_global_init_class device_global_init_class_cik; |
f3a39818 AL |
704 | |
705 | enum kfd_event_wait_result { | |
706 | KFD_WAIT_COMPLETE, | |
707 | KFD_WAIT_TIMEOUT, | |
708 | KFD_WAIT_ERROR | |
709 | }; | |
710 | ||
711 | void kfd_event_init_process(struct kfd_process *p); | |
712 | void kfd_event_free_process(struct kfd_process *p); | |
713 | int kfd_event_mmap(struct kfd_process *process, struct vm_area_struct *vma); | |
714 | int kfd_wait_on_events(struct kfd_process *p, | |
59d3e8be | 715 | uint32_t num_events, void __user *data, |
f3a39818 AL |
716 | bool all, uint32_t user_timeout_ms, |
717 | enum kfd_event_wait_result *wait_result); | |
718 | void kfd_signal_event_interrupt(unsigned int pasid, uint32_t partial_id, | |
719 | uint32_t valid_id_bits); | |
59d3e8be AS |
720 | void kfd_signal_iommu_event(struct kfd_dev *dev, |
721 | unsigned int pasid, unsigned long address, | |
722 | bool is_write_requested, bool is_execute_requested); | |
930c5ff4 | 723 | void kfd_signal_hw_exception_event(unsigned int pasid); |
f3a39818 AL |
724 | int kfd_set_event(struct kfd_process *p, uint32_t event_id); |
725 | int kfd_reset_event(struct kfd_process *p, uint32_t event_id); | |
726 | int kfd_event_create(struct file *devkfd, struct kfd_process *p, | |
727 | uint32_t event_type, bool auto_reset, uint32_t node_id, | |
728 | uint32_t *event_id, uint32_t *event_trigger_data, | |
729 | uint64_t *event_page_offset, uint32_t *event_slot_index); | |
730 | int kfd_event_destroy(struct kfd_process *p, uint32_t event_id); | |
731 | ||
c3447e81 BG |
732 | int dbgdev_wave_reset_wavefronts(struct kfd_dev *dev, struct kfd_process *p); |
733 | ||
4a488a7a | 734 | #endif |