rendition.c revision bdcaa8d0
1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/rendition/rendition.c,v 1.58 2003/11/03 05:11:26 tsi Exp $ */
2/*
3 * Copyright (C) 1998 The XFree86 Project, Inc.  All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18 * XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Except as contained in this notice, the name of the XFree86 Project shall
23 * not be used in advertising or otherwise to promote the sale, use or other
24 * dealings in this Software without prior written authorization from the
25 * XFree86 Project.
26 */
27
28/*
29 * This is essentially a transfer of the 3.3 sources written by
30 * Marc Langenbach and Tim Rowley.
31 *
32 * The initial port of this driver to XFree86 4.0 was done by
33 * Marc Langenbach <mlangen@studcs.uni-sb.de>
34 * Additions, updates and bugfixes by Dejan Ilic <dejan.ilic@home.se>
35 */
36
37#ifdef HAVE_CONFIG_H
38#include "config.h"
39#endif
40
41/*
42 * Activate acceleration code or not.
43 *
44 *         WARNING BUGGY !!!
45 * Yes, you activate it on your own risk.
46 */
47#define USE_ACCEL 0
48
49/*
50 * includes
51 */
52
53#include "rendition.h"
54#include "rendition_options.h"
55
56#include "hwcursor.h"
57#include "xf86int10.h"
58
59#include "vtypes.h"
60#include "vboard.h"
61#include "vmodes.h"
62#include "accel.h"
63#include "vramdac.h"
64#include "rendition_shadow.h"
65#include "vbe.h"
66
67/*
68 * defines
69 */
70
71#undef DEBUG
72
73#define RENDITION_NAME            "RENDITION"
74#define RENDITION_DRIVER_NAME     "rendition"
75#define RENDITION_VERSION_NAME    "4.1.0"
76#define RENDITION_VERSION_MAJOR   4
77#define RENDITION_VERSION_MINOR   1
78#define RENDITION_PATCHLEVEL      0
79#define RENDITION_VERSION_CURRENT ((RENDITION_VERSION_MAJOR << 24) | \
80                 (RENDITION_VERSION_MINOR << 16) | RENDITION_PATCHLEVEL)
81
82/*
83 * Constants for the (theoretical) maximum width and height that can
84 * be used to display data on the CRT.  These were calculated from
85 * the HORZ and VERT macors, respectively, in vmodes.c.
86 */
87static const int MAX_HDISPLAY = 2048;
88static const int MAX_VDISPLAY = 2048;
89
90/*
91 * Constants for the (theoretical) maximum line length of a scan line
92 * and scan lines per screen (including overdraw).  These were
93 * calculated from the HORZ and VERT macors, respectively, in vmodes.c.
94 */
95static const int MAX_HTOTAL   = 2880;
96static const int MAX_VTOTAL   = 2184;
97
98/*
99 * local function prototypes
100 */
101
102static const OptionInfoRec * renditionAvailableOptions(int, int);
103static void       renditionIdentify(int);
104static Bool       renditionProbe(DriverPtr, int);
105static Bool       renditionPreInit(ScrnInfoPtr, int);
106static Bool       renditionScreenInit(int, ScreenPtr, int, char **);
107static Bool       renditionSwitchMode(int, DisplayModePtr, int);
108static void       renditionAdjustFrame(int, int, int, int);
109static Bool       renditionEnterVT(int, int);
110static void       renditionLeaveVT(int, int);
111static void       renditionFreeScreen(int, int);
112
113static ModeStatus renditionValidMode(int, DisplayModePtr, Bool, int);
114static Bool renditionMapMem(ScrnInfoPtr pScreenInfo);
115static Bool renditionUnmapMem(ScrnInfoPtr pScreenInfo);
116#if 0
117static xf86MonPtr renditionDDC(ScrnInfoPtr pScreenInfo);
118static unsigned int renditionDDC1Read (ScrnInfoPtr pScreenInfo);
119#endif
120static xf86MonPtr renditionProbeDDC(ScrnInfoPtr pScrn, int index);
121
122static void renditionLoadPalette(ScrnInfoPtr, int, int *, LOCO *, VisualPtr);
123
124
125/*
126 * global data
127 */
128
129OptionInfoRec const renditionOptions[]={
130    { OPTION_FBWC,      "FramebufferWC", OPTV_BOOLEAN, {0}, FALSE },
131    { OPTION_SW_CURSOR, "SW_Cursor", OPTV_BOOLEAN, {0}, FALSE },
132    { OPTION_NOACCEL,   "NoAccel",  OPTV_BOOLEAN, {0}, FALSE },
133    { OPTION_OVERCLOCK_MEM,"Overclock_Mem",  OPTV_BOOLEAN, {0}, FALSE },
134    { OPTION_NO_DDC,    "NoDDC",    OPTV_BOOLEAN, {0}, FALSE },
135    { OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE },
136    { OPTION_ROTATE,    "Rotate",   OPTV_ANYSTR,  {0}, FALSE },
137    { -1,                NULL,      OPTV_NONE,    {0}, FALSE }
138};
139
140_X_EXPORT DriverRec RENDITION={
141    RENDITION_VERSION_CURRENT,
142    "rendition",
143    renditionIdentify,
144    renditionProbe,
145    renditionAvailableOptions,
146    NULL,
147    0
148};
149
150static const char *vgahwSymbols[]={
151    "vgaHWBlankScreen",
152    "vgaHWDPMSSet",
153    "vgaHWFreeHWRec",
154    "vgaHWGetHWRec",
155    "vgaHWGetIOBase",
156    "vgaHWGetIndex",
157    "vgaHWLock",
158    "vgaHWMapMem",
159    "vgaHWProtect",
160    "vgaHWRestore",
161    "vgaHWSave",
162    "vgaHWSaveScreen",
163    "vgaHWUnlock",
164    "vgaHWHandleColormaps",
165    NULL
166};
167
168static const char *ramdacSymbols[] = {
169    "xf86CreateCursorInfoRec",
170    "xf86DestroyCursorInfoRec",
171    "xf86InitCursor",
172    NULL
173};
174
175#if defined(XFree86LOADER) || USE_ACCEL
176static const char *xaaSymbols[] = {
177    "XAACreateInfoRec",
178    "XAADestroyInfoRec",
179    "XAAInit",
180    NULL
181};
182#endif
183
184static const char *ddcSymbols[] = {
185    "xf86DoEDID_DDC1",
186    "xf86PrintEDID",
187    NULL
188};
189
190static const char *int10Symbols[] = {
191    "xf86FreeInt10",
192    "xf86InitInt10",
193    NULL
194};
195
196static const char *fbSymbols[]={
197    "fbScreenInit",
198    "fbPictureInit",
199    NULL
200};
201
202static const char *shadowfbSymbols[] = {
203    "ShadowFBInit",
204    NULL
205};
206
207static const char *vbeSymbols[] = {
208    "VBEInit",
209    "vbeDoEDID",
210    "vbeFree",
211    NULL
212};
213
214
215
216#ifdef XFree86LOADER
217
218/* Module loader interface */
219
220static MODULESETUPPROTO(renditionSetup);
221
222static XF86ModuleVersionInfo renditionVersionRec = {
223    RENDITION_DRIVER_NAME,
224    MODULEVENDORSTRING,
225    MODINFOSTRING1,
226    MODINFOSTRING2,
227    XORG_VERSION_CURRENT,
228    RENDITION_VERSION_MAJOR, RENDITION_VERSION_MINOR, RENDITION_PATCHLEVEL,
229    ABI_CLASS_VIDEODRV,
230    ABI_VIDEODRV_VERSION,
231    MOD_CLASS_VIDEODRV,
232    {0, 0, 0, 0}
233};
234
235_X_EXPORT XF86ModuleData renditionModuleData =
236               { &renditionVersionRec, renditionSetup, NULL };
237
238static pointer
239renditionSetup(pointer Module, pointer Options, int *ErrorMajor,
240               int *ErrorMinor)
241{
242    static Bool Initialised=FALSE;
243
244    if (!Initialised) {
245        Initialised=TRUE;
246        xf86AddDriver(&RENDITION, Module, 0);
247        LoaderRefSymLists(vgahwSymbols, ramdacSymbols,
248			  fbSymbols, xaaSymbols, ddcSymbols, int10Symbols,
249			  shadowfbSymbols, vbeSymbols, NULL);
250        return (pointer)TRUE;
251    }
252
253    if (ErrorMajor)
254        *ErrorMajor=LDR_ONCEONLY;
255
256    return NULL;
257}
258
259#endif
260
261
262enum renditionTypes {
263    CHIP_RENDITION_V1000,
264    CHIP_RENDITION_V2x00
265};
266
267/* supported chipsets */
268static SymTabRec renditionChipsets[] = {
269    {CHIP_RENDITION_V1000, "V1000"},
270    {CHIP_RENDITION_V2x00, "V2x00"},
271    {-1,                   NULL}
272};
273
274static PciChipsets renditionPCIchipsets[] = {
275  { CHIP_RENDITION_V1000, PCI_CHIP_V1000, RES_SHARED_VGA },
276  { CHIP_RENDITION_V2x00, PCI_CHIP_V2x00, RES_SHARED_VGA },
277  { -1,                   -1,             RES_UNDEFINED }
278};
279
280/*
281 * functions
282 */
283
284static const OptionInfoRec *
285renditionAvailableOptions(int chipid, int busid)
286{
287    return renditionOptions;
288}
289
290static void
291renditionIdentify(int flags)
292{
293    xf86PrintChipsets(RENDITION_NAME,
294        "rendition driver (version " RENDITION_VERSION_NAME ") for chipsets",
295        renditionChipsets);
296}
297
298
299
300/*
301 * This function is called once, at the start of the first server generation to
302 * do a minimal probe for supported hardware.
303 */
304static Bool
305renditionProbe(DriverPtr drv, int flags)
306{
307    Bool foundScreen=FALSE;
308    int numDevSections, numUsed;
309    GDevPtr *devSections;
310    int *usedChips;
311    int c;
312
313    /* Find the config file Device sections that match this
314     * driver, and return if there are none. */
315    if ((numDevSections=xf86MatchDevice(RENDITION_DRIVER_NAME, &devSections)) <= 0)
316        return FALSE;
317
318    /* PCI BUS */
319    if (xf86GetPciVideoInfo()) {
320        numUsed=xf86MatchPciInstances(RENDITION_DRIVER_NAME, PCI_VENDOR_RENDITION,
321                    renditionChipsets, renditionPCIchipsets,
322                    devSections, numDevSections, drv, &usedChips);
323
324	xfree(devSections);
325	if (numUsed <= 0)
326	    return FALSE;
327
328        if (flags & PROBE_DETECT)
329            foundScreen = TRUE;
330        else for (c=0; c<numUsed; c++) {
331            ScrnInfoPtr pScrn;
332            /* Allocate a ScrnInfoRec and claim the slot */
333            pScrn=NULL;
334            if ((pScrn = xf86ConfigPciEntity(pScrn, 0,usedChips[c],
335						   renditionPCIchipsets, NULL,
336						   NULL, NULL, NULL, NULL))) {
337
338		pScrn->driverVersion=RENDITION_VERSION_CURRENT;
339		pScrn->driverName   =RENDITION_DRIVER_NAME;
340		pScrn->name         =RENDITION_NAME;
341		pScrn->Probe        =renditionProbe;
342		pScrn->PreInit      =renditionPreInit;
343		pScrn->ScreenInit   =renditionScreenInit;
344		pScrn->SwitchMode   =renditionSwitchMode;
345		pScrn->AdjustFrame  =renditionAdjustFrame;
346		pScrn->EnterVT      =renditionEnterVT;
347		pScrn->LeaveVT      =renditionLeaveVT;
348		pScrn->FreeScreen   =renditionFreeScreen;
349		pScrn->ValidMode    =renditionValidMode;
350		foundScreen=TRUE;
351	    }
352        }
353	xfree(usedChips);
354    }
355    return foundScreen;
356}
357
358
359#if 0
360static Bool
361renditionClockSelect(ScrnInfoPtr pScreenInfo, int ClockNumber)
362{
363        vgaHWPtr pvgaHW = VGAHWPTR(pScreenInfo);
364        static CARD8 save_misc;
365
366        switch (ClockNumber)
367        {
368            case CLK_REG_SAVE:
369                save_misc = inb(pvgaHW->PIOOffset + VGA_MISC_OUT_R);
370                break;
371
372            case CLK_REG_RESTORE:
373                outb(pvgaHW->PIOOffset + VGA_MISC_OUT_W, save_misc);
374                break;
375
376            default:
377                outb(pvgaHW->PIOOffset + VGA_MISC_OUT_W,
378		     (save_misc & 0xF3) | ((ClockNumber << 2) & 0x0C));
379                break;
380        }
381
382    return TRUE;
383}
384#endif
385
386static renditionPtr
387renditionGetRec(ScrnInfoPtr pScreenInfo)
388{
389#ifdef DEBUG
390    ErrorF("GetRec ...!!!!\n");
391    sleep(1);
392#endif
393    if (!pScreenInfo->driverPrivate)
394        pScreenInfo->driverPrivate=xcalloc(sizeof(renditionRec), 1);
395
396    /* perhaps some initialization? <ml> */
397
398#ifdef DEBUG
399    ErrorF("GetRec ...!!!!\n");
400    sleep(1);
401#endif
402    return (renditionPtr)pScreenInfo->driverPrivate;
403}
404
405
406static void
407renditionFreeRec(ScrnInfoPtr pScreenInfo)
408{
409#ifdef DEBUG
410    ErrorF("FreeRec...!!!!\n");
411    sleep(1);
412#endif
413    if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
414	vgaHWFreeHWRec(pScreenInfo);
415    xfree(pScreenInfo->driverPrivate);
416    pScreenInfo->driverPrivate=NULL;
417
418#ifdef DEBUG
419    ErrorF("FreeRec OK...!!!!\n");
420    sleep(1);
421#endif
422}
423
424#if 0
425static void
426renditionProtect(ScrnInfoPtr pScreenInfo, Bool On)
427{
428#ifdef DEBUG
429    ErrorF("Protect...!!!!\n");
430    sleep(1);
431#endif
432
433    vgaHWProtect(pScreenInfo, On);
434
435#ifdef DEBUG
436    ErrorF("Protect OK...!!!!\n");
437    sleep(1);
438#endif
439}
440#endif
441
442static Bool
443renditionSaveScreen(ScreenPtr pScreen, int mode)
444{
445#ifdef DEBUG
446    ErrorF("Savescreen...!!!!\n");
447    sleep(1);
448#endif
449
450    return vgaHWSaveScreen(pScreen, mode);
451}
452
453#if 0
454static void
455renditionBlankScreen(ScrnInfoPtr pScreenInfo, Bool Unblank)
456{
457#ifdef DEBUG
458    ErrorF("Blankscreen...!!!!\n");
459    sleep(1);
460#endif
461
462    vgaHWBlankScreen(pScreenInfo, Unblank);
463#ifdef DEBUG
464    ErrorF("Blankscreen OK...!!!!\n");
465    sleep(1);
466#endif
467}
468#endif
469
470
471/*
472 * This function is called once for each screen at the start of the first
473 * server generation to initialise the screen for all server generations.
474 */
475
476static Bool
477renditionPreInit(ScrnInfoPtr pScreenInfo, int flags)
478{
479    static ClockRange renditionClockRange = {NULL, 0, 135000, -1, FALSE, TRUE, 1, 1, 0};
480    MessageType       From;
481    int               videoRam, Rounding, nModes = 0;
482    renditionPtr      pRendition;
483    char             *in_string;
484    vgaHWPtr          pvgaHW;
485
486#ifdef DEBUG
487    ErrorF("Rendition: renditionPreInit() called\n");
488#endif
489
490    /* Check the number of entities, and fail if it isn't one. */
491    if (pScreenInfo->numEntities != 1)
492	return FALSE;
493
494    /* allocate driver private structure */
495    if (!renditionGetRec(pScreenInfo))
496        return FALSE;
497
498    pRendition=RENDITIONPTR(pScreenInfo);
499
500    /* Get the entity, and make sure it is PCI. */
501    pRendition->pEnt = xf86GetEntityInfo(pScreenInfo->entityList[0]);
502    if (pRendition->pEnt->location.type != BUS_PCI)
503	return FALSE;
504
505    if (flags & PROBE_DETECT) {
506        ConfiguredMonitor =
507	    renditionProbeDDC(pScreenInfo, pRendition->pEnt->index);
508        return TRUE;
509    }
510
511    /* set the monitor */
512    pScreenInfo->monitor=pScreenInfo->confScreen->monitor;
513
514    /* Initialize the card through int10 interface if needed */
515    if (xf86LoadSubModule(pScreenInfo, "int10")){
516        xf86Int10InfoPtr pInt=NULL;
517
518        xf86LoaderReqSymLists(int10Symbols, NULL);
519
520        xf86DrvMsg(pScreenInfo->scrnIndex, X_INFO, "Initializing int10\n");
521        pInt = xf86InitInt10(pRendition->pEnt->index);
522        xf86FreeInt10(pInt);
523    }
524
525    /* Find the PCI info for this screen */
526    pRendition->PciInfo = xf86GetPciInfoForEntity(pRendition->pEnt->index);
527    pRendition->pcitag= pciTag(pRendition->PciInfo->bus,
528               pRendition->PciInfo->device, pRendition->PciInfo->func);
529
530    /*
531     * XXX This could be refined if some VGA memory resources are not
532     * decoded in operating mode.
533     */
534    xf86SetOperatingState(resVgaMem, pRendition->pEnt->index, ResUnusedOpr);
535
536    if (xf86RegisterResources(pRendition->pEnt->index, NULL, ResExclusive))
537         return FALSE;
538
539    /* Operations for which memory access is required. */
540    pScreenInfo->racMemFlags = RAC_FB | RAC_CURSOR;
541    /* Operations for which I/O access is required. (XXX Check this) */
542    pScreenInfo->racIoFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT;
543
544    /* determine depth, bpp, etc. */
545    if (!xf86SetDepthBpp(pScreenInfo, 0, 0, 0, Support32bppFb))
546        return FALSE;
547
548    /* Verify that the color depth is supported. */
549    switch( pScreenInfo->depth ) {
550
551        case 8:
552        case 16:
553        case 24:
554        {
555            break;
556        }
557
558        case 15:
559        {
560            if (PCI_CHIP_V1000 != pRendition->PciInfo->chipType) {
561                xf86DrvMsg( pScreenInfo->scrnIndex, X_ERROR,
562                        "Given depth (%d) is not supported by this chipset.\n",
563                        pScreenInfo->depth);
564                return FALSE;
565            }
566        }
567
568        default:
569        {
570            xf86DrvMsg( pScreenInfo->scrnIndex, X_ERROR,
571                    "Given depth (%d) is not supported by this driver\n",
572                    pScreenInfo->depth );
573            return FALSE;
574        }
575
576    } /* End of switch( pScreenInfo->depth ) {*/
577
578
579    /* Print the color depth and frame buffer bits per pixel. */
580    xf86PrintDepthBpp( pScreenInfo );
581
582
583    /* collect all of the options flags and process them */
584
585    xf86CollectOptions(pScreenInfo, NULL);
586    if (!(pRendition->Options = xalloc(sizeof(renditionOptions))))
587	return FALSE;
588    memcpy(pRendition->Options, renditionOptions, sizeof(renditionOptions));
589    xf86ProcessOptions(pScreenInfo->scrnIndex, pScreenInfo->options,
590        pRendition->Options);
591
592
593    /* Load fb */
594    if (!xf86LoadSubModule(pScreenInfo, "fb"))
595      return FALSE;
596
597    xf86LoaderReqSymLists(fbSymbols, NULL);
598
599    /* determine colour weights */
600    pScreenInfo->rgbBits=8;
601
602    if (pScreenInfo->depth > 8) {
603      rgb defaultWeight = {0, 0, 0};
604      rgb defaultMask = {0, 0, 0};
605
606      xf86PrintDepthBpp(pScreenInfo);
607
608      /* Standard defaults are OK if depths are OK */
609      if (!xf86SetWeight(pScreenInfo, defaultWeight, defaultMask))
610        return FALSE;
611      else{
612	/* XXX:  Check that returned weight is supported */
613      }
614    }
615
616    /* determine default visual */
617    if (!xf86SetDefaultVisual(pScreenInfo, -1))
618      return FALSE;
619
620    /* the gamma fields must be initialised when using the new cmap code */
621    if (pScreenInfo->depth > 1) {
622        Gamma zeros = {0.0, 0.0, 0.0};
623
624        if (!xf86SetGamma(pScreenInfo, zeros))
625            return FALSE;
626    }
627
628    /* the Rendition chips have a programmable clock */
629    pScreenInfo->progClock=TRUE;
630
631    /* set various fields according to the given options */
632    /* to be filled in <ml> */
633
634    if (PCI_CHIP_V1000==pRendition->PciInfo->chipType){
635      pRendition->board.chip=V1000_DEVICE;
636    }
637    else {
638      pRendition->board.chip=V2000_DEVICE;
639      renditionClockRange.maxClock = 170000;
640      renditionClockRange.clockIndex = -1;
641    }
642
643    if (!xf86LoadSubModule(pScreenInfo, "vgahw")){
644        return FALSE;
645    }
646    xf86LoaderReqSymLists(vgahwSymbols, NULL);
647
648    if (!vgaHWGetHWRec(pScreenInfo))
649        return FALSE;
650
651    pvgaHW = VGAHWPTR(pScreenInfo);
652    pvgaHW->MapSize = 0x00010000;       /* Standard 64kB VGA window */
653    vgaHWGetIOBase(pvgaHW);             /* Get VGA I/O base */
654
655    pRendition->board.accel=0;
656    pRendition->board.vgaio_base = pvgaHW->PIOOffset;
657    pRendition->board.io_base =
658	pRendition->board.vgaio_base + pRendition->PciInfo->ioBase[1];
659    pRendition->board.mmio_base=0;
660    pRendition->board.vmmio_base=0;
661    pRendition->board.mem_size=0;
662    pRendition->board.mem_base=(vu8 *)pRendition->PciInfo->memBase[0];
663    pRendition->board.vmem_base=NULL;
664    pRendition->board.init=0;
665
666    if (pScreenInfo->chipset)
667        xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG, "Chipset: \"%s\".\n",
668            pScreenInfo->chipset);
669    else
670        xf86DrvMsg(pScreenInfo->scrnIndex, X_PROBED, "Chipset: \"%s\".\n",
671            renditionChipsets[
672        pRendition->board.chip==V1000_DEVICE ? 0:1].name);
673
674    /* I do not get the IO base addres <ml> */
675    /* XXX Is this still true?  If so, the wrong base is being checked */
676    xf86DrvMsg(pScreenInfo->scrnIndex, X_PROBED,
677	       "Rendition %s @ %lx/%lx\n",
678	       renditionChipsets[pRendition->board.chip==V1000_DEVICE ? 0:1]
679	       .name,
680	       pRendition->PciInfo->ioBase[1],
681	       pRendition->PciInfo->memBase[0]);
682
683    /* First of all get a "clean" starting state */
684    verite_resetboard(pScreenInfo);
685
686    /* determine video ram -- to do so, we assume a full size memory of 16M,
687     * then map it and use verite_getmemorysize() to determine the real
688     * amount of memory */
689    pScreenInfo->videoRam = 16<<10;
690    pRendition->board.mem_size = pScreenInfo->videoRam * 1024;
691    renditionMapMem(pScreenInfo);
692
693    videoRam=verite_getmemorysize(pScreenInfo)>>10;
694    renditionUnmapMem(pScreenInfo);
695
696    From = X_PROBED;
697    xf86DrvMsg(pScreenInfo->scrnIndex, From, "videoRam: %d kBytes\n", videoRam);
698    pScreenInfo->videoRam=videoRam;
699    pRendition->board.mem_size=videoRam * 1024;
700
701    /* Load the needed symbols */
702
703    pRendition->board.shadowfb=TRUE;
704
705    if ((in_string = xf86GetOptValString(pRendition->Options, OPTION_ROTATE))){
706	if(!xf86NameCmp(in_string, "CW")) {
707	    /* accel is disabled below for shadowFB */
708	    pRendition->board.shadowfb = TRUE;
709	    pRendition->board.rotate = 1;
710	    xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,
711		       "Rotating screen clockwise - acceleration disabled\n");
712	} else if(!xf86NameCmp(in_string, "CCW")) {
713	    pRendition->board.shadowfb = TRUE;
714	    pRendition->board.rotate = -1;
715	    xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,  "Rotating screen "
716		       "counter clockwise - acceleration disabled\n");
717	} else {
718	    xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,
719		       "\"%s\" is not a valid value for Option \"Rotate\"\n",
720		       in_string);
721	    xf86DrvMsg(pScreenInfo->scrnIndex, X_INFO,
722		       "Valid options are \"CW\" or \"CCW\"\n");
723	}
724    }
725
726    if (xf86ReturnOptValBool(pRendition->Options, OPTION_SHADOW_FB,1)||
727	pRendition->board.rotate) {
728	if (!xf86LoadSubModule(pScreenInfo, "shadowfb")) {
729	    xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
730		       "Oops, \"ShadowFB\" module loading failed, disabling ShadowFB!\n");
731	}
732	else{
733	    xf86LoaderReqSymLists(shadowfbSymbols, NULL);
734	    pRendition->board.shadowfb=TRUE;
735	    xf86DrvMsg(pScreenInfo->scrnIndex, X_INFO,
736		       "Using \"Shadow Framebuffer\"\n");
737	}
738    }
739    else {
740	pRendition->board.shadowfb=FALSE;
741	xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,
742		   "\"Shadow Framebuffer\" disabled\n");
743    }
744
745
746    /* Load Ramdac module if needed */
747    if (!xf86ReturnOptValBool(pRendition->Options, OPTION_SW_CURSOR,0) &&
748	!pRendition->board.rotate){
749      if (!xf86LoadSubModule(pScreenInfo, "ramdac")) {
750	return FALSE;
751      }
752      xf86LoaderReqSymLists(ramdacSymbols, NULL);
753    }
754
755#if 0
756    /* Load DDC module if needed */
757    if (!xf86ReturnOptValBool(pRendition->Options, OPTION_NO_DDC,0)){
758      if (!xf86LoadSubModule(pScreenInfo, "ddc")) {
759	xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
760		   ("Loading of DDC library failed, skipping DDC-probe\n"));
761      }
762      else {
763	xf86LoaderReqSymLists(ddcSymbols, NULL);
764	pScreenInfo->monitor->DDC = renditionDDC(pScreenInfo);
765      }
766    }
767    else {
768      xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,
769		 ("Skipping DDC probe on users request\n"));
770    }
771#else
772    /* Load DDC module if needed */
773    if (!xf86ReturnOptValBool(pRendition->Options, OPTION_NO_DDC,0)){
774      if (!xf86LoadSubModule(pScreenInfo, "ddc")) {
775	xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
776		   ("Loading of DDC library failed, skipping DDC-probe\n"));
777      }
778      else {
779	  xf86MonPtr mon;
780	  xf86LoaderReqSymLists(ddcSymbols, NULL);
781	  mon = renditionProbeDDC(pScreenInfo, pRendition->pEnt->index);
782	  xf86PrintEDID(mon);
783	  xf86SetDDCproperties(pScreenInfo, mon);
784      }
785    }
786    else {
787      xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,
788		 ("Skipping DDC probe on users request\n"));
789    }
790#endif
791
792    /* Set the virtual X rounding (in bits) */
793    if (pScreenInfo->depth == 8)
794        Rounding = 16 * 8;
795    else
796        Rounding = 16;
797
798    /*
799     * Validate the modes.  Note that the limits passed to
800     * xf86ValidateModes() are VGA CRTC architectural limits.
801     */
802    pScreenInfo->maxHValue = MAX_HTOTAL;
803    pScreenInfo->maxVValue = MAX_VTOTAL;
804    nModes = xf86ValidateModes(pScreenInfo,
805            pScreenInfo->monitor->Modes, pScreenInfo->display->modes,
806            &renditionClockRange, NULL, 8, MAX_HDISPLAY, Rounding,
807            1, MAX_VDISPLAY, pScreenInfo->display->virtualX,
808            pScreenInfo->display->virtualY,
809            0x10000, LOOKUP_CLOSEST_CLOCK | LOOKUP_CLKDIV2);
810
811    if (nModes < 0)
812        return FALSE;
813
814    /* Remove invalid modes */
815    xf86PruneDriverModes(pScreenInfo);
816
817    /* Set CRTC values for the modes */
818    xf86SetCrtcForModes(pScreenInfo, 0);
819
820    /* Set current mode to the first in list */
821    pScreenInfo->currentMode = pScreenInfo->modes;
822
823    /* Print mode list */
824    xf86PrintModes(pScreenInfo);
825
826    /* Set display resolution */
827    xf86SetDpi(pScreenInfo, 0, 0);
828
829    /* Only one chipset here */
830    if (!pScreenInfo->chipset)
831        pScreenInfo->chipset = (char *)renditionChipsets[0].name;
832
833    if(!xf86ReturnOptValBool(pRendition->Options, OPTION_SW_CURSOR,0)){
834      if(!pRendition->board.rotate)
835	/* Do preemtive things for HW cursor */
836	RenditionHWCursorPreInit(pScreenInfo);
837      else{
838	xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
839		   "Hardware cursor not supported on rotated screen\n");
840	xf86DrvMsg(pScreenInfo->scrnIndex, X_INFO,
841		   "Software cursor activated\n");
842      }
843    }
844    else
845      xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,
846		 "Software cursor selected\n");
847
848    /* Unmapping delayed until after micrcode loading */
849      /****************************************/
850      /* Reserve memory and load the microcode */
851      /****************************************/
852#if USE_ACCEL
853    if (!xf86ReturnOptValBool(pRendition->Options, OPTION_NOACCEL,0) &&
854	!pRendition->board.shadowfb) {
855	/* Load XAA if needed */
856	if (xf86LoadSubModule(pScreenInfo, "xaa")) {
857	    xf86LoaderReqSymLists(xaaSymbols, NULL);
858	    renditionMapMem(pScreenInfo);
859  	    RENDITIONAccelPreInit (pScreenInfo);
860	    renditionUnmapMem(pScreenInfo);
861	    pRendition->board.accel = TRUE;
862	} else     xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
863			      ("XAA module not found: "
864			       "Skipping acceleration\n"));
865    }
866    else
867      xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,
868		 ("Skipping acceleration on users request\n"));
869#else
870    xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
871	       ("Skipping acceleration\n"));
872#endif
873
874#ifdef DEBUG
875    ErrorF("PreInit OK...!!!!\n");
876    sleep(2);
877#endif
878
879    return TRUE;        /* Tada! */
880}
881
882
883/* Save mode on server entry */
884static void
885renditionSave(ScrnInfoPtr pScreenInfo)
886{
887#ifdef DEBUG
888    ErrorF("Save...!!!!\n");
889    sleep(1);
890#endif
891    vgaHWSave(pScreenInfo, &VGAHWPTR(pScreenInfo)->SavedReg,VGA_SR_ALL);
892
893#ifdef DEBUG
894    ErrorF("Save OK...!!!!\n");
895    sleep(1);
896#endif
897}
898
899#if 0
900/* Restore the mode that was saved on server entry */
901static void
902renditionRestore(ScrnInfoPtr pScreenInfo)
903{
904#ifdef DEBUG
905    ErrorF("Restore...!!!!\n");
906    sleep(1);
907#endif
908
909    vgaHWProtect(pScreenInfo, TRUE);
910    vgaHWRestore(pScreenInfo, &VGAHWPTR(pScreenInfo)->SavedReg, VGA_SR_ALL);
911    vgaHWProtect(pScreenInfo, FALSE);
912
913    verite_setmode(pScreenInfo, &RENDITIONPTR(pScreenInfo)->mode);
914
915#ifdef DEBUG
916    ErrorF("Restore OK...!!!!\n");
917    sleep(1);
918#endif
919}
920#endif
921
922/* Set a graphics mode */
923static Bool
924renditionSetMode(ScrnInfoPtr pScreenInfo, DisplayModePtr pMode)
925{
926    struct verite_modeinfo_t *modeinfo=&RENDITIONPTR(pScreenInfo)->mode;
927
928#ifdef DEBUG
929    ErrorF("RENDITION: renditionSetMode() called\n");
930    ErrorF("Setmode...!!!!\n");
931    sleep(1);
932#endif
933
934    /* construct a modeinfo for the verite_setmode function */
935    modeinfo->clock=pMode->SynthClock;
936    modeinfo->hdisplay=pMode->HDisplay;
937    modeinfo->hsyncstart=pMode->HSyncStart;
938    modeinfo->hsyncend=pMode->HSyncEnd;
939    modeinfo->htotal=pMode->HTotal;
940    modeinfo->hskew=pMode->HSkew;
941    modeinfo->vdisplay=pMode->VDisplay;
942    modeinfo->vsyncstart=pMode->VSyncStart;
943    modeinfo->vsyncend=pMode->VSyncEnd;
944    modeinfo->vtotal=pMode->VTotal;
945
946    modeinfo->screenwidth = pMode->HDisplay;
947    modeinfo->virtualwidth = pScreenInfo->virtualX & 0xfff8;
948    modeinfo->screenheight = pMode->VDisplay;
949    modeinfo->virtualheight = pScreenInfo->virtualY & 0xfff8;
950
951    if ((pMode->Flags&(V_PHSYNC|V_NHSYNC))
952        && (pMode->Flags&(V_PVSYNC|V_NVSYNC))) {
953        modeinfo->hsynchi=((pMode->Flags&V_PHSYNC) == V_PHSYNC);
954        modeinfo->vsynchi=((pMode->Flags&V_PVSYNC) == V_PVSYNC);
955    }
956    else {
957        int VDisplay=pMode->VDisplay;
958        if (pMode->Flags & V_DBLSCAN)
959            VDisplay*=2;
960        if (VDisplay < 400) {
961            /* +hsync -vsync */
962            modeinfo->hsynchi=1;
963            modeinfo->vsynchi=0;
964        }
965        else if (VDisplay < 480) {
966            /* -hsync +vsync */
967            modeinfo->hsynchi=0;
968            modeinfo->vsynchi=1;
969        }
970        else if (VDisplay < 768) {
971            /* -hsync -vsync */
972            modeinfo->hsynchi=0;
973            modeinfo->vsynchi=0;
974        }
975        else {
976            /* +hsync +vsync */
977            modeinfo->hsynchi=1;
978            modeinfo->vsynchi=1;
979        }
980    }
981
982    switch (pScreenInfo->bitsPerPixel) {
983        case 8:
984            modeinfo->bitsperpixel=8;
985            modeinfo->pixelformat=V_PIXFMT_8I;
986            break;
987        case 16:
988            modeinfo->bitsperpixel=16;
989            if (pScreenInfo->weight.green == 5)
990                /* on a V1000, this looks too 'red/magenta' <ml> */
991                modeinfo->pixelformat=V_PIXFMT_1555;
992            else
993                modeinfo->pixelformat=V_PIXFMT_565;
994            break;
995        case 32:
996            modeinfo->bitsperpixel=32;
997            modeinfo->pixelformat=V_PIXFMT_8888;
998            break;
999    }
1000    modeinfo->fifosize=128;
1001    modeinfo->flags=pMode->Flags;
1002
1003    verite_setmode(pScreenInfo,&RENDITIONPTR(pScreenInfo)->mode);
1004#ifdef DEBUG
1005    ErrorF("Setmode OK...!!!!\n");
1006    sleep(1);
1007#endif
1008    return TRUE;
1009}
1010
1011static void
1012renditionLeaveGraphics(ScrnInfoPtr pScreenInfo)
1013{
1014    renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
1015
1016#ifdef DEBUG
1017    ErrorF("RENDITION: renditionLeaveGraphics() called\n");
1018    sleep(1);
1019#endif
1020    verite_restore(pScreenInfo, &pRendition->saveRegs);
1021
1022    vgaHWProtect(pScreenInfo, TRUE);
1023    vgaHWRestore(pScreenInfo, &VGAHWPTR(pScreenInfo)->SavedReg, VGA_SR_ALL);
1024    vgaHWProtect(pScreenInfo, FALSE);
1025
1026    vgaHWLock(VGAHWPTR(pScreenInfo));
1027
1028#ifdef DEBUG
1029    ErrorF("Leavegraphics OK...!!!!\n");
1030    sleep(1);
1031#endif
1032}
1033
1034
1035/* Unravel the screen */
1036static Bool
1037renditionCloseScreen(int scrnIndex, ScreenPtr pScreen)
1038{
1039    ScrnInfoPtr pScreenInfo = xf86Screens[scrnIndex];
1040    renditionPtr prenditionPriv=renditionGetRec(pScreenInfo);
1041    Bool Closed = TRUE;
1042
1043#ifdef DEBUG
1044    ErrorF("RENDITION: renditionCloseScreen() called\n");
1045    sleep(1);
1046#endif
1047
1048    if (prenditionPriv->board.hwcursor_used)
1049	RenditionHWCursorRelease(pScreenInfo);
1050
1051    if (prenditionPriv->board.accel)
1052	RENDITIONAccelNone(pScreenInfo);
1053
1054    if (pScreenInfo->vtSema)
1055	renditionLeaveGraphics(pScreenInfo);
1056
1057    pScreenInfo->vtSema = FALSE;
1058
1059    if (prenditionPriv
1060	&& (pScreen->CloseScreen = prenditionPriv->CloseScreen)) {
1061        prenditionPriv->CloseScreen = NULL;
1062        Closed = (*pScreen->CloseScreen)(scrnIndex, pScreen);
1063    }
1064
1065#ifdef DEBUG
1066    ErrorF("Closescreen OK...!!!!\n");
1067    sleep(1);
1068#endif
1069    return Closed;
1070}
1071
1072
1073static void
1074renditionDPMSSet(ScrnInfoPtr pScreen, int mode, int flags)
1075{
1076#ifdef DEBUG
1077    ErrorF("RENDITION: renditionDPMSSet() called\n");
1078#endif
1079
1080    vgaHWDPMSSet(pScreen, mode, flags);
1081}
1082
1083static Bool
1084renditionScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
1085{
1086    ScrnInfoPtr pScreenInfo = xf86Screens[scrnIndex];
1087    renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
1088    Bool Inited = FALSE;
1089    unsigned char *FBBase;
1090    VisualPtr visual;
1091    vgaHWPtr pvgaHW;
1092    int displayWidth,width,height;
1093
1094#ifdef DEBUG
1095    ErrorF("RENDITION: renditionScreenInit() called\n");
1096    sleep(1);
1097#endif
1098    /* Get vgahw private     */
1099    pvgaHW = VGAHWPTR(pScreenInfo);
1100
1101    /* Get driver private */
1102    pRendition=renditionGetRec(pScreenInfo);
1103
1104    /* Save the current state and setup the current mode */
1105    renditionSave(pScreenInfo);
1106
1107    /* Map VGA aperture */
1108    if (!vgaHWMapMem(pScreenInfo))
1109        return FALSE;
1110
1111    if (!renditionMapMem(pScreenInfo))
1112	return FALSE;
1113
1114    /* Unlock VGA registers */
1115    vgaHWUnlock(pvgaHW);
1116
1117    verite_save(pScreenInfo);
1118
1119    pScreenInfo->vtSema = TRUE;
1120
1121    if (!renditionSetMode(pScreenInfo, pScreenInfo->currentMode))
1122        return FALSE;
1123
1124    /* blank the screen */
1125    renditionSaveScreen(pScreen, SCREEN_SAVER_ON);
1126
1127    (*pScreenInfo->AdjustFrame)(pScreenInfo->scrnIndex,
1128				pScreenInfo->frameX0, pScreenInfo->frameY0, 0);
1129
1130
1131    miClearVisualTypes();
1132
1133    if (!miSetVisualTypes(pScreenInfo->depth,
1134			  miGetDefaultVisualMask(pScreenInfo->depth),
1135			  pScreenInfo->rgbBits, pScreenInfo->defaultVisual))
1136	return FALSE;
1137
1138    miSetPixmapDepths ();
1139
1140    if (pRendition->board.rotate) {
1141	height = pScreenInfo->virtualX;
1142	width = pScreenInfo->virtualY;
1143    } else {
1144	width = pScreenInfo->virtualX;
1145	height = pScreenInfo->virtualY;
1146    }
1147
1148    if(pRendition->board.shadowfb) {
1149	pRendition->board.shadowPitch
1150	    = BitmapBytePad(pScreenInfo->bitsPerPixel * width);
1151	pRendition->board.shadowPtr
1152	    = xalloc(pRendition->board.shadowPitch * height);
1153	displayWidth = pRendition->board.shadowPitch
1154	    / (pScreenInfo->bitsPerPixel >> 3);
1155	FBBase = pRendition->board.shadowPtr;
1156    } else {
1157	pRendition->board.shadowPtr = NULL;
1158	FBBase = pRendition->board.vmem_base+pRendition->board.fbOffset;
1159	displayWidth=pScreenInfo->displayWidth;
1160    }
1161
1162    Inited = fbScreenInit(pScreen, FBBase,
1163			  width, height,
1164			  pScreenInfo->xDpi, pScreenInfo->yDpi,
1165			  displayWidth,
1166			  pScreenInfo->bitsPerPixel);
1167
1168    if (!Inited)
1169        return FALSE;
1170
1171    if (pScreenInfo->bitsPerPixel > 8) {
1172        /* Fixup RGB ordering */
1173        visual=pScreen->visuals+pScreen->numVisuals;
1174        while (--visual >= pScreen->visuals) {
1175	    if ((visual->class | DynamicClass) == DirectColor){
1176		visual->offsetRed = pScreenInfo->offset.red;
1177		visual->offsetGreen = pScreenInfo->offset.green;
1178		visual->offsetBlue = pScreenInfo->offset.blue;
1179		visual->redMask = pScreenInfo->mask.red;
1180		visual->greenMask = pScreenInfo->mask.green;
1181		visual->blueMask = pScreenInfo->mask.blue;
1182	    }
1183	}
1184    }
1185
1186    /* must be after RGB ordering fixed */
1187    fbPictureInit (pScreen, 0, 0);
1188
1189    xf86SetBlackWhitePixels(pScreen);
1190    miInitializeBackingStore(pScreen);
1191
1192    /*********************************************************/
1193    /* The actual setup of the driver-specific code          */
1194    /* has to be after fbScreenInit and before cursor init */
1195    /*********************************************************/
1196#if USE_ACCEL
1197    if (pRendition->board.accel)
1198	RENDITIONAccelXAAInit (pScreen);
1199#endif
1200
1201    /* Initialise cursor functions */
1202    xf86SetSilkenMouse(pScreen);
1203    miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
1204
1205    if(!xf86ReturnOptValBool(pRendition->Options, OPTION_SW_CURSOR,0)&&
1206       !pRendition->board.rotate){
1207	/* Initialise HW cursor */
1208	if(!RenditionHWCursorInit(scrnIndex, pScreen)){
1209	    xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
1210		       "Hardware Cursor initalization failed!!\n");
1211	}
1212    }
1213
1214    if (pRendition->board.shadowfb) {
1215	RefreshAreaFuncPtr refreshArea = renditionRefreshArea;
1216
1217	if(pRendition->board.rotate) {
1218	    if (!pRendition->board.PointerMoved) {
1219		pRendition->board.PointerMoved = pScreenInfo->PointerMoved;
1220		pScreenInfo->PointerMoved = renditionPointerMoved;
1221	    }
1222
1223	    switch(pScreenInfo->bitsPerPixel) {
1224		case 8:         refreshArea = renditionRefreshArea8;  break;
1225		case 16:        refreshArea = renditionRefreshArea16; break;
1226		case 24:        refreshArea = renditionRefreshArea24; break;
1227		case 32:        refreshArea = renditionRefreshArea32; break;
1228	    }
1229	}
1230
1231	ShadowFBInit(pScreen, refreshArea);
1232    }
1233
1234    /* Setup default colourmap */
1235    if (!miCreateDefColormap(pScreen))
1236	return FALSE;
1237
1238    /* Try the new code based on the new colormap layer */
1239    if (pScreenInfo->depth > 1)
1240	if (!xf86HandleColormaps(pScreen, 256, pScreenInfo->rgbBits,
1241				 renditionLoadPalette, NULL,
1242				 CMAP_RELOAD_ON_MODE_SWITCH)) {
1243	    xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
1244		       "Colormap initialization failed\n");
1245	    return FALSE;
1246	}
1247
1248    xf86DPMSInit(pScreen, renditionDPMSSet, 0);
1249
1250    if (xf86ReturnOptValBool(pRendition->Options, OPTION_OVERCLOCK_MEM,0)) {
1251	pRendition->board.overclock_mem=TRUE;
1252    }
1253
1254    /* Wrap the screen's CloseScreen vector and set its SaveScreen vector */
1255    pRendition->CloseScreen = pScreen->CloseScreen;
1256    pScreen->CloseScreen = renditionCloseScreen;
1257    pScreen->SaveScreen = renditionSaveScreen;
1258
1259    if (!Inited)
1260        renditionCloseScreen(scrnIndex, pScreen);
1261
1262    if (serverGeneration == 1)
1263	xf86ShowUnusedOptions(pScreenInfo->scrnIndex, pScreenInfo->options);
1264
1265#ifdef DEBUG
1266    ErrorF("ScreenInit OK...!!!!\n");
1267    sleep(1);
1268#endif
1269    return Inited;
1270}
1271
1272static Bool
1273renditionSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags)
1274{
1275#ifdef DEBUG
1276    ErrorF("RENDITION: renditionSwitchMode() called\n");
1277#endif
1278    return renditionSetMode(xf86Screens[scrnIndex], pMode);
1279}
1280
1281
1282static void
1283renditionAdjustFrame(int scrnIndex, int x, int y, int flags)
1284{
1285    ScrnInfoPtr pScreenInfo=xf86Screens[scrnIndex];
1286    renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
1287    int offset, virtualwidth, bitsPerPixel;
1288
1289#ifdef DEBUG
1290    ErrorF("RENDITION: renditionAdjustFrame() called\n");
1291#endif
1292
1293    bitsPerPixel=pScreenInfo->bitsPerPixel;
1294    virtualwidth=pRendition->mode.virtualwidth;
1295    offset=(y*virtualwidth+x)*(bitsPerPixel>>3);
1296
1297    offset+= pRendition->board.fbOffset;
1298
1299#ifdef DEBUG
1300    ErrorF ("MOVING SCREEN %d bytes!!\n",offset);
1301#endif
1302    verite_setframebase(pScreenInfo, offset);
1303}
1304
1305
1306static Bool
1307renditionEnterVT(int scrnIndex, int flags)
1308{
1309    ScrnInfoPtr pScreenInfo = xf86Screens[scrnIndex];
1310    vgaHWPtr pvgaHW = VGAHWPTR(pScreenInfo);
1311
1312#ifdef DEBUG
1313    ErrorF("RENDITION: renditionEnterVT() called\n");
1314#endif
1315
1316    /* Map VGA aperture */
1317    if (!vgaHWMapMem(pScreenInfo))
1318        return FALSE;
1319
1320    /* Unlock VGA registers */
1321    vgaHWUnlock(pvgaHW);
1322
1323    if (!renditionSetMode(pScreenInfo, pScreenInfo->currentMode))
1324        return FALSE;
1325
1326    (*pScreenInfo->AdjustFrame)(pScreenInfo->scrnIndex,
1327				pScreenInfo->frameX0, pScreenInfo->frameY0, 0);
1328
1329    return TRUE;
1330}
1331
1332
1333static void
1334renditionLeaveVT(int scrnIndex, int flags)
1335{
1336#ifdef DEBUG
1337    ErrorF("RENDITION: renditionLeaveVT() called\n");
1338#endif
1339    renditionLeaveGraphics(xf86Screens[scrnIndex]);
1340}
1341
1342
1343static void
1344renditionFreeScreen(int scrnIndex, int flags)
1345{
1346    renditionFreeRec(xf86Screens[scrnIndex]);
1347}
1348
1349
1350static ModeStatus
1351renditionValidMode(int scrnIndex, DisplayModePtr pMode, Bool Verbose,
1352		   int flags)
1353{
1354    if (pMode->Flags & V_INTERLACE)
1355        return MODE_NO_INTERLACE;
1356
1357    return MODE_OK;
1358}
1359
1360static Bool
1361renditionMapMem(ScrnInfoPtr pScreenInfo)
1362{
1363    Bool WriteCombine;
1364    int mapOption;
1365    renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
1366
1367#ifdef DEBUG
1368    ErrorF("Mapping ...\n");
1369    ErrorF("%d %d %d %x %d\n", pScreenInfo->scrnIndex, VIDMEM_FRAMEBUFFER,
1370	   pRendition->pcitag,
1371	   pRendition->board.mem_base, pScreenInfo->videoRam * 1024);
1372#endif
1373
1374    if (pRendition->board.chip == V1000_DEVICE){
1375	/* Some V1000 boards are known to have problems with Write-Combining */
1376	/* V2x00 also found to have similar problems with memcpy & WC ! */
1377	WriteCombine = 0;
1378    } else {
1379	/* Activate Write_Combine if possible */
1380	WriteCombine = 1;
1381    }
1382       /* Override on users request */
1383    WriteCombine
1384	= xf86ReturnOptValBool(pRendition->Options, OPTION_FBWC, WriteCombine);
1385    if (WriteCombine) {
1386	xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,
1387		   ("Requesting Write-Combined memory access\n"));
1388	mapOption = VIDMEM_FRAMEBUFFER;
1389    } else {
1390	xf86DrvMsg(pScreenInfo->scrnIndex, X_CONFIG,
1391		   ("Requesting MMIO-style memory access\n"));
1392	mapOption = VIDMEM_MMIO;
1393    }
1394
1395    pRendition->board.vmem_base=
1396        xf86MapPciMem(pScreenInfo->scrnIndex, mapOption,
1397		      pRendition->pcitag,
1398		      (unsigned long)pRendition->board.mem_base,
1399		      pScreenInfo->videoRam * 1024);
1400    return TRUE;
1401
1402#ifdef DEBUG0
1403    ErrorF("Done\n");
1404#endif
1405}
1406
1407static Bool
1408renditionUnmapMem(ScrnInfoPtr pScreenInfo)
1409{
1410#ifdef DEBUG
1411  ErrorF("Unmapping ...\n");
1412#endif
1413    xf86UnMapVidMem(pScreenInfo->scrnIndex,
1414        RENDITIONPTR(pScreenInfo)->board.vmem_base,
1415		    pScreenInfo->videoRam * 1024);
1416    return TRUE;
1417#ifdef DEBUG0
1418    ErrorF("Done\n");
1419#endif
1420}
1421
1422static void
1423renditionLoadPalette(ScrnInfoPtr pScreenInfo, int numColors,
1424		     int *indices, LOCO *colors,
1425		     VisualPtr pVisual)
1426{
1427  verite_setpalette(pScreenInfo, numColors, indices, colors, pVisual);
1428}
1429
1430xf86MonPtr
1431renditionProbeDDC(ScrnInfoPtr pScreenInfo, int index)
1432{
1433  vbeInfoPtr pVbe;
1434  xf86MonPtr mon = NULL;
1435
1436  if (xf86LoadSubModule(pScreenInfo, "vbe")) {
1437    xf86LoaderReqSymLists(vbeSymbols, NULL);
1438
1439    pVbe = VBEInit(NULL,index);
1440    mon = vbeDoEDID(pVbe, NULL);
1441    vbeFree(pVbe);
1442  }
1443  return mon;
1444}
1445
1446# if 0
1447static xf86MonPtr
1448renditionDDC (ScrnInfoPtr pScreenInfo)
1449{
1450  renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
1451  IOADDRESS iob=pRendition->board.io_base;
1452  vu32 temp;
1453
1454  xf86MonPtr MonInfo = NULL;
1455  temp = verite_in32(iob+CRTCCTL); /* Remember original value */
1456
1457  /* Enable DDC1 */
1458  verite_out32(iob+CRTCCTL,(temp|
1459		       CRTCCTL_ENABLEDDC|
1460		       CRTCCTL_VSYNCENABLE|
1461		       CRTCCTL_VIDEOENABLE));
1462
1463  MonInfo = xf86DoEDID_DDC1(pScreenInfo->scrnIndex,
1464			    vgaHWddc1SetSpeed,
1465			    renditionDDC1Read );
1466
1467  verite_out32(iob+CRTCCTL,temp); /* return the original values */
1468
1469  xf86DrvMsg(pScreenInfo->scrnIndex, X_INFO,
1470	     "DDC Monitor info: %p\n", MonInfo);
1471
1472  xf86PrintEDID( MonInfo );
1473  xf86DrvMsg(pScreenInfo->scrnIndex, X_INFO,
1474	     "end of DDC Monitor info\n\n");
1475
1476  /* xf86SetDDCproperties(pScreenInfo, MonInfo); */
1477  return MonInfo;
1478}
1479
1480static unsigned int
1481renditionDDC1Read (ScrnInfoPtr pScreenInfo)
1482{
1483  renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
1484  IOADDRESS iob=pRendition->board.io_base;
1485  vu32 value = 0;
1486
1487  /* wait for Vsync */
1488  while (!(verite_in32(iob+CRTCSTATUS) & CRTCSTATUS_VERT_SYNC));
1489  while (verite_in32(iob+CRTCSTATUS) & CRTCSTATUS_VERT_SYNC);
1490
1491  /* Read the value */
1492  value = verite_in32(iob+CRTCCTL) & CRTCCTL_DDCDATA;
1493  return value;
1494}
1495
1496#endif
1497