dce_ipp.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * Copyright 2017 Advanced Micro Devices, 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. * Authors: AMD
  23. *
  24. */
  25. #include "dce_ipp.h"
  26. #include "reg_helper.h"
  27. #include "dm_services.h"
  28. #define REG(reg) \
  29. (ipp_dce->regs->reg)
  30. #undef FN
  31. #define FN(reg_name, field_name) \
  32. ipp_dce->ipp_shift->field_name, ipp_dce->ipp_mask->field_name
  33. #define CTX \
  34. ipp_dce->base.ctx
  35. static void dce_ipp_cursor_set_position(
  36. struct input_pixel_processor *ipp,
  37. const struct dc_cursor_position *position,
  38. const struct dc_cursor_mi_param *param)
  39. {
  40. struct dce_ipp *ipp_dce = TO_DCE_IPP(ipp);
  41. /* lock cursor registers */
  42. REG_UPDATE(CUR_UPDATE, CURSOR_UPDATE_LOCK, true);
  43. /* Flag passed in structure differentiates cursor enable/disable. */
  44. /* Update if it differs from cached state. */
  45. REG_UPDATE(CUR_CONTROL, CURSOR_EN, position->enable);
  46. REG_SET_2(CUR_POSITION, 0,
  47. CURSOR_X_POSITION, position->x,
  48. CURSOR_Y_POSITION, position->y);
  49. REG_SET_2(CUR_HOT_SPOT, 0,
  50. CURSOR_HOT_SPOT_X, position->x_hotspot,
  51. CURSOR_HOT_SPOT_Y, position->y_hotspot);
  52. /* unlock cursor registers */
  53. REG_UPDATE(CUR_UPDATE, CURSOR_UPDATE_LOCK, false);
  54. }
  55. static void dce_ipp_cursor_set_attributes(
  56. struct input_pixel_processor *ipp,
  57. const struct dc_cursor_attributes *attributes)
  58. {
  59. struct dce_ipp *ipp_dce = TO_DCE_IPP(ipp);
  60. int mode;
  61. /* Lock cursor registers */
  62. REG_UPDATE(CUR_UPDATE, CURSOR_UPDATE_LOCK, true);
  63. /* Program cursor control */
  64. switch (attributes->color_format) {
  65. case CURSOR_MODE_MONO:
  66. mode = 0;
  67. break;
  68. case CURSOR_MODE_COLOR_1BIT_AND:
  69. mode = 1;
  70. break;
  71. case CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA:
  72. mode = 2;
  73. break;
  74. case CURSOR_MODE_COLOR_UN_PRE_MULTIPLIED_ALPHA:
  75. mode = 3;
  76. break;
  77. default:
  78. BREAK_TO_DEBUGGER(); /* unsupported */
  79. mode = 0;
  80. }
  81. REG_UPDATE_3(CUR_CONTROL,
  82. CURSOR_MODE, mode,
  83. CURSOR_2X_MAGNIFY, attributes->attribute_flags.bits.ENABLE_MAGNIFICATION,
  84. CUR_INV_TRANS_CLAMP, attributes->attribute_flags.bits.INVERSE_TRANSPARENT_CLAMPING);
  85. if (attributes->color_format == CURSOR_MODE_MONO) {
  86. REG_SET_3(CUR_COLOR1, 0,
  87. CUR_COLOR1_BLUE, 0,
  88. CUR_COLOR1_GREEN, 0,
  89. CUR_COLOR1_RED, 0);
  90. REG_SET_3(CUR_COLOR2, 0,
  91. CUR_COLOR2_BLUE, 0xff,
  92. CUR_COLOR2_GREEN, 0xff,
  93. CUR_COLOR2_RED, 0xff);
  94. }
  95. /*
  96. * Program cursor size -- NOTE: HW spec specifies that HW register
  97. * stores size as (height - 1, width - 1)
  98. */
  99. REG_SET_2(CUR_SIZE, 0,
  100. CURSOR_WIDTH, attributes->width-1,
  101. CURSOR_HEIGHT, attributes->height-1);
  102. /* Program cursor surface address */
  103. /* SURFACE_ADDRESS_HIGH: Higher order bits (39:32) of hardware cursor
  104. * surface base address in byte. It is 4K byte aligned.
  105. * The correct way to program cursor surface address is to first write
  106. * to CUR_SURFACE_ADDRESS_HIGH, and then write to CUR_SURFACE_ADDRESS
  107. */
  108. REG_SET(CUR_SURFACE_ADDRESS_HIGH, 0,
  109. CURSOR_SURFACE_ADDRESS_HIGH, attributes->address.high_part);
  110. REG_SET(CUR_SURFACE_ADDRESS, 0,
  111. CURSOR_SURFACE_ADDRESS, attributes->address.low_part);
  112. /* Unlock Cursor registers. */
  113. REG_UPDATE(CUR_UPDATE, CURSOR_UPDATE_LOCK, false);
  114. }
  115. static void dce_ipp_program_prescale(struct input_pixel_processor *ipp,
  116. struct ipp_prescale_params *params)
  117. {
  118. struct dce_ipp *ipp_dce = TO_DCE_IPP(ipp);
  119. /* set to bypass mode first before change */
  120. REG_UPDATE(PRESCALE_GRPH_CONTROL,
  121. GRPH_PRESCALE_BYPASS, 1);
  122. REG_SET_2(PRESCALE_VALUES_GRPH_R, 0,
  123. GRPH_PRESCALE_SCALE_R, params->scale,
  124. GRPH_PRESCALE_BIAS_R, params->bias);
  125. REG_SET_2(PRESCALE_VALUES_GRPH_G, 0,
  126. GRPH_PRESCALE_SCALE_G, params->scale,
  127. GRPH_PRESCALE_BIAS_G, params->bias);
  128. REG_SET_2(PRESCALE_VALUES_GRPH_B, 0,
  129. GRPH_PRESCALE_SCALE_B, params->scale,
  130. GRPH_PRESCALE_BIAS_B, params->bias);
  131. if (params->mode != IPP_PRESCALE_MODE_BYPASS) {
  132. REG_UPDATE(PRESCALE_GRPH_CONTROL,
  133. GRPH_PRESCALE_BYPASS, 0);
  134. /* If prescale is in use, then legacy lut should be bypassed */
  135. REG_UPDATE(INPUT_GAMMA_CONTROL,
  136. GRPH_INPUT_GAMMA_MODE, 1);
  137. }
  138. }
  139. static void dce_ipp_program_input_lut(
  140. struct input_pixel_processor *ipp,
  141. const struct dc_gamma *gamma)
  142. {
  143. int i;
  144. struct dce_ipp *ipp_dce = TO_DCE_IPP(ipp);
  145. /* power on LUT memory */
  146. if (REG(DCFE_MEM_PWR_CTRL))
  147. REG_SET(DCFE_MEM_PWR_CTRL, 0, DCP_LUT_MEM_PWR_DIS, 1);
  148. /* enable all */
  149. REG_SET(DC_LUT_WRITE_EN_MASK, 0, DC_LUT_WRITE_EN_MASK, 0x7);
  150. /* 256 entry mode */
  151. REG_UPDATE(DC_LUT_RW_MODE, DC_LUT_RW_MODE, 0);
  152. /* LUT-256, unsigned, integer, new u0.12 format */
  153. REG_SET_3(DC_LUT_CONTROL, 0,
  154. DC_LUT_DATA_R_FORMAT, 3,
  155. DC_LUT_DATA_G_FORMAT, 3,
  156. DC_LUT_DATA_B_FORMAT, 3);
  157. /* start from index 0 */
  158. REG_SET(DC_LUT_RW_INDEX, 0,
  159. DC_LUT_RW_INDEX, 0);
  160. for (i = 0; i < gamma->num_entries; i++) {
  161. REG_SET(DC_LUT_SEQ_COLOR, 0, DC_LUT_SEQ_COLOR,
  162. dc_fixpt_round(
  163. gamma->entries.red[i]));
  164. REG_SET(DC_LUT_SEQ_COLOR, 0, DC_LUT_SEQ_COLOR,
  165. dc_fixpt_round(
  166. gamma->entries.green[i]));
  167. REG_SET(DC_LUT_SEQ_COLOR, 0, DC_LUT_SEQ_COLOR,
  168. dc_fixpt_round(
  169. gamma->entries.blue[i]));
  170. }
  171. /* power off LUT memory */
  172. if (REG(DCFE_MEM_PWR_CTRL))
  173. REG_SET(DCFE_MEM_PWR_CTRL, 0, DCP_LUT_MEM_PWR_DIS, 0);
  174. /* bypass prescale, enable legacy LUT */
  175. REG_UPDATE(PRESCALE_GRPH_CONTROL, GRPH_PRESCALE_BYPASS, 1);
  176. REG_UPDATE(INPUT_GAMMA_CONTROL, GRPH_INPUT_GAMMA_MODE, 0);
  177. }
  178. static void dce_ipp_set_degamma(
  179. struct input_pixel_processor *ipp,
  180. enum ipp_degamma_mode mode)
  181. {
  182. struct dce_ipp *ipp_dce = TO_DCE_IPP(ipp);
  183. uint32_t degamma_type = (mode == IPP_DEGAMMA_MODE_HW_sRGB) ? 1 : 0;
  184. ASSERT(mode == IPP_DEGAMMA_MODE_BYPASS || mode == IPP_DEGAMMA_MODE_HW_sRGB);
  185. REG_SET_3(DEGAMMA_CONTROL, 0,
  186. GRPH_DEGAMMA_MODE, degamma_type,
  187. CURSOR_DEGAMMA_MODE, degamma_type,
  188. CURSOR2_DEGAMMA_MODE, degamma_type);
  189. }
  190. static const struct ipp_funcs dce_ipp_funcs = {
  191. .ipp_cursor_set_attributes = dce_ipp_cursor_set_attributes,
  192. .ipp_cursor_set_position = dce_ipp_cursor_set_position,
  193. .ipp_program_prescale = dce_ipp_program_prescale,
  194. .ipp_program_input_lut = dce_ipp_program_input_lut,
  195. .ipp_set_degamma = dce_ipp_set_degamma
  196. };
  197. /*****************************************/
  198. /* Constructor, Destructor */
  199. /*****************************************/
  200. void dce_ipp_construct(
  201. struct dce_ipp *ipp_dce,
  202. struct dc_context *ctx,
  203. int inst,
  204. const struct dce_ipp_registers *regs,
  205. const struct dce_ipp_shift *ipp_shift,
  206. const struct dce_ipp_mask *ipp_mask)
  207. {
  208. ipp_dce->base.ctx = ctx;
  209. ipp_dce->base.inst = inst;
  210. ipp_dce->base.funcs = &dce_ipp_funcs;
  211. ipp_dce->regs = regs;
  212. ipp_dce->ipp_shift = ipp_shift;
  213. ipp_dce->ipp_mask = ipp_mask;
  214. }
  215. void dce_ipp_destroy(struct input_pixel_processor **ipp)
  216. {
  217. kfree(TO_DCE_IPP(*ipp));
  218. *ipp = NULL;
  219. }