• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Samsung Electronics Co.,LTD.
3  * Copyright (C) 2017 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __UAPI_G2D_H__
19 #define __UAPI_G2D_H__
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define G2D_SWZ_MASK           0xFFFF
26 
27 #define G2D_SWZ_ARGB           0x3210
28 #define G2D_SWZ_ABGR           0x3012
29 #define G2D_SWZ_xBGR           0x5012
30 #define G2D_SWZ_xRGB           0x5210
31 
32 #define G2D_SWZ_ALPHA_MASK     (0xF << 12)
33 #define G2D_SWZ_ALPHA_ONE      (0x5 << 12)
34 
35 #define G2D_YUVORDER_MASK      (0x3 << 24)
36 
37 #define G2D_YUV_UV             ((1 << 24) | G2D_SWZ_ARGB)
38 #define G2D_YUV_VU             ((0 << 24) | G2D_SWZ_ARGB)
39 #define G2D_YUV_YC             (0 << 25)
40 #define G2D_YUV_CY             (1 << 25)
41 
42 #define G2D_DATAFORMAT_AFBC    (1 << 20)
43 #define G2D_DATAFORMAT_UORDER  (1 << 21)
44 #define G2D_DATAFORMAT_SBWC    (1 << 22)
45 
46 #define G2D_DATAFMT_SHIFT      16
47 #define G2D_DATAFMT_MASK       (0xF << G2D_DATAFMT_SHIFT)
48 
49 #define G2D_DATAFMT_8888       (0 << G2D_DATAFMT_SHIFT)
50 #define G2D_DATAFMT_565        (1 << G2D_DATAFMT_SHIFT)
51 #define G2D_DATAFMT_4444       (2 << G2D_DATAFMT_SHIFT)
52 #define G2D_DATAFMT_888        (3 << G2D_DATAFMT_SHIFT)
53 #define G2D_DATAFMT_1555       (4 << G2D_DATAFMT_SHIFT)
54 #define G2D_DATAFMT_5551       (5 << G2D_DATAFMT_SHIFT)
55 #define G2D_DATAFMT_RGB8_MAX   (5 << G2D_DATAFMT_SHIFT)
56 #define G2D_DATAFMT_8          (6 << G2D_DATAFMT_SHIFT)
57 #define G2D_DATAFMT_RESERVED   (7 << G2D_DATAFMT_SHIFT)
58 #define G2D_DATAFMT_YUV_MIN    (8 << G2D_DATAFMT_SHIFT)
59 #define G2D_DATAFMT_YUV420SP   (8 << G2D_DATAFMT_SHIFT)
60 #define G2D_DATAFMT_YUV420P    (9 << G2D_DATAFMT_SHIFT)
61 #define G2D_DATAFMT_YUV422I    (10 << G2D_DATAFMT_SHIFT)
62 #define G2D_DATAFMT_YUV422SP   (11 << G2D_DATAFMT_SHIFT)
63 #define G2D_DATAFMT_P010_LGCY  (12 << G2D_DATAFMT_SHIFT)
64 #define G2D_DATAFMT_YUV_MAX    (12 << G2D_DATAFMT_SHIFT)
65 #define G2D_DATAFMT_ABGR2101010 (14 << G2D_DATAFMT_SHIFT)
66 
67 #define G2D_FMT_YCBCR_BITDEPTH_SHIFT 28
68 #define G2D_FMT_YCBCR_BITDEPTH_MASK  (0x3 << G2D_FMT_YCBCR_BITDEPTH_SHIFT)
69 #define G2D_FMT_YCBCR_8BIT     (0 << G2D_FMT_YCBCR_BITDEPTH_SHIFT)
70 #define G2D_FMT_YCBCR_10BIT    (1 << G2D_FMT_YCBCR_BITDEPTH_SHIFT)
71 
72 #define G2D_FMT_ARGB8888       (G2D_DATAFMT_8888 | G2D_SWZ_ARGB)
73 #define G2D_FMT_ABGR8888       (G2D_DATAFMT_8888 | G2D_SWZ_ABGR)
74 #define G2D_FMT_XBGR8888       (G2D_DATAFMT_8888 | G2D_SWZ_xBGR)
75 #define G2D_FMT_RGB565         (G2D_DATAFMT_565 | G2D_SWZ_xRGB)
76 #define G2D_FMT_BGR565         (G2D_DATAFMT_565 | G2D_SWZ_xBGR)
77 #define G2D_FMT_RGB888         (G2D_DATAFMT_888 | G2D_SWZ_xRGB)
78 #define G2D_FMT_NV12           (G2D_DATAFMT_YUV420SP | G2D_YUV_UV)
79 #define G2D_FMT_NV21           (G2D_DATAFMT_YUV420SP | G2D_YUV_VU)
80 #define G2D_FMT_YUV420P        (G2D_DATAFMT_YUV420P | G2D_YUV_UV)
81 #define G2D_FMT_YV12           (G2D_DATAFMT_YUV420P | G2D_YUV_VU)
82 #define G2D_FMT_YUYV           (G2D_DATAFMT_YUV422I | G2D_YUV_YC | G2D_YUV_UV)
83 #define G2D_FMT_YVYU           (G2D_DATAFMT_YUV422I | G2D_YUV_YC | G2D_YUV_VU)
84 #define G2D_FMT_UYVY           (G2D_DATAFMT_YUV422I | G2D_YUV_CY | G2D_YUV_UV)
85 #define G2D_FMT_VYUY           (G2D_DATAFMT_YUV422I | G2D_YUV_CY | G2D_YUV_VU)
86 #define G2D_FMT_NV16           (G2D_DATAFMT_YUV422SP | G2D_YUV_UV)
87 #define G2D_FMT_NV61           (G2D_DATAFMT_YUV422SP | G2D_YUV_VU)
88 #define G2D_FMT_NV12_P010_LGCY (G2D_DATAFMT_P010_LGCY | G2D_YUV_UV)
89 #define G2D_FMT_NV21_P010_LGCY (G2D_DATAFMT_P010_LGCY | G2D_YUV_VU)
90 #define G2D_FMT_NV12_P010      (G2D_DATAFMT_YUV420SP | G2D_FMT_YCBCR_10BIT | G2D_YUV_UV)
91 #define G2D_FMT_NV21_P010      (G2D_DATAFMT_YUV420SP | G2D_FMT_YCBCR_10BIT | G2D_YUV_VU)
92 #define G2D_FMT_NV16_P210      (G2D_DATAFMT_YUV422SP | G2D_FMT_YCBCR_10BIT | G2D_YUV_UV)
93 #define G2D_FMT_NV61_P210      (G2D_DATAFMT_YUV422SP | G2D_FMT_YCBCR_10BIT | G2D_YUV_VU)
94 #define G2D_FMT_ABGR2101010    (G2D_DATAFMT_ABGR2101010 | G2D_SWZ_ABGR)
95 #define G2D_FMT_NV12_SBWC      (G2D_FMT_NV12 | G2D_DATAFORMAT_SBWC)
96 #define G2D_FMT_NV21_SBWC      (G2D_FMT_NV21 | G2D_DATAFORMAT_SBWC)
97 #define G2D_FMT_NV12_SBWC_10B  (G2D_FMT_NV12_P010 | G2D_DATAFORMAT_SBWC)
98 #define G2D_FMT_NV21_SBWC_10B  (G2D_FMT_NV21_P010 | G2D_DATAFORMAT_SBWC)
99 
100 #define G2D_YCBCRMODE_DITHER   (1 << 2)
101 
102 #define IS_YUV(fmt) ((((fmt) & G2D_DATAFMT_MASK) >= G2D_DATAFMT_YUV_MIN) && (((fmt) & G2D_DATAFMT_MASK) <= G2D_DATAFMT_YUV_MAX))
103 #define IS_RGB(fmt) ((((fmt) & G2D_DATAFMT_MASK) <= G2D_DATAFMT_RGB8_MAX) || (((fmt) & G2D_DATAFMT_MASK) > G2D_DATAFMT_YUV_MAX))
104 
105 #define G2D_IMGFMT(value) ((value) & \
106             (G2D_DATAFMT_MASK | G2D_YUVORDER_MASK | G2D_SWZ_MASK))
107 
108 #define G2D_MAX_PLANES    4
109 
110 #define G2D_ROTATEDIR_FLIP_SHIFT    4
111 #define G2D_ROTATEDIR_ROT90CCW      (1 << 0)
112 
113 #define G2D_BLEND_NONE    (2 | (2 << 4) | (2 << 8) | (2 << 12) | (1 << 18)) // Ga*Sa*Sc + (1-Sa*Ga)*Dc
114 #define G2D_BLEND_SRCOVER (6 |            (2 << 8) | (2 << 12) | (1 << 18)) // Ga*Sc + (1-Sa*Ga)*Dc
115 #define G2D_BLEND_SRCCOPY (6 |            (1 << 8)                        ) // Ga*Sc
116 
117 #define G2D_LAYERCMD_PREMULT_GLOBALALPHA   (2 << 24)
118 #define G2D_LAYERCMD_PREMULT_ALPHA         (1 << 24)
119 
120 #define G2D_LAYERCMD_ALPHABLEND (1 << 20)
121 #define G2D_LAYERCMD_OPAQUE     (1 << 1)
122 #define G2D_LAYERCMD_VALID      (1 << 0)
123 
124 #define G2D_LAYERSEL_COLORFILL   1
125 
126 #define G2D_LAYER_YCBCRMODE_WIDE (1 << 4)
127 #define G2D_LAYER_YCBCRMODE_OFFX (2 << 8)
128 #define G2D_LAYER_YCBCRMODE_OFFY (2 << 12)
129 
130 #define G2D_SCALECONTROL_BILINEAR 2
131 #define G2D_SCALECONTROL_POLYPHASE 3
132 #define G2D_SCALECONTROL_FILTERCOEF_SHIFT 4
133 #define G2D_SCALEFACTOR_FRACBITS  16
134 
135 #define G2D_LAYER_HDRMODE_DEMULT_ALPHA (1 << 12)
136 
137 struct g2d_reg {
138     uint32_t offset;
139     uint32_t value;
140 };
141 
142 enum g2dsfr_img_register {
143     G2DSFR_IMG_STRIDE,
144     G2DSFR_IMG_COLORMODE,
145     G2DSFR_IMG_LEFT,
146     G2DSFR_IMG_TOP,
147     G2DSFR_IMG_RIGHT,
148     G2DSFR_IMG_BOTTOM,
149     G2DSFR_IMG_WIDTH,
150     G2DSFR_IMG_HEIGHT,
151 
152     G2DSFR_IMG_FIELD_COUNT,
153 };
154 
155 /*
156  * The order of command list should be fixed.
157  * The new command item must be added from the bottom.
158  */
159 enum g2dsfr_src_register {
160     G2DSFR_SRC_COMMAND = G2DSFR_IMG_FIELD_COUNT,
161     G2DSFR_SRC_SELECT,
162     G2DSFR_SRC_ROTATE,
163     G2DSFR_SRC_DSTLEFT,
164     G2DSFR_SRC_DSTTOP,
165     G2DSFR_SRC_DSTRIGHT,
166     G2DSFR_SRC_DSTBOTTOM,
167     G2DSFR_SRC_SCALECONTROL,
168     G2DSFR_SRC_XSCALE,
169     G2DSFR_SRC_YSCALE,
170     G2DSFR_SRC_XPHASE,
171     G2DSFR_SRC_YPHASE,
172     G2DSFR_SRC_COLOR,
173     G2DSFR_SRC_ALPHA,
174     G2DSFR_SRC_BLEND,
175     G2DSFR_SRC_YCBCRMODE,
176     G2DSFR_SRC_HDRMODE,
177     G2DSFR_SRC_Y_HEADER_STRIDE,
178     G2DSFR_SRC_Y_PAYLOAD_STRIDE,
179     G2DSFR_SRC_C_HEADER_STRIDE,
180     G2DSFR_SRC_C_PAYLOAD_STRIDE,
181     G2DSFR_SRC_SBWCINFO,
182 
183     G2DSFR_SRC_FIELD_COUNT
184 };
185 
186 enum g2dsfr_dst_register {
187     G2DSFR_DST_YCBCRMODE = G2DSFR_IMG_FIELD_COUNT,
188 
189     G2DSFR_DST_COMPAT_FIELD_COUNT,
190 
191     G2DSFR_DST_Y_HEADER_STRIDE = G2DSFR_DST_COMPAT_FIELD_COUNT,
192     G2DSFR_DST_Y_PAYLOAD_STRIDE,
193     G2DSFR_DST_C_HEADER_STRIDE,
194     G2DSFR_DST_C_PAYLOAD_STRIDE,
195     G2DSFR_DST_SBWCINFO,
196 
197     G2DSFR_DST_FIELD_COUNT,
198 };
199 
200 #define G2D_MAX_PLANES         4
201 #define G2D_MAX_SFR_COUNT      1024
202 #define G2D_MAX_BUFFERS        4
203 #define G2D_MAX_IMAGES         16
204 #define G2D_MAX_PRIORITY       3
205 #define G2D_MAX_RELEASE_FENCES (G2D_MAX_IMAGES + 1)
206 
207 struct g2d_compat_commands {
208     uint32_t       target[G2DSFR_DST_COMPAT_FIELD_COUNT];
209     uint32_t       *source[G2D_MAX_IMAGES];
210     struct g2d_reg *extra;
211     uint32_t       num_extra_regs;
212 };
213 
214 #define G2D_BUFTYPE_NONE    0
215 #define G2D_BUFTYPE_EMPTY   1
216 #define G2D_BUFTYPE_USERPTR 2
217 #define G2D_BUFTYPE_DMABUF  3
218 
219 #define G2D_BUFTYPE_VALID(type) !(((type) & G2D_BUFTYPE_DMABUF) == 0)
220 
221 struct g2d_buffer {
222     union {
223         void *userptr;
224         struct {
225             int32_t  fd;
226             uint32_t offset;
227         } dmabuf;
228     };
229     uint32_t      length;
230 };
231 
232 #define G2D_LAYERFLAG_ACQUIRE_FENCE (1 << 1)
233 #define G2D_LAYERFLAG_SECURE (1 << 2)
234 #define G2D_LAYERFLAG_COLORFILL (1 << 3)
235 #define G2D_LAYERFLAG_MFC_STRIDE (1 << 4)
236 #define G2D_LAYERFLAG_AFBC_WIDEBLK (1 << 5)
237 #define G2D_LAYERFLAG_NO_CACHECLEAN (1 << 16)
238 #define G2D_LAYERFLAG_NO_CACHEINV (1 << 17)
239 
240 struct g2d_layer {
241     uint32_t          flags;
242     int32_t           fence;
243     uint32_t          buffer_type;
244     uint32_t          num_buffers;
245     struct g2d_buffer buffer[G2D_MAX_BUFFERS];
246 };
247 
248 #define G2D_FLAG_DITHER   (1 << 1)
249 #define G2D_FLAG_NONBLOCK (1 << 2)
250 #define G2D_FLAG_HWFC     (1 << 3)
251 #define G2D_FLAG_APB      (1 << 4)
252 #define G2D_FLAG_ERROR    (1 << 5)
253 
254 struct g2d_compat_task {
255     uint32_t            version;
256     uint32_t            flags;
257     uint32_t            laptime_in_usec;
258     uint32_t            priority;
259     uint32_t            num_source;
260     uint32_t            num_release_fences;
261     int32_t             *release_fence;
262     struct g2d_layer    target;
263     struct g2d_layer    *source;
264     struct g2d_compat_commands commands;
265 };
266 
267 /*
268  * Commands must be flexible because it may change according to H/W changes.
269  * The commands must be written in the promised order as version.
270  */
271 struct g2d_commands {
272     uint32_t       *target;
273     uint32_t       *source[G2D_MAX_IMAGES];
274     struct g2d_reg *extra;
275     uint32_t       num_extra_regs;
276 };
277 
278 struct g2d_task {
279     uint32_t            version;
280     uint32_t            flags;
281     uint32_t            laptime_in_usec;
282     uint32_t            priority;
283     uint32_t            num_source;
284     uint32_t            num_release_fences;
285     int32_t             *release_fence;
286     struct g2d_layer    target;
287     struct g2d_layer    *source;
288     struct g2d_commands commands;
289 };
290 
291 #define G2D_PERF_LAYER_ROTATE     (1 << 0)
292 #define G2D_PERF_LAYER_SCALING    (1 << 1)
293 #define G2D_PERF_LAYER_YUV2P      (1 << 4)
294 #define G2D_PERF_LAYER_SBWC       (1 << 5)
295 #define G2D_PERF_LAYER_RGB_AFBC   (1 << 6)
296 #define G2D_PERF_LAYER_YUV_AFBC   (1 << 7)
297 
298 struct g2d_performance_layer {
299     uint16_t crop_width;
300     uint16_t crop_height;
301     uint16_t window_width;
302     uint16_t window_height;
303     uint32_t layer_attr;
304 };
305 
306 #define G2D_PERF_FRAME_SOLIDCOLORFILL    (1 << 0)
307 
308 struct g2d_performance_frame {
309     struct g2d_performance_layer layer[G2D_MAX_IMAGES];
310     uint32_t bandwidth_read;
311     uint32_t bandwidth_write;
312     uint32_t target_pixelcount;
313     uint32_t frame_rate;
314     uint32_t frame_attr;
315     uint32_t num_layers;
316 };
317 
318 #define G2D_PERF_MAX_FRAMES 4
319 
320 struct g2d_performance {
321     struct g2d_performance_frame frame[G2D_PERF_MAX_FRAMES];
322     uint32_t num_frame;
323     uint32_t reserved;
324 };
325 
326 enum g2d_priority {
327     G2D_LOW_PRIORITY,
328     G2D_MEDIUM_PRIORITY,
329     G2D_DEFAULT_PRIORITY = G2D_MEDIUM_PRIORITY,
330     G2D_HIGH_PRIORITY,
331     G2D_HIGHEST_PRIORITY,
332     G2D_PRIORITY_END
333 };
334 
335 #define G2D_IOC_PROCESS        _IOWR('M', 3, struct g2d_task)
336 #define G2D_IOC_COMPAT_PROCESS _IOWR('M', 4, struct g2d_compat_task)
337 #define G2D_IOC_PRIORITY       _IOR('M', 5, int32_t)
338 #define G2D_IOC_PERFORMANCE    _IOR('M', 6, struct g2d_performance)
339 #define G2D_IOC_VERSION		_IOR('M', 7, uint32_t)
340 
341 #ifdef __cplusplus
342 }
343 #endif
344 
345 #endif /* __UAPI_G2D_H__ */
346