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