Commit d96ae5309165d9ed7c008a178238977b73595cd9

Authored by akpm@linux-foundation.org
Committed by Linus Torvalds
1 parent 9d8cebd4bc

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>

Showing 3 changed files with 43 additions and 24 deletions Side-by-side Diff

drivers/firmware/memmap.c
... ... @@ -122,29 +122,53 @@
122 122 return 0;
123 123 }
124 124  
  125 +/*
  126 + * Add memmap entry on sysfs
  127 + */
  128 +static 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 149 * @start: Start of the memory range.
128 150 * @end: End of the memory range (inclusive).
129 151 * @type: Type of the memory range.
130 152 *
131   - * This function uses kmalloc() for memory
132   - * allocation. Use firmware_map_add_early() if you want to use the bootmem
133   - * allocator.
  153 + * Adds a firmware mapping entry. This function is for memory hotplug, it is
  154 + * similar to function firmware_map_add_early(). The only difference is that
  155 + * it will create the syfs entry dynamically.
134 156 *
135   - * That function must be called before late_initcall.
136   - *
137 157 * Returns 0 on success, or -ENOMEM if no memory could be allocated.
138 158 **/
139   -int firmware_map_add(u64 start, u64 end, const char *type)
  159 +int __meminit firmware_map_add_hotplug(u64 start, u64 end, const char *type)
140 160 {
141 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 164 if (!entry)
145 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 @@
154 178 * @type: Type of the memory range.
155 179 *
156 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 183 * That function must be called before late_initcall.
160 184 *
161 185  
162 186  
... ... @@ -214,19 +238,10 @@
214 238 */
215 239 static int __init memmap_init(void)
216 240 {
217   - int i = 0;
218 241 struct firmware_map_entry *entry;
219   - struct kset *memmap_kset;
220 242  
221   - memmap_kset = kset_create_and_add("memmap", NULL, firmware_kobj);
222   - if (WARN_ON(!memmap_kset))
223   - return -ENOMEM;
224   -
225   - list_for_each_entry(entry, &map_entries, list) {
226   - entry->kobj.kset = memmap_kset;
227   - if (kobject_add(&entry->kobj, NULL, "%d", i++))
228   - kobject_put(&entry->kobj);
229   - }
  243 + list_for_each_entry(entry, &map_entries, list)
  244 + add_sysfs_fw_map_entry(entry);
230 245  
231 246 return 0;
232 247 }
include/linux/firmware-map.h
... ... @@ -24,17 +24,17 @@
24 24 */
25 25 #ifdef CONFIG_FIRMWARE_MEMMAP
26 26  
27   -int firmware_map_add(u64 start, u64 end, const char *type);
28 27 int firmware_map_add_early(u64 start, u64 end, const char *type);
  28 +int firmware_map_add_hotplug(u64 start, u64 end, const char *type);
29 29  
30 30 #else /* CONFIG_FIRMWARE_MEMMAP */
31 31  
32   -static inline int firmware_map_add(u64 start, u64 end, const char *type)
  32 +static inline int firmware_map_add_early(u64 start, u64 end, const char *type)
33 33 {
34 34 return 0;
35 35 }
36 36  
37   -static inline int firmware_map_add_early(u64 start, u64 end, const char *type)
  37 +static inline int firmware_map_add_hotplug(u64 start, u64 end, const char *type)
38 38 {
39 39 return 0;
40 40 }
... ... @@ -28,6 +28,7 @@
28 28 #include <linux/pfn.h>
29 29 #include <linux/suspend.h>
30 30 #include <linux/mm_inline.h>
  31 +#include <linux/firmware-map.h>
31 32  
32 33 #include <asm/tlbflush.h>
33 34  
... ... @@ -522,6 +523,9 @@
522 523 */
523 524 BUG_ON(ret);
524 525 }
  526 +
  527 + /* create new memmap entry */
  528 + firmware_map_add_hotplug(start, start + size, "System RAM");
525 529  
526 530 goto out;
527 531