aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/memmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/firmware/memmap.c')
-rw-r--r--drivers/firmware/memmap.c57
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 */
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}