1 #include "nv_include.h"
3 #define _XF86DRI_SERVER_
10 static Bool NVCreateContext(ScreenPtr pScreen, VisualPtr visual,
11 drm_context_t hwContext, void *pVisualConfigPriv,
12 DRIContextType contextStore)
18 static void NVDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
19 DRIContextType contextStore)
24 static void NVDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
25 DRIContextType oldContextType,
27 DRIContextType newContextType,
30 /* we really should do something here */
34 static void NVDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 indx)
39 static void NVDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
40 RegionPtr prgnSrc, CARD32 indx)
46 Bool NVDRIScreenInit(ScrnInfoPtr pScrn)
49 NVPtr pNv = NVPTR(pScrn);
50 drmVersionPtr drm_version;
52 pScreen = screenInfo.screens[pScrn->scrnIndex];
54 if (!xf86LoadSubModule(pScrn, "dri")) {
55 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
56 "Could not load DRI module\n");
60 xf86LoaderReqSymLists(drmSymbols, NULL);
61 xf86LoaderReqSymLists(driSymbols, NULL);
62 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
63 "Loaded DRI module\n");
65 if (!(pDRIInfo = DRICreateInfoRec())) return FALSE;
67 pNv->pDRIInfo = pDRIInfo;
68 pDRIInfo->drmDriverName = "nouveau";
70 pDRIInfo->frameBufferPhysicalAddress = (void *)pNv->FbAddress;
71 pDRIInfo->frameBufferSize = pNv->FbUsableSize;
72 pDRIInfo->frameBufferStride = pScrn->displayWidth * pScrn->bitsPerPixel/8;
74 pDRIInfo->ddxDrawableTableEntry = 1;
75 pDRIInfo->maxDrawableTableEntry = 1;
77 pDRIInfo->devPrivate = NULL;
78 pDRIInfo->devPrivateSize = 0;
79 pDRIInfo->contextSize = 0;
80 pDRIInfo->SAREASize = SAREA_MAX;
82 pDRIInfo->CreateContext = NVCreateContext;
83 pDRIInfo->DestroyContext = NVDestroyContext;
84 pDRIInfo->SwapContext = NVDRISwapContext;
85 pDRIInfo->InitBuffers = NVDRIInitBuffers;
86 pDRIInfo->MoveBuffers = NVDRIMoveBuffers;
87 pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
88 if (!DRIScreenInit(pScreen, pDRIInfo, &pNv->drm_fd)) {
89 xf86DrvMsg(pScreen->myNum, X_ERROR,
90 "[dri] DRIScreenInit failed. Disabling DRI.\n");
91 xfree(pDRIInfo->devPrivate);
92 pDRIInfo->devPrivate = NULL;
93 DRIDestroyInfoRec(pDRIInfo);
97 drm_version = drmGetVersion(pNv->drm_fd);
99 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
100 "DRM version: %d.%d.%d (name: %s)\n",
101 drm_version->version_major,
102 drm_version->version_minor,
103 drm_version->version_patchlevel,
109 Bool NVInitAGP(ScrnInfoPtr pScrn)
111 NVPtr pNv = NVPTR(pScrn);
113 unsigned long agp_size;
115 if (drmAgpAcquire(pNv->drm_fd)) {
116 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
117 "Could not access AGP, disabling DMA transfers\n");
121 agp_size = drmAgpSize(pNv->drm_fd);
122 pNv->agpSize = agp_size < 16*0x100000 ? agp_size : 16*0x100000;
123 pNv->agpPhysical = drmAgpBase(pNv->drm_fd);
125 agp_mode = drmAgpGetMode(pNv->drm_fd);
126 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
127 "AGP: version %d.%d\n"
129 " base=%08lx size=%08lx (%08lx)\n"
130 , drmAgpVersionMajor(pNv->drm_fd),
131 drmAgpVersionMinor(pNv->drm_fd), agp_mode,
132 pNv->agpPhysical, agp_size, pNv->agpSize);
134 if (drmAgpEnable(pNv->drm_fd, agp_mode) < 0) {
135 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
136 "could not enable AGP\n");
140 if (drmAgpAlloc(pNv->drm_fd, pNv->agpSize, 0, 0, &pNv->drm_agp_handle)) {
141 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
142 "could not allocate AGP memory\n");
146 if (drmAgpBind(pNv->drm_fd, pNv->drm_agp_handle, 0)) {
147 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
148 "could not bind AGP memory\n");
152 if (drmAddMap(pNv->drm_fd, 0, pNv->agpSize, /* agp_size, */
154 &pNv->drm_agp_map_handle)) {
155 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
156 "could not add AGP map, %s\n", strerror(errno));
160 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
161 "agp map handle=%08lx\n", pNv->drm_agp_map_handle);
162 /* no idea why the handle is set to 0 in the addMap call. */
164 if (drmMap(pNv->drm_fd, pNv->agpPhysical, pNv->agpSize /* agp_size */, (drmAddressPtr)&pNv->agpMemory)) {
165 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
166 "could not map AGP memory: %s\n", strerror(errno));
174 char *tmp = malloc(pNv->agpSize);
175 struct timeval tv, tv2;
176 gettimeofday(&tv, 0);
177 memcpy(tmp, pNv->agpMemory, pNv->agpSize);
178 gettimeofday(&tv2, 0);
179 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
180 "agp: Memory benchmark %f MB/s\n",
181 (pNv->agpSize/(1024.*1024.))*1000000
182 /((int)tv2.tv_usec- (int)tv.tv_usec + 1000000*(tv2.tv_sec-tv.tv_sec)+1));