From patchwork Thu Mar 14 18:45:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 780304 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 68D5D1A38D0; Thu, 14 Mar 2024 18:45:57 +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=1710441960; cv=none; b=OvkZ/T86uM/u0WIOe09mB6fVuYzk2IOQmsw+2mjZWZuiQYrLxefx/oZ/IXkd1ULmSQOIwWZ/bB5oxGPdLy8qE5hJuJzrKOWLG5liDicb2E7XyoDu2msaAN6UJ43sP/mNkJkgNKPLQCXOG2swKCv8p3TipIz7DI2WfUn1VjLE2v0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710441960; c=relaxed/simple; bh=Yt/Ht2srOy/MWCeGWifQCTS+hIHpil3Qr+8V2f3E2F4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=gKilfIDWLxDlPDOUQLnrEVFYwGUioaSwTzfnvlwhvvNlO9FWcwZRjkn7QAVpk46p2movZZ74lYkLMdviqm4bAR9Zb/tVuhHym3Kn8fn0Ih7s1V8sqIgYPq3CF/Cct7z7af1MxJTBHuZhkDWPkFIhTGa3Bh71nwTC+N3Fai+Mge0= 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=rHy0czus; 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="rHy0czus" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1710441944; x=1711046744; i=w_armin@gmx.de; bh=/mn6muzWIRKWcjsSnajnl4H8oquLpAAam6hy8/xPwIQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=rHy0czusPTznn1fpc3Y8eDzLXfwUvohmWNqKR7VakmygTrjrIvLdQgscmsTpbouB 7eGTBBny+eF0lb2NmjrM81MI4B1V+VAMQnKig4UODlTnofid0Wn+h8pl7v55EVyu+ HM2RCpIjyXPWgASzvIUMNx4UsKgmLaaI+5cSHk4E0F9a74B10fhpmcsYryNfW+6e/ M2+DEz7OxNT3SBPNw2SM5ocYv3kWtxHiP5eDMRCxN9Ol9wRj68uajiVACVMzS2AL/ j1DnEA/KPUL+g91dnDZ1javkRGy7qJ06fDNu0gyKiml/tOGJdHv2v33XjTeewk7rG peXfegeiqW5OBCM7hw== 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 1MGhyS-1rX8yQ0JOM-00DoVs; Thu, 14 Mar 2024 19:45:44 +0100 From: Armin Wolf To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: rafael@kernel.org, lenb@kernel.org, mario.limonciello@amd.com, sathyanarayanan.kuppuswamy@linux.intel.com, linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Date: Thu, 14 Mar 2024 19:45:37 +0100 Message-Id: <20240314184538.2933-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:/cqH+NjydsRZcAVaI7S67/vzGgGpC5ogQtVinAFyhRN575Hz5aH JMetDs+5HM0fcKKi0hHLiAvrwxDRiVYZLkYucxrwmLijq7a6DXOcxjuo6K5YlbDT1wVNFCo 7a5aexbIEKtucHVIn/A8meyuKw3dio5bZDvJMixIjaChquzt5Tn+gcSgNoGhI+YMo8VhCSY WCzlphX8ZUGjhiZjEAuXA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:FabCNjlmGVU=;O794OGRdPae3dIb4R1gaWQv8KA9 K8mT4uQ3b5lB08wTSukck2bRDH5MMDcSlkRUiOz1CLci1V9cixwE1CB6aM/rhdGlvc8IiOjwh 1LXM6N4DMeVbL3nsDRo+EoM66MswaECp8q6SMUmiZPhvBd3uWMtyF0VZwMxSC/kCwrFF2gPpz XKmrIV4p0jL0cCkhFhzOILbSAzJzeNpcTzpKvq2hScckdVmENGe76CLaZzJvg5wA2rxH28JJY Co93bkDu45B8ugjVgfkF2PMXdnYTDO56EXmZjp8qY3LAriXJSPLvc31sf3VxhbJIj7qtIOHqP cGodsui0KXrp9U/0h6hZP/jMnYeTnBQFUUIVx0uwLTynwPMscyDX/4A7EZx1huYlHgmEg38UI 277nnnfBkpJmh+RYj0yqakvfKMQ35kiM53Qwvn/bCu1F/vDi553yR7DcLMH3vO+vcK2gtnJx0 TGI55mlV1Uf42np2fdhDLAxDFryyG0nCCGhXrohwdpx9T5pGmKn0yS/DLjkIc6dEjaci5fkyv 1l7Eq6u03+H9zaXfaYPBGA68A+ip7lmT3r7POfdOG/ZZC86rt3LmLgWmkow5GB4AVLbOOR1AT iKnYRggAaU1cIiSdxyQgjKZ4J9lzrAihm9+6vjYnSi1Q3LDKFZQtMKt/VjTaZ2L92ZcVP6t6s kwfsfU4rK7+Qj1Ke51vMbapEVd84JxPqbuS4xzAJ438kHWlxSN1ATPFb/9xhWwkl8xyVPJcz3 PpgS+4e3NGkZM306xo3sqFknpo5yhreyOyX2QWSUHAUCb224lZaQGDYBAHc4KbWiC0sY/DmUF VD0W3IjMx4gyRZpcYGOtH5gabCHnuMmh01cOXk3dKfRsQ= 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 perfectly 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. Reviewed-by: Ilpo Järvinen Signed-off-by: Armin Wolf Reviewed-by: Kuppuswamy Sathyanarayanan --- Chnages since v4: - spelling fix - fix checkpatch warning Changes since v3: - change type of variable i to size_t Changes 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 | 54 +++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 13 deletions(-) -- 2.39.2 diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 1920e115da89..9602658711cf 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -1153,6 +1153,34 @@ 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) +{ + size_t i; + int 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) +{ + size_t i; + int 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 +1190,27 @@ 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 ((address > 0xFF) || !value) + if (!value) + return AE_NULL_ENTRY; + + 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; - } else { - temp = 0xff & *value; - result = ec_write(address, temp); - } + if (function == ACPI_READ) + ret = ec_read_multiple(address, (u8 *)value, bytes); + else + ret = ec_write_multiple(address, (u8 *)value, bytes); - switch (result) { + switch (ret) { case -EINVAL: return AE_BAD_PARAMETER; case -ENODEV: From patchwork Thu Mar 14 18:45:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 780546 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (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 71CFF1E480; Thu, 14 Mar 2024 18:46:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710441965; cv=none; b=PH0lePPLSD07S23ht8Ywvhk5XQDPIK+Q+A7o0Tpytwy83gLHeWZ4EjhrE79YFz5VG94Z68kifK7PnbfaHCJbuqwegdKO0qJrO5X3eZ6LRKl87eagUWX7PDQi0k2FKz6KLVPDE2oSwWhm6pQst+UCzpI2Yq+TFaIEYjj2MYkKsOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710441965; c=relaxed/simple; bh=73pleJhpD+977gat83JtY6VoRHWs9PM2nlEgjX6dODM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Wpuqdap1h+8wnaLfITTPaRIJbcQ01uVs3Gkg2FjgD2xnXvuoQnFVkot8T8GCSaDnz5ICBAejJsn/3KV9BOni+ZrMaKdhE1nj/+6JGHK5sReYubDHW2S5afh1WFHe75whdw+bi0OxquXrzykq4u0wzFQaBvDiA4lTyC4jbZw/m/k= 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=tOeFAKIc; arc=none smtp.client-ip=212.227.17.22 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="tOeFAKIc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1710441946; x=1711046746; i=w_armin@gmx.de; bh=OvYtfM9Idw423mYxqaNVgKEM4T4GduoNSCU/wC8Pn1E=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=tOeFAKIcNUuva+vSuzovLT1LU0qxVMTnPiaEdPMWXhJj+htslM/O+UdVSMpeEv+m jihiyUg1NkOjBBhM7SKSBN+YlFptq9mL/SgbOaffTxv2SDN6ApQpy3ibPAHu2hts6 VDXjGLmIhuhCNprVMKjc5E2fSv8t/9R5NBn4bw+d46w2OtzTWFjR2T2jzCjnEt4Zl i1/9Vn1RJiiLzkQNv5xwLUwdj91S35c4skPiRx/BrdxOiSSu+YnrjGMQmZgkkiqR0 GIfAqif/9IoaGORWboecJgYZHm5LKtPWMXTZN3o9ZnbFP84/R/1t9ADJIk+QgbTfM NCMWiG61eafr15sN0A== 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 1Mt757-1qw2iJ25Np-00tVY5; Thu, 14 Mar 2024 19:45:46 +0100 From: Armin Wolf To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: rafael@kernel.org, lenb@kernel.org, mario.limonciello@amd.com, sathyanarayanan.kuppuswamy@linux.intel.com, linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Date: Thu, 14 Mar 2024 19:45:38 +0100 Message-Id: <20240314184538.2933-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240314184538.2933-1-W_Armin@gmx.de> References: <20240314184538.2933-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:BzNMQR+CPawSYJ7irsf98oWrdE8WPnzPb/P+gCNQPTjfHVCjbVM sBffKxV7U5JJAsA2qjjJgo2UoAvtoIAtCTikGGpHdGJ62AHjsYs9+HhPwXoKtIt5BmlHQmH bW/cBV+1q9BSXPmH0qij/L4v1Cq9lMxRd7rjWQqz6PGZto2onpt2BiZf8bVPbKeCHgyNhyq MD2v1zTVxG+7idXZbqHFQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:vZGeaRnPzjI=;Zb46cEwHdsv1VGbzDtSrQBIrCQ3 QnW/GtdlNUE5+tm7hfEQsdAHEWfwLgOt5IBpjoKHIbtqP+XlIgHKBQ78z59jCs44O1htJtjHi +cy1aRLIoCAD/Vvf2gM48WAfMmF+Pcvk1XcHtxBAWNcVng+qcgfcYFlroNQSdGbn/MBprp00g mVxilJlmcqPZZW7St2qvHebCpaxNbJ5y3yh2K8oFaaKf3T/bYhmcz5LBHOEpFyeUXsxZTqbYg h0ngJSHOPQ3fHm3Hd4vtu94seoDRQYa1MDsnA0QNV4A7CaHg8guLUzVnnp0UOm7JT0FB0TEjb jMQMgM0lLYjICObtwlsiiNoAnrBy0k0fhZSwFAM3mEnYiIlFo4WiXEikqW/fD7nroQKPA9USM QDzNqtOS3+0kjc67d3mC094ZZAmZrZaK1y29KEASQb+bKt9WOKLgdNSPj2Hp3UisWK42LGDve 1ItLOi+v2p3wgkgWvwA2jZsp5qb/SRy3HQ+Cap+p++vXI9wwMrU3WIs5c3oRrm30m+zIN9/aY OU1HKh2Tsi7DPJGdhmZXEEWT2AljXPMkz27K46DpwU3KquxtcuJy+Kg8ued+G79deU9BbDb0S w+Fav4lhIY3Ky4wrSAtCk1a6RFFSKMvKY64yRcemKv3a8qnRLgCOYmNgWtNnHzUpiSUICpQp6 onx1I+4tK4Gpf/fnHVJT5rAk6VBo8m8iJkvaHMTIByFnlwTTDLwdhFLEKenveq6gQaneonxc3 0OC1xJiLOFB7DNRySrUy++fh9sr8B7TXFjN+U34rbx7Vojl+zmkUT4Ohhnm+VITZSi/SqgLKb 0nzS09uaxhcQBXzvzdoxlaXVvuYy76vIPGQ9P5NjZ0oJw= 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 Reviewed-by: Kuppuswamy Sathyanarayanan 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 9602658711cf..060e4236f932 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -1217,8 +1217,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; } }