From patchwork Thu Mar 7 19:57:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13586212 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10444137C37; Thu, 7 Mar 2024 19:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709841496; cv=none; b=WL5TD3lcG0OS1gIrEbXQtbMs9ZJLP4o82TFhbdEQbwxcpTniMC35JNhMgt/ydq4bi7uROqfLy2LA+Iw1enrvf7nHOmcoWXlVvlvKK0vyUScFjTCxupdPLFDn8uvkCmB7f4IP4/wUHUti6uxq8U9aiX7SgWeZ7wtUsLRD0Pcek9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709841496; c=relaxed/simple; bh=SfL6tjOb05/VPDRBKcHaN0jfguu2f2ZuyXGBWNiPbMM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=UL9zw7YdVZd/6M2Tvm5W1Twljd+VXGTUM8xAHupg/4mgnprFxVbku8TvyHUu8xykKM2pF3alO6RzHKIB/iwDLf6XfiwOb2y4U1QNdrIAI2Z/QuZy4v4Imo6X3220xEs5kS3zNnbZABXGnwb0CjpWtyGat3nELQiMS3aUDPhgcZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=lTw8q/Qd; arc=none smtp.client-ip=212.227.17.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="lTw8q/Qd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1709841477; x=1710446277; i=w_armin@gmx.de; bh=SfL6tjOb05/VPDRBKcHaN0jfguu2f2ZuyXGBWNiPbMM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=lTw8q/QdTtLoH5EcfrqhI4muZHFRSXfsMeyfBHbc/8P6vcRK6sa6m/CCjMNTl3Lb Y7psyGVgtYTVNGPKgKEdGs45LHcZBar+RmNUsrBjSMkCcxmJmS3CaovhF2ZReNe9s NpP8dFJU/f+09JGK/khA8HToudbCBY7wOeInJlm+fsjMsiUz7VlODsu7cvbtAsB9a 5X1cv3odKdV7m1wq14CroJL2/0IZ8ioS/6jJzr2eE14PeoXaDT7c7zuJZNwIHdbDG FjHkIOJGIso1/Zpcx3eS567OOaQ9qiz0ZjE2vYA7qKmPiUPy6Xgeo98Umc6t6cdeL BuedyWSvzQ4U/6OvJw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M59C8-1rjPnt2qDU-001Dm1; Thu, 07 Mar 2024 20:57:57 +0100 From: Armin Wolf To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Date: Thu, 7 Mar 2024 20:57:52 +0100 Message-Id: <20240307195753.2961-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:IgIGkb1CooilHWRWBcwjfw6/swGMCO/qvBY2LaJ2FDTkoA4lRXC QZx8TmYGGFQa+8jpXHQRt29yplfLUKlzJPB71qqkdxgHcLOl9i+Fym/FIOpgzUr/EY5iMke Fh1MibgWUy6aFyPhEebKmXVHOaE7BkkjCFAp085bTLxa9qWqP3B7kplbkWxyNVARywIKNht /+5+i09xbNPZANIjPl6eg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:FK4KqCJSjOg=;d6qdQdkCMNfCLDjOKaRTBFFi+u/ oMV23C1f+VlTVlIkRfeD0T/kDI7GOYf3ODbwf0tzdeGi1NmIL+z61yym+8pCKcnFnZz9f8jUU 0srfG6RqUoQeY4FlE6JI1Qr1ywuCGYlkMvM+h5ux5/JSGDyDEt3B8LYRqrD3pZvVmgNIrDD9g J0njNBvbI2EUHZZIF9y49tRGt/fep14cnD055R0xSbo2CqMsJZ9tN782CKUXo5ov10pBfBBI6 aIK8j33AY1d49lnUBmoEtfYycIqXT8tr5XG04y6ZRGTGErFo38nATlwkWQemN6mE0MI6pObL1 1Ub7jbOYl1XV/erJcFdzihojbZZbWA1cWwgGuC4+qx/qa7QMaQiAseeZgSi2JdAXXb+r25JEx JsqPjs6COkrQiojmXpQPiKgheaIfLT2L8Bec4OfUNtkJJV04r4d/UAF88hrkzKL6wthCw/Uot zf5UKSNdHCGpwpPnqYFSviinIGpbhmmaYvNzWiVPs1McWS+feZHuS+UT9CsTMPBnD9dVi3GtO S7HCFOh57gwupy3DffxiYf8QGPxL4Oz9hd8hIPOsasZP++X7guqwl6dgbcvBTxS5VhVjfs1hu Mrv+2OPotr9auOPWXtSzG5gfNWFnXeVVIIKka3iofEeaxsnReU1lpMT220TFHj+/xEVWHdA5R dHGLy1aMST2O5GNXbJbZ1xGlqyNcae9Pr3xpj9Vt4e4+6yH3AazG0S1+KdiOCgakv5MfL5j+z YjDti6cV5mvupgKniPniJXaraDpNCg0F2AuJvrPGazcFFQFG0blP+BcgTFaRPHSk/bWBmyMIz u2T9GPrCaFRFThsX7SIUBlWFZXn1uRONuRLLpQTeJRoYk= The ACPI EC address space handler currently only supports reading/writing 8 bit values. Some firmware implementations however want to access for example 16 bit values, which is prefectly legal according to the ACPI spec. Add support for reading/writing such values. Tested on a Dell Inspiron 3505 and a Asus Prime B650-Plus. Signed-off-by: Armin Wolf --- Changes since v1: - use BITS_PER_BYTE - validate that number of bytes to read/write does not overflow the address --- drivers/platform/x86/wmi.c | 47 ++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-) -- 2.39.2 diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 1920e115da89..e542aef825a3 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -1153,6 +1153,32 @@ static int parse_wdg(struct device *wmi_bus_dev, struct platform_device *pdev) return 0; } +static int ec_read_multiple(u8 address, u8 *buffer, size_t bytes) +{ + int i, ret; + + for (i = 0; i < bytes; i++) { + ret = ec_read(address + i, &buffer[i]); + if (ret < 0) + return ret; + } + + return 0; +} + +static int ec_write_multiple(u8 address, u8 *buffer, size_t bytes) +{ + int i, ret; + + for (i = 0; i < bytes; i++) { + ret = ec_write(address + i, buffer[i]); + if (ret < 0) + return ret; + } + + return 0; +} + /* * WMI can have EmbeddedControl access regions. In which case, we just want to * hand these off to the EC driver. @@ -1162,27 +1188,28 @@ acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address, u32 bits, u64 *value, void *handler_context, void *region_context) { - int result = 0; - u8 temp = 0; + int bytes = bits / BITS_PER_BYTE; + int ret; + + if (!value) + return AE_NULL_ENTRY; - if ((address > 0xFF) || !value) + if (bytes > sizeof(*value)) return AE_BAD_PARAMETER; - if (function != ACPI_READ && function != ACPI_WRITE) + if (address > U8_MAX || address + bytes > U8_MAX) return AE_BAD_PARAMETER; - if (bits != 8) + if (function != ACPI_READ && function != ACPI_WRITE) return AE_BAD_PARAMETER; if (function == ACPI_READ) { - result = ec_read(address, &temp); - *value = temp; + ret = ec_read_multiple(address, (u8 *)value, bytes); } else { - temp = 0xff & *value; - result = ec_write(address, temp); + ret = ec_write_multiple(address, (u8 *)value, bytes); } - switch (result) { + switch (ret) { case -EINVAL: return AE_BAD_PARAMETER; case -ENODEV: From patchwork Thu Mar 7 19:57:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13586213 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10408137C36; Thu, 7 Mar 2024 19:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709841496; cv=none; b=PduHsLVtCE8pauatNgRDbstglwjX+xB1x4wJvEUM0E3G9NynTCqxG5X1p6PvMv+uMyf+BDO3gtBmkBSIPWpZjyZTuCmtom4oPGYpXnbbHQVybq6+G3yyrq9TihmYd/MpWI/LjEwLWE3lKEbs4dQkYjw8yt+3pOp/eNl0wIZfFYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709841496; c=relaxed/simple; bh=dVVO80js759j4nvce22wbRDafQcr7cFxiq3JvwZyOYM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=m0wBZvi7DOkgC6Liqo9XyQNKtEu1JPCYQonDiC0HeikS1XPGmr8IFBxe/TyUX6zkdleQxWGRUKqG3L23peIZdbm8TFm/7uDkJzxDWhXxRidLB6nLUw2vTHyO+tlnnn1A4gvALO2PhmW8U3orxw1CiVOzUNhQzNCn+lGnJIjNiDc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=eE96wVP5; arc=none smtp.client-ip=212.227.17.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="eE96wVP5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1709841482; x=1710446282; i=w_armin@gmx.de; bh=dVVO80js759j4nvce22wbRDafQcr7cFxiq3JvwZyOYM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=eE96wVP5omenyoQ3PEfl82WJTUkbrl16Z+HTy0/MAikyXymwen12ChVAqy5fa5UR kNm94v1wuvG+f/zFRuStZUAtuUVN7zsnFZ2CQWKE7ImNMExi6TPLCBD7OGDpwITVA tx/T9AcdcpStnBE4ItYRZp6N1sGcsV2OMJ8Hp/kWRxv9z+k3ClN0/rzroWyWWOrzA gA1r3kkbwWecRZtnkXJ6oJX6w/eMl4UVb1aXPZzItYzwyNNRCJGCbEkVxeSIiy7Tg IbzDovkYDVxL59aJ1MeJgP5DJ3XZ92cBtJFhhlVwdXrprRLNQ/3+5F6BMzNRVjgTH tlqw/qtb8jp5h8HVqQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MXp9Y-1rLIIA0NPI-00YCrb; Thu, 07 Mar 2024 20:58:02 +0100 From: Armin Wolf To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Date: Thu, 7 Mar 2024 20:57:53 +0100 Message-Id: <20240307195753.2961-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307195753.2961-1-W_Armin@gmx.de> References: <20240307195753.2961-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:B1KLFHgvBUA/1PWVazQcA7KyQurIENAqhMXKuSgnGfTB6TKorHW ZHwSid6Km3NV7GUhbz1ph8/1TKHVcXB6dD7vBg+jvElCYARMZ/5Hw2x6uBZVlAQy9gk5ZLV CJB7GjkAttNvl6v5dD0av9lsONBUZusSw2UnK1Qfkymo3xLd/O32AY70pYV7G+yX8HQ1EV+ KC9kULR8ir2saG02l0D7A== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:4wi1RJYkdXk=;tRAdEKzXE8V8wR9rPtN9FACtYRW lvvlBw1YqPTZH0lUW4DEyOzTKtSXoHo5gHtKNHUCpJjcOooUgQUiKPtHqO6Cw0b2F49w6QBsg irzXd/1Hw9t+Hy2uIg7+W+RVukACQ21Z1+cNm7yLCfeWHhULZhUwXvZB1gX7eTnnVk+nVzXdE /T4DbBY29eny50i7tDQpJOq80LnLLfzrF25xIfmTY9O646qn5kAFkFwJozqibVSUROUZmGDtz qB3A0NdCE7ct8vHnEAOj2ERrFjAykdmDQ+ztfUe8FwriH6FYD/y1jOEhvkQejdBXvKS6CO6xu GwnIrkwokIrgYNMOfllTsOeSlxH2uH8p2EXxjgx/Jq0GeeOv9H85exE1vDkHt+64menvGcObA Yo59uzSVi1pnMO2R7JBjvfvXXU4uRPXMlU4LiNYVZFgdNWppH8E0Ve4hCDYQJoCxB+PQRhPkL KEzLU9ykViOJd0xsyGac+K8g7DKwwBHxhBZ/DmNtBFoREgp7VzFPuCy6NQr+XSVWUpalhwKx6 QYpNHGptWjet4ggYHxe+OT/FF6cYs58OIRc4leVY87xklcOdfRjbAobM0eDTn+RgI3nv8iqxf s1ucSLQ3pA1Jvn6V3mxwsLxF20ARn5vQ3DYNE54xqQASw5VM6WhvsocuqLrfbqnf7+sOjr9ik KmAcqtIba1HGpVvluVJfLwixi+Diot2JCvJClmnQWJYSsfmNVaro8TbNraXO1H/Kcjlc8X8kl NFzYsvxGsailVgY5FfXyNNpnDCYOMA1Lt/nmz7Yj0A0n9o6Cs68LaC0AQtnEZq99z0iJuFviH 8d7VFiTQmNDiaJ0mOyQz6QEzhY4bIlWejT85CQzNKfsUk= If an error code other than EINVAL, ENODEV or ETIME is returned by ec_read()/ec_write(), then AE_OK is wrongly returned. Fix this by only returning AE_OK if the return code is 0, and return AE_ERROR otherwise. Tested on a Dell Inspiron 3505 and a Asus Prime B650-Plus. Reviewed-by: Hans de Goede Reviewed-by: Ilpo Järvinen Signed-off-by: Armin Wolf --- drivers/platform/x86/wmi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.39.2 diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index e542aef825a3..ad82a96ed145 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -1216,8 +1216,10 @@ acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address, return AE_NOT_FOUND; case -ETIME: return AE_TIME; - default: + case 0: return AE_OK; + default: + return AE_ERROR; } }