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 *my_index;
22 const unsigned int *regs;
28 * Check to see if we are actually removing memory
30 type = of_get_property(np, "device_type", NULL);
31 if (type == NULL || strcmp(type, "memory") != 0)
35 * Find the memory index and size of the removing section
37 my_index = of_get_property(np, "ibm,my-drc-index", NULL);
41 regs = of_get_property(np, "reg", NULL);
45 start_pfn = section_nr_to_pfn(*my_index & 0xffff);
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, regs[3] >> PAGE_SHIFT);
62 * Update memory regions for memory remove
64 lmb_remove(start_pfn << PAGE_SHIFT, regs[3]);
67 * Remove htab bolted mappings for this section of memory
69 start = (unsigned long)__va(start_pfn << PAGE_SHIFT);
70 ret = remove_section_mapping(start, start + regs[3]);
74 static int pseries_add_memory(struct device_node *np)
77 const unsigned int *my_index;
78 const unsigned int *regs;
83 * Check to see if we are actually adding memory
85 type = of_get_property(np, "device_type", NULL);
86 if (type == NULL || strcmp(type, "memory") != 0)
90 * Find the memory index and size of the added section
92 my_index = of_get_property(np, "ibm,my-drc-index", NULL);
96 regs = of_get_property(np, "reg", NULL);
100 start_pfn = section_nr_to_pfn(*my_index & 0xffff);
103 * Update memory region to represent the memory add
105 lmb_add(start_pfn << PAGE_SHIFT, regs[3]);
109 static int pseries_memory_notifier(struct notifier_block *nb,
110 unsigned long action, void *node)
115 case PSERIES_RECONFIG_ADD:
116 if (pseries_add_memory(node))
119 case PSERIES_RECONFIG_REMOVE:
120 if (pseries_remove_memory(node))
130 static struct notifier_block pseries_mem_nb = {
131 .notifier_call = pseries_memory_notifier,
134 static int __init pseries_memory_hotplug_init(void)
136 if (firmware_has_feature(FW_FEATURE_LPAR))
137 pSeries_reconfig_notifier_register(&pseries_mem_nb);
141 machine_device_initcall(pseries, pseries_memory_hotplug_init);