1 /* SPDX-License-Identifier: GPL-2.0 or MIT */
3 /* Copyright 2023 Collabora ltd. */
5 #ifndef __PANTHOR_GEM_H__
6 #define __PANTHOR_GEM_H__
8 #include <drm/drm_gem_shmem_helper.h>
9 #include <drm/drm_mm.h>
11 #include <linux/iosys-map.h>
12 #include <linux/rwsem.h>
17 * struct panthor_gem_object - Driver specific GEM object.
19 struct panthor_gem_object {
20 /** @base: Inherit from drm_gem_shmem_object. */
21 struct drm_gem_shmem_object base;
24 * @exclusive_vm_root_gem: Root GEM of the exclusive VM this GEM object
27 * If @exclusive_vm_root_gem != NULL, any attempt to bind the GEM to a
28 * different VM will fail.
30 * All FW memory objects have this field set to the root GEM of the MCU
33 struct drm_gem_object *exclusive_vm_root_gem;
36 * @gpuva_list_lock: Custom GPUVA lock.
38 * Used to protect insertion of drm_gpuva elements to the
39 * drm_gem_object.gpuva.list list.
41 * We can't use the GEM resv for that, because drm_gpuva_link() is
42 * called in a dma-signaling path, where we're not allowed to take
45 struct mutex gpuva_list_lock;
47 /** @flags: Combination of drm_panthor_bo_flags flags. */
52 * struct panthor_kernel_bo - Kernel buffer object.
54 * These objects are only manipulated by the kernel driver and not
55 * directly exposed to the userspace. The GPU address of a kernel
56 * BO might be passed to userspace though.
58 struct panthor_kernel_bo {
60 * @obj: The GEM object backing this kernel buffer object.
62 struct drm_gem_object *obj;
65 * @va_node: VA space allocated to this GEM.
67 struct drm_mm_node va_node;
70 * @kmap: Kernel CPU mapping of @gem.
76 struct panthor_gem_object *to_panthor_bo(struct drm_gem_object *obj)
78 return container_of(to_drm_gem_shmem_obj(obj), struct panthor_gem_object, base);
81 struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_t size);
83 struct drm_gem_object *
84 panthor_gem_prime_import_sg_table(struct drm_device *ddev,
85 struct dma_buf_attachment *attach,
86 struct sg_table *sgt);
89 panthor_gem_create_with_handle(struct drm_file *file,
90 struct drm_device *ddev,
91 struct panthor_vm *exclusive_vm,
92 u64 *size, u32 flags, uint32_t *handle);
95 panthor_kernel_bo_gpuva(struct panthor_kernel_bo *bo)
97 return bo->va_node.start;
101 panthor_kernel_bo_size(struct panthor_kernel_bo *bo)
103 return bo->obj->size;
107 panthor_kernel_bo_vmap(struct panthor_kernel_bo *bo)
109 struct iosys_map map;
115 ret = drm_gem_vmap_unlocked(bo->obj, &map);
119 bo->kmap = map.vaddr;
124 panthor_kernel_bo_vunmap(struct panthor_kernel_bo *bo)
127 struct iosys_map map = IOSYS_MAP_INIT_VADDR(bo->kmap);
129 drm_gem_vunmap_unlocked(bo->obj, &map);
134 struct panthor_kernel_bo *
135 panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
136 size_t size, u32 bo_flags, u32 vm_map_flags,
139 void panthor_kernel_bo_destroy(struct panthor_vm *vm,
140 struct panthor_kernel_bo *bo);
142 #endif /* __PANTHOR_GEM_H__ */