0476-drm-vc4-Move-validation-s-current-max-ip-into-the-va.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. From 6af02628d1704bf16359696593246bbb78222363 Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Sat, 2 Jul 2016 09:57:07 -0700
  4. Subject: [PATCH] drm/vc4: Move validation's current/max ip into the validation
  5. struct.
  6. Reduces the argument count for some of the functions, and will be used
  7. more with the upcoming looping support.
  8. Signed-off-by: Eric Anholt <eric@anholt.net>
  9. (cherry picked from commit d0566c2a2f2baacefe1eb75be8a001fdd6fe84a3)
  10. ---
  11. drivers/gpu/drm/vc4/vc4_validate_shaders.c | 54 +++++++++++++++++-------------
  12. 1 file changed, 30 insertions(+), 24 deletions(-)
  13. --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
  14. +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
  15. @@ -40,6 +40,14 @@
  16. #include "vc4_qpu_defines.h"
  17. struct vc4_shader_validation_state {
  18. + /* Current IP being validated. */
  19. + uint32_t ip;
  20. +
  21. + /* IP at the end of the BO, do not read shader[max_ip] */
  22. + uint32_t max_ip;
  23. +
  24. + uint64_t *shader;
  25. +
  26. struct vc4_texture_sample_info tmu_setup[2];
  27. int tmu_write_count[2];
  28. @@ -129,11 +137,11 @@ record_texture_sample(struct vc4_validat
  29. }
  30. static bool
  31. -check_tmu_write(uint64_t inst,
  32. - struct vc4_validated_shader_info *validated_shader,
  33. +check_tmu_write(struct vc4_validated_shader_info *validated_shader,
  34. struct vc4_shader_validation_state *validation_state,
  35. bool is_mul)
  36. {
  37. + uint64_t inst = validation_state->shader[validation_state->ip];
  38. uint32_t waddr = (is_mul ?
  39. QPU_GET_FIELD(inst, QPU_WADDR_MUL) :
  40. QPU_GET_FIELD(inst, QPU_WADDR_ADD));
  41. @@ -228,11 +236,11 @@ check_tmu_write(uint64_t inst,
  42. }
  43. static bool
  44. -check_reg_write(uint64_t inst,
  45. - struct vc4_validated_shader_info *validated_shader,
  46. +check_reg_write(struct vc4_validated_shader_info *validated_shader,
  47. struct vc4_shader_validation_state *validation_state,
  48. bool is_mul)
  49. {
  50. + uint64_t inst = validation_state->shader[validation_state->ip];
  51. uint32_t waddr = (is_mul ?
  52. QPU_GET_FIELD(inst, QPU_WADDR_MUL) :
  53. QPU_GET_FIELD(inst, QPU_WADDR_ADD));
  54. @@ -261,7 +269,7 @@ check_reg_write(uint64_t inst,
  55. case QPU_W_TMU1_T:
  56. case QPU_W_TMU1_R:
  57. case QPU_W_TMU1_B:
  58. - return check_tmu_write(inst, validated_shader, validation_state,
  59. + return check_tmu_write(validated_shader, validation_state,
  60. is_mul);
  61. case QPU_W_HOST_INT:
  62. @@ -294,10 +302,10 @@ check_reg_write(uint64_t inst,
  63. }
  64. static void
  65. -track_live_clamps(uint64_t inst,
  66. - struct vc4_validated_shader_info *validated_shader,
  67. +track_live_clamps(struct vc4_validated_shader_info *validated_shader,
  68. struct vc4_shader_validation_state *validation_state)
  69. {
  70. + uint64_t inst = validation_state->shader[validation_state->ip];
  71. uint32_t op_add = QPU_GET_FIELD(inst, QPU_OP_ADD);
  72. uint32_t waddr_add = QPU_GET_FIELD(inst, QPU_WADDR_ADD);
  73. uint32_t waddr_mul = QPU_GET_FIELD(inst, QPU_WADDR_MUL);
  74. @@ -369,10 +377,10 @@ track_live_clamps(uint64_t inst,
  75. }
  76. static bool
  77. -check_instruction_writes(uint64_t inst,
  78. - struct vc4_validated_shader_info *validated_shader,
  79. +check_instruction_writes(struct vc4_validated_shader_info *validated_shader,
  80. struct vc4_shader_validation_state *validation_state)
  81. {
  82. + uint64_t inst = validation_state->shader[validation_state->ip];
  83. uint32_t waddr_add = QPU_GET_FIELD(inst, QPU_WADDR_ADD);
  84. uint32_t waddr_mul = QPU_GET_FIELD(inst, QPU_WADDR_MUL);
  85. bool ok;
  86. @@ -382,12 +390,10 @@ check_instruction_writes(uint64_t inst,
  87. return false;
  88. }
  89. - ok = (check_reg_write(inst, validated_shader, validation_state,
  90. - false) &&
  91. - check_reg_write(inst, validated_shader, validation_state,
  92. - true));
  93. + ok = (check_reg_write(validated_shader, validation_state, false) &&
  94. + check_reg_write(validated_shader, validation_state, true));
  95. - track_live_clamps(inst, validated_shader, validation_state);
  96. + track_live_clamps(validated_shader, validation_state);
  97. return ok;
  98. }
  99. @@ -417,30 +423,30 @@ vc4_validate_shader(struct drm_gem_cma_o
  100. {
  101. bool found_shader_end = false;
  102. int shader_end_ip = 0;
  103. - uint32_t ip, max_ip;
  104. - uint64_t *shader;
  105. + uint32_t ip;
  106. struct vc4_validated_shader_info *validated_shader;
  107. struct vc4_shader_validation_state validation_state;
  108. int i;
  109. memset(&validation_state, 0, sizeof(validation_state));
  110. + validation_state.shader = shader_obj->vaddr;
  111. + validation_state.max_ip = shader_obj->base.size / sizeof(uint64_t);
  112. for (i = 0; i < 8; i++)
  113. validation_state.tmu_setup[i / 4].p_offset[i % 4] = ~0;
  114. for (i = 0; i < ARRAY_SIZE(validation_state.live_min_clamp_offsets); i++)
  115. validation_state.live_min_clamp_offsets[i] = ~0;
  116. - shader = shader_obj->vaddr;
  117. - max_ip = shader_obj->base.size / sizeof(uint64_t);
  118. -
  119. validated_shader = kcalloc(1, sizeof(*validated_shader), GFP_KERNEL);
  120. if (!validated_shader)
  121. return NULL;
  122. - for (ip = 0; ip < max_ip; ip++) {
  123. - uint64_t inst = shader[ip];
  124. + for (ip = 0; ip < validation_state.max_ip; ip++) {
  125. + uint64_t inst = validation_state.shader[ip];
  126. uint32_t sig = QPU_GET_FIELD(inst, QPU_SIG);
  127. + validation_state.ip = ip;
  128. +
  129. switch (sig) {
  130. case QPU_SIG_NONE:
  131. case QPU_SIG_WAIT_FOR_SCOREBOARD:
  132. @@ -450,7 +456,7 @@ vc4_validate_shader(struct drm_gem_cma_o
  133. case QPU_SIG_LOAD_TMU1:
  134. case QPU_SIG_PROG_END:
  135. case QPU_SIG_SMALL_IMM:
  136. - if (!check_instruction_writes(inst, validated_shader,
  137. + if (!check_instruction_writes(validated_shader,
  138. &validation_state)) {
  139. DRM_ERROR("Bad write at ip %d\n", ip);
  140. goto fail;
  141. @@ -467,7 +473,7 @@ vc4_validate_shader(struct drm_gem_cma_o
  142. break;
  143. case QPU_SIG_LOAD_IMM:
  144. - if (!check_instruction_writes(inst, validated_shader,
  145. + if (!check_instruction_writes(validated_shader,
  146. &validation_state)) {
  147. DRM_ERROR("Bad LOAD_IMM write at ip %d\n", ip);
  148. goto fail;
  149. @@ -487,7 +493,7 @@ vc4_validate_shader(struct drm_gem_cma_o
  150. break;
  151. }
  152. - if (ip == max_ip) {
  153. + if (ip == validation_state.max_ip) {
  154. DRM_ERROR("shader failed to terminate before "
  155. "shader BO end at %zd\n",
  156. shader_obj->base.size);