1 /* $XdotOrg: driver/xf86-video-nv/src/nv_driver.c,v 1.21 2006/01/24 16:45:29 aplattner Exp $ */
2 /* $XConsortium: nv_driver.c /main/3 1996/10/28 05:13:37 kaleb $ */
4 * Copyright 1996-1997 David J. McKay
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * DAVID J. MCKAY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 /* Hacked together from mga driver and 3.3.4 NVIDIA driver by Jarno Paananen
28 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/nv_driver.c,v 1.144 2006/06/16 00:19:32 mvojkovi Exp $ */
30 #include "nv_include.h"
32 #include "xf86int10.h"
38 const OptionInfoRec * RivaAvailableOptions(int chipid, int busid);
39 Bool RivaGetScrnInfoRec(PciChipsets *chips, int chip);
42 * Forward definitions for the functions that make up the driver.
44 /* Mandatory functions */
45 static const OptionInfoRec * NVAvailableOptions(int chipid, int busid);
46 static void NVIdentify(int flags);
47 static Bool NVProbe(DriverPtr drv, int flags);
48 static Bool NVPreInit(ScrnInfoPtr pScrn, int flags);
49 static Bool NVScreenInit(int Index, ScreenPtr pScreen, int argc,
51 static Bool NVEnterVT(int scrnIndex, int flags);
52 static void NVLeaveVT(int scrnIndex, int flags);
53 static Bool NVCloseScreen(int scrnIndex, ScreenPtr pScreen);
54 static Bool NVSaveScreen(ScreenPtr pScreen, int mode);
56 /* Optional functions */
57 static void NVFreeScreen(int scrnIndex, int flags);
58 static ModeStatus NVValidMode(int scrnIndex, DisplayModePtr mode,
59 Bool verbose, int flags);
61 static Bool NVDriverFunc(ScrnInfoPtr pScrnInfo, xorgDriverFuncOp op,
65 /* Internally used functions */
67 static Bool NVMapMem(ScrnInfoPtr pScrn);
68 static Bool NVUnmapMem(ScrnInfoPtr pScrn);
69 static void NVSave(ScrnInfoPtr pScrn);
70 static void NVRestore(ScrnInfoPtr pScrn);
71 static Bool NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
75 * This contains the functions needed by the server after loading the
76 * driver module. It must be supplied, and gets added the driver list by
77 * the Module Setup funtion in the dynamic case. In the static case a
78 * reference to this is compiled in, and this requires that the name of
79 * this DriverRec be an upper-case version of the driver name.
82 _X_EXPORT DriverRec NV = {
92 /* Known cards as of 2006/06/16 */
94 static SymTabRec NVKnownChipsets[] =
96 { 0x12D20018, "RIVA 128" },
98 { 0x10DE0020, "RIVA TNT" },
100 { 0x10DE0028, "RIVA TNT2" },
101 { 0x10DE002A, "Unknown TNT2" },
102 { 0x10DE002C, "Vanta" },
103 { 0x10DE0029, "RIVA TNT2 Ultra" },
104 { 0x10DE002D, "RIVA TNT2 Model 64" },
106 { 0x10DE00A0, "Aladdin TNT2" },
108 { 0x10DE0100, "GeForce 256" },
109 { 0x10DE0101, "GeForce DDR" },
110 { 0x10DE0103, "Quadro" },
112 { 0x10DE0110, "GeForce2 MX/MX 400" },
113 { 0x10DE0111, "GeForce2 MX 100/200" },
114 { 0x10DE0112, "GeForce2 Go" },
115 { 0x10DE0113, "Quadro2 MXR/EX/Go" },
117 { 0x10DE01A0, "GeForce2 Integrated GPU" },
119 { 0x10DE0150, "GeForce2 GTS" },
120 { 0x10DE0151, "GeForce2 Ti" },
121 { 0x10DE0152, "GeForce2 Ultra" },
122 { 0x10DE0153, "Quadro2 Pro" },
124 { 0x10DE0170, "GeForce4 MX 460" },
125 { 0x10DE0171, "GeForce4 MX 440" },
126 { 0x10DE0172, "GeForce4 MX 420" },
127 { 0x10DE0173, "GeForce4 MX 440-SE" },
128 { 0x10DE0174, "GeForce4 440 Go" },
129 { 0x10DE0175, "GeForce4 420 Go" },
130 { 0x10DE0176, "GeForce4 420 Go 32M" },
131 { 0x10DE0177, "GeForce4 460 Go" },
132 { 0x10DE0178, "Quadro4 550 XGL" },
133 #if defined(__powerpc__)
134 { 0x10DE0179, "GeForce4 MX (Mac)" },
136 { 0x10DE0179, "GeForce4 440 Go 64M" },
138 { 0x10DE017A, "Quadro NVS" },
139 { 0x10DE017C, "Quadro4 500 GoGL" },
140 { 0x10DE017D, "GeForce4 410 Go 16M" },
142 { 0x10DE0181, "GeForce4 MX 440 with AGP8X" },
143 { 0x10DE0182, "GeForce4 MX 440SE with AGP8X" },
144 { 0x10DE0183, "GeForce4 MX 420 with AGP8X" },
145 { 0x10DE0185, "GeForce4 MX 4000" },
146 { 0x10DE0186, "GeForce4 448 Go" },
147 { 0x10DE0187, "GeForce4 488 Go" },
148 { 0x10DE0188, "Quadro4 580 XGL" },
149 #if defined(__powerpc__)
150 { 0x10DE0189, "GeForce4 MX with AGP8X (Mac)" },
152 { 0x10DE018A, "Quadro4 NVS 280 SD" },
153 { 0x10DE018B, "Quadro4 380 XGL" },
154 { 0x10DE018C, "Quadro NVS 50 PCI" },
155 { 0x10DE018D, "GeForce4 448 Go" },
157 { 0x10DE01F0, "GeForce4 MX Integrated GPU" },
159 { 0x10DE0200, "GeForce3" },
160 { 0x10DE0201, "GeForce3 Ti 200" },
161 { 0x10DE0202, "GeForce3 Ti 500" },
162 { 0x10DE0203, "Quadro DCC" },
164 { 0x10DE0250, "GeForce4 Ti 4600" },
165 { 0x10DE0251, "GeForce4 Ti 4400" },
166 { 0x10DE0253, "GeForce4 Ti 4200" },
167 { 0x10DE0258, "Quadro4 900 XGL" },
168 { 0x10DE0259, "Quadro4 750 XGL" },
169 { 0x10DE025B, "Quadro4 700 XGL" },
171 { 0x10DE0280, "GeForce4 Ti 4800" },
172 { 0x10DE0281, "GeForce4 Ti 4200 with AGP8X" },
173 { 0x10DE0282, "GeForce4 Ti 4800 SE" },
174 { 0x10DE0286, "GeForce4 4200 Go" },
175 { 0x10DE028C, "Quadro4 700 GoGL" },
176 { 0x10DE0288, "Quadro4 980 XGL" },
177 { 0x10DE0289, "Quadro4 780 XGL" },
179 { 0x10DE0301, "GeForce FX 5800 Ultra" },
180 { 0x10DE0302, "GeForce FX 5800" },
181 { 0x10DE0308, "Quadro FX 2000" },
182 { 0x10DE0309, "Quadro FX 1000" },
184 { 0x10DE0311, "GeForce FX 5600 Ultra" },
185 { 0x10DE0312, "GeForce FX 5600" },
186 { 0x10DE0314, "GeForce FX 5600XT" },
187 { 0x10DE031A, "GeForce FX Go5600" },
188 { 0x10DE031B, "GeForce FX Go5650" },
189 { 0x10DE031C, "Quadro FX Go700" },
191 { 0x10DE0320, "GeForce FX 5200" },
192 { 0x10DE0321, "GeForce FX 5200 Ultra" },
193 { 0x10DE0322, "GeForce FX 5200" },
194 { 0x10DE0323, "GeForce FX 5200LE" },
195 { 0x10DE0324, "GeForce FX Go5200" },
196 { 0x10DE0325, "GeForce FX Go5250" },
197 { 0x10DE0326, "GeForce FX 5500" },
198 { 0x10DE0327, "GeForce FX 5100" },
199 { 0x10DE0328, "GeForce FX Go5200 32M/64M" },
200 #if defined(__powerpc__)
201 { 0x10DE0329, "GeForce FX 5200 (Mac)" },
203 { 0x10DE032A, "Quadro NVS 55/280 PCI" },
204 { 0x10DE032B, "Quadro FX 500/600 PCI" },
205 { 0x10DE032C, "GeForce FX Go53xx Series" },
206 { 0x10DE032D, "GeForce FX Go5100" },
208 { 0x10DE0330, "GeForce FX 5900 Ultra" },
209 { 0x10DE0331, "GeForce FX 5900" },
210 { 0x10DE0332, "GeForce FX 5900XT" },
211 { 0x10DE0333, "GeForce FX 5950 Ultra" },
212 { 0x10DE0334, "GeForce FX 5900ZT" },
213 { 0x10DE0338, "Quadro FX 3000" },
214 { 0x10DE033F, "Quadro FX 700" },
216 { 0x10DE0341, "GeForce FX 5700 Ultra" },
217 { 0x10DE0342, "GeForce FX 5700" },
218 { 0x10DE0343, "GeForce FX 5700LE" },
219 { 0x10DE0344, "GeForce FX 5700VE" },
220 { 0x10DE0347, "GeForce FX Go5700" },
221 { 0x10DE0348, "GeForce FX Go5700" },
222 { 0x10DE034C, "Quadro FX Go1000" },
223 { 0x10DE034E, "Quadro FX 1100" },
225 { 0x10DE0040, "GeForce 6800 Ultra" },
226 { 0x10DE0041, "GeForce 6800" },
227 { 0x10DE0042, "GeForce 6800 LE" },
228 { 0x10DE0043, "GeForce 6800 XE" },
229 { 0x10DE0044, "GeForce 6800 XT" },
230 { 0x10DE0045, "GeForce 6800 GT" },
231 { 0x10DE0046, "GeForce 6800 GT" },
232 { 0x10DE0047, "GeForce 6800 GS" },
233 { 0x10DE0048, "GeForce 6800 XT" },
234 { 0x10DE004E, "Quadro FX 4000" },
236 { 0x10DE00C0, "GeForce 6800 GS" },
237 { 0x10DE00C1, "GeForce 6800" },
238 { 0x10DE00C2, "GeForce 6800 LE" },
239 { 0x10DE00C3, "GeForce 6800 XT" },
240 { 0x10DE00C8, "GeForce Go 6800" },
241 { 0x10DE00C9, "GeForce Go 6800 Ultra" },
242 { 0x10DE00CC, "Quadro FX Go1400" },
243 { 0x10DE00CD, "Quadro FX 3450/4000 SDI" },
244 { 0x10DE00CE, "Quadro FX 1400" },
246 { 0x10DE0140, "GeForce 6600 GT" },
247 { 0x10DE0141, "GeForce 6600" },
248 { 0x10DE0142, "GeForce 6600 LE" },
249 { 0x10DE0143, "GeForce 6600 VE" },
250 { 0x10DE0144, "GeForce Go 6600" },
251 { 0x10DE0145, "GeForce 6610 XL" },
252 { 0x10DE0146, "GeForce Go 6600 TE/6200 TE" },
253 { 0x10DE0147, "GeForce 6700 XL" },
254 { 0x10DE0148, "GeForce Go 6600" },
255 { 0x10DE0149, "GeForce Go 6600 GT" },
256 { 0x10DE014C, "Quadro FX 550" },
257 { 0x10DE014D, "Quadro FX 550" },
258 { 0x10DE014E, "Quadro FX 540" },
259 { 0x10DE014F, "GeForce 6200" },
261 { 0x10DE0160, "GeForce 6500" },
262 { 0x10DE0161, "GeForce 6200 TurboCache(TM)" },
263 { 0x10DE0162, "GeForce 6200SE TurboCache(TM)" },
264 { 0x10DE0163, "GeForce 6200 LE" },
265 { 0x10DE0164, "GeForce Go 6200" },
266 { 0x10DE0165, "Quadro NVS 285" },
267 { 0x10DE0166, "GeForce Go 6400" },
268 { 0x10DE0167, "GeForce Go 6200" },
269 { 0x10DE0168, "GeForce Go 6400" },
270 { 0x10DE0169, "GeForce 6250" },
272 { 0x10DE0211, "GeForce 6800" },
273 { 0x10DE0212, "GeForce 6800 LE" },
274 { 0x10DE0215, "GeForce 6800 GT" },
275 { 0x10DE0218, "GeForce 6800 XT" },
277 { 0x10DE0221, "GeForce 6200" },
278 { 0x10DE0222, "GeForce 6200 A-LE" },
280 { 0x10DE0090, "GeForce 7800 GTX" },
281 { 0x10DE0091, "GeForce 7800 GTX" },
282 { 0x10DE0092, "GeForce 7800 GT" },
283 { 0x10DE0093, "GeForce 7800 GS" },
284 { 0x10DE0095, "GeForce 7800 SLI" },
285 { 0x10DE0098, "GeForce Go 7800" },
286 { 0x10DE0099, "GeForce Go 7800 GTX" },
287 { 0x10DE009D, "Quadro FX 4500" },
289 { 0x10DE01D1, "GeForce 7300 LE" },
290 { 0x10DE01D3, "GeForce 7300 SE" },
291 { 0x10DE01D6, "GeForce Go 7200" },
292 { 0x10DE01D7, "GeForce Go 7300" },
293 { 0x10DE01D8, "GeForce Go 7400" },
294 { 0x10DE01D9, "GeForce Go 7400 GS" },
295 { 0x10DE01DA, "Quadro NVS 110M" },
296 { 0x10DE01DB, "Quadro NVS 120M" },
297 { 0x10DE01DC, "Quadro FX 350M" },
298 { 0x10DE01DD, "GeForce 7500 LE" },
299 { 0x10DE01DE, "Quadro FX 350" },
300 { 0x10DE01DF, "GeForce 7300 GS" },
302 { 0x10DE0391, "GeForce 7600 GT" },
303 { 0x10DE0392, "GeForce 7600 GS" },
304 { 0x10DE0393, "GeForce 7300 GT" },
305 { 0x10DE0394, "GeForce 7600 LE" },
306 { 0x10DE0395, "GeForce 7300 GT" },
307 { 0x10DE0397, "GeForce Go 7700" },
308 { 0x10DE0398, "GeForce Go 7600" },
309 { 0x10DE0399, "GeForce Go 7600 GT"},
310 { 0x10DE039A, "Quadro NVS 300M" },
311 { 0x10DE039B, "GeForce Go 7900 SE" },
312 { 0x10DE039C, "Quadro FX 550M" },
313 { 0x10DE039E, "Quadro FX 560" },
315 { 0x10DE0290, "GeForce 7900 GTX" },
316 { 0x10DE0291, "GeForce 7900 GT" },
317 { 0x10DE0292, "GeForce 7900 GS" },
318 { 0x10DE0298, "GeForce Go 7900 GS" },
319 { 0x10DE0299, "GeForce Go 7900 GTX" },
320 { 0x10DE029A, "Quadro FX 2500M" },
321 { 0x10DE029B, "Quadro FX 1500M" },
322 { 0x10DE029C, "Quadro FX 5500" },
323 { 0x10DE029D, "Quadro FX 3500" },
324 { 0x10DE029E, "Quadro FX 1500" },
325 { 0x10DE029F, "Quadro FX 4500 X2" },
327 { 0x10DE0240, "GeForce 6150" },
328 { 0x10DE0241, "GeForce 6150 LE" },
329 { 0x10DE0242, "GeForce 6100" },
330 { 0x10DE0244, "GeForce Go 6150" },
331 { 0x10DE0247, "GeForce Go 6100" },
338 * List of symbols from other modules that this module references. This
339 * list is used to tell the loader that it is OK for symbols here to be
340 * unresolved providing that it hasn't been told that they haven't been
341 * told that they are essential via a call to xf86LoaderReqSymbols() or
342 * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
343 * unresolved symbols that are not required.
346 static const char *vgahwSymbols[] = {
361 static const char *fbSymbols[] = {
367 static const char *xaaSymbols[] = {
377 static const char *exaSymbols[] = {
383 static const char *ramdacSymbols[] = {
384 "xf86CreateCursorInfoRec",
385 "xf86DestroyCursorInfoRec",
390 static const char *ddcSymbols[] = {
393 "xf86SetDDCproperties",
397 static const char *vbeSymbols[] = {
404 static const char *i2cSymbols[] = {
405 "xf86CreateI2CBusRec",
410 static const char *shadowSymbols[] = {
415 static const char *int10Symbols[] = {
421 static const char *rivaSymbols[] = {
422 "RivaGetScrnInfoRec",
423 "RivaAvailableOptions",
428 const char *drmSymbols[] = {
433 "drmAgpVersionMajor",
434 "drmAgpVersionMinor",
446 "drmCtlUninstHandler",
449 "drmGetInterruptFromBusID",
455 const char *driSymbols[] = {
459 "DRIFinishScreenInit",
460 "DRIGetSAREAPrivate",
465 "GlxSetVisualConfigs",
472 static MODULESETUPPROTO(nvSetup);
474 static XF86ModuleVersionInfo nvVersRec =
480 XORG_VERSION_CURRENT,
481 NV_MAJOR_VERSION, NV_MINOR_VERSION, NV_PATCHLEVEL,
482 ABI_CLASS_VIDEODRV, /* This is a video driver */
483 ABI_VIDEODRV_VERSION,
488 _X_EXPORT XF86ModuleData nvModuleData = { &nvVersRec, nvSetup, NULL };
507 static const OptionInfoRec NVOptions[] = {
508 { OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE },
509 { OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, FALSE },
510 { OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE },
511 { OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE },
512 { OPTION_ROTATE, "Rotate", OPTV_ANYSTR, {0}, FALSE },
513 { OPTION_VIDEO_KEY, "VideoKey", OPTV_INTEGER, {0}, FALSE },
514 { OPTION_FLAT_PANEL, "FlatPanel", OPTV_BOOLEAN, {0}, FALSE },
515 { OPTION_FP_DITHER, "FPDither", OPTV_BOOLEAN, {0}, FALSE },
516 { OPTION_CRTC_NUMBER, "CrtcNumber", OPTV_INTEGER, {0}, FALSE },
517 { OPTION_FP_SCALE, "FPScale", OPTV_BOOLEAN, {0}, FALSE },
518 { OPTION_FP_TWEAK, "FPTweak", OPTV_INTEGER, {0}, FALSE },
519 { OPTION_ACCELMETHOD, "AccelMethod", OPTV_STRING, {0}, FALSE },
520 { -1, NULL, OPTV_NONE, {0}, FALSE }
524 * This is intentionally screen-independent. It indicates the binding
525 * choice made in the first PreInit.
527 static int pix24bpp = 0;
529 NVAllocRec *NVAllocateMemory(NVPtr pNv, int type, int size)
531 drm_nouveau_mem_alloc_t memalloc;
534 mem = malloc(sizeof(NVAllocRec));
537 mem->type = type | NOUVEAU_MEM_MAPPED;
540 memalloc.flags = mem->type;
541 memalloc.size = mem->size;
542 memalloc.alignment = 0;
543 memalloc.region_offset = &mem->offset;
544 if (drmCommandWriteRead(pNv->drm_fd, DRM_NOUVEAU_MEM_ALLOC, &memalloc,
546 ErrorF("NOUVEAU_MEM_ALLOC failed. flags=0x%08x, size=%d (%d)\n",
547 mem->type, mem->size, errno);
552 if (drmMap(pNv->drm_fd, mem->offset, mem->size, &mem->map)) {
553 ErrorF("drmMap() failed. offset=0x%llx, size=%d (%d)\n",
554 mem->offset, mem->size, errno);
555 //XXX: NOUVEAU_MEM_FREE
563 void NVFreeMemory(NVPtr pNv, NVAllocRec *mem)
565 drm_nouveau_mem_free_t memfree;
568 memfree.flags = mem->type;
569 memfree.region_offset = mem->offset;
570 if (drmCommandWriteRead(pNv->drm_fd, DRM_NOUVEAU_MEM_FREE, &memfree,
572 ErrorF("NOUVEAU_MEM_FREE failed. flags=0x%08x, offset=0x%llx (%d)\n",
573 mem->type, mem->size, errno);
580 NVGetRec(ScrnInfoPtr pScrn)
583 * Allocate an NVRec, and hook it into pScrn->driverPrivate.
584 * pScrn->driverPrivate is initialised to NULL, so we can check if
585 * the allocation has already been done.
587 if (pScrn->driverPrivate != NULL)
590 pScrn->driverPrivate = xnfcalloc(sizeof(NVRec), 1);
597 NVFreeRec(ScrnInfoPtr pScrn)
599 if (pScrn->driverPrivate == NULL)
601 xfree(pScrn->driverPrivate);
602 pScrn->driverPrivate = NULL;
607 nvSetup(pointer module, pointer opts, int *errmaj, int *errmin)
609 static Bool setupDone = FALSE;
611 /* This module should be loaded only once, but check to be sure. */
615 xf86AddDriver(&NV, module, 0);
618 * Modules that this driver always requires may be loaded here
619 * by calling LoadSubModule().
622 * Tell the loader about symbols from other modules that this module
625 LoaderRefSymLists(vgahwSymbols, xaaSymbols, exaSymbols, fbSymbols,
629 ramdacSymbols, shadowSymbols, rivaSymbols,
630 i2cSymbols, ddcSymbols, vbeSymbols,
634 * The return value must be non-NULL on success even though there
635 * is no TearDownProc.
639 if (errmaj) *errmaj = LDR_ONCEONLY;
644 static const OptionInfoRec *
645 NVAvailableOptions(int chipid, int busid)
647 if(chipid == 0x12D20018) {
648 if (!xf86LoadOneModule("riva128", NULL)) {
651 return RivaAvailableOptions(chipid, busid);
659 NVIdentify(int flags)
661 xf86PrintChipsets(NV_NAME, "driver for NVIDIA chipsets", NVKnownChipsets);
666 NVGetScrnInfoRec(PciChipsets *chips, int chip)
670 pScrn = xf86ConfigPciEntity(NULL, 0, chip,
671 chips, NULL, NULL, NULL,
674 if(!pScrn) return FALSE;
676 pScrn->driverVersion = NV_VERSION;
677 pScrn->driverName = NV_DRIVER_NAME;
678 pScrn->name = NV_NAME;
680 pScrn->Probe = NVProbe;
681 pScrn->PreInit = NVPreInit;
682 pScrn->ScreenInit = NVScreenInit;
683 pScrn->SwitchMode = NVSwitchMode;
684 pScrn->AdjustFrame = NVAdjustFrame;
685 pScrn->EnterVT = NVEnterVT;
686 pScrn->LeaveVT = NVLeaveVT;
687 pScrn->FreeScreen = NVFreeScreen;
688 pScrn->ValidMode = NVValidMode;
693 #define MAX_CHIPS MAXSCREENS
697 NVGetPCIXpressChip (pciVideoPtr pVideo)
699 volatile CARD32 *regs;
700 CARD32 pciid, pcicmd;
701 PCITAG Tag = ((pciConfigPtr)(pVideo->thisCard))->tag;
703 pcicmd = pciReadLong(Tag, PCI_CMD_STAT_REG);
704 pciWriteLong(Tag, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
706 regs = xf86MapPciMem(-1, VIDMEM_MMIO, Tag, pVideo->memBase[0], 0x2000);
708 pciid = regs[0x1800/4];
710 xf86UnMapVidMem(-1, (pointer)regs, 0x2000);
712 pciWriteLong(Tag, PCI_CMD_STAT_REG, pcicmd);
714 if((pciid & 0x0000ffff) == 0x000010DE)
715 pciid = 0x10DE0000 | (pciid >> 16);
717 if((pciid & 0xffff0000) == 0xDE100000) /* wrong endian */
718 pciid = 0x10DE0000 | ((pciid << 8) & 0x0000ff00) |
719 ((pciid >> 8) & 0x000000ff);
727 NVProbe(DriverPtr drv, int flags)
730 GDevPtr *devSections;
732 SymTabRec NVChipsets[MAX_CHIPS + 1];
733 PciChipsets NVPciChipsets[MAX_CHIPS + 1];
737 Bool foundScreen = FALSE;
740 if ((numDevSections = xf86MatchDevice(NV_DRIVER_NAME, &devSections)) <= 0)
741 return FALSE; /* no matching device section */
743 if (!(ppPci = xf86GetPciVideoInfo()))
744 return FALSE; /* no PCI cards found */
748 /* Create the NVChipsets and NVPciChipsets from found devices */
749 while (*ppPci && (numUsed < MAX_CHIPS)) {
750 if(((*ppPci)->vendor == PCI_VENDOR_NVIDIA_SGS) ||
751 ((*ppPci)->vendor == PCI_VENDOR_NVIDIA))
753 SymTabRec *nvchips = NVKnownChipsets;
754 int pciid = ((*ppPci)->vendor << 16) | (*ppPci)->chipType;
757 if(((token & 0xfff0) == CHIPSET_MISC_BRIDGED) ||
758 ((token & 0xfff0) == CHIPSET_G73_BRIDGED))
760 token = NVGetPCIXpressChip(*ppPci);
763 while(nvchips->name) {
764 if(token == nvchips->token)
769 if(nvchips->name) { /* found one */
770 NVChipsets[numUsed].token = pciid;
771 NVChipsets[numUsed].name = nvchips->name;
772 NVPciChipsets[numUsed].numChipset = pciid;
773 NVPciChipsets[numUsed].PCIid = pciid;
774 NVPciChipsets[numUsed].resList = RES_SHARED_VGA;
776 } else if ((*ppPci)->vendor == PCI_VENDOR_NVIDIA) {
777 /* look for a compatible devices which may be newer than
778 the NVKnownChipsets list above. */
779 switch(token & 0xfff0) {
803 NVChipsets[numUsed].token = pciid;
804 NVChipsets[numUsed].name = "Unknown NVIDIA chip";
805 NVPciChipsets[numUsed].numChipset = pciid;
806 NVPciChipsets[numUsed].PCIid = pciid;
807 NVPciChipsets[numUsed].resList = RES_SHARED_VGA;
810 default: break; /* we don't recognize it */
817 /* terminate the list */
818 NVChipsets[numUsed].token = -1;
819 NVChipsets[numUsed].name = NULL;
820 NVPciChipsets[numUsed].numChipset = -1;
821 NVPciChipsets[numUsed].PCIid = -1;
822 NVPciChipsets[numUsed].resList = RES_UNDEFINED;
824 numUsed = xf86MatchPciInstances(NV_NAME, 0, NVChipsets, NVPciChipsets,
825 devSections, numDevSections, drv,
831 if (flags & PROBE_DETECT)
833 else for (i = 0; i < numUsed; i++) {
836 pPci = xf86GetPciInfoForEntity(usedChips[i]);
837 if(pPci->vendor == PCI_VENDOR_NVIDIA_SGS) {
838 if (!xf86LoadDrvSubModule(drv, "riva128")) {
841 xf86LoaderReqSymLists(rivaSymbols, NULL);
842 if(RivaGetScrnInfoRec(NVPciChipsets, usedChips[i]))
845 if(NVGetScrnInfoRec(NVPciChipsets, usedChips[i]))
856 /* Usually mandatory */
858 NVSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
860 return NVModeInit(xf86Screens[scrnIndex], mode);
864 * This function is used to initialize the Start Address - the first
865 * displayed location in the video memory.
867 /* Usually mandatory */
869 NVAdjustFrame(int scrnIndex, int x, int y, int flags)
871 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
873 NVPtr pNv = NVPTR(pScrn);
874 NVFBLayout *pLayout = &pNv->CurrentLayout;
876 startAddr = (((y*pLayout->displayWidth)+x)*(pLayout->bitsPerPixel/8));
877 startAddr += (pNv->FB->offset - pNv->VRAMPhysical);
878 NVSetStartAddress(pNv, startAddr);
883 * This is called when VT switching back to the X server. Its job is
884 * to reinitialise the video mode.
886 * We may wish to unmap video/MMIO memory too.
891 NVEnterVT(int scrnIndex, int flags)
893 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
894 NVPtr pNv = NVPTR(pScrn);
896 if (!NVModeInit(pScrn, pScrn->currentMode))
898 NVAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
900 if(pNv->overlayAdaptor)
906 * This is called when VT switching away from the X server. Its job is
907 * to restore the previous (text) mode.
909 * We may wish to remap video/MMIO memory too.
914 NVLeaveVT(int scrnIndex, int flags)
916 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
917 NVPtr pNv = NVPTR(pScrn);
921 NVLockUnlock(pNv, 1);
934 ScreenPtr pScreen = screenInfo.screens[i];
935 ScrnInfoPtr pScrnInfo = xf86Screens[i];
936 NVPtr pNv = NVPTR(pScrnInfo);
938 if (pNv->DMAKickoffCallback)
939 (*pNv->DMAKickoffCallback)(pNv);
941 pScreen->BlockHandler = pNv->BlockHandler;
942 (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
943 pScreen->BlockHandler = NVBlockHandler;
945 if (pNv->VideoTimerCallback)
946 (*pNv->VideoTimerCallback)(pScrnInfo, currentTime.milliseconds);
952 * This is called at the end of each server generation. It restores the
953 * original (text) mode. It should also unmap the video memory, and free
954 * any per-generation data allocated by the driver. It should finish
955 * by unwrapping and calling the saved CloseScreen function.
960 NVCloseScreen(int scrnIndex, ScreenPtr pScreen)
962 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
963 NVPtr pNv = NVPTR(pScrn);
968 NVLockUnlock(pNv, 1);
972 vgaHWUnmapMem(pScrn);
973 if (pNv->AccelInfoRec)
974 XAADestroyInfoRec(pNv->AccelInfoRec);
975 if (pNv->CursorInfoRec)
976 xf86DestroyCursorInfoRec(pNv->CursorInfoRec);
978 xfree(pNv->ShadowPtr);
979 if (pNv->overlayAdaptor)
980 xfree(pNv->overlayAdaptor);
981 if (pNv->blitAdaptor)
982 xfree(pNv->blitAdaptor);
984 pScrn->vtSema = FALSE;
985 pScreen->CloseScreen = pNv->CloseScreen;
986 pScreen->BlockHandler = pNv->BlockHandler;
987 return (*pScreen->CloseScreen)(scrnIndex, pScreen);
990 /* Free up any persistent data structures */
994 NVFreeScreen(int scrnIndex, int flags)
997 * This only gets called when a screen is being deleted. It does not
998 * get called routinely at the end of a server generation.
1000 if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
1001 vgaHWFreeHWRec(xf86Screens[scrnIndex]);
1002 NVFreeRec(xf86Screens[scrnIndex]);
1006 /* Checks if a mode is suitable for the selected chipset. */
1010 NVValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
1012 NVPtr pNv = NVPTR(xf86Screens[scrnIndex]);
1014 if(pNv->fpWidth && pNv->fpHeight)
1015 if((pNv->fpWidth < mode->HDisplay) || (pNv->fpHeight < mode->VDisplay))
1016 return (MODE_PANEL);
1022 nvProbeDDC(ScrnInfoPtr pScrn, int index)
1026 if (xf86LoadSubModule(pScrn, "vbe")) {
1027 pVbe = VBEInit(NULL,index);
1028 ConfiguredMonitor = vbeDoEDID(pVbe, NULL);
1034 Bool NVI2CInit(ScrnInfoPtr pScrn)
1038 if (xf86LoadSubModule(pScrn, mod)) {
1039 xf86LoaderReqSymLists(i2cSymbols,NULL);
1042 if(xf86LoadSubModule(pScrn, mod)) {
1043 xf86LoaderReqSymLists(ddcSymbols, NULL);
1044 return NVDACi2cInit(pScrn);
1048 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
1049 "Couldn't load %s module. DDC probing can't be done\n", mod);
1056 NVPreInit(ScrnInfoPtr pScrn, int flags)
1060 int i, max_width, max_height;
1061 ClockRangePtr clockRanges;
1064 if (flags & PROBE_DETECT) {
1065 EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1073 nvProbeDDC(pScrn, i);
1078 * Note: This function is only called once at server startup, and
1079 * not at the start of each server generation. This means that
1080 * only things that are persistent across server generations can
1081 * be initialised here. xf86Screens[] is (pScrn is a pointer to one
1082 * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex()
1083 * are too, and should be used for data that must persist across
1084 * server generations.
1086 * Per-generation data should be allocated with
1087 * AllocateScreenPrivateIndex() from the ScreenInit() function.
1090 /* Check the number of entities, and fail if it isn't one. */
1091 if (pScrn->numEntities != 1)
1094 /* Allocate the NVRec driverPrivate */
1095 if (!NVGetRec(pScrn)) {
1100 /* Get the entity, and make sure it is PCI. */
1101 pNv->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1102 if (pNv->pEnt->location.type != BUS_PCI)
1105 /* Find the PCI info for this screen */
1106 pNv->PciInfo = xf86GetPciInfoForEntity(pNv->pEnt->index);
1107 pNv->PciTag = pciTag(pNv->PciInfo->bus, pNv->PciInfo->device,
1108 pNv->PciInfo->func);
1110 pNv->Primary = xf86IsPrimaryPci(pNv->PciInfo);
1112 /* Initialize the card through int10 interface if needed */
1113 if (xf86LoadSubModule(pScrn, "int10")) {
1114 xf86LoaderReqSymLists(int10Symbols, NULL);
1115 #if !defined(__alpha__) && !defined(__powerpc__)
1116 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initializing int10\n");
1117 pNv->pInt = xf86InitInt10(pNv->pEnt->index);
1121 xf86SetOperatingState(resVgaIo, pNv->pEnt->index, ResUnusedOpr);
1122 xf86SetOperatingState(resVgaMem, pNv->pEnt->index, ResDisableOpr);
1124 /* Set pScrn->monitor */
1125 pScrn->monitor = pScrn->confScreen->monitor;
1128 * Set the Chipset and ChipRev, allowing config file entries to
1131 if (pNv->pEnt->device->chipset && *pNv->pEnt->device->chipset) {
1132 pScrn->chipset = pNv->pEnt->device->chipset;
1133 pNv->Chipset = xf86StringToToken(NVKnownChipsets, pScrn->chipset);
1135 } else if (pNv->pEnt->device->chipID >= 0) {
1136 pNv->Chipset = pNv->pEnt->device->chipID;
1137 pScrn->chipset = (char *)xf86TokenToString(NVKnownChipsets,
1140 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipID override: 0x%04X\n",
1144 pNv->Chipset = (pNv->PciInfo->vendor << 16) | pNv->PciInfo->chipType;
1146 if(((pNv->Chipset & 0xfff0) == CHIPSET_MISC_BRIDGED) ||
1147 ((pNv->Chipset & 0xfff0) == CHIPSET_G73_BRIDGED))
1149 pNv->Chipset = NVGetPCIXpressChip(pNv->PciInfo);
1152 pScrn->chipset = (char *)xf86TokenToString(NVKnownChipsets,
1155 pScrn->chipset = "Unknown NVIDIA chipset";
1158 if (pNv->pEnt->device->chipRev >= 0) {
1159 pNv->ChipRev = pNv->pEnt->device->chipRev;
1160 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
1163 pNv->ChipRev = pNv->PciInfo->chipRev;
1167 * This shouldn't happen because such problems should be caught in
1168 * NVProbe(), but check it just in case.
1170 if (pScrn->chipset == NULL) {
1171 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1172 "ChipID 0x%04X is not recognised\n", pNv->Chipset);
1173 xf86FreeInt10(pNv->pInt);
1176 if (pNv->Chipset < 0) {
1177 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1178 "Chipset \"%s\" is not recognised\n", pScrn->chipset);
1179 xf86FreeInt10(pNv->pInt);
1183 xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n", pScrn->chipset);
1187 * The first thing we should figure out is the depth, bpp, etc.
1190 if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support32bppFb)) {
1191 xf86FreeInt10(pNv->pInt);
1194 /* Check that the returned depth is one we support */
1195 switch (pScrn->depth) {
1203 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1204 "Given depth (%d) is not supported by this driver\n",
1206 xf86FreeInt10(pNv->pInt);
1210 xf86PrintDepthBpp(pScrn);
1212 /* Get the depth24 pixmap format */
1213 if (pScrn->depth == 24 && pix24bpp == 0)
1214 pix24bpp = xf86GetBppFromDepth(pScrn, 24);
1217 * This must happen after pScrn->display has been set because
1218 * xf86SetWeight references it.
1220 if (pScrn->depth > 8) {
1221 /* The defaults are OK for us */
1222 rgb zeros = {0, 0, 0};
1224 if (!xf86SetWeight(pScrn, zeros, zeros)) {
1225 xf86FreeInt10(pNv->pInt);
1230 if (!xf86SetDefaultVisual(pScrn, -1)) {
1231 xf86FreeInt10(pNv->pInt);
1234 /* We don't currently support DirectColor at > 8bpp */
1235 if (pScrn->depth > 8 && (pScrn->defaultVisual != TrueColor)) {
1236 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual"
1237 " (%s) is not supported at depth %d\n",
1238 xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
1239 xf86FreeInt10(pNv->pInt);
1244 /* The vgahw module should be loaded here when needed */
1245 if (!xf86LoadSubModule(pScrn, "vgahw")) {
1246 xf86FreeInt10(pNv->pInt);
1250 xf86LoaderReqSymLists(vgahwSymbols, NULL);
1253 * Allocate a vgaHWRec
1255 if (!vgaHWGetHWRec(pScrn)) {
1256 xf86FreeInt10(pNv->pInt);
1260 /* We use a programmable clock */
1261 pScrn->progClock = TRUE;
1263 /* Collect all of the relevant option flags (fill in pScrn->options) */
1264 xf86CollectOptions(pScrn, NULL);
1266 /* Process the options */
1267 if (!(pNv->Options = xalloc(sizeof(NVOptions))))
1269 memcpy(pNv->Options, NVOptions, sizeof(NVOptions));
1270 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pNv->Options);
1272 /* Set the bits per RGB for 8bpp mode */
1273 if (pScrn->depth == 8)
1277 pNv->HWCursor = TRUE;
1279 * The preferred method is to use the "hw cursor" option as a tri-state
1280 * option, with the default set above.
1282 if (xf86GetOptValBool(pNv->Options, OPTION_HW_CURSOR, &pNv->HWCursor)) {
1285 /* For compatibility, accept this too (as an override) */
1286 if (xf86ReturnOptValBool(pNv->Options, OPTION_SW_CURSOR, FALSE)) {
1288 pNv->HWCursor = FALSE;
1290 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
1291 pNv->HWCursor ? "HW" : "SW");
1293 pNv->FpScale = TRUE;
1294 if (xf86GetOptValBool(pNv->Options, OPTION_FP_SCALE, &pNv->FpScale)) {
1295 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Flat panel scaling %s\n",
1296 pNv->FpScale ? "on" : "off");
1298 if (xf86ReturnOptValBool(pNv->Options, OPTION_NOACCEL, FALSE)) {
1299 pNv->NoAccel = TRUE;
1300 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1302 if (xf86ReturnOptValBool(pNv->Options, OPTION_SHADOW_FB, FALSE)) {
1303 pNv->ShadowFB = TRUE;
1304 pNv->NoAccel = TRUE;
1305 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1306 "Using \"Shadow Framebuffer\" - acceleration disabled\n");
1308 if (!pNv->NoAccel) {
1309 if((s = (char *)xf86GetOptValString(pNv->Options, OPTION_ACCELMETHOD))) {
1310 if(!xf86NameCmp(s,"XAA")) {
1312 pNv->useEXA = FALSE;
1313 } else if(!xf86NameCmp(s,"EXA")) {
1318 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using %s acceleration method\n", s);
1320 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1324 pNv->RandRRotation = FALSE;
1325 if ((s = xf86GetOptValString(pNv->Options, OPTION_ROTATE))) {
1326 if(!xf86NameCmp(s, "CW")) {
1327 pNv->ShadowFB = TRUE;
1328 pNv->NoAccel = TRUE;
1329 pNv->HWCursor = FALSE;
1331 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1332 "Rotating screen clockwise - acceleration disabled\n");
1334 if(!xf86NameCmp(s, "CCW")) {
1335 pNv->ShadowFB = TRUE;
1336 pNv->NoAccel = TRUE;
1337 pNv->HWCursor = FALSE;
1339 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1340 "Rotating screen counter clockwise - acceleration disabled\n");
1342 if(!xf86NameCmp(s, "RandR")) {
1344 pNv->ShadowFB = TRUE;
1345 pNv->NoAccel = TRUE;
1346 pNv->HWCursor = FALSE;
1347 pNv->RandRRotation = TRUE;
1348 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1349 "Using RandR rotation - acceleration disabled\n");
1351 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
1352 "This driver was not compiled with support for the Resize and "
1353 "Rotate extension. Cannot honor 'Option \"Rotate\" "
1357 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1358 "\"%s\" is not a valid value for Option \"Rotate\"\n", s);
1359 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1360 "Valid options are \"CW\", \"CCW\", and \"RandR\"\n");
1364 if(xf86GetOptValInteger(pNv->Options, OPTION_VIDEO_KEY, &(pNv->videoKey))) {
1365 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n",
1368 pNv->videoKey = (1 << pScrn->offset.red) |
1369 (1 << pScrn->offset.green) |
1370 (((pScrn->mask.blue >> pScrn->offset.blue) - 1) << pScrn->offset.blue);
1373 if (xf86GetOptValBool(pNv->Options, OPTION_FLAT_PANEL, &(pNv->FlatPanel))) {
1374 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "forcing %s usage\n",
1375 pNv->FlatPanel ? "DFP" : "CRTC");
1377 pNv->FlatPanel = -1; /* autodetect later */
1380 pNv->FPDither = FALSE;
1381 if (xf86GetOptValBool(pNv->Options, OPTION_FP_DITHER, &(pNv->FPDither)))
1382 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "enabling flat panel dither\n");
1384 if (xf86GetOptValInteger(pNv->Options, OPTION_CRTC_NUMBER,
1387 if((pNv->CRTCnumber < 0) || (pNv->CRTCnumber > 1)) {
1388 pNv->CRTCnumber = -1;
1389 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1390 "Invalid CRTC number. Must be 0 or 1\n");
1393 pNv->CRTCnumber = -1; /* autodetect later */
1397 if (xf86GetOptValInteger(pNv->Options, OPTION_FP_TWEAK,
1400 pNv->usePanelTweak = TRUE;
1402 pNv->usePanelTweak = FALSE;
1405 if (pNv->pEnt->device->MemBase != 0) {
1406 /* Require that the config file value matches one of the PCI values. */
1407 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->MemBase)) {
1408 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1409 "MemBase 0x%08lX doesn't match any PCI base register.\n",
1410 pNv->pEnt->device->MemBase);
1411 xf86FreeInt10(pNv->pInt);
1415 pNv->VRAMPhysical = pNv->pEnt->device->MemBase;
1418 if (pNv->PciInfo->memBase[1] != 0) {
1419 pNv->VRAMPhysical = pNv->PciInfo->memBase[1] & 0xff800000;
1422 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1423 "No valid FB address in PCI config space\n");
1424 xf86FreeInt10(pNv->pInt);
1429 xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
1430 (unsigned long)pNv->VRAMPhysical);
1432 if (pNv->pEnt->device->IOBase != 0) {
1433 /* Require that the config file value matches one of the PCI values. */
1434 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->IOBase)) {
1435 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1436 "IOBase 0x%08lX doesn't match any PCI base register.\n",
1437 pNv->pEnt->device->IOBase);
1438 xf86FreeInt10(pNv->pInt);
1442 pNv->IOAddress = pNv->pEnt->device->IOBase;
1445 if (pNv->PciInfo->memBase[0] != 0) {
1446 pNv->IOAddress = pNv->PciInfo->memBase[0] & 0xffffc000;
1449 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1450 "No valid MMIO address in PCI config space\n");
1451 xf86FreeInt10(pNv->pInt);
1456 xf86DrvMsg(pScrn->scrnIndex, from, "MMIO registers at 0x%lX\n",
1457 (unsigned long)pNv->IOAddress);
1459 if (xf86RegisterResources(pNv->pEnt->index, NULL, ResExclusive)) {
1460 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1461 "xf86RegisterResources() found resource conflicts\n");
1462 xf86FreeInt10(pNv->pInt);
1467 switch (pNv->Chipset & 0x0ff0) {
1468 case CHIPSET_NV10: /* GeForce 256 */
1469 case CHIPSET_NV11: /* GeForce2 MX */
1470 case CHIPSET_NV15: /* GeForce2 */
1471 case CHIPSET_NV17: /* GeForce4 MX */
1472 case CHIPSET_NV18: /* GeForce4 MX (8x AGP) */
1473 case CHIPSET_NFORCE: /* nForce */
1474 case CHIPSET_NFORCE2:/* nForce2 */
1475 pNv->Architecture = NV_ARCH_10;
1477 case CHIPSET_NV20: /* GeForce3 */
1478 case CHIPSET_NV25: /* GeForce4 Ti */
1479 case CHIPSET_NV28: /* GeForce4 Ti (8x AGP) */
1480 pNv->Architecture = NV_ARCH_20;
1482 case CHIPSET_NV30: /* GeForceFX 5800 */
1483 case CHIPSET_NV31: /* GeForceFX 5600 */
1484 case CHIPSET_NV34: /* GeForceFX 5200 */
1485 case CHIPSET_NV35: /* GeForceFX 5900 */
1486 case CHIPSET_NV36: /* GeForceFX 5700 */
1487 pNv->Architecture = NV_ARCH_30;
1489 case CHIPSET_NV40: /* GeForce 6800 */
1490 case CHIPSET_NV41: /* GeForce 6800 */
1491 case 0x0120: /* GeForce 6800 */
1492 case CHIPSET_NV43: /* GeForce 6600 */
1493 case CHIPSET_NV44: /* GeForce 6200 */
1494 case CHIPSET_G72: /* GeForce 7200, 7300, 7400 */
1495 case CHIPSET_G70: /* GeForce 7800 */
1496 case CHIPSET_NV45: /* GeForce 6800 */
1497 case CHIPSET_NV44A: /* GeForce 6200 */
1498 case CHIPSET_G71: /* GeForce 7900 */
1499 case CHIPSET_G73: /* GeForce 7600 */
1500 case CHIPSET_C51: /* GeForce 6100 */
1501 case CHIPSET_C512: /* Geforce 6100 (nForce 4xx) */
1502 pNv->Architecture = NV_ARCH_40;
1505 pNv->Architecture = NV_ARCH_04;
1509 pNv->alphaCursor = (pNv->Architecture >= NV_ARCH_10) &&
1510 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10);
1512 NVCommonSetup(pScrn);
1514 pScrn->videoRam = pNv->RamAmountKBytes;
1515 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kBytes\n",
1518 pNv->VRAMPhysicalSize = pScrn->videoRam * 1024;
1521 * If the driver can do gamma correction, it should call xf86SetGamma()
1526 Gamma zeros = {0.0, 0.0, 0.0};
1528 if (!xf86SetGamma(pScrn, zeros)) {
1529 xf86FreeInt10(pNv->pInt);
1535 * Setup the ClockRanges, which describe what clock ranges are available,
1536 * and what sort of modes they can be used for.
1539 clockRanges = xnfcalloc(sizeof(ClockRange), 1);
1540 clockRanges->next = NULL;
1541 clockRanges->minClock = pNv->MinVClockFreqKHz;
1542 clockRanges->maxClock = pNv->MaxVClockFreqKHz;
1543 clockRanges->clockIndex = -1; /* programmable */
1544 clockRanges->doubleScanAllowed = TRUE;
1545 if((pNv->Architecture == NV_ARCH_20) ||
1546 ((pNv->Architecture == NV_ARCH_10) &&
1547 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10) &&
1548 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV15)))
1551 clockRanges->interlaceAllowed = FALSE;
1553 clockRanges->interlaceAllowed = TRUE;
1556 if(pNv->FlatPanel == 1) {
1557 clockRanges->interlaceAllowed = FALSE;
1558 clockRanges->doubleScanAllowed = FALSE;
1561 if(pNv->Architecture < NV_ARCH_10) {
1562 max_width = (pScrn->bitsPerPixel > 16) ? 2032 : 2048;
1565 max_width = (pScrn->bitsPerPixel > 16) ? 4080 : 4096;
1570 * xf86ValidateModes will check that the mode HTotal and VTotal values
1571 * don't exceed the chipset's limit if pScrn->maxHValue and
1572 * pScrn->maxVValue are set. Since our NVValidMode() already takes
1573 * care of this, we don't worry about setting them here.
1575 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
1576 pScrn->display->modes, clockRanges,
1577 NULL, 256, max_width,
1578 512, 128, max_height,
1579 pScrn->display->virtualX,
1580 pScrn->display->virtualY,
1581 pNv->VRAMPhysicalSize / 2,
1582 LOOKUP_BEST_REFRESH);
1585 xf86FreeInt10(pNv->pInt);
1590 /* Prune the modes marked as invalid */
1591 xf86PruneDriverModes(pScrn);
1593 if (i == 0 || pScrn->modes == NULL) {
1594 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n");
1595 xf86FreeInt10(pNv->pInt);
1601 * Set the CRTC parameters for all of the modes based on the type
1602 * of mode, and the chipset's interlace requirements.
1604 * Calling this is required if the mode->Crtc* values are used by the
1605 * driver and if the driver doesn't provide code to set them. They
1606 * are not pre-initialised at all.
1608 xf86SetCrtcForModes(pScrn, 0);
1610 /* Set the current mode to the first in the list */
1611 pScrn->currentMode = pScrn->modes;
1613 /* Print the list of modes being used */
1614 xf86PrintModes(pScrn);
1616 /* Set display resolution */
1617 xf86SetDpi(pScrn, 0, 0);
1621 * XXX This should be taken into account in some way in the mode valdation
1625 if (xf86LoadSubModule(pScrn, "fb") == NULL) {
1626 xf86FreeInt10(pNv->pInt);
1631 xf86LoaderReqSymLists(fbSymbols, NULL);
1633 /* Load XAA if needed */
1634 if (!pNv->NoAccel) {
1635 if (!xf86LoadSubModule(pScrn, pNv->useEXA ? "exa" : "xaa")) {
1636 xf86FreeInt10(pNv->pInt);
1640 xf86LoaderReqSymLists(xaaSymbols, NULL);
1643 /* Load ramdac if needed */
1644 if (pNv->HWCursor) {
1645 if (!xf86LoadSubModule(pScrn, "ramdac")) {
1646 xf86FreeInt10(pNv->pInt);
1650 xf86LoaderReqSymLists(ramdacSymbols, NULL);
1653 /* Load shadowfb if needed */
1654 if (pNv->ShadowFB) {
1655 if (!xf86LoadSubModule(pScrn, "shadowfb")) {
1656 xf86FreeInt10(pNv->pInt);
1660 xf86LoaderReqSymLists(shadowSymbols, NULL);
1663 pNv->CurrentLayout.bitsPerPixel = pScrn->bitsPerPixel;
1664 pNv->CurrentLayout.depth = pScrn->depth;
1665 pNv->CurrentLayout.displayWidth = pScrn->displayWidth;
1666 pNv->CurrentLayout.weight.red = pScrn->weight.red;
1667 pNv->CurrentLayout.weight.green = pScrn->weight.green;
1668 pNv->CurrentLayout.weight.blue = pScrn->weight.blue;
1669 pNv->CurrentLayout.mode = pScrn->currentMode;
1671 xf86FreeInt10(pNv->pInt);
1679 * Map the framebuffer and MMIO memory.
1683 NVMapMem(ScrnInfoPtr pScrn)
1685 NVPtr pNv = NVPTR(pScrn);
1687 pNv->FB = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, pNv->VRAMPhysicalSize/2);
1689 ErrorF("Failed to allocate memory for framebuffer!\n");
1692 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1693 "Allocated %dMiB VRAM for framebuffer + offscreen pixmaps\n",
1697 pNv->Cursor = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, 64*1024);
1699 ErrorF("Failed to allocate memory for hardware cursor\n");
1703 pNv->ScratchBuffer = NVAllocateMemory(pNv, NOUVEAU_MEM_FB,
1704 pNv->Architecture <NV_ARCH_10 ? 8192 : 16384);
1705 if (!pNv->ScratchBuffer) {
1706 ErrorF("Failed to allocate memory for scratch buffer\n");
1714 * Unmap the framebuffer and MMIO memory.
1718 NVUnmapMem(ScrnInfoPtr pScrn)
1720 NVPtr pNv = NVPTR(pScrn);
1722 NVFreeMemory(pNv, pNv->FB);
1723 NVFreeMemory(pNv, pNv->ScratchBuffer);
1724 NVFreeMemory(pNv, pNv->Cursor);
1731 * Initialise a new mode.
1735 NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
1737 vgaHWPtr hwp = VGAHWPTR(pScrn);
1739 NVPtr pNv = NVPTR(pScrn);
1742 /* Initialise the ModeReg values */
1743 if (!vgaHWInit(pScrn, mode))
1745 pScrn->vtSema = TRUE;
1747 vgaReg = &hwp->ModeReg;
1748 nvReg = &pNv->ModeReg;
1750 if(!NVDACInit(pScrn, mode))
1753 NVLockUnlock(pNv, 0);
1755 nvWriteVGA(pNv, 0x44, nvReg->crtcOwner);
1756 NVLockUnlock(pNv, 0);
1759 /* Program the registers */
1760 vgaHWProtect(pScrn, TRUE);
1762 NVDACRestore(pScrn, vgaReg, nvReg, FALSE);
1764 #if X_BYTE_ORDER == X_BIG_ENDIAN
1765 /* turn on LFB swapping */
1769 tmp = nvReadVGA(pNv, 0x46);
1771 nvWriteVGA(pNv, 0x46, tmp);
1775 NVResetGraphics(pScrn);
1777 vgaHWProtect(pScrn, FALSE);
1779 pNv->CurrentLayout.mode = mode;
1785 * Restore the initial (text) mode.
1788 NVRestore(ScrnInfoPtr pScrn)
1790 vgaHWPtr hwp = VGAHWPTR(pScrn);
1791 vgaRegPtr vgaReg = &hwp->SavedReg;
1792 NVPtr pNv = NVPTR(pScrn);
1793 NVRegPtr nvReg = &pNv->SavedReg;
1795 NVLockUnlock(pNv, 0);
1798 nvWriteVGA(pNv, 0x44, pNv->CRTCnumber * 0x3);
1799 NVLockUnlock(pNv, 0);
1802 /* Only restore text mode fonts/text for the primary card */
1803 vgaHWProtect(pScrn, TRUE);
1804 NVDACRestore(pScrn, vgaReg, nvReg, pNv->Primary);
1806 nvWriteVGA(pNv, 0x44, pNv->vtOWNER);
1808 vgaHWProtect(pScrn, FALSE);
1811 static void NVBacklightEnable(NVPtr pNv, Bool on)
1813 /* This is done differently on each laptop. Here we
1814 define the ones we know for sure. */
1816 #if defined(__powerpc__)
1817 if((pNv->Chipset == 0x10DE0179) ||
1818 (pNv->Chipset == 0x10DE0189) ||
1819 (pNv->Chipset == 0x10DE0329))
1821 /* NV17,18,34 Apple iMac, iBook, PowerBook */
1822 CARD32 tmp_pmc, tmp_pcrt;
1823 tmp_pmc = pNv->PMC[0x10F0/4] & 0x7FFFFFFF;
1824 tmp_pcrt = pNv->PCRTC0[0x081C/4] & 0xFFFFFFFC;
1826 tmp_pmc |= (1 << 31);
1829 pNv->PMC[0x10F0/4] = tmp_pmc;
1830 pNv->PCRTC0[0x081C/4] = tmp_pcrt;
1835 if(pNv->twoHeads && ((pNv->Chipset & 0x0ff0) != CHIPSET_NV11)) {
1836 pNv->PMC[0x130C/4] = on ? 3 : 7;
1841 fpcontrol = nvReadCurRAMDAC(pNv, 0x848) & 0xCfffffCC;
1843 /* cut the TMDS output */
1844 if(on) fpcontrol |= pNv->fpSyncs;
1845 else fpcontrol |= 0x20000022;
1847 nvWriteCurRAMDAC(pNv, 0x0848, fpcontrol);
1852 NVDPMSSetLCD(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
1854 NVPtr pNv = NVPTR(pScrn);
1856 if (!pScrn->vtSema) return;
1858 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
1860 switch (PowerManagementMode) {
1861 case DPMSModeStandby: /* HSync: Off, VSync: On */
1862 case DPMSModeSuspend: /* HSync: On, VSync: Off */
1863 case DPMSModeOff: /* HSync: Off, VSync: Off */
1864 NVBacklightEnable(pNv, 0);
1866 case DPMSModeOn: /* HSync: On, VSync: On */
1867 NVBacklightEnable(pNv, 1);
1875 NVDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
1877 unsigned char crtc1A;
1878 vgaHWPtr hwp = VGAHWPTR(pScrn);
1880 if (!pScrn->vtSema) return;
1882 crtc1A = hwp->readCrtc(hwp, 0x1A) & ~0xC0;
1884 switch (PowerManagementMode) {
1885 case DPMSModeStandby: /* HSync: Off, VSync: On */
1888 case DPMSModeSuspend: /* HSync: On, VSync: Off */
1891 case DPMSModeOff: /* HSync: Off, VSync: Off */
1894 case DPMSModeOn: /* HSync: On, VSync: On */
1899 /* vgaHWDPMSSet will merely cut the dac output */
1900 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
1902 hwp->writeCrtc(hwp, 0x1A, crtc1A);
1908 /* This gets called at the start of each server generation */
1911 NVScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
1918 unsigned char *FBStart;
1919 int width, height, displayWidth, offscreenHeight, shadowHeight;
1923 * First get the ScrnInfoRec
1925 pScrn = xf86Screens[pScreen->myNum];
1927 hwp = VGAHWPTR(pScrn);
1930 /* Map the VGA memory when the primary video */
1932 hwp->MapSize = 0x10000;
1933 if (!vgaHWMapMem(pScrn))
1937 /* Init DRM - Alloc FIFO, setup graphics objects */
1938 if (!NVInitDma(pScrn))
1941 /* Allocate and map memory areas we need */
1942 if (!NVMapMem(pScrn)) {
1946 /* Save the current state */
1948 /* Initialise the first mode */
1949 if (!NVModeInit(pScrn, pScrn->currentMode)) {
1953 /* Darken the screen for aesthetic reasons and set the viewport */
1954 NVSaveScreen(pScreen, SCREEN_SAVER_ON);
1955 pScrn->AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
1958 * The next step is to setup the screen's visuals, and initialise the
1959 * framebuffer code. In cases where the framebuffer's default
1960 * choices for things like visual layouts and bits per RGB are OK,
1961 * this may be as simple as calling the framebuffer's ScreenInit()
1962 * function. If not, the visuals will need to be setup before calling
1963 * a fb ScreenInit() function and fixed up after.
1965 * For most PC hardware at depths >= 8, the defaults that fb uses
1966 * are not appropriate. In this driver, we fixup the visuals after.
1970 * Reset the visual list.
1972 miClearVisualTypes();
1974 /* Setup the visuals we support. */
1976 if (!miSetVisualTypes(pScrn->depth,
1977 miGetDefaultVisualMask(pScrn->depth), 8,
1978 pScrn->defaultVisual))
1980 if (!miSetPixmapDepths ()) return FALSE;
1983 * Call the framebuffer layer's ScreenInit function, and fill in other
1987 width = pScrn->virtualX;
1988 height = pScrn->virtualY;
1989 displayWidth = pScrn->displayWidth;
1993 height = pScrn->virtualX;
1994 width = pScrn->virtualY;
1997 /* If RandR rotation is enabled, leave enough space in the
1998 * framebuffer for us to rotate the screen dimensions without
1999 * changing the pitch.
2001 if(pNv->RandRRotation)
2002 shadowHeight = max(width, height);
2004 shadowHeight = height;
2007 pNv->ShadowPitch = BitmapBytePad(pScrn->bitsPerPixel * width);
2008 pNv->ShadowPtr = xalloc(pNv->ShadowPitch * shadowHeight);
2009 displayWidth = pNv->ShadowPitch / (pScrn->bitsPerPixel >> 3);
2010 FBStart = pNv->ShadowPtr;
2012 pNv->ShadowPtr = NULL;
2013 FBStart = pNv->FB->map;
2016 switch (pScrn->bitsPerPixel) {
2020 ret = fbScreenInit(pScreen, FBStart, width, height,
2021 pScrn->xDpi, pScrn->yDpi,
2022 displayWidth, pScrn->bitsPerPixel);
2025 xf86DrvMsg(scrnIndex, X_ERROR,
2026 "Internal error: invalid bpp (%d) in NVScreenInit\n",
2027 pScrn->bitsPerPixel);
2034 if (pScrn->bitsPerPixel > 8) {
2035 /* Fixup RGB ordering */
2036 visual = pScreen->visuals + pScreen->numVisuals;
2037 while (--visual >= pScreen->visuals) {
2038 if ((visual->class | DynamicClass) == DirectColor) {
2039 visual->offsetRed = pScrn->offset.red;
2040 visual->offsetGreen = pScrn->offset.green;
2041 visual->offsetBlue = pScrn->offset.blue;
2042 visual->redMask = pScrn->mask.red;
2043 visual->greenMask = pScrn->mask.green;
2044 visual->blueMask = pScrn->mask.blue;
2049 fbPictureInit (pScreen, 0, 0);
2051 xf86SetBlackWhitePixels(pScreen);
2053 offscreenHeight = pNv->FB->size /
2054 (pScrn->displayWidth * pScrn->bitsPerPixel >> 3);
2055 if(offscreenHeight > 32767)
2056 offscreenHeight = 32767;
2061 AvailFBArea.x2 = pScrn->displayWidth;
2062 AvailFBArea.y2 = offscreenHeight;
2063 xf86InitFBManager(pScreen, &AvailFBArea);
2066 if (!pNv->NoAccel) {
2072 NVResetGraphics(pScrn);
2074 miInitializeBackingStore(pScreen);
2075 xf86SetBackingStore(pScreen);
2076 xf86SetSilkenMouse(pScreen);
2078 /* Initialize software cursor.
2079 Must precede creation of the default colormap */
2080 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
2082 /* Initialize HW cursor layer.
2083 Must follow software cursor initialization*/
2084 if (pNv->HWCursor) {
2085 if(!NVCursorInit(pScreen))
2086 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2087 "Hardware cursor initialization failed\n");
2090 /* Initialise default colourmap */
2091 if (!miCreateDefColormap(pScreen))
2094 /* Initialize colormap layer.
2095 Must follow initialization of the default colormap */
2096 if(!xf86HandleColormaps(pScreen, 256, 8, NVDACLoadPalette,
2097 NULL, CMAP_RELOAD_ON_MODE_SWITCH | CMAP_PALETTED_TRUECOLOR))
2101 RefreshAreaFuncPtr refreshArea = NVRefreshArea;
2103 if(pNv->Rotate || pNv->RandRRotation) {
2104 pNv->PointerMoved = pScrn->PointerMoved;
2106 pScrn->PointerMoved = NVPointerMoved;
2108 switch(pScrn->bitsPerPixel) {
2109 case 8: refreshArea = NVRefreshArea8; break;
2110 case 16: refreshArea = NVRefreshArea16; break;
2111 case 32: refreshArea = NVRefreshArea32; break;
2113 if(!pNv->RandRRotation) {
2115 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2116 "Driver rotation enabled, RandR disabled\n");
2120 ShadowFBInit(pScreen, refreshArea);
2124 xf86DPMSInit(pScreen, NVDPMSSetLCD, 0);
2126 xf86DPMSInit(pScreen, NVDPMSSet, 0);
2128 pScrn->memPhysBase = pNv->VRAMPhysical;
2129 pScrn->fbOffset = 0;
2131 if(pNv->Rotate == 0 && !pNv->RandRRotation)
2132 NVInitVideo(pScreen);
2134 pScreen->SaveScreen = NVSaveScreen;
2136 /* Wrap the current CloseScreen function */
2137 pNv->CloseScreen = pScreen->CloseScreen;
2138 pScreen->CloseScreen = NVCloseScreen;
2140 pNv->BlockHandler = pScreen->BlockHandler;
2141 pScreen->BlockHandler = NVBlockHandler;
2144 /* Install our DriverFunc. We have to do it this way instead of using the
2145 * HaveDriverFuncs argument to xf86AddDriver, because InitOutput clobbers
2146 * pScrn->DriverFunc */
2147 pScrn->DriverFunc = NVDriverFunc;
2150 /* Report any unused options (only for the first generation) */
2151 if (serverGeneration == 1) {
2152 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
2158 NVSaveScreen(ScreenPtr pScreen, int mode)
2160 return vgaHWSaveScreen(pScreen, mode);
2164 NVSave(ScrnInfoPtr pScrn)
2166 NVPtr pNv = NVPTR(pScrn);
2167 NVRegPtr nvReg = &pNv->SavedReg;
2168 vgaHWPtr pVga = VGAHWPTR(pScrn);
2169 vgaRegPtr vgaReg = &pVga->SavedReg;
2171 NVLockUnlock(pNv, 0);
2173 nvWriteVGA(pNv, 0x44, pNv->CRTCnumber * 0x3);
2174 NVLockUnlock(pNv, 0);
2177 NVDACSave(pScrn, vgaReg, nvReg, pNv->Primary);
2182 NVRandRGetInfo(ScrnInfoPtr pScrn, Rotation *rotations)
2184 NVPtr pNv = NVPTR(pScrn);
2186 if(pNv->RandRRotation)
2187 *rotations = RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_270;
2189 *rotations = RR_Rotate_0;
2195 NVRandRSetConfig(ScrnInfoPtr pScrn, xorgRRConfig *config)
2197 NVPtr pNv = NVPTR(pScrn);
2199 switch(config->rotation) {
2202 pScrn->PointerMoved = pNv->PointerMoved;
2207 pScrn->PointerMoved = NVPointerMoved;
2212 pScrn->PointerMoved = NVPointerMoved;
2216 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2217 "Unexpected rotation in NVRandRSetConfig!\n");
2219 pScrn->PointerMoved = pNv->PointerMoved;
2227 NVDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer data)
2231 return NVRandRGetInfo(pScrn, (Rotation*)data);
2233 return NVRandRSetConfig(pScrn, (xorgRRConfig*)data);