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  *    Waldo Bastian <waldo.bastian (at) intel.com>
     27  *    Zeng Li <zeng.li (at) intel.com>
     28  *    Lin Edward <edward.lin (at) intel.com>
     29  *
     30  */
     31 
     32 #ifndef _TNG_CMDBUF_H_
     33 #define _TNG_CMDBUF_H_
     34 
     35 #include "psb_drv_video.h"
     36 #include "psb_surface.h"
     37 #include "psb_buffer.h"
     38 
     39 #include <stdint.h>
     40 
     41 //#ifndef MTX_CMDWORD_ID_MASK
     42 #define MTX_CMDWORD_ID_MASK     (0x7f)
     43 #define MTX_CMDWORD_ID_SHIFT    (0)
     44 #define MTX_CMDWORD_CORE_MASK   (0xff)
     45 #define MTX_CMDWORD_CORE_SHIFT  (8)
     46 #define MTX_CMDWORD_COUNT_MASK  (0x7fff)
     47 #define MTX_CMDWORD_COUNT_SHIFT (16)
     48 #define MTX_CMDWORD_INT_SHIFT   (7)
     49 #define MTX_CMDWORD_INT_MASK    (1)
     50 //#endif
     51 
     52 #define TNG_CMDBUF_SEQ_HEADER_IDX       (0)
     53 #define TNG_CMDBUF_PIC_HEADER_IDX       (1)
     54 #define TNG_CMDBUF_MVC_SEQ_HEADER_IDX (2)
     55 
     56 /* @{ */
     57 #define SHIFT_MTX_CMDWORD_ID    (0)
     58 #define MASK_MTX_CMDWORD_ID     (0xff << SHIFT_MTX_CMDWORD_ID)
     59 #define SHIFT_MTX_CMDWORD_CORE  (8)
     60 #define MASK_MTX_CMDWORD_CORE   (0xff << SHIFT_MTX_CMDWORD_CORE)
     61 #define SHIFT_MTX_CMDWORD_COUNT (16)
     62 #define MASK_MTX_CMDWORD_COUNT  (0xffff << SHIFT_MTX_CMDWORD_COUNT)
     63 /* @} */
     64 
     65 #define SHIFT_MTX_WBWORD_ID    (0)
     66 #define MASK_MTX_WBWORD_ID     (0xff << SHIFT_MTX_WBWORD_ID)
     67 #define SHIFT_MTX_WBWORD_CORE  (8)
     68 #define MASK_MTX_WBWORD_CORE   (0xff << SHIFT_MTX_WBWORD_CORE)
     69 
     70 #define tng_align_KB(x)  (((x) + (IMG_UINT32)(0xfff)) & (~(IMG_UINT32)(0xfff)))
     71 
     72 struct tng_cmdbuf_s {
     73     struct psb_buffer_s buf;
     74     unsigned int size;
     75 
     76     /* Relocation records */
     77     unsigned char *reloc_base;
     78     struct drm_psb_reloc *reloc_idx;
     79 
     80     /* CMD stream data */
     81     int cmd_count;
     82     unsigned char *cmd_base;
     83     unsigned char *cmd_start;
     84     IMG_UINT32 *cmd_idx;
     85     IMG_UINT32 *cmd_idx_saved[3]; /* idx saved for dual-core adjustion */
     86 
     87     unsigned int mem_size;
     88 
     89     /* JPEG quantization tables buffer*/
     90     struct psb_buffer_s jpeg_pic_params;
     91     void *jpeg_pic_params_p;
     92 
     93     /* JPEG MTX setup buffer */
     94     struct psb_buffer_s jpeg_header_mem;
     95     void *jpeg_header_mem_p;
     96 
     97     /* JPEG MTX setup interface buffer */
     98     struct psb_buffer_s jpeg_header_interface_mem;
     99     void *jpeg_header_interface_mem_p;
    100 
    101 
    102     /*buffer information g_apsCmdDataInfo */
    103     struct psb_buffer_s frame_mem;
    104     unsigned char *frame_mem_p;
    105     unsigned int frame_mem_index;
    106 
    107     /*picuture management g_apsCmdDataInfo */
    108     void *writeback_mem_p;
    109 
    110     /*buffer information g_apsCmdDataInfo
    111     struct psb_buffer_s coded_mem;
    112     void *coded_mem_p;
    113     */
    114 
    115     /* all frames share one topaz param buffer which contains InParamBase
    116      * AboveParam/BellowParam, and the buffer allocated when the context is created
    117      */
    118     struct psb_buffer_s *topaz_in_params_I;
    119     void *topaz_in_params_I_p;
    120 
    121     struct psb_buffer_s *topaz_in_params_P;
    122     void *topaz_in_params_P_p;
    123 
    124     struct psb_buffer_s *topaz_below_params;
    125     void *topaz_below_params_p;
    126 
    127     /* Every frame has its own PIC_PARAMS, SLICE_PARAMS and HEADER mem
    128      */
    129 
    130 /*
    131     PicParams:
    132     struct psb_buffer_s pic_params;
    133     void *pic_params_p;
    134 */
    135 
    136     /* Referenced buffers */
    137     psb_buffer_p *buffer_refs;
    138     int buffer_refs_count;
    139     int buffer_refs_allocated;
    140 };
    141 
    142 typedef struct tng_cmdbuf_s *tng_cmdbuf_p;
    143 
    144 /*
    145  * Create command buffer
    146  */
    147 VAStatus tng_cmdbuf_create(object_context_p obj_context,
    148                            psb_driver_data_p driver_data,
    149                            tng_cmdbuf_p cmdbuf
    150                           );
    151 
    152 /*
    153  * Destroy buffer
    154  */
    155 void tng_cmdbuf_destroy(tng_cmdbuf_p cmdbuf);
    156 
    157 /*
    158  * Reset buffer & map
    159  *
    160  * Returns 0 on success
    161  */
    162 int tng_cmdbuf_reset(tng_cmdbuf_p cmdbuf);
    163 
    164 /*
    165  * Unmap buffer
    166  *
    167  * Returns 0 on success
    168  */
    169 int tng_cmdbuf_unmap(tng_cmdbuf_p cmdbuf);
    170 
    171 /*
    172  * Reference an addtional buffer "buf" in the command stream
    173  * Returns a reference index that can be used to refer to "buf" in
    174  * relocation records, on error -1 is returned.
    175  */
    176 int tng_cmdbuf_buffer_ref(tng_cmdbuf_p cmdbuf, psb_buffer_p buf);
    177 
    178 /* Creates a relocation record for a DWORD in the mapped "cmdbuf" at address
    179  * "addr_in_cmdbuf"
    180  * The relocation is based on the device virtual address of "ref_buffer"
    181  * "buf_offset" is be added to the device virtual address, and the sum is then
    182  * right shifted with "align_shift".
    183  * "mask" determines which bits of the target DWORD will be updated with the so
    184  * constructed address. The remaining bits will be filled with bits from "background".
    185  */
    186 void tng_cmdbuf_add_relocation(tng_cmdbuf_p cmdbuf,
    187                                IMG_UINT32 *addr_in_dst_buffer,/*addr of dst_buffer for the DWORD*/
    188                                psb_buffer_p ref_buffer,
    189                                IMG_UINT32 buf_offset,
    190                                IMG_UINT32 mask,
    191                                IMG_UINT32 background,
    192                                IMG_UINT32 align_shift,
    193                                IMG_UINT32 dst_buffer, /*Index of the list refered by cmdbuf->buffer_refs */
    194                                IMG_UINT32 *start_of_dst_buffer);
    195 
    196 #define TNG_RELOC_CMDBUF_START(dest, offset, buf)    tng_cmdbuf_add_relocation(cmdbuf, (IMG_UINT32*)(dest), buf, offset, 0XFFFFFFFF, 0, 0, 0, (IMG_UINT32 *)(cmdbuf->cmd_start))
    197 /* do relocation in IMG_BUFFER_PARAMS: reference Y/UV base,CodedData */
    198 #define TNG_RELOC_CMDBUF_FRAMES(dest, offset, buf)   tng_cmdbuf_add_relocation(cmdbuf, (IMG_UINT32*)(dest), buf, offset, 0XFFFFFFFF, 0, 0, 3,(IMG_UINT32 *)(cmdbuf->frame_mem_p))
    199 
    200 /* do relocation in PIC_PARAMS: src/dst Y/UV base, InParamsBase, CodeBase, BellowParamsBase, AboveParamsBase
    201 #define RELOC_PIC_PARAMS_PTG(dest, offset, buf) tng_cmdbuf_add_relocation(cmdbuf, (IMG_UINT32*)(dest), buf, offset, 0XFFFFFFFF, 0, 0, 1, (uint32_t *)cmdbuf->pic_params_p)
    202 */
    203 
    204 /* do relocation in MTX_ENC_PARAMS */
    205 #define RELOC_MTXCTX_PARAMS_PTG(dest, offset, buf)       tng_cmdbuf_add_relocation(cmdbuf, (IMG_UINT32*)(dest), buf, offset, 0XFFFFFFFF, 0, 0, 3,(uint32_t *)cmdbuf->mtx_ctx_mem_p)
    206 
    207 /* do relocation in SLICE_PARAMS: reference Y/UV base,CodedData */
    208 //#define RELOC_SLICE_PARAMS_PTG(dest, offset, buf)       tng_cmdbuf_add_relocation(cmdbuf, (IMG_UINT32*)(dest), buf, offset, 0XFFFFFFFF, 0, 0, 2,(uint32_t *)cmdbuf->slice_mem_p)
    209 
    210 
    211 /* do relocation in IMG_BUFFER_PARAMS: reference Y/UV base,CodedData */
    212 #define RELOC_PICMGMT_PARAMS_PTG(dest, offset, buf)       tng_cmdbuf_add_relocation(cmdbuf, (IMG_UINT32*)(dest), buf, offset, 0XFFFFFFFF, 0, 0, 3,(uint32_t *)cmdbuf->picmgmt_mem_p)
    213 
    214 /* do relocation in PIC_PARAMS: src/dst Y/UV base, InParamsBase, CodeBase, BellowParamsBase, AboveParamsBase */
    215 #define RELOC_JPEG_PIC_PARAMS_PTG(dest, offset, buf) tng_cmdbuf_add_relocation(cmdbuf, (IMG_UINT32*)(dest), buf, offset, 0XFFFFFFFF, 0, 0, 1, (IMG_UINT32 *)cmdbuf->jpeg_pic_params_p)
    216 
    217 /* do relocation in IMG_BUFFER_PARAMS: reference Y/UV base,CodedData
    218 #define RELOC_CODED_PARAMS_PTG(dest, offset, buf)       tng_cmdbuf_add_relocation(cmdbuf, (IMG_UINT32*)(dest), buf, offset, 0XFFFFFFFF, 0, 0, 3,(uint32_t *)cmdbuf->coded_mem_p)
    219 */
    220 
    221 /* operation number is inserted by DRM */
    222 /*
    223 #define tng_cmdbuf_insert_command(cmdbuf,cmdhdr,size,hint)              \
    224     do { *cmdbuf->cmd_idx++ = ((cmdhdr) << 1) | ((size)<<8) | ((hint)<<16); } while(0)
    225 */
    226 
    227 #define tng_cmdbuf_insert_command_param(param)   \
    228     do { *cmdbuf->cmd_idx++ = param; } while(0)
    229 
    230 
    231 #define tng_cmdbuf_insert_reg_write(topaz_reg, base, offset, value)        \
    232     do { *cmdbuf->cmd_idx++ = topaz_reg; *cmdbuf->cmd_idx++ = base + offset; *cmdbuf->cmd_idx++ = value; count++; } while(0)
    233 
    234 void tng_cmdbuf_insert_command(
    235     object_context_p obj_context, IMG_UINT32 core,
    236     IMG_UINT32 cmd_id, IMG_UINT32 cmd_data,
    237     psb_buffer_p data_addr, IMG_UINT32 offset);
    238 
    239 /*
    240  * Advances "obj_context" to the next cmdbuf
    241  * Returns 0 on success
    242  */
    243 int tng_context_get_next_cmdbuf(object_context_p obj_context);
    244 
    245 /*
    246  * Submits the current cmdbuf
    247  * Returns 0 on success
    248  */
    249 int tng_context_submit_cmdbuf(object_context_p obj_context);
    250 
    251 /*
    252  * Get a encode surface FRAMESKIP flag, and store it into frame_skip argument
    253  * Returns 0 on success
    254  */
    255 int tng_surface_get_frameskip(psb_driver_data_p driver_data, psb_surface_p psb_surface, int *frame_skip);
    256 
    257 /*
    258  * Flushes the pending cmdbuf
    259  * Return 0 on success
    260  */
    261 int tng_context_flush_cmdbuf(object_context_p obj_context);
    262 
    263 void tng_cmdbuf_mem_unmap(tng_cmdbuf_p cmdbuf);
    264 
    265 void tng_cmdbuf_set_phys(IMG_UINT32 *dest_buf, int dest_num, psb_buffer_p ref_buf, unsigned int ref_ofs, unsigned int ref_len);
    266 int tng_get_pipe_number(object_context_p obj_context);
    267 VAStatus tng_set_frame_skip_flag(object_context_p obj_context);
    268 
    269 #endif /* _TNG_CMDBUF_H_ */
    270 
    271