0119-drm-vc4-Synchronize-validation-code-for-v2-submissio.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. From 2181b6ab6f7cddcd5ca908007a14fde90cc8d2b1 Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Mon, 7 Dec 2015 12:35:01 -0800
  4. Subject: [PATCH 119/381] drm/vc4: Synchronize validation code for v2
  5. submission upstream.
  6. Signed-off-by: Eric Anholt <eric@anholt.net>
  7. ---
  8. drivers/gpu/drm/vc4/vc4_drv.h | 24 +--
  9. drivers/gpu/drm/vc4/vc4_gem.c | 14 +-
  10. drivers/gpu/drm/vc4/vc4_render_cl.c | 6 +-
  11. drivers/gpu/drm/vc4/vc4_validate.c | 287 +++++++++++++++---------------------
  12. 4 files changed, 135 insertions(+), 196 deletions(-)
  13. --- a/drivers/gpu/drm/vc4/vc4_drv.h
  14. +++ b/drivers/gpu/drm/vc4/vc4_drv.h
  15. @@ -189,17 +189,6 @@ to_vc4_encoder(struct drm_encoder *encod
  16. #define HVS_READ(offset) readl(vc4->hvs->regs + offset)
  17. #define HVS_WRITE(offset, val) writel(val, vc4->hvs->regs + offset)
  18. -enum vc4_bo_mode {
  19. - VC4_MODE_UNDECIDED,
  20. - VC4_MODE_RENDER,
  21. - VC4_MODE_SHADER,
  22. -};
  23. -
  24. -struct vc4_bo_exec_state {
  25. - struct drm_gem_cma_object *bo;
  26. - enum vc4_bo_mode mode;
  27. -};
  28. -
  29. struct vc4_exec_info {
  30. /* Sequence number for this bin/render job. */
  31. uint64_t seqno;
  32. @@ -210,7 +199,7 @@ struct vc4_exec_info {
  33. /* This is the array of BOs that were looked up at the start of exec.
  34. * Command validation will use indices into this array.
  35. */
  36. - struct vc4_bo_exec_state *bo;
  37. + struct drm_gem_cma_object **bo;
  38. uint32_t bo_count;
  39. /* Pointers for our position in vc4->job_list */
  40. @@ -238,7 +227,6 @@ struct vc4_exec_info {
  41. * command lists.
  42. */
  43. struct vc4_shader_state {
  44. - uint8_t packet;
  45. uint32_t addr;
  46. /* Maximum vertex index referenced by any primitive using this
  47. * shader state.
  48. @@ -254,6 +242,7 @@ struct vc4_exec_info {
  49. bool found_tile_binning_mode_config_packet;
  50. bool found_start_tile_binning_packet;
  51. bool found_increment_semaphore_packet;
  52. + bool found_flush;
  53. uint8_t bin_tiles_x, bin_tiles_y;
  54. struct drm_gem_cma_object *tile_bo;
  55. uint32_t tile_alloc_offset;
  56. @@ -265,6 +254,9 @@ struct vc4_exec_info {
  57. uint32_t ct0ca, ct0ea;
  58. uint32_t ct1ca, ct1ea;
  59. + /* Pointer to the unvalidated bin CL (if present). */
  60. + void *bin_u;
  61. +
  62. /* Pointers to the shader recs. These paddr gets incremented as CL
  63. * packets are relocated in validate_gl_shader_state, and the vaddrs
  64. * (u and v) get incremented and size decremented as the shader recs
  65. @@ -455,10 +447,8 @@ vc4_validate_bin_cl(struct drm_device *d
  66. int
  67. vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
  68. -bool vc4_use_bo(struct vc4_exec_info *exec,
  69. - uint32_t hindex,
  70. - enum vc4_bo_mode mode,
  71. - struct drm_gem_cma_object **obj);
  72. +struct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec,
  73. + uint32_t hindex);
  74. int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
  75. --- a/drivers/gpu/drm/vc4/vc4_gem.c
  76. +++ b/drivers/gpu/drm/vc4/vc4_gem.c
  77. @@ -169,8 +169,8 @@ vc4_save_hang_state(struct drm_device *d
  78. }
  79. for (i = 0; i < exec->bo_count; i++) {
  80. - drm_gem_object_reference(&exec->bo[i].bo->base);
  81. - kernel_state->bo[i] = &exec->bo[i].bo->base;
  82. + drm_gem_object_reference(&exec->bo[i]->base);
  83. + kernel_state->bo[i] = &exec->bo[i]->base;
  84. }
  85. list_for_each_entry(bo, &exec->unref_list, unref_head) {
  86. @@ -397,7 +397,7 @@ vc4_update_bo_seqnos(struct vc4_exec_inf
  87. unsigned i;
  88. for (i = 0; i < exec->bo_count; i++) {
  89. - bo = to_vc4_bo(&exec->bo[i].bo->base);
  90. + bo = to_vc4_bo(&exec->bo[i]->base);
  91. bo->seqno = seqno;
  92. }
  93. @@ -467,7 +467,7 @@ vc4_cl_lookup_bos(struct drm_device *dev
  94. return -EINVAL;
  95. }
  96. - exec->bo = kcalloc(exec->bo_count, sizeof(struct vc4_bo_exec_state),
  97. + exec->bo = kcalloc(exec->bo_count, sizeof(struct drm_gem_cma_object *),
  98. GFP_KERNEL);
  99. if (!exec->bo) {
  100. DRM_ERROR("Failed to allocate validated BO pointers\n");
  101. @@ -500,7 +500,7 @@ vc4_cl_lookup_bos(struct drm_device *dev
  102. goto fail;
  103. }
  104. drm_gem_object_reference(bo);
  105. - exec->bo[i].bo = (struct drm_gem_cma_object *)bo;
  106. + exec->bo[i] = (struct drm_gem_cma_object *)bo;
  107. }
  108. spin_unlock(&file_priv->table_lock);
  109. @@ -591,6 +591,8 @@ vc4_get_bcl(struct drm_device *dev, stru
  110. exec->ct0ca = exec->exec_bo->paddr + bin_offset;
  111. + exec->bin_u = bin;
  112. +
  113. exec->shader_rec_v = exec->exec_bo->vaddr + shader_rec_offset;
  114. exec->shader_rec_p = exec->exec_bo->paddr + shader_rec_offset;
  115. exec->shader_rec_size = args->shader_rec_size;
  116. @@ -622,7 +624,7 @@ vc4_complete_exec(struct drm_device *dev
  117. mutex_lock(&dev->struct_mutex);
  118. if (exec->bo) {
  119. for (i = 0; i < exec->bo_count; i++)
  120. - drm_gem_object_unreference(&exec->bo[i].bo->base);
  121. + drm_gem_object_unreference(&exec->bo[i]->base);
  122. kfree(exec->bo);
  123. }
  124. --- a/drivers/gpu/drm/vc4/vc4_render_cl.c
  125. +++ b/drivers/gpu/drm/vc4/vc4_render_cl.c
  126. @@ -436,7 +436,8 @@ static int vc4_rcl_surface_setup(struct
  127. if (surf->hindex == ~0)
  128. return 0;
  129. - if (!vc4_use_bo(exec, surf->hindex, VC4_MODE_RENDER, obj))
  130. + *obj = vc4_use_bo(exec, surf->hindex);
  131. + if (!*obj)
  132. return -EINVAL;
  133. if (surf->flags & VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES) {
  134. @@ -537,7 +538,8 @@ vc4_rcl_render_config_surface_setup(stru
  135. if (surf->hindex == ~0)
  136. return 0;
  137. - if (!vc4_use_bo(exec, surf->hindex, VC4_MODE_RENDER, obj))
  138. + *obj = vc4_use_bo(exec, surf->hindex);
  139. + if (!*obj)
  140. return -EINVAL;
  141. if (tiling > VC4_TILING_FORMAT_LT) {
  142. --- a/drivers/gpu/drm/vc4/vc4_validate.c
  143. +++ b/drivers/gpu/drm/vc4/vc4_validate.c
  144. @@ -94,42 +94,42 @@ size_is_lt(uint32_t width, uint32_t heig
  145. height <= 4 * utile_height(cpp));
  146. }
  147. -bool
  148. -vc4_use_bo(struct vc4_exec_info *exec,
  149. - uint32_t hindex,
  150. - enum vc4_bo_mode mode,
  151. - struct drm_gem_cma_object **obj)
  152. +struct drm_gem_cma_object *
  153. +vc4_use_bo(struct vc4_exec_info *exec, uint32_t hindex)
  154. {
  155. - *obj = NULL;
  156. + struct drm_gem_cma_object *obj;
  157. + struct vc4_bo *bo;
  158. if (hindex >= exec->bo_count) {
  159. DRM_ERROR("BO index %d greater than BO count %d\n",
  160. hindex, exec->bo_count);
  161. - return false;
  162. + return NULL;
  163. }
  164. + obj = exec->bo[hindex];
  165. + bo = to_vc4_bo(&obj->base);
  166. - if (exec->bo[hindex].mode != mode) {
  167. - if (exec->bo[hindex].mode == VC4_MODE_UNDECIDED) {
  168. - exec->bo[hindex].mode = mode;
  169. - } else {
  170. - DRM_ERROR("BO index %d reused with mode %d vs %d\n",
  171. - hindex, exec->bo[hindex].mode, mode);
  172. - return false;
  173. - }
  174. + if (bo->validated_shader) {
  175. + DRM_ERROR("Trying to use shader BO as something other than "
  176. + "a shader\n");
  177. + return NULL;
  178. }
  179. - *obj = exec->bo[hindex].bo;
  180. - return true;
  181. + return obj;
  182. +}
  183. +
  184. +static struct drm_gem_cma_object *
  185. +vc4_use_handle(struct vc4_exec_info *exec, uint32_t gem_handles_packet_index)
  186. +{
  187. + return vc4_use_bo(exec, exec->bo_index[gem_handles_packet_index]);
  188. }
  189. static bool
  190. -vc4_use_handle(struct vc4_exec_info *exec,
  191. - uint32_t gem_handles_packet_index,
  192. - enum vc4_bo_mode mode,
  193. - struct drm_gem_cma_object **obj)
  194. +validate_bin_pos(struct vc4_exec_info *exec, void *untrusted, uint32_t pos)
  195. {
  196. - return vc4_use_bo(exec, exec->bo_index[gem_handles_packet_index],
  197. - mode, obj);
  198. + /* Note that the untrusted pointer passed to these functions is
  199. + * incremented past the packet byte.
  200. + */
  201. + return (untrusted - 1 == exec->bin_u + pos);
  202. }
  203. static uint32_t
  204. @@ -202,13 +202,13 @@ vc4_check_tex_size(struct vc4_exec_info
  205. }
  206. static int
  207. -validate_flush_all(VALIDATE_ARGS)
  208. +validate_flush(VALIDATE_ARGS)
  209. {
  210. - if (exec->found_increment_semaphore_packet) {
  211. - DRM_ERROR("VC4_PACKET_FLUSH_ALL after "
  212. - "VC4_PACKET_INCREMENT_SEMAPHORE\n");
  213. + if (!validate_bin_pos(exec, untrusted, exec->args->bin_cl_size - 1)) {
  214. + DRM_ERROR("Bin CL must end with VC4_PACKET_FLUSH\n");
  215. return -EINVAL;
  216. }
  217. + exec->found_flush = true;
  218. return 0;
  219. }
  220. @@ -233,17 +233,13 @@ validate_start_tile_binning(VALIDATE_ARG
  221. static int
  222. validate_increment_semaphore(VALIDATE_ARGS)
  223. {
  224. - if (exec->found_increment_semaphore_packet) {
  225. - DRM_ERROR("Duplicate VC4_PACKET_INCREMENT_SEMAPHORE\n");
  226. + if (!validate_bin_pos(exec, untrusted, exec->args->bin_cl_size - 2)) {
  227. + DRM_ERROR("Bin CL must end with "
  228. + "VC4_PACKET_INCREMENT_SEMAPHORE\n");
  229. return -EINVAL;
  230. }
  231. exec->found_increment_semaphore_packet = true;
  232. - /* Once we've found the semaphore increment, there should be one FLUSH
  233. - * then the end of the command list. The FLUSH actually triggers the
  234. - * increment, so we only need to make sure there
  235. - */
  236. -
  237. return 0;
  238. }
  239. @@ -257,11 +253,6 @@ validate_indexed_prim_list(VALIDATE_ARGS
  240. uint32_t index_size = (*(uint8_t *)(untrusted + 0) >> 4) ? 2 : 1;
  241. struct vc4_shader_state *shader_state;
  242. - if (exec->found_increment_semaphore_packet) {
  243. - DRM_ERROR("Drawing after VC4_PACKET_INCREMENT_SEMAPHORE\n");
  244. - return -EINVAL;
  245. - }
  246. -
  247. /* Check overflow condition */
  248. if (exec->shader_state_count == 0) {
  249. DRM_ERROR("shader state must precede primitives\n");
  250. @@ -272,7 +263,8 @@ validate_indexed_prim_list(VALIDATE_ARGS
  251. if (max_index > shader_state->max_index)
  252. shader_state->max_index = max_index;
  253. - if (!vc4_use_handle(exec, 0, VC4_MODE_RENDER, &ib))
  254. + ib = vc4_use_handle(exec, 0);
  255. + if (!ib)
  256. return -EINVAL;
  257. if (offset > ib->base.size ||
  258. @@ -295,11 +287,6 @@ validate_gl_array_primitive(VALIDATE_ARG
  259. uint32_t max_index;
  260. struct vc4_shader_state *shader_state;
  261. - if (exec->found_increment_semaphore_packet) {
  262. - DRM_ERROR("Drawing after VC4_PACKET_INCREMENT_SEMAPHORE\n");
  263. - return -EINVAL;
  264. - }
  265. -
  266. /* Check overflow condition */
  267. if (exec->shader_state_count == 0) {
  268. DRM_ERROR("shader state must precede primitives\n");
  269. @@ -329,7 +316,6 @@ validate_gl_shader_state(VALIDATE_ARGS)
  270. return -EINVAL;
  271. }
  272. - exec->shader_state[i].packet = VC4_PACKET_GL_SHADER_STATE;
  273. exec->shader_state[i].addr = *(uint32_t *)untrusted;
  274. exec->shader_state[i].max_index = 0;
  275. @@ -348,31 +334,6 @@ validate_gl_shader_state(VALIDATE_ARGS)
  276. }
  277. static int
  278. -validate_nv_shader_state(VALIDATE_ARGS)
  279. -{
  280. - uint32_t i = exec->shader_state_count++;
  281. -
  282. - if (i >= exec->shader_state_size) {
  283. - DRM_ERROR("More requests for shader states than declared\n");
  284. - return -EINVAL;
  285. - }
  286. -
  287. - exec->shader_state[i].packet = VC4_PACKET_NV_SHADER_STATE;
  288. - exec->shader_state[i].addr = *(uint32_t *)untrusted;
  289. -
  290. - if (exec->shader_state[i].addr & 15) {
  291. - DRM_ERROR("NV shader state address 0x%08x misaligned\n",
  292. - exec->shader_state[i].addr);
  293. - return -EINVAL;
  294. - }
  295. -
  296. - *(uint32_t *)validated = (exec->shader_state[i].addr +
  297. - exec->shader_rec_p);
  298. -
  299. - return 0;
  300. -}
  301. -
  302. -static int
  303. validate_tile_binning_config(VALIDATE_ARGS)
  304. {
  305. struct drm_device *dev = exec->exec_bo->base.dev;
  306. @@ -473,8 +434,8 @@ static const struct cmd_info {
  307. } cmd_info[] = {
  308. VC4_DEFINE_PACKET(VC4_PACKET_HALT, NULL),
  309. VC4_DEFINE_PACKET(VC4_PACKET_NOP, NULL),
  310. - VC4_DEFINE_PACKET(VC4_PACKET_FLUSH, NULL),
  311. - VC4_DEFINE_PACKET(VC4_PACKET_FLUSH_ALL, validate_flush_all),
  312. + VC4_DEFINE_PACKET(VC4_PACKET_FLUSH, validate_flush),
  313. + VC4_DEFINE_PACKET(VC4_PACKET_FLUSH_ALL, NULL),
  314. VC4_DEFINE_PACKET(VC4_PACKET_START_TILE_BINNING,
  315. validate_start_tile_binning),
  316. VC4_DEFINE_PACKET(VC4_PACKET_INCREMENT_SEMAPHORE,
  317. @@ -488,7 +449,6 @@ static const struct cmd_info {
  318. VC4_DEFINE_PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT, NULL),
  319. VC4_DEFINE_PACKET(VC4_PACKET_GL_SHADER_STATE, validate_gl_shader_state),
  320. - VC4_DEFINE_PACKET(VC4_PACKET_NV_SHADER_STATE, validate_nv_shader_state),
  321. VC4_DEFINE_PACKET(VC4_PACKET_CONFIGURATION_BITS, NULL),
  322. VC4_DEFINE_PACKET(VC4_PACKET_FLAT_SHADE_FLAGS, NULL),
  323. @@ -575,8 +535,16 @@ vc4_validate_bin_cl(struct drm_device *d
  324. return -EINVAL;
  325. }
  326. - if (!exec->found_increment_semaphore_packet) {
  327. - DRM_ERROR("Bin CL missing VC4_PACKET_INCREMENT_SEMAPHORE\n");
  328. + /* The bin CL must be ended with INCREMENT_SEMAPHORE and FLUSH. The
  329. + * semaphore is used to trigger the render CL to start up, and the
  330. + * FLUSH is what caps the bin lists with
  331. + * VC4_PACKET_RETURN_FROM_SUB_LIST (so they jump back to the main
  332. + * render CL when they get called to) and actually triggers the queued
  333. + * semaphore increment.
  334. + */
  335. + if (!exec->found_increment_semaphore_packet || !exec->found_flush) {
  336. + DRM_ERROR("Bin CL missing VC4_PACKET_INCREMENT_SEMAPHORE + "
  337. + "VC4_PACKET_FLUSH\n");
  338. return -EINVAL;
  339. }
  340. @@ -607,7 +575,8 @@ reloc_tex(struct vc4_exec_info *exec,
  341. uint32_t cube_map_stride = 0;
  342. enum vc4_texture_data_type type;
  343. - if (!vc4_use_bo(exec, texture_handle_index, VC4_MODE_RENDER, &tex))
  344. + tex = vc4_use_bo(exec, texture_handle_index);
  345. + if (!tex)
  346. return false;
  347. if (sample->is_direct) {
  348. @@ -755,51 +724,28 @@ reloc_tex(struct vc4_exec_info *exec,
  349. }
  350. static int
  351. -validate_shader_rec(struct drm_device *dev,
  352. - struct vc4_exec_info *exec,
  353. - struct vc4_shader_state *state)
  354. +validate_gl_shader_rec(struct drm_device *dev,
  355. + struct vc4_exec_info *exec,
  356. + struct vc4_shader_state *state)
  357. {
  358. uint32_t *src_handles;
  359. void *pkt_u, *pkt_v;
  360. - enum shader_rec_reloc_type {
  361. - RELOC_CODE,
  362. - RELOC_VBO,
  363. - };
  364. - struct shader_rec_reloc {
  365. - enum shader_rec_reloc_type type;
  366. - uint32_t offset;
  367. - };
  368. - static const struct shader_rec_reloc gl_relocs[] = {
  369. - { RELOC_CODE, 4 }, /* fs */
  370. - { RELOC_CODE, 16 }, /* vs */
  371. - { RELOC_CODE, 28 }, /* cs */
  372. - };
  373. - static const struct shader_rec_reloc nv_relocs[] = {
  374. - { RELOC_CODE, 4 }, /* fs */
  375. - { RELOC_VBO, 12 }
  376. + static const uint32_t shader_reloc_offsets[] = {
  377. + 4, /* fs */
  378. + 16, /* vs */
  379. + 28, /* cs */
  380. };
  381. - const struct shader_rec_reloc *relocs;
  382. - struct drm_gem_cma_object *bo[ARRAY_SIZE(gl_relocs) + 8];
  383. - uint32_t nr_attributes = 0, nr_fixed_relocs, nr_relocs, packet_size;
  384. + uint32_t shader_reloc_count = ARRAY_SIZE(shader_reloc_offsets);
  385. + struct drm_gem_cma_object *bo[shader_reloc_count + 8];
  386. + uint32_t nr_attributes, nr_relocs, packet_size;
  387. int i;
  388. - struct vc4_validated_shader_info *shader;
  389. - if (state->packet == VC4_PACKET_NV_SHADER_STATE) {
  390. - relocs = nv_relocs;
  391. - nr_fixed_relocs = ARRAY_SIZE(nv_relocs);
  392. -
  393. - packet_size = 16;
  394. - } else {
  395. - relocs = gl_relocs;
  396. - nr_fixed_relocs = ARRAY_SIZE(gl_relocs);
  397. -
  398. - nr_attributes = state->addr & 0x7;
  399. - if (nr_attributes == 0)
  400. - nr_attributes = 8;
  401. - packet_size = gl_shader_rec_size(state->addr);
  402. - }
  403. - nr_relocs = nr_fixed_relocs + nr_attributes;
  404. + nr_attributes = state->addr & 0x7;
  405. + if (nr_attributes == 0)
  406. + nr_attributes = 8;
  407. + packet_size = gl_shader_rec_size(state->addr);
  408. + nr_relocs = ARRAY_SIZE(shader_reloc_offsets) + nr_attributes;
  409. if (nr_relocs * 4 > exec->shader_rec_size) {
  410. DRM_ERROR("overflowed shader recs reading %d handles "
  411. "from %d bytes left\n",
  412. @@ -829,21 +775,30 @@ validate_shader_rec(struct drm_device *d
  413. exec->shader_rec_v += roundup(packet_size, 16);
  414. exec->shader_rec_size -= packet_size;
  415. - for (i = 0; i < nr_relocs; i++) {
  416. - enum vc4_bo_mode mode;
  417. + if (!(*(uint16_t *)pkt_u & VC4_SHADER_FLAG_FS_SINGLE_THREAD)) {
  418. + DRM_ERROR("Multi-threaded fragment shaders not supported.\n");
  419. + return -EINVAL;
  420. + }
  421. - if (i < nr_fixed_relocs && relocs[i].type == RELOC_CODE)
  422. - mode = VC4_MODE_SHADER;
  423. - else
  424. - mode = VC4_MODE_RENDER;
  425. + for (i = 0; i < shader_reloc_count; i++) {
  426. + if (src_handles[i] > exec->bo_count) {
  427. + DRM_ERROR("Shader handle %d too big\n", src_handles[i]);
  428. + return -EINVAL;
  429. + }
  430. - if (!vc4_use_bo(exec, src_handles[i], mode, &bo[i]))
  431. - return false;
  432. + bo[i] = exec->bo[src_handles[i]];
  433. + if (!bo[i])
  434. + return -EINVAL;
  435. + }
  436. + for (i = shader_reloc_count; i < nr_relocs; i++) {
  437. + bo[i] = vc4_use_bo(exec, src_handles[i]);
  438. + if (!bo[i])
  439. + return -EINVAL;
  440. }
  441. - for (i = 0; i < nr_fixed_relocs; i++) {
  442. - struct vc4_bo *vc4_bo;
  443. - uint32_t o = relocs[i].offset;
  444. + for (i = 0; i < shader_reloc_count; i++) {
  445. + struct vc4_validated_shader_info *validated_shader;
  446. + uint32_t o = shader_reloc_offsets[i];
  447. uint32_t src_offset = *(uint32_t *)(pkt_u + o);
  448. uint32_t *texture_handles_u;
  449. void *uniform_data_u;
  450. @@ -851,57 +806,50 @@ validate_shader_rec(struct drm_device *d
  451. *(uint32_t *)(pkt_v + o) = bo[i]->paddr + src_offset;
  452. - switch (relocs[i].type) {
  453. - case RELOC_CODE:
  454. - if (src_offset != 0) {
  455. - DRM_ERROR("Shaders must be at offset 0 "
  456. - "of the BO.\n");
  457. - goto fail;
  458. - }
  459. + if (src_offset != 0) {
  460. + DRM_ERROR("Shaders must be at offset 0 of "
  461. + "the BO.\n");
  462. + return -EINVAL;
  463. + }
  464. - vc4_bo = to_vc4_bo(&bo[i]->base);
  465. - shader = vc4_bo->validated_shader;
  466. - if (!shader)
  467. - goto fail;
  468. + validated_shader = to_vc4_bo(&bo[i]->base)->validated_shader;
  469. + if (!validated_shader)
  470. + return -EINVAL;
  471. - if (shader->uniforms_src_size > exec->uniforms_size) {
  472. - DRM_ERROR("Uniforms src buffer overflow\n");
  473. - goto fail;
  474. - }
  475. + if (validated_shader->uniforms_src_size >
  476. + exec->uniforms_size) {
  477. + DRM_ERROR("Uniforms src buffer overflow\n");
  478. + return -EINVAL;
  479. + }
  480. - texture_handles_u = exec->uniforms_u;
  481. - uniform_data_u = (texture_handles_u +
  482. - shader->num_texture_samples);
  483. -
  484. - memcpy(exec->uniforms_v, uniform_data_u,
  485. - shader->uniforms_size);
  486. -
  487. - for (tex = 0;
  488. - tex < shader->num_texture_samples;
  489. - tex++) {
  490. - if (!reloc_tex(exec,
  491. - uniform_data_u,
  492. - &shader->texture_samples[tex],
  493. - texture_handles_u[tex])) {
  494. - goto fail;
  495. - }
  496. + texture_handles_u = exec->uniforms_u;
  497. + uniform_data_u = (texture_handles_u +
  498. + validated_shader->num_texture_samples);
  499. +
  500. + memcpy(exec->uniforms_v, uniform_data_u,
  501. + validated_shader->uniforms_size);
  502. +
  503. + for (tex = 0;
  504. + tex < validated_shader->num_texture_samples;
  505. + tex++) {
  506. + if (!reloc_tex(exec,
  507. + uniform_data_u,
  508. + &validated_shader->texture_samples[tex],
  509. + texture_handles_u[tex])) {
  510. + return -EINVAL;
  511. }
  512. + }
  513. - *(uint32_t *)(pkt_v + o + 4) = exec->uniforms_p;
  514. -
  515. - exec->uniforms_u += shader->uniforms_src_size;
  516. - exec->uniforms_v += shader->uniforms_size;
  517. - exec->uniforms_p += shader->uniforms_size;
  518. -
  519. - break;
  520. + *(uint32_t *)(pkt_v + o + 4) = exec->uniforms_p;
  521. - case RELOC_VBO:
  522. - break;
  523. - }
  524. + exec->uniforms_u += validated_shader->uniforms_src_size;
  525. + exec->uniforms_v += validated_shader->uniforms_size;
  526. + exec->uniforms_p += validated_shader->uniforms_size;
  527. }
  528. for (i = 0; i < nr_attributes; i++) {
  529. - struct drm_gem_cma_object *vbo = bo[nr_fixed_relocs + i];
  530. + struct drm_gem_cma_object *vbo =
  531. + bo[ARRAY_SIZE(shader_reloc_offsets) + i];
  532. uint32_t o = 36 + i * 8;
  533. uint32_t offset = *(uint32_t *)(pkt_u + o + 0);
  534. uint32_t attr_size = *(uint8_t *)(pkt_u + o + 4) + 1;
  535. @@ -933,9 +881,6 @@ validate_shader_rec(struct drm_device *d
  536. }
  537. return 0;
  538. -
  539. -fail:
  540. - return -EINVAL;
  541. }
  542. int
  543. @@ -946,7 +891,7 @@ vc4_validate_shader_recs(struct drm_devi
  544. int ret = 0;
  545. for (i = 0; i < exec->shader_state_count; i++) {
  546. - ret = validate_shader_rec(dev, exec, &exec->shader_state[i]);
  547. + ret = validate_gl_shader_rec(dev, exec, &exec->shader_state[i]);
  548. if (ret)
  549. return ret;
  550. }