curs507a.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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/cl507a.h>
  26. #include <drm/drm_atomic_helper.h>
  27. #include <drm/drm_plane_helper.h>
  28. static void
  29. curs507a_update(struct nv50_wndw *wndw, u32 *interlock)
  30. {
  31. nvif_wr32(&wndw->wimm.base.user, 0x0080, 0x00000000);
  32. }
  33. static void
  34. curs507a_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  35. {
  36. nvif_wr32(&wndw->wimm.base.user, 0x0084, asyw->point.y << 16 |
  37. asyw->point.x);
  38. }
  39. const struct nv50_wimm_func
  40. curs507a = {
  41. .point = curs507a_point,
  42. .update = curs507a_update,
  43. };
  44. static void
  45. curs507a_prepare(struct nv50_wndw *wndw, struct nv50_head_atom *asyh,
  46. struct nv50_wndw_atom *asyw)
  47. {
  48. u32 handle = nv50_disp(wndw->plane.dev)->core->chan.vram.handle;
  49. u32 offset = asyw->image.offset[0];
  50. if (asyh->curs.handle != handle || asyh->curs.offset != offset) {
  51. asyh->curs.handle = handle;
  52. asyh->curs.offset = offset;
  53. asyh->set.curs = asyh->curs.visible;
  54. }
  55. }
  56. static void
  57. curs507a_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  58. struct nv50_head_atom *asyh)
  59. {
  60. asyh->curs.visible = false;
  61. }
  62. static int
  63. curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  64. struct nv50_head_atom *asyh)
  65. {
  66. struct nv50_head *head = nv50_head(asyw->state.crtc);
  67. int ret;
  68. ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
  69. DRM_PLANE_HELPER_NO_SCALING,
  70. DRM_PLANE_HELPER_NO_SCALING,
  71. true, true);
  72. asyh->curs.visible = asyw->state.visible;
  73. if (ret || !asyh->curs.visible)
  74. return ret;
  75. if (asyw->image.w != asyw->image.h)
  76. return -EINVAL;
  77. ret = head->func->curs_layout(head, asyw, asyh);
  78. if (ret)
  79. return ret;
  80. return head->func->curs_format(head, asyw, asyh);
  81. }
  82. static const u32
  83. curs507a_format[] = {
  84. DRM_FORMAT_ARGB8888,
  85. 0
  86. };
  87. static const struct nv50_wndw_func
  88. curs507a_wndw = {
  89. .acquire = curs507a_acquire,
  90. .release = curs507a_release,
  91. .prepare = curs507a_prepare,
  92. };
  93. int
  94. curs507a_new_(const struct nv50_wimm_func *func, struct nouveau_drm *drm,
  95. int head, s32 oclass, u32 interlock_data,
  96. struct nv50_wndw **pwndw)
  97. {
  98. struct nv50_disp_cursor_v0 args = {
  99. .head = head,
  100. };
  101. struct nv50_disp *disp = nv50_disp(drm->dev);
  102. struct nv50_wndw *wndw;
  103. int ret;
  104. ret = nv50_wndw_new_(&curs507a_wndw, drm->dev, DRM_PLANE_TYPE_CURSOR,
  105. "curs", head, curs507a_format, BIT(head),
  106. NV50_DISP_INTERLOCK_CURS, interlock_data, &wndw);
  107. if (*pwndw = wndw, ret)
  108. return ret;
  109. ret = nvif_object_init(&disp->disp->object, 0, oclass, &args,
  110. sizeof(args), &wndw->wimm.base.user);
  111. if (ret) {
  112. NV_ERROR(drm, "curs%04x allocation failed: %d\n", oclass, ret);
  113. return ret;
  114. }
  115. nvif_object_map(&wndw->wimm.base.user, NULL, 0);
  116. wndw->immd = func;
  117. wndw->ctxdma.parent = NULL;
  118. return 0;
  119. }
  120. int
  121. curs507a_new(struct nouveau_drm *drm, int head, s32 oclass,
  122. struct nv50_wndw **pwndw)
  123. {
  124. return curs507a_new_(&curs507a, drm, head, oclass,
  125. 0x00000001 << (head * 8), pwndw);
  126. }