mdp5_mixer.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (C) 2017 The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published by
  6. * the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "mdp5_kms.h"
  17. /*
  18. * As of now, there are only 2 combinations possible for source split:
  19. *
  20. * Left | Right
  21. * -----|------
  22. * LM0 | LM1
  23. * LM2 | LM5
  24. *
  25. */
  26. static int lm_right_pair[] = { 1, -1, 5, -1, -1, -1 };
  27. static int get_right_pair_idx(struct mdp5_kms *mdp5_kms, int lm)
  28. {
  29. int i;
  30. int pair_lm;
  31. pair_lm = lm_right_pair[lm];
  32. if (pair_lm < 0)
  33. return -EINVAL;
  34. for (i = 0; i < mdp5_kms->num_hwmixers; i++) {
  35. struct mdp5_hw_mixer *mixer = mdp5_kms->hwmixers[i];
  36. if (mixer->lm == pair_lm)
  37. return mixer->idx;
  38. }
  39. return -1;
  40. }
  41. int mdp5_mixer_assign(struct drm_atomic_state *s, struct drm_crtc *crtc,
  42. uint32_t caps, struct mdp5_hw_mixer **mixer,
  43. struct mdp5_hw_mixer **r_mixer)
  44. {
  45. struct msm_drm_private *priv = s->dev->dev_private;
  46. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms));
  47. struct mdp5_state *state = mdp5_get_state(s);
  48. struct mdp5_hw_mixer_state *new_state;
  49. int i;
  50. if (IS_ERR(state))
  51. return PTR_ERR(state);
  52. new_state = &state->hwmixer;
  53. for (i = 0; i < mdp5_kms->num_hwmixers; i++) {
  54. struct mdp5_hw_mixer *cur = mdp5_kms->hwmixers[i];
  55. /*
  56. * skip if already in-use by a different CRTC. If there is a
  57. * mixer already assigned to this CRTC, it means this call is
  58. * a request to get an additional right mixer. Assume that the
  59. * existing mixer is the 'left' one, and try to see if we can
  60. * get its corresponding 'right' pair.
  61. */
  62. if (new_state->hwmixer_to_crtc[cur->idx] &&
  63. new_state->hwmixer_to_crtc[cur->idx] != crtc)
  64. continue;
  65. /* skip if doesn't support some required caps: */
  66. if (caps & ~cur->caps)
  67. continue;
  68. if (r_mixer) {
  69. int pair_idx;
  70. pair_idx = get_right_pair_idx(mdp5_kms, cur->lm);
  71. if (pair_idx < 0)
  72. return -EINVAL;
  73. if (new_state->hwmixer_to_crtc[pair_idx])
  74. continue;
  75. *r_mixer = mdp5_kms->hwmixers[pair_idx];
  76. }
  77. /*
  78. * prefer a pair-able LM over an unpairable one. We can
  79. * switch the CRTC from Normal mode to Source Split mode
  80. * without requiring a full modeset if we had already
  81. * assigned this CRTC a pair-able LM.
  82. *
  83. * TODO: There will be assignment sequences which would
  84. * result in the CRTC requiring a full modeset, even
  85. * if we have the LM resources to prevent it. For a platform
  86. * with a few displays, we don't run out of pair-able LMs
  87. * so easily. For now, ignore the possibility of requiring
  88. * a full modeset.
  89. */
  90. if (!(*mixer) || cur->caps & MDP_LM_CAP_PAIR)
  91. *mixer = cur;
  92. }
  93. if (!(*mixer))
  94. return -ENOMEM;
  95. if (r_mixer && !(*r_mixer))
  96. return -ENOMEM;
  97. DBG("assigning Layer Mixer %d to crtc %s", (*mixer)->lm, crtc->name);
  98. new_state->hwmixer_to_crtc[(*mixer)->idx] = crtc;
  99. if (r_mixer) {
  100. DBG("assigning Right Layer Mixer %d to crtc %s", (*r_mixer)->lm,
  101. crtc->name);
  102. new_state->hwmixer_to_crtc[(*r_mixer)->idx] = crtc;
  103. }
  104. return 0;
  105. }
  106. void mdp5_mixer_release(struct drm_atomic_state *s, struct mdp5_hw_mixer *mixer)
  107. {
  108. struct mdp5_state *state = mdp5_get_state(s);
  109. struct mdp5_hw_mixer_state *new_state = &state->hwmixer;
  110. if (!mixer)
  111. return;
  112. if (WARN_ON(!new_state->hwmixer_to_crtc[mixer->idx]))
  113. return;
  114. DBG("%s: release from crtc %s", mixer->name,
  115. new_state->hwmixer_to_crtc[mixer->idx]->name);
  116. new_state->hwmixer_to_crtc[mixer->idx] = NULL;
  117. }
  118. void mdp5_mixer_destroy(struct mdp5_hw_mixer *mixer)
  119. {
  120. kfree(mixer);
  121. }
  122. static const char * const mixer_names[] = {
  123. "LM0", "LM1", "LM2", "LM3", "LM4", "LM5",
  124. };
  125. struct mdp5_hw_mixer *mdp5_mixer_init(const struct mdp5_lm_instance *lm)
  126. {
  127. struct mdp5_hw_mixer *mixer;
  128. mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
  129. if (!mixer)
  130. return ERR_PTR(-ENOMEM);
  131. mixer->name = mixer_names[lm->id];
  132. mixer->lm = lm->id;
  133. mixer->caps = lm->caps;
  134. mixer->pp = lm->pp;
  135. mixer->dspp = lm->dspp;
  136. mixer->flush_mask = mdp_ctl_flush_mask_lm(lm->id);
  137. return mixer;
  138. }