summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell King <rmk+cubox@arm.linux.org.uk>2013-12-05 18:44:51 +0000
committerRussell King <rmk@arm.linux.org.uk>2013-12-05 18:44:51 +0000
commit6def9c19ccdfb0cb2c22a5f1dcfb3bb1aba60c99 (patch)
tree7c35ef927565e61d0c682108d43f151373cb91ad
parent6c486964005d3968aee0897ce0e67ea53f8fcb4d (diff)
Fix bmm_attach() followed by bmm_get_paddr()
Attaching to a buffer with an offset, and then subsequently asking for it's physical address returned the non-offset buffer. Fix this by tracking the physical offset.
-rw-r--r--bmm_lib.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/bmm_lib.c b/bmm_lib.c
index 86f16cd..72f5301 100644
--- a/bmm_lib.c
+++ b/bmm_lib.c
@@ -61,6 +61,7 @@ struct bmm_phys_buffer {
struct bmm_virt_buffer {
void *vaddr;
size_t size;
+ unsigned phys_offset;
struct bmm_phys_buffer *phys;
};
@@ -312,6 +313,7 @@ void *bmm_malloc_aligned_phys(unsigned long size, int attr, unsigned align,
vbuf->vaddr = vaddr;
vbuf->size = size;
+ vbuf->phys_offset = 0;
vbuf->phys = pbuf;
pthread_mutex_lock(&bmm_mutex);
@@ -463,6 +465,7 @@ void *bmm_attach(unsigned long paddr, unsigned long len)
if (!pbuf->virt)
pbuf->virt = vbuf;
+ vbuf->phys_offset = paddr - pbuf->paddr;
vbuf->phys = pbuf;
bmm_rb_virt_insert(vbuf);
@@ -538,7 +541,8 @@ unsigned long bmm_get_paddr(void *vaddr)
pthread_mutex_lock(&bmm_mutex);
vbuf = bmm_buf_find_virt(vaddr);
if (vbuf)
- pa = vbuf->phys->paddr + (vaddr - vbuf->vaddr);
+ pa = vbuf->phys->paddr + vbuf->phys_offset +
+ (vaddr - vbuf->vaddr);
pthread_mutex_unlock(&bmm_mutex);
return pa;