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 <asm/firmware.h>
14 #include <asm/machdep.h>
15 #include <asm/pSeries_reconfig.h>
17 static int pseries_remove_memory(struct device_node
*np
)
20 const unsigned int *my_index
;
21 const unsigned int *regs
;
27 * Check to see if we are actually removing memory
29 type
= of_get_property(np
, "device_type", NULL
);
30 if (type
== NULL
|| strcmp(type
, "memory") != 0)
34 * Find the memory index and size of the removing section
36 my_index
= of_get_property(np
, "ibm,my-drc-index", NULL
);
40 regs
= of_get_property(np
, "reg", NULL
);
44 start_pfn
= section_nr_to_pfn(*my_index
& 0xffff);
45 zone
= page_zone(pfn_to_page(start_pfn
));
48 * Remove section mappings and sysfs entries for the
49 * section of the memory we are removing.
51 * NOTE: Ideally, this should be done in generic code like
52 * remove_memory(). But remove_memory() gets called by writing
53 * to sysfs "state" file and we can't remove sysfs entries
54 * while writing to it. So we have to defer it to here.
56 ret
= __remove_pages(zone
, start_pfn
, regs
[3] >> PAGE_SHIFT
);
61 * Remove htab bolted mappings for this section of memory
63 start
= (unsigned long)__va(start_pfn
<< PAGE_SHIFT
);
64 ret
= remove_section_mapping(start
, start
+ regs
[3]);
68 static int pseries_memory_notifier(struct notifier_block
*nb
,
69 unsigned long action
, void *node
)
74 case PSERIES_RECONFIG_ADD
:
76 case PSERIES_RECONFIG_REMOVE
:
77 if (pseries_remove_memory(node
))
87 static struct notifier_block pseries_mem_nb
= {
88 .notifier_call
= pseries_memory_notifier
,
91 static int __init
pseries_memory_hotplug_init(void)
93 if (firmware_has_feature(FW_FEATURE_LPAR
))
94 pSeries_reconfig_notifier_register(&pseries_mem_nb
);
98 machine_device_initcall(pseries
, pseries_memory_hotplug_init
);