drivers/platform/x86/intel/speed_select_if/isst_if_common.c

Source file repositories/reference/linux-study-clean/drivers/platform/x86/intel/speed_select_if/isst_if_common.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/x86/intel/speed_select_if/isst_if_common.c
Extension
.c
Size
19973 bytes
Lines
827
Domain
Driver Families
Bucket
drivers/platform
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct file_operations isst_if_char_driver_ops = {
	.open = isst_if_open,
	.unlocked_ioctl = isst_if_def_ioctl,
	.release = isst_if_relase,
};

static struct miscdevice isst_if_char_driver = {
	.minor		= MISC_DYNAMIC_MINOR,
	.name		= "isst_interface",
	.fops		= &isst_if_char_driver_ops,
};

static int isst_misc_reg(void)
{
	int ret;

	ret = isst_if_cpu_info_init();
	if (ret)
		return ret;

	ret = misc_register(&isst_if_char_driver);
	if (ret)
		isst_if_cpu_info_exit();

	return ret;
}

static void isst_misc_unreg(void)
{
	misc_deregister(&isst_if_char_driver);
	isst_if_cpu_info_exit();
}

/**
 * isst_if_cdev_register() - Register callback for IOCTL
 * @device_type: The device type this callback handling.
 * @cb:	Callback structure.
 *
 * This function registers a callback to device type. On very first call
 * it will register a misc device, which is used for user kernel interface.
 * Other calls simply increment ref count. Registry will fail, if the user
 * already opened misc device for operation. Also if the misc device
 * creation failed, then it will not try again and all callers will get
 * failure code.
 *
 * Return: Return the return value from the misc creation device or -EINVAL
 * for unsupported device type.
 */
int isst_if_cdev_register(int device_type, struct isst_if_cmd_cb *cb)
{
	if (device_type >= ISST_IF_DEV_MAX)
		return -EINVAL;

	if (device_type < ISST_IF_DEV_TPMI && isst_hpm_support)
		return -ENODEV;

	mutex_lock(&punit_misc_dev_open_lock);
	/* Device is already open, we don't want to add new callbacks */
	if (misc_device_open) {
		mutex_unlock(&punit_misc_dev_open_lock);
		return -EAGAIN;
	}
	if (!cb->api_version)
		cb->api_version = ISST_IF_API_VERSION;
	if (cb->api_version > isst_if_api_version)
		isst_if_api_version = cb->api_version;
	memcpy(&punit_callbacks[device_type], cb, sizeof(*cb));
	punit_callbacks[device_type].registered = 1;
	mutex_unlock(&punit_misc_dev_open_lock);

	return 0;
}
EXPORT_SYMBOL_GPL(isst_if_cdev_register);

/**
 * isst_if_cdev_unregister() - Unregister callback for IOCTL
 * @device_type: The device type to unregister.
 *
 * This function unregisters the previously registered callback. If this
 * is the last callback unregistering, then misc device is removed.
 *
 * Return: None.
 */
void isst_if_cdev_unregister(int device_type)
{
	mutex_lock(&punit_misc_dev_open_lock);
	punit_callbacks[device_type].def_ioctl = NULL;
	punit_callbacks[device_type].registered = 0;
	if (device_type == ISST_IF_DEV_MBOX)
		isst_delete_hash();

Annotation

Implementation Notes