intel_xvmc_private.h revision 03b705cf
1/* 2 * Copyright © 2007 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 * 23 * Authors: 24 * Zhenyu Wang <zhenyu.z.wang@intel.com> 25 * 26 */ 27#ifndef INTEL_XVMC_H 28#define INTEL_XVMC_H 29 30#include <pthread.h> 31#include <stdio.h> 32#include <stdlib.h> 33#include <unistd.h> 34#include <errno.h> 35#include <signal.h> 36#include <fcntl.h> 37#include <dirent.h> 38#include <string.h> 39#include <assert.h> 40#include <signal.h> 41#include <stdint.h> 42 43#include <xf86drm.h> 44#include <X11/X.h> 45#include <X11/Xlibint.h> 46#include <X11/Xutil.h> 47#include <fourcc.h> 48#include <X11/extensions/Xv.h> 49#include <X11/extensions/Xvlib.h> 50#include <X11/extensions/XvMC.h> 51#include <X11/extensions/XvMClib.h> 52#include <X11/extensions/vldXvMC.h> 53#include <drm_sarea.h> 54 55#include "i915_drm.h" 56#include "intel_bufmgr.h" 57 58#include "intel_xvmc.h" 59#include "intel_batchbuffer.h" 60 61#define GTT_PAGE_SIZE 4*1024 62 63#define XVMC_ERR(s, arg...) \ 64 do { \ 65 fprintf(stderr, "[intel_xvmc] err: " s "\n", ##arg); \ 66 } while (0) 67 68#define XVMC_INFO(s, arg...) \ 69 do { \ 70 fprintf(stderr, "[intel_xvmc] info: " s "\n", ##arg); \ 71 } while (0) 72 73/* Subpicture fourcc */ 74#define FOURCC_IA44 0x34344149 75 76/* 77 Definitions for temporary wire protocol hooks to be replaced 78 when a HW independent libXvMC is created. 79*/ 80extern Status _xvmc_create_context(Display * dpy, XvMCContext * context, 81 int *priv_count, CARD32 ** priv_data); 82 83extern Status _xvmc_destroy_context(Display * dpy, XvMCContext * context); 84 85extern Status _xvmc_create_surface(Display * dpy, XvMCContext * context, 86 XvMCSurface * surface, int *priv_count, 87 CARD32 ** priv_data); 88 89extern Status _xvmc_destroy_surface(Display * dpy, XvMCSurface * surface); 90 91extern Status _xvmc_create_subpicture(Display * dpy, XvMCContext * context, 92 XvMCSubpicture * subpicture, 93 int *priv_count, uint ** priv_data); 94 95extern Status _xvmc_destroy_subpicture(Display * dpy, 96 XvMCSubpicture * subpicture); 97 98struct intel_xvmc_context { 99 struct intel_xvmc_hw_context *hw; 100 uint32_t surface_bo_size; 101 drm_context_t hw_context; /* context id to kernel drm */ 102}; 103typedef struct intel_xvmc_context *intel_xvmc_context_ptr; 104 105struct intel_xvmc_surface { 106 XvMCContext *context; 107 XvImage *image; 108 GC gc; 109 Bool gc_init; 110 Drawable last_draw; 111 drm_intel_bo *bo; 112 uint32_t gem_handle; 113}; 114typedef struct intel_xvmc_surface *intel_xvmc_surface_ptr; 115 116typedef struct _intel_xvmc_drm_map { 117 drm_handle_t handle; 118 unsigned long offset; 119 unsigned long size; 120 unsigned long bus_addr; 121 drmAddress map; 122} intel_xvmc_drm_map_t, *intel_xvmc_drm_map_ptr; 123 124typedef struct _intel_xvmc_driver { 125 int type; /* hw xvmc type - i830_hwmc.h */ 126 int screen; /* current screen num */ 127 128 int fd; /* drm file handler */ 129 130 dri_bufmgr *bufmgr; 131 132 struct { 133 unsigned int init_offset; 134 unsigned int size; 135 unsigned int space; 136 unsigned char *ptr; 137 unsigned char *init_ptr; 138 dri_bo *buf; 139 } batch; 140 141 struct { 142 void *ptr; 143 unsigned int size; 144 unsigned int offset; 145 unsigned int active_buf; 146 unsigned int irq_emitted; 147 } alloc; 148 intel_xvmc_drm_map_t batchbuffer; 149 150 sigset_t sa_mask; 151 pthread_mutex_t ctxmutex; 152 int locked; 153 154 int num_ctx; 155 intel_xvmc_context_ptr ctx_list; 156 int num_surf; 157 struct intel_xvmc_surface * surf_list; 158 159 void *private; 160 161 /* driver specific xvmc callbacks */ 162 Status(*create_context) (Display * display, XvMCContext * context, 163 int priv_count, CARD32 * priv_data); 164 165 Status(*destroy_context) (Display * display, XvMCContext * context); 166 167 Status(*render_surface) (Display * display, XvMCContext * context, 168 unsigned int picture_structure, 169 XvMCSurface * target_surface, 170 XvMCSurface * past_surface, 171 XvMCSurface * future_surface, 172 unsigned int flags, 173 unsigned int num_macroblocks, 174 unsigned int first_macroblock, 175 XvMCMacroBlockArray * macroblock_array, 176 XvMCBlockArray * blocks); 177 178 Status(*begin_surface) (Display * display, XvMCContext * context, 179 XvMCSurface * target_surface, 180 XvMCSurface * past_surface, 181 XvMCSurface * future_surface, 182 const XvMCMpegControl * control); 183 Status(*load_qmatrix) (Display * display, XvMCContext * context, 184 const XvMCQMatrix * qmx); 185 Status(*put_slice) (Display * display, XvMCContext * context, 186 unsigned char *slice, int bytes); 187 Status(*put_slice2) (Display * display, XvMCContext * context, 188 unsigned char *slice, int bytes, int slice_code); 189 190} intel_xvmc_driver_t, *intel_xvmc_driver_ptr; 191 192extern struct _intel_xvmc_driver i915_xvmc_mc_driver; 193extern struct _intel_xvmc_driver i965_xvmc_mc_driver; 194extern struct _intel_xvmc_driver xvmc_vld_driver; 195extern struct _intel_xvmc_driver *xvmc_driver; 196 197#define SET_BLOCKED_SIGSET() do { \ 198 sigset_t bl_mask; \ 199 sigfillset(&bl_mask); \ 200 sigdelset(&bl_mask, SIGFPE); \ 201 sigdelset(&bl_mask, SIGILL); \ 202 sigdelset(&bl_mask, SIGSEGV); \ 203 sigdelset(&bl_mask, SIGBUS); \ 204 sigdelset(&bl_mask, SIGKILL); \ 205 pthread_sigmask(SIG_SETMASK, &bl_mask, &xvmc_driver->sa_mask); \ 206 } while (0) 207 208#define RESTORE_BLOCKED_SIGSET() do { \ 209 pthread_sigmask(SIG_SETMASK, &xvmc_driver->sa_mask, NULL); \ 210 } while (0) 211 212#define PPTHREAD_MUTEX_LOCK() do { \ 213 SET_BLOCKED_SIGSET(); \ 214 pthread_mutex_lock(&xvmc_driver->ctxmutex); \ 215 } while (0) 216 217#define PPTHREAD_MUTEX_UNLOCK() do { \ 218 pthread_mutex_unlock(&xvmc_driver->ctxmutex); \ 219 RESTORE_BLOCKED_SIGSET(); \ 220 } while (0) 221 222extern void LOCK_HARDWARE(drm_context_t); 223extern void UNLOCK_HARDWARE(drm_context_t); 224 225static inline const char *intel_xvmc_decoder_string(int flag) 226{ 227 switch (flag) { 228 case XVMC_I915_MPEG2_MC: 229 return "i915/945 MPEG2 MC decoder"; 230 case XVMC_I965_MPEG2_MC: 231 return "i965 MPEG2 MC decoder"; 232 case XVMC_I945_MPEG2_VLD: 233 return "i945 MPEG2 VLD decoder"; 234 case XVMC_I965_MPEG2_VLD: 235 return "i965 MPEG2 VLD decoder"; 236 default: 237 return "Unknown decoder"; 238 } 239} 240 241extern unsigned int mb_bytes_420[64]; 242 243/* dump function */ 244extern void intel_xvmc_dump_open(void); 245extern void intel_xvmc_dump_close(void); 246extern void intel_xvmc_dump_render(XvMCContext * context, 247 unsigned int picture_structure, 248 XvMCSurface * target_surface, 249 XvMCSurface * past_surface, 250 XvMCSurface * future_surface, 251 unsigned int flags, 252 unsigned int num_macroblocks, 253 unsigned int first_macroblock, 254 XvMCMacroBlockArray * macroblock_array, 255 XvMCBlockArray * blocks); 256 257#define VFE_GENERIC_MODE 0x0 258#define VFE_VLD_MODE 0x1 259#define VFE_IS_MODE 0x2 260#define VFE_AVC_MC_MODE 0x4 261#define VFE_AVC_IT_MODE 0x7 262#define VFE_VC1_IT_MODE 0x7 263 264#endif 265