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

📄 pci.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Support for PCI bridges found on Power Macintoshes. * * Copyright (C) 2003-2005 Benjamin Herrenschmuidt (benh@kernel.crashing.org) * Copyright (C) 1997 Paul Mackerras (paulus@samba.org) * * 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 <linux/irq.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>#include <asm/grackle.h>#include <asm/ppc-pci.h>#undef DEBUG#ifdef DEBUG#define DBG(x...) printk(x)#else#define DBG(x...)#endif/* 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_PPC64static struct pci_controller *u3_agp;static struct pci_controller *u4_pcie;static struct pci_controller *u3_ht;#elsestatic int has_second_ohare;#endif /* CONFIG_PPC64 */extern int pcibios_assign_bus_offset;struct device_node *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 __init fixup_one_level_bus_range(struct device_node *node, int higher){	for (; node != 0;node = node->sibling) {		const int * bus_range;		const unsigned int *class_code;		int len;		/* For PCI<->PCI bridges or CardBus bridges, we go down */		class_code = of_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 = of_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 __init fixup_bus_range(struct device_node *bridge){	int *bus_range, len;	struct property *prop;	/* Lookup the "bus-range" property for the hose */	prop = of_find_property(bridge, "bus-range", &len);	if (prop == NULL || prop->length < 2 * sizeof(int))		return;	bus_range = prop->value;	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 int)PCI_SLOT(dev_fn)) \	| (((unsigned int)PCI_FUNC(dev_fn)) << 8) \	| (((unsigned int)(off)) & 0xFCUL))#define MACRISC_CFA1(bus, devfn, off)	\	((((unsigned int)(bus)) << 16) \	|(((unsigned int)(devfn)) << 8) \	|(((unsigned int)(off)) & 0xFCUL) \	|1UL)static volatile void __iomem *macrisc_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 NULL;		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 hose->cfg_data + offset;}static int macrisc_read_config(struct pci_bus *bus, unsigned int devfn,				      int offset, int len, u32 *val){	struct pci_controller *hose;	volatile void __iomem *addr;	hose = pci_bus_to_host(bus);	if (hose == NULL)		return PCIBIOS_DEVICE_NOT_FOUND;	if (offset >= 0x100)		return  PCIBIOS_BAD_REGISTER_NUMBER;	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(addr);		break;	case 2:		*val = in_le16(addr);		break;	default:		*val = in_le32(addr);		break;	}	return PCIBIOS_SUCCESSFUL;}static int macrisc_write_config(struct pci_bus *bus, unsigned int devfn,				       int offset, int len, u32 val){	struct pci_controller *hose;	volatile void __iomem *addr;	hose = pci_bus_to_host(bus);	if (hose == NULL)		return PCIBIOS_DEVICE_NOT_FOUND;	if (offset >= 0x100)		return  PCIBIOS_BAD_REGISTER_NUMBER;	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(addr, val);		break;	case 2:		out_le16(addr, val);		break;	default:		out_le32(addr, val);		break;	}	return PCIBIOS_SUCCESSFUL;}static struct pci_ops macrisc_pci_ops ={	.read = macrisc_read_config,	.write = macrisc_write_config,};#ifdef CONFIG_PPC32/* * Verify that a specific (bus, dev_fn) exists on chaos */static int chaos_validate_dev(struct pci_bus *bus, int devfn, int offset){	struct device_node *np;	const u32 *vendor, *device;	if (offset >= 0x100)		return  PCIBIOS_BAD_REGISTER_NUMBER;	np = pci_busdev_to_OF_node(bus, devfn);	if (np == NULL)		return PCIBIOS_DEVICE_NOT_FOUND;	vendor = of_get_property(np, "vendor-id", NULL);	device = of_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 intchaos_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 intchaos_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 ={	.read = chaos_read_config,	.write = chaos_write_config,};static void __init setup_chaos(struct pci_controller *hose,			       struct resource *addr){	/* assume a `chaos' bridge */	hose->ops = &chaos_pci_ops;	hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);	hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);}#endif /* CONFIG_PPC32 */#ifdef CONFIG_PPC64/* * These versions of U3 HyperTransport config space access ops do not * implement self-view of the HT host yet *//* * This function deals with some "special cases" devices. * *  0 -> No special case *  1 -> Skip the device but act as if the access was successfull *       (return 0xff's on reads, eventually, cache config space *       accesses in a later version) * -1 -> Hide the device (unsuccessful acess) */static int u3_ht_skip_device(struct pci_controller *hose,			     struct pci_bus *bus, unsigned int devfn){	struct device_node *busdn, *dn;	int i;	/* We only allow config cycles to devices that are in OF device-tree	 * as we are apparently having some weird things going on with some	 * revs of K2 on recent G5s	 */	if (bus->self)		busdn = pci_device_to_OF_node(bus->self);	else		busdn = hose->arch_data;	for (dn = busdn->child; dn; dn = dn->sibling)		if (PCI_DN(dn) && PCI_DN(dn)->devfn == devfn)			break;	if (dn == NULL)		return -1;	/*	 * 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] == dn)			return 1;	return 0;}#define U3_HT_CFA0(devfn, off)		\		((((unsigned int)devfn) << 8) | offset)#define U3_HT_CFA1(bus, devfn, off)	\		(U3_HT_CFA0(devfn, off) \		+ (((unsigned int)bus) << 16) \		+ 0x01000000UL)static volatile void __iomem *u3_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_SLOT(devfn) == 0)			return NULL;		return hose->cfg_data + U3_HT_CFA0(devfn, offset);	} else		return hose->cfg_data + U3_HT_CFA1(bus, devfn, offset);}static int u3_ht_read_config(struct pci_bus *bus, unsigned int devfn,				    int offset, int len, u32 *val){	struct pci_controller *hose;	volatile void __iomem *addr;	hose = pci_bus_to_host(bus);	if (hose == NULL)		return PCIBIOS_DEVICE_NOT_FOUND;	if (offset >= 0x100)		return  PCIBIOS_BAD_REGISTER_NUMBER;	addr = u3_ht_cfg_access(hose, bus->number, devfn, offset);	if (!addr)		return PCIBIOS_DEVICE_NOT_FOUND;	switch (u3_ht_skip_device(hose, bus, devfn)) {	case 0:		break;	case 1:		switch (len) {		case 1:			*val = 0xff; break;		case 2:			*val = 0xffff; break;		default:			*val = 0xfffffffful; break;		}		return PCIBIOS_SUCCESSFUL;	default:		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(addr);		break;	case 2:		*val = in_le16(addr);		break;	default:		*val = in_le32(addr);		break;	}	return PCIBIOS_SUCCESSFUL;}static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn,				     int offset, int len, u32 val){	struct pci_controller *hose;	volatile void __iomem *addr;	hose = pci_bus_to_host(bus);	if (hose == NULL)		return PCIBIOS_DEVICE_NOT_FOUND;	if (offset >= 0x100)		return  PCIBIOS_BAD_REGISTER_NUMBER;	addr = u3_ht_cfg_access(hose, bus->number, devfn, offset);	if (!addr)		return PCIBIOS_DEVICE_NOT_FOUND;	switch (u3_ht_skip_device(hose, bus, devfn)) {	case 0:		break;	case 1:		return PCIBIOS_SUCCESSFUL;	default:		return PCIBIOS_DEVICE_NOT_FOUND;	}	/*

⌨️ 快捷键说明

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