2012-06-12 02:32:33

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 0/3] EDAC support for Calxeda Highbank

From: Rob Herring <[email protected]>

This series adds EDAC support for Calxeda Highbank platform L2 and
memory ECC hardware.

This version is rebased current edac next tree for 3.6. Changes in
this version are the addition of a common edac debugfs directory and
coverting the highbank error injection to use debugfs.

Rob

Rob Herring (3):
edac: create top-level debugfs directory
edac: add support for Calxeda highbank memory controller
edac: add support for Calxeda highbank L2 cache ecc

.../devicetree/bindings/arm/calxeda/l2ecc.txt | 17 ++
.../devicetree/bindings/arm/calxeda/mem-ctrlr.txt | 17 ++
arch/arm/boot/dts/highbank.dts | 12 +
drivers/edac/Kconfig | 16 +-
drivers/edac/Makefile | 4 +
drivers/edac/edac_mc_sysfs.c | 23 +-
drivers/edac/edac_module.c | 3 +
drivers/edac/edac_module.h | 14 ++
drivers/edac/highbank_l2_edac.c | 149 ++++++++++++
drivers/edac/highbank_mc_edac.c | 256 ++++++++++++++++++++
10 files changed, 509 insertions(+), 2 deletions(-)
create mode 100644 Documentation/devicetree/bindings/arm/calxeda/l2ecc.txt
create mode 100644 Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
create mode 100644 drivers/edac/highbank_l2_edac.c
create mode 100644 drivers/edac/highbank_mc_edac.c

--
1.7.9.5


2012-06-12 02:32:48

by Rob Herring

[permalink] [raw]
Subject: [PATCH 1/3] edac: create top-level debugfs directory

From: Rob Herring <[email protected]>

Create a single, top-level "edac" directory for debugfs. An "mc[0-N]"
directory is then created for each memory controller. Individual drivers
can create additional entries such as h/w error injection control.

Signed-off-by: Rob Herring <[email protected]>
---
drivers/edac/edac_mc_sysfs.c | 23 ++++++++++++++++++++++-
drivers/edac/edac_module.c | 3 +++
drivers/edac/edac_module.h | 14 ++++++++++++++
3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 55b2f0a..a2bf7e9 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -899,13 +899,33 @@ static struct device_type mci_attr_type = {
};

#ifdef CONFIG_EDAC_DEBUG
+static struct dentry *edac_debugfs;
+
+int __init edac_debugfs_init(void)
+{
+ edac_debugfs = debugfs_create_dir("edac", NULL);
+ if (IS_ERR(edac_debugfs)) {
+ edac_debugfs = NULL;
+ return -ENOMEM;
+ }
+ return 0;
+}
+
+void __exit edac_debugfs_exit(void)
+{
+ debugfs_remove(edac_debugfs);
+}
+
int edac_create_debug_nodes(struct mem_ctl_info *mci)
{
struct dentry *d, *parent;
char name[80];
int i;

- d = debugfs_create_dir(mci->dev.kobj.name, mci->debugfs);
+ if (!edac_debugfs)
+ return -ENODEV;
+
+ d = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs);
if (!d)
return -ENOMEM;
parent = d;
@@ -930,6 +950,7 @@ int edac_create_debug_nodes(struct mem_ctl_info *mci)
if (!d)
goto nomem;

+ mci->debugfs = parent;
return 0;
nomem:
debugfs_remove(mci->debugfs);
diff --git a/drivers/edac/edac_module.c b/drivers/edac/edac_module.c
index 3454798..58a28d8 100644
--- a/drivers/edac/edac_module.c
+++ b/drivers/edac/edac_module.c
@@ -94,6 +94,8 @@ static int __init edac_init(void)
if (err)
goto error;

+ edac_debugfs_init();
+
/* Setup/Initialize the workq for this core */
err = edac_workqueue_setup();
if (err) {
@@ -118,6 +120,7 @@ static void __exit edac_exit(void)
/* tear down the various subsystems */
edac_workqueue_teardown();
edac_mc_sysfs_exit();
+ edac_debugfs_exit();
}

/*
diff --git a/drivers/edac/edac_module.h b/drivers/edac/edac_module.h
index 62de640..3d139c6 100644
--- a/drivers/edac/edac_module.h
+++ b/drivers/edac/edac_module.h
@@ -57,6 +57,20 @@ extern void edac_mc_reset_delay_period(int value);
extern void *edac_align_ptr(void **p, unsigned size, int n_elems);

/*
+ * EDAC debugfs functions
+ */
+#ifdef CONFIG_EDAC_DEBUG
+int edac_debugfs_init(void);
+void edac_debugfs_exit(void);
+#else
+static inline int edac_debugfs_init(void)
+{
+ return -ENODEV;
+}
+static inline void edac_debugfs_exit(void) {}
+#endif
+
+/*
* EDAC PCI functions
*/
#ifdef CONFIG_PCI
--
1.7.9.5

2012-06-12 02:33:25

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 3/3] edac: add support for Calxeda highbank L2 cache ecc

From: Rob Herring <[email protected]>

Add support for L2 ECC on Calxeda highbank platform.

Signed-off-by: Rob Herring <[email protected]>
---
.../devicetree/bindings/arm/calxeda/l2ecc.txt | 17 +++
arch/arm/boot/dts/highbank.dts | 6 +
drivers/edac/Kconfig | 7 +
drivers/edac/Makefile | 2 +
drivers/edac/highbank_l2_edac.c | 149 ++++++++++++++++++++
5 files changed, 181 insertions(+)
create mode 100644 Documentation/devicetree/bindings/arm/calxeda/l2ecc.txt
create mode 100644 drivers/edac/highbank_l2_edac.c

diff --git a/Documentation/devicetree/bindings/arm/calxeda/l2ecc.txt b/Documentation/devicetree/bindings/arm/calxeda/l2ecc.txt
new file mode 100644
index 0000000..f71e898
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/calxeda/l2ecc.txt
@@ -0,0 +1,17 @@
+Calxeda Highbank L2 cache ECC
+
+Properties:
+- compatible : Should be "calxeda,hb-sregs-l2-ecc"
+- reg : Address and size for ECC error interrupt clear registers.
+- interrupts : Should be single bit error interrupt, then double bit error
+ interrupt.
+
+Example:
+
+ sregs@fff3c200 {
+ compatible = "calxeda,hb-sregs-l2-ecc";
+ reg = <0xfff3c200 0x100>;
+ interrupts = <0 71 4 0 72 4>;
+ };
+
+
diff --git a/arch/arm/boot/dts/highbank.dts b/arch/arm/boot/dts/highbank.dts
index d4b4941..4d641ea 100644
--- a/arch/arm/boot/dts/highbank.dts
+++ b/arch/arm/boot/dts/highbank.dts
@@ -194,6 +194,12 @@
reg = <0xfff3c000 0x1000>;
};

+ sregs@fff3c200 {
+ compatible = "calxeda,hb-sregs-l2-ecc";
+ reg = <0xfff3c200 0x100>;
+ interrupts = <0 71 4 0 72 4>;
+ };
+
dma@fff3d000 {
compatible = "arm,pl330", "arm,primecell";
reg = <0xfff3d000 0x1000>;
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index f7efa8b..409b92b 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -309,4 +309,11 @@ config EDAC_HIGHBANK_MC
Support for error detection and correction on the
Calxeda Highbank memory controller.

+config EDAC_HIGHBANK_L2
+ tristate "Highbank L2 Cache"
+ depends on EDAC_MM_EDAC && ARCH_HIGHBANK
+ help
+ Support for error detection and correction on the
+ Calxeda Highbank memory controller.
+
endif # EDAC
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index 44f2044..a227c7f 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -57,3 +57,5 @@ obj-$(CONFIG_EDAC_AMD8131) += amd8131_edac.o
obj-$(CONFIG_EDAC_TILE) += tile_edac.o

obj-$(CONFIG_EDAC_HIGHBANK_MC) += highbank_mc_edac.o
+obj-$(CONFIG_EDAC_HIGHBANK_L2) += highbank_l2_edac.o
+
diff --git a/drivers/edac/highbank_l2_edac.c b/drivers/edac/highbank_l2_edac.c
new file mode 100644
index 0000000..e599b00
--- /dev/null
+++ b/drivers/edac/highbank_l2_edac.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2011-2012 Calxeda, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/ctype.h>
+#include <linux/edac.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/of_platform.h>
+
+#include "edac_core.h"
+#include "edac_module.h"
+
+#define SR_CLR_SB_ECC_INTR 0x0
+#define SR_CLR_DB_ECC_INTR 0x4
+
+struct hb_l2_drvdata {
+ void __iomem *base;
+ int sb_irq;
+ int db_irq;
+};
+
+static irqreturn_t highbank_l2_err_handler(int irq, void *dev_id)
+{
+ struct edac_device_ctl_info *dci = dev_id;
+ struct hb_l2_drvdata *drvdata = dci->pvt_info;
+
+ if (irq == drvdata->sb_irq) {
+ writel(1, drvdata->base + SR_CLR_SB_ECC_INTR);
+ edac_device_handle_ce(dci, 0, 0, dci->ctl_name);
+ }
+ if (irq == drvdata->db_irq) {
+ writel(1, drvdata->base + SR_CLR_DB_ECC_INTR);
+ edac_device_handle_ue(dci, 0, 0, dci->ctl_name);
+ }
+
+ return IRQ_HANDLED;
+}
+
+static int __devinit highbank_l2_err_probe(struct platform_device *pdev)
+{
+ struct edac_device_ctl_info *dci;
+ struct hb_l2_drvdata *drvdata;
+ struct resource *r;
+ int res = 0;
+
+ dci = edac_device_alloc_ctl_info(sizeof(*drvdata), "cpu",
+ 1, "L", 1, 2, NULL, 0, 0);
+ if (!dci)
+ return -ENOMEM;
+
+ drvdata = dci->pvt_info;
+ dci->dev = &pdev->dev;
+ platform_set_drvdata(pdev, dci);
+
+ if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
+ return -ENOMEM;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!r) {
+ dev_err(&pdev->dev, "Unable to get mem resource\n");
+ res = -ENODEV;
+ goto err;
+ }
+
+ if (!devm_request_mem_region(&pdev->dev, r->start,
+ resource_size(r), dev_name(&pdev->dev))) {
+ dev_err(&pdev->dev, "Error while requesting mem region\n");
+ res = -EBUSY;
+ goto err;
+ }
+
+ drvdata->base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
+ if (!drvdata->base) {
+ dev_err(&pdev->dev, "Unable to map regs\n");
+ res = -ENOMEM;
+ goto err;
+ }
+
+ drvdata->db_irq = platform_get_irq(pdev, 0);
+ res = devm_request_irq(&pdev->dev, drvdata->db_irq,
+ highbank_l2_err_handler,
+ 0, dev_name(&pdev->dev), dci);
+ if (res < 0)
+ goto err;
+
+ drvdata->sb_irq = platform_get_irq(pdev, 1);
+ res = devm_request_irq(&pdev->dev, drvdata->sb_irq,
+ highbank_l2_err_handler,
+ 0, dev_name(&pdev->dev), dci);
+ if (res < 0)
+ goto err;
+
+ dci->mod_name = dev_name(&pdev->dev);
+ dci->dev_name = dev_name(&pdev->dev);
+
+ if (edac_device_add_device(dci))
+ goto err;
+
+ devres_close_group(&pdev->dev, NULL);
+ return 0;
+err:
+ devres_release_group(&pdev->dev, NULL);
+ edac_device_free_ctl_info(dci);
+ return res;
+}
+
+static int highbank_l2_err_remove(struct platform_device *pdev)
+{
+ struct edac_device_ctl_info *dci = platform_get_drvdata(pdev);
+
+ edac_device_del_device(&pdev->dev);
+ edac_device_free_ctl_info(dci);
+ return 0;
+}
+
+static const struct of_device_id hb_l2_err_of_match[] = {
+ { .compatible = "calxeda,hb-sregs-l2-ecc", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, hb_l2_err_of_match);
+
+static struct platform_driver highbank_l2_edac_driver = {
+ .probe = highbank_l2_err_probe,
+ .remove = highbank_l2_err_remove,
+ .driver = {
+ .name = "hb_l2_edac",
+ .of_match_table = hb_l2_err_of_match,
+ },
+};
+
+module_platform_driver(highbank_l2_edac_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Calxeda, Inc.");
+MODULE_DESCRIPTION("EDAC Driver for Calxeda Highbank L2 Cache");
--
1.7.9.5

2012-06-12 02:33:23

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 2/3] edac: add support for Calxeda highbank memory controller

From: Rob Herring <[email protected]>

Add support for memory controller on Calxeda Highbank platforms. Highbank
platforms support a single 4GB mini-DIMM with 1-bit correction and 2-bit
detection.

Signed-off-by: Rob Herring <[email protected]>
---
.../devicetree/bindings/arm/calxeda/mem-ctrlr.txt | 17 ++
arch/arm/boot/dts/highbank.dts | 6 +
drivers/edac/Kconfig | 9 +-
drivers/edac/Makefile | 2 +
drivers/edac/highbank_mc_edac.c | 256 ++++++++++++++++++++
5 files changed, 289 insertions(+), 1 deletion(-)
create mode 100644 Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
create mode 100644 drivers/edac/highbank_mc_edac.c

diff --git a/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
new file mode 100644
index 0000000..5c74a0b
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
@@ -0,0 +1,17 @@
+Calxeda DDR memory controller
+
+Properties:
+- compatible : Should be "calxeda,hb-ddr-ctrl"
+- reg : Address and size for DDR controller registers.
+- interrupts : Interrupt for DDR controller.
+
+Example:
+
+ memory-controller@fff00000 {
+ compatible = "calxeda,hb-ddr-ctrl";
+ reg = <0xfff00000 0x1000>;
+ interrupts = <0 91 4>;
+ };
+
+
+
diff --git a/arch/arm/boot/dts/highbank.dts b/arch/arm/boot/dts/highbank.dts
index 83e7229..d4b4941 100644
--- a/arch/arm/boot/dts/highbank.dts
+++ b/arch/arm/boot/dts/highbank.dts
@@ -118,6 +118,12 @@
interrupts = <0 90 4>;
};

+ memory-controller@fff00000 {
+ compatible = "calxeda,hb-ddr-ctrl";
+ reg = <0xfff00000 0x1000>;
+ interrupts = <0 91 4>;
+ };
+
ipc@fff20000 {
compatible = "arm,pl320", "arm,primecell";
reg = <0xfff20000 0x1000>;
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 3b3f84f..f7efa8b 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -7,7 +7,7 @@
menuconfig EDAC
bool "EDAC (Error Detection And Correction) reporting"
depends on HAS_IOMEM
- depends on X86 || PPC || TILE
+ depends on X86 || PPC || TILE || ARM
help
EDAC is designed to report errors in the core system.
These are low-level errors that are reported in the CPU or
@@ -302,4 +302,11 @@ config EDAC_TILE
Support for error detection and correction on the
Tilera memory controller.

+config EDAC_HIGHBANK_MC
+ tristate "Highbank Memory Controller"
+ depends on EDAC_MM_EDAC && ARCH_HIGHBANK
+ help
+ Support for error detection and correction on the
+ Calxeda Highbank memory controller.
+
endif # EDAC
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index 196a63d..44f2044 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -55,3 +55,5 @@ obj-$(CONFIG_EDAC_AMD8111) += amd8111_edac.o
obj-$(CONFIG_EDAC_AMD8131) += amd8131_edac.o

obj-$(CONFIG_EDAC_TILE) += tile_edac.o
+
+obj-$(CONFIG_EDAC_HIGHBANK_MC) += highbank_mc_edac.o
diff --git a/drivers/edac/highbank_mc_edac.c b/drivers/edac/highbank_mc_edac.c
new file mode 100644
index 0000000..d00dc0b
--- /dev/null
+++ b/drivers/edac/highbank_mc_edac.c
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2011-2012 Calxeda, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/ctype.h>
+#include <linux/edac.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/of_platform.h>
+#include <linux/uaccess.h>
+
+#include "edac_core.h"
+#include "edac_module.h"
+
+/* DDR Ctrlr Error Registers */
+#define HB_DDR_ECC_OPT 0x128
+#define HB_DDR_ECC_U_ERR_ADDR 0x130
+#define HB_DDR_ECC_U_ERR_STAT 0x134
+#define HB_DDR_ECC_U_ERR_DATAL 0x138
+#define HB_DDR_ECC_U_ERR_DATAH 0x13c
+#define HB_DDR_ECC_C_ERR_ADDR 0x140
+#define HB_DDR_ECC_C_ERR_STAT 0x144
+#define HB_DDR_ECC_C_ERR_DATAL 0x148
+#define HB_DDR_ECC_C_ERR_DATAH 0x14c
+#define HB_DDR_ECC_INT_STATUS 0x180
+#define HB_DDR_ECC_INT_ACK 0x184
+#define HB_DDR_ECC_U_ERR_ID 0x424
+#define HB_DDR_ECC_C_ERR_ID 0x428
+
+#define HB_DDR_ECC_INT_STAT_CE 0x8
+#define HB_DDR_ECC_INT_STAT_DOUBLE_CE 0x10
+#define HB_DDR_ECC_INT_STAT_UE 0x20
+#define HB_DDR_ECC_INT_STAT_DOUBLE_UE 0x40
+
+#define HB_DDR_ECC_OPT_MODE_MASK 0x3
+#define HB_DDR_ECC_OPT_FWC 0x100
+#define HB_DDR_ECC_OPT_XOR_SHIFT 16
+
+struct hb_mc_drvdata {
+ void __iomem *mc_vbase;
+};
+
+static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
+{
+ struct mem_ctl_info *mci = dev_id;
+ struct hb_mc_drvdata *drvdata = mci->pvt_info;
+ u32 status, err_addr;
+
+ /* Read the interrupt status register */
+ status = readl(drvdata->mc_vbase + HB_DDR_ECC_INT_STATUS);
+
+ if (status & HB_DDR_ECC_INT_STAT_UE) {
+ err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_U_ERR_ADDR);
+ edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
+ err_addr >> PAGE_SHIFT,
+ err_addr & ~PAGE_MASK, 0,
+ 0, 0, -1,
+ mci->ctl_name, "");
+ }
+ if (status & HB_DDR_ECC_INT_STAT_CE) {
+ u32 syndrome = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_STAT);
+ syndrome = (syndrome >> 8) & 0xff;
+ err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_ADDR);
+ edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
+ err_addr >> PAGE_SHIFT,
+ err_addr & ~PAGE_MASK, syndrome,
+ 0, 0, -1,
+ mci->ctl_name, "");
+ }
+
+ /* clear the error, clears the interrupt */
+ writel(status, drvdata->mc_vbase + HB_DDR_ECC_INT_ACK);
+ return IRQ_HANDLED;
+}
+
+#ifdef CONFIG_EDAC_DEBUG
+static ssize_t highbank_mc_err_inject_write(struct file *file,
+ const char __user *data,
+ size_t count, loff_t *ppos)
+{
+ struct mem_ctl_info *mci = file->private_data;
+ struct hb_mc_drvdata *pdata = mci->pvt_info;
+ char buf[32];
+ size_t buf_size;
+ u32 reg;
+ u8 synd;
+
+ buf_size = min(count, (sizeof(buf)-1));
+ if (copy_from_user(buf, data, buf_size))
+ return -EFAULT;
+ buf[buf_size] = 0;
+
+ if (!kstrtou8(buf, 16, &synd)) {
+ reg = readl(pdata->mc_vbase + HB_DDR_ECC_OPT);
+ reg &= HB_DDR_ECC_OPT_MODE_MASK;
+ reg |= (synd << HB_DDR_ECC_OPT_XOR_SHIFT) | HB_DDR_ECC_OPT_FWC;
+ writel(reg, pdata->mc_vbase + HB_DDR_ECC_OPT);
+ }
+
+ return count;
+}
+
+static int debugfs_open(struct inode *inode, struct file *file)
+{
+ file->private_data = inode->i_private;
+ return 0;
+}
+
+static const struct file_operations highbank_mc_debug_inject_fops = {
+ .open = debugfs_open,
+ .write = highbank_mc_err_inject_write,
+ .llseek = generic_file_llseek,
+};
+#endif
+
+static int __devinit highbank_mc_probe(struct platform_device *pdev)
+{
+ struct edac_mc_layer layers[2];
+ struct mem_ctl_info *mci;
+ struct hb_mc_drvdata *drvdata;
+ struct dimm_info *dimm;
+ struct resource *r;
+ u32 control;
+ int irq;
+ int res = 0;
+
+ layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
+ layers[0].size = 1;
+ layers[0].is_virt_csrow = true;
+ layers[1].type = EDAC_MC_LAYER_CHANNEL;
+ layers[1].size = 1;
+ layers[1].is_virt_csrow = false;
+ mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers,
+ sizeof(struct hb_mc_drvdata));
+ if (!mci)
+ return -ENOMEM;
+
+ mci->pdev = &pdev->dev;
+ drvdata = mci->pvt_info;
+ platform_set_drvdata(pdev, mci);
+
+ if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
+ return -ENOMEM;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!r) {
+ dev_err(&pdev->dev, "Unable to get mem resource\n");
+ res = -ENODEV;
+ goto err;
+ }
+
+ if (!devm_request_mem_region(&pdev->dev, r->start,
+ resource_size(r), dev_name(&pdev->dev))) {
+ dev_err(&pdev->dev, "Error while requesting mem region\n");
+ res = -EBUSY;
+ goto err;
+ }
+
+ drvdata->mc_vbase = devm_ioremap(&pdev->dev,
+ r->start, resource_size(r));
+ if (!drvdata->mc_vbase) {
+ dev_err(&pdev->dev, "Unable to map regs\n");
+ res = -ENOMEM;
+ goto err;
+ }
+
+ control = readl(drvdata->mc_vbase + HB_DDR_ECC_OPT) & 0x3;
+ if (!control || (control == 0x2)) {
+ dev_err(&pdev->dev, "No ECC present, or ECC disabled\n");
+ res = -ENODEV;
+ goto err;
+ }
+
+ irq = platform_get_irq(pdev, 0);
+ res = devm_request_irq(&pdev->dev, irq, highbank_mc_err_handler,
+ 0, dev_name(&pdev->dev), mci);
+ if (res < 0) {
+ dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
+ goto err;
+ }
+
+ mci->mtype_cap = MEM_FLAG_DDR3;
+ mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
+ mci->edac_cap = EDAC_FLAG_SECDED;
+ mci->mod_name = dev_name(&pdev->dev);
+ mci->mod_ver = "1";
+ mci->ctl_name = dev_name(&pdev->dev);
+ mci->scrub_mode = SCRUB_SW_SRC;
+
+ /* Only a single 4GB DIMM is supported */
+ dimm = *mci->dimms;
+ dimm->nr_pages = (~0UL >> PAGE_SHIFT) + 1;
+ dimm->grain = 8;
+ dimm->dtype = DEV_X8;
+ dimm->mtype = MEM_DDR3;
+ dimm->edac_mode = EDAC_SECDED;
+
+ res = edac_mc_add_mc(mci);
+ if (res < 0)
+ goto err;
+
+ if (mci->debugfs)
+ debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs,
+ mci,
+ &highbank_mc_debug_inject_fops);
+
+ devres_close_group(&pdev->dev, NULL);
+ return 0;
+err:
+ devres_release_group(&pdev->dev, NULL);
+ edac_mc_free(mci);
+ return res;
+}
+
+static int highbank_mc_remove(struct platform_device *pdev)
+{
+ struct mem_ctl_info *mci = platform_get_drvdata(pdev);
+
+ edac_mc_del_mc(&pdev->dev);
+ edac_mc_free(mci);
+ return 0;
+}
+
+static const struct of_device_id hb_ddr_ctrl_of_match[] = {
+ { .compatible = "calxeda,hb-ddr-ctrl", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, hb_ddr_ctrl_of_match);
+
+static struct platform_driver highbank_mc_edac_driver = {
+ .probe = highbank_mc_probe,
+ .remove = highbank_mc_remove,
+ .driver = {
+ .name = "hb_mc_edac",
+ .of_match_table = hb_ddr_ctrl_of_match,
+ },
+};
+
+module_platform_driver(highbank_mc_edac_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Calxeda, Inc.");
+MODULE_DESCRIPTION("EDAC Driver for Calxeda Highbank");
--
1.7.9.5

2012-06-12 13:24:40

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] EDAC support for Calxeda Highbank

Hi Rob,

Em 11-06-2012 23:32, Rob Herring escreveu:
> From: Rob Herring <[email protected]>
>
> This series adds EDAC support for Calxeda Highbank platform L2 and
> memory ECC hardware.
>
> This version is rebased current edac next tree for 3.6. Changes in
> this version are the addition of a common edac debugfs directory and
> coverting the highbank error injection to use debugfs.

Thanks for the patches.

It looks OK on my eyes, with regards to the EDAC API usage. While this patch
touches at the arm/devicetree stuff, most of the changes belong to EDAC, so
I'll apply them with my SOB on my tree.

Regards,
Mauro.
>
> Rob
>
> Rob Herring (3):
> edac: create top-level debugfs directory
> edac: add support for Calxeda highbank memory controller
> edac: add support for Calxeda highbank L2 cache ecc
>
> .../devicetree/bindings/arm/calxeda/l2ecc.txt | 17 ++
> .../devicetree/bindings/arm/calxeda/mem-ctrlr.txt | 17 ++
> arch/arm/boot/dts/highbank.dts | 12 +
> drivers/edac/Kconfig | 16 +-
> drivers/edac/Makefile | 4 +
> drivers/edac/edac_mc_sysfs.c | 23 +-
> drivers/edac/edac_module.c | 3 +
> drivers/edac/edac_module.h | 14 ++
> drivers/edac/highbank_l2_edac.c | 149 ++++++++++++
> drivers/edac/highbank_mc_edac.c | 256 ++++++++++++++++++++
> 10 files changed, 509 insertions(+), 2 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/arm/calxeda/l2ecc.txt
> create mode 100644 Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
> create mode 100644 drivers/edac/highbank_l2_edac.c
> create mode 100644 drivers/edac/highbank_mc_edac.c
>

2012-06-13 14:57:21

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] EDAC support for Calxeda Highbank

Mauro,

On 06/12/2012 08:24 AM, Mauro Carvalho Chehab wrote:
> Hi Rob,
>
> Em 11-06-2012 23:32, Rob Herring escreveu:
>> From: Rob Herring <[email protected]>
>>
>> This series adds EDAC support for Calxeda Highbank platform L2 and
>> memory ECC hardware.
>>
>> This version is rebased current edac next tree for 3.6. Changes in
>> this version are the addition of a common edac debugfs directory and
>> coverting the highbank error injection to use debugfs.
>
> Thanks for the patches.
>
> It looks OK on my eyes, with regards to the EDAC API usage. While this patch
> touches at the arm/devicetree stuff, most of the changes belong to EDAC, so
> I'll apply them with my SOB on my tree.
>

I found a build error when EDAC_DEBUG is turned off.

drivers/edac/highbank_mc_edac.c: In function 'highbank_mc_probe':
drivers/edac/highbank_mc_edac.c:215:9: error: 'struct mem_ctl_info' has no member named 'debugfs'
drivers/edac/highbank_mc_edac.c:216:50: error: 'struct mem_ctl_info' has no member named 'debugfs'
drivers/edac/highbank_mc_edac.c:218:10: error: 'highbank_mc_debug_inject_fops' undeclared (first use in this function)


Do you prefer I respin the patch or do you want a follow on patch? This
is what the fix looks like:

diff --git a/drivers/edac/highbank_mc_edac.c b/drivers/edac/highbank_mc_edac.c
index d00dc0b..3185961 100644
--- a/drivers/edac/highbank_mc_edac.c
+++ b/drivers/edac/highbank_mc_edac.c
@@ -124,6 +124,22 @@ static const struct file_operations highbank_mc_debug_inject_fops = {
.write = highbank_mc_err_inject_write,
.llseek = generic_file_llseek,
};
+
+static int __devinit highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
+{
+ if (!mci->debugfs)
+ return -ENODEV;
+
+ debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs, mci,
+ &highbank_mc_debug_inject_fops);
+
+ return 0;
+}
+#else
+static int __devinit highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
+{
+ return -ENODEV;
+}
#endif

static int __devinit highbank_mc_probe(struct platform_device *pdev)
@@ -212,10 +228,7 @@ static int __devinit highbank_mc_probe(struct platform_device *pdev)
if (res < 0)
goto err;

- if (mci->debugfs)
- debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs,
- mci,
- &highbank_mc_debug_inject_fops);
+ highbank_mc_create_debugfs_nodes(mci);

devres_close_group(&pdev->dev, NULL);
return 0;


Rob

> Regards,
> Mauro.
>>
>> Rob
>>
>> Rob Herring (3):
>> edac: create top-level debugfs directory
>> edac: add support for Calxeda highbank memory controller
>> edac: add support for Calxeda highbank L2 cache ecc
>>
>> .../devicetree/bindings/arm/calxeda/l2ecc.txt | 17 ++
>> .../devicetree/bindings/arm/calxeda/mem-ctrlr.txt | 17 ++
>> arch/arm/boot/dts/highbank.dts | 12 +
>> drivers/edac/Kconfig | 16 +-
>> drivers/edac/Makefile | 4 +
>> drivers/edac/edac_mc_sysfs.c | 23 +-
>> drivers/edac/edac_module.c | 3 +
>> drivers/edac/edac_module.h | 14 ++
>> drivers/edac/highbank_l2_edac.c | 149 ++++++++++++
>> drivers/edac/highbank_mc_edac.c | 256 ++++++++++++++++++++
>> 10 files changed, 509 insertions(+), 2 deletions(-)
>> create mode 100644 Documentation/devicetree/bindings/arm/calxeda/l2ecc.txt
>> create mode 100644 Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
>> create mode 100644 drivers/edac/highbank_l2_edac.c
>> create mode 100644 drivers/edac/highbank_mc_edac.c
>>
>
>

2012-06-13 15:36:33

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] EDAC support for Calxeda Highbank

Hi Rob,


Em 13-06-2012 11:57, Rob Herring escreveu:
> Mauro,
>
> On 06/12/2012 08:24 AM, Mauro Carvalho Chehab wrote:
>> Hi Rob,
>>
>> Em 11-06-2012 23:32, Rob Herring escreveu:
>>> From: Rob Herring <[email protected]>
>>>
>>> This series adds EDAC support for Calxeda Highbank platform L2 and
>>> memory ECC hardware.
>>>
>>> This version is rebased current edac next tree for 3.6. Changes in
>>> this version are the addition of a common edac debugfs directory and
>>> coverting the highbank error injection to use debugfs.
>>
>> Thanks for the patches.
>>
>> It looks OK on my eyes, with regards to the EDAC API usage. While this patch
>> touches at the arm/devicetree stuff, most of the changes belong to EDAC, so
>> I'll apply them with my SOB on my tree.
>>
>
> I found a build error when EDAC_DEBUG is turned off.
>
> drivers/edac/highbank_mc_edac.c: In function 'highbank_mc_probe':
> drivers/edac/highbank_mc_edac.c:215:9: error: 'struct mem_ctl_info' has no member named 'debugfs'
> drivers/edac/highbank_mc_edac.c:216:50: error: 'struct mem_ctl_info' has no member named 'debugfs'
> drivers/edac/highbank_mc_edac.c:218:10: error: 'highbank_mc_debug_inject_fops' undeclared (first use in this function)
>
>
> Do you prefer I respin the patch or do you want a follow on patch?

Both approaches work for me. As such patch fixes a compilation bug, fixing the existing
patch is preferred.

> This is what the fix looks like:
>
> diff --git a/drivers/edac/highbank_mc_edac.c b/drivers/edac/highbank_mc_edac.c
> index d00dc0b..3185961 100644
> --- a/drivers/edac/highbank_mc_edac.c
> +++ b/drivers/edac/highbank_mc_edac.c
> @@ -124,6 +124,22 @@ static const struct file_operations highbank_mc_debug_inject_fops = {
> .write = highbank_mc_err_inject_write,
> .llseek = generic_file_llseek,
> };
> +
> +static int __devinit highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
> +{
> + if (!mci->debugfs)
> + return -ENODEV;
> +
> + debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs, mci,
> + &highbank_mc_debug_inject_fops);
> +
> + return 0;
> +}
> +#else
> +static int __devinit highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
> +{
> + return -ENODEV;
> +}
> #endif
>
> static int __devinit highbank_mc_probe(struct platform_device *pdev)
> @@ -212,10 +228,7 @@ static int __devinit highbank_mc_probe(struct platform_device *pdev)
> if (res < 0)
> goto err;
>
> - if (mci->debugfs)
> - debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs,
> - mci,
> - &highbank_mc_debug_inject_fops);
> + highbank_mc_create_debugfs_nodes(mci);

I would just declare the function as void, as you're not using the returned argument.

>
> devres_close_group(&pdev->dev, NULL);
> return 0;
>
>
> Rob
>
>> Regards,
>> Mauro.
>>>
>>> Rob
>>>
>>> Rob Herring (3):
>>> edac: create top-level debugfs directory
>>> edac: add support for Calxeda highbank memory controller
>>> edac: add support for Calxeda highbank L2 cache ecc
>>>
>>> .../devicetree/bindings/arm/calxeda/l2ecc.txt | 17 ++
>>> .../devicetree/bindings/arm/calxeda/mem-ctrlr.txt | 17 ++
>>> arch/arm/boot/dts/highbank.dts | 12 +
>>> drivers/edac/Kconfig | 16 +-
>>> drivers/edac/Makefile | 4 +
>>> drivers/edac/edac_mc_sysfs.c | 23 +-
>>> drivers/edac/edac_module.c | 3 +
>>> drivers/edac/edac_module.h | 14 ++
>>> drivers/edac/highbank_l2_edac.c | 149 ++++++++++++
>>> drivers/edac/highbank_mc_edac.c | 256 ++++++++++++++++++++
>>> 10 files changed, 509 insertions(+), 2 deletions(-)
>>> create mode 100644 Documentation/devicetree/bindings/arm/calxeda/l2ecc.txt
>>> create mode 100644 Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
>>> create mode 100644 drivers/edac/highbank_l2_edac.c
>>> create mode 100644 drivers/edac/highbank_mc_edac.c
>>>
>>
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-edac" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2012-06-13 17:02:11

by Rob Herring

[permalink] [raw]
Subject: [PATCH v3] edac: add support for Calxeda highbank memory controller

From: Rob Herring <[email protected]>

Add support for memory controller on Calxeda Highbank platforms. Highbank
platforms support a single 4GB mini-DIMM with 1-bit correction and 2-bit
detection.

Signed-off-by: Rob Herring <[email protected]>
---
v3: fix compile when EDAC_DEBUG is disabled

.../devicetree/bindings/arm/calxeda/mem-ctrlr.txt | 17 ++
arch/arm/boot/dts/highbank.dts | 6 +
drivers/edac/Kconfig | 9 +-
drivers/edac/Makefile | 2 +
drivers/edac/highbank_mc_edac.c | 264 ++++++++++++++++++++
5 files changed, 297 insertions(+), 1 deletion(-)
create mode 100644 Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
create mode 100644 drivers/edac/highbank_mc_edac.c

diff --git a/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
new file mode 100644
index 0000000..5c74a0b
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
@@ -0,0 +1,17 @@
+Calxeda DDR memory controller
+
+Properties:
+- compatible : Should be "calxeda,hb-ddr-ctrl"
+- reg : Address and size for DDR controller registers.
+- interrupts : Interrupt for DDR controller.
+
+Example:
+
+ memory-controller@fff00000 {
+ compatible = "calxeda,hb-ddr-ctrl";
+ reg = <0xfff00000 0x1000>;
+ interrupts = <0 91 4>;
+ };
+
+
+
diff --git a/arch/arm/boot/dts/highbank.dts b/arch/arm/boot/dts/highbank.dts
index 83e7229..d4b4941 100644
--- a/arch/arm/boot/dts/highbank.dts
+++ b/arch/arm/boot/dts/highbank.dts
@@ -118,6 +118,12 @@
interrupts = <0 90 4>;
};

+ memory-controller@fff00000 {
+ compatible = "calxeda,hb-ddr-ctrl";
+ reg = <0xfff00000 0x1000>;
+ interrupts = <0 91 4>;
+ };
+
ipc@fff20000 {
compatible = "arm,pl320", "arm,primecell";
reg = <0xfff20000 0x1000>;
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 3b3f84f..f7efa8b 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -7,7 +7,7 @@
menuconfig EDAC
bool "EDAC (Error Detection And Correction) reporting"
depends on HAS_IOMEM
- depends on X86 || PPC || TILE
+ depends on X86 || PPC || TILE || ARM
help
EDAC is designed to report errors in the core system.
These are low-level errors that are reported in the CPU or
@@ -302,4 +302,11 @@ config EDAC_TILE
Support for error detection and correction on the
Tilera memory controller.

+config EDAC_HIGHBANK_MC
+ tristate "Highbank Memory Controller"
+ depends on EDAC_MM_EDAC && ARCH_HIGHBANK
+ help
+ Support for error detection and correction on the
+ Calxeda Highbank memory controller.
+
endif # EDAC
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index 196a63d..44f2044 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -55,3 +55,5 @@ obj-$(CONFIG_EDAC_AMD8111) += amd8111_edac.o
obj-$(CONFIG_EDAC_AMD8131) += amd8131_edac.o

obj-$(CONFIG_EDAC_TILE) += tile_edac.o
+
+obj-$(CONFIG_EDAC_HIGHBANK_MC) += highbank_mc_edac.o
diff --git a/drivers/edac/highbank_mc_edac.c b/drivers/edac/highbank_mc_edac.c
new file mode 100644
index 0000000..c769f47
--- /dev/null
+++ b/drivers/edac/highbank_mc_edac.c
@@ -0,0 +1,264 @@
+/*
+ * Copyright 2011-2012 Calxeda, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/ctype.h>
+#include <linux/edac.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/of_platform.h>
+#include <linux/uaccess.h>
+
+#include "edac_core.h"
+#include "edac_module.h"
+
+/* DDR Ctrlr Error Registers */
+#define HB_DDR_ECC_OPT 0x128
+#define HB_DDR_ECC_U_ERR_ADDR 0x130
+#define HB_DDR_ECC_U_ERR_STAT 0x134
+#define HB_DDR_ECC_U_ERR_DATAL 0x138
+#define HB_DDR_ECC_U_ERR_DATAH 0x13c
+#define HB_DDR_ECC_C_ERR_ADDR 0x140
+#define HB_DDR_ECC_C_ERR_STAT 0x144
+#define HB_DDR_ECC_C_ERR_DATAL 0x148
+#define HB_DDR_ECC_C_ERR_DATAH 0x14c
+#define HB_DDR_ECC_INT_STATUS 0x180
+#define HB_DDR_ECC_INT_ACK 0x184
+#define HB_DDR_ECC_U_ERR_ID 0x424
+#define HB_DDR_ECC_C_ERR_ID 0x428
+
+#define HB_DDR_ECC_INT_STAT_CE 0x8
+#define HB_DDR_ECC_INT_STAT_DOUBLE_CE 0x10
+#define HB_DDR_ECC_INT_STAT_UE 0x20
+#define HB_DDR_ECC_INT_STAT_DOUBLE_UE 0x40
+
+#define HB_DDR_ECC_OPT_MODE_MASK 0x3
+#define HB_DDR_ECC_OPT_FWC 0x100
+#define HB_DDR_ECC_OPT_XOR_SHIFT 16
+
+struct hb_mc_drvdata {
+ void __iomem *mc_vbase;
+};
+
+static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
+{
+ struct mem_ctl_info *mci = dev_id;
+ struct hb_mc_drvdata *drvdata = mci->pvt_info;
+ u32 status, err_addr;
+
+ /* Read the interrupt status register */
+ status = readl(drvdata->mc_vbase + HB_DDR_ECC_INT_STATUS);
+
+ if (status & HB_DDR_ECC_INT_STAT_UE) {
+ err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_U_ERR_ADDR);
+ edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
+ err_addr >> PAGE_SHIFT,
+ err_addr & ~PAGE_MASK, 0,
+ 0, 0, -1,
+ mci->ctl_name, "");
+ }
+ if (status & HB_DDR_ECC_INT_STAT_CE) {
+ u32 syndrome = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_STAT);
+ syndrome = (syndrome >> 8) & 0xff;
+ err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_ADDR);
+ edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
+ err_addr >> PAGE_SHIFT,
+ err_addr & ~PAGE_MASK, syndrome,
+ 0, 0, -1,
+ mci->ctl_name, "");
+ }
+
+ /* clear the error, clears the interrupt */
+ writel(status, drvdata->mc_vbase + HB_DDR_ECC_INT_ACK);
+ return IRQ_HANDLED;
+}
+
+#ifdef CONFIG_EDAC_DEBUG
+static ssize_t highbank_mc_err_inject_write(struct file *file,
+ const char __user *data,
+ size_t count, loff_t *ppos)
+{
+ struct mem_ctl_info *mci = file->private_data;
+ struct hb_mc_drvdata *pdata = mci->pvt_info;
+ char buf[32];
+ size_t buf_size;
+ u32 reg;
+ u8 synd;
+
+ buf_size = min(count, (sizeof(buf)-1));
+ if (copy_from_user(buf, data, buf_size))
+ return -EFAULT;
+ buf[buf_size] = 0;
+
+ if (!kstrtou8(buf, 16, &synd)) {
+ reg = readl(pdata->mc_vbase + HB_DDR_ECC_OPT);
+ reg &= HB_DDR_ECC_OPT_MODE_MASK;
+ reg |= (synd << HB_DDR_ECC_OPT_XOR_SHIFT) | HB_DDR_ECC_OPT_FWC;
+ writel(reg, pdata->mc_vbase + HB_DDR_ECC_OPT);
+ }
+
+ return count;
+}
+
+static int debugfs_open(struct inode *inode, struct file *file)
+{
+ file->private_data = inode->i_private;
+ return 0;
+}
+
+static const struct file_operations highbank_mc_debug_inject_fops = {
+ .open = debugfs_open,
+ .write = highbank_mc_err_inject_write,
+ .llseek = generic_file_llseek,
+};
+
+static void __devinit highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
+{
+ if (mci->debugfs)
+ debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs, mci,
+ &highbank_mc_debug_inject_fops);
+;
+}
+#else
+static void __devinit highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
+{}
+#endif
+
+static int __devinit highbank_mc_probe(struct platform_device *pdev)
+{
+ struct edac_mc_layer layers[2];
+ struct mem_ctl_info *mci;
+ struct hb_mc_drvdata *drvdata;
+ struct dimm_info *dimm;
+ struct resource *r;
+ u32 control;
+ int irq;
+ int res = 0;
+
+ layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
+ layers[0].size = 1;
+ layers[0].is_virt_csrow = true;
+ layers[1].type = EDAC_MC_LAYER_CHANNEL;
+ layers[1].size = 1;
+ layers[1].is_virt_csrow = false;
+ mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers,
+ sizeof(struct hb_mc_drvdata));
+ if (!mci)
+ return -ENOMEM;
+
+ mci->pdev = &pdev->dev;
+ drvdata = mci->pvt_info;
+ platform_set_drvdata(pdev, mci);
+
+ if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
+ return -ENOMEM;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!r) {
+ dev_err(&pdev->dev, "Unable to get mem resource\n");
+ res = -ENODEV;
+ goto err;
+ }
+
+ if (!devm_request_mem_region(&pdev->dev, r->start,
+ resource_size(r), dev_name(&pdev->dev))) {
+ dev_err(&pdev->dev, "Error while requesting mem region\n");
+ res = -EBUSY;
+ goto err;
+ }
+
+ drvdata->mc_vbase = devm_ioremap(&pdev->dev,
+ r->start, resource_size(r));
+ if (!drvdata->mc_vbase) {
+ dev_err(&pdev->dev, "Unable to map regs\n");
+ res = -ENOMEM;
+ goto err;
+ }
+
+ control = readl(drvdata->mc_vbase + HB_DDR_ECC_OPT) & 0x3;
+ if (!control || (control == 0x2)) {
+ dev_err(&pdev->dev, "No ECC present, or ECC disabled\n");
+ res = -ENODEV;
+ goto err;
+ }
+
+ irq = platform_get_irq(pdev, 0);
+ res = devm_request_irq(&pdev->dev, irq, highbank_mc_err_handler,
+ 0, dev_name(&pdev->dev), mci);
+ if (res < 0) {
+ dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
+ goto err;
+ }
+
+ mci->mtype_cap = MEM_FLAG_DDR3;
+ mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
+ mci->edac_cap = EDAC_FLAG_SECDED;
+ mci->mod_name = dev_name(&pdev->dev);
+ mci->mod_ver = "1";
+ mci->ctl_name = dev_name(&pdev->dev);
+ mci->scrub_mode = SCRUB_SW_SRC;
+
+ /* Only a single 4GB DIMM is supported */
+ dimm = *mci->dimms;
+ dimm->nr_pages = (~0UL >> PAGE_SHIFT) + 1;
+ dimm->grain = 8;
+ dimm->dtype = DEV_X8;
+ dimm->mtype = MEM_DDR3;
+ dimm->edac_mode = EDAC_SECDED;
+
+ res = edac_mc_add_mc(mci);
+ if (res < 0)
+ goto err;
+
+ highbank_mc_create_debugfs_nodes(mci);
+
+ devres_close_group(&pdev->dev, NULL);
+ return 0;
+err:
+ devres_release_group(&pdev->dev, NULL);
+ edac_mc_free(mci);
+ return res;
+}
+
+static int highbank_mc_remove(struct platform_device *pdev)
+{
+ struct mem_ctl_info *mci = platform_get_drvdata(pdev);
+
+ edac_mc_del_mc(&pdev->dev);
+ edac_mc_free(mci);
+ return 0;
+}
+
+static const struct of_device_id hb_ddr_ctrl_of_match[] = {
+ { .compatible = "calxeda,hb-ddr-ctrl", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, hb_ddr_ctrl_of_match);
+
+static struct platform_driver highbank_mc_edac_driver = {
+ .probe = highbank_mc_probe,
+ .remove = highbank_mc_remove,
+ .driver = {
+ .name = "hb_mc_edac",
+ .of_match_table = hb_ddr_ctrl_of_match,
+ },
+};
+
+module_platform_driver(highbank_mc_edac_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Calxeda, Inc.");
+MODULE_DESCRIPTION("EDAC Driver for Calxeda Highbank");
--
1.7.9.5

2012-06-26 13:45:30

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH v3] edac: add support for Calxeda highbank memory controller

Mauro,

On 06/13/2012 12:01 PM, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> Add support for memory controller on Calxeda Highbank platforms. Highbank
> platforms support a single 4GB mini-DIMM with 1-bit correction and 2-bit
> detection.
>
> Signed-off-by: Rob Herring <[email protected]>
> ---
> v3: fix compile when EDAC_DEBUG is disabled

Ping. linux-next is broken for highbank without this fix.

Regards,
Rob

>
> .../devicetree/bindings/arm/calxeda/mem-ctrlr.txt | 17 ++
> arch/arm/boot/dts/highbank.dts | 6 +
> drivers/edac/Kconfig | 9 +-
> drivers/edac/Makefile | 2 +
> drivers/edac/highbank_mc_edac.c | 264 ++++++++++++++++++++
> 5 files changed, 297 insertions(+), 1 deletion(-)
> create mode 100644 Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
> create mode 100644 drivers/edac/highbank_mc_edac.c
>
> diff --git a/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
> new file mode 100644
> index 0000000..5c74a0b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
> @@ -0,0 +1,17 @@
> +Calxeda DDR memory controller
> +
> +Properties:
> +- compatible : Should be "calxeda,hb-ddr-ctrl"
> +- reg : Address and size for DDR controller registers.
> +- interrupts : Interrupt for DDR controller.
> +
> +Example:
> +
> + memory-controller@fff00000 {
> + compatible = "calxeda,hb-ddr-ctrl";
> + reg = <0xfff00000 0x1000>;
> + interrupts = <0 91 4>;
> + };
> +
> +
> +
> diff --git a/arch/arm/boot/dts/highbank.dts b/arch/arm/boot/dts/highbank.dts
> index 83e7229..d4b4941 100644
> --- a/arch/arm/boot/dts/highbank.dts
> +++ b/arch/arm/boot/dts/highbank.dts
> @@ -118,6 +118,12 @@
> interrupts = <0 90 4>;
> };
>
> + memory-controller@fff00000 {
> + compatible = "calxeda,hb-ddr-ctrl";
> + reg = <0xfff00000 0x1000>;
> + interrupts = <0 91 4>;
> + };
> +
> ipc@fff20000 {
> compatible = "arm,pl320", "arm,primecell";
> reg = <0xfff20000 0x1000>;
> diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
> index 3b3f84f..f7efa8b 100644
> --- a/drivers/edac/Kconfig
> +++ b/drivers/edac/Kconfig
> @@ -7,7 +7,7 @@
> menuconfig EDAC
> bool "EDAC (Error Detection And Correction) reporting"
> depends on HAS_IOMEM
> - depends on X86 || PPC || TILE
> + depends on X86 || PPC || TILE || ARM
> help
> EDAC is designed to report errors in the core system.
> These are low-level errors that are reported in the CPU or
> @@ -302,4 +302,11 @@ config EDAC_TILE
> Support for error detection and correction on the
> Tilera memory controller.
>
> +config EDAC_HIGHBANK_MC
> + tristate "Highbank Memory Controller"
> + depends on EDAC_MM_EDAC && ARCH_HIGHBANK
> + help
> + Support for error detection and correction on the
> + Calxeda Highbank memory controller.
> +
> endif # EDAC
> diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
> index 196a63d..44f2044 100644
> --- a/drivers/edac/Makefile
> +++ b/drivers/edac/Makefile
> @@ -55,3 +55,5 @@ obj-$(CONFIG_EDAC_AMD8111) += amd8111_edac.o
> obj-$(CONFIG_EDAC_AMD8131) += amd8131_edac.o
>
> obj-$(CONFIG_EDAC_TILE) += tile_edac.o
> +
> +obj-$(CONFIG_EDAC_HIGHBANK_MC) += highbank_mc_edac.o
> diff --git a/drivers/edac/highbank_mc_edac.c b/drivers/edac/highbank_mc_edac.c
> new file mode 100644
> index 0000000..c769f47
> --- /dev/null
> +++ b/drivers/edac/highbank_mc_edac.c
> @@ -0,0 +1,264 @@
> +/*
> + * Copyright 2011-2012 Calxeda, Inc.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +#include <linux/types.h>
> +#include <linux/kernel.h>
> +#include <linux/ctype.h>
> +#include <linux/edac.h>
> +#include <linux/interrupt.h>
> +#include <linux/platform_device.h>
> +#include <linux/of_platform.h>
> +#include <linux/uaccess.h>
> +
> +#include "edac_core.h"
> +#include "edac_module.h"
> +
> +/* DDR Ctrlr Error Registers */
> +#define HB_DDR_ECC_OPT 0x128
> +#define HB_DDR_ECC_U_ERR_ADDR 0x130
> +#define HB_DDR_ECC_U_ERR_STAT 0x134
> +#define HB_DDR_ECC_U_ERR_DATAL 0x138
> +#define HB_DDR_ECC_U_ERR_DATAH 0x13c
> +#define HB_DDR_ECC_C_ERR_ADDR 0x140
> +#define HB_DDR_ECC_C_ERR_STAT 0x144
> +#define HB_DDR_ECC_C_ERR_DATAL 0x148
> +#define HB_DDR_ECC_C_ERR_DATAH 0x14c
> +#define HB_DDR_ECC_INT_STATUS 0x180
> +#define HB_DDR_ECC_INT_ACK 0x184
> +#define HB_DDR_ECC_U_ERR_ID 0x424
> +#define HB_DDR_ECC_C_ERR_ID 0x428
> +
> +#define HB_DDR_ECC_INT_STAT_CE 0x8
> +#define HB_DDR_ECC_INT_STAT_DOUBLE_CE 0x10
> +#define HB_DDR_ECC_INT_STAT_UE 0x20
> +#define HB_DDR_ECC_INT_STAT_DOUBLE_UE 0x40
> +
> +#define HB_DDR_ECC_OPT_MODE_MASK 0x3
> +#define HB_DDR_ECC_OPT_FWC 0x100
> +#define HB_DDR_ECC_OPT_XOR_SHIFT 16
> +
> +struct hb_mc_drvdata {
> + void __iomem *mc_vbase;
> +};
> +
> +static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
> +{
> + struct mem_ctl_info *mci = dev_id;
> + struct hb_mc_drvdata *drvdata = mci->pvt_info;
> + u32 status, err_addr;
> +
> + /* Read the interrupt status register */
> + status = readl(drvdata->mc_vbase + HB_DDR_ECC_INT_STATUS);
> +
> + if (status & HB_DDR_ECC_INT_STAT_UE) {
> + err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_U_ERR_ADDR);
> + edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
> + err_addr >> PAGE_SHIFT,
> + err_addr & ~PAGE_MASK, 0,
> + 0, 0, -1,
> + mci->ctl_name, "");
> + }
> + if (status & HB_DDR_ECC_INT_STAT_CE) {
> + u32 syndrome = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_STAT);
> + syndrome = (syndrome >> 8) & 0xff;
> + err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_ADDR);
> + edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
> + err_addr >> PAGE_SHIFT,
> + err_addr & ~PAGE_MASK, syndrome,
> + 0, 0, -1,
> + mci->ctl_name, "");
> + }
> +
> + /* clear the error, clears the interrupt */
> + writel(status, drvdata->mc_vbase + HB_DDR_ECC_INT_ACK);
> + return IRQ_HANDLED;
> +}
> +
> +#ifdef CONFIG_EDAC_DEBUG
> +static ssize_t highbank_mc_err_inject_write(struct file *file,
> + const char __user *data,
> + size_t count, loff_t *ppos)
> +{
> + struct mem_ctl_info *mci = file->private_data;
> + struct hb_mc_drvdata *pdata = mci->pvt_info;
> + char buf[32];
> + size_t buf_size;
> + u32 reg;
> + u8 synd;
> +
> + buf_size = min(count, (sizeof(buf)-1));
> + if (copy_from_user(buf, data, buf_size))
> + return -EFAULT;
> + buf[buf_size] = 0;
> +
> + if (!kstrtou8(buf, 16, &synd)) {
> + reg = readl(pdata->mc_vbase + HB_DDR_ECC_OPT);
> + reg &= HB_DDR_ECC_OPT_MODE_MASK;
> + reg |= (synd << HB_DDR_ECC_OPT_XOR_SHIFT) | HB_DDR_ECC_OPT_FWC;
> + writel(reg, pdata->mc_vbase + HB_DDR_ECC_OPT);
> + }
> +
> + return count;
> +}
> +
> +static int debugfs_open(struct inode *inode, struct file *file)
> +{
> + file->private_data = inode->i_private;
> + return 0;
> +}
> +
> +static const struct file_operations highbank_mc_debug_inject_fops = {
> + .open = debugfs_open,
> + .write = highbank_mc_err_inject_write,
> + .llseek = generic_file_llseek,
> +};
> +
> +static void __devinit highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
> +{
> + if (mci->debugfs)
> + debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs, mci,
> + &highbank_mc_debug_inject_fops);
> +;
> +}
> +#else
> +static void __devinit highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
> +{}
> +#endif
> +
> +static int __devinit highbank_mc_probe(struct platform_device *pdev)
> +{
> + struct edac_mc_layer layers[2];
> + struct mem_ctl_info *mci;
> + struct hb_mc_drvdata *drvdata;
> + struct dimm_info *dimm;
> + struct resource *r;
> + u32 control;
> + int irq;
> + int res = 0;
> +
> + layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
> + layers[0].size = 1;
> + layers[0].is_virt_csrow = true;
> + layers[1].type = EDAC_MC_LAYER_CHANNEL;
> + layers[1].size = 1;
> + layers[1].is_virt_csrow = false;
> + mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers,
> + sizeof(struct hb_mc_drvdata));
> + if (!mci)
> + return -ENOMEM;
> +
> + mci->pdev = &pdev->dev;
> + drvdata = mci->pvt_info;
> + platform_set_drvdata(pdev, mci);
> +
> + if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
> + return -ENOMEM;
> +
> + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!r) {
> + dev_err(&pdev->dev, "Unable to get mem resource\n");
> + res = -ENODEV;
> + goto err;
> + }
> +
> + if (!devm_request_mem_region(&pdev->dev, r->start,
> + resource_size(r), dev_name(&pdev->dev))) {
> + dev_err(&pdev->dev, "Error while requesting mem region\n");
> + res = -EBUSY;
> + goto err;
> + }
> +
> + drvdata->mc_vbase = devm_ioremap(&pdev->dev,
> + r->start, resource_size(r));
> + if (!drvdata->mc_vbase) {
> + dev_err(&pdev->dev, "Unable to map regs\n");
> + res = -ENOMEM;
> + goto err;
> + }
> +
> + control = readl(drvdata->mc_vbase + HB_DDR_ECC_OPT) & 0x3;
> + if (!control || (control == 0x2)) {
> + dev_err(&pdev->dev, "No ECC present, or ECC disabled\n");
> + res = -ENODEV;
> + goto err;
> + }
> +
> + irq = platform_get_irq(pdev, 0);
> + res = devm_request_irq(&pdev->dev, irq, highbank_mc_err_handler,
> + 0, dev_name(&pdev->dev), mci);
> + if (res < 0) {
> + dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
> + goto err;
> + }
> +
> + mci->mtype_cap = MEM_FLAG_DDR3;
> + mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
> + mci->edac_cap = EDAC_FLAG_SECDED;
> + mci->mod_name = dev_name(&pdev->dev);
> + mci->mod_ver = "1";
> + mci->ctl_name = dev_name(&pdev->dev);
> + mci->scrub_mode = SCRUB_SW_SRC;
> +
> + /* Only a single 4GB DIMM is supported */
> + dimm = *mci->dimms;
> + dimm->nr_pages = (~0UL >> PAGE_SHIFT) + 1;
> + dimm->grain = 8;
> + dimm->dtype = DEV_X8;
> + dimm->mtype = MEM_DDR3;
> + dimm->edac_mode = EDAC_SECDED;
> +
> + res = edac_mc_add_mc(mci);
> + if (res < 0)
> + goto err;
> +
> + highbank_mc_create_debugfs_nodes(mci);
> +
> + devres_close_group(&pdev->dev, NULL);
> + return 0;
> +err:
> + devres_release_group(&pdev->dev, NULL);
> + edac_mc_free(mci);
> + return res;
> +}
> +
> +static int highbank_mc_remove(struct platform_device *pdev)
> +{
> + struct mem_ctl_info *mci = platform_get_drvdata(pdev);
> +
> + edac_mc_del_mc(&pdev->dev);
> + edac_mc_free(mci);
> + return 0;
> +}
> +
> +static const struct of_device_id hb_ddr_ctrl_of_match[] = {
> + { .compatible = "calxeda,hb-ddr-ctrl", },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, hb_ddr_ctrl_of_match);
> +
> +static struct platform_driver highbank_mc_edac_driver = {
> + .probe = highbank_mc_probe,
> + .remove = highbank_mc_remove,
> + .driver = {
> + .name = "hb_mc_edac",
> + .of_match_table = hb_ddr_ctrl_of_match,
> + },
> +};
> +
> +module_platform_driver(highbank_mc_edac_driver);
> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_AUTHOR("Calxeda, Inc.");
> +MODULE_DESCRIPTION("EDAC Driver for Calxeda Highbank");

2012-06-27 12:13:29

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH v3] edac: add support for Calxeda highbank memory controller

Em 26-06-2012 10:45, Rob Herring escreveu:
> Mauro,
>
> On 06/13/2012 12:01 PM, Rob Herring wrote:
>> From: Rob Herring <[email protected]>
>>
>> Add support for memory controller on Calxeda Highbank platforms. Highbank
>> platforms support a single 4GB mini-DIMM with 1-bit correction and 2-bit
>> detection.
>>
>> Signed-off-by: Rob Herring <[email protected]>
>> ---
>> v3: fix compile when EDAC_DEBUG is disabled
>
> Ping. linux-next is broken for highbank without this fix.

Patch replaced and merged on my trees (with a minor change, see below).

-next should likely get the fix tomorrow.

Thanks,
Mauro.

>> .../devicetree/bindings/arm/calxeda/mem-ctrlr.txt | 17 ++
>> arch/arm/boot/dts/highbank.dts | 6 +
>> drivers/edac/Kconfig | 9 +-
>> drivers/edac/Makefile | 2 +
>> drivers/edac/highbank_mc_edac.c | 264 ++++++++++++++++++++
>> 5 files changed, 297 insertions(+), 1 deletion(-)
>> create mode 100644 Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
>> create mode 100644 drivers/edac/highbank_mc_edac.c
>>
>> diff --git a/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
>> new file mode 100644
>> index 0000000..5c74a0b
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
>> @@ -0,0 +1,17 @@
>> +Calxeda DDR memory controller
>> +
>> +Properties:
>> +- compatible : Should be "calxeda,hb-ddr-ctrl"
>> +- reg : Address and size for DDR controller registers.
>> +- interrupts : Interrupt for DDR controller.
>> +
>> +Example:
>> +
>> + memory-controller@fff00000 {
>> + compatible = "calxeda,hb-ddr-ctrl";
>> + reg = <0xfff00000 0x1000>;
>> + interrupts = <0 91 4>;
>> + };
>> +
>> +
>> +

There are some extra blank likes at the end of this file. I removed them.