Add missing boilerplate
[platform/adaptation/libtdm-drm.git] / src / libtdm-drm / tdm_drm_types.h
1 /**************************************************************************
2
3 libtdm_drm
4
5 Copyright 2015 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 _TDM_DRM_TYPES_H_
32 #define _TDM_DRM_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
46 #include <linux/fb.h>
47 #include <xf86drm.h>
48 #include <xf86drmMode.h>
49 #include <tbm_surface.h>
50 #include <tbm_surface_internal.h>
51 #include <tdm_backend.h>
52 #include <tdm_log.h>
53 #include <tdm_list.h>
54 #include <drm_fourcc.h>
55 #include <tdm_helper.h>
56
57 #if HAVE_UDEV
58 #include <libudev.h>
59 #endif
60
61 #define MIN_WIDTH   32
62
63 /* drm module internal macros, structures, functions */
64 #define NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")
65
66 #define C(b, m)                   (((b) >> (m)) & 0xFF)
67 #define B(c, s)                   ((((unsigned int)(c)) & 0xff) << (s))
68 #define FOURCC(a, b, c, d)       (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
69 #define FOURCC_STR(id)    C(id, 0), C(id, 8), C(id, 16), C(id, 24)
70
71 #define IS_RGB(format)    (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
72                                                          format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
73
74 #define CLEAR(x) memset(&(x), 0, sizeof(x))
75 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
76 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
77 #define SWAP(a, b)  ({int t; t = a; a = b; b = t; })
78 #define ROUNDUP(x)  (ceil(floor((float)(height) / 4)))
79
80 #define ALIGN_TO_16B(x) ((((x) + (1 <<  4) - 1) >>  4) <<  4)
81 #define ALIGN_TO_32B(x) ((((x) + (1 <<  5) - 1) >>  5) <<  5)
82 #define ALIGN_TO_128B(x)   ((((x) + (1 <<  7) - 1) >>  7) <<  7)
83 #define ALIGN_TO_2KB(x) ((((x) + (1 << 11) - 1) >> 11) << 11)
84 #define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13)
85 #define ALIGN_TO_64KB(x)   ((((x) + (1 << 16) - 1) >> 16) << 16)
86
87 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
88
89 #define CURSOR_MIN_W 192
90 #define CURSOR_MIN_H 192
91 #define CURSOR_MAX_W 192
92 #define CURSOR_MAX_H 192
93
94 #define RETURN_VAL_IF_FAIL(cond, val) {\
95         if (!(cond)) {\
96                 TDM_ERR("'%s' failed", #cond);\
97                 return val;\
98         } \
99 }
100
101 #define RETURN_IF_FAIL(cond) {\
102         if (!(cond)) {\
103                 TDM_ERR("'%s' failed", #cond);\
104                 return;\
105         } \
106 }
107
108 #define GOTO_IF_FAIL(cond, val) {\
109         if (!(cond)) {\
110                 TDM_ERR("'%s' failed", #cond);\
111                 goto val;\
112         } \
113 }
114
115 typedef struct _tdm_drm_data tdm_drm_data;
116 typedef struct _tdm_drm_output_data tdm_drm_output_data;
117 typedef struct _tdm_drm_layer_data tdm_drm_layer_data;
118 typedef struct _tdm_drm_hwc_data tdm_drm_hwc_data;
119 typedef struct _tdm_drm_hwc_window_data tdm_drm_hwc_window_data;
120 typedef struct _tdm_drm_event_data tdm_drm_event_data;
121 typedef struct _tdm_drm_display_buffer tdm_drm_display_buffer;
122
123 typedef enum {
124                 TDM_DRM_EVENT_TYPE_WAIT,
125                 TDM_DRM_EVENT_TYPE_COMMIT,
126                 TDM_DRM_EVENT_TYPE_PAGEFLIP,
127 } tdm_drm_event_type;
128
129 struct _tdm_drm_data {
130         tdm_display *dpy;
131
132         int drm_fd;
133
134 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4  && LIBDRM_MICRO_VERSION >= 47
135         int has_universal_plane;
136 #endif
137
138 #if HAVE_UDEV
139         struct udev_monitor *uevent_monitor;
140         tdm_event_loop_source *uevent_source;
141 #endif
142
143         drmModeResPtr mode_res;
144         drmModePlaneResPtr plane_res;
145
146         int hwc_mode;
147
148         struct list_head output_list;
149         struct list_head buffer_list;
150 };
151
152 struct _tdm_drm_display_buffer {
153         struct list_head link;
154
155         unsigned int fb_id;
156         tbm_surface_h buffer;
157         int width;
158         unsigned int height;
159         unsigned int format;
160         unsigned int handles[4];
161         unsigned int fds[4];
162         unsigned int pitches[4];
163         unsigned int offsets[4];
164         unsigned int size;
165         unsigned int count;
166 };
167
168 struct _tdm_drm_event_data {
169         tdm_drm_event_type type;
170         tdm_drm_output_data *output_data;
171         void *user_data;
172 };
173
174 struct _tdm_drm_output_data {
175         struct list_head link;
176
177         /* data which are fixed at initializing */
178         tdm_drm_data *drm_data;
179         uint32_t connector_id;
180         uint32_t encoder_id;
181         uint32_t crtc_id;
182         uint32_t pipe;
183         uint32_t dpms_prop_id;
184         int count_modes;
185         drmModeModeInfoPtr drm_modes;
186         tdm_output_mode *output_modes;
187         tdm_output_type connector_type;
188         unsigned int connector_type_id;
189         struct list_head layer_list;
190         tdm_drm_layer_data *primary_layer;
191
192         /* not fixed data below */
193         tdm_output_vblank_handler vblank_func;
194         tdm_output_commit_handler commit_func;
195
196         tdm_output_conn_status status;
197         tdm_output_status_handler status_func;
198         void *status_user_data;
199
200         int mode_changed;
201         const tdm_output_mode *current_mode;
202
203         /* hwc */
204         int hwc_enable;
205         tdm_drm_hwc_data *hwc_data;
206
207         /* dpms */
208         tdm_output_dpms current_dpms;
209 };
210
211 struct _tdm_drm_layer_data {
212         struct list_head link;
213
214         /* data which are fixed at initializing */
215         tdm_drm_data *drm_data;
216         tdm_drm_output_data *output_data;
217         uint32_t plane_id;
218         tdm_layer_capability capabilities;
219         int zpos;
220
221         /* not fixed data below */
222         tdm_info_layer info;
223         int info_changed;
224
225         tdm_drm_display_buffer *display_buffer;
226         int display_buffer_changed;
227 };
228
229 struct _tdm_drm_hwc_data {
230         tdm_drm_hwc_window_data *target_hwc_window;
231
232         int need_validate;
233         int need_target_window;
234         int need_set_crtc;
235
236         int target_window_zpos;
237
238         tdm_drm_output_data *output_data;
239         struct list_head hwc_window_list;
240
241         tbm_surface_h cursor_tsurface;
242
243         tdm_hwc_commit_handler commit_func;
244 };
245
246 struct _tdm_drm_hwc_window_data {
247         struct list_head link;
248
249         tdm_drm_hwc_data *hwc_data;
250
251         tdm_hwc_window_info info;
252         tbm_surface_h surface;
253         tdm_hwc_window_composition client_type;
254         tdm_hwc_window_composition validated_type;
255         int lzpos;
256
257         char name[TDM_NAME_LEN];
258         struct {
259                 int width;
260                 int height;
261                 int stride;
262                 void *ptr;
263         } cursor_img;
264         int cursor_img_surface;
265         int cursor_img_refresh;
266 };
267
268 #endif /* _TDM_DRM_TYPES_H_ */