Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1659307 > unrolled thread

EDAC: simplify total memory calculation

Started byChris Packham <chris.packham@alliedtelesis.co.nz>
First post2017-06-07 02:00 +0200
Last post2017-06-07 02:00 +0200
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  EDAC: simplify total memory calculation Chris Packham <chris.packham@alliedtelesis.co.nz> - 2017-06-07 02:00 +0200
    [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory Chris Packham <chris.packham@alliedtelesis.co.nz> - 2017-06-07 02:00 +0200
    [PATCH v2 1/3] EDAC: mv64x60: calculate memory size correctly Chris Packham <chris.packham@alliedtelesis.co.nz> - 2017-06-07 02:00 +0200

#1659307 — EDAC: simplify total memory calculation

FromChris Packham <chris.packham@alliedtelesis.co.nz>
Date2017-06-07 02:00 +0200
SubjectEDAC: simplify total memory calculation
Message-ID<tPwye-7dr-11@gated-at.bofh.it>
This take the approach used by cell_edac.c to obtain the total memory from
the devicetree and applies it to mv64x60_edac.c, altera_edac.c and
cpc925_edac.c which were all manually parsing the reg property. In the case
of mv64x60 this actually fixes cases where #address/size-cells != 1. For
altera and cpc925 this is just a cleanup.

Chris Packham (3):
  EDAC: mv64x60: calculate memory size correctly
  EDAC: altera: simplify calculation of total memory
  EDAC: cpc925: simplify calculation of total memory

 drivers/edac/altera_edac.c  | 24 ++++++++----------------
 drivers/edac/cpc925_edac.c  | 32 ++++++++++----------------------
 drivers/edac/mv64x60_edac.c | 17 +++++++++++------
 3 files changed, 29 insertions(+), 44 deletions(-)

-- 
2.13.0

[toc] | [next] | [standalone]


#1659308 — [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory

FromChris Packham <chris.packham@alliedtelesis.co.nz>
Date2017-06-07 02:00 +0200
Subject[PATCH v2 2/3] EDAC: altera: simplify calculation of total memory
Message-ID<tPwye-7dr-15@gated-at.bofh.it>
In reply to#1659307
Use of_address_to_resource() and resource_size() instead of manually
parsing the "reg" property from the "memory" node(s).

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- New

 drivers/edac/altera_edac.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/edac/altera_edac.c b/drivers/edac/altera_edac.c
index 7717b094fabb..f8b623352627 100644
--- a/drivers/edac/altera_edac.c
+++ b/drivers/edac/altera_edac.c
@@ -214,24 +214,16 @@ static void altr_sdr_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
 static unsigned long get_total_mem(void)
 {
 	struct device_node *np = NULL;
-	const unsigned int *reg, *reg_end;
-	int len, sw, aw;
-	unsigned long start, size, total_mem = 0;
+	struct resource res;
+	int ret;
+	unsigned long total_mem = 0;
 
 	for_each_node_by_type(np, "memory") {
-		aw = of_n_addr_cells(np);
-		sw = of_n_size_cells(np);
-		reg = (const unsigned int *)of_get_property(np, "reg", &len);
-		reg_end = reg + (len / sizeof(u32));
-
-		total_mem = 0;
-		do {
-			start = of_read_number(reg, aw);
-			reg += aw;
-			size = of_read_number(reg, sw);
-			reg += sw;
-			total_mem += size;
-		} while (reg < reg_end);
+		ret = of_address_to_resource(np, 0, &res);
+		if (ret)
+			continue;
+
+		total_mem += resource_size(&res);
 	}
 	edac_dbg(0, "total_mem 0x%lx\n", total_mem);
 	return total_mem;
-- 
2.13.0

[toc] | [prev] | [next] | [standalone]


#1659309 — [PATCH v2 1/3] EDAC: mv64x60: calculate memory size correctly

FromChris Packham <chris.packham@alliedtelesis.co.nz>
Date2017-06-07 02:00 +0200
Subject[PATCH v2 1/3] EDAC: mv64x60: calculate memory size correctly
Message-ID<tPwye-7dr-21@gated-at.bofh.it>
In reply to#1659307
The #address-cells and #size-cells properties need to be accounted for
when dealing with the "memory" device tree node. Use
of_address_to_resource() and resource_size() to retrieve the size of the
memory node which will automatically take the #cells into account.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- Use of_address_to_resource() instead of manually parsing the reg property.

 drivers/edac/mv64x60_edac.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/edac/mv64x60_edac.c b/drivers/edac/mv64x60_edac.c
index 3461db3723cb..93623e704623 100644
--- a/drivers/edac/mv64x60_edac.c
+++ b/drivers/edac/mv64x60_edac.c
@@ -16,6 +16,7 @@
 #include <linux/io.h>
 #include <linux/edac.h>
 #include <linux/gfp.h>
+#include <linux/of_address.h>
 #include <linux/of_platform.h>
 #include <linux/of_device.h>
 
@@ -644,15 +645,19 @@ static irqreturn_t mv64x60_mc_isr(int irq, void *dev_id)
 static void get_total_mem(struct mv64x60_mc_pdata *pdata)
 {
 	struct device_node *np = NULL;
-	const unsigned int *reg;
+	struct resource res;
+	int ret;
+	unsigned long total_mem = 0;
 
-	np = of_find_node_by_type(NULL, "memory");
-	if (!np)
-		return;
+	for_each_node_by_type(np, "memory") {
+		ret = of_address_to_resource(np, 0, &res);
+		if (ret)
+			continue;
 
-	reg = of_get_property(np, "reg", NULL);
+		total_mem += resource_size(&res);
+	}
 
-	pdata->total_mem = reg[1];
+	pdata->total_mem = total_mem;
 }
 
 static void mv64x60_init_csrows(struct mem_ctl_info *mci,
-- 
2.13.0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web