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

📄 pci.c

📁 LINUX 2.6.17.4的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	DBG("Adding PCI host bridge %s\n", dev->full_name);	/* Fetch host bridge registers address */	has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);	/* Get bus range if any */	bus_range = (int *) get_property(dev, "bus-range", &len);	if (bus_range == NULL || len < 2 * sizeof(int)) {		printk(KERN_WARNING "Can't get bus-range for %s, assume"		       " bus 0\n", dev->full_name);	}	/* XXX Different prototypes, to be merged */#ifdef CONFIG_PPC64	hose = pcibios_alloc_controller(dev);#else	hose = pcibios_alloc_controller();#endif	if (!hose)		return -ENOMEM;	hose->arch_data = dev;	hose->first_busno = bus_range ? bus_range[0] : 0;	hose->last_busno = bus_range ? bus_range[1] : 0xff;	disp_name = NULL;	/* 64 bits only bridges */#ifdef CONFIG_PPC64	if (device_is_compatible(dev, "u3-agp")) {		setup_u3_agp(hose);		disp_name = "U3-AGP";		primary = 0;	} else if (device_is_compatible(dev, "u3-ht")) {		setup_u3_ht(hose);		disp_name = "U3-HT";		primary = 1;	} else if (device_is_compatible(dev, "u4-pcie")) {		setup_u4_pcie(hose);		disp_name = "U4-PCIE";		primary = 0;	}	printk(KERN_INFO "Found %s PCI host bridge.  Firmware bus number:"	       " %d->%d\n", disp_name, hose->first_busno, hose->last_busno);#endif /* CONFIG_PPC64 */	/* 32 bits only bridges */#ifdef CONFIG_PPC32	if (device_is_compatible(dev, "uni-north")) {		primary = setup_uninorth(hose, &rsrc);		disp_name = "UniNorth";	} else if (strcmp(dev->name, "pci") == 0) {		/* XXX assume this is a mpc106 (grackle) */		setup_grackle(hose);		disp_name = "Grackle (MPC106)";	} else if (strcmp(dev->name, "bandit") == 0) {		setup_bandit(hose, &rsrc);		disp_name = "Bandit";	} else if (strcmp(dev->name, "chaos") == 0) {		setup_chaos(hose, &rsrc);		disp_name = "Chaos";		primary = 0;	}	printk(KERN_INFO "Found %s PCI host bridge at 0x%08lx. "	       "Firmware bus number: %d->%d\n",		disp_name, rsrc.start, hose->first_busno, hose->last_busno);#endif /* CONFIG_PPC32 */	DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",		hose, hose->cfg_addr, hose->cfg_data);	/* Interpret the "ranges" property */	/* This also maps the I/O region and sets isa_io/mem_base */	pci_process_bridge_OF_ranges(hose, dev, primary);	/* Fixup "bus-range" OF property */	fixup_bus_range(dev);	return 0;}static void __init pcibios_fixup_OF_interrupts(void){	struct pci_dev* dev = NULL;	/*	 * Open Firmware often doesn't initialize the	 * PCI_INTERRUPT_LINE config register properly, so we	 * should find the device node and apply the interrupt	 * obtained from the OF device-tree	 */	for_each_pci_dev(dev) {		struct device_node *node;		node = pci_device_to_OF_node(dev);		/* this is the node, see if it has interrupts */		if (node && node->n_intrs > 0)			dev->irq = node->intrs[0].line;		pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);	}}void __init pmac_pcibios_fixup(void){	/* Fixup interrupts according to OF tree */	pcibios_fixup_OF_interrupts();}#ifdef CONFIG_PPC64static void __init pmac_fixup_phb_resources(void){	struct pci_controller *hose, *tmp;	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {		printk(KERN_INFO "PCI Host %d, io start: %lx; io end: %lx\n",		       hose->global_number,		       hose->io_resource.start, hose->io_resource.end);	}}#endifvoid __init pmac_pci_init(void){	struct device_node *np, *root;	struct device_node *ht = NULL;	root = of_find_node_by_path("/");	if (root == NULL) {		printk(KERN_CRIT "pmac_pci_init: can't find root "		       "of device tree\n");		return;	}	for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) {		if (np->name == NULL)			continue;		if (strcmp(np->name, "bandit") == 0		    || strcmp(np->name, "chaos") == 0		    || strcmp(np->name, "pci") == 0) {			if (add_bridge(np) == 0)				of_node_get(np);		}		if (strcmp(np->name, "ht") == 0) {			of_node_get(np);			ht = np;		}	}	of_node_put(root);#ifdef CONFIG_PPC64	/* Probe HT last as it relies on the agp resources to be already	 * setup	 */	if (ht && add_bridge(ht) != 0)		of_node_put(ht);	/*	 * We need to call pci_setup_phb_io for the HT bridge first	 * so it gets the I/O port numbers starting at 0, and we	 * need to call it for the AGP bridge after that so it gets	 * small positive I/O port numbers.	 */	if (u3_ht)		pci_setup_phb_io(u3_ht, 1);	if (u3_agp)		pci_setup_phb_io(u3_agp, 0);	if (u4_pcie)		pci_setup_phb_io(u4_pcie, 0);	/*	 * On ppc64, fixup the IO resources on our host bridges as	 * the common code does it only for children of the host bridges	 */	pmac_fixup_phb_resources();	/* Setup the linkage between OF nodes and PHBs */	pci_devs_phb_init();	/* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We	 * assume there is no P2P bridge on the AGP bus, which should be a	 * safe assumptions for now. We should do something better in the	 * future though	 */	if (u3_agp) {		struct device_node *np = u3_agp->arch_data;		PCI_DN(np)->busno = 0xf0;		for (np = np->child; np; np = np->sibling)			PCI_DN(np)->busno = 0xf0;	}	/* pmac_check_ht_link(); */	/* Tell pci.c to not use the common resource allocation mechanism */	pci_probe_only = 1;	/* Allow all IO */	io_page_mask = -1;#else /* CONFIG_PPC64 */	init_p2pbridge();	fixup_nec_usb2();	/* We are still having some issues with the Xserve G4, enabling	 * some offset between bus number and domains for now when we	 * assign all busses should help for now	 */	if (pci_assign_all_buses)		pcibios_assign_bus_offset = 0x10;#endif}intpmac_pci_enable_device_hook(struct pci_dev *dev, int initial){	struct device_node* node;	int updatecfg = 0;	int uninorth_child;	node = pci_device_to_OF_node(dev);	/* We don't want to enable USB controllers absent from the OF tree	 * (iBook second controller)	 */	if (dev->vendor == PCI_VENDOR_ID_APPLE	    && dev->class == PCI_CLASS_SERIAL_USB_OHCI	    && !node) {		printk(KERN_INFO "Apple USB OHCI %s disabled by firmware\n",		       pci_name(dev));		return -EINVAL;	}	if (!node)		return 0;	uninorth_child = node->parent &&		device_is_compatible(node->parent, "uni-north");	/* Firewire & GMAC were disabled after PCI probe, the driver is	 * claiming them, we must re-enable them now.	 */	if (uninorth_child && !strcmp(node->name, "firewire") &&	    (device_is_compatible(node, "pci106b,18") ||	     device_is_compatible(node, "pci106b,30") ||	     device_is_compatible(node, "pci11c1,5811"))) {		pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, node, 0, 1);		pmac_call_feature(PMAC_FTR_1394_ENABLE, node, 0, 1);		updatecfg = 1;	}	if (uninorth_child && !strcmp(node->name, "ethernet") &&	    device_is_compatible(node, "gmac")) {		pmac_call_feature(PMAC_FTR_GMAC_ENABLE, node, 0, 1);		updatecfg = 1;	}	if (updatecfg) {		u16 cmd;		/*		 * Make sure PCI is correctly configured		 *		 * We use old pci_bios versions of the function since, by		 * default, gmac is not powered up, and so will be absent		 * from the kernel initial PCI lookup.		 *		 * Should be replaced by 2.4 new PCI mechanisms and really		 * register the device.		 */		pci_read_config_word(dev, PCI_COMMAND, &cmd);		cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER			| PCI_COMMAND_INVALIDATE;		pci_write_config_word(dev, PCI_COMMAND, cmd);		pci_write_config_byte(dev, PCI_LATENCY_TIMER, 16);		pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,				      L1_CACHE_BYTES >> 2);	}	return 0;}/* We power down some devices after they have been probed. They'll * be powered back on later on */void __init pmac_pcibios_after_init(void){	struct device_node* nd;#ifdef CONFIG_BLK_DEV_IDE	struct pci_dev *dev = NULL;	/* OF fails to initialize IDE controllers on macs	 * (and maybe other machines)	 *	 * Ideally, this should be moved to the IDE layer, but we need	 * to check specifically with Andre Hedrick how to do it cleanly	 * since the common IDE code seem to care about the fact that the	 * BIOS may have disabled a controller.	 *	 * -- BenH	 */	for_each_pci_dev(dev) {		if ((dev->class >> 16) == PCI_BASE_CLASS_STORAGE)			pci_enable_device(dev);	}#endif /* CONFIG_BLK_DEV_IDE */	nd = find_devices("firewire");	while (nd) {		if (nd->parent && (device_is_compatible(nd, "pci106b,18") ||				   device_is_compatible(nd, "pci106b,30") ||				   device_is_compatible(nd, "pci11c1,5811"))		    && device_is_compatible(nd->parent, "uni-north")) {			pmac_call_feature(PMAC_FTR_1394_ENABLE, nd, 0, 0);			pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, nd, 0, 0);		}		nd = nd->next;	}	nd = find_devices("ethernet");	while (nd) {		if (nd->parent && device_is_compatible(nd, "gmac")		    && device_is_compatible(nd->parent, "uni-north"))			pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0);		nd = nd->next;	}}#ifdef CONFIG_PPC32void pmac_pci_fixup_cardbus(struct pci_dev* dev){	if (!machine_is(powermac))		return;	/*	 * Fix the interrupt routing on the various cardbus bridges	 * used on powerbooks	 */	if (dev->vendor != PCI_VENDOR_ID_TI)		return;	if (dev->device == PCI_DEVICE_ID_TI_1130 ||	    dev->device == PCI_DEVICE_ID_TI_1131) {		u8 val;		/* Enable PCI interrupt */		if (pci_read_config_byte(dev, 0x91, &val) == 0)			pci_write_config_byte(dev, 0x91, val | 0x30);		/* Disable ISA interrupt mode */		if (pci_read_config_byte(dev, 0x92, &val) == 0)			pci_write_config_byte(dev, 0x92, val & ~0x06);	}	if (dev->device == PCI_DEVICE_ID_TI_1210 ||	    dev->device == PCI_DEVICE_ID_TI_1211 ||	    dev->device == PCI_DEVICE_ID_TI_1410 ||	    dev->device == PCI_DEVICE_ID_TI_1510) {		u8 val;		/* 0x8c == TI122X_IRQMUX, 2 says to route the INTA		   signal out the MFUNC0 pin */		if (pci_read_config_byte(dev, 0x8c, &val) == 0)			pci_write_config_byte(dev, 0x8c, (val & ~0x0f) | 2);		/* Disable ISA interrupt mode */		if (pci_read_config_byte(dev, 0x92, &val) == 0)			pci_write_config_byte(dev, 0x92, val & ~0x06);	}}DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_ANY_ID, pmac_pci_fixup_cardbus);void pmac_pci_fixup_pciata(struct pci_dev* dev){       u8 progif = 0;       /*        * On PowerMacs, we try to switch any PCI ATA controller to	* fully native mode        */	if (!machine_is(powermac))		return;	/* Some controllers don't have the class IDE */	if (dev->vendor == PCI_VENDOR_ID_PROMISE)		switch(dev->device) {		case PCI_DEVICE_ID_PROMISE_20246:		case PCI_DEVICE_ID_PROMISE_20262:		case PCI_DEVICE_ID_PROMISE_20263:		case PCI_DEVICE_ID_PROMISE_20265:		case PCI_DEVICE_ID_PROMISE_20267:		case PCI_DEVICE_ID_PROMISE_20268:		case PCI_DEVICE_ID_PROMISE_20269:		case PCI_DEVICE_ID_PROMISE_20270:		case PCI_DEVICE_ID_PROMISE_20271:		case PCI_DEVICE_ID_PROMISE_20275:		case PCI_DEVICE_ID_PROMISE_20276:		case PCI_DEVICE_ID_PROMISE_20277:			goto good;		}	/* Others, check PCI class */	if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)		return; good:	pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);	if ((progif & 5) != 5) {		printk(KERN_INFO "Forcing PCI IDE into native mode: %s\n",		       pci_name(dev));		(void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);		if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||		    (progif & 5) != 5)			printk(KERN_ERR "Rewrite of PROGIF failed !\n");	}}DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pmac_pci_fixup_pciata);#endif/* * Disable second function on K2-SATA, it's broken * and disable IO BARs on first one */static void fixup_k2_sata(struct pci_dev* dev){	int i;	u16 cmd;	if (PCI_FUNC(dev->devfn) > 0) {		pci_read_config_word(dev, PCI_COMMAND, &cmd);		cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY);		pci_write_config_word(dev, PCI_COMMAND, cmd);		for (i = 0; i < 6; i++) {			dev->resource[i].start = dev->resource[i].end = 0;			dev->resource[i].flags = 0;			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,					       0);		}	} else {		pci_read_config_word(dev, PCI_COMMAND, &cmd);		cmd &= ~PCI_COMMAND_IO;		pci_write_config_word(dev, PCI_COMMAND, cmd);		for (i = 0; i < 5; i++) {			dev->resource[i].start = dev->resource[i].end = 0;			dev->resource[i].flags = 0;			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,					       0);		}	}}DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS, 0x0240, fixup_k2_sata);

⌨️ 快捷键说明

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