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_sched.h"
32 #include "amdgpu_uvd.h"
33 #include "amdgpu_vce.h"
36 #include <linux/vga_switcheroo.h>
37 #include <linux/slab.h>
38 #include <linux/pm_runtime.h>
39 #include "amdgpu_amdkfd.h"
40 #include "amdgpu_gem.h"
41 #include "amdgpu_display.h"
44 * amdgpu_driver_unload_kms - Main unload function for KMS.
46 * @dev: drm dev pointer
48 * This is the main unload function for KMS (all asics).
49 * Returns 0 on success.
51 void amdgpu_driver_unload_kms(struct drm_device *dev)
53 struct amdgpu_device *adev = dev->dev_private;
58 if (adev->rmmio == NULL)
61 if (amdgpu_sriov_vf(adev))
62 amdgpu_virt_request_full_gpu(adev, false);
64 if (amdgpu_device_is_px(dev)) {
65 pm_runtime_get_sync(dev->dev);
66 pm_runtime_forbid(dev->dev);
69 amdgpu_acpi_fini(adev);
71 amdgpu_device_fini(adev);
75 dev->dev_private = NULL;
79 * amdgpu_driver_load_kms - Main load function for KMS.
81 * @dev: drm dev pointer
82 * @flags: device flags
84 * This is the main load function for KMS (all asics).
85 * Returns 0 on success, error on failure.
87 int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
89 struct amdgpu_device *adev;
92 #ifdef CONFIG_DRM_AMDGPU_SI
93 if (!amdgpu_si_support) {
94 switch (flags & AMD_ASIC_MASK) {
101 "SI support provided by radeon.\n");
103 "Use radeon.si_support=0 amdgpu.si_support=1 to override.\n"
109 #ifdef CONFIG_DRM_AMDGPU_CIK
110 if (!amdgpu_cik_support) {
111 switch (flags & AMD_ASIC_MASK) {
118 "CIK support provided by radeon.\n");
120 "Use radeon.cik_support=0 amdgpu.cik_support=1 to override.\n"
127 adev = kzalloc(sizeof(struct amdgpu_device), GFP_KERNEL);
131 dev->dev_private = (void *)adev;
133 if ((amdgpu_runtime_pm != 0) &&
135 (amdgpu_is_atpx_hybrid() ||
136 amdgpu_has_atpx_dgpu_power_cntl()) &&
137 ((flags & AMD_IS_APU) == 0) &&
138 !pci_is_thunderbolt_attached(dev->pdev))
141 /* amdgpu_device_init should report only fatal error
142 * like memory allocation failure or iomapping failure,
143 * or memory manager initialization failure, it must
144 * properly initialize the GPU MC controller and permit
147 r = amdgpu_device_init(adev, dev, dev->pdev, flags);
149 dev_err(&dev->pdev->dev, "Fatal error during GPU init\n");
153 /* Call ACPI methods: require modeset init
154 * but failure is not fatal
157 acpi_status = amdgpu_acpi_init(adev);
159 dev_dbg(&dev->pdev->dev,
160 "Error during ACPI methods call\n");
163 if (amdgpu_device_is_px(dev)) {
164 pm_runtime_use_autosuspend(dev->dev);
165 pm_runtime_set_autosuspend_delay(dev->dev, 5000);
166 pm_runtime_set_active(dev->dev);
167 pm_runtime_allow(dev->dev);
168 pm_runtime_mark_last_busy(dev->dev);
169 pm_runtime_put_autosuspend(dev->dev);
174 /* balance pm_runtime_get_sync in amdgpu_driver_unload_kms */
175 if (adev->rmmio && amdgpu_device_is_px(dev))
176 pm_runtime_put_noidle(dev->dev);
177 amdgpu_driver_unload_kms(dev);
183 static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info,
184 struct drm_amdgpu_query_fw *query_fw,
185 struct amdgpu_device *adev)
187 switch (query_fw->fw_type) {
188 case AMDGPU_INFO_FW_VCE:
189 fw_info->ver = adev->vce.fw_version;
190 fw_info->feature = adev->vce.fb_version;
192 case AMDGPU_INFO_FW_UVD:
193 fw_info->ver = adev->uvd.fw_version;
194 fw_info->feature = 0;
196 case AMDGPU_INFO_FW_VCN:
197 fw_info->ver = adev->vcn.fw_version;
198 fw_info->feature = 0;
200 case AMDGPU_INFO_FW_GMC:
201 fw_info->ver = adev->gmc.fw_version;
202 fw_info->feature = 0;
204 case AMDGPU_INFO_FW_GFX_ME:
205 fw_info->ver = adev->gfx.me_fw_version;
206 fw_info->feature = adev->gfx.me_feature_version;
208 case AMDGPU_INFO_FW_GFX_PFP:
209 fw_info->ver = adev->gfx.pfp_fw_version;
210 fw_info->feature = adev->gfx.pfp_feature_version;
212 case AMDGPU_INFO_FW_GFX_CE:
213 fw_info->ver = adev->gfx.ce_fw_version;
214 fw_info->feature = adev->gfx.ce_feature_version;
216 case AMDGPU_INFO_FW_GFX_RLC:
217 fw_info->ver = adev->gfx.rlc_fw_version;
218 fw_info->feature = adev->gfx.rlc_feature_version;
220 case AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_CNTL:
221 fw_info->ver = adev->gfx.rlc_srlc_fw_version;
222 fw_info->feature = adev->gfx.rlc_srlc_feature_version;
224 case AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_GPM_MEM:
225 fw_info->ver = adev->gfx.rlc_srlg_fw_version;
226 fw_info->feature = adev->gfx.rlc_srlg_feature_version;
228 case AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_SRM_MEM:
229 fw_info->ver = adev->gfx.rlc_srls_fw_version;
230 fw_info->feature = adev->gfx.rlc_srls_feature_version;
232 case AMDGPU_INFO_FW_GFX_MEC:
233 if (query_fw->index == 0) {
234 fw_info->ver = adev->gfx.mec_fw_version;
235 fw_info->feature = adev->gfx.mec_feature_version;
236 } else if (query_fw->index == 1) {
237 fw_info->ver = adev->gfx.mec2_fw_version;
238 fw_info->feature = adev->gfx.mec2_feature_version;
242 case AMDGPU_INFO_FW_SMC:
243 fw_info->ver = adev->pm.fw_version;
244 fw_info->feature = 0;
246 case AMDGPU_INFO_FW_SDMA:
247 if (query_fw->index >= adev->sdma.num_instances)
249 fw_info->ver = adev->sdma.instance[query_fw->index].fw_version;
250 fw_info->feature = adev->sdma.instance[query_fw->index].feature_version;
252 case AMDGPU_INFO_FW_SOS:
253 fw_info->ver = adev->psp.sos_fw_version;
254 fw_info->feature = adev->psp.sos_feature_version;
256 case AMDGPU_INFO_FW_ASD:
257 fw_info->ver = adev->psp.asd_fw_version;
258 fw_info->feature = adev->psp.asd_feature_version;
267 * Userspace get information ioctl
270 * amdgpu_info_ioctl - answer a device specific request.
272 * @adev: amdgpu device pointer
273 * @data: request object
276 * This function is used to pass device specific parameters to the userspace
277 * drivers. Examples include: pci device id, pipeline parms, tiling params,
279 * Returns 0 on success, -EINVAL on failure.
281 static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
283 struct amdgpu_device *adev = dev->dev_private;
284 struct drm_amdgpu_info *info = data;
285 struct amdgpu_mode_info *minfo = &adev->mode_info;
286 void __user *out = (void __user *)(uintptr_t)info->return_pointer;
287 uint32_t size = info->return_size;
288 struct drm_crtc *crtc;
292 int ui32_size = sizeof(ui32);
294 if (!info->return_size || !info->return_pointer)
297 /* Ensure IB tests are run on ring */
298 flush_delayed_work(&adev->late_init_work);
300 switch (info->query) {
301 case AMDGPU_INFO_ACCEL_WORKING:
302 ui32 = adev->accel_working;
303 return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
304 case AMDGPU_INFO_CRTC_FROM_ID:
305 for (i = 0, found = 0; i < adev->mode_info.num_crtc; i++) {
306 crtc = (struct drm_crtc *)minfo->crtcs[i];
307 if (crtc && crtc->base.id == info->mode_crtc.id) {
308 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
309 ui32 = amdgpu_crtc->crtc_id;
315 DRM_DEBUG_KMS("unknown crtc id %d\n", info->mode_crtc.id);
318 return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
319 case AMDGPU_INFO_HW_IP_INFO: {
320 struct drm_amdgpu_info_hw_ip ip = {};
321 enum amd_ip_block_type type;
322 uint32_t ring_mask = 0;
323 uint32_t ib_start_alignment = 0;
324 uint32_t ib_size_alignment = 0;
326 if (info->query_hw_ip.ip_instance >= AMDGPU_HW_IP_INSTANCE_MAX_COUNT)
329 switch (info->query_hw_ip.type) {
330 case AMDGPU_HW_IP_GFX:
331 type = AMD_IP_BLOCK_TYPE_GFX;
332 for (i = 0; i < adev->gfx.num_gfx_rings; i++)
333 ring_mask |= adev->gfx.gfx_ring[i].ready << i;
334 ib_start_alignment = 32;
335 ib_size_alignment = 32;
337 case AMDGPU_HW_IP_COMPUTE:
338 type = AMD_IP_BLOCK_TYPE_GFX;
339 for (i = 0; i < adev->gfx.num_compute_rings; i++)
340 ring_mask |= adev->gfx.compute_ring[i].ready << i;
341 ib_start_alignment = 32;
342 ib_size_alignment = 32;
344 case AMDGPU_HW_IP_DMA:
345 type = AMD_IP_BLOCK_TYPE_SDMA;
346 for (i = 0; i < adev->sdma.num_instances; i++)
347 ring_mask |= adev->sdma.instance[i].ring.ready << i;
348 ib_start_alignment = 256;
349 ib_size_alignment = 4;
351 case AMDGPU_HW_IP_UVD:
352 type = AMD_IP_BLOCK_TYPE_UVD;
353 for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
354 if (adev->uvd.harvest_config & (1 << i))
356 ring_mask |= adev->uvd.inst[i].ring.ready;
358 ib_start_alignment = 64;
359 ib_size_alignment = 64;
361 case AMDGPU_HW_IP_VCE:
362 type = AMD_IP_BLOCK_TYPE_VCE;
363 for (i = 0; i < adev->vce.num_rings; i++)
364 ring_mask |= adev->vce.ring[i].ready << i;
365 ib_start_alignment = 4;
366 ib_size_alignment = 1;
368 case AMDGPU_HW_IP_UVD_ENC:
369 type = AMD_IP_BLOCK_TYPE_UVD;
370 for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
371 if (adev->uvd.harvest_config & (1 << i))
373 for (j = 0; j < adev->uvd.num_enc_rings; j++)
374 ring_mask |= adev->uvd.inst[i].ring_enc[j].ready << j;
376 ib_start_alignment = 64;
377 ib_size_alignment = 64;
379 case AMDGPU_HW_IP_VCN_DEC:
380 type = AMD_IP_BLOCK_TYPE_VCN;
381 ring_mask = adev->vcn.ring_dec.ready;
382 ib_start_alignment = 16;
383 ib_size_alignment = 16;
385 case AMDGPU_HW_IP_VCN_ENC:
386 type = AMD_IP_BLOCK_TYPE_VCN;
387 for (i = 0; i < adev->vcn.num_enc_rings; i++)
388 ring_mask |= adev->vcn.ring_enc[i].ready << i;
389 ib_start_alignment = 64;
390 ib_size_alignment = 1;
392 case AMDGPU_HW_IP_VCN_JPEG:
393 type = AMD_IP_BLOCK_TYPE_VCN;
394 ring_mask = adev->vcn.ring_jpeg.ready;
395 ib_start_alignment = 16;
396 ib_size_alignment = 16;
402 for (i = 0; i < adev->num_ip_blocks; i++) {
403 if (adev->ip_blocks[i].version->type == type &&
404 adev->ip_blocks[i].status.valid) {
405 ip.hw_ip_version_major = adev->ip_blocks[i].version->major;
406 ip.hw_ip_version_minor = adev->ip_blocks[i].version->minor;
407 ip.capabilities_flags = 0;
408 ip.available_rings = ring_mask;
409 ip.ib_start_alignment = ib_start_alignment;
410 ip.ib_size_alignment = ib_size_alignment;
414 return copy_to_user(out, &ip,
415 min((size_t)size, sizeof(ip))) ? -EFAULT : 0;
417 case AMDGPU_INFO_HW_IP_COUNT: {
418 enum amd_ip_block_type type;
421 switch (info->query_hw_ip.type) {
422 case AMDGPU_HW_IP_GFX:
423 type = AMD_IP_BLOCK_TYPE_GFX;
425 case AMDGPU_HW_IP_COMPUTE:
426 type = AMD_IP_BLOCK_TYPE_GFX;
428 case AMDGPU_HW_IP_DMA:
429 type = AMD_IP_BLOCK_TYPE_SDMA;
431 case AMDGPU_HW_IP_UVD:
432 type = AMD_IP_BLOCK_TYPE_UVD;
434 case AMDGPU_HW_IP_VCE:
435 type = AMD_IP_BLOCK_TYPE_VCE;
437 case AMDGPU_HW_IP_UVD_ENC:
438 type = AMD_IP_BLOCK_TYPE_UVD;
440 case AMDGPU_HW_IP_VCN_DEC:
441 case AMDGPU_HW_IP_VCN_ENC:
442 case AMDGPU_HW_IP_VCN_JPEG:
443 type = AMD_IP_BLOCK_TYPE_VCN;
449 for (i = 0; i < adev->num_ip_blocks; i++)
450 if (adev->ip_blocks[i].version->type == type &&
451 adev->ip_blocks[i].status.valid &&
452 count < AMDGPU_HW_IP_INSTANCE_MAX_COUNT)
455 return copy_to_user(out, &count, min(size, 4u)) ? -EFAULT : 0;
457 case AMDGPU_INFO_TIMESTAMP:
458 ui64 = amdgpu_gfx_get_gpu_clock_counter(adev);
459 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
460 case AMDGPU_INFO_FW_VERSION: {
461 struct drm_amdgpu_info_firmware fw_info;
464 /* We only support one instance of each IP block right now. */
465 if (info->query_fw.ip_instance != 0)
468 ret = amdgpu_firmware_info(&fw_info, &info->query_fw, adev);
472 return copy_to_user(out, &fw_info,
473 min((size_t)size, sizeof(fw_info))) ? -EFAULT : 0;
475 case AMDGPU_INFO_NUM_BYTES_MOVED:
476 ui64 = atomic64_read(&adev->num_bytes_moved);
477 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
478 case AMDGPU_INFO_NUM_EVICTIONS:
479 ui64 = atomic64_read(&adev->num_evictions);
480 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
481 case AMDGPU_INFO_NUM_VRAM_CPU_PAGE_FAULTS:
482 ui64 = atomic64_read(&adev->num_vram_cpu_page_faults);
483 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
484 case AMDGPU_INFO_VRAM_USAGE:
485 ui64 = amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
486 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
487 case AMDGPU_INFO_VIS_VRAM_USAGE:
488 ui64 = amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
489 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
490 case AMDGPU_INFO_GTT_USAGE:
491 ui64 = amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]);
492 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
493 case AMDGPU_INFO_GDS_CONFIG: {
494 struct drm_amdgpu_info_gds gds_info;
496 memset(&gds_info, 0, sizeof(gds_info));
497 gds_info.gds_gfx_partition_size = adev->gds.mem.gfx_partition_size >> AMDGPU_GDS_SHIFT;
498 gds_info.compute_partition_size = adev->gds.mem.cs_partition_size >> AMDGPU_GDS_SHIFT;
499 gds_info.gds_total_size = adev->gds.mem.total_size >> AMDGPU_GDS_SHIFT;
500 gds_info.gws_per_gfx_partition = adev->gds.gws.gfx_partition_size >> AMDGPU_GWS_SHIFT;
501 gds_info.gws_per_compute_partition = adev->gds.gws.cs_partition_size >> AMDGPU_GWS_SHIFT;
502 gds_info.oa_per_gfx_partition = adev->gds.oa.gfx_partition_size >> AMDGPU_OA_SHIFT;
503 gds_info.oa_per_compute_partition = adev->gds.oa.cs_partition_size >> AMDGPU_OA_SHIFT;
504 return copy_to_user(out, &gds_info,
505 min((size_t)size, sizeof(gds_info))) ? -EFAULT : 0;
507 case AMDGPU_INFO_VRAM_GTT: {
508 struct drm_amdgpu_info_vram_gtt vram_gtt;
510 vram_gtt.vram_size = adev->gmc.real_vram_size -
511 atomic64_read(&adev->vram_pin_size);
512 vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size -
513 atomic64_read(&adev->visible_pin_size);
514 vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT].size;
515 vram_gtt.gtt_size *= PAGE_SIZE;
516 vram_gtt.gtt_size -= atomic64_read(&adev->gart_pin_size);
517 return copy_to_user(out, &vram_gtt,
518 min((size_t)size, sizeof(vram_gtt))) ? -EFAULT : 0;
520 case AMDGPU_INFO_MEMORY: {
521 struct drm_amdgpu_memory_info mem;
523 memset(&mem, 0, sizeof(mem));
524 mem.vram.total_heap_size = adev->gmc.real_vram_size;
525 mem.vram.usable_heap_size = adev->gmc.real_vram_size -
526 atomic64_read(&adev->vram_pin_size);
527 mem.vram.heap_usage =
528 amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
529 mem.vram.max_allocation = mem.vram.usable_heap_size * 3 / 4;
531 mem.cpu_accessible_vram.total_heap_size =
532 adev->gmc.visible_vram_size;
533 mem.cpu_accessible_vram.usable_heap_size = adev->gmc.visible_vram_size -
534 atomic64_read(&adev->visible_pin_size);
535 mem.cpu_accessible_vram.heap_usage =
536 amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
537 mem.cpu_accessible_vram.max_allocation =
538 mem.cpu_accessible_vram.usable_heap_size * 3 / 4;
540 mem.gtt.total_heap_size = adev->mman.bdev.man[TTM_PL_TT].size;
541 mem.gtt.total_heap_size *= PAGE_SIZE;
542 mem.gtt.usable_heap_size = mem.gtt.total_heap_size -
543 atomic64_read(&adev->gart_pin_size);
545 amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]);
546 mem.gtt.max_allocation = mem.gtt.usable_heap_size * 3 / 4;
548 return copy_to_user(out, &mem,
549 min((size_t)size, sizeof(mem)))
552 case AMDGPU_INFO_READ_MMR_REG: {
553 unsigned n, alloc_size;
555 unsigned se_num = (info->read_mmr_reg.instance >>
556 AMDGPU_INFO_MMR_SE_INDEX_SHIFT) &
557 AMDGPU_INFO_MMR_SE_INDEX_MASK;
558 unsigned sh_num = (info->read_mmr_reg.instance >>
559 AMDGPU_INFO_MMR_SH_INDEX_SHIFT) &
560 AMDGPU_INFO_MMR_SH_INDEX_MASK;
562 /* set full masks if the userspace set all bits
563 * in the bitfields */
564 if (se_num == AMDGPU_INFO_MMR_SE_INDEX_MASK)
566 if (sh_num == AMDGPU_INFO_MMR_SH_INDEX_MASK)
569 regs = kmalloc_array(info->read_mmr_reg.count, sizeof(*regs), GFP_KERNEL);
572 alloc_size = info->read_mmr_reg.count * sizeof(*regs);
574 for (i = 0; i < info->read_mmr_reg.count; i++)
575 if (amdgpu_asic_read_register(adev, se_num, sh_num,
576 info->read_mmr_reg.dword_offset + i,
578 DRM_DEBUG_KMS("unallowed offset %#x\n",
579 info->read_mmr_reg.dword_offset + i);
583 n = copy_to_user(out, regs, min(size, alloc_size));
585 return n ? -EFAULT : 0;
587 case AMDGPU_INFO_DEV_INFO: {
588 struct drm_amdgpu_info_device dev_info = {};
591 dev_info.device_id = dev->pdev->device;
592 dev_info.chip_rev = adev->rev_id;
593 dev_info.external_rev = adev->external_rev_id;
594 dev_info.pci_rev = dev->pdev->revision;
595 dev_info.family = adev->family;
596 dev_info.num_shader_engines = adev->gfx.config.max_shader_engines;
597 dev_info.num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
598 /* return all clocks in KHz */
599 dev_info.gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
600 if (adev->pm.dpm_enabled) {
601 dev_info.max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
602 dev_info.max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
604 dev_info.max_engine_clock = adev->clock.default_sclk * 10;
605 dev_info.max_memory_clock = adev->clock.default_mclk * 10;
607 dev_info.enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
608 dev_info.num_rb_pipes = adev->gfx.config.max_backends_per_se *
609 adev->gfx.config.max_shader_engines;
610 dev_info.num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
612 dev_info.ids_flags = 0;
613 if (adev->flags & AMD_IS_APU)
614 dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
615 if (amdgpu_sriov_vf(adev))
616 dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
618 vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
619 vm_size -= AMDGPU_VA_RESERVED_SIZE;
621 /* Older VCE FW versions are buggy and can handle only 40bits */
622 if (adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
623 vm_size = min(vm_size, 1ULL << 40);
625 dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;
626 dev_info.virtual_address_max =
627 min(vm_size, AMDGPU_VA_HOLE_START);
629 if (vm_size > AMDGPU_VA_HOLE_START) {
630 dev_info.high_va_offset = AMDGPU_VA_HOLE_END;
631 dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;
633 dev_info.virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
634 dev_info.pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
635 dev_info.gart_page_size = AMDGPU_GPU_PAGE_SIZE;
636 dev_info.cu_active_number = adev->gfx.cu_info.number;
637 dev_info.cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
638 dev_info.ce_ram_size = adev->gfx.ce_ram_size;
639 memcpy(&dev_info.cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
640 sizeof(adev->gfx.cu_info.ao_cu_bitmap));
641 memcpy(&dev_info.cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
642 sizeof(adev->gfx.cu_info.bitmap));
643 dev_info.vram_type = adev->gmc.vram_type;
644 dev_info.vram_bit_width = adev->gmc.vram_width;
645 dev_info.vce_harvest_config = adev->vce.harvest_config;
646 dev_info.gc_double_offchip_lds_buf =
647 adev->gfx.config.double_offchip_lds_buf;
650 dev_info.prim_buf_gpu_addr = adev->gfx.ngg.buf[NGG_PRIM].gpu_addr;
651 dev_info.prim_buf_size = adev->gfx.ngg.buf[NGG_PRIM].size;
652 dev_info.pos_buf_gpu_addr = adev->gfx.ngg.buf[NGG_POS].gpu_addr;
653 dev_info.pos_buf_size = adev->gfx.ngg.buf[NGG_POS].size;
654 dev_info.cntl_sb_buf_gpu_addr = adev->gfx.ngg.buf[NGG_CNTL].gpu_addr;
655 dev_info.cntl_sb_buf_size = adev->gfx.ngg.buf[NGG_CNTL].size;
656 dev_info.param_buf_gpu_addr = adev->gfx.ngg.buf[NGG_PARAM].gpu_addr;
657 dev_info.param_buf_size = adev->gfx.ngg.buf[NGG_PARAM].size;
659 dev_info.wave_front_size = adev->gfx.cu_info.wave_front_size;
660 dev_info.num_shader_visible_vgprs = adev->gfx.config.max_gprs;
661 dev_info.num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
662 dev_info.num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
663 dev_info.gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
664 dev_info.gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
665 dev_info.max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
667 return copy_to_user(out, &dev_info,
668 min((size_t)size, sizeof(dev_info))) ? -EFAULT : 0;
670 case AMDGPU_INFO_VCE_CLOCK_TABLE: {
672 struct drm_amdgpu_info_vce_clock_table vce_clk_table = {};
673 struct amd_vce_state *vce_state;
675 for (i = 0; i < AMDGPU_VCE_CLOCK_TABLE_ENTRIES; i++) {
676 vce_state = amdgpu_dpm_get_vce_clock_state(adev, i);
678 vce_clk_table.entries[i].sclk = vce_state->sclk;
679 vce_clk_table.entries[i].mclk = vce_state->mclk;
680 vce_clk_table.entries[i].eclk = vce_state->evclk;
681 vce_clk_table.num_valid_entries++;
685 return copy_to_user(out, &vce_clk_table,
686 min((size_t)size, sizeof(vce_clk_table))) ? -EFAULT : 0;
688 case AMDGPU_INFO_VBIOS: {
689 uint32_t bios_size = adev->bios_size;
691 switch (info->vbios_info.type) {
692 case AMDGPU_INFO_VBIOS_SIZE:
693 return copy_to_user(out, &bios_size,
694 min((size_t)size, sizeof(bios_size)))
696 case AMDGPU_INFO_VBIOS_IMAGE: {
698 uint32_t bios_offset = info->vbios_info.offset;
700 if (bios_offset >= bios_size)
703 bios = adev->bios + bios_offset;
704 return copy_to_user(out, bios,
705 min((size_t)size, (size_t)(bios_size - bios_offset)))
709 DRM_DEBUG_KMS("Invalid request %d\n",
710 info->vbios_info.type);
714 case AMDGPU_INFO_NUM_HANDLES: {
715 struct drm_amdgpu_info_num_handles handle;
717 switch (info->query_hw_ip.type) {
718 case AMDGPU_HW_IP_UVD:
719 /* Starting Polaris, we support unlimited UVD handles */
720 if (adev->asic_type < CHIP_POLARIS10) {
721 handle.uvd_max_handles = adev->uvd.max_handles;
722 handle.uvd_used_handles = amdgpu_uvd_used_handles(adev);
724 return copy_to_user(out, &handle,
725 min((size_t)size, sizeof(handle))) ? -EFAULT : 0;
735 case AMDGPU_INFO_SENSOR: {
736 if (!adev->pm.dpm_enabled)
739 switch (info->sensor_info.type) {
740 case AMDGPU_INFO_SENSOR_GFX_SCLK:
741 /* get sclk in Mhz */
742 if (amdgpu_dpm_read_sensor(adev,
743 AMDGPU_PP_SENSOR_GFX_SCLK,
744 (void *)&ui32, &ui32_size)) {
749 case AMDGPU_INFO_SENSOR_GFX_MCLK:
750 /* get mclk in Mhz */
751 if (amdgpu_dpm_read_sensor(adev,
752 AMDGPU_PP_SENSOR_GFX_MCLK,
753 (void *)&ui32, &ui32_size)) {
758 case AMDGPU_INFO_SENSOR_GPU_TEMP:
759 /* get temperature in millidegrees C */
760 if (amdgpu_dpm_read_sensor(adev,
761 AMDGPU_PP_SENSOR_GPU_TEMP,
762 (void *)&ui32, &ui32_size)) {
766 case AMDGPU_INFO_SENSOR_GPU_LOAD:
768 if (amdgpu_dpm_read_sensor(adev,
769 AMDGPU_PP_SENSOR_GPU_LOAD,
770 (void *)&ui32, &ui32_size)) {
774 case AMDGPU_INFO_SENSOR_GPU_AVG_POWER:
775 /* get average GPU power */
776 if (amdgpu_dpm_read_sensor(adev,
777 AMDGPU_PP_SENSOR_GPU_POWER,
778 (void *)&ui32, &ui32_size)) {
783 case AMDGPU_INFO_SENSOR_VDDNB:
784 /* get VDDNB in millivolts */
785 if (amdgpu_dpm_read_sensor(adev,
786 AMDGPU_PP_SENSOR_VDDNB,
787 (void *)&ui32, &ui32_size)) {
791 case AMDGPU_INFO_SENSOR_VDDGFX:
792 /* get VDDGFX in millivolts */
793 if (amdgpu_dpm_read_sensor(adev,
794 AMDGPU_PP_SENSOR_VDDGFX,
795 (void *)&ui32, &ui32_size)) {
799 case AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_SCLK:
800 /* get stable pstate sclk in Mhz */
801 if (amdgpu_dpm_read_sensor(adev,
802 AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK,
803 (void *)&ui32, &ui32_size)) {
808 case AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_MCLK:
809 /* get stable pstate mclk in Mhz */
810 if (amdgpu_dpm_read_sensor(adev,
811 AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK,
812 (void *)&ui32, &ui32_size)) {
818 DRM_DEBUG_KMS("Invalid request %d\n",
819 info->sensor_info.type);
822 return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
824 case AMDGPU_INFO_VRAM_LOST_COUNTER:
825 ui32 = atomic_read(&adev->vram_lost_counter);
826 return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
828 DRM_DEBUG_KMS("Invalid request %d\n", info->query);
836 * Outdated mess for old drm with Xorg being in charge (void function now).
839 * amdgpu_driver_lastclose_kms - drm callback for last close
841 * @dev: drm dev pointer
843 * Switch vga_switcheroo state after last close (all asics).
845 void amdgpu_driver_lastclose_kms(struct drm_device *dev)
847 drm_fb_helper_lastclose(dev);
848 vga_switcheroo_process_delayed_switch();
852 * amdgpu_driver_open_kms - drm callback for open
854 * @dev: drm dev pointer
855 * @file_priv: drm file
857 * On device open, init vm on cayman+ (all asics).
858 * Returns 0 on success, error on failure.
860 int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
862 struct amdgpu_device *adev = dev->dev_private;
863 struct amdgpu_fpriv *fpriv;
866 file_priv->driver_priv = NULL;
868 r = pm_runtime_get_sync(dev->dev);
872 fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
873 if (unlikely(!fpriv)) {
878 pasid = amdgpu_pasid_alloc(16);
880 dev_warn(adev->dev, "No more PASIDs available!");
883 r = amdgpu_vm_init(adev, &fpriv->vm, AMDGPU_VM_CONTEXT_GFX, pasid);
887 fpriv->prt_va = amdgpu_vm_bo_add(adev, &fpriv->vm, NULL);
888 if (!fpriv->prt_va) {
893 if (amdgpu_sriov_vf(adev)) {
894 r = amdgpu_map_static_csa(adev, &fpriv->vm, &fpriv->csa_va);
899 mutex_init(&fpriv->bo_list_lock);
900 idr_init(&fpriv->bo_list_handles);
902 amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
904 file_priv->driver_priv = fpriv;
908 amdgpu_vm_fini(adev, &fpriv->vm);
912 amdgpu_pasid_free(pasid);
917 pm_runtime_mark_last_busy(dev->dev);
918 pm_runtime_put_autosuspend(dev->dev);
924 * amdgpu_driver_postclose_kms - drm callback for post close
926 * @dev: drm dev pointer
927 * @file_priv: drm file
929 * On device post close, tear down vm on cayman+ (all asics).
931 void amdgpu_driver_postclose_kms(struct drm_device *dev,
932 struct drm_file *file_priv)
934 struct amdgpu_device *adev = dev->dev_private;
935 struct amdgpu_fpriv *fpriv = file_priv->driver_priv;
936 struct amdgpu_bo_list *list;
937 struct amdgpu_bo *pd;
944 pm_runtime_get_sync(dev->dev);
946 if (adev->asic_type != CHIP_RAVEN) {
947 amdgpu_uvd_free_handles(adev, file_priv);
948 amdgpu_vce_free_handles(adev, file_priv);
951 amdgpu_vm_bo_rmv(adev, fpriv->prt_va);
953 if (amdgpu_sriov_vf(adev)) {
954 /* TODO: how to handle reserve failure */
955 BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, true));
956 amdgpu_vm_bo_rmv(adev, fpriv->csa_va);
957 fpriv->csa_va = NULL;
958 amdgpu_bo_unreserve(adev->virt.csa_obj);
961 pasid = fpriv->vm.pasid;
962 pd = amdgpu_bo_ref(fpriv->vm.root.base.bo);
964 amdgpu_vm_fini(adev, &fpriv->vm);
965 amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
968 amdgpu_pasid_free_delayed(pd->tbo.resv, pasid);
969 amdgpu_bo_unref(&pd);
971 idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
972 amdgpu_bo_list_put(list);
974 idr_destroy(&fpriv->bo_list_handles);
975 mutex_destroy(&fpriv->bo_list_lock);
978 file_priv->driver_priv = NULL;
980 pm_runtime_mark_last_busy(dev->dev);
981 pm_runtime_put_autosuspend(dev->dev);
985 * VBlank related functions.
988 * amdgpu_get_vblank_counter_kms - get frame count
990 * @dev: drm dev pointer
991 * @pipe: crtc to get the frame count from
993 * Gets the frame count on the requested crtc (all asics).
994 * Returns frame count on success, -EINVAL on failure.
996 u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe)
998 struct amdgpu_device *adev = dev->dev_private;
999 int vpos, hpos, stat;
1002 if (pipe >= adev->mode_info.num_crtc) {
1003 DRM_ERROR("Invalid crtc %u\n", pipe);
1007 /* The hw increments its frame counter at start of vsync, not at start
1008 * of vblank, as is required by DRM core vblank counter handling.
1009 * Cook the hw count here to make it appear to the caller as if it
1010 * incremented at start of vblank. We measure distance to start of
1011 * vblank in vpos. vpos therefore will be >= 0 between start of vblank
1012 * and start of vsync, so vpos >= 0 means to bump the hw frame counter
1013 * result by 1 to give the proper appearance to caller.
1015 if (adev->mode_info.crtcs[pipe]) {
1016 /* Repeat readout if needed to provide stable result if
1017 * we cross start of vsync during the queries.
1020 count = amdgpu_display_vblank_get_counter(adev, pipe);
1021 /* Ask amdgpu_display_get_crtc_scanoutpos to return
1022 * vpos as distance to start of vblank, instead of
1023 * regular vertical scanout pos.
1025 stat = amdgpu_display_get_crtc_scanoutpos(
1026 dev, pipe, GET_DISTANCE_TO_VBLANKSTART,
1027 &vpos, &hpos, NULL, NULL,
1028 &adev->mode_info.crtcs[pipe]->base.hwmode);
1029 } while (count != amdgpu_display_vblank_get_counter(adev, pipe));
1031 if (((stat & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE)) !=
1032 (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE))) {
1033 DRM_DEBUG_VBL("Query failed! stat %d\n", stat);
1035 DRM_DEBUG_VBL("crtc %d: dist from vblank start %d\n",
1038 /* Bump counter if we are at >= leading edge of vblank,
1039 * but before vsync where vpos would turn negative and
1040 * the hw counter really increments.
1046 /* Fallback to use value as is. */
1047 count = amdgpu_display_vblank_get_counter(adev, pipe);
1048 DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n");
1055 * amdgpu_enable_vblank_kms - enable vblank interrupt
1057 * @dev: drm dev pointer
1058 * @pipe: crtc to enable vblank interrupt for
1060 * Enable the interrupt on the requested crtc (all asics).
1061 * Returns 0 on success, -EINVAL on failure.
1063 int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe)
1065 struct amdgpu_device *adev = dev->dev_private;
1066 int idx = amdgpu_display_crtc_idx_to_irq_type(adev, pipe);
1068 return amdgpu_irq_get(adev, &adev->crtc_irq, idx);
1072 * amdgpu_disable_vblank_kms - disable vblank interrupt
1074 * @dev: drm dev pointer
1075 * @pipe: crtc to disable vblank interrupt for
1077 * Disable the interrupt on the requested crtc (all asics).
1079 void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)
1081 struct amdgpu_device *adev = dev->dev_private;
1082 int idx = amdgpu_display_crtc_idx_to_irq_type(adev, pipe);
1084 amdgpu_irq_put(adev, &adev->crtc_irq, idx);
1087 const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
1088 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_CREATE, amdgpu_gem_create_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1089 DRM_IOCTL_DEF_DRV(AMDGPU_CTX, amdgpu_ctx_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1090 DRM_IOCTL_DEF_DRV(AMDGPU_VM, amdgpu_vm_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1091 DRM_IOCTL_DEF_DRV(AMDGPU_SCHED, amdgpu_sched_ioctl, DRM_MASTER),
1092 DRM_IOCTL_DEF_DRV(AMDGPU_BO_LIST, amdgpu_bo_list_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1093 DRM_IOCTL_DEF_DRV(AMDGPU_FENCE_TO_HANDLE, amdgpu_cs_fence_to_handle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1095 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_MMAP, amdgpu_gem_mmap_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1096 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_WAIT_IDLE, amdgpu_gem_wait_idle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1097 DRM_IOCTL_DEF_DRV(AMDGPU_CS, amdgpu_cs_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1098 DRM_IOCTL_DEF_DRV(AMDGPU_INFO, amdgpu_info_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1099 DRM_IOCTL_DEF_DRV(AMDGPU_WAIT_CS, amdgpu_cs_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1100 DRM_IOCTL_DEF_DRV(AMDGPU_WAIT_FENCES, amdgpu_cs_wait_fences_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1101 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_METADATA, amdgpu_gem_metadata_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1102 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_VA, amdgpu_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1103 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
1104 DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW)
1106 const int amdgpu_max_kms_ioctl = ARRAY_SIZE(amdgpu_ioctls_kms);
1111 #if defined(CONFIG_DEBUG_FS)
1113 static int amdgpu_debugfs_firmware_info(struct seq_file *m, void *data)
1115 struct drm_info_node *node = (struct drm_info_node *) m->private;
1116 struct drm_device *dev = node->minor->dev;
1117 struct amdgpu_device *adev = dev->dev_private;
1118 struct drm_amdgpu_info_firmware fw_info;
1119 struct drm_amdgpu_query_fw query_fw;
1120 struct atom_context *ctx = adev->mode_info.atom_context;
1124 query_fw.fw_type = AMDGPU_INFO_FW_VCE;
1125 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1128 seq_printf(m, "VCE feature version: %u, firmware version: 0x%08x\n",
1129 fw_info.feature, fw_info.ver);
1132 query_fw.fw_type = AMDGPU_INFO_FW_UVD;
1133 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1136 seq_printf(m, "UVD feature version: %u, firmware version: 0x%08x\n",
1137 fw_info.feature, fw_info.ver);
1140 query_fw.fw_type = AMDGPU_INFO_FW_GMC;
1141 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1144 seq_printf(m, "MC feature version: %u, firmware version: 0x%08x\n",
1145 fw_info.feature, fw_info.ver);
1148 query_fw.fw_type = AMDGPU_INFO_FW_GFX_ME;
1149 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1152 seq_printf(m, "ME feature version: %u, firmware version: 0x%08x\n",
1153 fw_info.feature, fw_info.ver);
1156 query_fw.fw_type = AMDGPU_INFO_FW_GFX_PFP;
1157 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1160 seq_printf(m, "PFP feature version: %u, firmware version: 0x%08x\n",
1161 fw_info.feature, fw_info.ver);
1164 query_fw.fw_type = AMDGPU_INFO_FW_GFX_CE;
1165 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1168 seq_printf(m, "CE feature version: %u, firmware version: 0x%08x\n",
1169 fw_info.feature, fw_info.ver);
1172 query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC;
1173 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1176 seq_printf(m, "RLC feature version: %u, firmware version: 0x%08x\n",
1177 fw_info.feature, fw_info.ver);
1179 /* RLC SAVE RESTORE LIST CNTL */
1180 query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_CNTL;
1181 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1184 seq_printf(m, "RLC SRLC feature version: %u, firmware version: 0x%08x\n",
1185 fw_info.feature, fw_info.ver);
1187 /* RLC SAVE RESTORE LIST GPM MEM */
1188 query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_GPM_MEM;
1189 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1192 seq_printf(m, "RLC SRLG feature version: %u, firmware version: 0x%08x\n",
1193 fw_info.feature, fw_info.ver);
1195 /* RLC SAVE RESTORE LIST SRM MEM */
1196 query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_SRM_MEM;
1197 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1200 seq_printf(m, "RLC SRLS feature version: %u, firmware version: 0x%08x\n",
1201 fw_info.feature, fw_info.ver);
1204 query_fw.fw_type = AMDGPU_INFO_FW_GFX_MEC;
1206 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1209 seq_printf(m, "MEC feature version: %u, firmware version: 0x%08x\n",
1210 fw_info.feature, fw_info.ver);
1213 if (adev->asic_type == CHIP_KAVERI ||
1214 (adev->asic_type > CHIP_TOPAZ && adev->asic_type != CHIP_STONEY)) {
1216 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1219 seq_printf(m, "MEC2 feature version: %u, firmware version: 0x%08x\n",
1220 fw_info.feature, fw_info.ver);
1224 query_fw.fw_type = AMDGPU_INFO_FW_SOS;
1225 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1228 seq_printf(m, "SOS feature version: %u, firmware version: 0x%08x\n",
1229 fw_info.feature, fw_info.ver);
1233 query_fw.fw_type = AMDGPU_INFO_FW_ASD;
1234 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1237 seq_printf(m, "ASD feature version: %u, firmware version: 0x%08x\n",
1238 fw_info.feature, fw_info.ver);
1241 query_fw.fw_type = AMDGPU_INFO_FW_SMC;
1242 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1245 seq_printf(m, "SMC feature version: %u, firmware version: 0x%08x\n",
1246 fw_info.feature, fw_info.ver);
1249 query_fw.fw_type = AMDGPU_INFO_FW_SDMA;
1250 for (i = 0; i < adev->sdma.num_instances; i++) {
1252 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1255 seq_printf(m, "SDMA%d feature version: %u, firmware version: 0x%08x\n",
1256 i, fw_info.feature, fw_info.ver);
1260 query_fw.fw_type = AMDGPU_INFO_FW_VCN;
1261 ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
1264 seq_printf(m, "VCN feature version: %u, firmware version: 0x%08x\n",
1265 fw_info.feature, fw_info.ver);
1268 seq_printf(m, "VBIOS version: %s\n", ctx->vbios_version);
1273 static const struct drm_info_list amdgpu_firmware_info_list[] = {
1274 {"amdgpu_firmware_info", amdgpu_debugfs_firmware_info, 0, NULL},
1278 int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
1280 #if defined(CONFIG_DEBUG_FS)
1281 return amdgpu_debugfs_add_files(adev, amdgpu_firmware_info_list,
1282 ARRAY_SIZE(amdgpu_firmware_info_list));