mdp5_pipe.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (C) 2016 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "mdp5_kms.h"
  18. int mdp5_pipe_assign(struct drm_atomic_state *s, struct drm_plane *plane,
  19. uint32_t caps, uint32_t blkcfg,
  20. struct mdp5_hw_pipe **hwpipe,
  21. struct mdp5_hw_pipe **r_hwpipe)
  22. {
  23. struct msm_drm_private *priv = s->dev->dev_private;
  24. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms));
  25. struct mdp5_global_state *new_global_state, *old_global_state;
  26. struct mdp5_hw_pipe_state *old_state, *new_state;
  27. int i, j;
  28. new_global_state = mdp5_get_global_state(s);
  29. if (IS_ERR(new_global_state))
  30. return PTR_ERR(new_global_state);
  31. /* grab old_state after mdp5_get_global_state(), since now we hold lock: */
  32. old_global_state = mdp5_get_existing_global_state(mdp5_kms);
  33. old_state = &old_global_state->hwpipe;
  34. new_state = &new_global_state->hwpipe;
  35. for (i = 0; i < mdp5_kms->num_hwpipes; i++) {
  36. struct mdp5_hw_pipe *cur = mdp5_kms->hwpipes[i];
  37. /* skip if already in-use.. check both new and old state,
  38. * since we cannot immediately re-use a pipe that is
  39. * released in the current update in some cases:
  40. * (1) mdp5 can have SMP (non-double-buffered)
  41. * (2) hw pipe previously assigned to different CRTC
  42. * (vblanks might not be aligned)
  43. */
  44. if (new_state->hwpipe_to_plane[cur->idx] ||
  45. old_state->hwpipe_to_plane[cur->idx])
  46. continue;
  47. /* skip if doesn't support some required caps: */
  48. if (caps & ~cur->caps)
  49. continue;
  50. /*
  51. * don't assign a cursor pipe to a plane that isn't going to
  52. * be used as a cursor
  53. */
  54. if (cur->caps & MDP_PIPE_CAP_CURSOR &&
  55. plane->type != DRM_PLANE_TYPE_CURSOR)
  56. continue;
  57. /* possible candidate, take the one with the
  58. * fewest unneeded caps bits set:
  59. */
  60. if (!(*hwpipe) || (hweight_long(cur->caps & ~caps) <
  61. hweight_long((*hwpipe)->caps & ~caps))) {
  62. bool r_found = false;
  63. if (r_hwpipe) {
  64. for (j = i + 1; j < mdp5_kms->num_hwpipes;
  65. j++) {
  66. struct mdp5_hw_pipe *r_cur =
  67. mdp5_kms->hwpipes[j];
  68. /* reject different types of hwpipes */
  69. if (r_cur->caps != cur->caps)
  70. continue;
  71. /* respect priority, eg. VIG0 > VIG1 */
  72. if (cur->pipe > r_cur->pipe)
  73. continue;
  74. *r_hwpipe = r_cur;
  75. r_found = true;
  76. break;
  77. }
  78. }
  79. if (!r_hwpipe || r_found)
  80. *hwpipe = cur;
  81. }
  82. }
  83. if (!(*hwpipe))
  84. return -ENOMEM;
  85. if (r_hwpipe && !(*r_hwpipe))
  86. return -ENOMEM;
  87. if (mdp5_kms->smp) {
  88. int ret;
  89. /* We don't support SMP and 2 hwpipes/plane together */
  90. WARN_ON(r_hwpipe);
  91. DBG("%s: alloc SMP blocks", (*hwpipe)->name);
  92. ret = mdp5_smp_assign(mdp5_kms->smp, &new_global_state->smp,
  93. (*hwpipe)->pipe, blkcfg);
  94. if (ret)
  95. return -ENOMEM;
  96. (*hwpipe)->blkcfg = blkcfg;
  97. }
  98. DBG("%s: assign to plane %s for caps %x",
  99. (*hwpipe)->name, plane->name, caps);
  100. new_state->hwpipe_to_plane[(*hwpipe)->idx] = plane;
  101. if (r_hwpipe) {
  102. DBG("%s: assign to right of plane %s for caps %x",
  103. (*r_hwpipe)->name, plane->name, caps);
  104. new_state->hwpipe_to_plane[(*r_hwpipe)->idx] = plane;
  105. }
  106. return 0;
  107. }
  108. void mdp5_pipe_release(struct drm_atomic_state *s, struct mdp5_hw_pipe *hwpipe)
  109. {
  110. struct msm_drm_private *priv = s->dev->dev_private;
  111. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms));
  112. struct mdp5_global_state *state = mdp5_get_global_state(s);
  113. struct mdp5_hw_pipe_state *new_state = &state->hwpipe;
  114. if (!hwpipe)
  115. return;
  116. if (WARN_ON(!new_state->hwpipe_to_plane[hwpipe->idx]))
  117. return;
  118. DBG("%s: release from plane %s", hwpipe->name,
  119. new_state->hwpipe_to_plane[hwpipe->idx]->name);
  120. if (mdp5_kms->smp) {
  121. DBG("%s: free SMP blocks", hwpipe->name);
  122. mdp5_smp_release(mdp5_kms->smp, &state->smp, hwpipe->pipe);
  123. }
  124. new_state->hwpipe_to_plane[hwpipe->idx] = NULL;
  125. }
  126. void mdp5_pipe_destroy(struct mdp5_hw_pipe *hwpipe)
  127. {
  128. kfree(hwpipe);
  129. }
  130. struct mdp5_hw_pipe *mdp5_pipe_init(enum mdp5_pipe pipe,
  131. uint32_t reg_offset, uint32_t caps)
  132. {
  133. struct mdp5_hw_pipe *hwpipe;
  134. hwpipe = kzalloc(sizeof(*hwpipe), GFP_KERNEL);
  135. if (!hwpipe)
  136. return ERR_PTR(-ENOMEM);
  137. hwpipe->name = pipe2name(pipe);
  138. hwpipe->pipe = pipe;
  139. hwpipe->reg_offset = reg_offset;
  140. hwpipe->caps = caps;
  141. hwpipe->flush_mask = mdp_ctl_flush_mask_pipe(pipe);
  142. return hwpipe;
  143. }