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

📄 pciehp_ctrl.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 5 页
字号:
	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);						p_slot->hpc_ops->green_led_on(p_slot);						/* Wait for the command to complete */						wait_for_ctrl_irq (ctrl);						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);						p_slot->hpc_ops->green_led_off(p_slot);						/* Wait for the command to complete */						wait_for_ctrl_irq (ctrl);						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) {					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 */					p_slot->hpc_ops->green_led_blink(p_slot);					/* Wait for the command to complete */					wait_for_ctrl_irq (ctrl);										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) {					dbg("power fault\n");					/* Wait for exclusive access to hardware */					down(&ctrl->crit_sect);					p_slot->hpc_ops->set_attention_status(p_slot, 1);					wait_for_ctrl_irq (ctrl);											p_slot->hpc_ops->green_led_off(p_slot);					wait_for_ctrl_irq (ctrl);					/* Done with exclusive hardware access */					up(&ctrl->crit_sect);				} 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;	}		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;	}		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);	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;	}	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;	}	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++;		stop_it = 0;		/*  The following loop skips to the next present function		 *  and creates a board structure		 */		while ((function < max_functions) && (!stop_it)) {			pci_bus_read_config_dword(pci_bus, PCI_DEVFN(func->device, function), 0x00, &ID);			if (ID == 0xFFFFFFFF) {	  /* There's nothing there. */				function++;			} else {  /* There's something there */				/* Setup slot structure. */				new_slot = pciehp_slot_create(func->bus);				if (new_slot == NULL) {					/* Out of memory */					return 1;				}				new_slot->bus = func->bus;				new_slot->device = func->device;				new_slot->function = function;				new_slot->is_a_board = 1;				new_slot->status = 0;				stop_it++;			}		}	} while (function < max_functions);	dbg("returning from %s\n", __FUNCTION__);	return 0;}/* * Configuration logic that involves the hotplug data structures and  * their bookkeeping *//** * configure_bridge: fill bridge's registers, either configure or disable it. */static intconfigure_bridge(struct pci_bus *pci_bus, unsigned int devfn,			struct pci_resource *mem_node,			struct pci_resource **hold_mem_node,			int base_addr, int limit_addr){	u16 temp_word;	u32 rc;	if (mem_node) {		memcpy(*hold_mem_node, mem_node, sizeof(struct pci_resource));		mem_node->next = NULL;		/* set Mem base and Limit registers */		RES_CHECK(mem_node->base, 16);		temp_word = (u16)(mem_node->base >> 16);		rc = pci_bus_write_config_word(pci_bus, devfn, base_addr, temp_word);		RES_CHECK(mem_node->base + mem_node->length - 1, 16);		temp_word = (u16)((mem_node->base + mem_node->length - 1) >> 16);		rc = pci_bus_write_config_word(pci_bus, devfn, limit_addr, temp_word);	} else {		temp_word = 0xFFFF;		rc = pci_bus_write_config_word(pci_bus, devfn, base_addr, temp_word);		temp_word = 0x0000;		rc = pci_bus_write_config_word(pci_bus, devfn, limit_addr, temp_word);		kfree(*hold_mem_node);		*hold_mem_node = NULL;	}	return rc;}static intconfigure_new_bridge(struct controller *ctrl, struct pci_func *func,		u8 behind_bridge, struct resource_lists *resources,		struct pci_bus *pci_bus){	int cloop;	u8 temp_byte;	u8 device;	u16 temp_word;	u32 rc;	u32 ID;	unsigned int devfn;	struct pci_resource *mem_node;	struct pci_resource *p_mem_node;	struct pci_resource *io_node;	struct pci_resource *bus_node;	struct pci_resource *hold_mem_node;	struct pci_resource *hold_p_mem_node;	struct pci_resource *hold_IO_node;	struct pci_resource *hold_bus_node;	struct irq_mapping irqs;	struct pci_func *new_slot;	struct resource_lists temp_resources;

⌨️ 快捷键说明

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