2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 * Authors: Dave Airlie
30 #include <drm/amdgpu_drm.h>
31 #include "amdgpu_uvd.h"
32 #include "amdgpu_vce.h"
35 #include <linux/vga_switcheroo.h>
36 #include <linux/slab.h>
37 #include <linux/uaccess.h>
38 #include <linux/pci.h>
39 #include <linux/pm_runtime.h>
40 #include "amdgpu_amdkfd.h"
41 #include "amdgpu_gem.h"
42 #include "amdgpu_display.h"
43 #include "amdgpu_ras.h"
45 void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev)
47 struct amdgpu_gpu_instance *gpu_instance;
50 mutex_lock(&mgpu_info.mutex);
52 for (i = 0; i < mgpu_info.num_gpu; i++) {
53 gpu_instance = &(mgpu_info.gpu_ins[i]);
54 if (gpu_instance->adev == adev) {
55 mgpu_info.gpu_ins[i] =
56 mgpu_info.gpu_ins[mgpu_info.num_gpu - 1];
58 if (adev->flags & AMD_IS_APU)
66 mutex_unlock(&mgpu_info.mutex);
70 * amdgpu_driver_unload_kms - Main unload function for KMS.
72 * @dev: drm dev pointer
74 * This is the main unload function for KMS (all asics).
75 * Returns 0 on success.
77 void amdgpu_driver_unload_kms(struct drm_device *dev)
79 struct amdgpu_device *adev = drm_to_adev(dev);
84 amdgpu_unregister_gpu_instance(adev);
86 if (adev->rmmio == NULL)
90 pm_runtime_get_sync(dev->dev);
91 pm_runtime_forbid(dev->dev);
94 amdgpu_acpi_fini(adev);
95 amdgpu_device_fini(adev);
98 void amdgpu_register_gpu_instance(struct amdgpu_device *adev)
100 struct amdgpu_gpu_instance *gpu_instance;
102 mutex_lock(&mgpu_info.mutex);
104 if (mgpu_info.num_gpu >= MAX_GPU_INSTANCE) {
105 DRM_ERROR("Cannot register more gpu instance\n");
106 mutex_unlock(&mgpu_info.mutex);
110 gpu_instance = &(mgpu_info.gpu_ins[mgpu_info.num_gpu]);
111 gpu_instance->adev = adev;
112 gpu_instance->mgpu_fan_enabled = 0;
115 if (adev->flags & AMD_IS_APU)
118 mgpu_info.num_dgpu++;
120 mutex_unlock(&mgpu_info.mutex);
124 * amdgpu_driver_load_kms - Main load function for KMS.
126 * @adev: pointer to struct amdgpu_device
127 * @flags: device flags
129 * This is the main load function for KMS (all asics).
130 * Returns 0 on success, error on failure.
132 int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
134 struct drm_device *dev;
135 struct pci_dev *parent;
138 dev = adev_to_drm(adev);
140 if (amdgpu_has_atpx() &&
141 (amdgpu_is_atpx_hybrid() ||
142 amdgpu_has_atpx_dgpu_power_cntl()) &&
143 ((flags & AMD_IS_APU) == 0) &&
144 !pci_is_thunderbolt_attached(to_pci_dev(dev->dev)))
147 parent = pci_upstream_bridge(adev->pdev);
148 adev->has_pr3 = parent ? pci_pr3_present(parent) : false;
150 /* amdgpu_device_init should report only fatal error
151 * like memory allocation failure or iomapping failure,
152 * or memory manager initialization failure, it must
153 * properly initialize the GPU MC controller and permit
156 r = amdgpu_device_init(adev, flags);
158 dev_err(dev->dev, "Fatal error during GPU init\n");
162 if (amdgpu_device_supports_atpx(dev) &&
163 (amdgpu_runtime_pm != 0)) { /* enable runpm by default for atpx */
165 dev_info(adev->dev, "Using ATPX for runtime pm\n");
166 } else if (amdgpu_device_supports_boco(dev) &&
167 (amdgpu_runtime_pm != 0)) { /* enable runpm by default for boco */
169 dev_info(adev->dev, "Using BOCO for runtime pm\n");
170 } else if (amdgpu_device_supports_baco(dev) &&
171 (amdgpu_runtime_pm != 0)) {
172 switch (adev->asic_type) {
175 case CHIP_SIENNA_CICHLID:
176 case CHIP_NAVY_FLOUNDER:
177 /* enable runpm if runpm=1 */
178 if (amdgpu_runtime_pm > 0)
182 /* turn runpm on if noretry=0 */
183 if (!adev->gmc.noretry)
187 /* enable runpm on CI+ */
192 dev_info(adev->dev, "Using BACO for runtime pm\n");
195 /* Call ACPI methods: require modeset init
196 * but failure is not fatal
199 acpi_status = amdgpu_acpi_init(adev);
201 dev_dbg(dev->dev, "Error during ACPI methods call\n");
204 /* only need to skip on ATPX */
205 if (amdgpu_device_supports_atpx(dev) &&
206 !amdgpu_is_atpx_hybrid())
207 dev_pm_set_driver_flags(dev->dev, DPM_FLAG_NO_DIRECT_COMPLETE);
208 pm_runtime_use_autosuspend(dev->dev);
209 pm_runtime_set_autosuspend_delay(dev->dev, 5000);
210 pm_runtime_allow(dev->dev);
211 pm_runtime_mark_last_busy(dev->dev);
212 pm_runtime_put_autosuspend(dev->dev);
217 /* balance pm_runtime_get_sync in amdgpu_driver_unload_kms */
218 if (adev->rmmio && adev->runpm)
219 pm_runtime_put_noidle(dev->dev);
220 amdgpu_driver_unload_kms(dev);
226 static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info,
227 struct drm_amdgpu_query_fw *query_fw,
228 struct amdgpu_device *adev)
230 switch (query_fw->fw_type) {
231 case AMDGPU_INFO_FW_VCE:
232 fw_info->ver = adev->vce.fw_version;
233 fw_info->feature = adev->vce.fb_version;
235 case AMDGPU_INFO_FW_UVD:
236 fw_info->ver = adev->uvd.fw_version;
237 fw_info->feature = 0;
239 case AMDGPU_INFO_FW_VCN:
240 fw_info->ver = adev->vcn.fw_version;
241 fw_info->feature = 0;
243 case AMDGPU_INFO_FW_GMC:
244 fw_info->ver = adev->gmc.fw_version;
245 fw_info->feature = 0;
247 case AMDGPU_INFO_FW_GFX_ME:
248 fw_info->ver = adev->gfx.me_fw_version;
249 fw_info->feature = adev->gfx.me_feature_version;
251 case AMDGPU_INFO_FW_GFX_PFP:
252 fw_info->ver = adev->gfx.pfp_fw_version;
253 fw_info->feature = adev->gfx.pfp_feature_version;
255 case AMDGPU_INFO_FW_GFX_CE:
256 fw_info->ver = adev->gfx.ce_fw_version;
257 fw_info->feature = adev->gfx.ce_feature_version;
259 case AMDGPU_INFO_FW_GFX_RLC:
260 fw_info->ver = adev->gfx.rlc_fw_version;
261 fw_info->feature = adev->gfx.rlc_feature_version;
263 case AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_CNTL:
264 fw_info->ver = adev->gfx.rlc_srlc_fw_version;
265 fw_info->feature = adev->gfx.rlc_srlc_feature_version;
267 case AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_GPM_MEM:
268 fw_info->ver = adev->gfx.rlc_srlg_fw_version;
269 fw_info->feature = adev->gfx.rlc_srlg_feature_version;
271 case AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_SRM_MEM:
272 fw_info->ver = adev->gfx.rlc_srls_fw_version;
273 fw_info->feature = adev->gfx.rlc_srls_feature_version;
275 case AMDGPU_INFO_FW_GFX_MEC:
276 if (query_fw->index == 0) {
277 fw_info->ver = adev->gfx.mec_fw_version;
278 fw_info->feature = adev->gfx.mec_feature_version;
279 } else if (query_fw->index == 1) {
280 fw_info->ver = adev->gfx.mec2_fw_version;
281 fw_info->feature = adev->gfx.mec2_feature_version;
285 case AMDGPU_INFO_FW_SMC:
286 fw_info->ver = adev->pm.fw_version;
287 fw_info->feature = 0;
289 case AMDGPU_INFO_FW_TA:
290 switch (query_fw->index) {
292 fw_info->ver = adev->psp.ta_fw_version;
293 fw_info->feature = adev->psp.ta_xgmi_ucode_version;
296 fw_info->ver = adev->psp.ta_fw_version;
297 fw_info->feature = adev->psp.ta_ras_ucode_version;
300 fw_info->ver = adev->psp.ta_fw_version;
301 fw_info->feature = adev->psp.ta_hdcp_ucode_version;
304 fw_info->ver = adev->psp.ta_fw_version;
305 fw_info->feature = adev->psp.ta_dtm_ucode_version;
311 case AMDGPU_INFO_FW_SDMA:
312 if (query_fw->index >= adev->sdma.num_instances)
314 fw_info->ver = adev->sdma.instance[query_fw->index].fw_version;
315 fw_info->feature = adev->sdma.instance[query_fw->index].feature_version;
317 case AMDGPU_INFO_FW_SOS:
318 fw_info->ver = adev->psp.sos_fw_version;
319 fw_info->feature = adev->psp.sos_feature_version;
321 case AMDGPU_INFO_FW_ASD:
322 fw_info->ver = adev->psp.asd_fw_version;
323 fw_info->feature = adev->psp.asd_feature_version;
325 case AMDGPU_INFO_FW_DMCU:
326 fw_info->ver = adev->dm.dmcu_fw_version;
327 fw_info->feature = 0;
329 case AMDGPU_INFO_FW_DMCUB:
330 fw_info->ver = adev->dm.dmcub_fw_version;
331 fw_info->feature = 0;
333 case AMDGPU_INFO_FW_TOC:
334 fw_info->ver = adev->psp.toc_fw_version;
335 fw_info->feature = adev->psp.toc_feature_version;
343 static int amdgpu_hw_ip_info(struct amdgpu_device *adev,
344 struct drm_amdgpu_info *info,
345 struct drm_amdgpu_info_hw_ip *result)
347 uint32_t ib_start_alignment = 0;
348 uint32_t ib_size_alignment = 0;
349 enum amd_ip_block_type type;
350 unsigned int num_rings = 0;
353 if (info->query_hw_ip.ip_instance >= AMDGPU_HW_IP_INSTANCE_MAX_COUNT)
356 switch (info->query_hw_ip.type) {
357 case AMDGPU_HW_IP_GFX:
358 type = AMD_IP_BLOCK_TYPE_GFX;
359 for (i = 0; i < adev->gfx.num_gfx_rings; i++)
360 if (adev->gfx.gfx_ring[i].sched.ready)
362 ib_start_alignment = 32;
363 ib_size_alignment = 32;
365 case AMDGPU_HW_IP_COMPUTE:
366 type = AMD_IP_BLOCK_TYPE_GFX;
367 for (i = 0; i < adev->gfx.num_compute_rings; i++)
368 if (adev->gfx.compute_ring[i].sched.ready)
370 ib_start_alignment = 32;
371 ib_size_alignment = 32;
373 case AMDGPU_HW_IP_DMA:
374 type = AMD_IP_BLOCK_TYPE_SDMA;
375 for (i = 0; i < adev->sdma.num_instances; i++)
376 if (adev->sdma.instance[i].ring.sched.ready)
378 ib_start_alignment = 256;
379 ib_size_alignment = 4;
381 case AMDGPU_HW_IP_UVD:
382 type = AMD_IP_BLOCK_TYPE_UVD;
383 for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
384 if (adev->uvd.harvest_config & (1 << i))
387 if (adev->uvd.inst[i].ring.sched.ready)
390 ib_start_alignment = 64;
391 ib_size_alignment = 64;
393 case AMDGPU_HW_IP_VCE:
394 type = AMD_IP_BLOCK_TYPE_VCE;
395 for (i = 0; i < adev->vce.num_rings; i++)
396 if (adev->vce.ring[i].sched.ready)
398 ib_start_alignment = 4;
399 ib_size_alignment = 1;
401 case AMDGPU_HW_IP_UVD_ENC:
402 type = AMD_IP_BLOCK_TYPE_UVD;
403 for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
404 if (adev->uvd.harvest_config & (1 << i))
407 for (j = 0; j < adev->uvd.num_enc_rings; j++)
408 if (adev->uvd.inst[i].ring_enc[j].sched.ready)
411 ib_start_alignment = 64;
412 ib_size_alignment = 64;
414 case AMDGPU_HW_IP_VCN_DEC:
415 type = AMD_IP_BLOCK_TYPE_VCN;
416 for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
417 if (adev->uvd.harvest_config & (1 << i))
420 if (adev->vcn.inst[i].ring_dec.sched.ready)
423 ib_start_alignment = 16;
424 ib_size_alignment = 16;
426 case AMDGPU_HW_IP_VCN_ENC:
427 type = AMD_IP_BLOCK_TYPE_VCN;
428 for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
429 if (adev->uvd.harvest_config & (1 << i))
432 for (j = 0; j < adev->vcn.num_enc_rings; j++)
433 if (adev->vcn.inst[i].ring_enc[j].sched.ready)
436 ib_start_alignment = 64;
437 ib_size_alignment = 1;
439 case AMDGPU_HW_IP_VCN_JPEG:
440 type = (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_JPEG)) ?
441 AMD_IP_BLOCK_TYPE_JPEG : AMD_IP_BLOCK_TYPE_VCN;
443 for (i = 0; i < adev->jpeg.num_jpeg_inst; i++) {
444 if (adev->jpeg.harvest_config & (1 << i))
447 if (adev->jpeg.inst[i].ring_dec.sched.ready)
450 ib_start_alignment = 16;
451 ib_size_alignment = 16;
457 for (i = 0; i < adev->num_ip_blocks; i++)
458 if (adev->ip_blocks[i].version->type == type &&
459 adev->ip_blocks[i].status.valid)
462 if (i == adev->num_ip_blocks)
465 num_rings = min(amdgpu_ctx_num_entities[info->query_hw_ip.type],
468 result->hw_ip_version_major = adev->ip_blocks[i].version->major;
469 result->hw_ip_version_minor = adev->ip_blocks[i].version->minor;
470 result->capabilities_flags = 0;
471 result->available_rings = (1 << num_rings) - 1;
472 result->ib_start_alignment = ib_start_alignment;
473 result->ib_size_alignment = ib_size_alignment;
478 * Userspace get information ioctl
481 * amdgpu_info_ioctl - answer a device specific request.
483 * @dev: drm device pointer
484 * @data: request object
487 * This function is used to pass device specific parameters to the userspace
488 * drivers. Examples include: pci device id, pipeline parms, tiling params,
490 * Returns 0 on success, -EINVAL on failure.
492 int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
494 struct amdgpu_device *adev = drm_to_adev(dev);
495 struct drm_amdgpu_info *info = data;
496 struct amdgpu_mode_info *minfo = &adev->mode_info;
497 void __user *out = (void __user *)(uintptr_t)info->return_pointer;
498 uint32_t size = info->return_size;
499 struct drm_crtc *crtc;
503 int ui32_size = sizeof(ui32);
505 if (!info->return_size || !info->return_pointer)
508 switch (info->query) {
509 case AMDGPU_INFO_ACCEL_WORKING:
510 ui32 = adev->accel_working;
511 return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
512 case AMDGPU_INFO_CRTC_FROM_ID:
513 for (i = 0, found = 0; i < adev->mode_info.num_crtc; i++) {
514 crtc = (struct drm_crtc *)minfo->crtcs[i];
515 if (crtc && crtc->base.id == info->mode_crtc.id) {
516 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
517 ui32 = amdgpu_crtc->crtc_id;
523 DRM_DEBUG_KMS("unknown crtc id %d\n", info->mode_crtc.id);
526 return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
527 case AMDGPU_INFO_HW_IP_INFO: {
528 struct drm_amdgpu_info_hw_ip ip = {};
531 ret = amdgpu_hw_ip_info(adev, info, &ip);
535 ret = copy_to_user(out, &ip, min((size_t)size, sizeof(ip)));
536 return ret ? -EFAULT : 0;
538 case AMDGPU_INFO_HW_IP_COUNT: {
539 enum amd_ip_block_type type;
542 switch (info->query_hw_ip.type) {
543 case AMDGPU_HW_IP_GFX:
544 type = AMD_IP_BLOCK_TYPE_GFX;
546 case AMDGPU_HW_IP_COMPUTE:
547 type = AMD_IP_BLOCK_TYPE_GFX;
549 case AMDGPU_HW_IP_DMA:
550 type = AMD_IP_BLOCK_TYPE_SDMA;
552 case AMDGPU_HW_IP_UVD:
553 type = AMD_IP_BLOCK_TYPE_UVD;
555 case AMDGPU_HW_IP_VCE:
556 type = AMD_IP_BLOCK_TYPE_VCE;
558 case AMDGPU_HW_IP_UVD_ENC:
559 type = AMD_IP_BLOCK_TYPE_UVD;
561 case AMDGPU_HW_IP_VCN_DEC:
562 case AMDGPU_HW_IP_VCN_ENC:
563 type = AMD_IP_BLOCK_TYPE_VCN;
565 case AMDGPU_HW_IP_VCN_JPEG:
566 type = (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_JPEG)) ?
567 AMD_IP_BLOCK_TYPE_JPEG : AMD_IP_BLOCK_TYPE_VCN;
573 for (i = 0; i < adev->num_ip_blocks; i++)
574 if (adev->ip_blocks[i].version->type == type &&
575 adev->ip_blocks[i].status.valid &&
576 count < AMDGPU_HW_IP_INSTANCE_MAX_COUNT)
579 return copy_to_user(out, &count, min(size, 4u)) ? -EFAULT : 0;
581 case AMDGPU_INFO_TIMESTAMP:
582 ui64 = amdgpu_gfx_get_gpu_clock_counter(adev);
583 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
584 case AMDGPU_INFO_FW_VERSION: {
585 struct drm_amdgpu_info_firmware fw_info;
588 /* We only support one instance of each IP block right now. */
589 if (info->query_fw.ip_instance != 0)
592 ret = amdgpu_firmware_info(&fw_info, &info->query_fw, adev);
596 return copy_to_user(out, &fw_info,
597 min((size_t)size, sizeof(fw_info))) ? -EFAULT : 0;
599 case AMDGPU_INFO_NUM_BYTES_MOVED:
600 ui64 = atomic64_read(&adev->num_bytes_moved);
601 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
602 case AMDGPU_INFO_NUM_EVICTIONS:
603 ui64 = atomic64_read(&adev->num_evictions);
604 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
605 case AMDGPU_INFO_NUM_VRAM_CPU_PAGE_FAULTS:
606 ui64 = atomic64_read(&adev->num_vram_cpu_page_faults);
607 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
608 case AMDGPU_INFO_VRAM_USAGE:
609 ui64 = amdgpu_vram_mgr_usage(ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM));
610 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
611 case AMDGPU_INFO_VIS_VRAM_USAGE:
612 ui64 = amdgpu_vram_mgr_vis_usage(ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM));
613 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
614 case AMDGPU_INFO_GTT_USAGE:
615 ui64 = amdgpu_gtt_mgr_usage(ttm_manager_type(&adev->mman.bdev, TTM_PL_TT));
616 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
617 case AMDGPU_INFO_GDS_CONFIG: {
618 struct drm_amdgpu_info_gds gds_info;
620 memset(&gds_info, 0, sizeof(gds_info));
621 gds_info.compute_partition_size = adev->gds.gds_size;
622 gds_info.gds_total_size = adev->gds.gds_size;
623 gds_info.gws_per_compute_partition = adev->gds.gws_size;
624 gds_info.oa_per_compute_partition = adev->gds.oa_size;
625 return copy_to_user(out, &gds_info,
626 min((size_t)size, sizeof(gds_info))) ? -EFAULT : 0;
628 case AMDGPU_INFO_VRAM_GTT: {
629 struct drm_amdgpu_info_vram_gtt vram_gtt;
631 vram_gtt.vram_size = adev->gmc.real_vram_size -
632 atomic64_read(&adev->vram_pin_size) -
633 AMDGPU_VM_RESERVED_VRAM;
634 vram_gtt.vram_cpu_accessible_size =
635 min(adev->gmc.visible_vram_size -
636 atomic64_read(&adev->visible_pin_size),
638 vram_gtt.gtt_size = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT)->size;
639 vram_gtt.gtt_size *= PAGE_SIZE;
640 vram_gtt.gtt_size -= atomic64_read(&adev->gart_pin_size);
641 return copy_to_user(out, &vram_gtt,
642 min((size_t)size, sizeof(vram_gtt))) ? -EFAULT : 0;
644 case AMDGPU_INFO_MEMORY: {
645 struct drm_amdgpu_memory_info mem;
646 struct ttm_resource_manager *vram_man =
647 ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
648 struct ttm_resource_manager *gtt_man =
649 ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
650 memset(&mem, 0, sizeof(mem));
651 mem.vram.total_heap_size = adev->gmc.real_vram_size;
652 mem.vram.usable_heap_size = adev->gmc.real_vram_size -
653 atomic64_read(&adev->vram_pin_size) -
654 AMDGPU_VM_RESERVED_VRAM;
655 mem.vram.heap_usage =
656 amdgpu_vram_mgr_usage(vram_man);
657 mem.vram.max_allocation = mem.vram.usable_heap_size * 3 / 4;
659 mem.cpu_accessible_vram.total_heap_size =
660 adev->gmc.visible_vram_size;
661 mem.cpu_accessible_vram.usable_heap_size =
662 min(adev->gmc.visible_vram_size -
663 atomic64_read(&adev->visible_pin_size),
664 mem.vram.usable_heap_size);
665 mem.cpu_accessible_vram.heap_usage =
666 amdgpu_vram_mgr_vis_usage(vram_man);
667 mem.cpu_accessible_vram.max_allocation =
668 mem.cpu_accessible_vram.usable_heap_size * 3 / 4;
670 mem.gtt.total_heap_size = gtt_man->size;
671 mem.gtt.total_heap_size *= PAGE_SIZE;
672 mem.gtt.usable_heap_size = mem.gtt.total_heap_size -
673 atomic64_read(&adev->gart_pin_size);
675 amdgpu_gtt_mgr_usage(gtt_man);
676 mem.gtt.max_allocation = mem.gtt.usable_heap_size * 3 / 4;
678 return copy_to_user(out, &mem,
679 min((size_t)size, sizeof(mem)))
682 case AMDGPU_INFO_READ_MMR_REG: {
683 unsigned n, alloc_size;
685 unsigned se_num = (info->read_mmr_reg.instance >>
686 AMDGPU_INFO_MMR_SE_INDEX_SHIFT) &
687 AMDGPU_INFO_MMR_SE_INDEX_MASK;
688 unsigned sh_num = (info->read_mmr_reg.instance >>
689 AMDGPU_INFO_MMR_SH_INDEX_SHIFT) &
690 AMDGPU_INFO_MMR_SH_INDEX_MASK;
692 /* set full masks if the userspace set all bits
693 * in the bitfields */
694 if (se_num == AMDGPU_INFO_MMR_SE_INDEX_MASK)
696 else if (se_num >= AMDGPU_GFX_MAX_SE)
698 if (sh_num == AMDGPU_INFO_MMR_SH_INDEX_MASK)
700 else if (sh_num >= AMDGPU_GFX_MAX_SH_PER_SE)
703 if (info->read_mmr_reg.count > 128)
706 regs = kmalloc_array(info->read_mmr_reg.count, sizeof(*regs), GFP_KERNEL);
709 alloc_size = info->read_mmr_reg.count * sizeof(*regs);
711 amdgpu_gfx_off_ctrl(adev, false);
712 for (i = 0; i < info->read_mmr_reg.count; i++) {
713 if (amdgpu_asic_read_register(adev, se_num, sh_num,
714 info->read_mmr_reg.dword_offset + i,
716 DRM_DEBUG_KMS("unallowed offset %#x\n",
717 info->read_mmr_reg.dword_offset + i);
719 amdgpu_gfx_off_ctrl(adev, true);
723 amdgpu_gfx_off_ctrl(adev, true);
724 n = copy_to_user(out, regs, min(size, alloc_size));
726 return n ? -EFAULT : 0;
728 case AMDGPU_INFO_DEV_INFO: {
729 struct drm_amdgpu_info_device *dev_info;
733 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
737 dev_info->device_id = adev->pdev->device;
738 dev_info->chip_rev = adev->rev_id;
739 dev_info->external_rev = adev->external_rev_id;
740 dev_info->pci_rev = adev->pdev->revision;
741 dev_info->family = adev->family;
742 dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
743 dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
744 /* return all clocks in KHz */
745 dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
746 if (adev->pm.dpm_enabled) {
747 dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
748 dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
750 dev_info->max_engine_clock = adev->clock.default_sclk * 10;
751 dev_info->max_memory_clock = adev->clock.default_mclk * 10;
753 dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
754 dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
755 adev->gfx.config.max_shader_engines;
756 dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
758 dev_info->ids_flags = 0;
759 if (adev->flags & AMD_IS_APU)
760 dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
761 if (amdgpu_mcbp || amdgpu_sriov_vf(adev))
762 dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
763 if (amdgpu_is_tmz(adev))
764 dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
766 vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
767 vm_size -= AMDGPU_VA_RESERVED_SIZE;
769 /* Older VCE FW versions are buggy and can handle only 40bits */
770 if (adev->vce.fw_version &&
771 adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
772 vm_size = min(vm_size, 1ULL << 40);
774 dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;
775 dev_info->virtual_address_max =
776 min(vm_size, AMDGPU_GMC_HOLE_START);
778 if (vm_size > AMDGPU_GMC_HOLE_START) {
779 dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
780 dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
782 dev_info->virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
783 dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
784 dev_info->gart_page_size = AMDGPU_GPU_PAGE_SIZE;
785 dev_info->cu_active_number = adev->gfx.cu_info.number;
786 dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
787 dev_info->ce_ram_size = adev->gfx.ce_ram_size;
788 memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
789 sizeof(adev->gfx.cu_info.ao_cu_bitmap));
790 memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
791 sizeof(adev->gfx.cu_info.bitmap));
792 dev_info->vram_type = adev->gmc.vram_type;
793 dev_info->vram_bit_width = adev->gmc.vram_width;
794 dev_info->vce_harvest_config = adev->vce.harvest_config;
795 dev_info->gc_double_offchip_lds_buf =
796 adev->gfx.config.double_offchip_lds_buf;
797 dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
798 dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
799 dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
800 dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
801 dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
802 dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
803 dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
805 if (adev->family >= AMDGPU_FAMILY_NV)
806 dev_info->pa_sc_tile_steering_override =
807 adev->gfx.config.pa_sc_tile_steering_override;
809 dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
811 ret = copy_to_user(out, dev_info,
812 min((size_t)size, sizeof(*dev_info))) ? -EFAULT : 0;
816 case AMDGPU_INFO_VCE_CLOCK_TABLE: {
818 struct drm_amdgpu_info_vce_clock_table vce_clk_table = {};
819 struct amd_vce_state *vce_state;
821 for (i = 0; i < AMDGPU_VCE_CLOCK_TABLE_ENTRIES; i++) {
822 vce_state = amdgpu_dpm_get_vce_clock_state(adev, i);
824 vce_clk_table.entries[i].sclk = vce_state->sclk;
825 vce_clk_table.entries[i].mclk = vce_state->mclk;
826 vce_clk_table.entries[i].eclk = vce_state->evclk;
827 vce_clk_table.num_valid_entries++;
831 return copy_to_user(out, &vce_clk_table,
832 min((size_t)size, sizeof(vce_clk_table))) ? -EFAULT : 0;
834 case AMDGPU_INFO_VBIOS: {
835 uint32_t bios_size = adev->bios_size;
837 switch (info->vbios_info.type) {
838 case AMDGPU_INFO_VBIOS_SIZE:
839 return copy_to_user(out, &bios_size,
840 min((size_t)size, sizeof(bios_size)))
842 case AMDGPU_INFO_VBIOS_IMAGE: {
844 uint32_t bios_offset = info->vbios_info.offset;
846 if (bios_offset >= bios_size)
849 bios = adev->bios + bios_offset;
850 return copy_to_user(out, bios,
851 min((size_t)size, (size_t)(bios_size - bios_offset)))
855 DRM_DEBUG_KMS("Invalid request %d\n",
856 info->vbios_info.type);
860 case AMDGPU_INFO_NUM_HANDLES: {
861 struct drm_amdgpu_info_num_handles handle;
863 switch (info->query_hw_ip.type) {
864 case AMDGPU_HW_IP_UVD:
865 /* Starting Polaris, we support unlimited UVD handles */
866 if (adev->asic_type < CHIP_POLARIS10) {
867 handle.uvd_max_handles = adev->uvd.max_handles;
868 handle.uvd_used_handles = amdgpu_uvd_used_handles(adev);
870 return copy_to_user(out, &handle,
871 min((size_t)size, sizeof(handle))) ? -EFAULT : 0;
881 case AMDGPU_INFO_SENSOR: {
882 if (!adev->pm.dpm_enabled)
885 switch (info->sensor_info.type) {
886 case AMDGPU_INFO_SENSOR_GFX_SCLK:
887 /* get sclk in Mhz */
888 if (amdgpu_dpm_read_sensor(adev,
889 AMDGPU_PP_SENSOR_GFX_SCLK,
890 (void *)&ui32, &ui32_size)) {
895 case AMDGPU_INFO_SENSOR_GFX_MCLK:
896 /* get mclk in Mhz */
897 if (amdgpu_dpm_read_sensor(adev,
898 AMDGPU_PP_SENSOR_GFX_MCLK,
899 (void *)&ui32, &ui32_size)) {
904 case AMDGPU_INFO_SENSOR_GPU_TEMP:
905 /* get temperature in millidegrees C */
906 if (amdgpu_dpm_read_sensor(adev,
907 AMDGPU_PP_SENSOR_GPU_TEMP,
908 (void *)&ui32, &ui32_size)) {
912 case AMDGPU_INFO_SENSOR_GPU_LOAD:
914 if (amdgpu_dpm_read_sensor(adev,
915 AMDGPU_PP_SENSOR_GPU_LOAD,
916 (void *)&ui32, &ui32_size)) {
920 case AMDGPU_INFO_SENSOR_GPU_AVG_POWER:
921 /* get average GPU power */
922 if (amdgpu_dpm_read_sensor(adev,
923 AMDGPU_PP_SENSOR_GPU_POWER,
924 (void *)&ui32, &ui32_size)) {
929 case AMDGPU_INFO_SENSOR_VDDNB:
930 /* get VDDNB in millivolts */
931 if (amdgpu_dpm_read_sensor(adev,
932 AMDGPU_PP_SENSOR_VDDNB,
933 (void *)&ui32, &ui32_size)) {
937 case AMDGPU_INFO_SENSOR_VDDGFX:
938 /* get VDDGFX in millivolts */
939 if (amdgpu_dpm_read_sensor(adev,
940 AMDGPU_PP_SENSOR_VDDGFX,
941 (void *)&ui32, &ui32_size)) {
945 case AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_SCLK:
946 /* get stable pstate sclk in Mhz */
947 if (amdgpu_dpm_read_sensor(adev,
948 AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK,
949 (void *)&ui32, &ui32_size)) {
954 case AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_MCLK:
955 /* get stable pstate mclk in Mhz */
956 if (amdgpu_dpm_read_sensor(adev,
957 AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK,
958 (void *)&ui32, &ui32_size)) {
964 DRM_DEBUG_KMS("Invalid request %d\n",
965 info->sensor_info.type);
968 return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
970 case AMDGPU_INFO_VRAM_LOST_COUNTER:
971 ui32 = atomic_read(&adev->vram_lost_counter);
972 return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
973 case AMDGPU_INFO_RAS_ENABLED_FEATURES: {
974 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
979 ras_mask = (uint64_t)ras->supported << 32 | ras->features;
981 return copy_to_user(out, &ras_mask,
982 min_t(u64, size, sizeof(ras_mask))) ?
986 DRM_DEBUG_KMS("Invalid request %d\n", info->query);
994 * Outdated mess for old drm with Xorg being in charge (void function now).
997 * amdgpu_driver_lastclose_kms - drm callback for last close
999 * @dev: drm dev pointer
1001 * Switch vga_switcheroo state after last close (all asics).
1003 void amdgpu_driver_lastclose_kms(struct drm_device *dev)
1005 drm_fb_helper_lastclose(dev);
1006 vga_switcheroo_process_delayed_switch();
1010 * amdgpu_driver_open_kms - drm callback for open
1012 * @dev: drm dev pointer
1013 * @file_priv: drm file
1015 * On device open, init vm on cayman+ (all asics).
1016 * Returns 0 on success, error on failure.
1018 int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
1020 struct amdgpu_device *adev = drm_to_adev(dev);
1021 struct amdgpu_fpriv *fpriv;
1024 /* Ensure IB tests are run on ring */
1025 flush_delayed_work(&adev->delayed_init_work);
1028 if (amdgpu_ras_intr_triggered()) {
1029 DRM_ERROR("RAS Intr triggered, device disabled!!");
1033 file_priv->driver_priv = NULL;
1035 r = pm_runtime_get_sync(dev->dev);
1039 fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
1040 if (unlikely(!fpriv)) {
1045 pasid = amdgpu_pasid_alloc(16);
1047 dev_warn(adev->dev, "No more PASIDs available!");
1050 r = amdgpu_vm_init(adev, &fpriv->vm, AMDGPU_VM_CONTEXT_GFX, pasid);
1054 fpriv->prt_va = amdgpu_vm_bo_add(adev, &fpriv->vm, NULL);
1055 if (!fpriv->prt_va) {
1060 if (amdgpu_mcbp || amdgpu_sriov_vf(adev)) {
1061 uint64_t csa_addr = amdgpu_csa_vaddr(adev) & AMDGPU_GMC_HOLE_MASK;
1063 r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
1064 &fpriv->csa_va, csa_addr, AMDGPU_CSA_SIZE);
1069 mutex_init(&fpriv->bo_list_lock);
1070 idr_init(&fpriv->bo_list_handles);
1072 amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
1074 file_priv->driver_priv = fpriv;
1078 amdgpu_vm_fini(adev, &fpriv->vm);
1082 amdgpu_pasid_free(pasid);
1087 pm_runtime_mark_last_busy(dev->dev);
1089 pm_runtime_put_autosuspend(dev->dev);
1095 * amdgpu_driver_postclose_kms - drm callback for post close
1097 * @dev: drm dev pointer
1098 * @file_priv: drm file
1100 * On device post close, tear down vm on cayman+ (all asics).
1102 void amdgpu_driver_postclose_kms(struct drm_device *dev,
1103 struct drm_file *file_priv)
1105 struct amdgpu_device *adev = drm_to_adev(dev);
1106 struct amdgpu_fpriv *fpriv = file_priv->driver_priv;
1107 struct amdgpu_bo_list *list;
1108 struct amdgpu_bo *pd;
1115 pm_runtime_get_sync(dev->dev);
1117 if (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_UVD) != NULL)
1118 amdgpu_uvd_free_handles(adev, file_priv);
1119 if (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_VCE) != NULL)
1120 amdgpu_vce_free_handles(adev, file_priv);
1122 amdgpu_vm_bo_rmv(adev, fpriv->prt_va);
1124 if (amdgpu_mcbp || amdgpu_sriov_vf(adev)) {
1125 /* TODO: how to handle reserve failure */
1126 BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, true));
1127 amdgpu_vm_bo_rmv(adev, fpriv->csa_va);
1128 fpriv->csa_va = NULL;
1129 amdgpu_bo_unreserve(adev->virt.csa_obj);
1132 pasid = fpriv->vm.pasid;
1133 pd = amdgpu_bo_ref(fpriv->vm.root.base.bo);
1135 amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
1136 amdgpu_vm_fini(adev, &fpriv->vm);
1139 amdgpu_pasid_free_delayed(pd->tbo.base.resv, pasid);
1140 amdgpu_bo_unref(&pd);
1142 idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
1143 amdgpu_bo_list_put(list);
1145 idr_destroy(&fpriv->bo_list_handles);
1146 mutex_destroy(&fpriv->bo_list_lock);
1149 file_priv->driver_priv = NULL;
1151 pm_runtime_mark_last_busy(dev->dev);
1152 pm_runtime_put_autosuspend(dev->dev);
1156 * VBlank related functions.
1159 * amdgpu_get_vblank_counter_kms - get frame count
1161 * @crtc: crtc to get the frame count from
1163 * Gets the frame count on the requested crtc (all asics).
1164 * Returns frame count on success, -EINVAL on failure.
1166 u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc)
1168 struct drm_device *dev = crtc->dev;
1169 unsigned int pipe = crtc->index;
1170 struct amdgpu_device *adev = drm_to_adev(dev);
1171 int vpos, hpos, stat;
1174 if (pipe >= adev->mode_info.num_crtc) {
1175 DRM_ERROR("Invalid crtc %u\n", pipe);
1179 /* The hw increments its frame counter at start of vsync, not at start
1180 * of vblank, as is required by DRM core vblank counter handling.
1181 * Cook the hw count here to make it appear to the caller as if it
1182 * incremented at start of vblank. We measure distance to start of
1183 * vblank in vpos. vpos therefore will be >= 0 between start of vblank
1184 * and start of vsync, so vpos >= 0 means to bump the hw frame counter
1185 * result by 1 to give the proper appearance to caller.
1187 if (adev->mode_info.crtcs[pipe]) {
1188 /* Repeat readout if needed to provide stable result if
1189 * we cross start of vsync during the queries.
1192 count = amdgpu_display_vblank_get_counter(adev, pipe);
1193 /* Ask amdgpu_display_get_crtc_scanoutpos to return
1194 * vpos as distance to start of vblank, instead of
1195 * regular vertical scanout pos.
1197 stat = amdgpu_display_get_crtc_scanoutpos(
1198 dev, pipe, GET_DISTANCE_TO_VBLANKSTART,
1199 &vpos, &hpos, NULL, NULL,
1200 &adev->mode_info.crtcs[pipe]->base.hwmode);
1201 } while (count != amdgpu_display_vblank_get_counter(adev, pipe));
1203 if (((stat & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE)) !=
1204 (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE))) {
1205 DRM_DEBUG_VBL("Query failed! stat %d\n", stat);
1207 DRM_DEBUG_VBL("crtc %d: dist from vblank start %d\n",
1210 /* Bump counter if we are at >= leading edge of vblank,
1211 * but before vsync where vpos would turn negative and
1212 * the hw counter really increments.
1218 /* Fallback to use value as is. */
1219 count = amdgpu_display_vblank_get_counter(adev, pipe);
1220 DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n");
1227 * amdgpu_enable_vblank_kms - enable vblank interrupt
1229 * @crtc: crtc to enable vblank interrupt for
1231 * Enable the interrupt on the requested crtc (all asics).
1232 * Returns 0 on success, -EINVAL on failure.
1234 int amdgpu_enable_vblank_kms(struct drm_crtc *crtc)
1236 struct drm_device *dev = crtc->dev;
1237 unsigned int pipe = crtc->index;
1238 struct amdgpu_device *adev = drm_to_adev(dev);
1239 int idx = amdgpu_display_crtc_idx_to_irq_type(adev, pipe);
1241 return amdgpu_irq_get(adev, &adev->crtc_irq, idx);
1245 * amdgpu_disable_vblank_kms - disable vblank interrupt
1247 * @crtc: crtc to disable vblank interrupt for
1249 * Disable the interrupt on the requested crtc (all asics).
1251 void amdgpu_disable_vblank_kms(struct drm_crtc *crtc)
1253 struct drm_device *dev = crtc->dev;
1254 unsigned int pipe = crtc->index;
1255 struct amdgpu_device *adev = drm_to_adev(dev);
1256 int idx = amdgpu_display_crtc_idx_to_irq_type(adev, pipe);
1258 amdgpu_irq_put(adev, &adev->crtc_irq, idx);
1264 #if defined(CONFIG_DEBUG_FS)
1266 static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
1268 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
1269 struct drm_amdgpu_info_firmware fw_info;
1270 struct drm_amdgpu_query_fw query_fw;
1271 struct atom_context *ctx = adev->mode_info.atom_context;
1275 query_fw.fw_type = AMDGPU_INFO_FW_VCE;
1276 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1279 seq_printf(m, "VCE feature version: %u, firmware version: 0x%08x\n",
1280 fw_info.feature, fw_info.ver);
1283 query_fw.fw_type = AMDGPU_INFO_FW_UVD;
1284 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1287 seq_printf(m, "UVD feature version: %u, firmware version: 0x%08x\n",
1288 fw_info.feature, fw_info.ver);
1291 query_fw.fw_type = AMDGPU_INFO_FW_GMC;
1292 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1295 seq_printf(m, "MC feature version: %u, firmware version: 0x%08x\n",
1296 fw_info.feature, fw_info.ver);
1299 query_fw.fw_type = AMDGPU_INFO_FW_GFX_ME;
1300 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1303 seq_printf(m, "ME feature version: %u, firmware version: 0x%08x\n",
1304 fw_info.feature, fw_info.ver);
1307 query_fw.fw_type = AMDGPU_INFO_FW_GFX_PFP;
1308 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1311 seq_printf(m, "PFP feature version: %u, firmware version: 0x%08x\n",
1312 fw_info.feature, fw_info.ver);
1315 query_fw.fw_type = AMDGPU_INFO_FW_GFX_CE;
1316 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1319 seq_printf(m, "CE feature version: %u, firmware version: 0x%08x\n",
1320 fw_info.feature, fw_info.ver);
1323 query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC;
1324 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1327 seq_printf(m, "RLC feature version: %u, firmware version: 0x%08x\n",
1328 fw_info.feature, fw_info.ver);
1330 /* RLC SAVE RESTORE LIST CNTL */
1331 query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_CNTL;
1332 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1335 seq_printf(m, "RLC SRLC feature version: %u, firmware version: 0x%08x\n",
1336 fw_info.feature, fw_info.ver);
1338 /* RLC SAVE RESTORE LIST GPM MEM */
1339 query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_GPM_MEM;
1340 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1343 seq_printf(m, "RLC SRLG feature version: %u, firmware version: 0x%08x\n",
1344 fw_info.feature, fw_info.ver);
1346 /* RLC SAVE RESTORE LIST SRM MEM */
1347 query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_SRM_MEM;
1348 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1351 seq_printf(m, "RLC SRLS feature version: %u, firmware version: 0x%08x\n",
1352 fw_info.feature, fw_info.ver);
1355 query_fw.fw_type = AMDGPU_INFO_FW_GFX_MEC;
1357 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1360 seq_printf(m, "MEC feature version: %u, firmware version: 0x%08x\n",
1361 fw_info.feature, fw_info.ver);
1364 if (adev->gfx.mec2_fw) {
1366 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1369 seq_printf(m, "MEC2 feature version: %u, firmware version: 0x%08x\n",
1370 fw_info.feature, fw_info.ver);
1374 query_fw.fw_type = AMDGPU_INFO_FW_SOS;
1375 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1378 seq_printf(m, "SOS feature version: %u, firmware version: 0x%08x\n",
1379 fw_info.feature, fw_info.ver);
1383 query_fw.fw_type = AMDGPU_INFO_FW_ASD;
1384 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1387 seq_printf(m, "ASD feature version: %u, firmware version: 0x%08x\n",
1388 fw_info.feature, fw_info.ver);
1390 query_fw.fw_type = AMDGPU_INFO_FW_TA;
1391 for (i = 0; i < 4; i++) {
1393 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1396 switch (query_fw.index) {
1398 seq_printf(m, "TA %s feature version: 0x%08x, firmware version: 0x%08x\n",
1399 "RAS", fw_info.feature, fw_info.ver);
1402 seq_printf(m, "TA %s feature version: 0x%08x, firmware version: 0x%08x\n",
1403 "XGMI", fw_info.feature, fw_info.ver);
1406 seq_printf(m, "TA %s feature version: 0x%08x, firmware version: 0x%08x\n",
1407 "HDCP", fw_info.feature, fw_info.ver);
1410 seq_printf(m, "TA %s feature version: 0x%08x, firmware version: 0x%08x\n",
1411 "DTM", fw_info.feature, fw_info.ver);
1419 query_fw.fw_type = AMDGPU_INFO_FW_SMC;
1420 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1423 seq_printf(m, "SMC feature version: %u, firmware version: 0x%08x\n",
1424 fw_info.feature, fw_info.ver);
1427 query_fw.fw_type = AMDGPU_INFO_FW_SDMA;
1428 for (i = 0; i < adev->sdma.num_instances; i++) {
1430 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1433 seq_printf(m, "SDMA%d feature version: %u, firmware version: 0x%08x\n",
1434 i, fw_info.feature, fw_info.ver);
1438 query_fw.fw_type = AMDGPU_INFO_FW_VCN;
1439 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1442 seq_printf(m, "VCN feature version: %u, firmware version: 0x%08x\n",
1443 fw_info.feature, fw_info.ver);
1446 query_fw.fw_type = AMDGPU_INFO_FW_DMCU;
1447 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1450 seq_printf(m, "DMCU feature version: %u, firmware version: 0x%08x\n",
1451 fw_info.feature, fw_info.ver);
1454 query_fw.fw_type = AMDGPU_INFO_FW_DMCUB;
1455 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1458 seq_printf(m, "DMCUB feature version: %u, firmware version: 0x%08x\n",
1459 fw_info.feature, fw_info.ver);
1462 query_fw.fw_type = AMDGPU_INFO_FW_TOC;
1463 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1466 seq_printf(m, "TOC feature version: %u, firmware version: 0x%08x\n",
1467 fw_info.feature, fw_info.ver);
1469 seq_printf(m, "VBIOS version: %s\n", ctx->vbios_version);
1474 DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_firmware_info);
1478 void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
1480 #if defined(CONFIG_DEBUG_FS)
1481 struct drm_minor *minor = adev_to_drm(adev)->primary;
1482 struct dentry *root = minor->debugfs_root;
1484 debugfs_create_file("amdgpu_firmware_info", 0444, root,
1485 adev, &amdgpu_debugfs_firmware_info_fops);