2 * Copyright 1996-1997 David J. McKay
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * DAVID J. MCKAY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 /* Hacked together from mga driver and 3.3.4 NVIDIA driver by Jarno Paananen
26 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/riva_driver.c,v 1.5 2003/11/03 05:11:26 tsi Exp $ */
28 #include "riva_include.h"
30 #include "xf86int10.h"
33 * Forward definitions for the functions that make up the driver.
35 /* Mandatory functions */
36 static Bool RivaPreInit(ScrnInfoPtr pScrn, int flags);
37 static Bool RivaScreenInit(int Index, ScreenPtr pScreen, int argc,
39 static Bool RivaEnterVT(int scrnIndex, int flags);
40 static Bool RivaEnterVTFBDev(int scrnIndex, int flags);
41 static void RivaLeaveVT(int scrnIndex, int flags);
42 static Bool RivaCloseScreen(int scrnIndex, ScreenPtr pScreen);
43 static Bool RivaSaveScreen(ScreenPtr pScreen, int mode);
45 /* Optional functions */
46 static void RivaFreeScreen(int scrnIndex, int flags);
47 static ModeStatus RivaValidMode(int scrnIndex, DisplayModePtr mode,
48 Bool verbose, int flags);
50 /* Internally used functions */
52 static Bool RivaMapMem(ScrnInfoPtr pScrn);
53 static Bool RivaMapMemFBDev(ScrnInfoPtr pScrn);
54 static Bool RivaUnmapMem(ScrnInfoPtr pScrn);
55 static void RivaSave(ScrnInfoPtr pScrn);
56 static void RivaRestore(ScrnInfoPtr pScrn);
57 static Bool RivaModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
61 * List of symbols from other modules that this module references. This
62 * list is used to tell the loader that it is OK for symbols here to be
63 * unresolved providing that it hasn't been told that they haven't been
64 * told that they are essential via a call to xf86LoaderReqSymbols() or
65 * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
66 * unresolved symbols that are not required.
69 static const char *vgahwSymbols[] = {
84 static const char *fbSymbols[] = {
90 static const char *xaaSymbols[] = {
100 static const char *ramdacSymbols[] = {
101 "xf86CreateCursorInfoRec",
102 "xf86DestroyCursorInfoRec",
107 static const char *ddcSymbols[] = {
110 "xf86SetDDCproperties",
114 static const char *vbeSymbols[] = {
121 static const char *i2cSymbols[] = {
122 "xf86CreateI2CBusRec",
127 static const char *shadowSymbols[] = {
132 static const char *fbdevHWSymbols[] = {
134 "fbdevHWUseBuildinMode",
139 "fbdevHWLoadPaletteWeak",
142 "fbdevHWAdjustFrameWeak",
144 "fbdevHWLeaveVTWeak",
147 "fbdevHWSwitchModeWeak",
148 "fbdevHWValidModeWeak",
156 static const char *int10Symbols[] = {
163 static MODULESETUPPROTO(rivaSetup);
165 static XF86ModuleVersionInfo rivaVersRec =
171 XORG_VERSION_CURRENT,
172 NV_MAJOR_VERSION, NV_MINOR_VERSION, NV_PATCHLEVEL,
173 ABI_CLASS_VIDEODRV, /* This is a video driver */
174 ABI_VIDEODRV_VERSION,
179 _X_EXPORT XF86ModuleData riva128ModuleData = { &rivaVersRec, rivaSetup, NULL };
192 static const OptionInfoRec RivaOptions[] = {
193 { OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE },
194 { OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, FALSE },
195 { OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE },
196 { OPTION_SHOWCACHE, "ShowCache", OPTV_BOOLEAN, {0}, FALSE },
197 { OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE },
198 { OPTION_FBDEV, "UseFBDev", OPTV_BOOLEAN, {0}, FALSE },
199 { OPTION_ROTATE, "Rotate", OPTV_ANYSTR, {0}, FALSE },
200 { -1, NULL, OPTV_NONE, {0}, FALSE }
204 * This is intentionally screen-independent. It indicates the binding
205 * choice made in the first PreInit.
207 static int pix24bpp = 0;
210 * ramdac info structure initialization
212 static RivaRamdacRec DacInit = {
213 FALSE, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL,
214 0, NULL, NULL, NULL, NULL
220 RivaGetRec(ScrnInfoPtr pScrn)
223 * Allocate an RivaRec, and hook it into pScrn->driverPrivate.
224 * pScrn->driverPrivate is initialised to NULL, so we can check if
225 * the allocation has already been done.
227 if (pScrn->driverPrivate != NULL)
230 pScrn->driverPrivate = xnfcalloc(sizeof(RivaRec), 1);
233 RivaPTR(pScrn)->Dac = DacInit;
238 RivaFreeRec(ScrnInfoPtr pScrn)
240 if (pScrn->driverPrivate == NULL)
242 xfree(pScrn->driverPrivate);
243 pScrn->driverPrivate = NULL;
247 rivaSetup(pointer module, pointer opts, int *errmaj, int *errmin)
249 static Bool setupDone = FALSE;
251 /* This module should be loaded only once, but check to be sure. */
256 LoaderRefSymLists(vgahwSymbols, xaaSymbols, fbSymbols,
257 ramdacSymbols, shadowSymbols,
258 i2cSymbols, ddcSymbols, vbeSymbols,
259 fbdevHWSymbols, int10Symbols, NULL);
264 _X_EXPORT const OptionInfoRec *
265 RivaAvailableOptions(int chipid, int busid)
272 RivaGetScrnInfoRec(PciChipsets *chips, int chip)
276 pScrn = xf86ConfigPciEntity(NULL, 0, chip,
277 chips, NULL, NULL, NULL,
280 if(!pScrn) return FALSE;
282 pScrn->driverVersion = RIVA_VERSION;
283 pScrn->driverName = RIVA_DRIVER_NAME;
284 pScrn->name = RIVA_NAME;
287 pScrn->PreInit = RivaPreInit;
288 pScrn->ScreenInit = RivaScreenInit;
289 pScrn->SwitchMode = RivaSwitchMode;
290 pScrn->AdjustFrame = RivaAdjustFrame;
291 pScrn->EnterVT = RivaEnterVT;
292 pScrn->LeaveVT = RivaLeaveVT;
293 pScrn->FreeScreen = RivaFreeScreen;
294 pScrn->ValidMode = RivaValidMode;
299 /* Usually mandatory */
301 RivaSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
303 return RivaModeInit(xf86Screens[scrnIndex], mode);
307 * This function is used to initialize the Start Address - the first
308 * displayed location in the video memory.
310 /* Usually mandatory */
312 RivaAdjustFrame(int scrnIndex, int x, int y, int flags)
314 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
316 RivaPtr pRiva = RivaPTR(pScrn);
317 RivaFBLayout *pLayout = &pRiva->CurrentLayout;
319 if(pRiva->ShowCache && y && pScrn->vtSema)
320 y += pScrn->virtualY - 1;
322 startAddr = (((y*pLayout->displayWidth)+x)*(pLayout->bitsPerPixel/8));
323 pRiva->riva.SetStartAddress(&pRiva->riva, startAddr);
328 * This is called when VT switching back to the X server. Its job is
329 * to reinitialise the video mode.
331 * We may wish to unmap video/MMIO memory too.
336 RivaEnterVT(int scrnIndex, int flags)
338 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
340 if (!RivaModeInit(pScrn, pScrn->currentMode))
342 RivaAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
348 RivaEnterVTFBDev(int scrnIndex, int flags)
350 fbdevHWEnterVT(scrnIndex,flags);
355 * This is called when VT switching away from the X server. Its job is
356 * to restore the previous (text) mode.
358 * We may wish to remap video/MMIO memory too.
363 RivaLeaveVT(int scrnIndex, int flags)
365 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
366 RivaPtr pRiva = RivaPTR(pScrn);
369 pRiva->riva.LockUnlock(&pRiva->riva, 1);
375 * This is called at the end of each server generation. It restores the
376 * original (text) mode. It should also unmap the video memory, and free
377 * any per-generation data allocated by the driver. It should finish
378 * by unwrapping and calling the saved CloseScreen function.
383 RivaCloseScreen(int scrnIndex, ScreenPtr pScreen)
385 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
386 RivaPtr pRiva = RivaPTR(pScrn);
390 pRiva->riva.LockUnlock(&pRiva->riva, 1);
394 vgaHWUnmapMem(pScrn);
395 if (pRiva->AccelInfoRec)
396 XAADestroyInfoRec(pRiva->AccelInfoRec);
397 if (pRiva->CursorInfoRec)
398 xf86DestroyCursorInfoRec(pRiva->CursorInfoRec);
399 if (pRiva->ShadowPtr)
400 xfree(pRiva->ShadowPtr);
402 xfree(pRiva->DGAModes);
403 if ( pRiva->expandBuffer )
404 xfree(pRiva->expandBuffer);
406 pScrn->vtSema = FALSE;
407 pScreen->CloseScreen = pRiva->CloseScreen;
408 return (*pScreen->CloseScreen)(scrnIndex, pScreen);
411 /* Free up any persistent data structures */
415 RivaFreeScreen(int scrnIndex, int flags)
418 * This only gets called when a screen is being deleted. It does not
419 * get called routinely at the end of a server generation.
421 if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
422 vgaHWFreeHWRec(xf86Screens[scrnIndex]);
423 RivaFreeRec(xf86Screens[scrnIndex]);
427 /* Checks if a mode is suitable for the selected chipset. */
431 RivaValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
437 rivaProbeDDC(ScrnInfoPtr pScrn, int index)
441 if (xf86LoadSubModule(pScrn, "vbe")) {
442 pVbe = VBEInit(NULL,index);
443 ConfiguredMonitor = vbeDoEDID(pVbe, NULL);
449 Bool RivaI2CInit(ScrnInfoPtr pScrn)
453 if (xf86LoadSubModule(pScrn, mod)) {
454 xf86LoaderReqSymLists(i2cSymbols,NULL);
457 if(xf86LoadSubModule(pScrn, mod)) {
458 xf86LoaderReqSymLists(ddcSymbols, NULL);
459 return RivaDACi2cInit(pScrn);
463 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
464 "Couldn't load %s module. DDC probing can't be done\n", mod);
471 RivaPreInit(ScrnInfoPtr pScrn, int flags)
476 ClockRangePtr clockRanges;
479 if (flags & PROBE_DETECT) {
480 EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
488 rivaProbeDDC(pScrn, i);
493 * Note: This function is only called once at server startup, and
494 * not at the start of each server generation. This means that
495 * only things that are persistent across server generations can
496 * be initialised here. xf86Screens[] is (pScrn is a pointer to one
497 * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex()
498 * are too, and should be used for data that must persist across
499 * server generations.
501 * Per-generation data should be allocated with
502 * AllocateScreenPrivateIndex() from the ScreenInit() function.
505 /* Check the number of entities, and fail if it isn't one. */
506 if (pScrn->numEntities != 1)
509 /* Allocate the RivaRec driverPrivate */
510 if (!RivaGetRec(pScrn)) {
513 pRiva = RivaPTR(pScrn);
515 /* Get the entity, and make sure it is PCI. */
516 pRiva->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
517 if (pRiva->pEnt->location.type != BUS_PCI)
520 /* Find the PCI info for this screen */
521 pRiva->PciInfo = xf86GetPciInfoForEntity(pRiva->pEnt->index);
522 pRiva->PciTag = pciTag(pRiva->PciInfo->bus, pRiva->PciInfo->device,
523 pRiva->PciInfo->func);
525 pRiva->Primary = xf86IsPrimaryPci(pRiva->PciInfo);
527 /* Initialize the card through int10 interface if needed */
528 if (xf86LoadSubModule(pScrn, "int10")) {
529 xf86LoaderReqSymLists(int10Symbols, NULL);
530 #if !defined(__alpha__)
531 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initializing int10\n");
532 pRiva->pInt = xf86InitInt10(pRiva->pEnt->index);
536 xf86SetOperatingState(resVgaIo, pRiva->pEnt->index, ResUnusedOpr);
537 xf86SetOperatingState(resVgaMem, pRiva->pEnt->index, ResDisableOpr);
539 /* Set pScrn->monitor */
540 pScrn->monitor = pScrn->confScreen->monitor;
542 pRiva->ChipRev = pRiva->PciInfo->chipRev;
543 if((pRiva->PciInfo->vendor != 0x12D2) || (pRiva->PciInfo->chipType != 0x0018))
545 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "This is not a RIVA 128\n");
546 xf86FreeInt10(pRiva->pInt);
550 pScrn->chipset = "RIVA 128";
553 * The first thing we should figure out is the depth, bpp, etc.
556 if (!xf86SetDepthBpp(pScrn, 15, 0, 0, Support32bppFb)) {
557 xf86FreeInt10(pRiva->pInt);
560 /* Check that the returned depth is one we support */
561 switch (pScrn->depth) {
567 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
568 "Given depth (%d) is not supported by this driver\n",
570 xf86FreeInt10(pRiva->pInt);
574 xf86PrintDepthBpp(pScrn);
576 /* Get the depth24 pixmap format */
577 if (pScrn->depth == 24 && pix24bpp == 0)
578 pix24bpp = xf86GetBppFromDepth(pScrn, 24);
581 * This must happen after pScrn->display has been set because
582 * xf86SetWeight references it.
584 if (pScrn->depth > 8) {
585 /* The defaults are OK for us */
586 rgb zeros = {0, 0, 0};
588 if (!xf86SetWeight(pScrn, zeros, zeros)) {
589 xf86FreeInt10(pRiva->pInt);
594 if (!xf86SetDefaultVisual(pScrn, -1)) {
595 xf86FreeInt10(pRiva->pInt);
598 /* We don't currently support DirectColor at > 8bpp */
599 if (pScrn->depth > 8 && (pScrn->defaultVisual != TrueColor)) {
600 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual"
601 " (%s) is not supported at depth %d\n",
602 xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
603 xf86FreeInt10(pRiva->pInt);
608 /* The vgahw module should be loaded here when needed */
609 if (!xf86LoadSubModule(pScrn, "vgahw")) {
610 xf86FreeInt10(pRiva->pInt);
614 xf86LoaderReqSymLists(vgahwSymbols, NULL);
617 * Allocate a vgaHWRec
619 if (!vgaHWGetHWRec(pScrn)) {
620 xf86FreeInt10(pRiva->pInt);
624 /* We use a programmable clock */
625 pScrn->progClock = TRUE;
627 /* Collect all of the relevant option flags (fill in pScrn->options) */
628 xf86CollectOptions(pScrn, NULL);
630 /* Process the options */
631 if (!(pRiva->Options = xalloc(sizeof(RivaOptions))))
633 memcpy(pRiva->Options, RivaOptions, sizeof(RivaOptions));
634 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pRiva->Options);
636 /* Set the bits per RGB for 8bpp mode */
637 if (pScrn->depth == 8)
641 pRiva->HWCursor = TRUE;
643 * The preferred method is to use the "hw cursor" option as a tri-state
644 * option, with the default set above.
646 if (xf86GetOptValBool(pRiva->Options, OPTION_HW_CURSOR, &pRiva->HWCursor)) {
649 /* For compatibility, accept this too (as an override) */
650 if (xf86ReturnOptValBool(pRiva->Options, OPTION_SW_CURSOR, FALSE)) {
652 pRiva->HWCursor = FALSE;
654 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
655 pRiva->HWCursor ? "HW" : "SW");
656 if (xf86ReturnOptValBool(pRiva->Options, OPTION_NOACCEL, FALSE)) {
657 pRiva->NoAccel = TRUE;
658 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
660 if (xf86ReturnOptValBool(pRiva->Options, OPTION_SHOWCACHE, FALSE)) {
661 pRiva->ShowCache = TRUE;
662 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ShowCache enabled\n");
664 if (xf86ReturnOptValBool(pRiva->Options, OPTION_SHADOW_FB, FALSE)) {
665 pRiva->ShadowFB = TRUE;
666 pRiva->NoAccel = TRUE;
667 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
668 "Using \"Shadow Framebuffer\" - acceleration disabled\n");
670 if (xf86ReturnOptValBool(pRiva->Options, OPTION_FBDEV, FALSE)) {
672 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
673 "Using framebuffer device\n");
676 /* check for linux framebuffer device */
677 if (!xf86LoadSubModule(pScrn, "fbdevhw")) {
678 xf86FreeInt10(pRiva->pInt);
682 xf86LoaderReqSymLists(fbdevHWSymbols, NULL);
683 if (!fbdevHWInit(pScrn, pRiva->PciInfo, NULL)) {
684 xf86FreeInt10(pRiva->pInt);
687 pScrn->SwitchMode = fbdevHWSwitchModeWeak();
688 pScrn->AdjustFrame = fbdevHWAdjustFrameWeak();
689 pScrn->EnterVT = RivaEnterVTFBDev;
690 pScrn->LeaveVT = fbdevHWLeaveVTWeak();
691 pScrn->ValidMode = fbdevHWValidModeWeak();
694 if ((s = xf86GetOptValString(pRiva->Options, OPTION_ROTATE))) {
695 if(!xf86NameCmp(s, "CW")) {
696 pRiva->ShadowFB = TRUE;
697 pRiva->NoAccel = TRUE;
698 pRiva->HWCursor = FALSE;
700 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
701 "Rotating screen clockwise - acceleration disabled\n");
703 if(!xf86NameCmp(s, "CCW")) {
704 pRiva->ShadowFB = TRUE;
705 pRiva->NoAccel = TRUE;
706 pRiva->HWCursor = FALSE;
708 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
709 "Rotating screen counter clockwise - acceleration disabled\n");
711 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
712 "\"%s\" is not a valid value for Option \"Rotate\"\n", s);
713 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
714 "Valid options are \"CW\" or \"CCW\"\n");
718 if (pRiva->pEnt->device->MemBase != 0) {
719 /* Require that the config file value matches one of the PCI values. */
720 if (!xf86CheckPciMemBase(pRiva->PciInfo, pRiva->pEnt->device->MemBase)) {
721 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
722 "MemBase 0x%08lX doesn't match any PCI base register.\n",
723 pRiva->pEnt->device->MemBase);
724 xf86FreeInt10(pRiva->pInt);
728 pRiva->FbAddress = pRiva->pEnt->device->MemBase;
732 pRiva->FbBaseReg = i;
733 if (pRiva->PciInfo->memBase[i] != 0) {
734 pRiva->FbAddress = pRiva->PciInfo->memBase[i] & 0xff800000;
737 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
738 "No valid FB address in PCI config space\n");
739 xf86FreeInt10(pRiva->pInt);
744 xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
745 (unsigned long)pRiva->FbAddress);
747 if (pRiva->pEnt->device->IOBase != 0) {
748 /* Require that the config file value matches one of the PCI values. */
749 if (!xf86CheckPciMemBase(pRiva->PciInfo, pRiva->pEnt->device->IOBase)) {
750 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
751 "IOBase 0x%08lX doesn't match any PCI base register.\n",
752 pRiva->pEnt->device->IOBase);
753 xf86FreeInt10(pRiva->pInt);
757 pRiva->IOAddress = pRiva->pEnt->device->IOBase;
761 if (pRiva->PciInfo->memBase[i] != 0) {
762 pRiva->IOAddress = pRiva->PciInfo->memBase[i] & 0xffffc000;
765 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
766 "No valid MMIO address in PCI config space\n");
767 xf86FreeInt10(pRiva->pInt);
772 xf86DrvMsg(pScrn->scrnIndex, from, "MMIO registers at 0x%lX\n",
773 (unsigned long)pRiva->IOAddress);
775 if (xf86RegisterResources(pRiva->pEnt->index, NULL, ResExclusive)) {
776 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
777 "xf86RegisterResources() found resource conflicts\n");
778 xf86FreeInt10(pRiva->pInt);
786 * If the user has specified the amount of memory in the XF86Config
787 * file, we respect that setting.
789 if (pRiva->pEnt->device->videoRam != 0) {
790 pScrn->videoRam = pRiva->pEnt->device->videoRam;
794 pScrn->videoRam = fbdevHWGetVidmem(pScrn)/1024;
796 pScrn->videoRam = pRiva->riva.RamAmountKBytes;
800 xf86DrvMsg(pScrn->scrnIndex, from, "VideoRAM: %d kBytes\n",
803 pRiva->FbMapSize = pScrn->videoRam * 1024;
806 * If the driver can do gamma correction, it should call xf86SetGamma()
811 Gamma zeros = {0.0, 0.0, 0.0};
813 if (!xf86SetGamma(pScrn, zeros)) {
814 xf86FreeInt10(pRiva->pInt);
819 pRiva->FbUsableSize = pRiva->FbMapSize - (32 * 1024);
822 * Setup the ClockRanges, which describe what clock ranges are available,
823 * and what sort of modes they can be used for.
826 pRiva->MinClock = 12000;
827 pRiva->MaxClock = pRiva->riva.MaxVClockFreqKHz;
829 clockRanges = xnfcalloc(sizeof(ClockRange), 1);
830 clockRanges->next = NULL;
831 clockRanges->minClock = pRiva->MinClock;
832 clockRanges->maxClock = pRiva->MaxClock;
833 clockRanges->clockIndex = -1; /* programmable */
834 clockRanges->interlaceAllowed = TRUE;
835 clockRanges->doubleScanAllowed = TRUE;
839 * xf86ValidateModes will check that the mode HTotal and VTotal values
840 * don't exceed the chipset's limit if pScrn->maxHValue and
841 * pScrn->maxVValue are set. Since our RivaValidMode() already takes
842 * care of this, we don't worry about setting them here.
844 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
845 pScrn->display->modes, clockRanges,
847 32 * pScrn->bitsPerPixel, 128, 2048,
848 pScrn->display->virtualX,
849 pScrn->display->virtualY,
851 LOOKUP_BEST_REFRESH);
853 if (i < 1 && pRiva->FBDev) {
854 fbdevHWUseBuildinMode(pScrn);
855 pScrn->displayWidth = pScrn->virtualX; /* FIXME: might be wrong */
859 xf86FreeInt10(pRiva->pInt);
864 /* Prune the modes marked as invalid */
865 xf86PruneDriverModes(pScrn);
867 if (i == 0 || pScrn->modes == NULL) {
868 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n");
869 xf86FreeInt10(pRiva->pInt);
875 * Set the CRTC parameters for all of the modes based on the type
876 * of mode, and the chipset's interlace requirements.
878 * Calling this is required if the mode->Crtc* values are used by the
879 * driver and if the driver doesn't provide code to set them. They
880 * are not pre-initialised at all.
882 xf86SetCrtcForModes(pScrn, 0);
884 /* Set the current mode to the first in the list */
885 pScrn->currentMode = pScrn->modes;
887 /* Print the list of modes being used */
888 xf86PrintModes(pScrn);
890 /* Set display resolution */
891 xf86SetDpi(pScrn, 0, 0);
895 * XXX This should be taken into account in some way in the mode valdation
899 if (xf86LoadSubModule(pScrn, "fb") == NULL) {
900 xf86FreeInt10(pRiva->pInt);
905 xf86LoaderReqSymLists(fbSymbols, NULL);
907 /* Load XAA if needed */
908 if (!pRiva->NoAccel) {
909 if (!xf86LoadSubModule(pScrn, "xaa")) {
910 xf86FreeInt10(pRiva->pInt);
914 xf86LoaderReqSymLists(xaaSymbols, NULL);
917 /* Load ramdac if needed */
918 if (pRiva->HWCursor) {
919 if (!xf86LoadSubModule(pScrn, "ramdac")) {
920 xf86FreeInt10(pRiva->pInt);
924 xf86LoaderReqSymLists(ramdacSymbols, NULL);
927 /* Load shadowfb if needed */
928 if (pRiva->ShadowFB) {
929 if (!xf86LoadSubModule(pScrn, "shadowfb")) {
930 xf86FreeInt10(pRiva->pInt);
934 xf86LoaderReqSymLists(shadowSymbols, NULL);
937 pRiva->CurrentLayout.bitsPerPixel = pScrn->bitsPerPixel;
938 pRiva->CurrentLayout.depth = pScrn->depth;
939 pRiva->CurrentLayout.displayWidth = pScrn->displayWidth;
940 pRiva->CurrentLayout.weight.red = pScrn->weight.red;
941 pRiva->CurrentLayout.weight.green = pScrn->weight.green;
942 pRiva->CurrentLayout.weight.blue = pScrn->weight.blue;
943 pRiva->CurrentLayout.mode = pScrn->currentMode;
945 xf86FreeInt10(pRiva->pInt);
953 * Map the framebuffer and MMIO memory.
957 RivaMapMem(ScrnInfoPtr pScrn)
961 pRiva = RivaPTR(pScrn);
964 * Map IO registers to virtual address space
966 pRiva->IOBase = xf86MapPciMem(pScrn->scrnIndex,
967 VIDMEM_MMIO | VIDMEM_READSIDEEFFECT,
968 pRiva->PciTag, pRiva->IOAddress, 0x1000000);
969 if (pRiva->IOBase == NULL)
972 pRiva->FbBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER,
973 pRiva->PciTag, pRiva->FbAddress,
975 if (pRiva->FbBase == NULL)
978 pRiva->FbStart = pRiva->FbBase;
984 RivaMapMemFBDev(ScrnInfoPtr pScrn)
988 pRiva = RivaPTR(pScrn);
990 pRiva->FbBase = fbdevHWMapVidmem(pScrn);
991 if (pRiva->FbBase == NULL)
994 pRiva->IOBase = fbdevHWMapMMIO(pScrn);
995 if (pRiva->IOBase == NULL)
998 pRiva->FbStart = pRiva->FbBase;
1004 * Unmap the framebuffer and MMIO memory.
1008 RivaUnmapMem(ScrnInfoPtr pScrn)
1012 pRiva = RivaPTR(pScrn);
1015 * Unmap IO registers to virtual address space
1017 xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pRiva->IOBase, 0x1000000);
1018 pRiva->IOBase = NULL;
1020 xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pRiva->FbBase, pRiva->FbMapSize);
1021 pRiva->FbBase = NULL;
1022 pRiva->FbStart = NULL;
1029 * Initialise a new mode.
1033 RivaModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
1035 vgaHWPtr hwp = VGAHWPTR(pScrn);
1037 RivaPtr pRiva = RivaPTR(pScrn);
1041 /* Initialise the ModeReg values */
1042 if (!vgaHWInit(pScrn, mode))
1044 pScrn->vtSema = TRUE;
1046 vgaReg = &hwp->ModeReg;
1047 rivaReg = &pRiva->ModeReg;
1049 if(!(*pRiva->ModeInit)(pScrn, mode))
1052 pRiva->riva.LockUnlock(&pRiva->riva, 0);
1054 /* Program the registers */
1055 vgaHWProtect(pScrn, TRUE);
1057 (*pRiva->Restore)(pScrn, vgaReg, rivaReg, FALSE);
1059 RivaResetGraphics(pScrn);
1061 vgaHWProtect(pScrn, FALSE);
1063 pRiva->CurrentLayout.mode = mode;
1069 * Restore the initial (text) mode.
1072 RivaRestore(ScrnInfoPtr pScrn)
1074 vgaHWPtr hwp = VGAHWPTR(pScrn);
1075 vgaRegPtr vgaReg = &hwp->SavedReg;
1076 RivaPtr pRiva = RivaPTR(pScrn);
1077 RivaRegPtr rivaReg = &pRiva->SavedReg;
1080 pRiva->riva.LockUnlock(&pRiva->riva, 0);
1082 /* Only restore text mode fonts/text for the primary card */
1083 vgaHWProtect(pScrn, TRUE);
1084 (*pRiva->Restore)(pScrn, vgaReg, rivaReg, pRiva->Primary);
1085 vgaHWProtect(pScrn, FALSE);
1089 RivaDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
1091 unsigned char crtc1A;
1092 vgaHWPtr hwp = VGAHWPTR(pScrn);
1094 if (!pScrn->vtSema) return;
1096 crtc1A = hwp->readCrtc(hwp, 0x1A) & ~0xC0;
1098 switch (PowerManagementMode) {
1099 case DPMSModeStandby: /* HSync: Off, VSync: On */
1102 case DPMSModeSuspend: /* HSync: On, VSync: Off */
1105 case DPMSModeOff: /* HSync: Off, VSync: Off */
1108 case DPMSModeOn: /* HSync: On, VSync: On */
1113 /* vgaHWDPMSSet will merely cut the dac output */
1114 vgaHWDPMSSet(pScrn, PowerManagementMode, flags);
1116 hwp->writeCrtc(hwp, 0x1A, crtc1A);
1122 /* This gets called at the start of each server generation */
1125 RivaScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
1130 RivaRamdacPtr Rivadac;
1133 unsigned char *FBStart;
1134 int width, height, displayWidth;
1138 * First get the ScrnInfoRec
1140 pScrn = xf86Screens[pScreen->myNum];
1143 hwp = VGAHWPTR(pScrn);
1144 pRiva = RivaPTR(pScrn);
1145 Rivadac = &pRiva->Dac;
1147 /* Map the Riva memory and MMIO areas */
1149 if (!RivaMapMemFBDev(pScrn))
1152 if (!RivaMapMem(pScrn))
1156 /* Map the VGA memory when the primary video */
1157 if (pRiva->Primary && !pRiva->FBDev) {
1158 hwp->MapSize = 0x10000;
1159 if (!vgaHWMapMem(pScrn))
1165 if (!fbdevHWModeInit(pScrn, pScrn->currentMode))
1168 /* Save the current state */
1170 /* Initialise the first mode */
1171 if (!RivaModeInit(pScrn, pScrn->currentMode))
1176 /* Darken the screen for aesthetic reasons and set the viewport */
1177 RivaSaveScreen(pScreen, SCREEN_SAVER_ON);
1178 pScrn->AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
1182 * The next step is to setup the screen's visuals, and initialise the
1183 * framebuffer code. In cases where the framebuffer's default
1184 * choices for things like visual layouts and bits per RGB are OK,
1185 * this may be as simple as calling the framebuffer's ScreenInit()
1186 * function. If not, the visuals will need to be setup before calling
1187 * a fb ScreenInit() function and fixed up after.
1189 * For most PC hardware at depths >= 8, the defaults that fb uses
1190 * are not appropriate. In this driver, we fixup the visuals after.
1194 * Reset the visual list.
1196 miClearVisualTypes();
1198 /* Setup the visuals we support. */
1200 if (pScrn->bitsPerPixel > 8) {
1201 if (!miSetVisualTypes(pScrn->depth, TrueColorMask, 8,
1202 pScrn->defaultVisual))
1205 if (!miSetVisualTypes(pScrn->depth,
1206 miGetDefaultVisualMask(pScrn->depth), 8,
1207 pScrn->defaultVisual))
1210 if (!miSetPixmapDepths ()) return FALSE;
1214 * Call the framebuffer layer's ScreenInit function, and fill in other
1218 width = pScrn->virtualX;
1219 height = pScrn->virtualY;
1220 displayWidth = pScrn->displayWidth;
1224 height = pScrn->virtualX;
1225 width = pScrn->virtualY;
1228 if(pRiva->ShadowFB) {
1229 pRiva->ShadowPitch = BitmapBytePad(pScrn->bitsPerPixel * width);
1230 pRiva->ShadowPtr = xalloc(pRiva->ShadowPitch * height);
1231 displayWidth = pRiva->ShadowPitch / (pScrn->bitsPerPixel >> 3);
1232 FBStart = pRiva->ShadowPtr;
1234 pRiva->ShadowPtr = NULL;
1235 FBStart = pRiva->FbStart;
1238 switch (pScrn->bitsPerPixel) {
1242 ret = fbScreenInit(pScreen, FBStart, width, height,
1243 pScrn->xDpi, pScrn->yDpi,
1244 displayWidth, pScrn->bitsPerPixel);
1247 xf86DrvMsg(scrnIndex, X_ERROR,
1248 "Internal error: invalid bpp (%d) in RivaScreenInit\n",
1249 pScrn->bitsPerPixel);
1257 if (pScrn->bitsPerPixel > 8) {
1258 /* Fixup RGB ordering */
1259 visual = pScreen->visuals + pScreen->numVisuals;
1260 while (--visual >= pScreen->visuals) {
1261 if ((visual->class | DynamicClass) == DirectColor) {
1262 visual->offsetRed = pScrn->offset.red;
1263 visual->offsetGreen = pScrn->offset.green;
1264 visual->offsetBlue = pScrn->offset.blue;
1265 visual->redMask = pScrn->mask.red;
1266 visual->greenMask = pScrn->mask.green;
1267 visual->blueMask = pScrn->mask.blue;
1272 fbPictureInit (pScreen, 0, 0);
1274 xf86SetBlackWhitePixels(pScreen);
1277 if(!pRiva->ShadowFB) /* hardware cursor needs to wrap this layer */
1278 RivaDGAInit(pScreen);
1282 AvailFBArea.x2 = pScrn->displayWidth;
1283 AvailFBArea.y2 = (min(pRiva->FbUsableSize, 32*1024*1024)) /
1284 (pScrn->displayWidth * pScrn->bitsPerPixel / 8);
1285 xf86InitFBManager(pScreen, &AvailFBArea);
1287 if (!pRiva->NoAccel)
1288 RivaAccelInit(pScreen);
1290 miInitializeBackingStore(pScreen);
1291 xf86SetBackingStore(pScreen);
1292 xf86SetSilkenMouse(pScreen);
1295 /* Initialize software cursor.
1296 Must precede creation of the default colormap */
1297 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
1300 /* Initialize HW cursor layer.
1301 Must follow software cursor initialization*/
1302 if (pRiva->HWCursor) {
1303 if(!RivaCursorInit(pScreen))
1304 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1305 "Hardware cursor initialization failed\n");
1308 /* Initialise default colourmap */
1309 if (!miCreateDefColormap(pScreen))
1313 /* Initialize colormap layer.
1314 Must follow initialization of the default colormap */
1315 if(!xf86HandleColormaps(pScreen, 256, 8,
1316 (pRiva->FBDev ? fbdevHWLoadPaletteWeak() : Rivadac->LoadPalette),
1317 NULL, CMAP_RELOAD_ON_MODE_SWITCH | CMAP_PALETTED_TRUECOLOR))
1321 if(pRiva->ShadowFB) {
1322 RefreshAreaFuncPtr refreshArea = RivaRefreshArea;
1325 pRiva->PointerMoved = pScrn->PointerMoved;
1326 pScrn->PointerMoved = RivaPointerMoved;
1328 switch(pScrn->bitsPerPixel) {
1329 case 8: refreshArea = RivaRefreshArea8; break;
1330 case 16: refreshArea = RivaRefreshArea16; break;
1331 case 32: refreshArea = RivaRefreshArea32; break;
1334 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1335 "Driver rotation enabled, RandR disabled\n");
1338 ShadowFBInit(pScreen, refreshArea);
1341 xf86DPMSInit(pScreen, RivaDPMSSet, 0);
1344 pScrn->memPhysBase = pRiva->FbAddress;
1345 pScrn->fbOffset = 0;
1347 pScreen->SaveScreen = RivaSaveScreen;
1349 /* Wrap the current CloseScreen function */
1350 pRiva->CloseScreen = pScreen->CloseScreen;
1351 pScreen->CloseScreen = RivaCloseScreen;
1353 /* Report any unused options (only for the first generation) */
1354 if (serverGeneration == 1) {
1355 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
1361 /* Free up any persistent data structures */
1364 /* Do screen blanking */
1368 RivaSaveScreen(ScreenPtr pScreen, int mode)
1370 return vgaHWSaveScreen(pScreen, mode);
1374 RivaSave(ScrnInfoPtr pScrn)
1376 RivaPtr pRiva = RivaPTR(pScrn);
1377 RivaRegPtr rivaReg = &pRiva->SavedReg;
1378 vgaHWPtr pVga = VGAHWPTR(pScrn);
1379 vgaRegPtr vgaReg = &pVga->SavedReg;
1381 (*pRiva->Save)(pScrn, vgaReg, rivaReg, pRiva->Primary);