wndwc57e.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 "wndw.h"
  23. #include "atom.h"
  24. #include <drm/drm_atomic_helper.h>
  25. #include <nouveau_bo.h>
  26. #include <nvif/pushc37b.h>
  27. #include <nvhw/class/clc57e.h>
  28. static int
  29. wndwc57e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  30. {
  31. struct nvif_push *push = wndw->wndw.push;
  32. int ret;
  33. if ((ret = PUSH_WAIT(push, 17)))
  34. return ret;
  35. PUSH_MTHD(push, NVC57E, SET_PRESENT_CONTROL,
  36. NVVAL(NVC57E, SET_PRESENT_CONTROL, MIN_PRESENT_INTERVAL, asyw->image.interval) |
  37. NVVAL(NVC57E, SET_PRESENT_CONTROL, BEGIN_MODE, asyw->image.mode) |
  38. NVDEF(NVC57E, SET_PRESENT_CONTROL, TIMESTAMP_MODE, DISABLE));
  39. PUSH_MTHD(push, NVC57E, SET_SIZE,
  40. NVVAL(NVC57E, SET_SIZE, WIDTH, asyw->image.w) |
  41. NVVAL(NVC57E, SET_SIZE, HEIGHT, asyw->image.h),
  42. SET_STORAGE,
  43. NVVAL(NVC57E, SET_STORAGE, BLOCK_HEIGHT, asyw->image.blockh) |
  44. NVVAL(NVC57E, SET_STORAGE, MEMORY_LAYOUT, asyw->image.layout),
  45. SET_PARAMS,
  46. NVVAL(NVC57E, SET_PARAMS, FORMAT, asyw->image.format) |
  47. NVDEF(NVC57E, SET_PARAMS, CLAMP_BEFORE_BLEND, DISABLE) |
  48. NVDEF(NVC57E, SET_PARAMS, SWAP_UV, DISABLE) |
  49. NVDEF(NVC57E, SET_PARAMS, FMT_ROUNDING_MODE, ROUND_TO_NEAREST),
  50. SET_PLANAR_STORAGE(0),
  51. NVVAL(NVC57E, SET_PLANAR_STORAGE, PITCH, asyw->image.blocks[0]) |
  52. NVVAL(NVC57E, SET_PLANAR_STORAGE, PITCH, asyw->image.pitch[0] >> 6));
  53. PUSH_MTHD(push, NVC57E, SET_CONTEXT_DMA_ISO(0), asyw->image.handle, 1);
  54. PUSH_MTHD(push, NVC57E, SET_OFFSET(0), asyw->image.offset[0] >> 8);
  55. PUSH_MTHD(push, NVC57E, SET_POINT_IN(0),
  56. NVVAL(NVC57E, SET_POINT_IN, X, asyw->state.src_x >> 16) |
  57. NVVAL(NVC57E, SET_POINT_IN, Y, asyw->state.src_y >> 16));
  58. PUSH_MTHD(push, NVC57E, SET_SIZE_IN,
  59. NVVAL(NVC57E, SET_SIZE_IN, WIDTH, asyw->state.src_w >> 16) |
  60. NVVAL(NVC57E, SET_SIZE_IN, HEIGHT, asyw->state.src_h >> 16));
  61. PUSH_MTHD(push, NVC57E, SET_SIZE_OUT,
  62. NVVAL(NVC57E, SET_SIZE_OUT, WIDTH, asyw->state.crtc_w) |
  63. NVVAL(NVC57E, SET_SIZE_OUT, HEIGHT, asyw->state.crtc_h));
  64. return 0;
  65. }
  66. int
  67. wndwc57e_csc_clr(struct nv50_wndw *wndw)
  68. {
  69. struct nvif_push *push = wndw->wndw.push;
  70. const u32 identity[12] = {
  71. 0x00010000, 0x00000000, 0x00000000, 0x00000000,
  72. 0x00000000, 0x00010000, 0x00000000, 0x00000000,
  73. 0x00000000, 0x00000000, 0x00010000, 0x00000000,
  74. };
  75. int ret;
  76. if ((ret = PUSH_WAIT(push, 1 + ARRAY_SIZE(identity))))
  77. return ret;
  78. PUSH_MTHD(push, NVC57E, SET_FMT_COEFFICIENT_C00, identity, ARRAY_SIZE(identity));
  79. return 0;
  80. }
  81. int
  82. wndwc57e_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  83. {
  84. struct nvif_push *push = wndw->wndw.push;
  85. int ret;
  86. if ((ret = PUSH_WAIT(push, 13)))
  87. return ret;
  88. PUSH_MTHD(push, NVC57E, SET_FMT_COEFFICIENT_C00, asyw->csc.matrix, 12);
  89. return 0;
  90. }
  91. int
  92. wndwc57e_ilut_clr(struct nv50_wndw *wndw)
  93. {
  94. struct nvif_push *push = wndw->wndw.push;
  95. int ret;
  96. if ((ret = PUSH_WAIT(push, 2)))
  97. return ret;
  98. PUSH_MTHD(push, NVC57E, SET_CONTEXT_DMA_ILUT, 0x00000000);
  99. return 0;
  100. }
  101. int
  102. wndwc57e_ilut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  103. {
  104. struct nvif_push *push = wndw->wndw.push;
  105. int ret;
  106. if ((ret = PUSH_WAIT(push, 4)))
  107. return ret;
  108. PUSH_MTHD(push, NVC57E, SET_ILUT_CONTROL,
  109. NVVAL(NVC57E, SET_ILUT_CONTROL, SIZE, asyw->xlut.i.size) |
  110. NVVAL(NVC57E, SET_ILUT_CONTROL, MODE, asyw->xlut.i.mode) |
  111. NVVAL(NVC57E, SET_ILUT_CONTROL, INTERPOLATE, asyw->xlut.i.output_mode),
  112. SET_CONTEXT_DMA_ILUT, asyw->xlut.handle,
  113. SET_OFFSET_ILUT, asyw->xlut.i.offset >> 8);
  114. return 0;
  115. }
  116. static u16
  117. fixedU0_16_FP16(u16 fixed)
  118. {
  119. int sign = 0, exp = 0, man = 0;
  120. if (fixed) {
  121. while (--exp && !(fixed & 0x8000))
  122. fixed <<= 1;
  123. man = ((fixed << 1) & 0xffc0) >> 6;
  124. exp += 15;
  125. }
  126. return (sign << 15) | (exp << 10) | man;
  127. }
  128. static void
  129. wndwc57e_ilut_load(struct drm_color_lut *in, int size, void __iomem *mem)
  130. {
  131. memset_io(mem, 0x00, 0x20); /* VSS header. */
  132. mem += 0x20;
  133. for (; size--; in++, mem += 0x08) {
  134. u16 r = fixedU0_16_FP16(drm_color_lut_extract(in-> red, 16));
  135. u16 g = fixedU0_16_FP16(drm_color_lut_extract(in->green, 16));
  136. u16 b = fixedU0_16_FP16(drm_color_lut_extract(in-> blue, 16));
  137. writew(r, mem + 0);
  138. writew(g, mem + 2);
  139. writew(b, mem + 4);
  140. }
  141. /* INTERPOLATE modes require a "next" entry to interpolate with,
  142. * so we replicate the last entry to deal with this for now.
  143. */
  144. writew(readw(mem - 8), mem + 0);
  145. writew(readw(mem - 6), mem + 2);
  146. writew(readw(mem - 4), mem + 4);
  147. }
  148. void
  149. wndwc57e_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, int size)
  150. {
  151. if (!size)
  152. size = 1024;
  153. if (size == 256)
  154. asyw->xlut.i.mode = NVC57E_SET_ILUT_CONTROL_MODE_DIRECT8;
  155. else
  156. asyw->xlut.i.mode = NVC57E_SET_ILUT_CONTROL_MODE_DIRECT10;
  157. asyw->xlut.i.size = 4 /* VSS header. */ + size + 1 /* Entries. */;
  158. asyw->xlut.i.output_mode = NVC57E_SET_ILUT_CONTROL_INTERPOLATE_DISABLE;
  159. asyw->xlut.i.load = wndwc57e_ilut_load;
  160. }
  161. /****************************************************************
  162. * Log2(block height) ----------------------------+ *
  163. * Page Kind ----------------------------------+ | *
  164. * Gob Height/Page Kind Generation ------+ | | *
  165. * Sector layout -------+ | | | *
  166. * Compression ------+ | | | | */
  167. const u64 wndwc57e_modifiers[] = { /* | | | | | */
  168. DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 0),
  169. DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 1),
  170. DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 2),
  171. DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 3),
  172. DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 4),
  173. DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 5),
  174. DRM_FORMAT_MOD_LINEAR,
  175. DRM_FORMAT_MOD_INVALID
  176. };
  177. static const struct nv50_wndw_func
  178. wndwc57e = {
  179. .acquire = wndwc37e_acquire,
  180. .release = wndwc37e_release,
  181. .sema_set = wndwc37e_sema_set,
  182. .sema_clr = wndwc37e_sema_clr,
  183. .ntfy_set = wndwc37e_ntfy_set,
  184. .ntfy_clr = wndwc37e_ntfy_clr,
  185. .ntfy_reset = corec37d_ntfy_init,
  186. .ntfy_wait_begun = base507c_ntfy_wait_begun,
  187. .ilut = wndwc57e_ilut,
  188. .ilut_identity = true,
  189. .ilut_size = 1024,
  190. .xlut_set = wndwc57e_ilut_set,
  191. .xlut_clr = wndwc57e_ilut_clr,
  192. .csc = base907c_csc,
  193. .csc_set = wndwc57e_csc_set,
  194. .csc_clr = wndwc57e_csc_clr,
  195. .image_set = wndwc57e_image_set,
  196. .image_clr = wndwc37e_image_clr,
  197. .blend_set = wndwc37e_blend_set,
  198. .update = wndwc37e_update,
  199. };
  200. int
  201. wndwc57e_new(struct nouveau_drm *drm, enum drm_plane_type type, int index,
  202. s32 oclass, struct nv50_wndw **pwndw)
  203. {
  204. return wndwc37e_new_(&wndwc57e, drm, type, index, oclass,
  205. BIT(index >> 1), pwndw);
  206. }