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

📄 pmac_pci.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Support for PCI bridges found on Power Macintoshes. * At present the "bandit" and "chaos" bridges are supported. * Fortunately you access configuration space in the same * way with either bridge. * * Copyright (C) 1997 Paul Mackerras (paulus@cs.anu.edu.au) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */#include <linux/kernel.h>#include <linux/pci.h>#include <linux/delay.h>#include <linux/string.h>#include <linux/init.h>#include <linux/bootmem.h>#include <asm/sections.h>#include <asm/io.h>#include <asm/prom.h>#include <asm/pci-bridge.h>#include <asm/machdep.h>#include <asm/pmac_feature.h>#undef DEBUG#ifdef DEBUG#ifdef CONFIG_XMONextern void xmon_printf(const char *fmt, ...);#define DBG(x...) xmon_printf(x)#else#define DBG(x...) printk(x)#endif#else#define DBG(x...)#endifstatic int add_bridge(struct device_node *dev);extern void pmac_check_ht_link(void);/* XXX Could be per-controller, but I don't think we risk anything by * assuming we won't have both UniNorth and Bandit */static int has_uninorth;#ifdef CONFIG_POWER4static struct pci_controller *u3_agp;#endif /* CONFIG_POWER4 */extern u8 pci_cache_line_size;struct pci_dev *k2_skiplist[2];/* * Magic constants for enabling cache coherency in the bandit/PSX bridge. */#define BANDIT_DEVID_2	8#define BANDIT_REVID	3#define BANDIT_DEVNUM	11#define BANDIT_MAGIC	0x50#define BANDIT_COHERENT	0x40static int __initfixup_one_level_bus_range(struct device_node *node, int higher){	for (; node != 0;node = node->sibling) {		int * bus_range;		unsigned int *class_code;		int len;		/* For PCI<->PCI bridges or CardBus bridges, we go down */		class_code = (unsigned int *) get_property(node, "class-code", NULL);		if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&			(*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))			continue;		bus_range = (int *) get_property(node, "bus-range", &len);		if (bus_range != NULL && len > 2 * sizeof(int)) {			if (bus_range[1] > higher)				higher = bus_range[1];		}		higher = fixup_one_level_bus_range(node->child, higher);	}	return higher;}/* This routine fixes the "bus-range" property of all bridges in the * system since they tend to have their "last" member wrong on macs * * Note that the bus numbers manipulated here are OF bus numbers, they * are not Linux bus numbers. */static void __initfixup_bus_range(struct device_node *bridge){	int * bus_range;	int len;	/* Lookup the "bus-range" property for the hose */	bus_range = (int *) get_property(bridge, "bus-range", &len);	if (bus_range == NULL || len < 2 * sizeof(int)) {		printk(KERN_WARNING "Can't get bus-range for %s\n",			       bridge->full_name);		return;	}	bus_range[1] = fixup_one_level_bus_range(bridge->child, bus_range[1]);}/* * Apple MacRISC (U3, UniNorth, Bandit, Chaos) PCI controllers. * * The "Bandit" version is present in all early PCI PowerMacs, * and up to the first ones using Grackle. Some machines may * have 2 bandit controllers (2 PCI busses). * * "Chaos" is used in some "Bandit"-type machines as a bridge * for the separate display bus. It is accessed the same * way as bandit, but cannot be probed for devices. It therefore * has its own config access functions. * * The "UniNorth" version is present in all Core99 machines * (iBook, G4, new IMacs, and all the recent Apple machines). * It contains 3 controllers in one ASIC. * * The U3 is the bridge used on G5 machines. It contains an * AGP bus which is dealt with the old UniNorth access routines * and a HyperTransport bus which uses its own set of access * functions. */#define MACRISC_CFA0(devfn, off)	\	((1 << (unsigned long)PCI_SLOT(dev_fn)) \	| (((unsigned long)PCI_FUNC(dev_fn)) << 8) \	| (((unsigned long)(off)) & 0xFCUL))#define MACRISC_CFA1(bus, devfn, off)	\	((((unsigned long)(bus)) << 16) \	|(((unsigned long)(devfn)) << 8) \	|(((unsigned long)(off)) & 0xFCUL) \	|1UL)static unsigned int __pmacmacrisc_cfg_access(struct pci_controller* hose, u8 bus, u8 dev_fn, u8 offset){	unsigned int caddr;	if (bus == hose->first_busno) {		if (dev_fn < (11 << 3))			return 0;		caddr = MACRISC_CFA0(dev_fn, offset);	} else		caddr = MACRISC_CFA1(bus, dev_fn, offset);	/* Uninorth will return garbage if we don't read back the value ! */	do {		out_le32(hose->cfg_addr, caddr);	} while (in_le32(hose->cfg_addr) != caddr);	offset &= has_uninorth ? 0x07 : 0x03;	return (unsigned int)(hose->cfg_data) + (unsigned int)offset;}static int __pmacmacrisc_read_config(struct pci_bus *bus, unsigned int devfn, int offset,		    int len, u32 *val){	struct pci_controller *hose = bus->sysdata;	unsigned int addr;	addr = macrisc_cfg_access(hose, bus->number, devfn, offset);	if (!addr)		return PCIBIOS_DEVICE_NOT_FOUND;	/*	 * Note: the caller has already checked that offset is	 * suitably aligned and that len is 1, 2 or 4.	 */	switch (len) {	case 1:		*val = in_8((u8 *)addr);		break;	case 2:		*val = in_le16((u16 *)addr);		break;	default:		*val = in_le32((u32 *)addr);		break;	}	return PCIBIOS_SUCCESSFUL;}static int __pmacmacrisc_write_config(struct pci_bus *bus, unsigned int devfn, int offset,		     int len, u32 val){	struct pci_controller *hose = bus->sysdata;	unsigned int addr;	addr = macrisc_cfg_access(hose, bus->number, devfn, offset);	if (!addr)		return PCIBIOS_DEVICE_NOT_FOUND;	/*	 * Note: the caller has already checked that offset is	 * suitably aligned and that len is 1, 2 or 4.	 */	switch (len) {	case 1:		out_8((u8 *)addr, val);		(void) in_8((u8 *)addr);		break;	case 2:		out_le16((u16 *)addr, val);		(void) in_le16((u16 *)addr);		break;	default:		out_le32((u32 *)addr, val);		(void) in_le32((u32 *)addr);		break;	}	return PCIBIOS_SUCCESSFUL;}static struct pci_ops macrisc_pci_ops ={	macrisc_read_config,	macrisc_write_config};/* * Verifiy that a specific (bus, dev_fn) exists on chaos */static int __pmacchaos_validate_dev(struct pci_bus *bus, int devfn, int offset){	struct device_node *np;	u32 *vendor, *device;	np = pci_busdev_to_OF_node(bus, devfn);	if (np == NULL)		return PCIBIOS_DEVICE_NOT_FOUND;	vendor = (u32 *)get_property(np, "vendor-id", NULL);	device = (u32 *)get_property(np, "device-id", NULL);	if (vendor == NULL || device == NULL)		return PCIBIOS_DEVICE_NOT_FOUND;	if ((*vendor == 0x106b) && (*device == 3) && (offset >= 0x10)	    && (offset != 0x14) && (offset != 0x18) && (offset <= 0x24))		return PCIBIOS_BAD_REGISTER_NUMBER;	return PCIBIOS_SUCCESSFUL;}static int __pmacchaos_read_config(struct pci_bus *bus, unsigned int devfn, int offset,		  int len, u32 *val){	int result = chaos_validate_dev(bus, devfn, offset);	if (result == PCIBIOS_BAD_REGISTER_NUMBER)		*val = ~0U;	if (result != PCIBIOS_SUCCESSFUL)		return result;	return macrisc_read_config(bus, devfn, offset, len, val);}static int __pmacchaos_write_config(struct pci_bus *bus, unsigned int devfn, int offset,		   int len, u32 val){	int result = chaos_validate_dev(bus, devfn, offset);	if (result != PCIBIOS_SUCCESSFUL)		return result;	return macrisc_write_config(bus, devfn, offset, len, val);}static struct pci_ops chaos_pci_ops ={	chaos_read_config,	chaos_write_config};#ifdef CONFIG_POWER4/* * These versions of U3 HyperTransport config space access ops do not * implement self-view of the HT host yet */#define U3_HT_CFA0(devfn, off)		\		((((unsigned long)devfn) << 8) | offset)#define U3_HT_CFA1(bus, devfn, off)	\		(U3_HT_CFA0(devfn, off) \		+ (((unsigned long)bus) << 16) \		+ 0x01000000UL)static unsigned long __pmacu3_ht_cfg_access(struct pci_controller* hose, u8 bus, u8 devfn, u8 offset){	if (bus == hose->first_busno) {		/* For now, we don't self probe U3 HT bridge */		if (PCI_FUNC(devfn) != 0 || PCI_SLOT(devfn) > 7 ||		    PCI_SLOT(devfn) < 1)			return 0;		return ((unsigned long)hose->cfg_data) + U3_HT_CFA0(devfn, offset);	} else		return ((unsigned long)hose->cfg_data) + U3_HT_CFA1(bus, devfn, offset);}static int __pmacu3_ht_read_config(struct pci_bus *bus, unsigned int devfn, int offset,		    int len, u32 *val){	struct pci_controller *hose = bus->sysdata;	unsigned int addr;	int i;	/*	 * When a device in K2 is powered down, we die on config	 * cycle accesses. Fix that here.	 */	for (i=0; i<2; i++)		if (k2_skiplist[i] && k2_skiplist[i]->bus == bus &&		    k2_skiplist[i]->devfn == devfn) {			switch (len) {			case 1:				*val = 0xff; break;			case 2:				*val = 0xffff; break;			default:				*val = 0xfffffffful; break;			}			return PCIBIOS_SUCCESSFUL;		}	    	addr = u3_ht_cfg_access(hose, bus->number, devfn, offset);	if (!addr)		return PCIBIOS_DEVICE_NOT_FOUND;	/*	 * Note: the caller has already checked that offset is	 * suitably aligned and that len is 1, 2 or 4.	 */	switch (len) {	case 1:		*val = in_8((u8 *)addr);		break;	case 2:		*val = in_le16((u16 *)addr);		break;	default:		*val = in_le32((u32 *)addr);		break;	}	return PCIBIOS_SUCCESSFUL;}static int __pmacu3_ht_write_config(struct pci_bus *bus, unsigned int devfn, int offset,		     int len, u32 val){	struct pci_controller *hose = bus->sysdata;	unsigned int addr;	int i;	/*	 * When a device in K2 is powered down, we die on config	 * cycle accesses. Fix that here.	 */	for (i=0; i<2; i++)

⌨️ 快捷键说明

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