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/power_supply.h>
29 #include <linux/kthread.h>
30 #include <linux/module.h>
31 #include <linux/console.h>
32 #include <linux/slab.h>
34 #include <drm/drm_atomic_helper.h>
35 #include <drm/drm_probe_helper.h>
36 #include <drm/amdgpu_drm.h>
37 #include <linux/vgaarb.h>
38 #include <linux/vga_switcheroo.h>
39 #include <linux/efi.h>
41 #include "amdgpu_trace.h"
42 #include "amdgpu_i2c.h"
44 #include "amdgpu_atombios.h"
45 #include "amdgpu_atomfirmware.h"
47 #ifdef CONFIG_DRM_AMDGPU_SI
50 #ifdef CONFIG_DRM_AMDGPU_CIK
56 #include "bif/bif_4_1_d.h"
57 #include <linux/pci.h>
58 #include <linux/firmware.h>
59 #include "amdgpu_vf_error.h"
61 #include "amdgpu_amdkfd.h"
62 #include "amdgpu_pm.h"
64 #include "amdgpu_xgmi.h"
65 #include "amdgpu_ras.h"
66 #include "amdgpu_pmu.h"
68 #include <linux/suspend.h>
69 #include <drm/task_barrier.h>
71 MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin");
72 MODULE_FIRMWARE("amdgpu/vega12_gpu_info.bin");
73 MODULE_FIRMWARE("amdgpu/raven_gpu_info.bin");
74 MODULE_FIRMWARE("amdgpu/picasso_gpu_info.bin");
75 MODULE_FIRMWARE("amdgpu/raven2_gpu_info.bin");
76 MODULE_FIRMWARE("amdgpu/arcturus_gpu_info.bin");
77 MODULE_FIRMWARE("amdgpu/renoir_gpu_info.bin");
78 MODULE_FIRMWARE("amdgpu/navi10_gpu_info.bin");
79 MODULE_FIRMWARE("amdgpu/navi14_gpu_info.bin");
80 MODULE_FIRMWARE("amdgpu/navi12_gpu_info.bin");
82 #define AMDGPU_RESUME_MS 2000
84 const char *amdgpu_asic_name
[] = {
117 * DOC: pcie_replay_count
119 * The amdgpu driver provides a sysfs API for reporting the total number
120 * of PCIe replays (NAKs)
121 * The file pcie_replay_count is used for this and returns the total
122 * number of replays as a sum of the NAKs generated and NAKs received
125 static ssize_t
amdgpu_device_get_pcie_replay_count(struct device
*dev
,
126 struct device_attribute
*attr
, char *buf
)
128 struct drm_device
*ddev
= dev_get_drvdata(dev
);
129 struct amdgpu_device
*adev
= ddev
->dev_private
;
130 uint64_t cnt
= amdgpu_asic_get_pcie_replay_count(adev
);
132 return snprintf(buf
, PAGE_SIZE
, "%llu\n", cnt
);
135 static DEVICE_ATTR(pcie_replay_count
, S_IRUGO
,
136 amdgpu_device_get_pcie_replay_count
, NULL
);
138 static void amdgpu_device_get_pcie_info(struct amdgpu_device
*adev
);
141 * amdgpu_device_supports_boco - Is the device a dGPU with HG/PX power control
143 * @dev: drm_device pointer
145 * Returns true if the device is a dGPU with HG/PX power control,
146 * otherwise return false.
148 bool amdgpu_device_supports_boco(struct drm_device
*dev
)
150 struct amdgpu_device
*adev
= dev
->dev_private
;
152 if (adev
->flags
& AMD_IS_PX
)
158 * amdgpu_device_supports_baco - Does the device support BACO
160 * @dev: drm_device pointer
162 * Returns true if the device supporte BACO,
163 * otherwise return false.
165 bool amdgpu_device_supports_baco(struct drm_device
*dev
)
167 struct amdgpu_device
*adev
= dev
->dev_private
;
169 return amdgpu_asic_supports_baco(adev
);
173 * VRAM access helper functions.
175 * amdgpu_device_vram_access - read/write a buffer in vram
177 * @adev: amdgpu_device pointer
178 * @pos: offset of the buffer in vram
179 * @buf: virtual address of the buffer in system memory
180 * @size: read/write size, sizeof(@buf) must > @size
181 * @write: true - write to vram, otherwise - read from vram
183 void amdgpu_device_vram_access(struct amdgpu_device
*adev
, loff_t pos
,
184 uint32_t *buf
, size_t size
, bool write
)
192 last
= min(pos
+ size
, adev
->gmc
.visible_vram_size
);
194 void __iomem
*addr
= adev
->mman
.aper_base_kaddr
+ pos
;
195 size_t count
= last
- pos
;
198 memcpy_toio(addr
, buf
, count
);
200 amdgpu_asic_flush_hdp(adev
, NULL
);
202 amdgpu_asic_invalidate_hdp(adev
, NULL
);
204 memcpy_fromio(buf
, addr
, count
);
216 spin_lock_irqsave(&adev
->mmio_idx_lock
, flags
);
217 for (last
= pos
+ size
; pos
< last
; pos
+= 4) {
218 uint32_t tmp
= pos
>> 31;
220 WREG32_NO_KIQ(mmMM_INDEX
, ((uint32_t)pos
) | 0x80000000);
222 WREG32_NO_KIQ(mmMM_INDEX_HI
, tmp
);
226 WREG32_NO_KIQ(mmMM_DATA
, *buf
++);
228 *buf
++ = RREG32_NO_KIQ(mmMM_DATA
);
230 spin_unlock_irqrestore(&adev
->mmio_idx_lock
, flags
);
234 * MMIO register access helper functions.
237 * amdgpu_mm_rreg - read a memory mapped IO register
239 * @adev: amdgpu_device pointer
240 * @reg: dword aligned register offset
241 * @acc_flags: access flags which require special behavior
243 * Returns the 32 bit value from the offset specified.
245 uint32_t amdgpu_mm_rreg(struct amdgpu_device
*adev
, uint32_t reg
,
250 if ((acc_flags
& AMDGPU_REGS_KIQ
) || (!(acc_flags
& AMDGPU_REGS_NO_KIQ
) && amdgpu_sriov_runtime(adev
)))
251 return amdgpu_kiq_rreg(adev
, reg
);
253 if ((reg
* 4) < adev
->rmmio_size
&& !(acc_flags
& AMDGPU_REGS_IDX
))
254 ret
= readl(((void __iomem
*)adev
->rmmio
) + (reg
* 4));
258 spin_lock_irqsave(&adev
->mmio_idx_lock
, flags
);
259 writel((reg
* 4), ((void __iomem
*)adev
->rmmio
) + (mmMM_INDEX
* 4));
260 ret
= readl(((void __iomem
*)adev
->rmmio
) + (mmMM_DATA
* 4));
261 spin_unlock_irqrestore(&adev
->mmio_idx_lock
, flags
);
263 trace_amdgpu_mm_rreg(adev
->pdev
->device
, reg
, ret
);
268 * MMIO register read with bytes helper functions
269 * @offset:bytes offset from MMIO start
274 * amdgpu_mm_rreg8 - read a memory mapped IO register
276 * @adev: amdgpu_device pointer
277 * @offset: byte aligned register offset
279 * Returns the 8 bit value from the offset specified.
281 uint8_t amdgpu_mm_rreg8(struct amdgpu_device
*adev
, uint32_t offset
) {
282 if (offset
< adev
->rmmio_size
)
283 return (readb(adev
->rmmio
+ offset
));
288 * MMIO register write with bytes helper functions
289 * @offset:bytes offset from MMIO start
290 * @value: the value want to be written to the register
294 * amdgpu_mm_wreg8 - read a memory mapped IO register
296 * @adev: amdgpu_device pointer
297 * @offset: byte aligned register offset
298 * @value: 8 bit value to write
300 * Writes the value specified to the offset specified.
302 void amdgpu_mm_wreg8(struct amdgpu_device
*adev
, uint32_t offset
, uint8_t value
) {
303 if (offset
< adev
->rmmio_size
)
304 writeb(value
, adev
->rmmio
+ offset
);
309 void static inline amdgpu_mm_wreg_mmio(struct amdgpu_device
*adev
, uint32_t reg
, uint32_t v
, uint32_t acc_flags
)
311 trace_amdgpu_mm_wreg(adev
->pdev
->device
, reg
, v
);
313 if ((reg
* 4) < adev
->rmmio_size
&& !(acc_flags
& AMDGPU_REGS_IDX
))
314 writel(v
, ((void __iomem
*)adev
->rmmio
) + (reg
* 4));
318 spin_lock_irqsave(&adev
->mmio_idx_lock
, flags
);
319 writel((reg
* 4), ((void __iomem
*)adev
->rmmio
) + (mmMM_INDEX
* 4));
320 writel(v
, ((void __iomem
*)adev
->rmmio
) + (mmMM_DATA
* 4));
321 spin_unlock_irqrestore(&adev
->mmio_idx_lock
, flags
);
324 if (adev
->asic_type
>= CHIP_VEGA10
&& reg
== 1 && adev
->last_mm_index
== 0x5702C) {
330 * amdgpu_mm_wreg - write to a memory mapped IO register
332 * @adev: amdgpu_device pointer
333 * @reg: dword aligned register offset
334 * @v: 32 bit value to write to the register
335 * @acc_flags: access flags which require special behavior
337 * Writes the value specified to the offset specified.
339 void amdgpu_mm_wreg(struct amdgpu_device
*adev
, uint32_t reg
, uint32_t v
,
342 if (adev
->asic_type
>= CHIP_VEGA10
&& reg
== 0) {
343 adev
->last_mm_index
= v
;
346 if ((acc_flags
& AMDGPU_REGS_KIQ
) || (!(acc_flags
& AMDGPU_REGS_NO_KIQ
) && amdgpu_sriov_runtime(adev
)))
347 return amdgpu_kiq_wreg(adev
, reg
, v
);
349 amdgpu_mm_wreg_mmio(adev
, reg
, v
, acc_flags
);
353 * amdgpu_mm_wreg_mmio_rlc - write register either with mmio or with RLC path if in range
355 * this function is invoked only the debugfs register access
357 void amdgpu_mm_wreg_mmio_rlc(struct amdgpu_device
*adev
, uint32_t reg
, uint32_t v
,
360 if (amdgpu_sriov_fullaccess(adev
) &&
361 adev
->gfx
.rlc
.funcs
&&
362 adev
->gfx
.rlc
.funcs
->is_rlcg_access_range
) {
364 if (adev
->gfx
.rlc
.funcs
->is_rlcg_access_range(adev
, reg
))
365 return adev
->gfx
.rlc
.funcs
->rlcg_wreg(adev
, reg
, v
);
368 amdgpu_mm_wreg_mmio(adev
, reg
, v
, acc_flags
);
372 * amdgpu_io_rreg - read an IO register
374 * @adev: amdgpu_device pointer
375 * @reg: dword aligned register offset
377 * Returns the 32 bit value from the offset specified.
379 u32
amdgpu_io_rreg(struct amdgpu_device
*adev
, u32 reg
)
381 if ((reg
* 4) < adev
->rio_mem_size
)
382 return ioread32(adev
->rio_mem
+ (reg
* 4));
384 iowrite32((reg
* 4), adev
->rio_mem
+ (mmMM_INDEX
* 4));
385 return ioread32(adev
->rio_mem
+ (mmMM_DATA
* 4));
390 * amdgpu_io_wreg - write to an IO register
392 * @adev: amdgpu_device pointer
393 * @reg: dword aligned register offset
394 * @v: 32 bit value to write to the register
396 * Writes the value specified to the offset specified.
398 void amdgpu_io_wreg(struct amdgpu_device
*adev
, u32 reg
, u32 v
)
400 if (adev
->asic_type
>= CHIP_VEGA10
&& reg
== 0) {
401 adev
->last_mm_index
= v
;
404 if ((reg
* 4) < adev
->rio_mem_size
)
405 iowrite32(v
, adev
->rio_mem
+ (reg
* 4));
407 iowrite32((reg
* 4), adev
->rio_mem
+ (mmMM_INDEX
* 4));
408 iowrite32(v
, adev
->rio_mem
+ (mmMM_DATA
* 4));
411 if (adev
->asic_type
>= CHIP_VEGA10
&& reg
== 1 && adev
->last_mm_index
== 0x5702C) {
417 * amdgpu_mm_rdoorbell - read a doorbell dword
419 * @adev: amdgpu_device pointer
420 * @index: doorbell index
422 * Returns the value in the doorbell aperture at the
423 * requested doorbell index (CIK).
425 u32
amdgpu_mm_rdoorbell(struct amdgpu_device
*adev
, u32 index
)
427 if (index
< adev
->doorbell
.num_doorbells
) {
428 return readl(adev
->doorbell
.ptr
+ index
);
430 DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index
);
436 * amdgpu_mm_wdoorbell - write a doorbell dword
438 * @adev: amdgpu_device pointer
439 * @index: doorbell index
442 * Writes @v to the doorbell aperture at the
443 * requested doorbell index (CIK).
445 void amdgpu_mm_wdoorbell(struct amdgpu_device
*adev
, u32 index
, u32 v
)
447 if (index
< adev
->doorbell
.num_doorbells
) {
448 writel(v
, adev
->doorbell
.ptr
+ index
);
450 DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index
);
455 * amdgpu_mm_rdoorbell64 - read a doorbell Qword
457 * @adev: amdgpu_device pointer
458 * @index: doorbell index
460 * Returns the value in the doorbell aperture at the
461 * requested doorbell index (VEGA10+).
463 u64
amdgpu_mm_rdoorbell64(struct amdgpu_device
*adev
, u32 index
)
465 if (index
< adev
->doorbell
.num_doorbells
) {
466 return atomic64_read((atomic64_t
*)(adev
->doorbell
.ptr
+ index
));
468 DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index
);
474 * amdgpu_mm_wdoorbell64 - write a doorbell Qword
476 * @adev: amdgpu_device pointer
477 * @index: doorbell index
480 * Writes @v to the doorbell aperture at the
481 * requested doorbell index (VEGA10+).
483 void amdgpu_mm_wdoorbell64(struct amdgpu_device
*adev
, u32 index
, u64 v
)
485 if (index
< adev
->doorbell
.num_doorbells
) {
486 atomic64_set((atomic64_t
*)(adev
->doorbell
.ptr
+ index
), v
);
488 DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index
);
493 * amdgpu_invalid_rreg - dummy reg read function
495 * @adev: amdgpu device pointer
496 * @reg: offset of register
498 * Dummy register read function. Used for register blocks
499 * that certain asics don't have (all asics).
500 * Returns the value in the register.
502 static uint32_t amdgpu_invalid_rreg(struct amdgpu_device
*adev
, uint32_t reg
)
504 DRM_ERROR("Invalid callback to read register 0x%04X\n", reg
);
510 * amdgpu_invalid_wreg - dummy reg write function
512 * @adev: amdgpu device pointer
513 * @reg: offset of register
514 * @v: value to write to the register
516 * Dummy register read function. Used for register blocks
517 * that certain asics don't have (all asics).
519 static void amdgpu_invalid_wreg(struct amdgpu_device
*adev
, uint32_t reg
, uint32_t v
)
521 DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n",
527 * amdgpu_invalid_rreg64 - dummy 64 bit reg read function
529 * @adev: amdgpu device pointer
530 * @reg: offset of register
532 * Dummy register read function. Used for register blocks
533 * that certain asics don't have (all asics).
534 * Returns the value in the register.
536 static uint64_t amdgpu_invalid_rreg64(struct amdgpu_device
*adev
, uint32_t reg
)
538 DRM_ERROR("Invalid callback to read 64 bit register 0x%04X\n", reg
);
544 * amdgpu_invalid_wreg64 - dummy reg write function
546 * @adev: amdgpu device pointer
547 * @reg: offset of register
548 * @v: value to write to the register
550 * Dummy register read function. Used for register blocks
551 * that certain asics don't have (all asics).
553 static void amdgpu_invalid_wreg64(struct amdgpu_device
*adev
, uint32_t reg
, uint64_t v
)
555 DRM_ERROR("Invalid callback to write 64 bit register 0x%04X with 0x%08llX\n",
561 * amdgpu_block_invalid_rreg - dummy reg read function
563 * @adev: amdgpu device pointer
564 * @block: offset of instance
565 * @reg: offset of register
567 * Dummy register read function. Used for register blocks
568 * that certain asics don't have (all asics).
569 * Returns the value in the register.
571 static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device
*adev
,
572 uint32_t block
, uint32_t reg
)
574 DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n",
581 * amdgpu_block_invalid_wreg - dummy reg write function
583 * @adev: amdgpu device pointer
584 * @block: offset of instance
585 * @reg: offset of register
586 * @v: value to write to the register
588 * Dummy register read function. Used for register blocks
589 * that certain asics don't have (all asics).
591 static void amdgpu_block_invalid_wreg(struct amdgpu_device
*adev
,
593 uint32_t reg
, uint32_t v
)
595 DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n",
601 * amdgpu_device_vram_scratch_init - allocate the VRAM scratch page
603 * @adev: amdgpu device pointer
605 * Allocates a scratch page of VRAM for use by various things in the
608 static int amdgpu_device_vram_scratch_init(struct amdgpu_device
*adev
)
610 return amdgpu_bo_create_kernel(adev
, AMDGPU_GPU_PAGE_SIZE
,
611 PAGE_SIZE
, AMDGPU_GEM_DOMAIN_VRAM
,
612 &adev
->vram_scratch
.robj
,
613 &adev
->vram_scratch
.gpu_addr
,
614 (void **)&adev
->vram_scratch
.ptr
);
618 * amdgpu_device_vram_scratch_fini - Free the VRAM scratch page
620 * @adev: amdgpu device pointer
622 * Frees the VRAM scratch page.
624 static void amdgpu_device_vram_scratch_fini(struct amdgpu_device
*adev
)
626 amdgpu_bo_free_kernel(&adev
->vram_scratch
.robj
, NULL
, NULL
);
630 * amdgpu_device_program_register_sequence - program an array of registers.
632 * @adev: amdgpu_device pointer
633 * @registers: pointer to the register array
634 * @array_size: size of the register array
636 * Programs an array or registers with and and or masks.
637 * This is a helper for setting golden registers.
639 void amdgpu_device_program_register_sequence(struct amdgpu_device
*adev
,
640 const u32
*registers
,
641 const u32 array_size
)
643 u32 tmp
, reg
, and_mask
, or_mask
;
649 for (i
= 0; i
< array_size
; i
+=3) {
650 reg
= registers
[i
+ 0];
651 and_mask
= registers
[i
+ 1];
652 or_mask
= registers
[i
+ 2];
654 if (and_mask
== 0xffffffff) {
659 if (adev
->family
>= AMDGPU_FAMILY_AI
)
660 tmp
|= (or_mask
& and_mask
);
669 * amdgpu_device_pci_config_reset - reset the GPU
671 * @adev: amdgpu_device pointer
673 * Resets the GPU using the pci config reset sequence.
674 * Only applicable to asics prior to vega10.
676 void amdgpu_device_pci_config_reset(struct amdgpu_device
*adev
)
678 pci_write_config_dword(adev
->pdev
, 0x7c, AMDGPU_ASIC_RESET_DATA
);
682 * GPU doorbell aperture helpers function.
685 * amdgpu_device_doorbell_init - Init doorbell driver information.
687 * @adev: amdgpu_device pointer
689 * Init doorbell driver information (CIK)
690 * Returns 0 on success, error on failure.
692 static int amdgpu_device_doorbell_init(struct amdgpu_device
*adev
)
695 /* No doorbell on SI hardware generation */
696 if (adev
->asic_type
< CHIP_BONAIRE
) {
697 adev
->doorbell
.base
= 0;
698 adev
->doorbell
.size
= 0;
699 adev
->doorbell
.num_doorbells
= 0;
700 adev
->doorbell
.ptr
= NULL
;
704 if (pci_resource_flags(adev
->pdev
, 2) & IORESOURCE_UNSET
)
707 amdgpu_asic_init_doorbell_index(adev
);
709 /* doorbell bar mapping */
710 adev
->doorbell
.base
= pci_resource_start(adev
->pdev
, 2);
711 adev
->doorbell
.size
= pci_resource_len(adev
->pdev
, 2);
713 adev
->doorbell
.num_doorbells
= min_t(u32
, adev
->doorbell
.size
/ sizeof(u32
),
714 adev
->doorbell_index
.max_assignment
+1);
715 if (adev
->doorbell
.num_doorbells
== 0)
718 /* For Vega, reserve and map two pages on doorbell BAR since SDMA
719 * paging queue doorbell use the second page. The
720 * AMDGPU_DOORBELL64_MAX_ASSIGNMENT definition assumes all the
721 * doorbells are in the first page. So with paging queue enabled,
722 * the max num_doorbells should + 1 page (0x400 in dword)
724 if (adev
->asic_type
>= CHIP_VEGA10
)
725 adev
->doorbell
.num_doorbells
+= 0x400;
727 adev
->doorbell
.ptr
= ioremap(adev
->doorbell
.base
,
728 adev
->doorbell
.num_doorbells
*
730 if (adev
->doorbell
.ptr
== NULL
)
737 * amdgpu_device_doorbell_fini - Tear down doorbell driver information.
739 * @adev: amdgpu_device pointer
741 * Tear down doorbell driver information (CIK)
743 static void amdgpu_device_doorbell_fini(struct amdgpu_device
*adev
)
745 iounmap(adev
->doorbell
.ptr
);
746 adev
->doorbell
.ptr
= NULL
;
752 * amdgpu_device_wb_*()
753 * Writeback is the method by which the GPU updates special pages in memory
754 * with the status of certain GPU events (fences, ring pointers,etc.).
758 * amdgpu_device_wb_fini - Disable Writeback and free memory
760 * @adev: amdgpu_device pointer
762 * Disables Writeback and frees the Writeback memory (all asics).
763 * Used at driver shutdown.
765 static void amdgpu_device_wb_fini(struct amdgpu_device
*adev
)
767 if (adev
->wb
.wb_obj
) {
768 amdgpu_bo_free_kernel(&adev
->wb
.wb_obj
,
770 (void **)&adev
->wb
.wb
);
771 adev
->wb
.wb_obj
= NULL
;
776 * amdgpu_device_wb_init- Init Writeback driver info and allocate memory
778 * @adev: amdgpu_device pointer
780 * Initializes writeback and allocates writeback memory (all asics).
781 * Used at driver startup.
782 * Returns 0 on success or an -error on failure.
784 static int amdgpu_device_wb_init(struct amdgpu_device
*adev
)
788 if (adev
->wb
.wb_obj
== NULL
) {
789 /* AMDGPU_MAX_WB * sizeof(uint32_t) * 8 = AMDGPU_MAX_WB 256bit slots */
790 r
= amdgpu_bo_create_kernel(adev
, AMDGPU_MAX_WB
* sizeof(uint32_t) * 8,
791 PAGE_SIZE
, AMDGPU_GEM_DOMAIN_GTT
,
792 &adev
->wb
.wb_obj
, &adev
->wb
.gpu_addr
,
793 (void **)&adev
->wb
.wb
);
795 dev_warn(adev
->dev
, "(%d) create WB bo failed\n", r
);
799 adev
->wb
.num_wb
= AMDGPU_MAX_WB
;
800 memset(&adev
->wb
.used
, 0, sizeof(adev
->wb
.used
));
802 /* clear wb memory */
803 memset((char *)adev
->wb
.wb
, 0, AMDGPU_MAX_WB
* sizeof(uint32_t) * 8);
810 * amdgpu_device_wb_get - Allocate a wb entry
812 * @adev: amdgpu_device pointer
815 * Allocate a wb slot for use by the driver (all asics).
816 * Returns 0 on success or -EINVAL on failure.
818 int amdgpu_device_wb_get(struct amdgpu_device
*adev
, u32
*wb
)
820 unsigned long offset
= find_first_zero_bit(adev
->wb
.used
, adev
->wb
.num_wb
);
822 if (offset
< adev
->wb
.num_wb
) {
823 __set_bit(offset
, adev
->wb
.used
);
824 *wb
= offset
<< 3; /* convert to dw offset */
832 * amdgpu_device_wb_free - Free a wb entry
834 * @adev: amdgpu_device pointer
837 * Free a wb slot allocated for use by the driver (all asics)
839 void amdgpu_device_wb_free(struct amdgpu_device
*adev
, u32 wb
)
842 if (wb
< adev
->wb
.num_wb
)
843 __clear_bit(wb
, adev
->wb
.used
);
847 * amdgpu_device_resize_fb_bar - try to resize FB BAR
849 * @adev: amdgpu_device pointer
851 * Try to resize FB BAR to make all VRAM CPU accessible. We try very hard not
852 * to fail, but if any of the BARs is not accessible after the size we abort
853 * driver loading by returning -ENODEV.
855 int amdgpu_device_resize_fb_bar(struct amdgpu_device
*adev
)
857 u64 space_needed
= roundup_pow_of_two(adev
->gmc
.real_vram_size
);
858 u32 rbar_size
= order_base_2(((space_needed
>> 20) | 1)) - 1;
859 struct pci_bus
*root
;
860 struct resource
*res
;
866 if (amdgpu_sriov_vf(adev
))
869 /* Check if the root BUS has 64bit memory resources */
870 root
= adev
->pdev
->bus
;
874 pci_bus_for_each_resource(root
, res
, i
) {
875 if (res
&& res
->flags
& (IORESOURCE_MEM
| IORESOURCE_MEM_64
) &&
876 res
->start
> 0x100000000ull
)
880 /* Trying to resize is pointless without a root hub window above 4GB */
884 /* Disable memory decoding while we change the BAR addresses and size */
885 pci_read_config_word(adev
->pdev
, PCI_COMMAND
, &cmd
);
886 pci_write_config_word(adev
->pdev
, PCI_COMMAND
,
887 cmd
& ~PCI_COMMAND_MEMORY
);
889 /* Free the VRAM and doorbell BAR, we most likely need to move both. */
890 amdgpu_device_doorbell_fini(adev
);
891 if (adev
->asic_type
>= CHIP_BONAIRE
)
892 pci_release_resource(adev
->pdev
, 2);
894 pci_release_resource(adev
->pdev
, 0);
896 r
= pci_resize_resource(adev
->pdev
, 0, rbar_size
);
898 DRM_INFO("Not enough PCI address space for a large BAR.");
899 else if (r
&& r
!= -ENOTSUPP
)
900 DRM_ERROR("Problem resizing BAR0 (%d).", r
);
902 pci_assign_unassigned_bus_resources(adev
->pdev
->bus
);
904 /* When the doorbell or fb BAR isn't available we have no chance of
907 r
= amdgpu_device_doorbell_init(adev
);
908 if (r
|| (pci_resource_flags(adev
->pdev
, 0) & IORESOURCE_UNSET
))
911 pci_write_config_word(adev
->pdev
, PCI_COMMAND
, cmd
);
917 * GPU helpers function.
920 * amdgpu_device_need_post - check if the hw need post or not
922 * @adev: amdgpu_device pointer
924 * Check if the asic has been initialized (all asics) at driver startup
925 * or post is needed if hw reset is performed.
926 * Returns true if need or false if not.
928 bool amdgpu_device_need_post(struct amdgpu_device
*adev
)
932 if (amdgpu_sriov_vf(adev
))
935 if (amdgpu_passthrough(adev
)) {
936 /* for FIJI: In whole GPU pass-through virtualization case, after VM reboot
937 * some old smc fw still need driver do vPost otherwise gpu hang, while
938 * those smc fw version above 22.15 doesn't have this flaw, so we force
939 * vpost executed for smc version below 22.15
941 if (adev
->asic_type
== CHIP_FIJI
) {
944 err
= request_firmware(&adev
->pm
.fw
, "amdgpu/fiji_smc.bin", adev
->dev
);
945 /* force vPost if error occured */
949 fw_ver
= *((uint32_t *)adev
->pm
.fw
->data
+ 69);
950 if (fw_ver
< 0x00160e00)
955 if (adev
->has_hw_reset
) {
956 adev
->has_hw_reset
= false;
960 /* bios scratch used on CIK+ */
961 if (adev
->asic_type
>= CHIP_BONAIRE
)
962 return amdgpu_atombios_scratch_need_asic_init(adev
);
964 /* check MEM_SIZE for older asics */
965 reg
= amdgpu_asic_get_config_memsize(adev
);
967 if ((reg
!= 0) && (reg
!= 0xffffffff))
973 /* if we get transitioned to only one device, take VGA back */
975 * amdgpu_device_vga_set_decode - enable/disable vga decode
977 * @cookie: amdgpu_device pointer
978 * @state: enable/disable vga decode
980 * Enable/disable vga decode (all asics).
981 * Returns VGA resource flags.
983 static unsigned int amdgpu_device_vga_set_decode(void *cookie
, bool state
)
985 struct amdgpu_device
*adev
= cookie
;
986 amdgpu_asic_set_vga_state(adev
, state
);
988 return VGA_RSRC_LEGACY_IO
| VGA_RSRC_LEGACY_MEM
|
989 VGA_RSRC_NORMAL_IO
| VGA_RSRC_NORMAL_MEM
;
991 return VGA_RSRC_NORMAL_IO
| VGA_RSRC_NORMAL_MEM
;
995 * amdgpu_device_check_block_size - validate the vm block size
997 * @adev: amdgpu_device pointer
999 * Validates the vm block size specified via module parameter.
1000 * The vm block size defines number of bits in page table versus page directory,
1001 * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
1002 * page table and the remaining bits are in the page directory.
1004 static void amdgpu_device_check_block_size(struct amdgpu_device
*adev
)
1006 /* defines number of bits in page table versus page directory,
1007 * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
1008 * page table and the remaining bits are in the page directory */
1009 if (amdgpu_vm_block_size
== -1)
1012 if (amdgpu_vm_block_size
< 9) {
1013 dev_warn(adev
->dev
, "VM page table size (%d) too small\n",
1014 amdgpu_vm_block_size
);
1015 amdgpu_vm_block_size
= -1;
1020 * amdgpu_device_check_vm_size - validate the vm size
1022 * @adev: amdgpu_device pointer
1024 * Validates the vm size in GB specified via module parameter.
1025 * The VM size is the size of the GPU virtual memory space in GB.
1027 static void amdgpu_device_check_vm_size(struct amdgpu_device
*adev
)
1029 /* no need to check the default value */
1030 if (amdgpu_vm_size
== -1)
1033 if (amdgpu_vm_size
< 1) {
1034 dev_warn(adev
->dev
, "VM size (%d) too small, min is 1GB\n",
1036 amdgpu_vm_size
= -1;
1040 static void amdgpu_device_check_smu_prv_buffer_size(struct amdgpu_device
*adev
)
1043 bool is_os_64
= (sizeof(void *) == 8);
1044 uint64_t total_memory
;
1045 uint64_t dram_size_seven_GB
= 0x1B8000000;
1046 uint64_t dram_size_three_GB
= 0xB8000000;
1048 if (amdgpu_smu_memory_pool_size
== 0)
1052 DRM_WARN("Not 64-bit OS, feature not supported\n");
1056 total_memory
= (uint64_t)si
.totalram
* si
.mem_unit
;
1058 if ((amdgpu_smu_memory_pool_size
== 1) ||
1059 (amdgpu_smu_memory_pool_size
== 2)) {
1060 if (total_memory
< dram_size_three_GB
)
1062 } else if ((amdgpu_smu_memory_pool_size
== 4) ||
1063 (amdgpu_smu_memory_pool_size
== 8)) {
1064 if (total_memory
< dram_size_seven_GB
)
1067 DRM_WARN("Smu memory pool size not supported\n");
1070 adev
->pm
.smu_prv_buffer_size
= amdgpu_smu_memory_pool_size
<< 28;
1075 DRM_WARN("No enough system memory\n");
1077 adev
->pm
.smu_prv_buffer_size
= 0;
1081 * amdgpu_device_check_arguments - validate module params
1083 * @adev: amdgpu_device pointer
1085 * Validates certain module parameters and updates
1086 * the associated values used by the driver (all asics).
1088 static int amdgpu_device_check_arguments(struct amdgpu_device
*adev
)
1090 if (amdgpu_sched_jobs
< 4) {
1091 dev_warn(adev
->dev
, "sched jobs (%d) must be at least 4\n",
1093 amdgpu_sched_jobs
= 4;
1094 } else if (!is_power_of_2(amdgpu_sched_jobs
)){
1095 dev_warn(adev
->dev
, "sched jobs (%d) must be a power of 2\n",
1097 amdgpu_sched_jobs
= roundup_pow_of_two(amdgpu_sched_jobs
);
1100 if (amdgpu_gart_size
!= -1 && amdgpu_gart_size
< 32) {
1101 /* gart size must be greater or equal to 32M */
1102 dev_warn(adev
->dev
, "gart size (%d) too small\n",
1104 amdgpu_gart_size
= -1;
1107 if (amdgpu_gtt_size
!= -1 && amdgpu_gtt_size
< 32) {
1108 /* gtt size must be greater or equal to 32M */
1109 dev_warn(adev
->dev
, "gtt size (%d) too small\n",
1111 amdgpu_gtt_size
= -1;
1114 /* valid range is between 4 and 9 inclusive */
1115 if (amdgpu_vm_fragment_size
!= -1 &&
1116 (amdgpu_vm_fragment_size
> 9 || amdgpu_vm_fragment_size
< 4)) {
1117 dev_warn(adev
->dev
, "valid range is between 4 and 9\n");
1118 amdgpu_vm_fragment_size
= -1;
1121 amdgpu_device_check_smu_prv_buffer_size(adev
);
1123 amdgpu_device_check_vm_size(adev
);
1125 amdgpu_device_check_block_size(adev
);
1127 adev
->firmware
.load_type
= amdgpu_ucode_get_load_type(adev
, amdgpu_fw_load_type
);
1133 * amdgpu_switcheroo_set_state - set switcheroo state
1135 * @pdev: pci dev pointer
1136 * @state: vga_switcheroo state
1138 * Callback for the switcheroo driver. Suspends or resumes the
1139 * the asics before or after it is powered up using ACPI methods.
1141 static void amdgpu_switcheroo_set_state(struct pci_dev
*pdev
, enum vga_switcheroo_state state
)
1143 struct drm_device
*dev
= pci_get_drvdata(pdev
);
1146 if (amdgpu_device_supports_boco(dev
) && state
== VGA_SWITCHEROO_OFF
)
1149 if (state
== VGA_SWITCHEROO_ON
) {
1150 pr_info("amdgpu: switched on\n");
1151 /* don't suspend or resume card normally */
1152 dev
->switch_power_state
= DRM_SWITCH_POWER_CHANGING
;
1154 pci_set_power_state(dev
->pdev
, PCI_D0
);
1155 pci_restore_state(dev
->pdev
);
1156 r
= pci_enable_device(dev
->pdev
);
1158 DRM_WARN("pci_enable_device failed (%d)\n", r
);
1159 amdgpu_device_resume(dev
, true);
1161 dev
->switch_power_state
= DRM_SWITCH_POWER_ON
;
1162 drm_kms_helper_poll_enable(dev
);
1164 pr_info("amdgpu: switched off\n");
1165 drm_kms_helper_poll_disable(dev
);
1166 dev
->switch_power_state
= DRM_SWITCH_POWER_CHANGING
;
1167 amdgpu_device_suspend(dev
, true);
1168 pci_save_state(dev
->pdev
);
1169 /* Shut down the device */
1170 pci_disable_device(dev
->pdev
);
1171 pci_set_power_state(dev
->pdev
, PCI_D3cold
);
1172 dev
->switch_power_state
= DRM_SWITCH_POWER_OFF
;
1177 * amdgpu_switcheroo_can_switch - see if switcheroo state can change
1179 * @pdev: pci dev pointer
1181 * Callback for the switcheroo driver. Check of the switcheroo
1182 * state can be changed.
1183 * Returns true if the state can be changed, false if not.
1185 static bool amdgpu_switcheroo_can_switch(struct pci_dev
*pdev
)
1187 struct drm_device
*dev
= pci_get_drvdata(pdev
);
1190 * FIXME: open_count is protected by drm_global_mutex but that would lead to
1191 * locking inversion with the driver load path. And the access here is
1192 * completely racy anyway. So don't bother with locking for now.
1194 return atomic_read(&dev
->open_count
) == 0;
1197 static const struct vga_switcheroo_client_ops amdgpu_switcheroo_ops
= {
1198 .set_gpu_state
= amdgpu_switcheroo_set_state
,
1200 .can_switch
= amdgpu_switcheroo_can_switch
,
1204 * amdgpu_device_ip_set_clockgating_state - set the CG state
1206 * @dev: amdgpu_device pointer
1207 * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
1208 * @state: clockgating state (gate or ungate)
1210 * Sets the requested clockgating state for all instances of
1211 * the hardware IP specified.
1212 * Returns the error code from the last instance.
1214 int amdgpu_device_ip_set_clockgating_state(void *dev
,
1215 enum amd_ip_block_type block_type
,
1216 enum amd_clockgating_state state
)
1218 struct amdgpu_device
*adev
= dev
;
1221 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1222 if (!adev
->ip_blocks
[i
].status
.valid
)
1224 if (adev
->ip_blocks
[i
].version
->type
!= block_type
)
1226 if (!adev
->ip_blocks
[i
].version
->funcs
->set_clockgating_state
)
1228 r
= adev
->ip_blocks
[i
].version
->funcs
->set_clockgating_state(
1229 (void *)adev
, state
);
1231 DRM_ERROR("set_clockgating_state of IP block <%s> failed %d\n",
1232 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
1238 * amdgpu_device_ip_set_powergating_state - set the PG state
1240 * @dev: amdgpu_device pointer
1241 * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
1242 * @state: powergating state (gate or ungate)
1244 * Sets the requested powergating state for all instances of
1245 * the hardware IP specified.
1246 * Returns the error code from the last instance.
1248 int amdgpu_device_ip_set_powergating_state(void *dev
,
1249 enum amd_ip_block_type block_type
,
1250 enum amd_powergating_state state
)
1252 struct amdgpu_device
*adev
= dev
;
1255 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1256 if (!adev
->ip_blocks
[i
].status
.valid
)
1258 if (adev
->ip_blocks
[i
].version
->type
!= block_type
)
1260 if (!adev
->ip_blocks
[i
].version
->funcs
->set_powergating_state
)
1262 r
= adev
->ip_blocks
[i
].version
->funcs
->set_powergating_state(
1263 (void *)adev
, state
);
1265 DRM_ERROR("set_powergating_state of IP block <%s> failed %d\n",
1266 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
1272 * amdgpu_device_ip_get_clockgating_state - get the CG state
1274 * @adev: amdgpu_device pointer
1275 * @flags: clockgating feature flags
1277 * Walks the list of IPs on the device and updates the clockgating
1278 * flags for each IP.
1279 * Updates @flags with the feature flags for each hardware IP where
1280 * clockgating is enabled.
1282 void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device
*adev
,
1287 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1288 if (!adev
->ip_blocks
[i
].status
.valid
)
1290 if (adev
->ip_blocks
[i
].version
->funcs
->get_clockgating_state
)
1291 adev
->ip_blocks
[i
].version
->funcs
->get_clockgating_state((void *)adev
, flags
);
1296 * amdgpu_device_ip_wait_for_idle - wait for idle
1298 * @adev: amdgpu_device pointer
1299 * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
1301 * Waits for the request hardware IP to be idle.
1302 * Returns 0 for success or a negative error code on failure.
1304 int amdgpu_device_ip_wait_for_idle(struct amdgpu_device
*adev
,
1305 enum amd_ip_block_type block_type
)
1309 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1310 if (!adev
->ip_blocks
[i
].status
.valid
)
1312 if (adev
->ip_blocks
[i
].version
->type
== block_type
) {
1313 r
= adev
->ip_blocks
[i
].version
->funcs
->wait_for_idle((void *)adev
);
1324 * amdgpu_device_ip_is_idle - is the hardware IP idle
1326 * @adev: amdgpu_device pointer
1327 * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
1329 * Check if the hardware IP is idle or not.
1330 * Returns true if it the IP is idle, false if not.
1332 bool amdgpu_device_ip_is_idle(struct amdgpu_device
*adev
,
1333 enum amd_ip_block_type block_type
)
1337 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1338 if (!adev
->ip_blocks
[i
].status
.valid
)
1340 if (adev
->ip_blocks
[i
].version
->type
== block_type
)
1341 return adev
->ip_blocks
[i
].version
->funcs
->is_idle((void *)adev
);
1348 * amdgpu_device_ip_get_ip_block - get a hw IP pointer
1350 * @adev: amdgpu_device pointer
1351 * @type: Type of hardware IP (SMU, GFX, UVD, etc.)
1353 * Returns a pointer to the hardware IP block structure
1354 * if it exists for the asic, otherwise NULL.
1356 struct amdgpu_ip_block
*
1357 amdgpu_device_ip_get_ip_block(struct amdgpu_device
*adev
,
1358 enum amd_ip_block_type type
)
1362 for (i
= 0; i
< adev
->num_ip_blocks
; i
++)
1363 if (adev
->ip_blocks
[i
].version
->type
== type
)
1364 return &adev
->ip_blocks
[i
];
1370 * amdgpu_device_ip_block_version_cmp
1372 * @adev: amdgpu_device pointer
1373 * @type: enum amd_ip_block_type
1374 * @major: major version
1375 * @minor: minor version
1377 * return 0 if equal or greater
1378 * return 1 if smaller or the ip_block doesn't exist
1380 int amdgpu_device_ip_block_version_cmp(struct amdgpu_device
*adev
,
1381 enum amd_ip_block_type type
,
1382 u32 major
, u32 minor
)
1384 struct amdgpu_ip_block
*ip_block
= amdgpu_device_ip_get_ip_block(adev
, type
);
1386 if (ip_block
&& ((ip_block
->version
->major
> major
) ||
1387 ((ip_block
->version
->major
== major
) &&
1388 (ip_block
->version
->minor
>= minor
))))
1395 * amdgpu_device_ip_block_add
1397 * @adev: amdgpu_device pointer
1398 * @ip_block_version: pointer to the IP to add
1400 * Adds the IP block driver information to the collection of IPs
1403 int amdgpu_device_ip_block_add(struct amdgpu_device
*adev
,
1404 const struct amdgpu_ip_block_version
*ip_block_version
)
1406 if (!ip_block_version
)
1409 DRM_INFO("add ip block number %d <%s>\n", adev
->num_ip_blocks
,
1410 ip_block_version
->funcs
->name
);
1412 adev
->ip_blocks
[adev
->num_ip_blocks
++].version
= ip_block_version
;
1418 * amdgpu_device_enable_virtual_display - enable virtual display feature
1420 * @adev: amdgpu_device pointer
1422 * Enabled the virtual display feature if the user has enabled it via
1423 * the module parameter virtual_display. This feature provides a virtual
1424 * display hardware on headless boards or in virtualized environments.
1425 * This function parses and validates the configuration string specified by
1426 * the user and configues the virtual display configuration (number of
1427 * virtual connectors, crtcs, etc.) specified.
1429 static void amdgpu_device_enable_virtual_display(struct amdgpu_device
*adev
)
1431 adev
->enable_virtual_display
= false;
1433 if (amdgpu_virtual_display
) {
1434 struct drm_device
*ddev
= adev
->ddev
;
1435 const char *pci_address_name
= pci_name(ddev
->pdev
);
1436 char *pciaddstr
, *pciaddstr_tmp
, *pciaddname_tmp
, *pciaddname
;
1438 pciaddstr
= kstrdup(amdgpu_virtual_display
, GFP_KERNEL
);
1439 pciaddstr_tmp
= pciaddstr
;
1440 while ((pciaddname_tmp
= strsep(&pciaddstr_tmp
, ";"))) {
1441 pciaddname
= strsep(&pciaddname_tmp
, ",");
1442 if (!strcmp("all", pciaddname
)
1443 || !strcmp(pci_address_name
, pciaddname
)) {
1447 adev
->enable_virtual_display
= true;
1450 res
= kstrtol(pciaddname_tmp
, 10,
1458 adev
->mode_info
.num_crtc
= num_crtc
;
1460 adev
->mode_info
.num_crtc
= 1;
1466 DRM_INFO("virtual display string:%s, %s:virtual_display:%d, num_crtc:%d\n",
1467 amdgpu_virtual_display
, pci_address_name
,
1468 adev
->enable_virtual_display
, adev
->mode_info
.num_crtc
);
1475 * amdgpu_device_parse_gpu_info_fw - parse gpu info firmware
1477 * @adev: amdgpu_device pointer
1479 * Parses the asic configuration parameters specified in the gpu info
1480 * firmware and makes them availale to the driver for use in configuring
1482 * Returns 0 on success, -EINVAL on failure.
1484 static int amdgpu_device_parse_gpu_info_fw(struct amdgpu_device
*adev
)
1486 const char *chip_name
;
1489 const struct gpu_info_firmware_header_v1_0
*hdr
;
1491 adev
->firmware
.gpu_info_fw
= NULL
;
1493 switch (adev
->asic_type
) {
1497 case CHIP_POLARIS10
:
1498 case CHIP_POLARIS11
:
1499 case CHIP_POLARIS12
:
1503 #ifdef CONFIG_DRM_AMDGPU_SI
1510 #ifdef CONFIG_DRM_AMDGPU_CIK
1521 chip_name
= "vega10";
1524 chip_name
= "vega12";
1527 if (adev
->rev_id
>= 8)
1528 chip_name
= "raven2";
1529 else if (adev
->pdev
->device
== 0x15d8)
1530 chip_name
= "picasso";
1532 chip_name
= "raven";
1535 chip_name
= "arcturus";
1538 chip_name
= "renoir";
1541 chip_name
= "navi10";
1544 chip_name
= "navi14";
1547 chip_name
= "navi12";
1551 snprintf(fw_name
, sizeof(fw_name
), "amdgpu/%s_gpu_info.bin", chip_name
);
1552 err
= request_firmware(&adev
->firmware
.gpu_info_fw
, fw_name
, adev
->dev
);
1555 "Failed to load gpu_info firmware \"%s\"\n",
1559 err
= amdgpu_ucode_validate(adev
->firmware
.gpu_info_fw
);
1562 "Failed to validate gpu_info firmware \"%s\"\n",
1567 hdr
= (const struct gpu_info_firmware_header_v1_0
*)adev
->firmware
.gpu_info_fw
->data
;
1568 amdgpu_ucode_print_gpu_info_hdr(&hdr
->header
);
1570 switch (hdr
->version_major
) {
1573 const struct gpu_info_firmware_v1_0
*gpu_info_fw
=
1574 (const struct gpu_info_firmware_v1_0
*)(adev
->firmware
.gpu_info_fw
->data
+
1575 le32_to_cpu(hdr
->header
.ucode_array_offset_bytes
));
1577 if (amdgpu_discovery
&& adev
->asic_type
>= CHIP_NAVI10
)
1578 goto parse_soc_bounding_box
;
1580 adev
->gfx
.config
.max_shader_engines
= le32_to_cpu(gpu_info_fw
->gc_num_se
);
1581 adev
->gfx
.config
.max_cu_per_sh
= le32_to_cpu(gpu_info_fw
->gc_num_cu_per_sh
);
1582 adev
->gfx
.config
.max_sh_per_se
= le32_to_cpu(gpu_info_fw
->gc_num_sh_per_se
);
1583 adev
->gfx
.config
.max_backends_per_se
= le32_to_cpu(gpu_info_fw
->gc_num_rb_per_se
);
1584 adev
->gfx
.config
.max_texture_channel_caches
=
1585 le32_to_cpu(gpu_info_fw
->gc_num_tccs
);
1586 adev
->gfx
.config
.max_gprs
= le32_to_cpu(gpu_info_fw
->gc_num_gprs
);
1587 adev
->gfx
.config
.max_gs_threads
= le32_to_cpu(gpu_info_fw
->gc_num_max_gs_thds
);
1588 adev
->gfx
.config
.gs_vgt_table_depth
= le32_to_cpu(gpu_info_fw
->gc_gs_table_depth
);
1589 adev
->gfx
.config
.gs_prim_buffer_depth
= le32_to_cpu(gpu_info_fw
->gc_gsprim_buff_depth
);
1590 adev
->gfx
.config
.double_offchip_lds_buf
=
1591 le32_to_cpu(gpu_info_fw
->gc_double_offchip_lds_buffer
);
1592 adev
->gfx
.cu_info
.wave_front_size
= le32_to_cpu(gpu_info_fw
->gc_wave_size
);
1593 adev
->gfx
.cu_info
.max_waves_per_simd
=
1594 le32_to_cpu(gpu_info_fw
->gc_max_waves_per_simd
);
1595 adev
->gfx
.cu_info
.max_scratch_slots_per_cu
=
1596 le32_to_cpu(gpu_info_fw
->gc_max_scratch_slots_per_cu
);
1597 adev
->gfx
.cu_info
.lds_size
= le32_to_cpu(gpu_info_fw
->gc_lds_size
);
1598 if (hdr
->version_minor
>= 1) {
1599 const struct gpu_info_firmware_v1_1
*gpu_info_fw
=
1600 (const struct gpu_info_firmware_v1_1
*)(adev
->firmware
.gpu_info_fw
->data
+
1601 le32_to_cpu(hdr
->header
.ucode_array_offset_bytes
));
1602 adev
->gfx
.config
.num_sc_per_sh
=
1603 le32_to_cpu(gpu_info_fw
->num_sc_per_sh
);
1604 adev
->gfx
.config
.num_packer_per_sc
=
1605 le32_to_cpu(gpu_info_fw
->num_packer_per_sc
);
1608 parse_soc_bounding_box
:
1610 * soc bounding box info is not integrated in disocovery table,
1611 * we always need to parse it from gpu info firmware.
1613 if (hdr
->version_minor
== 2) {
1614 const struct gpu_info_firmware_v1_2
*gpu_info_fw
=
1615 (const struct gpu_info_firmware_v1_2
*)(adev
->firmware
.gpu_info_fw
->data
+
1616 le32_to_cpu(hdr
->header
.ucode_array_offset_bytes
));
1617 adev
->dm
.soc_bounding_box
= &gpu_info_fw
->soc_bounding_box
;
1623 "Unsupported gpu_info table %d\n", hdr
->header
.ucode_version
);
1632 * amdgpu_device_ip_early_init - run early init for hardware IPs
1634 * @adev: amdgpu_device pointer
1636 * Early initialization pass for hardware IPs. The hardware IPs that make
1637 * up each asic are discovered each IP's early_init callback is run. This
1638 * is the first stage in initializing the asic.
1639 * Returns 0 on success, negative error code on failure.
1641 static int amdgpu_device_ip_early_init(struct amdgpu_device
*adev
)
1645 amdgpu_device_enable_virtual_display(adev
);
1647 switch (adev
->asic_type
) {
1651 case CHIP_POLARIS10
:
1652 case CHIP_POLARIS11
:
1653 case CHIP_POLARIS12
:
1657 if (adev
->asic_type
== CHIP_CARRIZO
|| adev
->asic_type
== CHIP_STONEY
)
1658 adev
->family
= AMDGPU_FAMILY_CZ
;
1660 adev
->family
= AMDGPU_FAMILY_VI
;
1662 r
= vi_set_ip_blocks(adev
);
1666 #ifdef CONFIG_DRM_AMDGPU_SI
1672 adev
->family
= AMDGPU_FAMILY_SI
;
1673 r
= si_set_ip_blocks(adev
);
1678 #ifdef CONFIG_DRM_AMDGPU_CIK
1684 if ((adev
->asic_type
== CHIP_BONAIRE
) || (adev
->asic_type
== CHIP_HAWAII
))
1685 adev
->family
= AMDGPU_FAMILY_CI
;
1687 adev
->family
= AMDGPU_FAMILY_KV
;
1689 r
= cik_set_ip_blocks(adev
);
1700 if (adev
->asic_type
== CHIP_RAVEN
||
1701 adev
->asic_type
== CHIP_RENOIR
)
1702 adev
->family
= AMDGPU_FAMILY_RV
;
1704 adev
->family
= AMDGPU_FAMILY_AI
;
1706 r
= soc15_set_ip_blocks(adev
);
1713 adev
->family
= AMDGPU_FAMILY_NV
;
1715 r
= nv_set_ip_blocks(adev
);
1720 /* FIXME: not supported yet */
1724 r
= amdgpu_device_parse_gpu_info_fw(adev
);
1728 if (amdgpu_discovery
&& adev
->asic_type
>= CHIP_NAVI10
)
1729 amdgpu_discovery_get_gfx_info(adev
);
1731 amdgpu_amdkfd_device_probe(adev
);
1733 if (amdgpu_sriov_vf(adev
)) {
1734 r
= amdgpu_virt_request_full_gpu(adev
, true);
1739 adev
->pm
.pp_feature
= amdgpu_pp_feature_mask
;
1740 if (amdgpu_sriov_vf(adev
) || sched_policy
== KFD_SCHED_POLICY_NO_HWS
)
1741 adev
->pm
.pp_feature
&= ~PP_GFXOFF_MASK
;
1743 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1744 if ((amdgpu_ip_block_mask
& (1 << i
)) == 0) {
1745 DRM_ERROR("disabled ip block: %d <%s>\n",
1746 i
, adev
->ip_blocks
[i
].version
->funcs
->name
);
1747 adev
->ip_blocks
[i
].status
.valid
= false;
1749 if (adev
->ip_blocks
[i
].version
->funcs
->early_init
) {
1750 r
= adev
->ip_blocks
[i
].version
->funcs
->early_init((void *)adev
);
1752 adev
->ip_blocks
[i
].status
.valid
= false;
1754 DRM_ERROR("early_init of IP block <%s> failed %d\n",
1755 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
1758 adev
->ip_blocks
[i
].status
.valid
= true;
1761 adev
->ip_blocks
[i
].status
.valid
= true;
1764 /* get the vbios after the asic_funcs are set up */
1765 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_COMMON
) {
1767 if (!amdgpu_get_bios(adev
))
1770 r
= amdgpu_atombios_init(adev
);
1772 dev_err(adev
->dev
, "amdgpu_atombios_init failed\n");
1773 amdgpu_vf_error_put(adev
, AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL
, 0, 0);
1779 adev
->cg_flags
&= amdgpu_cg_mask
;
1780 adev
->pg_flags
&= amdgpu_pg_mask
;
1785 static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device
*adev
)
1789 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1790 if (!adev
->ip_blocks
[i
].status
.sw
)
1792 if (adev
->ip_blocks
[i
].status
.hw
)
1794 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_COMMON
||
1795 (amdgpu_sriov_vf(adev
) && (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_PSP
)) ||
1796 adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_IH
) {
1797 r
= adev
->ip_blocks
[i
].version
->funcs
->hw_init(adev
);
1799 DRM_ERROR("hw_init of IP block <%s> failed %d\n",
1800 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
1803 adev
->ip_blocks
[i
].status
.hw
= true;
1810 static int amdgpu_device_ip_hw_init_phase2(struct amdgpu_device
*adev
)
1814 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1815 if (!adev
->ip_blocks
[i
].status
.sw
)
1817 if (adev
->ip_blocks
[i
].status
.hw
)
1819 r
= adev
->ip_blocks
[i
].version
->funcs
->hw_init(adev
);
1821 DRM_ERROR("hw_init of IP block <%s> failed %d\n",
1822 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
1825 adev
->ip_blocks
[i
].status
.hw
= true;
1831 static int amdgpu_device_fw_loading(struct amdgpu_device
*adev
)
1835 uint32_t smu_version
;
1837 if (adev
->asic_type
>= CHIP_VEGA10
) {
1838 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1839 if (adev
->ip_blocks
[i
].version
->type
!= AMD_IP_BLOCK_TYPE_PSP
)
1842 /* no need to do the fw loading again if already done*/
1843 if (adev
->ip_blocks
[i
].status
.hw
== true)
1846 if (adev
->in_gpu_reset
|| adev
->in_suspend
) {
1847 r
= adev
->ip_blocks
[i
].version
->funcs
->resume(adev
);
1849 DRM_ERROR("resume of IP block <%s> failed %d\n",
1850 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
1854 r
= adev
->ip_blocks
[i
].version
->funcs
->hw_init(adev
);
1856 DRM_ERROR("hw_init of IP block <%s> failed %d\n",
1857 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
1862 adev
->ip_blocks
[i
].status
.hw
= true;
1867 if (!amdgpu_sriov_vf(adev
) || adev
->asic_type
== CHIP_TONGA
)
1868 r
= amdgpu_pm_load_smu_firmware(adev
, &smu_version
);
1874 * amdgpu_device_ip_init - run init for hardware IPs
1876 * @adev: amdgpu_device pointer
1878 * Main initialization pass for hardware IPs. The list of all the hardware
1879 * IPs that make up the asic is walked and the sw_init and hw_init callbacks
1880 * are run. sw_init initializes the software state associated with each IP
1881 * and hw_init initializes the hardware associated with each IP.
1882 * Returns 0 on success, negative error code on failure.
1884 static int amdgpu_device_ip_init(struct amdgpu_device
*adev
)
1888 r
= amdgpu_ras_init(adev
);
1892 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
1893 if (!adev
->ip_blocks
[i
].status
.valid
)
1895 r
= adev
->ip_blocks
[i
].version
->funcs
->sw_init((void *)adev
);
1897 DRM_ERROR("sw_init of IP block <%s> failed %d\n",
1898 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
1901 adev
->ip_blocks
[i
].status
.sw
= true;
1903 /* need to do gmc hw init early so we can allocate gpu mem */
1904 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_GMC
) {
1905 r
= amdgpu_device_vram_scratch_init(adev
);
1907 DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r
);
1910 r
= adev
->ip_blocks
[i
].version
->funcs
->hw_init((void *)adev
);
1912 DRM_ERROR("hw_init %d failed %d\n", i
, r
);
1915 r
= amdgpu_device_wb_init(adev
);
1917 DRM_ERROR("amdgpu_device_wb_init failed %d\n", r
);
1920 adev
->ip_blocks
[i
].status
.hw
= true;
1922 /* right after GMC hw init, we create CSA */
1923 if (amdgpu_mcbp
|| amdgpu_sriov_vf(adev
)) {
1924 r
= amdgpu_allocate_static_csa(adev
, &adev
->virt
.csa_obj
,
1925 AMDGPU_GEM_DOMAIN_VRAM
,
1928 DRM_ERROR("allocate CSA failed %d\n", r
);
1935 if (amdgpu_sriov_vf(adev
))
1936 amdgpu_virt_init_data_exchange(adev
);
1938 r
= amdgpu_ib_pool_init(adev
);
1940 dev_err(adev
->dev
, "IB initialization failed (%d).\n", r
);
1941 amdgpu_vf_error_put(adev
, AMDGIM_ERROR_VF_IB_INIT_FAIL
, 0, r
);
1945 r
= amdgpu_ucode_create_bo(adev
); /* create ucode bo when sw_init complete*/
1949 r
= amdgpu_device_ip_hw_init_phase1(adev
);
1953 r
= amdgpu_device_fw_loading(adev
);
1957 r
= amdgpu_device_ip_hw_init_phase2(adev
);
1962 * retired pages will be loaded from eeprom and reserved here,
1963 * it should be called after amdgpu_device_ip_hw_init_phase2 since
1964 * for some ASICs the RAS EEPROM code relies on SMU fully functioning
1965 * for I2C communication which only true at this point.
1966 * recovery_init may fail, but it can free all resources allocated by
1967 * itself and its failure should not stop amdgpu init process.
1969 * Note: theoretically, this should be called before all vram allocations
1970 * to protect retired page from abusing
1972 amdgpu_ras_recovery_init(adev
);
1974 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1)
1975 amdgpu_xgmi_add_device(adev
);
1976 amdgpu_amdkfd_device_init(adev
);
1979 if (amdgpu_sriov_vf(adev
))
1980 amdgpu_virt_release_full_gpu(adev
, true);
1986 * amdgpu_device_fill_reset_magic - writes reset magic to gart pointer
1988 * @adev: amdgpu_device pointer
1990 * Writes a reset magic value to the gart pointer in VRAM. The driver calls
1991 * this function before a GPU reset. If the value is retained after a
1992 * GPU reset, VRAM has not been lost. Some GPU resets may destry VRAM contents.
1994 static void amdgpu_device_fill_reset_magic(struct amdgpu_device
*adev
)
1996 memcpy(adev
->reset_magic
, adev
->gart
.ptr
, AMDGPU_RESET_MAGIC_NUM
);
2000 * amdgpu_device_check_vram_lost - check if vram is valid
2002 * @adev: amdgpu_device pointer
2004 * Checks the reset magic value written to the gart pointer in VRAM.
2005 * The driver calls this after a GPU reset to see if the contents of
2006 * VRAM is lost or now.
2007 * returns true if vram is lost, false if not.
2009 static bool amdgpu_device_check_vram_lost(struct amdgpu_device
*adev
)
2011 return !!memcmp(adev
->gart
.ptr
, adev
->reset_magic
,
2012 AMDGPU_RESET_MAGIC_NUM
);
2016 * amdgpu_device_set_cg_state - set clockgating for amdgpu device
2018 * @adev: amdgpu_device pointer
2019 * @state: clockgating state (gate or ungate)
2021 * The list of all the hardware IPs that make up the asic is walked and the
2022 * set_clockgating_state callbacks are run.
2023 * Late initialization pass enabling clockgating for hardware IPs.
2024 * Fini or suspend, pass disabling clockgating for hardware IPs.
2025 * Returns 0 on success, negative error code on failure.
2028 static int amdgpu_device_set_cg_state(struct amdgpu_device
*adev
,
2029 enum amd_clockgating_state state
)
2033 if (amdgpu_emu_mode
== 1)
2036 for (j
= 0; j
< adev
->num_ip_blocks
; j
++) {
2037 i
= state
== AMD_CG_STATE_GATE
? j
: adev
->num_ip_blocks
- j
- 1;
2038 if (!adev
->ip_blocks
[i
].status
.late_initialized
)
2040 /* skip CG for VCE/UVD, it's handled specially */
2041 if (adev
->ip_blocks
[i
].version
->type
!= AMD_IP_BLOCK_TYPE_UVD
&&
2042 adev
->ip_blocks
[i
].version
->type
!= AMD_IP_BLOCK_TYPE_VCE
&&
2043 adev
->ip_blocks
[i
].version
->type
!= AMD_IP_BLOCK_TYPE_VCN
&&
2044 adev
->ip_blocks
[i
].version
->type
!= AMD_IP_BLOCK_TYPE_JPEG
&&
2045 adev
->ip_blocks
[i
].version
->funcs
->set_clockgating_state
) {
2046 /* enable clockgating to save power */
2047 r
= adev
->ip_blocks
[i
].version
->funcs
->set_clockgating_state((void *)adev
,
2050 DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n",
2051 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2060 static int amdgpu_device_set_pg_state(struct amdgpu_device
*adev
, enum amd_powergating_state state
)
2064 if (amdgpu_emu_mode
== 1)
2067 for (j
= 0; j
< adev
->num_ip_blocks
; j
++) {
2068 i
= state
== AMD_PG_STATE_GATE
? j
: adev
->num_ip_blocks
- j
- 1;
2069 if (!adev
->ip_blocks
[i
].status
.late_initialized
)
2071 /* skip CG for VCE/UVD, it's handled specially */
2072 if (adev
->ip_blocks
[i
].version
->type
!= AMD_IP_BLOCK_TYPE_UVD
&&
2073 adev
->ip_blocks
[i
].version
->type
!= AMD_IP_BLOCK_TYPE_VCE
&&
2074 adev
->ip_blocks
[i
].version
->type
!= AMD_IP_BLOCK_TYPE_VCN
&&
2075 adev
->ip_blocks
[i
].version
->type
!= AMD_IP_BLOCK_TYPE_JPEG
&&
2076 adev
->ip_blocks
[i
].version
->funcs
->set_powergating_state
) {
2077 /* enable powergating to save power */
2078 r
= adev
->ip_blocks
[i
].version
->funcs
->set_powergating_state((void *)adev
,
2081 DRM_ERROR("set_powergating_state(gate) of IP block <%s> failed %d\n",
2082 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2090 static int amdgpu_device_enable_mgpu_fan_boost(void)
2092 struct amdgpu_gpu_instance
*gpu_ins
;
2093 struct amdgpu_device
*adev
;
2096 mutex_lock(&mgpu_info
.mutex
);
2099 * MGPU fan boost feature should be enabled
2100 * only when there are two or more dGPUs in
2103 if (mgpu_info
.num_dgpu
< 2)
2106 for (i
= 0; i
< mgpu_info
.num_dgpu
; i
++) {
2107 gpu_ins
= &(mgpu_info
.gpu_ins
[i
]);
2108 adev
= gpu_ins
->adev
;
2109 if (!(adev
->flags
& AMD_IS_APU
) &&
2110 !gpu_ins
->mgpu_fan_enabled
&&
2111 adev
->powerplay
.pp_funcs
&&
2112 adev
->powerplay
.pp_funcs
->enable_mgpu_fan_boost
) {
2113 ret
= amdgpu_dpm_enable_mgpu_fan_boost(adev
);
2117 gpu_ins
->mgpu_fan_enabled
= 1;
2122 mutex_unlock(&mgpu_info
.mutex
);
2128 * amdgpu_device_ip_late_init - run late init for hardware IPs
2130 * @adev: amdgpu_device pointer
2132 * Late initialization pass for hardware IPs. The list of all the hardware
2133 * IPs that make up the asic is walked and the late_init callbacks are run.
2134 * late_init covers any special initialization that an IP requires
2135 * after all of the have been initialized or something that needs to happen
2136 * late in the init process.
2137 * Returns 0 on success, negative error code on failure.
2139 static int amdgpu_device_ip_late_init(struct amdgpu_device
*adev
)
2141 struct amdgpu_gpu_instance
*gpu_instance
;
2144 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
2145 if (!adev
->ip_blocks
[i
].status
.hw
)
2147 if (adev
->ip_blocks
[i
].version
->funcs
->late_init
) {
2148 r
= adev
->ip_blocks
[i
].version
->funcs
->late_init((void *)adev
);
2150 DRM_ERROR("late_init of IP block <%s> failed %d\n",
2151 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2155 adev
->ip_blocks
[i
].status
.late_initialized
= true;
2158 amdgpu_device_set_cg_state(adev
, AMD_CG_STATE_GATE
);
2159 amdgpu_device_set_pg_state(adev
, AMD_PG_STATE_GATE
);
2161 amdgpu_device_fill_reset_magic(adev
);
2163 r
= amdgpu_device_enable_mgpu_fan_boost();
2165 DRM_ERROR("enable mgpu fan boost failed (%d).\n", r
);
2168 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1) {
2169 mutex_lock(&mgpu_info
.mutex
);
2172 * Reset device p-state to low as this was booted with high.
2174 * This should be performed only after all devices from the same
2175 * hive get initialized.
2177 * However, it's unknown how many device in the hive in advance.
2178 * As this is counted one by one during devices initializations.
2180 * So, we wait for all XGMI interlinked devices initialized.
2181 * This may bring some delays as those devices may come from
2182 * different hives. But that should be OK.
2184 if (mgpu_info
.num_dgpu
== adev
->gmc
.xgmi
.num_physical_nodes
) {
2185 for (i
= 0; i
< mgpu_info
.num_gpu
; i
++) {
2186 gpu_instance
= &(mgpu_info
.gpu_ins
[i
]);
2187 if (gpu_instance
->adev
->flags
& AMD_IS_APU
)
2190 r
= amdgpu_xgmi_set_pstate(gpu_instance
->adev
, 0);
2192 DRM_ERROR("pstate setting failed (%d).\n", r
);
2198 mutex_unlock(&mgpu_info
.mutex
);
2205 * amdgpu_device_ip_fini - run fini for hardware IPs
2207 * @adev: amdgpu_device pointer
2209 * Main teardown pass for hardware IPs. The list of all the hardware
2210 * IPs that make up the asic is walked and the hw_fini and sw_fini callbacks
2211 * are run. hw_fini tears down the hardware associated with each IP
2212 * and sw_fini tears down any software state associated with each IP.
2213 * Returns 0 on success, negative error code on failure.
2215 static int amdgpu_device_ip_fini(struct amdgpu_device
*adev
)
2219 amdgpu_ras_pre_fini(adev
);
2221 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1)
2222 amdgpu_xgmi_remove_device(adev
);
2224 amdgpu_amdkfd_device_fini(adev
);
2226 amdgpu_device_set_pg_state(adev
, AMD_PG_STATE_UNGATE
);
2227 amdgpu_device_set_cg_state(adev
, AMD_CG_STATE_UNGATE
);
2229 /* need to disable SMC first */
2230 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
2231 if (!adev
->ip_blocks
[i
].status
.hw
)
2233 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_SMC
) {
2234 r
= adev
->ip_blocks
[i
].version
->funcs
->hw_fini((void *)adev
);
2235 /* XXX handle errors */
2237 DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
2238 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2240 adev
->ip_blocks
[i
].status
.hw
= false;
2245 for (i
= adev
->num_ip_blocks
- 1; i
>= 0; i
--) {
2246 if (!adev
->ip_blocks
[i
].status
.hw
)
2249 r
= adev
->ip_blocks
[i
].version
->funcs
->hw_fini((void *)adev
);
2250 /* XXX handle errors */
2252 DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
2253 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2256 adev
->ip_blocks
[i
].status
.hw
= false;
2260 for (i
= adev
->num_ip_blocks
- 1; i
>= 0; i
--) {
2261 if (!adev
->ip_blocks
[i
].status
.sw
)
2264 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_GMC
) {
2265 amdgpu_ucode_free_bo(adev
);
2266 amdgpu_free_static_csa(&adev
->virt
.csa_obj
);
2267 amdgpu_device_wb_fini(adev
);
2268 amdgpu_device_vram_scratch_fini(adev
);
2269 amdgpu_ib_pool_fini(adev
);
2272 r
= adev
->ip_blocks
[i
].version
->funcs
->sw_fini((void *)adev
);
2273 /* XXX handle errors */
2275 DRM_DEBUG("sw_fini of IP block <%s> failed %d\n",
2276 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2278 adev
->ip_blocks
[i
].status
.sw
= false;
2279 adev
->ip_blocks
[i
].status
.valid
= false;
2282 for (i
= adev
->num_ip_blocks
- 1; i
>= 0; i
--) {
2283 if (!adev
->ip_blocks
[i
].status
.late_initialized
)
2285 if (adev
->ip_blocks
[i
].version
->funcs
->late_fini
)
2286 adev
->ip_blocks
[i
].version
->funcs
->late_fini((void *)adev
);
2287 adev
->ip_blocks
[i
].status
.late_initialized
= false;
2290 amdgpu_ras_fini(adev
);
2292 if (amdgpu_sriov_vf(adev
))
2293 if (amdgpu_virt_release_full_gpu(adev
, false))
2294 DRM_ERROR("failed to release exclusive mode on fini\n");
2300 * amdgpu_device_delayed_init_work_handler - work handler for IB tests
2302 * @work: work_struct.
2304 static void amdgpu_device_delayed_init_work_handler(struct work_struct
*work
)
2306 struct amdgpu_device
*adev
=
2307 container_of(work
, struct amdgpu_device
, delayed_init_work
.work
);
2310 r
= amdgpu_ib_ring_tests(adev
);
2312 DRM_ERROR("ib ring test failed (%d).\n", r
);
2315 static void amdgpu_device_delay_enable_gfx_off(struct work_struct
*work
)
2317 struct amdgpu_device
*adev
=
2318 container_of(work
, struct amdgpu_device
, gfx
.gfx_off_delay_work
.work
);
2320 mutex_lock(&adev
->gfx
.gfx_off_mutex
);
2321 if (!adev
->gfx
.gfx_off_state
&& !adev
->gfx
.gfx_off_req_count
) {
2322 if (!amdgpu_dpm_set_powergating_by_smu(adev
, AMD_IP_BLOCK_TYPE_GFX
, true))
2323 adev
->gfx
.gfx_off_state
= true;
2325 mutex_unlock(&adev
->gfx
.gfx_off_mutex
);
2329 * amdgpu_device_ip_suspend_phase1 - run suspend for hardware IPs (phase 1)
2331 * @adev: amdgpu_device pointer
2333 * Main suspend function for hardware IPs. The list of all the hardware
2334 * IPs that make up the asic is walked, clockgating is disabled and the
2335 * suspend callbacks are run. suspend puts the hardware and software state
2336 * in each IP into a state suitable for suspend.
2337 * Returns 0 on success, negative error code on failure.
2339 static int amdgpu_device_ip_suspend_phase1(struct amdgpu_device
*adev
)
2344 for (i
= adev
->num_ip_blocks
- 1; i
>= 0; i
--) {
2345 if (!adev
->ip_blocks
[i
].status
.valid
)
2347 /* displays are handled separately */
2348 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_DCE
) {
2349 /* XXX handle errors */
2350 r
= adev
->ip_blocks
[i
].version
->funcs
->suspend(adev
);
2351 /* XXX handle errors */
2353 DRM_ERROR("suspend of IP block <%s> failed %d\n",
2354 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2357 adev
->ip_blocks
[i
].status
.hw
= false;
2365 * amdgpu_device_ip_suspend_phase2 - run suspend for hardware IPs (phase 2)
2367 * @adev: amdgpu_device pointer
2369 * Main suspend function for hardware IPs. The list of all the hardware
2370 * IPs that make up the asic is walked, clockgating is disabled and the
2371 * suspend callbacks are run. suspend puts the hardware and software state
2372 * in each IP into a state suitable for suspend.
2373 * Returns 0 on success, negative error code on failure.
2375 static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device
*adev
)
2379 for (i
= adev
->num_ip_blocks
- 1; i
>= 0; i
--) {
2380 if (!adev
->ip_blocks
[i
].status
.valid
)
2382 /* displays are handled in phase1 */
2383 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_DCE
)
2385 /* PSP lost connection when err_event_athub occurs */
2386 if (amdgpu_ras_intr_triggered() &&
2387 adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_PSP
) {
2388 adev
->ip_blocks
[i
].status
.hw
= false;
2391 /* XXX handle errors */
2392 r
= adev
->ip_blocks
[i
].version
->funcs
->suspend(adev
);
2393 /* XXX handle errors */
2395 DRM_ERROR("suspend of IP block <%s> failed %d\n",
2396 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2398 adev
->ip_blocks
[i
].status
.hw
= false;
2399 /* handle putting the SMC in the appropriate state */
2400 if(!amdgpu_sriov_vf(adev
)){
2401 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_SMC
) {
2402 r
= amdgpu_dpm_set_mp1_state(adev
, adev
->mp1_state
);
2404 DRM_ERROR("SMC failed to set mp1 state %d, %d\n",
2405 adev
->mp1_state
, r
);
2410 adev
->ip_blocks
[i
].status
.hw
= false;
2417 * amdgpu_device_ip_suspend - run suspend for hardware IPs
2419 * @adev: amdgpu_device pointer
2421 * Main suspend function for hardware IPs. The list of all the hardware
2422 * IPs that make up the asic is walked, clockgating is disabled and the
2423 * suspend callbacks are run. suspend puts the hardware and software state
2424 * in each IP into a state suitable for suspend.
2425 * Returns 0 on success, negative error code on failure.
2427 int amdgpu_device_ip_suspend(struct amdgpu_device
*adev
)
2431 if (amdgpu_sriov_vf(adev
))
2432 amdgpu_virt_request_full_gpu(adev
, false);
2434 r
= amdgpu_device_ip_suspend_phase1(adev
);
2437 r
= amdgpu_device_ip_suspend_phase2(adev
);
2439 if (amdgpu_sriov_vf(adev
))
2440 amdgpu_virt_release_full_gpu(adev
, false);
2445 static int amdgpu_device_ip_reinit_early_sriov(struct amdgpu_device
*adev
)
2449 static enum amd_ip_block_type ip_order
[] = {
2450 AMD_IP_BLOCK_TYPE_GMC
,
2451 AMD_IP_BLOCK_TYPE_COMMON
,
2452 AMD_IP_BLOCK_TYPE_PSP
,
2453 AMD_IP_BLOCK_TYPE_IH
,
2456 for (i
= 0; i
< ARRAY_SIZE(ip_order
); i
++) {
2458 struct amdgpu_ip_block
*block
;
2460 for (j
= 0; j
< adev
->num_ip_blocks
; j
++) {
2461 block
= &adev
->ip_blocks
[j
];
2463 block
->status
.hw
= false;
2464 if (block
->version
->type
!= ip_order
[i
] ||
2465 !block
->status
.valid
)
2468 r
= block
->version
->funcs
->hw_init(adev
);
2469 DRM_INFO("RE-INIT-early: %s %s\n", block
->version
->funcs
->name
, r
?"failed":"succeeded");
2472 block
->status
.hw
= true;
2479 static int amdgpu_device_ip_reinit_late_sriov(struct amdgpu_device
*adev
)
2483 static enum amd_ip_block_type ip_order
[] = {
2484 AMD_IP_BLOCK_TYPE_SMC
,
2485 AMD_IP_BLOCK_TYPE_DCE
,
2486 AMD_IP_BLOCK_TYPE_GFX
,
2487 AMD_IP_BLOCK_TYPE_SDMA
,
2488 AMD_IP_BLOCK_TYPE_UVD
,
2489 AMD_IP_BLOCK_TYPE_VCE
,
2490 AMD_IP_BLOCK_TYPE_VCN
2493 for (i
= 0; i
< ARRAY_SIZE(ip_order
); i
++) {
2495 struct amdgpu_ip_block
*block
;
2497 for (j
= 0; j
< adev
->num_ip_blocks
; j
++) {
2498 block
= &adev
->ip_blocks
[j
];
2500 if (block
->version
->type
!= ip_order
[i
] ||
2501 !block
->status
.valid
||
2505 if (block
->version
->type
== AMD_IP_BLOCK_TYPE_SMC
)
2506 r
= block
->version
->funcs
->resume(adev
);
2508 r
= block
->version
->funcs
->hw_init(adev
);
2510 DRM_INFO("RE-INIT-late: %s %s\n", block
->version
->funcs
->name
, r
?"failed":"succeeded");
2513 block
->status
.hw
= true;
2521 * amdgpu_device_ip_resume_phase1 - run resume for hardware IPs
2523 * @adev: amdgpu_device pointer
2525 * First resume function for hardware IPs. The list of all the hardware
2526 * IPs that make up the asic is walked and the resume callbacks are run for
2527 * COMMON, GMC, and IH. resume puts the hardware into a functional state
2528 * after a suspend and updates the software state as necessary. This
2529 * function is also used for restoring the GPU after a GPU reset.
2530 * Returns 0 on success, negative error code on failure.
2532 static int amdgpu_device_ip_resume_phase1(struct amdgpu_device
*adev
)
2536 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
2537 if (!adev
->ip_blocks
[i
].status
.valid
|| adev
->ip_blocks
[i
].status
.hw
)
2539 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_COMMON
||
2540 adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_GMC
||
2541 adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_IH
) {
2543 r
= adev
->ip_blocks
[i
].version
->funcs
->resume(adev
);
2545 DRM_ERROR("resume of IP block <%s> failed %d\n",
2546 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2549 adev
->ip_blocks
[i
].status
.hw
= true;
2557 * amdgpu_device_ip_resume_phase2 - run resume for hardware IPs
2559 * @adev: amdgpu_device pointer
2561 * First resume function for hardware IPs. The list of all the hardware
2562 * IPs that make up the asic is walked and the resume callbacks are run for
2563 * all blocks except COMMON, GMC, and IH. resume puts the hardware into a
2564 * functional state after a suspend and updates the software state as
2565 * necessary. This function is also used for restoring the GPU after a GPU
2567 * Returns 0 on success, negative error code on failure.
2569 static int amdgpu_device_ip_resume_phase2(struct amdgpu_device
*adev
)
2573 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
2574 if (!adev
->ip_blocks
[i
].status
.valid
|| adev
->ip_blocks
[i
].status
.hw
)
2576 if (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_COMMON
||
2577 adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_GMC
||
2578 adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_IH
||
2579 adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_PSP
)
2581 r
= adev
->ip_blocks
[i
].version
->funcs
->resume(adev
);
2583 DRM_ERROR("resume of IP block <%s> failed %d\n",
2584 adev
->ip_blocks
[i
].version
->funcs
->name
, r
);
2587 adev
->ip_blocks
[i
].status
.hw
= true;
2594 * amdgpu_device_ip_resume - run resume for hardware IPs
2596 * @adev: amdgpu_device pointer
2598 * Main resume function for hardware IPs. The hardware IPs
2599 * are split into two resume functions because they are
2600 * are also used in in recovering from a GPU reset and some additional
2601 * steps need to be take between them. In this case (S3/S4) they are
2603 * Returns 0 on success, negative error code on failure.
2605 static int amdgpu_device_ip_resume(struct amdgpu_device
*adev
)
2609 r
= amdgpu_device_ip_resume_phase1(adev
);
2613 r
= amdgpu_device_fw_loading(adev
);
2617 r
= amdgpu_device_ip_resume_phase2(adev
);
2623 * amdgpu_device_detect_sriov_bios - determine if the board supports SR-IOV
2625 * @adev: amdgpu_device pointer
2627 * Query the VBIOS data tables to determine if the board supports SR-IOV.
2629 static void amdgpu_device_detect_sriov_bios(struct amdgpu_device
*adev
)
2631 if (amdgpu_sriov_vf(adev
)) {
2632 if (adev
->is_atom_fw
) {
2633 if (amdgpu_atomfirmware_gpu_supports_virtualization(adev
))
2634 adev
->virt
.caps
|= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS
;
2636 if (amdgpu_atombios_has_gpu_virtualization_table(adev
))
2637 adev
->virt
.caps
|= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS
;
2640 if (!(adev
->virt
.caps
& AMDGPU_SRIOV_CAPS_SRIOV_VBIOS
))
2641 amdgpu_vf_error_put(adev
, AMDGIM_ERROR_VF_NO_VBIOS
, 0, 0);
2646 * amdgpu_device_asic_has_dc_support - determine if DC supports the asic
2648 * @asic_type: AMD asic type
2650 * Check if there is DC (new modesetting infrastructre) support for an asic.
2651 * returns true if DC has support, false if not.
2653 bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type
)
2655 switch (asic_type
) {
2656 #if defined(CONFIG_DRM_AMD_DC)
2662 * We have systems in the wild with these ASICs that require
2663 * LVDS and VGA support which is not supported with DC.
2665 * Fallback to the non-DC driver here by default so as not to
2666 * cause regressions.
2668 return amdgpu_dc
> 0;
2672 case CHIP_POLARIS10
:
2673 case CHIP_POLARIS11
:
2674 case CHIP_POLARIS12
:
2681 #if defined(CONFIG_DRM_AMD_DC_DCN)
2688 return amdgpu_dc
!= 0;
2692 DRM_INFO("Display Core has been requested via kernel parameter "
2693 "but isn't supported by ASIC, ignoring\n");
2699 * amdgpu_device_has_dc_support - check if dc is supported
2701 * @adev: amdgpu_device_pointer
2703 * Returns true for supported, false for not supported
2705 bool amdgpu_device_has_dc_support(struct amdgpu_device
*adev
)
2707 if (amdgpu_sriov_vf(adev
))
2710 return amdgpu_device_asic_has_dc_support(adev
->asic_type
);
2714 static void amdgpu_device_xgmi_reset_func(struct work_struct
*__work
)
2716 struct amdgpu_device
*adev
=
2717 container_of(__work
, struct amdgpu_device
, xgmi_reset_work
);
2718 struct amdgpu_hive_info
*hive
= amdgpu_get_xgmi_hive(adev
, 0);
2720 /* It's a bug to not have a hive within this function */
2725 * Use task barrier to synchronize all xgmi reset works across the
2726 * hive. task_barrier_enter and task_barrier_exit will block
2727 * until all the threads running the xgmi reset works reach
2728 * those points. task_barrier_full will do both blocks.
2730 if (amdgpu_asic_reset_method(adev
) == AMD_RESET_METHOD_BACO
) {
2732 task_barrier_enter(&hive
->tb
);
2733 adev
->asic_reset_res
= amdgpu_device_baco_enter(adev
->ddev
);
2735 if (adev
->asic_reset_res
)
2738 task_barrier_exit(&hive
->tb
);
2739 adev
->asic_reset_res
= amdgpu_device_baco_exit(adev
->ddev
);
2741 if (adev
->asic_reset_res
)
2744 if (adev
->mmhub
.funcs
&& adev
->mmhub
.funcs
->reset_ras_error_count
)
2745 adev
->mmhub
.funcs
->reset_ras_error_count(adev
);
2748 task_barrier_full(&hive
->tb
);
2749 adev
->asic_reset_res
= amdgpu_asic_reset(adev
);
2753 if (adev
->asic_reset_res
)
2754 DRM_WARN("ASIC reset failed with error, %d for drm dev, %s",
2755 adev
->asic_reset_res
, adev
->ddev
->unique
);
2758 static int amdgpu_device_get_job_timeout_settings(struct amdgpu_device
*adev
)
2760 char *input
= amdgpu_lockup_timeout
;
2761 char *timeout_setting
= NULL
;
2767 * By default timeout for non compute jobs is 10000.
2768 * And there is no timeout enforced on compute jobs.
2769 * In SR-IOV or passthrough mode, timeout for compute
2770 * jobs are 10000 by default.
2772 adev
->gfx_timeout
= msecs_to_jiffies(10000);
2773 adev
->sdma_timeout
= adev
->video_timeout
= adev
->gfx_timeout
;
2774 if (amdgpu_sriov_vf(adev
) || amdgpu_passthrough(adev
))
2775 adev
->compute_timeout
= adev
->gfx_timeout
;
2777 adev
->compute_timeout
= MAX_SCHEDULE_TIMEOUT
;
2779 if (strnlen(input
, AMDGPU_MAX_TIMEOUT_PARAM_LENGTH
)) {
2780 while ((timeout_setting
= strsep(&input
, ",")) &&
2781 strnlen(timeout_setting
, AMDGPU_MAX_TIMEOUT_PARAM_LENGTH
)) {
2782 ret
= kstrtol(timeout_setting
, 0, &timeout
);
2789 } else if (timeout
< 0) {
2790 timeout
= MAX_SCHEDULE_TIMEOUT
;
2792 timeout
= msecs_to_jiffies(timeout
);
2797 adev
->gfx_timeout
= timeout
;
2800 adev
->compute_timeout
= timeout
;
2803 adev
->sdma_timeout
= timeout
;
2806 adev
->video_timeout
= timeout
;
2813 * There is only one value specified and
2814 * it should apply to all non-compute jobs.
2817 adev
->sdma_timeout
= adev
->video_timeout
= adev
->gfx_timeout
;
2818 if (amdgpu_sriov_vf(adev
) || amdgpu_passthrough(adev
))
2819 adev
->compute_timeout
= adev
->gfx_timeout
;
2827 * amdgpu_device_init - initialize the driver
2829 * @adev: amdgpu_device pointer
2830 * @ddev: drm dev pointer
2831 * @pdev: pci dev pointer
2832 * @flags: driver flags
2834 * Initializes the driver info and hw (all asics).
2835 * Returns 0 for success or an error on failure.
2836 * Called at driver startup.
2838 int amdgpu_device_init(struct amdgpu_device
*adev
,
2839 struct drm_device
*ddev
,
2840 struct pci_dev
*pdev
,
2847 adev
->shutdown
= false;
2848 adev
->dev
= &pdev
->dev
;
2851 adev
->flags
= flags
;
2853 if (amdgpu_force_asic_type
>= 0 && amdgpu_force_asic_type
< CHIP_LAST
)
2854 adev
->asic_type
= amdgpu_force_asic_type
;
2856 adev
->asic_type
= flags
& AMD_ASIC_MASK
;
2858 adev
->usec_timeout
= AMDGPU_MAX_USEC_TIMEOUT
;
2859 if (amdgpu_emu_mode
== 1)
2860 adev
->usec_timeout
*= 10;
2861 adev
->gmc
.gart_size
= 512 * 1024 * 1024;
2862 adev
->accel_working
= false;
2863 adev
->num_rings
= 0;
2864 adev
->mman
.buffer_funcs
= NULL
;
2865 adev
->mman
.buffer_funcs_ring
= NULL
;
2866 adev
->vm_manager
.vm_pte_funcs
= NULL
;
2867 adev
->vm_manager
.vm_pte_num_scheds
= 0;
2868 adev
->gmc
.gmc_funcs
= NULL
;
2869 adev
->fence_context
= dma_fence_context_alloc(AMDGPU_MAX_RINGS
);
2870 bitmap_zero(adev
->gfx
.pipe_reserve_bitmap
, AMDGPU_MAX_COMPUTE_QUEUES
);
2872 adev
->smc_rreg
= &amdgpu_invalid_rreg
;
2873 adev
->smc_wreg
= &amdgpu_invalid_wreg
;
2874 adev
->pcie_rreg
= &amdgpu_invalid_rreg
;
2875 adev
->pcie_wreg
= &amdgpu_invalid_wreg
;
2876 adev
->pciep_rreg
= &amdgpu_invalid_rreg
;
2877 adev
->pciep_wreg
= &amdgpu_invalid_wreg
;
2878 adev
->pcie_rreg64
= &amdgpu_invalid_rreg64
;
2879 adev
->pcie_wreg64
= &amdgpu_invalid_wreg64
;
2880 adev
->uvd_ctx_rreg
= &amdgpu_invalid_rreg
;
2881 adev
->uvd_ctx_wreg
= &amdgpu_invalid_wreg
;
2882 adev
->didt_rreg
= &amdgpu_invalid_rreg
;
2883 adev
->didt_wreg
= &amdgpu_invalid_wreg
;
2884 adev
->gc_cac_rreg
= &amdgpu_invalid_rreg
;
2885 adev
->gc_cac_wreg
= &amdgpu_invalid_wreg
;
2886 adev
->audio_endpt_rreg
= &amdgpu_block_invalid_rreg
;
2887 adev
->audio_endpt_wreg
= &amdgpu_block_invalid_wreg
;
2889 DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n",
2890 amdgpu_asic_name
[adev
->asic_type
], pdev
->vendor
, pdev
->device
,
2891 pdev
->subsystem_vendor
, pdev
->subsystem_device
, pdev
->revision
);
2893 /* mutex initialization are all done here so we
2894 * can recall function without having locking issues */
2895 atomic_set(&adev
->irq
.ih
.lock
, 0);
2896 mutex_init(&adev
->firmware
.mutex
);
2897 mutex_init(&adev
->pm
.mutex
);
2898 mutex_init(&adev
->gfx
.gpu_clock_mutex
);
2899 mutex_init(&adev
->srbm_mutex
);
2900 mutex_init(&adev
->gfx
.pipe_reserve_mutex
);
2901 mutex_init(&adev
->gfx
.gfx_off_mutex
);
2902 mutex_init(&adev
->grbm_idx_mutex
);
2903 mutex_init(&adev
->mn_lock
);
2904 mutex_init(&adev
->virt
.vf_errors
.lock
);
2905 hash_init(adev
->mn_hash
);
2906 mutex_init(&adev
->lock_reset
);
2907 mutex_init(&adev
->psp
.mutex
);
2908 mutex_init(&adev
->notifier_lock
);
2910 r
= amdgpu_device_check_arguments(adev
);
2914 spin_lock_init(&adev
->mmio_idx_lock
);
2915 spin_lock_init(&adev
->smc_idx_lock
);
2916 spin_lock_init(&adev
->pcie_idx_lock
);
2917 spin_lock_init(&adev
->uvd_ctx_idx_lock
);
2918 spin_lock_init(&adev
->didt_idx_lock
);
2919 spin_lock_init(&adev
->gc_cac_idx_lock
);
2920 spin_lock_init(&adev
->se_cac_idx_lock
);
2921 spin_lock_init(&adev
->audio_endpt_idx_lock
);
2922 spin_lock_init(&adev
->mm_stats
.lock
);
2924 INIT_LIST_HEAD(&adev
->shadow_list
);
2925 mutex_init(&adev
->shadow_list_lock
);
2927 INIT_LIST_HEAD(&adev
->ring_lru_list
);
2928 spin_lock_init(&adev
->ring_lru_list_lock
);
2930 INIT_DELAYED_WORK(&adev
->delayed_init_work
,
2931 amdgpu_device_delayed_init_work_handler
);
2932 INIT_DELAYED_WORK(&adev
->gfx
.gfx_off_delay_work
,
2933 amdgpu_device_delay_enable_gfx_off
);
2935 INIT_WORK(&adev
->xgmi_reset_work
, amdgpu_device_xgmi_reset_func
);
2937 adev
->gfx
.gfx_off_req_count
= 1;
2938 adev
->pm
.ac_power
= power_supply_is_system_supplied() > 0 ? true : false;
2940 /* Registers mapping */
2941 /* TODO: block userspace mapping of io register */
2942 if (adev
->asic_type
>= CHIP_BONAIRE
) {
2943 adev
->rmmio_base
= pci_resource_start(adev
->pdev
, 5);
2944 adev
->rmmio_size
= pci_resource_len(adev
->pdev
, 5);
2946 adev
->rmmio_base
= pci_resource_start(adev
->pdev
, 2);
2947 adev
->rmmio_size
= pci_resource_len(adev
->pdev
, 2);
2950 adev
->rmmio
= ioremap(adev
->rmmio_base
, adev
->rmmio_size
);
2951 if (adev
->rmmio
== NULL
) {
2954 DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev
->rmmio_base
);
2955 DRM_INFO("register mmio size: %u\n", (unsigned)adev
->rmmio_size
);
2957 /* io port mapping */
2958 for (i
= 0; i
< DEVICE_COUNT_RESOURCE
; i
++) {
2959 if (pci_resource_flags(adev
->pdev
, i
) & IORESOURCE_IO
) {
2960 adev
->rio_mem_size
= pci_resource_len(adev
->pdev
, i
);
2961 adev
->rio_mem
= pci_iomap(adev
->pdev
, i
, adev
->rio_mem_size
);
2965 if (adev
->rio_mem
== NULL
)
2966 DRM_INFO("PCI I/O BAR is not found.\n");
2968 /* enable PCIE atomic ops */
2969 r
= pci_enable_atomic_ops_to_root(adev
->pdev
,
2970 PCI_EXP_DEVCAP2_ATOMIC_COMP32
|
2971 PCI_EXP_DEVCAP2_ATOMIC_COMP64
);
2973 adev
->have_atomics_support
= false;
2974 DRM_INFO("PCIE atomic ops is not supported\n");
2976 adev
->have_atomics_support
= true;
2979 amdgpu_device_get_pcie_info(adev
);
2982 DRM_INFO("MCBP is enabled\n");
2984 if (amdgpu_mes
&& adev
->asic_type
>= CHIP_NAVI10
)
2985 adev
->enable_mes
= true;
2987 if (amdgpu_discovery
&& adev
->asic_type
>= CHIP_NAVI10
) {
2988 r
= amdgpu_discovery_init(adev
);
2990 dev_err(adev
->dev
, "amdgpu_discovery_init failed\n");
2995 /* early init functions */
2996 r
= amdgpu_device_ip_early_init(adev
);
3000 r
= amdgpu_device_get_job_timeout_settings(adev
);
3002 dev_err(adev
->dev
, "invalid lockup_timeout parameter syntax\n");
3006 /* doorbell bar mapping and doorbell index init*/
3007 amdgpu_device_doorbell_init(adev
);
3009 /* if we have > 1 VGA cards, then disable the amdgpu VGA resources */
3010 /* this will fail for cards that aren't VGA class devices, just
3012 vga_client_register(adev
->pdev
, adev
, NULL
, amdgpu_device_vga_set_decode
);
3014 if (amdgpu_device_supports_boco(ddev
))
3016 if (amdgpu_has_atpx() &&
3017 (amdgpu_is_atpx_hybrid() ||
3018 amdgpu_has_atpx_dgpu_power_cntl()) &&
3019 !pci_is_thunderbolt_attached(adev
->pdev
))
3020 vga_switcheroo_register_client(adev
->pdev
,
3021 &amdgpu_switcheroo_ops
, boco
);
3023 vga_switcheroo_init_domain_pm_ops(adev
->dev
, &adev
->vga_pm_domain
);
3025 if (amdgpu_emu_mode
== 1) {
3026 /* post the asic on emulation mode */
3027 emu_soc_asic_init(adev
);
3028 goto fence_driver_init
;
3031 /* detect if we are with an SRIOV vbios */
3032 amdgpu_device_detect_sriov_bios(adev
);
3034 /* check if we need to reset the asic
3035 * E.g., driver was not cleanly unloaded previously, etc.
3037 if (!amdgpu_sriov_vf(adev
) && amdgpu_asic_need_reset_on_init(adev
)) {
3038 r
= amdgpu_asic_reset(adev
);
3040 dev_err(adev
->dev
, "asic reset on init failed\n");
3045 /* Post card if necessary */
3046 if (amdgpu_device_need_post(adev
)) {
3048 dev_err(adev
->dev
, "no vBIOS found\n");
3052 DRM_INFO("GPU posting now...\n");
3053 r
= amdgpu_atom_asic_init(adev
->mode_info
.atom_context
);
3055 dev_err(adev
->dev
, "gpu post error!\n");
3060 if (adev
->is_atom_fw
) {
3061 /* Initialize clocks */
3062 r
= amdgpu_atomfirmware_get_clock_info(adev
);
3064 dev_err(adev
->dev
, "amdgpu_atomfirmware_get_clock_info failed\n");
3065 amdgpu_vf_error_put(adev
, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL
, 0, 0);
3069 /* Initialize clocks */
3070 r
= amdgpu_atombios_get_clock_info(adev
);
3072 dev_err(adev
->dev
, "amdgpu_atombios_get_clock_info failed\n");
3073 amdgpu_vf_error_put(adev
, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL
, 0, 0);
3076 /* init i2c buses */
3077 if (!amdgpu_device_has_dc_support(adev
))
3078 amdgpu_atombios_i2c_init(adev
);
3083 r
= amdgpu_fence_driver_init(adev
);
3085 dev_err(adev
->dev
, "amdgpu_fence_driver_init failed\n");
3086 amdgpu_vf_error_put(adev
, AMDGIM_ERROR_VF_FENCE_INIT_FAIL
, 0, 0);
3090 /* init the mode config */
3091 drm_mode_config_init(adev
->ddev
);
3093 r
= amdgpu_device_ip_init(adev
);
3095 /* failed in exclusive mode due to timeout */
3096 if (amdgpu_sriov_vf(adev
) &&
3097 !amdgpu_sriov_runtime(adev
) &&
3098 amdgpu_virt_mmio_blocked(adev
) &&
3099 !amdgpu_virt_wait_reset(adev
)) {
3100 dev_err(adev
->dev
, "VF exclusive mode timeout\n");
3101 /* Don't send request since VF is inactive. */
3102 adev
->virt
.caps
&= ~AMDGPU_SRIOV_CAPS_RUNTIME
;
3103 adev
->virt
.ops
= NULL
;
3107 dev_err(adev
->dev
, "amdgpu_device_ip_init failed\n");
3108 amdgpu_vf_error_put(adev
, AMDGIM_ERROR_VF_AMDGPU_INIT_FAIL
, 0, 0);
3112 DRM_DEBUG("SE %d, SH per SE %d, CU per SH %d, active_cu_number %d\n",
3113 adev
->gfx
.config
.max_shader_engines
,
3114 adev
->gfx
.config
.max_sh_per_se
,
3115 adev
->gfx
.config
.max_cu_per_sh
,
3116 adev
->gfx
.cu_info
.number
);
3118 amdgpu_ctx_init_sched(adev
);
3120 adev
->accel_working
= true;
3122 amdgpu_vm_check_compute_bug(adev
);
3124 /* Initialize the buffer migration limit. */
3125 if (amdgpu_moverate
>= 0)
3126 max_MBps
= amdgpu_moverate
;
3128 max_MBps
= 8; /* Allow 8 MB/s. */
3129 /* Get a log2 for easy divisions. */
3130 adev
->mm_stats
.log2_max_MBps
= ilog2(max(1u, max_MBps
));
3132 amdgpu_fbdev_init(adev
);
3134 r
= amdgpu_pm_sysfs_init(adev
);
3136 adev
->pm_sysfs_en
= false;
3137 DRM_ERROR("registering pm debugfs failed (%d).\n", r
);
3139 adev
->pm_sysfs_en
= true;
3141 r
= amdgpu_ucode_sysfs_init(adev
);
3143 adev
->ucode_sysfs_en
= false;
3144 DRM_ERROR("Creating firmware sysfs failed (%d).\n", r
);
3146 adev
->ucode_sysfs_en
= true;
3148 if ((amdgpu_testing
& 1)) {
3149 if (adev
->accel_working
)
3150 amdgpu_test_moves(adev
);
3152 DRM_INFO("amdgpu: acceleration disabled, skipping move tests\n");
3154 if (amdgpu_benchmarking
) {
3155 if (adev
->accel_working
)
3156 amdgpu_benchmark(adev
, amdgpu_benchmarking
);
3158 DRM_INFO("amdgpu: acceleration disabled, skipping benchmarks\n");
3162 * Register gpu instance before amdgpu_device_enable_mgpu_fan_boost.
3163 * Otherwise the mgpu fan boost feature will be skipped due to the
3164 * gpu instance is counted less.
3166 amdgpu_register_gpu_instance(adev
);
3168 /* enable clockgating, etc. after ib tests, etc. since some blocks require
3169 * explicit gating rather than handling it automatically.
3171 r
= amdgpu_device_ip_late_init(adev
);
3173 dev_err(adev
->dev
, "amdgpu_device_ip_late_init failed\n");
3174 amdgpu_vf_error_put(adev
, AMDGIM_ERROR_VF_AMDGPU_LATE_INIT_FAIL
, 0, r
);
3179 amdgpu_ras_resume(adev
);
3181 queue_delayed_work(system_wq
, &adev
->delayed_init_work
,
3182 msecs_to_jiffies(AMDGPU_RESUME_MS
));
3184 r
= device_create_file(adev
->dev
, &dev_attr_pcie_replay_count
);
3186 dev_err(adev
->dev
, "Could not create pcie_replay_count");
3190 if (IS_ENABLED(CONFIG_PERF_EVENTS
))
3191 r
= amdgpu_pmu_init(adev
);
3193 dev_err(adev
->dev
, "amdgpu_pmu_init failed\n");
3198 amdgpu_vf_error_trans_all(adev
);
3200 vga_switcheroo_fini_domain_pm_ops(adev
->dev
);
3206 * amdgpu_device_fini - tear down the driver
3208 * @adev: amdgpu_device pointer
3210 * Tear down the driver info (all asics).
3211 * Called at driver shutdown.
3213 void amdgpu_device_fini(struct amdgpu_device
*adev
)
3217 DRM_INFO("amdgpu: finishing device.\n");
3218 flush_delayed_work(&adev
->delayed_init_work
);
3219 adev
->shutdown
= true;
3221 /* make sure IB test finished before entering exclusive mode
3222 * to avoid preemption on IB test
3224 if (amdgpu_sriov_vf(adev
))
3225 amdgpu_virt_request_full_gpu(adev
, false);
3227 /* disable all interrupts */
3228 amdgpu_irq_disable_all(adev
);
3229 if (adev
->mode_info
.mode_config_initialized
){
3230 if (!amdgpu_device_has_dc_support(adev
))
3231 drm_helper_force_disable_all(adev
->ddev
);
3233 drm_atomic_helper_shutdown(adev
->ddev
);
3235 amdgpu_fence_driver_fini(adev
);
3236 if (adev
->pm_sysfs_en
)
3237 amdgpu_pm_sysfs_fini(adev
);
3238 amdgpu_fbdev_fini(adev
);
3239 r
= amdgpu_device_ip_fini(adev
);
3240 if (adev
->firmware
.gpu_info_fw
) {
3241 release_firmware(adev
->firmware
.gpu_info_fw
);
3242 adev
->firmware
.gpu_info_fw
= NULL
;
3244 adev
->accel_working
= false;
3245 /* free i2c buses */
3246 if (!amdgpu_device_has_dc_support(adev
))
3247 amdgpu_i2c_fini(adev
);
3249 if (amdgpu_emu_mode
!= 1)
3250 amdgpu_atombios_fini(adev
);
3254 if (amdgpu_has_atpx() &&
3255 (amdgpu_is_atpx_hybrid() ||
3256 amdgpu_has_atpx_dgpu_power_cntl()) &&
3257 !pci_is_thunderbolt_attached(adev
->pdev
))
3258 vga_switcheroo_unregister_client(adev
->pdev
);
3259 if (amdgpu_device_supports_boco(adev
->ddev
))
3260 vga_switcheroo_fini_domain_pm_ops(adev
->dev
);
3261 vga_client_register(adev
->pdev
, NULL
, NULL
, NULL
);
3263 pci_iounmap(adev
->pdev
, adev
->rio_mem
);
3264 adev
->rio_mem
= NULL
;
3265 iounmap(adev
->rmmio
);
3267 amdgpu_device_doorbell_fini(adev
);
3269 device_remove_file(adev
->dev
, &dev_attr_pcie_replay_count
);
3270 if (adev
->ucode_sysfs_en
)
3271 amdgpu_ucode_sysfs_fini(adev
);
3272 if (IS_ENABLED(CONFIG_PERF_EVENTS
))
3273 amdgpu_pmu_fini(adev
);
3274 if (amdgpu_discovery
&& adev
->asic_type
>= CHIP_NAVI10
)
3275 amdgpu_discovery_fini(adev
);
3283 * amdgpu_device_suspend - initiate device suspend
3285 * @dev: drm dev pointer
3286 * @suspend: suspend state
3287 * @fbcon : notify the fbdev of suspend
3289 * Puts the hw in the suspend state (all asics).
3290 * Returns 0 for success or an error on failure.
3291 * Called at driver suspend.
3293 int amdgpu_device_suspend(struct drm_device
*dev
, bool fbcon
)
3295 struct amdgpu_device
*adev
;
3296 struct drm_crtc
*crtc
;
3297 struct drm_connector
*connector
;
3298 struct drm_connector_list_iter iter
;
3301 if (dev
== NULL
|| dev
->dev_private
== NULL
) {
3305 adev
= dev
->dev_private
;
3307 if (dev
->switch_power_state
== DRM_SWITCH_POWER_OFF
)
3310 adev
->in_suspend
= true;
3311 drm_kms_helper_poll_disable(dev
);
3314 amdgpu_fbdev_set_suspend(adev
, 1);
3316 cancel_delayed_work_sync(&adev
->delayed_init_work
);
3318 if (!amdgpu_device_has_dc_support(adev
)) {
3319 /* turn off display hw */
3320 drm_modeset_lock_all(dev
);
3321 drm_connector_list_iter_begin(dev
, &iter
);
3322 drm_for_each_connector_iter(connector
, &iter
)
3323 drm_helper_connector_dpms(connector
,
3325 drm_connector_list_iter_end(&iter
);
3326 drm_modeset_unlock_all(dev
);
3327 /* unpin the front buffers and cursors */
3328 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
3329 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
3330 struct drm_framebuffer
*fb
= crtc
->primary
->fb
;
3331 struct amdgpu_bo
*robj
;
3333 if (amdgpu_crtc
->cursor_bo
&& !adev
->enable_virtual_display
) {
3334 struct amdgpu_bo
*aobj
= gem_to_amdgpu_bo(amdgpu_crtc
->cursor_bo
);
3335 r
= amdgpu_bo_reserve(aobj
, true);
3337 amdgpu_bo_unpin(aobj
);
3338 amdgpu_bo_unreserve(aobj
);
3342 if (fb
== NULL
|| fb
->obj
[0] == NULL
) {
3345 robj
= gem_to_amdgpu_bo(fb
->obj
[0]);
3346 /* don't unpin kernel fb objects */
3347 if (!amdgpu_fbdev_robj_is_fb(adev
, robj
)) {
3348 r
= amdgpu_bo_reserve(robj
, true);
3350 amdgpu_bo_unpin(robj
);
3351 amdgpu_bo_unreserve(robj
);
3357 amdgpu_device_set_pg_state(adev
, AMD_PG_STATE_UNGATE
);
3358 amdgpu_device_set_cg_state(adev
, AMD_CG_STATE_UNGATE
);
3360 amdgpu_amdkfd_suspend(adev
, !fbcon
);
3362 amdgpu_ras_suspend(adev
);
3364 r
= amdgpu_device_ip_suspend_phase1(adev
);
3366 /* evict vram memory */
3367 amdgpu_bo_evict_vram(adev
);
3369 amdgpu_fence_driver_suspend(adev
);
3371 r
= amdgpu_device_ip_suspend_phase2(adev
);
3373 /* evict remaining vram memory
3374 * This second call to evict vram is to evict the gart page table
3377 amdgpu_bo_evict_vram(adev
);
3383 * amdgpu_device_resume - initiate device resume
3385 * @dev: drm dev pointer
3386 * @resume: resume state
3387 * @fbcon : notify the fbdev of resume
3389 * Bring the hw back to operating state (all asics).
3390 * Returns 0 for success or an error on failure.
3391 * Called at driver resume.
3393 int amdgpu_device_resume(struct drm_device
*dev
, bool fbcon
)
3395 struct drm_connector
*connector
;
3396 struct drm_connector_list_iter iter
;
3397 struct amdgpu_device
*adev
= dev
->dev_private
;
3398 struct drm_crtc
*crtc
;
3401 if (dev
->switch_power_state
== DRM_SWITCH_POWER_OFF
)
3405 if (amdgpu_device_need_post(adev
)) {
3406 r
= amdgpu_atom_asic_init(adev
->mode_info
.atom_context
);
3408 DRM_ERROR("amdgpu asic init failed\n");
3411 r
= amdgpu_device_ip_resume(adev
);
3413 DRM_ERROR("amdgpu_device_ip_resume failed (%d).\n", r
);
3416 amdgpu_fence_driver_resume(adev
);
3419 r
= amdgpu_device_ip_late_init(adev
);
3423 queue_delayed_work(system_wq
, &adev
->delayed_init_work
,
3424 msecs_to_jiffies(AMDGPU_RESUME_MS
));
3426 if (!amdgpu_device_has_dc_support(adev
)) {
3428 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
3429 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
3431 if (amdgpu_crtc
->cursor_bo
&& !adev
->enable_virtual_display
) {
3432 struct amdgpu_bo
*aobj
= gem_to_amdgpu_bo(amdgpu_crtc
->cursor_bo
);
3433 r
= amdgpu_bo_reserve(aobj
, true);
3435 r
= amdgpu_bo_pin(aobj
, AMDGPU_GEM_DOMAIN_VRAM
);
3437 DRM_ERROR("Failed to pin cursor BO (%d)\n", r
);
3438 amdgpu_crtc
->cursor_addr
= amdgpu_bo_gpu_offset(aobj
);
3439 amdgpu_bo_unreserve(aobj
);
3444 r
= amdgpu_amdkfd_resume(adev
, !fbcon
);
3448 /* Make sure IB tests flushed */
3449 flush_delayed_work(&adev
->delayed_init_work
);
3451 /* blat the mode back in */
3453 if (!amdgpu_device_has_dc_support(adev
)) {
3455 drm_helper_resume_force_mode(dev
);
3457 /* turn on display hw */
3458 drm_modeset_lock_all(dev
);
3460 drm_connector_list_iter_begin(dev
, &iter
);
3461 drm_for_each_connector_iter(connector
, &iter
)
3462 drm_helper_connector_dpms(connector
,
3464 drm_connector_list_iter_end(&iter
);
3466 drm_modeset_unlock_all(dev
);
3468 amdgpu_fbdev_set_suspend(adev
, 0);
3471 drm_kms_helper_poll_enable(dev
);
3473 amdgpu_ras_resume(adev
);
3476 * Most of the connector probing functions try to acquire runtime pm
3477 * refs to ensure that the GPU is powered on when connector polling is
3478 * performed. Since we're calling this from a runtime PM callback,
3479 * trying to acquire rpm refs will cause us to deadlock.
3481 * Since we're guaranteed to be holding the rpm lock, it's safe to
3482 * temporarily disable the rpm helpers so this doesn't deadlock us.
3485 dev
->dev
->power
.disable_depth
++;
3487 if (!amdgpu_device_has_dc_support(adev
))
3488 drm_helper_hpd_irq_event(dev
);
3490 drm_kms_helper_hotplug_event(dev
);
3492 dev
->dev
->power
.disable_depth
--;
3494 adev
->in_suspend
= false;
3500 * amdgpu_device_ip_check_soft_reset - did soft reset succeed
3502 * @adev: amdgpu_device pointer
3504 * The list of all the hardware IPs that make up the asic is walked and
3505 * the check_soft_reset callbacks are run. check_soft_reset determines
3506 * if the asic is still hung or not.
3507 * Returns true if any of the IPs are still in a hung state, false if not.
3509 static bool amdgpu_device_ip_check_soft_reset(struct amdgpu_device
*adev
)
3512 bool asic_hang
= false;
3514 if (amdgpu_sriov_vf(adev
))
3517 if (amdgpu_asic_need_full_reset(adev
))
3520 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
3521 if (!adev
->ip_blocks
[i
].status
.valid
)
3523 if (adev
->ip_blocks
[i
].version
->funcs
->check_soft_reset
)
3524 adev
->ip_blocks
[i
].status
.hang
=
3525 adev
->ip_blocks
[i
].version
->funcs
->check_soft_reset(adev
);
3526 if (adev
->ip_blocks
[i
].status
.hang
) {
3527 DRM_INFO("IP block:%s is hung!\n", adev
->ip_blocks
[i
].version
->funcs
->name
);
3535 * amdgpu_device_ip_pre_soft_reset - prepare for soft reset
3537 * @adev: amdgpu_device pointer
3539 * The list of all the hardware IPs that make up the asic is walked and the
3540 * pre_soft_reset callbacks are run if the block is hung. pre_soft_reset
3541 * handles any IP specific hardware or software state changes that are
3542 * necessary for a soft reset to succeed.
3543 * Returns 0 on success, negative error code on failure.
3545 static int amdgpu_device_ip_pre_soft_reset(struct amdgpu_device
*adev
)
3549 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
3550 if (!adev
->ip_blocks
[i
].status
.valid
)
3552 if (adev
->ip_blocks
[i
].status
.hang
&&
3553 adev
->ip_blocks
[i
].version
->funcs
->pre_soft_reset
) {
3554 r
= adev
->ip_blocks
[i
].version
->funcs
->pre_soft_reset(adev
);
3564 * amdgpu_device_ip_need_full_reset - check if a full asic reset is needed
3566 * @adev: amdgpu_device pointer
3568 * Some hardware IPs cannot be soft reset. If they are hung, a full gpu
3569 * reset is necessary to recover.
3570 * Returns true if a full asic reset is required, false if not.
3572 static bool amdgpu_device_ip_need_full_reset(struct amdgpu_device
*adev
)
3576 if (amdgpu_asic_need_full_reset(adev
))
3579 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
3580 if (!adev
->ip_blocks
[i
].status
.valid
)
3582 if ((adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_GMC
) ||
3583 (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_SMC
) ||
3584 (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_ACP
) ||
3585 (adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_DCE
) ||
3586 adev
->ip_blocks
[i
].version
->type
== AMD_IP_BLOCK_TYPE_PSP
) {
3587 if (adev
->ip_blocks
[i
].status
.hang
) {
3588 DRM_INFO("Some block need full reset!\n");
3597 * amdgpu_device_ip_soft_reset - do a soft reset
3599 * @adev: amdgpu_device pointer
3601 * The list of all the hardware IPs that make up the asic is walked and the
3602 * soft_reset callbacks are run if the block is hung. soft_reset handles any
3603 * IP specific hardware or software state changes that are necessary to soft
3605 * Returns 0 on success, negative error code on failure.
3607 static int amdgpu_device_ip_soft_reset(struct amdgpu_device
*adev
)
3611 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
3612 if (!adev
->ip_blocks
[i
].status
.valid
)
3614 if (adev
->ip_blocks
[i
].status
.hang
&&
3615 adev
->ip_blocks
[i
].version
->funcs
->soft_reset
) {
3616 r
= adev
->ip_blocks
[i
].version
->funcs
->soft_reset(adev
);
3626 * amdgpu_device_ip_post_soft_reset - clean up from soft reset
3628 * @adev: amdgpu_device pointer
3630 * The list of all the hardware IPs that make up the asic is walked and the
3631 * post_soft_reset callbacks are run if the asic was hung. post_soft_reset
3632 * handles any IP specific hardware or software state changes that are
3633 * necessary after the IP has been soft reset.
3634 * Returns 0 on success, negative error code on failure.
3636 static int amdgpu_device_ip_post_soft_reset(struct amdgpu_device
*adev
)
3640 for (i
= 0; i
< adev
->num_ip_blocks
; i
++) {
3641 if (!adev
->ip_blocks
[i
].status
.valid
)
3643 if (adev
->ip_blocks
[i
].status
.hang
&&
3644 adev
->ip_blocks
[i
].version
->funcs
->post_soft_reset
)
3645 r
= adev
->ip_blocks
[i
].version
->funcs
->post_soft_reset(adev
);
3654 * amdgpu_device_recover_vram - Recover some VRAM contents
3656 * @adev: amdgpu_device pointer
3658 * Restores the contents of VRAM buffers from the shadows in GTT. Used to
3659 * restore things like GPUVM page tables after a GPU reset where
3660 * the contents of VRAM might be lost.
3663 * 0 on success, negative error code on failure.
3665 static int amdgpu_device_recover_vram(struct amdgpu_device
*adev
)
3667 struct dma_fence
*fence
= NULL
, *next
= NULL
;
3668 struct amdgpu_bo
*shadow
;
3671 if (amdgpu_sriov_runtime(adev
))
3672 tmo
= msecs_to_jiffies(8000);
3674 tmo
= msecs_to_jiffies(100);
3676 DRM_INFO("recover vram bo from shadow start\n");
3677 mutex_lock(&adev
->shadow_list_lock
);
3678 list_for_each_entry(shadow
, &adev
->shadow_list
, shadow_list
) {
3680 /* No need to recover an evicted BO */
3681 if (shadow
->tbo
.mem
.mem_type
!= TTM_PL_TT
||
3682 shadow
->tbo
.mem
.start
== AMDGPU_BO_INVALID_OFFSET
||
3683 shadow
->parent
->tbo
.mem
.mem_type
!= TTM_PL_VRAM
)
3686 r
= amdgpu_bo_restore_shadow(shadow
, &next
);
3691 tmo
= dma_fence_wait_timeout(fence
, false, tmo
);
3692 dma_fence_put(fence
);
3697 } else if (tmo
< 0) {
3705 mutex_unlock(&adev
->shadow_list_lock
);
3708 tmo
= dma_fence_wait_timeout(fence
, false, tmo
);
3709 dma_fence_put(fence
);
3711 if (r
< 0 || tmo
<= 0) {
3712 DRM_ERROR("recover vram bo from shadow failed, r is %ld, tmo is %ld\n", r
, tmo
);
3716 DRM_INFO("recover vram bo from shadow done\n");
3722 * amdgpu_device_reset_sriov - reset ASIC for SR-IOV vf
3724 * @adev: amdgpu device pointer
3725 * @from_hypervisor: request from hypervisor
3727 * do VF FLR and reinitialize Asic
3728 * return 0 means succeeded otherwise failed
3730 static int amdgpu_device_reset_sriov(struct amdgpu_device
*adev
,
3731 bool from_hypervisor
)
3735 if (from_hypervisor
)
3736 r
= amdgpu_virt_request_full_gpu(adev
, true);
3738 r
= amdgpu_virt_reset_gpu(adev
);
3742 /* Resume IP prior to SMC */
3743 r
= amdgpu_device_ip_reinit_early_sriov(adev
);
3747 amdgpu_virt_init_data_exchange(adev
);
3748 /* we need recover gart prior to run SMC/CP/SDMA resume */
3749 amdgpu_gtt_mgr_recover(&adev
->mman
.bdev
.man
[TTM_PL_TT
]);
3751 r
= amdgpu_device_fw_loading(adev
);
3755 /* now we are okay to resume SMC/CP/SDMA */
3756 r
= amdgpu_device_ip_reinit_late_sriov(adev
);
3760 amdgpu_irq_gpu_reset_resume_helper(adev
);
3761 r
= amdgpu_ib_ring_tests(adev
);
3762 amdgpu_amdkfd_post_reset(adev
);
3765 amdgpu_virt_release_full_gpu(adev
, true);
3766 if (!r
&& adev
->virt
.gim_feature
& AMDGIM_FEATURE_GIM_FLR_VRAMLOST
) {
3767 amdgpu_inc_vram_lost(adev
);
3768 r
= amdgpu_device_recover_vram(adev
);
3775 * amdgpu_device_should_recover_gpu - check if we should try GPU recovery
3777 * @adev: amdgpu device pointer
3779 * Check amdgpu_gpu_recovery and SRIOV status to see if we should try to recover
3782 bool amdgpu_device_should_recover_gpu(struct amdgpu_device
*adev
)
3784 if (!amdgpu_device_ip_check_soft_reset(adev
)) {
3785 DRM_INFO("Timeout, but no hardware hang detected.\n");
3789 if (amdgpu_gpu_recovery
== 0)
3792 if (amdgpu_sriov_vf(adev
))
3795 if (amdgpu_gpu_recovery
== -1) {
3796 switch (adev
->asic_type
) {
3802 case CHIP_POLARIS10
:
3803 case CHIP_POLARIS11
:
3804 case CHIP_POLARIS12
:
3824 DRM_INFO("GPU recovery disabled.\n");
3829 static int amdgpu_device_pre_asic_reset(struct amdgpu_device
*adev
,
3830 struct amdgpu_job
*job
,
3831 bool *need_full_reset_arg
)
3834 bool need_full_reset
= *need_full_reset_arg
;
3836 /* block all schedulers and reset given job's ring */
3837 for (i
= 0; i
< AMDGPU_MAX_RINGS
; ++i
) {
3838 struct amdgpu_ring
*ring
= adev
->rings
[i
];
3840 if (!ring
|| !ring
->sched
.thread
)
3843 /* after all hw jobs are reset, hw fence is meaningless, so force_completion */
3844 amdgpu_fence_driver_force_completion(ring
);
3848 drm_sched_increase_karma(&job
->base
);
3850 /* Don't suspend on bare metal if we are not going to HW reset the ASIC */
3851 if (!amdgpu_sriov_vf(adev
)) {
3853 if (!need_full_reset
)
3854 need_full_reset
= amdgpu_device_ip_need_full_reset(adev
);
3856 if (!need_full_reset
) {
3857 amdgpu_device_ip_pre_soft_reset(adev
);
3858 r
= amdgpu_device_ip_soft_reset(adev
);
3859 amdgpu_device_ip_post_soft_reset(adev
);
3860 if (r
|| amdgpu_device_ip_check_soft_reset(adev
)) {
3861 DRM_INFO("soft reset failed, will fallback to full reset!\n");
3862 need_full_reset
= true;
3866 if (need_full_reset
)
3867 r
= amdgpu_device_ip_suspend(adev
);
3869 *need_full_reset_arg
= need_full_reset
;
3875 static int amdgpu_do_asic_reset(struct amdgpu_hive_info
*hive
,
3876 struct list_head
*device_list_handle
,
3877 bool *need_full_reset_arg
)
3879 struct amdgpu_device
*tmp_adev
= NULL
;
3880 bool need_full_reset
= *need_full_reset_arg
, vram_lost
= false;
3884 * ASIC reset has to be done on all HGMI hive nodes ASAP
3885 * to allow proper links negotiation in FW (within 1 sec)
3887 if (need_full_reset
) {
3888 list_for_each_entry(tmp_adev
, device_list_handle
, gmc
.xgmi
.head
) {
3889 /* For XGMI run all resets in parallel to speed up the process */
3890 if (tmp_adev
->gmc
.xgmi
.num_physical_nodes
> 1) {
3891 if (!queue_work(system_unbound_wq
, &tmp_adev
->xgmi_reset_work
))
3894 r
= amdgpu_asic_reset(tmp_adev
);
3897 DRM_ERROR("ASIC reset failed with error, %d for drm dev, %s",
3898 r
, tmp_adev
->ddev
->unique
);
3903 /* For XGMI wait for all resets to complete before proceed */
3905 list_for_each_entry(tmp_adev
, device_list_handle
,
3907 if (tmp_adev
->gmc
.xgmi
.num_physical_nodes
> 1) {
3908 flush_work(&tmp_adev
->xgmi_reset_work
);
3909 r
= tmp_adev
->asic_reset_res
;
3917 if (!r
&& amdgpu_ras_intr_triggered()) {
3918 list_for_each_entry(tmp_adev
, device_list_handle
, gmc
.xgmi
.head
) {
3919 if (tmp_adev
->mmhub
.funcs
&&
3920 tmp_adev
->mmhub
.funcs
->reset_ras_error_count
)
3921 tmp_adev
->mmhub
.funcs
->reset_ras_error_count(tmp_adev
);
3924 amdgpu_ras_intr_cleared();
3927 list_for_each_entry(tmp_adev
, device_list_handle
, gmc
.xgmi
.head
) {
3928 if (need_full_reset
) {
3930 if (amdgpu_atom_asic_init(tmp_adev
->mode_info
.atom_context
))
3931 DRM_WARN("asic atom init failed!");
3934 dev_info(tmp_adev
->dev
, "GPU reset succeeded, trying to resume\n");
3935 r
= amdgpu_device_ip_resume_phase1(tmp_adev
);
3939 vram_lost
= amdgpu_device_check_vram_lost(tmp_adev
);
3941 DRM_INFO("VRAM is lost due to GPU reset!\n");
3942 amdgpu_inc_vram_lost(tmp_adev
);
3945 r
= amdgpu_gtt_mgr_recover(
3946 &tmp_adev
->mman
.bdev
.man
[TTM_PL_TT
]);
3950 r
= amdgpu_device_fw_loading(tmp_adev
);
3954 r
= amdgpu_device_ip_resume_phase2(tmp_adev
);
3959 amdgpu_device_fill_reset_magic(tmp_adev
);
3962 * Add this ASIC as tracked as reset was already
3963 * complete successfully.
3965 amdgpu_register_gpu_instance(tmp_adev
);
3967 r
= amdgpu_device_ip_late_init(tmp_adev
);
3971 amdgpu_fbdev_set_suspend(tmp_adev
, 0);
3974 amdgpu_ras_resume(tmp_adev
);
3976 /* Update PSP FW topology after reset */
3977 if (hive
&& tmp_adev
->gmc
.xgmi
.num_physical_nodes
> 1)
3978 r
= amdgpu_xgmi_update_topology(hive
, tmp_adev
);
3985 amdgpu_irq_gpu_reset_resume_helper(tmp_adev
);
3986 r
= amdgpu_ib_ring_tests(tmp_adev
);
3988 dev_err(tmp_adev
->dev
, "ib ring test failed (%d).\n", r
);
3989 r
= amdgpu_device_ip_suspend(tmp_adev
);
3990 need_full_reset
= true;
3997 r
= amdgpu_device_recover_vram(tmp_adev
);
3999 tmp_adev
->asic_reset_res
= r
;
4003 *need_full_reset_arg
= need_full_reset
;
4007 static bool amdgpu_device_lock_adev(struct amdgpu_device
*adev
, bool trylock
)
4010 if (!mutex_trylock(&adev
->lock_reset
))
4013 mutex_lock(&adev
->lock_reset
);
4015 atomic_inc(&adev
->gpu_reset_counter
);
4016 adev
->in_gpu_reset
= true;
4017 switch (amdgpu_asic_reset_method(adev
)) {
4018 case AMD_RESET_METHOD_MODE1
:
4019 adev
->mp1_state
= PP_MP1_STATE_SHUTDOWN
;
4021 case AMD_RESET_METHOD_MODE2
:
4022 adev
->mp1_state
= PP_MP1_STATE_RESET
;
4025 adev
->mp1_state
= PP_MP1_STATE_NONE
;
4032 static void amdgpu_device_unlock_adev(struct amdgpu_device
*adev
)
4034 amdgpu_vf_error_trans_all(adev
);
4035 adev
->mp1_state
= PP_MP1_STATE_NONE
;
4036 adev
->in_gpu_reset
= false;
4037 mutex_unlock(&adev
->lock_reset
);
4041 * amdgpu_device_gpu_recover - reset the asic and recover scheduler
4043 * @adev: amdgpu device pointer
4044 * @job: which job trigger hang
4046 * Attempt to reset the GPU if it has hung (all asics).
4047 * Attempt to do soft-reset or full-reset and reinitialize Asic
4048 * Returns 0 for success or an error on failure.
4051 int amdgpu_device_gpu_recover(struct amdgpu_device
*adev
,
4052 struct amdgpu_job
*job
)
4054 struct list_head device_list
, *device_list_handle
= NULL
;
4055 bool need_full_reset
, job_signaled
;
4056 struct amdgpu_hive_info
*hive
= NULL
;
4057 struct amdgpu_device
*tmp_adev
= NULL
;
4059 bool in_ras_intr
= amdgpu_ras_intr_triggered();
4061 (amdgpu_asic_reset_method(adev
) == AMD_RESET_METHOD_BACO
) ?
4065 * Flush RAM to disk so that after reboot
4066 * the user can read log and see why the system rebooted.
4068 if (in_ras_intr
&& !use_baco
&& amdgpu_ras_get_context(adev
)->reboot
) {
4070 DRM_WARN("Emergency reboot.");
4073 emergency_restart();
4076 need_full_reset
= job_signaled
= false;
4077 INIT_LIST_HEAD(&device_list
);
4079 dev_info(adev
->dev
, "GPU %s begin!\n",
4080 (in_ras_intr
&& !use_baco
) ? "jobs stop":"reset");
4082 cancel_delayed_work_sync(&adev
->delayed_init_work
);
4084 hive
= amdgpu_get_xgmi_hive(adev
, false);
4087 * Here we trylock to avoid chain of resets executing from
4088 * either trigger by jobs on different adevs in XGMI hive or jobs on
4089 * different schedulers for same device while this TO handler is running.
4090 * We always reset all schedulers for device and all devices for XGMI
4091 * hive so that should take care of them too.
4094 if (hive
&& !mutex_trylock(&hive
->reset_lock
)) {
4095 DRM_INFO("Bailing on TDR for s_job:%llx, hive: %llx as another already in progress",
4096 job
? job
->base
.id
: -1, hive
->hive_id
);
4100 /* Start with adev pre asic reset first for soft reset check.*/
4101 if (!amdgpu_device_lock_adev(adev
, !hive
)) {
4102 DRM_INFO("Bailing on TDR for s_job:%llx, as another already in progress",
4103 job
? job
->base
.id
: -1);
4107 /* Block kfd: SRIOV would do it separately */
4108 if (!amdgpu_sriov_vf(adev
))
4109 amdgpu_amdkfd_pre_reset(adev
);
4111 /* Build list of devices to reset */
4112 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1) {
4114 /*unlock kfd: SRIOV would do it separately */
4115 if (!amdgpu_sriov_vf(adev
))
4116 amdgpu_amdkfd_post_reset(adev
);
4117 amdgpu_device_unlock_adev(adev
);
4122 * In case we are in XGMI hive mode device reset is done for all the
4123 * nodes in the hive to retrain all XGMI links and hence the reset
4124 * sequence is executed in loop on all nodes.
4126 device_list_handle
= &hive
->device_list
;
4128 list_add_tail(&adev
->gmc
.xgmi
.head
, &device_list
);
4129 device_list_handle
= &device_list
;
4132 /* block all schedulers and reset given job's ring */
4133 list_for_each_entry(tmp_adev
, device_list_handle
, gmc
.xgmi
.head
) {
4134 if (tmp_adev
!= adev
) {
4135 amdgpu_device_lock_adev(tmp_adev
, false);
4136 if (!amdgpu_sriov_vf(tmp_adev
))
4137 amdgpu_amdkfd_pre_reset(tmp_adev
);
4141 * Mark these ASICs to be reseted as untracked first
4142 * And add them back after reset completed
4144 amdgpu_unregister_gpu_instance(tmp_adev
);
4146 amdgpu_fbdev_set_suspend(adev
, 1);
4148 /* disable ras on ALL IPs */
4149 if (!(in_ras_intr
&& !use_baco
) &&
4150 amdgpu_device_ip_need_full_reset(tmp_adev
))
4151 amdgpu_ras_suspend(tmp_adev
);
4153 for (i
= 0; i
< AMDGPU_MAX_RINGS
; ++i
) {
4154 struct amdgpu_ring
*ring
= tmp_adev
->rings
[i
];
4156 if (!ring
|| !ring
->sched
.thread
)
4159 drm_sched_stop(&ring
->sched
, job
? &job
->base
: NULL
);
4161 if (in_ras_intr
&& !use_baco
)
4162 amdgpu_job_stop_all_jobs_on_sched(&ring
->sched
);
4167 if (in_ras_intr
&& !use_baco
)
4168 goto skip_sched_resume
;
4171 * Must check guilty signal here since after this point all old
4172 * HW fences are force signaled.
4174 * job->base holds a reference to parent fence
4176 if (job
&& job
->base
.s_fence
->parent
&&
4177 dma_fence_is_signaled(job
->base
.s_fence
->parent
))
4178 job_signaled
= true;
4181 dev_info(adev
->dev
, "Guilty job already signaled, skipping HW reset");
4186 /* Guilty job will be freed after this*/
4187 r
= amdgpu_device_pre_asic_reset(adev
, job
, &need_full_reset
);
4189 /*TODO Should we stop ?*/
4190 DRM_ERROR("GPU pre asic reset failed with err, %d for drm dev, %s ",
4191 r
, adev
->ddev
->unique
);
4192 adev
->asic_reset_res
= r
;
4195 retry
: /* Rest of adevs pre asic reset from XGMI hive. */
4196 list_for_each_entry(tmp_adev
, device_list_handle
, gmc
.xgmi
.head
) {
4198 if (tmp_adev
== adev
)
4201 r
= amdgpu_device_pre_asic_reset(tmp_adev
,
4204 /*TODO Should we stop ?*/
4206 DRM_ERROR("GPU pre asic reset failed with err, %d for drm dev, %s ",
4207 r
, tmp_adev
->ddev
->unique
);
4208 tmp_adev
->asic_reset_res
= r
;
4212 /* Actual ASIC resets if needed.*/
4213 /* TODO Implement XGMI hive reset logic for SRIOV */
4214 if (amdgpu_sriov_vf(adev
)) {
4215 r
= amdgpu_device_reset_sriov(adev
, job
? false : true);
4217 adev
->asic_reset_res
= r
;
4219 r
= amdgpu_do_asic_reset(hive
, device_list_handle
, &need_full_reset
);
4220 if (r
&& r
== -EAGAIN
)
4226 /* Post ASIC reset for all devs .*/
4227 list_for_each_entry(tmp_adev
, device_list_handle
, gmc
.xgmi
.head
) {
4229 for (i
= 0; i
< AMDGPU_MAX_RINGS
; ++i
) {
4230 struct amdgpu_ring
*ring
= tmp_adev
->rings
[i
];
4232 if (!ring
|| !ring
->sched
.thread
)
4235 /* No point to resubmit jobs if we didn't HW reset*/
4236 if (!tmp_adev
->asic_reset_res
&& !job_signaled
)
4237 drm_sched_resubmit_jobs(&ring
->sched
);
4239 drm_sched_start(&ring
->sched
, !tmp_adev
->asic_reset_res
);
4242 if (!amdgpu_device_has_dc_support(tmp_adev
) && !job_signaled
) {
4243 drm_helper_resume_force_mode(tmp_adev
->ddev
);
4246 tmp_adev
->asic_reset_res
= 0;
4249 /* bad news, how to tell it to userspace ? */
4250 dev_info(tmp_adev
->dev
, "GPU reset(%d) failed\n", atomic_read(&tmp_adev
->gpu_reset_counter
));
4251 amdgpu_vf_error_put(tmp_adev
, AMDGIM_ERROR_VF_GPU_RESET_FAIL
, 0, r
);
4253 dev_info(tmp_adev
->dev
, "GPU reset(%d) succeeded!\n", atomic_read(&tmp_adev
->gpu_reset_counter
));
4258 list_for_each_entry(tmp_adev
, device_list_handle
, gmc
.xgmi
.head
) {
4259 /*unlock kfd: SRIOV would do it separately */
4260 if (!(in_ras_intr
&& !use_baco
) && !amdgpu_sriov_vf(tmp_adev
))
4261 amdgpu_amdkfd_post_reset(tmp_adev
);
4262 amdgpu_device_unlock_adev(tmp_adev
);
4266 mutex_unlock(&hive
->reset_lock
);
4269 dev_info(adev
->dev
, "GPU reset end with ret = %d\n", r
);
4274 * amdgpu_device_get_pcie_info - fence pcie info about the PCIE slot
4276 * @adev: amdgpu_device pointer
4278 * Fetchs and stores in the driver the PCIE capabilities (gen speed
4279 * and lanes) of the slot the device is in. Handles APUs and
4280 * virtualized environments where PCIE config space may not be available.
4282 static void amdgpu_device_get_pcie_info(struct amdgpu_device
*adev
)
4284 struct pci_dev
*pdev
;
4285 enum pci_bus_speed speed_cap
, platform_speed_cap
;
4286 enum pcie_link_width platform_link_width
;
4288 if (amdgpu_pcie_gen_cap
)
4289 adev
->pm
.pcie_gen_mask
= amdgpu_pcie_gen_cap
;
4291 if (amdgpu_pcie_lane_cap
)
4292 adev
->pm
.pcie_mlw_mask
= amdgpu_pcie_lane_cap
;
4294 /* covers APUs as well */
4295 if (pci_is_root_bus(adev
->pdev
->bus
)) {
4296 if (adev
->pm
.pcie_gen_mask
== 0)
4297 adev
->pm
.pcie_gen_mask
= AMDGPU_DEFAULT_PCIE_GEN_MASK
;
4298 if (adev
->pm
.pcie_mlw_mask
== 0)
4299 adev
->pm
.pcie_mlw_mask
= AMDGPU_DEFAULT_PCIE_MLW_MASK
;
4303 if (adev
->pm
.pcie_gen_mask
&& adev
->pm
.pcie_mlw_mask
)
4306 pcie_bandwidth_available(adev
->pdev
, NULL
,
4307 &platform_speed_cap
, &platform_link_width
);
4309 if (adev
->pm
.pcie_gen_mask
== 0) {
4312 speed_cap
= pcie_get_speed_cap(pdev
);
4313 if (speed_cap
== PCI_SPEED_UNKNOWN
) {
4314 adev
->pm
.pcie_gen_mask
|= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1
|
4315 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2
|
4316 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3
);
4318 if (speed_cap
== PCIE_SPEED_16_0GT
)
4319 adev
->pm
.pcie_gen_mask
|= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1
|
4320 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2
|
4321 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3
|
4322 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN4
);
4323 else if (speed_cap
== PCIE_SPEED_8_0GT
)
4324 adev
->pm
.pcie_gen_mask
|= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1
|
4325 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2
|
4326 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3
);
4327 else if (speed_cap
== PCIE_SPEED_5_0GT
)
4328 adev
->pm
.pcie_gen_mask
|= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1
|
4329 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2
);
4331 adev
->pm
.pcie_gen_mask
|= CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1
;
4334 if (platform_speed_cap
== PCI_SPEED_UNKNOWN
) {
4335 adev
->pm
.pcie_gen_mask
|= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1
|
4336 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2
);
4338 if (platform_speed_cap
== PCIE_SPEED_16_0GT
)
4339 adev
->pm
.pcie_gen_mask
|= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1
|
4340 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2
|
4341 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3
|
4342 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN4
);
4343 else if (platform_speed_cap
== PCIE_SPEED_8_0GT
)
4344 adev
->pm
.pcie_gen_mask
|= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1
|
4345 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2
|
4346 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3
);
4347 else if (platform_speed_cap
== PCIE_SPEED_5_0GT
)
4348 adev
->pm
.pcie_gen_mask
|= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1
|
4349 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2
);
4351 adev
->pm
.pcie_gen_mask
|= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1
;
4355 if (adev
->pm
.pcie_mlw_mask
== 0) {
4356 if (platform_link_width
== PCIE_LNK_WIDTH_UNKNOWN
) {
4357 adev
->pm
.pcie_mlw_mask
|= AMDGPU_DEFAULT_PCIE_MLW_MASK
;
4359 switch (platform_link_width
) {
4361 adev
->pm
.pcie_mlw_mask
= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32
|
4362 CAIL_PCIE_LINK_WIDTH_SUPPORT_X16
|
4363 CAIL_PCIE_LINK_WIDTH_SUPPORT_X12
|
4364 CAIL_PCIE_LINK_WIDTH_SUPPORT_X8
|
4365 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4
|
4366 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2
|
4367 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1
);
4370 adev
->pm
.pcie_mlw_mask
= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16
|
4371 CAIL_PCIE_LINK_WIDTH_SUPPORT_X12
|
4372 CAIL_PCIE_LINK_WIDTH_SUPPORT_X8
|
4373 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4
|
4374 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2
|
4375 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1
);
4378 adev
->pm
.pcie_mlw_mask
= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12
|
4379 CAIL_PCIE_LINK_WIDTH_SUPPORT_X8
|
4380 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4
|
4381 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2
|
4382 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1
);
4385 adev
->pm
.pcie_mlw_mask
= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8
|
4386 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4
|
4387 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2
|
4388 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1
);
4391 adev
->pm
.pcie_mlw_mask
= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4
|
4392 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2
|
4393 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1
);
4396 adev
->pm
.pcie_mlw_mask
= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2
|
4397 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1
);
4400 adev
->pm
.pcie_mlw_mask
= CAIL_PCIE_LINK_WIDTH_SUPPORT_X1
;
4409 int amdgpu_device_baco_enter(struct drm_device
*dev
)
4411 struct amdgpu_device
*adev
= dev
->dev_private
;
4412 struct amdgpu_ras
*ras
= amdgpu_ras_get_context(adev
);
4414 if (!amdgpu_device_supports_baco(adev
->ddev
))
4417 if (ras
&& ras
->supported
)
4418 adev
->nbio
.funcs
->enable_doorbell_interrupt(adev
, false);
4420 return amdgpu_dpm_baco_enter(adev
);
4423 int amdgpu_device_baco_exit(struct drm_device
*dev
)
4425 struct amdgpu_device
*adev
= dev
->dev_private
;
4426 struct amdgpu_ras
*ras
= amdgpu_ras_get_context(adev
);
4429 if (!amdgpu_device_supports_baco(adev
->ddev
))
4432 ret
= amdgpu_dpm_baco_exit(adev
);
4436 if (ras
&& ras
->supported
)
4437 adev
->nbio
.funcs
->enable_doorbell_interrupt(adev
, true);