gpu: ion: Refactor debugfs printing
Printing to debugfs is done from a centralized location for
all the heaps managed by ion. This architecture is not
sustainable in the long run since different heaps have different
requirements for what should be printed.
Refactor the debugfs printing for ion so that each heap is
responsible for printing its information.
Change-Id: I1dbe13432a4ab07f27ea4756c3be7fa01ad1df92
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c
index ec93055..34145fe 100644
--- a/drivers/gpu/ion/ion.c
+++ b/drivers/gpu/ion/ion.c
@@ -1605,30 +1605,8 @@
seq_printf(s, "%16.s %16u %16x\n", client->name, client->pid,
size);
}
- if (heap->ops->get_allocated) {
- seq_printf(s, "total bytes currently allocated: %lx\n",
- heap->ops->get_allocated(heap));
- }
- if (heap->ops->get_total) {
- seq_printf(s, "total heap size: %lx\n",
- heap->ops->get_total(heap));
- }
- if (heap->ops->get_alloc_cnt) {
- seq_printf(s, "allocation count: %lx\n",
- heap->ops->get_alloc_cnt(heap));
- }
- if (heap->ops->get_umap_cnt) {
- seq_printf(s, "umapping count: %lx\n",
- heap->ops->get_umap_cnt(heap));
- }
- if (heap->ops->get_kmap_cnt) {
- seq_printf(s, "kmapping count: %lx\n",
- heap->ops->get_kmap_cnt(heap));
- }
- if (heap->ops->get_secured) {
- seq_printf(s, "secured heap: %s\n",
- heap->ops->get_secured(heap) ? "Yes" : "No");
- }
+ if (heap->ops->print_debug)
+ heap->ops->print_debug(heap, s);
return 0;
}
diff --git a/drivers/gpu/ion/ion_carveout_heap.c b/drivers/gpu/ion/ion_carveout_heap.c
index 10daf91..ad0c7b1 100644
--- a/drivers/gpu/ion/ion_carveout_heap.c
+++ b/drivers/gpu/ion/ion_carveout_heap.c
@@ -25,6 +25,7 @@
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/iommu.h>
+#include <linux/seq_file.h>
#include "ion_priv.h"
#include <mach/iommu_domains.h>
@@ -255,20 +256,16 @@
return 0;
}
-static unsigned long ion_carveout_get_allocated(struct ion_heap *heap)
+static int ion_carveout_print_debug(struct ion_heap *heap, struct seq_file *s)
{
struct ion_carveout_heap *carveout_heap =
container_of(heap, struct ion_carveout_heap, heap);
- return carveout_heap->allocated_bytes;
-}
+ seq_printf(s, "total bytes currently allocated: %lx\n",
+ carveout_heap->allocated_bytes);
+ seq_printf(s, "total heap size: %lx\n", carveout_heap->total_size);
-static unsigned long ion_carveout_get_total(struct ion_heap *heap)
-{
- struct ion_carveout_heap *carveout_heap =
- container_of(heap, struct ion_carveout_heap, heap);
-
- return carveout_heap->total_size;
+ return 0;
}
int ion_carveout_heap_map_iommu(struct ion_buffer *buffer,
@@ -384,8 +381,7 @@
.map_dma = ion_carveout_heap_map_dma,
.unmap_dma = ion_carveout_heap_unmap_dma,
.cache_op = ion_carveout_cache_ops,
- .get_allocated = ion_carveout_get_allocated,
- .get_total = ion_carveout_get_total,
+ .print_debug = ion_carveout_print_debug,
.map_iommu = ion_carveout_heap_map_iommu,
.unmap_iommu = ion_carveout_heap_unmap_iommu,
};
diff --git a/drivers/gpu/ion/ion_cp_heap.c b/drivers/gpu/ion/ion_cp_heap.c
index 6eca0f0..16ace6f 100644
--- a/drivers/gpu/ion/ion_cp_heap.c
+++ b/drivers/gpu/ion/ion_cp_heap.c
@@ -25,6 +25,7 @@
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/memory_alloc.h>
+#include <linux/seq_file.h>
#include <mach/msm_memtypes.h>
#include <mach/scm.h>
#include "ion_priv.h"
@@ -454,77 +455,34 @@
return 0;
}
-static unsigned long ion_cp_get_allocated(struct ion_heap *heap)
+static int ion_cp_print_debug(struct ion_heap *heap, struct seq_file *s)
{
- struct ion_cp_heap *cp_heap =
- container_of(heap, struct ion_cp_heap, heap);
- unsigned long allocated_bytes;
-
- mutex_lock(&cp_heap->lock);
- allocated_bytes = cp_heap->allocated_bytes;
- mutex_unlock(&cp_heap->lock);
-
- return allocated_bytes;
-}
-
-static unsigned long ion_cp_get_total(struct ion_heap *heap)
-{
- struct ion_cp_heap *cp_heap =
- container_of(heap, struct ion_cp_heap, heap);
-
- return cp_heap->total_size;
-}
-
-static unsigned long ion_cp_get_umap_count(struct ion_heap *heap)
-{
- struct ion_cp_heap *cp_heap =
- container_of(heap, struct ion_cp_heap, heap);
- unsigned long umap_count;
-
- mutex_lock(&cp_heap->lock);
- umap_count = cp_heap->umap_count;
- mutex_unlock(&cp_heap->lock);
-
- return umap_count;
-}
-
-static unsigned long ion_cp_get_kmap_count(struct ion_heap *heap)
-{
- struct ion_cp_heap *cp_heap =
- container_of(heap, struct ion_cp_heap, heap);
- unsigned long kmap_count;
-
- mutex_lock(&cp_heap->lock);
- kmap_count = cp_heap->kmap_count;
- mutex_unlock(&cp_heap->lock);
-
- return kmap_count;
-}
-
-static unsigned long ion_cp_get_alloc_count(struct ion_heap *heap)
-{
- struct ion_cp_heap *cp_heap =
- container_of(heap, struct ion_cp_heap, heap);
+ unsigned long total_alloc;
+ unsigned long total_size;
unsigned long alloc_count;
-
- mutex_lock(&cp_heap->lock);
- alloc_count = cp_heap->alloc_count;
- mutex_unlock(&cp_heap->lock);
-
- return alloc_count;
-}
-
-static unsigned long ion_cp_get_secured(struct ion_heap *heap)
-{
+ unsigned long umap_count;
+ unsigned long kmap_count;
+ unsigned long heap_secured;
struct ion_cp_heap *cp_heap =
container_of(heap, struct ion_cp_heap, heap);
- unsigned long secured_heap = 0;
mutex_lock(&cp_heap->lock);
- secured_heap = cp_heap->heap_secured == SECURED_HEAP;
+ total_alloc = cp_heap->allocated_bytes;
+ total_size = cp_heap->total_size;
+ alloc_count = cp_heap->alloc_count;
+ umap_count = cp_heap->umap_count;
+ kmap_count = cp_heap->kmap_count;
+ heap_secured = cp_heap->heap_secured == SECURED_HEAP;
mutex_unlock(&cp_heap->lock);
- return secured_heap;
+ seq_printf(s, "total bytes currently allocated: %lx\n", total_alloc);
+ seq_printf(s, "total heap size: %lx\n", total_size);
+ seq_printf(s, "allocation count: %lx\n", alloc_count);
+ seq_printf(s, "umapping count: %lx\n", umap_count);
+ seq_printf(s, "kmapping count: %lx\n", kmap_count);
+ seq_printf(s, "secured heap: %s\n", heap_secured ? "Yes" : "No");
+
+ return 0;
}
int ion_cp_secure_heap(struct ion_heap *heap)
@@ -561,12 +519,7 @@
.map_dma = ion_cp_heap_map_dma,
.unmap_dma = ion_cp_heap_unmap_dma,
.cache_op = ion_cp_cache_ops,
- .get_allocated = ion_cp_get_allocated,
- .get_total = ion_cp_get_total,
- .get_umap_cnt = ion_cp_get_umap_count,
- .get_kmap_cnt = ion_cp_get_kmap_count,
- .get_alloc_cnt = ion_cp_get_alloc_count,
- .get_secured = ion_cp_get_secured,
+ .print_debug = ion_cp_print_debug,
.secure_heap = ion_cp_secure_heap,
.unsecure_heap = ion_cp_unsecure_heap,
};
diff --git a/drivers/gpu/ion/ion_priv.h b/drivers/gpu/ion/ion_priv.h
index 98709b6..78dfe6e 100644
--- a/drivers/gpu/ion/ion_priv.h
+++ b/drivers/gpu/ion/ion_priv.h
@@ -139,8 +139,6 @@
int (*cache_op)(struct ion_heap *heap, struct ion_buffer *buffer,
void *vaddr, unsigned int offset,
unsigned int length, unsigned int cmd);
- unsigned long (*get_allocated)(struct ion_heap *heap);
- unsigned long (*get_total)(struct ion_heap *heap);
int (*map_iommu)(struct ion_buffer *buffer,
struct ion_iommu_map *map_data,
unsigned int domain_num,
@@ -149,10 +147,7 @@
unsigned long iova_length,
unsigned long flags);
void (*unmap_iommu)(struct ion_iommu_map *data);
- unsigned long (*get_umap_cnt)(struct ion_heap *heap);
- unsigned long (*get_kmap_cnt)(struct ion_heap *heap);
- unsigned long (*get_alloc_cnt)(struct ion_heap *heap);
- unsigned long (*get_secured)(struct ion_heap *heap);
+ int (*print_debug)(struct ion_heap *heap, struct seq_file *s);
int (*secure_heap)(struct ion_heap *heap);
int (*unsecure_heap)(struct ion_heap *heap);
};
diff --git a/drivers/gpu/ion/ion_system_heap.c b/drivers/gpu/ion/ion_system_heap.c
index 5957658..316740e 100644
--- a/drivers/gpu/ion/ion_system_heap.c
+++ b/drivers/gpu/ion/ion_system_heap.c
@@ -2,7 +2,7 @@
* drivers/gpu/ion/ion_system_heap.c
*
* Copyright (C) 2011 Google, Inc.
- * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/iommu.h>
+#include <linux/seq_file.h>
#include <mach/iommu_domains.h>
#include "ion_priv.h"
#include <mach/memory.h>
@@ -189,9 +190,12 @@
return 0;
}
-static unsigned long ion_system_heap_get_allocated(struct ion_heap *heap)
+static int ion_system_print_debug(struct ion_heap *heap, struct seq_file *s)
{
- return atomic_read(&system_heap_allocated);
+ seq_printf(s, "total bytes currently allocated: %lx\n",
+ (unsigned long) atomic_read(&system_heap_allocated));
+
+ return 0;
}
int ion_system_heap_map_iommu(struct ion_buffer *buffer,
@@ -274,7 +278,7 @@
.unmap_kernel = ion_system_heap_unmap_kernel,
.map_user = ion_system_heap_map_user,
.cache_op = ion_system_heap_cache_ops,
- .get_allocated = ion_system_heap_get_allocated,
+ .print_debug = ion_system_print_debug,
.map_iommu = ion_system_heap_map_iommu,
.unmap_iommu = ion_system_heap_unmap_iommu,
};
@@ -387,9 +391,13 @@
return 0;
}
-static unsigned long ion_system_contig_heap_get_allocated(struct ion_heap *heap)
+static int ion_system_contig_print_debug(struct ion_heap *heap,
+ struct seq_file *s)
{
- return atomic_read(&system_contig_heap_allocated);
+ seq_printf(s, "total bytes currently allocated: %lx\n",
+ (unsigned long) atomic_read(&system_contig_heap_allocated));
+
+ return 0;
}
int ion_system_contig_heap_map_iommu(struct ion_buffer *buffer,
@@ -470,7 +478,7 @@
.unmap_kernel = ion_system_heap_unmap_kernel,
.map_user = ion_system_contig_heap_map_user,
.cache_op = ion_system_contig_heap_cache_ops,
- .get_allocated = ion_system_contig_heap_get_allocated,
+ .print_debug = ion_system_contig_print_debug,
.map_iommu = ion_system_contig_heap_map_iommu,
.unmap_iommu = ion_system_heap_unmap_iommu,
};