public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
* [RFC PATCH 1/3] powerpc/mem: Store the dt_root_size/addr cell values for later usage
@ 2020-08-06 12:36 Aneesh Kumar K.V
  2020-08-06 12:36 ` [RFC PATCH 2/3] powerpc/numa: Use global variable instead of fetching again Aneesh Kumar K.V
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Aneesh Kumar K.V @ 2020-08-06 12:36 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Nathan Lynch, Aneesh Kumar K.V, Hari Bathini

dt_root_addr_cells and dt_root_size_cells are __initdata variables.
So make a copy of the same which can be used post init.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux•ibm.com>
---
 arch/powerpc/include/asm/drmem.h | 2 ++
 arch/powerpc/kernel/prom.c       | 7 +++++++
 arch/powerpc/mm/numa.c           | 1 +
 3 files changed, 10 insertions(+)

diff --git a/arch/powerpc/include/asm/drmem.h b/arch/powerpc/include/asm/drmem.h
index 07c158c5f939..1f0eaf432755 100644
--- a/arch/powerpc/include/asm/drmem.h
+++ b/arch/powerpc/include/asm/drmem.h
@@ -123,4 +123,6 @@ static inline void lmb_clear_nid(struct drmem_lmb *lmb)
 }
 #endif
 
+extern int mem_addr_cells, mem_size_cells;
+
 #endif /* _ASM_POWERPC_LMB_H */
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index d8a2fb87ba0c..9a1701e85747 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -73,6 +73,7 @@ u64 ppc64_rma_size;
 #endif
 static phys_addr_t first_memblock_size;
 static int __initdata boot_cpu_count;
+int mem_addr_cells, mem_size_cells;
 
 static int __init early_parse_mem(char *p)
 {
@@ -536,6 +537,12 @@ static int __init early_init_dt_scan_memory_ppc(unsigned long node,
 						const char *uname,
 						int depth, void *data)
 {
+	/*
+	 * Make a copy from __initdata variable
+	 */
+	mem_addr_cells = dt_root_addr_cells;
+	mem_size_cells = dt_root_size_cells;
+
 #ifdef CONFIG_PPC_PSERIES
 	if (depth == 1 &&
 	    strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) {
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 058fee9a0835..77d41d9775d2 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -368,6 +368,7 @@ static void __init get_n_mem_cells(int *n_addr_cells, int *n_size_cells)
 	of_node_put(memory);
 }
 
+/*  dt_mem_next_cell is __init  */
 static unsigned long read_n_cells(int n, const __be32 **buf)
 {
 	unsigned long result = 0;
-- 
2.26.2


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

* [RFC PATCH 2/3] powerpc/numa: Use global variable instead of fetching again
  2020-08-06 12:36 [RFC PATCH 1/3] powerpc/mem: Store the dt_root_size/addr cell values for later usage Aneesh Kumar K.V
@ 2020-08-06 12:36 ` Aneesh Kumar K.V
  2020-08-06 12:36 ` [RFC PATCH 3/3] powerpc/lmb-size: Use addr #size-cells value when fetching lmb-size Aneesh Kumar K.V
  2020-08-06 12:52 ` [RFC PATCH] powerpc/drmem: use global variable instead of fetching again Aneesh Kumar K.V
  2 siblings, 0 replies; 5+ messages in thread
From: Aneesh Kumar K.V @ 2020-08-06 12:36 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Nathan Lynch, Aneesh Kumar K.V, Hari Bathini

use mem_addr_cells/mem_size_cells instead of fetching the values
again from device tree.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux•ibm.com>
---
 arch/powerpc/mm/numa.c | 36 ++++++++++--------------------------
 1 file changed, 10 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 77d41d9775d2..c420872acd61 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -52,7 +52,6 @@ EXPORT_SYMBOL(node_to_cpumask_map);
 EXPORT_SYMBOL(node_data);
 
 static int min_common_depth;
-static int n_mem_addr_cells, n_mem_size_cells;
 static int form1_affinity;
 
 #define MAX_DISTANCE_REF_POINTS 4
@@ -355,19 +354,6 @@ static int __init find_min_common_depth(void)
 	return -1;
 }
 
-static void __init get_n_mem_cells(int *n_addr_cells, int *n_size_cells)
-{
-	struct device_node *memory = NULL;
-
-	memory = of_find_node_by_type(memory, "memory");
-	if (!memory)
-		panic("numa.c: No memory nodes found!");
-
-	*n_addr_cells = of_n_addr_cells(memory);
-	*n_size_cells = of_n_size_cells(memory);
-	of_node_put(memory);
-}
-
 /*  dt_mem_next_cell is __init  */
 static unsigned long read_n_cells(int n, const __be32 **buf)
 {
@@ -639,12 +625,12 @@ static inline int __init read_usm_ranges(const __be32 **usm)
 	 * a counter followed by that many (base, size) duple.
 	 * read the counter from linux,drconf-usable-memory
 	 */
-	return read_n_cells(n_mem_size_cells, usm);
+	return read_n_cells(mem_size_cells, usm);
 }
 
 /*
  * Extract NUMA information from the ibm,dynamic-reconfiguration-memory
- * node.  This assumes n_mem_{addr,size}_cells have been set.
+ * node.  This assumes mem_{addr,size}_cells have been set.
  */
 static int __init numa_setup_drmem_lmb(struct drmem_lmb *lmb,
 					const __be32 **usm,
@@ -677,8 +663,8 @@ static int __init numa_setup_drmem_lmb(struct drmem_lmb *lmb,
 
 	do {
 		if (is_kexec_kdump) {
-			base = read_n_cells(n_mem_addr_cells, usm);
-			size = read_n_cells(n_mem_size_cells, usm);
+			base = read_n_cells(mem_addr_cells, usm);
+			size = read_n_cells(mem_size_cells, usm);
 		}
 
 		nid = of_drconf_to_nid_single(lmb);
@@ -741,8 +727,6 @@ static int __init parse_numa_properties(void)
 		node_set_online(nid);
 	}
 
-	get_n_mem_cells(&n_mem_addr_cells, &n_mem_size_cells);
-
 	for_each_node_by_type(memory, "memory") {
 		unsigned long start;
 		unsigned long size;
@@ -759,11 +743,11 @@ static int __init parse_numa_properties(void)
 			continue;
 
 		/* ranges in cell */
-		ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
+		ranges = (len >> 2) / (mem_addr_cells + mem_size_cells);
 new_range:
 		/* these are order-sensitive, and modify the buffer pointer */
-		start = read_n_cells(n_mem_addr_cells, &memcell_buf);
-		size = read_n_cells(n_mem_size_cells, &memcell_buf);
+		start = read_n_cells(mem_addr_cells, &memcell_buf);
+		size = read_n_cells(mem_size_cells, &memcell_buf);
 
 		/*
 		 * Assumption: either all memory nodes or none will
@@ -1042,11 +1026,11 @@ static int hot_add_node_scn_to_nid(unsigned long scn_addr)
 			continue;
 
 		/* ranges in cell */
-		ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
+		ranges = (len >> 2) / (mem_addr_cells + mem_size_cells);
 
 		while (ranges--) {
-			start = read_n_cells(n_mem_addr_cells, &memcell_buf);
-			size = read_n_cells(n_mem_size_cells, &memcell_buf);
+			start = read_n_cells(mem_addr_cells, &memcell_buf);
+			size = read_n_cells(mem_size_cells, &memcell_buf);
 
 			if ((scn_addr < start) || (scn_addr >= (start + size)))
 				continue;
-- 
2.26.2


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

* [RFC PATCH 3/3] powerpc/lmb-size: Use addr #size-cells value when fetching lmb-size
  2020-08-06 12:36 [RFC PATCH 1/3] powerpc/mem: Store the dt_root_size/addr cell values for later usage Aneesh Kumar K.V
  2020-08-06 12:36 ` [RFC PATCH 2/3] powerpc/numa: Use global variable instead of fetching again Aneesh Kumar K.V
@ 2020-08-06 12:36 ` Aneesh Kumar K.V
  2020-08-06 12:52 ` [RFC PATCH] powerpc/drmem: use global variable instead of fetching again Aneesh Kumar K.V
  2 siblings, 0 replies; 5+ messages in thread
From: Aneesh Kumar K.V @ 2020-08-06 12:36 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Nathan Lynch, Aneesh Kumar K.V, Hari Bathini

Make it consistent with other usages.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux•ibm.com>
---
 arch/powerpc/mm/book3s64/radix_pgtable.c        |  7 ++++---
 arch/powerpc/platforms/pseries/hotplug-memory.c | 10 ++++++----
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index ca76d9d6372a..a48e6618a27b 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -497,7 +497,7 @@ static int __init probe_memory_block_size(unsigned long node, const char *uname,
 					  depth, void *data)
 {
 	unsigned long *mem_block_size = (unsigned long *)data;
-	const __be64 *prop;
+	const __be32 *prop;
 	int len;
 
 	if (depth != 1)
@@ -507,13 +507,14 @@ static int __init probe_memory_block_size(unsigned long node, const char *uname,
 		return 0;
 
 	prop = of_get_flat_dt_prop(node, "ibm,lmb-size", &len);
-	if (!prop || len < sizeof(__be64))
+
+	if (!prop || len < dt_root_size_cells * sizeof(__be32))
 		/*
 		 * Nothing in the device tree
 		 */
 		*mem_block_size = MIN_MEMORY_BLOCK_SIZE;
 	else
-		*mem_block_size = be64_to_cpup(prop);
+		*mem_block_size = of_read_number(prop, dt_root_size_cells);
 	return 1;
 }
 
diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index 5d545b78111f..aba23ef8dfdd 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -30,12 +30,14 @@ unsigned long pseries_memory_block_size(void)
 
 	np = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
 	if (np) {
-		const __be64 *size;
+		int len;
+		const __be32 *prop;
 
-		size = of_get_property(np, "ibm,lmb-size", NULL);
-		if (size)
-			memblock_size = be64_to_cpup(size);
+		prop = of_get_property(np, "ibm,lmb-size", &len);
+		if (prop && len >= mem_size_cells * sizeof(__be32))
+			memblock_size = of_read_number(prop, mem_size_cells);
 		of_node_put(np);
+
 	} else  if (machine_is(pseries)) {
 		/* This fallback really only applies to pseries */
 		unsigned int memzero_size = 0;
-- 
2.26.2


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

* [RFC PATCH] powerpc/drmem: use global variable instead of fetching again
  2020-08-06 12:36 [RFC PATCH 1/3] powerpc/mem: Store the dt_root_size/addr cell values for later usage Aneesh Kumar K.V
  2020-08-06 12:36 ` [RFC PATCH 2/3] powerpc/numa: Use global variable instead of fetching again Aneesh Kumar K.V
  2020-08-06 12:36 ` [RFC PATCH 3/3] powerpc/lmb-size: Use addr #size-cells value when fetching lmb-size Aneesh Kumar K.V
@ 2020-08-06 12:52 ` Aneesh Kumar K.V
  2020-08-17 17:31   ` Hari Bathini
  2 siblings, 1 reply; 5+ messages in thread
From: Aneesh Kumar K.V @ 2020-08-06 12:52 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Nathan Lynch, Aneesh Kumar K.V, Hari Bathini

use mem_addr_cells/mem_size_cells instead of fetching the values
again from device tree.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux•ibm.com>
---
 arch/powerpc/mm/drmem.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/mm/drmem.c b/arch/powerpc/mm/drmem.c
index b2eeea39684c..f533a7b04ab9 100644
--- a/arch/powerpc/mm/drmem.c
+++ b/arch/powerpc/mm/drmem.c
@@ -14,8 +14,6 @@
 #include <asm/prom.h>
 #include <asm/drmem.h>
 
-static int n_root_addr_cells, n_root_size_cells;
-
 static struct drmem_lmb_info __drmem_info;
 struct drmem_lmb_info *drmem_info = &__drmem_info;
 
@@ -196,8 +194,8 @@ static void read_drconf_v1_cell(struct drmem_lmb *lmb,
 {
 	const __be32 *p = *prop;
 
-	lmb->base_addr = of_read_number(p, n_root_addr_cells);
-	p += n_root_addr_cells;
+	lmb->base_addr = of_read_number(p, mem_addr_cells);
+	p += mem_addr_cells;
 	lmb->drc_index = of_read_number(p++, 1);
 
 	p++; /* skip reserved field */
@@ -233,8 +231,8 @@ static void read_drconf_v2_cell(struct of_drconf_cell_v2 *dr_cell,
 	const __be32 *p = *prop;
 
 	dr_cell->seq_lmbs = of_read_number(p++, 1);
-	dr_cell->base_addr = of_read_number(p, n_root_addr_cells);
-	p += n_root_addr_cells;
+	dr_cell->base_addr = of_read_number(p, mem_addr_cells);
+	p += mem_addr_cells;
 	dr_cell->drc_index = of_read_number(p++, 1);
 	dr_cell->aa_index = of_read_number(p++, 1);
 	dr_cell->flags = of_read_number(p++, 1);
@@ -285,10 +283,6 @@ int __init walk_drmem_lmbs_early(unsigned long node, void *data,
 	if (!prop || len < dt_root_size_cells * sizeof(__be32))
 		return ret;
 
-	/* Get the address & size cells */
-	n_root_addr_cells = dt_root_addr_cells;
-	n_root_size_cells = dt_root_size_cells;
-
 	drmem_info->lmb_size = dt_mem_next_cell(dt_root_size_cells, &prop);
 
 	usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory", &len);
@@ -318,12 +312,12 @@ static int init_drmem_lmb_size(struct device_node *dn)
 		return 0;
 
 	prop = of_get_property(dn, "ibm,lmb-size", &len);
-	if (!prop || len < n_root_size_cells * sizeof(__be32)) {
+	if (!prop || len < mem_size_cells * sizeof(__be32)) {
 		pr_info("Could not determine LMB size\n");
 		return -1;
 	}
 
-	drmem_info->lmb_size = of_read_number(prop, n_root_size_cells);
+	drmem_info->lmb_size = of_read_number(prop, mem_size_cells);
 	return 0;
 }
 
@@ -353,12 +347,6 @@ int walk_drmem_lmbs(struct device_node *dn, void *data,
 	if (!of_root)
 		return ret;
 
-	/* Get the address & size cells */
-	of_node_get(of_root);
-	n_root_addr_cells = of_n_addr_cells(of_root);
-	n_root_size_cells = of_n_size_cells(of_root);
-	of_node_put(of_root);
-
 	if (init_drmem_lmb_size(dn))
 		return ret;
 
-- 
2.26.2


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

* Re: [RFC PATCH] powerpc/drmem: use global variable instead of fetching again
  2020-08-06 12:52 ` [RFC PATCH] powerpc/drmem: use global variable instead of fetching again Aneesh Kumar K.V
@ 2020-08-17 17:31   ` Hari Bathini
  0 siblings, 0 replies; 5+ messages in thread
From: Hari Bathini @ 2020-08-17 17:31 UTC (permalink / raw)
  To: Aneesh Kumar K.V, linuxppc-dev, mpe; +Cc: Nathan Lynch



On 06/08/20 6:22 pm, Aneesh Kumar K.V wrote:
> use mem_addr_cells/mem_size_cells instead of fetching the values
> again from device tree.
> 

Looks good to me.

> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux•ibm.com>
> ---
>   arch/powerpc/mm/drmem.c | 24 ++++++------------------
>   1 file changed, 6 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/powerpc/mm/drmem.c b/arch/powerpc/mm/drmem.c
> index b2eeea39684c..f533a7b04ab9 100644
> --- a/arch/powerpc/mm/drmem.c
> +++ b/arch/powerpc/mm/drmem.c
> @@ -14,8 +14,6 @@
>   #include <asm/prom.h>
>   #include <asm/drmem.h>
>   
> -static int n_root_addr_cells, n_root_size_cells;
> -
>   static struct drmem_lmb_info __drmem_info;
>   struct drmem_lmb_info *drmem_info = &__drmem_info;
>   
> @@ -196,8 +194,8 @@ static void read_drconf_v1_cell(struct drmem_lmb *lmb,
>   {
>   	const __be32 *p = *prop;
>   
> -	lmb->base_addr = of_read_number(p, n_root_addr_cells);
> -	p += n_root_addr_cells;
> +	lmb->base_addr = of_read_number(p, mem_addr_cells);
> +	p += mem_addr_cells;
>   	lmb->drc_index = of_read_number(p++, 1);
>   
>   	p++; /* skip reserved field */
> @@ -233,8 +231,8 @@ static void read_drconf_v2_cell(struct of_drconf_cell_v2 *dr_cell,
>   	const __be32 *p = *prop;
>   
>   	dr_cell->seq_lmbs = of_read_number(p++, 1);
> -	dr_cell->base_addr = of_read_number(p, n_root_addr_cells);
> -	p += n_root_addr_cells;
> +	dr_cell->base_addr = of_read_number(p, mem_addr_cells);
> +	p += mem_addr_cells;
>   	dr_cell->drc_index = of_read_number(p++, 1);
>   	dr_cell->aa_index = of_read_number(p++, 1);
>   	dr_cell->flags = of_read_number(p++, 1);
> @@ -285,10 +283,6 @@ int __init walk_drmem_lmbs_early(unsigned long node, void *data,
>   	if (!prop || len < dt_root_size_cells * sizeof(__be32))
>   		return ret;
>   
> -	/* Get the address & size cells */
> -	n_root_addr_cells = dt_root_addr_cells;
> -	n_root_size_cells = dt_root_size_cells;
> -
>   	drmem_info->lmb_size = dt_mem_next_cell(dt_root_size_cells, &prop);
>   
>   	usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory", &len);
> @@ -318,12 +312,12 @@ static int init_drmem_lmb_size(struct device_node *dn)
>   		return 0;
>   
>   	prop = of_get_property(dn, "ibm,lmb-size", &len);
> -	if (!prop || len < n_root_size_cells * sizeof(__be32)) {
> +	if (!prop || len < mem_size_cells * sizeof(__be32)) {
>   		pr_info("Could not determine LMB size\n");
>   		return -1;
>   	}
>   
> -	drmem_info->lmb_size = of_read_number(prop, n_root_size_cells);
> +	drmem_info->lmb_size = of_read_number(prop, mem_size_cells);
>   	return 0;
>   }
>   
> @@ -353,12 +347,6 @@ int walk_drmem_lmbs(struct device_node *dn, void *data,
>   	if (!of_root)
>   		return ret;
>   
> -	/* Get the address & size cells */
> -	of_node_get(of_root);
> -	n_root_addr_cells = of_n_addr_cells(of_root);
> -	n_root_size_cells = of_n_size_cells(of_root);
> -	of_node_put(of_root);
> -
>   	if (init_drmem_lmb_size(dn))
>   		return ret;
>   
> 

Thanks
Hari

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

end of thread, other threads:[~2020-08-17 17:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-06 12:36 [RFC PATCH 1/3] powerpc/mem: Store the dt_root_size/addr cell values for later usage Aneesh Kumar K.V
2020-08-06 12:36 ` [RFC PATCH 2/3] powerpc/numa: Use global variable instead of fetching again Aneesh Kumar K.V
2020-08-06 12:36 ` [RFC PATCH 3/3] powerpc/lmb-size: Use addr #size-cells value when fetching lmb-size Aneesh Kumar K.V
2020-08-06 12:52 ` [RFC PATCH] powerpc/drmem: use global variable instead of fetching again Aneesh Kumar K.V
2020-08-17 17:31   ` Hari Bathini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox