hfi_buffer_iris2.h 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  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) { \
  325. _size = VPP_CMD_MAX_SIZE; \
  326. } \
  327. } while (0)
  328. #define HFI_BUFFER_COMV_H264D(coMV_size, frame_width, \
  329. frame_height, _yuv_bufcount_min) \
  330. do { \
  331. HFI_U32 frame_width_in_mbs = ((frame_width + 15) >> 4); \
  332. HFI_U32 frame_height_in_mbs = ((frame_height + 15) >> 4); \
  333. HFI_U32 col_mv_aligned_width = (frame_width_in_mbs << 7); \
  334. HFI_U32 col_zero_aligned_width = (frame_width_in_mbs << 2); \
  335. HFI_U32 col_zero_size = 0, size_colloc = 0; \
  336. col_mv_aligned_width = HFI_ALIGN(col_mv_aligned_width, \
  337. BUFFER_ALIGNMENT_16_BYTES); \
  338. col_zero_aligned_width = HFI_ALIGN(col_zero_aligned_width, \
  339. BUFFER_ALIGNMENT_16_BYTES); \
  340. col_zero_size = col_zero_aligned_width * \
  341. ((frame_height_in_mbs + 1) >> 1); \
  342. col_zero_size = HFI_ALIGN(col_zero_size, \
  343. BUFFER_ALIGNMENT_64_BYTES); \
  344. col_zero_size <<= 1; \
  345. col_zero_size = HFI_ALIGN(col_zero_size, \
  346. BUFFER_ALIGNMENT_512_BYTES); \
  347. size_colloc = col_mv_aligned_width * ((frame_height_in_mbs + \
  348. 1) >> 1); \
  349. size_colloc = HFI_ALIGN(size_colloc, \
  350. BUFFER_ALIGNMENT_64_BYTES); \
  351. size_colloc <<= 1; \
  352. size_colloc = HFI_ALIGN(size_colloc, \
  353. BUFFER_ALIGNMENT_512_BYTES); \
  354. size_colloc += (col_zero_size + SIZE_H264D_BUFTAB_T * 2); \
  355. coMV_size = size_colloc * (_yuv_bufcount_min); \
  356. coMV_size += BUFFER_ALIGNMENT_512_BYTES; \
  357. } while (0)
  358. #define HFI_BUFFER_NON_COMV_H264D(_size, frame_width, frame_height, \
  359. num_vpp_pipes) \
  360. do { \
  361. HFI_U32 _size_bse, _size_vpp; \
  362. SIZE_H264D_BSE_CMD_BUF(_size_bse, frame_width, frame_height); \
  363. SIZE_H264D_VPP_CMD_BUF(_size_vpp, frame_width, frame_height); \
  364. _size = HFI_ALIGN(_size_bse, VENUS_DMA_ALIGNMENT) + \
  365. HFI_ALIGN(_size_vpp, VENUS_DMA_ALIGNMENT) + \
  366. HFI_ALIGN(SIZE_HW_PIC(SIZE_H264D_HW_PIC_T), \
  367. VENUS_DMA_ALIGNMENT); \
  368. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  369. } while (0)
  370. #define HFI_BUFFER_LINE_H264D(_size, frame_width, frame_height, \
  371. is_opb, num_vpp_pipes) \
  372. do { \
  373. HFI_U32 vpss_lb_size = 0; \
  374. _size = HFI_ALIGN(SIZE_H264D_LB_FE_TOP_DATA(frame_width, \
  375. frame_height), VENUS_DMA_ALIGNMENT) + \
  376. HFI_ALIGN(SIZE_H264D_LB_FE_TOP_CTRL(frame_width, \
  377. frame_height), VENUS_DMA_ALIGNMENT) + \
  378. HFI_ALIGN(SIZE_H264D_LB_FE_LEFT_CTRL(frame_width, \
  379. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  380. HFI_ALIGN(SIZE_H264D_LB_SE_TOP_CTRL(frame_width, \
  381. frame_height), VENUS_DMA_ALIGNMENT) + \
  382. HFI_ALIGN(SIZE_H264D_LB_SE_LEFT_CTRL(frame_width, \
  383. frame_height), VENUS_DMA_ALIGNMENT) * \
  384. num_vpp_pipes + \
  385. HFI_ALIGN(SIZE_H264D_LB_PE_TOP_DATA(frame_width, \
  386. frame_height), VENUS_DMA_ALIGNMENT) + \
  387. HFI_ALIGN(SIZE_H264D_LB_VSP_TOP(frame_width, \
  388. frame_height), VENUS_DMA_ALIGNMENT) + \
  389. HFI_ALIGN(SIZE_H264D_LB_RECON_DMA_METADATA_WR\
  390. (frame_width, frame_height), \
  391. VENUS_DMA_ALIGNMENT) * 2 + HFI_ALIGN(SIZE_H264D_QP\
  392. (frame_width, frame_height), VENUS_DMA_ALIGNMENT); \
  393. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  394. if (is_opb) { \
  395. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  396. num_vpp_pipes); \
  397. } \
  398. _size = HFI_ALIGN((_size + vpss_lb_size), \
  399. VENUS_DMA_ALIGNMENT); \
  400. } while (0)
  401. #define H264_CABAC_HDR_RATIO_HD_TOT 1
  402. #define H264_CABAC_RES_RATIO_HD_TOT 3
  403. #define SIZE_H264D_HW_BIN_BUFFER(_size, frame_width, frame_height, \
  404. delay, num_vpp_pipes) \
  405. do { \
  406. HFI_U32 size_yuv, size_bin_hdr, size_bin_res; \
  407. size_yuv = ((frame_width * frame_height) <= \
  408. BIN_BUFFER_THRESHOLD) ?\
  409. ((BIN_BUFFER_THRESHOLD * 3) >> 1) : \
  410. ((frame_width * frame_height * 3) >> 1); \
  411. size_bin_hdr = size_yuv * H264_CABAC_HDR_RATIO_HD_TOT; \
  412. size_bin_res = size_yuv * H264_CABAC_RES_RATIO_HD_TOT; \
  413. size_bin_hdr = size_bin_hdr * (((((HFI_U32)(delay)) & 31) /\
  414. 10) + 2) / 2; \
  415. size_bin_res = size_bin_res * (((((HFI_U32)(delay)) & 31) /\
  416. 10) + 2) / 2; \
  417. size_bin_hdr = HFI_ALIGN(size_bin_hdr / num_vpp_pipes,\
  418. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  419. size_bin_res = HFI_ALIGN(size_bin_res / num_vpp_pipes, \
  420. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  421. _size = size_bin_hdr + size_bin_res; \
  422. } while (0)
  423. #define HFI_BUFFER_BIN_H264D(_size, frame_width, frame_height, is_interlaced, \
  424. delay, num_vpp_pipes) \
  425. do { \
  426. HFI_U32 n_aligned_w = HFI_ALIGN(frame_width, \
  427. BUFFER_ALIGNMENT_16_BYTES);\
  428. HFI_U32 n_aligned_h = HFI_ALIGN(frame_height, \
  429. BUFFER_ALIGNMENT_16_BYTES); \
  430. if (!is_interlaced) { \
  431. SIZE_H264D_HW_BIN_BUFFER(_size, n_aligned_w, \
  432. n_aligned_h, delay, num_vpp_pipes); \
  433. } else { \
  434. _size = 0; \
  435. } \
  436. } while (0)
  437. #define NUM_SLIST_BUF_H264 (256 + 32)
  438. #define SIZE_SLIST_BUF_H264 (512)
  439. #define SIZE_SEI_USERDATA (4096)
  440. #define H264_NUM_FRM_INFO (66)
  441. #define H264_DISPLAY_BUF_SIZE (3328)
  442. #define SIZE_DOLBY_RPU_METADATA (41 * 1024)
  443. #define HFI_BUFFER_PERSIST_H264D(_size, rpu_enabled) \
  444. (_size = HFI_ALIGN((SIZE_SLIST_BUF_H264 * NUM_SLIST_BUF_H264 + \
  445. H264_DISPLAY_BUF_SIZE * H264_NUM_FRM_INFO + \
  446. NUM_HW_PIC_BUF * SIZE_SEI_USERDATA + \
  447. (rpu_enabled) * NUM_HW_PIC_BUF * SIZE_DOLBY_RPU_METADATA), \
  448. VENUS_DMA_ALIGNMENT))
  449. #define LCU_MAX_SIZE_PELS 64
  450. #define LCU_MIN_SIZE_PELS 16
  451. #define H265D_MAX_SLICE 1200
  452. #define SIZE_H265D_HW_PIC_T SIZE_H264D_HW_PIC_T
  453. #define SIZE_H265D_BSE_CMD_PER_BUF (16 * sizeof(HFI_U32))
  454. #define SIZE_H265D_VPP_CMD_PER_BUF (256)
  455. #define SIZE_H265D_LB_FE_TOP_DATA(frame_width, frame_height) \
  456. (MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE * \
  457. (HFI_ALIGN(frame_width, 64) + 8) * 2)
  458. #define SIZE_H265D_LB_FE_TOP_CTRL(frame_width, frame_height) \
  459. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * \
  460. (HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  461. #define SIZE_H265D_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  462. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * \
  463. (HFI_ALIGN(frame_height, LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  464. #define SIZE_H265D_LB_SE_TOP_CTRL(frame_width, frame_height) \
  465. ((LCU_MAX_SIZE_PELS / 8 * (128 / 8)) * ((frame_width + 15) >> 4))
  466. #define SIZE_H265D_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  467. (MAX(((frame_height + 16 - 1) / 8) * \
  468. MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE, \
  469. MAX(((frame_height + 32 - 1) / 8) * \
  470. MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  471. ((frame_height + 64 - 1) / 8) * \
  472. MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE)))
  473. #define SIZE_H265D_LB_PE_TOP_DATA(frame_width, frame_height) \
  474. (MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE * (HFI_ALIGN(frame_width, \
  475. LCU_MIN_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  476. #define SIZE_H265D_LB_VSP_TOP(frame_width, frame_height) \
  477. (((frame_width + 63) >> 6) * 128)
  478. #define SIZE_H265D_LB_VSP_LEFT(frame_width, frame_height) \
  479. (((frame_height + 63) >> 6) * 128)
  480. #define SIZE_H265D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  481. SIZE_H264D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height)
  482. #define SIZE_H265D_QP(frame_width, frame_height) \
  483. SIZE_H264D_QP(frame_width, frame_height)
  484. #define SIZE_H265D_BSE_CMD_BUF(_size, frame_width, frame_height)\
  485. do { \
  486. _size = HFI_ALIGN(((HFI_ALIGN(frame_width, \
  487. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS) * \
  488. (HFI_ALIGN(frame_height, LCU_MAX_SIZE_PELS) /\
  489. LCU_MIN_SIZE_PELS)) * NUM_HW_PIC_BUF, VENUS_DMA_ALIGNMENT); \
  490. _size = MIN(_size, H265D_MAX_SLICE + 1); \
  491. _size = 2 * _size * SIZE_H265D_BSE_CMD_PER_BUF; \
  492. } while (0)
  493. #define SIZE_H265D_VPP_CMD_BUF(_size, frame_width, frame_height) \
  494. do { \
  495. _size = HFI_ALIGN(((HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) /\
  496. LCU_MIN_SIZE_PELS) * (HFI_ALIGN(frame_height, \
  497. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS)) * \
  498. NUM_HW_PIC_BUF, VENUS_DMA_ALIGNMENT); \
  499. _size = MIN(_size, H265D_MAX_SLICE + 1); \
  500. _size = HFI_ALIGN(_size, 4); \
  501. _size = 2 * _size * SIZE_H265D_VPP_CMD_PER_BUF; \
  502. if (_size > VPP_CMD_MAX_SIZE) { \
  503. _size = VPP_CMD_MAX_SIZE; \
  504. } \
  505. } while (0)
  506. #define HFI_BUFFER_COMV_H265D(_size, frame_width, frame_height, \
  507. _yuv_bufcount_min) \
  508. do { \
  509. _size = HFI_ALIGN(((((frame_width + 15) >> 4) * \
  510. ((frame_height + 15) >> 4)) << 8), \
  511. BUFFER_ALIGNMENT_512_BYTES); \
  512. _size *= _yuv_bufcount_min; \
  513. _size += BUFFER_ALIGNMENT_512_BYTES; \
  514. } while (0)
  515. #define HDR10_HIST_EXTRADATA_SIZE (4 * 1024)
  516. #define HFI_BUFFER_NON_COMV_H265D(_size, frame_width, frame_height, \
  517. num_vpp_pipes) \
  518. do { \
  519. HFI_U32 _size_bse, _size_vpp; \
  520. SIZE_H265D_BSE_CMD_BUF(_size_bse, frame_width, \
  521. frame_height); \
  522. SIZE_H265D_VPP_CMD_BUF(_size_vpp, frame_width, \
  523. frame_height); \
  524. _size = HFI_ALIGN(_size_bse, VENUS_DMA_ALIGNMENT) + \
  525. HFI_ALIGN(_size_vpp, VENUS_DMA_ALIGNMENT) + \
  526. HFI_ALIGN(NUM_HW_PIC_BUF * 20 * 22 * 4, \
  527. VENUS_DMA_ALIGNMENT) + \
  528. HFI_ALIGN(2 * sizeof(HFI_U16) * \
  529. (HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) / \
  530. LCU_MIN_SIZE_PELS) * (HFI_ALIGN(frame_height, \
  531. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS), \
  532. VENUS_DMA_ALIGNMENT) + \
  533. HFI_ALIGN(SIZE_HW_PIC(SIZE_H265D_HW_PIC_T), \
  534. VENUS_DMA_ALIGNMENT) + \
  535. HDR10_HIST_EXTRADATA_SIZE; \
  536. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  537. } while (0)
  538. #define HFI_BUFFER_LINE_H265D(_size, frame_width, frame_height, \
  539. is_opb, num_vpp_pipes) \
  540. do { \
  541. HFI_U32 vpss_lb_size = 0; \
  542. _size = HFI_ALIGN(SIZE_H265D_LB_FE_TOP_DATA(frame_width, \
  543. frame_height), VENUS_DMA_ALIGNMENT) + \
  544. HFI_ALIGN(SIZE_H265D_LB_FE_TOP_CTRL(frame_width, \
  545. frame_height), VENUS_DMA_ALIGNMENT) + \
  546. HFI_ALIGN(SIZE_H265D_LB_FE_LEFT_CTRL(frame_width, \
  547. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  548. HFI_ALIGN(SIZE_H265D_LB_SE_LEFT_CTRL(frame_width, \
  549. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  550. HFI_ALIGN(SIZE_H265D_LB_SE_TOP_CTRL(frame_width, \
  551. frame_height), VENUS_DMA_ALIGNMENT) + \
  552. HFI_ALIGN(SIZE_H265D_LB_PE_TOP_DATA(frame_width, \
  553. frame_height), VENUS_DMA_ALIGNMENT) + \
  554. HFI_ALIGN(SIZE_H265D_LB_VSP_TOP(frame_width, \
  555. frame_height), VENUS_DMA_ALIGNMENT) + \
  556. HFI_ALIGN(SIZE_H265D_LB_VSP_LEFT(frame_width, \
  557. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  558. HFI_ALIGN(SIZE_H265D_LB_RECON_DMA_METADATA_WR\
  559. (frame_width, frame_height), \
  560. VENUS_DMA_ALIGNMENT) * 4 + \
  561. HFI_ALIGN(SIZE_H265D_QP(frame_width, frame_height),\
  562. VENUS_DMA_ALIGNMENT); \
  563. if (is_opb) { \
  564. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height,\
  565. num_vpp_pipes); \
  566. } \
  567. _size = HFI_ALIGN((_size + vpss_lb_size), \
  568. VENUS_DMA_ALIGNMENT); \
  569. } while (0)
  570. #define H265_CABAC_HDR_RATIO_HD_TOT 2
  571. #define H265_CABAC_RES_RATIO_HD_TOT 2
  572. #define SIZE_H265D_HW_BIN_BUFFER(_size, frame_width, frame_height, \
  573. delay, num_vpp_pipes) \
  574. do { \
  575. HFI_U32 size_yuv, size_bin_hdr, size_bin_res; \
  576. size_yuv = ((frame_width * frame_height) <= \
  577. BIN_BUFFER_THRESHOLD) ? \
  578. ((BIN_BUFFER_THRESHOLD * 3) >> 1) : \
  579. ((frame_width * frame_height * 3) >> 1); \
  580. size_bin_hdr = size_yuv * H265_CABAC_HDR_RATIO_HD_TOT; \
  581. size_bin_res = size_yuv * H265_CABAC_RES_RATIO_HD_TOT; \
  582. size_bin_hdr = size_bin_hdr * \
  583. (((((HFI_U32)(delay)) & 31) / 10) + 2) / 2; \
  584. size_bin_res = size_bin_res * \
  585. (((((HFI_U32)(delay)) & 31) / 10) + 2) / 2; \
  586. size_bin_hdr = HFI_ALIGN(size_bin_hdr / \
  587. num_vpp_pipes, VENUS_DMA_ALIGNMENT) * \
  588. num_vpp_pipes; \
  589. size_bin_res = HFI_ALIGN(size_bin_res / num_vpp_pipes,\
  590. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  591. _size = size_bin_hdr + size_bin_res; \
  592. } while (0)
  593. #define HFI_BUFFER_BIN_H265D(_size, frame_width, frame_height, \
  594. is_interlaced, delay, num_vpp_pipes) \
  595. do { \
  596. HFI_U32 n_aligned_w = HFI_ALIGN(frame_width, \
  597. BUFFER_ALIGNMENT_16_BYTES); \
  598. HFI_U32 n_aligned_h = HFI_ALIGN(frame_height, \
  599. BUFFER_ALIGNMENT_16_BYTES); \
  600. if (!is_interlaced) { \
  601. SIZE_H265D_HW_BIN_BUFFER(_size, n_aligned_w, \
  602. n_aligned_h, delay, num_vpp_pipes); \
  603. } else { \
  604. _size = 0; \
  605. } \
  606. } while (0)
  607. #define SIZE_SLIST_BUF_H265 (1 << 10)
  608. #define NUM_SLIST_BUF_H265 (80 + 20)
  609. #define H265_NUM_TILE_COL 32
  610. #define H265_NUM_TILE_ROW 128
  611. #define H265_NUM_TILE (H265_NUM_TILE_ROW * H265_NUM_TILE_COL + 1)
  612. #define H265_NUM_FRM_INFO (48)
  613. #define H265_DISPLAY_BUF_SIZE (3072)
  614. #define HFI_BUFFER_PERSIST_H265D(_size, rpu_enabled) \
  615. (_size = HFI_ALIGN((SIZE_SLIST_BUF_H265 * NUM_SLIST_BUF_H265 + \
  616. H265_NUM_FRM_INFO * H265_DISPLAY_BUF_SIZE + \
  617. H265_NUM_TILE * sizeof(HFI_U32) + NUM_HW_PIC_BUF * SIZE_SEI_USERDATA + \
  618. (rpu_enabled) * NUM_HW_PIC_BUF * SIZE_DOLBY_RPU_METADATA),\
  619. VENUS_DMA_ALIGNMENT))
  620. #define SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  621. MAX(((frame_height + 15) >> 4) * \
  622. MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE, \
  623. MAX(((frame_height + 31) >> 5) * \
  624. MAX_FE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  625. ((frame_height + 63) >> 6) * MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE))
  626. #define SIZE_VPXD_LB_FE_TOP_CTRL(frame_width, frame_height) \
  627. (((HFI_ALIGN(frame_width, 64) + 8) * 10 * 2))
  628. #define SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height) \
  629. (((frame_width + 15) >> 4) * MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE)
  630. #define SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  631. MAX(((frame_height + 15) >> 4) * \
  632. MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE,\
  633. MAX(((frame_height + 31) >> 5) * \
  634. MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  635. ((frame_height + 63) >> 6) * MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE))
  636. #define SIZE_VPXD_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  637. HFI_ALIGN((HFI_ALIGN(frame_height, 8) / (4 / 2)) * 64,\
  638. BUFFER_ALIGNMENT_32_BYTES)
  639. #define SIZE_MP2D_LB_FE_TOP_DATA(frame_width, frame_height) \
  640. ((HFI_ALIGN(frame_width, 16) + 8) * 10 * 2)
  641. #define SIZE_VP9D_LB_FE_TOP_DATA(frame_width, frame_height) \
  642. ((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) + 8) * 10 * 2)
  643. #define SIZE_MP2D_LB_PE_TOP_DATA(frame_width, frame_height) \
  644. ((HFI_ALIGN(frame_width, 16) >> 4) * 64)
  645. #define SIZE_VP9D_LB_PE_TOP_DATA(frame_width, frame_height) \
  646. ((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) >> 6) * 176)
  647. #define SIZE_MP2D_LB_VSP_TOP(frame_width, frame_height) \
  648. (((HFI_ALIGN(frame_width, 16) >> 4) * 64 / 2) + 256)
  649. #define SIZE_VP9D_LB_VSP_TOP(frame_width, frame_height) \
  650. ((((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) >> 6) * 64 * 8) + 256))
  651. #define HFI_IRIS2_VP9D_COMV_SIZE \
  652. ((((8192 + 63) >> 6) * ((4320 + 63) >> 6) * 8 * 8 * 2 * 8))
  653. #define SIZE_VP9D_QP(frame_width, frame_height) \
  654. SIZE_H264D_QP(frame_width, frame_height)
  655. #define HFI_IRIS2_VP9D_LB_SIZE(_size, frame_width, frame_height, num_vpp_pipes)\
  656. do { \
  657. _size = HFI_ALIGN(SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, \
  658. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  659. HFI_ALIGN(SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height),\
  660. VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  661. HFI_ALIGN(SIZE_VP9D_LB_VSP_TOP(frame_width, frame_height), \
  662. VENUS_DMA_ALIGNMENT) + \
  663. HFI_ALIGN(SIZE_VPXD_LB_FE_TOP_CTRL(frame_width, frame_height), \
  664. VENUS_DMA_ALIGNMENT) + 2 * \
  665. HFI_ALIGN(SIZE_VPXD_LB_RECON_DMA_METADATA_WR \
  666. (frame_width, frame_height), VENUS_DMA_ALIGNMENT) + \
  667. HFI_ALIGN(SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height), \
  668. VENUS_DMA_ALIGNMENT) + \
  669. HFI_ALIGN(SIZE_VP9D_LB_PE_TOP_DATA(frame_width, frame_height), \
  670. VENUS_DMA_ALIGNMENT) + \
  671. HFI_ALIGN(SIZE_VP9D_LB_FE_TOP_DATA(frame_width, frame_height), \
  672. VENUS_DMA_ALIGNMENT) + \
  673. HFI_ALIGN(SIZE_VP9D_QP(frame_width, frame_height), \
  674. VENUS_DMA_ALIGNMENT); \
  675. } while (0)
  676. #define HFI_BUFFER_LINE_VP9D(_size, frame_width, frame_height, \
  677. _yuv_bufcount_min, is_opb, num_vpp_pipes) \
  678. do { \
  679. HFI_U32 _lb_size = 0; \
  680. HFI_U32 vpss_lb_size = 0; \
  681. HFI_IRIS2_VP9D_LB_SIZE(_lb_size, frame_width, frame_height,\
  682. num_vpp_pipes); \
  683. if (is_opb) { \
  684. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  685. num_vpp_pipes); \
  686. } \
  687. _size = _lb_size + vpss_lb_size; \
  688. } while (0)
  689. #define VPX_DECODER_FRAME_CONCURENCY_LVL (2)
  690. #define VPX_DECODER_FRAME_BIN_HDR_BUDGET_RATIO 1 / 2
  691. #define VPX_DECODER_FRAME_BIN_RES_BUDGET_RATIO 3 / 2
  692. #define HFI_BUFFER_BIN_VP9D(_size, frame_width, frame_height, \
  693. is_interlaced, num_vpp_pipes) \
  694. do { \
  695. HFI_U32 _size_yuv = HFI_ALIGN(frame_width, \
  696. BUFFER_ALIGNMENT_16_BYTES) *\
  697. HFI_ALIGN(frame_height, BUFFER_ALIGNMENT_16_BYTES) * 3 / 2; \
  698. if (!is_interlaced) { \
  699. _size = HFI_ALIGN(((MAX(_size_yuv, \
  700. ((BIN_BUFFER_THRESHOLD * 3) >> 1)) * \
  701. VPX_DECODER_FRAME_BIN_HDR_BUDGET_RATIO * \
  702. VPX_DECODER_FRAME_CONCURENCY_LVL) / num_vpp_pipes), \
  703. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(((MAX(_size_yuv, \
  704. ((BIN_BUFFER_THRESHOLD * 3) >> 1)) * \
  705. VPX_DECODER_FRAME_BIN_RES_BUDGET_RATIO * \
  706. VPX_DECODER_FRAME_CONCURENCY_LVL) / num_vpp_pipes), \
  707. VENUS_DMA_ALIGNMENT); \
  708. _size = _size * num_vpp_pipes; \
  709. } \
  710. else \
  711. _size = 0; \
  712. } while (0)
  713. #define VP9_NUM_FRAME_INFO_BUF 32
  714. #define VP9_NUM_PROBABILITY_TABLE_BUF (VP9_NUM_FRAME_INFO_BUF + 4)
  715. #define VP9_PROB_TABLE_SIZE (3840)
  716. #define VP9_FRAME_INFO_BUF_SIZE (6144)
  717. #define VP9_UDC_HEADER_BUF_SIZE (3 * 128)
  718. #define MAX_SUPERFRAME_HEADER_LEN (34)
  719. #define CCE_TILE_OFFSET_SIZE HFI_ALIGN(32 * 4 * 4, BUFFER_ALIGNMENT_32_BYTES)
  720. #define HFI_BUFFER_PERSIST_VP9D(_size) \
  721. (_size = HFI_ALIGN(VP9_NUM_PROBABILITY_TABLE_BUF * VP9_PROB_TABLE_SIZE, \
  722. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(HFI_IRIS2_VP9D_COMV_SIZE, \
  723. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(MAX_SUPERFRAME_HEADER_LEN, \
  724. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(VP9_UDC_HEADER_BUF_SIZE, \
  725. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(VP9_NUM_FRAME_INFO_BUF * \
  726. CCE_TILE_OFFSET_SIZE, VENUS_DMA_ALIGNMENT) + \
  727. HFI_ALIGN(VP9_NUM_FRAME_INFO_BUF * VP9_FRAME_INFO_BUF_SIZE, \
  728. VENUS_DMA_ALIGNMENT) + HDR10_HIST_EXTRADATA_SIZE)
  729. #define HFI_BUFFER_LINE_MP2D(_size, frame_width, frame_height, \
  730. _yuv_bufcount_min, is_opb, num_vpp_pipes) \
  731. do { \
  732. HFI_U32 vpss_lb_size = 0; \
  733. _size = HFI_ALIGN(SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, \
  734. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  735. HFI_ALIGN(SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height),\
  736. VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  737. HFI_ALIGN(SIZE_MP2D_LB_VSP_TOP(frame_width, frame_height),\
  738. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(SIZE_VPXD_LB_FE_TOP_CTRL\
  739. (frame_width, frame_height), VENUS_DMA_ALIGNMENT) + \
  740. 2 * HFI_ALIGN(SIZE_VPXD_LB_RECON_DMA_METADATA_WR(frame_width,\
  741. frame_height), VENUS_DMA_ALIGNMENT) + \
  742. HFI_ALIGN(SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height),\
  743. VENUS_DMA_ALIGNMENT) + \
  744. HFI_ALIGN(SIZE_MP2D_LB_PE_TOP_DATA(frame_width, frame_height), \
  745. VENUS_DMA_ALIGNMENT) + \
  746. HFI_ALIGN(SIZE_MP2D_LB_FE_TOP_DATA(frame_width, frame_height), \
  747. VENUS_DMA_ALIGNMENT); \
  748. if (is_opb) { \
  749. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  750. num_vpp_pipes); \
  751. } \
  752. _size += vpss_lb_size; \
  753. } while (0)
  754. #define HFI_BUFFER_BIN_MP2D(_size, frame_width, frame_height, is_interlaced) 0
  755. #define QMATRIX_SIZE (sizeof(HFI_U32) * 128 + 256)
  756. #define MP2D_QPDUMP_SIZE 115200
  757. #define HFI_BUFFER_PERSIST_MP2D(_size) \
  758. (_size = QMATRIX_SIZE + MP2D_QPDUMP_SIZE;)
  759. #define HFI_BUFFER_BITSTREAM_ENC(size, frame_width, frame_height, \
  760. rc_type, is_ten_bit) \
  761. do { \
  762. HFI_U32 aligned_width, aligned_height, bitstream_size; \
  763. aligned_width = HFI_ALIGN(frame_width, 32); \
  764. aligned_height = HFI_ALIGN(frame_height, 32); \
  765. bitstream_size = aligned_width * aligned_height * 3; \
  766. if (aligned_width * aligned_height > (4096 * 2176)) { \
  767. bitstream_size = (bitstream_size >> 3); \
  768. } \
  769. else if (bitstream_size > (1280 * 720)) { \
  770. bitstream_size = (bitstream_size >> 2); \
  771. } else { \
  772. bitstream_size = (bitstream_size << 1);\
  773. } \
  774. if ((rc_type == HFI_RC_CQ) || (rc_type == HFI_RC_OFF)) { \
  775. bitstream_size = (bitstream_size << 1);\
  776. } \
  777. if (is_ten_bit) { \
  778. bitstream_size = (bitstream_size) + \
  779. (bitstream_size >> 2); \
  780. } \
  781. size = HFI_ALIGN(bitstream_size, HFI_ALIGNMENT_4096); \
  782. } while (0)
  783. #define SIZE_ROI_METADATA_ENC(size_roi, frame_width, frame_height, lcu_size)\
  784. do { \
  785. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, n_shift = 0; \
  786. while (lcu_size && !(lcu_size & 0x1)) { \
  787. n_shift++; \
  788. lcu_size = lcu_size >> 1; \
  789. } \
  790. width_in_lcus = (frame_width + (lcu_size - 1)) >> n_shift; \
  791. height_in_lcus = (frame_height + (lcu_size - 1)) >> n_shift; \
  792. size_roi = (((width_in_lcus + 7) >> 3) << 3) * \
  793. height_in_lcus * 2 + 256; \
  794. } while (0)
  795. #define HFI_BUFFER_INPUT_METADATA_ENC(size, frame_width, frame_height, \
  796. is_roi_enabled, lcu_size) \
  797. do { \
  798. HFI_U32 roi_size = 0; \
  799. if (is_roi_enabled) { \
  800. SIZE_ROI_METADATA_ENC(roi_size, frame_width, \
  801. frame_height, lcu_size); \
  802. } \
  803. size = roi_size + 16384; \
  804. size = HFI_ALIGN(size, HFI_ALIGNMENT_4096); \
  805. } while (0)
  806. #define HFI_BUFFER_INPUT_METADATA_H264E(size_metadata, frame_width, \
  807. frame_height, is_roi_enabled) \
  808. do { \
  809. HFI_BUFFER_INPUT_METADATA_ENC(size_metadata, frame_width, \
  810. frame_height, is_roi_enabled, 16); \
  811. } while (0)
  812. #define HFI_BUFFER_INPUT_METADATA_H265E(size_metadata, frame_width, \
  813. frame_height, is_roi_enabled) \
  814. do { \
  815. HFI_BUFFER_INPUT_METADATA_ENC(size_metadata, frame_width, \
  816. frame_height, is_roi_enabled, 32); \
  817. } while (0)
  818. #define HFI_BUFFER_ARP_ENC(size) \
  819. do { \
  820. size = 204800; \
  821. } while (0)
  822. #define HFI_MAX_COL_FRAME 6
  823. #define HFI_VENUS_VENC_TRE_WB_BUFF_SIZE (65 << 4) // bytes
  824. #define HFI_VENUS_VENC_DB_LINE_BUFF_PER_MB 512
  825. #define HFI_VENUS_VPPSG_MAX_REGISTERS 2048
  826. #define HFI_VENUS_WIDTH_ALIGNMENT 128
  827. #define HFI_VENUS_WIDTH_TEN_BIT_ALIGNMENT 192
  828. #define HFI_VENUS_HEIGHT_ALIGNMENT 32
  829. #define VENUS_METADATA_STRIDE_MULTIPLE 64
  830. #define VENUS_METADATA_HEIGHT_MULTIPLE 16
  831. #ifndef SYSTEM_LAL_TILE10
  832. #define SYSTEM_LAL_TILE10 192
  833. #endif
  834. #define HFI_IRIS2_ENC_RECON_BUF_COUNT(num_recon, n_bframe, ltr_count, \
  835. _total_hp_layers, _total_hb_layers, hybrid_hp, codec_standard) \
  836. do { \
  837. HFI_U32 num_ref = 1; \
  838. if (n_bframe) \
  839. num_ref = 2; \
  840. if (_total_hp_layers > 1) { \
  841. if (hybrid_hp) \
  842. num_ref = (_total_hp_layers + 1) >> 1; \
  843. else if (codec_standard == HFI_CODEC_ENCODE_HEVC) \
  844. num_ref = (_total_hp_layers + 1) >> 1; \
  845. else if (codec_standard == HFI_CODEC_ENCODE_AVC && \
  846. _total_hp_layers < 4) \
  847. num_ref = (_total_hp_layers - 1); \
  848. else \
  849. num_ref = _total_hp_layers; \
  850. } \
  851. if (ltr_count) \
  852. num_ref = num_ref + ltr_count; \
  853. if (_total_hb_layers > 1) { \
  854. if (codec_standard == HFI_CODEC_ENCODE_HEVC) \
  855. num_ref = (_total_hb_layers); \
  856. else if (codec_standard == HFI_CODEC_ENCODE_AVC) \
  857. num_ref = (1 << (_total_hb_layers - 2)) + 1; \
  858. } \
  859. num_recon = num_ref + 1; \
  860. } while (0)
  861. #define SIZE_BIN_BITSTREAM_ENC(_size, rc_type, frame_width, frame_height, \
  862. work_mode, lcu_size) \
  863. do { \
  864. HFI_U32 size_aligned_width = 0, size_aligned_height = 0; \
  865. HFI_U32 bitstream_size_eval = 0; \
  866. size_aligned_width = HFI_ALIGN((frame_width), lcu_size); \
  867. size_aligned_height = HFI_ALIGN((frame_height), lcu_size); \
  868. if (work_mode == HFI_WORKMODE_2) { \
  869. if ((rc_type == HFI_RC_CQ) || (rc_type == HFI_RC_OFF)) { \
  870. bitstream_size_eval = (((size_aligned_width) * \
  871. (size_aligned_height) * 3) >> 1); \
  872. } \
  873. else { \
  874. bitstream_size_eval = ((size_aligned_width) * \
  875. (size_aligned_height) * 3); \
  876. if (rc_type == HFI_RC_LOSSLESS) { \
  877. bitstream_size_eval = (bitstream_size_eval * 3 >> 2); \
  878. } \
  879. else if ((size_aligned_width * size_aligned_height) > \
  880. (4096 * 2176)) { \
  881. bitstream_size_eval >>= 3; \
  882. } \
  883. else if ((size_aligned_width * size_aligned_height) > \
  884. (480 * 320)) { \
  885. bitstream_size_eval >>= 2; \
  886. } \
  887. if (lcu_size == 32) { \
  888. bitstream_size_eval = (bitstream_size_eval * 5 >> 2); \
  889. } \
  890. } \
  891. } else { \
  892. bitstream_size_eval = size_aligned_width * \
  893. size_aligned_height * 3; \
  894. } \
  895. _size = HFI_ALIGN(bitstream_size_eval, VENUS_DMA_ALIGNMENT); \
  896. } while (0)
  897. #define SIZE_ENC_SINGLE_PIPE(size, rc_type, bitbin_size, num_vpp_pipes, \
  898. frame_width, frame_height, lcu_size) \
  899. do { \
  900. HFI_U32 size_single_pipe_eval = 0, sao_bin_buffer_size = 0, \
  901. _padded_bin_sz = 0; \
  902. HFI_U32 size_aligned_width = 0, size_aligned_height = 0; \
  903. size_aligned_width = HFI_ALIGN((frame_width), lcu_size); \
  904. size_aligned_height = HFI_ALIGN((frame_height), lcu_size); \
  905. if ((size_aligned_width * size_aligned_height) > \
  906. (3840 * 2160)) { \
  907. size_single_pipe_eval = (bitbin_size / num_vpp_pipes); \
  908. } \
  909. else if (num_vpp_pipes > 2) { \
  910. size_single_pipe_eval = bitbin_size / 2; \
  911. } else { \
  912. size_single_pipe_eval = bitbin_size; \
  913. } \
  914. if (rc_type == HFI_RC_LOSSLESS) { \
  915. size_single_pipe_eval = (size_single_pipe_eval << 1); \
  916. } \
  917. sao_bin_buffer_size = (64 * ((((frame_width) + \
  918. BUFFER_ALIGNMENT_32_BYTES) * ((frame_height) +\
  919. BUFFER_ALIGNMENT_32_BYTES)) >> 10)) + 384; \
  920. _padded_bin_sz = HFI_ALIGN(size_single_pipe_eval, \
  921. VENUS_DMA_ALIGNMENT);\
  922. size_single_pipe_eval = sao_bin_buffer_size + _padded_bin_sz; \
  923. size_single_pipe_eval = HFI_ALIGN(size_single_pipe_eval, \
  924. VENUS_DMA_ALIGNMENT); \
  925. size = size_single_pipe_eval; \
  926. } while (0)
  927. #define HFI_BUFFER_BIN_ENC(_size, rc_type, frame_width, frame_height, lcu_size, \
  928. work_mode, num_vpp_pipes) \
  929. do { \
  930. HFI_U32 bitstream_size = 0, total_bitbin_buffers = 0, \
  931. size_single_pipe = 0, bitbin_size = 0; \
  932. SIZE_BIN_BITSTREAM_ENC(bitstream_size, rc_type, frame_width, \
  933. frame_height, work_mode, lcu_size); \
  934. if (work_mode == HFI_WORKMODE_2) { \
  935. total_bitbin_buffers = 3; \
  936. bitbin_size = bitstream_size * 17 / 10; \
  937. bitbin_size = HFI_ALIGN(bitbin_size, \
  938. VENUS_DMA_ALIGNMENT); \
  939. } \
  940. else if ((lcu_size == 16) || (num_vpp_pipes > 1)) { \
  941. total_bitbin_buffers = 1; \
  942. bitbin_size = bitstream_size; \
  943. } \
  944. if (total_bitbin_buffers > 0) { \
  945. SIZE_ENC_SINGLE_PIPE(size_single_pipe, rc_type, bitbin_size, \
  946. num_vpp_pipes, frame_width, frame_height, lcu_size); \
  947. bitbin_size = size_single_pipe * num_vpp_pipes; \
  948. _size = HFI_ALIGN(bitbin_size, VENUS_DMA_ALIGNMENT) * \
  949. total_bitbin_buffers + 512; \
  950. } else { \
  951. /* Avoid 512 Bytes allocation in case of 1Pipe HEVC Direct Mode*/ \
  952. _size = 0; \
  953. } \
  954. } while (0)
  955. #define HFI_BUFFER_BIN_H264E(_size, rc_type, frame_width, frame_height, \
  956. work_mode, num_vpp_pipes) \
  957. do { \
  958. HFI_BUFFER_BIN_ENC(_size, rc_type, frame_width, frame_height, 16, \
  959. work_mode, num_vpp_pipes); \
  960. } while (0)
  961. #define HFI_BUFFER_BIN_H265E(_size, rc_type, frame_width, frame_height, \
  962. work_mode, num_vpp_pipes) \
  963. do { \
  964. HFI_BUFFER_BIN_ENC(_size, rc_type, frame_width, frame_height, 32,\
  965. work_mode, num_vpp_pipes); \
  966. } while (0)
  967. #define SIZE_ENC_SLICE_INFO_BUF(num_lcu_in_frame) HFI_ALIGN((256 + \
  968. (num_lcu_in_frame << 4)), VENUS_DMA_ALIGNMENT)
  969. #define SIZE_LINE_BUF_CTRL(frame_width_coded) \
  970. HFI_ALIGN(frame_width_coded, VENUS_DMA_ALIGNMENT)
  971. #define SIZE_LINE_BUF_CTRL_ID2(frame_width_coded) \
  972. HFI_ALIGN(frame_width_coded, VENUS_DMA_ALIGNMENT)
  973. #define SIZE_LINEBUFF_DATA(_size, is_ten_bit, frame_width_coded) \
  974. do { \
  975. _size = is_ten_bit ? (((((10 * (frame_width_coded) +\
  976. 1024) + (VENUS_DMA_ALIGNMENT - 1)) & \
  977. (~(VENUS_DMA_ALIGNMENT - 1))) * 1) + \
  978. (((((10 * (frame_width_coded) + 1024) >> 1) + \
  979. (VENUS_DMA_ALIGNMENT - 1)) & (~(VENUS_DMA_ALIGNMENT - 1))) * \
  980. 2)) : (((((8 * (frame_width_coded) + 1024) + \
  981. (VENUS_DMA_ALIGNMENT - 1)) \
  982. & (~(VENUS_DMA_ALIGNMENT - 1))) * 1) + \
  983. (((((8 * (frame_width_coded) +\
  984. 1024) >> 1) + (VENUS_DMA_ALIGNMENT - 1)) & \
  985. (~(VENUS_DMA_ALIGNMENT - 1))) * 2)); \
  986. } while (0)
  987. #define SIZE_LEFT_LINEBUFF_CTRL(_size, standard, frame_height_coded, \
  988. num_vpp_pipes_enc) \
  989. do { \
  990. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? \
  991. (((frame_height_coded) + \
  992. (BUF_SIZE_ALIGN_32)) / BUF_SIZE_ALIGN_32 * 4 * 16) : \
  993. (((frame_height_coded) + 15) / 16 * 5 * 16); \
  994. if ((num_vpp_pipes_enc) > 1) { \
  995. _size += BUFFER_ALIGNMENT_512_BYTES; \
  996. _size = HFI_ALIGN(_size, BUFFER_ALIGNMENT_512_BYTES) *\
  997. (num_vpp_pipes_enc); \
  998. } \
  999. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1000. } while (0)
  1001. #define SIZE_LEFT_LINEBUFF_RECON_PIX(_size, is_ten_bit, frame_height_coded, \
  1002. num_vpp_pipes_enc) \
  1003. do { \
  1004. _size = (((is_ten_bit + 1) * 2 * (frame_height_coded) + \
  1005. VENUS_DMA_ALIGNMENT) + \
  1006. (VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1) & \
  1007. (~((VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1)) * 1; \
  1008. } while (0)
  1009. #define SIZE_TOP_LINEBUFF_CTRL_FE(_size, frame_width_coded, standard) \
  1010. do { \
  1011. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? (64 * \
  1012. ((frame_width_coded) >> 5)) : (VENUS_DMA_ALIGNMENT + 16 * \
  1013. ((frame_width_coded) >> 4)); \
  1014. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1015. } while (0)
  1016. #define SIZE_LEFT_LINEBUFF_CTRL_FE(frame_height_coded, num_vpp_pipes_enc) \
  1017. ((((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) >> 4)) + \
  1018. (VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1) & \
  1019. (~((VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1)) * 1) * \
  1020. num_vpp_pipes_enc)
  1021. #define SIZE_LEFT_LINEBUFF_METADATA_RECON_Y(_size, frame_height_coded, \
  1022. is_ten_bit, num_vpp_pipes_enc) \
  1023. do { \
  1024. _size = ((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) / \
  1025. (8 * (is_ten_bit ? 4 : 8))))); \
  1026. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1027. _size = (_size * num_vpp_pipes_enc); \
  1028. } while (0)
  1029. #define SIZE_LEFT_LINEBUFF_METADATA_RECON_UV(_size, frame_height_coded, \
  1030. is_ten_bit, num_vpp_pipes_enc) \
  1031. do { \
  1032. _size = ((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) / \
  1033. (4 * (is_ten_bit ? 4 : 8))))); \
  1034. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1035. _size = (_size * num_vpp_pipes_enc); \
  1036. } while (0)
  1037. #define SIZE_LINEBUFF_RECON_PIX(_size, is_ten_bit, frame_width_coded) \
  1038. do { \
  1039. _size = ((is_ten_bit ? 3 : 2) * (frame_width_coded)); \
  1040. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1041. } while (0)
  1042. #define SIZE_SLICE_CMD_BUFFER (HFI_ALIGN(20480, VENUS_DMA_ALIGNMENT))
  1043. #define SIZE_SPS_PPS_SLICE_HDR (2048 + 4096)
  1044. #define SIZE_FRAME_RC_BUF_SIZE(_size, standard, frame_height_coded, \
  1045. num_vpp_pipes_enc) \
  1046. do { \
  1047. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? (256 + 16 * \
  1048. (14 + ((((frame_height_coded) >> 5) + 7) >> 3))) : \
  1049. (256 + 16 * (14 + ((((frame_height_coded) >> 4) + 7) >> 3))); \
  1050. _size *= 11; \
  1051. if (num_vpp_pipes_enc > 1) { \
  1052. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT) * \
  1053. num_vpp_pipes_enc;\
  1054. } \
  1055. _size = HFI_ALIGN(_size, BUFFER_ALIGNMENT_512_BYTES) * \
  1056. HFI_MAX_COL_FRAME; \
  1057. } while (0)
  1058. #define ENC_BITCNT_BUF_SIZE(num_lcu_in_frame) HFI_ALIGN((256 + \
  1059. (4 * (num_lcu_in_frame))), VENUS_DMA_ALIGNMENT)
  1060. #define ENC_BITMAP_BUF_SIZE(num_lcu_in_frame) HFI_ALIGN((256 + \
  1061. ((num_lcu_in_frame) >> 3)), VENUS_DMA_ALIGNMENT)
  1062. #define SIZE_LINE_BUF_SDE(frame_width_coded) HFI_ALIGN((256 + \
  1063. (16 * ((frame_width_coded) >> 4))), VENUS_DMA_ALIGNMENT)
  1064. #define SIZE_BSE_SLICE_CMD_BUF ((((8192 << 2) + 7) & (~7)) * 3)
  1065. #define SIZE_LAMBDA_LUT (256 * 11)
  1066. #define SIZE_OVERRIDE_BUF(num_lcumb) (HFI_ALIGN(((16 * (((num_lcumb) + 7)\
  1067. >> 3))), VENUS_DMA_ALIGNMENT) * 2)
  1068. #define SIZE_IR_BUF(num_lcu_in_frame) HFI_ALIGN((((((num_lcu_in_frame) << 1) + 7) &\
  1069. (~7)) * 3), VENUS_DMA_ALIGNMENT)
  1070. #define SIZE_VPSS_LINE_BUF(num_vpp_pipes_enc, frame_height_coded, \
  1071. frame_width_coded) \
  1072. (HFI_ALIGN(((((((8192) >> 2) << 5) * (num_vpp_pipes_enc)) + 64) + \
  1073. (((((MAX((frame_width_coded), (frame_height_coded)) + 3) >> 2) << 5) +\
  1074. 256) * 16)), VENUS_DMA_ALIGNMENT))
  1075. #define SIZE_TOP_LINE_BUF_FIRST_STG_SAO(frame_width_coded) \
  1076. HFI_ALIGN((16 * ((frame_width_coded) >> 5)), VENUS_DMA_ALIGNMENT)
  1077. #define HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, is_ten_bit, \
  1078. num_vpp_pipes_enc, lcu_size, standard) \
  1079. do { \
  1080. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, \
  1081. frame_width_coded = 0, frame_height_coded = 0; \
  1082. HFI_U32 line_buff_data_size = 0, left_line_buff_ctrl_size = 0, \
  1083. left_line_buff_recon_pix_size = 0, \
  1084. top_line_buff_ctrl_fe_size = 0; \
  1085. HFI_U32 left_line_buff_metadata_recon__y__size = 0, \
  1086. left_line_buff_metadata_recon__uv__size = 0, \
  1087. line_buff_recon_pix_size = 0; \
  1088. width_in_lcus = ((frame_width) + (lcu_size)-1) / (lcu_size); \
  1089. height_in_lcus = ((frame_height) + (lcu_size)-1) / (lcu_size); \
  1090. frame_width_coded = width_in_lcus * (lcu_size); \
  1091. frame_height_coded = height_in_lcus * (lcu_size); \
  1092. SIZE_LINEBUFF_DATA(line_buff_data_size, is_ten_bit, \
  1093. frame_width_coded);\
  1094. SIZE_LEFT_LINEBUFF_CTRL(left_line_buff_ctrl_size, standard, \
  1095. frame_height_coded, num_vpp_pipes_enc); \
  1096. SIZE_LEFT_LINEBUFF_RECON_PIX(left_line_buff_recon_pix_size, \
  1097. is_ten_bit, frame_height_coded, num_vpp_pipes_enc); \
  1098. SIZE_TOP_LINEBUFF_CTRL_FE(top_line_buff_ctrl_fe_size, \
  1099. frame_width_coded, standard); \
  1100. SIZE_LEFT_LINEBUFF_METADATA_RECON_Y\
  1101. (left_line_buff_metadata_recon__y__size, \
  1102. frame_height_coded, is_ten_bit, num_vpp_pipes_enc); \
  1103. SIZE_LEFT_LINEBUFF_METADATA_RECON_UV\
  1104. (left_line_buff_metadata_recon__uv__size, \
  1105. frame_height_coded, is_ten_bit, num_vpp_pipes_enc); \
  1106. SIZE_LINEBUFF_RECON_PIX(line_buff_recon_pix_size, is_ten_bit,\
  1107. frame_width_coded); \
  1108. _size = SIZE_LINE_BUF_CTRL(frame_width_coded) + \
  1109. SIZE_LINE_BUF_CTRL_ID2(frame_width_coded) + \
  1110. line_buff_data_size + \
  1111. left_line_buff_ctrl_size + \
  1112. left_line_buff_recon_pix_size + \
  1113. top_line_buff_ctrl_fe_size + \
  1114. left_line_buff_metadata_recon__y__size + \
  1115. left_line_buff_metadata_recon__uv__size + \
  1116. line_buff_recon_pix_size + \
  1117. SIZE_LEFT_LINEBUFF_CTRL_FE(frame_height_coded, \
  1118. num_vpp_pipes_enc) + SIZE_LINE_BUF_SDE(frame_width_coded) + \
  1119. SIZE_VPSS_LINE_BUF(num_vpp_pipes_enc, frame_height_coded, \
  1120. frame_width_coded) + \
  1121. SIZE_TOP_LINE_BUF_FIRST_STG_SAO(frame_width_coded); \
  1122. } while (0)
  1123. #define HFI_BUFFER_LINE_H264E(_size, frame_width, frame_height, is_ten_bit, \
  1124. num_vpp_pipes) \
  1125. do { \
  1126. HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, 0, \
  1127. num_vpp_pipes, 16, HFI_CODEC_ENCODE_AVC); \
  1128. } while (0)
  1129. #define HFI_BUFFER_LINE_H265E(_size, frame_width, frame_height, is_ten_bit, \
  1130. num_vpp_pipes) \
  1131. do { \
  1132. HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, \
  1133. is_ten_bit, num_vpp_pipes, 32, HFI_CODEC_ENCODE_HEVC); \
  1134. } while (0)
  1135. #define HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, lcu_size, \
  1136. num_recon, standard) \
  1137. do { \
  1138. HFI_U32 size_colloc_mv = 0, size_colloc_rc = 0; \
  1139. HFI_U32 mb_width = ((frame_width) + 15) >> 4; \
  1140. HFI_U32 mb_height = ((frame_height) + 15) >> 4; \
  1141. HFI_U32 width_in_lcus = ((frame_width) + (lcu_size)-1) /\
  1142. (lcu_size); \
  1143. HFI_U32 height_in_lcus = ((frame_height) + (lcu_size)-1) / \
  1144. (lcu_size); \
  1145. HFI_U32 num_lcu_in_frame = width_in_lcus * height_in_lcus; \
  1146. size_colloc_mv = (standard == HFI_CODEC_ENCODE_HEVC) ? \
  1147. (16 * ((num_lcu_in_frame << 2) + BUFFER_ALIGNMENT_32_BYTES)) : \
  1148. (3 * 16 * (width_in_lcus * height_in_lcus +\
  1149. BUFFER_ALIGNMENT_32_BYTES)); \
  1150. size_colloc_mv = HFI_ALIGN(size_colloc_mv, \
  1151. VENUS_DMA_ALIGNMENT) * num_recon; \
  1152. size_colloc_rc = (((mb_width + 7) >> 3) * 16 * 2 * mb_height); \
  1153. size_colloc_rc = HFI_ALIGN(size_colloc_rc, \
  1154. VENUS_DMA_ALIGNMENT) * HFI_MAX_COL_FRAME; \
  1155. _size = size_colloc_mv + size_colloc_rc; \
  1156. } while (0)
  1157. #define HFI_BUFFER_COMV_H264E(_size, frame_width, frame_height, num_recon) \
  1158. do { \
  1159. HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, 16, \
  1160. num_recon, HFI_CODEC_ENCODE_AVC); \
  1161. } while (0)
  1162. #define HFI_BUFFER_COMV_H265E(_size, frame_width, frame_height, num_recon) \
  1163. do { \
  1164. HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, 32,\
  1165. num_recon, HFI_CODEC_ENCODE_HEVC); \
  1166. } while (0)
  1167. #define HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1168. num_vpp_pipes_enc, lcu_size, standard) \
  1169. do { \
  1170. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, \
  1171. frame_width_coded = 0, frame_height_coded = 0, \
  1172. num_lcu_in_frame = 0, num_lcumb = 0; \
  1173. HFI_U32 frame_rc_buf_size = 0; \
  1174. width_in_lcus = ((frame_width) + (lcu_size)-1) / (lcu_size); \
  1175. height_in_lcus = ((frame_height) + (lcu_size)-1) / (lcu_size); \
  1176. num_lcu_in_frame = width_in_lcus * height_in_lcus; \
  1177. frame_width_coded = width_in_lcus * (lcu_size); \
  1178. frame_height_coded = height_in_lcus * (lcu_size); \
  1179. num_lcumb = (frame_height_coded / lcu_size) * \
  1180. ((frame_width_coded + lcu_size * 8) / lcu_size); \
  1181. SIZE_FRAME_RC_BUF_SIZE(frame_rc_buf_size, standard, \
  1182. frame_height_coded, num_vpp_pipes_enc); \
  1183. _size = SIZE_ENC_SLICE_INFO_BUF(num_lcu_in_frame) + \
  1184. SIZE_SLICE_CMD_BUFFER + \
  1185. SIZE_SPS_PPS_SLICE_HDR + \
  1186. frame_rc_buf_size + \
  1187. ENC_BITCNT_BUF_SIZE(num_lcu_in_frame) + \
  1188. ENC_BITMAP_BUF_SIZE(num_lcu_in_frame) + \
  1189. SIZE_BSE_SLICE_CMD_BUF + \
  1190. SIZE_LAMBDA_LUT + \
  1191. SIZE_OVERRIDE_BUF(num_lcumb) + \
  1192. SIZE_IR_BUF(num_lcu_in_frame); \
  1193. } while (0)
  1194. #define HFI_BUFFER_NON_COMV_H264E(_size, frame_width, frame_height, \
  1195. num_vpp_pipes_enc) \
  1196. do { \
  1197. HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1198. num_vpp_pipes_enc, 16, HFI_CODEC_ENCODE_AVC); \
  1199. } while (0)
  1200. #define HFI_BUFFER_NON_COMV_H265E(_size, frame_width, frame_height, \
  1201. num_vpp_pipes_enc) \
  1202. do { \
  1203. HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1204. num_vpp_pipes_enc, 32, HFI_CODEC_ENCODE_HEVC); \
  1205. } while (0)
  1206. #define SIZE_ENC_REF_BUFFER(size, frame_width, frame_height) \
  1207. do { \
  1208. HFI_U32 u_buffer_width = 0, u_buffer_height = 0, \
  1209. u_chroma_buffer_height = 0; \
  1210. u_buffer_height = HFI_ALIGN(frame_height, \
  1211. HFI_VENUS_HEIGHT_ALIGNMENT); \
  1212. u_chroma_buffer_height = frame_height >> 1; \
  1213. u_chroma_buffer_height = HFI_ALIGN(u_chroma_buffer_height, \
  1214. HFI_VENUS_HEIGHT_ALIGNMENT); \
  1215. u_buffer_width = HFI_ALIGN(frame_width, \
  1216. HFI_VENUS_WIDTH_ALIGNMENT); \
  1217. size = (u_buffer_height + u_chroma_buffer_height) * \
  1218. u_buffer_width; \
  1219. } while (0)
  1220. #define SIZE_ENC_TEN_BIT_REF_BUFFER(size, frame_width, frame_height) \
  1221. do { \
  1222. HFI_U32 ref_buf_height = 0, ref_luma_stride_in_bytes = 0, \
  1223. u_ref_stride = 0, luma_size = 0, ref_chrm_height_in_bytes = 0, \
  1224. chroma_size = 0, ref_buf_size = 0; \
  1225. ref_buf_height = (frame_height + \
  1226. (HFI_VENUS_HEIGHT_ALIGNMENT - 1)) \
  1227. & (~(HFI_VENUS_HEIGHT_ALIGNMENT - 1)); \
  1228. ref_luma_stride_in_bytes = ((frame_width + \
  1229. SYSTEM_LAL_TILE10 - 1) / SYSTEM_LAL_TILE10) * \
  1230. SYSTEM_LAL_TILE10; \
  1231. u_ref_stride = 4 * (ref_luma_stride_in_bytes / 3); \
  1232. u_ref_stride = (u_ref_stride + (BUF_SIZE_ALIGN_128 - 1)) &\
  1233. (~(BUF_SIZE_ALIGN_128 - 1)); \
  1234. luma_size = ref_buf_height * u_ref_stride; \
  1235. ref_chrm_height_in_bytes = (((frame_height + 1) >> 1) + \
  1236. (BUF_SIZE_ALIGN_32 - 1)) & (~(BUF_SIZE_ALIGN_32 - 1)); \
  1237. chroma_size = u_ref_stride * ref_chrm_height_in_bytes; \
  1238. luma_size = (luma_size + (BUF_SIZE_ALIGN_4096 - 1)) & \
  1239. (~(BUF_SIZE_ALIGN_4096 - 1)); \
  1240. chroma_size = (chroma_size + (BUF_SIZE_ALIGN_4096 - 1)) & \
  1241. (~(BUF_SIZE_ALIGN_4096 - 1)); \
  1242. ref_buf_size = luma_size + chroma_size; \
  1243. size = ref_buf_size; \
  1244. } while (0)
  1245. #define HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, is_ten_bit) \
  1246. do { \
  1247. HFI_U32 metadata_stride, metadata_buf_height, meta_size_y, \
  1248. meta_size_c; \
  1249. HFI_U32 ten_bit_ref_buf_size = 0, ref_buf_size = 0; \
  1250. if (!is_ten_bit) { \
  1251. SIZE_ENC_REF_BUFFER(ref_buf_size, frame_width, \
  1252. frame_height); \
  1253. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, \
  1254. (frame_width), 64, \
  1255. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH); \
  1256. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, \
  1257. (frame_height), 16, \
  1258. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT); \
  1259. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_y, \
  1260. metadata_stride, metadata_buf_height); \
  1261. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_c, \
  1262. metadata_stride, metadata_buf_height); \
  1263. _size = ref_buf_size + meta_size_y + meta_size_c; \
  1264. } else { \
  1265. SIZE_ENC_TEN_BIT_REF_BUFFER(ten_bit_ref_buf_size, \
  1266. frame_width, frame_height); \
  1267. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, \
  1268. frame_width, VENUS_METADATA_STRIDE_MULTIPLE, \
  1269. HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_WIDTH); \
  1270. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, \
  1271. frame_height, VENUS_METADATA_HEIGHT_MULTIPLE, \
  1272. HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_HEIGHT); \
  1273. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_y, \
  1274. metadata_stride, metadata_buf_height); \
  1275. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_c, \
  1276. metadata_stride, metadata_buf_height); \
  1277. _size = ten_bit_ref_buf_size + meta_size_y + \
  1278. meta_size_c; \
  1279. } \
  1280. } while (0)
  1281. #define HFI_BUFFER_DPB_H264E(_size, frame_width, frame_height) \
  1282. do { \
  1283. HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, 0); \
  1284. } while (0)
  1285. #define HFI_BUFFER_DPB_H265E(_size, frame_width, frame_height, is_ten_bit) \
  1286. do { \
  1287. HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, is_ten_bit); \
  1288. } while (0)
  1289. #define HFI_BUFFER_VPSS_ENC(vpss_size, dswidth, dsheight, ds_enable, blur, is_ten_bit) \
  1290. do { \
  1291. vpss_size = 0; \
  1292. if (ds_enable || blur) { \
  1293. HFI_BUFFER_DPB_ENC(vpss_size, dswidth, dsheight, is_ten_bit); \
  1294. } \
  1295. } while (0)
  1296. #define HFI_IRIS2_ENC_MIN_INPUT_BUF_COUNT(numInput, TotalHBLayers) \
  1297. do { \
  1298. numInput = 3; \
  1299. if (TotalHBLayers >= 2) { \
  1300. numInput = (1 << (TotalHBLayers - 1)) + 2; \
  1301. } \
  1302. } while (0)
  1303. #endif /* __HFI_BUFFER_IRIS2__ */