From patchwork Fri Mar 8 19:50:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 779470 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (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 B7A2E5A7B6; Fri, 8 Mar 2024 19:50:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709927448; cv=none; b=lQg9U5aJ3c9vYj067J8Wwf2SkOgNgQEcf9LUSOBlwVsUI/Pkh1myp88IaiAGU27jsWYpTV+sFxxOlaS47Z2PKhiziygPu3QWO8yV2ZpROvbZZ+NBGWh2EXL+HKNwyBebJc/bLS0wQKn/rWvBBIWSV7da7Zy8D8tuarI2QoY1nMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709927448; c=relaxed/simple; bh=GInZ2URda4ZR/awa7AAlXa5X3pT6P2FUwC1sJRaJ+SE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=K0xtIpfci2r6NL84Ufbk/WKOv9yq+4350nOgJM5O8uN5i+RLLeH9FYeeSRwbCMoccHmwoQUarTb+5H+hfvZSNTzczfDsnAc9yhNNJtOswLWsZicy/c1vwPVqt1A3iavBiXDXRslwfYe8doMSlix2/HkAPTjEOYpSQGUIMtu3Md8= 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=uLSVaJlt; arc=none smtp.client-ip=212.227.15.15 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="uLSVaJlt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1709927433; x=1710532233; i=w_armin@gmx.de; bh=GInZ2URda4ZR/awa7AAlXa5X3pT6P2FUwC1sJRaJ+SE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=uLSVaJltz501mreBO38jIJr0ZvO5+be0rmpFBXzDBAuylMG3y3Uc2J/emV24XK+S n8Ih3mBGCKbfXlDhta7NBDypoqBRn5jf7NJNESZOx1c0FbYPup7uUb3x95IGR3SzX rDAGlFOkEQWXzgzRcb6Ba2Mt1BZSKaXwLrI7yMd8Y1ReQBqtOjlfzHHd/ysPOIkb4 srGhkO4Fswb+tTW4KpAvnTr92i2oE17TcONxuV3D3+xLSKOfXg1ru8mclpEyPUSYs pcFvaFAVWHKg75fUts/cK99L78Ld5ln0ucF+FKE6lnALvnXUs+lebc2IkgemqAuSx T0AdG3dM5W6Y/nPsVQ== 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 (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MTzay-1rHdD10Xr8-00R123; Fri, 08 Mar 2024 20:50:33 +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 v3 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Date: Fri, 8 Mar 2024 20:50:26 +0100 Message-Id: <20240308195027.7640-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:CtZhcD0n0yHdmdum9rwj1NwZDAGDtI2rhCGhj2/joM0d71v5Q1q 7P7pnmGPakEDFu27C5grY+kwmicPhNrqDlMfi2S8TF1lqy3x6pG+w7fWdAQjBic28CXCZuj 9EncNSHFGkiWff6vt8B9PltJbYVuduzyAkw3cw4jLB8cVghPfdwwiPJjTlII0IuCM8R5xHH 0IMQOeexx/QPH6ClZfMdg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:7n9CoxRLmQU=;nNIRGz+Uz9smsiJiA1VhCPtFG4W elrxO25Y13f7dAar0c8osfZ++hs20CNEFaUN9k+o3A9j3SD0F3vgNS8Z6+RnTpa1iKqRWCSbw rTty0DFg6shqYKGk9t2u6xOdM2kd9p/Zmk6wNn7Chrk81XHROIMTBwlvAzfdxm+K5FaOmAt1q j2dvrtXRhXhweM/wsccW+vqiZtotGs2ilXASjXeY1SUJWkrzmpYh0TbizI27n8/rZpC/Nidj7 b7Jpm/wrZolJEbg8c65rWtrVUAixRvS5W4a8u1e78yancVDyNQOCP1Hc5Pp6/IdpjbRp6lw1w /hcS+u0PDW2LP+0W1cye2h4ysfbEIW85BTgwkG7tb33l07dADwUyNVhS+VAZOJ4Kt/pXj/rby b1tgIBVVtzjbQN7PYQV3JzdVqIuRPLG/ijTBHBXl20k0bPz+odv1pfIb8faDoUSvM3wHlmA/l /m/6Kfb0tr3mDX/Q4abvFP0Umb3h7OmplOEDaMBSUdVbE+ng+3DH7+mVng60feGT6O3r6oBDA c8+lQMu6zLwk6oxBGPVHkH6FvuE1i5KPfABlhDd4dEtKH3BKC9ZBTz0HAXuU8FuRXr524pziM 8z3Vx3SsyC9s3m0ymGY1q0rsXNvEb7rAVThz+aMWetWyyfs9E50nLJTbJzx9kk6pUg4LIinwM 8kQV5r24QchACFohnKBHY93q53sIOrGMzfeNARrWxrIy/rsIBV8S2Z2uOKisomyRz58fo1FvQ HVEL4KdTZc8V9BawRt0gbEDJKd/TjDmHCk3sc7AboYLwseYBsaNm0kZ38HaigL5ZmMX7VXkyE MHD4XPwbW/jFUJbFBFtzcsNHHhqPpLKsiDueW7t16j7HM= 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 --- Chnages since v2: - fix address overflow check 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..e6cab1cf611a 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 || bytes > sizeof(*value)) return AE_BAD_PARAMETER; - if (function != ACPI_READ && function != ACPI_WRITE) + if (address > U8_MAX || address + bytes - 1 > 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 Fri Mar 8 19:50:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 778872 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (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 D295A5A7B8; Fri, 8 Mar 2024 19:50:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709927448; cv=none; b=hhZrWnia7ESki6udLodpMOItQK2qGo660BbPiJtoz/+f4XbVBqemUPqugimhTqtzt50PWIJ4rOClCdAH0icRi7SbENO0A9zRcWJMrluq2Ah548ZCA9e+bvW0MF/8kvq0iHtFdRawQNX8VU2WfBReHnggz1VIe9f8mFGt9GD18Gg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709927448; c=relaxed/simple; bh=SE7zZzdSvh30m3p68BbPZ7PZvfih8AStt4mVSuZXlMk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=kRfMv+MuMBGRezFKNU+nfLSNzY/RX/l/oC/9JxqyIO0x9AfIW8ShLVXO1jMlUsjW5WZppR3i60zeOqvSnqN/M7Tho395Yoipat7ODK1tcZqHb4d6uSRILwkWmXh3Ag+SEPvj6z6LePVDoU63d2k9JrQQPiIKZWmifbZqotneTQY= 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=hOCree/y; arc=none smtp.client-ip=212.227.15.15 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="hOCree/y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1709927436; x=1710532236; i=w_armin@gmx.de; bh=SE7zZzdSvh30m3p68BbPZ7PZvfih8AStt4mVSuZXlMk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=hOCree/y5KKagT876Co36RG9EwUcq85pBrx4D7n3eVQZFKs5fWLvkT403q2Q8gQ+ g53m+qreWs4dQbiktdz263B+CNDZJDe4nblC+lhGAIb+edxZwCUpvOVJ3J61BGlD9 sBnpIttklFQbXQl2iVS2OoXQiL+q2jt6hQq6ndRnohbD050ZhO02I7MqRrlaCr2Bx 6vaJyUnCbffF/fKwTVvdo7hR8xW0/K+O48ucsFPBdkcnvixWQf7KjimEMHnSXBGF2 djO3fA+TttqM1wk1i7e1/NTd1B5Ub6LIRE6nArjbS0J6DIvtuarTy8BuE5YXCm7r2 EFF4fSEwMxLECtM8bw== 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 (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MjS9I-1qy1xJ3OtG-00kvMF; Fri, 08 Mar 2024 20:50:35 +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 v3 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Date: Fri, 8 Mar 2024 20:50:27 +0100 Message-Id: <20240308195027.7640-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240308195027.7640-1-W_Armin@gmx.de> References: <20240308195027.7640-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:ITvl0mwxzK0bYYhNzD8L/9G/fdu5flI0mYdYIo9Z6G96G7zuxVy TCgKocEUY3O3VtSA3ZRB0mMHR6HVIPaN72tOB1s8jMbUDGHg9VzZWgdSUudBRAd9JCx/VhB liOPmxfLd7ArLW4y8bWwpAY0FIkA1uHxQVVW5uob00T6rXiC5hXPgnghg4/RQsiKgYfdomi AnLL7x+WC4oMC3IaH4JBg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:lRGWUd8rbD0=;S3VNApLh4SSMB/cUCUVGpwJPrjz h5eQf1dROgx3oZVf/8xQGNV0k6XtXXV8FWFd3Yr8w/Yabdiq+jSg34WPPEAcF3m/Ib54+cEuc Ub6B9cV55OsaSP6Wp/i2S/NKv+q5M+B/vBTsjjcI6XTfvp5Rqhj3cP1m/XiiJMXrhgq6ddYLa E6mENN2PyYknmTtjnjr4k3YeIt4A/z8CZLD8gHqd5ySbE0N+zO6aeQksHNNaBs/EMJ6QuQSh4 3cNvv+X1ESsA7HHAx+M1uJoMJ08QFaMlPSAgrmLeat/vIZa2rD/4zJy/s9haAVFtF+ELI4WBX vkqGcCGxTZF3e/XM7I7KFPSLGlSqW+jijtxVgcqR06Tca/8fHjVnZn5XkcnRMiXGXDjAmYduv QJUESLKDgAvMKj30UFfFdKkKRlRsgcJ28z1qz0SZETLh6gn3CFoiZ1Ash1Omk2vLVCOcZhkEb /yo/sxM6045buMO4JYG7Ji8N0Am5nuNa3vd+eop2c72trHw9aNXwV+L3xqisriVlgvP4KE5rL pooYk1gxvWpTS5LMzdtT8K4qHXzacdwBSGlWmhirbTGlU2gnURealpnC2OlRqK3qAhPUNOm6p EDPlKkIlf9/i527HYGkBL0SsBmRYLKF2/Yc4wfEoRr1FK9TvKlTY7w5yoAeCTTZJf7VFyiuFn 9RmK8EIGeE21bprwRQ9jKLILWR+SjkFBdS8HrEBbY6J0H9n9cI3ytzPryx3fuVewI/rKKTXxv mezBTxKN2GhhztIlC7eY6NCig0P77htw1B13Wwf/WegziETdaPno2aj1CKr8cZaaV4dkgML5v hkK2awNic2ugRPZEztS3lOvevY3K+XmkYRPAKRbR2C+Dw= 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 e6cab1cf611a..3f75220558aa 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; } }