[PATCH V8 2/8] powerpc/memory: Parse new memory property to register blocks.
powerpc/memory: Add parallel routines to parse the new property "ibm,dynamic-memory-v2" property when it is present, and then to register the relevant memory blocks with the operating system. This property format is intended to provide a more compact representation of memory when communicating with the front end processor, especially when describing vast amounts of RAM. [V2: Revise contant names.] [V3: Fix error parsing the new memory block sets.] [V4: Move a couple of function prototypes from header file a later patch where first used. Amend some comments. Change a firmware architure vec check for scan actual device tree. Compress some common code.] [V5: Resynchronize/resubmit] [V6: No change] [V7: Correct mail threading] [v8: Insert more useful variable names] Signed-off-by: Michael Bringmann--- arch/powerpc/include/asm/prom.h | 24 -- arch/powerpc/kernel/prom.c | 97 --- arch/powerpc/mm/numa.c | 22 - 3 files changed, 129 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h index bc7c4b5..43a002b 100644 --- a/arch/powerpc/include/asm/prom.h +++ b/arch/powerpc/include/asm/prom.h @@ -69,6 +69,8 @@ struct boot_param_header { * OF address retreival & translation */ +extern int n_mem_addr_cells; + /* Parse the ibm,dma-window property of an OF node into the busno, phys and * size parameters. */ @@ -81,8 +83,9 @@ extern void of_instantiate_rtc(void); extern int of_get_ibm_chip_id(struct device_node *np); /* The of_drconf_cell struct defines the layout of the LMB array - * specified in the device tree property - * ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory + * specified in the device tree properties, + * ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory + * ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory-v2 */ struct of_drconf_cell { u64 base_addr; @@ -92,9 +95,20 @@ struct of_drconf_cell { u32 flags; }; -#define DRCONF_MEM_ASSIGNED0x0008 -#define DRCONF_MEM_AI_INVALID 0x0040 -#define DRCONF_MEM_RESERVED0x0080 +#define DRCONF_MEM_ASSIGNED0x0008 +#define DRCONF_MEM_AI_INVALID 0x0040 +#define DRCONF_MEM_RESERVED0x0080 + +struct of_drconf_cell_v2 { + u32 num_seq_lmbs; + u64 base_addr; + u32 drc_index; + u32 aa_index; + u32 flags; +} __attribute__((packed)); + +extern void read_drconf_cell_v2(struct of_drconf_cell_v2 *drmem, + const __be32 **cellp); /* * There are two methods for telling firmware what our capabilities are. diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index b0245be..2d49887 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -443,23 +443,34 @@ static int __init early_init_dt_scan_chosen_ppc(unsigned long node, #ifdef CONFIG_PPC_PSERIES /* - * Interpret the ibm,dynamic-memory property in the - * /ibm,dynamic-reconfiguration-memory node. + * Retrieve and validate the ibm,lmb-size property for drconf memory + * from the flattened device tree. + */ +static u64 __init get_lmb_size(unsigned long node) +{ + const __be32 *ls; + int len; + ls = of_get_flat_dt_prop(node, "ibm,lmb-size", ); + if (!ls || len < dt_root_size_cells * sizeof(__be32)) + return 0; + return dt_mem_next_cell(dt_root_size_cells, ); +} + +/* + * Interpret the ibm,dynamic-memory property/ibm,dynamic-memory-v2 + * in the /ibm,dynamic-reconfiguration-memory node. * This contains a list of memory blocks along with NUMA affinity * information. */ -static int __init early_init_dt_scan_drconf_memory(unsigned long node) +static int __init early_init_dt_scan_drconf_memory_v1(unsigned long node) { - const __be32 *dm, *ls, *usm; + const __be32 *dm, *usm; int l; unsigned long n, flags; u64 base, size, memblock_size; unsigned int is_kexec_kdump = 0, rngs; - ls = of_get_flat_dt_prop(node, "ibm,lmb-size", ); - if (ls == NULL || l < dt_root_size_cells * sizeof(__be32)) - return 0; - memblock_size = dt_mem_next_cell(dt_root_size_cells, ); + memblock_size = get_lmb_size(node); dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory", ); if (dm == NULL || l < sizeof(__be32)) @@ -518,6 +529,76 @@ static int __init early_init_dt_scan_drconf_memory(unsigned long node) memblock_dump_all(); return 0; } + +static int __init early_init_dt_scan_drconf_memory_v2(unsigned long node) +{ + const __be32 *dm; + int l; + unsigned long num_sets; + u64 size, base, memblock_size; + + memblock_size = get_lmb_size(node); + + dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory-v2", ); + if (dm == NULL || l < sizeof(__be32))
[PATCH V8 2/8] powerpc/memory: Parse new memory property to register blocks.
powerpc/memory: Add parallel routines to parse the new property "ibm,dynamic-memory-v2" property when it is present, and then to register the relevant memory blocks with the operating system. This property format is intended to provide a more compact representation of memory when communicating with the front end processor, especially when describing vast amounts of RAM. [V2: Revise contant names.] [V3: Fix error parsing the new memory block sets.] [V4: Move a couple of function prototypes from header file a later patch where first used. Amend some comments. Change a firmware architure vec check for scan actual device tree. Compress some common code.] [V5: Resynchronize/resubmit] [V6: No change] [V7: Correct mail threading] [v8: Insert more useful variable names] Signed-off-by: Michael Bringmann--- arch/powerpc/include/asm/prom.h | 24 -- arch/powerpc/kernel/prom.c | 97 --- arch/powerpc/mm/numa.c | 22 - 3 files changed, 129 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h index bc7c4b5..43a002b 100644 --- a/arch/powerpc/include/asm/prom.h +++ b/arch/powerpc/include/asm/prom.h @@ -69,6 +69,8 @@ struct boot_param_header { * OF address retreival & translation */ +extern int n_mem_addr_cells; + /* Parse the ibm,dma-window property of an OF node into the busno, phys and * size parameters. */ @@ -81,8 +83,9 @@ extern void of_instantiate_rtc(void); extern int of_get_ibm_chip_id(struct device_node *np); /* The of_drconf_cell struct defines the layout of the LMB array - * specified in the device tree property - * ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory + * specified in the device tree properties, + * ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory + * ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory-v2 */ struct of_drconf_cell { u64 base_addr; @@ -92,9 +95,20 @@ struct of_drconf_cell { u32 flags; }; -#define DRCONF_MEM_ASSIGNED0x0008 -#define DRCONF_MEM_AI_INVALID 0x0040 -#define DRCONF_MEM_RESERVED0x0080 +#define DRCONF_MEM_ASSIGNED0x0008 +#define DRCONF_MEM_AI_INVALID 0x0040 +#define DRCONF_MEM_RESERVED0x0080 + +struct of_drconf_cell_v2 { + u32 num_seq_lmbs; + u64 base_addr; + u32 drc_index; + u32 aa_index; + u32 flags; +} __attribute__((packed)); + +extern void read_drconf_cell_v2(struct of_drconf_cell_v2 *drmem, + const __be32 **cellp); /* * There are two methods for telling firmware what our capabilities are. diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index b0245be..2d49887 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -443,23 +443,34 @@ static int __init early_init_dt_scan_chosen_ppc(unsigned long node, #ifdef CONFIG_PPC_PSERIES /* - * Interpret the ibm,dynamic-memory property in the - * /ibm,dynamic-reconfiguration-memory node. + * Retrieve and validate the ibm,lmb-size property for drconf memory + * from the flattened device tree. + */ +static u64 __init get_lmb_size(unsigned long node) +{ + const __be32 *ls; + int len; + ls = of_get_flat_dt_prop(node, "ibm,lmb-size", ); + if (!ls || len < dt_root_size_cells * sizeof(__be32)) + return 0; + return dt_mem_next_cell(dt_root_size_cells, ); +} + +/* + * Interpret the ibm,dynamic-memory property/ibm,dynamic-memory-v2 + * in the /ibm,dynamic-reconfiguration-memory node. * This contains a list of memory blocks along with NUMA affinity * information. */ -static int __init early_init_dt_scan_drconf_memory(unsigned long node) +static int __init early_init_dt_scan_drconf_memory_v1(unsigned long node) { - const __be32 *dm, *ls, *usm; + const __be32 *dm, *usm; int l; unsigned long n, flags; u64 base, size, memblock_size; unsigned int is_kexec_kdump = 0, rngs; - ls = of_get_flat_dt_prop(node, "ibm,lmb-size", ); - if (ls == NULL || l < dt_root_size_cells * sizeof(__be32)) - return 0; - memblock_size = dt_mem_next_cell(dt_root_size_cells, ); + memblock_size = get_lmb_size(node); dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory", ); if (dm == NULL || l < sizeof(__be32)) @@ -518,6 +529,76 @@ static int __init early_init_dt_scan_drconf_memory(unsigned long node) memblock_dump_all(); return 0; } + +static int __init early_init_dt_scan_drconf_memory_v2(unsigned long node) +{ + const __be32 *dm; + int l; + unsigned long num_sets; + u64 size, base, memblock_size; + + memblock_size = get_lmb_size(node); + + dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory-v2", ); + if (dm == NULL || l < sizeof(__be32))