2 * Copyright 2014 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #include <linux/bsearch.h>
24 #include <linux/pci.h>
25 #include <linux/slab.h>
27 #include "kfd_device_queue_manager.h"
28 #include "kfd_pm4_headers_vi.h"
29 #include "kfd_pm4_headers_aldebaran.h"
30 #include "cwsr_trap_handler.h"
31 #include "kfd_iommu.h"
32 #include "amdgpu_amdkfd.h"
33 #include "kfd_smi_events.h"
34 #include "kfd_migrate.h"
36 #define MQD_SIZE_ALIGNED 768
39 * kfd_locked is used to lock the kfd driver during suspend or reset
40 * once locked, kfd driver will stop any further GPU execution.
41 * create process (open) will return -EAGAIN.
43 static atomic_t kfd_locked = ATOMIC_INIT(0);
45 #ifdef CONFIG_DRM_AMDGPU_CIK
46 extern const struct kfd2kgd_calls gfx_v7_kfd2kgd;
48 extern const struct kfd2kgd_calls gfx_v8_kfd2kgd;
49 extern const struct kfd2kgd_calls gfx_v9_kfd2kgd;
50 extern const struct kfd2kgd_calls arcturus_kfd2kgd;
51 extern const struct kfd2kgd_calls aldebaran_kfd2kgd;
52 extern const struct kfd2kgd_calls gfx_v10_kfd2kgd;
53 extern const struct kfd2kgd_calls gfx_v10_3_kfd2kgd;
55 static const struct kfd2kgd_calls *kfd2kgd_funcs[] = {
56 #ifdef KFD_SUPPORT_IOMMU_V2
57 #ifdef CONFIG_DRM_AMDGPU_CIK
58 [CHIP_KAVERI] = &gfx_v7_kfd2kgd,
60 [CHIP_CARRIZO] = &gfx_v8_kfd2kgd,
61 [CHIP_RAVEN] = &gfx_v9_kfd2kgd,
63 #ifdef CONFIG_DRM_AMDGPU_CIK
64 [CHIP_HAWAII] = &gfx_v7_kfd2kgd,
66 [CHIP_TONGA] = &gfx_v8_kfd2kgd,
67 [CHIP_FIJI] = &gfx_v8_kfd2kgd,
68 [CHIP_POLARIS10] = &gfx_v8_kfd2kgd,
69 [CHIP_POLARIS11] = &gfx_v8_kfd2kgd,
70 [CHIP_POLARIS12] = &gfx_v8_kfd2kgd,
71 [CHIP_VEGAM] = &gfx_v8_kfd2kgd,
72 [CHIP_VEGA10] = &gfx_v9_kfd2kgd,
73 [CHIP_VEGA12] = &gfx_v9_kfd2kgd,
74 [CHIP_VEGA20] = &gfx_v9_kfd2kgd,
75 [CHIP_RENOIR] = &gfx_v9_kfd2kgd,
76 [CHIP_ARCTURUS] = &arcturus_kfd2kgd,
77 [CHIP_ALDEBARAN] = &aldebaran_kfd2kgd,
78 [CHIP_NAVI10] = &gfx_v10_kfd2kgd,
79 [CHIP_NAVI12] = &gfx_v10_kfd2kgd,
80 [CHIP_NAVI14] = &gfx_v10_kfd2kgd,
81 [CHIP_SIENNA_CICHLID] = &gfx_v10_3_kfd2kgd,
82 [CHIP_NAVY_FLOUNDER] = &gfx_v10_3_kfd2kgd,
83 [CHIP_VANGOGH] = &gfx_v10_3_kfd2kgd,
84 [CHIP_DIMGREY_CAVEFISH] = &gfx_v10_3_kfd2kgd,
87 #ifdef KFD_SUPPORT_IOMMU_V2
88 static const struct kfd_device_info kaveri_device_info = {
89 .asic_family = CHIP_KAVERI,
90 .asic_name = "kaveri",
92 /* max num of queues for KV.TODO should be a dynamic value */
95 .ih_ring_entry_size = 4 * sizeof(uint32_t),
96 .event_interrupt_class = &event_interrupt_class_cik,
97 .num_of_watch_points = 4,
98 .mqd_size_aligned = MQD_SIZE_ALIGNED,
99 .supports_cwsr = false,
100 .needs_iommu_device = true,
101 .needs_pci_atomics = false,
102 .num_sdma_engines = 2,
103 .num_xgmi_sdma_engines = 0,
104 .num_sdma_queues_per_engine = 2,
107 static const struct kfd_device_info carrizo_device_info = {
108 .asic_family = CHIP_CARRIZO,
109 .asic_name = "carrizo",
110 .max_pasid_bits = 16,
111 /* max num of queues for CZ.TODO should be a dynamic value */
114 .ih_ring_entry_size = 4 * sizeof(uint32_t),
115 .event_interrupt_class = &event_interrupt_class_cik,
116 .num_of_watch_points = 4,
117 .mqd_size_aligned = MQD_SIZE_ALIGNED,
118 .supports_cwsr = true,
119 .needs_iommu_device = true,
120 .needs_pci_atomics = false,
121 .num_sdma_engines = 2,
122 .num_xgmi_sdma_engines = 0,
123 .num_sdma_queues_per_engine = 2,
127 static const struct kfd_device_info raven_device_info = {
128 .asic_family = CHIP_RAVEN,
129 .asic_name = "raven",
130 .max_pasid_bits = 16,
133 .ih_ring_entry_size = 8 * sizeof(uint32_t),
134 .event_interrupt_class = &event_interrupt_class_v9,
135 .num_of_watch_points = 4,
136 .mqd_size_aligned = MQD_SIZE_ALIGNED,
137 .supports_cwsr = true,
138 .needs_iommu_device = true,
139 .needs_pci_atomics = true,
140 .num_sdma_engines = 1,
141 .num_xgmi_sdma_engines = 0,
142 .num_sdma_queues_per_engine = 2,
145 static const struct kfd_device_info hawaii_device_info = {
146 .asic_family = CHIP_HAWAII,
147 .asic_name = "hawaii",
148 .max_pasid_bits = 16,
149 /* max num of queues for KV.TODO should be a dynamic value */
152 .ih_ring_entry_size = 4 * sizeof(uint32_t),
153 .event_interrupt_class = &event_interrupt_class_cik,
154 .num_of_watch_points = 4,
155 .mqd_size_aligned = MQD_SIZE_ALIGNED,
156 .supports_cwsr = false,
157 .needs_iommu_device = false,
158 .needs_pci_atomics = false,
159 .num_sdma_engines = 2,
160 .num_xgmi_sdma_engines = 0,
161 .num_sdma_queues_per_engine = 2,
164 static const struct kfd_device_info tonga_device_info = {
165 .asic_family = CHIP_TONGA,
166 .asic_name = "tonga",
167 .max_pasid_bits = 16,
170 .ih_ring_entry_size = 4 * sizeof(uint32_t),
171 .event_interrupt_class = &event_interrupt_class_cik,
172 .num_of_watch_points = 4,
173 .mqd_size_aligned = MQD_SIZE_ALIGNED,
174 .supports_cwsr = false,
175 .needs_iommu_device = false,
176 .needs_pci_atomics = true,
177 .num_sdma_engines = 2,
178 .num_xgmi_sdma_engines = 0,
179 .num_sdma_queues_per_engine = 2,
182 static const struct kfd_device_info fiji_device_info = {
183 .asic_family = CHIP_FIJI,
185 .max_pasid_bits = 16,
188 .ih_ring_entry_size = 4 * sizeof(uint32_t),
189 .event_interrupt_class = &event_interrupt_class_cik,
190 .num_of_watch_points = 4,
191 .mqd_size_aligned = MQD_SIZE_ALIGNED,
192 .supports_cwsr = true,
193 .needs_iommu_device = false,
194 .needs_pci_atomics = true,
195 .num_sdma_engines = 2,
196 .num_xgmi_sdma_engines = 0,
197 .num_sdma_queues_per_engine = 2,
200 static const struct kfd_device_info fiji_vf_device_info = {
201 .asic_family = CHIP_FIJI,
203 .max_pasid_bits = 16,
206 .ih_ring_entry_size = 4 * sizeof(uint32_t),
207 .event_interrupt_class = &event_interrupt_class_cik,
208 .num_of_watch_points = 4,
209 .mqd_size_aligned = MQD_SIZE_ALIGNED,
210 .supports_cwsr = true,
211 .needs_iommu_device = false,
212 .needs_pci_atomics = false,
213 .num_sdma_engines = 2,
214 .num_xgmi_sdma_engines = 0,
215 .num_sdma_queues_per_engine = 2,
219 static const struct kfd_device_info polaris10_device_info = {
220 .asic_family = CHIP_POLARIS10,
221 .asic_name = "polaris10",
222 .max_pasid_bits = 16,
225 .ih_ring_entry_size = 4 * sizeof(uint32_t),
226 .event_interrupt_class = &event_interrupt_class_cik,
227 .num_of_watch_points = 4,
228 .mqd_size_aligned = MQD_SIZE_ALIGNED,
229 .supports_cwsr = true,
230 .needs_iommu_device = false,
231 .needs_pci_atomics = true,
232 .num_sdma_engines = 2,
233 .num_xgmi_sdma_engines = 0,
234 .num_sdma_queues_per_engine = 2,
237 static const struct kfd_device_info polaris10_vf_device_info = {
238 .asic_family = CHIP_POLARIS10,
239 .asic_name = "polaris10",
240 .max_pasid_bits = 16,
243 .ih_ring_entry_size = 4 * sizeof(uint32_t),
244 .event_interrupt_class = &event_interrupt_class_cik,
245 .num_of_watch_points = 4,
246 .mqd_size_aligned = MQD_SIZE_ALIGNED,
247 .supports_cwsr = true,
248 .needs_iommu_device = false,
249 .needs_pci_atomics = false,
250 .num_sdma_engines = 2,
251 .num_xgmi_sdma_engines = 0,
252 .num_sdma_queues_per_engine = 2,
255 static const struct kfd_device_info polaris11_device_info = {
256 .asic_family = CHIP_POLARIS11,
257 .asic_name = "polaris11",
258 .max_pasid_bits = 16,
261 .ih_ring_entry_size = 4 * sizeof(uint32_t),
262 .event_interrupt_class = &event_interrupt_class_cik,
263 .num_of_watch_points = 4,
264 .mqd_size_aligned = MQD_SIZE_ALIGNED,
265 .supports_cwsr = true,
266 .needs_iommu_device = false,
267 .needs_pci_atomics = true,
268 .num_sdma_engines = 2,
269 .num_xgmi_sdma_engines = 0,
270 .num_sdma_queues_per_engine = 2,
273 static const struct kfd_device_info polaris12_device_info = {
274 .asic_family = CHIP_POLARIS12,
275 .asic_name = "polaris12",
276 .max_pasid_bits = 16,
279 .ih_ring_entry_size = 4 * sizeof(uint32_t),
280 .event_interrupt_class = &event_interrupt_class_cik,
281 .num_of_watch_points = 4,
282 .mqd_size_aligned = MQD_SIZE_ALIGNED,
283 .supports_cwsr = true,
284 .needs_iommu_device = false,
285 .needs_pci_atomics = true,
286 .num_sdma_engines = 2,
287 .num_xgmi_sdma_engines = 0,
288 .num_sdma_queues_per_engine = 2,
291 static const struct kfd_device_info vegam_device_info = {
292 .asic_family = CHIP_VEGAM,
293 .asic_name = "vegam",
294 .max_pasid_bits = 16,
297 .ih_ring_entry_size = 4 * sizeof(uint32_t),
298 .event_interrupt_class = &event_interrupt_class_cik,
299 .num_of_watch_points = 4,
300 .mqd_size_aligned = MQD_SIZE_ALIGNED,
301 .supports_cwsr = true,
302 .needs_iommu_device = false,
303 .needs_pci_atomics = true,
304 .num_sdma_engines = 2,
305 .num_xgmi_sdma_engines = 0,
306 .num_sdma_queues_per_engine = 2,
309 static const struct kfd_device_info vega10_device_info = {
310 .asic_family = CHIP_VEGA10,
311 .asic_name = "vega10",
312 .max_pasid_bits = 16,
315 .ih_ring_entry_size = 8 * sizeof(uint32_t),
316 .event_interrupt_class = &event_interrupt_class_v9,
317 .num_of_watch_points = 4,
318 .mqd_size_aligned = MQD_SIZE_ALIGNED,
319 .supports_cwsr = true,
320 .needs_iommu_device = false,
321 .needs_pci_atomics = false,
322 .num_sdma_engines = 2,
323 .num_xgmi_sdma_engines = 0,
324 .num_sdma_queues_per_engine = 2,
327 static const struct kfd_device_info vega10_vf_device_info = {
328 .asic_family = CHIP_VEGA10,
329 .asic_name = "vega10",
330 .max_pasid_bits = 16,
333 .ih_ring_entry_size = 8 * sizeof(uint32_t),
334 .event_interrupt_class = &event_interrupt_class_v9,
335 .num_of_watch_points = 4,
336 .mqd_size_aligned = MQD_SIZE_ALIGNED,
337 .supports_cwsr = true,
338 .needs_iommu_device = false,
339 .needs_pci_atomics = false,
340 .num_sdma_engines = 2,
341 .num_xgmi_sdma_engines = 0,
342 .num_sdma_queues_per_engine = 2,
345 static const struct kfd_device_info vega12_device_info = {
346 .asic_family = CHIP_VEGA12,
347 .asic_name = "vega12",
348 .max_pasid_bits = 16,
351 .ih_ring_entry_size = 8 * sizeof(uint32_t),
352 .event_interrupt_class = &event_interrupt_class_v9,
353 .num_of_watch_points = 4,
354 .mqd_size_aligned = MQD_SIZE_ALIGNED,
355 .supports_cwsr = true,
356 .needs_iommu_device = false,
357 .needs_pci_atomics = false,
358 .num_sdma_engines = 2,
359 .num_xgmi_sdma_engines = 0,
360 .num_sdma_queues_per_engine = 2,
363 static const struct kfd_device_info vega20_device_info = {
364 .asic_family = CHIP_VEGA20,
365 .asic_name = "vega20",
366 .max_pasid_bits = 16,
369 .ih_ring_entry_size = 8 * sizeof(uint32_t),
370 .event_interrupt_class = &event_interrupt_class_v9,
371 .num_of_watch_points = 4,
372 .mqd_size_aligned = MQD_SIZE_ALIGNED,
373 .supports_cwsr = true,
374 .needs_iommu_device = false,
375 .needs_pci_atomics = false,
376 .num_sdma_engines = 2,
377 .num_xgmi_sdma_engines = 0,
378 .num_sdma_queues_per_engine = 8,
381 static const struct kfd_device_info arcturus_device_info = {
382 .asic_family = CHIP_ARCTURUS,
383 .asic_name = "arcturus",
384 .max_pasid_bits = 16,
387 .ih_ring_entry_size = 8 * sizeof(uint32_t),
388 .event_interrupt_class = &event_interrupt_class_v9,
389 .num_of_watch_points = 4,
390 .mqd_size_aligned = MQD_SIZE_ALIGNED,
391 .supports_cwsr = true,
392 .needs_iommu_device = false,
393 .needs_pci_atomics = false,
394 .num_sdma_engines = 2,
395 .num_xgmi_sdma_engines = 6,
396 .num_sdma_queues_per_engine = 8,
399 static const struct kfd_device_info aldebaran_device_info = {
400 .asic_family = CHIP_ALDEBARAN,
401 .asic_name = "aldebaran",
402 .max_pasid_bits = 16,
405 .ih_ring_entry_size = 8 * sizeof(uint32_t),
406 .event_interrupt_class = &event_interrupt_class_v9,
407 .num_of_watch_points = 4,
408 .mqd_size_aligned = MQD_SIZE_ALIGNED,
409 .supports_cwsr = true,
410 .needs_iommu_device = false,
411 .needs_pci_atomics = false,
412 .num_sdma_engines = 2,
413 .num_xgmi_sdma_engines = 3,
414 .num_sdma_queues_per_engine = 8,
417 static const struct kfd_device_info renoir_device_info = {
418 .asic_family = CHIP_RENOIR,
419 .asic_name = "renoir",
420 .max_pasid_bits = 16,
423 .ih_ring_entry_size = 8 * sizeof(uint32_t),
424 .event_interrupt_class = &event_interrupt_class_v9,
425 .num_of_watch_points = 4,
426 .mqd_size_aligned = MQD_SIZE_ALIGNED,
427 .supports_cwsr = true,
428 .needs_iommu_device = false,
429 .needs_pci_atomics = false,
430 .num_sdma_engines = 1,
431 .num_xgmi_sdma_engines = 0,
432 .num_sdma_queues_per_engine = 2,
435 static const struct kfd_device_info navi10_device_info = {
436 .asic_family = CHIP_NAVI10,
437 .asic_name = "navi10",
438 .max_pasid_bits = 16,
441 .ih_ring_entry_size = 8 * sizeof(uint32_t),
442 .event_interrupt_class = &event_interrupt_class_v9,
443 .num_of_watch_points = 4,
444 .mqd_size_aligned = MQD_SIZE_ALIGNED,
445 .needs_iommu_device = false,
446 .supports_cwsr = true,
447 .needs_pci_atomics = true,
448 .num_sdma_engines = 2,
449 .num_xgmi_sdma_engines = 0,
450 .num_sdma_queues_per_engine = 8,
453 static const struct kfd_device_info navi12_device_info = {
454 .asic_family = CHIP_NAVI12,
455 .asic_name = "navi12",
456 .max_pasid_bits = 16,
459 .ih_ring_entry_size = 8 * sizeof(uint32_t),
460 .event_interrupt_class = &event_interrupt_class_v9,
461 .num_of_watch_points = 4,
462 .mqd_size_aligned = MQD_SIZE_ALIGNED,
463 .needs_iommu_device = false,
464 .supports_cwsr = true,
465 .needs_pci_atomics = true,
466 .num_sdma_engines = 2,
467 .num_xgmi_sdma_engines = 0,
468 .num_sdma_queues_per_engine = 8,
471 static const struct kfd_device_info navi14_device_info = {
472 .asic_family = CHIP_NAVI14,
473 .asic_name = "navi14",
474 .max_pasid_bits = 16,
477 .ih_ring_entry_size = 8 * sizeof(uint32_t),
478 .event_interrupt_class = &event_interrupt_class_v9,
479 .num_of_watch_points = 4,
480 .mqd_size_aligned = MQD_SIZE_ALIGNED,
481 .needs_iommu_device = false,
482 .supports_cwsr = true,
483 .needs_pci_atomics = true,
484 .num_sdma_engines = 2,
485 .num_xgmi_sdma_engines = 0,
486 .num_sdma_queues_per_engine = 8,
489 static const struct kfd_device_info sienna_cichlid_device_info = {
490 .asic_family = CHIP_SIENNA_CICHLID,
491 .asic_name = "sienna_cichlid",
492 .max_pasid_bits = 16,
495 .ih_ring_entry_size = 8 * sizeof(uint32_t),
496 .event_interrupt_class = &event_interrupt_class_v9,
497 .num_of_watch_points = 4,
498 .mqd_size_aligned = MQD_SIZE_ALIGNED,
499 .needs_iommu_device = false,
500 .supports_cwsr = true,
501 .needs_pci_atomics = true,
502 .num_sdma_engines = 4,
503 .num_xgmi_sdma_engines = 0,
504 .num_sdma_queues_per_engine = 8,
507 static const struct kfd_device_info navy_flounder_device_info = {
508 .asic_family = CHIP_NAVY_FLOUNDER,
509 .asic_name = "navy_flounder",
510 .max_pasid_bits = 16,
513 .ih_ring_entry_size = 8 * sizeof(uint32_t),
514 .event_interrupt_class = &event_interrupt_class_v9,
515 .num_of_watch_points = 4,
516 .mqd_size_aligned = MQD_SIZE_ALIGNED,
517 .needs_iommu_device = false,
518 .supports_cwsr = true,
519 .needs_pci_atomics = true,
520 .num_sdma_engines = 2,
521 .num_xgmi_sdma_engines = 0,
522 .num_sdma_queues_per_engine = 8,
525 static const struct kfd_device_info vangogh_device_info = {
526 .asic_family = CHIP_VANGOGH,
527 .asic_name = "vangogh",
528 .max_pasid_bits = 16,
531 .ih_ring_entry_size = 8 * sizeof(uint32_t),
532 .event_interrupt_class = &event_interrupt_class_v9,
533 .num_of_watch_points = 4,
534 .mqd_size_aligned = MQD_SIZE_ALIGNED,
535 .needs_iommu_device = false,
536 .supports_cwsr = true,
537 .needs_pci_atomics = false,
538 .num_sdma_engines = 1,
539 .num_xgmi_sdma_engines = 0,
540 .num_sdma_queues_per_engine = 2,
543 static const struct kfd_device_info dimgrey_cavefish_device_info = {
544 .asic_family = CHIP_DIMGREY_CAVEFISH,
545 .asic_name = "dimgrey_cavefish",
546 .max_pasid_bits = 16,
549 .ih_ring_entry_size = 8 * sizeof(uint32_t),
550 .event_interrupt_class = &event_interrupt_class_v9,
551 .num_of_watch_points = 4,
552 .mqd_size_aligned = MQD_SIZE_ALIGNED,
553 .needs_iommu_device = false,
554 .supports_cwsr = true,
555 .needs_pci_atomics = true,
556 .num_sdma_engines = 2,
557 .num_xgmi_sdma_engines = 0,
558 .num_sdma_queues_per_engine = 8,
561 static const struct kfd_device_info beige_goby_device_info = {
562 .asic_family = CHIP_BEIGE_GOBY,
563 .asic_name = "beige_goby",
564 .max_pasid_bits = 16,
567 .ih_ring_entry_size = 8 * sizeof(uint32_t),
568 .event_interrupt_class = &event_interrupt_class_v9,
569 .num_of_watch_points = 4,
570 .mqd_size_aligned = MQD_SIZE_ALIGNED,
571 .needs_iommu_device = false,
572 .supports_cwsr = true,
573 .needs_pci_atomics = true,
574 .num_sdma_engines = 1,
575 .num_xgmi_sdma_engines = 0,
576 .num_sdma_queues_per_engine = 8,
580 /* For each entry, [0] is regular and [1] is virtualisation device. */
581 static const struct kfd_device_info *kfd_supported_devices[][2] = {
582 #ifdef KFD_SUPPORT_IOMMU_V2
583 [CHIP_KAVERI] = {&kaveri_device_info, NULL},
584 [CHIP_CARRIZO] = {&carrizo_device_info, NULL},
586 [CHIP_RAVEN] = {&raven_device_info, NULL},
587 [CHIP_HAWAII] = {&hawaii_device_info, NULL},
588 [CHIP_TONGA] = {&tonga_device_info, NULL},
589 [CHIP_FIJI] = {&fiji_device_info, &fiji_vf_device_info},
590 [CHIP_POLARIS10] = {&polaris10_device_info, &polaris10_vf_device_info},
591 [CHIP_POLARIS11] = {&polaris11_device_info, NULL},
592 [CHIP_POLARIS12] = {&polaris12_device_info, NULL},
593 [CHIP_VEGAM] = {&vegam_device_info, NULL},
594 [CHIP_VEGA10] = {&vega10_device_info, &vega10_vf_device_info},
595 [CHIP_VEGA12] = {&vega12_device_info, NULL},
596 [CHIP_VEGA20] = {&vega20_device_info, NULL},
597 [CHIP_RENOIR] = {&renoir_device_info, NULL},
598 [CHIP_ARCTURUS] = {&arcturus_device_info, &arcturus_device_info},
599 [CHIP_ALDEBARAN] = {&aldebaran_device_info, &aldebaran_device_info},
600 [CHIP_NAVI10] = {&navi10_device_info, NULL},
601 [CHIP_NAVI12] = {&navi12_device_info, &navi12_device_info},
602 [CHIP_NAVI14] = {&navi14_device_info, NULL},
603 [CHIP_SIENNA_CICHLID] = {&sienna_cichlid_device_info, &sienna_cichlid_device_info},
604 [CHIP_NAVY_FLOUNDER] = {&navy_flounder_device_info, &navy_flounder_device_info},
605 [CHIP_VANGOGH] = {&vangogh_device_info, NULL},
606 [CHIP_DIMGREY_CAVEFISH] = {&dimgrey_cavefish_device_info, &dimgrey_cavefish_device_info},
607 [CHIP_BEIGE_GOBY] = {&beige_goby_device_info, &beige_goby_device_info},
610 static int kfd_gtt_sa_init(struct kfd_dev *kfd, unsigned int buf_size,
611 unsigned int chunk_size);
612 static void kfd_gtt_sa_fini(struct kfd_dev *kfd);
614 static int kfd_resume(struct kfd_dev *kfd);
616 struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd,
617 struct pci_dev *pdev, unsigned int asic_type, bool vf)
620 const struct kfd_device_info *device_info;
621 const struct kfd2kgd_calls *f2g;
623 if (asic_type >= sizeof(kfd_supported_devices) / (sizeof(void *) * 2)
624 || asic_type >= sizeof(kfd2kgd_funcs) / sizeof(void *)) {
625 dev_err(kfd_device, "asic_type %d out of range\n", asic_type);
626 return NULL; /* asic_type out of range */
629 device_info = kfd_supported_devices[asic_type][vf];
630 f2g = kfd2kgd_funcs[asic_type];
632 if (!device_info || !f2g) {
633 dev_err(kfd_device, "%s %s not supported in kfd\n",
634 amdgpu_asic_name[asic_type], vf ? "VF" : "");
638 kfd = kzalloc(sizeof(*kfd), GFP_KERNEL);
642 /* Allow BIF to recode atomics to PCIe 3.0 AtomicOps.
643 * 32 and 64-bit requests are possible and must be
646 kfd->pci_atomic_requested = amdgpu_amdkfd_have_atomics_support(kgd);
647 if (device_info->needs_pci_atomics &&
648 !kfd->pci_atomic_requested) {
650 "skipped device %x:%x, PCI rejects atomics\n",
651 pdev->vendor, pdev->device);
657 kfd->device_info = device_info;
659 kfd->init_complete = false;
661 atomic_set(&kfd->compute_profile, 0);
663 mutex_init(&kfd->doorbell_mutex);
664 memset(&kfd->doorbell_available_index, 0,
665 sizeof(kfd->doorbell_available_index));
667 atomic_set(&kfd->sram_ecc_flag, 0);
669 ida_init(&kfd->doorbell_ida);
674 static void kfd_cwsr_init(struct kfd_dev *kfd)
676 if (cwsr_enable && kfd->device_info->supports_cwsr) {
677 if (kfd->device_info->asic_family < CHIP_VEGA10) {
678 BUILD_BUG_ON(sizeof(cwsr_trap_gfx8_hex) > PAGE_SIZE);
679 kfd->cwsr_isa = cwsr_trap_gfx8_hex;
680 kfd->cwsr_isa_size = sizeof(cwsr_trap_gfx8_hex);
681 } else if (kfd->device_info->asic_family == CHIP_ARCTURUS) {
682 BUILD_BUG_ON(sizeof(cwsr_trap_arcturus_hex) > PAGE_SIZE);
683 kfd->cwsr_isa = cwsr_trap_arcturus_hex;
684 kfd->cwsr_isa_size = sizeof(cwsr_trap_arcturus_hex);
685 } else if (kfd->device_info->asic_family == CHIP_ALDEBARAN) {
686 BUILD_BUG_ON(sizeof(cwsr_trap_aldebaran_hex) > PAGE_SIZE);
687 kfd->cwsr_isa = cwsr_trap_aldebaran_hex;
688 kfd->cwsr_isa_size = sizeof(cwsr_trap_aldebaran_hex);
689 } else if (kfd->device_info->asic_family < CHIP_NAVI10) {
690 BUILD_BUG_ON(sizeof(cwsr_trap_gfx9_hex) > PAGE_SIZE);
691 kfd->cwsr_isa = cwsr_trap_gfx9_hex;
692 kfd->cwsr_isa_size = sizeof(cwsr_trap_gfx9_hex);
693 } else if (kfd->device_info->asic_family < CHIP_SIENNA_CICHLID) {
694 BUILD_BUG_ON(sizeof(cwsr_trap_nv1x_hex) > PAGE_SIZE);
695 kfd->cwsr_isa = cwsr_trap_nv1x_hex;
696 kfd->cwsr_isa_size = sizeof(cwsr_trap_nv1x_hex);
698 BUILD_BUG_ON(sizeof(cwsr_trap_gfx10_hex) > PAGE_SIZE);
699 kfd->cwsr_isa = cwsr_trap_gfx10_hex;
700 kfd->cwsr_isa_size = sizeof(cwsr_trap_gfx10_hex);
703 kfd->cwsr_enabled = true;
707 static int kfd_gws_init(struct kfd_dev *kfd)
711 if (kfd->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
715 || (kfd->device_info->asic_family == CHIP_VEGA10
716 && kfd->mec2_fw_version >= 0x81b3)
717 || (kfd->device_info->asic_family >= CHIP_VEGA12
718 && kfd->device_info->asic_family <= CHIP_RAVEN
719 && kfd->mec2_fw_version >= 0x1b3)
720 || (kfd->device_info->asic_family == CHIP_ARCTURUS
721 && kfd->mec2_fw_version >= 0x30)
722 || (kfd->device_info->asic_family == CHIP_ALDEBARAN
723 && kfd->mec2_fw_version >= 0x28))
724 ret = amdgpu_amdkfd_alloc_gws(kfd->kgd,
725 amdgpu_amdkfd_get_num_gws(kfd->kgd), &kfd->gws);
730 static void kfd_smi_init(struct kfd_dev *dev) {
731 INIT_LIST_HEAD(&dev->smi_clients);
732 spin_lock_init(&dev->smi_lock);
735 bool kgd2kfd_device_init(struct kfd_dev *kfd,
736 struct drm_device *ddev,
737 const struct kgd2kfd_shared_resources *gpu_resources)
739 unsigned int size, map_process_packet_size;
742 kfd->mec_fw_version = amdgpu_amdkfd_get_fw_version(kfd->kgd,
744 kfd->mec2_fw_version = amdgpu_amdkfd_get_fw_version(kfd->kgd,
746 kfd->sdma_fw_version = amdgpu_amdkfd_get_fw_version(kfd->kgd,
748 kfd->shared_resources = *gpu_resources;
750 kfd->vm_info.first_vmid_kfd = ffs(gpu_resources->compute_vmid_bitmap)-1;
751 kfd->vm_info.last_vmid_kfd = fls(gpu_resources->compute_vmid_bitmap)-1;
752 kfd->vm_info.vmid_num_kfd = kfd->vm_info.last_vmid_kfd
753 - kfd->vm_info.first_vmid_kfd + 1;
755 /* Verify module parameters regarding mapped process number*/
756 if ((hws_max_conc_proc < 0)
757 || (hws_max_conc_proc > kfd->vm_info.vmid_num_kfd)) {
759 "hws_max_conc_proc %d must be between 0 and %d, use %d instead\n",
760 hws_max_conc_proc, kfd->vm_info.vmid_num_kfd,
761 kfd->vm_info.vmid_num_kfd);
762 kfd->max_proc_per_quantum = kfd->vm_info.vmid_num_kfd;
764 kfd->max_proc_per_quantum = hws_max_conc_proc;
766 /* calculate max size of mqds needed for queues */
767 size = max_num_of_queues_per_device *
768 kfd->device_info->mqd_size_aligned;
771 * calculate max size of runlist packet.
772 * There can be only 2 packets at once
774 map_process_packet_size =
775 kfd->device_info->asic_family == CHIP_ALDEBARAN ?
776 sizeof(struct pm4_mes_map_process_aldebaran) :
777 sizeof(struct pm4_mes_map_process);
778 size += (KFD_MAX_NUM_OF_PROCESSES * map_process_packet_size +
779 max_num_of_queues_per_device * sizeof(struct pm4_mes_map_queues)
780 + sizeof(struct pm4_mes_runlist)) * 2;
782 /* Add size of HIQ & DIQ */
783 size += KFD_KERNEL_QUEUE_SIZE * 2;
785 /* add another 512KB for all other allocations on gart (HPD, fences) */
788 if (amdgpu_amdkfd_alloc_gtt_mem(
789 kfd->kgd, size, &kfd->gtt_mem,
790 &kfd->gtt_start_gpu_addr, &kfd->gtt_start_cpu_ptr,
792 dev_err(kfd_device, "Could not allocate %d bytes\n", size);
793 goto alloc_gtt_mem_failure;
796 dev_info(kfd_device, "Allocated %d bytes on gart\n", size);
798 /* Initialize GTT sa with 512 byte chunk size */
799 if (kfd_gtt_sa_init(kfd, size, 512) != 0) {
800 dev_err(kfd_device, "Error initializing gtt sub-allocator\n");
801 goto kfd_gtt_sa_init_error;
804 if (kfd_doorbell_init(kfd)) {
806 "Error initializing doorbell aperture\n");
807 goto kfd_doorbell_error;
810 kfd->hive_id = amdgpu_amdkfd_get_hive_id(kfd->kgd);
812 kfd->noretry = amdgpu_amdkfd_get_noretry(kfd->kgd);
814 if (kfd_interrupt_init(kfd)) {
815 dev_err(kfd_device, "Error initializing interrupts\n");
816 goto kfd_interrupt_error;
819 kfd->dqm = device_queue_manager_init(kfd);
821 dev_err(kfd_device, "Error initializing queue manager\n");
822 goto device_queue_manager_error;
825 /* If supported on this device, allocate global GWS that is shared
826 * by all KFD processes
828 if (kfd_gws_init(kfd)) {
829 dev_err(kfd_device, "Could not allocate %d gws\n",
830 amdgpu_amdkfd_get_num_gws(kfd->kgd));
834 /* If CRAT is broken, won't set iommu enabled */
835 kfd_double_confirm_iommu_support(kfd);
837 if (kfd_iommu_device_init(kfd)) {
838 dev_err(kfd_device, "Error initializing iommuv2\n");
839 goto device_iommu_error;
844 svm_migrate_init((struct amdgpu_device *)kfd->kgd);
847 goto kfd_resume_error;
851 if (kfd_topology_add_device(kfd)) {
852 dev_err(kfd_device, "Error adding device to topology\n");
853 goto kfd_topology_add_device_error;
858 kfd->init_complete = true;
859 dev_info(kfd_device, "added device %x:%x\n", kfd->pdev->vendor,
862 pr_debug("Starting kfd with the following scheduling policy %d\n",
863 kfd->dqm->sched_policy);
867 kfd_topology_add_device_error:
871 device_queue_manager_uninit(kfd->dqm);
872 device_queue_manager_error:
873 kfd_interrupt_exit(kfd);
875 kfd_doorbell_fini(kfd);
877 kfd_gtt_sa_fini(kfd);
878 kfd_gtt_sa_init_error:
879 amdgpu_amdkfd_free_gtt_mem(kfd->kgd, kfd->gtt_mem);
880 alloc_gtt_mem_failure:
882 amdgpu_amdkfd_free_gws(kfd->kgd, kfd->gws);
884 "device %x:%x NOT added due to errors\n",
885 kfd->pdev->vendor, kfd->pdev->device);
887 return kfd->init_complete;
890 void kgd2kfd_device_exit(struct kfd_dev *kfd)
892 if (kfd->init_complete) {
893 kgd2kfd_suspend(kfd, false);
894 svm_migrate_fini((struct amdgpu_device *)kfd->kgd);
895 device_queue_manager_uninit(kfd->dqm);
896 kfd_interrupt_exit(kfd);
897 kfd_topology_remove_device(kfd);
898 kfd_doorbell_fini(kfd);
899 ida_destroy(&kfd->doorbell_ida);
900 kfd_gtt_sa_fini(kfd);
901 amdgpu_amdkfd_free_gtt_mem(kfd->kgd, kfd->gtt_mem);
903 amdgpu_amdkfd_free_gws(kfd->kgd, kfd->gws);
909 int kgd2kfd_pre_reset(struct kfd_dev *kfd)
911 if (!kfd->init_complete)
914 kfd_smi_event_update_gpu_reset(kfd, false);
916 kfd->dqm->ops.pre_reset(kfd->dqm);
918 kgd2kfd_suspend(kfd, false);
920 kfd_signal_reset_event(kfd);
925 * Fix me. KFD won't be able to resume existing process for now.
926 * We will keep all existing process in a evicted state and
927 * wait the process to be terminated.
930 int kgd2kfd_post_reset(struct kfd_dev *kfd)
934 if (!kfd->init_complete)
937 ret = kfd_resume(kfd);
940 atomic_dec(&kfd_locked);
942 atomic_set(&kfd->sram_ecc_flag, 0);
944 kfd_smi_event_update_gpu_reset(kfd, true);
949 bool kfd_is_locked(void)
951 return (atomic_read(&kfd_locked) > 0);
954 void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
956 if (!kfd->init_complete)
959 /* for runtime suspend, skip locking kfd */
961 /* For first KFD device suspend all the KFD processes */
962 if (atomic_inc_return(&kfd_locked) == 1)
963 kfd_suspend_all_processes();
966 kfd->dqm->ops.stop(kfd->dqm);
967 kfd_iommu_suspend(kfd);
970 int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)
974 if (!kfd->init_complete)
977 ret = kfd_resume(kfd);
981 /* for runtime resume, skip unlocking kfd */
983 count = atomic_dec_return(&kfd_locked);
984 WARN_ONCE(count < 0, "KFD suspend / resume ref. error");
986 ret = kfd_resume_all_processes();
992 static int kfd_resume(struct kfd_dev *kfd)
996 err = kfd_iommu_resume(kfd);
999 "Failed to resume IOMMU for device %x:%x\n",
1000 kfd->pdev->vendor, kfd->pdev->device);
1004 err = kfd->dqm->ops.start(kfd->dqm);
1007 "Error starting queue manager for device %x:%x\n",
1008 kfd->pdev->vendor, kfd->pdev->device);
1009 goto dqm_start_error;
1015 kfd_iommu_suspend(kfd);
1019 static inline void kfd_queue_work(struct workqueue_struct *wq,
1020 struct work_struct *work)
1024 cpu = new_cpu = smp_processor_id();
1026 new_cpu = cpumask_next(new_cpu, cpu_online_mask) % nr_cpu_ids;
1027 if (cpu_to_node(new_cpu) == numa_node_id())
1029 } while (cpu != new_cpu);
1031 queue_work_on(new_cpu, wq, work);
1034 /* This is called directly from KGD at ISR. */
1035 void kgd2kfd_interrupt(struct kfd_dev *kfd, const void *ih_ring_entry)
1037 uint32_t patched_ihre[KFD_MAX_RING_ENTRY_SIZE];
1038 bool is_patched = false;
1039 unsigned long flags;
1041 if (!kfd->init_complete)
1044 if (kfd->device_info->ih_ring_entry_size > sizeof(patched_ihre)) {
1045 dev_err_once(kfd_device, "Ring entry too small\n");
1049 spin_lock_irqsave(&kfd->interrupt_lock, flags);
1051 if (kfd->interrupts_active
1052 && interrupt_is_wanted(kfd, ih_ring_entry,
1053 patched_ihre, &is_patched)
1054 && enqueue_ih_ring_entry(kfd,
1055 is_patched ? patched_ihre : ih_ring_entry))
1056 kfd_queue_work(kfd->ih_wq, &kfd->interrupt_work);
1058 spin_unlock_irqrestore(&kfd->interrupt_lock, flags);
1061 int kgd2kfd_quiesce_mm(struct mm_struct *mm)
1063 struct kfd_process *p;
1066 /* Because we are called from arbitrary context (workqueue) as opposed
1067 * to process context, kfd_process could attempt to exit while we are
1068 * running so the lookup function increments the process ref count.
1070 p = kfd_lookup_process_by_mm(mm);
1074 WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid);
1075 r = kfd_process_evict_queues(p);
1077 kfd_unref_process(p);
1081 int kgd2kfd_resume_mm(struct mm_struct *mm)
1083 struct kfd_process *p;
1086 /* Because we are called from arbitrary context (workqueue) as opposed
1087 * to process context, kfd_process could attempt to exit while we are
1088 * running so the lookup function increments the process ref count.
1090 p = kfd_lookup_process_by_mm(mm);
1094 r = kfd_process_restore_queues(p);
1096 kfd_unref_process(p);
1100 /** kgd2kfd_schedule_evict_and_restore_process - Schedules work queue that will
1101 * prepare for safe eviction of KFD BOs that belong to the specified
1104 * @mm: mm_struct that identifies the specified KFD process
1105 * @fence: eviction fence attached to KFD process BOs
1108 int kgd2kfd_schedule_evict_and_restore_process(struct mm_struct *mm,
1109 struct dma_fence *fence)
1111 struct kfd_process *p;
1112 unsigned long active_time;
1113 unsigned long delay_jiffies = msecs_to_jiffies(PROCESS_ACTIVE_TIME_MS);
1118 if (dma_fence_is_signaled(fence))
1121 p = kfd_lookup_process_by_mm(mm);
1125 if (fence->seqno == p->last_eviction_seqno)
1128 p->last_eviction_seqno = fence->seqno;
1130 /* Avoid KFD process starvation. Wait for at least
1131 * PROCESS_ACTIVE_TIME_MS before evicting the process again
1133 active_time = get_jiffies_64() - p->last_restore_timestamp;
1134 if (delay_jiffies > active_time)
1135 delay_jiffies -= active_time;
1139 /* During process initialization eviction_work.dwork is initialized
1140 * to kfd_evict_bo_worker
1142 WARN(debug_evictions, "Scheduling eviction of pid %d in %ld jiffies",
1143 p->lead_thread->pid, delay_jiffies);
1144 schedule_delayed_work(&p->eviction_work, delay_jiffies);
1146 kfd_unref_process(p);
1150 static int kfd_gtt_sa_init(struct kfd_dev *kfd, unsigned int buf_size,
1151 unsigned int chunk_size)
1153 unsigned int num_of_longs;
1155 if (WARN_ON(buf_size < chunk_size))
1157 if (WARN_ON(buf_size == 0))
1159 if (WARN_ON(chunk_size == 0))
1162 kfd->gtt_sa_chunk_size = chunk_size;
1163 kfd->gtt_sa_num_of_chunks = buf_size / chunk_size;
1165 num_of_longs = (kfd->gtt_sa_num_of_chunks + BITS_PER_LONG - 1) /
1168 kfd->gtt_sa_bitmap = kcalloc(num_of_longs, sizeof(long), GFP_KERNEL);
1170 if (!kfd->gtt_sa_bitmap)
1173 pr_debug("gtt_sa_num_of_chunks = %d, gtt_sa_bitmap = %p\n",
1174 kfd->gtt_sa_num_of_chunks, kfd->gtt_sa_bitmap);
1176 mutex_init(&kfd->gtt_sa_lock);
1182 static void kfd_gtt_sa_fini(struct kfd_dev *kfd)
1184 mutex_destroy(&kfd->gtt_sa_lock);
1185 kfree(kfd->gtt_sa_bitmap);
1188 static inline uint64_t kfd_gtt_sa_calc_gpu_addr(uint64_t start_addr,
1189 unsigned int bit_num,
1190 unsigned int chunk_size)
1192 return start_addr + bit_num * chunk_size;
1195 static inline uint32_t *kfd_gtt_sa_calc_cpu_addr(void *start_addr,
1196 unsigned int bit_num,
1197 unsigned int chunk_size)
1199 return (uint32_t *) ((uint64_t) start_addr + bit_num * chunk_size);
1202 int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size,
1203 struct kfd_mem_obj **mem_obj)
1205 unsigned int found, start_search, cur_size;
1210 if (size > kfd->gtt_sa_num_of_chunks * kfd->gtt_sa_chunk_size)
1213 *mem_obj = kzalloc(sizeof(struct kfd_mem_obj), GFP_KERNEL);
1217 pr_debug("Allocated mem_obj = %p for size = %d\n", *mem_obj, size);
1221 mutex_lock(&kfd->gtt_sa_lock);
1223 kfd_gtt_restart_search:
1224 /* Find the first chunk that is free */
1225 found = find_next_zero_bit(kfd->gtt_sa_bitmap,
1226 kfd->gtt_sa_num_of_chunks,
1229 pr_debug("Found = %d\n", found);
1231 /* If there wasn't any free chunk, bail out */
1232 if (found == kfd->gtt_sa_num_of_chunks)
1233 goto kfd_gtt_no_free_chunk;
1235 /* Update fields of mem_obj */
1236 (*mem_obj)->range_start = found;
1237 (*mem_obj)->range_end = found;
1238 (*mem_obj)->gpu_addr = kfd_gtt_sa_calc_gpu_addr(
1239 kfd->gtt_start_gpu_addr,
1241 kfd->gtt_sa_chunk_size);
1242 (*mem_obj)->cpu_ptr = kfd_gtt_sa_calc_cpu_addr(
1243 kfd->gtt_start_cpu_ptr,
1245 kfd->gtt_sa_chunk_size);
1247 pr_debug("gpu_addr = %p, cpu_addr = %p\n",
1248 (uint64_t *) (*mem_obj)->gpu_addr, (*mem_obj)->cpu_ptr);
1250 /* If we need only one chunk, mark it as allocated and get out */
1251 if (size <= kfd->gtt_sa_chunk_size) {
1252 pr_debug("Single bit\n");
1253 set_bit(found, kfd->gtt_sa_bitmap);
1257 /* Otherwise, try to see if we have enough contiguous chunks */
1258 cur_size = size - kfd->gtt_sa_chunk_size;
1260 (*mem_obj)->range_end =
1261 find_next_zero_bit(kfd->gtt_sa_bitmap,
1262 kfd->gtt_sa_num_of_chunks, ++found);
1264 * If next free chunk is not contiguous than we need to
1265 * restart our search from the last free chunk we found (which
1266 * wasn't contiguous to the previous ones
1268 if ((*mem_obj)->range_end != found) {
1269 start_search = found;
1270 goto kfd_gtt_restart_search;
1274 * If we reached end of buffer, bail out with error
1276 if (found == kfd->gtt_sa_num_of_chunks)
1277 goto kfd_gtt_no_free_chunk;
1279 /* Check if we don't need another chunk */
1280 if (cur_size <= kfd->gtt_sa_chunk_size)
1283 cur_size -= kfd->gtt_sa_chunk_size;
1285 } while (cur_size > 0);
1287 pr_debug("range_start = %d, range_end = %d\n",
1288 (*mem_obj)->range_start, (*mem_obj)->range_end);
1290 /* Mark the chunks as allocated */
1291 for (found = (*mem_obj)->range_start;
1292 found <= (*mem_obj)->range_end;
1294 set_bit(found, kfd->gtt_sa_bitmap);
1297 mutex_unlock(&kfd->gtt_sa_lock);
1300 kfd_gtt_no_free_chunk:
1301 pr_debug("Allocation failed with mem_obj = %p\n", *mem_obj);
1302 mutex_unlock(&kfd->gtt_sa_lock);
1307 int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj)
1311 /* Act like kfree when trying to free a NULL object */
1315 pr_debug("Free mem_obj = %p, range_start = %d, range_end = %d\n",
1316 mem_obj, mem_obj->range_start, mem_obj->range_end);
1318 mutex_lock(&kfd->gtt_sa_lock);
1320 /* Mark the chunks as free */
1321 for (bit = mem_obj->range_start;
1322 bit <= mem_obj->range_end;
1324 clear_bit(bit, kfd->gtt_sa_bitmap);
1326 mutex_unlock(&kfd->gtt_sa_lock);
1332 void kgd2kfd_set_sram_ecc_flag(struct kfd_dev *kfd)
1335 atomic_inc(&kfd->sram_ecc_flag);
1338 void kfd_inc_compute_active(struct kfd_dev *kfd)
1340 if (atomic_inc_return(&kfd->compute_profile) == 1)
1341 amdgpu_amdkfd_set_compute_idle(kfd->kgd, false);
1344 void kfd_dec_compute_active(struct kfd_dev *kfd)
1346 int count = atomic_dec_return(&kfd->compute_profile);
1349 amdgpu_amdkfd_set_compute_idle(kfd->kgd, true);
1350 WARN_ONCE(count < 0, "Compute profile ref. count error");
1353 void kgd2kfd_smi_event_throttle(struct kfd_dev *kfd, uint32_t throttle_bitmask)
1355 if (kfd && kfd->init_complete)
1356 kfd_smi_event_update_thermal_throttling(kfd, throttle_bitmask);
1359 #if defined(CONFIG_DEBUG_FS)
1361 /* This function will send a package to HIQ to hang the HWS
1362 * which will trigger a GPU reset and bring the HWS back to normal state
1364 int kfd_debugfs_hang_hws(struct kfd_dev *dev)
1368 if (dev->dqm->sched_policy != KFD_SCHED_POLICY_HWS) {
1369 pr_err("HWS is not enabled");
1373 r = pm_debugfs_hang_hws(&dev->dqm->packets);
1375 r = dqm_debugfs_execute_queues(dev->dqm);