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

📄 shpchp_ctrl.c

📁 h内核
💻 C
📖 第 1 页 / 共 5 页
字号:
	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;	struct pci_func *func;	if (!p_slot->ctrl)		return 1;	pci_bus = p_slot->ctrl->pci_dev->subordinate;	/* 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 = shpchp_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 = shpchp_slot_find(p_slot->bus, p_slot->device, index++);	}	func = shpchp_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 = shpchp_slot_find(new_slot->bus, new_slot->device, index++);				if (new_slot)					shpchp_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 = shpchp_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 configure_new_device\n");	return 0;}/* * Configuration logic that involves the hotplug data structures and  * their bookkeeping *//** * configure_new_function - Configures the PCI header information of one device * * @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 * * Calls itself recursively for bridged devices. * Returns 0 if success * */static int configure_new_function (struct controller * ctrl, struct pci_func * func,	u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev){	int cloop;	u8 temp_byte;	u8 device;	u8 class_code;	u16 temp_word;	u32 rc;	u32 temp_register;	u32 base;	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 pci_bus lpci_bus, *pci_bus;	struct resource_lists temp_resources;#if defined(CONFIG_X86_64)	u8 IRQ=0;#endif	memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));	pci_bus = &lpci_bus;	pci_bus->number = func->bus;	devfn = PCI_DEVFN(func->device, func->function);	/* Check for Bridge */	rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &temp_byte);	if (rc)		return rc;	if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { /* PCI-PCI Bridge */		/* set Primary bus */		dbg("set Primary bus = 0x%x\n", func->bus);		rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_PRIMARY_BUS, func->bus);		if (rc)			return rc;		/* find range of busses to use */		bus_node = get_max_resource(&resources->bus_head, 1L);		/* If we don't have any busses to allocate, we can't continue */		if (!bus_node) {			err("Got NO bus resource to use\n");			return -ENOMEM;		}		dbg("Got ranges of buses to use: base:len=0x%x:%x\n", bus_node->base, bus_node->length);		/* set Secondary bus */		temp_byte = (u8)bus_node->base;		dbg("set Secondary bus = 0x%x\n", temp_byte);		rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, temp_byte);		if (rc)			return rc;		/* set subordinate bus */		temp_byte = (u8)(bus_node->base + bus_node->length - 1);		dbg("set subordinate bus = 0x%x\n", temp_byte);		rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);		if (rc)			return rc;		/* Set HP parameters (Cache Line Size, Latency Timer) */		rc = shpchprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_BRIDGE);		if (rc)			return rc;		/* Setup the IO, memory, and prefetchable windows */		io_node = get_max_resource(&(resources->io_head), 0x1000L);		if (io_node) {			dbg("io_node(base, len, next) (%x, %x, %p)\n", io_node->base, io_node->length, io_node->next);		}		mem_node = get_max_resource(&(resources->mem_head), 0x100000L);		if (mem_node) {			dbg("mem_node(base, len, next) (%x, %x, %p)\n", mem_node->base, mem_node->length, mem_node->next);		}		if (resources->p_mem_head)			p_mem_node = get_max_resource(&(resources->p_mem_head), 0x100000L);		else {			/*			 * In some platform implementation, MEM and PMEM are not			 *  distinguished, and hence ACPI _CRS has only MEM entries			 *  for both MEM and PMEM.			 */			dbg("using MEM for PMEM\n");			p_mem_node = get_max_resource(&(resources->mem_head), 0x100000L);		}		if (p_mem_node) {			dbg("p_mem_node(base, len, next) (%x, %x, %p)\n", p_mem_node->base, p_mem_node->length, p_mem_node->next);		}		/* set up the IRQ info */		if (!resources->irqs) {			irqs.barber_pole = 0;			irqs.interrupt[0] = 0;			irqs.interrupt[1] = 0;			irqs.interrupt[2] = 0;			irqs.interrupt[3] = 0;			irqs.valid_INT = 0;		} else {			irqs.barber_pole = resources->irqs->barber_pole;			irqs.interrupt[0] = resources->irqs->interrupt[0];			irqs.interrupt[1] = resources->irqs->interrupt[1];			irqs.interrupt[2] = resources->irqs->interrupt[2];			irqs.interrupt[3] = resources->irqs->interrupt[3];			irqs.valid_INT = resources->irqs->valid_INT;		}		/* set up resource lists that are now aligned on top and bottom		 * for anything behind the bridge.		 */		temp_resources.bus_head = bus_node;		temp_resources.io_head = io_node;		temp_resources.mem_head = mem_node;		temp_resources.p_mem_head = p_mem_node;		temp_resources.irqs = &irqs;		/* Make copies of the nodes we are going to pass down so that		 * if there is a problem,we can just use these to free resources		 */		hold_bus_node = kmalloc(sizeof(*hold_bus_node), GFP_KERNEL);		hold_IO_node = kmalloc(sizeof(*hold_IO_node), GFP_KERNEL);		hold_mem_node = kmalloc(sizeof(*hold_mem_node), GFP_KERNEL);		hold_p_mem_node = kmalloc(sizeof(*hold_p_mem_node), GFP_KERNEL);		if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) {			kfree(hold_bus_node);			kfree(hold_IO_node);			kfree(hold_mem_node);			kfree(hold_p_mem_node);			return 1;		}		memcpy(hold_bus_node, bus_node, sizeof(struct pci_resource));		bus_node->base += 1;		bus_node->length -= 1;		bus_node->next = NULL;		/* If we have IO resources copy them and fill in the bridge's		 * IO range registers		 */		if (io_node) {			memcpy(hold_IO_node, io_node, sizeof(struct pci_resource));			io_node->next = NULL;			/* set IO base and Limit registers */			RES_CHECK(io_node->base, 8);			temp_byte = (u8)(io_node->base >> 8);			rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_BASE, temp_byte);			RES_CHECK(io_node->base + io_node->length - 1, 8);			temp_byte = (u8)((io_node->base + io_node->length - 1) >> 8);			rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte);		} else {			kfree(hold_IO_node);			hold_IO_node = NULL;		}		/* If we have memory resources copy them and fill in the bridge's		 * memory range registers.  Otherwise, fill in the range		 * registers with values that disable them.		 */		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 = (u32)(mem_node->base >> 16);			rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_BASE, temp_word);			RES_CHECK(mem_node->base + mem_node->length - 1, 16);			temp_word = (u32)((mem_node->base + mem_node->length - 1) >> 16);			rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);		} else {			temp_word = 0xFFFF;			rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_BASE, temp_word);			temp_word = 0x0000;			rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);			kfree(hold_mem_node);			hold_mem_node = NULL;		}		/* If we have prefetchable memory resources copy them and 		 * fill in the bridge's memory range registers.  Otherwise,		 * fill in the range registers with values that disable them.		 */		if (p_mem_node) {			memcpy(hold_p_mem_node, p_mem_node, sizeof(struct pci_resource));			p_mem_node->next = NULL;			/* set Pre Mem base and Limit registers */			RES_CHECK(p_mem_node->base, 16);			temp_word = (u32)(p_mem_node->base >> 16);			rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);			RES_CHECK(p_mem_node->base + p_mem_node->length - 1, 16);			temp_word = (u32)((p_mem_node->base + p_mem_node->length - 1) >> 16);			rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);		} else {			temp_word = 0xFFFF;			rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);			temp_word = 0x0000;			rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);			kfree(hold_p_mem_node);			hold_p_mem_node = NULL;		}		/* Adjust this to compensate for extra adjustment in first loop */		irqs.barber_pole--;		rc = 0;		/* Here we actually find the devices and configure them */		for (device = 0; (device <= 0x1F) && !rc; device++) {			irqs.barber_pole = (irqs.barber_pole + 1) & 0x03;			ID = 0xFFFFFFFF;			pci_bus->number = hold_bus_node->base;			pci_bus_read_config_dword(pci_bus, PCI_DEVFN(device, 0),					PCI_VENDOR_ID, &ID);			pci_bus->number = func->bus;			if (ID != 0xFFFFFFFF) {	  /*  device Present */				/* Setup slot structure. */				new_slot = shpchp_slot_create(hold_bus_node->base);				if (new_slot == NULL) {					/* Out of memory */					rc = -ENOMEM;					continue;				}				new_slot->bus = hold_bus_node->base;				new_slot->device = device;				new_slot->function = 0;				new_slot->is_a_board = 1;				new_slot->status = 0;				rc = configure_new_device(ctrl, new_slot, 1, &temp_resources, func->bus, func->device);				dbg("configure_new_device rc=0x%x\n",rc);			}	/* End of IF (device in slot?) */		}		/* End of FOR loop */		if (rc) {			shpchp_destroy_resource_list(&temp_resources);			return_resource(&(resources->bus_head), hold_bus_node);			return_resource(&(resources->io_head), hold_IO_node);			return_resource(&(resources->mem_head), hold_mem_node);			return_resource(&(resources->p_mem_head), hold_p_mem_node);			return(rc);		}		/* save the interrupt routing information */		if (resources->irqs) {			resources->irqs->interrupt[0] = irqs.interrupt[0];			resources->irqs->interrupt[1] = irqs.interrupt[1];			resources->irqs->interrupt[2] = irqs.interrupt[2];			resources->irqs->interrupt[3] = irqs.interrupt[3];			resources->irqs->valid_INT = irqs.valid_INT;		} else if (!behind_bridge) {			/* We need to hook up the interrupts here */			for (cloop = 0; cloop < 4; cloop++) {				if (i

⌨️ 快捷键说明

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