hfi_buffer_iris2.h 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __HFI_BUFFER_IRIS2__
  6. #define __HFI_BUFFER_IRIS2__
  7. #include <linux/types.h>
  8. #include "hfi_property.h"
  9. typedef u8 HFI_U8;
  10. typedef s8 HFI_S8;
  11. typedef u16 HFI_U16;
  12. typedef s16 HFI_S16;
  13. typedef u32 HFI_U32;
  14. typedef s32 HFI_S32;
  15. typedef u64 HFI_U64;
  16. typedef HFI_U32 HFI_BOOL;
  17. #ifndef MIN
  18. #define MIN(x, y) (((x) < (y)) ? (x) : (y))
  19. #endif
  20. #ifndef MAX
  21. #define MAX(x, y) (((x) > (y)) ? (x) : (y))
  22. #endif
  23. /*
  24. * Default buffer size alignment value
  25. */
  26. #define HFI_ALIGNMENT_4096 (4096)
  27. #define BUF_SIZE_ALIGN_16 (16)
  28. #define BUF_SIZE_ALIGN_32 (32)
  29. #define BUF_SIZE_ALIGN_64 (64)
  30. #define BUF_SIZE_ALIGN_128 (128)
  31. #define BUF_SIZE_ALIGN_256 (256)
  32. #define BUF_SIZE_ALIGN_512 (512)
  33. #define BUF_SIZE_ALIGN_4096 (4096)
  34. /*
  35. * Macro to align a to b
  36. */
  37. #define HFI_ALIGN(a, b) (((b) & ((b) - 1)) ? (((a) + (b) - 1) / \
  38. (b) * (b)) : (((a) + (b) - 1) & (~((b) - 1))))
  39. #define HFI_WORKMODE_1 1 /* stage 1 */
  40. #define HFI_WORKMODE_2 2 /* stage 2 */
  41. /*
  42. * Default ubwc metadata buffer stride and height alignment values
  43. */
  44. #define HFI_DEFAULT_METADATA_STRIDE_MULTIPLE (64)
  45. #define HFI_DEFAULT_METADATA_BUFFERHEIGHT_MULTIPLE (16)
  46. /*
  47. * Level 2 Comment: "Default Parameters for Firmware "
  48. * This section defines all the default constants used by Firmware
  49. * for any encoding session:
  50. * 1. Bitstream Restriction VUI: TRUE
  51. * 2. Picture Order Count: 2 (for all profiles except B frame case)
  52. * 3. Constrained intra pred flag : TRUE (if Intra-refresh (IR) is enabled)
  53. */
  54. /*
  55. * Level 2 Comment: "Tile dimensions(in pixels) macros for
  56. * different color formats"
  57. * @datatypes
  58. * @sa
  59. */
  60. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT (8)
  61. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH (32)
  62. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_HEIGHT (8)
  63. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_WIDTH (16)
  64. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_HEIGHT (4)
  65. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_WIDTH (48)
  66. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_UV_TILE_HEIGHT (4)
  67. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_UV_TILE_WIDTH (24)
  68. #define HFI_COLOR_FORMAT_RGBA8888_UBWC_TILE_HEIGHT (4)
  69. #define HFI_COLOR_FORMAT_RGBA8888_UBWC_TILE_WIDTH (16)
  70. /*
  71. * Level 2 Comment: "Macros to calculate YUV strides and size"
  72. * @datatypes
  73. * HFI_UNCOMPRESSED_FORMAT_SUPPORTED_TYPE
  74. * HFI_UNCOMPRESSED_PLANE_INFO_TYPE
  75. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  76. * @sa
  77. * HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED
  78. */
  79. /*
  80. * Luma stride calculation for YUV420, NV12/NV21, NV12_UBWC color format
  81. * Stride arrived at here is the minimum required stride. Host may
  82. * set a stride higher than the one calculated here, till the stride
  83. * is a multiple of "nStrideMultiples" in
  84. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  85. */
  86. #define HFI_NV12_IL_CALC_Y_STRIDE(stride, frame_width, stride_multiple) \
  87. stride = HFI_ALIGN(frame_width, stride_multiple)
  88. /*
  89. * Luma plane height calculation for YUV420 NV12/NV21, NV12_UBWC color format
  90. * Luma plane height used by the host needs to be either equal
  91. * to higher than the value calculated here
  92. */
  93. #define HFI_NV12_IL_CALC_Y_BUFHEIGHT(buf_height, frame_height, \
  94. min_buf_height_multiple) buf_height = HFI_ALIGN(frame_height, \
  95. min_buf_height_multiple)
  96. /*
  97. * Chroma stride calculation for NV12/NV21, NV12_UBWC color format
  98. */
  99. #define HFI_NV12_IL_CALC_UV_STRIDE(stride, frame_width, stride_multiple) \
  100. stride = HFI_ALIGN(frame_width, stride_multiple)
  101. /*
  102. * Chroma plane height calculation for NV12/NV21, NV12_UBWC color format
  103. */
  104. #define HFI_NV12_IL_CALC_UV_BUFHEIGHT(buf_height, frame_height, \
  105. min_buf_height_multiple) buf_height = HFI_ALIGN(((frame_height + 1) \
  106. >> 1), min_buf_height_multiple)
  107. /*
  108. * Minimum buffer size that needs to be allocated for current
  109. * frame dimensions for NV12/N21 Linear format
  110. * (calcualtion includes both luma and chroma plane)
  111. */
  112. #define HFI_NV12_IL_CALC_BUF_SIZE(buf_size, y_bufSize, y_stride, y_buf_height, \
  113. uv_buf_size, uv_stride, uv_buf_height) \
  114. y_bufSize = (y_stride * y_buf_height); \
  115. uv_buf_size = (uv_stride * uv_buf_height); \
  116. buf_size = HFI_ALIGN(y_bufSize + uv_buf_size, HFI_ALIGNMENT_4096)
  117. /*
  118. * Minimum Luma buffer size that needs to be allocated for current
  119. * frame dimensions NV12_UBWC format
  120. */
  121. #define HFI_NV12_UBWC_IL_CALC_Y_BUF_SIZE(y_bufSize, y_stride, y_buf_height) \
  122. y_bufSize = HFI_ALIGN(y_stride * y_buf_height, HFI_ALIGNMENT_4096)
  123. /*
  124. * Minimum chroma buffer size that needs to be allocated for current
  125. * frame dimensions NV12_UBWC format
  126. */
  127. #define HFI_NV12_UBWC_IL_CALC_UV_BUF_SIZE(uv_buf_size, \
  128. uv_stride, uv_buf_height) \
  129. uv_buf_size = HFI_ALIGN(uv_stride * uv_buf_height, HFI_ALIGNMENT_4096)
  130. /*
  131. * This is for sdm845 onwards:
  132. * Ver2.0: Minimum buffer size that needs to be allocated for current
  133. * frame dimensions NV12_UBWC format (including interlace UBWC)
  134. * (calculation includes all data & metadata planes)
  135. */
  136. #define HFI_NV12_UBWC_IL_CALC_BUF_SIZE_V2 \
  137. (buf_size, frame_width, frame_height, y_stride_multiple,\
  138. y_buffer_height_multiple, uv_stride_multiple, \
  139. uv_buffer_height_multiple, y_metadata_stride_multiple, \
  140. y_metadata_buffer_height_multiple, \
  141. uv_metadata_stride_multiple, uv_metadata_buffer_height_multiple) \
  142. do \
  143. { \
  144. HFI_U32 y_buf_size, uv_buf_size, y_meta_size, uv_meta_size; \
  145. HFI_U32 stride, height; \
  146. HFI_U32 halfHeight = (frame_height + 1) >> 1; \
  147. HFI_NV12_IL_CALC_Y_STRIDE(stride, frame_width,\
  148. y_stride_multiple); \
  149. HFI_NV12_IL_CALC_Y_BUFHEIGHT(height, half_height,\
  150. y_buffer_height_multiple); \
  151. HFI_NV12_UBWC_IL_CALC_Y_BUF_SIZE(y_buf_size, stride, height);\
  152. HFI_NV12_IL_CALC_UV_STRIDE(stride, frame_width, \
  153. uv_stride_multiple); \
  154. HFI_NV12_IL_CALC_UV_BUFHEIGHT(height, half_height, \
  155. uv_buffer_height_multiple); \
  156. HFI_NV12_UBWC_IL_CALC_UV_BUF_SIZE(uv_buf_size, stride, height);\
  157. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(stride, frame_width,\
  158. y_metadata_stride_multiple, \
  159. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH);\
  160. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(height, half_height, \
  161. y_metadata_buffer_height_multiple,\
  162. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT);\
  163. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(y_meta_size, stride, \
  164. height); \
  165. HFI_UBWC_UV_METADATA_PLANE_STRIDE(stride, frame_width,\
  166. uv_metadata_stride_multiple, \
  167. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_WIDTH); \
  168. HFI_UBWC_UV_METADATA_PLANE_BUFHEIGHT(height, half_height,\
  169. uv_metadata_buffer_height_multiple,\
  170. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_HEIGHT);\
  171. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(uv_meta_size, stride, \
  172. height); \
  173. bufSize = (y_buf_size + uv_buf_size + y_meta_size + \
  174. uv_meta_size) << 1;\
  175. } while (0)
  176. /*
  177. * Luma stride calculation for YUV420_TP10 color format
  178. * Stride arrived at here is the minimum required stride. Host may
  179. * set a stride higher than the one calculated here, till the stride
  180. * is a multiple of "nStrideMultiples" in
  181. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  182. */
  183. #define HFI_YUV420_TP10_CALC_Y_STRIDE(stride, frame_width, stride_multiple) \
  184. stride = HFI_ALIGN(frame_width, 192); \
  185. stride = HFI_ALIGN(stride * 4 / 3, stride_multiple)
  186. /*
  187. * Luma plane height calculation for YUV420_TP10 linear & UBWC color format
  188. * Luma plane height used by the host needs to be either equal
  189. * to higher than the value calculated here
  190. */
  191. #define HFI_YUV420_TP10_CALC_Y_BUFHEIGHT(buf_height, frame_height, \
  192. min_buf_height_multiple) \
  193. buf_height = HFI_ALIGN(frame_height, min_buf_height_multiple)
  194. /*
  195. * Chroma stride calculation for YUV420_TP10 linear & UBWC color format
  196. */
  197. #define HFI_YUV420_TP10_CALC_UV_STRIDE(stride, frame_width, stride_multiple) \
  198. stride = HFI_ALIGN(frame_width, 192); \
  199. stride = HFI_ALIGN(stride * 4 / 3, stride_multiple)
  200. /*
  201. * Chroma plane height calculation for YUV420_TP10 linear & UBWC color format
  202. */
  203. #define HFI_YUV420_TP10_CALC_UV_BUFHEIGHT(buf_height, frame_height, \
  204. min_buf_height_multiple) \
  205. buf_height = HFI_ALIGN(((frame_height + 1) >> 1), \
  206. min_buf_height_multiple)
  207. /*
  208. * Minimum buffer size that needs to be allocated for current
  209. * frame dimensions for YUV420_TP10 linear format
  210. * (calcualtion includes both luma and chroma plane)
  211. */
  212. #define HFI_YUV420_TP10_CALC_BUF_SIZE(buf_size, y_buf_size, y_stride,\
  213. y_buf_height, uv_buf_size, uv_stride, uv_buf_height) \
  214. y_buf_size = (y_stride * y_buf_height); \
  215. uv_buf_size = (uv_stride * uv_buf_height); \
  216. buf_size = y_buf_size + uv_buf_size
  217. /*
  218. * Minimum Luma data buffer size that needs to be allocated for current
  219. * frame dimensions YUV420_TP10_UBWC format
  220. */
  221. #define HFI_YUV420_TP10_UBWC_CALC_Y_BUF_SIZE(y_buf_size, y_stride, \
  222. y_buf_height) \
  223. y_buf_size = HFI_ALIGN(y_stride * y_buf_height, HFI_ALIGNMENT_4096)
  224. /*
  225. * Minimum chroma data buffer size that needs to be allocated for current
  226. * frame dimensions YUV420_TP10_UBWC format
  227. */
  228. #define HFI_YUV420_TP10_UBWC_CALC_UV_BUF_SIZE(uv_buf_size, uv_stride, \
  229. uv_buf_height) \
  230. uv_buf_size = HFI_ALIGN(uv_stride * uv_buf_height, HFI_ALIGNMENT_4096)
  231. /*
  232. * Minimum buffer size that needs to be allocated for current
  233. * frame dimensions NV12_UBWC format
  234. * (calculation includes all data & metadata planes)
  235. */
  236. #define HFI_YUV420_TP10_UBWC_CALC_BUF_SIZE(buf_size, y_stride, y_buf_height, \
  237. uv_stride, uv_buf_height, y_md_stride, y_md_height, uv_md_stride, \
  238. uv_md_height)\
  239. do \
  240. { \
  241. HFI_U32 y_data_size, uv_data_size, y_md_size, uv_md_size; \
  242. HFI_YUV420_TP10_UBWC_CALC_Y_BUF_SIZE(y_data_size, y_stride,\
  243. y_buf_height); \
  244. HFI_YUV420_TP10_UBWC_CALC_UV_BUF_SIZE(uv_data_size, uv_stride, \
  245. uv_buf_height); \
  246. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(y_md_size, y_md_stride, \
  247. y_md_height); \
  248. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(uv_md_size, uv_md_stride, \
  249. uv_md_height); \
  250. buf_size = y_data_size + uv_data_size + y_md_size + \
  251. uv_md_size; \
  252. } while (0)
  253. /*
  254. * Luma stride calculation for YUV420_P010 color format
  255. * Stride arrived at here is the minimum required stride. Host may
  256. * set a stride higher than the one calculated here, till the stride
  257. * is a multiple of "nStrideMultiples" in
  258. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  259. */
  260. #define HFI_YUV420_P010_CALC_Y_STRIDE(stride, frame_width, stride_multiple) \
  261. stride = HFI_ALIGN(frame_width * 2, stride_multiple)
  262. /*
  263. * Luma plane height calculation for YUV420_P010 linear color format
  264. * Luma plane height used by the host needs to be either equal
  265. * to higher than the value calculated here
  266. */
  267. #define HFI_YUV420_P010_CALC_Y_BUFHEIGHT(buf_height, frame_height, \
  268. min_buf_height_multiple) \
  269. buf_height = HFI_ALIGN(frame_height, min_buf_height_multiple)
  270. /*
  271. * Chroma stride calculation for YUV420_P010 linear color format
  272. */
  273. #define HFI_YUV420_P010_CALC_UV_STRIDE(stride, frame_width, stride_multiple) \
  274. stride = HFI_ALIGN(frame_width * 2, stride_multiple)
  275. /*
  276. * Chroma plane height calculation for YUV420_P010 linear color format
  277. */
  278. #define HFI_YUV420_P010_CALC_UV_BUFHEIGHT(buf_height, frame_height, \
  279. min_buf_height_multiple) \
  280. buf_height = HFI_ALIGN(((frame_height + 1) >> 1), \
  281. min_buf_height_multiple)
  282. /*
  283. * Minimum buffer size that needs to be allocated for current
  284. * frame dimensions for YUV420_P010 linear format
  285. * (calculation includes both luma and chroma plane)
  286. */
  287. #define HFI_YUV420_P010_CALC_BUF_SIZE(buf_size, y_data_size, y_stride, \
  288. y_buf_height, uv_data_size, uv_stride, uv_buf_height) \
  289. do \
  290. { \
  291. y_data_size = HFI_ALIGN(y_stride * y_buf_height, \
  292. HFI_ALIGNMENT_4096);\
  293. uv_data_size = HFI_ALIGN(uv_stride * uv_buf_height, \
  294. HFI_ALIGNMENT_4096); \
  295. buf_size = y_data_size + uv_data_size; \
  296. } while (0)
  297. /*
  298. * Plane stride calculation for RGB888/BGR888 color format
  299. * Stride arrived at here is the minimum required stride. Host may
  300. * set a stride higher than the one calculated here, till the stride
  301. * is a multiple of "nStrideMultiples" in
  302. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  303. */
  304. #define HFI_RGB888_CALC_STRIDE(stride, frame_width, stride_multiple) \
  305. stride = ((frame_width * 3) + stride_multiple - 1) & \
  306. (0xffffffff - (stride_multiple - 1))
  307. /*
  308. * Plane height calculation for RGB888/BGR888 color format
  309. * Luma plane height used by the host needs to be either equal
  310. * to higher than the value calculated here
  311. */
  312. #define HFI_RGB888_CALC_BUFHEIGHT(buf_height, frame_height, \
  313. min_buf_height_multiple) \
  314. buf_height = ((frame_height + min_buf_height_multiple - 1) & \
  315. (0xffffffff - (min_buf_height_multiple - 1)))
  316. /*
  317. * Minimum buffer size that needs to be allocated for current
  318. * frame dimensions for RGB888/BGR888 format
  319. */
  320. #define HFI_RGB888_CALC_BUF_SIZE(buf_size, stride, buf_height) \
  321. buf_size = ((stride) * (buf_height))
  322. /*
  323. * Plane stride calculation for RGBA8888 color format
  324. * Stride arrived at here is the minimum required stride. Host may
  325. * set a stride higher than the one calculated here, till the stride
  326. * is a multiple of "nStrideMultiples" in
  327. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  328. */
  329. #define HFI_RGBA8888_CALC_STRIDE(stride, frame_width, stride_multiple) \
  330. stride = HFI_ALIGN((frame_width << 2), stride_multiple)
  331. /*
  332. * Plane height calculation for RGBA8888 color format
  333. * Luma plane height used by the host needs to be either equal
  334. * to higher than the value calculated here
  335. */
  336. #define HFI_RGBA8888_CALC_BUFHEIGHT(buf_height, frame_height, \
  337. min_buf_height_multiple) \
  338. buf_height = HFI_ALIGN(frame_height, min_buf_height_multiple)
  339. /*
  340. * Minimum buffer size that needs to be allocated for current
  341. * frame dimensions for RGBA8888 format
  342. */
  343. #define HFI_RGBA8888_CALC_BUF_SIZE(buf_size, stride, buf_height) \
  344. buf_size = (stride) * (buf_height)
  345. /*
  346. * Minimum buffer size that needs to be allocated for current
  347. * frame dimensions for data plane of RGBA8888_UBWC format
  348. */
  349. #define HFI_RGBA8888_UBWC_CALC_DATA_PLANE_BUF_SIZE(buf_size, stride, \
  350. buf_height) \
  351. buf_size = HFI_ALIGN((stride) * (buf_height), HFI_ALIGNMENT_4096)
  352. /*
  353. * Minimum buffer size that needs to be allocated for current
  354. * frame dimensions for of RGBA8888_UBWC format
  355. */
  356. #define HFI_RGBA8888_UBWC_BUF_SIZE(buf_size, data_buf_size, \
  357. metadata_buffer_size, stride, buf_height, _metadata_tride, \
  358. _metadata_buf_height) \
  359. HFI_RGBA8888_UBWC_CALC_DATA_PLANE_BUF_SIZE(data_buf_size, \
  360. stride, buf_height); \
  361. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(metadata_buffer_size, \
  362. _metadata_tride, _metadata_buf_height); \
  363. buf_size = data_buf_size + metadata_buffer_size
  364. /*
  365. * Metadata plane stride calculation for all UBWC color formats
  366. * Should be used for Y metadata Plane & all single plane color
  367. * formats. Stride arrived at here is the minimum required
  368. * stride. Host may set a stride higher than the one calculated
  369. * here, till the stride is a multiple of
  370. * "_metadata_trideMultiple" in
  371. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE Default
  372. * metadataDataStrideMultiple = 64
  373. */
  374. #define HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, frame_width,\
  375. metadata_stride_multiple, tile_width_in_pels) \
  376. metadata_stride = HFI_ALIGN(((frame_width + (tile_width_in_pels - 1)) /\
  377. tile_width_in_pels), metadata_stride_multiple)
  378. /*
  379. * Metadata plane height calculation for all UBWC color formats
  380. * Should be used for Y metadata Plane & all single plane color
  381. * formats. Plane height used by the host needs to be either
  382. * equal to higher than the value calculated here
  383. * Default metadataHeightMultiple = 16
  384. */
  385. #define HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, frame_height, \
  386. metadata_height_multiple, tile_height_in_pels) \
  387. metadata_buf_height = HFI_ALIGN(((frame_height + \
  388. (tile_height_in_pels - 1)) / tile_height_in_pels), \
  389. metadata_height_multiple)
  390. /*
  391. * UV Metadata plane stride calculation for NV12_UBWC color
  392. * format. Stride arrived at here is the minimum required
  393. * stride. Host may set a stride higher than the one calculated
  394. * here, till the stride is a multiple of
  395. * "_metadata_trideMultiple" in
  396. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE Default
  397. * metadataDataStrideMultiple = 64
  398. */
  399. #define HFI_UBWC_UV_METADATA_PLANE_STRIDE(metadata_stride, frame_width, \
  400. metadata_stride_multiple, tile_width_in_pels) \
  401. metadata_stride = HFI_ALIGN(((((frame_width + 1) >> 1) +\
  402. (tile_width_in_pels - 1)) / tile_width_in_pels), \
  403. metadata_stride_multiple)
  404. /*
  405. * UV Metadata plane height calculation for NV12_UBWC color
  406. * format. Plane height used by the host needs to be either
  407. * equal to higher than the value calculated here Default
  408. * metadata_height_multiple = 16
  409. */
  410. #define HFI_UBWC_UV_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, frame_height,\
  411. metadata_height_multiple, tile_height_in_pels) \
  412. metadata_buf_height = HFI_ALIGN(((((frame_height + 1) >> 1) + \
  413. (tile_height_in_pels - 1)) / tile_height_in_pels), \
  414. metadata_height_multiple)
  415. /*
  416. * Minimum metadata buffer size that needs to be allocated for
  417. * current frame dimensions for each metadata plane.
  418. * This macro applies to all UBWC color format
  419. */
  420. #define HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(buffer_size, _metadata_tride, \
  421. _metadata_buf_height) \
  422. buffer_size = HFI_ALIGN(_metadata_tride * _metadata_buf_height, \
  423. HFI_ALIGNMENT_4096)
  424. #define BUFFER_ALIGNMENT_512_BYTES 512
  425. #define BUFFER_ALIGNMENT_256_BYTES 256
  426. #define BUFFER_ALIGNMENT_128_BYTES 128
  427. #define BUFFER_ALIGNMENT_64_BYTES 64
  428. #define BUFFER_ALIGNMENT_32_BYTES 32
  429. #define BUFFER_ALIGNMENT_16_BYTES 16
  430. #define BUFFER_ALIGNMENT_8_BYTES 8
  431. #define BUFFER_ALIGNMENT_4_BYTES 4
  432. #define VENUS_DMA_ALIGNMENT BUFFER_ALIGNMENT_256_BYTES
  433. #define MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE 64
  434. #define MAX_FE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE 64
  435. #define MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE 64
  436. #define MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE 640
  437. #define MAX_FE_NBR_DATA_CB_LINE_BUFFER_SIZE 320
  438. #define MAX_FE_NBR_DATA_CR_LINE_BUFFER_SIZE 320
  439. #define MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE (128 / 8)
  440. #define MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE (128 / 8)
  441. #define MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE (128 / 8)
  442. #define MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE (64 * 2 * 3)
  443. #define MAX_PE_NBR_DATA_LCU32_LINE_BUFFER_SIZE (32 * 2 * 3)
  444. #define MAX_PE_NBR_DATA_LCU16_LINE_BUFFER_SIZE (16 * 2 * 3)
  445. /* Begin of IRIS2 */
  446. /*
  447. * VPSS internal buffer definition
  448. * Only for 1:1 DS ratio case
  449. */
  450. #define MAX_TILE_COLUMNS 32 /* 8K/256 */
  451. /*
  452. * For all buffer size calculators using num_vpp_pipes,
  453. * use per chipset "static" pipe count.
  454. * Note that this applies to all use-cases,
  455. * e.g. buffer sizes for interlace decode
  456. * will be calculated using 4 vpp pipes on Kona,
  457. * even though interlace decode uses single vpp pipe.
  458. * __________________________________________________________
  459. * |_____________Target_____________|_______numVPPpipes_______|
  460. * | IRIS2(e.g. Kona) | 4 |
  461. * | IRIS2(e.g. Cedros) | 2 |
  462. * |_______IRIS2(e.g. Bitra)________|___________1_____________|
  463. */
  464. #define SIZE_VPSS_LB(Size, frame_width, frame_height, num_vpp_pipes) \
  465. do \
  466. { \
  467. HFI_U32 vpss_4tap_top_buffer_size, vpss_div2_top_buffer_size, \
  468. vpss_4tap_left_buffer_size, vpss_div2_left_buffer_size; \
  469. HFI_U32 opb_wr_top_line_luma_buffer_size, \
  470. opb_wr_top_line_chroma_buffer_size, \
  471. opb_lb_wr_llb_y_buffer_size,\
  472. opb_lb_wr_llb_uv_buffer_size; \
  473. HFI_U32 macrotiling_size; \
  474. vpss_4tap_top_buffer_size = vpss_div2_top_buffer_size = \
  475. vpss_4tap_left_buffer_size = vpss_div2_left_buffer_size = 0; \
  476. macrotiling_size = 32; \
  477. opb_wr_top_line_luma_buffer_size = HFI_ALIGN(frame_width, \
  478. macrotiling_size) / macrotiling_size * 256; \
  479. opb_wr_top_line_luma_buffer_size = \
  480. HFI_ALIGN(opb_wr_top_line_luma_buffer_size, \
  481. VENUS_DMA_ALIGNMENT) + (MAX_TILE_COLUMNS - 1) * 256; \
  482. opb_wr_top_line_luma_buffer_size = \
  483. MAX(opb_wr_top_line_luma_buffer_size, (32 * \
  484. HFI_ALIGN(frame_height, 8))); \
  485. opb_wr_top_line_chroma_buffer_size = \
  486. opb_wr_top_line_luma_buffer_size;\
  487. opb_lb_wr_llb_uv_buffer_size = opb_lb_wr_llb_y_buffer_size = \
  488. HFI_ALIGN((HFI_ALIGN(frame_height, 8) / (4 / 2)) * 64,\
  489. BUFFER_ALIGNMENT_32_BYTES); \
  490. Size = num_vpp_pipes * 2 * (vpss_4tap_top_buffer_size + \
  491. vpss_div2_top_buffer_size) + \
  492. 2 * (vpss_4tap_left_buffer_size + \
  493. vpss_div2_left_buffer_size) + \
  494. opb_wr_top_line_luma_buffer_size + \
  495. opb_wr_top_line_chroma_buffer_size + \
  496. opb_lb_wr_llb_uv_buffer_size + \
  497. opb_lb_wr_llb_y_buffer_size; \
  498. } while (0)
  499. /*
  500. * H264d internal buffer definition
  501. */
  502. #define VPP_CMD_MAX_SIZE (1 << 20)
  503. #define NUM_HW_PIC_BUF 32
  504. #define BIN_BUFFER_THRESHOLD (1280 * 736)
  505. #define H264D_MAX_SLICE 1800
  506. #define SIZE_H264D_BUFTAB_T (256) /* sizeof(h264d_buftab_t) aligned to 256 */
  507. #define SIZE_H264D_HW_PIC_T (1 << 11) /* sizeof(h264d_hw_pic_t) 32 aligned */
  508. #define SIZE_H264D_BSE_CMD_PER_BUF (32 * 4)
  509. #define SIZE_H264D_VPP_CMD_PER_BUF (512)
  510. /* Line Buffer definitions */
  511. /* one for luma and 1/2 for each chroma */
  512. #define SIZE_H264D_LB_FE_TOP_DATA(frame_width, frame_height) \
  513. (MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE * HFI_ALIGN(frame_width, 16) * 3)
  514. #define SIZE_H264D_LB_FE_TOP_CTRL(frame_width, frame_height) \
  515. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_width + 15) >> 4))
  516. #define SIZE_H264D_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  517. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_height + 15) >> 4))
  518. #define SIZE_H264D_LB_SE_TOP_CTRL(frame_width, frame_height) \
  519. (MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_width + 15) >> 4))
  520. #define SIZE_H264D_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  521. (MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_height + 15) >> 4))
  522. #define SIZE_H264D_LB_PE_TOP_DATA(frame_width, frame_height) \
  523. (MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE * ((frame_width + 15) >> 4))
  524. #define SIZE_H264D_LB_VSP_TOP(frame_width, frame_height) \
  525. ((((frame_width + 15) >> 4) << 7))
  526. #define SIZE_H264D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  527. (HFI_ALIGN(frame_height, 16) * 32)
  528. #define SIZE_H264D_QP(frame_width, frame_height) \
  529. (((frame_width + 63) >> 6) * ((frame_height + 63) >> 6) * 128)
  530. #define SIZE_HW_PIC(size_per_buf) \
  531. (NUM_HW_PIC_BUF * size_per_buf)
  532. #define SIZE_H264D_BSE_CMD_BUF(_size, frame_width, frame_height) \
  533. do \
  534. { /* this could change alignment */ \
  535. HFI_U32 _height = HFI_ALIGN(frame_height, \
  536. BUFFER_ALIGNMENT_32_BYTES); \
  537. _size = MIN((((_height + 15) >> 4) * 3 * 4), H264D_MAX_SLICE) *\
  538. SIZE_H264D_BSE_CMD_PER_BUF; \
  539. } while (0)
  540. #define SIZE_H264D_VPP_CMD_BUF(_size, frame_width, frame_height) \
  541. do \
  542. { /* this could change alignment */ \
  543. HFI_U32 _height = HFI_ALIGN(frame_height, \
  544. BUFFER_ALIGNMENT_32_BYTES); \
  545. _size = MIN((((_height + 15) >> 4) * 3 * 4), H264D_MAX_SLICE) * \
  546. SIZE_H264D_VPP_CMD_PER_BUF; \
  547. if (_size > VPP_CMD_MAX_SIZE) { _size = VPP_CMD_MAX_SIZE; } \
  548. } while (0)
  549. #define HFI_BUFFER_COMV_H264D(coMV_size, frame_width, \
  550. frame_height, _yuv_bufcount_min) \
  551. do \
  552. { \
  553. HFI_U32 frame_width_in_mbs = ((frame_width + 15) >> 4); \
  554. HFI_U32 frame_height_in_mbs = ((frame_height + 15) >> 4); \
  555. HFI_U32 col_mv_aligned_width = (frame_width_in_mbs << 7); \
  556. HFI_U32 col_zero_aligned_width = (frame_width_in_mbs << 2); \
  557. HFI_U32 col_zero_size = 0, size_colloc = 0; \
  558. col_mv_aligned_width = HFI_ALIGN(col_mv_aligned_width, \
  559. BUFFER_ALIGNMENT_16_BYTES); \
  560. col_zero_aligned_width = HFI_ALIGN(col_zero_aligned_width, \
  561. BUFFER_ALIGNMENT_16_BYTES); \
  562. col_zero_size = col_zero_aligned_width * \
  563. ((frame_height_in_mbs + 1) >> 1); \
  564. col_zero_size = HFI_ALIGN(col_zero_size, \
  565. BUFFER_ALIGNMENT_64_BYTES); \
  566. col_zero_size <<= 1; \
  567. col_zero_size = HFI_ALIGN(col_zero_size, \
  568. BUFFER_ALIGNMENT_512_BYTES); \
  569. size_colloc = col_mv_aligned_width * ((frame_height_in_mbs + \
  570. 1) >> 1); \
  571. size_colloc = HFI_ALIGN(size_colloc, \
  572. BUFFER_ALIGNMENT_64_BYTES); \
  573. size_colloc <<= 1; \
  574. size_colloc = HFI_ALIGN(size_colloc, \
  575. BUFFER_ALIGNMENT_512_BYTES); \
  576. size_colloc += (col_zero_size + SIZE_H264D_BUFTAB_T * 2); \
  577. coMV_size = size_colloc * (_yuv_bufcount_min); \
  578. coMV_size += BUFFER_ALIGNMENT_512_BYTES; \
  579. } while (0)
  580. #define HFI_BUFFER_NON_COMV_H264D(_size, frame_width, frame_height, \
  581. num_vpp_pipes) \
  582. do \
  583. { \
  584. HFI_U32 _size_bse, _size_vpp; \
  585. SIZE_H264D_BSE_CMD_BUF(_size_bse, frame_width, frame_height); \
  586. SIZE_H264D_VPP_CMD_BUF(_size_vpp, frame_width, frame_height); \
  587. _size = HFI_ALIGN(_size_bse, VENUS_DMA_ALIGNMENT) + \
  588. HFI_ALIGN(_size_vpp, VENUS_DMA_ALIGNMENT) + \
  589. HFI_ALIGN(SIZE_HW_PIC(SIZE_H264D_HW_PIC_T), \
  590. VENUS_DMA_ALIGNMENT)+ HFI_ALIGN(SIZE_H264D_QP\
  591. (frame_width, frame_height), VENUS_DMA_ALIGNMENT); \
  592. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  593. } while (0)
  594. /*
  595. * _yuv_bufcount_min = MAX(Min YUV Buffer count,
  596. * (HFI_PROPERTY_PARAM_VDEC_VPP_DELAY + 1))
  597. */
  598. #define HFI_BUFFER_LINE_H264D(_size, frame_width, frame_height, \
  599. _yuv_bufcount_min, is_opb, num_vpp_pipes) \
  600. do \
  601. { \
  602. HFI_U32 vpss_lb_size = 0; \
  603. _size = HFI_ALIGN(SIZE_H264D_LB_FE_TOP_DATA(frame_width, \
  604. frame_height), VENUS_DMA_ALIGNMENT) + \
  605. HFI_ALIGN(SIZE_H264D_LB_FE_TOP_CTRL(frame_width, \
  606. frame_height), VENUS_DMA_ALIGNMENT) + \
  607. HFI_ALIGN(SIZE_H264D_LB_FE_LEFT_CTRL(frame_width, \
  608. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  609. HFI_ALIGN(SIZE_H264D_LB_SE_TOP_CTRL(frame_width, \
  610. frame_height), VENUS_DMA_ALIGNMENT) + \
  611. HFI_ALIGN(SIZE_H264D_LB_SE_LEFT_CTRL(frame_width, \
  612. frame_height), VENUS_DMA_ALIGNMENT) * \
  613. num_vpp_pipes + \
  614. HFI_ALIGN(SIZE_H264D_LB_PE_TOP_DATA(frame_width, \
  615. frame_height), VENUS_DMA_ALIGNMENT) + \
  616. HFI_ALIGN(SIZE_H264D_LB_VSP_TOP(frame_width, \
  617. frame_height), VENUS_DMA_ALIGNMENT) + \
  618. HFI_ALIGN(SIZE_H264D_LB_RECON_DMA_METADATA_WR\
  619. (frame_width, frame_height), \
  620. VENUS_DMA_ALIGNMENT) * 2; \
  621. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  622. if (is_opb) \
  623. { \
  624. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  625. num_vpp_pipes); \
  626. } \
  627. _size = HFI_ALIGN((_size + vpss_lb_size), \
  628. VENUS_DMA_ALIGNMENT); \
  629. } while (0)
  630. #define H264_CABAC_HDR_RATIO_HD_TOT 1
  631. #define H264_CABAC_RES_RATIO_HD_TOT 3
  632. /*
  633. * some content need more bin buffer,
  634. * but limit buffer size for high resolution
  635. */
  636. #define SIZE_H264D_HW_BIN_BUFFER(_size, frame_width, frame_height, \
  637. delay, num_vpp_pipes) \
  638. do \
  639. { \
  640. HFI_U32 size_yuv, size_bin_hdr, size_bin_res; \
  641. size_yuv = ((frame_width * frame_height) <= \
  642. BIN_BUFFER_THRESHOLD) ?\
  643. ((BIN_BUFFER_THRESHOLD * 3) >> 1) : \
  644. ((frame_width * frame_height * 3) >> 1); \
  645. size_bin_hdr = size_yuv * H264_CABAC_HDR_RATIO_HD_TOT; \
  646. size_bin_res = size_yuv * H264_CABAC_RES_RATIO_HD_TOT; \
  647. size_bin_hdr = size_bin_hdr * (((((HFI_U32)(delay)) & 31) /\
  648. 10) + 2) / 2; \
  649. size_bin_res = size_bin_res * (((((HFI_U32)(delay)) & 31) /\
  650. 10) + 2) / 2; \
  651. size_bin_hdr = HFI_ALIGN(size_bin_hdr / num_vpp_pipes,\
  652. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  653. size_bin_res = HFI_ALIGN(size_bin_res / num_vpp_pipes, \
  654. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  655. _size = size_bin_hdr + size_bin_res; \
  656. } while (0)
  657. #define HFI_BUFFER_BIN_H264D(_size, frame_width, frame_height, is_interlaced, \
  658. delay, num_vpp_pipes) \
  659. do \
  660. { \
  661. HFI_U32 n_aligned_w = HFI_ALIGN(frame_width, \
  662. BUFFER_ALIGNMENT_16_BYTES);\
  663. HFI_U32 n_aligned_h = HFI_ALIGN(frame_height, \
  664. BUFFER_ALIGNMENT_16_BYTES); \
  665. if (!is_interlaced) \
  666. { \
  667. SIZE_H264D_HW_BIN_BUFFER(_size, n_aligned_w, \
  668. n_aligned_h, delay, num_vpp_pipes); \
  669. } \
  670. else \
  671. { \
  672. _size = 0; \
  673. } \
  674. } while (0)
  675. #define NUM_SLIST_BUF_H264 (256 + 32)
  676. #define SIZE_SLIST_BUF_H264 (512)
  677. #define SIZE_SEI_USERDATA (4096)
  678. #define HFI_BUFFER_PERSIST_H264D(_size) \
  679. _size = HFI_ALIGN((SIZE_SLIST_BUF_H264 * NUM_SLIST_BUF_H264 + \
  680. NUM_HW_PIC_BUF * SIZE_SEI_USERDATA), VENUS_DMA_ALIGNMENT)
  681. /*
  682. * H265d internal buffer definition
  683. */
  684. #define LCU_MAX_SIZE_PELS 64
  685. #define LCU_MIN_SIZE_PELS 16
  686. #define H265D_MAX_SLICE 1200
  687. #define SIZE_H265D_HW_PIC_T SIZE_H264D_HW_PIC_T
  688. #define SIZE_H265D_BSE_CMD_PER_BUF (16 * sizeof(HFI_U32))
  689. #define SIZE_H265D_VPP_CMD_PER_BUF (256)
  690. #define SIZE_H265D_LB_FE_TOP_DATA(frame_width, frame_height) \
  691. (MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE * \
  692. (HFI_ALIGN(frame_width, 64) + 8) * 2)
  693. #define SIZE_H265D_LB_FE_TOP_CTRL(frame_width, frame_height) \
  694. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * \
  695. (HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  696. #define SIZE_H265D_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  697. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * \
  698. (HFI_ALIGN(frame_height, LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  699. #define SIZE_H265D_LB_SE_TOP_CTRL(frame_width, frame_height) \
  700. ((LCU_MAX_SIZE_PELS / 8 * (128 / 8)) * ((frame_width + 15) >> 4))
  701. #define SIZE_H265D_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  702. (MAX(((frame_height + 16 - 1) / 8) * \
  703. MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE, \
  704. MAX(((frame_height + 32 - 1) / 8) * \
  705. MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  706. ((frame_height + 64 - 1) / 8) * \
  707. MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE)))
  708. #define SIZE_H265D_LB_PE_TOP_DATA(frame_width, frame_height) \
  709. (MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE * (HFI_ALIGN(frame_width, \
  710. LCU_MIN_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  711. #define SIZE_H265D_LB_VSP_TOP(frame_width, frame_height) \
  712. (((frame_width + 63) >> 6) * 128)
  713. #define SIZE_H265D_LB_VSP_LEFT(frame_width, frame_height) \
  714. (((frame_height + 63) >> 6) * 128)
  715. #define SIZE_H265D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  716. SIZE_H264D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height)
  717. #define SIZE_H265D_QP(frame_width, frame_height) \
  718. SIZE_H264D_QP(frame_width, frame_height)
  719. #define SIZE_H265D_BSE_CMD_BUF(_size, frame_width, frame_height)\
  720. do \
  721. { \
  722. _size = HFI_ALIGN(((HFI_ALIGN(frame_width, \
  723. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS) * \
  724. (HFI_ALIGN(frame_height, LCU_MAX_SIZE_PELS) /\
  725. LCU_MIN_SIZE_PELS)) * NUM_HW_PIC_BUF, VENUS_DMA_ALIGNMENT); \
  726. _size = MIN(_size, H265D_MAX_SLICE + 1); \
  727. _size = 2 * _size * SIZE_H265D_BSE_CMD_PER_BUF; \
  728. } while (0)
  729. #define SIZE_H265D_VPP_CMD_BUF(_size, frame_width, frame_height) \
  730. do \
  731. { \
  732. _size = HFI_ALIGN(((HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) /\
  733. LCU_MIN_SIZE_PELS) * (HFI_ALIGN(frame_height, \
  734. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS)) * \
  735. NUM_HW_PIC_BUF, VENUS_DMA_ALIGNMENT); \
  736. _size = MIN(_size, H265D_MAX_SLICE + 1); \
  737. _size = HFI_ALIGN(_size, 4); \
  738. _size = 2 * _size * SIZE_H265D_VPP_CMD_PER_BUF; \
  739. if (_size > VPP_CMD_MAX_SIZE) \
  740. { \
  741. _size = VPP_CMD_MAX_SIZE; \
  742. } \
  743. } while (0)
  744. #define HFI_BUFFER_COMV_H265D(_size, frame_width, frame_height, \
  745. _yuv_bufcount_min) \
  746. do \
  747. { \
  748. _size = HFI_ALIGN(((((frame_width + 15) >> 4) * \
  749. ((frame_height + 15) >> 4)) << 8), \
  750. BUFFER_ALIGNMENT_512_BYTES); \
  751. _size *= _yuv_bufcount_min; \
  752. _size += BUFFER_ALIGNMENT_512_BYTES; \
  753. } while (0)
  754. #define HDR10_HIST_EXTRADATA_SIZE (4 * 1024)
  755. /* c2 divide this into NON_COMV and LINE */
  756. #define HFI_BUFFER_NON_COMV_H265D(_size, frame_width, frame_height, \
  757. num_vpp_pipes) \
  758. do \
  759. { \
  760. HFI_U32 _size_bse, _size_vpp; \
  761. SIZE_H265D_BSE_CMD_BUF(_size_bse, frame_width, \
  762. frame_height); \
  763. SIZE_H265D_VPP_CMD_BUF(_size_vpp, frame_width, \
  764. frame_height); \
  765. _size = HFI_ALIGN(_size_bse, VENUS_DMA_ALIGNMENT) + \
  766. HFI_ALIGN(_size_vpp, VENUS_DMA_ALIGNMENT) + \
  767. HFI_ALIGN(NUM_HW_PIC_BUF * 20 * 22 * 4, \
  768. VENUS_DMA_ALIGNMENT) + \
  769. HFI_ALIGN(2 * sizeof(HFI_U16) * \
  770. (HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) / \
  771. LCU_MIN_SIZE_PELS) * (HFI_ALIGN(frame_height, \
  772. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS), \
  773. VENUS_DMA_ALIGNMENT) + \
  774. HFI_ALIGN(SIZE_HW_PIC(SIZE_H265D_HW_PIC_T), \
  775. VENUS_DMA_ALIGNMENT) + \
  776. HDR10_HIST_EXTRADATA_SIZE; \
  777. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  778. } while (0)
  779. #define HFI_BUFFER_LINE_H265D(_size, frame_width, frame_height, \
  780. is_opb, num_vpp_pipes) \
  781. do \
  782. { \
  783. HFI_U32 vpss_lb_size = 0; \
  784. _size = HFI_ALIGN(SIZE_H265D_LB_FE_TOP_DATA(frame_width, \
  785. frame_height), VENUS_DMA_ALIGNMENT) + \
  786. HFI_ALIGN(SIZE_H265D_LB_FE_TOP_CTRL(frame_width, \
  787. frame_height), VENUS_DMA_ALIGNMENT) + \
  788. HFI_ALIGN(SIZE_H265D_LB_FE_LEFT_CTRL(frame_width, \
  789. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  790. HFI_ALIGN(SIZE_H265D_LB_SE_LEFT_CTRL(frame_width, \
  791. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  792. HFI_ALIGN(SIZE_H265D_LB_SE_TOP_CTRL(frame_width, \
  793. frame_height), VENUS_DMA_ALIGNMENT) + \
  794. HFI_ALIGN(SIZE_H265D_LB_PE_TOP_DATA(frame_width, \
  795. frame_height), VENUS_DMA_ALIGNMENT) + \
  796. HFI_ALIGN(SIZE_H265D_LB_VSP_TOP(frame_width, \
  797. frame_height), VENUS_DMA_ALIGNMENT) + \
  798. HFI_ALIGN(SIZE_H265D_LB_VSP_LEFT(frame_width, \
  799. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  800. HFI_ALIGN(SIZE_H265D_LB_RECON_DMA_METADATA_WR\
  801. (frame_width, frame_height), \
  802. VENUS_DMA_ALIGNMENT) * 4 + \
  803. HFI_ALIGN(SIZE_H265D_QP(frame_width, frame_height),\
  804. VENUS_DMA_ALIGNMENT); \
  805. if (is_opb) \
  806. { \
  807. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height,\
  808. num_vpp_pipes); \
  809. } \
  810. _size = HFI_ALIGN((_size + vpss_lb_size), \
  811. VENUS_DMA_ALIGNMENT); \
  812. } while (0)
  813. #define H265_CABAC_HDR_RATIO_HD_TOT 2
  814. #define H265_CABAC_RES_RATIO_HD_TOT 2
  815. /*
  816. * some content need more bin buffer,
  817. * but limit buffer size for high resolution
  818. */
  819. #define SIZE_H265D_HW_BIN_BUFFER(_size, frame_width, frame_height, \
  820. delay, num_vpp_pipes) \
  821. do \
  822. { \
  823. HFI_U32 size_yuv, size_bin_hdr, size_bin_res; \
  824. size_yuv = ((frame_width * frame_height) <= \
  825. BIN_BUFFER_THRESHOLD) ? \
  826. ((BIN_BUFFER_THRESHOLD * 3) >> 1) : \
  827. ((frame_width * frame_height * 3) >> 1); \
  828. size_bin_hdr = size_yuv * H265_CABAC_HDR_RATIO_HD_TOT; \
  829. size_bin_res = size_yuv * H265_CABAC_RES_RATIO_HD_TOT; \
  830. size_bin_hdr = size_bin_hdr * \
  831. (((((HFI_U32)(delay)) & 31) / 10) + 2) / 2; \
  832. size_bin_res = size_bin_res * \
  833. (((((HFI_U32)(delay)) & 31) / 10) + 2) / 2; \
  834. size_bin_hdr = HFI_ALIGN(size_bin_hdr / \
  835. num_vpp_pipes, VENUS_DMA_ALIGNMENT) * \
  836. num_vpp_pipes; \
  837. size_bin_res = HFI_ALIGN(size_bin_res / num_vpp_pipes,\
  838. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  839. _size = size_bin_hdr + size_bin_res; \
  840. } while (0)
  841. #define HFI_BUFFER_BIN_H265D(_size, frame_width, frame_height, \
  842. is_interlaced, delay, num_vpp_pipes) \
  843. do \
  844. { \
  845. HFI_U32 n_aligned_w = HFI_ALIGN(frame_width, \
  846. BUFFER_ALIGNMENT_16_BYTES); \
  847. HFI_U32 n_aligned_h = HFI_ALIGN(frame_height, \
  848. BUFFER_ALIGNMENT_16_BYTES); \
  849. if (!is_interlaced) \
  850. { \
  851. SIZE_H265D_HW_BIN_BUFFER(_size, n_aligned_w, \
  852. n_aligned_h, delay, num_vpp_pipes); \
  853. } \
  854. else \
  855. { \
  856. _size = 0; \
  857. } \
  858. } while (0)
  859. #define SIZE_SLIST_BUF_H265 (1 << 10)
  860. #define NUM_SLIST_BUF_H265 (80 + 20)
  861. #define H265_NUM_TILE_COL 32
  862. #define H265_NUM_TILE_ROW 128
  863. #define H265_NUM_TILE (H265_NUM_TILE_ROW * H265_NUM_TILE_COL + 1)
  864. #define HFI_BUFFER_PERSIST_H265D(_size) \
  865. _size = HFI_ALIGN((SIZE_SLIST_BUF_H265 * NUM_SLIST_BUF_H265 + \
  866. H265_NUM_TILE * sizeof(HFI_U32) + NUM_HW_PIC_BUF * SIZE_SEI_USERDATA),\
  867. VENUS_DMA_ALIGNMENT)
  868. /*
  869. * VPxd internal buffer definition
  870. */
  871. #define SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  872. MAX(((frame_height + 15) >> 4) * \
  873. MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE, \
  874. MAX(((frame_height + 31) >> 5) * \
  875. MAX_FE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  876. ((frame_height + 63) >> 6) * MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE))
  877. #define SIZE_VPXD_LB_FE_TOP_CTRL(frame_width, frame_height) \
  878. (((HFI_ALIGN(frame_width, 64) + 8) * 10 * 2)) /* + small line */
  879. #define SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height) \
  880. (((frame_width + 15) >> 4) * MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE)
  881. #define SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  882. MAX(((frame_height + 15) >> 4) * \
  883. MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE,\
  884. MAX(((frame_height + 31) >> 5) * \
  885. MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  886. ((frame_height + 63) >> 6) * MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE))
  887. #define SIZE_VPXD_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  888. HFI_ALIGN((HFI_ALIGN(frame_height, 8) / (4 / 2)) * 64,\
  889. BUFFER_ALIGNMENT_32_BYTES)
  890. #define SIZE_MP2D_LB_FE_TOP_DATA(frame_width, frame_height) \
  891. ((HFI_ALIGN(frame_width, 16) + 8) * 10 * 2)
  892. #define SIZE_VP9D_LB_FE_TOP_DATA(frame_width, frame_height) \
  893. ((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) + 8) * 10 * 2)
  894. #define SIZE_MP2D_LB_PE_TOP_DATA(frame_width, frame_height) \
  895. ((HFI_ALIGN(frame_width, 16) >> 4) * 64)
  896. #define SIZE_VP9D_LB_PE_TOP_DATA(frame_width, frame_height) \
  897. ((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) >> 6) * 176)
  898. #define SIZE_MP2D_LB_VSP_TOP(frame_width, frame_height) \
  899. (((HFI_ALIGN(frame_width, 16) >> 4) * 64 / 2) + 256)
  900. #define SIZE_VP9D_LB_VSP_TOP(frame_width, frame_height) \
  901. ((((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) >> 6) * 64 * 8) + 256))
  902. /* sizeof(VP9_COL_MV_BUFFER) */
  903. #define HFI_IRIS2_VP9D_COMV_SIZE \
  904. ((((8192 + 63) >> 6) * ((4320 + 63) >> 6) * 8 * 8 * 2 * 8))
  905. #define HFI_IRIS2_VP9D_LB_SIZE(_size, frame_width, frame_height, num_vpp_pipes)\
  906. do \
  907. { \
  908. _size = HFI_ALIGN(SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, \
  909. frame_height),VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  910. HFI_ALIGN(SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height),\
  911. VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  912. HFI_ALIGN(SIZE_VP9D_LB_VSP_TOP(frame_width, frame_height), \
  913. VENUS_DMA_ALIGNMENT) + \
  914. HFI_ALIGN(SIZE_VPXD_LB_FE_TOP_CTRL(frame_width, frame_height), \
  915. VENUS_DMA_ALIGNMENT) + 2 * \
  916. HFI_ALIGN(SIZE_VPXD_LB_RECON_DMA_METADATA_WR \
  917. (frame_width, frame_height), VENUS_DMA_ALIGNMENT) + \
  918. HFI_ALIGN(SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height), \
  919. VENUS_DMA_ALIGNMENT) + \
  920. HFI_ALIGN(SIZE_VP9D_LB_PE_TOP_DATA(frame_width, frame_height), \
  921. VENUS_DMA_ALIGNMENT) + \
  922. HFI_ALIGN(SIZE_VP9D_LB_FE_TOP_DATA(frame_width, frame_height), \
  923. VENUS_DMA_ALIGNMENT); \
  924. } while (0)
  925. /* _yuv_bufcount_min = MAX(Min YUV Buffer count,
  926. * (HFI_PROPERTY_PARAM_VDEC_VPP_DELAY + 1))
  927. */
  928. #define HFI_BUFFER_LINE_VP9D(_size, frame_width, frame_height, \
  929. _yuv_bufcount_min, is_opb, num_vpp_pipes) \
  930. do \
  931. { \
  932. HFI_U32 _lb_size = 0; \
  933. HFI_U32 vpss_lb_size = 0; \
  934. HFI_IRIS2_VP9D_LB_SIZE(_lb_size, frame_width, frame_height,\
  935. num_vpp_pipes); \
  936. if (is_opb) \
  937. { \
  938. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  939. num_vpp_pipes); \
  940. } \
  941. _size = _lb_size + vpss_lb_size + HDR10_HIST_EXTRADATA_SIZE; \
  942. } while (0)
  943. #define VPX_DECODER_FRAME_CONCURENCY_LVL (2)
  944. #define VPX_DECODER_FRAME_BIN_HDR_BUDGET_RATIO 1 / 2
  945. #define VPX_DECODER_FRAME_BIN_RES_BUDGET_RATIO 3 / 2
  946. #define HFI_BUFFER_BIN_VP9D(_size, frame_width, frame_height, \
  947. is_interlaced, num_vpp_pipes) \
  948. do \
  949. { \
  950. HFI_U32 _size_yuv = HFI_ALIGN(frame_width, \
  951. BUFFER_ALIGNMENT_16_BYTES) *\
  952. HFI_ALIGN(frame_height, BUFFER_ALIGNMENT_16_BYTES) * 3 / 2; \
  953. if (!is_interlaced) \
  954. { \
  955. /* binbuffer1_size + binbufer2_size */ \
  956. _size = HFI_ALIGN(((MAX(_size_yuv, \
  957. ((BIN_BUFFER_THRESHOLD * 3) >> 1)) * \
  958. VPX_DECODER_FRAME_BIN_HDR_BUDGET_RATIO * \
  959. VPX_DECODER_FRAME_CONCURENCY_LVL) / num_vpp_pipes), \
  960. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(((MAX(_size_yuv, \
  961. ((BIN_BUFFER_THRESHOLD * 3) >> 1)) * \
  962. VPX_DECODER_FRAME_BIN_RES_BUDGET_RATIO * \
  963. VPX_DECODER_FRAME_CONCURENCY_LVL) / num_vpp_pipes), \
  964. VENUS_DMA_ALIGNMENT); \
  965. _size = _size * num_vpp_pipes; \
  966. } \
  967. else \
  968. { \
  969. _size = 0; \
  970. } \
  971. } while (0)
  972. #define VP9_NUM_FRAME_INFO_BUF 32
  973. #define VP9_NUM_PROBABILITY_TABLE_BUF (VP9_NUM_FRAME_INFO_BUF + 4)
  974. #define VP9_PROB_TABLE_SIZE (3840)
  975. #define VP9_UDC_HEADER_BUF_SIZE (3 * 128)
  976. #define MAX_SUPERFRAME_HEADER_LEN (34)
  977. #define CCE_TILE_OFFSET_SIZE HFI_ALIGN(32 * 4 * 4, BUFFER_ALIGNMENT_32_BYTES)
  978. #define HFI_BUFFER_PERSIST_VP9D(_size) \
  979. _size = HFI_ALIGN(VP9_NUM_PROBABILITY_TABLE_BUF * VP9_PROB_TABLE_SIZE, \
  980. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(HFI_IRIS2_VP9D_COMV_SIZE, \
  981. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(MAX_SUPERFRAME_HEADER_LEN, \
  982. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(VP9_UDC_HEADER_BUF_SIZE, \
  983. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(VP9_NUM_FRAME_INFO_BUF * \
  984. CCE_TILE_OFFSET_SIZE, VENUS_DMA_ALIGNMENT)
  985. /*
  986. * MP2d internal buffer definition
  987. */
  988. #define HFI_BUFFER_LINE_MP2D(_size, frame_width, frame_height, \
  989. _yuv_bufcount_min, is_opb, num_vpp_pipes) \
  990. do \
  991. { \
  992. HFI_U32 vpss_lb_size = 0; \
  993. _size = HFI_ALIGN(SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, \
  994. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  995. HFI_ALIGN(SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height),\
  996. VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  997. HFI_ALIGN(SIZE_MP2D_LB_VSP_TOP(frame_width, frame_height),\
  998. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(SIZE_VPXD_LB_FE_TOP_CTRL\
  999. (frame_width, frame_height), VENUS_DMA_ALIGNMENT) + \
  1000. 2 * HFI_ALIGN(SIZE_VPXD_LB_RECON_DMA_METADATA_WR(frame_width,\
  1001. frame_height), VENUS_DMA_ALIGNMENT) + \
  1002. HFI_ALIGN(SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height),\
  1003. VENUS_DMA_ALIGNMENT) + \
  1004. HFI_ALIGN(SIZE_MP2D_LB_PE_TOP_DATA(frame_width, frame_height), \
  1005. VENUS_DMA_ALIGNMENT) + \
  1006. HFI_ALIGN(SIZE_MP2D_LB_FE_TOP_DATA(frame_width, frame_height), \
  1007. VENUS_DMA_ALIGNMENT); \
  1008. if (is_opb) \
  1009. { \
  1010. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  1011. num_vpp_pipes); \
  1012. } \
  1013. _size += vpss_lb_size; \
  1014. } while (0)
  1015. #define HFI_BUFFER_BIN_MP2D(_size, frame_width, frame_height, is_interlaced) 0
  1016. #define QMATRIX_SIZE (sizeof(HFI_U32) * 128 + 256)
  1017. #define MP2D_QPDUMP_SIZE 115200
  1018. #define HFI_BUFFER_PERSIST_MP2D(_size) \
  1019. _size = QMATRIX_SIZE + MP2D_QPDUMP_SIZE;
  1020. /* Begin of IRIS2 Encoder */
  1021. /*
  1022. * Encoder Output Bitstream Buffer definition
  1023. * To match with driver Calculation,
  1024. * the output bitstream = YUV/4 for larger than 4K size.
  1025. */
  1026. #define HFI_BUFFER_BITSTREAM_ENC(size, frame_width, frame_height, \
  1027. rc_type, is_ten_bit) \
  1028. do \
  1029. { \
  1030. HFI_U32 aligned_width, aligned_height, bitstream_size; \
  1031. aligned_width = HFI_ALIGN(frame_width, 32); \
  1032. aligned_height = HFI_ALIGN(frame_height, 32); \
  1033. bitstream_size = aligned_width * aligned_height * 3; \
  1034. if (aligned_width * aligned_height > (4096 * 2176)) \
  1035. { \
  1036. bitstream_size = (bitstream_size >> 3); \
  1037. } \
  1038. else if (bitstream_size > (1280 * 720)) \
  1039. { \
  1040. bitstream_size = (bitstream_size >> 2); \
  1041. } \
  1042. else \
  1043. { \
  1044. bitstream_size = (bitstream_size << 1);\
  1045. } \
  1046. if ((rc_type == HFI_RC_CQ) || (rc_type == HFI_RC_OFF)) \
  1047. { \
  1048. bitstream_size = (bitstream_size << 1);\
  1049. } \
  1050. if (is_ten_bit) \
  1051. { \
  1052. bitstream_size = (bitstream_size) + \
  1053. (bitstream_size >> 2); \
  1054. } \
  1055. size = HFI_ALIGN(bitstream_size, HFI_ALIGNMENT_4096); \
  1056. } while (0)
  1057. #define SIZE_ROI_METADATA_ENC(size_roi, frame_width, frame_height, lcu_size)\
  1058. do \
  1059. { \
  1060. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, n_shift = 0; \
  1061. while (lcu_size && !(lcu_size & 0x1)) \
  1062. { \
  1063. n_shift++; \
  1064. lcu_size = lcu_size >> 1; \
  1065. } \
  1066. width_in_lcus = (frame_width + (lcu_size - 1)) >> n_shift; \
  1067. height_in_lcus = (frame_height + (lcu_size - 1)) >> n_shift; \
  1068. size_roi = (((width_in_lcus + 7) >> 3) << 3) * \
  1069. height_in_lcus * 2 + 256; \
  1070. } while (0)
  1071. /*
  1072. * Encoder Input Extradata Buffer definition
  1073. */
  1074. #define HFI_BUFFER_INPUT_METADATA_ENC(size, frame_width, frame_height, \
  1075. is_roi_enabled, lcu_size) \
  1076. do \
  1077. { \
  1078. HFI_U32 roi_size = 0; \
  1079. if (is_roi_enabled) \
  1080. { \
  1081. SIZE_ROI_METADATA_ENC(roi_size, frame_width, \
  1082. frame_height, lcu_size); \
  1083. } \
  1084. size = roi_size + 16384; \
  1085. size = HFI_ALIGN(size, HFI_ALIGNMENT_4096); \
  1086. } while (0)
  1087. #define HFI_BUFFER_INPUT_METADATA_H264E(size_metadata, frame_width, \
  1088. frame_height, is_roi_enabled) \
  1089. do \
  1090. { \
  1091. HFI_BUFFER_INPUT_METADATA_ENC(size_metadata, frame_width, \
  1092. frame_height, is_roi_enabled, 16); \
  1093. }while (0)
  1094. #define HFI_BUFFER_INPUT_METADATA_H265E(size_metadata, frame_width, \
  1095. frame_height, is_roi_enabled) \
  1096. do \
  1097. { \
  1098. HFI_BUFFER_INPUT_METADATA_ENC(size_metadata, frame_width, \
  1099. frame_height, is_roi_enabled, 32); \
  1100. } while (0)
  1101. #define HFI_BUFFER_ARP_ENC(size) \
  1102. do \
  1103. { \
  1104. size = 204800; \
  1105. } while (0)
  1106. /*
  1107. * Encoder Scratch Buffer definition
  1108. */
  1109. #define HFI_MAX_COL_FRAME 6
  1110. #define HFI_VENUS_VENC_TRE_WB_BUFF_SIZE (65 << 4) // bytes
  1111. #define HFI_VENUS_VENC_DB_LINE_BUFF_PER_MB 512
  1112. #define HFI_VENUS_VPPSG_MAX_REGISTERS 2048
  1113. #define HFI_VENUS_WIDTH_ALIGNMENT 128
  1114. #define HFI_VENUS_WIDTH_TEN_BIT_ALIGNMENT 192
  1115. #define HFI_VENUS_HEIGHT_ALIGNMENT 32
  1116. #define VENUS_METADATA_STRIDE_MULTIPLE 64
  1117. #define VENUS_METADATA_HEIGHT_MULTIPLE 16
  1118. #ifndef SYSTEM_LAL_TILE10
  1119. #define SYSTEM_LAL_TILE10 192
  1120. #endif
  1121. /*
  1122. * Host uses following macro to calculate num_ref for encoder
  1123. * Here: _total_hp_layers = HFI_PROPERTY_PARAM_VENC_HIER_P_MAX_NUM_ENH_LAYER + 1
  1124. * Here: _total_hb_layers = HFI_PROPERTY_PARAM_VENC_HIER_B_MAX_NUM_ENH_LAYER + 1
  1125. */
  1126. #define HFI_IRIS2_ENC_RECON_BUF_COUNT(num_ref, n_bframe, ltr_count, \
  1127. _total_hp_layers, _total_hb_layers, hybrid_hp, codec_standard) \
  1128. do \
  1129. { \
  1130. num_ref = 1; \
  1131. if (n_bframe) \
  1132. num_ref = n_bframe + 1; \
  1133. if (ltr_count) \
  1134. /* B and LTR can't be at same time */\
  1135. num_ref = num_ref + ltr_count; \
  1136. if (_total_hp_layers) \
  1137. { \
  1138. if (hybrid_hp) \
  1139. /* LTR and B-frame not supported with hybrid HP */\
  1140. num_ref = (_total_hp_layers - 1); \
  1141. if (codec_standard == HFI_CODEC_ENCODE_HEVC) \
  1142. num_ref = (_total_hp_layers + 1) / 2 + \
  1143. ltr_count; \
  1144. else if (codec_standard == HFI_CODEC_ENCODE_AVC && \
  1145. _total_hp_layers <= 4) \
  1146. num_ref = (2 ^ (_total_hp_layers - 1)) - 1 + \
  1147. ltr_count; \
  1148. else \
  1149. /* AVC normal HP and TotalHPLayer>4.*/ \
  1150. /* This is NPOR. uses MMCO. */ \
  1151. num_ref = (_total_hp_layers + 1) / 2 + \
  1152. ltr_count; \
  1153. } \
  1154. if (_total_hb_layers >= 2) \
  1155. { \
  1156. num_ref = (2 ^ (_total_hb_layers - 1)) / 2 + 1; \
  1157. } \
  1158. } while (0)
  1159. #define SIZE_BIN_BITSTREAM_ENC(_size, frame_width, frame_height, \
  1160. work_mode, lcu_size) \
  1161. do \
  1162. { \
  1163. HFI_U32 size_aligned_width = 0, size_aligned_height = 0; \
  1164. HFI_U32 bitstream_size_eval = 0; \
  1165. size_aligned_width = HFI_ALIGN((frame_width), lcu_size); \
  1166. size_aligned_height = HFI_ALIGN((frame_height), lcu_size); \
  1167. if (work_mode == HFI_WORKMODE_2) \
  1168. { \
  1169. bitstream_size_eval = (((size_aligned_width) * \
  1170. (size_aligned_height)*3 * 5) >> 2); \
  1171. if (size_aligned_width * size_aligned_height > \
  1172. (4096 * 2176)) \
  1173. { \
  1174. bitstream_size_eval = \
  1175. (bitstream_size_eval >> 3); \
  1176. } \
  1177. else if (bitstream_size_eval > (352 * 288 * 4)) \
  1178. { \
  1179. bitstream_size_eval = \
  1180. (bitstream_size_eval >> 2); \
  1181. } \
  1182. } \
  1183. else \
  1184. { \
  1185. bitstream_size_eval = size_aligned_width * \
  1186. size_aligned_height * 3; \
  1187. } \
  1188. _size = HFI_ALIGN(bitstream_size_eval, VENUS_DMA_ALIGNMENT); \
  1189. } while (0)
  1190. #define SIZE_ENC_SINGLE_PIPE(size, bitbin_size, num_vpp_pipes, \
  1191. frame_height, frame_width) \
  1192. do \
  1193. { \
  1194. HFI_U32 size_single_pipe_eval = 0, sao_bin_buffer_size = 0, \
  1195. _padded_bin_sz = 0; \
  1196. if (num_vpp_pipes > 2) \
  1197. { \
  1198. size_single_pipe_eval = bitbin_size / 2; \
  1199. } \
  1200. else \
  1201. { \
  1202. size_single_pipe_eval = bitbin_size; \
  1203. } \
  1204. size_single_pipe_eval = HFI_ALIGN(size_single_pipe_eval, \
  1205. VENUS_DMA_ALIGNMENT); \
  1206. sao_bin_buffer_size = (64 * ((((frame_width) + \
  1207. BUFFER_ALIGNMENT_32_BYTES) * ((frame_height) +\
  1208. BUFFER_ALIGNMENT_32_BYTES)) >> 10)) + 384; \
  1209. _padded_bin_sz = HFI_ALIGN(size_single_pipe_eval, \
  1210. VENUS_DMA_ALIGNMENT);\
  1211. size_single_pipe_eval = sao_bin_buffer_size + _padded_bin_sz; \
  1212. size_single_pipe_eval = HFI_ALIGN(size_single_pipe_eval, \
  1213. VENUS_DMA_ALIGNMENT); \
  1214. size = size_single_pipe_eval; \
  1215. } while (0)
  1216. #define HFI_BUFFER_BIN_ENC(_size, frame_width, frame_height, lcu_size, \
  1217. work_mode, num_vpp_pipes) \
  1218. do \
  1219. { \
  1220. HFI_U32 bitstream_size = 0, total_bitbin_buffers = 0, \
  1221. size_single_pipe = 0, bitbin_size = 0; \
  1222. SIZE_BIN_BITSTREAM_ENC(bitstream_size, frame_width, \
  1223. frame_height, work_mode, lcu_size); \
  1224. if (work_mode == HFI_WORKMODE_2) \
  1225. { \
  1226. total_bitbin_buffers = 3; \
  1227. bitbin_size = bitstream_size * 17 / 10; \
  1228. bitbin_size = HFI_ALIGN(bitbin_size, \
  1229. VENUS_DMA_ALIGNMENT); \
  1230. } \
  1231. else \
  1232. { \
  1233. total_bitbin_buffers = 1; \
  1234. bitbin_size = bitstream_size; \
  1235. } \
  1236. SIZE_ENC_SINGLE_PIPE(size_single_pipe, bitbin_size, \
  1237. num_vpp_pipes, frame_height, frame_width); \
  1238. bitbin_size = size_single_pipe * num_vpp_pipes; \
  1239. _size = HFI_ALIGN(bitbin_size, VENUS_DMA_ALIGNMENT) * \
  1240. total_bitbin_buffers + 512; \
  1241. } while (0)
  1242. #define HFI_BUFFER_BIN_H264E(_size, frame_width, frame_height, \
  1243. work_mode, num_vpp_pipes) \
  1244. do \
  1245. { \
  1246. HFI_BUFFER_BIN_ENC(_size, frame_width, frame_height, 16, \
  1247. work_mode, num_vpp_pipes); \
  1248. } while (0)
  1249. #define HFI_BUFFER_BIN_H265E(_size, frame_width, frame_height, \
  1250. work_mode, num_vpp_pipes) \
  1251. do \
  1252. { \
  1253. HFI_BUFFER_BIN_ENC(_size, frame_width, frame_height, 32,\
  1254. work_mode, num_vpp_pipes); \
  1255. } while (0)
  1256. #define SIZE_ENC_SLICE_INFO_BUF(num_lcu_in_frame) HFI_ALIGN((256 + \
  1257. (num_lcu_in_frame << 4)), VENUS_DMA_ALIGNMENT)
  1258. #define SIZE_LINE_BUF_CTRL(frame_width_coded) \
  1259. HFI_ALIGN(frame_width_coded, VENUS_DMA_ALIGNMENT)
  1260. #define SIZE_LINE_BUF_CTRL_ID2(frame_width_coded) \
  1261. HFI_ALIGN(frame_width_coded, VENUS_DMA_ALIGNMENT)
  1262. #define SIZE_LINEBUFF_DATA(_size, is_ten_bit, frame_width_coded) \
  1263. do \
  1264. { \
  1265. _size = is_ten_bit ? (((((10 * (frame_width_coded) +\
  1266. 1024) + (VENUS_DMA_ALIGNMENT - 1)) & \
  1267. (~(VENUS_DMA_ALIGNMENT - 1))) * 1) + \
  1268. (((((10 * (frame_width_coded) + 1024) >> 1) + \
  1269. (VENUS_DMA_ALIGNMENT - 1)) & (~(VENUS_DMA_ALIGNMENT - 1))) * \
  1270. 2)) : (((((8 * (frame_width_coded) + 1024) + \
  1271. (VENUS_DMA_ALIGNMENT - 1)) \
  1272. & (~(VENUS_DMA_ALIGNMENT - 1))) * 1) + \
  1273. (((((8 * (frame_width_coded) +\
  1274. 1024) >> 1) + (VENUS_DMA_ALIGNMENT - 1)) & \
  1275. (~(VENUS_DMA_ALIGNMENT - 1))) * 2)); \
  1276. } while (0)
  1277. #define SIZE_LEFT_LINEBUFF_CTRL(_size, standard, frame_height_coded, \
  1278. num_vpp_pipes_enc) \
  1279. do \
  1280. { \
  1281. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? \
  1282. (((frame_height_coded) + \
  1283. (BUF_SIZE_ALIGN_32)) / BUF_SIZE_ALIGN_32 * 4 * 16) : \
  1284. (((frame_height_coded) + 15) / 16 * 5 * 16); \
  1285. if ((num_vpp_pipes_enc) > 1) \
  1286. { \
  1287. _size += BUFFER_ALIGNMENT_512_BYTES; \
  1288. _size = HFI_ALIGN(_size, BUFFER_ALIGNMENT_512_BYTES) *\
  1289. (num_vpp_pipes_enc); \
  1290. } \
  1291. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1292. } while (0)
  1293. #define SIZE_LEFT_LINEBUFF_RECON_PIX(_size, is_ten_bit, frame_height_coded, \
  1294. num_vpp_pipes_enc) \
  1295. do \
  1296. { \
  1297. _size = (((is_ten_bit + 1) * 2 * (frame_height_coded) + \
  1298. VENUS_DMA_ALIGNMENT) + \
  1299. (VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1) & \
  1300. (~((VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1)) * 1; \
  1301. } while (0)
  1302. #define SIZE_TOP_LINEBUFF_CTRL_FE(_size, frame_width_coded, standard) \
  1303. do \
  1304. { \
  1305. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? (64 * \
  1306. ((frame_width_coded) >> 5)) : (VENUS_DMA_ALIGNMENT + 16 * \
  1307. ((frame_width_coded) >> 4)); \
  1308. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1309. } while (0)
  1310. #define SIZE_LEFT_LINEBUFF_CTRL_FE(frame_height_coded, num_vpp_pipes_enc) \
  1311. ((((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) >> 4)) + \
  1312. (VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1) & \
  1313. (~((VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1)) * 1) * \
  1314. num_vpp_pipes_enc)
  1315. #define SIZE_LEFT_LINEBUFF_METADATA_RECON_Y(_size, frame_height_coded, \
  1316. is_ten_bit, num_vpp_pipes_enc) \
  1317. do \
  1318. { \
  1319. _size = ((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) / \
  1320. (8 * (is_ten_bit ? 4 : 8))))); \
  1321. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1322. _size = (_size * num_vpp_pipes_enc); \
  1323. } while (0)
  1324. #define SIZE_LEFT_LINEBUFF_METADATA_RECON_UV(_size, frame_height_coded, \
  1325. is_ten_bit, num_vpp_pipes_enc) \
  1326. do \
  1327. { \
  1328. _size = ((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) / \
  1329. (4 * (is_ten_bit ? 4 : 8))))); \
  1330. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1331. _size = (_size * num_vpp_pipes_enc); \
  1332. } while (0)
  1333. #define SIZE_LINEBUFF_RECON_PIX(_size, is_ten_bit, frame_width_coded) \
  1334. do \
  1335. { \
  1336. _size = ((is_ten_bit ? 3 : 2) * (frame_width_coded)); \
  1337. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1338. } while (0)
  1339. #define SIZE_SLICE_CMD_BUFFER (HFI_ALIGN(20480, VENUS_DMA_ALIGNMENT))
  1340. #define SIZE_SPS_PPS_SLICE_HDR (2048 + 4096)
  1341. #define SIZE_FRAME_RC_BUF_SIZE(_size, standard, frame_height_coded, \
  1342. num_vpp_pipes_enc) \
  1343. do \
  1344. { \
  1345. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? (256 + 16 * \
  1346. (14 + ((((frame_height_coded) >> 5) + 7) >> 3))) : \
  1347. (256 + 16 * (14 + ((((frame_height_coded) >> 4) + 7) >> 3))); \
  1348. _size *= 6; /* multiply by max numtilescol */ \
  1349. if (num_vpp_pipes_enc > 1) \
  1350. { \
  1351. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT) \
  1352. * num_vpp_pipes_enc;\
  1353. } \
  1354. _size = HFI_ALIGN(_size, BUFFER_ALIGNMENT_512_BYTES) * \
  1355. HFI_MAX_COL_FRAME; \
  1356. } while (0)
  1357. #define ENC_BITCNT_BUF_SIZE(num_lcu_in_frame) HFI_ALIGN((256 + \
  1358. (4 * (num_lcu_in_frame))), VENUS_DMA_ALIGNMENT)
  1359. #define ENC_BITMAP_BUF_SIZE(num_lcu_in_frame) HFI_ALIGN((256 + \
  1360. ((num_lcu_in_frame) >> 3)), VENUS_DMA_ALIGNMENT)
  1361. #define SIZE_LINE_BUF_SDE(frame_width_coded) HFI_ALIGN((256 + \
  1362. (16 * ((frame_width_coded) >> 4))), VENUS_DMA_ALIGNMENT)
  1363. #define SIZE_SE_STATS_BUF(_size, frame_width_coded, frame_height_coded, \
  1364. num_lcu_in_frame) \
  1365. do \
  1366. { \
  1367. if (((frame_width_coded) * (frame_height_coded)) > \
  1368. (4096 * 2160)) \
  1369. { \
  1370. _size = 0; \
  1371. } \
  1372. else if (((frame_width_coded) * (frame_height_coded)) > \
  1373. (1920 * 1088)) \
  1374. { \
  1375. _size = (40 * 4 * num_lcu_in_frame + 256 + 256); \
  1376. } \
  1377. else \
  1378. { \
  1379. _size = (1024 * num_lcu_in_frame + 256 + 256); \
  1380. } \
  1381. _size = HFI_ALIGN(se_stats_buf_size, VENUS_DMA_ALIGNMENT) * 2; \
  1382. } while (0)
  1383. #define SIZE_BSE_SLICE_CMD_BUF ((((8192 << 2) + 7) & (~7)) * 6)
  1384. #define SIZE_BSE_REG_BUF ((((512 << 3) + 7) & (~7)) * 4)
  1385. #define SIZE_VPP_REG_BUF ((((HFI_VENUS_VPPSG_MAX_REGISTERS << 3) +\
  1386. 31) & (~31)) * 10)
  1387. #define SIZE_LAMBDA_LUT (256 * 11)
  1388. #define SIZE_OVERRIDE_BUF(num_lcumb) (HFI_ALIGN(((16 * (((num_lcumb) + 7)\
  1389. >> 3))), VENUS_DMA_ALIGNMENT) * 2)
  1390. #define SIZE_IR_BUF(num_lcu_in_frame) (((((num_lcu_in_frame) << 1) + 7) &\
  1391. (~7)) * 3)
  1392. #define SIZE_VPSS_LINE_BUF(num_vpp_pipes_enc, frame_height_coded, \
  1393. frame_width_coded) \
  1394. ((((((8192) >> 2) << 5) * (num_vpp_pipes_enc)) + 64) + \
  1395. (((((MAX((frame_width_coded), (frame_height_coded)) + 3) >> 2) << 5) +\
  1396. 256) * 16))
  1397. #define SIZE_TOP_LINE_BUF_FIRST_STG_SAO(frame_width_coded) \
  1398. HFI_ALIGN((16 * ((frame_width_coded) >> 5)), VENUS_DMA_ALIGNMENT)
  1399. #define HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, is_ten_bit, \
  1400. num_vpp_pipes_enc, lcu_size, standard) \
  1401. do \
  1402. { \
  1403. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, \
  1404. frame_width_coded = 0, frame_height_coded = 0; \
  1405. HFI_U32 line_buff_data_size = 0, left_line_buff_ctrl_size = 0, \
  1406. left_line_buff_recon_pix_size = 0, \
  1407. top_line_buff_ctrl_fe_size = 0; \
  1408. HFI_U32 left_line_buff_metadata_recon__y__size = 0, \
  1409. left_line_buff_metadata_recon__uv__size = 0, \
  1410. line_buff_recon_pix_size = 0; \
  1411. width_in_lcus = ((frame_width) + (lcu_size)-1) / (lcu_size); \
  1412. height_in_lcus = ((frame_height) + (lcu_size)-1) / (lcu_size); \
  1413. frame_width_coded = width_in_lcus * (lcu_size); \
  1414. frame_height_coded = height_in_lcus * (lcu_size); \
  1415. SIZE_LINEBUFF_DATA(line_buff_data_size, is_ten_bit, \
  1416. frame_width_coded);\
  1417. SIZE_LEFT_LINEBUFF_CTRL(left_line_buff_ctrl_size, standard, \
  1418. frame_height_coded, num_vpp_pipes_enc); \
  1419. SIZE_LEFT_LINEBUFF_RECON_PIX(left_line_buff_recon_pix_size, \
  1420. is_ten_bit, frame_height_coded, num_vpp_pipes_enc); \
  1421. SIZE_TOP_LINEBUFF_CTRL_FE(top_line_buff_ctrl_fe_size, \
  1422. frame_width_coded, standard); \
  1423. SIZE_LEFT_LINEBUFF_METADATA_RECON_Y\
  1424. (left_line_buff_metadata_recon__y__size, \
  1425. frame_height_coded, is_ten_bit, num_vpp_pipes_enc); \
  1426. SIZE_LEFT_LINEBUFF_METADATA_RECON_UV\
  1427. (left_line_buff_metadata_recon__uv__size, \
  1428. frame_height_coded, is_ten_bit, num_vpp_pipes_enc); \
  1429. SIZE_LINEBUFF_RECON_PIX(line_buff_recon_pix_size, is_ten_bit,\
  1430. frame_width_coded); \
  1431. _size = SIZE_LINE_BUF_CTRL(frame_width_coded) + \
  1432. SIZE_LINE_BUF_CTRL_ID2(frame_width_coded) + \
  1433. line_buff_data_size + \
  1434. left_line_buff_ctrl_size + \
  1435. left_line_buff_recon_pix_size + \
  1436. top_line_buff_ctrl_fe_size + \
  1437. left_line_buff_metadata_recon__y__size + \
  1438. left_line_buff_metadata_recon__uv__size + \
  1439. line_buff_recon_pix_size + \
  1440. SIZE_LEFT_LINEBUFF_CTRL_FE(frame_height_coded, \
  1441. num_vpp_pipes_enc) + SIZE_LINE_BUF_SDE(frame_width_coded) + \
  1442. SIZE_VPSS_LINE_BUF(num_vpp_pipes_enc, frame_height_coded, \
  1443. frame_width_coded) + \
  1444. SIZE_TOP_LINE_BUF_FIRST_STG_SAO(frame_width_coded); \
  1445. } while (0)
  1446. #define HFI_BUFFER_LINE_H264E(_size, frame_width, frame_height, is_ten_bit, \
  1447. num_vpp_pipes) \
  1448. do \
  1449. { \
  1450. HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, 0, \
  1451. num_vpp_pipes, 16, HFI_CODEC_ENCODE_AVC); \
  1452. } while (0)
  1453. #define HFI_BUFFER_LINE_H265E(_size, frame_width, frame_height, is_ten_bit, \
  1454. num_vpp_pipes) \
  1455. do \
  1456. { \
  1457. HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, \
  1458. is_ten_bit, num_vpp_pipes, 32, HFI_CODEC_ENCODE_HEVC); \
  1459. } while (0)
  1460. #define HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, lcu_size, \
  1461. num_ref, standard) \
  1462. do \
  1463. { \
  1464. HFI_U32 size_colloc_mv = 0, size_colloc_rc = 0; \
  1465. HFI_U32 mb_width = ((frame_width) + 15) >> 4; \
  1466. HFI_U32 mb_height = ((frame_height) + 15) >> 4; \
  1467. HFI_U32 width_in_lcus = ((frame_width) + (lcu_size)-1) /\
  1468. (lcu_size); \
  1469. HFI_U32 height_in_lcus = ((frame_height) + (lcu_size)-1) / \
  1470. (lcu_size); \
  1471. HFI_U32 num_lcu_in_frame = width_in_lcus * height_in_lcus; \
  1472. size_colloc_mv = (standard == HFI_CODEC_ENCODE_HEVC) ? \
  1473. (16 * ((num_lcu_in_frame << 2) + BUFFER_ALIGNMENT_32_BYTES)) : \
  1474. (3 * 16 * (width_in_lcus * height_in_lcus +\
  1475. BUFFER_ALIGNMENT_32_BYTES)); \
  1476. size_colloc_mv = HFI_ALIGN(size_colloc_mv, \
  1477. VENUS_DMA_ALIGNMENT) * (num_ref + 1); \
  1478. size_colloc_rc = (((mb_width + 7) >> 3) * 16 * 2 * mb_height); \
  1479. size_colloc_rc = HFI_ALIGN(size_colloc_rc, \
  1480. VENUS_DMA_ALIGNMENT) * HFI_MAX_COL_FRAME; \
  1481. _size = size_colloc_mv + size_colloc_rc; \
  1482. } while (0)
  1483. #define HFI_BUFFER_COMV_H264E(_size, frame_width, frame_height, num_ref) \
  1484. do \
  1485. { \
  1486. HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, 16, \
  1487. num_ref, HFI_CODEC_ENCODE_AVC); \
  1488. } while (0)
  1489. #define HFI_BUFFER_COMV_H265E(_size, frame_width, frame_height, num_ref) \
  1490. do \
  1491. { \
  1492. HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, 32,\
  1493. num_ref, HFI_CODEC_ENCODE_HEVC); \
  1494. } while (0)
  1495. #define HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1496. num_vpp_pipes_enc, lcu_size, standard) \
  1497. do \
  1498. { \
  1499. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, \
  1500. frame_width_coded = 0, frame_height_coded = 0, \
  1501. num_lcu_in_frame = 0, num_lcumb = 0; \
  1502. HFI_U32 frame_rc_buf_size = 0, \
  1503. se_stats_buf_size = 0; \
  1504. width_in_lcus = ((frame_width) + (lcu_size)-1) / (lcu_size); \
  1505. height_in_lcus = ((frame_height) + (lcu_size)-1) / (lcu_size); \
  1506. num_lcu_in_frame = width_in_lcus * height_in_lcus; \
  1507. frame_width_coded = width_in_lcus * (lcu_size); \
  1508. frame_height_coded = height_in_lcus * (lcu_size); \
  1509. num_lcumb = (frame_height_coded / lcu_size) * \
  1510. ((frame_width_coded + lcu_size * 8) / lcu_size); \
  1511. SIZE_FRAME_RC_BUF_SIZE(frame_rc_buf_size, standard, \
  1512. frame_height_coded, num_vpp_pipes_enc); \
  1513. SIZE_SE_STATS_BUF(se_stats_buf_size, frame_width_coded, \
  1514. frame_height_coded, num_lcu_in_frame); \
  1515. _size = SIZE_ENC_SLICE_INFO_BUF(num_lcu_in_frame) + \
  1516. SIZE_SLICE_CMD_BUFFER + \
  1517. SIZE_SPS_PPS_SLICE_HDR + \
  1518. frame_rc_buf_size + \
  1519. ENC_BITCNT_BUF_SIZE(num_lcu_in_frame) + \
  1520. ENC_BITMAP_BUF_SIZE(num_lcu_in_frame) + \
  1521. se_stats_buf_size + \
  1522. SIZE_BSE_SLICE_CMD_BUF + \
  1523. SIZE_BSE_REG_BUF + \
  1524. SIZE_VPP_REG_BUF + \
  1525. SIZE_LAMBDA_LUT + \
  1526. SIZE_OVERRIDE_BUF(num_lcumb) + \
  1527. SIZE_IR_BUF(num_lcu_in_frame); \
  1528. } while (0)
  1529. #define HFI_BUFFER_NON_COMV_H264E(_size, frame_width, frame_height, \
  1530. num_vpp_pipes_enc) \
  1531. do \
  1532. { \
  1533. HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1534. num_vpp_pipes_enc, 16, HFI_CODEC_ENCODE_AVC); \
  1535. } while (0)
  1536. #define HFI_BUFFER_NON_COMV_H265E(_size, frame_width, frame_height, \
  1537. num_vpp_pipes_enc) \
  1538. do \
  1539. { \
  1540. HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1541. num_vpp_pipes_enc, 32, HFI_CODEC_ENCODE_HEVC); \
  1542. } while (0)
  1543. #define SIZE_ENC_REF_BUFFER(size, frame_width, frame_height) \
  1544. do \
  1545. { \
  1546. HFI_U32 u_buffer_width = 0, u_buffer_height = 0, \
  1547. u_chroma_buffer_height = 0; \
  1548. u_buffer_height = HFI_ALIGN(frame_height, \
  1549. HFI_VENUS_HEIGHT_ALIGNMENT); \
  1550. u_chroma_buffer_height = frame_height >> 1; \
  1551. u_chroma_buffer_height = HFI_ALIGN(u_chroma_buffer_height, \
  1552. HFI_VENUS_HEIGHT_ALIGNMENT); \
  1553. u_buffer_width = HFI_ALIGN(frame_width, \
  1554. HFI_VENUS_WIDTH_ALIGNMENT); \
  1555. size = (u_buffer_height + u_chroma_buffer_height) * \
  1556. u_buffer_width; \
  1557. } while (0)
  1558. #define SIZE_ENC_TEN_BIT_REF_BUFFER(size, frame_width, frame_height) \
  1559. do \
  1560. { \
  1561. HFI_U32 ref_buf_height = 0, ref_luma_stride_in_bytes = 0, \
  1562. u_ref_stride = 0, luma_size = 0, ref_chrm_height_in_bytes = 0, \
  1563. chroma_size = 0, ref_buf_size = 0; \
  1564. ref_buf_height = (frame_height + \
  1565. (HFI_VENUS_HEIGHT_ALIGNMENT - 1)) \
  1566. & (~(HFI_VENUS_HEIGHT_ALIGNMENT - 1)); \
  1567. ref_luma_stride_in_bytes = ((frame_width + \
  1568. SYSTEM_LAL_TILE10 - 1) / SYSTEM_LAL_TILE10) * \
  1569. SYSTEM_LAL_TILE10; \
  1570. u_ref_stride = 4 * (ref_luma_stride_in_bytes / 3); \
  1571. u_ref_stride = (u_ref_stride + (BUF_SIZE_ALIGN_128 - 1)) &\
  1572. (~(BUF_SIZE_ALIGN_128 - 1)); \
  1573. luma_size = ref_buf_height * u_ref_stride; \
  1574. ref_chrm_height_in_bytes = (((frame_height + 1) >> 1) + \
  1575. (BUF_SIZE_ALIGN_32 - 1)) & (~(BUF_SIZE_ALIGN_32 - 1)); \
  1576. chroma_size = u_ref_stride * ref_chrm_height_in_bytes; \
  1577. luma_size = (luma_size + (BUF_SIZE_ALIGN_4096 - 1)) & \
  1578. (~(BUF_SIZE_ALIGN_4096 - 1)); \
  1579. chroma_size = (chroma_size + (BUF_SIZE_ALIGN_4096 - 1)) & \
  1580. (~(BUF_SIZE_ALIGN_4096 - 1)); \
  1581. ref_buf_size = luma_size + chroma_size; \
  1582. size = ref_buf_size; \
  1583. } while (0)
  1584. /*
  1585. * Encoder Scratch2 Buffer definition
  1586. */
  1587. #define HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, is_ten_bit) \
  1588. do \
  1589. { \
  1590. HFI_U32 metadata_stride, metadata_buf_height, meta_size_y, \
  1591. meta_size_c; \
  1592. HFI_U32 ten_bit_ref_buf_size = 0, ref_buf_size = 0; \
  1593. if (!is_ten_bit) \
  1594. { \
  1595. SIZE_ENC_REF_BUFFER(ref_buf_size, frame_width, \
  1596. frame_height); \
  1597. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, \
  1598. (frame_width), 64, \
  1599. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH); \
  1600. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, \
  1601. (frame_height), 16, \
  1602. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT); \
  1603. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_y, \
  1604. metadata_stride, metadata_buf_height); \
  1605. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_c, \
  1606. metadata_stride, metadata_buf_height); \
  1607. _size = ref_buf_size + meta_size_y + meta_size_c; \
  1608. } \
  1609. else \
  1610. { \
  1611. SIZE_ENC_TEN_BIT_REF_BUFFER(ten_bit_ref_buf_size, \
  1612. frame_width, frame_height); \
  1613. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, \
  1614. frame_width, VENUS_METADATA_STRIDE_MULTIPLE, \
  1615. HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_WIDTH); \
  1616. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, \
  1617. frame_height, VENUS_METADATA_HEIGHT_MULTIPLE, \
  1618. HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_HEIGHT); \
  1619. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_y, \
  1620. metadata_stride, metadata_buf_height); \
  1621. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_c, \
  1622. metadata_stride, metadata_buf_height); \
  1623. _size = ten_bit_ref_buf_size + meta_size_y + \
  1624. meta_size_c; \
  1625. } \
  1626. } while (0)
  1627. #define HFI_BUFFER_DPB_H264E(_size, frame_width, frame_height) \
  1628. do \
  1629. { \
  1630. HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, 0); \
  1631. } while (0)
  1632. #define HFI_BUFFER_DPB_H265E(_size, frame_width, frame_height, is_ten_bit) \
  1633. do \
  1634. { \
  1635. HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, is_ten_bit); \
  1636. } while (0)
  1637. #define HFI_BUFFER_VPSS_ENC(vpss_size, frame_width, frame_height, ds_enable, \
  1638. rot_enable, flip_enable, is_ten_bit) \
  1639. do \
  1640. { \
  1641. HFI_U32 vpss_size = 0; \
  1642. if (ds_enable) \
  1643. { \
  1644. if (rot_enable) \
  1645. { \
  1646. HFI_BUFFER_DPB_ENC(vpss_size, frame_height, \
  1647. frame_width, is_ten_bit); \
  1648. } \
  1649. else if (flip_enable) \
  1650. { \
  1651. HFI_BUFFER_DPB_ENC(vpss_size, frame_width, \
  1652. frame_height, is_ten_bit); \
  1653. } \
  1654. else \
  1655. { \
  1656. vpss_size = 0; \
  1657. } \
  1658. vpss_size = vpss_size; \
  1659. } \
  1660. else \
  1661. { \
  1662. vpss_size = vpss_size; \
  1663. } \
  1664. } while (0)
  1665. /* End of IRIS2 */
  1666. #endif /* __HFI_BUFFER_IRIS2__ */