mdp_kms.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2013 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 "msm_drv.h"
  18. #include "mdp_kms.h"
  19. struct mdp_irq_wait {
  20. struct mdp_irq irq;
  21. int count;
  22. };
  23. static DECLARE_WAIT_QUEUE_HEAD(wait_event);
  24. static DEFINE_SPINLOCK(list_lock);
  25. static void update_irq(struct mdp_kms *mdp_kms)
  26. {
  27. struct mdp_irq *irq;
  28. uint32_t irqmask = mdp_kms->vblank_mask;
  29. assert_spin_locked(&list_lock);
  30. list_for_each_entry(irq, &mdp_kms->irq_list, node)
  31. irqmask |= irq->irqmask;
  32. mdp_kms->funcs->set_irqmask(mdp_kms, irqmask, mdp_kms->cur_irq_mask);
  33. mdp_kms->cur_irq_mask = irqmask;
  34. }
  35. /* if an mdp_irq's irqmask has changed, such as when mdp5 crtc<->encoder
  36. * link changes, this must be called to figure out the new global irqmask
  37. */
  38. void mdp_irq_update(struct mdp_kms *mdp_kms)
  39. {
  40. unsigned long flags;
  41. spin_lock_irqsave(&list_lock, flags);
  42. update_irq(mdp_kms);
  43. spin_unlock_irqrestore(&list_lock, flags);
  44. }
  45. void mdp_dispatch_irqs(struct mdp_kms *mdp_kms, uint32_t status)
  46. {
  47. struct mdp_irq *handler, *n;
  48. unsigned long flags;
  49. spin_lock_irqsave(&list_lock, flags);
  50. mdp_kms->in_irq = true;
  51. list_for_each_entry_safe(handler, n, &mdp_kms->irq_list, node) {
  52. if (handler->irqmask & status) {
  53. spin_unlock_irqrestore(&list_lock, flags);
  54. handler->irq(handler, handler->irqmask & status);
  55. spin_lock_irqsave(&list_lock, flags);
  56. }
  57. }
  58. mdp_kms->in_irq = false;
  59. update_irq(mdp_kms);
  60. spin_unlock_irqrestore(&list_lock, flags);
  61. }
  62. void mdp_update_vblank_mask(struct mdp_kms *mdp_kms, uint32_t mask, bool enable)
  63. {
  64. unsigned long flags;
  65. spin_lock_irqsave(&list_lock, flags);
  66. if (enable)
  67. mdp_kms->vblank_mask |= mask;
  68. else
  69. mdp_kms->vblank_mask &= ~mask;
  70. update_irq(mdp_kms);
  71. spin_unlock_irqrestore(&list_lock, flags);
  72. }
  73. static void wait_irq(struct mdp_irq *irq, uint32_t irqstatus)
  74. {
  75. struct mdp_irq_wait *wait =
  76. container_of(irq, struct mdp_irq_wait, irq);
  77. wait->count--;
  78. wake_up_all(&wait_event);
  79. }
  80. void mdp_irq_wait(struct mdp_kms *mdp_kms, uint32_t irqmask)
  81. {
  82. struct mdp_irq_wait wait = {
  83. .irq = {
  84. .irq = wait_irq,
  85. .irqmask = irqmask,
  86. },
  87. .count = 1,
  88. };
  89. mdp_irq_register(mdp_kms, &wait.irq);
  90. wait_event_timeout(wait_event, (wait.count <= 0),
  91. msecs_to_jiffies(100));
  92. mdp_irq_unregister(mdp_kms, &wait.irq);
  93. }
  94. void mdp_irq_register(struct mdp_kms *mdp_kms, struct mdp_irq *irq)
  95. {
  96. unsigned long flags;
  97. bool needs_update = false;
  98. spin_lock_irqsave(&list_lock, flags);
  99. if (!irq->registered) {
  100. irq->registered = true;
  101. list_add(&irq->node, &mdp_kms->irq_list);
  102. needs_update = !mdp_kms->in_irq;
  103. }
  104. spin_unlock_irqrestore(&list_lock, flags);
  105. if (needs_update)
  106. mdp_irq_update(mdp_kms);
  107. }
  108. void mdp_irq_unregister(struct mdp_kms *mdp_kms, struct mdp_irq *irq)
  109. {
  110. unsigned long flags;
  111. bool needs_update = false;
  112. spin_lock_irqsave(&list_lock, flags);
  113. if (irq->registered) {
  114. irq->registered = false;
  115. list_del(&irq->node);
  116. needs_update = !mdp_kms->in_irq;
  117. }
  118. spin_unlock_irqrestore(&list_lock, flags);
  119. if (needs_update)
  120. mdp_irq_update(mdp_kms);
  121. }