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 * Copies in the user's binning command list and generates the validated bin
30 * CL, along with associated data (shader records, uniforms).
33 vc4_get_bcl(struct drm_device
*dev
, struct vc4_exec_info
*exec
)
35 struct drm_vc4_submit_cl
*args
= exec
->args
;
39 uint32_t bin_offset
= 0;
40 uint32_t shader_rec_offset
= roundup(bin_offset
+ args
->bin_cl_size
,
42 uint32_t uniforms_offset
= shader_rec_offset
+ args
->shader_rec_size
;
43 uint32_t exec_size
= uniforms_offset
+ args
->uniforms_size
;
44 uint32_t temp_size
= exec_size
+ (sizeof(struct vc4_shader_state
) *
45 args
->shader_rec_count
);
47 if (uniforms_offset
< shader_rec_offset
||
48 exec_size
< uniforms_offset
||
49 args
->shader_rec_count
>= (UINT_MAX
/
50 sizeof(struct vc4_shader_state
)) ||
51 temp_size
< exec_size
) {
52 DRM_ERROR("overflow in exec arguments\n");
56 /* Allocate space where we'll store the copied in user command lists
59 * We don't just copy directly into the BOs because we need to
60 * read the contents back for validation, and I think the
61 * bo->vaddr is uncached access.
63 temp
= kmalloc(temp_size
, GFP_KERNEL
);
65 DRM_ERROR("Failed to allocate storage for copying "
66 "in bin/render CLs.\n");
70 bin
= temp
+ bin_offset
;
71 exec
->shader_rec_u
= temp
+ shader_rec_offset
;
72 exec
->uniforms_u
= temp
+ uniforms_offset
;
73 exec
->shader_state
= temp
+ exec_size
;
74 exec
->shader_state_size
= args
->shader_rec_count
;
76 ret
= copy_from_user(bin
,
77 (void __user
*)(uintptr_t)args
->bin_cl
,
80 DRM_ERROR("Failed to copy in bin cl\n");
84 ret
= copy_from_user(exec
->shader_rec_u
,
85 (void __user
*)(uintptr_t)args
->shader_rec
,
86 args
->shader_rec_size
);
88 DRM_ERROR("Failed to copy in shader recs\n");
92 ret
= copy_from_user(exec
->uniforms_u
,
93 (void __user
*)(uintptr_t)args
->uniforms
,
96 DRM_ERROR("Failed to copy in uniforms cl\n");
100 exec
->exec_bo
= drm_gem_cma_create(dev
, exec_size
);
102 if (IS_ERR(exec
->exec_bo
)) {
103 DRM_ERROR("Couldn't allocate BO for exec\n");
104 ret
= PTR_ERR(exec
->exec_bo
);
105 exec
->exec_bo
= NULL
;
110 list_addtail(&to_vc4_bo(&exec
->exec_bo
->base
)->unref_head
,
113 exec
->ct0ca
= exec
->exec_bo
->paddr
+ bin_offset
;
115 exec
->shader_rec_v
= exec
->exec_bo
->vaddr
+ shader_rec_offset
;
116 exec
->shader_rec_p
= exec
->exec_bo
->paddr
+ shader_rec_offset
;
117 exec
->shader_rec_size
= args
->shader_rec_size
;
119 exec
->uniforms_v
= exec
->exec_bo
->vaddr
+ uniforms_offset
;
120 exec
->uniforms_p
= exec
->exec_bo
->paddr
+ uniforms_offset
;
121 exec
->uniforms_size
= args
->uniforms_size
;
123 ret
= vc4_validate_bin_cl(dev
,
124 exec
->exec_bo
->vaddr
+ bin_offset
,
130 ret
= vc4_validate_shader_recs(dev
, exec
);
138 vc4_cl_validate(struct drm_device
*dev
, struct vc4_exec_info
*exec
)
142 if (exec
->args
->bin_cl_size
!= 0) {
143 ret
= vc4_get_bcl(dev
, exec
);
147 exec
->ct0ca
= exec
->ct0ea
= 0;
150 ret
= vc4_get_rcl(dev
, exec
);
158 #endif /* USE_VC4_SIMULATOR */