1 /**************************************************************************
5 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>
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:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
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.
29 **************************************************************************/
31 #ifndef _TDM_DRM_TYPES_H_
32 #define _TDM_DRM_TYPES_H_
41 #include <sys/types.h>
43 #include <sys/ioctl.h>
48 #include <xf86drmMode.h>
49 #include <tbm_surface.h>
50 #include <tbm_surface_internal.h>
51 #include <tdm_backend.h>
54 #include <drm_fourcc.h>
55 #include <tdm_helper.h>
63 /* drm module internal macros, structures, functions */
64 #define NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")
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)
71 #define IS_RGB(format) (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
72 format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
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)))
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)
87 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
89 #define CURSOR_MIN_W 192
90 #define CURSOR_MIN_H 192
91 #define CURSOR_MAX_W 192
92 #define CURSOR_MAX_H 192
94 #define RETURN_VAL_IF_FAIL(cond, val) {\
96 TDM_ERR("'%s' failed", #cond);\
101 #define RETURN_IF_FAIL(cond) {\
103 TDM_ERR("'%s' failed", #cond);\
108 #define GOTO_IF_FAIL(cond, val) {\
110 TDM_ERR("'%s' failed", #cond);\
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;
124 TDM_DRM_EVENT_TYPE_WAIT,
125 TDM_DRM_EVENT_TYPE_COMMIT,
126 TDM_DRM_EVENT_TYPE_PAGEFLIP,
127 } tdm_drm_event_type;
129 struct _tdm_drm_data {
134 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47
135 int has_universal_plane;
139 struct udev_monitor *uevent_monitor;
140 tdm_event_loop_source *uevent_source;
143 drmModeResPtr mode_res;
144 drmModePlaneResPtr plane_res;
148 struct list_head output_list;
149 struct list_head buffer_list;
152 struct _tdm_drm_display_buffer {
153 struct list_head link;
156 tbm_surface_h buffer;
160 unsigned int handles[4];
162 unsigned int pitches[4];
163 unsigned int offsets[4];
168 struct _tdm_drm_event_data {
169 tdm_drm_event_type type;
170 tdm_drm_output_data *output_data;
174 struct _tdm_drm_output_data {
175 struct list_head link;
177 /* data which are fixed at initializing */
178 tdm_drm_data *drm_data;
179 uint32_t connector_id;
183 uint32_t dpms_prop_id;
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;
192 /* not fixed data below */
193 tdm_output_vblank_handler vblank_func;
194 tdm_output_commit_handler commit_func;
196 tdm_output_conn_status status;
197 tdm_output_status_handler status_func;
198 void *status_user_data;
201 const tdm_output_mode *current_mode;
205 tdm_drm_hwc_data *hwc_data;
208 tdm_output_dpms current_dpms;
211 struct _tdm_drm_layer_data {
212 struct list_head link;
214 /* data which are fixed at initializing */
215 tdm_drm_data *drm_data;
216 tdm_drm_output_data *output_data;
218 tdm_layer_capability capabilities;
221 /* not fixed data below */
225 tdm_drm_display_buffer *display_buffer;
226 int display_buffer_changed;
229 struct _tdm_drm_hwc_data {
230 tdm_drm_hwc_window_data *target_hwc_window;
233 int need_target_window;
236 int target_window_zpos;
238 tdm_drm_output_data *output_data;
239 struct list_head hwc_window_list;
241 tbm_surface_h cursor_tsurface;
243 tdm_hwc_commit_handler commit_func;
246 struct _tdm_drm_hwc_window_data {
247 struct list_head link;
249 tdm_drm_hwc_data *hwc_data;
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;
257 char name[TDM_NAME_LEN];
264 int cursor_img_surface;
265 int cursor_img_refresh;
268 #endif /* _TDM_DRM_TYPES_H_ */