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 $ */
32 #include "nv_include.h"
34 #include "xf86int10.h"
38 extern DisplayModePtr xf86ModesAdd(DisplayModePtr Modes, DisplayModePtr Additions);
41 * Forward definitions for the functions that make up the driver.
43 /* Mandatory functions */
44 static const OptionInfoRec * NVAvailableOptions(int chipid, int busid);
45 static void NVIdentify(int flags);
46 #ifndef XSERVER_LIBPCIACCESS
47 static Bool NVProbe(DriverPtr drv, int flags);
48 #endif /* XSERVER_LIBPCIACCESS */
49 static Bool NVPreInit(ScrnInfoPtr pScrn, int flags);
50 static Bool NVScreenInit(int Index, ScreenPtr pScreen, int argc,
52 static Bool NVEnterVT(int scrnIndex, int flags);
53 static void NVLeaveVT(int scrnIndex, int flags);
54 static Bool NVCloseScreen(int scrnIndex, ScreenPtr pScreen);
55 static Bool NVSaveScreen(ScreenPtr pScreen, int mode);
57 /* Optional functions */
58 static void NVFreeScreen(int scrnIndex, int flags);
59 static ModeStatus NVValidMode(int scrnIndex, DisplayModePtr mode,
60 Bool verbose, int flags);
62 static Bool NVDriverFunc(ScrnInfoPtr pScrnInfo, xorgDriverFuncOp op,
66 /* Internally used functions */
68 static Bool NVMapMem(ScrnInfoPtr pScrn);
69 static Bool NVUnmapMem(ScrnInfoPtr pScrn);
70 static void NVSave(ScrnInfoPtr pScrn);
71 static void NVRestore(ScrnInfoPtr pScrn);
72 static Bool NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
74 #ifdef XSERVER_LIBPCIACCESS
76 #define NOUVEAU_PCI_DEVICE(_vendor_id, _device_id) \
77 { (_vendor_id), (_device_id), PCI_MATCH_ANY, PCI_MATCH_ANY, 0x00030000, 0x00ffffff, 0 }
79 static const struct pci_id_match nouveau_device_match[] = {
80 NOUVEAU_PCI_DEVICE(PCI_VENDOR_NVIDIA, PCI_MATCH_ANY),
81 NOUVEAU_PCI_DEVICE(PCI_VENDOR_NVIDIA_SGS, PCI_MATCH_ANY),
85 static Bool NVPciProbe ( DriverPtr drv,
87 struct pci_device *dev,
88 intptr_t match_data );
90 #endif /* XSERVER_LIBPCIACCESS */
93 * This contains the functions needed by the server after loading the
94 * driver module. It must be supplied, and gets added the driver list by
95 * the Module Setup funtion in the dynamic case. In the static case a
96 * reference to this is compiled in, and this requires that the name of
97 * this DriverRec be an upper-case version of the driver name.
100 _X_EXPORT DriverRec NV = {
104 #ifdef XSERVER_LIBPCIACCESS
108 #endif /* XSERVER_LIBPCIACCESS */
113 #ifdef XSERVER_LIBPCIACCESS
114 nouveau_device_match,
116 #endif /* XSERVER_LIBPCIACCESS */
125 static struct NvFamily NVKnownFamilies[] =
127 { "RIVA TNT", "NV04" },
128 { "RIVA TNT2", "NV05" },
129 { "GeForce 256", "NV10" },
130 { "GeForce 2", "NV11, NV15" },
131 { "GeForce 4MX", "NV17, NV18" },
132 { "GeForce 3", "NV20" },
133 { "GeForce 4Ti", "NV25, NV28" },
134 { "GeForce FX", "NV3x" },
135 { "GeForce 6", "NV4x" },
136 { "GeForce 7", "G7x" },
137 { "GeForce 8", "G8x" },
142 * List of symbols from other modules that this module references. This
143 * list is used to tell the loader that it is OK for symbols here to be
144 * unresolved providing that it hasn't been told that they haven't been
145 * told that they are essential via a call to xf86LoaderReqSymbols() or
146 * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
147 * unresolved symbols that are not required.
150 static const char *vgahwSymbols[] = {
165 static const char *fbSymbols[] = {
171 static const char *exaSymbols[] = {
177 static const char *ramdacSymbols[] = {
178 "xf86CreateCursorInfoRec",
179 "xf86DestroyCursorInfoRec",
184 static const char *ddcSymbols[] = {
187 "xf86SetDDCproperties",
191 static const char *vbeSymbols[] = {
198 static const char *i2cSymbols[] = {
199 "xf86CreateI2CBusRec",
204 static const char *shadowSymbols[] = {
209 static const char *int10Symbols[] = {
215 const char *drmSymbols[] = {
220 "drmAgpVersionMajor",
221 "drmAgpVersionMinor",
231 "drmCommandWriteRead",
234 "drmCtlUninstHandler",
237 "drmGetInterruptFromBusID",
243 const char *driSymbols[] = {
247 "DRIFinishScreenInit",
248 "DRIGetSAREAPrivate",
253 "GlxSetVisualConfigs",
259 static MODULESETUPPROTO(nouveauSetup);
261 static XF86ModuleVersionInfo nouveauVersRec =
267 XORG_VERSION_CURRENT,
268 NV_MAJOR_VERSION, NV_MINOR_VERSION, NV_PATCHLEVEL,
269 ABI_CLASS_VIDEODRV, /* This is a video driver */
270 ABI_VIDEODRV_VERSION,
275 _X_EXPORT XF86ModuleData nouveauModuleData = { &nouveauVersRec, nouveauSetup, NULL };
279 * This is intentionally screen-independent. It indicates the binding
280 * choice made in the first PreInit.
282 static int pix24bpp = 0;
285 NVGetRec(ScrnInfoPtr pScrn)
288 * Allocate an NVRec, and hook it into pScrn->driverPrivate.
289 * pScrn->driverPrivate is initialised to NULL, so we can check if
290 * the allocation has already been done.
292 if (pScrn->driverPrivate != NULL)
295 pScrn->driverPrivate = xnfcalloc(sizeof(NVRec), 1);
302 NVFreeRec(ScrnInfoPtr pScrn)
304 if (pScrn->driverPrivate == NULL)
306 xfree(pScrn->driverPrivate);
307 pScrn->driverPrivate = NULL;
312 nouveauSetup(pointer module, pointer opts, int *errmaj, int *errmin)
314 static Bool setupDone = FALSE;
316 /* This module should be loaded only once, but check to be sure. */
320 /* The 1 here is needed to turn off a backwards compatibility mode */
321 /* Otherwise NVPciProbe() is not called */
322 xf86AddDriver(&NV, module, 1);
325 * Modules that this driver always requires may be loaded here
326 * by calling LoadSubModule().
329 * Tell the loader about symbols from other modules that this module
332 LoaderRefSymLists(vgahwSymbols, exaSymbols, fbSymbols,
336 ramdacSymbols, shadowSymbols,
337 i2cSymbols, ddcSymbols, vbeSymbols,
341 * The return value must be non-NULL on success even though there
342 * is no TearDownProc.
346 if (errmaj) *errmaj = LDR_ONCEONLY;
351 static const OptionInfoRec *
352 NVAvailableOptions(int chipid, int busid)
359 NVIdentify(int flags)
361 struct NvFamily *family;
364 xf86DrvMsg(0, X_INFO, NV_NAME " driver " NV_DRIVER_DATE "\n");
365 xf86DrvMsg(0, X_INFO, NV_NAME " driver for NVIDIA chipset families :\n");
367 /* maximum length for alignment */
368 family = NVKnownFamilies;
369 while(family->name && family->chipset)
371 maxLen = max(maxLen, strlen(family->name));
376 family = NVKnownFamilies;
377 while(family->name && family->chipset)
379 size_t len = strlen(family->name);
380 xf86ErrorF("\t%s", family->name);
386 xf86ErrorF("(%s)\n", family->chipset);
392 #ifndef XSERVER_LIBPCIACCESS
394 NVGetScrnInfoRec(PciChipsets *chips, int chip)
398 pScrn = xf86ConfigPciEntity(NULL, 0, chip,
399 chips, NULL, NULL, NULL,
402 if(!pScrn) return FALSE;
404 pScrn->driverVersion = NV_VERSION;
405 pScrn->driverName = NV_DRIVER_NAME;
406 pScrn->name = NV_NAME;
408 pScrn->Probe = NVProbe;
409 pScrn->PreInit = NVPreInit;
410 pScrn->ScreenInit = NVScreenInit;
411 pScrn->SwitchMode = NVSwitchMode;
412 pScrn->AdjustFrame = NVAdjustFrame;
413 pScrn->EnterVT = NVEnterVT;
414 pScrn->LeaveVT = NVLeaveVT;
415 pScrn->FreeScreen = NVFreeScreen;
416 pScrn->ValidMode = NVValidMode;
422 /* This returns architecture in hexdecimal, so NV40 is 0x40 */
423 static int NVGetArchitecture (volatile CARD32 *regs)
425 int 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 int architecture = NVGetArchitecture(regs);
446 /* Dealing with an unknown or unsupported card */
447 if (architecture == 0) {
451 if (architecture >= 0x40)
452 pci_id = regs[0x88000/4];
454 pci_id = regs[0x1800/4];
456 /* A pci-id can be inverted, we must correct this */
457 if ((pci_id & 0xffff) == PCI_VENDOR_NVIDIA) {
458 pci_id = (PCI_VENDOR_NVIDIA << 16) | (pci_id >> 16);
459 } else if ((pci_id & 0xffff) == PCI_VENDOR_NVIDIA_SGS) {
460 pci_id = (PCI_VENDOR_NVIDIA_SGS << 16) | (pci_id >> 16);
461 /* Checking endian issues */
463 /* PCI_VENDOR_NVIDIA = 0x10DE */
464 if ((pci_id & (0xffff << 16)) == (0xDE10 << 16)) { /* wrong endian */
465 pci_id = (PCI_VENDOR_NVIDIA << 16) | ((pci_id << 8) & 0x0000ff00) |
466 ((pci_id >> 8) & 0x000000ff);
467 /* PCI_VENDOR_NVIDIA_SGS = 0x12D2 */
468 } else if ((pci_id & (0xffff << 16)) == (0xD212 << 16)) { /* wrong endian */
469 pci_id = (PCI_VENDOR_NVIDIA_SGS << 16) | ((pci_id << 8) & 0x0000ff00) |
470 ((pci_id >> 8) & 0x000000ff);
477 #ifdef XSERVER_LIBPCIACCESS
479 static Bool NVPciProbe ( DriverPtr drv,
481 struct pci_device *dev,
482 intptr_t match_data )
484 ScrnInfoPtr pScrn = NULL;
486 volatile uint32_t *regs = NULL;
488 /* Temporary mapping to discover the architecture */
489 pci_device_map_range(dev, PCI_DEV_MEM_BASE(dev, 0), 0x90000, 0,
492 uint8_t architecture = NVGetArchitecture(regs);
494 CARD32 pci_id = NVGetPCIID(regs);
496 pci_device_unmap_range(dev, (void *) regs, 0x90000);
498 /* Currently NV04 up to NV83 is supported */
499 /* For safety the fictional NV8F is used */
500 if (architecture >= 0x04 && architecture <= 0x8F) {
502 /* At this stage the pci_id should be ok, so we generate this
503 * to avoid list duplication */
504 /* AGP bridge chips need their bridge chip id to be detected */
505 PciChipsets NVChipsets[] = {
506 { pci_id, PCI_DEV_PCI_ID(dev), RES_SHARED_VGA },
507 { -1, -1, RES_UNDEFINED }
510 pScrn = xf86ConfigPciEntity(pScrn, 0, entity_num, NVChipsets,
511 NULL, NULL, NULL, NULL, NULL);
514 pScrn->driverVersion = NV_VERSION;
515 pScrn->driverName = NV_DRIVER_NAME;
516 pScrn->name = NV_NAME;
519 pScrn->PreInit = NVPreInit;
520 pScrn->ScreenInit = NVScreenInit;
521 pScrn->SwitchMode = NVSwitchMode;
522 pScrn->AdjustFrame = NVAdjustFrame;
523 pScrn->EnterVT = NVEnterVT;
524 pScrn->LeaveVT = NVLeaveVT;
525 pScrn->FreeScreen = NVFreeScreen;
526 pScrn->ValidMode = NVValidMode;
535 #endif /* XSERVER_LIBPCIACCESS */
537 #define MAX_CHIPS MAXSCREENS
539 #ifndef XSERVER_LIBPCIACCESS
542 NVProbe(DriverPtr drv, int flags)
545 GDevPtr *devSections;
547 SymTabRec NVChipsets[MAX_CHIPS + 1];
548 PciChipsets NVPciChipsets[MAX_CHIPS + 1];
552 Bool foundScreen = FALSE;
554 if ((numDevSections = xf86MatchDevice(NV_DRIVER_NAME, &devSections)) <= 0)
555 return FALSE; /* no matching device section */
557 if (!(ppPci = xf86GetPciVideoInfo()))
558 return FALSE; /* no PCI cards found */
562 /* Create the NVChipsets and NVPciChipsets from found devices */
563 while (*ppPci && (numUsed < MAX_CHIPS)) {
564 if (((*ppPci)->vendor == PCI_VENDOR_NVIDIA_SGS) ||
565 ((*ppPci)->vendor == PCI_VENDOR_NVIDIA))
567 volatile CARD32 *regs;
570 PCI_DEV_READ_LONG(*ppPci, PCI_CMD_STAT_REG, &pcicmd);
571 /* Enable reading memory? */
572 PCI_DEV_WRITE_LONG(*ppPci, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
574 regs = xf86MapPciMem(-1, VIDMEM_MMIO, PCI_DEV_TAG(*ppPci), PCI_DEV_MEM_BASE(*ppPci, 0), 0x90000);
575 int pciid = NVGetPCIID(regs);
577 int architecture = NVGetArchitecture(regs);
579 sprintf(name, "NVIDIA NV%02X", architecture);
580 /* NV04 upto NV83 is supported, NV8F is fictive limit */
581 if (architecture >= 0x04 && architecture <= 0x8F) {
582 NVChipsets[numUsed].token = pciid;
583 NVChipsets[numUsed].name = name;
584 NVPciChipsets[numUsed].numChipset = pciid;
585 /* AGP bridge chips need their bridge chip id to be detected */
586 NVPciChipsets[numUsed].PCIid = PCI_DEV_PCI_ID(*ppPci);
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 NVSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
636 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
637 NVPtr pNv = NVPTR(pScrn);
639 if (pNv->randr12_enable) {
640 /* No rotation support for the moment */
641 return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
644 return NVModeInit(xf86Screens[scrnIndex], mode);
648 * This function is used to initialize the Start Address - the first
649 * displayed location in the video memory.
651 /* Usually mandatory */
653 NVAdjustFrame(int scrnIndex, int x, int y, int flags)
655 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
657 NVPtr pNv = NVPTR(pScrn);
658 NVFBLayout *pLayout = &pNv->CurrentLayout;
660 if (pNv->randr12_enable) {
661 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
662 xf86CrtcPtr crtc = config->output[config->compat_output]->crtc;
664 if (crtc && crtc->enabled) {
665 NVCrtcSetBase(crtc, x, y);
668 startAddr = (((y*pLayout->displayWidth)+x)*(pLayout->bitsPerPixel/8));
669 startAddr += pNv->FB->offset;
670 NVSetStartAddress(pNv, startAddr);
675 NVResetCrtcConfig(ScrnInfoPtr pScrn, int set)
677 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
678 NVPtr pNv = NVPTR(pScrn);
682 for (i = 0; i < config->num_crtc; i++) {
683 xf86CrtcPtr crtc = config->crtc[i];
684 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
689 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
693 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_FSEL, val);
698 NV50AcquireDisplay(ScrnInfoPtr pScrn)
700 if (!NV50DispInit(pScrn))
702 if (!NV50CursorAcquire(pScrn))
704 xf86SetDesiredModes(pScrn);
710 NV50ReleaseDisplay(ScrnInfoPtr pScrn)
712 NV50CursorRelease(pScrn);
713 NV50DispShutdown(pScrn);
718 * This is called when VT switching back to the X server. Its job is
719 * to reinitialise the video mode.
721 * We may wish to unmap video/MMIO memory too.
726 NVEnterVT(int scrnIndex, int flags)
728 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
729 NVPtr pNv = NVPTR(pScrn);
731 if (pNv->randr12_enable) {
732 ErrorF("NVEnterVT is called\n");
733 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
735 pScrn->vtSema = TRUE;
737 if (pNv->Architecture == NV_ARCH_50) {
738 if (!NV50AcquireDisplay(pScrn))
743 /* Save the current state */
744 if (pNv->SaveGeneration != serverGeneration) {
745 pNv->SaveGeneration = serverGeneration;
749 for (i = 0; i < xf86_config->num_crtc; i++) {
750 NVCrtcLockUnlock(xf86_config->crtc[i], 0);
753 /* Reassign outputs so disabled outputs don't get stuck on the wrong crtc */
754 for (i = 0; i < xf86_config->num_output; i++) {
755 xf86OutputPtr output = xf86_config->output[i];
756 NVOutputPrivatePtr nv_output = output->driver_private;
757 if (nv_output->type == OUTPUT_TMDS || nv_output->type == OUTPUT_LVDS) {
760 /* Disable any crosswired tmds, to avoid picking up a signal on a disabled output */
761 /* Example: TMDS1 crosswired to CRTC0 (by bios) reassigned to CRTC1 in xorg, disabled. */
762 /* But the bios reinits it to CRTC0 when going back to VT. */
763 /* Because it's disabled, it doesn't get a mode set, still it picks up the signal from CRTC0 (which is another output) */
764 /* A legitimately crosswired output will get set properly during mode set */
765 if ((tmds_reg4 = NVReadTMDS(pNv, nv_output->preferred_output, 0x4)) & (1 << 3)) {
766 NVWriteTMDS(pNv, nv_output->preferred_output, 0x4, tmds_reg4 & ~(1 << 3));
771 NVResetCrtcConfig(pScrn, 0);
772 if (!xf86SetDesiredModes(pScrn))
774 NVResetCrtcConfig(pScrn, 1);
777 if (!NVModeInit(pScrn, pScrn->currentMode))
781 NVAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
782 if(pNv->overlayAdaptor)
789 * This is called when VT switching away from the X server. Its job is
790 * to restore the previous (text) mode.
792 * We may wish to remap video/MMIO memory too.
797 NVLeaveVT(int scrnIndex, int flags)
799 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
800 NVPtr pNv = NVPTR(pScrn);
801 if (pNv->randr12_enable)
802 ErrorF("NVLeaveVT is called\n");
804 if (pNv->Architecture == NV_ARCH_50) {
805 NV50ReleaseDisplay(pScrn);
810 if (!pNv->randr12_enable)
811 NVLockUnlock(pNv, 1);
824 ScreenPtr pScreen = screenInfo.screens[i];
825 ScrnInfoPtr pScrnInfo = xf86Screens[i];
826 NVPtr pNv = NVPTR(pScrnInfo);
830 pScreen->BlockHandler = pNv->BlockHandler;
831 (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
832 pScreen->BlockHandler = NVBlockHandler;
834 if (pNv->VideoTimerCallback)
835 (*pNv->VideoTimerCallback)(pScrnInfo, currentTime.milliseconds);
841 * This is called at the end of each server generation. It restores the
842 * original (text) mode. It should also unmap the video memory, and free
843 * any per-generation data allocated by the driver. It should finish
844 * by unwrapping and calling the saved CloseScreen function.
849 NVCloseScreen(int scrnIndex, ScreenPtr pScreen)
851 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
852 NVPtr pNv = NVPTR(pScrn);
855 pScrn->vtSema = FALSE;
856 if (pNv->Architecture == NV_ARCH_50) {
857 NV50ReleaseDisplay(pScrn);
861 if (!pNv->randr12_enable)
862 NVLockUnlock(pNv, 1);
867 vgaHWUnmapMem(pScrn);
868 if (pNv->CursorInfoRec)
869 xf86DestroyCursorInfoRec(pNv->CursorInfoRec);
871 xfree(pNv->ShadowPtr);
872 if (pNv->overlayAdaptor)
873 xfree(pNv->overlayAdaptor);
874 if (pNv->blitAdaptor)
875 xfree(pNv->blitAdaptor);
877 pScrn->vtSema = FALSE;
878 pScreen->CloseScreen = pNv->CloseScreen;
879 pScreen->BlockHandler = pNv->BlockHandler;
880 return (*pScreen->CloseScreen)(scrnIndex, pScreen);
883 /* Free up any persistent data structures */
887 NVFreeScreen(int scrnIndex, int flags)
890 * This only gets called when a screen is being deleted. It does not
891 * get called routinely at the end of a server generation.
893 if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
894 vgaHWFreeHWRec(xf86Screens[scrnIndex]);
895 NVFreeRec(xf86Screens[scrnIndex]);
899 /* Checks if a mode is suitable for the selected chipset. */
903 NVValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
905 NVPtr pNv = NVPTR(xf86Screens[scrnIndex]);
907 if(pNv->fpWidth && pNv->fpHeight)
908 if((pNv->fpWidth < mode->HDisplay) || (pNv->fpHeight < mode->VDisplay))
915 nvProbeDDC(ScrnInfoPtr pScrn, int index)
919 if (xf86LoadSubModule(pScrn, "vbe")) {
920 pVbe = VBEInit(NULL,index);
921 ConfiguredMonitor = vbeDoEDID(pVbe, NULL);
927 Bool NVI2CInit(ScrnInfoPtr pScrn)
929 NVPtr pNv = NVPTR(pScrn);
932 if (xf86LoadSubModule(pScrn, mod)) {
933 xf86LoaderReqSymLists(i2cSymbols,NULL);
936 if(xf86LoadSubModule(pScrn, mod)) {
937 xf86LoaderReqSymLists(ddcSymbols, NULL);
938 /* randr-1.2 clients have their DDC's initialized elsewhere */
939 if (pNv->randr12_enable) {
942 return NVDACi2cInit(pScrn);
947 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
948 "Couldn't load %s module. DDC probing can't be done\n", mod);
953 static Bool NVPreInitDRI(ScrnInfoPtr pScrn)
955 NVPtr pNv = NVPTR(pScrn);
957 if (!NVDRIGetVersion(pScrn))
960 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
961 "[dri] Found DRI library version %d.%d.%d and kernel"
962 " module version %d.%d.%d\n",
963 pNv->pLibDRMVersion->version_major,
964 pNv->pLibDRMVersion->version_minor,
965 pNv->pLibDRMVersion->version_patchlevel,
966 pNv->pKernelDRMVersion->version_major,
967 pNv->pKernelDRMVersion->version_minor,
968 pNv->pKernelDRMVersion->version_patchlevel);
974 nv_xf86crtc_resize(ScrnInfoPtr pScrn, int width, int height)
976 ErrorF("nv_xf86crtc_resize is called with %dx%d resolution\n", width, height);
977 pScrn->virtualX = width;
978 pScrn->virtualY = height;
982 static const xf86CrtcConfigFuncsRec nv_xf86crtc_config_funcs = {
986 /* This is taken from the haiku driver */
987 /* We must accept crtc pitch constrains */
988 /* A hardware bug on some hardware requires twice the pitch */
989 static CARD8 NVGetCRTCMask(ScrnInfoPtr pScrn, CARD8 bpp)
994 mask = 0xf; /* 0x7 */
997 mask = 0x7; /* 0x3 */
1000 mask = 0x7; /* 0x3 */
1003 mask = 0xf; /* 0x7 */
1006 mask = 0x3; /* 0x1 */
1009 ErrorF("Unkown color format\n");
1016 /* This is taken from the haiku driver */
1017 static CARD8 NVGetAccelerationMask(ScrnInfoPtr pScrn, CARD8 bpp)
1019 NVPtr pNv = NVPTR(pScrn);
1021 /* Identical for NV04 */
1022 if (pNv->Architecture == NV_ARCH_04) {
1023 return NVGetCRTCMask(pScrn, bpp);
1042 ErrorF("Unkown color format\n");
1050 static CARD32 NVGetVideoPitch(ScrnInfoPtr pScrn, CARD8 bpp)
1052 NVPtr pNv = NVPTR(pScrn);
1053 CARD8 crtc_mask, accel_mask = 0;
1054 crtc_mask = NVGetCRTCMask(pScrn, bpp);
1055 if (!pNv->NoAccel) {
1056 accel_mask = NVGetAccelerationMask(pScrn, bpp);
1059 /* adhere to the largest granularity imposed */
1060 if (accel_mask > crtc_mask) {
1061 return (pScrn->virtualX + accel_mask) & ~accel_mask;
1063 return (pScrn->virtualX + crtc_mask) & ~crtc_mask;
1067 #define NVPreInitFail(fmt, args...) do { \
1068 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%d: "fmt, __LINE__, ##args); \
1070 xf86FreeInt10(pNv->pInt10); \
1077 NVPreInit(ScrnInfoPtr pScrn, int flags)
1079 xf86CrtcConfigPtr xf86_config;
1082 int i, max_width, max_height;
1083 ClockRangePtr clockRanges;
1085 int config_mon_rates = FALSE;
1088 if (flags & PROBE_DETECT) {
1089 EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1097 nvProbeDDC(pScrn, i);
1102 * Note: This function is only called once at server startup, and
1103 * not at the start of each server generation. This means that
1104 * only things that are persistent across server generations can
1105 * be initialised here. xf86Screens[] is (pScrn is a pointer to one
1106 * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex()
1107 * are too, and should be used for data that must persist across
1108 * server generations.
1110 * Per-generation data should be allocated with
1111 * AllocateScreenPrivateIndex() from the ScreenInit() function.
1114 /* Check the number of entities, and fail if it isn't one. */
1115 if (pScrn->numEntities != 1)
1118 /* Allocate the NVRec driverPrivate */
1119 if (!NVGetRec(pScrn)) {
1124 /* Get the entity, and make sure it is PCI. */
1125 pNv->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1126 if (pNv->pEnt->location.type != BUS_PCI)
1129 /* Find the PCI info for this screen */
1130 pNv->PciInfo = xf86GetPciInfoForEntity(pNv->pEnt->index);
1131 #ifndef XSERVER_LIBPCIACCESS
1132 pNv->PciTag = pciTag(pNv->PciInfo->bus, pNv->PciInfo->device,
1133 pNv->PciInfo->func);
1134 #endif /* XSERVER_LIBPCIACCESS */
1136 pNv->Primary = xf86IsPrimaryPci(pNv->PciInfo);
1138 /* Initialize the card through int10 interface if needed */
1139 if (xf86LoadSubModule(pScrn, "int10")) {
1140 xf86LoaderReqSymLists(int10Symbols, NULL);
1141 #if !defined(__alpha__) && !defined(__powerpc__)
1142 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initializing int10\n");
1143 pNv->pInt10 = xf86InitInt10(pNv->pEnt->index);
1147 xf86SetOperatingState(resVgaIo, pNv->pEnt->index, ResUnusedOpr);
1148 xf86SetOperatingState(resVgaMem, pNv->pEnt->index, ResDisableOpr);
1150 /* Set pScrn->monitor */
1151 pScrn->monitor = pScrn->confScreen->monitor;
1153 volatile uint32_t *regs = NULL;
1154 #ifdef XSERVER_LIBPCIACCESS
1155 pci_device_map_range(pNv->PciInfo, PCI_DEV_MEM_BASE(pNv->PciInfo, 0),
1156 0x90000, 0, (void *)®s);
1157 pNv->Chipset = NVGetPCIID(regs) & 0xffff;
1158 pNv->NVArch = NVGetArchitecture(regs);
1159 pci_device_unmap_range(pNv->PciInfo, (void *) regs, 0x90000);
1162 PCI_DEV_READ_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, &pcicmd);
1163 /* Enable reading memory? */
1164 PCI_DEV_WRITE_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, pcicmd | PCI_CMD_MEM_ENABLE);
1165 regs = xf86MapPciMem(-1, VIDMEM_MMIO, pNv->PciTag, PCI_DEV_MEM_BASE(pNv->PciInfo, 0), 0x90000);
1166 pNv->Chipset = NVGetPCIID(regs) & 0xffff;
1167 pNv->NVArch = NVGetArchitecture(regs);
1168 xf86UnMapVidMem(-1, (pointer)regs, 0x90000);
1169 /* Reset previous state */
1170 PCI_DEV_WRITE_LONG(pNv->PciInfo, PCI_CMD_STAT_REG, pcicmd);
1171 #endif /* XSERVER_LIBPCIACCESS */
1173 pScrn->chipset = malloc(sizeof(char) * 25);
1174 sprintf(pScrn->chipset, "NVIDIA NV%02X", pNv->NVArch);
1176 if(!pScrn->chipset) {
1177 pScrn->chipset = "Unknown NVIDIA";
1181 * This shouldn't happen because such problems should be caught in
1182 * NVProbe(), but check it just in case.
1184 if (pScrn->chipset == NULL)
1185 NVPreInitFail("ChipID 0x%04X is not recognised\n", pNv->Chipset);
1187 if (pNv->NVArch < 0x04)
1188 NVPreInitFail("Chipset \"%s\" is not recognised\n", pScrn->chipset);
1190 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Chipset: \"%s\"\n", pScrn->chipset);
1192 /* The highest architecture currently supported is NV5x */
1193 if (pNv->NVArch >= 0x50) {
1194 pNv->Architecture = NV_ARCH_50;
1195 } else if (pNv->NVArch >= 0x40) {
1196 pNv->Architecture = NV_ARCH_40;
1197 } else if (pNv->NVArch >= 0x30) {
1198 pNv->Architecture = NV_ARCH_30;
1199 } else if (pNv->NVArch >= 0x20) {
1200 pNv->Architecture = NV_ARCH_20;
1201 } else if (pNv->NVArch >= 0x10) {
1202 pNv->Architecture = NV_ARCH_10;
1203 } else if (pNv->NVArch >= 0x04) {
1204 pNv->Architecture = NV_ARCH_04;
1205 /* The lowest architecture currently supported is NV04 */
1211 * The first thing we should figure out is the depth, bpp, etc.
1214 if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support32bppFb)) {
1215 NVPreInitFail("\n");
1217 /* Check that the returned depth is one we support */
1218 switch (pScrn->depth) {
1226 NVPreInitFail("Given depth (%d) is not supported by this driver\n",
1230 xf86PrintDepthBpp(pScrn);
1232 /* Get the depth24 pixmap format */
1233 if (pScrn->depth == 24 && pix24bpp == 0)
1234 pix24bpp = xf86GetBppFromDepth(pScrn, 24);
1237 * This must happen after pScrn->display has been set because
1238 * xf86SetWeight references it.
1240 if (pScrn->depth > 8) {
1241 /* The defaults are OK for us */
1242 rgb zeros = {0, 0, 0};
1244 if (!xf86SetWeight(pScrn, zeros, zeros)) {
1245 NVPreInitFail("\n");
1249 if (!xf86SetDefaultVisual(pScrn, -1)) {
1250 NVPreInitFail("\n");
1252 /* We don't currently support DirectColor at > 8bpp */
1253 if (pScrn->depth > 8 && (pScrn->defaultVisual != TrueColor)) {
1254 NVPreInitFail("Given default visual"
1255 " (%s) is not supported at depth %d\n",
1256 xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
1261 /* The vgahw module should be loaded here when needed */
1262 if (!xf86LoadSubModule(pScrn, "vgahw")) {
1263 NVPreInitFail("\n");
1266 xf86LoaderReqSymLists(vgahwSymbols, NULL);
1269 * Allocate a vgaHWRec
1271 if (!vgaHWGetHWRec(pScrn)) {
1272 NVPreInitFail("\n");
1275 /* We use a programmable clock */
1276 pScrn->progClock = TRUE;
1278 /* Collect all of the relevant option flags (fill in pScrn->options) */
1279 xf86CollectOptions(pScrn, NULL);
1281 /* Process the options */
1282 if (!(pNv->Options = xalloc(sizeof(NVOptions))))
1284 memcpy(pNv->Options, NVOptions, sizeof(NVOptions));
1285 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pNv->Options);
1287 /* Set the bits per RGB for 8bpp mode */
1288 if (pScrn->depth == 8)
1293 if (pNv->Architecture == NV_ARCH_50) {
1294 pNv->randr12_enable = TRUE;
1296 pNv->randr12_enable = FALSE;
1297 if (xf86ReturnOptValBool(pNv->Options, OPTION_RANDR12, FALSE)) {
1298 pNv->randr12_enable = TRUE;
1301 xf86DrvMsg(pScrn->scrnIndex, from, "Randr1.2 support %sabled\n", pNv->randr12_enable ? "en" : "dis");
1303 pNv->HWCursor = TRUE;
1305 * The preferred method is to use the "hw cursor" option as a tri-state
1306 * option, with the default set above.
1308 if (xf86GetOptValBool(pNv->Options, OPTION_HW_CURSOR, &pNv->HWCursor)) {
1311 /* For compatibility, accept this too (as an override) */
1312 if (xf86ReturnOptValBool(pNv->Options, OPTION_SW_CURSOR, FALSE)) {
1314 pNv->HWCursor = FALSE;
1316 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
1317 pNv->HWCursor ? "HW" : "SW");
1319 pNv->FpScale = TRUE;
1321 if (xf86GetOptValBool(pNv->Options, OPTION_FP_SCALE, &pNv->FpScale)) {
1322 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Flat panel scaling %s\n",
1323 pNv->FpScale ? "on" : "off");
1325 if (xf86ReturnOptValBool(pNv->Options, OPTION_NOACCEL, FALSE)) {
1326 pNv->NoAccel = TRUE;
1327 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1329 if (xf86ReturnOptValBool(pNv->Options, OPTION_SHADOW_FB, FALSE)) {
1330 pNv->ShadowFB = TRUE;
1331 pNv->NoAccel = TRUE;
1332 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1333 "Using \"Shadow Framebuffer\" - acceleration disabled\n");
1337 pNv->RandRRotation = FALSE;
1338 if ((s = xf86GetOptValString(pNv->Options, OPTION_ROTATE))) {
1339 if(!xf86NameCmp(s, "CW")) {
1340 pNv->ShadowFB = TRUE;
1341 pNv->NoAccel = TRUE;
1342 pNv->HWCursor = FALSE;
1344 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1345 "Rotating screen clockwise - acceleration disabled\n");
1347 if(!xf86NameCmp(s, "CCW")) {
1348 pNv->ShadowFB = TRUE;
1349 pNv->NoAccel = TRUE;
1350 pNv->HWCursor = FALSE;
1352 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1353 "Rotating screen counter clockwise - acceleration disabled\n");
1355 if(!xf86NameCmp(s, "RandR")) {
1357 pNv->ShadowFB = TRUE;
1358 pNv->NoAccel = TRUE;
1359 pNv->HWCursor = FALSE;
1360 pNv->RandRRotation = TRUE;
1361 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1362 "Using RandR rotation - acceleration disabled\n");
1364 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
1365 "This driver was not compiled with support for the Resize and "
1366 "Rotate extension. Cannot honor 'Option \"Rotate\" "
1370 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
1371 "\"%s\" is not a valid value for Option \"Rotate\"\n", s);
1372 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1373 "Valid options are \"CW\", \"CCW\", and \"RandR\"\n");
1377 if(xf86GetOptValInteger(pNv->Options, OPTION_VIDEO_KEY, &(pNv->videoKey))) {
1378 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n",
1381 pNv->videoKey = (1 << pScrn->offset.red) |
1382 (1 << pScrn->offset.green) |
1383 (((pScrn->mask.blue >> pScrn->offset.blue) - 1) << pScrn->offset.blue);
1386 if (xf86GetOptValBool(pNv->Options, OPTION_FLAT_PANEL, &(pNv->FlatPanel))) {
1387 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "forcing %s usage\n",
1388 pNv->FlatPanel ? "DFP" : "CRTC");
1390 pNv->FlatPanel = -1; /* autodetect later */
1393 pNv->FPDither = FALSE;
1394 if (xf86GetOptValBool(pNv->Options, OPTION_FP_DITHER, &(pNv->FPDither)))
1395 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "enabling flat panel dither\n");
1397 //if (xf86GetOptValInteger(pNv->Options, OPTION_CRTC_NUMBER,
1398 // &pNv->CRTCnumber))
1400 //pNv->crtc_active[0] = FALSE;
1401 //pNv->crtc_active[1] = FALSE;
1405 if (xf86GetOptValInteger(pNv->Options, OPTION_FP_TWEAK,
1408 pNv->usePanelTweak = TRUE;
1410 pNv->usePanelTweak = FALSE;
1413 if (pNv->pEnt->device->MemBase != 0) {
1414 /* Require that the config file value matches one of the PCI values. */
1415 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->MemBase)) {
1417 "MemBase 0x%08lX doesn't match any PCI base register.\n",
1418 pNv->pEnt->device->MemBase);
1420 pNv->VRAMPhysical = pNv->pEnt->device->MemBase;
1423 if (PCI_DEV_MEM_BASE(pNv->PciInfo, 1) != 0) {
1424 pNv->VRAMPhysical = PCI_DEV_MEM_BASE(pNv->PciInfo, 1) & 0xff800000;
1427 NVPreInitFail("No valid FB address in PCI config space\n");
1431 xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
1432 (unsigned long)pNv->VRAMPhysical);
1434 if (pNv->pEnt->device->IOBase != 0) {
1435 /* Require that the config file value matches one of the PCI values. */
1436 if (!xf86CheckPciMemBase(pNv->PciInfo, pNv->pEnt->device->IOBase)) {
1437 NVPreInitFail("IOBase 0x%08lX doesn't match any PCI base register.\n",
1438 pNv->pEnt->device->IOBase);
1440 pNv->IOAddress = pNv->pEnt->device->IOBase;
1443 if (PCI_DEV_MEM_BASE(pNv->PciInfo, 0) != 0) {
1444 pNv->IOAddress = PCI_DEV_MEM_BASE(pNv->PciInfo, 0) & 0xffffc000;
1447 NVPreInitFail("No valid MMIO address in PCI config space\n");
1450 xf86DrvMsg(pScrn->scrnIndex, from, "MMIO registers at 0x%lX\n",
1451 (unsigned long)pNv->IOAddress);
1453 if (xf86RegisterResources(pNv->pEnt->index, NULL, ResExclusive)) {
1454 NVPreInitFail("xf86RegisterResources() found resource conflicts\n");
1457 pNv->alphaCursor = (pNv->NVArch >= 0x11);
1459 //pNv->alphaCursor = FALSE;
1461 if (pNv->randr12_enable) {
1462 /* Allocate an xf86CrtcConfig */
1463 xf86CrtcConfigInit(pScrn, &nv_xf86crtc_config_funcs);
1464 xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1467 xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, 2048);
1470 if (NVPreInitDRI(pScrn) == FALSE) {
1471 NVPreInitFail("\n");
1474 if (!pNv->randr12_enable) {
1475 if ((pScrn->monitor->nHsync == 0) &&
1476 (pScrn->monitor->nVrefresh == 0))
1477 config_mon_rates = FALSE;
1479 config_mon_rates = TRUE;
1482 NVCommonSetup(pScrn);
1484 if (pNv->randr12_enable) {
1485 if (pNv->Architecture < NV_ARCH_50) {
1488 num_crtc = pNv->twoHeads ? 2 : 1;
1489 for (i = 0; i < num_crtc; i++) {
1490 nv_crtc_init(pScrn, i);
1493 NvSetupOutputs(pScrn);
1495 if (!NV50DispPreInit(pScrn))
1496 NVPreInitFail("\n");
1497 if (!NV50CreateOutputs(pScrn))
1498 NVPreInitFail("\n");
1499 NV50DispCreateCrtcs(pScrn);
1502 if (!xf86InitialConfiguration(pScrn, FALSE))
1503 NVPreInitFail("No valid modes.\n");
1506 pScrn->videoRam = pNv->RamAmountKBytes;
1507 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kBytes\n",
1510 pNv->VRAMPhysicalSize = pScrn->videoRam * 1024;
1513 * If the driver can do gamma correction, it should call xf86SetGamma()
1518 Gamma zeros = {0.0, 0.0, 0.0};
1520 if (!xf86SetGamma(pScrn, zeros)) {
1521 NVPreInitFail("\n");
1526 * Setup the ClockRanges, which describe what clock ranges are available,
1527 * and what sort of modes they can be used for.
1530 clockRanges = xnfcalloc(sizeof(ClockRange), 1);
1531 clockRanges->next = NULL;
1532 clockRanges->minClock = pNv->MinVClockFreqKHz;
1533 clockRanges->maxClock = pNv->MaxVClockFreqKHz;
1534 clockRanges->clockIndex = -1; /* programmable */
1535 clockRanges->doubleScanAllowed = TRUE;
1536 if((pNv->Architecture == NV_ARCH_20) ||
1537 ((pNv->Architecture == NV_ARCH_10) &&
1538 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV10) &&
1539 ((pNv->Chipset & 0x0ff0) != CHIPSET_NV15)))
1542 clockRanges->interlaceAllowed = FALSE;
1544 clockRanges->interlaceAllowed = TRUE;
1547 if(pNv->FlatPanel == 1) {
1548 clockRanges->interlaceAllowed = FALSE;
1549 clockRanges->doubleScanAllowed = FALSE;
1552 if(pNv->Architecture < NV_ARCH_10) {
1553 max_width = (pScrn->bitsPerPixel > 16) ? 2032 : 2048;
1556 max_width = (pScrn->bitsPerPixel > 16) ? 4080 : 4096;
1561 /* If DFP, add a modeline corresponding to its panel size */
1562 if (pNv->FlatPanel && !pNv->Television && pNv->fpWidth && pNv->fpHeight) {
1563 DisplayModePtr Mode;
1565 Mode = xnfcalloc(1, sizeof(DisplayModeRec));
1566 Mode = xf86CVTMode(pNv->fpWidth, pNv->fpHeight, 60.00, TRUE, FALSE);
1567 Mode->type = M_T_DRIVER;
1568 pScrn->monitor->Modes = xf86ModesAdd(pScrn->monitor->Modes, Mode);
1570 if (!config_mon_rates) {
1572 Mode->HSync = ((float) Mode->Clock ) / ((float) Mode->HTotal);
1573 if (!Mode->VRefresh)
1574 Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) /
1575 ((float) (Mode->HTotal * Mode->VTotal));
1577 if (Mode->HSync < pScrn->monitor->hsync[0].lo)
1578 pScrn->monitor->hsync[0].lo = Mode->HSync;
1579 if (Mode->HSync > pScrn->monitor->hsync[0].hi)
1580 pScrn->monitor->hsync[0].hi = Mode->HSync;
1581 if (Mode->VRefresh < pScrn->monitor->vrefresh[0].lo)
1582 pScrn->monitor->vrefresh[0].lo = Mode->VRefresh;
1583 if (Mode->VRefresh > pScrn->monitor->vrefresh[0].hi)
1584 pScrn->monitor->vrefresh[0].hi = Mode->VRefresh;
1586 pScrn->monitor->nHsync = 1;
1587 pScrn->monitor->nVrefresh = 1;
1592 if (pNv->randr12_enable) {
1593 pScrn->displayWidth = NVGetVideoPitch(pScrn, pScrn->depth);
1596 * xf86ValidateModes will check that the mode HTotal and VTotal values
1597 * don't exceed the chipset's limit if pScrn->maxHValue and
1598 * pScrn->maxVValue are set. Since our NVValidMode() already takes
1599 * care of this, we don't worry about setting them here.
1601 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
1602 pScrn->display->modes, clockRanges,
1603 NULL, 256, max_width,
1604 512, 128, max_height,
1605 pScrn->display->virtualX,
1606 pScrn->display->virtualY,
1607 pNv->VRAMPhysicalSize / 2,
1608 LOOKUP_BEST_REFRESH);
1611 NVPreInitFail("\n");
1614 /* Prune the modes marked as invalid */
1615 xf86PruneDriverModes(pScrn);
1618 * Set the CRTC parameters for all of the modes based on the type
1619 * of mode, and the chipset's interlace requirements.
1621 * Calling this is required if the mode->Crtc* values are used by the
1622 * driver and if the driver doesn't provide code to set them. They
1623 * are not pre-initialised at all.
1625 xf86SetCrtcForModes(pScrn, 0);
1628 if (pScrn->modes == NULL) {
1629 NVPreInitFail("No valid modes found\n");
1632 /* Set the current mode to the first in the list */
1633 pScrn->currentMode = pScrn->modes;
1635 /* Print the list of modes being used */
1636 xf86PrintModes(pScrn);
1638 /* Set display resolution */
1639 xf86SetDpi(pScrn, 0, 0);
1643 * XXX This should be taken into account in some way in the mode valdation
1647 if (xf86LoadSubModule(pScrn, "fb") == NULL) {
1648 NVPreInitFail("\n");
1651 xf86LoaderReqSymLists(fbSymbols, NULL);
1653 /* Load EXA if needed */
1654 if (!pNv->NoAccel) {
1655 if (!xf86LoadSubModule(pScrn, "exa")) {
1656 NVPreInitFail("\n");
1658 xf86LoaderReqSymLists(exaSymbols, NULL);
1661 /* Load ramdac if needed */
1662 if (pNv->HWCursor) {
1663 if (!xf86LoadSubModule(pScrn, "ramdac")) {
1664 NVPreInitFail("\n");
1666 xf86LoaderReqSymLists(ramdacSymbols, NULL);
1669 /* Load shadowfb if needed */
1670 if (pNv->ShadowFB) {
1671 if (!xf86LoadSubModule(pScrn, "shadowfb")) {
1672 NVPreInitFail("\n");
1674 xf86LoaderReqSymLists(shadowSymbols, NULL);
1677 pNv->CurrentLayout.bitsPerPixel = pScrn->bitsPerPixel;
1678 pNv->CurrentLayout.depth = pScrn->depth;
1679 pNv->CurrentLayout.displayWidth = pScrn->displayWidth;
1680 pNv->CurrentLayout.weight.red = pScrn->weight.red;
1681 pNv->CurrentLayout.weight.green = pScrn->weight.green;
1682 pNv->CurrentLayout.weight.blue = pScrn->weight.blue;
1683 pNv->CurrentLayout.mode = pScrn->currentMode;
1685 xf86FreeInt10(pNv->pInt10);
1693 * Map the framebuffer and MMIO memory.
1697 NVMapMem(ScrnInfoPtr pScrn)
1699 NVPtr pNv = NVPTR(pScrn);
1700 int gart_scratch_size;
1703 nouveau_device_get_param(pNv->dev, NOUVEAU_GETPARAM_FB_SIZE, &res);
1705 nouveau_device_get_param(pNv->dev, NOUVEAU_GETPARAM_FB_PHYSICAL, &res);
1706 pNv->VRAMPhysical=res;
1707 nouveau_device_get_param(pNv->dev, NOUVEAU_GETPARAM_AGP_SIZE, &res);
1710 #if !NOUVEAU_EXA_PIXMAPS
1711 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1712 0, pNv->VRAMPhysicalSize / 2, &pNv->FB)) {
1713 ErrorF("Failed to allocate memory for framebuffer!\n");
1716 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1717 "Allocated %dMiB VRAM for framebuffer + offscreen pixmaps\n",
1718 (unsigned int)(pNv->FB->size >> 20));
1723 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1724 "AGPGART: %dMiB available\n",
1725 (unsigned int)(pNv->AGPSize >> 20));
1726 if (pNv->AGPSize > (16*1024*1024))
1727 gart_scratch_size = 16*1024*1024;
1729 gart_scratch_size = pNv->AGPSize;
1731 gart_scratch_size = (4 << 20) - (1 << 18) ;
1732 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1733 "GART: PCI DMA - using %dKiB\n",
1734 gart_scratch_size >> 10);
1738 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_GART | NOUVEAU_BO_PIN, 0,
1739 gart_scratch_size, &pNv->GART)) {
1740 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1741 "Unable to allocate GART memory\n");
1745 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1746 "GART: Allocated %dMiB as a scratch buffer\n",
1747 (unsigned int)(pNv->GART->size >> 20));
1750 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN, 0,
1751 64 * 1024, &pNv->Cursor)) {
1752 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1753 "Failed to allocate memory for hardware cursor\n");
1757 if (pNv->Architecture >= NV_ARCH_50) {
1758 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1759 0, 0x1000, &pNv->CLUT)) {
1760 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1761 "Failed to allocate memory for CLUT\n");
1766 if ((pNv->FB && nouveau_bo_map(pNv->FB, NOUVEAU_BO_RDWR)) ||
1767 (pNv->GART && nouveau_bo_map(pNv->GART, NOUVEAU_BO_RDWR)) ||
1768 (pNv->CLUT && nouveau_bo_map(pNv->CLUT, NOUVEAU_BO_RDWR)) ||
1769 nouveau_bo_map(pNv->Cursor, NOUVEAU_BO_RDWR)) {
1770 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1771 "Failed to map pinned buffers\n");
1779 * Unmap the framebuffer and MMIO memory.
1783 NVUnmapMem(ScrnInfoPtr pScrn)
1785 NVPtr pNv = NVPTR(pScrn);
1787 nouveau_bo_del(&pNv->FB);
1788 nouveau_bo_del(&pNv->GART);
1789 nouveau_bo_del(&pNv->Cursor);
1790 nouveau_bo_del(&pNv->CLUT);
1797 * Initialise a new mode.
1801 NVModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
1803 vgaHWPtr hwp = VGAHWPTR(pScrn);
1805 NVPtr pNv = NVPTR(pScrn);
1808 /* Initialise the ModeReg values */
1809 if (!vgaHWInit(pScrn, mode))
1811 pScrn->vtSema = TRUE;
1813 vgaReg = &hwp->ModeReg;
1814 nvReg = &pNv->ModeReg;
1816 if(!NVDACInit(pScrn, mode))
1819 NVLockUnlock(pNv, 0);
1821 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, nvReg->crtcOwner);
1822 NVLockUnlock(pNv, 0);
1825 /* Program the registers */
1826 vgaHWProtect(pScrn, TRUE);
1828 NVDACRestore(pScrn, vgaReg, nvReg, FALSE);
1830 #if X_BYTE_ORDER == X_BIG_ENDIAN
1831 /* turn on LFB swapping */
1835 tmp = nvReadVGA(pNv, NV_VGA_CRTCX_SWAPPING);
1837 nvWriteVGA(pNv, NV_VGA_CRTCX_SWAPPING, tmp);
1842 NVResetGraphics(pScrn);
1844 vgaHWProtect(pScrn, FALSE);
1846 pNv->CurrentLayout.mode = mode;
1852 * Restore the initial (text) mode.
1855 NVRestore(ScrnInfoPtr pScrn)
1857 vgaHWPtr hwp = VGAHWPTR(pScrn);
1858 vgaRegPtr vgaReg = &hwp->SavedReg;
1859 NVPtr pNv = NVPTR(pScrn);
1860 NVRegPtr nvReg = &pNv->SavedReg;
1862 if (pNv->randr12_enable) {
1863 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1866 for (i = 0; i < xf86_config->num_crtc; i++) {
1867 NVCrtcLockUnlock(xf86_config->crtc[i], 0);
1870 for (i = 0; i < xf86_config->num_crtc; i++) {
1871 xf86_config->crtc[i]->funcs->restore(xf86_config->crtc[i]);
1874 for (i = 0; i < xf86_config->num_output; i++) {
1875 xf86_config->output[i]->funcs->restore(xf86_config->
1879 for (i = 0; i < xf86_config->num_crtc; i++) {
1880 NVCrtcLockUnlock(xf86_config->crtc[i], 1);
1883 NVLockUnlock(pNv, 0);
1886 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->crtc_active[1] * 0x3);
1887 NVLockUnlock(pNv, 0);
1890 /* Only restore text mode fonts/text for the primary card */
1891 vgaHWProtect(pScrn, TRUE);
1892 NVDACRestore(pScrn, vgaReg, nvReg, pNv->Primary);
1894 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->vtOWNER);
1896 vgaHWProtect(pScrn, FALSE);
1901 NVLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
1902 LOCO * colors, VisualPtr pVisual)
1904 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
1907 CARD16 lut_r[256], lut_g[256], lut_b[256];
1909 for (c = 0; c < xf86_config->num_crtc; c++) {
1910 xf86CrtcPtr crtc = xf86_config->crtc[c];
1912 if (crtc->enabled == 0)
1915 /* code borrowed from intel driver */
1916 switch (pScrn->depth) {
1918 for (i = 0; i < numColors; i++) {
1920 for (j = 0; j < 8; j++) {
1921 lut_r[index * 8 + j] = colors[index].red << 8;
1922 lut_g[index * 8 + j] = colors[index].green << 8;
1923 lut_b[index * 8 + j] = colors[index].blue << 8;
1927 for (i = 0; i < numColors; i++) {
1931 for (j = 0; j < 8; j++) {
1932 lut_r[index * 8 + j] = colors[index].red << 8;
1933 lut_b[index * 8 + j] = colors[index].blue << 8;
1937 for (j = 0; j < 4; j++) {
1938 lut_g[index * 4 + j] = colors[index].green << 8;
1942 for (i = 0; i < numColors; i++) {
1944 lut_r[index] = colors[index].red << 8;
1945 lut_g[index] = colors[index].green << 8;
1946 lut_b[index] = colors[index].blue << 8;
1951 /* Make the change through RandR */
1952 #ifdef RANDR_12_INTERFACE
1953 RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
1955 crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
1960 #define DEPTH_SHIFT(val, w) ((val << (8 - w)) | (val >> ((w << 1) - 8)))
1961 #define COLOR(c) (unsigned int)(0x3fff * ((c)/255.0))
1963 NV50LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
1964 LOCO * colors, VisualPtr pVisual)
1966 NVPtr pNv = NVPTR(pScrn);
1969 unsigned short red, green, blue, unused;
1970 } *lut = (void *) pNv->CLUT->map;
1972 switch (pScrn->depth) {
1974 for (i = 0; i < numColors; i++) {
1976 lut[DEPTH_SHIFT(index, 5)].red =
1977 COLOR(colors[index].red);
1978 lut[DEPTH_SHIFT(index, 5)].green =
1979 COLOR(colors[index].green);
1980 lut[DEPTH_SHIFT(index, 5)].blue =
1981 COLOR(colors[index].blue);
1985 for (i = 0; i < numColors; i++) {
1987 lut[DEPTH_SHIFT(index, 6)].green =
1988 COLOR(colors[index].green);
1990 lut[DEPTH_SHIFT(index, 5)].red =
1991 COLOR(colors[index].red);
1992 lut[DEPTH_SHIFT(index, 5)].blue =
1993 COLOR(colors[index].blue);
1998 for (i = 0; i < numColors; i++) {
2000 lut[index].red = COLOR(colors[index].red);
2001 lut[index].green = COLOR(colors[index].green);
2002 lut[index].blue = COLOR(colors[index].blue);
2009 static void NVBacklightEnable(NVPtr pNv, Bool on)
2011 /* This is done differently on each laptop. Here we
2012 define the ones we know for sure. */
2014 #if defined(__powerpc__)
2015 if((pNv->Chipset == 0x10DE0179) ||
2016 (pNv->Chipset == 0x10DE0189) ||
2017 (pNv->Chipset == 0x10DE0329))
2019 /* NV17,18,34 Apple iMac, iBook, PowerBook */
2020 CARD32 tmp_pmc, tmp_pcrt;
2021 tmp_pmc = nvReadMC(pNv, 0x10F0) & 0x7FFFFFFF;
2022 tmp_pcrt = nvReadCRTC0(pNv, NV_CRTC_081C) & 0xFFFFFFFC;
2024 tmp_pmc |= (1 << 31);
2027 nvWriteMC(pNv, 0x10F0, tmp_pmc);
2028 nvWriteCRTC0(pNv, NV_CRTC_081C, tmp_pcrt);
2033 if(pNv->twoHeads && ((pNv->Chipset & 0x0ff0) != CHIPSET_NV11)) {
2034 nvWriteMC(pNv, 0x130C, on ? 3 : 7);
2039 fpcontrol = nvReadCurRAMDAC(pNv, 0x848) & 0xCfffffCC;
2041 /* cut the TMDS output */
2042 if(on) fpcontrol |= pNv->fpSyncs;
2043 else fpcontrol |= 0x20000022;
2045 nvWriteCurRAMDAC(pNv, 0x0848, fpcontrol);
2050 NVDPMSSetLCD(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
2052 NVPtr pNv = NVPTR(pScrn);
2054 if (!pScrn->vtSema) return;
2056 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
2058 switch (PowerManagementMode) {
2059 case DPMSModeStandby: /* HSync: Off, VSync: On */
2060 case DPMSModeSuspend: /* HSync: On, VSync: Off */
2061 case DPMSModeOff: /* HSync: Off, VSync: Off */
2062 NVBacklightEnable(pNv, 0);
2064 case DPMSModeOn: /* HSync: On, VSync: On */
2065 NVBacklightEnable(pNv, 1);
2073 NVDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
2075 unsigned char crtc1A;
2076 vgaHWPtr hwp = VGAHWPTR(pScrn);
2078 if (!pScrn->vtSema) return;
2080 crtc1A = hwp->readCrtc(hwp, 0x1A) & ~0xC0;
2082 switch (PowerManagementMode) {
2083 case DPMSModeStandby: /* HSync: Off, VSync: On */
2086 case DPMSModeSuspend: /* HSync: On, VSync: Off */
2089 case DPMSModeOff: /* HSync: Off, VSync: Off */
2092 case DPMSModeOn: /* HSync: On, VSync: On */
2097 /* vgaHWDPMSSet will merely cut the dac output */
2098 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
2100 hwp->writeCrtc(hwp, 0x1A, crtc1A);
2106 /* This gets called at the start of each server generation */
2109 NVScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
2116 unsigned char *FBStart;
2117 int width, height, displayWidth, shadowHeight;
2120 * First get the ScrnInfoRec
2122 pScrn = xf86Screens[pScreen->myNum];
2124 hwp = VGAHWPTR(pScrn);
2127 /* Map the VGA memory when the primary video */
2129 hwp->MapSize = 0x10000;
2130 if (!vgaHWMapMem(pScrn))
2134 /* First init DRI/DRM */
2135 if (!NVDRIScreenInit(pScrn))
2138 /* Allocate and map memory areas we need */
2139 if (!NVMapMem(pScrn))
2142 if (!pNv->NoAccel) {
2143 /* Init DRM - Alloc FIFO */
2144 if (!NVInitDma(pScrn))
2147 /* setup graphics objects */
2148 if (!NVAccelCommonInit(pScrn))
2152 #if NOUVEAU_EXA_PIXMAPS
2153 if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
2154 0, pScrn->virtualX * pScrn->virtualY *
2155 (pScrn->bitsPerPixel >> 3), &pNv->FB)) {
2156 ErrorF("Failed to allocate memory for screen pixmap.\n");
2161 if (!pNv->randr12_enable) {
2162 /* Save the current state */
2164 /* Initialise the first mode */
2165 if (!NVModeInit(pScrn, pScrn->currentMode))
2168 /* Darken the screen for aesthetic reasons and set the viewport */
2170 NVSaveScreen(pScreen, SCREEN_SAVER_ON);
2171 pScrn->AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
2174 pScrn->memPhysBase = pNv->VRAMPhysical;
2175 pScrn->fbOffset = 0;
2177 /* Gather some misc info before the randr stuff kicks in */
2178 pNv->misc_info.crtc_0_reg_52 = NVReadVGA0(pNv, NV_VGA_CRTCX_52);
2179 if (pNv->Architecture == NV_ARCH_40) {
2180 pNv->misc_info.ramdac_0_reg_580 = nvReadRAMDAC(pNv, 0, NV_RAMDAC_580);
2181 pNv->misc_info.reg_c040 = nvReadMC(pNv, 0xc040);
2183 pNv->misc_info.ramdac_0_pllsel = nvReadRAMDAC(pNv, 0, NV_RAMDAC_PLL_SELECT);
2184 pNv->misc_info.sel_clk = nvReadRAMDAC(pNv, 0, NV_RAMDAC_SEL_CLK);
2186 if (!NVEnterVT(scrnIndex, 0))
2188 NVSaveScreen(pScreen, SCREEN_SAVER_ON);
2193 * The next step is to setup the screen's visuals, and initialise the
2194 * framebuffer code. In cases where the framebuffer's default
2195 * choices for things like visual layouts and bits per RGB are OK,
2196 * this may be as simple as calling the framebuffer's ScreenInit()
2197 * function. If not, the visuals will need to be setup before calling
2198 * a fb ScreenInit() function and fixed up after.
2200 * For most PC hardware at depths >= 8, the defaults that fb uses
2201 * are not appropriate. In this driver, we fixup the visuals after.
2205 * Reset the visual list.
2207 miClearVisualTypes();
2209 /* Setup the visuals we support. */
2211 if (!miSetVisualTypes(pScrn->depth,
2212 miGetDefaultVisualMask(pScrn->depth), 8,
2213 pScrn->defaultVisual))
2215 if (!miSetPixmapDepths ()) return FALSE;
2218 * Call the framebuffer layer's ScreenInit function, and fill in other
2222 width = pScrn->virtualX;
2223 height = pScrn->virtualY;
2224 displayWidth = pScrn->displayWidth;
2227 height = pScrn->virtualX;
2228 width = pScrn->virtualY;
2231 /* If RandR rotation is enabled, leave enough space in the
2232 * framebuffer for us to rotate the screen dimensions without
2233 * changing the pitch.
2235 if(pNv->RandRRotation)
2236 shadowHeight = max(width, height);
2238 shadowHeight = height;
2241 pNv->ShadowPitch = BitmapBytePad(pScrn->bitsPerPixel * width);
2242 pNv->ShadowPtr = xalloc(pNv->ShadowPitch * shadowHeight);
2243 displayWidth = pNv->ShadowPitch / (pScrn->bitsPerPixel >> 3);
2244 FBStart = pNv->ShadowPtr;
2246 pNv->ShadowPtr = NULL;
2247 FBStart = pNv->FB->map;
2250 switch (pScrn->bitsPerPixel) {
2254 ret = fbScreenInit(pScreen, FBStart, width, height,
2255 pScrn->xDpi, pScrn->yDpi,
2256 displayWidth, pScrn->bitsPerPixel);
2259 xf86DrvMsg(scrnIndex, X_ERROR,
2260 "Internal error: invalid bpp (%d) in NVScreenInit\n",
2261 pScrn->bitsPerPixel);
2268 if (pScrn->bitsPerPixel > 8) {
2269 /* Fixup RGB ordering */
2270 visual = pScreen->visuals + pScreen->numVisuals;
2271 while (--visual >= pScreen->visuals) {
2272 if ((visual->class | DynamicClass) == DirectColor) {
2273 visual->offsetRed = pScrn->offset.red;
2274 visual->offsetGreen = pScrn->offset.green;
2275 visual->offsetBlue = pScrn->offset.blue;
2276 visual->redMask = pScrn->mask.red;
2277 visual->greenMask = pScrn->mask.green;
2278 visual->blueMask = pScrn->mask.blue;
2283 fbPictureInit (pScreen, 0, 0);
2285 xf86SetBlackWhitePixels(pScreen);
2287 if (!pNv->NoAccel) {
2289 NVResetGraphics(pScrn);
2292 miInitializeBackingStore(pScreen);
2293 xf86SetBackingStore(pScreen);
2294 xf86SetSilkenMouse(pScreen);
2296 /* Finish DRI init */
2297 NVDRIFinishScreenInit(pScrn);
2299 /* Initialize software cursor.
2300 Must precede creation of the default colormap */
2301 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
2303 /* Initialize HW cursor layer.
2304 Must follow software cursor initialization*/
2305 if (pNv->HWCursor) {
2306 if (pNv->Architecture < NV_ARCH_50 && !pNv->randr12_enable)
2307 ret = NVCursorInit(pScreen);
2308 else if (pNv->Architecture < NV_ARCH_50 && pNv->randr12_enable)
2309 ret = NVCursorInitRandr12(pScreen);
2311 ret = NV50CursorInit(pScreen);
2314 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2315 "Hardware cursor initialization failed\n");
2316 pNv->HWCursor = FALSE;
2320 if (pNv->randr12_enable) {
2321 xf86DPMSInit(pScreen, xf86DPMSSet, 0);
2323 if (!xf86CrtcScreenInit(pScreen))
2326 pNv->PointerMoved = pScrn->PointerMoved;
2327 pScrn->PointerMoved = NVPointerMoved;
2330 /* Initialise default colourmap */
2331 if (!miCreateDefColormap(pScreen))
2334 /* Initialize colormap layer.
2335 Must follow initialization of the default colormap */
2336 if (!pNv->randr12_enable) {
2337 if(!xf86HandleColormaps(pScreen, 256, 8, NVDACLoadPalette,
2338 NULL, CMAP_RELOAD_ON_MODE_SWITCH | CMAP_PALETTED_TRUECOLOR))
2341 if (pNv->Architecture < NV_ARCH_50) {
2342 if (!xf86HandleColormaps(pScreen, 256, 8, NVLoadPalette,
2344 CMAP_RELOAD_ON_MODE_SWITCH |
2345 CMAP_PALETTED_TRUECOLOR))
2348 if (!xf86HandleColormaps(pScreen, 256, 8, NV50LoadPalette,
2349 NULL, CMAP_PALETTED_TRUECOLOR))
2355 RefreshAreaFuncPtr refreshArea = NVRefreshArea;
2357 if(pNv->Rotate || pNv->RandRRotation) {
2358 pNv->PointerMoved = pScrn->PointerMoved;
2360 pScrn->PointerMoved = NVPointerMoved;
2362 switch(pScrn->bitsPerPixel) {
2363 case 8: refreshArea = NVRefreshArea8; break;
2364 case 16: refreshArea = NVRefreshArea16; break;
2365 case 32: refreshArea = NVRefreshArea32; break;
2367 if(!pNv->RandRRotation) {
2369 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
2370 "Driver rotation enabled, RandR disabled\n");
2374 ShadowFBInit(pScreen, refreshArea);
2377 if (!pNv->randr12_enable) {
2379 xf86DPMSInit(pScreen, NVDPMSSetLCD, 0);
2381 xf86DPMSInit(pScreen, NVDPMSSet, 0);
2384 pScrn->memPhysBase = pNv->VRAMPhysical;
2385 pScrn->fbOffset = 0;
2387 if(pNv->Rotate == 0 && !pNv->RandRRotation)
2388 NVInitVideo(pScreen);
2390 pScreen->SaveScreen = NVSaveScreen;
2392 /* Wrap the current CloseScreen function */
2393 pNv->CloseScreen = pScreen->CloseScreen;
2394 pScreen->CloseScreen = NVCloseScreen;
2396 pNv->BlockHandler = pScreen->BlockHandler;
2397 pScreen->BlockHandler = NVBlockHandler;
2400 /* Install our DriverFunc. We have to do it this way instead of using the
2401 * HaveDriverFuncs argument to xf86AddDriver, because InitOutput clobbers
2402 * pScrn->DriverFunc */
2403 if (!pNv->randr12_enable)
2404 pScrn->DriverFunc = NVDriverFunc;
2407 /* Report any unused options (only for the first generation) */
2408 if (serverGeneration == 1) {
2409 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
2415 NVSaveScreen(ScreenPtr pScreen, int mode)
2417 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
2418 NVPtr pNv = NVPTR(pScrn);
2420 Bool on = xf86IsUnblank(mode);
2422 if (pNv->randr12_enable) {
2423 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
2424 if (pScrn->vtSema && pNv->Architecture < NV_ARCH_50) {
2425 for (i = 0; i < xf86_config->num_crtc; i++) {
2427 if (xf86_config->crtc[i]->enabled) {
2428 NVCrtcBlankScreen(xf86_config->crtc[i],
2437 return vgaHWSaveScreen(pScreen, mode);
2441 NVSave(ScrnInfoPtr pScrn)
2443 NVPtr pNv = NVPTR(pScrn);
2444 NVRegPtr nvReg = &pNv->SavedReg;
2445 vgaHWPtr pVga = VGAHWPTR(pScrn);
2446 vgaRegPtr vgaReg = &pVga->SavedReg;
2448 if (pNv->randr12_enable) {
2449 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
2450 int vgaflags = VGA_SR_CMAP | VGA_SR_MODE;
2453 for (i = 0; i < xf86_config->num_crtc; i++) {
2454 xf86_config->crtc[i]->funcs->save(xf86_config->crtc[i]);
2457 for (i = 0; i < xf86_config->num_output; i++) {
2458 xf86_config->output[i]->funcs->save(xf86_config->
2464 vgaflags |= VGA_SR_FONTS;
2466 vgaHWSave(pScrn, vgaReg, vgaflags);
2468 NVLockUnlock(pNv, 0);
2470 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->crtc_active[1] * 0x3);
2471 NVLockUnlock(pNv, 0);
2474 NVDACSave(pScrn, vgaReg, nvReg, pNv->Primary);
2480 NVRandRGetInfo(ScrnInfoPtr pScrn, Rotation *rotations)
2482 NVPtr pNv = NVPTR(pScrn);
2484 if(pNv->RandRRotation)
2485 *rotations = RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_270;
2487 *rotations = RR_Rotate_0;
2493 NVRandRSetConfig(ScrnInfoPtr pScrn, xorgRRConfig *config)
2495 NVPtr pNv = NVPTR(pScrn);
2497 switch(config->rotation) {
2500 pScrn->PointerMoved = pNv->PointerMoved;
2505 pScrn->PointerMoved = NVPointerMoved;
2510 pScrn->PointerMoved = NVPointerMoved;
2514 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2515 "Unexpected rotation in NVRandRSetConfig!\n");
2517 pScrn->PointerMoved = pNv->PointerMoved;
2525 NVDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer data)
2529 return NVRandRGetInfo(pScrn, (Rotation*)data);
2531 return NVRandRSetConfig(pScrn, (xorgRRConfig*)data);