~ubuntu-branches/ubuntu/trusty/xserver-xorg-video-nouveau/trusty

« back to all changes in this revision

Viewing changes to src/nv_dri.c

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2009-12-04 12:31:58 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20091204123158-oc7ytykkz8anvr6i
Tags: 1:0.0.15+git20100128+2630a15-0ubuntu1
* New upstream snapshot
  + Too many commits to usefully list in the changelog.
  + User modesetting code is now removed.  Nouveau will now only work with 
    KMS.
* debian/control:
  + Bump versioned Build-Dep on libdrm-dev to >= 2.4.17-1ubuntu1~ to pick 
    up nouveau #define updates.
  + Bump build-dep on xserver-xorg-dev to >= 2:1.7.  Nouveau now requires 
    xorg-server >= 1.7.
  + Drop duplicate build-dep on xserver-xorg-dev
  + List the Build-Depends one-to-a-line for clarity
  + Drop the Depends: on linux-nouveau-modules.  Replace with temporary 
    Depends against apw's linux-backports-modules-nouveau* packages.
  + Bump Standards version to 3.8.3.
* debian/README.source
  + Quilt patchsys README for standards version 3.8.3 compliance
* Change versioning to match Sarvatt's snapshot versioning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2006 Stephane Marchesin
3
 
 * Copyright 2006 Ben Skeggs
4
 
 *
5
 
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 
 * copy of this software and associated documentation files (the "Software"),
7
 
 * to deal in the Software without restriction, including without limitation
8
 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 
 * and/or sell copies of the Software, and to permit persons to whom the
10
 
 * Software is furnished to do so, subject to the following conditions:
11
 
 *
12
 
 * The above copyright notice and this permission notice shall be included in
13
 
 * all copies or substantial portions of the 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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
 
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20
 
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
 
 * SOFTWARE.
22
 
 */
23
 
 
24
 
#include "nv_include.h"
25
 
 
26
 
#define _XF86DRI_SERVER_
27
 
#include "GL/glxint.h"
28
 
#include "GL/glxtokens.h"
29
 
#include "sarea.h"
30
 
#include "xf86drm.h"
31
 
#include "dri.h"
32
 
#include "nv_dripriv.h"
33
 
#include "nv_dri.h"
34
 
 
35
 
static Bool NVCreateContext(ScreenPtr pScreen, VisualPtr visual,
36
 
                drm_context_t hwContext, void *pVisualConfigPriv,
37
 
                DRIContextType contextStore)
38
 
{
39
 
        return TRUE;
40
 
}
41
 
 
42
 
 
43
 
static void NVDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
44
 
                DRIContextType contextStore)
45
 
{
46
 
        return;
47
 
}
48
 
 
49
 
static void NVDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
50
 
                DRIContextType oldContextType,
51
 
                void *oldContext,
52
 
                DRIContextType newContextType,
53
 
                void *newContext)
54
 
{
55
 
        /* we really should do something here */
56
 
        return;
57
 
}
58
 
 
59
 
static void NVDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 indx)
60
 
{   
61
 
        return;
62
 
}
63
 
 
64
 
static void NVDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
65
 
                RegionPtr prgnSrc, CARD32 indx)
66
 
{
67
 
        return;
68
 
}       
69
 
 
70
 
static void NVDRITransitionTo2d(ScreenPtr pScreen)
71
 
{
72
 
        return;
73
 
}
74
 
 
75
 
static void NVDRITransitionTo3d(ScreenPtr pScreen)
76
 
{
77
 
        return;
78
 
}
79
 
 
80
 
static void NVDRITransitionSingleToMulti3d(ScreenPtr pScreen)
81
 
{           
82
 
        return;
83
 
}           
84
 
        
85
 
static void NVDRITransitionMultiToSingle3d(ScreenPtr pScreen)
86
 
{       
87
 
        return;
88
 
}
89
 
 
90
 
static Bool NVDRIInitVisualConfigs(ScreenPtr pScreen)
91
 
{
92
 
        ScrnInfoPtr pScrn=xf86Screens[pScreen->myNum];
93
 
        __GLXvisualConfig* pConfigs = NULL;
94
 
        NVConfigPrivPtr pNVConfigs = NULL;
95
 
        NVConfigPrivPtr* pNVConfigPtrs = NULL;
96
 
        int db,depth,alpha,stencil;
97
 
        int depths[]={24,16,0};
98
 
        int num_configs,i;
99
 
 
100
 
        switch(pScrn->depth)
101
 
        {
102
 
                case 16:
103
 
                case 24:
104
 
                        num_configs=2*3*((pScrn->depth==24)?2:1)*2; /* db*depth*alpha*stencil */
105
 
                        if (!(pConfigs=(__GLXvisualConfig*)xcalloc(sizeof(__GLXvisualConfig),num_configs)))
106
 
                                return FALSE;
107
 
                        if (!(pNVConfigs=(NVConfigPrivPtr)xcalloc(sizeof(NVConfigPrivRec), num_configs))) {
108
 
                                xfree(pConfigs);
109
 
                                return FALSE;
110
 
                        }
111
 
                        if (!(pNVConfigPtrs=(NVConfigPrivPtr *)xcalloc(sizeof(NVConfigPrivPtr),num_configs))) {
112
 
                                xfree(pConfigs);
113
 
                                xfree(pNVConfigs);
114
 
                                return FALSE;
115
 
                        }
116
 
 
117
 
                        i = 0;
118
 
                        for(db=1;db>=0;db--)
119
 
                        for(depth=0;depth<3;depth++)
120
 
                        for(alpha=0;alpha<((pScrn->depth==24)?2:1);alpha++)
121
 
                        for(stencil=0;stencil<2;stencil++)
122
 
                        {
123
 
                                pConfigs[i].vid                = (VisualID)(-1);
124
 
                                pConfigs[i].class              = -1;
125
 
                                pConfigs[i].rgba               = TRUE;
126
 
                                if (pScrn->depth==16)
127
 
                                {                                       
128
 
                                        pConfigs[i].redSize            = 5;
129
 
                                        pConfigs[i].greenSize          = 6;
130
 
                                        pConfigs[i].blueSize           = 5;
131
 
                                        pConfigs[i].alphaSize          = 0;
132
 
                                        pConfigs[i].redMask            = 0x0000F800;
133
 
                                        pConfigs[i].greenMask          = 0x000007E0;
134
 
                                        pConfigs[i].blueMask           = 0x0000001F;
135
 
                                        pConfigs[i].alphaMask          = 0x00000000;
136
 
                                } else {
137
 
                                        pConfigs[i].redSize            = 8;
138
 
                                        pConfigs[i].greenSize          = 8;
139
 
                                        pConfigs[i].blueSize           = 8;
140
 
                                        pConfigs[i].redMask            = 0x00FF0000;
141
 
                                        pConfigs[i].greenMask          = 0x0000FF00;
142
 
                                        pConfigs[i].blueMask           = 0x000000FF;
143
 
                                        if (alpha) {
144
 
                                                pConfigs[i].alphaSize          = 8;
145
 
                                                pConfigs[i].alphaMask          = 0xFF000000;
146
 
                                        } else {
147
 
                                                pConfigs[i].alphaSize          = 0;
148
 
                                                pConfigs[i].alphaMask          = 0x00000000;
149
 
                                        }
150
 
                                }
151
 
 
152
 
                                pConfigs[i].accumRedSize   = 0;
153
 
                                pConfigs[i].accumGreenSize = 0;
154
 
                                pConfigs[i].accumBlueSize  = 0;
155
 
                                pConfigs[i].accumAlphaSize = 0;
156
 
                                if (db)
157
 
                                        pConfigs[i].doubleBuffer   = TRUE;
158
 
                                else
159
 
                                        pConfigs[i].doubleBuffer   = FALSE;
160
 
                                pConfigs[i].stereo             = FALSE;
161
 
                                pConfigs[i].bufferSize         = pScrn->depth;
162
 
                                if (depths[depth] == 24 && stencil) {
163
 
                                        pConfigs[i].depthSize          = depths[depth];
164
 
                                        pConfigs[i].stencilSize        = 8;
165
 
                                } else {
166
 
                                        pConfigs[i].depthSize          = depths[depth];
167
 
                                        pConfigs[i].stencilSize        = 0;
168
 
                                }
169
 
                                pConfigs[i].auxBuffers         = 0;
170
 
                                pConfigs[i].level              = 0;
171
 
                                pConfigs[i].visualRating       = GLX_NONE;
172
 
                                pConfigs[i].transparentPixel   = GLX_NONE;
173
 
                                pConfigs[i].transparentRed     = 0;
174
 
                                pConfigs[i].transparentGreen   = 0;
175
 
                                pConfigs[i].transparentBlue    = 0;
176
 
                                pConfigs[i].transparentAlpha   = 0;
177
 
                                pConfigs[i].transparentIndex   = 0;
178
 
                                i++;
179
 
                        }
180
 
                        break;
181
 
                default:
182
 
                        xf86DrvMsg(pScreen->myNum, X_ERROR, "[dri] no DRI at %d bpp ",pScrn->depth);
183
 
                        return FALSE;
184
 
        }
185
 
        GlxSetVisualConfigs(num_configs, pConfigs, (void**)pNVConfigPtrs);
186
 
        return TRUE;
187
 
}
188
 
 
189
 
Bool NVDRIGetVersion(ScrnInfoPtr pScrn)
190
 
{
191
 
        NVPtr pNv = NVPTR(pScrn);
192
 
        int errmaj, errmin;
193
 
        pointer ret;
194
 
 
195
 
        ret = LoadSubModule(pScrn->module, "dri", NULL, NULL, NULL,
196
 
                            NULL, &errmaj, &errmin);
197
 
        if (!ret) {
198
 
                xf86DrvMsg(pScrn->scrnIndex, X_INFO,
199
 
                                "error %d\n", errmaj);
200
 
                LoaderErrorMsg(pScrn->name, "dri", errmaj, errmin);
201
 
        }
202
 
 
203
 
        if (!ret && errmaj != LDR_ONCEONLY)
204
 
                return FALSE;
205
 
 
206
 
        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Loaded DRI module\n");
207
 
 
208
 
        /* Check the lib version */
209
 
        if (xf86LoaderCheckSymbol("drmGetLibVersion"))
210
 
                pNv->pLibDRMVersion = drmGetLibVersion(0);
211
 
        if (pNv->pLibDRMVersion == NULL) {
212
 
                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
213
 
                "NVDRIGetVersion failed because libDRM is really "
214
 
                "way to old to even get a version number out of it.\n"
215
 
                "[dri] Disabling DRI.\n");
216
 
                return FALSE;
217
 
        }
218
 
 
219
 
        return TRUE;
220
 
}
221
 
 
222
 
Bool NVDRICheckModules(ScrnInfoPtr pScrn)
223
 
{
224
 
        if (!xf86LoaderCheckSymbol("GlxSetVisualConfigs")) {
225
 
                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
226
 
                           "[dri] GlxSetVisualConfigs not found.\n");
227
 
                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
228
 
                           "      NVIDIA's glx present, or glx not loaded.\n");
229
 
                return FALSE;
230
 
        }
231
 
 
232
 
        return TRUE;
233
 
}
234
 
 
235
 
Bool NVDRIScreenInit(ScrnInfoPtr pScrn)
236
 
{
237
 
        DRIInfoPtr     pDRIInfo;
238
 
        NOUVEAUDRIPtr  pNOUVEAUDRI;
239
 
        NVPtr pNv = NVPTR(pScrn);
240
 
        ScreenPtr pScreen;
241
 
        pScreen = screenInfo.screens[pScrn->scrnIndex];
242
 
        int drm_page_size;
243
 
 
244
 
        if (!NVDRICheckModules(pScrn))
245
 
                return FALSE;
246
 
 
247
 
        drm_page_size = getpagesize();
248
 
        if (!(pDRIInfo = DRICreateInfoRec())) return FALSE;
249
 
 
250
 
        pDRIInfo->drmDriverName              = "nouveau";
251
 
        pDRIInfo->clientDriverName           = "nouveau";
252
 
        pDRIInfo->busIdString                = DRICreatePCIBusID(pNv->PciInfo);
253
 
 
254
 
        pDRIInfo->ddxDriverMajorVersion      = NV_MAJOR_VERSION;
255
 
        pDRIInfo->ddxDriverMinorVersion      = NV_MINOR_VERSION;
256
 
        pDRIInfo->ddxDriverPatchVersion      = NV_PATCHLEVEL;
257
 
 
258
 
        pDRIInfo->frameBufferSize            = getpagesize();
259
 
        pDRIInfo->frameBufferPhysicalAddress = (void *)pNv->VRAMPhysical;
260
 
        pDRIInfo->frameBufferStride          = pScrn->displayWidth * pScrn->bitsPerPixel/8;
261
 
 
262
 
        pDRIInfo->ddxDrawableTableEntry      = 1;
263
 
        pDRIInfo->maxDrawableTableEntry      = 1;
264
 
 
265
 
        if (!(pNOUVEAUDRI = (NOUVEAUDRIPtr)xcalloc(sizeof(NOUVEAUDRIRec), 1))) {
266
 
                DRIDestroyInfoRec(pDRIInfo);
267
 
                return FALSE;
268
 
        }
269
 
        pDRIInfo->devPrivate                 = pNOUVEAUDRI; 
270
 
        pDRIInfo->devPrivateSize             = sizeof(NOUVEAUDRIRec);
271
 
        pDRIInfo->contextSize                = sizeof(NVDRIContextRec);
272
 
        pDRIInfo->SAREASize                  = (drm_page_size > SAREA_MAX) ? drm_page_size : SAREA_MAX;
273
 
 
274
 
        pDRIInfo->CreateContext              = NVCreateContext;
275
 
        pDRIInfo->DestroyContext             = NVDestroyContext;
276
 
        pDRIInfo->SwapContext                = NVDRISwapContext;
277
 
        pDRIInfo->InitBuffers                = NVDRIInitBuffers;
278
 
        pDRIInfo->MoveBuffers                = NVDRIMoveBuffers;
279
 
        pDRIInfo->bufferRequests             = DRI_ALL_WINDOWS;
280
 
        pDRIInfo->TransitionTo2d             = NVDRITransitionTo2d;
281
 
        pDRIInfo->TransitionTo3d             = NVDRITransitionTo3d;
282
 
        pDRIInfo->TransitionSingleToMulti3D  = NVDRITransitionSingleToMulti3d;
283
 
        pDRIInfo->TransitionMultiToSingle3D  = NVDRITransitionMultiToSingle3d;
284
 
 
285
 
        pDRIInfo->createDummyCtx     = FALSE;
286
 
        pDRIInfo->createDummyCtxPriv = FALSE;
287
 
 
288
 
        pDRIInfo->keepFDOpen = TRUE;
289
 
 
290
 
        if (!DRIScreenInit(pScreen, pDRIInfo, &nouveau_device(pNv->dev)->fd)) {
291
 
                xf86DrvMsg(pScreen->myNum, X_ERROR,
292
 
                                "[dri] DRIScreenInit failed.  Disabling DRI.\n");
293
 
                xfree(pDRIInfo->devPrivate);
294
 
                pDRIInfo->devPrivate = NULL;
295
 
                DRIDestroyInfoRec(pDRIInfo);
296
 
                return FALSE;
297
 
        }
298
 
 
299
 
        if (!NVDRIInitVisualConfigs(pScreen)) {
300
 
                xf86DrvMsg(pScreen->myNum, X_ERROR,
301
 
                           "[dri] NVDRIInitVisualConfigs failed."
302
 
                           "  Disabling DRI.\n");
303
 
                DRICloseScreen(pScreen);
304
 
                xfree(pDRIInfo->devPrivate);
305
 
                pDRIInfo->devPrivate = NULL;
306
 
                DRIDestroyInfoRec(pDRIInfo);
307
 
                return FALSE;
308
 
        }
309
 
 
310
 
        pNv->pDRIInfo = pDRIInfo;
311
 
        return TRUE;
312
 
}
313
 
 
314
 
Bool NVDRIFinishScreenInit(ScrnInfoPtr pScrn, bool update)
315
 
{
316
 
        ScreenPtr      pScreen = screenInfo.screens[pScrn->scrnIndex];
317
 
        NVPtr          pNv = NVPTR(pScrn);
318
 
        NOUVEAUDRIPtr  pNOUVEAUDRI;
319
 
        int ret;
320
 
 
321
 
        if (!pNv->pDRIInfo)
322
 
                return TRUE;
323
 
 
324
 
        if (!update) {
325
 
                if (!DRIFinishScreenInit(pScreen))
326
 
                        return FALSE;
327
 
        }
328
 
 
329
 
        pNOUVEAUDRI                     = (NOUVEAUDRIPtr)pNv->pDRIInfo->devPrivate;
330
 
 
331
 
        pNOUVEAUDRI->device_id          = pNv->Chipset;
332
 
 
333
 
        pNOUVEAUDRI->width              = pScrn->virtualX;
334
 
        pNOUVEAUDRI->height             = pScrn->virtualY;
335
 
        pNOUVEAUDRI->depth              = pScrn->depth;
336
 
        pNOUVEAUDRI->bpp                = pScrn->bitsPerPixel;
337
 
 
338
 
        ret = nouveau_bo_handle_get(pNv->scanout, &pNOUVEAUDRI->front_offset);
339
 
        if (ret) {
340
 
                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
341
 
                           "[dri] unable to reference front buffer: %d\n", ret);
342
 
                return FALSE;
343
 
        }
344
 
        pNOUVEAUDRI->front_pitch        = pScrn->displayWidth;
345
 
        /* back/depth buffers will likely be allocated on a per-drawable
346
 
         * basis, but these may be useful if we want to support shared back
347
 
         * buffers at some point.
348
 
         */
349
 
        pNOUVEAUDRI->back_offset        = 0;
350
 
        pNOUVEAUDRI->back_pitch         = 0;
351
 
        pNOUVEAUDRI->depth_offset       = 0;
352
 
        pNOUVEAUDRI->depth_pitch        = 0;
353
 
 
354
 
        return TRUE;
355
 
}
356
 
 
357
 
void NVDRICloseScreen(ScrnInfoPtr pScrn)
358
 
{
359
 
        ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
360
 
        NVPtr pNv = NVPTR(pScrn);
361
 
 
362
 
        if (pNv->NoAccel)
363
 
                return;
364
 
 
365
 
        DRICloseScreen(pScreen);
366
 
 
367
 
        if (pNv->pDRIInfo) {
368
 
                if (pNv->pDRIInfo->devPrivate) {
369
 
                        xfree(pNv->pDRIInfo->devPrivate);
370
 
                        pNv->pDRIInfo->devPrivate = NULL;
371
 
                }
372
 
                DRIDestroyInfoRec(pNv->pDRIInfo);
373
 
                pNv->pDRIInfo = NULL;
374
 
        }
375
 
}
376