Initialize Tizen 2.3
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / lib / xdbg_log_drmevent.c
1 /**************************************************************************
2
3 xdbg
4
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>
8          Sangjin LEE <lsj119@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <strings.h>
39 #include <sys/types.h>
40 #include <sys/fcntl.h>
41 #include <unistd.h>
42 #include <stdarg.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45
46 #include "xdbg.h"
47 #include "xdbg_log_int.h"
48 #include "xdbg_types.h"
49 #include <list.h>
50
51 #ifndef API
52 #define API __attribute__ ((visibility("default")))
53 #endif
54
55 typedef struct _xdbgVblankInfo
56 {
57     int crtc_pipe;
58     unsigned int client_idx;
59     unsigned int draw_id;
60     int flag;
61     unsigned long time;
62     struct xorg_list link;
63 } XDbgVblankInfo, *XDbgVblankInfoPtr;
64
65 typedef struct _xdbgPageFlipInfo
66 {
67     int crtc_pipe;
68     unsigned int client_idx;
69     unsigned int draw_id;
70     unsigned long time;
71     struct xorg_list link;
72 } XDbgPageFlipInfo, *XDbgPageFlipInfoPtr;
73
74 static int init_drmevent = 0;
75 static struct xorg_list vblank_event_list;
76 static struct xorg_list pageflip_event_list;
77
78 API void
79 xDbgLogDrmEventInit ()
80 {
81     init_drmevent = 1;
82
83     xorg_list_init (&vblank_event_list);
84     xorg_list_init (&pageflip_event_list);
85 }
86
87 API void
88 xDbgLogDrmEventDeInit ()
89 {
90     /* TODO: delete all link(xorg_list_del) in the two list */
91 }
92
93 API void *
94 xDbgLogDrmEventAddVblank ( int crtc_pipe, unsigned int client_idx, unsigned int draw_id, int flag)
95 {
96     XDbgVblankInfoPtr pVblankInfo = NULL;
97
98     pVblankInfo = calloc (1, sizeof (XDbgVblankInfo));
99     if (!pVblankInfo)
100         return NULL;
101
102     pVblankInfo->crtc_pipe = crtc_pipe;
103     pVblankInfo->client_idx = client_idx;
104     pVblankInfo->draw_id = draw_id;
105     pVblankInfo->flag = flag;
106     pVblankInfo->time =GetTimeInMillis();
107
108     xorg_list_init(&pVblankInfo->link);
109     xorg_list_add(&pVblankInfo->link, &vblank_event_list);
110
111     return (void *)pVblankInfo;
112 }
113
114 API void
115 xDbgLogDrmEventRemoveVblank (void *vblank_data)
116 {
117     XDbgVblankInfoPtr pVblankInfo = (XDbgVblankInfoPtr) vblank_data;
118
119     xorg_list_del (&pVblankInfo->link);
120     free (pVblankInfo);
121     pVblankInfo = NULL;
122 }
123
124 API void *
125 xDbgLogDrmEventAddPageflip (int crtc_pipe, unsigned int client_idx, unsigned int draw_id)
126 {
127     XDbgPageFlipInfoPtr pPageFlipInfo = NULL;
128
129     pPageFlipInfo = calloc (1, sizeof (XDbgPageFlipInfo));
130     if (!pPageFlipInfo)
131         return NULL;
132
133     pPageFlipInfo->crtc_pipe = crtc_pipe;
134     pPageFlipInfo->client_idx = client_idx;
135     pPageFlipInfo->draw_id = draw_id;
136     pPageFlipInfo->time =GetTimeInMillis();
137
138     xorg_list_init(&pPageFlipInfo->link);
139     xorg_list_add(&pPageFlipInfo->link, &pageflip_event_list);
140
141     return (void *)pPageFlipInfo;
142 }
143
144 API void
145 xDbgLogDrmEventRemovePageflip (void *pageflip_data)
146 {
147     XDbgPageFlipInfoPtr pPageFlipInfo = (XDbgPageFlipInfoPtr) pageflip_data;
148
149     xorg_list_del (&pPageFlipInfo->link);
150     free (pPageFlipInfo);
151     pPageFlipInfo = NULL;
152 }
153
154 API void
155 xDbgLogDrmEventPendingLists ( char *reply, int *len)
156 {
157     XDbgVblankInfoPtr vblank_ref = NULL;
158     XDbgVblankInfoPtr vblank_next = NULL;
159     XDbgPageFlipInfoPtr flip_ref = NULL;
160     XDbgPageFlipInfoPtr flip_next = NULL;
161     Bool check_flip = FALSE;
162     Bool check_vblank = FALSE;
163
164     if (!init_drmevent)
165     {
166         XDBG_REPLY ("drmevent_pending is not supported.\n");
167         return;
168     }
169
170
171     XDBG_REPLY ("[vblank event pending]\n");
172     xorg_list_for_each_entry_safe (vblank_ref, vblank_next, &vblank_event_list, link)
173     {
174         check_vblank = TRUE;
175
176         if (vblank_ref->flag > -1)
177         {
178             XDBG_REPLY ("req_time        client_id       draw_id       crtc_pipe     vblank_type\n");
179             XDBG_REPLY ("[%10.3f]    %5d          0x%x     %5d          %5d\n",
180                        (double)vblank_ref->time/1000.0,
181                        (unsigned int)vblank_ref->client_idx,
182                        (unsigned int)vblank_ref->draw_id, vblank_ref->crtc_pipe, vblank_ref->flag);
183         }
184         else
185         {
186             XDBG_REPLY ("req_time        vblank_type\n");
187             XDBG_REPLY ("[%10.3f]             %d\n", (double)vblank_ref->time/1000.0, vblank_ref->flag);
188         }
189     }
190     if (!check_vblank)
191         XDBG_REPLY ("\t no pending events\n");
192
193     XDBG_REPLY ("[flip event pending]\n");
194     xorg_list_for_each_entry_safe (flip_ref, flip_next, &pageflip_event_list, link)
195     {
196         check_flip = TRUE;
197
198         XDBG_REPLY ("req_time        client_id       draw_id       crtc_pipe\n");
199         XDBG_REPLY ("[%10.3f]    %5d           0x%x      %4d\n",
200                    (double)flip_ref->time/1000.0, (unsigned int)flip_ref->client_idx,
201                    (unsigned int)flip_ref->draw_id, flip_ref->crtc_pipe);
202     }
203     if (!check_flip)
204         XDBG_REPLY ("\t no pending events\n");
205 }
206
207
208