Skip to content

Commit 666db56

Browse files
Scott Woodsuryasaimadhu
authored andcommitted
EDAC, mpc85xx: Make mpc85xx-pci-edac a platform device
Originally the mpc85xx-pci-edac driver bound directly to the PCI controller node. Commit 905e75c ("powerpc/fsl-pci: Unify pci/pcie initialization code") turned the PCI controller code into a platform device. Since we can't have two drivers binding to the same device, the EDAC code was changed to be called into as a library-style submodule. However, this doesn't work if the EDAC driver is built as a module. Commit 8d8fcba6d1ea ("EDAC: Rip out the edac_subsys reference counting") exposed another problem with this approach -- mpc85xx_pci_err_probe() was being called in the same early boot phase that the PCI controller is initialized, rather than in the device_initcall phase that the EDAC layer expects. This caused a crash on boot. To fix this, the PCI controller code now creates a child platform device specifically for EDAC, which the mpc85xx-pci-edac driver binds to. Reported-by: Michael Ellerman <mpe@ellerman.id.au> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Scott Wood <scottwood@freescale.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Daniel Axtens <dja@axtens.net> Cc: Doug Thompson <dougthompson@xmission.com> Cc: Jia Hongtao <B38951@freescale.com> Cc: Jiri Kosina <jkosina@suse.com> Cc: Kim Phillips <kim.phillips@freescale.com> Cc: linux-edac <linux-edac@vger.kernel.org> Cc: linuxppc-dev@lists.ozlabs.org Cc: Masanari Iida <standby24x7@gmail.com> Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Rob Herring <robh@kernel.org> Link: http://lkml.kernel.org/r/1449774432-18593-1-git-send-email-scottwood@freescale.com Signed-off-by: Borislav Petkov <bp@suse.de>
1 parent d0cdf90 commit 666db56

4 files changed

Lines changed: 68 additions & 15 deletions

File tree

‎arch/powerpc/sysdev/fsl_pci.c‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
#include <linux/pci.h>
2222
#include <linux/delay.h>
2323
#include <linux/string.h>
24+
#include <linux/fsl/edac.h>
2425
#include <linux/init.h>
2526
#include <linux/interrupt.h>
2627
#include <linux/memblock.h>
2728
#include <linux/log2.h>
29+
#include <linux/platform_device.h>
2830
#include <linux/slab.h>
2931
#include <linux/suspend.h>
3032
#include <linux/syscore_ops.h>
@@ -1255,15 +1257,39 @@ void fsl_pcibios_fixup_phb(struct pci_controller *phb)
12551257
#endif
12561258
}
12571259

1260+
static int add_err_dev(struct platform_device *pdev)
1261+
{
1262+
struct platform_device *errdev;
1263+
struct mpc85xx_edac_pci_plat_data pd = {
1264+
.of_node = pdev->dev.of_node
1265+
};
1266+
1267+
errdev = platform_device_register_resndata(&pdev->dev,
1268+
"mpc85xx-pci-edac",
1269+
PLATFORM_DEVID_AUTO,
1270+
pdev->resource,
1271+
pdev->num_resources,
1272+
&pd, sizeof(pd));
1273+
if (IS_ERR(errdev))
1274+
return PTR_ERR(errdev);
1275+
1276+
return 0;
1277+
}
1278+
12581279
static int fsl_pci_probe(struct platform_device *pdev)
12591280
{
12601281
struct device_node *node;
12611282
int ret;
12621283

12631284
node = pdev->dev.of_node;
12641285
ret = fsl_add_bridge(pdev, fsl_pci_primary == node);
1286+
if (ret)
1287+
return ret;
12651288

1266-
mpc85xx_pci_err_probe(pdev);
1289+
ret = add_err_dev(pdev);
1290+
if (ret)
1291+
dev_err(&pdev->dev, "couldn't register error device: %d\n",
1292+
ret);
12671293

12681294
return 0;
12691295
}

‎arch/powerpc/sysdev/fsl_pci.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,6 @@ void fsl_pci_assign_primary(void);
130130
static inline void fsl_pci_assign_primary(void) {}
131131
#endif
132132

133-
#ifdef CONFIG_EDAC_MPC85XX
134-
int mpc85xx_pci_err_probe(struct platform_device *op);
135-
#else
136-
static inline int mpc85xx_pci_err_probe(struct platform_device *op)
137-
{
138-
return -ENOTSUPP;
139-
}
140-
#endif
141-
142133
#ifdef CONFIG_FSL_PCI
143134
extern int fsl_pci_mcheck_exception(struct pt_regs *);
144135
#else

‎drivers/edac/mpc85xx_edac.c‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/edac.h>
2121
#include <linux/smp.h>
2222
#include <linux/gfp.h>
23+
#include <linux/fsl/edac.h>
2324

2425
#include <linux/of_platform.h>
2526
#include <linux/of_device.h>
@@ -238,10 +239,12 @@ static irqreturn_t mpc85xx_pci_isr(int irq, void *dev_id)
238239
return IRQ_HANDLED;
239240
}
240241

241-
int mpc85xx_pci_err_probe(struct platform_device *op)
242+
static int mpc85xx_pci_err_probe(struct platform_device *op)
242243
{
243244
struct edac_pci_ctl_info *pci;
244245
struct mpc85xx_pci_pdata *pdata;
246+
struct mpc85xx_edac_pci_plat_data *plat_data;
247+
struct device_node *of_node;
245248
struct resource r;
246249
int res = 0;
247250

@@ -266,7 +269,15 @@ int mpc85xx_pci_err_probe(struct platform_device *op)
266269
pdata->name = "mpc85xx_pci_err";
267270
pdata->irq = NO_IRQ;
268271

269-
if (mpc85xx_pcie_find_capability(op->dev.of_node) > 0)
272+
plat_data = op->dev.platform_data;
273+
if (!plat_data) {
274+
dev_err(&op->dev, "no platform data");
275+
res = -ENXIO;
276+
goto err;
277+
}
278+
of_node = plat_data->of_node;
279+
280+
if (mpc85xx_pcie_find_capability(of_node) > 0)
270281
pdata->is_pcie = true;
271282

272283
dev_set_drvdata(&op->dev, pci);
@@ -284,7 +295,7 @@ int mpc85xx_pci_err_probe(struct platform_device *op)
284295

285296
pdata->edac_idx = edac_pci_idx++;
286297

287-
res = of_address_to_resource(op->dev.of_node, 0, &r);
298+
res = of_address_to_resource(of_node, 0, &r);
288299
if (res) {
289300
printk(KERN_ERR "%s: Unable to get resource for "
290301
"PCI err regs\n", __func__);
@@ -339,7 +350,7 @@ int mpc85xx_pci_err_probe(struct platform_device *op)
339350
}
340351

341352
if (edac_op_state == EDAC_OPSTATE_INT) {
342-
pdata->irq = irq_of_parse_and_map(op->dev.of_node, 0);
353+
pdata->irq = irq_of_parse_and_map(of_node, 0);
343354
res = devm_request_irq(&op->dev, pdata->irq,
344355
mpc85xx_pci_isr,
345356
IRQF_SHARED,
@@ -386,8 +397,22 @@ int mpc85xx_pci_err_probe(struct platform_device *op)
386397
devres_release_group(&op->dev, mpc85xx_pci_err_probe);
387398
return res;
388399
}
389-
EXPORT_SYMBOL(mpc85xx_pci_err_probe);
390400

401+
static const struct platform_device_id mpc85xx_pci_err_match[] = {
402+
{
403+
.name = "mpc85xx-pci-edac"
404+
},
405+
{}
406+
};
407+
408+
static struct platform_driver mpc85xx_pci_err_driver = {
409+
.probe = mpc85xx_pci_err_probe,
410+
.id_table = mpc85xx_pci_err_match,
411+
.driver = {
412+
.name = "mpc85xx_pci_err",
413+
.suppress_bind_attrs = true,
414+
},
415+
};
391416
#endif /* CONFIG_PCI */
392417

393418
/**************************** L2 Err device ***************************/
@@ -1211,6 +1236,9 @@ static void __init mpc85xx_mc_clear_rfxe(void *data)
12111236
static struct platform_driver * const drivers[] = {
12121237
&mpc85xx_mc_err_driver,
12131238
&mpc85xx_l2_err_driver,
1239+
#ifdef CONFIG_PCI
1240+
&mpc85xx_pci_err_driver,
1241+
#endif
12141242
};
12151243

12161244
static int __init mpc85xx_mc_init(void)

‎include/linux/fsl/edac.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef FSL_EDAC_H
2+
#define FSL_EDAC_H
3+
4+
struct mpc85xx_edac_pci_plat_data {
5+
struct device_node *of_node;
6+
};
7+
8+
#endif

0 commit comments

Comments
 (0)