From c82b518135f55a8fd075b4df20c04b78c2475c53 Mon Sep 17 00:00:00 2001 From: Russell King Date: Thu, 25 Oct 2012 11:57:26 +0100 Subject: 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. --- bmm_lib.c | 14 +++++++++++--- bmm_lib.h | 1 + bmm_lib_priv.h | 1 + 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" -- cgit