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

📄 pci.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 3 页
字号:
			printk(KERN_WARNING "Running out of resources"			       " for /ht host !\n");			hose->mem_resources[cur].end = res->start - 1;			continue;		}		cur++;		DBG("U3/HT: hole, %d end at %08lx, %d start at %08lx\n",		    cur-1, res->start - 1, cur, res->end + 1);		hose->mem_resources[cur].name = np->full_name;		hose->mem_resources[cur].flags = IORESOURCE_MEM;		hose->mem_resources[cur].start = res->end + 1;		hose->mem_resources[cur].end = hose->mem_resources[cur-1].end;		hose->mem_resources[cur-1].end = res->start - 1;	}}#endif /* CONFIG_PPC64 *//* * We assume that if we have a G3 powermac, we have one bridge called * "pci" (a MPC106) and no bandit or chaos bridges, and contrariwise, * if we have one or more bandit or chaos bridges, we don't have a MPC106. */static int __init pmac_add_bridge(struct device_node *dev){	int len;	struct pci_controller *hose;	struct resource rsrc;	char *disp_name;	const int *bus_range;	int primary = 1, has_address = 0;	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 = of_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);	}	hose = pcibios_alloc_controller(dev);	if (!hose)		return -ENOMEM;	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 (of_device_is_compatible(dev, "u3-agp")) {		setup_u3_agp(hose);		disp_name = "U3-AGP";		primary = 0;	} else if (of_device_is_compatible(dev, "u3-ht")) {		setup_u3_ht(hose);		disp_name = "U3-HT";		primary = 1;	} else if (of_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 (of_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%016llx. "	       "Firmware bus number: %d->%d\n",		disp_name, (unsigned long long)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;}void __devinit pmac_pci_irq_fixup(struct pci_dev *dev){#ifdef CONFIG_PPC32	/* Fixup interrupt for the modem/ethernet combo controller.	 * on machines with a second ohare chip.	 * The number in the device tree (27) is bogus (correct for	 * the ethernet-only board but not the combo ethernet/modem	 * board). The real interrupt is 28 on the second controller	 * -> 28+32 = 60.	 */	if (has_second_ohare &&	    dev->vendor == PCI_VENDOR_ID_DEC &&	    dev->device == PCI_DEVICE_ID_DEC_TULIP_PLUS) {		dev->irq = irq_create_mapping(NULL, 60);		set_irq_type(dev->irq, IRQ_TYPE_LEVEL_LOW);	}#endif /* CONFIG_PPC32 */}void __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 (pmac_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 && pmac_add_bridge(ht) != 0)		of_node_put(ht);	/* 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;#else /* CONFIG_PPC64 */	init_p2pbridge();	init_second_ohare();	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 &&		of_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") &&	    (of_device_is_compatible(node, "pci106b,18") ||	     of_device_is_compatible(node, "pci106b,30") ||	     of_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") &&	    of_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)			continue;		if (pci_enable_device(dev))			printk(KERN_WARNING			       "pci: Failed to enable %s\n", pci_name(dev));	}#endif /* CONFIG_BLK_DEV_IDE */	for_each_node_by_name(nd, "firewire") {		if (nd->parent && (of_device_is_compatible(nd, "pci106b,18") ||				   of_device_is_compatible(nd, "pci106b,30") ||				   of_device_is_compatible(nd, "pci11c1,5811"))		    && of_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);		}	}	of_node_put(nd);	for_each_node_by_name(nd, "ethernet") {		if (nd->parent && of_device_is_compatible(nd, "gmac")		    && of_device_is_compatible(nd->parent, "uni-north"))			pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0);	}	of_node_put(nd);}#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 "PCI: %s Forcing PCI IDE into native mode\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");		else {			/* Clear IO BARs, they will be reassigned */			pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0);			pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, 0);			pci_write_config_dword(dev, PCI_BASE_ADDRESS_2, 0);			pci_write_config_dword(dev, PCI_BASE_ADDRESS_3, 0);		}	}}DECLARE_PCI_FIXUP_EARLY(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 + -