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
28 #include <linux/kthread.h>
29 #include <linux/console.h>
30 #include <linux/slab.h>
31 #include <linux/debugfs.h>
33 #include <drm/drm_crtc_helper.h>
34 #include <drm/drm_atomic_helper.h>
35 #include <drm/amdgpu_drm.h>
36 #include <linux/vgaarb.h>
37 #include <linux/vga_switcheroo.h>
38 #include <linux/efi.h>
40 #include "amdgpu_trace.h"
41 #include "amdgpu_i2c.h"
43 #include "amdgpu_atombios.h"
44 #include "amdgpu_atomfirmware.h"
46 #ifdef CONFIG_DRM_AMDGPU_SI
49 #ifdef CONFIG_DRM_AMDGPU_CIK
54 #include "bif/bif_4_1_d.h"
55 #include <linux/pci.h>
56 #include <linux/firmware.h>
57 #include "amdgpu_vf_error.h"
59 #include "amdgpu_amdkfd.h"
60 #include "amdgpu_pm.h"
62 MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin");
63 MODULE_FIRMWARE("amdgpu/raven_gpu_info.bin");
65 #define AMDGPU_RESUME_MS 2000
67 static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev);
68 static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev);
69 static int amdgpu_debugfs_test_ib_ring_init(struct amdgpu_device *adev);
70 static int amdgpu_debugfs_vbios_dump_init(struct amdgpu_device *adev);
72 static const char *amdgpu_asic_name[] = {
96 bool amdgpu_device_is_px(struct drm_device *dev)
98 struct amdgpu_device *adev = dev->dev_private;
100 if (adev->flags & AMD_IS_PX)
106 * MMIO register access helper functions.
108 uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
113 if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
114 return amdgpu_virt_kiq_rreg(adev, reg);
116 if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
117 ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
121 spin_lock_irqsave(&adev->mmio_idx_lock, flags);
122 writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
123 ret = readl(((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
124 spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
126 trace_amdgpu_mm_rreg(adev->pdev->device, reg, ret);
130 void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
133 trace_amdgpu_mm_wreg(adev->pdev->device, reg, v);
135 if (adev->asic_type >= CHIP_VEGA10 && reg == 0) {
136 adev->last_mm_index = v;
139 if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
140 return amdgpu_virt_kiq_wreg(adev, reg, v);
142 if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
143 writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
147 spin_lock_irqsave(&adev->mmio_idx_lock, flags);
148 writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
149 writel(v, ((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
150 spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
153 if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) {
158 u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg)
160 if ((reg * 4) < adev->rio_mem_size)
161 return ioread32(adev->rio_mem + (reg * 4));
163 iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
164 return ioread32(adev->rio_mem + (mmMM_DATA * 4));
168 void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
170 if (adev->asic_type >= CHIP_VEGA10 && reg == 0) {
171 adev->last_mm_index = v;
174 if ((reg * 4) < adev->rio_mem_size)
175 iowrite32(v, adev->rio_mem + (reg * 4));
177 iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
178 iowrite32(v, adev->rio_mem + (mmMM_DATA * 4));
181 if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) {
187 * amdgpu_mm_rdoorbell - read a doorbell dword
189 * @adev: amdgpu_device pointer
190 * @index: doorbell index
192 * Returns the value in the doorbell aperture at the
193 * requested doorbell index (CIK).
195 u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index)
197 if (index < adev->doorbell.num_doorbells) {
198 return readl(adev->doorbell.ptr + index);
200 DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
206 * amdgpu_mm_wdoorbell - write a doorbell dword
208 * @adev: amdgpu_device pointer
209 * @index: doorbell index
212 * Writes @v to the doorbell aperture at the
213 * requested doorbell index (CIK).
215 void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v)
217 if (index < adev->doorbell.num_doorbells) {
218 writel(v, adev->doorbell.ptr + index);
220 DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
225 * amdgpu_mm_rdoorbell64 - read a doorbell Qword
227 * @adev: amdgpu_device pointer
228 * @index: doorbell index
230 * Returns the value in the doorbell aperture at the
231 * requested doorbell index (VEGA10+).
233 u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index)
235 if (index < adev->doorbell.num_doorbells) {
236 return atomic64_read((atomic64_t *)(adev->doorbell.ptr + index));
238 DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
244 * amdgpu_mm_wdoorbell64 - write a doorbell Qword
246 * @adev: amdgpu_device pointer
247 * @index: doorbell index
250 * Writes @v to the doorbell aperture at the
251 * requested doorbell index (VEGA10+).
253 void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v)
255 if (index < adev->doorbell.num_doorbells) {
256 atomic64_set((atomic64_t *)(adev->doorbell.ptr + index), v);
258 DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
263 * amdgpu_invalid_rreg - dummy reg read function
265 * @adev: amdgpu device pointer
266 * @reg: offset of register
268 * Dummy register read function. Used for register blocks
269 * that certain asics don't have (all asics).
270 * Returns the value in the register.
272 static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg)
274 DRM_ERROR("Invalid callback to read register 0x%04X\n", reg);
280 * amdgpu_invalid_wreg - dummy reg write function
282 * @adev: amdgpu device pointer
283 * @reg: offset of register
284 * @v: value to write to the register
286 * Dummy register read function. Used for register blocks
287 * that certain asics don't have (all asics).
289 static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
291 DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n",
297 * amdgpu_block_invalid_rreg - dummy reg read function
299 * @adev: amdgpu device pointer
300 * @block: offset of instance
301 * @reg: offset of register
303 * Dummy register read function. Used for register blocks
304 * that certain asics don't have (all asics).
305 * Returns the value in the register.
307 static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev,
308 uint32_t block, uint32_t reg)
310 DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n",
317 * amdgpu_block_invalid_wreg - dummy reg write function
319 * @adev: amdgpu device pointer
320 * @block: offset of instance
321 * @reg: offset of register
322 * @v: value to write to the register
324 * Dummy register read function. Used for register blocks
325 * that certain asics don't have (all asics).
327 static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev,
329 uint32_t reg, uint32_t v)
331 DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n",
336 static int amdgpu_vram_scratch_init(struct amdgpu_device *adev)
338 return amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE,
339 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
340 &adev->vram_scratch.robj,
341 &adev->vram_scratch.gpu_addr,
342 (void **)&adev->vram_scratch.ptr);
345 static void amdgpu_vram_scratch_fini(struct amdgpu_device *adev)
347 amdgpu_bo_free_kernel(&adev->vram_scratch.robj, NULL, NULL);
351 * amdgpu_program_register_sequence - program an array of registers.
353 * @adev: amdgpu_device pointer
354 * @registers: pointer to the register array
355 * @array_size: size of the register array
357 * Programs an array or registers with and and or masks.
358 * This is a helper for setting golden registers.
360 void amdgpu_program_register_sequence(struct amdgpu_device *adev,
361 const u32 *registers,
362 const u32 array_size)
364 u32 tmp, reg, and_mask, or_mask;
370 for (i = 0; i < array_size; i +=3) {
371 reg = registers[i + 0];
372 and_mask = registers[i + 1];
373 or_mask = registers[i + 2];
375 if (and_mask == 0xffffffff) {
386 void amdgpu_pci_config_reset(struct amdgpu_device *adev)
388 pci_write_config_dword(adev->pdev, 0x7c, AMDGPU_ASIC_RESET_DATA);
392 * GPU doorbell aperture helpers function.
395 * amdgpu_doorbell_init - Init doorbell driver information.
397 * @adev: amdgpu_device pointer
399 * Init doorbell driver information (CIK)
400 * Returns 0 on success, error on failure.
402 static int amdgpu_doorbell_init(struct amdgpu_device *adev)
404 /* No doorbell on SI hardware generation */
405 if (adev->asic_type < CHIP_BONAIRE) {
406 adev->doorbell.base = 0;
407 adev->doorbell.size = 0;
408 adev->doorbell.num_doorbells = 0;
409 adev->doorbell.ptr = NULL;
413 if (pci_resource_flags(adev->pdev, 2) & IORESOURCE_UNSET)
416 /* doorbell bar mapping */
417 adev->doorbell.base = pci_resource_start(adev->pdev, 2);
418 adev->doorbell.size = pci_resource_len(adev->pdev, 2);
420 adev->doorbell.num_doorbells = min_t(u32, adev->doorbell.size / sizeof(u32),
421 AMDGPU_DOORBELL_MAX_ASSIGNMENT+1);
422 if (adev->doorbell.num_doorbells == 0)
425 adev->doorbell.ptr = ioremap(adev->doorbell.base,
426 adev->doorbell.num_doorbells *
428 if (adev->doorbell.ptr == NULL)
435 * amdgpu_doorbell_fini - Tear down doorbell driver information.
437 * @adev: amdgpu_device pointer
439 * Tear down doorbell driver information (CIK)
441 static void amdgpu_doorbell_fini(struct amdgpu_device *adev)
443 iounmap(adev->doorbell.ptr);
444 adev->doorbell.ptr = NULL;
448 * amdgpu_doorbell_get_kfd_info - Report doorbell configuration required to
451 * @adev: amdgpu_device pointer
452 * @aperture_base: output returning doorbell aperture base physical address
453 * @aperture_size: output returning doorbell aperture size in bytes
454 * @start_offset: output returning # of doorbell bytes reserved for amdgpu.
456 * amdgpu and amdkfd share the doorbell aperture. amdgpu sets it up,
457 * takes doorbells required for its own rings and reports the setup to amdkfd.
458 * amdgpu reserved doorbells are at the start of the doorbell aperture.
460 void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
461 phys_addr_t *aperture_base,
462 size_t *aperture_size,
463 size_t *start_offset)
466 * The first num_doorbells are used by amdgpu.
467 * amdkfd takes whatever's left in the aperture.
469 if (adev->doorbell.size > adev->doorbell.num_doorbells * sizeof(u32)) {
470 *aperture_base = adev->doorbell.base;
471 *aperture_size = adev->doorbell.size;
472 *start_offset = adev->doorbell.num_doorbells * sizeof(u32);
482 * Writeback is the method by which the GPU updates special pages in memory
483 * with the status of certain GPU events (fences, ring pointers,etc.).
487 * amdgpu_wb_fini - Disable Writeback and free memory
489 * @adev: amdgpu_device pointer
491 * Disables Writeback and frees the Writeback memory (all asics).
492 * Used at driver shutdown.
494 static void amdgpu_wb_fini(struct amdgpu_device *adev)
496 if (adev->wb.wb_obj) {
497 amdgpu_bo_free_kernel(&adev->wb.wb_obj,
499 (void **)&adev->wb.wb);
500 adev->wb.wb_obj = NULL;
505 * amdgpu_wb_init- Init Writeback driver info and allocate memory
507 * @adev: amdgpu_device pointer
509 * Initializes writeback and allocates writeback memory (all asics).
510 * Used at driver startup.
511 * Returns 0 on success or an -error on failure.
513 static int amdgpu_wb_init(struct amdgpu_device *adev)
517 if (adev->wb.wb_obj == NULL) {
518 /* AMDGPU_MAX_WB * sizeof(uint32_t) * 8 = AMDGPU_MAX_WB 256bit slots */
519 r = amdgpu_bo_create_kernel(adev, AMDGPU_MAX_WB * sizeof(uint32_t) * 8,
520 PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
521 &adev->wb.wb_obj, &adev->wb.gpu_addr,
522 (void **)&adev->wb.wb);
524 dev_warn(adev->dev, "(%d) create WB bo failed\n", r);
528 adev->wb.num_wb = AMDGPU_MAX_WB;
529 memset(&adev->wb.used, 0, sizeof(adev->wb.used));
531 /* clear wb memory */
532 memset((char *)adev->wb.wb, 0, AMDGPU_MAX_WB * sizeof(uint32_t));
539 * amdgpu_wb_get - Allocate a wb entry
541 * @adev: amdgpu_device pointer
544 * Allocate a wb slot for use by the driver (all asics).
545 * Returns 0 on success or -EINVAL on failure.
547 int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb)
549 unsigned long offset = find_first_zero_bit(adev->wb.used, adev->wb.num_wb);
551 if (offset < adev->wb.num_wb) {
552 __set_bit(offset, adev->wb.used);
553 *wb = offset << 3; /* convert to dw offset */
561 * amdgpu_wb_free - Free a wb entry
563 * @adev: amdgpu_device pointer
566 * Free a wb slot allocated for use by the driver (all asics)
568 void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb)
570 if (wb < adev->wb.num_wb)
571 __clear_bit(wb >> 3, adev->wb.used);
575 * amdgpu_vram_location - try to find VRAM location
576 * @adev: amdgpu device structure holding all necessary informations
577 * @mc: memory controller structure holding memory informations
578 * @base: base address at which to put VRAM
580 * Function will try to place VRAM at base address provided
583 void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base)
585 uint64_t limit = (uint64_t)amdgpu_vram_limit << 20;
587 mc->vram_start = base;
588 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
589 if (limit && limit < mc->real_vram_size)
590 mc->real_vram_size = limit;
591 dev_info(adev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
592 mc->mc_vram_size >> 20, mc->vram_start,
593 mc->vram_end, mc->real_vram_size >> 20);
597 * amdgpu_gart_location - try to find GTT location
598 * @adev: amdgpu device structure holding all necessary informations
599 * @mc: memory controller structure holding memory informations
601 * Function will place try to place GTT before or after VRAM.
603 * If GTT size is bigger than space left then we ajust GTT size.
604 * Thus function will never fails.
606 * FIXME: when reducing GTT size align new size on power of 2.
608 void amdgpu_gart_location(struct amdgpu_device *adev, struct amdgpu_mc *mc)
610 u64 size_af, size_bf;
612 size_af = adev->mc.mc_mask - mc->vram_end;
613 size_bf = mc->vram_start;
614 if (size_bf > size_af) {
615 if (mc->gart_size > size_bf) {
616 dev_warn(adev->dev, "limiting GTT\n");
617 mc->gart_size = size_bf;
621 if (mc->gart_size > size_af) {
622 dev_warn(adev->dev, "limiting GTT\n");
623 mc->gart_size = size_af;
625 mc->gart_start = mc->vram_end + 1;
627 mc->gart_end = mc->gart_start + mc->gart_size - 1;
628 dev_info(adev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
629 mc->gart_size >> 20, mc->gart_start, mc->gart_end);
633 * Firmware Reservation functions
636 * amdgpu_fw_reserve_vram_fini - free fw reserved vram
638 * @adev: amdgpu_device pointer
640 * free fw reserved vram if it has been reserved.
642 void amdgpu_fw_reserve_vram_fini(struct amdgpu_device *adev)
644 amdgpu_bo_free_kernel(&adev->fw_vram_usage.reserved_bo,
645 NULL, &adev->fw_vram_usage.va);
649 * amdgpu_fw_reserve_vram_init - create bo vram reservation from fw
651 * @adev: amdgpu_device pointer
653 * create bo vram reservation from fw.
655 int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev)
659 u64 vram_size = adev->mc.visible_vram_size;
660 u64 offset = adev->fw_vram_usage.start_offset;
661 u64 size = adev->fw_vram_usage.size;
662 struct amdgpu_bo *bo;
664 adev->fw_vram_usage.va = NULL;
665 adev->fw_vram_usage.reserved_bo = NULL;
667 if (adev->fw_vram_usage.size > 0 &&
668 adev->fw_vram_usage.size <= vram_size) {
670 r = amdgpu_bo_create(adev, adev->fw_vram_usage.size,
671 PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM,
672 AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
673 AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL, 0,
674 &adev->fw_vram_usage.reserved_bo);
678 r = amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo, false);
682 /* remove the original mem node and create a new one at the
685 bo = adev->fw_vram_usage.reserved_bo;
686 offset = ALIGN(offset, PAGE_SIZE);
687 for (i = 0; i < bo->placement.num_placement; ++i) {
688 bo->placements[i].fpfn = offset >> PAGE_SHIFT;
689 bo->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;
692 ttm_bo_mem_put(&bo->tbo, &bo->tbo.mem);
693 r = ttm_bo_mem_space(&bo->tbo, &bo->placement, &bo->tbo.mem,
698 r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo,
699 AMDGPU_GEM_DOMAIN_VRAM,
700 adev->fw_vram_usage.start_offset,
701 (adev->fw_vram_usage.start_offset +
702 adev->fw_vram_usage.size), NULL);
705 r = amdgpu_bo_kmap(adev->fw_vram_usage.reserved_bo,
706 &adev->fw_vram_usage.va);
710 amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);
715 amdgpu_bo_unpin(adev->fw_vram_usage.reserved_bo);
717 amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);
719 amdgpu_bo_unref(&adev->fw_vram_usage.reserved_bo);
721 adev->fw_vram_usage.va = NULL;
722 adev->fw_vram_usage.reserved_bo = NULL;
727 * amdgpu_device_resize_fb_bar - try to resize FB BAR
729 * @adev: amdgpu_device pointer
731 * Try to resize FB BAR to make all VRAM CPU accessible. We try very hard not
732 * to fail, but if any of the BARs is not accessible after the size we abort
733 * driver loading by returning -ENODEV.
735 int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
737 u64 space_needed = roundup_pow_of_two(adev->mc.real_vram_size);
738 u32 rbar_size = order_base_2(((space_needed >> 20) | 1)) - 1;
739 struct pci_bus *root;
740 struct resource *res;
746 if (amdgpu_sriov_vf(adev))
749 /* Check if the root BUS has 64bit memory resources */
750 root = adev->pdev->bus;
754 pci_bus_for_each_resource(root, res, i) {
755 if (res && res->flags & IORESOURCE_MEM_64 &&
756 res->start > 0x100000000ull)
760 /* Trying to resize is pointless without a root hub window above 4GB */
764 /* Disable memory decoding while we change the BAR addresses and size */
765 pci_read_config_word(adev->pdev, PCI_COMMAND, &cmd);
766 pci_write_config_word(adev->pdev, PCI_COMMAND,
767 cmd & ~PCI_COMMAND_MEMORY);
769 /* Free the VRAM and doorbell BAR, we most likely need to move both. */
770 amdgpu_doorbell_fini(adev);
771 if (adev->asic_type >= CHIP_BONAIRE)
772 pci_release_resource(adev->pdev, 2);
774 pci_release_resource(adev->pdev, 0);
776 r = pci_resize_resource(adev->pdev, 0, rbar_size);
778 DRM_INFO("Not enough PCI address space for a large BAR.");
779 else if (r && r != -ENOTSUPP)
780 DRM_ERROR("Problem resizing BAR0 (%d).", r);
782 pci_assign_unassigned_bus_resources(adev->pdev->bus);
784 /* When the doorbell or fb BAR isn't available we have no chance of
787 r = amdgpu_doorbell_init(adev);
788 if (r || (pci_resource_flags(adev->pdev, 0) & IORESOURCE_UNSET))
791 pci_write_config_word(adev->pdev, PCI_COMMAND, cmd);
797 * GPU helpers function.
800 * amdgpu_need_post - check if the hw need post or not
802 * @adev: amdgpu_device pointer
804 * Check if the asic has been initialized (all asics) at driver startup
805 * or post is needed if hw reset is performed.
806 * Returns true if need or false if not.
808 bool amdgpu_need_post(struct amdgpu_device *adev)
812 if (amdgpu_sriov_vf(adev))
815 if (amdgpu_passthrough(adev)) {
816 /* for FIJI: In whole GPU pass-through virtualization case, after VM reboot
817 * some old smc fw still need driver do vPost otherwise gpu hang, while
818 * those smc fw version above 22.15 doesn't have this flaw, so we force
819 * vpost executed for smc version below 22.15
821 if (adev->asic_type == CHIP_FIJI) {
824 err = request_firmware(&adev->pm.fw, "amdgpu/fiji_smc.bin", adev->dev);
825 /* force vPost if error occured */
829 fw_ver = *((uint32_t *)adev->pm.fw->data + 69);
830 if (fw_ver < 0x00160e00)
835 if (adev->has_hw_reset) {
836 adev->has_hw_reset = false;
840 /* bios scratch used on CIK+ */
841 if (adev->asic_type >= CHIP_BONAIRE)
842 return amdgpu_atombios_scratch_need_asic_init(adev);
844 /* check MEM_SIZE for older asics */
845 reg = amdgpu_asic_get_config_memsize(adev);
847 if ((reg != 0) && (reg != 0xffffffff))
854 * amdgpu_dummy_page_init - init dummy page used by the driver
856 * @adev: amdgpu_device pointer
858 * Allocate the dummy page used by the driver (all asics).
859 * This dummy page is used by the driver as a filler for gart entries
860 * when pages are taken out of the GART
861 * Returns 0 on sucess, -ENOMEM on failure.
863 int amdgpu_dummy_page_init(struct amdgpu_device *adev)
865 if (adev->dummy_page.page)
867 adev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO);
868 if (adev->dummy_page.page == NULL)
870 adev->dummy_page.addr = pci_map_page(adev->pdev, adev->dummy_page.page,
871 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
872 if (pci_dma_mapping_error(adev->pdev, adev->dummy_page.addr)) {
873 dev_err(&adev->pdev->dev, "Failed to DMA MAP the dummy page\n");
874 __free_page(adev->dummy_page.page);
875 adev->dummy_page.page = NULL;
882 * amdgpu_dummy_page_fini - free dummy page used by the driver
884 * @adev: amdgpu_device pointer
886 * Frees the dummy page used by the driver (all asics).
888 void amdgpu_dummy_page_fini(struct amdgpu_device *adev)
890 if (adev->dummy_page.page == NULL)
892 pci_unmap_page(adev->pdev, adev->dummy_page.addr,
893 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
894 __free_page(adev->dummy_page.page);
895 adev->dummy_page.page = NULL;
899 /* ATOM accessor methods */
901 * ATOM is an interpreted byte code stored in tables in the vbios. The
902 * driver registers callbacks to access registers and the interpreter
903 * in the driver parses the tables and executes then to program specific
904 * actions (set display modes, asic init, etc.). See amdgpu_atombios.c,
905 * atombios.h, and atom.c
909 * cail_pll_read - read PLL register
911 * @info: atom card_info pointer
912 * @reg: PLL register offset
914 * Provides a PLL register accessor for the atom interpreter (r4xx+).
915 * Returns the value of the PLL register.
917 static uint32_t cail_pll_read(struct card_info *info, uint32_t reg)
923 * cail_pll_write - write PLL register
925 * @info: atom card_info pointer
926 * @reg: PLL register offset
927 * @val: value to write to the pll register
929 * Provides a PLL register accessor for the atom interpreter (r4xx+).
931 static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val)
937 * cail_mc_read - read MC (Memory Controller) register
939 * @info: atom card_info pointer
940 * @reg: MC register offset
942 * Provides an MC register accessor for the atom interpreter (r4xx+).
943 * Returns the value of the MC register.
945 static uint32_t cail_mc_read(struct card_info *info, uint32_t reg)
951 * cail_mc_write - write MC (Memory Controller) register
953 * @info: atom card_info pointer
954 * @reg: MC register offset
955 * @val: value to write to the pll register
957 * Provides a MC register accessor for the atom interpreter (r4xx+).
959 static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val)
965 * cail_reg_write - write MMIO register
967 * @info: atom card_info pointer
968 * @reg: MMIO register offset
969 * @val: value to write to the pll register
971 * Provides a MMIO register accessor for the atom interpreter (r4xx+).
973 static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val)
975 struct amdgpu_device *adev = info->dev->dev_private;
981 * cail_reg_read - read MMIO register
983 * @info: atom card_info pointer
984 * @reg: MMIO register offset
986 * Provides an MMIO register accessor for the atom interpreter (r4xx+).
987 * Returns the value of the MMIO register.
989 static uint32_t cail_reg_read(struct card_info *info, uint32_t reg)
991 struct amdgpu_device *adev = info->dev->dev_private;
999 * cail_ioreg_write - write IO register
1001 * @info: atom card_info pointer
1002 * @reg: IO register offset
1003 * @val: value to write to the pll register
1005 * Provides a IO register accessor for the atom interpreter (r4xx+).
1007 static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val)
1009 struct amdgpu_device *adev = info->dev->dev_private;
1011 WREG32_IO(reg, val);
1015 * cail_ioreg_read - read IO register
1017 * @info: atom card_info pointer
1018 * @reg: IO register offset
1020 * Provides an IO register accessor for the atom interpreter (r4xx+).
1021 * Returns the value of the IO register.
1023 static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg)
1025 struct amdgpu_device *adev = info->dev->dev_private;
1032 static ssize_t amdgpu_atombios_get_vbios_version(struct device *dev,
1033 struct device_attribute *attr,
1036 struct drm_device *ddev = dev_get_drvdata(dev);
1037 struct amdgpu_device *adev = ddev->dev_private;
1038 struct atom_context *ctx = adev->mode_info.atom_context;
1040 return snprintf(buf, PAGE_SIZE, "%s\n", ctx->vbios_version);
1043 static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version,
1047 * amdgpu_atombios_fini - free the driver info and callbacks for atombios
1049 * @adev: amdgpu_device pointer
1051 * Frees the driver info and register access callbacks for the ATOM
1052 * interpreter (r4xx+).
1053 * Called at driver shutdown.
1055 static void amdgpu_atombios_fini(struct amdgpu_device *adev)
1057 if (adev->mode_info.atom_context) {
1058 kfree(adev->mode_info.atom_context->scratch);
1059 kfree(adev->mode_info.atom_context->iio);
1061 kfree(adev->mode_info.atom_context);
1062 adev->mode_info.atom_context = NULL;
1063 kfree(adev->mode_info.atom_card_info);
1064 adev->mode_info.atom_card_info = NULL;
1065 device_remove_file(adev->dev, &dev_attr_vbios_version);
1069 * amdgpu_atombios_init - init the driver info and callbacks for atombios
1071 * @adev: amdgpu_device pointer
1073 * Initializes the driver info and register access callbacks for the
1074 * ATOM interpreter (r4xx+).
1075 * Returns 0 on sucess, -ENOMEM on failure.
1076 * Called at driver startup.
1078 static int amdgpu_atombios_init(struct amdgpu_device *adev)
1080 struct card_info *atom_card_info =
1081 kzalloc(sizeof(struct card_info), GFP_KERNEL);
1084 if (!atom_card_info)
1087 adev->mode_info.atom_card_info = atom_card_info;
1088 atom_card_info->dev = adev->ddev;
1089 atom_card_info->reg_read = cail_reg_read;
1090 atom_card_info->reg_write = cail_reg_write;
1091 /* needed for iio ops */
1092 if (adev->rio_mem) {
1093 atom_card_info->ioreg_read = cail_ioreg_read;
1094 atom_card_info->ioreg_write = cail_ioreg_write;
1096 DRM_DEBUG("PCI I/O BAR is not found. Using MMIO to access ATOM BIOS\n");
1097 atom_card_info->ioreg_read = cail_reg_read;
1098 atom_card_info->ioreg_write = cail_reg_write;
1100 atom_card_info->mc_read = cail_mc_read;
1101 atom_card_info->mc_write = cail_mc_write;
1102 atom_card_info->pll_read = cail_pll_read;
1103 atom_card_info->pll_write = cail_pll_write;
1105 adev->mode_info.atom_context = amdgpu_atom_parse(atom_card_info, adev->bios);
1106 if (!adev->mode_info.atom_context) {
1107 amdgpu_atombios_fini(adev);
1111 mutex_init(&adev->mode_info.atom_context->mutex);
1112 if (adev->is_atom_fw) {
1113 amdgpu_atomfirmware_scratch_regs_init(adev);
1114 amdgpu_atomfirmware_allocate_fb_scratch(adev);
1116 amdgpu_atombios_scratch_regs_init(adev);
1117 amdgpu_atombios_allocate_fb_scratch(adev);
1120 ret = device_create_file(adev->dev, &dev_attr_vbios_version);
1122 DRM_ERROR("Failed to create device file for VBIOS version\n");
1129 /* if we get transitioned to only one device, take VGA back */
1131 * amdgpu_vga_set_decode - enable/disable vga decode
1133 * @cookie: amdgpu_device pointer
1134 * @state: enable/disable vga decode
1136 * Enable/disable vga decode (all asics).
1137 * Returns VGA resource flags.
1139 static unsigned int amdgpu_vga_set_decode(void *cookie, bool state)
1141 struct amdgpu_device *adev = cookie;
1142 amdgpu_asic_set_vga_state(adev, state);
1144 return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
1145 VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
1147 return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
1150 static void amdgpu_check_block_size(struct amdgpu_device *adev)
1152 /* defines number of bits in page table versus page directory,
1153 * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
1154 * page table and the remaining bits are in the page directory */
1155 if (amdgpu_vm_block_size == -1)
1158 if (amdgpu_vm_block_size < 9) {
1159 dev_warn(adev->dev, "VM page table size (%d) too small\n",
1160 amdgpu_vm_block_size);
1164 if (amdgpu_vm_block_size > 24 ||
1165 (amdgpu_vm_size * 1024) < (1ull << amdgpu_vm_block_size)) {
1166 dev_warn(adev->dev, "VM page table size (%d) too large\n",
1167 amdgpu_vm_block_size);
1174 amdgpu_vm_block_size = -1;
1177 static void amdgpu_check_vm_size(struct amdgpu_device *adev)
1179 /* no need to check the default value */
1180 if (amdgpu_vm_size == -1)
1183 if (!is_power_of_2(amdgpu_vm_size)) {
1184 dev_warn(adev->dev, "VM size (%d) must be a power of 2\n",
1189 if (amdgpu_vm_size < 1) {
1190 dev_warn(adev->dev, "VM size (%d) too small, min is 1GB\n",
1196 * Max GPUVM size for Cayman, SI, CI VI are 40 bits.
1198 if (amdgpu_vm_size > 1024) {
1199 dev_warn(adev->dev, "VM size (%d) too large, max is 1TB\n",
1207 amdgpu_vm_size = -1;
1211 * amdgpu_check_arguments - validate module params
1213 * @adev: amdgpu_device pointer
1215 * Validates certain module parameters and updates
1216 * the associated values used by the driver (all asics).
1218 static void amdgpu_check_arguments(struct amdgpu_device *adev)
1220 if (amdgpu_sched_jobs < 4) {
1221 dev_warn(adev->dev, "sched jobs (%d) must be at least 4\n",
1223 amdgpu_sched_jobs = 4;
1224 } else if (!is_power_of_2(amdgpu_sched_jobs)){
1225 dev_warn(adev->dev, "sched jobs (%d) must be a power of 2\n",
1227 amdgpu_sched_jobs = roundup_pow_of_two(amdgpu_sched_jobs);
1230 if (amdgpu_gart_size != -1 && amdgpu_gart_size < 32) {
1231 /* gart size must be greater or equal to 32M */
1232 dev_warn(adev->dev, "gart size (%d) too small\n",
1234 amdgpu_gart_size = -1;
1237 if (amdgpu_gtt_size != -1 && amdgpu_gtt_size < 32) {
1238 /* gtt size must be greater or equal to 32M */
1239 dev_warn(adev->dev, "gtt size (%d) too small\n",
1241 amdgpu_gtt_size = -1;
1244 /* valid range is between 4 and 9 inclusive */
1245 if (amdgpu_vm_fragment_size != -1 &&
1246 (amdgpu_vm_fragment_size > 9 || amdgpu_vm_fragment_size < 4)) {
1247 dev_warn(adev->dev, "valid range is between 4 and 9\n");
1248 amdgpu_vm_fragment_size = -1;
1251 amdgpu_check_vm_size(adev);
1253 amdgpu_check_block_size(adev);
1255 if (amdgpu_vram_page_split != -1 && (amdgpu_vram_page_split < 16 ||
1256 !is_power_of_2(amdgpu_vram_page_split))) {
1257 dev_warn(adev->dev, "invalid VRAM page split (%d)\n",
1258 amdgpu_vram_page_split);
1259 amdgpu_vram_page_split = 1024;
1264 * amdgpu_switcheroo_set_state - set switcheroo state
1266 * @pdev: pci dev pointer
1267 * @state: vga_switcheroo state
1269 * Callback for the switcheroo driver. Suspends or resumes the
1270 * the asics before or after it is powered up using ACPI methods.
1272 static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
1274 struct drm_device *dev = pci_get_drvdata(pdev);
1276 if (amdgpu_device_is_px(dev) && state == VGA_SWITCHEROO_OFF)
1279 if (state == VGA_SWITCHEROO_ON) {
1280 pr_info("amdgpu: switched on\n");
1281 /* don't suspend or resume card normally */
1282 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
1284 amdgpu_device_resume(dev, true, true);
1286 dev->switch_power_state = DRM_SWITCH_POWER_ON;
1287 drm_kms_helper_poll_enable(dev);
1289 pr_info("amdgpu: switched off\n");
1290 drm_kms_helper_poll_disable(dev);
1291 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
1292 amdgpu_device_suspend(dev, true, true);
1293 dev->switch_power_state = DRM_SWITCH_POWER_OFF;
1298 * amdgpu_switcheroo_can_switch - see if switcheroo state can change
1300 * @pdev: pci dev pointer
1302 * Callback for the switcheroo driver. Check of the switcheroo
1303 * state can be changed.
1304 * Returns true if the state can be changed, false if not.
1306 static bool amdgpu_switcheroo_can_switch(struct pci_dev *pdev)
1308 struct drm_device *dev = pci_get_drvdata(pdev);
1311 * FIXME: open_count is protected by drm_global_mutex but that would lead to
1312 * locking inversion with the driver load path. And the access here is
1313 * completely racy anyway. So don't bother with locking for now.
1315 return dev->open_count == 0;
1318 static const struct vga_switcheroo_client_ops amdgpu_switcheroo_ops = {
1319 .set_gpu_state = amdgpu_switcheroo_set_state,
1321 .can_switch = amdgpu_switcheroo_can_switch,
1324 int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
1325 enum amd_ip_block_type block_type,
1326 enum amd_clockgating_state state)
1330 for (i = 0; i < adev->num_ip_blocks; i++) {
1331 if (!adev->ip_blocks[i].status.valid)
1333 if (adev->ip_blocks[i].version->type != block_type)
1335 if (!adev->ip_blocks[i].version->funcs->set_clockgating_state)
1337 r = adev->ip_blocks[i].version->funcs->set_clockgating_state(
1338 (void *)adev, state);
1340 DRM_ERROR("set_clockgating_state of IP block <%s> failed %d\n",
1341 adev->ip_blocks[i].version->funcs->name, r);
1346 int amdgpu_set_powergating_state(struct amdgpu_device *adev,
1347 enum amd_ip_block_type block_type,
1348 enum amd_powergating_state state)
1352 for (i = 0; i < adev->num_ip_blocks; i++) {
1353 if (!adev->ip_blocks[i].status.valid)
1355 if (adev->ip_blocks[i].version->type != block_type)
1357 if (!adev->ip_blocks[i].version->funcs->set_powergating_state)
1359 r = adev->ip_blocks[i].version->funcs->set_powergating_state(
1360 (void *)adev, state);
1362 DRM_ERROR("set_powergating_state of IP block <%s> failed %d\n",
1363 adev->ip_blocks[i].version->funcs->name, r);
1368 void amdgpu_get_clockgating_state(struct amdgpu_device *adev, u32 *flags)
1372 for (i = 0; i < adev->num_ip_blocks; i++) {
1373 if (!adev->ip_blocks[i].status.valid)
1375 if (adev->ip_blocks[i].version->funcs->get_clockgating_state)
1376 adev->ip_blocks[i].version->funcs->get_clockgating_state((void *)adev, flags);
1380 int amdgpu_wait_for_idle(struct amdgpu_device *adev,
1381 enum amd_ip_block_type block_type)
1385 for (i = 0; i < adev->num_ip_blocks; i++) {
1386 if (!adev->ip_blocks[i].status.valid)
1388 if (adev->ip_blocks[i].version->type == block_type) {
1389 r = adev->ip_blocks[i].version->funcs->wait_for_idle((void *)adev);
1399 bool amdgpu_is_idle(struct amdgpu_device *adev,
1400 enum amd_ip_block_type block_type)
1404 for (i = 0; i < adev->num_ip_blocks; i++) {
1405 if (!adev->ip_blocks[i].status.valid)
1407 if (adev->ip_blocks[i].version->type == block_type)
1408 return adev->ip_blocks[i].version->funcs->is_idle((void *)adev);
1414 struct amdgpu_ip_block * amdgpu_get_ip_block(struct amdgpu_device *adev,
1415 enum amd_ip_block_type type)
1419 for (i = 0; i < adev->num_ip_blocks; i++)
1420 if (adev->ip_blocks[i].version->type == type)
1421 return &adev->ip_blocks[i];
1427 * amdgpu_ip_block_version_cmp
1429 * @adev: amdgpu_device pointer
1430 * @type: enum amd_ip_block_type
1431 * @major: major version
1432 * @minor: minor version
1434 * return 0 if equal or greater
1435 * return 1 if smaller or the ip_block doesn't exist
1437 int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
1438 enum amd_ip_block_type type,
1439 u32 major, u32 minor)
1441 struct amdgpu_ip_block *ip_block = amdgpu_get_ip_block(adev, type);
1443 if (ip_block && ((ip_block->version->major > major) ||
1444 ((ip_block->version->major == major) &&
1445 (ip_block->version->minor >= minor))))
1452 * amdgpu_ip_block_add
1454 * @adev: amdgpu_device pointer
1455 * @ip_block_version: pointer to the IP to add
1457 * Adds the IP block driver information to the collection of IPs
1460 int amdgpu_ip_block_add(struct amdgpu_device *adev,
1461 const struct amdgpu_ip_block_version *ip_block_version)
1463 if (!ip_block_version)
1466 DRM_DEBUG("add ip block number %d <%s>\n", adev->num_ip_blocks,
1467 ip_block_version->funcs->name);
1469 adev->ip_blocks[adev->num_ip_blocks++].version = ip_block_version;
1474 static void amdgpu_device_enable_virtual_display(struct amdgpu_device *adev)
1476 adev->enable_virtual_display = false;
1478 if (amdgpu_virtual_display) {
1479 struct drm_device *ddev = adev->ddev;
1480 const char *pci_address_name = pci_name(ddev->pdev);
1481 char *pciaddstr, *pciaddstr_tmp, *pciaddname_tmp, *pciaddname;
1483 pciaddstr = kstrdup(amdgpu_virtual_display, GFP_KERNEL);
1484 pciaddstr_tmp = pciaddstr;
1485 while ((pciaddname_tmp = strsep(&pciaddstr_tmp, ";"))) {
1486 pciaddname = strsep(&pciaddname_tmp, ",");
1487 if (!strcmp("all", pciaddname)
1488 || !strcmp(pci_address_name, pciaddname)) {
1492 adev->enable_virtual_display = true;
1495 res = kstrtol(pciaddname_tmp, 10,
1503 adev->mode_info.num_crtc = num_crtc;
1505 adev->mode_info.num_crtc = 1;
1511 DRM_INFO("virtual display string:%s, %s:virtual_display:%d, num_crtc:%d\n",
1512 amdgpu_virtual_display, pci_address_name,
1513 adev->enable_virtual_display, adev->mode_info.num_crtc);
1519 static int amdgpu_device_parse_gpu_info_fw(struct amdgpu_device *adev)
1521 const char *chip_name;
1524 const struct gpu_info_firmware_header_v1_0 *hdr;
1526 adev->firmware.gpu_info_fw = NULL;
1528 switch (adev->asic_type) {
1532 case CHIP_POLARIS11:
1533 case CHIP_POLARIS10:
1534 case CHIP_POLARIS12:
1537 #ifdef CONFIG_DRM_AMDGPU_SI
1544 #ifdef CONFIG_DRM_AMDGPU_CIK
1554 chip_name = "vega10";
1557 chip_name = "raven";
1561 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_gpu_info.bin", chip_name);
1562 err = request_firmware(&adev->firmware.gpu_info_fw, fw_name, adev->dev);
1565 "Failed to load gpu_info firmware \"%s\"\n",
1569 err = amdgpu_ucode_validate(adev->firmware.gpu_info_fw);
1572 "Failed to validate gpu_info firmware \"%s\"\n",
1577 hdr = (const struct gpu_info_firmware_header_v1_0 *)adev->firmware.gpu_info_fw->data;
1578 amdgpu_ucode_print_gpu_info_hdr(&hdr->header);
1580 switch (hdr->version_major) {
1583 const struct gpu_info_firmware_v1_0 *gpu_info_fw =
1584 (const struct gpu_info_firmware_v1_0 *)(adev->firmware.gpu_info_fw->data +
1585 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1587 adev->gfx.config.max_shader_engines = le32_to_cpu(gpu_info_fw->gc_num_se);
1588 adev->gfx.config.max_cu_per_sh = le32_to_cpu(gpu_info_fw->gc_num_cu_per_sh);
1589 adev->gfx.config.max_sh_per_se = le32_to_cpu(gpu_info_fw->gc_num_sh_per_se);
1590 adev->gfx.config.max_backends_per_se = le32_to_cpu(gpu_info_fw->gc_num_rb_per_se);
1591 adev->gfx.config.max_texture_channel_caches =
1592 le32_to_cpu(gpu_info_fw->gc_num_tccs);
1593 adev->gfx.config.max_gprs = le32_to_cpu(gpu_info_fw->gc_num_gprs);
1594 adev->gfx.config.max_gs_threads = le32_to_cpu(gpu_info_fw->gc_num_max_gs_thds);
1595 adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gpu_info_fw->gc_gs_table_depth);
1596 adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gpu_info_fw->gc_gsprim_buff_depth);
1597 adev->gfx.config.double_offchip_lds_buf =
1598 le32_to_cpu(gpu_info_fw->gc_double_offchip_lds_buffer);
1599 adev->gfx.cu_info.wave_front_size = le32_to_cpu(gpu_info_fw->gc_wave_size);
1600 adev->gfx.cu_info.max_waves_per_simd =
1601 le32_to_cpu(gpu_info_fw->gc_max_waves_per_simd);
1602 adev->gfx.cu_info.max_scratch_slots_per_cu =
1603 le32_to_cpu(gpu_info_fw->gc_max_scratch_slots_per_cu);
1604 adev->gfx.cu_info.lds_size = le32_to_cpu(gpu_info_fw->gc_lds_size);
1609 "Unsupported gpu_info table %d\n", hdr->header.ucode_version);
1617 static int amdgpu_early_init(struct amdgpu_device *adev)
1621 amdgpu_device_enable_virtual_display(adev);
1623 switch (adev->asic_type) {
1627 case CHIP_POLARIS11:
1628 case CHIP_POLARIS10:
1629 case CHIP_POLARIS12:
1632 if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY)
1633 adev->family = AMDGPU_FAMILY_CZ;
1635 adev->family = AMDGPU_FAMILY_VI;
1637 r = vi_set_ip_blocks(adev);
1641 #ifdef CONFIG_DRM_AMDGPU_SI
1647 adev->family = AMDGPU_FAMILY_SI;
1648 r = si_set_ip_blocks(adev);
1653 #ifdef CONFIG_DRM_AMDGPU_CIK
1659 if ((adev->asic_type == CHIP_BONAIRE) || (adev->asic_type == CHIP_HAWAII))
1660 adev->family = AMDGPU_FAMILY_CI;
1662 adev->family = AMDGPU_FAMILY_KV;
1664 r = cik_set_ip_blocks(adev);
1671 if (adev->asic_type == CHIP_RAVEN)
1672 adev->family = AMDGPU_FAMILY_RV;
1674 adev->family = AMDGPU_FAMILY_AI;
1676 r = soc15_set_ip_blocks(adev);
1681 /* FIXME: not supported yet */
1685 r = amdgpu_device_parse_gpu_info_fw(adev);
1689 amdgpu_amdkfd_device_probe(adev);
1691 if (amdgpu_sriov_vf(adev)) {
1692 r = amdgpu_virt_request_full_gpu(adev, true);
1697 for (i = 0; i < adev->num_ip_blocks; i++) {
1698 if ((amdgpu_ip_block_mask & (1 << i)) == 0) {
1699 DRM_ERROR("disabled ip block: %d <%s>\n",
1700 i, adev->ip_blocks[i].version->funcs->name);
1701 adev->ip_blocks[i].status.valid = false;
1703 if (adev->ip_blocks[i].version->funcs->early_init) {
1704 r = adev->ip_blocks[i].version->funcs->early_init((void *)adev);
1706 adev->ip_blocks[i].status.valid = false;
1708 DRM_ERROR("early_init of IP block <%s> failed %d\n",
1709 adev->ip_blocks[i].version->funcs->name, r);
1712 adev->ip_blocks[i].status.valid = true;
1715 adev->ip_blocks[i].status.valid = true;
1720 adev->cg_flags &= amdgpu_cg_mask;
1721 adev->pg_flags &= amdgpu_pg_mask;
1726 static int amdgpu_init(struct amdgpu_device *adev)
1730 for (i = 0; i < adev->num_ip_blocks; i++) {
1731 if (!adev->ip_blocks[i].status.valid)
1733 r = adev->ip_blocks[i].version->funcs->sw_init((void *)adev);
1735 DRM_ERROR("sw_init of IP block <%s> failed %d\n",
1736 adev->ip_blocks[i].version->funcs->name, r);
1739 adev->ip_blocks[i].status.sw = true;
1740 /* need to do gmc hw init early so we can allocate gpu mem */
1741 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
1742 r = amdgpu_vram_scratch_init(adev);
1744 DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r);
1747 r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev);
1749 DRM_ERROR("hw_init %d failed %d\n", i, r);
1752 r = amdgpu_wb_init(adev);
1754 DRM_ERROR("amdgpu_wb_init failed %d\n", r);
1757 adev->ip_blocks[i].status.hw = true;
1759 /* right after GMC hw init, we create CSA */
1760 if (amdgpu_sriov_vf(adev)) {
1761 r = amdgpu_allocate_static_csa(adev);
1763 DRM_ERROR("allocate CSA failed %d\n", r);
1770 for (i = 0; i < adev->num_ip_blocks; i++) {
1771 if (!adev->ip_blocks[i].status.sw)
1773 /* gmc hw init is done early */
1774 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC)
1776 r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev);
1778 DRM_ERROR("hw_init of IP block <%s> failed %d\n",
1779 adev->ip_blocks[i].version->funcs->name, r);
1782 adev->ip_blocks[i].status.hw = true;
1785 amdgpu_amdkfd_device_init(adev);
1787 if (amdgpu_sriov_vf(adev))
1788 amdgpu_virt_release_full_gpu(adev, true);
1793 static void amdgpu_fill_reset_magic(struct amdgpu_device *adev)
1795 memcpy(adev->reset_magic, adev->gart.ptr, AMDGPU_RESET_MAGIC_NUM);
1798 static bool amdgpu_check_vram_lost(struct amdgpu_device *adev)
1800 return !!memcmp(adev->gart.ptr, adev->reset_magic,
1801 AMDGPU_RESET_MAGIC_NUM);
1804 static int amdgpu_late_set_cg_state(struct amdgpu_device *adev)
1808 for (i = 0; i < adev->num_ip_blocks; i++) {
1809 if (!adev->ip_blocks[i].status.valid)
1811 /* skip CG for VCE/UVD, it's handled specially */
1812 if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
1813 adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) {
1814 /* enable clockgating to save power */
1815 r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
1818 DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n",
1819 adev->ip_blocks[i].version->funcs->name, r);
1827 static int amdgpu_late_init(struct amdgpu_device *adev)
1831 for (i = 0; i < adev->num_ip_blocks; i++) {
1832 if (!adev->ip_blocks[i].status.valid)
1834 if (adev->ip_blocks[i].version->funcs->late_init) {
1835 r = adev->ip_blocks[i].version->funcs->late_init((void *)adev);
1837 DRM_ERROR("late_init of IP block <%s> failed %d\n",
1838 adev->ip_blocks[i].version->funcs->name, r);
1841 adev->ip_blocks[i].status.late_initialized = true;
1845 mod_delayed_work(system_wq, &adev->late_init_work,
1846 msecs_to_jiffies(AMDGPU_RESUME_MS));
1848 amdgpu_fill_reset_magic(adev);
1853 static int amdgpu_fini(struct amdgpu_device *adev)
1857 amdgpu_amdkfd_device_fini(adev);
1858 /* need to disable SMC first */
1859 for (i = 0; i < adev->num_ip_blocks; i++) {
1860 if (!adev->ip_blocks[i].status.hw)
1862 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) {
1863 /* ungate blocks before hw fini so that we can shutdown the blocks safely */
1864 r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
1865 AMD_CG_STATE_UNGATE);
1867 DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
1868 adev->ip_blocks[i].version->funcs->name, r);
1871 r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev);
1872 /* XXX handle errors */
1874 DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
1875 adev->ip_blocks[i].version->funcs->name, r);
1877 adev->ip_blocks[i].status.hw = false;
1882 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
1883 if (!adev->ip_blocks[i].status.hw)
1885 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
1886 amdgpu_free_static_csa(adev);
1887 amdgpu_wb_fini(adev);
1888 amdgpu_vram_scratch_fini(adev);
1891 if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
1892 adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) {
1893 /* ungate blocks before hw fini so that we can shutdown the blocks safely */
1894 r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
1895 AMD_CG_STATE_UNGATE);
1897 DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
1898 adev->ip_blocks[i].version->funcs->name, r);
1903 r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev);
1904 /* XXX handle errors */
1906 DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
1907 adev->ip_blocks[i].version->funcs->name, r);
1910 adev->ip_blocks[i].status.hw = false;
1913 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
1914 if (!adev->ip_blocks[i].status.sw)
1916 r = adev->ip_blocks[i].version->funcs->sw_fini((void *)adev);
1917 /* XXX handle errors */
1919 DRM_DEBUG("sw_fini of IP block <%s> failed %d\n",
1920 adev->ip_blocks[i].version->funcs->name, r);
1922 adev->ip_blocks[i].status.sw = false;
1923 adev->ip_blocks[i].status.valid = false;
1926 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
1927 if (!adev->ip_blocks[i].status.late_initialized)
1929 if (adev->ip_blocks[i].version->funcs->late_fini)
1930 adev->ip_blocks[i].version->funcs->late_fini((void *)adev);
1931 adev->ip_blocks[i].status.late_initialized = false;
1934 if (amdgpu_sriov_vf(adev))
1935 if (amdgpu_virt_release_full_gpu(adev, false))
1936 DRM_ERROR("failed to release exclusive mode on fini\n");
1941 static void amdgpu_late_init_func_handler(struct work_struct *work)
1943 struct amdgpu_device *adev =
1944 container_of(work, struct amdgpu_device, late_init_work.work);
1945 amdgpu_late_set_cg_state(adev);
1948 int amdgpu_suspend(struct amdgpu_device *adev)
1952 if (amdgpu_sriov_vf(adev))
1953 amdgpu_virt_request_full_gpu(adev, false);
1955 /* ungate SMC block first */
1956 r = amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_SMC,
1957 AMD_CG_STATE_UNGATE);
1959 DRM_ERROR("set_clockgating_state(ungate) SMC failed %d\n",r);
1962 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
1963 if (!adev->ip_blocks[i].status.valid)
1965 /* ungate blocks so that suspend can properly shut them down */
1966 if (i != AMD_IP_BLOCK_TYPE_SMC) {
1967 r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
1968 AMD_CG_STATE_UNGATE);
1970 DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
1971 adev->ip_blocks[i].version->funcs->name, r);
1974 /* XXX handle errors */
1975 r = adev->ip_blocks[i].version->funcs->suspend(adev);
1976 /* XXX handle errors */
1978 DRM_ERROR("suspend of IP block <%s> failed %d\n",
1979 adev->ip_blocks[i].version->funcs->name, r);
1983 if (amdgpu_sriov_vf(adev))
1984 amdgpu_virt_release_full_gpu(adev, false);
1989 static int amdgpu_sriov_reinit_early(struct amdgpu_device *adev)
1993 static enum amd_ip_block_type ip_order[] = {
1994 AMD_IP_BLOCK_TYPE_GMC,
1995 AMD_IP_BLOCK_TYPE_COMMON,
1996 AMD_IP_BLOCK_TYPE_IH,
1999 for (i = 0; i < ARRAY_SIZE(ip_order); i++) {
2001 struct amdgpu_ip_block *block;
2003 for (j = 0; j < adev->num_ip_blocks; j++) {
2004 block = &adev->ip_blocks[j];
2006 if (block->version->type != ip_order[i] ||
2007 !block->status.valid)
2010 r = block->version->funcs->hw_init(adev);
2011 DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed");
2018 static int amdgpu_sriov_reinit_late(struct amdgpu_device *adev)
2022 static enum amd_ip_block_type ip_order[] = {
2023 AMD_IP_BLOCK_TYPE_SMC,
2024 AMD_IP_BLOCK_TYPE_PSP,
2025 AMD_IP_BLOCK_TYPE_DCE,
2026 AMD_IP_BLOCK_TYPE_GFX,
2027 AMD_IP_BLOCK_TYPE_SDMA,
2028 AMD_IP_BLOCK_TYPE_UVD,
2029 AMD_IP_BLOCK_TYPE_VCE
2032 for (i = 0; i < ARRAY_SIZE(ip_order); i++) {
2034 struct amdgpu_ip_block *block;
2036 for (j = 0; j < adev->num_ip_blocks; j++) {
2037 block = &adev->ip_blocks[j];
2039 if (block->version->type != ip_order[i] ||
2040 !block->status.valid)
2043 r = block->version->funcs->hw_init(adev);
2044 DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed");
2051 static int amdgpu_resume_phase1(struct amdgpu_device *adev)
2055 for (i = 0; i < adev->num_ip_blocks; i++) {
2056 if (!adev->ip_blocks[i].status.valid)
2058 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
2059 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
2060 adev->ip_blocks[i].version->type ==
2061 AMD_IP_BLOCK_TYPE_IH) {
2062 r = adev->ip_blocks[i].version->funcs->resume(adev);
2064 DRM_ERROR("resume of IP block <%s> failed %d\n",
2065 adev->ip_blocks[i].version->funcs->name, r);
2074 static int amdgpu_resume_phase2(struct amdgpu_device *adev)
2078 for (i = 0; i < adev->num_ip_blocks; i++) {
2079 if (!adev->ip_blocks[i].status.valid)
2081 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
2082 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
2083 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH )
2085 r = adev->ip_blocks[i].version->funcs->resume(adev);
2087 DRM_ERROR("resume of IP block <%s> failed %d\n",
2088 adev->ip_blocks[i].version->funcs->name, r);
2096 static int amdgpu_resume(struct amdgpu_device *adev)
2100 r = amdgpu_resume_phase1(adev);
2103 r = amdgpu_resume_phase2(adev);
2108 static void amdgpu_device_detect_sriov_bios(struct amdgpu_device *adev)
2110 if (amdgpu_sriov_vf(adev)) {
2111 if (adev->is_atom_fw) {
2112 if (amdgpu_atomfirmware_gpu_supports_virtualization(adev))
2113 adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
2115 if (amdgpu_atombios_has_gpu_virtualization_table(adev))
2116 adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
2119 if (!(adev->virt.caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS))
2120 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_NO_VBIOS, 0, 0);
2124 bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type)
2126 switch (asic_type) {
2127 #if defined(CONFIG_DRM_AMD_DC)
2133 case CHIP_POLARIS11:
2134 case CHIP_POLARIS10:
2135 case CHIP_POLARIS12:
2138 #if defined(CONFIG_DRM_AMD_DC_PRE_VEGA)
2139 return amdgpu_dc != 0;
2143 return amdgpu_dc > 0;
2145 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
2148 return amdgpu_dc != 0;
2156 * amdgpu_device_has_dc_support - check if dc is supported
2158 * @adev: amdgpu_device_pointer
2160 * Returns true for supported, false for not supported
2162 bool amdgpu_device_has_dc_support(struct amdgpu_device *adev)
2164 if (amdgpu_sriov_vf(adev))
2167 return amdgpu_device_asic_has_dc_support(adev->asic_type);
2171 * amdgpu_device_init - initialize the driver
2173 * @adev: amdgpu_device pointer
2174 * @pdev: drm dev pointer
2175 * @pdev: pci dev pointer
2176 * @flags: driver flags
2178 * Initializes the driver info and hw (all asics).
2179 * Returns 0 for success or an error on failure.
2180 * Called at driver startup.
2182 int amdgpu_device_init(struct amdgpu_device *adev,
2183 struct drm_device *ddev,
2184 struct pci_dev *pdev,
2188 bool runtime = false;
2191 adev->shutdown = false;
2192 adev->dev = &pdev->dev;
2195 adev->flags = flags;
2196 adev->asic_type = flags & AMD_ASIC_MASK;
2197 adev->usec_timeout = AMDGPU_MAX_USEC_TIMEOUT;
2198 adev->mc.gart_size = 512 * 1024 * 1024;
2199 adev->accel_working = false;
2200 adev->num_rings = 0;
2201 adev->mman.buffer_funcs = NULL;
2202 adev->mman.buffer_funcs_ring = NULL;
2203 adev->vm_manager.vm_pte_funcs = NULL;
2204 adev->vm_manager.vm_pte_num_rings = 0;
2205 adev->gart.gart_funcs = NULL;
2206 adev->fence_context = dma_fence_context_alloc(AMDGPU_MAX_RINGS);
2207 bitmap_zero(adev->gfx.pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
2209 adev->smc_rreg = &amdgpu_invalid_rreg;
2210 adev->smc_wreg = &amdgpu_invalid_wreg;
2211 adev->pcie_rreg = &amdgpu_invalid_rreg;
2212 adev->pcie_wreg = &amdgpu_invalid_wreg;
2213 adev->pciep_rreg = &amdgpu_invalid_rreg;
2214 adev->pciep_wreg = &amdgpu_invalid_wreg;
2215 adev->uvd_ctx_rreg = &amdgpu_invalid_rreg;
2216 adev->uvd_ctx_wreg = &amdgpu_invalid_wreg;
2217 adev->didt_rreg = &amdgpu_invalid_rreg;
2218 adev->didt_wreg = &amdgpu_invalid_wreg;
2219 adev->gc_cac_rreg = &amdgpu_invalid_rreg;
2220 adev->gc_cac_wreg = &amdgpu_invalid_wreg;
2221 adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg;
2222 adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg;
2224 DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n",
2225 amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device,
2226 pdev->subsystem_vendor, pdev->subsystem_device, pdev->revision);
2228 /* mutex initialization are all done here so we
2229 * can recall function without having locking issues */
2230 atomic_set(&adev->irq.ih.lock, 0);
2231 mutex_init(&adev->firmware.mutex);
2232 mutex_init(&adev->pm.mutex);
2233 mutex_init(&adev->gfx.gpu_clock_mutex);
2234 mutex_init(&adev->srbm_mutex);
2235 mutex_init(&adev->gfx.pipe_reserve_mutex);
2236 mutex_init(&adev->grbm_idx_mutex);
2237 mutex_init(&adev->mn_lock);
2238 mutex_init(&adev->virt.vf_errors.lock);
2239 hash_init(adev->mn_hash);
2240 mutex_init(&adev->lock_reset);
2242 amdgpu_check_arguments(adev);
2244 spin_lock_init(&adev->mmio_idx_lock);
2245 spin_lock_init(&adev->smc_idx_lock);
2246 spin_lock_init(&adev->pcie_idx_lock);
2247 spin_lock_init(&adev->uvd_ctx_idx_lock);
2248 spin_lock_init(&adev->didt_idx_lock);
2249 spin_lock_init(&adev->gc_cac_idx_lock);
2250 spin_lock_init(&adev->se_cac_idx_lock);
2251 spin_lock_init(&adev->audio_endpt_idx_lock);
2252 spin_lock_init(&adev->mm_stats.lock);
2254 INIT_LIST_HEAD(&adev->shadow_list);
2255 mutex_init(&adev->shadow_list_lock);
2257 INIT_LIST_HEAD(&adev->ring_lru_list);
2258 spin_lock_init(&adev->ring_lru_list_lock);
2260 INIT_DELAYED_WORK(&adev->late_init_work, amdgpu_late_init_func_handler);
2262 /* Registers mapping */
2263 /* TODO: block userspace mapping of io register */
2264 if (adev->asic_type >= CHIP_BONAIRE) {
2265 adev->rmmio_base = pci_resource_start(adev->pdev, 5);
2266 adev->rmmio_size = pci_resource_len(adev->pdev, 5);
2268 adev->rmmio_base = pci_resource_start(adev->pdev, 2);
2269 adev->rmmio_size = pci_resource_len(adev->pdev, 2);
2272 adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
2273 if (adev->rmmio == NULL) {
2276 DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
2277 DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size);
2279 /* doorbell bar mapping */
2280 amdgpu_doorbell_init(adev);
2282 /* io port mapping */
2283 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
2284 if (pci_resource_flags(adev->pdev, i) & IORESOURCE_IO) {
2285 adev->rio_mem_size = pci_resource_len(adev->pdev, i);
2286 adev->rio_mem = pci_iomap(adev->pdev, i, adev->rio_mem_size);
2290 if (adev->rio_mem == NULL)
2291 DRM_INFO("PCI I/O BAR is not found.\n");
2293 /* early init functions */
2294 r = amdgpu_early_init(adev);
2298 /* if we have > 1 VGA cards, then disable the amdgpu VGA resources */
2299 /* this will fail for cards that aren't VGA class devices, just
2301 vga_client_register(adev->pdev, adev, NULL, amdgpu_vga_set_decode);
2303 if (amdgpu_runtime_pm == 1)
2305 if (amdgpu_device_is_px(ddev))
2307 if (!pci_is_thunderbolt_attached(adev->pdev))
2308 vga_switcheroo_register_client(adev->pdev,
2309 &amdgpu_switcheroo_ops, runtime);
2311 vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain);
2314 if (!amdgpu_get_bios(adev)) {
2319 r = amdgpu_atombios_init(adev);
2321 dev_err(adev->dev, "amdgpu_atombios_init failed\n");
2322 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL, 0, 0);
2326 /* detect if we are with an SRIOV vbios */
2327 amdgpu_device_detect_sriov_bios(adev);
2329 /* Post card if necessary */
2330 if (amdgpu_need_post(adev)) {
2332 dev_err(adev->dev, "no vBIOS found\n");
2336 DRM_INFO("GPU posting now...\n");
2337 r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
2339 dev_err(adev->dev, "gpu post error!\n");
2344 if (adev->is_atom_fw) {
2345 /* Initialize clocks */
2346 r = amdgpu_atomfirmware_get_clock_info(adev);
2348 dev_err(adev->dev, "amdgpu_atomfirmware_get_clock_info failed\n");
2349 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
2353 /* Initialize clocks */
2354 r = amdgpu_atombios_get_clock_info(adev);
2356 dev_err(adev->dev, "amdgpu_atombios_get_clock_info failed\n");
2357 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
2360 /* init i2c buses */
2361 if (!amdgpu_device_has_dc_support(adev))
2362 amdgpu_atombios_i2c_init(adev);
2366 r = amdgpu_fence_driver_init(adev);
2368 dev_err(adev->dev, "amdgpu_fence_driver_init failed\n");
2369 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_FENCE_INIT_FAIL, 0, 0);
2373 /* init the mode config */
2374 drm_mode_config_init(adev->ddev);
2376 r = amdgpu_init(adev);
2378 /* failed in exclusive mode due to timeout */
2379 if (amdgpu_sriov_vf(adev) &&
2380 !amdgpu_sriov_runtime(adev) &&
2381 amdgpu_virt_mmio_blocked(adev) &&
2382 !amdgpu_virt_wait_reset(adev)) {
2383 dev_err(adev->dev, "VF exclusive mode timeout\n");
2384 /* Don't send request since VF is inactive. */
2385 adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
2386 adev->virt.ops = NULL;
2390 dev_err(adev->dev, "amdgpu_init failed\n");
2391 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_INIT_FAIL, 0, 0);
2396 adev->accel_working = true;
2398 amdgpu_vm_check_compute_bug(adev);
2400 /* Initialize the buffer migration limit. */
2401 if (amdgpu_moverate >= 0)
2402 max_MBps = amdgpu_moverate;
2404 max_MBps = 8; /* Allow 8 MB/s. */
2405 /* Get a log2 for easy divisions. */
2406 adev->mm_stats.log2_max_MBps = ilog2(max(1u, max_MBps));
2408 r = amdgpu_ib_pool_init(adev);
2410 dev_err(adev->dev, "IB initialization failed (%d).\n", r);
2411 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_IB_INIT_FAIL, 0, r);
2415 r = amdgpu_ib_ring_tests(adev);
2417 DRM_ERROR("ib ring test failed (%d).\n", r);
2419 if (amdgpu_sriov_vf(adev))
2420 amdgpu_virt_init_data_exchange(adev);
2422 amdgpu_fbdev_init(adev);
2424 r = amdgpu_pm_sysfs_init(adev);
2426 DRM_ERROR("registering pm debugfs failed (%d).\n", r);
2428 r = amdgpu_gem_debugfs_init(adev);
2430 DRM_ERROR("registering gem debugfs failed (%d).\n", r);
2432 r = amdgpu_debugfs_regs_init(adev);
2434 DRM_ERROR("registering register debugfs failed (%d).\n", r);
2436 r = amdgpu_debugfs_test_ib_ring_init(adev);
2438 DRM_ERROR("registering register test ib ring debugfs failed (%d).\n", r);
2440 r = amdgpu_debugfs_firmware_init(adev);
2442 DRM_ERROR("registering firmware debugfs failed (%d).\n", r);
2444 r = amdgpu_debugfs_vbios_dump_init(adev);
2446 DRM_ERROR("Creating vbios dump debugfs failed (%d).\n", r);
2448 if ((amdgpu_testing & 1)) {
2449 if (adev->accel_working)
2450 amdgpu_test_moves(adev);
2452 DRM_INFO("amdgpu: acceleration disabled, skipping move tests\n");
2454 if (amdgpu_benchmarking) {
2455 if (adev->accel_working)
2456 amdgpu_benchmark(adev, amdgpu_benchmarking);
2458 DRM_INFO("amdgpu: acceleration disabled, skipping benchmarks\n");
2461 /* enable clockgating, etc. after ib tests, etc. since some blocks require
2462 * explicit gating rather than handling it automatically.
2464 r = amdgpu_late_init(adev);
2466 dev_err(adev->dev, "amdgpu_late_init failed\n");
2467 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_LATE_INIT_FAIL, 0, r);
2474 amdgpu_vf_error_trans_all(adev);
2476 vga_switcheroo_fini_domain_pm_ops(adev->dev);
2482 * amdgpu_device_fini - tear down the driver
2484 * @adev: amdgpu_device pointer
2486 * Tear down the driver info (all asics).
2487 * Called at driver shutdown.
2489 void amdgpu_device_fini(struct amdgpu_device *adev)
2493 DRM_INFO("amdgpu: finishing device.\n");
2494 adev->shutdown = true;
2495 if (adev->mode_info.mode_config_initialized)
2496 drm_crtc_force_disable_all(adev->ddev);
2497 /* evict vram memory */
2498 amdgpu_bo_evict_vram(adev);
2499 amdgpu_ib_pool_fini(adev);
2500 amdgpu_fence_driver_fini(adev);
2501 amdgpu_fbdev_fini(adev);
2502 r = amdgpu_fini(adev);
2503 if (adev->firmware.gpu_info_fw) {
2504 release_firmware(adev->firmware.gpu_info_fw);
2505 adev->firmware.gpu_info_fw = NULL;
2507 adev->accel_working = false;
2508 cancel_delayed_work_sync(&adev->late_init_work);
2509 /* free i2c buses */
2510 if (!amdgpu_device_has_dc_support(adev))
2511 amdgpu_i2c_fini(adev);
2512 amdgpu_atombios_fini(adev);
2515 if (!pci_is_thunderbolt_attached(adev->pdev))
2516 vga_switcheroo_unregister_client(adev->pdev);
2517 if (adev->flags & AMD_IS_PX)
2518 vga_switcheroo_fini_domain_pm_ops(adev->dev);
2519 vga_client_register(adev->pdev, NULL, NULL, NULL);
2521 pci_iounmap(adev->pdev, adev->rio_mem);
2522 adev->rio_mem = NULL;
2523 iounmap(adev->rmmio);
2525 amdgpu_doorbell_fini(adev);
2526 amdgpu_pm_sysfs_fini(adev);
2527 amdgpu_debugfs_regs_cleanup(adev);
2535 * amdgpu_device_suspend - initiate device suspend
2537 * @pdev: drm dev pointer
2538 * @state: suspend state
2540 * Puts the hw in the suspend state (all asics).
2541 * Returns 0 for success or an error on failure.
2542 * Called at driver suspend.
2544 int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
2546 struct amdgpu_device *adev;
2547 struct drm_crtc *crtc;
2548 struct drm_connector *connector;
2551 if (dev == NULL || dev->dev_private == NULL) {
2555 adev = dev->dev_private;
2557 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2560 drm_kms_helper_poll_disable(dev);
2562 if (!amdgpu_device_has_dc_support(adev)) {
2563 /* turn off display hw */
2564 drm_modeset_lock_all(dev);
2565 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2566 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
2568 drm_modeset_unlock_all(dev);
2571 amdgpu_amdkfd_suspend(adev);
2573 /* unpin the front buffers and cursors */
2574 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2575 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2576 struct amdgpu_framebuffer *rfb = to_amdgpu_framebuffer(crtc->primary->fb);
2577 struct amdgpu_bo *robj;
2579 if (amdgpu_crtc->cursor_bo) {
2580 struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
2581 r = amdgpu_bo_reserve(aobj, true);
2583 amdgpu_bo_unpin(aobj);
2584 amdgpu_bo_unreserve(aobj);
2588 if (rfb == NULL || rfb->obj == NULL) {
2591 robj = gem_to_amdgpu_bo(rfb->obj);
2592 /* don't unpin kernel fb objects */
2593 if (!amdgpu_fbdev_robj_is_fb(adev, robj)) {
2594 r = amdgpu_bo_reserve(robj, true);
2596 amdgpu_bo_unpin(robj);
2597 amdgpu_bo_unreserve(robj);
2601 /* evict vram memory */
2602 amdgpu_bo_evict_vram(adev);
2604 amdgpu_fence_driver_suspend(adev);
2606 r = amdgpu_suspend(adev);
2608 /* evict remaining vram memory
2609 * This second call to evict vram is to evict the gart page table
2612 amdgpu_bo_evict_vram(adev);
2614 amdgpu_atombios_scratch_regs_save(adev);
2615 pci_save_state(dev->pdev);
2617 /* Shut down the device */
2618 pci_disable_device(dev->pdev);
2619 pci_set_power_state(dev->pdev, PCI_D3hot);
2621 r = amdgpu_asic_reset(adev);
2623 DRM_ERROR("amdgpu asic reset failed\n");
2628 amdgpu_fbdev_set_suspend(adev, 1);
2635 * amdgpu_device_resume - initiate device resume
2637 * @pdev: drm dev pointer
2639 * Bring the hw back to operating state (all asics).
2640 * Returns 0 for success or an error on failure.
2641 * Called at driver resume.
2643 int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon)
2645 struct drm_connector *connector;
2646 struct amdgpu_device *adev = dev->dev_private;
2647 struct drm_crtc *crtc;
2650 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2657 pci_set_power_state(dev->pdev, PCI_D0);
2658 pci_restore_state(dev->pdev);
2659 r = pci_enable_device(dev->pdev);
2663 amdgpu_atombios_scratch_regs_restore(adev);
2666 if (amdgpu_need_post(adev)) {
2667 r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
2669 DRM_ERROR("amdgpu asic init failed\n");
2672 r = amdgpu_resume(adev);
2674 DRM_ERROR("amdgpu_resume failed (%d).\n", r);
2677 amdgpu_fence_driver_resume(adev);
2680 r = amdgpu_ib_ring_tests(adev);
2682 DRM_ERROR("ib ring test failed (%d).\n", r);
2685 r = amdgpu_late_init(adev);
2690 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2691 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2693 if (amdgpu_crtc->cursor_bo) {
2694 struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
2695 r = amdgpu_bo_reserve(aobj, true);
2697 r = amdgpu_bo_pin(aobj,
2698 AMDGPU_GEM_DOMAIN_VRAM,
2699 &amdgpu_crtc->cursor_addr);
2701 DRM_ERROR("Failed to pin cursor BO (%d)\n", r);
2702 amdgpu_bo_unreserve(aobj);
2706 r = amdgpu_amdkfd_resume(adev);
2710 /* blat the mode back in */
2712 if (!amdgpu_device_has_dc_support(adev)) {
2714 drm_helper_resume_force_mode(dev);
2716 /* turn on display hw */
2717 drm_modeset_lock_all(dev);
2718 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2719 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
2721 drm_modeset_unlock_all(dev);
2724 * There is no equivalent atomic helper to turn on
2725 * display, so we defined our own function for this,
2726 * once suspend resume is supported by the atomic
2727 * framework this will be reworked
2729 amdgpu_dm_display_resume(adev);
2733 drm_kms_helper_poll_enable(dev);
2736 * Most of the connector probing functions try to acquire runtime pm
2737 * refs to ensure that the GPU is powered on when connector polling is
2738 * performed. Since we're calling this from a runtime PM callback,
2739 * trying to acquire rpm refs will cause us to deadlock.
2741 * Since we're guaranteed to be holding the rpm lock, it's safe to
2742 * temporarily disable the rpm helpers so this doesn't deadlock us.
2745 dev->dev->power.disable_depth++;
2747 if (!amdgpu_device_has_dc_support(adev))
2748 drm_helper_hpd_irq_event(dev);
2750 drm_kms_helper_hotplug_event(dev);
2752 dev->dev->power.disable_depth--;
2756 amdgpu_fbdev_set_suspend(adev, 0);
2765 static bool amdgpu_check_soft_reset(struct amdgpu_device *adev)
2768 bool asic_hang = false;
2770 if (amdgpu_sriov_vf(adev))
2773 for (i = 0; i < adev->num_ip_blocks; i++) {
2774 if (!adev->ip_blocks[i].status.valid)
2776 if (adev->ip_blocks[i].version->funcs->check_soft_reset)
2777 adev->ip_blocks[i].status.hang =
2778 adev->ip_blocks[i].version->funcs->check_soft_reset(adev);
2779 if (adev->ip_blocks[i].status.hang) {
2780 DRM_INFO("IP block:%s is hung!\n", adev->ip_blocks[i].version->funcs->name);
2787 static int amdgpu_pre_soft_reset(struct amdgpu_device *adev)
2791 for (i = 0; i < adev->num_ip_blocks; i++) {
2792 if (!adev->ip_blocks[i].status.valid)
2794 if (adev->ip_blocks[i].status.hang &&
2795 adev->ip_blocks[i].version->funcs->pre_soft_reset) {
2796 r = adev->ip_blocks[i].version->funcs->pre_soft_reset(adev);
2805 static bool amdgpu_need_full_reset(struct amdgpu_device *adev)
2809 for (i = 0; i < adev->num_ip_blocks; i++) {
2810 if (!adev->ip_blocks[i].status.valid)
2812 if ((adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) ||
2813 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) ||
2814 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_ACP) ||
2815 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE) ||
2816 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP) {
2817 if (adev->ip_blocks[i].status.hang) {
2818 DRM_INFO("Some block need full reset!\n");
2826 static int amdgpu_soft_reset(struct amdgpu_device *adev)
2830 for (i = 0; i < adev->num_ip_blocks; i++) {
2831 if (!adev->ip_blocks[i].status.valid)
2833 if (adev->ip_blocks[i].status.hang &&
2834 adev->ip_blocks[i].version->funcs->soft_reset) {
2835 r = adev->ip_blocks[i].version->funcs->soft_reset(adev);
2844 static int amdgpu_post_soft_reset(struct amdgpu_device *adev)
2848 for (i = 0; i < adev->num_ip_blocks; i++) {
2849 if (!adev->ip_blocks[i].status.valid)
2851 if (adev->ip_blocks[i].status.hang &&
2852 adev->ip_blocks[i].version->funcs->post_soft_reset)
2853 r = adev->ip_blocks[i].version->funcs->post_soft_reset(adev);
2861 bool amdgpu_need_backup(struct amdgpu_device *adev)
2863 if (adev->flags & AMD_IS_APU)
2866 return amdgpu_lockup_timeout > 0 ? true : false;
2869 static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
2870 struct amdgpu_ring *ring,
2871 struct amdgpu_bo *bo,
2872 struct dma_fence **fence)
2880 r = amdgpu_bo_reserve(bo, true);
2883 domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
2884 /* if bo has been evicted, then no need to recover */
2885 if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
2886 r = amdgpu_bo_validate(bo->shadow);
2888 DRM_ERROR("bo validate failed!\n");
2892 r = amdgpu_bo_restore_from_shadow(adev, ring, bo,
2895 DRM_ERROR("recover page table failed!\n");
2900 amdgpu_bo_unreserve(bo);
2905 * amdgpu_reset - reset ASIC/GPU for bare-metal or passthrough
2907 * @adev: amdgpu device pointer
2908 * @reset_flags: output param tells caller the reset result
2910 * attempt to do soft-reset or full-reset and reinitialize Asic
2911 * return 0 means successed otherwise failed
2913 static int amdgpu_reset(struct amdgpu_device *adev, uint64_t* reset_flags)
2915 bool need_full_reset, vram_lost = 0;
2918 need_full_reset = amdgpu_need_full_reset(adev);
2920 if (!need_full_reset) {
2921 amdgpu_pre_soft_reset(adev);
2922 r = amdgpu_soft_reset(adev);
2923 amdgpu_post_soft_reset(adev);
2924 if (r || amdgpu_check_soft_reset(adev)) {
2925 DRM_INFO("soft reset failed, will fallback to full reset!\n");
2926 need_full_reset = true;
2931 if (need_full_reset) {
2932 r = amdgpu_suspend(adev);
2935 amdgpu_atombios_scratch_regs_save(adev);
2936 r = amdgpu_asic_reset(adev);
2937 amdgpu_atombios_scratch_regs_restore(adev);
2939 amdgpu_atom_asic_init(adev->mode_info.atom_context);
2942 dev_info(adev->dev, "GPU reset succeeded, trying to resume\n");
2943 r = amdgpu_resume_phase1(adev);
2947 vram_lost = amdgpu_check_vram_lost(adev);
2949 DRM_ERROR("VRAM is lost!\n");
2950 atomic_inc(&adev->vram_lost_counter);
2953 r = amdgpu_gtt_mgr_recover(
2954 &adev->mman.bdev.man[TTM_PL_TT]);
2958 r = amdgpu_resume_phase2(adev);
2963 amdgpu_fill_reset_magic(adev);
2969 amdgpu_irq_gpu_reset_resume_helper(adev);
2970 r = amdgpu_ib_ring_tests(adev);
2972 dev_err(adev->dev, "ib ring test failed (%d).\n", r);
2973 r = amdgpu_suspend(adev);
2974 need_full_reset = true;
2981 (*reset_flags) |= AMDGPU_RESET_INFO_VRAM_LOST;
2983 if (need_full_reset)
2984 (*reset_flags) |= AMDGPU_RESET_INFO_FULLRESET;
2991 * amdgpu_reset_sriov - reset ASIC for SR-IOV vf
2993 * @adev: amdgpu device pointer
2994 * @reset_flags: output param tells caller the reset result
2996 * do VF FLR and reinitialize Asic
2997 * return 0 means successed otherwise failed
2999 static int amdgpu_reset_sriov(struct amdgpu_device *adev, uint64_t *reset_flags, bool from_hypervisor)
3003 if (from_hypervisor)
3004 r = amdgpu_virt_request_full_gpu(adev, true);
3006 r = amdgpu_virt_reset_gpu(adev);
3010 /* Resume IP prior to SMC */
3011 r = amdgpu_sriov_reinit_early(adev);
3015 /* we need recover gart prior to run SMC/CP/SDMA resume */
3016 amdgpu_gtt_mgr_recover(&adev->mman.bdev.man[TTM_PL_TT]);
3018 /* now we are okay to resume SMC/CP/SDMA */
3019 r = amdgpu_sriov_reinit_late(adev);
3023 amdgpu_irq_gpu_reset_resume_helper(adev);
3024 r = amdgpu_ib_ring_tests(adev);
3026 dev_err(adev->dev, "[GPU_RESET] ib ring test failed (%d).\n", r);
3029 /* release full control of GPU after ib test */
3030 amdgpu_virt_release_full_gpu(adev, true);
3033 if (adev->virt.gim_feature & AMDGIM_FEATURE_GIM_FLR_VRAMLOST) {
3034 (*reset_flags) |= AMDGPU_RESET_INFO_VRAM_LOST;
3035 atomic_inc(&adev->vram_lost_counter);
3038 /* VF FLR or hotlink reset is always full-reset */
3039 (*reset_flags) |= AMDGPU_RESET_INFO_FULLRESET;
3046 * amdgpu_gpu_recover - reset the asic and recover scheduler
3048 * @adev: amdgpu device pointer
3049 * @job: which job trigger hang
3051 * Attempt to reset the GPU if it has hung (all asics).
3052 * Returns 0 for success or an error on failure.
3054 int amdgpu_gpu_recover(struct amdgpu_device *adev, struct amdgpu_job *job)
3056 struct drm_atomic_state *state = NULL;
3057 uint64_t reset_flags = 0;
3060 if (!amdgpu_check_soft_reset(adev)) {
3061 DRM_INFO("No hardware hang detected. Did some blocks stall?\n");
3065 dev_info(adev->dev, "GPU reset begin!\n");
3067 mutex_lock(&adev->lock_reset);
3068 atomic_inc(&adev->gpu_reset_counter);
3069 adev->in_gpu_reset = 1;
3072 resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
3073 /* store modesetting */
3074 if (amdgpu_device_has_dc_support(adev))
3075 state = drm_atomic_helper_suspend(adev->ddev);
3077 /* block scheduler */
3078 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
3079 struct amdgpu_ring *ring = adev->rings[i];
3081 if (!ring || !ring->sched.thread)
3084 /* only focus on the ring hit timeout if &job not NULL */
3085 if (job && job->ring->idx != i)
3088 kthread_park(ring->sched.thread);
3089 amd_sched_hw_job_reset(&ring->sched, &job->base);
3091 /* after all hw jobs are reset, hw fence is meaningless, so force_completion */
3092 amdgpu_fence_driver_force_completion(ring);
3095 if (amdgpu_sriov_vf(adev))
3096 r = amdgpu_reset_sriov(adev, &reset_flags, job ? false : true);
3098 r = amdgpu_reset(adev, &reset_flags);
3101 if (((reset_flags & AMDGPU_RESET_INFO_FULLRESET) && !(adev->flags & AMD_IS_APU)) ||
3102 (reset_flags & AMDGPU_RESET_INFO_VRAM_LOST)) {
3103 struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
3104 struct amdgpu_bo *bo, *tmp;
3105 struct dma_fence *fence = NULL, *next = NULL;
3107 DRM_INFO("recover vram bo from shadow\n");
3108 mutex_lock(&adev->shadow_list_lock);
3109 list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list) {
3111 amdgpu_recover_vram_from_shadow(adev, ring, bo, &next);
3113 r = dma_fence_wait(fence, false);
3115 WARN(r, "recovery from shadow isn't completed\n");
3120 dma_fence_put(fence);
3123 mutex_unlock(&adev->shadow_list_lock);
3125 r = dma_fence_wait(fence, false);
3127 WARN(r, "recovery from shadow isn't completed\n");
3129 dma_fence_put(fence);
3132 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
3133 struct amdgpu_ring *ring = adev->rings[i];
3135 if (!ring || !ring->sched.thread)
3138 /* only focus on the ring hit timeout if &job not NULL */
3139 if (job && job->ring->idx != i)
3142 amd_sched_job_recovery(&ring->sched);
3143 kthread_unpark(ring->sched.thread);
3146 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
3147 struct amdgpu_ring *ring = adev->rings[i];
3149 if (!ring || !ring->sched.thread)
3152 /* only focus on the ring hit timeout if &job not NULL */
3153 if (job && job->ring->idx != i)
3156 kthread_unpark(adev->rings[i]->sched.thread);
3160 if (amdgpu_device_has_dc_support(adev)) {
3161 if (drm_atomic_helper_resume(adev->ddev, state))
3162 dev_info(adev->dev, "drm resume failed:%d\n", r);
3163 amdgpu_dm_display_resume(adev);
3165 drm_helper_resume_force_mode(adev->ddev);
3168 ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched);
3171 /* bad news, how to tell it to userspace ? */
3172 dev_info(adev->dev, "GPU reset(%d) failed\n", atomic_read(&adev->gpu_reset_counter));
3173 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_GPU_RESET_FAIL, 0, r);
3175 dev_info(adev->dev, "GPU reset(%d) successed!\n",atomic_read(&adev->gpu_reset_counter));
3178 amdgpu_vf_error_trans_all(adev);
3179 adev->in_gpu_reset = 0;
3180 mutex_unlock(&adev->lock_reset);
3184 void amdgpu_get_pcie_info(struct amdgpu_device *adev)
3189 if (amdgpu_pcie_gen_cap)
3190 adev->pm.pcie_gen_mask = amdgpu_pcie_gen_cap;
3192 if (amdgpu_pcie_lane_cap)
3193 adev->pm.pcie_mlw_mask = amdgpu_pcie_lane_cap;
3195 /* covers APUs as well */
3196 if (pci_is_root_bus(adev->pdev->bus)) {
3197 if (adev->pm.pcie_gen_mask == 0)
3198 adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
3199 if (adev->pm.pcie_mlw_mask == 0)
3200 adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
3204 if (adev->pm.pcie_gen_mask == 0) {
3205 ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask);
3207 adev->pm.pcie_gen_mask = (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
3208 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
3209 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3);
3211 if (mask & DRM_PCIE_SPEED_25)
3212 adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1;
3213 if (mask & DRM_PCIE_SPEED_50)
3214 adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2;
3215 if (mask & DRM_PCIE_SPEED_80)
3216 adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3;
3218 adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
3221 if (adev->pm.pcie_mlw_mask == 0) {
3222 ret = drm_pcie_get_max_link_width(adev->ddev, &mask);
3226 adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 |
3227 CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
3228 CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
3229 CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
3230 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
3231 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
3232 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
3235 adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
3236 CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
3237 CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
3238 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
3239 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
3240 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
3243 adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
3244 CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
3245 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
3246 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
3247 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
3250 adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
3251 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
3252 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
3253 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
3256 adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
3257 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
3258 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
3261 adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
3262 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
3265 adev->pm.pcie_mlw_mask = CAIL_PCIE_LINK_WIDTH_SUPPORT_X1;
3271 adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
3279 int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
3280 const struct drm_info_list *files,
3285 for (i = 0; i < adev->debugfs_count; i++) {
3286 if (adev->debugfs[i].files == files) {
3287 /* Already registered */
3292 i = adev->debugfs_count + 1;
3293 if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) {
3294 DRM_ERROR("Reached maximum number of debugfs components.\n");
3295 DRM_ERROR("Report so we increase "
3296 "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n");
3299 adev->debugfs[adev->debugfs_count].files = files;
3300 adev->debugfs[adev->debugfs_count].num_files = nfiles;
3301 adev->debugfs_count = i;
3302 #if defined(CONFIG_DEBUG_FS)
3303 drm_debugfs_create_files(files, nfiles,
3304 adev->ddev->primary->debugfs_root,
3305 adev->ddev->primary);
3310 #if defined(CONFIG_DEBUG_FS)
3312 static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf,
3313 size_t size, loff_t *pos)
3315 struct amdgpu_device *adev = file_inode(f)->i_private;
3318 bool pm_pg_lock, use_bank;
3319 unsigned instance_bank, sh_bank, se_bank;
3321 if (size & 0x3 || *pos & 0x3)
3324 /* are we reading registers for which a PG lock is necessary? */
3325 pm_pg_lock = (*pos >> 23) & 1;
3327 if (*pos & (1ULL << 62)) {
3328 se_bank = (*pos & GENMASK_ULL(33, 24)) >> 24;
3329 sh_bank = (*pos & GENMASK_ULL(43, 34)) >> 34;
3330 instance_bank = (*pos & GENMASK_ULL(53, 44)) >> 44;
3332 if (se_bank == 0x3FF)
3333 se_bank = 0xFFFFFFFF;
3334 if (sh_bank == 0x3FF)
3335 sh_bank = 0xFFFFFFFF;
3336 if (instance_bank == 0x3FF)
3337 instance_bank = 0xFFFFFFFF;
3343 *pos &= (1UL << 22) - 1;
3346 if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) ||
3347 (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines))
3349 mutex_lock(&adev->grbm_idx_mutex);
3350 amdgpu_gfx_select_se_sh(adev, se_bank,
3351 sh_bank, instance_bank);
3355 mutex_lock(&adev->pm.mutex);
3360 if (*pos > adev->rmmio_size)
3363 value = RREG32(*pos >> 2);
3364 r = put_user(value, (uint32_t *)buf);
3378 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3379 mutex_unlock(&adev->grbm_idx_mutex);
3383 mutex_unlock(&adev->pm.mutex);
3388 static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf,
3389 size_t size, loff_t *pos)
3391 struct amdgpu_device *adev = file_inode(f)->i_private;
3394 bool pm_pg_lock, use_bank;
3395 unsigned instance_bank, sh_bank, se_bank;
3397 if (size & 0x3 || *pos & 0x3)
3400 /* are we reading registers for which a PG lock is necessary? */
3401 pm_pg_lock = (*pos >> 23) & 1;
3403 if (*pos & (1ULL << 62)) {
3404 se_bank = (*pos & GENMASK_ULL(33, 24)) >> 24;
3405 sh_bank = (*pos & GENMASK_ULL(43, 34)) >> 34;
3406 instance_bank = (*pos & GENMASK_ULL(53, 44)) >> 44;
3408 if (se_bank == 0x3FF)
3409 se_bank = 0xFFFFFFFF;
3410 if (sh_bank == 0x3FF)
3411 sh_bank = 0xFFFFFFFF;
3412 if (instance_bank == 0x3FF)
3413 instance_bank = 0xFFFFFFFF;
3419 *pos &= (1UL << 22) - 1;
3422 if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) ||
3423 (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines))
3425 mutex_lock(&adev->grbm_idx_mutex);
3426 amdgpu_gfx_select_se_sh(adev, se_bank,
3427 sh_bank, instance_bank);
3431 mutex_lock(&adev->pm.mutex);
3436 if (*pos > adev->rmmio_size)
3439 r = get_user(value, (uint32_t *)buf);
3443 WREG32(*pos >> 2, value);
3452 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3453 mutex_unlock(&adev->grbm_idx_mutex);
3457 mutex_unlock(&adev->pm.mutex);
3462 static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf,
3463 size_t size, loff_t *pos)
3465 struct amdgpu_device *adev = file_inode(f)->i_private;
3469 if (size & 0x3 || *pos & 0x3)
3475 value = RREG32_PCIE(*pos >> 2);
3476 r = put_user(value, (uint32_t *)buf);
3489 static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user *buf,
3490 size_t size, loff_t *pos)
3492 struct amdgpu_device *adev = file_inode(f)->i_private;
3496 if (size & 0x3 || *pos & 0x3)
3502 r = get_user(value, (uint32_t *)buf);
3506 WREG32_PCIE(*pos >> 2, value);
3517 static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf,
3518 size_t size, loff_t *pos)
3520 struct amdgpu_device *adev = file_inode(f)->i_private;
3524 if (size & 0x3 || *pos & 0x3)
3530 value = RREG32_DIDT(*pos >> 2);
3531 r = put_user(value, (uint32_t *)buf);
3544 static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user *buf,
3545 size_t size, loff_t *pos)
3547 struct amdgpu_device *adev = file_inode(f)->i_private;
3551 if (size & 0x3 || *pos & 0x3)
3557 r = get_user(value, (uint32_t *)buf);
3561 WREG32_DIDT(*pos >> 2, value);
3572 static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf,
3573 size_t size, loff_t *pos)
3575 struct amdgpu_device *adev = file_inode(f)->i_private;
3579 if (size & 0x3 || *pos & 0x3)
3585 value = RREG32_SMC(*pos);
3586 r = put_user(value, (uint32_t *)buf);
3599 static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *buf,
3600 size_t size, loff_t *pos)
3602 struct amdgpu_device *adev = file_inode(f)->i_private;
3606 if (size & 0x3 || *pos & 0x3)
3612 r = get_user(value, (uint32_t *)buf);
3616 WREG32_SMC(*pos, value);
3627 static ssize_t amdgpu_debugfs_gca_config_read(struct file *f, char __user *buf,
3628 size_t size, loff_t *pos)
3630 struct amdgpu_device *adev = file_inode(f)->i_private;
3633 uint32_t *config, no_regs = 0;
3635 if (size & 0x3 || *pos & 0x3)
3638 config = kmalloc_array(256, sizeof(*config), GFP_KERNEL);
3642 /* version, increment each time something is added */
3643 config[no_regs++] = 3;
3644 config[no_regs++] = adev->gfx.config.max_shader_engines;
3645 config[no_regs++] = adev->gfx.config.max_tile_pipes;
3646 config[no_regs++] = adev->gfx.config.max_cu_per_sh;
3647 config[no_regs++] = adev->gfx.config.max_sh_per_se;
3648 config[no_regs++] = adev->gfx.config.max_backends_per_se;
3649 config[no_regs++] = adev->gfx.config.max_texture_channel_caches;
3650 config[no_regs++] = adev->gfx.config.max_gprs;
3651 config[no_regs++] = adev->gfx.config.max_gs_threads;
3652 config[no_regs++] = adev->gfx.config.max_hw_contexts;
3653 config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_frontend;
3654 config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_backend;
3655 config[no_regs++] = adev->gfx.config.sc_hiz_tile_fifo_size;
3656 config[no_regs++] = adev->gfx.config.sc_earlyz_tile_fifo_size;
3657 config[no_regs++] = adev->gfx.config.num_tile_pipes;
3658 config[no_regs++] = adev->gfx.config.backend_enable_mask;
3659 config[no_regs++] = adev->gfx.config.mem_max_burst_length_bytes;
3660 config[no_regs++] = adev->gfx.config.mem_row_size_in_kb;
3661 config[no_regs++] = adev->gfx.config.shader_engine_tile_size;
3662 config[no_regs++] = adev->gfx.config.num_gpus;
3663 config[no_regs++] = adev->gfx.config.multi_gpu_tile_size;
3664 config[no_regs++] = adev->gfx.config.mc_arb_ramcfg;
3665 config[no_regs++] = adev->gfx.config.gb_addr_config;
3666 config[no_regs++] = adev->gfx.config.num_rbs;
3669 config[no_regs++] = adev->rev_id;
3670 config[no_regs++] = adev->pg_flags;
3671 config[no_regs++] = adev->cg_flags;
3674 config[no_regs++] = adev->family;
3675 config[no_regs++] = adev->external_rev_id;
3678 config[no_regs++] = adev->pdev->device;
3679 config[no_regs++] = adev->pdev->revision;
3680 config[no_regs++] = adev->pdev->subsystem_device;
3681 config[no_regs++] = adev->pdev->subsystem_vendor;
3683 while (size && (*pos < no_regs * 4)) {
3686 value = config[*pos >> 2];
3687 r = put_user(value, (uint32_t *)buf);
3703 static ssize_t amdgpu_debugfs_sensor_read(struct file *f, char __user *buf,
3704 size_t size, loff_t *pos)
3706 struct amdgpu_device *adev = file_inode(f)->i_private;
3707 int idx, x, outsize, r, valuesize;
3708 uint32_t values[16];
3710 if (size & 3 || *pos & 0x3)
3713 if (amdgpu_dpm == 0)
3716 /* convert offset to sensor number */
3719 valuesize = sizeof(values);
3720 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor)
3721 r = amdgpu_dpm_read_sensor(adev, idx, &values[0], &valuesize);
3725 if (size > valuesize)
3732 r = put_user(values[x++], (int32_t *)buf);
3739 return !r ? outsize : r;
3742 static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,
3743 size_t size, loff_t *pos)
3745 struct amdgpu_device *adev = f->f_inode->i_private;
3748 uint32_t offset, se, sh, cu, wave, simd, data[32];
3750 if (size & 3 || *pos & 3)
3754 offset = (*pos & GENMASK_ULL(6, 0));
3755 se = (*pos & GENMASK_ULL(14, 7)) >> 7;
3756 sh = (*pos & GENMASK_ULL(22, 15)) >> 15;
3757 cu = (*pos & GENMASK_ULL(30, 23)) >> 23;
3758 wave = (*pos & GENMASK_ULL(36, 31)) >> 31;
3759 simd = (*pos & GENMASK_ULL(44, 37)) >> 37;
3761 /* switch to the specific se/sh/cu */
3762 mutex_lock(&adev->grbm_idx_mutex);
3763 amdgpu_gfx_select_se_sh(adev, se, sh, cu);
3766 if (adev->gfx.funcs->read_wave_data)
3767 adev->gfx.funcs->read_wave_data(adev, simd, wave, data, &x);
3769 amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
3770 mutex_unlock(&adev->grbm_idx_mutex);
3775 while (size && (offset < x * 4)) {
3778 value = data[offset >> 2];
3779 r = put_user(value, (uint32_t *)buf);
3792 static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
3793 size_t size, loff_t *pos)
3795 struct amdgpu_device *adev = f->f_inode->i_private;
3798 uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
3800 if (size & 3 || *pos & 3)
3804 offset = *pos & GENMASK_ULL(11, 0);
3805 se = (*pos & GENMASK_ULL(19, 12)) >> 12;
3806 sh = (*pos & GENMASK_ULL(27, 20)) >> 20;
3807 cu = (*pos & GENMASK_ULL(35, 28)) >> 28;
3808 wave = (*pos & GENMASK_ULL(43, 36)) >> 36;
3809 simd = (*pos & GENMASK_ULL(51, 44)) >> 44;
3810 thread = (*pos & GENMASK_ULL(59, 52)) >> 52;
3811 bank = (*pos & GENMASK_ULL(61, 60)) >> 60;
3813 data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);
3817 /* switch to the specific se/sh/cu */
3818 mutex_lock(&adev->grbm_idx_mutex);
3819 amdgpu_gfx_select_se_sh(adev, se, sh, cu);
3822 if (adev->gfx.funcs->read_wave_vgprs)
3823 adev->gfx.funcs->read_wave_vgprs(adev, simd, wave, thread, offset, size>>2, data);
3825 if (adev->gfx.funcs->read_wave_sgprs)
3826 adev->gfx.funcs->read_wave_sgprs(adev, simd, wave, offset, size>>2, data);
3829 amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
3830 mutex_unlock(&adev->grbm_idx_mutex);
3835 value = data[offset++];
3836 r = put_user(value, (uint32_t *)buf);
3852 static const struct file_operations amdgpu_debugfs_regs_fops = {
3853 .owner = THIS_MODULE,
3854 .read = amdgpu_debugfs_regs_read,
3855 .write = amdgpu_debugfs_regs_write,
3856 .llseek = default_llseek
3858 static const struct file_operations amdgpu_debugfs_regs_didt_fops = {
3859 .owner = THIS_MODULE,
3860 .read = amdgpu_debugfs_regs_didt_read,
3861 .write = amdgpu_debugfs_regs_didt_write,
3862 .llseek = default_llseek
3864 static const struct file_operations amdgpu_debugfs_regs_pcie_fops = {
3865 .owner = THIS_MODULE,
3866 .read = amdgpu_debugfs_regs_pcie_read,
3867 .write = amdgpu_debugfs_regs_pcie_write,
3868 .llseek = default_llseek
3870 static const struct file_operations amdgpu_debugfs_regs_smc_fops = {
3871 .owner = THIS_MODULE,
3872 .read = amdgpu_debugfs_regs_smc_read,
3873 .write = amdgpu_debugfs_regs_smc_write,
3874 .llseek = default_llseek
3877 static const struct file_operations amdgpu_debugfs_gca_config_fops = {
3878 .owner = THIS_MODULE,
3879 .read = amdgpu_debugfs_gca_config_read,
3880 .llseek = default_llseek
3883 static const struct file_operations amdgpu_debugfs_sensors_fops = {
3884 .owner = THIS_MODULE,
3885 .read = amdgpu_debugfs_sensor_read,
3886 .llseek = default_llseek
3889 static const struct file_operations amdgpu_debugfs_wave_fops = {
3890 .owner = THIS_MODULE,
3891 .read = amdgpu_debugfs_wave_read,
3892 .llseek = default_llseek
3894 static const struct file_operations amdgpu_debugfs_gpr_fops = {
3895 .owner = THIS_MODULE,
3896 .read = amdgpu_debugfs_gpr_read,
3897 .llseek = default_llseek
3900 static const struct file_operations *debugfs_regs[] = {
3901 &amdgpu_debugfs_regs_fops,
3902 &amdgpu_debugfs_regs_didt_fops,
3903 &amdgpu_debugfs_regs_pcie_fops,
3904 &amdgpu_debugfs_regs_smc_fops,
3905 &amdgpu_debugfs_gca_config_fops,
3906 &amdgpu_debugfs_sensors_fops,
3907 &amdgpu_debugfs_wave_fops,
3908 &amdgpu_debugfs_gpr_fops,
3911 static const char *debugfs_regs_names[] = {
3916 "amdgpu_gca_config",
3922 static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
3924 struct drm_minor *minor = adev->ddev->primary;
3925 struct dentry *ent, *root = minor->debugfs_root;
3928 for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
3929 ent = debugfs_create_file(debugfs_regs_names[i],
3930 S_IFREG | S_IRUGO, root,
3931 adev, debugfs_regs[i]);
3933 for (j = 0; j < i; j++) {
3934 debugfs_remove(adev->debugfs_regs[i]);
3935 adev->debugfs_regs[i] = NULL;
3937 return PTR_ERR(ent);
3941 i_size_write(ent->d_inode, adev->rmmio_size);
3942 adev->debugfs_regs[i] = ent;
3948 static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev)
3952 for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
3953 if (adev->debugfs_regs[i]) {
3954 debugfs_remove(adev->debugfs_regs[i]);
3955 adev->debugfs_regs[i] = NULL;
3960 static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
3962 struct drm_info_node *node = (struct drm_info_node *) m->private;
3963 struct drm_device *dev = node->minor->dev;
3964 struct amdgpu_device *adev = dev->dev_private;
3967 /* hold on the scheduler */
3968 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
3969 struct amdgpu_ring *ring = adev->rings[i];
3971 if (!ring || !ring->sched.thread)
3973 kthread_park(ring->sched.thread);
3976 seq_printf(m, "run ib test:\n");
3977 r = amdgpu_ib_ring_tests(adev);
3979 seq_printf(m, "ib ring tests failed (%d).\n", r);
3981 seq_printf(m, "ib ring tests passed.\n");
3983 /* go on the scheduler */
3984 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
3985 struct amdgpu_ring *ring = adev->rings[i];
3987 if (!ring || !ring->sched.thread)
3989 kthread_unpark(ring->sched.thread);
3995 static const struct drm_info_list amdgpu_debugfs_test_ib_ring_list[] = {
3996 {"amdgpu_test_ib", &amdgpu_debugfs_test_ib}
3999 static int amdgpu_debugfs_test_ib_ring_init(struct amdgpu_device *adev)
4001 return amdgpu_debugfs_add_files(adev,
4002 amdgpu_debugfs_test_ib_ring_list, 1);
4005 int amdgpu_debugfs_init(struct drm_minor *minor)
4010 static int amdgpu_debugfs_get_vbios_dump(struct seq_file *m, void *data)
4012 struct drm_info_node *node = (struct drm_info_node *) m->private;
4013 struct drm_device *dev = node->minor->dev;
4014 struct amdgpu_device *adev = dev->dev_private;
4016 seq_write(m, adev->bios, adev->bios_size);
4020 static const struct drm_info_list amdgpu_vbios_dump_list[] = {
4022 amdgpu_debugfs_get_vbios_dump,
4026 static int amdgpu_debugfs_vbios_dump_init(struct amdgpu_device *adev)
4028 return amdgpu_debugfs_add_files(adev,
4029 amdgpu_vbios_dump_list, 1);
4032 static int amdgpu_debugfs_test_ib_ring_init(struct amdgpu_device *adev)
4036 static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
4040 static int amdgpu_debugfs_vbios_dump_init(struct amdgpu_device *adev)
4044 static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev) { }