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

📄 pci.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2004 Benjamin Herrenschmuidt (benh@kernel.crashing.org), *		      IBM Corp. * * 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. */#undef DEBUG#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/iommu.h>#include <asm/ppc-pci.h>#include "maple.h"#ifdef DEBUG#define DBG(x...) printk(x)#else#define DBG(x...)#endifstatic struct pci_controller *u3_agp, *u3_ht, *u4_pcie;static 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;	struct property *prop;	int len;	/* Lookup the "bus-range" property for the hose */	prop = of_find_property(bridge, "bus-range", &len);	if (prop == NULL  || prop->value == NULL || len < 2 * sizeof(int)) {		printk(KERN_WARNING "Can't get bus-range for %s\n",			       bridge->full_name);		return;	}	bus_range = prop->value;	bus_range[1] = fixup_one_level_bus_range(bridge->child, bus_range[1]);}static unsigned long u3_agp_cfa0(u8 devfn, u8 off){	return (1 << (unsigned long)PCI_SLOT(devfn)) |		((unsigned long)PCI_FUNC(devfn) << 8) |		((unsigned long)off & 0xFCUL);}static unsigned long u3_agp_cfa1(u8 bus, u8 devfn, u8 off){	return ((unsigned long)bus << 16) |		((unsigned long)devfn << 8) |		((unsigned long)off & 0xFCUL) |		1UL;}static volatile void __iomem *u3_agp_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 = u3_agp_cfa0(dev_fn, offset);	} else		caddr = u3_agp_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 &= 0x07;	return hose->cfg_data + offset;}static int u3_agp_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;	addr = u3_agp_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 u3_agp_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;	addr = u3_agp_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 u3_agp_pci_ops ={	.read = u3_agp_read_config,	.write = u3_agp_write_config,};static unsigned long u3_ht_cfa0(u8 devfn, u8 off){	return (devfn << 8) | off;}static unsigned long u3_ht_cfa1(u8 bus, u8 devfn, u8 off){	return u3_ht_cfa0(devfn, off) + (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) {		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 > 0xff)		return PCIBIOS_BAD_REGISTER_NUMBER;	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(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 > 0xff)		return PCIBIOS_BAD_REGISTER_NUMBER;	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:		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 u3_ht_pci_ops ={	.read = u3_ht_read_config,	.write = u3_ht_write_config,};static unsigned int u4_pcie_cfa0(unsigned int devfn, unsigned int off){	return (1 << PCI_SLOT(devfn))	|	       (PCI_FUNC(devfn) << 8)	|	       ((off >> 8) << 28) 	|	       (off & 0xfcu);}static unsigned int u4_pcie_cfa1(unsigned int bus, unsigned int devfn,				 unsigned int off){        return (bus << 16)		|	       (devfn << 8)		|	       ((off >> 8) << 28)	|	       (off & 0xfcu)		| 1u;}static volatile void __iomem *u4_pcie_cfg_access(struct pci_controller* hose,                                        u8 bus, u8 dev_fn, int offset){        unsigned int caddr;        if (bus == hose->first_busno)                caddr = u4_pcie_cfa0(dev_fn, offset);        else                caddr = u4_pcie_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 &= 0x03;        return hose->cfg_data + offset;}static int u4_pcie_read_config(struct pci_bus *bus, unsigned int devfn,

⌨️ 快捷键说明

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