2 * Copyright 1996-1997 David J. McKay
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #include "nv_include.h"
27 #include "xf86int10.h"
32 * Forward definitions for the functions that make up the driver.
34 /* Mandatory functions */
35 static const OptionInfoRec * NVAvailableOptions(int chipid, int busid);
36 static void NVIdentify(int flags);
37 #ifndef XSERVER_LIBPCIACCESS
38 static Bool NVProbe(DriverPtr drv, int flags);
39 #endif /* XSERVER_LIBPCIACCESS */
40 static Bool NVPreInit(ScrnInfoPtr pScrn, int flags);
41 static Bool NVScreenInit(int Index, ScreenPtr pScreen, int argc,
43 static Bool NVEnterVT(int scrnIndex, int flags);
44 static void NVLeaveVT(int scrnIndex, int flags);
45 static Bool NVCloseScreen(int scrnIndex, ScreenPtr pScreen);
46 static Bool NVSaveScreen(ScreenPtr pScreen, int mode);
48 /* Optional functions */
49 static Bool NVSwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
50 static void NVAdjustFrame(int scrnIndex, int x, int y, int flags);
51 static void NVFreeScreen(int scrnIndex, int flags);
52 static ModeStatus NVValidMode(int scrnIndex, DisplayModePtr mode,
53 Bool verbose, int flags);
55 /* Internally used functions */
57 static Bool NVMapMem(ScrnInfoPtr pScrn);
58 static Bool NVUnmapMem(ScrnInfoPtr pScrn);
59 static void NVSave(ScrnInfoPtr pScrn);
60 static void NVRestore(ScrnInfoPtr pScrn);
61 static Bool NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
63 #ifdef XSERVER_LIBPCIACCESS
65 #define NOUVEAU_PCI_DEVICE(_vendor_id, _device_id) \
66 { (_vendor_id), (_device_id), PCI_MATCH_ANY, PCI_MATCH_ANY, 0x00030000, 0x00ffffff, 0 }
68 static const struct pci_id_match nouveau_device_match[] = {
69 NOUVEAU_PCI_DEVICE(PCI_VENDOR_NVIDIA, PCI_MATCH_ANY),
70 NOUVEAU_PCI_DEVICE(PCI_VENDOR_NVIDIA_SGS, PCI_MATCH_ANY),
74 static Bool NVPciProbe ( DriverPtr drv,
76 struct pci_device *dev,
77 intptr_t match_data );
79 #endif /* XSERVER_LIBPCIACCESS */
82 * This contains the functions needed by the server after loading the
83 * driver module. It must be supplied, and gets added the driver list by
84 * the Module Setup funtion in the dynamic case. In the static case a
85 * reference to this is compiled in, and this requires that the name of
86 * this DriverRec be an upper-case version of the driver name.
89 _X_EXPORT DriverRec NV = {
93 #ifdef XSERVER_LIBPCIACCESS
97 #endif /* XSERVER_LIBPCIACCESS */
102 #ifdef XSERVER_LIBPCIACCESS
103 nouveau_device_match,
105 #endif /* XSERVER_LIBPCIACCESS */
114 static struct NvFamily NVKnownFamilies[] =
116 { "RIVA TNT", "NV04" },
117 { "RIVA TNT2", "NV05" },
118 { "GeForce 256", "NV10" },
119 { "GeForce 2", "NV11, NV15" },
120 { "GeForce 4MX", "NV17, NV18" },
121 { "GeForce 3", "NV20" },
122 { "GeForce 4Ti", "NV25, NV28" },
123 { "GeForce FX", "NV3x" },
124 { "GeForce 6", "NV4x" },
125 { "GeForce 7", "G7x" },
126 { "GeForce 8", "G8x" },
131 * List of symbols from other modules that this module references. This
132 * list is used to tell the loader that it is OK for symbols here to be
133 * unresolved providing that it hasn't been told that they haven't been
134 * told that they are essential via a call to xf86LoaderReqSymbols() or
135 * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
136 * unresolved symbols that are not required.
139 static const char *vgahwSymbols[] = {
154 static const char *fbSymbols[] = {
160 static const char *exaSymbols[] = {
166 static const char *ramdacSymbols[] = {
167 "xf86CreateCursorInfoRec",
168 "xf86DestroyCursorInfoRec",
173 static const char *ddcSymbols[] = {
176 "xf86SetDDCproperties",
180 static const char *vbeSymbols[] = {
187 static const char *i2cSymbols[] = {
188 "xf86CreateI2CBusRec",
193 static const char *shadowSymbols[] = {
198 static const char *int10Symbols[] = {
205 const char *drmSymbols[] = {
210 "drmAgpVersionMajor",
211 "drmAgpVersionMinor",
221 "drmCommandWriteRead",
224 "drmCtlUninstHandler",
227 "drmGetInterruptFromBusID",
233 const char *driSymbols[] = {
237 "DRIFinishScreenInit",
238 "DRIGetSAREAPrivate",
243 "GlxSetVisualConfigs",
249 static MODULESETUPPROTO(nouveauSetup);
251 static XF86ModuleVersionInfo nouveauVersRec =
257 XORG_VERSION_CURRENT,
258 NV_MAJOR_VERSION, NV_MINOR_VERSION, NV_PATCHLEVEL,
259 ABI_CLASS_VIDEODRV, /* This is a video driver */
260 ABI_VIDEODRV_VERSION,
265 _X_EXPORT XF86ModuleData nouveauModuleData = { &nouveauVersRec, nouveauSetup, NULL };
268 nouveauSetup(pointer module, pointer opts, int *errmaj, int *errmin)
270 static Bool setupDone = FALSE;
272 /* This module should be loaded only once, but check to be sure. */
276 /* The 1 here is needed to turn off a backwards compatibility mode */
277 /* Otherwise NVPciProbe() is not called */
278 xf86AddDriver(&NV, module, 1);
281 * Modules that this driver always requires may be loaded here
282 * by calling LoadSubModule().
285 * Tell the loader about symbols from other modules that this module
288 LoaderRefSymLists(vgahwSymbols, exaSymbols, fbSymbols,
289 ramdacSymbols, shadowSymbols, drmSymbols,
290 i2cSymbols, ddcSymbols, vbeSymbols,
294 * The return value must be non-NULL on success even though there
295 * is no TearDownProc.
299 if (errmaj) *errmaj = LDR_ONCEONLY;
304 static const OptionInfoRec *
305 NVAvailableOptions(int chipid, int busid)
312 NVIdentify(int flags)
314 struct NvFamily *family;
317 xf86DrvMsg(0, X_INFO, NV_NAME " driver " NV_DRIVER_DATE "\n");
318 xf86DrvMsg(0, X_INFO, NV_NAME " driver for NVIDIA chipset families :\n");
320 /* maximum length for alignment */
321 family = NVKnownFamilies;
322 while(family->name && family->chipset)
324 maxLen = max(maxLen, strlen(family->name));
329 family = NVKnownFamilies;
330 while(family->name && family->chipset)
332 size_t len = strlen(family->name);
333 xf86ErrorF("\t%s", family->name);
339 xf86ErrorF("(%s)\n", family->chipset);
345 #ifndef XSERVER_LIBPCIACCESS
347 NVGetScrnInfoRec(PciChipsets *chips, int chip)
351 pScrn = xf86ConfigPciEntity(NULL, 0, chip,
352 chips, NULL, NULL, NULL,
355 if(!pScrn) return FALSE;
357 pScrn->driverVersion = NV_VERSION;
358 pScrn->driverName = NV_DRIVER_NAME;
359 pScrn->name = NV_NAME;
361 pScrn->Probe = NVProbe;
362 pScrn->PreInit = NVPreInit;
363 pScrn->ScreenInit = NVScreenInit;
364 pScrn->SwitchMode = NVSwitchMode;
365 pScrn->AdjustFrame = NVAdjustFrame;
366 pScrn->EnterVT = NVEnterVT;
367 pScrn->LeaveVT = NVLeaveVT;
368 pScrn->FreeScreen = NVFreeScreen;
369 pScrn->ValidMode = NVValidMode;
375 /* This returns architecture in hexdecimal, so NV40 is 0x40 */
376 static int NVGetArchitecture(volatile uint32_t *regs)
378 int architecture = 0;
380 /* We're dealing with >=NV10 */
381 if ((regs[0] & 0x0f000000) > 0 )
382 /* Bit 27-20 contain the architecture in hex */
383 architecture = (regs[0] & 0xff00000) >> 20;
385 else if ((regs[0] & 0xff00fff0) == 0x20004000)
391 /* Reading the pci_id from the card registers is the most reliable way */
392 static uint32_t NVGetPCIID(volatile uint32_t *regs)
394 int architecture = NVGetArchitecture(regs);
397 /* Dealing with an unknown or unsupported card */
398 if (architecture == 0)
401 if (architecture >= 0x40)
402 pci_id = regs[0x88000/4];
404 pci_id = regs[0x1800/4];
406 /* A pci-id can be inverted, we must correct this */
407 if ((pci_id & 0xffff) == PCI_VENDOR_NVIDIA)
408 pci_id = (PCI_VENDOR_NVIDIA << 16) | (pci_id >> 16);
409 else if ((pci_id & 0xffff) == PCI_VENDOR_NVIDIA_SGS)
410 pci_id = (PCI_VENDOR_NVIDIA_SGS << 16) | (pci_id >> 16);
411 /* Checking endian issues */
413 /* PCI_VENDOR_NVIDIA = 0x10DE */
414 if ((pci_id & (0xffff << 16)) == (0xDE10 << 16)) /* wrong endian */
415 pci_id = (PCI_VENDOR_NVIDIA << 16) | ((pci_id << 8) & 0x0000ff00) |
416 ((pci_id >> 8) & 0x000000ff);
417 /* PCI_VENDOR_NVIDIA_SGS = 0x12D2 */
418 else if ((pci_id & (0xffff << 16)) == (0xD212 << 16)) /* wrong endian */
419 pci_id = (PCI_VENDOR_NVIDIA_SGS << 16) | ((pci_id << 8) & 0x0000ff00) |
420 ((pci_id >> 8) & 0x000000ff);
426 #ifdef XSERVER_LIBPCIACCESS
428 static Bool NVPciProbe ( DriverPtr drv,
430 struct pci_device *dev,
431 intptr_t match_data )
433 ScrnInfoPtr pScrn = NULL;
435 volatile uint32_t *regs = NULL;
437 /* Temporary mapping to discover the architecture */
438 pci_device_map_range(dev, PCI_DEV_MEM_BASE(dev, 0), 0x90000, 0,
441 uint8_t architecture = NVGetArchitecture(regs);
443 CARD32 pci_id = NVGetPCIID(regs);
445 pci_device_unmap_range(dev, (void *) regs, 0x90000);
447 /* Currently NV04 up to NVAA is known. */
448 /* Using 0xAF as upper bound for some margin. */
449 if (architecture >= 0x04 && architecture <= 0xAF) {
451 /* At this stage the pci_id should be ok, so we generate this
452 * to avoid list duplication */
453 /* AGP bridge chips need their bridge chip id to be detected */
454 PciChipsets NVChipsets[] = {
455 { pci_id, PCI_DEV_PCI_ID(dev), RES_SHARED_VGA },
456 { -1, -1, RES_UNDEFINED }
459 pScrn = xf86ConfigPciEntity(pScrn, 0, entity_num, NVChipsets,
460 NULL, NULL, NULL, NULL, NULL);
463 pScrn->driverVersion = NV_VERSION;
464 pScrn->driverName = NV_DRIVER_NAME;
465 pScrn->name = NV_NAME;
468 pScrn->PreInit = NVPreInit;
469 pScrn->ScreenInit = NVScreenInit;
470 pScrn->SwitchMode = NVSwitchMode;
471 pScrn->AdjustFrame = NVAdjustFrame;
472 pScrn->EnterVT = NVEnterVT;
473 pScrn->LeaveVT = NVLeaveVT;
474 pScrn->FreeScreen = NVFreeScreen;
475 pScrn->ValidMode = NVValidMode;
484 #endif /* XSERVER_LIBPCIACCESS */
486 #define MAX_CHIPS MAXSCREENS
488 #ifndef XSERVER_LIBPCIACCESS
491 NVProbe(DriverPtr drv, int flags)
494 GDevPtr *devSections;
496 SymTabRec NVChipsets[MAX_CHIPS + 1];
497 PciChipsets NVPciChipsets[MAX_CHIPS + 1];
501 Bool foundScreen = FALSE;
503 if ((numDevSections = xf86MatchDevice(NV_DRIVER_NAME, &devSections)) <= 0)
504 return FALSE; /* no matching device section */
506 if (!(ppPci = xf86GetPciVideoInfo()))
507 return FALSE; /* no PCI cards found */
511 /* Create the NVChipsets and NVPciChipsets from found devices */
512 while (*ppPci && (numUsed < MAX_CHIPS)) {
513 if (((*ppPci)->vendor == PCI_VENDOR_NVIDIA_SGS) ||
514 ((*ppPci)->vendor == PCI_VENDOR_NVIDIA))
516 volatile uint32_t *regs;
519 PCI_DEV_READ_LONG(*ppPci, PCI_CMD_STAT_REG, &pcicmd);
520 /* Enable reading memory? */
521 PCI_DEV_WRITE_LONG(*ppPci, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
523 regs = xf86MapPciMem(-1, VIDMEM_MMIO, PCI_DEV_TAG(*ppPci), PCI_DEV_MEM_BASE(*ppPci, 0), 0x90000);
524 int pciid = NVGetPCIID(regs);
526 int architecture = NVGetArchitecture(regs);
528 sprintf(name, "NVIDIA NV%02X", architecture);
529 /* NV04 upto NV98 is known. */
530 if (architecture >= 0x04 && architecture <= 0x9F) {
531 NVChipsets[numUsed].token = pciid;
532 NVChipsets[numUsed].name = name;
533 NVPciChipsets[numUsed].numChipset = pciid;
534 /* AGP bridge chips need their bridge chip id to be detected */
535 NVPciChipsets[numUsed].PCIid = PCI_DEV_PCI_ID(*ppPci);
536 NVPciChipsets[numUsed].resList = RES_SHARED_VGA;
539 xf86UnMapVidMem(-1, (pointer)regs, 0x90000);
541 /* Reset previous state */
542 PCI_DEV_WRITE_LONG(*ppPci, PCI_CMD_STAT_REG, pcicmd);
547 /* terminate the list */
548 NVChipsets[numUsed].token = -1;
549 NVChipsets[numUsed].name = NULL;
550 NVPciChipsets[numUsed].numChipset = -1;
551 NVPciChipsets[numUsed].PCIid = -1;
552 NVPciChipsets[numUsed].resList = RES_UNDEFINED;
554 numUsed = xf86MatchPciInstances(NV_NAME, 0, NVChipsets, NVPciChipsets,
555 devSections, numDevSections, drv,
562 if (flags & PROBE_DETECT) {
565 for (i = 0; i < numUsed; i++) {
568 pPci = xf86GetPciInfoForEntity(usedChips[i]);
569 if (NVGetScrnInfoRec(NVPciChipsets, usedChips[i])) {
580 #endif /* XSERVER_LIBPCIACCESS */
583 NVSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
585 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
586 NVPtr pNv = NVPTR(pScrn);
588 if (pNv->randr12_enable)
589 return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
591 return NVModeInit(xf86Screens[scrnIndex], mode);
595 * This function is used to initialize the Start Address - the first
596 * displayed location in the video memory.
598 /* Usually mandatory */
600 NVAdjustFrame(int scrnIndex, int x, int y, int flags)
602 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
603 NVPtr pNv = NVPTR(pScrn);
605 if (pNv->randr12_enable) {
606 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
607 xf86CrtcPtr crtc = config->output[config->compat_output]->crtc;
609 if (crtc && crtc->enabled)
610 NVCrtcSetBase(crtc, x, y);
613 startAddr = (((y*pScrn->displayWidth)+x)*(pScrn->bitsPerPixel/8));
614 startAddr += pNv->FB->offset;
615 NVSetStartAddress(pNv, startAddr);
620 NV50AcquireDisplay(ScrnInfoPtr pScrn)
622 if (!NV50DispInit(pScrn))
624 if (!NV50CursorAcquire(pScrn))
626 xf86SetDesiredModes(pScrn);
632 NV50ReleaseDisplay(ScrnInfoPtr pScrn)
634 NVPtr pNv = NVPTR(pScrn);
636 NV50CursorRelease(pScrn);
637 NV50DispShutdown(pScrn);
639 if (pNv->pInt10 && pNv->Int10Mode) {
640 xf86Int10InfoPtr pInt10 = pNv->pInt10;
644 pInt10->bx = pNv->Int10Mode | 0x8000;
647 xf86ExecX86int10(pInt10);
654 * This is called when VT switching back to the X server. Its job is
655 * to reinitialise the video mode.
657 * We may wish to unmap video/MMIO memory too.
662 NVEnterVT(int scrnIndex, int flags)
664 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
665 NVPtr pNv = NVPTR(pScrn);
667 if (!pNv->kms_enable) {
668 if (pNv->randr12_enable) {
669 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NVEnterVT is called.\n");
670 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
672 pScrn->vtSema = TRUE;
674 if (pNv->Architecture == NV_ARCH_50) {
675 if (!NV50AcquireDisplay(pScrn))
680 /* Save the current state */
683 for (i = 0; i < xf86_config->num_crtc; i++) {
684 NVCrtcLockUnlock(xf86_config->crtc[i], 0);
687 if (!xf86SetDesiredModes(pScrn))
690 NVAccelCommonInit(pScrn);
692 if (!NVModeInit(pScrn, pScrn->currentMode))
695 NVAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
698 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NVEnterVT is called.\n");
699 if (!xf86SetDesiredModes(pScrn)) {
700 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "xf86SetDesiredModes failed\n");
705 if (pNv->overlayAdaptor && pNv->Architecture != NV_ARCH_04)
706 NV10WriteOverlayParameters(pScrn);
712 * This is called when VT switching away from the X server. Its job is
713 * to restore the previous (text) mode.
715 * We may wish to remap video/MMIO memory too.
720 NVLeaveVT(int scrnIndex, int flags)
722 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
723 NVPtr pNv = NVPTR(pScrn);
724 if (pNv->randr12_enable)
725 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NVLeaveVT is called.\n");
732 if (pNv->Architecture == NV_ARCH_50) {
733 NV50ReleaseDisplay(pScrn);
738 if (!pNv->randr12_enable)
739 NVLockUnlock(pScrn, 1);
750 ScreenPtr pScreen = screenInfo.screens[i];
751 ScrnInfoPtr pScrnInfo = xf86Screens[i];
752 NVPtr pNv = NVPTR(pScrnInfo);
755 FIRE_RING (pNv->chan);
757 pScreen->BlockHandler = pNv->BlockHandler;
758 (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
759 pScreen->BlockHandler = NVBlockHandler;
761 if (pNv->VideoTimerCallback)
762 (*pNv->VideoTimerCallback)(pScrnInfo, currentTime.milliseconds);
767 * This is called at the end of each server generation. It restores the
768 * original (text) mode. It should also unmap the video memory, and free
769 * any per-generation data allocated by the driver. It should finish
770 * by unwrapping and calling the saved CloseScreen function.
775 NVCloseScreen(int scrnIndex, ScreenPtr pScreen)
777 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
778 NVPtr pNv = NVPTR(pScrn);
781 pScrn->vtSema = FALSE;
783 if (pNv->kms_enable) {
787 if (pNv->Architecture == NV_ARCH_50) {
788 NV50ReleaseDisplay(pScrn);
790 if (pNv->randr12_enable)
791 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NVCloseScreen is called.\n");
794 if (!pNv->randr12_enable)
795 NVLockUnlock(pScrn, 1);
801 nouveau_channel_free(&pNv->chan);
803 vgaHWUnmapMem(pScrn);
804 NVDRICloseScreen(pScrn);
805 xf86_cursors_fini(pScreen);
806 if (pNv->CursorInfoRec)
807 xf86DestroyCursorInfoRec(pNv->CursorInfoRec);
808 if (pNv->ShadowPtr) {
809 xfree(pNv->ShadowPtr);
810 pNv->ShadowPtr = NULL;
812 if (pNv->overlayAdaptor) {
813 xfree(pNv->overlayAdaptor);
814 pNv->overlayAdaptor = NULL;
816 if (pNv->blitAdaptor) {
817 xfree(pNv->blitAdaptor);
818 pNv->blitAdaptor = NULL;
820 if (pNv->textureAdaptor[0]) {
821 xfree(pNv->textureAdaptor[0]);
822 pNv->textureAdaptor[0] = NULL;
824 if (pNv->textureAdaptor[1]) {
825 xfree(pNv->textureAdaptor[1]);
826 pNv->textureAdaptor[1] = NULL;
828 if (pNv->EXADriverPtr) {
829 exaDriverFini(pScreen);
830 xfree(pNv->EXADriverPtr);
831 pNv->EXADriverPtr = NULL;
834 pScrn->vtSema = FALSE;
835 pScreen->CloseScreen = pNv->CloseScreen;
836 pScreen->BlockHandler = pNv->BlockHandler;
837 return (*pScreen->CloseScreen)(scrnIndex, pScreen);
840 /* Free up any persistent data structures */
844 NVFreeScreen(int scrnIndex, int flags)
847 * This only gets called when a screen is being deleted. It does not
848 * get called routinely at the end of a server generation.
851 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
852 NVPtr pNv = NVPTR(pScrn);
854 if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
855 vgaHWFreeHWRec(xf86Screens[scrnIndex]);
860 if (pNv->Architecture == NV_ARCH_50 && !pNv->kms_enable) {
861 NV50ConnectorDestroy(pScrn);
862 NV50OutputDestroy(pScrn);
863 NV50CrtcDestroy(pScrn);
866 /* Free this here and not in CloseScreen, as it's needed after the first server generation. */
868 xf86FreeInt10(pNv->pInt10);
870 xfree(pScrn->driverPrivate);
871 pScrn->driverPrivate = NULL;
875 /* Checks if a mode is suitable for the selected chipset. */
879 NVValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
881 NVPtr pNv = NVPTR(xf86Screens[scrnIndex]);
883 if(pNv->fpWidth && pNv->fpHeight)
884 if((pNv->fpWidth < mode->HDisplay) || (pNv->fpHeight < mode->VDisplay))
890 Bool NVI2CInit(ScrnInfoPtr pScrn)
892 NVPtr pNv = NVPTR(pScrn);
894 if (xf86LoadSubModule(pScrn, "i2c") && xf86LoadSubModule(pScrn, "ddc")) {
895 xf86LoaderReqSymLists(i2cSymbols,NULL);
896 xf86LoaderReqSymLists(ddcSymbols, NULL);
898 /* randr-1.2 clients have their DDCs initialized elsewhere */
899 if (!pNv->randr12_enable)
900 return NVDACi2cInit(pScrn);
903 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
904 "Couldn't load i2c and ddc modules. DDC probing can't be done\n");
909 static bool nouveau_kernel_modesetting_enabled(ScrnInfoPtr pScrn)
911 #if XSERVER_LIBPCIACCESS
912 struct pci_device *PciInfo;
920 pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
921 PciInfo = xf86GetPciInfoForEntity(pEnt->index);
923 busIdString = DRICreatePCIBusID(PciInfo);
925 ret = drmCheckModesettingSupported(busIdString);
933 #define nouveau_kernel_modesetting_enabled(x) FALSE
936 static Bool NVPreInitDRI(ScrnInfoPtr pScrn)
938 NVPtr pNv = NVPTR(pScrn);
940 if (!NVDRIGetVersion(pScrn))
943 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
944 "[dri] Found DRI library version %d.%d.%d and kernel"
945 " module version %d.%d.%d\n",
946 pNv->pLibDRMVersion->version_major,
947 pNv->pLibDRMVersion->version_minor,
948 pNv->pLibDRMVersion->version_patchlevel,
949 pNv->pKernelDRMVersion->version_major,
950 pNv->pKernelDRMVersion->version_minor,
951 pNv->pKernelDRMVersion->version_patchlevel);
957 nv_xf86crtc_resize(ScrnInfoPtr pScrn, int width, int height)
959 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "nv_xf86crtc_resize is called with %dx%d resolution.\n", width, height);
960 pScrn->virtualX = width;
961 pScrn->virtualY = height;
965 static const xf86CrtcConfigFuncsRec nv_xf86crtc_config_funcs = {
969 #define NVPreInitFail(fmt, args...) do { \
970 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%d: "fmt, __LINE__, ##args); \
971 NVFreeScreen(pScrn->scrnIndex, 0); \
977 NVPreInit(ScrnInfoPtr pScrn, int flags)
981 int i, max_width, max_height;
982 ClockRangePtr clockRanges;
983 int config_mon_rates = FALSE;
985 if (flags & PROBE_DETECT) {
986 EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
994 if (xf86LoadSubModule(pScrn, "vbe")) {
995 vbeInfoPtr pVbe = VBEInit(NULL, i);
996 ConfiguredMonitor = vbeDoEDID(pVbe, NULL);
1004 * Note: This function is only called once at server startup, and
1005 * not at the start of each server generation. This means that
1006 * only things that are persistent across server generations can
1007 * be initialised here. xf86Screens[] is (pScrn is a pointer to one
1008 * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex()
1009 * are too, and should be used for data that must persist across
1010 * server generations.
1012 * Per-generation data should be allocated with
1013 * AllocateScreenPrivateIndex() from the ScreenInit() function.
1016 /* Check the number of entities, and fail if it isn't one. */
1017 if (pScrn->numEntities != 1)
1020 /* Allocate the NVRec driverPrivate */
1021 if (!(pScrn->driverPrivate = xnfcalloc(1, sizeof(NVRec))))
1025 /* Get the entity, and make sure it is PCI. */
1026 pNv->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1027 if (pNv->pEnt->location.type != BUS_PCI)
1030 /* Find the PCI info for this screen */
1031 pNv->PciInfo = xf86GetPciInfoForEntity(pNv->pEnt->index);
1032 #ifndef XSERVER_LIBPCIACCESS
1033 pNv->PciTag = pciTag(pNv->PciInfo->bus, pNv->PciInfo->device,
1034 pNv->PciInfo->func);
1035 #endif /* XSERVER_LIBPCIACCESS */
1037 pNv->Primary = xf86IsPrimaryPci(pNv->PciInfo);
1039 volatile uint32_t *regs = NULL;
1040 #ifdef XSERVER_LIBPCIACCESS
1041 pci_device_map_range(pNv->PciInfo, PCI_DEV_MEM_BASE(pNv->PciInfo, 0),
1042 0x90000, 0, (void *)®s);
1043 pNv->Chipset = NVGetPCIID(regs) & 0xffff;
1044 pNv->NVArch = NVGetArchitecture(regs);
1045 pci_device_unmap_range(pNv->PciInfo, (void *) regs, 0x90000);
1048 PCI_DEV_READ_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, &pcicmd);
1049 /* Enable reading memory? */
1050 PCI_DEV_WRITE_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
1051 regs = xf86MapPciMem(-1, VIDMEM_MMIO, pNv->PciTag, PCI_DEV_MEM_BASE(pNv->PciInfo, 0), 0x90000);
1052 pNv->Chipset = NVGetPCIID(regs) & 0xffff;
1053 pNv->NVArch = NVGetArchitecture(regs);
1054 xf86UnMapVidMem(-1, (pointer)regs, 0x90000);
1055 /* Reset previous state */
1056 PCI_DEV_WRITE_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, pcicmd);
1057 #endif /* XSERVER_LIBPCIACCESS */
1059 pScrn->chipset = malloc(sizeof(char) * 25);
1060 sprintf(pScrn->chipset, "NVIDIA NV%02X", pNv->NVArch);
1062 if(!pScrn->chipset) {
1063 pScrn->chipset = "Unknown NVIDIA";
1067 * This shouldn't happen because such problems should be caught in
1068 * NVProbe(), but check it just in case.
1070 if (pScrn->chipset == NULL)
1071 NVPreInitFail("ChipID 0x%04X is not recognised\n", pNv->Chipset);
1073 if (pNv->NVArch < 0x04)
1074 NVPreInitFail("Chipset \"%s\" is not recognised\n", pScrn->chipset);
1076 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Chipset: \"%s\"\n", pScrn->chipset);
1078 /* The highest architecture currently supported is NV5x */
1079 if (pNv->NVArch >= 0x80) {
1080 pNv->Architecture = NV_ARCH_50;
1081 } else if (pNv->NVArch >= 0x60) {
1082 pNv->Architecture = NV_ARCH_40;
1083 } else if (pNv->NVArch >= 0x50) {
1084 pNv->Architecture = NV_ARCH_50;
1085 } else if (pNv->NVArch >= 0x40) {
1086 pNv->Architecture = NV_ARCH_40;
1087 } else if (pNv->NVArch >= 0x30) {
1088 pNv->Architecture = NV_ARCH_30;
1089 } else if (pNv->NVArch >= 0x20) {
1090 pNv->Architecture = NV_ARCH_20;
1091 } else if (pNv->NVArch >= 0x10) {
1092 pNv->Architecture = NV_ARCH_10;
1093 } else if (pNv->NVArch >= 0x04) {
1094 pNv->Architecture = NV_ARCH_04;
1095 /* The lowest architecture currently supported is NV04 */
1100 /* Initialize the card through int10 interface if needed */
1101 if (xf86LoadSubModule(pScrn, "int10")) {
1102 xf86LoaderReqSymLists(int10Symbols, NULL);
1103 #if !defined(__alpha__) && !defined(__powerpc__)
1104 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initializing int10\n");
1105 pNv->pInt10 = xf86InitInt10(pNv->pEnt->index);
1109 /* Save current console video mode */
1110 if (pNv->Architecture >= NV_ARCH_50 && pNv->pInt10 && !pNv->kms_enable) {
1111 const xf86Int10InfoPtr pInt10 = pNv->pInt10;
1114 pInt10->ax = 0x4f03;
1118 xf86ExecX86int10(pInt10);
1119 pNv->Int10Mode = pInt10->bx & 0x3fff;
1121 xf86DrvMsg(pScrn->scrnIndex, X_PROBED,
1122 "VESA-HACK: Console VGA mode is 0x%x\n",
1126 xf86SetOperatingState(resVgaIo, pNv->pEnt->index, ResUnusedOpr);
1127 xf86SetOperatingState(resVgaMem, pNv->pEnt->index, ResDisableOpr);
1129 /* Set pScrn->monitor */
1130 pScrn->monitor = pScrn->confScreen->monitor;
1133 * The first thing we should figure out is the depth, bpp, etc.
1136 if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support32bppFb)) {
1137 NVPreInitFail("\n");
1139 /* Check that the returned depth is one we support */
1140 switch (pScrn->depth) {
1145 case 15: /* 15 may get done one day, so leave any code for it in place */
1147 NVPreInitFail("Given depth (%d) is not supported by this driver\n",
1151 xf86PrintDepthBpp(pScrn);
1154 * This must happen after pScrn->display has been set because
1155 * xf86SetWeight references it.
1157 /* The defaults are OK for us */
1158 rgb rgbzeros = {0, 0, 0};
1160 if (!xf86SetWeight(pScrn, rgbzeros, rgbzeros))
1161 NVPreInitFail("\n");
1163 if (!xf86SetDefaultVisual(pScrn, -1))
1164 NVPreInitFail("\n");
1165 /* We don't support DirectColor */
1166 else if (pScrn->defaultVisual != TrueColor)
1167 NVPreInitFail("Given default visual (%s) is not supported at depth %d\n",
1168 xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
1170 /* The vgahw module should be loaded here when needed */
1171 if (!xf86LoadSubModule(pScrn, "vgahw")) {
1172 NVPreInitFail("\n");
1175 xf86LoaderReqSymLists(vgahwSymbols, NULL);
1178 * Allocate a vgaHWRec
1180 if (!vgaHWGetHWRec(pScrn)) {
1181 NVPreInitFail("\n");
1184 /* We use a programmable clock */
1185 pScrn->progClock = TRUE;
1187 /* Collect all of the relevant option flags (fill in pScrn->options) */
1188 xf86CollectOptions(pScrn, NULL);
1190 /* Process the options */
1191 if (!(pNv->Options = xalloc(sizeof(NVOptions))))
1193 memcpy(pNv->Options, NVOptions, sizeof(NVOptions));
1194 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pNv->Options);
1198 pNv->kms_enable = false;
1200 if (pNv->Architecture == NV_ARCH_50)
1201 pNv->kms_enable = nouveau_kernel_modesetting_enabled(pScrn);
1202 #endif /* XF86DRM_MODE */
1204 if (pNv->kms_enable)
1205 xf86DrvMsg(pScrn->scrnIndex, from, "NV50 Kernel modesetting enabled\n");
1207 pNv->randr12_enable = true;
1208 if (pNv->Architecture != NV_ARCH_50 && !xf86ReturnOptValBool(pNv->Options, OPTION_RANDR12, TRUE))
1209 pNv->randr12_enable = false;
1210 xf86DrvMsg(pScrn->scrnIndex, from, "Randr1.2 support %sabled\n", pNv->randr12_enable ? "en" : "dis");
1212 pNv->HWCursor = TRUE;
1214 * The preferred method is to use the "hw cursor" option as a tri-state
1215 * option, with the default set above.
1217 if (xf86GetOptValBool(pNv->Options, OPTION_HW_CURSOR, &pNv->HWCursor)) {
1220 /* For compatibility, accept this too (as an override) */
1221 if (xf86ReturnOptValBool(pNv->Options, OPTION_SW_CURSOR, FALSE)) {
1223 pNv->HWCursor = FALSE;
1225 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
1226 pNv->HWCursor ? "HW" : "SW");
1228 pNv->FpScale = TRUE;
1230 if (xf86GetOptValBool(pNv->Options, OPTION_FP_SCALE, &pNv->FpScale)) {
1231 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Flat panel scaling %s\n",
1232 pNv->FpScale ? "on" : "off");
1234 if (xf86ReturnOptValBool(pNv->Options, OPTION_NOACCEL, FALSE)) {
1235 pNv->NoAccel = TRUE;
1236 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1238 if (xf86ReturnOptValBool(pNv->Options, OPTION_SHADOW_FB, FALSE)) {
1239 pNv->ShadowFB = TRUE;
1240 pNv->NoAccel = TRUE;
1241 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1242 "Using \"Shadow Framebuffer\" - acceleration disabled\n");
1245 if(xf86GetOptValInteger(pNv->Options, OPTION_VIDEO_KEY, &(pNv->videoKey))) {
1246 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n",
1249 pNv->videoKey = (1 << pScrn->offset.red) |
1250 (1 << pScrn->offset.green) |
1251 (((pScrn->mask.blue >> pScrn->offset.blue) - 1) << pScrn->offset.blue);
1254 /* Things happen on a per output basis for a randr-1.2 driver. */
1255 if (xf86GetOptValBool(pNv->Options, OPTION_FLAT_PANEL, &(pNv->FlatPanel)) && !pNv->randr12_enable) {
1256 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "forcing %s usage\n",
1257 pNv->FlatPanel ? "DFP" : "CRTC");
1259 pNv->FlatPanel = -1; /* autodetect later */
1262 pNv->FPDither = FALSE;
1263 if (xf86GetOptValBool(pNv->Options, OPTION_FP_DITHER, &(pNv->FPDither)))
1264 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "enabling flat panel dither\n");
1266 if (xf86GetOptValInteger(pNv->Options, OPTION_FP_TWEAK,
1267 &pNv->PanelTweak)) {
1268 pNv->usePanelTweak = TRUE;
1270 pNv->usePanelTweak = FALSE;
1273 if (pNv->pEnt->device->MemBase != 0) {
1274 /* Require that the config file value matches one of the PCI values. */
1275 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->MemBase)) {
1277 "MemBase 0x%08lX doesn't match any PCI base register.\n",
1278 pNv->pEnt->device->MemBase);
1280 pNv->VRAMPhysical = pNv->pEnt->device->MemBase;
1283 if (PCI_DEV_MEM_BASE(pNv->PciInfo, 1) != 0) {
1284 pNv->VRAMPhysical = PCI_DEV_MEM_BASE(pNv->PciInfo, 1) & 0xff800000;
1287 NVPreInitFail("No valid FB address in PCI config space\n");
1291 xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
1292 (unsigned long)pNv->VRAMPhysical);
1294 if (pNv->pEnt->device->IOBase != 0) {
1295 /* Require that the config file value matches one of the PCI values. */
1296 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->IOBase)) {
1297 NVPreInitFail("IOBase 0x%08lX doesn't match any PCI base register.\n",
1298 pNv->pEnt->device->IOBase);
1300 pNv->IOAddress = pNv->pEnt->device->IOBase;
1303 if (PCI_DEV_MEM_BASE(pNv->PciInfo, 0) != 0) {
1304 pNv->IOAddress = PCI_DEV_MEM_BASE(pNv->PciInfo, 0) & 0xffffc000;
1307 NVPreInitFail("No valid MMIO address in PCI config space\n");
1310 xf86DrvMsg(pScrn->scrnIndex, from, "MMIO registers at 0x%lX\n",
1311 (unsigned long)pNv->IOAddress);
1313 if (xf86RegisterResources(pNv->pEnt->index, NULL, ResExclusive))
1314 NVPreInitFail("xf86RegisterResources() found resource conflicts\n");
1316 if (pNv->Architecture < NV_ARCH_10) {
1317 max_width = (pScrn->bitsPerPixel > 16) ? 2032 : 2048;
1319 } else if (pNv->Architecture < NV_ARCH_50) {
1320 max_width = (pScrn->bitsPerPixel > 16) ? 4080 : 4096;
1323 max_width = (pScrn->bitsPerPixel > 16) ? 8176 : 8192;
1328 if (pNv->kms_enable){
1331 bus_id = DRICreatePCIBusID(pNv->PciInfo);
1333 pNv->drmmode = calloc(1, sizeof(drmmode_rec));
1334 res = drmmode_pre_init(pScrn, bus_id, pNv->drmmode, pScrn->bitsPerPixel >> 3);
1337 NVPreInitFail("Kernel modesetting failed to initialize\n");
1341 if (pNv->randr12_enable) {
1342 /* Allocate an xf86CrtcConfig */
1343 xf86CrtcConfigInit(pScrn, &nv_xf86crtc_config_funcs);
1344 xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
1347 if (NVPreInitDRI(pScrn) == FALSE)
1348 NVPreInitFail("\n");
1350 if (!pNv->randr12_enable) {
1351 if ((pScrn->monitor->nHsync == 0) &&
1352 (pScrn->monitor->nVrefresh == 0)) {
1354 config_mon_rates = FALSE;
1356 config_mon_rates = TRUE;
1360 NVCommonSetup(pScrn);
1362 if (pNv->randr12_enable && !pNv->kms_enable) {
1363 if (pNv->Architecture == NV_ARCH_50)
1364 if (!NV50DispPreInit(pScrn))
1365 NVPreInitFail("\n");
1369 /* This is the internal system, not the randr-1.2 ones. */
1370 if (pNv->Architecture == NV_ARCH_50) {
1371 NV50CrtcInit(pScrn);
1372 NV50ConnectorInit(pScrn);
1373 NV50OutputSetup(pScrn);
1376 for (i = 0; i <= pNv->twoHeads; i++) {
1377 if (pNv->Architecture == NV_ARCH_50)
1378 nv50_crtc_init(pScrn, i);
1380 nv_crtc_init(pScrn, i);
1383 if (pNv->Architecture < NV_ARCH_50)
1384 NvSetupOutputs(pScrn);
1386 nv50_output_create(pScrn); /* create randr-1.2 "outputs". */
1388 if (!xf86InitialConfiguration(pScrn, FALSE))
1389 NVPreInitFail("No valid modes.\n");
1392 pScrn->videoRam = pNv->RamAmountKBytes;
1393 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kBytes\n",
1396 pNv->VRAMPhysicalSize = pScrn->videoRam * 1024;
1399 * If the driver can do gamma correction, it should call xf86SetGamma()
1402 Gamma gammazeros = {0.0, 0.0, 0.0};
1404 if (!xf86SetGamma(pScrn, gammazeros))
1405 NVPreInitFail("\n");
1408 * Setup the ClockRanges, which describe what clock ranges are available,
1409 * and what sort of modes they can be used for.
1412 clockRanges = xnfcalloc(sizeof(ClockRange), 1);
1413 clockRanges->next = NULL;
1414 clockRanges->minClock = pNv->MinVClockFreqKHz;
1415 clockRanges->maxClock = pNv->MaxVClockFreqKHz;
1416 clockRanges->clockIndex = -1; /* programmable */
1417 clockRanges->doubleScanAllowed = TRUE;
1418 if ((pNv->Architecture == NV_ARCH_20) ||
1419 ((pNv->Architecture == NV_ARCH_10) &&
1420 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10) &&
1421 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV15))) {
1423 clockRanges->interlaceAllowed = FALSE;
1425 clockRanges->interlaceAllowed = TRUE;
1428 if(pNv->FlatPanel == 1) {
1429 clockRanges->interlaceAllowed = FALSE;
1430 clockRanges->doubleScanAllowed = FALSE;
1434 /* If DFP, add a modeline corresponding to its panel size */
1435 if (pNv->FlatPanel && !pNv->Television && pNv->fpWidth && pNv->fpHeight) {
1436 DisplayModePtr Mode;
1438 Mode = xnfcalloc(1, sizeof(DisplayModeRec));
1439 Mode = xf86CVTMode(pNv->fpWidth, pNv->fpHeight, 60.00, TRUE, FALSE);
1440 Mode->type = M_T_DRIVER;
1441 pScrn->monitor->Modes = xf86ModesAdd(pScrn->monitor->Modes, Mode);
1443 if (!config_mon_rates) {
1445 Mode->HSync = ((float) Mode->Clock ) / ((float) Mode->HTotal);
1446 if (!Mode->VRefresh)
1447 Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) /
1448 ((float) (Mode->HTotal * Mode->VTotal));
1450 if (Mode->HSync < pScrn->monitor->hsync[0].lo)
1451 pScrn->monitor->hsync[0].lo = Mode->HSync;
1452 if (Mode->HSync > pScrn->monitor->hsync[0].hi)
1453 pScrn->monitor->hsync[0].hi = Mode->HSync;
1454 if (Mode->VRefresh < pScrn->monitor->vrefresh[0].lo)
1455 pScrn->monitor->vrefresh[0].lo = Mode->VRefresh;
1456 if (Mode->VRefresh > pScrn->monitor->vrefresh[0].hi)
1457 pScrn->monitor->vrefresh[0].hi = Mode->VRefresh;
1459 pScrn->monitor->nHsync = 1;
1460 pScrn->monitor->nVrefresh = 1;
1465 if (pNv->randr12_enable) {
1466 pScrn->displayWidth = nv_pitch_align(pNv, pScrn->virtualX, pScrn->depth);
1469 * xf86ValidateModes will check that the mode HTotal and VTotal values
1470 * don't exceed the chipset's limit if pScrn->maxHValue and
1471 * pScrn->maxVValue are set. Since our NVValidMode() already takes
1472 * care of this, we don't worry about setting them here.
1474 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
1475 pScrn->display->modes, clockRanges,
1476 NULL, 256, max_width,
1477 512, 128, max_height,
1478 pScrn->display->virtualX,
1479 pScrn->display->virtualY,
1480 pNv->VRAMPhysicalSize / 2,
1481 LOOKUP_BEST_REFRESH);
1484 NVPreInitFail("\n");
1487 /* Prune the modes marked as invalid */
1488 xf86PruneDriverModes(pScrn);
1491 * Set the CRTC parameters for all of the modes based on the type
1492 * of mode, and the chipset's interlace requirements.
1494 * Calling this is required if the mode->Crtc* values are used by the
1495 * driver and if the driver doesn't provide code to set them. They
1496 * are not pre-initialised at all.
1498 xf86SetCrtcForModes(pScrn, 0);
1500 if (pScrn->modes == NULL)
1501 NVPreInitFail("No valid modes found\n");
1504 /* Set the current mode to the first in the list */
1505 pScrn->currentMode = pScrn->modes;
1507 /* Print the list of modes being used */
1508 xf86PrintModes(pScrn);
1510 /* Set display resolution */
1511 xf86SetDpi(pScrn, 0, 0);
1514 * XXX This should be taken into account in some way in the mode valdation
1518 if (xf86LoadSubModule(pScrn, "fb") == NULL)
1519 NVPreInitFail("\n");
1521 xf86LoaderReqSymLists(fbSymbols, NULL);
1523 /* Load EXA if needed */
1524 if (!pNv->NoAccel) {
1525 if (!xf86LoadSubModule(pScrn, "exa")) {
1526 NVPreInitFail("\n");
1528 xf86LoaderReqSymLists(exaSymbols, NULL);
1531 /* Load ramdac if needed */
1532 if (pNv->HWCursor) {
1533 if (!xf86LoadSubModule(pScrn, "ramdac")) {
1534 NVPreInitFail("\n");
1536 xf86LoaderReqSymLists(ramdacSymbols, NULL);
1539 /* Load shadowfb if needed */
1540 if (pNv->ShadowFB) {
1541 if (!xf86LoadSubModule(pScrn, "shadowfb")) {
1542 NVPreInitFail("\n");
1544 xf86LoaderReqSymLists(shadowSymbols, NULL);
1552 * Map the framebuffer and MMIO memory.
1556 NVMapMem(ScrnInfoPtr pScrn)
1558 NVPtr pNv = NVPTR(pScrn);
1559 int gart_scratch_size;
1562 nouveau_device_get_param(pNv->dev, NOUVEAU_GETPARAM_FB_SIZE, &res);
1564 nouveau_device_get_param(pNv->dev, NOUVEAU_GETPARAM_FB_PHYSICAL, &res);
1565 pNv->VRAMPhysical=res;
1566 nouveau_device_get_param(pNv->dev, NOUVEAU_GETPARAM_AGP_SIZE, &res);
1569 #if !NOUVEAU_EXA_PIXMAPS
1570 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1571 0, pNv->VRAMPhysicalSize / 2, &pNv->FB)) {
1572 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to allocate memory for framebuffer!\n");
1575 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1576 "Allocated %dMiB VRAM for framebuffer + offscreen pixmaps, at offset 0x%X\n",
1577 (uint32_t)(pNv->FB->size >> 20), (uint32_t) pNv->FB->offset);
1579 if (pNv->kms_enable)
1580 drmmode_set_fb(pScrn, pNv->drmmode, pScrn->virtualX, pScrn->virtualY, pScrn->displayWidth*(pScrn->bitsPerPixel >> 3), pNv->FB);
1585 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1586 "AGPGART: %dMiB available\n",
1587 (unsigned int)(pNv->AGPSize >> 20));
1588 if (pNv->AGPSize > (16*1024*1024))
1589 gart_scratch_size = 16*1024*1024;
1591 /* always leave 512kb for other things like the fifos */
1592 gart_scratch_size = pNv->AGPSize - 512*1024;
1594 gart_scratch_size = (4 << 20) - (1 << 18) ;
1595 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1596 "GART: PCI DMA - using %dKiB\n",
1597 gart_scratch_size >> 10);
1600 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_GART | NOUVEAU_BO_PIN, 0,
1601 gart_scratch_size, &pNv->GART)) {
1602 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1603 "Unable to allocate GART memory\n");
1606 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1607 "GART: Allocated %dMiB as a scratch buffer\n",
1608 (unsigned int)(pNv->GART->size >> 20));
1611 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN, 0,
1612 64 * 1024, &pNv->Cursor)) {
1613 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1614 "Failed to allocate memory for hardware cursor\n");
1618 if (pNv->randr12_enable) {
1619 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN, 0,
1620 64 * 1024, &pNv->Cursor2)) {
1621 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1622 "Failed to allocate memory for hardware cursor\n");
1627 if (pNv->Architecture >= NV_ARCH_50) {
1628 /* Both CRTC's have a CLUT. */
1629 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1630 0, 0x1000, &pNv->CLUT0)) {
1631 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1632 "Failed to allocate memory for CLUT0\n");
1636 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1637 0, 0x1000, &pNv->CLUT1)) {
1638 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1639 "Failed to allocate memory for CLUT1\n");
1644 if ((pNv->FB && nouveau_bo_map(pNv->FB, NOUVEAU_BO_RDWR)) ||
1645 (pNv->GART && nouveau_bo_map(pNv->GART, NOUVEAU_BO_RDWR)) ||
1646 (pNv->CLUT0 && nouveau_bo_map(pNv->CLUT0, NOUVEAU_BO_RDWR)) ||
1647 (pNv->CLUT1 && nouveau_bo_map(pNv->CLUT1, NOUVEAU_BO_RDWR)) ||
1648 nouveau_bo_map(pNv->Cursor, NOUVEAU_BO_RDWR) ||
1649 (pNv->randr12_enable && nouveau_bo_map(pNv->Cursor2, NOUVEAU_BO_RDWR))) {
1650 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1651 "Failed to map pinned buffers\n");
1659 * Unmap the framebuffer and MMIO memory.
1663 NVUnmapMem(ScrnInfoPtr pScrn)
1665 NVPtr pNv = NVPTR(pScrn);
1667 nouveau_bo_del(&pNv->xv_filtertable_mem);
1668 if (pNv->blitAdaptor)
1669 NVFreePortMemory(pScrn, GET_BLIT_PRIVATE(pNv));
1670 if (pNv->textureAdaptor[0])
1671 NVFreePortMemory(pScrn, pNv->textureAdaptor[0]->pPortPrivates[0].ptr);
1672 if (pNv->textureAdaptor[1])
1673 NVFreePortMemory(pScrn, pNv->textureAdaptor[1]->pPortPrivates[0].ptr);
1675 nouveau_bo_del(&pNv->FB);
1676 nouveau_bo_del(&pNv->GART);
1677 nouveau_bo_del(&pNv->Cursor);
1678 if (pNv->randr12_enable) {
1679 nouveau_bo_del(&pNv->Cursor2);
1681 nouveau_bo_del(&pNv->CLUT0);
1682 nouveau_bo_del(&pNv->CLUT1);
1689 * Initialise a new mode.
1693 NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
1695 vgaHWPtr hwp = VGAHWPTR(pScrn);
1697 NVPtr pNv = NVPTR(pScrn);
1700 /* Initialise the ModeReg values */
1701 if (!vgaHWInit(pScrn, mode))
1703 pScrn->vtSema = TRUE;
1705 vgaReg = &hwp->ModeReg;
1706 nvReg = &pNv->ModeReg;
1708 if(!NVDACInit(pScrn, mode))
1711 NVLockUnlock(pScrn, 0);
1713 nvWriteCurVGA(pNv, NV_CIO_CRE_44, nvReg->crtcOwner);
1714 NVLockUnlock(pScrn, 0);
1717 /* Program the registers */
1718 vgaHWProtect(pScrn, TRUE);
1720 NVDACRestore(pScrn, vgaReg, nvReg, FALSE);
1722 #if X_BYTE_ORDER == X_BIG_ENDIAN
1723 /* turn on LFB swapping */
1727 tmp = nvReadCurVGA(pNv, NV_CIO_CRE_RCR);
1729 nvWriteCurVGA(pNv, NV_CIO_CRE_RCR, tmp);
1734 NVAccelCommonInit(pScrn);
1736 vgaHWProtect(pScrn, FALSE);
1738 pScrn->currentMode = mode;
1744 * Restore the initial (text) mode.
1747 NVRestore(ScrnInfoPtr pScrn)
1749 NVPtr pNv = NVPTR(pScrn);
1751 if (pNv->randr12_enable) {
1752 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1755 for (i = 0; i < xf86_config->num_crtc; i++)
1756 NVCrtcLockUnlock(xf86_config->crtc[i], 0);
1758 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Restoring encoders\n");
1759 for (i = 0; i < pNv->dcb_table.entries; i++)
1760 nv_encoder_restore(pScrn, &pNv->encoders[i]);
1762 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Restoring crtcs\n");
1763 for (i = 0; i < xf86_config->num_crtc; i++)
1764 xf86_config->crtc[i]->funcs->restore(xf86_config->crtc[i]);
1766 nv_save_restore_vga_fonts(pScrn, 0);
1768 for (i = 0; i < xf86_config->num_crtc; i++)
1769 NVCrtcLockUnlock(xf86_config->crtc[i], 1);
1771 vgaHWPtr hwp = VGAHWPTR(pScrn);
1772 vgaRegPtr vgaReg = &hwp->SavedReg;
1773 NVRegPtr nvReg = &pNv->SavedReg;
1775 NVLockUnlock(pScrn, 0);
1778 nvWriteCurVGA(pNv, NV_CIO_CRE_44, pNv->crtc_active[1] * 0x3);
1779 NVLockUnlock(pScrn, 0);
1782 /* Only restore text mode fonts/text for the primary card */
1783 vgaHWProtect(pScrn, TRUE);
1784 NVDACRestore(pScrn, vgaReg, nvReg, pNv->Primary);
1785 vgaHWProtect(pScrn, FALSE);
1788 if (pNv->twoHeads) {
1789 NVSetOwner(pNv, 0); /* move to head A to set owner */
1790 NVLockVgaCrtc(pNv, 0, false);
1791 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Restoring CRTC_OWNER to %d.\n", pNv->vtOWNER);
1792 NVWriteVgaCrtc(pNv, 0, NV_CIO_CRE_44, pNv->vtOWNER);
1793 NVLockVgaCrtc(pNv, 0, true);
1798 NVLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
1799 LOCO * colors, VisualPtr pVisual)
1801 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1804 CARD16 lut_r[256], lut_g[256], lut_b[256];
1806 for (c = 0; c < xf86_config->num_crtc; c++) {
1807 xf86CrtcPtr crtc = xf86_config->crtc[c];
1809 /* code borrowed from intel driver */
1810 switch (pScrn->depth) {
1812 for (i = 0; i < numColors; i++) {
1814 for (j = 0; j < 8; j++) {
1815 lut_r[index * 8 + j] = colors[index].red << 8;
1816 lut_g[index * 8 + j] = colors[index].green << 8;
1817 lut_b[index * 8 + j] = colors[index].blue << 8;
1821 for (i = 0; i < numColors; i++) {
1825 for (j = 0; j < 8; j++) {
1826 lut_r[index * 8 + j] = colors[index].red << 8;
1827 lut_b[index * 8 + j] = colors[index].blue << 8;
1831 for (j = 0; j < 4; j++) {
1832 lut_g[index * 4 + j] = colors[index].green << 8;
1836 for (i = 0; i < numColors; i++) {
1838 lut_r[index] = colors[index].red << 8;
1839 lut_g[index] = colors[index].green << 8;
1840 lut_b[index] = colors[index].blue << 8;
1845 /* Make the change through RandR */
1846 RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
1850 static void NVBacklightEnable(NVPtr pNv, Bool on)
1852 /* This is done differently on each laptop. Here we
1853 define the ones we know for sure. */
1855 #if defined(__powerpc__)
1856 if((pNv->Chipset & 0xffff == 0x0179) ||
1857 (pNv->Chipset & 0xffff == 0x0189) ||
1858 (pNv->Chipset & 0xffff == 0x0329))
1860 /* NV17,18,34 Apple iMac, iBook, PowerBook */
1861 CARD32 tmp_pmc, tmp_pcrt;
1862 tmp_pmc = nvReadMC(pNv, NV_PBUS_DEBUG_DUALHEAD_CTL) & 0x7FFFFFFF;
1863 tmp_pcrt = NVReadCRTC(pNv, 0, NV_CRTC_GPIO_EXT) & 0xFFFFFFFC;
1865 tmp_pmc |= (1 << 31);
1868 nvWriteMC(pNv, NV_PBUS_DEBUG_DUALHEAD_CTL, tmp_pmc);
1869 NVWriteCRTC(pNv, 0, NV_CRTC_GPIO_EXT, tmp_pcrt);
1874 if(pNv->twoHeads && ((pNv->Chipset & 0x0ff0) != CHIPSET_NV11)) {
1875 nvWriteMC(pNv, 0x130C, on ? 3 : 7);
1880 fpcontrol = nvReadCurRAMDAC(pNv, NV_RAMDAC_FP_CONTROL) & 0xCfffffCC;
1882 /* cut the TMDS output */
1883 if(on) fpcontrol |= pNv->fpSyncs;
1884 else fpcontrol |= 0x20000022;
1886 nvWriteCurRAMDAC(pNv, NV_RAMDAC_FP_CONTROL, fpcontrol);
1891 NVDPMSSetLCD(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
1893 NVPtr pNv = NVPTR(pScrn);
1895 if (!pScrn->vtSema) return;
1897 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
1899 switch (PowerManagementMode) {
1900 case DPMSModeStandby: /* HSync: Off, VSync: On */
1901 case DPMSModeSuspend: /* HSync: On, VSync: Off */
1902 case DPMSModeOff: /* HSync: Off, VSync: Off */
1903 NVBacklightEnable(pNv, 0);
1905 case DPMSModeOn: /* HSync: On, VSync: On */
1906 NVBacklightEnable(pNv, 1);
1914 NVDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
1916 unsigned char crtc1A;
1917 vgaHWPtr hwp = VGAHWPTR(pScrn);
1919 if (!pScrn->vtSema) return;
1921 crtc1A = hwp->readCrtc(hwp, 0x1A) & ~0xC0;
1923 switch (PowerManagementMode) {
1924 case DPMSModeStandby: /* HSync: Off, VSync: On */
1927 case DPMSModeSuspend: /* HSync: On, VSync: Off */
1930 case DPMSModeOff: /* HSync: Off, VSync: Off */
1933 case DPMSModeOn: /* HSync: On, VSync: On */
1938 /* vgaHWDPMSSet will merely cut the dac output */
1939 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
1941 hwp->writeCrtc(hwp, 0x1A, crtc1A);
1947 /* This gets called at the start of each server generation */
1950 NVScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
1957 unsigned char *FBStart;
1961 * First get the ScrnInfoRec
1963 pScrn = xf86Screens[pScreen->myNum];
1965 hwp = VGAHWPTR(pScrn);
1968 /* Map the VGA memory when the primary video */
1970 hwp->MapSize = 0x10000;
1971 if (!vgaHWMapMem(pScrn))
1975 /* First init DRI/DRM */
1976 if (!NVDRIScreenInit(pScrn))
1979 /* Allocate and map memory areas we need */
1980 if (!NVMapMem(pScrn))
1983 if (!pNv->NoAccel) {
1984 /* Init DRM - Alloc FIFO */
1985 if (!NVInitDma(pScrn))
1988 /* setup graphics objects */
1989 if (!NVAccelCommonInit(pScrn))
1993 #if NOUVEAU_EXA_PIXMAPS
1994 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1995 0, NOUVEAU_ALIGN(pScrn->virtualX, 64) * NOUVEAU_ALIGN(pScrn->virtualY, 64) *
1996 (pScrn->bitsPerPixel >> 3), &pNv->FB)) {
1997 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to allocate memory for screen pixmap.\n");
2002 if (!pNv->randr12_enable) {
2003 /* Save the current state */
2005 /* Initialise the first mode */
2006 if (!NVModeInit(pScrn, pScrn->currentMode))
2009 /* Darken the screen for aesthetic reasons and set the viewport */
2010 NVSaveScreen(pScreen, SCREEN_SAVER_ON);
2011 pScrn->AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
2013 pScrn->memPhysBase = pNv->VRAMPhysical;
2014 pScrn->fbOffset = 0;
2016 if (!NVEnterVT(scrnIndex, 0))
2018 NVSaveScreen(pScreen, SCREEN_SAVER_ON);
2023 * The next step is to setup the screen's visuals, and initialise the
2024 * framebuffer code. In cases where the framebuffer's default
2025 * choices for things like visual layouts and bits per RGB are OK,
2026 * this may be as simple as calling the framebuffer's ScreenInit()
2027 * function. If not, the visuals will need to be setup before calling
2028 * a fb ScreenInit() function and fixed up after.
2030 * For most PC hardware at depths >= 8, the defaults that fb uses
2031 * are not appropriate. In this driver, we fixup the visuals after.
2035 * Reset the visual list.
2037 miClearVisualTypes();
2039 /* Setup the visuals we support. */
2041 if (!miSetVisualTypes(pScrn->depth,
2042 miGetDefaultVisualMask(pScrn->depth), 8,
2043 pScrn->defaultVisual))
2045 if (!miSetPixmapDepths ())
2049 * Call the framebuffer layer's ScreenInit function, and fill in other
2053 if (pNv->ShadowFB) {
2054 pNv->ShadowPitch = BitmapBytePad(pScrn->bitsPerPixel * pScrn->virtualX);
2055 pNv->ShadowPtr = xalloc(pNv->ShadowPitch * pScrn->virtualY);
2056 displayWidth = pNv->ShadowPitch / (pScrn->bitsPerPixel >> 3);
2057 FBStart = pNv->ShadowPtr;
2059 pNv->ShadowPtr = NULL;
2060 displayWidth = pScrn->displayWidth;
2061 FBStart = pNv->FB->map;
2064 switch (pScrn->bitsPerPixel) {
2067 ret = fbScreenInit(pScreen, FBStart, pScrn->virtualX, pScrn->virtualY,
2068 pScrn->xDpi, pScrn->yDpi,
2069 displayWidth, pScrn->bitsPerPixel);
2072 xf86DrvMsg(scrnIndex, X_ERROR,
2073 "Internal error: invalid bpp (%d) in NVScreenInit\n",
2074 pScrn->bitsPerPixel);
2081 /* Fixup RGB ordering */
2082 visual = pScreen->visuals + pScreen->numVisuals;
2083 while (--visual >= pScreen->visuals) {
2084 if ((visual->class | DynamicClass) == DirectColor) {
2085 visual->offsetRed = pScrn->offset.red;
2086 visual->offsetGreen = pScrn->offset.green;
2087 visual->offsetBlue = pScrn->offset.blue;
2088 visual->redMask = pScrn->mask.red;
2089 visual->greenMask = pScrn->mask.green;
2090 visual->blueMask = pScrn->mask.blue;
2094 fbPictureInit (pScreen, 0, 0);
2096 xf86SetBlackWhitePixels(pScreen);
2098 if (!pNv->NoAccel) {
2099 if (!NVExaInit(pScreen))
2101 } else if (pNv->VRAMPhysicalSize / 2 < NOUVEAU_ALIGN(pScrn->virtualX, 64) * NOUVEAU_ALIGN(pScrn->virtualY, 64) * (pScrn->bitsPerPixel >> 3)) {
2102 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "The virtual screen size's resolution is too big for the video RAM framebuffer at this colour depth.\n");
2107 miInitializeBackingStore(pScreen);
2108 xf86SetBackingStore(pScreen);
2109 xf86SetSilkenMouse(pScreen);
2111 /* Finish DRI init */
2112 NVDRIFinishScreenInit(pScrn);
2115 * Initialize software cursor.
2116 * Must precede creation of the default colormap.
2118 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
2121 * Initialize HW cursor layer.
2122 * Must follow software cursor initialization.
2124 if (pNv->HWCursor) {
2125 if (pNv->Architecture < NV_ARCH_50 && !pNv->randr12_enable)
2126 ret = NVCursorInit(pScreen);
2127 else if (pNv->Architecture < NV_ARCH_50 && pNv->randr12_enable)
2128 ret = NVCursorInitRandr12(pScreen);
2130 ret = NV50CursorInit(pScreen);
2133 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2134 "Hardware cursor initialization failed\n");
2135 pNv->HWCursor = FALSE;
2139 if (pNv->randr12_enable) {
2140 xf86DPMSInit(pScreen, xf86DPMSSet, 0);
2142 if (!xf86CrtcScreenInit(pScreen))
2146 /* Initialise default colourmap */
2147 if (!miCreateDefColormap(pScreen))
2151 * Initialize colormap layer.
2152 * Must follow initialization of the default colormap
2154 if (!pNv->randr12_enable && !pNv->kms_enable) {
2155 if(!xf86HandleColormaps(pScreen, 256, 8, NVDACLoadPalette,
2156 NULL, CMAP_RELOAD_ON_MODE_SWITCH | CMAP_PALETTED_TRUECOLOR))
2159 if (!xf86HandleColormaps(pScreen, 256, 8, NVLoadPalette,
2160 NULL, CMAP_PALETTED_TRUECOLOR))
2165 ShadowFBInit(pScreen, NVRefreshArea);
2167 if (!pNv->randr12_enable) {
2168 if(pNv->FlatPanel) {
2169 xf86DPMSInit(pScreen, NVDPMSSetLCD, 0);
2171 xf86DPMSInit(pScreen, NVDPMSSet, 0);
2175 pScrn->memPhysBase = pNv->VRAMPhysical;
2176 pScrn->fbOffset = 0;
2178 NVInitVideo(pScreen);
2180 pScreen->SaveScreen = NVSaveScreen;
2182 /* Wrap the current CloseScreen function */
2183 pNv->CloseScreen = pScreen->CloseScreen;
2184 pScreen->CloseScreen = NVCloseScreen;
2186 pNv->BlockHandler = pScreen->BlockHandler;
2187 pScreen->BlockHandler = NVBlockHandler;
2189 /* Report any unused options (only for the first generation) */
2190 if (serverGeneration == 1)
2191 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
2197 NVSaveScreen(ScreenPtr pScreen, int mode)
2199 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
2200 NVPtr pNv = NVPTR(pScrn);
2202 Bool on = xf86IsUnblank(mode);
2204 if (pNv->randr12_enable) {
2205 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
2206 if (pScrn->vtSema && pNv->Architecture < NV_ARCH_50) {
2207 for (i = 0; i < xf86_config->num_crtc; i++) {
2209 if (xf86_config->crtc[i]->enabled) {
2210 struct nouveau_crtc *nv_crtc = to_nouveau_crtc(xf86_config->crtc[i]);
2211 NVBlankScreen(pNv, nv_crtc->head, !on);
2219 return vgaHWSaveScreen(pScreen, mode);
2223 NVSave(ScrnInfoPtr pScrn)
2225 NVPtr pNv = NVPTR(pScrn);
2226 NVRegPtr nvReg = &pNv->SavedReg;
2228 if (pNv->randr12_enable) {
2229 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
2232 nv_save_restore_vga_fonts(pScrn, 1);
2234 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Saving crtcs\n");
2235 for (i = 0; i < xf86_config->num_crtc; i++)
2236 xf86_config->crtc[i]->funcs->save(xf86_config->crtc[i]);
2238 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Saving encoders\n");
2239 for (i = 0; i < pNv->dcb_table.entries; i++)
2240 nv_encoder_save(pScrn, &pNv->encoders[i]);
2242 vgaHWPtr pVga = VGAHWPTR(pScrn);
2243 vgaRegPtr vgaReg = &pVga->SavedReg;
2244 NVLockUnlock(pScrn, 0);
2245 if (pNv->twoHeads) {
2246 nvWriteCurVGA(pNv, NV_CIO_CRE_44, pNv->crtc_active[1] * 0x3);
2247 NVLockUnlock(pScrn, 0);
2250 NVDACSave(pScrn, vgaReg, nvReg, pNv->Primary);