use drmHandleEvent() 39/60039/3 accepted/tizen/mobile/20160228.232057 submit/tizen/20160229.555555
authorRoman Marchenko <r.marchenko@samsung.com>
Fri, 19 Feb 2016 14:12:39 +0000 (16:12 +0200)
committerRoman Marchenko <r.marchenko@samsung.com>
Tue, 23 Feb 2016 15:50:04 +0000 (17:50 +0200)
Change-Id: I963bb434e8cfd436840b1f31ea6142ec023d41a1
Signed-off-by: Roman Marchenko <r.marchenko@samsung.com>
src/tdm_sprd.c [changed mode: 0644->0755]
src/tdm_sprd.h
src/tdm_sprd_display.c
src/tdm_sprd_pp.c

old mode 100644 (file)
new mode 100755 (executable)
index f3b3cab..70a70b7
@@ -9,6 +9,8 @@
 #include "tdm_sprd.h"
 #include <tdm_helper.h>
 
+#define SET_DRM_IRQ
+
 #define SPRD_DRM_NAME "sprd"
 
 static tdm_func_display sprd_func_display =
@@ -157,7 +159,7 @@ tdm_sprd_deinit(tdm_backend_data *bdata)
 
     TDM_INFO("deinit");
     tdm_sprd_display_destroy_output_list(sprd_data);
-    tdm_sprd_display_destroy_event_list(sprd_data);
+    tdm_sprd_display_deinit_event_handling(sprd_data);
 
     free(sprd_data);
     sprd_data = NULL;
@@ -195,7 +197,6 @@ tdm_sprd_init(tdm_display *dpy, tdm_error *error)
 
     LIST_INITHEAD(&sprd_data->output_list);
     LIST_INITHEAD(&sprd_data->buffer_list);
-    LIST_INITHEAD(&sprd_data->events_list);
 
     ret = tdm_backend_register_func_display(dpy, &sprd_func_display);
     if (ret != TDM_ERROR_NONE)
@@ -234,7 +235,7 @@ tdm_sprd_init(tdm_display *dpy, tdm_error *error)
     if (ret != TDM_ERROR_NONE)
         goto failed_l;
 
-    ret = tdm_sprd_display_create_event_list(sprd_data);
+    ret = tdm_sprd_display_init_event_handling(sprd_data);
     if (ret != TDM_ERROR_NONE)
         goto failed_l;
     if (error)
index 7527506..8b79922 100644 (file)
@@ -88,7 +88,8 @@ tdm_error    sprd_pp_set_done_handler(tdm_pp *pp, tdm_pp_done_handler func, void
 
 typedef struct _tdm_sprd_data
 {
-    struct list_head events_list;
+    drmEventContext evctx;
+
     tdm_display *dpy;
     int drm_fd;
     int output_count;
@@ -107,7 +108,7 @@ tdm_error    tdm_sprd_display_create_layer_list(tdm_sprd_data *sprd_data);
 
 tdm_error    tdm_sprd_pp_get_capability(tdm_sprd_data *sprd_data, tdm_caps_pp *caps);
 tdm_pp*      tdm_sprd_pp_create(tdm_sprd_data *sprd_data, tdm_error *error);
-void         tdm_sprd_pp_handler(int fd, tdm_sprd_data *sprd_data_p, void* hw_event_data);
-tdm_error   tdm_sprd_display_create_event_list(tdm_sprd_data *sprd_data);
-void        tdm_sprd_display_destroy_event_list(tdm_sprd_data *sprd_data);
+void         tdm_sprd_pp_handler(struct drm_sprd_ipp_event *hw_ipp_p);
+tdm_error   tdm_sprd_display_init_event_handling(tdm_sprd_data *sprd_data);
+void        tdm_sprd_display_deinit_event_handling(tdm_sprd_data *sprd_data);
 #endif /* _TDM_SPRD_H_ */
index 26950fb..d97d922 100644 (file)
@@ -28,13 +28,6 @@ typedef enum
     VBLANK_TYPE_COMMIT,
 } vblank_type_t;
 
-typedef struct
-{
-    struct list_head link;
-    uint32_t hw_event_type;
-    void (*hw_event_func)(int fd, tdm_sprd_data *sprd_data_p, void* hw_event_data);
-} hw_event_callback_t;
-
 struct _tdm_sprd_vblank_data_s
 {
     vblank_type_t type;
@@ -971,46 +964,10 @@ sprd_display_handle_events(tdm_backend_data *bdata)
 {
     tdm_sprd_data *sprd_data = bdata;
     RETURN_VAL_IF_FAIL(sprd_data, TDM_ERROR_INVALID_PARAMETER);
-    #define MAX_BUF_SIZE    1024
 
-    char buffer[MAX_BUF_SIZE];
-    unsigned int len, i;
-    hw_event_t *kernel_event_p;
-    hw_event_callback_t *event_list_cur = NULL, *event_list_next = NULL;
-    /* The DRM read semantics guarantees that we always get only
-     * complete events. */
-    len = read(sprd_data->drm_fd, buffer, sizeof buffer);
-    if (len == 0)
-    {
-        TDM_WRN("warning: the size of the drm_event is 0.");
-        return TDM_ERROR_NONE;
-    }
-    if (len < sizeof *kernel_event_p)
-    {
-        TDM_WRN("warning: the size of the drm_event is less than drm_event structure.");
+    if (drmHandleEvent(sprd_data->drm_fd, &sprd_data->evctx) < 0) {
         return TDM_ERROR_OPERATION_FAILED;
     }
-    if (len > MAX_BUF_SIZE)
-    {
-        TDM_WRN("warning: the size of the drm_event can be over the maximum size.");
-        return TDM_ERROR_OPERATION_FAILED;
-    }
-    i = 0;
-    while (i < len)
-    {
-        kernel_event_p = (hw_event_t *) &buffer[i];
-        LIST_FOR_EACH_ENTRY_SAFE(event_list_cur, event_list_next, &sprd_data->events_list, link)
-        {
-            if (event_list_cur->hw_event_type == kernel_event_p->type)
-            {
-                if (event_list_cur->hw_event_func)
-                    event_list_cur->hw_event_func(sprd_data->drm_fd, sprd_data, &buffer[i]);
-                break;
-            }
-        }
-        i += kernel_event_p->length;
-    }
-
     return TDM_ERROR_NONE;
 }
 
@@ -1472,13 +1429,25 @@ sprd_layer_unset_buffer(tdm_layer *layer)
     return TDM_ERROR_NONE;
 }
 
+static int
+_sprd_drm_user_handler(struct drm_event *event)
+{
+    RETURN_VAL_IF_FAIL(event, -1);
+
+    TDM_DBG("got event %d\n", event->type);
+
+    if (event->type != DRM_SPRD_IPP_EVENT)
+        return -1;
+
+    tdm_sprd_pp_handler((struct drm_sprd_ipp_event *)event);
+
+    return 0;
+}
+
 static void
-_sprd_drm_vblank_event (int fd, tdm_sprd_data *sprd_data_p, void* hw_event_data)
+_sprd_drm_vblank_event (int fd, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data)
 {
-    RETURN_VAL_IF_FAIL(hw_event_data,);
-    RETURN_VAL_IF_FAIL(sprd_data_p,);
-    struct drm_event_vblank *hw_vblank = (struct drm_event_vblank *) hw_event_data;
-    tdm_sprd_vblank_data *vblank_data = (tdm_sprd_vblank_data* )((unsigned long) hw_vblank->user_data);
+    tdm_sprd_vblank_data *vblank_data = (tdm_sprd_vblank_data* )user_data;
     tdm_sprd_output_data *output_data;
 
     if (!vblank_data)
@@ -1497,76 +1466,47 @@ _sprd_drm_vblank_event (int fd, tdm_sprd_data *sprd_data_p, void* hw_event_data)
     {
     case VBLANK_TYPE_WAIT:
         if (output_data->vblank_func)
-            output_data->vblank_func(output_data, hw_vblank->sequence,
-                                     hw_vblank->tv_sec, hw_vblank->tv_usec,
+            output_data->vblank_func(output_data, sequence,
+                                     tv_sec, tv_usec,
                                      vblank_data->user_data);
         break;
     case VBLANK_TYPE_COMMIT:
 
         if (output_data->commit_func)
-            output_data->commit_func(output_data, hw_vblank->sequence,
-                                     hw_vblank->tv_sec, hw_vblank->tv_usec,
+            output_data->commit_func(output_data, sequence,
+                                     tv_sec, tv_usec,
                                      vblank_data->user_data);
+
         break;
     default:
         return;
     }
 }
+
 static void
-_sprd_drm_flip_complete_event (int fd, tdm_sprd_data *sprd_data_p, void* hw_event_data)
+_sprd_drm_flip_complete_event (int fd, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data)
 {
     TDM_DBG("FLIP EVENT");
 }
 
 tdm_error
-tdm_sprd_display_create_event_list(tdm_sprd_data *sprd_data)
+tdm_sprd_display_init_event_handling(tdm_sprd_data *sprd_data)
 {
     RETURN_VAL_IF_FAIL(sprd_data, TDM_ERROR_INVALID_PARAMETER);
-    tdm_error ret_err = TDM_ERROR_NONE;
-    hw_event_callback_t *vblank_event_p = NULL;
-    hw_event_callback_t *ipp_event_p = NULL;
-    hw_event_callback_t *flip_complete_event_p = NULL;
-#ifdef HAVE_FB_VBLANK
-/** @TODO FB vblank */
-#else
-    if ((vblank_event_p = malloc(sizeof(hw_event_callback_t))) == NULL)
-    {
-        TDM_ERR("alloc fail");
-        ret_err = TDM_ERROR_OUT_OF_MEMORY;
-        goto bad_l;
-    }
-    vblank_event_p->hw_event_type = DRM_EVENT_VBLANK;
-    vblank_event_p->hw_event_func = _sprd_drm_vblank_event;
-    LIST_ADD(&vblank_event_p->link, &sprd_data->events_list);
-    if ((flip_complete_event_p = malloc(sizeof(hw_event_callback_t))) == NULL)
-    {
-        TDM_ERR("alloc fail");
-        ret_err = TDM_ERROR_OUT_OF_MEMORY;
-        goto bad_l;
-    }
-    flip_complete_event_p->hw_event_type = DRM_EVENT_FLIP_COMPLETE;
-    flip_complete_event_p->hw_event_func = _sprd_drm_flip_complete_event;
-    LIST_ADD(&flip_complete_event_p->link, &sprd_data->events_list);
-#endif
-    if ((ipp_event_p = malloc(sizeof(hw_event_callback_t))) == NULL)
-    {
-        TDM_ERR("alloc_fail");
-        ret_err = TDM_ERROR_OUT_OF_MEMORY;
-        goto bad_l;
-    }
-    ipp_event_p->hw_event_type = DRM_SPRD_IPP_EVENT;
-    ipp_event_p->hw_event_func = tdm_sprd_pp_handler;
-    LIST_ADD(&ipp_event_p->link, &sprd_data->events_list);
-    if (ret_err != TDM_ERROR_NONE)
-        goto bad_l;
+
+    sprd_data->evctx.version = 2;
+    sprd_data->evctx.page_flip_handler = _sprd_drm_flip_complete_event;
+    sprd_data->evctx.vblank_handler = _sprd_drm_vblank_event;
+
+    drmAddUserHandler(sprd_data->drm_fd, _sprd_drm_user_handler);
+
     return TDM_ERROR_NONE;
-bad_l:
-    tdm_sprd_display_destroy_event_list(sprd_data);
-    return ret_err;
 }
 
 void
-tdm_sprd_display_destroy_event_list(tdm_sprd_data *sprd_data)
+tdm_sprd_display_deinit_event_handling(tdm_sprd_data *sprd_data)
 {
-    RETURN_VAL_IF_FAIL(sprd_data,);
+    RETURN_VOID_IF_FAIL(sprd_data);
+
+    drmRemoveUserHandler(sprd_data->drm_fd, _sprd_drm_user_handler);
 }
index 2ea641c..7a68e99 100755 (executable)
@@ -231,10 +231,9 @@ _tdm_sprd_pp_cmd(tdm_sprd_pp_data *pp_data, unsigned int prop_id, enum drm_sprd_
 }
 #endif
 void
-tdm_sprd_pp_handler(int fd, tdm_sprd_data *sprd_data_p, void* hw_event_data_p)
+tdm_sprd_pp_handler(struct drm_sprd_ipp_event *hw_ipp_p)
 {
-    RETURN_VOID_IF_FAIL(hw_event_data_p);
-    struct drm_sprd_ipp_event *hw_ipp_p = (struct drm_sprd_ipp_event *) hw_event_data_p;
+    RETURN_VOID_IF_FAIL(hw_ipp_p);
     tdm_sprd_pp_data *found = NULL, *pp_data = (tdm_sprd_pp_data *)(unsigned long) hw_ipp_p->user_data;
     tdm_sprd_pp_buffer *b = NULL, *bb = NULL, *dequeued_buffer = NULL;
 
@@ -252,11 +251,6 @@ tdm_sprd_pp_handler(int fd, tdm_sprd_data *sprd_data_p, void* hw_event_data_p)
     if (!found)
         return;
 
-    if (sprd_data_p == NULL) {
-        sprd_data_p = pp_data->sprd_data;
-    }
-    RETURN_VOID_IF_FAIL(sprd_data_p);
-
     TDM_DBG("pp_data(%p) index(%d, %d) prop_id(%u)", pp_data, hw_ipp_p->buf_id[0], hw_ipp_p->buf_id[1], hw_ipp_p->prop_id);
     if (hw_ipp_p->prop_id != pp_data->prop_id)
     {