powerpc/mem: Store the dt_root_size/addr cell values for later usage
RFC PATCH 1/3 powerpc/mem: Store the dt_root_size/addr cell values for later usage
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.
--- arch/powerpc/include/asm/drmem.h | 2 ++ arch/powerpc/kernel/prom.c | 7 +++++++ arch/powerpc/mm/numa.c | 1 + 3 files changed, 10 insertions(+)
arch/powerpc/include/asm/drmem.h +2 -0
@@ -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 */
arch/powerpc/kernel/prom.c +7 -0
@@ -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) {
arch/powerpc/mm/numa.c +1 -0
@@ -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 ;
Signature · 1 line
2.26.2
RFC PATCH 2/3 powerpc/numa: Use global variable instead of fetching again
use mem_addr_cells/mem_size_cells instead of fetching the values again from device tree.
--- arch/powerpc/mm/numa.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-)
arch/powerpc/mm/numa.c +10 -26
@@ -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 ;
Signature · 1 line
2.26.2
RFC PATCH 3/3 powerpc/lmb-size: Use addr #size-cells value when fetching lmb-size
In reply to Aneesh Kumar K.VMake it consistent with other usages.
--- arch/powerpc/mm/book3s64/radix_pgtable.c | 7 ++++--- arch/powerpc/platforms/pseries/hotplug-memory.c | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-)
arch/powerpc/mm/book3s64/radix_pgtable.c +4 -3
@@ -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 ; }
arch/powerpc/platforms/pseries/hotplug-memory.c +6 -4
@@ -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 ;
Signature · 1 line
2.26.2
RFC PATCH 1/1 powerpc/drmem: use global variable instead of fetching again
In reply to Aneesh Kumar K.Vuse mem_addr_cells/mem_size_cells instead of fetching the values again from device tree.
--- arch/powerpc/mm/drmem.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)
arch/powerpc/mm/drmem.c +6 -18
@@ -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;
Signature · 1 line
2.26.2
Re: [RFC PATCH] powerpc/drmem: use global variable instead of fetching again
Quoted 3 lines · Aneesh Kumar K.V
use mem_addr_cells/mem_size_cells instead of fetching the values again from device tree.
Looks good to me.
Quoted 70 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/mm/drmem.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)arch/powerpc/mm/drmem.c +6
-12@@ -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;
arch/powerpc/mm/drmem.c int walk_drmem_lmbs(struct device_node *dn, void *data, · line 352
Quoted 10 lines
arch/powerpc/mm/drmem.c +0
-6-/* 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