summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell King <rmk@arm.linux.org.uk>2012-10-25 11:57:26 +0100
committerRussell King <rmk@arm.linux.org.uk>2012-10-25 12:14:42 +0100
commitc82b518135f55a8fd075b4df20c04b78c2475c53 (patch)
tree253512589f53d45b89324a2d1af597e7396aa98b
parent28ee15c339a4e893e95cac5b8c6fbf2730e0149e (diff)
Add aligned malloc function [new kernel required]
vmeta wants to allocate memory with specific alignments. Rather than having vmeta request more memory of bmm, and then doing alignment on the result, provide a proper API to do this task. This requires an updated kernel.
-rw-r--r--bmm_lib.c14
-rw-r--r--bmm_lib.h1
-rw-r--r--bmm_lib_priv.h1
3 files changed, 13 insertions, 3 deletions
diff --git a/bmm_lib.c b/bmm_lib.c
index ab33cde..4def40b 100644
--- a/bmm_lib.c
+++ b/bmm_lib.c
@@ -51,7 +51,7 @@ void bmm_exit()
bmm_fd = -1;
}
-void *bmm_malloc(unsigned long size, int attr)
+void *bmm_malloc_aligned(unsigned long size, int attr, unsigned align)
{
int ret;
void *vaddr;
@@ -63,6 +63,8 @@ void *bmm_malloc(unsigned long size, int attr)
if(bmm_init() < 0)
return NULL;
+ pr_debug("%s(size=%lu,attr=%x,align=%u)\n", __FUNCTION__, size, attr, align);
+
/* obsolete, only for back-compatible */
if ((attr & BMM_ATTR_NONBUFFERABLE)&&(attr & BMM_ATTR_NONCACHEABLE))
attr = BMM_ATTR_NONCACHED;
@@ -70,10 +72,11 @@ void *bmm_malloc(unsigned long size, int attr)
if ((!(attr & BMM_ATTR_NONBUFFERABLE))&&(attr & BMM_ATTR_NONCACHEABLE))
attr = BMM_ATTR_WRITECOMBINE;
- io.input = size;
+ io.input = align;
+ io.length = size;
io.output = 0;
io.arg = attr;
- ret = ioctl(bmm_fd, BMM_MALLOC, &io);
+ ret = ioctl(bmm_fd, BMM_MALLOC_ALIGNED, &io);
if(ret < 0 || io.output == 0)
return NULL;
@@ -83,6 +86,11 @@ void *bmm_malloc(unsigned long size, int attr)
return ((int)vaddr == -1) ? NULL : vaddr;
}
+void *bmm_malloc(unsigned long size, int attr)
+{
+ return bmm_malloc_aligned(size, attr, sizeof(int));
+}
+
void bmm_free(void *vaddr)
{
unsigned long size;
diff --git a/bmm_lib.h b/bmm_lib.h
index 37dfe67..f8c160b 100644
--- a/bmm_lib.h
+++ b/bmm_lib.h
@@ -41,6 +41,7 @@ extern "C" {
int bmm_init();
void bmm_exit();
void *bmm_malloc(unsigned long size, int attr);
+void *bmm_malloc_aligned(unsigned long size, int attr, unsigned align);
void bmm_free(void *vaddr);
void *bmm_attach(unsigned long paddr, unsigned long len);
void bmm_detach(void *vaddr, unsigned long len);
diff --git a/bmm_lib_priv.h b/bmm_lib_priv.h
index 9b92681..3ae48f2 100644
--- a/bmm_lib_priv.h
+++ b/bmm_lib_priv.h
@@ -40,6 +40,7 @@ typedef struct {
#define BMM_GET_ALLOCATED_SPACE _IOWR(BMEM_IOCTL_MAGIC, 14, ioctl_arg_t)
#define BMM_GET_KERN_PHYS_ADDR _IOWR(BMEM_IOCTL_MAGIC, 15, ioctl_arg_t)
#define BMM_SYNC_USER _IOWR(BMEM_IOCTL_MAGIC, 16, ioctl_arg_t)
+#define BMM_MALLOC_ALIGNED _IOWR(BMEM_IOCTL_MAGIC, 17, ioctl_arg_t)
#define BMM_DEVICE_FILE "/dev/bmm"