12
12
#include <linux/of.h>
13
13
#include <linux/memblock.h>
14
14
#include <linux/vmalloc.h>
15
#include <linux/memory.h>
15
17
#include <asm/firmware.h>
16
18
#include <asm/machdep.h>
17
19
#include <asm/pSeries_reconfig.h>
18
20
#include <asm/sparsemem.h>
22
static unsigned long get_memblock_size(void)
24
struct device_node *np;
25
unsigned int memblock_size = MIN_MEMORY_BLOCK_SIZE;
28
np = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
32
size = of_get_property(np, "ibm,lmb-size", NULL);
34
memblock_size = be64_to_cpup(size);
36
} else if (machine_is(pseries)) {
37
/* This fallback really only applies to pseries */
38
unsigned int memzero_size = 0;
40
np = of_find_node_by_path("/memory@0");
42
if (!of_address_to_resource(np, 0, &r))
43
memzero_size = resource_size(&r);
48
/* We now know the size of memory@0, use this to find
49
* the first memoryblock and get its size.
53
sprintf(buf, "/memory@%x", memzero_size);
54
np = of_find_node_by_path(buf);
56
if (!of_address_to_resource(np, 0, &r))
57
memblock_size = resource_size(&r);
65
/* WARNING: This is going to override the generic definition whenever
66
* pseries is built-in regardless of what platform is active at boot
67
* time. This is fine for now as this is the only "option" and it
68
* should work everywhere. If not, we'll have to turn this into a
71
unsigned long memory_block_size_bytes(void)
73
return get_memblock_size();
20
76
static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size)
22
78
unsigned long start, start_pfn;
128
184
static int pseries_drconf_memory(unsigned long *base, unsigned int action)
130
struct device_node *np;
131
const unsigned long *lmb_size;
186
unsigned long memblock_size;
134
np = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
138
lmb_size = of_get_property(np, "ibm,lmb-size", NULL);
189
memblock_size = get_memblock_size();
144
193
if (action == PSERIES_DRCONF_MEM_ADD) {
145
rc = memblock_add(*base, *lmb_size);
194
rc = memblock_add(*base, memblock_size);
146
195
rc = (rc < 0) ? -EINVAL : 0;
147
196
} else if (action == PSERIES_DRCONF_MEM_REMOVE) {
148
rc = pseries_remove_memblock(*base, *lmb_size);
197
rc = pseries_remove_memblock(*base, memblock_size);