curs507a.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright 2018 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "curs.h"
  23. #include "core.h"
  24. #include "head.h"
  25. #include <nvif/if0014.h>
  26. #include <nvif/timer.h>
  27. #include <nvhw/class/cl507a.h>
  28. #include <drm/drm_atomic_helper.h>
  29. bool
  30. curs507a_space(struct nv50_wndw *wndw)
  31. {
  32. nvif_msec(&nouveau_drm(wndw->plane.dev)->client.device, 100,
  33. if (NVIF_TV32(&wndw->wimm.base.user, NV507A, FREE, COUNT, >=, 4))
  34. return true;
  35. );
  36. WARN_ON(1);
  37. return false;
  38. }
  39. static int
  40. curs507a_update(struct nv50_wndw *wndw, u32 *interlock)
  41. {
  42. struct nvif_object *user = &wndw->wimm.base.user;
  43. int ret = nvif_chan_wait(&wndw->wimm, 1);
  44. if (ret == 0) {
  45. NVIF_WR32(user, NV507A, UPDATE,
  46. NVDEF(NV507A, UPDATE, INTERLOCK_WITH_CORE, DISABLE));
  47. }
  48. return ret;
  49. }
  50. static int
  51. curs507a_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  52. {
  53. struct nvif_object *user = &wndw->wimm.base.user;
  54. int ret = nvif_chan_wait(&wndw->wimm, 1);
  55. if (ret == 0) {
  56. NVIF_WR32(user, NV507A, SET_CURSOR_HOT_SPOT_POINT_OUT,
  57. NVVAL(NV507A, SET_CURSOR_HOT_SPOT_POINT_OUT, X, asyw->point.x) |
  58. NVVAL(NV507A, SET_CURSOR_HOT_SPOT_POINT_OUT, Y, asyw->point.y));
  59. }
  60. return ret;
  61. }
  62. const struct nv50_wimm_func
  63. curs507a = {
  64. .point = curs507a_point,
  65. .update = curs507a_update,
  66. };
  67. static void
  68. curs507a_prepare(struct nv50_wndw *wndw, struct nv50_head_atom *asyh,
  69. struct nv50_wndw_atom *asyw)
  70. {
  71. u32 handle = nv50_disp(wndw->plane.dev)->core->chan.vram.handle;
  72. u32 offset = asyw->image.offset[0];
  73. if (asyh->curs.handle != handle || asyh->curs.offset != offset) {
  74. asyh->curs.handle = handle;
  75. asyh->curs.offset = offset;
  76. asyh->set.curs = asyh->curs.visible;
  77. }
  78. }
  79. static void
  80. curs507a_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  81. struct nv50_head_atom *asyh)
  82. {
  83. asyh->curs.visible = false;
  84. }
  85. static int
  86. curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  87. struct nv50_head_atom *asyh)
  88. {
  89. struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev);
  90. struct nv50_head *head = nv50_head(asyw->state.crtc);
  91. int ret;
  92. ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
  93. DRM_PLANE_NO_SCALING,
  94. DRM_PLANE_NO_SCALING,
  95. true, true);
  96. asyh->curs.visible = asyw->state.visible;
  97. if (ret || !asyh->curs.visible)
  98. return ret;
  99. if (asyw->state.crtc_w != asyw->state.crtc_h) {
  100. NV_ATOMIC(drm, "Plane width/height must be equal for cursors\n");
  101. return -EINVAL;
  102. }
  103. if (asyw->image.w != asyw->state.crtc_w) {
  104. NV_ATOMIC(drm, "Plane width must be equal to fb width for cursors (height can be larger though)\n");
  105. return -EINVAL;
  106. }
  107. if (asyw->state.src_x || asyw->state.src_y) {
  108. NV_ATOMIC(drm, "Cursor planes do not support framebuffer offsets\n");
  109. return -EINVAL;
  110. }
  111. ret = head->func->curs_layout(head, asyw, asyh);
  112. if (ret)
  113. return ret;
  114. return head->func->curs_format(head, asyw, asyh);
  115. }
  116. static const u32
  117. curs507a_format[] = {
  118. DRM_FORMAT_ARGB8888,
  119. 0
  120. };
  121. static const struct nv50_wndw_func
  122. curs507a_wndw = {
  123. .acquire = curs507a_acquire,
  124. .release = curs507a_release,
  125. .prepare = curs507a_prepare,
  126. };
  127. int
  128. curs507a_new_(const struct nv50_wimm_func *func, struct nouveau_drm *drm,
  129. int head, s32 oclass, u32 interlock_data,
  130. struct nv50_wndw **pwndw)
  131. {
  132. struct nvif_disp_chan_v0 args = {
  133. .id = head,
  134. };
  135. struct nv50_disp *disp = nv50_disp(drm->dev);
  136. struct nv50_wndw *wndw;
  137. int ret;
  138. ret = nv50_wndw_new_(&curs507a_wndw, drm->dev, DRM_PLANE_TYPE_CURSOR,
  139. "curs", head, curs507a_format, BIT(head),
  140. NV50_DISP_INTERLOCK_CURS, interlock_data, &wndw);
  141. if (*pwndw = wndw, ret)
  142. return ret;
  143. ret = nvif_object_ctor(&disp->disp->object, "kmsCurs", 0, oclass,
  144. &args, sizeof(args), &wndw->wimm.base.user);
  145. if (ret) {
  146. NV_ERROR(drm, "curs%04x allocation failed: %d\n", oclass, ret);
  147. return ret;
  148. }
  149. nvif_object_map(&wndw->wimm.base.user, NULL, 0);
  150. wndw->immd = func;
  151. wndw->ctxdma.parent = NULL;
  152. return 0;
  153. }
  154. int
  155. curs507a_new(struct nouveau_drm *drm, int head, s32 oclass,
  156. struct nv50_wndw **pwndw)
  157. {
  158. return curs507a_new_(&curs507a, drm, head, oclass,
  159. 0x00000001 << (head * 8), pwndw);
  160. }