nouveau.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Ratchanan Srirattanamet <peathot@hotmail.com>
To: bskeggs@redhat.com
Cc: nouveau@lists.freedesktop.org,
	Ratchanan Srirattanamet <peathot@hotmail.com>
Subject: [Nouveau] [PATCH] drm/nouveau: don't touch has_pr3 for likely-non-NVIDIA device
Date: Sun, 18 Jul 2021 01:02:41 +0700	[thread overview]
Message-ID: <DM6PR19MB278063772C30271C6B8929B5BC109@DM6PR19MB2780.namprd19.prod.outlook.com> (raw)

The call site of nouveau_dsm_pci_probe() uses single set of output
variables for all invocations. So, we must not write anything to them
until we think this is an NVIDIA device of interest. Otherwise, if we
are called with another device after the NVIDIA device, we'll clober the
result of the NVIDIA device.

In this case, if the other device doesn't have _PR3 resources, the
detection later would miss the presence of power resource support, and
the rest of the code will keep using Optimus DSM, breaking power
management for that machine. In particular, this fixes power management
of the NVIDIA card in Lenovo Legion 5-15ARH05... well, at least
partially. New error shows up, but this patch is correct in itself
anyway.

As a bonus, we'll also stop preventing _PR3 usage from the bridge for
unrelated devices, which is always nice, I guess.

As noted in commit ccfc2d5cdb024 ("drm/nouveau: Use generic helper to
check _PR3 presence"), care is taken to leave the _PR3 detection outside
of the optimus_func condition.

https://gitlab.freedesktop.org/drm/nouveau/-/issues/79

Fixes: ccfc2d5cdb024 ("drm/nouveau: Use generic helper to check _PR3
presence")
Signed-off-by: Ratchanan Srirattanamet <peathot@hotmail.com>
---

Hello,

This is my first time submitting a Linux patch. I've done a
number of PR/MR workflows on GitHub or GitLab, but never done any
email-oriented development. So, please excuse me if I'm doing something
incorrectly.

 drivers/gpu/drm/nouveau/nouveau_acpi.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.c b/drivers/gpu/drm/nouveau/nouveau_acpi.c
index 7c15f6448428..c88bda3ac820 100644
--- a/drivers/gpu/drm/nouveau/nouveau_acpi.c
+++ b/drivers/gpu/drm/nouveau/nouveau_acpi.c
@@ -220,15 +220,6 @@ static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out
 	int optimus_funcs;
 	struct pci_dev *parent_pdev;
 
-	*has_pr3 = false;
-	parent_pdev = pci_upstream_bridge(pdev);
-	if (parent_pdev) {
-		if (parent_pdev->bridge_d3)
-			*has_pr3 = pci_pr3_present(parent_pdev);
-		else
-			pci_d3cold_disable(pdev);
-	}
-
 	dhandle = ACPI_HANDLE(&pdev->dev);
 	if (!dhandle)
 		return;
@@ -249,6 +240,15 @@ static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out
 	*has_opt = !!optimus_funcs;
 	*has_opt_flags = optimus_funcs & (1 << NOUVEAU_DSM_OPTIMUS_FLAGS);
 
+	*has_pr3 = false;
+	parent_pdev = pci_upstream_bridge(pdev);
+	if (parent_pdev) {
+		if (parent_pdev->bridge_d3)
+			*has_pr3 = pci_pr3_present(parent_pdev);
+		else
+			pci_d3cold_disable(pdev);
+	}
+
 	if (optimus_funcs) {
 		uint32_t result;
 		nouveau_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, 0,
-- 
2.25.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

             reply	other threads:[~2021-07-22  3:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-17 18:02 Ratchanan Srirattanamet [this message]
2021-07-22 16:36 ` [Nouveau] [PATCH] drm/nouveau: don't touch has_pr3 for likely-non-NVIDIA device Karol Herbst
2021-07-22 19:49   ` Ratchanan Srirattanamet
2021-07-22 19:54     ` Karol Herbst
2021-07-22 19:57       ` Karol Herbst
2021-07-27 12:11 ` Karol Herbst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM6PR19MB278063772C30271C6B8929B5BC109@DM6PR19MB2780.namprd19.prod.outlook.com \
    --to=peathot@hotmail.com \
    --cc=bskeggs@redhat.com \
    --cc=nouveau@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).