xref: /OK3568_Linux_fs/kernel/arch/mips/pci/pci-ip32.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
3*4882a593Smuzhiyun  * License.  See the file "COPYING" in the main directory of this archive
4*4882a593Smuzhiyun  * for more details.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2000, 2001 Keith M Wesolowski
7*4882a593Smuzhiyun  * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun #include <linux/kernel.h>
10*4882a593Smuzhiyun #include <linux/init.h>
11*4882a593Smuzhiyun #include <linux/interrupt.h>
12*4882a593Smuzhiyun #include <linux/pci.h>
13*4882a593Smuzhiyun #include <linux/types.h>
14*4882a593Smuzhiyun #include <asm/ip32/mace.h>
15*4882a593Smuzhiyun #include <asm/ip32/ip32_ints.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #undef DEBUG_MACE_PCI
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun /*
20*4882a593Smuzhiyun  * Handle errors from the bridge.  This includes master and target aborts,
21*4882a593Smuzhiyun  * various command and address errors, and the interrupt test.	This gets
22*4882a593Smuzhiyun  * registered on the bridge error irq.	It's conceivable that some of these
23*4882a593Smuzhiyun  * conditions warrant a panic.	Anybody care to say which ones?
24*4882a593Smuzhiyun  */
macepci_error(int irq,void * dev)25*4882a593Smuzhiyun static irqreturn_t macepci_error(int irq, void *dev)
26*4882a593Smuzhiyun {
27*4882a593Smuzhiyun 	char s;
28*4882a593Smuzhiyun 	unsigned int flags = mace->pci.error;
29*4882a593Smuzhiyun 	unsigned int addr = mace->pci.error_addr;
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_MEMORY_ADDR)
32*4882a593Smuzhiyun 		s = 'M';
33*4882a593Smuzhiyun 	else if (flags & MACEPCI_ERROR_CONFIG_ADDR)
34*4882a593Smuzhiyun 		s = 'C';
35*4882a593Smuzhiyun 	else
36*4882a593Smuzhiyun 		s = 'X';
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_MASTER_ABORT) {
39*4882a593Smuzhiyun 		printk("MACEPCI: Master abort at 0x%08x (%c)\n", addr, s);
40*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_MASTER_ABORT;
41*4882a593Smuzhiyun 	}
42*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_TARGET_ABORT) {
43*4882a593Smuzhiyun 		printk("MACEPCI: Target abort at 0x%08x (%c)\n", addr, s);
44*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_TARGET_ABORT;
45*4882a593Smuzhiyun 	}
46*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_DATA_PARITY_ERR) {
47*4882a593Smuzhiyun 		printk("MACEPCI: Data parity error at 0x%08x (%c)\n", addr, s);
48*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_DATA_PARITY_ERR;
49*4882a593Smuzhiyun 	}
50*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_RETRY_ERR) {
51*4882a593Smuzhiyun 		printk("MACEPCI: Retry error at 0x%08x (%c)\n", addr, s);
52*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_RETRY_ERR;
53*4882a593Smuzhiyun 	}
54*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_ILLEGAL_CMD) {
55*4882a593Smuzhiyun 		printk("MACEPCI: Illegal command at 0x%08x (%c)\n", addr, s);
56*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_ILLEGAL_CMD;
57*4882a593Smuzhiyun 	}
58*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_SYSTEM_ERR) {
59*4882a593Smuzhiyun 		printk("MACEPCI: System error at 0x%08x (%c)\n", addr, s);
60*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_SYSTEM_ERR;
61*4882a593Smuzhiyun 	}
62*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_PARITY_ERR) {
63*4882a593Smuzhiyun 		printk("MACEPCI: Parity error at 0x%08x (%c)\n", addr, s);
64*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_PARITY_ERR;
65*4882a593Smuzhiyun 	}
66*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_OVERRUN) {
67*4882a593Smuzhiyun 		printk("MACEPCI: Overrun error at 0x%08x (%c)\n", addr, s);
68*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_OVERRUN;
69*4882a593Smuzhiyun 	}
70*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_SIG_TABORT) {
71*4882a593Smuzhiyun 		printk("MACEPCI: Signaled target abort (clearing)\n");
72*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_SIG_TABORT;
73*4882a593Smuzhiyun 	}
74*4882a593Smuzhiyun 	if (flags & MACEPCI_ERROR_INTERRUPT_TEST) {
75*4882a593Smuzhiyun 		printk("MACEPCI: Interrupt test triggered (clearing)\n");
76*4882a593Smuzhiyun 		flags &= ~MACEPCI_ERROR_INTERRUPT_TEST;
77*4882a593Smuzhiyun 	}
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	mace->pci.error = flags;
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	return IRQ_HANDLED;
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun extern struct pci_ops mace_pci_ops;
86*4882a593Smuzhiyun #ifdef CONFIG_64BIT
87*4882a593Smuzhiyun static struct resource mace_pci_mem_resource = {
88*4882a593Smuzhiyun 	.name	= "SGI O2 PCI MEM",
89*4882a593Smuzhiyun 	.start	= MACEPCI_HI_MEMORY,
90*4882a593Smuzhiyun 	.end	= 0x2FFFFFFFFUL,
91*4882a593Smuzhiyun 	.flags	= IORESOURCE_MEM,
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun static struct resource mace_pci_io_resource = {
94*4882a593Smuzhiyun 	.name	= "SGI O2 PCI IO",
95*4882a593Smuzhiyun 	.start	= 0x00000000UL,
96*4882a593Smuzhiyun 	.end	= 0xffffffffUL,
97*4882a593Smuzhiyun 	.flags	= IORESOURCE_IO,
98*4882a593Smuzhiyun };
99*4882a593Smuzhiyun #define MACE_PCI_MEM_OFFSET 0x200000000
100*4882a593Smuzhiyun #else
101*4882a593Smuzhiyun static struct resource mace_pci_mem_resource = {
102*4882a593Smuzhiyun 	.name	= "SGI O2 PCI MEM",
103*4882a593Smuzhiyun 	.start	= MACEPCI_LOW_MEMORY,
104*4882a593Smuzhiyun 	.end	= MACEPCI_LOW_MEMORY + 0x2000000 - 1,
105*4882a593Smuzhiyun 	.flags	= IORESOURCE_MEM,
106*4882a593Smuzhiyun };
107*4882a593Smuzhiyun static struct resource mace_pci_io_resource = {
108*4882a593Smuzhiyun 	.name	= "SGI O2 PCI IO",
109*4882a593Smuzhiyun 	.start	= 0x00000000,
110*4882a593Smuzhiyun 	.end	= 0xFFFFFFFF,
111*4882a593Smuzhiyun 	.flags	= IORESOURCE_IO,
112*4882a593Smuzhiyun };
113*4882a593Smuzhiyun #define MACE_PCI_MEM_OFFSET (MACEPCI_LOW_MEMORY - 0x80000000)
114*4882a593Smuzhiyun #endif
115*4882a593Smuzhiyun static struct pci_controller mace_pci_controller = {
116*4882a593Smuzhiyun 	.pci_ops	= &mace_pci_ops,
117*4882a593Smuzhiyun 	.mem_resource	= &mace_pci_mem_resource,
118*4882a593Smuzhiyun 	.io_resource	= &mace_pci_io_resource,
119*4882a593Smuzhiyun 	.mem_offset	= MACE_PCI_MEM_OFFSET,
120*4882a593Smuzhiyun 	.io_offset	= 0,
121*4882a593Smuzhiyun 	.io_map_base	= CKSEG1ADDR(MACEPCI_LOW_IO),
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun 
mace_init(void)124*4882a593Smuzhiyun static int __init mace_init(void)
125*4882a593Smuzhiyun {
126*4882a593Smuzhiyun 	PCIBIOS_MIN_IO = 0x1000;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	/* Clear any outstanding errors and enable interrupts */
129*4882a593Smuzhiyun 	mace->pci.error_addr = 0;
130*4882a593Smuzhiyun 	mace->pci.error = 0;
131*4882a593Smuzhiyun 	mace->pci.control = 0xff008500;
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	printk("MACE PCI rev %d\n", mace->pci.rev);
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	BUG_ON(request_irq(MACE_PCI_BRIDGE_IRQ, macepci_error, 0,
136*4882a593Smuzhiyun 			   "MACE PCI error", NULL));
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 	/* extend memory resources */
139*4882a593Smuzhiyun 	iomem_resource.end = mace_pci_mem_resource.end;
140*4882a593Smuzhiyun 	ioport_resource = mace_pci_io_resource;
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun 	register_pci_controller(&mace_pci_controller);
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	return 0;
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun arch_initcall(mace_init);
148