mdp5_pipe.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_state *state;
  26. struct mdp5_hw_pipe_state *old_state, *new_state;
  27. int i, j;
  28. state = mdp5_get_state(s);
  29. if (IS_ERR(state))
  30. return PTR_ERR(state);
  31. /* grab old_state after mdp5_get_state(), since now we hold lock: */
  32. old_state = &mdp5_kms->state->hwpipe;
  33. new_state = &state->hwpipe;
  34. for (i = 0; i < mdp5_kms->num_hwpipes; i++) {
  35. struct mdp5_hw_pipe *cur = mdp5_kms->hwpipes[i];
  36. /* skip if already in-use.. check both new and old state,
  37. * since we cannot immediately re-use a pipe that is
  38. * released in the current update in some cases:
  39. * (1) mdp5 can have SMP (non-double-buffered)
  40. * (2) hw pipe previously assigned to different CRTC
  41. * (vblanks might not be aligned)
  42. */
  43. if (new_state->hwpipe_to_plane[cur->idx] ||
  44. old_state->hwpipe_to_plane[cur->idx])
  45. continue;
  46. /* skip if doesn't support some required caps: */
  47. if (caps & ~cur->caps)
  48. continue;
  49. /*
  50. * don't assign a cursor pipe to a plane that isn't going to
  51. * be used as a cursor
  52. */
  53. if (cur->caps & MDP_PIPE_CAP_CURSOR &&
  54. plane->type != DRM_PLANE_TYPE_CURSOR)
  55. continue;
  56. /* possible candidate, take the one with the
  57. * fewest unneeded caps bits set:
  58. */
  59. if (!(*hwpipe) || (hweight_long(cur->caps & ~caps) <
  60. hweight_long((*hwpipe)->caps & ~caps))) {
  61. bool r_found = false;
  62. if (r_hwpipe) {
  63. for (j = i + 1; j < mdp5_kms->num_hwpipes;
  64. j++) {
  65. struct mdp5_hw_pipe *r_cur =
  66. mdp5_kms->hwpipes[j];
  67. /* reject different types of hwpipes */
  68. if (r_cur->caps != cur->caps)
  69. continue;
  70. /* respect priority, eg. VIG0 > VIG1 */
  71. if (cur->pipe > r_cur->pipe)
  72. continue;
  73. *r_hwpipe = r_cur;
  74. r_found = true;
  75. break;
  76. }
  77. }
  78. if (!r_hwpipe || r_found)
  79. *hwpipe = cur;
  80. }
  81. }
  82. if (!(*hwpipe))
  83. return -ENOMEM;
  84. if (r_hwpipe && !(*r_hwpipe))
  85. return -ENOMEM;
  86. if (mdp5_kms->smp) {
  87. int ret;
  88. /* We don't support SMP and 2 hwpipes/plane together */
  89. WARN_ON(r_hwpipe);
  90. DBG("%s: alloc SMP blocks", (*hwpipe)->name);
  91. ret = mdp5_smp_assign(mdp5_kms->smp, &state->smp,
  92. (*hwpipe)->pipe, blkcfg);
  93. if (ret)
  94. return -ENOMEM;
  95. (*hwpipe)->blkcfg = blkcfg;
  96. }
  97. DBG("%s: assign to plane %s for caps %x",
  98. (*hwpipe)->name, plane->name, caps);
  99. new_state->hwpipe_to_plane[(*hwpipe)->idx] = plane;
  100. if (r_hwpipe) {
  101. DBG("%s: assign to right of plane %s for caps %x",
  102. (*r_hwpipe)->name, plane->name, caps);
  103. new_state->hwpipe_to_plane[(*r_hwpipe)->idx] = plane;
  104. }
  105. return 0;
  106. }
  107. void mdp5_pipe_release(struct drm_atomic_state *s, struct mdp5_hw_pipe *hwpipe)
  108. {
  109. struct msm_drm_private *priv = s->dev->dev_private;
  110. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms));
  111. struct mdp5_state *state = mdp5_get_state(s);
  112. struct mdp5_hw_pipe_state *new_state = &state->hwpipe;
  113. if (!hwpipe)
  114. return;
  115. if (WARN_ON(!new_state->hwpipe_to_plane[hwpipe->idx]))
  116. return;
  117. DBG("%s: release from plane %s", hwpipe->name,
  118. new_state->hwpipe_to_plane[hwpipe->idx]->name);
  119. if (mdp5_kms->smp) {
  120. DBG("%s: free SMP blocks", hwpipe->name);
  121. mdp5_smp_release(mdp5_kms->smp, &state->smp, hwpipe->pipe);
  122. }
  123. new_state->hwpipe_to_plane[hwpipe->idx] = NULL;
  124. }
  125. void mdp5_pipe_destroy(struct mdp5_hw_pipe *hwpipe)
  126. {
  127. kfree(hwpipe);
  128. }
  129. struct mdp5_hw_pipe *mdp5_pipe_init(enum mdp5_pipe pipe,
  130. uint32_t reg_offset, uint32_t caps)
  131. {
  132. struct mdp5_hw_pipe *hwpipe;
  133. hwpipe = kzalloc(sizeof(*hwpipe), GFP_KERNEL);
  134. if (!hwpipe)
  135. return ERR_PTR(-ENOMEM);
  136. hwpipe->name = pipe2name(pipe);
  137. hwpipe->pipe = pipe;
  138. hwpipe->reg_offset = reg_offset;
  139. hwpipe->caps = caps;
  140. hwpipe->flush_mask = mdp_ctl_flush_mask_pipe(pipe);
  141. return hwpipe;
  142. }