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

📄 pciehp_ctrl.c

📁 底层驱动开发
💻 C
📖 第 1 页 / 共 5 页
字号:
		return 0;	} else		return 2;}/** * pciehp_slot_find - Looks for a node by bus, and device, multiple functions accessed * @bus: bus to find * @device: device to find * @index: is 0 for first function found, 1 for the second... * * Returns pointer to the node if successful, %NULL otherwise. */struct pci_func *pciehp_slot_find(u8 bus, u8 device, u8 index){	int found = -1;	struct pci_func *func;	func = pciehp_slot_list[bus];	dbg("%s: bus %x device %x index %x\n",		__FUNCTION__, bus, device, index);	if (func != NULL) {		dbg("%s: func-> bus %x device %x function %x pci_dev %p\n",			__FUNCTION__, func->bus, func->device, func->function,			func->pci_dev);	} else		dbg("%s: func == NULL\n", __FUNCTION__);	if ((func == NULL) || ((func->device == device) && (index == 0)))		return func;	if (func->device == device)		found++;	while (func->next != NULL) {		func = func->next;		dbg("%s: In while loop, func-> bus %x device %x function %x pci_dev %p\n",			__FUNCTION__, func->bus, func->device, func->function,			func->pci_dev);		if (func->device == device)			found++;		dbg("%s: while loop, found %d, index %d\n", __FUNCTION__,			found, index);		if ((found == index) || (func->function == index)) {			dbg("%s: Found bus %x dev %x func %x\n", __FUNCTION__,					func->bus, func->device, func->function);			return func;		}	}	return NULL;}static int is_bridge(struct pci_func * func){	/* Check the header type */	if (((func->config_space[0x03] >> 16) & 0xFF) == 0x01)		return 1;	else		return 0;}/* The following routines constitute the bulk of the    hotplug controller logic */static void set_slot_off(struct controller *ctrl, struct slot * pslot){	/* Wait for exclusive access to hardware */	down(&ctrl->crit_sect);	/* turn off slot, turn on Amber LED, turn off Green LED if supported*/	if (POWER_CTRL(ctrl->ctrlcap)) {		if (pslot->hpc_ops->power_off_slot(pslot)) {   			err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);			up(&ctrl->crit_sect);			return;		}		wait_for_ctrl_irq (ctrl);	}	if (PWR_LED(ctrl->ctrlcap)) {		pslot->hpc_ops->green_led_off(pslot);   		wait_for_ctrl_irq (ctrl);	}	if (ATTN_LED(ctrl->ctrlcap)) { 		if (pslot->hpc_ops->set_attention_status(pslot, 1)) {   			err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);			up(&ctrl->crit_sect);			return;		}		wait_for_ctrl_irq (ctrl);	}	/* Done with exclusive hardware access */	up(&ctrl->crit_sect);}/** * board_added - Called after a board has been added to the system. * * Turns power on for the board * Configures board * */static u32 board_added(struct pci_func * func, struct controller * ctrl){	u8 hp_slot;	int index;	u32 temp_register = 0xFFFFFFFF;	u32 rc = 0;	struct pci_func *new_func = NULL;	struct slot *p_slot;	struct resource_lists res_lists;	p_slot = pciehp_find_slot(ctrl, func->device);	hp_slot = func->device - ctrl->slot_device_offset;	dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot);	/* Wait for exclusive access to hardware */	down(&ctrl->crit_sect);	if (POWER_CTRL(ctrl->ctrlcap)) {		/* Power on slot */		rc = p_slot->hpc_ops->power_on_slot(p_slot);		if (rc) {			up(&ctrl->crit_sect);			return -1;		}		/* Wait for the command to complete */		wait_for_ctrl_irq (ctrl);	}		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);	}	/* Done with exclusive hardware access */	up(&ctrl->crit_sect);	/* Wait for ~1 second */	dbg("%s: before long_delay\n", __FUNCTION__);	wait_for_ctrl_irq (ctrl);	dbg("%s: afterlong_delay\n", __FUNCTION__);	/*  Check link training status */	rc = p_slot->hpc_ops->check_lnk_status(ctrl);  	if (rc) {		err("%s: Failed to check link status\n", __FUNCTION__);		set_slot_off(ctrl, p_slot);		return rc;	}	dbg("%s: func status = %x\n", __FUNCTION__, func->status);	/* Check for a power fault */	if (func->status == 0xFF) {		/* power fault occurred, but it was benign */		temp_register = 0xFFFFFFFF;		dbg("%s: temp register set to %x by power fault\n", __FUNCTION__, temp_register);		rc = POWER_FAILURE;		func->status = 0;	} else {		/* Get vendor/device ID u32 */		rc = pci_bus_read_config_dword (ctrl->pci_dev->subordinate, PCI_DEVFN(func->device, func->function), 			PCI_VENDOR_ID, &temp_register);		dbg("%s: pci_bus_read_config_dword returns %d\n", __FUNCTION__, rc);		dbg("%s: temp_register is %x\n", __FUNCTION__, temp_register);		if (rc != 0) {			/* Something's wrong here */			temp_register = 0xFFFFFFFF;			dbg("%s: temp register set to %x by error\n", __FUNCTION__, temp_register);		}		/* Preset return code.  It will be changed later if things go okay. */		rc = NO_ADAPTER_PRESENT;	}	/* All F's is an empty slot or an invalid board */	if (temp_register != 0xFFFFFFFF) {	  /* Check for a board in the slot */		res_lists.io_head = ctrl->io_head;		res_lists.mem_head = ctrl->mem_head;		res_lists.p_mem_head = ctrl->p_mem_head;		res_lists.bus_head = ctrl->bus_head;		res_lists.irqs = NULL;		rc = configure_new_device(ctrl, func, 0, &res_lists, 0, 0);		dbg("%s: back from configure_new_device\n", __FUNCTION__);		ctrl->io_head = res_lists.io_head;		ctrl->mem_head = res_lists.mem_head;		ctrl->p_mem_head = res_lists.p_mem_head;		ctrl->bus_head = res_lists.bus_head;		pciehp_resource_sort_and_combine(&(ctrl->mem_head));		pciehp_resource_sort_and_combine(&(ctrl->p_mem_head));		pciehp_resource_sort_and_combine(&(ctrl->io_head));		pciehp_resource_sort_and_combine(&(ctrl->bus_head));		if (rc) {			set_slot_off(ctrl, p_slot);			return rc;		}		pciehp_save_slot_config(ctrl, func);		func->status = 0;		func->switch_save = 0x10;		func->is_a_board = 0x01;		/* next, we will instantiate the linux pci_dev structures 		 * (with appropriate driver notification, if already present) 		 */		index = 0;		do {			new_func = pciehp_slot_find(ctrl->slot_bus, func->device, index++);			if (new_func && !new_func->pci_dev) {				dbg("%s:call pci_hp_configure_dev, func %x\n", 					__FUNCTION__, index);				pciehp_configure_device(ctrl, new_func);			}		} while (new_func); 		/*  		 * Some PCI Express root ports require fixup after hot-plug operation. 		 */ 		if (pcie_mch_quirk) 			pci_fixup_device(pci_fixup_final, ctrl->pci_dev);   		if (PWR_LED(ctrl->ctrlcap)) {  			/* Wait for exclusive access to hardware */  			down(&ctrl->crit_sect);     			p_slot->hpc_ops->green_led_on(p_slot);    			/* Wait for the command to complete */  			wait_for_ctrl_irq (ctrl);  	  			/* Done with exclusive hardware access */  			up(&ctrl->crit_sect);  		}	} else {		set_slot_off(ctrl, p_slot);		return -1;	}	return 0;}/** * remove_board - Turns off slot and LED's * */static u32 remove_board(struct pci_func *func, struct controller *ctrl){	int index;	u8 skip = 0;	u8 device;	u8 hp_slot;	u32 rc;	struct resource_lists res_lists;	struct pci_func *temp_func;	struct slot *p_slot;	if (func == NULL)		return 1;	if (pciehp_unconfigure_device(func))		return 1;	device = func->device;	hp_slot = func->device - ctrl->slot_device_offset;	p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);	dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);	if ((ctrl->add_support) &&		!(func->bus_head || func->mem_head || func->p_mem_head || func->io_head)) {		/* Here we check to see if we've saved any of the board's		 * resources already.  If so, we'll skip the attempt to		 * determine what's being used.		 */		index = 0;		temp_func = func;		while ((temp_func = pciehp_slot_find(temp_func->bus, temp_func->device, index++))) {			if (temp_func->bus_head || temp_func->mem_head			    || temp_func->p_mem_head || temp_func->io_head) {				skip = 1;				break;			}		}		if (!skip)			rc = pciehp_save_used_resources(ctrl, func, DISABLE_CARD);	}	/* Change status to shutdown */	if (func->is_a_board)		func->status = 0x01;	func->configured = 0;	/* Wait for exclusive access to hardware */	down(&ctrl->crit_sect);	if (POWER_CTRL(ctrl->ctrlcap)) {		/* power off slot */		rc = p_slot->hpc_ops->power_off_slot(p_slot);		if (rc) {			err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);			up(&ctrl->crit_sect);			return rc;		}		/* Wait for the command to complete */		wait_for_ctrl_irq (ctrl);	}	if (PWR_LED(ctrl->ctrlcap)) {		/* turn off Green LED */		p_slot->hpc_ops->green_led_off(p_slot);			/* Wait for the command to complete */		wait_for_ctrl_irq (ctrl);	}	/* Done with exclusive hardware access */	up(&ctrl->crit_sect);	if (ctrl->add_support) {		while (func) {			res_lists.io_head = ctrl->io_head;			res_lists.mem_head = ctrl->mem_head;			res_lists.p_mem_head = ctrl->p_mem_head;			res_lists.bus_head = ctrl->bus_head;			dbg("Returning resources to ctlr lists for (B/D/F) = (%#x/%#x/%#x)\n", 				func->bus, func->device, func->function);			pciehp_return_board_resources(func, &res_lists);			ctrl->io_head = res_lists.io_head;			ctrl->mem_head = res_lists.mem_head;			ctrl->p_mem_head = res_lists.p_mem_head;			ctrl->bus_head = res_lists.bus_head;			pciehp_resource_sort_and_combine(&(ctrl->mem_head));			pciehp_resource_sort_and_combine(&(ctrl->p_mem_head));			pciehp_resource_sort_and_combine(&(ctrl->io_head));			pciehp_resource_sort_and_combine(&(ctrl->bus_head));			if (is_bridge(func)) {				dbg("PCI Bridge Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", 					ctrl->seg, func->bus, func->device, func->function);				bridge_slot_remove(func);			} else {				dbg("PCI Function Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", 					ctrl->seg, func->bus, func->device, func->function);				slot_remove(func);			}			func = pciehp_slot_find(ctrl->slot_bus, device, 0);		}		/* Setup slot structure with entry for empty slot */		func = pciehp_slot_create(ctrl->slot_bus);		if (func == NULL) {			return 1;		}		func->bus = ctrl->slot_bus;		func->device = device;		func->function = 0;		func->configured = 0;		func->switch_save = 0x10;		func->is_a_board = 0;	}	return 0;}static void pushbutton_helper_thread(unsigned long data){	pushbutton_pending = data;	up(&event_semaphore);}/** * pciehp_pushbutton_thread * * Scheduled procedure to handle blocking stuff for the pushbuttons * Handles all pending events and exits. * */static void pciehp_pushbutton_thread(unsigned long slot){	struct slot *p_slot = (struct slot *) slot;	u8 getstatus;		pushbutton_pending = 0;	if (!p_slot) {		dbg("%s: Error! slot NULL\n", __FUNCTION__);		return;	}	p_slot->hpc_ops->get_power_status(p_slot, &getstatus);	if (getstatus) {		p_slot->state = POWEROFF_STATE;		dbg("In power_down_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);		pciehp_disable_slot(p_slot);		p_slot->state = STATIC_STATE;	} else {		p_slot->state = POWERON_STATE;		dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);		if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {			/* Wait for exclusive access to hardware */			down(&p_slot->ctrl->crit_sect);			p_slot->hpc_ops->green_led_off(p_slot);			/* Wait for the command to complete */			wait_for_ctrl_irq (p_slot->ctrl);			/* Done with exclusive hardware access */			up(&p_slot->ctrl->crit_sect);		}		p_slot->state = STATIC_STATE;	}	return;}/** * pciehp_surprise_rm_thread * * Scheduled procedure to handle blocking stuff for the surprise removal * Handles all pending events and exits. * */static void pciehp_surprise_rm_thread(unsigned long slot){	struct slot *p_slot = (struct slot *) slot;	u8 getstatus;		surprise_rm_pending = 0;	if (!p_slot) {		dbg("%s: Error! slot NULL\n", __FUNCTION__);		return;	}	p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);	if (!getstatus) {		p_slot->state = POWEROFF_STATE;		dbg("In removing board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);		pciehp_disable_slot(p_slot);		p_slot->state = STATIC_STATE;	} else {		p_slot->state = POWERON_STATE;		dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);		if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {			/* Wait for exclusive access to hardware */			down(&p_slot->ctrl->crit_sect);			p_slot->hpc_ops->green_led_off(p_slot);			/* Wait for the command to complete */			wait_for_ctrl_irq (p_slot->ctrl);			/* Done with exclusive hardware access */			up(&p_slot->ctrl->crit_sect);		}		p_slot->state = STATIC_STATE;	}	return;}

⌨️ 快捷键说明

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