base907c.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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/push507c.h>
  24. #include <nvhw/class/cl907c.h>
  25. static int
  26. base907c_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  27. {
  28. struct nvif_push *push = wndw->wndw.push;
  29. int ret;
  30. if ((ret = PUSH_WAIT(push, 10)))
  31. return ret;
  32. PUSH_MTHD(push, NV907C, SET_PRESENT_CONTROL,
  33. NVVAL(NV907C, SET_PRESENT_CONTROL, BEGIN_MODE, asyw->image.mode) |
  34. NVDEF(NV907C, SET_PRESENT_CONTROL, TIMESTAMP_MODE, DISABLE) |
  35. NVVAL(NV907C, SET_PRESENT_CONTROL, MIN_PRESENT_INTERVAL, asyw->image.interval));
  36. PUSH_MTHD(push, NV907C, SET_CONTEXT_DMAS_ISO(0), asyw->image.handle, 1);
  37. PUSH_MTHD(push, NV907C, SURFACE_SET_OFFSET(0, 0), asyw->image.offset[0] >> 8,
  38. SURFACE_SET_OFFSET(0, 1), 0x00000000,
  39. SURFACE_SET_SIZE(0),
  40. NVVAL(NV907C, SURFACE_SET_SIZE, WIDTH, asyw->image.w) |
  41. NVVAL(NV907C, SURFACE_SET_SIZE, HEIGHT, asyw->image.h),
  42. SURFACE_SET_STORAGE(0),
  43. NVVAL(NV907C, SURFACE_SET_STORAGE, BLOCK_HEIGHT, asyw->image.blockh) |
  44. NVVAL(NV907C, SURFACE_SET_STORAGE, PITCH, asyw->image.pitch[0] >> 8) |
  45. NVVAL(NV907C, SURFACE_SET_STORAGE, PITCH, asyw->image.blocks[0]) |
  46. NVVAL(NV907C, SURFACE_SET_STORAGE, MEMORY_LAYOUT, asyw->image.layout),
  47. SURFACE_SET_PARAMS(0),
  48. NVVAL(NV907C, SURFACE_SET_PARAMS, FORMAT, asyw->image.format) |
  49. NVDEF(NV907C, SURFACE_SET_PARAMS, SUPER_SAMPLE, X1_AA) |
  50. NVDEF(NV907C, SURFACE_SET_PARAMS, GAMMA, LINEAR) |
  51. NVDEF(NV907C, SURFACE_SET_PARAMS, LAYOUT, FRM));
  52. return 0;
  53. }
  54. static int
  55. base907c_xlut_clr(struct nv50_wndw *wndw)
  56. {
  57. struct nvif_push *push = wndw->wndw.push;
  58. int ret;
  59. if ((ret = PUSH_WAIT(push, 6)))
  60. return ret;
  61. PUSH_MTHD(push, NV907C, SET_BASE_LUT_LO,
  62. NVDEF(NV907C, SET_BASE_LUT_LO, ENABLE, DISABLE));
  63. PUSH_MTHD(push, NV907C, SET_OUTPUT_LUT_LO,
  64. NVDEF(NV907C, SET_OUTPUT_LUT_LO, ENABLE, DISABLE));
  65. PUSH_MTHD(push, NV907C, SET_CONTEXT_DMA_LUT, 0x00000000);
  66. return 0;
  67. }
  68. static int
  69. base907c_xlut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  70. {
  71. struct nvif_push *push = wndw->wndw.push;
  72. int ret;
  73. if ((ret = PUSH_WAIT(push, 6)))
  74. return ret;
  75. PUSH_MTHD(push, NV907C, SET_BASE_LUT_LO,
  76. NVVAL(NV907C, SET_BASE_LUT_LO, ENABLE, asyw->xlut.i.enable) |
  77. NVVAL(NV907C, SET_BASE_LUT_LO, MODE, asyw->xlut.i.mode),
  78. SET_BASE_LUT_HI, asyw->xlut.i.offset >> 8,
  79. SET_OUTPUT_LUT_LO,
  80. NVDEF(NV907C, SET_OUTPUT_LUT_LO, ENABLE, USE_CORE_LUT));
  81. PUSH_MTHD(push, NV907C, SET_CONTEXT_DMA_LUT, asyw->xlut.handle);
  82. return 0;
  83. }
  84. static void
  85. base907c_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, int size)
  86. {
  87. if (size == 1024)
  88. asyw->xlut.i.mode = NV907C_SET_BASE_LUT_LO_MODE_INTERPOLATE_1025_UNITY_RANGE;
  89. else
  90. asyw->xlut.i.mode = NV907C_SET_BASE_LUT_LO_MODE_INTERPOLATE_257_UNITY_RANGE;
  91. asyw->xlut.i.enable = NV907C_SET_BASE_LUT_LO_ENABLE_ENABLE;
  92. asyw->xlut.i.load = head907d_olut_load;
  93. }
  94. static inline u32
  95. csc_drm_to_base(u64 in)
  96. {
  97. /* base takes a 19-bit 2's complement value in S3.16 format */
  98. bool sign = in & BIT_ULL(63);
  99. u32 integer = (in >> 32) & 0x7fffffff;
  100. u32 fraction = in & 0xffffffff;
  101. if (integer >= 4) {
  102. return (1 << 18) - (sign ? 0 : 1);
  103. } else {
  104. u32 ret = (integer << 16) | (fraction >> 16);
  105. if (sign)
  106. ret = -ret;
  107. return ret & GENMASK(18, 0);
  108. }
  109. }
  110. void
  111. base907c_csc(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  112. const struct drm_color_ctm *ctm)
  113. {
  114. int i, j;
  115. for (j = 0; j < 3; j++) {
  116. for (i = 0; i < 4; i++) {
  117. u32 *val = &asyw->csc.matrix[j * 4 + i];
  118. /* DRM does not support constant offset, while
  119. * HW CSC does. Skip it. */
  120. if (i == 3) {
  121. *val = 0;
  122. } else {
  123. *val = csc_drm_to_base(ctm->matrix[j * 3 + i]);
  124. }
  125. }
  126. }
  127. }
  128. static int
  129. base907c_csc_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, NV907C, SET_CSC_RED2RED,
  136. NVDEF(NV907C, SET_CSC_RED2RED, OWNER, CORE));
  137. return 0;
  138. }
  139. static int
  140. base907c_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  141. {
  142. struct nvif_push *push = wndw->wndw.push;
  143. int ret;
  144. if ((ret = PUSH_WAIT(push, 13)))
  145. return ret;
  146. PUSH_MTHD(push, NV907C, SET_CSC_RED2RED,
  147. NVDEF(NV907C, SET_CSC_RED2RED, OWNER, BASE) |
  148. NVVAL(NV907C, SET_CSC_RED2RED, COEFF, asyw->csc.matrix[0]),
  149. SET_CSC_GRN2RED, &asyw->csc.matrix[1], 11);
  150. return 0;
  151. }
  152. const struct nv50_wndw_func
  153. base907c = {
  154. .acquire = base507c_acquire,
  155. .release = base507c_release,
  156. .sema_set = base507c_sema_set,
  157. .sema_clr = base507c_sema_clr,
  158. .ntfy_reset = base507c_ntfy_reset,
  159. .ntfy_set = base507c_ntfy_set,
  160. .ntfy_clr = base507c_ntfy_clr,
  161. .ntfy_wait_begun = base507c_ntfy_wait_begun,
  162. .ilut = base907c_ilut,
  163. .csc = base907c_csc,
  164. .csc_set = base907c_csc_set,
  165. .csc_clr = base907c_csc_clr,
  166. .olut_core = true,
  167. .ilut_size = 1024,
  168. .xlut_set = base907c_xlut_set,
  169. .xlut_clr = base907c_xlut_clr,
  170. .image_set = base907c_image_set,
  171. .image_clr = base507c_image_clr,
  172. .update = base507c_update,
  173. };
  174. int
  175. base907c_new(struct nouveau_drm *drm, int head, s32 oclass,
  176. struct nv50_wndw **pwndw)
  177. {
  178. return base507c_new_(&base907c, base507c_format, drm, head, oclass,
  179. 0x00000002 << (head * 4), pwndw);
  180. }