...
...
7
To visualise it, cat sudo cat /sys/kernel/debug/dri/*.gpu/gems.
7
To visualise it, cat sudo cat /sys/kernel/debug/dri/*.gpu/gems.
8
To test this functionality from UM, please refer to this Mesa patch series:
8
To test this functionality from UM, please refer to this Mesa patch series:
9
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34224
9
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34224
10
10
11
Discussion of previous revision of this patch series can be found at:
11
Discussion of previous revision of this patch series can be found at:
12
https://lore.kernel.org/dri-devel/20250327140845.105962-1-adrian.larumbe@collabora.com/
12
https://lore.kernel.org/dri-devel/20250408222427.1214330-1-adrian.larumbe@collabora.com/T/#t
13
13
14
Changelog:
14
Changelog:
15
v6:
16
- Replaced some mutex calls with scoped guards
17
- Documented data size limits in the label ioctl
18
- Simplified GEMS status flags treatment (Panthor doesn't use madvise)
19
- Fixed some array size and string bugs
20
- Improved the naming of GEM status and usage flags to reflect their meaning
21
- Improved the formatting of the output table
22
23
v5:
24
- Kept case and naming of kernel BO's consistent
25
- Increased the driver minor after new ioctl
26
- Now adds BO to debugfs GEMs list at GEM object creation time
27
- No longer try to hide BO creator's name when it's a workqueue or modprobe
28
- Reworked the procedure for printing GEM state and kernel BO flags
29
- Turned kernel BO flags and GEM state flags into bit enums
30
- Wait until BO state is marked as initialied for debugfs display
15
31
16
v4:
32
v4:
17
- Labelled all kernel BO's, not just heap chunks.
33
- Labelled all kernel BO's, not just heap chunks.
18
- Refactored DebugGFs GEMs list handling functions
34
- Refactored DebugGFs GEMs list handling functions
19
- Added debugfs GEMS node mask to tell different kinds of BO's
35
- Added debugfs GEMS node mask to tell different kinds of BO's
...
...
24
drm/panthor: Label all kernel BO's
40
drm/panthor: Label all kernel BO's
25
drm/panthor: show device-wide list of DRM GEM objects over DebugFS
41
drm/panthor: show device-wide list of DRM GEM objects over DebugFS
26
42
27
drivers/gpu/drm/panthor/panthor_device.c | 5 +
43
drivers/gpu/drm/panthor/panthor_device.c | 5 +
28
drivers/gpu/drm/panthor/panthor_device.h | 11 ++
44
drivers/gpu/drm/panthor/panthor_device.h | 11 ++
29
drivers/gpu/drm/panthor/panthor_drv.c | 66 ++++++++
45
drivers/gpu/drm/panthor/panthor_drv.c | 68 ++++++-
30
drivers/gpu/drm/panthor/panthor_fw.c | 8 +-
46
drivers/gpu/drm/panthor/panthor_fw.c | 8 +-
31
drivers/gpu/drm/panthor/panthor_gem.c | 190 ++++++++++++++++++++++-
47
drivers/gpu/drm/panthor/panthor_gem.c | 229 ++++++++++++++++++++++-
32
drivers/gpu/drm/panthor/panthor_gem.h | 56 ++++++-
48
drivers/gpu/drm/panthor/panthor_gem.h | 80 +++++++-
33
drivers/gpu/drm/panthor/panthor_heap.c | 6 +-
49
drivers/gpu/drm/panthor/panthor_heap.c | 6 +-
34
drivers/gpu/drm/panthor/panthor_sched.c | 9 +-
50
drivers/gpu/drm/panthor/panthor_sched.c | 9 +-
35
include/uapi/drm/panthor_drm.h | 19 +++
51
include/uapi/drm/panthor_drm.h | 23 +++
36
9 files changed, 360 insertions(+), 10 deletions(-)
52
9 files changed, 428 insertions(+), 11 deletions(-)
37
53
38
--
54
--
39
2.48.1
55
2.48.1
diff view generated by jsdifflib
...
...
4
Driver takes care of freeing the string when it's replaced or no longer
4
Driver takes care of freeing the string when it's replaced or no longer
5
needed at object destruction time, but allocating it is the responsibility
5
needed at object destruction time, but allocating it is the responsibility
6
of callers.
6
of callers.
7
7
8
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
8
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
9
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
9
---
10
---
10
drivers/gpu/drm/panthor/panthor_gem.c | 38 +++++++++++++++++++++++++++
11
drivers/gpu/drm/panthor/panthor_gem.c | 39 +++++++++++++++++++++++++++
11
drivers/gpu/drm/panthor/panthor_gem.h | 17 ++++++++++++
12
drivers/gpu/drm/panthor/panthor_gem.h | 17 ++++++++++++
12
2 files changed, 55 insertions(+)
13
2 files changed, 56 insertions(+)
13
14
14
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
15
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/drivers/gpu/drm/panthor/panthor_gem.c
17
--- a/drivers/gpu/drm/panthor/panthor_gem.c
17
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
18
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
19
@@ -XXX,XX +XXX,XX @@
20
/* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */
21
/* Copyright 2023 Collabora ltd. */
22
23
+#include <linux/cleanup.h>
24
#include <linux/dma-buf.h>
25
#include <linux/dma-mapping.h>
26
#include <linux/err.h>
18
@@ -XXX,XX +XXX,XX @@ static void panthor_gem_free_object(struct drm_gem_object *obj)
27
@@ -XXX,XX +XXX,XX @@ static void panthor_gem_free_object(struct drm_gem_object *obj)
19
    struct panthor_gem_object *bo = to_panthor_bo(obj);
28
    struct panthor_gem_object *bo = to_panthor_bo(obj);
20
    struct drm_gem_object *vm_root_gem = bo->exclusive_vm_root_gem;
29
    struct drm_gem_object *vm_root_gem = bo->exclusive_vm_root_gem;
21
30
22
+    /*
31
+    /*
...
...
47
+panthor_gem_bo_set_label(struct drm_gem_object *obj, const char *label)
56
+panthor_gem_bo_set_label(struct drm_gem_object *obj, const char *label)
48
+{
57
+{
49
+    struct panthor_gem_object *bo = to_panthor_bo(obj);
58
+    struct panthor_gem_object *bo = to_panthor_bo(obj);
50
+    const char *old_label;
59
+    const char *old_label;
51
+
60
+
52
+    mutex_lock(&bo->label.lock);
61
+    scoped_guard(mutex, &bo->label.lock) {
53
+    old_label = bo->label.str;
62
+        old_label = bo->label.str;
54
+    bo->label.str = label;
63
+        bo->label.str = label;
55
+    mutex_unlock(&bo->label.lock);
64
+    }
56
+
65
+
57
+    kfree(old_label);
66
+    kfree(old_label);
58
+}
67
+}
59
+
68
+
60
+void
69
+void
...
...
67
+        /* Failing to allocate memory for a label isn't a fatal condition */
76
+        /* Failing to allocate memory for a label isn't a fatal condition */
68
+        drm_warn(bo->obj->dev, "Not enough memory to allocate BO label");
77
+        drm_warn(bo->obj->dev, "Not enough memory to allocate BO label");
69
+        return;
78
+        return;
70
+    }
79
+    }
71
+
80
+
72
+    panthor_gem_bo_set_label(bo->obj, kstrdup_const(str, GFP_KERNEL));
81
+    panthor_gem_bo_set_label(bo->obj, str);
73
+}
82
+}
74
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
83
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
75
index XXXXXXX..XXXXXXX 100644
84
index XXXXXXX..XXXXXXX 100644
76
--- a/drivers/gpu/drm/panthor/panthor_gem.h
85
--- a/drivers/gpu/drm/panthor/panthor_gem.h
77
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
86
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
...
...
diff view generated by jsdifflib
1
Allow UM to label a BO for which it possesses a DRM handle.
1
Allow UM to label a BO for which it possesses a DRM handle.
2
2
3
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
3
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
4
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
5
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
4
---
6
---
5
drivers/gpu/drm/panthor/panthor_drv.c | 40 +++++++++++++++++++++++++++
7
drivers/gpu/drm/panthor/panthor_drv.c | 42 ++++++++++++++++++++++++++-
6
drivers/gpu/drm/panthor/panthor_gem.h | 2 ++
8
drivers/gpu/drm/panthor/panthor_gem.h | 2 ++
7
include/uapi/drm/panthor_drm.h | 19 +++++++++++++
9
include/uapi/drm/panthor_drm.h | 23 +++++++++++++++
8
3 files changed, 61 insertions(+)
10
3 files changed, 66 insertions(+), 1 deletion(-)
9
11
10
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
12
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
11
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
12
--- a/drivers/gpu/drm/panthor/panthor_drv.c
14
--- a/drivers/gpu/drm/panthor/panthor_drv.c
13
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
15
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
...
...
70
* - 1.3 - adds DRM_PANTHOR_GROUP_STATE_INNOCENT flag
72
* - 1.3 - adds DRM_PANTHOR_GROUP_STATE_INNOCENT flag
71
+ * - 1.4 - adds DRM_IOCTL_PANTHOR_BO_SET_LABEL ioctl
73
+ * - 1.4 - adds DRM_IOCTL_PANTHOR_BO_SET_LABEL ioctl
72
*/
74
*/
73
static const struct drm_driver panthor_drm_driver = {
75
static const struct drm_driver panthor_drm_driver = {
74
    .driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
76
    .driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
77
@@ -XXX,XX +XXX,XX @@ static const struct drm_driver panthor_drm_driver = {
78
    .name = "panthor",
79
    .desc = "Panthor DRM driver",
80
    .major = 1,
81
-    .minor = 3,
82
+    .minor = 4,
83
84
    .gem_create_object = panthor_gem_create_object,
85
    .gem_prime_import_sg_table = drm_gem_shmem_prime_import_sg_table,
75
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
86
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
76
index XXXXXXX..XXXXXXX 100644
87
index XXXXXXX..XXXXXXX 100644
77
--- a/drivers/gpu/drm/panthor/panthor_gem.h
88
--- a/drivers/gpu/drm/panthor/panthor_gem.h
78
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
89
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
79
@@ -XXX,XX +XXX,XX @@
90
@@ -XXX,XX +XXX,XX @@
...
...
108
+ */
119
+ */
109
+struct drm_panthor_bo_set_label {
120
+struct drm_panthor_bo_set_label {
110
+    /** @handle: Handle of the buffer object to label. */
121
+    /** @handle: Handle of the buffer object to label. */
111
+    __u32 handle;
122
+    __u32 handle;
112
+
123
+
113
+    /** @size: Length of the label, including the NULL terminator. */
124
+    /**
125
+     * @size: Length of the label, including the NULL terminator.
126
+     *
127
+     * Cannot be greater than the OS page size.
128
+     */
114
+    __u32 size;
129
+    __u32 size;
115
+
130
+
116
+    /** @label: User pointer to a NULL-terminated string */
131
+    /** @label: User pointer to a NULL-terminated string */
117
+    __u64 label;
132
+    __u64 label;
118
+};
133
+};
...
...
diff view generated by jsdifflib
...
...
7
as statically-allocated literals, but if a more complex kernel BO naming
7
as statically-allocated literals, but if a more complex kernel BO naming
8
scheme with explicit memory allocation and formatting was desired in the
8
scheme with explicit memory allocation and formatting was desired in the
9
future, this would have to change.
9
future, this would have to change.
10
10
11
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
11
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
12
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
12
---
13
---
13
drivers/gpu/drm/panthor/panthor_fw.c | 8 +++++---
14
drivers/gpu/drm/panthor/panthor_fw.c | 8 +++++---
14
drivers/gpu/drm/panthor/panthor_gem.c | 3 ++-
15
drivers/gpu/drm/panthor/panthor_gem.c | 4 +++-
15
drivers/gpu/drm/panthor/panthor_gem.h | 2 +-
16
drivers/gpu/drm/panthor/panthor_gem.h | 2 +-
16
drivers/gpu/drm/panthor/panthor_heap.c | 6 ++++--
17
drivers/gpu/drm/panthor/panthor_heap.c | 6 ++++--
17
drivers/gpu/drm/panthor/panthor_sched.c | 9 ++++++---
18
drivers/gpu/drm/panthor/panthor_sched.c | 9 ++++++---
18
5 files changed, 18 insertions(+), 10 deletions(-)
19
5 files changed, 19 insertions(+), 10 deletions(-)
19
20
20
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
21
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
21
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
22
--- a/drivers/gpu/drm/panthor/panthor_fw.c
23
--- a/drivers/gpu/drm/panthor/panthor_fw.c
23
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
24
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
...
...
44
@@ -XXX,XX +XXX,XX @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
45
@@ -XXX,XX +XXX,XX @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
45
        section->mem = panthor_kernel_bo_create(ptdev, panthor_fw_vm(ptdev),
46
        section->mem = panthor_kernel_bo_create(ptdev, panthor_fw_vm(ptdev),
46
                            section_size,
47
                            section_size,
47
                            DRM_PANTHOR_BO_NO_MMAP,
48
                            DRM_PANTHOR_BO_NO_MMAP,
48
-                            vm_map_flags, va);
49
-                            vm_map_flags, va);
49
+                            vm_map_flags, va, "FW Section");
50
+                            vm_map_flags, va, "FW section");
50
        if (IS_ERR(section->mem))
51
        if (IS_ERR(section->mem))
51
            return PTR_ERR(section->mem);
52
            return PTR_ERR(section->mem);
52
53
53
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
54
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
54
index XXXXXXX..XXXXXXX 100644
55
index XXXXXXX..XXXXXXX 100644
...
...
66
@@ -XXX,XX +XXX,XX @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
67
@@ -XXX,XX +XXX,XX @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
67
    kbo->obj = &obj->base;
68
    kbo->obj = &obj->base;
68
    bo->flags = bo_flags;
69
    bo->flags = bo_flags;
69
70
70
+    panthor_gem_kernel_bo_set_label(kbo, name);
71
+    panthor_gem_kernel_bo_set_label(kbo, name);
72
+
71
    /* The system and GPU MMU page size might differ, which becomes a
73
    /* The system and GPU MMU page size might differ, which becomes a
72
     * problem for FW sections that need to be mapped at explicit address
74
     * problem for FW sections that need to be mapped at explicit address
73
     * since our PAGE_SIZE alignment might cover a VA range that's
75
     * since our PAGE_SIZE alignment might cover a VA range that's
74
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
76
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
75
index XXXXXXX..XXXXXXX 100644
77
index XXXXXXX..XXXXXXX 100644
...
...
86
88
87
diff --git a/drivers/gpu/drm/panthor/panthor_heap.c b/drivers/gpu/drm/panthor/panthor_heap.c
89
diff --git a/drivers/gpu/drm/panthor/panthor_heap.c b/drivers/gpu/drm/panthor/panthor_heap.c
88
index XXXXXXX..XXXXXXX 100644
90
index XXXXXXX..XXXXXXX 100644
89
--- a/drivers/gpu/drm/panthor/panthor_heap.c
91
--- a/drivers/gpu/drm/panthor/panthor_heap.c
90
+++ b/drivers/gpu/drm/panthor/panthor_heap.c
92
+++ b/drivers/gpu/drm/panthor/panthor_heap.c
91
@@ -XXX,XX +XXX,XX @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
93
@@ -XXX,XX +XXX,XX @@ static int panthor_alloc_heap_chunk(struct panthor_heap_pool *pool,
92
    chunk->bo = panthor_kernel_bo_create(ptdev, vm, heap->chunk_size,
94
    chunk->bo = panthor_kernel_bo_create(pool->ptdev, pool->vm, heap->chunk_size,
93
                     DRM_PANTHOR_BO_NO_MMAP,
95
                     DRM_PANTHOR_BO_NO_MMAP,
94
                     DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC,
96
                     DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC,
95
-                     PANTHOR_VM_KERNEL_AUTO_VA);
97
-                     PANTHOR_VM_KERNEL_AUTO_VA);
96
+                     PANTHOR_VM_KERNEL_AUTO_VA,
98
+                     PANTHOR_VM_KERNEL_AUTO_VA,
97
+                     "Tiler heap chunk");
99
+                     "Tiler heap chunk");
...
...
116
                         DRM_PANTHOR_BO_NO_MMAP,
118
                         DRM_PANTHOR_BO_NO_MMAP,
117
                         DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC |
119
                         DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC |
118
                         DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED,
120
                         DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED,
119
-                         PANTHOR_VM_KERNEL_AUTO_VA);
121
-                         PANTHOR_VM_KERNEL_AUTO_VA);
120
+                         PANTHOR_VM_KERNEL_AUTO_VA,
122
+                         PANTHOR_VM_KERNEL_AUTO_VA,
121
+                         "Ring buffer");
123
+                         "CS ring buffer");
122
    if (IS_ERR(queue->ringbuf)) {
124
    if (IS_ERR(queue->ringbuf)) {
123
        ret = PTR_ERR(queue->ringbuf);
125
        ret = PTR_ERR(queue->ringbuf);
124
        goto err_free_queue;
126
        goto err_free_queue;
125
@@ -XXX,XX +XXX,XX @@ group_create_queue(struct panthor_group *group,
127
@@ -XXX,XX +XXX,XX @@ group_create_queue(struct panthor_group *group,
126
                     DRM_PANTHOR_BO_NO_MMAP,
128
                     DRM_PANTHOR_BO_NO_MMAP,
127
                     DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC |
129
                     DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC |
128
                     DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED,
130
                     DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED,
129
-                     PANTHOR_VM_KERNEL_AUTO_VA);
131
-                     PANTHOR_VM_KERNEL_AUTO_VA);
130
+                     PANTHOR_VM_KERNEL_AUTO_VA,
132
+                     PANTHOR_VM_KERNEL_AUTO_VA,
131
+                     "fdinfo slots");
133
+                     "Group job stats");
132
134
133
    if (IS_ERR(queue->profiling.slots)) {
135
    if (IS_ERR(queue->profiling.slots)) {
134
        ret = PTR_ERR(queue->profiling.slots);
136
        ret = PTR_ERR(queue->profiling.slots);
135
@@ -XXX,XX +XXX,XX @@ int panthor_group_create(struct panthor_file *pfile,
137
@@ -XXX,XX +XXX,XX @@ int panthor_group_create(struct panthor_file *pfile,
136
                         DRM_PANTHOR_BO_NO_MMAP,
138
                         DRM_PANTHOR_BO_NO_MMAP,
...
...
diff view generated by jsdifflib
...
...
8
File format is that of a table, with each entry displaying a variety of
8
File format is that of a table, with each entry displaying a variety of
9
fields with information about each GEM object.
9
fields with information about each GEM object.
10
10
11
Each GEM object entry in the file displays the following information
11
Each GEM object entry in the file displays the following information
12
fields: Client PID, BO's global name, reference count, BO virtual size,
12
fields: Client PID, BO's global name, reference count, BO virtual size,
13
BO resize size, VM address in its DRM-managed range, BO label and a flag
13
BO resize size, VM address in its DRM-managed range, BO label and a GEM
14
bitmask.
14
state flags.
15
15
16
There's also a kflags field for the type of BO. Bit 0 tells us whether
16
There's also a usage flags field for the type of BO, which tells us
17
it's a kernel BO, and bit 1 means the BO is mapped onto the FW's address
17
whether it's a kernel BO and/or mapped onto the FW's address space.
18
space.
19
18
20
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
19
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
21
---
20
---
22
drivers/gpu/drm/panthor/panthor_device.c | 5 +
21
drivers/gpu/drm/panthor/panthor_device.c | 5 +
23
drivers/gpu/drm/panthor/panthor_device.h | 11 ++
22
drivers/gpu/drm/panthor/panthor_device.h | 11 ++
24
drivers/gpu/drm/panthor/panthor_drv.c | 26 ++++
23
drivers/gpu/drm/panthor/panthor_drv.c | 26 ++++
25
drivers/gpu/drm/panthor/panthor_gem.c | 149 +++++++++++++++++++++++
24
drivers/gpu/drm/panthor/panthor_gem.c | 186 +++++++++++++++++++++++
26
drivers/gpu/drm/panthor/panthor_gem.h | 35 ++++++
25
drivers/gpu/drm/panthor/panthor_gem.h | 59 +++++++
27
5 files changed, 226 insertions(+)
26
5 files changed, 287 insertions(+)
28
27
29
diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
28
diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
30
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
31
--- a/drivers/gpu/drm/panthor/panthor_device.c
30
--- a/drivers/gpu/drm/panthor/panthor_device.c
32
+++ b/drivers/gpu/drm/panthor/panthor_device.c
31
+++ b/drivers/gpu/drm/panthor/panthor_device.c
...
...
107
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
106
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
108
index XXXXXXX..XXXXXXX 100644
107
index XXXXXXX..XXXXXXX 100644
109
--- a/drivers/gpu/drm/panthor/panthor_gem.c
108
--- a/drivers/gpu/drm/panthor/panthor_gem.c
110
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
109
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
111
@@ -XXX,XX +XXX,XX @@
110
@@ -XXX,XX +XXX,XX @@
112
/* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */
113
/* Copyright 2023 Collabora ltd. */
114
115
+#include <linux/cleanup.h>
116
#include <linux/dma-buf.h>
117
#include <linux/dma-mapping.h>
118
#include <linux/err.h>
119
@@ -XXX,XX +XXX,XX @@
120
#include <drm/panthor_drm.h>
111
#include <drm/panthor_drm.h>
121
112
122
#include "panthor_device.h"
113
#include "panthor_device.h"
123
+#include "panthor_fw.h"
114
+#include "panthor_fw.h"
124
#include "panthor_gem.h"
115
#include "panthor_gem.h"
125
#include "panthor_mmu.h"
116
#include "panthor_mmu.h"
126
117
127
+#ifdef CONFIG_DEBUG_FS
118
+#ifdef CONFIG_DEBUG_FS
128
+static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo, u32 type_mask)
119
+static void panthor_gem_debugfs_bo_add(struct panthor_device *ptdev,
120
+                 struct panthor_gem_object *bo)
129
+{
121
+{
130
+    INIT_LIST_HEAD(&bo->debugfs.node);
122
+    INIT_LIST_HEAD(&bo->debugfs.node);
131
+
123
+
132
+    if (!(type_mask & PANTHOR_BO_FW_MAPPED)) {
124
+    bo->debugfs.creator.tgid = current->group_leader->pid;
133
+        bo->debugfs.creator.tgid = current->group_leader->pid;
125
+    get_task_comm(bo->debugfs.creator.process_name, current->group_leader);
134
+        get_task_comm(bo->debugfs.creator.process_name, current->group_leader);
135
+    } else {
136
+        bo->debugfs.creator.tgid = 0;
137
+        snprintf(bo->debugfs.creator.process_name,
138
+             sizeof(bo->debugfs.creator.process_name),
139
+             "kernel");
140
+    }
141
+
142
+    bo->debugfs.bo_mask = type_mask;
143
+}
144
+
145
+static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo, u32 type_mask)
146
+{
147
+    struct panthor_device *ptdev = container_of(bo->base.base.dev,
148
+                         struct panthor_device, base);
149
+
150
+    panthor_gem_debugfs_bo_init(bo, type_mask);
151
+
126
+
152
+    mutex_lock(&ptdev->gems.lock);
127
+    mutex_lock(&ptdev->gems.lock);
153
+    list_add_tail(&bo->debugfs.node, &ptdev->gems.node);
128
+    list_add_tail(&bo->debugfs.node, &ptdev->gems.node);
154
+    mutex_unlock(&ptdev->gems.lock);
129
+    mutex_unlock(&ptdev->gems.lock);
155
+}
130
+}
...
...
166
+    list_del_init(&bo->debugfs.node);
141
+    list_del_init(&bo->debugfs.node);
167
+    mutex_unlock(&ptdev->gems.lock);
142
+    mutex_unlock(&ptdev->gems.lock);
168
+}
143
+}
169
+
144
+
170
+#else
145
+#else
171
+static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo, u32 type_mask) {}
146
+static void panthor_gem_debugfs_bo_add(struct panthor_device *ptdev,
147
+                 struct panthor_gem_object *bo)
148
+{}
172
+static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo) {}
149
+static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo) {}
173
+#endif
150
+#endif
174
+
151
+
175
static void panthor_gem_free_object(struct drm_gem_object *obj)
152
static void panthor_gem_free_object(struct drm_gem_object *obj)
176
{
153
{
...
...
184
     * we need to take that into account when freeing the memory
161
     * we need to take that into account when freeing the memory
185
@@ -XXX,XX +XXX,XX @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
162
@@ -XXX,XX +XXX,XX @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
186
    struct drm_gem_shmem_object *obj;
163
    struct drm_gem_shmem_object *obj;
187
    struct panthor_kernel_bo *kbo;
164
    struct panthor_kernel_bo *kbo;
188
    struct panthor_gem_object *bo;
165
    struct panthor_gem_object *bo;
189
+    u32 type_mask = PANTHOR_BO_KERNEL;
166
+    u32 debug_flags = PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL;
190
    int ret;
167
    int ret;
191
168
192
    if (drm_WARN_ON(&ptdev->base, !vm))
169
    if (drm_WARN_ON(&ptdev->base, !vm))
193
@@ -XXX,XX +XXX,XX @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
170
@@ -XXX,XX +XXX,XX @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
194
    kbo->obj = &obj->base;
171
    kbo->obj = &obj->base;
195
    bo->flags = bo_flags;
172
    bo->flags = bo_flags;
196
173
197
+    if (vm == panthor_fw_vm(ptdev))
174
+    if (vm == panthor_fw_vm(ptdev))
198
+        type_mask |= PANTHOR_BO_FW_MAPPED;
175
+        debug_flags |= PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED;
199
+
176
+
200
    panthor_gem_kernel_bo_set_label(kbo, name);
177
    panthor_gem_kernel_bo_set_label(kbo, name);
201
+    panthor_gem_debugfs_bo_add(to_panthor_bo(kbo->obj), type_mask);
178
+    panthor_gem_debugfs_bo_set_mask(to_panthor_bo(kbo->obj), debug_flags);
202
+
179
203
    /* The system and GPU MMU page size might differ, which becomes a
180
    /* The system and GPU MMU page size might differ, which becomes a
204
     * problem for FW sections that need to be mapped at explicit address
181
     * problem for FW sections that need to be mapped at explicit address
205
     * since our PAGE_SIZE alignment might cover a VA range that's
182
@@ -XXX,XX +XXX,XX @@ struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_t
183
    drm_gem_gpuva_set_lock(&obj->base.base, &obj->gpuva_list_lock);
184
    mutex_init(&obj->label.lock);
185
186
+    panthor_gem_debugfs_bo_add(ptdev, obj);
187
+
188
    return &obj->base.base;
189
}
190
206
@@ -XXX,XX +XXX,XX @@ panthor_gem_create_with_handle(struct drm_file *file,
191
@@ -XXX,XX +XXX,XX @@ panthor_gem_create_with_handle(struct drm_file *file,
207
    /* drop reference from allocate - handle holds it now. */
192
    /* drop reference from allocate - handle holds it now. */
208
    drm_gem_object_put(&shmem->base);
193
    drm_gem_object_put(&shmem->base);
209
194
210
+    panthor_gem_debugfs_bo_add(bo, 0);
195
+    /*
196
+     * No explicit flags are needed in the call below, since the
197
+     * function internally sets the INITIALIZED bit for us.
198
+     */
199
+    panthor_gem_debugfs_bo_set_mask(bo, 0);
211
+
200
+
212
    return ret;
201
    return ret;
213
}
202
}
214
203
215
@@ -XXX,XX +XXX,XX @@ panthor_gem_kernel_bo_set_label(struct panthor_kernel_bo *bo, const char *label)
204
@@ -XXX,XX +XXX,XX @@ panthor_gem_kernel_bo_set_label(struct panthor_kernel_bo *bo, const char *label)
216
205
217
    panthor_gem_bo_set_label(bo->obj, kstrdup_const(str, GFP_KERNEL));
206
    panthor_gem_bo_set_label(bo->obj, str);
218
}
207
}
219
+
208
+
220
+#ifdef CONFIG_DEBUG_FS
209
+#ifdef CONFIG_DEBUG_FS
221
+static bool panfrost_gem_print_flag(const char *name,
210
+static void
222
+                 bool is_set,
211
+panthor_gem_debugfs_format_flags(char flags_str[], int flags_len,
223
+                 bool other_flags_printed,
212
+                 const char * const names[], u32 name_count,
224
+                 struct seq_file *m)
213
+                 u32 flags)
225
+{
214
+{
226
+    if (is_set)
215
+    bool first = true;
227
+        seq_printf(m, "%s%s", other_flags_printed ? "," : "", name);
216
+    int offset = 0;
228
+
217
+
229
+    return is_set | other_flags_printed;
218
+#define ACC_FLAGS(...) \
219
+    ({ \
220
+        offset += snprintf(flags_str + offset, flags_len - offset, ##__VA_ARGS__); \
221
+        if (offset == flags_len) \
222
+            return; \
223
+    })
224
+
225
+    ACC_FLAGS("%c", '(');
226
+
227
+    if (!flags)
228
+        ACC_FLAGS("%s", "none");
229
+
230
+    while (flags) {
231
+        u32 bit = fls(flags) - 1;
232
+        u32 idx = bit + 1;
233
+
234
+        if (!first)
235
+            ACC_FLAGS("%s", ",");
236
+
237
+        if (idx >= name_count || !names[idx])
238
+            ACC_FLAGS("unknown-bit%d", bit);
239
+        else
240
+            ACC_FLAGS("%s", names[idx]);
241
+
242
+        first = false;
243
+        flags &= ~BIT(bit);
244
+    }
245
+
246
+    ACC_FLAGS("%c", ')');
247
+
248
+#undef ACC_FLAGS
230
+}
249
+}
231
+
250
+
232
+struct gem_size_totals {
251
+struct gem_size_totals {
233
+    size_t size;
252
+    size_t size;
234
+    size_t resident;
253
+    size_t resident;
...
...
239
+                     struct seq_file *m,
258
+                     struct seq_file *m,
240
+                     struct gem_size_totals *totals)
259
+                     struct gem_size_totals *totals)
241
+{
260
+{
242
+    unsigned int refcount = kref_read(&bo->base.base.refcount);
261
+    unsigned int refcount = kref_read(&bo->base.base.refcount);
243
+    char creator_info[32] = {};
262
+    char creator_info[32] = {};
244
+    bool has_flags = false;
245
+    size_t resident_size;
263
+    size_t resident_size;
264
+    char gem_state_str[24] = {};
265
+    char gem_usage_str[24] = {};
266
+    u32 gem_usage_flags = bo->debugfs.flags & (u32)~PANTHOR_DEBUGFS_GEM_USAGE_FLAG_INITIALIZED;
267
+    u32 gem_state_flags = 0;
268
+
269
+    static const char * const gem_state_flags_names[] = {
270
+        [PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED] = "imported",
271
+        [PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED] = "exported",
272
+    };
273
+
274
+    static const char * const gem_usage_flags_names[] = {
275
+        [PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL] = "kernel",
276
+        [PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED] = "fw-mapped",
277
+    };
246
+
278
+
247
+    /* Skip BOs being destroyed. */
279
+    /* Skip BOs being destroyed. */
248
+    if (!refcount)
280
+    if (!refcount)
249
+        return;
281
+        return;
250
+
282
+
...
...
258
+         refcount,
290
+         refcount,
259
+         bo->base.base.size,
291
+         bo->base.base.size,
260
+         resident_size,
292
+         resident_size,
261
+         drm_vma_node_start(&bo->base.base.vma_node));
293
+         drm_vma_node_start(&bo->base.base.vma_node));
262
+
294
+
263
+    seq_puts(m, "(");
295
+
264
+    has_flags = panfrost_gem_print_flag("imported", bo->base.base.import_attach != NULL,
296
+    if (bo->base.base.import_attach != NULL)
265
+                     has_flags, m);
297
+        gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED;
266
+    has_flags = panfrost_gem_print_flag("exported", bo->base.base.dma_buf != NULL,
298
+    if (bo->base.base.dma_buf != NULL)
267
+                     has_flags, m);
299
+        gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED;
268
+    if (bo->base.madv < 0)
300
+
269
+        has_flags = panfrost_gem_print_flag("purged", true, has_flags, m);
301
+    panthor_gem_debugfs_format_flags(gem_state_str, sizeof(gem_state_str),
270
+    else if (bo->base.madv > 0)
302
+                     gem_state_flags_names, ARRAY_SIZE(gem_state_flags_names),
271
+        has_flags = panfrost_gem_print_flag("purgeable", true, has_flags, m);
303
+                     gem_state_flags);
272
+    if (!has_flags)
304
+    panthor_gem_debugfs_format_flags(gem_usage_str, sizeof(gem_usage_str),
273
+        seq_puts(m, "none");
305
+                     gem_usage_flags_names, ARRAY_SIZE(gem_usage_flags_names),
274
+    seq_puts(m, ")");
306
+                     gem_usage_flags);
275
+
307
+
276
+    seq_printf(m, "%-6s0x%-2x", "", bo->debugfs.bo_mask);
308
+    seq_printf(m, "%-24s%-24s", gem_state_str, gem_usage_str);
277
+
309
+
278
+    mutex_lock(&bo->label.lock);
310
+    scoped_guard(mutex, &bo->label.lock) {
279
+    seq_printf(m, "%-6s%-60s", "", bo->label.str ? : NULL);
311
+        seq_printf(m, "%s", bo->label.str ? : "");
280
+    mutex_unlock(&bo->label.lock);
312
+    }
313
+
281
+    seq_puts(m, "\n");
314
+    seq_puts(m, "\n");
282
+
315
+
283
+    totals->size += bo->base.base.size;
316
+    totals->size += bo->base.base.size;
284
+    totals->resident += resident_size;
317
+    totals->resident += resident_size;
285
+    if (bo->base.madv > 0)
318
+    if (bo->base.madv > 0)
...
...
290
+                 struct seq_file *m)
323
+                 struct seq_file *m)
291
+{
324
+{
292
+    struct gem_size_totals totals = {0};
325
+    struct gem_size_totals totals = {0};
293
+    struct panthor_gem_object *bo;
326
+    struct panthor_gem_object *bo;
294
+
327
+
295
+    seq_puts(m, "created-by global-name refcount size resident-size file-offset flags kflags label\n");
328
+    seq_puts(m, "created-by global-name refcount size resident-size file-offset state usage label\n");
296
+    seq_puts(m, "------------------------------------------------------------------------------------------------------------------------------------------------\n");
329
+    seq_puts(m, "---------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
297
+
330
+
298
+    scoped_guard(mutex, &ptdev->gems.lock) {
331
+    scoped_guard(mutex, &ptdev->gems.lock) {
299
+        list_for_each_entry(bo, &ptdev->gems.node, debugfs.node)
332
+        list_for_each_entry(bo, &ptdev->gems.node, debugfs.node) {
300
+            panthor_gem_debugfs_bo_print(bo, m, &totals);
333
+            if (bo->debugfs.flags & PANTHOR_DEBUGFS_GEM_USAGE_FLAG_INITIALIZED)
334
+                panthor_gem_debugfs_bo_print(bo, m, &totals);
335
+        }
336
+
301
+    }
337
+    }
302
+
338
+
303
+    seq_puts(m, "==========================================================================================================================================================\n");
339
+    seq_puts(m, "=====================================================================================================================================================================\n");
304
+    seq_printf(m, "Total size: %zd, Total resident: %zd, Total reclaimable: %zd\n",
340
+    seq_printf(m, "Total size: %zd, Total resident: %zd, Total reclaimable: %zd\n",
305
+         totals.size, totals.resident, totals.reclaimable);
341
+         totals.size, totals.resident, totals.reclaimable);
306
+}
342
+}
307
+#endif
343
+#endif
308
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
344
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
...
...
311
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
347
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
312
@@ -XXX,XX +XXX,XX @@ struct panthor_vm;
348
@@ -XXX,XX +XXX,XX @@ struct panthor_vm;
313
349
314
#define PANTHOR_BO_LABEL_MAXLEN    PAGE_SIZE
350
#define PANTHOR_BO_LABEL_MAXLEN    PAGE_SIZE
315
351
316
+#define PANTHOR_BO_KERNEL    BIT(0)
352
+enum panthor_debugfs_gem_state_flags {
317
+#define PANTHOR_BO_FW_MAPPED    BIT(1)
353
+    /** @PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED: GEM BO is PRIME imported. */
354
+    PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED = BIT(0),
355
+
356
+    /** @PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED: GEM BO is PRIME exported. */
357
+    PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED = BIT(1),
358
+};
359
+
360
+enum panthor_debugfs_gem_usage_flags {
361
+    /** @PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL: BO is for kernel use only. */
362
+    PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL = BIT(0),
363
+
364
+    /** @PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED: BO is mapped on the FW VM. */
365
+    PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED = BIT(1),
366
+
367
+    /** @PANTHOR_DEBUGFS_GEM_USAGE_FLAG_INITIALIZED: BO is ready for DebugFS display. */
368
+    PANTHOR_DEBUGFS_GEM_USAGE_FLAG_INITIALIZED = BIT(31),
369
+};
318
+
370
+
319
+/**
371
+/**
320
+ * struct panthor_gem_debugfs - GEM object's DebugFS list information
372
+ * struct panthor_gem_debugfs - GEM object's DebugFS list information
321
+ */
373
+ */
322
+struct panthor_gem_debugfs {
374
+struct panthor_gem_debugfs {
...
...
333
+
385
+
334
+        /** @creator.tgid: PID of the thread's group leader within its process */
386
+        /** @creator.tgid: PID of the thread's group leader within its process */
335
+        pid_t tgid;
387
+        pid_t tgid;
336
+    } creator;
388
+    } creator;
337
+
389
+
338
+    /** @bo_mask: Bitmask encoding BO type as {USER, KERNEL} x {GPU, FW} */
390
+    /** @flags: Combination of panthor_debugfs_gem_usage_flags flags */
339
+    u32 bo_mask;
391
+    u32 flags;
340
+};
392
+};
341
+
393
+
342
/**
394
/**
343
* struct panthor_gem_object - Driver specific GEM object.
395
* struct panthor_gem_object - Driver specific GEM object.
344
*/
396
*/
...
...
358
void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo);
410
void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo);
359
411
360
+#ifdef CONFIG_DEBUG_FS
412
+#ifdef CONFIG_DEBUG_FS
361
+void panthor_gem_debugfs_print_bos(struct panthor_device *pfdev,
413
+void panthor_gem_debugfs_print_bos(struct panthor_device *pfdev,
362
+                 struct seq_file *m);
414
+                 struct seq_file *m);
415
+static inline void
416
+panthor_gem_debugfs_bo_set_mask(struct panthor_gem_object *bo, u32 type_mask)
417
+{
418
+    bo->debugfs.flags = type_mask | PANTHOR_DEBUGFS_GEM_USAGE_FLAG_INITIALIZED;
419
+}
420
+
421
+#else
422
+void panthor_gem_debugfs_bo_set_mask(struct panthor_gem_object *bo, u32 type_mask) {};
363
+#endif
423
+#endif
364
+
424
+
365
#endif /* __PANTHOR_GEM_H__ */
425
#endif /* __PANTHOR_GEM_H__ */
366
--
426
--
367
2.48.1
427
2.48.1
368
428
diff view generated by jsdifflib