summaryrefslogtreecommitdiff
path: root/src/nv_dri.c
blob: 05e3d3026a98d0f91f91e557080fa332a801b39f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef XF86DRI
#include "nv_include.h"
#define _XF86DRI_SERVER_
#include "GL/glxint.h"
#include "sarea.h"
#include "xf86drm.h"
#include "dri.h"


static Bool NVCreateContext(ScreenPtr pScreen, VisualPtr visual,
		drm_context_t hwContext, void *pVisualConfigPriv,
		DRIContextType contextStore)
{
	return TRUE;
}


static void NVDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
		DRIContextType contextStore)
{
	return;
}

static void NVDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
		DRIContextType oldContextType,
		void *oldContext,
		DRIContextType newContextType,
		void *newContext)
{
	/* we really should do something here */
	return;
}

static void NVDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 indx)
{   
	return;
}

static void NVDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
		RegionPtr prgnSrc, CARD32 indx)
{
	return;
}	


Bool NVDRIScreenInit(ScrnInfoPtr pScrn)
{
    DRIInfoPtr     pDRIInfo;
    NVPtr pNv = NVPTR(pScrn);
    drmVersionPtr drm_version;
    ScreenPtr pScreen;
    pScreen = screenInfo.screens[pScrn->scrnIndex];

    if (!xf86LoadSubModule(pScrn, "dri")) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
                   "Could not load DRI module\n");
        return FALSE;
    }

    xf86LoaderReqSymLists(drmSymbols, NULL);
    xf86LoaderReqSymLists(driSymbols, NULL);
    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "Loaded DRI module\n");

    if (!(pDRIInfo = DRICreateInfoRec())) return FALSE;
    
    pNv->pDRIInfo                        = pDRIInfo;
    pDRIInfo->drmDriverName              = "nouveau";

    pDRIInfo->frameBufferPhysicalAddress = (void *)pNv->FbAddress;
    pDRIInfo->frameBufferSize            = pNv->FbUsableSize;
    pDRIInfo->frameBufferStride          = pScrn->displayWidth * pScrn->bitsPerPixel/8;
 
    pDRIInfo->ddxDrawableTableEntry      = 1;
    pDRIInfo->maxDrawableTableEntry      = 1;

    pDRIInfo->devPrivate                 = NULL; 
    pDRIInfo->devPrivateSize             = 0;
    pDRIInfo->contextSize                = 0;
    pDRIInfo->SAREASize                  = SAREA_MAX;
    
    pDRIInfo->CreateContext              = NVCreateContext;
    pDRIInfo->DestroyContext             = NVDestroyContext;
    pDRIInfo->SwapContext                = NVDRISwapContext;
    pDRIInfo->InitBuffers                = NVDRIInitBuffers;
    pDRIInfo->MoveBuffers                = NVDRIMoveBuffers;
    pDRIInfo->bufferRequests             = DRI_ALL_WINDOWS;
    if (!DRIScreenInit(pScreen, pDRIInfo, &pNv->drm_fd)) {
	xf86DrvMsg(pScreen->myNum, X_ERROR,
	    	    "[dri] DRIScreenInit failed.  Disabling DRI.\n");
	xfree(pDRIInfo->devPrivate);
	pDRIInfo->devPrivate = NULL;
	DRIDestroyInfoRec(pDRIInfo);
	pDRIInfo = NULL;
	return FALSE;
    }
    drm_version = drmGetVersion(pNv->drm_fd);

    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
               "DRM version: %d.%d.%d (name: %s)\n",
               drm_version->version_major, 
               drm_version->version_minor, 
               drm_version->version_patchlevel,
               drm_version->name);

    return TRUE;
}

Bool NVInitAGP(ScrnInfoPtr pScrn)
{
    NVPtr pNv = NVPTR(pScrn);
    int agp_mode;
    unsigned long agp_size;

    if (drmAgpAcquire(pNv->drm_fd)) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
                   "Could not access AGP, disabling DMA transfers\n");
        return FALSE;
    }        

    agp_size = drmAgpSize(pNv->drm_fd);
    pNv->agpSize = agp_size < 16*0x100000 ? agp_size : 16*0x100000;
    pNv->agpPhysical = drmAgpBase(pNv->drm_fd);
    
    agp_mode = drmAgpGetMode(pNv->drm_fd);
    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
               "AGP: version %d.%d\n"
               "     mode %x\n"
               "     base=%08lx size=%08lx (%08lx)\n"
               , drmAgpVersionMajor(pNv->drm_fd),
               drmAgpVersionMinor(pNv->drm_fd), agp_mode,
               pNv->agpPhysical, agp_size, pNv->agpSize);

    if (drmAgpEnable(pNv->drm_fd, agp_mode) < 0) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
                   "could not enable AGP\n");
        return FALSE;
    }

    if (drmAgpAlloc(pNv->drm_fd, pNv->agpSize, 0, 0, &pNv->drm_agp_handle)) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
                   "could not allocate AGP memory\n");
        return FALSE;
    }

    if (drmAgpBind(pNv->drm_fd, pNv->drm_agp_handle, 0)) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
                   "could not bind AGP memory\n");
        return FALSE;
    }

    if (drmAddMap(pNv->drm_fd, 0, pNv->agpSize, /* agp_size, */
                  DRM_AGP, 0,
                  &pNv->drm_agp_map_handle)) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
                   "could not add AGP map, %s\n", strerror(errno));
        return FALSE;
    }        
    
    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
               "agp map handle=%08lx\n", pNv->drm_agp_map_handle);
    /* no idea why the handle is set to 0 in the addMap call. */
    
    if (drmMap(pNv->drm_fd, pNv->agpPhysical, pNv->agpSize /* agp_size */, (drmAddressPtr)&pNv->agpMemory)) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
                   "could not map AGP memory: %s\n", strerror(errno));
        return FALSE;
    }

    return TRUE;
    
#if 0
    {
        char *tmp = malloc(pNv->agpSize);
        struct timeval tv, tv2;
        gettimeofday(&tv, 0);
        memcpy(tmp, pNv->agpMemory, pNv->agpSize);
        gettimeofday(&tv2, 0);
        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                   "agp: Memory benchmark %f MB/s\n",
                   (pNv->agpSize/(1024.*1024.))*1000000
                   /((int)tv2.tv_usec- (int)tv.tv_usec + 1000000*(tv2.tv_sec-tv.tv_sec)+1));
        free(tmp);
    }
#endif
}
#endif