linux_dsm_epyc7002/drivers/gpu/drm/radeon
Lukas Wunner 07f4f97d7b vga_switcheroo: Use device link for HDA controller
Back in 2013, runtime PM for GPUs with integrated HDA controller was
introduced with commits 0d69704ae3 ("gpu/vga_switcheroo: add driver
control power feature. (v3)") and 246efa4a07 ("snd/hda: add runtime
suspend/resume on optimus support (v4)").

Briefly, the idea was that the HDA controller is forced on and off in
unison with the GPU.

The original code is mostly still in place even though it was never a
100% perfect solution:  E.g. on access to the HDA controller, the GPU
is powered up via vga_switcheroo_runtime_resume_hdmi_audio() but there
are no provisions to keep it resumed until access to the HDA controller
has ceased:  The GPU autosuspends after 5 seconds, rendering the HDA
controller inaccessible.

Additionally, a kludge is required when hda_intel.c probes:  It has to
check whether the GPU is powered down (check_hdmi_disabled()) and defer
probing if so.

However in the meantime (in v4.10) the driver core has gained a feature
called device links which promises to solve such issues in a clean way:
It allows us to declare a dependency from the HDA controller (consumer)
to the GPU (supplier).  The PM core then automagically ensures that the
GPU is runtime resumed as long as the HDA controller's ->probe hook is
executed and whenever the HDA controller is accessed.

By default, the HDA controller has a dependency on its parent, a PCIe
Root Port.  Adding a device link creates another dependency on its
sibling:

                            PCIe Root Port
                             ^          ^
                             |          |
                             |          |
                            HDA  ===>  GPU

The device link is not only used for runtime PM, it also guarantees that
on system sleep, the HDA controller suspends before the GPU and resumes
after the GPU, and on system shutdown the HDA controller's ->shutdown
hook is executed before the one of the GPU.  It is a complete solution.

Using this functionality is as simple as calling device_link_add(),
which results in a dmesg entry like this:

        pci 0000:01:00.1: Linked as a consumer to 0000:01:00.0

The code for the GPU-governed audio power management can thus be removed
(except where it's still needed for legacy manual power control).

The device link is added in a PCI quirk rather than in hda_intel.c.
It is therefore legal for the GPU to runtime suspend to D3cold even if
the HDA controller is not bound to a driver or if CONFIG_SND_HDA_INTEL
is not enabled, for accesses to the HDA controller will cause the GPU to
wake up regardless if they're occurring outside of hda_intel.c (think
config space readout via sysfs).

Contrary to the previous implementation, the HDA controller's power
state is now self-governed, rather than GPU-governed, whereas the GPU's
power state is no longer fully self-governed.  (The HDA controller needs
to runtime suspend before the GPU can.)

It is thus crucial that runtime PM is always activated on the HDA
controller even if CONFIG_SND_HDA_POWER_SAVE_DEFAULT is set to 0 (which
is the default), lest the GPU stays awake.  This is achieved by setting
the auto_runtime_pm flag on every codec and the AZX_DCAPS_PM_RUNTIME
flag on the HDA controller.

A side effect is that power consumption might be reduced if the GPU is
in use but the HDA controller is not, because the HDA controller is now
allowed to go to D3hot.  Before, it was forced to stay in D0 as long as
the GPU was in use.  (There is no reduction in power consumption on my
Nvidia GK107, but there might be on other chips.)

The code paths for legacy manual power control are adjusted such that
runtime PM is disabled during power off, thereby preventing the PM core
from resuming the HDA controller.

Note that the device link is not only added on vga_switcheroo capable
systems, but for *any* GPU with integrated HDA controller.  The idea is
that the HDA controller streams audio via connectors located on the GPU,
so the GPU needs to be on for the HDA controller to do anything useful.

This commit implicitly fixes an unbalanced runtime PM ref upon unbind of
hda_intel.c:  On ->probe, a runtime PM ref was previously released under
the condition "azx_has_pm_runtime(chip) || hda->use_vga_switcheroo", but
on ->remove a runtime PM ref was only acquired under the first of those
conditions.  Thus, binding and unbinding the driver twice on a
vga_switcheroo capable system caused the runtime PM refcount to drop
below zero.  The issue is resolved because the AZX_DCAPS_PM_RUNTIME flag
is now always set if use_vga_switcheroo is true.

For more information on device links please refer to:
https://www.kernel.org/doc/html/latest/driver-api/device_link.html
Documentation/driver-api/device_link.rst

Cc: Dave Airlie <airlied@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Kai Heng Feng <kai.heng.feng@canonical.com> # AMD PowerXpress
Tested-by: Mike Lothian <mike@fireburn.co.uk>          # AMD PowerXpress
Tested-by: Denis Lisov <dennis.lissov@gmail.com>       # Nvidia Optimus
Tested-by: Peter Wu <peter@lekensteyn.nl>              # Nvidia Optimus
Tested-by: Lukas Wunner <lukas@wunner.de>              # MacBook Pro
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Link: https://patchwork.freedesktop.org/patch/msgid/51bd38360ff502a8c42b1ebf4405ee1d3f27118d.1520068884.git.lukas@wunner.de
2018-03-13 22:58:09 +01:00
..
reg_srcs
.gitignore
atom-bits.h
atom-names.h
atom-types.h
atom.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
atom.h
atombios_crtc.c drm: radeon: remove dead code and pointless local lut storage 2017-08-04 11:36:17 +02:00
atombios_dp.c drm/radeon: fix atombios on big endian 2017-10-31 18:24:59 -04:00
atombios_encoders.c drm/radeon: Fix eDP for single-display iMac10,1 (v2) 2017-07-07 11:11:28 -04:00
atombios_i2c.c
atombios.h scripts/spelling.txt: add "aligment" pattern and fix typo instances 2017-02-27 18:43:46 -08:00
avivod.h
btc_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
btc_dpm.h
btcd.h
cayman_blit_shaders.c
cayman_blit_shaders.h
ci_dpm.c drm/radeon: move ci_send_msg_to_smc to where it's used 2017-10-08 20:16:28 -04:00
ci_dpm.h drm/radeon: move ci_send_msg_to_smc to where it's used 2017-10-08 20:16:28 -04:00
ci_smc.c drm/radeon: move ci_send_msg_to_smc to where it's used 2017-10-08 20:16:28 -04:00
cik_blit_shaders.c
cik_blit_shaders.h
cik_reg.h drm/radeon: Remove KFD_CIK_SDMA_QUEUE_OFFSET 2017-12-20 12:00:22 -05:00
cik_sdma.c
cik.c Revert "drm/radeon: reduce number of free VMIDs and pipes in KV" 2017-12-20 12:00:15 -05:00
cikd.h drm/radeon: deprecate and remove KFD interface 2017-10-30 14:16:21 +01:00
clearstate_cayman.h
clearstate_ci.h
clearstate_defs.h
clearstate_evergreen.h
clearstate_si.h
cypress_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
cypress_dpm.h
dce3_1_afmt.c
dce6_afmt.c
evergreen_blit_shaders.c
evergreen_blit_shaders.h
evergreen_cs.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
evergreen_dma.c
evergreen_hdmi.c
evergreen_reg.h
evergreen_smc.h
evergreen.c drm/radeon: fill in rb backend map on evergreen/ni. 2018-01-16 15:35:28 -05:00
evergreend.h
Kconfig
kv_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
kv_dpm.h
kv_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
Makefile main drm pull request for v4.15 2017-11-15 20:42:10 -08:00
mkregtable.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ni_dma.c
ni_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
ni_dpm.h
ni_reg.h
ni.c drm/radeon: fill in rb backend map on evergreen/ni. 2018-01-16 15:35:28 -05:00
nid.h
nislands_smc.h
ObjectID.h
ppsmc.h
pptable.h
r100_track.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
r100.c drm: Pass struct drm_file * to __drm_mode_object_find [v2] 2017-10-12 10:03:04 +10:00
r100d.h
r200.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
r300_reg.h
r300.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
r300d.h
r420.c drm/radeon: check return value of radeon_ring_lock 2017-04-28 17:33:02 -04:00
r420d.h
r500_reg.h
r520.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
r520d.h
r600_blit_shaders.c
r600_blit_shaders.h
r600_cs.c drm: Pass struct drm_file * to __drm_mode_object_find [v2] 2017-10-12 10:03:04 +10:00
r600_dma.c
r600_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
r600_dpm.h
r600_hdmi.c drm/radeon: properly initialize r600_audio_status() data 2017-09-18 23:30:30 -04:00
r600_reg.h
r600.c drm/radeon: Unbreak HPD handling for r600+ 2017-05-24 17:39:33 -04:00
r600d.h
radeon_acpi.c drm/radeon: Make radeon_atif_handler static 2017-08-15 14:46:07 -04:00
radeon_acpi.h drm/radeon: Make radeon_atif_handler static 2017-08-15 14:46:07 -04:00
radeon_agp.c
radeon_asic.c
radeon_asic.h
radeon_atombios.c
radeon_atpx_handler.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
radeon_audio.c drm: handle HDMI 2.0 VICs in AVI info-frames 2017-07-14 21:23:54 +03:00
radeon_audio.h
radeon_benchmark.c
radeon_bios.c
radeon_clocks.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
radeon_combios.c drm/radeon: add a quirk for Toshiba Satellite L20-183 2017-06-20 12:06:51 -04:00
radeon_connectors.c Merge airlied/drm-next into drm-misc-next 2017-11-21 14:17:56 +01:00
radeon_cs.c drm/radeon: Fix preferred typo 2017-08-15 14:46:16 -04:00
radeon_cursor.c drm/radeon: switch to drm_*{get,put} helpers 2017-08-15 14:46:12 -04:00
radeon_device.c drm/radeon: only enable swiotlb path when need v2 2018-02-13 13:35:14 -05:00
radeon_display.c drm/radeon: Use drm_fb_helper_lastclose() and _poll_changed() 2017-12-06 12:48:34 -05:00
radeon_dp_auxch.c drm/radeon/dp_auxch: Ratelimit aux transfer debug messages 2017-03-29 23:53:21 -04:00
radeon_dp_mst.c drm/radeon: fix sparse warning: Should it be static? 2018-01-16 15:23:30 -05:00
radeon_drv.c vga_switcheroo: Use device link for HDA controller 2018-03-13 22:58:09 +01:00
radeon_drv.h
radeon_encoders.c
radeon_family.h
radeon_fb.c drm/radeon: Use drm_fb_helper_lastclose() and _poll_changed() 2017-12-06 12:48:34 -05:00
radeon_fence.c sched/wait: Rename wait_queue_t => wait_queue_entry_t 2017-06-20 12:18:27 +02:00
radeon_gart.c drm: use set_memory.h header 2017-05-08 17:15:14 -07:00
radeon_gem.c drm/ttm: add operation ctx to ttm_bo_validate v2 2017-12-06 12:48:01 -05:00
radeon_i2c.c
radeon_ib.c
radeon_irq_kms.c Merge branch 'drm-next-4.14' of git://people.freedesktop.org/~agd5f/linux into drm-next 2017-08-02 12:43:12 +10:00
radeon_kms.c drm/radeon: Use drm_fb_helper_lastclose() and _poll_changed() 2017-12-06 12:48:34 -05:00
radeon_legacy_crtc.c drm: radeon: remove dead code and pointless local lut storage 2017-08-04 11:36:17 +02:00
radeon_legacy_encoders.c
radeon_legacy_tv.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
radeon_mn.c drm/ttm: add operation ctx to ttm_bo_validate v2 2017-12-06 12:48:01 -05:00
radeon_mode.h drm/radeon: Use drm_fb_helper_lastclose() and _poll_changed() 2017-12-06 12:48:34 -05:00
radeon_object.c drm/ttm: add operation ctx to ttm_bo_validate v2 2017-12-06 12:48:01 -05:00
radeon_object.h
radeon_pm.c
radeon_prime.c drm/radeon: Maintain prime import/export refcount for BOs 2017-04-07 12:20:40 -04:00
radeon_reg.h
radeon_ring.c drm: drop drm_[cm]alloc* helpers 2017-05-18 17:22:39 +02:00
radeon_sa.c
radeon_semaphore.c
radeon_sync.c
radeon_test.c drm/radeon: check return value of radeon_fence_emit 2017-04-28 17:33:02 -04:00
radeon_trace_points.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
radeon_trace.h main drm pull request for v4.15 2017-11-15 20:42:10 -08:00
radeon_ttm.c drm/radeon: only enable swiotlb path when need v2 2018-02-13 13:35:14 -05:00
radeon_ucode.c
radeon_ucode.h
radeon_uvd.c drm/radeon: adjust tested variable 2018-01-29 23:18:17 -05:00
radeon_vce.c
radeon_vm.c drm/ttm: add operation ctx to ttm_bo_validate v2 2017-12-06 12:48:01 -05:00
radeon.h drm/radeon: only enable swiotlb path when need v2 2018-02-13 13:35:14 -05:00
rs100d.h
rs400.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
rs400d.h
rs600.c
rs600d.h
rs690.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
rs690d.h
rs780_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
rs780_dpm.h
rs780d.h
rv6xx_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
rv6xx_dpm.h
rv6xxd.h
rv200d.h
rv250d.h
rv350d.h
rv515.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
rv515d.h
rv730_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
rv730d.h
rv740_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
rv740d.h
rv770_dma.c
rv770_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
rv770_dpm.h
rv770_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
rv770_smc.h
rv770.c
rv770d.h
si_blit_shaders.c
si_blit_shaders.h
si_dma.c
si_dpm.c drm/radeon: Add dpm quirk for Jet PRO (v2) 2018-01-10 15:44:14 -05:00
si_dpm.h
si_reg.h
si_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
si.c Linux 4.12-rc7 2017-06-27 08:28:30 +10:00
sid.h
sislands_smc.h
smu7_discrete.h
smu7_fusion.h
smu7.h
sumo_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
sumo_dpm.h
sumo_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
sumod.h
trinity_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
trinity_dpm.h
trinity_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
trinityd.h
uvd_v1_0.c
uvd_v2_2.c
uvd_v3_1.c
uvd_v4_2.c
vce_v1_0.c
vce_v2_0.c drm/radeon: add header comment for clarification to vce_v2_0_enable_mgcg() 2017-07-14 11:05:55 -04:00