vserver 1.9.3
[linux-2.6.git] / arch / arm / mach-iop3xx / iq80321-pci.c
1 /*
2  * arch/arm/mach-iop3xx/iq80321-pci.c
3  *
4  * PCI support for the Intel IQ80321 reference board
5  *
6  * Author: Rory Bolt <rorybolt@pacbell.net>
7  * Copyright (C) 2002 Rory Bolt
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 #include <linux/kernel.h>
14 #include <linux/pci.h>
15 #include <linux/init.h>
16
17 #include <asm/hardware.h>
18 #include <asm/irq.h>
19 #include <asm/mach/pci.h>
20 #include <asm/mach-types.h>
21
22 /*
23  * The following macro is used to lookup irqs in a standard table
24  * format for those systems that do not already have PCI
25  * interrupts properly routed.  We assume 1 <= pin <= 4
26  */
27 #define PCI_IRQ_TABLE_LOOKUP(minid,maxid)       \
28 ({ int _ctl_ = -1;                              \
29    unsigned int _idsel = idsel - minid;         \
30    if (_idsel <= maxid)                         \
31       _ctl_ = pci_irq_table[_idsel][pin-1];     \
32    _ctl_; })
33
34 #define INTA    IRQ_IQ80321_INTA
35 #define INTB    IRQ_IQ80321_INTB
36 #define INTC    IRQ_IQ80321_INTC
37 #define INTD    IRQ_IQ80321_INTD
38
39 #define INTE    IRQ_IQ80321_I82544
40
41 static inline int __init
42 iq80321_map_irq(struct pci_dev *dev, u8 idsel, u8 pin)
43 {
44         static int pci_irq_table[][4] = {
45                 /*
46                  * PCI IDSEL/INTPIN->INTLINE
47                  * A       B       C       D
48                  */
49                 {INTE, INTE, INTE, INTE}, /* Gig-E */
50                 {-1, -1, -1, -1},         /* Unused */
51                 {INTC, INTD, INTA, INTB}, /* PCI-X Slot */
52                 {-1, -1, -1, -1},
53         };
54
55         BUG_ON(pin < 1 || pin > 4);
56
57 //      return PCI_IRQ_TABLE_LOOKUP(4, 7);
58         return pci_irq_table[idsel%4][pin-1];
59 }
60
61 static int iq80321_setup(int nr, struct pci_sys_data *sys)
62 {
63         struct resource *res;
64
65         if(nr != 0)
66                 return 0;
67
68         res = kmalloc(sizeof(struct resource) * 2, GFP_KERNEL);
69         if (!res)
70                 panic("PCI: unable to alloc resources");
71
72         memset(res, 0, sizeof(struct resource) * 2);
73
74         res[0].start = IQ80321_PCI_IO_BASE + IQ80321_PCI_IO_OFFSET;
75         res[0].end   = IQ80321_PCI_IO_BASE + IQ80321_PCI_IO_SIZE - 1 + IQ80321_PCI_IO_OFFSET;
76         res[0].name  = "IQ80321 PCI I/O Space";
77         res[0].flags = IORESOURCE_IO;
78
79         res[1].start = IQ80321_PCI_MEM_BASE;
80         res[1].end   = IQ80321_PCI_MEM_BASE + IQ80321_PCI_MEM_SIZE;
81         res[1].name  = "IQ80321 PCI Memory Space";
82         res[1].flags = IORESOURCE_MEM;
83
84         request_resource(&ioport_resource, &res[0]);
85         request_resource(&iomem_resource, &res[1]);
86
87         /*
88          * Since the IQ80321 is a slave card on a PCI backplane,
89          * it uses BAR1 to reserve a portion of PCI memory space for
90          * use with the private devices on the secondary bus
91          * (GigE and PCI-X slot). We read BAR1 and configure
92          * our outbound translation windows to target that
93          * address range and assign all devices in that
94          * address range. W/O this, certain BIOSes will fail
95          * to boot as the IQ80321 claims addresses that are
96          * in use by other devices.
97          *
98          * Note that the same cannot be done  with I/O space,
99          * so hopefully the host will stick to the lower 64K for
100          * PCI I/O and leave us alone.
101          */
102         sys->mem_offset = IQ80321_PCI_MEM_BASE -
103                 (*IOP321_IABAR1 & PCI_BASE_ADDRESS_MEM_MASK);
104
105         sys->resource[0] = &res[0];
106         sys->resource[1] = &res[1];
107         sys->resource[2] = NULL;
108         sys->io_offset   = IQ80321_PCI_IO_OFFSET;
109
110         iop3xx_pcibios_min_io = IQ80321_PCI_IO_BASE;
111         iop3xx_pcibios_min_mem = IQ80321_PCI_MEM_BASE;
112
113         return 1;
114 }
115
116 static void iq80321_preinit(void)
117 {
118         iop321_init();
119 }
120
121 static struct hw_pci iq80321_pci __initdata = {
122         .swizzle        = pci_std_swizzle,
123         .nr_controllers = 1,
124         .setup          = iq80321_setup,
125         .scan           = iop321_scan_bus,
126         .preinit        = iq80321_preinit,
127         .map_irq        = iq80321_map_irq
128 };
129
130 static int __init iq80321_pci_init(void)
131 {
132         if (machine_is_iq80321())
133                 pci_common_init(&iq80321_pci);
134         return 0;
135 }
136
137 subsys_initcall(iq80321_pci_init);
138
139
140
141