aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/memmap.c
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /drivers/firmware/memmap.c
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/firmware/memmap.c')
-rw-r--r--drivers/firmware/memmap.c60
1 files changed, 38 insertions, 22 deletions
diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
index 56f9234781fa..adc07102a20d 100644
--- a/drivers/firmware/memmap.c
+++ b/drivers/firmware/memmap.c
@@ -20,6 +20,7 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/types.h> 21#include <linux/types.h>
22#include <linux/bootmem.h> 22#include <linux/bootmem.h>
23#include <linux/slab.h>
23 24
24/* 25/*
25 * Data types ------------------------------------------------------------------ 26 * Data types ------------------------------------------------------------------
@@ -74,7 +75,7 @@ static struct attribute *def_attrs[] = {
74 NULL 75 NULL
75}; 76};
76 77
77static struct sysfs_ops memmap_attr_ops = { 78static const struct sysfs_ops memmap_attr_ops = {
78 .show = memmap_attr_show, 79 .show = memmap_attr_show,
79}; 80};
80 81
@@ -122,29 +123,53 @@ static int firmware_map_add_entry(u64 start, u64 end,
122 return 0; 123 return 0;
123} 124}
124 125
126/*
127 * Add memmap entry on sysfs
128 */
129static int add_sysfs_fw_map_entry(struct firmware_map_entry *entry)
130{
131 static int map_entries_nr;
132 static struct kset *mmap_kset;
133
134 if (!mmap_kset) {
135 mmap_kset = kset_create_and_add("memmap", NULL, firmware_kobj);
136 if (!mmap_kset)
137 return -ENOMEM;
138 }
139
140 entry->kobj.kset = mmap_kset;
141 if (kobject_add(&entry->kobj, NULL, "%d", map_entries_nr++))
142 kobject_put(&entry->kobj);
143
144 return 0;
145}
146
125/** 147/**
126 * firmware_map_add() - Adds a firmware mapping entry. 148 * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do
149 * memory hotplug.
127 * @start: Start of the memory range. 150 * @start: Start of the memory range.
128 * @end: End of the memory range (inclusive). 151 * @end: End of the memory range (inclusive).
129 * @type: Type of the memory range. 152 * @type: Type of the memory range.
130 * 153 *
131 * This function uses kmalloc() for memory 154 * 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 155 * similar to function firmware_map_add_early(). The only difference is that
133 * allocator. 156 * it will create the syfs entry dynamically.
134 *
135 * That function must be called before late_initcall.
136 * 157 *
137 * Returns 0 on success, or -ENOMEM if no memory could be allocated. 158 * Returns 0 on success, or -ENOMEM if no memory could be allocated.
138 **/ 159 **/
139int firmware_map_add(u64 start, u64 end, const char *type) 160int __meminit firmware_map_add_hotplug(u64 start, u64 end, const char *type)
140{ 161{
141 struct firmware_map_entry *entry; 162 struct firmware_map_entry *entry;
142 163
143 entry = kmalloc(sizeof(struct firmware_map_entry), GFP_ATOMIC); 164 entry = kzalloc(sizeof(struct firmware_map_entry), GFP_ATOMIC);
144 if (!entry) 165 if (!entry)
145 return -ENOMEM; 166 return -ENOMEM;
146 167
147 return firmware_map_add_entry(start, end, type, entry); 168 firmware_map_add_entry(start, end, type, entry);
169 /* create the memmap entry */
170 add_sysfs_fw_map_entry(entry);
171
172 return 0;
148} 173}
149 174
150/** 175/**
@@ -154,7 +179,7 @@ int firmware_map_add(u64 start, u64 end, const char *type)
154 * @type: Type of the memory range. 179 * @type: Type of the memory range.
155 * 180 *
156 * Adds a firmware mapping entry. This function uses the bootmem allocator 181 * 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(). 182 * for memory allocation.
158 * 183 *
159 * That function must be called before late_initcall. 184 * That function must be called before late_initcall.
160 * 185 *
@@ -214,19 +239,10 @@ static ssize_t memmap_attr_show(struct kobject *kobj,
214 */ 239 */
215static int __init memmap_init(void) 240static int __init memmap_init(void)
216{ 241{
217 int i = 0;
218 struct firmware_map_entry *entry; 242 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 243
225 list_for_each_entry(entry, &map_entries, list) { 244 list_for_each_entry(entry, &map_entries, list)
226 entry->kobj.kset = memmap_kset; 245 add_sysfs_fw_map_entry(entry);
227 if (kobject_add(&entry->kobj, NULL, "%d", i++))
228 kobject_put(&entry->kobj);
229 }
230 246
231 return 0; 247 return 0;
232} 248}