Skip to content

Commit 6c6ea53

Browse files
nfontmpe
authored andcommitted
powerpc/mm: Separate ibm, dynamic-memory data from DT format
We currently have code to parse the dynamic reconfiguration LMB information from the ibm,dynamic-meory device tree property in multiple locations; numa.c, prom.c, and pseries/hotplug-memory.c. In anticipation of adding support for a version 2 of the ibm,dynamic-memory property this patch aims to separate the device tree information from the device tree format. Doing this requires a two step process to avoid a possibly very large bootmem allocation early in boot. During initial boot, new routines are provided to walk the device tree property and make a call-back for each LMB. The second step (introduced in later patches) will allocate an array of LMB information that can be used directly without needing to know the DT format. This approach provides the benefit of consolidating the device tree property parsing to a single location and (eventually) providing a common data structure for retrieving LMB information. This patch introduces a routine to walk the ibm,dynamic-memory property in the flattened device tree and updates the prom.c code to use this to initialize memory. Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent b88fc30 commit 6c6ea53

4 files changed

Lines changed: 174 additions & 67 deletions

File tree

‎arch/powerpc/include/asm/drmem.h‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* drmem.h: Power specific logical memory block representation
3+
*
4+
* Copyright 2017 IBM Corporation
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version
9+
* 2 of the License, or (at your option) any later version.
10+
*/
11+
12+
#ifndef _ASM_POWERPC_LMB_H
13+
#define _ASM_POWERPC_LMB_H
14+
15+
struct drmem_lmb {
16+
u64 base_addr;
17+
u32 drc_index;
18+
u32 aa_index;
19+
u32 flags;
20+
};
21+
22+
struct drmem_lmb_info {
23+
struct drmem_lmb *lmbs;
24+
int n_lmbs;
25+
u32 lmb_size;
26+
};
27+
28+
extern struct drmem_lmb_info *drmem_info;
29+
30+
#define for_each_drmem_lmb_in_range(lmb, start, end) \
31+
for ((lmb) = (start); (lmb) <= (end); (lmb)++)
32+
33+
#define for_each_drmem_lmb(lmb) \
34+
for_each_drmem_lmb_in_range((lmb), \
35+
&drmem_info->lmbs[0], \
36+
&drmem_info->lmbs[drmem_info->n_lmbs - 1])
37+
38+
static inline u32 drmem_lmb_size(void)
39+
{
40+
return drmem_info->lmb_size;
41+
}
42+
43+
#ifdef CONFIG_PPC_PSERIES
44+
void __init walk_drmem_lmbs_early(unsigned long node,
45+
void (*func)(struct drmem_lmb *, const __be32 **));
46+
#endif
47+
48+
#endif /* _ASM_POWERPC_LMB_H */

‎arch/powerpc/kernel/prom.c‎

Lines changed: 49 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include <asm/epapr_hcalls.h>
6060
#include <asm/firmware.h>
6161
#include <asm/dt_cpu_ftrs.h>
62+
#include <asm/drmem.h>
6263

6364
#include <mm/mmu_decl.h>
6465

@@ -455,92 +456,74 @@ static int __init early_init_dt_scan_chosen_ppc(unsigned long node,
455456

456457
#ifdef CONFIG_PPC_PSERIES
457458
/*
458-
* Interpret the ibm,dynamic-memory property in the
459-
* /ibm,dynamic-reconfiguration-memory node.
459+
* Interpret the ibm dynamic reconfiguration memory LMBs.
460460
* This contains a list of memory blocks along with NUMA affinity
461461
* information.
462462
*/
463-
static int __init early_init_dt_scan_drconf_memory(unsigned long node)
463+
static void __init early_init_drmem_lmb(struct drmem_lmb *lmb,
464+
const __be32 **usm)
464465
{
465-
const __be32 *dm, *ls, *usm;
466-
int l;
467-
unsigned long n, flags;
468-
u64 base, size, memblock_size;
469-
unsigned int is_kexec_kdump = 0, rngs;
470-
471-
ls = of_get_flat_dt_prop(node, "ibm,lmb-size", &l);
472-
if (ls == NULL || l < dt_root_size_cells * sizeof(__be32))
473-
return 0;
474-
memblock_size = dt_mem_next_cell(dt_root_size_cells, &ls);
466+
u64 base, size;
467+
int is_kexec_kdump = 0, rngs;
475468

476-
dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &l);
477-
if (dm == NULL || l < sizeof(__be32))
478-
return 0;
469+
base = lmb->base_addr;
470+
size = drmem_lmb_size();
471+
rngs = 1;
479472

480-
n = of_read_number(dm++, 1); /* number of entries */
481-
if (l < (n * (dt_root_addr_cells + 4) + 1) * sizeof(__be32))
482-
return 0;
473+
/*
474+
* Skip this block if the reserved bit is set in flags
475+
* or if the block is not assigned to this partition.
476+
*/
477+
if ((lmb->flags & DRCONF_MEM_RESERVED) ||
478+
!(lmb->flags & DRCONF_MEM_ASSIGNED))
479+
return;
483480

484-
/* check if this is a kexec/kdump kernel. */
485-
usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory",
486-
&l);
487-
if (usm != NULL)
481+
if (*usm)
488482
is_kexec_kdump = 1;
489483

490-
for (; n != 0; --n) {
491-
base = dt_mem_next_cell(dt_root_addr_cells, &dm);
492-
flags = of_read_number(&dm[3], 1);
493-
/* skip DRC index, pad, assoc. list index, flags */
494-
dm += 4;
495-
/* skip this block if the reserved bit is set in flags
496-
or if the block is not assigned to this partition */
497-
if ((flags & DRCONF_MEM_RESERVED) ||
498-
!(flags & DRCONF_MEM_ASSIGNED))
499-
continue;
500-
size = memblock_size;
501-
rngs = 1;
484+
if (is_kexec_kdump) {
485+
/*
486+
* For each memblock in ibm,dynamic-memory, a
487+
* corresponding entry in linux,drconf-usable-memory
488+
* property contains a counter 'p' followed by 'p'
489+
* (base, size) duple. Now read the counter from
490+
* linux,drconf-usable-memory property
491+
*/
492+
rngs = dt_mem_next_cell(dt_root_size_cells, usm);
493+
if (!rngs) /* there are no (base, size) duple */
494+
return;
495+
}
496+
497+
do {
502498
if (is_kexec_kdump) {
503-
/*
504-
* For each memblock in ibm,dynamic-memory, a corresponding
505-
* entry in linux,drconf-usable-memory property contains
506-
* a counter 'p' followed by 'p' (base, size) duple.
507-
* Now read the counter from
508-
* linux,drconf-usable-memory property
509-
*/
510-
rngs = dt_mem_next_cell(dt_root_size_cells, &usm);
511-
if (!rngs) /* there are no (base, size) duple */
499+
base = dt_mem_next_cell(dt_root_addr_cells, usm);
500+
size = dt_mem_next_cell(dt_root_size_cells, usm);
501+
}
502+
503+
if (iommu_is_off) {
504+
if (base >= 0x80000000ul)
512505
continue;
506+
if ((base + size) > 0x80000000ul)
507+
size = 0x80000000ul - base;
513508
}
514-
do {
515-
if (is_kexec_kdump) {
516-
base = dt_mem_next_cell(dt_root_addr_cells,
517-
&usm);
518-
size = dt_mem_next_cell(dt_root_size_cells,
519-
&usm);
520-
}
521-
if (iommu_is_off) {
522-
if (base >= 0x80000000ul)
523-
continue;
524-
if ((base + size) > 0x80000000ul)
525-
size = 0x80000000ul - base;
526-
}
527-
memblock_add(base, size);
528-
} while (--rngs);
529-
}
530-
memblock_dump_all();
531-
return 0;
509+
510+
DBG("Adding: %llx -> %llx\n", base, size);
511+
memblock_add(base, size);
512+
} while (--rngs);
532513
}
533-
#else
534-
#define early_init_dt_scan_drconf_memory(node) 0
535514
#endif /* CONFIG_PPC_PSERIES */
536515

537516
static int __init early_init_dt_scan_memory_ppc(unsigned long node,
538517
const char *uname,
539518
int depth, void *data)
540519
{
520+
#ifdef CONFIG_PPC_PSERIES
541521
if (depth == 1 &&
542-
strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0)
543-
return early_init_dt_scan_drconf_memory(node);
522+
strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) {
523+
walk_drmem_lmbs_early(node, early_init_drmem_lmb);
524+
return 0;
525+
}
526+
#endif
544527

545528
return early_init_dt_scan_memory(node, uname, depth, data);
546529
}

‎arch/powerpc/mm/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC)
99

1010
obj-y := fault.o mem.o pgtable.o mmap.o \
1111
init_$(BITS).o pgtable_$(BITS).o \
12-
init-common.o mmu_context.o
12+
init-common.o mmu_context.o drmem.o
1313
obj-$(CONFIG_PPC_MMU_NOHASH) += mmu_context_nohash.o tlb_nohash.o \
1414
tlb_nohash_low.o
1515
obj-$(CONFIG_PPC_BOOK3E) += tlb_low_$(BITS)e.o

‎arch/powerpc/mm/drmem.c‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Dynamic reconfiguration memory support
3+
*
4+
* Copyright 2017 IBM Corporation
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version
9+
* 2 of the License, or (at your option) any later version.
10+
*/
11+
12+
#define pr_fmt(fmt) "drmem: " fmt
13+
14+
#include <linux/kernel.h>
15+
#include <linux/of.h>
16+
#include <linux/of_fdt.h>
17+
#include <linux/memblock.h>
18+
#include <asm/prom.h>
19+
#include <asm/drmem.h>
20+
21+
static struct drmem_lmb_info __drmem_info;
22+
struct drmem_lmb_info *drmem_info = &__drmem_info;
23+
24+
#ifdef CONFIG_PPC_PSERIES
25+
static void __init read_drconf_v1_cell(struct drmem_lmb *lmb,
26+
const __be32 **prop)
27+
{
28+
const __be32 *p = *prop;
29+
30+
lmb->base_addr = dt_mem_next_cell(dt_root_addr_cells, &p);
31+
lmb->drc_index = of_read_number(p++, 1);
32+
33+
p++; /* skip reserved field */
34+
35+
lmb->aa_index = of_read_number(p++, 1);
36+
lmb->flags = of_read_number(p++, 1);
37+
38+
*prop = p;
39+
}
40+
41+
static void __init __walk_drmem_v1_lmbs(const __be32 *prop, const __be32 *usm,
42+
void (*func)(struct drmem_lmb *, const __be32 **))
43+
{
44+
struct drmem_lmb lmb;
45+
u32 i, n_lmbs;
46+
47+
n_lmbs = of_read_number(prop++, 1);
48+
49+
for (i = 0; i < n_lmbs; i++) {
50+
read_drconf_v1_cell(&lmb, &prop);
51+
func(&lmb, &usm);
52+
}
53+
}
54+
55+
void __init walk_drmem_lmbs_early(unsigned long node,
56+
void (*func)(struct drmem_lmb *, const __be32 **))
57+
{
58+
const __be32 *prop, *usm;
59+
int len;
60+
61+
prop = of_get_flat_dt_prop(node, "ibm,lmb-size", &len);
62+
if (!prop || len < dt_root_size_cells * sizeof(__be32))
63+
return;
64+
65+
drmem_info->lmb_size = dt_mem_next_cell(dt_root_size_cells, &prop);
66+
67+
usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory", &len);
68+
69+
prop = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &len);
70+
if (prop)
71+
__walk_drmem_v1_lmbs(prop, usm, func);
72+
73+
memblock_dump_all();
74+
}
75+
76+
#endif

0 commit comments

Comments
 (0)