aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakpm@linux-foundation.org <akpm@linux-foundation.org>2010-03-05 16:41:58 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-06 14:26:25 -0500
commitd96ae5309165d9ed7c008a178238977b73595cd9 (patch)
tree78b169102b718a9489fcc41ad4829a646492d2fb
parent9d8cebd4bcd7c3878462fdfda34bbcdeb4df7ef4 (diff)
memory-hotplug: create /sys/firmware/memmap entry for new memory
A memmap is a directory in sysfs which includes 3 text files: start, end and type. For example: start: 0x100000 end: 0x7e7b1cff type: System RAM Interface firmware_map_add was not called explicitly. Remove it and add function firmware_map_add_hotplug as hotplug interface of memmap. Each memory entry has a memmap in sysfs, When we hot-add new memory, sysfs does not export memmap entry for it. We add a call in function add_memory to function firmware_map_add_hotplug. Add a new function add_sysfs_fw_map_entry() to create memmap entry, it will be called when initialize memmap and hot-add memory. [akpm@linux-foundation.org: un-kernedoc a no longer kerneldoc comment] Signed-off-by: Shaohui Zheng <shaohui.zheng@intel.com> Acked-by: Andi Kleen <ak@linux.intel.com> Acked-by: Yasunori Goto <y-goto@jp.fujitsu.com> Reviewed-by: Wu Fengguang <fengguang.wu@intel.com> Cc: Dave Hansen <haveblue@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/firmware/memmap.c57
-rw-r--r--include/linux/firmware-map.h6
-rw-r--r--mm/memory_hotplug.c4
3 files changed, 43 insertions, 24 deletions
diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
index 56f9234781fa..20f645743ead 100644
--- a/drivers/firmware/memmap.c
+++ b/drivers/firmware/memmap.c
@@ -122,29 +122,53 @@ static int firmware_map_add_entry(u64 start, u64 end,
122 return 0; 122 return 0;
123} 123}
124 124
125/*
126 * Add memmap entry on sysfs
127 */
128static int add_sysfs_fw_map_entry(struct firmware_map_entry *entry)
129{
130 static int map_entries_nr;
131 static struct kset *mmap_kset;
132
133 if (!mmap_kset) {
134 mmap_kset = kset_create_and_add("memmap", NULL, firmware_kobj);
135 if (!mmap_kset)
136 return -ENOMEM;
137 }
138
139 entry->kobj.kset = mmap_kset;
140 if (kobject_add(&entry->kobj, NULL, "%d", map_entries_nr++))
141 kobject_put(&entry->kobj);
142
143 return 0;
144}
145
125/** 146/**
126 * firmware_map_add() - Adds a firmware mapping entry. 147 * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do
148 * memory hotplug.
127 * @start: Start of the memory range. 149 * @start: Start of the memory range.
128 * @end: End of the memory range (inclusive). 150 * @end: End of the memory range (inclusive).
129 * @type: Type of the memory range. 151 * @type: Type of the memory range.
130 * 152 *
131 * This function uses kmalloc() for memory 153 * Adds a firmware mapping entry. This function is for memory hotplug, it is
132 * allocation. Use firmware_map_add_early() if you want to use the bootmem 154 * similar to function firmware_map_add_early(). The only difference is that
133 * allocator. 155 * it will create the syfs entry dynamically.
134 *
135 * That function must be called before late_initcall.
136 * 156 *
137 * Returns 0 on success, or -ENOMEM if no memory could be allocated. 157 * Returns 0 on success, or -ENOMEM if no memory could be allocated.
138 **/ 158 **/
139int firmware_map_add(u64 start, u64 end, const char *type) 159int __meminit firmware_map_add_hotplug(u64 start, u64 end, const char *type)
140{ 160{
141 struct firmware_map_entry *entry; 161 struct firmware_map_entry *entry;
142 162
143 entry = kmalloc(sizeof(struct firmware_map_entry), GFP_ATOMIC); 163 entry = kzalloc(sizeof(struct firmware_map_entry), GFP_ATOMIC);
144 if (!entry) 164 if (!entry)
145 return -ENOMEM; 165 return -ENOMEM;
146 166
147 return firmware_map_add_entry(start, end, type, entry); 167 firmware_map_add_entry(start, end, type, entry);
168 /* create the memmap entry */
169 add_sysfs_fw_map_entry(entry);
170
171 return 0;
148} 172}
149 173
150/** 174/**
@@ -154,7 +178,7 @@ int firmware_map_add(u64 start, u64 end, const char *type)
154 * @type: Type of the memory range. 178 * @type: Type of the memory range.
155 * 179 *
156 * Adds a firmware mapping entry. This function uses the bootmem allocator 180 * Adds a firmware mapping entry. This function uses the bootmem allocator
157 * for memory allocation. Use firmware_map_add() if you want to use kmalloc(). 181 * for memory allocation.
158 * 182 *
159 * That function must be called before late_initcall. 183 * That function must be called before late_initcall.
160 * 184 *
@@ -214,19 +238,10 @@ static ssize_t memmap_attr_show(struct kobject *kobj,
214 */ 238 */
215static int __init memmap_init(void) 239static int __init memmap_init(void)
216{ 240{
217 int i = 0;
218 struct firmware_map_entry *entry; 241 struct firmware_map_entry *entry;
219 struct kset *memmap_kset;
220
221 memmap_kset = kset_create_and_add("memmap", NULL, firmware_kobj);
222 if (WARN_ON(!memmap_kset))
223 return -ENOMEM;
224 242
225 list_for_each_entry(entry, &map_entries, list) { 243 list_for_each_entry(entry, &map_entries, list)
226 entry->kobj.kset = memmap_kset; 244 add_sysfs_fw_map_entry(entry);
227 if (kobject_add(&entry->kobj, NULL, "%d", i++))
228 kobject_put(&entry->kobj);
229 }
230 245
231 return 0; 246 return 0;
232} 247}
diff --git a/include/linux/firmware-map.h b/include/linux/firmware-map.h
index 875451f1373a..c6dcc1dfe781 100644
--- a/include/linux/firmware-map.h
+++ b/include/linux/firmware-map.h
@@ -24,17 +24,17 @@
24 */ 24 */
25#ifdef CONFIG_FIRMWARE_MEMMAP 25#ifdef CONFIG_FIRMWARE_MEMMAP
26 26
27int firmware_map_add(u64 start, u64 end, const char *type);
28int firmware_map_add_early(u64 start, u64 end, const char *type); 27int firmware_map_add_early(u64 start, u64 end, const char *type);
28int firmware_map_add_hotplug(u64 start, u64 end, const char *type);
29 29
30#else /* CONFIG_FIRMWARE_MEMMAP */ 30#else /* CONFIG_FIRMWARE_MEMMAP */
31 31
32static inline int firmware_map_add(u64 start, u64 end, const char *type) 32static inline int firmware_map_add_early(u64 start, u64 end, const char *type)
33{ 33{
34 return 0; 34 return 0;
35} 35}
36 36
37static inline int firmware_map_add_early(u64 start, u64 end, const char *type) 37static inline int firmware_map_add_hotplug(u64 start, u64 end, const char *type)
38{ 38{
39 return 0; 39 return 0;
40} 40}
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 030ce8a5bb0e..78e34e63c7b8 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -28,6 +28,7 @@
28#include <linux/pfn.h> 28#include <linux/pfn.h>
29#include <linux/suspend.h> 29#include <linux/suspend.h>
30#include <linux/mm_inline.h> 30#include <linux/mm_inline.h>
31#include <linux/firmware-map.h>
31 32
32#include <asm/tlbflush.h> 33#include <asm/tlbflush.h>
33 34
@@ -523,6 +524,9 @@ int __ref add_memory(int nid, u64 start, u64 size)
523 BUG_ON(ret); 524 BUG_ON(ret);
524 } 525 }
525 526
527 /* create new memmap entry */
528 firmware_map_add_hotplug(start, start + size, "System RAM");
529
526 goto out; 530 goto out;
527 531
528error: 532error: