cg6_driver.c revision 7a5333bc
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 "micmap.h"
37
38#include "fb.h"
39#include "xf86cmap.h"
40#include "cg6.h"
41
42#include "compat-api.h"
43
44static const OptionInfoRec * CG6AvailableOptions(int chipid, int busid);
45static void	CG6Identify(int flags);
46static Bool	CG6Probe(DriverPtr drv, int flags);
47static Bool	CG6PreInit(ScrnInfoPtr pScrn, int flags);
48static Bool	CG6ScreenInit(SCREEN_INIT_ARGS_DECL);
49static Bool	CG6EnterVT(VT_FUNC_ARGS_DECL);
50static void	CG6LeaveVT(VT_FUNC_ARGS_DECL);
51static Bool	CG6CloseScreen(CLOSE_SCREEN_ARGS_DECL);
52static Bool	CG6SaveScreen(ScreenPtr pScreen, int mode);
53
54/* Required if the driver supports mode switching */
55static Bool	CG6SwitchMode(SWITCH_MODE_ARGS_DECL);
56/* Required if the driver supports moving the viewport */
57static void	CG6AdjustFrame(ADJUST_FRAME_ARGS_DECL);
58
59/* Optional functions */
60static void	CG6FreeScreen(FREE_SCREEN_ARGS_DECL);
61static ModeStatus CG6ValidMode(SCRN_ARG_TYPE arg, 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    free(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    free(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	free(pEnt);
291    }
292    free(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 = malloc(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(SCREEN_INIT_ARGS_DECL)
452{
453    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
454    Cg6Ptr pCg6;
455    sbusDevicePtr psdp;
456    int ret;
457
458    pCg6 = GET_CG6_FROM_SCRN(pScrn);
459    psdp = pCg6->psdp;
460
461    /* Map the CG6 memory */
462
463    pCg6->fbc = xf86MapSbusMem(psdp, CG6_FBC_VOFF, sizeof(*pCg6->fbc));
464    pCg6->thc = xf86MapSbusMem(psdp, CG6_THC_VOFF, sizeof(*pCg6->thc));
465
466    /*
467     * XXX need something better here - we rely on the OS to allow mmap()ing
468     * usable VRAM ONLY. Works with NetBSD, may crash and burn on other OSes.
469     */
470    pCg6->vidmem = 2 * 1024 * 1024;
471    pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
472
473    if (pCg6->fb == NULL) {
474        /* mapping 2MB failed - try 1MB */
475        pCg6->vidmem = 1024 * 1024;
476        pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
477    }
478
479    if (pCg6->fb == NULL) {
480        /* we can't map all video RAM - fall back to width*height */
481        pCg6->vidmem = psdp->width * psdp->height;
482        pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
483    }
484
485    if (pCg6->fb != NULL) {
486        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "mapped %d KB video RAM\n",
487            pCg6->vidmem >> 10);
488    }
489
490    if (!pCg6->fbc || !pCg6->thc || !pCg6->fb) {
491        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
492                   "xf86MapSbusMem failed fbc:%" PRIxPTR " fb:%" PRIxPTR
493                   " thc:%" PRIxPTR "\n",
494                   pCg6->fbc, pCg6->fb, pCg6->thc );
495
496        if (pCg6->fbc) {
497            xf86UnmapSbusMem(psdp, pCg6->fbc, sizeof(*pCg6->fbc));
498            pCg6->fbc = NULL;
499        }
500
501        if (pCg6->thc) {
502            xf86UnmapSbusMem(psdp, pCg6->thc, sizeof(*pCg6->thc));
503            pCg6->thc = NULL;
504        }
505
506        if (pCg6->fb) {
507            xf86UnmapSbusMem(psdp, pCg6->fb, pCg6->vidmem);
508            pCg6->fb = NULL;
509        }
510
511        return FALSE;
512    }
513
514    /* Darken the screen for aesthetic reasons and set the viewport */
515    CG6SaveScreen(pScreen, SCREEN_SAVER_ON);
516
517    /*
518     * The next step is to setup the screen's visuals, and initialise the
519     * framebuffer code.  In cases where the framebuffer's default
520     * choices for things like visual layouts and bits per RGB are OK,
521     * this may be as simple as calling the framebuffer's ScreenInit()
522     * function.  If not, the visuals will need to be setup before calling
523     * a fb ScreenInit() function and fixed up after.
524     */
525
526    /*
527     * Reset visual list.
528     */
529    miClearVisualTypes();
530
531    /* Set the bits per RGB for 8bpp mode */
532    pScrn->rgbBits = 8;
533
534    /* Setup the visuals we support. */
535
536    if (!miSetVisualTypes(pScrn->depth, miGetDefaultVisualMask(pScrn->depth),
537			  pScrn->rgbBits, pScrn->defaultVisual))
538	return FALSE;
539
540    miSetPixmapDepths ();
541
542    /*
543     * Call the framebuffer layer's ScreenInit function, and fill in other
544     * pScreen fields.
545     */
546
547    ret = fbScreenInit(pScreen, pCg6->fb, pScrn->virtualX,
548		       pScrn->virtualY, pScrn->xDpi, pScrn->yDpi,
549		       pScrn->virtualX, 8);
550    if (!ret)
551	return FALSE;
552
553    pCg6->width = pScrn->virtualX;
554    pCg6->height = pScrn->virtualY;
555    pCg6->maxheight = (pCg6->vidmem / pCg6->width) & 0xffff;
556
557    fbPictureInit (pScreen, 0, 0);
558
559    xf86SetBackingStore(pScreen);
560    xf86SetSilkenMouse(pScreen);
561
562    xf86SetBlackWhitePixels(pScreen);
563
564    if (!pCg6->NoAccel) {
565        BoxRec bx;
566        pCg6->pXAA=XAACreateInfoRec();
567        CG6AccelInit(pScrn);
568        bx.x1=bx.y1=0;
569        bx.x2=pCg6->width;
570        bx.y2=pCg6->maxheight;
571        xf86InitFBManager(pScreen,&bx);
572        if(!XAAInit(pScreen, pCg6->pXAA))
573            return FALSE;
574
575        xf86Msg(X_INFO, "%s: Using acceleration\n", pCg6->psdp->device);
576    }
577
578    /* setup DGA */
579    Cg6DGAInit(pScreen);
580
581
582    /* Initialise cursor functions */
583    miDCInitialize (pScreen, xf86GetPointerScreenFuncs());
584
585    /* Initialize HW cursor layer.
586       Must follow software cursor initialization*/
587    if (pCg6->HWCursor) {
588	extern Bool CG6HWCursorInit(ScreenPtr pScreen);
589
590	if(!CG6HWCursorInit(pScreen)) {
591	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
592		       "Hardware cursor initialization failed\n");
593	    return(FALSE);
594	}
595	xf86SbusHideOsHwCursor(pCg6->psdp);
596    }
597
598    /* Initialise default colourmap */
599    if (!miCreateDefColormap(pScreen))
600	return FALSE;
601
602    if(!xf86SbusHandleColormaps(pScreen, pCg6->psdp))
603	return FALSE;
604
605    pCg6->CloseScreen = pScreen->CloseScreen;
606    pScreen->CloseScreen = CG6CloseScreen;
607    pScreen->SaveScreen = CG6SaveScreen;
608
609    /* Report any unused options (only for the first generation) */
610    if (serverGeneration == 1) {
611	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
612    }
613
614    /* unblank the screen */
615    CG6SaveScreen(pScreen, SCREEN_SAVER_OFF);
616
617    /* Done */
618    return TRUE;
619}
620
621
622/* Usually mandatory */
623static Bool
624CG6SwitchMode(SWITCH_MODE_ARGS_DECL)
625{
626    return TRUE;
627}
628
629
630/*
631 * This function is used to initialize the Start Address - the first
632 * displayed location in the video memory.
633 */
634/* Usually mandatory */
635static void
636CG6AdjustFrame(ADJUST_FRAME_ARGS_DECL)
637{
638    /* we don't support virtual desktops */
639    return;
640}
641
642/*
643 * This is called when VT switching back to the X server.  Its job is
644 * to reinitialise the video mode.
645 */
646
647/* Mandatory */
648static Bool
649CG6EnterVT(VT_FUNC_ARGS_DECL)
650{
651    SCRN_INFO_PTR(arg);
652    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
653
654    if (pCg6->HWCursor) {
655	xf86SbusHideOsHwCursor (pCg6->psdp);
656	pCg6->CursorFg = 0;
657	pCg6->CursorBg = 0;
658    }
659    return TRUE;
660}
661
662
663/*
664 * This is called when VT switching away from the X server.
665 */
666
667/* Mandatory */
668static void
669CG6LeaveVT(VT_FUNC_ARGS_DECL)
670{
671    return;
672}
673
674
675/*
676 * This is called at the end of each server generation.  It restores the
677 * original (text) mode.  It should really also unmap the video memory too.
678 */
679
680/* Mandatory */
681static Bool
682CG6CloseScreen(CLOSE_SCREEN_ARGS_DECL)
683{
684    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
685    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
686    sbusDevicePtr psdp = pCg6->psdp;
687
688    pScrn->vtSema = FALSE;
689
690    if (pCg6->fbc) {
691        xf86UnmapSbusMem(psdp, pCg6->fbc, sizeof(*pCg6->fbc));
692        pCg6->fbc = NULL;
693    }
694
695    if (pCg6->thc) {
696        xf86UnmapSbusMem(psdp, pCg6->thc, sizeof(*pCg6->thc));
697        pCg6->thc = NULL;
698    }
699
700    if (pCg6->fb) {
701        xf86UnmapSbusMem(psdp, pCg6->fb, pCg6->vidmem);
702        pCg6->fb = NULL;
703    }
704
705    if (pCg6->HWCursor)
706    	xf86SbusHideOsHwCursor(pCg6->psdp);
707
708    pScreen->CloseScreen = pCg6->CloseScreen;
709    return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS);
710}
711
712
713/* Free up any per-generation data structures */
714
715/* Optional */
716static void
717CG6FreeScreen(FREE_SCREEN_ARGS_DECL)
718{
719    SCRN_INFO_PTR(arg);
720    CG6FreeRec(pScrn);
721}
722
723
724/* Checks if a mode is suitable for the selected chipset. */
725
726/* Optional */
727static ModeStatus
728CG6ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
729{
730    if (mode->Flags & V_INTERLACE)
731	return(MODE_BAD);
732
733    return(MODE_OK);
734}
735
736/* Do screen blanking */
737
738/* Mandatory */
739static Bool
740CG6SaveScreen(ScreenPtr pScreen, int mode)
741{
742    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
743    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
744    unsigned int tmp = pCg6->thc->thc_misc;
745
746    switch(mode)
747    {
748    case SCREEN_SAVER_ON:
749    case SCREEN_SAVER_CYCLE:
750       tmp &= ~CG6_THC_MISC_SYNC_ENAB;
751       break;
752    case SCREEN_SAVER_OFF:
753    case SCREEN_SAVER_FORCER:
754       tmp |= CG6_THC_MISC_SYNC_ENAB;
755       break;
756    default:
757       return FALSE;
758    }
759
760    pCg6->thc->thc_misc = tmp;
761    return TRUE;
762}
763
764static Bool
765CG6DriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,
766    pointer ptr)
767{
768	xorgHWFlags *flag;
769
770	switch (op) {
771	case GET_REQUIRED_HW_INTERFACES:
772		flag = (CARD32*)ptr;
773		(*flag) = HW_MMIO;
774		return TRUE;
775	default:
776		return FALSE;
777	}
778}
779
780