⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pci_hotplug_core.c

📁 h内核
💻 C
📖 第 1 页 / 共 2 页
字号:
	enum pci_bus_speed value;	retval = get_cur_bus_speed (slot, &value);	if (retval)		goto exit;	if (value == PCI_SPEED_UNKNOWN)		speed_string = unknown_speed;	else		speed_string = pci_bus_speed_strings[value];		retval = sprintf (buf, "%s\n", speed_string);exit:	return retval;}static struct hotplug_slot_attribute hotplug_slot_attr_cur_bus_speed = {	.attr = {.name = "cur_bus_speed", .mode = S_IFREG | S_IRUGO},	.show = cur_bus_speed_read_file,};static ssize_t test_write_file (struct hotplug_slot *slot, const char *buf,		size_t count){	unsigned long ltest;	u32 test;	int retval = 0;	ltest = simple_strtoul (buf, NULL, 10);	test = (u32)(ltest & 0xffffffff);	dbg ("test = %d\n", test);	if (!try_module_get(slot->ops->owner)) {		retval = -ENODEV;		goto exit;	}	if (slot->ops->hardware_test)		retval = slot->ops->hardware_test(slot, test);	module_put(slot->ops->owner);exit:		if (retval)		return retval;	return count;}static struct hotplug_slot_attribute hotplug_slot_attr_test = {	.attr = {.name = "test", .mode = S_IFREG | S_IRUGO | S_IWUSR},	.store = test_write_file};static int has_power_file (struct hotplug_slot *slot){	if ((!slot) || (!slot->ops))		return -ENODEV;	if ((slot->ops->enable_slot) ||	    (slot->ops->disable_slot) ||	    (slot->ops->get_power_status))		return 0;	return -ENOENT;}static int has_attention_file (struct hotplug_slot *slot){	if ((!slot) || (!slot->ops))		return -ENODEV;	if ((slot->ops->set_attention_status) ||	    (slot->ops->get_attention_status))		return 0;	return -ENOENT;}static int has_latch_file (struct hotplug_slot *slot){	if ((!slot) || (!slot->ops))		return -ENODEV;	if (slot->ops->get_latch_status)		return 0;	return -ENOENT;}static int has_adapter_file (struct hotplug_slot *slot){	if ((!slot) || (!slot->ops))		return -ENODEV;	if (slot->ops->get_adapter_status)		return 0;	return -ENOENT;}static int has_address_file (struct hotplug_slot *slot){	if ((!slot) || (!slot->ops))		return -ENODEV;	if (slot->ops->get_address)		return 0;	return -ENOENT;}static int has_max_bus_speed_file (struct hotplug_slot *slot){	if ((!slot) || (!slot->ops))		return -ENODEV;	if (slot->ops->get_max_bus_speed)		return 0;	return -ENOENT;}static int has_cur_bus_speed_file (struct hotplug_slot *slot){	if ((!slot) || (!slot->ops))		return -ENODEV;	if (slot->ops->get_cur_bus_speed)		return 0;	return -ENOENT;}static int has_test_file (struct hotplug_slot *slot){	if ((!slot) || (!slot->ops))		return -ENODEV;	if (slot->ops->hardware_test)		return 0;	return -ENOENT;}static int fs_add_slot (struct hotplug_slot *slot){	if (has_power_file(slot) == 0)		sysfs_create_file(&slot->kobj, &hotplug_slot_attr_power.attr);	if (has_attention_file(slot) == 0)		sysfs_create_file(&slot->kobj, &hotplug_slot_attr_attention.attr);	if (has_latch_file(slot) == 0)		sysfs_create_file(&slot->kobj, &hotplug_slot_attr_latch.attr);	if (has_adapter_file(slot) == 0)		sysfs_create_file(&slot->kobj, &hotplug_slot_attr_presence.attr);	if (has_address_file(slot) == 0)		sysfs_create_file(&slot->kobj, &hotplug_slot_attr_address.attr);	if (has_max_bus_speed_file(slot) == 0)		sysfs_create_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);	if (has_cur_bus_speed_file(slot) == 0)		sysfs_create_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr);	if (has_test_file(slot) == 0)		sysfs_create_file(&slot->kobj, &hotplug_slot_attr_test.attr);	return 0;}static void fs_remove_slot (struct hotplug_slot *slot){	if (has_power_file(slot) == 0)		sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr);	if (has_attention_file(slot) == 0)		sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_attention.attr);	if (has_latch_file(slot) == 0)		sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_latch.attr);	if (has_adapter_file(slot) == 0)		sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr);	if (has_address_file(slot) == 0)		sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr);	if (has_max_bus_speed_file(slot) == 0)		sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);	if (has_cur_bus_speed_file(slot) == 0)		sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr);	if (has_test_file(slot) == 0)		sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_test.attr);}static struct hotplug_slot *get_slot_from_name (const char *name){	struct hotplug_slot *slot;	struct list_head *tmp;	list_for_each (tmp, &pci_hotplug_slot_list) {		slot = list_entry (tmp, struct hotplug_slot, slot_list);		if (strcmp(slot->name, name) == 0)			return slot;	}	return NULL;}/** * pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem * @slot: pointer to the &struct hotplug_slot to register * * Registers a hotplug slot with the pci hotplug subsystem, which will allow * userspace interaction to the slot. * * Returns 0 if successful, anything else for an error. */int pci_hp_register (struct hotplug_slot *slot){	int result;	if (slot == NULL)		return -ENODEV;	if ((slot->info == NULL) || (slot->ops == NULL))		return -EINVAL;	kobject_set_name(&slot->kobj, "%s", slot->name);	kobj_set_kset_s(slot, pci_hotplug_slots_subsys);	/* this can fail if we have already registered a slot with the same name */	if (kobject_register(&slot->kobj)) {		err("Unable to register kobject");		return -EINVAL;	}			list_add (&slot->slot_list, &pci_hotplug_slot_list);	result = fs_add_slot (slot);	dbg ("Added slot %s to the list\n", slot->name);	return result;}/** * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem * @slot: pointer to the &struct hotplug_slot to deregister * * The @slot must have been registered with the pci hotplug subsystem * previously with a call to pci_hp_register(). * * Returns 0 if successful, anything else for an error. */int pci_hp_deregister (struct hotplug_slot *slot){	struct hotplug_slot *temp;	if (slot == NULL)		return -ENODEV;	temp = get_slot_from_name (slot->name);	if (temp != slot) {		return -ENODEV;	}	list_del (&slot->slot_list);	fs_remove_slot (slot);	dbg ("Removed slot %s from the list\n", slot->name);	kobject_unregister(&slot->kobj);	return 0;}/** * pci_hp_change_slot_info - changes the slot's information structure in the core * @slot: pointer to the slot whose info has changed * @info: pointer to the info copy into the slot's info structure * * @slot must have been registered with the pci  * hotplug subsystem previously with a call to pci_hp_register(). * * Returns 0 if successful, anything else for an error. */int pci_hp_change_slot_info (struct hotplug_slot *slot, struct hotplug_slot_info *info){	if ((slot == NULL) || (info == NULL))		return -ENODEV;	/*	* check all fields in the info structure, and update timestamps	* for the files referring to the fields that have now changed.	*/	if ((has_power_file(slot) == 0) &&	    (slot->info->power_status != info->power_status))		sysfs_update_file(&slot->kobj, &hotplug_slot_attr_power.attr);	if ((has_attention_file(slot) == 0) &&	    (slot->info->attention_status != info->attention_status))		sysfs_update_file(&slot->kobj, &hotplug_slot_attr_attention.attr);	if ((has_latch_file(slot) == 0) &&	    (slot->info->latch_status != info->latch_status))		sysfs_update_file(&slot->kobj, &hotplug_slot_attr_latch.attr);	if ((has_adapter_file(slot) == 0) &&	    (slot->info->adapter_status != info->adapter_status))		sysfs_update_file(&slot->kobj, &hotplug_slot_attr_presence.attr);	if ((has_address_file(slot) == 0) &&	    (slot->info->address != info->address))		sysfs_update_file(&slot->kobj, &hotplug_slot_attr_address.attr);	if ((has_max_bus_speed_file(slot) == 0) &&	    (slot->info->max_bus_speed != info->max_bus_speed))		sysfs_update_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);	if ((has_cur_bus_speed_file(slot) == 0) &&	    (slot->info->cur_bus_speed != info->cur_bus_speed))		sysfs_update_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr);	memcpy (slot->info, info, sizeof (struct hotplug_slot_info));	return 0;}static int __init pci_hotplug_init (void){	int result;	kset_set_kset_s(&pci_hotplug_slots_subsys, pci_bus_type.subsys);	result = subsystem_register(&pci_hotplug_slots_subsys);	if (result) {		err("Register subsys with error %d\n", result);		goto exit;	}	result = cpci_hotplug_init(debug);	if (result) {		err ("cpci_hotplug_init with error %d\n", result);		goto err_subsys;	}	info (DRIVER_DESC " version: " DRIVER_VERSION "\n");	goto exit;	err_subsys:	subsystem_unregister(&pci_hotplug_slots_subsys);exit:	return result;}static void __exit pci_hotplug_exit (void){	cpci_hotplug_exit();	subsystem_unregister(&pci_hotplug_slots_subsys);}module_init(pci_hotplug_init);module_exit(pci_hotplug_exit);MODULE_AUTHOR(DRIVER_AUTHOR);MODULE_DESCRIPTION(DRIVER_DESC);MODULE_LICENSE("GPL");module_param(debug, bool, 0644);MODULE_PARM_DESC(debug, "Debugging mode enabled or not");EXPORT_SYMBOL_GPL(pci_hotplug_slots_subsys);EXPORT_SYMBOL_GPL(pci_hp_register);EXPORT_SYMBOL_GPL(pci_hp_deregister);EXPORT_SYMBOL_GPL(pci_hp_change_slot_info);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -