cg6_driver.c revision 404274b3
1/*
2 * GX and Turbo GX framebuffer driver.
3 *
4 * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28/* need this for PRIxPTR macro */
29#include <machine/int_fmtio.h>
30
31#include <string.h>
32
33#include "xf86.h"
34#include "xf86_OSproc.h"
35#include "mipointer.h"
36#include "mibstore.h"
37#include "micmap.h"
38
39#include "fb.h"
40#include "xf86cmap.h"
41#include "cg6.h"
42
43static const OptionInfoRec * CG6AvailableOptions(int chipid, int busid);
44static void	CG6Identify(int flags);
45static Bool	CG6Probe(DriverPtr drv, int flags);
46static Bool	CG6PreInit(ScrnInfoPtr pScrn, int flags);
47static Bool	CG6ScreenInit(int Index, ScreenPtr pScreen, int argc,
48			      char **argv);
49static Bool	CG6EnterVT(int scrnIndex, int flags);
50static void	CG6LeaveVT(int scrnIndex, int flags);
51static Bool	CG6CloseScreen(int scrnIndex, ScreenPtr pScreen);
52static Bool	CG6SaveScreen(ScreenPtr pScreen, int mode);
53
54/* Required if the driver supports mode switching */
55static Bool	CG6SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
56/* Required if the driver supports moving the viewport */
57static void	CG6AdjustFrame(int scrnIndex, int x, int y, int flags);
58
59/* Optional functions */
60static void	CG6FreeScreen(int scrnIndex, int flags);
61static ModeStatus CG6ValidMode(int scrnIndex, DisplayModePtr mode,
62			       Bool verbose, int flags);
63
64static Bool CG6DriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,
65				pointer ptr);
66
67#define CG6_VERSION 4000
68#define CG6_NAME "SUNCG6"
69#define CG6_DRIVER_NAME "suncg6"
70#define CG6_MAJOR_VERSION PACKAGE_VERSION_MAJOR
71#define CG6_MINOR_VERSION PACKAGE_VERSION_MINOR
72#define CG6_PATCHLEVEL PACKAGE_VERSION_PATCHLEVEL
73
74/*
75 * This contains the functions needed by the server after loading the driver
76 * module.  It must be supplied, and gets passed back by the SetupProc
77 * function in the dynamic case.  In the static case, a reference to this
78 * is compiled in, and this requires that the name of this DriverRec be
79 * an upper-case version of the driver name.
80 */
81
82_X_EXPORT DriverRec SUNCG6 = {
83    CG6_VERSION,
84    CG6_DRIVER_NAME,
85    CG6Identify,
86    CG6Probe,
87    CG6AvailableOptions,
88    NULL,
89    0,
90    CG6DriverFunc
91};
92
93typedef enum {
94    OPTION_SW_CURSOR,
95    OPTION_HW_CURSOR,
96    OPTION_NOACCEL
97} CG6Opts;
98
99static const OptionInfoRec CG6Options[] = {
100    { OPTION_SW_CURSOR,		"SWcursor",	OPTV_BOOLEAN,	{0}, FALSE },
101    { OPTION_HW_CURSOR,		"HWcursor",	OPTV_BOOLEAN,	{0}, FALSE },
102    { OPTION_NOACCEL,		"NoAccel",	OPTV_BOOLEAN,	{0}, FALSE },
103    { -1,			NULL,		OPTV_NONE,	{0}, FALSE }
104};
105
106static const char *xaaSymbols[] =
107{
108    "XAACreateInfoRec",
109    "XAADestroyInfoRec",
110    "XAAInit",
111    NULL
112};
113
114#ifdef XFree86LOADER
115
116static MODULESETUPPROTO(cg6Setup);
117
118static XF86ModuleVersionInfo suncg6VersRec =
119{
120	"suncg6",
121	MODULEVENDORSTRING,
122	MODINFOSTRING1,
123	MODINFOSTRING2,
124	XORG_VERSION_CURRENT,
125	CG6_MAJOR_VERSION, CG6_MINOR_VERSION, CG6_PATCHLEVEL,
126	ABI_CLASS_VIDEODRV,
127	ABI_VIDEODRV_VERSION,
128	MOD_CLASS_VIDEODRV,
129	{0,0,0,0}
130};
131
132_X_EXPORT XF86ModuleData suncg6ModuleData = { &suncg6VersRec, cg6Setup, NULL };
133
134pointer
135cg6Setup(pointer module, pointer opts, int *errmaj, int *errmin)
136{
137    static Bool setupDone = FALSE;
138
139    if (!setupDone) {
140	setupDone = TRUE;
141	xf86AddDriver(&SUNCG6, module, HaveDriverFuncs);
142
143	/*
144	 * Modules that this driver always requires can be loaded here
145	 * by calling LoadSubModule().
146	 */
147
148	/*
149	 * The return value must be non-NULL on success even though there
150	 * is no TearDownProc.
151	 */
152	return (pointer)TRUE;
153    } else {
154	if (errmaj) *errmaj = LDR_ONCEONLY;
155	return NULL;
156    }
157}
158
159#endif /* XFree86LOADER */
160
161static Bool
162CG6GetRec(ScrnInfoPtr pScrn)
163{
164    /*
165     * Allocate an Cg6Rec, and hook it into pScrn->driverPrivate.
166     * pScrn->driverPrivate is initialised to NULL, so we can check if
167     * the allocation has already been done.
168     */
169    if (pScrn->driverPrivate != NULL)
170	return TRUE;
171
172    pScrn->driverPrivate = xnfcalloc(sizeof(Cg6Rec), 1);
173    return TRUE;
174}
175
176static void
177CG6FreeRec(ScrnInfoPtr pScrn)
178{
179    Cg6Ptr pCg6;
180
181    if (pScrn->driverPrivate == NULL)
182	return;
183
184    pCg6 = GET_CG6_FROM_SCRN(pScrn);
185
186    xfree(pScrn->driverPrivate);
187    pScrn->driverPrivate = NULL;
188
189    return;
190}
191
192static const OptionInfoRec *
193CG6AvailableOptions(int chipid, int busid)
194{
195    return CG6Options;
196}
197
198/* Mandatory */
199static void
200CG6Identify(int flags)
201{
202    xf86Msg(X_INFO, "%s: driver for CGsix (GX and Turbo GX)\n", CG6_NAME);
203}
204
205
206/* Mandatory */
207static Bool
208CG6Probe(DriverPtr drv, int flags)
209{
210    int i;
211    GDevPtr *devSections;
212    int *usedChips;
213    int numDevSections;
214    int numUsed;
215    Bool foundScreen = FALSE;
216    EntityInfoPtr pEnt;
217
218    /*
219     * The aim here is to find all cards that this driver can handle,
220     * and for the ones not already claimed by another driver, claim the
221     * slot, and allocate a ScrnInfoRec.
222     *
223     * This should be a minimal probe, and it should under no circumstances
224     * change the state of the hardware.  Because a device is found, don't
225     * assume that it will be used.  Don't do any initialisations other than
226     * the required ScrnInfoRec initialisations.  Don't allocate any new
227     * data structures.
228     */
229
230    /*
231     * Next we check, if there has been a chipset override in the config file.
232     * For this we must find out if there is an active device section which
233     * is relevant, i.e., which has no driver specified or has THIS driver
234     * specified.
235     */
236
237    if ((numDevSections = xf86MatchDevice(CG6_DRIVER_NAME,
238					  &devSections)) <= 0) {
239	/*
240	 * There's no matching device section in the config file, so quit
241	 * now.
242	 */
243	return FALSE;
244    }
245
246    /*
247     * We need to probe the hardware first.  We then need to see how this
248     * fits in with what is given in the config file, and allow the config
249     * file info to override any contradictions.
250     */
251
252    numUsed = xf86MatchSbusInstances(CG6_NAME, SBUS_DEVICE_CG6,
253		   devSections, numDevSections,
254		   drv, &usedChips);
255
256    xfree(devSections);
257    if (numUsed <= 0)
258	return FALSE;
259
260    if (flags & PROBE_DETECT)
261	foundScreen = TRUE;
262    else for (i = 0; i < numUsed; i++) {
263	pEnt = xf86GetEntityInfo(usedChips[i]);
264
265	/*
266	 * Check that nothing else has claimed the slots.
267	 */
268	if(pEnt->active) {
269	    ScrnInfoPtr pScrn;
270
271	    /* Allocate a ScrnInfoRec and claim the slot */
272	    pScrn = xf86AllocateScreen(drv, 0);
273
274	    /* Fill in what we can of the ScrnInfoRec */
275	    pScrn->driverVersion = CG6_VERSION;
276	    pScrn->driverName	 = CG6_DRIVER_NAME;
277	    pScrn->name		 = CG6_NAME;
278	    pScrn->Probe	 = CG6Probe;
279	    pScrn->PreInit	 = CG6PreInit;
280	    pScrn->ScreenInit	 = CG6ScreenInit;
281  	    pScrn->SwitchMode	 = CG6SwitchMode;
282  	    pScrn->AdjustFrame	 = CG6AdjustFrame;
283	    pScrn->EnterVT	 = CG6EnterVT;
284	    pScrn->LeaveVT	 = CG6LeaveVT;
285	    pScrn->FreeScreen	 = CG6FreeScreen;
286	    pScrn->ValidMode	 = CG6ValidMode;
287	    xf86AddEntityToScreen(pScrn, pEnt->index);
288	    foundScreen = TRUE;
289	}
290	xfree(pEnt);
291    }
292    xfree(usedChips);
293    return foundScreen;
294}
295
296/* Mandatory */
297static Bool
298CG6PreInit(ScrnInfoPtr pScrn, int flags)
299{
300    Cg6Ptr pCg6;
301    sbusDevicePtr psdp;
302    MessageType from;
303    int i;
304
305    if (flags & PROBE_DETECT) return FALSE;
306
307    /*
308     * Note: This function is only called once at server startup, and
309     * not at the start of each server generation.  This means that
310     * only things that are persistent across server generations can
311     * be initialised here.  xf86Screens[] is (pScrn is a pointer to one
312     * of these).  Privates allocated using xf86AllocateScrnInfoPrivateIndex()
313     * are too, and should be used for data that must persist across
314     * server generations.
315     *
316     * Per-generation data should be allocated with
317     * AllocateScreenPrivateIndex() from the ScreenInit() function.
318     */
319
320    /* Allocate the Cg6Rec driverPrivate */
321    if (!CG6GetRec(pScrn)) {
322	return FALSE;
323    }
324    pCg6 = GET_CG6_FROM_SCRN(pScrn);
325
326    /* Set pScrn->monitor */
327    pScrn->monitor = pScrn->confScreen->monitor;
328
329    /* This driver doesn't expect more than one entity per screen */
330    if (pScrn->numEntities > 1)
331	return FALSE;
332    /* This is the general case */
333    for (i = 0; i < pScrn->numEntities; i++) {
334	EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[i]);
335
336	/* CG6 is purely SBUS */
337	if (pEnt->location.type == BUS_SBUS) {
338	    psdp = xf86GetSbusInfoForEntity(pEnt->index);
339	    pCg6->psdp = psdp;
340	} else
341	    return FALSE;
342    }
343
344    /*********************
345    deal with depth
346    *********************/
347
348    if (!xf86SetDepthBpp(pScrn, 8, 0, 0, NoDepth24Support)) {
349	return FALSE;
350    } else {
351	/* Check that the returned depth is one we support */
352	switch (pScrn->depth) {
353	case 8:
354	    /* OK */
355	    break;
356	default:
357	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
358		       "Given depth (%d) is not supported by this driver\n",
359		       pScrn->depth);
360	    return FALSE;
361	}
362    }
363
364    /* Collect all of the relevant option flags (fill in pScrn->options) */
365    xf86CollectOptions(pScrn, NULL);
366    /* Process the options */
367    if (!(pCg6->Options = xalloc(sizeof(CG6Options))))
368	return FALSE;
369    memcpy(pCg6->Options, CG6Options, sizeof(CG6Options));
370    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pCg6->Options);
371
372    if (!xf86SetDefaultVisual(pScrn, -1))
373	return FALSE;
374
375    /*
376     * The new cmap code requires this to be initialised.
377     */
378
379    {
380	Gamma zeros = {0.0, 0.0, 0.0};
381
382	if (!xf86SetGamma(pScrn, zeros)) {
383	    return FALSE;
384	}
385    }
386
387    /* Set the bits per RGB for 8bpp mode */
388    from = X_DEFAULT;
389
390    /* determine whether we use hardware or software cursor */
391
392    pCg6->HWCursor = TRUE;
393    if (xf86GetOptValBool(pCg6->Options, OPTION_HW_CURSOR, &pCg6->HWCursor))
394	from = X_CONFIG;
395    if (xf86ReturnOptValBool(pCg6->Options, OPTION_SW_CURSOR, FALSE)) {
396	from = X_CONFIG;
397	pCg6->HWCursor = FALSE;
398    }
399
400    xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
401		pCg6->HWCursor ? "HW" : "SW");
402
403    if (xf86ReturnOptValBool(pCg6->Options, OPTION_NOACCEL, FALSE)) {
404	pCg6->NoAccel = TRUE;
405	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
406    }
407
408    if (xf86LoadSubModule(pScrn, "fb") == NULL) {
409	CG6FreeRec(pScrn);
410	return FALSE;
411    }
412
413    if (pCg6->HWCursor && xf86LoadSubModule(pScrn, "ramdac") == NULL) {
414	CG6FreeRec(pScrn);
415	return FALSE;
416    }
417
418    if (pCg6->HWCursor && xf86LoadSubModule(pScrn, "xaa") == NULL) {
419        CG6FreeRec(pScrn);
420        return FALSE;
421    }
422
423    /*********************
424    set up clock and mode stuff
425    *********************/
426
427    pScrn->progClock = TRUE;
428
429    if(pScrn->display->virtualX || pScrn->display->virtualY) {
430	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
431		   "CG6 does not support a virtual desktop\n");
432	pScrn->display->virtualX = 0;
433	pScrn->display->virtualY = 0;
434    }
435
436    xf86SbusUseBuiltinMode(pScrn, pCg6->psdp);
437    pScrn->currentMode = pScrn->modes;
438    pScrn->displayWidth = pScrn->virtualX;
439
440    /* Set display resolution */
441    xf86SetDpi(pScrn, 0, 0);
442
443    return TRUE;
444}
445
446/* Mandatory */
447
448/* This gets called at the start of each server generation */
449
450static Bool
451CG6ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
452{
453    ScrnInfoPtr pScrn;
454    Cg6Ptr pCg6;
455    sbusDevicePtr psdp;
456    int ret;
457
458    /*
459     * First get the ScrnInfoRec
460     */
461    pScrn = xf86Screens[pScreen->myNum];
462    pCg6 = GET_CG6_FROM_SCRN(pScrn);
463    psdp = pCg6->psdp;
464
465    /* Map the CG6 memory */
466
467    pCg6->fbc = xf86MapSbusMem(psdp, CG6_FBC_VOFF, sizeof(*pCg6->fbc));
468    pCg6->thc = xf86MapSbusMem(psdp, CG6_THC_VOFF, sizeof(*pCg6->thc));
469
470    /*
471     * XXX need something better here - we rely on the OS to allow mmap()ing
472     * usable VRAM ONLY. Works with NetBSD, may crash and burn on other OSes.
473     */
474    pCg6->vidmem = 2 * 1024 * 1024;
475    pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
476
477    if (pCg6->fb == NULL) {
478        /* mapping 2MB failed - try 1MB */
479        pCg6->vidmem = 1024 * 1024;
480        pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
481    }
482
483    if (pCg6->fb == NULL) {
484        /* we can't map all video RAM - fall back to width*height */
485        pCg6->vidmem = psdp->width * psdp->height;
486        pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
487    }
488
489    if (pCg6->fb != NULL) {
490        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "mapped %d KB video RAM\n",
491            pCg6->vidmem >> 10);
492    }
493
494    if (!pCg6->fbc || !pCg6->thc || !pCg6->fb) {
495        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
496                   "xf86MapSbusMem failed fbc:%" PRIxPTR " fb:%" PRIxPTR
497                   " thc:%" PRIxPTR "\n",
498                   pCg6->fbc, pCg6->fb, pCg6->thc );
499
500        if (pCg6->fbc) {
501            xf86UnmapSbusMem(psdp, pCg6->fbc, sizeof(*pCg6->fbc));
502            pCg6->fbc = NULL;
503        }
504
505        if (pCg6->thc) {
506            xf86UnmapSbusMem(psdp, pCg6->thc, sizeof(*pCg6->thc));
507            pCg6->thc = NULL;
508        }
509
510        if (pCg6->fb) {
511            xf86UnmapSbusMem(psdp, pCg6->fb, pCg6->vidmem);
512            pCg6->fb = NULL;
513        }
514
515        return FALSE;
516    }
517
518    /* Darken the screen for aesthetic reasons and set the viewport */
519    CG6SaveScreen(pScreen, SCREEN_SAVER_ON);
520
521    /*
522     * The next step is to setup the screen's visuals, and initialise the
523     * framebuffer code.  In cases where the framebuffer's default
524     * choices for things like visual layouts and bits per RGB are OK,
525     * this may be as simple as calling the framebuffer's ScreenInit()
526     * function.  If not, the visuals will need to be setup before calling
527     * a fb ScreenInit() function and fixed up after.
528     */
529
530    /*
531     * Reset visual list.
532     */
533    miClearVisualTypes();
534
535    /* Set the bits per RGB for 8bpp mode */
536    pScrn->rgbBits = 8;
537
538    /* Setup the visuals we support. */
539
540    if (!miSetVisualTypes(pScrn->depth, miGetDefaultVisualMask(pScrn->depth),
541			  pScrn->rgbBits, pScrn->defaultVisual))
542	return FALSE;
543
544    miSetPixmapDepths ();
545
546    /*
547     * Call the framebuffer layer's ScreenInit function, and fill in other
548     * pScreen fields.
549     */
550
551    ret = fbScreenInit(pScreen, pCg6->fb, pScrn->virtualX,
552		       pScrn->virtualY, pScrn->xDpi, pScrn->yDpi,
553		       pScrn->virtualX, 8);
554    if (!ret)
555	return FALSE;
556
557    pCg6->width = pScrn->virtualX;
558    pCg6->height = pScrn->virtualY;
559    pCg6->maxheight = (pCg6->vidmem / pCg6->width) & 0xffff;
560
561    fbPictureInit (pScreen, 0, 0);
562
563    miInitializeBackingStore(pScreen);
564    xf86SetBackingStore(pScreen);
565    xf86SetSilkenMouse(pScreen);
566
567    xf86SetBlackWhitePixels(pScreen);
568
569    if (!pCg6->NoAccel) {
570        BoxRec bx;
571        pCg6->pXAA=XAACreateInfoRec();
572        CG6AccelInit(pScrn);
573        bx.x1=bx.y1=0;
574        bx.x2=pCg6->width;
575        bx.y2=pCg6->maxheight;
576        xf86InitFBManager(pScreen,&bx);
577        if(!XAAInit(pScreen, pCg6->pXAA))
578            return FALSE;
579
580        xf86Msg(X_INFO, "%s: Using acceleration\n", pCg6->psdp->device);
581    }
582
583    /* setup DGA */
584    Cg6DGAInit(pScreen);
585
586
587    /* Initialise cursor functions */
588    miDCInitialize (pScreen, xf86GetPointerScreenFuncs());
589
590    /* Initialize HW cursor layer.
591       Must follow software cursor initialization*/
592    if (pCg6->HWCursor) {
593	extern Bool CG6HWCursorInit(ScreenPtr pScreen);
594
595	if(!CG6HWCursorInit(pScreen)) {
596	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
597		       "Hardware cursor initialization failed\n");
598	    return(FALSE);
599	}
600	xf86SbusHideOsHwCursor(pCg6->psdp);
601    }
602
603    /* Initialise default colourmap */
604    if (!miCreateDefColormap(pScreen))
605	return FALSE;
606
607    if(!xf86SbusHandleColormaps(pScreen, pCg6->psdp))
608	return FALSE;
609
610    pCg6->CloseScreen = pScreen->CloseScreen;
611    pScreen->CloseScreen = CG6CloseScreen;
612    pScreen->SaveScreen = CG6SaveScreen;
613
614    /* Report any unused options (only for the first generation) */
615    if (serverGeneration == 1) {
616	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
617    }
618
619    /* unblank the screen */
620    CG6SaveScreen(pScreen, SCREEN_SAVER_OFF);
621
622    /* Done */
623    return TRUE;
624}
625
626
627/* Usually mandatory */
628static Bool
629CG6SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
630{
631    return TRUE;
632}
633
634
635/*
636 * This function is used to initialize the Start Address - the first
637 * displayed location in the video memory.
638 */
639/* Usually mandatory */
640static void
641CG6AdjustFrame(int scrnIndex, int x, int y, int flags)
642{
643    /* we don't support virtual desktops */
644    return;
645}
646
647/*
648 * This is called when VT switching back to the X server.  Its job is
649 * to reinitialise the video mode.
650 */
651
652/* Mandatory */
653static Bool
654CG6EnterVT(int scrnIndex, int flags)
655{
656    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
657    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
658
659    if (pCg6->HWCursor) {
660	xf86SbusHideOsHwCursor (pCg6->psdp);
661	pCg6->CursorFg = 0;
662	pCg6->CursorBg = 0;
663    }
664    return TRUE;
665}
666
667
668/*
669 * This is called when VT switching away from the X server.
670 */
671
672/* Mandatory */
673static void
674CG6LeaveVT(int scrnIndex, int flags)
675{
676    return;
677}
678
679
680/*
681 * This is called at the end of each server generation.  It restores the
682 * original (text) mode.  It should really also unmap the video memory too.
683 */
684
685/* Mandatory */
686static Bool
687CG6CloseScreen(int scrnIndex, ScreenPtr pScreen)
688{
689    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
690    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
691    sbusDevicePtr psdp = pCg6->psdp;
692
693    pScrn->vtSema = FALSE;
694
695    if (pCg6->fbc) {
696        xf86UnmapSbusMem(psdp, pCg6->fbc, sizeof(*pCg6->fbc));
697        pCg6->fbc = NULL;
698    }
699
700    if (pCg6->thc) {
701        xf86UnmapSbusMem(psdp, pCg6->thc, sizeof(*pCg6->thc));
702        pCg6->thc = NULL;
703    }
704
705    if (pCg6->fb) {
706        xf86UnmapSbusMem(psdp, pCg6->fb, pCg6->vidmem);
707        pCg6->fb = NULL;
708    }
709
710    if (pCg6->HWCursor)
711    	xf86SbusHideOsHwCursor(pCg6->psdp);
712
713    pScreen->CloseScreen = pCg6->CloseScreen;
714
715    return (*pScreen->CloseScreen)(scrnIndex, pScreen);
716}
717
718
719/* Free up any per-generation data structures */
720
721/* Optional */
722static void
723CG6FreeScreen(int scrnIndex, int flags)
724{
725    CG6FreeRec(xf86Screens[scrnIndex]);
726}
727
728
729/* Checks if a mode is suitable for the selected chipset. */
730
731/* Optional */
732static ModeStatus
733CG6ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
734{
735    if (mode->Flags & V_INTERLACE)
736	return(MODE_BAD);
737
738    return(MODE_OK);
739}
740
741/* Do screen blanking */
742
743/* Mandatory */
744static Bool
745CG6SaveScreen(ScreenPtr pScreen, int mode)
746{
747    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
748    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
749    unsigned int tmp = pCg6->thc->thc_misc;
750
751    switch(mode)
752    {
753    case SCREEN_SAVER_ON:
754    case SCREEN_SAVER_CYCLE:
755       tmp &= ~CG6_THC_MISC_SYNC_ENAB;
756       break;
757    case SCREEN_SAVER_OFF:
758    case SCREEN_SAVER_FORCER:
759       tmp |= CG6_THC_MISC_SYNC_ENAB;
760       break;
761    default:
762       return FALSE;
763    }
764
765    pCg6->thc->thc_misc = tmp;
766    return TRUE;
767}
768
769static Bool
770CG6DriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,
771    pointer ptr)
772{
773	xorgHWFlags *flag;
774
775	switch (op) {
776	case GET_REQUIRED_HW_INTERFACES:
777		flag = (CARD32*)ptr;
778		(*flag) = HW_MMIO;
779		return TRUE;
780	default:
781		return FALSE;
782	}
783}
784
785