* [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values
@ 2024-03-04 22:17 Armin Wolf
2024-03-04 22:17 ` [PATCH 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Armin Wolf
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Armin Wolf @ 2024-03-04 22:17 UTC (permalink / raw)
To: hdegoede, ilpo.jarvinen; +Cc: platform-driver-x86, linux-kernel
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 <W_Armin@gmx.de>
---
drivers/platform/x86/wmi.c | 44 +++++++++++++++++++++++++++++---------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 1920e115da89..900e0e52a5fa 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,25 @@ 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 / 8;
+ int ret;
- if ((address > 0xFF) || !value)
+ if (address > 0xFF || !value)
return AE_BAD_PARAMETER;
- if (function != ACPI_READ && function != ACPI_WRITE)
+ if (bytes > sizeof(*value))
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:
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error
2024-03-04 22:17 [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Armin Wolf
@ 2024-03-04 22:17 ` Armin Wolf
2024-03-05 9:08 ` Hans de Goede
2024-03-06 10:20 ` Ilpo Järvinen
2024-03-05 9:08 ` [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Hans de Goede
2024-03-06 10:19 ` Ilpo Järvinen
2 siblings, 2 replies; 7+ messages in thread
From: Armin Wolf @ 2024-03-04 22:17 UTC (permalink / raw)
To: hdegoede, ilpo.jarvinen; +Cc: platform-driver-x86, linux-kernel
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.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/platform/x86/wmi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 900e0e52a5fa..be0e772a87c8 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -1213,8 +1213,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;
}
}
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values
2024-03-04 22:17 [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Armin Wolf
2024-03-04 22:17 ` [PATCH 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Armin Wolf
@ 2024-03-05 9:08 ` Hans de Goede
2024-03-06 10:19 ` Ilpo Järvinen
2 siblings, 0 replies; 7+ messages in thread
From: Hans de Goede @ 2024-03-05 9:08 UTC (permalink / raw)
To: Armin Wolf, ilpo.jarvinen; +Cc: platform-driver-x86, linux-kernel
Hi,
On 3/4/24 23:17, Armin Wolf wrote:
> 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 <W_Armin@gmx.de>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Regards,
Hans
> ---
> drivers/platform/x86/wmi.c | 44 +++++++++++++++++++++++++++++---------
> 1 file changed, 34 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
> index 1920e115da89..900e0e52a5fa 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,25 @@ 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 / 8;
> + int ret;
>
> - if ((address > 0xFF) || !value)
> + if (address > 0xFF || !value)
> return AE_BAD_PARAMETER;
>
> - if (function != ACPI_READ && function != ACPI_WRITE)
> + if (bytes > sizeof(*value))
> 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:
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error
2024-03-04 22:17 ` [PATCH 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Armin Wolf
@ 2024-03-05 9:08 ` Hans de Goede
2024-03-06 10:20 ` Ilpo Järvinen
1 sibling, 0 replies; 7+ messages in thread
From: Hans de Goede @ 2024-03-05 9:08 UTC (permalink / raw)
To: Armin Wolf, ilpo.jarvinen; +Cc: platform-driver-x86, linux-kernel
Hi,
On 3/4/24 23:17, Armin Wolf wrote:
> 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.
>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Regards,
Hans
> ---
> drivers/platform/x86/wmi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
> index 900e0e52a5fa..be0e772a87c8 100644
> --- a/drivers/platform/x86/wmi.c
> +++ b/drivers/platform/x86/wmi.c
> @@ -1213,8 +1213,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;
> }
> }
>
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values
2024-03-04 22:17 [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Armin Wolf
2024-03-04 22:17 ` [PATCH 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Armin Wolf
2024-03-05 9:08 ` [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Hans de Goede
@ 2024-03-06 10:19 ` Ilpo Järvinen
2024-03-06 17:57 ` Armin Wolf
2 siblings, 1 reply; 7+ messages in thread
From: Ilpo Järvinen @ 2024-03-06 10:19 UTC (permalink / raw)
To: Armin Wolf; +Cc: Hans de Goede, platform-driver-x86, LKML
On Mon, 4 Mar 2024, Armin Wolf wrote:
> 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 <W_Armin@gmx.de>
> ---
> drivers/platform/x86/wmi.c | 44 +++++++++++++++++++++++++++++---------
> 1 file changed, 34 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
> index 1920e115da89..900e0e52a5fa 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,25 @@ 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 / 8;
I'm a quite hesitant about this. IMO, it should do DIV_ROUND_UP(bits,
BITS_PER_BYTE) or return AE_BAD_PARAMETER when bits is not divisable by 8.
And if you choose the round up approach, I'm not sure what the write
should do with the excess bits.
In any case, 8 -> BITS_PER_BYTE.
> + int ret;
>
> - if ((address > 0xFF) || !value)
> + if (address > 0xFF || !value)
This should takes bytes into account to not overflow the u8 address?
--
i.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error
2024-03-04 22:17 ` [PATCH 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Armin Wolf
2024-03-05 9:08 ` Hans de Goede
@ 2024-03-06 10:20 ` Ilpo Järvinen
1 sibling, 0 replies; 7+ messages in thread
From: Ilpo Järvinen @ 2024-03-06 10:20 UTC (permalink / raw)
To: Armin Wolf; +Cc: Hans de Goede, platform-driver-x86, LKML
[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]
On Mon, 4 Mar 2024, Armin Wolf wrote:
> 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.
>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
> drivers/platform/x86/wmi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
> index 900e0e52a5fa..be0e772a87c8 100644
> --- a/drivers/platform/x86/wmi.c
> +++ b/drivers/platform/x86/wmi.c
> @@ -1213,8 +1213,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;
> }
> }
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
--
i.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values
2024-03-06 10:19 ` Ilpo Järvinen
@ 2024-03-06 17:57 ` Armin Wolf
0 siblings, 0 replies; 7+ messages in thread
From: Armin Wolf @ 2024-03-06 17:57 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Hans de Goede, platform-driver-x86, LKML, Rafael J. Wysocki,
Len Brown
Am 06.03.24 um 11:19 schrieb Ilpo Järvinen:
> On Mon, 4 Mar 2024, Armin Wolf wrote:
>
>> 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 <W_Armin@gmx.de>
>> ---
>> drivers/platform/x86/wmi.c | 44 +++++++++++++++++++++++++++++---------
>> 1 file changed, 34 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
>> index 1920e115da89..900e0e52a5fa 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,25 @@ 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 / 8;
> I'm a quite hesitant about this. IMO, it should do DIV_ROUND_UP(bits,
> BITS_PER_BYTE) or return AE_BAD_PARAMETER when bits is not divisable by 8.
> And if you choose the round up approach, I'm not sure what the write
> should do with the excess bits.
>
> In any case, 8 -> BITS_PER_BYTE.
After taking a look at acpi_ex_access_region(), which invokes the address space handler,
i think the number of bits are always divisible by 8.
I CCed the maintainers of the ACPI EC driver, so that we can clarify if this is indeed
always the case.
Thanks,
Armin Wolf
>> + int ret;
>>
>> - if ((address > 0xFF) || !value)
>> + if (address > 0xFF || !value)
> This should takes bytes into account to not overflow the u8 address?
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-03-06 17:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-04 22:17 [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Armin Wolf
2024-03-04 22:17 ` [PATCH 2/2] platform/x86: wmi: Avoid returning AE_OK upon unknown error Armin Wolf
2024-03-05 9:08 ` Hans de Goede
2024-03-06 10:20 ` Ilpo Järvinen
2024-03-05 9:08 ` [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Hans de Goede
2024-03-06 10:19 ` Ilpo Järvinen
2024-03-06 17:57 ` Armin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox