drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c

Source file repositories/reference/linux-study-clean/drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
Extension
.c
Size
7752 bytes
Lines
313
Domain
Driver Families
Bucket
drivers/platform
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

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
 *

Annotation

Implementation Notes