drmrga.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * Copyright (C) 2016 Rockchip Electronics Co., Ltd.
  3. * Authors:
  4. * Zhiqin Wei <wzq@rock-chips.com>
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef _rk_drm_rga_
  19. #define _rk_drm_rga_
  20. #include <stdint.h>
  21. #include <errno.h>
  22. #include <sys/cdefs.h>
  23. #include "rga.h"
  24. #ifdef ANDROID
  25. #define DRMRGA_HARDWARE_MODULE_ID "librga"
  26. #include <hardware/gralloc.h>
  27. #include <hardware/hardware.h>
  28. #include <system/graphics.h>
  29. #include <cutils/native_handle.h>
  30. #if defined(ANDROID_12) || defined(USE_HARDWARE_ROCKCHIP) || defined(__ANDROID_VENDOR_API__)
  31. #include <hardware/hardware_rockchip.h>
  32. #endif
  33. #endif
  34. #define RGA_BLIT_SYNC 0x5017
  35. #define RGA_BLIT_ASYNC 0x5018
  36. #ifndef ANDROID /* LINUX */
  37. /* flip source image horizontally (around the vertical axis) */
  38. #define HAL_TRANSFORM_FLIP_H 0x01
  39. /* flip source image vertically (around the horizontal axis)*/
  40. #define HAL_TRANSFORM_FLIP_V 0x02
  41. /* rotate source image 90 degrees clockwise */
  42. #define HAL_TRANSFORM_ROT_90 0x04
  43. /* rotate source image 180 degrees */
  44. #define HAL_TRANSFORM_ROT_180 0x03
  45. /* rotate source image 270 degrees clockwise */
  46. #define HAL_TRANSFORM_ROT_270 0x07
  47. #endif
  48. #define HAL_TRANSFORM_FLIP_H_V 0x08
  49. /*****************************************************************************/
  50. /* for compatibility */
  51. #define DRM_RGA_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1
  52. #define DRM_RGA_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1
  53. #define DRM_RGA_API_VERSION HWC_DEVICE_API_VERSION
  54. #define DRM_RGA_TRANSFORM_ROT_MASK 0x0000000F
  55. #define DRM_RGA_TRANSFORM_ROT_0 0x00000000
  56. #define DRM_RGA_TRANSFORM_ROT_90 HAL_TRANSFORM_ROT_90
  57. #define DRM_RGA_TRANSFORM_ROT_180 HAL_TRANSFORM_ROT_180
  58. #define DRM_RGA_TRANSFORM_ROT_270 HAL_TRANSFORM_ROT_270
  59. #define DRM_RGA_TRANSFORM_FLIP_MASK 0x00000003
  60. #define DRM_RGA_TRANSFORM_FLIP_H HAL_TRANSFORM_FLIP_H
  61. #define DRM_RGA_TRANSFORM_FLIP_V HAL_TRANSFORM_FLIP_V
  62. enum {
  63. AWIDTH = 0,
  64. AHEIGHT,
  65. ASTRIDE,
  66. AFORMAT,
  67. ASIZE,
  68. ATYPE,
  69. };
  70. /*****************************************************************************/
  71. #ifndef ANDROID /* LINUX */
  72. /* memory type definitions. */
  73. enum drm_rockchip_gem_mem_type {
  74. /* Physically Continuous memory and used as default. */
  75. ROCKCHIP_BO_CONTIG = 1 << 0,
  76. /* cachable mapping. */
  77. ROCKCHIP_BO_CACHABLE = 1 << 1,
  78. /* write-combine mapping. */
  79. ROCKCHIP_BO_WC = 1 << 2,
  80. ROCKCHIP_BO_SECURE = 1 << 3,
  81. ROCKCHIP_BO_MASK = ROCKCHIP_BO_CONTIG | ROCKCHIP_BO_CACHABLE |
  82. ROCKCHIP_BO_WC | ROCKCHIP_BO_SECURE
  83. };
  84. typedef struct bo {
  85. int fd;
  86. void *ptr;
  87. size_t size;
  88. size_t offset;
  89. size_t pitch;
  90. unsigned handle;
  91. } bo_t;
  92. #endif
  93. /*
  94. @value size: user not need care about.For avoid read/write out of memory
  95. */
  96. typedef struct rga_rect {
  97. int xoffset;
  98. int yoffset;
  99. int width;
  100. int height;
  101. int wstride;
  102. int hstride;
  103. int format;
  104. int size;
  105. } rga_rect_t;
  106. typedef struct rga_nn {
  107. int nn_flag;
  108. int scale_r;
  109. int scale_g;
  110. int scale_b;
  111. int offset_r;
  112. int offset_g;
  113. int offset_b;
  114. } rga_nn_t;
  115. typedef struct rga_dither {
  116. int enable;
  117. int mode;
  118. int lut0_l;
  119. int lut0_h;
  120. int lut1_l;
  121. int lut1_h;
  122. } rga_dither_t;
  123. struct rga_mosaic_info {
  124. uint8_t enable;
  125. uint8_t mode;
  126. };
  127. struct rga_pre_intr_info {
  128. uint8_t enable;
  129. uint8_t read_intr_en;
  130. uint8_t write_intr_en;
  131. uint8_t read_hold_en;
  132. uint32_t read_threshold;
  133. uint32_t write_start;
  134. uint32_t write_step;
  135. };
  136. /* MAX(min, (max - channel_value)) */
  137. struct rga_osd_invert_factor {
  138. uint8_t alpha_max;
  139. uint8_t alpha_min;
  140. uint8_t yg_max;
  141. uint8_t yg_min;
  142. uint8_t crb_max;
  143. uint8_t crb_min;
  144. };
  145. struct rga_color {
  146. union {
  147. struct {
  148. uint8_t red;
  149. uint8_t green;
  150. uint8_t blue;
  151. uint8_t alpha;
  152. };
  153. uint32_t value;
  154. };
  155. };
  156. struct rga_osd_bpp2 {
  157. uint8_t ac_swap; // ac swap flag
  158. // 0: CA
  159. // 1: AC
  160. uint8_t endian_swap; // rgba2bpp endian swap
  161. // 0: Big endian
  162. // 1: Little endian
  163. struct rga_color color0;
  164. struct rga_color color1;
  165. };
  166. struct rga_osd_mode_ctrl {
  167. uint8_t mode; // OSD cal mode:
  168. // 0b'1: statistics mode
  169. // 1b'1: auto inversion overlap mode
  170. uint8_t direction_mode; // horizontal or vertical
  171. // 0: horizontal
  172. // 1: vertical
  173. uint8_t width_mode; // using @fix_width or LUT width
  174. // 0: fix width
  175. // 1: LUT width
  176. uint16_t block_fix_width; // OSD block fixed width
  177. // real width = (fix_width + 1) * 2
  178. uint8_t block_num; // OSD block num
  179. uint16_t flags_index; // auto invert flags index
  180. /* invertion config */
  181. uint8_t color_mode; // selete color
  182. // 0: src1 color
  183. // 1: config data color
  184. uint8_t invert_flags_mode; // invert flag selete
  185. // 0: use RAM flag
  186. // 1: usr last result
  187. uint8_t default_color_sel; // default color mode
  188. // 0: default is bright
  189. // 1: default is dark
  190. uint8_t invert_enable; // invert channel enable
  191. // 1 << 0: aplha enable
  192. // 1 << 1: Y/G disable
  193. // 1 << 2: C/RB disable
  194. uint8_t invert_mode; // invert cal mode
  195. // 0: normal(max-data)
  196. // 1: swap
  197. uint8_t invert_thresh; // if luma > thresh, osd_flag to be 1
  198. uint8_t unfix_index; // OSD width config index
  199. };
  200. struct rga_osd_info {
  201. uint8_t enable;
  202. struct rga_osd_mode_ctrl mode_ctrl;
  203. struct rga_osd_invert_factor cal_factor;
  204. struct rga_osd_bpp2 bpp2_info;
  205. union {
  206. struct {
  207. uint32_t last_flags1;
  208. uint32_t last_flags0;
  209. };
  210. uint64_t last_flags;
  211. };
  212. union {
  213. struct {
  214. uint32_t cur_flags1;
  215. uint32_t cur_flags0;
  216. };
  217. uint64_t cur_flags;
  218. };
  219. };
  220. /*
  221. @value fd: use fd to share memory, it can be ion shard fd,and dma fd.
  222. @value virAddr:userspace address
  223. @value phyAddr:use phy address
  224. @value hnd: use buffer_handle_t
  225. */
  226. typedef struct rga_info {
  227. int fd;
  228. void *virAddr;
  229. void *phyAddr;
  230. #ifndef ANDROID /* LINUX */
  231. unsigned hnd;
  232. #else /* Android */
  233. buffer_handle_t hnd;
  234. #endif
  235. int format;
  236. rga_rect_t rect;
  237. unsigned int blend;
  238. int bufferSize;
  239. int rotation;
  240. int color;
  241. int testLog;
  242. int mmuFlag;
  243. int colorkey_en;
  244. int colorkey_mode;
  245. int colorkey_max;
  246. int colorkey_min;
  247. int scale_mode;
  248. int color_space_mode;
  249. int sync_mode;
  250. rga_nn_t nn;
  251. rga_dither_t dither;
  252. int rop_code;
  253. int rd_mode;
  254. unsigned short is_10b_compact;
  255. unsigned short is_10b_endian;
  256. int in_fence_fd;
  257. int out_fence_fd;
  258. int core;
  259. int priority;
  260. unsigned short enable;
  261. int handle;
  262. struct rga_mosaic_info mosaic_info;
  263. struct rga_osd_info osd_info;
  264. struct rga_pre_intr_info pre_intr;
  265. int mpi_mode;
  266. union {
  267. int ctx_id;
  268. int job_handle;
  269. };
  270. uint16_t rgba5551_flags;
  271. uint8_t rgba5551_alpha0;
  272. uint8_t rgba5551_alpha1;
  273. char reserve[398];
  274. } rga_info_t;
  275. typedef struct drm_rga {
  276. rga_rect_t src;
  277. rga_rect_t dst;
  278. } drm_rga_t;
  279. /*
  280. @fun rga_set_rect:For use to set the rects esayly
  281. @param rect:The rect user want to set,like setting the src rect:
  282. drm_rga_t rects;
  283. rga_set_rect(rects.src,0,0,1920,1080,1920,NV12);
  284. mean to set the src rect to the value.
  285. */
  286. static inline int rga_set_rect(rga_rect_t *rect,
  287. int x, int y, int w, int h, int sw, int sh, int f) {
  288. if (!rect)
  289. return -EINVAL;
  290. rect->xoffset = x;
  291. rect->yoffset = y;
  292. rect->width = w;
  293. rect->height = h;
  294. rect->wstride = sw;
  295. rect->hstride = sh;
  296. rect->format = f;
  297. return 0;
  298. }
  299. #ifndef ANDROID /* LINUX */
  300. static inline void rga_set_rotation(rga_info_t *info, int angle) {
  301. if (angle == 90)
  302. info->rotation = HAL_TRANSFORM_ROT_90;
  303. else if (angle == 180)
  304. info->rotation = HAL_TRANSFORM_ROT_180;
  305. else if (angle == 270)
  306. info->rotation = HAL_TRANSFORM_ROT_270;
  307. }
  308. #endif
  309. /*****************************************************************************/
  310. #endif