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

📄 pmac_pci.c

📁 ARM 嵌入式 系统 设计与实例开发 实验教材 二源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		printk("Can't find hose for PCI<->PCI bridge\n");#endif				return;	}	if (early_read_config_word(hose, bus, devfn,				   PCI_BRIDGE_CONTROL, &val) < 0) {		printk(KERN_ERR "init_p2pbridge: couldn't read bridge control\n");		return;	}	val &= ~PCI_BRIDGE_CTL_MASTER_ABORT;	early_write_config_word(hose, bus, devfn, PCI_BRIDGE_CONTROL, val);}void __initpmac_find_bridges(void){	add_bridges(find_devices("bandit"));	add_bridges(find_devices("chaos"));	add_bridges(find_devices("pci"));	init_p2pbridge();}#define GRACKLE_CFA(b, d, o)	(0x80 | ((b) << 8) | ((d) << 16) \				 | (((o) & ~3) << 24))#define GRACKLE_PICR1_STG		0x00000040#define GRACKLE_PICR1_LOOPSNOOP		0x00000010/* N.B. this is called before bridges is initialized, so we can't   use grackle_pcibios_{read,write}_config_dword. */static inline void grackle_set_stg(struct pci_controller* bp, int enable){	unsigned int val;	out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));	val = in_le32((volatile unsigned int *)bp->cfg_data);	val = enable? (val | GRACKLE_PICR1_STG) :		(val & ~GRACKLE_PICR1_STG);	out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));	out_le32((volatile unsigned int *)bp->cfg_data, val);	(void)in_le32((volatile unsigned int *)bp->cfg_data);}static inline void grackle_set_loop_snoop(struct pci_controller *bp, int enable){	unsigned int val;	out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));	val = in_le32((volatile unsigned int *)bp->cfg_data);	val = enable? (val | GRACKLE_PICR1_LOOPSNOOP) :		(val & ~GRACKLE_PICR1_LOOPSNOOP);	out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));	out_le32((volatile unsigned int *)bp->cfg_data, val);	(void)in_le32((volatile unsigned int *)bp->cfg_data);}static int __initsetup_uninorth(struct pci_controller* hose, struct reg_property* addr){	pci_assign_all_busses = 1;	has_uninorth = 1;	hose->ops = &macrisc_pci_ops;	hose->cfg_addr = ioremap(addr->address + 0x800000, 0x1000);	hose->cfg_data = ioremap(addr->address + 0xc00000, 0x1000);	/* We "know" that the bridge at f2000000 has the PCI slots. */	return addr->address == 0xf2000000;}static void __initsetup_bandit(struct pci_controller* hose, struct reg_property* addr){	hose->ops = &macrisc_pci_ops;	hose->cfg_addr = (volatile unsigned int *)		ioremap(addr->address + 0x800000, 0x1000);	hose->cfg_data = (volatile unsigned char *)		ioremap(addr->address + 0xc00000, 0x1000);	init_bandit(hose);}static void __initsetup_chaos(struct pci_controller* hose, struct reg_property* addr){	/* assume a `chaos' bridge */	hose->ops = &chaos_pci_ops;	hose->cfg_addr = (volatile unsigned int *)		ioremap(addr->address + 0x800000, 0x1000);	hose->cfg_data = (volatile unsigned char *)		ioremap(addr->address + 0xc00000, 0x1000);}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 void __initadd_bridges(struct device_node *dev){	int len;	struct pci_controller *hose;	struct reg_property *addr;	char* disp_name;	int *bus_range;	int first = 1, primary;		for (; dev != NULL; dev = dev->next) {		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);			continue;		}		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)			continue;		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;		primary = first;		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);#ifdef DEBUG		printk(" ->Hose at 0x%08lx, cfg_addr=0x%08lx,cfg_data=0x%08lx\n",			hose, hose->cfg_addr, hose->cfg_data);#endif						/* 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);		first &= !primary;	}}static void __initpcibios_fixup_OF_interrupts(void){		struct pci_dev* dev;		pci_for_each_dev(dev)	{		/*		 * Open Firmware often doesn't initialize the,		 * PCI_INTERRUPT_LINE config register properly, so we		 * should find the device node and se if it has an		 * AAPL,interrupts property.		 */		unsigned char pin;		struct device_node* node;					if (pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin) || !pin)			continue; /* No interrupt generated -> no fixup */		node = pci_device_to_OF_node(dev);		if (!node) {			printk("No OF node for device %x:%x\n", dev->bus->number, dev->devfn >> 3);			continue;		}		/* this is the node, see if it has interrupts */		if (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 mecanisms and really		 * regiser 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, 8);	}		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;	/* 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	 */	pci_for_each_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;	}}

⌨️ 快捷键说明

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