2 * Copyright © 2014 Broadcom
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #ifdef USE_VC4_SIMULATOR
29 vc4_cl_validate(struct drm_device
*dev
, struct vc4_exec_info
*exec
)
31 struct drm_vc4_submit_cl
*args
= exec
->args
;
35 uint32_t bin_offset
= 0;
36 uint32_t render_offset
= bin_offset
+ args
->bin_cl_size
;
37 uint32_t shader_rec_offset
= roundup(render_offset
+
38 args
->render_cl_size
, 16);
39 uint32_t uniforms_offset
= shader_rec_offset
+ args
->shader_rec_size
;
40 uint32_t exec_size
= uniforms_offset
+ args
->uniforms_size
;
41 uint32_t temp_size
= exec_size
+ (sizeof(struct vc4_shader_state
) *
42 args
->shader_rec_count
);
44 if (shader_rec_offset
< render_offset
||
45 uniforms_offset
< shader_rec_offset
||
46 exec_size
< uniforms_offset
||
47 args
->shader_rec_count
>= (UINT_MAX
/
48 sizeof(struct vc4_shader_state
)) ||
49 temp_size
< exec_size
) {
50 DRM_ERROR("overflow in exec arguments\n");
54 /* Allocate space where we'll store the copied in user command lists
57 * We don't just copy directly into the BOs because we need to
58 * read the contents back for validation, and I think the
59 * bo->vaddr is uncached access.
61 temp
= kmalloc(temp_size
, GFP_KERNEL
);
63 DRM_ERROR("Failed to allocate storage for copying "
64 "in bin/render CLs.\n");
68 bin
= temp
+ bin_offset
;
69 render
= temp
+ render_offset
;
70 exec
->shader_rec_u
= temp
+ shader_rec_offset
;
71 exec
->uniforms_u
= temp
+ uniforms_offset
;
72 exec
->shader_state
= temp
+ exec_size
;
73 exec
->shader_state_size
= args
->shader_rec_count
;
75 ret
= copy_from_user(bin
,
76 (void __user
*)(uintptr_t)args
->bin_cl
,
79 DRM_ERROR("Failed to copy in bin cl\n");
83 ret
= copy_from_user(render
,
84 (void __user
*)(uintptr_t)args
->render_cl
,
85 args
->render_cl_size
);
87 DRM_ERROR("Failed to copy in render cl\n");
91 ret
= copy_from_user(exec
->shader_rec_u
,
92 (void __user
*)(uintptr_t)args
->shader_rec
,
93 args
->shader_rec_size
);
95 DRM_ERROR("Failed to copy in shader recs\n");
99 ret
= copy_from_user(exec
->uniforms_u
,
100 (void __user
*)(uintptr_t)args
->uniforms
,
101 args
->uniforms_size
);
103 DRM_ERROR("Failed to copy in uniforms cl\n");
107 exec
->exec_bo
= drm_gem_cma_create(dev
, exec_size
);
109 if (IS_ERR(exec
->exec_bo
)) {
110 DRM_ERROR("Couldn't allocate BO for exec\n");
111 ret
= PTR_ERR(exec
->exec_bo
);
112 exec
->exec_bo
= NULL
;
117 exec
->ct0ca
= exec
->exec_bo
->paddr
+ bin_offset
;
118 exec
->ct1ca
= exec
->exec_bo
->paddr
+ render_offset
;
120 exec
->shader_rec_v
= exec
->exec_bo
->vaddr
+ shader_rec_offset
;
121 exec
->shader_rec_p
= exec
->exec_bo
->paddr
+ shader_rec_offset
;
122 exec
->shader_rec_size
= args
->shader_rec_size
;
124 exec
->uniforms_v
= exec
->exec_bo
->vaddr
+ uniforms_offset
;
125 exec
->uniforms_p
= exec
->exec_bo
->paddr
+ uniforms_offset
;
126 exec
->uniforms_size
= args
->uniforms_size
;
128 ret
= vc4_validate_cl(dev
,
129 exec
->exec_bo
->vaddr
+ bin_offset
,
133 args
->bin_cl_size
!= 0,
138 ret
= vc4_validate_cl(dev
,
139 exec
->exec_bo
->vaddr
+ render_offset
,
141 args
->render_cl_size
,
143 args
->bin_cl_size
!= 0,
148 ret
= vc4_validate_shader_recs(dev
, exec
);
155 #endif /* USE_VC4_SIMULATOR */