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

📄 pciehp_ctrl.c

📁 底层驱动开发
💻 C
📖 第 1 页 / 共 5 页
字号:
/* this is the main worker thread */static int event_thread(void* data){	struct controller *ctrl;	lock_kernel();	daemonize("pciehpd_event");	unlock_kernel();	while (1) {		dbg("!!!!event_thread sleeping\n");		down_interruptible (&event_semaphore);		dbg("event_thread woken finished = %d\n", event_finished);		if (event_finished || signal_pending(current))			break;		/* Do stuff here */		if (pushbutton_pending)			pciehp_pushbutton_thread(pushbutton_pending);		else if (surprise_rm_pending)			pciehp_surprise_rm_thread(surprise_rm_pending);		else			for (ctrl = pciehp_ctrl_list; ctrl; ctrl=ctrl->next)				interrupt_event_handler(ctrl);	}	dbg("event_thread signals exit\n");	up(&event_exit);	return 0;}int pciehp_event_start_thread(void){	int pid;	/* initialize our semaphores */	init_MUTEX_LOCKED(&event_exit);	event_finished=0;	init_MUTEX_LOCKED(&event_semaphore);	pid = kernel_thread(event_thread, NULL, 0);	if (pid < 0) {		err ("Can't start up our event thread\n");		return -1;	}	dbg("Our event thread pid = %d\n", pid);	return 0;}void pciehp_event_stop_thread(void){	event_finished = 1;	dbg("event_thread finish command given\n");	up(&event_semaphore);	dbg("wait for event_thread to exit\n");	down(&event_exit);}static int update_slot_info(struct slot *slot){	struct hotplug_slot_info *info;	/* char buffer[SLOT_NAME_SIZE]; */	int result;	info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);	if (!info)		return -ENOMEM;	/* make_slot_name (&buffer[0], SLOT_NAME_SIZE, slot); */	slot->hpc_ops->get_power_status(slot, &(info->power_status));	slot->hpc_ops->get_attention_status(slot, &(info->attention_status));	slot->hpc_ops->get_latch_status(slot, &(info->latch_status));	slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));	/* result = pci_hp_change_slot_info(buffer, info); */	result = pci_hp_change_slot_info(slot->hotplug_slot, info);	kfree (info);	return result;}static void interrupt_event_handler(struct controller *ctrl){	int loop = 0;	int change = 1;	struct pci_func *func;	u8 hp_slot;	u8 getstatus;	struct slot *p_slot;	while (change) {		change = 0;		for (loop = 0; loop < 10; loop++) {			if (ctrl->event_queue[loop].event_type != 0) {				hp_slot = ctrl->event_queue[loop].hp_slot;				func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);				p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);				dbg("hp_slot %d, func %p, p_slot %p\n", hp_slot, func, p_slot);				if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {					dbg("button cancel\n");					del_timer(&p_slot->task_event);					switch (p_slot->state) {					case BLINKINGOFF_STATE:						/* Wait for exclusive access to hardware */						down(&ctrl->crit_sect);												if (PWR_LED(ctrl->ctrlcap)) {							p_slot->hpc_ops->green_led_on(p_slot);							/* Wait for the command to complete */							wait_for_ctrl_irq (ctrl);						}						if (ATTN_LED(ctrl->ctrlcap)) {							p_slot->hpc_ops->set_attention_status(p_slot, 0);							/* Wait for the command to complete */							wait_for_ctrl_irq (ctrl);						}						/* Done with exclusive hardware access */						up(&ctrl->crit_sect);						break;					case BLINKINGON_STATE:						/* Wait for exclusive access to hardware */						down(&ctrl->crit_sect);						if (PWR_LED(ctrl->ctrlcap)) {							p_slot->hpc_ops->green_led_off(p_slot);							/* Wait for the command to complete */							wait_for_ctrl_irq (ctrl);						}						if (ATTN_LED(ctrl->ctrlcap)){							p_slot->hpc_ops->set_attention_status(p_slot, 0);							/* Wait for the command to complete */							wait_for_ctrl_irq (ctrl);						}						/* Done with exclusive hardware access */						up(&ctrl->crit_sect);						break;					default:						warn("Not a valid state\n");						return;					}					info(msg_button_cancel, p_slot->number);					p_slot->state = STATIC_STATE;				}				/* ***********Button Pressed (No action on 1st press...) */				else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {										if (ATTN_BUTTN(ctrl->ctrlcap)) {						dbg("Button pressed\n");						p_slot->hpc_ops->get_power_status(p_slot, &getstatus);						if (getstatus) {							/* slot is on */							dbg("slot is on\n");							p_slot->state = BLINKINGOFF_STATE;							info(msg_button_off, p_slot->number);						} else {							/* slot is off */							dbg("slot is off\n");							p_slot->state = BLINKINGON_STATE;							info(msg_button_on, p_slot->number);						}						/* Wait for exclusive access to hardware */						down(&ctrl->crit_sect);						/* blink green LED and turn off amber */						if (PWR_LED(ctrl->ctrlcap)) {							p_slot->hpc_ops->green_led_blink(p_slot);							/* Wait for the command to complete */							wait_for_ctrl_irq (ctrl);						}						if (ATTN_LED(ctrl->ctrlcap)) {							p_slot->hpc_ops->set_attention_status(p_slot, 0);							/* Wait for the command to complete */							wait_for_ctrl_irq (ctrl);						}						/* Done with exclusive hardware access */						up(&ctrl->crit_sect);						init_timer(&p_slot->task_event);						p_slot->task_event.expires = jiffies + 5 * HZ;   /* 5 second delay */						p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;						p_slot->task_event.data = (unsigned long) p_slot;						dbg("add_timer p_slot = %p\n", (void *) p_slot);						add_timer(&p_slot->task_event);					}				}				/***********POWER FAULT********************/				else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {					if (POWER_CTRL(ctrl->ctrlcap)) {						dbg("power fault\n");						/* Wait for exclusive access to hardware */						down(&ctrl->crit_sect);						if (ATTN_LED(ctrl->ctrlcap)) {							p_slot->hpc_ops->set_attention_status(p_slot, 1);							wait_for_ctrl_irq (ctrl);						}						if (PWR_LED(ctrl->ctrlcap)) {							p_slot->hpc_ops->green_led_off(p_slot);							wait_for_ctrl_irq (ctrl);						}						/* Done with exclusive hardware access */						up(&ctrl->crit_sect);					}				}				/***********SURPRISE REMOVAL********************/				else if ((ctrl->event_queue[loop].event_type == INT_PRESENCE_ON) || 					(ctrl->event_queue[loop].event_type == INT_PRESENCE_OFF)) {					if (HP_SUPR_RM(ctrl->ctrlcap)) {						dbg("Surprise Removal\n");						if (p_slot) {							surprise_rm_pending = (unsigned long) p_slot;							up(&event_semaphore);							update_slot_info(p_slot);						}					}				} else {					/* refresh notification */					if (p_slot)						update_slot_info(p_slot);				}				ctrl->event_queue[loop].event_type = 0;				change = 1;			}		}		/* End of FOR loop */	}}int pciehp_enable_slot(struct slot *p_slot){	u8 getstatus = 0;	int rc;	struct pci_func *func;	func = pciehp_slot_find(p_slot->bus, p_slot->device, 0);	if (!func) {		dbg("%s: Error! slot NULL\n", __FUNCTION__);		return 1;	}	/* Check to see if (latch closed, card present, power off) */	down(&p_slot->ctrl->crit_sect);	rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);	if (rc || !getstatus) {		info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);		up(&p_slot->ctrl->crit_sect);		return 1;	}	if (MRL_SENS(p_slot->ctrl->ctrlcap)) {			rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);		if (rc || getstatus) {			info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);			up(&p_slot->ctrl->crit_sect);			return 1;		}	}		if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {			rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);		if (rc || getstatus) {			info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);			up(&p_slot->ctrl->crit_sect);			return 1;		}	}	up(&p_slot->ctrl->crit_sect);	slot_remove(func);	func = pciehp_slot_create(p_slot->bus);	if (func == NULL)		return 1;	func->bus = p_slot->bus;	func->device = p_slot->device;	func->function = 0;	func->configured = 0;	func->is_a_board = 1;	/* We have to save the presence info for these slots */	p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));	p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);	func->switch_save = !getstatus? 0x10:0;	rc = board_added(func, p_slot->ctrl);	if (rc) {		if (is_bridge(func))			bridge_slot_remove(func);		else			slot_remove(func);		/* Setup slot structure with entry for empty slot */		func = pciehp_slot_create(p_slot->bus);		if (func == NULL)			return 1;	/* Out of memory */		func->bus = p_slot->bus;		func->device = p_slot->device;		func->function = 0;		func->configured = 0;		func->is_a_board = 1;		/* We have to save the presence info for these slots */		p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));		p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);		func->switch_save = !getstatus? 0x10:0;	}	if (p_slot)		update_slot_info(p_slot);	return rc;}int pciehp_disable_slot(struct slot *p_slot){	u8 class_code, header_type, BCR;	u8 index = 0;	u8 getstatus = 0;	u32 rc = 0;	int ret = 0;	unsigned int devfn;	struct pci_bus *pci_bus = p_slot->ctrl->pci_dev->subordinate;	struct pci_func *func;	if (!p_slot->ctrl)		return 1;	/* Check to see if (latch closed, card present, power on) */	down(&p_slot->ctrl->crit_sect);	if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) {			ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);		if (ret || !getstatus) {			info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);			up(&p_slot->ctrl->crit_sect);			return 1;		}	}	if (MRL_SENS(p_slot->ctrl->ctrlcap)) {			ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);		if (ret || getstatus) {			info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);			up(&p_slot->ctrl->crit_sect);			return 1;		}	}	if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {			ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);		if (ret || !getstatus) {			info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);			up(&p_slot->ctrl->crit_sect);			return 1;		}	}	up(&p_slot->ctrl->crit_sect);	func = pciehp_slot_find(p_slot->bus, p_slot->device, index++);	/* Make sure there are no video controllers here	 * for all func of p_slot	 */	while (func && !rc) {		pci_bus->number = func->bus;		devfn = PCI_DEVFN(func->device, func->function);		/* Check the Class Code */		rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);		if (rc)			return rc;		if (class_code == PCI_BASE_CLASS_DISPLAY) {			/* Display/Video adapter (not supported) */			rc = REMOVE_NOT_SUPPORTED;		} else {			/* See if it's a bridge */			rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &header_type);			if (rc)				return rc;			/* If it's a bridge, check the VGA Enable bit */			if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {				rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_BRIDGE_CONTROL, &BCR);				if (rc)					return rc;				/* If the VGA Enable bit is set, remove isn't supported */				if (BCR & PCI_BRIDGE_CTL_VGA) {					rc = REMOVE_NOT_SUPPORTED;				}			}		}		func = pciehp_slot_find(p_slot->bus, p_slot->device, index++);	}	func = pciehp_slot_find(p_slot->bus, p_slot->device, 0);	if ((func != NULL) && !rc) {		rc = remove_board(func, p_slot->ctrl);	} else if (!rc)		rc = 1;	if (p_slot)		update_slot_info(p_slot);	return rc;}/** * configure_new_device - Configures the PCI header information of one board. * * @ctrl: pointer to controller structure * @func: pointer to function structure * @behind_bridge: 1 if this is a recursive call, 0 if not * @resources: pointer to set of resource lists * * Returns 0 if success * */static u32 configure_new_device(struct controller * ctrl, struct pci_func * func,	u8 behind_bridge, struct resource_lists * resources, u8 bridge_bus, u8 bridge_dev){	u8 temp_byte, function, max_functions, stop_it;	int rc;	u32 ID;	struct pci_func *new_slot;	struct pci_bus lpci_bus, *pci_bus;	int index;	new_slot = func;	dbg("%s\n", __FUNCTION__);	memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));	pci_bus = &lpci_bus;	pci_bus->number = func->bus;	/* Check for Multi-function device */	rc = pci_bus_read_config_byte(pci_bus, PCI_DEVFN(func->device, func->function), 0x0E, &temp_byte);	if (rc) {		dbg("%s: rc = %d\n", __FUNCTION__, rc);		return rc;	}	if (temp_byte & 0x80)	/* Multi-function device */		max_functions = 8;	else		max_functions = 1;	function = 0;	do {		rc = configure_new_function(ctrl, new_slot, behind_bridge,					resources, bridge_bus, bridge_dev);		if (rc) {			dbg("configure_new_function failed: %d\n", rc);			index = 0;			while (new_slot) {				new_slot = pciehp_slot_find(new_slot->bus,						new_slot->device, index++);				if (new_slot)					pciehp_return_board_resources(new_slot,						resources);			}			return rc;		}		function++;

⌨️ 快捷键说明

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