Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,81 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# X86 Platform Specific Drivers
#
menuconfig X86_PLATFORM_DRIVERS_HP
bool "HP X86 Platform Specific Device Drivers"
depends on X86_PLATFORM_DEVICES
help
Say Y here to get to see options for device drivers for various
HP x86 platforms, including vendor-specific laptop extension drivers.
This option alone does not add any kernel code.
If you say N, all options in this submenu will be skipped and disabled.
if X86_PLATFORM_DRIVERS_HP
config HP_ACCEL
tristate "HP laptop accelerometer"
default m
depends on INPUT && ACPI
depends on SERIO_I8042
select SENSORS_LIS3LV02D
select NEW_LEDS
select LEDS_CLASS
help
This driver provides support for the "Mobile Data Protection System 3D"
or "3D DriveGuard" feature of HP laptops. On such systems the driver
should load automatically (via ACPI alias).
Support for a led indicating disk protection will be provided as
hp::hddprotect. For more information on the feature, refer to
Documentation/misc-devices/lis3lv02d.rst.
To compile this driver as a module, choose M here: the module will
be called hp_accel.
config HP_WMI
tristate "HP WMI extras"
default m
depends on ACPI_EC
depends on ACPI_WMI
depends on INPUT
depends on RFKILL || RFKILL = n
select POWER_SUPPLY
select INPUT_SPARSEKMAP
select ACPI_PLATFORM_PROFILE
select HWMON
help
Say Y here if you want to support WMI-based hotkeys on HP laptops and
to read data from WMI such as docking or ambient light sensor state.
To compile this driver as a module, choose M here: the module will
be called hp-wmi.
config TC1100_WMI
tristate "HP Compaq TC1100 Tablet WMI Extras"
default m
depends on !X86_64
depends on ACPI
depends on ACPI_WMI
help
This is a driver for the WMI extensions (wireless and bluetooth power
control) of the HP Compaq TC1100 tablet.
config HP_BIOSCFG
tristate "HP BIOS Configuration Driver"
default m
depends on ACPI_WMI
select NLS
select FW_ATTR_CLASS
help
This driver enables administrators to securely manage BIOS settings
using digital certificates and public-key cryptography that eliminate
the need for passwords for both remote and local management. It supports
changing BIOS settings on many HP machines from 2018 and newer without
the use of any additional software.
To compile this driver as a module, choose M here: the module will
be called hp-bioscfg.
endif # X86_PLATFORM_DRIVERS_HP
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: GPL-2.0
#
# Makefile for linux/drivers/platform/x86/hp
# HP x86 Platform-Specific Drivers
#
# Hewlett Packard
obj-$(CONFIG_HP_ACCEL) += hp_accel.o
obj-$(CONFIG_HP_WMI) += hp-wmi.o
obj-$(CONFIG_TC1100_WMI) += tc1100-wmi.o
obj-$(CONFIG_HP_BIOSCFG) += hp-bioscfg/
@@ -0,0 +1,11 @@
obj-$(CONFIG_HP_BIOSCFG) := hp-bioscfg.o
hp-bioscfg-y := bioscfg.o \
biosattr-interface.o \
enum-attributes.o \
int-attributes.o \
order-list-attributes.o \
passwdobj-attributes.o \
spmobj-attributes.o \
string-attributes.o \
surestart-attributes.o
@@ -0,0 +1,312 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Functions corresponding to methods under BIOS interface GUID
* for use with hp-bioscfg driver.
*
* Copyright (c) 2022 Hewlett-Packard Inc.
*/
#include <linux/wmi.h>
#include "bioscfg.h"
/*
* struct bios_args buffer is dynamically allocated. New WMI command types
* were introduced that exceeds 128-byte data size. Changes to handle
* the data size allocation scheme were kept in hp_wmi_perform_query function.
*/
struct bios_args {
u32 signature;
u32 command;
u32 commandtype;
u32 datasize;
u8 data[] __counted_by(datasize);
};
/**
* hp_set_attribute
*
* @a_name: The attribute name
* @a_value: The attribute value
*
* Sets an attribute to new value
*
* Returns zero on success
* -ENODEV if device is not found
* -EINVAL if the instance of 'Setup Admin' password is not found.
* -ENOMEM unable to allocate memory
*/
int hp_set_attribute(const char *a_name, const char *a_value)
{
int security_area_size;
int a_name_size, a_value_size;
u16 *buffer = NULL;
u16 *start;
int buffer_size, instance, ret;
char *auth_token_choice;
mutex_lock(&bioscfg_drv.mutex);
instance = hp_get_password_instance_for_type(SETUP_PASSWD);
if (instance < 0) {
ret = -EINVAL;
goto out_set_attribute;
}
/* Select which auth token to use; password or [auth token] */
if (bioscfg_drv.spm_data.auth_token)
auth_token_choice = bioscfg_drv.spm_data.auth_token;
else
auth_token_choice = bioscfg_drv.password_data[instance].current_password;
a_name_size = hp_calculate_string_buffer(a_name);
a_value_size = hp_calculate_string_buffer(a_value);
security_area_size = hp_calculate_security_buffer(auth_token_choice);
buffer_size = a_name_size + a_value_size + security_area_size;
buffer = kmalloc(buffer_size + 1, GFP_KERNEL);
if (!buffer) {
ret = -ENOMEM;
goto out_set_attribute;
}
/* build variables to set */
start = buffer;
start = hp_ascii_to_utf16_unicode(start, a_name);
if (!start) {
ret = -EINVAL;
goto out_set_attribute;
}
start = hp_ascii_to_utf16_unicode(start, a_value);
if (!start) {
ret = -EINVAL;
goto out_set_attribute;
}
ret = hp_populate_security_buffer(start, auth_token_choice);
if (ret < 0)
goto out_set_attribute;
ret = hp_wmi_set_bios_setting(buffer, buffer_size);
out_set_attribute:
kfree(buffer);
mutex_unlock(&bioscfg_drv.mutex);
return ret;
}
/**
* hp_wmi_perform_query
*
* @query: The commandtype (enum hp_wmi_commandtype)
* @command: The command (enum hp_wmi_command)
* @buffer: Buffer used as input and/or output
* @insize: Size of input buffer
* @outsize: Size of output buffer
*
* returns zero on success
* an HP WMI query specific error code (which is positive)
* -EINVAL if the query was not successful at all
* -EINVAL if the output buffer size exceeds buffersize
*
* Note: The buffersize must at least be the maximum of the input and output
* size. E.g. Battery info query is defined to have 1 byte input
* and 128 byte output. The caller would do:
* buffer = kzalloc(128, GFP_KERNEL);
* ret = hp_wmi_perform_query(HPWMI_BATTERY_QUERY, HPWMI_READ,
* buffer, 1, 128)
*/
int hp_wmi_perform_query(int query, enum hp_wmi_command command, void *buffer,
u32 insize, u32 outsize)
{
struct acpi_buffer input, output = { ACPI_ALLOCATE_BUFFER, NULL };
struct bios_return *bios_return;
union acpi_object *obj = NULL;
struct bios_args *args = NULL;
int mid, actual_outsize, ret;
size_t bios_args_size;
mid = hp_encode_outsize_for_pvsz(outsize);
if (WARN_ON(mid < 0))
return mid;
bios_args_size = struct_size(args, data, insize);
args = kmalloc(bios_args_size, GFP_KERNEL);
if (!args)
return -ENOMEM;
input.length = bios_args_size;
input.pointer = args;
/* BIOS expects 'SECU' in hex as the signature value*/
args->signature = 0x55434553;
args->command = command;
args->commandtype = query;
args->datasize = insize;
memcpy(args->data, buffer, flex_array_size(args, data, insize));
ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);
if (ret)
goto out_free;
obj = output.pointer;
if (!obj) {
ret = -EINVAL;
goto out_free;
}
if (obj->type != ACPI_TYPE_BUFFER ||
obj->buffer.length < sizeof(*bios_return)) {
pr_warn("query 0x%x returned wrong type or too small buffer\n", query);
ret = -EINVAL;
goto out_free;
}
bios_return = (struct bios_return *)obj->buffer.pointer;
ret = bios_return->return_code;
if (ret) {
if (ret != INVALID_CMD_VALUE && ret != INVALID_CMD_TYPE)
pr_warn("query 0x%x returned error 0x%x\n", query, ret);
goto out_free;
}
/* Ignore output data of zero size */
if (!outsize)
goto out_free;
actual_outsize = min_t(u32, outsize, obj->buffer.length - sizeof(*bios_return));
memcpy_and_pad(buffer, outsize, obj->buffer.pointer + sizeof(*bios_return),
actual_outsize, 0);
out_free:
ret = hp_wmi_error_and_message(ret);
kfree(obj);
kfree(args);
return ret;
}
static void *utf16_empty_string(u16 *p)
{
*p++ = 2;
*p++ = 0x00;
return p;
}
/**
* hp_ascii_to_utf16_unicode - Convert ascii string to UTF-16 unicode
*
* BIOS supports UTF-16 characters that are 2 bytes long. No variable
* multi-byte language supported.
*
* @p: Unicode buffer address
* @str: string to convert to unicode
*
* Returns a void pointer to the buffer string
*/
void *hp_ascii_to_utf16_unicode(u16 *p, const u8 *str)
{
int len = strlen(str);
int ret;
/*
* Add null character when reading an empty string
* "02 00 00 00"
*/
if (len == 0)
return utf16_empty_string(p);
/* Move pointer len * 2 number of bytes */
*p++ = len * 2;
ret = utf8s_to_utf16s(str, strlen(str), UTF16_HOST_ENDIAN, p, len);
if (ret < 0) {
dev_err(bioscfg_drv.class_dev, "UTF16 conversion failed\n");
return NULL;
}
if (ret * sizeof(u16) > U16_MAX) {
dev_err(bioscfg_drv.class_dev, "Error string too long\n");
return NULL;
}
p += len;
return p;
}
/**
* hp_wmi_set_bios_setting - Set setting's value in BIOS
*
* @input_buffer: Input buffer address
* @input_size: Input buffer size
*
* Returns: Count of unicode characters written to BIOS if successful, otherwise
* -ENOMEM unable to allocate memory
* -EINVAL buffer not allocated or too small
*/
int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size)
{
union acpi_object *obj;
struct acpi_buffer input = {input_size, input_buffer};
struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
int ret;
ret = wmi_evaluate_method(HP_WMI_SET_BIOS_SETTING_GUID, 0, 1, &input, &output);
obj = output.pointer;
if (!obj)
return -EINVAL;
if (obj->type != ACPI_TYPE_INTEGER) {
ret = -EINVAL;
goto out_free;
}
ret = obj->integer.value;
if (ret) {
ret = hp_wmi_error_and_message(ret);
goto out_free;
}
out_free:
kfree(obj);
return ret;
}
static int hp_attr_set_interface_probe(struct wmi_device *wdev, const void *context)
{
mutex_lock(&bioscfg_drv.mutex);
mutex_unlock(&bioscfg_drv.mutex);
return 0;
}
static void hp_attr_set_interface_remove(struct wmi_device *wdev)
{
mutex_lock(&bioscfg_drv.mutex);
mutex_unlock(&bioscfg_drv.mutex);
}
static const struct wmi_device_id hp_attr_set_interface_id_table[] = {
{ .guid_string = HP_WMI_BIOS_GUID},
{ }
};
static struct wmi_driver hp_attr_set_interface_driver = {
.driver = {
.name = DRIVER_NAME,
},
.probe = hp_attr_set_interface_probe,
.remove = hp_attr_set_interface_remove,
.id_table = hp_attr_set_interface_id_table,
};
int hp_init_attr_set_interface(void)
{
return wmi_driver_register(&hp_attr_set_interface_driver);
}
void hp_exit_attr_set_interface(void)
{
wmi_driver_unregister(&hp_attr_set_interface_driver);
}
MODULE_DEVICE_TABLE(wmi, hp_attr_set_interface_id_table);
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,489 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Definitions for kernel modules using hp_bioscfg driver
*
* Copyright (c) 2022 HP Development Company, L.P.
*/
#ifndef _HP_BIOSCFG_H_
#define _HP_BIOSCFG_H_
#include <linux/wmi.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/nls.h>
#define DRIVER_NAME "hp-bioscfg"
#define MAX_BUFF_SIZE 512
#define MAX_KEY_MOD_SIZE 256
#define MAX_PASSWD_SIZE 64
#define MAX_PREREQUISITES_SIZE 20
#define MAX_REQ_ELEM_SIZE 128
#define MAX_VALUES_SIZE 16
#define MAX_ENCODINGS_SIZE 16
#define MAX_ELEMENTS_SIZE 16
#define SPM_STR_DESC "Secure Platform Management"
#define SPM_STR "SPM"
#define SURE_START_DESC "Sure Start"
#define SURE_START_STR "Sure_Start"
#define SETUP_PASSWD "Setup Password"
#define POWER_ON_PASSWD "Power-On Password"
#define LANG_CODE_STR "en_US.UTF-8"
#define SCHEDULE_POWER_ON "Scheduled Power-On"
#define COMMA_SEP ","
#define SEMICOLON_SEP ";"
/* Sure Admin Functions */
#define UTF_PREFIX "<utf-16/>"
#define BEAM_PREFIX "<BEAM/>"
enum mechanism_values {
PASSWORD = 0x00,
SIGNING_KEY = 0x01,
ENDORSEMENT_KEY = 0x02,
};
#define BIOS_ADMIN "bios-admin"
#define POWER_ON "power-on"
#define BIOS_SPM "enhanced-bios-auth"
#define PASSWD_MECHANISM_TYPES "password"
#define HP_WMI_BIOS_GUID "5FB7F034-2C63-45E9-BE91-3D44E2C707E4"
#define HP_WMI_BIOS_STRING_GUID "988D08E3-68F4-4C35-AF3E-6A1B8106F83C"
#define HP_WMI_BIOS_INTEGER_GUID "8232DE3D-663D-4327-A8F4-E293ADB9BF05"
#define HP_WMI_BIOS_ENUMERATION_GUID "2D114B49-2DFB-4130-B8FE-4A3C09E75133"
#define HP_WMI_BIOS_ORDERED_LIST_GUID "14EA9746-CE1F-4098-A0E0-7045CB4DA745"
#define HP_WMI_BIOS_PASSWORD_GUID "322F2028-0F84-4901-988E-015176049E2D"
#define HP_WMI_SET_BIOS_SETTING_GUID "1F4C91EB-DC5C-460B-951D-C7CB9B4B8D5E"
enum hp_wmi_spm_commandtype {
HPWMI_SECUREPLATFORM_GET_STATE = 0x10,
HPWMI_SECUREPLATFORM_SET_KEK = 0x11,
HPWMI_SECUREPLATFORM_SET_SK = 0x12,
};
enum hp_wmi_surestart_commandtype {
HPWMI_SURESTART_GET_LOG_COUNT = 0x01,
HPWMI_SURESTART_GET_LOG = 0x02,
};
enum hp_wmi_command {
HPWMI_READ = 0x01,
HPWMI_WRITE = 0x02,
HPWMI_ODM = 0x03,
HPWMI_SURESTART = 0x20006,
HPWMI_GM = 0x20008,
HPWMI_SECUREPLATFORM = 0x20010,
};
struct bios_return {
u32 sigpass;
u32 return_code;
};
enum wmi_error_values {
SUCCESS = 0x00,
CMD_FAILED = 0x01,
INVALID_SIGN = 0x02,
INVALID_CMD_VALUE = 0x03,
INVALID_CMD_TYPE = 0x04,
INVALID_DATA_SIZE = 0x05,
INVALID_CMD_PARAM = 0x06,
ENCRYP_CMD_REQUIRED = 0x07,
NO_SECURE_SESSION = 0x08,
SECURE_SESSION_FOUND = 0x09,
SECURE_SESSION_FAILED = 0x0A,
AUTH_FAILED = 0x0B,
INVALID_BIOS_AUTH = 0x0E,
NONCE_DID_NOT_MATCH = 0x18,
GENERIC_ERROR = 0x1C,
BIOS_ADMIN_POLICY_NOT_MET = 0x28,
BIOS_ADMIN_NOT_SET = 0x38,
P21_NO_PROVISIONED = 0x1000,
P21_PROVISION_IN_PROGRESS = 0x1001,
P21_IN_USE = 0x1002,
HEP_NOT_ACTIVE = 0x1004,
HEP_ALREADY_SET = 0x1006,
HEP_CHECK_STATE = 0x1007,
};
struct common_data {
u8 display_name[MAX_BUFF_SIZE];
u8 path[MAX_BUFF_SIZE];
u32 is_readonly;
u32 display_in_ui;
u32 requires_physical_presence;
u32 sequence;
u32 prerequisites_size;
u8 prerequisites[MAX_PREREQUISITES_SIZE][MAX_BUFF_SIZE];
u32 security_level;
};
struct string_data {
struct common_data common;
struct kobject *attr_name_kobj;
u8 current_value[MAX_BUFF_SIZE];
u8 new_value[MAX_BUFF_SIZE];
u32 min_length;
u32 max_length;
};
struct integer_data {
struct common_data common;
struct kobject *attr_name_kobj;
u32 current_value;
u32 new_value;
u32 lower_bound;
u32 upper_bound;
u32 scalar_increment;
};
struct enumeration_data {
struct common_data common;
struct kobject *attr_name_kobj;
u8 current_value[MAX_BUFF_SIZE];
u8 new_value[MAX_BUFF_SIZE];
u32 possible_values_size;
u8 possible_values[MAX_VALUES_SIZE][MAX_BUFF_SIZE];
};
struct ordered_list_data {
struct common_data common;
struct kobject *attr_name_kobj;
u8 current_value[MAX_BUFF_SIZE];
u8 new_value[MAX_BUFF_SIZE];
u32 elements_size;
u8 elements[MAX_ELEMENTS_SIZE][MAX_BUFF_SIZE];
};
struct password_data {
struct common_data common;
struct kobject *attr_name_kobj;
u8 current_password[MAX_PASSWD_SIZE];
u8 new_password[MAX_PASSWD_SIZE];
u32 min_password_length;
u32 max_password_length;
u32 encodings_size;
u8 encodings[MAX_ENCODINGS_SIZE][MAX_BUFF_SIZE];
bool is_enabled;
/*
* 'role' identifies the type of authentication.
* Two known types are bios-admin and power-on.
* 'bios-admin' represents BIOS administrator password
* 'power-on' represents a password required to use the system
*/
u32 role;
/*
* 'mechanism' represents the means of authentication.
* Only supported type currently is "password"
*/
u32 mechanism;
};
struct secure_platform_data {
struct kobject *attr_name_kobj;
u8 attribute_name[MAX_BUFF_SIZE];
u8 *endorsement_key;
u8 *signing_key;
u8 *auth_token;
bool is_enabled;
u32 mechanism;
};
struct bioscfg_priv {
struct kset *authentication_dir_kset;
struct kset *main_dir_kset;
struct device *class_dev;
struct string_data *string_data;
u32 string_instances_count;
struct integer_data *integer_data;
u32 integer_instances_count;
struct enumeration_data *enumeration_data;
u32 enumeration_instances_count;
struct ordered_list_data *ordered_list_data;
u32 ordered_list_instances_count;
struct password_data *password_data;
u32 password_instances_count;
struct kobject *sure_start_attr_kobj;
struct secure_platform_data spm_data;
u8 display_name_language_code[MAX_BUFF_SIZE];
bool pending_reboot;
struct mutex mutex;
};
/* global structure used by multiple WMI interfaces */
extern struct bioscfg_priv bioscfg_drv;
enum hp_wmi_data_type {
HPWMI_STRING_TYPE,
HPWMI_INTEGER_TYPE,
HPWMI_ENUMERATION_TYPE,
HPWMI_ORDERED_LIST_TYPE,
HPWMI_PASSWORD_TYPE,
HPWMI_SECURE_PLATFORM_TYPE,
HPWMI_SURE_START_TYPE,
};
enum hp_wmi_data_elements {
/* Common elements */
NAME = 0,
VALUE = 1,
PATH = 2,
IS_READONLY = 3,
DISPLAY_IN_UI = 4,
REQUIRES_PHYSICAL_PRESENCE = 5,
SEQUENCE = 6,
PREREQUISITES_SIZE = 7,
PREREQUISITES = 8,
SECURITY_LEVEL = 9,
/* String elements */
STR_MIN_LENGTH = 10,
STR_MAX_LENGTH = 11,
STR_ELEM_CNT = 12,
/* Integer elements */
INT_LOWER_BOUND = 10,
INT_UPPER_BOUND = 11,
INT_SCALAR_INCREMENT = 12,
INT_ELEM_CNT = 13,
/* Enumeration elements */
ENUM_CURRENT_VALUE = 10,
ENUM_SIZE = 11,
ENUM_POSSIBLE_VALUES = 12,
ENUM_ELEM_CNT = 13,
/* Ordered list elements */
ORD_LIST_SIZE = 10,
ORD_LIST_ELEMENTS = 11,
ORD_ELEM_CNT = 12,
/* Password elements */
PSWD_MIN_LENGTH = 10,
PSWD_MAX_LENGTH = 11,
PSWD_SIZE = 12,
PSWD_ENCODINGS = 13,
PSWD_IS_SET = 14,
PSWD_ELEM_CNT = 15,
};
#define GET_INSTANCE_ID(type) \
static int get_##type##_instance_id(struct kobject *kobj) \
{ \
int i; \
\
for (i = 0; i < bioscfg_drv.type##_instances_count; i++) { \
if (bioscfg_drv.type##_data[i].attr_name_kobj && \
!strcmp(kobj->name, bioscfg_drv.type##_data[i].attr_name_kobj->name)) \
return i; \
} \
return -EIO; \
}
#define ATTRIBUTE_S_PROPERTY_SHOW(name, type) \
static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \
char *buf) \
{ \
int i = get_##type##_instance_id(kobj); \
if (i >= 0) \
return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].name); \
return -EIO; \
}
#define ATTRIBUTE_N_PROPERTY_SHOW(name, type) \
static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \
char *buf) \
{ \
int i = get_##type##_instance_id(kobj); \
if (i >= 0) \
return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data[i].name); \
return -EIO; \
}
#define ATTRIBUTE_PROPERTY_STORE(curr_val, type) \
static ssize_t curr_val##_store(struct kobject *kobj, \
struct kobj_attribute *attr, \
const char *buf, size_t count) \
{ \
char *attr_value = NULL; \
int i; \
int ret = -EIO; \
\
attr_value = kstrdup(buf, GFP_KERNEL); \
if (!attr_value) \
return -ENOMEM; \
\
ret = hp_enforce_single_line_input(attr_value, count); \
if (!ret) { \
i = get_##type##_instance_id(kobj); \
if (i >= 0) \
ret = validate_##type##_input(i, attr_value); \
} \
if (!ret) \
ret = hp_set_attribute(kobj->name, attr_value); \
if (!ret) { \
update_##type##_value(i, attr_value); \
if (bioscfg_drv.type##_data[i].common.requires_physical_presence) \
hp_set_reboot_and_signal_event(); \
} \
hp_clear_all_credentials(); \
kfree(attr_value); \
\
return ret ? ret : count; \
}
#define ATTRIBUTE_SPM_N_PROPERTY_SHOW(name, type) \
static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
{ \
return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data.name); \
}
#define ATTRIBUTE_SPM_S_PROPERTY_SHOW(name, type) \
static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
{ \
return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data.name); \
}
#define ATTRIBUTE_VALUES_PROPERTY_SHOW(name, type, sep) \
static ssize_t name##_show(struct kobject *kobj, \
struct kobj_attribute *attr, char *buf) \
{ \
int i; \
int len = 0; \
int instance_id = get_##type##_instance_id(kobj); \
\
if (instance_id < 0) \
return 0; \
\
for (i = 0; i < bioscfg_drv.type##_data[instance_id].name##_size; i++) { \
if (i) \
len += sysfs_emit_at(buf, len, "%s", sep); \
\
len += sysfs_emit_at(buf, len, "%s", \
bioscfg_drv.type##_data[instance_id].name[i]); \
} \
len += sysfs_emit_at(buf, len, "\n"); \
return len; \
}
#define ATTRIBUTE_S_COMMON_PROPERTY_SHOW(name, type) \
static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \
char *buf) \
{ \
int i = get_##type##_instance_id(kobj); \
if (i >= 0) \
return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].common.name); \
return -EIO; \
}
extern struct kobj_attribute common_display_langcode;
/* Prototypes */
/* String attributes */
int hp_populate_string_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
int instance_id,
struct kobject *attr_name_kobj);
int hp_alloc_string_data(void);
void hp_exit_string_attributes(void);
int hp_populate_string_package_data(union acpi_object *str_obj,
int instance_id,
struct kobject *attr_name_kobj);
/* Integer attributes */
int hp_populate_integer_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
int instance_id,
struct kobject *attr_name_kobj);
int hp_alloc_integer_data(void);
void hp_exit_integer_attributes(void);
int hp_populate_integer_package_data(union acpi_object *integer_obj,
int instance_id,
struct kobject *attr_name_kobj);
/* Enumeration attributes */
int hp_populate_enumeration_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
int instance_id,
struct kobject *attr_name_kobj);
int hp_alloc_enumeration_data(void);
void hp_exit_enumeration_attributes(void);
int hp_populate_enumeration_package_data(union acpi_object *enum_obj,
int instance_id,
struct kobject *attr_name_kobj);
/* Ordered list */
int hp_populate_ordered_list_buffer_data(u8 *buffer_ptr,
u32 *buffer_size,
int instance_id,
struct kobject *attr_name_kobj);
int hp_alloc_ordered_list_data(void);
void hp_exit_ordered_list_attributes(void);
int hp_populate_ordered_list_package_data(union acpi_object *order_obj,
int instance_id,
struct kobject *attr_name_kobj);
/* Password authentication attributes */
int hp_populate_password_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
int instance_id,
struct kobject *attr_name_kobj);
int hp_populate_password_package_data(union acpi_object *password_obj,
int instance_id,
struct kobject *attr_name_kobj);
int hp_alloc_password_data(void);
int hp_get_password_instance_for_type(const char *name);
int hp_clear_all_credentials(void);
int hp_set_attribute(const char *a_name, const char *a_value);
/* SPM attributes */
void hp_exit_password_attributes(void);
void hp_exit_secure_platform_attributes(void);
int hp_populate_secure_platform_data(struct kobject *attr_name_kobj);
int hp_populate_security_buffer(u16 *buffer, const char *authentication);
/* Bios Attributes interface */
int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size);
int hp_wmi_perform_query(int query, enum hp_wmi_command command,
void *buffer, u32 insize, u32 outsize);
/* Sure Start attributes */
void hp_exit_sure_start_attributes(void);
int hp_populate_sure_start_data(struct kobject *attr_name_kobj);
/* Bioscfg */
void hp_exit_attr_set_interface(void);
int hp_init_attr_set_interface(void);
size_t hp_calculate_string_buffer(const char *str);
size_t hp_calculate_security_buffer(const char *authentication);
void *hp_ascii_to_utf16_unicode(u16 *p, const u8 *str);
int hp_get_integer_from_buffer(u8 **buffer, u32 *buffer_size, u32 *integer);
int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_size);
int hp_convert_hexstr_to_str(const char *input, u32 input_len, char **str, int *len);
int hp_encode_outsize_for_pvsz(int outsize);
int hp_enforce_single_line_input(char *buf, size_t count);
void hp_set_reboot_and_signal_event(void);
ssize_t display_name_language_code_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf);
union acpi_object *hp_get_wmiobj_pointer(int instance_id, const char *guid_string);
int hp_get_instance_count(const char *guid_string);
void hp_update_attribute_permissions(bool isreadonly, struct kobj_attribute *current_val);
void hp_friendly_user_name_update(char *path, const char *attr_name,
char *attr_display, int attr_size);
int hp_wmi_error_and_message(int error_code);
int hp_get_common_data_from_buffer(u8 **buffer_ptr, u32 *buffer_size, struct common_data *common);
#endif
@@ -0,0 +1,452 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Functions corresponding to enumeration type attributes under
* BIOS Enumeration GUID for use with hp-bioscfg driver.
*
* Copyright (c) 2022 HP Development Company, L.P.
*/
#include "bioscfg.h"
GET_INSTANCE_ID(enumeration);
static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int instance_id = get_enumeration_instance_id(kobj);
if (instance_id < 0)
return -EIO;
return sysfs_emit(buf, "%s\n",
bioscfg_drv.enumeration_data[instance_id].current_value);
}
/**
* validate_enumeration_input() -
* Validate input of current_value against possible values
*
* @instance_id: The instance on which input is validated
* @buf: Input value
*/
static int validate_enumeration_input(int instance_id, const char *buf)
{
int i;
int found = 0;
struct enumeration_data *enum_data = &bioscfg_drv.enumeration_data[instance_id];
/* Is it a read only attribute */
if (enum_data->common.is_readonly)
return -EIO;
for (i = 0; i < enum_data->possible_values_size && !found; i++)
if (!strcmp(enum_data->possible_values[i], buf))
found = 1;
if (!found)
return -EINVAL;
return 0;
}
static void update_enumeration_value(int instance_id, char *attr_value)
{
struct enumeration_data *enum_data = &bioscfg_drv.enumeration_data[instance_id];
strscpy(enum_data->current_value, attr_value);
}
ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, enumeration);
static struct kobj_attribute enumeration_display_name =
__ATTR_RO(display_name);
ATTRIBUTE_PROPERTY_STORE(current_value, enumeration);
static struct kobj_attribute enumeration_current_val =
__ATTR_RW(current_value);
ATTRIBUTE_VALUES_PROPERTY_SHOW(possible_values, enumeration, SEMICOLON_SEP);
static struct kobj_attribute enumeration_poss_val =
__ATTR_RO(possible_values);
static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "enumeration\n");
}
static struct kobj_attribute enumeration_type =
__ATTR_RO(type);
static struct attribute *enumeration_attrs[] = {
&common_display_langcode.attr,
&enumeration_display_name.attr,
&enumeration_current_val.attr,
&enumeration_poss_val.attr,
&enumeration_type.attr,
NULL
};
static const struct attribute_group enumeration_attr_group = {
.attrs = enumeration_attrs,
};
int hp_alloc_enumeration_data(void)
{
bioscfg_drv.enumeration_instances_count =
hp_get_instance_count(HP_WMI_BIOS_ENUMERATION_GUID);
if (!bioscfg_drv.enumeration_instances_count)
return -EINVAL;
bioscfg_drv.enumeration_data = kvcalloc(bioscfg_drv.enumeration_instances_count,
sizeof(*bioscfg_drv.enumeration_data), GFP_KERNEL);
if (!bioscfg_drv.enumeration_data) {
bioscfg_drv.enumeration_instances_count = 0;
return -ENOMEM;
}
return 0;
}
/* Expected Values types associated with each element */
static const acpi_object_type expected_enum_types[] = {
[NAME] = ACPI_TYPE_STRING,
[VALUE] = ACPI_TYPE_STRING,
[PATH] = ACPI_TYPE_STRING,
[IS_READONLY] = ACPI_TYPE_INTEGER,
[DISPLAY_IN_UI] = ACPI_TYPE_INTEGER,
[REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER,
[SEQUENCE] = ACPI_TYPE_INTEGER,
[PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER,
[PREREQUISITES] = ACPI_TYPE_STRING,
[SECURITY_LEVEL] = ACPI_TYPE_INTEGER,
[ENUM_CURRENT_VALUE] = ACPI_TYPE_STRING,
[ENUM_SIZE] = ACPI_TYPE_INTEGER,
[ENUM_POSSIBLE_VALUES] = ACPI_TYPE_STRING,
};
static int hp_populate_enumeration_elements_from_package(union acpi_object *enum_obj,
int enum_obj_count,
int instance_id)
{
char *str_value = NULL;
int value_len;
u32 size = 0;
u32 int_value = 0;
int elem = 0;
int reqs;
int pos_values;
int ret;
int eloc;
struct enumeration_data *enum_data = &bioscfg_drv.enumeration_data[instance_id];
for (elem = 1, eloc = 1; elem < enum_obj_count; elem++, eloc++) {
/* ONLY look at the first ENUM_ELEM_CNT elements */
if (eloc == ENUM_ELEM_CNT)
goto exit_enumeration_package;
switch (enum_obj[elem].type) {
case ACPI_TYPE_STRING:
if (PREREQUISITES != elem && ENUM_POSSIBLE_VALUES != elem) {
ret = hp_convert_hexstr_to_str(enum_obj[elem].string.pointer,
enum_obj[elem].string.length,
&str_value, &value_len);
if (ret)
return -EINVAL;
}
break;
case ACPI_TYPE_INTEGER:
int_value = (u32)enum_obj[elem].integer.value;
break;
default:
pr_warn("Unsupported object type [%d]\n", enum_obj[elem].type);
continue;
}
/* Check that both expected and read object type match */
if (expected_enum_types[eloc] != enum_obj[elem].type) {
pr_err("Error expected type %d for elem %d, but got type %d instead\n",
expected_enum_types[eloc], elem, enum_obj[elem].type);
kfree(str_value);
return -EIO;
}
/* Assign appropriate element value to corresponding field */
switch (eloc) {
case NAME:
case VALUE:
break;
case PATH:
strscpy(enum_data->common.path, str_value);
break;
case IS_READONLY:
enum_data->common.is_readonly = int_value;
break;
case DISPLAY_IN_UI:
enum_data->common.display_in_ui = int_value;
break;
case REQUIRES_PHYSICAL_PRESENCE:
enum_data->common.requires_physical_presence = int_value;
break;
case SEQUENCE:
enum_data->common.sequence = int_value;
break;
case PREREQUISITES_SIZE:
if (int_value > MAX_PREREQUISITES_SIZE) {
pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
int_value = MAX_PREREQUISITES_SIZE;
}
enum_data->common.prerequisites_size = int_value;
/*
* This step is needed to keep the expected
* element list pointing to the right obj[elem].type
* when the size is zero. PREREQUISITES
* object is omitted by BIOS when the size is
* zero.
*/
if (int_value == 0)
eloc++;
break;
case PREREQUISITES:
size = min_t(u32, enum_data->common.prerequisites_size, MAX_PREREQUISITES_SIZE);
for (reqs = 0; reqs < size; reqs++) {
if (elem + reqs >= enum_obj_count) {
pr_err("Error enum-objects package is too small\n");
return -EINVAL;
}
ret = hp_convert_hexstr_to_str(enum_obj[elem + reqs].string.pointer,
enum_obj[elem + reqs].string.length,
&str_value, &value_len);
if (ret)
return -EINVAL;
strscpy(enum_data->common.prerequisites[reqs], str_value);
kfree(str_value);
str_value = NULL;
}
break;
case SECURITY_LEVEL:
enum_data->common.security_level = int_value;
break;
case ENUM_CURRENT_VALUE:
strscpy(enum_data->current_value, str_value);
break;
case ENUM_SIZE:
if (int_value > MAX_VALUES_SIZE) {
pr_warn("Possible number values size value exceeded the maximum number of elements supported or data may be malformed\n");
int_value = MAX_VALUES_SIZE;
}
enum_data->possible_values_size = int_value;
/*
* This step is needed to keep the expected
* element list pointing to the right obj[elem].type
* when the size is zero. POSSIBLE_VALUES
* object is omitted by BIOS when the size is zero.
*/
if (int_value == 0)
eloc++;
break;
case ENUM_POSSIBLE_VALUES:
size = enum_data->possible_values_size;
for (pos_values = 0; pos_values < size && pos_values < MAX_VALUES_SIZE;
pos_values++) {
if (elem + pos_values >= enum_obj_count) {
pr_err("Error enum-objects package is too small\n");
return -EINVAL;
}
ret = hp_convert_hexstr_to_str(enum_obj[elem + pos_values].string.pointer,
enum_obj[elem + pos_values].string.length,
&str_value, &value_len);
if (ret)
return -EINVAL;
/*
* ignore strings when possible values size
* is greater than MAX_VALUES_SIZE
*/
if (size < MAX_VALUES_SIZE)
strscpy(enum_data->possible_values[pos_values], str_value);
kfree(str_value);
str_value = NULL;
}
break;
default:
pr_warn("Invalid element: %d found in Enumeration attribute or data may be malformed\n", elem);
break;
}
kfree(str_value);
str_value = NULL;
}
exit_enumeration_package:
kfree(str_value);
return 0;
}
/**
* hp_populate_enumeration_package_data() -
* Populate all properties of an instance under enumeration attribute
*
* @enum_obj: ACPI object with enumeration data
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_enumeration_package_data(union acpi_object *enum_obj,
int instance_id,
struct kobject *attr_name_kobj)
{
struct enumeration_data *enum_data = &bioscfg_drv.enumeration_data[instance_id];
enum_data->attr_name_kobj = attr_name_kobj;
hp_populate_enumeration_elements_from_package(enum_obj,
enum_obj->package.count,
instance_id);
hp_update_attribute_permissions(enum_data->common.is_readonly,
&enumeration_current_val);
/*
* Several attributes have names such "MONDAY". Friendly
* user nane is generated to make the name more descriptive
*/
hp_friendly_user_name_update(enum_data->common.path,
attr_name_kobj->name,
enum_data->common.display_name,
sizeof(enum_data->common.display_name));
return sysfs_create_group(attr_name_kobj, &enumeration_attr_group);
}
static int hp_populate_enumeration_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size,
int instance_id)
{
int values;
struct enumeration_data *enum_data = &bioscfg_drv.enumeration_data[instance_id];
int ret = 0;
/*
* Only data relevant to this driver and its functionality is
* read. BIOS defines the order in which each * element is
* read. Element 0 data is not relevant to this
* driver hence it is ignored. For clarity, all element names
* (DISPLAY_IN_UI) which defines the order in which is read
* and the name matches the variable where the data is stored.
*
* In earlier implementation, reported errors were ignored
* causing the data to remain uninitialized. It is not
* possible to determine if data read from BIOS is valid or
* not. It is for this reason functions may return a error
* without validating the data itself.
*/
// VALUE:
ret = hp_get_string_from_buffer(&buffer_ptr, buffer_size, enum_data->current_value,
sizeof(enum_data->current_value));
if (ret < 0)
goto buffer_exit;
// COMMON:
ret = hp_get_common_data_from_buffer(&buffer_ptr, buffer_size, &enum_data->common);
if (ret < 0)
goto buffer_exit;
// ENUM_CURRENT_VALUE:
ret = hp_get_string_from_buffer(&buffer_ptr, buffer_size,
enum_data->current_value,
sizeof(enum_data->current_value));
if (ret < 0)
goto buffer_exit;
// ENUM_SIZE:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&enum_data->possible_values_size);
if (enum_data->possible_values_size > MAX_VALUES_SIZE) {
/* Report a message and limit possible values size to maximum value */
pr_warn("Enum Possible size value exceeded the maximum number of elements supported or data may be malformed\n");
enum_data->possible_values_size = MAX_VALUES_SIZE;
}
// ENUM_POSSIBLE_VALUES:
for (values = 0; values < enum_data->possible_values_size; values++) {
ret = hp_get_string_from_buffer(&buffer_ptr, buffer_size,
enum_data->possible_values[values],
sizeof(enum_data->possible_values[values]));
if (ret < 0)
break;
}
buffer_exit:
return ret;
}
/**
* hp_populate_enumeration_buffer_data() -
* Populate all properties of an instance under enumeration attribute
*
* @buffer_ptr: Buffer pointer
* @buffer_size: Buffer size
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_enumeration_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
int instance_id,
struct kobject *attr_name_kobj)
{
struct enumeration_data *enum_data = &bioscfg_drv.enumeration_data[instance_id];
int ret = 0;
enum_data->attr_name_kobj = attr_name_kobj;
/* Populate enumeration elements */
ret = hp_populate_enumeration_elements_from_buffer(buffer_ptr, buffer_size,
instance_id);
if (ret < 0)
return ret;
hp_update_attribute_permissions(enum_data->common.is_readonly,
&enumeration_current_val);
/*
* Several attributes have names such "MONDAY". A Friendlier
* user nane is generated to make the name more descriptive
*/
hp_friendly_user_name_update(enum_data->common.path,
attr_name_kobj->name,
enum_data->common.display_name,
sizeof(enum_data->common.display_name));
return sysfs_create_group(attr_name_kobj, &enumeration_attr_group);
}
/**
* hp_exit_enumeration_attributes() - Clear all attribute data
*
* Clears all data allocated for this group of attributes
*/
void hp_exit_enumeration_attributes(void)
{
int instance_id;
for (instance_id = 0; instance_id < bioscfg_drv.enumeration_instances_count;
instance_id++) {
struct enumeration_data *enum_data = &bioscfg_drv.enumeration_data[instance_id];
struct kobject *attr_name_kobj = enum_data->attr_name_kobj;
if (attr_name_kobj)
sysfs_remove_group(attr_name_kobj, &enumeration_attr_group);
}
bioscfg_drv.enumeration_instances_count = 0;
kvfree(bioscfg_drv.enumeration_data);
bioscfg_drv.enumeration_data = NULL;
}
@@ -0,0 +1,415 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Functions corresponding to integer type attributes under
* BIOS Enumeration GUID for use with hp-bioscfg driver.
*
* Copyright (c) 2022 Hewlett-Packard Inc.
*/
#include "bioscfg.h"
GET_INSTANCE_ID(integer);
static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int instance_id = get_integer_instance_id(kobj);
if (instance_id < 0)
return -EIO;
return sysfs_emit(buf, "%d\n",
bioscfg_drv.integer_data[instance_id].current_value);
}
/**
* validate_integer_input() -
* Validate input of current_value against lower and upper bound
*
* @instance_id: The instance on which input is validated
* @buf: Input value
*/
static int validate_integer_input(int instance_id, char *buf)
{
int in_val;
int ret;
struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
/* BIOS treats it as a read only attribute */
if (integer_data->common.is_readonly)
return -EIO;
ret = kstrtoint(buf, 10, &in_val);
if (ret < 0)
return ret;
if (in_val < integer_data->lower_bound ||
in_val > integer_data->upper_bound)
return -ERANGE;
return 0;
}
static void update_integer_value(int instance_id, char *attr_value)
{
int in_val;
int ret;
struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
ret = kstrtoint(attr_value, 10, &in_val);
if (ret == 0)
integer_data->current_value = in_val;
else
pr_warn("Invalid integer value found: %s\n", attr_value);
}
ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, integer);
static struct kobj_attribute integer_display_name =
__ATTR_RO(display_name);
ATTRIBUTE_PROPERTY_STORE(current_value, integer);
static struct kobj_attribute integer_current_val =
__ATTR_RW_MODE(current_value, 0644);
ATTRIBUTE_N_PROPERTY_SHOW(lower_bound, integer);
static struct kobj_attribute integer_lower_bound =
__ATTR_RO(lower_bound);
ATTRIBUTE_N_PROPERTY_SHOW(upper_bound, integer);
static struct kobj_attribute integer_upper_bound =
__ATTR_RO(upper_bound);
ATTRIBUTE_N_PROPERTY_SHOW(scalar_increment, integer);
static struct kobj_attribute integer_scalar_increment =
__ATTR_RO(scalar_increment);
static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "integer\n");
}
static struct kobj_attribute integer_type =
__ATTR_RO(type);
static struct attribute *integer_attrs[] = {
&common_display_langcode.attr,
&integer_display_name.attr,
&integer_current_val.attr,
&integer_lower_bound.attr,
&integer_upper_bound.attr,
&integer_scalar_increment.attr,
&integer_type.attr,
NULL
};
static const struct attribute_group integer_attr_group = {
.attrs = integer_attrs,
};
int hp_alloc_integer_data(void)
{
bioscfg_drv.integer_instances_count = hp_get_instance_count(HP_WMI_BIOS_INTEGER_GUID);
bioscfg_drv.integer_data = kzalloc_objs(*bioscfg_drv.integer_data,
bioscfg_drv.integer_instances_count);
if (!bioscfg_drv.integer_data) {
bioscfg_drv.integer_instances_count = 0;
return -ENOMEM;
}
return 0;
}
/* Expected Values types associated with each element */
static const acpi_object_type expected_integer_types[] = {
[NAME] = ACPI_TYPE_STRING,
[VALUE] = ACPI_TYPE_STRING,
[PATH] = ACPI_TYPE_STRING,
[IS_READONLY] = ACPI_TYPE_INTEGER,
[DISPLAY_IN_UI] = ACPI_TYPE_INTEGER,
[REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER,
[SEQUENCE] = ACPI_TYPE_INTEGER,
[PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER,
[PREREQUISITES] = ACPI_TYPE_STRING,
[SECURITY_LEVEL] = ACPI_TYPE_INTEGER,
[INT_LOWER_BOUND] = ACPI_TYPE_INTEGER,
[INT_UPPER_BOUND] = ACPI_TYPE_INTEGER,
[INT_SCALAR_INCREMENT] = ACPI_TYPE_INTEGER,
};
static int hp_populate_integer_elements_from_package(union acpi_object *integer_obj,
int integer_obj_count,
int instance_id)
{
char *str_value = NULL;
int value_len;
int ret;
u32 int_value = 0;
int elem;
int reqs;
int eloc;
int size;
struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
if (!integer_obj)
return -EINVAL;
for (elem = 1, eloc = 1; elem < integer_obj_count; elem++, eloc++) {
/* ONLY look at the first INTEGER_ELEM_CNT elements */
if (eloc == INT_ELEM_CNT)
goto exit_integer_package;
switch (integer_obj[elem].type) {
case ACPI_TYPE_STRING:
if (elem != PREREQUISITES) {
ret = hp_convert_hexstr_to_str(integer_obj[elem].string.pointer,
integer_obj[elem].string.length,
&str_value, &value_len);
if (ret)
continue;
}
break;
case ACPI_TYPE_INTEGER:
int_value = (u32)integer_obj[elem].integer.value;
break;
default:
pr_warn("Unsupported object type [%d]\n", integer_obj[elem].type);
continue;
}
/* Check that both expected and read object type match */
if (expected_integer_types[eloc] != integer_obj[elem].type) {
pr_err("Error expected type %d for elem %d, but got type %d instead\n",
expected_integer_types[eloc], elem, integer_obj[elem].type);
kfree(str_value);
return -EIO;
}
/* Assign appropriate element value to corresponding field*/
switch (eloc) {
case VALUE:
ret = kstrtoint(str_value, 10, &int_value);
if (ret)
continue;
integer_data->current_value = int_value;
break;
case PATH:
strscpy(integer_data->common.path, str_value);
break;
case IS_READONLY:
integer_data->common.is_readonly = int_value;
break;
case DISPLAY_IN_UI:
integer_data->common.display_in_ui = int_value;
break;
case REQUIRES_PHYSICAL_PRESENCE:
integer_data->common.requires_physical_presence = int_value;
break;
case SEQUENCE:
integer_data->common.sequence = int_value;
break;
case PREREQUISITES_SIZE:
if (int_value > MAX_PREREQUISITES_SIZE) {
pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
int_value = MAX_PREREQUISITES_SIZE;
}
integer_data->common.prerequisites_size = int_value;
/*
* This step is needed to keep the expected
* element list pointing to the right obj[elem].type
* when the size is zero. PREREQUISITES
* object is omitted by BIOS when the size is
* zero.
*/
if (integer_data->common.prerequisites_size == 0)
eloc++;
break;
case PREREQUISITES:
size = min_t(u32, integer_data->common.prerequisites_size, MAX_PREREQUISITES_SIZE);
for (reqs = 0; reqs < size; reqs++) {
if (elem + reqs >= integer_obj_count) {
pr_err("Error elem-objects package is too small\n");
return -EINVAL;
}
ret = hp_convert_hexstr_to_str(integer_obj[elem + reqs].string.pointer,
integer_obj[elem + reqs].string.length,
&str_value, &value_len);
if (ret)
continue;
strscpy(integer_data->common.prerequisites[reqs], str_value);
kfree(str_value);
str_value = NULL;
}
break;
case SECURITY_LEVEL:
integer_data->common.security_level = int_value;
break;
case INT_LOWER_BOUND:
integer_data->lower_bound = int_value;
break;
case INT_UPPER_BOUND:
integer_data->upper_bound = int_value;
break;
case INT_SCALAR_INCREMENT:
integer_data->scalar_increment = int_value;
break;
default:
pr_warn("Invalid element: %d found in Integer attribute or data may be malformed\n", elem);
break;
}
kfree(str_value);
str_value = NULL;
}
exit_integer_package:
kfree(str_value);
return 0;
}
/**
* hp_populate_integer_package_data() -
* Populate all properties of an instance under integer attribute
*
* @integer_obj: ACPI object with integer data
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_integer_package_data(union acpi_object *integer_obj,
int instance_id,
struct kobject *attr_name_kobj)
{
struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
integer_data->attr_name_kobj = attr_name_kobj;
hp_populate_integer_elements_from_package(integer_obj,
integer_obj->package.count,
instance_id);
hp_update_attribute_permissions(integer_data->common.is_readonly,
&integer_current_val);
hp_friendly_user_name_update(integer_data->common.path,
attr_name_kobj->name,
integer_data->common.display_name,
sizeof(integer_data->common.display_name));
return sysfs_create_group(attr_name_kobj, &integer_attr_group);
}
static int hp_populate_integer_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size,
int instance_id)
{
char *dst = NULL;
int dst_size = *buffer_size / sizeof(u16);
struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
int ret = 0;
dst = kcalloc(dst_size, sizeof(char), GFP_KERNEL);
if (!dst)
return -ENOMEM;
/*
* Only data relevant to this driver and its functionality is
* read. BIOS defines the order in which each * element is
* read. Element 0 data is not relevant to this
* driver hence it is ignored. For clarity, all element names
* (DISPLAY_IN_UI) which defines the order in which is read
* and the name matches the variable where the data is stored.
*
* In earlier implementation, reported errors were ignored
* causing the data to remain uninitialized. It is not
* possible to determine if data read from BIOS is valid or
* not. It is for this reason functions may return a error
* without validating the data itself.
*/
// VALUE:
integer_data->current_value = 0;
hp_get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size);
ret = kstrtoint(dst, 10, &integer_data->current_value);
if (ret)
pr_warn("Unable to convert string to integer: %s\n", dst);
kfree(dst);
// COMMON:
ret = hp_get_common_data_from_buffer(&buffer_ptr, buffer_size, &integer_data->common);
if (ret < 0)
goto buffer_exit;
// INT_LOWER_BOUND:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&integer_data->lower_bound);
if (ret < 0)
goto buffer_exit;
// INT_UPPER_BOUND:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&integer_data->upper_bound);
if (ret < 0)
goto buffer_exit;
// INT_SCALAR_INCREMENT:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&integer_data->scalar_increment);
buffer_exit:
return ret;
}
/**
* hp_populate_integer_buffer_data() -
* Populate all properties of an instance under integer attribute
*
* @buffer_ptr: Buffer pointer
* @buffer_size: Buffer size
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_integer_buffer_data(u8 *buffer_ptr, u32 *buffer_size, int instance_id,
struct kobject *attr_name_kobj)
{
struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
int ret = 0;
integer_data->attr_name_kobj = attr_name_kobj;
/* Populate integer elements */
ret = hp_populate_integer_elements_from_buffer(buffer_ptr, buffer_size,
instance_id);
if (ret < 0)
return ret;
hp_update_attribute_permissions(integer_data->common.is_readonly,
&integer_current_val);
hp_friendly_user_name_update(integer_data->common.path,
attr_name_kobj->name,
integer_data->common.display_name,
sizeof(integer_data->common.display_name));
return sysfs_create_group(attr_name_kobj, &integer_attr_group);
}
/**
* hp_exit_integer_attributes() - Clear all attribute data
*
* Clears all data allocated for this group of attributes
*/
void hp_exit_integer_attributes(void)
{
int instance_id;
for (instance_id = 0; instance_id < bioscfg_drv.integer_instances_count;
instance_id++) {
struct kobject *attr_name_kobj =
bioscfg_drv.integer_data[instance_id].attr_name_kobj;
if (attr_name_kobj)
sysfs_remove_group(attr_name_kobj, &integer_attr_group);
}
bioscfg_drv.integer_instances_count = 0;
kfree(bioscfg_drv.integer_data);
bioscfg_drv.integer_data = NULL;
}
@@ -0,0 +1,437 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Functions corresponding to ordered list type attributes under
* BIOS ORDERED LIST GUID for use with hp-bioscfg driver.
*
* Copyright (c) 2022 HP Development Company, L.P.
*/
#include "bioscfg.h"
GET_INSTANCE_ID(ordered_list);
static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int instance_id = get_ordered_list_instance_id(kobj);
if (instance_id < 0)
return -EIO;
return sysfs_emit(buf, "%s\n",
bioscfg_drv.ordered_list_data[instance_id].current_value);
}
static int replace_char_str(u8 *buffer, char *repl_char, char *repl_with)
{
char *src = buffer;
int buflen = strlen(buffer);
int item;
if (buflen < 1)
return -EINVAL;
for (item = 0; item < buflen; item++)
if (src[item] == *repl_char)
src[item] = *repl_with;
return 0;
}
/**
* validate_ordered_list_input() -
* Validate input of current_value against possible values
*
* @instance: The instance on which input is validated
* @buf: Input value
*/
static int validate_ordered_list_input(int instance, char *buf)
{
/* validation is done by BIOS. This validation function will
* convert semicolon to commas. BIOS uses commas as
* separators when reporting ordered-list values.
*/
return replace_char_str(buf, SEMICOLON_SEP, COMMA_SEP);
}
static void update_ordered_list_value(int instance, char *attr_value)
{
struct ordered_list_data *ordered_list_data = &bioscfg_drv.ordered_list_data[instance];
strscpy(ordered_list_data->current_value, attr_value);
}
ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, ordered_list);
static struct kobj_attribute ordered_list_display_name =
__ATTR_RO(display_name);
ATTRIBUTE_PROPERTY_STORE(current_value, ordered_list);
static struct kobj_attribute ordered_list_current_val =
__ATTR_RW_MODE(current_value, 0644);
ATTRIBUTE_VALUES_PROPERTY_SHOW(elements, ordered_list, SEMICOLON_SEP);
static struct kobj_attribute ordered_list_elements_val =
__ATTR_RO(elements);
static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "ordered-list\n");
}
static struct kobj_attribute ordered_list_type =
__ATTR_RO(type);
static struct attribute *ordered_list_attrs[] = {
&common_display_langcode.attr,
&ordered_list_display_name.attr,
&ordered_list_current_val.attr,
&ordered_list_elements_val.attr,
&ordered_list_type.attr,
NULL
};
static const struct attribute_group ordered_list_attr_group = {
.attrs = ordered_list_attrs,
};
int hp_alloc_ordered_list_data(void)
{
bioscfg_drv.ordered_list_instances_count =
hp_get_instance_count(HP_WMI_BIOS_ORDERED_LIST_GUID);
bioscfg_drv.ordered_list_data = kzalloc_objs(*bioscfg_drv.ordered_list_data,
bioscfg_drv.ordered_list_instances_count);
if (!bioscfg_drv.ordered_list_data) {
bioscfg_drv.ordered_list_instances_count = 0;
return -ENOMEM;
}
return 0;
}
/* Expected Values types associated with each element */
static const acpi_object_type expected_order_types[] = {
[NAME] = ACPI_TYPE_STRING,
[VALUE] = ACPI_TYPE_STRING,
[PATH] = ACPI_TYPE_STRING,
[IS_READONLY] = ACPI_TYPE_INTEGER,
[DISPLAY_IN_UI] = ACPI_TYPE_INTEGER,
[REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER,
[SEQUENCE] = ACPI_TYPE_INTEGER,
[PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER,
[PREREQUISITES] = ACPI_TYPE_STRING,
[SECURITY_LEVEL] = ACPI_TYPE_INTEGER,
[ORD_LIST_SIZE] = ACPI_TYPE_INTEGER,
[ORD_LIST_ELEMENTS] = ACPI_TYPE_STRING,
};
static int hp_populate_ordered_list_elements_from_package(union acpi_object *order_obj,
int order_obj_count,
int instance_id)
{
char *str_value = NULL;
int value_len = 0;
int ret;
u32 size;
u32 int_value = 0;
int elem;
int olist_elem;
int reqs;
int eloc;
char *tmpstr = NULL;
char *part_tmp = NULL;
int tmp_len = 0;
char *part = NULL;
struct ordered_list_data *ordered_list_data = &bioscfg_drv.ordered_list_data[instance_id];
if (!order_obj)
return -EINVAL;
for (elem = 1, eloc = 1; eloc < ORD_ELEM_CNT; elem++, eloc++) {
switch (order_obj[elem].type) {
case ACPI_TYPE_STRING:
if (elem != PREREQUISITES && elem != ORD_LIST_ELEMENTS) {
ret = hp_convert_hexstr_to_str(order_obj[elem].string.pointer,
order_obj[elem].string.length,
&str_value, &value_len);
if (ret)
continue;
}
break;
case ACPI_TYPE_INTEGER:
int_value = (u32)order_obj[elem].integer.value;
break;
default:
pr_warn("Unsupported object type [%d]\n", order_obj[elem].type);
continue;
}
/* Check that both expected and read object type match */
if (expected_order_types[eloc] != order_obj[elem].type) {
pr_err("Error expected type %d for elem %d, but got type %d instead\n",
expected_order_types[eloc], elem, order_obj[elem].type);
kfree(str_value);
return -EIO;
}
/* Assign appropriate element value to corresponding field*/
switch (eloc) {
case VALUE:
strscpy(ordered_list_data->current_value, str_value);
replace_char_str(ordered_list_data->current_value, COMMA_SEP, SEMICOLON_SEP);
break;
case PATH:
strscpy(ordered_list_data->common.path, str_value);
break;
case IS_READONLY:
ordered_list_data->common.is_readonly = int_value;
break;
case DISPLAY_IN_UI:
ordered_list_data->common.display_in_ui = int_value;
break;
case REQUIRES_PHYSICAL_PRESENCE:
ordered_list_data->common.requires_physical_presence = int_value;
break;
case SEQUENCE:
ordered_list_data->common.sequence = int_value;
break;
case PREREQUISITES_SIZE:
if (int_value > MAX_PREREQUISITES_SIZE) {
pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
int_value = MAX_PREREQUISITES_SIZE;
}
ordered_list_data->common.prerequisites_size = int_value;
/*
* This step is needed to keep the expected
* element list pointing to the right obj[elem].type
* when the size is zero. PREREQUISITES
* object is omitted by BIOS when the size is
* zero.
*/
if (int_value == 0)
eloc++;
break;
case PREREQUISITES:
size = min_t(u32, ordered_list_data->common.prerequisites_size,
MAX_PREREQUISITES_SIZE);
for (reqs = 0; reqs < size; reqs++) {
if (elem + reqs >= order_obj_count) {
pr_err("Error elem-objects package is too small\n");
return -EINVAL;
}
ret = hp_convert_hexstr_to_str(order_obj[elem + reqs].string.pointer,
order_obj[elem + reqs].string.length,
&str_value, &value_len);
if (ret)
continue;
strscpy(ordered_list_data->common.prerequisites[reqs], str_value);
kfree(str_value);
str_value = NULL;
}
break;
case SECURITY_LEVEL:
ordered_list_data->common.security_level = int_value;
break;
case ORD_LIST_SIZE:
if (int_value > MAX_ELEMENTS_SIZE) {
pr_warn("Order List size value exceeded the maximum number of elements supported or data may be malformed\n");
int_value = MAX_ELEMENTS_SIZE;
}
ordered_list_data->elements_size = int_value;
/*
* This step is needed to keep the expected
* element list pointing to the right obj[elem].type
* when the size is zero. ORD_LIST_ELEMENTS
* object is omitted by BIOS when the size is
* zero.
*/
if (int_value == 0)
eloc++;
break;
case ORD_LIST_ELEMENTS:
/*
* Ordered list data is stored in hex and comma separated format
* Convert the data and split it to show each element
*/
ret = hp_convert_hexstr_to_str(str_value, value_len, &tmpstr, &tmp_len);
if (ret)
goto exit_list;
part_tmp = tmpstr;
part = strsep(&part_tmp, COMMA_SEP);
for (olist_elem = 0; olist_elem < MAX_ELEMENTS_SIZE && part; olist_elem++) {
strscpy(ordered_list_data->elements[olist_elem], part);
part = strsep(&part_tmp, COMMA_SEP);
}
ordered_list_data->elements_size = olist_elem;
kfree(str_value);
str_value = NULL;
break;
default:
pr_warn("Invalid element: %d found in Ordered_List attribute or data may be malformed\n", elem);
break;
}
kfree(tmpstr);
tmpstr = NULL;
kfree(str_value);
str_value = NULL;
}
exit_list:
kfree(tmpstr);
kfree(str_value);
return 0;
}
/**
* hp_populate_ordered_list_package_data() -
* Populate all properties of an instance under ordered_list attribute
*
* @order_obj: ACPI object with ordered_list data
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_ordered_list_package_data(union acpi_object *order_obj, int instance_id,
struct kobject *attr_name_kobj)
{
struct ordered_list_data *ordered_list_data = &bioscfg_drv.ordered_list_data[instance_id];
ordered_list_data->attr_name_kobj = attr_name_kobj;
hp_populate_ordered_list_elements_from_package(order_obj,
order_obj->package.count,
instance_id);
hp_update_attribute_permissions(ordered_list_data->common.is_readonly,
&ordered_list_current_val);
hp_friendly_user_name_update(ordered_list_data->common.path,
attr_name_kobj->name,
ordered_list_data->common.display_name,
sizeof(ordered_list_data->common.display_name));
return sysfs_create_group(attr_name_kobj, &ordered_list_attr_group);
}
static int hp_populate_ordered_list_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size,
int instance_id)
{
int values;
struct ordered_list_data *ordered_list_data = &bioscfg_drv.ordered_list_data[instance_id];
int ret = 0;
/*
* Only data relevant to this driver and its functionality is
* read. BIOS defines the order in which each * element is
* read. Element 0 data is not relevant to this
* driver hence it is ignored. For clarity, all element names
* (DISPLAY_IN_UI) which defines the order in which is read
* and the name matches the variable where the data is stored.
*
* In earlier implementation, reported errors were ignored
* causing the data to remain uninitialized. It is not
* possible to determine if data read from BIOS is valid or
* not. It is for this reason functions may return a error
* without validating the data itself.
*/
// VALUE:
ret = hp_get_string_from_buffer(&buffer_ptr, buffer_size, ordered_list_data->current_value,
sizeof(ordered_list_data->current_value));
if (ret < 0)
goto buffer_exit;
replace_char_str(ordered_list_data->current_value, COMMA_SEP, SEMICOLON_SEP);
// COMMON:
ret = hp_get_common_data_from_buffer(&buffer_ptr, buffer_size,
&ordered_list_data->common);
if (ret < 0)
goto buffer_exit;
// ORD_LIST_SIZE:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&ordered_list_data->elements_size);
if (ordered_list_data->elements_size > MAX_ELEMENTS_SIZE) {
/* Report a message and limit elements size to maximum value */
pr_warn("Ordered List size value exceeded the maximum number of elements supported or data may be malformed\n");
ordered_list_data->elements_size = MAX_ELEMENTS_SIZE;
}
// ORD_LIST_ELEMENTS:
for (values = 0; values < ordered_list_data->elements_size; values++) {
ret = hp_get_string_from_buffer(&buffer_ptr, buffer_size,
ordered_list_data->elements[values],
sizeof(ordered_list_data->elements[values]));
if (ret < 0)
break;
}
buffer_exit:
return ret;
}
/**
* hp_populate_ordered_list_buffer_data() - Populate all properties of an
* instance under ordered list attribute
*
* @buffer_ptr: Buffer pointer
* @buffer_size: Buffer size
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_ordered_list_buffer_data(u8 *buffer_ptr, u32 *buffer_size, int instance_id,
struct kobject *attr_name_kobj)
{
struct ordered_list_data *ordered_list_data = &bioscfg_drv.ordered_list_data[instance_id];
int ret = 0;
ordered_list_data->attr_name_kobj = attr_name_kobj;
/* Populate ordered list elements */
ret = hp_populate_ordered_list_elements_from_buffer(buffer_ptr, buffer_size,
instance_id);
if (ret < 0)
return ret;
hp_update_attribute_permissions(ordered_list_data->common.is_readonly,
&ordered_list_current_val);
hp_friendly_user_name_update(ordered_list_data->common.path,
attr_name_kobj->name,
ordered_list_data->common.display_name,
sizeof(ordered_list_data->common.display_name));
return sysfs_create_group(attr_name_kobj, &ordered_list_attr_group);
}
/**
* hp_exit_ordered_list_attributes() - Clear all attribute data
*
* Clears all data allocated for this group of attributes
*/
void hp_exit_ordered_list_attributes(void)
{
int instance_id;
for (instance_id = 0; instance_id < bioscfg_drv.ordered_list_instances_count;
instance_id++) {
struct kobject *attr_name_kobj =
bioscfg_drv.ordered_list_data[instance_id].attr_name_kobj;
if (attr_name_kobj)
sysfs_remove_group(attr_name_kobj,
&ordered_list_attr_group);
}
bioscfg_drv.ordered_list_instances_count = 0;
kfree(bioscfg_drv.ordered_list_data);
bioscfg_drv.ordered_list_data = NULL;
}
@@ -0,0 +1,546 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Functions corresponding to password object type attributes under
* BIOS PASSWORD for use with hp-bioscfg driver.
*
* Copyright (c) 2022 HP Development Company, L.P.
*/
#include "bioscfg.h"
GET_INSTANCE_ID(password);
/*
* Clear all passwords copied to memory for a particular
* authentication instance
*/
static int clear_passwords(const int instance)
{
struct password_data *password_data = &bioscfg_drv.password_data[instance];
if (!password_data->is_enabled)
return 0;
memset(password_data->current_password,
0, sizeof(password_data->current_password));
memset(password_data->new_password,
0, sizeof(password_data->new_password));
return 0;
}
/*
* Clear all credentials copied to memory for both Power-ON and Setup
* BIOS instances
*/
int hp_clear_all_credentials(void)
{
int count = bioscfg_drv.password_instances_count;
int instance;
/* clear all passwords */
for (instance = 0; instance < count; instance++)
clear_passwords(instance);
/* clear auth_token */
kfree(bioscfg_drv.spm_data.auth_token);
bioscfg_drv.spm_data.auth_token = NULL;
return 0;
}
int hp_get_password_instance_for_type(const char *name)
{
int count = bioscfg_drv.password_instances_count;
int instance;
for (instance = 0; instance < count; instance++)
if (!strcmp(bioscfg_drv.password_data[instance].common.display_name, name))
return instance;
return -EINVAL;
}
static int validate_password_input(int instance_id, const char *buf)
{
int length;
struct password_data *password_data = &bioscfg_drv.password_data[instance_id];
length = strlen(buf);
if (buf[length - 1] == '\n')
length--;
if (length > MAX_PASSWD_SIZE)
return INVALID_BIOS_AUTH;
if (password_data->min_password_length > length ||
password_data->max_password_length < length)
return INVALID_BIOS_AUTH;
return SUCCESS;
}
ATTRIBUTE_N_PROPERTY_SHOW(is_enabled, password);
static struct kobj_attribute password_is_password_set = __ATTR_RO(is_enabled);
static int store_password_instance(struct kobject *kobj, const char *buf,
size_t count, bool is_current)
{
char *buf_cp;
int id, ret = 0;
buf_cp = kstrdup(buf, GFP_KERNEL);
if (!buf_cp)
return -ENOMEM;
ret = hp_enforce_single_line_input(buf_cp, count);
if (!ret) {
id = get_password_instance_id(kobj);
if (id >= 0)
ret = validate_password_input(id, buf_cp);
}
if (!ret) {
if (is_current)
strscpy(bioscfg_drv.password_data[id].current_password, buf_cp);
else
strscpy(bioscfg_drv.password_data[id].new_password, buf_cp);
}
kfree(buf_cp);
return ret < 0 ? ret : count;
}
static ssize_t current_password_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
return store_password_instance(kobj, buf, count, true);
}
static struct kobj_attribute password_current_password = __ATTR_WO(current_password);
static ssize_t new_password_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
return store_password_instance(kobj, buf, count, true);
}
static struct kobj_attribute password_new_password = __ATTR_WO(new_password);
ATTRIBUTE_N_PROPERTY_SHOW(min_password_length, password);
static struct kobj_attribute password_min_password_length = __ATTR_RO(min_password_length);
ATTRIBUTE_N_PROPERTY_SHOW(max_password_length, password);
static struct kobj_attribute password_max_password_length = __ATTR_RO(max_password_length);
static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
if (!strcmp(kobj->name, SETUP_PASSWD))
return sysfs_emit(buf, "%s\n", BIOS_ADMIN);
if (!strcmp(kobj->name, POWER_ON_PASSWD))
return sysfs_emit(buf, "%s\n", POWER_ON);
return -EIO;
}
static struct kobj_attribute password_role = __ATTR_RO(role);
static ssize_t mechanism_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int i = get_password_instance_id(kobj);
if (i < 0)
return i;
if (bioscfg_drv.password_data[i].mechanism != PASSWORD)
return -EINVAL;
return sysfs_emit(buf, "%s\n", PASSWD_MECHANISM_TYPES);
}
static struct kobj_attribute password_mechanism = __ATTR_RO(mechanism);
ATTRIBUTE_VALUES_PROPERTY_SHOW(encodings, password, SEMICOLON_SEP);
static struct kobj_attribute password_encodings_val = __ATTR_RO(encodings);
static struct attribute *password_attrs[] = {
&password_is_password_set.attr,
&password_min_password_length.attr,
&password_max_password_length.attr,
&password_current_password.attr,
&password_new_password.attr,
&password_role.attr,
&password_mechanism.attr,
&password_encodings_val.attr,
NULL
};
static const struct attribute_group password_attr_group = {
.attrs = password_attrs
};
int hp_alloc_password_data(void)
{
bioscfg_drv.password_instances_count = hp_get_instance_count(HP_WMI_BIOS_PASSWORD_GUID);
bioscfg_drv.password_data = kzalloc_objs(*bioscfg_drv.password_data,
bioscfg_drv.password_instances_count);
if (!bioscfg_drv.password_data) {
bioscfg_drv.password_instances_count = 0;
return -ENOMEM;
}
return 0;
}
/* Expected Values types associated with each element */
static const acpi_object_type expected_password_types[] = {
[NAME] = ACPI_TYPE_STRING,
[VALUE] = ACPI_TYPE_STRING,
[PATH] = ACPI_TYPE_STRING,
[IS_READONLY] = ACPI_TYPE_INTEGER,
[DISPLAY_IN_UI] = ACPI_TYPE_INTEGER,
[REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER,
[SEQUENCE] = ACPI_TYPE_INTEGER,
[PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER,
[PREREQUISITES] = ACPI_TYPE_STRING,
[SECURITY_LEVEL] = ACPI_TYPE_INTEGER,
[PSWD_MIN_LENGTH] = ACPI_TYPE_INTEGER,
[PSWD_MAX_LENGTH] = ACPI_TYPE_INTEGER,
[PSWD_SIZE] = ACPI_TYPE_INTEGER,
[PSWD_ENCODINGS] = ACPI_TYPE_STRING,
[PSWD_IS_SET] = ACPI_TYPE_INTEGER,
};
static int hp_populate_password_elements_from_package(union acpi_object *password_obj,
int password_obj_count,
int instance_id)
{
char *str_value = NULL;
int value_len;
int ret;
u32 size;
u32 int_value = 0;
int elem;
int reqs;
int eloc;
int pos_values;
struct password_data *password_data = &bioscfg_drv.password_data[instance_id];
if (!password_obj)
return -EINVAL;
for (elem = 1, eloc = 1; elem < password_obj_count; elem++, eloc++) {
/* ONLY look at the first PASSWORD_ELEM_CNT elements */
if (eloc == PSWD_ELEM_CNT)
goto exit_package;
switch (password_obj[elem].type) {
case ACPI_TYPE_STRING:
if (PREREQUISITES != elem && PSWD_ENCODINGS != elem) {
ret = hp_convert_hexstr_to_str(password_obj[elem].string.pointer,
password_obj[elem].string.length,
&str_value, &value_len);
if (ret)
continue;
}
break;
case ACPI_TYPE_INTEGER:
int_value = (u32)password_obj[elem].integer.value;
break;
default:
pr_warn("Unsupported object type [%d]\n", password_obj[elem].type);
continue;
}
/* Check that both expected and read object type match */
if (expected_password_types[eloc] != password_obj[elem].type) {
pr_err("Error expected type %d for elem %d, but got type %d instead\n",
expected_password_types[eloc], elem, password_obj[elem].type);
kfree(str_value);
return -EIO;
}
/* Assign appropriate element value to corresponding field*/
switch (eloc) {
case VALUE:
break;
case PATH:
strscpy(password_data->common.path, str_value);
break;
case IS_READONLY:
password_data->common.is_readonly = int_value;
break;
case DISPLAY_IN_UI:
password_data->common.display_in_ui = int_value;
break;
case REQUIRES_PHYSICAL_PRESENCE:
password_data->common.requires_physical_presence = int_value;
break;
case SEQUENCE:
password_data->common.sequence = int_value;
break;
case PREREQUISITES_SIZE:
if (int_value > MAX_PREREQUISITES_SIZE) {
pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
int_value = MAX_PREREQUISITES_SIZE;
}
password_data->common.prerequisites_size = int_value;
/* This step is needed to keep the expected
* element list pointing to the right obj[elem].type
* when the size is zero. PREREQUISITES
* object is omitted by BIOS when the size is
* zero.
*/
if (int_value == 0)
eloc++;
break;
case PREREQUISITES:
size = min_t(u32, password_data->common.prerequisites_size,
MAX_PREREQUISITES_SIZE);
for (reqs = 0; reqs < size; reqs++) {
if (elem + reqs >= password_obj_count) {
pr_err("Error elem-objects package is too small\n");
return -EINVAL;
}
ret = hp_convert_hexstr_to_str(password_obj[elem + reqs].string.pointer,
password_obj[elem + reqs].string.length,
&str_value, &value_len);
if (ret)
break;
strscpy(password_data->common.prerequisites[reqs], str_value);
kfree(str_value);
str_value = NULL;
}
break;
case SECURITY_LEVEL:
password_data->common.security_level = int_value;
break;
case PSWD_MIN_LENGTH:
password_data->min_password_length = int_value;
break;
case PSWD_MAX_LENGTH:
password_data->max_password_length = int_value;
break;
case PSWD_SIZE:
if (int_value > MAX_ENCODINGS_SIZE) {
pr_warn("Password Encoding size value exceeded the maximum number of elements supported or data may be malformed\n");
int_value = MAX_ENCODINGS_SIZE;
}
password_data->encodings_size = int_value;
/* This step is needed to keep the expected
* element list pointing to the right obj[elem].type
* when the size is zero. PSWD_ENCODINGS
* object is omitted by BIOS when the size is
* zero.
*/
if (int_value == 0)
eloc++;
break;
case PSWD_ENCODINGS:
size = min_t(u32, password_data->encodings_size, MAX_ENCODINGS_SIZE);
for (pos_values = 0; pos_values < size; pos_values++) {
ret = hp_convert_hexstr_to_str(password_obj[elem + pos_values].string.pointer,
password_obj[elem + pos_values].string.length,
&str_value, &value_len);
if (ret)
break;
strscpy(password_data->encodings[pos_values], str_value);
kfree(str_value);
str_value = NULL;
}
break;
case PSWD_IS_SET:
password_data->is_enabled = int_value;
break;
default:
pr_warn("Invalid element: %d found in Password attribute or data may be malformed\n", elem);
break;
}
kfree(str_value);
str_value = NULL;
}
exit_package:
kfree(str_value);
return 0;
}
/**
* hp_populate_password_package_data()
* Populate all properties for an instance under password attribute
*
* @password_obj: ACPI object with password data
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_password_package_data(union acpi_object *password_obj, int instance_id,
struct kobject *attr_name_kobj)
{
struct password_data *password_data = &bioscfg_drv.password_data[instance_id];
password_data->attr_name_kobj = attr_name_kobj;
hp_populate_password_elements_from_package(password_obj,
password_obj->package.count,
instance_id);
hp_friendly_user_name_update(password_data->common.path,
attr_name_kobj->name,
password_data->common.display_name,
sizeof(password_data->common.display_name));
if (!strcmp(attr_name_kobj->name, SETUP_PASSWD))
return sysfs_create_group(attr_name_kobj, &password_attr_group);
return sysfs_create_group(attr_name_kobj, &password_attr_group);
}
static int hp_populate_password_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size,
int instance_id)
{
int values;
int isreadonly;
struct password_data *password_data = &bioscfg_drv.password_data[instance_id];
int ret = 0;
/*
* Only data relevant to this driver and its functionality is
* read. BIOS defines the order in which each * element is
* read. Element 0 data is not relevant to this
* driver hence it is ignored. For clarity, all element names
* (DISPLAY_IN_UI) which defines the order in which is read
* and the name matches the variable where the data is stored.
*
* In earlier implementation, reported errors were ignored
* causing the data to remain uninitialized. It is not
* possible to determine if data read from BIOS is valid or
* not. It is for this reason functions may return a error
* without validating the data itself.
*/
// VALUE:
ret = hp_get_string_from_buffer(&buffer_ptr, buffer_size, password_data->current_password,
sizeof(password_data->current_password));
if (ret < 0)
goto buffer_exit;
// COMMON:
ret = hp_get_common_data_from_buffer(&buffer_ptr, buffer_size,
&password_data->common);
if (ret < 0)
goto buffer_exit;
// PSWD_MIN_LENGTH:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&password_data->min_password_length);
if (ret < 0)
goto buffer_exit;
// PSWD_MAX_LENGTH:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&password_data->max_password_length);
if (ret < 0)
goto buffer_exit;
// PSWD_SIZE:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&password_data->encodings_size);
if (ret < 0)
goto buffer_exit;
if (password_data->encodings_size > MAX_ENCODINGS_SIZE) {
/* Report a message and limit possible values size to maximum value */
pr_warn("Password Encoding size value exceeded the maximum number of elements supported or data may be malformed\n");
password_data->encodings_size = MAX_ENCODINGS_SIZE;
}
// PSWD_ENCODINGS:
for (values = 0; values < password_data->encodings_size; values++) {
ret = hp_get_string_from_buffer(&buffer_ptr, buffer_size,
password_data->encodings[values],
sizeof(password_data->encodings[values]));
if (ret < 0)
break;
}
// PSWD_IS_SET:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size, &isreadonly);
if (ret < 0)
goto buffer_exit;
password_data->is_enabled = isreadonly ? true : false;
buffer_exit:
return ret;
}
/**
* hp_populate_password_buffer_data()
* Populate all properties for an instance under password object attribute
*
* @buffer_ptr: Buffer pointer
* @buffer_size: Buffer size
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_password_buffer_data(u8 *buffer_ptr, u32 *buffer_size, int instance_id,
struct kobject *attr_name_kobj)
{
struct password_data *password_data = &bioscfg_drv.password_data[instance_id];
int ret = 0;
password_data->attr_name_kobj = attr_name_kobj;
/* Populate Password attributes */
ret = hp_populate_password_elements_from_buffer(buffer_ptr, buffer_size,
instance_id);
if (ret < 0)
return ret;
hp_friendly_user_name_update(password_data->common.path,
attr_name_kobj->name,
password_data->common.display_name,
sizeof(password_data->common.display_name));
if (!strcmp(attr_name_kobj->name, SETUP_PASSWD))
return sysfs_create_group(attr_name_kobj, &password_attr_group);
return sysfs_create_group(attr_name_kobj, &password_attr_group);
}
/**
* hp_exit_password_attributes() - Clear all attribute data
*
* Clears all data allocated for this group of attributes
*/
void hp_exit_password_attributes(void)
{
int instance_id;
for (instance_id = 0; instance_id < bioscfg_drv.password_instances_count;
instance_id++) {
struct kobject *attr_name_kobj =
bioscfg_drv.password_data[instance_id].attr_name_kobj;
if (attr_name_kobj)
sysfs_remove_group(attr_name_kobj,
&password_attr_group);
}
bioscfg_drv.password_instances_count = 0;
kfree(bioscfg_drv.password_data);
bioscfg_drv.password_data = NULL;
}
@@ -0,0 +1,380 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Functions corresponding to secure platform management object type
* attributes under BIOS PASSWORD for use with hp-bioscfg driver
*
* Copyright (c) 2022 HP Development Company, L.P.
*/
#include "bioscfg.h"
static const char * const spm_state_types[] = {
"not provisioned",
"provisioned",
"provisioning in progress",
};
static const char * const spm_mechanism_types[] = {
"not provisioned",
"signing-key",
"endorsement-key",
};
struct secureplatform_provisioning_data {
u8 state;
u8 version[2];
u8 reserved1;
u32 features;
u32 nonce;
u8 reserved2[28];
u8 sk_mod[MAX_KEY_MOD_SIZE];
u8 kek_mod[MAX_KEY_MOD_SIZE];
};
/**
* hp_calculate_security_buffer() - determines size of security buffer
* for authentication scheme
*
* @authentication: the authentication content
*
* Currently only supported type is Admin password
*/
size_t hp_calculate_security_buffer(const char *authentication)
{
size_t size, authlen;
if (!authentication)
return sizeof(u16) * 2;
authlen = strlen(authentication);
if (!authlen)
return sizeof(u16) * 2;
size = sizeof(u16) + authlen * sizeof(u16);
if (!strstarts(authentication, BEAM_PREFIX))
size += strlen(UTF_PREFIX) * sizeof(u16);
return size;
}
/**
* hp_populate_security_buffer() - builds a security buffer for
* authentication scheme
*
* @authbuf: the security buffer
* @authentication: the authentication content
*
* Currently only supported type is PLAIN TEXT
*/
int hp_populate_security_buffer(u16 *authbuf, const char *authentication)
{
u16 *auth = authbuf;
char *strprefix = NULL;
int ret = 0;
if (strstarts(authentication, BEAM_PREFIX)) {
/*
* BEAM_PREFIX is append to authbuf when a signature
* is provided and Sure Admin is enabled in BIOS
*/
/* BEAM_PREFIX found, convert part to unicode */
auth = hp_ascii_to_utf16_unicode(auth, authentication);
if (!auth)
return -EINVAL;
} else {
/*
* UTF-16 prefix is append to the * authbuf when a BIOS
* admin password is configured in BIOS
*/
/* append UTF_PREFIX to part and then convert it to unicode */
strprefix = kasprintf(GFP_KERNEL, "%s%s", UTF_PREFIX,
authentication);
if (!strprefix)
return -ENOMEM;
auth = hp_ascii_to_utf16_unicode(auth, strprefix);
kfree(strprefix);
if (!auth) {
ret = -EINVAL;
goto out_buffer;
}
}
out_buffer:
return ret;
}
static ssize_t update_spm_state(void)
{
struct secureplatform_provisioning_data data;
int ret;
ret = hp_wmi_perform_query(HPWMI_SECUREPLATFORM_GET_STATE,
HPWMI_SECUREPLATFORM, &data, 0,
sizeof(data));
if (ret < 0)
return ret;
bioscfg_drv.spm_data.mechanism = data.state;
if (bioscfg_drv.spm_data.mechanism)
bioscfg_drv.spm_data.is_enabled = 1;
return 0;
}
static ssize_t statusbin(struct kobject *kobj,
struct kobj_attribute *attr,
struct secureplatform_provisioning_data *buf)
{
int ret = hp_wmi_perform_query(HPWMI_SECUREPLATFORM_GET_STATE,
HPWMI_SECUREPLATFORM, buf, 0,
sizeof(*buf));
if (ret < 0)
return ret;
return sizeof(struct secureplatform_provisioning_data);
}
/*
* status_show - Reads SPM status
*/
static ssize_t status_show(struct kobject *kobj, struct kobj_attribute
*attr, char *buf)
{
int ret, i;
int len = 0;
struct secureplatform_provisioning_data data;
ret = statusbin(kobj, attr, &data);
if (ret < 0)
return ret;
/*
* 'status' is a read-only file that returns ASCII text in
* JSON format reporting the status information.
*
* "State": "not provisioned | provisioned | provisioning in progress ",
* "Version": " Major. Minor ",
* "Nonce": <16-bit unsigned number display in base 10>,
* "FeaturesInUse": <16-bit unsigned number display in base 10>,
* "EndorsementKeyMod": "<256 bytes in base64>",
* "SigningKeyMod": "<256 bytes in base64>"
*/
len += sysfs_emit_at(buf, len, "{\n");
len += sysfs_emit_at(buf, len, "\t\"State\": \"%s\",\n",
spm_state_types[data.state]);
len += sysfs_emit_at(buf, len, "\t\"Version\": \"%d.%d\"",
data.version[0], data.version[1]);
/*
* state == 0 means secure platform management
* feature is not configured in BIOS.
*/
if (data.state == 0) {
len += sysfs_emit_at(buf, len, "\n");
goto status_exit;
} else {
len += sysfs_emit_at(buf, len, ",\n");
}
len += sysfs_emit_at(buf, len, "\t\"Nonce\": %d,\n", data.nonce);
len += sysfs_emit_at(buf, len, "\t\"FeaturesInUse\": %d,\n", data.features);
len += sysfs_emit_at(buf, len, "\t\"EndorsementKeyMod\": \"");
for (i = 255; i >= 0; i--)
len += sysfs_emit_at(buf, len, " %u", data.kek_mod[i]);
len += sysfs_emit_at(buf, len, " \",\n");
len += sysfs_emit_at(buf, len, "\t\"SigningKeyMod\": \"");
for (i = 255; i >= 0; i--)
len += sysfs_emit_at(buf, len, " %u", data.sk_mod[i]);
/* Return buf contents */
len += sysfs_emit_at(buf, len, " \"\n");
status_exit:
len += sysfs_emit_at(buf, len, "}\n");
return len;
}
static struct kobj_attribute password_spm_status = __ATTR_RO(status);
ATTRIBUTE_SPM_N_PROPERTY_SHOW(is_enabled, spm);
static struct kobj_attribute password_spm_is_key_enabled = __ATTR_RO(is_enabled);
static ssize_t key_mechanism_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n",
spm_mechanism_types[bioscfg_drv.spm_data.mechanism]);
}
static struct kobj_attribute password_spm_key_mechanism = __ATTR_RO(key_mechanism);
static ssize_t sk_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
int ret;
int length;
length = count;
if (buf[length - 1] == '\n')
length--;
/* allocate space and copy current signing key */
bioscfg_drv.spm_data.signing_key = kmemdup(buf, length, GFP_KERNEL);
if (!bioscfg_drv.spm_data.signing_key)
return -ENOMEM;
/* submit signing key payload */
ret = hp_wmi_perform_query(HPWMI_SECUREPLATFORM_SET_SK,
HPWMI_SECUREPLATFORM,
(void *)bioscfg_drv.spm_data.signing_key,
count, 0);
if (!ret) {
bioscfg_drv.spm_data.mechanism = SIGNING_KEY;
hp_set_reboot_and_signal_event();
}
kfree(bioscfg_drv.spm_data.signing_key);
bioscfg_drv.spm_data.signing_key = NULL;
return ret ? ret : count;
}
static struct kobj_attribute password_spm_signing_key = __ATTR_WO(sk);
static ssize_t kek_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
int ret;
int length;
length = count;
if (buf[length - 1] == '\n')
length--;
/* allocate space and copy current signing key */
bioscfg_drv.spm_data.endorsement_key = kmemdup(buf, length, GFP_KERNEL);
if (!bioscfg_drv.spm_data.endorsement_key) {
ret = -ENOMEM;
goto exit_kek;
}
ret = hp_wmi_perform_query(HPWMI_SECUREPLATFORM_SET_KEK,
HPWMI_SECUREPLATFORM,
(void *)bioscfg_drv.spm_data.endorsement_key,
count, 0);
if (!ret) {
bioscfg_drv.spm_data.mechanism = ENDORSEMENT_KEY;
hp_set_reboot_and_signal_event();
}
exit_kek:
kfree(bioscfg_drv.spm_data.endorsement_key);
bioscfg_drv.spm_data.endorsement_key = NULL;
return ret ? ret : count;
}
static struct kobj_attribute password_spm_endorsement_key = __ATTR_WO(kek);
static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n", BIOS_SPM);
}
static struct kobj_attribute password_spm_role = __ATTR_RO(role);
static ssize_t auth_token_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
int ret = 0;
int length;
length = count;
if (buf[length - 1] == '\n')
length--;
/* allocate space and copy current auth token */
bioscfg_drv.spm_data.auth_token = kmemdup(buf, length, GFP_KERNEL);
if (!bioscfg_drv.spm_data.auth_token) {
ret = -ENOMEM;
goto exit_token;
}
return count;
exit_token:
kfree(bioscfg_drv.spm_data.auth_token);
bioscfg_drv.spm_data.auth_token = NULL;
return ret;
}
static struct kobj_attribute password_spm_auth_token = __ATTR_WO(auth_token);
static struct attribute *secure_platform_attrs[] = {
&password_spm_is_key_enabled.attr,
&password_spm_signing_key.attr,
&password_spm_endorsement_key.attr,
&password_spm_key_mechanism.attr,
&password_spm_status.attr,
&password_spm_role.attr,
&password_spm_auth_token.attr,
NULL,
};
static const struct attribute_group secure_platform_attr_group = {
.attrs = secure_platform_attrs,
};
void hp_exit_secure_platform_attributes(void)
{
/* remove secure platform sysfs entry and free key data*/
kfree(bioscfg_drv.spm_data.endorsement_key);
bioscfg_drv.spm_data.endorsement_key = NULL;
kfree(bioscfg_drv.spm_data.signing_key);
bioscfg_drv.spm_data.signing_key = NULL;
kfree(bioscfg_drv.spm_data.auth_token);
bioscfg_drv.spm_data.auth_token = NULL;
if (bioscfg_drv.spm_data.attr_name_kobj)
sysfs_remove_group(bioscfg_drv.spm_data.attr_name_kobj,
&secure_platform_attr_group);
}
int hp_populate_secure_platform_data(struct kobject *attr_name_kobj)
{
/* Populate data for Secure Platform Management */
bioscfg_drv.spm_data.attr_name_kobj = attr_name_kobj;
strscpy(bioscfg_drv.spm_data.attribute_name, SPM_STR);
bioscfg_drv.spm_data.is_enabled = 0;
bioscfg_drv.spm_data.mechanism = 0;
bioscfg_drv.pending_reboot = false;
update_spm_state();
bioscfg_drv.spm_data.endorsement_key = NULL;
bioscfg_drv.spm_data.signing_key = NULL;
bioscfg_drv.spm_data.auth_token = NULL;
return sysfs_create_group(attr_name_kobj, &secure_platform_attr_group);
}
@@ -0,0 +1,391 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Functions corresponding to string type attributes under
* HP_WMI_BIOS_STRING_GUID for use with hp-bioscfg driver.
*
* Copyright (c) 2022 HP Development Company, L.P.
*/
#include "bioscfg.h"
#define WMI_STRING_TYPE "HPBIOS_BIOSString"
GET_INSTANCE_ID(string);
static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
int instance_id = get_string_instance_id(kobj);
if (instance_id < 0)
return -EIO;
return sysfs_emit(buf, "%s\n",
bioscfg_drv.string_data[instance_id].current_value);
}
/**
* validate_string_input() -
* Validate input of current_value against min and max lengths
*
* @instance_id: The instance on which input is validated
* @buf: Input value
*/
static int validate_string_input(int instance_id, const char *buf)
{
int in_len = strlen(buf);
struct string_data *string_data = &bioscfg_drv.string_data[instance_id];
/* BIOS treats it as a read only attribute */
if (string_data->common.is_readonly)
return -EIO;
if (in_len < string_data->min_length || in_len > string_data->max_length)
return -ERANGE;
return 0;
}
static void update_string_value(int instance_id, char *attr_value)
{
struct string_data *string_data = &bioscfg_drv.string_data[instance_id];
/* Write settings to BIOS */
strscpy(string_data->current_value, attr_value);
}
/*
* ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name_language_code, string);
* static struct kobj_attribute string_display_langcode =
* __ATTR_RO(display_name_language_code);
*/
ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, string);
static struct kobj_attribute string_display_name =
__ATTR_RO(display_name);
ATTRIBUTE_PROPERTY_STORE(current_value, string);
static struct kobj_attribute string_current_val =
__ATTR_RW_MODE(current_value, 0644);
ATTRIBUTE_N_PROPERTY_SHOW(min_length, string);
static struct kobj_attribute string_min_length =
__ATTR_RO(min_length);
ATTRIBUTE_N_PROPERTY_SHOW(max_length, string);
static struct kobj_attribute string_max_length =
__ATTR_RO(max_length);
static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "string\n");
}
static struct kobj_attribute string_type =
__ATTR_RO(type);
static struct attribute *string_attrs[] = {
&common_display_langcode.attr,
&string_display_name.attr,
&string_current_val.attr,
&string_min_length.attr,
&string_max_length.attr,
&string_type.attr,
NULL
};
static const struct attribute_group string_attr_group = {
.attrs = string_attrs,
};
int hp_alloc_string_data(void)
{
bioscfg_drv.string_instances_count = hp_get_instance_count(HP_WMI_BIOS_STRING_GUID);
bioscfg_drv.string_data = kzalloc_objs(*bioscfg_drv.string_data,
bioscfg_drv.string_instances_count);
if (!bioscfg_drv.string_data) {
bioscfg_drv.string_instances_count = 0;
return -ENOMEM;
}
return 0;
}
/* Expected Values types associated with each element */
static const acpi_object_type expected_string_types[] = {
[NAME] = ACPI_TYPE_STRING,
[VALUE] = ACPI_TYPE_STRING,
[PATH] = ACPI_TYPE_STRING,
[IS_READONLY] = ACPI_TYPE_INTEGER,
[DISPLAY_IN_UI] = ACPI_TYPE_INTEGER,
[REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER,
[SEQUENCE] = ACPI_TYPE_INTEGER,
[PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER,
[PREREQUISITES] = ACPI_TYPE_STRING,
[SECURITY_LEVEL] = ACPI_TYPE_INTEGER,
[STR_MIN_LENGTH] = ACPI_TYPE_INTEGER,
[STR_MAX_LENGTH] = ACPI_TYPE_INTEGER,
};
static int hp_populate_string_elements_from_package(union acpi_object *string_obj,
int string_obj_count,
int instance_id)
{
char *str_value = NULL;
int value_len;
int ret = 0;
u32 int_value = 0;
int elem;
int reqs;
int eloc;
int size;
struct string_data *string_data = &bioscfg_drv.string_data[instance_id];
if (!string_obj)
return -EINVAL;
for (elem = 1, eloc = 1; elem < string_obj_count; elem++, eloc++) {
/* ONLY look at the first STRING_ELEM_CNT elements */
if (eloc == STR_ELEM_CNT)
goto exit_string_package;
switch (string_obj[elem].type) {
case ACPI_TYPE_STRING:
if (elem != PREREQUISITES) {
ret = hp_convert_hexstr_to_str(string_obj[elem].string.pointer,
string_obj[elem].string.length,
&str_value, &value_len);
if (ret)
continue;
}
break;
case ACPI_TYPE_INTEGER:
int_value = (u32)string_obj[elem].integer.value;
break;
default:
pr_warn("Unsupported object type [%d]\n", string_obj[elem].type);
continue;
}
/* Check that both expected and read object type match */
if (expected_string_types[eloc] != string_obj[elem].type) {
pr_err("Error expected type %d for elem %d, but got type %d instead\n",
expected_string_types[eloc], elem, string_obj[elem].type);
kfree(str_value);
return -EIO;
}
/* Assign appropriate element value to corresponding field*/
switch (eloc) {
case VALUE:
strscpy(string_data->current_value, str_value);
break;
case PATH:
strscpy(string_data->common.path, str_value);
break;
case IS_READONLY:
string_data->common.is_readonly = int_value;
break;
case DISPLAY_IN_UI:
string_data->common.display_in_ui = int_value;
break;
case REQUIRES_PHYSICAL_PRESENCE:
string_data->common.requires_physical_presence = int_value;
break;
case SEQUENCE:
string_data->common.sequence = int_value;
break;
case PREREQUISITES_SIZE:
if (int_value > MAX_PREREQUISITES_SIZE) {
pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
int_value = MAX_PREREQUISITES_SIZE;
}
string_data->common.prerequisites_size = int_value;
/*
* This step is needed to keep the expected
* element list pointing to the right obj[elem].type
* when the size is zero. PREREQUISITES
* object is omitted by BIOS when the size is
* zero.
*/
if (string_data->common.prerequisites_size == 0)
eloc++;
break;
case PREREQUISITES:
size = min_t(u32, string_data->common.prerequisites_size,
MAX_PREREQUISITES_SIZE);
for (reqs = 0; reqs < size; reqs++) {
if (elem + reqs >= string_obj_count) {
pr_err("Error elem-objects package is too small\n");
return -EINVAL;
}
ret = hp_convert_hexstr_to_str(string_obj[elem + reqs].string.pointer,
string_obj[elem + reqs].string.length,
&str_value, &value_len);
if (ret)
continue;
strscpy(string_data->common.prerequisites[reqs], str_value);
kfree(str_value);
str_value = NULL;
}
break;
case SECURITY_LEVEL:
string_data->common.security_level = int_value;
break;
case STR_MIN_LENGTH:
string_data->min_length = int_value;
break;
case STR_MAX_LENGTH:
string_data->max_length = int_value;
break;
default:
pr_warn("Invalid element: %d found in String attribute or data may be malformed\n", elem);
break;
}
kfree(str_value);
str_value = NULL;
}
exit_string_package:
kfree(str_value);
return 0;
}
/**
* hp_populate_string_package_data() -
* Populate all properties of an instance under string attribute
*
* @string_obj: ACPI object with string data
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_string_package_data(union acpi_object *string_obj,
int instance_id,
struct kobject *attr_name_kobj)
{
struct string_data *string_data = &bioscfg_drv.string_data[instance_id];
string_data->attr_name_kobj = attr_name_kobj;
hp_populate_string_elements_from_package(string_obj,
string_obj->package.count,
instance_id);
hp_update_attribute_permissions(string_data->common.is_readonly,
&string_current_val);
hp_friendly_user_name_update(string_data->common.path,
attr_name_kobj->name,
string_data->common.display_name,
sizeof(string_data->common.display_name));
return sysfs_create_group(attr_name_kobj, &string_attr_group);
}
static int hp_populate_string_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size,
int instance_id)
{
int ret = 0;
struct string_data *string_data = &bioscfg_drv.string_data[instance_id];
/*
* Only data relevant to this driver and its functionality is
* read. BIOS defines the order in which each * element is
* read. Element 0 data is not relevant to this
* driver hence it is ignored. For clarity, all element names
* (DISPLAY_IN_UI) which defines the order in which is read
* and the name matches the variable where the data is stored.
*
* In earlier implementation, reported errors were ignored
* causing the data to remain uninitialized. It is not
* possible to determine if data read from BIOS is valid or
* not. It is for this reason functions may return a error
* without validating the data itself.
*/
// VALUE:
ret = hp_get_string_from_buffer(&buffer_ptr, buffer_size, string_data->current_value,
sizeof(string_data->current_value));
if (ret < 0)
goto buffer_exit;
// COMMON:
ret = hp_get_common_data_from_buffer(&buffer_ptr, buffer_size, &string_data->common);
if (ret < 0)
goto buffer_exit;
// STR_MIN_LENGTH:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&string_data->min_length);
if (ret < 0)
goto buffer_exit;
// STR_MAX_LENGTH:
ret = hp_get_integer_from_buffer(&buffer_ptr, buffer_size,
&string_data->max_length);
buffer_exit:
return ret;
}
/**
* hp_populate_string_buffer_data() -
* Populate all properties of an instance under string attribute
*
* @buffer_ptr: Buffer pointer
* @buffer_size: Buffer size
* @instance_id: The instance to enumerate
* @attr_name_kobj: The parent kernel object
*/
int hp_populate_string_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
int instance_id,
struct kobject *attr_name_kobj)
{
struct string_data *string_data = &bioscfg_drv.string_data[instance_id];
int ret = 0;
string_data->attr_name_kobj = attr_name_kobj;
ret = hp_populate_string_elements_from_buffer(buffer_ptr, buffer_size,
instance_id);
if (ret < 0)
return ret;
hp_update_attribute_permissions(string_data->common.is_readonly,
&string_current_val);
hp_friendly_user_name_update(string_data->common.path,
attr_name_kobj->name,
string_data->common.display_name,
sizeof(string_data->common.display_name));
return sysfs_create_group(attr_name_kobj, &string_attr_group);
}
/**
* hp_exit_string_attributes() - Clear all attribute data
*
* Clears all data allocated for this group of attributes
*/
void hp_exit_string_attributes(void)
{
int instance_id;
for (instance_id = 0; instance_id < bioscfg_drv.string_instances_count;
instance_id++) {
struct kobject *attr_name_kobj =
bioscfg_drv.string_data[instance_id].attr_name_kobj;
if (attr_name_kobj)
sysfs_remove_group(attr_name_kobj, &string_attr_group);
}
bioscfg_drv.string_instances_count = 0;
kfree(bioscfg_drv.string_data);
bioscfg_drv.string_data = NULL;
}
@@ -0,0 +1,132 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Functions corresponding to sure start object type attributes under
* BIOS for use with hp-bioscfg driver
*
* Copyright (c) 2022 HP Development Company, L.P.
*/
#include "bioscfg.h"
#include <linux/types.h>
/* Maximum number of log entries supported when log entry size is 16
* bytes. This value is calculated by dividing 4096 (page size) by
* log entry size.
*/
#define LOG_MAX_ENTRIES 254
/*
* Current Log entry size. This value size will change in the
* future. The driver reads a total of 128 bytes for each log entry
* provided by BIOS but only the first 16 bytes are used/read.
*/
#define LOG_ENTRY_SIZE 16
/*
* audit_log_entry_count_show - Reports the number of
* existing audit log entries available
* to be read
*/
static ssize_t audit_log_entry_count_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
int ret;
u32 count = 0;
ret = hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG_COUNT,
HPWMI_SURESTART,
&count, 1, sizeof(count));
if (ret < 0)
return ret;
return sysfs_emit(buf, "%d,%d,%d\n", count, LOG_ENTRY_SIZE,
LOG_MAX_ENTRIES);
}
/*
* audit_log_entries_show() - Return all entries found in log file
*/
static ssize_t audit_log_entries_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
int ret;
int i;
u32 count = 0;
u8 audit_log_buffer[128];
// Get the number of event logs
ret = hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG_COUNT,
HPWMI_SURESTART,
&count, 1, sizeof(count));
if (ret < 0)
return ret;
/*
* The show() api will not work if the audit logs ever go
* beyond 4KB
*/
if (count * LOG_ENTRY_SIZE > PAGE_SIZE)
return -EIO;
/*
* We are guaranteed the buffer is 4KB so today all the event
* logs will fit
*/
for (i = 0; i < count; i++) {
audit_log_buffer[0] = i + 1;
/*
* read audit log entry at a time. 'buf' input value
* provides the audit log entry to be read. On
* input, Byte 0 = Audit Log entry number from
* beginning (1..254)
* Entry number 1 is the newest entry whereas the
* highest entry number (number of entries) is the
* oldest entry.
*/
ret = hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG,
HPWMI_SURESTART,
audit_log_buffer, 1, 128);
if (ret < 0 || (LOG_ENTRY_SIZE * i) > PAGE_SIZE) {
/*
* Encountered a failure while reading
* individual logs. Only a partial list of
* audit log will be returned.
*/
break;
} else {
memcpy(buf, audit_log_buffer, LOG_ENTRY_SIZE);
buf += LOG_ENTRY_SIZE;
}
}
return i * LOG_ENTRY_SIZE;
}
static struct kobj_attribute sure_start_audit_log_entry_count = __ATTR_RO(audit_log_entry_count);
static struct kobj_attribute sure_start_audit_log_entries = __ATTR_RO(audit_log_entries);
static struct attribute *sure_start_attrs[] = {
&sure_start_audit_log_entry_count.attr,
&sure_start_audit_log_entries.attr,
NULL
};
static const struct attribute_group sure_start_attr_group = {
.attrs = sure_start_attrs,
};
void hp_exit_sure_start_attributes(void)
{
sysfs_remove_group(bioscfg_drv.sure_start_attr_kobj,
&sure_start_attr_group);
}
int hp_populate_sure_start_data(struct kobject *attr_name_kobj)
{
bioscfg_drv.sure_start_attr_kobj = attr_name_kobj;
return sysfs_create_group(attr_name_kobj, &sure_start_attr_group);
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,389 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* hp_accel.c - Interface between LIS3LV02DL driver and HP ACPI BIOS
*
* Copyright (C) 2007-2008 Yan Burman
* Copyright (C) 2008 Eric Piel
* Copyright (C) 2008-2009 Pavel Machek
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/dmi.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/platform_device.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/wait.h>
#include <linux/poll.h>
#include <linux/freezer.h>
#include <linux/uaccess.h>
#include <linux/leds.h>
#include <linux/atomic.h>
#include <linux/acpi.h>
#include <linux/i8042.h>
#include <linux/serio.h>
#include "../../../misc/lis3lv02d/lis3lv02d.h"
/* Delayed LEDs infrastructure ------------------------------------ */
/* Special LED class that can defer work */
struct delayed_led_classdev {
struct led_classdev led_classdev;
struct work_struct work;
enum led_brightness new_brightness;
unsigned int led; /* For driver */
void (*set_brightness)(struct delayed_led_classdev *data, enum led_brightness value);
};
static inline void delayed_set_status_worker(struct work_struct *work)
{
struct delayed_led_classdev *data =
container_of(work, struct delayed_led_classdev, work);
data->set_brightness(data, data->new_brightness);
}
static inline void delayed_sysfs_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct delayed_led_classdev *data = container_of(led_cdev,
struct delayed_led_classdev, led_classdev);
data->new_brightness = brightness;
schedule_work(&data->work);
}
/* HP-specific accelerometer driver ------------------------------------ */
/* e0 25, e0 26, e0 27, e0 28 are scan codes that the accelerometer with acpi id
* HPQ6000 sends through the keyboard bus */
#define ACCEL_1 0x25
#define ACCEL_2 0x26
#define ACCEL_3 0x27
#define ACCEL_4 0x28
/* For automatic insertion of the module */
static const struct acpi_device_id lis3lv02d_device_ids[] = {
{"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */
{"HPQ6000", 0}, /* HP Mobile Data Protection System PNP */
{"HPQ6007", 0}, /* HP Mobile Data Protection System PNP */
{"", 0},
};
MODULE_DEVICE_TABLE(acpi, lis3lv02d_device_ids);
/**
* lis3lv02d_acpi_init - initialize the device for ACPI
* @lis3: pointer to the device struct
*
* Returns 0 on success.
*/
static int lis3lv02d_acpi_init(struct lis3lv02d *lis3)
{
return 0;
}
/**
* lis3lv02d_acpi_read - ACPI ALRD method: read a register
* @lis3: pointer to the device struct
* @reg: the register to read
* @ret: result of the operation
*
* Returns 0 on success.
*/
static int lis3lv02d_acpi_read(struct lis3lv02d *lis3, int reg, u8 *ret)
{
struct acpi_device *dev = lis3->bus_priv;
union acpi_object arg0 = { ACPI_TYPE_INTEGER };
struct acpi_object_list args = { 1, &arg0 };
unsigned long long lret;
acpi_status status;
arg0.integer.value = reg;
status = acpi_evaluate_integer(dev->handle, "ALRD", &args, &lret);
if (ACPI_FAILURE(status))
return -EINVAL;
*ret = lret;
return 0;
}
/**
* lis3lv02d_acpi_write - ACPI ALWR method: write to a register
* @lis3: pointer to the device struct
* @reg: the register to write to
* @val: the value to write
*
* Returns 0 on success.
*/
static int lis3lv02d_acpi_write(struct lis3lv02d *lis3, int reg, u8 val)
{
struct acpi_device *dev = lis3->bus_priv;
unsigned long long ret; /* Not used when writting */
union acpi_object in_obj[2];
struct acpi_object_list args = { 2, in_obj };
in_obj[0].type = ACPI_TYPE_INTEGER;
in_obj[0].integer.value = reg;
in_obj[1].type = ACPI_TYPE_INTEGER;
in_obj[1].integer.value = val;
if (acpi_evaluate_integer(dev->handle, "ALWR", &args, &ret) != AE_OK)
return -EINVAL;
return 0;
}
static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi)
{
lis3_dev.ac = *((union axis_conversion *)dmi->driver_data);
pr_info("hardware type %s found\n", dmi->ident);
return 1;
}
/* Represents, for each axis seen by userspace, the corresponding hw axis (+1).
* If the value is negative, the opposite of the hw value is used. */
#define DEFINE_CONV(name, x, y, z) \
static union axis_conversion lis3lv02d_axis_##name = \
{ .as_array = { x, y, z } }
DEFINE_CONV(normal, 1, 2, 3);
DEFINE_CONV(y_inverted, 1, -2, 3);
DEFINE_CONV(x_inverted, -1, 2, 3);
DEFINE_CONV(x_inverted_usd, -1, 2, -3);
DEFINE_CONV(z_inverted, 1, 2, -3);
DEFINE_CONV(xy_swap, 2, 1, 3);
DEFINE_CONV(xy_rotated_left, -2, 1, 3);
DEFINE_CONV(xy_rotated_left_usd, -2, 1, -3);
DEFINE_CONV(xy_swap_inverted, -2, -1, 3);
DEFINE_CONV(xy_rotated_right, 2, -1, 3);
DEFINE_CONV(xy_swap_yz_inverted, 2, -1, -3);
#define AXIS_DMI_MATCH(_ident, _name, _axis) { \
.ident = _ident, \
.callback = lis3lv02d_dmi_matched, \
.matches = { \
DMI_MATCH(DMI_PRODUCT_NAME, _name) \
}, \
.driver_data = &lis3lv02d_axis_##_axis \
}
#define AXIS_DMI_MATCH2(_ident, _class1, _name1, \
_class2, _name2, \
_axis) { \
.ident = _ident, \
.callback = lis3lv02d_dmi_matched, \
.matches = { \
DMI_MATCH(DMI_##_class1, _name1), \
DMI_MATCH(DMI_##_class2, _name2), \
}, \
.driver_data = &lis3lv02d_axis_##_axis \
}
static const struct dmi_system_id lis3lv02d_dmi_ids[] = {
/* product names are truncated to match all kinds of a same model */
AXIS_DMI_MATCH("NC64x0", "HP Compaq nc64", x_inverted),
AXIS_DMI_MATCH("NC84x0", "HP Compaq nc84", z_inverted),
AXIS_DMI_MATCH("NX9420", "HP Compaq nx9420", x_inverted),
AXIS_DMI_MATCH("NW9440", "HP Compaq nw9440", x_inverted),
AXIS_DMI_MATCH("NC2510", "HP Compaq 2510", y_inverted),
AXIS_DMI_MATCH("NC2710", "HP Compaq 2710", xy_swap),
AXIS_DMI_MATCH("NC8510", "HP Compaq 8510", xy_swap_inverted),
AXIS_DMI_MATCH("HP2133", "HP 2133", xy_rotated_left),
AXIS_DMI_MATCH("HP2140", "HP 2140", xy_swap_inverted),
AXIS_DMI_MATCH("NC653x", "HP Compaq 653", xy_rotated_left_usd),
AXIS_DMI_MATCH("NC6730b", "HP Compaq 6730b", xy_rotated_left_usd),
AXIS_DMI_MATCH("NC6730s", "HP Compaq 6730s", xy_swap),
AXIS_DMI_MATCH("NC651xx", "HP Compaq 651", xy_rotated_right),
AXIS_DMI_MATCH("NC6710x", "HP Compaq 6710", xy_swap_yz_inverted),
AXIS_DMI_MATCH("NC6715x", "HP Compaq 6715", y_inverted),
AXIS_DMI_MATCH("NC693xx", "HP EliteBook 693", xy_rotated_right),
AXIS_DMI_MATCH("NC693xx", "HP EliteBook 853", xy_swap),
AXIS_DMI_MATCH("NC854xx", "HP EliteBook 854", y_inverted),
AXIS_DMI_MATCH("NC273xx", "HP EliteBook 273", y_inverted),
/* Intel-based HP Pavilion dv5 */
AXIS_DMI_MATCH2("HPDV5_I",
PRODUCT_NAME, "HP Pavilion dv5",
BOARD_NAME, "3603",
x_inverted),
/* AMD-based HP Pavilion dv5 */
AXIS_DMI_MATCH2("HPDV5_A",
PRODUCT_NAME, "HP Pavilion dv5",
BOARD_NAME, "3600",
y_inverted),
AXIS_DMI_MATCH("DV7", "HP Pavilion dv7", x_inverted),
AXIS_DMI_MATCH("HP8710", "HP Compaq 8710", y_inverted),
AXIS_DMI_MATCH("HDX18", "HP HDX 18", x_inverted),
AXIS_DMI_MATCH("HPB432x", "HP ProBook 432", xy_rotated_left),
AXIS_DMI_MATCH("HPB440G3", "HP ProBook 440 G3", x_inverted_usd),
AXIS_DMI_MATCH("HPB440G4", "HP ProBook 440 G4", x_inverted),
AXIS_DMI_MATCH("HPB442x", "HP ProBook 442", xy_rotated_left),
AXIS_DMI_MATCH("HPB450G0", "HP ProBook 450 G0", x_inverted),
AXIS_DMI_MATCH("HPB452x", "HP ProBook 452", y_inverted),
AXIS_DMI_MATCH("HPB522x", "HP ProBook 522", xy_swap),
AXIS_DMI_MATCH("HPB532x", "HP ProBook 532", y_inverted),
AXIS_DMI_MATCH("HPB655x", "HP ProBook 655", xy_swap_inverted),
AXIS_DMI_MATCH("Mini510x", "HP Mini 510", xy_rotated_left_usd),
AXIS_DMI_MATCH("HPB63xx", "HP ProBook 63", xy_swap),
AXIS_DMI_MATCH("HPB64xx", "HP ProBook 64", xy_swap),
AXIS_DMI_MATCH("HPB64xx", "HP EliteBook 84", xy_swap),
AXIS_DMI_MATCH("HPB65xx", "HP ProBook 65", x_inverted),
AXIS_DMI_MATCH("HPZBook15", "HP ZBook 15", x_inverted),
AXIS_DMI_MATCH("HPZBook17G5", "HP ZBook 17 G5", x_inverted),
AXIS_DMI_MATCH("HPZBook17", "HP ZBook 17", xy_swap_yz_inverted),
{ NULL, }
/* Laptop models without axis info (yet):
* "NC6910" "HP Compaq 6910"
* "NC2400" "HP Compaq nc2400"
* "NX74x0" "HP Compaq nx74"
* "NX6325" "HP Compaq nx6325"
* "NC4400" "HP Compaq nc4400"
*/
};
static void hpled_set(struct delayed_led_classdev *led_cdev, enum led_brightness value)
{
struct acpi_device *dev = lis3_dev.bus_priv;
unsigned long long ret; /* Not used when writing */
union acpi_object in_obj[1];
struct acpi_object_list args = { 1, in_obj };
in_obj[0].type = ACPI_TYPE_INTEGER;
in_obj[0].integer.value = !!value;
acpi_evaluate_integer(dev->handle, "ALED", &args, &ret);
}
static struct delayed_led_classdev hpled_led = {
.led_classdev = {
.name = "hp::hddprotect",
.default_trigger = "none",
.brightness_set = delayed_sysfs_set,
.flags = LED_CORE_SUSPENDRESUME,
},
.set_brightness = hpled_set,
};
static bool hp_accel_i8042_filter(unsigned char data, unsigned char str,
struct serio *port, void *context)
{
static bool extended;
if (str & I8042_STR_AUXDATA)
return false;
if (data == 0xe0) {
extended = true;
return true;
} else if (unlikely(extended)) {
extended = false;
switch (data) {
case ACCEL_1:
case ACCEL_2:
case ACCEL_3:
case ACCEL_4:
return true;
default:
serio_interrupt(port, 0xe0, 0);
return false;
}
}
return false;
}
static int lis3lv02d_probe(struct platform_device *device)
{
int ret;
lis3_dev.bus_priv = ACPI_COMPANION(&device->dev);
if (!lis3_dev.bus_priv)
return -ENODEV;
lis3_dev.init = lis3lv02d_acpi_init;
lis3_dev.read = lis3lv02d_acpi_read;
lis3_dev.write = lis3lv02d_acpi_write;
/* obtain IRQ number of our device from ACPI */
ret = platform_get_irq_optional(device, 0);
if (ret > 0)
lis3_dev.irq = ret;
/* If possible use a "standard" axes order */
if (lis3_dev.ac.x && lis3_dev.ac.y && lis3_dev.ac.z) {
pr_info("Using custom axes %d,%d,%d\n",
lis3_dev.ac.x, lis3_dev.ac.y, lis3_dev.ac.z);
} else if (dmi_check_system(lis3lv02d_dmi_ids) == 0) {
pr_info("laptop model unknown, using default axes configuration\n");
lis3_dev.ac = lis3lv02d_axis_normal;
}
/* call the core layer do its init */
ret = lis3lv02d_init_device(&lis3_dev);
if (ret)
return ret;
/* filter to remove HPQ6000 accelerometer data
* from keyboard bus stream */
if (strstr(dev_name(&device->dev), "HPQ6000"))
i8042_install_filter(hp_accel_i8042_filter, NULL);
INIT_WORK(&hpled_led.work, delayed_set_status_worker);
ret = led_classdev_register(NULL, &hpled_led.led_classdev);
if (ret) {
i8042_remove_filter(hp_accel_i8042_filter);
lis3lv02d_joystick_disable(&lis3_dev);
lis3lv02d_poweroff(&lis3_dev);
flush_work(&hpled_led.work);
lis3lv02d_remove_fs(&lis3_dev);
return ret;
}
return ret;
}
static void lis3lv02d_remove(struct platform_device *device)
{
i8042_remove_filter(hp_accel_i8042_filter);
lis3lv02d_joystick_disable(&lis3_dev);
lis3lv02d_poweroff(&lis3_dev);
led_classdev_unregister(&hpled_led.led_classdev);
flush_work(&hpled_led.work);
lis3lv02d_remove_fs(&lis3_dev);
}
static int __maybe_unused lis3lv02d_suspend(struct device *dev)
{
/* make sure the device is off when we suspend */
lis3lv02d_poweroff(&lis3_dev);
return 0;
}
static int __maybe_unused lis3lv02d_resume(struct device *dev)
{
lis3lv02d_poweron(&lis3_dev);
return 0;
}
static SIMPLE_DEV_PM_OPS(hp_accel_pm, lis3lv02d_suspend, lis3lv02d_resume);
/* For the HP MDPS aka 3D Driveguard */
static struct platform_driver lis3lv02d_driver = {
.probe = lis3lv02d_probe,
.remove = lis3lv02d_remove,
.driver = {
.name = "hp_accel",
.pm = &hp_accel_pm,
.acpi_match_table = lis3lv02d_device_ids,
},
};
module_platform_driver(lis3lv02d_driver);
MODULE_DESCRIPTION("Glue between LIS3LV02Dx and HP ACPI BIOS and support for disk protection LED.");
MODULE_AUTHOR("Yan Burman, Eric Piel, Pavel Machek");
MODULE_LICENSE("GPL");
@@ -0,0 +1,263 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* HP Compaq TC1100 Tablet WMI Extras Driver
*
* Copyright (C) 2007 Carlos Corbacho <carlos@strangeworlds.co.uk>
* Copyright (C) 2004 Jamey Hicks <jamey.hicks@hp.com>
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/acpi.h>
#include <linux/platform_device.h>
#define GUID "C364AC71-36DB-495A-8494-B439D472A505"
#define TC1100_INSTANCE_WIRELESS 1
#define TC1100_INSTANCE_JOGDIAL 2
MODULE_AUTHOR("Jamey Hicks, Carlos Corbacho");
MODULE_DESCRIPTION("HP Compaq TC1100 Tablet WMI Extras");
MODULE_LICENSE("GPL");
MODULE_ALIAS("wmi:C364AC71-36DB-495A-8494-B439D472A505");
static struct platform_device *tc1100_device;
struct tc1100_data {
u32 wireless;
u32 jogdial;
};
#ifdef CONFIG_PM
static struct tc1100_data suspend_data;
#endif
/* --------------------------------------------------------------------------
Device Management
-------------------------------------------------------------------------- */
static int get_state(u32 *out, u8 instance)
{
u32 tmp;
acpi_status status;
struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
if (!out)
return -EINVAL;
if (instance > 2)
return -ENODEV;
status = wmi_query_block(GUID, instance, &result);
if (ACPI_FAILURE(status))
return -ENODEV;
obj = (union acpi_object *) result.pointer;
if (obj && obj->type == ACPI_TYPE_INTEGER) {
tmp = obj->integer.value;
} else {
tmp = 0;
}
if (result.length > 0)
kfree(result.pointer);
switch (instance) {
case TC1100_INSTANCE_WIRELESS:
*out = (tmp == 3) ? 1 : 0;
return 0;
case TC1100_INSTANCE_JOGDIAL:
*out = (tmp == 1) ? 0 : 1;
return 0;
default:
return -ENODEV;
}
}
static int set_state(u32 *in, u8 instance)
{
u32 value;
acpi_status status;
struct acpi_buffer input;
if (!in)
return -EINVAL;
if (instance > 2)
return -ENODEV;
switch (instance) {
case TC1100_INSTANCE_WIRELESS:
value = (*in) ? 1 : 2;
break;
case TC1100_INSTANCE_JOGDIAL:
value = (*in) ? 0 : 1;
break;
default:
return -ENODEV;
}
input.length = sizeof(u32);
input.pointer = &value;
status = wmi_set_block(GUID, instance, &input);
if (ACPI_FAILURE(status))
return -ENODEV;
return 0;
}
/* --------------------------------------------------------------------------
FS Interface (/sys)
-------------------------------------------------------------------------- */
/*
* Read/ write bool sysfs macro
*/
#define show_set_bool(value, instance) \
static ssize_t \
show_bool_##value(struct device *dev, struct device_attribute *attr, \
char *buf) \
{ \
u32 result; \
acpi_status status = get_state(&result, instance); \
if (ACPI_SUCCESS(status)) \
return sprintf(buf, "%d\n", result); \
return sprintf(buf, "Read error\n"); \
} \
\
static ssize_t \
set_bool_##value(struct device *dev, struct device_attribute *attr, \
const char *buf, size_t count) \
{ \
u32 tmp = simple_strtoul(buf, NULL, 10); \
acpi_status status = set_state(&tmp, instance); \
if (ACPI_FAILURE(status)) \
return -EINVAL; \
return count; \
} \
static DEVICE_ATTR(value, S_IRUGO | S_IWUSR, \
show_bool_##value, set_bool_##value);
show_set_bool(wireless, TC1100_INSTANCE_WIRELESS);
show_set_bool(jogdial, TC1100_INSTANCE_JOGDIAL);
static struct attribute *tc1100_attributes[] = {
&dev_attr_wireless.attr,
&dev_attr_jogdial.attr,
NULL
};
static const struct attribute_group tc1100_attribute_group = {
.attrs = tc1100_attributes,
};
/* --------------------------------------------------------------------------
Driver Model
-------------------------------------------------------------------------- */
static int __init tc1100_probe(struct platform_device *device)
{
return sysfs_create_group(&device->dev.kobj, &tc1100_attribute_group);
}
static void tc1100_remove(struct platform_device *device)
{
sysfs_remove_group(&device->dev.kobj, &tc1100_attribute_group);
}
#ifdef CONFIG_PM
static int tc1100_suspend(struct device *dev)
{
int ret;
ret = get_state(&suspend_data.wireless, TC1100_INSTANCE_WIRELESS);
if (ret)
return ret;
ret = get_state(&suspend_data.jogdial, TC1100_INSTANCE_JOGDIAL);
if (ret)
return ret;
return 0;
}
static int tc1100_resume(struct device *dev)
{
int ret;
ret = set_state(&suspend_data.wireless, TC1100_INSTANCE_WIRELESS);
if (ret)
return ret;
ret = set_state(&suspend_data.jogdial, TC1100_INSTANCE_JOGDIAL);
if (ret)
return ret;
return 0;
}
static const struct dev_pm_ops tc1100_pm_ops = {
.suspend = tc1100_suspend,
.resume = tc1100_resume,
.freeze = tc1100_suspend,
.restore = tc1100_resume,
};
#endif
static struct platform_driver tc1100_driver = {
.driver = {
.name = "tc1100-wmi",
#ifdef CONFIG_PM
.pm = &tc1100_pm_ops,
#endif
},
.remove = tc1100_remove,
};
static int __init tc1100_init(void)
{
int error;
if (!wmi_has_guid(GUID))
return -ENODEV;
tc1100_device = platform_device_alloc("tc1100-wmi", PLATFORM_DEVID_NONE);
if (!tc1100_device)
return -ENOMEM;
error = platform_device_add(tc1100_device);
if (error)
goto err_device_put;
error = platform_driver_probe(&tc1100_driver, tc1100_probe);
if (error)
goto err_device_del;
pr_info("HP Compaq TC1100 Tablet WMI Extras loaded\n");
return 0;
err_device_del:
platform_device_del(tc1100_device);
err_device_put:
platform_device_put(tc1100_device);
return error;
}
static void __exit tc1100_exit(void)
{
platform_device_unregister(tc1100_device);
platform_driver_unregister(&tc1100_driver);
}
module_init(tc1100_init);
module_exit(tc1100_exit);