diff options
author | akpm@linux-foundation.org <akpm@linux-foundation.org> | 2010-03-05 16:41:58 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-03-06 14:26:25 -0500 |
commit | d96ae5309165d9ed7c008a178238977b73595cd9 (patch) | |
tree | 78b169102b718a9489fcc41ad4829a646492d2fb /drivers/firmware | |
parent | 9d8cebd4bcd7c3878462fdfda34bbcdeb4df7ef4 (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>
Diffstat (limited to 'drivers/firmware')
-rw-r--r-- | drivers/firmware/memmap.c | 57 |
1 files changed, 36 insertions, 21 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 | */ | ||
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 | * @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 | **/ |
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 | 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 | */ |
215 | static int __init memmap_init(void) | 239 | static 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 | } |