sde_kms_utils.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[sde-kms_utils:%s:%d] " fmt, __func__, __LINE__
  7. #include "sde_kms.h"
  8. void sde_kms_info_reset(struct sde_kms_info *info)
  9. {
  10. if (info) {
  11. info->len = 0;
  12. info->staged_len = 0;
  13. }
  14. }
  15. void sde_kms_info_add_keyint(struct sde_kms_info *info,
  16. const char *key,
  17. int64_t value)
  18. {
  19. uint32_t len;
  20. if (info && key) {
  21. len = snprintf(info->data + info->len,
  22. SDE_KMS_INFO_MAX_SIZE - info->len,
  23. "%s=%lld\n",
  24. key,
  25. value);
  26. /* check if snprintf truncated the string */
  27. if ((info->len + len) < SDE_KMS_INFO_MAX_SIZE)
  28. info->len += len;
  29. }
  30. }
  31. void sde_kms_info_add_keystr(struct sde_kms_info *info,
  32. const char *key,
  33. const char *value)
  34. {
  35. uint32_t len;
  36. if (info && key && value) {
  37. len = snprintf(info->data + info->len,
  38. SDE_KMS_INFO_MAX_SIZE - info->len,
  39. "%s=%s\n",
  40. key,
  41. value);
  42. /* check if snprintf truncated the string */
  43. if ((info->len + len) < SDE_KMS_INFO_MAX_SIZE)
  44. info->len += len;
  45. }
  46. }
  47. void sde_kms_info_start(struct sde_kms_info *info,
  48. const char *key)
  49. {
  50. uint32_t len;
  51. if (info && key) {
  52. len = snprintf(info->data + info->len,
  53. SDE_KMS_INFO_MAX_SIZE - info->len,
  54. "%s=",
  55. key);
  56. info->start = true;
  57. /* check if snprintf truncated the string */
  58. if ((info->len + len) < SDE_KMS_INFO_MAX_SIZE)
  59. info->staged_len = info->len + len;
  60. }
  61. }
  62. void sde_kms_info_append(struct sde_kms_info *info,
  63. const char *str)
  64. {
  65. uint32_t len;
  66. if (info) {
  67. len = snprintf(info->data + info->staged_len,
  68. SDE_KMS_INFO_MAX_SIZE - info->staged_len,
  69. "%s",
  70. str);
  71. /* check if snprintf truncated the string */
  72. if ((info->staged_len + len) < SDE_KMS_INFO_MAX_SIZE) {
  73. info->staged_len += len;
  74. info->start = false;
  75. }
  76. }
  77. }
  78. void sde_kms_info_add_list(struct sde_kms_info *info, const char *key, uint32_t *value, size_t size)
  79. {
  80. uint32_t i, len;
  81. if (!info || !key || !value || !size)
  82. return;
  83. sde_kms_info_start(info, key);
  84. for (i = 0; i < size; i++) {
  85. len = scnprintf(info->data + info->staged_len,
  86. SDE_KMS_INFO_MAX_SIZE - info->len, "%d ",
  87. value[i]);
  88. /* check if snprintf truncated the string */
  89. if ((info->staged_len + len) < SDE_KMS_INFO_MAX_SIZE) {
  90. info->staged_len += len;
  91. info->start = false;
  92. }
  93. }
  94. sde_kms_info_stop(info);
  95. }
  96. void sde_kms_info_append_format(struct sde_kms_info *info,
  97. uint32_t pixel_format,
  98. uint64_t modifier)
  99. {
  100. uint32_t len;
  101. if (!info)
  102. return;
  103. if (modifier) {
  104. len = snprintf(info->data + info->staged_len,
  105. SDE_KMS_INFO_MAX_SIZE - info->staged_len,
  106. info->start ?
  107. "%c%c%c%c/%llX/%llX" : " %c%c%c%c/%llX/%llX",
  108. (pixel_format >> 0) & 0xFF,
  109. (pixel_format >> 8) & 0xFF,
  110. (pixel_format >> 16) & 0xFF,
  111. (pixel_format >> 24) & 0xFF,
  112. (modifier >> 56) & 0xFF,
  113. modifier & ((1ULL << 56) - 1));
  114. } else {
  115. len = snprintf(info->data + info->staged_len,
  116. SDE_KMS_INFO_MAX_SIZE - info->staged_len,
  117. info->start ?
  118. "%c%c%c%c" : " %c%c%c%c",
  119. (pixel_format >> 0) & 0xFF,
  120. (pixel_format >> 8) & 0xFF,
  121. (pixel_format >> 16) & 0xFF,
  122. (pixel_format >> 24) & 0xFF);
  123. }
  124. /* check if snprintf truncated the string */
  125. if ((info->staged_len + len) < SDE_KMS_INFO_MAX_SIZE) {
  126. info->staged_len += len;
  127. info->start = false;
  128. }
  129. }
  130. void sde_kms_info_stop(struct sde_kms_info *info)
  131. {
  132. uint32_t len;
  133. if (info) {
  134. /* insert final delimiter */
  135. len = snprintf(info->data + info->staged_len,
  136. SDE_KMS_INFO_MAX_SIZE - info->staged_len,
  137. "\n");
  138. /* check if snprintf truncated the string */
  139. if ((info->staged_len + len) < SDE_KMS_INFO_MAX_SIZE)
  140. info->len = info->staged_len + len;
  141. }
  142. }
  143. void sde_kms_info_append_dnsc_blur_filter_info(struct sde_kms_info *info,
  144. struct sde_dnsc_blur_filter_info *filter_info)
  145. {
  146. int i;
  147. uint32_t len, cur_len;
  148. if (!info)
  149. return;
  150. len = snprintf(info->data + info->staged_len, SDE_KMS_INFO_MAX_SIZE - info->staged_len,
  151. info->start ?
  152. "%c/%c/%c/%c/%c/%c/%c/%c/%c/" : " %c/%c/%c/%c/%c/%c/%c/%c/%c/",
  153. filter_info->filter & 0xFF, filter_info->src_min & 0xFF,
  154. filter_info->src_max & 0xFF, filter_info->dst_min & 0xFF,
  155. filter_info->dst_max & 0xFF, filter_info->min_ratio & 0xFF,
  156. filter_info->max_ratio & 0xFF, filter_info->fraction_support & 0xFF,
  157. filter_info->ratio_count & 0xFF);
  158. cur_len = len;
  159. for (i = 0; i < filter_info->ratio_count; i++) {
  160. len = snprintf(info->data + (info->staged_len + cur_len),
  161. SDE_KMS_INFO_MAX_SIZE - (info->staged_len + cur_len),
  162. (i == filter_info->ratio_count - 1) ? "%c" : "%c,",
  163. filter_info->ratio[i]);
  164. cur_len += len;
  165. }
  166. /* check if snprintf truncated the string */
  167. if ((info->staged_len + cur_len) < SDE_KMS_INFO_MAX_SIZE) {
  168. info->staged_len += cur_len;
  169. info->start = false;
  170. }
  171. }
  172. void sde_kms_rect_intersect(const struct sde_rect *r1,
  173. const struct sde_rect *r2,
  174. struct sde_rect *result)
  175. {
  176. int l, t, r, b;
  177. if (!r1 || !r2 || !result)
  178. return;
  179. l = max(r1->x, r2->x);
  180. t = max(r1->y, r2->y);
  181. r = min((r1->x + r1->w), (r2->x + r2->w));
  182. b = min((r1->y + r1->h), (r2->y + r2->h));
  183. if (r <= l || b <= t) {
  184. memset(result, 0, sizeof(*result));
  185. } else {
  186. result->x = l;
  187. result->y = t;
  188. result->w = r - l;
  189. result->h = b - t;
  190. }
  191. }
  192. void sde_kms_rect_merge_rectangles(const struct msm_roi_list *rois,
  193. struct sde_rect *result)
  194. {
  195. struct drm_clip_rect clip;
  196. const struct drm_clip_rect *roi_rect;
  197. int i;
  198. if (!rois || !result)
  199. return;
  200. memset(result, 0, sizeof(*result));
  201. /* init to invalid range maxes */
  202. clip.x1 = ~0;
  203. clip.y1 = ~0;
  204. clip.x2 = 0;
  205. clip.y2 = 0;
  206. /* aggregate all clipping rectangles together for overall roi */
  207. for (i = 0; i < rois->num_rects; i++) {
  208. roi_rect = &rois->roi[i];
  209. clip.x1 = min(clip.x1, roi_rect->x1);
  210. clip.y1 = min(clip.y1, roi_rect->y1);
  211. clip.x2 = max(clip.x2, roi_rect->x2);
  212. clip.y2 = max(clip.y2, roi_rect->y2);
  213. SDE_DEBUG("roi%d (%d,%d),(%d,%d) -> crtc (%d,%d),(%d,%d)\n", i,
  214. roi_rect->x1, roi_rect->y1,
  215. roi_rect->x2, roi_rect->y2,
  216. clip.x1, clip.y1,
  217. clip.x2, clip.y2);
  218. }
  219. if (clip.x2 && clip.y2) {
  220. result->x = clip.x1;
  221. result->y = clip.y1;
  222. result->w = clip.x2 - clip.x1;
  223. result->h = clip.y2 - clip.y1;
  224. }
  225. }