2 * pseries Memory Hotplug infrastructure.
4 * Copyright (C) 2008 Badari Pulavarty, IBM Corporation
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.
13 #include <linux/lmb.h>
14 #include <linux/vmalloc.h>
15 #include <asm/firmware.h>
16 #include <asm/machdep.h>
17 #include <asm/pSeries_reconfig.h>
18 #include <asm/sparsemem.h>
20 static int pseries_remove_lmb(unsigned long base
, unsigned int lmb_size
)
22 unsigned long start
, start_pfn
;
26 start_pfn
= base
>> PAGE_SHIFT
;
28 if (!pfn_valid(start_pfn
)) {
29 lmb_remove(base
, lmb_size
);
33 zone
= page_zone(pfn_to_page(start_pfn
));
36 * Remove section mappings and sysfs entries for the
37 * section of the memory we are removing.
39 * NOTE: Ideally, this should be done in generic code like
40 * remove_memory(). But remove_memory() gets called by writing
41 * to sysfs "state" file and we can't remove sysfs entries
42 * while writing to it. So we have to defer it to here.
44 ret
= __remove_pages(zone
, start_pfn
, lmb_size
>> PAGE_SHIFT
);
49 * Update memory regions for memory remove
51 lmb_remove(base
, lmb_size
);
54 * Remove htab bolted mappings for this section of memory
56 start
= (unsigned long)__va(base
);
57 ret
= remove_section_mapping(start
, start
+ lmb_size
);
59 /* Ensure all vmalloc mappings are flushed in case they also
60 * hit that section of memory
67 static int pseries_remove_memory(struct device_node
*np
)
70 const unsigned int *regs
;
72 unsigned int lmb_size
;
76 * Check to see if we are actually removing memory
78 type
= of_get_property(np
, "device_type", NULL
);
79 if (type
== NULL
|| strcmp(type
, "memory") != 0)
83 * Find the bae address and size of the lmb
85 regs
= of_get_property(np
, "reg", NULL
);
89 base
= *(unsigned long *)regs
;
92 ret
= pseries_remove_lmb(base
, lmb_size
);
96 static int pseries_add_memory(struct device_node
*np
)
99 const unsigned int *regs
;
101 unsigned int lmb_size
;
105 * Check to see if we are actually adding memory
107 type
= of_get_property(np
, "device_type", NULL
);
108 if (type
== NULL
|| strcmp(type
, "memory") != 0)
112 * Find the base and size of the lmb
114 regs
= of_get_property(np
, "reg", NULL
);
118 base
= *(unsigned long *)regs
;
122 * Update memory region to represent the memory add
124 ret
= lmb_add(base
, lmb_size
);
125 return (ret
< 0) ? -EINVAL
: 0;
128 static int pseries_drconf_memory(unsigned long *base
, unsigned int action
)
130 struct device_node
*np
;
131 const unsigned long *lmb_size
;
134 np
= of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
138 lmb_size
= of_get_property(np
, "ibm,lmb-size", NULL
);
144 if (action
== PSERIES_DRCONF_MEM_ADD
) {
145 rc
= lmb_add(*base
, *lmb_size
);
146 rc
= (rc
< 0) ? -EINVAL
: 0;
147 } else if (action
== PSERIES_DRCONF_MEM_REMOVE
) {
148 rc
= pseries_remove_lmb(*base
, *lmb_size
);
157 static int pseries_memory_notifier(struct notifier_block
*nb
,
158 unsigned long action
, void *node
)
163 case PSERIES_RECONFIG_ADD
:
164 if (pseries_add_memory(node
))
167 case PSERIES_RECONFIG_REMOVE
:
168 if (pseries_remove_memory(node
))
171 case PSERIES_DRCONF_MEM_ADD
:
172 case PSERIES_DRCONF_MEM_REMOVE
:
173 if (pseries_drconf_memory(node
, action
))
183 static struct notifier_block pseries_mem_nb
= {
184 .notifier_call
= pseries_memory_notifier
,
187 static int __init
pseries_memory_hotplug_init(void)
189 if (firmware_has_feature(FW_FEATURE_LPAR
))
190 pSeries_reconfig_notifier_register(&pseries_mem_nb
);
194 machine_device_initcall(pseries
, pseries_memory_hotplug_init
);