1 /**************************************************************************
5 Copyright 2017 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_NEXELL_TYPES_H_
32 #define _TDM_NEXELL_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>
61 #define C(b, m) (((b) >> (m)) & 0xFF)
62 #define B(c, s) ((((unsigned int)(c)) & 0xff) << (s))
63 #define FOURCC(a, b, c, d) (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
64 #define FOURCC_STR(id) C(id, 0), C(id, 8), C(id, 16), C(id, 24)
66 #define IS_RGB(format) (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
67 format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
69 #define CLEAR(x) memset(&(x), 0, sizeof(x))
70 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
71 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
72 #define SWAP(a, b) ({int t; t = a; a = b; b = t; })
73 #define ROUNDUP(x) (ceil(floor((float)(height) / 4)))
75 #define ALIGN_TO_16B(x) ((((x) + (1 << 4) - 1) >> 4) << 4)
76 #define ALIGN_TO_32B(x) ((((x) + (1 << 5) - 1) >> 5) << 5)
77 #define ALIGN_TO_128B(x) ((((x) + (1 << 7) - 1) >> 7) << 7)
78 #define ALIGN_TO_2KB(x) ((((x) + (1 << 11) - 1) >> 11) << 11)
79 #define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13)
80 #define ALIGN_TO_64KB(x) ((((x) + (1 << 16) - 1) >> 16) << 16)
82 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
87 #define NUM_UI_LAYERS 2
89 #define ZPOS_CURSOR 2 // cursor
90 #define ZPOS_2 2 // ui
91 #define ZPOS_1 1 // ui, primary layer
92 #define ZPOS_0 0 // video
93 #define ZPOS_VIDEO1 0 // video
94 #define ZPOS_NONE -999
96 #define RETURN_VAL_IF_FAIL(cond, val) {\
98 TDM_ERR("'%s' failed", #cond);\
103 #define RETURN_IF_FAIL(cond) {\
105 TDM_ERR("'%s' failed", #cond);\
110 #define GOTO_IF_FAIL(cond, val) {\
112 TDM_ERR("'%s' failed", #cond);\
117 typedef struct _tdm_nexell_data tdm_nexell_data;
118 typedef struct _tdm_nexell_output_data tdm_nexell_output_data;
119 typedef struct _tdm_nexell_layer_data tdm_nexell_layer_data;
120 typedef struct _tdm_nexell_hwc_data tdm_nexell_hwc_data;
121 typedef struct _tdm_nexell_hwc_window_data tdm_nexell_hwc_window_data;
122 typedef struct _tdm_nexell_event_data tdm_nexell_event_data;
123 typedef struct _tdm_nexell_display_buffer tdm_nexell_display_buffer;
126 TDM_NEXELL_EVENT_TYPE_WAIT,
127 TDM_NEXELL_EVENT_TYPE_COMMIT,
128 TDM_NEXELL_EVENT_TYPE_PAGEFLIP,
129 } tdm_nexell_event_type;
131 struct _tdm_nexell_data
138 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47
139 int has_universal_plane;
144 struct udev_monitor *uevent_monitor;
145 tdm_event_loop_source *uevent_source;
148 drmModeResPtr mode_res;
149 drmModePlaneResPtr plane_res;
153 struct list_head output_list;
154 struct list_head buffer_list;
157 struct _tdm_nexell_display_buffer {
158 struct list_head link;
161 tbm_surface_h buffer;
165 unsigned int handles[4];
167 unsigned int pitches[4];
168 unsigned int offsets[4];
173 struct _tdm_nexell_event_data {
174 tdm_nexell_event_type type;
175 tdm_nexell_output_data *output_data;
179 struct display_properties_ids {
180 uint32_t connector_crtc_id;
181 uint32_t crtc_mode_id;
182 uint32_t crtc_active;
183 uint32_t plane_fb_id;
184 uint32_t plane_crtc_id;
185 uint32_t plane_src_x;
186 uint32_t plane_src_y;
187 uint32_t plane_src_w;
188 uint32_t plane_src_h;
189 uint32_t plane_crtc_x;
190 uint32_t plane_crtc_y;
191 uint32_t plane_crtc_w;
192 uint32_t plane_crtc_h;
196 struct _tdm_nexell_output_data {
197 struct list_head link;
199 /* data which are fixed at initializing */
200 tdm_nexell_data *nexell_data;
201 uint32_t connector_id;
205 uint32_t dpms_prop_id;
207 drmModeModeInfoPtr drm_modes;
208 tdm_output_mode *output_modes;
209 tdm_output_type connector_type;
210 unsigned int connector_type_id;
211 struct list_head layer_list;
212 tdm_nexell_layer_data *primary_layer;
214 /* not fixed data below */
215 tdm_output_vblank_handler vblank_func;
216 tdm_output_commit_handler commit_func;
218 tdm_output_conn_status status;
219 tdm_output_status_handler status_func;
220 void *status_user_data;
223 const tdm_output_mode *current_mode;
225 struct display_properties_ids props;
232 uint32_t crtc_mode_id;
233 uint32_t crtc_active;
238 tdm_nexell_hwc_data *hwc_data;
241 struct _tdm_nexell_layer_data {
242 struct list_head link;
244 /* data which are fixed at initializing */
245 tdm_nexell_data *nexell_data;
246 tdm_nexell_output_data *output_data;
248 tdm_layer_capability capabilities;
251 /* not fixed data below */
255 tdm_nexell_display_buffer *display_buffer;
256 int display_buffer_changed;
274 struct _tdm_nexell_hwc_data {
275 tdm_nexell_hwc_window_data *target_hwc_window;
278 int need_target_window;
281 int target_window_zpos;
283 tdm_nexell_output_data *output_data;
284 struct list_head hwc_window_list;
286 tbm_surface_queue_h cursor_tqueue;
287 tbm_surface_h cursor_tsurface;
289 /* UI buffer_queue list for the reserved scanout memory */
291 tbm_surface_queue_h tqueue;
293 } ui_buffer_queue[NUM_LAYERS];
295 tdm_hwc_commit_handler commit_func;
298 struct _tdm_nexell_hwc_window_data {
299 struct list_head link;
301 tdm_nexell_hwc_data *hwc_data;
303 tdm_hwc_window_info info;
304 tbm_surface_h surface;
305 tdm_hwc_window_composition client_type;
306 tdm_hwc_window_composition validated_type;
310 char name[TDM_NAME_LEN];
317 int cursor_img_surface;
318 int cursor_img_refresh;
323 #endif /* _TDM_NEXELL_TYPES_H_ */