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

📄 pci_st40.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  * Copyright (C) 2001 David J. Mckay (david.mckay@st.com) * * May be copied or modified under the terms of the GNU General Public * License.  See linux/COPYING for more information.                             * * Support functions for the ST40 PCI hardware. */#include <linux/config.h>#include <linux/kernel.h>#include <linux/smp.h>#include <linux/smp_lock.h>#include <linux/init.h>#include <linux/errno.h>#include <linux/pci.h>#include <linux/delay.h>#include <linux/types.h>#include <asm/pci.h>#include <linux/irq.h>#include "pci_st40.h"static struct resource pci_io_space, pci_mem_space;/* This is in P2 of course */#define ST40PCI_BASE_ADDRESS     (0xb0000000)#define ST40PCI_MEM_ADDRESS      (ST40PCI_BASE_ADDRESS+0x0)#define ST40PCI_IO_ADDRESS       (ST40PCI_BASE_ADDRESS+0x06000000)#define ST40PCI_REG_ADDRESS      (ST40PCI_BASE_ADDRESS+0x07000000)#define ST40PCI_REG(x) (ST40PCI_REG_ADDRESS+(ST40PCI_##x))#define ST40PCI_REG_INDEXED(reg, index) 				\	(ST40PCI_REG(reg##0) +					\	  ((ST40PCI_REG(reg##1) - ST40PCI_REG(reg##0))*index))#define ST40PCI_WRITE(reg,val) writel((val),ST40PCI_REG(reg));udelay(2);#define ST40PCI_WRITE_SHORT(reg,val) writew((val),ST40PCI_REG(reg));udelay(2);#define ST40PCI_WRITE_BYTE(reg,val) writeb((val),ST40PCI_REG(reg));udelay(2);#define ST40PCI_WRITE_INDEXED(reg, index, val)				\	 writel((val), ST40PCI_REG_INDEXED(reg, index)); udelay(2);#define ST40PCI_READ(reg) readl(ST40PCI_REG(reg))#define ST40PCI_READ_SHORT(reg) readw(ST40PCI_REG(reg))#define ST40PCI_READ_BYTE(reg) readb(ST40PCI_REG(reg))#define ST40PCI_READ_INDEXED(reg, index) readl(ST40PCI_REG_INDEXED(reg, index))#define ST40PCI_SERR_IRQ        64#define ST40PCI_ERR_IRQ        65#define ST40PCI_AD_INT			66#define ST40PCI_PWR_DWN_INT		67#define PLLPCICR (0xbb040000+0x10)	// CLKGENA.PLL2CR/* From ST's include/asm-sh/st40_clock.h *//* Macros to extract PLL params */#define PLL_MDIV(reg)  ( ((unsigned)reg) & 0xff )#define PLL_NDIV(reg) ( (((unsigned)reg)>>8) & 0xff )#define PLL_PDIV(reg) ( (((unsigned)reg)>>16) & 0x7 )#define PLL_SETUP(reg) ( (((unsigned)reg)>>19) & 0x1ff )/* * The pcibios_map_platform_irq function is defined in the appropraite * board specific code and referenced here */extern int __init pcibios_map_platform_irq(struct pci_dev *dev, u8 slot, u8 pin);static void __init pcibios_assign_resources(void);static __init void SetPCIPLL(void){	{		/* Lets play with the PLL values */		unsigned long pll1cr1;		unsigned long mdiv, ndiv, pdiv;		unsigned long muxcr;		unsigned int muxcr_ratios[4] = { 8, 16, 21, 1 };		unsigned int freq;#define CLKGENA            0xbb040000#define CLKGENA_PLL2_MUXCR CLKGENA + 0x48		pll1cr1 = ctrl_inl(PLLPCICR);		printk("PLL1CR1 %08x\n", pll1cr1);		mdiv = PLL_MDIV(pll1cr1);		ndiv = PLL_NDIV(pll1cr1);		pdiv = PLL_PDIV(pll1cr1);		printk("mdiv %02x ndiv %02x pdiv %02x\n", mdiv, ndiv, pdiv);		freq = ((2*27*ndiv)/mdiv) / (1 << pdiv);		printk("PLL freq %dMHz\n", freq);		muxcr = ctrl_inl(CLKGENA_PLL2_MUXCR);		printk("PCI freq %dMhz\n", freq / muxcr_ratios[muxcr & 3]);	}}struct pci_err {  unsigned mask;  const char *error_string;};static struct pci_err int_error[]={  { INT_MNLTDIM,"MNLTDIM: Master non-lock transfer"},  { INT_TTADI,  "TTADI: Illegal byte enable in I/O transfer"},    { INT_TMTO,   "TMTO: Target memory read/write timeout"},    { INT_MDEI,   "MDEI: Master function disable error"},  { INT_APEDI,  "APEDI: Address parity error"},  { INT_SDI,    "SDI: SERR detected"},  { INT_DPEITW, "DPEITW: Data parity error target write"},    { INT_PEDITR, "PEDITR: PERR detected"},  { INT_TADIM,  "TADIM: Target abort detected"},  { INT_MADIM,  "MADIM: Master abort detected"},  { INT_MWPDI,  "MWPDI: PERR from target at data write"},  { INT_MRDPEI, "MRDPEI: Master read data parity error"}};#define NUM_PCI_INT_ERRS (sizeof(int_error)/sizeof(struct pci_err))static struct pci_err aint_error[]={  { AINT_MBI,   "MBI: Master broken"},  { AINT_TBTOI, "TBTOI: Target bus timeout"},  { AINT_MBTOI, "MBTOI: Master bus timeout"},  { AINT_TAI,   "TAI: Target abort"},  { AINT_MAI,   "MAI: Master abort"},  { AINT_RDPEI, "RDPEI: Read data parity"},  { AINT_WDPE,  "WDPE: Write data parity"}};#define NUM_PCI_AINT_ERRS (sizeof(aint_error)/sizeof(struct pci_err))static void print_pci_errors(unsigned reg,struct pci_err *error,int num_errors){  int i;  for(i=0;i<num_errors;i++) {    if(reg & error[i].mask) {      printk("%s\n",error[i].error_string);    }  }}static char * pci_commands[16]={	"Int Ack",	"Special Cycle",	"I/O Read",	"I/O Write",	"Reserved",	"Reserved",	"Memory Read",	"Memory Write",	"Reserved",	"Reserved",	"Configuration Read",	"Configuration Write",	"Memory Read Multiple",	"Dual Address Cycle",	"Memory Read Line",	"Memory Write-and-Invalidate"};static void st40_pci_irq(int irq, void *dev_instance, struct pt_regs *regs){	unsigned pci_int, pci_air, pci_cir, pci_aint;	static int count=0;	pci_int = ST40PCI_READ(INT);pci_aint = ST40PCI_READ(AINT);	pci_cir = ST40PCI_READ(CIR);pci_air = ST40PCI_READ(AIR);	/* Reset state to stop multiple interrupts */        ST40PCI_WRITE(INT, ~0); ST40PCI_WRITE(AINT, ~0); 	if(++count>1) return;	printk("** PCI ERROR **\n");        if(pci_int) {		printk("** INT register status\n");		print_pci_errors(pci_int,int_error,NUM_PCI_INT_ERRS);	}        if(pci_aint) {		printk("** AINT register status\n");		print_pci_errors(pci_aint,aint_error,NUM_PCI_AINT_ERRS);	}   		printk("** Address and command info\n");	printk("** Command  %s : Address 0x%x\n",	       pci_commands[pci_cir&0xf],pci_air);	if(pci_cir&CIR_PIOTEM) {		printk("CIR_PIOTEM:PIO transfer error for master\n");	}        if(pci_cir&CIR_RWTET) {		printk("CIR_RWTET:Read/Write transfer error for target\n");	}}/* Rounds a number UP to the nearest power of two. Used for * sizing the PCI window. */static u32 r2p2(u32 num){	int i = 31;	u32 tmp = num;	if (num == 0)		return 0;	do {		if (tmp & (1 << 31))			break;		i--;		tmp <<= 1;	} while (i >= 0);	tmp = 1 << i;	/* If the original number isn't a power of 2, round it up */	if (tmp != num)		tmp <<= 1;	return tmp;}static void __init pci_fixup_ide_bases(struct pci_dev *d){	int i;	/*	 * PCI IDE controllers use non-standard I/O port decoding, respect it.	 */	if ((d->class >> 8) != PCI_CLASS_STORAGE_IDE)		return;	printk("PCI: IDE base address fixup for %s\n", d->slot_name);	for(i=0; i<4; i++) {		struct resource *r = &d->resource[i];		if ((r->start & ~0x80) == 0x374) {			r->start |= 2;			r->end = r->start;		}	}}static void __init pci_fixup_cache_line(struct pci_dev *d){	pci_write_config_byte(d,PCI_CACHE_LINE_SIZE,0);}/* Add future fixups here... */struct pci_fixup pcibios_fixups[] = {	{ PCI_FIXUP_HEADER,	PCI_ANY_ID,	PCI_ANY_ID,	pci_fixup_ide_bases },	{ PCI_FIXUP_FINAL,	PCI_ANY_ID,	PCI_ANY_ID,	pci_fixup_cache_line },	{ 0 }};char * __init pcibios_setup(char *str){	return str;}static void __init st40pci_init_resources(void){	pci_io_space.start = PCIBIOS_MIN_IO;	pci_io_space.end   = 64*1024 - PCIBIOS_MIN_IO - 1;	pci_io_space.name = "ST40 PCI";	pci_io_space.flags = IORESOURCE_IO;	request_resource(&ioport_resource, &pci_io_space);	pci_mem_space.start = PCIBIOS_MIN_MEM;	pci_mem_space.end   = PCIBIOS_MIN_MEM + (96*1024*1024) -1;	pci_mem_space.name = "ST40 PCI";	pci_mem_space.flags = IORESOURCE_MEM;	request_resource(&iomem_resource, &pci_mem_space);}int __init st40pci_init(unsigned memStart, unsigned memSize){	u32 lsr0; 	printk("PCI version register reads 0x%x\n",ST40PCI_READ(VCR_VERSION));	SetPCIPLL();	st40pci_init_resources();	/* Initialises the ST40 pci subsystem, performing a reset, then programming	 * up the address space decoders appropriately	 */	/* Should reset core here as well methink */	ST40PCI_WRITE(CR, CR_LOCK_MASK | CR_SOFT_RESET);	/* Loop while core resets */	while (ST40PCI_READ(CR) & CR_SOFT_RESET);	/* Switch off interrupts */	ST40PCI_WRITE(INTM, 0);	ST40PCI_WRITE(AINT, 0);	/* Now, lets reset all the cards on the bus with extreme prejudice */	ST40PCI_WRITE(CR, CR_LOCK_MASK | CR_RSTCTL);	udelay(250);	/* Set bus active, take it out of reset */	ST40PCI_WRITE(CR, CR_LOCK_MASK | CR_BMAM | CR_CFINT | CR_PFCS | CR_PFE);	/* The PCI spec says that no access must be made to the bus until 1 second	 * after reset. This seem ludicrously long, but some delay is needed here	 */	mdelay(1000);	/* Allow it to be a master */	ST40PCI_WRITE_SHORT(CSR_CMD,			    PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |			    PCI_COMMAND_IO);	/* Accesse to the 0xb0000000 -> 0xb6000000 area will go through to 0x10000000 -> 0x16000000	 * on the PCI bus. This allows a nice 1-1 bus to phys mapping.	 */	ST40PCI_WRITE(MBR, 0x10000000);	/* Always set the max size 128M (actually, it is only 96MB wide) */	ST40PCI_WRITE(MBMR, 0x07ff0000);	/* I/O addresses are mapped at 0xb6000000 -> 0xb7000000. These are changed to 0, to 	 * allow cards that have legacy io such as vga to function correctly. This gives a 	 * maximum of 64K of io/space as only the bottom 16 bits of the address are copied 	 * over to the bus  when the transaction is made. 64K of io space is more than enough	 */	ST40PCI_WRITE(IOBR, 0x0);	/* Set up the 64K window */	ST40PCI_WRITE(IOBMR, 0x0);	/* Now we set up the mbars so the PCI bus can see the local memory */

⌨️ 快捷键说明

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