base507c.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 "base.h"
  23. #include <nvif/cl507c.h>
  24. #include <nvif/event.h>
  25. #include <drm/drm_atomic_helper.h>
  26. #include <drm/drm_plane_helper.h>
  27. #include "nouveau_bo.h"
  28. void
  29. base507c_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. base507c_image_clr(struct nv50_wndw *wndw)
  40. {
  41. u32 *push;
  42. if ((push = evo_wait(&wndw->wndw, 4))) {
  43. evo_mthd(push, 0x0084, 1);
  44. evo_data(push, 0x00000000);
  45. evo_mthd(push, 0x00c0, 1);
  46. evo_data(push, 0x00000000);
  47. evo_kick(push, &wndw->wndw);
  48. }
  49. }
  50. static void
  51. base507c_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  52. {
  53. u32 *push;
  54. if ((push = evo_wait(&wndw->wndw, 10))) {
  55. evo_mthd(push, 0x0084, 1);
  56. evo_data(push, asyw->image.mode << 8 |
  57. asyw->image.interval << 4);
  58. evo_mthd(push, 0x00c0, 1);
  59. evo_data(push, asyw->image.handle[0]);
  60. evo_mthd(push, 0x0800, 5);
  61. evo_data(push, asyw->image.offset[0] >> 8);
  62. evo_data(push, 0x00000000);
  63. evo_data(push, asyw->image.h << 16 | asyw->image.w);
  64. evo_data(push, asyw->image.layout << 20 |
  65. (asyw->image.pitch[0] >> 8) << 8 |
  66. asyw->image.blocks[0] << 8 |
  67. asyw->image.blockh);
  68. evo_data(push, asyw->image.kind << 16 |
  69. asyw->image.format << 8);
  70. evo_kick(push, &wndw->wndw);
  71. }
  72. }
  73. void
  74. base507c_xlut_clr(struct nv50_wndw *wndw)
  75. {
  76. u32 *push;
  77. if ((push = evo_wait(&wndw->wndw, 2))) {
  78. evo_mthd(push, 0x00e0, 1);
  79. evo_data(push, 0x00000000);
  80. evo_kick(push, &wndw->wndw);
  81. }
  82. }
  83. void
  84. base507c_xlut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  85. {
  86. u32 *push;
  87. if ((push = evo_wait(&wndw->wndw, 2))) {
  88. evo_mthd(push, 0x00e0, 1);
  89. evo_data(push, 0x40000000);
  90. evo_kick(push, &wndw->wndw);
  91. }
  92. }
  93. int
  94. base507c_ntfy_wait_begun(struct nouveau_bo *bo, u32 offset,
  95. struct nvif_device *device)
  96. {
  97. s64 time = nvif_msec(device, 2000ULL,
  98. u32 data = nouveau_bo_rd32(bo, offset / 4);
  99. if ((data & 0xc0000000) == 0x40000000)
  100. break;
  101. usleep_range(1, 2);
  102. );
  103. return time < 0 ? time : 0;
  104. }
  105. void
  106. base507c_ntfy_clr(struct nv50_wndw *wndw)
  107. {
  108. u32 *push;
  109. if ((push = evo_wait(&wndw->wndw, 2))) {
  110. evo_mthd(push, 0x00a4, 1);
  111. evo_data(push, 0x00000000);
  112. evo_kick(push, &wndw->wndw);
  113. }
  114. }
  115. void
  116. base507c_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  117. {
  118. u32 *push;
  119. if ((push = evo_wait(&wndw->wndw, 3))) {
  120. evo_mthd(push, 0x00a0, 2);
  121. evo_data(push, asyw->ntfy.awaken << 30 | asyw->ntfy.offset);
  122. evo_data(push, asyw->ntfy.handle);
  123. evo_kick(push, &wndw->wndw);
  124. }
  125. }
  126. void
  127. base507c_ntfy_reset(struct nouveau_bo *bo, u32 offset)
  128. {
  129. nouveau_bo_wr32(bo, offset / 4, 0x00000000);
  130. }
  131. void
  132. base507c_sema_clr(struct nv50_wndw *wndw)
  133. {
  134. u32 *push;
  135. if ((push = evo_wait(&wndw->wndw, 2))) {
  136. evo_mthd(push, 0x0094, 1);
  137. evo_data(push, 0x00000000);
  138. evo_kick(push, &wndw->wndw);
  139. }
  140. }
  141. void
  142. base507c_sema_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  143. {
  144. u32 *push;
  145. if ((push = evo_wait(&wndw->wndw, 5))) {
  146. evo_mthd(push, 0x0088, 4);
  147. evo_data(push, asyw->sema.offset);
  148. evo_data(push, asyw->sema.acquire);
  149. evo_data(push, asyw->sema.release);
  150. evo_data(push, asyw->sema.handle);
  151. evo_kick(push, &wndw->wndw);
  152. }
  153. }
  154. void
  155. base507c_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  156. struct nv50_head_atom *asyh)
  157. {
  158. asyh->base.cpp = 0;
  159. }
  160. int
  161. base507c_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  162. struct nv50_head_atom *asyh)
  163. {
  164. const struct drm_framebuffer *fb = asyw->state.fb;
  165. int ret;
  166. if (!fb->format->depth)
  167. return -EINVAL;
  168. ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
  169. DRM_PLANE_HELPER_NO_SCALING,
  170. DRM_PLANE_HELPER_NO_SCALING,
  171. false, true);
  172. if (ret)
  173. return ret;
  174. if (!wndw->func->ilut) {
  175. if ((asyh->base.cpp != 1) ^ (fb->format->cpp[0] != 1))
  176. asyh->state.color_mgmt_changed = true;
  177. }
  178. asyh->base.depth = fb->format->depth;
  179. asyh->base.cpp = fb->format->cpp[0];
  180. asyh->base.x = asyw->state.src.x1 >> 16;
  181. asyh->base.y = asyw->state.src.y1 >> 16;
  182. asyh->base.w = asyw->state.fb->width;
  183. asyh->base.h = asyw->state.fb->height;
  184. return 0;
  185. }
  186. const u32
  187. base507c_format[] = {
  188. DRM_FORMAT_C8,
  189. DRM_FORMAT_RGB565,
  190. DRM_FORMAT_XRGB1555,
  191. DRM_FORMAT_ARGB1555,
  192. DRM_FORMAT_XRGB8888,
  193. DRM_FORMAT_ARGB8888,
  194. DRM_FORMAT_XBGR2101010,
  195. DRM_FORMAT_ABGR2101010,
  196. DRM_FORMAT_XBGR8888,
  197. DRM_FORMAT_ABGR8888,
  198. 0
  199. };
  200. static const struct nv50_wndw_func
  201. base507c = {
  202. .acquire = base507c_acquire,
  203. .release = base507c_release,
  204. .sema_set = base507c_sema_set,
  205. .sema_clr = base507c_sema_clr,
  206. .ntfy_reset = base507c_ntfy_reset,
  207. .ntfy_set = base507c_ntfy_set,
  208. .ntfy_clr = base507c_ntfy_clr,
  209. .ntfy_wait_begun = base507c_ntfy_wait_begun,
  210. .olut_core = 1,
  211. .xlut_set = base507c_xlut_set,
  212. .xlut_clr = base507c_xlut_clr,
  213. .image_set = base507c_image_set,
  214. .image_clr = base507c_image_clr,
  215. .update = base507c_update,
  216. };
  217. int
  218. base507c_new_(const struct nv50_wndw_func *func, const u32 *format,
  219. struct nouveau_drm *drm, int head, s32 oclass, u32 interlock_data,
  220. struct nv50_wndw **pwndw)
  221. {
  222. struct nv50_disp_base_channel_dma_v0 args = {
  223. .head = head,
  224. };
  225. struct nv50_disp *disp = nv50_disp(drm->dev);
  226. struct nv50_wndw *wndw;
  227. int ret;
  228. ret = nv50_wndw_new_(func, drm->dev, DRM_PLANE_TYPE_PRIMARY,
  229. "base", head, format, BIT(head),
  230. NV50_DISP_INTERLOCK_BASE, interlock_data, &wndw);
  231. if (*pwndw = wndw, ret)
  232. return ret;
  233. ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
  234. &oclass, head, &args, sizeof(args),
  235. disp->sync->bo.offset, &wndw->wndw);
  236. if (ret) {
  237. NV_ERROR(drm, "base%04x allocation failed: %d\n", oclass, ret);
  238. return ret;
  239. }
  240. ret = nvif_notify_init(&wndw->wndw.base.user, wndw->notify.func,
  241. false, NV50_DISP_BASE_CHANNEL_DMA_V0_NTFY_UEVENT,
  242. &(struct nvif_notify_uevent_req) {},
  243. sizeof(struct nvif_notify_uevent_req),
  244. sizeof(struct nvif_notify_uevent_rep),
  245. &wndw->notify);
  246. if (ret)
  247. return ret;
  248. wndw->ntfy = NV50_DISP_BASE_NTFY(wndw->id);
  249. wndw->sema = NV50_DISP_BASE_SEM0(wndw->id);
  250. wndw->data = 0x00000000;
  251. return 0;
  252. }
  253. int
  254. base507c_new(struct nouveau_drm *drm, int head, s32 oclass,
  255. struct nv50_wndw **pwndw)
  256. {
  257. return base507c_new_(&base507c, base507c_format, drm, head, oclass,
  258. 0x00000002 << (head * 8), pwndw);
  259. }