1
/***************************************************************************
3
Copyright 2000 Intel Corporation. All Rights Reserved.
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:
13
The above copyright notice and this permission notice (including the
14
next paragraph) shall be included in all copies or substantial portions
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 INTEL, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
21
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
23
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
**************************************************************************/
28
* i810_hwmc.c: i810 HWMC Driver
31
* Matt Sottek <matthew.j.sottek@intel.com>
35
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i810_hwmc.c,v 1.4 2002/09/11 00:29:32 dawes Exp $ */
39
#include "xf86_OSproc.h"
40
#include "xf86Resources.h"
41
#include "xf86_ansic.h"
43
#include "xf86PciInfo.h"
45
#include "xf86fbman.h"
46
#include "regionstr.h"
57
#include "dixstruct.h"
60
int I810XvMCCreateContext (ScrnInfoPtr pScrn, XvMCContextPtr pContext,
61
int *num_priv, long **priv );
62
void I810XvMCDestroyContext (ScrnInfoPtr pScrn, XvMCContextPtr pContext);
64
int I810XvMCCreateSurface (ScrnInfoPtr pScrn, XvMCSurfacePtr pSurf,
65
int *num_priv, long **priv );
66
void I810XvMCDestroySurface (ScrnInfoPtr pScrn, XvMCSurfacePtr pSurf);
68
int I810XvMCCreateSubpicture (ScrnInfoPtr pScrn, XvMCSubpicturePtr pSurf,
69
int *num_priv, long **priv );
70
void I810XvMCDestroySubpicture (ScrnInfoPtr pScrn, XvMCSubpicturePtr pSurf);
74
drmContext drmcontext;
76
unsigned int OverlayOffset;
77
unsigned int OverlaySize;
78
unsigned int SurfacesOffset;
79
unsigned int SurfacesSize;
82
} I810XvMCCreateContextRec;
85
static int yv12_subpicture_index_list[2] =
91
static XF86MCImageIDList yv12_subpicture_list =
94
yv12_subpicture_index_list
97
static XF86MCSurfaceInfoRec i810_YV12_mpg2_surface =
100
XVMC_CHROMA_FORMAT_420,
107
XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING |
109
&yv12_subpicture_list
112
static XF86MCSurfaceInfoRec i810_YV12_mpg1_surface =
115
XVMC_CHROMA_FORMAT_420,
122
XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING |
124
&yv12_subpicture_list
127
static XF86MCSurfaceInfoPtr ppSI[2] =
129
(XF86MCSurfaceInfoPtr)&i810_YV12_mpg2_surface,
130
(XF86MCSurfaceInfoPtr)&i810_YV12_mpg1_surface
133
/* List of subpicture types that we support */
134
static XF86ImageRec ia44_subpicture = XVIMAGE_IA44;
135
static XF86ImageRec ai44_subpicture = XVIMAGE_AI44;
137
static XF86ImagePtr i810_subpicture_list[2] =
139
(XF86ImagePtr)&ia44_subpicture,
140
(XF86ImagePtr)&ai44_subpicture
143
/* Fill in the device dependent adaptor record.
144
* This is named "I810 Video Overlay" because this code falls under the
145
* XV extenstion, the name must match or it won't be used.
147
* Surface and Subpicture - see above
148
* Function pointers to functions below
150
static XF86MCAdaptorRec pAdapt =
152
"I810 Video Overlay", /* name */
153
2, /* num_surfaces */
155
2, /* num_subpictures */
156
i810_subpicture_list, /* subpictures */
157
(xf86XvMCCreateContextProcPtr)I810XvMCCreateContext,
158
(xf86XvMCDestroyContextProcPtr)I810XvMCDestroyContext,
159
(xf86XvMCCreateSurfaceProcPtr)I810XvMCCreateSurface,
160
(xf86XvMCDestroySurfaceProcPtr)I810XvMCDestroySurface,
161
(xf86XvMCCreateSubpictureProcPtr)I810XvMCCreateSubpicture,
162
(xf86XvMCDestroySubpictureProcPtr)I810XvMCDestroySubpicture
165
static XF86MCAdaptorPtr ppAdapt[1] =
167
(XF86MCAdaptorPtr)&pAdapt
170
/**************************************************************************
174
* Initialize the hardware motion compenstation extention for this
175
* hardware. The initialization routines want the address of the pointers
176
* to the structures, not the address of the structures. This means we
177
* allocate (or create static?) the pointer memory and pass that
178
* address. This seems a little convoluted.
180
* We need to allocate memory for the device depended adaptor record.
181
* This is what holds the pointers to all our device functions.
183
* We need to map the overlay registers into the drm.
185
* We need to map the surfaces into the drm.
191
* None, this calls the device independent screen initialization
196
**************************************************************************/
197
void I810InitMC(ScreenPtr pScreen)
199
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
200
I810Ptr pI810 = I810PTR(pScrn);
203
/* Clear the Surface Allocation */
204
for(i=0; i<I810_MAX_SURFACES; i++) {
205
pI810->surfaceAllocation[i] = 0;
208
/* Cursor is at a page boundary, Overlay regs are not, don't forget */
209
if (drmAddMap(pI810->drmSubFD, (drmHandle)pI810->CursorStart,
210
4096, DRM_AGP, 0, &pI810->overlay_map) < 0) {
211
xf86DrvMsg(pScreen->myNum, X_ERROR, "drmAddMap(overlay) failed\n");
214
if (drmAddMap(pI810->drmSubFD, (drmHandle)pI810->MC.Start,
215
pI810->MC.Size, DRM_AGP, 0, &pI810->mc_map) < 0) {
216
xf86DrvMsg(pScreen->myNum, X_ERROR, "drmAddMap(MC) failed\n");
219
xf86XvMCScreenInit(pScreen, 1, ppAdapt);
222
/**************************************************************************
224
* I810XvMCCreateContext
226
* Some info about the private data:
228
* Set *num_priv to the number of 32bit words that make up the size of
229
* of the data that priv will point to.
231
* *priv = (long *) xcalloc (elements, sizeof(element))
232
* *num_priv = (elements * sizeof(element)) >> 2;
234
**************************************************************************/
236
int I810XvMCCreateContext (ScrnInfoPtr pScrn, XvMCContextPtr pContext,
237
int *num_priv, long **priv )
239
I810Ptr pI810 = I810PTR(pScrn);
240
DRIInfoPtr pDRIInfo = pI810->pDRIInfo;
241
I810XvMCCreateContextRec *contextRec;
244
if(!pI810->directRenderingEnabled) {
245
xf86DrvMsg(X_ERROR, pScrn->scrnIndex,
246
"I810XvMCCreateContext: Cannot use XvMC without DRI!\n");
250
/* Context Already in use! */
251
if(pI810->xvmcContext) {
252
xf86DrvMsg(X_WARNING, pScrn->scrnIndex,
253
"I810XvMCCreateContext: 2 XvMC Contexts Attempted, not supported.\n");
257
*priv = xcalloc(1,sizeof(I810XvMCCreateContextRec));
258
contextRec = (I810XvMCCreateContextRec *)*priv;
265
*num_priv = sizeof(I810XvMCCreateContextRec) >> 2;
266
if(drmCreateContext(pI810->drmSubFD, &(contextRec->drmcontext) ) < 0) {
267
xf86DrvMsg(X_ERROR, pScrn->scrnIndex,
268
"I810XvMCCreateContext: Unable to create DRMContext!\n");
273
drmAuthMagic(pI810->drmSubFD, pContext->flags);
275
pI810->xvmcContext = contextRec->drmcontext;
276
contextRec->fbBase = pScrn->memPhysBase;
278
/* Overlay Regs are at 1024 offset into the Cursor Space */
279
contextRec->OverlayOffset = pI810->CursorStart;
280
contextRec->OverlaySize = 4096;
282
contextRec->SurfacesOffset = pI810->MC.Start;
283
contextRec->SurfacesSize = pI810->MC.Size;
284
strncpy (contextRec->busIdString, pDRIInfo->busIdString, 9);
290
int I810XvMCCreateSurface (ScrnInfoPtr pScrn, XvMCSurfacePtr pSurf,
291
int *num_priv, long **priv )
293
I810Ptr pI810 = I810PTR(pScrn);
296
*priv = (long *)xcalloc(2,sizeof(long));
299
xf86DrvMsg(X_ERROR, pScrn->scrnIndex,
300
"I810XvMCCreateSurface: Unable to allocate memory!\n");
306
/* Surface Arrangement is different based on 6 or 7 Surfaces */
307
if(pI810->numSurfaces == 6) {
308
for(i=0; i<pI810->numSurfaces; i++) {
309
if(!pI810->surfaceAllocation[i]) {
310
pI810->surfaceAllocation[i] = pSurf->surface_id;
311
/* Y data starts at 2MB offset, each surface is 576k */
312
(*priv)[0] = (2*1024*1024 + 576*1024 * i);
313
/* UV data starts at 0 offset, each set is 288k */
314
(*priv)[1] = (576*512 * i);
319
if(pI810->numSurfaces == 7) {
320
for(i=0; i<pI810->numSurfaces; i++) {
321
if(!pI810->surfaceAllocation[i]) {
322
pI810->surfaceAllocation[i] = pSurf->surface_id;
323
/* Y data starts at 2.5MB offset, each surface is 576k */
324
(*priv)[0] = (2*1024*1024 + 512*1024 + 576*1024 * i);
325
/* UV data starts at 0 offset, each set is 288k */
326
(*priv)[1] = (576*512 * i);
336
int I810XvMCCreateSubpicture (ScrnInfoPtr pScrn, XvMCSubpicturePtr pSubp,
337
int *num_priv, long **priv )
339
I810Ptr pI810 = I810PTR(pScrn);
342
*priv = (long *)xcalloc(1,sizeof(long));
345
xf86DrvMsg(X_ERROR, pScrn->scrnIndex,
346
"I810XvMCCreateSubpicture: Unable to allocate memory!\n");
352
if(pI810->numSurfaces == 6) {
354
if(!pI810->surfaceAllocation[i]) {
355
pI810->surfaceAllocation[i] = pSubp->subpicture_id;
356
/* Subpictures are after the Y surfaces in memory */
357
(*priv)[0] = (2*1024*1024 + 576*1024 * i);
362
if(pI810->numSurfaces == 7) {
364
if(!pI810->surfaceAllocation[i]) {
365
pI810->surfaceAllocation[i] = pSubp->subpicture_id;
366
/* Subpictures are after the Y surfaces in memory */
367
(*priv)[0] = (2*1024*1024 + 512*1024 + 576*1024 * i);
377
void I810XvMCDestroyContext (ScrnInfoPtr pScrn, XvMCContextPtr pContext)
379
I810Ptr pI810 = I810PTR(pScrn);
381
drmDestroyContext(pI810->drmSubFD,pI810->xvmcContext);
382
pI810->xvmcContext = 0;
385
void I810XvMCDestroySurface (ScrnInfoPtr pScrn, XvMCSurfacePtr pSurf)
387
I810Ptr pI810 = I810PTR(pScrn);
390
for(i=0; i<I810_MAX_SURFACES; i++) {
391
if(pI810->surfaceAllocation[i] == pSurf->surface_id) {
392
pI810->surfaceAllocation[i] = 0;
399
void I810XvMCDestroySubpicture (ScrnInfoPtr pScrn, XvMCSubpicturePtr pSubp)
401
I810Ptr pI810 = I810PTR(pScrn);
404
for(i=pI810->numSurfaces; i<I810_MAX_SURFACES + I810_MAX_SUBPICTURES; i++) {
405
if(pI810->surfaceAllocation[i] == pSubp->subpicture_id) {
406
pI810->surfaceAllocation[i] = 0;