1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (C) 2020 Google, Inc */
#include "drm/drm_drv.h"
#include "msm_drv.h"
#include "msm_syncobj.h"
struct drm_syncobj **
msm_syncobj_parse_deps(struct drm_device *dev,
struct drm_sched_job *job,
struct drm_file *file,
uint64_t in_syncobjs_addr,
uint32_t nr_in_syncobjs,
size_t syncobj_stride)
{
struct drm_syncobj **syncobjs = NULL;
struct drm_msm_syncobj syncobj_desc = {0};
int ret = 0;
uint32_t i, j;
syncobjs = kcalloc(nr_in_syncobjs, sizeof(*syncobjs),
GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
if (!syncobjs)
return ERR_PTR(-ENOMEM);
for (i = 0; i < nr_in_syncobjs; ++i) {
uint64_t address = in_syncobjs_addr + i * syncobj_stride;
if (copy_from_user(&syncobj_desc,
u64_to_user_ptr(address),
min(syncobj_stride, sizeof(syncobj_desc)))) {
ret = -EFAULT;
break;
}
if (syncobj_desc.point &&
!drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE)) {
ret = UERR(EOPNOTSUPP, dev, "syncobj timeline unsupported");
break;
}
if (syncobj_desc.flags & ~MSM_SYNCOBJ_FLAGS) {
ret = UERR(EINVAL, dev, "invalid syncobj flags: %x", syncobj_desc.flags);
break;
}
ret = drm_sched_job_add_syncobj_dependency(job, file,
syncobj_desc.handle,
syncobj_desc.point);
if (ret)
break;
if (syncobj_desc.flags & MSM_SYNCOBJ_RESET) {
syncobjs[i] = drm_syncobj_find(file, syncobj_desc.handle);
if (!syncobjs[i]) {
ret = UERR(EINVAL, dev, "invalid syncobj handle: %u", i);
break;
}
}
}
if (ret) {
for (j = 0; j <= i; ++j) {
if (syncobjs[j])
drm_syncobj_put(syncobjs[j]);
}
kfree(syncobjs);
return ERR_PTR(ret);
}
return syncobjs;
}
void
msm_syncobj_reset(struct drm_syncobj **syncobjs, uint32_t nr_syncobjs)
{
uint32_t i;
for (i = 0; syncobjs && i < nr_syncobjs; ++i) {
if (syncobjs[i])
drm_syncobj_replace_fence(syncobjs[i], NULL);
}
}
struct msm_syncobj_post_dep *
msm_syncobj_parse_post_deps(struct drm_device *dev,
struct drm_file *file,
uint64_t syncobjs_addr,
uint32_t nr_syncobjs,
size_t syncobj_stride)
{
struct msm_syncobj_post_dep *post_deps;
struct drm_msm_syncobj syncobj_desc = {0};
int ret = 0;
uint32_t i, j;
post_deps = kcalloc(nr_syncobjs, sizeof(*post_deps),
GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
if (!post_deps)
return ERR_PTR(-ENOMEM);
for (i = 0; i < nr_syncobjs; ++i) {
uint64_t address = syncobjs_addr + i * syncobj_stride;
if (copy_from_user(&syncobj_desc,
u64_to_user_ptr(address),
min(syncobj_stride, sizeof(syncobj_desc)))) {
ret = -EFAULT;
break;
}
post_deps[i].point = syncobj_desc.point;
if (syncobj_desc.flags) {
ret = UERR(EINVAL, dev, "invalid syncobj flags");
break;
}
if (syncobj_desc.point) {
if (!drm_core_check_feature(dev,
DRIVER_SYNCOBJ_TIMELINE)) {
ret = UERR(EOPNOTSUPP, dev, "syncobj timeline unsupported");
break;
}
post_deps[i].chain = dma_fence_chain_alloc();
if (!post_deps[i].chain) {
ret = -ENOMEM;
break;
}
}
post_deps[i].syncobj =
drm_syncobj_find(file, syncobj_desc.handle);
if (!post_deps[i].syncobj) {
ret = UERR(EINVAL, dev, "invalid syncobj handle");
break;
}
}
if (ret) {
for (j = 0; j <= i; ++j) {
dma_fence_chain_free(post_deps[j].chain);
if (post_deps[j].syncobj)
drm_syncobj_put(post_deps[j].syncobj);
}
kfree(post_deps);
return ERR_PTR(ret);
}
return post_deps;
}
void
msm_syncobj_process_post_deps(struct msm_syncobj_post_dep *post_deps,
uint32_t count, struct dma_fence *fence)
{
uint32_t i;
for (i = 0; post_deps && i < count; ++i) {
if (post_deps[i].chain) {
drm_syncobj_add_point(post_deps[i].syncobj,
post_deps[i].chain,
fence, post_deps[i].point);
post_deps[i].chain = NULL;
} else {
drm_syncobj_replace_fence(post_deps[i].syncobj,
fence);
}
}
}
|