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"
36 extern DisplayModePtr xf86ModesAdd(DisplayModePtr Modes, DisplayModePtr Additions);
39 * Forward definitions for the functions that make up the driver.
41 /* Mandatory functions */
42 static const OptionInfoRec * NVAvailableOptions(int chipid, int busid);
43 static void NVIdentify(int flags);
44 #ifndef XSERVER_LIBPCIACCESS
45 static Bool NVProbe(DriverPtr drv, int flags);
46 #endif /* XSERVER_LIBPCIACCESS */
47 static Bool NVPreInit(ScrnInfoPtr pScrn, int flags);
48 static Bool NVScreenInit(int Index, ScreenPtr pScreen, int argc,
50 static Bool NVEnterVT(int scrnIndex, int flags);
51 static void NVLeaveVT(int scrnIndex, int flags);
52 static Bool NVCloseScreen(int scrnIndex, ScreenPtr pScreen);
53 static Bool NVSaveScreen(ScreenPtr pScreen, int mode);
55 /* Optional functions */
56 static void NVFreeScreen(int scrnIndex, int flags);
57 static ModeStatus NVValidMode(int scrnIndex, DisplayModePtr mode,
58 Bool verbose, int flags);
60 static Bool NVDriverFunc(ScrnInfoPtr pScrnInfo, xorgDriverFuncOp op,
64 /* Internally used functions */
66 static Bool NVMapMem(ScrnInfoPtr pScrn);
67 static Bool NVUnmapMem(ScrnInfoPtr pScrn);
68 static void NVSave(ScrnInfoPtr pScrn);
69 static void NVRestore(ScrnInfoPtr pScrn);
70 static Bool NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
72 #ifdef XSERVER_LIBPCIACCESS
74 #define NOUVEAU_PCI_DEVICE(_vendor_id, _device_id) \
75 { (_vendor_id), (_device_id), PCI_MATCH_ANY, PCI_MATCH_ANY, 0x00030000, 0x00ffffff, 0 }
77 static const struct pci_id_match nouveau_device_match[] = {
78 NOUVEAU_PCI_DEVICE(PCI_VENDOR_NVIDIA, PCI_MATCH_ANY),
79 NOUVEAU_PCI_DEVICE(PCI_VENDOR_NVIDIA_SGS, PCI_MATCH_ANY),
83 static Bool NVPciProbe ( DriverPtr drv,
85 struct pci_device *dev,
86 intptr_t match_data );
88 #endif /* XSERVER_LIBPCIACCESS */
91 * This contains the functions needed by the server after loading the
92 * driver module. It must be supplied, and gets added the driver list by
93 * the Module Setup funtion in the dynamic case. In the static case a
94 * reference to this is compiled in, and this requires that the name of
95 * this DriverRec be an upper-case version of the driver name.
98 _X_EXPORT DriverRec NV = {
102 #ifdef XSERVER_LIBPCIACCESS
106 #endif /* XSERVER_LIBPCIACCESS */
111 #ifdef XSERVER_LIBPCIACCESS
112 nouveau_device_match,
114 #endif /* XSERVER_LIBPCIACCESS */
123 static struct NvFamily NVKnownFamilies[] =
125 { "RIVA TNT", "NV04" },
126 { "RIVA TNT2", "NV05" },
127 { "GeForce 256", "NV10" },
128 { "GeForce 2", "NV11, NV15" },
129 { "GeForce 4MX", "NV17, NV18" },
130 { "GeForce 3", "NV20" },
131 { "GeForce 4Ti", "NV25, NV28" },
132 { "GeForce FX", "NV3x" },
133 { "GeForce 6", "NV4x" },
134 { "GeForce 7", "G7x" },
135 { "GeForce 8", "G8x" },
140 * List of symbols from other modules that this module references. This
141 * list is used to tell the loader that it is OK for symbols here to be
142 * unresolved providing that it hasn't been told that they haven't been
143 * told that they are essential via a call to xf86LoaderReqSymbols() or
144 * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
145 * unresolved symbols that are not required.
148 static const char *vgahwSymbols[] = {
163 static const char *fbSymbols[] = {
169 static const char *exaSymbols[] = {
175 static const char *ramdacSymbols[] = {
176 "xf86CreateCursorInfoRec",
177 "xf86DestroyCursorInfoRec",
182 static const char *ddcSymbols[] = {
185 "xf86SetDDCproperties",
189 static const char *vbeSymbols[] = {
196 static const char *i2cSymbols[] = {
197 "xf86CreateI2CBusRec",
202 static const char *shadowSymbols[] = {
207 static const char *int10Symbols[] = {
213 const char *drmSymbols[] = {
218 "drmAgpVersionMajor",
219 "drmAgpVersionMinor",
229 "drmCommandWriteRead",
232 "drmCtlUninstHandler",
235 "drmGetInterruptFromBusID",
241 const char *driSymbols[] = {
245 "DRIFinishScreenInit",
246 "DRIGetSAREAPrivate",
251 "GlxSetVisualConfigs",
257 static MODULESETUPPROTO(nouveauSetup);
259 static XF86ModuleVersionInfo nouveauVersRec =
265 XORG_VERSION_CURRENT,
266 NV_MAJOR_VERSION, NV_MINOR_VERSION, NV_PATCHLEVEL,
267 ABI_CLASS_VIDEODRV, /* This is a video driver */
268 ABI_VIDEODRV_VERSION,
273 _X_EXPORT XF86ModuleData nouveauModuleData = { &nouveauVersRec, nouveauSetup, NULL };
277 * This is intentionally screen-independent. It indicates the binding
278 * choice made in the first PreInit.
280 static int pix24bpp = 0;
283 NVGetRec(ScrnInfoPtr pScrn)
286 * Allocate an NVRec, and hook it into pScrn->driverPrivate.
287 * pScrn->driverPrivate is initialised to NULL, so we can check if
288 * the allocation has already been done.
290 if (pScrn->driverPrivate != NULL)
293 pScrn->driverPrivate = xnfcalloc(sizeof(NVRec), 1);
300 NVFreeRec(ScrnInfoPtr pScrn)
302 if (pScrn->driverPrivate == NULL)
304 xfree(pScrn->driverPrivate);
305 pScrn->driverPrivate = NULL;
310 nouveauSetup(pointer module, pointer opts, int *errmaj, int *errmin)
312 static Bool setupDone = FALSE;
314 /* This module should be loaded only once, but check to be sure. */
318 /* The 1 here is needed to turn off a backwards compatibility mode */
319 /* Otherwise NVPciProbe() is not called */
320 xf86AddDriver(&NV, module, 1);
323 * Modules that this driver always requires may be loaded here
324 * by calling LoadSubModule().
327 * Tell the loader about symbols from other modules that this module
330 LoaderRefSymLists(vgahwSymbols, exaSymbols, fbSymbols,
334 ramdacSymbols, shadowSymbols,
335 i2cSymbols, ddcSymbols, vbeSymbols,
339 * The return value must be non-NULL on success even though there
340 * is no TearDownProc.
344 if (errmaj) *errmaj = LDR_ONCEONLY;
349 static const OptionInfoRec *
350 NVAvailableOptions(int chipid, int busid)
357 NVIdentify(int flags)
359 struct NvFamily *family;
362 xf86DrvMsg(0, X_INFO, NV_NAME " driver " NV_DRIVER_DATE "\n");
363 xf86DrvMsg(0, X_INFO, NV_NAME " driver for NVIDIA chipset families :\n");
365 /* maximum length for alignment */
366 family = NVKnownFamilies;
367 while(family->name && family->chipset)
369 maxLen = max(maxLen, strlen(family->name));
374 family = NVKnownFamilies;
375 while(family->name && family->chipset)
377 size_t len = strlen(family->name);
378 xf86ErrorF("\t%s", family->name);
384 xf86ErrorF("(%s)\n", family->chipset);
391 NVGetScrnInfoRec(PciChipsets *chips, int chip)
395 pScrn = xf86ConfigPciEntity(NULL, 0, chip,
396 chips, NULL, NULL, NULL,
399 if(!pScrn) return FALSE;
401 pScrn->driverVersion = NV_VERSION;
402 pScrn->driverName = NV_DRIVER_NAME;
403 pScrn->name = NV_NAME;
405 #ifndef XSERVER_LIBPCIACCESS
406 pScrn->Probe = NVProbe;
410 pScrn->PreInit = NVPreInit;
411 pScrn->ScreenInit = NVScreenInit;
412 pScrn->SwitchMode = NVSwitchMode;
413 pScrn->AdjustFrame = NVAdjustFrame;
414 pScrn->EnterVT = NVEnterVT;
415 pScrn->LeaveVT = NVLeaveVT;
416 pScrn->FreeScreen = NVFreeScreen;
417 pScrn->ValidMode = NVValidMode;
422 /* This returns architecture in hexdecimal, so NV40 is 0x40 */
423 static char NVGetArchitecture (volatile CARD32 *regs)
425 char architecture = 0;
427 /* We're dealing with >=NV10 */
428 if ((regs[0] & 0x0f000000) > 0 ) {
429 /* Bit 27-20 contain the architecture in hex */
430 architecture = (regs[0] & 0xff00000) >> 20;
432 } else if ((regs[0] & 0xff00fff0) == 0x20004000) {
439 /* Reading the pci_id from the card registers is the most reliable way */
440 static CARD32 NVGetPCIID (volatile CARD32 *regs)
444 char architecture = NVGetArchitecture(regs);
446 /* Dealing with an unknown or unsupported card */
447 if (architecture == 0) {
451 if (architecture >= 0x04 && architecture <= 0x4F) {
452 pci_id = regs[0x1800/4];
453 } else if (architecture >= 0x50 && architecture <= 0x5F) {
454 pci_id = regs[0x88000/4];
459 /* A pci-id can be inverted, we must correct this */
460 if ((pci_id & 0xffff) == PCI_VENDOR_NVIDIA) {
461 pci_id = (PCI_VENDOR_NVIDIA << 16) | (pci_id >> 16);
462 } else if ((pci_id & 0xffff) == PCI_VENDOR_NVIDIA_SGS) {
463 pci_id = (PCI_VENDOR_NVIDIA_SGS << 16) | (pci_id >> 16);
464 /* Checking endian issues */
466 /* PCI_VENDOR_NVIDIA = 0x10DE */
467 if ((pci_id & (0xffff << 16)) == (0xDE10 << 16)) { /* wrong endian */
468 pci_id = (PCI_VENDOR_NVIDIA << 16) | ((pci_id << 8) & 0x0000ff00) |
469 ((pci_id >> 8) & 0x000000ff);
470 /* PCI_VENDOR_NVIDIA_SGS = 0x12D2 */
471 } else if ((pci_id & (0xffff << 16)) == (0xD212 << 16)) { /* wrong endian */
472 pci_id = (PCI_VENDOR_NVIDIA_SGS << 16) | ((pci_id << 8) & 0x0000ff00) |
473 ((pci_id >> 8) & 0x000000ff);
480 #ifdef XSERVER_LIBPCIACCESS
482 static Bool NVPciProbe ( DriverPtr drv,
484 struct pci_device *dev,
485 intptr_t match_data )
487 ScrnInfoPtr pScrn = NULL;
489 volatile CARD32 *regs = NULL;
491 /* Temporary mapping to discover the architecture */
492 pci_device_map_memory_range(dev, PCI_DEV_MEM_BASE(dev, 0), 0x90000, FALSE, ®s);
494 /* Bit 27-20 contain the architecture in hex */
495 char architecture = (regs[0] & 0xff00000) >> 20;
497 CARD32 pci_id = NVGetPCIID(regs);
499 pci_device_unmap_memory_range(dev, regs, 0x90000);
501 /* Currently NV04 up to NV83 is supported */
502 /* For safety the fictional NV8F is used */
503 if (architecture >= 0x04 && architecture <= 0x8F) {
505 /* At this stage the pci_id should be ok, so we generate this to avoid list duplication */
506 const PciChipsets NVChipsets[] = {
507 { pci_id, pci_id, RES_SHARED_VGA },
508 { -1, -1, RES_UNDEFINED }
511 pScrn = xf86ConfigPciEntity(pScrn, 0, entity_num, NVChipsets,
512 NULL, NULL, NULL, NULL, NULL);
515 pScrn->driverVersion = NV_VERSION;
516 pScrn->driverName = NV_DRIVER_NAME;
517 pScrn->name = NV_NAME;
520 pScrn->PreInit = NVPreInit;
521 pScrn->ScreenInit = NVScreenInit;
522 pScrn->SwitchMode = NVSwitchMode;
523 pScrn->AdjustFrame = NVAdjustFrame;
524 pScrn->EnterVT = NVEnterVT;
525 pScrn->LeaveVT = NVLeaveVT;
526 pScrn->FreeScreen = NVFreeScreen;
527 pScrn->ValidMode = NVValidMode;
536 #endif /* XSERVER_LIBPCIACCESS */
538 #define MAX_CHIPS MAXSCREENS
540 #ifndef XSERVER_LIBPCIACCESS
543 NVProbe(DriverPtr drv, int flags)
546 GDevPtr *devSections;
548 SymTabRec NVChipsets[MAX_CHIPS + 1];
549 PciChipsets NVPciChipsets[MAX_CHIPS + 1];
553 Bool foundScreen = FALSE;
555 if ((numDevSections = xf86MatchDevice(NV_DRIVER_NAME, &devSections)) <= 0)
556 return FALSE; /* no matching device section */
558 if (!(ppPci = xf86GetPciVideoInfo()))
559 return FALSE; /* no PCI cards found */
563 /* Create the NVChipsets and NVPciChipsets from found devices */
564 while (*ppPci && (numUsed < MAX_CHIPS)) {
565 if (((*ppPci)->vendor == PCI_VENDOR_NVIDIA_SGS) ||
566 ((*ppPci)->vendor == PCI_VENDOR_NVIDIA))
568 volatile CARD32 *regs;
571 PCI_DEV_READ_LONG(*ppPci, PCI_CMD_STAT_REG, &pcicmd);
572 /* Enable reading memory? */
573 PCI_DEV_WRITE_LONG(*ppPci, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
575 regs = xf86MapPciMem(-1, VIDMEM_MMIO, PCI_DEV_TAG(*ppPci), PCI_DEV_MEM_BASE(*ppPci, 0), 0x90000);
576 int pciid = NVGetPCIID(regs);
578 char architecture = NVGetArchitecture(regs);
580 sprintf(name, "NVIDIA NV%02X", architecture);
581 /* NV04 upto NV83 is supported, NV8F is fictive limit */
582 if (architecture >= 0x04 && architecture <= 0x8F) {
583 NVChipsets[numUsed].token = pciid;
584 NVChipsets[numUsed].name = name;
585 NVPciChipsets[numUsed].numChipset = pciid;
586 NVPciChipsets[numUsed].PCIid = pciid;
587 NVPciChipsets[numUsed].resList = RES_SHARED_VGA;
590 xf86UnMapVidMem(-1, (pointer)regs, 0x90000);
592 /* Reset previous state */
593 PCI_DEV_WRITE_LONG(*ppPci, PCI_CMD_STAT_REG, pcicmd);
598 /* terminate the list */
599 NVChipsets[numUsed].token = -1;
600 NVChipsets[numUsed].name = NULL;
601 NVPciChipsets[numUsed].numChipset = -1;
602 NVPciChipsets[numUsed].PCIid = -1;
603 NVPciChipsets[numUsed].resList = RES_UNDEFINED;
605 numUsed = xf86MatchPciInstances(NV_NAME, 0, NVChipsets, NVPciChipsets,
606 devSections, numDevSections, drv,
613 if (flags & PROBE_DETECT) {
616 for (i = 0; i < numUsed; i++) {
619 pPci = xf86GetPciInfoForEntity(usedChips[i]);
620 if (NVGetScrnInfoRec(NVPciChipsets, usedChips[i])) {
631 #endif /* XSERVER_LIBPCIACCESS */
634 * This function is needed by the XF86VideMode extension which is used by
635 * the current pre-randr clients. The API covers only one screen, but
636 * implementing the latest modesetting framework like done in the Intel
637 * driver is more than a few lines of patch, the randr-1.2 branch in its
638 * current form cannot the mode switching in a perfect way right now.
640 * As there are effors to bring modesetting into the kernel, controlled
641 * thru the drm module, of which nouveu currently requires its own version,
642 * one could even try to go one step further and try to bring the nouveau
643 * modesetting into the nouveau kernel module.c (as a first step which does
644 * not require a kernel patch), which would increase the chances that the
645 * text console is properly restored after X dies as the kernel can simply
646 * restore the text console when the process which has changed modes thru
647 * /dev/drm has been disconnected from the device.
649 * The current implementation simply tries to set each crtc to the mode
650 * for which the application asks for, hoping that one of them gives a
651 * usable monitor display (no error handling implemented), and sets
652 * the viewport of each crtc to (0,0), which means essentially clone
653 * mode with all monitors which managed to switch to the mode showing
654 * top left area of the framebuffer memory if the application's window
655 * is there. This is essentially what the Intel driver did in earlyer
656 * versions. To restore a LeftOf/RightOf layout, you two randr calls
657 * seem to be neccessary, one which sets the reversed layout, followed
658 * by one which sets the desired layout:
660 * xrandr --output Digital-1 --left-of Digital-0
661 * xrandr --output Digital-0 --left-of Digital-1
663 * FIXME: This could be fixed by getting the current viewports for the
664 * CRTCs and use these during mode settings, or (preferably) by getting
665 * the current screen layout and adapting the new viewports so that
666 * a new, continuos screen layout with the same monitor arrangement,
667 * but in the new mode is set up.
670 NVSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
672 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
673 NVPtr pNv = NVPTR(pScrn);
676 if (pNv->randr12_enable) {
677 NVFBLayout *pLayout = &pNv->CurrentLayout;
679 if (pLayout->mode != mode) {
680 /* This needs to be fixed with error handling */
681 NVSetMode(pScrn, mode);
682 pLayout->mode = mode;
685 pLayout->mode = mode;
688 return NVModeInit(xf86Screens[scrnIndex], mode);
693 * This function is used to initialize the Start Address - the first
694 * displayed location in the video memory.
696 /* Usually mandatory */
698 NVAdjustFrame(int scrnIndex, int x, int y, int flags)
700 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
702 NVPtr pNv = NVPTR(pScrn);
703 NVFBLayout *pLayout = &pNv->CurrentLayout;
705 if (pNv->randr12_enable) {
706 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
708 xf86CrtcPtr crtc = config->output[config->compat_output]->crtc;
710 if (crtc && crtc->enabled) {
711 NVCrtcSetBase(crtc, x, y);
714 startAddr = (((y*pLayout->displayWidth)+x)*(pLayout->bitsPerPixel/8));
715 startAddr += pNv->FB->offset;
716 NVSetStartAddress(pNv, startAddr);
721 NVResetCrtcConfig(ScrnInfoPtr pScrn, int set)
723 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
724 NVPtr pNv = NVPTR(pScrn);
728 for (i = 0; i < config->num_crtc; i++) {
729 xf86CrtcPtr crtc = config->crtc[i];
730 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
735 regp = &pNv->ModeReg.crtc_reg[nv_crtc->crtc];
739 nvWriteCRTC(pNv, nv_crtc->crtc, NV_CRTC_FSEL, val);
744 NV50AcquireDisplay(ScrnInfoPtr pScrn)
746 if (!NV50DispInit(pScrn))
748 if (!NV50CursorAcquire(pScrn))
750 xf86SetDesiredModes(pScrn);
756 NV50ReleaseDisplay(ScrnInfoPtr pScrn)
758 NV50CursorRelease(pScrn);
759 NV50DispShutdown(pScrn);
765 * This is called when VT switching back to the X server. Its job is
766 * to reinitialise the video mode.
768 * We may wish to unmap video/MMIO memory too.
773 NVEnterVT(int scrnIndex, int flags)
775 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
776 NVPtr pNv = NVPTR(pScrn);
778 if (pNv->randr12_enable) {
779 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
780 pScrn->vtSema = TRUE;
782 if (pNv->Architecture == NV_ARCH_50) {
783 if (!NV50AcquireDisplay(pScrn))
788 /* Save the current state */
789 if (pNv->SaveGeneration != serverGeneration) {
790 pNv->SaveGeneration = serverGeneration;
794 NVResetCrtcConfig(pScrn, 0);
795 if (!xf86SetDesiredModes(pScrn))
797 NVResetCrtcConfig(pScrn, 1);
800 if (!NVModeInit(pScrn, pScrn->currentMode))
804 NVAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
805 if(pNv->overlayAdaptor)
812 * This is called when VT switching away from the X server. Its job is
813 * to restore the previous (text) mode.
815 * We may wish to remap video/MMIO memory too.
820 NVLeaveVT(int scrnIndex, int flags)
822 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
823 NVPtr pNv = NVPTR(pScrn);
825 if (pNv->Architecture == NV_ARCH_50) {
826 NV50ReleaseDisplay(pScrn);
831 if (!pNv->randr12_enable)
832 NVLockUnlock(pNv, 1);
845 ScreenPtr pScreen = screenInfo.screens[i];
846 ScrnInfoPtr pScrnInfo = xf86Screens[i];
847 NVPtr pNv = NVPTR(pScrnInfo);
849 if (pNv->DMAKickoffCallback)
850 (*pNv->DMAKickoffCallback)(pNv);
852 pScreen->BlockHandler = pNv->BlockHandler;
853 (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
854 pScreen->BlockHandler = NVBlockHandler;
856 if (pNv->VideoTimerCallback)
857 (*pNv->VideoTimerCallback)(pScrnInfo, currentTime.milliseconds);
863 * This is called at the end of each server generation. It restores the
864 * original (text) mode. It should also unmap the video memory, and free
865 * any per-generation data allocated by the driver. It should finish
866 * by unwrapping and calling the saved CloseScreen function.
871 NVCloseScreen(int scrnIndex, ScreenPtr pScreen)
873 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
874 NVPtr pNv = NVPTR(pScrn);
877 pScrn->vtSema = FALSE;
878 if (pNv->Architecture == NV_ARCH_50) {
879 NV50ReleaseDisplay(pScrn);
883 if (!pNv->randr12_enable)
884 NVLockUnlock(pNv, 1);
889 vgaHWUnmapMem(pScrn);
890 if (pNv->CursorInfoRec)
891 xf86DestroyCursorInfoRec(pNv->CursorInfoRec);
893 xfree(pNv->ShadowPtr);
894 if (pNv->overlayAdaptor)
895 xfree(pNv->overlayAdaptor);
896 if (pNv->blitAdaptor)
897 xfree(pNv->blitAdaptor);
899 pScrn->vtSema = FALSE;
900 pScreen->CloseScreen = pNv->CloseScreen;
901 pScreen->BlockHandler = pNv->BlockHandler;
902 return (*pScreen->CloseScreen)(scrnIndex, pScreen);
905 /* Free up any persistent data structures */
909 NVFreeScreen(int scrnIndex, int flags)
912 * This only gets called when a screen is being deleted. It does not
913 * get called routinely at the end of a server generation.
915 if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
916 vgaHWFreeHWRec(xf86Screens[scrnIndex]);
917 NVFreeRec(xf86Screens[scrnIndex]);
921 /* Checks if a mode is suitable for the selected chipset. */
925 NVValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
927 NVPtr pNv = NVPTR(xf86Screens[scrnIndex]);
929 if(pNv->fpWidth && pNv->fpHeight)
930 if((pNv->fpWidth < mode->HDisplay) || (pNv->fpHeight < mode->VDisplay))
937 nvProbeDDC(ScrnInfoPtr pScrn, int index)
941 if (xf86LoadSubModule(pScrn, "vbe")) {
942 pVbe = VBEInit(NULL,index);
943 ConfiguredMonitor = vbeDoEDID(pVbe, NULL);
949 Bool NVI2CInit(ScrnInfoPtr pScrn)
953 if (xf86LoadSubModule(pScrn, mod)) {
954 xf86LoaderReqSymLists(i2cSymbols,NULL);
957 if(xf86LoadSubModule(pScrn, mod)) {
958 xf86LoaderReqSymLists(ddcSymbols, NULL);
959 return NVDACi2cInit(pScrn);
963 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
964 "Couldn't load %s module. DDC probing can't be done\n", mod);
969 static Bool NVPreInitDRI(ScrnInfoPtr pScrn)
971 NVPtr pNv = NVPTR(pScrn);
973 if (!NVDRIGetVersion(pScrn))
976 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
977 "[dri] Found DRI library version %d.%d.%d and kernel"
978 " module version %d.%d.%d\n",
979 pNv->pLibDRMVersion->version_major,
980 pNv->pLibDRMVersion->version_minor,
981 pNv->pLibDRMVersion->version_patchlevel,
982 pNv->pKernelDRMVersion->version_major,
983 pNv->pKernelDRMVersion->version_minor,
984 pNv->pKernelDRMVersion->version_patchlevel);
991 nv_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
993 scrn->virtualX = width;
994 scrn->virtualY = height;
998 static const xf86CrtcConfigFuncsRec nv_xf86crtc_config_funcs = {
1002 #define NVPreInitFail(fmt, args...) do { \
1003 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%d: "fmt, __LINE__, ##args); \
1005 xf86FreeInt10(pNv->pInt10); \
1012 NVPreInit(ScrnInfoPtr pScrn, int flags)
1014 xf86CrtcConfigPtr xf86_config;
1017 int i, max_width, max_height;
1018 ClockRangePtr clockRanges;
1020 int config_mon_rates = FALSE;
1023 if (flags & PROBE_DETECT) {
1024 EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1032 nvProbeDDC(pScrn, i);
1037 * Note: This function is only called once at server startup, and
1038 * not at the start of each server generation. This means that
1039 * only things that are persistent across server generations can
1040 * be initialised here. xf86Screens[] is (pScrn is a pointer to one
1041 * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex()
1042 * are too, and should be used for data that must persist across
1043 * server generations.
1045 * Per-generation data should be allocated with
1046 * AllocateScreenPrivateIndex() from the ScreenInit() function.
1049 /* Check the number of entities, and fail if it isn't one. */
1050 if (pScrn->numEntities != 1)
1053 /* Allocate the NVRec driverPrivate */
1054 if (!NVGetRec(pScrn)) {
1059 /* Get the entity, and make sure it is PCI. */
1060 pNv->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1061 if (pNv->pEnt->location.type != BUS_PCI)
1064 /* Find the PCI info for this screen */
1065 pNv->PciInfo = xf86GetPciInfoForEntity(pNv->pEnt->index);
1066 #ifndef XSERVER_LIBPCIACCESS
1067 pNv->PciTag = pciTag(pNv->PciInfo->bus, pNv->PciInfo->device,
1068 pNv->PciInfo->func);
1069 #endif /* XSERVER_LIBPCIACCESS */
1071 pNv->Primary = xf86IsPrimaryPci(pNv->PciInfo);
1073 /* Initialize the card through int10 interface if needed */
1074 if (xf86LoadSubModule(pScrn, "int10")) {
1075 xf86LoaderReqSymLists(int10Symbols, NULL);
1076 #if !defined(__alpha__) && !defined(__powerpc__)
1077 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initializing int10\n");
1078 pNv->pInt10 = xf86InitInt10(pNv->pEnt->index);
1082 xf86SetOperatingState(resVgaIo, pNv->pEnt->index, ResUnusedOpr);
1083 xf86SetOperatingState(resVgaMem, pNv->pEnt->index, ResDisableOpr);
1085 /* Set pScrn->monitor */
1086 pScrn->monitor = pScrn->confScreen->monitor;
1088 volatile CARD32 *regs = NULL;
1089 #ifdef XSERVER_LIBPCIACCESS
1090 pci_device_map_memory_range(pNv->PciInfo, PCI_DEV_MEM_BASE(pNv->PciInfo, 0), 0x90000, FALSE, ®s);
1091 pNv->Chipset = NVGetPCIID(regs) & 0xffff;
1092 pNv->NVArch = NVGetArchitecture(regs);
1093 pci_device_unmap_memory_range(pNv->PciInfo, regs, 0x90000);
1096 PCI_DEV_READ_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, &pcicmd);
1097 /* Enable reading memory? */
1098 PCI_DEV_WRITE_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
1099 regs = xf86MapPciMem(-1, VIDMEM_MMIO, pNv->PciTag, PCI_DEV_MEM_BASE(pNv->PciInfo, 0), 0x90000);
1100 pNv->Chipset = NVGetPCIID(regs) & 0xffff;
1101 pNv->NVArch = NVGetArchitecture(regs);
1102 xf86UnMapVidMem(-1, (pointer)regs, 0x90000);
1103 /* Reset previous state */
1104 PCI_DEV_WRITE_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, pcicmd);
1105 #endif /* XSERVER_LIBPCIACCESS */
1107 pScrn->chipset = malloc(sizeof(char) * 25);
1108 sprintf(pScrn->chipset, "NVIDIA NV%02X", pNv->NVArch);
1110 if(!pScrn->chipset) {
1111 pScrn->chipset = "Unknown NVIDIA";
1115 * This shouldn't happen because such problems should be caught in
1116 * NVProbe(), but check it just in case.
1118 if (pScrn->chipset == NULL)
1119 NVPreInitFail("ChipID 0x%04X is not recognised\n", pNv->Chipset);
1121 if (pNv->NVArch < 0x04)
1122 NVPreInitFail("Chipset \"%s\" is not recognised\n", pScrn->chipset);
1124 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Chipset: \"%s\"\n", pScrn->chipset);
1126 /* The highest architecture currently supported is NV5x */
1127 if (pNv->NVArch >= 0x50) {
1128 pNv->Architecture = NV_ARCH_50;
1129 } else if (pNv->NVArch >= 0x40) {
1130 pNv->Architecture = NV_ARCH_40;
1131 } else if (pNv->NVArch >= 0x30) {
1132 pNv->Architecture = NV_ARCH_30;
1133 } else if (pNv->NVArch >= 0x20) {
1134 pNv->Architecture = NV_ARCH_20;
1135 } else if (pNv->NVArch >= 0x10) {
1136 pNv->Architecture = NV_ARCH_10;
1137 } else if (pNv->NVArch >= 0x04) {
1138 pNv->Architecture = NV_ARCH_04;
1139 /* The lowest architecture currently supported is NV04 */
1145 * The first thing we should figure out is the depth, bpp, etc.
1148 if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support32bppFb)) {
1149 NVPreInitFail("\n");
1151 /* Check that the returned depth is one we support */
1152 switch (pScrn->depth) {
1160 NVPreInitFail("Given depth (%d) is not supported by this driver\n",
1164 xf86PrintDepthBpp(pScrn);
1166 /* Get the depth24 pixmap format */
1167 if (pScrn->depth == 24 && pix24bpp == 0)
1168 pix24bpp = xf86GetBppFromDepth(pScrn, 24);
1171 * This must happen after pScrn->display has been set because
1172 * xf86SetWeight references it.
1174 if (pScrn->depth > 8) {
1175 /* The defaults are OK for us */
1176 rgb zeros = {0, 0, 0};
1178 if (!xf86SetWeight(pScrn, zeros, zeros)) {
1179 NVPreInitFail("\n");
1183 if (!xf86SetDefaultVisual(pScrn, -1)) {
1184 NVPreInitFail("\n");
1186 /* We don't currently support DirectColor at > 8bpp */
1187 if (pScrn->depth > 8 && (pScrn->defaultVisual != TrueColor)) {
1188 NVPreInitFail("Given default visual"
1189 " (%s) is not supported at depth %d\n",
1190 xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
1195 /* The vgahw module should be loaded here when needed */
1196 if (!xf86LoadSubModule(pScrn, "vgahw")) {
1197 NVPreInitFail("\n");
1200 xf86LoaderReqSymLists(vgahwSymbols, NULL);
1203 * Allocate a vgaHWRec
1205 if (!vgaHWGetHWRec(pScrn)) {
1206 NVPreInitFail("\n");
1209 /* We use a programmable clock */
1210 pScrn->progClock = TRUE;
1212 /* Collect all of the relevant option flags (fill in pScrn->options) */
1213 xf86CollectOptions(pScrn, NULL);
1215 /* Process the options */
1216 if (!(pNv->Options = xalloc(sizeof(NVOptions))))
1218 memcpy(pNv->Options, NVOptions, sizeof(NVOptions));
1219 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pNv->Options);
1221 /* Set the bits per RGB for 8bpp mode */
1222 if (pScrn->depth == 8)
1227 if (pNv->Architecture == NV_ARCH_50) {
1228 pNv->randr12_enable = TRUE;
1230 pNv->randr12_enable = FALSE;
1231 if (xf86ReturnOptValBool(pNv->Options, OPTION_RANDR12, FALSE)) {
1232 pNv->randr12_enable = TRUE;
1235 xf86DrvMsg(pScrn->scrnIndex, from, "Randr1.2 support %sabled\n", pNv->randr12_enable ? "en" : "dis");
1237 pNv->HWCursor = TRUE;
1239 * The preferred method is to use the "hw cursor" option as a tri-state
1240 * option, with the default set above.
1242 if (xf86GetOptValBool(pNv->Options, OPTION_HW_CURSOR, &pNv->HWCursor)) {
1245 /* For compatibility, accept this too (as an override) */
1246 if (xf86ReturnOptValBool(pNv->Options, OPTION_SW_CURSOR, FALSE)) {
1248 pNv->HWCursor = FALSE;
1250 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
1251 pNv->HWCursor ? "HW" : "SW");
1253 pNv->FpScale = TRUE;
1254 if (xf86GetOptValBool(pNv->Options, OPTION_FP_SCALE, &pNv->FpScale)) {
1255 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Flat panel scaling %s\n",
1256 pNv->FpScale ? "on" : "off");
1258 if (xf86ReturnOptValBool(pNv->Options, OPTION_NOACCEL, FALSE)) {
1259 pNv->NoAccel = TRUE;
1260 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1262 if (xf86ReturnOptValBool(pNv->Options, OPTION_SHADOW_FB, FALSE)) {
1263 pNv->ShadowFB = TRUE;
1264 pNv->NoAccel = TRUE;
1265 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1266 "Using \"Shadow Framebuffer\" - acceleration disabled\n");
1270 pNv->RandRRotation = FALSE;
1271 if ((s = xf86GetOptValString(pNv->Options, OPTION_ROTATE))) {
1272 if(!xf86NameCmp(s, "CW")) {
1273 pNv->ShadowFB = TRUE;
1274 pNv->NoAccel = TRUE;
1275 pNv->HWCursor = FALSE;
1277 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1278 "Rotating screen clockwise - acceleration disabled\n");
1280 if(!xf86NameCmp(s, "CCW")) {
1281 pNv->ShadowFB = TRUE;
1282 pNv->NoAccel = TRUE;
1283 pNv->HWCursor = FALSE;
1285 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1286 "Rotating screen counter clockwise - acceleration disabled\n");
1288 if(!xf86NameCmp(s, "RandR")) {
1290 pNv->ShadowFB = TRUE;
1291 pNv->NoAccel = TRUE;
1292 pNv->HWCursor = FALSE;
1293 pNv->RandRRotation = TRUE;
1294 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1295 "Using RandR rotation - acceleration disabled\n");
1297 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
1298 "This driver was not compiled with support for the Resize and "
1299 "Rotate extension. Cannot honor 'Option \"Rotate\" "
1303 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1304 "\"%s\" is not a valid value for Option \"Rotate\"\n", s);
1305 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1306 "Valid options are \"CW\", \"CCW\", and \"RandR\"\n");
1310 if(xf86GetOptValInteger(pNv->Options, OPTION_VIDEO_KEY, &(pNv->videoKey))) {
1311 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n",
1314 pNv->videoKey = (1 << pScrn->offset.red) |
1315 (1 << pScrn->offset.green) |
1316 (((pScrn->mask.blue >> pScrn->offset.blue) - 1) << pScrn->offset.blue);
1319 if (xf86GetOptValBool(pNv->Options, OPTION_FLAT_PANEL, &(pNv->FlatPanel))) {
1320 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "forcing %s usage\n",
1321 pNv->FlatPanel ? "DFP" : "CRTC");
1323 pNv->FlatPanel = -1; /* autodetect later */
1326 pNv->FPDither = FALSE;
1327 if (xf86GetOptValBool(pNv->Options, OPTION_FP_DITHER, &(pNv->FPDither)))
1328 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "enabling flat panel dither\n");
1330 if (xf86GetOptValInteger(pNv->Options, OPTION_CRTC_NUMBER,
1333 if((pNv->CRTCnumber < 0) || (pNv->CRTCnumber > 1)) {
1334 pNv->CRTCnumber = -1;
1335 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1336 "Invalid CRTC number. Must be 0 or 1\n");
1339 pNv->CRTCnumber = -1; /* autodetect later */
1343 if (xf86GetOptValInteger(pNv->Options, OPTION_FP_TWEAK,
1346 pNv->usePanelTweak = TRUE;
1348 pNv->usePanelTweak = FALSE;
1351 if (pNv->pEnt->device->MemBase != 0) {
1352 /* Require that the config file value matches one of the PCI values. */
1353 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->MemBase)) {
1355 "MemBase 0x%08lX doesn't match any PCI base register.\n",
1356 pNv->pEnt->device->MemBase);
1358 pNv->VRAMPhysical = pNv->pEnt->device->MemBase;
1361 if (PCI_DEV_MEM_BASE(pNv->PciInfo, 1) != 0) {
1362 pNv->VRAMPhysical = PCI_DEV_MEM_BASE(pNv->PciInfo, 1) & 0xff800000;
1365 NVPreInitFail("No valid FB address in PCI config space\n");
1369 xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
1370 (unsigned long)pNv->VRAMPhysical);
1372 if (pNv->pEnt->device->IOBase != 0) {
1373 /* Require that the config file value matches one of the PCI values. */
1374 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->IOBase)) {
1375 NVPreInitFail("IOBase 0x%08lX doesn't match any PCI base register.\n",
1376 pNv->pEnt->device->IOBase);
1378 pNv->IOAddress = pNv->pEnt->device->IOBase;
1381 if (PCI_DEV_MEM_BASE(pNv->PciInfo, 0) != 0) {
1382 pNv->IOAddress = PCI_DEV_MEM_BASE(pNv->PciInfo, 0) & 0xffffc000;
1385 NVPreInitFail("No valid MMIO address in PCI config space\n");
1388 xf86DrvMsg(pScrn->scrnIndex, from, "MMIO registers at 0x%lX\n",
1389 (unsigned long)pNv->IOAddress);
1391 if (xf86RegisterResources(pNv->pEnt->index, NULL, ResExclusive)) {
1392 NVPreInitFail("xf86RegisterResources() found resource conflicts\n");
1395 pNv->alphaCursor = (pNv->Architecture >= NV_ARCH_10) &&
1396 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10);
1398 if (pNv->randr12_enable) {
1399 /* Allocate an xf86CrtcConfig */
1400 xf86CrtcConfigInit(pScrn, &nv_xf86crtc_config_funcs);
1401 xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1404 xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, 2048);
1407 if (NVPreInitDRI(pScrn) == FALSE) {
1408 NVPreInitFail("\n");
1411 if (!pNv->randr12_enable) {
1412 if ((pScrn->monitor->nHsync == 0) &&
1413 (pScrn->monitor->nVrefresh == 0))
1414 config_mon_rates = FALSE;
1416 config_mon_rates = TRUE;
1419 NVCommonSetup(pScrn);
1421 if (pNv->randr12_enable) {
1422 if (pNv->Architecture < NV_ARCH_50) {
1425 num_crtc = pNv->twoHeads ? 2 : 1;
1426 for (i = 0; i < num_crtc; i++) {
1427 nv_crtc_init(pScrn, i);
1430 NvSetupOutputs(pScrn);
1432 if (!NV50DispPreInit(pScrn))
1433 NVPreInitFail("\n");
1434 if (!NV50CreateOutputs(pScrn))
1435 NVPreInitFail("\n");
1436 NV50DispCreateCrtcs(pScrn);
1439 if (!xf86InitialConfiguration(pScrn, FALSE))
1440 NVPreInitFail("No valid modes.\n");
1443 pScrn->videoRam = pNv->RamAmountKBytes;
1444 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kBytes\n",
1447 pNv->VRAMPhysicalSize = pScrn->videoRam * 1024;
1450 * If the driver can do gamma correction, it should call xf86SetGamma()
1455 Gamma zeros = {0.0, 0.0, 0.0};
1457 if (!xf86SetGamma(pScrn, zeros)) {
1458 NVPreInitFail("\n");
1463 * Setup the ClockRanges, which describe what clock ranges are available,
1464 * and what sort of modes they can be used for.
1467 clockRanges = xnfcalloc(sizeof(ClockRange), 1);
1468 clockRanges->next = NULL;
1469 clockRanges->minClock = pNv->MinVClockFreqKHz;
1470 clockRanges->maxClock = pNv->MaxVClockFreqKHz;
1471 clockRanges->clockIndex = -1; /* programmable */
1472 clockRanges->doubleScanAllowed = TRUE;
1473 if((pNv->Architecture == NV_ARCH_20) ||
1474 ((pNv->Architecture == NV_ARCH_10) &&
1475 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10) &&
1476 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV15)))
1479 clockRanges->interlaceAllowed = FALSE;
1481 clockRanges->interlaceAllowed = TRUE;
1484 if(pNv->FlatPanel == 1) {
1485 clockRanges->interlaceAllowed = FALSE;
1486 clockRanges->doubleScanAllowed = FALSE;
1489 if(pNv->Architecture < NV_ARCH_10) {
1490 max_width = (pScrn->bitsPerPixel > 16) ? 2032 : 2048;
1493 max_width = (pScrn->bitsPerPixel > 16) ? 4080 : 4096;
1498 /* If DFP, add a modeline corresponding to its panel size */
1499 if (pNv->FlatPanel && !pNv->Television && pNv->fpWidth && pNv->fpHeight) {
1500 DisplayModePtr Mode;
1502 Mode = xnfcalloc(1, sizeof(DisplayModeRec));
1503 Mode = xf86CVTMode(pNv->fpWidth, pNv->fpHeight, 60.00, TRUE, FALSE);
1504 Mode->type = M_T_DRIVER;
1505 pScrn->monitor->Modes = xf86ModesAdd(pScrn->monitor->Modes, Mode);
1507 if (!config_mon_rates) {
1509 Mode->HSync = ((float) Mode->Clock ) / ((float) Mode->HTotal);
1510 if (!Mode->VRefresh)
1511 Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) /
1512 ((float) (Mode->HTotal * Mode->VTotal));
1514 if (Mode->HSync < pScrn->monitor->hsync[0].lo)
1515 pScrn->monitor->hsync[0].lo = Mode->HSync;
1516 if (Mode->HSync > pScrn->monitor->hsync[0].hi)
1517 pScrn->monitor->hsync[0].hi = Mode->HSync;
1518 if (Mode->VRefresh < pScrn->monitor->vrefresh[0].lo)
1519 pScrn->monitor->vrefresh[0].lo = Mode->VRefresh;
1520 if (Mode->VRefresh > pScrn->monitor->vrefresh[0].hi)
1521 pScrn->monitor->vrefresh[0].hi = Mode->VRefresh;
1523 pScrn->monitor->nHsync = 1;
1524 pScrn->monitor->nVrefresh = 1;
1530 * xf86ValidateModes will check that the mode HTotal and VTotal values
1531 * don't exceed the chipset's limit if pScrn->maxHValue and
1532 * pScrn->maxVValue are set. Since our NVValidMode() already takes
1533 * care of this, we don't worry about setting them here.
1535 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
1536 pScrn->display->modes, clockRanges,
1537 NULL, 256, max_width,
1538 512, 128, max_height,
1539 pScrn->display->virtualX,
1540 pScrn->display->virtualY,
1541 pNv->VRAMPhysicalSize / 2,
1542 LOOKUP_BEST_REFRESH);
1545 NVPreInitFail("\n");
1548 /* Prune the modes marked as invalid */
1549 xf86PruneDriverModes(pScrn);
1551 if (i == 0 || pScrn->modes == NULL) {
1552 NVPreInitFail("No valid modes found\n");
1556 * Set the CRTC parameters for all of the modes based on the type
1557 * of mode, and the chipset's interlace requirements.
1559 * Calling this is required if the mode->Crtc* values are used by the
1560 * driver and if the driver doesn't provide code to set them. They
1561 * are not pre-initialised at all.
1563 xf86SetCrtcForModes(pScrn, 0);
1565 /* Set the current mode to the first in the list */
1566 pScrn->currentMode = pScrn->modes;
1568 /* Print the list of modes being used */
1569 xf86PrintModes(pScrn);
1571 /* Set display resolution */
1572 xf86SetDpi(pScrn, 0, 0);
1576 * XXX This should be taken into account in some way in the mode valdation
1580 if (xf86LoadSubModule(pScrn, "fb") == NULL) {
1581 NVPreInitFail("\n");
1584 xf86LoaderReqSymLists(fbSymbols, NULL);
1586 /* Load EXA if needed */
1587 if (!pNv->NoAccel) {
1588 if (!xf86LoadSubModule(pScrn, "exa")) {
1589 NVPreInitFail("\n");
1591 xf86LoaderReqSymLists(exaSymbols, NULL);
1594 /* Load ramdac if needed */
1595 if (pNv->HWCursor) {
1596 if (!xf86LoadSubModule(pScrn, "ramdac")) {
1597 NVPreInitFail("\n");
1599 xf86LoaderReqSymLists(ramdacSymbols, NULL);
1602 /* Load shadowfb if needed */
1603 if (pNv->ShadowFB) {
1604 if (!xf86LoadSubModule(pScrn, "shadowfb")) {
1605 NVPreInitFail("\n");
1607 xf86LoaderReqSymLists(shadowSymbols, NULL);
1610 pNv->CurrentLayout.bitsPerPixel = pScrn->bitsPerPixel;
1611 pNv->CurrentLayout.depth = pScrn->depth;
1612 pNv->CurrentLayout.displayWidth = pScrn->displayWidth;
1613 pNv->CurrentLayout.weight.red = pScrn->weight.red;
1614 pNv->CurrentLayout.weight.green = pScrn->weight.green;
1615 pNv->CurrentLayout.weight.blue = pScrn->weight.blue;
1616 pNv->CurrentLayout.mode = pScrn->currentMode;
1618 xf86FreeInt10(pNv->pInt10);
1626 * Map the framebuffer and MMIO memory.
1630 NVMapMem(ScrnInfoPtr pScrn)
1632 NVPtr pNv = NVPTR(pScrn);
1634 pNv->FB = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, pNv->VRAMPhysicalSize/2);
1636 ErrorF("Failed to allocate memory for framebuffer!\n");
1639 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1640 "Allocated %dMiB VRAM for framebuffer + offscreen pixmaps\n",
1641 (unsigned int)(pNv->FB->size >> 20));
1643 /*XXX: have to get these after we've allocated something, otherwise
1644 * they're uninitialised in the DRM!
1646 pNv->VRAMSize = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_FB_SIZE);
1647 pNv->VRAMPhysical = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_FB_PHYSICAL);
1648 pNv->AGPSize = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_AGP_SIZE);
1649 pNv->AGPPhysical = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_AGP_PHYSICAL);
1650 if ( ! pNv->AGPSize ) /*if no AGP*/
1652 pNv->SGPhysical = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_PCI_PHYSICAL);
1654 int gart_scratch_size;
1657 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1658 "AGPGART: %dMiB available\n",
1659 (unsigned int)(pNv->AGPSize >> 20));
1661 if (pNv->AGPSize > (16*1024*1024))
1662 gart_scratch_size = 16*1024*1024;
1664 gart_scratch_size = pNv->AGPSize;
1669 gart_scratch_size = (4 << 20) - (1 << 18) ;
1670 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1671 "GART: PCI DMA - using %dKiB\n", gart_scratch_size >> 10);
1675 /*The DRM allocates AGP memory, PCI as a fallback */
1676 pNv->GARTScratch = NVAllocateMemory(pNv, NOUVEAU_MEM_AGP | NOUVEAU_MEM_PCI_ACCEPTABLE,
1678 if (!pNv->GARTScratch) {
1679 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1680 "Unable to allocate GART memory\n");
1682 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1683 "GART: mapped %dMiB at %p, offset is %d\n",
1684 (unsigned int)(pNv->GARTScratch->size >> 20),
1685 pNv->GARTScratch->map, pNv->GARTScratch->offset);
1689 pNv->Cursor = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, 64*1024);
1691 ErrorF("Failed to allocate memory for hardware cursor\n");
1695 pNv->ScratchBuffer = NVAllocateMemory(pNv, NOUVEAU_MEM_FB,
1696 pNv->Architecture <NV_ARCH_10 ? 8192 : 16384);
1697 if (!pNv->ScratchBuffer) {
1698 ErrorF("Failed to allocate memory for scratch buffer\n");
1702 if (pNv->Architecture >= NV_ARCH_50) {
1703 pNv->CLUT = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, 0x1000);
1705 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1706 "Failed to allocate memory for CLUT\n");
1715 * Unmap the framebuffer and MMIO memory.
1719 NVUnmapMem(ScrnInfoPtr pScrn)
1721 NVPtr pNv = NVPTR(pScrn);
1723 NVFreeMemory(pNv, pNv->FB);
1724 NVFreeMemory(pNv, pNv->ScratchBuffer);
1725 NVFreeMemory(pNv, pNv->Cursor);
1732 * Initialise a new mode.
1736 NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
1738 vgaHWPtr hwp = VGAHWPTR(pScrn);
1740 NVPtr pNv = NVPTR(pScrn);
1743 /* Initialise the ModeReg values */
1744 if (!vgaHWInit(pScrn, mode))
1746 pScrn->vtSema = TRUE;
1748 vgaReg = &hwp->ModeReg;
1749 nvReg = &pNv->ModeReg;
1751 if(!NVDACInit(pScrn, mode))
1754 NVLockUnlock(pNv, 0);
1756 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, nvReg->crtcOwner);
1757 NVLockUnlock(pNv, 0);
1760 /* Program the registers */
1761 vgaHWProtect(pScrn, TRUE);
1763 NVDACRestore(pScrn, vgaReg, nvReg, FALSE);
1765 #if X_BYTE_ORDER == X_BIG_ENDIAN
1766 /* turn on LFB swapping */
1770 tmp = nvReadVGA(pNv, NV_VGA_CRTCX_SWAPPING);
1772 nvWriteVGA(pNv, NV_VGA_CRTCX_SWAPPING, tmp);
1777 NVResetGraphics(pScrn);
1779 vgaHWProtect(pScrn, FALSE);
1781 pNv->CurrentLayout.mode = mode;
1787 * Restore the initial (text) mode.
1790 NVRestore(ScrnInfoPtr pScrn)
1792 vgaHWPtr hwp = VGAHWPTR(pScrn);
1793 vgaRegPtr vgaReg = &hwp->SavedReg;
1794 NVPtr pNv = NVPTR(pScrn);
1795 NVRegPtr nvReg = &pNv->SavedReg;
1797 if (pNv->randr12_enable) {
1798 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1800 int vgaflags = VGA_SR_CMAP | VGA_SR_MODE;
1802 for (i = 0; i < xf86_config->num_crtc; i++) {
1803 NVCrtcLockUnlock(xf86_config->crtc[i], 0);
1806 for (i = 0; i < xf86_config->num_crtc; i++) {
1807 xf86_config->crtc[i]->funcs->restore(xf86_config->crtc[i]);
1810 for (i = 0; i < xf86_config->num_output; i++) {
1811 xf86_config->output[i]->funcs->restore(xf86_config->
1816 vgaflags |= VGA_SR_FONTS;
1818 vgaHWRestore(pScrn, vgaReg, vgaflags);
1821 for (i = 0; i < xf86_config->num_crtc; i++) {
1822 NVCrtcLockUnlock(xf86_config->crtc[i], 1);
1825 NVLockUnlock(pNv, 0);
1828 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->CRTCnumber * 0x3);
1829 NVLockUnlock(pNv, 0);
1832 /* Only restore text mode fonts/text for the primary card */
1833 vgaHWProtect(pScrn, TRUE);
1834 NVDACRestore(pScrn, vgaReg, nvReg, pNv->Primary);
1836 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->vtOWNER);
1838 vgaHWProtect(pScrn, FALSE);
1843 #define DEPTH_SHIFT(val, w) ((val << (8 - w)) | (val >> ((w << 1) - 8)))
1844 #define MAKE_INDEX(in, w) (DEPTH_SHIFT(in, w) * 3)
1847 NVLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
1848 LOCO * colors, VisualPtr pVisual)
1850 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1852 NVPtr pNv = NVPTR(pScrn);
1855 for (c = 0; c < xf86_config->num_crtc; c++) {
1856 xf86CrtcPtr crtc = xf86_config->crtc[c];
1857 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1860 regp = &pNv->ModeReg.crtc_reg[nv_crtc->crtc];
1862 if (crtc->enabled == 0)
1865 switch (pNv->CurrentLayout.depth) {
1867 for (i = 0; i < numColors; i++) {
1869 regp->DAC[MAKE_INDEX(index, 5) + 0] =
1871 regp->DAC[MAKE_INDEX(index, 5) + 1] =
1872 colors[index].green;
1873 regp->DAC[MAKE_INDEX(index, 5) + 2] =
1878 for (i = 0; i < numColors; i++) {
1880 regp->DAC[MAKE_INDEX(index, 6) + 1] =
1881 colors[index].green;
1883 regp->DAC[MAKE_INDEX(index, 5) +
1884 0] = colors[index].red;
1885 regp->DAC[MAKE_INDEX(index, 5) +
1886 2] = colors[index].blue;
1891 for (i = 0; i < numColors; i++) {
1893 regp->DAC[index * 3] = colors[index].red;
1894 regp->DAC[(index * 3) + 1] =
1895 colors[index].green;
1896 regp->DAC[(index * 3) + 2] =
1902 NVCrtcLoadPalette(crtc);
1906 //#define DEPTH_SHIFT(val, w) ((val << (8 - w)) | (val >> ((w << 1) - 8)))
1907 #define COLOR(c) (unsigned int)(0x3fff * ((c)/255.0))
1909 NV50LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
1910 LOCO * colors, VisualPtr pVisual)
1912 NVPtr pNv = NVPTR(pScrn);
1915 unsigned short red, green, blue, unused;
1916 } *lut = (void *) pNv->CLUT->map;
1918 switch (pScrn->depth) {
1920 for (i = 0; i < numColors; i++) {
1922 lut[DEPTH_SHIFT(index, 5)].red =
1923 COLOR(colors[index].red);
1924 lut[DEPTH_SHIFT(index, 5)].green =
1925 COLOR(colors[index].green);
1926 lut[DEPTH_SHIFT(index, 5)].blue =
1927 COLOR(colors[index].blue);
1931 for (i = 0; i < numColors; i++) {
1933 lut[DEPTH_SHIFT(index, 6)].green =
1934 COLOR(colors[index].green);
1936 lut[DEPTH_SHIFT(index, 5)].red =
1937 COLOR(colors[index].red);
1938 lut[DEPTH_SHIFT(index, 5)].blue =
1939 COLOR(colors[index].blue);
1944 for (i = 0; i < numColors; i++) {
1946 lut[index].red = COLOR(colors[index].red);
1947 lut[index].green = COLOR(colors[index].green);
1948 lut[index].blue = COLOR(colors[index].blue);
1955 static void NVBacklightEnable(NVPtr pNv, Bool on)
1957 /* This is done differently on each laptop. Here we
1958 define the ones we know for sure. */
1960 #if defined(__powerpc__)
1961 if((pNv->Chipset == 0x10DE0179) ||
1962 (pNv->Chipset == 0x10DE0189) ||
1963 (pNv->Chipset == 0x10DE0329))
1965 /* NV17,18,34 Apple iMac, iBook, PowerBook */
1966 CARD32 tmp_pmc, tmp_pcrt;
1967 tmp_pmc = nvReadMC(pNv, 0x10F0) & 0x7FFFFFFF;
1968 tmp_pcrt = nvReadCRTC0(pNv, NV_CRTC_081C) & 0xFFFFFFFC;
1970 tmp_pmc |= (1 << 31);
1973 nvWriteMC(pNv, 0x10F0, tmp_pmc);
1974 nvWriteCRTC0(pNv, NV_CRTC_081C, tmp_pcrt);
1979 if(pNv->twoHeads && ((pNv->Chipset & 0x0ff0) != CHIPSET_NV11)) {
1980 nvWriteMC(pNv, 0x130C, on ? 3 : 7);
1985 fpcontrol = nvReadCurRAMDAC(pNv, 0x848) & 0xCfffffCC;
1987 /* cut the TMDS output */
1988 if(on) fpcontrol |= pNv->fpSyncs;
1989 else fpcontrol |= 0x20000022;
1991 nvWriteCurRAMDAC(pNv, 0x0848, fpcontrol);
1996 NVDPMSSetLCD(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
1998 NVPtr pNv = NVPTR(pScrn);
2000 if (!pScrn->vtSema) return;
2002 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
2004 switch (PowerManagementMode) {
2005 case DPMSModeStandby: /* HSync: Off, VSync: On */
2006 case DPMSModeSuspend: /* HSync: On, VSync: Off */
2007 case DPMSModeOff: /* HSync: Off, VSync: Off */
2008 NVBacklightEnable(pNv, 0);
2010 case DPMSModeOn: /* HSync: On, VSync: On */
2011 NVBacklightEnable(pNv, 1);
2019 NVDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
2021 unsigned char crtc1A;
2022 vgaHWPtr hwp = VGAHWPTR(pScrn);
2024 if (!pScrn->vtSema) return;
2026 crtc1A = hwp->readCrtc(hwp, 0x1A) & ~0xC0;
2028 switch (PowerManagementMode) {
2029 case DPMSModeStandby: /* HSync: Off, VSync: On */
2032 case DPMSModeSuspend: /* HSync: On, VSync: Off */
2035 case DPMSModeOff: /* HSync: Off, VSync: Off */
2038 case DPMSModeOn: /* HSync: On, VSync: On */
2043 /* vgaHWDPMSSet will merely cut the dac output */
2044 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
2046 hwp->writeCrtc(hwp, 0x1A, crtc1A);
2052 /* This gets called at the start of each server generation */
2055 NVScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
2062 unsigned char *FBStart;
2063 int width, height, displayWidth, shadowHeight;
2066 * First get the ScrnInfoRec
2068 pScrn = xf86Screens[pScreen->myNum];
2070 hwp = VGAHWPTR(pScrn);
2073 /* Map the VGA memory when the primary video */
2075 hwp->MapSize = 0x10000;
2076 if (!vgaHWMapMem(pScrn))
2080 /* First init DRI/DRM */
2081 if (!NVDRIScreenInit(pScrn))
2084 ret = drmCommandNone(pNv->drm_fd, DRM_NOUVEAU_CARD_INIT);
2086 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2087 "Error initialising the nouveau kernel module: %d\n",
2092 /* Allocate and map memory areas we need */
2093 if (!NVMapMem(pScrn))
2096 if (!pNv->NoAccel) {
2097 /* Init DRM - Alloc FIFO */
2098 if (!NVInitDma(pScrn))
2101 /* setup graphics objects */
2102 if (!NVAccelCommonInit(pScrn))
2106 if (!pNv->randr12_enable) {
2107 /* Save the current state */
2109 /* Initialise the first mode */
2110 if (!NVModeInit(pScrn, pScrn->currentMode))
2113 /* Darken the screen for aesthetic reasons and set the viewport */
2115 NVSaveScreen(pScreen, SCREEN_SAVER_ON);
2116 pScrn->AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
2119 pScrn->memPhysBase = pNv->VRAMPhysical;
2120 pScrn->fbOffset = 0;
2122 if (!NVEnterVT(scrnIndex, 0))
2128 * The next step is to setup the screen's visuals, and initialise the
2129 * framebuffer code. In cases where the framebuffer's default
2130 * choices for things like visual layouts and bits per RGB are OK,
2131 * this may be as simple as calling the framebuffer's ScreenInit()
2132 * function. If not, the visuals will need to be setup before calling
2133 * a fb ScreenInit() function and fixed up after.
2135 * For most PC hardware at depths >= 8, the defaults that fb uses
2136 * are not appropriate. In this driver, we fixup the visuals after.
2140 * Reset the visual list.
2142 miClearVisualTypes();
2144 /* Setup the visuals we support. */
2146 if (!miSetVisualTypes(pScrn->depth,
2147 miGetDefaultVisualMask(pScrn->depth), 8,
2148 pScrn->defaultVisual))
2150 if (!miSetPixmapDepths ()) return FALSE;
2153 * Call the framebuffer layer's ScreenInit function, and fill in other
2157 width = pScrn->virtualX;
2158 height = pScrn->virtualY;
2159 displayWidth = pScrn->displayWidth;
2163 height = pScrn->virtualX;
2164 width = pScrn->virtualY;
2167 /* If RandR rotation is enabled, leave enough space in the
2168 * framebuffer for us to rotate the screen dimensions without
2169 * changing the pitch.
2171 if(pNv->RandRRotation)
2172 shadowHeight = max(width, height);
2174 shadowHeight = height;
2177 pNv->ShadowPitch = BitmapBytePad(pScrn->bitsPerPixel * width);
2178 pNv->ShadowPtr = xalloc(pNv->ShadowPitch * shadowHeight);
2179 displayWidth = pNv->ShadowPitch / (pScrn->bitsPerPixel >> 3);
2180 FBStart = pNv->ShadowPtr;
2182 pNv->ShadowPtr = NULL;
2183 FBStart = pNv->FB->map;
2186 switch (pScrn->bitsPerPixel) {
2190 ret = fbScreenInit(pScreen, FBStart, width, height,
2191 pScrn->xDpi, pScrn->yDpi,
2192 displayWidth, pScrn->bitsPerPixel);
2195 xf86DrvMsg(scrnIndex, X_ERROR,
2196 "Internal error: invalid bpp (%d) in NVScreenInit\n",
2197 pScrn->bitsPerPixel);
2204 if (pScrn->bitsPerPixel > 8) {
2205 /* Fixup RGB ordering */
2206 visual = pScreen->visuals + pScreen->numVisuals;
2207 while (--visual >= pScreen->visuals) {
2208 if ((visual->class | DynamicClass) == DirectColor) {
2209 visual->offsetRed = pScrn->offset.red;
2210 visual->offsetGreen = pScrn->offset.green;
2211 visual->offsetBlue = pScrn->offset.blue;
2212 visual->redMask = pScrn->mask.red;
2213 visual->greenMask = pScrn->mask.green;
2214 visual->blueMask = pScrn->mask.blue;
2219 fbPictureInit (pScreen, 0, 0);
2221 xf86SetBlackWhitePixels(pScreen);
2223 if (!pNv->NoAccel) {
2225 NVResetGraphics(pScrn);
2228 miInitializeBackingStore(pScreen);
2229 xf86SetBackingStore(pScreen);
2230 xf86SetSilkenMouse(pScreen);
2232 /* Finish DRI init */
2233 NVDRIFinishScreenInit(pScrn);
2235 /* Initialize software cursor.
2236 Must precede creation of the default colormap */
2237 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
2239 /* Initialize HW cursor layer.
2240 Must follow software cursor initialization*/
2241 if (pNv->HWCursor) {
2242 if (pNv->Architecture < NV_ARCH_50)
2243 ret = NVCursorInit(pScreen);
2245 ret = NV50CursorInit(pScreen);
2248 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2249 "Hardware cursor initialization failed\n");
2250 pNv->HWCursor = FALSE;
2254 /* Initialise default colourmap */
2255 if (!miCreateDefColormap(pScreen))
2258 /* Initialize colormap layer.
2259 Must follow initialization of the default colormap */
2260 if (!pNv->randr12_enable) {
2261 if(!xf86HandleColormaps(pScreen, 256, 8, NVDACLoadPalette,
2262 NULL, CMAP_RELOAD_ON_MODE_SWITCH | CMAP_PALETTED_TRUECOLOR))
2265 if (pNv->Architecture < NV_ARCH_50) {
2266 if (!xf86HandleColormaps(pScreen, 256, 8, NVLoadPalette,
2268 CMAP_RELOAD_ON_MODE_SWITCH |
2269 CMAP_PALETTED_TRUECOLOR))
2272 if (!xf86HandleColormaps(pScreen, 256, 8, NV50LoadPalette,
2273 NULL, CMAP_PALETTED_TRUECOLOR))
2278 if (pNv->randr12_enable) {
2279 xf86DPMSInit(pScreen, xf86DPMSSet, 0);
2281 if (!xf86CrtcScreenInit(pScreen))
2284 pNv->PointerMoved = pScrn->PointerMoved;
2285 pScrn->PointerMoved = NVPointerMoved;
2289 RefreshAreaFuncPtr refreshArea = NVRefreshArea;
2291 if(pNv->Rotate || pNv->RandRRotation) {
2292 pNv->PointerMoved = pScrn->PointerMoved;
2294 pScrn->PointerMoved = NVPointerMoved;
2296 switch(pScrn->bitsPerPixel) {
2297 case 8: refreshArea = NVRefreshArea8; break;
2298 case 16: refreshArea = NVRefreshArea16; break;
2299 case 32: refreshArea = NVRefreshArea32; break;
2301 if(!pNv->RandRRotation) {
2303 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2304 "Driver rotation enabled, RandR disabled\n");
2308 ShadowFBInit(pScreen, refreshArea);
2311 if (!pNv->randr12_enable) {
2313 xf86DPMSInit(pScreen, NVDPMSSetLCD, 0);
2315 xf86DPMSInit(pScreen, NVDPMSSet, 0);
2318 pScrn->memPhysBase = pNv->VRAMPhysical;
2319 pScrn->fbOffset = 0;
2321 if(pNv->Rotate == 0 && !pNv->RandRRotation)
2322 NVInitVideo(pScreen);
2324 pScreen->SaveScreen = NVSaveScreen;
2326 /* Wrap the current CloseScreen function */
2327 pNv->CloseScreen = pScreen->CloseScreen;
2328 pScreen->CloseScreen = NVCloseScreen;
2330 pNv->BlockHandler = pScreen->BlockHandler;
2331 pScreen->BlockHandler = NVBlockHandler;
2334 /* Install our DriverFunc. We have to do it this way instead of using the
2335 * HaveDriverFuncs argument to xf86AddDriver, because InitOutput clobbers
2336 * pScrn->DriverFunc */
2337 if (!pNv->randr12_enable)
2338 pScrn->DriverFunc = NVDriverFunc;
2341 /* Report any unused options (only for the first generation) */
2342 if (serverGeneration == 1) {
2343 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
2349 NVSaveScreen(ScreenPtr pScreen, int mode)
2351 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
2352 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
2353 NVPtr pNv = NVPTR(pScrn);
2355 Bool on = xf86IsUnblank(mode);
2357 if (pNv->randr12_enable) {
2358 if (pScrn->vtSema) {
2359 for (i = 0; i < xf86_config->num_crtc; i++) {
2361 if (xf86_config->crtc[i]->enabled) {
2362 NVCrtcBlankScreen(xf86_config->crtc[i],
2370 return vgaHWSaveScreen(pScreen, mode);
2374 NVSave(ScrnInfoPtr pScrn)
2376 NVPtr pNv = NVPTR(pScrn);
2377 NVRegPtr nvReg = &pNv->SavedReg;
2378 vgaHWPtr pVga = VGAHWPTR(pScrn);
2379 vgaRegPtr vgaReg = &pVga->SavedReg;
2382 if (pNv->randr12_enable) {
2383 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
2384 int vgaflags = VGA_SR_CMAP | VGA_SR_MODE;
2386 for (i = 0; i < xf86_config->num_crtc; i++) {
2387 xf86_config->crtc[i]->funcs->save(xf86_config->crtc[i]);
2390 for (i = 0; i < xf86_config->num_output; i++) {
2391 xf86_config->output[i]->funcs->save(xf86_config->
2397 vgaflags |= VGA_SR_FONTS;
2399 vgaHWSave(pScrn, vgaReg, vgaflags);
2401 NVLockUnlock(pNv, 0);
2403 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->CRTCnumber * 0x3);
2404 NVLockUnlock(pNv, 0);
2407 NVDACSave(pScrn, vgaReg, nvReg, pNv->Primary);
2413 NVRandRGetInfo(ScrnInfoPtr pScrn, Rotation *rotations)
2415 NVPtr pNv = NVPTR(pScrn);
2417 if(pNv->RandRRotation)
2418 *rotations = RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_270;
2420 *rotations = RR_Rotate_0;
2426 NVRandRSetConfig(ScrnInfoPtr pScrn, xorgRRConfig *config)
2428 NVPtr pNv = NVPTR(pScrn);
2430 switch(config->rotation) {
2433 pScrn->PointerMoved = pNv->PointerMoved;
2438 pScrn->PointerMoved = NVPointerMoved;
2443 pScrn->PointerMoved = NVPointerMoved;
2447 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2448 "Unexpected rotation in NVRandRSetConfig!\n");
2450 pScrn->PointerMoved = pNv->PointerMoved;
2458 NVDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer data)
2462 return NVRandRGetInfo(pScrn, (Rotation*)data);
2464 return NVRandRSetConfig(pScrn, (xorgRRConfig*)data);