linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* EDAC: simplify total memory calculation
@ 2017-06-06 23:54 Chris Packham
  2017-06-06 23:54 ` [PATCH v2 1/3] EDAC: mv64x60: calculate memory size correctly Chris Packham
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chris Packham @ 2017-06-06 23:54 UTC (permalink / raw)
  To: bp, linux-edac; +Cc: mchehab, mpe, linuxppc-dev, linux-kernel, Chris Packham

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] EDAC: mv64x60: calculate memory size correctly
  2017-06-06 23:54 EDAC: simplify total memory calculation Chris Packham
@ 2017-06-06 23:54 ` Chris Packham
  2017-06-06 23:54 ` [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory Chris Packham
  2017-06-06 23:55 ` [PATCH v2 3/3] EDAC: cpc925: " Chris Packham
  2 siblings, 0 replies; 6+ messages in thread
From: Chris Packham @ 2017-06-06 23:54 UTC (permalink / raw)
  To: bp, linux-edac; +Cc: mchehab, mpe, linuxppc-dev, linux-kernel, Chris Packham

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory
  2017-06-06 23:54 EDAC: simplify total memory calculation Chris Packham
  2017-06-06 23:54 ` [PATCH v2 1/3] EDAC: mv64x60: calculate memory size correctly Chris Packham
@ 2017-06-06 23:54 ` Chris Packham
  2017-06-12 18:34   ` Thor Thayer
  2017-06-06 23:55 ` [PATCH v2 3/3] EDAC: cpc925: " Chris Packham
  2 siblings, 1 reply; 6+ messages in thread
From: Chris Packham @ 2017-06-06 23:54 UTC (permalink / raw)
  To: bp, linux-edac
  Cc: mchehab, mpe, linuxppc-dev, linux-kernel, Chris Packham, Thor Thayer

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] EDAC: cpc925: simplify calculation of total memory
  2017-06-06 23:54 EDAC: simplify total memory calculation Chris Packham
  2017-06-06 23:54 ` [PATCH v2 1/3] EDAC: mv64x60: calculate memory size correctly Chris Packham
  2017-06-06 23:54 ` [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory Chris Packham
@ 2017-06-06 23:55 ` Chris Packham
  2 siblings, 0 replies; 6+ messages in thread
From: Chris Packham @ 2017-06-06 23:55 UTC (permalink / raw)
  To: bp, linux-edac; +Cc: mchehab, mpe, linuxppc-dev, linux-kernel, Chris Packham

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/cpc925_edac.c | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/drivers/edac/cpc925_edac.c b/drivers/edac/cpc925_edac.c
index 837b62c4993d..ea347cd7eb92 100644
--- a/drivers/edac/cpc925_edac.c
+++ b/drivers/edac/cpc925_edac.c
@@ -24,6 +24,7 @@
 #include <linux/io.h>
 #include <linux/edac.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/platform_device.h>
 #include <linux/gfp.h>
 
@@ -296,30 +297,17 @@ struct cpc925_dev_info {
 static void get_total_mem(struct cpc925_mc_pdata *pdata)
 {
 	struct device_node *np = NULL;
-	const unsigned int *reg, *reg_end;
-	int len, sw, aw;
-	unsigned long start, size;
+	struct resource res;
+	int ret;
 
-	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;
+
+		pdata->total_mem += resource_size(&res);
+	}
 
-	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/4;
-
-	pdata->total_mem = 0;
-	do {
-		start = of_read_number(reg, aw);
-		reg += aw;
-		size = of_read_number(reg, sw);
-		reg += sw;
-		edac_dbg(1, "start 0x%lx, size 0x%lx\n", start, size);
-		pdata->total_mem += size;
-	} while (reg < reg_end);
-
-	of_node_put(np);
 	edac_dbg(0, "total_mem 0x%lx\n", pdata->total_mem);
 }
 
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory
  2017-06-06 23:54 ` [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory Chris Packham
@ 2017-06-12 18:34   ` Thor Thayer
  2017-06-14 11:50     ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: Thor Thayer @ 2017-06-12 18:34 UTC (permalink / raw)
  To: Chris Packham, bp, linux-edac; +Cc: mchehab, mpe, linuxppc-dev, linux-kernel

On 06/06/2017 06:54 PM, Chris Packham wrote:
> 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;
> 
Nice change! Tested on Cyclone5 DevKit & Arria10 DevKit.

Tested-by: Thor Thayer <thor.thayer@linux.intel.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory
  2017-06-12 18:34   ` Thor Thayer
@ 2017-06-14 11:50     ` Borislav Petkov
  0 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2017-06-14 11:50 UTC (permalink / raw)
  To: Thor Thayer, Chris Packham
  Cc: linux-edac, mchehab, mpe, linuxppc-dev, linux-kernel

On Mon, Jun 12, 2017 at 01:34:05PM -0500, Thor Thayer wrote:
> On 06/06/2017 06:54 PM, Chris Packham wrote:
> > 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>
> > ---

...

> Nice change! Tested on Cyclone5 DevKit & Arria10 DevKit.
> 
> Tested-by: Thor Thayer <thor.thayer@linux.intel.com>

Applied, thanks.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-06-14 11:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-06 23:54 EDAC: simplify total memory calculation Chris Packham
2017-06-06 23:54 ` [PATCH v2 1/3] EDAC: mv64x60: calculate memory size correctly Chris Packham
2017-06-06 23:54 ` [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory Chris Packham
2017-06-12 18:34   ` Thor Thayer
2017-06-14 11:50     ` Borislav Petkov
2017-06-06 23:55 ` [PATCH v2 3/3] EDAC: cpc925: " Chris Packham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).