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

📄 bios32.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
void pcibios_fixup_bus(struct pci_bus *bus){	struct pci_sys_data *root = bus->sysdata;	struct pci_dev *dev;	u16 features = PCI_COMMAND_SERR | PCI_COMMAND_PARITY | PCI_COMMAND_FAST_BACK;	pbus_assign_bus_resources(bus, root);	/*	 * Walk the devices on this bus, working out what we can	 * and can't support.	 */	list_for_each_entry(dev, &bus->devices, bus_list) {		u16 status;		pdev_fixup_device_resources(root, dev);		pci_read_config_word(dev, PCI_STATUS, &status);		/*		 * If any device on this bus does not support fast back		 * to back transfers, then the bus as a whole is not able		 * to support them.  Having fast back to back transfers		 * on saves us one PCI cycle per transaction.		 */		if (!(status & PCI_STATUS_FAST_BACK))			features &= ~PCI_COMMAND_FAST_BACK;		if (pdev_bad_for_parity(dev))			features &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);		switch (dev->class >> 8) {		case PCI_CLASS_BRIDGE_PCI:			pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &status);			status |= PCI_BRIDGE_CTL_PARITY|PCI_BRIDGE_CTL_MASTER_ABORT;			status &= ~(PCI_BRIDGE_CTL_BUS_RESET|PCI_BRIDGE_CTL_FAST_BACK);			pci_write_config_word(dev, PCI_BRIDGE_CONTROL, status);			break;		case PCI_CLASS_BRIDGE_CARDBUS:			pci_read_config_word(dev, PCI_CB_BRIDGE_CONTROL, &status);			status |= PCI_CB_BRIDGE_CTL_PARITY|PCI_CB_BRIDGE_CTL_MASTER_ABORT;			pci_write_config_word(dev, PCI_CB_BRIDGE_CONTROL, status);			break;		}	}	/*	 * Now walk the devices again, this time setting them up.	 */	list_for_each_entry(dev, &bus->devices, bus_list) {		u16 cmd;		pci_read_config_word(dev, PCI_COMMAND, &cmd);		cmd |= features;		pci_write_config_word(dev, PCI_COMMAND, cmd);		pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,				      L1_CACHE_BYTES >> 2);	}	/*	 * Propagate the flags to the PCI bridge.	 */	if (bus->self && bus->self->hdr_type == PCI_HEADER_TYPE_BRIDGE) {		if (features & PCI_COMMAND_FAST_BACK)			bus->bridge_ctl |= PCI_BRIDGE_CTL_FAST_BACK;		if (features & PCI_COMMAND_PARITY)			bus->bridge_ctl |= PCI_BRIDGE_CTL_PARITY;	}	/*	 * Report what we did for this bus	 */	printk(KERN_INFO "PCI: bus%d: Fast back to back transfers %sabled\n",		bus->number, (features & PCI_COMMAND_FAST_BACK) ? "en" : "dis");}/* * Convert from Linux-centric to bus-centric addresses for bridge devices. */voidpcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,			 struct resource *res){	struct pci_sys_data *root = dev->sysdata;	unsigned long offset = 0;	if (res->flags & IORESOURCE_IO)		offset = root->io_offset;	if (res->flags & IORESOURCE_MEM)		offset = root->mem_offset;	region->start = res->start - offset;	region->end   = res->end - offset;}void __devinitpcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,			struct pci_bus_region *region){	struct pci_sys_data *root = dev->sysdata;	unsigned long offset = 0;	if (res->flags & IORESOURCE_IO)		offset = root->io_offset;	if (res->flags & IORESOURCE_MEM)		offset = root->mem_offset;	res->start = region->start + offset;	res->end   = region->end + offset;}#ifdef CONFIG_HOTPLUGEXPORT_SYMBOL(pcibios_fixup_bus);EXPORT_SYMBOL(pcibios_resource_to_bus);EXPORT_SYMBOL(pcibios_bus_to_resource);#endif/* * This is the standard PCI-PCI bridge swizzling algorithm: * *   Dev: 0  1  2  3 *    A   A  B  C  D *    B   B  C  D  A *    C   C  D  A  B *    D   D  A  B  C *        ^^^^^^^^^^ irq pin on bridge */u8 __devinit pci_std_swizzle(struct pci_dev *dev, u8 *pinp){	int pin = *pinp - 1;	while (dev->bus->self) {		pin = (pin + PCI_SLOT(dev->devfn)) & 3;		/*		 * move up the chain of bridges,		 * swizzling as we go.		 */		dev = dev->bus->self;	}	*pinp = pin + 1;	return PCI_SLOT(dev->devfn);}/* * Swizzle the device pin each time we cross a bridge. * This might update pin and returns the slot number. */static u8 __devinit pcibios_swizzle(struct pci_dev *dev, u8 *pin){	struct pci_sys_data *sys = dev->sysdata;	int slot = 0, oldpin = *pin;	if (sys->swizzle)		slot = sys->swizzle(dev, pin);	if (debug_pci)		printk("PCI: %s swizzling pin %d => pin %d slot %d\n",			pci_name(dev), oldpin, *pin, slot);	return slot;}/* * Map a slot/pin to an IRQ. */static int pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin){	struct pci_sys_data *sys = dev->sysdata;	int irq = -1;	if (sys->map_irq)		irq = sys->map_irq(dev, slot, pin);	if (debug_pci)		printk("PCI: %s mapping slot %d pin %d => irq %d\n",			pci_name(dev), slot, pin, irq);	return irq;}static void __init pcibios_init_hw(struct hw_pci *hw){	struct pci_sys_data *sys = NULL;	int ret;	int nr, busnr;	for (nr = busnr = 0; nr < hw->nr_controllers; nr++) {		sys = kzalloc(sizeof(struct pci_sys_data), GFP_KERNEL);		if (!sys)			panic("PCI: unable to allocate sys data!");		sys->hw      = hw;		sys->busnr   = busnr;		sys->swizzle = hw->swizzle;		sys->map_irq = hw->map_irq;		sys->resource[0] = &ioport_resource;		sys->resource[1] = &iomem_resource;		ret = hw->setup(nr, sys);		if (ret > 0) {			sys->bus = hw->scan(nr, sys);			if (!sys->bus)				panic("PCI: unable to scan bus!");			busnr = sys->bus->subordinate + 1;			list_add(&sys->node, &hw->buses);		} else {			kfree(sys);			if (ret < 0)				break;		}	}}void __init pci_common_init(struct hw_pci *hw){	struct pci_sys_data *sys;	INIT_LIST_HEAD(&hw->buses);	if (hw->preinit)		hw->preinit();	pcibios_init_hw(hw);	if (hw->postinit)		hw->postinit();	pci_fixup_irqs(pcibios_swizzle, pcibios_map_irq);	list_for_each_entry(sys, &hw->buses, node) {		struct pci_bus *bus = sys->bus;		if (!use_firmware) {			/*			 * Size the bridge windows.			 */			pci_bus_size_bridges(bus);			/*			 * Assign resources.			 */			pci_bus_assign_resources(bus);		}		/*		 * Tell drivers about devices found.		 */		pci_bus_add_devices(bus);	}}char * __init pcibios_setup(char *str){	if (!strcmp(str, "debug")) {		debug_pci = 1;		return NULL;	} else if (!strcmp(str, "firmware")) {		use_firmware = 1;		return NULL;	}	return str;}/* * From arch/i386/kernel/pci-i386.c: * * We need to avoid collisions with `mirrored' VGA ports * and other strange ISA hardware, so we always want the * addresses to be allocated in the 0x000-0x0ff region * modulo 0x400. * * Why? Because some silly external IO cards only decode * the low 10 bits of the IO address. The 0x00-0xff region * is reserved for motherboard devices that decode all 16 * bits, so it's ok to allocate at, say, 0x2800-0x28ff, * but we want to try to avoid allocating at 0x2900-0x2bff * which might be mirrored at 0x0100-0x03ff.. */void pcibios_align_resource(void *data, struct resource *res,			    resource_size_t size, resource_size_t align){	resource_size_t start = res->start;	if (res->flags & IORESOURCE_IO && start & 0x300)		start = (start + 0x3ff) & ~0x3ff;	res->start = (start + align - 1) & ~(align - 1);}/** * pcibios_enable_device - Enable I/O and memory. * @dev: PCI device to be enabled */int pcibios_enable_device(struct pci_dev *dev, int mask){	u16 cmd, old_cmd;	int idx;	struct resource *r;	pci_read_config_word(dev, PCI_COMMAND, &cmd);	old_cmd = cmd;	for (idx = 0; idx < 6; idx++) {		/* Only set up the requested stuff */		if (!(mask & (1 << idx)))			continue;		r = dev->resource + idx;		if (!r->start && r->end) {			printk(KERN_ERR "PCI: Device %s not available because"			       " of resource collisions\n", pci_name(dev));			return -EINVAL;		}		if (r->flags & IORESOURCE_IO)			cmd |= PCI_COMMAND_IO;		if (r->flags & IORESOURCE_MEM)			cmd |= PCI_COMMAND_MEMORY;	}	/*	 * Bridges (eg, cardbus bridges) need to be fully enabled	 */	if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)		cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY;	if (cmd != old_cmd) {		printk("PCI: enabling device %s (%04x -> %04x)\n",		       pci_name(dev), old_cmd, cmd);		pci_write_config_word(dev, PCI_COMMAND, cmd);	}	return 0;}int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,			enum pci_mmap_state mmap_state, int write_combine){	struct pci_sys_data *root = dev->sysdata;	unsigned long phys;	if (mmap_state == pci_mmap_io) {		return -EINVAL;	} else {		phys = vma->vm_pgoff + (root->mem_offset >> PAGE_SHIFT);	}	/*	 * Mark this as IO	 */	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);	if (remap_pfn_range(vma, vma->vm_start, phys,			     vma->vm_end - vma->vm_start,			     vma->vm_page_prot))		return -EAGAIN;	return 0;}

⌨️ 快捷键说明

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