16f2c06d5SJorge Lopez // SPDX-License-Identifier: GPL-2.0
26f2c06d5SJorge Lopez /*
36f2c06d5SJorge Lopez * Functions corresponding to integer type attributes under
46f2c06d5SJorge Lopez * BIOS Enumeration GUID for use with hp-bioscfg driver.
56f2c06d5SJorge Lopez *
66f2c06d5SJorge Lopez * Copyright (c) 2022 Hewlett-Packard Inc.
76f2c06d5SJorge Lopez */
86f2c06d5SJorge Lopez
96f2c06d5SJorge Lopez #include "bioscfg.h"
106f2c06d5SJorge Lopez
116f2c06d5SJorge Lopez GET_INSTANCE_ID(integer);
126f2c06d5SJorge Lopez
current_value_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)136f2c06d5SJorge Lopez static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
146f2c06d5SJorge Lopez {
156f2c06d5SJorge Lopez int instance_id = get_integer_instance_id(kobj);
166f2c06d5SJorge Lopez
176f2c06d5SJorge Lopez if (instance_id < 0)
186f2c06d5SJorge Lopez return -EIO;
196f2c06d5SJorge Lopez
206f2c06d5SJorge Lopez return sysfs_emit(buf, "%d\n",
216f2c06d5SJorge Lopez bioscfg_drv.integer_data[instance_id].current_value);
226f2c06d5SJorge Lopez }
236f2c06d5SJorge Lopez
246f2c06d5SJorge Lopez /**
256f2c06d5SJorge Lopez * validate_integer_input() -
266f2c06d5SJorge Lopez * Validate input of current_value against lower and upper bound
276f2c06d5SJorge Lopez *
286f2c06d5SJorge Lopez * @instance_id: The instance on which input is validated
296f2c06d5SJorge Lopez * @buf: Input value
306f2c06d5SJorge Lopez */
validate_integer_input(int instance_id,char * buf)316f2c06d5SJorge Lopez static int validate_integer_input(int instance_id, char *buf)
326f2c06d5SJorge Lopez {
336f2c06d5SJorge Lopez int in_val;
346f2c06d5SJorge Lopez int ret;
356f2c06d5SJorge Lopez struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
366f2c06d5SJorge Lopez
376f2c06d5SJorge Lopez /* BIOS treats it as a read only attribute */
386f2c06d5SJorge Lopez if (integer_data->common.is_readonly)
396f2c06d5SJorge Lopez return -EIO;
406f2c06d5SJorge Lopez
416f2c06d5SJorge Lopez ret = kstrtoint(buf, 10, &in_val);
426f2c06d5SJorge Lopez if (ret < 0)
436f2c06d5SJorge Lopez return ret;
446f2c06d5SJorge Lopez
456f2c06d5SJorge Lopez if (in_val < integer_data->lower_bound ||
466f2c06d5SJorge Lopez in_val > integer_data->upper_bound)
476f2c06d5SJorge Lopez return -ERANGE;
486f2c06d5SJorge Lopez
496f2c06d5SJorge Lopez return 0;
506f2c06d5SJorge Lopez }
516f2c06d5SJorge Lopez
update_integer_value(int instance_id,char * attr_value)526f2c06d5SJorge Lopez static void update_integer_value(int instance_id, char *attr_value)
536f2c06d5SJorge Lopez {
546f2c06d5SJorge Lopez int in_val;
556f2c06d5SJorge Lopez int ret;
566f2c06d5SJorge Lopez struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
576f2c06d5SJorge Lopez
586f2c06d5SJorge Lopez ret = kstrtoint(attr_value, 10, &in_val);
596f2c06d5SJorge Lopez if (ret == 0)
606f2c06d5SJorge Lopez integer_data->current_value = in_val;
616f2c06d5SJorge Lopez else
626f2c06d5SJorge Lopez pr_warn("Invalid integer value found: %s\n", attr_value);
636f2c06d5SJorge Lopez }
646f2c06d5SJorge Lopez
656f2c06d5SJorge Lopez ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, integer);
666f2c06d5SJorge Lopez static struct kobj_attribute integer_display_name =
676f2c06d5SJorge Lopez __ATTR_RO(display_name);
686f2c06d5SJorge Lopez
696f2c06d5SJorge Lopez ATTRIBUTE_PROPERTY_STORE(current_value, integer);
706f2c06d5SJorge Lopez static struct kobj_attribute integer_current_val =
716f2c06d5SJorge Lopez __ATTR_RW_MODE(current_value, 0644);
726f2c06d5SJorge Lopez
736f2c06d5SJorge Lopez ATTRIBUTE_N_PROPERTY_SHOW(lower_bound, integer);
746f2c06d5SJorge Lopez static struct kobj_attribute integer_lower_bound =
756f2c06d5SJorge Lopez __ATTR_RO(lower_bound);
766f2c06d5SJorge Lopez
776f2c06d5SJorge Lopez ATTRIBUTE_N_PROPERTY_SHOW(upper_bound, integer);
786f2c06d5SJorge Lopez static struct kobj_attribute integer_upper_bound =
796f2c06d5SJorge Lopez __ATTR_RO(upper_bound);
806f2c06d5SJorge Lopez
816f2c06d5SJorge Lopez ATTRIBUTE_N_PROPERTY_SHOW(scalar_increment, integer);
826f2c06d5SJorge Lopez static struct kobj_attribute integer_scalar_increment =
836f2c06d5SJorge Lopez __ATTR_RO(scalar_increment);
846f2c06d5SJorge Lopez
type_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)856f2c06d5SJorge Lopez static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
866f2c06d5SJorge Lopez char *buf)
876f2c06d5SJorge Lopez {
886f2c06d5SJorge Lopez return sysfs_emit(buf, "integer\n");
896f2c06d5SJorge Lopez }
906f2c06d5SJorge Lopez
916f2c06d5SJorge Lopez static struct kobj_attribute integer_type =
926f2c06d5SJorge Lopez __ATTR_RO(type);
936f2c06d5SJorge Lopez
946f2c06d5SJorge Lopez static struct attribute *integer_attrs[] = {
956f2c06d5SJorge Lopez &common_display_langcode.attr,
966f2c06d5SJorge Lopez &integer_display_name.attr,
976f2c06d5SJorge Lopez &integer_current_val.attr,
986f2c06d5SJorge Lopez &integer_lower_bound.attr,
996f2c06d5SJorge Lopez &integer_upper_bound.attr,
1006f2c06d5SJorge Lopez &integer_scalar_increment.attr,
1016f2c06d5SJorge Lopez &integer_type.attr,
1026f2c06d5SJorge Lopez NULL
1036f2c06d5SJorge Lopez };
1046f2c06d5SJorge Lopez
1056f2c06d5SJorge Lopez static const struct attribute_group integer_attr_group = {
1066f2c06d5SJorge Lopez .attrs = integer_attrs,
1076f2c06d5SJorge Lopez };
1086f2c06d5SJorge Lopez
hp_alloc_integer_data(void)1096f2c06d5SJorge Lopez int hp_alloc_integer_data(void)
1106f2c06d5SJorge Lopez {
1116f2c06d5SJorge Lopez bioscfg_drv.integer_instances_count = hp_get_instance_count(HP_WMI_BIOS_INTEGER_GUID);
1126f2c06d5SJorge Lopez bioscfg_drv.integer_data = kcalloc(bioscfg_drv.integer_instances_count,
1136f2c06d5SJorge Lopez sizeof(*bioscfg_drv.integer_data), GFP_KERNEL);
1146f2c06d5SJorge Lopez
1156f2c06d5SJorge Lopez if (!bioscfg_drv.integer_data) {
1166f2c06d5SJorge Lopez bioscfg_drv.integer_instances_count = 0;
1176f2c06d5SJorge Lopez return -ENOMEM;
1186f2c06d5SJorge Lopez }
1196f2c06d5SJorge Lopez return 0;
1206f2c06d5SJorge Lopez }
1216f2c06d5SJorge Lopez
1226f2c06d5SJorge Lopez /* Expected Values types associated with each element */
1236f2c06d5SJorge Lopez static const acpi_object_type expected_integer_types[] = {
1246f2c06d5SJorge Lopez [NAME] = ACPI_TYPE_STRING,
1256f2c06d5SJorge Lopez [VALUE] = ACPI_TYPE_STRING,
1266f2c06d5SJorge Lopez [PATH] = ACPI_TYPE_STRING,
1276f2c06d5SJorge Lopez [IS_READONLY] = ACPI_TYPE_INTEGER,
1286f2c06d5SJorge Lopez [DISPLAY_IN_UI] = ACPI_TYPE_INTEGER,
1296f2c06d5SJorge Lopez [REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER,
1306f2c06d5SJorge Lopez [SEQUENCE] = ACPI_TYPE_INTEGER,
1316f2c06d5SJorge Lopez [PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER,
1326f2c06d5SJorge Lopez [PREREQUISITES] = ACPI_TYPE_STRING,
1336f2c06d5SJorge Lopez [SECURITY_LEVEL] = ACPI_TYPE_INTEGER,
1346f2c06d5SJorge Lopez [INT_LOWER_BOUND] = ACPI_TYPE_INTEGER,
1356f2c06d5SJorge Lopez [INT_UPPER_BOUND] = ACPI_TYPE_INTEGER,
1366f2c06d5SJorge Lopez [INT_SCALAR_INCREMENT] = ACPI_TYPE_INTEGER,
1376f2c06d5SJorge Lopez };
1386f2c06d5SJorge Lopez
hp_populate_integer_elements_from_package(union acpi_object * integer_obj,int integer_obj_count,int instance_id)1396f2c06d5SJorge Lopez static int hp_populate_integer_elements_from_package(union acpi_object *integer_obj,
1406f2c06d5SJorge Lopez int integer_obj_count,
1416f2c06d5SJorge Lopez int instance_id)
1426f2c06d5SJorge Lopez {
1436f2c06d5SJorge Lopez char *str_value = NULL;
1446f2c06d5SJorge Lopez int value_len;
1456f2c06d5SJorge Lopez int ret;
14680d7ba30SJorge Lopez u32 int_value = 0;
1476f2c06d5SJorge Lopez int elem;
1486f2c06d5SJorge Lopez int reqs;
1496f2c06d5SJorge Lopez int eloc;
1506f2c06d5SJorge Lopez int size;
1516f2c06d5SJorge Lopez struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
1526f2c06d5SJorge Lopez
1536f2c06d5SJorge Lopez if (!integer_obj)
1546f2c06d5SJorge Lopez return -EINVAL;
1556f2c06d5SJorge Lopez
1566f2c06d5SJorge Lopez for (elem = 1, eloc = 1; elem < integer_obj_count; elem++, eloc++) {
1576f2c06d5SJorge Lopez /* ONLY look at the first INTEGER_ELEM_CNT elements */
1586f2c06d5SJorge Lopez if (eloc == INT_ELEM_CNT)
1596f2c06d5SJorge Lopez goto exit_integer_package;
1606f2c06d5SJorge Lopez
1616f2c06d5SJorge Lopez switch (integer_obj[elem].type) {
1626f2c06d5SJorge Lopez case ACPI_TYPE_STRING:
1636f2c06d5SJorge Lopez if (elem != PREREQUISITES) {
1646f2c06d5SJorge Lopez ret = hp_convert_hexstr_to_str(integer_obj[elem].string.pointer,
1656f2c06d5SJorge Lopez integer_obj[elem].string.length,
1666f2c06d5SJorge Lopez &str_value, &value_len);
1676f2c06d5SJorge Lopez if (ret)
1686f2c06d5SJorge Lopez continue;
1696f2c06d5SJorge Lopez }
1706f2c06d5SJorge Lopez break;
1716f2c06d5SJorge Lopez case ACPI_TYPE_INTEGER:
1726f2c06d5SJorge Lopez int_value = (u32)integer_obj[elem].integer.value;
1736f2c06d5SJorge Lopez break;
1746f2c06d5SJorge Lopez default:
1756f2c06d5SJorge Lopez pr_warn("Unsupported object type [%d]\n", integer_obj[elem].type);
1766f2c06d5SJorge Lopez continue;
1776f2c06d5SJorge Lopez }
1786f2c06d5SJorge Lopez /* Check that both expected and read object type match */
1796f2c06d5SJorge Lopez if (expected_integer_types[eloc] != integer_obj[elem].type) {
1806f2c06d5SJorge Lopez pr_err("Error expected type %d for elem %d, but got type %d instead\n",
1816f2c06d5SJorge Lopez expected_integer_types[eloc], elem, integer_obj[elem].type);
182467d4163SJorge Lopez kfree(str_value);
1836f2c06d5SJorge Lopez return -EIO;
1846f2c06d5SJorge Lopez }
1856f2c06d5SJorge Lopez /* Assign appropriate element value to corresponding field*/
1866f2c06d5SJorge Lopez switch (eloc) {
1876f2c06d5SJorge Lopez case VALUE:
1886f2c06d5SJorge Lopez ret = kstrtoint(str_value, 10, &int_value);
1896f2c06d5SJorge Lopez if (ret)
1906f2c06d5SJorge Lopez continue;
1916f2c06d5SJorge Lopez
1926f2c06d5SJorge Lopez integer_data->current_value = int_value;
1936f2c06d5SJorge Lopez break;
1946f2c06d5SJorge Lopez case PATH:
1956f2c06d5SJorge Lopez strscpy(integer_data->common.path, str_value,
1966f2c06d5SJorge Lopez sizeof(integer_data->common.path));
1976f2c06d5SJorge Lopez break;
1986f2c06d5SJorge Lopez case IS_READONLY:
1996f2c06d5SJorge Lopez integer_data->common.is_readonly = int_value;
2006f2c06d5SJorge Lopez break;
2016f2c06d5SJorge Lopez case DISPLAY_IN_UI:
2026f2c06d5SJorge Lopez integer_data->common.display_in_ui = int_value;
2036f2c06d5SJorge Lopez break;
2046f2c06d5SJorge Lopez case REQUIRES_PHYSICAL_PRESENCE:
2056f2c06d5SJorge Lopez integer_data->common.requires_physical_presence = int_value;
2066f2c06d5SJorge Lopez break;
2076f2c06d5SJorge Lopez case SEQUENCE:
2086f2c06d5SJorge Lopez integer_data->common.sequence = int_value;
2096f2c06d5SJorge Lopez break;
2106f2c06d5SJorge Lopez case PREREQUISITES_SIZE:
211*08f1f212SJorge Lopez if (int_value > MAX_PREREQUISITES_SIZE) {
2126f2c06d5SJorge Lopez pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
213*08f1f212SJorge Lopez int_value = MAX_PREREQUISITES_SIZE;
214*08f1f212SJorge Lopez }
215*08f1f212SJorge Lopez integer_data->common.prerequisites_size = int_value;
216*08f1f212SJorge Lopez
2176f2c06d5SJorge Lopez /*
218a585400bSJorge Lopez * This step is needed to keep the expected
2196f2c06d5SJorge Lopez * element list pointing to the right obj[elem].type
2206f2c06d5SJorge Lopez * when the size is zero. PREREQUISITES
2216f2c06d5SJorge Lopez * object is omitted by BIOS when the size is
2226f2c06d5SJorge Lopez * zero.
2236f2c06d5SJorge Lopez */
2246f2c06d5SJorge Lopez if (integer_data->common.prerequisites_size == 0)
2256f2c06d5SJorge Lopez eloc++;
2266f2c06d5SJorge Lopez break;
2276f2c06d5SJorge Lopez case PREREQUISITES:
2286f2c06d5SJorge Lopez size = min_t(u32, integer_data->common.prerequisites_size, MAX_PREREQUISITES_SIZE);
2296f2c06d5SJorge Lopez
2306f2c06d5SJorge Lopez for (reqs = 0; reqs < size; reqs++) {
2316f2c06d5SJorge Lopez if (elem >= integer_obj_count) {
2326f2c06d5SJorge Lopez pr_err("Error elem-objects package is too small\n");
2336f2c06d5SJorge Lopez return -EINVAL;
2346f2c06d5SJorge Lopez }
2356f2c06d5SJorge Lopez
2366f2c06d5SJorge Lopez ret = hp_convert_hexstr_to_str(integer_obj[elem + reqs].string.pointer,
2376f2c06d5SJorge Lopez integer_obj[elem + reqs].string.length,
2386f2c06d5SJorge Lopez &str_value, &value_len);
2396f2c06d5SJorge Lopez
2406f2c06d5SJorge Lopez if (ret)
2416f2c06d5SJorge Lopez continue;
2426f2c06d5SJorge Lopez
2436f2c06d5SJorge Lopez strscpy(integer_data->common.prerequisites[reqs],
2446f2c06d5SJorge Lopez str_value,
2456f2c06d5SJorge Lopez sizeof(integer_data->common.prerequisites[reqs]));
2466f2c06d5SJorge Lopez kfree(str_value);
247467d4163SJorge Lopez str_value = NULL;
2486f2c06d5SJorge Lopez }
2496f2c06d5SJorge Lopez break;
2506f2c06d5SJorge Lopez
2516f2c06d5SJorge Lopez case SECURITY_LEVEL:
2526f2c06d5SJorge Lopez integer_data->common.security_level = int_value;
2536f2c06d5SJorge Lopez break;
2546f2c06d5SJorge Lopez case INT_LOWER_BOUND:
2556f2c06d5SJorge Lopez integer_data->lower_bound = int_value;
2566f2c06d5SJorge Lopez break;
2576f2c06d5SJorge Lopez case INT_UPPER_BOUND:
2586f2c06d5SJorge Lopez integer_data->upper_bound = int_value;
2596f2c06d5SJorge Lopez break;
2606f2c06d5SJorge Lopez case INT_SCALAR_INCREMENT:
2616f2c06d5SJorge Lopez integer_data->scalar_increment = int_value;
2626f2c06d5SJorge Lopez break;
2636f2c06d5SJorge Lopez default:
2646f2c06d5SJorge Lopez pr_warn("Invalid element: %d found in Integer attribute or data may be malformed\n", elem);
2656f2c06d5SJorge Lopez break;
2666f2c06d5SJorge Lopez }
267467d4163SJorge Lopez
268467d4163SJorge Lopez kfree(str_value);
269467d4163SJorge Lopez str_value = NULL;
2706f2c06d5SJorge Lopez }
2716f2c06d5SJorge Lopez exit_integer_package:
2726f2c06d5SJorge Lopez kfree(str_value);
2736f2c06d5SJorge Lopez return 0;
2746f2c06d5SJorge Lopez }
2756f2c06d5SJorge Lopez
2766f2c06d5SJorge Lopez /**
2776f2c06d5SJorge Lopez * hp_populate_integer_package_data() -
2786f2c06d5SJorge Lopez * Populate all properties of an instance under integer attribute
2796f2c06d5SJorge Lopez *
2806f2c06d5SJorge Lopez * @integer_obj: ACPI object with integer data
2816f2c06d5SJorge Lopez * @instance_id: The instance to enumerate
2826f2c06d5SJorge Lopez * @attr_name_kobj: The parent kernel object
2836f2c06d5SJorge Lopez */
hp_populate_integer_package_data(union acpi_object * integer_obj,int instance_id,struct kobject * attr_name_kobj)2846f2c06d5SJorge Lopez int hp_populate_integer_package_data(union acpi_object *integer_obj,
2856f2c06d5SJorge Lopez int instance_id,
2866f2c06d5SJorge Lopez struct kobject *attr_name_kobj)
2876f2c06d5SJorge Lopez {
2886f2c06d5SJorge Lopez struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
2896f2c06d5SJorge Lopez
2906f2c06d5SJorge Lopez integer_data->attr_name_kobj = attr_name_kobj;
2916f2c06d5SJorge Lopez hp_populate_integer_elements_from_package(integer_obj,
2926f2c06d5SJorge Lopez integer_obj->package.count,
2936f2c06d5SJorge Lopez instance_id);
2946f2c06d5SJorge Lopez hp_update_attribute_permissions(integer_data->common.is_readonly,
2956f2c06d5SJorge Lopez &integer_current_val);
2966f2c06d5SJorge Lopez hp_friendly_user_name_update(integer_data->common.path,
2976f2c06d5SJorge Lopez attr_name_kobj->name,
2986f2c06d5SJorge Lopez integer_data->common.display_name,
2996f2c06d5SJorge Lopez sizeof(integer_data->common.display_name));
3006f2c06d5SJorge Lopez return sysfs_create_group(attr_name_kobj, &integer_attr_group);
3016f2c06d5SJorge Lopez }
3026f2c06d5SJorge Lopez
hp_populate_integer_elements_from_buffer(u8 * buffer_ptr,u32 * buffer_size,int instance_id)3036f2c06d5SJorge Lopez static int hp_populate_integer_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size,
3046f2c06d5SJorge Lopez int instance_id)
3056f2c06d5SJorge Lopez {
3066f2c06d5SJorge Lopez char *dst = NULL;
3076f2c06d5SJorge Lopez int dst_size = *buffer_size / sizeof(u16);
3086f2c06d5SJorge Lopez struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
3096f2c06d5SJorge Lopez int ret = 0;
3106f2c06d5SJorge Lopez
3116f2c06d5SJorge Lopez dst = kcalloc(dst_size, sizeof(char), GFP_KERNEL);
3126f2c06d5SJorge Lopez if (!dst)
3136f2c06d5SJorge Lopez return -ENOMEM;
3146f2c06d5SJorge Lopez
3156f2c06d5SJorge Lopez /*
3166f2c06d5SJorge Lopez * Only data relevant to this driver and its functionality is
3176f2c06d5SJorge Lopez * read. BIOS defines the order in which each * element is
3186f2c06d5SJorge Lopez * read. Element 0 data is not relevant to this
3196f2c06d5SJorge Lopez * driver hence it is ignored. For clarity, all element names
3206f2c06d5SJorge Lopez * (DISPLAY_IN_UI) which defines the order in which is read
3216f2c06d5SJorge Lopez * and the name matches the variable where the data is stored.
3226f2c06d5SJorge Lopez *
3236f2c06d5SJorge Lopez * In earlier implementation, reported errors were ignored
3246f2c06d5SJorge Lopez * causing the data to remain uninitialized. It is not
3256f2c06d5SJorge Lopez * possible to determine if data read from BIOS is valid or
3266f2c06d5SJorge Lopez * not. It is for this reason functions may return a error
3276f2c06d5SJorge Lopez * without validating the data itself.
3286f2c06d5SJorge Lopez */
3296f2c06d5SJorge Lopez
3306f2c06d5SJorge Lopez // VALUE:
3316f2c06d5SJorge Lopez integer_data->current_value = 0;
3326f2c06d5SJorge Lopez
3336f2c06d5SJorge Lopez hp_get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size);
3346f2c06d5SJorge Lopez ret = kstrtoint(dst, 10, &integer_data->current_value);
3356f2c06d5SJorge Lopez if (ret)
3366f2c06d5SJorge Lopez pr_warn("Unable to convert string to integer: %s\n", dst);
3376f2c06d5SJorge Lopez kfree(dst);
3386f2c06d5SJorge Lopez
3396f2c06d5SJorge Lopez // COMMON:
3406f2c06d5SJorge Lopez ret = hp_get_common_data_from_buffer(&buffer_ptr, buffer_size, &integer_data->common);
3416f2c06d5SJorge Lopez if (ret < 0)
3426f2c06d5SJorge Lopez goto buffer_exit;
3436f2c06d5SJorge Lopez
3446f2c06d5SJorge Lopez // INT_LOWER_BOUND:
3456f2c06d5SJorge Lopez ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
3466f2c06d5SJorge Lopez &integer_data->lower_bound);
3476f2c06d5SJorge Lopez if (ret < 0)
3486f2c06d5SJorge Lopez goto buffer_exit;
3496f2c06d5SJorge Lopez
3506f2c06d5SJorge Lopez // INT_UPPER_BOUND:
3516f2c06d5SJorge Lopez ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
3526f2c06d5SJorge Lopez &integer_data->upper_bound);
3536f2c06d5SJorge Lopez if (ret < 0)
3546f2c06d5SJorge Lopez goto buffer_exit;
3556f2c06d5SJorge Lopez
3566f2c06d5SJorge Lopez // INT_SCALAR_INCREMENT:
3576f2c06d5SJorge Lopez ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
3586f2c06d5SJorge Lopez &integer_data->scalar_increment);
3596f2c06d5SJorge Lopez
3606f2c06d5SJorge Lopez buffer_exit:
3616f2c06d5SJorge Lopez return ret;
3626f2c06d5SJorge Lopez }
3636f2c06d5SJorge Lopez
3646f2c06d5SJorge Lopez /**
3656f2c06d5SJorge Lopez * hp_populate_integer_buffer_data() -
3666f2c06d5SJorge Lopez * Populate all properties of an instance under integer attribute
3676f2c06d5SJorge Lopez *
3686f2c06d5SJorge Lopez * @buffer_ptr: Buffer pointer
3696f2c06d5SJorge Lopez * @buffer_size: Buffer size
3706f2c06d5SJorge Lopez * @instance_id: The instance to enumerate
3716f2c06d5SJorge Lopez * @attr_name_kobj: The parent kernel object
3726f2c06d5SJorge Lopez */
hp_populate_integer_buffer_data(u8 * buffer_ptr,u32 * buffer_size,int instance_id,struct kobject * attr_name_kobj)3736f2c06d5SJorge Lopez int hp_populate_integer_buffer_data(u8 *buffer_ptr, u32 *buffer_size, int instance_id,
3746f2c06d5SJorge Lopez struct kobject *attr_name_kobj)
3756f2c06d5SJorge Lopez {
3766f2c06d5SJorge Lopez struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
3776f2c06d5SJorge Lopez int ret = 0;
3786f2c06d5SJorge Lopez
3796f2c06d5SJorge Lopez integer_data->attr_name_kobj = attr_name_kobj;
3806f2c06d5SJorge Lopez
3816f2c06d5SJorge Lopez /* Populate integer elements */
3826f2c06d5SJorge Lopez ret = hp_populate_integer_elements_from_buffer(buffer_ptr, buffer_size,
3836f2c06d5SJorge Lopez instance_id);
3846f2c06d5SJorge Lopez if (ret < 0)
3856f2c06d5SJorge Lopez return ret;
3866f2c06d5SJorge Lopez
3876f2c06d5SJorge Lopez hp_update_attribute_permissions(integer_data->common.is_readonly,
3886f2c06d5SJorge Lopez &integer_current_val);
3896f2c06d5SJorge Lopez hp_friendly_user_name_update(integer_data->common.path,
3906f2c06d5SJorge Lopez attr_name_kobj->name,
3916f2c06d5SJorge Lopez integer_data->common.display_name,
3926f2c06d5SJorge Lopez sizeof(integer_data->common.display_name));
3936f2c06d5SJorge Lopez
3946f2c06d5SJorge Lopez return sysfs_create_group(attr_name_kobj, &integer_attr_group);
3956f2c06d5SJorge Lopez }
3966f2c06d5SJorge Lopez
3976f2c06d5SJorge Lopez /**
3986f2c06d5SJorge Lopez * hp_exit_integer_attributes() - Clear all attribute data
3996f2c06d5SJorge Lopez *
4006f2c06d5SJorge Lopez * Clears all data allocated for this group of attributes
4016f2c06d5SJorge Lopez */
hp_exit_integer_attributes(void)4026f2c06d5SJorge Lopez void hp_exit_integer_attributes(void)
4036f2c06d5SJorge Lopez {
4046f2c06d5SJorge Lopez int instance_id;
4056f2c06d5SJorge Lopez
4066f2c06d5SJorge Lopez for (instance_id = 0; instance_id < bioscfg_drv.integer_instances_count;
4076f2c06d5SJorge Lopez instance_id++) {
4086f2c06d5SJorge Lopez struct kobject *attr_name_kobj =
4096f2c06d5SJorge Lopez bioscfg_drv.integer_data[instance_id].attr_name_kobj;
4106f2c06d5SJorge Lopez
4116f2c06d5SJorge Lopez if (attr_name_kobj)
4126f2c06d5SJorge Lopez sysfs_remove_group(attr_name_kobj, &integer_attr_group);
4136f2c06d5SJorge Lopez }
4146f2c06d5SJorge Lopez bioscfg_drv.integer_instances_count = 0;
4156f2c06d5SJorge Lopez
4166f2c06d5SJorge Lopez kfree(bioscfg_drv.integer_data);
4176f2c06d5SJorge Lopez bioscfg_drv.integer_data = NULL;
4186f2c06d5SJorge Lopez }
419