Home | History | Annotate | Download | only in exynos
      1 /*
      2  * Copyright (C) 2013 Samsung Electronics Co.Ltd
      3  * Authors:
      4  *	Inki Dae <inki.dae (at) samsung.com>
      5  *
      6  * This program is free software; you can redistribute  it and/or modify it
      7  * under  the terms of  the GNU General  Public License as published by the
      8  * Free Software Foundation;  either version 2 of the  License, or (at your
      9  * option) any later version.
     10  *
     11  */
     12 
     13 #ifndef _FIMG2D_H_
     14 #define _FIMG2D_H_
     15 
     16 #ifndef TRUE
     17 #define TRUE 0
     18 #endif
     19 #ifndef FALSE
     20 #define FALSE -1
     21 #endif
     22 
     23 #define G2D_MAX_CMD_NR		64
     24 #define G2D_MAX_GEM_CMD_NR	64
     25 #define G2D_MAX_CMD_LIST_NR	64
     26 #define G2D_PLANE_MAX_NR	2
     27 
     28 #define G2D_DOUBLE_TO_FIXED(d)		((unsigned int)((d) * 65536.0))
     29 
     30 enum e_g2d_color_mode {
     31 	/* COLOR FORMAT */
     32 	G2D_COLOR_FMT_XRGB8888,
     33 	G2D_COLOR_FMT_ARGB8888,
     34 	G2D_COLOR_FMT_RGB565,
     35 	G2D_COLOR_FMT_XRGB1555,
     36 	G2D_COLOR_FMT_ARGB1555,
     37 	G2D_COLOR_FMT_XRGB4444,
     38 	G2D_COLOR_FMT_ARGB4444,
     39 	G2D_COLOR_FMT_PRGB888,
     40 	G2D_COLOR_FMT_YCbCr444,
     41 	G2D_COLOR_FMT_YCbCr422,
     42 	G2D_COLOR_FMT_YCbCr420,
     43 	/* alpha 8bit */
     44 	G2D_COLOR_FMT_A8,
     45 	/* Luminance 8bit: gray color */
     46 	G2D_COLOR_FMT_L8,
     47 	/* alpha 1bit */
     48 	G2D_COLOR_FMT_A1,
     49 	/* alpha 4bit */
     50 	G2D_COLOR_FMT_A4,
     51 	G2D_COLOR_FMT_MASK,				/* VER4.1 */
     52 
     53 	/* COLOR ORDER */
     54 	G2D_ORDER_AXRGB		= (0 << 4),		/* VER4.1 */
     55 	G2D_ORDER_RGBAX		= (1 << 4),		/* VER4.1 */
     56 	G2D_ORDER_AXBGR		= (2 << 4),		/* VER4.1 */
     57 	G2D_ORDER_BGRAX		= (3 << 4),		/* VER4.1 */
     58 	G2D_ORDER_MASK		= (3 << 4),		/* VER4.1 */
     59 
     60 	/* Number of YCbCr plane */
     61 	G2D_YCbCr_1PLANE	= (0 << 8),		/* VER4.1 */
     62 	G2D_YCbCr_2PLANE	= (1 << 8),		/* VER4.1 */
     63 	G2D_YCbCr_PLANE_MASK	= (3 << 8),		/* VER4.1 */
     64 
     65 	/* Order in YCbCr */
     66 	G2D_YCbCr_ORDER_CrY1CbY0 = (0 << 12),			/* VER4.1 */
     67 	G2D_YCbCr_ORDER_CbY1CrY0 = (1 << 12),			/* VER4.1 */
     68 	G2D_YCbCr_ORDER_Y1CrY0Cb = (2 << 12),			/* VER4.1 */
     69 	G2D_YCbCr_ORDER_Y1CbY0Cr = (3 << 12),			/* VER4.1 */
     70 	G2D_YCbCr_ORDER_CrCb = G2D_YCbCr_ORDER_CrY1CbY0,	/* VER4.1 */
     71 	G2D_YCbCr_ORDER_CbCr = G2D_YCbCr_ORDER_CbY1CrY0,	/* VER4.1 */
     72 	G2D_YCbCr_ORDER_MASK = (3 < 12),			/* VER4.1 */
     73 
     74 	/* CSC */
     75 	G2D_CSC_601 = (0 << 16),		/* VER4.1 */
     76 	G2D_CSC_709 = (1 << 16),		/* VER4.1 */
     77 	G2D_CSC_MASK = (1 << 16),		/* VER4.1 */
     78 
     79 	/* Valid value range of YCbCr */
     80 	G2D_YCbCr_RANGE_NARROW = (0 << 17),	/* VER4.1 */
     81 	G2D_YCbCr_RANGE_WIDE = (1 << 17),	/* VER4.1 */
     82 	G2D_YCbCr_RANGE_MASK = (1 << 17),	/* VER4.1 */
     83 
     84 	G2D_COLOR_MODE_MASK = 0xFFFFFFFF,
     85 };
     86 
     87 enum e_g2d_select_mode {
     88 	G2D_SELECT_MODE_NORMAL	= (0 << 0),
     89 	G2D_SELECT_MODE_FGCOLOR = (1 << 0),
     90 	G2D_SELECT_MODE_BGCOLOR = (2 << 0),
     91 };
     92 
     93 enum e_g2d_repeat_mode {
     94 	G2D_REPEAT_MODE_REPEAT,
     95 	G2D_REPEAT_MODE_PAD,
     96 	G2D_REPEAT_MODE_REFLECT,
     97 	G2D_REPEAT_MODE_CLAMP,
     98 	G2D_REPEAT_MODE_NONE,
     99 };
    100 
    101 enum e_g2d_scale_mode {
    102 	G2D_SCALE_MODE_NONE = 0,
    103 	G2D_SCALE_MODE_NEAREST,
    104 	G2D_SCALE_MODE_BILINEAR,
    105 	G2D_SCALE_MODE_MAX,
    106 };
    107 
    108 enum e_g2d_buf_type {
    109 	G2D_IMGBUF_COLOR,
    110 	G2D_IMGBUF_GEM,
    111 	G2D_IMGBUF_USERPTR,
    112 };
    113 
    114 enum e_g2d_rop3_type {
    115 	G2D_ROP3_DST = 0xAA,
    116 	G2D_ROP3_SRC = 0xCC,
    117 	G2D_ROP3_3RD = 0xF0,
    118 	G2D_ROP3_MASK = 0xFF,
    119 };
    120 
    121 enum e_g2d_select_alpha_src {
    122 	G2D_SELECT_SRC_FOR_ALPHA_BLEND,	/* VER4.1 */
    123 	G2D_SELECT_ROP_FOR_ALPHA_BLEND,	/* VER4.1 */
    124 };
    125 
    126 enum e_g2d_transparent_mode {
    127 	G2D_TRANSPARENT_MODE_OPAQUE,
    128 	G2D_TRANSPARENT_MODE_TRANSPARENT,
    129 	G2D_TRANSPARENT_MODE_BLUESCREEN,
    130 	G2D_TRANSPARENT_MODE_MAX,
    131 };
    132 
    133 enum e_g2d_color_key_mode {
    134 	G2D_COLORKEY_MODE_DISABLE	= 0,
    135 	G2D_COLORKEY_MODE_SRC_RGBA	= (1<<0),
    136 	G2D_COLORKEY_MODE_DST_RGBA	= (1<<1),
    137 	G2D_COLORKEY_MODE_SRC_YCbCr	= (1<<2),		/* VER4.1 */
    138 	G2D_COLORKEY_MODE_DST_YCbCr	= (1<<3),		/* VER4.1 */
    139 	G2D_COLORKEY_MODE_MASK		= 15,
    140 };
    141 
    142 enum e_g2d_alpha_blend_mode {
    143 	G2D_ALPHA_BLEND_MODE_DISABLE,
    144 	G2D_ALPHA_BLEND_MODE_ENABLE,
    145 	G2D_ALPHA_BLEND_MODE_FADING,				/* VER3.0 */
    146 	G2D_ALPHA_BLEND_MODE_MAX,
    147 };
    148 
    149 enum e_g2d_op {
    150 	G2D_OP_CLEAR			= 0x00,
    151 	G2D_OP_SRC			= 0x01,
    152 	G2D_OP_DST			= 0x02,
    153 	G2D_OP_OVER			= 0x03,
    154 	G2D_OP_DISJOINT_CLEAR		= 0x10,
    155 	G2D_OP_DISJOINT_SRC		= 0x11,
    156 	G2D_OP_DISJOINT_DST		= 0x12,
    157 	G2D_OP_CONJOINT_CLEAR		= 0x20,
    158 	G2D_OP_CONJOINT_SRC		= 0x21,
    159 	G2D_OP_CONJOINT_DST		= 0x22,
    160 };
    161 
    162 enum e_g2d_coeff_mode {
    163 	G2D_COEFF_MODE_ONE,
    164 	G2D_COEFF_MODE_ZERO,
    165 	G2D_COEFF_MODE_SRC_ALPHA,
    166 	G2D_COEFF_MODE_SRC_COLOR,
    167 	G2D_COEFF_MODE_DST_ALPHA,
    168 	G2D_COEFF_MODE_DST_COLOR,
    169 	/* Global Alpha : Set by ALPHA_REG(0x618) */
    170 	G2D_COEFF_MODE_GB_ALPHA,
    171 	/* Global Alpha : Set by ALPHA_REG(0x618) */
    172 	G2D_COEFF_MODE_GB_COLOR,
    173 	/* (1-SRC alpha)/DST Alpha */
    174 	G2D_COEFF_MODE_DISJOINT_S,
    175 	/* (1-DST alpha)/SRC Alpha */
    176 	G2D_COEFF_MODE_DISJOINT_D,
    177 	/* SRC alpha/DST alpha */
    178 	G2D_COEFF_MODE_CONJOINT_S,
    179 	/* DST alpha/SRC alpha */
    180 	G2D_COEFF_MODE_CONJOINT_D,
    181 	/* DST alpha/SRC alpha */
    182 	G2D_COEFF_MODE_MASK
    183 };
    184 
    185 enum e_g2d_acoeff_mode {
    186 	G2D_ACOEFF_MODE_A,          /* alpha */
    187 	G2D_ACOEFF_MODE_APGA,	/* alpha + global alpha */
    188 	G2D_ACOEFF_MODE_AMGA,	/* alpha * global alpha */
    189 	G2D_ACOEFF_MODE_MASK
    190 };
    191 
    192 union g2d_point_val {
    193 	unsigned int val;
    194 	struct {
    195 		/*
    196 		 * Coordinate of Source Image
    197 		 * Range: 0 ~ 8000 (Requirement: SrcLeftX < SrcRightX)
    198 		 * In YCbCr 422 and YCbCr 420 format with even number.
    199 		 */
    200 		unsigned int x:16;
    201 		/*
    202 		 * Y Coordinate of Source Image
    203 		 * Range: 0 ~ 8000 (Requirement: SrcTopY < SrcBottomY)
    204 		 * In YCbCr 420 format with even number.
    205 		 */
    206 		unsigned int y:16;
    207 	} data;
    208 };
    209 
    210 union g2d_rop4_val {
    211 	unsigned int val;
    212 	struct {
    213 		enum e_g2d_rop3_type	unmasked_rop3:8;
    214 		enum e_g2d_rop3_type	masked_rop3:8;
    215 		unsigned int		reserved:16;
    216 	} data;
    217 };
    218 
    219 union g2d_bitblt_cmd_val {
    220 	unsigned int val;
    221 	struct {
    222 		/* [0:3] */
    223 		unsigned int			mask_rop4_en:1;
    224 		unsigned int			masking_en:1;
    225 		enum e_g2d_select_alpha_src	rop4_alpha_en:1;
    226 		unsigned int			dither_en:1;
    227 		/* [4:7] */
    228 		unsigned int			resolved1:4;
    229 		/* [8:11] */
    230 		unsigned int			cw_en:4;
    231 		/* [12:15] */
    232 		enum e_g2d_transparent_mode	transparent_mode:4;
    233 		/* [16:19] */
    234 		enum e_g2d_color_key_mode	color_key_mode:4;
    235 		/* [20:23] */
    236 		enum e_g2d_alpha_blend_mode	alpha_blend_mode:4;
    237 		/* [24:27] */
    238 		unsigned int src_pre_multiply:1;
    239 		unsigned int pat_pre_multiply:1;
    240 		unsigned int dst_pre_multiply:1;
    241 		unsigned int dst_depre_multiply:1;
    242 		/* [28:31] */
    243 		unsigned int fast_solid_color_fill_en:1;
    244 		unsigned int reserved:3;
    245 	} data;
    246 };
    247 
    248 union g2d_blend_func_val {
    249 	unsigned int val;
    250 	struct {
    251 		/* [0:15] */
    252 		enum e_g2d_coeff_mode src_coeff:4;
    253 		enum e_g2d_acoeff_mode src_coeff_src_a:2;
    254 		enum e_g2d_acoeff_mode src_coeff_dst_a:2;
    255 		enum e_g2d_coeff_mode dst_coeff:4;
    256 		enum e_g2d_acoeff_mode dst_coeff_src_a:2;
    257 		enum e_g2d_acoeff_mode dst_coeff_dst_a:2;
    258 		/* [16:19] */
    259 		unsigned int inv_src_color_coeff:1;
    260 		unsigned int resoled1:1;
    261 		unsigned int inv_dst_color_coeff:1;
    262 		unsigned int resoled2:1;
    263 		/* [20:23] */
    264 		unsigned int lighten_en:1;
    265 		unsigned int darken_en:1;
    266 		unsigned int win_ce_src_over_en:2;
    267 		/* [24:31] */
    268 		unsigned int reserved:8;
    269 	} data;
    270 };
    271 
    272 struct g2d_image {
    273 	enum e_g2d_select_mode		select_mode;
    274 	enum e_g2d_color_mode		color_mode;
    275 	enum e_g2d_repeat_mode		repeat_mode;
    276 	enum e_g2d_scale_mode		scale_mode;
    277 	unsigned int			xscale;
    278 	unsigned int			yscale;
    279 	unsigned char			rotate_90;
    280 	unsigned char			x_dir;
    281 	unsigned char			y_dir;
    282 	unsigned char			component_alpha;
    283 	unsigned int			width;
    284 	unsigned int			height;
    285 	unsigned int			stride;
    286 	unsigned int			need_free;
    287 	unsigned int			color;
    288 	enum e_g2d_buf_type		buf_type;
    289 	unsigned int			bo[G2D_PLANE_MAX_NR];
    290 	struct drm_exynos_g2d_userptr	user_ptr[G2D_PLANE_MAX_NR];
    291 	void				*mapped_ptr[G2D_PLANE_MAX_NR];
    292 };
    293 
    294 struct g2d_context {
    295 	int				fd;
    296 	unsigned int			major;
    297 	unsigned int			minor;
    298 	struct drm_exynos_g2d_cmd	cmd[G2D_MAX_CMD_NR];
    299 	struct drm_exynos_g2d_cmd	cmd_buf[G2D_MAX_GEM_CMD_NR];
    300 	unsigned int			cmd_nr;
    301 	unsigned int			cmd_buf_nr;
    302 	unsigned int			cmdlist_nr;
    303 };
    304 
    305 struct g2d_context *g2d_init(int fd);
    306 void g2d_fini(struct g2d_context *ctx);
    307 int g2d_exec(struct g2d_context *ctx);
    308 int g2d_solid_fill(struct g2d_context *ctx, struct g2d_image *img,
    309 			unsigned int x, unsigned int y, unsigned int w,
    310 			unsigned int h);
    311 int g2d_copy(struct g2d_context *ctx, struct g2d_image *src,
    312 		struct g2d_image *dst, unsigned int src_x,
    313 		unsigned int src_y, unsigned int dst_x, unsigned int dst_y,
    314 		unsigned int w, unsigned int h);
    315 int g2d_copy_with_scale(struct g2d_context *ctx, struct g2d_image *src,
    316 				struct g2d_image *dst, unsigned int src_x,
    317 				unsigned int src_y, unsigned int src_w,
    318 				unsigned int src_h, unsigned int dst_x,
    319 				unsigned int dst_y, unsigned int dst_w,
    320 				unsigned int dst_h, unsigned int negative);
    321 int g2d_blend(struct g2d_context *ctx, struct g2d_image *src,
    322 		struct g2d_image *dst, unsigned int src_x,
    323 		unsigned int src_y, unsigned int dst_x, unsigned int dst_y,
    324 		unsigned int w, unsigned int h, enum e_g2d_op op);
    325 #endif /* _FIMG2D_H_ */
    326