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 <asm/firmware.h>
15 #include <asm/machdep.h>
16 #include <asm/pSeries_reconfig.h>
18 static int pseries_remove_memory(struct device_node
*np
)
21 const unsigned int *regs
;
23 unsigned int lmb_size
;
29 * Check to see if we are actually removing memory
31 type
= of_get_property(np
, "device_type", NULL
);
32 if (type
== NULL
|| strcmp(type
, "memory") != 0)
36 * Find the bae address and size of the lmb
38 regs
= of_get_property(np
, "reg", NULL
);
42 base
= *(unsigned long *)regs
;
45 start_pfn
= base
>> PFN_SECTION_SHIFT
;
46 zone
= page_zone(pfn_to_page(start_pfn
));
49 * Remove section mappings and sysfs entries for the
50 * section of the memory we are removing.
52 * NOTE: Ideally, this should be done in generic code like
53 * remove_memory(). But remove_memory() gets called by writing
54 * to sysfs "state" file and we can't remove sysfs entries
55 * while writing to it. So we have to defer it to here.
57 ret
= __remove_pages(zone
, start_pfn
, lmb_size
>> PAGE_SHIFT
);
62 * Update memory regions for memory remove
64 lmb_remove(base
, lmb_size
);
67 * Remove htab bolted mappings for this section of memory
69 start
= (unsigned long)__va(base
);
70 ret
= remove_section_mapping(start
, start
+ lmb_size
);
74 static int pseries_add_memory(struct device_node
*np
)
77 const unsigned int *regs
;
79 unsigned int lmb_size
;
84 * Check to see if we are actually adding memory
86 type
= of_get_property(np
, "device_type", NULL
);
87 if (type
== NULL
|| strcmp(type
, "memory") != 0)
91 * Find the base and size of the lmb
93 regs
= of_get_property(np
, "reg", NULL
);
97 base
= *(unsigned long *)regs
;
101 * Update memory region to represent the memory add
103 lmb_add(base
, lmb_size
);
107 static int pseries_memory_notifier(struct notifier_block
*nb
,
108 unsigned long action
, void *node
)
113 case PSERIES_RECONFIG_ADD
:
114 if (pseries_add_memory(node
))
117 case PSERIES_RECONFIG_REMOVE
:
118 if (pseries_remove_memory(node
))
128 static struct notifier_block pseries_mem_nb
= {
129 .notifier_call
= pseries_memory_notifier
,
132 static int __init
pseries_memory_hotplug_init(void)
134 if (firmware_has_feature(FW_FEATURE_LPAR
))
135 pSeries_reconfig_notifier_register(&pseries_mem_nb
);
139 machine_device_initcall(pseries
, pseries_memory_hotplug_init
);