1 /*
2  * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3  * Copyright (c) Imagination Technologies Limited, UK
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Authors:
26  *    Fei Jiang <fei.jiang@intel.com>
27  *
28  */
29 
30 #include <va/va_backend.h>
31 #include <va/va_backend_tpi.h>
32 #include <va/va_backend_egl.h>
33 #include <va/va_drmcommon.h>
34 #include <stdlib.h>
35 
36 #include "psb_drv_video.h"
37 #include "psb_drv_debug.h"
38 #include "psb_buffer.h"
39 #include "psb_cmdbuf.h"
40 #include "psb_surface.h"
41 #include "hwdefs/mem_io.h"
42 #include "hwdefs/msvdx_offsets.h"
43 #include "hwdefs/dma_api.h"
44 #include "hwdefs/reg_io2.h"
45 #include "hwdefs/msvdx_vec_reg_io2.h"
46 #include "hwdefs/msvdx_vdmc_reg_io2.h"
47 #include "hwdefs/msvdx_mtx_reg_io2.h"
48 #include "hwdefs/msvdx_dmac_linked_list.h"
49 #include "hwdefs/msvdx_rendec_mtx_slice_cntrl_reg_io2.h"
50 #include "hwdefs/dxva_cmdseq_msg.h"
51 #include "hwdefs/dxva_fw_ctrl.h"
52 #include "hwdefs/fwrk_msg_mem_io.h"
53 #include "hwdefs/dxva_msg.h"
54 #include "hwdefs/msvdx_cmds_io2.h"
55 
56 #define PSB_VIDEO_DEBUG_FILE "/data/mediadrm/log"
57 #define PSB_VIDEO_TRACE_FILE "/data/mediadrm/trace"
58 #define PSB_VIDEO_DUMP_VABUF_FILE "/data/mediadrm/dump.va"
59 #define PSB_VIDEO_DUMP_VABUF_VERBOSE_FILE "/data/mediadrm/dump.va.verbose"
60 #define PSB_VIDEO_DUMP_YUVBUF_FILE "/data/mediadrm/dump.yuv"
61 
psb__open_log(void)62 void psb__open_log(void)
63 {
64     char log_fn[1024] = {0};
65     unsigned int suffix;
66     char env_fn[1024] = {0};//used to get file name from psbvideo.conf, only to check if value is set
67 
68     if ((psb_video_debug_fp != NULL) && (psb_video_debug_fp != stderr)) {
69         debug_fp_count++;
70     } else {
71         /* psb video info debug */
72         if (psb_parse_config("PSB_VIDEO_DEBUG", &env_fn[0]) == 0) {
73             strcpy(log_fn, PSB_VIDEO_DEBUG_FILE);
74             drv_debug_msg(VIDEO_DEBUG_GENERAL, "Log file %s , force use %s\n", env_fn, log_fn);
75             suffix = 0xffff & ((unsigned int)time(NULL));
76             snprintf(log_fn + strnlen(log_fn, 1024),
77                      (1024 - 8 - strnlen(log_fn, 1024)),
78                      ".%d.%d", getpid(), suffix);
79             psb_video_debug_fp = fopen(log_fn, "w");
80             if (psb_video_debug_fp == 0) {
81                 drv_debug_msg(VIDEO_DEBUG_ERROR, "Log file %s open failed, reason %s, fall back to stderr\n",
82                                    log_fn, strerror(errno));
83                 psb_video_debug_fp = stderr;
84             } else {
85                 drv_debug_msg(VIDEO_DEBUG_GENERAL, "Log file %s open successfully\n", log_fn);
86                 debug_fp_count++;
87             }
88 #ifdef ANDROID
89             ALOGD("PSB_VIDEO_DEBUG is enabled.\n");
90 #endif
91         } else {
92             psb_video_debug_fp = NULL;
93         }
94     }
95 
96     if(psb_parse_config("PSB_VIDEO_TRACE", &env_fn[0]) == 0) {
97         strcpy(log_fn, PSB_VIDEO_TRACE_FILE);
98         drv_debug_msg(VIDEO_DEBUG_GENERAL, "Log file %s , force use %s\n", env_fn, log_fn);
99         unsigned int suffix = 0xffff & ((unsigned int)time(NULL));
100         time_t curtime;
101 
102         log_fn[1024 - 8] = '\0';
103         if(strncmp(log_fn, "/dev/stdout", sizeof("/dev/stdout")) != 0)
104             sprintf(log_fn + strlen(log_fn), ".%d", suffix);
105         psb_video_trace_fp = fopen(log_fn, "w");
106         if (psb_video_trace_fp == NULL)
107             psb_video_trace_fp = stderr;
108         time(&curtime);
109         fprintf(psb_video_trace_fp, "---- %s\n---- Start Trace ----\n", ctime(&curtime));
110         debug_dump_count = 0;
111         g_hexdump_offset = 0;
112 #ifdef ANDROID
113         ALOGD("PSB_VIDEO_TRACE is enabled.\n");
114 #endif
115     } else {
116         psb_video_trace_fp = NULL;
117     }
118 
119     /* debug level include error, warning, general, init, entry, ...... */
120     if(psb_parse_config("PSB_VIDEO_DEBUG_LEVEL", &env_fn[0]) == 0) {
121         psb_video_debug_level = atoi(env_fn);
122 #ifdef ANDROID
123         ALOGD("psb_video_debug_level is %d parsed.\n", psb_video_debug_level);
124 #endif
125     } else {
126         psb_video_debug_level = 0x1;
127     }
128 
129     /* control debug output option, logcat output or print to file */
130     if(psb_parse_config("PSB_VIDEO_DEBUG_OPTION", &env_fn[0]) == 0) {
131         psb_video_debug_option = atoi(env_fn);
132 #ifdef ANDROID
133         ALOGD("psb_video_debug_option is %d parsed.\n", psb_video_debug_option);
134 #endif
135     } else {
136         psb_video_debug_option = 0;
137     }
138 
139     /* trace level include vabuf, cmdmsg buf, aux buffer, lldma */
140     if(psb_parse_config("PSB_VIDEO_TRACE_LEVEL", &env_fn[0]) == 0) {
141         psb_video_trace_level = atoi(env_fn);
142 #ifdef ANDROID
143         ALOGD("psb_video_trace_level is %d parsed.\n", psb_video_trace_level);
144 #endif
145     } else {
146         psb_video_trace_level = 0;
147     }
148 
149     /* control trace output option, logcat output or print to file */
150     if(psb_parse_config("PSB_VIDEO_TRACE_OPTION", &env_fn[0]) == 0) {
151         psb_video_trace_option = atoi(env_fn);
152 #ifdef ANDROID
153         ALOGD("psb_video_debug_option is %d parsed.\n", psb_video_trace_option);
154 #endif
155     } else {
156         psb_video_trace_option = 0;
157     }
158 
159     /* cmdbuf dump, every frame decoded cmdbuf dump to /data/ctrlAlloc%i.txt */
160     if(psb_parse_config("PSB_VIDEO_DUMP_CMDBUF", &env_fn[0]) == 0) {
161         if(strstr(env_fn, "true") != NULL)
162             psb_video_dump_cmdbuf = TRUE;
163         else
164             psb_video_dump_cmdbuf = FALSE;
165 #ifdef ANDROID
166         ALOGD("PSB_VIDEO_DUMP_CMDBUF is %d.\n", psb_video_dump_cmdbuf);
167 #endif
168     } else {
169         psb_video_dump_cmdbuf = FALSE;
170     }
171 
172     /* psb video va buffers dump */
173     if(psb_parse_config("PSB_VIDEO_DUMP_VABUF", &env_fn[0]) == 0) {
174         strcpy(log_fn, PSB_VIDEO_DUMP_VABUF_FILE);
175         drv_debug_msg(VIDEO_DEBUG_GENERAL, "Log file %s , force use %s\n", env_fn, log_fn);
176         unsigned int suffix = 0xffff & ((unsigned int)time(NULL));
177         /* Make sure there is space left for suffix */
178         log_fn[1024 - 12] = '\0';
179         if(strncmp(log_fn, "/dev/stdout", sizeof("/dev/stdout")) != 0)
180             snprintf(log_fn + strlen(log_fn), 11, ".%d", suffix);
181         psb_dump_vabuf_fp = fopen(log_fn, "w");
182 #ifdef ANDROID
183         ALOGD("PSB_VIDEO_DUMP_VABUF is enabled.\n");
184 #endif
185     } else {
186         psb_dump_vabuf_fp = NULL;
187     }
188 
189     /* psb video va buffer verbose dump */
190     if(psb_parse_config("PSB_VIDEO_DUMP_VABUF_VERBOSE", &env_fn[0]) == 0) {
191         strcpy(log_fn, PSB_VIDEO_DUMP_VABUF_VERBOSE_FILE);
192         drv_debug_msg(VIDEO_DEBUG_GENERAL, "Log file %s , force use %s\n", env_fn, log_fn);
193         unsigned int suffix = 0xffff & ((unsigned int)time(NULL));
194         /* Make sure there is space left for suffix */
195         log_fn[1024 - 12] = '\0';
196         if(strncmp(log_fn, "/dev/stdout", sizeof("/dev/stdout")) != 0)
197             snprintf(log_fn + strlen(log_fn), 11, ".%d", suffix);
198         psb_dump_vabuf_verbose_fp = fopen(log_fn, "w");
199 #ifdef ANDROID
200         ALOGD("PSB_VIDEO_DUMP_VABUF_VERBOSE is enabled.\n");
201 #endif
202     } else {
203         psb_dump_vabuf_verbose_fp = NULL;
204     }
205 
206     /* dump decoded surface to a yuv file */
207     if(psb_parse_config("PSB_VIDEO_DUMP_YUVBUF", &env_fn[0]) == 0) {
208         strcpy(log_fn, PSB_VIDEO_DUMP_YUVBUF_FILE);
209         drv_debug_msg(VIDEO_DEBUG_GENERAL, "Log file %s , force use %s\n", env_fn, log_fn);
210         unsigned int suffix = 0xffff & ((unsigned int)time(NULL));
211         /* Make sure there is space left for suffix */
212         log_fn[1024 - 12] = '\0';
213         if(strncmp(log_fn, "/dev/stdout", sizeof("/dev/stdout")) != 0)
214             snprintf(log_fn + strlen(log_fn), 11, ".%d", suffix);
215         psb_dump_yuvbuf_fp = fopen(log_fn, "ab");
216 #ifdef ANDROID
217         ALOGD("PSB_VIDEO_DUMP_YUVBUF is enabled.\n");
218 #endif
219     } else {
220         psb_dump_yuvbuf_fp = NULL;
221     }
222 }
223 
psb__close_log(void)224 void psb__close_log(void)
225 {
226     if ((psb_video_debug_fp != NULL) & (psb_video_debug_fp != stderr)) {
227         debug_fp_count--;
228         if (debug_fp_count == 0) {
229             fclose(psb_video_debug_fp);
230             psb_video_debug_fp = NULL;
231         }
232     }
233 
234     if(psb_video_trace_fp != NULL) {
235         fclose(psb_video_trace_fp);
236         psb_video_trace_fp = NULL;
237     }
238 
239     if(psb_dump_vabuf_fp != NULL) {
240         fclose(psb_dump_vabuf_fp);
241         psb_dump_vabuf_fp = NULL;
242     }
243 
244     if(psb_dump_vabuf_verbose_fp != NULL) {
245         fclose(psb_dump_vabuf_verbose_fp);
246         psb_dump_vabuf_verbose_fp = NULL;
247     }
248 
249     if(psb_dump_yuvbuf_fp != NULL) {
250         fclose(psb_dump_yuvbuf_fp);
251         psb_dump_yuvbuf_fp = NULL;
252     }
253 
254     return;
255 }
256 
257 /*
258  * read a config "env" for libva.conf or from environment setting
259  * liva.conf has higher priority
260  * return 0: the "env" is set, and the value is copied into env_value
261  *        1: the env is not set
262  */
psb_parse_config(char * env,char * env_value)263 int psb_parse_config(char *env, char *env_value)
264 {
265     char *token, *value, *saveptr;
266     char oneline[1024];
267     FILE *fp = NULL;
268     char *env_ptr;
269 
270     if (env == NULL)
271         return 1;
272 
273     fp = fopen("/etc/psbvideo.conf", "r");
274     while (fp && (fgets(oneline, 1024, fp) != NULL)) {
275         if (strlen(oneline) == 1)
276             continue;
277         token = strtok_r(oneline, "=\n", &saveptr);
278         value = strtok_r(NULL, "=\n", &saveptr);
279 
280         if (NULL == token || NULL == value)
281             continue;
282 
283         if (strcmp(token, env) == 0) {
284             if (env_value)
285                 strcpy(env_value, value);
286 
287             fclose(fp);
288 
289             return 0;
290         }
291     }
292     if (fp)
293         fclose(fp);
294 
295     env_ptr = getenv(env);
296     if (env_ptr) {
297         if (env_value)
298             strncpy(env_value, env_ptr, strlen(env_ptr));
299 
300         return 0;
301     }
302 
303     return 1;
304 }
305 
drv_debug_msg(DEBUG_LEVEL debug_level,const char * msg,...)306 void drv_debug_msg(DEBUG_LEVEL debug_level, const char *msg, ...)
307 {
308     va_list args;
309 
310 #ifdef ANDROID
311     if (debug_level == VIDEO_DEBUG_ERROR) {
312         va_start(args, msg);
313         char tag[128];
314         (void)tag;
315         sprintf(tag, "pvr_drv_video ");
316         __android_log_vprint(ANDROID_LOG_ERROR, tag, msg, args);
317         va_end(args);
318     }
319 
320     if ((psb_video_debug_option & PRINT_TO_LOGCAT) && (debug_level & psb_video_debug_level)) {
321         va_start(args, msg);
322         char tag[128];
323         (void)tag;
324         if (psb_video_debug_option & THREAD_DEBUG)
325             sprintf(tag, "pvr_drv_video[%d:0x%08lx]", getpid(), pthread_self());
326         else
327             sprintf(tag, "pvr_drv_video ");
328         __android_log_vprint(ANDROID_LOG_DEBUG, tag, msg, args);
329         va_end(args);
330     }
331 #endif
332 
333     if (!psb_video_debug_fp && (psb_video_debug_level & VIDEO_DEBUG_ERROR))
334         psb_video_debug_fp = stderr;
335     if (psb_video_debug_fp && (psb_video_debug_option & PRINT_TO_FILE) &&
336             (debug_level & psb_video_debug_level)) {
337         if (psb_video_debug_option & TIME_DEBUG)
338             fprintf(psb_video_debug_fp, "TickCount - [0x%08lx], ",
339                     GetTickCount());
340         if (psb_video_debug_option & THREAD_DEBUG)
341             fprintf(psb_video_debug_fp, "Thread - (%d:0x%08lx) ",
342                     getpid(), pthread_self());
343         va_start(args, msg);
344         vfprintf(psb_video_debug_fp, msg, args);
345         va_end(args);
346         fflush(psb_video_debug_fp);
347         //fsync(fileno(psb_video_debug_fp));
348     }
349 }
350 
psb__dump_I420_buffers(psb_surface_p psb_surface,short __maybe_unused srcx,short srcy,unsigned short srcw,unsigned short srch)351 int psb__dump_I420_buffers(
352     psb_surface_p psb_surface,
353     short __maybe_unused srcx,
354     short srcy,
355     unsigned short srcw,
356     unsigned short srch)
357 {
358     unsigned char *mapped_buffer;
359     unsigned char *mapped_buffer1, *mapped_buffer2;
360 
361     if (psb_dump_yuvbuf_fp) {
362         psb_buffer_map(&psb_surface->buf, (unsigned char**)&mapped_buffer);
363         if(mapped_buffer == NULL)
364             return VA_STATUS_ERROR_INVALID_BUFFER;
365 
366         int j,k;
367         mapped_buffer1 = mapped_buffer + psb_surface->stride * srcy;
368         mapped_buffer2 = mapped_buffer + psb_surface->stride * (srch + srcy / 2);
369         mapped_buffer = mapped_buffer2;
370 
371         for(j = 0; j < srch; ++j)
372         {
373             fwrite(mapped_buffer1,  srcw, 1, psb_dump_yuvbuf_fp);
374             mapped_buffer1 += psb_surface->stride;
375         }
376 
377          for(j = 0; j < srch /2; ++j) {
378             for(k = 0; k < srcw; ++k) {
379                 if((k%2) == 0)fwrite(mapped_buffer2, 1, 1, psb_dump_yuvbuf_fp);
380 
381                 mapped_buffer2++;
382             }
383             mapped_buffer2 += psb_surface->stride - srcw;
384         }
385 
386         mapped_buffer2 = mapped_buffer;
387         for(j = 0; j < srch /2; ++j)
388         {
389             for(k = 0; k < srcw; ++k)
390             {
391                 if((k % 2) == 1)
392                     fwrite(mapped_buffer2, 1, 1, psb_dump_yuvbuf_fp);
393                 mapped_buffer2++;
394             }
395             mapped_buffer2 += psb_surface->stride-srcw;
396         }
397 
398         psb_buffer_unmap(&psb_surface->buf);
399     }
400 
401     return 0;
402 }
403 
psb__dump_NV12_buffers(psb_surface_p psb_surface,short __maybe_unused srcx,short __maybe_unused srcy,unsigned short srcw,unsigned short srch)404 int psb__dump_NV12_buffers(
405     psb_surface_p psb_surface,
406     short __maybe_unused srcx,
407     short __maybe_unused srcy,
408     unsigned short srcw,
409     unsigned short srch)
410 {
411     unsigned char *mapped_buffer;
412     unsigned char *mapped_start;
413 
414     if (psb_dump_yuvbuf_fp) {
415         psb_buffer_map(&psb_surface->buf, (unsigned char **)&mapped_buffer);
416         if(mapped_buffer == NULL)
417             return VA_STATUS_ERROR_INVALID_BUFFER;
418 
419         int i;
420         int row = srch;
421 
422         mapped_start = mapped_buffer;
423         for(i = 0; i < row; ++i)
424         {
425             fwrite(mapped_buffer,  srcw, 1, psb_dump_yuvbuf_fp);
426             mapped_buffer += psb_surface->stride;
427         }
428 
429         mapped_buffer = mapped_start + psb_surface->chroma_offset;
430         for(i = 0; i < row/2; ++i)
431         {
432             fwrite(mapped_buffer,  srcw, 1, psb_dump_yuvbuf_fp);
433             mapped_buffer += psb_surface->stride;
434         }
435         psb_buffer_unmap(&psb_surface->buf);
436     }
437 
438     return 0;
439 }
440 
psb_cmdbuf_dump(unsigned int * buffer,int byte_size)441 int psb_cmdbuf_dump(unsigned int *buffer, int byte_size)
442 {
443     static int c=0;
444     static char pFileName[50];
445 
446     if (psb_video_dump_cmdbuf == FALSE)
447         return 0;
448 
449     sprintf( pFileName , "/data/ctrlAlloc%i.txt", c++);
450     FILE* pF = fopen(pFileName,"w");
451     if(pF == NULL) {
452         return 1;
453     }
454 
455     int idx=0;
456     unsigned int x;
457     while( idx <  byte_size / 4 )
458     {
459         unsigned int cmd = buffer[idx++];
460         fprintf( pF , "Command Word: %08X\n" , cmd  );
461         switch( cmd&0xf0000000  )
462         {
463             case 0x70000000:
464             {
465                 fprintf( pF , "%04X 2NDPASSDEBLOCK\n" , (idx-1)*4  );
466                 for( x=0;x< 5 ;x++)
467                 {
468                     fprintf( pF ,"\t\t%08X\n",
469                         buffer[idx]        );
470                     idx++;
471 
472                 }
473 
474                 break;
475             }
476             case 0x90000000:
477             {
478                 fprintf( pF , "%04X HEADER\n" , (idx-1)*4  );
479                 for( x=0;x< 7 ;x++)
480                 {
481                     fprintf( pF ,"\t\t%08X\n",
482                         buffer[idx]        );
483                     idx++;
484 
485                 }
486 
487                 break;
488             }
489 
490             case 0x10000000:
491             {
492                 fprintf( pF , "%04X CMD_REGVALPAIR_WRITE ( %08X )\n", (idx-1)*4 , cmd);
493                 unsigned int addr = cmd&0xffff;
494                 unsigned int count = (cmd>>16)&0xff;
495                 for( x=0;x< count ;x++)
496                 {
497                     fprintf( pF ,"\t\t%08X %08X\n",
498                         addr ,
499                         buffer[idx]    );
500                     idx+=1;
501                     addr+=4;
502 
503                 }
504                 break;
505             }
506 
507             case 0x50000000:
508             {
509                 fprintf( pF , "%04X CMD_RENDEC_BLOCK( %08X )\n", (idx-1)*4 , cmd);
510                 unsigned int  count    = (cmd>>16)&0x00ff;
511                 unsigned int  uiAddr = (cmd &0xffff );            /* to do,  limit this */
512 
513                 for( x=0;x< count ;x++)
514                 {
515                     fprintf( pF ,"\t\t%08X %08X\n",
516                         uiAddr ,
517                         buffer[idx++]    );
518                     uiAddr+= 4;
519 
520                 }
521                 break;
522             }
523             case 0xd0000000:
524             {
525                 fprintf( pF , "%04X CMD_NEXT_SEG\n", (idx-1)*4 );
526                 fprintf( pF , "wrong\n");
527                 goto done;
528 
529                 break;
530             }
531             case 0xb0000000:
532             {
533                 fprintf( pF , "%04X SR SETUP %08x\n" , (idx-1)*4  , cmd );
534                 for( x=0;x< 2 ;x++)
535                 {
536                     fprintf( pF ,"\t\t%08X\n",
537                         buffer[idx]        );
538                     idx++;
539 
540                 }
541                 break;
542             }
543 
544             case 0xf0000000:
545             {
546                 fprintf( pF , "%04X CMD_PARSE_HEADER %08x\n" , (idx-1)*4  , cmd );
547                 for( x=0;x< 8 ;x++)
548                 {
549                     fprintf( pF ,"\t\t%08X\n",
550                         buffer[idx]        );
551                     idx++;
552 
553                 }
554                 break;
555             }
556 
557         case 0x60000000:
558             goto done;
559 
560             default:
561                 fprintf( pF , "%04X %08x\n" ,(idx-1)*4 , cmd);
562 
563 
564         }
565 
566 
567     }
568 done:
569     fclose( pF );
570     return 0;
571 
572 }
573 
574 /********************* trace debug start *************************/
575 
psb__trace_message(const char * msg,...)576 void psb__trace_message(const char *msg, ...)
577 {
578     va_list args;
579 
580 #ifdef ANDROID
581     if ((psb_video_trace_option & PRINT_TO_LOGCAT) && msg) {
582         va_start(args, msg);
583         char tag[128];
584         (void)tag;
585         sprintf(tag, "pvr_drv_video ");
586         __android_log_vprint(ANDROID_LOG_DEBUG, tag, msg, args);
587         va_end(args);
588     }
589 #endif
590 
591     if (psb_video_trace_fp && (psb_video_trace_option & PRINT_TO_FILE)) {
592         if (msg) {
593             va_start(args, msg);
594             vfprintf(psb_video_trace_fp, msg, args);
595             va_end(args);
596         } else {
597             fflush(psb_video_trace_fp);
598             //fsync(fileno(psb_video_trace_fp));
599         }
600     }
601 }
602 
psb__debug_w(uint32_t val,char * fmt,uint32_t bit_to,uint32_t bit_from)603 void psb__debug_w(uint32_t val, char *fmt, uint32_t bit_to, uint32_t bit_from)
604 {
605     if (bit_to < 31) {
606         val &= ~(0xffffffff << (bit_to + 1));
607     }
608     val = val >> bit_from;
609     psb__trace_message(fmt, val);
610 }
611 
612 #define DBH(fmt, arg...)        psb__trace_message(fmt, ##arg)
613 #define DB(fmt, arg1, arg...)        psb__trace_message("[%08x] %08x = " fmt, ((unsigned char *) arg1) - cmd_start, *arg1, ##arg)
614 
615 /* See also MsvdxGpuSim() in msvdxgpu.c */
debug_dump_cmdbuf(uint32_t * cmd_idx,uint32_t cmd_size_in_bytes)616 void debug_dump_cmdbuf(uint32_t *cmd_idx, uint32_t cmd_size_in_bytes)
617 {
618     uint32_t cmd_size = cmd_size_in_bytes / sizeof(uint32_t);
619     uint32_t *cmd_end = cmd_idx + cmd_size;
620     unsigned char *cmd_start = (unsigned char *)cmd_idx;
621     struct {
622         unsigned int start;
623         unsigned int end;
624         char *name;
625     } msvdx_regs[11] = {{0x00000000, 0x000003FF, "MTX_MTX"},
626         {0x00000400, 0x0000047F, "VDMC_MTX"},
627         {0x00000480, 0x000004FF, "VDEB_MTX"},
628         {0x00000500, 0x000005FF, "DMAC_MTX"},
629         {0x00000600, 0x000006FF, "SYS_MTX"},
630         {0x00000700, 0x000007FF, "VEC_IQRAM_MTX"},
631         {0x00000800, 0x00000FFF, "VEC_MTX"},
632         {0x00001000, 0x00001FFF, "CMD_MTX"},
633         {0x00002000, 0x00002FFF, "VEC_RAM_MTX"},
634         {0x00003000, 0x00004FFF, "VEC_VLC_M"},
635         {0x00005000, 0xFFFFFFFF, "OUT_OF_RANGE"}
636     };
637 
638     DBH("CMD BUFFER [%08x] - [%08x], %08x bytes, %08x dwords\n", (uint32_t) cmd_idx, cmd_end, cmd_size_in_bytes, cmd_size);
639     while (cmd_idx < cmd_end) {
640         uint32_t cmd = *cmd_idx;
641         /* What about CMD_MAGIC_BEGIN ?*/
642 
643         switch (cmd & CMD_MASK) {
644         case CMD_NOP: {
645             DB("CMD_NOPE\n", cmd_idx);
646             cmd_idx++;
647             break;
648         }
649         case CMD_REGVALPAIR_WRITE: {
650             uint32_t count = (cmd & 0xfff0000) >> 16;
651             uint32_t reg = cmd & 0xffff;
652             DB("CMD_REGVALPAIR_WRITE count = 0x%08x\n", cmd_idx, count);
653             cmd_idx++;
654 
655             while (count--) {
656                 int i;
657                 for (i = 0; i < 10; i++) {
658                     if ((reg >= msvdx_regs[i].start) &&
659                         (reg <= msvdx_regs[i].end))
660                         break;
661                 }
662                 psb__trace_message("%s_%04x\n", msvdx_regs[i].name, reg);
663                 reg += 4;
664                 DB("value\n", cmd_idx);
665                 cmd_idx++;
666             }
667             break;
668         }
669         case CMD_RENDEC_WRITE: {
670             uint32_t encoding;
671             uint32_t count = (cmd & CMD_RENDEC_COUNT_MASK) >> CMD_RENDEC_COUNT_SHIFT;
672             DB("CMD_RENDEC_WRITE count = %08x\n", cmd_idx, count);
673             cmd_idx++;
674 
675             DB("RENDEC_SL_HDR\n", cmd_idx);
676             cmd_idx++;
677 
678             DB("RENDEC_SL_NULL\n", cmd_idx);
679             cmd_idx++;
680 
681             do {
682                 uint32_t chk_hdr = *cmd_idx;
683                 count = 1 + ((chk_hdr & 0x07FF0000) >> 16);
684                 uint32_t start_address = (chk_hdr & 0x0000FFF0) >> 4;
685                 encoding = (chk_hdr & 0x07);
686                 if ((count == 1) && (encoding == 7)) {
687                     count = 0;
688                     DB("SLICE_SEPARATOR\n", cmd_idx);
689                 } else {
690                     DB("RENDEC_CK_HDR #symbols = %d address = %08x encoding = %01x\n", cmd_idx, count, start_address, encoding);
691                 }
692                 cmd_idx++;
693 
694                 while (count && (count < 0x1000)) {
695                     DB("value\n", cmd_idx);
696                     cmd_idx++;
697 
698                     count -= 2;
699                 }
700             } while (encoding != 0x07);
701 
702             break;
703         }
704         case CMD_RENDEC_BLOCK: {
705             uint32_t count = (cmd & 0xff0000) >> 16;
706             uint32_t rendec = cmd & 0xffff;
707             DB("CMD_RENDEC_BLOCK count = 0x%08x\n", cmd_idx, count);
708             cmd_idx++;
709 
710             while (count--) {
711                 psb__trace_message("%04x\n", rendec);
712                 rendec += 4;
713                 DB("value\n", cmd_idx);
714                 cmd_idx++;
715             }
716             break;
717         }
718 
719         case CMD_COMPLETION: {
720             if (*cmd_idx == PSB_RELOC_MAGIC) {
721                 DB("CMD_(S)LLDMA (assumed)\n", cmd_idx);
722                 cmd_idx++;
723 
724             } else {
725                 DB("CMD_COMPLETION\n", cmd_idx);
726                 cmd_idx++;
727 
728 //              DB("interrupt\n", cmd_idx);
729 //              cmd_idx++;
730             }
731             break;
732         }
733         case CMD_HEADER: {
734             uint32_t context = cmd & CMD_HEADER_CONTEXT_MASK;
735             DB("CMD_HEADER context = %08x\n", cmd_idx, context);
736             cmd_idx++;
737             DB("StatusBufferAddress\n", cmd_idx);
738             cmd_idx++;
739             DB("PreloadSave\n", cmd_idx);
740             cmd_idx++;
741             DB("PreloadRestore\n", cmd_idx);
742             cmd_idx++;
743             break;
744         }
745         case CMD_CONDITIONAL_SKIP: {
746             DB("CMD_CONDITIONAL_SKIP\n", cmd_idx);
747             cmd_idx++;
748             DB("vlc table address\n", cmd_idx);
749             break;
750         }
751         case CMD_CTRL_ALLOC_HEADER: {
752             psb__trace_message("CMD_CTRL_ALLOC_HEADER count = 0x%08x\n", sizeof(CTRL_ALLOC_HEADER));
753             uint32_t count = sizeof(CTRL_ALLOC_HEADER)/4;
754             while (count) {
755                     DB("value\n", cmd_idx);
756                     cmd_idx++;
757                     count--;
758             }
759             break;
760         }
761         case CMD_LLDMA: {
762             DB("CMD_LLDMA\n", cmd_idx);
763             cmd_idx++;
764             break;
765         }
766         case CMD_SR_SETUP: {
767             DB("CMD_SR_SETUP\n", cmd_idx);
768             cmd_idx++;
769             DB("offset in bits\n", cmd_idx);
770             cmd_idx++;
771             DB("size in bytes\n", cmd_idx);
772             cmd_idx++;
773             break;
774         }
775         case CMD_SLLDMA: {
776             DB("CMD_SLLDMA\n", cmd_idx);
777             cmd_idx++;
778             break;
779         }
780         case CMD_DMA: {
781             DB("CMD_DMA\n", cmd_idx);
782             cmd_idx++;
783             DB("cmd dma address\n", cmd_idx);
784             break;
785         }
786         default:
787             if (*cmd_idx == PSB_RELOC_MAGIC) {
788                 DB("CMD_(S)LLDMA (assumed)\n", cmd_idx);
789                 cmd_idx++;
790 
791             } else {
792                 DB("*** Unknown command ***\n", cmd_idx);
793                 cmd_idx++;
794             }
795             break;
796         } /* switch */
797     } /* while */
798 }
799 
800 /********************* trace debug end *************************/
801 
802 /********************* dump buffer when flush cmdbuf - start *************************/
psb__debug_schedule_hexdump(const char * name,psb_buffer_p buf,uint32_t offset,uint32_t size)803 void psb__debug_schedule_hexdump(const char *name, psb_buffer_p buf, uint32_t offset, uint32_t size)
804 {
805     ASSERT(debug_dump_count < MAX_DUMP_COUNT);
806     debug_dump_name[debug_dump_count] = name;
807     debug_dump_buf[debug_dump_count] = buf;
808     debug_dump_offset[debug_dump_count] = offset;
809     debug_dump_size[debug_dump_count] = size;
810     debug_dump_count++;
811 }
812 
psb__hexdump2(unsigned char * p,int offset,int size)813 static void psb__hexdump2(unsigned char *p, int offset, int size)
814 {
815     if (offset + size > 8)
816         size = 8 - offset;
817     psb__trace_message("[%04x]", g_hexdump_offset);
818     g_hexdump_offset += offset;
819     g_hexdump_offset += size;
820     while (offset-- > 0) {
821         psb__trace_message(" --");
822     }
823     while (size-- > 0) {
824         psb__trace_message(" %02x", *p++);
825     }
826     psb__trace_message("\n");
827 }
828 
psb__hexdump(unsigned char * addr,int size)829 void psb__hexdump(unsigned char *addr, int size)
830 {
831     unsigned char *p = (unsigned char *) addr;
832 
833     int offset = g_hexdump_offset % 8;
834     g_hexdump_offset -= offset;
835     if (offset) {
836         psb__hexdump2(p, offset, size);
837         size -= 8 - offset;
838         p += 8 - offset;
839     }
840 
841     while (1) {
842         if (size < 8) {
843             if (size > 0) {
844                 psb__hexdump2(p, 0, size);
845             }
846             return;
847         }
848         psb__trace_message("[%04x] %02x %02x %02x %02x %02x %02x %02x %02x\n", g_hexdump_offset, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
849         p += 8;
850         size -= 8;
851         g_hexdump_offset += 8;
852     }
853 }
854 /********************* dump buffer when flush cmdbuf - end*************************/
855 
psb__dump_va_buffers(object_buffer_p obj_buffer)856 int  psb__dump_va_buffers(object_buffer_p obj_buffer)
857 {
858     unsigned int j,k;
859     unsigned char *mapped_buffer;
860     int print_num;
861 
862     if(psb_dump_vabuf_fp) {
863         fprintf(psb_dump_vabuf_fp, "%s", buffer_type_to_string(obj_buffer->type));
864         print_num = fprintf(psb_dump_vabuf_fp, "BUFF SIZE :%d	NUMELEMENTS:%d BUFF INFO:\n", obj_buffer->size, obj_buffer->num_elements);
865 
866         switch(obj_buffer->type) {
867             case VAPictureParameterBufferType:
868             case VAIQMatrixBufferType:
869             case VASliceParameterBufferType:
870                 j=0;
871                 for(k=0;k < obj_buffer->size;++k)
872                     print_num = fprintf(psb_dump_vabuf_fp,"0x%02x ,",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
873                     fprintf(psb_dump_vabuf_fp,"\n ");
874                 break;
875 
876             case VASliceGroupMapBufferType:
877             case VABitPlaneBufferType:
878                 psb_buffer_map(obj_buffer->psb_buffer, (unsigned char **)&mapped_buffer);
879                 if(mapped_buffer == NULL)
880                     return VA_STATUS_ERROR_INVALID_BUFFER;
881 
882                 for(j=0; j<obj_buffer->size;++j) {
883                     if(j%16 == 0) fprintf(psb_dump_vabuf_fp,"\n");
884                     for(k=0;k < obj_buffer->num_elements;++k)
885                         fprintf(psb_dump_vabuf_fp,"0x%02x   ",*((unsigned char *)(mapped_buffer+obj_buffer->num_elements*j+k)));
886                 }
887 
888                 psb_buffer_unmap(obj_buffer->psb_buffer);
889                 break;
890 
891             case VASliceDataBufferType:
892             case VAProtectedSliceDataBufferType:
893                 fprintf(psb_dump_vabuf_fp,"first 256 bytes:\n");
894                 psb_buffer_map(obj_buffer->psb_buffer, (unsigned char **)&mapped_buffer);
895                 if (!mapped_buffer)
896                     break;
897                 for(j=0; j<256;++j) {
898                     if(j%16 == 0) fprintf(psb_dump_vabuf_fp,"\n");
899                     for(k=0;k < obj_buffer->num_elements;++k)
900                         fprintf(psb_dump_vabuf_fp,"0x%02x   ",*((unsigned char *)(mapped_buffer+obj_buffer->num_elements*j+k)));
901                 }
902                 psb_buffer_unmap(obj_buffer->psb_buffer);
903                 break;
904 
905             default:
906                 break;
907 
908         }
909         fprintf(psb_dump_vabuf_fp, "\n");
910         fflush(psb_dump_vabuf_fp);
911         fsync(fileno(psb_dump_vabuf_fp));
912     }
913 
914     return 0;
915 }
916 
psb__dump_va_buffers_verbose(object_buffer_p obj_buffer)917 int  psb__dump_va_buffers_verbose(object_buffer_p obj_buffer)
918 {
919     unsigned int j,k;
920     unsigned char *mapped_buffer;
921     if(psb_dump_vabuf_verbose_fp) {
922         fprintf(psb_dump_vabuf_verbose_fp, "%s", buffer_type_to_string(obj_buffer->type));
923         fprintf(psb_dump_vabuf_verbose_fp, "BUFF SIZE :%d	NUMELEMENTS:%d BUFF INFO:\n", obj_buffer->size, obj_buffer->num_elements);
924         switch(obj_buffer->type) {
925             case VAPictureParameterBufferType:
926                 for(j=0; j < 340; j = j+20) {
927                     if(j==0) fprintf(psb_dump_vabuf_verbose_fp,"\nCurrPic:\n");
928                     else fprintf(psb_dump_vabuf_verbose_fp,"\nReferenceFrames%d\n", j / 20);
929                     fprintf(psb_dump_vabuf_verbose_fp,"picture_id:");
930                     for(k=0;k < 4;++k)
931                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
932                         fprintf(psb_dump_vabuf_verbose_fp,"    frame_idx:");
933                     for(k=4;k < 8;++k)
934                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
935                         fprintf(psb_dump_vabuf_verbose_fp,"    flags:");
936                     for(k=8;k < 12;++k)
937                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
938                         fprintf(psb_dump_vabuf_verbose_fp,"    TopFieldOrderCnt:");
939                     for(k=12;k < 16;++k)
940                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
941                         fprintf(psb_dump_vabuf_verbose_fp,"    BottomFieldOrderCnt:");
942                     for(k=16;k < 20;++k)
943                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
944                 }
945                 j=340;k=0;
946                 fprintf(psb_dump_vabuf_verbose_fp,"\npicture_width_in_mbs_minus1:");
947                 for(k=0;k < 2;++k)
948                     fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
949                 j=342;k=0;
950                 fprintf(psb_dump_vabuf_verbose_fp, "\npicture_height_in_mbs_minus1:");
951                 for(k=0;k < 2;++k)
952                     fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
953                 j=344;k=0;
954                 fprintf(psb_dump_vabuf_verbose_fp,  "\nbit_depth_luma_minus8:");
955                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
956                 j=345;k=0;
957                 fprintf(psb_dump_vabuf_verbose_fp, "\nbit_depth_chroma_minus8:");
958                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
959                 j=346;k=0;
960                 fprintf(psb_dump_vabuf_verbose_fp, "\nnum_ref_frames:");
961                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
962                 j=348;k=0;
963                 fprintf(psb_dump_vabuf_verbose_fp,"\nseq_fields_value:");
964                 for(k=0;k < 4;++k)
965                     fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
966                 j=352;k=0;
967                 fprintf(psb_dump_vabuf_verbose_fp,"\nnum_slice_groups_minus1:");
968                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
969                 j=353;k=0;
970                 fprintf(psb_dump_vabuf_verbose_fp,"\nslice_group_map_type:");
971                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
972                 j=354;k=0;
973                 fprintf(psb_dump_vabuf_verbose_fp, "\nslice_group_change_rate_minus1:");
974                 for(k=0;k < 2;++k)
975                     fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
976                 j=356;k=0;
977                 fprintf(psb_dump_vabuf_verbose_fp,"\npic_init_qp_minus26:");
978                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
979                 j=357;k=0;
980                 fprintf(psb_dump_vabuf_verbose_fp,"\npic_init_qs_minus26:");
981                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
982                 j=358;k=0;
983                 fprintf(psb_dump_vabuf_verbose_fp,"\nchroma_qp_index_offset:");
984                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
985                 j=359;k=0;
986                 fprintf(psb_dump_vabuf_verbose_fp, "\nsecond_chroma_qp_index_offset:");
987                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
988                 j=360;k=0;
989                 fprintf(psb_dump_vabuf_verbose_fp,"\npic_fields_value:");
990                 for(k=0;k < 4;++k)
991                     fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
992                 j=364;k=0;
993                 fprintf(psb_dump_vabuf_verbose_fp,"\nframe_num:");
994                 for(k=0;k < 2;++k)
995                     fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
996                 break;
997 
998             case VAIQMatrixBufferType:
999                 for(j=0;j<96;j=j+16) {
1000                     fprintf(psb_dump_vabuf_verbose_fp,"\nScalingList4x4_%d:", j/16);
1001                     for(k=0; k<16;++k) {
1002                         if(k%4 == 0) fprintf(psb_dump_vabuf_verbose_fp, "\n");
1003                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x   ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1004                     }
1005                 }
1006                 for(j=96;j<224;j=j+64) {
1007                     fprintf(psb_dump_vabuf_verbose_fp,"\nScalingList4x4_%d:",( j-96)/64);
1008                     for(k=0; k<64;++k) {
1009                         if(k%8 == 0) fprintf(psb_dump_vabuf_verbose_fp, "\n");
1010                         fprintf(psb_dump_vabuf_verbose_fp, "0x%02x   ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1011                     }
1012                 }
1013                 break;
1014 
1015             case VASliceParameterBufferType:
1016                 j=0;k=0;
1017                 fprintf(psb_dump_vabuf_verbose_fp,"\nslice_data_size:");
1018                 for(k=0;k < 4;++k)
1019                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1020                 j=4;k=0;
1021                 fprintf(psb_dump_vabuf_verbose_fp,"\nslice_data_offset:");
1022                 for(k=0;k < 4;++k)
1023                     fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1024                 j=8;k=0;
1025                 fprintf(psb_dump_vabuf_verbose_fp,"\nslice_data_flag:");
1026                 for(k=0;k < 4;++k)
1027                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1028                 j=12;k=0;
1029                 fprintf(psb_dump_vabuf_verbose_fp,"\nslice_data_bit_offset:");
1030                 for(k=0;k < 2;++k)
1031                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1032                 j=14;k=0;
1033                 fprintf(psb_dump_vabuf_verbose_fp,"\nfirst_mb_in_slice:");
1034                 for(k=0;k < 2;++k)
1035                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1036                 j=16;k=0;
1037                 fprintf(psb_dump_vabuf_verbose_fp,"\nslice_type:");
1038                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1039                 j=17;k=0;
1040                 fprintf(psb_dump_vabuf_verbose_fp,"\ndirect_spatial_mv_pred_flag:");
1041                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1042                 j=18;k=0;
1043                 fprintf(psb_dump_vabuf_verbose_fp,  "\nnum_ref_idx_l0_active_minus1:");
1044                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1045                 j=19;k=0;
1046                 fprintf(psb_dump_vabuf_verbose_fp, "\nnum_ref_idx_l1_active_minus1:");
1047                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1048                 j=20;k=0;
1049                 fprintf(psb_dump_vabuf_verbose_fp,"\ncabac_init_idc:");
1050                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1051                 j=21;k=0;
1052                 fprintf(psb_dump_vabuf_verbose_fp,"\nslice_qp_delta:");
1053                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1054                 j=22;k=0;
1055                 fprintf(psb_dump_vabuf_verbose_fp, "\ndisable_deblocking_filter_idc:");
1056                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1057                 j=23;k=0;
1058                 fprintf(psb_dump_vabuf_verbose_fp,"\nslice_alpha_c0_offset_div2:");
1059                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1060                 j=24;k=0;
1061                 fprintf(psb_dump_vabuf_verbose_fp,"\nslice_beta_offset_div2:");
1062                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1063                 for(j=28; j < 668; j = j+20) {
1064                     fprintf(psb_dump_vabuf_verbose_fp,"\nRefPicList0 ListIndex=%d\n", (j -28)/ 20);
1065                     fprintf(psb_dump_vabuf_verbose_fp,"picture_id:");
1066                     for(k=0;k < 4;++k)
1067                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1068                         fprintf(psb_dump_vabuf_verbose_fp,"   frame_idx:");
1069                     for(k=4;k < 8;++k)
1070                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1071                         fprintf(psb_dump_vabuf_verbose_fp,"   flags:");
1072                     for(k=8;k < 12;++k)
1073                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1074                         fprintf(psb_dump_vabuf_verbose_fp,"   TopFieldOrderCnt:");
1075                     for(k=12;k < 16;++k)
1076                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1077                         fprintf(psb_dump_vabuf_verbose_fp,"   BottomFieldOrderCnt:");
1078                     for(k=16;k < 20;++k)
1079                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1080                     }
1081                 for(j=668; j < 1308; j = j+20) {
1082                     fprintf(psb_dump_vabuf_verbose_fp,"\nRefPicList1 ListIndex=%d\n", (j -668)/ 20);
1083                     fprintf(psb_dump_vabuf_verbose_fp,"picture_id:");
1084                     for(k=0;k < 4;++k)
1085                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1086                         fprintf(psb_dump_vabuf_verbose_fp,"   frame_idx:");
1087                     for(k=4;k < 8;++k)
1088                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1089                         fprintf(psb_dump_vabuf_verbose_fp,"   flags:");
1090                     for(k=8;k < 12;++k)
1091                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1092                         fprintf(psb_dump_vabuf_verbose_fp,"   TopFieldOrderCnt:");
1093                     for(k=12;k < 16;++k)
1094                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1095                         fprintf(psb_dump_vabuf_verbose_fp,"   BottomFieldOrderCnt:");
1096                     for(k=16;k < 20;++k)
1097                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1098                     }
1099                 j=1308;k=0;
1100                 fprintf(psb_dump_vabuf_verbose_fp,"\nluma_log2_weight_denom:");
1101                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1102 j=1309;k=0;
1103                 fprintf(psb_dump_vabuf_verbose_fp,"\nchroma_log2_weight_denom:");
1104                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1105                 j=1310;k=0;
1106                 fprintf(psb_dump_vabuf_verbose_fp,"\nluma_weight_l0_flag:");
1107                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1108                 j=1312;k=0;
1109                 fprintf(psb_dump_vabuf_verbose_fp,"\nluma_weight_l0:");
1110                 for(j=1312;j<1376;j=j+2) {
1111                     if((j-1312)%16 == 0)fprintf(psb_dump_vabuf_verbose_fp,"\n");
1112                     fprintf(psb_dump_vabuf_verbose_fp,"     :");
1113                     for(k=0;k < 2;++k)
1114                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1115                 }
1116                 fprintf(psb_dump_vabuf_verbose_fp,"\nluma_offset_l0:");
1117                 for(j=1376;j<1440;j=j+2) {
1118                     if((j-1376)%16 == 0) fprintf(psb_dump_vabuf_verbose_fp,"\n");
1119                     fprintf(psb_dump_vabuf_verbose_fp,"     ");
1120                     for(k=0;k < 2;++k)
1121                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1122                 }
1123                 j=1440;k=0;
1124                 fprintf(psb_dump_vabuf_verbose_fp,"\nchroma_weight_l0_flag:");
1125                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1126                 j=1442;k=0;
1127                 fprintf(psb_dump_vabuf_verbose_fp,"\nchroma_weight_l0:");
1128                 for(j=1442;j<1570;j=j+4) {
1129                     if((j-1442)%16 == 0) fprintf(psb_dump_vabuf_verbose_fp,"\n");
1130                     fprintf(psb_dump_vabuf_verbose_fp,"     ");
1131                     for(k=0;k < 2;++k)
1132                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1133                         fprintf(psb_dump_vabuf_verbose_fp," , ");
1134                     for(k=2;k < 4;++k)
1135                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1136 
1137                 }
1138 
1139                 fprintf(psb_dump_vabuf_verbose_fp,"\nchroma_offset_l0:");
1140                 for(j=1570;j<1698;j=j+4) {
1141                     if((j-1570)%16 == 0) fprintf(psb_dump_vabuf_verbose_fp,"\n");
1142                     fprintf(psb_dump_vabuf_verbose_fp,"     ");
1143                     for(k=0;k < 2;++k)
1144                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1145                         fprintf(psb_dump_vabuf_verbose_fp," , ");
1146                     for(k=2;k < 4;++k)
1147                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1148                 }
1149                 j=1698;k=0;
1150                 fprintf(psb_dump_vabuf_verbose_fp,"\nluma_weight_l1_flag:");
1151                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1152                 fprintf(psb_dump_vabuf_verbose_fp,"\nluma_weight_l1:");
1153                 for(j=1700;j<1764;j=j+2) {
1154                     if((j-1700)%16 == 0) fprintf(psb_dump_vabuf_verbose_fp,"\n");
1155                     fprintf(psb_dump_vabuf_verbose_fp,"     ");
1156                     for(k=0;k < 2;++k)
1157                     fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1158                 }
1159                 fprintf(psb_dump_vabuf_verbose_fp,"\nluma_offset_l1:");
1160                 for(j=1764;j<1828;j=j+2) {
1161                     if((j-1764)%16 == 0) fprintf(psb_dump_vabuf_verbose_fp,"\n");
1162                     fprintf(psb_dump_vabuf_verbose_fp,"     ");
1163                     for(k=0;k < 2;++k)
1164                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1165                 }
1166                 j=1828;k=0;
1167                 fprintf(psb_dump_vabuf_verbose_fp,"\nchroma_weight_l1_flag:");
1168                 fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1169                 fprintf(psb_dump_vabuf_verbose_fp,"\nchroma_weight_l1:");
1170                 for(j=1830;j<1958;j=j+4) {
1171                     if((j-1830)%16 == 0) fprintf(psb_dump_vabuf_verbose_fp,"\n");
1172                     fprintf(psb_dump_vabuf_verbose_fp,"     ");
1173                     for(k=0;k < 2;++k)
1174                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1175                         fprintf(psb_dump_vabuf_verbose_fp," , ");
1176                     for(k=2;k < 4;++k)
1177                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1178                 }
1179                 fprintf(psb_dump_vabuf_verbose_fp,"\nchroma_offset_l1:");
1180                 for(j=1958;j<2086;j=j+4) {
1181                     if((j-1958)%16 == 0) fprintf(psb_dump_vabuf_verbose_fp,"\n");
1182                     fprintf(psb_dump_vabuf_verbose_fp,"     ");
1183                     for(k=0;k < 2;++k)
1184                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1185                         fprintf(psb_dump_vabuf_verbose_fp," , ");
1186                     for(k=2;k < 4;++k)
1187                     fprintf(psb_dump_vabuf_verbose_fp,"0x%02x ",*((unsigned char *)(obj_buffer->buffer_data+obj_buffer->num_elements*j+k)));
1188                 }
1189                 break;
1190 
1191             case VASliceGroupMapBufferType:
1192                 psb_buffer_map(obj_buffer->psb_buffer, (unsigned char **)&mapped_buffer);
1193                 if(mapped_buffer == NULL)
1194                     return VA_STATUS_ERROR_INVALID_BUFFER;
1195 
1196                 for(j=0; j<obj_buffer->size;++j) {
1197                     if(j%16 == 0) fprintf(psb_dump_vabuf_verbose_fp,"\n");
1198                     for(k=0;k < obj_buffer->num_elements;++k)
1199                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x   ",*((unsigned char *)(mapped_buffer+obj_buffer->num_elements*j+k)));
1200                 }
1201                 psb_buffer_unmap(obj_buffer->psb_buffer);
1202                 break;
1203 
1204             case VASliceDataBufferType:
1205             case VAProtectedSliceDataBufferType:
1206                 fprintf(psb_dump_vabuf_verbose_fp,"first 256 bytes:\n");
1207                 psb_buffer_map(obj_buffer->psb_buffer,(unsigned char **)&mapped_buffer);
1208                 if(mapped_buffer == NULL)
1209                     return VA_STATUS_ERROR_INVALID_BUFFER;
1210                 for(j=0; j<256;++j) {
1211                     if(j%16 == 0) fprintf(psb_dump_vabuf_verbose_fp,"\n");
1212                     for(k=0;k < obj_buffer->num_elements;++k)
1213                         fprintf(psb_dump_vabuf_verbose_fp,"0x%02x   ",*((unsigned char *)(mapped_buffer+obj_buffer->num_elements*j+k)));
1214                 }
1215                 psb_buffer_unmap(obj_buffer->psb_buffer);
1216                 break;
1217             default:
1218                 break;
1219 
1220             }
1221         fprintf(psb_dump_vabuf_verbose_fp, "\n");
1222         fflush(psb_dump_vabuf_verbose_fp);
1223         fsync(fileno(psb_dump_vabuf_verbose_fp));
1224     }
1225     return 0;
1226 }
1227 
1228