From patchwork Tue Jun 20 02:56:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3386443vqr; Mon, 19 Jun 2023 19:59:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YXdt1J2bqvUbsjDfKKJaYCgeS1TGiX1Z8bHqdhB1P0gtO6R0UCuxcmVABCb6nYkrdTuWT X-Received: by 2002:a67:e404:0:b0:43c:381d:a04 with SMTP id d4-20020a67e404000000b0043c381d0a04mr2582432vsf.18.1687229975471; Mon, 19 Jun 2023 19:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687229975; cv=none; d=google.com; s=arc-20160816; b=RJF6LHaFWKUh44uDvnynLAw9V2Im3C/bBLjPo23qRKBc+RekMBTkwcJkNpM9qE73/I zqcl/UzOti5UsVxb60UaRowVHyC7+2J7QET8O+6Ot05IxPkEyvBMvB7M/DrFxXzgO/5l qZOqpyhNdXfeZWq2gA2iLyy/HyjngrlGDr5Ef2HgzKIbg1qVuICml3YvzBvq2uOnmBSk TjCGZiAbXCO/G+FcgT0ThsA8JmaC/8NQNMU4jMVvk+NmWCRJQtCkVn7TgnKnkH4oe6TJ PgY3D5NhW3Z3hiP58OhDxk3QLzz7lEaFPBnUO5eLENW8EXBNrGufquTcJQHBRSKaJ+zU EqiQ== 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=I8Xbl0BJKPKnoyHohJOj+6eHAELlgJ6aFeDPrAiW/Gk=; b=OENZYbNpx4Y4KsWtAB9RmHz0ML4FnF4ffC1hhXQOC2K66Mq+YqVkK9EL0tjYWqbbmR NPbKPdb1c0UI3EzqEgbbqF2/H2w7saTuD/s4fneuIiIAb/jo9H+6OQdsDb/BV504QX+p S5k39jfhHUK+05f/42EDQpnsVfI+PTGblTOx5db9HlPVjdMnB0hFqGCgpnnePuRT3C6w i/LFFkGyfjfXxTXMf7jaxFw8vZg+XEhBdZ44hFyK3nmJAFsMK2oWQckTO/DguHI/hGp+ C8HI02Z6YNfvTBgHAMoD6MjSxptDFu916L47DmHEhVs+bKtQHxBbEP/6Hv4/bUhkh4hn 6Ltw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=Ul27cz2O; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=dL1ub+6o; 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 n4-20020a63b444000000b00533fce755adsi793988pgu.130.2023.06.19.19.59.23; Mon, 19 Jun 2023 19:59:35 -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=Ul27cz2O; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=dL1ub+6o; 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 S230134AbjFTC5q (ORCPT + 99 others); Mon, 19 Jun 2023 22:57:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229683AbjFTC5k (ORCPT ); Mon, 19 Jun 2023 22:57:40 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C0510E2; Mon, 19 Jun 2023 19:57:27 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id D0CD15C01F4; Mon, 19 Jun 2023 22:57:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Jun 2023 22:57:26 -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=1687229846; x= 1687316246; bh=I8Xbl0BJKPKnoyHohJOj+6eHAELlgJ6aFeDPrAiW/Gk=; b=U l27cz2Ow6Iux71DMKTU/qE+7APTsz3GrOvM1cDM8MY4739+fnsRd+f8xQzvuJLS8 fQu6r8Jfk4NEKPsI0tjSomyKucdStsyQ0gQZ0TGTjIDJMtbOcWsc3guu4TvyVnU8 MowVi+89gVjrATf2lAG8NruSOpjWOGXHZDRtAM2aTlz1vjJrZrkWJ/z6XLLND7gy OtRph6CyDLQSmWu9b/ZJmLbFQ75uLIBVYubeucK8EK0ZA3kytnNK+IR3mjdR9km2 pMsO7kGRQu9s4KC0I046HwuGFERmgLFdJE+TKs5/tn9k6MuF5FZ0ZYQ5eLBHQEoz aTCeDlqCgbLNz8Hb18TkQ== 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=1687229846; x= 1687316246; bh=I8Xbl0BJKPKnoyHohJOj+6eHAELlgJ6aFeDPrAiW/Gk=; b=d L1ub+6ozQsGMvzSk2rEfK1h6H16yBCI7ytDvl4g5PQ/gfdzK2DR7Agd8Isk6C4gZ 4y3bs7B0zAezqah+Uf3Lzx5yOND5lFcwEobfT16aFA1ggEixD+dXcRIbC7TueZll hvrh6eey6/0LB6XSNLHQ37GStLiODjzGKWONbqiFpGmuO1cD0VsYtP4D7PCMH8fV PBGdmxEsrOYhahuwkHtlqrlcj/liO5MfWL9nVbVSZx0h0ZeP5qfui6MeL3p571ZV gChzmu8uRQcZ6q7AhBzDag/mDYu28K8P+mNmOqg1K9JWk5X8Ex7i4WfGlc/QkaGP 457tMSaSuZoRsBIekG4FQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepvden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:23 -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 6/8] platform/x86: asus-wmi: add safety checks to gpu switching Date: Tue, 20 Jun 2023 14:56:39 +1200 Message-Id: <20230620025641.53197-7-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-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?1769188858397002871?= X-GMAIL-MSGID: =?utf-8?q?1769188858397002871?= 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 --- 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);