Skip to content

Commit

Permalink
drm/tegra: Implement job submission part of new UAPI
Browse files Browse the repository at this point in the history
Implement the job submission IOCTL with a minimum feature set.

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
  • Loading branch information
cyndis authored and intel-lab-lkp committed Nov 20, 2020
1 parent 2b3b622 commit d5a3a65
Show file tree
Hide file tree
Showing 6 changed files with 552 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/gpu/drm/tegra/Makefile
Expand Up @@ -4,6 +4,8 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
tegra-drm-y := \
drm.o \
uapi/uapi.o \
uapi/submit.o \
uapi/gather_bo.o \
gem.o \
fb.o \
dp.o \
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/tegra/drm.c
Expand Up @@ -740,6 +740,8 @@ static const struct drm_ioctl_desc tegra_drm_ioctls[] = {
DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(TEGRA_CHANNEL_UNMAP, tegra_drm_ioctl_channel_unmap,
DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(TEGRA_CHANNEL_SUBMIT, tegra_drm_ioctl_channel_submit,
DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(TEGRA_GEM_CREATE, tegra_drm_ioctl_gem_create,
DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP, tegra_drm_ioctl_gem_mmap,
Expand Down
86 changes: 86 additions & 0 deletions drivers/gpu/drm/tegra/uapi/gather_bo.c
@@ -0,0 +1,86 @@
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2020 NVIDIA Corporation */

#include <linux/scatterlist.h>
#include <linux/slab.h>

#include "gather_bo.h"

static struct host1x_bo *gather_bo_get(struct host1x_bo *host_bo)
{
struct gather_bo *bo = container_of(host_bo, struct gather_bo, base);

kref_get(&bo->ref);

return host_bo;
}

static void gather_bo_release(struct kref *ref)
{
struct gather_bo *bo = container_of(ref, struct gather_bo, ref);

kfree(bo->gather_data);
kfree(bo);
}

void gather_bo_put(struct host1x_bo *host_bo)
{
struct gather_bo *bo = container_of(host_bo, struct gather_bo, base);

kref_put(&bo->ref, gather_bo_release);
}

static struct sg_table *
gather_bo_pin(struct device *dev, struct host1x_bo *host_bo, dma_addr_t *phys)
{
struct gather_bo *bo = container_of(host_bo, struct gather_bo, base);
struct sg_table *sgt;
int err;

if (phys) {
*phys = virt_to_phys(bo->gather_data);
return NULL;
}

sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
if (!sgt)
return ERR_PTR(-ENOMEM);

err = sg_alloc_table(sgt, 1, GFP_KERNEL);
if (err) {
kfree(sgt);
return ERR_PTR(err);
}

sg_init_one(sgt->sgl, bo->gather_data, bo->gather_data_words*4);

return sgt;
}

static void gather_bo_unpin(struct device *dev, struct sg_table *sgt)
{
if (sgt) {
sg_free_table(sgt);
kfree(sgt);
}
}

static void *gather_bo_mmap(struct host1x_bo *host_bo)
{
struct gather_bo *bo = container_of(host_bo, struct gather_bo, base);

return bo->gather_data;
}

static void gather_bo_munmap(struct host1x_bo *host_bo, void *addr)
{
}

const struct host1x_bo_ops gather_bo_ops = {
.get = gather_bo_get,
.put = gather_bo_put,
.pin = gather_bo_pin,
.unpin = gather_bo_unpin,
.mmap = gather_bo_mmap,
.munmap = gather_bo_munmap,
};
22 changes: 22 additions & 0 deletions drivers/gpu/drm/tegra/uapi/gather_bo.h
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (c) 2020 NVIDIA Corporation */

#ifndef _TEGRA_DRM_SUBMIT_GATHER_BO_H
#define _TEGRA_DRM_SUBMIT_GATHER_BO_H

#include <linux/host1x.h>
#include <linux/kref.h>

struct gather_bo {
struct host1x_bo base;

struct kref ref;

u32 *gather_data;
size_t gather_data_words;
};

extern const struct host1x_bo_ops gather_bo_ops;
void gather_bo_put(struct host1x_bo *host_bo);

#endif

0 comments on commit d5a3a65

Please sign in to comment.