stfmod_isp_buf.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /**
  2. ******************************************************************************
  3. * @file stfmod_isp_buf.h
  4. * @author StarFive Isp Team
  5. * @version V1.0
  6. * @date 05/26/2020
  7. * @brief
  8. ******************************************************************************
  9. * @copy
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, STARFIVE SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * Copyright (C) 2019 - 2022 StarFive Technology Co., Ltd.
  19. */
  20. #ifndef __STFMOD_ISP_BUF_H__
  21. #define __STFMOD_ISP_BUF_H__
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #include "stf_include.h"
  26. #include "ci/ci_api_structs.h"
  27. #include "registers/stf_isp_buf_rdma.h"
  28. #include "stflib_isp_pipeline.h"
  29. /* ISP video output module parameters structure */
  30. //-----------------------------------------------------------------------------
  31. // Define initial values
  32. #define BUF_PIXEL_BITS (8)
  33. #define BUF_PIXEL_VALUE_MAX ((1 << BUF_PIXEL_BITS) - 1)
  34. #define BUF_ALIGN_BITS (3)
  35. #define BUF_ALIGN_MASK ((1 << BUF_ALIGN_BITS) - 1)
  36. #define BUF_ALIGNMENT (1 << BUF_ALIGN_BITS)
  37. #define BUF_SCALE_FACTOR_BITS (12)
  38. #define BUF_SCALE_FACTOR_MAX (1 << BUF_SCALE_FACTOR_BITS)
  39. #define ISP_DEF_BUF_USING_IMG_SIZE_FOR_CALC (STF_TRUE) /** Turn this flag to using image size to calculate the scaling factor. */
  40. #define ISP_DEF_BUF_UO_IMAGE_WIDTH (ISP_IMG_WIDTH) /** Unscaled output image width. */
  41. #define ISP_DEF_BUF_UO_IMAGE_HEIGHT (ISP_IMG_HEIGHT) /** Unscaled output image Height. */
  42. #define ISP_DEF_BUF_UO_UV_MODET (STF_FALSE) /** Output image UV swap, 0 : NV12, 1 : NV21. */
  43. #define ISP_DEF_BUF_UO_AXI_ID (0) /** ID of AXI bus for unscaled output image write. */
  44. #define ISP_DEF_BUF_UO_STRIDE (1920) /** unscaled output buffer stride, 8 byte aligned. */
  45. #define ISP_DEF_BUF_UO_BUFFER_ADDRESS (0x6C800000) /** Point to unscaled output buffer address. */
  46. #define ISP_DEF_BUF_SS0_IMAGE_WIDTH (1280) /** Scaled stream 0 output image width. */
  47. #define ISP_DEF_BUF_SS0_IMAGE_HEIGHT (720) /** Scaled stream 0 output image Height. */
  48. #define ISP_DEF_BUF_SS0_UV_MODET (ISP_DEF_BUF_UO_UV_MODET) /** Output image UV swap, 0 : NV12, 1 : NV21. */
  49. #define ISP_DEF_BUF_SS0_H_SCALE_MODE (0) /** Scaled stream 0 output image horizontal Scaling mode, 0 : scaling down, 2 : no scaling. */
  50. #define ISP_DEF_BUF_SS0_H_SCALE_FACTOR (0.666748047) /** Scaled stream 0 output image horizontal Scaling factor. */
  51. #define ISP_DEF_BUF_SS0_V_SCALE_MODE (0) /** Scaled stream 0 output image vertical Scaling mode, 0 : scaling down, 2 : no scaling. */
  52. #define ISP_DEF_BUF_SS0_V_SCALE_FACTOR (0.666748047) /** Scaled stream 0 output image vertical Scaling factor. */
  53. #define ISP_DEF_BUF_SS0_AXI_ID (0) /** ID of AXI bus for scaled stream 0 output image write. */
  54. #define ISP_DEF_BUF_SS0_STRIDE (1280) /** scaled stream 0 output buffer stride, 8 byte aligned. */
  55. #define ISP_DEF_BUF_SS0_BUFFER_ADDRESS (0x6CC00000) /** Point to scaled stream 0 output buffer address. */
  56. #define ISP_DEF_BUF_SS1_IMAGE_WIDTH (960) /** Scaled stream 1 output image width. */
  57. #define ISP_DEF_BUF_SS1_IMAGE_HEIGHT (540) /** Scaled stream 1 output image Height. */
  58. #define ISP_DEF_BUF_SS1_UV_MODET (ISP_DEF_BUF_UO_UV_MODET) /** Output image UV swap, 0 : NV12, 1 : NV21. */
  59. #define ISP_DEF_BUF_SS1_H_SCALE_MODE (0) /** Scaled stream 1 output image horizontal Scaling mode, 0 : scaling down, 2 : no scaling. */
  60. #define ISP_DEF_BUF_SS1_H_SCALE_FACTOR (0.666748047) /** Scaled stream 1 output image horizontal Scaling factor. */
  61. #define ISP_DEF_BUF_SS1_V_SCALE_MODE (0) /** Scaled stream 1 output image vertical Scaling mode, 0 : scaling down, 2 : no scaling. */
  62. #define ISP_DEF_BUF_SS1_V_SCALE_FACTOR (0.666748047) /** Scaled stream 1 output image vertical Scaling factor. */
  63. #define ISP_DEF_BUF_SS1_AXI_ID (0) /** ID of AXI bus for scaled stream 1 output image write. */
  64. #define ISP_DEF_BUF_SS1_STRIDE (960) /** scaled stream 1 output buffer stride, 8 byte aligned. */
  65. #define ISP_DEF_BUF_SS1_BUFFER_ADDRESS (0x6D000000) /** Point to scaled stream 1 output buffer address. */
  66. #pragma pack(push, 1)
  67. //=== Godspeed === Add new memory/buffer type support here.
  68. typedef enum _EN_BUF_UPDATE {
  69. EN_BUF_UPDATE_NONE = 0X00000000,
  70. EN_BUF_UPDATE_UO_BUFFER = 0x00000001,
  71. EN_BUF_UPDATE_SS0_BUFFER = 0x00000002,
  72. EN_BUF_UPDATE_SS1_BUFFER = 0x00000004,
  73. EN_BUF_UPDATE_DUMP_BUFFER = 0x00000008,
  74. EN_BUF_UPDATE_TILING_1_READ_BUFFER = 0x00000010,
  75. EN_BUF_UPDATE_TILING_1_WRITE_BUFFER = 0x00000020,
  76. EN_BUF_UPDATE_SC_DUMP_BUFFER = 0x00000100,
  77. EN_BUF_UPDATE_Y_HIST_BUFFER = 0x00000200,
  78. EN_BUF_UPDATE_ALL = (EN_BUF_UPDATE_UO_BUFFER
  79. | EN_BUF_UPDATE_SS0_BUFFER
  80. | EN_BUF_UPDATE_SS1_BUFFER
  81. | EN_BUF_UPDATE_DUMP_BUFFER
  82. | EN_BUF_UPDATE_TILING_1_READ_BUFFER
  83. | EN_BUF_UPDATE_TILING_1_WRITE_BUFFER
  84. | EN_BUF_UPDATE_SC_DUMP_BUFFER
  85. | EN_BUF_UPDATE_Y_HIST_BUFFER
  86. ),
  87. } EN_BUF_UPDATE, *PEN_BUF_UPDATE;
  88. typedef struct _ST_BUF_INFO {
  89. STF_U16 u16Stride; /** Output/Input image line stride. */
  90. STF_U16 u16Height; /** Output/Input image height. */
  91. STF_VOID *pvBuffer; /** Output/Input image RAW/RGB/Y plane data store buffer. */
  92. } ST_BUF_INFO, *PST_BUF_INFO;
  93. typedef struct _ST_MOD_BUF_SETTING {
  94. //-------------------------------------------------------------------------
  95. // This section parameters value is assign from setting file.
  96. STF_BOOL8 bEnable; /** Enable/Disable the BUF module. */
  97. } ST_MOD_BUF_SETTING, *PST_MOD_BUF_SETTING;
  98. //=== Godspeed === Add new memory/buffer type support here.
  99. typedef struct _ST_BUF_PARAM {
  100. ST_MOD_BUF_SETTING stSetting; /** Module BUF setting file parameters. */
  101. //-------------------------------------------------------------------------
  102. // This section parameters is internal using.
  103. STF_BOOL8 bSetup; /** Flag set if the module setup has been completed. */
  104. STF_BOOL8 bUpdate; /** Enable/Disable program BUF module register. */
  105. STF_U32 u32UpdateRequest; /** Flag to indicate that this module update has been requested. */
  106. ST_BUF_INFO stUoBuf; /** Unscaled output image buffer information. */
  107. ST_BUF_INFO stSs0Buf; /** Scaled stream 0 output image buffer information. */
  108. ST_BUF_INFO stSs1Buf; /** Scaled stream 1 output image buffer information. */
  109. ST_BUF_INFO stDumpBuf; /** CSI raw data dump image buffer information. */
  110. ST_BUF_INFO stTiling_1_ReadBuf; /** Tiling 1 read input image buffer information. */
  111. ST_BUF_INFO stTiling_1_WriteBuf; /** Tiling 1 write input image buffer information. */
  112. ST_BUF_INFO stScDumpBuf; /** statistics collection dump buffer information. */
  113. ST_BUF_INFO stYHistBuf; /** Y histogram dump buffer information. */
  114. } ST_BUF_PARAM, *PST_BUF_PARAM;
  115. #define ST_MOD_BUF_SETTING_LEN (sizeof(ST_MOD_BUF_SETTING))
  116. #define ST_MOD_BUF_GET_PARAM_LEN (ST_MOD_BUF_SETTING_LEN)
  117. #define ST_MOD_BUF_SET_PARAM_LEN (ST_MOD_BUF_SETTING_LEN)
  118. //#define ST_BUF_PARAM_SIZE (sizeof(ST_BUF_PARAM) - (sizeof(ST_BUF_INFO) * 8))
  119. #define ST_BUF_PARAM_SIZE (sizeof(ST_BUF_PARAM))
  120. #define ST_BUF_PARAM_LEN (ST_BUF_PARAM_SIZE)
  121. typedef struct _ST_ISP_MOD_BUF {
  122. #if defined(VIRTUAL_IO_MAPPING)
  123. STF_VOID *pPipeline; /** Pointer to Pipeline. */
  124. #endif //VIRTUAL_IO_MAPPING
  125. STF_VOID *pIspCtx; /** Pointer to ISP context. */
  126. STF_U32 u32Id; /** Module ID. */
  127. STF_CHAR szName[16]; /** Module Name. */
  128. CI_MEM_PARAM *pstBufRdmaBuf; /** BUF's DMA buffer pointer for RDMA. */
  129. #if defined(SUPPORT_MULTI_ISP)
  130. ST_ISP_BUF_RDMA *pstIspBufRdma; /** BUF's RDMA structure pointer that include ISP index.*/
  131. #endif //SUPPORT_MULTI_ISP
  132. ST_BUF_RDMA *pstBufRdma; /** BUF's RDMA structure pointer.*/
  133. ST_BUF_PARAM *pstBufParam; /** BUF's parameters structure pointer. */
  134. STF_BOOL8 bRegistered; /** Module register in pipeline. */
  135. STF_S32 (*Init)(STF_VOID *pIspCtx, STF_U32 *pNextRdma);
  136. STF_S32 (*LoadBinParam)(STF_VOID *pIspCtx, STF_U8 *pu8ParamBuf, STF_U16 u16ParamSize);
  137. STF_S32 (*LoadBinClbrt)(STF_VOID *pIspCtx);
  138. STF_S32 (*Enable)(STF_VOID *pIspCtx, STF_BOOL8 bEnable);
  139. STF_BOOL8 (*IsEnable)(STF_VOID *pIspCtx);
  140. STF_S32 (*Update)(STF_VOID *pIspCtx, STF_BOOL8 bUpdate);
  141. STF_BOOL8 (*IsUpdate)(STF_VOID *pIspCtx);
  142. STF_S32 (*Registered)(STF_VOID *pIspCtx, STF_BOOL8 bRegistered);
  143. STF_BOOL8 (*IsRegistered)(STF_VOID *pIspCtx);
  144. STF_S32 (*UpdateReg)(STF_VOID *pIspCtx);
  145. STF_S32 (*SetReg)(STF_VOID *pIspCtx);
  146. STF_S32 (*SetNext)(STF_VOID *pIspCtx, STF_U32 *pNextRdma);
  147. STF_S32 (*FreeResource)(STF_VOID *pIspCtx);
  148. STF_S32 (*GetIqParam)(STF_VOID *pIspCtx, STF_VOID *pParamBuf, STF_U16 *pu16ParamSize);
  149. STF_S32 (*SetIqParam)(STF_VOID *pIspCtx, STF_VOID *pParamBuf, STF_U16 u16ParamSize);
  150. } ST_ISP_MOD_BUF, *PST_ISP_MOD_BUF;
  151. #pragma pack(pop)
  152. /* ISP video output module parameters interface */
  153. //-----------------------------------------------------------------------------
  154. extern
  155. STF_S32 STFMOD_ISP_BUF_InitRdma(
  156. ST_BUF_RDMA *pstBufRdma,
  157. ST_BUF_PARAM *pstBufParam,
  158. STF_U32 *pNextRdma
  159. );
  160. extern
  161. STF_S32 STFMOD_ISP_BUF_UpdateRdma(
  162. ST_BUF_RDMA *pstBufRdma,
  163. ST_BUF_PARAM *pstBufParam
  164. );
  165. //-----------------------------------------------------------------------------
  166. //=== Godspeed === Add new memory/buffer type support here.
  167. extern
  168. STF_S32 STFMOD_ISP_BUF_UpdateUoBuffer(
  169. ST_BUF_RDMA *pstBufRdma,
  170. ST_BUF_PARAM *pstBufParam
  171. );
  172. extern
  173. STF_S32 STFMOD_ISP_BUF_UpdateSs0Buffer(
  174. ST_BUF_RDMA *pstBufRdma,
  175. ST_BUF_PARAM *pstBufParam
  176. );
  177. extern
  178. STF_S32 STFMOD_ISP_BUF_UpdateSs1Buffer(
  179. ST_BUF_RDMA *pstBufRdma,
  180. ST_BUF_PARAM *pstBufParam
  181. );
  182. extern
  183. STF_S32 STFMOD_ISP_BUF_UpdateDumpBuffer(
  184. ST_BUF_RDMA *pstBufRdma,
  185. ST_BUF_PARAM *pstBufParam
  186. );
  187. extern
  188. STF_S32 STFMOD_ISP_BUF_UpdateTiling_1_ReadBuffer(
  189. ST_BUF_RDMA *pstBufRdma,
  190. ST_BUF_PARAM *pstBufParam
  191. );
  192. extern
  193. STF_S32 STFMOD_ISP_BUF_UpdateTiling_1_WriteBuffer(
  194. ST_BUF_RDMA *pstBufRdma,
  195. ST_BUF_PARAM *pstBufParam
  196. );
  197. extern
  198. STF_S32 STFMOD_ISP_BUF_UpdateScDumpBuffer(
  199. ST_BUF_RDMA *pstBufRdma,
  200. ST_BUF_PARAM *pstBufParam
  201. );
  202. extern
  203. STF_S32 STFMOD_ISP_BUF_UpdateYHistBuffer(
  204. ST_BUF_RDMA *pstBufRdma,
  205. ST_BUF_PARAM *pstBufParam
  206. );
  207. //-----------------------------------------------------------------------------
  208. extern
  209. STF_S32 STFMOD_ISP_BUF_SetNextRdma(
  210. ST_BUF_RDMA *pstBufRdma,
  211. STF_U32 *pNextRdma
  212. );
  213. //-----------------------------------------------------------------------------
  214. extern
  215. STF_S32 STFMOD_ISP_BUF_SetEnable(
  216. ST_ISP_MOD_BUF *pstModBuf,
  217. STF_BOOL8 bEnable
  218. );
  219. extern
  220. STF_S32 STFMOD_ISP_BUF_SetUpdate(
  221. ST_ISP_MOD_BUF *pstModBuf,
  222. STF_BOOL8 bUpdate
  223. );
  224. //=== Godspeed === Add new memory/buffer type support here.
  225. extern
  226. STF_S32 STFMOD_ISP_BUF_SetUoBuffer(
  227. STF_VOID *pIspCtx,
  228. ST_BUF_INFO *pstBufferInfo
  229. );
  230. extern
  231. STF_S32 STFMOD_ISP_BUF_GetUoBuffer(
  232. STF_VOID *pIspCtx,
  233. STF_VOID **ppvBuffer
  234. );
  235. extern
  236. STF_S32 STFMOD_ISP_BUF_SetSs0Buffer(
  237. STF_VOID *pIspCtx,
  238. ST_BUF_INFO *pstBufferInfo
  239. );
  240. extern
  241. STF_S32 STFMOD_ISP_BUF_GetSs0Buffer(
  242. STF_VOID *pIspCtx,
  243. STF_VOID **ppvBuffer
  244. );
  245. extern
  246. STF_S32 STFMOD_ISP_BUF_SetSs1Buffer(
  247. STF_VOID *pIspCtx,
  248. ST_BUF_INFO *pstBufferInfo
  249. );
  250. extern
  251. STF_S32 STFMOD_ISP_BUF_GetSs1Buffer(
  252. STF_VOID *pIspCtx,
  253. STF_VOID **ppvBuffer
  254. );
  255. extern
  256. STF_S32 STFMOD_ISP_BUF_SetDumpBuffer(
  257. STF_VOID *pIspCtx,
  258. ST_BUF_INFO *pstBufferInfo
  259. );
  260. extern
  261. STF_S32 STFMOD_ISP_BUF_GetDumpBuffer(
  262. STF_VOID *pIspCtx,
  263. STF_U16 **ppu16Buffer
  264. );
  265. extern
  266. STF_S32 STFMOD_ISP_BUF_SetTiling_1_ReadBuffer(
  267. STF_VOID *pIspCtx,
  268. ST_BUF_INFO *pstBufferInfo
  269. );
  270. extern
  271. STF_S32 STFMOD_ISP_BUF_GetTiling_1_ReadBuffer(
  272. STF_VOID *pIspCtx,
  273. STF_VOID **ppvBuffer
  274. );
  275. extern
  276. STF_S32 STFMOD_ISP_BUF_SetTiling_1_WriteBuffer(
  277. STF_VOID *pIspCtx,
  278. ST_BUF_INFO *pstBufferInfo
  279. );
  280. extern
  281. STF_S32 STFMOD_ISP_BUF_GetTiling_1_WriteBuffer(
  282. STF_VOID *pIspCtx,
  283. STF_VOID **ppvBuffer
  284. );
  285. extern
  286. STF_S32 STFMOD_ISP_BUF_SetScDumpBuffer(
  287. STF_VOID *pIspCtx,
  288. ST_BUF_INFO *pstBufferInfo
  289. );
  290. extern
  291. STF_S32 STFMOD_ISP_BUF_GetScDumpBuffer(
  292. STF_VOID *pIspCtx,
  293. STF_U16 **ppu16Buffer
  294. );
  295. extern
  296. STF_S32 STFMOD_ISP_BUF_SetYHistBuffer(
  297. STF_VOID *pIspCtx,
  298. ST_BUF_INFO *pstBufferInfo
  299. );
  300. extern
  301. STF_S32 STFMOD_ISP_BUF_GetYHistBuffer(
  302. STF_VOID *pIspCtx,
  303. STF_U16 **ppu16Buffer
  304. );
  305. //-----------------------------------------------------------------------------
  306. extern
  307. STF_S32 STFMOD_ISP_BUF_Init(
  308. STF_VOID *pIspCtx,
  309. STF_U32 *pNextRdma
  310. );
  311. extern
  312. STF_S32 STFMOD_ISP_BUF_LoadBinParam(
  313. STF_VOID *pIspCtx,
  314. STF_U8 *pu8ParamBuf,
  315. STF_U16 u16ParamSize
  316. );
  317. extern
  318. STF_S32 STFMOD_ISP_BUF_LoadBinClbrt(
  319. STF_VOID *pIspCtx
  320. );
  321. extern
  322. STF_S32 STFMOD_ISP_BUF_Enable(
  323. STF_VOID *pIspCtx,
  324. STF_BOOL8 bEnable
  325. );
  326. extern
  327. STF_BOOL8 STFMOD_ISP_BUF_IsEnable(
  328. STF_VOID *pIspCtx
  329. );
  330. extern
  331. STF_S32 STFMOD_ISP_BUF_Update(
  332. STF_VOID *pIspCtx,
  333. STF_BOOL8 bUpdate
  334. );
  335. extern
  336. STF_BOOL8 STFMOD_ISP_BUF_IsUpdate(
  337. STF_VOID *pIspCtx
  338. );
  339. extern
  340. STF_S32 STFMOD_ISP_BUF_Registered(
  341. STF_VOID *pIspCtx,
  342. STF_BOOL8 bRegistered
  343. );
  344. extern
  345. STF_BOOL8 STFMOD_ISP_BUF_IsRegistered(
  346. STF_VOID *pIspCtx
  347. );
  348. extern
  349. STF_S32 STFMOD_ISP_BUF_UpdateReg(
  350. STF_VOID *pIspCtx
  351. );
  352. extern
  353. STF_S32 STFMOD_ISP_BUF_SetReg(
  354. STF_VOID *pIspCtx
  355. );
  356. extern
  357. STF_S32 STFMOD_ISP_BUF_SetNext(
  358. STF_VOID *pIspCtx,
  359. STF_U32 *pNextRdma
  360. );
  361. extern
  362. STF_S32 STFMOD_ISP_BUF_FreeResource(
  363. STF_VOID *pIspCtx
  364. );
  365. extern
  366. STF_S32 STFMOD_ISP_BUF_GetIqParam(
  367. STF_VOID *pIspCtx,
  368. STF_VOID *pParamBuf,
  369. STF_U16 *pu16ParamSize
  370. );
  371. extern
  372. STF_S32 STFMOD_ISP_BUF_SetIqParam(
  373. STF_VOID *pIspCtx,
  374. STF_VOID *pParamBuf,
  375. STF_U16 u16ParamSize
  376. );
  377. //-----------------------------------------------------------------------------
  378. extern
  379. STF_S32 STFMOD_ISP_BUF_Create(
  380. STF_VOID *pPipeline
  381. );
  382. extern
  383. STF_S32 STFMOD_ISP_BUF_Destroy(
  384. STF_VOID *pPipeline
  385. );
  386. //-----------------------------------------------------------------------------
  387. #ifdef __cplusplus
  388. }
  389. #endif
  390. #endif //__STFMOD_ISP_BUF_H__