Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/firmware/memmap.c |
| 3 | * Copyright (C) 2008 SUSE LINUX Products GmbH |
Bernhard Walle | 97bef7d | 2009-02-18 14:48:40 -0800 | [diff] [blame] | 4 | * by Bernhard Walle <bernhard.walle@gmx.de> |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License v2.0 as published by |
| 8 | * the Free Software Foundation |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/firmware-map.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/bootmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 24 | #include <linux/mm.h> |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * Data types ------------------------------------------------------------------ |
| 28 | */ |
| 29 | |
| 30 | /* |
| 31 | * Firmware map entry. Because firmware memory maps are flat and not |
| 32 | * hierarchical, it's ok to organise them in a linked list. No parent |
| 33 | * information is necessary as for the resource tree. |
| 34 | */ |
| 35 | struct firmware_map_entry { |
Yinghai Lu | 3b0fde0 | 2009-06-16 15:31:16 -0700 | [diff] [blame] | 36 | /* |
| 37 | * start and end must be u64 rather than resource_size_t, because e820 |
| 38 | * resources can lie at addresses above 4G. |
| 39 | */ |
| 40 | u64 start; /* start of the memory range */ |
| 41 | u64 end; /* end of the memory range (incl.) */ |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 42 | const char *type; /* type of the memory range */ |
| 43 | struct list_head list; /* entry for the linked list */ |
| 44 | struct kobject kobj; /* kobject for each entry */ |
| 45 | }; |
| 46 | |
| 47 | /* |
| 48 | * Forward declarations -------------------------------------------------------- |
| 49 | */ |
| 50 | static ssize_t memmap_attr_show(struct kobject *kobj, |
| 51 | struct attribute *attr, char *buf); |
| 52 | static ssize_t start_show(struct firmware_map_entry *entry, char *buf); |
| 53 | static ssize_t end_show(struct firmware_map_entry *entry, char *buf); |
| 54 | static ssize_t type_show(struct firmware_map_entry *entry, char *buf); |
| 55 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 56 | static struct firmware_map_entry * __meminit |
| 57 | firmware_map_find_entry(u64 start, u64 end, const char *type); |
| 58 | |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 59 | /* |
| 60 | * Static data ----------------------------------------------------------------- |
| 61 | */ |
| 62 | |
| 63 | struct memmap_attribute { |
| 64 | struct attribute attr; |
| 65 | ssize_t (*show)(struct firmware_map_entry *entry, char *buf); |
| 66 | }; |
| 67 | |
Roel Kluin | da2bdf9 | 2009-01-07 18:09:15 -0800 | [diff] [blame] | 68 | static struct memmap_attribute memmap_start_attr = __ATTR_RO(start); |
| 69 | static struct memmap_attribute memmap_end_attr = __ATTR_RO(end); |
| 70 | static struct memmap_attribute memmap_type_attr = __ATTR_RO(type); |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * These are default attributes that are added for every memmap entry. |
| 74 | */ |
| 75 | static struct attribute *def_attrs[] = { |
| 76 | &memmap_start_attr.attr, |
| 77 | &memmap_end_attr.attr, |
| 78 | &memmap_type_attr.attr, |
| 79 | NULL |
| 80 | }; |
| 81 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 82 | static const struct sysfs_ops memmap_attr_ops = { |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 83 | .show = memmap_attr_show, |
| 84 | }; |
| 85 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 86 | /* Firmware memory map entries. */ |
| 87 | static LIST_HEAD(map_entries); |
| 88 | static DEFINE_SPINLOCK(map_entries_lock); |
| 89 | |
| 90 | /* |
| 91 | * For memory hotplug, there is no way to free memory map entries allocated |
| 92 | * by boot mem after the system is up. So when we hot-remove memory whose |
| 93 | * map entry is allocated by bootmem, we need to remember the storage and |
| 94 | * reuse it when the memory is hot-added again. |
| 95 | */ |
| 96 | static LIST_HEAD(map_entries_bootmem); |
| 97 | static DEFINE_SPINLOCK(map_entries_bootmem_lock); |
| 98 | |
| 99 | |
| 100 | static inline struct firmware_map_entry * |
| 101 | to_memmap_entry(struct kobject *kobj) |
| 102 | { |
| 103 | return container_of(kobj, struct firmware_map_entry, kobj); |
| 104 | } |
| 105 | |
| 106 | static void __meminit release_firmware_map_entry(struct kobject *kobj) |
| 107 | { |
| 108 | struct firmware_map_entry *entry = to_memmap_entry(kobj); |
| 109 | |
| 110 | if (PageReserved(virt_to_page(entry))) { |
| 111 | /* |
| 112 | * Remember the storage allocated by bootmem, and reuse it when |
| 113 | * the memory is hot-added again. The entry will be added to |
| 114 | * map_entries_bootmem here, and deleted from &map_entries in |
| 115 | * firmware_map_remove_entry(). |
| 116 | */ |
Yasuaki Ishimatsu | 7a6f93b | 2013-04-29 15:08:39 -0700 | [diff] [blame] | 117 | spin_lock(&map_entries_bootmem_lock); |
| 118 | list_add(&entry->list, &map_entries_bootmem); |
| 119 | spin_unlock(&map_entries_bootmem_lock); |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 120 | |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | kfree(entry); |
| 125 | } |
| 126 | |
| 127 | static struct kobj_type __refdata memmap_ktype = { |
| 128 | .release = release_firmware_map_entry, |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 129 | .sysfs_ops = &memmap_attr_ops, |
| 130 | .default_attrs = def_attrs, |
| 131 | }; |
| 132 | |
| 133 | /* |
| 134 | * Registration functions ------------------------------------------------------ |
| 135 | */ |
| 136 | |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 137 | /** |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 138 | * firmware_map_add_entry() - Does the real work to add a firmware memmap entry. |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 139 | * @start: Start of the memory range. |
Yasuaki Ishimatsu | 4ed940d | 2012-07-30 14:41:13 -0700 | [diff] [blame] | 140 | * @end: End of the memory range (exclusive). |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 141 | * @type: Type of the memory range. |
| 142 | * @entry: Pre-allocated (either kmalloc() or bootmem allocator), uninitialised |
| 143 | * entry. |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 144 | * |
| 145 | * Common implementation of firmware_map_add() and firmware_map_add_early() |
| 146 | * which expects a pre-allocated struct firmware_map_entry. |
| 147 | **/ |
Yinghai Lu | 3b0fde0 | 2009-06-16 15:31:16 -0700 | [diff] [blame] | 148 | static int firmware_map_add_entry(u64 start, u64 end, |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 149 | const char *type, |
| 150 | struct firmware_map_entry *entry) |
| 151 | { |
| 152 | BUG_ON(start > end); |
| 153 | |
| 154 | entry->start = start; |
Yasuaki Ishimatsu | 4ed940d | 2012-07-30 14:41:13 -0700 | [diff] [blame] | 155 | entry->end = end - 1; |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 156 | entry->type = type; |
| 157 | INIT_LIST_HEAD(&entry->list); |
| 158 | kobject_init(&entry->kobj, &memmap_ktype); |
| 159 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 160 | spin_lock(&map_entries_lock); |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 161 | list_add_tail(&entry->list, &map_entries); |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 162 | spin_unlock(&map_entries_lock); |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 167 | /** |
| 168 | * firmware_map_remove_entry() - Does the real work to remove a firmware |
| 169 | * memmap entry. |
| 170 | * @entry: removed entry. |
| 171 | * |
| 172 | * The caller must hold map_entries_lock, and release it properly. |
| 173 | **/ |
| 174 | static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) |
| 175 | { |
| 176 | list_del(&entry->list); |
| 177 | } |
| 178 | |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 179 | /* |
| 180 | * Add memmap entry on sysfs |
| 181 | */ |
| 182 | static int add_sysfs_fw_map_entry(struct firmware_map_entry *entry) |
| 183 | { |
| 184 | static int map_entries_nr; |
| 185 | static struct kset *mmap_kset; |
| 186 | |
| 187 | if (!mmap_kset) { |
| 188 | mmap_kset = kset_create_and_add("memmap", NULL, firmware_kobj); |
| 189 | if (!mmap_kset) |
| 190 | return -ENOMEM; |
| 191 | } |
| 192 | |
| 193 | entry->kobj.kset = mmap_kset; |
| 194 | if (kobject_add(&entry->kobj, NULL, "%d", map_entries_nr++)) |
| 195 | kobject_put(&entry->kobj); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 200 | /* |
| 201 | * Remove memmap entry on sysfs |
| 202 | */ |
| 203 | static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) |
| 204 | { |
| 205 | kobject_put(&entry->kobj); |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * firmware_map_find_entry_in_list() - Search memmap entry in a given list. |
| 210 | * @start: Start of the memory range. |
| 211 | * @end: End of the memory range (exclusive). |
| 212 | * @type: Type of the memory range. |
| 213 | * @list: In which to find the entry. |
| 214 | * |
| 215 | * This function is to find the memmap entey of a given memory range in a |
| 216 | * given list. The caller must hold map_entries_lock, and must not release |
| 217 | * the lock until the processing of the returned entry has completed. |
| 218 | * |
| 219 | * Return: Pointer to the entry to be found on success, or NULL on failure. |
| 220 | */ |
| 221 | static struct firmware_map_entry * __meminit |
| 222 | firmware_map_find_entry_in_list(u64 start, u64 end, const char *type, |
| 223 | struct list_head *list) |
| 224 | { |
| 225 | struct firmware_map_entry *entry; |
| 226 | |
| 227 | list_for_each_entry(entry, list, list) |
| 228 | if ((entry->start == start) && (entry->end == end) && |
| 229 | (!strcmp(entry->type, type))) { |
| 230 | return entry; |
| 231 | } |
| 232 | |
| 233 | return NULL; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * firmware_map_find_entry() - Search memmap entry in map_entries. |
| 238 | * @start: Start of the memory range. |
| 239 | * @end: End of the memory range (exclusive). |
| 240 | * @type: Type of the memory range. |
| 241 | * |
| 242 | * This function is to find the memmap entey of a given memory range. |
| 243 | * The caller must hold map_entries_lock, and must not release the lock |
| 244 | * until the processing of the returned entry has completed. |
| 245 | * |
| 246 | * Return: Pointer to the entry to be found on success, or NULL on failure. |
| 247 | */ |
| 248 | static struct firmware_map_entry * __meminit |
| 249 | firmware_map_find_entry(u64 start, u64 end, const char *type) |
| 250 | { |
| 251 | return firmware_map_find_entry_in_list(start, end, type, &map_entries); |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * firmware_map_find_entry_bootmem() - Search memmap entry in map_entries_bootmem. |
| 256 | * @start: Start of the memory range. |
| 257 | * @end: End of the memory range (exclusive). |
| 258 | * @type: Type of the memory range. |
| 259 | * |
| 260 | * This function is similar to firmware_map_find_entry except that it find the |
| 261 | * given entry in map_entries_bootmem. |
| 262 | * |
| 263 | * Return: Pointer to the entry to be found on success, or NULL on failure. |
| 264 | */ |
| 265 | static struct firmware_map_entry * __meminit |
| 266 | firmware_map_find_entry_bootmem(u64 start, u64 end, const char *type) |
| 267 | { |
| 268 | return firmware_map_find_entry_in_list(start, end, type, |
| 269 | &map_entries_bootmem); |
| 270 | } |
| 271 | |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 272 | /** |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 273 | * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do |
| 274 | * memory hotplug. |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 275 | * @start: Start of the memory range. |
Yasuaki Ishimatsu | 4ed940d | 2012-07-30 14:41:13 -0700 | [diff] [blame] | 276 | * @end: End of the memory range (exclusive) |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 277 | * @type: Type of the memory range. |
| 278 | * |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 279 | * Adds a firmware mapping entry. This function is for memory hotplug, it is |
| 280 | * similar to function firmware_map_add_early(). The only difference is that |
| 281 | * it will create the syfs entry dynamically. |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 282 | * |
| 283 | * Returns 0 on success, or -ENOMEM if no memory could be allocated. |
| 284 | **/ |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 285 | int __meminit firmware_map_add_hotplug(u64 start, u64 end, const char *type) |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 286 | { |
| 287 | struct firmware_map_entry *entry; |
| 288 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 289 | entry = firmware_map_find_entry_bootmem(start, end, type); |
| 290 | if (!entry) { |
| 291 | entry = kzalloc(sizeof(struct firmware_map_entry), GFP_ATOMIC); |
| 292 | if (!entry) |
| 293 | return -ENOMEM; |
| 294 | } else { |
| 295 | /* Reuse storage allocated by bootmem. */ |
| 296 | spin_lock(&map_entries_bootmem_lock); |
| 297 | list_del(&entry->list); |
| 298 | spin_unlock(&map_entries_bootmem_lock); |
| 299 | |
| 300 | memset(entry, 0, sizeof(*entry)); |
| 301 | } |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 302 | |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 303 | firmware_map_add_entry(start, end, type, entry); |
| 304 | /* create the memmap entry */ |
| 305 | add_sysfs_fw_map_entry(entry); |
| 306 | |
| 307 | return 0; |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 310 | /** |
| 311 | * firmware_map_add_early() - Adds a firmware mapping entry. |
| 312 | * @start: Start of the memory range. |
Yasuaki Ishimatsu | 4ed940d | 2012-07-30 14:41:13 -0700 | [diff] [blame] | 313 | * @end: End of the memory range. |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 314 | * @type: Type of the memory range. |
| 315 | * |
| 316 | * Adds a firmware mapping entry. This function uses the bootmem allocator |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 317 | * for memory allocation. |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 318 | * |
| 319 | * That function must be called before late_initcall. |
| 320 | * |
| 321 | * Returns 0 on success, or -ENOMEM if no memory could be allocated. |
| 322 | **/ |
Yinghai Lu | 3b0fde0 | 2009-06-16 15:31:16 -0700 | [diff] [blame] | 323 | int __init firmware_map_add_early(u64 start, u64 end, const char *type) |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 324 | { |
| 325 | struct firmware_map_entry *entry; |
| 326 | |
Santosh Shilimkar | 4fc0bc5 | 2014-01-21 15:50:45 -0800 | [diff] [blame] | 327 | entry = memblock_virt_alloc(sizeof(struct firmware_map_entry), 0); |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 328 | if (WARN_ON(!entry)) |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 329 | return -ENOMEM; |
| 330 | |
| 331 | return firmware_map_add_entry(start, end, type, entry); |
| 332 | } |
| 333 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 334 | /** |
| 335 | * firmware_map_remove() - remove a firmware mapping entry |
| 336 | * @start: Start of the memory range. |
| 337 | * @end: End of the memory range. |
| 338 | * @type: Type of the memory range. |
| 339 | * |
| 340 | * removes a firmware mapping entry. |
| 341 | * |
| 342 | * Returns 0 on success, or -EINVAL if no entry. |
| 343 | **/ |
| 344 | int __meminit firmware_map_remove(u64 start, u64 end, const char *type) |
| 345 | { |
| 346 | struct firmware_map_entry *entry; |
| 347 | |
| 348 | spin_lock(&map_entries_lock); |
| 349 | entry = firmware_map_find_entry(start, end - 1, type); |
| 350 | if (!entry) { |
| 351 | spin_unlock(&map_entries_lock); |
| 352 | return -EINVAL; |
| 353 | } |
| 354 | |
| 355 | firmware_map_remove_entry(entry); |
| 356 | spin_unlock(&map_entries_lock); |
| 357 | |
| 358 | /* remove the memmap entry */ |
| 359 | remove_sysfs_fw_map_entry(entry); |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 364 | /* |
| 365 | * Sysfs functions ------------------------------------------------------------- |
| 366 | */ |
| 367 | |
| 368 | static ssize_t start_show(struct firmware_map_entry *entry, char *buf) |
| 369 | { |
Randy Dunlap | 78681ac | 2008-07-26 15:22:28 -0700 | [diff] [blame] | 370 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", |
| 371 | (unsigned long long)entry->start); |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static ssize_t end_show(struct firmware_map_entry *entry, char *buf) |
| 375 | { |
Randy Dunlap | 78681ac | 2008-07-26 15:22:28 -0700 | [diff] [blame] | 376 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", |
| 377 | (unsigned long long)entry->end); |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static ssize_t type_show(struct firmware_map_entry *entry, char *buf) |
| 381 | { |
| 382 | return snprintf(buf, PAGE_SIZE, "%s\n", entry->type); |
| 383 | } |
| 384 | |
Yasuaki Ishimatsu | 46c66c4 | 2013-02-22 16:32:56 -0800 | [diff] [blame] | 385 | static inline struct memmap_attribute *to_memmap_attr(struct attribute *attr) |
| 386 | { |
| 387 | return container_of(attr, struct memmap_attribute, attr); |
| 388 | } |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 389 | |
| 390 | static ssize_t memmap_attr_show(struct kobject *kobj, |
| 391 | struct attribute *attr, char *buf) |
| 392 | { |
| 393 | struct firmware_map_entry *entry = to_memmap_entry(kobj); |
| 394 | struct memmap_attribute *memmap_attr = to_memmap_attr(attr); |
| 395 | |
| 396 | return memmap_attr->show(entry, buf); |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * Initialises stuff and adds the entries in the map_entries list to |
| 401 | * sysfs. Important is that firmware_map_add() and firmware_map_add_early() |
Bernhard Walle | 31bad92 | 2008-08-12 15:09:14 -0700 | [diff] [blame] | 402 | * must be called before late_initcall. That's just because that function |
| 403 | * is called as late_initcall() function, which means that if you call |
| 404 | * firmware_map_add() or firmware_map_add_early() afterwards, the entries |
| 405 | * are not added to sysfs. |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 406 | */ |
Fengguang Wu | bac7169 | 2012-10-19 13:56:55 -0700 | [diff] [blame] | 407 | static int __init firmware_memmap_init(void) |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 408 | { |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 409 | struct firmware_map_entry *entry; |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 410 | |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 411 | list_for_each_entry(entry, &map_entries, list) |
| 412 | add_sysfs_fw_map_entry(entry); |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 413 | |
| 414 | return 0; |
| 415 | } |
Fengguang Wu | bac7169 | 2012-10-19 13:56:55 -0700 | [diff] [blame] | 416 | late_initcall(firmware_memmap_init); |
Bernhard Walle | 69ac9cd | 2008-06-27 13:12:54 +0200 | [diff] [blame] | 417 | |