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