s5p_mfc_opr_v6.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537
  1. /*
  2. * drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
  3. *
  4. * Samsung MFC (Multi Function Codec - FIMV) driver
  5. * This file contains hw related functions.
  6. *
  7. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  8. * http://www.samsung.com/
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #undef DEBUG
  15. #include <linux/delay.h>
  16. #include <linux/mm.h>
  17. #include <linux/io.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/firmware.h>
  20. #include <linux/err.h>
  21. #include <linux/sched.h>
  22. #include <linux/dma-mapping.h>
  23. #include <asm/cacheflush.h>
  24. #include "s5p_mfc_common.h"
  25. #include "s5p_mfc_cmd.h"
  26. #include "s5p_mfc_intr.h"
  27. #include "s5p_mfc_pm.h"
  28. #include "s5p_mfc_debug.h"
  29. #include "s5p_mfc_opr.h"
  30. #include "s5p_mfc_opr_v6.h"
  31. /* #define S5P_MFC_DEBUG_REGWRITE */
  32. #ifdef S5P_MFC_DEBUG_REGWRITE
  33. #undef writel
  34. #define writel(v, r) \
  35. do { \
  36. pr_err("MFCWRITE(%p): %08x\n", r, (unsigned int)v); \
  37. __raw_writel(v, r); \
  38. } while (0)
  39. #endif /* S5P_MFC_DEBUG_REGWRITE */
  40. #define IS_MFCV6_V2(dev) (!IS_MFCV7_PLUS(dev) && dev->fw_ver == MFC_FW_V2)
  41. /* Allocate temporary buffers for decoding */
  42. static int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
  43. {
  44. /* NOP */
  45. return 0;
  46. }
  47. /* Release temproary buffers for decoding */
  48. static void s5p_mfc_release_dec_desc_buffer_v6(struct s5p_mfc_ctx *ctx)
  49. {
  50. /* NOP */
  51. }
  52. /* Allocate codec buffers */
  53. static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
  54. {
  55. struct s5p_mfc_dev *dev = ctx->dev;
  56. unsigned int mb_width, mb_height;
  57. unsigned int lcu_width = 0, lcu_height = 0;
  58. int ret;
  59. mb_width = MB_WIDTH(ctx->img_width);
  60. mb_height = MB_HEIGHT(ctx->img_height);
  61. if (ctx->type == MFCINST_DECODER) {
  62. mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n",
  63. ctx->luma_size, ctx->chroma_size, ctx->mv_size);
  64. mfc_debug(2, "Totals bufs: %d\n", ctx->total_dpb_count);
  65. } else if (ctx->type == MFCINST_ENCODER) {
  66. if (IS_MFCV10(dev)) {
  67. ctx->tmv_buffer_size = 0;
  68. } else if (IS_MFCV8_PLUS(dev))
  69. ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
  70. ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V8(mb_width, mb_height),
  71. S5P_FIMV_TMV_BUFFER_ALIGN_V6);
  72. else
  73. ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
  74. ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V6(mb_width, mb_height),
  75. S5P_FIMV_TMV_BUFFER_ALIGN_V6);
  76. if (IS_MFCV10(dev)) {
  77. lcu_width = S5P_MFC_LCU_WIDTH(ctx->img_width);
  78. lcu_height = S5P_MFC_LCU_HEIGHT(ctx->img_height);
  79. if (ctx->codec_mode != S5P_FIMV_CODEC_HEVC_ENC) {
  80. ctx->luma_dpb_size =
  81. ALIGN((mb_width * 16), 64)
  82. * ALIGN((mb_height * 16), 32)
  83. + 64;
  84. ctx->chroma_dpb_size =
  85. ALIGN((mb_width * 16), 64)
  86. * (mb_height * 8)
  87. + 64;
  88. } else {
  89. ctx->luma_dpb_size =
  90. ALIGN((lcu_width * 32), 64)
  91. * ALIGN((lcu_height * 32), 32)
  92. + 64;
  93. ctx->chroma_dpb_size =
  94. ALIGN((lcu_width * 32), 64)
  95. * (lcu_height * 16)
  96. + 64;
  97. }
  98. } else {
  99. ctx->luma_dpb_size = ALIGN((mb_width * mb_height) *
  100. S5P_FIMV_LUMA_MB_TO_PIXEL_V6,
  101. S5P_FIMV_LUMA_DPB_BUFFER_ALIGN_V6);
  102. ctx->chroma_dpb_size = ALIGN((mb_width * mb_height) *
  103. S5P_FIMV_CHROMA_MB_TO_PIXEL_V6,
  104. S5P_FIMV_CHROMA_DPB_BUFFER_ALIGN_V6);
  105. }
  106. if (IS_MFCV8_PLUS(dev))
  107. ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V8(
  108. ctx->img_width, ctx->img_height,
  109. mb_width, mb_height),
  110. S5P_FIMV_ME_BUFFER_ALIGN_V6);
  111. else
  112. ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V6(
  113. ctx->img_width, ctx->img_height,
  114. mb_width, mb_height),
  115. S5P_FIMV_ME_BUFFER_ALIGN_V6);
  116. mfc_debug(2, "recon luma size: %zu chroma size: %zu\n",
  117. ctx->luma_dpb_size, ctx->chroma_dpb_size);
  118. } else {
  119. return -EINVAL;
  120. }
  121. /* Codecs have different memory requirements */
  122. switch (ctx->codec_mode) {
  123. case S5P_MFC_CODEC_H264_DEC:
  124. case S5P_MFC_CODEC_H264_MVC_DEC:
  125. if (IS_MFCV10(dev))
  126. mfc_debug(2, "Use min scratch buffer size\n");
  127. else if (IS_MFCV8_PLUS(dev))
  128. ctx->scratch_buf_size =
  129. S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V8(
  130. mb_width,
  131. mb_height);
  132. else
  133. ctx->scratch_buf_size =
  134. S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(
  135. mb_width,
  136. mb_height);
  137. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  138. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  139. ctx->bank1.size =
  140. ctx->scratch_buf_size +
  141. (ctx->mv_count * ctx->mv_size);
  142. break;
  143. case S5P_MFC_CODEC_MPEG4_DEC:
  144. if (IS_MFCV10(dev))
  145. mfc_debug(2, "Use min scratch buffer size\n");
  146. else if (IS_MFCV7_PLUS(dev)) {
  147. ctx->scratch_buf_size =
  148. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V7(
  149. mb_width,
  150. mb_height);
  151. } else {
  152. ctx->scratch_buf_size =
  153. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(
  154. mb_width,
  155. mb_height);
  156. }
  157. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  158. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  159. ctx->bank1.size = ctx->scratch_buf_size;
  160. break;
  161. case S5P_MFC_CODEC_VC1RCV_DEC:
  162. case S5P_MFC_CODEC_VC1_DEC:
  163. if (IS_MFCV10(dev))
  164. mfc_debug(2, "Use min scratch buffer size\n");
  165. else
  166. ctx->scratch_buf_size =
  167. S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(
  168. mb_width,
  169. mb_height);
  170. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  171. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  172. ctx->bank1.size = ctx->scratch_buf_size;
  173. break;
  174. case S5P_MFC_CODEC_MPEG2_DEC:
  175. ctx->bank1.size = 0;
  176. ctx->bank2.size = 0;
  177. break;
  178. case S5P_MFC_CODEC_H263_DEC:
  179. if (IS_MFCV10(dev))
  180. mfc_debug(2, "Use min scratch buffer size\n");
  181. else
  182. ctx->scratch_buf_size =
  183. S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(
  184. mb_width,
  185. mb_height);
  186. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  187. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  188. ctx->bank1.size = ctx->scratch_buf_size;
  189. break;
  190. case S5P_MFC_CODEC_VP8_DEC:
  191. if (IS_MFCV10(dev))
  192. mfc_debug(2, "Use min scratch buffer size\n");
  193. else if (IS_MFCV8_PLUS(dev))
  194. ctx->scratch_buf_size =
  195. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V8(
  196. mb_width,
  197. mb_height);
  198. else
  199. ctx->scratch_buf_size =
  200. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V6(
  201. mb_width,
  202. mb_height);
  203. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  204. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  205. ctx->bank1.size = ctx->scratch_buf_size;
  206. break;
  207. case S5P_MFC_CODEC_HEVC_DEC:
  208. mfc_debug(2, "Use min scratch buffer size\n");
  209. ctx->bank1.size =
  210. ctx->scratch_buf_size +
  211. (ctx->mv_count * ctx->mv_size);
  212. break;
  213. case S5P_MFC_CODEC_VP9_DEC:
  214. mfc_debug(2, "Use min scratch buffer size\n");
  215. ctx->bank1.size =
  216. ctx->scratch_buf_size +
  217. DEC_VP9_STATIC_BUFFER_SIZE;
  218. break;
  219. case S5P_MFC_CODEC_H264_ENC:
  220. if (IS_MFCV10(dev)) {
  221. mfc_debug(2, "Use min scratch buffer size\n");
  222. ctx->me_buffer_size =
  223. ALIGN(ENC_V100_H264_ME_SIZE(mb_width, mb_height), 16);
  224. } else if (IS_MFCV8_PLUS(dev))
  225. ctx->scratch_buf_size =
  226. S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V8(
  227. mb_width,
  228. mb_height);
  229. else
  230. ctx->scratch_buf_size =
  231. S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V6(
  232. mb_width,
  233. mb_height);
  234. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  235. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  236. ctx->bank1.size =
  237. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  238. (ctx->pb_count * (ctx->luma_dpb_size +
  239. ctx->chroma_dpb_size + ctx->me_buffer_size));
  240. ctx->bank2.size = 0;
  241. break;
  242. case S5P_MFC_CODEC_MPEG4_ENC:
  243. case S5P_MFC_CODEC_H263_ENC:
  244. if (IS_MFCV10(dev)) {
  245. mfc_debug(2, "Use min scratch buffer size\n");
  246. ctx->me_buffer_size =
  247. ALIGN(ENC_V100_MPEG4_ME_SIZE(mb_width,
  248. mb_height), 16);
  249. } else
  250. ctx->scratch_buf_size =
  251. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_ENC_V6(
  252. mb_width,
  253. mb_height);
  254. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  255. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  256. ctx->bank1.size =
  257. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  258. (ctx->pb_count * (ctx->luma_dpb_size +
  259. ctx->chroma_dpb_size + ctx->me_buffer_size));
  260. ctx->bank2.size = 0;
  261. break;
  262. case S5P_MFC_CODEC_VP8_ENC:
  263. if (IS_MFCV10(dev)) {
  264. mfc_debug(2, "Use min scratch buffer size\n");
  265. ctx->me_buffer_size =
  266. ALIGN(ENC_V100_VP8_ME_SIZE(mb_width, mb_height),
  267. 16);
  268. } else if (IS_MFCV8_PLUS(dev))
  269. ctx->scratch_buf_size =
  270. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V8(
  271. mb_width,
  272. mb_height);
  273. else
  274. ctx->scratch_buf_size =
  275. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V7(
  276. mb_width,
  277. mb_height);
  278. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  279. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  280. ctx->bank1.size =
  281. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  282. (ctx->pb_count * (ctx->luma_dpb_size +
  283. ctx->chroma_dpb_size + ctx->me_buffer_size));
  284. ctx->bank2.size = 0;
  285. break;
  286. case S5P_MFC_CODEC_HEVC_ENC:
  287. mfc_debug(2, "Use min scratch buffer size\n");
  288. ctx->me_buffer_size =
  289. ALIGN(ENC_V100_HEVC_ME_SIZE(lcu_width, lcu_height), 16);
  290. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size, 256);
  291. ctx->bank1.size =
  292. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  293. (ctx->pb_count * (ctx->luma_dpb_size +
  294. ctx->chroma_dpb_size + ctx->me_buffer_size));
  295. ctx->bank2.size = 0;
  296. break;
  297. default:
  298. break;
  299. }
  300. /* Allocate only if memory from bank 1 is necessary */
  301. if (ctx->bank1.size > 0) {
  302. ret = s5p_mfc_alloc_generic_buf(dev, BANK_L_CTX, &ctx->bank1);
  303. if (ret) {
  304. mfc_err("Failed to allocate Bank1 memory\n");
  305. return ret;
  306. }
  307. BUG_ON(ctx->bank1.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
  308. }
  309. return 0;
  310. }
  311. /* Release buffers allocated for codec */
  312. static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
  313. {
  314. s5p_mfc_release_generic_buf(ctx->dev, &ctx->bank1);
  315. }
  316. /* Allocate memory for instance data buffer */
  317. static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
  318. {
  319. struct s5p_mfc_dev *dev = ctx->dev;
  320. struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
  321. int ret;
  322. mfc_debug_enter();
  323. switch (ctx->codec_mode) {
  324. case S5P_MFC_CODEC_H264_DEC:
  325. case S5P_MFC_CODEC_H264_MVC_DEC:
  326. case S5P_MFC_CODEC_HEVC_DEC:
  327. ctx->ctx.size = buf_size->h264_dec_ctx;
  328. break;
  329. case S5P_MFC_CODEC_MPEG4_DEC:
  330. case S5P_MFC_CODEC_H263_DEC:
  331. case S5P_MFC_CODEC_VC1RCV_DEC:
  332. case S5P_MFC_CODEC_VC1_DEC:
  333. case S5P_MFC_CODEC_MPEG2_DEC:
  334. case S5P_MFC_CODEC_VP8_DEC:
  335. case S5P_MFC_CODEC_VP9_DEC:
  336. ctx->ctx.size = buf_size->other_dec_ctx;
  337. break;
  338. case S5P_MFC_CODEC_H264_ENC:
  339. ctx->ctx.size = buf_size->h264_enc_ctx;
  340. break;
  341. case S5P_MFC_CODEC_HEVC_ENC:
  342. ctx->ctx.size = buf_size->hevc_enc_ctx;
  343. break;
  344. case S5P_MFC_CODEC_MPEG4_ENC:
  345. case S5P_MFC_CODEC_H263_ENC:
  346. case S5P_MFC_CODEC_VP8_ENC:
  347. ctx->ctx.size = buf_size->other_enc_ctx;
  348. break;
  349. default:
  350. ctx->ctx.size = 0;
  351. mfc_err("Codec type(%d) should be checked!\n", ctx->codec_mode);
  352. break;
  353. }
  354. ret = s5p_mfc_alloc_priv_buf(dev, BANK_L_CTX, &ctx->ctx);
  355. if (ret) {
  356. mfc_err("Failed to allocate instance buffer\n");
  357. return ret;
  358. }
  359. memset(ctx->ctx.virt, 0, ctx->ctx.size);
  360. wmb();
  361. mfc_debug_leave();
  362. return 0;
  363. }
  364. /* Release instance buffer */
  365. static void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
  366. {
  367. s5p_mfc_release_priv_buf(ctx->dev, &ctx->ctx);
  368. }
  369. /* Allocate context buffers for SYS_INIT */
  370. static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
  371. {
  372. struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
  373. int ret;
  374. mfc_debug_enter();
  375. dev->ctx_buf.size = buf_size->dev_ctx;
  376. ret = s5p_mfc_alloc_priv_buf(dev, BANK_L_CTX, &dev->ctx_buf);
  377. if (ret) {
  378. mfc_err("Failed to allocate device context buffer\n");
  379. return ret;
  380. }
  381. memset(dev->ctx_buf.virt, 0, buf_size->dev_ctx);
  382. wmb();
  383. mfc_debug_leave();
  384. return 0;
  385. }
  386. /* Release context buffers for SYS_INIT */
  387. static void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
  388. {
  389. s5p_mfc_release_priv_buf(dev, &dev->ctx_buf);
  390. }
  391. static int calc_plane(int width, int height)
  392. {
  393. int mbX, mbY;
  394. mbX = DIV_ROUND_UP(width, S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
  395. mbY = DIV_ROUND_UP(height, S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6);
  396. if (width * height < S5P_FIMV_MAX_FRAME_SIZE_V6)
  397. mbY = (mbY + 1) / 2 * 2;
  398. return (mbX * S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6) *
  399. (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
  400. }
  401. static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx)
  402. {
  403. struct s5p_mfc_dev *dev = ctx->dev;
  404. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6);
  405. ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN_V6);
  406. mfc_debug(2, "SEQ Done: Movie dimensions %dx%d,\n"
  407. "buffer dimensions: %dx%d\n", ctx->img_width,
  408. ctx->img_height, ctx->buf_width, ctx->buf_height);
  409. ctx->luma_size = calc_plane(ctx->img_width, ctx->img_height);
  410. ctx->chroma_size = calc_plane(ctx->img_width, (ctx->img_height >> 1));
  411. if (IS_MFCV8_PLUS(ctx->dev)) {
  412. /* MFCv8 needs additional 64 bytes for luma,chroma dpb*/
  413. ctx->luma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
  414. ctx->chroma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
  415. }
  416. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
  417. ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
  418. if (IS_MFCV10(dev)) {
  419. ctx->mv_size = S5P_MFC_DEC_MV_SIZE_V10(ctx->img_width,
  420. ctx->img_height);
  421. } else {
  422. ctx->mv_size = S5P_MFC_DEC_MV_SIZE_V6(ctx->img_width,
  423. ctx->img_height);
  424. }
  425. } else if (ctx->codec_mode == S5P_MFC_CODEC_HEVC_DEC) {
  426. ctx->mv_size = s5p_mfc_dec_hevc_mv_size(ctx->img_width,
  427. ctx->img_height);
  428. ctx->mv_size = ALIGN(ctx->mv_size, 32);
  429. } else {
  430. ctx->mv_size = 0;
  431. }
  432. }
  433. static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
  434. {
  435. unsigned int mb_width, mb_height;
  436. mb_width = MB_WIDTH(ctx->img_width);
  437. mb_height = MB_HEIGHT(ctx->img_height);
  438. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
  439. ctx->luma_size = ALIGN((mb_width * mb_height) * 256, 256);
  440. ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
  441. /* MFCv7 needs pad bytes for Luma and Chroma */
  442. if (IS_MFCV7_PLUS(ctx->dev)) {
  443. ctx->luma_size += MFC_LUMA_PAD_BYTES_V7;
  444. ctx->chroma_size += MFC_CHROMA_PAD_BYTES_V7;
  445. }
  446. }
  447. /* Set registers for decoding stream buffer */
  448. static int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
  449. int buf_addr, unsigned int start_num_byte,
  450. unsigned int strm_size)
  451. {
  452. struct s5p_mfc_dev *dev = ctx->dev;
  453. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  454. struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size;
  455. mfc_debug_enter();
  456. mfc_debug(2, "inst_no: %d, buf_addr: 0x%08x,\n"
  457. "buf_size: 0x%08x (%d)\n",
  458. ctx->inst_no, buf_addr, strm_size, strm_size);
  459. writel(strm_size, mfc_regs->d_stream_data_size);
  460. writel(buf_addr, mfc_regs->d_cpb_buffer_addr);
  461. writel(buf_size->cpb, mfc_regs->d_cpb_buffer_size);
  462. writel(start_num_byte, mfc_regs->d_cpb_buffer_offset);
  463. mfc_debug_leave();
  464. return 0;
  465. }
  466. /* Set decoding frame buffer */
  467. static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
  468. {
  469. unsigned int frame_size, i;
  470. unsigned int frame_size_ch, frame_size_mv;
  471. struct s5p_mfc_dev *dev = ctx->dev;
  472. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  473. size_t buf_addr1;
  474. int buf_size1;
  475. int align_gap;
  476. buf_addr1 = ctx->bank1.dma;
  477. buf_size1 = ctx->bank1.size;
  478. mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
  479. mfc_debug(2, "Total DPB COUNT: %d\n", ctx->total_dpb_count);
  480. mfc_debug(2, "Setting display delay to %d\n", ctx->display_delay);
  481. writel(ctx->total_dpb_count, mfc_regs->d_num_dpb);
  482. writel(ctx->luma_size, mfc_regs->d_first_plane_dpb_size);
  483. writel(ctx->chroma_size, mfc_regs->d_second_plane_dpb_size);
  484. writel(buf_addr1, mfc_regs->d_scratch_buffer_addr);
  485. writel(ctx->scratch_buf_size, mfc_regs->d_scratch_buffer_size);
  486. if (IS_MFCV8_PLUS(dev)) {
  487. writel(ctx->img_width,
  488. mfc_regs->d_first_plane_dpb_stride_size);
  489. writel(ctx->img_width,
  490. mfc_regs->d_second_plane_dpb_stride_size);
  491. }
  492. buf_addr1 += ctx->scratch_buf_size;
  493. buf_size1 -= ctx->scratch_buf_size;
  494. if (ctx->codec_mode == S5P_FIMV_CODEC_H264_DEC ||
  495. ctx->codec_mode == S5P_FIMV_CODEC_H264_MVC_DEC ||
  496. ctx->codec_mode == S5P_FIMV_CODEC_HEVC_DEC) {
  497. writel(ctx->mv_size, mfc_regs->d_mv_buffer_size);
  498. writel(ctx->mv_count, mfc_regs->d_num_mv);
  499. }
  500. frame_size = ctx->luma_size;
  501. frame_size_ch = ctx->chroma_size;
  502. frame_size_mv = ctx->mv_size;
  503. mfc_debug(2, "Frame size: %d ch: %d mv: %d\n",
  504. frame_size, frame_size_ch, frame_size_mv);
  505. for (i = 0; i < ctx->total_dpb_count; i++) {
  506. /* Bank2 */
  507. mfc_debug(2, "Luma %d: %zx\n", i,
  508. ctx->dst_bufs[i].cookie.raw.luma);
  509. writel(ctx->dst_bufs[i].cookie.raw.luma,
  510. mfc_regs->d_first_plane_dpb + i * 4);
  511. mfc_debug(2, "\tChroma %d: %zx\n", i,
  512. ctx->dst_bufs[i].cookie.raw.chroma);
  513. writel(ctx->dst_bufs[i].cookie.raw.chroma,
  514. mfc_regs->d_second_plane_dpb + i * 4);
  515. }
  516. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
  517. ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC ||
  518. ctx->codec_mode == S5P_MFC_CODEC_HEVC_DEC) {
  519. for (i = 0; i < ctx->mv_count; i++) {
  520. /* To test alignment */
  521. align_gap = buf_addr1;
  522. buf_addr1 = ALIGN(buf_addr1, 16);
  523. align_gap = buf_addr1 - align_gap;
  524. buf_size1 -= align_gap;
  525. mfc_debug(2, "\tBuf1: %zx, size: %d\n",
  526. buf_addr1, buf_size1);
  527. writel(buf_addr1, mfc_regs->d_mv_buffer + i * 4);
  528. buf_addr1 += frame_size_mv;
  529. buf_size1 -= frame_size_mv;
  530. }
  531. }
  532. if (ctx->codec_mode == S5P_FIMV_CODEC_VP9_DEC) {
  533. writel(buf_addr1, mfc_regs->d_static_buffer_addr);
  534. writel(DEC_VP9_STATIC_BUFFER_SIZE,
  535. mfc_regs->d_static_buffer_size);
  536. buf_addr1 += DEC_VP9_STATIC_BUFFER_SIZE;
  537. buf_size1 -= DEC_VP9_STATIC_BUFFER_SIZE;
  538. }
  539. mfc_debug(2, "Buf1: %zx, buf_size1: %d (frames %d)\n",
  540. buf_addr1, buf_size1, ctx->total_dpb_count);
  541. if (buf_size1 < 0) {
  542. mfc_debug(2, "Not enough memory has been allocated.\n");
  543. return -ENOMEM;
  544. }
  545. writel(ctx->inst_no, mfc_regs->instance_id);
  546. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  547. S5P_FIMV_CH_INIT_BUFS_V6, NULL);
  548. mfc_debug(2, "After setting buffers.\n");
  549. return 0;
  550. }
  551. /* Set registers for encoding stream buffer */
  552. static int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
  553. unsigned long addr, unsigned int size)
  554. {
  555. struct s5p_mfc_dev *dev = ctx->dev;
  556. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  557. writel(addr, mfc_regs->e_stream_buffer_addr); /* 16B align */
  558. writel(size, mfc_regs->e_stream_buffer_size);
  559. mfc_debug(2, "stream buf addr: 0x%08lx, size: 0x%x\n",
  560. addr, size);
  561. return 0;
  562. }
  563. static void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
  564. unsigned long y_addr, unsigned long c_addr)
  565. {
  566. struct s5p_mfc_dev *dev = ctx->dev;
  567. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  568. writel(y_addr, mfc_regs->e_source_first_plane_addr);
  569. writel(c_addr, mfc_regs->e_source_second_plane_addr);
  570. mfc_debug(2, "enc src y buf addr: 0x%08lx\n", y_addr);
  571. mfc_debug(2, "enc src c buf addr: 0x%08lx\n", c_addr);
  572. }
  573. static void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
  574. unsigned long *y_addr, unsigned long *c_addr)
  575. {
  576. struct s5p_mfc_dev *dev = ctx->dev;
  577. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  578. unsigned long enc_recon_y_addr, enc_recon_c_addr;
  579. *y_addr = readl(mfc_regs->e_encoded_source_first_plane_addr);
  580. *c_addr = readl(mfc_regs->e_encoded_source_second_plane_addr);
  581. enc_recon_y_addr = readl(mfc_regs->e_recon_luma_dpb_addr);
  582. enc_recon_c_addr = readl(mfc_regs->e_recon_chroma_dpb_addr);
  583. mfc_debug(2, "recon y addr: 0x%08lx y_addr: 0x%08lx\n", enc_recon_y_addr, *y_addr);
  584. mfc_debug(2, "recon c addr: 0x%08lx\n", enc_recon_c_addr);
  585. }
  586. /* Set encoding ref & codec buffer */
  587. static int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx)
  588. {
  589. struct s5p_mfc_dev *dev = ctx->dev;
  590. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  591. size_t buf_addr1;
  592. int i, buf_size1;
  593. mfc_debug_enter();
  594. buf_addr1 = ctx->bank1.dma;
  595. buf_size1 = ctx->bank1.size;
  596. mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
  597. if (IS_MFCV10(dev)) {
  598. /* start address of per buffer is aligned */
  599. for (i = 0; i < ctx->pb_count; i++) {
  600. writel(buf_addr1, mfc_regs->e_luma_dpb + (4 * i));
  601. buf_addr1 += ctx->luma_dpb_size;
  602. buf_size1 -= ctx->luma_dpb_size;
  603. }
  604. for (i = 0; i < ctx->pb_count; i++) {
  605. writel(buf_addr1, mfc_regs->e_chroma_dpb + (4 * i));
  606. buf_addr1 += ctx->chroma_dpb_size;
  607. buf_size1 -= ctx->chroma_dpb_size;
  608. }
  609. for (i = 0; i < ctx->pb_count; i++) {
  610. writel(buf_addr1, mfc_regs->e_me_buffer + (4 * i));
  611. buf_addr1 += ctx->me_buffer_size;
  612. buf_size1 -= ctx->me_buffer_size;
  613. }
  614. } else {
  615. for (i = 0; i < ctx->pb_count; i++) {
  616. writel(buf_addr1, mfc_regs->e_luma_dpb + (4 * i));
  617. buf_addr1 += ctx->luma_dpb_size;
  618. writel(buf_addr1, mfc_regs->e_chroma_dpb + (4 * i));
  619. buf_addr1 += ctx->chroma_dpb_size;
  620. writel(buf_addr1, mfc_regs->e_me_buffer + (4 * i));
  621. buf_addr1 += ctx->me_buffer_size;
  622. buf_size1 -= (ctx->luma_dpb_size + ctx->chroma_dpb_size
  623. + ctx->me_buffer_size);
  624. }
  625. }
  626. writel(buf_addr1, mfc_regs->e_scratch_buffer_addr);
  627. writel(ctx->scratch_buf_size, mfc_regs->e_scratch_buffer_size);
  628. buf_addr1 += ctx->scratch_buf_size;
  629. buf_size1 -= ctx->scratch_buf_size;
  630. writel(buf_addr1, mfc_regs->e_tmv_buffer0);
  631. buf_addr1 += ctx->tmv_buffer_size >> 1;
  632. writel(buf_addr1, mfc_regs->e_tmv_buffer1);
  633. buf_addr1 += ctx->tmv_buffer_size >> 1;
  634. buf_size1 -= ctx->tmv_buffer_size;
  635. mfc_debug(2, "Buf1: %zu, buf_size1: %d (ref frames %d)\n",
  636. buf_addr1, buf_size1, ctx->pb_count);
  637. if (buf_size1 < 0) {
  638. mfc_debug(2, "Not enough memory has been allocated.\n");
  639. return -ENOMEM;
  640. }
  641. writel(ctx->inst_no, mfc_regs->instance_id);
  642. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  643. S5P_FIMV_CH_INIT_BUFS_V6, NULL);
  644. mfc_debug_leave();
  645. return 0;
  646. }
  647. static int s5p_mfc_set_slice_mode(struct s5p_mfc_ctx *ctx)
  648. {
  649. struct s5p_mfc_dev *dev = ctx->dev;
  650. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  651. /* multi-slice control */
  652. /* multi-slice MB number or bit size */
  653. writel(ctx->slice_mode, mfc_regs->e_mslice_mode);
  654. if (ctx->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
  655. writel(ctx->slice_size.mb, mfc_regs->e_mslice_size_mb);
  656. } else if (ctx->slice_mode ==
  657. V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
  658. writel(ctx->slice_size.bits, mfc_regs->e_mslice_size_bits);
  659. } else {
  660. writel(0x0, mfc_regs->e_mslice_size_mb);
  661. writel(0x0, mfc_regs->e_mslice_size_bits);
  662. }
  663. return 0;
  664. }
  665. static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx)
  666. {
  667. struct s5p_mfc_dev *dev = ctx->dev;
  668. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  669. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  670. unsigned int reg = 0;
  671. mfc_debug_enter();
  672. /* width */
  673. writel(ctx->img_width, mfc_regs->e_frame_width); /* 16 align */
  674. /* height */
  675. writel(ctx->img_height, mfc_regs->e_frame_height); /* 16 align */
  676. /* cropped width */
  677. writel(ctx->img_width, mfc_regs->e_cropped_frame_width);
  678. /* cropped height */
  679. writel(ctx->img_height, mfc_regs->e_cropped_frame_height);
  680. /* cropped offset */
  681. writel(0x0, mfc_regs->e_frame_crop_offset);
  682. /* pictype : IDR period */
  683. reg = 0;
  684. reg |= p->gop_size & 0xFFFF;
  685. writel(reg, mfc_regs->e_gop_config);
  686. /* multi-slice control */
  687. /* multi-slice MB number or bit size */
  688. ctx->slice_mode = p->slice_mode;
  689. reg = 0;
  690. if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
  691. reg |= (0x1 << 3);
  692. writel(reg, mfc_regs->e_enc_options);
  693. ctx->slice_size.mb = p->slice_mb;
  694. } else if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
  695. reg |= (0x1 << 3);
  696. writel(reg, mfc_regs->e_enc_options);
  697. ctx->slice_size.bits = p->slice_bit;
  698. } else {
  699. reg &= ~(0x1 << 3);
  700. writel(reg, mfc_regs->e_enc_options);
  701. }
  702. s5p_mfc_set_slice_mode(ctx);
  703. /* cyclic intra refresh */
  704. writel(p->intra_refresh_mb, mfc_regs->e_ir_size);
  705. reg = readl(mfc_regs->e_enc_options);
  706. if (p->intra_refresh_mb == 0)
  707. reg &= ~(0x1 << 4);
  708. else
  709. reg |= (0x1 << 4);
  710. writel(reg, mfc_regs->e_enc_options);
  711. /* 'NON_REFERENCE_STORE_ENABLE' for debugging */
  712. reg = readl(mfc_regs->e_enc_options);
  713. reg &= ~(0x1 << 9);
  714. writel(reg, mfc_regs->e_enc_options);
  715. /* memory structure cur. frame */
  716. if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) {
  717. /* 0: Linear, 1: 2D tiled*/
  718. reg = readl(mfc_regs->e_enc_options);
  719. reg &= ~(0x1 << 7);
  720. writel(reg, mfc_regs->e_enc_options);
  721. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  722. writel(0x0, mfc_regs->pixel_format);
  723. } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV21M) {
  724. /* 0: Linear, 1: 2D tiled*/
  725. reg = readl(mfc_regs->e_enc_options);
  726. reg &= ~(0x1 << 7);
  727. writel(reg, mfc_regs->e_enc_options);
  728. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  729. writel(0x1, mfc_regs->pixel_format);
  730. } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16) {
  731. /* 0: Linear, 1: 2D tiled*/
  732. reg = readl(mfc_regs->e_enc_options);
  733. reg |= (0x1 << 7);
  734. writel(reg, mfc_regs->e_enc_options);
  735. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  736. writel(0x0, mfc_regs->pixel_format);
  737. }
  738. /* memory structure recon. frame */
  739. /* 0: Linear, 1: 2D tiled */
  740. reg = readl(mfc_regs->e_enc_options);
  741. reg |= (0x1 << 8);
  742. writel(reg, mfc_regs->e_enc_options);
  743. /* padding control & value */
  744. writel(0x0, mfc_regs->e_padding_ctrl);
  745. if (p->pad) {
  746. reg = 0;
  747. /** enable */
  748. reg |= (1 << 31);
  749. /** cr value */
  750. reg |= ((p->pad_cr & 0xFF) << 16);
  751. /** cb value */
  752. reg |= ((p->pad_cb & 0xFF) << 8);
  753. /** y value */
  754. reg |= p->pad_luma & 0xFF;
  755. writel(reg, mfc_regs->e_padding_ctrl);
  756. }
  757. /* rate control config. */
  758. reg = 0;
  759. /* frame-level rate control */
  760. reg |= ((p->rc_frame & 0x1) << 9);
  761. writel(reg, mfc_regs->e_rc_config);
  762. /* bit rate */
  763. if (p->rc_frame)
  764. writel(p->rc_bitrate,
  765. mfc_regs->e_rc_bit_rate);
  766. else
  767. writel(1, mfc_regs->e_rc_bit_rate);
  768. /* reaction coefficient */
  769. if (p->rc_frame) {
  770. if (p->rc_reaction_coeff < TIGHT_CBR_MAX) /* tight CBR */
  771. writel(1, mfc_regs->e_rc_mode);
  772. else /* loose CBR */
  773. writel(2, mfc_regs->e_rc_mode);
  774. }
  775. /* seq header ctrl */
  776. reg = readl(mfc_regs->e_enc_options);
  777. reg &= ~(0x1 << 2);
  778. reg |= ((p->seq_hdr_mode & 0x1) << 2);
  779. /* frame skip mode */
  780. reg &= ~(0x3);
  781. reg |= (p->frame_skip_mode & 0x3);
  782. writel(reg, mfc_regs->e_enc_options);
  783. /* 'DROP_CONTROL_ENABLE', disable */
  784. reg = readl(mfc_regs->e_rc_config);
  785. reg &= ~(0x1 << 10);
  786. writel(reg, mfc_regs->e_rc_config);
  787. /* setting for MV range [16, 256] */
  788. reg = (p->mv_h_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
  789. writel(reg, mfc_regs->e_mv_hor_range);
  790. reg = (p->mv_v_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
  791. writel(reg, mfc_regs->e_mv_ver_range);
  792. writel(0x0, mfc_regs->e_frame_insertion);
  793. writel(0x0, mfc_regs->e_roi_buffer_addr);
  794. writel(0x0, mfc_regs->e_param_change);
  795. writel(0x0, mfc_regs->e_rc_roi_ctrl);
  796. writel(0x0, mfc_regs->e_picture_tag);
  797. writel(0x0, mfc_regs->e_bit_count_enable);
  798. writel(0x0, mfc_regs->e_max_bit_count);
  799. writel(0x0, mfc_regs->e_min_bit_count);
  800. writel(0x0, mfc_regs->e_metadata_buffer_addr);
  801. writel(0x0, mfc_regs->e_metadata_buffer_size);
  802. mfc_debug_leave();
  803. return 0;
  804. }
  805. static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)
  806. {
  807. struct s5p_mfc_dev *dev = ctx->dev;
  808. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  809. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  810. struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
  811. unsigned int reg = 0;
  812. int i;
  813. mfc_debug_enter();
  814. s5p_mfc_set_enc_params(ctx);
  815. /* pictype : number of B */
  816. reg = readl(mfc_regs->e_gop_config);
  817. reg &= ~(0x3 << 16);
  818. reg |= ((p->num_b_frame & 0x3) << 16);
  819. writel(reg, mfc_regs->e_gop_config);
  820. /* profile & level */
  821. reg = 0;
  822. /** level */
  823. reg |= ((p_h264->level & 0xFF) << 8);
  824. /** profile - 0 ~ 3 */
  825. reg |= p_h264->profile & 0x3F;
  826. writel(reg, mfc_regs->e_picture_profile);
  827. /* rate control config. */
  828. reg = readl(mfc_regs->e_rc_config);
  829. /** macroblock level rate control */
  830. reg &= ~(0x1 << 8);
  831. reg |= ((p->rc_mb & 0x1) << 8);
  832. writel(reg, mfc_regs->e_rc_config);
  833. /** frame QP */
  834. reg &= ~(0x3F);
  835. reg |= p_h264->rc_frame_qp & 0x3F;
  836. writel(reg, mfc_regs->e_rc_config);
  837. /* max & min value of QP */
  838. reg = 0;
  839. /** max QP */
  840. reg |= ((p_h264->rc_max_qp & 0x3F) << 8);
  841. /** min QP */
  842. reg |= p_h264->rc_min_qp & 0x3F;
  843. writel(reg, mfc_regs->e_rc_qp_bound);
  844. /* other QPs */
  845. writel(0x0, mfc_regs->e_fixed_picture_qp);
  846. if (!p->rc_frame && !p->rc_mb) {
  847. reg = 0;
  848. reg |= ((p_h264->rc_b_frame_qp & 0x3F) << 16);
  849. reg |= ((p_h264->rc_p_frame_qp & 0x3F) << 8);
  850. reg |= p_h264->rc_frame_qp & 0x3F;
  851. writel(reg, mfc_regs->e_fixed_picture_qp);
  852. }
  853. /* frame rate */
  854. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  855. reg = 0;
  856. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  857. reg |= p->rc_framerate_denom & 0xFFFF;
  858. writel(reg, mfc_regs->e_rc_frame_rate);
  859. }
  860. /* vbv buffer size */
  861. if (p->frame_skip_mode ==
  862. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  863. writel(p_h264->cpb_size & 0xFFFF,
  864. mfc_regs->e_vbv_buffer_size);
  865. if (p->rc_frame)
  866. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  867. }
  868. /* interlace */
  869. reg = 0;
  870. reg |= ((p_h264->interlace & 0x1) << 3);
  871. writel(reg, mfc_regs->e_h264_options);
  872. /* height */
  873. if (p_h264->interlace) {
  874. writel(ctx->img_height >> 1,
  875. mfc_regs->e_frame_height); /* 32 align */
  876. /* cropped height */
  877. writel(ctx->img_height >> 1,
  878. mfc_regs->e_cropped_frame_height);
  879. }
  880. /* loop filter ctrl */
  881. reg = readl(mfc_regs->e_h264_options);
  882. reg &= ~(0x3 << 1);
  883. reg |= ((p_h264->loop_filter_mode & 0x3) << 1);
  884. writel(reg, mfc_regs->e_h264_options);
  885. /* loopfilter alpha offset */
  886. if (p_h264->loop_filter_alpha < 0) {
  887. reg = 0x10;
  888. reg |= (0xFF - p_h264->loop_filter_alpha) + 1;
  889. } else {
  890. reg = 0x00;
  891. reg |= (p_h264->loop_filter_alpha & 0xF);
  892. }
  893. writel(reg, mfc_regs->e_h264_lf_alpha_offset);
  894. /* loopfilter beta offset */
  895. if (p_h264->loop_filter_beta < 0) {
  896. reg = 0x10;
  897. reg |= (0xFF - p_h264->loop_filter_beta) + 1;
  898. } else {
  899. reg = 0x00;
  900. reg |= (p_h264->loop_filter_beta & 0xF);
  901. }
  902. writel(reg, mfc_regs->e_h264_lf_beta_offset);
  903. /* entropy coding mode */
  904. reg = readl(mfc_regs->e_h264_options);
  905. reg &= ~(0x1);
  906. reg |= p_h264->entropy_mode & 0x1;
  907. writel(reg, mfc_regs->e_h264_options);
  908. /* number of ref. picture */
  909. reg = readl(mfc_regs->e_h264_options);
  910. reg &= ~(0x1 << 7);
  911. reg |= (((p_h264->num_ref_pic_4p - 1) & 0x1) << 7);
  912. writel(reg, mfc_regs->e_h264_options);
  913. /* 8x8 transform enable */
  914. reg = readl(mfc_regs->e_h264_options);
  915. reg &= ~(0x3 << 12);
  916. reg |= ((p_h264->_8x8_transform & 0x3) << 12);
  917. writel(reg, mfc_regs->e_h264_options);
  918. /* macroblock adaptive scaling features */
  919. writel(0x0, mfc_regs->e_mb_rc_config);
  920. if (p->rc_mb) {
  921. reg = 0;
  922. /** dark region */
  923. reg |= ((p_h264->rc_mb_dark & 0x1) << 3);
  924. /** smooth region */
  925. reg |= ((p_h264->rc_mb_smooth & 0x1) << 2);
  926. /** static region */
  927. reg |= ((p_h264->rc_mb_static & 0x1) << 1);
  928. /** high activity region */
  929. reg |= p_h264->rc_mb_activity & 0x1;
  930. writel(reg, mfc_regs->e_mb_rc_config);
  931. }
  932. /* aspect ratio VUI */
  933. readl(mfc_regs->e_h264_options);
  934. reg &= ~(0x1 << 5);
  935. reg |= ((p_h264->vui_sar & 0x1) << 5);
  936. writel(reg, mfc_regs->e_h264_options);
  937. writel(0x0, mfc_regs->e_aspect_ratio);
  938. writel(0x0, mfc_regs->e_extended_sar);
  939. if (p_h264->vui_sar) {
  940. /* aspect ration IDC */
  941. reg = 0;
  942. reg |= p_h264->vui_sar_idc & 0xFF;
  943. writel(reg, mfc_regs->e_aspect_ratio);
  944. if (p_h264->vui_sar_idc == 0xFF) {
  945. /* extended SAR */
  946. reg = 0;
  947. reg |= (p_h264->vui_ext_sar_width & 0xFFFF) << 16;
  948. reg |= p_h264->vui_ext_sar_height & 0xFFFF;
  949. writel(reg, mfc_regs->e_extended_sar);
  950. }
  951. }
  952. /* intra picture period for H.264 open GOP */
  953. /* control */
  954. readl(mfc_regs->e_h264_options);
  955. reg &= ~(0x1 << 4);
  956. reg |= ((p_h264->open_gop & 0x1) << 4);
  957. writel(reg, mfc_regs->e_h264_options);
  958. /* value */
  959. writel(0x0, mfc_regs->e_h264_i_period);
  960. if (p_h264->open_gop) {
  961. reg = 0;
  962. reg |= p_h264->open_gop_size & 0xFFFF;
  963. writel(reg, mfc_regs->e_h264_i_period);
  964. }
  965. /* 'WEIGHTED_BI_PREDICTION' for B is disable */
  966. readl(mfc_regs->e_h264_options);
  967. reg &= ~(0x3 << 9);
  968. writel(reg, mfc_regs->e_h264_options);
  969. /* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */
  970. readl(mfc_regs->e_h264_options);
  971. reg &= ~(0x1 << 14);
  972. writel(reg, mfc_regs->e_h264_options);
  973. /* ASO */
  974. readl(mfc_regs->e_h264_options);
  975. reg &= ~(0x1 << 6);
  976. reg |= ((p_h264->aso & 0x1) << 6);
  977. writel(reg, mfc_regs->e_h264_options);
  978. /* hier qp enable */
  979. readl(mfc_regs->e_h264_options);
  980. reg &= ~(0x1 << 8);
  981. reg |= ((p_h264->open_gop & 0x1) << 8);
  982. writel(reg, mfc_regs->e_h264_options);
  983. reg = 0;
  984. if (p_h264->hier_qp && p_h264->hier_qp_layer) {
  985. reg |= (p_h264->hier_qp_type & 0x1) << 0x3;
  986. reg |= p_h264->hier_qp_layer & 0x7;
  987. writel(reg, mfc_regs->e_h264_num_t_layer);
  988. /* QP value for each layer */
  989. for (i = 0; i < p_h264->hier_qp_layer &&
  990. i < ARRAY_SIZE(p_h264->hier_qp_layer_qp); i++) {
  991. writel(p_h264->hier_qp_layer_qp[i],
  992. mfc_regs->e_h264_hierarchical_qp_layer0
  993. + i * 4);
  994. }
  995. }
  996. /* number of coding layer should be zero when hierarchical is disable */
  997. writel(reg, mfc_regs->e_h264_num_t_layer);
  998. /* frame packing SEI generation */
  999. readl(mfc_regs->e_h264_options);
  1000. reg &= ~(0x1 << 25);
  1001. reg |= ((p_h264->sei_frame_packing & 0x1) << 25);
  1002. writel(reg, mfc_regs->e_h264_options);
  1003. if (p_h264->sei_frame_packing) {
  1004. reg = 0;
  1005. /** current frame0 flag */
  1006. reg |= ((p_h264->sei_fp_curr_frame_0 & 0x1) << 2);
  1007. /** arrangement type */
  1008. reg |= p_h264->sei_fp_arrangement_type & 0x3;
  1009. writel(reg, mfc_regs->e_h264_frame_packing_sei_info);
  1010. }
  1011. if (p_h264->fmo) {
  1012. switch (p_h264->fmo_map_type) {
  1013. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES:
  1014. if (p_h264->fmo_slice_grp > 4)
  1015. p_h264->fmo_slice_grp = 4;
  1016. for (i = 0; i < (p_h264->fmo_slice_grp & 0xF); i++)
  1017. writel(p_h264->fmo_run_len[i] - 1,
  1018. mfc_regs->e_h264_fmo_run_length_minus1_0
  1019. + i * 4);
  1020. break;
  1021. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES:
  1022. if (p_h264->fmo_slice_grp > 4)
  1023. p_h264->fmo_slice_grp = 4;
  1024. break;
  1025. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN:
  1026. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN:
  1027. if (p_h264->fmo_slice_grp > 2)
  1028. p_h264->fmo_slice_grp = 2;
  1029. writel(p_h264->fmo_chg_dir & 0x1,
  1030. mfc_regs->e_h264_fmo_slice_grp_change_dir);
  1031. /* the valid range is 0 ~ number of macroblocks -1 */
  1032. writel(p_h264->fmo_chg_rate,
  1033. mfc_regs->e_h264_fmo_slice_grp_change_rate_minus1);
  1034. break;
  1035. default:
  1036. mfc_err("Unsupported map type for FMO: %d\n",
  1037. p_h264->fmo_map_type);
  1038. p_h264->fmo_map_type = 0;
  1039. p_h264->fmo_slice_grp = 1;
  1040. break;
  1041. }
  1042. writel(p_h264->fmo_map_type,
  1043. mfc_regs->e_h264_fmo_slice_grp_map_type);
  1044. writel(p_h264->fmo_slice_grp - 1,
  1045. mfc_regs->e_h264_fmo_num_slice_grp_minus1);
  1046. } else {
  1047. writel(0, mfc_regs->e_h264_fmo_num_slice_grp_minus1);
  1048. }
  1049. mfc_debug_leave();
  1050. return 0;
  1051. }
  1052. static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx *ctx)
  1053. {
  1054. struct s5p_mfc_dev *dev = ctx->dev;
  1055. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1056. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1057. struct s5p_mfc_mpeg4_enc_params *p_mpeg4 = &p->codec.mpeg4;
  1058. unsigned int reg = 0;
  1059. mfc_debug_enter();
  1060. s5p_mfc_set_enc_params(ctx);
  1061. /* pictype : number of B */
  1062. reg = readl(mfc_regs->e_gop_config);
  1063. reg &= ~(0x3 << 16);
  1064. reg |= ((p->num_b_frame & 0x3) << 16);
  1065. writel(reg, mfc_regs->e_gop_config);
  1066. /* profile & level */
  1067. reg = 0;
  1068. /** level */
  1069. reg |= ((p_mpeg4->level & 0xFF) << 8);
  1070. /** profile - 0 ~ 1 */
  1071. reg |= p_mpeg4->profile & 0x3F;
  1072. writel(reg, mfc_regs->e_picture_profile);
  1073. /* rate control config. */
  1074. reg = readl(mfc_regs->e_rc_config);
  1075. /** macroblock level rate control */
  1076. reg &= ~(0x1 << 8);
  1077. reg |= ((p->rc_mb & 0x1) << 8);
  1078. writel(reg, mfc_regs->e_rc_config);
  1079. /** frame QP */
  1080. reg &= ~(0x3F);
  1081. reg |= p_mpeg4->rc_frame_qp & 0x3F;
  1082. writel(reg, mfc_regs->e_rc_config);
  1083. /* max & min value of QP */
  1084. reg = 0;
  1085. /** max QP */
  1086. reg |= ((p_mpeg4->rc_max_qp & 0x3F) << 8);
  1087. /** min QP */
  1088. reg |= p_mpeg4->rc_min_qp & 0x3F;
  1089. writel(reg, mfc_regs->e_rc_qp_bound);
  1090. /* other QPs */
  1091. writel(0x0, mfc_regs->e_fixed_picture_qp);
  1092. if (!p->rc_frame && !p->rc_mb) {
  1093. reg = 0;
  1094. reg |= ((p_mpeg4->rc_b_frame_qp & 0x3F) << 16);
  1095. reg |= ((p_mpeg4->rc_p_frame_qp & 0x3F) << 8);
  1096. reg |= p_mpeg4->rc_frame_qp & 0x3F;
  1097. writel(reg, mfc_regs->e_fixed_picture_qp);
  1098. }
  1099. /* frame rate */
  1100. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  1101. reg = 0;
  1102. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  1103. reg |= p->rc_framerate_denom & 0xFFFF;
  1104. writel(reg, mfc_regs->e_rc_frame_rate);
  1105. }
  1106. /* vbv buffer size */
  1107. if (p->frame_skip_mode ==
  1108. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  1109. writel(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
  1110. if (p->rc_frame)
  1111. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  1112. }
  1113. /* Disable HEC */
  1114. writel(0x0, mfc_regs->e_mpeg4_options);
  1115. writel(0x0, mfc_regs->e_mpeg4_hec_period);
  1116. mfc_debug_leave();
  1117. return 0;
  1118. }
  1119. static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
  1120. {
  1121. struct s5p_mfc_dev *dev = ctx->dev;
  1122. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1123. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1124. struct s5p_mfc_mpeg4_enc_params *p_h263 = &p->codec.mpeg4;
  1125. unsigned int reg = 0;
  1126. mfc_debug_enter();
  1127. s5p_mfc_set_enc_params(ctx);
  1128. /* profile & level */
  1129. reg = 0;
  1130. /** profile */
  1131. reg |= (0x1 << 4);
  1132. writel(reg, mfc_regs->e_picture_profile);
  1133. /* rate control config. */
  1134. reg = readl(mfc_regs->e_rc_config);
  1135. /** macroblock level rate control */
  1136. reg &= ~(0x1 << 8);
  1137. reg |= ((p->rc_mb & 0x1) << 8);
  1138. writel(reg, mfc_regs->e_rc_config);
  1139. /** frame QP */
  1140. reg &= ~(0x3F);
  1141. reg |= p_h263->rc_frame_qp & 0x3F;
  1142. writel(reg, mfc_regs->e_rc_config);
  1143. /* max & min value of QP */
  1144. reg = 0;
  1145. /** max QP */
  1146. reg |= ((p_h263->rc_max_qp & 0x3F) << 8);
  1147. /** min QP */
  1148. reg |= p_h263->rc_min_qp & 0x3F;
  1149. writel(reg, mfc_regs->e_rc_qp_bound);
  1150. /* other QPs */
  1151. writel(0x0, mfc_regs->e_fixed_picture_qp);
  1152. if (!p->rc_frame && !p->rc_mb) {
  1153. reg = 0;
  1154. reg |= ((p_h263->rc_b_frame_qp & 0x3F) << 16);
  1155. reg |= ((p_h263->rc_p_frame_qp & 0x3F) << 8);
  1156. reg |= p_h263->rc_frame_qp & 0x3F;
  1157. writel(reg, mfc_regs->e_fixed_picture_qp);
  1158. }
  1159. /* frame rate */
  1160. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  1161. reg = 0;
  1162. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  1163. reg |= p->rc_framerate_denom & 0xFFFF;
  1164. writel(reg, mfc_regs->e_rc_frame_rate);
  1165. }
  1166. /* vbv buffer size */
  1167. if (p->frame_skip_mode ==
  1168. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  1169. writel(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
  1170. if (p->rc_frame)
  1171. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  1172. }
  1173. mfc_debug_leave();
  1174. return 0;
  1175. }
  1176. static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx *ctx)
  1177. {
  1178. struct s5p_mfc_dev *dev = ctx->dev;
  1179. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1180. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1181. struct s5p_mfc_vp8_enc_params *p_vp8 = &p->codec.vp8;
  1182. unsigned int reg = 0;
  1183. unsigned int val = 0;
  1184. mfc_debug_enter();
  1185. s5p_mfc_set_enc_params(ctx);
  1186. /* pictype : number of B */
  1187. reg = readl(mfc_regs->e_gop_config);
  1188. reg &= ~(0x3 << 16);
  1189. reg |= ((p->num_b_frame & 0x3) << 16);
  1190. writel(reg, mfc_regs->e_gop_config);
  1191. /* profile - 0 ~ 3 */
  1192. reg = p_vp8->profile & 0x3;
  1193. writel(reg, mfc_regs->e_picture_profile);
  1194. /* rate control config. */
  1195. reg = readl(mfc_regs->e_rc_config);
  1196. /** macroblock level rate control */
  1197. reg &= ~(0x1 << 8);
  1198. reg |= ((p->rc_mb & 0x1) << 8);
  1199. writel(reg, mfc_regs->e_rc_config);
  1200. /* frame rate */
  1201. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  1202. reg = 0;
  1203. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  1204. reg |= p->rc_framerate_denom & 0xFFFF;
  1205. writel(reg, mfc_regs->e_rc_frame_rate);
  1206. }
  1207. /* frame QP */
  1208. reg &= ~(0x7F);
  1209. reg |= p_vp8->rc_frame_qp & 0x7F;
  1210. writel(reg, mfc_regs->e_rc_config);
  1211. /* other QPs */
  1212. writel(0x0, mfc_regs->e_fixed_picture_qp);
  1213. if (!p->rc_frame && !p->rc_mb) {
  1214. reg = 0;
  1215. reg |= ((p_vp8->rc_p_frame_qp & 0x7F) << 8);
  1216. reg |= p_vp8->rc_frame_qp & 0x7F;
  1217. writel(reg, mfc_regs->e_fixed_picture_qp);
  1218. }
  1219. /* max QP */
  1220. reg = ((p_vp8->rc_max_qp & 0x7F) << 8);
  1221. /* min QP */
  1222. reg |= p_vp8->rc_min_qp & 0x7F;
  1223. writel(reg, mfc_regs->e_rc_qp_bound);
  1224. /* vbv buffer size */
  1225. if (p->frame_skip_mode ==
  1226. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  1227. writel(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
  1228. if (p->rc_frame)
  1229. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  1230. }
  1231. /* VP8 specific params */
  1232. reg = 0;
  1233. reg |= (p_vp8->imd_4x4 & 0x1) << 10;
  1234. switch (p_vp8->num_partitions) {
  1235. case V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION:
  1236. val = 0;
  1237. break;
  1238. case V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS:
  1239. val = 2;
  1240. break;
  1241. case V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS:
  1242. val = 4;
  1243. break;
  1244. case V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS:
  1245. val = 8;
  1246. break;
  1247. }
  1248. reg |= (val & 0xF) << 3;
  1249. reg |= (p_vp8->num_ref & 0x2);
  1250. writel(reg, mfc_regs->e_vp8_options);
  1251. mfc_debug_leave();
  1252. return 0;
  1253. }
  1254. static int s5p_mfc_set_enc_params_hevc(struct s5p_mfc_ctx *ctx)
  1255. {
  1256. struct s5p_mfc_dev *dev = ctx->dev;
  1257. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1258. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1259. struct s5p_mfc_hevc_enc_params *p_hevc = &p->codec.hevc;
  1260. unsigned int reg = 0;
  1261. int i;
  1262. mfc_debug_enter();
  1263. s5p_mfc_set_enc_params(ctx);
  1264. /* pictype : number of B */
  1265. reg = readl(mfc_regs->e_gop_config);
  1266. /* num_b_frame - 0 ~ 2 */
  1267. reg &= ~(0x3 << 16);
  1268. reg |= (p->num_b_frame << 16);
  1269. writel(reg, mfc_regs->e_gop_config);
  1270. /* UHD encoding case */
  1271. if ((ctx->img_width == 3840) && (ctx->img_height == 2160)) {
  1272. p_hevc->level = 51;
  1273. p_hevc->tier = 0;
  1274. /* this tier can be changed */
  1275. }
  1276. /* tier & level */
  1277. reg = 0;
  1278. /* profile */
  1279. reg |= p_hevc->profile & 0x3;
  1280. /* level */
  1281. reg &= ~(0xFF << 8);
  1282. reg |= (p_hevc->level << 8);
  1283. /* tier - 0 ~ 1 */
  1284. reg |= (p_hevc->tier << 16);
  1285. writel(reg, mfc_regs->e_picture_profile);
  1286. switch (p_hevc->loopfilter) {
  1287. case V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED:
  1288. p_hevc->loopfilter_disable = 1;
  1289. break;
  1290. case V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_ENABLED:
  1291. p_hevc->loopfilter_disable = 0;
  1292. p_hevc->loopfilter_across = 1;
  1293. break;
  1294. case V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY:
  1295. p_hevc->loopfilter_disable = 0;
  1296. p_hevc->loopfilter_across = 0;
  1297. break;
  1298. }
  1299. /* max partition depth */
  1300. reg = 0;
  1301. reg |= (p_hevc->max_partition_depth & 0x1);
  1302. reg |= (p_hevc->num_refs_for_p-1) << 2;
  1303. reg |= (p_hevc->refreshtype & 0x3) << 3;
  1304. reg |= (p_hevc->const_intra_period_enable & 0x1) << 5;
  1305. reg |= (p_hevc->lossless_cu_enable & 0x1) << 6;
  1306. reg |= (p_hevc->wavefront_enable & 0x1) << 7;
  1307. reg |= (p_hevc->loopfilter_disable & 0x1) << 8;
  1308. reg |= (p_hevc->loopfilter_across & 0x1) << 9;
  1309. reg |= (p_hevc->enable_ltr & 0x1) << 10;
  1310. reg |= (p_hevc->hier_qp_enable & 0x1) << 11;
  1311. reg |= (p_hevc->general_pb_enable & 0x1) << 13;
  1312. reg |= (p_hevc->temporal_id_enable & 0x1) << 14;
  1313. reg |= (p_hevc->strong_intra_smooth & 0x1) << 15;
  1314. reg |= (p_hevc->intra_pu_split_disable & 0x1) << 16;
  1315. reg |= (p_hevc->tmv_prediction_disable & 0x1) << 17;
  1316. reg |= (p_hevc->max_num_merge_mv & 0x7) << 18;
  1317. reg |= (p_hevc->encoding_nostartcode_enable & 0x1) << 23;
  1318. reg |= (p_hevc->prepend_sps_pps_to_idr << 26);
  1319. writel(reg, mfc_regs->e_hevc_options);
  1320. /* refresh period */
  1321. if (p_hevc->refreshtype) {
  1322. reg = 0;
  1323. reg |= (p_hevc->refreshperiod & 0xFFFF);
  1324. writel(reg, mfc_regs->e_hevc_refresh_period);
  1325. }
  1326. /* loop filter setting */
  1327. if (!(p_hevc->loopfilter_disable & 0x1)) {
  1328. reg = 0;
  1329. reg |= (p_hevc->lf_beta_offset_div2);
  1330. writel(reg, mfc_regs->e_hevc_lf_beta_offset_div2);
  1331. reg = 0;
  1332. reg |= (p_hevc->lf_tc_offset_div2);
  1333. writel(reg, mfc_regs->e_hevc_lf_tc_offset_div2);
  1334. }
  1335. /* hier qp enable */
  1336. if (p_hevc->num_hier_layer) {
  1337. reg = 0;
  1338. reg |= (p_hevc->hier_qp_type & 0x1) << 0x3;
  1339. reg |= p_hevc->num_hier_layer & 0x7;
  1340. writel(reg, mfc_regs->e_num_t_layer);
  1341. /* QP value for each layer */
  1342. if (p_hevc->hier_qp_enable) {
  1343. for (i = 0; i < 7; i++)
  1344. writel(p_hevc->hier_qp_layer[i],
  1345. mfc_regs->e_hier_qp_layer0 + i * 4);
  1346. }
  1347. if (p->rc_frame) {
  1348. for (i = 0; i < 7; i++)
  1349. writel(p_hevc->hier_bit_layer[i],
  1350. mfc_regs->e_hier_bit_rate_layer0
  1351. + i * 4);
  1352. }
  1353. }
  1354. /* rate control config. */
  1355. reg = readl(mfc_regs->e_rc_config);
  1356. /* macroblock level rate control */
  1357. reg &= ~(0x1 << 8);
  1358. reg |= (p->rc_mb << 8);
  1359. writel(reg, mfc_regs->e_rc_config);
  1360. /* frame QP */
  1361. reg &= ~(0xFF);
  1362. reg |= p_hevc->rc_frame_qp;
  1363. writel(reg, mfc_regs->e_rc_config);
  1364. /* frame rate */
  1365. if (p->rc_frame) {
  1366. reg = 0;
  1367. reg &= ~(0xFFFF << 16);
  1368. reg |= ((p_hevc->rc_framerate) << 16);
  1369. reg &= ~(0xFFFF);
  1370. reg |= FRAME_DELTA_DEFAULT;
  1371. writel(reg, mfc_regs->e_rc_frame_rate);
  1372. }
  1373. /* max & min value of QP */
  1374. reg = 0;
  1375. /* max QP */
  1376. reg &= ~(0xFF << 8);
  1377. reg |= (p_hevc->rc_max_qp << 8);
  1378. /* min QP */
  1379. reg &= ~(0xFF);
  1380. reg |= p_hevc->rc_min_qp;
  1381. writel(reg, mfc_regs->e_rc_qp_bound);
  1382. writel(0x0, mfc_regs->e_fixed_picture_qp);
  1383. if (!p->rc_frame && !p->rc_mb) {
  1384. reg = 0;
  1385. reg &= ~(0xFF << 16);
  1386. reg |= (p_hevc->rc_b_frame_qp << 16);
  1387. reg &= ~(0xFF << 8);
  1388. reg |= (p_hevc->rc_p_frame_qp << 8);
  1389. reg &= ~(0xFF);
  1390. reg |= p_hevc->rc_frame_qp;
  1391. writel(reg, mfc_regs->e_fixed_picture_qp);
  1392. }
  1393. mfc_debug_leave();
  1394. return 0;
  1395. }
  1396. /* Initialize decoding */
  1397. static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
  1398. {
  1399. struct s5p_mfc_dev *dev = ctx->dev;
  1400. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1401. unsigned int reg = 0;
  1402. int fmo_aso_ctrl = 0;
  1403. mfc_debug_enter();
  1404. mfc_debug(2, "InstNo: %d/%d\n", ctx->inst_no,
  1405. S5P_FIMV_CH_SEQ_HEADER_V6);
  1406. mfc_debug(2, "BUFs: %08x %08x %08x\n",
  1407. readl(mfc_regs->d_cpb_buffer_addr),
  1408. readl(mfc_regs->d_cpb_buffer_addr),
  1409. readl(mfc_regs->d_cpb_buffer_addr));
  1410. /* FMO_ASO_CTRL - 0: Enable, 1: Disable */
  1411. reg |= (fmo_aso_ctrl << S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6);
  1412. if (ctx->display_delay_enable) {
  1413. reg |= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6);
  1414. writel(ctx->display_delay, mfc_regs->d_display_delay);
  1415. }
  1416. if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev)) {
  1417. writel(reg, mfc_regs->d_dec_options);
  1418. reg = 0;
  1419. }
  1420. /* Setup loop filter, for decoding this is only valid for MPEG4 */
  1421. if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC) {
  1422. mfc_debug(2, "Set loop filter to: %d\n",
  1423. ctx->loop_filter_mpeg4);
  1424. reg |= (ctx->loop_filter_mpeg4 <<
  1425. S5P_FIMV_D_OPT_LF_CTRL_SHIFT_V6);
  1426. }
  1427. if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
  1428. reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
  1429. if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev))
  1430. writel(reg, mfc_regs->d_init_buffer_options);
  1431. else
  1432. writel(reg, mfc_regs->d_dec_options);
  1433. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  1434. if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV21M)
  1435. writel(0x1, mfc_regs->pixel_format);
  1436. else
  1437. writel(0x0, mfc_regs->pixel_format);
  1438. /* sei parse */
  1439. writel(ctx->sei_fp_parse & 0x1, mfc_regs->d_sei_enable);
  1440. writel(ctx->inst_no, mfc_regs->instance_id);
  1441. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1442. S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
  1443. mfc_debug_leave();
  1444. return 0;
  1445. }
  1446. static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
  1447. {
  1448. struct s5p_mfc_dev *dev = ctx->dev;
  1449. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1450. if (flush) {
  1451. dev->curr_ctx = ctx->num;
  1452. writel(ctx->inst_no, mfc_regs->instance_id);
  1453. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1454. S5P_FIMV_H2R_CMD_FLUSH_V6, NULL);
  1455. }
  1456. }
  1457. /* Decode a single frame */
  1458. static int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
  1459. enum s5p_mfc_decode_arg last_frame)
  1460. {
  1461. struct s5p_mfc_dev *dev = ctx->dev;
  1462. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1463. writel(ctx->dec_dst_flag, mfc_regs->d_available_dpb_flag_lower);
  1464. writel(ctx->slice_interface & 0x1, mfc_regs->d_slice_if_enable);
  1465. writel(ctx->inst_no, mfc_regs->instance_id);
  1466. /* Issue different commands to instance basing on whether it
  1467. * is the last frame or not. */
  1468. switch (last_frame) {
  1469. case 0:
  1470. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1471. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1472. break;
  1473. case 1:
  1474. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1475. S5P_FIMV_CH_LAST_FRAME_V6, NULL);
  1476. break;
  1477. default:
  1478. mfc_err("Unsupported last frame arg.\n");
  1479. return -EINVAL;
  1480. }
  1481. mfc_debug(2, "Decoding a usual frame.\n");
  1482. return 0;
  1483. }
  1484. static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
  1485. {
  1486. struct s5p_mfc_dev *dev = ctx->dev;
  1487. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1488. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1489. s5p_mfc_set_enc_params_h264(ctx);
  1490. else if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_ENC)
  1491. s5p_mfc_set_enc_params_mpeg4(ctx);
  1492. else if (ctx->codec_mode == S5P_MFC_CODEC_H263_ENC)
  1493. s5p_mfc_set_enc_params_h263(ctx);
  1494. else if (ctx->codec_mode == S5P_MFC_CODEC_VP8_ENC)
  1495. s5p_mfc_set_enc_params_vp8(ctx);
  1496. else if (ctx->codec_mode == S5P_FIMV_CODEC_HEVC_ENC)
  1497. s5p_mfc_set_enc_params_hevc(ctx);
  1498. else {
  1499. mfc_err("Unknown codec for encoding (%x).\n",
  1500. ctx->codec_mode);
  1501. return -EINVAL;
  1502. }
  1503. /* Set stride lengths for v7 & above */
  1504. if (IS_MFCV7_PLUS(dev)) {
  1505. writel(ctx->img_width, mfc_regs->e_source_first_plane_stride);
  1506. writel(ctx->img_width, mfc_regs->e_source_second_plane_stride);
  1507. }
  1508. writel(ctx->inst_no, mfc_regs->instance_id);
  1509. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1510. S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
  1511. return 0;
  1512. }
  1513. static int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
  1514. {
  1515. struct s5p_mfc_dev *dev = ctx->dev;
  1516. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1517. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1518. struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
  1519. int i;
  1520. if (p_h264->aso) {
  1521. for (i = 0; i < ARRAY_SIZE(p_h264->aso_slice_order); i++) {
  1522. writel(p_h264->aso_slice_order[i],
  1523. mfc_regs->e_h264_aso_slice_order_0 + i * 4);
  1524. }
  1525. }
  1526. return 0;
  1527. }
  1528. /* Encode a single frame */
  1529. static int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx)
  1530. {
  1531. struct s5p_mfc_dev *dev = ctx->dev;
  1532. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1533. int cmd;
  1534. mfc_debug(2, "++\n");
  1535. /* memory structure cur. frame */
  1536. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1537. s5p_mfc_h264_set_aso_slice_order_v6(ctx);
  1538. s5p_mfc_set_slice_mode(ctx);
  1539. if (ctx->state != MFCINST_FINISHING)
  1540. cmd = S5P_FIMV_CH_FRAME_START_V6;
  1541. else
  1542. cmd = S5P_FIMV_CH_LAST_FRAME_V6;
  1543. writel(ctx->inst_no, mfc_regs->instance_id);
  1544. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev, cmd, NULL);
  1545. mfc_debug(2, "--\n");
  1546. return 0;
  1547. }
  1548. static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
  1549. {
  1550. struct s5p_mfc_dev *dev = ctx->dev;
  1551. s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
  1552. dev->curr_ctx = ctx->num;
  1553. s5p_mfc_decode_one_frame_v6(ctx, MFC_DEC_LAST_FRAME);
  1554. }
  1555. static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
  1556. {
  1557. struct s5p_mfc_dev *dev = ctx->dev;
  1558. struct s5p_mfc_buf *temp_vb;
  1559. int last_frame = 0;
  1560. if (ctx->state == MFCINST_FINISHING) {
  1561. last_frame = MFC_DEC_LAST_FRAME;
  1562. s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
  1563. dev->curr_ctx = ctx->num;
  1564. s5p_mfc_clean_ctx_int_flags(ctx);
  1565. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1566. return 0;
  1567. }
  1568. /* Frames are being decoded */
  1569. if (list_empty(&ctx->src_queue)) {
  1570. mfc_debug(2, "No src buffers.\n");
  1571. return -EAGAIN;
  1572. }
  1573. /* Get the next source buffer */
  1574. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1575. temp_vb->flags |= MFC_BUF_FLAG_USED;
  1576. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1577. vb2_dma_contig_plane_dma_addr(&temp_vb->b->vb2_buf, 0),
  1578. ctx->consumed_stream,
  1579. temp_vb->b->vb2_buf.planes[0].bytesused);
  1580. dev->curr_ctx = ctx->num;
  1581. if (temp_vb->b->vb2_buf.planes[0].bytesused == 0) {
  1582. last_frame = 1;
  1583. mfc_debug(2, "Setting ctx->state to FINISHING\n");
  1584. ctx->state = MFCINST_FINISHING;
  1585. }
  1586. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1587. return 0;
  1588. }
  1589. static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
  1590. {
  1591. struct s5p_mfc_dev *dev = ctx->dev;
  1592. struct s5p_mfc_buf *dst_mb;
  1593. struct s5p_mfc_buf *src_mb;
  1594. unsigned long src_y_addr, src_c_addr, dst_addr;
  1595. /*
  1596. unsigned int src_y_size, src_c_size;
  1597. */
  1598. unsigned int dst_size;
  1599. if (list_empty(&ctx->src_queue) && ctx->state != MFCINST_FINISHING) {
  1600. mfc_debug(2, "no src buffers.\n");
  1601. return -EAGAIN;
  1602. }
  1603. if (list_empty(&ctx->dst_queue)) {
  1604. mfc_debug(2, "no dst buffers.\n");
  1605. return -EAGAIN;
  1606. }
  1607. if (list_empty(&ctx->src_queue)) {
  1608. /* send null frame */
  1609. s5p_mfc_set_enc_frame_buffer_v6(ctx, 0, 0);
  1610. src_mb = NULL;
  1611. } else {
  1612. src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1613. src_mb->flags |= MFC_BUF_FLAG_USED;
  1614. if (src_mb->b->vb2_buf.planes[0].bytesused == 0) {
  1615. s5p_mfc_set_enc_frame_buffer_v6(ctx, 0, 0);
  1616. ctx->state = MFCINST_FINISHING;
  1617. } else {
  1618. src_y_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 0);
  1619. src_c_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 1);
  1620. mfc_debug(2, "enc src y addr: 0x%08lx\n", src_y_addr);
  1621. mfc_debug(2, "enc src c addr: 0x%08lx\n", src_c_addr);
  1622. s5p_mfc_set_enc_frame_buffer_v6(ctx, src_y_addr, src_c_addr);
  1623. if (src_mb->flags & MFC_BUF_FLAG_EOS)
  1624. ctx->state = MFCINST_FINISHING;
  1625. }
  1626. }
  1627. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1628. dst_mb->flags |= MFC_BUF_FLAG_USED;
  1629. dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
  1630. dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
  1631. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1632. dev->curr_ctx = ctx->num;
  1633. s5p_mfc_encode_one_frame_v6(ctx);
  1634. return 0;
  1635. }
  1636. static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
  1637. {
  1638. struct s5p_mfc_dev *dev = ctx->dev;
  1639. struct s5p_mfc_buf *temp_vb;
  1640. /* Initializing decoding - parsing header */
  1641. mfc_debug(2, "Preparing to init decoding.\n");
  1642. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1643. mfc_debug(2, "Header size: %d\n", temp_vb->b->vb2_buf.planes[0].bytesused);
  1644. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1645. vb2_dma_contig_plane_dma_addr(&temp_vb->b->vb2_buf, 0), 0,
  1646. temp_vb->b->vb2_buf.planes[0].bytesused);
  1647. dev->curr_ctx = ctx->num;
  1648. s5p_mfc_init_decode_v6(ctx);
  1649. }
  1650. static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
  1651. {
  1652. struct s5p_mfc_dev *dev = ctx->dev;
  1653. struct s5p_mfc_buf *dst_mb;
  1654. unsigned long dst_addr;
  1655. unsigned int dst_size;
  1656. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1657. dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
  1658. dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
  1659. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1660. dev->curr_ctx = ctx->num;
  1661. s5p_mfc_init_encode_v6(ctx);
  1662. }
  1663. static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
  1664. {
  1665. struct s5p_mfc_dev *dev = ctx->dev;
  1666. int ret;
  1667. /* Header was parsed now start processing
  1668. * First set the output frame buffers
  1669. * s5p_mfc_alloc_dec_buffers(ctx); */
  1670. if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
  1671. mfc_err("It seems that not all destination buffers were\n"
  1672. "mmaped.MFC requires that all destination are mmaped\n"
  1673. "before starting processing.\n");
  1674. return -EAGAIN;
  1675. }
  1676. dev->curr_ctx = ctx->num;
  1677. ret = s5p_mfc_set_dec_frame_buffer_v6(ctx);
  1678. if (ret) {
  1679. mfc_err("Failed to alloc frame mem.\n");
  1680. ctx->state = MFCINST_ERROR;
  1681. }
  1682. return ret;
  1683. }
  1684. static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
  1685. {
  1686. struct s5p_mfc_dev *dev = ctx->dev;
  1687. int ret;
  1688. dev->curr_ctx = ctx->num;
  1689. ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
  1690. if (ret) {
  1691. mfc_err("Failed to alloc frame mem.\n");
  1692. ctx->state = MFCINST_ERROR;
  1693. }
  1694. return ret;
  1695. }
  1696. /* Try running an operation on hardware */
  1697. static void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
  1698. {
  1699. struct s5p_mfc_ctx *ctx;
  1700. int new_ctx;
  1701. unsigned int ret = 0;
  1702. mfc_debug(1, "Try run dev: %p\n", dev);
  1703. /* Check whether hardware is not running */
  1704. if (test_and_set_bit(0, &dev->hw_lock) != 0) {
  1705. /* This is perfectly ok, the scheduled ctx should wait */
  1706. mfc_debug(1, "Couldn't lock HW.\n");
  1707. return;
  1708. }
  1709. /* Choose the context to run */
  1710. new_ctx = s5p_mfc_get_new_ctx(dev);
  1711. if (new_ctx < 0) {
  1712. /* No contexts to run */
  1713. if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
  1714. mfc_err("Failed to unlock hardware.\n");
  1715. return;
  1716. }
  1717. mfc_debug(1, "No ctx is scheduled to be run.\n");
  1718. return;
  1719. }
  1720. mfc_debug(1, "New context: %d\n", new_ctx);
  1721. ctx = dev->ctx[new_ctx];
  1722. mfc_debug(1, "Setting new context to %p\n", ctx);
  1723. /* Got context to run in ctx */
  1724. mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
  1725. ctx->dst_queue_cnt, ctx->pb_count, ctx->src_queue_cnt);
  1726. mfc_debug(1, "ctx->state=%d\n", ctx->state);
  1727. /* Last frame has already been sent to MFC
  1728. * Now obtaining frames from MFC buffer */
  1729. s5p_mfc_clock_on();
  1730. s5p_mfc_clean_ctx_int_flags(ctx);
  1731. if (ctx->type == MFCINST_DECODER) {
  1732. switch (ctx->state) {
  1733. case MFCINST_FINISHING:
  1734. s5p_mfc_run_dec_last_frames(ctx);
  1735. break;
  1736. case MFCINST_RUNNING:
  1737. ret = s5p_mfc_run_dec_frame(ctx);
  1738. break;
  1739. case MFCINST_INIT:
  1740. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1741. ctx);
  1742. break;
  1743. case MFCINST_RETURN_INST:
  1744. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1745. ctx);
  1746. break;
  1747. case MFCINST_GOT_INST:
  1748. s5p_mfc_run_init_dec(ctx);
  1749. break;
  1750. case MFCINST_HEAD_PARSED:
  1751. ret = s5p_mfc_run_init_dec_buffers(ctx);
  1752. break;
  1753. case MFCINST_FLUSH:
  1754. s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
  1755. break;
  1756. case MFCINST_RES_CHANGE_INIT:
  1757. s5p_mfc_run_dec_last_frames(ctx);
  1758. break;
  1759. case MFCINST_RES_CHANGE_FLUSH:
  1760. s5p_mfc_run_dec_last_frames(ctx);
  1761. break;
  1762. case MFCINST_RES_CHANGE_END:
  1763. mfc_debug(2, "Finished remaining frames after resolution change.\n");
  1764. ctx->capture_state = QUEUE_FREE;
  1765. mfc_debug(2, "Will re-init the codec`.\n");
  1766. s5p_mfc_run_init_dec(ctx);
  1767. break;
  1768. default:
  1769. ret = -EAGAIN;
  1770. }
  1771. } else if (ctx->type == MFCINST_ENCODER) {
  1772. switch (ctx->state) {
  1773. case MFCINST_FINISHING:
  1774. case MFCINST_RUNNING:
  1775. ret = s5p_mfc_run_enc_frame(ctx);
  1776. break;
  1777. case MFCINST_INIT:
  1778. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1779. ctx);
  1780. break;
  1781. case MFCINST_RETURN_INST:
  1782. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1783. ctx);
  1784. break;
  1785. case MFCINST_GOT_INST:
  1786. s5p_mfc_run_init_enc(ctx);
  1787. break;
  1788. case MFCINST_HEAD_PRODUCED:
  1789. ret = s5p_mfc_run_init_enc_buffers(ctx);
  1790. break;
  1791. default:
  1792. ret = -EAGAIN;
  1793. }
  1794. } else {
  1795. mfc_err("invalid context type: %d\n", ctx->type);
  1796. ret = -EAGAIN;
  1797. }
  1798. if (ret) {
  1799. /* Free hardware lock */
  1800. if (test_and_clear_bit(0, &dev->hw_lock) == 0)
  1801. mfc_err("Failed to unlock hardware.\n");
  1802. /* This is in deed imporant, as no operation has been
  1803. * scheduled, reduce the clock count as no one will
  1804. * ever do this, because no interrupt related to this try_run
  1805. * will ever come from hardware. */
  1806. s5p_mfc_clock_off();
  1807. }
  1808. }
  1809. static void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev)
  1810. {
  1811. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1812. writel(0, mfc_regs->risc2host_command);
  1813. writel(0, mfc_regs->risc2host_int);
  1814. }
  1815. static unsigned int
  1816. s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned long ofs)
  1817. {
  1818. int ret;
  1819. s5p_mfc_clock_on();
  1820. ret = readl((void __iomem *)ofs);
  1821. s5p_mfc_clock_off();
  1822. return ret;
  1823. }
  1824. static int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev)
  1825. {
  1826. return readl(dev->mfc_regs->d_display_first_plane_addr);
  1827. }
  1828. static int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev)
  1829. {
  1830. return readl(dev->mfc_regs->d_decoded_first_plane_addr);
  1831. }
  1832. static int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev)
  1833. {
  1834. return readl(dev->mfc_regs->d_display_status);
  1835. }
  1836. static int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev)
  1837. {
  1838. return readl(dev->mfc_regs->d_decoded_status);
  1839. }
  1840. static int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev)
  1841. {
  1842. return readl(dev->mfc_regs->d_decoded_frame_type) &
  1843. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1844. }
  1845. static int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx)
  1846. {
  1847. struct s5p_mfc_dev *dev = ctx->dev;
  1848. return readl(dev->mfc_regs->d_display_frame_type) &
  1849. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1850. }
  1851. static int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev)
  1852. {
  1853. return readl(dev->mfc_regs->d_decoded_nal_size);
  1854. }
  1855. static int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev)
  1856. {
  1857. return readl(dev->mfc_regs->risc2host_command) &
  1858. S5P_FIMV_RISC2HOST_CMD_MASK;
  1859. }
  1860. static int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev)
  1861. {
  1862. return readl(dev->mfc_regs->error_code);
  1863. }
  1864. static int s5p_mfc_err_dec_v6(unsigned int err)
  1865. {
  1866. return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6;
  1867. }
  1868. static int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev)
  1869. {
  1870. return readl(dev->mfc_regs->d_display_frame_width);
  1871. }
  1872. static int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev)
  1873. {
  1874. return readl(dev->mfc_regs->d_display_frame_height);
  1875. }
  1876. static int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev)
  1877. {
  1878. return readl(dev->mfc_regs->d_min_num_dpb);
  1879. }
  1880. static int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev)
  1881. {
  1882. return readl(dev->mfc_regs->d_min_num_mv);
  1883. }
  1884. static int s5p_mfc_get_min_scratch_buf_size(struct s5p_mfc_dev *dev)
  1885. {
  1886. return readl(dev->mfc_regs->d_min_scratch_buffer_size);
  1887. }
  1888. static int s5p_mfc_get_e_min_scratch_buf_size(struct s5p_mfc_dev *dev)
  1889. {
  1890. return readl(dev->mfc_regs->e_min_scratch_buffer_size);
  1891. }
  1892. static int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev)
  1893. {
  1894. return readl(dev->mfc_regs->ret_instance_id);
  1895. }
  1896. static int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev)
  1897. {
  1898. return readl(dev->mfc_regs->e_num_dpb);
  1899. }
  1900. static int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev)
  1901. {
  1902. return readl(dev->mfc_regs->e_stream_size);
  1903. }
  1904. static int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev)
  1905. {
  1906. return readl(dev->mfc_regs->e_slice_type);
  1907. }
  1908. static unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx)
  1909. {
  1910. return s5p_mfc_read_info_v6(ctx,
  1911. (__force unsigned long) ctx->dev->mfc_regs->d_ret_picture_tag_top);
  1912. }
  1913. static unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx)
  1914. {
  1915. return s5p_mfc_read_info_v6(ctx,
  1916. (__force unsigned long) ctx->dev->mfc_regs->d_ret_picture_tag_bot);
  1917. }
  1918. static unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx)
  1919. {
  1920. return s5p_mfc_read_info_v6(ctx,
  1921. (__force unsigned long) ctx->dev->mfc_regs->d_display_crop_info1);
  1922. }
  1923. static unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx)
  1924. {
  1925. return s5p_mfc_read_info_v6(ctx,
  1926. (__force unsigned long) ctx->dev->mfc_regs->d_display_crop_info2);
  1927. }
  1928. static struct s5p_mfc_regs mfc_regs;
  1929. /* Initialize registers for MFC v6 onwards */
  1930. const struct s5p_mfc_regs *s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev)
  1931. {
  1932. memset(&mfc_regs, 0, sizeof(mfc_regs));
  1933. #define S5P_MFC_REG_ADDR(dev, reg) ((dev)->regs_base + (reg))
  1934. #define R(m, r) mfc_regs.m = S5P_MFC_REG_ADDR(dev, r)
  1935. /* codec common registers */
  1936. R(risc_on, S5P_FIMV_RISC_ON_V6);
  1937. R(risc2host_int, S5P_FIMV_RISC2HOST_INT_V6);
  1938. R(host2risc_int, S5P_FIMV_HOST2RISC_INT_V6);
  1939. R(risc_base_address, S5P_FIMV_RISC_BASE_ADDRESS_V6);
  1940. R(mfc_reset, S5P_FIMV_MFC_RESET_V6);
  1941. R(host2risc_command, S5P_FIMV_HOST2RISC_CMD_V6);
  1942. R(risc2host_command, S5P_FIMV_RISC2HOST_CMD_V6);
  1943. R(firmware_version, S5P_FIMV_FW_VERSION_V6);
  1944. R(instance_id, S5P_FIMV_INSTANCE_ID_V6);
  1945. R(codec_type, S5P_FIMV_CODEC_TYPE_V6);
  1946. R(context_mem_addr, S5P_FIMV_CONTEXT_MEM_ADDR_V6);
  1947. R(context_mem_size, S5P_FIMV_CONTEXT_MEM_SIZE_V6);
  1948. R(pixel_format, S5P_FIMV_PIXEL_FORMAT_V6);
  1949. R(ret_instance_id, S5P_FIMV_RET_INSTANCE_ID_V6);
  1950. R(error_code, S5P_FIMV_ERROR_CODE_V6);
  1951. /* decoder registers */
  1952. R(d_crc_ctrl, S5P_FIMV_D_CRC_CTRL_V6);
  1953. R(d_dec_options, S5P_FIMV_D_DEC_OPTIONS_V6);
  1954. R(d_display_delay, S5P_FIMV_D_DISPLAY_DELAY_V6);
  1955. R(d_sei_enable, S5P_FIMV_D_SEI_ENABLE_V6);
  1956. R(d_min_num_dpb, S5P_FIMV_D_MIN_NUM_DPB_V6);
  1957. R(d_min_num_mv, S5P_FIMV_D_MIN_NUM_MV_V6);
  1958. R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V6);
  1959. R(d_num_dpb, S5P_FIMV_D_NUM_DPB_V6);
  1960. R(d_num_mv, S5P_FIMV_D_NUM_MV_V6);
  1961. R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6);
  1962. R(d_first_plane_dpb_size, S5P_FIMV_D_LUMA_DPB_SIZE_V6);
  1963. R(d_second_plane_dpb_size, S5P_FIMV_D_CHROMA_DPB_SIZE_V6);
  1964. R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V6);
  1965. R(d_first_plane_dpb, S5P_FIMV_D_LUMA_DPB_V6);
  1966. R(d_second_plane_dpb, S5P_FIMV_D_CHROMA_DPB_V6);
  1967. R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V6);
  1968. R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V6);
  1969. R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V6);
  1970. R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V6);
  1971. R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V6);
  1972. R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6);
  1973. R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V6);
  1974. R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V6);
  1975. R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V6);
  1976. R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6);
  1977. R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6);
  1978. R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V6);
  1979. R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6);
  1980. R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_CHROMA_ADDR_V6);
  1981. R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6);
  1982. R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V6);
  1983. R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V6);
  1984. R(d_display_aspect_ratio, S5P_FIMV_D_DISPLAY_ASPECT_RATIO_V6);
  1985. R(d_display_extended_ar, S5P_FIMV_D_DISPLAY_EXTENDED_AR_V6);
  1986. R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V6);
  1987. R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_LUMA_ADDR_V6);
  1988. R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_CHROMA_ADDR_V6);
  1989. R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V6);
  1990. R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V6);
  1991. R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V6);
  1992. R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V6);
  1993. R(d_h264_info, S5P_FIMV_D_H264_INFO_V6);
  1994. R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V6);
  1995. R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6);
  1996. /* encoder registers */
  1997. R(e_frame_width, S5P_FIMV_E_FRAME_WIDTH_V6);
  1998. R(e_frame_height, S5P_FIMV_E_FRAME_HEIGHT_V6);
  1999. R(e_cropped_frame_width, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6);
  2000. R(e_cropped_frame_height, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
  2001. R(e_frame_crop_offset, S5P_FIMV_E_FRAME_CROP_OFFSET_V6);
  2002. R(e_enc_options, S5P_FIMV_E_ENC_OPTIONS_V6);
  2003. R(e_picture_profile, S5P_FIMV_E_PICTURE_PROFILE_V6);
  2004. R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
  2005. R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
  2006. R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  2007. R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V6);
  2008. R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V6);
  2009. R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V6);
  2010. R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V6);
  2011. R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V6);
  2012. R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V6);
  2013. R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V6);
  2014. R(e_num_dpb, S5P_FIMV_E_NUM_DPB_V6);
  2015. R(e_luma_dpb, S5P_FIMV_E_LUMA_DPB_V6);
  2016. R(e_chroma_dpb, S5P_FIMV_E_CHROMA_DPB_V6);
  2017. R(e_me_buffer, S5P_FIMV_E_ME_BUFFER_V6);
  2018. R(e_scratch_buffer_addr, S5P_FIMV_E_SCRATCH_BUFFER_ADDR_V6);
  2019. R(e_scratch_buffer_size, S5P_FIMV_E_SCRATCH_BUFFER_SIZE_V6);
  2020. R(e_tmv_buffer0, S5P_FIMV_E_TMV_BUFFER0_V6);
  2021. R(e_tmv_buffer1, S5P_FIMV_E_TMV_BUFFER1_V6);
  2022. R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6);
  2023. R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6);
  2024. R(e_stream_buffer_addr, S5P_FIMV_E_STREAM_BUFFER_ADDR_V6);
  2025. R(e_stream_buffer_size, S5P_FIMV_E_STREAM_BUFFER_SIZE_V6);
  2026. R(e_roi_buffer_addr, S5P_FIMV_E_ROI_BUFFER_ADDR_V6);
  2027. R(e_param_change, S5P_FIMV_E_PARAM_CHANGE_V6);
  2028. R(e_ir_size, S5P_FIMV_E_IR_SIZE_V6);
  2029. R(e_gop_config, S5P_FIMV_E_GOP_CONFIG_V6);
  2030. R(e_mslice_mode, S5P_FIMV_E_MSLICE_MODE_V6);
  2031. R(e_mslice_size_mb, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
  2032. R(e_mslice_size_bits, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
  2033. R(e_frame_insertion, S5P_FIMV_E_FRAME_INSERTION_V6);
  2034. R(e_rc_frame_rate, S5P_FIMV_E_RC_FRAME_RATE_V6);
  2035. R(e_rc_bit_rate, S5P_FIMV_E_RC_BIT_RATE_V6);
  2036. R(e_rc_roi_ctrl, S5P_FIMV_E_RC_ROI_CTRL_V6);
  2037. R(e_picture_tag, S5P_FIMV_E_PICTURE_TAG_V6);
  2038. R(e_bit_count_enable, S5P_FIMV_E_BIT_COUNT_ENABLE_V6);
  2039. R(e_max_bit_count, S5P_FIMV_E_MAX_BIT_COUNT_V6);
  2040. R(e_min_bit_count, S5P_FIMV_E_MIN_BIT_COUNT_V6);
  2041. R(e_metadata_buffer_addr, S5P_FIMV_E_METADATA_BUFFER_ADDR_V6);
  2042. R(e_metadata_buffer_size, S5P_FIMV_E_METADATA_BUFFER_SIZE_V6);
  2043. R(e_encoded_source_first_plane_addr,
  2044. S5P_FIMV_E_ENCODED_SOURCE_LUMA_ADDR_V6);
  2045. R(e_encoded_source_second_plane_addr,
  2046. S5P_FIMV_E_ENCODED_SOURCE_CHROMA_ADDR_V6);
  2047. R(e_stream_size, S5P_FIMV_E_STREAM_SIZE_V6);
  2048. R(e_slice_type, S5P_FIMV_E_SLICE_TYPE_V6);
  2049. R(e_picture_count, S5P_FIMV_E_PICTURE_COUNT_V6);
  2050. R(e_ret_picture_tag, S5P_FIMV_E_RET_PICTURE_TAG_V6);
  2051. R(e_recon_luma_dpb_addr, S5P_FIMV_E_RECON_LUMA_DPB_ADDR_V6);
  2052. R(e_recon_chroma_dpb_addr, S5P_FIMV_E_RECON_CHROMA_DPB_ADDR_V6);
  2053. R(e_mpeg4_options, S5P_FIMV_E_MPEG4_OPTIONS_V6);
  2054. R(e_mpeg4_hec_period, S5P_FIMV_E_MPEG4_HEC_PERIOD_V6);
  2055. R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V6);
  2056. R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V6);
  2057. R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V6);
  2058. R(e_h264_lf_alpha_offset, S5P_FIMV_E_H264_LF_ALPHA_OFFSET_V6);
  2059. R(e_h264_lf_beta_offset, S5P_FIMV_E_H264_LF_BETA_OFFSET_V6);
  2060. R(e_h264_i_period, S5P_FIMV_E_H264_I_PERIOD_V6);
  2061. R(e_h264_fmo_slice_grp_map_type,
  2062. S5P_FIMV_E_H264_FMO_SLICE_GRP_MAP_TYPE_V6);
  2063. R(e_h264_fmo_num_slice_grp_minus1,
  2064. S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
  2065. R(e_h264_fmo_slice_grp_change_dir,
  2066. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_DIR_V6);
  2067. R(e_h264_fmo_slice_grp_change_rate_minus1,
  2068. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_RATE_MINUS1_V6);
  2069. R(e_h264_fmo_run_length_minus1_0,
  2070. S5P_FIMV_E_H264_FMO_RUN_LENGTH_MINUS1_0_V6);
  2071. R(e_h264_aso_slice_order_0, S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6);
  2072. R(e_h264_num_t_layer, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
  2073. R(e_h264_hierarchical_qp_layer0,
  2074. S5P_FIMV_E_H264_HIERARCHICAL_QP_LAYER0_V6);
  2075. R(e_h264_frame_packing_sei_info,
  2076. S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
  2077. if (!IS_MFCV7_PLUS(dev))
  2078. goto done;
  2079. /* Initialize registers used in MFC v7+ */
  2080. R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_FIRST_ADDR_V7);
  2081. R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_SECOND_ADDR_V7);
  2082. R(e_source_third_plane_addr, S5P_FIMV_E_SOURCE_THIRD_ADDR_V7);
  2083. R(e_source_first_plane_stride, S5P_FIMV_E_SOURCE_FIRST_STRIDE_V7);
  2084. R(e_source_second_plane_stride, S5P_FIMV_E_SOURCE_SECOND_STRIDE_V7);
  2085. R(e_source_third_plane_stride, S5P_FIMV_E_SOURCE_THIRD_STRIDE_V7);
  2086. R(e_encoded_source_first_plane_addr,
  2087. S5P_FIMV_E_ENCODED_SOURCE_FIRST_ADDR_V7);
  2088. R(e_encoded_source_second_plane_addr,
  2089. S5P_FIMV_E_ENCODED_SOURCE_SECOND_ADDR_V7);
  2090. R(e_vp8_options, S5P_FIMV_E_VP8_OPTIONS_V7);
  2091. if (!IS_MFCV8_PLUS(dev))
  2092. goto done;
  2093. /* Initialize registers used in MFC v8 only.
  2094. * Also, over-write the registers which have
  2095. * a different offset for MFC v8. */
  2096. R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V8);
  2097. R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V8);
  2098. R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V8);
  2099. R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V8);
  2100. R(d_first_plane_dpb_size, S5P_FIMV_D_FIRST_PLANE_DPB_SIZE_V8);
  2101. R(d_second_plane_dpb_size, S5P_FIMV_D_SECOND_PLANE_DPB_SIZE_V8);
  2102. R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V8);
  2103. R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V8);
  2104. R(d_first_plane_dpb_stride_size,
  2105. S5P_FIMV_D_FIRST_PLANE_DPB_STRIDE_SIZE_V8);
  2106. R(d_second_plane_dpb_stride_size,
  2107. S5P_FIMV_D_SECOND_PLANE_DPB_STRIDE_SIZE_V8);
  2108. R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V8);
  2109. R(d_num_mv, S5P_FIMV_D_NUM_MV_V8);
  2110. R(d_first_plane_dpb, S5P_FIMV_D_FIRST_PLANE_DPB_V8);
  2111. R(d_second_plane_dpb, S5P_FIMV_D_SECOND_PLANE_DPB_V8);
  2112. R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V8);
  2113. R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V8);
  2114. R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V8);
  2115. R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V8);
  2116. R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_FIRST_PLANE_ADDR_V8);
  2117. R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_SECOND_PLANE_ADDR_V8);
  2118. R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_FIRST_PLANE_ADDR_V8);
  2119. R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_SECOND_PLANE_ADDR_V8);
  2120. R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V8);
  2121. R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V8);
  2122. R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V8);
  2123. R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V8);
  2124. R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V8);
  2125. R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V8);
  2126. R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V8);
  2127. R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8);
  2128. R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V8);
  2129. R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V8);
  2130. R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8);
  2131. R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8);
  2132. R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V8);
  2133. R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V8);
  2134. R(d_min_scratch_buffer_size, S5P_FIMV_D_MIN_SCRATCH_BUFFER_SIZE_V8);
  2135. /* encoder registers */
  2136. R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V8);
  2137. R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V8);
  2138. R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V8);
  2139. R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V8);
  2140. R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V8);
  2141. R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V8);
  2142. R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V8);
  2143. R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V8);
  2144. R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V8);
  2145. R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V8);
  2146. R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V8);
  2147. R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V8);
  2148. R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V8);
  2149. R(e_min_scratch_buffer_size, S5P_FIMV_E_MIN_SCRATCH_BUFFER_SIZE_V8);
  2150. if (!IS_MFCV10(dev))
  2151. goto done;
  2152. /* Initialize registers used in MFC v10 only.
  2153. * Also, over-write the registers which have
  2154. * a different offset for MFC v10.
  2155. */
  2156. /* decoder registers */
  2157. R(d_static_buffer_addr, S5P_FIMV_D_STATIC_BUFFER_ADDR_V10);
  2158. R(d_static_buffer_size, S5P_FIMV_D_STATIC_BUFFER_SIZE_V10);
  2159. /* encoder registers */
  2160. R(e_num_t_layer, S5P_FIMV_E_NUM_T_LAYER_V10);
  2161. R(e_hier_qp_layer0, S5P_FIMV_E_HIERARCHICAL_QP_LAYER0_V10);
  2162. R(e_hier_bit_rate_layer0, S5P_FIMV_E_HIERARCHICAL_BIT_RATE_LAYER0_V10);
  2163. R(e_hevc_options, S5P_FIMV_E_HEVC_OPTIONS_V10);
  2164. R(e_hevc_refresh_period, S5P_FIMV_E_HEVC_REFRESH_PERIOD_V10);
  2165. R(e_hevc_lf_beta_offset_div2, S5P_FIMV_E_HEVC_LF_BETA_OFFSET_DIV2_V10);
  2166. R(e_hevc_lf_tc_offset_div2, S5P_FIMV_E_HEVC_LF_TC_OFFSET_DIV2_V10);
  2167. R(e_hevc_nal_control, S5P_FIMV_E_HEVC_NAL_CONTROL_V10);
  2168. done:
  2169. return &mfc_regs;
  2170. #undef S5P_MFC_REG_ADDR
  2171. #undef R
  2172. }
  2173. /* Initialize opr function pointers for MFC v6 */
  2174. static struct s5p_mfc_hw_ops s5p_mfc_ops_v6 = {
  2175. .alloc_dec_temp_buffers = s5p_mfc_alloc_dec_temp_buffers_v6,
  2176. .release_dec_desc_buffer = s5p_mfc_release_dec_desc_buffer_v6,
  2177. .alloc_codec_buffers = s5p_mfc_alloc_codec_buffers_v6,
  2178. .release_codec_buffers = s5p_mfc_release_codec_buffers_v6,
  2179. .alloc_instance_buffer = s5p_mfc_alloc_instance_buffer_v6,
  2180. .release_instance_buffer = s5p_mfc_release_instance_buffer_v6,
  2181. .alloc_dev_context_buffer =
  2182. s5p_mfc_alloc_dev_context_buffer_v6,
  2183. .release_dev_context_buffer =
  2184. s5p_mfc_release_dev_context_buffer_v6,
  2185. .dec_calc_dpb_size = s5p_mfc_dec_calc_dpb_size_v6,
  2186. .enc_calc_src_size = s5p_mfc_enc_calc_src_size_v6,
  2187. .set_enc_stream_buffer = s5p_mfc_set_enc_stream_buffer_v6,
  2188. .set_enc_frame_buffer = s5p_mfc_set_enc_frame_buffer_v6,
  2189. .get_enc_frame_buffer = s5p_mfc_get_enc_frame_buffer_v6,
  2190. .try_run = s5p_mfc_try_run_v6,
  2191. .clear_int_flags = s5p_mfc_clear_int_flags_v6,
  2192. .get_dspl_y_adr = s5p_mfc_get_dspl_y_adr_v6,
  2193. .get_dec_y_adr = s5p_mfc_get_dec_y_adr_v6,
  2194. .get_dspl_status = s5p_mfc_get_dspl_status_v6,
  2195. .get_dec_status = s5p_mfc_get_dec_status_v6,
  2196. .get_dec_frame_type = s5p_mfc_get_dec_frame_type_v6,
  2197. .get_disp_frame_type = s5p_mfc_get_disp_frame_type_v6,
  2198. .get_consumed_stream = s5p_mfc_get_consumed_stream_v6,
  2199. .get_int_reason = s5p_mfc_get_int_reason_v6,
  2200. .get_int_err = s5p_mfc_get_int_err_v6,
  2201. .err_dec = s5p_mfc_err_dec_v6,
  2202. .get_img_width = s5p_mfc_get_img_width_v6,
  2203. .get_img_height = s5p_mfc_get_img_height_v6,
  2204. .get_dpb_count = s5p_mfc_get_dpb_count_v6,
  2205. .get_mv_count = s5p_mfc_get_mv_count_v6,
  2206. .get_inst_no = s5p_mfc_get_inst_no_v6,
  2207. .get_enc_strm_size = s5p_mfc_get_enc_strm_size_v6,
  2208. .get_enc_slice_type = s5p_mfc_get_enc_slice_type_v6,
  2209. .get_enc_dpb_count = s5p_mfc_get_enc_dpb_count_v6,
  2210. .get_pic_type_top = s5p_mfc_get_pic_type_top_v6,
  2211. .get_pic_type_bot = s5p_mfc_get_pic_type_bot_v6,
  2212. .get_crop_info_h = s5p_mfc_get_crop_info_h_v6,
  2213. .get_crop_info_v = s5p_mfc_get_crop_info_v_v6,
  2214. .get_min_scratch_buf_size = s5p_mfc_get_min_scratch_buf_size,
  2215. .get_e_min_scratch_buf_size = s5p_mfc_get_e_min_scratch_buf_size,
  2216. };
  2217. struct s5p_mfc_hw_ops *s5p_mfc_init_hw_ops_v6(void)
  2218. {
  2219. return &s5p_mfc_ops_v6;
  2220. }