Skip to contentSkip to conversation

Add Altera peripheral memories to EDAC framework

PATCH Superseded [email protected] 3 participants 18 messages Nov 12, 2014 – Dec 2, 2014

Subsystems (6)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover Add Altera peripheral memories to EDAC framework

From: Thor Thayer <[email protected]>

This patch adds the L2 cache and OCRAM peripherals to the EDAC framework using the EDAC device framework. The ECC is enabled early in the boot process in the platform specific code.

v2 changes:
- Split On-Chip RAM ECC platform initialization into separate patch from L2 ECC platform initialization.
- Fix L2 cache dependency comments.
- Remove OCRAM node from dts and reference prior patch.

v3 changes:
- Move L2 cache & On-Chip RAM EDAC code into altera_edac.c
- Remove SDRAM module compile.

v4 changes:
- Change mask defines to use BIT().
- Fix comment style to agree with kernel coding style.
- Better printk description for read != write in trigger.
- Remove SysFS debugging message.
- Better dci->mod_name
- Move gen_pool pointer assignment to end of function.
- Invert logic to reduce indent in ocram depenency check.
- Change from dev_err() to edac_printk()
- Replace magic numbers with defines & comments.
- Improve error injection test.
- Change Makefile intermediary name to altr (from alt)

v5 changes:
- Remove l2cache.h by using if (IS_ENABLED(CONFIG_EDAC_ALTERA_L2C))
- Remove ocram.h by using if (IS_ENABLED(CONFIG_EDAC_ALTERA_OCRAM))
- Check prop variable before using. Include io.h.
- Add defines for better readability. Remove MAINTAINERS changes.

Thor Thayer (5):
arm: socfpga: Enable L2 Cache ECC on startup.
arm: socfpga: Enable OCRAM ECC on startup.
edac: altera: Remove SDRAM module compile
edac: altera: Add Altera L2 Cache and OCRAM EDAC Support
arm: dts: Add Altera L2 Cache and OCRAM EDAC

 .../bindings/arm/altera/socfpga-l2-edac.txt        |   15 +
 .../bindings/arm/altera/socfpga-ocram-edac.txt     |   16 +
 arch/arm/boot/dts/socfpga.dtsi                     |   15 +-
 arch/arm/mach-socfpga/Makefile                     |    2 +
 arch/arm/mach-socfpga/core.h                       |    3 +
 arch/arm/mach-socfpga/l2_cache.c                   |   41 ++
 arch/arm/mach-socfpga/ocram.c                      |   90 ++++
 arch/arm/mach-socfpga/socfpga.c                    |   13 +-
 drivers/edac/Kconfig                               |   18 +-
 drivers/edac/Makefile                              |    5 +-
 drivers/edac/altera_edac.c                         |  481 +++++++++++++++++++-
 11 files changed, 693 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt
 create mode 100644 arch/arm/mach-socfpga/l2_cache.c
 create mode 100644 arch/arm/mach-socfpga/ocram.c
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v5 1/5 arm: socfpga: Enable L2 Cache ECC on startup.

From: Thor Thayer <[email protected]>

This patch enables the ECC for L2 cache on machine startup. The ECC has to be enabled before data is is stored in memory otherwise the ECC will fail on reads.

---
v2: Split OCRAM initialization into separate patch.

v3/4: No change

v5: Remove l2cache.h, use io.h instead of clk-provider.h
Make copyright header inclusive. Remove MAINTAINERS entry.

---
 arch/arm/mach-socfpga/Makefile   |    1 +
 arch/arm/mach-socfpga/core.h     |    2 ++
 arch/arm/mach-socfpga/l2_cache.c |   41 ++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c  |    4 +++-
 4 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-socfpga/l2_cache.c
arch/arm/mach-socfpga/Makefile +1 -0
index 6dd7a93..142609e 100644
@@ -4,3 +4,4 @@
 
 obj-y					:= socfpga.o
 obj-$(CONFIG_SMP)	+= headsmp.o platsmp.o
+obj-$(CONFIG_EDAC_ALTERA_L2C) += l2_cache.o
arch/arm/mach-socfpga/core.h +2 -0
index 572b8f7..385baba 100644
@@ -44,4 +44,6 @@ extern unsigned long cpu1start_addr;
 
 #define SOCFPGA_SCU_VIRT_BASE   0xfffec000
 
+void socfpga_init_l2_ecc(void);
+
 #endif
arch/arm/mach-socfpga/l2_cache.c new file +41 -0

41 lines not on this page · raw message

arch/arm/mach-socfpga/socfpga.c +3 -1
index adbf383..0954011 100644
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2012 Altera Corporation
+ *  Copyright (C) 2012-2014 Altera Corporation
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -83,6 +83,8 @@ static void __init socfpga_init_irq(void)
 {
 	irqchip_init();
 	socfpga_sysmgr_init();
+	if (IS_ENABLED(CONFIG_EDAC_ALTERA_L2C))
+		socfpga_init_l2_ecc();
 }
 
 static void socfpga_cyclone5_restart(enum reboot_mode mode, const char *cmd)
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v5 2/5 arm: socfpga: Enable OCRAM ECC on startup.

In reply to [email protected]

From: Thor Thayer <[email protected]>

This patch enables the ECC for On-Chip RAM on machine startup. The ECC has to be enabled before data is is stored in memory otherwise the ECC will fail on reads.

---
v2: Split OCRAM ECC portion separately. Addition of iounmap() and reorganization of gen_pool_free. Remove defconfig from patch.

v3/4: No change

v5: Remove ocram.h, use io.h instead of clk-provider.h
Check prop in correct place. Add ECC EN defines.

---
 arch/arm/mach-socfpga/Makefile  |    1 +
 arch/arm/mach-socfpga/core.h    |    1 +
 arch/arm/mach-socfpga/ocram.c   |   90 +++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c |    9 ++++
 4 files changed, 101 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/ocram.c
arch/arm/mach-socfpga/Makefile +1 -0
index 142609e..1552ca5 100644
@@ -5,3 +5,4 @@
 obj-y					:= socfpga.o
 obj-$(CONFIG_SMP)	+= headsmp.o platsmp.o
 obj-$(CONFIG_EDAC_ALTERA_L2C) += l2_cache.o
+obj-$(CONFIG_EDAC_ALTERA_OCRAM) += ocram.o
arch/arm/mach-socfpga/core.h +1 -0
index 385baba..f3eee32 100644
@@ -45,5 +45,6 @@ extern unsigned long cpu1start_addr;
 #define SOCFPGA_SCU_VIRT_BASE   0xfffec000
 
 void socfpga_init_l2_ecc(void);
+void socfpga_init_ocram_ecc(void);
 
 #endif
arch/arm/mach-socfpga/ocram.c new file +90 -0

90 lines not on this page · raw message

arch/arm/mach-socfpga/socfpga.c +9 -0
index 0954011..065d80d 100644
@@ -100,6 +100,14 @@ static void socfpga_cyclone5_restart(enum reboot_mode mode, const char *cmd)
 	writel(temp, rst_manager_base_addr + SOCFPGA_RSTMGR_CTRL);
 }
 
+static void __init socfpga_cyclone5_init(void)
+{
+	of_platform_populate(NULL, of_default_bus_match_table,
+			     NULL, NULL);
+	if (IS_ENABLED(CONFIG_EDAC_ALTERA_OCRAM))
+		socfpga_init_ocram_ecc();
+}
+
 static const char *altera_dt_match[] = {
 	"altr,socfpga",
 	NULL
@@ -111,6 +119,7 @@ DT_MACHINE_START(SOCFPGA, "Altera SOCFPGA")
 	.smp		= smp_ops(socfpga_smp_ops),
 	.map_io		= socfpga_map_io,
 	.init_irq	= socfpga_init_irq,
+	.init_machine	= socfpga_cyclone5_init,
 	.restart	= socfpga_cyclone5_restart,
 	.dt_compat	= altera_dt_match,
 MACHINE_END
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH v5 3/5 edac: altera: Remove SDRAM module compile

In reply to [email protected]

From: Thor Thayer <[email protected]>

The SDRAM EDAC requires SDRAM configuration/initialization before SDRAM is accessed (in the preloader). Having a module compile is not desired so force to be built into kernel.

---
v3: Added in this version as a separate patch.

v4/5: No change.

---
 drivers/edac/Kconfig |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/edac/Kconfig +2 -2
index 7072c28..1719975 100644
@@ -377,8 +377,8 @@ config EDAC_OCTEON_PCI
 	  Cavium Octeon family of SOCs.
 
 config EDAC_ALTERA_MC
-	tristate "Altera SDRAM Memory Controller EDAC"
-	depends on EDAC_MM_EDAC && ARCH_SOCFPGA
+	bool "Altera SDRAM Memory Controller EDAC"
+	depends on EDAC_MM_EDAC=y && ARCH_SOCFPGA
 	help
 	  Support for error detection and correction on the
 	  Altera SDRAM memory controller. Note that the
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH v5 4/5 edac: altera: Add Altera L2 Cache and OCRAM EDAC Support

In reply to [email protected]

From: Thor Thayer <[email protected]>

Adding L2 Cache and On-Chip RAM EDAC support for the Altera SoCs using the EDAC device model. The SDRAM controller is using the Memory Controller model.

The SDRAM ECC is a separate Kconfig option because:
1) the SDRAM preparation can take almost 2 seconds on boot and some customers need a faster boot time.
2) the SDRAM has an ECC initialization dependency on the preloader which is outside the kernel. It is desirable to be able to turn the SDRAM on & off separately.

---
v2: Fix L2 dependency comments.

v3: Move OCRAM and L2 cache EDAC functions into altera_edac.c
instead of separate files.

v4: Change mask defines to use BIT().
Fix comment style to agree with kernel coding style. Better printk description for read != write in trigger. Remove SysFS debugging message.
Better dci->mod_name
Move gen_pool pointer assignment to end of function. Invert logic to reduce indent in ocram depenency check. Change from dev_err() to edac_printk()
Replace magic numbers with defines & comments. Improve error injection test.
Change Makefile intermediary name to altr (from alt)

v5: No change.

---
 drivers/edac/Kconfig       |   14 ++
 drivers/edac/Makefile      |    5 +-
 drivers/edac/altera_edac.c |  481 +++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 498 insertions(+), 2 deletions(-)
drivers/edac/Kconfig +14 -0
index 1719975..b145a52 100644
@@ -385,4 +385,18 @@ config EDAC_ALTERA_MC
 	  preloader must initialize the SDRAM before loading
 	  the kernel.
 
+config EDAC_ALTERA_L2C
+	bool "Altera L2 Cache EDAC"
+	depends on EDAC_MM_EDAC=y && ARCH_SOCFPGA && CACHE_L2X0
+	help
+	  Support for error detection and correction on the
+	  Altera L2 cache Memory for Altera SoCs.
+
+config EDAC_ALTERA_OCRAM
+	bool "Altera On-Chip RAM EDAC"
+	depends on EDAC_MM_EDAC=y && ARCH_SOCFPGA && SRAM && GENERIC_ALLOCATOR
+	help
+	  Support for error detection and correction on the
+	  Altera On-Chip RAM Memory for Altera SoCs.
+
 endif # EDAC
drivers/edac/Makefile +4 -1
index 359aa49..20e9b6f 100644
@@ -66,4 +66,7 @@ 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
+altr_edac-y				:= altera_edac.o
+obj-$(CONFIG_EDAC_ALTERA_MC)		+= altr_edac.o
+obj-$(CONFIG_EDAC_ALTERA_L2C)		+= altr_edac.o
+obj-$(CONFIG_EDAC_ALTERA_OCRAM)		+= altr_edac.o
drivers/edac/altera_edac.c +480 -1

506 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#11 lore raw

PATCH v5 5/5 arm: dts: Add Altera L2 Cache and OCRAM EDAC

In reply to [email protected]

From: Thor Thayer <[email protected]>

Adding the device tree entries and bindings needed to support the Altera L2 cache and On-Chip RAM EDAC. This patch relies upon an earlier patch to declare and setup On-chip RAM properly.
http://www.spinics.net/lists/devicetree/msg51117.html

---
v2: Remove OCRAM declaration and reference prior patch.

v3-5: No Change

---
 .../bindings/arm/altera/socfpga-l2-edac.txt        |   15 +++++++++++++++
 .../bindings/arm/altera/socfpga-ocram-edac.txt     |   16 ++++++++++++++++
 arch/arm/boot/dts/socfpga.dtsi                     |   15 ++++++++++++++-
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt
Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt new file +15 -0
new file mode 100644
index 0000000..35b19e3
@@ -0,0 +1,15 @@
+Altera SoCFPGA L2 cache Error Detection and Correction [EDAC]
+
+Required Properties:
+- compatible : Should be "altr,l2-edac"
+- reg : Address and size for ECC error interrupt clear registers.
+- interrupts : Should be single bit error interrupt, then double bit error
+	interrupt. Note the rising edge type.
+
+Example:
+
+	l2edac at ffd08140 {
+		compatible = "altr,l2-edac";
+		reg = <0xffd08140 0x4>;
+		interrupts = <0 36 1>, <0 37 1>;
+	};
Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt new file +16 -0
new file mode 100644
index 0000000..31ab205
@@ -0,0 +1,16 @@
+Altera SoCFPGA On-Chip RAM Error Detection and Correction [EDAC]
+
+OCRAM ECC Required Properties:
+- compatible : Should be "altr,ocram-edac"
+- reg : Address and size for ECC error interrupt clear registers.
+- iram : phandle to On-Chip RAM definition.
+- interrupts : Should be single bit error interrupt, then double bit error
+	interrupt. Note the rising edge type.
+
+Example:
+	ocramedac at ffd08144 {
+		compatible = "altr,ocram-edac";
+		reg = <0xffd08144 0x4>;
+		iram = <&ocram>;
+		interrupts = <0 178 1>, <0 179 1>;
+	};
arch/arm/boot/dts/socfpga.dtsi +14 -1
index 6af96ed..32c63a3 100644
@@ -618,8 +618,21 @@
 			interrupts = <0 39 4>;
 		};
 
+		l2edac at ffd08140 {
+			compatible = "altr,l2-edac";
+			reg = <0xffd08140 0x4>;
+			interrupts = <0 36 1>, <0 37 1>;
+		};
+
+		ocramedac at ffd08144 {
+			compatible = "altr,ocram-edac";
+			reg = <0xffd08144 0x4>;
+			iram = <&ocram>;
+			interrupts = <0 178 1>, <0 179 1>;
+		};
+
 		L2: l2-cache at fffef000 {
-			compatible = "arm,pl310-cache";
+			compatible = "arm,pl310-cache", "syscon";
 			reg = <0xfffef000 0x1000>;
 			interrupts = <0 38 0x04>;
 			cache-unified;
Signature · 1 line
1.7.9.5
Acked-by on v5 1/5
#2 lore raw

Re: [PATCHv5 1/5] arm: socfpga: Enable L2 Cache ECC on startup.

In reply to [email protected]
Quoted 15 lines · tthayer at opensource.altera.com

From: Thor Thayer <[email protected]>

This patch enables the ECC for L2 cache on machine startup. The ECC has to be enabled before data is is stored in memory otherwise the ECC will fail on reads.

---
v2: Split OCRAM initialization into separate patch.

v3/4: No change

v5: Remove l2cache.h, use io.h instead of clk-provider.h
Make copyright header inclusive. Remove MAINTAINERS entry.

Quoted 8 lines
---
 arch/arm/mach-socfpga/Makefile   |    1 +
 arch/arm/mach-socfpga/core.h     |    2 ++
 arch/arm/mach-socfpga/l2_cache.c |   41 ++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c  |    4 +++-
 4 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-socfpga/l2_cache.c
Acked-by on v5 2/5
#4 lore raw

Re: [PATCHv5 2/5] arm: socfpga: Enable OCRAM ECC on startup.

In reply to [email protected]
Quoted 16 lines · tthayer at opensource.altera.com

From: Thor Thayer <[email protected]>

This patch enables the ECC for On-Chip RAM on machine startup. The ECC has to be enabled before data is is stored in memory otherwise the ECC will fail on reads.

---
v2: Split OCRAM ECC portion separately. Addition of iounmap() and reorganization of gen_pool_free. Remove defconfig from patch.

v3/4: No change

v5: Remove ocram.h, use io.h instead of clk-provider.h
Check prop in correct place. Add ECC EN defines.

Quoted 8 lines
---
 arch/arm/mach-socfpga/Makefile  |    1 +
 arch/arm/mach-socfpga/core.h    |    1 +
 arch/arm/mach-socfpga/ocram.c   |   90 +++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c |    9 ++++
 4 files changed, 101 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/ocram.c
#12 lore raw

PATCH RESEND v5 5/5 arm: dts: Add Altera L2 Cache and OCRAM EDAC

In reply to [email protected]

Hi all,

Quoted 6 lines · On 11/11/2014 06:14 PM, [email protected] wrote:

From: Thor Thayer<[email protected]>

Adding the device tree entries and bindings needed to support the Altera L2 cache and On-Chip RAM EDAC. This patch relies upon an earlier patch to declare and setup On-chip RAM properly.
http://www.spinics.net/lists/devicetree/msg51117.html

Any comments on these devicetree additions?

Thanks,
Thor

Quoted 83 lines

---
v2: Remove OCRAM declaration and reference prior patch.

v3-5: No Change

---
  .../bindings/arm/altera/socfpga-l2-edac.txt        |   15 +++++++++++++++
  .../bindings/arm/altera/socfpga-ocram-edac.txt     |   16 ++++++++++++++++
  arch/arm/boot/dts/socfpga.dtsi                     |   15 ++++++++++++++-
  3 files changed, 45 insertions(+), 1 deletion(-)

create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt

Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt new file +15 -0
new file mode 100644
index 0000000..35b19e3
@@ -0,0 +1,15 @@
+Altera SoCFPGA L2 cache Error Detection and Correction [EDAC]
+
+Required Properties:
+- compatible : Should be "altr,l2-edac"
+- reg : Address and size for ECC error interrupt clear registers.
+- interrupts : Should be single bit error interrupt, then double bit error
+	interrupt. Note the rising edge type.
+
+Example:
+
+	l2edac@ffd08140 {
+		compatible = "altr,l2-edac";
+		reg = <0xffd08140 0x4>;
+		interrupts = <0 36 1>, <0 37 1>;
+	};
Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt new file +16 -0
new file mode 100644
index 0000000..31ab205
@@ -0,0 +1,16 @@
+Altera SoCFPGA On-Chip RAM Error Detection and Correction [EDAC]
+
+OCRAM ECC Required Properties:
+- compatible : Should be "altr,ocram-edac"
+- reg : Address and size for ECC error interrupt clear registers.
+- iram : phandle to On-Chip RAM definition.
+- interrupts : Should be single bit error interrupt, then double bit error
+	interrupt. Note the rising edge type.
+
+Example:
+	ocramedac@ffd08144 {
+		compatible = "altr,ocram-edac";
+		reg = <0xffd08144 0x4>;
+		iram = <&ocram>;
+		interrupts = <0 178 1>, <0 179 1>;
+	};
arch/arm/boot/dts/socfpga.dtsi +14 -1
index 6af96ed..32c63a3 100644
@@ -618,8 +618,21 @@
  			interrupts = <0 39 4>;
  		};
 
+		l2edac@ffd08140 {
+			compatible = "altr,l2-edac";
+			reg = <0xffd08140 0x4>;
+			interrupts = <0 36 1>, <0 37 1>;
+		};
+
+		ocramedac@ffd08144 {
+			compatible = "altr,ocram-edac";
+			reg = <0xffd08144 0x4>;
+			iram = <&ocram>;
+			interrupts = <0 178 1>, <0 179 1>;
+		};
+
  		L2: l2-cache@fffef000 {
-			compatible = "arm,pl310-cache";
+			compatible = "arm,pl310-cache", "syscon";
  			reg = <0xfffef000 0x1000>;
  			interrupts = <0 38 0x04>;
  			cache-unified;
#13 lore raw

Re: [RESEND PATCHv5 5/5] arm: dts: Add Altera L2 Cache and OCRAM EDAC

Hi Boris,

Quoted 10 lines · Thor Thayer

Hi all,

Quoted 6 lines · tthayer at opensource.altera.com

From: Thor Thayer<[email protected]>

Adding the device tree entries and bindings needed to support the Altera L2 cache and On-Chip RAM EDAC. This patch relies upon an earlier patch to declare and setup On-chip RAM properly.
http://www.spinics.net/lists/devicetree/msg51117.html

Quoted 10 lines

Any comments on these devicetree additions?

Thanks,
Thor

Quoted 6 lines

---
v2: Remove OCRAM declaration and reference prior patch.

v3-5: No Change
---

I originally submitted this series on November 11, 2014.

I haven't received any comments or ACKs on the device tree patch portion (patch 5 of 5). According to Documentation/devicetree/bindings/submitting-patches.txt, if the patch hasn't been Acked after a couple of weeks, the maintainer can pull the changes if they are comfortable with those changes.

Dinh checked for merge conflicts in the DTS files in his November 7 email (queued patches for 3.19).

Dinh acked patches 1 & 2 on November 12.

Thanks,

Thor

#16 lore raw

Re: [PATCHv5 5/5] arm: dts: Add Altera L2 Cache and OCRAM EDAC

In reply to [email protected]
Quoted 31 lines · tthayer at opensource.altera.com

From: Thor Thayer <[email protected]>

Adding the device tree entries and bindings needed to support the Altera L2 cache and On-Chip RAM EDAC. This patch relies upon an earlier patch to declare and setup On-chip RAM properly.
http://www.spinics.net/lists/devicetree/msg51117.html

---
v2: Remove OCRAM declaration and reference prior patch.

v3-5: No Change

---
 .../bindings/arm/altera/socfpga-l2-edac.txt        |   15 +++++++++++++++
 .../bindings/arm/altera/socfpga-ocram-edac.txt     |   16 ++++++++++++++++
 arch/arm/boot/dts/socfpga.dtsi                     |   15 ++++++++++++++-
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt
 create mode 100644 Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt
Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt new file +5 -0
new file mode 100644
index 0000000..35b19e3
@@ -0,0 +1,15 @@
+Altera SoCFPGA L2 cache Error Detection and Correction [EDAC]
+
+Required Properties:
+- compatible : Should be "altr,l2-edac"
+- reg : Address and size for ECC error interrupt clear registers.

Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt line 15

Quoted 10 lines
Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt new file +10 -0
+- interrupts : Should be single bit error interrupt, then double bit error
+	interrupt. Note the rising edge type.
+
+Example:
+
+	l2edac at ffd08140 {
+		compatible = "altr,l2-edac";
+		reg = <0xffd08140 0x4>;
+		interrupts = <0 36 1>, <0 37 1>;
+	};

Judging by the size of the reg entry, this is part of a larger block (the same one the OCRAM EDAC lives in). Why isn't that larger block described?

EDAC is a Linux subsystem name, but typically not the HW block name. What HW block does this live in?

Quoted 36 lines
Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt new file +16 -0
new file mode 100644
index 0000000..31ab205
@@ -0,0 +1,16 @@
+Altera SoCFPGA On-Chip RAM Error Detection and Correction [EDAC]
+
+OCRAM ECC Required Properties:
+- compatible : Should be "altr,ocram-edac"
+- reg : Address and size for ECC error interrupt clear registers.
+- iram : phandle to On-Chip RAM definition.
+- interrupts : Should be single bit error interrupt, then double bit error
+	interrupt. Note the rising edge type.
+
+Example:
+	ocramedac at ffd08144 {
+		compatible = "altr,ocram-edac";
+		reg = <0xffd08144 0x4>;
+		iram = <&ocram>;
+		interrupts = <0 178 1>, <0 179 1>;
+	};
arch/arm/boot/dts/socfpga.dtsi +6 -0
index 6af96ed..32c63a3 100644
@@ -618,8 +618,21 @@
 			interrupts = <0 39 4>;
 		};
 
+		l2edac at ffd08140 {
+			compatible = "altr,l2-edac";
+			reg = <0xffd08140 0x4>;
+			interrupts = <0 36 1>, <0 37 1>;
+		};
+

arch/arm/boot/dts/socfpga.dtsi line 635

Quoted 10 lines
arch/arm/boot/dts/socfpga.dtsi +8 -1
+		ocramedac at ffd08144 {
+			compatible = "altr,ocram-edac";
+			reg = <0xffd08144 0x4>;
+			iram = <&ocram>;
+			interrupts = <0 178 1>, <0 179 1>;
+		};
+
 		L2: l2-cache at fffef000 {
-			compatible = "arm,pl310-cache";
+			compatible = "arm,pl310-cache", "syscon";

NAK.

Why are you marking the PL310 as a syscon device? It is most definitely _NOT_ a shared set of registers lumped together.

Thanks,
Mark.

#14 lore raw

Re: [RESEND PATCHv5 5/5] arm: dts: Add Altera L2 Cache and OCRAM EDAC

In reply to Thor Thayer

Hi Thor,

Quoted 24 lines · Thor Thayer

Hi Boris,

Quoted 10 lines · Thor Thayer

Hi all,

Quoted 6 lines · tthayer at opensource.altera.com

From: Thor Thayer<[email protected]>

Adding the device tree entries and bindings needed to support the Altera L2 cache and On-Chip RAM EDAC. This patch relies upon an earlier patch to declare and setup On-chip RAM properly.
http://www.spinics.net/lists/devicetree/msg51117.html

Quoted 10 lines

Any comments on these devicetree additions?

Thanks,
Thor

Quoted 6 lines

---
v2: Remove OCRAM declaration and reference prior patch.

v3-5: No Change
---

Quoted 7 lines

I originally submitted this series on November 11, 2014.

I haven't received any comments or ACKs on the device tree patch portion (patch 5 of 5). According to Documentation/devicetree/bindings/submitting-patches.txt, if the patch hasn't been Acked after a couple of weeks, the maintainer can pull the changes if they are comfortable with those changes.

Apologies it has taken so long for this to be looked at. Unfortunately my inbox is overflowing (as are all of ours) and things fall by the wayside. I am sorry that this has lead to such a delayed response, especially given that it was negative.

I'll try to keep up with this a bit more actively.

Thanks,
Mark.

#5 lore raw

Re: [PATCHv5 2/5] arm: socfpga: Enable OCRAM ECC on startup.

In reply to [email protected]
Quoted 66 lines · tthayer at opensource.altera.com

From: Thor Thayer <[email protected]>

This patch enables the ECC for On-Chip RAM on machine startup. The ECC has to be enabled before data is is stored in memory otherwise the ECC will fail on reads.

---
v2: Split OCRAM ECC portion separately. Addition of iounmap() and reorganization of gen_pool_free. Remove defconfig from patch.

v3/4: No change

v5: Remove ocram.h, use io.h instead of clk-provider.h
Check prop in correct place. Add ECC EN defines.

---
 arch/arm/mach-socfpga/Makefile  |    1 +
 arch/arm/mach-socfpga/core.h    |    1 +
 arch/arm/mach-socfpga/ocram.c   |   90 +++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/socfpga.c |    9 ++++
 4 files changed, 101 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/ocram.c
arch/arm/mach-socfpga/Makefile +1 -0
index 142609e..1552ca5 100644
@@ -5,3 +5,4 @@
 obj-y					:= socfpga.o
 obj-$(CONFIG_SMP)	+= headsmp.o platsmp.o
 obj-$(CONFIG_EDAC_ALTERA_L2C) += l2_cache.o
+obj-$(CONFIG_EDAC_ALTERA_OCRAM) += ocram.o
arch/arm/mach-socfpga/core.h +1 -0
index 385baba..f3eee32 100644
@@ -45,5 +45,6 @@ extern unsigned long cpu1start_addr;
 #define SOCFPGA_SCU_VIRT_BASE   0xfffec000
 
 void socfpga_init_l2_ecc(void);
+void socfpga_init_ocram_ecc(void);
 
 #endif
arch/arm/mach-socfpga/ocram.c new file +16 -0
new file mode 100644
index 0000000..a83b34f
@@ -0,0 +1,90 @@
+/*
+ * Copyright Altera Corporation (C) 2014. All rights reserved.
+ *
+ * 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/io.h>

arch/arm/mach-socfpga/ocram.c line 26

Quoted 10 lines
arch/arm/mach-socfpga/ocram.c new file +10 -0
+#include <linux/genalloc.h>
+#include <linux/of_platform.h>
+
+#define ALTR_OCRAM_CLEAR_ECC          0x00000018
+#define ALTR_OCRAM_ECC_EN             0x00000019
+
+void socfpga_init_ocram_ecc(void)
+{
+	struct device_node *np;
+	const __be32 *prop;

Please don't use accessors which return raw __be32s in drivers, typically it's the wrong thing to do and leaves horrible bugs and/or quirks that are painful to fix up.

Quoted 8 lines
arch/arm/mach-socfpga/ocram.c new file +8 -0
+	u32 ocr_edac_addr, iram_addr, len;
+	void __iomem  *mapped_ocr_edac_addr;
+	size_t size;
+	struct gen_pool *gp;
+
+	np = of_find_compatible_node(NULL, NULL, "altr,ocram-edac");
+	if (!np) {
+		pr_err("SOCFPGA: Unable to find altr,ocram-edac in dtb\n");

arch/arm/mach-socfpga/ocram.c line 44

Quoted 10 lines
arch/arm/mach-socfpga/ocram.c new file +10 -0
+		return;
+	}
+
+	prop = of_get_property(np, "reg", &size);
+	if (!prop || size < sizeof(*prop)) {
+		pr_err("SOCFPGA: Unable to find OCRAM ECC mapping in dtb\n");
+		return;
+	}
+	ocr_edac_addr = be32_to_cpup(prop++);
+	len = be32_to_cpup(prop);

Use of_iomap(np, 0). You don't seem to pass the address around, so that should be sufficient.

Quoted 11 lines
arch/arm/mach-socfpga/ocram.c new file +11 -0
+
+	gp = of_get_named_gen_pool(np, "iram", 0);
+	if (!gp) {
+		pr_err("SOCFPGA: OCRAM cannot find gen pool\n");
+		return;
+	}
+
+	np = of_find_compatible_node(NULL, NULL, "mmio-sram");
+	if (!np) {
+		pr_err("SOCFPGA: Unable to find mmio-sram in dtb\n");
+		return;

arch/arm/mach-socfpga/ocram.c line 65

Quoted 10 lines
arch/arm/mach-socfpga/ocram.c new file +10 -0
+	}
+
+	/* Determine the OCRAM address and size */
+	prop = of_get_property(np, "reg", &size);
+	if (!prop || size < sizeof(*prop)) {
+		pr_err("SOCFPGA: Unable to find OCRAM mapping in dtb\n");
+		return;
+	}
+	iram_addr = be32_to_cpup(prop++);
+	len = be32_to_cpup(prop);

This address is overwritten below. What's going on?

arch/arm/mach-socfpga/ocram.c line 73

Quoted 8 lines
arch/arm/mach-socfpga/ocram.c new file +8 -0
+
+	iram_addr = gen_pool_alloc(gp, len);
+	if (iram_addr == 0) {
+		pr_err("SOCFPGA: cannot alloc from gen pool\n");
+		return;
+	}
+
+	memset((void *)iram_addr, 0, len);

How is the iram mapped? Is memset to it safe (e.g. it unaligned accesses are made)?

Quoted 22 lines
arch/arm/mach-socfpga/ocram.c new file +17 -0
+
+	gen_pool_free(gp, iram_addr, len);
+
+	mapped_ocr_edac_addr = ioremap(ocr_edac_addr, 4);
+	if (!mapped_ocr_edac_addr) {
+		pr_err("SOCFPGA: Unable to map OCRAM ecc regs.\n");
+		return;
+	}
+
+	/* Clear any pending OCRAM ECC interrupts, then enable ECC */
+	writel(ALTR_OCRAM_CLEAR_ECC, mapped_ocr_edac_addr);
+	writel(ALTR_OCRAM_ECC_EN, mapped_ocr_edac_addr);
+
+	iounmap(mapped_ocr_edac_addr);
+
+	pr_debug("SOCFPGA: Success Initializing OCRAM\n");
+}
arch/arm/mach-socfpga/socfpga.c +0 -0
index 0954011..065d80d 100644

arch/arm/mach-socfpga/socfpga.c static void socfpga_cyclone5_restart(enum reboot_mode mode, const char *cmd) · line 108

Quoted 9 lines
arch/arm/mach-socfpga/socfpga.c +6 -0
@@ -100,6 +100,14 @@ static void socfpga_cyclone5_restart(enum reboot_mode mode, const char *cmd)
 	writel(temp, rst_manager_base_addr + SOCFPGA_RSTMGR_CTRL);
 }
 
+static void __init socfpga_cyclone5_init(void)
+{
+	of_platform_populate(NULL, of_default_bus_match_table,
+			     NULL, NULL);
+	if (IS_ENABLED(CONFIG_EDAC_ALTERA_OCRAM))
+		socfpga_init_ocram_ecc();

If it's safe to do this after probing everything else, why can't this be a normal device probe?

Thanks,
Mark.

#9 lore raw

Re: [PATCHv5 4/5] edac: altera: Add Altera L2 Cache and OCRAM EDAC Support

In reply to [email protected]

Hi,

drivers/edac/altera_edac.c struct altr_sdram_mc_data { · line 125

Quoted 3 lines
drivers/edac/altera_edac.c +3 -0
+/* MPU L2 Register Defines */
+#define ALTR_MPUL2_CONTROL_OFFSET       0x100
+#define ALTR_MPUL2_CTL_CACHE_EN_MASK    BIT(0)

These are just standard PL310 register definitions, no?

[...]

drivers/edac/altera_edac.c static struct platform_driver altr_sdram_edac_driver = { · line 715

Quoted 9 lines
drivers/edac/altera_edac.c +9 -0
+static void *ocram_alloc_mem(size_t size, void **other)
+{
+       struct device_node *np;
+       struct gen_pool *gp;
+       void *sram_addr;
+
+       np = of_find_compatible_node(NULL, NULL, "altr,ocram-edac");
+       if (!np)
+               return NULL;

Don't you need to have a corresponding of_node_put?

Is this ever called before the code above has probed? Can't you keep this information around rather than probing it every time?

drivers/edac/altera_edac.c static struct platform_driver altr_sdram_edac_driver = { · line 725

Quoted 10 lines
drivers/edac/altera_edac.c +10 -0
+
+       gp = of_get_named_gen_pool(np, "iram", 0);
+       if (!gp)
+               return NULL;
+
+       sram_addr = (void *)gen_pool_alloc(gp, size);
+       if (!sram_addr)
+               return NULL;
+
+       memset(sram_addr, 0, size);

Is it safe to do a memset to the sram? How is it mapped?

[...]

drivers/edac/altera_edac.c static struct platform_driver altr_sdram_edac_driver = { · line 805

Quoted 11 lines
drivers/edac/altera_edac.c +11 -0
+static void *l2_alloc_mem(size_t size, void **other)
+{
+       struct device *dev = *other;
+       void *ptemp = devm_kzalloc(dev, size, GFP_KERNEL);
+
+       if (!ptemp)
+               return NULL;
+
+       /* Make sure everything is written out */
+       wmb();
+       flush_cache_all();

Doesn't this just flush out _to_ the L2 (and not beyond)? Even then I don't think that's safe with the MMU enabled.

Why is the flush necessary?

[...]

Quoted 9 lines
drivers/edac/altera_edac.c +9 -0
+static int altr_l2_dependencies(struct platform_device *pdev,
+                               void __iomem *base)
+{
+       u32 control;
+       struct regmap *l2_vbase;
+
+       control = readl(base) & ALTR_L2_ECC_EN_MASK;
+       if (!control) {
+               edac_printk(KERN_ERR, EDAC_DEVICE,

drivers/edac/altera_edac.c static struct platform_driver altr_sdram_edac_driver = { · line 859

Quoted 10 lines
drivers/edac/altera_edac.c +10 -0
+                           "L2: No ECC present, or ECC disabled\n");
+               return -ENODEV;
+       }
+
+       l2_vbase = syscon_regmap_lookup_by_compatible("arm,pl310-cache");
+       if (IS_ERR(l2_vbase)) {
+               edac_printk(KERN_ERR, EDAC_DEVICE,
+                           "L2:regmap for arm,pl310-cache lookup failed.\n");
+               return -ENODEV;
+       }

I must NAK any use of the L2 as a syscon device. It's simply not a register file that was intended to be shared. I appreciate that you only want to check something very simple, but we should use a higher level API for that (and we should add one if we do not already have one)

Quoted 35 lines
drivers/edac/altera_edac.c +28 -2
+
+       regmap_read(l2_vbase, ALTR_MPUL2_CONTROL_OFFSET, &control);
+       if (!(control & ALTR_MPUL2_CTL_CACHE_EN_MASK)) {
+               edac_printk(KERN_ERR, EDAC_DEVICE, "L2: Cache disabled\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+const struct edac_device_prv_data l2ecc_data = {
+       .setup = altr_l2_dependencies,
+       .ce_clear_mask = 0,
+       .ue_clear_mask = 0,
+#ifdef CONFIG_EDAC_DEBUG
+       .eccmgr_sysfs_attr = altr_l2_sysfs_attributes,
+       .alloc_mem = l2_alloc_mem,
+       .free_mem = l2_free_mem,
+       .ecc_enable_mask = ALTR_L2_ECC_EN_MASK,
+       .ce_set_mask = (ALTR_L2_ECC_EN_MASK | ALTR_L2_ECC_INJS_MASK),
+       .ue_set_mask = (ALTR_L2_ECC_EN_MASK | ALTR_L2_ECC_INJD_MASK),
+       .trig_alloc_sz = ALTR_TRIG_L2C_BYTE_SIZE,
+#endif
+};
+
+#endif /* #ifdef CONFIG_EDAC_ALTERA_L2C */
+
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Thor Thayer");
-MODULE_DESCRIPTION("EDAC Driver for Altera SDRAM Controller");
+MODULE_DESCRIPTION("EDAC Driver for Altera Memories");
--

1.7.9.5

#15 lore raw

Re: [RESEND PATCHv5 5/5] arm: dts: Add Altera L2 Cache and OCRAM EDAC

In reply to Mark Rutland
Quoted 40 lines · Mark Rutland

Hi Thor,

Quoted 24 lines · Thor Thayer

Hi Boris,

Quoted 10 lines · Thor Thayer

Hi all,

Quoted 6 lines · tthayer at opensource.altera.com

From: Thor Thayer<[email protected]>

Adding the device tree entries and bindings needed to support the Altera L2 cache and On-Chip RAM EDAC. This patch relies upon an earlier patch to declare and setup On-chip RAM properly.
http://www.spinics.net/lists/devicetree/msg51117.html

Quoted 10 lines

Any comments on these devicetree additions?

Thanks,
Thor

Quoted 6 lines

---
v2: Remove OCRAM declaration and reference prior patch.

v3-5: No Change
---

Quoted 7 lines

I originally submitted this series on November 11, 2014.

I haven't received any comments or ACKs on the device tree patch portion (patch 5 of 5). According to Documentation/devicetree/bindings/submitting-patches.txt, if the patch hasn't been Acked after a couple of weeks, the maintainer can pull the changes if they are comfortable with those changes.

Apologies it has taken so long for this to be looked at. Unfortunately my inbox is overflowing (as are all of ours) and things fall by the wayside. I am sorry that this has lead to such a delayed response, especially given that it was negative.

Quoted 5 lines

I'll try to keep up with this a bit more actively.

Thanks,
Mark.

Hi Mark,

Thank you for reviewing this. I have seen how busy the device tree ML is so I completely understand.

You have reviewed previous patch revisions in this series - thanks. I thought that I'd addressed most of the issues (in some cases by explaining my implementation) and since I hadn't heard anything, I assumed there weren't concerns.

Thanks again,

Thor

#6 lore raw

Re: [PATCHv5 2/5] arm: socfpga: Enable OCRAM ECC on startup.

In reply to Mark Rutland
Quoted 18 lines · Mark Rutland
Quoted 17 lines · tthayer at opensource.altera.com

From: Thor Thayer <[email protected]>

This patch enables the ECC for On-Chip RAM on machine startup. The ECC has to be enabled before data is is stored in memory otherwise the ECC will fail on reads.

---
v2: Split OCRAM ECC portion separately. Addition of iounmap() and reorganization of gen_pool_free. Remove defconfig from patch.

v3/4: No change

v5: Remove ocram.h, use io.h instead of clk-provider.h
Check prop in correct place. Add ECC EN defines.
---

<snip>

Quoted 9 lines

arch/arm/mach-socfpga/ocram.c line 26

Quoted 5 lines
arch/arm/mach-socfpga/ocram.c new file +5 -0
+
+void socfpga_init_ocram_ecc(void)
+{
+	struct device_node *np;
+	const __be32 *prop;

Please don't use accessors which return raw __be32s in drivers, typically it's the wrong thing to do and leaves horrible bugs and/or quirks that are painful to fix up.

OK. Thanks.

Quoted 37 lines
Quoted 8 lines
arch/arm/mach-socfpga/ocram.c new file +8 -0
+	u32 ocr_edac_addr, iram_addr, len;
+	void __iomem  *mapped_ocr_edac_addr;
+	size_t size;
+	struct gen_pool *gp;
+
+	np = of_find_compatible_node(NULL, NULL, "altr,ocram-edac");
+	if (!np) {
+		pr_err("SOCFPGA: Unable to find altr,ocram-edac in dtb\n");

arch/arm/mach-socfpga/ocram.c line 44

Quoted 10 lines
arch/arm/mach-socfpga/ocram.c new file +10 -0
+		return;
+	}
+
+	prop = of_get_property(np, "reg", &size);
+	if (!prop || size < sizeof(*prop)) {
+		pr_err("SOCFPGA: Unable to find OCRAM ECC mapping in dtb\n");
+		return;
+	}
+	ocr_edac_addr = be32_to_cpup(prop++);
+	len = be32_to_cpup(prop);

Use of_iomap(np, 0). You don't seem to pass the address around, so that should be sufficient.

Quoted 15 lines
arch/arm/mach-socfpga/ocram.c new file +15 -0
+
+	gp = of_get_named_gen_pool(np, "iram", 0);
+	if (!gp) {
+		pr_err("SOCFPGA: OCRAM cannot find gen pool\n");
+		return;
+	}
+
+	np = of_find_compatible_node(NULL, NULL, "mmio-sram");
+	if (!np) {
+		pr_err("SOCFPGA: Unable to find mmio-sram in dtb\n");
+		return;
+	}
+
+	/* Determine the OCRAM address and size */
+	prop = of_get_property(np, "reg", &size);
Quoted 9 lines

arch/arm/mach-socfpga/ocram.c line 65

Quoted 6 lines
arch/arm/mach-socfpga/ocram.c new file +6 -0
+	if (!prop || size < sizeof(*prop)) {
+		pr_err("SOCFPGA: Unable to find OCRAM mapping in dtb\n");
+		return;
+	}
+	iram_addr = be32_to_cpup(prop++);
+	len = be32_to_cpup(prop);

This address is overwritten below. What's going on?

Thanks, leftovers from debugging. I will look for a different way of getting the information without the be32 stuff.

Quoted 12 lines

arch/arm/mach-socfpga/ocram.c line 73

Quoted 8 lines
arch/arm/mach-socfpga/ocram.c new file +8 -0
+
+	iram_addr = gen_pool_alloc(gp, len);
+	if (iram_addr == 0) {
+		pr_err("SOCFPGA: cannot alloc from gen pool\n");
+		return;
+	}
+
+	memset((void *)iram_addr, 0, len);

How is the iram mapped? Is memset to it safe (e.g. it unaligned accesses are made)?

I will need to look at this further - good points. The entire iram should be used as a pool so I didn't expect anything unusual even though I just realized allocations are not contiguous.

Quoted 35 lines
Quoted 22 lines
arch/arm/mach-socfpga/ocram.c new file +17 -0
+
+	gen_pool_free(gp, iram_addr, len);
+
+	mapped_ocr_edac_addr = ioremap(ocr_edac_addr, 4);
+	if (!mapped_ocr_edac_addr) {
+		pr_err("SOCFPGA: Unable to map OCRAM ecc regs.\n");
+		return;
+	}
+
+	/* Clear any pending OCRAM ECC interrupts, then enable ECC */
+	writel(ALTR_OCRAM_CLEAR_ECC, mapped_ocr_edac_addr);
+	writel(ALTR_OCRAM_ECC_EN, mapped_ocr_edac_addr);
+
+	iounmap(mapped_ocr_edac_addr);
+
+	pr_debug("SOCFPGA: Success Initializing OCRAM\n");
+}
arch/arm/mach-socfpga/socfpga.c +0 -0
index 0954011..065d80d 100644

arch/arm/mach-socfpga/socfpga.c static void socfpga_cyclone5_restart(enum reboot_mode mode, const char *cmd) · line 108

Quoted 9 lines
arch/arm/mach-socfpga/socfpga.c +6 -0
@@ -100,6 +100,14 @@ static void socfpga_cyclone5_restart(enum reboot_mode mode, const char *cmd)
  	writel(temp, rst_manager_base_addr + SOCFPGA_RSTMGR_CTRL);
  }
 
+static void __init socfpga_cyclone5_init(void)
+{
+	of_platform_populate(NULL, of_default_bus_match_table,
+			     NULL, NULL);
+	if (IS_ENABLED(CONFIG_EDAC_ALTERA_OCRAM))
+		socfpga_init_ocram_ecc();

If it's safe to do this after probing everything else, why can't this be a normal device probe?

Quoted 2 lines

Thanks,
Mark.

Good point. Thank you.

#10 lore raw

Re: [PATCHv5 4/5] edac: altera: Add Altera L2 Cache and OCRAM EDAC Support

In reply to Mark Rutland
Quoted 7 lines · Mark Rutland

Hi,

drivers/edac/altera_edac.c struct altr_sdram_mc_data { · line 125

Quoted 3 lines
drivers/edac/altera_edac.c +3 -0
+/* MPU L2 Register Defines */
+#define ALTR_MPUL2_CONTROL_OFFSET       0x100
+#define ALTR_MPUL2_CTL_CACHE_EN_MASK    BIT(0)

These are just standard PL310 register definitions, no?

Yes.

Quoted 14 lines

[...]

drivers/edac/altera_edac.c static struct platform_driver altr_sdram_edac_driver = { · line 715

Quoted 9 lines
drivers/edac/altera_edac.c +9 -0
+static void *ocram_alloc_mem(size_t size, void **other)
+{
+       struct device_node *np;
+       struct gen_pool *gp;
+       void *sram_addr;
+
+       np = of_find_compatible_node(NULL, NULL, "altr,ocram-edac");
+       if (!np)
+               return NULL;

Don't you need to have a corresponding of_node_put?

Quoted 3 lines

Is this ever called before the code above has probed? Can't you keep this information around rather than probing it every time?

This is only used for testing so it happens infrequently and always after the probe has finished.

These error injection functions will not be part of the standard distribution for our board so it was cleaner to leave it out.

Quoted 4 lines
Quoted 4 lines
drivers/edac/altera_edac.c +4 -0
+
+       gp = of_get_named_gen_pool(np, "iram", 0);
+       if (!gp)
+               return NULL;
Quoted 9 lines

drivers/edac/altera_edac.c static struct platform_driver altr_sdram_edac_driver = { · line 725

Quoted 6 lines
drivers/edac/altera_edac.c +6 -0
+
+       sram_addr = (void *)gen_pool_alloc(gp, size);
+       if (!sram_addr)
+               return NULL;
+
+       memset(sram_addr, 0, size);

Is it safe to do a memset to the sram? How is it mapped?

I checked the gen_pool and the memory may not be contiguous. I will fix this. Thanks!

Quoted 17 lines

[...]

drivers/edac/altera_edac.c static struct platform_driver altr_sdram_edac_driver = { · line 805

Quoted 11 lines
drivers/edac/altera_edac.c +11 -0
+static void *l2_alloc_mem(size_t size, void **other)
+{
+       struct device *dev = *other;
+       void *ptemp = devm_kzalloc(dev, size, GFP_KERNEL);
+
+       if (!ptemp)
+               return NULL;
+
+       /* Make sure everything is written out */
+       wmb();
+       flush_cache_all();

Doesn't this just flush out _to_ the L2 (and not beyond)? Even then I don't think that's safe with the MMU enabled.

Quoted 2 lines

Why is the flush necessary?

flush_cache_all() maps to flush_kern_all() which cleans all the cache levels up to the level of coherency which includes L2 in it.

This flush ensures the data is in a known state (zero) before I inject the errors for testing L2 ECC.

Quoted 18 lines

[...]

Quoted 16 lines
drivers/edac/altera_edac.c +16 -0
+static int altr_l2_dependencies(struct platform_device *pdev,
+                               void __iomem *base)
+{
+       u32 control;
+       struct regmap *l2_vbase;
+
+       control = readl(base) & ALTR_L2_ECC_EN_MASK;
+       if (!control) {
+               edac_printk(KERN_ERR, EDAC_DEVICE,
+                           "L2: No ECC present, or ECC disabled\n");
+               return -ENODEV;
+       }
+
+       l2_vbase = syscon_regmap_lookup_by_compatible("arm,pl310-cache");
+       if (IS_ERR(l2_vbase)) {
+               edac_printk(KERN_ERR, EDAC_DEVICE,
Quoted 9 lines

drivers/edac/altera_edac.c static struct platform_driver altr_sdram_edac_driver = { · line 859

Quoted 3 lines
drivers/edac/altera_edac.c +3 -0
+                           "L2:regmap for arm,pl310-cache lookup failed.\n");
+               return -ENODEV;
+       }

I must NAK any use of the L2 as a syscon device. It's simply not a register file that was intended to be shared. I appreciate that you only want to check something very simple, but we should use a higher level API for that (and we should add one if we do not already have one)

OK. I didn't know of a way to read that register otherwise. I will rework this.

Quoted 35 lines
Quoted 35 lines
drivers/edac/altera_edac.c +28 -2
+
+       regmap_read(l2_vbase, ALTR_MPUL2_CONTROL_OFFSET, &control);
+       if (!(control & ALTR_MPUL2_CTL_CACHE_EN_MASK)) {
+               edac_printk(KERN_ERR, EDAC_DEVICE, "L2: Cache disabled\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+const struct edac_device_prv_data l2ecc_data = {
+       .setup = altr_l2_dependencies,
+       .ce_clear_mask = 0,
+       .ue_clear_mask = 0,
+#ifdef CONFIG_EDAC_DEBUG
+       .eccmgr_sysfs_attr = altr_l2_sysfs_attributes,
+       .alloc_mem = l2_alloc_mem,
+       .free_mem = l2_free_mem,
+       .ecc_enable_mask = ALTR_L2_ECC_EN_MASK,
+       .ce_set_mask = (ALTR_L2_ECC_EN_MASK | ALTR_L2_ECC_INJS_MASK),
+       .ue_set_mask = (ALTR_L2_ECC_EN_MASK | ALTR_L2_ECC_INJD_MASK),
+       .trig_alloc_sz = ALTR_TRIG_L2C_BYTE_SIZE,
+#endif
+};
+
+#endif /* #ifdef CONFIG_EDAC_ALTERA_L2C */
+
  MODULE_LICENSE("GPL v2");
  MODULE_AUTHOR("Thor Thayer");
-MODULE_DESCRIPTION("EDAC Driver for Altera SDRAM Controller");
+MODULE_DESCRIPTION("EDAC Driver for Altera Memories");
--

1.7.9.5

#17 lore raw

Re: [PATCHv5 5/5] arm: dts: Add Altera L2 Cache and OCRAM EDAC

In reply to Mark Rutland
Quoted 9 lines · Mark Rutland
Quoted 8 lines · tthayer at opensource.altera.com

From: Thor Thayer <[email protected]>

Adding the device tree entries and bindings needed to support the Altera L2 cache and On-Chip RAM EDAC. This patch relies upon an earlier patch to declare and setup On-chip RAM properly.
http://www.spinics.net/lists/devicetree/msg51117.html

<snip>

Quoted 22 lines
Quoted 7 lines

+++ b/Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt

Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt new file +5 -0
@@ -0,0 +1,15 @@
+Altera SoCFPGA L2 cache Error Detection and Correction [EDAC]
+
+Required Properties:
+- compatible : Should be "altr,l2-edac"
+- reg : Address and size for ECC error interrupt clear registers.

Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt line 15

Quoted 10 lines
Documentation/devicetree/bindings/arm/altera/socfpga-l2-edac.txt new file +10 -0
+- interrupts : Should be single bit error interrupt, then double bit error
+	interrupt. Note the rising edge type.
+
+Example:
+
+	l2edac at ffd08140 {
+		compatible = "altr,l2-edac";
+		reg = <0xffd08140 0x4>;
+		interrupts = <0 36 1>, <0 37 1>;
+	};

Judging by the size of the reg entry, this is part of a larger block (the same one the OCRAM EDAC lives in). Why isn't that larger block described?

Quoted 3 lines

EDAC is a Linux subsystem name, but typically not the HW block name. What HW block does this live in?

Yes, this register is part of the ECC block of registers. In order to get each probe function to run, the L2 EDAC and OCRAM EDAC had to be at the top level of the device tree. If they are children of a parent node, the probe functions aren't executed.
Is there a better way or example I should follow?

Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt new file +0 -0
new file mode 100644
index 0000000..31ab205

<snip>

Quoted 10 lines

Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt

Quoted 4 lines
Documentation/devicetree/bindings/arm/altera/socfpga-ocram-edac.txt new file +2 -1
+
  		L2: l2-cache at fffef000 {
-			compatible = "arm,pl310-cache";
+			compatible = "arm,pl310-cache", "syscon";

NAK.

Why are you marking the PL310 as a syscon device? It is most definitely _NOT_ a shared set of registers lumped together.

Unfortunately, the register is locked for exclusive access by the L2 cache driver. I read your comment on patch 4 and will find a better way.

Quoted 3 lines

Thanks,
Mark.