dcn10_hubp.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. /*
  2. * Copyright 2012-15 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 "dm_services.h"
  26. #include "dce_calcs.h"
  27. #include "reg_helper.h"
  28. #include "basics/conversion.h"
  29. #include "dcn10_hubp.h"
  30. #define REG(reg)\
  31. hubp1->hubp_regs->reg
  32. #define CTX \
  33. hubp1->base.ctx
  34. #undef FN
  35. #define FN(reg_name, field_name) \
  36. hubp1->hubp_shift->field_name, hubp1->hubp_mask->field_name
  37. void hubp1_set_blank(struct hubp *hubp, bool blank)
  38. {
  39. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  40. uint32_t blank_en = blank ? 1 : 0;
  41. REG_UPDATE_2(DCHUBP_CNTL,
  42. HUBP_BLANK_EN, blank_en,
  43. HUBP_TTU_DISABLE, blank_en);
  44. if (blank) {
  45. uint32_t reg_val = REG_READ(DCHUBP_CNTL);
  46. if (reg_val) {
  47. /* init sequence workaround: in case HUBP is
  48. * power gated, this wait would timeout.
  49. *
  50. * we just wrote reg_val to non-0, if it stay 0
  51. * it means HUBP is gated
  52. */
  53. REG_WAIT(DCHUBP_CNTL,
  54. HUBP_NO_OUTSTANDING_REQ, 1,
  55. 1, 200);
  56. }
  57. hubp->mpcc_id = 0xf;
  58. hubp->opp_id = 0xf;
  59. }
  60. }
  61. static void hubp1_disconnect(struct hubp *hubp)
  62. {
  63. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  64. REG_UPDATE(DCHUBP_CNTL,
  65. HUBP_TTU_DISABLE, 1);
  66. REG_UPDATE(CURSOR_CONTROL,
  67. CURSOR_ENABLE, 0);
  68. }
  69. static void hubp1_disable_control(struct hubp *hubp, bool disable_hubp)
  70. {
  71. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  72. uint32_t disable = disable_hubp ? 1 : 0;
  73. REG_UPDATE(DCHUBP_CNTL,
  74. HUBP_DISABLE, disable);
  75. }
  76. static unsigned int hubp1_get_underflow_status(struct hubp *hubp)
  77. {
  78. uint32_t hubp_underflow = 0;
  79. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  80. REG_GET(DCHUBP_CNTL,
  81. HUBP_UNDERFLOW_STATUS,
  82. &hubp_underflow);
  83. return hubp_underflow;
  84. }
  85. static void hubp1_set_hubp_blank_en(struct hubp *hubp, bool blank)
  86. {
  87. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  88. uint32_t blank_en = blank ? 1 : 0;
  89. REG_UPDATE(DCHUBP_CNTL, HUBP_BLANK_EN, blank_en);
  90. }
  91. static void hubp1_vready_workaround(struct hubp *hubp,
  92. struct _vcs_dpi_display_pipe_dest_params_st *pipe_dest)
  93. {
  94. uint32_t value = 0;
  95. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  96. /* set HBUBREQ_DEBUG_DB[12] = 1 */
  97. value = REG_READ(HUBPREQ_DEBUG_DB);
  98. /* hack mode disable */
  99. value |= 0x100;
  100. value &= ~0x1000;
  101. if ((pipe_dest->vstartup_start - 2*(pipe_dest->vready_offset+pipe_dest->vupdate_width
  102. + pipe_dest->vupdate_offset) / pipe_dest->htotal) <= pipe_dest->vblank_end) {
  103. /* if (eco_fix_needed(otg_global_sync_timing)
  104. * set HBUBREQ_DEBUG_DB[12] = 1 */
  105. value |= 0x1000;
  106. }
  107. REG_WRITE(HUBPREQ_DEBUG_DB, value);
  108. }
  109. void hubp1_program_tiling(
  110. struct hubp *hubp,
  111. const union dc_tiling_info *info,
  112. const enum surface_pixel_format pixel_format)
  113. {
  114. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  115. REG_UPDATE_6(DCSURF_ADDR_CONFIG,
  116. NUM_PIPES, log_2(info->gfx9.num_pipes),
  117. NUM_BANKS, log_2(info->gfx9.num_banks),
  118. PIPE_INTERLEAVE, info->gfx9.pipe_interleave,
  119. NUM_SE, log_2(info->gfx9.num_shader_engines),
  120. NUM_RB_PER_SE, log_2(info->gfx9.num_rb_per_se),
  121. MAX_COMPRESSED_FRAGS, log_2(info->gfx9.max_compressed_frags));
  122. REG_UPDATE_4(DCSURF_TILING_CONFIG,
  123. SW_MODE, info->gfx9.swizzle,
  124. META_LINEAR, info->gfx9.meta_linear,
  125. RB_ALIGNED, info->gfx9.rb_aligned,
  126. PIPE_ALIGNED, info->gfx9.pipe_aligned);
  127. }
  128. void hubp1_program_size(
  129. struct hubp *hubp,
  130. enum surface_pixel_format format,
  131. const union plane_size *plane_size,
  132. struct dc_plane_dcc_param *dcc)
  133. {
  134. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  135. uint32_t pitch, meta_pitch, pitch_c, meta_pitch_c;
  136. /* Program data and meta surface pitch (calculation from addrlib)
  137. * 444 or 420 luma
  138. */
  139. if (format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN && format < SURFACE_PIXEL_FORMAT_SUBSAMPLE_END) {
  140. ASSERT(plane_size->video.chroma_pitch != 0);
  141. /* Chroma pitch zero can cause system hang! */
  142. pitch = plane_size->video.luma_pitch - 1;
  143. meta_pitch = dcc->video.meta_pitch_l - 1;
  144. pitch_c = plane_size->video.chroma_pitch - 1;
  145. meta_pitch_c = dcc->video.meta_pitch_c - 1;
  146. } else {
  147. pitch = plane_size->grph.surface_pitch - 1;
  148. meta_pitch = dcc->grph.meta_pitch - 1;
  149. pitch_c = 0;
  150. meta_pitch_c = 0;
  151. }
  152. if (!dcc->enable) {
  153. meta_pitch = 0;
  154. meta_pitch_c = 0;
  155. }
  156. REG_UPDATE_2(DCSURF_SURFACE_PITCH,
  157. PITCH, pitch, META_PITCH, meta_pitch);
  158. if (format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
  159. REG_UPDATE_2(DCSURF_SURFACE_PITCH_C,
  160. PITCH_C, pitch_c, META_PITCH_C, meta_pitch_c);
  161. }
  162. void hubp1_program_rotation(
  163. struct hubp *hubp,
  164. enum dc_rotation_angle rotation,
  165. bool horizontal_mirror)
  166. {
  167. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  168. uint32_t mirror;
  169. if (horizontal_mirror)
  170. mirror = 1;
  171. else
  172. mirror = 0;
  173. /* Program rotation angle and horz mirror - no mirror */
  174. if (rotation == ROTATION_ANGLE_0)
  175. REG_UPDATE_2(DCSURF_SURFACE_CONFIG,
  176. ROTATION_ANGLE, 0,
  177. H_MIRROR_EN, mirror);
  178. else if (rotation == ROTATION_ANGLE_90)
  179. REG_UPDATE_2(DCSURF_SURFACE_CONFIG,
  180. ROTATION_ANGLE, 1,
  181. H_MIRROR_EN, mirror);
  182. else if (rotation == ROTATION_ANGLE_180)
  183. REG_UPDATE_2(DCSURF_SURFACE_CONFIG,
  184. ROTATION_ANGLE, 2,
  185. H_MIRROR_EN, mirror);
  186. else if (rotation == ROTATION_ANGLE_270)
  187. REG_UPDATE_2(DCSURF_SURFACE_CONFIG,
  188. ROTATION_ANGLE, 3,
  189. H_MIRROR_EN, mirror);
  190. }
  191. void hubp1_program_pixel_format(
  192. struct hubp *hubp,
  193. enum surface_pixel_format format)
  194. {
  195. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  196. uint32_t red_bar = 3;
  197. uint32_t blue_bar = 2;
  198. /* swap for ABGR format */
  199. if (format == SURFACE_PIXEL_FORMAT_GRPH_ABGR8888
  200. || format == SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010
  201. || format == SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS
  202. || format == SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F) {
  203. red_bar = 2;
  204. blue_bar = 3;
  205. }
  206. REG_UPDATE_2(HUBPRET_CONTROL,
  207. CROSSBAR_SRC_CB_B, blue_bar,
  208. CROSSBAR_SRC_CR_R, red_bar);
  209. /* Mapping is same as ipp programming (cnvc) */
  210. switch (format) {
  211. case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
  212. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  213. SURFACE_PIXEL_FORMAT, 1);
  214. break;
  215. case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
  216. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  217. SURFACE_PIXEL_FORMAT, 3);
  218. break;
  219. case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
  220. case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
  221. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  222. SURFACE_PIXEL_FORMAT, 8);
  223. break;
  224. case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
  225. case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
  226. case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS:
  227. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  228. SURFACE_PIXEL_FORMAT, 10);
  229. break;
  230. case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
  231. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  232. SURFACE_PIXEL_FORMAT, 22);
  233. break;
  234. case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
  235. case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:/*we use crossbar already*/
  236. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  237. SURFACE_PIXEL_FORMAT, 24);
  238. break;
  239. case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
  240. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  241. SURFACE_PIXEL_FORMAT, 65);
  242. break;
  243. case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
  244. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  245. SURFACE_PIXEL_FORMAT, 64);
  246. break;
  247. case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
  248. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  249. SURFACE_PIXEL_FORMAT, 67);
  250. break;
  251. case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
  252. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  253. SURFACE_PIXEL_FORMAT, 66);
  254. break;
  255. case SURFACE_PIXEL_FORMAT_VIDEO_AYCrCb8888:
  256. REG_UPDATE(DCSURF_SURFACE_CONFIG,
  257. SURFACE_PIXEL_FORMAT, 12);
  258. break;
  259. default:
  260. BREAK_TO_DEBUGGER();
  261. break;
  262. }
  263. /* don't see the need of program the xbar in DCN 1.0 */
  264. }
  265. bool hubp1_program_surface_flip_and_addr(
  266. struct hubp *hubp,
  267. const struct dc_plane_address *address,
  268. bool flip_immediate)
  269. {
  270. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  271. //program flip type
  272. REG_UPDATE(DCSURF_FLIP_CONTROL,
  273. SURFACE_FLIP_TYPE, flip_immediate);
  274. if (address->type == PLN_ADDR_TYPE_GRPH_STEREO) {
  275. REG_UPDATE(DCSURF_FLIP_CONTROL, SURFACE_FLIP_MODE_FOR_STEREOSYNC, 0x1);
  276. REG_UPDATE(DCSURF_FLIP_CONTROL, SURFACE_FLIP_IN_STEREOSYNC, 0x1);
  277. } else {
  278. // turn off stereo if not in stereo
  279. REG_UPDATE(DCSURF_FLIP_CONTROL, SURFACE_FLIP_MODE_FOR_STEREOSYNC, 0x0);
  280. REG_UPDATE(DCSURF_FLIP_CONTROL, SURFACE_FLIP_IN_STEREOSYNC, 0x0);
  281. }
  282. /* HW automatically latch rest of address register on write to
  283. * DCSURF_PRIMARY_SURFACE_ADDRESS if SURFACE_UPDATE_LOCK is not used
  284. *
  285. * program high first and then the low addr, order matters!
  286. */
  287. switch (address->type) {
  288. case PLN_ADDR_TYPE_GRAPHICS:
  289. /* DCN1.0 does not support const color
  290. * TODO: program DCHUBBUB_RET_PATH_DCC_CFGx_0/1
  291. * base on address->grph.dcc_const_color
  292. * x = 0, 2, 4, 6 for pipe 0, 1, 2, 3 for rgb and luma
  293. * x = 1, 3, 5, 7 for pipe 0, 1, 2, 3 for chroma
  294. */
  295. if (address->grph.addr.quad_part == 0)
  296. break;
  297. REG_UPDATE_2(DCSURF_SURFACE_CONTROL,
  298. PRIMARY_SURFACE_TMZ, address->tmz_surface,
  299. PRIMARY_META_SURFACE_TMZ, address->tmz_surface);
  300. if (address->grph.meta_addr.quad_part != 0) {
  301. REG_SET(DCSURF_PRIMARY_META_SURFACE_ADDRESS_HIGH, 0,
  302. PRIMARY_META_SURFACE_ADDRESS_HIGH,
  303. address->grph.meta_addr.high_part);
  304. REG_SET(DCSURF_PRIMARY_META_SURFACE_ADDRESS, 0,
  305. PRIMARY_META_SURFACE_ADDRESS,
  306. address->grph.meta_addr.low_part);
  307. }
  308. REG_SET(DCSURF_PRIMARY_SURFACE_ADDRESS_HIGH, 0,
  309. PRIMARY_SURFACE_ADDRESS_HIGH,
  310. address->grph.addr.high_part);
  311. REG_SET(DCSURF_PRIMARY_SURFACE_ADDRESS, 0,
  312. PRIMARY_SURFACE_ADDRESS,
  313. address->grph.addr.low_part);
  314. break;
  315. case PLN_ADDR_TYPE_VIDEO_PROGRESSIVE:
  316. if (address->video_progressive.luma_addr.quad_part == 0
  317. || address->video_progressive.chroma_addr.quad_part == 0)
  318. break;
  319. REG_UPDATE_4(DCSURF_SURFACE_CONTROL,
  320. PRIMARY_SURFACE_TMZ, address->tmz_surface,
  321. PRIMARY_SURFACE_TMZ_C, address->tmz_surface,
  322. PRIMARY_META_SURFACE_TMZ, address->tmz_surface,
  323. PRIMARY_META_SURFACE_TMZ_C, address->tmz_surface);
  324. if (address->video_progressive.luma_meta_addr.quad_part != 0) {
  325. REG_SET(DCSURF_PRIMARY_META_SURFACE_ADDRESS_HIGH_C, 0,
  326. PRIMARY_META_SURFACE_ADDRESS_HIGH_C,
  327. address->video_progressive.chroma_meta_addr.high_part);
  328. REG_SET(DCSURF_PRIMARY_META_SURFACE_ADDRESS_C, 0,
  329. PRIMARY_META_SURFACE_ADDRESS_C,
  330. address->video_progressive.chroma_meta_addr.low_part);
  331. REG_SET(DCSURF_PRIMARY_META_SURFACE_ADDRESS_HIGH, 0,
  332. PRIMARY_META_SURFACE_ADDRESS_HIGH,
  333. address->video_progressive.luma_meta_addr.high_part);
  334. REG_SET(DCSURF_PRIMARY_META_SURFACE_ADDRESS, 0,
  335. PRIMARY_META_SURFACE_ADDRESS,
  336. address->video_progressive.luma_meta_addr.low_part);
  337. }
  338. REG_SET(DCSURF_PRIMARY_SURFACE_ADDRESS_HIGH_C, 0,
  339. PRIMARY_SURFACE_ADDRESS_HIGH_C,
  340. address->video_progressive.chroma_addr.high_part);
  341. REG_SET(DCSURF_PRIMARY_SURFACE_ADDRESS_C, 0,
  342. PRIMARY_SURFACE_ADDRESS_C,
  343. address->video_progressive.chroma_addr.low_part);
  344. REG_SET(DCSURF_PRIMARY_SURFACE_ADDRESS_HIGH, 0,
  345. PRIMARY_SURFACE_ADDRESS_HIGH,
  346. address->video_progressive.luma_addr.high_part);
  347. REG_SET(DCSURF_PRIMARY_SURFACE_ADDRESS, 0,
  348. PRIMARY_SURFACE_ADDRESS,
  349. address->video_progressive.luma_addr.low_part);
  350. break;
  351. case PLN_ADDR_TYPE_GRPH_STEREO:
  352. if (address->grph_stereo.left_addr.quad_part == 0)
  353. break;
  354. if (address->grph_stereo.right_addr.quad_part == 0)
  355. break;
  356. REG_UPDATE_8(DCSURF_SURFACE_CONTROL,
  357. PRIMARY_SURFACE_TMZ, address->tmz_surface,
  358. PRIMARY_SURFACE_TMZ_C, address->tmz_surface,
  359. PRIMARY_META_SURFACE_TMZ, address->tmz_surface,
  360. PRIMARY_META_SURFACE_TMZ_C, address->tmz_surface,
  361. SECONDARY_SURFACE_TMZ, address->tmz_surface,
  362. SECONDARY_SURFACE_TMZ_C, address->tmz_surface,
  363. SECONDARY_META_SURFACE_TMZ, address->tmz_surface,
  364. SECONDARY_META_SURFACE_TMZ_C, address->tmz_surface);
  365. if (address->grph_stereo.right_meta_addr.quad_part != 0) {
  366. REG_SET(DCSURF_SECONDARY_META_SURFACE_ADDRESS_HIGH, 0,
  367. SECONDARY_META_SURFACE_ADDRESS_HIGH,
  368. address->grph_stereo.right_meta_addr.high_part);
  369. REG_SET(DCSURF_SECONDARY_META_SURFACE_ADDRESS, 0,
  370. SECONDARY_META_SURFACE_ADDRESS,
  371. address->grph_stereo.right_meta_addr.low_part);
  372. }
  373. if (address->grph_stereo.left_meta_addr.quad_part != 0) {
  374. REG_SET(DCSURF_PRIMARY_META_SURFACE_ADDRESS_HIGH, 0,
  375. PRIMARY_META_SURFACE_ADDRESS_HIGH,
  376. address->grph_stereo.left_meta_addr.high_part);
  377. REG_SET(DCSURF_PRIMARY_META_SURFACE_ADDRESS, 0,
  378. PRIMARY_META_SURFACE_ADDRESS,
  379. address->grph_stereo.left_meta_addr.low_part);
  380. }
  381. REG_SET(DCSURF_SECONDARY_SURFACE_ADDRESS_HIGH, 0,
  382. SECONDARY_SURFACE_ADDRESS_HIGH,
  383. address->grph_stereo.right_addr.high_part);
  384. REG_SET(DCSURF_SECONDARY_SURFACE_ADDRESS, 0,
  385. SECONDARY_SURFACE_ADDRESS,
  386. address->grph_stereo.right_addr.low_part);
  387. REG_SET(DCSURF_PRIMARY_SURFACE_ADDRESS_HIGH, 0,
  388. PRIMARY_SURFACE_ADDRESS_HIGH,
  389. address->grph_stereo.left_addr.high_part);
  390. REG_SET(DCSURF_PRIMARY_SURFACE_ADDRESS, 0,
  391. PRIMARY_SURFACE_ADDRESS,
  392. address->grph_stereo.left_addr.low_part);
  393. break;
  394. default:
  395. BREAK_TO_DEBUGGER();
  396. break;
  397. }
  398. hubp->request_address = *address;
  399. return true;
  400. }
  401. void hubp1_dcc_control(struct hubp *hubp, bool enable,
  402. bool independent_64b_blks)
  403. {
  404. uint32_t dcc_en = enable ? 1 : 0;
  405. uint32_t dcc_ind_64b_blk = independent_64b_blks ? 1 : 0;
  406. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  407. REG_UPDATE_4(DCSURF_SURFACE_CONTROL,
  408. PRIMARY_SURFACE_DCC_EN, dcc_en,
  409. PRIMARY_SURFACE_DCC_IND_64B_BLK, dcc_ind_64b_blk,
  410. SECONDARY_SURFACE_DCC_EN, dcc_en,
  411. SECONDARY_SURFACE_DCC_IND_64B_BLK, dcc_ind_64b_blk);
  412. }
  413. void hubp1_program_surface_config(
  414. struct hubp *hubp,
  415. enum surface_pixel_format format,
  416. union dc_tiling_info *tiling_info,
  417. union plane_size *plane_size,
  418. enum dc_rotation_angle rotation,
  419. struct dc_plane_dcc_param *dcc,
  420. bool horizontal_mirror,
  421. unsigned int compat_level)
  422. {
  423. hubp1_dcc_control(hubp, dcc->enable, dcc->grph.independent_64b_blks);
  424. hubp1_program_tiling(hubp, tiling_info, format);
  425. hubp1_program_size(hubp, format, plane_size, dcc);
  426. hubp1_program_rotation(hubp, rotation, horizontal_mirror);
  427. hubp1_program_pixel_format(hubp, format);
  428. }
  429. void hubp1_program_requestor(
  430. struct hubp *hubp,
  431. struct _vcs_dpi_display_rq_regs_st *rq_regs)
  432. {
  433. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  434. REG_UPDATE(HUBPRET_CONTROL,
  435. DET_BUF_PLANE1_BASE_ADDRESS, rq_regs->plane1_base_address);
  436. REG_SET_4(DCN_EXPANSION_MODE, 0,
  437. DRQ_EXPANSION_MODE, rq_regs->drq_expansion_mode,
  438. PRQ_EXPANSION_MODE, rq_regs->prq_expansion_mode,
  439. MRQ_EXPANSION_MODE, rq_regs->mrq_expansion_mode,
  440. CRQ_EXPANSION_MODE, rq_regs->crq_expansion_mode);
  441. REG_SET_8(DCHUBP_REQ_SIZE_CONFIG, 0,
  442. CHUNK_SIZE, rq_regs->rq_regs_l.chunk_size,
  443. MIN_CHUNK_SIZE, rq_regs->rq_regs_l.min_chunk_size,
  444. META_CHUNK_SIZE, rq_regs->rq_regs_l.meta_chunk_size,
  445. MIN_META_CHUNK_SIZE, rq_regs->rq_regs_l.min_meta_chunk_size,
  446. DPTE_GROUP_SIZE, rq_regs->rq_regs_l.dpte_group_size,
  447. MPTE_GROUP_SIZE, rq_regs->rq_regs_l.mpte_group_size,
  448. SWATH_HEIGHT, rq_regs->rq_regs_l.swath_height,
  449. PTE_ROW_HEIGHT_LINEAR, rq_regs->rq_regs_l.pte_row_height_linear);
  450. REG_SET_8(DCHUBP_REQ_SIZE_CONFIG_C, 0,
  451. CHUNK_SIZE_C, rq_regs->rq_regs_c.chunk_size,
  452. MIN_CHUNK_SIZE_C, rq_regs->rq_regs_c.min_chunk_size,
  453. META_CHUNK_SIZE_C, rq_regs->rq_regs_c.meta_chunk_size,
  454. MIN_META_CHUNK_SIZE_C, rq_regs->rq_regs_c.min_meta_chunk_size,
  455. DPTE_GROUP_SIZE_C, rq_regs->rq_regs_c.dpte_group_size,
  456. MPTE_GROUP_SIZE_C, rq_regs->rq_regs_c.mpte_group_size,
  457. SWATH_HEIGHT_C, rq_regs->rq_regs_c.swath_height,
  458. PTE_ROW_HEIGHT_LINEAR_C, rq_regs->rq_regs_c.pte_row_height_linear);
  459. }
  460. void hubp1_program_deadline(
  461. struct hubp *hubp,
  462. struct _vcs_dpi_display_dlg_regs_st *dlg_attr,
  463. struct _vcs_dpi_display_ttu_regs_st *ttu_attr)
  464. {
  465. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  466. /* DLG - Per hubp */
  467. REG_SET_2(BLANK_OFFSET_0, 0,
  468. REFCYC_H_BLANK_END, dlg_attr->refcyc_h_blank_end,
  469. DLG_V_BLANK_END, dlg_attr->dlg_vblank_end);
  470. REG_SET(BLANK_OFFSET_1, 0,
  471. MIN_DST_Y_NEXT_START, dlg_attr->min_dst_y_next_start);
  472. REG_SET(DST_DIMENSIONS, 0,
  473. REFCYC_PER_HTOTAL, dlg_attr->refcyc_per_htotal);
  474. REG_SET_2(DST_AFTER_SCALER, 0,
  475. REFCYC_X_AFTER_SCALER, dlg_attr->refcyc_x_after_scaler,
  476. DST_Y_AFTER_SCALER, dlg_attr->dst_y_after_scaler);
  477. if (REG(PREFETCH_SETTINS))
  478. REG_SET_2(PREFETCH_SETTINS, 0,
  479. DST_Y_PREFETCH, dlg_attr->dst_y_prefetch,
  480. VRATIO_PREFETCH, dlg_attr->vratio_prefetch);
  481. else
  482. REG_SET_2(PREFETCH_SETTINGS, 0,
  483. DST_Y_PREFETCH, dlg_attr->dst_y_prefetch,
  484. VRATIO_PREFETCH, dlg_attr->vratio_prefetch);
  485. REG_SET_2(VBLANK_PARAMETERS_0, 0,
  486. DST_Y_PER_VM_VBLANK, dlg_attr->dst_y_per_vm_vblank,
  487. DST_Y_PER_ROW_VBLANK, dlg_attr->dst_y_per_row_vblank);
  488. REG_SET(REF_FREQ_TO_PIX_FREQ, 0,
  489. REF_FREQ_TO_PIX_FREQ, dlg_attr->ref_freq_to_pix_freq);
  490. /* DLG - Per luma/chroma */
  491. REG_SET(VBLANK_PARAMETERS_1, 0,
  492. REFCYC_PER_PTE_GROUP_VBLANK_L, dlg_attr->refcyc_per_pte_group_vblank_l);
  493. REG_SET(VBLANK_PARAMETERS_3, 0,
  494. REFCYC_PER_META_CHUNK_VBLANK_L, dlg_attr->refcyc_per_meta_chunk_vblank_l);
  495. if (REG(NOM_PARAMETERS_0))
  496. REG_SET(NOM_PARAMETERS_0, 0,
  497. DST_Y_PER_PTE_ROW_NOM_L, dlg_attr->dst_y_per_pte_row_nom_l);
  498. if (REG(NOM_PARAMETERS_1))
  499. REG_SET(NOM_PARAMETERS_1, 0,
  500. REFCYC_PER_PTE_GROUP_NOM_L, dlg_attr->refcyc_per_pte_group_nom_l);
  501. REG_SET(NOM_PARAMETERS_4, 0,
  502. DST_Y_PER_META_ROW_NOM_L, dlg_attr->dst_y_per_meta_row_nom_l);
  503. REG_SET(NOM_PARAMETERS_5, 0,
  504. REFCYC_PER_META_CHUNK_NOM_L, dlg_attr->refcyc_per_meta_chunk_nom_l);
  505. REG_SET_2(PER_LINE_DELIVERY_PRE, 0,
  506. REFCYC_PER_LINE_DELIVERY_PRE_L, dlg_attr->refcyc_per_line_delivery_pre_l,
  507. REFCYC_PER_LINE_DELIVERY_PRE_C, dlg_attr->refcyc_per_line_delivery_pre_c);
  508. REG_SET_2(PER_LINE_DELIVERY, 0,
  509. REFCYC_PER_LINE_DELIVERY_L, dlg_attr->refcyc_per_line_delivery_l,
  510. REFCYC_PER_LINE_DELIVERY_C, dlg_attr->refcyc_per_line_delivery_c);
  511. if (REG(PREFETCH_SETTINS_C))
  512. REG_SET(PREFETCH_SETTINS_C, 0,
  513. VRATIO_PREFETCH_C, dlg_attr->vratio_prefetch_c);
  514. else
  515. REG_SET(PREFETCH_SETTINGS_C, 0,
  516. VRATIO_PREFETCH_C, dlg_attr->vratio_prefetch_c);
  517. REG_SET(VBLANK_PARAMETERS_2, 0,
  518. REFCYC_PER_PTE_GROUP_VBLANK_C, dlg_attr->refcyc_per_pte_group_vblank_c);
  519. REG_SET(VBLANK_PARAMETERS_4, 0,
  520. REFCYC_PER_META_CHUNK_VBLANK_C, dlg_attr->refcyc_per_meta_chunk_vblank_c);
  521. if (REG(NOM_PARAMETERS_2))
  522. REG_SET(NOM_PARAMETERS_2, 0,
  523. DST_Y_PER_PTE_ROW_NOM_C, dlg_attr->dst_y_per_pte_row_nom_c);
  524. if (REG(NOM_PARAMETERS_3))
  525. REG_SET(NOM_PARAMETERS_3, 0,
  526. REFCYC_PER_PTE_GROUP_NOM_C, dlg_attr->refcyc_per_pte_group_nom_c);
  527. REG_SET(NOM_PARAMETERS_6, 0,
  528. DST_Y_PER_META_ROW_NOM_C, dlg_attr->dst_y_per_meta_row_nom_c);
  529. REG_SET(NOM_PARAMETERS_7, 0,
  530. REFCYC_PER_META_CHUNK_NOM_C, dlg_attr->refcyc_per_meta_chunk_nom_c);
  531. /* TTU - per hubp */
  532. REG_SET_2(DCN_TTU_QOS_WM, 0,
  533. QoS_LEVEL_LOW_WM, ttu_attr->qos_level_low_wm,
  534. QoS_LEVEL_HIGH_WM, ttu_attr->qos_level_high_wm);
  535. REG_SET_2(DCN_GLOBAL_TTU_CNTL, 0,
  536. MIN_TTU_VBLANK, ttu_attr->min_ttu_vblank,
  537. QoS_LEVEL_FLIP, ttu_attr->qos_level_flip);
  538. /* TTU - per luma/chroma */
  539. /* Assumed surf0 is luma and 1 is chroma */
  540. REG_SET_3(DCN_SURF0_TTU_CNTL0, 0,
  541. REFCYC_PER_REQ_DELIVERY, ttu_attr->refcyc_per_req_delivery_l,
  542. QoS_LEVEL_FIXED, ttu_attr->qos_level_fixed_l,
  543. QoS_RAMP_DISABLE, ttu_attr->qos_ramp_disable_l);
  544. REG_SET(DCN_SURF0_TTU_CNTL1, 0,
  545. REFCYC_PER_REQ_DELIVERY_PRE,
  546. ttu_attr->refcyc_per_req_delivery_pre_l);
  547. REG_SET_3(DCN_SURF1_TTU_CNTL0, 0,
  548. REFCYC_PER_REQ_DELIVERY, ttu_attr->refcyc_per_req_delivery_c,
  549. QoS_LEVEL_FIXED, ttu_attr->qos_level_fixed_c,
  550. QoS_RAMP_DISABLE, ttu_attr->qos_ramp_disable_c);
  551. REG_SET(DCN_SURF1_TTU_CNTL1, 0,
  552. REFCYC_PER_REQ_DELIVERY_PRE,
  553. ttu_attr->refcyc_per_req_delivery_pre_c);
  554. REG_SET_3(DCN_CUR0_TTU_CNTL0, 0,
  555. REFCYC_PER_REQ_DELIVERY, ttu_attr->refcyc_per_req_delivery_cur0,
  556. QoS_LEVEL_FIXED, ttu_attr->qos_level_fixed_cur0,
  557. QoS_RAMP_DISABLE, ttu_attr->qos_ramp_disable_cur0);
  558. REG_SET(DCN_CUR0_TTU_CNTL1, 0,
  559. REFCYC_PER_REQ_DELIVERY_PRE, ttu_attr->refcyc_per_req_delivery_pre_cur0);
  560. }
  561. static void hubp1_setup(
  562. struct hubp *hubp,
  563. struct _vcs_dpi_display_dlg_regs_st *dlg_attr,
  564. struct _vcs_dpi_display_ttu_regs_st *ttu_attr,
  565. struct _vcs_dpi_display_rq_regs_st *rq_regs,
  566. struct _vcs_dpi_display_pipe_dest_params_st *pipe_dest)
  567. {
  568. /* otg is locked when this func is called. Register are double buffered.
  569. * disable the requestors is not needed
  570. */
  571. hubp1_program_requestor(hubp, rq_regs);
  572. hubp1_program_deadline(hubp, dlg_attr, ttu_attr);
  573. hubp1_vready_workaround(hubp, pipe_dest);
  574. }
  575. bool hubp1_is_flip_pending(struct hubp *hubp)
  576. {
  577. uint32_t flip_pending = 0;
  578. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  579. struct dc_plane_address earliest_inuse_address;
  580. REG_GET(DCSURF_FLIP_CONTROL,
  581. SURFACE_FLIP_PENDING, &flip_pending);
  582. REG_GET(DCSURF_SURFACE_EARLIEST_INUSE,
  583. SURFACE_EARLIEST_INUSE_ADDRESS, &earliest_inuse_address.grph.addr.low_part);
  584. REG_GET(DCSURF_SURFACE_EARLIEST_INUSE_HIGH,
  585. SURFACE_EARLIEST_INUSE_ADDRESS_HIGH, &earliest_inuse_address.grph.addr.high_part);
  586. if (flip_pending)
  587. return true;
  588. if (earliest_inuse_address.grph.addr.quad_part != hubp->request_address.grph.addr.quad_part)
  589. return true;
  590. return false;
  591. }
  592. uint32_t aperture_default_system = 1;
  593. uint32_t context0_default_system; /* = 0;*/
  594. static void hubp1_set_vm_system_aperture_settings(struct hubp *hubp,
  595. struct vm_system_aperture_param *apt)
  596. {
  597. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  598. PHYSICAL_ADDRESS_LOC mc_vm_apt_default;
  599. PHYSICAL_ADDRESS_LOC mc_vm_apt_low;
  600. PHYSICAL_ADDRESS_LOC mc_vm_apt_high;
  601. mc_vm_apt_default.quad_part = apt->sys_default.quad_part >> 12;
  602. mc_vm_apt_low.quad_part = apt->sys_low.quad_part >> 12;
  603. mc_vm_apt_high.quad_part = apt->sys_high.quad_part >> 12;
  604. REG_SET_2(DCN_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB, 0,
  605. MC_VM_SYSTEM_APERTURE_DEFAULT_SYSTEM, aperture_default_system, /* 1 = system physical memory */
  606. MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB, mc_vm_apt_default.high_part);
  607. REG_SET(DCN_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB, 0,
  608. MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB, mc_vm_apt_default.low_part);
  609. REG_SET(DCN_VM_SYSTEM_APERTURE_LOW_ADDR_MSB, 0,
  610. MC_VM_SYSTEM_APERTURE_LOW_ADDR_MSB, mc_vm_apt_low.high_part);
  611. REG_SET(DCN_VM_SYSTEM_APERTURE_LOW_ADDR_LSB, 0,
  612. MC_VM_SYSTEM_APERTURE_LOW_ADDR_LSB, mc_vm_apt_low.low_part);
  613. REG_SET(DCN_VM_SYSTEM_APERTURE_HIGH_ADDR_MSB, 0,
  614. MC_VM_SYSTEM_APERTURE_HIGH_ADDR_MSB, mc_vm_apt_high.high_part);
  615. REG_SET(DCN_VM_SYSTEM_APERTURE_HIGH_ADDR_LSB, 0,
  616. MC_VM_SYSTEM_APERTURE_HIGH_ADDR_LSB, mc_vm_apt_high.low_part);
  617. }
  618. static void hubp1_set_vm_context0_settings(struct hubp *hubp,
  619. const struct vm_context0_param *vm0)
  620. {
  621. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  622. /* pte base */
  623. REG_SET(DCN_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_MSB, 0,
  624. VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_MSB, vm0->pte_base.high_part);
  625. REG_SET(DCN_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LSB, 0,
  626. VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LSB, vm0->pte_base.low_part);
  627. /* pte start */
  628. REG_SET(DCN_VM_CONTEXT0_PAGE_TABLE_START_ADDR_MSB, 0,
  629. VM_CONTEXT0_PAGE_TABLE_START_ADDR_MSB, vm0->pte_start.high_part);
  630. REG_SET(DCN_VM_CONTEXT0_PAGE_TABLE_START_ADDR_LSB, 0,
  631. VM_CONTEXT0_PAGE_TABLE_START_ADDR_LSB, vm0->pte_start.low_part);
  632. /* pte end */
  633. REG_SET(DCN_VM_CONTEXT0_PAGE_TABLE_END_ADDR_MSB, 0,
  634. VM_CONTEXT0_PAGE_TABLE_END_ADDR_MSB, vm0->pte_end.high_part);
  635. REG_SET(DCN_VM_CONTEXT0_PAGE_TABLE_END_ADDR_LSB, 0,
  636. VM_CONTEXT0_PAGE_TABLE_END_ADDR_LSB, vm0->pte_end.low_part);
  637. /* fault handling */
  638. REG_SET_2(DCN_VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR_MSB, 0,
  639. VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR_MSB, vm0->fault_default.high_part,
  640. VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_SYSTEM, context0_default_system);
  641. REG_SET(DCN_VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR_LSB, 0,
  642. VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR_LSB, vm0->fault_default.low_part);
  643. /* control: enable VM PTE*/
  644. REG_SET_2(DCN_VM_MX_L1_TLB_CNTL, 0,
  645. ENABLE_L1_TLB, 1,
  646. SYSTEM_ACCESS_MODE, 3);
  647. }
  648. void min_set_viewport(
  649. struct hubp *hubp,
  650. const struct rect *viewport,
  651. const struct rect *viewport_c)
  652. {
  653. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  654. REG_SET_2(DCSURF_PRI_VIEWPORT_DIMENSION, 0,
  655. PRI_VIEWPORT_WIDTH, viewport->width,
  656. PRI_VIEWPORT_HEIGHT, viewport->height);
  657. REG_SET_2(DCSURF_PRI_VIEWPORT_START, 0,
  658. PRI_VIEWPORT_X_START, viewport->x,
  659. PRI_VIEWPORT_Y_START, viewport->y);
  660. /*for stereo*/
  661. REG_SET_2(DCSURF_SEC_VIEWPORT_DIMENSION, 0,
  662. SEC_VIEWPORT_WIDTH, viewport->width,
  663. SEC_VIEWPORT_HEIGHT, viewport->height);
  664. REG_SET_2(DCSURF_SEC_VIEWPORT_START, 0,
  665. SEC_VIEWPORT_X_START, viewport->x,
  666. SEC_VIEWPORT_Y_START, viewport->y);
  667. /* DC supports NV12 only at the moment */
  668. REG_SET_2(DCSURF_PRI_VIEWPORT_DIMENSION_C, 0,
  669. PRI_VIEWPORT_WIDTH_C, viewport_c->width,
  670. PRI_VIEWPORT_HEIGHT_C, viewport_c->height);
  671. REG_SET_2(DCSURF_PRI_VIEWPORT_START_C, 0,
  672. PRI_VIEWPORT_X_START_C, viewport_c->x,
  673. PRI_VIEWPORT_Y_START_C, viewport_c->y);
  674. }
  675. void hubp1_read_state(struct hubp *hubp)
  676. {
  677. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  678. struct dcn_hubp_state *s = &hubp1->state;
  679. struct _vcs_dpi_display_dlg_regs_st *dlg_attr = &s->dlg_attr;
  680. struct _vcs_dpi_display_ttu_regs_st *ttu_attr = &s->ttu_attr;
  681. struct _vcs_dpi_display_rq_regs_st *rq_regs = &s->rq_regs;
  682. /* Requester */
  683. REG_GET(HUBPRET_CONTROL,
  684. DET_BUF_PLANE1_BASE_ADDRESS, &rq_regs->plane1_base_address);
  685. REG_GET_4(DCN_EXPANSION_MODE,
  686. DRQ_EXPANSION_MODE, &rq_regs->drq_expansion_mode,
  687. PRQ_EXPANSION_MODE, &rq_regs->prq_expansion_mode,
  688. MRQ_EXPANSION_MODE, &rq_regs->mrq_expansion_mode,
  689. CRQ_EXPANSION_MODE, &rq_regs->crq_expansion_mode);
  690. REG_GET_8(DCHUBP_REQ_SIZE_CONFIG,
  691. CHUNK_SIZE, &rq_regs->rq_regs_l.chunk_size,
  692. MIN_CHUNK_SIZE, &rq_regs->rq_regs_l.min_chunk_size,
  693. META_CHUNK_SIZE, &rq_regs->rq_regs_l.meta_chunk_size,
  694. MIN_META_CHUNK_SIZE, &rq_regs->rq_regs_l.min_meta_chunk_size,
  695. DPTE_GROUP_SIZE, &rq_regs->rq_regs_l.dpte_group_size,
  696. MPTE_GROUP_SIZE, &rq_regs->rq_regs_l.mpte_group_size,
  697. SWATH_HEIGHT, &rq_regs->rq_regs_l.swath_height,
  698. PTE_ROW_HEIGHT_LINEAR, &rq_regs->rq_regs_l.pte_row_height_linear);
  699. REG_GET_8(DCHUBP_REQ_SIZE_CONFIG_C,
  700. CHUNK_SIZE_C, &rq_regs->rq_regs_c.chunk_size,
  701. MIN_CHUNK_SIZE_C, &rq_regs->rq_regs_c.min_chunk_size,
  702. META_CHUNK_SIZE_C, &rq_regs->rq_regs_c.meta_chunk_size,
  703. MIN_META_CHUNK_SIZE_C, &rq_regs->rq_regs_c.min_meta_chunk_size,
  704. DPTE_GROUP_SIZE_C, &rq_regs->rq_regs_c.dpte_group_size,
  705. MPTE_GROUP_SIZE_C, &rq_regs->rq_regs_c.mpte_group_size,
  706. SWATH_HEIGHT_C, &rq_regs->rq_regs_c.swath_height,
  707. PTE_ROW_HEIGHT_LINEAR_C, &rq_regs->rq_regs_c.pte_row_height_linear);
  708. /* DLG - Per hubp */
  709. REG_GET_2(BLANK_OFFSET_0,
  710. REFCYC_H_BLANK_END, &dlg_attr->refcyc_h_blank_end,
  711. DLG_V_BLANK_END, &dlg_attr->dlg_vblank_end);
  712. REG_GET(BLANK_OFFSET_1,
  713. MIN_DST_Y_NEXT_START, &dlg_attr->min_dst_y_next_start);
  714. REG_GET(DST_DIMENSIONS,
  715. REFCYC_PER_HTOTAL, &dlg_attr->refcyc_per_htotal);
  716. REG_GET_2(DST_AFTER_SCALER,
  717. REFCYC_X_AFTER_SCALER, &dlg_attr->refcyc_x_after_scaler,
  718. DST_Y_AFTER_SCALER, &dlg_attr->dst_y_after_scaler);
  719. if (REG(PREFETCH_SETTINS))
  720. REG_GET_2(PREFETCH_SETTINS,
  721. DST_Y_PREFETCH, &dlg_attr->dst_y_prefetch,
  722. VRATIO_PREFETCH, &dlg_attr->vratio_prefetch);
  723. else
  724. REG_GET_2(PREFETCH_SETTINGS,
  725. DST_Y_PREFETCH, &dlg_attr->dst_y_prefetch,
  726. VRATIO_PREFETCH, &dlg_attr->vratio_prefetch);
  727. REG_GET_2(VBLANK_PARAMETERS_0,
  728. DST_Y_PER_VM_VBLANK, &dlg_attr->dst_y_per_vm_vblank,
  729. DST_Y_PER_ROW_VBLANK, &dlg_attr->dst_y_per_row_vblank);
  730. REG_GET(REF_FREQ_TO_PIX_FREQ,
  731. REF_FREQ_TO_PIX_FREQ, &dlg_attr->ref_freq_to_pix_freq);
  732. /* DLG - Per luma/chroma */
  733. REG_GET(VBLANK_PARAMETERS_1,
  734. REFCYC_PER_PTE_GROUP_VBLANK_L, &dlg_attr->refcyc_per_pte_group_vblank_l);
  735. REG_GET(VBLANK_PARAMETERS_3,
  736. REFCYC_PER_META_CHUNK_VBLANK_L, &dlg_attr->refcyc_per_meta_chunk_vblank_l);
  737. if (REG(NOM_PARAMETERS_0))
  738. REG_GET(NOM_PARAMETERS_0,
  739. DST_Y_PER_PTE_ROW_NOM_L, &dlg_attr->dst_y_per_pte_row_nom_l);
  740. if (REG(NOM_PARAMETERS_1))
  741. REG_GET(NOM_PARAMETERS_1,
  742. REFCYC_PER_PTE_GROUP_NOM_L, &dlg_attr->refcyc_per_pte_group_nom_l);
  743. REG_GET(NOM_PARAMETERS_4,
  744. DST_Y_PER_META_ROW_NOM_L, &dlg_attr->dst_y_per_meta_row_nom_l);
  745. REG_GET(NOM_PARAMETERS_5,
  746. REFCYC_PER_META_CHUNK_NOM_L, &dlg_attr->refcyc_per_meta_chunk_nom_l);
  747. REG_GET_2(PER_LINE_DELIVERY_PRE,
  748. REFCYC_PER_LINE_DELIVERY_PRE_L, &dlg_attr->refcyc_per_line_delivery_pre_l,
  749. REFCYC_PER_LINE_DELIVERY_PRE_C, &dlg_attr->refcyc_per_line_delivery_pre_c);
  750. REG_GET_2(PER_LINE_DELIVERY,
  751. REFCYC_PER_LINE_DELIVERY_L, &dlg_attr->refcyc_per_line_delivery_l,
  752. REFCYC_PER_LINE_DELIVERY_C, &dlg_attr->refcyc_per_line_delivery_c);
  753. if (REG(PREFETCH_SETTINS_C))
  754. REG_GET(PREFETCH_SETTINS_C,
  755. VRATIO_PREFETCH_C, &dlg_attr->vratio_prefetch_c);
  756. else
  757. REG_GET(PREFETCH_SETTINGS_C,
  758. VRATIO_PREFETCH_C, &dlg_attr->vratio_prefetch_c);
  759. REG_GET(VBLANK_PARAMETERS_2,
  760. REFCYC_PER_PTE_GROUP_VBLANK_C, &dlg_attr->refcyc_per_pte_group_vblank_c);
  761. REG_GET(VBLANK_PARAMETERS_4,
  762. REFCYC_PER_META_CHUNK_VBLANK_C, &dlg_attr->refcyc_per_meta_chunk_vblank_c);
  763. if (REG(NOM_PARAMETERS_2))
  764. REG_GET(NOM_PARAMETERS_2,
  765. DST_Y_PER_PTE_ROW_NOM_C, &dlg_attr->dst_y_per_pte_row_nom_c);
  766. if (REG(NOM_PARAMETERS_3))
  767. REG_GET(NOM_PARAMETERS_3,
  768. REFCYC_PER_PTE_GROUP_NOM_C, &dlg_attr->refcyc_per_pte_group_nom_c);
  769. REG_GET(NOM_PARAMETERS_6,
  770. DST_Y_PER_META_ROW_NOM_C, &dlg_attr->dst_y_per_meta_row_nom_c);
  771. REG_GET(NOM_PARAMETERS_7,
  772. REFCYC_PER_META_CHUNK_NOM_C, &dlg_attr->refcyc_per_meta_chunk_nom_c);
  773. /* TTU - per hubp */
  774. REG_GET_2(DCN_TTU_QOS_WM,
  775. QoS_LEVEL_LOW_WM, &ttu_attr->qos_level_low_wm,
  776. QoS_LEVEL_HIGH_WM, &ttu_attr->qos_level_high_wm);
  777. REG_GET_2(DCN_GLOBAL_TTU_CNTL,
  778. MIN_TTU_VBLANK, &ttu_attr->min_ttu_vblank,
  779. QoS_LEVEL_FLIP, &ttu_attr->qos_level_flip);
  780. /* TTU - per luma/chroma */
  781. /* Assumed surf0 is luma and 1 is chroma */
  782. REG_GET_3(DCN_SURF0_TTU_CNTL0,
  783. REFCYC_PER_REQ_DELIVERY, &ttu_attr->refcyc_per_req_delivery_l,
  784. QoS_LEVEL_FIXED, &ttu_attr->qos_level_fixed_l,
  785. QoS_RAMP_DISABLE, &ttu_attr->qos_ramp_disable_l);
  786. REG_GET(DCN_SURF0_TTU_CNTL1,
  787. REFCYC_PER_REQ_DELIVERY_PRE,
  788. &ttu_attr->refcyc_per_req_delivery_pre_l);
  789. REG_GET_3(DCN_SURF1_TTU_CNTL0,
  790. REFCYC_PER_REQ_DELIVERY, &ttu_attr->refcyc_per_req_delivery_c,
  791. QoS_LEVEL_FIXED, &ttu_attr->qos_level_fixed_c,
  792. QoS_RAMP_DISABLE, &ttu_attr->qos_ramp_disable_c);
  793. REG_GET(DCN_SURF1_TTU_CNTL1,
  794. REFCYC_PER_REQ_DELIVERY_PRE,
  795. &ttu_attr->refcyc_per_req_delivery_pre_c);
  796. /* Rest of hubp */
  797. REG_GET(DCSURF_SURFACE_CONFIG,
  798. SURFACE_PIXEL_FORMAT, &s->pixel_format);
  799. REG_GET(DCSURF_SURFACE_EARLIEST_INUSE_HIGH,
  800. SURFACE_EARLIEST_INUSE_ADDRESS_HIGH, &s->inuse_addr_hi);
  801. REG_GET(DCSURF_SURFACE_EARLIEST_INUSE,
  802. SURFACE_EARLIEST_INUSE_ADDRESS, &s->inuse_addr_lo);
  803. REG_GET_2(DCSURF_PRI_VIEWPORT_DIMENSION,
  804. PRI_VIEWPORT_WIDTH, &s->viewport_width,
  805. PRI_VIEWPORT_HEIGHT, &s->viewport_height);
  806. REG_GET_2(DCSURF_SURFACE_CONFIG,
  807. ROTATION_ANGLE, &s->rotation_angle,
  808. H_MIRROR_EN, &s->h_mirror_en);
  809. REG_GET(DCSURF_TILING_CONFIG,
  810. SW_MODE, &s->sw_mode);
  811. REG_GET(DCSURF_SURFACE_CONTROL,
  812. PRIMARY_SURFACE_DCC_EN, &s->dcc_en);
  813. REG_GET_3(DCHUBP_CNTL,
  814. HUBP_BLANK_EN, &s->blank_en,
  815. HUBP_TTU_DISABLE, &s->ttu_disable,
  816. HUBP_UNDERFLOW_STATUS, &s->underflow_status);
  817. REG_GET(DCN_GLOBAL_TTU_CNTL,
  818. MIN_TTU_VBLANK, &s->min_ttu_vblank);
  819. REG_GET_2(DCN_TTU_QOS_WM,
  820. QoS_LEVEL_LOW_WM, &s->qos_level_low_wm,
  821. QoS_LEVEL_HIGH_WM, &s->qos_level_high_wm);
  822. }
  823. enum cursor_pitch hubp1_get_cursor_pitch(unsigned int pitch)
  824. {
  825. enum cursor_pitch hw_pitch;
  826. switch (pitch) {
  827. case 64:
  828. hw_pitch = CURSOR_PITCH_64_PIXELS;
  829. break;
  830. case 128:
  831. hw_pitch = CURSOR_PITCH_128_PIXELS;
  832. break;
  833. case 256:
  834. hw_pitch = CURSOR_PITCH_256_PIXELS;
  835. break;
  836. default:
  837. DC_ERR("Invalid cursor pitch of %d. "
  838. "Only 64/128/256 is supported on DCN.\n", pitch);
  839. hw_pitch = CURSOR_PITCH_64_PIXELS;
  840. break;
  841. }
  842. return hw_pitch;
  843. }
  844. static enum cursor_lines_per_chunk hubp1_get_lines_per_chunk(
  845. unsigned int cur_width,
  846. enum dc_cursor_color_format format)
  847. {
  848. enum cursor_lines_per_chunk line_per_chunk;
  849. if (format == CURSOR_MODE_MONO)
  850. /* impl B. expansion in CUR Buffer reader */
  851. line_per_chunk = CURSOR_LINE_PER_CHUNK_16;
  852. else if (cur_width <= 32)
  853. line_per_chunk = CURSOR_LINE_PER_CHUNK_16;
  854. else if (cur_width <= 64)
  855. line_per_chunk = CURSOR_LINE_PER_CHUNK_8;
  856. else if (cur_width <= 128)
  857. line_per_chunk = CURSOR_LINE_PER_CHUNK_4;
  858. else
  859. line_per_chunk = CURSOR_LINE_PER_CHUNK_2;
  860. return line_per_chunk;
  861. }
  862. void hubp1_cursor_set_attributes(
  863. struct hubp *hubp,
  864. const struct dc_cursor_attributes *attr)
  865. {
  866. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  867. enum cursor_pitch hw_pitch = hubp1_get_cursor_pitch(attr->pitch);
  868. enum cursor_lines_per_chunk lpc = hubp1_get_lines_per_chunk(
  869. attr->width, attr->color_format);
  870. hubp->curs_attr = *attr;
  871. REG_UPDATE(CURSOR_SURFACE_ADDRESS_HIGH,
  872. CURSOR_SURFACE_ADDRESS_HIGH, attr->address.high_part);
  873. REG_UPDATE(CURSOR_SURFACE_ADDRESS,
  874. CURSOR_SURFACE_ADDRESS, attr->address.low_part);
  875. REG_UPDATE_2(CURSOR_SIZE,
  876. CURSOR_WIDTH, attr->width,
  877. CURSOR_HEIGHT, attr->height);
  878. REG_UPDATE_3(CURSOR_CONTROL,
  879. CURSOR_MODE, attr->color_format,
  880. CURSOR_PITCH, hw_pitch,
  881. CURSOR_LINES_PER_CHUNK, lpc);
  882. REG_SET_2(CURSOR_SETTINS, 0,
  883. /* no shift of the cursor HDL schedule */
  884. CURSOR0_DST_Y_OFFSET, 0,
  885. /* used to shift the cursor chunk request deadline */
  886. CURSOR0_CHUNK_HDL_ADJUST, 3);
  887. }
  888. void hubp1_cursor_set_position(
  889. struct hubp *hubp,
  890. const struct dc_cursor_position *pos,
  891. const struct dc_cursor_mi_param *param)
  892. {
  893. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  894. int src_x_offset = pos->x - pos->x_hotspot - param->viewport.x;
  895. int src_y_offset = pos->y - pos->y_hotspot - param->viewport.y;
  896. int x_hotspot = pos->x_hotspot;
  897. int y_hotspot = pos->y_hotspot;
  898. uint32_t dst_x_offset;
  899. uint32_t cur_en = pos->enable ? 1 : 0;
  900. /*
  901. * Guard aganst cursor_set_position() from being called with invalid
  902. * attributes
  903. *
  904. * TODO: Look at combining cursor_set_position() and
  905. * cursor_set_attributes() into cursor_update()
  906. */
  907. if (hubp->curs_attr.address.quad_part == 0)
  908. return;
  909. if (param->rotation == ROTATION_ANGLE_90 || param->rotation == ROTATION_ANGLE_270) {
  910. src_x_offset = pos->y - pos->y_hotspot - param->viewport.x;
  911. y_hotspot = pos->x_hotspot;
  912. x_hotspot = pos->y_hotspot;
  913. }
  914. if (param->mirror) {
  915. x_hotspot = param->viewport.width - x_hotspot;
  916. src_x_offset = param->viewport.x + param->viewport.width - src_x_offset;
  917. }
  918. dst_x_offset = (src_x_offset >= 0) ? src_x_offset : 0;
  919. dst_x_offset *= param->ref_clk_khz;
  920. dst_x_offset /= param->pixel_clk_khz;
  921. ASSERT(param->h_scale_ratio.value);
  922. if (param->h_scale_ratio.value)
  923. dst_x_offset = dc_fixpt_floor(dc_fixpt_div(
  924. dc_fixpt_from_int(dst_x_offset),
  925. param->h_scale_ratio));
  926. if (src_x_offset >= (int)param->viewport.width)
  927. cur_en = 0; /* not visible beyond right edge*/
  928. if (src_x_offset + (int)hubp->curs_attr.width <= 0)
  929. cur_en = 0; /* not visible beyond left edge*/
  930. if (src_y_offset >= (int)param->viewport.height)
  931. cur_en = 0; /* not visible beyond bottom edge*/
  932. if (src_y_offset < 0) //+ (int)hubp->curs_attr.height
  933. cur_en = 0; /* not visible beyond top edge*/
  934. if (cur_en && REG_READ(CURSOR_SURFACE_ADDRESS) == 0)
  935. hubp->funcs->set_cursor_attributes(hubp, &hubp->curs_attr);
  936. REG_UPDATE(CURSOR_CONTROL,
  937. CURSOR_ENABLE, cur_en);
  938. REG_SET_2(CURSOR_POSITION, 0,
  939. CURSOR_X_POSITION, pos->x,
  940. CURSOR_Y_POSITION, pos->y);
  941. REG_SET_2(CURSOR_HOT_SPOT, 0,
  942. CURSOR_HOT_SPOT_X, x_hotspot,
  943. CURSOR_HOT_SPOT_Y, y_hotspot);
  944. REG_SET(CURSOR_DST_OFFSET, 0,
  945. CURSOR_DST_X_OFFSET, dst_x_offset);
  946. /* TODO Handle surface pixel formats other than 4:4:4 */
  947. }
  948. void hubp1_clk_cntl(struct hubp *hubp, bool enable)
  949. {
  950. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  951. uint32_t clk_enable = enable ? 1 : 0;
  952. REG_UPDATE(HUBP_CLK_CNTL, HUBP_CLOCK_ENABLE, clk_enable);
  953. }
  954. void hubp1_vtg_sel(struct hubp *hubp, uint32_t otg_inst)
  955. {
  956. struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp);
  957. REG_UPDATE(DCHUBP_CNTL, HUBP_VTG_SEL, otg_inst);
  958. }
  959. static const struct hubp_funcs dcn10_hubp_funcs = {
  960. .hubp_program_surface_flip_and_addr =
  961. hubp1_program_surface_flip_and_addr,
  962. .hubp_program_surface_config =
  963. hubp1_program_surface_config,
  964. .hubp_is_flip_pending = hubp1_is_flip_pending,
  965. .hubp_setup = hubp1_setup,
  966. .hubp_set_vm_system_aperture_settings = hubp1_set_vm_system_aperture_settings,
  967. .hubp_set_vm_context0_settings = hubp1_set_vm_context0_settings,
  968. .set_blank = hubp1_set_blank,
  969. .dcc_control = hubp1_dcc_control,
  970. .mem_program_viewport = min_set_viewport,
  971. .set_hubp_blank_en = hubp1_set_hubp_blank_en,
  972. .set_cursor_attributes = hubp1_cursor_set_attributes,
  973. .set_cursor_position = hubp1_cursor_set_position,
  974. .hubp_disconnect = hubp1_disconnect,
  975. .hubp_clk_cntl = hubp1_clk_cntl,
  976. .hubp_vtg_sel = hubp1_vtg_sel,
  977. .hubp_read_state = hubp1_read_state,
  978. .hubp_disable_control = hubp1_disable_control,
  979. .hubp_get_underflow_status = hubp1_get_underflow_status,
  980. };
  981. /*****************************************/
  982. /* Constructor, Destructor */
  983. /*****************************************/
  984. void dcn10_hubp_construct(
  985. struct dcn10_hubp *hubp1,
  986. struct dc_context *ctx,
  987. uint32_t inst,
  988. const struct dcn_mi_registers *hubp_regs,
  989. const struct dcn_mi_shift *hubp_shift,
  990. const struct dcn_mi_mask *hubp_mask)
  991. {
  992. hubp1->base.funcs = &dcn10_hubp_funcs;
  993. hubp1->base.ctx = ctx;
  994. hubp1->hubp_regs = hubp_regs;
  995. hubp1->hubp_shift = hubp_shift;
  996. hubp1->hubp_mask = hubp_mask;
  997. hubp1->base.inst = inst;
  998. hubp1->base.opp_id = 0xf;
  999. hubp1->base.mpcc_id = 0xf;
  1000. }