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

📄 pci.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * iop13xx PCI support * Copyright (c) 2005-2006, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307 USA. * */#include <linux/pci.h>#include <linux/delay.h>#include <linux/jiffies.h>#include <asm/irq.h>#include <asm/hardware.h>#include <asm/sizes.h>#include <asm/signal.h>#include <asm/mach/pci.h>#include <asm/arch/pci.h>#define IOP13XX_PCI_DEBUG 0#define PRINTK(x...) ((void)(IOP13XX_PCI_DEBUG && printk(x)))u32 iop13xx_atux_pmmr_offset; /* This offset can change based on strapping */u32 iop13xx_atue_pmmr_offset; /* This offset can change based on strapping */static struct pci_bus *pci_bus_atux = 0;static struct pci_bus *pci_bus_atue = 0;u32 iop13xx_atue_mem_base;u32 iop13xx_atux_mem_base;size_t iop13xx_atue_mem_size;size_t iop13xx_atux_mem_size;unsigned long iop13xx_pcibios_min_io = 0;unsigned long iop13xx_pcibios_min_mem = 0;EXPORT_SYMBOL(iop13xx_atue_mem_base);EXPORT_SYMBOL(iop13xx_atux_mem_base);EXPORT_SYMBOL(iop13xx_atue_mem_size);EXPORT_SYMBOL(iop13xx_atux_mem_size);int init_atu = 0; /* Flag to select which ATU(s) to initialize / disable */static unsigned long atux_trhfa_timeout = 0; /* Trhfa = RST# high to first						 access *//* Scan the initialized busses and ioremap the requested memory range */void iop13xx_map_pci_memory(void){	int atu;	struct pci_bus *bus;	struct pci_dev *dev;	resource_size_t end = 0;	for (atu = 0; atu < 2; atu++) {		bus = atu ? pci_bus_atue : pci_bus_atux;		if (bus) {			list_for_each_entry(dev, &bus->devices, bus_list) {				int i;				int max = 7;				if (dev->subordinate)					max = DEVICE_COUNT_RESOURCE;				for (i = 0; i < max; i++) {					struct resource *res = &dev->resource[i];					if (res->flags & IORESOURCE_MEM)						end = max(res->end, end);				}			}			switch(atu) {			case 0:				iop13xx_atux_mem_size =					(end - IOP13XX_PCIX_LOWER_MEM_RA) + 1;				/* 16MB align the request */				if (iop13xx_atux_mem_size & (SZ_16M - 1)) {					iop13xx_atux_mem_size &= ~(SZ_16M - 1);					iop13xx_atux_mem_size += SZ_16M;				}				if (end) {					iop13xx_atux_mem_base =					(u32) __arm_ioremap_pfn(					__phys_to_pfn(IOP13XX_PCIX_LOWER_MEM_PA)					, 0, iop13xx_atux_mem_size, MT_DEVICE);					if (!iop13xx_atux_mem_base) {						printk("%s: atux allocation "						       "failed\n", __FUNCTION__);						BUG();					}				} else					iop13xx_atux_mem_size = 0;				PRINTK("%s: atu: %d bus_size: %d mem_base: %x\n",				__FUNCTION__, atu, iop13xx_atux_mem_size,				iop13xx_atux_mem_base);				break;			case 1:				iop13xx_atue_mem_size =					(end - IOP13XX_PCIE_LOWER_MEM_RA) + 1;				/* 16MB align the request */				if (iop13xx_atue_mem_size & (SZ_16M - 1)) {					iop13xx_atue_mem_size &= ~(SZ_16M - 1);					iop13xx_atue_mem_size += SZ_16M;				}				if (end) {					iop13xx_atue_mem_base =					(u32) __arm_ioremap_pfn(					__phys_to_pfn(IOP13XX_PCIE_LOWER_MEM_PA)					, 0, iop13xx_atue_mem_size, MT_DEVICE);					if (!iop13xx_atue_mem_base) {						printk("%s: atue allocation "						       "failed\n", __FUNCTION__);						BUG();					}				} else					iop13xx_atue_mem_size = 0;				PRINTK("%s: atu: %d bus_size: %d mem_base: %x\n",				__FUNCTION__, atu, iop13xx_atue_mem_size,				iop13xx_atue_mem_base);				break;			}			printk("%s: Initialized (%uM @ resource/virtual: %08lx/%08x)\n",			atu ? "ATUE" : "ATUX",			(atu ? iop13xx_atue_mem_size : iop13xx_atux_mem_size) /			SZ_1M,			atu ? IOP13XX_PCIE_LOWER_MEM_RA :			IOP13XX_PCIX_LOWER_MEM_RA,			atu ? iop13xx_atue_mem_base :			iop13xx_atux_mem_base);			end = 0;		}	}}static int iop13xx_atu_function(int atu){	int func = 0;	/* the function number depends on the value of the	 * IOP13XX_INTERFACE_SEL_PCIX reset strap	 * see C-Spec section 3.17	 */	switch(atu) {	case IOP13XX_INIT_ATU_ATUX:		if (__raw_readl(IOP13XX_ESSR0) & IOP13XX_INTERFACE_SEL_PCIX)			func = 5;		else			func = 0;		break;	case IOP13XX_INIT_ATU_ATUE:		if (__raw_readl(IOP13XX_ESSR0) & IOP13XX_INTERFACE_SEL_PCIX)			func = 0;		else			func = 5;		break;	default:		BUG();	}	return func;}/* iop13xx_atux_cfg_address - format a configuration address for atux * @bus: Target bus to access * @devfn: Combined device number and function number * @where: Desired register's address offset * * Convert the parameters to a configuration address formatted * according the PCI-X 2.0 specification */static u32 iop13xx_atux_cfg_address(struct pci_bus *bus, int devfn, int where){	struct pci_sys_data *sys = bus->sysdata;	u32 addr;	if (sys->busnr == bus->number)		addr = 1 << (PCI_SLOT(devfn) + 16) | (PCI_SLOT(devfn) << 11);	else		addr = bus->number << 16 | PCI_SLOT(devfn) << 11 | 1;	addr |=	PCI_FUNC(devfn) << 8 | ((where & 0xff) & ~3);	addr |= ((where & 0xf00) >> 8) << 24; /* upper register number */	return addr;}/* iop13xx_atue_cfg_address - format a configuration address for atue * @bus: Target bus to access * @devfn: Combined device number and function number * @where: Desired register's address offset * * Convert the parameters to an address usable by the ATUE_OCCAR */static u32 iop13xx_atue_cfg_address(struct pci_bus *bus, int devfn, int where){	struct pci_sys_data *sys = bus->sysdata;	u32 addr;	PRINTK("iop13xx_atue_cfg_address: bus: %d dev: %d func: %d",		bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));	addr = ((u32) bus->number)     << IOP13XX_ATUE_OCCAR_BUS_NUM |		   ((u32) PCI_SLOT(devfn)) << IOP13XX_ATUE_OCCAR_DEV_NUM |		   ((u32) PCI_FUNC(devfn)) << IOP13XX_ATUE_OCCAR_FUNC_NUM |		   (where & ~0x3);	if (sys->busnr != bus->number)		addr |= 1; /* type 1 access */	return addr;}/* This routine checks the status of the last configuration cycle.  If an error * was detected it returns >0, else it returns a 0.  The errors being checked * are parity, master abort, target abort (master and target).  These types of * errors occure during a config cycle where there is no device, like during * the discovery stage. */static int iop13xx_atux_pci_status(int clear){	unsigned int status;	int err = 0;	/*	 * Check the status registers.	 */	status = __raw_readw(IOP13XX_ATUX_ATUSR);	if (status & IOP_PCI_STATUS_ERROR)	{		PRINTK("\t\t\tPCI error: ATUSR %#08x", status);		if(clear)			__raw_writew(status & IOP_PCI_STATUS_ERROR,				IOP13XX_ATUX_ATUSR);		err = 1;	}	status = __raw_readl(IOP13XX_ATUX_ATUISR);	if (status & IOP13XX_ATUX_ATUISR_ERROR)	{		PRINTK("\t\t\tPCI error interrupt:  ATUISR %#08x", status);		if(clear)			__raw_writel(status & IOP13XX_ATUX_ATUISR_ERROR,				IOP13XX_ATUX_ATUISR);		err = 1;	}	return err;}/* Simply write the address register and read the configuration * data.  Note that the data dependency on %0 encourages an abort * to be detected before we return. */static u32 iop13xx_atux_read(unsigned long addr){	u32 val;	__asm__ __volatile__(		"str	%1, [%2]\n\t"		"ldr	%0, [%3]\n\t"		"mov	%0, %0\n\t"		: "=r" (val)		: "r" (addr), "r" (IOP13XX_ATUX_OCCAR), "r" (IOP13XX_ATUX_OCCDR));	return val;}/* The read routines must check the error status of the last configuration * cycle.  If there was an error, the routine returns all hex f's. */static intiop13xx_atux_read_config(struct pci_bus *bus, unsigned int devfn, int where,		int size, u32 *value){	unsigned long addr = iop13xx_atux_cfg_address(bus, devfn, where);	u32 val = iop13xx_atux_read(addr) >> ((where & 3) * 8);	if (iop13xx_atux_pci_status(1) || is_atux_occdr_error()) {		__raw_writel(__raw_readl(IOP13XX_XBG_BECSR) & 3,			IOP13XX_XBG_BECSR);		val = 0xffffffff;	}	*value = val;	return PCIBIOS_SUCCESSFUL;}static intiop13xx_atux_write_config(struct pci_bus *bus, unsigned int devfn, int where,		int size, u32 value){	unsigned long addr = iop13xx_atux_cfg_address(bus, devfn, where);	u32 val;	if (size != 4) {		val = iop13xx_atux_read(addr);		if (!iop13xx_atux_pci_status(1) == 0)			return PCIBIOS_SUCCESSFUL;		where = (where & 3) * 8;		if (size == 1)			val &= ~(0xff << where);		else			val &= ~(0xffff << where);		__raw_writel(val | value << where, IOP13XX_ATUX_OCCDR);	} else {		__raw_writel(addr, IOP13XX_ATUX_OCCAR);		__raw_writel(value, IOP13XX_ATUX_OCCDR);	}	return PCIBIOS_SUCCESSFUL;}static struct pci_ops iop13xx_atux_ops = {	.read	= iop13xx_atux_read_config,	.write	= iop13xx_atux_write_config,};/* This routine checks the status of the last configuration cycle.  If an error * was detected it returns >0, else it returns a 0.  The errors being checked * are parity, master abort, target abort (master and target).  These types of * errors occure during a config cycle where there is no device, like during * the discovery stage. */static int iop13xx_atue_pci_status(int clear){	unsigned int status;	int err = 0;	/*	 * Check the status registers.	 */	/* standard pci status register */	status = __raw_readw(IOP13XX_ATUE_ATUSR);	if (status & IOP_PCI_STATUS_ERROR) {		PRINTK("\t\t\tPCI error: ATUSR %#08x", status);		if(clear)			__raw_writew(status & IOP_PCI_STATUS_ERROR,				IOP13XX_ATUE_ATUSR);		err++;	}	/* check the normal status bits in the ATUISR */	status = __raw_readl(IOP13XX_ATUE_ATUISR);	if (status & IOP13XX_ATUE_ATUISR_ERROR)	{		PRINTK("\t\t\tPCI error: ATUISR %#08x", status);		if (clear)			__raw_writew(status & IOP13XX_ATUE_ATUISR_ERROR,				IOP13XX_ATUE_ATUISR);		err++;		/* check the PCI-E status if the ATUISR reports an interface error */		if (status & IOP13XX_ATUE_STAT_PCI_IFACE_ERR) {			/* get the unmasked errors */			status = __raw_readl(IOP13XX_ATUE_PIE_STS) &					~(__raw_readl(IOP13XX_ATUE_PIE_MSK));			if (status) {				PRINTK("\t\t\tPCI-E error: ATUE_PIE_STS %#08x",					__raw_readl(IOP13XX_ATUE_PIE_STS));				err++;			} else {				PRINTK("\t\t\tPCI-E error: ATUE_PIE_STS %#08x",					__raw_readl(IOP13XX_ATUE_PIE_STS));

⌨️ 快捷键说明

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