hfi_buffer_iris2.h 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021,, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __HFI_BUFFER_IRIS2__
  7. #define __HFI_BUFFER_IRIS2__
  8. #include <linux/types.h>
  9. #include "hfi_property.h"
  10. typedef u8 HFI_U8;
  11. typedef s8 HFI_S8;
  12. typedef u16 HFI_U16;
  13. typedef s16 HFI_S16;
  14. typedef u32 HFI_U32;
  15. typedef s32 HFI_S32;
  16. typedef u64 HFI_U64;
  17. typedef HFI_U32 HFI_BOOL;
  18. #ifndef MIN
  19. #define MIN(x, y) (((x) < (y)) ? (x) : (y))
  20. #endif
  21. #ifndef MAX
  22. #define MAX(x, y) (((x) > (y)) ? (x) : (y))
  23. #endif
  24. #define HFI_ALIGNMENT_4096 (4096)
  25. #define BUF_SIZE_ALIGN_16 (16)
  26. #define BUF_SIZE_ALIGN_32 (32)
  27. #define BUF_SIZE_ALIGN_64 (64)
  28. #define BUF_SIZE_ALIGN_128 (128)
  29. #define BUF_SIZE_ALIGN_256 (256)
  30. #define BUF_SIZE_ALIGN_512 (512)
  31. #define BUF_SIZE_ALIGN_4096 (4096)
  32. #define HFI_ALIGN(a, b) (((b) & ((b) - 1)) ? (((a) + (b) - 1) / \
  33. (b) * (b)) : (((a) + (b) - 1) & (~((b) - 1))))
  34. #define HFI_WORKMODE_1 1
  35. #define HFI_WORKMODE_2 2
  36. #define HFI_DEFAULT_METADATA_STRIDE_MULTIPLE (64)
  37. #define HFI_DEFAULT_METADATA_BUFFERHEIGHT_MULTIPLE (16)
  38. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT (8)
  39. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH (32)
  40. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_HEIGHT (8)
  41. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_WIDTH (16)
  42. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_HEIGHT (4)
  43. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_WIDTH (48)
  44. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_UV_TILE_HEIGHT (4)
  45. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_UV_TILE_WIDTH (24)
  46. #define HFI_COLOR_FORMAT_RGBA8888_UBWC_TILE_HEIGHT (4)
  47. #define HFI_COLOR_FORMAT_RGBA8888_UBWC_TILE_WIDTH (16)
  48. #define HFI_NV12_IL_CALC_Y_STRIDE(stride, frame_width, stride_multiple) \
  49. (stride = HFI_ALIGN(frame_width, stride_multiple))
  50. #define HFI_NV12_IL_CALC_Y_BUFHEIGHT(buf_height, frame_height, \
  51. min_buf_height_multiple) (buf_height = HFI_ALIGN(frame_height, \
  52. min_buf_height_multiple))
  53. #define HFI_NV12_IL_CALC_UV_STRIDE(stride, frame_width, stride_multiple) \
  54. (stride = HFI_ALIGN(frame_width, stride_multiple))
  55. #define HFI_NV12_IL_CALC_UV_BUFHEIGHT(buf_height, frame_height, \
  56. min_buf_height_multiple) (buf_height = HFI_ALIGN(((frame_height + 1) \
  57. >> 1), min_buf_height_multiple))
  58. #define HFI_NV12_IL_CALC_BUF_SIZE(buf_size, y_bufSize, y_stride, y_buf_height, \
  59. uv_buf_size, uv_stride, uv_buf_height) \
  60. do { \
  61. y_bufSize = (y_stride * y_buf_height); \
  62. uv_buf_size = (uv_stride * uv_buf_height); \
  63. buf_size = HFI_ALIGN(y_bufSize + uv_buf_size, HFI_ALIGNMENT_4096) \
  64. } while (0)
  65. #define HFI_NV12_UBWC_IL_CALC_Y_BUF_SIZE(y_bufSize, y_stride, y_buf_height) \
  66. (y_bufSize = HFI_ALIGN(y_stride * y_buf_height, HFI_ALIGNMENT_4096))
  67. #define HFI_NV12_UBWC_IL_CALC_UV_BUF_SIZE(uv_buf_size, \
  68. uv_stride, uv_buf_height) \
  69. (uv_buf_size = HFI_ALIGN(uv_stride * uv_buf_height, HFI_ALIGNMENT_4096))
  70. #define HFI_NV12_UBWC_IL_CALC_BUF_SIZE_V2(buf_size,\
  71. frame_width, frame_height, y_stride_multiple,\
  72. y_buffer_height_multiple, uv_stride_multiple, \
  73. uv_buffer_height_multiple, y_metadata_stride_multiple, \
  74. y_metadata_buffer_height_multiple, \
  75. uv_metadata_stride_multiple, uv_metadata_buffer_height_multiple) \
  76. do { \
  77. HFI_U32 y_buf_size, uv_buf_size, y_meta_size, uv_meta_size; \
  78. HFI_U32 stride, _height; \
  79. HFI_U32 half_height = (frame_height + 1) >> 1; \
  80. HFI_NV12_IL_CALC_Y_STRIDE(stride, frame_width,\
  81. y_stride_multiple); \
  82. HFI_NV12_IL_CALC_Y_BUFHEIGHT(_height, half_height,\
  83. y_buffer_height_multiple); \
  84. HFI_NV12_UBWC_IL_CALC_Y_BUF_SIZE(y_buf_size, stride, _height);\
  85. HFI_NV12_IL_CALC_UV_STRIDE(stride, frame_width, \
  86. uv_stride_multiple); \
  87. HFI_NV12_IL_CALC_UV_BUFHEIGHT(_height, half_height, \
  88. uv_buffer_height_multiple); \
  89. HFI_NV12_UBWC_IL_CALC_UV_BUF_SIZE(uv_buf_size, stride, _height);\
  90. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(stride, frame_width,\
  91. y_metadata_stride_multiple, \
  92. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH);\
  93. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(_height, half_height, \
  94. y_metadata_buffer_height_multiple,\
  95. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT);\
  96. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(y_meta_size, stride, \
  97. _height); \
  98. HFI_UBWC_UV_METADATA_PLANE_STRIDE(stride, frame_width,\
  99. uv_metadata_stride_multiple, \
  100. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_WIDTH); \
  101. HFI_UBWC_UV_METADATA_PLANE_BUFHEIGHT(_height, half_height,\
  102. uv_metadata_buffer_height_multiple,\
  103. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_HEIGHT);\
  104. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(uv_meta_size, stride, \
  105. _height); \
  106. buf_size = (y_buf_size + uv_buf_size + y_meta_size + \
  107. uv_meta_size) << 1;\
  108. } while (0)
  109. #define HFI_YUV420_TP10_CALC_Y_STRIDE(stride, frame_width, stride_multiple) \
  110. do { \
  111. stride = HFI_ALIGN(frame_width, 192); \
  112. stride = HFI_ALIGN(stride * 4 / 3, stride_multiple) \
  113. } while (0)
  114. #define HFI_YUV420_TP10_CALC_Y_BUFHEIGHT(buf_height, frame_height, \
  115. min_buf_height_multiple) \
  116. (buf_height = HFI_ALIGN(frame_height, min_buf_height_multiple))
  117. #define HFI_YUV420_TP10_CALC_UV_STRIDE(stride, frame_width, stride_multiple) \
  118. do { \
  119. stride = HFI_ALIGN(frame_width, 192); \
  120. stride = HFI_ALIGN(stride * 4 / 3, stride_multiple); \
  121. } while (0)
  122. #define HFI_YUV420_TP10_CALC_UV_BUFHEIGHT(buf_height, frame_height, \
  123. min_buf_height_multiple) \
  124. (buf_height = HFI_ALIGN(((frame_height + 1) >> 1), \
  125. min_buf_height_multiple))
  126. #define HFI_YUV420_TP10_CALC_BUF_SIZE(buf_size, y_buf_size, y_stride,\
  127. y_buf_height, uv_buf_size, uv_stride, uv_buf_height) \
  128. do { \
  129. y_buf_size = (y_stride * y_buf_height); \
  130. uv_buf_size = (uv_stride * uv_buf_height); \
  131. buf_size = y_buf_size + uv_buf_size \
  132. } while (0)
  133. #define HFI_YUV420_TP10_UBWC_CALC_Y_BUF_SIZE(y_buf_size, y_stride, \
  134. y_buf_height) \
  135. (y_buf_size = HFI_ALIGN(y_stride * y_buf_height, HFI_ALIGNMENT_4096))
  136. #define HFI_YUV420_TP10_UBWC_CALC_UV_BUF_SIZE(uv_buf_size, uv_stride, \
  137. uv_buf_height) \
  138. (uv_buf_size = HFI_ALIGN(uv_stride * uv_buf_height, HFI_ALIGNMENT_4096))
  139. #define HFI_YUV420_TP10_UBWC_CALC_BUF_SIZE(buf_size, y_stride, y_buf_height, \
  140. uv_stride, uv_buf_height, y_md_stride, y_md_height, uv_md_stride, \
  141. uv_md_height)\
  142. do { \
  143. HFI_U32 y_data_size, uv_data_size, y_md_size, uv_md_size; \
  144. HFI_YUV420_TP10_UBWC_CALC_Y_BUF_SIZE(y_data_size, y_stride,\
  145. y_buf_height); \
  146. HFI_YUV420_TP10_UBWC_CALC_UV_BUF_SIZE(uv_data_size, uv_stride, \
  147. uv_buf_height); \
  148. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(y_md_size, y_md_stride, \
  149. y_md_height); \
  150. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(uv_md_size, uv_md_stride, \
  151. uv_md_height); \
  152. buf_size = y_data_size + uv_data_size + y_md_size + \
  153. uv_md_size; \
  154. } while (0)
  155. #define HFI_YUV420_P010_CALC_Y_STRIDE(stride, frame_width, stride_multiple) \
  156. (stride = HFI_ALIGN(frame_width * 2, stride_multiple))
  157. #define HFI_YUV420_P010_CALC_Y_BUFHEIGHT(buf_height, frame_height, \
  158. min_buf_height_multiple) \
  159. (buf_height = HFI_ALIGN(frame_height, min_buf_height_multiple))
  160. #define HFI_YUV420_P010_CALC_UV_STRIDE(stride, frame_width, stride_multiple) \
  161. (stride = HFI_ALIGN(frame_width * 2, stride_multiple))
  162. #define HFI_YUV420_P010_CALC_UV_BUFHEIGHT(buf_height, frame_height, \
  163. min_buf_height_multiple) \
  164. (buf_height = HFI_ALIGN(((frame_height + 1) >> 1), \
  165. min_buf_height_multiple))
  166. #define HFI_YUV420_P010_CALC_BUF_SIZE(buf_size, y_data_size, y_stride, \
  167. y_buf_height, uv_data_size, uv_stride, uv_buf_height) \
  168. do { \
  169. y_data_size = HFI_ALIGN(y_stride * y_buf_height, \
  170. HFI_ALIGNMENT_4096);\
  171. uv_data_size = HFI_ALIGN(uv_stride * uv_buf_height, \
  172. HFI_ALIGNMENT_4096); \
  173. buf_size = y_data_size + uv_data_size; \
  174. } while (0)
  175. #define HFI_RGB888_CALC_STRIDE(stride, frame_width, stride_multiple) \
  176. (stride = ((frame_width * 3) + stride_multiple - 1) & \
  177. (0xffffffff - (stride_multiple - 1)))
  178. #define HFI_RGB888_CALC_BUFHEIGHT(buf_height, frame_height, \
  179. min_buf_height_multiple) \
  180. (buf_height = ((frame_height + min_buf_height_multiple - 1) & \
  181. (0xffffffff - (min_buf_height_multiple - 1))))
  182. #define HFI_RGB888_CALC_BUF_SIZE(buf_size, stride, buf_height) \
  183. (buf_size = ((stride) * (buf_height)))
  184. #define HFI_RGBA8888_CALC_STRIDE(stride, frame_width, stride_multiple) \
  185. (stride = HFI_ALIGN((frame_width << 2), stride_multiple))
  186. #define HFI_RGBA8888_CALC_BUFHEIGHT(buf_height, frame_height, \
  187. min_buf_height_multiple) \
  188. (buf_height = HFI_ALIGN(frame_height, min_buf_height_multiple))
  189. #define HFI_RGBA8888_CALC_BUF_SIZE(buf_size, stride, buf_height) \
  190. (buf_size = (stride) * (buf_height))
  191. #define HFI_RGBA8888_UBWC_CALC_DATA_PLANE_BUF_SIZE(buf_size, stride, \
  192. buf_height) \
  193. (buf_size = HFI_ALIGN((stride) * (buf_height), HFI_ALIGNMENT_4096))
  194. #define HFI_RGBA8888_UBWC_BUF_SIZE(buf_size, data_buf_size, \
  195. metadata_buffer_size, stride, buf_height, _metadata_tride, \
  196. _metadata_buf_height) \
  197. do { \
  198. HFI_RGBA8888_UBWC_CALC_DATA_PLANE_BUF_SIZE(data_buf_size, \
  199. stride, buf_height); \
  200. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(metadata_buffer_size, \
  201. _metadata_tride, _metadata_buf_height); \
  202. buf_size = data_buf_size + metadata_buffer_size \
  203. } while (0)
  204. #define HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, frame_width,\
  205. metadata_stride_multiple, tile_width_in_pels) \
  206. (metadata_stride = HFI_ALIGN(((frame_width + (tile_width_in_pels - 1)) /\
  207. tile_width_in_pels), metadata_stride_multiple))
  208. #define HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, frame_height, \
  209. metadata_height_multiple, tile_height_in_pels) \
  210. (metadata_buf_height = HFI_ALIGN(((frame_height + \
  211. (tile_height_in_pels - 1)) / tile_height_in_pels), \
  212. metadata_height_multiple))
  213. #define HFI_UBWC_UV_METADATA_PLANE_STRIDE(metadata_stride, frame_width, \
  214. metadata_stride_multiple, tile_width_in_pels) \
  215. (metadata_stride = HFI_ALIGN(((((frame_width + 1) >> 1) +\
  216. (tile_width_in_pels - 1)) / tile_width_in_pels), \
  217. metadata_stride_multiple))
  218. #define HFI_UBWC_UV_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, frame_height,\
  219. metadata_height_multiple, tile_height_in_pels) \
  220. (metadata_buf_height = HFI_ALIGN(((((frame_height + 1) >> 1) + \
  221. (tile_height_in_pels - 1)) / tile_height_in_pels), \
  222. metadata_height_multiple))
  223. #define HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(buffer_size, _metadata_tride, \
  224. _metadata_buf_height) \
  225. (buffer_size = HFI_ALIGN(_metadata_tride * _metadata_buf_height, \
  226. HFI_ALIGNMENT_4096))
  227. #define BUFFER_ALIGNMENT_512_BYTES 512
  228. #define BUFFER_ALIGNMENT_256_BYTES 256
  229. #define BUFFER_ALIGNMENT_128_BYTES 128
  230. #define BUFFER_ALIGNMENT_64_BYTES 64
  231. #define BUFFER_ALIGNMENT_32_BYTES 32
  232. #define BUFFER_ALIGNMENT_16_BYTES 16
  233. #define BUFFER_ALIGNMENT_8_BYTES 8
  234. #define BUFFER_ALIGNMENT_4_BYTES 4
  235. #define VENUS_DMA_ALIGNMENT BUFFER_ALIGNMENT_256_BYTES
  236. #define MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE 64
  237. #define MAX_FE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE 64
  238. #define MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE 64
  239. #define MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE 640
  240. #define MAX_FE_NBR_DATA_CB_LINE_BUFFER_SIZE 320
  241. #define MAX_FE_NBR_DATA_CR_LINE_BUFFER_SIZE 320
  242. #define MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE (128 / 8)
  243. #define MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE (128 / 8)
  244. #define MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE (128 / 8)
  245. #define MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE (64 * 2 * 3)
  246. #define MAX_PE_NBR_DATA_LCU32_LINE_BUFFER_SIZE (32 * 2 * 3)
  247. #define MAX_PE_NBR_DATA_LCU16_LINE_BUFFER_SIZE (16 * 2 * 3)
  248. #define MAX_TILE_COLUMNS 32
  249. #define SIZE_VPSS_LB(Size, frame_width, frame_height, num_vpp_pipes) \
  250. do { \
  251. HFI_U32 vpss_4tap_top_buffer_size, vpss_div2_top_buffer_size, \
  252. vpss_4tap_left_buffer_size, vpss_div2_left_buffer_size; \
  253. HFI_U32 opb_wr_top_line_luma_buffer_size, \
  254. opb_wr_top_line_chroma_buffer_size, \
  255. opb_lb_wr_llb_y_buffer_size,\
  256. opb_lb_wr_llb_uv_buffer_size; \
  257. HFI_U32 macrotiling_size; \
  258. vpss_4tap_top_buffer_size = vpss_div2_top_buffer_size = \
  259. vpss_4tap_left_buffer_size = vpss_div2_left_buffer_size = 0; \
  260. macrotiling_size = 32; \
  261. opb_wr_top_line_luma_buffer_size = HFI_ALIGN(frame_width, \
  262. macrotiling_size) / macrotiling_size * 256; \
  263. opb_wr_top_line_luma_buffer_size = \
  264. HFI_ALIGN(opb_wr_top_line_luma_buffer_size, \
  265. VENUS_DMA_ALIGNMENT) + (MAX_TILE_COLUMNS - 1) * 256; \
  266. opb_wr_top_line_luma_buffer_size = \
  267. MAX(opb_wr_top_line_luma_buffer_size, (32 * \
  268. HFI_ALIGN(frame_height, 8))); \
  269. opb_wr_top_line_chroma_buffer_size = \
  270. opb_wr_top_line_luma_buffer_size;\
  271. opb_lb_wr_llb_uv_buffer_size = opb_lb_wr_llb_y_buffer_size = \
  272. HFI_ALIGN((HFI_ALIGN(frame_height, 8) / (4 / 2)) * 64,\
  273. BUFFER_ALIGNMENT_32_BYTES); \
  274. Size = num_vpp_pipes * 2 * (vpss_4tap_top_buffer_size + \
  275. vpss_div2_top_buffer_size) + \
  276. 2 * (vpss_4tap_left_buffer_size + \
  277. vpss_div2_left_buffer_size) + \
  278. opb_wr_top_line_luma_buffer_size + \
  279. opb_wr_top_line_chroma_buffer_size + \
  280. opb_lb_wr_llb_uv_buffer_size + \
  281. opb_lb_wr_llb_y_buffer_size; \
  282. } while (0)
  283. #define VPP_CMD_MAX_SIZE (1 << 20)
  284. #define NUM_HW_PIC_BUF 32
  285. #define BIN_BUFFER_THRESHOLD (1280 * 736)
  286. #define H264D_MAX_SLICE 1800
  287. #define SIZE_H264D_BUFTAB_T (256)
  288. #define SIZE_H264D_HW_PIC_T (1 << 11)
  289. #define SIZE_H264D_BSE_CMD_PER_BUF (32 * 4)
  290. #define SIZE_H264D_VPP_CMD_PER_BUF (512)
  291. #define SIZE_H264D_LB_FE_TOP_DATA(frame_width, frame_height) \
  292. (MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE * HFI_ALIGN(frame_width, 16) * 3)
  293. #define SIZE_H264D_LB_FE_TOP_CTRL(frame_width, frame_height) \
  294. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_width + 15) >> 4))
  295. #define SIZE_H264D_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  296. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_height + 15) >> 4))
  297. #define SIZE_H264D_LB_SE_TOP_CTRL(frame_width, frame_height) \
  298. (MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_width + 15) >> 4))
  299. #define SIZE_H264D_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  300. (MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_height + 15) >> 4))
  301. #define SIZE_H264D_LB_PE_TOP_DATA(frame_width, frame_height) \
  302. (MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE * ((frame_width + 15) >> 4))
  303. #define SIZE_H264D_LB_VSP_TOP(frame_width, frame_height) \
  304. ((((frame_width + 15) >> 4) << 7))
  305. #define SIZE_H264D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  306. (HFI_ALIGN(frame_height, 16) * 32)
  307. #define SIZE_H264D_QP(frame_width, frame_height) \
  308. (((frame_width + 63) >> 6) * ((frame_height + 63) >> 6) * 128)
  309. #define SIZE_HW_PIC(size_per_buf) \
  310. (NUM_HW_PIC_BUF * size_per_buf)
  311. #define SIZE_H264D_BSE_CMD_BUF(_size, frame_width, frame_height) \
  312. do { \
  313. HFI_U32 _height = HFI_ALIGN(frame_height, \
  314. BUFFER_ALIGNMENT_32_BYTES); \
  315. _size = MIN((((_height + 15) >> 4) * 48), H264D_MAX_SLICE) *\
  316. SIZE_H264D_BSE_CMD_PER_BUF; \
  317. } while (0)
  318. #define SIZE_H264D_VPP_CMD_BUF(_size, frame_width, frame_height) \
  319. do { \
  320. HFI_U32 _height = HFI_ALIGN(frame_height, \
  321. BUFFER_ALIGNMENT_32_BYTES); \
  322. _size = MIN((((_height + 15) >> 4) * 48), H264D_MAX_SLICE) * \
  323. SIZE_H264D_VPP_CMD_PER_BUF; \
  324. if (_size > VPP_CMD_MAX_SIZE) { _size = VPP_CMD_MAX_SIZE; } \
  325. } while (0)
  326. #define HFI_BUFFER_COMV_H264D(coMV_size, frame_width, \
  327. frame_height, _yuv_bufcount_min) \
  328. do { \
  329. HFI_U32 frame_width_in_mbs = ((frame_width + 15) >> 4); \
  330. HFI_U32 frame_height_in_mbs = ((frame_height + 15) >> 4); \
  331. HFI_U32 col_mv_aligned_width = (frame_width_in_mbs << 7); \
  332. HFI_U32 col_zero_aligned_width = (frame_width_in_mbs << 2); \
  333. HFI_U32 col_zero_size = 0, size_colloc = 0; \
  334. col_mv_aligned_width = HFI_ALIGN(col_mv_aligned_width, \
  335. BUFFER_ALIGNMENT_16_BYTES); \
  336. col_zero_aligned_width = HFI_ALIGN(col_zero_aligned_width, \
  337. BUFFER_ALIGNMENT_16_BYTES); \
  338. col_zero_size = col_zero_aligned_width * \
  339. ((frame_height_in_mbs + 1) >> 1); \
  340. col_zero_size = HFI_ALIGN(col_zero_size, \
  341. BUFFER_ALIGNMENT_64_BYTES); \
  342. col_zero_size <<= 1; \
  343. col_zero_size = HFI_ALIGN(col_zero_size, \
  344. BUFFER_ALIGNMENT_512_BYTES); \
  345. size_colloc = col_mv_aligned_width * ((frame_height_in_mbs + \
  346. 1) >> 1); \
  347. size_colloc = HFI_ALIGN(size_colloc, \
  348. BUFFER_ALIGNMENT_64_BYTES); \
  349. size_colloc <<= 1; \
  350. size_colloc = HFI_ALIGN(size_colloc, \
  351. BUFFER_ALIGNMENT_512_BYTES); \
  352. size_colloc += (col_zero_size + SIZE_H264D_BUFTAB_T * 2); \
  353. coMV_size = size_colloc * (_yuv_bufcount_min); \
  354. coMV_size += BUFFER_ALIGNMENT_512_BYTES; \
  355. } while (0)
  356. #define HFI_BUFFER_NON_COMV_H264D(_size, frame_width, frame_height, \
  357. num_vpp_pipes) \
  358. do { \
  359. HFI_U32 _size_bse, _size_vpp; \
  360. SIZE_H264D_BSE_CMD_BUF(_size_bse, frame_width, frame_height); \
  361. SIZE_H264D_VPP_CMD_BUF(_size_vpp, frame_width, frame_height); \
  362. _size = HFI_ALIGN(_size_bse, VENUS_DMA_ALIGNMENT) + \
  363. HFI_ALIGN(_size_vpp, VENUS_DMA_ALIGNMENT) + \
  364. HFI_ALIGN(SIZE_HW_PIC(SIZE_H264D_HW_PIC_T), \
  365. VENUS_DMA_ALIGNMENT); \
  366. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  367. } while (0)
  368. #define HFI_BUFFER_LINE_H264D(_size, frame_width, frame_height, \
  369. is_opb, num_vpp_pipes) \
  370. do { \
  371. HFI_U32 vpss_lb_size = 0; \
  372. _size = HFI_ALIGN(SIZE_H264D_LB_FE_TOP_DATA(frame_width, \
  373. frame_height), VENUS_DMA_ALIGNMENT) + \
  374. HFI_ALIGN(SIZE_H264D_LB_FE_TOP_CTRL(frame_width, \
  375. frame_height), VENUS_DMA_ALIGNMENT) + \
  376. HFI_ALIGN(SIZE_H264D_LB_FE_LEFT_CTRL(frame_width, \
  377. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  378. HFI_ALIGN(SIZE_H264D_LB_SE_TOP_CTRL(frame_width, \
  379. frame_height), VENUS_DMA_ALIGNMENT) + \
  380. HFI_ALIGN(SIZE_H264D_LB_SE_LEFT_CTRL(frame_width, \
  381. frame_height), VENUS_DMA_ALIGNMENT) * \
  382. num_vpp_pipes + \
  383. HFI_ALIGN(SIZE_H264D_LB_PE_TOP_DATA(frame_width, \
  384. frame_height), VENUS_DMA_ALIGNMENT) + \
  385. HFI_ALIGN(SIZE_H264D_LB_VSP_TOP(frame_width, \
  386. frame_height), VENUS_DMA_ALIGNMENT) + \
  387. HFI_ALIGN(SIZE_H264D_LB_RECON_DMA_METADATA_WR\
  388. (frame_width, frame_height), \
  389. VENUS_DMA_ALIGNMENT) * 2 + HFI_ALIGN(SIZE_H264D_QP\
  390. (frame_width, frame_height), VENUS_DMA_ALIGNMENT); \
  391. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  392. if (is_opb) { \
  393. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  394. num_vpp_pipes); \
  395. } \
  396. _size = HFI_ALIGN((_size + vpss_lb_size), \
  397. VENUS_DMA_ALIGNMENT); \
  398. } while (0)
  399. #define H264_CABAC_HDR_RATIO_HD_TOT 1
  400. #define H264_CABAC_RES_RATIO_HD_TOT 3
  401. #define SIZE_H264D_HW_BIN_BUFFER(_size, frame_width, frame_height, \
  402. delay, num_vpp_pipes) \
  403. do { \
  404. HFI_U32 size_yuv, size_bin_hdr, size_bin_res; \
  405. size_yuv = ((frame_width * frame_height) <= \
  406. BIN_BUFFER_THRESHOLD) ?\
  407. ((BIN_BUFFER_THRESHOLD * 3) >> 1) : \
  408. ((frame_width * frame_height * 3) >> 1); \
  409. size_bin_hdr = size_yuv * H264_CABAC_HDR_RATIO_HD_TOT; \
  410. size_bin_res = size_yuv * H264_CABAC_RES_RATIO_HD_TOT; \
  411. size_bin_hdr = size_bin_hdr * (((((HFI_U32)(delay)) & 31) /\
  412. 10) + 2) / 2; \
  413. size_bin_res = size_bin_res * (((((HFI_U32)(delay)) & 31) /\
  414. 10) + 2) / 2; \
  415. size_bin_hdr = HFI_ALIGN(size_bin_hdr / num_vpp_pipes,\
  416. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  417. size_bin_res = HFI_ALIGN(size_bin_res / num_vpp_pipes, \
  418. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  419. _size = size_bin_hdr + size_bin_res; \
  420. } while (0)
  421. #define HFI_BUFFER_BIN_H264D(_size, frame_width, frame_height, is_interlaced, \
  422. delay, num_vpp_pipes) \
  423. do { \
  424. HFI_U32 n_aligned_w = HFI_ALIGN(frame_width, \
  425. BUFFER_ALIGNMENT_16_BYTES);\
  426. HFI_U32 n_aligned_h = HFI_ALIGN(frame_height, \
  427. BUFFER_ALIGNMENT_16_BYTES); \
  428. if (!is_interlaced) { \
  429. SIZE_H264D_HW_BIN_BUFFER(_size, n_aligned_w, \
  430. n_aligned_h, delay, num_vpp_pipes); \
  431. } else { \
  432. _size = 0; \
  433. } \
  434. } while (0)
  435. #define NUM_SLIST_BUF_H264 (256 + 32)
  436. #define SIZE_SLIST_BUF_H264 (512)
  437. #define SIZE_SEI_USERDATA (4096)
  438. #define H264_NUM_FRM_INFO (66)
  439. #define H264_DISPLAY_BUF_SIZE (3328)
  440. #define SIZE_DOLBY_RPU_METADATA (41 * 1024)
  441. #define HFI_BUFFER_PERSIST_H264D(_size, rpu_enabled) \
  442. (_size = HFI_ALIGN((SIZE_SLIST_BUF_H264 * NUM_SLIST_BUF_H264 + \
  443. H264_DISPLAY_BUF_SIZE * H264_NUM_FRM_INFO + \
  444. NUM_HW_PIC_BUF * SIZE_SEI_USERDATA + \
  445. (rpu_enabled) * NUM_HW_PIC_BUF * SIZE_DOLBY_RPU_METADATA), \
  446. VENUS_DMA_ALIGNMENT))
  447. #define LCU_MAX_SIZE_PELS 64
  448. #define LCU_MIN_SIZE_PELS 16
  449. #define H265D_MAX_SLICE 1200
  450. #define SIZE_H265D_HW_PIC_T SIZE_H264D_HW_PIC_T
  451. #define SIZE_H265D_BSE_CMD_PER_BUF (16 * sizeof(HFI_U32))
  452. #define SIZE_H265D_VPP_CMD_PER_BUF (256)
  453. #define SIZE_H265D_LB_FE_TOP_DATA(frame_width, frame_height) \
  454. (MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE * \
  455. (HFI_ALIGN(frame_width, 64) + 8) * 2)
  456. #define SIZE_H265D_LB_FE_TOP_CTRL(frame_width, frame_height) \
  457. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * \
  458. (HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  459. #define SIZE_H265D_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  460. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * \
  461. (HFI_ALIGN(frame_height, LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  462. #define SIZE_H265D_LB_SE_TOP_CTRL(frame_width, frame_height) \
  463. ((LCU_MAX_SIZE_PELS / 8 * (128 / 8)) * ((frame_width + 15) >> 4))
  464. #define SIZE_H265D_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  465. (MAX(((frame_height + 16 - 1) / 8) * \
  466. MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE, \
  467. MAX(((frame_height + 32 - 1) / 8) * \
  468. MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  469. ((frame_height + 64 - 1) / 8) * \
  470. MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE)))
  471. #define SIZE_H265D_LB_PE_TOP_DATA(frame_width, frame_height) \
  472. (MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE * (HFI_ALIGN(frame_width, \
  473. LCU_MIN_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  474. #define SIZE_H265D_LB_VSP_TOP(frame_width, frame_height) \
  475. (((frame_width + 63) >> 6) * 128)
  476. #define SIZE_H265D_LB_VSP_LEFT(frame_width, frame_height) \
  477. (((frame_height + 63) >> 6) * 128)
  478. #define SIZE_H265D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  479. SIZE_H264D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height)
  480. #define SIZE_H265D_QP(frame_width, frame_height) \
  481. SIZE_H264D_QP(frame_width, frame_height)
  482. #define SIZE_H265D_BSE_CMD_BUF(_size, frame_width, frame_height)\
  483. do { \
  484. _size = HFI_ALIGN(((HFI_ALIGN(frame_width, \
  485. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS) * \
  486. (HFI_ALIGN(frame_height, LCU_MAX_SIZE_PELS) /\
  487. LCU_MIN_SIZE_PELS)) * NUM_HW_PIC_BUF, VENUS_DMA_ALIGNMENT); \
  488. _size = MIN(_size, H265D_MAX_SLICE + 1); \
  489. _size = 2 * _size * SIZE_H265D_BSE_CMD_PER_BUF; \
  490. } while (0)
  491. #define SIZE_H265D_VPP_CMD_BUF(_size, frame_width, frame_height) \
  492. do { \
  493. _size = HFI_ALIGN(((HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) /\
  494. LCU_MIN_SIZE_PELS) * (HFI_ALIGN(frame_height, \
  495. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS)) * \
  496. NUM_HW_PIC_BUF, VENUS_DMA_ALIGNMENT); \
  497. _size = MIN(_size, H265D_MAX_SLICE + 1); \
  498. _size = HFI_ALIGN(_size, 4); \
  499. _size = 2 * _size * SIZE_H265D_VPP_CMD_PER_BUF; \
  500. if (_size > VPP_CMD_MAX_SIZE) { \
  501. _size = VPP_CMD_MAX_SIZE; \
  502. } \
  503. } while (0)
  504. #define HFI_BUFFER_COMV_H265D(_size, frame_width, frame_height, \
  505. _yuv_bufcount_min) \
  506. do { \
  507. _size = HFI_ALIGN(((((frame_width + 15) >> 4) * \
  508. ((frame_height + 15) >> 4)) << 8), \
  509. BUFFER_ALIGNMENT_512_BYTES); \
  510. _size *= _yuv_bufcount_min; \
  511. _size += BUFFER_ALIGNMENT_512_BYTES; \
  512. } while (0)
  513. #define HDR10_HIST_EXTRADATA_SIZE (4 * 1024)
  514. #define HFI_BUFFER_NON_COMV_H265D(_size, frame_width, frame_height, \
  515. num_vpp_pipes) \
  516. do { \
  517. HFI_U32 _size_bse, _size_vpp; \
  518. SIZE_H265D_BSE_CMD_BUF(_size_bse, frame_width, \
  519. frame_height); \
  520. SIZE_H265D_VPP_CMD_BUF(_size_vpp, frame_width, \
  521. frame_height); \
  522. _size = HFI_ALIGN(_size_bse, VENUS_DMA_ALIGNMENT) + \
  523. HFI_ALIGN(_size_vpp, VENUS_DMA_ALIGNMENT) + \
  524. HFI_ALIGN(NUM_HW_PIC_BUF * 20 * 22 * 4, \
  525. VENUS_DMA_ALIGNMENT) + \
  526. HFI_ALIGN(2 * sizeof(HFI_U16) * \
  527. (HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) / \
  528. LCU_MIN_SIZE_PELS) * (HFI_ALIGN(frame_height, \
  529. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS), \
  530. VENUS_DMA_ALIGNMENT) + \
  531. HFI_ALIGN(SIZE_HW_PIC(SIZE_H265D_HW_PIC_T), \
  532. VENUS_DMA_ALIGNMENT) + \
  533. HDR10_HIST_EXTRADATA_SIZE; \
  534. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  535. } while (0)
  536. #define HFI_BUFFER_LINE_H265D(_size, frame_width, frame_height, \
  537. is_opb, num_vpp_pipes) \
  538. do { \
  539. HFI_U32 vpss_lb_size = 0; \
  540. _size = HFI_ALIGN(SIZE_H265D_LB_FE_TOP_DATA(frame_width, \
  541. frame_height), VENUS_DMA_ALIGNMENT) + \
  542. HFI_ALIGN(SIZE_H265D_LB_FE_TOP_CTRL(frame_width, \
  543. frame_height), VENUS_DMA_ALIGNMENT) + \
  544. HFI_ALIGN(SIZE_H265D_LB_FE_LEFT_CTRL(frame_width, \
  545. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  546. HFI_ALIGN(SIZE_H265D_LB_SE_LEFT_CTRL(frame_width, \
  547. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  548. HFI_ALIGN(SIZE_H265D_LB_SE_TOP_CTRL(frame_width, \
  549. frame_height), VENUS_DMA_ALIGNMENT) + \
  550. HFI_ALIGN(SIZE_H265D_LB_PE_TOP_DATA(frame_width, \
  551. frame_height), VENUS_DMA_ALIGNMENT) + \
  552. HFI_ALIGN(SIZE_H265D_LB_VSP_TOP(frame_width, \
  553. frame_height), VENUS_DMA_ALIGNMENT) + \
  554. HFI_ALIGN(SIZE_H265D_LB_VSP_LEFT(frame_width, \
  555. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  556. HFI_ALIGN(SIZE_H265D_LB_RECON_DMA_METADATA_WR\
  557. (frame_width, frame_height), \
  558. VENUS_DMA_ALIGNMENT) * 4 + \
  559. HFI_ALIGN(SIZE_H265D_QP(frame_width, frame_height),\
  560. VENUS_DMA_ALIGNMENT); \
  561. if (is_opb) { \
  562. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height,\
  563. num_vpp_pipes); \
  564. } \
  565. _size = HFI_ALIGN((_size + vpss_lb_size), \
  566. VENUS_DMA_ALIGNMENT); \
  567. } while (0)
  568. #define H265_CABAC_HDR_RATIO_HD_TOT 2
  569. #define H265_CABAC_RES_RATIO_HD_TOT 2
  570. #define SIZE_H265D_HW_BIN_BUFFER(_size, frame_width, frame_height, \
  571. delay, num_vpp_pipes) \
  572. do { \
  573. HFI_U32 size_yuv, size_bin_hdr, size_bin_res; \
  574. size_yuv = ((frame_width * frame_height) <= \
  575. BIN_BUFFER_THRESHOLD) ? \
  576. ((BIN_BUFFER_THRESHOLD * 3) >> 1) : \
  577. ((frame_width * frame_height * 3) >> 1); \
  578. size_bin_hdr = size_yuv * H265_CABAC_HDR_RATIO_HD_TOT; \
  579. size_bin_res = size_yuv * H265_CABAC_RES_RATIO_HD_TOT; \
  580. size_bin_hdr = size_bin_hdr * \
  581. (((((HFI_U32)(delay)) & 31) / 10) + 2) / 2; \
  582. size_bin_res = size_bin_res * \
  583. (((((HFI_U32)(delay)) & 31) / 10) + 2) / 2; \
  584. size_bin_hdr = HFI_ALIGN(size_bin_hdr / \
  585. num_vpp_pipes, VENUS_DMA_ALIGNMENT) * \
  586. num_vpp_pipes; \
  587. size_bin_res = HFI_ALIGN(size_bin_res / num_vpp_pipes,\
  588. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  589. _size = size_bin_hdr + size_bin_res; \
  590. } while (0)
  591. #define HFI_BUFFER_BIN_H265D(_size, frame_width, frame_height, \
  592. is_interlaced, delay, num_vpp_pipes) \
  593. do { \
  594. HFI_U32 n_aligned_w = HFI_ALIGN(frame_width, \
  595. BUFFER_ALIGNMENT_16_BYTES); \
  596. HFI_U32 n_aligned_h = HFI_ALIGN(frame_height, \
  597. BUFFER_ALIGNMENT_16_BYTES); \
  598. if (!is_interlaced) { \
  599. SIZE_H265D_HW_BIN_BUFFER(_size, n_aligned_w, \
  600. n_aligned_h, delay, num_vpp_pipes); \
  601. } else { \
  602. _size = 0; \
  603. } \
  604. } while (0)
  605. #define SIZE_SLIST_BUF_H265 (1 << 10)
  606. #define NUM_SLIST_BUF_H265 (80 + 20)
  607. #define H265_NUM_TILE_COL 32
  608. #define H265_NUM_TILE_ROW 128
  609. #define H265_NUM_TILE (H265_NUM_TILE_ROW * H265_NUM_TILE_COL + 1)
  610. #define H265_NUM_FRM_INFO (48)
  611. #define H265_DISPLAY_BUF_SIZE (3072)
  612. #define HFI_BUFFER_PERSIST_H265D(_size, rpu_enabled) \
  613. (_size = HFI_ALIGN((SIZE_SLIST_BUF_H265 * NUM_SLIST_BUF_H265 + \
  614. H265_NUM_FRM_INFO * H265_DISPLAY_BUF_SIZE + \
  615. H265_NUM_TILE * sizeof(HFI_U32) + NUM_HW_PIC_BUF * SIZE_SEI_USERDATA + \
  616. (rpu_enabled) * NUM_HW_PIC_BUF * SIZE_DOLBY_RPU_METADATA),\
  617. VENUS_DMA_ALIGNMENT))
  618. #define SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  619. MAX(((frame_height + 15) >> 4) * \
  620. MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE, \
  621. MAX(((frame_height + 31) >> 5) * \
  622. MAX_FE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  623. ((frame_height + 63) >> 6) * MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE))
  624. #define SIZE_VPXD_LB_FE_TOP_CTRL(frame_width, frame_height) \
  625. (((HFI_ALIGN(frame_width, 64) + 8) * 10 * 2))
  626. #define SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height) \
  627. (((frame_width + 15) >> 4) * MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE)
  628. #define SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  629. MAX(((frame_height + 15) >> 4) * \
  630. MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE,\
  631. MAX(((frame_height + 31) >> 5) * \
  632. MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  633. ((frame_height + 63) >> 6) * MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE))
  634. #define SIZE_VPXD_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  635. HFI_ALIGN((HFI_ALIGN(frame_height, 8) / (4 / 2)) * 64,\
  636. BUFFER_ALIGNMENT_32_BYTES)
  637. #define SIZE_MP2D_LB_FE_TOP_DATA(frame_width, frame_height) \
  638. ((HFI_ALIGN(frame_width, 16) + 8) * 10 * 2)
  639. #define SIZE_VP9D_LB_FE_TOP_DATA(frame_width, frame_height) \
  640. ((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) + 8) * 10 * 2)
  641. #define SIZE_MP2D_LB_PE_TOP_DATA(frame_width, frame_height) \
  642. ((HFI_ALIGN(frame_width, 16) >> 4) * 64)
  643. #define SIZE_VP9D_LB_PE_TOP_DATA(frame_width, frame_height) \
  644. ((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) >> 6) * 176)
  645. #define SIZE_MP2D_LB_VSP_TOP(frame_width, frame_height) \
  646. (((HFI_ALIGN(frame_width, 16) >> 4) * 64 / 2) + 256)
  647. #define SIZE_VP9D_LB_VSP_TOP(frame_width, frame_height) \
  648. ((((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) >> 6) * 64 * 8) + 256))
  649. #define HFI_IRIS2_VP9D_COMV_SIZE \
  650. ((((8192 + 63) >> 6) * ((4320 + 63) >> 6) * 8 * 8 * 2 * 8))
  651. #define SIZE_VP9D_QP(frame_width, frame_height) \
  652. SIZE_H264D_QP(frame_width, frame_height)
  653. #define HFI_IRIS2_VP9D_LB_SIZE(_size, frame_width, frame_height, num_vpp_pipes)\
  654. do { \
  655. _size = HFI_ALIGN(SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, \
  656. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  657. HFI_ALIGN(SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height),\
  658. VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  659. HFI_ALIGN(SIZE_VP9D_LB_VSP_TOP(frame_width, frame_height), \
  660. VENUS_DMA_ALIGNMENT) + \
  661. HFI_ALIGN(SIZE_VPXD_LB_FE_TOP_CTRL(frame_width, frame_height), \
  662. VENUS_DMA_ALIGNMENT) + 2 * \
  663. HFI_ALIGN(SIZE_VPXD_LB_RECON_DMA_METADATA_WR \
  664. (frame_width, frame_height), VENUS_DMA_ALIGNMENT) + \
  665. HFI_ALIGN(SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height), \
  666. VENUS_DMA_ALIGNMENT) + \
  667. HFI_ALIGN(SIZE_VP9D_LB_PE_TOP_DATA(frame_width, frame_height), \
  668. VENUS_DMA_ALIGNMENT) + \
  669. HFI_ALIGN(SIZE_VP9D_LB_FE_TOP_DATA(frame_width, frame_height), \
  670. VENUS_DMA_ALIGNMENT) + \
  671. HFI_ALIGN(SIZE_VP9D_QP(frame_width, frame_height), \
  672. VENUS_DMA_ALIGNMENT); \
  673. } while (0)
  674. #define HFI_BUFFER_LINE_VP9D(_size, frame_width, frame_height, \
  675. _yuv_bufcount_min, is_opb, num_vpp_pipes) \
  676. do { \
  677. HFI_U32 _lb_size = 0; \
  678. HFI_U32 vpss_lb_size = 0; \
  679. HFI_IRIS2_VP9D_LB_SIZE(_lb_size, frame_width, frame_height,\
  680. num_vpp_pipes); \
  681. if (is_opb) { \
  682. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  683. num_vpp_pipes); \
  684. } \
  685. _size = _lb_size + vpss_lb_size; \
  686. } while (0)
  687. #define VPX_DECODER_FRAME_CONCURENCY_LVL (2)
  688. #define VPX_DECODER_FRAME_BIN_HDR_BUDGET_RATIO 1 / 2
  689. #define VPX_DECODER_FRAME_BIN_RES_BUDGET_RATIO 3 / 2
  690. #define HFI_BUFFER_BIN_VP9D(_size, frame_width, frame_height, \
  691. is_interlaced, num_vpp_pipes) \
  692. do { \
  693. HFI_U32 _size_yuv = HFI_ALIGN(frame_width, \
  694. BUFFER_ALIGNMENT_16_BYTES) *\
  695. HFI_ALIGN(frame_height, BUFFER_ALIGNMENT_16_BYTES) * 3 / 2; \
  696. if (!is_interlaced) { \
  697. _size = HFI_ALIGN(((MAX(_size_yuv, \
  698. ((BIN_BUFFER_THRESHOLD * 3) >> 1)) * \
  699. VPX_DECODER_FRAME_BIN_HDR_BUDGET_RATIO * \
  700. VPX_DECODER_FRAME_CONCURENCY_LVL) / num_vpp_pipes), \
  701. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(((MAX(_size_yuv, \
  702. ((BIN_BUFFER_THRESHOLD * 3) >> 1)) * \
  703. VPX_DECODER_FRAME_BIN_RES_BUDGET_RATIO * \
  704. VPX_DECODER_FRAME_CONCURENCY_LVL) / num_vpp_pipes), \
  705. VENUS_DMA_ALIGNMENT); \
  706. _size = _size * num_vpp_pipes; \
  707. } \
  708. else \
  709. _size = 0; \
  710. } while (0)
  711. #define VP9_NUM_FRAME_INFO_BUF 32
  712. #define VP9_NUM_PROBABILITY_TABLE_BUF (VP9_NUM_FRAME_INFO_BUF + 4)
  713. #define VP9_PROB_TABLE_SIZE (3840)
  714. #define VP9_FRAME_INFO_BUF_SIZE (6144)
  715. #define VP9_UDC_HEADER_BUF_SIZE (3 * 128)
  716. #define MAX_SUPERFRAME_HEADER_LEN (34)
  717. #define CCE_TILE_OFFSET_SIZE HFI_ALIGN(32 * 4 * 4, BUFFER_ALIGNMENT_32_BYTES)
  718. #define HFI_BUFFER_PERSIST_VP9D(_size) \
  719. _size = HFI_ALIGN(VP9_NUM_PROBABILITY_TABLE_BUF * VP9_PROB_TABLE_SIZE, \
  720. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(HFI_IRIS2_VP9D_COMV_SIZE, \
  721. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(MAX_SUPERFRAME_HEADER_LEN, \
  722. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(VP9_UDC_HEADER_BUF_SIZE, \
  723. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(VP9_NUM_FRAME_INFO_BUF * \
  724. CCE_TILE_OFFSET_SIZE, VENUS_DMA_ALIGNMENT) + \
  725. HFI_ALIGN(VP9_NUM_FRAME_INFO_BUF * VP9_FRAME_INFO_BUF_SIZE, \
  726. VENUS_DMA_ALIGNMENT) + HDR10_HIST_EXTRADATA_SIZE
  727. #define HFI_BUFFER_LINE_MP2D(_size, frame_width, frame_height, \
  728. _yuv_bufcount_min, is_opb, num_vpp_pipes) \
  729. do { \
  730. HFI_U32 vpss_lb_size = 0; \
  731. _size = HFI_ALIGN(SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, \
  732. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  733. HFI_ALIGN(SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height),\
  734. VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  735. HFI_ALIGN(SIZE_MP2D_LB_VSP_TOP(frame_width, frame_height),\
  736. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(SIZE_VPXD_LB_FE_TOP_CTRL\
  737. (frame_width, frame_height), VENUS_DMA_ALIGNMENT) + \
  738. 2 * HFI_ALIGN(SIZE_VPXD_LB_RECON_DMA_METADATA_WR(frame_width,\
  739. frame_height), VENUS_DMA_ALIGNMENT) + \
  740. HFI_ALIGN(SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height),\
  741. VENUS_DMA_ALIGNMENT) + \
  742. HFI_ALIGN(SIZE_MP2D_LB_PE_TOP_DATA(frame_width, frame_height), \
  743. VENUS_DMA_ALIGNMENT) + \
  744. HFI_ALIGN(SIZE_MP2D_LB_FE_TOP_DATA(frame_width, frame_height), \
  745. VENUS_DMA_ALIGNMENT); \
  746. if (is_opb) { \
  747. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  748. num_vpp_pipes); \
  749. } \
  750. _size += vpss_lb_size; \
  751. } while (0)
  752. #define HFI_BUFFER_BIN_MP2D(_size, frame_width, frame_height, is_interlaced) 0
  753. #define QMATRIX_SIZE (sizeof(HFI_U32) * 128 + 256)
  754. #define MP2D_QPDUMP_SIZE 115200
  755. #define HFI_BUFFER_PERSIST_MP2D(_size) \
  756. _size = QMATRIX_SIZE + MP2D_QPDUMP_SIZE;
  757. #define HFI_BUFFER_BITSTREAM_ENC(size, frame_width, frame_height, \
  758. rc_type, is_ten_bit) \
  759. do { \
  760. HFI_U32 aligned_width, aligned_height, bitstream_size; \
  761. aligned_width = HFI_ALIGN(frame_width, 32); \
  762. aligned_height = HFI_ALIGN(frame_height, 32); \
  763. bitstream_size = aligned_width * aligned_height * 3; \
  764. if (aligned_width * aligned_height > (4096 * 2176)) { \
  765. bitstream_size = (bitstream_size >> 3); \
  766. } \
  767. else if (bitstream_size > (1280 * 720)) { \
  768. bitstream_size = (bitstream_size >> 2); \
  769. } else { \
  770. bitstream_size = (bitstream_size << 1);\
  771. } \
  772. if ((rc_type == HFI_RC_CQ) || (rc_type == HFI_RC_OFF)) { \
  773. bitstream_size = (bitstream_size << 1);\
  774. } \
  775. if (is_ten_bit) { \
  776. bitstream_size = (bitstream_size) + \
  777. (bitstream_size >> 2); \
  778. } \
  779. size = HFI_ALIGN(bitstream_size, HFI_ALIGNMENT_4096); \
  780. } while (0)
  781. #define SIZE_ROI_METADATA_ENC(size_roi, frame_width, frame_height, lcu_size)\
  782. do { \
  783. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, n_shift = 0; \
  784. while (lcu_size && !(lcu_size & 0x1)) { \
  785. n_shift++; \
  786. lcu_size = lcu_size >> 1; \
  787. } \
  788. width_in_lcus = (frame_width + (lcu_size - 1)) >> n_shift; \
  789. height_in_lcus = (frame_height + (lcu_size - 1)) >> n_shift; \
  790. size_roi = (((width_in_lcus + 7) >> 3) << 3) * \
  791. height_in_lcus * 2 + 256; \
  792. } while (0)
  793. #define HFI_BUFFER_INPUT_METADATA_ENC(size, frame_width, frame_height, \
  794. is_roi_enabled, lcu_size) \
  795. do { \
  796. HFI_U32 roi_size = 0; \
  797. if (is_roi_enabled) { \
  798. SIZE_ROI_METADATA_ENC(roi_size, frame_width, \
  799. frame_height, lcu_size); \
  800. } \
  801. size = roi_size + 16384; \
  802. size = HFI_ALIGN(size, HFI_ALIGNMENT_4096); \
  803. } while (0)
  804. #define HFI_BUFFER_INPUT_METADATA_H264E(size_metadata, frame_width, \
  805. frame_height, is_roi_enabled) \
  806. do { \
  807. HFI_BUFFER_INPUT_METADATA_ENC(size_metadata, frame_width, \
  808. frame_height, is_roi_enabled, 16); \
  809. } while (0)
  810. #define HFI_BUFFER_INPUT_METADATA_H265E(size_metadata, frame_width, \
  811. frame_height, is_roi_enabled) \
  812. do { \
  813. HFI_BUFFER_INPUT_METADATA_ENC(size_metadata, frame_width, \
  814. frame_height, is_roi_enabled, 32); \
  815. } while (0)
  816. #define HFI_BUFFER_ARP_ENC(size) \
  817. do { \
  818. size = 204800; \
  819. } while (0)
  820. #define HFI_MAX_COL_FRAME 6
  821. #define HFI_VENUS_VENC_TRE_WB_BUFF_SIZE (65 << 4) // bytes
  822. #define HFI_VENUS_VENC_DB_LINE_BUFF_PER_MB 512
  823. #define HFI_VENUS_VPPSG_MAX_REGISTERS 2048
  824. #define HFI_VENUS_WIDTH_ALIGNMENT 128
  825. #define HFI_VENUS_WIDTH_TEN_BIT_ALIGNMENT 192
  826. #define HFI_VENUS_HEIGHT_ALIGNMENT 32
  827. #define VENUS_METADATA_STRIDE_MULTIPLE 64
  828. #define VENUS_METADATA_HEIGHT_MULTIPLE 16
  829. #ifndef SYSTEM_LAL_TILE10
  830. #define SYSTEM_LAL_TILE10 192
  831. #endif
  832. #define HFI_IRIS2_ENC_RECON_BUF_COUNT(num_recon, n_bframe, ltr_count, \
  833. _total_hp_layers, _total_hb_layers, hybrid_hp, codec_standard) \
  834. do { \
  835. HFI_U32 num_ref = 1; \
  836. if (n_bframe) \
  837. num_ref = 2; \
  838. if (_total_hp_layers > 1) { \
  839. if (hybrid_hp) \
  840. num_ref = (_total_hp_layers + 1) >> 1; \
  841. else if (codec_standard == HFI_CODEC_ENCODE_HEVC) \
  842. num_ref = (_total_hp_layers + 1) >> 1; \
  843. else if (codec_standard == HFI_CODEC_ENCODE_AVC && \
  844. _total_hp_layers < 4) \
  845. num_ref = (_total_hp_layers - 1); \
  846. else \
  847. num_ref = _total_hp_layers; \
  848. } \
  849. if (ltr_count) \
  850. num_ref = num_ref + ltr_count; \
  851. if (_total_hb_layers > 1) { \
  852. if (codec_standard == HFI_CODEC_ENCODE_HEVC) \
  853. num_ref = (_total_hb_layers); \
  854. else if (codec_standard == HFI_CODEC_ENCODE_AVC) \
  855. num_ref = (1 << (_total_hb_layers - 2)) + 1; \
  856. } \
  857. num_recon = num_ref + 1; \
  858. } while (0)
  859. #define SIZE_BIN_BITSTREAM_ENC(_size, rc_type, frame_width, frame_height, \
  860. work_mode, lcu_size) \
  861. do { \
  862. HFI_U32 size_aligned_width = 0, size_aligned_height = 0; \
  863. HFI_U32 bitstream_size_eval = 0; \
  864. size_aligned_width = HFI_ALIGN((frame_width), lcu_size); \
  865. size_aligned_height = HFI_ALIGN((frame_height), lcu_size); \
  866. if (work_mode == HFI_WORKMODE_2) { \
  867. if ((rc_type == HFI_RC_CQ) || (rc_type == HFI_RC_OFF)) { \
  868. bitstream_size_eval = (((size_aligned_width) * \
  869. (size_aligned_height) * 3) >> 1); \
  870. } \
  871. else { \
  872. bitstream_size_eval = ((size_aligned_width) * \
  873. (size_aligned_height) * 3); \
  874. if (rc_type == HFI_RC_LOSSLESS) { \
  875. bitstream_size_eval = (bitstream_size_eval * 3 >> 2); \
  876. } \
  877. else if ((size_aligned_width * size_aligned_height) > \
  878. (4096 * 2176)) { \
  879. bitstream_size_eval >>= 3; \
  880. } \
  881. else if ((size_aligned_width * size_aligned_height) > \
  882. (480 * 320)) { \
  883. bitstream_size_eval >>= 2; \
  884. } \
  885. if (lcu_size == 32) { \
  886. bitstream_size_eval = (bitstream_size_eval * 5 >> 2); \
  887. } \
  888. } \
  889. } else { \
  890. bitstream_size_eval = size_aligned_width * \
  891. size_aligned_height * 3; \
  892. } \
  893. _size = HFI_ALIGN(bitstream_size_eval, VENUS_DMA_ALIGNMENT); \
  894. } while (0)
  895. #define SIZE_ENC_SINGLE_PIPE(size, rc_type, bitbin_size, num_vpp_pipes, \
  896. frame_width, frame_height, lcu_size) \
  897. do { \
  898. HFI_U32 size_single_pipe_eval = 0, sao_bin_buffer_size = 0, \
  899. _padded_bin_sz = 0; \
  900. HFI_U32 size_aligned_width = 0, size_aligned_height = 0; \
  901. size_aligned_width = HFI_ALIGN((frame_width), lcu_size); \
  902. size_aligned_height = HFI_ALIGN((frame_height), lcu_size); \
  903. if ((size_aligned_width * size_aligned_height) > \
  904. (3840 * 2160)) { \
  905. size_single_pipe_eval = (bitbin_size / num_vpp_pipes); \
  906. } \
  907. else if (num_vpp_pipes > 2) { \
  908. size_single_pipe_eval = bitbin_size / 2; \
  909. } else { \
  910. size_single_pipe_eval = bitbin_size; \
  911. } \
  912. if (rc_type == HFI_RC_LOSSLESS) { \
  913. size_single_pipe_eval = (size_single_pipe_eval << 1); \
  914. } \
  915. sao_bin_buffer_size = (64 * ((((frame_width) + \
  916. BUFFER_ALIGNMENT_32_BYTES) * ((frame_height) +\
  917. BUFFER_ALIGNMENT_32_BYTES)) >> 10)) + 384; \
  918. _padded_bin_sz = HFI_ALIGN(size_single_pipe_eval, \
  919. VENUS_DMA_ALIGNMENT);\
  920. size_single_pipe_eval = sao_bin_buffer_size + _padded_bin_sz; \
  921. size_single_pipe_eval = HFI_ALIGN(size_single_pipe_eval, \
  922. VENUS_DMA_ALIGNMENT); \
  923. size = size_single_pipe_eval; \
  924. } while (0)
  925. #define HFI_BUFFER_BIN_ENC(_size, rc_type, frame_width, frame_height, lcu_size, \
  926. work_mode, num_vpp_pipes) \
  927. do { \
  928. HFI_U32 bitstream_size = 0, total_bitbin_buffers = 0, \
  929. size_single_pipe = 0, bitbin_size = 0; \
  930. SIZE_BIN_BITSTREAM_ENC(bitstream_size, rc_type, frame_width, \
  931. frame_height, work_mode, lcu_size); \
  932. if (work_mode == HFI_WORKMODE_2) { \
  933. total_bitbin_buffers = 3; \
  934. bitbin_size = bitstream_size * 17 / 10; \
  935. bitbin_size = HFI_ALIGN(bitbin_size, \
  936. VENUS_DMA_ALIGNMENT); \
  937. } \
  938. else if ((lcu_size == 16) || (num_vpp_pipes > 1)) { \
  939. total_bitbin_buffers = 1; \
  940. bitbin_size = bitstream_size; \
  941. } \
  942. if (total_bitbin_buffers > 0) { \
  943. SIZE_ENC_SINGLE_PIPE(size_single_pipe, rc_type, bitbin_size, \
  944. num_vpp_pipes, frame_width, frame_height, lcu_size); \
  945. bitbin_size = size_single_pipe * num_vpp_pipes; \
  946. _size = HFI_ALIGN(bitbin_size, VENUS_DMA_ALIGNMENT) * \
  947. total_bitbin_buffers + 512; \
  948. } else { \
  949. /* Avoid 512 Bytes allocation in case of 1Pipe HEVC Direct Mode*/ \
  950. _size = 0; \
  951. } \
  952. } while (0)
  953. #define HFI_BUFFER_BIN_H264E(_size, rc_type, frame_width, frame_height, \
  954. work_mode, num_vpp_pipes) \
  955. do { \
  956. HFI_BUFFER_BIN_ENC(_size, rc_type, frame_width, frame_height, 16, \
  957. work_mode, num_vpp_pipes); \
  958. } while (0)
  959. #define HFI_BUFFER_BIN_H265E(_size, rc_type, frame_width, frame_height, \
  960. work_mode, num_vpp_pipes) \
  961. do { \
  962. HFI_BUFFER_BIN_ENC(_size, rc_type, frame_width, frame_height, 32,\
  963. work_mode, num_vpp_pipes); \
  964. } while (0)
  965. #define SIZE_ENC_SLICE_INFO_BUF(num_lcu_in_frame) HFI_ALIGN((256 + \
  966. (num_lcu_in_frame << 4)), VENUS_DMA_ALIGNMENT)
  967. #define SIZE_LINE_BUF_CTRL(frame_width_coded) \
  968. HFI_ALIGN(frame_width_coded, VENUS_DMA_ALIGNMENT)
  969. #define SIZE_LINE_BUF_CTRL_ID2(frame_width_coded) \
  970. HFI_ALIGN(frame_width_coded, VENUS_DMA_ALIGNMENT)
  971. #define SIZE_LINEBUFF_DATA(_size, is_ten_bit, frame_width_coded) \
  972. do { \
  973. _size = is_ten_bit ? (((((10 * (frame_width_coded) +\
  974. 1024) + (VENUS_DMA_ALIGNMENT - 1)) & \
  975. (~(VENUS_DMA_ALIGNMENT - 1))) * 1) + \
  976. (((((10 * (frame_width_coded) + 1024) >> 1) + \
  977. (VENUS_DMA_ALIGNMENT - 1)) & (~(VENUS_DMA_ALIGNMENT - 1))) * \
  978. 2)) : (((((8 * (frame_width_coded) + 1024) + \
  979. (VENUS_DMA_ALIGNMENT - 1)) \
  980. & (~(VENUS_DMA_ALIGNMENT - 1))) * 1) + \
  981. (((((8 * (frame_width_coded) +\
  982. 1024) >> 1) + (VENUS_DMA_ALIGNMENT - 1)) & \
  983. (~(VENUS_DMA_ALIGNMENT - 1))) * 2)); \
  984. } while (0)
  985. #define SIZE_LEFT_LINEBUFF_CTRL(_size, standard, frame_height_coded, \
  986. num_vpp_pipes_enc) \
  987. do { \
  988. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? \
  989. (((frame_height_coded) + \
  990. (BUF_SIZE_ALIGN_32)) / BUF_SIZE_ALIGN_32 * 4 * 16) : \
  991. (((frame_height_coded) + 15) / 16 * 5 * 16); \
  992. if ((num_vpp_pipes_enc) > 1) { \
  993. _size += BUFFER_ALIGNMENT_512_BYTES; \
  994. _size = HFI_ALIGN(_size, BUFFER_ALIGNMENT_512_BYTES) *\
  995. (num_vpp_pipes_enc); \
  996. } \
  997. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  998. } while (0)
  999. #define SIZE_LEFT_LINEBUFF_RECON_PIX(_size, is_ten_bit, frame_height_coded, \
  1000. num_vpp_pipes_enc) \
  1001. do { \
  1002. _size = (((is_ten_bit + 1) * 2 * (frame_height_coded) + \
  1003. VENUS_DMA_ALIGNMENT) + \
  1004. (VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1) & \
  1005. (~((VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1)) * 1; \
  1006. } while (0)
  1007. #define SIZE_TOP_LINEBUFF_CTRL_FE(_size, frame_width_coded, standard) \
  1008. do { \
  1009. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? (64 * \
  1010. ((frame_width_coded) >> 5)) : (VENUS_DMA_ALIGNMENT + 16 * \
  1011. ((frame_width_coded) >> 4)); \
  1012. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1013. } while (0)
  1014. #define SIZE_LEFT_LINEBUFF_CTRL_FE(frame_height_coded, num_vpp_pipes_enc) \
  1015. ((((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) >> 4)) + \
  1016. (VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1) & \
  1017. (~((VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1)) * 1) * \
  1018. num_vpp_pipes_enc)
  1019. #define SIZE_LEFT_LINEBUFF_METADATA_RECON_Y(_size, frame_height_coded, \
  1020. is_ten_bit, num_vpp_pipes_enc) \
  1021. do { \
  1022. _size = ((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) / \
  1023. (8 * (is_ten_bit ? 4 : 8))))); \
  1024. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1025. _size = (_size * num_vpp_pipes_enc); \
  1026. } while (0)
  1027. #define SIZE_LEFT_LINEBUFF_METADATA_RECON_UV(_size, frame_height_coded, \
  1028. is_ten_bit, num_vpp_pipes_enc) \
  1029. do { \
  1030. _size = ((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) / \
  1031. (4 * (is_ten_bit ? 4 : 8))))); \
  1032. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1033. _size = (_size * num_vpp_pipes_enc); \
  1034. } while (0)
  1035. #define SIZE_LINEBUFF_RECON_PIX(_size, is_ten_bit, frame_width_coded) \
  1036. do { \
  1037. _size = ((is_ten_bit ? 3 : 2) * (frame_width_coded)); \
  1038. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1039. } while (0)
  1040. #define SIZE_SLICE_CMD_BUFFER (HFI_ALIGN(20480, VENUS_DMA_ALIGNMENT))
  1041. #define SIZE_SPS_PPS_SLICE_HDR (2048 + 4096)
  1042. #define SIZE_FRAME_RC_BUF_SIZE(_size, standard, frame_height_coded, \
  1043. num_vpp_pipes_enc) \
  1044. do { \
  1045. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? (256 + 16 * \
  1046. (14 + ((((frame_height_coded) >> 5) + 7) >> 3))) : \
  1047. (256 + 16 * (14 + ((((frame_height_coded) >> 4) + 7) >> 3))); \
  1048. _size *= 11; \
  1049. if (num_vpp_pipes_enc > 1) { \
  1050. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT) * \
  1051. num_vpp_pipes_enc;\
  1052. } \
  1053. _size = HFI_ALIGN(_size, BUFFER_ALIGNMENT_512_BYTES) * \
  1054. HFI_MAX_COL_FRAME; \
  1055. } while (0)
  1056. #define ENC_BITCNT_BUF_SIZE(num_lcu_in_frame) HFI_ALIGN((256 + \
  1057. (4 * (num_lcu_in_frame))), VENUS_DMA_ALIGNMENT)
  1058. #define ENC_BITMAP_BUF_SIZE(num_lcu_in_frame) HFI_ALIGN((256 + \
  1059. ((num_lcu_in_frame) >> 3)), VENUS_DMA_ALIGNMENT)
  1060. #define SIZE_LINE_BUF_SDE(frame_width_coded) HFI_ALIGN((256 + \
  1061. (16 * ((frame_width_coded) >> 4))), VENUS_DMA_ALIGNMENT)
  1062. #define SIZE_BSE_SLICE_CMD_BUF ((((8192 << 2) + 7) & (~7)) * 3)
  1063. #define SIZE_LAMBDA_LUT (256 * 11)
  1064. #define SIZE_OVERRIDE_BUF(num_lcumb) (HFI_ALIGN(((16 * (((num_lcumb) + 7)\
  1065. >> 3))), VENUS_DMA_ALIGNMENT) * 2)
  1066. #define SIZE_IR_BUF(num_lcu_in_frame) HFI_ALIGN((((((num_lcu_in_frame) << 1) + 7) &\
  1067. (~7)) * 3), VENUS_DMA_ALIGNMENT)
  1068. #define SIZE_VPSS_LINE_BUF(num_vpp_pipes_enc, frame_height_coded, \
  1069. frame_width_coded) \
  1070. (HFI_ALIGN(((((((8192) >> 2) << 5) * (num_vpp_pipes_enc)) + 64) + \
  1071. (((((MAX((frame_width_coded), (frame_height_coded)) + 3) >> 2) << 5) +\
  1072. 256) * 16)), VENUS_DMA_ALIGNMENT))
  1073. #define SIZE_TOP_LINE_BUF_FIRST_STG_SAO(frame_width_coded) \
  1074. HFI_ALIGN((16 * ((frame_width_coded) >> 5)), VENUS_DMA_ALIGNMENT)
  1075. #define HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, is_ten_bit, \
  1076. num_vpp_pipes_enc, lcu_size, standard) \
  1077. do { \
  1078. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, \
  1079. frame_width_coded = 0, frame_height_coded = 0; \
  1080. HFI_U32 line_buff_data_size = 0, left_line_buff_ctrl_size = 0, \
  1081. left_line_buff_recon_pix_size = 0, \
  1082. top_line_buff_ctrl_fe_size = 0; \
  1083. HFI_U32 left_line_buff_metadata_recon__y__size = 0, \
  1084. left_line_buff_metadata_recon__uv__size = 0, \
  1085. line_buff_recon_pix_size = 0; \
  1086. width_in_lcus = ((frame_width) + (lcu_size)-1) / (lcu_size); \
  1087. height_in_lcus = ((frame_height) + (lcu_size)-1) / (lcu_size); \
  1088. frame_width_coded = width_in_lcus * (lcu_size); \
  1089. frame_height_coded = height_in_lcus * (lcu_size); \
  1090. SIZE_LINEBUFF_DATA(line_buff_data_size, is_ten_bit, \
  1091. frame_width_coded);\
  1092. SIZE_LEFT_LINEBUFF_CTRL(left_line_buff_ctrl_size, standard, \
  1093. frame_height_coded, num_vpp_pipes_enc); \
  1094. SIZE_LEFT_LINEBUFF_RECON_PIX(left_line_buff_recon_pix_size, \
  1095. is_ten_bit, frame_height_coded, num_vpp_pipes_enc); \
  1096. SIZE_TOP_LINEBUFF_CTRL_FE(top_line_buff_ctrl_fe_size, \
  1097. frame_width_coded, standard); \
  1098. SIZE_LEFT_LINEBUFF_METADATA_RECON_Y\
  1099. (left_line_buff_metadata_recon__y__size, \
  1100. frame_height_coded, is_ten_bit, num_vpp_pipes_enc); \
  1101. SIZE_LEFT_LINEBUFF_METADATA_RECON_UV\
  1102. (left_line_buff_metadata_recon__uv__size, \
  1103. frame_height_coded, is_ten_bit, num_vpp_pipes_enc); \
  1104. SIZE_LINEBUFF_RECON_PIX(line_buff_recon_pix_size, is_ten_bit,\
  1105. frame_width_coded); \
  1106. _size = SIZE_LINE_BUF_CTRL(frame_width_coded) + \
  1107. SIZE_LINE_BUF_CTRL_ID2(frame_width_coded) + \
  1108. line_buff_data_size + \
  1109. left_line_buff_ctrl_size + \
  1110. left_line_buff_recon_pix_size + \
  1111. top_line_buff_ctrl_fe_size + \
  1112. left_line_buff_metadata_recon__y__size + \
  1113. left_line_buff_metadata_recon__uv__size + \
  1114. line_buff_recon_pix_size + \
  1115. SIZE_LEFT_LINEBUFF_CTRL_FE(frame_height_coded, \
  1116. num_vpp_pipes_enc) + SIZE_LINE_BUF_SDE(frame_width_coded) + \
  1117. SIZE_VPSS_LINE_BUF(num_vpp_pipes_enc, frame_height_coded, \
  1118. frame_width_coded) + \
  1119. SIZE_TOP_LINE_BUF_FIRST_STG_SAO(frame_width_coded); \
  1120. } while (0)
  1121. #define HFI_BUFFER_LINE_H264E(_size, frame_width, frame_height, is_ten_bit, \
  1122. num_vpp_pipes) \
  1123. do { \
  1124. HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, 0, \
  1125. num_vpp_pipes, 16, HFI_CODEC_ENCODE_AVC); \
  1126. } while (0)
  1127. #define HFI_BUFFER_LINE_H265E(_size, frame_width, frame_height, is_ten_bit, \
  1128. num_vpp_pipes) \
  1129. do { \
  1130. HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, \
  1131. is_ten_bit, num_vpp_pipes, 32, HFI_CODEC_ENCODE_HEVC); \
  1132. } while (0)
  1133. #define HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, lcu_size, \
  1134. num_recon, standard) \
  1135. do { \
  1136. HFI_U32 size_colloc_mv = 0, size_colloc_rc = 0; \
  1137. HFI_U32 mb_width = ((frame_width) + 15) >> 4; \
  1138. HFI_U32 mb_height = ((frame_height) + 15) >> 4; \
  1139. HFI_U32 width_in_lcus = ((frame_width) + (lcu_size)-1) /\
  1140. (lcu_size); \
  1141. HFI_U32 height_in_lcus = ((frame_height) + (lcu_size)-1) / \
  1142. (lcu_size); \
  1143. HFI_U32 num_lcu_in_frame = width_in_lcus * height_in_lcus; \
  1144. size_colloc_mv = (standard == HFI_CODEC_ENCODE_HEVC) ? \
  1145. (16 * ((num_lcu_in_frame << 2) + BUFFER_ALIGNMENT_32_BYTES)) : \
  1146. (3 * 16 * (width_in_lcus * height_in_lcus +\
  1147. BUFFER_ALIGNMENT_32_BYTES)); \
  1148. size_colloc_mv = HFI_ALIGN(size_colloc_mv, \
  1149. VENUS_DMA_ALIGNMENT) * num_recon; \
  1150. size_colloc_rc = (((mb_width + 7) >> 3) * 16 * 2 * mb_height); \
  1151. size_colloc_rc = HFI_ALIGN(size_colloc_rc, \
  1152. VENUS_DMA_ALIGNMENT) * HFI_MAX_COL_FRAME; \
  1153. _size = size_colloc_mv + size_colloc_rc; \
  1154. } while (0)
  1155. #define HFI_BUFFER_COMV_H264E(_size, frame_width, frame_height, num_recon) \
  1156. do { \
  1157. HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, 16, \
  1158. num_recon, HFI_CODEC_ENCODE_AVC); \
  1159. } while (0)
  1160. #define HFI_BUFFER_COMV_H265E(_size, frame_width, frame_height, num_recon) \
  1161. do { \
  1162. HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, 32,\
  1163. num_recon, HFI_CODEC_ENCODE_HEVC); \
  1164. } while (0)
  1165. #define HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1166. num_vpp_pipes_enc, lcu_size, standard) \
  1167. do { \
  1168. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, \
  1169. frame_width_coded = 0, frame_height_coded = 0, \
  1170. num_lcu_in_frame = 0, num_lcumb = 0; \
  1171. HFI_U32 frame_rc_buf_size = 0; \
  1172. width_in_lcus = ((frame_width) + (lcu_size)-1) / (lcu_size); \
  1173. height_in_lcus = ((frame_height) + (lcu_size)-1) / (lcu_size); \
  1174. num_lcu_in_frame = width_in_lcus * height_in_lcus; \
  1175. frame_width_coded = width_in_lcus * (lcu_size); \
  1176. frame_height_coded = height_in_lcus * (lcu_size); \
  1177. num_lcumb = (frame_height_coded / lcu_size) * \
  1178. ((frame_width_coded + lcu_size * 8) / lcu_size); \
  1179. SIZE_FRAME_RC_BUF_SIZE(frame_rc_buf_size, standard, \
  1180. frame_height_coded, num_vpp_pipes_enc); \
  1181. _size = SIZE_ENC_SLICE_INFO_BUF(num_lcu_in_frame) + \
  1182. SIZE_SLICE_CMD_BUFFER + \
  1183. SIZE_SPS_PPS_SLICE_HDR + \
  1184. frame_rc_buf_size + \
  1185. ENC_BITCNT_BUF_SIZE(num_lcu_in_frame) + \
  1186. ENC_BITMAP_BUF_SIZE(num_lcu_in_frame) + \
  1187. SIZE_BSE_SLICE_CMD_BUF + \
  1188. SIZE_LAMBDA_LUT + \
  1189. SIZE_OVERRIDE_BUF(num_lcumb) + \
  1190. SIZE_IR_BUF(num_lcu_in_frame); \
  1191. } while (0)
  1192. #define HFI_BUFFER_NON_COMV_H264E(_size, frame_width, frame_height, \
  1193. num_vpp_pipes_enc) \
  1194. do { \
  1195. HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1196. num_vpp_pipes_enc, 16, HFI_CODEC_ENCODE_AVC); \
  1197. } while (0)
  1198. #define HFI_BUFFER_NON_COMV_H265E(_size, frame_width, frame_height, \
  1199. num_vpp_pipes_enc) \
  1200. do { \
  1201. HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1202. num_vpp_pipes_enc, 32, HFI_CODEC_ENCODE_HEVC); \
  1203. } while (0)
  1204. #define SIZE_ENC_REF_BUFFER(size, frame_width, frame_height) \
  1205. do { \
  1206. HFI_U32 u_buffer_width = 0, u_buffer_height = 0, \
  1207. u_chroma_buffer_height = 0; \
  1208. u_buffer_height = HFI_ALIGN(frame_height, \
  1209. HFI_VENUS_HEIGHT_ALIGNMENT); \
  1210. u_chroma_buffer_height = frame_height >> 1; \
  1211. u_chroma_buffer_height = HFI_ALIGN(u_chroma_buffer_height, \
  1212. HFI_VENUS_HEIGHT_ALIGNMENT); \
  1213. u_buffer_width = HFI_ALIGN(frame_width, \
  1214. HFI_VENUS_WIDTH_ALIGNMENT); \
  1215. size = (u_buffer_height + u_chroma_buffer_height) * \
  1216. u_buffer_width; \
  1217. } while (0)
  1218. #define SIZE_ENC_TEN_BIT_REF_BUFFER(size, frame_width, frame_height) \
  1219. do { \
  1220. HFI_U32 ref_buf_height = 0, ref_luma_stride_in_bytes = 0, \
  1221. u_ref_stride = 0, luma_size = 0, ref_chrm_height_in_bytes = 0, \
  1222. chroma_size = 0, ref_buf_size = 0; \
  1223. ref_buf_height = (frame_height + \
  1224. (HFI_VENUS_HEIGHT_ALIGNMENT - 1)) \
  1225. & (~(HFI_VENUS_HEIGHT_ALIGNMENT - 1)); \
  1226. ref_luma_stride_in_bytes = ((frame_width + \
  1227. SYSTEM_LAL_TILE10 - 1) / SYSTEM_LAL_TILE10) * \
  1228. SYSTEM_LAL_TILE10; \
  1229. u_ref_stride = 4 * (ref_luma_stride_in_bytes / 3); \
  1230. u_ref_stride = (u_ref_stride + (BUF_SIZE_ALIGN_128 - 1)) &\
  1231. (~(BUF_SIZE_ALIGN_128 - 1)); \
  1232. luma_size = ref_buf_height * u_ref_stride; \
  1233. ref_chrm_height_in_bytes = (((frame_height + 1) >> 1) + \
  1234. (BUF_SIZE_ALIGN_32 - 1)) & (~(BUF_SIZE_ALIGN_32 - 1)); \
  1235. chroma_size = u_ref_stride * ref_chrm_height_in_bytes; \
  1236. luma_size = (luma_size + (BUF_SIZE_ALIGN_4096 - 1)) & \
  1237. (~(BUF_SIZE_ALIGN_4096 - 1)); \
  1238. chroma_size = (chroma_size + (BUF_SIZE_ALIGN_4096 - 1)) & \
  1239. (~(BUF_SIZE_ALIGN_4096 - 1)); \
  1240. ref_buf_size = luma_size + chroma_size; \
  1241. size = ref_buf_size; \
  1242. } while (0)
  1243. #define HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, is_ten_bit) \
  1244. do { \
  1245. HFI_U32 metadata_stride, metadata_buf_height, meta_size_y, \
  1246. meta_size_c; \
  1247. HFI_U32 ten_bit_ref_buf_size = 0, ref_buf_size = 0; \
  1248. if (!is_ten_bit) { \
  1249. SIZE_ENC_REF_BUFFER(ref_buf_size, frame_width, \
  1250. frame_height); \
  1251. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, \
  1252. (frame_width), 64, \
  1253. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH); \
  1254. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, \
  1255. (frame_height), 16, \
  1256. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT); \
  1257. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_y, \
  1258. metadata_stride, metadata_buf_height); \
  1259. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_c, \
  1260. metadata_stride, metadata_buf_height); \
  1261. _size = ref_buf_size + meta_size_y + meta_size_c; \
  1262. } else { \
  1263. SIZE_ENC_TEN_BIT_REF_BUFFER(ten_bit_ref_buf_size, \
  1264. frame_width, frame_height); \
  1265. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, \
  1266. frame_width, VENUS_METADATA_STRIDE_MULTIPLE, \
  1267. HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_WIDTH); \
  1268. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, \
  1269. frame_height, VENUS_METADATA_HEIGHT_MULTIPLE, \
  1270. HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_HEIGHT); \
  1271. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_y, \
  1272. metadata_stride, metadata_buf_height); \
  1273. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_c, \
  1274. metadata_stride, metadata_buf_height); \
  1275. _size = ten_bit_ref_buf_size + meta_size_y + \
  1276. meta_size_c; \
  1277. } \
  1278. } while (0)
  1279. #define HFI_BUFFER_DPB_H264E(_size, frame_width, frame_height) \
  1280. do { \
  1281. HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, 0); \
  1282. } while (0)
  1283. #define HFI_BUFFER_DPB_H265E(_size, frame_width, frame_height, is_ten_bit) \
  1284. do { \
  1285. HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, is_ten_bit); \
  1286. } while (0)
  1287. #define HFI_BUFFER_VPSS_ENC(vpss_size, dswidth, dsheight, ds_enable, blur, is_ten_bit) \
  1288. do { \
  1289. vpss_size = 0; \
  1290. if (ds_enable || blur) { \
  1291. HFI_BUFFER_DPB_ENC(vpss_size, dswidth, dsheight, is_ten_bit); \
  1292. } \
  1293. } while (0)
  1294. #define HFI_IRIS2_ENC_MIN_INPUT_BUF_COUNT(numInput, TotalHBLayers) \
  1295. do { \
  1296. numInput = 3; \
  1297. if (TotalHBLayers >= 2) { \
  1298. numInput = (1 << (TotalHBLayers - 1)) + 2; \
  1299. } \
  1300. } while (0)
  1301. #endif /* __HFI_BUFFER_IRIS2__ */