From 2f9be2b33130e780a72826598c5bb0a927bc867f Mon Sep 17 00:00:00 2001 From: Russell King Date: Sun, 23 Jun 2013 09:19:22 +0100 Subject: Add bmm_malloc_aligned_phys() API Vmeta really wants the physical and virtual address of the buffer. Adjust the BMM API to give that to it. --- bmm_lib.c | 18 ++++++++++++++---- bmm_lib.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bmm_lib.c b/bmm_lib.c index 64a11e7..6e6f5b5 100644 --- a/bmm_lib.c +++ b/bmm_lib.c @@ -213,7 +213,8 @@ void bmm_exit() bmm_fd = -1; } -void *bmm_malloc_aligned(unsigned long size, int attr, unsigned align) +void *bmm_malloc_aligned_phys(unsigned long size, int attr, unsigned align, + unsigned long *paddr) { struct bmm_buffer *buf; int ret; @@ -230,7 +231,8 @@ void *bmm_malloc_aligned(unsigned long size, int attr, unsigned align) if (!buf) return NULL; - pr_debug("%s(size=%lu,attr=%x,align=%u)\n", __FUNCTION__, size, attr, align); + pr_debug("%s(size=%lu,attr=%x,align=%u,paddr=%p)\n", + __FUNCTION__, size, attr, align, paddr); /* obsolete, only for back-compatible */ if ((attr & BMM_ATTR_NONBUFFERABLE)&&(attr & BMM_ATTR_NONCACHEABLE)) @@ -247,12 +249,15 @@ void *bmm_malloc_aligned(unsigned long size, int attr, unsigned align) if (ret < 0 || io.output == 0) goto err_free_buf; - pr_debug("bmm_malloc return paddr = 0x%08lx\n", io.output); + pr_debug("%s return paddr = 0x%08lx\n", __FUNCTION__, io.output); vaddr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, bmm_fd, io.output); if ((int)vaddr == -1) goto err_free_bmm; + if (paddr) + *paddr = io.output; + buf->vaddr = vaddr; buf->paddr = io.output; buf->size = size; @@ -278,9 +283,14 @@ void *bmm_malloc_aligned(unsigned long size, int attr, unsigned align) return NULL; } +void *bmm_malloc_aligned(unsigned long size, int attr, unsigned align) +{ + return bmm_malloc_aligned_phys(size, attr, align, NULL); +} + void *bmm_malloc(unsigned long size, int attr) { - return bmm_malloc_aligned(size, attr, sizeof(int)); + return bmm_malloc_aligned_phys(size, attr, sizeof(int), NULL); } void bmm_free(void *vaddr) diff --git a/bmm_lib.h b/bmm_lib.h index 1c4bbec..56d9d50 100644 --- a/bmm_lib.h +++ b/bmm_lib.h @@ -42,6 +42,8 @@ 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_malloc_aligned_phys(unsigned long size, int attr, unsigned align, + unsigned long *paddr); void bmm_free(void *vaddr); void *bmm_attach(unsigned long paddr, unsigned long len); void bmm_detach(void *vaddr, unsigned long len); -- cgit