dma-buf: rk_heaps: update /sys/kernel/debug/rk_dma_heap/dma_heap_info

List total buffer size on the last line
List each buffer size

Change-Id: I5ca932cf77d3fb041c90df38b1cd19f68665f3f3
Signed-off-by: Simon Xue <xxm@rock-chips.com>
This commit is contained in:
Simon Xue
2022-03-13 18:26:27 +08:00
committed by Tao Huang
parent def4274701
commit 0e671b294c
3 changed files with 60 additions and 8 deletions

View File

@@ -353,6 +353,7 @@ static void rk_cma_heap_dma_buf_release(struct dma_buf *dmabuf)
{
struct rk_cma_heap_buffer *buffer = dmabuf->priv;
struct rk_cma_heap *cma_heap = buffer->heap;
struct rk_dma_heap *heap = cma_heap->heap;
if (buffer->vmap_cnt > 0) {
WARN(1, "%s: buffer still mapped in the kernel\n", __func__);
@@ -365,6 +366,8 @@ static void rk_cma_heap_dma_buf_release(struct dma_buf *dmabuf)
kfree(buffer->pages);
/* release memory */
cma_release(cma_heap->cma, buffer->cma_pages, buffer->pagecount);
rk_dma_heap_total_dec(heap, buffer->len);
kfree(buffer);
}
@@ -471,6 +474,8 @@ static struct dma_buf *rk_cma_heap_allocate(struct rk_dma_heap *heap,
if (ret)
goto fail_dma_buf;
rk_dma_heap_total_inc(heap, buffer->len);
return dmabuf;
fail_dma_buf:
@@ -508,6 +513,8 @@ static struct page *rk_cma_heap_allocate_pages(struct rk_dma_heap *heap,
return ERR_PTR(-EINVAL);
}
rk_dma_heap_total_inc(heap, size);
return page;
}
@@ -521,6 +528,8 @@ static void rk_cma_heap_free_pages(struct rk_dma_heap *heap,
rk_cma_heap_remove_contig_list(heap, page, name);
cma_release(cma_heap->cma, page, pagecount);
rk_dma_heap_total_dec(heap, len);
}
static const struct rk_dma_heap_ops rk_cma_heap_ops = {

View File

@@ -241,6 +241,25 @@ void rk_dma_heap_free_contig_pages(struct rk_dma_heap *heap,
}
EXPORT_SYMBOL_GPL(rk_dma_heap_free_contig_pages);
void rk_dma_heap_total_inc(struct rk_dma_heap *heap, size_t len)
{
mutex_lock(&rk_heap_list_lock);
heap->total_size += len;
mutex_unlock(&rk_heap_list_lock);
}
EXPORT_SYMBOL_GPL(rk_dma_heap_total_inc);
void rk_dma_heap_total_dec(struct rk_dma_heap *heap, size_t len)
{
mutex_lock(&rk_heap_list_lock);
if (WARN_ON(heap->total_size < len))
heap->total_size = 0;
else
heap->total_size -= len;
mutex_unlock(&rk_heap_list_lock);
}
EXPORT_SYMBOL_GPL(rk_dma_heap_total_dec);
static int rk_dma_heap_open(struct inode *inode, struct file *file)
{
struct rk_dma_heap *heap;
@@ -516,6 +535,7 @@ static int rk_dma_heap_dump_dmabuf(const struct dma_buf *dmabuf, void *data)
struct rk_dma_heap *heap = (struct rk_dma_heap *)data;
struct rk_dma_heap_dmabuf *buf;
struct dma_buf_attachment *a;
phys_addr_t size;
int attach_count;
int ret;
@@ -528,10 +548,11 @@ static int rk_dma_heap_dump_dmabuf(const struct dma_buf *dmabuf, void *data)
seq_printf(heap->s,
"\ti_ino = %ld\n",
dmabuf->file->f_inode->i_ino);
size = buf->end - buf->start + 1;
seq_printf(heap->s,
"\tAlloc by (%s)\t[%pa-%pa]\n",
"\tAlloc by (%s)\t[%pa-%pa]\t%pa\n",
buf->orig_alloc, &buf->start,
&buf->end);
&buf->end, &size);
seq_puts(heap->s, "\t\tAttached Devices:\n");
attach_count = 0;
ret = dma_resv_lock_interruptible(dmabuf->resv,
@@ -563,12 +584,14 @@ static int rk_dma_heap_dump_contig(void *data)
{
struct rk_dma_heap *heap = (struct rk_dma_heap *)data;
struct rk_dma_heap_contig_buf *buf;
phys_addr_t size;
mutex_lock(&heap->contig_lock);
list_for_each_entry(buf, &heap->contig_list, node) {
size = buf->end - buf->start + 1;
seq_printf(heap->s, "dma-heap:<%s> -non dmabuf\n", heap->name);
seq_printf(heap->s, "\tAlloc by (%s)\t[%pa-%pa]\n",
buf->orig_alloc, &buf->start, &buf->end);
seq_printf(heap->s, "\tAlloc by (%s)\t[%pa-%pa]\t%pa\n",
buf->orig_alloc, &buf->start, &buf->end, &size);
}
mutex_unlock(&heap->contig_lock);
@@ -633,16 +656,16 @@ static struct dentry *rk_dma_heap_debugfs_dir;
static int rk_dma_heap_debug_show(struct seq_file *s, void *unused)
{
struct rk_dma_heap *heap;
unsigned long total = 0;
mutex_lock(&rk_heap_list_lock);
list_for_each_entry(heap, &rk_heap_list, list) {
heap->s = s;
get_each_dmabuf(rk_dma_heap_dump_dmabuf, heap);
}
list_for_each_entry(heap, &rk_heap_list, list) {
heap->s = s;
rk_dma_heap_dump_contig(heap);
total += heap->total_size;
}
seq_printf(s, "\nTotal : 0x%lx\n", total);
mutex_unlock(&rk_heap_list_lock);
return 0;

View File

@@ -111,6 +111,7 @@ struct rk_dma_heap {
struct device *heap_dev;
bool support_cma;
struct seq_file *s;
unsigned long total_size;
};
struct rk_dma_heap_dmabuf {
@@ -246,7 +247,18 @@ void rk_dma_heap_free_contig_pages(struct rk_dma_heap *heap,
*/
void *rk_vmap_contig_pfn(unsigned long pfn, unsigned int count,
pgprot_t prot);
/**
* rk_dma_heap_total_inc - Increase total buffer size
* @heap: dma_heap to increase
* @len: length to increase
*/
void rk_dma_heap_total_inc(struct rk_dma_heap *heap, size_t len);
/**
* rk_dma_heap_total_dec - Decrease total buffer size
* @heap: dma_heap to decrease
* @len: length to decrease
*/
void rk_dma_heap_total_dec(struct rk_dma_heap *heap, size_t len);
/**
* rk_dma_heap_get_cma - get cma structure
*/
@@ -328,6 +340,14 @@ static inline void *rk_vmap_contig_pfn(unsigned long pfn, unsigned int count,
return NULL;
}
void rk_dma_heap_total_inc(struct rk_dma_heap *heap, size_t len)
{
}
void rk_dma_heap_total_dec(struct rk_dma_heap *heap, size_t len)
{
}
static inline struct cma *rk_dma_heap_get_cma(void)
{
return NULL;