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

📄 pcic.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: pcic.c,v 1.22.2.1 2002/01/23 14:35:45 davem Exp $ * pcic.c: Sparc/PCI controller support * * Copyright (C) 1998 V. Roganov and G. Raiko * * Code is derived from Ultra/PCI PSYCHO controller support, see that * for author info. * * Support for diverse IIep based platforms by Pete Zaitcev. * CP-1200 by Eric Brower. */#include <linux/config.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/init.h>#include <linux/mm.h>#include <linux/slab.h>#include <asm/ebus.h>#include <asm/sbus.h> /* for sanity check... */#include <asm/swift.h> /* for cache flushing. */#include <asm/io.h>#include <linux/ctype.h>#include <linux/pci.h>#include <linux/timex.h>#include <linux/interrupt.h>#include <asm/irq.h>#include <asm/oplib.h>#include <asm/pcic.h>#include <asm/timer.h>#include <asm/uaccess.h>#ifndef CONFIG_PCIasmlinkage int sys_pciconfig_read(unsigned long bus,				  unsigned long dfn,				  unsigned long off,				  unsigned long len,				  unsigned char *buf){	return -EINVAL;}asmlinkage int sys_pciconfig_write(unsigned long bus,				   unsigned long dfn,				   unsigned long off,				   unsigned long len,				   unsigned char *buf){	return -EINVAL;}#else#ifdef CONFIG_SUN_JSFLASHextern int jsflash_init(void);#endifstruct pci_fixup pcibios_fixups[] = {	{ 0 }};unsigned int pcic_pin_to_irq(unsigned int pin, char *name);/* * I studied different documents and many live PROMs both from 2.30 * family and 3.xx versions. I came to the amazing conclusion: there is * absolutely no way to route interrupts in IIep systems relying on * information which PROM presents. We must hardcode interrupt routing * schematics. And this actually sucks.   -- zaitcev 1999/05/12 * * To find irq for a device we determine which routing map * is in effect or, in other words, on which machine we are running. * We use PROM name for this although other techniques may be used * in special cases (Gleb reports a PROMless IIep based system). * Once we know the map we take device configuration address and * find PCIC pin number where INT line goes. Then we may either program * preferred irq into the PCIC or supply the preexisting irq to the device. */struct pcic_ca2irq {	unsigned char busno;		/* PCI bus number */	unsigned char devfn;		/* Configuration address */	unsigned char pin;		/* PCIC external interrupt pin */	unsigned char irq;		/* Preferred IRQ (mappable in PCIC) */	unsigned int force;		/* Enforce preferred IRQ */};struct pcic_sn2list {	char *sysname;	struct pcic_ca2irq *intmap;	int mapdim;};/* * JavaEngine-1 apparently has different versions. * * According to communications with Sun folks, for P2 build 501-4628-03: * pin 0 - parallel, audio; * pin 1 - Ethernet; * pin 2 - su; * pin 3 - PS/2 kbd and mouse. * * OEM manual (805-1486): * pin 0: Ethernet * pin 1: All EBus * pin 2: IGA (unused) * pin 3: Not connected * OEM manual says that 501-4628 & 501-4811 are the same thing, * only the latter has NAND flash in place. * * So far unofficial Sun wins over the OEM manual. Poor OEMs... */static struct pcic_ca2irq pcic_i_je1a[] = {	/* 501-4811-03 */	{ 0, 0x00, 2, 12, 0 },		/* EBus: hogs all */	{ 0, 0x01, 1,  6, 1 },		/* Happy Meal */	{ 0, 0x80, 0,  7, 0 },		/* IGA (unused) */};/* XXX JS-E entry is incomplete - PCI Slot 2 address (pin 7)? */static struct pcic_ca2irq pcic_i_jse[] = {	{ 0, 0x00, 0, 13, 0 },		/* Ebus - serial and keyboard */	{ 0, 0x01, 1,  6, 0 },		/* hme */	{ 0, 0x08, 2,  9, 0 },		/* VGA - we hope not used :) */	{ 0, 0x10, 6,  8, 0 },		/* PCI INTA# in Slot 1 */	{ 0, 0x18, 7, 12, 0 },		/* PCI INTA# in Slot 2, shared w. RTC */	{ 0, 0x38, 4,  9, 0 },		/* All ISA devices. Read 8259. */	{ 0, 0x80, 5, 11, 0 },		/* EIDE */	/* {0,0x88, 0,0,0} - unknown device... PMU? Probably no interrupt. */	{ 0, 0xA0, 4,  9, 0 },		/* USB */	/*	 * Some pins belong to non-PCI devices, we hardcode them in drivers.	 * sun4m timers - irq 10, 14	 * PC style RTC - pin 7, irq 4 ?	 * Smart card, Parallel - pin 4 shared with USB, ISA	 * audio - pin 3, irq 5 ?	 */};/* SPARCengine-6 was the original release name of CP1200. * The documentation differs between the two versions */static struct pcic_ca2irq pcic_i_se6[] = {	{ 0, 0x08, 0,  2, 0 },		/* SCSI	*/	{ 0, 0x01, 1,  6, 0 },		/* HME	*/	{ 0, 0x00, 3, 13, 0 },		/* EBus	*/};/* * Krups (courtesy of Varol Kaptan) * No documentation available, but it was easy to guess * because it was very similar to Espresso. *   * pin 0 - kbd, mouse, serial; * pin 1 - Ethernet; * pin 2 - igs (we do not use it); * pin 3 - audio; * pin 4,5,6 - unused; * pin 7 - RTC (from P2 onwards as David B. says). */static struct pcic_ca2irq pcic_i_jk[] = {	{ 0, 0x00, 0, 13, 0 },		/* Ebus - serial and keyboard */	{ 0, 0x01, 1,  6, 0 },		/* hme */};/* * Several entries in this list may point to the same routing map * as several PROMs may be installed on the same physical board. */#define SN2L_INIT(name, map)	\  { name, map, sizeof(map)/sizeof(struct pcic_ca2irq) }static struct pcic_sn2list pcic_known_sysnames[] = {	SN2L_INIT("SUNW,JavaEngine1", pcic_i_je1a),	/* JE1, PROM 2.32 */	SN2L_INIT("SUNW,JS-E", pcic_i_jse),	/* PROLL JavaStation-E */	SN2L_INIT("SUNW,SPARCengine-6", pcic_i_se6), /* SPARCengine-6/CP-1200 */	SN2L_INIT("SUNW,JS-NC", pcic_i_jk),	/* PROLL JavaStation-NC */	SN2L_INIT("SUNW,JSIIep", pcic_i_jk),	/* OBP JavaStation-NC */	{ NULL, NULL, 0 }};/* * Only one PCIC per IIep, * and since we have no SMP IIep, only one per system. */static int pcic0_up = 0;static struct linux_pcic pcic0;unsigned int pcic_regs;volatile int pcic_speculative;volatile int pcic_trapped;static void pci_do_gettimeofday(struct timeval *tv);static void pci_do_settimeofday(struct timeval *tv);#define CONFIG_CMD(bus, device_fn, where) (0x80000000 | (((unsigned int)bus) << 16) | (((unsigned int)device_fn) << 8) | (where & ~3))static int pcic_read_config_dword(struct pci_dev *dev, int where, u32 *value);static int pcic_write_config_dword(struct pci_dev *dev, int where, u32 value);static int pcic_read_config_byte(struct pci_dev *dev, int where, u8 *value){	unsigned int v;	pcic_read_config_dword(dev, where&~3, &v);	*value = 0xff & (v >> (8*(where & 3)));	return PCIBIOS_SUCCESSFUL;}static int pcic_read_config_word(struct pci_dev *dev, int where, u16 *value){	unsigned int v;	if (where&1) return PCIBIOS_BAD_REGISTER_NUMBER;	pcic_read_config_dword(dev, where&~3, &v);	*value = 0xffff & (v >> (8*(where & 3)));	return PCIBIOS_SUCCESSFUL;}static int pcic_read_config_dword(struct pci_dev *dev, int where, u32 *value){	unsigned char bus = dev->bus->number;	unsigned char device_fn = dev->devfn;	/* unsigned char where; */	struct linux_pcic *pcic;	unsigned long flags;	if (where&3) return PCIBIOS_BAD_REGISTER_NUMBER;	if (bus != 0) return PCIBIOS_DEVICE_NOT_FOUND;	pcic = &pcic0;	save_and_cli(flags);#if 0 /* does not fail here */	pcic_speculative = 1;	pcic_trapped = 0;#endif	writel(CONFIG_CMD(bus,device_fn,where), pcic->pcic_config_space_addr);#if 0 /* does not fail here */	nop();	if (pcic_trapped) {		restore_flags(flags);		*value = ~0;		return PCIBIOS_SUCCESSFUL;	}#endif	pcic_speculative = 2;	pcic_trapped = 0;	*value = readl(pcic->pcic_config_space_data + (where&4));	nop();	if (pcic_trapped) {		pcic_speculative = 0;		restore_flags(flags);		*value = ~0;		return PCIBIOS_SUCCESSFUL;	}	pcic_speculative = 0;	restore_flags(flags);	return PCIBIOS_SUCCESSFUL;}static int pcic_write_config_byte(struct pci_dev *dev, int where, u8 value){	unsigned int v;	pcic_read_config_dword(dev, where&~3, &v);        v = (v & ~(0xff << (8*(where&3)))) |            ((0xff&(unsigned)value) << (8*(where&3)));	return pcic_write_config_dword(dev, where&~3, v);}static int pcic_write_config_word(struct pci_dev *dev, int where, u16 value){	unsigned int v;	if (where&1) return PCIBIOS_BAD_REGISTER_NUMBER;	pcic_read_config_dword(dev, where&~3, &v);	v = (v & ~(0xffff << (8*(where&3)))) |	    ((0xffff&(unsigned)value) << (8*(where&3)));	return pcic_write_config_dword(dev, where&~3, v);}static int pcic_write_config_dword(struct pci_dev *dev, int where, u32 value){	unsigned char bus = dev->bus->number;	unsigned char devfn = dev->devfn;	struct linux_pcic *pcic;	unsigned long flags;	if (where&3) return PCIBIOS_BAD_REGISTER_NUMBER;	if (bus != 0) return PCIBIOS_DEVICE_NOT_FOUND;	pcic = &pcic0;	save_and_cli(flags);	writel(CONFIG_CMD(bus,devfn,where), pcic->pcic_config_space_addr);	writel(value, pcic->pcic_config_space_data + (where&4));	restore_flags(flags);	return PCIBIOS_SUCCESSFUL;}static struct pci_ops pcic_ops = {	pcic_read_config_byte,	pcic_read_config_word,	pcic_read_config_dword,	pcic_write_config_byte,	pcic_write_config_word,	pcic_write_config_dword,};/* * On sparc64 pcibios_init() calls pci_controller_probe(). * We want PCIC probed little ahead so that interrupt controller * would be operational. */int __init pcic_probe(void){	struct linux_pcic *pcic;	struct linux_prom_registers regs[PROMREG_MAX];	struct linux_pbm_info* pbm;	char namebuf[64];	int node;	int err;	if (pcic0_up) {		prom_printf("PCIC: called twice!\n");		prom_halt();	}	pcic = &pcic0;	node = prom_getchild (prom_root_node);	node = prom_searchsiblings (node, "pci");	if (node == 0)		return -ENODEV;	/*	 * Map in PCIC register set, config space, and IO base	 */	err = prom_getproperty(node, "reg", (char*)regs, sizeof(regs));	if (err == 0 || err == -1) {		prom_printf("PCIC: Error, cannot get PCIC registers "			    "from PROM.\n");		prom_halt();	}	pcic0_up = 1;	pcic->pcic_res_regs.name = "pcic_registers";	pcic->pcic_regs = (unsigned long)	    ioremap(regs[0].phys_addr, regs[0].reg_size);	if (!pcic->pcic_regs) {		prom_printf("PCIC: Error, cannot map PCIC registers.\n");		prom_halt();	}	pcic->pcic_res_io.name = "pcic_io";	if ((pcic->pcic_io = (unsigned long)	    ioremap(regs[1].phys_addr, 0x10000)) == 0) {		prom_printf("PCIC: Error, cannot map PCIC IO Base.\n");		prom_halt();	}	pcic->pcic_res_cfg_addr.name = "pcic_cfg_addr";	if ((pcic->pcic_config_space_addr = (unsigned long)	    ioremap(regs[2].phys_addr, regs[2].reg_size * 2)) == 0) {		prom_printf("PCIC: Error, cannot map" 			    "PCI Configuration Space Address.\n");		prom_halt();	}	/*	 * Docs say three least significant bits in address and data	 * must be the same. Thus, we need adjust size of data.	 */	pcic->pcic_res_cfg_data.name = "pcic_cfg_data";	if ((pcic->pcic_config_space_data = (unsigned long)	    ioremap(regs[3].phys_addr, regs[3].reg_size * 2)) == 0) {		prom_printf("PCIC: Error, cannot map" 			    "PCI Configuration Space Data.\n");		prom_halt();	}	pbm = &pcic->pbm;	pbm->prom_node = node;	prom_getstring(node, "name", namebuf, 63);  namebuf[63] = 0;	strcpy(pbm->prom_name, namebuf);	{		extern volatile int t_nmi[1];		extern int pcic_nmi_trap_patch[1];		t_nmi[0] = pcic_nmi_trap_patch[0];		t_nmi[1] = pcic_nmi_trap_patch[1];		t_nmi[2] = pcic_nmi_trap_patch[2];		t_nmi[3] = pcic_nmi_trap_patch[3];		swift_flush_dcache();		pcic_regs = pcic->pcic_regs;	}	prom_getstring(prom_root_node, "name", namebuf, 63);  namebuf[63] = 0;	{		struct pcic_sn2list *p;		for (p = pcic_known_sysnames; p->sysname != NULL; p++) {			if (strcmp(namebuf, p->sysname) == 0)				break;		}		pcic->pcic_imap = p->intmap;		pcic->pcic_imdim = p->mapdim;	}	if (pcic->pcic_imap == NULL) {		/*		 * We do not panic here for the sake of embedded systems.		 */		printk("PCIC: System %s is unknown, cannot route interrupts\n",		    namebuf);	}	return 0;}static void __init pcic_pbm_scan_bus(struct linux_pcic *pcic){	struct linux_pbm_info *pbm = &pcic->pbm;	pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno, &pcic_ops, pbm);#if 0 /* deadwood transplanted from sparc64 */	pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);	pci_record_assignments(pbm, pbm->pci_bus);	pci_assign_unassigned(pbm, pbm->pci_bus);	pci_fixup_irq(pbm, pbm->pci_bus);#endif}/* * Main entry point from the PCI subsystem. */void __init pcibios_init(void){	struct linux_pcic *pcic;	/*	 * PCIC should be initialized at start of the timer.	 * So, here we report the presence of PCIC and do some magic passes.	 */	if(!pcic0_up)		return;	pcic = &pcic0;	/*	 *      Switch off IOTLB translation.	 */	writeb(PCI_DVMA_CONTROL_IOTLB_DISABLE, 	       pcic->pcic_regs+PCI_DVMA_CONTROL);	/*	 *      Increase mapped size for PCI memory space (DMA access).	 *      Should be done in that order (size first, address second).	 *      Why we couldn't set up 4GB and forget about it? XXX	 */	writel(0xF0000000UL, pcic->pcic_regs+PCI_SIZE_0);	writel(0+PCI_BASE_ADDRESS_SPACE_MEMORY, 	       pcic->pcic_regs+PCI_BASE_ADDRESS_0);	pcic_pbm_scan_bus(pcic);	ebus_init();#ifdef CONFIG_SUN_JSFLASH	jsflash_init();#endif}int pcic_present(void){	return pcic0_up;}static int __init pdev_to_pnode(struct linux_pbm_info *pbm, 				    struct pci_dev *pdev){	struct linux_prom_pci_registers regs[PROMREG_MAX];	int err;	int node = prom_getchild(pbm->prom_node);	while(node) {		err = prom_getproperty(node, "reg", 				       (char *)&regs[0], sizeof(regs));		if(err != 0 && err != -1) {			unsigned long devfn = (regs[0].which_io >> 8) & 0xff;			if(devfn == pdev->devfn)				return node;		}		node = prom_getsibling(node);	}	return 0;}static inline struct pcidev_cookie *pci_devcookie_alloc(void){	return kmalloc(sizeof(struct pcidev_cookie), GFP_ATOMIC);}static void pcic_map_pci_device(struct linux_pcic *pcic,    struct pci_dev *dev, int node){	char namebuf[64];	unsigned long address;	unsigned long flags;	int j;	if (node == 0 || node == -1) {		strcpy(namebuf, "???");	} else {		prom_getstring(node, "name", namebuf, 63); namebuf[63] = 0;	}	for (j = 0; j < 6; j++) {		address = dev->resource[j].start;		if (address == 0) break;	/* are sequential */		flags = dev->resource[j].flags;

⌨️ 快捷键说明

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