cg6_driver.c revision 185b32ea
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    OPTION_ACCELMETHOD
98} CG6Opts;
99
100static const OptionInfoRec CG6Options[] = {
101    { OPTION_SW_CURSOR,		"SWcursor",	OPTV_BOOLEAN,	{0}, FALSE },
102    { OPTION_HW_CURSOR,		"HWcursor",	OPTV_BOOLEAN,	{0}, FALSE },
103    { OPTION_NOACCEL,		"NoAccel",	OPTV_BOOLEAN,	{0}, FALSE },
104    { OPTION_ACCELMETHOD,	"AccelMethod",	OPTV_STRING,	{0}, FALSE },
105    { -1,			NULL,		OPTV_NONE,	{0}, FALSE }
106};
107
108static const char *xaaSymbols[] =
109{
110    "XAACreateInfoRec",
111    "XAADestroyInfoRec",
112    "XAAInit",
113    NULL
114};
115
116#ifdef XFree86LOADER
117
118static MODULESETUPPROTO(cg6Setup);
119
120static XF86ModuleVersionInfo suncg6VersRec =
121{
122	"suncg6",
123	MODULEVENDORSTRING,
124	MODINFOSTRING1,
125	MODINFOSTRING2,
126	XORG_VERSION_CURRENT,
127	CG6_MAJOR_VERSION, CG6_MINOR_VERSION, CG6_PATCHLEVEL,
128	ABI_CLASS_VIDEODRV,
129	ABI_VIDEODRV_VERSION,
130	MOD_CLASS_VIDEODRV,
131	{0,0,0,0}
132};
133
134_X_EXPORT XF86ModuleData suncg6ModuleData = { &suncg6VersRec, cg6Setup, NULL };
135
136pointer
137cg6Setup(pointer module, pointer opts, int *errmaj, int *errmin)
138{
139    static Bool setupDone = FALSE;
140
141    if (!setupDone) {
142	setupDone = TRUE;
143	xf86AddDriver(&SUNCG6, module, HaveDriverFuncs);
144
145	/*
146	 * Modules that this driver always requires can be loaded here
147	 * by calling LoadSubModule().
148	 */
149
150	/*
151	 * The return value must be non-NULL on success even though there
152	 * is no TearDownProc.
153	 */
154	return (pointer)TRUE;
155    } else {
156	if (errmaj) *errmaj = LDR_ONCEONLY;
157	return NULL;
158    }
159}
160
161#endif /* XFree86LOADER */
162
163static Bool
164CG6GetRec(ScrnInfoPtr pScrn)
165{
166    /*
167     * Allocate an Cg6Rec, and hook it into pScrn->driverPrivate.
168     * pScrn->driverPrivate is initialised to NULL, so we can check if
169     * the allocation has already been done.
170     */
171    if (pScrn->driverPrivate != NULL)
172	return TRUE;
173
174    pScrn->driverPrivate = xnfcalloc(sizeof(Cg6Rec), 1);
175    return TRUE;
176}
177
178static void
179CG6FreeRec(ScrnInfoPtr pScrn)
180{
181    Cg6Ptr pCg6;
182
183    if (pScrn->driverPrivate == NULL)
184	return;
185
186    pCg6 = GET_CG6_FROM_SCRN(pScrn);
187
188    free(pScrn->driverPrivate);
189    pScrn->driverPrivate = NULL;
190
191    return;
192}
193
194static const OptionInfoRec *
195CG6AvailableOptions(int chipid, int busid)
196{
197    return CG6Options;
198}
199
200/* Mandatory */
201static void
202CG6Identify(int flags)
203{
204    xf86Msg(X_INFO, "%s: driver for CGsix (GX and Turbo GX)\n", CG6_NAME);
205}
206
207
208/* Mandatory */
209static Bool
210CG6Probe(DriverPtr drv, int flags)
211{
212    int i;
213    GDevPtr *devSections;
214    int *usedChips;
215    int numDevSections;
216    int numUsed;
217    Bool foundScreen = FALSE;
218    EntityInfoPtr pEnt;
219
220    /*
221     * The aim here is to find all cards that this driver can handle,
222     * and for the ones not already claimed by another driver, claim the
223     * slot, and allocate a ScrnInfoRec.
224     *
225     * This should be a minimal probe, and it should under no circumstances
226     * change the state of the hardware.  Because a device is found, don't
227     * assume that it will be used.  Don't do any initialisations other than
228     * the required ScrnInfoRec initialisations.  Don't allocate any new
229     * data structures.
230     */
231
232    /*
233     * Next we check, if there has been a chipset override in the config file.
234     * For this we must find out if there is an active device section which
235     * is relevant, i.e., which has no driver specified or has THIS driver
236     * specified.
237     */
238
239    if ((numDevSections = xf86MatchDevice(CG6_DRIVER_NAME,
240					  &devSections)) <= 0) {
241	/*
242	 * There's no matching device section in the config file, so quit
243	 * now.
244	 */
245	return FALSE;
246    }
247
248    /*
249     * We need to probe the hardware first.  We then need to see how this
250     * fits in with what is given in the config file, and allow the config
251     * file info to override any contradictions.
252     */
253
254    numUsed = xf86MatchSbusInstances(CG6_NAME, SBUS_DEVICE_CG6,
255		   devSections, numDevSections,
256		   drv, &usedChips);
257
258    free(devSections);
259    if (numUsed <= 0)
260	return FALSE;
261
262    if (flags & PROBE_DETECT)
263	foundScreen = TRUE;
264    else for (i = 0; i < numUsed; i++) {
265	pEnt = xf86GetEntityInfo(usedChips[i]);
266
267	/*
268	 * Check that nothing else has claimed the slots.
269	 */
270	if(pEnt->active) {
271	    ScrnInfoPtr pScrn;
272
273	    /* Allocate a ScrnInfoRec and claim the slot */
274	    pScrn = xf86AllocateScreen(drv, 0);
275
276	    /* Fill in what we can of the ScrnInfoRec */
277	    pScrn->driverVersion = CG6_VERSION;
278	    pScrn->driverName	 = CG6_DRIVER_NAME;
279	    pScrn->name		 = CG6_NAME;
280	    pScrn->Probe	 = CG6Probe;
281	    pScrn->PreInit	 = CG6PreInit;
282	    pScrn->ScreenInit	 = CG6ScreenInit;
283  	    pScrn->SwitchMode	 = CG6SwitchMode;
284  	    pScrn->AdjustFrame	 = CG6AdjustFrame;
285	    pScrn->EnterVT	 = CG6EnterVT;
286	    pScrn->LeaveVT	 = CG6LeaveVT;
287	    pScrn->FreeScreen	 = CG6FreeScreen;
288	    pScrn->ValidMode	 = CG6ValidMode;
289	    xf86AddEntityToScreen(pScrn, pEnt->index);
290	    foundScreen = TRUE;
291	}
292	free(pEnt);
293    }
294    free(usedChips);
295    return foundScreen;
296}
297
298/* Mandatory */
299static Bool
300CG6PreInit(ScrnInfoPtr pScrn, int flags)
301{
302    Cg6Ptr pCg6;
303    sbusDevicePtr psdp;
304    MessageType from;
305    int i;
306
307    if (flags & PROBE_DETECT) return FALSE;
308
309    /*
310     * Note: This function is only called once at server startup, and
311     * not at the start of each server generation.  This means that
312     * only things that are persistent across server generations can
313     * be initialised here.  xf86Screens[] is (pScrn is a pointer to one
314     * of these).  Privates allocated using xf86AllocateScrnInfoPrivateIndex()
315     * are too, and should be used for data that must persist across
316     * server generations.
317     *
318     * Per-generation data should be allocated with
319     * AllocateScreenPrivateIndex() from the ScreenInit() function.
320     */
321
322    /* Allocate the Cg6Rec driverPrivate */
323    if (!CG6GetRec(pScrn)) {
324	return FALSE;
325    }
326    pCg6 = GET_CG6_FROM_SCRN(pScrn);
327
328    /* Set pScrn->monitor */
329    pScrn->monitor = pScrn->confScreen->monitor;
330
331    /* This driver doesn't expect more than one entity per screen */
332    if (pScrn->numEntities > 1)
333	return FALSE;
334    /* This is the general case */
335    for (i = 0; i < pScrn->numEntities; i++) {
336	EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[i]);
337
338	/* CG6 is purely SBUS */
339	if (pEnt->location.type == BUS_SBUS) {
340	    psdp = xf86GetSbusInfoForEntity(pEnt->index);
341	    pCg6->psdp = psdp;
342	} else
343	    return FALSE;
344    }
345
346    /*********************
347    deal with depth
348    *********************/
349
350    if (!xf86SetDepthBpp(pScrn, 8, 0, 0, NoDepth24Support)) {
351	return FALSE;
352    } else {
353	/* Check that the returned depth is one we support */
354	switch (pScrn->depth) {
355	case 8:
356	    /* OK */
357	    break;
358	default:
359	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
360		       "Given depth (%d) is not supported by this driver\n",
361		       pScrn->depth);
362	    return FALSE;
363	}
364    }
365
366    /* Collect all of the relevant option flags (fill in pScrn->options) */
367    xf86CollectOptions(pScrn, NULL);
368    /* Process the options */
369    if (!(pCg6->Options = malloc(sizeof(CG6Options))))
370	return FALSE;
371    memcpy(pCg6->Options, CG6Options, sizeof(CG6Options));
372    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pCg6->Options);
373
374    if (!xf86SetDefaultVisual(pScrn, -1))
375	return FALSE;
376
377    /*
378     * The new cmap code requires this to be initialised.
379     */
380
381    {
382	Gamma zeros = {0.0, 0.0, 0.0};
383
384	if (!xf86SetGamma(pScrn, zeros)) {
385	    return FALSE;
386	}
387    }
388
389    /* Set the bits per RGB for 8bpp mode */
390    from = X_DEFAULT;
391
392    /* determine whether we use hardware or software cursor */
393
394    pCg6->HWCursor = TRUE;
395    if (xf86GetOptValBool(pCg6->Options, OPTION_HW_CURSOR, &pCg6->HWCursor))
396	from = X_CONFIG;
397    if (xf86ReturnOptValBool(pCg6->Options, OPTION_SW_CURSOR, FALSE)) {
398	from = X_CONFIG;
399	pCg6->HWCursor = FALSE;
400    }
401
402    xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
403		pCg6->HWCursor ? "HW" : "SW");
404
405    if (xf86ReturnOptValBool(pCg6->Options, OPTION_NOACCEL, FALSE)) {
406	pCg6->NoAccel = TRUE;
407	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
408    }
409    pCg6->useXAA = FALSE;
410
411    char *optstr;
412    optstr = (char *)xf86GetOptValString(pCg6->Options, OPTION_ACCELMETHOD);
413    if (optstr == NULL) optstr = "exa";
414    if (xf86NameCmp(optstr, "xaa") == 0)
415        pCg6->useXAA = TRUE;
416
417    if (xf86LoadSubModule(pScrn, "fb") == NULL) {
418	CG6FreeRec(pScrn);
419	return FALSE;
420    }
421
422    if (pCg6->HWCursor && xf86LoadSubModule(pScrn, "ramdac") == NULL) {
423	CG6FreeRec(pScrn);
424	return FALSE;
425    }
426
427    /*********************
428    set up clock and mode stuff
429    *********************/
430
431    pScrn->progClock = TRUE;
432
433    if(pScrn->display->virtualX || pScrn->display->virtualY) {
434	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
435		   "CG6 does not support a virtual desktop\n");
436	pScrn->display->virtualX = 0;
437	pScrn->display->virtualY = 0;
438    }
439
440    xf86SbusUseBuiltinMode(pScrn, pCg6->psdp);
441    pScrn->currentMode = pScrn->modes;
442    pScrn->displayWidth = pScrn->virtualX;
443
444    /* Set display resolution */
445    xf86SetDpi(pScrn, 0, 0);
446
447    return TRUE;
448}
449
450/* Mandatory */
451
452/* This gets called at the start of each server generation */
453
454static Bool
455CG6ScreenInit(SCREEN_INIT_ARGS_DECL)
456{
457    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
458    Cg6Ptr pCg6;
459    sbusDevicePtr psdp;
460    int ret;
461
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    xf86SetBackingStore(pScreen);
564    xf86SetSilkenMouse(pScreen);
565
566    xf86SetBlackWhitePixels(pScreen);
567
568    if (!pCg6->NoAccel) {
569#ifdef HAVE_XAA_H
570    	if (pCg6->useXAA) {
571	    BoxRec bx;
572	    if (!xf86LoadSubModule(pScrn, "xaa"))
573	    	return FALSE;
574	    pCg6->pXAA=XAACreateInfoRec();
575	    CG6AccelInit(pScrn);
576	    bx.x1=bx.y1=0;
577	    bx.x2=pCg6->width;
578	    bx.y2=pCg6->maxheight;
579	    xf86InitFBManager(pScreen,&bx);
580	    if(!XAAInit(pScreen, pCg6->pXAA))
581		return FALSE;
582
583	    xf86Msg(X_INFO, "%s: Using XAA acceleration\n", pCg6->psdp->device);
584	} else
585#endif /* HAVE_XAA_H */
586	 {
587	    /* EXA */
588	    XF86ModReqInfo req;
589	    int errmaj, errmin;
590
591	    memset(&req, 0, sizeof(XF86ModReqInfo));
592	    req.majorversion = EXA_VERSION_MAJOR;
593	    req.minorversion = EXA_VERSION_MINOR;
594	    if (!LoadSubModule(pScrn->module, "exa", NULL, NULL, NULL, &req,
595		&errmaj, &errmin)) {
596		LoaderErrorMsg(NULL, "exa", errmaj, errmin);
597		return FALSE;
598	    }
599	    if (!CG6EXAInit(pScreen))
600		return FALSE;
601	    xf86Msg(X_INFO, "%s: Using EXA acceleration\n", pCg6->psdp->device);
602	}
603    }
604
605    /* setup DGA */
606    Cg6DGAInit(pScreen);
607
608
609    /* Initialise cursor functions */
610    miDCInitialize (pScreen, xf86GetPointerScreenFuncs());
611
612    /* Initialize HW cursor layer.
613       Must follow software cursor initialization*/
614    if (pCg6->HWCursor) {
615	extern Bool CG6HWCursorInit(ScreenPtr pScreen);
616
617	if(!CG6HWCursorInit(pScreen)) {
618	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
619		       "Hardware cursor initialization failed\n");
620	    return(FALSE);
621	}
622	xf86SbusHideOsHwCursor(pCg6->psdp);
623    }
624
625    /* Initialise default colourmap */
626    if (!miCreateDefColormap(pScreen))
627	return FALSE;
628
629    if(!xf86SbusHandleColormaps(pScreen, pCg6->psdp))
630	return FALSE;
631
632    pCg6->CloseScreen = pScreen->CloseScreen;
633    pScreen->CloseScreen = CG6CloseScreen;
634    pScreen->SaveScreen = CG6SaveScreen;
635
636    /* Report any unused options (only for the first generation) */
637    if (serverGeneration == 1) {
638	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
639    }
640
641    /* unblank the screen */
642    CG6SaveScreen(pScreen, SCREEN_SAVER_OFF);
643
644    /* Done */
645    return TRUE;
646}
647
648
649/* Usually mandatory */
650static Bool
651CG6SwitchMode(SWITCH_MODE_ARGS_DECL)
652{
653    return TRUE;
654}
655
656
657/*
658 * This function is used to initialize the Start Address - the first
659 * displayed location in the video memory.
660 */
661/* Usually mandatory */
662static void
663CG6AdjustFrame(ADJUST_FRAME_ARGS_DECL)
664{
665    /* we don't support virtual desktops */
666    return;
667}
668
669/*
670 * This is called when VT switching back to the X server.  Its job is
671 * to reinitialise the video mode.
672 */
673
674/* Mandatory */
675static Bool
676CG6EnterVT(VT_FUNC_ARGS_DECL)
677{
678    SCRN_INFO_PTR(arg);
679    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
680
681    if (pCg6->HWCursor) {
682	xf86SbusHideOsHwCursor (pCg6->psdp);
683	pCg6->CursorFg = 0;
684	pCg6->CursorBg = 0;
685    }
686    return TRUE;
687}
688
689
690/*
691 * This is called when VT switching away from the X server.
692 */
693
694/* Mandatory */
695static void
696CG6LeaveVT(VT_FUNC_ARGS_DECL)
697{
698    return;
699}
700
701
702/*
703 * This is called at the end of each server generation.  It restores the
704 * original (text) mode.  It should really also unmap the video memory too.
705 */
706
707/* Mandatory */
708static Bool
709CG6CloseScreen(CLOSE_SCREEN_ARGS_DECL)
710{
711    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
712    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
713    sbusDevicePtr psdp = pCg6->psdp;
714
715    pScrn->vtSema = FALSE;
716
717    if (pCg6->fbc) {
718        xf86UnmapSbusMem(psdp, pCg6->fbc, sizeof(*pCg6->fbc));
719        pCg6->fbc = NULL;
720    }
721
722    if (pCg6->thc) {
723        xf86UnmapSbusMem(psdp, pCg6->thc, sizeof(*pCg6->thc));
724        pCg6->thc = NULL;
725    }
726
727    if (pCg6->fb) {
728        xf86UnmapSbusMem(psdp, pCg6->fb, pCg6->vidmem);
729        pCg6->fb = NULL;
730    }
731
732    if (pCg6->HWCursor)
733    	xf86SbusHideOsHwCursor(pCg6->psdp);
734
735    pScreen->CloseScreen = pCg6->CloseScreen;
736    return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS);
737}
738
739
740/* Free up any per-generation data structures */
741
742/* Optional */
743static void
744CG6FreeScreen(FREE_SCREEN_ARGS_DECL)
745{
746    SCRN_INFO_PTR(arg);
747    CG6FreeRec(pScrn);
748}
749
750
751/* Checks if a mode is suitable for the selected chipset. */
752
753/* Optional */
754static ModeStatus
755CG6ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
756{
757    if (mode->Flags & V_INTERLACE)
758	return(MODE_BAD);
759
760    return(MODE_OK);
761}
762
763/* Do screen blanking */
764
765/* Mandatory */
766static Bool
767CG6SaveScreen(ScreenPtr pScreen, int mode)
768{
769    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
770    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
771    unsigned int tmp = pCg6->thc->thc_misc;
772
773    switch(mode)
774    {
775    case SCREEN_SAVER_ON:
776    case SCREEN_SAVER_CYCLE:
777       tmp &= ~CG6_THC_MISC_SYNC_ENAB;
778       break;
779    case SCREEN_SAVER_OFF:
780    case SCREEN_SAVER_FORCER:
781       tmp |= CG6_THC_MISC_SYNC_ENAB;
782       break;
783    default:
784       return FALSE;
785    }
786
787    pCg6->thc->thc_misc = tmp;
788    return TRUE;
789}
790
791static Bool
792CG6DriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,
793    pointer ptr)
794{
795	xorgHWFlags *flag;
796
797	switch (op) {
798	case GET_REQUIRED_HW_INTERFACES:
799		flag = (CARD32*)ptr;
800		(*flag) = HW_MMIO;
801		return TRUE;
802	default:
803		return FALSE;
804	}
805}
806
807