-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnx_gem_submit.c
90 lines (75 loc) · 2.3 KB
/
dnx_gem_submit.c
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
#include "dnx_gem.h"
#include <drm/drm_gem.h>
#include <drm/drm_gem_cma_helper.h>
#include "dnx_gpu.h"
int dnx_ioctl_gem_submit(struct drm_device *dev, void *data,
struct drm_file *file)
{
struct dnx_device *dnx = dev->dev_private;
struct drm_dnx_stream_submit *args = data;
u32 *handles;
struct drm_gem_cma_object **bos = NULL;
struct dnx_cmdbuf *cmdbuf;
struct drm_gem_cma_object *last_page;
dma_addr_t stream_addr;
void* stream_jmpaddr;
int ret, i;
dev_dbg(dev->dev, "Submitting stream:\n");
dev_dbg(dev->dev, " paddr=0x%08llx\n", args->stream);
dev_dbg(dev->dev, " pjmpaddr=0x%08llx\n", args->jump);
dev_dbg(dev->dev, " nr_bo=%d\n", args->nr_bos);
dev_dbg(dev->dev, " bos=0x%08llx\n", args->bos);
if(args->nr_bos == 0)
return -EINVAL;
handles = drm_malloc_ab(args->nr_bos, sizeof(*handles));
bos = drm_malloc_ab(args->nr_bos, sizeof(*bos));
cmdbuf = dnx_gpu_cmdbuf_new(dnx, args->nr_bos);
if(!handles || !bos || !cmdbuf) {
ret = -ENOMEM;
goto error_handles;
}
ret = copy_from_user(handles, u64_to_user_ptr(args->bos),
args->nr_bos * sizeof(*handles));
if(ret) {
ret = -EFAULT;
goto error_handles;
}
ret = dnx_gpu_cmdbuf_lookup_objects(cmdbuf, file, handles, args->nr_bos);
if(ret)
goto error_handles;
/* todo: remove when offset is computed in userspace */
stream_addr = args->stream;
/* Check if address of last jump lies within stream */
for(i = 0; i < cmdbuf->nr_bos; ++i) {
if((args->jump > cmdbuf->bos[i]->paddr) &&
(args->jump < (cmdbuf->bos[i]->paddr + cmdbuf->bos[i]->base.size))) {
break;
}
}
if(i == cmdbuf->nr_bos) {
dev_err(dev->dev,
"Error in stream data. Given jump address 0x%llx is not"
" within stream.\n",
args->jump);
ret = -EFAULT;
goto error_handles;
}
last_page = cmdbuf->bos[i];
stream_jmpaddr = (void*) (last_page->vaddr + (args->jump - last_page->paddr));
cmdbuf->paddr = stream_addr;
cmdbuf->vjmpaddr = stream_jmpaddr;
dev_dbg(dev->dev, " pstreamaddr=0x%08x vjmpaddr=0x%p\n", stream_addr, stream_jmpaddr);
ret = dnx_gpu_submit(dev->dev_private, cmdbuf);
args->fence = cmdbuf->fence;
if(ret == 0)
cmdbuf = NULL;
error_handles:
/* if we still own the cmdbuf, we came here due to an error */
if(cmdbuf)
dnx_gpu_cmdbuf_free(cmdbuf);
if(handles)
drm_free_large(handles);
if(bos)
drm_free_large(bos);
return ret;
}