nv50_cursor.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (C) 2008 Maarten Maathuis.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "drmP.h"
  27. #define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO)
  28. #include "nouveau_reg.h"
  29. #include "nouveau_drv.h"
  30. #include "nouveau_crtc.h"
  31. #include "nv50_display.h"
  32. static void
  33. nv50_cursor_show(struct nouveau_crtc *nv_crtc, bool update)
  34. {
  35. struct drm_device *dev = nv_crtc->base.dev;
  36. struct drm_nouveau_private *dev_priv = dev->dev_private;
  37. struct nouveau_channel *evo = nv50_display(dev)->master;
  38. int ret;
  39. NV_DEBUG_KMS(dev, "\n");
  40. if (update && nv_crtc->cursor.visible)
  41. return;
  42. ret = RING_SPACE(evo, (dev_priv->chipset != 0x50 ? 5 : 3) + update * 2);
  43. if (ret) {
  44. NV_ERROR(dev, "no space while unhiding cursor\n");
  45. return;
  46. }
  47. if (dev_priv->chipset != 0x50) {
  48. BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1);
  49. OUT_RING(evo, NvEvoVRAM);
  50. }
  51. BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2);
  52. OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_SHOW);
  53. OUT_RING(evo, nv_crtc->cursor.offset >> 8);
  54. if (update) {
  55. BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
  56. OUT_RING(evo, 0);
  57. FIRE_RING(evo);
  58. nv_crtc->cursor.visible = true;
  59. }
  60. }
  61. static void
  62. nv50_cursor_hide(struct nouveau_crtc *nv_crtc, bool update)
  63. {
  64. struct drm_device *dev = nv_crtc->base.dev;
  65. struct drm_nouveau_private *dev_priv = dev->dev_private;
  66. struct nouveau_channel *evo = nv50_display(dev)->master;
  67. int ret;
  68. NV_DEBUG_KMS(dev, "\n");
  69. if (update && !nv_crtc->cursor.visible)
  70. return;
  71. ret = RING_SPACE(evo, (dev_priv->chipset != 0x50 ? 5 : 3) + update * 2);
  72. if (ret) {
  73. NV_ERROR(dev, "no space while hiding cursor\n");
  74. return;
  75. }
  76. BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2);
  77. OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_HIDE);
  78. OUT_RING(evo, 0);
  79. if (dev_priv->chipset != 0x50) {
  80. BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1);
  81. OUT_RING(evo, NV84_EVO_CRTC_CURSOR_DMA_HANDLE_NONE);
  82. }
  83. if (update) {
  84. BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
  85. OUT_RING(evo, 0);
  86. FIRE_RING(evo);
  87. nv_crtc->cursor.visible = false;
  88. }
  89. }
  90. static void
  91. nv50_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
  92. {
  93. struct drm_device *dev = nv_crtc->base.dev;
  94. nv_crtc->cursor_saved_x = x; nv_crtc->cursor_saved_y = y;
  95. nv_wr32(dev, NV50_PDISPLAY_CURSOR_USER_POS(nv_crtc->index),
  96. ((y & 0xFFFF) << 16) | (x & 0xFFFF));
  97. /* Needed to make the cursor move. */
  98. nv_wr32(dev, NV50_PDISPLAY_CURSOR_USER_POS_CTRL(nv_crtc->index), 0);
  99. }
  100. static void
  101. nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
  102. {
  103. NV_DEBUG_KMS(nv_crtc->base.dev, "\n");
  104. if (offset == nv_crtc->cursor.offset)
  105. return;
  106. nv_crtc->cursor.offset = offset;
  107. if (nv_crtc->cursor.visible) {
  108. nv_crtc->cursor.visible = false;
  109. nv_crtc->cursor.show(nv_crtc, true);
  110. }
  111. }
  112. int
  113. nv50_cursor_init(struct nouveau_crtc *nv_crtc)
  114. {
  115. nv_crtc->cursor.set_offset = nv50_cursor_set_offset;
  116. nv_crtc->cursor.set_pos = nv50_cursor_set_pos;
  117. nv_crtc->cursor.hide = nv50_cursor_hide;
  118. nv_crtc->cursor.show = nv50_cursor_show;
  119. return 0;
  120. }