From patchwork Fri Jun 30 05:35:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13297615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1B73EB64D7 for ; Fri, 30 Jun 2023 05:36:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232268AbjF3Fgl (ORCPT ); Fri, 30 Jun 2023 01:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbjF3Fgf (ORCPT ); Fri, 30 Jun 2023 01:36:35 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F83E3585; Thu, 29 Jun 2023 22:36:34 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id A4C70320098C; Fri, 30 Jun 2023 01:36:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 30 Jun 2023 01:36:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1688103392; x= 1688189792; bh=bWv6npFXhdXxLcYc0Px3FglQvMChhuV4rcjQEuBLYbk=; b=Y Zk/LMaq/CDrkbNzgDOA8FxLB5xK1jRPgdPxfsIs/aHcNnCDkvLGqcQyjvRwIX7MX ay2npQQYjLAPqYzHc66CH3T2VrS+IlPAjjNCLatrRuJ4HCTSM7Bz6BHbc8ZBOq0/ PAAZVweeItWkFIY3cq52OC+OAO9kcpsF2Nex2sEF6oMbYxvi5Uh6HSnVLXVQMD/L hN1f7l5SQ1SpCQDG5aWgitevI/wbnA4N6TjHeuXo4Bnsn0m79JXFncAN4jSAfqzI XGFc5S9K9QgxTNwqFlUdInVwEZmN3yykCE5bG1BMJUe5fa6jWvocI/N6xQChkgdv gvP4X2jLGoFLnSORwZiBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1688103392; x= 1688189792; bh=bWv6npFXhdXxLcYc0Px3FglQvMChhuV4rcjQEuBLYbk=; b=O AbS+R0ycqgXv4b7My5WBhW49FOY9YfxEhkTZBaMGGKpvEpUJblrT09okc81zrLiL 3vGnjs/0FmFlPSVlNPZJuG9Ha4SBjh2ydIV38WxKI/fyNokDWmPYPOLO4UnwiI/n E7KqINhoelctPCUuXYVGGZSzBkkvuY57hj/sT5at2K8eMa+kC7OMTkPyh+N2BPI4 AdseyPoKBiJylttW1s/9Id3gmkv+XjQfay0Z8tgyleCTwPbf8xLA9ZiprR8ZQXoH fjmqk10Ix/FpVCL/4LvHfCs9hAgFCdBBEWUVqbs0cn7arhqjA5HYtS1VbgYv+4L3 CBFvnALAbw1bwJRNuDElA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhj ohhnvghsrdguvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugf fgleeltedvveethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedunecu rfgrrhgrmhepmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghv X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36:28 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH v2 6/8] platform/x86: asus-wmi: add safety checks to gpu switching Date: Fri, 30 Jun 2023 17:35:50 +1200 Message-ID: <20230630053552.976579-7-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-1-luke@ljones.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add safety checking to dgpu_disable, egpu_enable, gpu_mux_mode. These checks prevent users from doing such things as: - disabling the dGPU while is muxed to drive the internal screen - enabling the eGPU which also disables the dGPU, while muxed to the internal screen - switching the MUX to dGPU while the dGPU is disabled Signed-off-by: Luke D. Jones Reviewed-by: Hans de Goede --- drivers/platform/x86/asus-wmi.c | 50 ++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 821addb284d7..602426a7fb41 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -645,6 +645,18 @@ static ssize_t dgpu_disable_store(struct device *dev, if (disable > 1) return -EINVAL; + if (asus->gpu_mux_mode_available) { + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPU_MUX); + if (result < 0) + /* An error here may signal greater failure of GPU handling */ + return result; + if (!result && disable) { + err = -ENODEV; + pr_warn("Can not disable dGPU when the MUX is in dGPU mode: %d\n", err); + return err; + } + } + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_DGPU, disable, &result); if (err) { pr_warn("Failed to set dgpu disable: %d\n", err); @@ -693,7 +705,7 @@ static ssize_t egpu_enable_store(struct device *dev, if (enable > 1) return -EINVAL; - err = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU_CONNECTED); + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU_CONNECTED); if (err < 0) return err; if (err < 1) { @@ -702,6 +714,18 @@ static ssize_t egpu_enable_store(struct device *dev, return err; } + if (asus->gpu_mux_mode_available) { + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPU_MUX); + if (result < 0) + /* An error here may signal greater failure of GPU handling */ + return result; + if (!result && enable) { + err = -ENODEV; + pr_warn("Can not enable eGPU when the MUX is in dGPU mode: %d\n", err); + return err; + } + } + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_EGPU, enable, &result); if (err) { pr_warn("Failed to set egpu disable: %d\n", err); @@ -764,6 +788,30 @@ static ssize_t gpu_mux_mode_store(struct device *dev, if (optimus > 1) return -EINVAL; + if (asus->dgpu_disable_available) { + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_DGPU); + if (result < 0) + /* An error here may signal greater failure of GPU handling */ + return result; + if (result && !optimus) { + err = -ENODEV; + pr_warn("Can not switch MUX to dGPU mode when dGPU is disabled: %d\n", err); + return err; + } + } + + if (asus->egpu_enable_available) { + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU); + if (result < 0) + /* An error here may signal greater failure of GPU handling */ + return result; + if (result && !optimus) { + err = -ENODEV; + pr_warn("Can not switch MUX to dGPU mode when eGPU is enabled: %d\n", err); + return err; + } + } + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_GPU_MUX, optimus, &result); if (err) { dev_err(dev, "Failed to set GPU MUX mode: %d\n", err);