ovly507e.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 "ovly.h"
  23. #include "atom.h"
  24. #include <drm/drm_atomic_helper.h>
  25. #include <drm/drm_plane_helper.h>
  26. #include <nvif/cl507e.h>
  27. #include <nvif/event.h>
  28. void
  29. ovly507e_update(struct nv50_wndw *wndw, u32 *interlock)
  30. {
  31. u32 *push;
  32. if ((push = evo_wait(&wndw->wndw, 2))) {
  33. evo_mthd(push, 0x0080, 1);
  34. evo_data(push, interlock[NV50_DISP_INTERLOCK_CORE]);
  35. evo_kick(push, &wndw->wndw);
  36. }
  37. }
  38. void
  39. ovly507e_scale_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  40. {
  41. u32 *push;
  42. if ((push = evo_wait(&wndw->wndw, 4))) {
  43. evo_mthd(push, 0x00e0, 3);
  44. evo_data(push, asyw->scale.sy << 16 | asyw->scale.sx);
  45. evo_data(push, asyw->scale.sh << 16 | asyw->scale.sw);
  46. evo_data(push, asyw->scale.dw);
  47. evo_kick(push, &wndw->wndw);
  48. }
  49. }
  50. void
  51. ovly507e_image_clr(struct nv50_wndw *wndw)
  52. {
  53. u32 *push;
  54. if ((push = evo_wait(&wndw->wndw, 4))) {
  55. evo_mthd(push, 0x0084, 1);
  56. evo_data(push, 0x00000000);
  57. evo_mthd(push, 0x00c0, 1);
  58. evo_data(push, 0x00000000);
  59. evo_kick(push, &wndw->wndw);
  60. }
  61. }
  62. static void
  63. ovly507e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  64. {
  65. u32 *push;
  66. if ((push = evo_wait(&wndw->wndw, 12))) {
  67. evo_mthd(push, 0x0084, 1);
  68. evo_data(push, asyw->image.interval << 4);
  69. evo_mthd(push, 0x00c0, 1);
  70. evo_data(push, asyw->image.handle[0]);
  71. evo_mthd(push, 0x0100, 1);
  72. evo_data(push, 0x00000002);
  73. evo_mthd(push, 0x0800, 1);
  74. evo_data(push, asyw->image.offset[0] >> 8);
  75. evo_mthd(push, 0x0808, 3);
  76. evo_data(push, asyw->image.h << 16 | asyw->image.w);
  77. evo_data(push, asyw->image.layout << 20 |
  78. (asyw->image.pitch[0] >> 8) << 8 |
  79. asyw->image.blocks[0] << 8 |
  80. asyw->image.blockh);
  81. evo_data(push, asyw->image.kind << 16 |
  82. asyw->image.format << 8 |
  83. asyw->image.colorspace);
  84. evo_kick(push, &wndw->wndw);
  85. }
  86. }
  87. void
  88. ovly507e_ntfy_clr(struct nv50_wndw *wndw)
  89. {
  90. u32 *push;
  91. if ((push = evo_wait(&wndw->wndw, 2))) {
  92. evo_mthd(push, 0x00a4, 1);
  93. evo_data(push, 0x00000000);
  94. evo_kick(push, &wndw->wndw);
  95. }
  96. }
  97. void
  98. ovly507e_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  99. {
  100. u32 *push;
  101. if ((push = evo_wait(&wndw->wndw, 3))) {
  102. evo_mthd(push, 0x00a0, 2);
  103. evo_data(push, asyw->ntfy.awaken << 30 | asyw->ntfy.offset);
  104. evo_data(push, asyw->ntfy.handle);
  105. evo_kick(push, &wndw->wndw);
  106. }
  107. }
  108. void
  109. ovly507e_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  110. struct nv50_head_atom *asyh)
  111. {
  112. asyh->ovly.cpp = 0;
  113. }
  114. int
  115. ovly507e_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  116. struct nv50_head_atom *asyh)
  117. {
  118. const struct drm_framebuffer *fb = asyw->state.fb;
  119. int ret;
  120. ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
  121. DRM_PLANE_HELPER_NO_SCALING,
  122. DRM_PLANE_HELPER_NO_SCALING,
  123. true, true);
  124. if (ret)
  125. return ret;
  126. asyh->ovly.cpp = fb->format->cpp[0];
  127. return 0;
  128. }
  129. #include "nouveau_bo.h"
  130. static const struct nv50_wndw_func
  131. ovly507e = {
  132. .acquire = ovly507e_acquire,
  133. .release = ovly507e_release,
  134. .ntfy_set = ovly507e_ntfy_set,
  135. .ntfy_clr = ovly507e_ntfy_clr,
  136. .ntfy_reset = base507c_ntfy_reset,
  137. .ntfy_wait_begun = base507c_ntfy_wait_begun,
  138. .image_set = ovly507e_image_set,
  139. .image_clr = ovly507e_image_clr,
  140. .scale_set = ovly507e_scale_set,
  141. .update = ovly507e_update,
  142. };
  143. static const u32
  144. ovly507e_format[] = {
  145. DRM_FORMAT_YUYV,
  146. DRM_FORMAT_UYVY,
  147. DRM_FORMAT_XRGB8888,
  148. DRM_FORMAT_ARGB8888,
  149. DRM_FORMAT_XRGB1555,
  150. DRM_FORMAT_ARGB1555,
  151. 0
  152. };
  153. int
  154. ovly507e_new_(const struct nv50_wndw_func *func, const u32 *format,
  155. struct nouveau_drm *drm, int head, s32 oclass, u32 interlock_data,
  156. struct nv50_wndw **pwndw)
  157. {
  158. struct nv50_disp_overlay_channel_dma_v0 args = {
  159. .head = head,
  160. };
  161. struct nv50_disp *disp = nv50_disp(drm->dev);
  162. struct nv50_wndw *wndw;
  163. int ret;
  164. ret = nv50_wndw_new_(func, drm->dev, DRM_PLANE_TYPE_OVERLAY,
  165. "ovly", head, format, BIT(head),
  166. NV50_DISP_INTERLOCK_OVLY, interlock_data,
  167. &wndw);
  168. if (*pwndw = wndw, ret)
  169. return ret;
  170. ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
  171. &oclass, 0, &args, sizeof(args),
  172. disp->sync->bo.offset, &wndw->wndw);
  173. if (ret) {
  174. NV_ERROR(drm, "ovly%04x allocation failed: %d\n", oclass, ret);
  175. return ret;
  176. }
  177. ret = nvif_notify_init(&wndw->wndw.base.user, wndw->notify.func, false,
  178. NV50_DISP_OVERLAY_CHANNEL_DMA_V0_NTFY_UEVENT,
  179. &(struct nvif_notify_uevent_req) {},
  180. sizeof(struct nvif_notify_uevent_req),
  181. sizeof(struct nvif_notify_uevent_rep),
  182. &wndw->notify);
  183. if (ret)
  184. return ret;
  185. wndw->ntfy = NV50_DISP_OVLY_NTFY(wndw->id);
  186. wndw->sema = NV50_DISP_OVLY_SEM0(wndw->id);
  187. wndw->data = 0x00000000;
  188. return 0;
  189. }
  190. int
  191. ovly507e_new(struct nouveau_drm *drm, int head, s32 oclass,
  192. struct nv50_wndw **pwndw)
  193. {
  194. return ovly507e_new_(&ovly507e, ovly507e_format, drm, head, oclass,
  195. 0x00000004 << (head * 8), pwndw);
  196. }