sti_plane.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2014
  3. * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  4. * Fabien Dessenne <fabien.dessenne@st.com>
  5. * for STMicroelectronics.
  6. * License terms: GNU General Public License (GPL), version 2
  7. */
  8. #include <drm/drmP.h>
  9. #include <drm/drm_fb_cma_helper.h>
  10. #include <drm/drm_gem_cma_helper.h>
  11. #include "sti_compositor.h"
  12. #include "sti_drv.h"
  13. #include "sti_plane.h"
  14. const char *sti_plane_to_str(struct sti_plane *plane)
  15. {
  16. switch (plane->desc) {
  17. case STI_GDP_0:
  18. return "GDP0";
  19. case STI_GDP_1:
  20. return "GDP1";
  21. case STI_GDP_2:
  22. return "GDP2";
  23. case STI_GDP_3:
  24. return "GDP3";
  25. case STI_HQVDP_0:
  26. return "HQVDP0";
  27. case STI_CURSOR:
  28. return "CURSOR";
  29. default:
  30. return "<UNKNOWN PLANE>";
  31. }
  32. }
  33. #define STI_FPS_INTERVAL_MS 3000
  34. void sti_plane_update_fps(struct sti_plane *plane,
  35. bool new_frame,
  36. bool new_field)
  37. {
  38. ktime_t now;
  39. struct sti_fps_info *fps;
  40. int fpks, fipks, ms_since_last, num_frames, num_fields;
  41. now = ktime_get();
  42. /* Compute number of frame updates */
  43. fps = &plane->fps_info;
  44. if (new_field)
  45. fps->curr_field_counter++;
  46. /* do not perform fps calcul if new_frame is false */
  47. if (!new_frame)
  48. return;
  49. fps->curr_frame_counter++;
  50. ms_since_last = ktime_to_ms(ktime_sub(now, fps->last_timestamp));
  51. num_frames = fps->curr_frame_counter - fps->last_frame_counter;
  52. if (num_frames <= 0 || ms_since_last < STI_FPS_INTERVAL_MS)
  53. return;
  54. fps->last_timestamp = now;
  55. fps->last_frame_counter = fps->curr_frame_counter;
  56. if (plane->drm_plane.fb) {
  57. fpks = (num_frames * 1000000) / ms_since_last;
  58. snprintf(plane->fps_info.fps_str, FPS_LENGTH,
  59. "%-8s %4dx%-4d %.4s @ %3d.%-3.3d fps (%s)",
  60. plane->drm_plane.name,
  61. plane->drm_plane.fb->width,
  62. plane->drm_plane.fb->height,
  63. (char *)&plane->drm_plane.fb->format->format,
  64. fpks / 1000, fpks % 1000,
  65. sti_plane_to_str(plane));
  66. }
  67. if (fps->curr_field_counter) {
  68. /* Compute number of field updates */
  69. num_fields = fps->curr_field_counter - fps->last_field_counter;
  70. fps->last_field_counter = fps->curr_field_counter;
  71. fipks = (num_fields * 1000000) / ms_since_last;
  72. snprintf(plane->fps_info.fips_str,
  73. FPS_LENGTH, " - %3d.%-3.3d field/sec",
  74. fipks / 1000, fipks % 1000);
  75. } else {
  76. plane->fps_info.fips_str[0] = '\0';
  77. }
  78. if (fps->output)
  79. DRM_INFO("%s%s\n",
  80. plane->fps_info.fps_str,
  81. plane->fps_info.fips_str);
  82. }
  83. static int sti_plane_get_default_zpos(enum drm_plane_type type)
  84. {
  85. switch (type) {
  86. case DRM_PLANE_TYPE_PRIMARY:
  87. return 0;
  88. case DRM_PLANE_TYPE_OVERLAY:
  89. return 1;
  90. case DRM_PLANE_TYPE_CURSOR:
  91. return 7;
  92. }
  93. return 0;
  94. }
  95. void sti_plane_reset(struct drm_plane *plane)
  96. {
  97. drm_atomic_helper_plane_reset(plane);
  98. plane->state->zpos = sti_plane_get_default_zpos(plane->type);
  99. }
  100. static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane,
  101. enum drm_plane_type type)
  102. {
  103. int zpos = sti_plane_get_default_zpos(type);
  104. switch (type) {
  105. case DRM_PLANE_TYPE_PRIMARY:
  106. case DRM_PLANE_TYPE_OVERLAY:
  107. drm_plane_create_zpos_property(drm_plane, zpos, 0, 6);
  108. break;
  109. case DRM_PLANE_TYPE_CURSOR:
  110. drm_plane_create_zpos_immutable_property(drm_plane, zpos);
  111. break;
  112. }
  113. }
  114. void sti_plane_init_property(struct sti_plane *plane,
  115. enum drm_plane_type type)
  116. {
  117. sti_plane_attach_zorder_property(&plane->drm_plane, type);
  118. DRM_DEBUG_DRIVER("drm plane:%d mapped to %s\n",
  119. plane->drm_plane.base.id, sti_plane_to_str(plane));
  120. }