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

📄 pmac_pci.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
			continue;		/* We don't care about "fine" resources */		if (res->start >= 0xf0000000)			continue;		/* Check if it's just a matter of "shrinking" us in one direction */		if (hose->mem_resources[cur].start == res->start) {			DBG("U3/HT: shrink start of %d, %08lx -> %08lx\n",			    cur, hose->mem_resources[cur].start, res->end + 1);			hose->mem_resources[cur].start = res->end + 1;			continue;		}		if (hose->mem_resources[cur].end == res->end) {			DBG("U3/HT: shrink end of %d, %08lx -> %08lx\n",			    cur, hose->mem_resources[cur].end, res->start - 1);			hose->mem_resources[cur].end = res->start - 1;			continue;		}		/* No, it's not the case, we need a hole */		if (cur == 2) {			/* not enough resources to make a hole, we drop part of the range */			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_POWER4 */void __initsetup_grackle(struct pci_controller *hose){	setup_indirect_pci(hose, 0xfec00000, 0xfee00000);	if (machine_is_compatible("AAPL,PowerBook1998"))		grackle_set_loop_snoop(hose, 1);#if 0	/* Disabled for now, HW problems ??? */	grackle_set_stg(hose, 1);#endif}/* * 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 __initadd_bridge(struct device_node *dev){	int len;	struct pci_controller *hose;	struct reg_property *addr;	char* disp_name;	int *bus_range;	int primary = 1;	DBG("Adding PCI host bridge %s\n", dev->full_name);       	addr = (struct reg_property *) get_property(dev, "reg", &len);       	if (addr == NULL || len < sizeof(*addr)) {       		printk(KERN_WARNING "Can't use %s: no address\n",       		       dev->full_name);       		return -ENODEV;       	}       	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);       	}       	hose = pcibios_alloc_controller();       	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;#ifdef CONFIG_POWER4       	if (device_is_compatible(dev, "u3-agp")) {       		setup_u3_agp(hose, addr);       		disp_name = "U3-AGP";       		primary = 0;       	} else if (device_is_compatible(dev, "u3-ht")) {       		setup_u3_ht(hose, addr);       		disp_name = "U3-HT";       		primary = 1;       	} else#endif /* CONFIG_POWER4 */	if (device_is_compatible(dev, "uni-north")) {       		primary = setup_uninorth(hose, addr);       		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, addr);       		disp_name = "Bandit";       	} else if (strcmp(dev->name, "chaos") == 0) {       		setup_chaos(hose, addr);       		disp_name = "Chaos";       		primary = 0;       	}       	printk(KERN_INFO "Found %s PCI host bridge at 0x%08x. Firmware bus number: %d->%d\n",       		disp_name, addr->address, hose->first_busno, hose->last_busno);       	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 __initpcibios_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	 */	while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {		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 __initpmac_pcibios_fixup(void){	/* Fixup interrupts according to OF tree */	pcibios_fixup_OF_interrupts();}int __pmacpmac_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->device == PCI_DEVICE_ID_APPLE_KL_USB && !node)		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, pci_cache_line_size);	}	return 0;}/* We power down some devices after they have been probed. They'll * be powered back on later on */void __initpmac_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	 */	while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {		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;	}}void pmac_pci_fixup_cardbus(struct pci_dev* dev){	if (_machine != _MACH_Pmac)		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);	}}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 != _MACH_Pmac)		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");	}}/* * Disable second function on K2-SATA, it's broken * and disable IO BARs on first one */void __pmac pmac_pci_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);		}	}}

⌨️ 快捷键说明

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