Commit adfefc60 authored by Hari Bathini's avatar Hari Bathini Committed by Michael Ellerman

powerpc/drmem: Make LMB walk a bit more flexible

Currently, numa & prom are the only users of drmem LMB walk code.
Loading kdump with kexec_file also needs to walk the drmem LMBs to
setup the usable memory ranges for kdump kernel. But there are couple
of issues in using the code as is. One, walk_drmem_lmb() code is built
into the .init section currently, while kexec_file needs it later.
Two, there is no scope to pass data to the callback function for
processing and/or erroring out on certain conditions.

Fix that by, moving drmem LMB walk code out of .init section, adding
scope to pass data to the callback function and bailing out when an
error is encountered in the callback function.
Signed-off-by: default avatarHari Bathini <hbathini@linux.ibm.com>
Tested-by: default avatarPingfan Liu <piliu@redhat.com>
Reviewed-by: default avatarThiago Jung Bauermann <bauerman@linux.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/159602282727.575379.3979857013827701828.stgit@hbathini
parent b8e55a3e
...@@ -90,13 +90,14 @@ static inline bool drmem_lmb_reserved(struct drmem_lmb *lmb) ...@@ -90,13 +90,14 @@ static inline bool drmem_lmb_reserved(struct drmem_lmb *lmb)
} }
u64 drmem_lmb_memory_max(void); u64 drmem_lmb_memory_max(void);
void __init walk_drmem_lmbs(struct device_node *dn, int walk_drmem_lmbs(struct device_node *dn, void *data,
void (*func)(struct drmem_lmb *, const __be32 **)); int (*func)(struct drmem_lmb *, const __be32 **, void *));
int drmem_update_dt(void); int drmem_update_dt(void);
#ifdef CONFIG_PPC_PSERIES #ifdef CONFIG_PPC_PSERIES
void __init walk_drmem_lmbs_early(unsigned long node, int __init
void (*func)(struct drmem_lmb *, const __be32 **)); walk_drmem_lmbs_early(unsigned long node, void *data,
int (*func)(struct drmem_lmb *, const __be32 **, void *));
#endif #endif
static inline void invalidate_lmb_associativity_index(struct drmem_lmb *lmb) static inline void invalidate_lmb_associativity_index(struct drmem_lmb *lmb)
......
...@@ -470,8 +470,9 @@ static bool validate_mem_limit(u64 base, u64 *size) ...@@ -470,8 +470,9 @@ static bool validate_mem_limit(u64 base, u64 *size)
* This contains a list of memory blocks along with NUMA affinity * This contains a list of memory blocks along with NUMA affinity
* information. * information.
*/ */
static void __init early_init_drmem_lmb(struct drmem_lmb *lmb, static int __init early_init_drmem_lmb(struct drmem_lmb *lmb,
const __be32 **usm) const __be32 **usm,
void *data)
{ {
u64 base, size; u64 base, size;
int is_kexec_kdump = 0, rngs; int is_kexec_kdump = 0, rngs;
...@@ -486,7 +487,7 @@ static void __init early_init_drmem_lmb(struct drmem_lmb *lmb, ...@@ -486,7 +487,7 @@ static void __init early_init_drmem_lmb(struct drmem_lmb *lmb,
*/ */
if ((lmb->flags & DRCONF_MEM_RESERVED) || if ((lmb->flags & DRCONF_MEM_RESERVED) ||
!(lmb->flags & DRCONF_MEM_ASSIGNED)) !(lmb->flags & DRCONF_MEM_ASSIGNED))
return; return 0;
if (*usm) if (*usm)
is_kexec_kdump = 1; is_kexec_kdump = 1;
...@@ -501,7 +502,7 @@ static void __init early_init_drmem_lmb(struct drmem_lmb *lmb, ...@@ -501,7 +502,7 @@ static void __init early_init_drmem_lmb(struct drmem_lmb *lmb,
*/ */
rngs = dt_mem_next_cell(dt_root_size_cells, usm); rngs = dt_mem_next_cell(dt_root_size_cells, usm);
if (!rngs) /* there are no (base, size) duple */ if (!rngs) /* there are no (base, size) duple */
return; return 0;
} }
do { do {
...@@ -526,6 +527,8 @@ static void __init early_init_drmem_lmb(struct drmem_lmb *lmb, ...@@ -526,6 +527,8 @@ static void __init early_init_drmem_lmb(struct drmem_lmb *lmb,
if (lmb->flags & DRCONF_MEM_HOTREMOVABLE) if (lmb->flags & DRCONF_MEM_HOTREMOVABLE)
memblock_mark_hotplug(base, size); memblock_mark_hotplug(base, size);
} while (--rngs); } while (--rngs);
return 0;
} }
#endif /* CONFIG_PPC_PSERIES */ #endif /* CONFIG_PPC_PSERIES */
...@@ -536,7 +539,7 @@ static int __init early_init_dt_scan_memory_ppc(unsigned long node, ...@@ -536,7 +539,7 @@ static int __init early_init_dt_scan_memory_ppc(unsigned long node,
#ifdef CONFIG_PPC_PSERIES #ifdef CONFIG_PPC_PSERIES
if (depth == 1 && if (depth == 1 &&
strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) { strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) {
walk_drmem_lmbs_early(node, early_init_drmem_lmb); walk_drmem_lmbs_early(node, NULL, early_init_drmem_lmb);
return 0; return 0;
} }
#endif #endif
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <asm/prom.h> #include <asm/prom.h>
#include <asm/drmem.h> #include <asm/drmem.h>
static int n_root_addr_cells, n_root_size_cells;
static struct drmem_lmb_info __drmem_info; static struct drmem_lmb_info __drmem_info;
struct drmem_lmb_info *drmem_info = &__drmem_info; struct drmem_lmb_info *drmem_info = &__drmem_info;
...@@ -189,12 +191,13 @@ int drmem_update_dt(void) ...@@ -189,12 +191,13 @@ int drmem_update_dt(void)
return rc; return rc;
} }
static void __init read_drconf_v1_cell(struct drmem_lmb *lmb, static void read_drconf_v1_cell(struct drmem_lmb *lmb,
const __be32 **prop) const __be32 **prop)
{ {
const __be32 *p = *prop; const __be32 *p = *prop;
lmb->base_addr = dt_mem_next_cell(dt_root_addr_cells, &p); lmb->base_addr = of_read_number(p, n_root_addr_cells);
p += n_root_addr_cells;
lmb->drc_index = of_read_number(p++, 1); lmb->drc_index = of_read_number(p++, 1);
p++; /* skip reserved field */ p++; /* skip reserved field */
...@@ -205,29 +208,33 @@ static void __init read_drconf_v1_cell(struct drmem_lmb *lmb, ...@@ -205,29 +208,33 @@ static void __init read_drconf_v1_cell(struct drmem_lmb *lmb,
*prop = p; *prop = p;
} }
static void __init __walk_drmem_v1_lmbs(const __be32 *prop, const __be32 *usm, static int
void (*func)(struct drmem_lmb *, const __be32 **)) __walk_drmem_v1_lmbs(const __be32 *prop, const __be32 *usm, void *data,
int (*func)(struct drmem_lmb *, const __be32 **, void *))
{ {
struct drmem_lmb lmb; struct drmem_lmb lmb;
u32 i, n_lmbs; u32 i, n_lmbs;
int ret = 0;
n_lmbs = of_read_number(prop++, 1); n_lmbs = of_read_number(prop++, 1);
if (n_lmbs == 0)
return;
for (i = 0; i < n_lmbs; i++) { for (i = 0; i < n_lmbs; i++) {
read_drconf_v1_cell(&lmb, &prop); read_drconf_v1_cell(&lmb, &prop);
func(&lmb, &usm); ret = func(&lmb, &usm, data);
if (ret)
break;
} }
return ret;
} }
static void __init read_drconf_v2_cell(struct of_drconf_cell_v2 *dr_cell, static void read_drconf_v2_cell(struct of_drconf_cell_v2 *dr_cell,
const __be32 **prop) const __be32 **prop)
{ {
const __be32 *p = *prop; const __be32 *p = *prop;
dr_cell->seq_lmbs = of_read_number(p++, 1); dr_cell->seq_lmbs = of_read_number(p++, 1);
dr_cell->base_addr = dt_mem_next_cell(dt_root_addr_cells, &p); dr_cell->base_addr = of_read_number(p, n_root_addr_cells);
p += n_root_addr_cells;
dr_cell->drc_index = of_read_number(p++, 1); dr_cell->drc_index = of_read_number(p++, 1);
dr_cell->aa_index = of_read_number(p++, 1); dr_cell->aa_index = of_read_number(p++, 1);
dr_cell->flags = of_read_number(p++, 1); dr_cell->flags = of_read_number(p++, 1);
...@@ -235,17 +242,16 @@ static void __init read_drconf_v2_cell(struct of_drconf_cell_v2 *dr_cell, ...@@ -235,17 +242,16 @@ static void __init read_drconf_v2_cell(struct of_drconf_cell_v2 *dr_cell,
*prop = p; *prop = p;
} }
static void __init __walk_drmem_v2_lmbs(const __be32 *prop, const __be32 *usm, static int
void (*func)(struct drmem_lmb *, const __be32 **)) __walk_drmem_v2_lmbs(const __be32 *prop, const __be32 *usm, void *data,
int (*func)(struct drmem_lmb *, const __be32 **, void *))
{ {
struct of_drconf_cell_v2 dr_cell; struct of_drconf_cell_v2 dr_cell;
struct drmem_lmb lmb; struct drmem_lmb lmb;
u32 i, j, lmb_sets; u32 i, j, lmb_sets;
int ret = 0;
lmb_sets = of_read_number(prop++, 1); lmb_sets = of_read_number(prop++, 1);
if (lmb_sets == 0)
return;
for (i = 0; i < lmb_sets; i++) { for (i = 0; i < lmb_sets; i++) {
read_drconf_v2_cell(&dr_cell, &prop); read_drconf_v2_cell(&dr_cell, &prop);
...@@ -259,21 +265,29 @@ static void __init __walk_drmem_v2_lmbs(const __be32 *prop, const __be32 *usm, ...@@ -259,21 +265,29 @@ static void __init __walk_drmem_v2_lmbs(const __be32 *prop, const __be32 *usm,
lmb.aa_index = dr_cell.aa_index; lmb.aa_index = dr_cell.aa_index;
lmb.flags = dr_cell.flags; lmb.flags = dr_cell.flags;
func(&lmb, &usm); ret = func(&lmb, &usm, data);
if (ret)
break;
} }
} }
return ret;
} }
#ifdef CONFIG_PPC_PSERIES #ifdef CONFIG_PPC_PSERIES
void __init walk_drmem_lmbs_early(unsigned long node, int __init walk_drmem_lmbs_early(unsigned long node, void *data,
void (*func)(struct drmem_lmb *, const __be32 **)) int (*func)(struct drmem_lmb *, const __be32 **, void *))
{ {
const __be32 *prop, *usm; const __be32 *prop, *usm;
int len; int len, ret = -ENODEV;
prop = of_get_flat_dt_prop(node, "ibm,lmb-size", &len); prop = of_get_flat_dt_prop(node, "ibm,lmb-size", &len);
if (!prop || len < dt_root_size_cells * sizeof(__be32)) if (!prop || len < dt_root_size_cells * sizeof(__be32))
return; 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); drmem_info->lmb_size = dt_mem_next_cell(dt_root_size_cells, &prop);
...@@ -281,20 +295,21 @@ void __init walk_drmem_lmbs_early(unsigned long node, ...@@ -281,20 +295,21 @@ void __init walk_drmem_lmbs_early(unsigned long node,
prop = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &len); prop = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &len);
if (prop) { if (prop) {
__walk_drmem_v1_lmbs(prop, usm, func); ret = __walk_drmem_v1_lmbs(prop, usm, data, func);
} else { } else {
prop = of_get_flat_dt_prop(node, "ibm,dynamic-memory-v2", prop = of_get_flat_dt_prop(node, "ibm,dynamic-memory-v2",
&len); &len);
if (prop) if (prop)
__walk_drmem_v2_lmbs(prop, usm, func); ret = __walk_drmem_v2_lmbs(prop, usm, data, func);
} }
memblock_dump_all(); memblock_dump_all();
return ret;
} }
#endif #endif
static int __init init_drmem_lmb_size(struct device_node *dn) static int init_drmem_lmb_size(struct device_node *dn)
{ {
const __be32 *prop; const __be32 *prop;
int len; int len;
...@@ -303,12 +318,12 @@ static int __init init_drmem_lmb_size(struct device_node *dn) ...@@ -303,12 +318,12 @@ static int __init init_drmem_lmb_size(struct device_node *dn)
return 0; return 0;
prop = of_get_property(dn, "ibm,lmb-size", &len); prop = of_get_property(dn, "ibm,lmb-size", &len);
if (!prop || len < dt_root_size_cells * sizeof(__be32)) { if (!prop || len < n_root_size_cells * sizeof(__be32)) {
pr_info("Could not determine LMB size\n"); pr_info("Could not determine LMB size\n");
return -1; return -1;
} }
drmem_info->lmb_size = dt_mem_next_cell(dt_root_size_cells, &prop); drmem_info->lmb_size = of_read_number(prop, n_root_size_cells);
return 0; return 0;
} }
...@@ -329,24 +344,36 @@ static const __be32 *of_get_usable_memory(struct device_node *dn) ...@@ -329,24 +344,36 @@ static const __be32 *of_get_usable_memory(struct device_node *dn)
return prop; return prop;
} }
void __init walk_drmem_lmbs(struct device_node *dn, int walk_drmem_lmbs(struct device_node *dn, void *data,
void (*func)(struct drmem_lmb *, const __be32 **)) int (*func)(struct drmem_lmb *, const __be32 **, void *))
{ {
const __be32 *prop, *usm; const __be32 *prop, *usm;
int ret = -ENODEV;
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)) if (init_drmem_lmb_size(dn))
return; return ret;
usm = of_get_usable_memory(dn); usm = of_get_usable_memory(dn);
prop = of_get_property(dn, "ibm,dynamic-memory", NULL); prop = of_get_property(dn, "ibm,dynamic-memory", NULL);
if (prop) { if (prop) {
__walk_drmem_v1_lmbs(prop, usm, func); ret = __walk_drmem_v1_lmbs(prop, usm, data, func);
} else { } else {
prop = of_get_property(dn, "ibm,dynamic-memory-v2", NULL); prop = of_get_property(dn, "ibm,dynamic-memory-v2", NULL);
if (prop) if (prop)
__walk_drmem_v2_lmbs(prop, usm, func); ret = __walk_drmem_v2_lmbs(prop, usm, data, func);
} }
return ret;
} }
static void __init init_drmem_v1_lmbs(const __be32 *prop) static void __init init_drmem_v1_lmbs(const __be32 *prop)
......
...@@ -645,8 +645,9 @@ static inline int __init read_usm_ranges(const __be32 **usm) ...@@ -645,8 +645,9 @@ static inline int __init read_usm_ranges(const __be32 **usm)
* Extract NUMA information from the ibm,dynamic-reconfiguration-memory * Extract NUMA information from the ibm,dynamic-reconfiguration-memory
* node. This assumes n_mem_{addr,size}_cells have been set. * node. This assumes n_mem_{addr,size}_cells have been set.
*/ */
static void __init numa_setup_drmem_lmb(struct drmem_lmb *lmb, static int __init numa_setup_drmem_lmb(struct drmem_lmb *lmb,
const __be32 **usm) const __be32 **usm,
void *data)
{ {
unsigned int ranges, is_kexec_kdump = 0; unsigned int ranges, is_kexec_kdump = 0;
unsigned long base, size, sz; unsigned long base, size, sz;
...@@ -658,7 +659,7 @@ static void __init numa_setup_drmem_lmb(struct drmem_lmb *lmb, ...@@ -658,7 +659,7 @@ static void __init numa_setup_drmem_lmb(struct drmem_lmb *lmb,
*/ */
if ((lmb->flags & DRCONF_MEM_RESERVED) if ((lmb->flags & DRCONF_MEM_RESERVED)
|| !(lmb->flags & DRCONF_MEM_ASSIGNED)) || !(lmb->flags & DRCONF_MEM_ASSIGNED))
return; return 0;
if (*usm) if (*usm)
is_kexec_kdump = 1; is_kexec_kdump = 1;
...@@ -670,7 +671,7 @@ static void __init numa_setup_drmem_lmb(struct drmem_lmb *lmb, ...@@ -670,7 +671,7 @@ static void __init numa_setup_drmem_lmb(struct drmem_lmb *lmb,
if (is_kexec_kdump) { if (is_kexec_kdump) {
ranges = read_usm_ranges(usm); ranges = read_usm_ranges(usm);
if (!ranges) /* there are no (base, size) duple */ if (!ranges) /* there are no (base, size) duple */
return; return 0;
} }
do { do {
...@@ -687,6 +688,8 @@ static void __init numa_setup_drmem_lmb(struct drmem_lmb *lmb, ...@@ -687,6 +688,8 @@ static void __init numa_setup_drmem_lmb(struct drmem_lmb *lmb,
if (sz) if (sz)
memblock_set_node(base, sz, &memblock.memory, nid); memblock_set_node(base, sz, &memblock.memory, nid);
} while (--ranges); } while (--ranges);
return 0;
} }
static int __init parse_numa_properties(void) static int __init parse_numa_properties(void)
...@@ -788,7 +791,7 @@ static int __init parse_numa_properties(void) ...@@ -788,7 +791,7 @@ static int __init parse_numa_properties(void)
*/ */
memory = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory"); memory = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
if (memory) { if (memory) {
walk_drmem_lmbs(memory, numa_setup_drmem_lmb); walk_drmem_lmbs(memory, NULL, numa_setup_drmem_lmb);
of_node_put(memory); of_node_put(memory);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment