1 /* 2 * Copyright (C) 2022 Rockchip Electronics Co., Ltd. 3 * Authors: 4 * Cerf Yu <cerf.yu@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 19 #ifndef _RGA_IM2D_TYPE_H_ 20 #define _RGA_IM2D_TYPE_H_ 21 22 #include <stdint.h> 23 24 typedef enum { 25 /* Rotation */ 26 IM_HAL_TRANSFORM_ROT_90 = 1 << 0, 27 IM_HAL_TRANSFORM_ROT_180 = 1 << 1, 28 IM_HAL_TRANSFORM_ROT_270 = 1 << 2, 29 IM_HAL_TRANSFORM_FLIP_H = 1 << 3, 30 IM_HAL_TRANSFORM_FLIP_V = 1 << 4, 31 IM_HAL_TRANSFORM_FLIP_H_V = 1 << 5, 32 IM_HAL_TRANSFORM_MASK = 0x3f, 33 34 /* 35 * Blend 36 * Additional blend usage, can be used with both source and target configs. 37 * If none of the below is set, the default "SRC over DST" is applied. 38 */ 39 IM_ALPHA_BLEND_SRC_OVER = 1 << 6, /* Default, Porter-Duff "SRC over DST" */ 40 IM_ALPHA_BLEND_SRC = 1 << 7, /* Porter-Duff "SRC" */ 41 IM_ALPHA_BLEND_DST = 1 << 8, /* Porter-Duff "DST" */ 42 IM_ALPHA_BLEND_SRC_IN = 1 << 9, /* Porter-Duff "SRC in DST" */ 43 IM_ALPHA_BLEND_DST_IN = 1 << 10, /* Porter-Duff "DST in SRC" */ 44 IM_ALPHA_BLEND_SRC_OUT = 1 << 11, /* Porter-Duff "SRC out DST" */ 45 IM_ALPHA_BLEND_DST_OUT = 1 << 12, /* Porter-Duff "DST out SRC" */ 46 IM_ALPHA_BLEND_DST_OVER = 1 << 13, /* Porter-Duff "DST over SRC" */ 47 IM_ALPHA_BLEND_SRC_ATOP = 1 << 14, /* Porter-Duff "SRC ATOP" */ 48 IM_ALPHA_BLEND_DST_ATOP = 1 << 15, /* Porter-Duff "DST ATOP" */ 49 IM_ALPHA_BLEND_XOR = 1 << 16, /* Xor */ 50 IM_ALPHA_BLEND_MASK = 0x1ffc0, 51 52 IM_ALPHA_COLORKEY_NORMAL = 1 << 17, 53 IM_ALPHA_COLORKEY_INVERTED = 1 << 18, 54 IM_ALPHA_COLORKEY_MASK = 0x60000, 55 56 IM_SYNC = 1 << 19, 57 IM_CROP = 1 << 20, /* Unused */ 58 IM_COLOR_FILL = 1 << 21, 59 IM_COLOR_PALETTE = 1 << 22, 60 IM_NN_QUANTIZE = 1 << 23, 61 IM_ROP = 1 << 24, 62 IM_ALPHA_BLEND_PRE_MUL = 1 << 25, 63 IM_ASYNC = 1 << 26, 64 IM_MOSAIC = 1 << 27, 65 IM_OSD = 1 << 28, 66 IM_PRE_INTR = 1 << 29, 67 } IM_USAGE; 68 69 typedef enum { 70 IM_RASTER_MODE = 1 << 0, 71 IM_FBC_MODE = 1 << 1, 72 IM_TILE_MODE = 1 << 2, 73 } IM_RD_MODE; 74 75 typedef enum { 76 IM_SCHEDULER_RGA3_CORE0 = 1 << 0, 77 IM_SCHEDULER_RGA3_CORE1 = 1 << 1, 78 IM_SCHEDULER_RGA2_CORE0 = 1 << 2, 79 IM_SCHEDULER_RGA3_DEFAULT = IM_SCHEDULER_RGA3_CORE0, 80 IM_SCHEDULER_RGA2_DEFAULT = IM_SCHEDULER_RGA2_CORE0, 81 IM_SCHEDULER_MASK = 0x7, 82 IM_SCHEDULER_DEFAULT = 0, 83 } IM_SCHEDULER_CORE; 84 85 typedef enum { 86 IM_ROP_AND = 0x88, 87 IM_ROP_OR = 0xee, 88 IM_ROP_NOT_DST = 0x55, 89 IM_ROP_NOT_SRC = 0x33, 90 IM_ROP_XOR = 0xf6, 91 IM_ROP_NOT_XOR = 0xf9, 92 } IM_ROP_CODE; 93 94 typedef enum { 95 IM_MOSAIC_8 = 0x0, 96 IM_MOSAIC_16 = 0x1, 97 IM_MOSAIC_32 = 0x2, 98 IM_MOSAIC_64 = 0x3, 99 IM_MOSAIC_128 = 0x4, 100 } IM_MOSAIC_MODE; 101 102 /* Status codes, returned by any blit function */ 103 typedef enum { 104 IM_YUV_TO_RGB_BT601_LIMIT = 1 << 0, 105 IM_YUV_TO_RGB_BT601_FULL = 2 << 0, 106 IM_YUV_TO_RGB_BT709_LIMIT = 3 << 0, 107 IM_YUV_TO_RGB_MASK = 3 << 0, 108 IM_RGB_TO_YUV_BT601_FULL = 1 << 2, 109 IM_RGB_TO_YUV_BT601_LIMIT = 2 << 2, 110 IM_RGB_TO_YUV_BT709_LIMIT = 3 << 2, 111 IM_RGB_TO_YUV_MASK = 3 << 2, 112 IM_RGB_TO_Y4 = 1 << 4, 113 IM_RGB_TO_Y4_DITHER = 2 << 4, 114 IM_RGB_TO_Y1_DITHER = 3 << 4, 115 IM_Y4_MASK = 3 << 4, 116 IM_RGB_FULL = 1 << 8, 117 IM_RGB_CLIP = 2 << 8, 118 IM_YUV_BT601_LIMIT_RANGE = 3 << 8, 119 IM_YUV_BT601_FULL_RANGE = 4 << 8, 120 IM_YUV_BT709_LIMIT_RANGE = 5 << 8, 121 IM_YUV_BT709_FULL_RANGE = 6 << 8, 122 IM_FULL_CSC_MASK = 0xf << 8, 123 IM_COLOR_SPACE_DEFAULT = 0, 124 } IM_COLOR_SPACE_MODE; 125 126 typedef enum { 127 IM_UP_SCALE, 128 IM_DOWN_SCALE, 129 } IM_SCALE; 130 131 typedef enum { 132 INTER_NEAREST, 133 INTER_LINEAR, 134 INTER_CUBIC, 135 } IM_SCALE_MODE; 136 137 typedef enum { 138 IM_CONFIG_SCHEDULER_CORE, 139 IM_CONFIG_PRIORITY, 140 IM_CONFIG_CHECK, 141 } IM_CONFIG_NAME; 142 143 typedef enum { 144 IM_OSD_MODE_STATISTICS = 0x1 << 0, 145 IM_OSD_MODE_AUTO_INVERT = 0x1 << 1, 146 } IM_OSD_MODE; 147 148 typedef enum { 149 IM_OSD_INVERT_CHANNEL_NONE = 0x0, 150 IM_OSD_INVERT_CHANNEL_Y_G = 0x1 << 0, 151 IM_OSD_INVERT_CHANNEL_C_RB = 0x1 << 1, 152 IM_OSD_INVERT_CHANNEL_ALPHA = 0x1 << 2, 153 IM_OSD_INVERT_CHANNEL_COLOR = IM_OSD_INVERT_CHANNEL_Y_G | 154 IM_OSD_INVERT_CHANNEL_C_RB, 155 IM_OSD_INVERT_CHANNEL_BOTH = IM_OSD_INVERT_CHANNEL_COLOR | 156 IM_OSD_INVERT_CHANNEL_ALPHA, 157 } IM_OSD_INVERT_CHANNEL; 158 159 typedef enum { 160 IM_OSD_FLAGS_INTERNAL = 0, 161 IM_OSD_FLAGS_EXTERNAL, 162 } IM_OSD_FLAGS_MODE; 163 164 typedef enum { 165 IM_OSD_INVERT_USE_FACTOR, 166 IM_OSD_INVERT_USE_SWAP, 167 } IM_OSD_INVERT_MODE; 168 169 typedef enum { 170 IM_OSD_BACKGROUND_DEFAULT_BRIGHT = 0, 171 IM_OSD_BACKGROUND_DEFAULT_DARK, 172 } IM_OSD_BACKGROUND_DEFAULT; 173 174 typedef enum { 175 IM_OSD_BLOCK_MODE_NORMAL = 0, 176 IM_OSD_BLOCK_MODE_DIFFERENT, 177 } IM_OSD_BLOCK_WIDTH_MODE; 178 179 typedef enum { 180 IM_OSD_MODE_HORIZONTAL, 181 IM_OSD_MODE_VERTICAL, 182 } IM_OSD_DIRECTION; 183 184 typedef enum { 185 IM_OSD_COLOR_PIXEL, 186 IM_OSD_COLOR_EXTERNAL, 187 } IM_OSD_COLOR_MODE; 188 189 typedef enum { 190 IM_INTR_READ_INTR = 1 << 0, 191 IM_INTR_READ_HOLD = 1 << 1, 192 IM_INTR_WRITE_INTR = 1 << 2, 193 } IM_PRE_INTR_FLAGS; 194 195 typedef enum { 196 IM_CONTEXT_NONE = 0x0, 197 IM_CONTEXT_SRC_FIX_ENABLE = 0x1 << 0, // Enable kernel to modify the image parameters of the channel. 198 IM_CONTEXT_SRC_CACHE_INFO = 0x1 << 1, // It will replace the parameters in ctx with the modified parameters. 199 IM_CONTEXT_SRC1_FIX_ENABLE = 0x1 << 2, 200 IM_CONTEXT_SRC1_CACHE_INFO = 0x1 << 3, 201 IM_CONTEXT_DST_FIX_ENABLE = 0x1 << 4, 202 IM_CONTEXT_DST_CACHE_INFO = 0x1 << 5, 203 } IM_CONTEXT_FLAGS; 204 205 /* Get RGA basic information index */ 206 typedef enum { 207 RGA_VENDOR = 0, 208 RGA_VERSION, 209 RGA_MAX_INPUT, 210 RGA_MAX_OUTPUT, 211 RGA_BYTE_STRIDE, 212 RGA_SCALE_LIMIT, 213 RGA_INPUT_FORMAT, 214 RGA_OUTPUT_FORMAT, 215 RGA_FEATURE, 216 RGA_EXPECTED, 217 RGA_ALL, 218 } IM_INFORMATION; 219 220 /* Status codes, returned by any blit function */ 221 typedef enum { 222 IM_STATUS_NOERROR = 2, 223 IM_STATUS_SUCCESS = 1, 224 IM_STATUS_NOT_SUPPORTED = -1, 225 IM_STATUS_OUT_OF_MEMORY = -2, 226 IM_STATUS_INVALID_PARAM = -3, 227 IM_STATUS_ILLEGAL_PARAM = -4, 228 IM_STATUS_ERROR_VERSION = -5, 229 IM_STATUS_FAILED = 0, 230 } IM_STATUS; 231 232 typedef uint32_t im_api_version_t; 233 typedef uint32_t im_ctx_id_t; 234 typedef uint32_t rga_buffer_handle_t; 235 236 /* Rectangle definition */ 237 typedef struct { 238 int x; /* upper-left x */ 239 int y; /* upper-left y */ 240 int width; /* width */ 241 int height; /* height */ 242 } im_rect; 243 244 typedef struct { 245 int max; /* The Maximum value of the color key */ 246 int min; /* The minimum value of the color key */ 247 } im_colorkey_range; 248 249 250 typedef struct im_nn { 251 int scale_r; /* scaling factor on R channal */ 252 int scale_g; /* scaling factor on G channal */ 253 int scale_b; /* scaling factor on B channal */ 254 int offset_r; /* offset on R channal */ 255 int offset_g; /* offset on G channal */ 256 int offset_b; /* offset on B channal */ 257 } im_nn_t; 258 259 /* im_info definition */ 260 typedef struct { 261 void* vir_addr; /* virtual address */ 262 void* phy_addr; /* physical address */ 263 int fd; /* shared fd */ 264 265 int width; /* width */ 266 int height; /* height */ 267 int wstride; /* wstride */ 268 int hstride; /* hstride */ 269 int format; /* format */ 270 271 int color_space_mode; /* color_space_mode */ 272 int global_alpha; /* global_alpha */ 273 int rd_mode; 274 275 /* legarcy */ 276 int color; /* color, used by color fill */ 277 im_colorkey_range colorkey_range; /* range value of color key */ 278 im_nn_t nn; 279 int rop_code; 280 281 rga_buffer_handle_t handle; /* buffer handle */ 282 } rga_buffer_t; 283 284 typedef struct im_color { 285 union { 286 struct { 287 uint8_t red; 288 uint8_t green; 289 uint8_t blue; 290 uint8_t alpha; 291 }; 292 uint32_t value; 293 }; 294 } im_color_t; 295 296 typedef struct im_osd_invert_factor { 297 uint8_t alpha_max; 298 uint8_t alpha_min; 299 uint8_t yg_max; 300 uint8_t yg_min; 301 uint8_t crb_max; 302 uint8_t crb_min; 303 } im_osd_invert_factor_t; 304 305 typedef struct im_osd_bpp2 { 306 uint8_t ac_swap; // ac swap flag 307 // 0: CA 308 // 1: AC 309 uint8_t endian_swap; // rgba2bpp endian swap 310 // 0: Big endian 311 // 1: Little endian 312 im_color_t color0; 313 im_color_t color1; 314 } im_osd_bpp2_t; 315 316 typedef struct im_osd_block { 317 int width_mode; // normal or different 318 // IM_OSD_BLOCK_MODE_NORMAL 319 // IM_OSD_BLOCK_MODE_DIFFERENT 320 union { 321 int width; // normal_mode block width 322 int width_index; // different_mode block width index in RAM 323 }; 324 325 int block_count; // block count 326 327 int background_config; // background config is bright or dark 328 // IM_OSD_BACKGROUND_DEFAULT_BRIGHT 329 // IM_OSD_BACKGROUND_DEFAULT_DARK 330 331 int direction; // osd block direction 332 // IM_OSD_MODE_HORIZONTAL 333 // IM_OSD_MODE_VERTICAL 334 335 int color_mode; // using src1 color or config color 336 // IM_OSD_COLOR_PIXEL 337 // IM_OSD_COLOR_EXTERNAL 338 im_color_t normal_color; // config color: normal 339 im_color_t invert_color; // config color: invert 340 } im_osd_block_t; 341 342 typedef struct im_osd_invert { 343 int invert_channel; // invert channel config: 344 // IM_OSD_INVERT_CHANNEL_NONE 345 // IM_OSD_INVERT_CHANNEL_Y_G 346 // IM_OSD_INVERT_CHANNEL_C_RB 347 // IM_OSD_INVERT_CHANNEL_ALPHA 348 // IM_OSD_INVERT_CHANNEL_COLOR 349 // IM_OSD_INVERT_CHANNEL_BOTH 350 int flags_mode; // use external or inertnal RAM invert flags 351 // IM_OSD_FLAGS_EXTERNAL 352 // IM_OSD_FLAGS_INTERNAL 353 int flags_index; // flags index when using internal RAM invert flags 354 355 uint64_t invert_flags; // external invert flags 356 uint64_t current_flags; // current flags 357 358 int invert_mode; // invert use swap or factor 359 // IM_OSD_INVERT_USE_FACTOR 360 // IM_OSD_INVERT_USE_SWAP 361 im_osd_invert_factor_t factor; 362 363 int threash; 364 } im_osd_invert_t; 365 366 typedef struct im_osd { 367 int osd_mode; // osd mode: statistics or auto_invert 368 // IM_OSD_MODE_STATISTICS 369 // IM_OSD_MODE_AUTO_INVERT 370 im_osd_block_t block_parm; // osd block info config 371 372 im_osd_invert_t invert_config; 373 374 im_osd_bpp2_t bpp2_info; 375 } im_osd_t; 376 377 typedef struct im_intr_config { 378 uint32_t flags; 379 380 int read_threshold; 381 int write_start; 382 int write_step; 383 } im_intr_config_t; 384 385 typedef struct im_opt { 386 im_api_version_t version; 387 388 int color; /* color, used by color fill */ 389 im_colorkey_range colorkey_range; /* range value of color key */ 390 im_nn_t nn; 391 int rop_code; 392 393 int priority; 394 int core; 395 396 int mosaic_mode; 397 398 im_osd_t osd_config; 399 400 im_intr_config_t intr_config; 401 402 char reserve[128]; 403 } im_opt_t; 404 405 typedef struct im_context { 406 int priority; 407 IM_SCHEDULER_CORE core; 408 int check_mode; 409 } im_context_t; 410 411 typedef struct im_handle_param { 412 uint32_t width; 413 uint32_t height; 414 uint32_t format; 415 }im_handle_param_t; 416 417 #endif /* _RGA_IM2D_TYPE_H_ */ 418