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(nouveauSetup);
474 static XF86ModuleVersionInfo nouveauVersRec =
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 nouveauModuleData = { &nouveauVersRec, nouveauSetup, NULL };
492 * This is intentionally screen-independent. It indicates the binding
493 * choice made in the first PreInit.
495 static int pix24bpp = 0;
497 NVAllocRec *NVAllocateMemory(NVPtr pNv, int type, int size)
499 drm_nouveau_mem_alloc_t memalloc;
502 mem = malloc(sizeof(NVAllocRec));
505 mem->type = type | NOUVEAU_MEM_MAPPED;
508 memalloc.flags = mem->type;
509 memalloc.size = mem->size;
510 memalloc.alignment = 0;
511 memalloc.region_offset = &mem->offset;
512 if (drmCommandWriteRead(pNv->drm_fd, DRM_NOUVEAU_MEM_ALLOC, &memalloc,
514 ErrorF("NOUVEAU_MEM_ALLOC failed. flags=0x%08x, size=%d (%d)\n",
515 mem->type, mem->size, errno);
520 if (drmMap(pNv->drm_fd, mem->offset, mem->size, &mem->map)) {
521 ErrorF("drmMap() failed. offset=0x%llx, size=%d (%d)\n",
522 mem->offset, mem->size, errno);
524 NVFreeMemory(pNv, mem);
531 void NVFreeMemory(NVPtr pNv, NVAllocRec *mem)
533 drm_nouveau_mem_free_t memfree;
537 if (drmUnmap(mem->map, mem->size))
538 ErrorF("drmUnmap() failed. map=%p, size=%d\n", mem->map, mem->size);
541 memfree.flags = mem->type;
542 memfree.region_offset = mem->offset;
543 if (drmCommandWriteRead(pNv->drm_fd, DRM_NOUVEAU_MEM_FREE, &memfree,
545 ErrorF("NOUVEAU_MEM_FREE failed. flags=0x%08x, offset=0x%llx (%d)\n",
546 mem->type, mem->size, errno);
553 NVGetRec(ScrnInfoPtr pScrn)
556 * Allocate an NVRec, and hook it into pScrn->driverPrivate.
557 * pScrn->driverPrivate is initialised to NULL, so we can check if
558 * the allocation has already been done.
560 if (pScrn->driverPrivate != NULL)
563 pScrn->driverPrivate = xnfcalloc(sizeof(NVRec), 1);
570 NVFreeRec(ScrnInfoPtr pScrn)
572 if (pScrn->driverPrivate == NULL)
574 xfree(pScrn->driverPrivate);
575 pScrn->driverPrivate = NULL;
580 nouveauSetup(pointer module, pointer opts, int *errmaj, int *errmin)
582 static Bool setupDone = FALSE;
584 /* This module should be loaded only once, but check to be sure. */
588 xf86AddDriver(&NV, module, 0);
591 * Modules that this driver always requires may be loaded here
592 * by calling LoadSubModule().
595 * Tell the loader about symbols from other modules that this module
598 LoaderRefSymLists(vgahwSymbols, xaaSymbols, exaSymbols, fbSymbols,
602 ramdacSymbols, shadowSymbols, rivaSymbols,
603 i2cSymbols, ddcSymbols, vbeSymbols,
607 * The return value must be non-NULL on success even though there
608 * is no TearDownProc.
612 if (errmaj) *errmaj = LDR_ONCEONLY;
617 static const OptionInfoRec *
618 NVAvailableOptions(int chipid, int busid)
620 if(chipid == 0x12D20018) {
621 if (!xf86LoadOneModule("riva128", NULL)) {
624 return RivaAvailableOptions(chipid, busid);
632 NVIdentify(int flags)
634 xf86PrintChipsets(NV_NAME, "driver for NVIDIA chipsets", NVKnownChipsets);
639 NVGetScrnInfoRec(PciChipsets *chips, int chip)
643 pScrn = xf86ConfigPciEntity(NULL, 0, chip,
644 chips, NULL, NULL, NULL,
647 if(!pScrn) return FALSE;
649 pScrn->driverVersion = NV_VERSION;
650 pScrn->driverName = NV_DRIVER_NAME;
651 pScrn->name = NV_NAME;
653 pScrn->Probe = NVProbe;
654 pScrn->PreInit = NVPreInit;
655 pScrn->ScreenInit = NVScreenInit;
656 pScrn->SwitchMode = NVSwitchMode;
657 pScrn->AdjustFrame = NVAdjustFrame;
658 pScrn->EnterVT = NVEnterVT;
659 pScrn->LeaveVT = NVLeaveVT;
660 pScrn->FreeScreen = NVFreeScreen;
661 pScrn->ValidMode = NVValidMode;
666 #define MAX_CHIPS MAXSCREENS
670 NVGetPCIXpressChip (pciVideoPtr pVideo)
672 volatile CARD32 *regs;
673 CARD32 pciid, pcicmd;
674 PCITAG Tag = ((pciConfigPtr)(pVideo->thisCard))->tag;
676 pcicmd = pciReadLong(Tag, PCI_CMD_STAT_REG);
677 pciWriteLong(Tag, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
679 regs = xf86MapPciMem(-1, VIDMEM_MMIO, Tag, pVideo->memBase[0], 0x2000);
681 pciid = regs[0x1800/4];
683 xf86UnMapVidMem(-1, (pointer)regs, 0x2000);
685 pciWriteLong(Tag, PCI_CMD_STAT_REG, pcicmd);
687 if((pciid & 0x0000ffff) == 0x000010DE)
688 pciid = 0x10DE0000 | (pciid >> 16);
690 if((pciid & 0xffff0000) == 0xDE100000) /* wrong endian */
691 pciid = 0x10DE0000 | ((pciid << 8) & 0x0000ff00) |
692 ((pciid >> 8) & 0x000000ff);
700 NVProbe(DriverPtr drv, int flags)
703 GDevPtr *devSections;
705 SymTabRec NVChipsets[MAX_CHIPS + 1];
706 PciChipsets NVPciChipsets[MAX_CHIPS + 1];
710 Bool foundScreen = FALSE;
713 if ((numDevSections = xf86MatchDevice(NV_DRIVER_NAME, &devSections)) <= 0)
714 return FALSE; /* no matching device section */
716 if (!(ppPci = xf86GetPciVideoInfo()))
717 return FALSE; /* no PCI cards found */
721 /* Create the NVChipsets and NVPciChipsets from found devices */
722 while (*ppPci && (numUsed < MAX_CHIPS)) {
723 if(((*ppPci)->vendor == PCI_VENDOR_NVIDIA_SGS) ||
724 ((*ppPci)->vendor == PCI_VENDOR_NVIDIA))
726 SymTabRec *nvchips = NVKnownChipsets;
727 int pciid = ((*ppPci)->vendor << 16) | (*ppPci)->chipType;
730 if(((token & 0xfff0) == CHIPSET_MISC_BRIDGED) ||
731 ((token & 0xfff0) == CHIPSET_G73_BRIDGED))
733 token = NVGetPCIXpressChip(*ppPci);
736 while(nvchips->name) {
737 if(token == nvchips->token)
742 if(nvchips->name) { /* found one */
743 NVChipsets[numUsed].token = pciid;
744 NVChipsets[numUsed].name = nvchips->name;
745 NVPciChipsets[numUsed].numChipset = pciid;
746 NVPciChipsets[numUsed].PCIid = pciid;
747 NVPciChipsets[numUsed].resList = RES_SHARED_VGA;
749 } else if ((*ppPci)->vendor == PCI_VENDOR_NVIDIA) {
750 /* look for a compatible devices which may be newer than
751 the NVKnownChipsets list above. */
752 switch(token & 0xfff0) {
776 NVChipsets[numUsed].token = pciid;
777 NVChipsets[numUsed].name = "Unknown NVIDIA chip";
778 NVPciChipsets[numUsed].numChipset = pciid;
779 NVPciChipsets[numUsed].PCIid = pciid;
780 NVPciChipsets[numUsed].resList = RES_SHARED_VGA;
783 default: break; /* we don't recognize it */
790 /* terminate the list */
791 NVChipsets[numUsed].token = -1;
792 NVChipsets[numUsed].name = NULL;
793 NVPciChipsets[numUsed].numChipset = -1;
794 NVPciChipsets[numUsed].PCIid = -1;
795 NVPciChipsets[numUsed].resList = RES_UNDEFINED;
797 numUsed = xf86MatchPciInstances(NV_NAME, 0, NVChipsets, NVPciChipsets,
798 devSections, numDevSections, drv,
804 if (flags & PROBE_DETECT)
806 else for (i = 0; i < numUsed; i++) {
809 pPci = xf86GetPciInfoForEntity(usedChips[i]);
810 if(pPci->vendor == PCI_VENDOR_NVIDIA_SGS) {
811 if (!xf86LoadDrvSubModule(drv, "riva128")) {
814 xf86LoaderReqSymLists(rivaSymbols, NULL);
815 if(RivaGetScrnInfoRec(NVPciChipsets, usedChips[i]))
818 if(NVGetScrnInfoRec(NVPciChipsets, usedChips[i]))
829 /* Usually mandatory */
831 NVSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
833 return NVModeInit(xf86Screens[scrnIndex], mode);
837 * This function is used to initialize the Start Address - the first
838 * displayed location in the video memory.
840 /* Usually mandatory */
842 NVAdjustFrame(int scrnIndex, int x, int y, int flags)
844 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
846 NVPtr pNv = NVPTR(pScrn);
847 NVFBLayout *pLayout = &pNv->CurrentLayout;
849 startAddr = (((y*pLayout->displayWidth)+x)*(pLayout->bitsPerPixel/8));
850 startAddr += (pNv->FB->offset - pNv->VRAMPhysical);
851 NVSetStartAddress(pNv, startAddr);
856 * This is called when VT switching back to the X server. Its job is
857 * to reinitialise the video mode.
859 * We may wish to unmap video/MMIO memory too.
864 NVEnterVT(int scrnIndex, int flags)
866 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
867 NVPtr pNv = NVPTR(pScrn);
869 if (!NVModeInit(pScrn, pScrn->currentMode))
871 NVAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
873 if(pNv->overlayAdaptor)
879 * This is called when VT switching away from the X server. Its job is
880 * to restore the previous (text) mode.
882 * We may wish to remap video/MMIO memory too.
887 NVLeaveVT(int scrnIndex, int flags)
889 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
890 NVPtr pNv = NVPTR(pScrn);
894 NVLockUnlock(pNv, 1);
907 ScreenPtr pScreen = screenInfo.screens[i];
908 ScrnInfoPtr pScrnInfo = xf86Screens[i];
909 NVPtr pNv = NVPTR(pScrnInfo);
911 if (pNv->DMAKickoffCallback)
912 (*pNv->DMAKickoffCallback)(pNv);
914 pScreen->BlockHandler = pNv->BlockHandler;
915 (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
916 pScreen->BlockHandler = NVBlockHandler;
918 if (pNv->VideoTimerCallback)
919 (*pNv->VideoTimerCallback)(pScrnInfo, currentTime.milliseconds);
925 * This is called at the end of each server generation. It restores the
926 * original (text) mode. It should also unmap the video memory, and free
927 * any per-generation data allocated by the driver. It should finish
928 * by unwrapping and calling the saved CloseScreen function.
933 NVCloseScreen(int scrnIndex, ScreenPtr pScreen)
935 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
936 NVPtr pNv = NVPTR(pScrn);
941 NVLockUnlock(pNv, 1);
945 vgaHWUnmapMem(pScrn);
946 if (pNv->AccelInfoRec)
947 XAADestroyInfoRec(pNv->AccelInfoRec);
948 if (pNv->CursorInfoRec)
949 xf86DestroyCursorInfoRec(pNv->CursorInfoRec);
951 xfree(pNv->ShadowPtr);
952 if (pNv->overlayAdaptor)
953 xfree(pNv->overlayAdaptor);
954 if (pNv->blitAdaptor)
955 xfree(pNv->blitAdaptor);
957 pScrn->vtSema = FALSE;
958 pScreen->CloseScreen = pNv->CloseScreen;
959 pScreen->BlockHandler = pNv->BlockHandler;
960 return (*pScreen->CloseScreen)(scrnIndex, pScreen);
963 /* Free up any persistent data structures */
967 NVFreeScreen(int scrnIndex, int flags)
970 * This only gets called when a screen is being deleted. It does not
971 * get called routinely at the end of a server generation.
973 if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
974 vgaHWFreeHWRec(xf86Screens[scrnIndex]);
975 NVFreeRec(xf86Screens[scrnIndex]);
979 /* Checks if a mode is suitable for the selected chipset. */
983 NVValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
985 NVPtr pNv = NVPTR(xf86Screens[scrnIndex]);
987 if(pNv->fpWidth && pNv->fpHeight)
988 if((pNv->fpWidth < mode->HDisplay) || (pNv->fpHeight < mode->VDisplay))
995 nvProbeDDC(ScrnInfoPtr pScrn, int index)
999 if (xf86LoadSubModule(pScrn, "vbe")) {
1000 pVbe = VBEInit(NULL,index);
1001 ConfiguredMonitor = vbeDoEDID(pVbe, NULL);
1007 Bool NVI2CInit(ScrnInfoPtr pScrn)
1011 if (xf86LoadSubModule(pScrn, mod)) {
1012 xf86LoaderReqSymLists(i2cSymbols,NULL);
1015 if(xf86LoadSubModule(pScrn, mod)) {
1016 xf86LoaderReqSymLists(ddcSymbols, NULL);
1017 return NVDACi2cInit(pScrn);
1021 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
1022 "Couldn't load %s module. DDC probing can't be done\n", mod);
1029 NVPreInit(ScrnInfoPtr pScrn, int flags)
1033 int i, max_width, max_height;
1034 ClockRangePtr clockRanges;
1037 if (flags & PROBE_DETECT) {
1038 EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1046 nvProbeDDC(pScrn, i);
1051 * Note: This function is only called once at server startup, and
1052 * not at the start of each server generation. This means that
1053 * only things that are persistent across server generations can
1054 * be initialised here. xf86Screens[] is (pScrn is a pointer to one
1055 * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex()
1056 * are too, and should be used for data that must persist across
1057 * server generations.
1059 * Per-generation data should be allocated with
1060 * AllocateScreenPrivateIndex() from the ScreenInit() function.
1063 /* Check the number of entities, and fail if it isn't one. */
1064 if (pScrn->numEntities != 1)
1067 /* Allocate the NVRec driverPrivate */
1068 if (!NVGetRec(pScrn)) {
1073 /* Get the entity, and make sure it is PCI. */
1074 pNv->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1075 if (pNv->pEnt->location.type != BUS_PCI)
1078 /* Find the PCI info for this screen */
1079 pNv->PciInfo = xf86GetPciInfoForEntity(pNv->pEnt->index);
1080 pNv->PciTag = pciTag(pNv->PciInfo->bus, pNv->PciInfo->device,
1081 pNv->PciInfo->func);
1083 pNv->Primary = xf86IsPrimaryPci(pNv->PciInfo);
1085 /* Initialize the card through int10 interface if needed */
1086 if (xf86LoadSubModule(pScrn, "int10")) {
1087 xf86LoaderReqSymLists(int10Symbols, NULL);
1088 #if !defined(__alpha__) && !defined(__powerpc__)
1089 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initializing int10\n");
1090 pNv->pInt = xf86InitInt10(pNv->pEnt->index);
1094 xf86SetOperatingState(resVgaIo, pNv->pEnt->index, ResUnusedOpr);
1095 xf86SetOperatingState(resVgaMem, pNv->pEnt->index, ResDisableOpr);
1097 /* Set pScrn->monitor */
1098 pScrn->monitor = pScrn->confScreen->monitor;
1101 * Set the Chipset and ChipRev, allowing config file entries to
1104 if (pNv->pEnt->device->chipset && *pNv->pEnt->device->chipset) {
1105 pScrn->chipset = pNv->pEnt->device->chipset;
1106 pNv->Chipset = xf86StringToToken(NVKnownChipsets, pScrn->chipset);
1108 } else if (pNv->pEnt->device->chipID >= 0) {
1109 pNv->Chipset = pNv->pEnt->device->chipID;
1110 pScrn->chipset = (char *)xf86TokenToString(NVKnownChipsets,
1113 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipID override: 0x%04X\n",
1117 pNv->Chipset = (pNv->PciInfo->vendor << 16) | pNv->PciInfo->chipType;
1119 if(((pNv->Chipset & 0xfff0) == CHIPSET_MISC_BRIDGED) ||
1120 ((pNv->Chipset & 0xfff0) == CHIPSET_G73_BRIDGED))
1122 pNv->Chipset = NVGetPCIXpressChip(pNv->PciInfo);
1125 pScrn->chipset = (char *)xf86TokenToString(NVKnownChipsets,
1128 pScrn->chipset = "Unknown NVIDIA chipset";
1131 if (pNv->pEnt->device->chipRev >= 0) {
1132 pNv->ChipRev = pNv->pEnt->device->chipRev;
1133 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
1136 pNv->ChipRev = pNv->PciInfo->chipRev;
1140 * This shouldn't happen because such problems should be caught in
1141 * NVProbe(), but check it just in case.
1143 if (pScrn->chipset == NULL) {
1144 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1145 "ChipID 0x%04X is not recognised\n", pNv->Chipset);
1146 xf86FreeInt10(pNv->pInt);
1149 if (pNv->Chipset < 0) {
1150 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1151 "Chipset \"%s\" is not recognised\n", pScrn->chipset);
1152 xf86FreeInt10(pNv->pInt);
1156 xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n", pScrn->chipset);
1160 * The first thing we should figure out is the depth, bpp, etc.
1163 if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support32bppFb)) {
1164 xf86FreeInt10(pNv->pInt);
1167 /* Check that the returned depth is one we support */
1168 switch (pScrn->depth) {
1176 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1177 "Given depth (%d) is not supported by this driver\n",
1179 xf86FreeInt10(pNv->pInt);
1183 xf86PrintDepthBpp(pScrn);
1185 /* Get the depth24 pixmap format */
1186 if (pScrn->depth == 24 && pix24bpp == 0)
1187 pix24bpp = xf86GetBppFromDepth(pScrn, 24);
1190 * This must happen after pScrn->display has been set because
1191 * xf86SetWeight references it.
1193 if (pScrn->depth > 8) {
1194 /* The defaults are OK for us */
1195 rgb zeros = {0, 0, 0};
1197 if (!xf86SetWeight(pScrn, zeros, zeros)) {
1198 xf86FreeInt10(pNv->pInt);
1203 if (!xf86SetDefaultVisual(pScrn, -1)) {
1204 xf86FreeInt10(pNv->pInt);
1207 /* We don't currently support DirectColor at > 8bpp */
1208 if (pScrn->depth > 8 && (pScrn->defaultVisual != TrueColor)) {
1209 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual"
1210 " (%s) is not supported at depth %d\n",
1211 xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
1212 xf86FreeInt10(pNv->pInt);
1217 /* The vgahw module should be loaded here when needed */
1218 if (!xf86LoadSubModule(pScrn, "vgahw")) {
1219 xf86FreeInt10(pNv->pInt);
1223 xf86LoaderReqSymLists(vgahwSymbols, NULL);
1226 * Allocate a vgaHWRec
1228 if (!vgaHWGetHWRec(pScrn)) {
1229 xf86FreeInt10(pNv->pInt);
1233 /* We use a programmable clock */
1234 pScrn->progClock = TRUE;
1236 /* Collect all of the relevant option flags (fill in pScrn->options) */
1237 xf86CollectOptions(pScrn, NULL);
1239 /* Process the options */
1240 if (!(pNv->Options = xalloc(sizeof(NVOptions))))
1242 memcpy(pNv->Options, NVOptions, sizeof(NVOptions));
1243 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pNv->Options);
1245 /* Set the bits per RGB for 8bpp mode */
1246 if (pScrn->depth == 8)
1250 pNv->HWCursor = TRUE;
1252 * The preferred method is to use the "hw cursor" option as a tri-state
1253 * option, with the default set above.
1255 if (xf86GetOptValBool(pNv->Options, OPTION_HW_CURSOR, &pNv->HWCursor)) {
1258 /* For compatibility, accept this too (as an override) */
1259 if (xf86ReturnOptValBool(pNv->Options, OPTION_SW_CURSOR, FALSE)) {
1261 pNv->HWCursor = FALSE;
1263 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
1264 pNv->HWCursor ? "HW" : "SW");
1266 pNv->FpScale = TRUE;
1267 if (xf86GetOptValBool(pNv->Options, OPTION_FP_SCALE, &pNv->FpScale)) {
1268 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Flat panel scaling %s\n",
1269 pNv->FpScale ? "on" : "off");
1271 if (xf86ReturnOptValBool(pNv->Options, OPTION_NOACCEL, FALSE)) {
1272 pNv->NoAccel = TRUE;
1273 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1275 if (xf86ReturnOptValBool(pNv->Options, OPTION_SHADOW_FB, FALSE)) {
1276 pNv->ShadowFB = TRUE;
1277 pNv->NoAccel = TRUE;
1278 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1279 "Using \"Shadow Framebuffer\" - acceleration disabled\n");
1281 if (!pNv->NoAccel) {
1284 if((s = (char *)xf86GetOptValString(pNv->Options, OPTION_ACCELMETHOD))) {
1285 if(!xf86NameCmp(s,"XAA")) {
1287 pNv->useEXA = FALSE;
1288 } else if(!xf86NameCmp(s,"EXA")) {
1293 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s acceleration method\n", pNv->useEXA ? "EXA" : "XAA");
1295 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1299 pNv->RandRRotation = FALSE;
1300 if ((s = xf86GetOptValString(pNv->Options, OPTION_ROTATE))) {
1301 if(!xf86NameCmp(s, "CW")) {
1302 pNv->ShadowFB = TRUE;
1303 pNv->NoAccel = TRUE;
1304 pNv->HWCursor = FALSE;
1306 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1307 "Rotating screen clockwise - acceleration disabled\n");
1309 if(!xf86NameCmp(s, "CCW")) {
1310 pNv->ShadowFB = TRUE;
1311 pNv->NoAccel = TRUE;
1312 pNv->HWCursor = FALSE;
1314 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1315 "Rotating screen counter clockwise - acceleration disabled\n");
1317 if(!xf86NameCmp(s, "RandR")) {
1319 pNv->ShadowFB = TRUE;
1320 pNv->NoAccel = TRUE;
1321 pNv->HWCursor = FALSE;
1322 pNv->RandRRotation = TRUE;
1323 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1324 "Using RandR rotation - acceleration disabled\n");
1326 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
1327 "This driver was not compiled with support for the Resize and "
1328 "Rotate extension. Cannot honor 'Option \"Rotate\" "
1332 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1333 "\"%s\" is not a valid value for Option \"Rotate\"\n", s);
1334 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1335 "Valid options are \"CW\", \"CCW\", and \"RandR\"\n");
1339 if(xf86GetOptValInteger(pNv->Options, OPTION_VIDEO_KEY, &(pNv->videoKey))) {
1340 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n",
1343 pNv->videoKey = (1 << pScrn->offset.red) |
1344 (1 << pScrn->offset.green) |
1345 (((pScrn->mask.blue >> pScrn->offset.blue) - 1) << pScrn->offset.blue);
1348 if (xf86GetOptValBool(pNv->Options, OPTION_FLAT_PANEL, &(pNv->FlatPanel))) {
1349 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "forcing %s usage\n",
1350 pNv->FlatPanel ? "DFP" : "CRTC");
1352 pNv->FlatPanel = -1; /* autodetect later */
1355 pNv->FPDither = FALSE;
1356 if (xf86GetOptValBool(pNv->Options, OPTION_FP_DITHER, &(pNv->FPDither)))
1357 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "enabling flat panel dither\n");
1359 if (xf86GetOptValInteger(pNv->Options, OPTION_CRTC_NUMBER,
1362 if((pNv->CRTCnumber < 0) || (pNv->CRTCnumber > 1)) {
1363 pNv->CRTCnumber = -1;
1364 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1365 "Invalid CRTC number. Must be 0 or 1\n");
1368 pNv->CRTCnumber = -1; /* autodetect later */
1372 if (xf86GetOptValInteger(pNv->Options, OPTION_FP_TWEAK,
1375 pNv->usePanelTweak = TRUE;
1377 pNv->usePanelTweak = FALSE;
1380 if (pNv->pEnt->device->MemBase != 0) {
1381 /* Require that the config file value matches one of the PCI values. */
1382 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->MemBase)) {
1383 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1384 "MemBase 0x%08lX doesn't match any PCI base register.\n",
1385 pNv->pEnt->device->MemBase);
1386 xf86FreeInt10(pNv->pInt);
1390 pNv->VRAMPhysical = pNv->pEnt->device->MemBase;
1393 if (pNv->PciInfo->memBase[1] != 0) {
1394 pNv->VRAMPhysical = pNv->PciInfo->memBase[1] & 0xff800000;
1397 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1398 "No valid FB address in PCI config space\n");
1399 xf86FreeInt10(pNv->pInt);
1404 xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
1405 (unsigned long)pNv->VRAMPhysical);
1407 if (pNv->pEnt->device->IOBase != 0) {
1408 /* Require that the config file value matches one of the PCI values. */
1409 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->IOBase)) {
1410 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1411 "IOBase 0x%08lX doesn't match any PCI base register.\n",
1412 pNv->pEnt->device->IOBase);
1413 xf86FreeInt10(pNv->pInt);
1417 pNv->IOAddress = pNv->pEnt->device->IOBase;
1420 if (pNv->PciInfo->memBase[0] != 0) {
1421 pNv->IOAddress = pNv->PciInfo->memBase[0] & 0xffffc000;
1424 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1425 "No valid MMIO address in PCI config space\n");
1426 xf86FreeInt10(pNv->pInt);
1431 xf86DrvMsg(pScrn->scrnIndex, from, "MMIO registers at 0x%lX\n",
1432 (unsigned long)pNv->IOAddress);
1434 if (xf86RegisterResources(pNv->pEnt->index, NULL, ResExclusive)) {
1435 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1436 "xf86RegisterResources() found resource conflicts\n");
1437 xf86FreeInt10(pNv->pInt);
1442 switch (pNv->Chipset & 0x0ff0) {
1443 case CHIPSET_NV10: /* GeForce 256 */
1444 case CHIPSET_NV11: /* GeForce2 MX */
1445 case CHIPSET_NV15: /* GeForce2 */
1446 case CHIPSET_NV17: /* GeForce4 MX */
1447 case CHIPSET_NV18: /* GeForce4 MX (8x AGP) */
1448 case CHIPSET_NFORCE: /* nForce */
1449 case CHIPSET_NFORCE2:/* nForce2 */
1450 pNv->Architecture = NV_ARCH_10;
1452 case CHIPSET_NV20: /* GeForce3 */
1453 case CHIPSET_NV25: /* GeForce4 Ti */
1454 case CHIPSET_NV28: /* GeForce4 Ti (8x AGP) */
1455 pNv->Architecture = NV_ARCH_20;
1457 case CHIPSET_NV30: /* GeForceFX 5800 */
1458 case CHIPSET_NV31: /* GeForceFX 5600 */
1459 case CHIPSET_NV34: /* GeForceFX 5200 */
1460 case CHIPSET_NV35: /* GeForceFX 5900 */
1461 case CHIPSET_NV36: /* GeForceFX 5700 */
1462 pNv->Architecture = NV_ARCH_30;
1464 case CHIPSET_NV40: /* GeForce 6800 */
1465 case CHIPSET_NV41: /* GeForce 6800 */
1466 case 0x0120: /* GeForce 6800 */
1467 case CHIPSET_NV43: /* GeForce 6600 */
1468 case CHIPSET_NV44: /* GeForce 6200 */
1469 case CHIPSET_G72: /* GeForce 7200, 7300, 7400 */
1470 case CHIPSET_G70: /* GeForce 7800 */
1471 case CHIPSET_NV45: /* GeForce 6800 */
1472 case CHIPSET_NV44A: /* GeForce 6200 */
1473 case CHIPSET_G71: /* GeForce 7900 */
1474 case CHIPSET_G73: /* GeForce 7600 */
1475 case CHIPSET_C51: /* GeForce 6100 */
1476 case CHIPSET_C512: /* Geforce 6100 (nForce 4xx) */
1477 pNv->Architecture = NV_ARCH_40;
1480 pNv->Architecture = NV_ARCH_04;
1484 pNv->alphaCursor = (pNv->Architecture >= NV_ARCH_10) &&
1485 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10);
1487 NVCommonSetup(pScrn);
1489 pScrn->videoRam = pNv->RamAmountKBytes;
1490 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kBytes\n",
1493 pNv->VRAMPhysicalSize = pScrn->videoRam * 1024;
1496 * If the driver can do gamma correction, it should call xf86SetGamma()
1501 Gamma zeros = {0.0, 0.0, 0.0};
1503 if (!xf86SetGamma(pScrn, zeros)) {
1504 xf86FreeInt10(pNv->pInt);
1510 * Setup the ClockRanges, which describe what clock ranges are available,
1511 * and what sort of modes they can be used for.
1514 clockRanges = xnfcalloc(sizeof(ClockRange), 1);
1515 clockRanges->next = NULL;
1516 clockRanges->minClock = pNv->MinVClockFreqKHz;
1517 clockRanges->maxClock = pNv->MaxVClockFreqKHz;
1518 clockRanges->clockIndex = -1; /* programmable */
1519 clockRanges->doubleScanAllowed = TRUE;
1520 if((pNv->Architecture == NV_ARCH_20) ||
1521 ((pNv->Architecture == NV_ARCH_10) &&
1522 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10) &&
1523 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV15)))
1526 clockRanges->interlaceAllowed = FALSE;
1528 clockRanges->interlaceAllowed = TRUE;
1531 if(pNv->FlatPanel == 1) {
1532 clockRanges->interlaceAllowed = FALSE;
1533 clockRanges->doubleScanAllowed = FALSE;
1536 if(pNv->Architecture < NV_ARCH_10) {
1537 max_width = (pScrn->bitsPerPixel > 16) ? 2032 : 2048;
1540 max_width = (pScrn->bitsPerPixel > 16) ? 4080 : 4096;
1545 * xf86ValidateModes will check that the mode HTotal and VTotal values
1546 * don't exceed the chipset's limit if pScrn->maxHValue and
1547 * pScrn->maxVValue are set. Since our NVValidMode() already takes
1548 * care of this, we don't worry about setting them here.
1550 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
1551 pScrn->display->modes, clockRanges,
1552 NULL, 256, max_width,
1553 512, 128, max_height,
1554 pScrn->display->virtualX,
1555 pScrn->display->virtualY,
1556 pNv->VRAMPhysicalSize / 2,
1557 LOOKUP_BEST_REFRESH);
1560 xf86FreeInt10(pNv->pInt);
1565 /* Prune the modes marked as invalid */
1566 xf86PruneDriverModes(pScrn);
1568 if (i == 0 || pScrn->modes == NULL) {
1569 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n");
1570 xf86FreeInt10(pNv->pInt);
1576 * Set the CRTC parameters for all of the modes based on the type
1577 * of mode, and the chipset's interlace requirements.
1579 * Calling this is required if the mode->Crtc* values are used by the
1580 * driver and if the driver doesn't provide code to set them. They
1581 * are not pre-initialised at all.
1583 xf86SetCrtcForModes(pScrn, 0);
1585 /* Set the current mode to the first in the list */
1586 pScrn->currentMode = pScrn->modes;
1588 /* Print the list of modes being used */
1589 xf86PrintModes(pScrn);
1591 /* Set display resolution */
1592 xf86SetDpi(pScrn, 0, 0);
1596 * XXX This should be taken into account in some way in the mode valdation
1600 if (xf86LoadSubModule(pScrn, "fb") == NULL) {
1601 xf86FreeInt10(pNv->pInt);
1606 xf86LoaderReqSymLists(fbSymbols, NULL);
1608 /* Load XAA if needed */
1609 if (!pNv->NoAccel) {
1610 if (!xf86LoadSubModule(pScrn, pNv->useEXA ? "exa" : "xaa")) {
1611 xf86FreeInt10(pNv->pInt);
1615 xf86LoaderReqSymLists(xaaSymbols, NULL);
1618 /* Load ramdac if needed */
1619 if (pNv->HWCursor) {
1620 if (!xf86LoadSubModule(pScrn, "ramdac")) {
1621 xf86FreeInt10(pNv->pInt);
1625 xf86LoaderReqSymLists(ramdacSymbols, NULL);
1628 /* Load shadowfb if needed */
1629 if (pNv->ShadowFB) {
1630 if (!xf86LoadSubModule(pScrn, "shadowfb")) {
1631 xf86FreeInt10(pNv->pInt);
1635 xf86LoaderReqSymLists(shadowSymbols, NULL);
1638 pNv->CurrentLayout.bitsPerPixel = pScrn->bitsPerPixel;
1639 pNv->CurrentLayout.depth = pScrn->depth;
1640 pNv->CurrentLayout.displayWidth = pScrn->displayWidth;
1641 pNv->CurrentLayout.weight.red = pScrn->weight.red;
1642 pNv->CurrentLayout.weight.green = pScrn->weight.green;
1643 pNv->CurrentLayout.weight.blue = pScrn->weight.blue;
1644 pNv->CurrentLayout.mode = pScrn->currentMode;
1646 xf86FreeInt10(pNv->pInt);
1654 * Map the framebuffer and MMIO memory.
1658 NVMapMem(ScrnInfoPtr pScrn)
1660 NVPtr pNv = NVPTR(pScrn);
1662 pNv->FB = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, pNv->VRAMPhysicalSize/2);
1664 ErrorF("Failed to allocate memory for framebuffer!\n");
1667 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1668 "Allocated %dMiB VRAM for framebuffer + offscreen pixmaps\n",
1672 pNv->Cursor = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, 64*1024);
1674 ErrorF("Failed to allocate memory for hardware cursor\n");
1678 pNv->ScratchBuffer = NVAllocateMemory(pNv, NOUVEAU_MEM_FB,
1679 pNv->Architecture <NV_ARCH_10 ? 8192 : 16384);
1680 if (!pNv->ScratchBuffer) {
1681 ErrorF("Failed to allocate memory for scratch buffer\n");
1689 * Unmap the framebuffer and MMIO memory.
1693 NVUnmapMem(ScrnInfoPtr pScrn)
1695 NVPtr pNv = NVPTR(pScrn);
1697 NVFreeMemory(pNv, pNv->FB);
1698 NVFreeMemory(pNv, pNv->ScratchBuffer);
1699 NVFreeMemory(pNv, pNv->Cursor);
1706 * Initialise a new mode.
1710 NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
1712 vgaHWPtr hwp = VGAHWPTR(pScrn);
1714 NVPtr pNv = NVPTR(pScrn);
1717 /* Initialise the ModeReg values */
1718 if (!vgaHWInit(pScrn, mode))
1720 pScrn->vtSema = TRUE;
1722 vgaReg = &hwp->ModeReg;
1723 nvReg = &pNv->ModeReg;
1725 if(!NVDACInit(pScrn, mode))
1728 NVLockUnlock(pNv, 0);
1730 nvWriteVGA(pNv, 0x44, nvReg->crtcOwner);
1731 NVLockUnlock(pNv, 0);
1734 /* Program the registers */
1735 vgaHWProtect(pScrn, TRUE);
1737 NVDACRestore(pScrn, vgaReg, nvReg, FALSE);
1739 #if X_BYTE_ORDER == X_BIG_ENDIAN
1740 /* turn on LFB swapping */
1744 tmp = nvReadVGA(pNv, 0x46);
1746 nvWriteVGA(pNv, 0x46, tmp);
1750 NVResetGraphics(pScrn);
1752 vgaHWProtect(pScrn, FALSE);
1754 pNv->CurrentLayout.mode = mode;
1760 * Restore the initial (text) mode.
1763 NVRestore(ScrnInfoPtr pScrn)
1765 vgaHWPtr hwp = VGAHWPTR(pScrn);
1766 vgaRegPtr vgaReg = &hwp->SavedReg;
1767 NVPtr pNv = NVPTR(pScrn);
1768 NVRegPtr nvReg = &pNv->SavedReg;
1770 NVLockUnlock(pNv, 0);
1773 nvWriteVGA(pNv, 0x44, pNv->CRTCnumber * 0x3);
1774 NVLockUnlock(pNv, 0);
1777 /* Only restore text mode fonts/text for the primary card */
1778 vgaHWProtect(pScrn, TRUE);
1779 NVDACRestore(pScrn, vgaReg, nvReg, pNv->Primary);
1781 nvWriteVGA(pNv, 0x44, pNv->vtOWNER);
1783 vgaHWProtect(pScrn, FALSE);
1786 static void NVBacklightEnable(NVPtr pNv, Bool on)
1788 /* This is done differently on each laptop. Here we
1789 define the ones we know for sure. */
1791 #if defined(__powerpc__)
1792 if((pNv->Chipset == 0x10DE0179) ||
1793 (pNv->Chipset == 0x10DE0189) ||
1794 (pNv->Chipset == 0x10DE0329))
1796 /* NV17,18,34 Apple iMac, iBook, PowerBook */
1797 CARD32 tmp_pmc, tmp_pcrt;
1798 tmp_pmc = nvReadMC(pNv, 0x10F0) & 0x7FFFFFFF;
1799 tmp_pcrt = nvReadCRTC0(pNv, NV_CRTC_081C) & 0xFFFFFFFC;
1801 tmp_pmc |= (1 << 31);
1804 nvWriteMC(pNv, 0x10F0, tmp_pmc);
1805 nvWriteCRTC0(pNv, NV_CRTC_081C, tmp_pcrt);
1810 if(pNv->twoHeads && ((pNv->Chipset & 0x0ff0) != CHIPSET_NV11)) {
1811 nvWriteMC(pNv, 0x130C, on ? 3 : 7);
1816 fpcontrol = nvReadCurRAMDAC(pNv, 0x848) & 0xCfffffCC;
1818 /* cut the TMDS output */
1819 if(on) fpcontrol |= pNv->fpSyncs;
1820 else fpcontrol |= 0x20000022;
1822 nvWriteCurRAMDAC(pNv, 0x0848, fpcontrol);
1827 NVDPMSSetLCD(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
1829 NVPtr pNv = NVPTR(pScrn);
1831 if (!pScrn->vtSema) return;
1833 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
1835 switch (PowerManagementMode) {
1836 case DPMSModeStandby: /* HSync: Off, VSync: On */
1837 case DPMSModeSuspend: /* HSync: On, VSync: Off */
1838 case DPMSModeOff: /* HSync: Off, VSync: Off */
1839 NVBacklightEnable(pNv, 0);
1841 case DPMSModeOn: /* HSync: On, VSync: On */
1842 NVBacklightEnable(pNv, 1);
1850 NVDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
1852 unsigned char crtc1A;
1853 vgaHWPtr hwp = VGAHWPTR(pScrn);
1855 if (!pScrn->vtSema) return;
1857 crtc1A = hwp->readCrtc(hwp, 0x1A) & ~0xC0;
1859 switch (PowerManagementMode) {
1860 case DPMSModeStandby: /* HSync: Off, VSync: On */
1863 case DPMSModeSuspend: /* HSync: On, VSync: Off */
1866 case DPMSModeOff: /* HSync: Off, VSync: Off */
1869 case DPMSModeOn: /* HSync: On, VSync: On */
1874 /* vgaHWDPMSSet will merely cut the dac output */
1875 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
1877 hwp->writeCrtc(hwp, 0x1A, crtc1A);
1883 /* This gets called at the start of each server generation */
1886 NVScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
1893 unsigned char *FBStart;
1894 int width, height, displayWidth, offscreenHeight, shadowHeight;
1898 * First get the ScrnInfoRec
1900 pScrn = xf86Screens[pScreen->myNum];
1902 hwp = VGAHWPTR(pScrn);
1905 /* Map the VGA memory when the primary video */
1907 hwp->MapSize = 0x10000;
1908 if (!vgaHWMapMem(pScrn))
1912 /* Init DRM - Alloc FIFO, setup graphics objects */
1913 if (!NVInitDma(pScrn))
1916 /* Allocate and map memory areas we need */
1917 if (!NVMapMem(pScrn)) {
1921 /* Save the current state */
1923 /* Initialise the first mode */
1924 if (!NVModeInit(pScrn, pScrn->currentMode)) {
1928 /* Darken the screen for aesthetic reasons and set the viewport */
1929 NVSaveScreen(pScreen, SCREEN_SAVER_ON);
1930 pScrn->AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
1933 * The next step is to setup the screen's visuals, and initialise the
1934 * framebuffer code. In cases where the framebuffer's default
1935 * choices for things like visual layouts and bits per RGB are OK,
1936 * this may be as simple as calling the framebuffer's ScreenInit()
1937 * function. If not, the visuals will need to be setup before calling
1938 * a fb ScreenInit() function and fixed up after.
1940 * For most PC hardware at depths >= 8, the defaults that fb uses
1941 * are not appropriate. In this driver, we fixup the visuals after.
1945 * Reset the visual list.
1947 miClearVisualTypes();
1949 /* Setup the visuals we support. */
1951 if (!miSetVisualTypes(pScrn->depth,
1952 miGetDefaultVisualMask(pScrn->depth), 8,
1953 pScrn->defaultVisual))
1955 if (!miSetPixmapDepths ()) return FALSE;
1958 * Call the framebuffer layer's ScreenInit function, and fill in other
1962 width = pScrn->virtualX;
1963 height = pScrn->virtualY;
1964 displayWidth = pScrn->displayWidth;
1968 height = pScrn->virtualX;
1969 width = pScrn->virtualY;
1972 /* If RandR rotation is enabled, leave enough space in the
1973 * framebuffer for us to rotate the screen dimensions without
1974 * changing the pitch.
1976 if(pNv->RandRRotation)
1977 shadowHeight = max(width, height);
1979 shadowHeight = height;
1982 pNv->ShadowPitch = BitmapBytePad(pScrn->bitsPerPixel * width);
1983 pNv->ShadowPtr = xalloc(pNv->ShadowPitch * shadowHeight);
1984 displayWidth = pNv->ShadowPitch / (pScrn->bitsPerPixel >> 3);
1985 FBStart = pNv->ShadowPtr;
1987 pNv->ShadowPtr = NULL;
1988 FBStart = pNv->FB->map;
1991 switch (pScrn->bitsPerPixel) {
1995 ret = fbScreenInit(pScreen, FBStart, width, height,
1996 pScrn->xDpi, pScrn->yDpi,
1997 displayWidth, pScrn->bitsPerPixel);
2000 xf86DrvMsg(scrnIndex, X_ERROR,
2001 "Internal error: invalid bpp (%d) in NVScreenInit\n",
2002 pScrn->bitsPerPixel);
2009 if (pScrn->bitsPerPixel > 8) {
2010 /* Fixup RGB ordering */
2011 visual = pScreen->visuals + pScreen->numVisuals;
2012 while (--visual >= pScreen->visuals) {
2013 if ((visual->class | DynamicClass) == DirectColor) {
2014 visual->offsetRed = pScrn->offset.red;
2015 visual->offsetGreen = pScrn->offset.green;
2016 visual->offsetBlue = pScrn->offset.blue;
2017 visual->redMask = pScrn->mask.red;
2018 visual->greenMask = pScrn->mask.green;
2019 visual->blueMask = pScrn->mask.blue;
2024 fbPictureInit (pScreen, 0, 0);
2026 xf86SetBlackWhitePixels(pScreen);
2028 offscreenHeight = pNv->FB->size /
2029 (pScrn->displayWidth * pScrn->bitsPerPixel >> 3);
2030 if(offscreenHeight > 32767)
2031 offscreenHeight = 32767;
2036 AvailFBArea.x2 = pScrn->displayWidth;
2037 AvailFBArea.y2 = offscreenHeight;
2038 xf86InitFBManager(pScreen, &AvailFBArea);
2041 if (!pNv->NoAccel) {
2047 NVResetGraphics(pScrn);
2049 miInitializeBackingStore(pScreen);
2050 xf86SetBackingStore(pScreen);
2051 xf86SetSilkenMouse(pScreen);
2053 /* Initialize software cursor.
2054 Must precede creation of the default colormap */
2055 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
2057 /* Initialize HW cursor layer.
2058 Must follow software cursor initialization*/
2059 if (pNv->HWCursor) {
2060 if(!NVCursorInit(pScreen))
2061 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2062 "Hardware cursor initialization failed\n");
2065 /* Initialise default colourmap */
2066 if (!miCreateDefColormap(pScreen))
2069 /* Initialize colormap layer.
2070 Must follow initialization of the default colormap */
2071 if(!xf86HandleColormaps(pScreen, 256, 8, NVDACLoadPalette,
2072 NULL, CMAP_RELOAD_ON_MODE_SWITCH | CMAP_PALETTED_TRUECOLOR))
2076 RefreshAreaFuncPtr refreshArea = NVRefreshArea;
2078 if(pNv->Rotate || pNv->RandRRotation) {
2079 pNv->PointerMoved = pScrn->PointerMoved;
2081 pScrn->PointerMoved = NVPointerMoved;
2083 switch(pScrn->bitsPerPixel) {
2084 case 8: refreshArea = NVRefreshArea8; break;
2085 case 16: refreshArea = NVRefreshArea16; break;
2086 case 32: refreshArea = NVRefreshArea32; break;
2088 if(!pNv->RandRRotation) {
2090 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2091 "Driver rotation enabled, RandR disabled\n");
2095 ShadowFBInit(pScreen, refreshArea);
2099 xf86DPMSInit(pScreen, NVDPMSSetLCD, 0);
2101 xf86DPMSInit(pScreen, NVDPMSSet, 0);
2103 pScrn->memPhysBase = pNv->VRAMPhysical;
2104 pScrn->fbOffset = 0;
2106 if(pNv->Rotate == 0 && !pNv->RandRRotation)
2107 NVInitVideo(pScreen);
2109 pScreen->SaveScreen = NVSaveScreen;
2111 /* Wrap the current CloseScreen function */
2112 pNv->CloseScreen = pScreen->CloseScreen;
2113 pScreen->CloseScreen = NVCloseScreen;
2115 pNv->BlockHandler = pScreen->BlockHandler;
2116 pScreen->BlockHandler = NVBlockHandler;
2119 /* Install our DriverFunc. We have to do it this way instead of using the
2120 * HaveDriverFuncs argument to xf86AddDriver, because InitOutput clobbers
2121 * pScrn->DriverFunc */
2122 pScrn->DriverFunc = NVDriverFunc;
2125 /* Report any unused options (only for the first generation) */
2126 if (serverGeneration == 1) {
2127 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
2133 NVSaveScreen(ScreenPtr pScreen, int mode)
2135 return vgaHWSaveScreen(pScreen, mode);
2139 NVSave(ScrnInfoPtr pScrn)
2141 NVPtr pNv = NVPTR(pScrn);
2142 NVRegPtr nvReg = &pNv->SavedReg;
2143 vgaHWPtr pVga = VGAHWPTR(pScrn);
2144 vgaRegPtr vgaReg = &pVga->SavedReg;
2146 NVLockUnlock(pNv, 0);
2148 nvWriteVGA(pNv, 0x44, pNv->CRTCnumber * 0x3);
2149 NVLockUnlock(pNv, 0);
2152 NVDACSave(pScrn, vgaReg, nvReg, pNv->Primary);
2157 NVRandRGetInfo(ScrnInfoPtr pScrn, Rotation *rotations)
2159 NVPtr pNv = NVPTR(pScrn);
2161 if(pNv->RandRRotation)
2162 *rotations = RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_270;
2164 *rotations = RR_Rotate_0;
2170 NVRandRSetConfig(ScrnInfoPtr pScrn, xorgRRConfig *config)
2172 NVPtr pNv = NVPTR(pScrn);
2174 switch(config->rotation) {
2177 pScrn->PointerMoved = pNv->PointerMoved;
2182 pScrn->PointerMoved = NVPointerMoved;
2187 pScrn->PointerMoved = NVPointerMoved;
2191 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2192 "Unexpected rotation in NVRandRSetConfig!\n");
2194 pScrn->PointerMoved = pNv->PointerMoved;
2202 NVDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer data)
2206 return NVRandRGetInfo(pScrn, (Rotation*)data);
2208 return NVRandRSetConfig(pScrn, (xorgRRConfig*)data);