1
0
Fork 0
alistair23-linux/sound/pci
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
..
ac97 scripts/spelling.txt: add "swith" pattern and fix typo instances 2017-02-27 18:43:46 -08:00
ali5451 ALSA: ali5451: constify snd_pcm_ops structures 2017-08-10 17:56:04 +02:00
asihpi ASoC: Updates for v4.15 2017-11-13 15:45:57 +01:00
au88x0 ASoC: Updates for v4.15 2017-11-13 15:45:57 +01:00
aw2 ALSA: aw2: make snd_pcm_hardware const 2017-08-12 23:31:39 +02:00
ca0106 ALSA: ca0106: Delete an error message for a failed memory allocation in snd_ca0106_pcm_open_capture_channel() 2017-08-12 23:33:54 +02:00
cs46xx ALSA: cs46xx: make snd_pcm_hardware const 2017-08-12 23:31:41 +02:00
cs5535audio License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ctxfi ASoC: Updates for v4.15 2017-11-13 15:45:57 +01:00
echoaudio ASoC: Updates for v4.15 2017-11-13 15:45:57 +01:00
emu10k1 ASoC: Updates for v4.15 2017-11-13 15:45:57 +01:00
hda vga_switcheroo: Use device link for HDA controller 2018-03-13 22:58:09 +01:00
ice1712 ALSA: ice1724: Fix resume issues with Prodigy 7.1 HiFi 2017-11-29 09:30:11 +01:00
korg1212 ALSA: korg1212: Delete a duplicate function call "release_firmware" in snd_korg1212_create() 2017-11-29 09:29:41 +01:00
lola ALSA: lola: make snd_pcm_hardware const 2017-08-12 23:31:46 +02:00
lx6464es ALSA: lx6464es: make snd_pcm_hardware const 2017-08-12 23:31:48 +02:00
mixart ALSA: mixart: Delete an error message for a failed memory allocation in snd_mixart_create() 2017-08-12 23:33:20 +02:00
nm256 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
oxygen ASoC: Updates for v4.15 2017-11-13 15:45:57 +01:00
pcxhr ALSA: pcxhr: make snd_kcontrol_new const 2017-08-16 14:29:07 +02:00
riptide ALSA: riptide: make snd_pcm_hardware const 2017-08-12 23:31:53 +02:00
rme9652 ASoC: Updates for v4.15 2017-11-13 15:45:57 +01:00
trident ALSA: trident: make snd_pcm_hardware const 2017-08-12 23:31:55 +02:00
vx222 ALSA: vx222: Use container_of() 2017-05-15 11:21:05 +02:00
ymfpci ALSA: ymfpci: Use common error handling code in snd_ymfpci_create() 2017-09-07 10:33:28 +02:00
Kconfig ALSA: seq: Allow the modular sequencer registration 2017-06-12 08:43:33 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ad1889.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
ad1889.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ak4531_codec.c ALSA: pci: Drop superfluous ifdef CONFIG_PROC_FS 2015-05-29 08:00:06 +02:00
als300.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
als4000.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
atiixp.c ALSA: atiixp: constify ac97_pcm structures 2017-08-23 15:53:39 +02:00
atiixp_modem.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
azt3328.c ALSA: azt3328: Constify hw_constraints 2017-06-09 10:42:49 +02:00
azt3328.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
bt87x.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
cmipci.c ALSA: cmipci: Use common error handling code in snd_cmipci_probe() 2017-08-22 20:06:10 +02:00
cs4281.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
cs5530.c ASoC: sb16: Simplify snd_sb16dsp_pcm() 2015-01-02 16:28:35 +01:00
ens1370.c ALSA: ens137x: remove redundant variable result 2017-10-16 13:36:24 +02:00
ens1371.c
es1938.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
es1968.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
fm801.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
intel8x0.c ALSA: intel8x0: constify ac97_pcm structures 2017-08-23 15:53:40 +02:00
intel8x0m.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
maestro3.c ALSA: maestro3: Use common error handling code in two functions 2017-09-07 10:23:47 +02:00
rme32.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
rme96.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
sis7019.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
sis7019.h trivial: fix typos s/paramter/parameter/ and s/excute/execute/ in documentation and source comments. 2009-06-12 18:01:46 +02:00
sonicvibes.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
via82xx.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00
via82xx_modem.c ALSA: pci: make snd_pcm_hardware const 2017-08-12 23:31:58 +02:00