ar71xx: add preliminary support for Mikrotik RB2011L
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / patches-3.3 / 113-MIPS-ath79-allow-to-use-board-specific-pci_plat_dev_.patch
1 From 2b62c9d685d9bb048a006b695683b2a812c0a847 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Wed, 14 Mar 2012 10:36:09 +0100
4 Subject: [PATCH 18/47] MIPS: ath79: allow to use board specific pci_plat_dev_init functions
5
6 Th current implementation causes NULL pointer dereference
7 if 'pci_data' is not set:
8
9 pci 0000:00:00.0: BAR 0: assigned [mem 0x10000000-0x1000ffff 64bit]
10 pci 0000:00:00.0: BAR 0: set to [mem 0x10000000-0x1000ffff 64bit] (PCI
11 address [0x10000000-0x1000ffff])
12 CPU 0 Unable to handle kernel paging request at virtual address 00000000, epc == 802daca0, ra == 802e78a4
13 Oops[#1]:
14 Cpu 0
15 $ 0 : 00000000 80420000 00000000 00000000
16 $ 4 : 00000000 00000000 00000001 00000001
17 $ 8 : 00000001 0000032c 81c54700 00000001
18 $12 : 0000032d 0000000f 00000000 ffffffff
19 $16 : 81c14c00 00000001 802dac74 80195f98
20 $20 : 802ea050 00000000 00000000 00000000
21 $24 : 00000003 800617f0
22 $28 : 81c20000 81c21e70 00000000 802e78a4
23 Hi : 00000000
24 Lo : 4190ab00
25 epc : 802daca0 0x802daca0
26 Not tainted
27 ra : 802e78a4 0x802e78a4
28 Status: 1000c003 KERNEL EXL IE
29 Cause : 00800008
30 BadVA : 00000000
31 PrId : 00019374 (MIPS 24Kc)
32 Modules linked in:
33 Process swapper (pid: 1, threadinfo=81c20000, task=81c18000, tls=00000000)
34 Stack : 00000000 8027d5d8 802e8ae0 00000000 01000000 802e8b5c 81c50600 00000000
35 802ff290 00000000 80420000 802ea0bc 00000000 00000000 80420000 802ff290
36 80420000 80060930 33390000 00000000 00002308 80140a80 00000028 802d0000
37 00000000 800ba024 802ff004 802ff0c8 802ff290 00000000 00000000 00000000
38 00000000 802d897c 01234567 7f827068 00000000 0045f798 00460000 00000000
39
40 This can be avoided by calling the 'ar724x_pci_add_data'
41 function from the board specific setup code. However it
42 makes no sense to use that function for every board,
43 especially when the board does not needs to set the
44 platform_data field of any PCI device.
45
46 The patch allows the board setup code to specify a board
47 specific function if that is required.
48
49 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
50 Cc: linux-mips@linux-mips.org
51 Patchwork: https://patchwork.linux-mips.org/patch/3499/
52 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
53 ---
54 arch/mips/ath79/mach-ubnt-xm.c | 13 ++++++++++++-
55 arch/mips/ath79/pci.c | 14 ++++++++------
56 arch/mips/ath79/pci.h | 4 +++-
57 3 files changed, 23 insertions(+), 8 deletions(-)
58
59 --- a/arch/mips/ath79/mach-ubnt-xm.c
60 +++ b/arch/mips/ath79/mach-ubnt-xm.c
61 @@ -85,16 +85,27 @@ static struct ath9k_platform_data ubnt_x
62 static struct ar724x_pci_data ubnt_xm_pci_data[] = {
63 {
64 .irq = ATH79_PCI_IRQ(0),
65 - .pdata = &ubnt_xm_eeprom_data,
66 },
67 };
68
69 +static int ubnt_xm_pci_plat_dev_init(struct pci_dev *dev)
70 +{
71 + switch (PCI_SLOT(dev->devfn)) {
72 + case 0:
73 + dev->dev.platform_data = &ubnt_xm_eeprom_data;
74 + break;
75 + }
76 +
77 + return 0;
78 +}
79 +
80 static void __init ubnt_xm_pci_init(void)
81 {
82 memcpy(ubnt_xm_eeprom_data.eeprom_data, UBNT_XM_EEPROM_ADDR,
83 sizeof(ubnt_xm_eeprom_data.eeprom_data));
84
85 ar724x_pci_add_data(ubnt_xm_pci_data, ARRAY_SIZE(ubnt_xm_pci_data));
86 + ath79_pci_set_plat_dev_init(ubnt_xm_pci_plat_dev_init);
87 ath79_register_pci();
88 }
89 #else
90 --- a/arch/mips/ath79/pci.c
91 +++ b/arch/mips/ath79/pci.c
92 @@ -14,6 +14,7 @@
93 #include <asm/mach-ath79/pci.h>
94 #include "pci.h"
95
96 +static int (*ath79_pci_plat_dev_init)(struct pci_dev *dev);
97 static struct ar724x_pci_data *pci_data;
98 static int pci_data_size;
99
100 @@ -38,14 +39,15 @@ int __init pcibios_map_irq(const struct
101
102 int pcibios_plat_dev_init(struct pci_dev *dev)
103 {
104 - unsigned int devfn = dev->devfn;
105 -
106 - if (devfn > pci_data_size - 1)
107 - return PCIBIOS_DEVICE_NOT_FOUND;
108 + if (ath79_pci_plat_dev_init)
109 + return ath79_pci_plat_dev_init(dev);
110
111 - dev->dev.platform_data = pci_data[devfn].pdata;
112 + return 0;
113 +}
114
115 - return PCIBIOS_SUCCESSFUL;
116 +void __init ath79_pci_set_plat_dev_init(int (*func)(struct pci_dev *dev))
117 +{
118 + ath79_pci_plat_dev_init = func;
119 }
120
121 int __init ath79_register_pci(void)
122 --- a/arch/mips/ath79/pci.h
123 +++ b/arch/mips/ath79/pci.h
124 @@ -13,14 +13,16 @@
125
126 struct ar724x_pci_data {
127 int irq;
128 - void *pdata;
129 };
130
131 void ar724x_pci_add_data(struct ar724x_pci_data *data, int size);
132
133 #ifdef CONFIG_PCI
134 +void ath79_pci_set_plat_dev_init(int (*func)(struct pci_dev *dev));
135 int ath79_register_pci(void);
136 #else
137 +static inline void
138 +ath79_pci_set_plat_dev_init(int (*func)(struct pci_dev *)) {}
139 static inline int ath79_register_pci(void) { return 0; }
140 #endif
141