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
29 #include <linux/aperture.h>
30 #include <linux/power_supply.h>
31 #include <linux/kthread.h>
32 #include <linux/module.h>
33 #include <linux/console.h>
34 #include <linux/slab.h>
35 #include <linux/iommu.h>
36 #include <linux/pci.h>
37 #include <linux/pci-p2pdma.h>
38 #include <linux/apple-gmux.h>
40 #include <drm/drm_atomic_helper.h>
41 #include <drm/drm_client_event.h>
42 #include <drm/drm_crtc_helper.h>
43 #include <drm/drm_probe_helper.h>
44 #include <drm/amdgpu_drm.h>
45 #include <linux/device.h>
46 #include <linux/vgaarb.h>
47 #include <linux/vga_switcheroo.h>
48 #include <linux/efi.h>
50 #include "amdgpu_trace.h"
51 #include "amdgpu_i2c.h"
53 #include "amdgpu_atombios.h"
54 #include "amdgpu_atomfirmware.h"
56 #ifdef CONFIG_DRM_AMDGPU_SI
59 #ifdef CONFIG_DRM_AMDGPU_CIK
65 #include "bif/bif_4_1_d.h"
66 #include <linux/firmware.h>
67 #include "amdgpu_vf_error.h"
69 #include "amdgpu_amdkfd.h"
70 #include "amdgpu_pm.h"
72 #include "amdgpu_xgmi.h"
73 #include "amdgpu_ras.h"
74 #include "amdgpu_pmu.h"
75 #include "amdgpu_fru_eeprom.h"
76 #include "amdgpu_reset.h"
77 #include "amdgpu_virt.h"
78 #include "amdgpu_dev_coredump.h"
80 #include <linux/suspend.h>
81 #include <drm/task_barrier.h>
82 #include <linux/pm_runtime.h>
84 #include <drm/drm_drv.h>
86 #if IS_ENABLED(CONFIG_X86)
87 #include <asm/intel-family.h>
88 #include <asm/cpu_device_id.h>
91 MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin");
92 MODULE_FIRMWARE("amdgpu/vega12_gpu_info.bin");
93 MODULE_FIRMWARE("amdgpu/raven_gpu_info.bin");
94 MODULE_FIRMWARE("amdgpu/picasso_gpu_info.bin");
95 MODULE_FIRMWARE("amdgpu/raven2_gpu_info.bin");
96 MODULE_FIRMWARE("amdgpu/arcturus_gpu_info.bin");
97 MODULE_FIRMWARE("amdgpu/navi12_gpu_info.bin");
99 #define AMDGPU_RESUME_MS 2000
100 #define AMDGPU_MAX_RETRY_LIMIT 2
101 #define AMDGPU_RETRY_SRIOV_RESET(r) ((r) == -EBUSY || (r) == -ETIMEDOUT || (r) == -EINVAL)
102 #define AMDGPU_PCIE_INDEX_FALLBACK (0x38 >> 2)
103 #define AMDGPU_PCIE_INDEX_HI_FALLBACK (0x44 >> 2)
104 #define AMDGPU_PCIE_DATA_FALLBACK (0x3C >> 2)
106 #define AMDGPU_VBIOS_SKIP (1U << 0)
107 #define AMDGPU_VBIOS_OPTIONAL (1U << 1)
109 static const struct drm_driver amdgpu_kms_driver;
111 const char *amdgpu_asic_name[] = {
152 #define AMDGPU_IP_BLK_MASK_ALL GENMASK(AMD_IP_BLOCK_TYPE_NUM - 1, 0)
154 * Default init level where all blocks are expected to be initialized. This is
155 * the level of initialization expected by default and also after a full reset
158 struct amdgpu_init_level amdgpu_init_default = {
159 .level = AMDGPU_INIT_LEVEL_DEFAULT,
160 .hwini_ip_block_mask = AMDGPU_IP_BLK_MASK_ALL,
163 struct amdgpu_init_level amdgpu_init_recovery = {
164 .level = AMDGPU_INIT_LEVEL_RESET_RECOVERY,
165 .hwini_ip_block_mask = AMDGPU_IP_BLK_MASK_ALL,
169 * Minimal blocks needed to be initialized before a XGMI hive can be reset. This
170 * is used for cases like reset on initialization where the entire hive needs to
171 * be reset before first use.
173 struct amdgpu_init_level amdgpu_init_minimal_xgmi = {
174 .level = AMDGPU_INIT_LEVEL_MINIMAL_XGMI,
175 .hwini_ip_block_mask =
176 BIT(AMD_IP_BLOCK_TYPE_GMC) | BIT(AMD_IP_BLOCK_TYPE_SMC) |
177 BIT(AMD_IP_BLOCK_TYPE_COMMON) | BIT(AMD_IP_BLOCK_TYPE_IH) |
178 BIT(AMD_IP_BLOCK_TYPE_PSP)
181 static inline bool amdgpu_ip_member_of_hwini(struct amdgpu_device *adev,
182 enum amd_ip_block_type block)
184 return (adev->init_lvl->hwini_ip_block_mask & (1U << block)) != 0;
187 void amdgpu_set_init_level(struct amdgpu_device *adev,
188 enum amdgpu_init_lvl_id lvl)
191 case AMDGPU_INIT_LEVEL_MINIMAL_XGMI:
192 adev->init_lvl = &amdgpu_init_minimal_xgmi;
194 case AMDGPU_INIT_LEVEL_RESET_RECOVERY:
195 adev->init_lvl = &amdgpu_init_recovery;
197 case AMDGPU_INIT_LEVEL_DEFAULT:
200 adev->init_lvl = &amdgpu_init_default;
205 static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev);
206 static int amdgpu_device_pm_notifier(struct notifier_block *nb, unsigned long mode,
210 * DOC: pcie_replay_count
212 * The amdgpu driver provides a sysfs API for reporting the total number
213 * of PCIe replays (NAKs).
214 * The file pcie_replay_count is used for this and returns the total
215 * number of replays as a sum of the NAKs generated and NAKs received.
218 static ssize_t amdgpu_device_get_pcie_replay_count(struct device *dev,
219 struct device_attribute *attr, char *buf)
221 struct drm_device *ddev = dev_get_drvdata(dev);
222 struct amdgpu_device *adev = drm_to_adev(ddev);
223 uint64_t cnt = amdgpu_asic_get_pcie_replay_count(adev);
225 return sysfs_emit(buf, "%llu\n", cnt);
228 static DEVICE_ATTR(pcie_replay_count, 0444,
229 amdgpu_device_get_pcie_replay_count, NULL);
231 static int amdgpu_device_attr_sysfs_init(struct amdgpu_device *adev)
235 if (!amdgpu_sriov_vf(adev))
236 ret = sysfs_create_file(&adev->dev->kobj,
237 &dev_attr_pcie_replay_count.attr);
242 static void amdgpu_device_attr_sysfs_fini(struct amdgpu_device *adev)
244 if (!amdgpu_sriov_vf(adev))
245 sysfs_remove_file(&adev->dev->kobj,
246 &dev_attr_pcie_replay_count.attr);
249 static ssize_t amdgpu_sysfs_reg_state_get(struct file *f, struct kobject *kobj,
250 const struct bin_attribute *attr, char *buf,
251 loff_t ppos, size_t count)
253 struct device *dev = kobj_to_dev(kobj);
254 struct drm_device *ddev = dev_get_drvdata(dev);
255 struct amdgpu_device *adev = drm_to_adev(ddev);
259 case AMDGPU_SYS_REG_STATE_XGMI:
260 bytes_read = amdgpu_asic_get_reg_state(
261 adev, AMDGPU_REG_STATE_TYPE_XGMI, buf, count);
263 case AMDGPU_SYS_REG_STATE_WAFL:
264 bytes_read = amdgpu_asic_get_reg_state(
265 adev, AMDGPU_REG_STATE_TYPE_WAFL, buf, count);
267 case AMDGPU_SYS_REG_STATE_PCIE:
268 bytes_read = amdgpu_asic_get_reg_state(
269 adev, AMDGPU_REG_STATE_TYPE_PCIE, buf, count);
271 case AMDGPU_SYS_REG_STATE_USR:
272 bytes_read = amdgpu_asic_get_reg_state(
273 adev, AMDGPU_REG_STATE_TYPE_USR, buf, count);
275 case AMDGPU_SYS_REG_STATE_USR_1:
276 bytes_read = amdgpu_asic_get_reg_state(
277 adev, AMDGPU_REG_STATE_TYPE_USR_1, buf, count);
286 static const BIN_ATTR(reg_state, 0444, amdgpu_sysfs_reg_state_get, NULL,
287 AMDGPU_SYS_REG_STATE_END);
289 int amdgpu_reg_state_sysfs_init(struct amdgpu_device *adev)
293 if (!amdgpu_asic_get_reg_state_supported(adev))
296 ret = sysfs_create_bin_file(&adev->dev->kobj, &bin_attr_reg_state);
301 void amdgpu_reg_state_sysfs_fini(struct amdgpu_device *adev)
303 if (!amdgpu_asic_get_reg_state_supported(adev))
305 sysfs_remove_bin_file(&adev->dev->kobj, &bin_attr_reg_state);
308 int amdgpu_ip_block_suspend(struct amdgpu_ip_block *ip_block)
312 if (ip_block->version->funcs->suspend) {
313 r = ip_block->version->funcs->suspend(ip_block);
315 dev_err(ip_block->adev->dev,
316 "suspend of IP block <%s> failed %d\n",
317 ip_block->version->funcs->name, r);
322 ip_block->status.hw = false;
326 int amdgpu_ip_block_resume(struct amdgpu_ip_block *ip_block)
330 if (ip_block->version->funcs->resume) {
331 r = ip_block->version->funcs->resume(ip_block);
333 dev_err(ip_block->adev->dev,
334 "resume of IP block <%s> failed %d\n",
335 ip_block->version->funcs->name, r);
340 ip_block->status.hw = true;
347 * The amdgpu driver provides a sysfs API for giving board related information.
348 * It provides the form factor information in the format
352 * Possible form factor values
354 * - "cem" - PCIE CEM card
355 * - "oam" - Open Compute Accelerator Module
356 * - "unknown" - Not known
360 static ssize_t amdgpu_device_get_board_info(struct device *dev,
361 struct device_attribute *attr,
364 struct drm_device *ddev = dev_get_drvdata(dev);
365 struct amdgpu_device *adev = drm_to_adev(ddev);
366 enum amdgpu_pkg_type pkg_type = AMDGPU_PKG_TYPE_CEM;
369 if (adev->smuio.funcs && adev->smuio.funcs->get_pkg_type)
370 pkg_type = adev->smuio.funcs->get_pkg_type(adev);
373 case AMDGPU_PKG_TYPE_CEM:
376 case AMDGPU_PKG_TYPE_OAM:
384 return sysfs_emit(buf, "%s : %s\n", "type", pkg);
387 static DEVICE_ATTR(board_info, 0444, amdgpu_device_get_board_info, NULL);
389 static struct attribute *amdgpu_board_attrs[] = {
390 &dev_attr_board_info.attr,
394 static umode_t amdgpu_board_attrs_is_visible(struct kobject *kobj,
395 struct attribute *attr, int n)
397 struct device *dev = kobj_to_dev(kobj);
398 struct drm_device *ddev = dev_get_drvdata(dev);
399 struct amdgpu_device *adev = drm_to_adev(ddev);
401 if (adev->flags & AMD_IS_APU)
407 static const struct attribute_group amdgpu_board_attrs_group = {
408 .attrs = amdgpu_board_attrs,
409 .is_visible = amdgpu_board_attrs_is_visible
412 static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev);
416 * amdgpu_device_supports_px - Is the device a dGPU with ATPX power control
418 * @dev: drm_device pointer
420 * Returns true if the device is a dGPU with ATPX power control,
421 * otherwise return false.
423 bool amdgpu_device_supports_px(struct drm_device *dev)
425 struct amdgpu_device *adev = drm_to_adev(dev);
427 if ((adev->flags & AMD_IS_PX) && !amdgpu_is_atpx_hybrid())
433 * amdgpu_device_supports_boco - Is the device a dGPU with ACPI power resources
435 * @dev: drm_device pointer
437 * Returns true if the device is a dGPU with ACPI power control,
438 * otherwise return false.
440 bool amdgpu_device_supports_boco(struct drm_device *dev)
442 struct amdgpu_device *adev = drm_to_adev(dev);
444 if (!IS_ENABLED(CONFIG_HOTPLUG_PCI_PCIE))
448 ((adev->flags & AMD_IS_PX) && amdgpu_is_atpx_hybrid()))
454 * amdgpu_device_supports_baco - Does the device support BACO
456 * @dev: drm_device pointer
459 * 1 if the device supports BACO;
460 * 3 if the device supports MACO (only works if BACO is supported)
461 * otherwise return 0.
463 int amdgpu_device_supports_baco(struct drm_device *dev)
465 struct amdgpu_device *adev = drm_to_adev(dev);
467 return amdgpu_asic_supports_baco(adev);
470 void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
472 struct drm_device *dev;
475 dev = adev_to_drm(adev);
477 adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
478 bamaco_support = amdgpu_device_supports_baco(dev);
480 switch (amdgpu_runtime_pm) {
482 if (bamaco_support & MACO_SUPPORT) {
483 adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
484 dev_info(adev->dev, "Forcing BAMACO for runtime pm\n");
485 } else if (bamaco_support == BACO_SUPPORT) {
486 adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
487 dev_info(adev->dev, "Requested mode BAMACO not available,fallback to use BACO\n");
491 if (bamaco_support & BACO_SUPPORT) {
492 adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
493 dev_info(adev->dev, "Forcing BACO for runtime pm\n");
498 if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime mode */
499 adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
500 dev_info(adev->dev, "Using ATPX for runtime pm\n");
501 } else if (amdgpu_device_supports_boco(dev)) { /* enable boco as runtime mode */
502 adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
503 dev_info(adev->dev, "Using BOCO for runtime pm\n");
508 switch (adev->asic_type) {
511 /* BACO are not supported on vega20 and arctrus */
514 /* enable BACO as runpm mode if noretry=0 */
515 if (!adev->gmc.noretry && !amdgpu_passthrough(adev))
516 adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
519 /* enable BACO as runpm mode on CI+ */
520 if (!amdgpu_passthrough(adev))
521 adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
525 if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
526 if (bamaco_support & MACO_SUPPORT) {
527 adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
528 dev_info(adev->dev, "Using BAMACO for runtime pm\n");
530 dev_info(adev->dev, "Using BACO for runtime pm\n");
536 dev_info(adev->dev, "runtime pm is manually disabled\n");
543 if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
544 dev_info(adev->dev, "Runtime PM not available\n");
547 * amdgpu_device_supports_smart_shift - Is the device dGPU with
548 * smart shift support
550 * @dev: drm_device pointer
552 * Returns true if the device is a dGPU with Smart Shift support,
553 * otherwise returns false.
555 bool amdgpu_device_supports_smart_shift(struct drm_device *dev)
557 return (amdgpu_device_supports_boco(dev) &&
558 amdgpu_acpi_is_power_shift_control_supported());
562 * VRAM access helper functions
566 * amdgpu_device_mm_access - access vram by MM_INDEX/MM_DATA
568 * @adev: amdgpu_device pointer
569 * @pos: offset of the buffer in vram
570 * @buf: virtual address of the buffer in system memory
571 * @size: read/write size, sizeof(@buf) must > @size
572 * @write: true - write to vram, otherwise - read from vram
574 void amdgpu_device_mm_access(struct amdgpu_device *adev, loff_t pos,
575 void *buf, size_t size, bool write)
578 uint32_t hi = ~0, tmp = 0;
579 uint32_t *data = buf;
583 if (!drm_dev_enter(adev_to_drm(adev), &idx))
586 BUG_ON(!IS_ALIGNED(pos, 4) || !IS_ALIGNED(size, 4));
588 spin_lock_irqsave(&adev->mmio_idx_lock, flags);
589 for (last = pos + size; pos < last; pos += 4) {
592 WREG32_NO_KIQ(mmMM_INDEX, ((uint32_t)pos) | 0x80000000);
594 WREG32_NO_KIQ(mmMM_INDEX_HI, tmp);
598 WREG32_NO_KIQ(mmMM_DATA, *data++);
600 *data++ = RREG32_NO_KIQ(mmMM_DATA);
603 spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
608 * amdgpu_device_aper_access - access vram by vram aperture
610 * @adev: amdgpu_device pointer
611 * @pos: offset of the buffer in vram
612 * @buf: virtual address of the buffer in system memory
613 * @size: read/write size, sizeof(@buf) must > @size
614 * @write: true - write to vram, otherwise - read from vram
616 * The return value means how many bytes have been transferred.
618 size_t amdgpu_device_aper_access(struct amdgpu_device *adev, loff_t pos,
619 void *buf, size_t size, bool write)
626 if (!adev->mman.aper_base_kaddr)
629 last = min(pos + size, adev->gmc.visible_vram_size);
631 addr = adev->mman.aper_base_kaddr + pos;
635 memcpy_toio(addr, buf, count);
636 /* Make sure HDP write cache flush happens without any reordering
637 * after the system memory contents are sent over PCIe device
640 amdgpu_device_flush_hdp(adev, NULL);
642 amdgpu_device_invalidate_hdp(adev, NULL);
643 /* Make sure HDP read cache is invalidated before issuing a read
647 memcpy_fromio(buf, addr, count);
659 * amdgpu_device_vram_access - read/write a buffer in vram
661 * @adev: amdgpu_device pointer
662 * @pos: offset of the buffer in vram
663 * @buf: virtual address of the buffer in system memory
664 * @size: read/write size, sizeof(@buf) must > @size
665 * @write: true - write to vram, otherwise - read from vram
667 void amdgpu_device_vram_access(struct amdgpu_device *adev, loff_t pos,
668 void *buf, size_t size, bool write)
672 /* try to using vram apreature to access vram first */
673 count = amdgpu_device_aper_access(adev, pos, buf, size, write);
676 /* using MM to access rest vram */
679 amdgpu_device_mm_access(adev, pos, buf, size, write);
684 * register access helper functions.
687 /* Check if hw access should be skipped because of hotplug or device error */
688 bool amdgpu_device_skip_hw_access(struct amdgpu_device *adev)
690 if (adev->no_hw_access)
693 #ifdef CONFIG_LOCKDEP
695 * This is a bit complicated to understand, so worth a comment. What we assert
696 * here is that the GPU reset is not running on another thread in parallel.
698 * For this we trylock the read side of the reset semaphore, if that succeeds
699 * we know that the reset is not running in parallel.
701 * If the trylock fails we assert that we are either already holding the read
702 * side of the lock or are the reset thread itself and hold the write side of
706 if (down_read_trylock(&adev->reset_domain->sem))
707 up_read(&adev->reset_domain->sem);
709 lockdep_assert_held(&adev->reset_domain->sem);
716 * amdgpu_device_rreg - read a memory mapped IO or indirect register
718 * @adev: amdgpu_device pointer
719 * @reg: dword aligned register offset
720 * @acc_flags: access flags which require special behavior
722 * Returns the 32 bit value from the offset specified.
724 uint32_t amdgpu_device_rreg(struct amdgpu_device *adev,
725 uint32_t reg, uint32_t acc_flags)
729 if (amdgpu_device_skip_hw_access(adev))
732 if ((reg * 4) < adev->rmmio_size) {
733 if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
734 amdgpu_sriov_runtime(adev) &&
735 down_read_trylock(&adev->reset_domain->sem)) {
736 ret = amdgpu_kiq_rreg(adev, reg, 0);
737 up_read(&adev->reset_domain->sem);
739 ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
742 ret = adev->pcie_rreg(adev, reg * 4);
745 trace_amdgpu_device_rreg(adev->pdev->device, reg, ret);
751 * MMIO register read with bytes helper functions
752 * @offset:bytes offset from MMIO start
756 * amdgpu_mm_rreg8 - read a memory mapped IO register
758 * @adev: amdgpu_device pointer
759 * @offset: byte aligned register offset
761 * Returns the 8 bit value from the offset specified.
763 uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset)
765 if (amdgpu_device_skip_hw_access(adev))
768 if (offset < adev->rmmio_size)
769 return (readb(adev->rmmio + offset));
775 * amdgpu_device_xcc_rreg - read a memory mapped IO or indirect register with specific XCC
777 * @adev: amdgpu_device pointer
778 * @reg: dword aligned register offset
779 * @acc_flags: access flags which require special behavior
780 * @xcc_id: xcc accelerated compute core id
782 * Returns the 32 bit value from the offset specified.
784 uint32_t amdgpu_device_xcc_rreg(struct amdgpu_device *adev,
785 uint32_t reg, uint32_t acc_flags,
788 uint32_t ret, rlcg_flag;
790 if (amdgpu_device_skip_hw_access(adev))
793 if ((reg * 4) < adev->rmmio_size) {
794 if (amdgpu_sriov_vf(adev) &&
795 !amdgpu_sriov_runtime(adev) &&
796 adev->gfx.rlc.rlcg_reg_access_supported &&
797 amdgpu_virt_get_rlcg_reg_access_flag(adev, acc_flags,
800 ret = amdgpu_virt_rlcg_reg_rw(adev, reg, 0, rlcg_flag, GET_INST(GC, xcc_id));
801 } else if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
802 amdgpu_sriov_runtime(adev) &&
803 down_read_trylock(&adev->reset_domain->sem)) {
804 ret = amdgpu_kiq_rreg(adev, reg, xcc_id);
805 up_read(&adev->reset_domain->sem);
807 ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
810 ret = adev->pcie_rreg(adev, reg * 4);
817 * MMIO register write with bytes helper functions
818 * @offset:bytes offset from MMIO start
819 * @value: the value want to be written to the register
823 * amdgpu_mm_wreg8 - read a memory mapped IO register
825 * @adev: amdgpu_device pointer
826 * @offset: byte aligned register offset
827 * @value: 8 bit value to write
829 * Writes the value specified to the offset specified.
831 void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value)
833 if (amdgpu_device_skip_hw_access(adev))
836 if (offset < adev->rmmio_size)
837 writeb(value, adev->rmmio + offset);
843 * amdgpu_device_wreg - write to a memory mapped IO or indirect register
845 * @adev: amdgpu_device pointer
846 * @reg: dword aligned register offset
847 * @v: 32 bit value to write to the register
848 * @acc_flags: access flags which require special behavior
850 * Writes the value specified to the offset specified.
852 void amdgpu_device_wreg(struct amdgpu_device *adev,
853 uint32_t reg, uint32_t v,
856 if (amdgpu_device_skip_hw_access(adev))
859 if ((reg * 4) < adev->rmmio_size) {
860 if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
861 amdgpu_sriov_runtime(adev) &&
862 down_read_trylock(&adev->reset_domain->sem)) {
863 amdgpu_kiq_wreg(adev, reg, v, 0);
864 up_read(&adev->reset_domain->sem);
866 writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
869 adev->pcie_wreg(adev, reg * 4, v);
872 trace_amdgpu_device_wreg(adev->pdev->device, reg, v);
876 * amdgpu_mm_wreg_mmio_rlc - write register either with direct/indirect mmio or with RLC path if in range
878 * @adev: amdgpu_device pointer
879 * @reg: mmio/rlc register
881 * @xcc_id: xcc accelerated compute core id
883 * this function is invoked only for the debugfs register access
885 void amdgpu_mm_wreg_mmio_rlc(struct amdgpu_device *adev,
886 uint32_t reg, uint32_t v,
889 if (amdgpu_device_skip_hw_access(adev))
892 if (amdgpu_sriov_fullaccess(adev) &&
893 adev->gfx.rlc.funcs &&
894 adev->gfx.rlc.funcs->is_rlcg_access_range) {
895 if (adev->gfx.rlc.funcs->is_rlcg_access_range(adev, reg))
896 return amdgpu_sriov_wreg(adev, reg, v, 0, 0, xcc_id);
897 } else if ((reg * 4) >= adev->rmmio_size) {
898 adev->pcie_wreg(adev, reg * 4, v);
900 writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
905 * amdgpu_device_xcc_wreg - write to a memory mapped IO or indirect register with specific XCC
907 * @adev: amdgpu_device pointer
908 * @reg: dword aligned register offset
909 * @v: 32 bit value to write to the register
910 * @acc_flags: access flags which require special behavior
911 * @xcc_id: xcc accelerated compute core id
913 * Writes the value specified to the offset specified.
915 void amdgpu_device_xcc_wreg(struct amdgpu_device *adev,
916 uint32_t reg, uint32_t v,
917 uint32_t acc_flags, uint32_t xcc_id)
921 if (amdgpu_device_skip_hw_access(adev))
924 if ((reg * 4) < adev->rmmio_size) {
925 if (amdgpu_sriov_vf(adev) &&
926 !amdgpu_sriov_runtime(adev) &&
927 adev->gfx.rlc.rlcg_reg_access_supported &&
928 amdgpu_virt_get_rlcg_reg_access_flag(adev, acc_flags,
931 amdgpu_virt_rlcg_reg_rw(adev, reg, v, rlcg_flag, GET_INST(GC, xcc_id));
932 } else if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
933 amdgpu_sriov_runtime(adev) &&
934 down_read_trylock(&adev->reset_domain->sem)) {
935 amdgpu_kiq_wreg(adev, reg, v, xcc_id);
936 up_read(&adev->reset_domain->sem);
938 writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
941 adev->pcie_wreg(adev, reg * 4, v);
946 * amdgpu_device_indirect_rreg - read an indirect register
948 * @adev: amdgpu_device pointer
949 * @reg_addr: indirect register address to read from
951 * Returns the value of indirect register @reg_addr
953 u32 amdgpu_device_indirect_rreg(struct amdgpu_device *adev,
956 unsigned long flags, pcie_index, pcie_data;
957 void __iomem *pcie_index_offset;
958 void __iomem *pcie_data_offset;
961 pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev);
962 pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev);
964 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
965 pcie_index_offset = (void __iomem *)adev->rmmio + pcie_index * 4;
966 pcie_data_offset = (void __iomem *)adev->rmmio + pcie_data * 4;
968 writel(reg_addr, pcie_index_offset);
969 readl(pcie_index_offset);
970 r = readl(pcie_data_offset);
971 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
976 u32 amdgpu_device_indirect_rreg_ext(struct amdgpu_device *adev,
979 unsigned long flags, pcie_index, pcie_index_hi, pcie_data;
981 void __iomem *pcie_index_offset;
982 void __iomem *pcie_index_hi_offset;
983 void __iomem *pcie_data_offset;
985 if (unlikely(!adev->nbio.funcs)) {
986 pcie_index = AMDGPU_PCIE_INDEX_FALLBACK;
987 pcie_data = AMDGPU_PCIE_DATA_FALLBACK;
989 pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev);
990 pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev);
993 if (reg_addr >> 32) {
994 if (unlikely(!adev->nbio.funcs))
995 pcie_index_hi = AMDGPU_PCIE_INDEX_HI_FALLBACK;
997 pcie_index_hi = adev->nbio.funcs->get_pcie_index_hi_offset(adev);
1002 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1003 pcie_index_offset = (void __iomem *)adev->rmmio + pcie_index * 4;
1004 pcie_data_offset = (void __iomem *)adev->rmmio + pcie_data * 4;
1005 if (pcie_index_hi != 0)
1006 pcie_index_hi_offset = (void __iomem *)adev->rmmio +
1009 writel(reg_addr, pcie_index_offset);
1010 readl(pcie_index_offset);
1011 if (pcie_index_hi != 0) {
1012 writel((reg_addr >> 32) & 0xff, pcie_index_hi_offset);
1013 readl(pcie_index_hi_offset);
1015 r = readl(pcie_data_offset);
1017 /* clear the high bits */
1018 if (pcie_index_hi != 0) {
1019 writel(0, pcie_index_hi_offset);
1020 readl(pcie_index_hi_offset);
1023 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1029 * amdgpu_device_indirect_rreg64 - read a 64bits indirect register
1031 * @adev: amdgpu_device pointer
1032 * @reg_addr: indirect register address to read from
1034 * Returns the value of indirect register @reg_addr
1036 u64 amdgpu_device_indirect_rreg64(struct amdgpu_device *adev,
1039 unsigned long flags, pcie_index, pcie_data;
1040 void __iomem *pcie_index_offset;
1041 void __iomem *pcie_data_offset;
1044 pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev);
1045 pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev);
1047 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1048 pcie_index_offset = (void __iomem *)adev->rmmio + pcie_index * 4;
1049 pcie_data_offset = (void __iomem *)adev->rmmio + pcie_data * 4;
1051 /* read low 32 bits */
1052 writel(reg_addr, pcie_index_offset);
1053 readl(pcie_index_offset);
1054 r = readl(pcie_data_offset);
1055 /* read high 32 bits */
1056 writel(reg_addr + 4, pcie_index_offset);
1057 readl(pcie_index_offset);
1058 r |= ((u64)readl(pcie_data_offset) << 32);
1059 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1064 u64 amdgpu_device_indirect_rreg64_ext(struct amdgpu_device *adev,
1067 unsigned long flags, pcie_index, pcie_data;
1068 unsigned long pcie_index_hi = 0;
1069 void __iomem *pcie_index_offset;
1070 void __iomem *pcie_index_hi_offset;
1071 void __iomem *pcie_data_offset;
1074 pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev);
1075 pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev);
1076 if ((reg_addr >> 32) && (adev->nbio.funcs->get_pcie_index_hi_offset))
1077 pcie_index_hi = adev->nbio.funcs->get_pcie_index_hi_offset(adev);
1079 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1080 pcie_index_offset = (void __iomem *)adev->rmmio + pcie_index * 4;
1081 pcie_data_offset = (void __iomem *)adev->rmmio + pcie_data * 4;
1082 if (pcie_index_hi != 0)
1083 pcie_index_hi_offset = (void __iomem *)adev->rmmio +
1086 /* read low 32 bits */
1087 writel(reg_addr, pcie_index_offset);
1088 readl(pcie_index_offset);
1089 if (pcie_index_hi != 0) {
1090 writel((reg_addr >> 32) & 0xff, pcie_index_hi_offset);
1091 readl(pcie_index_hi_offset);
1093 r = readl(pcie_data_offset);
1094 /* read high 32 bits */
1095 writel(reg_addr + 4, pcie_index_offset);
1096 readl(pcie_index_offset);
1097 if (pcie_index_hi != 0) {
1098 writel((reg_addr >> 32) & 0xff, pcie_index_hi_offset);
1099 readl(pcie_index_hi_offset);
1101 r |= ((u64)readl(pcie_data_offset) << 32);
1103 /* clear the high bits */
1104 if (pcie_index_hi != 0) {
1105 writel(0, pcie_index_hi_offset);
1106 readl(pcie_index_hi_offset);
1109 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1115 * amdgpu_device_indirect_wreg - write an indirect register address
1117 * @adev: amdgpu_device pointer
1118 * @reg_addr: indirect register offset
1119 * @reg_data: indirect register data
1122 void amdgpu_device_indirect_wreg(struct amdgpu_device *adev,
1123 u32 reg_addr, u32 reg_data)
1125 unsigned long flags, pcie_index, pcie_data;
1126 void __iomem *pcie_index_offset;
1127 void __iomem *pcie_data_offset;
1129 pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev);
1130 pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev);
1132 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1133 pcie_index_offset = (void __iomem *)adev->rmmio + pcie_index * 4;
1134 pcie_data_offset = (void __iomem *)adev->rmmio + pcie_data * 4;
1136 writel(reg_addr, pcie_index_offset);
1137 readl(pcie_index_offset);
1138 writel(reg_data, pcie_data_offset);
1139 readl(pcie_data_offset);
1140 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1143 void amdgpu_device_indirect_wreg_ext(struct amdgpu_device *adev,
1144 u64 reg_addr, u32 reg_data)
1146 unsigned long flags, pcie_index, pcie_index_hi, pcie_data;
1147 void __iomem *pcie_index_offset;
1148 void __iomem *pcie_index_hi_offset;
1149 void __iomem *pcie_data_offset;
1151 pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev);
1152 pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev);
1153 if ((reg_addr >> 32) && (adev->nbio.funcs->get_pcie_index_hi_offset))
1154 pcie_index_hi = adev->nbio.funcs->get_pcie_index_hi_offset(adev);
1158 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1159 pcie_index_offset = (void __iomem *)adev->rmmio + pcie_index * 4;
1160 pcie_data_offset = (void __iomem *)adev->rmmio + pcie_data * 4;
1161 if (pcie_index_hi != 0)
1162 pcie_index_hi_offset = (void __iomem *)adev->rmmio +
1165 writel(reg_addr, pcie_index_offset);
1166 readl(pcie_index_offset);
1167 if (pcie_index_hi != 0) {
1168 writel((reg_addr >> 32) & 0xff, pcie_index_hi_offset);
1169 readl(pcie_index_hi_offset);
1171 writel(reg_data, pcie_data_offset);
1172 readl(pcie_data_offset);
1174 /* clear the high bits */
1175 if (pcie_index_hi != 0) {
1176 writel(0, pcie_index_hi_offset);
1177 readl(pcie_index_hi_offset);
1180 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1184 * amdgpu_device_indirect_wreg64 - write a 64bits indirect register address
1186 * @adev: amdgpu_device pointer
1187 * @reg_addr: indirect register offset
1188 * @reg_data: indirect register data
1191 void amdgpu_device_indirect_wreg64(struct amdgpu_device *adev,
1192 u32 reg_addr, u64 reg_data)
1194 unsigned long flags, pcie_index, pcie_data;
1195 void __iomem *pcie_index_offset;
1196 void __iomem *pcie_data_offset;
1198 pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev);
1199 pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev);
1201 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1202 pcie_index_offset = (void __iomem *)adev->rmmio + pcie_index * 4;
1203 pcie_data_offset = (void __iomem *)adev->rmmio + pcie_data * 4;
1205 /* write low 32 bits */
1206 writel(reg_addr, pcie_index_offset);
1207 readl(pcie_index_offset);
1208 writel((u32)(reg_data & 0xffffffffULL), pcie_data_offset);
1209 readl(pcie_data_offset);
1210 /* write high 32 bits */
1211 writel(reg_addr + 4, pcie_index_offset);
1212 readl(pcie_index_offset);
1213 writel((u32)(reg_data >> 32), pcie_data_offset);
1214 readl(pcie_data_offset);
1215 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1218 void amdgpu_device_indirect_wreg64_ext(struct amdgpu_device *adev,
1219 u64 reg_addr, u64 reg_data)
1221 unsigned long flags, pcie_index, pcie_data;
1222 unsigned long pcie_index_hi = 0;
1223 void __iomem *pcie_index_offset;
1224 void __iomem *pcie_index_hi_offset;
1225 void __iomem *pcie_data_offset;
1227 pcie_index = adev->nbio.funcs->get_pcie_index_offset(adev);
1228 pcie_data = adev->nbio.funcs->get_pcie_data_offset(adev);
1229 if ((reg_addr >> 32) && (adev->nbio.funcs->get_pcie_index_hi_offset))
1230 pcie_index_hi = adev->nbio.funcs->get_pcie_index_hi_offset(adev);
1232 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1233 pcie_index_offset = (void __iomem *)adev->rmmio + pcie_index * 4;
1234 pcie_data_offset = (void __iomem *)adev->rmmio + pcie_data * 4;
1235 if (pcie_index_hi != 0)
1236 pcie_index_hi_offset = (void __iomem *)adev->rmmio +
1239 /* write low 32 bits */
1240 writel(reg_addr, pcie_index_offset);
1241 readl(pcie_index_offset);
1242 if (pcie_index_hi != 0) {
1243 writel((reg_addr >> 32) & 0xff, pcie_index_hi_offset);
1244 readl(pcie_index_hi_offset);
1246 writel((u32)(reg_data & 0xffffffffULL), pcie_data_offset);
1247 readl(pcie_data_offset);
1248 /* write high 32 bits */
1249 writel(reg_addr + 4, pcie_index_offset);
1250 readl(pcie_index_offset);
1251 if (pcie_index_hi != 0) {
1252 writel((reg_addr >> 32) & 0xff, pcie_index_hi_offset);
1253 readl(pcie_index_hi_offset);
1255 writel((u32)(reg_data >> 32), pcie_data_offset);
1256 readl(pcie_data_offset);
1258 /* clear the high bits */
1259 if (pcie_index_hi != 0) {
1260 writel(0, pcie_index_hi_offset);
1261 readl(pcie_index_hi_offset);
1264 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1268 * amdgpu_device_get_rev_id - query device rev_id
1270 * @adev: amdgpu_device pointer
1272 * Return device rev_id
1274 u32 amdgpu_device_get_rev_id(struct amdgpu_device *adev)
1276 return adev->nbio.funcs->get_rev_id(adev);
1280 * amdgpu_invalid_rreg - dummy reg read function
1282 * @adev: amdgpu_device pointer
1283 * @reg: offset of register
1285 * Dummy register read function. Used for register blocks
1286 * that certain asics don't have (all asics).
1287 * Returns the value in the register.
1289 static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg)
1291 DRM_ERROR("Invalid callback to read register 0x%04X\n", reg);
1296 static uint32_t amdgpu_invalid_rreg_ext(struct amdgpu_device *adev, uint64_t reg)
1298 DRM_ERROR("Invalid callback to read register 0x%llX\n", reg);
1304 * amdgpu_invalid_wreg - dummy reg write function
1306 * @adev: amdgpu_device pointer
1307 * @reg: offset of register
1308 * @v: value to write to the register
1310 * Dummy register read function. Used for register blocks
1311 * that certain asics don't have (all asics).
1313 static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
1315 DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n",
1320 static void amdgpu_invalid_wreg_ext(struct amdgpu_device *adev, uint64_t reg, uint32_t v)
1322 DRM_ERROR("Invalid callback to write register 0x%llX with 0x%08X\n",
1328 * amdgpu_invalid_rreg64 - dummy 64 bit reg read function
1330 * @adev: amdgpu_device pointer
1331 * @reg: offset of register
1333 * Dummy register read function. Used for register blocks
1334 * that certain asics don't have (all asics).
1335 * Returns the value in the register.
1337 static uint64_t amdgpu_invalid_rreg64(struct amdgpu_device *adev, uint32_t reg)
1339 DRM_ERROR("Invalid callback to read 64 bit register 0x%04X\n", reg);
1344 static uint64_t amdgpu_invalid_rreg64_ext(struct amdgpu_device *adev, uint64_t reg)
1346 DRM_ERROR("Invalid callback to read register 0x%llX\n", reg);
1352 * amdgpu_invalid_wreg64 - dummy reg write function
1354 * @adev: amdgpu_device pointer
1355 * @reg: offset of register
1356 * @v: value to write to the register
1358 * Dummy register read function. Used for register blocks
1359 * that certain asics don't have (all asics).
1361 static void amdgpu_invalid_wreg64(struct amdgpu_device *adev, uint32_t reg, uint64_t v)
1363 DRM_ERROR("Invalid callback to write 64 bit register 0x%04X with 0x%08llX\n",
1368 static void amdgpu_invalid_wreg64_ext(struct amdgpu_device *adev, uint64_t reg, uint64_t v)
1370 DRM_ERROR("Invalid callback to write 64 bit register 0x%llX with 0x%08llX\n",
1376 * amdgpu_block_invalid_rreg - dummy reg read function
1378 * @adev: amdgpu_device pointer
1379 * @block: offset of instance
1380 * @reg: offset of register
1382 * Dummy register read function. Used for register blocks
1383 * that certain asics don't have (all asics).
1384 * Returns the value in the register.
1386 static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev,
1387 uint32_t block, uint32_t reg)
1389 DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n",
1396 * amdgpu_block_invalid_wreg - dummy reg write function
1398 * @adev: amdgpu_device pointer
1399 * @block: offset of instance
1400 * @reg: offset of register
1401 * @v: value to write to the register
1403 * Dummy register read function. Used for register blocks
1404 * that certain asics don't have (all asics).
1406 static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev,
1408 uint32_t reg, uint32_t v)
1410 DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n",
1415 static uint32_t amdgpu_device_get_vbios_flags(struct amdgpu_device *adev)
1417 if (hweight32(adev->aid_mask) && (adev->flags & AMD_IS_APU))
1418 return AMDGPU_VBIOS_SKIP;
1420 if (hweight32(adev->aid_mask) && amdgpu_passthrough(adev))
1421 return AMDGPU_VBIOS_OPTIONAL;
1427 * amdgpu_device_asic_init - Wrapper for atom asic_init
1429 * @adev: amdgpu_device pointer
1431 * Does any asic specific work and then calls atom asic init.
1433 static int amdgpu_device_asic_init(struct amdgpu_device *adev)
1439 amdgpu_asic_pre_asic_init(adev);
1440 flags = amdgpu_device_get_vbios_flags(adev);
1441 optional = !!(flags & (AMDGPU_VBIOS_OPTIONAL | AMDGPU_VBIOS_SKIP));
1443 if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) ||
1444 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 4) ||
1445 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 5, 0) ||
1446 amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(11, 0, 0)) {
1447 amdgpu_psp_wait_for_bootloader(adev);
1448 if (optional && !adev->bios)
1451 ret = amdgpu_atomfirmware_asic_init(adev, true);
1454 if (optional && !adev->bios)
1457 return amdgpu_atom_asic_init(adev->mode_info.atom_context);
1464 * amdgpu_device_mem_scratch_init - allocate the VRAM scratch page
1466 * @adev: amdgpu_device pointer
1468 * Allocates a scratch page of VRAM for use by various things in the
1471 static int amdgpu_device_mem_scratch_init(struct amdgpu_device *adev)
1473 return amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE,
1474 AMDGPU_GEM_DOMAIN_VRAM |
1475 AMDGPU_GEM_DOMAIN_GTT,
1476 &adev->mem_scratch.robj,
1477 &adev->mem_scratch.gpu_addr,
1478 (void **)&adev->mem_scratch.ptr);
1482 * amdgpu_device_mem_scratch_fini - Free the VRAM scratch page
1484 * @adev: amdgpu_device pointer
1486 * Frees the VRAM scratch page.
1488 static void amdgpu_device_mem_scratch_fini(struct amdgpu_device *adev)
1490 amdgpu_bo_free_kernel(&adev->mem_scratch.robj, NULL, NULL);
1494 * amdgpu_device_program_register_sequence - program an array of registers.
1496 * @adev: amdgpu_device pointer
1497 * @registers: pointer to the register array
1498 * @array_size: size of the register array
1500 * Programs an array or registers with and or masks.
1501 * This is a helper for setting golden registers.
1503 void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
1504 const u32 *registers,
1505 const u32 array_size)
1507 u32 tmp, reg, and_mask, or_mask;
1513 for (i = 0; i < array_size; i += 3) {
1514 reg = registers[i + 0];
1515 and_mask = registers[i + 1];
1516 or_mask = registers[i + 2];
1518 if (and_mask == 0xffffffff) {
1523 if (adev->family >= AMDGPU_FAMILY_AI)
1524 tmp |= (or_mask & and_mask);
1533 * amdgpu_device_pci_config_reset - reset the GPU
1535 * @adev: amdgpu_device pointer
1537 * Resets the GPU using the pci config reset sequence.
1538 * Only applicable to asics prior to vega10.
1540 void amdgpu_device_pci_config_reset(struct amdgpu_device *adev)
1542 pci_write_config_dword(adev->pdev, 0x7c, AMDGPU_ASIC_RESET_DATA);
1546 * amdgpu_device_pci_reset - reset the GPU using generic PCI means
1548 * @adev: amdgpu_device pointer
1550 * Resets the GPU using generic pci reset interfaces (FLR, SBR, etc.).
1552 int amdgpu_device_pci_reset(struct amdgpu_device *adev)
1554 return pci_reset_function(adev->pdev);
1558 * amdgpu_device_wb_*()
1559 * Writeback is the method by which the GPU updates special pages in memory
1560 * with the status of certain GPU events (fences, ring pointers,etc.).
1564 * amdgpu_device_wb_fini - Disable Writeback and free memory
1566 * @adev: amdgpu_device pointer
1568 * Disables Writeback and frees the Writeback memory (all asics).
1569 * Used at driver shutdown.
1571 static void amdgpu_device_wb_fini(struct amdgpu_device *adev)
1573 if (adev->wb.wb_obj) {
1574 amdgpu_bo_free_kernel(&adev->wb.wb_obj,
1576 (void **)&adev->wb.wb);
1577 adev->wb.wb_obj = NULL;
1582 * amdgpu_device_wb_init - Init Writeback driver info and allocate memory
1584 * @adev: amdgpu_device pointer
1586 * Initializes writeback and allocates writeback memory (all asics).
1587 * Used at driver startup.
1588 * Returns 0 on success or an -error on failure.
1590 static int amdgpu_device_wb_init(struct amdgpu_device *adev)
1594 if (adev->wb.wb_obj == NULL) {
1595 /* AMDGPU_MAX_WB * sizeof(uint32_t) * 8 = AMDGPU_MAX_WB 256bit slots */
1596 r = amdgpu_bo_create_kernel(adev, AMDGPU_MAX_WB * sizeof(uint32_t) * 8,
1597 PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
1598 &adev->wb.wb_obj, &adev->wb.gpu_addr,
1599 (void **)&adev->wb.wb);
1601 dev_warn(adev->dev, "(%d) create WB bo failed\n", r);
1605 adev->wb.num_wb = AMDGPU_MAX_WB;
1606 memset(&adev->wb.used, 0, sizeof(adev->wb.used));
1608 /* clear wb memory */
1609 memset((char *)adev->wb.wb, 0, AMDGPU_MAX_WB * sizeof(uint32_t) * 8);
1616 * amdgpu_device_wb_get - Allocate a wb entry
1618 * @adev: amdgpu_device pointer
1621 * Allocate a wb slot for use by the driver (all asics).
1622 * Returns 0 on success or -EINVAL on failure.
1624 int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb)
1626 unsigned long flags, offset;
1628 spin_lock_irqsave(&adev->wb.lock, flags);
1629 offset = find_first_zero_bit(adev->wb.used, adev->wb.num_wb);
1630 if (offset < adev->wb.num_wb) {
1631 __set_bit(offset, adev->wb.used);
1632 spin_unlock_irqrestore(&adev->wb.lock, flags);
1633 *wb = offset << 3; /* convert to dw offset */
1636 spin_unlock_irqrestore(&adev->wb.lock, flags);
1642 * amdgpu_device_wb_free - Free a wb entry
1644 * @adev: amdgpu_device pointer
1647 * Free a wb slot allocated for use by the driver (all asics)
1649 void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb)
1651 unsigned long flags;
1654 spin_lock_irqsave(&adev->wb.lock, flags);
1655 if (wb < adev->wb.num_wb)
1656 __clear_bit(wb, adev->wb.used);
1657 spin_unlock_irqrestore(&adev->wb.lock, flags);
1661 * amdgpu_device_resize_fb_bar - try to resize FB BAR
1663 * @adev: amdgpu_device pointer
1665 * Try to resize FB BAR to make all VRAM CPU accessible. We try very hard not
1666 * to fail, but if any of the BARs is not accessible after the size we abort
1667 * driver loading by returning -ENODEV.
1669 int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
1671 int rbar_size = pci_rebar_bytes_to_size(adev->gmc.real_vram_size);
1672 struct pci_bus *root;
1673 struct resource *res;
1678 if (!IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT))
1682 if (amdgpu_sriov_vf(adev))
1688 /* resizing on Dell G5 SE platforms causes problems with runtime pm */
1689 if ((amdgpu_runtime_pm != 0) &&
1690 adev->pdev->vendor == PCI_VENDOR_ID_ATI &&
1691 adev->pdev->device == 0x731f &&
1692 adev->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
1695 /* PCI_EXT_CAP_ID_VNDR extended capability is located at 0x100 */
1696 if (!pci_find_ext_capability(adev->pdev, PCI_EXT_CAP_ID_VNDR))
1697 DRM_WARN("System can't access extended configuration space, please check!!\n");
1699 /* skip if the bios has already enabled large BAR */
1700 if (adev->gmc.real_vram_size &&
1701 (pci_resource_len(adev->pdev, 0) >= adev->gmc.real_vram_size))
1704 /* Check if the root BUS has 64bit memory resources */
1705 root = adev->pdev->bus;
1706 while (root->parent)
1707 root = root->parent;
1709 pci_bus_for_each_resource(root, res, i) {
1710 if (res && res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
1711 res->start > 0x100000000ull)
1715 /* Trying to resize is pointless without a root hub window above 4GB */
1719 /* Limit the BAR size to what is available */
1720 rbar_size = min(fls(pci_rebar_get_possible_sizes(adev->pdev, 0)) - 1,
1723 /* Disable memory decoding while we change the BAR addresses and size */
1724 pci_read_config_word(adev->pdev, PCI_COMMAND, &cmd);
1725 pci_write_config_word(adev->pdev, PCI_COMMAND,
1726 cmd & ~PCI_COMMAND_MEMORY);
1728 /* Free the VRAM and doorbell BAR, we most likely need to move both. */
1729 amdgpu_doorbell_fini(adev);
1730 if (adev->asic_type >= CHIP_BONAIRE)
1731 pci_release_resource(adev->pdev, 2);
1733 pci_release_resource(adev->pdev, 0);
1735 r = pci_resize_resource(adev->pdev, 0, rbar_size);
1737 DRM_INFO("Not enough PCI address space for a large BAR.");
1738 else if (r && r != -ENOTSUPP)
1739 DRM_ERROR("Problem resizing BAR0 (%d).", r);
1741 pci_assign_unassigned_bus_resources(adev->pdev->bus);
1743 /* When the doorbell or fb BAR isn't available we have no chance of
1746 r = amdgpu_doorbell_init(adev);
1747 if (r || (pci_resource_flags(adev->pdev, 0) & IORESOURCE_UNSET))
1750 pci_write_config_word(adev->pdev, PCI_COMMAND, cmd);
1756 * GPU helpers function.
1759 * amdgpu_device_need_post - check if the hw need post or not
1761 * @adev: amdgpu_device pointer
1763 * Check if the asic has been initialized (all asics) at driver startup
1764 * or post is needed if hw reset is performed.
1765 * Returns true if need or false if not.
1767 bool amdgpu_device_need_post(struct amdgpu_device *adev)
1769 uint32_t reg, flags;
1771 if (amdgpu_sriov_vf(adev))
1774 flags = amdgpu_device_get_vbios_flags(adev);
1775 if (flags & AMDGPU_VBIOS_SKIP)
1777 if ((flags & AMDGPU_VBIOS_OPTIONAL) && !adev->bios)
1780 if (amdgpu_passthrough(adev)) {
1781 /* for FIJI: In whole GPU pass-through virtualization case, after VM reboot
1782 * some old smc fw still need driver do vPost otherwise gpu hang, while
1783 * those smc fw version above 22.15 doesn't have this flaw, so we force
1784 * vpost executed for smc version below 22.15
1786 if (adev->asic_type == CHIP_FIJI) {
1790 err = request_firmware(&adev->pm.fw, "amdgpu/fiji_smc.bin", adev->dev);
1791 /* force vPost if error occurred */
1795 fw_ver = *((uint32_t *)adev->pm.fw->data + 69);
1796 release_firmware(adev->pm.fw);
1797 if (fw_ver < 0x00160e00)
1802 /* Don't post if we need to reset whole hive on init */
1803 if (adev->init_lvl->level == AMDGPU_INIT_LEVEL_MINIMAL_XGMI)
1806 if (adev->has_hw_reset) {
1807 adev->has_hw_reset = false;
1811 /* bios scratch used on CIK+ */
1812 if (adev->asic_type >= CHIP_BONAIRE)
1813 return amdgpu_atombios_scratch_need_asic_init(adev);
1815 /* check MEM_SIZE for older asics */
1816 reg = amdgpu_asic_get_config_memsize(adev);
1818 if ((reg != 0) && (reg != 0xffffffff))
1825 * Check whether seamless boot is supported.
1827 * So far we only support seamless boot on DCE 3.0 or later.
1828 * If users report that it works on older ASICS as well, we may
1831 bool amdgpu_device_seamless_boot_supported(struct amdgpu_device *adev)
1833 switch (amdgpu_seamless) {
1841 DRM_ERROR("Invalid value for amdgpu.seamless: %d\n",
1846 if (!(adev->flags & AMD_IS_APU))
1849 if (adev->mman.keep_stolen_vga_memory)
1852 return amdgpu_ip_version(adev, DCE_HWIP, 0) >= IP_VERSION(3, 0, 0);
1856 * Intel hosts such as Rocket Lake, Alder Lake, Raptor Lake and Sapphire Rapids
1857 * don't support dynamic speed switching. Until we have confirmation from Intel
1858 * that a specific host supports it, it's safer that we keep it disabled for all.
1860 * https://edc.intel.com/content/www/us/en/design/products/platforms/details/raptor-lake-s/13th-generation-core-processors-datasheet-volume-1-of-2/005/pci-express-support/
1861 * https://gitlab.freedesktop.org/drm/amd/-/issues/2663
1863 static bool amdgpu_device_pcie_dynamic_switching_supported(struct amdgpu_device *adev)
1865 #if IS_ENABLED(CONFIG_X86)
1866 struct cpuinfo_x86 *c = &cpu_data(0);
1868 /* eGPU change speeds based on USB4 fabric conditions */
1869 if (dev_is_removable(adev->dev))
1872 if (c->x86_vendor == X86_VENDOR_INTEL)
1878 static bool amdgpu_device_aspm_support_quirk(struct amdgpu_device *adev)
1880 #if IS_ENABLED(CONFIG_X86)
1881 struct cpuinfo_x86 *c = &cpu_data(0);
1883 if (!(amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(12, 0, 0) ||
1884 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(12, 0, 1)))
1888 adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN5) {
1889 switch (c->x86_model) {
1890 case VFM_MODEL(INTEL_ALDERLAKE):
1891 case VFM_MODEL(INTEL_ALDERLAKE_L):
1892 case VFM_MODEL(INTEL_RAPTORLAKE):
1893 case VFM_MODEL(INTEL_RAPTORLAKE_P):
1894 case VFM_MODEL(INTEL_RAPTORLAKE_S):
1908 * amdgpu_device_should_use_aspm - check if the device should program ASPM
1910 * @adev: amdgpu_device pointer
1912 * Confirm whether the module parameter and pcie bridge agree that ASPM should
1913 * be set for this device.
1915 * Returns true if it should be used or false if not.
1917 bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev)
1919 switch (amdgpu_aspm) {
1929 if (adev->flags & AMD_IS_APU)
1931 if (amdgpu_device_aspm_support_quirk(adev))
1933 return pcie_aspm_enabled(adev->pdev);
1936 /* if we get transitioned to only one device, take VGA back */
1938 * amdgpu_device_vga_set_decode - enable/disable vga decode
1940 * @pdev: PCI device pointer
1941 * @state: enable/disable vga decode
1943 * Enable/disable vga decode (all asics).
1944 * Returns VGA resource flags.
1946 static unsigned int amdgpu_device_vga_set_decode(struct pci_dev *pdev,
1949 struct amdgpu_device *adev = drm_to_adev(pci_get_drvdata(pdev));
1951 amdgpu_asic_set_vga_state(adev, state);
1953 return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
1954 VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
1956 return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
1960 * amdgpu_device_check_block_size - validate the vm block size
1962 * @adev: amdgpu_device pointer
1964 * Validates the vm block size specified via module parameter.
1965 * The vm block size defines number of bits in page table versus page directory,
1966 * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
1967 * page table and the remaining bits are in the page directory.
1969 static void amdgpu_device_check_block_size(struct amdgpu_device *adev)
1971 /* defines number of bits in page table versus page directory,
1972 * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
1973 * page table and the remaining bits are in the page directory
1975 if (amdgpu_vm_block_size == -1)
1978 if (amdgpu_vm_block_size < 9) {
1979 dev_warn(adev->dev, "VM page table size (%d) too small\n",
1980 amdgpu_vm_block_size);
1981 amdgpu_vm_block_size = -1;
1986 * amdgpu_device_check_vm_size - validate the vm size
1988 * @adev: amdgpu_device pointer
1990 * Validates the vm size in GB specified via module parameter.
1991 * The VM size is the size of the GPU virtual memory space in GB.
1993 static void amdgpu_device_check_vm_size(struct amdgpu_device *adev)
1995 /* no need to check the default value */
1996 if (amdgpu_vm_size == -1)
1999 if (amdgpu_vm_size < 1) {
2000 dev_warn(adev->dev, "VM size (%d) too small, min is 1GB\n",
2002 amdgpu_vm_size = -1;
2006 static void amdgpu_device_check_smu_prv_buffer_size(struct amdgpu_device *adev)
2009 bool is_os_64 = (sizeof(void *) == 8);
2010 uint64_t total_memory;
2011 uint64_t dram_size_seven_GB = 0x1B8000000;
2012 uint64_t dram_size_three_GB = 0xB8000000;
2014 if (amdgpu_smu_memory_pool_size == 0)
2018 DRM_WARN("Not 64-bit OS, feature not supported\n");
2022 total_memory = (uint64_t)si.totalram * si.mem_unit;
2024 if ((amdgpu_smu_memory_pool_size == 1) ||
2025 (amdgpu_smu_memory_pool_size == 2)) {
2026 if (total_memory < dram_size_three_GB)
2028 } else if ((amdgpu_smu_memory_pool_size == 4) ||
2029 (amdgpu_smu_memory_pool_size == 8)) {
2030 if (total_memory < dram_size_seven_GB)
2033 DRM_WARN("Smu memory pool size not supported\n");
2036 adev->pm.smu_prv_buffer_size = amdgpu_smu_memory_pool_size << 28;
2041 DRM_WARN("No enough system memory\n");
2043 adev->pm.smu_prv_buffer_size = 0;
2046 static int amdgpu_device_init_apu_flags(struct amdgpu_device *adev)
2048 if (!(adev->flags & AMD_IS_APU) ||
2049 adev->asic_type < CHIP_RAVEN)
2052 switch (adev->asic_type) {
2054 if (adev->pdev->device == 0x15dd)
2055 adev->apu_flags |= AMD_APU_IS_RAVEN;
2056 if (adev->pdev->device == 0x15d8)
2057 adev->apu_flags |= AMD_APU_IS_PICASSO;
2060 if ((adev->pdev->device == 0x1636) ||
2061 (adev->pdev->device == 0x164c))
2062 adev->apu_flags |= AMD_APU_IS_RENOIR;
2064 adev->apu_flags |= AMD_APU_IS_GREEN_SARDINE;
2067 adev->apu_flags |= AMD_APU_IS_VANGOGH;
2069 case CHIP_YELLOW_CARP:
2071 case CHIP_CYAN_SKILLFISH:
2072 if ((adev->pdev->device == 0x13FE) ||
2073 (adev->pdev->device == 0x143F))
2074 adev->apu_flags |= AMD_APU_IS_CYAN_SKILLFISH2;
2084 * amdgpu_device_check_arguments - validate module params
2086 * @adev: amdgpu_device pointer
2088 * Validates certain module parameters and updates
2089 * the associated values used by the driver (all asics).
2091 static int amdgpu_device_check_arguments(struct amdgpu_device *adev)
2095 if (amdgpu_sched_jobs < 4) {
2096 dev_warn(adev->dev, "sched jobs (%d) must be at least 4\n",
2098 amdgpu_sched_jobs = 4;
2099 } else if (!is_power_of_2(amdgpu_sched_jobs)) {
2100 dev_warn(adev->dev, "sched jobs (%d) must be a power of 2\n",
2102 amdgpu_sched_jobs = roundup_pow_of_two(amdgpu_sched_jobs);
2105 if (amdgpu_gart_size != -1 && amdgpu_gart_size < 32) {
2106 /* gart size must be greater or equal to 32M */
2107 dev_warn(adev->dev, "gart size (%d) too small\n",
2109 amdgpu_gart_size = -1;
2112 if (amdgpu_gtt_size != -1 && amdgpu_gtt_size < 32) {
2113 /* gtt size must be greater or equal to 32M */
2114 dev_warn(adev->dev, "gtt size (%d) too small\n",
2116 amdgpu_gtt_size = -1;
2119 /* valid range is between 4 and 9 inclusive */
2120 if (amdgpu_vm_fragment_size != -1 &&
2121 (amdgpu_vm_fragment_size > 9 || amdgpu_vm_fragment_size < 4)) {
2122 dev_warn(adev->dev, "valid range is between 4 and 9\n");
2123 amdgpu_vm_fragment_size = -1;
2126 if (amdgpu_sched_hw_submission < 2) {
2127 dev_warn(adev->dev, "sched hw submission jobs (%d) must be at least 2\n",
2128 amdgpu_sched_hw_submission);
2129 amdgpu_sched_hw_submission = 2;
2130 } else if (!is_power_of_2(amdgpu_sched_hw_submission)) {
2131 dev_warn(adev->dev, "sched hw submission jobs (%d) must be a power of 2\n",
2132 amdgpu_sched_hw_submission);
2133 amdgpu_sched_hw_submission = roundup_pow_of_two(amdgpu_sched_hw_submission);
2136 if (amdgpu_reset_method < -1 || amdgpu_reset_method > 4) {
2137 dev_warn(adev->dev, "invalid option for reset method, reverting to default\n");
2138 amdgpu_reset_method = -1;
2141 amdgpu_device_check_smu_prv_buffer_size(adev);
2143 amdgpu_device_check_vm_size(adev);
2145 amdgpu_device_check_block_size(adev);
2147 adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type);
2149 for (i = 0; i < MAX_XCP; i++) {
2150 switch (amdgpu_enforce_isolation) {
2155 adev->enforce_isolation[i] = AMDGPU_ENFORCE_ISOLATION_DISABLE;
2159 adev->enforce_isolation[i] =
2160 AMDGPU_ENFORCE_ISOLATION_ENABLE;
2163 /* enable legacy mode */
2164 adev->enforce_isolation[i] =
2165 AMDGPU_ENFORCE_ISOLATION_ENABLE_LEGACY;
2168 /* enable only process isolation without submitting cleaner shader */
2169 adev->enforce_isolation[i] =
2170 AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER;
2179 * amdgpu_switcheroo_set_state - set switcheroo state
2181 * @pdev: pci dev pointer
2182 * @state: vga_switcheroo state
2184 * Callback for the switcheroo driver. Suspends or resumes
2185 * the asics before or after it is powered up using ACPI methods.
2187 static void amdgpu_switcheroo_set_state(struct pci_dev *pdev,
2188 enum vga_switcheroo_state state)
2190 struct drm_device *dev = pci_get_drvdata(pdev);
2193 if (amdgpu_device_supports_px(dev) && state == VGA_SWITCHEROO_OFF)
2196 if (state == VGA_SWITCHEROO_ON) {
2197 pr_info("switched on\n");
2198 /* don't suspend or resume card normally */
2199 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
2201 pci_set_power_state(pdev, PCI_D0);
2202 amdgpu_device_load_pci_state(pdev);
2203 r = pci_enable_device(pdev);
2205 DRM_WARN("pci_enable_device failed (%d)\n", r);
2206 amdgpu_device_resume(dev, true);
2208 dev->switch_power_state = DRM_SWITCH_POWER_ON;
2210 pr_info("switched off\n");
2211 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
2212 amdgpu_device_prepare(dev);
2213 amdgpu_device_suspend(dev, true);
2214 amdgpu_device_cache_pci_state(pdev);
2215 /* Shut down the device */
2216 pci_disable_device(pdev);
2217 pci_set_power_state(pdev, PCI_D3cold);
2218 dev->switch_power_state = DRM_SWITCH_POWER_OFF;
2223 * amdgpu_switcheroo_can_switch - see if switcheroo state can change
2225 * @pdev: pci dev pointer
2227 * Callback for the switcheroo driver. Check of the switcheroo
2228 * state can be changed.
2229 * Returns true if the state can be changed, false if not.
2231 static bool amdgpu_switcheroo_can_switch(struct pci_dev *pdev)
2233 struct drm_device *dev = pci_get_drvdata(pdev);
2236 * FIXME: open_count is protected by drm_global_mutex but that would lead to
2237 * locking inversion with the driver load path. And the access here is
2238 * completely racy anyway. So don't bother with locking for now.
2240 return atomic_read(&dev->open_count) == 0;
2243 static const struct vga_switcheroo_client_ops amdgpu_switcheroo_ops = {
2244 .set_gpu_state = amdgpu_switcheroo_set_state,
2246 .can_switch = amdgpu_switcheroo_can_switch,
2250 * amdgpu_device_ip_set_clockgating_state - set the CG state
2252 * @dev: amdgpu_device pointer
2253 * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
2254 * @state: clockgating state (gate or ungate)
2256 * Sets the requested clockgating state for all instances of
2257 * the hardware IP specified.
2258 * Returns the error code from the last instance.
2260 int amdgpu_device_ip_set_clockgating_state(void *dev,
2261 enum amd_ip_block_type block_type,
2262 enum amd_clockgating_state state)
2264 struct amdgpu_device *adev = dev;
2267 for (i = 0; i < adev->num_ip_blocks; i++) {
2268 if (!adev->ip_blocks[i].status.valid)
2270 if (adev->ip_blocks[i].version->type != block_type)
2272 if (!adev->ip_blocks[i].version->funcs->set_clockgating_state)
2274 r = adev->ip_blocks[i].version->funcs->set_clockgating_state(
2275 &adev->ip_blocks[i], state);
2277 DRM_ERROR("set_clockgating_state of IP block <%s> failed %d\n",
2278 adev->ip_blocks[i].version->funcs->name, r);
2284 * amdgpu_device_ip_set_powergating_state - set the PG state
2286 * @dev: amdgpu_device pointer
2287 * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
2288 * @state: powergating state (gate or ungate)
2290 * Sets the requested powergating state for all instances of
2291 * the hardware IP specified.
2292 * Returns the error code from the last instance.
2294 int amdgpu_device_ip_set_powergating_state(void *dev,
2295 enum amd_ip_block_type block_type,
2296 enum amd_powergating_state state)
2298 struct amdgpu_device *adev = dev;
2301 for (i = 0; i < adev->num_ip_blocks; i++) {
2302 if (!adev->ip_blocks[i].status.valid)
2304 if (adev->ip_blocks[i].version->type != block_type)
2306 if (!adev->ip_blocks[i].version->funcs->set_powergating_state)
2308 r = adev->ip_blocks[i].version->funcs->set_powergating_state(
2309 &adev->ip_blocks[i], state);
2311 DRM_ERROR("set_powergating_state of IP block <%s> failed %d\n",
2312 adev->ip_blocks[i].version->funcs->name, r);
2318 * amdgpu_device_ip_get_clockgating_state - get the CG state
2320 * @adev: amdgpu_device pointer
2321 * @flags: clockgating feature flags
2323 * Walks the list of IPs on the device and updates the clockgating
2324 * flags for each IP.
2325 * Updates @flags with the feature flags for each hardware IP where
2326 * clockgating is enabled.
2328 void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
2333 for (i = 0; i < adev->num_ip_blocks; i++) {
2334 if (!adev->ip_blocks[i].status.valid)
2336 if (adev->ip_blocks[i].version->funcs->get_clockgating_state)
2337 adev->ip_blocks[i].version->funcs->get_clockgating_state(
2338 &adev->ip_blocks[i], flags);
2343 * amdgpu_device_ip_wait_for_idle - wait for idle
2345 * @adev: amdgpu_device pointer
2346 * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
2348 * Waits for the request hardware IP to be idle.
2349 * Returns 0 for success or a negative error code on failure.
2351 int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
2352 enum amd_ip_block_type block_type)
2356 for (i = 0; i < adev->num_ip_blocks; i++) {
2357 if (!adev->ip_blocks[i].status.valid)
2359 if (adev->ip_blocks[i].version->type == block_type) {
2360 if (adev->ip_blocks[i].version->funcs->wait_for_idle) {
2361 r = adev->ip_blocks[i].version->funcs->wait_for_idle(
2362 &adev->ip_blocks[i]);
2374 * amdgpu_device_ip_is_valid - is the hardware IP enabled
2376 * @adev: amdgpu_device pointer
2377 * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
2379 * Check if the hardware IP is enable or not.
2380 * Returns true if it the IP is enable, false if not.
2382 bool amdgpu_device_ip_is_valid(struct amdgpu_device *adev,
2383 enum amd_ip_block_type block_type)
2387 for (i = 0; i < adev->num_ip_blocks; i++) {
2388 if (adev->ip_blocks[i].version->type == block_type)
2389 return adev->ip_blocks[i].status.valid;
2396 * amdgpu_device_ip_get_ip_block - get a hw IP pointer
2398 * @adev: amdgpu_device pointer
2399 * @type: Type of hardware IP (SMU, GFX, UVD, etc.)
2401 * Returns a pointer to the hardware IP block structure
2402 * if it exists for the asic, otherwise NULL.
2404 struct amdgpu_ip_block *
2405 amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
2406 enum amd_ip_block_type type)
2410 for (i = 0; i < adev->num_ip_blocks; i++)
2411 if (adev->ip_blocks[i].version->type == type)
2412 return &adev->ip_blocks[i];
2418 * amdgpu_device_ip_block_version_cmp
2420 * @adev: amdgpu_device pointer
2421 * @type: enum amd_ip_block_type
2422 * @major: major version
2423 * @minor: minor version
2425 * return 0 if equal or greater
2426 * return 1 if smaller or the ip_block doesn't exist
2428 int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
2429 enum amd_ip_block_type type,
2430 u32 major, u32 minor)
2432 struct amdgpu_ip_block *ip_block = amdgpu_device_ip_get_ip_block(adev, type);
2434 if (ip_block && ((ip_block->version->major > major) ||
2435 ((ip_block->version->major == major) &&
2436 (ip_block->version->minor >= minor))))
2443 * amdgpu_device_ip_block_add
2445 * @adev: amdgpu_device pointer
2446 * @ip_block_version: pointer to the IP to add
2448 * Adds the IP block driver information to the collection of IPs
2451 int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
2452 const struct amdgpu_ip_block_version *ip_block_version)
2454 if (!ip_block_version)
2457 switch (ip_block_version->type) {
2458 case AMD_IP_BLOCK_TYPE_VCN:
2459 if (adev->harvest_ip_mask & AMD_HARVEST_IP_VCN_MASK)
2462 case AMD_IP_BLOCK_TYPE_JPEG:
2463 if (adev->harvest_ip_mask & AMD_HARVEST_IP_JPEG_MASK)
2470 dev_info(adev->dev, "detected ip block number %d <%s>\n",
2471 adev->num_ip_blocks, ip_block_version->funcs->name);
2473 adev->ip_blocks[adev->num_ip_blocks].adev = adev;
2475 adev->ip_blocks[adev->num_ip_blocks++].version = ip_block_version;
2481 * amdgpu_device_enable_virtual_display - enable virtual display feature
2483 * @adev: amdgpu_device pointer
2485 * Enabled the virtual display feature if the user has enabled it via
2486 * the module parameter virtual_display. This feature provides a virtual
2487 * display hardware on headless boards or in virtualized environments.
2488 * This function parses and validates the configuration string specified by
2489 * the user and configures the virtual display configuration (number of
2490 * virtual connectors, crtcs, etc.) specified.
2492 static void amdgpu_device_enable_virtual_display(struct amdgpu_device *adev)
2494 adev->enable_virtual_display = false;
2496 if (amdgpu_virtual_display) {
2497 const char *pci_address_name = pci_name(adev->pdev);
2498 char *pciaddstr, *pciaddstr_tmp, *pciaddname_tmp, *pciaddname;
2500 pciaddstr = kstrdup(amdgpu_virtual_display, GFP_KERNEL);
2501 pciaddstr_tmp = pciaddstr;
2502 while ((pciaddname_tmp = strsep(&pciaddstr_tmp, ";"))) {
2503 pciaddname = strsep(&pciaddname_tmp, ",");
2504 if (!strcmp("all", pciaddname)
2505 || !strcmp(pci_address_name, pciaddname)) {
2509 adev->enable_virtual_display = true;
2512 res = kstrtol(pciaddname_tmp, 10,
2520 adev->mode_info.num_crtc = num_crtc;
2522 adev->mode_info.num_crtc = 1;
2528 DRM_INFO("virtual display string:%s, %s:virtual_display:%d, num_crtc:%d\n",
2529 amdgpu_virtual_display, pci_address_name,
2530 adev->enable_virtual_display, adev->mode_info.num_crtc);
2536 void amdgpu_device_set_sriov_virtual_display(struct amdgpu_device *adev)
2538 if (amdgpu_sriov_vf(adev) && !adev->enable_virtual_display) {
2539 adev->mode_info.num_crtc = 1;
2540 adev->enable_virtual_display = true;
2541 DRM_INFO("virtual_display:%d, num_crtc:%d\n",
2542 adev->enable_virtual_display, adev->mode_info.num_crtc);
2547 * amdgpu_device_parse_gpu_info_fw - parse gpu info firmware
2549 * @adev: amdgpu_device pointer
2551 * Parses the asic configuration parameters specified in the gpu info
2552 * firmware and makes them available to the driver for use in configuring
2554 * Returns 0 on success, -EINVAL on failure.
2556 static int amdgpu_device_parse_gpu_info_fw(struct amdgpu_device *adev)
2558 const char *chip_name;
2560 const struct gpu_info_firmware_header_v1_0 *hdr;
2562 adev->firmware.gpu_info_fw = NULL;
2564 if (adev->mman.discovery_bin)
2567 switch (adev->asic_type) {
2571 chip_name = "vega10";
2574 chip_name = "vega12";
2577 if (adev->apu_flags & AMD_APU_IS_RAVEN2)
2578 chip_name = "raven2";
2579 else if (adev->apu_flags & AMD_APU_IS_PICASSO)
2580 chip_name = "picasso";
2582 chip_name = "raven";
2585 chip_name = "arcturus";
2588 chip_name = "navi12";
2592 err = amdgpu_ucode_request(adev, &adev->firmware.gpu_info_fw,
2593 AMDGPU_UCODE_OPTIONAL,
2594 "amdgpu/%s_gpu_info.bin", chip_name);
2597 "Failed to get gpu_info firmware \"%s_gpu_info.bin\"\n",
2602 hdr = (const struct gpu_info_firmware_header_v1_0 *)adev->firmware.gpu_info_fw->data;
2603 amdgpu_ucode_print_gpu_info_hdr(&hdr->header);
2605 switch (hdr->version_major) {
2608 const struct gpu_info_firmware_v1_0 *gpu_info_fw =
2609 (const struct gpu_info_firmware_v1_0 *)(adev->firmware.gpu_info_fw->data +
2610 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
2613 * Should be dropped when DAL no longer needs it.
2615 if (adev->asic_type == CHIP_NAVI12)
2616 goto parse_soc_bounding_box;
2618 adev->gfx.config.max_shader_engines = le32_to_cpu(gpu_info_fw->gc_num_se);
2619 adev->gfx.config.max_cu_per_sh = le32_to_cpu(gpu_info_fw->gc_num_cu_per_sh);
2620 adev->gfx.config.max_sh_per_se = le32_to_cpu(gpu_info_fw->gc_num_sh_per_se);
2621 adev->gfx.config.max_backends_per_se = le32_to_cpu(gpu_info_fw->gc_num_rb_per_se);
2622 adev->gfx.config.max_texture_channel_caches =
2623 le32_to_cpu(gpu_info_fw->gc_num_tccs);
2624 adev->gfx.config.max_gprs = le32_to_cpu(gpu_info_fw->gc_num_gprs);
2625 adev->gfx.config.max_gs_threads = le32_to_cpu(gpu_info_fw->gc_num_max_gs_thds);
2626 adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gpu_info_fw->gc_gs_table_depth);
2627 adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gpu_info_fw->gc_gsprim_buff_depth);
2628 adev->gfx.config.double_offchip_lds_buf =
2629 le32_to_cpu(gpu_info_fw->gc_double_offchip_lds_buffer);
2630 adev->gfx.cu_info.wave_front_size = le32_to_cpu(gpu_info_fw->gc_wave_size);
2631 adev->gfx.cu_info.max_waves_per_simd =
2632 le32_to_cpu(gpu_info_fw->gc_max_waves_per_simd);
2633 adev->gfx.cu_info.max_scratch_slots_per_cu =
2634 le32_to_cpu(gpu_info_fw->gc_max_scratch_slots_per_cu);
2635 adev->gfx.cu_info.lds_size = le32_to_cpu(gpu_info_fw->gc_lds_size);
2636 if (hdr->version_minor >= 1) {
2637 const struct gpu_info_firmware_v1_1 *gpu_info_fw =
2638 (const struct gpu_info_firmware_v1_1 *)(adev->firmware.gpu_info_fw->data +
2639 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
2640 adev->gfx.config.num_sc_per_sh =
2641 le32_to_cpu(gpu_info_fw->num_sc_per_sh);
2642 adev->gfx.config.num_packer_per_sc =
2643 le32_to_cpu(gpu_info_fw->num_packer_per_sc);
2646 parse_soc_bounding_box:
2648 * soc bounding box info is not integrated in disocovery table,
2649 * we always need to parse it from gpu info firmware if needed.
2651 if (hdr->version_minor == 2) {
2652 const struct gpu_info_firmware_v1_2 *gpu_info_fw =
2653 (const struct gpu_info_firmware_v1_2 *)(adev->firmware.gpu_info_fw->data +
2654 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
2655 adev->dm.soc_bounding_box = &gpu_info_fw->soc_bounding_box;
2661 "Unsupported gpu_info table %d\n", hdr->header.ucode_version);
2670 * amdgpu_device_ip_early_init - run early init for hardware IPs
2672 * @adev: amdgpu_device pointer
2674 * Early initialization pass for hardware IPs. The hardware IPs that make
2675 * up each asic are discovered each IP's early_init callback is run. This
2676 * is the first stage in initializing the asic.
2677 * Returns 0 on success, negative error code on failure.
2679 static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
2681 struct amdgpu_ip_block *ip_block;
2682 struct pci_dev *parent;
2683 bool total, skip_bios;
2684 uint32_t bios_flags;
2687 amdgpu_device_enable_virtual_display(adev);
2689 if (amdgpu_sriov_vf(adev)) {
2690 r = amdgpu_virt_request_full_gpu(adev, true);
2695 switch (adev->asic_type) {
2696 #ifdef CONFIG_DRM_AMDGPU_SI
2702 adev->family = AMDGPU_FAMILY_SI;
2703 r = si_set_ip_blocks(adev);
2708 #ifdef CONFIG_DRM_AMDGPU_CIK
2714 if (adev->flags & AMD_IS_APU)
2715 adev->family = AMDGPU_FAMILY_KV;
2717 adev->family = AMDGPU_FAMILY_CI;
2719 r = cik_set_ip_blocks(adev);
2727 case CHIP_POLARIS10:
2728 case CHIP_POLARIS11:
2729 case CHIP_POLARIS12:
2733 if (adev->flags & AMD_IS_APU)
2734 adev->family = AMDGPU_FAMILY_CZ;
2736 adev->family = AMDGPU_FAMILY_VI;
2738 r = vi_set_ip_blocks(adev);
2743 r = amdgpu_discovery_set_ip_blocks(adev);
2749 /* Check for IP version 9.4.3 with A0 hardware */
2750 if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
2751 !amdgpu_device_get_rev_id(adev)) {
2752 dev_err(adev->dev, "Unsupported A0 hardware\n");
2753 return -ENODEV; /* device unsupported - no device error */
2756 if (amdgpu_has_atpx() &&
2757 (amdgpu_is_atpx_hybrid() ||
2758 amdgpu_has_atpx_dgpu_power_cntl()) &&
2759 ((adev->flags & AMD_IS_APU) == 0) &&
2760 !dev_is_removable(&adev->pdev->dev))
2761 adev->flags |= AMD_IS_PX;
2763 if (!(adev->flags & AMD_IS_APU)) {
2764 parent = pcie_find_root_port(adev->pdev);
2765 adev->has_pr3 = parent ? pci_pr3_present(parent) : false;
2768 adev->pm.pp_feature = amdgpu_pp_feature_mask;
2769 if (amdgpu_sriov_vf(adev) || sched_policy == KFD_SCHED_POLICY_NO_HWS)
2770 adev->pm.pp_feature &= ~PP_GFXOFF_MASK;
2771 if (amdgpu_sriov_vf(adev) && adev->asic_type == CHIP_SIENNA_CICHLID)
2772 adev->pm.pp_feature &= ~PP_OVERDRIVE_MASK;
2773 if (!amdgpu_device_pcie_dynamic_switching_supported(adev))
2774 adev->pm.pp_feature &= ~PP_PCIE_DPM_MASK;
2777 for (i = 0; i < adev->num_ip_blocks; i++) {
2778 ip_block = &adev->ip_blocks[i];
2780 if ((amdgpu_ip_block_mask & (1 << i)) == 0) {
2781 DRM_WARN("disabled ip block: %d <%s>\n",
2782 i, adev->ip_blocks[i].version->funcs->name);
2783 adev->ip_blocks[i].status.valid = false;
2784 } else if (ip_block->version->funcs->early_init) {
2785 r = ip_block->version->funcs->early_init(ip_block);
2787 adev->ip_blocks[i].status.valid = false;
2789 DRM_ERROR("early_init of IP block <%s> failed %d\n",
2790 adev->ip_blocks[i].version->funcs->name, r);
2793 adev->ip_blocks[i].status.valid = true;
2796 adev->ip_blocks[i].status.valid = true;
2798 /* get the vbios after the asic_funcs are set up */
2799 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
2800 r = amdgpu_device_parse_gpu_info_fw(adev);
2804 bios_flags = amdgpu_device_get_vbios_flags(adev);
2805 skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
2809 !!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
2810 if (!amdgpu_get_bios(adev) && !optional)
2813 if (optional && !adev->bios)
2816 "VBIOS image optional, proceeding without VBIOS image");
2819 r = amdgpu_atombios_init(adev);
2822 "amdgpu_atombios_init failed\n");
2823 amdgpu_vf_error_put(
2825 AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
2832 /*get pf2vf msg info at it's earliest time*/
2833 if (amdgpu_sriov_vf(adev))
2834 amdgpu_virt_init_data_exchange(adev);
2841 if (adev->gmc.xgmi.supported)
2842 amdgpu_xgmi_early_init(adev);
2844 ip_block = amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_GFX);
2845 if (ip_block->status.valid != false)
2846 amdgpu_amdkfd_device_probe(adev);
2848 adev->cg_flags &= amdgpu_cg_mask;
2849 adev->pg_flags &= amdgpu_pg_mask;
2854 static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
2858 for (i = 0; i < adev->num_ip_blocks; i++) {
2859 if (!adev->ip_blocks[i].status.sw)
2861 if (adev->ip_blocks[i].status.hw)
2863 if (!amdgpu_ip_member_of_hwini(
2864 adev, adev->ip_blocks[i].version->type))
2866 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
2867 (amdgpu_sriov_vf(adev) && (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP)) ||
2868 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH) {
2869 r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
2871 DRM_ERROR("hw_init of IP block <%s> failed %d\n",
2872 adev->ip_blocks[i].version->funcs->name, r);
2875 adev->ip_blocks[i].status.hw = true;
2882 static int amdgpu_device_ip_hw_init_phase2(struct amdgpu_device *adev)
2886 for (i = 0; i < adev->num_ip_blocks; i++) {
2887 if (!adev->ip_blocks[i].status.sw)
2889 if (adev->ip_blocks[i].status.hw)
2891 if (!amdgpu_ip_member_of_hwini(
2892 adev, adev->ip_blocks[i].version->type))
2894 r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
2896 DRM_ERROR("hw_init of IP block <%s> failed %d\n",
2897 adev->ip_blocks[i].version->funcs->name, r);
2900 adev->ip_blocks[i].status.hw = true;
2906 static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
2910 uint32_t smu_version;
2912 if (adev->asic_type >= CHIP_VEGA10) {
2913 for (i = 0; i < adev->num_ip_blocks; i++) {
2914 if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_PSP)
2917 if (!amdgpu_ip_member_of_hwini(adev,
2918 AMD_IP_BLOCK_TYPE_PSP))
2921 if (!adev->ip_blocks[i].status.sw)
2924 /* no need to do the fw loading again if already done*/
2925 if (adev->ip_blocks[i].status.hw == true)
2928 if (amdgpu_in_reset(adev) || adev->in_suspend) {
2929 r = amdgpu_ip_block_resume(&adev->ip_blocks[i]);
2933 r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
2935 DRM_ERROR("hw_init of IP block <%s> failed %d\n",
2936 adev->ip_blocks[i].version->funcs->name, r);
2939 adev->ip_blocks[i].status.hw = true;
2945 if (!amdgpu_sriov_vf(adev) || adev->asic_type == CHIP_TONGA)
2946 r = amdgpu_pm_load_smu_firmware(adev, &smu_version);
2951 static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
2953 struct drm_sched_init_args args = {
2954 .ops = &amdgpu_sched_ops,
2955 .num_rqs = DRM_SCHED_PRIORITY_COUNT,
2956 .timeout_wq = adev->reset_domain->wq,
2962 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
2963 struct amdgpu_ring *ring = adev->rings[i];
2965 /* No need to setup the GPU scheduler for rings that don't need it */
2966 if (!ring || ring->no_scheduler)
2969 switch (ring->funcs->type) {
2970 case AMDGPU_RING_TYPE_GFX:
2971 timeout = adev->gfx_timeout;
2973 case AMDGPU_RING_TYPE_COMPUTE:
2974 timeout = adev->compute_timeout;
2976 case AMDGPU_RING_TYPE_SDMA:
2977 timeout = adev->sdma_timeout;
2980 timeout = adev->video_timeout;
2984 args.timeout = timeout;
2985 args.credit_limit = ring->num_hw_submission;
2986 args.score = ring->sched_score;
2987 args.name = ring->name;
2989 r = drm_sched_init(&ring->sched, &args);
2991 DRM_ERROR("Failed to create scheduler on ring %s.\n",
2995 r = amdgpu_uvd_entity_init(adev, ring);
2997 DRM_ERROR("Failed to create UVD scheduling entity on ring %s.\n",
3001 r = amdgpu_vce_entity_init(adev, ring);
3003 DRM_ERROR("Failed to create VCE scheduling entity on ring %s.\n",
3009 amdgpu_xcp_update_partition_sched_list(adev);
3016 * amdgpu_device_ip_init - run init for hardware IPs
3018 * @adev: amdgpu_device pointer
3020 * Main initialization pass for hardware IPs. The list of all the hardware
3021 * IPs that make up the asic is walked and the sw_init and hw_init callbacks
3022 * are run. sw_init initializes the software state associated with each IP
3023 * and hw_init initializes the hardware associated with each IP.
3024 * Returns 0 on success, negative error code on failure.
3026 static int amdgpu_device_ip_init(struct amdgpu_device *adev)
3031 r = amdgpu_ras_init(adev);
3035 for (i = 0; i < adev->num_ip_blocks; i++) {
3036 if (!adev->ip_blocks[i].status.valid)
3038 if (adev->ip_blocks[i].version->funcs->sw_init) {
3039 r = adev->ip_blocks[i].version->funcs->sw_init(&adev->ip_blocks[i]);
3041 DRM_ERROR("sw_init of IP block <%s> failed %d\n",
3042 adev->ip_blocks[i].version->funcs->name, r);
3046 adev->ip_blocks[i].status.sw = true;
3048 if (!amdgpu_ip_member_of_hwini(
3049 adev, adev->ip_blocks[i].version->type))
3052 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
3053 /* need to do common hw init early so everything is set up for gmc */
3054 r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
3056 DRM_ERROR("hw_init %d failed %d\n", i, r);
3059 adev->ip_blocks[i].status.hw = true;
3060 } else if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
3061 /* need to do gmc hw init early so we can allocate gpu mem */
3062 /* Try to reserve bad pages early */
3063 if (amdgpu_sriov_vf(adev))
3064 amdgpu_virt_exchange_data(adev);
3066 r = amdgpu_device_mem_scratch_init(adev);
3068 DRM_ERROR("amdgpu_mem_scratch_init failed %d\n", r);
3071 r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
3073 DRM_ERROR("hw_init %d failed %d\n", i, r);
3076 r = amdgpu_device_wb_init(adev);
3078 DRM_ERROR("amdgpu_device_wb_init failed %d\n", r);
3081 adev->ip_blocks[i].status.hw = true;
3083 /* right after GMC hw init, we create CSA */
3084 if (adev->gfx.mcbp) {
3085 r = amdgpu_allocate_static_csa(adev, &adev->virt.csa_obj,
3086 AMDGPU_GEM_DOMAIN_VRAM |
3087 AMDGPU_GEM_DOMAIN_GTT,
3090 DRM_ERROR("allocate CSA failed %d\n", r);
3095 r = amdgpu_seq64_init(adev);
3097 DRM_ERROR("allocate seq64 failed %d\n", r);
3103 if (amdgpu_sriov_vf(adev))
3104 amdgpu_virt_init_data_exchange(adev);
3106 r = amdgpu_ib_pool_init(adev);
3108 dev_err(adev->dev, "IB initialization failed (%d).\n", r);
3109 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_IB_INIT_FAIL, 0, r);
3113 r = amdgpu_ucode_create_bo(adev); /* create ucode bo when sw_init complete*/
3117 r = amdgpu_device_ip_hw_init_phase1(adev);
3121 r = amdgpu_device_fw_loading(adev);
3125 r = amdgpu_device_ip_hw_init_phase2(adev);
3130 * retired pages will be loaded from eeprom and reserved here,
3131 * it should be called after amdgpu_device_ip_hw_init_phase2 since
3132 * for some ASICs the RAS EEPROM code relies on SMU fully functioning
3133 * for I2C communication which only true at this point.
3135 * amdgpu_ras_recovery_init may fail, but the upper only cares the
3136 * failure from bad gpu situation and stop amdgpu init process
3137 * accordingly. For other failed cases, it will still release all
3138 * the resource and print error message, rather than returning one
3139 * negative value to upper level.
3141 * Note: theoretically, this should be called before all vram allocations
3142 * to protect retired page from abusing
3144 init_badpage = (adev->init_lvl->level != AMDGPU_INIT_LEVEL_MINIMAL_XGMI);
3145 r = amdgpu_ras_recovery_init(adev, init_badpage);
3150 * In case of XGMI grab extra reference for reset domain for this device
3152 if (adev->gmc.xgmi.num_physical_nodes > 1) {
3153 if (amdgpu_xgmi_add_device(adev) == 0) {
3154 if (!amdgpu_sriov_vf(adev)) {
3155 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
3157 if (WARN_ON(!hive)) {
3162 if (!hive->reset_domain ||
3163 !amdgpu_reset_get_reset_domain(hive->reset_domain)) {
3165 amdgpu_put_xgmi_hive(hive);
3169 /* Drop the early temporary reset domain we created for device */
3170 amdgpu_reset_put_reset_domain(adev->reset_domain);
3171 adev->reset_domain = hive->reset_domain;
3172 amdgpu_put_xgmi_hive(hive);
3177 r = amdgpu_device_init_schedulers(adev);
3181 if (adev->mman.buffer_funcs_ring->sched.ready)
3182 amdgpu_ttm_set_buffer_funcs_status(adev, true);
3184 /* Don't init kfd if whole hive need to be reset during init */
3185 if (adev->init_lvl->level != AMDGPU_INIT_LEVEL_MINIMAL_XGMI) {
3186 kgd2kfd_init_zone_device(adev);
3187 amdgpu_amdkfd_device_init(adev);
3190 amdgpu_fru_get_product_info(adev);
3192 if (!amdgpu_sriov_vf(adev) || amdgpu_sriov_ras_cper_en(adev))
3193 r = amdgpu_cper_init(adev);
3201 * amdgpu_device_fill_reset_magic - writes reset magic to gart pointer
3203 * @adev: amdgpu_device pointer
3205 * Writes a reset magic value to the gart pointer in VRAM. The driver calls
3206 * this function before a GPU reset. If the value is retained after a
3207 * GPU reset, VRAM has not been lost. Some GPU resets may destroy VRAM contents.
3209 static void amdgpu_device_fill_reset_magic(struct amdgpu_device *adev)
3211 memcpy(adev->reset_magic, adev->gart.ptr, AMDGPU_RESET_MAGIC_NUM);
3215 * amdgpu_device_check_vram_lost - check if vram is valid
3217 * @adev: amdgpu_device pointer
3219 * Checks the reset magic value written to the gart pointer in VRAM.
3220 * The driver calls this after a GPU reset to see if the contents of
3221 * VRAM is lost or now.
3222 * returns true if vram is lost, false if not.
3224 static bool amdgpu_device_check_vram_lost(struct amdgpu_device *adev)
3226 if (memcmp(adev->gart.ptr, adev->reset_magic,
3227 AMDGPU_RESET_MAGIC_NUM))
3230 if (!amdgpu_in_reset(adev))
3234 * For all ASICs with baco/mode1 reset, the VRAM is
3235 * always assumed to be lost.
3237 switch (amdgpu_asic_reset_method(adev)) {
3238 case AMD_RESET_METHOD_LINK:
3239 case AMD_RESET_METHOD_BACO:
3240 case AMD_RESET_METHOD_MODE1:
3248 * amdgpu_device_set_cg_state - set clockgating for amdgpu device
3250 * @adev: amdgpu_device pointer
3251 * @state: clockgating state (gate or ungate)
3253 * The list of all the hardware IPs that make up the asic is walked and the
3254 * set_clockgating_state callbacks are run.
3255 * Late initialization pass enabling clockgating for hardware IPs.
3256 * Fini or suspend, pass disabling clockgating for hardware IPs.
3257 * Returns 0 on success, negative error code on failure.
3260 int amdgpu_device_set_cg_state(struct amdgpu_device *adev,
3261 enum amd_clockgating_state state)
3265 if (amdgpu_emu_mode == 1)
3268 for (j = 0; j < adev->num_ip_blocks; j++) {
3269 i = state == AMD_CG_STATE_GATE ? j : adev->num_ip_blocks - j - 1;
3270 if (!adev->ip_blocks[i].status.late_initialized)
3272 /* skip CG for GFX, SDMA on S0ix */
3273 if (adev->in_s0ix &&
3274 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GFX ||
3275 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SDMA))
3277 /* skip CG for VCE/UVD, it's handled specially */
3278 if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
3279 adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE &&
3280 adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCN &&
3281 adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_JPEG &&
3282 adev->ip_blocks[i].version->funcs->set_clockgating_state) {
3283 /* enable clockgating to save power */
3284 r = adev->ip_blocks[i].version->funcs->set_clockgating_state(&adev->ip_blocks[i],
3287 DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n",
3288 adev->ip_blocks[i].version->funcs->name, r);
3297 int amdgpu_device_set_pg_state(struct amdgpu_device *adev,
3298 enum amd_powergating_state state)
3302 if (amdgpu_emu_mode == 1)
3305 for (j = 0; j < adev->num_ip_blocks; j++) {
3306 i = state == AMD_PG_STATE_GATE ? j : adev->num_ip_blocks - j - 1;
3307 if (!adev->ip_blocks[i].status.late_initialized)
3309 /* skip PG for GFX, SDMA on S0ix */
3310 if (adev->in_s0ix &&
3311 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GFX ||
3312 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SDMA))
3314 /* skip CG for VCE/UVD, it's handled specially */
3315 if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
3316 adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE &&
3317 adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCN &&
3318 adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_JPEG &&
3319 adev->ip_blocks[i].version->funcs->set_powergating_state) {
3320 /* enable powergating to save power */
3321 r = adev->ip_blocks[i].version->funcs->set_powergating_state(&adev->ip_blocks[i],
3324 DRM_ERROR("set_powergating_state(gate) of IP block <%s> failed %d\n",
3325 adev->ip_blocks[i].version->funcs->name, r);
3333 static int amdgpu_device_enable_mgpu_fan_boost(void)
3335 struct amdgpu_gpu_instance *gpu_ins;
3336 struct amdgpu_device *adev;
3339 mutex_lock(&mgpu_info.mutex);
3342 * MGPU fan boost feature should be enabled
3343 * only when there are two or more dGPUs in
3346 if (mgpu_info.num_dgpu < 2)
3349 for (i = 0; i < mgpu_info.num_dgpu; i++) {
3350 gpu_ins = &(mgpu_info.gpu_ins[i]);
3351 adev = gpu_ins->adev;
3352 if (!(adev->flags & AMD_IS_APU) &&
3353 !gpu_ins->mgpu_fan_enabled) {
3354 ret = amdgpu_dpm_enable_mgpu_fan_boost(adev);
3358 gpu_ins->mgpu_fan_enabled = 1;
3363 mutex_unlock(&mgpu_info.mutex);
3369 * amdgpu_device_ip_late_init - run late init for hardware IPs
3371 * @adev: amdgpu_device pointer
3373 * Late initialization pass for hardware IPs. The list of all the hardware
3374 * IPs that make up the asic is walked and the late_init callbacks are run.
3375 * late_init covers any special initialization that an IP requires
3376 * after all of the have been initialized or something that needs to happen
3377 * late in the init process.
3378 * Returns 0 on success, negative error code on failure.
3380 static int amdgpu_device_ip_late_init(struct amdgpu_device *adev)
3382 struct amdgpu_gpu_instance *gpu_instance;
3385 for (i = 0; i < adev->num_ip_blocks; i++) {
3386 if (!adev->ip_blocks[i].status.hw)
3388 if (adev->ip_blocks[i].version->funcs->late_init) {
3389 r = adev->ip_blocks[i].version->funcs->late_init(&adev->ip_blocks[i]);
3391 DRM_ERROR("late_init of IP block <%s> failed %d\n",
3392 adev->ip_blocks[i].version->funcs->name, r);
3396 adev->ip_blocks[i].status.late_initialized = true;
3399 r = amdgpu_ras_late_init(adev);
3401 DRM_ERROR("amdgpu_ras_late_init failed %d", r);
3405 if (!amdgpu_reset_in_recovery(adev))
3406 amdgpu_ras_set_error_query_ready(adev, true);
3408 amdgpu_device_set_cg_state(adev, AMD_CG_STATE_GATE);
3409 amdgpu_device_set_pg_state(adev, AMD_PG_STATE_GATE);
3411 amdgpu_device_fill_reset_magic(adev);
3413 r = amdgpu_device_enable_mgpu_fan_boost();
3415 DRM_ERROR("enable mgpu fan boost failed (%d).\n", r);
3417 /* For passthrough configuration on arcturus and aldebaran, enable special handling SBR */
3418 if (amdgpu_passthrough(adev) &&
3419 ((adev->asic_type == CHIP_ARCTURUS && adev->gmc.xgmi.num_physical_nodes > 1) ||
3420 adev->asic_type == CHIP_ALDEBARAN))
3421 amdgpu_dpm_handle_passthrough_sbr(adev, true);
3423 if (adev->gmc.xgmi.num_physical_nodes > 1) {
3424 mutex_lock(&mgpu_info.mutex);
3427 * Reset device p-state to low as this was booted with high.
3429 * This should be performed only after all devices from the same
3430 * hive get initialized.
3432 * However, it's unknown how many device in the hive in advance.
3433 * As this is counted one by one during devices initializations.
3435 * So, we wait for all XGMI interlinked devices initialized.
3436 * This may bring some delays as those devices may come from
3437 * different hives. But that should be OK.
3439 if (mgpu_info.num_dgpu == adev->gmc.xgmi.num_physical_nodes) {
3440 for (i = 0; i < mgpu_info.num_gpu; i++) {
3441 gpu_instance = &(mgpu_info.gpu_ins[i]);
3442 if (gpu_instance->adev->flags & AMD_IS_APU)
3445 r = amdgpu_xgmi_set_pstate(gpu_instance->adev,
3446 AMDGPU_XGMI_PSTATE_MIN);
3448 DRM_ERROR("pstate setting failed (%d).\n", r);
3454 mutex_unlock(&mgpu_info.mutex);
3460 static void amdgpu_ip_block_hw_fini(struct amdgpu_ip_block *ip_block)
3464 if (!ip_block->version->funcs->hw_fini) {
3465 DRM_ERROR("hw_fini of IP block <%s> not defined\n",
3466 ip_block->version->funcs->name);
3468 r = ip_block->version->funcs->hw_fini(ip_block);
3469 /* XXX handle errors */
3471 DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
3472 ip_block->version->funcs->name, r);
3476 ip_block->status.hw = false;
3480 * amdgpu_device_smu_fini_early - smu hw_fini wrapper
3482 * @adev: amdgpu_device pointer
3484 * For ASICs need to disable SMC first
3486 static void amdgpu_device_smu_fini_early(struct amdgpu_device *adev)
3490 if (amdgpu_ip_version(adev, GC_HWIP, 0) > IP_VERSION(9, 0, 0))
3493 for (i = 0; i < adev->num_ip_blocks; i++) {
3494 if (!adev->ip_blocks[i].status.hw)
3496 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) {
3497 amdgpu_ip_block_hw_fini(&adev->ip_blocks[i]);
3503 static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev)
3507 for (i = 0; i < adev->num_ip_blocks; i++) {
3508 if (!adev->ip_blocks[i].version->funcs->early_fini)
3511 r = adev->ip_blocks[i].version->funcs->early_fini(&adev->ip_blocks[i]);
3513 DRM_DEBUG("early_fini of IP block <%s> failed %d\n",
3514 adev->ip_blocks[i].version->funcs->name, r);
3518 amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE);
3519 amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);
3521 amdgpu_amdkfd_suspend(adev, false);
3522 amdgpu_userq_suspend(adev);
3524 /* Workaround for ASICs need to disable SMC first */
3525 amdgpu_device_smu_fini_early(adev);
3527 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
3528 if (!adev->ip_blocks[i].status.hw)
3531 amdgpu_ip_block_hw_fini(&adev->ip_blocks[i]);
3534 if (amdgpu_sriov_vf(adev)) {
3535 if (amdgpu_virt_release_full_gpu(adev, false))
3536 DRM_ERROR("failed to release exclusive mode on fini\n");
3543 * amdgpu_device_ip_fini - run fini for hardware IPs
3545 * @adev: amdgpu_device pointer
3547 * Main teardown pass for hardware IPs. The list of all the hardware
3548 * IPs that make up the asic is walked and the hw_fini and sw_fini callbacks
3549 * are run. hw_fini tears down the hardware associated with each IP
3550 * and sw_fini tears down any software state associated with each IP.
3551 * Returns 0 on success, negative error code on failure.
3553 static int amdgpu_device_ip_fini(struct amdgpu_device *adev)
3557 amdgpu_cper_fini(adev);
3559 if (amdgpu_sriov_vf(adev) && adev->virt.ras_init_done)
3560 amdgpu_virt_release_ras_err_handler_data(adev);
3562 if (adev->gmc.xgmi.num_physical_nodes > 1)
3563 amdgpu_xgmi_remove_device(adev);
3565 amdgpu_amdkfd_device_fini_sw(adev);
3567 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
3568 if (!adev->ip_blocks[i].status.sw)
3571 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
3572 amdgpu_ucode_free_bo(adev);
3573 amdgpu_free_static_csa(&adev->virt.csa_obj);
3574 amdgpu_device_wb_fini(adev);
3575 amdgpu_device_mem_scratch_fini(adev);
3576 amdgpu_ib_pool_fini(adev);
3577 amdgpu_seq64_fini(adev);
3578 amdgpu_doorbell_fini(adev);
3580 if (adev->ip_blocks[i].version->funcs->sw_fini) {
3581 r = adev->ip_blocks[i].version->funcs->sw_fini(&adev->ip_blocks[i]);
3582 /* XXX handle errors */
3584 DRM_DEBUG("sw_fini of IP block <%s> failed %d\n",
3585 adev->ip_blocks[i].version->funcs->name, r);
3588 adev->ip_blocks[i].status.sw = false;
3589 adev->ip_blocks[i].status.valid = false;
3592 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
3593 if (!adev->ip_blocks[i].status.late_initialized)
3595 if (adev->ip_blocks[i].version->funcs->late_fini)
3596 adev->ip_blocks[i].version->funcs->late_fini(&adev->ip_blocks[i]);
3597 adev->ip_blocks[i].status.late_initialized = false;
3600 amdgpu_ras_fini(adev);
3606 * amdgpu_device_delayed_init_work_handler - work handler for IB tests
3608 * @work: work_struct.
3610 static void amdgpu_device_delayed_init_work_handler(struct work_struct *work)
3612 struct amdgpu_device *adev =
3613 container_of(work, struct amdgpu_device, delayed_init_work.work);
3616 r = amdgpu_ib_ring_tests(adev);
3618 DRM_ERROR("ib ring test failed (%d).\n", r);
3621 static void amdgpu_device_delay_enable_gfx_off(struct work_struct *work)
3623 struct amdgpu_device *adev =
3624 container_of(work, struct amdgpu_device, gfx.gfx_off_delay_work.work);
3626 WARN_ON_ONCE(adev->gfx.gfx_off_state);
3627 WARN_ON_ONCE(adev->gfx.gfx_off_req_count);
3629 if (!amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_GFX, true, 0))
3630 adev->gfx.gfx_off_state = true;
3634 * amdgpu_device_ip_suspend_phase1 - run suspend for hardware IPs (phase 1)
3636 * @adev: amdgpu_device pointer
3638 * Main suspend function for hardware IPs. The list of all the hardware
3639 * IPs that make up the asic is walked, clockgating is disabled and the
3640 * suspend callbacks are run. suspend puts the hardware and software state
3641 * in each IP into a state suitable for suspend.
3642 * Returns 0 on success, negative error code on failure.
3644 static int amdgpu_device_ip_suspend_phase1(struct amdgpu_device *adev)
3648 amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE);
3649 amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);
3652 * Per PMFW team's suggestion, driver needs to handle gfxoff
3653 * and df cstate features disablement for gpu reset(e.g. Mode1Reset)
3654 * scenario. Add the missing df cstate disablement here.
3656 if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
3657 dev_warn(adev->dev, "Failed to disallow df cstate");
3659 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
3660 if (!adev->ip_blocks[i].status.valid)
3663 /* displays are handled separately */
3664 if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_DCE)
3667 /* XXX handle errors */
3668 r = amdgpu_ip_block_suspend(&adev->ip_blocks[i]);
3677 * amdgpu_device_ip_suspend_phase2 - run suspend for hardware IPs (phase 2)
3679 * @adev: amdgpu_device pointer
3681 * Main suspend function for hardware IPs. The list of all the hardware
3682 * IPs that make up the asic is walked, clockgating is disabled and the
3683 * suspend callbacks are run. suspend puts the hardware and software state
3684 * in each IP into a state suitable for suspend.
3685 * Returns 0 on success, negative error code on failure.
3687 static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)
3692 amdgpu_dpm_gfx_state_change(adev, sGpuChangeState_D3Entry);
3694 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
3695 if (!adev->ip_blocks[i].status.valid)
3697 /* displays are handled in phase1 */
3698 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE)
3700 /* PSP lost connection when err_event_athub occurs */
3701 if (amdgpu_ras_intr_triggered() &&
3702 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP) {
3703 adev->ip_blocks[i].status.hw = false;
3707 /* skip unnecessary suspend if we do not initialize them yet */
3708 if (!amdgpu_ip_member_of_hwini(
3709 adev, adev->ip_blocks[i].version->type))
3712 /* Since we skip suspend for S0i3, we need to cancel the delayed
3713 * idle work here as the suspend callback never gets called.
3715 if (adev->in_s0ix &&
3716 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GFX &&
3717 amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(10, 0, 0))
3718 cancel_delayed_work_sync(&adev->gfx.idle_work);
3719 /* skip suspend of gfx/mes and psp for S0ix
3720 * gfx is in gfxoff state, so on resume it will exit gfxoff just
3721 * like at runtime. PSP is also part of the always on hardware
3722 * so no need to suspend it.
3724 if (adev->in_s0ix &&
3725 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP ||
3726 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GFX ||
3727 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_MES))
3730 /* SDMA 5.x+ is part of GFX power domain so it's covered by GFXOFF */
3731 if (adev->in_s0ix &&
3732 (amdgpu_ip_version(adev, SDMA0_HWIP, 0) >=
3733 IP_VERSION(5, 0, 0)) &&
3734 (adev->ip_blocks[i].version->type ==
3735 AMD_IP_BLOCK_TYPE_SDMA))
3738 /* Once swPSP provides the IMU, RLC FW binaries to TOS during cold-boot.
3739 * These are in TMR, hence are expected to be reused by PSP-TOS to reload
3740 * from this location and RLC Autoload automatically also gets loaded
3741 * from here based on PMFW -> PSP message during re-init sequence.
3742 * Therefore, the psp suspend & resume should be skipped to avoid destroy
3743 * the TMR and reload FWs again for IMU enabled APU ASICs.
3745 if (amdgpu_in_reset(adev) &&
3746 (adev->flags & AMD_IS_APU) && adev->gfx.imu.funcs &&
3747 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP)
3750 /* XXX handle errors */
3751 r = amdgpu_ip_block_suspend(&adev->ip_blocks[i]);
3752 adev->ip_blocks[i].status.hw = false;
3754 /* handle putting the SMC in the appropriate state */
3755 if (!amdgpu_sriov_vf(adev)) {
3756 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) {
3757 r = amdgpu_dpm_set_mp1_state(adev, adev->mp1_state);
3759 DRM_ERROR("SMC failed to set mp1 state %d, %d\n",
3760 adev->mp1_state, r);
3771 * amdgpu_device_ip_suspend - run suspend for hardware IPs
3773 * @adev: amdgpu_device pointer
3775 * Main suspend function for hardware IPs. The list of all the hardware
3776 * IPs that make up the asic is walked, clockgating is disabled and the
3777 * suspend callbacks are run. suspend puts the hardware and software state
3778 * in each IP into a state suitable for suspend.
3779 * Returns 0 on success, negative error code on failure.
3781 int amdgpu_device_ip_suspend(struct amdgpu_device *adev)
3785 if (amdgpu_sriov_vf(adev)) {
3786 amdgpu_virt_fini_data_exchange(adev);
3787 amdgpu_virt_request_full_gpu(adev, false);
3790 amdgpu_ttm_set_buffer_funcs_status(adev, false);
3792 r = amdgpu_device_ip_suspend_phase1(adev);
3795 r = amdgpu_device_ip_suspend_phase2(adev);
3797 if (amdgpu_sriov_vf(adev))
3798 amdgpu_virt_release_full_gpu(adev, false);
3803 static int amdgpu_device_ip_reinit_early_sriov(struct amdgpu_device *adev)
3807 static enum amd_ip_block_type ip_order[] = {
3808 AMD_IP_BLOCK_TYPE_COMMON,
3809 AMD_IP_BLOCK_TYPE_GMC,
3810 AMD_IP_BLOCK_TYPE_PSP,
3811 AMD_IP_BLOCK_TYPE_IH,
3814 for (i = 0; i < adev->num_ip_blocks; i++) {
3816 struct amdgpu_ip_block *block;
3818 block = &adev->ip_blocks[i];
3819 block->status.hw = false;
3821 for (j = 0; j < ARRAY_SIZE(ip_order); j++) {
3823 if (block->version->type != ip_order[j] ||
3824 !block->status.valid)
3827 r = block->version->funcs->hw_init(&adev->ip_blocks[i]);
3829 dev_err(adev->dev, "RE-INIT-early: %s failed\n",
3830 block->version->funcs->name);
3833 block->status.hw = true;
3840 static int amdgpu_device_ip_reinit_late_sriov(struct amdgpu_device *adev)
3842 struct amdgpu_ip_block *block;
3845 static enum amd_ip_block_type ip_order[] = {
3846 AMD_IP_BLOCK_TYPE_SMC,
3847 AMD_IP_BLOCK_TYPE_DCE,
3848 AMD_IP_BLOCK_TYPE_GFX,
3849 AMD_IP_BLOCK_TYPE_SDMA,
3850 AMD_IP_BLOCK_TYPE_MES,
3851 AMD_IP_BLOCK_TYPE_UVD,
3852 AMD_IP_BLOCK_TYPE_VCE,
3853 AMD_IP_BLOCK_TYPE_VCN,
3854 AMD_IP_BLOCK_TYPE_JPEG
3857 for (i = 0; i < ARRAY_SIZE(ip_order); i++) {
3858 block = amdgpu_device_ip_get_ip_block(adev, ip_order[i]);
3863 if (block->status.valid && !block->status.hw) {
3864 if (block->version->type == AMD_IP_BLOCK_TYPE_SMC) {
3865 r = amdgpu_ip_block_resume(block);
3867 r = block->version->funcs->hw_init(block);
3871 dev_err(adev->dev, "RE-INIT-late: %s failed\n",
3872 block->version->funcs->name);
3875 block->status.hw = true;
3883 * amdgpu_device_ip_resume_phase1 - run resume for hardware IPs
3885 * @adev: amdgpu_device pointer
3887 * First resume function for hardware IPs. The list of all the hardware
3888 * IPs that make up the asic is walked and the resume callbacks are run for
3889 * COMMON, GMC, and IH. resume puts the hardware into a functional state
3890 * after a suspend and updates the software state as necessary. This
3891 * function is also used for restoring the GPU after a GPU reset.
3892 * Returns 0 on success, negative error code on failure.
3894 static int amdgpu_device_ip_resume_phase1(struct amdgpu_device *adev)
3898 for (i = 0; i < adev->num_ip_blocks; i++) {
3899 if (!adev->ip_blocks[i].status.valid || adev->ip_blocks[i].status.hw)
3901 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
3902 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
3903 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH ||
3904 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP && amdgpu_sriov_vf(adev))) {
3906 r = amdgpu_ip_block_resume(&adev->ip_blocks[i]);
3916 * amdgpu_device_ip_resume_phase2 - run resume for hardware IPs
3918 * @adev: amdgpu_device pointer
3920 * Second resume function for hardware IPs. The list of all the hardware
3921 * IPs that make up the asic is walked and the resume callbacks are run for
3922 * all blocks except COMMON, GMC, and IH. resume puts the hardware into a
3923 * functional state after a suspend and updates the software state as
3924 * necessary. This function is also used for restoring the GPU after a GPU
3926 * Returns 0 on success, negative error code on failure.
3928 static int amdgpu_device_ip_resume_phase2(struct amdgpu_device *adev)
3932 for (i = 0; i < adev->num_ip_blocks; i++) {
3933 if (!adev->ip_blocks[i].status.valid || adev->ip_blocks[i].status.hw)
3935 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
3936 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
3937 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH ||
3938 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE ||
3939 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP)
3941 r = amdgpu_ip_block_resume(&adev->ip_blocks[i]);
3950 * amdgpu_device_ip_resume_phase3 - run resume for hardware IPs
3952 * @adev: amdgpu_device pointer
3954 * Third resume function for hardware IPs. The list of all the hardware
3955 * IPs that make up the asic is walked and the resume callbacks are run for
3956 * all DCE. resume puts the hardware into a functional state after a suspend
3957 * and updates the software state as necessary. This function is also used
3958 * for restoring the GPU after a GPU reset.
3960 * Returns 0 on success, negative error code on failure.
3962 static int amdgpu_device_ip_resume_phase3(struct amdgpu_device *adev)
3966 for (i = 0; i < adev->num_ip_blocks; i++) {
3967 if (!adev->ip_blocks[i].status.valid || adev->ip_blocks[i].status.hw)
3969 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE) {
3970 r = amdgpu_ip_block_resume(&adev->ip_blocks[i]);
3980 * amdgpu_device_ip_resume - run resume for hardware IPs
3982 * @adev: amdgpu_device pointer
3984 * Main resume function for hardware IPs. The hardware IPs
3985 * are split into two resume functions because they are
3986 * also used in recovering from a GPU reset and some additional
3987 * steps need to be take between them. In this case (S3/S4) they are
3989 * Returns 0 on success, negative error code on failure.
3991 static int amdgpu_device_ip_resume(struct amdgpu_device *adev)
3995 r = amdgpu_device_ip_resume_phase1(adev);
3999 r = amdgpu_device_fw_loading(adev);
4003 r = amdgpu_device_ip_resume_phase2(adev);
4005 if (adev->mman.buffer_funcs_ring->sched.ready)
4006 amdgpu_ttm_set_buffer_funcs_status(adev, true);
4011 amdgpu_fence_driver_hw_init(adev);
4013 r = amdgpu_device_ip_resume_phase3(adev);
4019 * amdgpu_device_detect_sriov_bios - determine if the board supports SR-IOV
4021 * @adev: amdgpu_device pointer
4023 * Query the VBIOS data tables to determine if the board supports SR-IOV.
4025 static void amdgpu_device_detect_sriov_bios(struct amdgpu_device *adev)
4027 if (amdgpu_sriov_vf(adev)) {
4028 if (adev->is_atom_fw) {
4029 if (amdgpu_atomfirmware_gpu_virtualization_supported(adev))
4030 adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
4032 if (amdgpu_atombios_has_gpu_virtualization_table(adev))
4033 adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
4036 if (!(adev->virt.caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS))
4037 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_NO_VBIOS, 0, 0);
4042 * amdgpu_device_asic_has_dc_support - determine if DC supports the asic
4044 * @asic_type: AMD asic type
4046 * Check if there is DC (new modesetting infrastructre) support for an asic.
4047 * returns true if DC has support, false if not.
4049 bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type)
4051 switch (asic_type) {
4052 #ifdef CONFIG_DRM_AMDGPU_SI
4056 /* chips with no display hardware */
4058 #if defined(CONFIG_DRM_AMD_DC)
4064 * We have systems in the wild with these ASICs that require
4065 * LVDS and VGA support which is not supported with DC.
4067 * Fallback to the non-DC driver here by default so as not to
4068 * cause regressions.
4070 #if defined(CONFIG_DRM_AMD_DC_SI)
4071 return amdgpu_dc > 0;
4080 * We have systems in the wild with these ASICs that require
4081 * VGA support which is not supported with DC.
4083 * Fallback to the non-DC driver here by default so as not to
4084 * cause regressions.
4086 return amdgpu_dc > 0;
4088 return amdgpu_dc != 0;
4092 DRM_INFO_ONCE("Display Core has been requested via kernel parameter but isn't supported by ASIC, ignoring\n");
4099 * amdgpu_device_has_dc_support - check if dc is supported
4101 * @adev: amdgpu_device pointer
4103 * Returns true for supported, false for not supported
4105 bool amdgpu_device_has_dc_support(struct amdgpu_device *adev)
4107 if (adev->enable_virtual_display ||
4108 (adev->harvest_ip_mask & AMD_HARVEST_IP_DMU_MASK))
4111 return amdgpu_device_asic_has_dc_support(adev->asic_type);
4114 static void amdgpu_device_xgmi_reset_func(struct work_struct *__work)
4116 struct amdgpu_device *adev =
4117 container_of(__work, struct amdgpu_device, xgmi_reset_work);
4118 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
4120 /* It's a bug to not have a hive within this function */
4125 * Use task barrier to synchronize all xgmi reset works across the
4126 * hive. task_barrier_enter and task_barrier_exit will block
4127 * until all the threads running the xgmi reset works reach
4128 * those points. task_barrier_full will do both blocks.
4130 if (amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
4132 task_barrier_enter(&hive->tb);
4133 adev->asic_reset_res = amdgpu_device_baco_enter(adev_to_drm(adev));
4135 if (adev->asic_reset_res)
4138 task_barrier_exit(&hive->tb);
4139 adev->asic_reset_res = amdgpu_device_baco_exit(adev_to_drm(adev));
4141 if (adev->asic_reset_res)
4144 amdgpu_ras_reset_error_count(adev, AMDGPU_RAS_BLOCK__MMHUB);
4147 task_barrier_full(&hive->tb);
4148 adev->asic_reset_res = amdgpu_asic_reset(adev);
4152 if (adev->asic_reset_res)
4153 DRM_WARN("ASIC reset failed with error, %d for drm dev, %s",
4154 adev->asic_reset_res, adev_to_drm(adev)->unique);
4155 amdgpu_put_xgmi_hive(hive);
4158 static int amdgpu_device_get_job_timeout_settings(struct amdgpu_device *adev)
4160 char *input = amdgpu_lockup_timeout;
4161 char *timeout_setting = NULL;
4167 * By default timeout for non compute jobs is 10000
4168 * and 60000 for compute jobs.
4169 * In SR-IOV or passthrough mode, timeout for compute
4170 * jobs are 60000 by default.
4172 adev->gfx_timeout = msecs_to_jiffies(10000);
4173 adev->sdma_timeout = adev->video_timeout = adev->gfx_timeout;
4174 if (amdgpu_sriov_vf(adev))
4175 adev->compute_timeout = amdgpu_sriov_is_pp_one_vf(adev) ?
4176 msecs_to_jiffies(60000) : msecs_to_jiffies(10000);
4178 adev->compute_timeout = msecs_to_jiffies(60000);
4180 if (strnlen(input, AMDGPU_MAX_TIMEOUT_PARAM_LENGTH)) {
4181 while ((timeout_setting = strsep(&input, ",")) &&
4182 strnlen(timeout_setting, AMDGPU_MAX_TIMEOUT_PARAM_LENGTH)) {
4183 ret = kstrtol(timeout_setting, 0, &timeout);
4190 } else if (timeout < 0) {
4191 timeout = MAX_SCHEDULE_TIMEOUT;
4192 dev_warn(adev->dev, "lockup timeout disabled");
4193 add_taint(TAINT_SOFTLOCKUP, LOCKDEP_STILL_OK);
4195 timeout = msecs_to_jiffies(timeout);
4200 adev->gfx_timeout = timeout;
4203 adev->compute_timeout = timeout;
4206 adev->sdma_timeout = timeout;
4209 adev->video_timeout = timeout;
4216 * There is only one value specified and
4217 * it should apply to all non-compute jobs.
4220 adev->sdma_timeout = adev->video_timeout = adev->gfx_timeout;
4221 if (amdgpu_sriov_vf(adev) || amdgpu_passthrough(adev))
4222 adev->compute_timeout = adev->gfx_timeout;
4230 * amdgpu_device_check_iommu_direct_map - check if RAM direct mapped to GPU
4232 * @adev: amdgpu_device pointer
4234 * RAM direct mapped to GPU if IOMMU is not enabled or is pass through mode
4236 static void amdgpu_device_check_iommu_direct_map(struct amdgpu_device *adev)
4238 struct iommu_domain *domain;
4240 domain = iommu_get_domain_for_dev(adev->dev);
4241 if (!domain || domain->type == IOMMU_DOMAIN_IDENTITY)
4242 adev->ram_is_direct_mapped = true;
4245 #if defined(CONFIG_HSA_AMD_P2P)
4247 * amdgpu_device_check_iommu_remap - Check if DMA remapping is enabled.
4249 * @adev: amdgpu_device pointer
4251 * return if IOMMU remapping bar address
4253 static bool amdgpu_device_check_iommu_remap(struct amdgpu_device *adev)
4255 struct iommu_domain *domain;
4257 domain = iommu_get_domain_for_dev(adev->dev);
4258 if (domain && (domain->type == IOMMU_DOMAIN_DMA ||
4259 domain->type == IOMMU_DOMAIN_DMA_FQ))
4266 static void amdgpu_device_set_mcbp(struct amdgpu_device *adev)
4268 if (amdgpu_mcbp == 1)
4269 adev->gfx.mcbp = true;
4270 else if (amdgpu_mcbp == 0)
4271 adev->gfx.mcbp = false;
4273 if (amdgpu_sriov_vf(adev))
4274 adev->gfx.mcbp = true;
4277 DRM_INFO("MCBP is enabled\n");
4281 * amdgpu_device_init - initialize the driver
4283 * @adev: amdgpu_device pointer
4284 * @flags: driver flags
4286 * Initializes the driver info and hw (all asics).
4287 * Returns 0 for success or an error on failure.
4288 * Called at driver startup.
4290 int amdgpu_device_init(struct amdgpu_device *adev,
4293 struct drm_device *ddev = adev_to_drm(adev);
4294 struct pci_dev *pdev = adev->pdev;
4300 adev->shutdown = false;
4301 adev->flags = flags;
4303 if (amdgpu_force_asic_type >= 0 && amdgpu_force_asic_type < CHIP_LAST)
4304 adev->asic_type = amdgpu_force_asic_type;
4306 adev->asic_type = flags & AMD_ASIC_MASK;
4308 adev->usec_timeout = AMDGPU_MAX_USEC_TIMEOUT;
4309 if (amdgpu_emu_mode == 1)
4310 adev->usec_timeout *= 10;
4311 adev->gmc.gart_size = 512 * 1024 * 1024;
4312 adev->accel_working = false;
4313 adev->num_rings = 0;
4314 RCU_INIT_POINTER(adev->gang_submit, dma_fence_get_stub());
4315 adev->mman.buffer_funcs = NULL;
4316 adev->mman.buffer_funcs_ring = NULL;
4317 adev->vm_manager.vm_pte_funcs = NULL;
4318 adev->vm_manager.vm_pte_num_scheds = 0;
4319 adev->gmc.gmc_funcs = NULL;
4320 adev->harvest_ip_mask = 0x0;
4321 adev->fence_context = dma_fence_context_alloc(AMDGPU_MAX_RINGS);
4322 bitmap_zero(adev->gfx.pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
4324 adev->smc_rreg = &amdgpu_invalid_rreg;
4325 adev->smc_wreg = &amdgpu_invalid_wreg;
4326 adev->pcie_rreg = &amdgpu_invalid_rreg;
4327 adev->pcie_wreg = &amdgpu_invalid_wreg;
4328 adev->pcie_rreg_ext = &amdgpu_invalid_rreg_ext;
4329 adev->pcie_wreg_ext = &amdgpu_invalid_wreg_ext;
4330 adev->pciep_rreg = &amdgpu_invalid_rreg;
4331 adev->pciep_wreg = &amdgpu_invalid_wreg;
4332 adev->pcie_rreg64 = &amdgpu_invalid_rreg64;
4333 adev->pcie_wreg64 = &amdgpu_invalid_wreg64;
4334 adev->pcie_rreg64_ext = &amdgpu_invalid_rreg64_ext;
4335 adev->pcie_wreg64_ext = &amdgpu_invalid_wreg64_ext;
4336 adev->uvd_ctx_rreg = &amdgpu_invalid_rreg;
4337 adev->uvd_ctx_wreg = &amdgpu_invalid_wreg;
4338 adev->didt_rreg = &amdgpu_invalid_rreg;
4339 adev->didt_wreg = &amdgpu_invalid_wreg;
4340 adev->gc_cac_rreg = &amdgpu_invalid_rreg;
4341 adev->gc_cac_wreg = &amdgpu_invalid_wreg;
4342 adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg;
4343 adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg;
4345 DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n",
4346 amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device,
4347 pdev->subsystem_vendor, pdev->subsystem_device, pdev->revision);
4349 /* mutex initialization are all done here so we
4350 * can recall function without having locking issues
4352 mutex_init(&adev->firmware.mutex);
4353 mutex_init(&adev->pm.mutex);
4354 mutex_init(&adev->gfx.gpu_clock_mutex);
4355 mutex_init(&adev->srbm_mutex);
4356 mutex_init(&adev->gfx.pipe_reserve_mutex);
4357 mutex_init(&adev->gfx.gfx_off_mutex);
4358 mutex_init(&adev->gfx.partition_mutex);
4359 mutex_init(&adev->grbm_idx_mutex);
4360 mutex_init(&adev->mn_lock);
4361 mutex_init(&adev->virt.vf_errors.lock);
4362 hash_init(adev->mn_hash);
4363 mutex_init(&adev->psp.mutex);
4364 mutex_init(&adev->notifier_lock);
4365 mutex_init(&adev->pm.stable_pstate_ctx_lock);
4366 mutex_init(&adev->benchmark_mutex);
4367 mutex_init(&adev->gfx.reset_sem_mutex);
4368 /* Initialize the mutex for cleaner shader isolation between GFX and compute processes */
4369 mutex_init(&adev->enforce_isolation_mutex);
4370 for (i = 0; i < MAX_XCP; ++i) {
4371 adev->isolation[i].spearhead = dma_fence_get_stub();
4372 amdgpu_sync_create(&adev->isolation[i].active);
4373 amdgpu_sync_create(&adev->isolation[i].prev);
4375 mutex_init(&adev->gfx.userq_sch_mutex);
4376 mutex_init(&adev->gfx.workload_profile_mutex);
4377 mutex_init(&adev->vcn.workload_profile_mutex);
4378 mutex_init(&adev->userq_mutex);
4380 amdgpu_device_init_apu_flags(adev);
4382 r = amdgpu_device_check_arguments(adev);
4386 spin_lock_init(&adev->mmio_idx_lock);
4387 spin_lock_init(&adev->smc_idx_lock);
4388 spin_lock_init(&adev->pcie_idx_lock);
4389 spin_lock_init(&adev->uvd_ctx_idx_lock);
4390 spin_lock_init(&adev->didt_idx_lock);
4391 spin_lock_init(&adev->gc_cac_idx_lock);
4392 spin_lock_init(&adev->se_cac_idx_lock);
4393 spin_lock_init(&adev->audio_endpt_idx_lock);
4394 spin_lock_init(&adev->mm_stats.lock);
4395 spin_lock_init(&adev->virt.rlcg_reg_lock);
4396 spin_lock_init(&adev->wb.lock);
4398 xa_init_flags(&adev->userq_xa, XA_FLAGS_LOCK_IRQ);
4400 INIT_LIST_HEAD(&adev->reset_list);
4402 INIT_LIST_HEAD(&adev->ras_list);
4404 INIT_LIST_HEAD(&adev->pm.od_kobj_list);
4406 INIT_LIST_HEAD(&adev->userq_mgr_list);
4408 INIT_DELAYED_WORK(&adev->delayed_init_work,
4409 amdgpu_device_delayed_init_work_handler);
4410 INIT_DELAYED_WORK(&adev->gfx.gfx_off_delay_work,
4411 amdgpu_device_delay_enable_gfx_off);
4413 * Initialize the enforce_isolation work structures for each XCP
4414 * partition. This work handler is responsible for enforcing shader
4415 * isolation on AMD GPUs. It counts the number of emitted fences for
4416 * each GFX and compute ring. If there are any fences, it schedules
4417 * the `enforce_isolation_work` to be run after a delay. If there are
4418 * no fences, it signals the Kernel Fusion Driver (KFD) to resume the
4421 for (i = 0; i < MAX_XCP; i++) {
4422 INIT_DELAYED_WORK(&adev->gfx.enforce_isolation[i].work,
4423 amdgpu_gfx_enforce_isolation_handler);
4424 adev->gfx.enforce_isolation[i].adev = adev;
4425 adev->gfx.enforce_isolation[i].xcp_id = i;
4428 INIT_WORK(&adev->xgmi_reset_work, amdgpu_device_xgmi_reset_func);
4430 adev->gfx.gfx_off_req_count = 1;
4431 adev->gfx.gfx_off_residency = 0;
4432 adev->gfx.gfx_off_entrycount = 0;
4433 adev->pm.ac_power = power_supply_is_system_supplied() > 0;
4435 atomic_set(&adev->throttling_logging_enabled, 1);
4437 * If throttling continues, logging will be performed every minute
4438 * to avoid log flooding. "-1" is subtracted since the thermal
4439 * throttling interrupt comes every second. Thus, the total logging
4440 * interval is 59 seconds(retelimited printk interval) + 1(waiting
4441 * for throttling interrupt) = 60 seconds.
4443 ratelimit_state_init(&adev->throttling_logging_rs, (60 - 1) * HZ, 1);
4445 ratelimit_set_flags(&adev->throttling_logging_rs, RATELIMIT_MSG_ON_RELEASE);
4447 /* Registers mapping */
4448 /* TODO: block userspace mapping of io register */
4449 if (adev->asic_type >= CHIP_BONAIRE) {
4450 adev->rmmio_base = pci_resource_start(adev->pdev, 5);
4451 adev->rmmio_size = pci_resource_len(adev->pdev, 5);
4453 adev->rmmio_base = pci_resource_start(adev->pdev, 2);
4454 adev->rmmio_size = pci_resource_len(adev->pdev, 2);
4457 for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
4458 atomic_set(&adev->pm.pwr_state[i], POWER_STATE_UNKNOWN);
4460 adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
4464 DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
4465 DRM_INFO("register mmio size: %u\n", (unsigned int)adev->rmmio_size);
4468 * Reset domain needs to be present early, before XGMI hive discovered
4469 * (if any) and initialized to use reset sem and in_gpu reset flag
4470 * early on during init and before calling to RREG32.
4472 adev->reset_domain = amdgpu_reset_create_reset_domain(SINGLE_DEVICE, "amdgpu-reset-dev");
4473 if (!adev->reset_domain)
4476 /* detect hw virtualization here */
4477 amdgpu_virt_init(adev);
4479 amdgpu_device_get_pcie_info(adev);
4481 r = amdgpu_device_get_job_timeout_settings(adev);
4483 dev_err(adev->dev, "invalid lockup_timeout parameter syntax\n");
4487 amdgpu_device_set_mcbp(adev);
4490 * By default, use default mode where all blocks are expected to be
4491 * initialized. At present a 'swinit' of blocks is required to be
4492 * completed before the need for a different level is detected.
4494 amdgpu_set_init_level(adev, AMDGPU_INIT_LEVEL_DEFAULT);
4495 /* early init functions */
4496 r = amdgpu_device_ip_early_init(adev);
4501 * No need to remove conflicting FBs for non-display class devices.
4502 * This prevents the sysfb from being freed accidently.
4504 if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA ||
4505 (pdev->class >> 8) == PCI_CLASS_DISPLAY_OTHER) {
4506 /* Get rid of things like offb */
4507 r = aperture_remove_conflicting_pci_devices(adev->pdev, amdgpu_kms_driver.name);
4512 /* Enable TMZ based on IP_VERSION */
4513 amdgpu_gmc_tmz_set(adev);
4515 if (amdgpu_sriov_vf(adev) &&
4516 amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(10, 3, 0))
4517 /* VF MMIO access (except mailbox range) from CPU
4518 * will be blocked during sriov runtime
4520 adev->virt.caps |= AMDGPU_VF_MMIO_ACCESS_PROTECT;
4522 amdgpu_gmc_noretry_set(adev);
4523 /* Need to get xgmi info early to decide the reset behavior*/
4524 if (adev->gmc.xgmi.supported) {
4525 r = adev->gfxhub.funcs->get_xgmi_info(adev);
4530 /* enable PCIE atomic ops */
4531 if (amdgpu_sriov_vf(adev)) {
4532 if (adev->virt.fw_reserve.p_pf2vf)
4533 adev->have_atomics_support = ((struct amd_sriov_msg_pf2vf_info *)
4534 adev->virt.fw_reserve.p_pf2vf)->pcie_atomic_ops_support_flags ==
4535 (PCI_EXP_DEVCAP2_ATOMIC_COMP32 | PCI_EXP_DEVCAP2_ATOMIC_COMP64);
4536 /* APUs w/ gfx9 onwards doesn't reply on PCIe atomics, rather it is a
4537 * internal path natively support atomics, set have_atomics_support to true.
4539 } else if ((adev->flags & AMD_IS_APU) &&
4540 (amdgpu_ip_version(adev, GC_HWIP, 0) >
4541 IP_VERSION(9, 0, 0))) {
4542 adev->have_atomics_support = true;
4544 adev->have_atomics_support =
4545 !pci_enable_atomic_ops_to_root(adev->pdev,
4546 PCI_EXP_DEVCAP2_ATOMIC_COMP32 |
4547 PCI_EXP_DEVCAP2_ATOMIC_COMP64);
4550 if (!adev->have_atomics_support)
4551 dev_info(adev->dev, "PCIE atomic ops is not supported\n");
4553 /* doorbell bar mapping and doorbell index init*/
4554 amdgpu_doorbell_init(adev);
4556 if (amdgpu_emu_mode == 1) {
4557 /* post the asic on emulation mode */
4558 emu_soc_asic_init(adev);
4559 goto fence_driver_init;
4562 amdgpu_reset_init(adev);
4564 /* detect if we are with an SRIOV vbios */
4566 amdgpu_device_detect_sriov_bios(adev);
4568 /* check if we need to reset the asic
4569 * E.g., driver was not cleanly unloaded previously, etc.
4571 if (!amdgpu_sriov_vf(adev) && amdgpu_asic_need_reset_on_init(adev)) {
4572 if (adev->gmc.xgmi.num_physical_nodes) {
4573 dev_info(adev->dev, "Pending hive reset.\n");
4574 amdgpu_set_init_level(adev,
4575 AMDGPU_INIT_LEVEL_MINIMAL_XGMI);
4576 } else if (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(13, 0, 10) &&
4577 !amdgpu_device_has_display_hardware(adev)) {
4578 r = psp_gpu_reset(adev);
4580 tmp = amdgpu_reset_method;
4581 /* It should do a default reset when loading or reloading the driver,
4582 * regardless of the module parameter reset_method.
4584 amdgpu_reset_method = AMD_RESET_METHOD_NONE;
4585 r = amdgpu_asic_reset(adev);
4586 amdgpu_reset_method = tmp;
4590 dev_err(adev->dev, "asic reset on init failed\n");
4595 /* Post card if necessary */
4596 if (amdgpu_device_need_post(adev)) {
4598 dev_err(adev->dev, "no vBIOS found\n");
4602 DRM_INFO("GPU posting now...\n");
4603 r = amdgpu_device_asic_init(adev);
4605 dev_err(adev->dev, "gpu post error!\n");
4611 if (adev->is_atom_fw) {
4612 /* Initialize clocks */
4613 r = amdgpu_atomfirmware_get_clock_info(adev);
4615 dev_err(adev->dev, "amdgpu_atomfirmware_get_clock_info failed\n");
4616 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
4620 /* Initialize clocks */
4621 r = amdgpu_atombios_get_clock_info(adev);
4623 dev_err(adev->dev, "amdgpu_atombios_get_clock_info failed\n");
4624 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
4627 /* init i2c buses */
4628 amdgpu_i2c_init(adev);
4634 r = amdgpu_fence_driver_sw_init(adev);
4636 dev_err(adev->dev, "amdgpu_fence_driver_sw_init failed\n");
4637 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_FENCE_INIT_FAIL, 0, 0);
4641 /* init the mode config */
4642 drm_mode_config_init(adev_to_drm(adev));
4644 r = amdgpu_device_ip_init(adev);
4646 dev_err(adev->dev, "amdgpu_device_ip_init failed\n");
4647 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_INIT_FAIL, 0, 0);
4648 goto release_ras_con;
4651 amdgpu_fence_driver_hw_init(adev);
4654 "SE %d, SH per SE %d, CU per SH %d, active_cu_number %d\n",
4655 adev->gfx.config.max_shader_engines,
4656 adev->gfx.config.max_sh_per_se,
4657 adev->gfx.config.max_cu_per_sh,
4658 adev->gfx.cu_info.number);
4660 adev->accel_working = true;
4662 amdgpu_vm_check_compute_bug(adev);
4664 /* Initialize the buffer migration limit. */
4665 if (amdgpu_moverate >= 0)
4666 max_MBps = amdgpu_moverate;
4668 max_MBps = 8; /* Allow 8 MB/s. */
4669 /* Get a log2 for easy divisions. */
4670 adev->mm_stats.log2_max_MBps = ilog2(max(1u, max_MBps));
4673 * Register gpu instance before amdgpu_device_enable_mgpu_fan_boost.
4674 * Otherwise the mgpu fan boost feature will be skipped due to the
4675 * gpu instance is counted less.
4677 amdgpu_register_gpu_instance(adev);
4679 /* enable clockgating, etc. after ib tests, etc. since some blocks require
4680 * explicit gating rather than handling it automatically.
4682 if (adev->init_lvl->level != AMDGPU_INIT_LEVEL_MINIMAL_XGMI) {
4683 r = amdgpu_device_ip_late_init(adev);
4685 dev_err(adev->dev, "amdgpu_device_ip_late_init failed\n");
4686 amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_LATE_INIT_FAIL, 0, r);
4687 goto release_ras_con;
4690 amdgpu_ras_resume(adev);
4691 queue_delayed_work(system_wq, &adev->delayed_init_work,
4692 msecs_to_jiffies(AMDGPU_RESUME_MS));
4695 if (amdgpu_sriov_vf(adev)) {
4696 amdgpu_virt_release_full_gpu(adev, true);
4697 flush_delayed_work(&adev->delayed_init_work);
4701 * Place those sysfs registering after `late_init`. As some of those
4702 * operations performed in `late_init` might affect the sysfs
4703 * interfaces creating.
4705 r = amdgpu_atombios_sysfs_init(adev);
4707 drm_err(&adev->ddev,
4708 "registering atombios sysfs failed (%d).\n", r);
4710 r = amdgpu_pm_sysfs_init(adev);
4712 DRM_ERROR("registering pm sysfs failed (%d).\n", r);
4714 r = amdgpu_ucode_sysfs_init(adev);
4716 adev->ucode_sysfs_en = false;
4717 DRM_ERROR("Creating firmware sysfs failed (%d).\n", r);
4719 adev->ucode_sysfs_en = true;
4721 r = amdgpu_device_attr_sysfs_init(adev);
4723 dev_err(adev->dev, "Could not create amdgpu device attr\n");
4725 r = devm_device_add_group(adev->dev, &amdgpu_board_attrs_group);
4728 "Could not create amdgpu board attributes\n");
4730 amdgpu_fru_sysfs_init(adev);
4731 amdgpu_reg_state_sysfs_init(adev);
4732 amdgpu_xcp_sysfs_init(adev);
4734 if (IS_ENABLED(CONFIG_PERF_EVENTS))
4735 r = amdgpu_pmu_init(adev);
4737 dev_err(adev->dev, "amdgpu_pmu_init failed\n");
4739 /* Have stored pci confspace at hand for restore in sudden PCI error */
4740 if (amdgpu_device_cache_pci_state(adev->pdev))
4741 pci_restore_state(pdev);
4743 /* if we have > 1 VGA cards, then disable the amdgpu VGA resources */
4744 /* this will fail for cards that aren't VGA class devices, just
4747 if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
4748 vga_client_register(adev->pdev, amdgpu_device_vga_set_decode);
4750 px = amdgpu_device_supports_px(ddev);
4752 if (px || (!dev_is_removable(&adev->pdev->dev) &&
4753 apple_gmux_detect(NULL, NULL)))
4754 vga_switcheroo_register_client(adev->pdev,
4755 &amdgpu_switcheroo_ops, px);
4758 vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain);
4760 if (adev->init_lvl->level == AMDGPU_INIT_LEVEL_MINIMAL_XGMI)
4761 amdgpu_xgmi_reset_on_init(adev);
4763 amdgpu_device_check_iommu_direct_map(adev);
4765 adev->pm_nb.notifier_call = amdgpu_device_pm_notifier;
4766 r = register_pm_notifier(&adev->pm_nb);
4773 if (amdgpu_sriov_vf(adev))
4774 amdgpu_virt_release_full_gpu(adev, true);
4776 /* failed in exclusive mode due to timeout */
4777 if (amdgpu_sriov_vf(adev) &&
4778 !amdgpu_sriov_runtime(adev) &&
4779 amdgpu_virt_mmio_blocked(adev) &&
4780 !amdgpu_virt_wait_reset(adev)) {
4781 dev_err(adev->dev, "VF exclusive mode timeout\n");
4782 /* Don't send request since VF is inactive. */
4783 adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
4784 adev->virt.ops = NULL;
4787 amdgpu_release_ras_context(adev);
4790 amdgpu_vf_error_trans_all(adev);
4795 static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)
4798 /* Clear all CPU mappings pointing to this device */
4799 unmap_mapping_range(adev->ddev.anon_inode->i_mapping, 0, 0, 1);
4801 /* Unmap all mapped bars - Doorbell, registers and VRAM */
4802 amdgpu_doorbell_fini(adev);
4804 iounmap(adev->rmmio);
4806 if (adev->mman.aper_base_kaddr)
4807 iounmap(adev->mman.aper_base_kaddr);
4808 adev->mman.aper_base_kaddr = NULL;
4810 /* Memory manager related */
4811 if (!adev->gmc.xgmi.connected_to_cpu && !adev->gmc.is_app_apu) {
4812 arch_phys_wc_del(adev->gmc.vram_mtrr);
4813 arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);
4818 * amdgpu_device_fini_hw - tear down the driver
4820 * @adev: amdgpu_device pointer
4822 * Tear down the driver info (all asics).
4823 * Called at driver shutdown.
4825 void amdgpu_device_fini_hw(struct amdgpu_device *adev)
4827 dev_info(adev->dev, "amdgpu: finishing device.\n");
4828 flush_delayed_work(&adev->delayed_init_work);
4830 if (adev->mman.initialized)
4831 drain_workqueue(adev->mman.bdev.wq);
4832 adev->shutdown = true;
4834 unregister_pm_notifier(&adev->pm_nb);
4836 /* make sure IB test finished before entering exclusive mode
4837 * to avoid preemption on IB test
4839 if (amdgpu_sriov_vf(adev)) {
4840 amdgpu_virt_request_full_gpu(adev, false);
4841 amdgpu_virt_fini_data_exchange(adev);
4844 /* disable all interrupts */
4845 amdgpu_irq_disable_all(adev);
4846 if (adev->mode_info.mode_config_initialized) {
4847 if (!drm_drv_uses_atomic_modeset(adev_to_drm(adev)))
4848 drm_helper_force_disable_all(adev_to_drm(adev));
4850 drm_atomic_helper_shutdown(adev_to_drm(adev));
4852 amdgpu_fence_driver_hw_fini(adev);
4854 if (adev->pm.sysfs_initialized)
4855 amdgpu_pm_sysfs_fini(adev);
4856 if (adev->ucode_sysfs_en)
4857 amdgpu_ucode_sysfs_fini(adev);
4858 amdgpu_device_attr_sysfs_fini(adev);
4859 amdgpu_fru_sysfs_fini(adev);
4861 amdgpu_reg_state_sysfs_fini(adev);
4862 amdgpu_xcp_sysfs_fini(adev);
4864 /* disable ras feature must before hw fini */
4865 amdgpu_ras_pre_fini(adev);
4867 amdgpu_ttm_set_buffer_funcs_status(adev, false);
4869 amdgpu_device_ip_fini_early(adev);
4871 amdgpu_irq_fini_hw(adev);
4873 if (adev->mman.initialized)
4874 ttm_device_clear_dma_mappings(&adev->mman.bdev);
4876 amdgpu_gart_dummy_page_fini(adev);
4878 if (drm_dev_is_unplugged(adev_to_drm(adev)))
4879 amdgpu_device_unmap_mmio(adev);
4883 void amdgpu_device_fini_sw(struct amdgpu_device *adev)
4888 amdgpu_device_ip_fini(adev);
4889 amdgpu_fence_driver_sw_fini(adev);
4890 amdgpu_ucode_release(&adev->firmware.gpu_info_fw);
4891 adev->accel_working = false;
4892 dma_fence_put(rcu_dereference_protected(adev->gang_submit, true));
4893 for (i = 0; i < MAX_XCP; ++i) {
4894 dma_fence_put(adev->isolation[i].spearhead);
4895 amdgpu_sync_free(&adev->isolation[i].active);
4896 amdgpu_sync_free(&adev->isolation[i].prev);
4899 amdgpu_reset_fini(adev);
4901 /* free i2c buses */
4902 amdgpu_i2c_fini(adev);
4905 if (amdgpu_emu_mode != 1)
4906 amdgpu_atombios_fini(adev);
4907 amdgpu_bios_release(adev);
4910 kfree(adev->fru_info);
4911 adev->fru_info = NULL;
4913 kfree(adev->xcp_mgr);
4914 adev->xcp_mgr = NULL;
4916 px = amdgpu_device_supports_px(adev_to_drm(adev));
4918 if (px || (!dev_is_removable(&adev->pdev->dev) &&
4919 apple_gmux_detect(NULL, NULL)))
4920 vga_switcheroo_unregister_client(adev->pdev);
4923 vga_switcheroo_fini_domain_pm_ops(adev->dev);
4925 if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
4926 vga_client_unregister(adev->pdev);
4928 if (drm_dev_enter(adev_to_drm(adev), &idx)) {
4930 iounmap(adev->rmmio);
4935 if (IS_ENABLED(CONFIG_PERF_EVENTS))
4936 amdgpu_pmu_fini(adev);
4937 if (adev->mman.discovery_bin)
4938 amdgpu_discovery_fini(adev);
4940 amdgpu_reset_put_reset_domain(adev->reset_domain);
4941 adev->reset_domain = NULL;
4943 kfree(adev->pci_state);
4948 * amdgpu_device_evict_resources - evict device resources
4949 * @adev: amdgpu device object
4951 * Evicts all ttm device resources(vram BOs, gart table) from the lru list
4952 * of the vram memory type. Mainly used for evicting device resources
4956 static int amdgpu_device_evict_resources(struct amdgpu_device *adev)
4960 /* No need to evict vram on APUs unless going to S4 */
4961 if (!adev->in_s4 && (adev->flags & AMD_IS_APU))
4964 ret = amdgpu_ttm_evict_resources(adev, TTM_PL_VRAM);
4966 DRM_WARN("evicting device resources failed\n");
4974 * amdgpu_device_pm_notifier - Notification block for Suspend/Hibernate events
4975 * @nb: notifier block
4976 * @mode: suspend mode
4979 * This function is called when the system is about to suspend or hibernate.
4980 * It is used to set the appropriate flags so that eviction can be optimized
4981 * in the pm prepare callback.
4983 static int amdgpu_device_pm_notifier(struct notifier_block *nb, unsigned long mode,
4986 struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb);
4989 case PM_HIBERNATION_PREPARE:
4992 case PM_POST_HIBERNATION:
4993 adev->in_s4 = false;
5001 * amdgpu_device_prepare - prepare for device suspend
5003 * @dev: drm dev pointer
5005 * Prepare to put the hw in the suspend state (all asics).
5006 * Returns 0 for success or an error on failure.
5007 * Called at driver suspend.
5009 int amdgpu_device_prepare(struct drm_device *dev)
5011 struct amdgpu_device *adev = drm_to_adev(dev);
5014 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
5017 /* Evict the majority of BOs before starting suspend sequence */
5018 r = amdgpu_device_evict_resources(adev);
5022 flush_delayed_work(&adev->gfx.gfx_off_delay_work);
5024 for (i = 0; i < adev->num_ip_blocks; i++) {
5025 if (!adev->ip_blocks[i].status.valid)
5027 if (!adev->ip_blocks[i].version->funcs->prepare_suspend)
5029 r = adev->ip_blocks[i].version->funcs->prepare_suspend(&adev->ip_blocks[i]);
5038 * amdgpu_device_suspend - initiate device suspend
5040 * @dev: drm dev pointer
5041 * @notify_clients: notify in-kernel DRM clients
5043 * Puts the hw in the suspend state (all asics).
5044 * Returns 0 for success or an error on failure.
5045 * Called at driver suspend.
5047 int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)
5049 struct amdgpu_device *adev = drm_to_adev(dev);
5052 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
5055 adev->in_suspend = true;
5057 if (amdgpu_sriov_vf(adev)) {
5058 amdgpu_virt_fini_data_exchange(adev);
5059 r = amdgpu_virt_request_full_gpu(adev, false);
5064 if (amdgpu_acpi_smart_shift_update(dev, AMDGPU_SS_DEV_D3))
5065 DRM_WARN("smart shift update failed\n");
5068 drm_client_dev_suspend(adev_to_drm(adev), false);
5070 cancel_delayed_work_sync(&adev->delayed_init_work);
5072 amdgpu_ras_suspend(adev);
5074 amdgpu_device_ip_suspend_phase1(adev);
5076 if (!adev->in_s0ix) {
5077 amdgpu_amdkfd_suspend(adev, adev->in_runpm);
5078 amdgpu_userq_suspend(adev);
5081 r = amdgpu_device_evict_resources(adev);
5085 amdgpu_ttm_set_buffer_funcs_status(adev, false);
5087 amdgpu_fence_driver_hw_fini(adev);
5089 amdgpu_device_ip_suspend_phase2(adev);
5091 if (amdgpu_sriov_vf(adev))
5092 amdgpu_virt_release_full_gpu(adev, false);
5094 r = amdgpu_dpm_notify_rlc_state(adev, false);
5102 * amdgpu_device_resume - initiate device resume
5104 * @dev: drm dev pointer
5105 * @notify_clients: notify in-kernel DRM clients
5107 * Bring the hw back to operating state (all asics).
5108 * Returns 0 for success or an error on failure.
5109 * Called at driver resume.
5111 int amdgpu_device_resume(struct drm_device *dev, bool notify_clients)
5113 struct amdgpu_device *adev = drm_to_adev(dev);
5116 if (amdgpu_sriov_vf(adev)) {
5117 r = amdgpu_virt_request_full_gpu(adev, true);
5122 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
5126 amdgpu_dpm_gfx_state_change(adev, sGpuChangeState_D0Entry);
5129 if (amdgpu_device_need_post(adev)) {
5130 r = amdgpu_device_asic_init(adev);
5132 dev_err(adev->dev, "amdgpu asic init failed\n");
5135 r = amdgpu_device_ip_resume(adev);
5138 dev_err(adev->dev, "amdgpu_device_ip_resume failed (%d).\n", r);
5142 if (!adev->in_s0ix) {
5143 r = amdgpu_amdkfd_resume(adev, adev->in_runpm);
5147 r = amdgpu_userq_resume(adev);
5152 r = amdgpu_device_ip_late_init(adev);
5156 queue_delayed_work(system_wq, &adev->delayed_init_work,
5157 msecs_to_jiffies(AMDGPU_RESUME_MS));
5159 if (amdgpu_sriov_vf(adev)) {
5160 amdgpu_virt_init_data_exchange(adev);
5161 amdgpu_virt_release_full_gpu(adev, true);
5167 /* Make sure IB tests flushed */
5168 flush_delayed_work(&adev->delayed_init_work);
5171 drm_client_dev_resume(adev_to_drm(adev), false);
5173 amdgpu_ras_resume(adev);
5175 if (adev->mode_info.num_crtc) {
5177 * Most of the connector probing functions try to acquire runtime pm
5178 * refs to ensure that the GPU is powered on when connector polling is
5179 * performed. Since we're calling this from a runtime PM callback,
5180 * trying to acquire rpm refs will cause us to deadlock.
5182 * Since we're guaranteed to be holding the rpm lock, it's safe to
5183 * temporarily disable the rpm helpers so this doesn't deadlock us.
5186 dev->dev->power.disable_depth++;
5188 if (!adev->dc_enabled)
5189 drm_helper_hpd_irq_event(dev);
5191 drm_kms_helper_hotplug_event(dev);
5193 dev->dev->power.disable_depth--;
5196 adev->in_suspend = false;
5198 if (amdgpu_acpi_smart_shift_update(dev, AMDGPU_SS_DEV_D0))
5199 DRM_WARN("smart shift update failed\n");
5205 * amdgpu_device_ip_check_soft_reset - did soft reset succeed
5207 * @adev: amdgpu_device pointer
5209 * The list of all the hardware IPs that make up the asic is walked and
5210 * the check_soft_reset callbacks are run. check_soft_reset determines
5211 * if the asic is still hung or not.
5212 * Returns true if any of the IPs are still in a hung state, false if not.
5214 static bool amdgpu_device_ip_check_soft_reset(struct amdgpu_device *adev)
5217 bool asic_hang = false;
5219 if (amdgpu_sriov_vf(adev))
5222 if (amdgpu_asic_need_full_reset(adev))
5225 for (i = 0; i < adev->num_ip_blocks; i++) {
5226 if (!adev->ip_blocks[i].status.valid)
5228 if (adev->ip_blocks[i].version->funcs->check_soft_reset)
5229 adev->ip_blocks[i].status.hang =
5230 adev->ip_blocks[i].version->funcs->check_soft_reset(
5231 &adev->ip_blocks[i]);
5232 if (adev->ip_blocks[i].status.hang) {
5233 dev_info(adev->dev, "IP block:%s is hung!\n", adev->ip_blocks[i].version->funcs->name);
5241 * amdgpu_device_ip_pre_soft_reset - prepare for soft reset
5243 * @adev: amdgpu_device pointer
5245 * The list of all the hardware IPs that make up the asic is walked and the
5246 * pre_soft_reset callbacks are run if the block is hung. pre_soft_reset
5247 * handles any IP specific hardware or software state changes that are
5248 * necessary for a soft reset to succeed.
5249 * Returns 0 on success, negative error code on failure.
5251 static int amdgpu_device_ip_pre_soft_reset(struct amdgpu_device *adev)
5255 for (i = 0; i < adev->num_ip_blocks; i++) {
5256 if (!adev->ip_blocks[i].status.valid)
5258 if (adev->ip_blocks[i].status.hang &&
5259 adev->ip_blocks[i].version->funcs->pre_soft_reset) {
5260 r = adev->ip_blocks[i].version->funcs->pre_soft_reset(&adev->ip_blocks[i]);
5270 * amdgpu_device_ip_need_full_reset - check if a full asic reset is needed
5272 * @adev: amdgpu_device pointer
5274 * Some hardware IPs cannot be soft reset. If they are hung, a full gpu
5275 * reset is necessary to recover.
5276 * Returns true if a full asic reset is required, false if not.
5278 static bool amdgpu_device_ip_need_full_reset(struct amdgpu_device *adev)
5282 if (amdgpu_asic_need_full_reset(adev))
5285 for (i = 0; i < adev->num_ip_blocks; i++) {
5286 if (!adev->ip_blocks[i].status.valid)
5288 if ((adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) ||
5289 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) ||
5290 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_ACP) ||
5291 (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE) ||
5292 adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP) {
5293 if (adev->ip_blocks[i].status.hang) {
5294 dev_info(adev->dev, "Some block need full reset!\n");
5303 * amdgpu_device_ip_soft_reset - do a soft reset
5305 * @adev: amdgpu_device pointer
5307 * The list of all the hardware IPs that make up the asic is walked and the
5308 * soft_reset callbacks are run if the block is hung. soft_reset handles any
5309 * IP specific hardware or software state changes that are necessary to soft
5311 * Returns 0 on success, negative error code on failure.
5313 static int amdgpu_device_ip_soft_reset(struct amdgpu_device *adev)
5317 for (i = 0; i < adev->num_ip_blocks; i++) {
5318 if (!adev->ip_blocks[i].status.valid)
5320 if (adev->ip_blocks[i].status.hang &&
5321 adev->ip_blocks[i].version->funcs->soft_reset) {
5322 r = adev->ip_blocks[i].version->funcs->soft_reset(&adev->ip_blocks[i]);
5332 * amdgpu_device_ip_post_soft_reset - clean up from soft reset
5334 * @adev: amdgpu_device pointer
5336 * The list of all the hardware IPs that make up the asic is walked and the
5337 * post_soft_reset callbacks are run if the asic was hung. post_soft_reset
5338 * handles any IP specific hardware or software state changes that are
5339 * necessary after the IP has been soft reset.
5340 * Returns 0 on success, negative error code on failure.
5342 static int amdgpu_device_ip_post_soft_reset(struct amdgpu_device *adev)
5346 for (i = 0; i < adev->num_ip_blocks; i++) {
5347 if (!adev->ip_blocks[i].status.valid)
5349 if (adev->ip_blocks[i].status.hang &&
5350 adev->ip_blocks[i].version->funcs->post_soft_reset)
5351 r = adev->ip_blocks[i].version->funcs->post_soft_reset(&adev->ip_blocks[i]);
5360 * amdgpu_device_reset_sriov - reset ASIC for SR-IOV vf
5362 * @adev: amdgpu_device pointer
5363 * @reset_context: amdgpu reset context pointer
5365 * do VF FLR and reinitialize Asic
5366 * return 0 means succeeded otherwise failed
5368 static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
5369 struct amdgpu_reset_context *reset_context)
5372 struct amdgpu_hive_info *hive = NULL;
5374 if (test_bit(AMDGPU_HOST_FLR, &reset_context->flags)) {
5375 if (!amdgpu_ras_get_fed_status(adev))
5376 amdgpu_virt_ready_to_reset(adev);
5377 amdgpu_virt_wait_reset(adev);
5378 clear_bit(AMDGPU_HOST_FLR, &reset_context->flags);
5379 r = amdgpu_virt_request_full_gpu(adev, true);
5381 r = amdgpu_virt_reset_gpu(adev);
5386 amdgpu_ras_clear_err_state(adev);
5387 amdgpu_irq_gpu_reset_resume_helper(adev);
5389 /* some sw clean up VF needs to do before recover */
5390 amdgpu_virt_post_reset(adev);
5392 /* Resume IP prior to SMC */
5393 r = amdgpu_device_ip_reinit_early_sriov(adev);
5397 amdgpu_virt_init_data_exchange(adev);
5399 r = amdgpu_device_fw_loading(adev);
5403 /* now we are okay to resume SMC/CP/SDMA */
5404 r = amdgpu_device_ip_reinit_late_sriov(adev);
5408 hive = amdgpu_get_xgmi_hive(adev);
5409 /* Update PSP FW topology after reset */
5410 if (hive && adev->gmc.xgmi.num_physical_nodes > 1)
5411 r = amdgpu_xgmi_update_topology(hive, adev);
5413 amdgpu_put_xgmi_hive(hive);
5417 r = amdgpu_ib_ring_tests(adev);
5421 if (adev->virt.gim_feature & AMDGIM_FEATURE_GIM_FLR_VRAMLOST)
5422 amdgpu_inc_vram_lost(adev);
5424 /* need to be called during full access so we can't do it later like
5427 amdgpu_amdkfd_post_reset(adev);
5428 amdgpu_virt_release_full_gpu(adev, true);
5430 /* Aldebaran and gfx_11_0_3 support ras in SRIOV, so need resume ras during reset */
5431 if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 2) ||
5432 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) ||
5433 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 4) ||
5434 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 5, 0) ||
5435 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 0, 3))
5436 amdgpu_ras_resume(adev);
5438 amdgpu_virt_ras_telemetry_post_reset(adev);
5444 * amdgpu_device_has_job_running - check if there is any unfinished job
5446 * @adev: amdgpu_device pointer
5448 * check if there is any job running on the device when guest driver receives
5449 * FLR notification from host driver. If there are still jobs running, then
5450 * the guest driver will not respond the FLR reset. Instead, let the job hit
5451 * the timeout and guest driver then issue the reset request.
5453 bool amdgpu_device_has_job_running(struct amdgpu_device *adev)
5457 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
5458 struct amdgpu_ring *ring = adev->rings[i];
5460 if (!amdgpu_ring_sched_ready(ring))
5463 if (amdgpu_fence_count_emitted(ring))
5470 * amdgpu_device_should_recover_gpu - check if we should try GPU recovery
5472 * @adev: amdgpu_device pointer
5474 * Check amdgpu_gpu_recovery and SRIOV status to see if we should try to recover
5477 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev)
5480 if (amdgpu_gpu_recovery == 0)
5483 /* Skip soft reset check in fatal error mode */
5484 if (!amdgpu_ras_is_poison_mode_supported(adev))
5487 if (amdgpu_sriov_vf(adev))
5490 if (amdgpu_gpu_recovery == -1) {
5491 switch (adev->asic_type) {
5492 #ifdef CONFIG_DRM_AMDGPU_SI
5499 #ifdef CONFIG_DRM_AMDGPU_CIK
5506 case CHIP_CYAN_SKILLFISH:
5516 dev_info(adev->dev, "GPU recovery disabled.\n");
5520 int amdgpu_device_mode1_reset(struct amdgpu_device *adev)
5526 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
5528 dev_info(adev->dev, "GPU mode1 reset\n");
5530 /* Cache the state before bus master disable. The saved config space
5531 * values are used in other cases like restore after mode-2 reset.
5533 amdgpu_device_cache_pci_state(adev->pdev);
5536 pci_clear_master(adev->pdev);
5538 if (amdgpu_dpm_is_mode1_reset_supported(adev)) {
5539 dev_info(adev->dev, "GPU smu mode1 reset\n");
5540 ret = amdgpu_dpm_mode1_reset(adev);
5542 dev_info(adev->dev, "GPU psp mode1 reset\n");
5543 ret = psp_gpu_reset(adev);
5547 goto mode1_reset_failed;
5549 amdgpu_device_load_pci_state(adev->pdev);
5550 ret = amdgpu_psp_wait_for_bootloader(adev);
5552 goto mode1_reset_failed;
5554 /* wait for asic to come out of reset */
5555 for (i = 0; i < adev->usec_timeout; i++) {
5556 u32 memsize = adev->nbio.funcs->get_memsize(adev);
5558 if (memsize != 0xffffffff)
5563 if (i >= adev->usec_timeout) {
5565 goto mode1_reset_failed;
5569 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
5574 dev_err(adev->dev, "GPU mode1 reset failed\n");
5578 int amdgpu_device_link_reset(struct amdgpu_device *adev)
5582 dev_info(adev->dev, "GPU link reset\n");
5584 if (!adev->pcie_reset_ctx.occurs_dpc)
5585 ret = amdgpu_dpm_link_reset(adev);
5588 goto link_reset_failed;
5590 ret = amdgpu_psp_wait_for_bootloader(adev);
5592 goto link_reset_failed;
5597 dev_err(adev->dev, "GPU link reset failed\n");
5601 int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,
5602 struct amdgpu_reset_context *reset_context)
5605 struct amdgpu_job *job = NULL;
5606 struct amdgpu_device *tmp_adev = reset_context->reset_req_dev;
5607 bool need_full_reset =
5608 test_bit(AMDGPU_NEED_FULL_RESET, &reset_context->flags);
5610 if (reset_context->reset_req_dev == adev)
5611 job = reset_context->job;
5613 if (amdgpu_sriov_vf(adev))
5614 amdgpu_virt_pre_reset(adev);
5616 amdgpu_fence_driver_isr_toggle(adev, true);
5618 /* block all schedulers and reset given job's ring */
5619 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
5620 struct amdgpu_ring *ring = adev->rings[i];
5622 if (!amdgpu_ring_sched_ready(ring))
5625 /* Clear job fence from fence drv to avoid force_completion
5626 * leave NULL and vm flush fence in fence drv
5628 amdgpu_fence_driver_clear_job_fences(ring);
5630 /* after all hw jobs are reset, hw fence is meaningless, so force_completion */
5631 amdgpu_fence_driver_force_completion(ring);
5634 amdgpu_fence_driver_isr_toggle(adev, false);
5637 drm_sched_increase_karma(&job->base);
5639 r = amdgpu_reset_prepare_hwcontext(adev, reset_context);
5640 /* If reset handler not implemented, continue; otherwise return */
5641 if (r == -EOPNOTSUPP)
5646 /* Don't suspend on bare metal if we are not going to HW reset the ASIC */
5647 if (!amdgpu_sriov_vf(adev)) {
5649 if (!need_full_reset)
5650 need_full_reset = amdgpu_device_ip_need_full_reset(adev);
5652 if (!need_full_reset && amdgpu_gpu_recovery &&
5653 amdgpu_device_ip_check_soft_reset(adev)) {
5654 amdgpu_device_ip_pre_soft_reset(adev);
5655 r = amdgpu_device_ip_soft_reset(adev);
5656 amdgpu_device_ip_post_soft_reset(adev);
5657 if (r || amdgpu_device_ip_check_soft_reset(adev)) {
5658 dev_info(adev->dev, "soft reset failed, will fallback to full reset!\n");
5659 need_full_reset = true;
5663 if (!test_bit(AMDGPU_SKIP_COREDUMP, &reset_context->flags)) {
5664 dev_info(tmp_adev->dev, "Dumping IP State\n");
5665 /* Trigger ip dump before we reset the asic */
5666 for (i = 0; i < tmp_adev->num_ip_blocks; i++)
5667 if (tmp_adev->ip_blocks[i].version->funcs->dump_ip_state)
5668 tmp_adev->ip_blocks[i].version->funcs
5669 ->dump_ip_state((void *)&tmp_adev->ip_blocks[i]);
5670 dev_info(tmp_adev->dev, "Dumping IP State Completed\n");
5673 if (need_full_reset)
5674 r = amdgpu_device_ip_suspend(adev);
5675 if (need_full_reset)
5676 set_bit(AMDGPU_NEED_FULL_RESET, &reset_context->flags);
5678 clear_bit(AMDGPU_NEED_FULL_RESET,
5679 &reset_context->flags);
5685 int amdgpu_device_reinit_after_reset(struct amdgpu_reset_context *reset_context)
5687 struct list_head *device_list_handle;
5688 bool full_reset, vram_lost = false;
5689 struct amdgpu_device *tmp_adev;
5692 device_list_handle = reset_context->reset_device_list;
5694 if (!device_list_handle)
5697 full_reset = test_bit(AMDGPU_NEED_FULL_RESET, &reset_context->flags);
5700 * If it's reset on init, it's default init level, otherwise keep level
5701 * as recovery level.
5703 if (reset_context->method == AMD_RESET_METHOD_ON_INIT)
5704 init_level = AMDGPU_INIT_LEVEL_DEFAULT;
5706 init_level = AMDGPU_INIT_LEVEL_RESET_RECOVERY;
5709 list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
5710 amdgpu_set_init_level(tmp_adev, init_level);
5713 amdgpu_ras_clear_err_state(tmp_adev);
5714 r = amdgpu_device_asic_init(tmp_adev);
5716 dev_warn(tmp_adev->dev, "asic atom init failed!");
5718 dev_info(tmp_adev->dev, "GPU reset succeeded, trying to resume\n");
5720 r = amdgpu_device_ip_resume_phase1(tmp_adev);
5724 vram_lost = amdgpu_device_check_vram_lost(tmp_adev);
5726 if (!test_bit(AMDGPU_SKIP_COREDUMP, &reset_context->flags))
5727 amdgpu_coredump(tmp_adev, false, vram_lost, reset_context->job);
5730 DRM_INFO("VRAM is lost due to GPU reset!\n");
5731 amdgpu_inc_vram_lost(tmp_adev);
5734 r = amdgpu_device_fw_loading(tmp_adev);
5738 r = amdgpu_xcp_restore_partition_mode(
5743 r = amdgpu_device_ip_resume_phase2(tmp_adev);
5747 if (tmp_adev->mman.buffer_funcs_ring->sched.ready)
5748 amdgpu_ttm_set_buffer_funcs_status(tmp_adev, true);
5750 r = amdgpu_device_ip_resume_phase3(tmp_adev);
5755 amdgpu_device_fill_reset_magic(tmp_adev);
5758 * Add this ASIC as tracked as reset was already
5759 * complete successfully.
5761 amdgpu_register_gpu_instance(tmp_adev);
5763 if (!reset_context->hive &&
5764 tmp_adev->gmc.xgmi.num_physical_nodes > 1)
5765 amdgpu_xgmi_add_device(tmp_adev);
5767 r = amdgpu_device_ip_late_init(tmp_adev);
5771 drm_client_dev_resume(adev_to_drm(tmp_adev), false);
5774 * The GPU enters bad state once faulty pages
5775 * by ECC has reached the threshold, and ras
5776 * recovery is scheduled next. So add one check
5777 * here to break recovery if it indeed exceeds
5778 * bad page threshold, and remind user to
5779 * retire this GPU or setting one bigger
5780 * bad_page_threshold value to fix this once
5781 * probing driver again.
5783 if (!amdgpu_ras_is_rma(tmp_adev)) {
5785 amdgpu_ras_resume(tmp_adev);
5791 /* Update PSP FW topology after reset */
5792 if (reset_context->hive &&
5793 tmp_adev->gmc.xgmi.num_physical_nodes > 1)
5794 r = amdgpu_xgmi_update_topology(
5795 reset_context->hive, tmp_adev);
5801 /* IP init is complete now, set level as default */
5802 amdgpu_set_init_level(tmp_adev,
5803 AMDGPU_INIT_LEVEL_DEFAULT);
5804 amdgpu_irq_gpu_reset_resume_helper(tmp_adev);
5805 r = amdgpu_ib_ring_tests(tmp_adev);
5807 dev_err(tmp_adev->dev, "ib ring test failed (%d).\n", r);
5814 tmp_adev->asic_reset_res = r;
5821 int amdgpu_do_asic_reset(struct list_head *device_list_handle,
5822 struct amdgpu_reset_context *reset_context)
5824 struct amdgpu_device *tmp_adev = NULL;
5825 bool need_full_reset, skip_hw_reset;
5828 /* Try reset handler method first */
5829 tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
5832 reset_context->reset_device_list = device_list_handle;
5833 r = amdgpu_reset_perform_reset(tmp_adev, reset_context);
5834 /* If reset handler not implemented, continue; otherwise return */
5835 if (r == -EOPNOTSUPP)
5840 /* Reset handler not implemented, use the default method */
5842 test_bit(AMDGPU_NEED_FULL_RESET, &reset_context->flags);
5843 skip_hw_reset = test_bit(AMDGPU_SKIP_HW_RESET, &reset_context->flags);
5846 * ASIC reset has to be done on all XGMI hive nodes ASAP
5847 * to allow proper links negotiation in FW (within 1 sec)
5849 if (!skip_hw_reset && need_full_reset) {
5850 list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
5851 /* For XGMI run all resets in parallel to speed up the process */
5852 if (tmp_adev->gmc.xgmi.num_physical_nodes > 1) {
5853 if (!queue_work(system_unbound_wq,
5854 &tmp_adev->xgmi_reset_work))
5857 r = amdgpu_asic_reset(tmp_adev);
5860 dev_err(tmp_adev->dev,
5861 "ASIC reset failed with error, %d for drm dev, %s",
5862 r, adev_to_drm(tmp_adev)->unique);
5867 /* For XGMI wait for all resets to complete before proceed */
5869 list_for_each_entry(tmp_adev, device_list_handle,
5871 if (tmp_adev->gmc.xgmi.num_physical_nodes > 1) {
5872 flush_work(&tmp_adev->xgmi_reset_work);
5873 r = tmp_adev->asic_reset_res;
5881 if (!r && amdgpu_ras_intr_triggered()) {
5882 list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
5883 amdgpu_ras_reset_error_count(tmp_adev,
5884 AMDGPU_RAS_BLOCK__MMHUB);
5887 amdgpu_ras_intr_cleared();
5890 r = amdgpu_device_reinit_after_reset(reset_context);
5892 set_bit(AMDGPU_NEED_FULL_RESET, &reset_context->flags);
5894 clear_bit(AMDGPU_NEED_FULL_RESET, &reset_context->flags);
5900 static void amdgpu_device_set_mp1_state(struct amdgpu_device *adev)
5903 switch (amdgpu_asic_reset_method(adev)) {
5904 case AMD_RESET_METHOD_MODE1:
5905 case AMD_RESET_METHOD_LINK:
5906 adev->mp1_state = PP_MP1_STATE_SHUTDOWN;
5908 case AMD_RESET_METHOD_MODE2:
5909 adev->mp1_state = PP_MP1_STATE_RESET;
5912 adev->mp1_state = PP_MP1_STATE_NONE;
5917 static void amdgpu_device_unset_mp1_state(struct amdgpu_device *adev)
5919 amdgpu_vf_error_trans_all(adev);
5920 adev->mp1_state = PP_MP1_STATE_NONE;
5923 static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
5925 struct pci_dev *p = NULL;
5927 p = pci_get_domain_bus_and_slot(pci_domain_nr(adev->pdev->bus),
5928 adev->pdev->bus->number, 1);
5930 pm_runtime_enable(&(p->dev));
5931 pm_runtime_resume(&(p->dev));
5937 static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
5939 enum amd_reset_method reset_method;
5940 struct pci_dev *p = NULL;
5944 * For now, only BACO and mode1 reset are confirmed
5945 * to suffer the audio issue without proper suspended.
5947 reset_method = amdgpu_asic_reset_method(adev);
5948 if ((reset_method != AMD_RESET_METHOD_BACO) &&
5949 (reset_method != AMD_RESET_METHOD_MODE1))
5952 p = pci_get_domain_bus_and_slot(pci_domain_nr(adev->pdev->bus),
5953 adev->pdev->bus->number, 1);
5957 expires = pm_runtime_autosuspend_expiration(&(p->dev));
5960 * If we cannot get the audio device autosuspend delay,
5961 * a fixed 4S interval will be used. Considering 3S is
5962 * the audio controller default autosuspend delay setting.
5963 * 4S used here is guaranteed to cover that.
5965 expires = ktime_get_mono_fast_ns() + NSEC_PER_SEC * 4ULL;
5967 while (!pm_runtime_status_suspended(&(p->dev))) {
5968 if (!pm_runtime_suspend(&(p->dev)))
5971 if (expires < ktime_get_mono_fast_ns()) {
5972 dev_warn(adev->dev, "failed to suspend display audio\n");
5974 /* TODO: abort the succeeding gpu reset? */
5979 pm_runtime_disable(&(p->dev));
5985 static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev)
5987 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
5989 #if defined(CONFIG_DEBUG_FS)
5990 if (!amdgpu_sriov_vf(adev))
5991 cancel_work(&adev->reset_work);
5995 cancel_work(&adev->kfd.reset_work);
5997 if (amdgpu_sriov_vf(adev))
5998 cancel_work(&adev->virt.flr_work);
6000 if (con && adev->ras_enabled)
6001 cancel_work(&con->recovery_work);
6005 static int amdgpu_device_health_check(struct list_head *device_list_handle)
6007 struct amdgpu_device *tmp_adev;
6011 list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
6012 pci_read_config_dword(tmp_adev->pdev, PCI_COMMAND, &status);
6013 if (PCI_POSSIBLE_ERROR(status)) {
6014 dev_err(tmp_adev->dev, "device lost from bus!");
6022 static int amdgpu_device_recovery_prepare(struct amdgpu_device *adev,
6023 struct list_head *device_list,
6024 struct amdgpu_hive_info *hive)
6026 struct amdgpu_device *tmp_adev = NULL;
6030 * Build list of devices to reset.
6031 * In case we are in XGMI hive mode, resort the device list
6032 * to put adev in the 1st position.
6034 if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes > 1) && hive) {
6035 list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {
6036 list_add_tail(&tmp_adev->reset_list, device_list);
6038 tmp_adev->shutdown = true;
6039 if (adev->pcie_reset_ctx.occurs_dpc)
6040 tmp_adev->pcie_reset_ctx.in_link_reset = true;
6042 if (!list_is_first(&adev->reset_list, device_list))
6043 list_rotate_to_front(&adev->reset_list, device_list);
6045 list_add_tail(&adev->reset_list, device_list);
6048 if (!amdgpu_sriov_vf(adev) && (!adev->pcie_reset_ctx.occurs_dpc)) {
6049 r = amdgpu_device_health_check(device_list);
6057 static void amdgpu_device_recovery_get_reset_lock(struct amdgpu_device *adev,
6058 struct list_head *device_list)
6060 struct amdgpu_device *tmp_adev = NULL;
6062 if (list_empty(device_list))
6065 list_first_entry(device_list, struct amdgpu_device, reset_list);
6066 amdgpu_device_lock_reset_domain(tmp_adev->reset_domain);
6069 static void amdgpu_device_recovery_put_reset_lock(struct amdgpu_device *adev,
6070 struct list_head *device_list)
6072 struct amdgpu_device *tmp_adev = NULL;
6074 if (list_empty(device_list))
6077 list_first_entry(device_list, struct amdgpu_device, reset_list);
6078 amdgpu_device_unlock_reset_domain(tmp_adev->reset_domain);
6081 static int amdgpu_device_halt_activities(
6082 struct amdgpu_device *adev, struct amdgpu_job *job,
6083 struct amdgpu_reset_context *reset_context,
6084 struct list_head *device_list, struct amdgpu_hive_info *hive,
6085 bool need_emergency_restart)
6087 struct amdgpu_device *tmp_adev = NULL;
6090 /* block all schedulers and reset given job's ring */
6091 list_for_each_entry(tmp_adev, device_list, reset_list) {
6092 amdgpu_device_set_mp1_state(tmp_adev);
6095 * Try to put the audio codec into suspend state
6096 * before gpu reset started.
6098 * Due to the power domain of the graphics device
6099 * is shared with AZ power domain. Without this,
6100 * we may change the audio hardware from behind
6101 * the audio driver's back. That will trigger
6102 * some audio codec errors.
6104 if (!amdgpu_device_suspend_display_audio(tmp_adev))
6105 tmp_adev->pcie_reset_ctx.audio_suspended = true;
6107 amdgpu_ras_set_error_query_ready(tmp_adev, false);
6109 cancel_delayed_work_sync(&tmp_adev->delayed_init_work);
6111 amdgpu_amdkfd_pre_reset(tmp_adev, reset_context);
6114 * Mark these ASICs to be reset as untracked first
6115 * And add them back after reset completed
6117 amdgpu_unregister_gpu_instance(tmp_adev);
6119 drm_client_dev_suspend(adev_to_drm(tmp_adev), false);
6121 /* disable ras on ALL IPs */
6122 if (!need_emergency_restart &&
6123 (!adev->pcie_reset_ctx.occurs_dpc) &&
6124 amdgpu_device_ip_need_full_reset(tmp_adev))
6125 amdgpu_ras_suspend(tmp_adev);
6127 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
6128 struct amdgpu_ring *ring = tmp_adev->rings[i];
6130 if (!amdgpu_ring_sched_ready(ring))
6133 drm_sched_stop(&ring->sched, job ? &job->base : NULL);
6135 if (need_emergency_restart)
6136 amdgpu_job_stop_all_jobs_on_sched(&ring->sched);
6138 atomic_inc(&tmp_adev->gpu_reset_counter);
6144 static int amdgpu_device_asic_reset(struct amdgpu_device *adev,
6145 struct list_head *device_list,
6146 struct amdgpu_reset_context *reset_context)
6148 struct amdgpu_device *tmp_adev = NULL;
6149 int retry_limit = AMDGPU_MAX_RETRY_LIMIT;
6152 retry: /* Rest of adevs pre asic reset from XGMI hive. */
6153 list_for_each_entry(tmp_adev, device_list, reset_list) {
6154 if (adev->pcie_reset_ctx.occurs_dpc)
6155 tmp_adev->no_hw_access = true;
6156 r = amdgpu_device_pre_asic_reset(tmp_adev, reset_context);
6157 if (adev->pcie_reset_ctx.occurs_dpc)
6158 tmp_adev->no_hw_access = false;
6159 /*TODO Should we stop ?*/
6161 dev_err(tmp_adev->dev, "GPU pre asic reset failed with err, %d for drm dev, %s ",
6162 r, adev_to_drm(tmp_adev)->unique);
6163 tmp_adev->asic_reset_res = r;
6167 /* Actual ASIC resets if needed.*/
6168 /* Host driver will handle XGMI hive reset for SRIOV */
6169 if (amdgpu_sriov_vf(adev)) {
6171 /* Bail out of reset early */
6172 if (amdgpu_ras_is_rma(adev))
6175 if (amdgpu_ras_get_fed_status(adev) || amdgpu_virt_rcvd_ras_interrupt(adev)) {
6176 dev_dbg(adev->dev, "Detected RAS error, wait for FLR completion\n");
6177 amdgpu_ras_set_fed(adev, true);
6178 set_bit(AMDGPU_HOST_FLR, &reset_context->flags);
6181 r = amdgpu_device_reset_sriov(adev, reset_context);
6182 if (AMDGPU_RETRY_SRIOV_RESET(r) && (retry_limit--) > 0) {
6183 amdgpu_virt_release_full_gpu(adev, true);
6187 adev->asic_reset_res = r;
6189 r = amdgpu_do_asic_reset(device_list, reset_context);
6190 if (r && r == -EAGAIN)
6194 list_for_each_entry(tmp_adev, device_list, reset_list) {
6196 * Drop any pending non scheduler resets queued before reset is done.
6197 * Any reset scheduled after this point would be valid. Scheduler resets
6198 * were already dropped during drm_sched_stop and no new ones can come
6199 * in before drm_sched_start.
6201 amdgpu_device_stop_pending_resets(tmp_adev);
6207 static int amdgpu_device_sched_resume(struct list_head *device_list,
6208 struct amdgpu_reset_context *reset_context,
6211 struct amdgpu_device *tmp_adev = NULL;
6214 /* Post ASIC reset for all devs .*/
6215 list_for_each_entry(tmp_adev, device_list, reset_list) {
6217 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
6218 struct amdgpu_ring *ring = tmp_adev->rings[i];
6220 if (!amdgpu_ring_sched_ready(ring))
6223 drm_sched_start(&ring->sched, 0);
6226 if (!drm_drv_uses_atomic_modeset(adev_to_drm(tmp_adev)) && !job_signaled)
6227 drm_helper_resume_force_mode(adev_to_drm(tmp_adev));
6229 if (tmp_adev->asic_reset_res)
6230 r = tmp_adev->asic_reset_res;
6232 tmp_adev->asic_reset_res = 0;
6235 /* bad news, how to tell it to userspace ?
6236 * for ras error, we should report GPU bad status instead of
6239 if (reset_context->src != AMDGPU_RESET_SRC_RAS ||
6240 !amdgpu_ras_eeprom_check_err_threshold(tmp_adev))
6241 dev_info(tmp_adev->dev, "GPU reset(%d) failed\n",
6242 atomic_read(&tmp_adev->gpu_reset_counter));
6243 amdgpu_vf_error_put(tmp_adev, AMDGIM_ERROR_VF_GPU_RESET_FAIL, 0, r);
6245 dev_info(tmp_adev->dev, "GPU reset(%d) succeeded!\n", atomic_read(&tmp_adev->gpu_reset_counter));
6246 if (amdgpu_acpi_smart_shift_update(adev_to_drm(tmp_adev), AMDGPU_SS_DEV_D0))
6247 DRM_WARN("smart shift update failed\n");
6254 static void amdgpu_device_gpu_resume(struct amdgpu_device *adev,
6255 struct list_head *device_list,
6256 bool need_emergency_restart)
6258 struct amdgpu_device *tmp_adev = NULL;
6260 list_for_each_entry(tmp_adev, device_list, reset_list) {
6261 /* unlock kfd: SRIOV would do it separately */
6262 if (!need_emergency_restart && !amdgpu_sriov_vf(tmp_adev))
6263 amdgpu_amdkfd_post_reset(tmp_adev);
6265 /* kfd_post_reset will do nothing if kfd device is not initialized,
6266 * need to bring up kfd here if it's not be initialized before
6268 if (!adev->kfd.init_complete)
6269 amdgpu_amdkfd_device_init(adev);
6271 if (tmp_adev->pcie_reset_ctx.audio_suspended)
6272 amdgpu_device_resume_display_audio(tmp_adev);
6274 amdgpu_device_unset_mp1_state(tmp_adev);
6276 amdgpu_ras_set_error_query_ready(tmp_adev, true);
6283 * amdgpu_device_gpu_recover - reset the asic and recover scheduler
6285 * @adev: amdgpu_device pointer
6286 * @job: which job trigger hang
6287 * @reset_context: amdgpu reset context pointer
6289 * Attempt to reset the GPU if it has hung (all asics).
6290 * Attempt to do soft-reset or full-reset and reinitialize Asic
6291 * Returns 0 for success or an error on failure.
6294 int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
6295 struct amdgpu_job *job,
6296 struct amdgpu_reset_context *reset_context)
6298 struct list_head device_list;
6299 bool job_signaled = false;
6300 struct amdgpu_hive_info *hive = NULL;
6302 bool need_emergency_restart = false;
6305 * If it reaches here because of hang/timeout and a RAS error is
6306 * detected at the same time, let RAS recovery take care of it.
6308 if (amdgpu_ras_is_err_state(adev, AMDGPU_RAS_BLOCK__ANY) &&
6309 !amdgpu_sriov_vf(adev) &&
6310 reset_context->src != AMDGPU_RESET_SRC_RAS) {
6312 "Gpu recovery from source: %d yielding to RAS error recovery handling",
6313 reset_context->src);
6318 * Special case: RAS triggered and full reset isn't supported
6320 need_emergency_restart = amdgpu_ras_need_emergency_restart(adev);
6323 * Flush RAM to disk so that after reboot
6324 * the user can read log and see why the system rebooted.
6326 if (need_emergency_restart && amdgpu_ras_get_context(adev) &&
6327 amdgpu_ras_get_context(adev)->reboot) {
6328 DRM_WARN("Emergency reboot.");
6331 emergency_restart();
6334 dev_info(adev->dev, "GPU %s begin!\n",
6335 need_emergency_restart ? "jobs stop":"reset");
6337 if (!amdgpu_sriov_vf(adev))
6338 hive = amdgpu_get_xgmi_hive(adev);
6340 mutex_lock(&hive->hive_lock);
6342 reset_context->job = job;
6343 reset_context->hive = hive;
6344 INIT_LIST_HEAD(&device_list);
6346 if (amdgpu_device_recovery_prepare(adev, &device_list, hive))
6349 /* We need to lock reset domain only once both for XGMI and single device */
6350 amdgpu_device_recovery_get_reset_lock(adev, &device_list);
6352 r = amdgpu_device_halt_activities(adev, job, reset_context, &device_list,
6353 hive, need_emergency_restart);
6357 if (need_emergency_restart)
6358 goto skip_sched_resume;
6360 * Must check guilty signal here since after this point all old
6361 * HW fences are force signaled.
6363 * job->base holds a reference to parent fence
6365 if (job && dma_fence_is_signaled(&job->hw_fence.base)) {
6366 job_signaled = true;
6367 dev_info(adev->dev, "Guilty job already signaled, skipping HW reset");
6371 r = amdgpu_device_asic_reset(adev, &device_list, reset_context);
6375 r = amdgpu_device_sched_resume(&device_list, reset_context, job_signaled);
6379 amdgpu_device_gpu_resume(adev, &device_list, need_emergency_restart);
6381 amdgpu_device_recovery_put_reset_lock(adev, &device_list);
6384 mutex_unlock(&hive->hive_lock);
6385 amdgpu_put_xgmi_hive(hive);
6389 dev_info(adev->dev, "GPU reset end with ret = %d\n", r);
6391 atomic_set(&adev->reset_domain->reset_res, r);
6394 drm_dev_wedged_event(adev_to_drm(adev), DRM_WEDGE_RECOVERY_NONE);
6400 * amdgpu_device_partner_bandwidth - find the bandwidth of appropriate partner
6402 * @adev: amdgpu_device pointer
6403 * @speed: pointer to the speed of the link
6404 * @width: pointer to the width of the link
6406 * Evaluate the hierarchy to find the speed and bandwidth capabilities of the
6407 * first physical partner to an AMD dGPU.
6408 * This will exclude any virtual switches and links.
6410 static void amdgpu_device_partner_bandwidth(struct amdgpu_device *adev,
6411 enum pci_bus_speed *speed,
6412 enum pcie_link_width *width)
6414 struct pci_dev *parent = adev->pdev;
6416 if (!speed || !width)
6419 *speed = PCI_SPEED_UNKNOWN;
6420 *width = PCIE_LNK_WIDTH_UNKNOWN;
6422 if (amdgpu_device_pcie_dynamic_switching_supported(adev)) {
6423 while ((parent = pci_upstream_bridge(parent))) {
6424 /* skip upstream/downstream switches internal to dGPU*/
6425 if (parent->vendor == PCI_VENDOR_ID_ATI)
6427 *speed = pcie_get_speed_cap(parent);
6428 *width = pcie_get_width_cap(parent);
6432 /* use the current speeds rather than max if switching is not supported */
6433 pcie_bandwidth_available(adev->pdev, NULL, speed, width);
6438 * amdgpu_device_gpu_bandwidth - find the bandwidth of the GPU
6440 * @adev: amdgpu_device pointer
6441 * @speed: pointer to the speed of the link
6442 * @width: pointer to the width of the link
6444 * Evaluate the hierarchy to find the speed and bandwidth capabilities of the
6445 * AMD dGPU which may be a virtual upstream bridge.
6447 static void amdgpu_device_gpu_bandwidth(struct amdgpu_device *adev,
6448 enum pci_bus_speed *speed,
6449 enum pcie_link_width *width)
6451 struct pci_dev *parent = adev->pdev;
6453 if (!speed || !width)
6456 parent = pci_upstream_bridge(parent);
6457 if (parent && parent->vendor == PCI_VENDOR_ID_ATI) {
6458 /* use the upstream/downstream switches internal to dGPU */
6459 *speed = pcie_get_speed_cap(parent);
6460 *width = pcie_get_width_cap(parent);
6461 while ((parent = pci_upstream_bridge(parent))) {
6462 if (parent->vendor == PCI_VENDOR_ID_ATI) {
6463 /* use the upstream/downstream switches internal to dGPU */
6464 *speed = pcie_get_speed_cap(parent);
6465 *width = pcie_get_width_cap(parent);
6469 /* use the device itself */
6470 *speed = pcie_get_speed_cap(adev->pdev);
6471 *width = pcie_get_width_cap(adev->pdev);
6476 * amdgpu_device_get_pcie_info - fence pcie info about the PCIE slot
6478 * @adev: amdgpu_device pointer
6480 * Fetches and stores in the driver the PCIE capabilities (gen speed
6481 * and lanes) of the slot the device is in. Handles APUs and
6482 * virtualized environments where PCIE config space may not be available.
6484 static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev)
6486 enum pci_bus_speed speed_cap, platform_speed_cap;
6487 enum pcie_link_width platform_link_width, link_width;
6489 if (amdgpu_pcie_gen_cap)
6490 adev->pm.pcie_gen_mask = amdgpu_pcie_gen_cap;
6492 if (amdgpu_pcie_lane_cap)
6493 adev->pm.pcie_mlw_mask = amdgpu_pcie_lane_cap;
6495 /* covers APUs as well */
6496 if (pci_is_root_bus(adev->pdev->bus) && !amdgpu_passthrough(adev)) {
6497 if (adev->pm.pcie_gen_mask == 0)
6498 adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
6499 if (adev->pm.pcie_mlw_mask == 0)
6500 adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
6504 if (adev->pm.pcie_gen_mask && adev->pm.pcie_mlw_mask)
6507 amdgpu_device_partner_bandwidth(adev, &platform_speed_cap,
6508 &platform_link_width);
6509 amdgpu_device_gpu_bandwidth(adev, &speed_cap, &link_width);
6511 if (adev->pm.pcie_gen_mask == 0) {
6513 if (speed_cap == PCI_SPEED_UNKNOWN) {
6514 adev->pm.pcie_gen_mask |= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6515 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
6516 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3);
6518 if (speed_cap == PCIE_SPEED_32_0GT)
6519 adev->pm.pcie_gen_mask |= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6520 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
6521 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3 |
6522 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN4 |
6523 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN5);
6524 else if (speed_cap == PCIE_SPEED_16_0GT)
6525 adev->pm.pcie_gen_mask |= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6526 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
6527 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3 |
6528 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN4);
6529 else if (speed_cap == PCIE_SPEED_8_0GT)
6530 adev->pm.pcie_gen_mask |= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6531 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
6532 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3);
6533 else if (speed_cap == PCIE_SPEED_5_0GT)
6534 adev->pm.pcie_gen_mask |= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6535 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2);
6537 adev->pm.pcie_gen_mask |= CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1;
6540 if (platform_speed_cap == PCI_SPEED_UNKNOWN) {
6541 adev->pm.pcie_gen_mask |= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6542 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2);
6544 if (platform_speed_cap == PCIE_SPEED_32_0GT)
6545 adev->pm.pcie_gen_mask |= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6546 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
6547 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3 |
6548 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN4 |
6549 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN5);
6550 else if (platform_speed_cap == PCIE_SPEED_16_0GT)
6551 adev->pm.pcie_gen_mask |= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6552 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
6553 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3 |
6554 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN4);
6555 else if (platform_speed_cap == PCIE_SPEED_8_0GT)
6556 adev->pm.pcie_gen_mask |= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6557 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
6558 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3);
6559 else if (platform_speed_cap == PCIE_SPEED_5_0GT)
6560 adev->pm.pcie_gen_mask |= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 |
6561 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2);
6563 adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1;
6567 if (adev->pm.pcie_mlw_mask == 0) {
6569 if (link_width == PCIE_LNK_WIDTH_UNKNOWN) {
6570 adev->pm.pcie_mlw_mask |= AMDGPU_DEFAULT_ASIC_PCIE_MLW_MASK;
6572 switch (link_width) {
6574 adev->pm.pcie_mlw_mask |= (CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X32 |
6575 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X16 |
6576 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X12 |
6577 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X8 |
6578 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X4 |
6579 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X2 |
6580 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X1);
6583 adev->pm.pcie_mlw_mask |= (CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X16 |
6584 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X12 |
6585 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X8 |
6586 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X4 |
6587 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X2 |
6588 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X1);
6591 adev->pm.pcie_mlw_mask |= (CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X12 |
6592 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X8 |
6593 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X4 |
6594 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X2 |
6595 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X1);
6598 adev->pm.pcie_mlw_mask |= (CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X8 |
6599 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X4 |
6600 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X2 |
6601 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X1);
6604 adev->pm.pcie_mlw_mask |= (CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X4 |
6605 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X2 |
6606 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X1);
6609 adev->pm.pcie_mlw_mask |= (CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X2 |
6610 CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X1);
6613 adev->pm.pcie_mlw_mask |= CAIL_ASIC_PCIE_LINK_WIDTH_SUPPORT_X1;
6620 if (platform_link_width == PCIE_LNK_WIDTH_UNKNOWN) {
6621 adev->pm.pcie_mlw_mask |= AMDGPU_DEFAULT_PCIE_MLW_MASK;
6623 switch (platform_link_width) {
6625 adev->pm.pcie_mlw_mask |= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 |
6626 CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
6627 CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
6628 CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
6629 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
6630 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
6631 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
6634 adev->pm.pcie_mlw_mask |= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
6635 CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
6636 CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
6637 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
6638 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
6639 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
6642 adev->pm.pcie_mlw_mask |= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
6643 CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
6644 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
6645 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
6646 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
6649 adev->pm.pcie_mlw_mask |= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
6650 CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
6651 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
6652 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
6655 adev->pm.pcie_mlw_mask |= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
6656 CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
6657 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
6660 adev->pm.pcie_mlw_mask |= (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
6661 CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
6664 adev->pm.pcie_mlw_mask |= CAIL_PCIE_LINK_WIDTH_SUPPORT_X1;
6674 * amdgpu_device_is_peer_accessible - Check peer access through PCIe BAR
6676 * @adev: amdgpu_device pointer
6677 * @peer_adev: amdgpu_device pointer for peer device trying to access @adev
6679 * Return true if @peer_adev can access (DMA) @adev through the PCIe
6680 * BAR, i.e. @adev is "large BAR" and the BAR matches the DMA mask of
6683 bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
6684 struct amdgpu_device *peer_adev)
6686 #ifdef CONFIG_HSA_AMD_P2P
6688 !adev->gmc.xgmi.connected_to_cpu &&
6689 !(pci_p2pdma_distance(adev->pdev, peer_adev->dev, false) < 0);
6691 dev_info(adev->dev, "PCIe P2P access from peer device %s is not supported by the chipset\n",
6692 pci_name(peer_adev->pdev));
6694 bool is_large_bar = adev->gmc.visible_vram_size &&
6695 adev->gmc.real_vram_size == adev->gmc.visible_vram_size;
6696 bool p2p_addressable = amdgpu_device_check_iommu_remap(peer_adev);
6698 if (!p2p_addressable) {
6699 uint64_t address_mask = peer_adev->dev->dma_mask ?
6700 ~*peer_adev->dev->dma_mask : ~((1ULL << 32) - 1);
6701 resource_size_t aper_limit =
6702 adev->gmc.aper_base + adev->gmc.aper_size - 1;
6704 p2p_addressable = !(adev->gmc.aper_base & address_mask ||
6705 aper_limit & address_mask);
6707 return pcie_p2p && is_large_bar && p2p_access && p2p_addressable;
6713 int amdgpu_device_baco_enter(struct drm_device *dev)
6715 struct amdgpu_device *adev = drm_to_adev(dev);
6716 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
6718 if (!amdgpu_device_supports_baco(dev))
6721 if (ras && adev->ras_enabled &&
6722 adev->nbio.funcs->enable_doorbell_interrupt)
6723 adev->nbio.funcs->enable_doorbell_interrupt(adev, false);
6725 return amdgpu_dpm_baco_enter(adev);
6728 int amdgpu_device_baco_exit(struct drm_device *dev)
6730 struct amdgpu_device *adev = drm_to_adev(dev);
6731 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
6734 if (!amdgpu_device_supports_baco(dev))
6737 ret = amdgpu_dpm_baco_exit(adev);
6741 if (ras && adev->ras_enabled &&
6742 adev->nbio.funcs->enable_doorbell_interrupt)
6743 adev->nbio.funcs->enable_doorbell_interrupt(adev, true);
6745 if (amdgpu_passthrough(adev) && adev->nbio.funcs &&
6746 adev->nbio.funcs->clear_doorbell_interrupt)
6747 adev->nbio.funcs->clear_doorbell_interrupt(adev);
6753 * amdgpu_pci_error_detected - Called when a PCI error is detected.
6754 * @pdev: PCI device struct
6755 * @state: PCI channel state
6757 * Description: Called when a PCI error is detected.
6759 * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT.
6761 pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6763 struct drm_device *dev = pci_get_drvdata(pdev);
6764 struct amdgpu_device *adev = drm_to_adev(dev);
6765 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
6766 struct amdgpu_reset_context reset_context;
6767 struct list_head device_list;
6770 dev_info(adev->dev, "PCI error: detected callback!!\n");
6772 if (!amdgpu_dpm_is_link_reset_supported(adev)) {
6773 dev_warn(adev->dev, "No support for XGMI hive yet...\n");
6774 return PCI_ERS_RESULT_DISCONNECT;
6777 adev->pci_channel_state = state;
6780 case pci_channel_io_normal:
6781 dev_info(adev->dev, "pci_channel_io_normal: state(%d)!!\n", state);
6782 return PCI_ERS_RESULT_CAN_RECOVER;
6783 case pci_channel_io_frozen:
6784 /* Fatal error, prepare for slot reset */
6785 dev_info(adev->dev, "pci_channel_io_frozen: state(%d)!!\n", state);
6788 mutex_lock(&hive->hive_lock);
6789 adev->pcie_reset_ctx.occurs_dpc = true;
6790 memset(&reset_context, 0, sizeof(reset_context));
6791 INIT_LIST_HEAD(&device_list);
6793 amdgpu_device_recovery_prepare(adev, &device_list, hive);
6794 amdgpu_device_recovery_get_reset_lock(adev, &device_list);
6795 r = amdgpu_device_halt_activities(adev, NULL, &reset_context, &device_list,
6798 mutex_unlock(&hive->hive_lock);
6799 amdgpu_put_xgmi_hive(hive);
6802 return PCI_ERS_RESULT_DISCONNECT;
6803 return PCI_ERS_RESULT_NEED_RESET;
6804 case pci_channel_io_perm_failure:
6805 /* Permanent error, prepare for device removal */
6806 dev_info(adev->dev, "pci_channel_io_perm_failure: state(%d)!!\n", state);
6807 return PCI_ERS_RESULT_DISCONNECT;
6810 return PCI_ERS_RESULT_NEED_RESET;
6814 * amdgpu_pci_mmio_enabled - Enable MMIO and dump debug registers
6815 * @pdev: pointer to PCI device
6817 pci_ers_result_t amdgpu_pci_mmio_enabled(struct pci_dev *pdev)
6819 struct drm_device *dev = pci_get_drvdata(pdev);
6820 struct amdgpu_device *adev = drm_to_adev(dev);
6822 dev_info(adev->dev, "PCI error: mmio enabled callback!!\n");
6824 /* TODO - dump whatever for debugging purposes */
6826 /* This called only if amdgpu_pci_error_detected returns
6827 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
6828 * works, no need to reset slot.
6831 return PCI_ERS_RESULT_RECOVERED;
6835 * amdgpu_pci_slot_reset - Called when PCI slot has been reset.
6836 * @pdev: PCI device struct
6838 * Description: This routine is called by the pci error recovery
6839 * code after the PCI slot has been reset, just before we
6840 * should resume normal operations.
6842 pci_ers_result_t amdgpu_pci_slot_reset(struct pci_dev *pdev)
6844 struct drm_device *dev = pci_get_drvdata(pdev);
6845 struct amdgpu_device *adev = drm_to_adev(dev);
6846 struct amdgpu_reset_context reset_context;
6847 struct amdgpu_device *tmp_adev;
6848 struct amdgpu_hive_info *hive;
6849 struct list_head device_list;
6853 /* PCI error slot reset should be skipped During RAS recovery */
6854 if ((amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) ||
6855 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 4)) &&
6856 amdgpu_ras_in_recovery(adev))
6857 return PCI_ERS_RESULT_RECOVERED;
6859 dev_info(adev->dev, "PCI error: slot reset callback!!\n");
6861 memset(&reset_context, 0, sizeof(reset_context));
6863 /* wait for asic to come out of reset */
6866 /* Restore PCI confspace */
6867 amdgpu_device_load_pci_state(pdev);
6869 /* confirm ASIC came out of reset */
6870 for (i = 0; i < adev->usec_timeout; i++) {
6871 memsize = amdgpu_asic_get_config_memsize(adev);
6873 if (memsize != 0xffffffff)
6877 if (memsize == 0xffffffff) {
6882 reset_context.method = AMD_RESET_METHOD_NONE;
6883 reset_context.reset_req_dev = adev;
6884 set_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);
6885 set_bit(AMDGPU_SKIP_COREDUMP, &reset_context.flags);
6886 INIT_LIST_HEAD(&device_list);
6888 hive = amdgpu_get_xgmi_hive(adev);
6890 mutex_lock(&hive->hive_lock);
6891 reset_context.hive = hive;
6892 list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {
6893 tmp_adev->pcie_reset_ctx.in_link_reset = true;
6894 list_add_tail(&tmp_adev->reset_list, &device_list);
6897 set_bit(AMDGPU_SKIP_HW_RESET, &reset_context.flags);
6898 list_add_tail(&adev->reset_list, &device_list);
6901 r = amdgpu_device_asic_reset(adev, &device_list, &reset_context);
6904 if (amdgpu_device_cache_pci_state(adev->pdev))
6905 pci_restore_state(adev->pdev);
6906 dev_info(adev->dev, "PCIe error recovery succeeded\n");
6908 dev_err(adev->dev, "PCIe error recovery failed, err:%d\n", r);
6910 list_for_each_entry(tmp_adev, &device_list, reset_list)
6911 amdgpu_device_unset_mp1_state(tmp_adev);
6913 amdgpu_device_recovery_put_reset_lock(adev, &device_list);
6917 mutex_unlock(&hive->hive_lock);
6918 amdgpu_put_xgmi_hive(hive);
6921 return r ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
6925 * amdgpu_pci_resume() - resume normal ops after PCI reset
6926 * @pdev: pointer to PCI device
6928 * Called when the error recovery driver tells us that its
6929 * OK to resume normal operation.
6931 void amdgpu_pci_resume(struct pci_dev *pdev)
6933 struct drm_device *dev = pci_get_drvdata(pdev);
6934 struct amdgpu_device *adev = drm_to_adev(dev);
6935 struct list_head device_list;
6936 struct amdgpu_hive_info *hive = NULL;
6937 struct amdgpu_device *tmp_adev = NULL;
6939 dev_info(adev->dev, "PCI error: resume callback!!\n");
6941 /* Only continue execution for the case of pci_channel_io_frozen */
6942 if (adev->pci_channel_state != pci_channel_io_frozen)
6945 INIT_LIST_HEAD(&device_list);
6947 hive = amdgpu_get_xgmi_hive(adev);
6949 mutex_lock(&hive->hive_lock);
6950 list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {
6951 tmp_adev->pcie_reset_ctx.in_link_reset = false;
6952 list_add_tail(&tmp_adev->reset_list, &device_list);
6955 list_add_tail(&adev->reset_list, &device_list);
6957 amdgpu_device_sched_resume(&device_list, NULL, NULL);
6958 amdgpu_device_gpu_resume(adev, &device_list, false);
6959 amdgpu_device_recovery_put_reset_lock(adev, &device_list);
6960 adev->pcie_reset_ctx.occurs_dpc = false;
6963 mutex_unlock(&hive->hive_lock);
6964 amdgpu_put_xgmi_hive(hive);
6968 bool amdgpu_device_cache_pci_state(struct pci_dev *pdev)
6970 struct drm_device *dev = pci_get_drvdata(pdev);
6971 struct amdgpu_device *adev = drm_to_adev(dev);
6974 if (amdgpu_sriov_vf(adev))
6977 r = pci_save_state(pdev);
6979 kfree(adev->pci_state);
6981 adev->pci_state = pci_store_saved_state(pdev);
6983 if (!adev->pci_state) {
6984 DRM_ERROR("Failed to store PCI saved state");
6988 DRM_WARN("Failed to save PCI state, err:%d\n", r);
6995 bool amdgpu_device_load_pci_state(struct pci_dev *pdev)
6997 struct drm_device *dev = pci_get_drvdata(pdev);
6998 struct amdgpu_device *adev = drm_to_adev(dev);
7001 if (!adev->pci_state)
7004 r = pci_load_saved_state(pdev, adev->pci_state);
7007 pci_restore_state(pdev);
7009 DRM_WARN("Failed to load PCI state, err:%d\n", r);
7016 void amdgpu_device_flush_hdp(struct amdgpu_device *adev,
7017 struct amdgpu_ring *ring)
7019 #ifdef CONFIG_X86_64
7020 if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev))
7023 if (adev->gmc.xgmi.connected_to_cpu)
7026 if (ring && ring->funcs->emit_hdp_flush)
7027 amdgpu_ring_emit_hdp_flush(ring);
7029 amdgpu_asic_flush_hdp(adev, ring);
7032 void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev,
7033 struct amdgpu_ring *ring)
7035 #ifdef CONFIG_X86_64
7036 if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev))
7039 if (adev->gmc.xgmi.connected_to_cpu)
7042 amdgpu_asic_invalidate_hdp(adev, ring);
7045 int amdgpu_in_reset(struct amdgpu_device *adev)
7047 return atomic_read(&adev->reset_domain->in_gpu_reset);
7051 * amdgpu_device_halt() - bring hardware to some kind of halt state
7053 * @adev: amdgpu_device pointer
7055 * Bring hardware to some kind of halt state so that no one can touch it
7056 * any more. It will help to maintain error context when error occurred.
7057 * Compare to a simple hang, the system will keep stable at least for SSH
7058 * access. Then it should be trivial to inspect the hardware state and
7059 * see what's going on. Implemented as following:
7061 * 1. drm_dev_unplug() makes device inaccessible to user space(IOCTLs, etc),
7062 * clears all CPU mappings to device, disallows remappings through page faults
7063 * 2. amdgpu_irq_disable_all() disables all interrupts
7064 * 3. amdgpu_fence_driver_hw_fini() signals all HW fences
7065 * 4. set adev->no_hw_access to avoid potential crashes after setp 5
7066 * 5. amdgpu_device_unmap_mmio() clears all MMIO mappings
7067 * 6. pci_disable_device() and pci_wait_for_pending_transaction()
7068 * flush any in flight DMA operations
7070 void amdgpu_device_halt(struct amdgpu_device *adev)
7072 struct pci_dev *pdev = adev->pdev;
7073 struct drm_device *ddev = adev_to_drm(adev);
7075 amdgpu_xcp_dev_unplug(adev);
7076 drm_dev_unplug(ddev);
7078 amdgpu_irq_disable_all(adev);
7080 amdgpu_fence_driver_hw_fini(adev);
7082 adev->no_hw_access = true;
7084 amdgpu_device_unmap_mmio(adev);
7086 pci_disable_device(pdev);
7087 pci_wait_for_pending_transaction(pdev);
7090 u32 amdgpu_device_pcie_port_rreg(struct amdgpu_device *adev,
7093 unsigned long flags, address, data;
7096 address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
7097 data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
7099 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
7100 WREG32(address, reg * 4);
7101 (void)RREG32(address);
7103 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
7107 void amdgpu_device_pcie_port_wreg(struct amdgpu_device *adev,
7110 unsigned long flags, address, data;
7112 address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
7113 data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
7115 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
7116 WREG32(address, reg * 4);
7117 (void)RREG32(address);
7120 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
7124 * amdgpu_device_get_gang - return a reference to the current gang
7125 * @adev: amdgpu_device pointer
7127 * Returns: A new reference to the current gang leader.
7129 struct dma_fence *amdgpu_device_get_gang(struct amdgpu_device *adev)
7131 struct dma_fence *fence;
7134 fence = dma_fence_get_rcu_safe(&adev->gang_submit);
7140 * amdgpu_device_switch_gang - switch to a new gang
7141 * @adev: amdgpu_device pointer
7142 * @gang: the gang to switch to
7144 * Try to switch to a new gang.
7145 * Returns: NULL if we switched to the new gang or a reference to the current
7148 struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
7149 struct dma_fence *gang)
7151 struct dma_fence *old = NULL;
7153 dma_fence_get(gang);
7156 old = amdgpu_device_get_gang(adev);
7160 if (!dma_fence_is_signaled(old)) {
7161 dma_fence_put(gang);
7165 } while (cmpxchg((struct dma_fence __force **)&adev->gang_submit,
7169 * Drop it once for the exchanged reference in adev and once for the
7170 * thread local reference acquired in amdgpu_device_get_gang().
7178 * amdgpu_device_enforce_isolation - enforce HW isolation
7179 * @adev: the amdgpu device pointer
7180 * @ring: the HW ring the job is supposed to run on
7181 * @job: the job which is about to be pushed to the HW ring
7183 * Makes sure that only one client at a time can use the GFX block.
7184 * Returns: The dependency to wait on before the job can be pushed to the HW.
7185 * The function is called multiple times until NULL is returned.
7187 struct dma_fence *amdgpu_device_enforce_isolation(struct amdgpu_device *adev,
7188 struct amdgpu_ring *ring,
7189 struct amdgpu_job *job)
7191 struct amdgpu_isolation *isolation = &adev->isolation[ring->xcp_id];
7192 struct drm_sched_fence *f = job->base.s_fence;
7193 struct dma_fence *dep;
7198 * For now enforce isolation only for the GFX block since we only need
7199 * the cleaner shader on those rings.
7201 if (ring->funcs->type != AMDGPU_RING_TYPE_GFX &&
7202 ring->funcs->type != AMDGPU_RING_TYPE_COMPUTE)
7206 * All submissions where enforce isolation is false are handled as if
7207 * they come from a single client. Use ~0l as the owner to distinct it
7208 * from kernel submissions where the owner is NULL.
7210 owner = job->enforce_isolation ? f->owner : (void *)~0l;
7212 mutex_lock(&adev->enforce_isolation_mutex);
7215 * The "spearhead" submission is the first one which changes the
7216 * ownership to its client. We always need to wait for it to be
7217 * pushed to the HW before proceeding with anything.
7219 if (&f->scheduled != isolation->spearhead &&
7220 !dma_fence_is_signaled(isolation->spearhead)) {
7221 dep = isolation->spearhead;
7225 if (isolation->owner != owner) {
7228 * Wait for any gang to be assembled before switching to a
7229 * different owner or otherwise we could deadlock the
7232 if (!job->gang_submit) {
7233 dep = amdgpu_device_get_gang(adev);
7234 if (!dma_fence_is_signaled(dep))
7235 goto out_return_dep;
7239 dma_fence_put(isolation->spearhead);
7240 isolation->spearhead = dma_fence_get(&f->scheduled);
7241 amdgpu_sync_move(&isolation->active, &isolation->prev);
7242 trace_amdgpu_isolation(isolation->owner, owner);
7243 isolation->owner = owner;
7247 * Specifying the ring here helps to pipeline submissions even when
7248 * isolation is enabled. If that is not desired for testing NULL can be
7249 * used instead of the ring to enforce a CPU round trip while switching
7252 dep = amdgpu_sync_peek_fence(&isolation->prev, ring);
7253 r = amdgpu_sync_fence(&isolation->active, &f->finished, GFP_NOWAIT);
7255 DRM_WARN("OOM tracking isolation\n");
7260 mutex_unlock(&adev->enforce_isolation_mutex);
7264 bool amdgpu_device_has_display_hardware(struct amdgpu_device *adev)
7266 switch (adev->asic_type) {
7267 #ifdef CONFIG_DRM_AMDGPU_SI
7271 /* chips with no display hardware */
7273 #ifdef CONFIG_DRM_AMDGPU_SI
7279 #ifdef CONFIG_DRM_AMDGPU_CIK
7288 case CHIP_POLARIS10:
7289 case CHIP_POLARIS11:
7290 case CHIP_POLARIS12:
7294 /* chips with display hardware */
7298 if (!amdgpu_ip_version(adev, DCE_HWIP, 0) ||
7299 (adev->harvest_ip_mask & AMD_HARVEST_IP_DMU_MASK))
7305 uint32_t amdgpu_device_wait_on_rreg(struct amdgpu_device *adev,
7306 uint32_t inst, uint32_t reg_addr, char reg_name[],
7307 uint32_t expected_value, uint32_t mask)
7311 uint32_t tmp_ = RREG32(reg_addr);
7312 uint32_t loop = adev->usec_timeout;
7314 while ((tmp_ & (mask)) != (expected_value)) {
7316 loop = adev->usec_timeout;
7320 tmp_ = RREG32(reg_addr);
7323 DRM_WARN("Register(%d) [%s] failed to reach value 0x%08x != 0x%08xn",
7324 inst, reg_name, (uint32_t)expected_value,
7325 (uint32_t)(tmp_ & (mask)));
7333 ssize_t amdgpu_get_soft_full_reset_mask(struct amdgpu_ring *ring)
7337 if (!ring || !ring->adev)
7340 if (amdgpu_device_should_recover_gpu(ring->adev))
7341 size |= AMDGPU_RESET_TYPE_FULL;
7343 if (unlikely(!ring->adev->debug_disable_soft_recovery) &&
7344 !amdgpu_sriov_vf(ring->adev) && ring->funcs->soft_recovery)
7345 size |= AMDGPU_RESET_TYPE_SOFT_RESET;
7350 ssize_t amdgpu_show_reset_mask(char *buf, uint32_t supported_reset)
7354 if (supported_reset == 0) {
7355 size += sysfs_emit_at(buf, size, "unsupported");
7356 size += sysfs_emit_at(buf, size, "\n");
7361 if (supported_reset & AMDGPU_RESET_TYPE_SOFT_RESET)
7362 size += sysfs_emit_at(buf, size, "soft ");
7364 if (supported_reset & AMDGPU_RESET_TYPE_PER_QUEUE)
7365 size += sysfs_emit_at(buf, size, "queue ");
7367 if (supported_reset & AMDGPU_RESET_TYPE_PER_PIPE)
7368 size += sysfs_emit_at(buf, size, "pipe ");
7370 if (supported_reset & AMDGPU_RESET_TYPE_FULL)
7371 size += sysfs_emit_at(buf, size, "full ");
7373 size += sysfs_emit_at(buf, size, "\n");