Skip to content
This repository was archived by the owner on Nov 21, 2022. It is now read-only.

Commit d96ae53

Browse files
akpm00torvalds
authored andcommitted
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>
1 parent 9d8cebd commit d96ae53

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

drivers/firmware/memmap.c

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,29 +122,53 @@ static int firmware_map_add_entry(u64 start, u64 end,
122122
return 0;
123123
}
124124

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+
125146
/**
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.
127149
* @start: Start of the memory range.
128150
* @end: End of the memory range (inclusive).
129151
* @type: Type of the memory range.
130152
*
131-
* This function uses kmalloc() for memory
132-
* allocation. Use firmware_map_add_early() if you want to use the bootmem
133-
* allocator.
134-
*
135-
* That function must be called before late_initcall.
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.
136156
*
137157
* Returns 0 on success, or -ENOMEM if no memory could be allocated.
138158
**/
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)
140160
{
141161
struct firmware_map_entry *entry;
142162

143-
entry = kmalloc(sizeof(struct firmware_map_entry), GFP_ATOMIC);
163+
entry = kzalloc(sizeof(struct firmware_map_entry), GFP_ATOMIC);
144164
if (!entry)
145165
return -ENOMEM;
146166

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;
148172
}
149173

150174
/**
@@ -154,7 +178,7 @@ int firmware_map_add(u64 start, u64 end, const char *type)
154178
* @type: Type of the memory range.
155179
*
156180
* 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.
158182
*
159183
* That function must be called before late_initcall.
160184
*
@@ -214,19 +238,10 @@ static ssize_t memmap_attr_show(struct kobject *kobj,
214238
*/
215239
static int __init memmap_init(void)
216240
{
217-
int i = 0;
218241
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;
224242

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);
230245

231246
return 0;
232247
}

include/linux/firmware-map.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
*/
2525
#ifdef CONFIG_FIRMWARE_MEMMAP
2626

27-
int firmware_map_add(u64 start, u64 end, const char *type);
2827
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);
2929

3030
#else /* CONFIG_FIRMWARE_MEMMAP */
3131

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)
3333
{
3434
return 0;
3535
}
3636

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)
3838
{
3939
return 0;
4040
}

mm/memory_hotplug.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/pfn.h>
2929
#include <linux/suspend.h>
3030
#include <linux/mm_inline.h>
31+
#include <linux/firmware-map.h>
3132

3233
#include <asm/tlbflush.h>
3334

@@ -523,6 +524,9 @@ int __ref add_memory(int nid, u64 start, u64 size)
523524
BUG_ON(ret);
524525
}
525526

527+
/* create new memmap entry */
528+
firmware_map_add_hotplug(start, start + size, "System RAM");
529+
526530
goto out;
527531

528532
error:

0 commit comments

Comments
 (0)