Skip to content

Commit 647371a

Browse files
jlawrynodanvet
authored andcommitted
accel/ivpu: Add GEM buffer object management
Adds four types of GEM-based BOs for the VPU: - shmem - internal - prime All types are implemented as struct ivpu_bo, based on struct drm_gem_object. VPU address is allocated when buffer is created except for imported prime buffers that allocate it in BO_INFO IOCTL due to missing file_priv arg in gem_prime_import callback. Internal buffers are pinned on creation, the rest of buffers types can be pinned on demand (in SUBMIT IOCTL). Buffer VPU address, allocated pages and mappings are released when the buffer is destroyed. Eviction mechanism is planned for future versions. Add two new IOCTLs: BO_CREATE, BO_INFO Signed-off-by: Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com> Reviewed-by: Oded Gabbay <ogabbay@kernel.org> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20230117092723.60441-4-jacek.lawrynowicz@linux.intel.com
1 parent 263b2ba commit 647371a

File tree

6 files changed

+977
-2
lines changed

6 files changed

+977
-2
lines changed

drivers/accel/ivpu/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
intel_vpu-y := \
55
ivpu_drv.o \
6+
ivpu_gem.o \
67
ivpu_hw_mtl.o \
78
ivpu_mmu.o \
89
ivpu_mmu_context.o

drivers/accel/ivpu/ivpu_drv.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
#include <drm/drm_file.h>
1313
#include <drm/drm_gem.h>
1414
#include <drm/drm_ioctl.h>
15+
#include <drm/drm_prime.h>
1516

1617
#include "ivpu_drv.h"
18+
#include "ivpu_gem.h"
1719
#include "ivpu_hw.h"
1820
#include "ivpu_mmu.h"
1921
#include "ivpu_mmu_context.h"
@@ -49,6 +51,24 @@ struct ivpu_file_priv *ivpu_file_priv_get(struct ivpu_file_priv *file_priv)
4951
return file_priv;
5052
}
5153

54+
struct ivpu_file_priv *ivpu_file_priv_get_by_ctx_id(struct ivpu_device *vdev, unsigned long id)
55+
{
56+
struct ivpu_file_priv *file_priv;
57+
58+
xa_lock_irq(&vdev->context_xa);
59+
file_priv = xa_load(&vdev->context_xa, id);
60+
/* file_priv may still be in context_xa during file_priv_release() */
61+
if (file_priv && !kref_get_unless_zero(&file_priv->ref))
62+
file_priv = NULL;
63+
xa_unlock_irq(&vdev->context_xa);
64+
65+
if (file_priv)
66+
ivpu_dbg(vdev, KREF, "file_priv get by id: ctx %u refcount %u\n",
67+
file_priv->ctx.id, kref_read(&file_priv->ref));
68+
69+
return file_priv;
70+
}
71+
5272
static void file_priv_release(struct kref *ref)
5373
{
5474
struct ivpu_file_priv *file_priv = container_of(ref, struct ivpu_file_priv, ref);
@@ -57,7 +77,7 @@ static void file_priv_release(struct kref *ref)
5777
ivpu_dbg(vdev, FILE, "file_priv release: ctx %u\n", file_priv->ctx.id);
5878

5979
ivpu_mmu_user_context_fini(vdev, &file_priv->ctx);
60-
WARN_ON(xa_erase_irq(&vdev->context_xa, file_priv->ctx.id) != file_priv);
80+
drm_WARN_ON(&vdev->drm, xa_erase_irq(&vdev->context_xa, file_priv->ctx.id) != file_priv);
6181
kfree(file_priv);
6282
}
6383

@@ -66,7 +86,7 @@ void ivpu_file_priv_put(struct ivpu_file_priv **link)
6686
struct ivpu_file_priv *file_priv = *link;
6787
struct ivpu_device *vdev = file_priv->vdev;
6888

69-
WARN_ON(!file_priv);
89+
drm_WARN_ON(&vdev->drm, !file_priv);
7090

7191
ivpu_dbg(vdev, KREF, "file_priv put: ctx %u refcount %u\n",
7292
file_priv->ctx.id, kref_read(&file_priv->ref));
@@ -200,6 +220,8 @@ static void ivpu_postclose(struct drm_device *dev, struct drm_file *file)
200220
static const struct drm_ioctl_desc ivpu_drm_ioctls[] = {
201221
DRM_IOCTL_DEF_DRV(IVPU_GET_PARAM, ivpu_get_param_ioctl, 0),
202222
DRM_IOCTL_DEF_DRV(IVPU_SET_PARAM, ivpu_set_param_ioctl, 0),
223+
DRM_IOCTL_DEF_DRV(IVPU_BO_CREATE, ivpu_bo_create_ioctl, 0),
224+
DRM_IOCTL_DEF_DRV(IVPU_BO_INFO, ivpu_bo_info_ioctl, 0),
203225
};
204226

205227
int ivpu_shutdown(struct ivpu_device *vdev)
@@ -227,6 +249,10 @@ static const struct drm_driver driver = {
227249

228250
.open = ivpu_open,
229251
.postclose = ivpu_postclose,
252+
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
253+
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
254+
.gem_prime_import = ivpu_gem_prime_import,
255+
.gem_prime_mmap = drm_gem_prime_mmap,
230256

231257
.ioctls = ivpu_drm_ioctls,
232258
.num_ioctls = ARRAY_SIZE(ivpu_drm_ioctls),

drivers/accel/ivpu/ivpu_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ extern u8 ivpu_pll_min_ratio;
115115
extern u8 ivpu_pll_max_ratio;
116116

117117
struct ivpu_file_priv *ivpu_file_priv_get(struct ivpu_file_priv *file_priv);
118+
struct ivpu_file_priv *ivpu_file_priv_get_by_ctx_id(struct ivpu_device *vdev, unsigned long id);
118119
void ivpu_file_priv_put(struct ivpu_file_priv **link);
119120
int ivpu_shutdown(struct ivpu_device *vdev);
120121

0 commit comments

Comments
 (0)