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);
38 /*const OptionInfoRec * RivaAvailableOptions(int chipid, int busid);
39 Bool RivaGetScrnInfoRec(PciChipsets *chips, int chip);*/
42 * Forward definitions for the functions that make up the driver.
44 /* Mandatory functions */
45 static const OptionInfoRec * NVAvailableOptions(int chipid, int busid);
46 static void NVIdentify(int flags);
47 #ifndef XSERVER_LIBPCIACCESS
48 static Bool NVProbe(DriverPtr drv, int flags);
49 #endif /* XSERVER_LIBPCIACCESS */
50 static Bool NVPreInit(ScrnInfoPtr pScrn, int flags);
51 static Bool NVScreenInit(int Index, ScreenPtr pScreen, int argc,
53 static Bool NVEnterVT(int scrnIndex, int flags);
54 static void NVLeaveVT(int scrnIndex, int flags);
55 static Bool NVCloseScreen(int scrnIndex, ScreenPtr pScreen);
56 static Bool NVSaveScreen(ScreenPtr pScreen, int mode);
58 /* Optional functions */
59 static void NVFreeScreen(int scrnIndex, int flags);
60 static ModeStatus NVValidMode(int scrnIndex, DisplayModePtr mode,
61 Bool verbose, int flags);
63 static Bool NVDriverFunc(ScrnInfoPtr pScrnInfo, xorgDriverFuncOp op,
67 /* Internally used functions */
69 static Bool NVMapMem(ScrnInfoPtr pScrn);
70 static Bool NVUnmapMem(ScrnInfoPtr pScrn);
71 static void NVSave(ScrnInfoPtr pScrn);
72 static void NVRestore(ScrnInfoPtr pScrn);
73 static Bool NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
75 #ifdef XSERVER_LIBPCIACCESS
77 #define NOUVEAU_PCI_DEVICE(_vendor_id, _device_id) \
78 { (_vendor_id), (_device_id), PCI_MATCH_ANY, PCI_MATCH_ANY, 0x00030000, 0x00ffffff, 0 }
80 static const struct pci_id_match nouveau_device_match[] = {
81 NOUVEAU_PCI_DEVICE(PCI_VENDOR_NVIDIA, PCI_MATCH_ANY),
82 NOUVEAU_PCI_DEVICE(PCI_VENDOR_NVIDIA_SGS, PCI_MATCH_ANY),
86 static Bool NVPciProbe ( DriverPtr drv,
88 struct pci_device *dev,
89 intptr_t match_data );
91 #endif /* XSERVER_LIBPCIACCESS */
94 * This contains the functions needed by the server after loading the
95 * driver module. It must be supplied, and gets added the driver list by
96 * the Module Setup funtion in the dynamic case. In the static case a
97 * reference to this is compiled in, and this requires that the name of
98 * this DriverRec be an upper-case version of the driver name.
101 _X_EXPORT DriverRec NV = {
105 #ifdef XSERVER_LIBPCIACCESS
109 #endif /* XSERVER_LIBPCIACCESS */
114 #ifdef XSERVER_LIBPCIACCESS
115 nouveau_device_match,
117 #endif /* XSERVER_LIBPCIACCESS */
126 static struct NvFamily NVKnownFamilies[] =
128 { "RIVA TNT", "NV04" },
129 { "RIVA TNT2", "NV05" },
130 { "GeForce 256", "NV10" },
131 { "GeForce 2", "NV11, NV15" },
132 { "GeForce 4MX", "NV17, NV18" },
133 { "GeForce 3", "NV20" },
134 { "GeForce 4Ti", "NV25, NV28" },
135 { "GeForce FX", "NV3x" },
136 { "GeForce 6", "NV4x" },
137 { "GeForce 7", "G7x" },
138 { "GeForce 8", "G8x" },
143 * List of symbols from other modules that this module references. This
144 * list is used to tell the loader that it is OK for symbols here to be
145 * unresolved providing that it hasn't been told that they haven't been
146 * told that they are essential via a call to xf86LoaderReqSymbols() or
147 * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
148 * unresolved symbols that are not required.
151 static const char *vgahwSymbols[] = {
166 static const char *fbSymbols[] = {
172 static const char *xaaSymbols[] = {
182 static const char *exaSymbols[] = {
188 static const char *ramdacSymbols[] = {
189 "xf86CreateCursorInfoRec",
190 "xf86DestroyCursorInfoRec",
195 static const char *ddcSymbols[] = {
198 "xf86SetDDCproperties",
202 static const char *vbeSymbols[] = {
209 static const char *i2cSymbols[] = {
210 "xf86CreateI2CBusRec",
215 static const char *shadowSymbols[] = {
220 static const char *int10Symbols[] = {
226 static const char *rivaSymbols[] = {
227 "RivaGetScrnInfoRec",
228 "RivaAvailableOptions",
232 const char *drmSymbols[] = {
237 "drmAgpVersionMajor",
238 "drmAgpVersionMinor",
248 "drmCommandWriteRead",
251 "drmCtlUninstHandler",
254 "drmGetInterruptFromBusID",
260 const char *driSymbols[] = {
264 "DRIFinishScreenInit",
265 "DRIGetSAREAPrivate",
270 "GlxSetVisualConfigs",
276 static MODULESETUPPROTO(nouveauSetup);
278 static XF86ModuleVersionInfo nouveauVersRec =
284 XORG_VERSION_CURRENT,
285 NV_MAJOR_VERSION, NV_MINOR_VERSION, NV_PATCHLEVEL,
286 ABI_CLASS_VIDEODRV, /* This is a video driver */
287 ABI_VIDEODRV_VERSION,
292 _X_EXPORT XF86ModuleData nouveauModuleData = { &nouveauVersRec, nouveauSetup, NULL };
296 * This is intentionally screen-independent. It indicates the binding
297 * choice made in the first PreInit.
299 static int pix24bpp = 0;
302 NVGetRec(ScrnInfoPtr pScrn)
305 * Allocate an NVRec, and hook it into pScrn->driverPrivate.
306 * pScrn->driverPrivate is initialised to NULL, so we can check if
307 * the allocation has already been done.
309 if (pScrn->driverPrivate != NULL)
312 pScrn->driverPrivate = xnfcalloc(sizeof(NVRec), 1);
319 NVFreeRec(ScrnInfoPtr pScrn)
321 if (pScrn->driverPrivate == NULL)
323 xfree(pScrn->driverPrivate);
324 pScrn->driverPrivate = NULL;
329 nouveauSetup(pointer module, pointer opts, int *errmaj, int *errmin)
331 static Bool setupDone = FALSE;
333 /* This module should be loaded only once, but check to be sure. */
337 /* The 1 here is needed to turn off a backwards compatibility mode */
338 /* Otherwise NVPciProbe() is not called */
339 xf86AddDriver(&NV, module, 1);
342 * Modules that this driver always requires may be loaded here
343 * by calling LoadSubModule().
346 * Tell the loader about symbols from other modules that this module
349 LoaderRefSymLists(vgahwSymbols, xaaSymbols, exaSymbols, fbSymbols,
353 ramdacSymbols, shadowSymbols, rivaSymbols,
354 i2cSymbols, ddcSymbols, vbeSymbols,
358 * The return value must be non-NULL on success even though there
359 * is no TearDownProc.
363 if (errmaj) *errmaj = LDR_ONCEONLY;
368 static const OptionInfoRec *
369 NVAvailableOptions(int chipid, int busid)
371 /* if(chipid == 0x12D20018) {
372 if (!xf86LoadOneModule("riva128", NULL)) {
375 return RivaAvailableOptions(chipid, busid);
383 NVIdentify(int flags)
385 struct NvFamily *family;
388 xf86DrvMsg(0, X_INFO, NV_NAME " driver " NV_DRIVER_DATE "\n");
389 xf86DrvMsg(0, X_INFO, NV_NAME " driver for NVIDIA chipset families :\n");
391 /* maximum length for alignment */
392 family = NVKnownFamilies;
393 while(family->name && family->chipset)
395 maxLen = max(maxLen, strlen(family->name));
400 family = NVKnownFamilies;
401 while(family->name && family->chipset)
403 size_t len = strlen(family->name);
404 xf86ErrorF("\t%s", family->name);
410 xf86ErrorF("(%s)\n", family->chipset);
417 NVGetScrnInfoRec(PciChipsets *chips, int chip)
421 pScrn = xf86ConfigPciEntity(NULL, 0, chip,
422 chips, NULL, NULL, NULL,
425 if(!pScrn) return FALSE;
427 pScrn->driverVersion = NV_VERSION;
428 pScrn->driverName = NV_DRIVER_NAME;
429 pScrn->name = NV_NAME;
431 #ifndef XSERVER_LIBPCIACCESS
432 pScrn->Probe = NVProbe;
436 pScrn->PreInit = NVPreInit;
437 pScrn->ScreenInit = NVScreenInit;
438 pScrn->SwitchMode = NVSwitchMode;
439 pScrn->AdjustFrame = NVAdjustFrame;
440 pScrn->EnterVT = NVEnterVT;
441 pScrn->LeaveVT = NVLeaveVT;
442 pScrn->FreeScreen = NVFreeScreen;
443 pScrn->ValidMode = NVValidMode;
448 /* This returns architecture in hexdecimal, so NV40 is 0x40 */
449 static char NVGetArchitecture (volatile CARD32 *regs)
451 char architecture = 0;
453 /* We're dealing with >=NV10 */
454 if ((regs[0] & 0x0f000000) > 0 ) {
455 /* Bit 27-20 contain the architecture in hex */
456 architecture = (regs[0] & 0xff00000) >> 20;
458 } else if ((regs[0] & 0xff00fff0) == 0x20004000) {
465 /* Reading the pci_id from the card registers is the most reliable way */
466 static CARD32 NVGetPCIID (volatile CARD32 *regs)
470 char architecture = NVGetArchitecture(regs);
472 /* Dealing with an unknown or unsupported card */
473 if (architecture == 0) {
477 if (architecture >= 0x04 && architecture <= 0x4F) {
478 pci_id = regs[0x1800/4];
479 } else if (architecture >= 0x50 && architecture <= 0x5F) {
480 pci_id = regs[0x88000/4];
485 /* A pci-id can be inverted, we must correct this */
486 if ((pci_id & 0xffff) == PCI_VENDOR_NVIDIA) {
487 pci_id = (PCI_VENDOR_NVIDIA << 16) | (pci_id >> 16);
488 } else if ((pci_id & 0xffff) == PCI_VENDOR_NVIDIA_SGS) {
489 pci_id = (PCI_VENDOR_NVIDIA_SGS << 16) | (pci_id >> 16);
490 /* Checking endian issues */
492 /* PCI_VENDOR_NVIDIA = 0x10DE */
493 if ((pci_id & (0xffff << 16)) == (0xDE10 << 16)) { /* wrong endian */
494 pci_id = (PCI_VENDOR_NVIDIA << 16) | ((pci_id << 8) & 0x0000ff00) |
495 ((pci_id >> 8) & 0x000000ff);
496 /* PCI_VENDOR_NVIDIA_SGS = 0x12D2 */
497 } else if ((pci_id & (0xffff << 16)) == (0xD212 << 16)) { /* wrong endian */
498 pci_id = (PCI_VENDOR_NVIDIA_SGS << 16) | ((pci_id << 8) & 0x0000ff00) |
499 ((pci_id >> 8) & 0x000000ff);
506 #ifdef XSERVER_LIBPCIACCESS
508 static Bool NVPciProbe ( DriverPtr drv,
510 struct pci_device *dev,
511 intptr_t match_data )
513 ScrnInfoPtr pScrn = NULL;
515 volatile CARD32 *regs = NULL;
517 /* Temporary mapping to discover the architecture */
518 pci_device_map_memory_range(dev, PCI_DEV_MEM_BASE(dev, 0), 0x90000, FALSE, ®s);
520 /* Bit 27-20 contain the architecture in hex */
521 char architecture = (regs[0] & 0xff00000) >> 20;
523 CARD32 pci_id = NVGetPCIID(regs);
525 pci_device_unmap_memory_range(dev, regs, 0x90000);
527 /* Currently NV04 up to NV83 is supported */
528 /* For safety the fictional NV8F is used */
529 if (architecture >= 0x04 && architecture <= 0x8F) {
531 /* At this stage the pci_id should be ok, so we generate this to avoid list duplication */
532 const PciChipsets NVChipsets[] = {
533 { pci_id, pci_id, RES_SHARED_VGA },
534 { -1, -1, RES_UNDEFINED }
537 pScrn = xf86ConfigPciEntity(pScrn, 0, entity_num, NVChipsets,
538 NULL, NULL, NULL, NULL, NULL);
541 pScrn->driverVersion = NV_VERSION;
542 pScrn->driverName = NV_DRIVER_NAME;
543 pScrn->name = NV_NAME;
546 pScrn->PreInit = NVPreInit;
547 pScrn->ScreenInit = NVScreenInit;
548 pScrn->SwitchMode = NVSwitchMode;
549 pScrn->AdjustFrame = NVAdjustFrame;
550 pScrn->EnterVT = NVEnterVT;
551 pScrn->LeaveVT = NVLeaveVT;
552 pScrn->FreeScreen = NVFreeScreen;
553 pScrn->ValidMode = NVValidMode;
562 #endif /* XSERVER_LIBPCIACCESS */
564 #define MAX_CHIPS MAXSCREENS
566 #ifndef XSERVER_LIBPCIACCESS
569 NVProbe(DriverPtr drv, int flags)
572 GDevPtr *devSections;
574 SymTabRec NVChipsets[MAX_CHIPS + 1];
575 PciChipsets NVPciChipsets[MAX_CHIPS + 1];
579 Bool foundScreen = FALSE;
581 if ((numDevSections = xf86MatchDevice(NV_DRIVER_NAME, &devSections)) <= 0)
582 return FALSE; /* no matching device section */
584 if (!(ppPci = xf86GetPciVideoInfo()))
585 return FALSE; /* no PCI cards found */
589 /* Create the NVChipsets and NVPciChipsets from found devices */
590 while (*ppPci && (numUsed < MAX_CHIPS)) {
591 if (((*ppPci)->vendor == PCI_VENDOR_NVIDIA_SGS) ||
592 ((*ppPci)->vendor == PCI_VENDOR_NVIDIA))
594 volatile CARD32 *regs;
597 PCI_DEV_READ_LONG(*ppPci, PCI_CMD_STAT_REG, &pcicmd);
598 /* Enable reading memory? */
599 PCI_DEV_WRITE_LONG(*ppPci, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
601 regs = xf86MapPciMem(-1, VIDMEM_MMIO, PCI_DEV_TAG(*ppPci), PCI_DEV_MEM_BASE(*ppPci, 0), 0x90000);
602 int pciid = NVGetPCIID(regs);
604 char architecture = NVGetArchitecture(regs);
606 sprintf(name, "NVIDIA NV%02X", architecture);
607 /* NV04 upto NV83 is supported, NV8F is fictive limit */
608 if (architecture >= 0x04 && architecture <= 0x8F) {
609 NVChipsets[numUsed].token = pciid;
610 NVChipsets[numUsed].name = name;
611 NVPciChipsets[numUsed].numChipset = pciid;
612 NVPciChipsets[numUsed].PCIid = pciid;
613 NVPciChipsets[numUsed].resList = RES_SHARED_VGA;
616 xf86UnMapVidMem(-1, (pointer)regs, 0x90000);
618 /* Reset previous state */
619 PCI_DEV_WRITE_LONG(*ppPci, PCI_CMD_STAT_REG, pcicmd);
624 /* terminate the list */
625 NVChipsets[numUsed].token = -1;
626 NVChipsets[numUsed].name = NULL;
627 NVPciChipsets[numUsed].numChipset = -1;
628 NVPciChipsets[numUsed].PCIid = -1;
629 NVPciChipsets[numUsed].resList = RES_UNDEFINED;
631 numUsed = xf86MatchPciInstances(NV_NAME, 0, NVChipsets, NVPciChipsets,
632 devSections, numDevSections, drv,
639 if (flags & PROBE_DETECT) {
642 for (i = 0; i < numUsed; i++) {
645 pPci = xf86GetPciInfoForEntity(usedChips[i]);
646 if (NVGetScrnInfoRec(NVPciChipsets, usedChips[i])) {
657 #endif /* XSERVER_LIBPCIACCESS */
659 /* Usually mandatory */
661 NVSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
663 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
664 NVPtr pNv = NVPTR(pScrn);
667 if (pNv->randr12_enable) {
668 NVFBLayout *pLayout = &pNv->CurrentLayout;
670 if (pLayout->mode != mode) {
671 if (!NVSetMode(pScrn, mode, RR_Rotate_0))
675 pLayout->mode = mode;
678 return NVModeInit(xf86Screens[scrnIndex], mode);
682 * This function is used to initialize the Start Address - the first
683 * displayed location in the video memory.
685 /* Usually mandatory */
687 NVAdjustFrame(int scrnIndex, int x, int y, int flags)
689 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
691 NVPtr pNv = NVPTR(pScrn);
692 NVFBLayout *pLayout = &pNv->CurrentLayout;
694 if (pNv->randr12_enable) {
695 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
697 xf86CrtcPtr crtc = config->output[config->compat_output]->crtc;
699 if (crtc && crtc->enabled) {
700 NVCrtcSetBase(crtc, x, y);
703 startAddr = (((y*pLayout->displayWidth)+x)*(pLayout->bitsPerPixel/8));
704 startAddr += pNv->FB->offset;
705 NVSetStartAddress(pNv, startAddr);
710 NVResetCrtcConfig(ScrnInfoPtr pScrn, int set)
712 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
713 NVPtr pNv = NVPTR(pScrn);
717 for (i = 0; i < config->num_crtc; i++) {
718 xf86CrtcPtr crtc = config->crtc[i];
719 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
724 regp = &pNv->ModeReg.crtc_reg[nv_crtc->crtc];
728 nvWriteCRTC(pNv, nv_crtc->crtc, NV_CRTC_FSEL, val);
733 NV50AcquireDisplay(ScrnInfoPtr pScrn)
735 if (!NV50DispInit(pScrn))
737 if (!NV50CursorAcquire(pScrn))
739 xf86SetDesiredModes(pScrn);
745 NV50ReleaseDisplay(ScrnInfoPtr pScrn)
747 NV50CursorRelease(pScrn);
748 NV50DispShutdown(pScrn);
754 * This is called when VT switching back to the X server. Its job is
755 * to reinitialise the video mode.
757 * We may wish to unmap video/MMIO memory too.
762 NVEnterVT(int scrnIndex, int flags)
764 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
765 NVPtr pNv = NVPTR(pScrn);
767 if (pNv->randr12_enable) {
768 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
769 pScrn->vtSema = TRUE;
771 if (pNv->Architecture == NV_ARCH_50) {
772 if (!NV50AcquireDisplay(pScrn))
777 /* Save the current state */
778 if (pNv->SaveGeneration != serverGeneration) {
779 pNv->SaveGeneration = serverGeneration;
783 NVResetCrtcConfig(pScrn, 0);
784 if (!xf86SetDesiredModes(pScrn))
786 NVResetCrtcConfig(pScrn, 1);
789 if (!NVModeInit(pScrn, pScrn->currentMode))
793 NVAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
794 if(pNv->overlayAdaptor)
801 * This is called when VT switching away from the X server. Its job is
802 * to restore the previous (text) mode.
804 * We may wish to remap video/MMIO memory too.
809 NVLeaveVT(int scrnIndex, int flags)
811 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
812 NVPtr pNv = NVPTR(pScrn);
814 if (pNv->Architecture == NV_ARCH_50) {
815 NV50ReleaseDisplay(pScrn);
820 if (!pNv->randr12_enable)
821 NVLockUnlock(pNv, 1);
834 ScreenPtr pScreen = screenInfo.screens[i];
835 ScrnInfoPtr pScrnInfo = xf86Screens[i];
836 NVPtr pNv = NVPTR(pScrnInfo);
838 if (pNv->DMAKickoffCallback)
839 (*pNv->DMAKickoffCallback)(pNv);
841 pScreen->BlockHandler = pNv->BlockHandler;
842 (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
843 pScreen->BlockHandler = NVBlockHandler;
845 if (pNv->VideoTimerCallback)
846 (*pNv->VideoTimerCallback)(pScrnInfo, currentTime.milliseconds);
852 * This is called at the end of each server generation. It restores the
853 * original (text) mode. It should also unmap the video memory, and free
854 * any per-generation data allocated by the driver. It should finish
855 * by unwrapping and calling the saved CloseScreen function.
860 NVCloseScreen(int scrnIndex, ScreenPtr pScreen)
862 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
863 NVPtr pNv = NVPTR(pScrn);
866 pScrn->vtSema = FALSE;
867 if (pNv->Architecture == NV_ARCH_50) {
868 NV50ReleaseDisplay(pScrn);
872 if (!pNv->randr12_enable)
873 NVLockUnlock(pNv, 1);
878 vgaHWUnmapMem(pScrn);
879 if (pNv->AccelInfoRec)
880 XAADestroyInfoRec(pNv->AccelInfoRec);
881 if (pNv->CursorInfoRec)
882 xf86DestroyCursorInfoRec(pNv->CursorInfoRec);
884 xfree(pNv->ShadowPtr);
885 if (pNv->overlayAdaptor)
886 xfree(pNv->overlayAdaptor);
887 if (pNv->blitAdaptor)
888 xfree(pNv->blitAdaptor);
890 pScrn->vtSema = FALSE;
891 pScreen->CloseScreen = pNv->CloseScreen;
892 pScreen->BlockHandler = pNv->BlockHandler;
893 return (*pScreen->CloseScreen)(scrnIndex, pScreen);
896 /* Free up any persistent data structures */
900 NVFreeScreen(int scrnIndex, int flags)
903 * This only gets called when a screen is being deleted. It does not
904 * get called routinely at the end of a server generation.
906 if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
907 vgaHWFreeHWRec(xf86Screens[scrnIndex]);
908 NVFreeRec(xf86Screens[scrnIndex]);
912 /* Checks if a mode is suitable for the selected chipset. */
916 NVValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
918 NVPtr pNv = NVPTR(xf86Screens[scrnIndex]);
920 if(pNv->fpWidth && pNv->fpHeight)
921 if((pNv->fpWidth < mode->HDisplay) || (pNv->fpHeight < mode->VDisplay))
928 nvProbeDDC(ScrnInfoPtr pScrn, int index)
932 if (xf86LoadSubModule(pScrn, "vbe")) {
933 pVbe = VBEInit(NULL,index);
934 ConfiguredMonitor = vbeDoEDID(pVbe, NULL);
940 Bool NVI2CInit(ScrnInfoPtr pScrn)
944 if (xf86LoadSubModule(pScrn, mod)) {
945 xf86LoaderReqSymLists(i2cSymbols,NULL);
948 if(xf86LoadSubModule(pScrn, mod)) {
949 xf86LoaderReqSymLists(ddcSymbols, NULL);
950 return NVDACi2cInit(pScrn);
954 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
955 "Couldn't load %s module. DDC probing can't be done\n", mod);
960 static Bool NVPreInitDRI(ScrnInfoPtr pScrn)
962 NVPtr pNv = NVPTR(pScrn);
964 if (!NVDRIGetVersion(pScrn))
967 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
968 "[dri] Found DRI library version %d.%d.%d and kernel"
969 " module version %d.%d.%d\n",
970 pNv->pLibDRMVersion->version_major,
971 pNv->pLibDRMVersion->version_minor,
972 pNv->pLibDRMVersion->version_patchlevel,
973 pNv->pKernelDRMVersion->version_major,
974 pNv->pKernelDRMVersion->version_minor,
975 pNv->pKernelDRMVersion->version_patchlevel);
982 nv_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
984 scrn->virtualX = width;
985 scrn->virtualY = height;
989 static const xf86CrtcConfigFuncsRec nv_xf86crtc_config_funcs = {
995 NVDetermineChipsetArch(ScrnInfoPtr pScrn)
997 NVPtr pNv = NVPTR(pScrn);
999 switch (pNv->Chipset & 0x0ff0) {
1000 case CHIPSET_NV03: /* Riva128 */
1001 pNv->Architecture = NV_ARCH_03;
1003 case CHIPSET_NV04: /* TNT/TNT2 */
1004 pNv->Architecture = NV_ARCH_04;
1006 case CHIPSET_NV10: /* GeForce 256 */
1007 case CHIPSET_NV11: /* GeForce2 MX */
1008 case CHIPSET_NV15: /* GeForce2 */
1009 case CHIPSET_NV17: /* GeForce4 MX */
1010 case CHIPSET_NV18: /* GeForce4 MX (8x AGP) */
1011 case CHIPSET_NFORCE: /* nForce */
1012 case CHIPSET_NFORCE2: /* nForce2 */
1013 pNv->Architecture = NV_ARCH_10;
1015 case CHIPSET_NV20: /* GeForce3 */
1016 case CHIPSET_NV25: /* GeForce4 Ti */
1017 case CHIPSET_NV28: /* GeForce4 Ti (8x AGP) */
1018 pNv->Architecture = NV_ARCH_20;
1020 case CHIPSET_NV30: /* GeForceFX 5800 */
1021 case CHIPSET_NV31: /* GeForceFX 5600 */
1022 case CHIPSET_NV34: /* GeForceFX 5200 */
1023 case CHIPSET_NV35: /* GeForceFX 5900 */
1024 case CHIPSET_NV36: /* GeForceFX 5700 */
1025 pNv->Architecture = NV_ARCH_30;
1027 case CHIPSET_NV40: /* GeForce 6800 */
1028 case CHIPSET_NV41: /* GeForce 6800 */
1029 case 0x0120: /* GeForce 6800 */
1030 case CHIPSET_NV43: /* GeForce 6600 */
1031 case CHIPSET_NV44: /* GeForce 6200 */
1032 case CHIPSET_G72: /* GeForce 7200, 7300, 7400 */
1033 case CHIPSET_G70: /* GeForce 7800 */
1034 case CHIPSET_NV45: /* GeForce 6800 */
1035 case CHIPSET_NV44A: /* GeForce 6200 */
1036 case CHIPSET_G71: /* GeForce 7900 */
1037 case CHIPSET_G73: /* GeForce 7600 */
1038 case CHIPSET_C51: /* GeForce 6100 */
1039 case CHIPSET_C512: /* Geforce 6100 (nForce 4xx) */
1040 pNv->Architecture = NV_ARCH_40;
1044 pNv->Architecture = NV_ARCH_50;
1046 default: /* Unknown, probably >=NV40 */
1047 pNv->Architecture = NV_ARCH_40;
1054 #define NVPreInitFail(fmt, args...) do { \
1055 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%d: "fmt, __LINE__, ##args); \
1057 xf86FreeInt10(pNv->pInt10); \
1064 NVPreInit(ScrnInfoPtr pScrn, int flags)
1066 xf86CrtcConfigPtr xf86_config;
1069 int i, max_width, max_height;
1070 ClockRangePtr clockRanges;
1072 int config_mon_rates = FALSE;
1075 if (flags & PROBE_DETECT) {
1076 EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1084 nvProbeDDC(pScrn, i);
1089 * Note: This function is only called once at server startup, and
1090 * not at the start of each server generation. This means that
1091 * only things that are persistent across server generations can
1092 * be initialised here. xf86Screens[] is (pScrn is a pointer to one
1093 * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex()
1094 * are too, and should be used for data that must persist across
1095 * server generations.
1097 * Per-generation data should be allocated with
1098 * AllocateScreenPrivateIndex() from the ScreenInit() function.
1101 /* Check the number of entities, and fail if it isn't one. */
1102 if (pScrn->numEntities != 1)
1105 /* Allocate the NVRec driverPrivate */
1106 if (!NVGetRec(pScrn)) {
1111 /* Get the entity, and make sure it is PCI. */
1112 pNv->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1113 if (pNv->pEnt->location.type != BUS_PCI)
1116 /* Find the PCI info for this screen */
1117 pNv->PciInfo = xf86GetPciInfoForEntity(pNv->pEnt->index);
1118 #ifndef XSERVER_LIBPCIACCESS
1119 pNv->PciTag = pciTag(pNv->PciInfo->bus, pNv->PciInfo->device,
1120 pNv->PciInfo->func);
1121 #endif /* XSERVER_LIBPCIACCESS */
1123 pNv->Primary = xf86IsPrimaryPci(pNv->PciInfo);
1125 /* Initialize the card through int10 interface if needed */
1126 if (xf86LoadSubModule(pScrn, "int10")) {
1127 xf86LoaderReqSymLists(int10Symbols, NULL);
1128 #if !defined(__alpha__) && !defined(__powerpc__)
1129 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initializing int10\n");
1130 pNv->pInt10 = xf86InitInt10(pNv->pEnt->index);
1134 xf86SetOperatingState(resVgaIo, pNv->pEnt->index, ResUnusedOpr);
1135 xf86SetOperatingState(resVgaMem, pNv->pEnt->index, ResDisableOpr);
1137 /* Set pScrn->monitor */
1138 pScrn->monitor = pScrn->confScreen->monitor;
1140 volatile CARD32 *regs = NULL;
1141 #ifdef XSERVER_LIBPCIACCESS
1142 pci_device_map_memory_range(pNv->PciInfo, PCI_DEV_MEM_BASE(pNv->PciInfo, 0), 0x90000, FALSE, ®s);
1143 pNv->Chipset = NVGetPCIID(regs) & 0xffff;
1144 pNv->NVArch = NVGetArchitecture(regs);
1145 pci_device_unmap_memory_range(pNv->PciInfo, regs, 0x90000);
1148 PCI_DEV_READ_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, &pcicmd);
1149 /* Enable reading memory? */
1150 PCI_DEV_WRITE_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
1151 regs = xf86MapPciMem(-1, VIDMEM_MMIO, pNv->PciTag, PCI_DEV_MEM_BASE(pNv->PciInfo, 0), 0x90000);
1152 pNv->Chipset = NVGetPCIID(regs) & 0xffff;
1153 pNv->NVArch = NVGetArchitecture(regs);
1154 xf86UnMapVidMem(-1, (pointer)regs, 0x90000);
1155 /* Reset previous state */
1156 PCI_DEV_WRITE_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, pcicmd);
1157 #endif /* XSERVER_LIBPCIACCESS */
1159 pScrn->chipset = malloc(sizeof(char) * 25);
1160 sprintf(pScrn->chipset, "NVIDIA NV%02X", pNv->NVArch);
1162 if(!pScrn->chipset) {
1163 pScrn->chipset = "Unknown NVIDIA";
1167 * This shouldn't happen because such problems should be caught in
1168 * NVProbe(), but check it just in case.
1170 if (pScrn->chipset == NULL)
1171 NVPreInitFail("ChipID 0x%04X is not recognised\n", pNv->Chipset);
1173 if (pNv->NVArch < 0x04)
1174 NVPreInitFail("Chipset \"%s\" is not recognised\n", pScrn->chipset);
1176 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Chipset: \"%s\"\n", pScrn->chipset);
1178 NVDetermineChipsetArch(pScrn);
1181 * The first thing we should figure out is the depth, bpp, etc.
1184 if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support32bppFb)) {
1185 NVPreInitFail("\n");
1187 /* Check that the returned depth is one we support */
1188 switch (pScrn->depth) {
1196 NVPreInitFail("Given depth (%d) is not supported by this driver\n",
1200 xf86PrintDepthBpp(pScrn);
1202 /* Get the depth24 pixmap format */
1203 if (pScrn->depth == 24 && pix24bpp == 0)
1204 pix24bpp = xf86GetBppFromDepth(pScrn, 24);
1207 * This must happen after pScrn->display has been set because
1208 * xf86SetWeight references it.
1210 if (pScrn->depth > 8) {
1211 /* The defaults are OK for us */
1212 rgb zeros = {0, 0, 0};
1214 if (!xf86SetWeight(pScrn, zeros, zeros)) {
1215 NVPreInitFail("\n");
1219 if (!xf86SetDefaultVisual(pScrn, -1)) {
1220 NVPreInitFail("\n");
1222 /* We don't currently support DirectColor at > 8bpp */
1223 if (pScrn->depth > 8 && (pScrn->defaultVisual != TrueColor)) {
1224 NVPreInitFail("Given default visual"
1225 " (%s) is not supported at depth %d\n",
1226 xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
1231 /* The vgahw module should be loaded here when needed */
1232 if (!xf86LoadSubModule(pScrn, "vgahw")) {
1233 NVPreInitFail("\n");
1236 xf86LoaderReqSymLists(vgahwSymbols, NULL);
1239 * Allocate a vgaHWRec
1241 if (!vgaHWGetHWRec(pScrn)) {
1242 NVPreInitFail("\n");
1245 /* We use a programmable clock */
1246 pScrn->progClock = TRUE;
1248 /* Collect all of the relevant option flags (fill in pScrn->options) */
1249 xf86CollectOptions(pScrn, NULL);
1251 /* Process the options */
1252 if (!(pNv->Options = xalloc(sizeof(NVOptions))))
1254 memcpy(pNv->Options, NVOptions, sizeof(NVOptions));
1255 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pNv->Options);
1257 /* Set the bits per RGB for 8bpp mode */
1258 if (pScrn->depth == 8)
1263 if (pNv->Architecture == NV_ARCH_50) {
1264 pNv->randr12_enable = TRUE;
1266 pNv->randr12_enable = FALSE;
1267 if (xf86ReturnOptValBool(pNv->Options, OPTION_RANDR12, FALSE)) {
1268 pNv->randr12_enable = TRUE;
1271 xf86DrvMsg(pScrn->scrnIndex, from, "Randr1.2 support %sabled\n", pNv->randr12_enable ? "en" : "dis");
1273 pNv->HWCursor = TRUE;
1275 * The preferred method is to use the "hw cursor" option as a tri-state
1276 * option, with the default set above.
1278 if (xf86GetOptValBool(pNv->Options, OPTION_HW_CURSOR, &pNv->HWCursor)) {
1281 /* For compatibility, accept this too (as an override) */
1282 if (xf86ReturnOptValBool(pNv->Options, OPTION_SW_CURSOR, FALSE)) {
1284 pNv->HWCursor = FALSE;
1286 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
1287 pNv->HWCursor ? "HW" : "SW");
1289 pNv->FpScale = TRUE;
1290 if (xf86GetOptValBool(pNv->Options, OPTION_FP_SCALE, &pNv->FpScale)) {
1291 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Flat panel scaling %s\n",
1292 pNv->FpScale ? "on" : "off");
1294 if (xf86ReturnOptValBool(pNv->Options, OPTION_NOACCEL, FALSE)) {
1295 pNv->NoAccel = TRUE;
1296 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1298 if (xf86ReturnOptValBool(pNv->Options, OPTION_SHADOW_FB, FALSE)) {
1299 pNv->ShadowFB = TRUE;
1300 pNv->NoAccel = TRUE;
1301 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1302 "Using \"Shadow Framebuffer\" - acceleration disabled\n");
1304 if (!pNv->NoAccel) {
1307 if((s = (char *)xf86GetOptValString(pNv->Options, OPTION_ACCELMETHOD))) {
1308 if(!xf86NameCmp(s,"XAA")) {
1310 pNv->useEXA = FALSE;
1311 } else if(!xf86NameCmp(s,"EXA")) {
1316 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s acceleration method\n", pNv->useEXA ? "EXA" : "XAA");
1318 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1322 pNv->RandRRotation = FALSE;
1323 if ((s = xf86GetOptValString(pNv->Options, OPTION_ROTATE))) {
1324 if(!xf86NameCmp(s, "CW")) {
1325 pNv->ShadowFB = TRUE;
1326 pNv->NoAccel = TRUE;
1327 pNv->HWCursor = FALSE;
1329 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1330 "Rotating screen clockwise - acceleration disabled\n");
1332 if(!xf86NameCmp(s, "CCW")) {
1333 pNv->ShadowFB = TRUE;
1334 pNv->NoAccel = TRUE;
1335 pNv->HWCursor = FALSE;
1337 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1338 "Rotating screen counter clockwise - acceleration disabled\n");
1340 if(!xf86NameCmp(s, "RandR")) {
1342 pNv->ShadowFB = TRUE;
1343 pNv->NoAccel = TRUE;
1344 pNv->HWCursor = FALSE;
1345 pNv->RandRRotation = TRUE;
1346 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1347 "Using RandR rotation - acceleration disabled\n");
1349 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
1350 "This driver was not compiled with support for the Resize and "
1351 "Rotate extension. Cannot honor 'Option \"Rotate\" "
1355 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1356 "\"%s\" is not a valid value for Option \"Rotate\"\n", s);
1357 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1358 "Valid options are \"CW\", \"CCW\", and \"RandR\"\n");
1362 if(xf86GetOptValInteger(pNv->Options, OPTION_VIDEO_KEY, &(pNv->videoKey))) {
1363 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n",
1366 pNv->videoKey = (1 << pScrn->offset.red) |
1367 (1 << pScrn->offset.green) |
1368 (((pScrn->mask.blue >> pScrn->offset.blue) - 1) << pScrn->offset.blue);
1371 if (xf86GetOptValBool(pNv->Options, OPTION_FLAT_PANEL, &(pNv->FlatPanel))) {
1372 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "forcing %s usage\n",
1373 pNv->FlatPanel ? "DFP" : "CRTC");
1375 pNv->FlatPanel = -1; /* autodetect later */
1378 pNv->FPDither = FALSE;
1379 if (xf86GetOptValBool(pNv->Options, OPTION_FP_DITHER, &(pNv->FPDither)))
1380 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "enabling flat panel dither\n");
1382 if (xf86GetOptValInteger(pNv->Options, OPTION_CRTC_NUMBER,
1385 if((pNv->CRTCnumber < 0) || (pNv->CRTCnumber > 1)) {
1386 pNv->CRTCnumber = -1;
1387 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1388 "Invalid CRTC number. Must be 0 or 1\n");
1391 pNv->CRTCnumber = -1; /* autodetect later */
1395 if (xf86GetOptValInteger(pNv->Options, OPTION_FP_TWEAK,
1398 pNv->usePanelTweak = TRUE;
1400 pNv->usePanelTweak = FALSE;
1403 if (pNv->pEnt->device->MemBase != 0) {
1404 /* Require that the config file value matches one of the PCI values. */
1405 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->MemBase)) {
1407 "MemBase 0x%08lX doesn't match any PCI base register.\n",
1408 pNv->pEnt->device->MemBase);
1410 pNv->VRAMPhysical = pNv->pEnt->device->MemBase;
1413 if (PCI_DEV_MEM_BASE(pNv->PciInfo, 1) != 0) {
1414 pNv->VRAMPhysical = PCI_DEV_MEM_BASE(pNv->PciInfo, 1) & 0xff800000;
1417 NVPreInitFail("No valid FB address in PCI config space\n");
1421 xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
1422 (unsigned long)pNv->VRAMPhysical);
1424 if (pNv->pEnt->device->IOBase != 0) {
1425 /* Require that the config file value matches one of the PCI values. */
1426 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->IOBase)) {
1427 NVPreInitFail("IOBase 0x%08lX doesn't match any PCI base register.\n",
1428 pNv->pEnt->device->IOBase);
1430 pNv->IOAddress = pNv->pEnt->device->IOBase;
1433 if (PCI_DEV_MEM_BASE(pNv->PciInfo, 0) != 0) {
1434 pNv->IOAddress = PCI_DEV_MEM_BASE(pNv->PciInfo, 0) & 0xffffc000;
1437 NVPreInitFail("No valid MMIO address in PCI config space\n");
1440 xf86DrvMsg(pScrn->scrnIndex, from, "MMIO registers at 0x%lX\n",
1441 (unsigned long)pNv->IOAddress);
1443 if (xf86RegisterResources(pNv->pEnt->index, NULL, ResExclusive)) {
1444 NVPreInitFail("xf86RegisterResources() found resource conflicts\n");
1446 /* The highest architecture currently supported is NV5x */
1447 if (pNv->NVArch >= 0x50) {
1448 pNv->Architecture = NV_ARCH_50;
1449 } else if (pNv->NVArch >= 0x40) {
1450 pNv->Architecture = NV_ARCH_40;
1451 } else if (pNv->NVArch >= 0x30) {
1452 pNv->Architecture = NV_ARCH_30;
1453 } else if (pNv->NVArch >= 0x20) {
1454 pNv->Architecture = NV_ARCH_20;
1455 } else if (pNv->NVArch >= 0x10) {
1456 pNv->Architecture = NV_ARCH_10;
1457 } else if (pNv->NVArch >= 0x04) {
1458 pNv->Architecture = NV_ARCH_04;
1459 /* The lowest architecture currently supported is NV04 */
1464 pNv->alphaCursor = (pNv->Architecture >= NV_ARCH_10) &&
1465 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10);
1467 if (pNv->randr12_enable) {
1468 /* Allocate an xf86CrtcConfig */
1469 xf86CrtcConfigInit(pScrn, &nv_xf86crtc_config_funcs);
1470 xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1473 xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, 2048);
1476 if (NVPreInitDRI(pScrn) == FALSE) {
1477 NVPreInitFail("\n");
1480 if (!pNv->randr12_enable) {
1481 if ((pScrn->monitor->nHsync == 0) &&
1482 (pScrn->monitor->nVrefresh == 0))
1483 config_mon_rates = FALSE;
1485 config_mon_rates = TRUE;
1488 NVCommonSetup(pScrn);
1490 if (pNv->randr12_enable) {
1491 if (pNv->Architecture < NV_ARCH_50) {
1494 num_crtc = pNv->twoHeads ? 2 : 1;
1495 for (i = 0; i < num_crtc; i++) {
1496 nv_crtc_init(pScrn, i);
1499 NvSetupOutputs(pScrn);
1501 if (!NV50DispPreInit(pScrn))
1502 NVPreInitFail("\n");
1503 if (!NV50CreateOutputs(pScrn))
1504 NVPreInitFail("\n");
1505 NV50DispCreateCrtcs(pScrn);
1508 if (!xf86InitialConfiguration(pScrn, FALSE))
1509 NVPreInitFail("No valid modes.\n");
1512 pScrn->videoRam = pNv->RamAmountKBytes;
1513 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kBytes\n",
1516 pNv->VRAMPhysicalSize = pScrn->videoRam * 1024;
1519 * If the driver can do gamma correction, it should call xf86SetGamma()
1524 Gamma zeros = {0.0, 0.0, 0.0};
1526 if (!xf86SetGamma(pScrn, zeros)) {
1527 NVPreInitFail("\n");
1532 * Setup the ClockRanges, which describe what clock ranges are available,
1533 * and what sort of modes they can be used for.
1536 clockRanges = xnfcalloc(sizeof(ClockRange), 1);
1537 clockRanges->next = NULL;
1538 clockRanges->minClock = pNv->MinVClockFreqKHz;
1539 clockRanges->maxClock = pNv->MaxVClockFreqKHz;
1540 clockRanges->clockIndex = -1; /* programmable */
1541 clockRanges->doubleScanAllowed = TRUE;
1542 if((pNv->Architecture == NV_ARCH_20) ||
1543 ((pNv->Architecture == NV_ARCH_10) &&
1544 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10) &&
1545 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV15)))
1548 clockRanges->interlaceAllowed = FALSE;
1550 clockRanges->interlaceAllowed = TRUE;
1553 if(pNv->FlatPanel == 1) {
1554 clockRanges->interlaceAllowed = FALSE;
1555 clockRanges->doubleScanAllowed = FALSE;
1558 if(pNv->Architecture < NV_ARCH_10) {
1559 max_width = (pScrn->bitsPerPixel > 16) ? 2032 : 2048;
1562 max_width = (pScrn->bitsPerPixel > 16) ? 4080 : 4096;
1567 /* If DFP, add a modeline corresponding to its panel size */
1568 if (pNv->FlatPanel && !pNv->Television && pNv->fpWidth && pNv->fpHeight) {
1569 DisplayModePtr Mode;
1571 Mode = xnfcalloc(1, sizeof(DisplayModeRec));
1572 Mode = xf86CVTMode(pNv->fpWidth, pNv->fpHeight, 60.00, TRUE, FALSE);
1573 Mode->type = M_T_DRIVER;
1574 pScrn->monitor->Modes = xf86ModesAdd(pScrn->monitor->Modes, Mode);
1576 if (!config_mon_rates) {
1578 Mode->HSync = ((float) Mode->Clock ) / ((float) Mode->HTotal);
1579 if (!Mode->VRefresh)
1580 Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) /
1581 ((float) (Mode->HTotal * Mode->VTotal));
1583 if (Mode->HSync < pScrn->monitor->hsync[0].lo)
1584 pScrn->monitor->hsync[0].lo = Mode->HSync;
1585 if (Mode->HSync > pScrn->monitor->hsync[0].hi)
1586 pScrn->monitor->hsync[0].hi = Mode->HSync;
1587 if (Mode->VRefresh < pScrn->monitor->vrefresh[0].lo)
1588 pScrn->monitor->vrefresh[0].lo = Mode->VRefresh;
1589 if (Mode->VRefresh > pScrn->monitor->vrefresh[0].hi)
1590 pScrn->monitor->vrefresh[0].hi = Mode->VRefresh;
1592 pScrn->monitor->nHsync = 1;
1593 pScrn->monitor->nVrefresh = 1;
1599 * xf86ValidateModes will check that the mode HTotal and VTotal values
1600 * don't exceed the chipset's limit if pScrn->maxHValue and
1601 * pScrn->maxVValue are set. Since our NVValidMode() already takes
1602 * care of this, we don't worry about setting them here.
1604 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
1605 pScrn->display->modes, clockRanges,
1606 NULL, 256, max_width,
1607 512, 128, max_height,
1608 pScrn->display->virtualX,
1609 pScrn->display->virtualY,
1610 pNv->VRAMPhysicalSize / 2,
1611 LOOKUP_BEST_REFRESH);
1614 NVPreInitFail("\n");
1617 /* Prune the modes marked as invalid */
1618 xf86PruneDriverModes(pScrn);
1620 if (i == 0 || pScrn->modes == NULL) {
1621 NVPreInitFail("No valid modes found\n");
1625 * Set the CRTC parameters for all of the modes based on the type
1626 * of mode, and the chipset's interlace requirements.
1628 * Calling this is required if the mode->Crtc* values are used by the
1629 * driver and if the driver doesn't provide code to set them. They
1630 * are not pre-initialised at all.
1632 xf86SetCrtcForModes(pScrn, 0);
1634 /* Set the current mode to the first in the list */
1635 pScrn->currentMode = pScrn->modes;
1637 /* Print the list of modes being used */
1638 xf86PrintModes(pScrn);
1640 /* Set display resolution */
1641 xf86SetDpi(pScrn, 0, 0);
1645 * XXX This should be taken into account in some way in the mode valdation
1649 if (xf86LoadSubModule(pScrn, "fb") == NULL) {
1650 NVPreInitFail("\n");
1653 xf86LoaderReqSymLists(fbSymbols, NULL);
1655 /* Load XAA if needed */
1656 if (!pNv->NoAccel) {
1657 if (!xf86LoadSubModule(pScrn, pNv->useEXA ? "exa" : "xaa")) {
1658 NVPreInitFail("\n");
1660 xf86LoaderReqSymLists(xaaSymbols, NULL);
1663 /* Load ramdac if needed */
1664 if (pNv->HWCursor) {
1665 if (!xf86LoadSubModule(pScrn, "ramdac")) {
1666 NVPreInitFail("\n");
1668 xf86LoaderReqSymLists(ramdacSymbols, NULL);
1671 /* Load shadowfb if needed */
1672 if (pNv->ShadowFB) {
1673 if (!xf86LoadSubModule(pScrn, "shadowfb")) {
1674 NVPreInitFail("\n");
1676 xf86LoaderReqSymLists(shadowSymbols, NULL);
1679 pNv->CurrentLayout.bitsPerPixel = pScrn->bitsPerPixel;
1680 pNv->CurrentLayout.depth = pScrn->depth;
1681 pNv->CurrentLayout.displayWidth = pScrn->displayWidth;
1682 pNv->CurrentLayout.weight.red = pScrn->weight.red;
1683 pNv->CurrentLayout.weight.green = pScrn->weight.green;
1684 pNv->CurrentLayout.weight.blue = pScrn->weight.blue;
1685 pNv->CurrentLayout.mode = pScrn->currentMode;
1687 xf86FreeInt10(pNv->pInt10);
1695 * Map the framebuffer and MMIO memory.
1699 NVMapMem(ScrnInfoPtr pScrn)
1701 NVPtr pNv = NVPTR(pScrn);
1703 pNv->FB = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, pNv->VRAMPhysicalSize/2);
1705 ErrorF("Failed to allocate memory for framebuffer!\n");
1708 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1709 "Allocated %dMiB VRAM for framebuffer + offscreen pixmaps\n",
1710 (unsigned int)(pNv->FB->size >> 20));
1712 /*XXX: have to get these after we've allocated something, otherwise
1713 * they're uninitialised in the DRM!
1715 pNv->VRAMSize = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_FB_SIZE);
1716 pNv->VRAMPhysical = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_FB_PHYSICAL);
1717 pNv->AGPSize = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_AGP_SIZE);
1718 pNv->AGPPhysical = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_AGP_PHYSICAL);
1719 if ( ! pNv->AGPSize ) /*if no AGP*/
1721 pNv->SGPhysical = NVDRMGetParam(pNv, NOUVEAU_GETPARAM_PCI_PHYSICAL);
1723 int gart_scratch_size;
1726 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1727 "AGPGART: %dMiB available\n",
1728 (unsigned int)(pNv->AGPSize >> 20));
1730 if (pNv->AGPSize > (16*1024*1024))
1731 gart_scratch_size = 16*1024*1024;
1733 gart_scratch_size = pNv->AGPSize;
1738 gart_scratch_size = (4 << 20) - (1 << 18) ;
1739 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1740 "GART: PCI DMA - using %dKiB\n", gart_scratch_size >> 10);
1744 /*The DRM allocates AGP memory, PCI as a fallback */
1745 pNv->GARTScratch = NVAllocateMemory(pNv, NOUVEAU_MEM_AGP | NOUVEAU_MEM_PCI_ACCEPTABLE,
1747 if (!pNv->GARTScratch) {
1748 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1749 "Unable to allocate GART memory\n");
1751 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1752 "GART: mapped %dMiB at %p, offset is %d\n",
1753 (unsigned int)(pNv->GARTScratch->size >> 20),
1754 pNv->GARTScratch->map, pNv->GARTScratch->offset);
1758 pNv->Cursor = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, 64*1024);
1760 ErrorF("Failed to allocate memory for hardware cursor\n");
1764 pNv->ScratchBuffer = NVAllocateMemory(pNv, NOUVEAU_MEM_FB,
1765 pNv->Architecture <NV_ARCH_10 ? 8192 : 16384);
1766 if (!pNv->ScratchBuffer) {
1767 ErrorF("Failed to allocate memory for scratch buffer\n");
1771 if (pNv->Architecture >= NV_ARCH_50) {
1772 pNv->CLUT = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, 0x1000);
1774 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1775 "Failed to allocate memory for CLUT\n");
1784 * Unmap the framebuffer and MMIO memory.
1788 NVUnmapMem(ScrnInfoPtr pScrn)
1790 NVPtr pNv = NVPTR(pScrn);
1792 NVFreeMemory(pNv, pNv->FB);
1793 NVFreeMemory(pNv, pNv->ScratchBuffer);
1794 NVFreeMemory(pNv, pNv->Cursor);
1801 * Initialise a new mode.
1805 NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
1807 vgaHWPtr hwp = VGAHWPTR(pScrn);
1809 NVPtr pNv = NVPTR(pScrn);
1812 /* Initialise the ModeReg values */
1813 if (!vgaHWInit(pScrn, mode))
1815 pScrn->vtSema = TRUE;
1817 vgaReg = &hwp->ModeReg;
1818 nvReg = &pNv->ModeReg;
1820 if(!NVDACInit(pScrn, mode))
1823 NVLockUnlock(pNv, 0);
1825 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, nvReg->crtcOwner);
1826 NVLockUnlock(pNv, 0);
1829 /* Program the registers */
1830 vgaHWProtect(pScrn, TRUE);
1832 NVDACRestore(pScrn, vgaReg, nvReg, FALSE);
1834 #if X_BYTE_ORDER == X_BIG_ENDIAN
1835 /* turn on LFB swapping */
1839 tmp = nvReadVGA(pNv, NV_VGA_CRTCX_SWAPPING);
1841 nvWriteVGA(pNv, NV_VGA_CRTCX_SWAPPING, tmp);
1845 NVResetGraphics(pScrn);
1847 vgaHWProtect(pScrn, FALSE);
1849 pNv->CurrentLayout.mode = mode;
1855 * Restore the initial (text) mode.
1858 NVRestore(ScrnInfoPtr pScrn)
1860 vgaHWPtr hwp = VGAHWPTR(pScrn);
1861 vgaRegPtr vgaReg = &hwp->SavedReg;
1862 NVPtr pNv = NVPTR(pScrn);
1863 NVRegPtr nvReg = &pNv->SavedReg;
1865 NVLockUnlock(pNv, 0);
1868 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->CRTCnumber * 0x3);
1869 NVLockUnlock(pNv, 0);
1872 /* Only restore text mode fonts/text for the primary card */
1873 vgaHWProtect(pScrn, TRUE);
1874 NVDACRestore(pScrn, vgaReg, nvReg, pNv->Primary);
1876 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->vtOWNER);
1878 vgaHWProtect(pScrn, FALSE);
1882 #define DEPTH_SHIFT(val, w) ((val << (8 - w)) | (val >> ((w << 1) - 8)))
1883 #define MAKE_INDEX(in, w) (DEPTH_SHIFT(in, w) * 3)
1886 NVLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
1887 LOCO * colors, VisualPtr pVisual)
1889 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1891 NVPtr pNv = NVPTR(pScrn);
1894 for (c = 0; c < xf86_config->num_crtc; c++) {
1895 xf86CrtcPtr crtc = xf86_config->crtc[c];
1896 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1899 regp = &pNv->ModeReg.crtc_reg[nv_crtc->crtc];
1901 if (crtc->enabled == 0)
1904 switch (pNv->CurrentLayout.depth) {
1906 for (i = 0; i < numColors; i++) {
1908 regp->DAC[MAKE_INDEX(index, 5) + 0] =
1910 regp->DAC[MAKE_INDEX(index, 5) + 1] =
1911 colors[index].green;
1912 regp->DAC[MAKE_INDEX(index, 5) + 2] =
1917 for (i = 0; i < numColors; i++) {
1919 regp->DAC[MAKE_INDEX(index, 6) + 1] =
1920 colors[index].green;
1922 regp->DAC[MAKE_INDEX(index, 5) +
1923 0] = colors[index].red;
1924 regp->DAC[MAKE_INDEX(index, 5) +
1925 2] = colors[index].blue;
1930 for (i = 0; i < numColors; i++) {
1932 regp->DAC[index * 3] = colors[index].red;
1933 regp->DAC[(index * 3) + 1] =
1934 colors[index].green;
1935 regp->DAC[(index * 3) + 2] =
1941 NVCrtcLoadPalette(crtc);
1945 //#define DEPTH_SHIFT(val, w) ((val << (8 - w)) | (val >> ((w << 1) - 8)))
1946 #define COLOR(c) (unsigned int)(0x3fff * ((c)/255.0))
1948 NV50LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
1949 LOCO * colors, VisualPtr pVisual)
1951 NVPtr pNv = NVPTR(pScrn);
1954 unsigned short red, green, blue, unused;
1955 } *lut = (void *) pNv->CLUT->map;
1957 switch (pScrn->depth) {
1959 for (i = 0; i < numColors; i++) {
1961 lut[DEPTH_SHIFT(index, 5)].red =
1962 COLOR(colors[index].red);
1963 lut[DEPTH_SHIFT(index, 5)].green =
1964 COLOR(colors[index].green);
1965 lut[DEPTH_SHIFT(index, 5)].blue =
1966 COLOR(colors[index].blue);
1970 for (i = 0; i < numColors; i++) {
1972 lut[DEPTH_SHIFT(index, 6)].green =
1973 COLOR(colors[index].green);
1975 lut[DEPTH_SHIFT(index, 5)].red =
1976 COLOR(colors[index].red);
1977 lut[DEPTH_SHIFT(index, 5)].blue =
1978 COLOR(colors[index].blue);
1983 for (i = 0; i < numColors; i++) {
1985 lut[index].red = COLOR(colors[index].red);
1986 lut[index].green = COLOR(colors[index].green);
1987 lut[index].blue = COLOR(colors[index].blue);
1994 static void NVBacklightEnable(NVPtr pNv, Bool on)
1996 /* This is done differently on each laptop. Here we
1997 define the ones we know for sure. */
1999 #if defined(__powerpc__)
2000 if((pNv->Chipset == 0x10DE0179) ||
2001 (pNv->Chipset == 0x10DE0189) ||
2002 (pNv->Chipset == 0x10DE0329))
2004 /* NV17,18,34 Apple iMac, iBook, PowerBook */
2005 CARD32 tmp_pmc, tmp_pcrt;
2006 tmp_pmc = nvReadMC(pNv, 0x10F0) & 0x7FFFFFFF;
2007 tmp_pcrt = nvReadCRTC0(pNv, NV_CRTC_081C) & 0xFFFFFFFC;
2009 tmp_pmc |= (1 << 31);
2012 nvWriteMC(pNv, 0x10F0, tmp_pmc);
2013 nvWriteCRTC0(pNv, NV_CRTC_081C, tmp_pcrt);
2018 if(pNv->twoHeads && ((pNv->Chipset & 0x0ff0) != CHIPSET_NV11)) {
2019 nvWriteMC(pNv, 0x130C, on ? 3 : 7);
2024 fpcontrol = nvReadCurRAMDAC(pNv, 0x848) & 0xCfffffCC;
2026 /* cut the TMDS output */
2027 if(on) fpcontrol |= pNv->fpSyncs;
2028 else fpcontrol |= 0x20000022;
2030 nvWriteCurRAMDAC(pNv, 0x0848, fpcontrol);
2035 NVDPMSSetLCD(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
2037 NVPtr pNv = NVPTR(pScrn);
2039 if (!pScrn->vtSema) return;
2041 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
2043 switch (PowerManagementMode) {
2044 case DPMSModeStandby: /* HSync: Off, VSync: On */
2045 case DPMSModeSuspend: /* HSync: On, VSync: Off */
2046 case DPMSModeOff: /* HSync: Off, VSync: Off */
2047 NVBacklightEnable(pNv, 0);
2049 case DPMSModeOn: /* HSync: On, VSync: On */
2050 NVBacklightEnable(pNv, 1);
2058 NVDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
2060 unsigned char crtc1A;
2061 vgaHWPtr hwp = VGAHWPTR(pScrn);
2063 if (!pScrn->vtSema) return;
2065 crtc1A = hwp->readCrtc(hwp, 0x1A) & ~0xC0;
2067 switch (PowerManagementMode) {
2068 case DPMSModeStandby: /* HSync: Off, VSync: On */
2071 case DPMSModeSuspend: /* HSync: On, VSync: Off */
2074 case DPMSModeOff: /* HSync: Off, VSync: Off */
2077 case DPMSModeOn: /* HSync: On, VSync: On */
2082 /* vgaHWDPMSSet will merely cut the dac output */
2083 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
2085 hwp->writeCrtc(hwp, 0x1A, crtc1A);
2091 /* This gets called at the start of each server generation */
2094 NVScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
2101 unsigned char *FBStart;
2102 int width, height, displayWidth, offscreenHeight, shadowHeight;
2106 * First get the ScrnInfoRec
2108 pScrn = xf86Screens[pScreen->myNum];
2110 hwp = VGAHWPTR(pScrn);
2113 /* Map the VGA memory when the primary video */
2115 hwp->MapSize = 0x10000;
2116 if (!vgaHWMapMem(pScrn))
2120 /* First init DRI/DRM */
2121 if (!NVDRIScreenInit(pScrn))
2124 ret = drmCommandNone(pNv->drm_fd, DRM_NOUVEAU_CARD_INIT);
2126 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2127 "Error initialising the nouveau kernel module: %d\n",
2132 /* Allocate and map memory areas we need */
2133 if (!NVMapMem(pScrn))
2136 if (!pNv->NoAccel) {
2137 /* Init DRM - Alloc FIFO */
2138 if (!NVInitDma(pScrn))
2141 /* setup graphics objects */
2142 if (!NVAccelCommonInit(pScrn))
2146 if (!pNv->randr12_enable) {
2147 /* Save the current state */
2149 /* Initialise the first mode */
2150 if (!NVModeInit(pScrn, pScrn->currentMode))
2153 /* Darken the screen for aesthetic reasons and set the viewport */
2155 NVSaveScreen(pScreen, SCREEN_SAVER_ON);
2156 pScrn->AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
2159 pScrn->memPhysBase = pNv->VRAMPhysical;
2160 pScrn->fbOffset = 0;
2162 if (!NVEnterVT(scrnIndex, 0))
2168 * The next step is to setup the screen's visuals, and initialise the
2169 * framebuffer code. In cases where the framebuffer's default
2170 * choices for things like visual layouts and bits per RGB are OK,
2171 * this may be as simple as calling the framebuffer's ScreenInit()
2172 * function. If not, the visuals will need to be setup before calling
2173 * a fb ScreenInit() function and fixed up after.
2175 * For most PC hardware at depths >= 8, the defaults that fb uses
2176 * are not appropriate. In this driver, we fixup the visuals after.
2180 * Reset the visual list.
2182 miClearVisualTypes();
2184 /* Setup the visuals we support. */
2186 if (!miSetVisualTypes(pScrn->depth,
2187 miGetDefaultVisualMask(pScrn->depth), 8,
2188 pScrn->defaultVisual))
2190 if (!miSetPixmapDepths ()) return FALSE;
2193 * Call the framebuffer layer's ScreenInit function, and fill in other
2197 width = pScrn->virtualX;
2198 height = pScrn->virtualY;
2199 displayWidth = pScrn->displayWidth;
2203 height = pScrn->virtualX;
2204 width = pScrn->virtualY;
2207 /* If RandR rotation is enabled, leave enough space in the
2208 * framebuffer for us to rotate the screen dimensions without
2209 * changing the pitch.
2211 if(pNv->RandRRotation)
2212 shadowHeight = max(width, height);
2214 shadowHeight = height;
2217 pNv->ShadowPitch = BitmapBytePad(pScrn->bitsPerPixel * width);
2218 pNv->ShadowPtr = xalloc(pNv->ShadowPitch * shadowHeight);
2219 displayWidth = pNv->ShadowPitch / (pScrn->bitsPerPixel >> 3);
2220 FBStart = pNv->ShadowPtr;
2222 pNv->ShadowPtr = NULL;
2223 FBStart = pNv->FB->map;
2226 switch (pScrn->bitsPerPixel) {
2230 ret = fbScreenInit(pScreen, FBStart, width, height,
2231 pScrn->xDpi, pScrn->yDpi,
2232 displayWidth, pScrn->bitsPerPixel);
2235 xf86DrvMsg(scrnIndex, X_ERROR,
2236 "Internal error: invalid bpp (%d) in NVScreenInit\n",
2237 pScrn->bitsPerPixel);
2244 if (pScrn->bitsPerPixel > 8) {
2245 /* Fixup RGB ordering */
2246 visual = pScreen->visuals + pScreen->numVisuals;
2247 while (--visual >= pScreen->visuals) {
2248 if ((visual->class | DynamicClass) == DirectColor) {
2249 visual->offsetRed = pScrn->offset.red;
2250 visual->offsetGreen = pScrn->offset.green;
2251 visual->offsetBlue = pScrn->offset.blue;
2252 visual->redMask = pScrn->mask.red;
2253 visual->greenMask = pScrn->mask.green;
2254 visual->blueMask = pScrn->mask.blue;
2259 fbPictureInit (pScreen, 0, 0);
2261 xf86SetBlackWhitePixels(pScreen);
2263 offscreenHeight = pNv->FB->size /
2264 (pScrn->displayWidth * pScrn->bitsPerPixel >> 3);
2265 if(offscreenHeight > 32767)
2266 offscreenHeight = 32767;
2271 AvailFBArea.x2 = pScrn->displayWidth;
2272 AvailFBArea.y2 = offscreenHeight;
2273 xf86InitFBManager(pScreen, &AvailFBArea);
2276 if (!pNv->NoAccel) {
2282 NVResetGraphics(pScrn);
2284 miInitializeBackingStore(pScreen);
2285 xf86SetBackingStore(pScreen);
2286 xf86SetSilkenMouse(pScreen);
2288 /* Finish DRI init */
2289 NVDRIFinishScreenInit(pScrn);
2291 /* Initialize software cursor.
2292 Must precede creation of the default colormap */
2293 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
2295 /* Initialize HW cursor layer.
2296 Must follow software cursor initialization*/
2297 if (pNv->HWCursor) {
2298 if (pNv->Architecture < NV_ARCH_50)
2299 ret = NVCursorInit(pScreen);
2301 ret = NV50CursorInit(pScreen);
2304 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2305 "Hardware cursor initialization failed\n");
2306 pNv->HWCursor = FALSE;
2310 /* Initialise default colourmap */
2311 if (!miCreateDefColormap(pScreen))
2314 /* Initialize colormap layer.
2315 Must follow initialization of the default colormap */
2316 if (!pNv->randr12_enable) {
2317 if(!xf86HandleColormaps(pScreen, 256, 8, NVDACLoadPalette,
2318 NULL, CMAP_RELOAD_ON_MODE_SWITCH | CMAP_PALETTED_TRUECOLOR))
2321 if (pNv->Architecture < NV_ARCH_50) {
2322 if (!xf86HandleColormaps(pScreen, 256, 8, NVLoadPalette,
2324 CMAP_RELOAD_ON_MODE_SWITCH |
2325 CMAP_PALETTED_TRUECOLOR))
2328 if (!xf86HandleColormaps(pScreen, 256, 8, NV50LoadPalette,
2329 NULL, CMAP_PALETTED_TRUECOLOR))
2334 if (pNv->randr12_enable) {
2335 xf86DPMSInit(pScreen, xf86DPMSSet, 0);
2337 if (!xf86CrtcScreenInit(pScreen))
2340 pNv->PointerMoved = pScrn->PointerMoved;
2341 pScrn->PointerMoved = NVPointerMoved;
2345 RefreshAreaFuncPtr refreshArea = NVRefreshArea;
2347 if(pNv->Rotate || pNv->RandRRotation) {
2348 pNv->PointerMoved = pScrn->PointerMoved;
2350 pScrn->PointerMoved = NVPointerMoved;
2352 switch(pScrn->bitsPerPixel) {
2353 case 8: refreshArea = NVRefreshArea8; break;
2354 case 16: refreshArea = NVRefreshArea16; break;
2355 case 32: refreshArea = NVRefreshArea32; break;
2357 if(!pNv->RandRRotation) {
2359 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2360 "Driver rotation enabled, RandR disabled\n");
2364 ShadowFBInit(pScreen, refreshArea);
2367 if (!pNv->randr12_enable) {
2369 xf86DPMSInit(pScreen, NVDPMSSetLCD, 0);
2371 xf86DPMSInit(pScreen, NVDPMSSet, 0);
2374 pScrn->memPhysBase = pNv->VRAMPhysical;
2375 pScrn->fbOffset = 0;
2377 if(pNv->Rotate == 0 && !pNv->RandRRotation)
2378 NVInitVideo(pScreen);
2380 pScreen->SaveScreen = NVSaveScreen;
2382 /* Wrap the current CloseScreen function */
2383 pNv->CloseScreen = pScreen->CloseScreen;
2384 pScreen->CloseScreen = NVCloseScreen;
2386 pNv->BlockHandler = pScreen->BlockHandler;
2387 pScreen->BlockHandler = NVBlockHandler;
2390 /* Install our DriverFunc. We have to do it this way instead of using the
2391 * HaveDriverFuncs argument to xf86AddDriver, because InitOutput clobbers
2392 * pScrn->DriverFunc */
2393 if (!pNv->randr12_enable)
2394 pScrn->DriverFunc = NVDriverFunc;
2397 /* Report any unused options (only for the first generation) */
2398 if (serverGeneration == 1) {
2399 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
2405 NVSaveScreen(ScreenPtr pScreen, int mode)
2407 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
2408 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
2409 NVPtr pNv = NVPTR(pScrn);
2411 Bool on = xf86IsUnblank(mode);
2413 if (pNv->randr12_enable) {
2414 if (pScrn->vtSema) {
2415 for (i = 0; i < xf86_config->num_crtc; i++) {
2417 if (xf86_config->crtc[i]->enabled) {
2418 NVCrtcBlankScreen(xf86_config->crtc[i],
2426 return vgaHWSaveScreen(pScreen, mode);
2430 NVSave(ScrnInfoPtr pScrn)
2432 NVPtr pNv = NVPTR(pScrn);
2433 NVRegPtr nvReg = &pNv->SavedReg;
2434 vgaHWPtr pVga = VGAHWPTR(pScrn);
2435 vgaRegPtr vgaReg = &pVga->SavedReg;
2438 if (pNv->randr12_enable) {
2439 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
2440 int vgaflags = VGA_SR_CMAP | VGA_SR_MODE;
2442 for (i = 0; i < xf86_config->num_crtc; i++) {
2443 xf86_config->crtc[i]->funcs->save(xf86_config->crtc[i]);
2446 for (i = 0; i < xf86_config->num_output; i++) {
2447 xf86_config->output[i]->funcs->save(xf86_config->
2453 vgaflags |= VGA_SR_FONTS;
2455 vgaHWSave(pScrn, vgaReg, vgaflags);
2457 NVLockUnlock(pNv, 0);
2459 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->CRTCnumber * 0x3);
2460 NVLockUnlock(pNv, 0);
2463 NVDACSave(pScrn, vgaReg, nvReg, pNv->Primary);
2469 NVRandRGetInfo(ScrnInfoPtr pScrn, Rotation *rotations)
2471 NVPtr pNv = NVPTR(pScrn);
2473 if(pNv->RandRRotation)
2474 *rotations = RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_270;
2476 *rotations = RR_Rotate_0;
2482 NVRandRSetConfig(ScrnInfoPtr pScrn, xorgRRConfig *config)
2484 NVPtr pNv = NVPTR(pScrn);
2486 switch(config->rotation) {
2489 pScrn->PointerMoved = pNv->PointerMoved;
2494 pScrn->PointerMoved = NVPointerMoved;
2499 pScrn->PointerMoved = NVPointerMoved;
2503 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2504 "Unexpected rotation in NVRandRSetConfig!\n");
2506 pScrn->PointerMoved = pNv->PointerMoved;
2514 NVDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer data)
2518 return NVRandRGetInfo(pScrn, (Rotation*)data);
2520 return NVRandRSetConfig(pScrn, (xorgRRConfig*)data);