* [PATCH v2 1/2] platform/x86: think-lmi: add missing type attribute
@ 2023-03-13 18:45 Mark Pearson
2023-03-13 18:45 ` [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation Mark Pearson
0 siblings, 1 reply; 5+ messages in thread
From: Mark Pearson @ 2023-03-13 18:45 UTC (permalink / raw)
To: mpearson-lenovo; +Cc: hdegoede, markgross, markpearson, platform-driver-x86
This driver was missing the mandatory type attribute...oops.
Add it in along with logic to determine whether the attribute is an
enumeration type or a string by parsing the possible_values attribute.
Upstream bug https://bugzilla.kernel.org/show_bug.cgi?id=216460
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
Changes in v2:
- Simplify the code and move type determination into show function
- Don't use Fixes with URL in commit info
drivers/platform/x86/think-lmi.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index 86b33b74519b..5fa5451c4802 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -947,6 +947,20 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute
return sysfs_emit(buf, "%s\n", setting->possible_values);
}
+static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+
+ if (setting->possible_values) {
+ /* Figure out what setting type is as BIOS does not return this */
+ if (strchr(setting->possible_values, ','))
+ return sysfs_emit(buf, "enumeration\n");
+ }
+ /* Anything else is going to be a string */
+ return sysfs_emit(buf, "string\n");
+}
+
static ssize_t current_value_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
@@ -1036,10 +1050,13 @@ static struct kobj_attribute attr_possible_values = __ATTR_RO(possible_values);
static struct kobj_attribute attr_current_val = __ATTR_RW_MODE(current_value, 0600);
+static struct kobj_attribute attr_type = __ATTR_RO(type);
+
static struct attribute *tlmi_attrs[] = {
&attr_displ_name.attr,
&attr_current_val.attr,
&attr_possible_values.attr,
+ &attr_type.attr,
NULL
};
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation
2023-03-13 18:45 [PATCH v2 1/2] platform/x86: think-lmi: add missing type attribute Mark Pearson
@ 2023-03-13 18:45 ` Mark Pearson
2023-03-13 23:58 ` Thomas Weißschuh
0 siblings, 1 reply; 5+ messages in thread
From: Mark Pearson @ 2023-03-13 18:45 UTC (permalink / raw)
To: mpearson-lenovo; +Cc: hdegoede, markgross, markpearson, platform-driver-x86
ThinkStation platforms don't support the API to return possible_values
but instead embed it in the settings string.
Try and extract this information and set the possible_values attribute
appropriately.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
Changes in V2:
- Move no value for possible_values handling into show function
- use kstrndup for allocating string
drivers/platform/x86/think-lmi.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index 5fa5451c4802..7dd8f72176f5 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -941,10 +941,9 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute
{
struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
- if (!tlmi_priv.can_get_bios_selections)
- return -EOPNOTSUPP;
-
- return sysfs_emit(buf, "%s\n", setting->possible_values);
+ if (setting->possible_values)
+ return sysfs_emit(buf, "%s\n", setting->possible_values);
+ return sysfs_emit(buf, "not available\n");
}
static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
@@ -1440,6 +1439,25 @@ static int tlmi_analyze(void)
if (ret || !setting->possible_values)
pr_info("Error retrieving possible values for %d : %s\n",
i, setting->display_name);
+ } else {
+ /*
+ * Older Thinkstations don't support the bios_selections API.
+ * Instead they store this as a [Optional:Option1,Option2] section of the
+ * name string.
+ * Try and pull that out if it's available.
+ */
+ char *item, *optstart, *optend;
+
+ if (!tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID)) {
+ optstart = strstr(item, "[Optional:");
+ if (optstart) {
+ optstart += strlen("[Optional:");
+ optend = strstr(optstart, "]");
+ if (optend)
+ setting->possible_values =
+ kstrndup(optstart, optend - optstart, GFP_KERNEL);
+ }
+ }
}
kobject_init(&setting->kobj, &tlmi_attr_setting_ktype);
tlmi_priv.setting[i] = setting;
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation
2023-03-13 18:45 ` [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation Mark Pearson
@ 2023-03-13 23:58 ` Thomas Weißschuh
2023-03-14 20:14 ` Mark Pearson
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Weißschuh @ 2023-03-13 23:58 UTC (permalink / raw)
To: Mark Pearson; +Cc: hdegoede, markgross, markpearson, platform-driver-x86
Hi Mark,
some more remarks, sorry not seeing this earlier.
On Mon, Mar 13, 2023 at 02:45:41PM -0400, Mark Pearson wrote:
> ThinkStation platforms don't support the API to return possible_values
> but instead embed it in the settings string.
>
> Try and extract this information and set the possible_values attribute
> appropriately.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> Changes in V2:
> - Move no value for possible_values handling into show function
> - use kstrndup for allocating string
>
> drivers/platform/x86/think-lmi.c | 26 ++++++++++++++++++++++----
> 1 file changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
> index 5fa5451c4802..7dd8f72176f5 100644
> --- a/drivers/platform/x86/think-lmi.c
> +++ b/drivers/platform/x86/think-lmi.c
> @@ -941,10 +941,9 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute
> {
> struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>
> - if (!tlmi_priv.can_get_bios_selections)
> - return -EOPNOTSUPP;
> -
> - return sysfs_emit(buf, "%s\n", setting->possible_values);
> + if (setting->possible_values)
> + return sysfs_emit(buf, "%s\n", setting->possible_values);
> + return sysfs_emit(buf, "not available\n");
> }
As the attribute "possible_values" is not mandatory it should be
possible to hide it completely with an is_visible callback.
This would indicate absence clearer than a magic value.
> static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
> @@ -1440,6 +1439,25 @@ static int tlmi_analyze(void)
> if (ret || !setting->possible_values)
> pr_info("Error retrieving possible values for %d : %s\n",
> i, setting->display_name);
> + } else {
> + /*
> + * Older Thinkstations don't support the bios_selections API.
> + * Instead they store this as a [Optional:Option1,Option2] section of the
> + * name string.
> + * Try and pull that out if it's available.
> + */
The values in possible_values are supposed to be separated by
semi-colons, not commas.
I don't know how this affects the existing parts of this driver but it
affects both patches of this series.
> + char *item, *optstart, *optend;
> +
> + if (!tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID)) {
> + optstart = strstr(item, "[Optional:");
> + if (optstart) {
> + optstart += strlen("[Optional:");
> + optend = strstr(optstart, "]");
> + if (optend)
> + setting->possible_values =
> + kstrndup(optstart, optend - optstart, GFP_KERNEL);
> + }
> + }
> }
> kobject_init(&setting->kobj, &tlmi_attr_setting_ktype);
> tlmi_priv.setting[i] = setting;
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation
2023-03-13 23:58 ` Thomas Weißschuh
@ 2023-03-14 20:14 ` Mark Pearson
2023-03-15 12:44 ` Hans de Goede
0 siblings, 1 reply; 5+ messages in thread
From: Mark Pearson @ 2023-03-14 20:14 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Hans de Goede, markgross, Mark Pearson, platform-driver-x86
Hi Thomas,
On Mon, Mar 13, 2023, at 7:58 PM, Thomas Weißschuh wrote:
> Hi Mark,
>
> some more remarks, sorry not seeing this earlier.
No worries :) I appreciate the reviews.
>
> On Mon, Mar 13, 2023 at 02:45:41PM -0400, Mark Pearson wrote:
>> ThinkStation platforms don't support the API to return possible_values
>> but instead embed it in the settings string.
>>
>> Try and extract this information and set the possible_values attribute
>> appropriately.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> Changes in V2:
>> - Move no value for possible_values handling into show function
>> - use kstrndup for allocating string
>>
>> drivers/platform/x86/think-lmi.c | 26 ++++++++++++++++++++++----
>> 1 file changed, 22 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
>> index 5fa5451c4802..7dd8f72176f5 100644
>> --- a/drivers/platform/x86/think-lmi.c
>> +++ b/drivers/platform/x86/think-lmi.c
>> @@ -941,10 +941,9 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute
>> {
>> struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>>
>> - if (!tlmi_priv.can_get_bios_selections)
>> - return -EOPNOTSUPP;
>> -
>> - return sysfs_emit(buf, "%s\n", setting->possible_values);
>> + if (setting->possible_values)
>> + return sysfs_emit(buf, "%s\n", setting->possible_values);
>> + return sysfs_emit(buf, "not available\n");
>> }
>
> As the attribute "possible_values" is not mandatory it should be
> possible to hide it completely with an is_visible callback.
>
> This would indicate absence clearer than a magic value.
Agreed - I like it. I'll look into implementing that. Thank you.
>
>> static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
>> @@ -1440,6 +1439,25 @@ static int tlmi_analyze(void)
>> if (ret || !setting->possible_values)
>> pr_info("Error retrieving possible values for %d : %s\n",
>> i, setting->display_name);
>> + } else {
>> + /*
>> + * Older Thinkstations don't support the bios_selections API.
>> + * Instead they store this as a [Optional:Option1,Option2] section of the
>> + * name string.
>> + * Try and pull that out if it's available.
>> + */
>
> The values in possible_values are supposed to be separated by
> semi-colons, not commas.
> I don't know how this affects the existing parts of this driver but it
> affects both patches of this series.
Good point, and I'd missed that.
The current string is returned directly from the BIOS, so I'll have to manipulate it. I would ask the BIOS team to change it but it will take forever and could impact Windows - so better to tweak it in the driver.
I'll do this as a third patch I think.
Thanks
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation
2023-03-14 20:14 ` Mark Pearson
@ 2023-03-15 12:44 ` Hans de Goede
0 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2023-03-15 12:44 UTC (permalink / raw)
To: Mark Pearson, Thomas Weißschuh
Cc: markgross, Mark Pearson, platform-driver-x86
Hi,
On 3/14/23 21:14, Mark Pearson wrote:
> Hi Thomas,
>
> On Mon, Mar 13, 2023, at 7:58 PM, Thomas Weißschuh wrote:
>> Hi Mark,
>>
>> some more remarks, sorry not seeing this earlier.
>
> No worries :) I appreciate the reviews.
>
>>
>> On Mon, Mar 13, 2023 at 02:45:41PM -0400, Mark Pearson wrote:
>>> ThinkStation platforms don't support the API to return possible_values
>>> but instead embed it in the settings string.
>>>
>>> Try and extract this information and set the possible_values attribute
>>> appropriately.
>>>
>>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>>> ---
>>> Changes in V2:
>>> - Move no value for possible_values handling into show function
>>> - use kstrndup for allocating string
>>>
>>> drivers/platform/x86/think-lmi.c | 26 ++++++++++++++++++++++----
>>> 1 file changed, 22 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
>>> index 5fa5451c4802..7dd8f72176f5 100644
>>> --- a/drivers/platform/x86/think-lmi.c
>>> +++ b/drivers/platform/x86/think-lmi.c
>>> @@ -941,10 +941,9 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute
>>> {
>>> struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>>>
>>> - if (!tlmi_priv.can_get_bios_selections)
>>> - return -EOPNOTSUPP;
>>> -
>>> - return sysfs_emit(buf, "%s\n", setting->possible_values);
>>> + if (setting->possible_values)
>>> + return sysfs_emit(buf, "%s\n", setting->possible_values);
>>> + return sysfs_emit(buf, "not available\n");
>>> }
>>
>> As the attribute "possible_values" is not mandatory it should be
>> possible to hide it completely with an is_visible callback.
>>
>> This would indicate absence clearer than a magic value.
>
> Agreed - I like it. I'll look into implementing that. Thank you.
>
>>
>>> static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
>>> @@ -1440,6 +1439,25 @@ static int tlmi_analyze(void)
>>> if (ret || !setting->possible_values)
>>> pr_info("Error retrieving possible values for %d : %s\n",
>>> i, setting->display_name);
>>> + } else {
>>> + /*
>>> + * Older Thinkstations don't support the bios_selections API.
>>> + * Instead they store this as a [Optional:Option1,Option2] section of the
>>> + * name string.
>>> + * Try and pull that out if it's available.
>>> + */
>>
>> The values in possible_values are supposed to be separated by
>> semi-colons, not commas.
>> I don't know how this affects the existing parts of this driver but it
>> affects both patches of this series.
>
> Good point, and I'd missed that.
> The current string is returned directly from the BIOS, so I'll have to manipulate it. I would ask the BIOS team to change it but it will take forever and could impact Windows - so better to tweak it in the driver.
> I'll do this as a third patch I think.
Yes putting this in a separate / third patch seems best.
Regards,
Hans
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-15 12:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-13 18:45 [PATCH v2 1/2] platform/x86: think-lmi: add missing type attribute Mark Pearson
2023-03-13 18:45 ` [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation Mark Pearson
2023-03-13 23:58 ` Thomas Weißschuh
2023-03-14 20:14 ` Mark Pearson
2023-03-15 12:44 ` Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).