nv50_cursor.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <drm/drmP.h>
  27. #include "nouveau_drm.h"
  28. #include "nouveau_dma.h"
  29. #include "nouveau_crtc.h"
  30. #include "nv50_display.h"
  31. static void
  32. nv50_cursor_show(struct nouveau_crtc *nv_crtc, bool update)
  33. {
  34. struct drm_device *dev = nv_crtc->base.dev;
  35. struct nouveau_drm *drm = nouveau_drm(dev);
  36. struct nouveau_channel *evo = nv50_display(dev)->master;
  37. int ret;
  38. NV_DEBUG(drm, "\n");
  39. if (update && nv_crtc->cursor.visible)
  40. return;
  41. ret = RING_SPACE(evo, (nv_device(drm->device)->chipset != 0x50 ? 5 : 3) + update * 2);
  42. if (ret) {
  43. NV_ERROR(drm, "no space while unhiding cursor\n");
  44. return;
  45. }
  46. if (nv_device(drm->device)->chipset != 0x50) {
  47. BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1);
  48. OUT_RING(evo, NvEvoVRAM);
  49. }
  50. BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2);
  51. OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_SHOW);
  52. OUT_RING(evo, nv_crtc->cursor.offset >> 8);
  53. if (update) {
  54. BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
  55. OUT_RING(evo, 0);
  56. FIRE_RING(evo);
  57. nv_crtc->cursor.visible = true;
  58. }
  59. }
  60. static void
  61. nv50_cursor_hide(struct nouveau_crtc *nv_crtc, bool update)
  62. {
  63. struct drm_device *dev = nv_crtc->base.dev;
  64. struct nouveau_drm *drm = nouveau_drm(dev);
  65. struct nouveau_channel *evo = nv50_display(dev)->master;
  66. int ret;
  67. NV_DEBUG(drm, "\n");
  68. if (update && !nv_crtc->cursor.visible)
  69. return;
  70. ret = RING_SPACE(evo, (nv_device(drm->device)->chipset != 0x50 ? 5 : 3) + update * 2);
  71. if (ret) {
  72. NV_ERROR(drm, "no space while hiding cursor\n");
  73. return;
  74. }
  75. BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2);
  76. OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_HIDE);
  77. OUT_RING(evo, 0);
  78. if (nv_device(drm->device)->chipset != 0x50) {
  79. BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1);
  80. OUT_RING(evo, NV84_EVO_CRTC_CURSOR_DMA_HANDLE_NONE);
  81. }
  82. if (update) {
  83. BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
  84. OUT_RING(evo, 0);
  85. FIRE_RING(evo);
  86. nv_crtc->cursor.visible = false;
  87. }
  88. }
  89. static void
  90. nv50_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
  91. {
  92. struct nouveau_device *device = nouveau_dev(nv_crtc->base.dev);
  93. nv_crtc->cursor_saved_x = x; nv_crtc->cursor_saved_y = y;
  94. nv_wr32(device, NV50_PDISPLAY_CURSOR_USER_POS(nv_crtc->index),
  95. ((y & 0xFFFF) << 16) | (x & 0xFFFF));
  96. /* Needed to make the cursor move. */
  97. nv_wr32(device, NV50_PDISPLAY_CURSOR_USER_POS_CTRL(nv_crtc->index), 0);
  98. }
  99. static void
  100. nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
  101. {
  102. if (offset == nv_crtc->cursor.offset)
  103. return;
  104. nv_crtc->cursor.offset = offset;
  105. if (nv_crtc->cursor.visible) {
  106. nv_crtc->cursor.visible = false;
  107. nv_crtc->cursor.show(nv_crtc, true);
  108. }
  109. }
  110. int
  111. nv50_cursor_init(struct nouveau_crtc *nv_crtc)
  112. {
  113. nv_crtc->cursor.set_offset = nv50_cursor_set_offset;
  114. nv_crtc->cursor.set_pos = nv50_cursor_set_pos;
  115. nv_crtc->cursor.hide = nv50_cursor_hide;
  116. nv_crtc->cursor.show = nv50_cursor_show;
  117. return 0;
  118. }