Skip to contentSkip to conversation

Addition of EDAC for Altera SoC SDRAM Controller

PATCH Superseded [email protected] 3 participants 6 messages May 12, 2014 – May 14, 2014

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#1 lore raw

PATCH v4 1/3 dts: socfpga: Add bindings for Altera SoC SDRAM controller

In reply to [email protected]

From: Thor Thayer <[email protected]>

Addition of the Altera SDRAM controller bindings and device tree changes to the Altera SoC project.

v2: Changes to SoC SDRAM EDAC code.

v3: Implement code suggestions for SDRAM EDAC code.

v4: Remove syscon from SDRAM controller bindings.

---
 .../bindings/arm/altera/socfpga-sdram.txt          |   11 +++++++++++
 arch/arm/boot/dts/socfpga.dtsi                     |    5 +++++
 2 files changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-sdram.txt
Documentation/devicetree/bindings/arm/altera/socfpga-sdram.txt new file +11 -0
new file mode 100644
index 0000000..8f8746b
@@ -0,0 +1,11 @@
+Altera SOCFPGA SDRAM Controller
+
+Required properties:
+- compatible : "altr,sdr-ctl";
+- reg : Should contain 1 register ranges(address and length)
+
+Example:
+	sdrctl@ffc25000 {
+		compatible = "altr,sdr-ctl";
+		reg = <0xffc25000 0x1000>;
+	};
arch/arm/boot/dts/socfpga.dtsi +5 -0
index df43702..6ce912e 100644
@@ -676,6 +676,11 @@
 			clocks = <&l4_sp_clk>;
 		};
 
+		sdrctl@ffc25000 {
+			compatible = "altr,sdr-ctl", "syscon";
+			reg = <0xffc25000 0x1000>;
+		};
+
 		rstmgr@ffd05000 {
 			compatible = "altr,rst-mgr";
 			reg = <0xffd05000 0x1000>;
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v4 2/3 dts: socfpga: Add bindings for Altera SoC SDRAM EDAC

In reply to [email protected]

From: Thor Thayer <[email protected]>

Addition of the Altera SDRAM EDAC bindings and device tree changes to the Altera SoC project.

v2: Changes to SoC EDAC source code.

v3: Fix typo in device tree documentation.

v4: No changes - bump version for consistency.

---
 .../bindings/arm/altera/socfpga-sdram-edac.txt     |   12 ++++++++++++
 arch/arm/boot/dts/socfpga.dtsi                     |    5 +++++
 2 files changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-sdram-edac.txt
Documentation/devicetree/bindings/arm/altera/socfpga-sdram-edac.txt new file +12 -0
new file mode 100644
index 0000000..431e98b
@@ -0,0 +1,12 @@
+Altera SOCFPGA SDRAM Error Detection & Correction [EDAC]
+
+Required properties:
+- compatible : should contain "altr,sdram-edac";
+- interrupts : Should contain the SDRAM ECC IRQ in the
+	appropriate format for the IRQ controller.
+
+Example:
+	sdramedac@0 {
+		compatible = "altr,sdram-edac";
+		interrupts = <0 39 4>;
+	};
arch/arm/boot/dts/socfpga.dtsi +5 -0
index 6ce912e..a0ea69b 100644
@@ -681,6 +681,11 @@
 			reg = <0xffc25000 0x1000>;
 		};
 
+		sdramedac@0 {
+			compatible = "altr,sdram-edac";
+			interrupts = <0 39 4>;
+		};
+
 		rstmgr@ffd05000 {
 			compatible = "altr,rst-mgr";
 			reg = <0xffd05000 0x1000>;
Signature · 1 line
1.7.9.5
#0 lore raw

[PATCHv4 1/3] dts: socfpga: Add bindings for Altera SoC SDRAM [PATCHv4 2/3] dts: socfpga: Add bindings for Altera SoC SDRAM EDAC [PATCHv4 3/3] edac: altera: Add EDAC support for Altera SoC SDRAM Controller

#3 lore raw

PATCH v4 3/3 edac: altera: Add EDAC support for Altera SoC SDRAM Controller

From: Thor Thayer <[email protected]>

This patch adds EDAC support for reporting ECC errors of CycloneV and ArriaV SDRAM controllers.
- The SDRAM Controller registers are shared with the FPGA bridge so these are accessed through the syscon interface.
- The configuration of the SDRAM memory size for the EDAC framework is discovered from the SDRAM Controller registers.
- Documentation of the bindings in devicetree/bindings/arm/altera/ socfpga-sdram-edac.txt
- Correction & reporting of single bit errors, panic on double bit errors.

v2: Use the SDRAM controller registers to calculate memory size
instead of the Device Tree. Update To & Cc list. Add maintainer information.

v3: EDAC driver cleanup based on comments from Mailing list.

v4: Panic on DBE. Add macro around inject-error reads to prevent
them from being optimized out. Remove of_match_ptr since this will always use Device Tree.

---
 MAINTAINERS                |    5 +
 drivers/edac/Kconfig       |    9 +
 drivers/edac/Makefile      |    2 +
 drivers/edac/altera_edac.c |  416 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 432 insertions(+)
 create mode 100644 drivers/edac/altera_edac.c
MAINTAINERS +5 -0
index e67ea24..ecd1277 100644
@@ -1290,6 +1290,11 @@ M:	Dinh Nguyen <[email protected]>
 S:	Maintained
 F:	drivers/clk/socfpga/
 
+ARM/SOCFPGA SDRAM EDAC SUPPORT
+M:	Thor Thayer <[email protected]>
+S:	Maintained
+F:	drivers/edac/altera_edac.c
+
 ARM/STI ARCHITECTURE
 M:	Srinivas Kandagatla <[email protected]>
 M:	Maxime Coquelin <[email protected]>
drivers/edac/Kconfig +9 -0
index 878f090..4f4d379 100644
@@ -368,4 +368,13 @@ config EDAC_OCTEON_PCI
 	  Support for error detection and correction on the
 	  Cavium Octeon family of SOCs.
 
+config EDAC_ALTERA_MC
+	bool "Altera SDRAM Memory Controller EDAC"
+	depends on EDAC_MM_EDAC && ARCH_SOCFPGA
+	help
+	  Support for error detection and correction on the
+	  Altera SDRAM memory controller. Note that the
+	  preloader must initialize the SDRAM before loading
+	  the kernel.
+
 endif # EDAC
drivers/edac/Makefile +2 -0
index 4154ed6..9741336 100644
@@ -64,3 +64,5 @@ obj-$(CONFIG_EDAC_OCTEON_PC)		+= octeon_edac-pc.o
 obj-$(CONFIG_EDAC_OCTEON_L2C)		+= octeon_edac-l2c.o
 obj-$(CONFIG_EDAC_OCTEON_LMC)		+= octeon_edac-lmc.o
 obj-$(CONFIG_EDAC_OCTEON_PCI)		+= octeon_edac-pci.o
+
+obj-$(CONFIG_EDAC_ALTERA_MC)	        += altera_edac.o
drivers/edac/altera_edac.c new file +416 -0

416 lines not on this page · raw message

Signature · 1 line
1.7.9.5
maintainer
#4 lore raw

Re: [PATCHv4 3/3] edac: altera: Add EDAC support for Altera SoC SDRAM Controller

Quoted 7 lines · tthayer at altera.com
drivers/edac/altera_edac.c new file +7 -0
+	ptemp[0] = 0x5A5A5A5A;
+	ptemp[1] = 0xA5A5A5A5;
+	/* Clear the error injection bits */
+	regmap_write(drvdata->mc_vbase,	CTLCFG, read_reg);
+	/* Ensure it has been written out */
+	wmb();
+

drivers/edac/altera_edac.c line 204

Quoted 10 lines
drivers/edac/altera_edac.c new file +10 -0
+	/*
+	 * To trigger the error, we need to read the data back
+	 * (the data was written with errors above)
+	 * The ACCESS_ONCE macros are used to prevent the
+	 * compiler optimizing these reads out.
+	 */
+	reg = ACCESS_ONCE(ptemp[0]);
+	read_reg = ACCESS_ONCE(ptemp[1]);
+	/* Force Read */
+	rmb();

Right, I still am a bit unsure about this thing. So sure, we funnel ptemp through an asm() block which stops the optimizer but we assign the results to reg and read_reg, i.e. two local variables which aren't used in this function anymore.

Thus, I don't see what stops the compiler from discarding them along with the ACCESS_ONCE() reads at some point, when it becomes really smart. Basically killing

drivers/edac/altera_edac.c line 202

Quoted 2 lines
drivers/edac/altera_edac.c new file +2 -0
+     reg = ACCESS_ONCE(ptemp[0]);
+     read_reg = ACCESS_ONCE(ptemp[1]);

as they have to effect.

Maybe we can do the reads in asm - this should be pretty safe.

I.e., something like this:

      asm volatile("" : "=r" (reg), "=r" (read_reg),
		      : "0" (ptemp[0]), "1" (ptemp[1]));

and it does it on x86 (did a small test program) by shuffling the values through registers so we definitely have the reads.

	.loc 1 28 0
	movl	-48(%rbp), %edx	# ptemp, D.2240
	movl	-44(%rbp), %eax	# ptemp, D.2240
	.loc 1 27 0
	movl	%edx, -28(%rbp)	# reg, reg
	movl	%eax, -32(%rbp)	# read_reg, read_reg

Btw, if you only want to do the reads, you can simply tell gcc to put them in registers

      asm volatile("" :: "r" (ptemp[0]), "r" (ptemp[1]));

and be done with it but I don't know how smart it is with register allocation so as to recognize that they're already in registers (when they already are in some registers) and discard the reads.

Fun stuff! :-)

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#5 lore raw

Re: [PATCHv4 3/3] edac: altera: Add EDAC support for Altera SoC SDRAM Controller

Quoted 59 lines · Borislav Petkov
Quoted 7 lines · tthayer at altera.com
drivers/edac/altera_edac.c new file +7 -0
+     ptemp[0] = 0x5A5A5A5A;
+     ptemp[1] = 0xA5A5A5A5;
+     /* Clear the error injection bits */
+     regmap_write(drvdata->mc_vbase, CTLCFG, read_reg);
+     /* Ensure it has been written out */
+     wmb();
+

drivers/edac/altera_edac.c line 204

Quoted 10 lines
drivers/edac/altera_edac.c new file +10 -0
+     /*
+      * To trigger the error, we need to read the data back
+      * (the data was written with errors above)
+      * The ACCESS_ONCE macros are used to prevent the
+      * compiler optimizing these reads out.
+      */
+     reg = ACCESS_ONCE(ptemp[0]);
+     read_reg = ACCESS_ONCE(ptemp[1]);
+     /* Force Read */
+     rmb();

Right, I still am a bit unsure about this thing. So sure, we funnel ptemp through an asm() block which stops the optimizer but we assign the results to reg and read_reg, i.e. two local variables which aren't used in this function anymore.

Thus, I don't see what stops the compiler from discarding them along with the ACCESS_ONCE() reads at some point, when it becomes really smart. Basically killing

drivers/edac/altera_edac.c line 202

Quoted 2 lines
drivers/edac/altera_edac.c new file +2 -0
+     reg = ACCESS_ONCE(ptemp[0]);
+     read_reg = ACCESS_ONCE(ptemp[1]);

as they have to effect.

Maybe we can do the reads in asm - this should be pretty safe.

I.e., something like this:

      asm volatile("" : "=r" (reg), "=r" (read_reg),
                      : "0" (ptemp[0]), "1" (ptemp[1]));

and it does it on x86 (did a small test program) by shuffling the values through registers so we definitely have the reads.

        .loc 1 28 0
        movl    -48(%rbp), %edx # ptemp, D.2240
        movl    -44(%rbp), %eax # ptemp, D.2240
        .loc 1 27 0
        movl    %edx, -28(%rbp) # reg, reg
        movl    %eax, -32(%rbp) # read_reg, read_reg

Btw, if you only want to do the reads, you can simply tell gcc to put them in registers

      asm volatile("" :: "r" (ptemp[0]), "r" (ptemp[1]));

and be done with it but I don't know how smart it is with register allocation so as to recognize that they're already in registers (when they already are in some registers) and discard the reads.

Quoted 8 lines

Fun stuff! :-)

--
Regards/Gruss,
Boris.

Sent from a fat crate under my desk. Formatting is fine. --

Hi Boris.

I'll look into that. I think I will use the registers in a edac_printk(). Since this is a debugging trigger function, the printout may be useful anyway.

Thanks!