Skip to contentSkip to conversation

NOMMU: Work around the lack of vmap()/vunmap() in firmware_loading_store() [ver #2]

PATCH In review David Howells 2 participants 3 messages Apr 8, 2010 – Mar 24, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NOMMU: Work around the lack of vmap()/vunmap() in firmware_loading_store() [ver #2]

Work around the lack of vmap()/vunmap() in firmware_loading_store() when operating in NOMMU mode. vmap() cannot be implemented as there's no virtual mapping available.

Instead, in NOMMU mode, make available a function (vcoalesce()) that can coalesce the supplied data into one big buffer and store as the address vmap() would've returned.

This can be #defined to vmap() in NOMMU mode by interested parties.

---

 drivers/base/firmware_class.c |    8 ++++++++
 include/linux/vmalloc.h       |    1 +
 mm/nommu.c                    |   24 ++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 0 deletions(-)
drivers/base/firmware_class.c +8 -0
index 985da11..be71e54 100644
@@ -60,6 +60,14 @@ static struct builtin_fw *__start_builtin_fw;
 static struct builtin_fw *__end_builtin_fw;
 #endif
 
+/*
+ * NOMMU mode can't provide vmap() as there's no MMU to do the virtual mapping.
+ * Coalesce the data into a big buffer instead.
+ */
+#ifndef CONFIG_MMU
+#define vmap(pg, c, f, pr)	vcoalesce(pg, c, f, pr)
+#endif
+
 static void
 fw_load_abort(struct firmware_priv *fw_priv)
 {
include/linux/vmalloc.h +1 -0
index 227c2a5..f36a4b2 100644
@@ -48,6 +48,7 @@ extern void __init vmalloc_init(void);
 static inline void vmalloc_init(void)
 {
 }
+extern void *vcoalesce(struct page **, unsigned int, unsigned long, pgprot_t);
 #endif
 
 extern void *vmalloc(unsigned long size);
mm/nommu.c +24 -0
index 63fa17d..05a5c63 100644
@@ -405,6 +405,30 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
 EXPORT_SYMBOL(vm_insert_page);
 
 /*
+ * NOMMU mode can't provide vmap() as there's no MMU to do the virtual mapping.
+ * Provide a facility to coalesce the data into a big buffer instead.
+ */
+void *vcoalesce(struct page **pages, unsigned int count,
+		unsigned long flags, pgprot_t prot)
+{
+	unsigned int i;
+	void *new_map, *page_data;
+
+	new_map = kmalloc(count << PAGE_SHIFT, GFP_KERNEL);
+	if (!new_map)
+		return NULL;
+
+	for (i = 0; i < count; ++i) {
+		page_data = kmap(pages[i]);
+		memcpy(new_map + (i << PAGE_SHIFT), page_data, PAGE_SIZE);
+		kunmap(page_data);
+	}
+
+	return new_map;
+}
+EXPORT_SYMBOL(vcoalesce);
+
+/*
  *  sys_brk() for the most part doesn't need the global kernel
  *  lock, except when an application is doing something nasty
  *  like trying to un-brk an area that has already been mapped
#1 lore raw
Quoted 9 lines · David Howells

Work around the lack of vmap()/vunmap() in firmware_loading_store() when operating in NOMMU mode.  vmap() cannot be implemented as there's no virtual mapping available.

Instead, in NOMMU mode, make available a function (vcoalesce()) that can coalesce the supplied data into one big buffer and store as the address vmap() would've returned.

This can be #defined to vmap() in NOMMU mode by interested parties.

these things work for us ... were you going to push them up to mainline ? -mike

#2 lore raw
In reply to David Howells
Quoted 9 lines · David Howells

Work around the lack of vmap()/vunmap() in firmware_loading_store() when operating in NOMMU mode.  vmap() cannot be implemented as there's no virtual mapping available.

Instead, in NOMMU mode, make available a function (vcoalesce()) that can coalesce the supplied data into one big buffer and store as the address vmap() would've returned.

This can be #defined to vmap() in NOMMU mode by interested parties.

seems this patch missed updating vunmap():

void vunmap(const void *addr)
{
BUG();
}

that BUG() just needs to be changed to a kfree(addr) ... -mike