aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/pci
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2013-02-21 06:51:33 -0500
committerRalf Baechle <ralf@linux-mips.org>2013-02-21 06:51:33 -0500
commit8bfc245f9ad7bd4e461179e4e7852ef99b8b6144 (patch)
tree0ad091f645fbc8318634599d278966a53d3922ee /arch/mips/pci
parent612663a974065c3445e641d046769fe4c55a6438 (diff)
parent535237cecab2b078114be712c67e89a0db61965f (diff)
Merge branch 'mips-next-3.9' of git://git.linux-mips.org/pub/scm/john/linux-john into mips-for-linux-next
Diffstat (limited to 'arch/mips/pci')
-rw-r--r--arch/mips/pci/pci-ar71xx.c194
-rw-r--r--arch/mips/pci/pci-ar724x.c304
-rw-r--r--arch/mips/pci/pci-lantiq.c12
-rw-r--r--arch/mips/pci/pci-xlp.c124
-rw-r--r--arch/mips/pci/pci.c15
5 files changed, 445 insertions, 204 deletions
diff --git a/arch/mips/pci/pci-ar71xx.c b/arch/mips/pci/pci-ar71xx.c
index 6eaa4f2d0e38..412ec025cf55 100644
--- a/arch/mips/pci/pci-ar71xx.c
+++ b/arch/mips/pci/pci-ar71xx.c
@@ -18,26 +18,11 @@
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <linux/pci_regs.h> 19#include <linux/pci_regs.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/module.h>
22#include <linux/platform_device.h>
21 23
22#include <asm/mach-ath79/ar71xx_regs.h> 24#include <asm/mach-ath79/ar71xx_regs.h>
23#include <asm/mach-ath79/ath79.h> 25#include <asm/mach-ath79/ath79.h>
24#include <asm/mach-ath79/pci.h>
25
26#define AR71XX_PCI_MEM_BASE 0x10000000
27#define AR71XX_PCI_MEM_SIZE 0x07000000
28
29#define AR71XX_PCI_WIN0_OFFS 0x10000000
30#define AR71XX_PCI_WIN1_OFFS 0x11000000
31#define AR71XX_PCI_WIN2_OFFS 0x12000000
32#define AR71XX_PCI_WIN3_OFFS 0x13000000
33#define AR71XX_PCI_WIN4_OFFS 0x14000000
34#define AR71XX_PCI_WIN5_OFFS 0x15000000
35#define AR71XX_PCI_WIN6_OFFS 0x16000000
36#define AR71XX_PCI_WIN7_OFFS 0x07000000
37
38#define AR71XX_PCI_CFG_BASE \
39 (AR71XX_PCI_MEM_BASE + AR71XX_PCI_WIN7_OFFS + 0x10000)
40#define AR71XX_PCI_CFG_SIZE 0x100
41 26
42#define AR71XX_PCI_REG_CRP_AD_CBE 0x00 27#define AR71XX_PCI_REG_CRP_AD_CBE 0x00
43#define AR71XX_PCI_REG_CRP_WRDATA 0x04 28#define AR71XX_PCI_REG_CRP_WRDATA 0x04
@@ -63,8 +48,15 @@
63 48
64#define AR71XX_PCI_IRQ_COUNT 5 49#define AR71XX_PCI_IRQ_COUNT 5
65 50
66static DEFINE_SPINLOCK(ar71xx_pci_lock); 51struct ar71xx_pci_controller {
67static void __iomem *ar71xx_pcicfg_base; 52 void __iomem *cfg_base;
53 spinlock_t lock;
54 int irq;
55 int irq_base;
56 struct pci_controller pci_ctrl;
57 struct resource io_res;
58 struct resource mem_res;
59};
68 60
69/* Byte lane enable bits */ 61/* Byte lane enable bits */
70static const u8 ar71xx_pci_ble_table[4][4] = { 62static const u8 ar71xx_pci_ble_table[4][4] = {
@@ -107,9 +99,18 @@ static inline u32 ar71xx_pci_bus_addr(struct pci_bus *bus, unsigned int devfn,
107 return ret; 99 return ret;
108} 100}
109 101
110static int ar71xx_pci_check_error(int quiet) 102static inline struct ar71xx_pci_controller *
103pci_bus_to_ar71xx_controller(struct pci_bus *bus)
111{ 104{
112 void __iomem *base = ar71xx_pcicfg_base; 105 struct pci_controller *hose;
106
107 hose = (struct pci_controller *) bus->sysdata;
108 return container_of(hose, struct ar71xx_pci_controller, pci_ctrl);
109}
110
111static int ar71xx_pci_check_error(struct ar71xx_pci_controller *apc, int quiet)
112{
113 void __iomem *base = apc->cfg_base;
113 u32 pci_err; 114 u32 pci_err;
114 u32 ahb_err; 115 u32 ahb_err;
115 116
@@ -144,9 +145,10 @@ static int ar71xx_pci_check_error(int quiet)
144 return !!(ahb_err | pci_err); 145 return !!(ahb_err | pci_err);
145} 146}
146 147
147static inline void ar71xx_pci_local_write(int where, int size, u32 value) 148static inline void ar71xx_pci_local_write(struct ar71xx_pci_controller *apc,
149 int where, int size, u32 value)
148{ 150{
149 void __iomem *base = ar71xx_pcicfg_base; 151 void __iomem *base = apc->cfg_base;
150 u32 ad_cbe; 152 u32 ad_cbe;
151 153
152 value = value << (8 * (where & 3)); 154 value = value << (8 * (where & 3));
@@ -162,7 +164,8 @@ static inline int ar71xx_pci_set_cfgaddr(struct pci_bus *bus,
162 unsigned int devfn, 164 unsigned int devfn,
163 int where, int size, u32 cmd) 165 int where, int size, u32 cmd)
164{ 166{
165 void __iomem *base = ar71xx_pcicfg_base; 167 struct ar71xx_pci_controller *apc = pci_bus_to_ar71xx_controller(bus);
168 void __iomem *base = apc->cfg_base;
166 u32 addr; 169 u32 addr;
167 170
168 addr = ar71xx_pci_bus_addr(bus, devfn, where); 171 addr = ar71xx_pci_bus_addr(bus, devfn, where);
@@ -171,13 +174,14 @@ static inline int ar71xx_pci_set_cfgaddr(struct pci_bus *bus,
171 __raw_writel(cmd | ar71xx_pci_get_ble(where, size, 0), 174 __raw_writel(cmd | ar71xx_pci_get_ble(where, size, 0),
172 base + AR71XX_PCI_REG_CFG_CBE); 175 base + AR71XX_PCI_REG_CFG_CBE);
173 176
174 return ar71xx_pci_check_error(1); 177 return ar71xx_pci_check_error(apc, 1);
175} 178}
176 179
177static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn, 180static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
178 int where, int size, u32 *value) 181 int where, int size, u32 *value)
179{ 182{
180 void __iomem *base = ar71xx_pcicfg_base; 183 struct ar71xx_pci_controller *apc = pci_bus_to_ar71xx_controller(bus);
184 void __iomem *base = apc->cfg_base;
181 unsigned long flags; 185 unsigned long flags;
182 u32 data; 186 u32 data;
183 int err; 187 int err;
@@ -186,7 +190,7 @@ static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
186 ret = PCIBIOS_SUCCESSFUL; 190 ret = PCIBIOS_SUCCESSFUL;
187 data = ~0; 191 data = ~0;
188 192
189 spin_lock_irqsave(&ar71xx_pci_lock, flags); 193 spin_lock_irqsave(&apc->lock, flags);
190 194
191 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size, 195 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
192 AR71XX_PCI_CFG_CMD_READ); 196 AR71XX_PCI_CFG_CMD_READ);
@@ -195,7 +199,7 @@ static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
195 else 199 else
196 data = __raw_readl(base + AR71XX_PCI_REG_CFG_RDDATA); 200 data = __raw_readl(base + AR71XX_PCI_REG_CFG_RDDATA);
197 201
198 spin_unlock_irqrestore(&ar71xx_pci_lock, flags); 202 spin_unlock_irqrestore(&apc->lock, flags);
199 203
200 *value = (data >> (8 * (where & 3))) & ar71xx_pci_read_mask[size & 7]; 204 *value = (data >> (8 * (where & 3))) & ar71xx_pci_read_mask[size & 7];
201 205
@@ -205,7 +209,8 @@ static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
205static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn, 209static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
206 int where, int size, u32 value) 210 int where, int size, u32 value)
207{ 211{
208 void __iomem *base = ar71xx_pcicfg_base; 212 struct ar71xx_pci_controller *apc = pci_bus_to_ar71xx_controller(bus);
213 void __iomem *base = apc->cfg_base;
209 unsigned long flags; 214 unsigned long flags;
210 int err; 215 int err;
211 int ret; 216 int ret;
@@ -213,7 +218,7 @@ static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
213 value = value << (8 * (where & 3)); 218 value = value << (8 * (where & 3));
214 ret = PCIBIOS_SUCCESSFUL; 219 ret = PCIBIOS_SUCCESSFUL;
215 220
216 spin_lock_irqsave(&ar71xx_pci_lock, flags); 221 spin_lock_irqsave(&apc->lock, flags);
217 222
218 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size, 223 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
219 AR71XX_PCI_CFG_CMD_WRITE); 224 AR71XX_PCI_CFG_CMD_WRITE);
@@ -222,7 +227,7 @@ static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
222 else 227 else
223 __raw_writel(value, base + AR71XX_PCI_REG_CFG_WRDATA); 228 __raw_writel(value, base + AR71XX_PCI_REG_CFG_WRDATA);
224 229
225 spin_unlock_irqrestore(&ar71xx_pci_lock, flags); 230 spin_unlock_irqrestore(&apc->lock, flags);
226 231
227 return ret; 232 return ret;
228} 233}
@@ -232,45 +237,28 @@ static struct pci_ops ar71xx_pci_ops = {
232 .write = ar71xx_pci_write_config, 237 .write = ar71xx_pci_write_config,
233}; 238};
234 239
235static struct resource ar71xx_pci_io_resource = {
236 .name = "PCI IO space",
237 .start = 0,
238 .end = 0,
239 .flags = IORESOURCE_IO,
240};
241
242static struct resource ar71xx_pci_mem_resource = {
243 .name = "PCI memory space",
244 .start = AR71XX_PCI_MEM_BASE,
245 .end = AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE - 1,
246 .flags = IORESOURCE_MEM
247};
248
249static struct pci_controller ar71xx_pci_controller = {
250 .pci_ops = &ar71xx_pci_ops,
251 .mem_resource = &ar71xx_pci_mem_resource,
252 .io_resource = &ar71xx_pci_io_resource,
253};
254
255static void ar71xx_pci_irq_handler(unsigned int irq, struct irq_desc *desc) 240static void ar71xx_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
256{ 241{
242 struct ar71xx_pci_controller *apc;
257 void __iomem *base = ath79_reset_base; 243 void __iomem *base = ath79_reset_base;
258 u32 pending; 244 u32 pending;
259 245
246 apc = irq_get_handler_data(irq);
247
260 pending = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_STATUS) & 248 pending = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_STATUS) &
261 __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE); 249 __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
262 250
263 if (pending & AR71XX_PCI_INT_DEV0) 251 if (pending & AR71XX_PCI_INT_DEV0)
264 generic_handle_irq(ATH79_PCI_IRQ(0)); 252 generic_handle_irq(apc->irq_base + 0);
265 253
266 else if (pending & AR71XX_PCI_INT_DEV1) 254 else if (pending & AR71XX_PCI_INT_DEV1)
267 generic_handle_irq(ATH79_PCI_IRQ(1)); 255 generic_handle_irq(apc->irq_base + 1);
268 256
269 else if (pending & AR71XX_PCI_INT_DEV2) 257 else if (pending & AR71XX_PCI_INT_DEV2)
270 generic_handle_irq(ATH79_PCI_IRQ(2)); 258 generic_handle_irq(apc->irq_base + 2);
271 259
272 else if (pending & AR71XX_PCI_INT_CORE) 260 else if (pending & AR71XX_PCI_INT_CORE)
273 generic_handle_irq(ATH79_PCI_IRQ(4)); 261 generic_handle_irq(apc->irq_base + 4);
274 262
275 else 263 else
276 spurious_interrupt(); 264 spurious_interrupt();
@@ -278,10 +266,14 @@ static void ar71xx_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
278 266
279static void ar71xx_pci_irq_unmask(struct irq_data *d) 267static void ar71xx_pci_irq_unmask(struct irq_data *d)
280{ 268{
281 unsigned int irq = d->irq - ATH79_PCI_IRQ_BASE; 269 struct ar71xx_pci_controller *apc;
270 unsigned int irq;
282 void __iomem *base = ath79_reset_base; 271 void __iomem *base = ath79_reset_base;
283 u32 t; 272 u32 t;
284 273
274 apc = irq_data_get_irq_chip_data(d);
275 irq = d->irq - apc->irq_base;
276
285 t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE); 277 t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
286 __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE); 278 __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
287 279
@@ -291,10 +283,14 @@ static void ar71xx_pci_irq_unmask(struct irq_data *d)
291 283
292static void ar71xx_pci_irq_mask(struct irq_data *d) 284static void ar71xx_pci_irq_mask(struct irq_data *d)
293{ 285{
294 unsigned int irq = d->irq - ATH79_PCI_IRQ_BASE; 286 struct ar71xx_pci_controller *apc;
287 unsigned int irq;
295 void __iomem *base = ath79_reset_base; 288 void __iomem *base = ath79_reset_base;
296 u32 t; 289 u32 t;
297 290
291 apc = irq_data_get_irq_chip_data(d);
292 irq = d->irq - apc->irq_base;
293
298 t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE); 294 t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
299 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE); 295 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
300 296
@@ -309,7 +305,7 @@ static struct irq_chip ar71xx_pci_irq_chip = {
309 .irq_mask_ack = ar71xx_pci_irq_mask, 305 .irq_mask_ack = ar71xx_pci_irq_mask,
310}; 306};
311 307
312static __init void ar71xx_pci_irq_init(void) 308static void ar71xx_pci_irq_init(struct ar71xx_pci_controller *apc)
313{ 309{
314 void __iomem *base = ath79_reset_base; 310 void __iomem *base = ath79_reset_base;
315 int i; 311 int i;
@@ -319,15 +315,19 @@ static __init void ar71xx_pci_irq_init(void)
319 315
320 BUILD_BUG_ON(ATH79_PCI_IRQ_COUNT < AR71XX_PCI_IRQ_COUNT); 316 BUILD_BUG_ON(ATH79_PCI_IRQ_COUNT < AR71XX_PCI_IRQ_COUNT);
321 317
322 for (i = ATH79_PCI_IRQ_BASE; 318 apc->irq_base = ATH79_PCI_IRQ_BASE;
323 i < ATH79_PCI_IRQ_BASE + AR71XX_PCI_IRQ_COUNT; i++) 319 for (i = apc->irq_base;
320 i < apc->irq_base + AR71XX_PCI_IRQ_COUNT; i++) {
324 irq_set_chip_and_handler(i, &ar71xx_pci_irq_chip, 321 irq_set_chip_and_handler(i, &ar71xx_pci_irq_chip,
325 handle_level_irq); 322 handle_level_irq);
323 irq_set_chip_data(i, apc);
324 }
326 325
327 irq_set_chained_handler(ATH79_CPU_IRQ_IP2, ar71xx_pci_irq_handler); 326 irq_set_handler_data(apc->irq, apc);
327 irq_set_chained_handler(apc->irq, ar71xx_pci_irq_handler);
328} 328}
329 329
330static __init void ar71xx_pci_reset(void) 330static void ar71xx_pci_reset(void)
331{ 331{
332 void __iomem *ddr_base = ath79_ddr_base; 332 void __iomem *ddr_base = ath79_ddr_base;
333 333
@@ -349,27 +349,83 @@ static __init void ar71xx_pci_reset(void)
349 mdelay(100); 349 mdelay(100);
350} 350}
351 351
352__init int ar71xx_pcibios_init(void) 352static int ar71xx_pci_probe(struct platform_device *pdev)
353{ 353{
354 struct ar71xx_pci_controller *apc;
355 struct resource *res;
354 u32 t; 356 u32 t;
355 357
356 ar71xx_pcicfg_base = ioremap(AR71XX_PCI_CFG_BASE, AR71XX_PCI_CFG_SIZE); 358 apc = devm_kzalloc(&pdev->dev, sizeof(struct ar71xx_pci_controller),
357 if (ar71xx_pcicfg_base == NULL) 359 GFP_KERNEL);
360 if (!apc)
361 return -ENOMEM;
362
363 spin_lock_init(&apc->lock);
364
365 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg_base");
366 if (!res)
367 return -EINVAL;
368
369 apc->cfg_base = devm_request_and_ioremap(&pdev->dev, res);
370 if (!apc->cfg_base)
358 return -ENOMEM; 371 return -ENOMEM;
359 372
373 apc->irq = platform_get_irq(pdev, 0);
374 if (apc->irq < 0)
375 return -EINVAL;
376
377 res = platform_get_resource_byname(pdev, IORESOURCE_IO, "io_base");
378 if (!res)
379 return -EINVAL;
380
381 apc->io_res.parent = res;
382 apc->io_res.name = "PCI IO space";
383 apc->io_res.start = res->start;
384 apc->io_res.end = res->end;
385 apc->io_res.flags = IORESOURCE_IO;
386
387 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem_base");
388 if (!res)
389 return -EINVAL;
390
391 apc->mem_res.parent = res;
392 apc->mem_res.name = "PCI memory space";
393 apc->mem_res.start = res->start;
394 apc->mem_res.end = res->end;
395 apc->mem_res.flags = IORESOURCE_MEM;
396
360 ar71xx_pci_reset(); 397 ar71xx_pci_reset();
361 398
362 /* setup COMMAND register */ 399 /* setup COMMAND register */
363 t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE 400 t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
364 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK; 401 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
365 ar71xx_pci_local_write(PCI_COMMAND, 4, t); 402 ar71xx_pci_local_write(apc, PCI_COMMAND, 4, t);
366 403
367 /* clear bus errors */ 404 /* clear bus errors */
368 ar71xx_pci_check_error(1); 405 ar71xx_pci_check_error(apc, 1);
406
407 ar71xx_pci_irq_init(apc);
369 408
370 ar71xx_pci_irq_init(); 409 apc->pci_ctrl.pci_ops = &ar71xx_pci_ops;
410 apc->pci_ctrl.mem_resource = &apc->mem_res;
411 apc->pci_ctrl.io_resource = &apc->io_res;
371 412
372 register_pci_controller(&ar71xx_pci_controller); 413 register_pci_controller(&apc->pci_ctrl);
373 414
374 return 0; 415 return 0;
375} 416}
417
418static struct platform_driver ar71xx_pci_driver = {
419 .probe = ar71xx_pci_probe,
420 .driver = {
421 .name = "ar71xx-pci",
422 .owner = THIS_MODULE,
423 },
424};
425
426static int __init ar71xx_pci_init(void)
427{
428 return platform_driver_register(&ar71xx_pci_driver);
429}
430
431postcore_initcall(ar71xx_pci_init);
diff --git a/arch/mips/pci/pci-ar724x.c b/arch/mips/pci/pci-ar724x.c
index 279585d6eca0..8a0700d448fe 100644
--- a/arch/mips/pci/pci-ar724x.c
+++ b/arch/mips/pci/pci-ar724x.c
@@ -9,19 +9,13 @@
9 * by the Free Software Foundation. 9 * by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/spinlock.h>
12#include <linux/irq.h> 13#include <linux/irq.h>
13#include <linux/pci.h> 14#include <linux/pci.h>
15#include <linux/module.h>
16#include <linux/platform_device.h>
14#include <asm/mach-ath79/ath79.h> 17#include <asm/mach-ath79/ath79.h>
15#include <asm/mach-ath79/ar71xx_regs.h> 18#include <asm/mach-ath79/ar71xx_regs.h>
16#include <asm/mach-ath79/pci.h>
17
18#define AR724X_PCI_CFG_BASE 0x14000000
19#define AR724X_PCI_CFG_SIZE 0x1000
20#define AR724X_PCI_CTRL_BASE (AR71XX_APB_BASE + 0x000f0000)
21#define AR724X_PCI_CTRL_SIZE 0x100
22
23#define AR724X_PCI_MEM_BASE 0x10000000
24#define AR724X_PCI_MEM_SIZE 0x04000000
25 19
26#define AR724X_PCI_REG_RESET 0x18 20#define AR724X_PCI_REG_RESET 0x18
27#define AR724X_PCI_REG_INT_STATUS 0x4c 21#define AR724X_PCI_REG_INT_STATUS 0x4c
@@ -35,38 +29,112 @@
35 29
36#define AR7240_BAR0_WAR_VALUE 0xffff 30#define AR7240_BAR0_WAR_VALUE 0xffff
37 31
38static DEFINE_SPINLOCK(ar724x_pci_lock); 32#define AR724X_PCI_CMD_INIT (PCI_COMMAND_MEMORY | \
39static void __iomem *ar724x_pci_devcfg_base; 33 PCI_COMMAND_MASTER | \
40static void __iomem *ar724x_pci_ctrl_base; 34 PCI_COMMAND_INVALIDATE | \
35 PCI_COMMAND_PARITY | \
36 PCI_COMMAND_SERR | \
37 PCI_COMMAND_FAST_BACK)
38
39struct ar724x_pci_controller {
40 void __iomem *devcfg_base;
41 void __iomem *ctrl_base;
42 void __iomem *crp_base;
43
44 int irq;
45 int irq_base;
46
47 bool link_up;
48 bool bar0_is_cached;
49 u32 bar0_value;
41 50
42static u32 ar724x_pci_bar0_value; 51 spinlock_t lock;
43static bool ar724x_pci_bar0_is_cached;
44static bool ar724x_pci_link_up;
45 52
46static inline bool ar724x_pci_check_link(void) 53 struct pci_controller pci_controller;
54 struct resource io_res;
55 struct resource mem_res;
56};
57
58static inline bool ar724x_pci_check_link(struct ar724x_pci_controller *apc)
47{ 59{
48 u32 reset; 60 u32 reset;
49 61
50 reset = __raw_readl(ar724x_pci_ctrl_base + AR724X_PCI_REG_RESET); 62 reset = __raw_readl(apc->ctrl_base + AR724X_PCI_REG_RESET);
51 return reset & AR724X_PCI_RESET_LINK_UP; 63 return reset & AR724X_PCI_RESET_LINK_UP;
52} 64}
53 65
66static inline struct ar724x_pci_controller *
67pci_bus_to_ar724x_controller(struct pci_bus *bus)
68{
69 struct pci_controller *hose;
70
71 hose = (struct pci_controller *) bus->sysdata;
72 return container_of(hose, struct ar724x_pci_controller, pci_controller);
73}
74
75static int ar724x_pci_local_write(struct ar724x_pci_controller *apc,
76 int where, int size, u32 value)
77{
78 unsigned long flags;
79 void __iomem *base;
80 u32 data;
81 int s;
82
83 WARN_ON(where & (size - 1));
84
85 if (!apc->link_up)
86 return PCIBIOS_DEVICE_NOT_FOUND;
87
88 base = apc->crp_base;
89
90 spin_lock_irqsave(&apc->lock, flags);
91 data = __raw_readl(base + (where & ~3));
92
93 switch (size) {
94 case 1:
95 s = ((where & 3) * 8);
96 data &= ~(0xff << s);
97 data |= ((value & 0xff) << s);
98 break;
99 case 2:
100 s = ((where & 2) * 8);
101 data &= ~(0xffff << s);
102 data |= ((value & 0xffff) << s);
103 break;
104 case 4:
105 data = value;
106 break;
107 default:
108 spin_unlock_irqrestore(&apc->lock, flags);
109 return PCIBIOS_BAD_REGISTER_NUMBER;
110 }
111
112 __raw_writel(data, base + (where & ~3));
113 /* flush write */
114 __raw_readl(base + (where & ~3));
115 spin_unlock_irqrestore(&apc->lock, flags);
116
117 return PCIBIOS_SUCCESSFUL;
118}
119
54static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where, 120static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where,
55 int size, uint32_t *value) 121 int size, uint32_t *value)
56{ 122{
123 struct ar724x_pci_controller *apc;
57 unsigned long flags; 124 unsigned long flags;
58 void __iomem *base; 125 void __iomem *base;
59 u32 data; 126 u32 data;
60 127
61 if (!ar724x_pci_link_up) 128 apc = pci_bus_to_ar724x_controller(bus);
129 if (!apc->link_up)
62 return PCIBIOS_DEVICE_NOT_FOUND; 130 return PCIBIOS_DEVICE_NOT_FOUND;
63 131
64 if (devfn) 132 if (devfn)
65 return PCIBIOS_DEVICE_NOT_FOUND; 133 return PCIBIOS_DEVICE_NOT_FOUND;
66 134
67 base = ar724x_pci_devcfg_base; 135 base = apc->devcfg_base;
68 136
69 spin_lock_irqsave(&ar724x_pci_lock, flags); 137 spin_lock_irqsave(&apc->lock, flags);
70 data = __raw_readl(base + (where & ~3)); 138 data = __raw_readl(base + (where & ~3));
71 139
72 switch (size) { 140 switch (size) {
@@ -85,17 +153,17 @@ static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where,
85 case 4: 153 case 4:
86 break; 154 break;
87 default: 155 default:
88 spin_unlock_irqrestore(&ar724x_pci_lock, flags); 156 spin_unlock_irqrestore(&apc->lock, flags);
89 157
90 return PCIBIOS_BAD_REGISTER_NUMBER; 158 return PCIBIOS_BAD_REGISTER_NUMBER;
91 } 159 }
92 160
93 spin_unlock_irqrestore(&ar724x_pci_lock, flags); 161 spin_unlock_irqrestore(&apc->lock, flags);
94 162
95 if (where == PCI_BASE_ADDRESS_0 && size == 4 && 163 if (where == PCI_BASE_ADDRESS_0 && size == 4 &&
96 ar724x_pci_bar0_is_cached) { 164 apc->bar0_is_cached) {
97 /* use the cached value */ 165 /* use the cached value */
98 *value = ar724x_pci_bar0_value; 166 *value = apc->bar0_value;
99 } else { 167 } else {
100 *value = data; 168 *value = data;
101 } 169 }
@@ -106,12 +174,14 @@ static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where,
106static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where, 174static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where,
107 int size, uint32_t value) 175 int size, uint32_t value)
108{ 176{
177 struct ar724x_pci_controller *apc;
109 unsigned long flags; 178 unsigned long flags;
110 void __iomem *base; 179 void __iomem *base;
111 u32 data; 180 u32 data;
112 int s; 181 int s;
113 182
114 if (!ar724x_pci_link_up) 183 apc = pci_bus_to_ar724x_controller(bus);
184 if (!apc->link_up)
115 return PCIBIOS_DEVICE_NOT_FOUND; 185 return PCIBIOS_DEVICE_NOT_FOUND;
116 186
117 if (devfn) 187 if (devfn)
@@ -129,18 +199,18 @@ static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where,
129 * BAR0 register in order to make the device memory 199 * BAR0 register in order to make the device memory
130 * accessible. 200 * accessible.
131 */ 201 */
132 ar724x_pci_bar0_is_cached = true; 202 apc->bar0_is_cached = true;
133 ar724x_pci_bar0_value = value; 203 apc->bar0_value = value;
134 204
135 value = AR7240_BAR0_WAR_VALUE; 205 value = AR7240_BAR0_WAR_VALUE;
136 } else { 206 } else {
137 ar724x_pci_bar0_is_cached = false; 207 apc->bar0_is_cached = false;
138 } 208 }
139 } 209 }
140 210
141 base = ar724x_pci_devcfg_base; 211 base = apc->devcfg_base;
142 212
143 spin_lock_irqsave(&ar724x_pci_lock, flags); 213 spin_lock_irqsave(&apc->lock, flags);
144 data = __raw_readl(base + (where & ~3)); 214 data = __raw_readl(base + (where & ~3));
145 215
146 switch (size) { 216 switch (size) {
@@ -158,7 +228,7 @@ static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where,
158 data = value; 228 data = value;
159 break; 229 break;
160 default: 230 default:
161 spin_unlock_irqrestore(&ar724x_pci_lock, flags); 231 spin_unlock_irqrestore(&apc->lock, flags);
162 232
163 return PCIBIOS_BAD_REGISTER_NUMBER; 233 return PCIBIOS_BAD_REGISTER_NUMBER;
164 } 234 }
@@ -166,7 +236,7 @@ static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where,
166 __raw_writel(data, base + (where & ~3)); 236 __raw_writel(data, base + (where & ~3));
167 /* flush write */ 237 /* flush write */
168 __raw_readl(base + (where & ~3)); 238 __raw_readl(base + (where & ~3));
169 spin_unlock_irqrestore(&ar724x_pci_lock, flags); 239 spin_unlock_irqrestore(&apc->lock, flags);
170 240
171 return PCIBIOS_SUCCESSFUL; 241 return PCIBIOS_SUCCESSFUL;
172} 242}
@@ -176,38 +246,20 @@ static struct pci_ops ar724x_pci_ops = {
176 .write = ar724x_pci_write, 246 .write = ar724x_pci_write,
177}; 247};
178 248
179static struct resource ar724x_io_resource = {
180 .name = "PCI IO space",
181 .start = 0,
182 .end = 0,
183 .flags = IORESOURCE_IO,
184};
185
186static struct resource ar724x_mem_resource = {
187 .name = "PCI memory space",
188 .start = AR724X_PCI_MEM_BASE,
189 .end = AR724X_PCI_MEM_BASE + AR724X_PCI_MEM_SIZE - 1,
190 .flags = IORESOURCE_MEM,
191};
192
193static struct pci_controller ar724x_pci_controller = {
194 .pci_ops = &ar724x_pci_ops,
195 .io_resource = &ar724x_io_resource,
196 .mem_resource = &ar724x_mem_resource,
197};
198
199static void ar724x_pci_irq_handler(unsigned int irq, struct irq_desc *desc) 249static void ar724x_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
200{ 250{
251 struct ar724x_pci_controller *apc;
201 void __iomem *base; 252 void __iomem *base;
202 u32 pending; 253 u32 pending;
203 254
204 base = ar724x_pci_ctrl_base; 255 apc = irq_get_handler_data(irq);
256 base = apc->ctrl_base;
205 257
206 pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) & 258 pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) &
207 __raw_readl(base + AR724X_PCI_REG_INT_MASK); 259 __raw_readl(base + AR724X_PCI_REG_INT_MASK);
208 260
209 if (pending & AR724X_PCI_INT_DEV0) 261 if (pending & AR724X_PCI_INT_DEV0)
210 generic_handle_irq(ATH79_PCI_IRQ(0)); 262 generic_handle_irq(apc->irq_base + 0);
211 263
212 else 264 else
213 spurious_interrupt(); 265 spurious_interrupt();
@@ -215,13 +267,17 @@ static void ar724x_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
215 267
216static void ar724x_pci_irq_unmask(struct irq_data *d) 268static void ar724x_pci_irq_unmask(struct irq_data *d)
217{ 269{
270 struct ar724x_pci_controller *apc;
218 void __iomem *base; 271 void __iomem *base;
272 int offset;
219 u32 t; 273 u32 t;
220 274
221 base = ar724x_pci_ctrl_base; 275 apc = irq_data_get_irq_chip_data(d);
276 base = apc->ctrl_base;
277 offset = apc->irq_base - d->irq;
222 278
223 switch (d->irq) { 279 switch (offset) {
224 case ATH79_PCI_IRQ(0): 280 case 0:
225 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK); 281 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
226 __raw_writel(t | AR724X_PCI_INT_DEV0, 282 __raw_writel(t | AR724X_PCI_INT_DEV0,
227 base + AR724X_PCI_REG_INT_MASK); 283 base + AR724X_PCI_REG_INT_MASK);
@@ -232,13 +288,17 @@ static void ar724x_pci_irq_unmask(struct irq_data *d)
232 288
233static void ar724x_pci_irq_mask(struct irq_data *d) 289static void ar724x_pci_irq_mask(struct irq_data *d)
234{ 290{
291 struct ar724x_pci_controller *apc;
235 void __iomem *base; 292 void __iomem *base;
293 int offset;
236 u32 t; 294 u32 t;
237 295
238 base = ar724x_pci_ctrl_base; 296 apc = irq_data_get_irq_chip_data(d);
297 base = apc->ctrl_base;
298 offset = apc->irq_base - d->irq;
239 299
240 switch (d->irq) { 300 switch (offset) {
241 case ATH79_PCI_IRQ(0): 301 case 0:
242 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK); 302 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
243 __raw_writel(t & ~AR724X_PCI_INT_DEV0, 303 __raw_writel(t & ~AR724X_PCI_INT_DEV0,
244 base + AR724X_PCI_REG_INT_MASK); 304 base + AR724X_PCI_REG_INT_MASK);
@@ -262,53 +322,123 @@ static struct irq_chip ar724x_pci_irq_chip = {
262 .irq_mask_ack = ar724x_pci_irq_mask, 322 .irq_mask_ack = ar724x_pci_irq_mask,
263}; 323};
264 324
265static void __init ar724x_pci_irq_init(int irq) 325static void ar724x_pci_irq_init(struct ar724x_pci_controller *apc,
326 int id)
266{ 327{
267 void __iomem *base; 328 void __iomem *base;
268 int i; 329 int i;
269 330
270 base = ar724x_pci_ctrl_base; 331 base = apc->ctrl_base;
271 332
272 __raw_writel(0, base + AR724X_PCI_REG_INT_MASK); 333 __raw_writel(0, base + AR724X_PCI_REG_INT_MASK);
273 __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS); 334 __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS);
274 335
275 BUILD_BUG_ON(ATH79_PCI_IRQ_COUNT < AR724X_PCI_IRQ_COUNT); 336 apc->irq_base = ATH79_PCI_IRQ_BASE + (id * AR724X_PCI_IRQ_COUNT);
276 337
277 for (i = ATH79_PCI_IRQ_BASE; 338 for (i = apc->irq_base;
278 i < ATH79_PCI_IRQ_BASE + AR724X_PCI_IRQ_COUNT; i++) 339 i < apc->irq_base + AR724X_PCI_IRQ_COUNT; i++) {
279 irq_set_chip_and_handler(i, &ar724x_pci_irq_chip, 340 irq_set_chip_and_handler(i, &ar724x_pci_irq_chip,
280 handle_level_irq); 341 handle_level_irq);
342 irq_set_chip_data(i, apc);
343 }
281 344
282 irq_set_chained_handler(irq, ar724x_pci_irq_handler); 345 irq_set_handler_data(apc->irq, apc);
346 irq_set_chained_handler(apc->irq, ar724x_pci_irq_handler);
283} 347}
284 348
285int __init ar724x_pcibios_init(int irq) 349static int ar724x_pci_probe(struct platform_device *pdev)
286{ 350{
287 int ret; 351 struct ar724x_pci_controller *apc;
352 struct resource *res;
353 int id;
288 354
289 ret = -ENOMEM; 355 id = pdev->id;
356 if (id == -1)
357 id = 0;
290 358
291 ar724x_pci_devcfg_base = ioremap(AR724X_PCI_CFG_BASE, 359 apc = devm_kzalloc(&pdev->dev, sizeof(struct ar724x_pci_controller),
292 AR724X_PCI_CFG_SIZE); 360 GFP_KERNEL);
293 if (ar724x_pci_devcfg_base == NULL) 361 if (!apc)
294 goto err; 362 return -ENOMEM;
295 363
296 ar724x_pci_ctrl_base = ioremap(AR724X_PCI_CTRL_BASE, 364 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctrl_base");
297 AR724X_PCI_CTRL_SIZE); 365 if (!res)
298 if (ar724x_pci_ctrl_base == NULL) 366 return -EINVAL;
299 goto err_unmap_devcfg;
300 367
301 ar724x_pci_link_up = ar724x_pci_check_link(); 368 apc->ctrl_base = devm_request_and_ioremap(&pdev->dev, res);
302 if (!ar724x_pci_link_up) 369 if (apc->ctrl_base == NULL)
303 pr_warn("ar724x: PCIe link is down\n"); 370 return -EBUSY;
304 371
305 ar724x_pci_irq_init(irq); 372 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg_base");
306 register_pci_controller(&ar724x_pci_controller); 373 if (!res)
374 return -EINVAL;
307 375
308 return PCIBIOS_SUCCESSFUL; 376 apc->devcfg_base = devm_request_and_ioremap(&pdev->dev, res);
377 if (!apc->devcfg_base)
378 return -EBUSY;
379
380 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "crp_base");
381 if (!res)
382 return -EINVAL;
309 383
310err_unmap_devcfg: 384 apc->crp_base = devm_request_and_ioremap(&pdev->dev, res);
311 iounmap(ar724x_pci_devcfg_base); 385 if (apc->crp_base == NULL)
312err: 386 return -EBUSY;
313 return ret; 387
388 apc->irq = platform_get_irq(pdev, 0);
389 if (apc->irq < 0)
390 return -EINVAL;
391
392 spin_lock_init(&apc->lock);
393
394 res = platform_get_resource_byname(pdev, IORESOURCE_IO, "io_base");
395 if (!res)
396 return -EINVAL;
397
398 apc->io_res.parent = res;
399 apc->io_res.name = "PCI IO space";
400 apc->io_res.start = res->start;
401 apc->io_res.end = res->end;
402 apc->io_res.flags = IORESOURCE_IO;
403
404 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem_base");
405 if (!res)
406 return -EINVAL;
407
408 apc->mem_res.parent = res;
409 apc->mem_res.name = "PCI memory space";
410 apc->mem_res.start = res->start;
411 apc->mem_res.end = res->end;
412 apc->mem_res.flags = IORESOURCE_MEM;
413
414 apc->pci_controller.pci_ops = &ar724x_pci_ops;
415 apc->pci_controller.io_resource = &apc->io_res;
416 apc->pci_controller.mem_resource = &apc->mem_res;
417
418 apc->link_up = ar724x_pci_check_link(apc);
419 if (!apc->link_up)
420 dev_warn(&pdev->dev, "PCIe link is down\n");
421
422 ar724x_pci_irq_init(apc, id);
423
424 ar724x_pci_local_write(apc, PCI_COMMAND, 4, AR724X_PCI_CMD_INIT);
425
426 register_pci_controller(&apc->pci_controller);
427
428 return 0;
314} 429}
430
431static struct platform_driver ar724x_pci_driver = {
432 .probe = ar724x_pci_probe,
433 .driver = {
434 .name = "ar724x-pci",
435 .owner = THIS_MODULE,
436 },
437};
438
439static int __init ar724x_pci_init(void)
440{
441 return platform_driver_register(&ar724x_pci_driver);
442}
443
444postcore_initcall(ar724x_pci_init);
diff --git a/arch/mips/pci/pci-lantiq.c b/arch/mips/pci/pci-lantiq.c
index 95681789b51e..f32664bbbe17 100644
--- a/arch/mips/pci/pci-lantiq.c
+++ b/arch/mips/pci/pci-lantiq.c
@@ -129,8 +129,16 @@ static int ltq_pci_startup(struct platform_device *pdev)
129 129
130 /* setup reset gpio used by pci */ 130 /* setup reset gpio used by pci */
131 reset_gpio = of_get_named_gpio(node, "gpio-reset", 0); 131 reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
132 if (gpio_is_valid(reset_gpio)) 132 if (gpio_is_valid(reset_gpio)) {
133 devm_gpio_request(&pdev->dev, reset_gpio, "pci-reset"); 133 int ret = devm_gpio_request(&pdev->dev,
134 reset_gpio, "pci-reset");
135 if (ret) {
136 dev_err(&pdev->dev,
137 "failed to request gpio %d\n", reset_gpio);
138 return ret;
139 }
140 gpio_direction_output(reset_gpio, 1);
141 }
134 142
135 /* enable auto-switching between PCI and EBU */ 143 /* enable auto-switching between PCI and EBU */
136 ltq_pci_w32(0xa, PCI_CR_CLK_CTRL); 144 ltq_pci_w32(0xa, PCI_CR_CLK_CTRL);
diff --git a/arch/mips/pci/pci-xlp.c b/arch/mips/pci/pci-xlp.c
index ad55f2cfeec1..653d2db9e0c5 100644
--- a/arch/mips/pci/pci-xlp.c
+++ b/arch/mips/pci/pci-xlp.c
@@ -46,6 +46,7 @@
46 46
47#include <asm/netlogic/interrupt.h> 47#include <asm/netlogic/interrupt.h>
48#include <asm/netlogic/haldefs.h> 48#include <asm/netlogic/haldefs.h>
49#include <asm/netlogic/common.h>
49 50
50#include <asm/netlogic/xlp-hal/iomap.h> 51#include <asm/netlogic/xlp-hal/iomap.h>
51#include <asm/netlogic/xlp-hal/pic.h> 52#include <asm/netlogic/xlp-hal/pic.h>
@@ -64,8 +65,12 @@ static inline u32 pci_cfg_read_32bit(struct pci_bus *bus, unsigned int devfn,
64 u32 data; 65 u32 data;
65 u32 *cfgaddr; 66 u32 *cfgaddr;
66 67
68 where &= ~3;
69 if (bus->number == 0 && PCI_SLOT(devfn) == 1 && where == 0x954)
70 return 0xffffffff;
71
67 cfgaddr = (u32 *)(pci_config_base + 72 cfgaddr = (u32 *)(pci_config_base +
68 pci_cfg_addr(bus->number, devfn, where & ~3)); 73 pci_cfg_addr(bus->number, devfn, where));
69 data = *cfgaddr; 74 data = *cfgaddr;
70 return data; 75 return data;
71} 76}
@@ -157,32 +162,38 @@ struct pci_controller nlm_pci_controller = {
157 .io_offset = 0x00000000UL, 162 .io_offset = 0x00000000UL,
158}; 163};
159 164
160static int get_irq_vector(const struct pci_dev *dev) 165static struct pci_dev *xlp_get_pcie_link(const struct pci_dev *dev)
161{ 166{
162 /* 167 struct pci_bus *bus, *p;
163 * For XLP PCIe, there is an IRQ per Link, find out which
164 * link the device is on to assign interrupts
165 */
166 if (dev->bus->self == NULL)
167 return 0;
168 168
169 switch (dev->bus->self->devfn) { 169 /* Find the bridge on bus 0 */
170 case 0x8: 170 bus = dev->bus;
171 return PIC_PCIE_LINK_0_IRQ; 171 for (p = bus->parent; p && p->number != 0; p = p->parent)
172 case 0x9: 172 bus = p;
173 return PIC_PCIE_LINK_1_IRQ; 173
174 case 0xa: 174 return p ? bus->self : NULL;
175 return PIC_PCIE_LINK_2_IRQ; 175}
176 case 0xb: 176
177 return PIC_PCIE_LINK_3_IRQ; 177static inline int nlm_pci_link_to_irq(int link)
178 } 178{
179 WARN(1, "Unexpected devfn %d\n", dev->bus->self->devfn); 179 return PIC_PCIE_LINK_0_IRQ + link;
180 return 0;
181} 180}
182 181
183int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) 182int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
184{ 183{
185 return get_irq_vector(dev); 184 struct pci_dev *lnkdev;
185 int lnkslot, lnkfunc;
186
187 /*
188 * For XLP PCIe, there is an IRQ per Link, find out which
189 * link the device is on to assign interrupts
190 */
191 lnkdev = xlp_get_pcie_link(dev);
192 if (lnkdev == NULL)
193 return 0;
194 lnkfunc = PCI_FUNC(lnkdev->devfn);
195 lnkslot = PCI_SLOT(lnkdev->devfn);
196 return nlm_irq_to_xirq(lnkslot / 8, nlm_pci_link_to_irq(lnkfunc));
186} 197}
187 198
188/* Do platform specific device initialization at pci_enable_device() time */ 199/* Do platform specific device initialization at pci_enable_device() time */
@@ -191,42 +202,48 @@ int pcibios_plat_dev_init(struct pci_dev *dev)
191 return 0; 202 return 0;
192} 203}
193 204
194static int xlp_enable_pci_bswap(void) 205/*
206 * If big-endian, enable hardware byteswap on the PCIe bridges.
207 * This will make both the SoC and PCIe devices behave consistently with
208 * readl/writel.
209 */
210#ifdef __BIG_ENDIAN
211static void xlp_config_pci_bswap(int node, int link)
195{ 212{
196 uint64_t pciebase, sysbase; 213 uint64_t nbubase, lnkbase;
197 int node, i;
198 u32 reg; 214 u32 reg;
199 215
200 /* Chip-0 so node set to 0 */ 216 nbubase = nlm_get_bridge_regbase(node);
201 node = 0; 217 lnkbase = nlm_get_pcie_base(node, link);
202 sysbase = nlm_get_bridge_regbase(node); 218
203 /* 219 /*
204 * Enable byte swap in hardware. Program each link's PCIe SWAP regions 220 * Enable byte swap in hardware. Program each link's PCIe SWAP regions
205 * from the link's address ranges. 221 * from the link's address ranges.
206 */ 222 */
207 for (i = 0; i < 4; i++) { 223 reg = nlm_read_bridge_reg(nbubase, BRIDGE_PCIEMEM_BASE0 + link);
208 pciebase = nlm_pcicfg_base(XLP_IO_PCIE_OFFSET(node, i)); 224 nlm_write_pci_reg(lnkbase, PCIE_BYTE_SWAP_MEM_BASE, reg);
209 if (nlm_read_pci_reg(pciebase, 0) == 0xffffffff)
210 continue;
211 225
212 reg = nlm_read_bridge_reg(sysbase, BRIDGE_PCIEMEM_BASE0 + i); 226 reg = nlm_read_bridge_reg(nbubase, BRIDGE_PCIEMEM_LIMIT0 + link);
213 nlm_write_pci_reg(pciebase, PCIE_BYTE_SWAP_MEM_BASE, reg); 227 nlm_write_pci_reg(lnkbase, PCIE_BYTE_SWAP_MEM_LIM, reg | 0xfff);
214 228
215 reg = nlm_read_bridge_reg(sysbase, BRIDGE_PCIEMEM_LIMIT0 + i); 229 reg = nlm_read_bridge_reg(nbubase, BRIDGE_PCIEIO_BASE0 + link);
216 nlm_write_pci_reg(pciebase, PCIE_BYTE_SWAP_MEM_LIM, 230 nlm_write_pci_reg(lnkbase, PCIE_BYTE_SWAP_IO_BASE, reg);
217 reg | 0xfff);
218 231
219 reg = nlm_read_bridge_reg(sysbase, BRIDGE_PCIEIO_BASE0 + i); 232 reg = nlm_read_bridge_reg(nbubase, BRIDGE_PCIEIO_LIMIT0 + link);
220 nlm_write_pci_reg(pciebase, PCIE_BYTE_SWAP_IO_BASE, reg); 233 nlm_write_pci_reg(lnkbase, PCIE_BYTE_SWAP_IO_LIM, reg | 0xfff);
221
222 reg = nlm_read_bridge_reg(sysbase, BRIDGE_PCIEIO_LIMIT0 + i);
223 nlm_write_pci_reg(pciebase, PCIE_BYTE_SWAP_IO_LIM, reg | 0xfff);
224 }
225 return 0;
226} 234}
235#else
236/* Swap configuration not needed in little-endian mode */
237static inline void xlp_config_pci_bswap(int node, int link) {}
238#endif /* __BIG_ENDIAN */
227 239
228static int __init pcibios_init(void) 240static int __init pcibios_init(void)
229{ 241{
242 struct nlm_soc_info *nodep;
243 uint64_t pciebase;
244 int link, n;
245 u32 reg;
246
230 /* Firmware assigns PCI resources */ 247 /* Firmware assigns PCI resources */
231 pci_set_flags(PCI_PROBE_ONLY); 248 pci_set_flags(PCI_PROBE_ONLY);
232 pci_config_base = ioremap(XLP_DEFAULT_PCI_ECFG_BASE, 64 << 20); 249 pci_config_base = ioremap(XLP_DEFAULT_PCI_ECFG_BASE, 64 << 20);
@@ -235,7 +252,26 @@ static int __init pcibios_init(void)
235 ioport_resource.start = 0; 252 ioport_resource.start = 0;
236 ioport_resource.end = ~0; 253 ioport_resource.end = ~0;
237 254
238 xlp_enable_pci_bswap(); 255 for (n = 0; n < NLM_NR_NODES; n++) {
256 nodep = nlm_get_node(n);
257 if (!nodep->coremask)
258 continue; /* node does not exist */
259
260 for (link = 0; link < 4; link++) {
261 pciebase = nlm_get_pcie_base(n, link);
262 if (nlm_read_pci_reg(pciebase, 0) == 0xffffffff)
263 continue;
264 xlp_config_pci_bswap(n, link);
265
266 /* put in intpin and irq - u-boot does not */
267 reg = nlm_read_pci_reg(pciebase, 0xf);
268 reg &= ~0x1fu;
269 reg |= (1 << 8) | nlm_pci_link_to_irq(link);
270 nlm_write_pci_reg(pciebase, 0xf, reg);
271 pr_info("XLP PCIe: Link %d-%d initialized.\n", n, link);
272 }
273 }
274
239 set_io_port_base(CKSEG1); 275 set_io_port_base(CKSEG1);
240 nlm_pci_controller.io_map_base = CKSEG1; 276 nlm_pci_controller.io_map_base = CKSEG1;
241 277
diff --git a/arch/mips/pci/pci.c b/arch/mips/pci/pci.c
index e8a14a6514cf..0872f12f268d 100644
--- a/arch/mips/pci/pci.c
+++ b/arch/mips/pci/pci.c
@@ -175,9 +175,20 @@ static DEFINE_MUTEX(pci_scan_mutex);
175 175
176void register_pci_controller(struct pci_controller *hose) 176void register_pci_controller(struct pci_controller *hose)
177{ 177{
178 if (request_resource(&iomem_resource, hose->mem_resource) < 0) 178 struct resource *parent;
179
180 parent = hose->mem_resource->parent;
181 if (!parent)
182 parent = &iomem_resource;
183
184 if (request_resource(parent, hose->mem_resource) < 0)
179 goto out; 185 goto out;
180 if (request_resource(&ioport_resource, hose->io_resource) < 0) { 186
187 parent = hose->io_resource->parent;
188 if (!parent)
189 parent = &ioport_resource;
190
191 if (request_resource(parent, hose->io_resource) < 0) {
181 release_resource(hose->mem_resource); 192 release_resource(hose->mem_resource);
182 goto out; 193 goto out;
183 } 194 }