Skip to contentSkip to conversation

edac: cpc925: Drop unused memory size DT parsing

PATCH In review Rob Herring 2 participants 7 messages Mar 19, 2023 – Apr 20, 2023 EDAC-core

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 edac: cpc925: Drop unused memory size DT parsing

The 'total_mem' memory size is parsed from DT, but never used anywhere. Just drop it as drivers shouldn't really do their own parsing of common bindings, and memblock would be a better way to get memory size now anyways.

---
 drivers/edac/cpc925_edac.c | 34 ----------------------------------
 1 file changed, 34 deletions(-)
drivers/edac/cpc925_edac.c +0 -34
index 9797e6d60dde..ee193aae8e14 100644
@@ -263,7 +263,6 @@ enum brgctrl_bits {
 /* Private structure for edac memory controller */
 struct cpc925_mc_pdata {
 	void __iomem *vbase;
-	unsigned long total_mem;
 	const char *name;
 	int edac_idx;
 };
@@ -280,37 +279,6 @@ struct cpc925_dev_info {
 	void (*check)(struct edac_device_ctl_info *edac_dev);
 };
 
-/* Get total memory size from Open Firmware DTB */
-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;
-
-	np = of_find_node_by_type(NULL, "memory");
-	if (!np)
-		return;
-
-	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);
-}
-
 static void cpc925_init_csrows(struct mem_ctl_info *mci)
 {
 	struct cpc925_mc_pdata *pdata = mci->pvt_info;
@@ -321,8 +289,6 @@ static void cpc925_init_csrows(struct mem_ctl_info *mci)
 	u32 mbmr, mbbar, bba, grain;
 	unsigned long row_size, nr_pages, last_nr_pages = 0;
 
-	get_total_mem(pdata);
-
 	for (index = 0; index < mci->nr_csrows; index++) {
 		mbmr = __raw_readl(pdata->vbase + REG_MBMR_OFFSET +
 				   0x20 * index);
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/2 edac: cpc925: Use of_get_cpu_hwid() to read CPU node 'reg'

Replace open coded reading of CPU nodes' "reg" properties with of_get_cpu_hwid() dedicated for this purpose.

---
 drivers/edac/cpc925_edac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/edac/cpc925_edac.c +3 -3
index ee193aae8e14..0182436c1b5a 100644
@@ -557,13 +557,13 @@ static u32 cpc925_cpu_mask_disabled(void)
 	mask = APIMASK_ADI0 | APIMASK_ADI1;
 
 	for_each_of_cpu_node(cpunode) {
-		const u32 *reg = of_get_property(cpunode, "reg", NULL);
-		if (reg == NULL || *reg > 2) {
+		int hwid = of_get_cpu_hwid(cpunode, 0);
+		if ((hwid < 0) || (hwid > 2)) {
 			cpc925_printk(KERN_ERR, "Bad reg value at %pOF\n", cpunode);
 			continue;
 		}
 
-		mask &= ~APIMASK_ADI(*reg);
+		mask &= ~APIMASK_ADI(hwid);
 	}
 
 	if (mask != (APIMASK_ADI0 | APIMASK_ADI1)) {
Signature · 1 line
2.39.2
maintainer
#2 lore raw

Re: [PATCH 2/2] edac: cpc925: Use of_get_cpu_hwid() to read CPU node 'reg'

Quoted 20 lines · Rob Herring

Replace open coded reading of CPU nodes' "reg" properties with of_get_cpu_hwid() dedicated for this purpose.

---
 drivers/edac/cpc925_edac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/edac/cpc925_edac.c +1 -2
index ee193aae8e14..0182436c1b5a 100644
@@ -557,13 +557,13 @@ static u32 cpc925_cpu_mask_disabled(void)
 	mask = APIMASK_ADI0 | APIMASK_ADI1;
 
 	for_each_of_cpu_node(cpunode) {
-		const u32 *reg = of_get_property(cpunode, "reg", NULL);
-		if (reg == NULL || *reg > 2) {
+		int hwid = of_get_cpu_hwid(cpunode, 0);

drivers/edac/cpc925_edac.c static u32 cpc925_cpu_mask_disabled(void) · line 569

Quoted 10 lines
drivers/edac/cpc925_edac.c +2 -1
+		if ((hwid < 0) || (hwid > 2)) {
 			cpc925_printk(KERN_ERR, "Bad reg value at %pOF\n", cpunode);
 			continue;
 		}
 
-		mask &= ~APIMASK_ADI(*reg);
+		mask &= ~APIMASK_ADI(hwid);
 	}
 
 	if (mask != (APIMASK_ADI0 | APIMASK_ADI1)) {
$ grep CPC925 .config
CONFIG_EDAC_CPC925=m
$ make ARCH=powerpc CROSS_COMPILE=/home/boris/src/crosstool/gcc-11.1.0-nolibc/powerpc64-linux/bin/powerpc64-linux-
...
ERROR: modpost: ".of_get_cpu_hwid" [drivers/edac/cpc925_edac.ko] undefined!
make[1]: *** [scripts/Makefile.modpost:136: Module.symvers] Error 1
make: *** [Makefile:1980: modpost] Error 2
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw

Re: [PATCH 2/2] edac: cpc925: Use of_get_cpu_hwid() to read CPU node 'reg'

Quoted 35 lines · Borislav Petkov
Quoted 20 lines · Rob Herring

Replace open coded reading of CPU nodes' "reg" properties with of_get_cpu_hwid() dedicated for this purpose.

---
 drivers/edac/cpc925_edac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/edac/cpc925_edac.c +1 -2
index ee193aae8e14..0182436c1b5a 100644
@@ -557,13 +557,13 @@ static u32 cpc925_cpu_mask_disabled(void)
 	mask = APIMASK_ADI0 | APIMASK_ADI1;
 
 	for_each_of_cpu_node(cpunode) {
-		const u32 *reg = of_get_property(cpunode, "reg", NULL);
-		if (reg == NULL || *reg > 2) {
+		int hwid = of_get_cpu_hwid(cpunode, 0);

drivers/edac/cpc925_edac.c static u32 cpc925_cpu_mask_disabled(void) · line 569

Quoted 10 lines
drivers/edac/cpc925_edac.c +2 -1
+		if ((hwid < 0) || (hwid > 2)) {
 			cpc925_printk(KERN_ERR, "Bad reg value at %pOF\n", cpunode);
 			continue;
 		}
 
-		mask &= ~APIMASK_ADI(*reg);
+		mask &= ~APIMASK_ADI(hwid);
 	}
 
 	if (mask != (APIMASK_ADI0 | APIMASK_ADI1)) {
$ grep CPC925 .config
CONFIG_EDAC_CPC925=m
Quoted 5 lines
$ make ARCH=powerpc CROSS_COMPILE=/home/boris/src/crosstool/gcc-11.1.0-nolibc/powerpc64-linux/bin/powerpc64-linux-
...
ERROR: modpost: ".of_get_cpu_hwid" [drivers/edac/cpc925_edac.ko] undefined!
make[1]: *** [scripts/Makefile.modpost:136: Module.symvers] Error 1
make: *** [Makefile:1980: modpost] Error 2

I'd rather not export of_get_cpu_hwid() which is otherwise only used in arch code. I think I'll rewrite this in terms of for_each_possible_cpu() and topology_core_id(). Though that would make a UP build not enable core 1, but that seems undesirable anyways.

Rob

maintainer
#4 lore raw

Re: [PATCH 2/2] edac: cpc925: Use of_get_cpu_hwid() to read CPU node 'reg'

Quoted 4 lines · Rob Herring

I'd rather not export of_get_cpu_hwid() which is otherwise only used in arch code. I think I'll rewrite this in terms of for_each_possible_cpu() and topology_core_id(). Though that would make a UP build not enable core 1, but that seems undesirable anyways.

TBH I'm not sure this driver is even worth any effort besides simply deleting it. I see one commit which reads like someone was really using it:

ce395088832b ("cpc925_edac: Support single-processor configurations")

but that one is from 2011 and since then it has received only API modifications/cleanups.

But if I delete it, someone might crawl out of the woodwork and say it is still used...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#5 lore raw

Re: [PATCH 2/2] edac: cpc925: Use of_get_cpu_hwid() to read CPU node 'reg'

+Arnd, Michael E

Quoted 11 lines · Borislav Petkov
Quoted 4 lines · Rob Herring

I'd rather not export of_get_cpu_hwid() which is otherwise only used in arch code. I think I'll rewrite this in terms of for_each_possible_cpu() and topology_core_id(). Though that would make a UP build not enable core 1, but that seems undesirable anyways.

TBH I'm not sure this driver is even worth any effort besides simply deleting it. I see one commit which reads like someone was really using it:

Quoted 7 lines

ce395088832b ("cpc925_edac: Support single-processor configurations")

but that one is from 2011 and since then it has received only API modifications/cleanups.

But if I delete it, someone might crawl out of the woodwork and say it is still used...

Yeah, I came to that conclusion as well. It's only used by "maple" (aka PPC970FX Evaluation Board) as the kernel has to instantiate this device (rather than DT). Seems like a 20 year old eval board is unlikely to have any users, so perhaps the whole platform could be removed.

Rob

#6 lore raw
In reply to Rob Herring
Quoted 9 lines · Rob Herring

The 'total_mem' memory size is parsed from DT, but never used anywhere. Just drop it as drivers shouldn't really do their own parsing of common bindings, and memblock would be a better way to get memory size now anyways.

---
 drivers/edac/cpc925_edac.c | 34 ----------------------------------
 1 file changed, 34 deletions(-)

Ping.

Quoted 63 lines
drivers/edac/cpc925_edac.c +0 -34
index 9797e6d60dde..ee193aae8e14 100644
@@ -263,7 +263,6 @@ enum brgctrl_bits {
 /* Private structure for edac memory controller */
 struct cpc925_mc_pdata {
 	void __iomem *vbase;
-	unsigned long total_mem;
 	const char *name;
 	int edac_idx;
 };
@@ -280,37 +279,6 @@ struct cpc925_dev_info {
 	void (*check)(struct edac_device_ctl_info *edac_dev);
 };
 
-/* Get total memory size from Open Firmware DTB */
-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;
-
-	np = of_find_node_by_type(NULL, "memory");
-	if (!np)
-		return;
-
-	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);
-}
-
 static void cpc925_init_csrows(struct mem_ctl_info *mci)
 {
 	struct cpc925_mc_pdata *pdata = mci->pvt_info;
@@ -321,8 +289,6 @@ static void cpc925_init_csrows(struct mem_ctl_info *mci)
 	u32 mbmr, mbbar, bba, grain;
 	unsigned long row_size, nr_pages, last_nr_pages = 0;
 
-	get_total_mem(pdata);
-
 	for (index = 0; index < mci->nr_csrows; index++) {
 		mbmr = __raw_readl(pdata->vbase + REG_MBMR_OFFSET +
 				   0x20 * index);
Signature · 1 line
2.39.2