sunInit.c revision f89f2ff9
1/* $Xorg: sunInit.c,v 1.4 2000/08/17 19:48:29 cpqbld Exp $ */
2/*
3 * sunInit.c --
4 *	Initialization functions for screen/keyboard/mouse, etc.
5 *
6 * Copyright 1987 by the Regents of the University of California
7 *
8 * Permission to use, copy, modify, and distribute this
9 * software and its documentation for any purpose and without
10 * fee is hereby granted, provided that the above copyright
11 * notice appear in all copies.  The University of California
12 * makes no representations about the suitability of this
13 * software for any purpose.  It is provided "as is" without
14 * express or implied warranty.
15 *
16 *
17 */
18/* $XFree86: xc/programs/Xserver/hw/sun/sunInit.c,v 3.14 2004/06/02 22:43:00 dawes Exp $ */
19
20/************************************************************
21Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
22
23                    All Rights Reserved
24
25Permission  to  use,  copy,  modify,  and  distribute   this
26software  and  its documentation for any purpose and without
27fee is hereby granted, provided that the above copyright no-
28tice  appear  in all copies and that both that copyright no-
29tice and this permission notice appear in  supporting  docu-
30mentation,  and  that the names of Sun or The Open Group
31not be used in advertising or publicity pertaining to
32distribution  of  the software  without specific prior
33written permission. Sun and The Open Group make no
34representations about the suitability of this software for
35any purpose. It is provided "as is" without any express or
36implied warranty.
37
38SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
39INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
40NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
41ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
43PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
44OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
45THE USE OR PERFORMANCE OF THIS SOFTWARE.
46
47*******************************************************/
48
49#include    "sun.h"
50#include    "gcstruct.h"
51#include    "mi.h"
52#include    "fb.h"
53
54/* default log file paths */
55#ifndef DEFAULT_LOGDIR
56#define DEFAULT_LOGDIR "/var/log"
57#endif
58#ifndef DEFAULT_LOGPREFIX
59#define DEFAULT_LOGPREFIX "Xsun."
60#endif
61
62/* maximum pixmap depth */
63#ifndef SUNMAXDEPTH
64#define SUNMAXDEPTH 8
65#endif
66
67#ifdef i386 /* { */
68#define BW2I NULL
69#else /* }{ */
70#define BW2I sunBW2Init
71#endif /* } */
72
73#ifdef LOWMEMFTPT
74#undef  BW2I
75#define BW2I NULL
76#endif /* ifdef LOWMEMFTPT */
77
78#if SUNMAXDEPTH == 1 /* { */
79#define CG2I NULL
80#define CG3I NULL
81#define CG4I NULL
82#define CG6I NULL
83#define CG8I NULL
84#define TCXI NULL
85#else /* }{ */
86#define CG3I sunCG3Init
87#if defined(i386) || defined(__bsdi__) /* { */
88#define CG2I NULL
89#define CG4I NULL
90#else /* }{ */
91#ifdef INCLUDE_CG2_HEADER
92#define CG2I sunCG2Init
93#endif /* INCLUDE_CG2_HEADER */
94#define CG4I sunCG4Init
95#endif /* } */
96#ifdef FBTYPE_SUNFAST_COLOR /* { */
97#define CG6I sunCG6Init
98#else /* }{ */
99#define CG6I NULL
100#endif /* } */
101#ifdef XFBTYPE_TCX  /* { */
102#define TCXI sunTCXInit
103#else /* }{ */
104#define TCXI NULL
105#endif /* } */
106#if SUNMAXDEPTH > 8 /* { */
107#ifdef FBTYPE_MEMCOLOR /* { */
108#define CG8I sunCG8Init
109#else /* }{ */
110#define CG8I NULL
111#endif /* } */
112#else /* }{ */
113#define CG8I NULL
114#endif /* } */
115
116#endif /* } */
117
118static int OpenFrameBuffer(char *, int);
119static void SigIOHandler(int);
120static char** GetDeviceList(int, char **);
121static void getKbdType(void);
122
123#if SUNMAXDEPTH == 32
124static Bool sunCfbCreateGC(GCPtr);
125static void sunCfbGetSpans(DrawablePtr, int, DDXPointPtr, int *, int, char *);
126static void sunCfbGetImage(DrawablePtr, int,int, int, int, unsigned int, unsigned long, char *);
127#endif /* SUNMAXDEPTH == 32 */
128
129static Bool	sunDevsInited = FALSE;
130
131EventList *sunEvents = NULL;
132
133Bool sunAutoRepeatHandlersInstalled;	/* FALSE each time InitOutput called */
134Bool sunSwapLkeys = FALSE;
135Bool sunFlipPixels = FALSE;
136Bool sunFbInfo = FALSE;
137Bool sunCG4Frob = FALSE;
138Bool sunNoGX = FALSE;
139
140sunKbdPrivRec sunKbdPriv = {
141    -1,		/* fd */
142    -1,		/* type */
143    -1,		/* layout */
144    0,		/* click */
145    (Leds)0,	/* leds */
146};
147
148sunPtrPrivRec sunPtrPriv = {
149    -1,		/* fd */
150    0		/* Current button state */
151};
152
153/*
154 * The name member in the following table corresponds to the
155 * FBTYPE_* macros defined in /usr/include/sun/fbio.h file
156 */
157sunFbDataRec sunFbData[XFBTYPE_LASTPLUSONE] = {
158  { NULL, "SUN1BW        (bw1)" },
159  { NULL, "SUN1COLOR     (cg1)" },
160  { BW2I, "SUN2BW        (bw2)" },
161#ifdef INCLUDE_CG2_HEADER
162  { CG2I, "SUN2COLOR     (cg2)" },
163#else
164  { NULL, "SUN2COLOR     (cg2)" },
165#endif /* INCLUDE_CG2_HEADER */
166  { NULL, "SUN2GP        (gp1/gp2)" },
167  { NULL, "SUN5COLOR     (cg5/386i accel)" },
168  { CG3I, "SUN3COLOR     (cg3)" },
169  { CG8I, "MEMCOLOR      (cg8)" },
170  { CG4I, "SUN4COLOR     (cg4)" },
171  { NULL, "NOTSUN1" },
172  { NULL, "NOTSUN2" },
173  { NULL, "NOTSUN3" }
174#ifndef i386 /* { */
175 ,{ CG6I, "SUNFAST_COLOR (cg6/gx)" },
176  { NULL, "SUNROP_COLOR  (cg9)" },
177  { NULL, "SUNFB_VIDEO" },
178  { NULL, "SUNGIFB" },
179  { NULL, "SUNPLAS" },
180#ifdef FBTYPE_SUNGP3
181  { NULL, "SUNGP3        (cg12/gs)" },
182#endif
183#ifdef FBTYPE_SUNGT
184  { NULL, "SUNGT         (gt)" },
185#endif
186#ifdef FBTYPE_SUNLEO
187  { NULL, "SUNLEO        (zx)" },
188#endif
189#ifdef FBTYPE_MDICOLOR
190  { NULL, "MDICOLOR      (cgfourteen)" },
191#endif
192#ifdef XFBTYPE_TCX
193  { TCXI, "TCX           (tcx)" },
194#endif
195#endif /* } */
196};
197
198/*
199 * a list of devices to try if there is no environment or command
200 * line list of devices
201 */
202#if SUNMAXDEPTH == 1 /* { */
203static char *fallbackList[] = {
204    BWTWO0DEV, BWTWO1DEV, BWTWO2DEV
205};
206#else /* }{ */
207static char *fallbackList[] = {
208#ifndef i386 /* { */
209    CGTWO0DEV, CGTWO1DEV, CGTWO2DEV,
210#if (MAXSCREENS == 4)
211    CGTWO3DEV,
212#endif
213#endif /* } */
214    CGTHREE0DEV,
215#ifndef i386 /* { */
216    CGTHREE1DEV, CGTHREE2DEV,
217#if (MAXSCREENS == 4)
218    CGTHREE3DEV,
219#endif
220#endif /* } */
221#ifdef FBTYPE_SUNFAST_COLOR /* { */
222    CGSIX0DEV, CGSIX1DEV, CGSIX2DEV,
223#if (MAXSCREENS == 4)
224    CGSIX3DEV,
225#endif
226#endif /* } */
227#ifndef i386 /* { */
228    CGFOUR0DEV, BWTWO0DEV, BWTWO1DEV, BWTWO2DEV,
229#if (MAXSCREENS == 4)
230    BWTWO3DEV,
231#endif
232#endif /* } */
233#if SUNMAXDEPTH > 8 /* { */
234    CGEIGHT0DEV,
235#if 0
236#ifdef XFBTYPE_TCX
237    TCX0DEV,
238#endif
239#endif
240#endif /* } */
241    "/dev/fb"
242};
243#endif /* } */
244
245#define FALLBACK_LIST_LEN sizeof fallbackList / sizeof fallbackList[0]
246
247fbFd sunFbs[MAXSCREENS];
248
249static PixmapFormatRec	formats[] = {
250    { 1, 1, BITMAP_SCANLINE_PAD	} /* 1-bit deep */
251#if SUNMAXDEPTH > 1
252    ,{ 8, 8, BITMAP_SCANLINE_PAD} /* 8-bit deep */
253#if SUNMAXDEPTH > 8
254    ,{ 12, 24, BITMAP_SCANLINE_PAD } /* 12-bit deep */
255    ,{ 24, 32, BITMAP_SCANLINE_PAD } /* 24-bit deep */
256#endif
257#endif
258};
259#define NUMFORMATS	(sizeof formats)/(sizeof formats[0])
260
261/*
262 * OpenFrameBuffer --
263 *	Open a frame buffer according to several rules.
264 *	Find the device to use by looking in the sunFbData table,
265 *	an XDEVICE envariable, a -dev switch or using /dev/fb if trying
266 *	to open screen 0 and all else has failed.
267 *
268 * Results:
269 *	The fd of the framebuffer.
270 */
271static int
272OpenFrameBuffer(
273    char		*device,	/* e.g. "/dev/cgtwo0" */
274    int			screen    	/* what screen am I going to be */
275)
276{
277    int			ret = TRUE;
278    struct fbgattr	*fbattr;
279    static int		devFbUsed;
280
281    sunFbs[screen].fd = -1;
282    if (strcmp (device, "/dev/fb") == 0 && devFbUsed)
283	return FALSE;
284    if (access (device, R_OK | W_OK) == -1)
285	return FALSE;
286    if ((sunFbs[screen].fd = open(device, O_RDWR, 0)) == -1)
287	ret = FALSE;
288    else {
289	fbattr = (struct fbgattr *) xalloc (sizeof (struct fbgattr));
290	if (ioctl(sunFbs[screen].fd, FBIOGATTR, fbattr) == -1) {
291	    /*
292		This is probably a bwtwo; the $64,000 question is:
293		is it the mono plane of a cgfour, or is it really a
294		real bwtwo?  If there is only a cgfour in the box or
295		only a bwtwo in the box, then it isn't a problem.  If
296		it's a 3/60, which has a bwtwo on the mother board *and*
297		a cgfour, then things get tricky because there's no way
298		to tell if the bwtwo is really being emulated by the cgfour.
299	    */
300	    xfree (fbattr);
301	    fbattr = NULL;
302	    if (ioctl(sunFbs[screen].fd, FBIOGTYPE, &sunFbs[screen].info) == -1) {
303		Error("unable to get frame buffer attributes");
304		(void) close(sunFbs[screen].fd);
305		sunFbs[screen].fd = -1;
306		return FALSE;
307	    }
308	}
309	if (ret) {
310	    devFbUsed = TRUE;
311	    if (fbattr) {
312		if (fbattr->fbtype.fb_type >= XFBTYPE_LASTPLUSONE) {
313		    ErrorF ("%s is an unknown framebuffer type\n", device);
314		    (void) close(sunFbs[screen].fd);
315		    sunFbs[screen].fd = -1;
316		    return FALSE;
317		}
318		sunFbs[screen].info = fbattr->fbtype;
319	    }
320	    sunFbs[screen].fbPriv = (pointer) fbattr;
321	    if (fbattr && !sunFbData[fbattr->fbtype.fb_type].init) {
322		int _i;
323		ret = FALSE;
324		for (_i = 0; _i < FB_ATTR_NEMUTYPES; _i++) {
325		    if (sunFbData[fbattr->emu_types[_i]].init) {
326			sunFbs[screen].info.fb_type = fbattr->emu_types[_i];
327			ret = TRUE;
328			if (sunFbInfo)
329			    ErrorF ("%s is emulating a %s\n", device,
330				sunFbData[fbattr->fbtype.fb_type].name);
331			break;
332		    }
333		}
334	    }
335	    if (sunFbInfo)
336		ErrorF ("%s is really a %s\n", device,
337		    sunFbData[fbattr ? fbattr->fbtype.fb_type : sunFbs[screen].info.fb_type].name);
338	}
339    }
340    if (!ret)
341	sunFbs[screen].fd = -1;
342    return ret;
343}
344
345/*-
346 *-----------------------------------------------------------------------
347 * SigIOHandler --
348 *	Signal handler for SIGIO - input is available.
349 *
350 * Results:
351 *	sunSigIO is set - ProcessInputEvents() will be called soon.
352 *
353 * Side Effects:
354 *	None
355 *
356 *-----------------------------------------------------------------------
357 */
358/*ARGSUSED*/
359static void
360SigIOHandler(int sig)
361{
362    int olderrno = errno;
363    sunEnqueueEvents ();
364    errno = olderrno;
365}
366
367/*-
368 *-----------------------------------------------------------------------
369 * sunNonBlockConsoleOff --
370 *	Turn non-blocking mode on the console off, so you don't get logged
371 *	out when the server exits.
372 *
373 * Results:
374 *	None.
375 *
376 * Side Effects:
377 *	None.
378 *
379 *-----------------------------------------------------------------------
380 */
381void
382sunNonBlockConsoleOff(
383#if defined(SVR4) || defined(CSRG_BASED)
384    void
385#else
386    char* arg
387#endif
388)
389{
390    register int i;
391
392    i = fcntl(2, F_GETFL, 0);
393    if (i >= 0)
394	(void) fcntl(2, F_SETFL, i & ~FNDELAY);
395}
396
397static char**
398GetDeviceList(int argc, char **argv)
399{
400    int		i;
401    char	*envList = NULL;
402    char	*cmdList = NULL;
403    char	**deviceList = (char **)NULL;
404
405    for (i = 1; i < argc; i++)
406	if (strcmp (argv[i], "-dev") == 0 && i+1 < argc) {
407	    cmdList = argv[i + 1];
408	    break;
409	}
410    if (!cmdList)
411	envList = getenv ("XDEVICE");
412
413    if (cmdList || envList) {
414	char	*_tmpa;
415	char	*_tmpb;
416	int	_i1;
417	deviceList = (char **) xalloc ((MAXSCREENS + 1) * sizeof (char *));
418	_tmpa = (cmdList) ? cmdList : envList;
419	for (_i1 = 0; _i1 < MAXSCREENS; _i1++) {
420	    _tmpb = strtok (_tmpa, ":");
421	    if (_tmpb)
422		deviceList[_i1] = _tmpb;
423	    else
424		deviceList[_i1] = NULL;
425	    _tmpa = NULL;
426	}
427	deviceList[MAXSCREENS] = NULL;
428    }
429    if (!deviceList) {
430	/* no environment and no cmdline, so default */
431	deviceList =
432	    (char **) xalloc ((FALLBACK_LIST_LEN + 1) * sizeof (char *));
433	for (i = 0; i < FALLBACK_LIST_LEN; i++)
434	    deviceList[i] = fallbackList[i];
435	deviceList[FALLBACK_LIST_LEN] = NULL;
436    }
437    return deviceList;
438}
439
440static void
441getKbdType(void)
442{
443/*
444 * The Sun 386i has system include files that preclude this pre SunOS 4.1
445 * test for the presence of a type 4 keyboard however it really doesn't
446 * matter since no 386i has ever been shipped with a type 3 keyboard.
447 * SunOS 4.1 no longer needs this kludge.
448 */
449#if !defined(i386) && !defined(KIOCGKEY)
450#define TYPE4KEYBOARDOVERRIDE
451#endif
452
453    int ii;
454
455    for (ii = 0; ii < 3; ii++) {
456	sunKbdWait();
457	(void) ioctl (sunKbdPriv.fd, KIOCTYPE, &sunKbdPriv.type);
458#ifdef TYPE4KEYBOARDOVERRIDE
459	/*
460	 * Magic. Look for a key which is non-existent on a real type
461	 * 3 keyboard but does exist on a type 4 keyboard.
462	 */
463	if (sunKbdPriv.type == KB_SUN3) {
464	    struct kiockeymap key;
465
466	    key.kio_tablemask = 0;
467	    key.kio_station = 118;
468	    if (ioctl(sunKbdPriv.fd, KIOCGKEY, &key) == -1) {
469		Error( "ioctl KIOCGKEY" );
470		FatalError("Can't KIOCGKEY on fd %d\n", sunKbdPriv.fd);
471	    }
472	    if (key.kio_entry != HOLE)
473		sunKbdPriv.type = KB_SUN4;
474	}
475#endif
476	switch (sunKbdPriv.type) {
477	case KB_SUN2:
478	case KB_SUN3:
479	case KB_SUN4: return;
480	default:
481	    sunChangeKbdTranslation(sunKbdPriv.fd, FALSE);
482	    continue;
483	}
484    }
485    FatalError ("Unsupported keyboard type %d\n", sunKbdPriv.type);
486}
487
488void
489OsVendorInit(void)
490{
491    static int inited;
492    if (!inited) {
493	const char *logfile;
494	char *lf;
495#ifndef i386
496	struct rlimit rl;
497
498	/*
499	 * one per client, one per screen, one per listen endpoint,
500	 * keyboard, mouse, and stderr
501	 */
502	int maxfds = MAXCLIENTS + MAXSCREENS + 5;
503
504	if (getrlimit (RLIMIT_NOFILE, &rl) == 0) {
505	    rl.rlim_cur = maxfds < rl.rlim_max ? maxfds : rl.rlim_max;
506	    (void) setrlimit (RLIMIT_NOFILE, &rl);
507	}
508#endif
509
510#define LOGSUFFIX ".log"
511#define LOGOLDSUFFIX ".old"
512
513	logfile = DEFAULT_LOGDIR "/" DEFAULT_LOGPREFIX;
514	if (asprintf(&lf, "%s%%s" LOGSUFFIX, logfile) == -1)
515	    FatalError("Cannot allocate space for the log file name\n");
516	LogInit(lf, LOGOLDSUFFIX);
517
518#undef LOGSUFFIX
519#undef LOGOLDSUFFIX
520
521	free(lf);
522
523	sunKbdPriv.fd = open ("/dev/kbd", O_RDWR, 0);
524	if (sunKbdPriv.fd < 0)
525	    FatalError ("Cannot open /dev/kbd, error %d\n", errno);
526	sunPtrPriv.fd = open ("/dev/mouse", O_RDWR, 0);
527	if (sunPtrPriv.fd < 0)
528	    FatalError ("Cannot open /dev/mouse, error %d\n", errno);
529	getKbdType ();
530	if (sunKbdPriv.type == KB_SUN4) {
531	    (void) ioctl (sunKbdPriv.fd, KIOCLAYOUT, &sunKbdPriv.layout);
532	    if (sunKbdPriv.layout < 0 ||
533		sunKbdPriv.layout > sunMaxLayout ||
534		sunType4KeyMaps[sunKbdPriv.layout] == NULL)
535		FatalError ("Unsupported keyboard type 4 layout %d\n",
536			    sunKbdPriv.layout);
537	    sunKeySyms[KB_SUN4].map = sunType4KeyMaps[sunKbdPriv.layout];
538        }
539	inited = 1;
540    }
541}
542
543void
544OsVendorFatalError(void)
545{
546}
547
548/*-
549 *-----------------------------------------------------------------------
550 * InitOutput --
551 *	Initialize screenInfo for all actually accessible framebuffers.
552 *	The
553 *
554 * Results:
555 *	screenInfo init proc field set
556 *
557 * Side Effects:
558 *	None
559 *
560 *-----------------------------------------------------------------------
561 */
562
563void
564InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
565{
566    int     	i, scr;
567    int		nonBlockConsole = 0;
568    char	**devList;
569    static int	setup_on_exit = 0;
570
571    if (!monitorResolution)
572	monitorResolution = 90;
573    if (RunFromSigStopParent)
574	nonBlockConsole = 1;
575    for (i = 1; i < argc; i++) {
576	if (!strcmp(argv[i],"-debug"))
577	    nonBlockConsole = 0;
578    }
579
580    /*
581     *	Writes to /dev/console can block - causing an
582     *	excess of error messages to hang the server in
583     *	deadlock.  So.......
584     */
585    if (nonBlockConsole) {
586	if (!setup_on_exit) {
587#if defined(SVR4) || defined(CSRG_BASED)
588	    if (atexit(sunNonBlockConsoleOff))
589#else
590	    if (on_exit(sunNonBlockConsoleOff, (char *)0))
591#endif
592		ErrorF("InitOutput: can't register NBIO exit handler\n");
593
594	    setup_on_exit = 1;
595	}
596	i = fcntl(2, F_GETFL, 0);
597	if (i >= 0)
598	    i = fcntl(2, F_SETFL, i | FNDELAY);
599	if (i < 0) {
600	    Error("fcntl");
601	    ErrorF("InitOutput: can't put stderr in non-block mode\n");
602	}
603    }
604    pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
605    pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
606    pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
607    pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
608
609    pScreenInfo->numPixmapFormats = NUMFORMATS;
610    for (i=0; i< NUMFORMATS; i++)
611        pScreenInfo->formats[i] = formats[i];
612    if (!sunDevsInited) {
613	/* first time ever */
614	for (scr = 0; scr < MAXSCREENS; scr++)
615	    sunFbs[scr].fd = -1;
616	devList = GetDeviceList (argc, argv);
617	for (i = 0, scr = 0; devList[i] != NULL && scr < MAXSCREENS; i++)
618	    if (OpenFrameBuffer (devList[i], scr))
619		scr++;
620	sunDevsInited = TRUE;
621	xfree (devList);
622    }
623    for (scr = 0; scr < MAXSCREENS; scr++)
624	if (sunFbs[scr].fd != -1)
625	    (void) AddScreen (sunFbData[sunFbs[scr].info.fb_type].init,
626			      argc, argv);
627    (void) OsSignal(SIGWINCH, SIG_IGN);
628}
629
630/*-
631 *-----------------------------------------------------------------------
632 * InitInput --
633 *	Initialize all supported input devices...what else is there
634 *	besides pointer and keyboard?
635 *
636 * Results:
637 *	None.
638 *
639 * Side Effects:
640 *	Two DeviceRec's are allocated and registered as the system pointer
641 *	and keyboard devices.
642 *
643 *-----------------------------------------------------------------------
644 */
645void
646InitInput(int argc, char **argv)
647{
648    int rc;
649
650    rc = AllocDevicePair(serverClient, "sun",
651			 &sunPointerDevice, &sunKeyboardDevice,
652			 sunMouseProc, sunKbdProc, FALSE);
653    if (rc != Success)
654	FatalError("Failed to init sun default input devices.\n");
655
656    GetEventList(&sunEvents);
657
658    (void)mieqInit();
659#define SET_FLOW(fd) fcntl(fd, F_SETFL, FNDELAY | FASYNC)
660#ifdef SVR4
661    (void) OsSignal(SIGPOLL, SigIOHandler);
662#define WANT_SIGNALS(fd) ioctl(fd, I_SETSIG, S_INPUT | S_HIPRI)
663#else
664    (void) OsSignal(SIGIO, SigIOHandler);
665#define WANT_SIGNALS(fd) fcntl(fd, F_SETOWN, getpid())
666#endif
667    if (sunKbdPriv.fd >= 0) {
668	if (SET_FLOW(sunKbdPriv.fd) == -1 || WANT_SIGNALS(sunKbdPriv.fd) == -1) {
669	    (void) close (sunKbdPriv.fd);
670	    sunKbdPriv.fd = -1;
671	    FatalError("Async kbd I/O failed in InitInput");
672	}
673    }
674    if (sunPtrPriv.fd >= 0) {
675	if (SET_FLOW(sunPtrPriv.fd) == -1 || WANT_SIGNALS(sunPtrPriv.fd) == -1) {
676	    (void) close (sunPtrPriv.fd);
677	    sunPtrPriv.fd = -1;
678	    FatalError("Async mouse I/O failed in InitInput");
679	}
680    }
681}
682
683void
684CloseInput(void)
685{
686}
687
688#if SUNMAXDEPTH == 8
689
690Bool
691sunCfbSetupScreen(
692    ScreenPtr pScreen,
693    pointer pbits,		/* pointer to screen bitmap */
694    int xsize,			/* in pixels */
695    int ysize,			/* in pixels */
696    int dpix,			/* dots per inch */
697    int dpiy,			/* dots per inch */
698    int width,			/* pixel width of frame buffer */
699    int	bpp			/* bits per pixel of root */
700)
701{
702    return fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy,
703			 width, bpp);
704}
705
706Bool
707sunCfbFinishScreenInit(
708    ScreenPtr pScreen,
709    pointer pbits,		/* pointer to screen bitmap */
710    int xsize,			/* in pixels */
711    int ysize,			/* in pixels */
712    int dpix,			/* dots per inch */
713    int dpiy,			/* dots per inch */
714    int width,			/* pixel width of frame buffer */
715    int bpp			/* bits per pixel of root */
716)
717{
718    return fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
719			      width, bpp);
720}
721
722Bool
723sunCfbScreenInit(
724    ScreenPtr pScreen,
725    pointer pbits,		/* pointer to screen bitmap */
726    int xsize,			/* in pixels */
727    int ysize,			/* in pixels */
728    int dpix,			/* dots per inch */
729    int dpiy,			/* dots per inch */
730    int width,			/* pixel width of frame buffer */
731    int bpp			/* bits per pixel of root */
732)
733{
734    return fbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp);
735}
736
737#else /* SUNMAXDEPTH != 8 */
738#if SUNMAXDEPTH == 32
739
740static Bool
741sunCfbCreateGC(GCPtr pGC)
742{
743    return fbCreateGC (pGC);
744}
745
746static void
747sunCfbGetSpans(
748    DrawablePtr		pDrawable,	/* drawable from which to get bits */
749    int			wMax,		/* largest value of all *pwidths */
750    DDXPointPtr		ppt,		/* points to start copying from */
751    int			*pwidth,	/* list of number of bits to copy */
752    int			nspans,		/* number of scanlines to copy */
753    char		*pdstStart	/* where to put the bits */
754)
755{
756    fbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
757}
758
759static void
760sunCfbGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h, unsigned int format, unsigned long planeMask, char *pdstLine)
761{
762    fbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
763}
764
765Bool
766sunCfbSetupScreen(
767    ScreenPtr pScreen,
768    pointer pbits,		/* pointer to screen bitmap */
769    int xsize,			/* in pixels */
770    int ysize,			/* in pixels */
771    int dpix,			/* dots per inch */
772    int dpiy,			/* dots per inch */
773    int width,			/* pixel width of frame buffer */
774    int	bpp			/* bits per pixel of root */
775)
776{
777    int ret;
778
779    ret = fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp);
780    pScreen->CreateGC = sunCfbCreateGC;
781    pScreen->GetImage = sunCfbGetImage;
782    pScreen->GetSpans = sunCfbGetSpans;
783    return ret;
784}
785
786/* Adapt cfb logic */
787
788Bool
789sunCfbFinishScreenInit(
790    ScreenPtr pScreen,
791    pointer pbits,		/* pointer to screen bitmap */
792    int xsize,			/* in pixels */
793    int ysize,			/* in pixels */
794    int dpix,			/* dots per inch */
795    int dpiy,			/* dots per inch */
796    int width,			/* pixel width of frame buffer */
797    int bpp
798)
799{
800    VisualPtr	visuals;
801    int		nvisuals;
802    DepthPtr	depths;
803    int		ndepths;
804    VisualID	defaultVisual;
805    int		rootdepth = 0;
806
807    if (!fbInitVisuals(&visuals, &depths, &nvisuals, &ndepths,
808		       &rootdepth, &defaultVisual, 1 << (bpp - 1), 8))
809	return FALSE;
810    if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
811			rootdepth, ndepths, depths,
812			defaultVisual, nvisuals, visuals))
813	return FALSE;
814    pScreen->CloseScreen = fbCloseScreen;
815    return TRUE;
816}
817
818
819Bool
820sunCfbScreenInit(
821    ScreenPtr pScreen,
822    pointer pbits,		/* pointer to screen bitmap */
823    int xsize,			/* in pixels */
824    int ysize,			/* in pixels */
825    int dpix,			/* dots per inch */
826    int dpiy,			/* dots per inch */
827    int width,			/* pixel width of frame buffer */
828    int bpp
829)
830{
831    if (!sunCfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy,
832			   width, bpp))
833	return FALSE;
834    return sunCfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix,
835				  dpiy, width, bpp);
836}
837
838#endif  /* SUNMAXDEPTH == 32 */
839#endif  /* SUNMAXDEPTH */
840