cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

dell-wmi-sysman.h (5920B)


      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
     26struct 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
     37struct 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
     49struct 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
     60struct 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
     67struct 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 */
     88extern struct wmi_sysman_priv wmi_priv;
     89
     90enum { ENUM, INT, STR, PO };
     91
     92enum {
     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)							\
    102static 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)					\
    113static 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)					\
    123static 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)				\
    133static 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#define check_property_type(attr, prop, valuetype)				\
    156	(attr##_obj[prop].type != valuetype)
    157
    158union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string);
    159int get_instance_count(const char *guid_string);
    160void strlcpy_attr(char *dest, char *src);
    161
    162int populate_enum_data(union acpi_object *enumeration_obj, int instance_id,
    163			struct kobject *attr_name_kobj, u32 enum_property_count);
    164int alloc_enum_data(void);
    165void exit_enum_attributes(void);
    166
    167int populate_int_data(union acpi_object *integer_obj, int instance_id,
    168			struct kobject *attr_name_kobj);
    169int alloc_int_data(void);
    170void exit_int_attributes(void);
    171
    172int populate_str_data(union acpi_object *str_obj, int instance_id, struct kobject *attr_name_kobj);
    173int alloc_str_data(void);
    174void exit_str_attributes(void);
    175
    176int populate_po_data(union acpi_object *po_obj, int instance_id, struct kobject *attr_name_kobj);
    177int alloc_po_data(void);
    178void exit_po_attributes(void);
    179
    180int set_attribute(const char *a_name, const char *a_value);
    181int set_bios_defaults(u8 defType);
    182
    183void exit_bios_attr_set_interface(void);
    184int init_bios_attr_set_interface(void);
    185int map_wmi_error(int error_code);
    186size_t calculate_string_buffer(const char *str);
    187size_t calculate_security_buffer(char *authentication);
    188void populate_security_buffer(char *buffer, char *authentication);
    189ssize_t populate_string_buffer(char *buffer, size_t buffer_len, const char *str);
    190int set_new_password(const char *password_type, const char *new);
    191int init_bios_attr_pass_interface(void);
    192void exit_bios_attr_pass_interface(void);
    193
    194#endif