3d52813b74329f4167e9f9f81cfaa1d07418c44b
[platform/adaptation/nexell/libtdm-nexell.git] / src / libhal-backend-tdm-nexell / tdm_backend_nexell_types.h
1 /**************************************************************************
2
3 libtdm_nexell
4
5 Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
19 of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 #ifndef _HAL_TDM_NEXELL_TYPES_H_
32 #define _HAL_TDM_NEXELL_TYPES_H_
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <stdlib.h>
37 #include <pthread.h>
38 #include <errno.h>
39 #include <unistd.h>
40 #include <limits.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <sys/ioctl.h>
44 #include <fcntl.h>
45 #include <linux/fb.h>
46
47 #include <drm.h>
48 #include <drm_fourcc.h>
49 #include <xf86drm.h>
50 #include <xf86drmMode.h>
51
52 #include <tbm_surface.h>
53 #include <tbm_surface_internal.h>
54 #include <tbm_surface_queue.h>
55
56 #include <hal-common.h>
57 #include <hal-tdm-types.h>
58 #include <hal-tdm-interface.h>
59 #include <pixman.h>
60
61 #include "tdm_backend_list.h"
62 #include "tdm_backend_log.h"
63
64 #define C(b, m)                   (((b) >> (m)) & 0xFF)
65 #define B(c, s)                   ((((unsigned int)(c)) & 0xff) << (s))
66 #define FOURCC(a, b, c, d)       (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
67 #define FOURCC_STR(id)    C(id, 0), C(id, 8), C(id, 16), C(id, 24)
68
69 #define IS_RGB(format)    (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
70                                                    format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
71
72 #define CLEAR(x) memset(&(x), 0, sizeof(x))
73 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
74 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
75 #define SWAP(a, b)  ({int t; t = a; a = b; b = t; })
76 #define ROUNDUP(x)  (ceil(floor((float)(height) / 4)))
77
78 #define ALIGN_TO_16B(x) ((((x) + (1 <<  4) - 1) >>  4) <<  4)
79 #define ALIGN_TO_32B(x) ((((x) + (1 <<  5) - 1) >>  5) <<  5)
80 #define ALIGN_TO_128B(x)   ((((x) + (1 <<  7) - 1) >>  7) <<  7)
81 #define ALIGN_TO_2KB(x) ((((x) + (1 << 11) - 1) >> 11) << 11)
82 #define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13)
83 #define ALIGN_TO_64KB(x)   ((((x) + (1 << 16) - 1) >> 16) << 16)
84
85 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
86
87 #define NUM_BUFFERS    3
88
89 #define NUM_LAYERS     3
90 #define NUM_UI_LAYERS  2
91 #define ZPOS_MAX       2
92 #define ZPOS_CURSOR    2  // cursor
93 #define ZPOS_2         2  // ui
94 #define ZPOS_1         1  // ui, primary layer_data
95 #define ZPOS_0         0  // video
96 #define ZPOS_VIDEO1    0  // video
97 #define ZPOS_NONE      -999
98
99 typedef struct _tdm_nexell_display tdm_nexell_display;
100 typedef struct _tdm_nexell_output_data tdm_nexell_output;
101 typedef struct _tdm_nexell_layer_data tdm_nexell_layer;
102 typedef struct _tdm_nexell_hwc_data tdm_nexell_hwc;
103 typedef struct _tdm_nexell_hwc_window_data tdm_nexell_hwc_window_data;
104 typedef struct _tdm_nexell_event_data tdm_nexell_event_data;
105 typedef struct _tdm_nexell_display_buffer tdm_nexell_display_buffer;
106
107 typedef enum {
108         TDM_NEXELL_LAYER_CAPABILITY_CURSOR         = (1 << 0), /**< cursor */
109         TDM_NEXELL_LAYER_CAPABILITY_PRIMARY        = (1 << 1), /**< primary */
110         TDM_NEXELL_LAYER_CAPABILITY_OVERLAY        = (1 << 2), /**< overlay */
111         TDM_NEXELL_LAYER_CAPABILITY_GRAPHIC        = (1 << 4), /**< graphic */
112         TDM_NEXELL_LAYER_CAPABILITY_VIDEO          = (1 << 5), /**< video */
113         TDM_NEXELL_LAYER_CAPABILITY_SCALE          = (1 << 8), /**< if a layer_data has scale capability  */
114         TDM_NEXELL_LAYER_CAPABILITY_TRANSFORM      = (1 << 9), /**< if a layer_data has transform capability  */
115         TDM_NEXELL_LAYER_CAPABILITY_SCANOUT        = (1 << 10), /**< if a layer_data allows a scanout buffer only */
116         TDM_NEXELL_LAYER_CAPABILITY_RESEVED_MEMORY = (1 << 11), /**< if a layer_data allows a reserved buffer only */
117         TDM_NEXELL_LAYER_CAPABILITY_NO_CROP        = (1 << 12), /**< if a layer_data has no cropping capability */
118 } tdm_nexell_layer_capability;
119
120 typedef enum {
121         HAL_TDM_NEXELL_EVENT_TYPE_WAIT,
122         HAL_TDM_NEXELL_EVENT_TYPE_COMMIT,
123         HAL_TDM_NEXELL_EVENT_TYPE_PAGEFLIP,
124 } tdm_nexell_event_type;
125
126 struct _tdm_nexell_display
127 {
128         int drm_fd;
129         int scaler_fd;
130
131 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4  && LIBDRM_MICRO_VERSION >= 47
132         int has_universal_plane;
133         int has_atomic;
134 #endif
135
136 #if HAVE_UDEV
137         struct udev_monitor *uevent_monitor;
138 #endif
139
140         drmModeResPtr mode_res;
141         drmModePlaneResPtr plane_res;
142
143         struct list_head output_list;
144         struct list_head buffer_list;
145 };
146
147 struct _tdm_nexell_display_buffer {
148         struct list_head link;
149
150         unsigned int fb_id;
151         tbm_surface_h buffer;
152         int width;
153         unsigned int height;
154         unsigned int format;
155         unsigned int handles[4];
156         unsigned int fds[4];
157         unsigned int pitches[4];
158         unsigned int offsets[4];
159         unsigned int size;
160         unsigned int count;
161 };
162
163 struct _tdm_nexell_event_data {
164         tdm_nexell_event_type type;
165         tdm_nexell_output *output_data;
166         void *user_data;
167 };
168
169 struct display_properties_ids {
170         uint32_t connector_crtc_id;
171         uint32_t crtc_mode_id;
172         uint32_t crtc_active;
173         uint32_t plane_fb_id;
174         uint32_t plane_crtc_id;
175         uint32_t plane_src_x;
176         uint32_t plane_src_y;
177         uint32_t plane_src_w;
178         uint32_t plane_src_h;
179         uint32_t plane_crtc_x;
180         uint32_t plane_crtc_y;
181         uint32_t plane_crtc_w;
182         uint32_t plane_crtc_h;
183         uint32_t plane_zpos;
184 };
185
186 struct _tdm_nexell_output_data {
187         struct list_head link;
188
189         /* data which are fixed at initializing */
190         tdm_nexell_display *display_data;
191         uint32_t connector_id;
192         uint32_t encoder_id;
193         uint32_t crtc_id;
194         uint32_t pipe;
195         uint32_t dpms_prop_id;
196         int count_modes;
197         drmModeModeInfoPtr drm_modes;
198         hal_tdm_output_mode *output_modes;
199         hal_tdm_output_type connector_type;
200         unsigned int connector_type_id;
201         struct list_head layer_list;
202         tdm_nexell_layer *primary_layer;
203
204         /* not fixed data below */
205         hal_tdm_output_vblank_handler vblank_func;
206         hal_tdm_output_commit_handler commit_func;
207
208         hal_tdm_output_conn_status status;
209         hal_tdm_output_status_handler status_func;
210         void *status_user_data;
211
212         int mode_changed;
213         const hal_tdm_output_mode *current_mode;
214
215         struct display_properties_ids props;
216
217         int crtc_enabled;
218
219         /* atomic prop ids*/
220         struct {
221                 uint32_t crtc_id;
222                 uint32_t crtc_mode_id;
223                 uint32_t crtc_active;
224         } atomic_props_ids;
225
226         /* hwc */
227         tdm_nexell_hwc *hwc_data;
228 };
229
230 typedef struct _tdm_nexell_layer_info {
231         hal_tdm_info_config src_config;
232         hal_tdm_pos dst_pos;
233         hal_tdm_transform transform;
234 } tdm_nexell_layer_info;
235
236 typedef struct _tdm_nexell_caps_layer {
237         tdm_nexell_layer_capability capabilities;  /**< The capabilities of layer_data */
238
239         /**
240          * The z-order
241          * GRAPHIC layers are non-changeable. The zpos of GRAPHIC layers starts
242          * from 0. If there are 4 GRAPHIC layers, The zpos SHOULD be 0, 1, 2, 3.\n
243          * But the zpos of VIDEO layer_data is changeable by layer_set_video_pos() function
244          * of #tdm_func_layer. And The zpos of VIDEO layers is less than GRAPHIC
245          * layers or more than GRAPHIC layers.
246          * ie, ..., -2, -1, 4, 5, ... (if 0 <= GRAPHIC layer_data's zpos < 4).
247          * The zpos of VIDEO layers is @b relative. It doesn't need to start
248          * from -1 or 4. Let's suppose that there are two VIDEO layers.
249          * One has -2 zpos. Another has -4 zpos. Then -2 Video layer_data is higher
250          * than -4 VIDEO layer_data.
251         */
252         int zpos;
253
254         unsigned int format_count;      /**< The count of available formats */
255         tbm_format *formats;            /**< The @b newly-allocated array of formats. will be freed in frontend. */
256
257         unsigned int prop_count;        /**< The count of available properties */
258         hal_tdm_prop *props;                /**< The @b newly-allocated array of properties. will be freed in frontend. */
259 } tdm_nexell_caps_layer;
260
261 struct _tdm_nexell_layer_data {
262         struct list_head link;
263
264         /* data which are fixed at initializing */
265         tdm_nexell_display *display_data;
266         tdm_nexell_output *output_data;
267         uint32_t plane_id;
268         tdm_nexell_layer_capability capabilities;
269         int zpos;
270
271         /* not fixed data below */
272         tdm_nexell_layer_info info;
273         int info_changed;
274
275         tdm_nexell_display_buffer *display_buffer;
276         int display_buffer_changed;
277
278         /* atomic prop ids*/
279         struct {
280                 uint32_t fb_id;
281                 uint32_t crtc_id;
282                 uint32_t src_x;
283                 uint32_t src_y;
284                 uint32_t src_w;
285                 uint32_t src_h;
286                 uint32_t crtc_x;
287                 uint32_t crtc_y;
288                 uint32_t crtc_w;
289                 uint32_t crtc_h;
290                 uint32_t zpos;
291         } atomic_props_ids;
292 };
293
294 struct _tdm_nexell_hwc_data {
295         tdm_nexell_hwc_window_data *target_hwc_window;
296
297         int need_validate;
298         int need_target_window;
299         int need_set_crtc;
300
301         int target_window_zpos;
302
303         tdm_nexell_output *output_data;
304         struct list_head hwc_window_list;
305
306         tbm_surface_queue_h cursor_tqueue;
307         tbm_surface_h cursor_tsurface;
308
309         /* UI buffer_queue list for the reserved scanout memory */
310         struct {
311                 tbm_surface_queue_h tqueue;
312                 int ref_cnt;
313         } ui_buffer_queue[NUM_LAYERS];
314
315         hal_tdm_hwc_commit_handler commit_func;
316 };
317
318 struct _tdm_nexell_hwc_window_data {
319         struct list_head link;
320
321         tdm_nexell_hwc *hwc_data;
322
323         hal_tdm_hwc_window_info info;
324         tbm_surface_h surface;
325         hal_tdm_hwc_window_composition client_type;
326         hal_tdm_hwc_window_composition validated_type;
327         int lzpos;
328         int lzpos_queue;
329
330         char name[HAL_TDM_NAME_LEN];
331         struct {
332                 int width;
333                 int height;
334                 int stride;
335                 void *ptr;
336         } cursor_img;
337         int cursor_img_surface;
338         int cursor_img_refresh;
339
340         int constraints;
341 };
342
343 #endif /* _HAL_TDM_NEXELL_TYPES_H_ */