// SPDX-License-Identifier: GPL-2.0 /* * Common methods for use with dell-wmi-sysman * * Copyright (c) 2020 Dell Inc. */ #define pr_fmt(fmt) … #include <linux/fs.h> #include <linux/dmi.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/wmi.h> #include "dell-wmi-sysman.h" #include "../../firmware_attributes_class.h" #define MAX_TYPES … #include <linux/nls.h> struct wmi_sysman_priv wmi_priv = …; /* reset bios to defaults */ static const char * const reset_types[] = …; static int reset_option = …; static const struct class *fw_attr_class; /** * populate_string_buffer() - populates a string buffer * @buffer: the start of the destination buffer * @buffer_len: length of the destination buffer * @str: the string to insert into buffer */ ssize_t populate_string_buffer(char *buffer, size_t buffer_len, const char *str) { … } /** * calculate_string_buffer() - determines size of string buffer for use with BIOS communication * @str: the string to calculate based upon * */ size_t calculate_string_buffer(const char *str) { … } /** * calculate_security_buffer() - determines size of security buffer for authentication scheme * @authentication: the authentication content * * Currently only supported type is Admin password */ size_t calculate_security_buffer(char *authentication) { … } /** * populate_security_buffer() - builds a security buffer for authentication scheme * @buffer: the buffer to populate * @authentication: the authentication content * * Currently only supported type is PLAIN TEXT */ void populate_security_buffer(char *buffer, char *authentication) { … } /** * map_wmi_error() - map errors from WMI methods to kernel error codes * @error_code: integer error code returned from Dell's firmware */ int map_wmi_error(int error_code) { … } /** * reset_bios_show() - sysfs implementaton for read reset_bios * @kobj: Kernel object for this attribute * @attr: Kernel object attribute * @buf: The buffer to display to userspace */ static ssize_t reset_bios_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { … } /** * reset_bios_store() - sysfs implementaton for write reset_bios * @kobj: Kernel object for this attribute * @attr: Kernel object attribute * @buf: The buffer from userspace * @count: the size of the buffer from userspace */ static ssize_t reset_bios_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { … } /** * pending_reboot_show() - sysfs implementaton for read pending_reboot * @kobj: Kernel object for this attribute * @attr: Kernel object attribute * @buf: The buffer to display to userspace * * Stores default value as 0 * When current_value is changed this attribute is set to 1 to notify reboot may be required */ static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { … } static struct kobj_attribute reset_bios = …; static struct kobj_attribute pending_reboot = …; /** * create_attributes_level_sysfs_files() - Creates reset_bios and * pending_reboot attributes */ static int create_attributes_level_sysfs_files(void) { … } static ssize_t wmi_sysman_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) { … } static ssize_t wmi_sysman_attr_store(struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) { … } static const struct sysfs_ops wmi_sysman_kobj_sysfs_ops = …; static void attr_name_release(struct kobject *kobj) { … } static const struct kobj_type attr_name_ktype = …; /** * strlcpy_attr - Copy a length-limited, NULL-terminated string with bound checks * @dest: Where to copy the string to * @src: Where to copy the string from */ void strlcpy_attr(char *dest, char *src) { … } /** * get_wmiobj_pointer() - Get Content of WMI block for particular instance * @instance_id: WMI instance ID * @guid_string: WMI GUID (in str form) * * Fetches the content for WMI block (instance_id) under GUID (guid_string) * Caller must kfree the return */ union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string) { … } /** * get_instance_count() - Compute total number of instances under guid_string * @guid_string: WMI GUID (in string form) */ int get_instance_count(const char *guid_string) { … } /** * alloc_attributes_data() - Allocate attributes data for a particular type * @attr_type: Attribute type to allocate */ static int alloc_attributes_data(int attr_type) { … } /** * destroy_attribute_objs() - Free a kset of kobjects * @kset: The kset to destroy * * Fress kobjects created for each attribute_name under attribute type kset */ static void destroy_attribute_objs(struct kset *kset) { … } /** * release_attributes_data() - Clean-up all sysfs directories and files created */ static void release_attributes_data(void) { … } /** * init_bios_attributes() - Initialize all attributes for a type * @attr_type: The attribute type to initialize * @guid: The WMI GUID associated with this type to initialize * * Initialiaze all 4 types of attributes enumeration, integer, string and password object. * Populates each attrbute typ's respective properties under sysfs files */ static int init_bios_attributes(int attr_type, const char *guid) { … } static int __init sysman_init(void) { … } static void __exit sysman_exit(void) { … } module_init(…) …; module_exit(sysman_exit); MODULE_AUTHOR(…) …; MODULE_AUTHOR(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;