From patchwork Fri Jul 15 13:12:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 9234171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4657160756 for ; Mon, 18 Jul 2016 07:55:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39910212D9 for ; Mon, 18 Jul 2016 07:55:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D39E269E2; Mon, 18 Jul 2016 07:55:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F01D212D9 for ; Mon, 18 Jul 2016 07:55:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 37CB26E273; Mon, 18 Jul 2016 07:54:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.lekensteyn.nl (mail.lekensteyn.nl [IPv6:2a02:2308::360:1:25]) by gabe.freedesktop.org (Postfix) with ESMTPS id 82D5D6EA0C; Fri, 15 Jul 2016 13:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2015-q1; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=0eD6SO2qGgA7QhBGADFQyV0beH/Hh/JXMnziML5H6ag=; b=xPB7zIIiZv1TA/H9CcR7VmN2xZU4Thc1OWE6pojvXOuL6WFHxzNZk2HeqGwVfFBgFqRW+Is4tnfigPTld+7qK+YyeUD7AwvY0FfLuVbwcyUqXgagAlvfJBSoIO5G1kbTjA3Bwqu04eVjhx6v7g37Gr6xIItreW7ol5PKNH/Q0EZxh7DthQww+uxw+KEO1ANeUGaet4n9w23BOsGg4AK8gszUf0FRbe1+oGSduniLvmjjtisxJGgYhieme9ZnEmtigDLYUCoBQTDiPSIxyLEPvhAzcBWu4zb0+GcTN6N8YXH8pa9W6TRbw8EGwqTZ+7LffLWv6kefFJ2LeMS8aej5NA==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1bO2vC-0002AX-9O; Fri, 15 Jul 2016 15:12:50 +0200 From: Peter Wu To: Dave Airlie Subject: [PATCH v3 3/4] drm/nouveau/acpi: check for function 0x1B before using it Date: Fri, 15 Jul 2016 15:12:17 +0200 Message-Id: <20160715131218.2416-4-peter@lekensteyn.nl> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160715131218.2416-1-peter@lekensteyn.nl> References: <20160715131218.2416-1-peter@lekensteyn.nl> X-Mailman-Approved-At: Mon, 18 Jul 2016 07:54:40 +0000 Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Do not unconditionally invoke function 0x1B without checking for its availability, it leads to an infinite loop on some firmware. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=104791 Fixes: 5addcf0a5f0fad ("nouveau: add runtime PM support (v0.9)") Reviewed-by: Hans de Goede Signed-off-by: Peter Wu --- drivers/gpu/drm/nouveau/nouveau_acpi.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.c b/drivers/gpu/drm/nouveau/nouveau_acpi.c index 572ac30..ad273ad 100644 --- a/drivers/gpu/drm/nouveau/nouveau_acpi.c +++ b/drivers/gpu/drm/nouveau/nouveau_acpi.c @@ -45,6 +45,7 @@ static struct nouveau_dsm_priv { bool dsm_detected; bool optimus_detected; + bool optimus_flags_detected; acpi_handle dhandle; acpi_handle rom_handle; } nouveau_dsm_priv; @@ -212,7 +213,8 @@ static const struct vga_switcheroo_handler nouveau_dsm_handler = { }; static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out, - bool *has_mux, bool *has_opt) + bool *has_mux, bool *has_opt, + bool *has_opt_flags) { acpi_handle dhandle; bool supports_mux; @@ -236,6 +238,7 @@ static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out *dhandle_out = dhandle; *has_mux = supports_mux; *has_opt = !!optimus_funcs; + *has_opt_flags = optimus_funcs & (1 << NOUVEAU_DSM_OPTIMUS_FLAGS); if (optimus_funcs) { uint32_t result; @@ -256,6 +259,7 @@ static bool nouveau_dsm_detect(void) acpi_handle dhandle = NULL; bool has_mux = false; bool has_optimus = false; + bool has_optimus_flags = false; int vga_count = 0; bool guid_valid; bool ret = false; @@ -270,13 +274,15 @@ static bool nouveau_dsm_detect(void) while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) { vga_count++; - nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus); + nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus, + &has_optimus_flags); } while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) { vga_count++; - nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus); + nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus, + &has_optimus_flags); } /* find the optimus DSM or the old v1 DSM */ @@ -287,6 +293,7 @@ static bool nouveau_dsm_detect(void) printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n", acpi_method_name); nouveau_dsm_priv.optimus_detected = true; + nouveau_dsm_priv.optimus_flags_detected = has_optimus_flags; ret = true; } else if (vga_count == 2 && has_mux && guid_valid) { nouveau_dsm_priv.dhandle = dhandle; @@ -320,8 +327,9 @@ void nouveau_switcheroo_optimus_dsm(void) if (!nouveau_dsm_priv.optimus_detected) return; - nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FLAGS, - 0x3, &result); + if (nouveau_dsm_priv.optimus_flags_detected) + nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FLAGS, + 0x3, &result); nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);