2024-02-29 17:22:19 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 or MIT */
|
|
|
|
/* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */
|
|
|
|
/* Copyright 2023 Collabora ltd. */
|
|
|
|
|
|
|
|
#ifndef __PANTHOR_GEM_H__
|
|
|
|
#define __PANTHOR_GEM_H__
|
|
|
|
|
|
|
|
#include <drm/drm_gem_shmem_helper.h>
|
|
|
|
#include <drm/drm_mm.h>
|
|
|
|
|
|
|
|
#include <linux/iosys-map.h>
|
|
|
|
#include <linux/rwsem.h>
|
|
|
|
|
|
|
|
struct panthor_vm;
|
|
|
|
|
2025-04-23 03:12:32 +01:00
|
|
|
#define PANTHOR_BO_LABEL_MAXLEN 4096
|
|
|
|
|
drm/panthor: show device-wide list of DRM GEM objects over DebugFS
Add a device DebugFS file that displays a complete list of all the DRM
GEM objects that are exposed to UM through a DRM handle.
Since leaking object identifiers that might belong to a different NS is
inadmissible, this functionality is only made available in debug builds
with DEBUGFS support enabled.
File format is that of a table, with each entry displaying a variety of
fields with information about each GEM object.
Each GEM object entry in the file displays the following information
fields: Client PID, BO's global name, reference count, BO virtual size,
BO resize size, VM address in its DRM-managed range, BO label and a GEM
state flags.
There's also a usage flags field for the type of BO, which tells us
whether it's a kernel BO and/or mapped onto the FW's address space.
GEM state and usage flag meanings are printed in the file prelude, so
that UM parsing tools can interpret the numerical values in the table.
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Link: https://lore.kernel.org/r/20250423021238.1639175-5-adrian.larumbe@collabora.com
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2025-04-23 03:12:34 +01:00
|
|
|
enum panthor_debugfs_gem_state_flags {
|
|
|
|
PANTHOR_DEBUGFS_GEM_STATE_IMPORTED_BIT = 0,
|
|
|
|
PANTHOR_DEBUGFS_GEM_STATE_EXPORTED_BIT = 1,
|
|
|
|
|
|
|
|
/** @PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED: GEM BO is PRIME imported. */
|
|
|
|
PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED = BIT(PANTHOR_DEBUGFS_GEM_STATE_IMPORTED_BIT),
|
|
|
|
|
|
|
|
/** @PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED: GEM BO is PRIME exported. */
|
|
|
|
PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED = BIT(PANTHOR_DEBUGFS_GEM_STATE_EXPORTED_BIT),
|
|
|
|
};
|
|
|
|
|
|
|
|
enum panthor_debugfs_gem_usage_flags {
|
|
|
|
PANTHOR_DEBUGFS_GEM_USAGE_KERNEL_BIT = 0,
|
|
|
|
PANTHOR_DEBUGFS_GEM_USAGE_FW_MAPPED_BIT = 1,
|
|
|
|
|
|
|
|
/** @PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL: BO is for kernel use only. */
|
|
|
|
PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL = BIT(PANTHOR_DEBUGFS_GEM_USAGE_KERNEL_BIT),
|
|
|
|
|
|
|
|
/** @PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED: BO is mapped on the FW VM. */
|
|
|
|
PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED = BIT(PANTHOR_DEBUGFS_GEM_USAGE_FW_MAPPED_BIT),
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct panthor_gem_debugfs - GEM object's DebugFS list information
|
|
|
|
*/
|
|
|
|
struct panthor_gem_debugfs {
|
|
|
|
/**
|
|
|
|
* @node: Node used to insert the object in the device-wide list of
|
|
|
|
* GEM objects, to display information about it through a DebugFS file.
|
|
|
|
*/
|
|
|
|
struct list_head node;
|
|
|
|
|
|
|
|
/** @creator: Information about the UM process which created the GEM. */
|
|
|
|
struct {
|
|
|
|
/** @creator.process_name: Group leader name in owning thread's process */
|
|
|
|
char process_name[TASK_COMM_LEN];
|
|
|
|
|
|
|
|
/** @creator.tgid: PID of the thread's group leader within its process */
|
|
|
|
pid_t tgid;
|
|
|
|
} creator;
|
|
|
|
|
|
|
|
/** @flags: Combination of panthor_debugfs_gem_usage_flags flags */
|
|
|
|
u32 flags;
|
|
|
|
};
|
|
|
|
|
2024-02-29 17:22:19 +01:00
|
|
|
/**
|
|
|
|
* struct panthor_gem_object - Driver specific GEM object.
|
|
|
|
*/
|
|
|
|
struct panthor_gem_object {
|
|
|
|
/** @base: Inherit from drm_gem_shmem_object. */
|
|
|
|
struct drm_gem_shmem_object base;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @exclusive_vm_root_gem: Root GEM of the exclusive VM this GEM object
|
|
|
|
* is attached to.
|
|
|
|
*
|
|
|
|
* If @exclusive_vm_root_gem != NULL, any attempt to bind the GEM to a
|
|
|
|
* different VM will fail.
|
|
|
|
*
|
|
|
|
* All FW memory objects have this field set to the root GEM of the MCU
|
|
|
|
* VM.
|
|
|
|
*/
|
|
|
|
struct drm_gem_object *exclusive_vm_root_gem;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @gpuva_list_lock: Custom GPUVA lock.
|
|
|
|
*
|
|
|
|
* Used to protect insertion of drm_gpuva elements to the
|
|
|
|
* drm_gem_object.gpuva.list list.
|
|
|
|
*
|
|
|
|
* We can't use the GEM resv for that, because drm_gpuva_link() is
|
|
|
|
* called in a dma-signaling path, where we're not allowed to take
|
|
|
|
* resv locks.
|
|
|
|
*/
|
|
|
|
struct mutex gpuva_list_lock;
|
|
|
|
|
|
|
|
/** @flags: Combination of drm_panthor_bo_flags flags. */
|
|
|
|
u32 flags;
|
2025-04-23 03:12:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @label: BO tagging fields. The label can be assigned within the
|
|
|
|
* driver itself or through a specific IOCTL.
|
|
|
|
*/
|
|
|
|
struct {
|
|
|
|
/**
|
|
|
|
* @label.str: Pointer to NULL-terminated string,
|
|
|
|
*/
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
/** @lock.str: Protects access to the @label.str field. */
|
|
|
|
struct mutex lock;
|
|
|
|
} label;
|
drm/panthor: show device-wide list of DRM GEM objects over DebugFS
Add a device DebugFS file that displays a complete list of all the DRM
GEM objects that are exposed to UM through a DRM handle.
Since leaking object identifiers that might belong to a different NS is
inadmissible, this functionality is only made available in debug builds
with DEBUGFS support enabled.
File format is that of a table, with each entry displaying a variety of
fields with information about each GEM object.
Each GEM object entry in the file displays the following information
fields: Client PID, BO's global name, reference count, BO virtual size,
BO resize size, VM address in its DRM-managed range, BO label and a GEM
state flags.
There's also a usage flags field for the type of BO, which tells us
whether it's a kernel BO and/or mapped onto the FW's address space.
GEM state and usage flag meanings are printed in the file prelude, so
that UM parsing tools can interpret the numerical values in the table.
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Link: https://lore.kernel.org/r/20250423021238.1639175-5-adrian.larumbe@collabora.com
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2025-04-23 03:12:34 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
struct panthor_gem_debugfs debugfs;
|
|
|
|
#endif
|
2024-02-29 17:22:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct panthor_kernel_bo - Kernel buffer object.
|
|
|
|
*
|
|
|
|
* These objects are only manipulated by the kernel driver and not
|
|
|
|
* directly exposed to the userspace. The GPU address of a kernel
|
|
|
|
* BO might be passed to userspace though.
|
|
|
|
*/
|
|
|
|
struct panthor_kernel_bo {
|
|
|
|
/**
|
|
|
|
* @obj: The GEM object backing this kernel buffer object.
|
|
|
|
*/
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
|
2024-05-02 20:38:10 +02:00
|
|
|
/**
|
|
|
|
* @vm: VM this private buffer is attached to.
|
|
|
|
*/
|
|
|
|
struct panthor_vm *vm;
|
|
|
|
|
2024-02-29 17:22:19 +01:00
|
|
|
/**
|
|
|
|
* @va_node: VA space allocated to this GEM.
|
|
|
|
*/
|
|
|
|
struct drm_mm_node va_node;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @kmap: Kernel CPU mapping of @gem.
|
|
|
|
*/
|
|
|
|
void *kmap;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline
|
|
|
|
struct panthor_gem_object *to_panthor_bo(struct drm_gem_object *obj)
|
|
|
|
{
|
|
|
|
return container_of(to_drm_gem_shmem_obj(obj), struct panthor_gem_object, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_t size);
|
|
|
|
|
|
|
|
int
|
|
|
|
panthor_gem_create_with_handle(struct drm_file *file,
|
|
|
|
struct drm_device *ddev,
|
|
|
|
struct panthor_vm *exclusive_vm,
|
|
|
|
u64 *size, u32 flags, uint32_t *handle);
|
|
|
|
|
2025-04-23 03:12:31 +01:00
|
|
|
void panthor_gem_bo_set_label(struct drm_gem_object *obj, const char *label);
|
|
|
|
void panthor_gem_kernel_bo_set_label(struct panthor_kernel_bo *bo, const char *label);
|
|
|
|
|
2024-02-29 17:22:19 +01:00
|
|
|
static inline u64
|
|
|
|
panthor_kernel_bo_gpuva(struct panthor_kernel_bo *bo)
|
|
|
|
{
|
|
|
|
return bo->va_node.start;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t
|
|
|
|
panthor_kernel_bo_size(struct panthor_kernel_bo *bo)
|
|
|
|
{
|
|
|
|
return bo->obj->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
panthor_kernel_bo_vmap(struct panthor_kernel_bo *bo)
|
|
|
|
{
|
|
|
|
struct iosys_map map;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (bo->kmap)
|
|
|
|
return 0;
|
|
|
|
|
2025-03-23 00:25:59 +03:00
|
|
|
ret = drm_gem_vmap(bo->obj, &map);
|
2024-02-29 17:22:19 +01:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
bo->kmap = map.vaddr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
panthor_kernel_bo_vunmap(struct panthor_kernel_bo *bo)
|
|
|
|
{
|
|
|
|
if (bo->kmap) {
|
|
|
|
struct iosys_map map = IOSYS_MAP_INIT_VADDR(bo->kmap);
|
|
|
|
|
2025-03-23 00:25:59 +03:00
|
|
|
drm_gem_vunmap(bo->obj, &map);
|
2024-02-29 17:22:19 +01:00
|
|
|
bo->kmap = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct panthor_kernel_bo *
|
|
|
|
panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
|
|
|
|
size_t size, u32 bo_flags, u32 vm_map_flags,
|
2025-04-23 03:12:33 +01:00
|
|
|
u64 gpu_va, const char *name);
|
2024-02-29 17:22:19 +01:00
|
|
|
|
2024-05-02 20:38:10 +02:00
|
|
|
void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo);
|
2024-02-29 17:22:19 +01:00
|
|
|
|
drm/panthor: show device-wide list of DRM GEM objects over DebugFS
Add a device DebugFS file that displays a complete list of all the DRM
GEM objects that are exposed to UM through a DRM handle.
Since leaking object identifiers that might belong to a different NS is
inadmissible, this functionality is only made available in debug builds
with DEBUGFS support enabled.
File format is that of a table, with each entry displaying a variety of
fields with information about each GEM object.
Each GEM object entry in the file displays the following information
fields: Client PID, BO's global name, reference count, BO virtual size,
BO resize size, VM address in its DRM-managed range, BO label and a GEM
state flags.
There's also a usage flags field for the type of BO, which tells us
whether it's a kernel BO and/or mapped onto the FW's address space.
GEM state and usage flag meanings are printed in the file prelude, so
that UM parsing tools can interpret the numerical values in the table.
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Link: https://lore.kernel.org/r/20250423021238.1639175-5-adrian.larumbe@collabora.com
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2025-04-23 03:12:34 +01:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
void panthor_gem_debugfs_print_bos(struct panthor_device *pfdev,
|
|
|
|
struct seq_file *m);
|
|
|
|
#endif
|
|
|
|
|
2024-02-29 17:22:19 +01:00
|
|
|
#endif /* __PANTHOR_GEM_H__ */
|