1 /* SPDX-License-Identifier: GPL-2.0 2 * Definitions for kernel modules using Dell WMI System Management Driver 3 * 4 * Copyright (c) 2020 Dell Inc. 5 */ 6 7 #ifndef _DELL_WMI_BIOS_ATTR_H_ 8 #define _DELL_WMI_BIOS_ATTR_H_ 9 10 #include <linux/wmi.h> 11 #include <linux/device.h> 12 #include <linux/module.h> 13 #include <linux/kernel.h> 14 #include <linux/capability.h> 15 16 #define DRIVER_NAME "dell-wmi-sysman" 17 #define MAX_BUFF 512 18 19 #define DELL_WMI_BIOS_ENUMERATION_ATTRIBUTE_GUID "F1DDEE52-063C-4784-A11E-8A06684B9BF5" 20 #define DELL_WMI_BIOS_INTEGER_ATTRIBUTE_GUID "F1DDEE52-063C-4784-A11E-8A06684B9BFA" 21 #define DELL_WMI_BIOS_STRING_ATTRIBUTE_GUID "F1DDEE52-063C-4784-A11E-8A06684B9BF9" 22 #define DELL_WMI_BIOS_PASSOBJ_ATTRIBUTE_GUID "0894B8D6-44A6-4719-97D7-6AD24108BFD4" 23 #define DELL_WMI_BIOS_ATTRIBUTES_INTERFACE_GUID "F1DDEE52-063C-4784-A11E-8A06684B9BF4" 24 #define DELL_WMI_BIOS_PASSWORD_INTERFACE_GUID "70FE8229-D03B-4214-A1C6-1F884B1A892A" 25 26 struct enumeration_data { 27 struct kobject *attr_name_kobj; 28 char display_name_language_code[MAX_BUFF]; 29 char dell_value_modifier[MAX_BUFF]; 30 char possible_values[MAX_BUFF]; 31 char attribute_name[MAX_BUFF]; 32 char default_value[MAX_BUFF]; 33 char dell_modifier[MAX_BUFF]; 34 char display_name[MAX_BUFF]; 35 }; 36 37 struct integer_data { 38 struct kobject *attr_name_kobj; 39 char display_name_language_code[MAX_BUFF]; 40 char attribute_name[MAX_BUFF]; 41 char dell_modifier[MAX_BUFF]; 42 char display_name[MAX_BUFF]; 43 int scalar_increment; 44 int default_value; 45 int min_value; 46 int max_value; 47 }; 48 49 struct str_data { 50 struct kobject *attr_name_kobj; 51 char display_name_language_code[MAX_BUFF]; 52 char attribute_name[MAX_BUFF]; 53 char display_name[MAX_BUFF]; 54 char default_value[MAX_BUFF]; 55 char dell_modifier[MAX_BUFF]; 56 int min_length; 57 int max_length; 58 }; 59 60 struct po_data { 61 struct kobject *attr_name_kobj; 62 char attribute_name[MAX_BUFF]; 63 int min_password_length; 64 int max_password_length; 65 }; 66 67 struct wmi_sysman_priv { 68 char current_admin_password[MAX_BUFF]; 69 char current_system_password[MAX_BUFF]; 70 struct wmi_device *password_attr_wdev; 71 struct wmi_device *bios_attr_wdev; 72 struct kset *authentication_dir_kset; 73 struct kset *main_dir_kset; 74 struct device *class_dev; 75 struct enumeration_data *enumeration_data; 76 int enumeration_instances_count; 77 struct integer_data *integer_data; 78 int integer_instances_count; 79 struct str_data *str_data; 80 int str_instances_count; 81 struct po_data *po_data; 82 int po_instances_count; 83 bool pending_changes; 84 struct mutex mutex; 85 }; 86 87 /* global structure used by multiple WMI interfaces */ 88 extern struct wmi_sysman_priv wmi_priv; 89 90 enum { ENUM, INT, STR, PO }; 91 92 enum { 93 ATTR_NAME, 94 DISPL_NAME_LANG_CODE, 95 DISPLAY_NAME, 96 DEFAULT_VAL, 97 CURRENT_VAL, 98 MODIFIER 99 }; 100 101 #define get_instance_id(type) \ 102 static int get_##type##_instance_id(struct kobject *kobj) \ 103 { \ 104 int i; \ 105 for (i = 0; i <= wmi_priv.type##_instances_count; i++) { \ 106 if (!(strcmp(kobj->name, wmi_priv.type##_data[i].attribute_name)))\ 107 return i; \ 108 } \ 109 return -EIO; \ 110 } 111 112 #define attribute_s_property_show(name, type) \ 113 static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \ 114 char *buf) \ 115 { \ 116 int i = get_##type##_instance_id(kobj); \ 117 if (i >= 0) \ 118 return sprintf(buf, "%s\n", wmi_priv.type##_data[i].name); \ 119 return 0; \ 120 } 121 122 #define attribute_n_property_show(name, type) \ 123 static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \ 124 char *buf) \ 125 { \ 126 int i = get_##type##_instance_id(kobj); \ 127 if (i >= 0) \ 128 return sprintf(buf, "%d\n", wmi_priv.type##_data[i].name); \ 129 return 0; \ 130 } 131 132 #define attribute_property_store(curr_val, type) \ 133 static ssize_t curr_val##_store(struct kobject *kobj, \ 134 struct kobj_attribute *attr, \ 135 const char *buf, size_t count) \ 136 { \ 137 char *p, *buf_cp; \ 138 int i, ret = -EIO; \ 139 buf_cp = kstrdup(buf, GFP_KERNEL); \ 140 if (!buf_cp) \ 141 return -ENOMEM; \ 142 p = memchr(buf_cp, '\n', count); \ 143 \ 144 if (p != NULL) \ 145 *p = '\0'; \ 146 i = get_##type##_instance_id(kobj); \ 147 if (i >= 0) \ 148 ret = validate_##type##_input(i, buf_cp); \ 149 if (!ret) \ 150 ret = set_attribute(kobj->name, buf_cp); \ 151 kfree(buf_cp); \ 152 return ret ? ret : count; \ 153 } 154 155 union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string); 156 int get_instance_count(const char *guid_string); 157 void strlcpy_attr(char *dest, char *src); 158 159 int populate_enum_data(union acpi_object *enumeration_obj, int instance_id, 160 struct kobject *attr_name_kobj); 161 int alloc_enum_data(void); 162 void exit_enum_attributes(void); 163 164 int populate_int_data(union acpi_object *integer_obj, int instance_id, 165 struct kobject *attr_name_kobj); 166 int alloc_int_data(void); 167 void exit_int_attributes(void); 168 169 int populate_str_data(union acpi_object *str_obj, int instance_id, struct kobject *attr_name_kobj); 170 int alloc_str_data(void); 171 void exit_str_attributes(void); 172 173 int populate_po_data(union acpi_object *po_obj, int instance_id, struct kobject *attr_name_kobj); 174 int alloc_po_data(void); 175 void exit_po_attributes(void); 176 177 int set_attribute(const char *a_name, const char *a_value); 178 int set_bios_defaults(u8 defType); 179 180 void exit_bios_attr_set_interface(void); 181 int init_bios_attr_set_interface(void); 182 int map_wmi_error(int error_code); 183 size_t calculate_string_buffer(const char *str); 184 size_t calculate_security_buffer(char *authentication); 185 void populate_security_buffer(char *buffer, char *authentication); 186 ssize_t populate_string_buffer(char *buffer, size_t buffer_len, const char *str); 187 int set_new_password(const char *password_type, const char *new); 188 int init_bios_attr_pass_interface(void); 189 void exit_bios_attr_pass_interface(void); 190 191 #endif 192