Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Guest-side test tools, config, and X11 stuff for PARAGRAPH graphics device
[palacios.git] / guest / linux / paragraph / x11_modified_files / dummy_driver.c
1
2 /*
3  * Copyright 2002, SuSE Linux AG, Author: Egbert Eich
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <fcntl.h>
13 #include <sys/mman.h>
14 /* All drivers should typically include these */
15 #include "xf86.h"
16 #include "xf86_OSproc.h"
17
18 /* All drivers initialising the SW cursor need this */
19 #include "mipointer.h"
20
21 /* All drivers using the mi colormap manipulation need this */
22 #include "micmap.h"
23
24 /* identifying atom needed by magnifiers */
25 #include <X11/Xatom.h>
26 #include "property.h"
27
28 #include "xf86cmap.h"
29
30 #include "xf86fbman.h"
31
32 #include "fb.h"
33
34 #include "picturestr.h"
35
36 #ifdef XvExtension
37 #include "xf86xv.h"
38 #include <X11/extensions/Xv.h>
39 #endif
40
41 /*
42  * Driver data structures.
43  */
44 #include "dummy.h"
45
46 /* These need to be checked */
47 #include <X11/X.h>
48 #include <X11/Xproto.h>
49 #include "scrnintstr.h"
50 #include "servermd.h"
51
52 #ifdef USE_DGA
53 #define _XF86DGA_SERVER_
54 #include <X11/extensions/xf86dgaproto.h>
55 #endif
56
57 /* Mandatory functions */
58 static const OptionInfoRec *    DUMMYAvailableOptions(int chipid, int busid);
59 static void     DUMMYIdentify(int flags);
60 static Bool     DUMMYProbe(DriverPtr drv, int flags);
61 static Bool     DUMMYPreInit(ScrnInfoPtr pScrn, int flags);
62 static Bool     DUMMYScreenInit(SCREEN_INIT_ARGS_DECL);
63 static Bool     DUMMYEnterVT(VT_FUNC_ARGS_DECL);
64 static void     DUMMYLeaveVT(VT_FUNC_ARGS_DECL);
65 static Bool     DUMMYCloseScreen(CLOSE_SCREEN_ARGS_DECL);
66 static Bool     DUMMYCreateWindow(WindowPtr pWin);
67 static void     DUMMYFreeScreen(FREE_SCREEN_ARGS_DECL);
68 static ModeStatus DUMMYValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode,
69                                  Bool verbose, int flags);
70 static Bool     DUMMYSaveScreen(ScreenPtr pScreen, int mode);
71
72 /* Internally used functions */
73 static Bool     dummyModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
74 static void     dummySave(ScrnInfoPtr pScrn);
75 static void     dummyRestore(ScrnInfoPtr pScrn, Bool restoreText);
76 static Bool     dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,
77                                 pointer ptr);
78
79
80 /* static void     DUMMYDisplayPowerManagementSet(ScrnInfoPtr pScrn, */
81 /*                              int PowerManagementMode, int flags); */
82
83 #define DUMMY_VERSION 4000
84 #define DUMMY_NAME "DUMMY"
85 #define DUMMY_DRIVER_NAME "dummy"
86
87 #define DUMMY_MAJOR_VERSION PACKAGE_VERSION_MAJOR
88 #define DUMMY_MINOR_VERSION PACKAGE_VERSION_MINOR
89 #define DUMMY_PATCHLEVEL PACKAGE_VERSION_PATCHLEVEL
90
91 #define DUMMY_MAX_WIDTH 32767
92 #define DUMMY_MAX_HEIGHT 32767
93
94 #define PARAGRAPH_LEN (1024*1024*4)
95 #define PARAGRAPH_PADDR 0x80000000
96 /*
97  * This is intentionally screen-independent.  It indicates the binding
98  * choice made in the first PreInit.
99  */
100 static int pix24bpp = 0;
101
102
103 /*
104  * This contains the functions needed by the server after loading the driver
105  * module.  It must be supplied, and gets passed back by the SetupProc
106  * function in the dynamic case.  In the static case, a reference to this
107  * is compiled in, and this requires that the name of this DriverRec be
108  * an upper-case version of the driver name.
109  */
110
111 _X_EXPORT DriverRec DUMMY = {
112     DUMMY_VERSION,
113     DUMMY_DRIVER_NAME,
114     DUMMYIdentify,
115     DUMMYProbe,
116     DUMMYAvailableOptions,
117     NULL,
118     0,
119     dummyDriverFunc
120 };
121
122 static SymTabRec DUMMYChipsets[] = {
123     { DUMMY_CHIP,   "dummy" },
124     { -1,                NULL }
125 };
126
127 typedef enum {
128     OPTION_SW_CURSOR
129 } DUMMYOpts;
130
131 static const OptionInfoRec DUMMYOptions[] = {
132     { OPTION_SW_CURSOR, "SWcursor",     OPTV_BOOLEAN,   {0}, FALSE },
133     { -1,                  NULL,           OPTV_NONE,   {0}, FALSE }
134 };
135
136 #ifdef XFree86LOADER
137
138 static MODULESETUPPROTO(dummySetup);
139
140 static XF86ModuleVersionInfo dummyVersRec =
141 {
142         "dummy",
143         MODULEVENDORSTRING,
144         MODINFOSTRING1,
145         MODINFOSTRING2,
146         XORG_VERSION_CURRENT,
147         DUMMY_MAJOR_VERSION, DUMMY_MINOR_VERSION, DUMMY_PATCHLEVEL,
148         ABI_CLASS_VIDEODRV,
149         ABI_VIDEODRV_VERSION,
150         MOD_CLASS_VIDEODRV,
151         {0,0,0,0}
152 };
153
154 /*
155  * This is the module init data.
156  * Its name has to be the driver name followed by ModuleData
157  */
158 _X_EXPORT XF86ModuleData dummyModuleData = { &dummyVersRec, dummySetup, NULL };
159
160 static pointer
161 dummySetup(pointer module, pointer opts, int *errmaj, int *errmin)
162 {
163     static Bool setupDone = FALSE;
164
165     if (!setupDone) {
166         setupDone = TRUE;
167         xf86AddDriver(&DUMMY, module, HaveDriverFuncs);
168
169         /*
170          * Modules that this driver always requires can be loaded here
171          * by calling LoadSubModule().
172          */
173
174         /*
175          * The return value must be non-NULL on success even though there
176          * is no TearDownProc.
177          */
178         return (pointer)1;
179     } else {
180         if (errmaj) *errmaj = LDR_ONCEONLY;
181         return NULL;
182     }
183 }
184
185 #endif /* XFree86LOADER */
186
187 static Bool
188 DUMMYGetRec(ScrnInfoPtr pScrn)
189 {
190     /*
191      * Allocate a DUMMYRec, and hook it into pScrn->driverPrivate.
192      * pScrn->driverPrivate is initialised to NULL, so we can check if
193      * the allocation has already been done.
194      */
195     if (pScrn->driverPrivate != NULL)
196         return TRUE;
197    
198     pScrn->driverPrivate = xnfcalloc(sizeof(DUMMYRec), 1);
199
200     if (pScrn->driverPrivate == NULL)
201         return FALSE;
202         return TRUE;
203 }
204
205 static void
206 DUMMYFreeRec(ScrnInfoPtr pScrn)
207 {
208     if (pScrn->driverPrivate == NULL)
209         return;
210     free(pScrn->driverPrivate);
211     pScrn->driverPrivate = NULL;
212 }
213
214 static const OptionInfoRec *
215 DUMMYAvailableOptions(int chipid, int busid)
216 {
217     return DUMMYOptions;
218 }
219
220 /* Mandatory */
221 static void
222 DUMMYIdentify(int flags)
223 {
224    printf("Identifying");
225     xf86PrintChipsets(DUMMY_NAME, "Driver for Dummy chipsets",
226                         DUMMYChipsets);
227 }
228
229 /* Mandatory */
230 static Bool
231 DUMMYProbe(DriverPtr drv, int flags)
232 {
233    printf("Probe function starts");
234     Bool foundScreen = FALSE;
235     int numDevSections, numUsed;
236     GDevPtr *devSections;
237     int i;
238
239     if (flags & PROBE_DETECT)
240         return FALSE;
241     /*
242      * Find the config file Device sections that match this
243      * driver, and return if there are none.
244      */
245     if ((numDevSections = xf86MatchDevice(DUMMY_DRIVER_NAME,
246                                           &devSections)) <= 0) {
247         return FALSE;
248     }
249
250     numUsed = numDevSections;
251
252     if (numUsed > 0) {
253
254         for (i = 0; i < numUsed; i++) {
255             ScrnInfoPtr pScrn = NULL;
256             int entityIndex = 
257                 xf86ClaimNoSlot(drv,DUMMY_CHIP,devSections[i],TRUE);
258             /* Allocate a ScrnInfoRec and claim the slot */
259             if ((pScrn = xf86AllocateScreen(drv,0 ))) {
260                    xf86AddEntityToScreen(pScrn,entityIndex);
261                     pScrn->driverVersion = DUMMY_VERSION;
262                     pScrn->driverName    = DUMMY_DRIVER_NAME;
263                     pScrn->name          = DUMMY_NAME;
264                     pScrn->Probe         = DUMMYProbe;
265                     pScrn->PreInit       = DUMMYPreInit;
266                     pScrn->ScreenInit    = DUMMYScreenInit;
267                     pScrn->SwitchMode    = DUMMYSwitchMode;
268                     pScrn->AdjustFrame   = DUMMYAdjustFrame;
269                     pScrn->EnterVT       = DUMMYEnterVT;
270                     pScrn->LeaveVT       = DUMMYLeaveVT;
271                     pScrn->FreeScreen    = DUMMYFreeScreen;
272                     pScrn->ValidMode     = DUMMYValidMode;
273
274                     foundScreen = TRUE;
275             }
276         }
277     }    
278
279    printf("Probe ends");
280     return foundScreen;
281 }
282
283 # define RETURN \
284     { DUMMYFreeRec(pScrn);\
285                             return FALSE;\
286                                              }
287
288 /* Mandatory */
289 Bool
290 DUMMYPreInit(ScrnInfoPtr pScrn, int flags)
291 {
292     printf("dummy PrInit starts");
293     ClockRangePtr clockRanges;
294     int i;
295     DUMMYPtr dPtr;
296     int maxClock = 230000;
297     GDevPtr device = xf86GetEntityInfo(pScrn->entityList[0])->device;
298
299     if (flags & PROBE_DETECT) 
300         return TRUE;
301     
302     /* Allocate the DummyRec driverPrivate */
303     if (!DUMMYGetRec(pScrn)) {
304         return FALSE;
305     }
306     
307     dPtr = DUMMYPTR(pScrn);
308
309     pScrn->chipset = (char *)xf86TokenToString(DUMMYChipsets,
310                                                DUMMY_CHIP);
311
312     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Chipset is a DUMMY\n");
313     
314     pScrn->monitor = pScrn->confScreen->monitor;
315
316     if (!xf86SetDepthBpp(pScrn, 0, 0, 0,  Support24bppFb | Support32bppFb))
317         return FALSE;
318     else {
319         /* Check that the returned depth is one we support */
320         switch (pScrn->depth) {
321         case 8:
322         case 15:
323         case 16:
324         case 24:
325             break;
326         default:
327             xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
328                        "Given depth (%d) is not supported by this driver\n",
329                        pScrn->depth);
330             return FALSE;
331         }
332     }
333
334     xf86PrintDepthBpp(pScrn);
335     if (pScrn->depth == 8)
336         pScrn->rgbBits = 8;
337
338     /* Get the depth24 pixmap format */
339     if (pScrn->depth == 24 && pix24bpp == 0)
340         pix24bpp = xf86GetBppFromDepth(pScrn, 24);
341
342     /*
343      * This must happen after pScrn->display has been set because
344      * xf86SetWeight references it.
345      */
346     if (pScrn->depth > 8) {
347         /* The defaults are OK for us */
348         rgb zeros = {0, 0, 0};
349
350         if (!xf86SetWeight(pScrn, zeros, zeros)) {
351             return FALSE;
352         } else {
353             /* XXX check that weight returned is supported */
354             ;
355         }
356     }
357
358     if (!xf86SetDefaultVisual(pScrn, -1)) 
359         return FALSE;
360
361     if (pScrn->depth > 1) {
362         Gamma zeros = {0.0, 0.0, 0.0};
363
364         if (!xf86SetGamma(pScrn, zeros))
365             return FALSE;
366     }
367
368     xf86CollectOptions(pScrn, device->options);
369     /* Process the options */
370     if (!(dPtr->Options = malloc(sizeof(DUMMYOptions))))
371         return FALSE;
372     memcpy(dPtr->Options, DUMMYOptions, sizeof(DUMMYOptions));
373
374     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, dPtr->Options);
375
376     xf86GetOptValBool(dPtr->Options, OPTION_SW_CURSOR,&dPtr->swCursor);
377
378     if (device->videoRam != 0) {
379         pScrn->videoRam = device->videoRam;
380         xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "VideoRAM: %d kByte\n",
381                    pScrn->videoRam);
382     } else {
383         pScrn->videoRam = 4096;
384         xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kByte\n",
385                    pScrn->videoRam);
386     }
387     
388     if (device->dacSpeeds[0] != 0) {
389         maxClock = device->dacSpeeds[0];
390         xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Max Clock: %d kHz\n",
391                    maxClock);
392     } else {
393         xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Max Clock: %d kHz\n",
394                    maxClock);
395     }
396
397     pScrn->progClock = TRUE;
398     /*
399      * Setup the ClockRanges, which describe what clock ranges are available,
400      * and what sort of modes they can be used for.
401      */
402     clockRanges = (ClockRangePtr)xnfcalloc(sizeof(ClockRange), 1);
403     clockRanges->next = NULL;
404     clockRanges->ClockMulFactor = 1;
405     clockRanges->minClock = 11000;   /* guessed ยงยงยง */
406     clockRanges->maxClock = 300000;
407     clockRanges->clockIndex = -1;               /* programmable */
408     clockRanges->interlaceAllowed = TRUE; 
409     clockRanges->doubleScanAllowed = TRUE;
410
411     /* Subtract memory for HW cursor */
412
413
414     {
415         int apertureSize = (pScrn->videoRam * 1024);
416         i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
417                               pScrn->display->modes, clockRanges,
418                               NULL, 256, DUMMY_MAX_WIDTH,
419                               (8 * pScrn->bitsPerPixel),
420                               128, DUMMY_MAX_HEIGHT, pScrn->display->virtualX,
421                               pScrn->display->virtualY, apertureSize,
422                               LOOKUP_BEST_REFRESH);
423
424        if (i == -1)
425            RETURN;
426     }
427
428     /* Prune the modes marked as invalid */
429     xf86PruneDriverModes(pScrn);
430
431     if (i == 0 || pScrn->modes == NULL) {
432         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n");
433         RETURN;
434     }
435
436     /*
437      * Set the CRTC parameters for all of the modes based on the type
438      * of mode, and the chipset's interlace requirements.
439      *
440      * Calling this is required if the mode->Crtc* values are used by the
441      * driver and if the driver doesn't provide code to set them.  They
442      * are not pre-initialised at all.
443      */
444     xf86SetCrtcForModes(pScrn, 0); 
445  
446     /* Set the current mode to the first in the list */
447     pScrn->currentMode = pScrn->modes;
448
449     /* Print the list of modes being used */
450     xf86PrintModes(pScrn);
451
452     /* If monitor resolution is set on the command line, use it */
453     xf86SetDpi(pScrn, 0, 0);
454
455     if (xf86LoadSubModule(pScrn, "fb") == NULL) {
456         RETURN;
457     }
458
459     if (!dPtr->swCursor) {
460         if (!xf86LoadSubModule(pScrn, "ramdac"))
461             RETURN;
462     }
463     
464     /* We have no contiguous physical fb in physical memory */
465     pScrn->memPhysBase = 0;
466     pScrn->fbOffset = 0;
467
468 printf("preinit endsss");
469     return TRUE;
470 }
471 #undef RETURN
472
473 /* Mandatory */
474 static Bool
475 DUMMYEnterVT(VT_FUNC_ARGS_DECL)
476 {
477 printf("entervt startssss");
478     SCRN_INFO_PTR(arg);
479     
480     /* Should we re-save the text mode on each VT enter? */
481     if(!dummyModeInit(pScrn, pScrn->currentMode))
482       return FALSE;
483
484     DUMMYAdjustFrame(ADJUST_FRAME_ARGS(pScrn, pScrn->frameX0, pScrn->frameY0));
485
486 printf("entervt endsss");
487     return TRUE;
488 }
489
490 /* Mandatory */
491 static void
492 DUMMYLeaveVT(VT_FUNC_ARGS_DECL)
493 {
494 printf("leavevt starts");
495     SCRN_INFO_PTR(arg);
496     dummyRestore(pScrn, TRUE);
497
498 printf("leavevt ends");
499 }
500
501 static void
502 DUMMYLoadPalette(
503    ScrnInfoPtr pScrn,
504    int numColors,
505    int *indices,
506    LOCO *colors,
507    VisualPtr pVisual
508 ){
509    int i, index, shift, Gshift;
510    DUMMYPtr dPtr = DUMMYPTR(pScrn);
511
512    switch(pScrn->depth) {
513    case 15:     
514         shift = Gshift = 1;
515         break;
516    case 16:
517         shift = 0; 
518         Gshift = 0;
519         break;
520    default:
521         shift = Gshift = 0;
522         break;
523    }
524
525    for(i = 0; i < numColors; i++) {
526        index = indices[i];
527        dPtr->colors[index].red = colors[index].red << shift;
528        dPtr->colors[index].green = colors[index].green << Gshift;
529        dPtr->colors[index].blue = colors[index].blue << shift;
530    } 
531
532 }
533
534 static ScrnInfoPtr DUMMYScrn; /* static-globalize it */
535
536 /* Mandatory */
537 static Bool
538 DUMMYScreenInit(SCREEN_INIT_ARGS_DECL)
539 {
540 printf("screeninit startsssss");
541     ScrnInfoPtr pScrn;
542     DUMMYPtr dPtr;
543     int ret;
544     VisualPtr visual;
545     
546     /*
547      * we need to get the ScrnInfoRec for this screen, so let's allocate
548      * one first thing
549      */
550     pScrn = xf86ScreenToScrn(pScreen);
551     dPtr = DUMMYPTR(pScrn);
552     DUMMYScrn = pScrn;
553
554     int fd = open("/dev/mem", O_RDWR | O_SYNC);
555
556     if (fd<0) {
557        perror("Cannot open /dev/mem");
558        return -1;
559     } 
560     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "This is Ruba's driver \n");
561
562     unsigned char *mem = mmap(NULL, PARAGRAPH_LEN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, PARAGRAPH_PADDR);
563
564     if (mem == MAP_FAILED) {
565       perror("Can't map memory");
566       return -1;
567     } else {
568       printf("Mapped to 0x%p (%d bytes)\n", mem, PARAGRAPH_LEN);
569     }
570
571     if (pScrn->videoRam * 1024 > 1024 * 1024 * 4) {
572         perror("Error but keep going");
573         
574         xf86DrvMsg(pScrn->scrnIndex, X_INFO, "pScrn-> videoRAM is greater than 4MB but keep going\n");
575         }
576
577     dPtr->FBBase = mem;
578     
579     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBBase is set to %p \n", dPtr->FBBase);
580 /*
581      * next we save the current state and setup the first mode
582      */
583     dummySave(pScrn);
584     
585     if (!dummyModeInit(pScrn,pScrn->currentMode))
586         return FALSE;
587     DUMMYAdjustFrame(ADJUST_FRAME_ARGS(pScrn, pScrn->frameX0, pScrn->frameY0));
588
589     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Adjust Frame function called, frameX0 is %d, frame Y0 is %d\n", pScrn->frameX0, pScrn->frameY0);
590     /*
591      * Reset visual list.
592      */
593     miClearVisualTypes();
594     
595     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "miClearVisualTypes called\n");
596     /* Setup the visuals we support. */
597     
598     if (!miSetVisualTypes(pScrn->depth,
599                       miGetDefaultVisualMask(pScrn->depth),
600                       pScrn->rgbBits, pScrn->defaultVisual))
601          return FALSE;
602
603     if (!miSetPixmapDepths ()) return FALSE;
604
605     /*
606      * Call the framebuffer layer's ScreenInit function, and fill in other
607      * pScreen fields.
608      */
609     ret = fbScreenInit(pScreen, dPtr->FBBase,
610                             pScrn->virtualX, pScrn->virtualY,
611                             pScrn->xDpi, pScrn->yDpi,
612                             pScrn->displayWidth, pScrn->bitsPerPixel);
613
614
615     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBBase before FBScreenInit is set to %p \n", dPtr->FBBase);
616     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "pScreen depth is %d \n", pScrn->depth);
617     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBScreenInit is called\n");
618     if (!ret)
619         return FALSE;
620
621     if (pScrn->depth > 8) {
622         /* Fixup RGB ordering */
623         visual = pScreen->visuals + pScreen->numVisuals;
624         while (--visual >= pScreen->visuals) {
625             if ((visual->class | DynamicClass) == DirectColor) {
626                 visual->offsetRed = pScrn->offset.red;
627                 visual->offsetGreen = pScrn->offset.green;
628                 visual->offsetBlue = pScrn->offset.blue;
629                 visual->redMask = pScrn->mask.red;
630                 visual->greenMask = pScrn->mask.green;
631                 visual->blueMask = pScrn->mask.blue;
632             }
633         }
634     }
635     
636     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBBase after fbScreenInit is set to %p \n", dPtr->FBBase);
637     /* must be after RGB ordering fixed */
638
639     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBBase before fbPictureInit is set to %p \n", dPtr->FBBase);
640     fbPictureInit(pScreen, 0, 0);
641
642     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBBase after fbPictureInit is set to %p \n", dPtr->FBBase);
643     xf86SetBlackWhitePixels(pScreen);
644
645 #ifdef USE_DGA
646     DUMMYDGAInit(pScreen);
647 #endif
648     
649     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBBase before checking software cursor is set to %p \n", dPtr->FBBase);
650     if (dPtr->swCursor)
651         xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using Software Cursor.\n");
652
653     {
654
655          
656         BoxRec AvailFBArea;
657         int lines = pScrn->videoRam * 1024 /
658             (pScrn->displayWidth * (pScrn->bitsPerPixel >> 3));
659         AvailFBArea.x1 = 0;
660         AvailFBArea.y1 = 0;
661         AvailFBArea.x2 = pScrn->displayWidth;
662         AvailFBArea.y2 = lines;
663
664     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBBase before InitFBManager is set to %p \n", dPtr->FBBase);
665         xf86InitFBManager(pScreen, &AvailFBArea); 
666         
667     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBBase after InitFBManager is set to %p \n", dPtr->FBBase);
668         xf86DrvMsg(pScrn->scrnIndex, X_INFO, 
669                    "Using %i scanlines of offscreen memory \n"
670                    , lines - pScrn->virtualY);
671     }
672
673     xf86SetBackingStore(pScreen);
674     xf86SetSilkenMouse(pScreen);
675         
676     /* Initialise cursor functions */
677     miDCInitialize (pScreen, xf86GetPointerScreenFuncs());
678
679
680     if (!dPtr->swCursor) {
681       /* HW cursor functions */
682       if (!DUMMYCursorInit(pScreen)) {
683           xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
684                      "Hardware cursor initialization failed\n");
685           return FALSE;
686       }
687     }
688     
689     /* Initialise default colourmap */
690     if(!miCreateDefColormap(pScreen))
691         return FALSE;
692
693     if (!xf86HandleColormaps(pScreen, 256, pScrn->rgbBits,
694                          DUMMYLoadPalette, NULL, 
695                          CMAP_PALETTED_TRUECOLOR 
696                              | CMAP_RELOAD_ON_MODE_SWITCH))
697         return FALSE;
698
699 /*     DUMMYInitVideo(pScreen); */
700
701     pScreen->SaveScreen = DUMMYSaveScreen;
702
703     
704     /* Wrap the current CloseScreen function */
705     dPtr->CloseScreen = pScreen->CloseScreen;
706     pScreen->CloseScreen = DUMMYCloseScreen;
707
708     /* Wrap the current CreateWindow function */
709     dPtr->CreateWindow = pScreen->CreateWindow;
710     pScreen->CreateWindow = DUMMYCreateWindow;
711
712     /* Report any unused options (only for the first generation) */
713     if (serverGeneration == 1) {
714         xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
715     }
716
717     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FBBase before ScreenInit returns is set to %p \n", dPtr->FBBase);
718     return TRUE;
719 }
720
721 /* Mandatory */
722 Bool
723 DUMMYSwitchMode(SWITCH_MODE_ARGS_DECL)
724 {
725     SCRN_INFO_PTR(arg);
726     return dummyModeInit(pScrn, mode);
727 }
728
729 /* Mandatory */
730 void
731 DUMMYAdjustFrame(ADJUST_FRAME_ARGS_DECL)
732 {
733
734     xf86DrvMsg(0, X_INFO, "Adjust frame function starts\n");
735     SCRN_INFO_PTR(arg);
736     int Base; 
737
738     Base = (y * pScrn->displayWidth + x) >> 2;
739
740     /* Scale Base by the number of bytes per pixel. */
741     switch (pScrn->depth) {
742     case  8 :
743         break;
744     case 15 :
745     case 16 :
746         Base *= 2;
747         break;
748     case 24 :
749         Base *= 3;
750         break;
751     default :
752         break;
753     }
754
755     xf86DrvMsg(pScrn->depth, X_INFO, "Adjust frame function ends, base is %d\n", Base);
756 }
757
758 /* Mandatory */
759 static Bool
760 DUMMYCloseScreen(CLOSE_SCREEN_ARGS_DECL)
761 {
762
763     xf86DrvMsg(0, X_INFO, "Close screen begins\n");
764     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
765     DUMMYPtr dPtr = DUMMYPTR(pScrn);
766
767     if(pScrn->vtSema){
768         dummyRestore(pScrn, TRUE);
769         free(dPtr->FBBase);
770     }
771
772     if (dPtr->CursorInfo)
773         xf86DestroyCursorInfoRec(dPtr->CursorInfo);
774
775     pScrn->vtSema = FALSE;
776     pScreen->CloseScreen = dPtr->CloseScreen;
777     return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS);
778
779     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "close screen function ends\n");
780 }
781
782 /* Optional */
783 static void
784 DUMMYFreeScreen(FREE_SCREEN_ARGS_DECL)
785 {
786
787     xf86DrvMsg(1, X_INFO, "free screen function begins\n");
788     SCRN_INFO_PTR(arg);
789     DUMMYFreeRec(pScrn);
790
791     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "free screen function ends\n");
792 }
793
794 static Bool
795 DUMMYSaveScreen(ScreenPtr pScreen, int mode)
796 {
797
798     xf86DrvMsg(2, X_INFO, "save screen function begins\n");
799     ScrnInfoPtr pScrn = NULL;
800     DUMMYPtr dPtr;
801
802     if (pScreen != NULL) {
803         pScrn = xf86ScreenToScrn(pScreen);
804         dPtr = DUMMYPTR(pScrn);
805
806         dPtr->screenSaver = xf86IsUnblank(mode);
807     }
808  
809     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "save screen function ends\n");
810     return TRUE;
811 }
812
813 /* Optional */
814 static ModeStatus
815 DUMMYValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
816 {
817
818     xf86DrvMsg(3, X_INFO, "valid mode function\n");
819     return(MODE_OK);
820 }
821
822 static void
823 dummySave(ScrnInfoPtr pScrn)
824 {
825 }
826
827 static void 
828 dummyRestore(ScrnInfoPtr pScrn, Bool restoreText)
829 {
830 }
831     
832 static Bool
833 dummyModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
834 {
835
836     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "mode init/ restore function beginss\n");
837     dummyRestore(pScrn, FALSE);
838     
839     xf86DrvMsg(pScrn->scrnIndex, X_INFO, " mode init / function ends\n");
840     return(TRUE);
841 }
842
843 Atom VFB_PROP  = 0;
844 #define  VFB_PROP_NAME  "VFB_IDENT"
845
846 static Bool
847 DUMMYCreateWindow(WindowPtr pWin)
848 {
849
850     xf86DrvMsg(0, X_INFO, "create screen function begins\n");
851     ScreenPtr pScreen = pWin->drawable.pScreen;
852     DUMMYPtr dPtr = DUMMYPTR(DUMMYScrn);
853     WindowPtr pWinRoot;
854     int ret;
855
856     pScreen->CreateWindow = dPtr->CreateWindow;
857     ret = pScreen->CreateWindow(pWin);
858     dPtr->CreateWindow = pScreen->CreateWindow;
859     pScreen->CreateWindow = DUMMYCreateWindow;
860
861     xf86DrvMsg(0, X_INFO, "ret value in create window is %d\n", ret);
862     if(ret != TRUE)
863         return(ret);
864         
865     if(dPtr->prop == FALSE) {
866 #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 8
867         pWinRoot = WindowTable[DUMMYScrn->pScreen->myNum];
868 #else
869         pWinRoot = DUMMYScrn->pScreen->root;
870 #endif
871         if (! ValidAtom(VFB_PROP))
872             VFB_PROP = MakeAtom(VFB_PROP_NAME, strlen(VFB_PROP_NAME), 1);
873
874         ret = ChangeWindowProperty(pWinRoot, VFB_PROP, XA_STRING, 
875                 8, PropModeReplace, (int)4, (pointer)"TRUE", FALSE);
876         if( ret != Success)
877                 ErrorF("Could not set VFB root window property");
878         dPtr->prop = TRUE;
879
880         return TRUE;
881     }
882     return TRUE;
883 }
884
885 #ifndef HW_SKIP_CONSOLE
886 #define HW_SKIP_CONSOLE 4
887 #endif
888
889 static Bool
890 dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer ptr)
891 {
892     CARD32 *flag;
893     
894     switch (op) {
895         case GET_REQUIRED_HW_INTERFACES:
896             flag = (CARD32*)ptr;
897             (*flag) = HW_SKIP_CONSOLE;
898             return TRUE;
899         default:
900             return FALSE;
901     }
902 }