base507c.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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/if0014.h>
  24. #include <nvif/push507c.h>
  25. #include <nvif/timer.h>
  26. #include <nvhw/class/cl507c.h>
  27. #include <drm/drm_atomic_helper.h>
  28. #include <drm/drm_fourcc.h>
  29. #include "nouveau_bo.h"
  30. int
  31. base507c_update(struct nv50_wndw *wndw, u32 *interlock)
  32. {
  33. struct nvif_push *push = wndw->wndw.push;
  34. int ret;
  35. if ((ret = PUSH_WAIT(push, 2)))
  36. return ret;
  37. PUSH_MTHD(push, NV507C, UPDATE, interlock[NV50_DISP_INTERLOCK_CORE]);
  38. return PUSH_KICK(push);
  39. }
  40. int
  41. base507c_image_clr(struct nv50_wndw *wndw)
  42. {
  43. struct nvif_push *push = wndw->wndw.push;
  44. int ret;
  45. if ((ret = PUSH_WAIT(push, 4)))
  46. return ret;
  47. PUSH_MTHD(push, NV507C, SET_PRESENT_CONTROL,
  48. NVDEF(NV507C, SET_PRESENT_CONTROL, BEGIN_MODE, NON_TEARING) |
  49. NVVAL(NV507C, SET_PRESENT_CONTROL, MIN_PRESENT_INTERVAL, 0));
  50. PUSH_MTHD(push, NV507C, SET_CONTEXT_DMA_ISO, 0x00000000);
  51. return 0;
  52. }
  53. static int
  54. base507c_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  55. {
  56. struct nvif_push *push = wndw->wndw.push;
  57. int ret;
  58. if ((ret = PUSH_WAIT(push, 13)))
  59. return ret;
  60. PUSH_MTHD(push, NV507C, SET_PRESENT_CONTROL,
  61. NVVAL(NV507C, SET_PRESENT_CONTROL, BEGIN_MODE, asyw->image.mode) |
  62. NVVAL(NV507C, SET_PRESENT_CONTROL, MIN_PRESENT_INTERVAL, asyw->image.interval));
  63. PUSH_MTHD(push, NV507C, SET_CONTEXT_DMA_ISO, asyw->image.handle[0]);
  64. if (asyw->image.format == NV507C_SURFACE_SET_PARAMS_FORMAT_RF16_GF16_BF16_AF16) {
  65. PUSH_MTHD(push, NV507C, SET_PROCESSING,
  66. NVDEF(NV507C, SET_PROCESSING, USE_GAIN_OFS, ENABLE),
  67. SET_CONVERSION,
  68. NVVAL(NV507C, SET_CONVERSION, GAIN, 0) |
  69. NVVAL(NV507C, SET_CONVERSION, OFS, 0x64));
  70. } else {
  71. PUSH_MTHD(push, NV507C, SET_PROCESSING,
  72. NVDEF(NV507C, SET_PROCESSING, USE_GAIN_OFS, DISABLE),
  73. SET_CONVERSION,
  74. NVVAL(NV507C, SET_CONVERSION, GAIN, 0) |
  75. NVVAL(NV507C, SET_CONVERSION, OFS, 0));
  76. }
  77. PUSH_MTHD(push, NV507C, SURFACE_SET_OFFSET(0, 0), asyw->image.offset[0] >> 8);
  78. PUSH_MTHD(push, NV507C, SURFACE_SET_SIZE(0),
  79. NVVAL(NV507C, SURFACE_SET_SIZE, WIDTH, asyw->image.w) |
  80. NVVAL(NV507C, SURFACE_SET_SIZE, HEIGHT, asyw->image.h),
  81. SURFACE_SET_STORAGE(0),
  82. NVVAL(NV507C, SURFACE_SET_STORAGE, MEMORY_LAYOUT, asyw->image.layout) |
  83. NVVAL(NV507C, SURFACE_SET_STORAGE, PITCH, asyw->image.pitch[0] >> 8) |
  84. NVVAL(NV507C, SURFACE_SET_STORAGE, PITCH, asyw->image.blocks[0]) |
  85. NVVAL(NV507C, SURFACE_SET_STORAGE, BLOCK_HEIGHT, asyw->image.blockh),
  86. SURFACE_SET_PARAMS(0),
  87. NVVAL(NV507C, SURFACE_SET_PARAMS, FORMAT, asyw->image.format) |
  88. NVDEF(NV507C, SURFACE_SET_PARAMS, SUPER_SAMPLE, X1_AA) |
  89. NVDEF(NV507C, SURFACE_SET_PARAMS, GAMMA, LINEAR) |
  90. NVDEF(NV507C, SURFACE_SET_PARAMS, LAYOUT, FRM) |
  91. NVVAL(NV507C, SURFACE_SET_PARAMS, KIND, asyw->image.kind) |
  92. NVDEF(NV507C, SURFACE_SET_PARAMS, PART_STRIDE, PARTSTRIDE_256));
  93. return 0;
  94. }
  95. int
  96. base507c_xlut_clr(struct nv50_wndw *wndw)
  97. {
  98. struct nvif_push *push = wndw->wndw.push;
  99. int ret;
  100. if ((ret = PUSH_WAIT(push, 2)))
  101. return ret;
  102. PUSH_MTHD(push, NV507C, SET_BASE_LUT_LO,
  103. NVDEF(NV507C, SET_BASE_LUT_LO, ENABLE, DISABLE));
  104. return 0;
  105. }
  106. int
  107. base507c_xlut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  108. {
  109. struct nvif_push *push = wndw->wndw.push;
  110. int ret;
  111. if ((ret = PUSH_WAIT(push, 2)))
  112. return ret;
  113. PUSH_MTHD(push, NV507C, SET_BASE_LUT_LO,
  114. NVDEF(NV507C, SET_BASE_LUT_LO, ENABLE, USE_CORE_LUT));
  115. return 0;
  116. }
  117. int
  118. base507c_ntfy_wait_begun(struct nouveau_bo *bo, u32 offset,
  119. struct nvif_device *device)
  120. {
  121. s64 time = nvif_msec(device, 2000ULL,
  122. if (NVBO_TD32(bo, offset, NV_DISP_BASE_NOTIFIER_1, _0, STATUS, ==, BEGUN))
  123. break;
  124. usleep_range(1, 2);
  125. );
  126. return time < 0 ? time : 0;
  127. }
  128. int
  129. base507c_ntfy_clr(struct nv50_wndw *wndw)
  130. {
  131. struct nvif_push *push = wndw->wndw.push;
  132. int ret;
  133. if ((ret = PUSH_WAIT(push, 2)))
  134. return ret;
  135. PUSH_MTHD(push, NV507C, SET_CONTEXT_DMA_NOTIFIER, 0x00000000);
  136. return 0;
  137. }
  138. int
  139. base507c_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  140. {
  141. struct nvif_push *push = wndw->wndw.push;
  142. int ret;
  143. if ((ret = PUSH_WAIT(push, 3)))
  144. return ret;
  145. PUSH_MTHD(push, NV507C, SET_NOTIFIER_CONTROL,
  146. NVVAL(NV507C, SET_NOTIFIER_CONTROL, MODE, asyw->ntfy.awaken) |
  147. NVVAL(NV507C, SET_NOTIFIER_CONTROL, OFFSET, asyw->ntfy.offset >> 2),
  148. SET_CONTEXT_DMA_NOTIFIER, asyw->ntfy.handle);
  149. return 0;
  150. }
  151. void
  152. base507c_ntfy_reset(struct nouveau_bo *bo, u32 offset)
  153. {
  154. NVBO_WR32(bo, offset, NV_DISP_BASE_NOTIFIER_1, _0,
  155. NVDEF(NV_DISP_BASE_NOTIFIER_1, _0, STATUS, NOT_BEGUN));
  156. }
  157. int
  158. base507c_sema_clr(struct nv50_wndw *wndw)
  159. {
  160. struct nvif_push *push = wndw->wndw.push;
  161. int ret;
  162. if ((ret = PUSH_WAIT(push, 2)))
  163. return ret;
  164. PUSH_MTHD(push, NV507C, SET_CONTEXT_DMA_SEMAPHORE, 0x00000000);
  165. return 0;
  166. }
  167. int
  168. base507c_sema_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  169. {
  170. struct nvif_push *push = wndw->wndw.push;
  171. int ret;
  172. if ((ret = PUSH_WAIT(push, 5)))
  173. return ret;
  174. PUSH_MTHD(push, NV507C, SET_SEMAPHORE_CONTROL, asyw->sema.offset,
  175. SET_SEMAPHORE_ACQUIRE, asyw->sema.acquire,
  176. SET_SEMAPHORE_RELEASE, asyw->sema.release,
  177. SET_CONTEXT_DMA_SEMAPHORE, asyw->sema.handle);
  178. return 0;
  179. }
  180. void
  181. base507c_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  182. struct nv50_head_atom *asyh)
  183. {
  184. asyh->base.cpp = 0;
  185. }
  186. int
  187. base507c_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  188. struct nv50_head_atom *asyh)
  189. {
  190. const struct drm_framebuffer *fb = asyw->state.fb;
  191. int ret;
  192. ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
  193. DRM_PLANE_NO_SCALING,
  194. DRM_PLANE_NO_SCALING,
  195. false, true);
  196. if (ret)
  197. return ret;
  198. if (!wndw->func->ilut) {
  199. if ((asyh->base.cpp != 1) ^ (fb->format->cpp[0] != 1))
  200. asyh->state.color_mgmt_changed = true;
  201. }
  202. asyh->base.depth = fb->format->depth;
  203. asyh->base.cpp = fb->format->cpp[0];
  204. asyh->base.x = asyw->state.src.x1 >> 16;
  205. asyh->base.y = asyw->state.src.y1 >> 16;
  206. asyh->base.w = asyw->state.fb->width;
  207. asyh->base.h = asyw->state.fb->height;
  208. /* Some newer formats, esp FP16 ones, don't have a
  209. * "depth". There's nothing that really makes sense there
  210. * either, so just set it to the implicit bit count.
  211. */
  212. if (!asyh->base.depth)
  213. asyh->base.depth = asyh->base.cpp * 8;
  214. return 0;
  215. }
  216. const u32
  217. base507c_format[] = {
  218. DRM_FORMAT_C8,
  219. DRM_FORMAT_RGB565,
  220. DRM_FORMAT_XRGB1555,
  221. DRM_FORMAT_ARGB1555,
  222. DRM_FORMAT_XRGB8888,
  223. DRM_FORMAT_ARGB8888,
  224. DRM_FORMAT_XBGR2101010,
  225. DRM_FORMAT_ABGR2101010,
  226. DRM_FORMAT_XBGR8888,
  227. DRM_FORMAT_ABGR8888,
  228. DRM_FORMAT_XBGR16161616F,
  229. DRM_FORMAT_ABGR16161616F,
  230. 0
  231. };
  232. static const struct nv50_wndw_func
  233. base507c = {
  234. .acquire = base507c_acquire,
  235. .release = base507c_release,
  236. .sema_set = base507c_sema_set,
  237. .sema_clr = base507c_sema_clr,
  238. .ntfy_reset = base507c_ntfy_reset,
  239. .ntfy_set = base507c_ntfy_set,
  240. .ntfy_clr = base507c_ntfy_clr,
  241. .ntfy_wait_begun = base507c_ntfy_wait_begun,
  242. .olut_core = 1,
  243. .xlut_set = base507c_xlut_set,
  244. .xlut_clr = base507c_xlut_clr,
  245. .image_set = base507c_image_set,
  246. .image_clr = base507c_image_clr,
  247. .update = base507c_update,
  248. };
  249. int
  250. base507c_new_(const struct nv50_wndw_func *func, const u32 *format,
  251. struct nouveau_drm *drm, int head, s32 oclass, u32 interlock_data,
  252. struct nv50_wndw **pwndw)
  253. {
  254. struct nvif_disp_chan_v0 args = {
  255. .id = head,
  256. };
  257. struct nouveau_display *disp = nouveau_display(drm->dev);
  258. struct nv50_disp *disp50 = nv50_disp(drm->dev);
  259. struct nv50_wndw *wndw;
  260. int ret;
  261. ret = nv50_wndw_new_(func, drm->dev, DRM_PLANE_TYPE_PRIMARY,
  262. "base", head, format, BIT(head),
  263. NV50_DISP_INTERLOCK_BASE, interlock_data, &wndw);
  264. if (*pwndw = wndw, ret)
  265. return ret;
  266. ret = nv50_dmac_create(&drm->client.device, &disp->disp.object,
  267. &oclass, head, &args, sizeof(args),
  268. disp50->sync->offset, &wndw->wndw);
  269. if (ret) {
  270. NV_ERROR(drm, "base%04x allocation failed: %d\n", oclass, ret);
  271. return ret;
  272. }
  273. wndw->ntfy = NV50_DISP_BASE_NTFY(wndw->id);
  274. wndw->sema = NV50_DISP_BASE_SEM0(wndw->id);
  275. wndw->data = 0x00000000;
  276. return 0;
  277. }
  278. int
  279. base507c_new(struct nouveau_drm *drm, int head, s32 oclass,
  280. struct nv50_wndw **pwndw)
  281. {
  282. return base507c_new_(&base507c, base507c_format, drm, head, oclass,
  283. 0x00000002 << (head * 8), pwndw);
  284. }