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: 114566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10122889vqr; Thu, 29 Jun 2023 22:41:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlHdZOUX5aNSSODwibRe3e7pAKPp8v+ceTAgo4kCb/AjUrwgo/KVekOET/EjH+z8wNSo/ysl X-Received: by 2002:a17:90a:4285:b0:263:2312:60c2 with SMTP id p5-20020a17090a428500b00263231260c2mr1598522pjg.3.1688103710475; Thu, 29 Jun 2023 22:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688103710; cv=none; d=google.com; s=arc-20160816; b=QTxDq8sfqlYhx94FUGVMofRsl11Z+eWrWz5GbiFCf5R37WkQvwxI2+1DlvSzPecUFT IC27U0Y1dtsq6p/w5q/rrBy/BJ3gFhTOGuYLF6226Y5+jhZIVo+QYugevHX4N6cE8W7M Q7AcEqVYsQ1v3j6K8UQXqSn3n6zzD3yl424PdC6/HsXwPcX6GzmAenssZ0DeegpkKmiW qbehoIwAmCJDQmL746Drb11H7Vu9uGVlXBtRF2UuMWvE/yrzrS+7PytyyT0BRkf/A/wt 5GJ0s3yNsMCg8lu+VMQeufethzOJDfo2jUFXEVf5qdd1E6sHFd3vp66BiqlEhoLJ+Vbm mq8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=bWv6npFXhdXxLcYc0Px3FglQvMChhuV4rcjQEuBLYbk=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=0M6w3TVfHvbSGRMwFnAyqkZ2ncNK1ve89X8kNcif3diFEginDPjA6uz4y/mFJfbbbH vcxUpbczlBmG3t9U5eB3YFf4zMutJ22uK0VYjpTsVSdXnwUel/vH552AHZeit1r0cdUA DQPuOdQs17aAEbNIFieQArH9Fo+n9N5Af4y5QywPN6fpvaOuZuLJ5jAkUTcwERH1RnUL 3pBBrNR0OwZOjSCcx4/cRxxXWWbIUggEPnxNwH4laXITJxyrtVgMB8gBlZsQ2BpsqDvz hZXhn83Ns+OPB9Vlh5YgFJ9fz1AiyvuBiTzd2ZKsl39PHm04rgbXH7fu7MfMpWakkJCe 9Drw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b="YZk/LMaq"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=OAbS+R0y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k191-20020a6384c8000000b0055336060f9csi12292014pgd.376.2023.06.29.22.41.35; Thu, 29 Jun 2023 22:41:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b="YZk/LMaq"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=OAbS+R0y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232262AbjF3Fgm (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:42 -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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770105036482042222?= X-GMAIL-MSGID: =?utf-8?q?1770105036482042222?= 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);