1 // SPDX-License-Identifier: GPL-2.0
3 * Functions corresponding to string type attributes under BIOS String GUID for use with
6 * Copyright (c) 2020 Dell Inc.
9 #include "dell-wmi-sysman.h"
11 enum string_properties {MIN_LEN = 6, MAX_LEN};
15 static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
17 int instance_id = get_str_instance_id(kobj);
18 union acpi_object *obj;
24 /* need to use specific instance_id and guid combination to get right data */
25 obj = get_wmiobj_pointer(instance_id, DELL_WMI_BIOS_STRING_ATTRIBUTE_GUID);
28 if (obj->package.elements[CURRENT_VAL].type != ACPI_TYPE_STRING) {
32 ret = snprintf(buf, PAGE_SIZE, "%s\n", obj->package.elements[CURRENT_VAL].string.pointer);
38 * validate_str_input() - Validate input of current_value against min and max lengths
39 * @instance_id: The instance on which input is validated
42 static int validate_str_input(int instance_id, const char *buf)
44 int in_len = strlen(buf);
46 if ((in_len < wmi_priv.str_data[instance_id].min_length) ||
47 (in_len > wmi_priv.str_data[instance_id].max_length))
53 attribute_s_property_show(display_name_language_code, str);
54 static struct kobj_attribute str_displ_langcode =
55 __ATTR_RO(display_name_language_code);
57 attribute_s_property_show(display_name, str);
58 static struct kobj_attribute str_displ_name =
59 __ATTR_RO(display_name);
61 attribute_s_property_show(default_value, str);
62 static struct kobj_attribute str_default_val =
63 __ATTR_RO(default_value);
65 attribute_property_store(current_value, str);
66 static struct kobj_attribute str_current_val =
67 __ATTR_RW_MODE(current_value, 0600);
69 attribute_s_property_show(dell_modifier, str);
70 static struct kobj_attribute str_modifier =
71 __ATTR_RO(dell_modifier);
73 attribute_n_property_show(min_length, str);
74 static struct kobj_attribute str_min_length =
75 __ATTR_RO(min_length);
77 attribute_n_property_show(max_length, str);
78 static struct kobj_attribute str_max_length =
79 __ATTR_RO(max_length);
81 static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
84 return sprintf(buf, "string\n");
86 static struct kobj_attribute str_type =
89 static struct attribute *str_attrs[] = {
90 &str_displ_langcode.attr,
92 &str_default_val.attr,
93 &str_current_val.attr,
101 static const struct attribute_group str_attr_group = {
105 int alloc_str_data(void)
109 wmi_priv.str_instances_count = get_instance_count(DELL_WMI_BIOS_STRING_ATTRIBUTE_GUID);
110 wmi_priv.str_data = kcalloc(wmi_priv.str_instances_count,
111 sizeof(struct str_data), GFP_KERNEL);
112 if (!wmi_priv.str_data) {
113 wmi_priv.str_instances_count = 0;
120 * populate_str_data() - Populate all properties of an instance under string attribute
121 * @str_obj: ACPI object with integer data
122 * @instance_id: The instance to enumerate
123 * @attr_name_kobj: The parent kernel object
125 int populate_str_data(union acpi_object *str_obj, int instance_id, struct kobject *attr_name_kobj)
127 wmi_priv.str_data[instance_id].attr_name_kobj = attr_name_kobj;
128 strlcpy_attr(wmi_priv.str_data[instance_id].attribute_name,
129 str_obj[ATTR_NAME].string.pointer);
130 strlcpy_attr(wmi_priv.str_data[instance_id].display_name_language_code,
131 str_obj[DISPL_NAME_LANG_CODE].string.pointer);
132 strlcpy_attr(wmi_priv.str_data[instance_id].display_name,
133 str_obj[DISPLAY_NAME].string.pointer);
134 strlcpy_attr(wmi_priv.str_data[instance_id].default_value,
135 str_obj[DEFAULT_VAL].string.pointer);
136 strlcpy_attr(wmi_priv.str_data[instance_id].dell_modifier,
137 str_obj[MODIFIER].string.pointer);
138 wmi_priv.str_data[instance_id].min_length = (uintptr_t)str_obj[MIN_LEN].string.pointer;
139 wmi_priv.str_data[instance_id].max_length = (uintptr_t) str_obj[MAX_LEN].string.pointer;
141 return sysfs_create_group(attr_name_kobj, &str_attr_group);
145 * exit_str_attributes() - Clear all attribute data
147 * Clears all data allocated for this group of attributes
149 void exit_str_attributes(void)
153 for (instance_id = 0; instance_id < wmi_priv.str_instances_count; instance_id++) {
154 if (wmi_priv.str_data[instance_id].attr_name_kobj)
155 sysfs_remove_group(wmi_priv.str_data[instance_id].attr_name_kobj,
158 kfree(wmi_priv.str_data);