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 _HAL_TDM_NEXELL_TYPES_H_
32 #define _HAL_TDM_NEXELL_TYPES_H_
41 #include <sys/types.h>
43 #include <sys/ioctl.h>
48 #include <drm_fourcc.h>
50 #include <xf86drmMode.h>
52 #include <tbm_surface.h>
53 #include <tbm_surface_internal.h>
54 #include <tbm_surface_queue.h>
56 #include <hal-common.h>
57 #include <hal-tdm-types.h>
58 #include <hal-tdm-interface.h>
61 #include "tdm_backend_list.h"
62 #include "tdm_backend_log.h"
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)
69 #define IS_RGB(format) (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
70 format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
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)))
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)
85 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
90 #define NUM_UI_LAYERS 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
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;
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;
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;
126 struct _tdm_nexell_display
131 #if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47
132 int has_universal_plane;
137 struct udev_monitor *uevent_monitor;
140 drmModeResPtr mode_res;
141 drmModePlaneResPtr plane_res;
143 struct list_head output_list;
144 struct list_head buffer_list;
147 struct _tdm_nexell_display_buffer {
148 struct list_head link;
151 tbm_surface_h buffer;
155 unsigned int handles[4];
157 unsigned int pitches[4];
158 unsigned int offsets[4];
163 struct _tdm_nexell_event_data {
164 tdm_nexell_event_type type;
165 tdm_nexell_output *output_data;
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;
186 struct _tdm_nexell_output_data {
187 struct list_head link;
189 /* data which are fixed at initializing */
190 tdm_nexell_display *display_data;
191 uint32_t connector_id;
195 uint32_t dpms_prop_id;
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;
204 /* not fixed data below */
205 hal_tdm_output_vblank_handler vblank_func;
206 hal_tdm_output_commit_handler commit_func;
208 hal_tdm_output_conn_status status;
209 hal_tdm_output_status_handler status_func;
210 void *status_user_data;
213 const hal_tdm_output_mode *current_mode;
215 struct display_properties_ids props;
222 uint32_t crtc_mode_id;
223 uint32_t crtc_active;
227 tdm_nexell_hwc *hwc_data;
230 typedef struct _tdm_nexell_layer_info {
231 hal_tdm_info_config src_config;
233 hal_tdm_transform transform;
234 } tdm_nexell_layer_info;
236 typedef struct _tdm_nexell_caps_layer {
237 tdm_nexell_layer_capability capabilities; /**< The capabilities of layer_data */
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.
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. */
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;
261 struct _tdm_nexell_layer_data {
262 struct list_head link;
264 /* data which are fixed at initializing */
265 tdm_nexell_display *display_data;
266 tdm_nexell_output *output_data;
268 tdm_nexell_layer_capability capabilities;
271 /* not fixed data below */
272 tdm_nexell_layer_info info;
275 tdm_nexell_display_buffer *display_buffer;
276 int display_buffer_changed;
294 struct _tdm_nexell_hwc_data {
295 tdm_nexell_hwc_window_data *target_hwc_window;
298 int need_target_window;
301 int target_window_zpos;
303 tdm_nexell_output *output_data;
304 struct list_head hwc_window_list;
306 tbm_surface_queue_h cursor_tqueue;
307 tbm_surface_h cursor_tsurface;
309 /* UI buffer_queue list for the reserved scanout memory */
311 tbm_surface_queue_h tqueue;
313 } ui_buffer_queue[NUM_LAYERS];
315 hal_tdm_hwc_commit_handler commit_func;
318 struct _tdm_nexell_hwc_window_data {
319 struct list_head link;
321 tdm_nexell_hwc *hwc_data;
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;
330 char name[HAL_TDM_NAME_LEN];
337 int cursor_img_surface;
338 int cursor_img_refresh;
343 #endif /* _HAL_TDM_NEXELL_TYPES_H_ */