nv50_cursor.c 4.0 KB

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