diff options
author | Jayachandran C <jayachandranc@netlogicmicro.com> | 2011-05-06 16:07:31 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2011-05-19 04:55:41 -0400 |
commit | 9b130f8004e51c65b20b0f0e17cdee073a719047 (patch) | |
tree | 3562752ebe2168361a09dd16baace9b6884672d8 /arch/mips | |
parent | f9cab74fd9b0cf19f52a989694e7a1d8213af3a1 (diff) |
MIPS: XLR, XLS: Add PCI support.
Adds pci/pci-xlr.c to support for XLR PCI/PCI-X interface and XLS PCIe
interface.
Update irq.c to ack PCI interrupts, use irq handler data to do the
PCI/PCIe bus ack.
Signed-off-by: Jayachandran C <jayachandranc@netlogicmicro.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/2337/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/include/asm/netlogic/xlr/xlr.h | 21 | ||||
-rw-r--r-- | arch/mips/netlogic/xlr/irq.c | 86 | ||||
-rw-r--r-- | arch/mips/pci/Makefile | 1 | ||||
-rw-r--r-- | arch/mips/pci/pci-xlr.c | 214 |
4 files changed, 321 insertions, 1 deletions
diff --git a/arch/mips/include/asm/netlogic/xlr/xlr.h b/arch/mips/include/asm/netlogic/xlr/xlr.h index 454c236d6854..3e6372692a04 100644 --- a/arch/mips/include/asm/netlogic/xlr/xlr.h +++ b/arch/mips/include/asm/netlogic/xlr/xlr.h | |||
@@ -41,6 +41,7 @@ unsigned int nlm_xlr_uart_in(struct uart_port *, int); | |||
41 | void nlm_xlr_uart_out(struct uart_port *, int, int); | 41 | void nlm_xlr_uart_out(struct uart_port *, int, int); |
42 | 42 | ||
43 | /* SMP support functions */ | 43 | /* SMP support functions */ |
44 | struct irq_desc; | ||
44 | void nlm_smp_function_ipi_handler(unsigned int irq, struct irq_desc *desc); | 45 | void nlm_smp_function_ipi_handler(unsigned int irq, struct irq_desc *desc); |
45 | void nlm_smp_resched_ipi_handler(unsigned int irq, struct irq_desc *desc); | 46 | void nlm_smp_resched_ipi_handler(unsigned int irq, struct irq_desc *desc); |
46 | int nlm_wakeup_secondary_cpus(u32 wakeup_mask); | 47 | int nlm_wakeup_secondary_cpus(u32 wakeup_mask); |
@@ -51,4 +52,24 @@ void prom_pre_boot_secondary_cpus(void); | |||
51 | extern struct plat_smp_ops nlm_smp_ops; | 52 | extern struct plat_smp_ops nlm_smp_ops; |
52 | extern unsigned long nlm_common_ebase; | 53 | extern unsigned long nlm_common_ebase; |
53 | 54 | ||
55 | /* XLS B silicon "Rook" */ | ||
56 | static inline unsigned int nlm_chip_is_xls_b(void) | ||
57 | { | ||
58 | uint32_t prid = read_c0_prid(); | ||
59 | |||
60 | return ((prid & 0xf000) == 0x4000); | ||
61 | } | ||
62 | |||
63 | /* | ||
64 | * XLR chip types | ||
65 | */ | ||
66 | /* The XLS product line has chip versions 0x[48c]? */ | ||
67 | static inline unsigned int nlm_chip_is_xls(void) | ||
68 | { | ||
69 | uint32_t prid = read_c0_prid(); | ||
70 | |||
71 | return ((prid & 0xf000) == 0x8000 || (prid & 0xf000) == 0x4000 || | ||
72 | (prid & 0xf000) == 0xc000); | ||
73 | } | ||
74 | |||
54 | #endif /* _ASM_NLM_XLR_H */ | 75 | #endif /* _ASM_NLM_XLR_H */ |
diff --git a/arch/mips/netlogic/xlr/irq.c b/arch/mips/netlogic/xlr/irq.c index 2033f5656f68..1446d58e364c 100644 --- a/arch/mips/netlogic/xlr/irq.c +++ b/arch/mips/netlogic/xlr/irq.c | |||
@@ -83,14 +83,71 @@ static void xlr_pic_mask(struct irq_data *d) | |||
83 | spin_unlock_irqrestore(&nlm_pic_lock, flags); | 83 | spin_unlock_irqrestore(&nlm_pic_lock, flags); |
84 | } | 84 | } |
85 | 85 | ||
86 | #ifdef CONFIG_PCI | ||
87 | /* Extra ACK needed for XLR on chip PCI controller */ | ||
88 | static void xlr_pci_ack(struct irq_data *d) | ||
89 | { | ||
90 | nlm_reg_t *pci_mmio = netlogic_io_mmio(NETLOGIC_IO_PCIX_OFFSET); | ||
91 | |||
92 | netlogic_read_reg(pci_mmio, (0x140 >> 2)); | ||
93 | } | ||
94 | |||
95 | /* Extra ACK needed for XLS on chip PCIe controller */ | ||
96 | static void xls_pcie_ack(struct irq_data *d) | ||
97 | { | ||
98 | nlm_reg_t *pcie_mmio_le = netlogic_io_mmio(NETLOGIC_IO_PCIE_1_OFFSET); | ||
99 | |||
100 | switch (d->irq) { | ||
101 | case PIC_PCIE_LINK0_IRQ: | ||
102 | netlogic_write_reg(pcie_mmio_le, (0x90 >> 2), 0xffffffff); | ||
103 | break; | ||
104 | case PIC_PCIE_LINK1_IRQ: | ||
105 | netlogic_write_reg(pcie_mmio_le, (0x94 >> 2), 0xffffffff); | ||
106 | break; | ||
107 | case PIC_PCIE_LINK2_IRQ: | ||
108 | netlogic_write_reg(pcie_mmio_le, (0x190 >> 2), 0xffffffff); | ||
109 | break; | ||
110 | case PIC_PCIE_LINK3_IRQ: | ||
111 | netlogic_write_reg(pcie_mmio_le, (0x194 >> 2), 0xffffffff); | ||
112 | break; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | /* For XLS B silicon, the 3,4 PCI interrupts are different */ | ||
117 | static void xls_pcie_ack_b(struct irq_data *d) | ||
118 | { | ||
119 | nlm_reg_t *pcie_mmio_le = netlogic_io_mmio(NETLOGIC_IO_PCIE_1_OFFSET); | ||
120 | |||
121 | switch (d->irq) { | ||
122 | case PIC_PCIE_LINK0_IRQ: | ||
123 | netlogic_write_reg(pcie_mmio_le, (0x90 >> 2), 0xffffffff); | ||
124 | break; | ||
125 | case PIC_PCIE_LINK1_IRQ: | ||
126 | netlogic_write_reg(pcie_mmio_le, (0x94 >> 2), 0xffffffff); | ||
127 | break; | ||
128 | case PIC_PCIE_XLSB0_LINK2_IRQ: | ||
129 | netlogic_write_reg(pcie_mmio_le, (0x190 >> 2), 0xffffffff); | ||
130 | break; | ||
131 | case PIC_PCIE_XLSB0_LINK3_IRQ: | ||
132 | netlogic_write_reg(pcie_mmio_le, (0x194 >> 2), 0xffffffff); | ||
133 | break; | ||
134 | } | ||
135 | } | ||
136 | #endif | ||
137 | |||
86 | static void xlr_pic_ack(struct irq_data *d) | 138 | static void xlr_pic_ack(struct irq_data *d) |
87 | { | 139 | { |
88 | unsigned long flags; | 140 | unsigned long flags; |
89 | nlm_reg_t *mmio; | 141 | nlm_reg_t *mmio; |
90 | int irq = d->irq; | 142 | int irq = d->irq; |
143 | void *hd = irq_data_get_irq_handler_data(d); | ||
91 | 144 | ||
92 | WARN(!PIC_IRQ_IS_IRT(irq), "Bad irq %d", irq); | 145 | WARN(!PIC_IRQ_IS_IRT(irq), "Bad irq %d", irq); |
93 | 146 | ||
147 | if (hd) { | ||
148 | void (*extra_ack)(void *) = hd; | ||
149 | extra_ack(d); | ||
150 | } | ||
94 | mmio = netlogic_io_mmio(NETLOGIC_IO_PIC_OFFSET); | 151 | mmio = netlogic_io_mmio(NETLOGIC_IO_PIC_OFFSET); |
95 | spin_lock_irqsave(&nlm_pic_lock, flags); | 152 | spin_lock_irqsave(&nlm_pic_lock, flags); |
96 | netlogic_write_reg(mmio, PIC_INT_ACK, (1 << (irq - PIC_IRQ_BASE))); | 153 | netlogic_write_reg(mmio, PIC_INT_ACK, (1 << (irq - PIC_IRQ_BASE))); |
@@ -162,6 +219,33 @@ void __init init_xlr_irqs(void) | |||
162 | nlm_irq_mask |= | 219 | nlm_irq_mask |= |
163 | ((1ULL << IRQ_IPI_SMP_FUNCTION) | (1ULL << IRQ_IPI_SMP_RESCHEDULE)); | 220 | ((1ULL << IRQ_IPI_SMP_FUNCTION) | (1ULL << IRQ_IPI_SMP_RESCHEDULE)); |
164 | #endif | 221 | #endif |
222 | |||
223 | #ifdef CONFIG_PCI | ||
224 | /* | ||
225 | * For PCI interrupts, we need to ack the PIC controller too, overload | ||
226 | * irq handler data to do this | ||
227 | */ | ||
228 | if (nlm_chip_is_xls()) { | ||
229 | if (nlm_chip_is_xls_b()) { | ||
230 | irq_set_handler_data(PIC_PCIE_LINK0_IRQ, | ||
231 | xls_pcie_ack_b); | ||
232 | irq_set_handler_data(PIC_PCIE_LINK1_IRQ, | ||
233 | xls_pcie_ack_b); | ||
234 | irq_set_handler_data(PIC_PCIE_XLSB0_LINK2_IRQ, | ||
235 | xls_pcie_ack_b); | ||
236 | irq_set_handler_data(PIC_PCIE_XLSB0_LINK3_IRQ, | ||
237 | xls_pcie_ack_b); | ||
238 | } else { | ||
239 | irq_set_handler_data(PIC_PCIE_LINK0_IRQ, xls_pcie_ack); | ||
240 | irq_set_handler_data(PIC_PCIE_LINK1_IRQ, xls_pcie_ack); | ||
241 | irq_set_handler_data(PIC_PCIE_LINK2_IRQ, xls_pcie_ack); | ||
242 | irq_set_handler_data(PIC_PCIE_LINK3_IRQ, xls_pcie_ack); | ||
243 | } | ||
244 | } else { | ||
245 | /* XLR PCI controller ACK */ | ||
246 | irq_set_handler_data(PIC_PCIE_XLSB0_LINK3_IRQ, xlr_pci_ack); | ||
247 | } | ||
248 | #endif | ||
165 | /* unmask all PIC related interrupts. If no handler is installed by the | 249 | /* unmask all PIC related interrupts. If no handler is installed by the |
166 | * drivers, it'll just ack the interrupt and return | 250 | * drivers, it'll just ack the interrupt and return |
167 | */ | 251 | */ |
@@ -199,7 +283,7 @@ asmlinkage void plat_irq_dispatch(void) | |||
199 | return; | 283 | return; |
200 | } | 284 | } |
201 | 285 | ||
202 | /* TODO use dcltz: optimize below code */ | 286 | /* use dcltz: optimize below code */ |
203 | for (i = 63; i != -1; i--) { | 287 | for (i = 63; i != -1; i--) { |
204 | if (eirr & (1ULL << i)) | 288 | if (eirr & (1ULL << i)) |
205 | break; | 289 | break; |
diff --git a/arch/mips/pci/Makefile b/arch/mips/pci/Makefile index c9209ca6c8e7..f0d5329289d1 100644 --- a/arch/mips/pci/Makefile +++ b/arch/mips/pci/Makefile | |||
@@ -55,6 +55,7 @@ obj-$(CONFIG_ZAO_CAPCELLA) += fixup-capcella.o | |||
55 | obj-$(CONFIG_WR_PPMC) += fixup-wrppmc.o | 55 | obj-$(CONFIG_WR_PPMC) += fixup-wrppmc.o |
56 | obj-$(CONFIG_MIKROTIK_RB532) += pci-rc32434.o ops-rc32434.o fixup-rc32434.o | 56 | obj-$(CONFIG_MIKROTIK_RB532) += pci-rc32434.o ops-rc32434.o fixup-rc32434.o |
57 | obj-$(CONFIG_CPU_CAVIUM_OCTEON) += pci-octeon.o pcie-octeon.o | 57 | obj-$(CONFIG_CPU_CAVIUM_OCTEON) += pci-octeon.o pcie-octeon.o |
58 | obj-$(CONFIG_NLM_XLR) += pci-xlr.o | ||
58 | 59 | ||
59 | ifdef CONFIG_PCI_MSI | 60 | ifdef CONFIG_PCI_MSI |
60 | obj-$(CONFIG_CPU_CAVIUM_OCTEON) += msi-octeon.o | 61 | obj-$(CONFIG_CPU_CAVIUM_OCTEON) += msi-octeon.o |
diff --git a/arch/mips/pci/pci-xlr.c b/arch/mips/pci/pci-xlr.c new file mode 100644 index 000000000000..38fece16c435 --- /dev/null +++ b/arch/mips/pci/pci-xlr.c | |||
@@ -0,0 +1,214 @@ | |||
1 | /* | ||
2 | * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights | ||
3 | * reserved. | ||
4 | * | ||
5 | * This software is available to you under a choice of one of two | ||
6 | * licenses. You may choose to be licensed under the terms of the GNU | ||
7 | * General Public License (GPL) Version 2, available from the file | ||
8 | * COPYING in the main directory of this source tree, or the NetLogic | ||
9 | * license below: | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * | ||
15 | * 1. Redistributions of source code must retain the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer. | ||
17 | * 2. Redistributions in binary form must reproduce the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer in | ||
19 | * the documentation and/or other materials provided with the | ||
20 | * distribution. | ||
21 | * | ||
22 | * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR | ||
23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE | ||
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
32 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | #include <linux/types.h> | ||
36 | #include <linux/pci.h> | ||
37 | #include <linux/kernel.h> | ||
38 | #include <linux/init.h> | ||
39 | #include <linux/mm.h> | ||
40 | #include <linux/console.h> | ||
41 | |||
42 | #include <asm/io.h> | ||
43 | |||
44 | #include <asm/netlogic/interrupt.h> | ||
45 | #include <asm/netlogic/xlr/iomap.h> | ||
46 | #include <asm/netlogic/xlr/pic.h> | ||
47 | #include <asm/netlogic/xlr/xlr.h> | ||
48 | |||
49 | static void *pci_config_base; | ||
50 | |||
51 | #define pci_cfg_addr(bus, devfn, off) (((bus) << 16) | ((devfn) << 8) | (off)) | ||
52 | |||
53 | /* PCI ops */ | ||
54 | static inline u32 pci_cfg_read_32bit(struct pci_bus *bus, unsigned int devfn, | ||
55 | int where) | ||
56 | { | ||
57 | u32 data; | ||
58 | u32 *cfgaddr; | ||
59 | |||
60 | cfgaddr = (u32 *)(pci_config_base + | ||
61 | pci_cfg_addr(bus->number, devfn, where & ~3)); | ||
62 | data = *cfgaddr; | ||
63 | return cpu_to_le32(data); | ||
64 | } | ||
65 | |||
66 | static inline void pci_cfg_write_32bit(struct pci_bus *bus, unsigned int devfn, | ||
67 | int where, u32 data) | ||
68 | { | ||
69 | u32 *cfgaddr; | ||
70 | |||
71 | cfgaddr = (u32 *)(pci_config_base + | ||
72 | pci_cfg_addr(bus->number, devfn, where & ~3)); | ||
73 | *cfgaddr = cpu_to_le32(data); | ||
74 | } | ||
75 | |||
76 | static int nlm_pcibios_read(struct pci_bus *bus, unsigned int devfn, | ||
77 | int where, int size, u32 *val) | ||
78 | { | ||
79 | u32 data; | ||
80 | |||
81 | if ((size == 2) && (where & 1)) | ||
82 | return PCIBIOS_BAD_REGISTER_NUMBER; | ||
83 | else if ((size == 4) && (where & 3)) | ||
84 | return PCIBIOS_BAD_REGISTER_NUMBER; | ||
85 | |||
86 | data = pci_cfg_read_32bit(bus, devfn, where); | ||
87 | |||
88 | if (size == 1) | ||
89 | *val = (data >> ((where & 3) << 3)) & 0xff; | ||
90 | else if (size == 2) | ||
91 | *val = (data >> ((where & 3) << 3)) & 0xffff; | ||
92 | else | ||
93 | *val = data; | ||
94 | |||
95 | return PCIBIOS_SUCCESSFUL; | ||
96 | } | ||
97 | |||
98 | |||
99 | static int nlm_pcibios_write(struct pci_bus *bus, unsigned int devfn, | ||
100 | int where, int size, u32 val) | ||
101 | { | ||
102 | u32 data; | ||
103 | |||
104 | if ((size == 2) && (where & 1)) | ||
105 | return PCIBIOS_BAD_REGISTER_NUMBER; | ||
106 | else if ((size == 4) && (where & 3)) | ||
107 | return PCIBIOS_BAD_REGISTER_NUMBER; | ||
108 | |||
109 | data = pci_cfg_read_32bit(bus, devfn, where); | ||
110 | |||
111 | if (size == 1) | ||
112 | data = (data & ~(0xff << ((where & 3) << 3))) | | ||
113 | (val << ((where & 3) << 3)); | ||
114 | else if (size == 2) | ||
115 | data = (data & ~(0xffff << ((where & 3) << 3))) | | ||
116 | (val << ((where & 3) << 3)); | ||
117 | else | ||
118 | data = val; | ||
119 | |||
120 | pci_cfg_write_32bit(bus, devfn, where, data); | ||
121 | |||
122 | return PCIBIOS_SUCCESSFUL; | ||
123 | } | ||
124 | |||
125 | struct pci_ops nlm_pci_ops = { | ||
126 | .read = nlm_pcibios_read, | ||
127 | .write = nlm_pcibios_write | ||
128 | }; | ||
129 | |||
130 | static struct resource nlm_pci_mem_resource = { | ||
131 | .name = "XLR PCI MEM", | ||
132 | .start = 0xd0000000UL, /* 256MB PCI mem @ 0xd000_0000 */ | ||
133 | .end = 0xdfffffffUL, | ||
134 | .flags = IORESOURCE_MEM, | ||
135 | }; | ||
136 | |||
137 | static struct resource nlm_pci_io_resource = { | ||
138 | .name = "XLR IO MEM", | ||
139 | .start = 0x10000000UL, /* 16MB PCI IO @ 0x1000_0000 */ | ||
140 | .end = 0x100fffffUL, | ||
141 | .flags = IORESOURCE_IO, | ||
142 | }; | ||
143 | |||
144 | struct pci_controller nlm_pci_controller = { | ||
145 | .index = 0, | ||
146 | .pci_ops = &nlm_pci_ops, | ||
147 | .mem_resource = &nlm_pci_mem_resource, | ||
148 | .mem_offset = 0x00000000UL, | ||
149 | .io_resource = &nlm_pci_io_resource, | ||
150 | .io_offset = 0x00000000UL, | ||
151 | }; | ||
152 | |||
153 | int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) | ||
154 | { | ||
155 | if (!nlm_chip_is_xls()) | ||
156 | return PIC_PCIX_IRQ; /* for XLR just one IRQ*/ | ||
157 | |||
158 | /* | ||
159 | * For XLS PCIe, there is an IRQ per Link, find out which | ||
160 | * link the device is on to assign interrupts | ||
161 | */ | ||
162 | if (dev->bus->self == NULL) | ||
163 | return 0; | ||
164 | |||
165 | switch (dev->bus->self->devfn) { | ||
166 | case 0x0: | ||
167 | return PIC_PCIE_LINK0_IRQ; | ||
168 | case 0x8: | ||
169 | return PIC_PCIE_LINK1_IRQ; | ||
170 | case 0x10: | ||
171 | if (nlm_chip_is_xls_b()) | ||
172 | return PIC_PCIE_XLSB0_LINK2_IRQ; | ||
173 | else | ||
174 | return PIC_PCIE_LINK2_IRQ; | ||
175 | case 0x18: | ||
176 | if (nlm_chip_is_xls_b()) | ||
177 | return PIC_PCIE_XLSB0_LINK3_IRQ; | ||
178 | else | ||
179 | return PIC_PCIE_LINK3_IRQ; | ||
180 | } | ||
181 | WARN(1, "Unexpected devfn %d\n", dev->bus->self->devfn); | ||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | /* Do platform specific device initialization at pci_enable_device() time */ | ||
186 | int pcibios_plat_dev_init(struct pci_dev *dev) | ||
187 | { | ||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | static int __init pcibios_init(void) | ||
192 | { | ||
193 | /* PSB assigns PCI resources */ | ||
194 | pci_probe_only = 1; | ||
195 | pci_config_base = ioremap(DEFAULT_PCI_CONFIG_BASE, 16 << 20); | ||
196 | |||
197 | /* Extend IO port for memory mapped io */ | ||
198 | ioport_resource.start = 0; | ||
199 | ioport_resource.end = ~0; | ||
200 | |||
201 | set_io_port_base(CKSEG1); | ||
202 | nlm_pci_controller.io_map_base = CKSEG1; | ||
203 | |||
204 | pr_info("Registering XLR/XLS PCIX/PCIE Controller.\n"); | ||
205 | register_pci_controller(&nlm_pci_controller); | ||
206 | |||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | arch_initcall(pcibios_init); | ||
211 | |||
212 | struct pci_fixup pcibios_fixups[] = { | ||
213 | {0} | ||
214 | }; | ||