From patchwork Fri Mar 8 21:05:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 778871 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (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 4CF4317745; Fri, 8 Mar 2024 21:05:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709931941; cv=none; b=jLZWaxyeYCqY+RoEm0xRmdghniL6L+xkwgZzkC1W6Y7KBDcjchMJ2faqaRlQ3C9vzu9uNTWQHCgLYbezU8DgVVBDgy12QZ4pwfTDFHzTOEeKVs1OpdRBrBWrjpHTCvrGmmSQn2e90GeqSWYU+PicGsWtMJMxrMcBbNPjSUF+r7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709931941; c=relaxed/simple; bh=CJpU7PWKIrFYOOqFWndohMTjLNyEZPWygUxPokaxCcQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=L0YF8CbXnZY+PjrGbqMIi/VNOLmdcuSH9ehDsF6yy9/n933kUF7BoU7uI0q6g11becQWl8610kKLRdCCnjn4SwwAtlBfUdJ0oYM7B8bvWPrsmpbzB6IaG1XOnvSTSp8zxDKvMjwmjOhU7bkrac7cqrbiciQumSOM7nu2THg3ppE= 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=BYluXopi; arc=none smtp.client-ip=212.227.17.20 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="BYluXopi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1709931923; x=1710536723; i=w_armin@gmx.de; bh=CJpU7PWKIrFYOOqFWndohMTjLNyEZPWygUxPokaxCcQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=BYluXopicfKwxb4kNRBAZGM+7BqLtW3izs1+WvcRuPX3kRljpM41EJZ6sWNzZbu/ 2O7r+iF1aD2426dvwm+IxQawEF+gpPZZswwVfAORqk+ZpG5Vmg+niLdzGtS4UbL4+ ltYNoH4Dc6rOd3C07PrpxbB42NYgPeBpqLZs508RFdViseBg/U8ldytS/cJrGD4E2 Rx1LVY9PEwfpFzCxKuDTcKKKRCCiKuOykNIdiMbiMYtXZLKqjRTtJ8VrZDY2TaIAD 7B7rt0+V8TCphu/EwMuY+krY0iuujAy0+r4n/sDs50COVB1CipF0lpgXFA94aHo2O 1HQ2YVM3sdzBVxlblQ== 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 1MVvLB-1rJ19i021V-00RqXc; Fri, 08 Mar 2024 22:05:23 +0100 From: Armin Wolf To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: rafael@kernel.org, lenb@kernel.org, mario.limonciello@amd.com, linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Date: Fri, 8 Mar 2024 22:05:18 +0100 Message-Id: <20240308210519.2986-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:mtu9WjXr40WaZ2ID4AXRXUusZwL9r7IBbaUfGB7C3QwidQdllXb lJFb8UHCwQAT5k/dx9avOSubQuFGgfSuPq+861b1tMVB4qP1TtMSkaPnrfMDp+Pzd4uKb2k DR3zItvG8MBcHwhzeI/JnLo+qxadtq3MFk90IWByj24XuD4mRxXklSBMjIk8Eyrv1Sr/4bX uHmyzoQ+p/tXj1I6w9Z+Q== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:4NUKyOK3Rx4=;G11GCJfi82Dmn84z8Oo9Twa3FU4 MsE4DPtcljrVZChUY+iZzezsOLEOS+f7ONKrNrt4RVHkYVeD8+lI2h7rSZTJPTPP0w0raE08Y csF12pKVBNxt8ydffMoBssbHJeZOE64nSv9IPFYFbSS0ui0jUoFE4xJMtQYsleYckihyr3RYE SHqQBoyTW5cEO1HlgqsbxtuuYpfLfpsXJA0ZNAYQwX1QJlJgJ2LRyjID7TPwVqb0Hxvwup59n gnwBW6R5xhtX6XAgfuqKTNxB1qLqpjlVDm54LkR2FJGaG0Y5WIOFb5l9VoudRepZasuCeWNYq VsCK0oivqMg5xRDRh+GspcxheU0/cKMxh1Rfke/VNo32g6115FMmYbC4uv/Qu4xPZh+9/N8Ue G8vo/5fvJkIuqXBBjHF87UNLsvI2rLqEv3NVwypSww8crLJF/o6M0UjOwJIV5Dm4Z3FcMPn7s Hh9LWusoMfCB1/BSUzATggyZo1Tu10K8ZgDLYvOGW11otJIdlRYylLEno1ni5ADe5Ev2komJc 0/FpOtwOku4LKXTJXpaf2+ujaBDgNp40y0LGKMJDJdvKsfj4DO2eQjXugls8TWEpgq3sOF+Zv UHBkLae8zO+RYuH537dOvaJ34MabSmG5f7uKVQM00iCjOno8qEgLQ9uldJPJHHAM2W0B7cBJi QXxWGBOohi0mp7rPLrhxZ+vyzVBkiDpJqc+xMtv8SOzWj8JSoeqSKPKlC6HhIB64hEPKijv1h zEJXILT5EIFnt3Ner4gf4ZgF268/3vYQLK04lQ1XVDGODqOd6oY8jIF8Ajvkqb/UFLNcOByGI VM46RCMh/AI+WEAolS3M2SDbY7pcWnZ8322BeKvPTodQ0= 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 Reviewed-by: Kuppuswamy Sathyanarayanan Reviewed-by: Kuppuswamy Sathyanarayanan Reviewed-by: Ilpo Järvinen --- 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 | 49 ++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) -- 2.39.2 diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 1920e115da89..d9bf6d452b3a 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,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 21:05:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 779469 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (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 BF2715E097; Fri, 8 Mar 2024 21:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709931942; cv=none; b=KwkF+byzu2w50Xn6jgyYblTuJ92d5btAU8NQmTeTYeUKo6zSEXvihwUAhFNJkjbB40m/FL3BCqc1Pe2wF5U1DhCA7xvF7i43xPu6Y3jwX+e2j7VkkQcB6q3HTNvSTQ3aKh37GcAgHPn+Ekxm8m4tmM5191erq3c1rVuTnLI/X7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709931942; c=relaxed/simple; bh=rie7fmUkfM0m8cYoiL41OvyYJnWYQxdPB6xJIoQaK9s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MXrI8I2g32dbFDS9Y/3xU+fnAvn3pAGlOoGts3R31aGtucxNr+zYGHnFRL0Unu4rv04kWyYIltzL3UMZKzBD0zfJAQP2isno6JotjgQaptrK9AE14o5JTJxU2RdgAqNJfcD6ZJKbgsKPtajGFhU9ZT0Mtk8dFZSOAaJOSihKIvs= 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=L39jFG3K; arc=none smtp.client-ip=212.227.15.19 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="L39jFG3K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1709931925; x=1710536725; i=w_armin@gmx.de; bh=rie7fmUkfM0m8cYoiL41OvyYJnWYQxdPB6xJIoQaK9s=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=L39jFG3KNdJcYIR9zz3ekYOkp2bOXpYWBJRjgHf6M1H7MkEJOS03CNer5FC4SYSD diZOsPHUUtgwclVt/44iM15F4RE6MmYqyMK+0tCiySIVRkSagSCrN7Tqdmy0hhnEZ n/OGfljVzTozinBPkN18fn5cQx5xYeywFNElafmBRY6zpy2rlAWatoJFSPV+3m49L 6BB6ux0+0jrSQ+IkxRuhFEPa3uJ+ofCv7ugoRkWBFsydMPsMMsfedk/cYV0xhReDG FeCsS4yqJMPwa9I8PkPIiXHi3WUlog++w+n/XydStTXdyvFrDhgUcTvVUpbqxAqNR OtuG51uesGca3k4oRw== 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 1M4b1o-1rjFMx1aQo-001ffC; Fri, 08 Mar 2024 22:05:25 +0100 From: Armin Wolf To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: rafael@kernel.org, lenb@kernel.org, mario.limonciello@amd.com, linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Date: Fri, 8 Mar 2024 22:05:19 +0100 Message-Id: <20240308210519.2986-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240308210519.2986-1-W_Armin@gmx.de> References: <20240308210519.2986-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:J8S3T8zp0/viK1dNI8/U0HtfNcG/2RqO6qETHNtIOpdJOTdw7aY dc0trKA0CKu64SvWOg7QyiWJhj4s8q32AXLjGFFdHh0SrmTi8qF05n52rfEJwV5bqTsdI8G shFXP8BI7a68NO2FeodXM5bNArk+uCVOO2tJNPGUJgzX4dyv8M6wytY9C7GbsKYX38IiSxX 3H0k5bJJg5BM0L+ALQBbg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:BPecIgapw+s=;3D0P6lza2e4okWHFLcxGy2BWAkV fXzvhW2hfKFClJjnAY1WCgam42VPDx0+TZ0X3qBLJrQkeIea371hZfz8GJEOU+UUx8oaDFJA0 VadTHmbSG8gVhoh6jW9poR0iQmKIAnNJOiP5B5ByXVsrM5aQmorpsR9GDOyewdspExGZCqyXk FhyqbNoDswqr5xymAZFsj3uYPJQQMkL1m96VRa10/UxMK6WxZQ07ufMD/t6LZ+WLzOBoXlyWb BdOc4wMVRVWyBSaTH3tJnAQQAlWfn8k0P98w0YZFt+Z89hA0ozCaK+lsbBtxa2fZR3XPY17eT 0M5RTeqaJeDTdm8grZYafstoPCnKrHoRusICjgqBoLMFvf2vIQTlgGB/+yQQpFobx/3AmcWv9 t4KBtQbt/fVGvoKC3i2kHk7m2r1RPQDYWiO+7IKJhuYw+ftwW18Z5+mvHciEOEbZquJPz2S26 3OJNdnvnoOR7sPz731kw5Od4nipihAdhc7ZehURUGeN2cfkdgpQYN3NywgWVD3IUVVCPhze4A 5gKR8yeurRC3KiCoZ+cUaCHVueXa837OPFkeSgWNLl7VieUFSN3Wrb71tEqUtdZLxsYexXPAl F4w6/axQdP73KbhCtY17qUF3sdolTl+VJSOF908cwWK9YpT+XM089+TO6xk/YH6lTEmIXPGCw 8dQKjSJmn8rgkd6HaTyG0iE2QlfyDrYi3K17CthJQ4u6KeFc28CYFApqWU0RG1YDogKgp09cB AWICj/ckXLYj3ANjPdf3kNWZLSdzbov2MNUm73rK+ZIFhZ8cjlsii3Qqb0YZyJQrDXTrmBOvl +ipnhgRCxRFlQe4FjuVEJV7vdJ4QG/i97SoHWZGRibImc= 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 Reviewed-by: Kuppuswamy Sathyanarayanan --- 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 d9bf6d452b3a..84d1ccf6bc14 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -1218,8 +1218,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; } }