xref: /OK3568_Linux_fs/external/xserver/hw/xfree86/common/xf86Init.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Loosely based on code bearing the following copyright:
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *   Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun /*
7*4882a593Smuzhiyun  * Copyright (c) 1992-2003 by The XFree86 Project, Inc.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
10*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
11*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
12*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
14*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * The above copyright notice and this permission notice shall be included in
17*4882a593Smuzhiyun  * all copies or substantial portions of the Software.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22*4882a593Smuzhiyun  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
23*4882a593Smuzhiyun  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24*4882a593Smuzhiyun  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25*4882a593Smuzhiyun  * OTHER DEALINGS IN THE SOFTWARE.
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  * Except as contained in this notice, the name of the copyright holder(s)
28*4882a593Smuzhiyun  * and author(s) shall not be used in advertising or otherwise to promote
29*4882a593Smuzhiyun  * the sale, use or other dealings in this Software without prior written
30*4882a593Smuzhiyun  * authorization from the copyright holder(s) and author(s).
31*4882a593Smuzhiyun  */
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #ifdef HAVE_XORG_CONFIG_H
34*4882a593Smuzhiyun #include <xorg-config.h>
35*4882a593Smuzhiyun #endif
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #include <stdlib.h>
38*4882a593Smuzhiyun #include <errno.h>
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun #undef HAS_UTSNAME
41*4882a593Smuzhiyun #if !defined(WIN32)
42*4882a593Smuzhiyun #define HAS_UTSNAME 1
43*4882a593Smuzhiyun #include <sys/utsname.h>
44*4882a593Smuzhiyun #endif
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #include <X11/X.h>
47*4882a593Smuzhiyun #include <X11/Xmd.h>
48*4882a593Smuzhiyun #include <X11/Xproto.h>
49*4882a593Smuzhiyun #include <X11/Xatom.h>
50*4882a593Smuzhiyun #include "input.h"
51*4882a593Smuzhiyun #include "servermd.h"
52*4882a593Smuzhiyun #include "windowstr.h"
53*4882a593Smuzhiyun #include "scrnintstr.h"
54*4882a593Smuzhiyun #include "site.h"
55*4882a593Smuzhiyun #include "mi.h"
56*4882a593Smuzhiyun #include "dbus-core.h"
57*4882a593Smuzhiyun #include "systemd-logind.h"
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun #include "loaderProcs.h"
60*4882a593Smuzhiyun #ifdef XFreeXDGA
61*4882a593Smuzhiyun #include "dgaproc.h"
62*4882a593Smuzhiyun #endif
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #define XF86_OS_PRIVS
65*4882a593Smuzhiyun #include "xf86.h"
66*4882a593Smuzhiyun #include "xf86Priv.h"
67*4882a593Smuzhiyun #include "xf86Config.h"
68*4882a593Smuzhiyun #include "xf86_OSlib.h"
69*4882a593Smuzhiyun #include "xf86cmap.h"
70*4882a593Smuzhiyun #include "xorgVersion.h"
71*4882a593Smuzhiyun #include "xf86Build.h"
72*4882a593Smuzhiyun #include "mipointer.h"
73*4882a593Smuzhiyun #include <X11/extensions/XI.h>
74*4882a593Smuzhiyun #include <X11/extensions/XIproto.h>
75*4882a593Smuzhiyun #include "xf86Extensions.h"
76*4882a593Smuzhiyun #include "xf86DDC.h"
77*4882a593Smuzhiyun #include "xf86Xinput.h"
78*4882a593Smuzhiyun #include "xf86InPriv.h"
79*4882a593Smuzhiyun #include "picturestr.h"
80*4882a593Smuzhiyun #include "randrstr.h"
81*4882a593Smuzhiyun #include "glxvndabi.h"
82*4882a593Smuzhiyun #include "xf86Bus.h"
83*4882a593Smuzhiyun #ifdef XSERVER_LIBPCIACCESS
84*4882a593Smuzhiyun #include "xf86VGAarbiter.h"
85*4882a593Smuzhiyun #endif
86*4882a593Smuzhiyun #include "globals.h"
87*4882a593Smuzhiyun #include "xserver-properties.h"
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun #ifdef DPMSExtension
90*4882a593Smuzhiyun #include <X11/extensions/dpmsconst.h>
91*4882a593Smuzhiyun #include "dpmsproc.h"
92*4882a593Smuzhiyun #endif
93*4882a593Smuzhiyun #include <hotplug.h>
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun #ifdef XF86PM
96*4882a593Smuzhiyun void (*xf86OSPMClose) (void) = NULL;
97*4882a593Smuzhiyun #endif
98*4882a593Smuzhiyun static Bool xorgHWOpenConsole = FALSE;
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun /* Common pixmap formats */
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun static PixmapFormatRec formats[MAXFORMATS] = {
103*4882a593Smuzhiyun     {1, 1, BITMAP_SCANLINE_PAD},
104*4882a593Smuzhiyun     {4, 8, BITMAP_SCANLINE_PAD},
105*4882a593Smuzhiyun     {8, 8, BITMAP_SCANLINE_PAD},
106*4882a593Smuzhiyun     {15, 16, BITMAP_SCANLINE_PAD},
107*4882a593Smuzhiyun     {16, 16, BITMAP_SCANLINE_PAD},
108*4882a593Smuzhiyun     {24, 32, BITMAP_SCANLINE_PAD},
109*4882a593Smuzhiyun     {32, 32, BITMAP_SCANLINE_PAD},
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun static int numFormats = 7;
113*4882a593Smuzhiyun static Bool formatsDone = FALSE;
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #ifndef OSNAME
116*4882a593Smuzhiyun #define OSNAME " unknown"
117*4882a593Smuzhiyun #endif
118*4882a593Smuzhiyun #ifndef OSVENDOR
119*4882a593Smuzhiyun #define OSVENDOR ""
120*4882a593Smuzhiyun #endif
121*4882a593Smuzhiyun #ifndef PRE_RELEASE
122*4882a593Smuzhiyun #define PRE_RELEASE XORG_VERSION_SNAP
123*4882a593Smuzhiyun #endif
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun static void
xf86PrintBanner(void)126*4882a593Smuzhiyun xf86PrintBanner(void)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun #if PRE_RELEASE
129*4882a593Smuzhiyun     xf86ErrorFVerb(0, "\n"
130*4882a593Smuzhiyun                    "This is a pre-release version of the X server from "
131*4882a593Smuzhiyun                    XVENDORNAME ".\n" "It is not supported in any way.\n"
132*4882a593Smuzhiyun                    "Bugs may be filed in the bugzilla at http://bugs.freedesktop.org/.\n"
133*4882a593Smuzhiyun                    "Select the \"xorg\" product for bugs you find in this release.\n"
134*4882a593Smuzhiyun                    "Before reporting bugs in pre-release versions please check the\n"
135*4882a593Smuzhiyun                    "latest version in the X.Org Foundation git repository.\n"
136*4882a593Smuzhiyun                    "See http://wiki.x.org/wiki/GitPage for git access instructions.\n");
137*4882a593Smuzhiyun #endif
138*4882a593Smuzhiyun     xf86ErrorFVerb(0, "\nX.Org X Server %d.%d.%d",
139*4882a593Smuzhiyun                    XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH);
140*4882a593Smuzhiyun #if XORG_VERSION_SNAP > 0
141*4882a593Smuzhiyun     xf86ErrorFVerb(0, ".%d", XORG_VERSION_SNAP);
142*4882a593Smuzhiyun #endif
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun #if XORG_VERSION_SNAP >= 900
145*4882a593Smuzhiyun     /* When the minor number is 99, that signifies that the we are making
146*4882a593Smuzhiyun      * a release candidate for a major version.  (X.0.0)
147*4882a593Smuzhiyun      * When the patch number is 99, that signifies that the we are making
148*4882a593Smuzhiyun      * a release candidate for a minor version.  (X.Y.0)
149*4882a593Smuzhiyun      * When the patch number is < 99, then we are making a release
150*4882a593Smuzhiyun      * candidate for the next point release.  (X.Y.Z)
151*4882a593Smuzhiyun      */
152*4882a593Smuzhiyun #if XORG_VERSION_MINOR >= 99
153*4882a593Smuzhiyun     xf86ErrorFVerb(0, " (%d.0.0 RC %d)", XORG_VERSION_MAJOR + 1,
154*4882a593Smuzhiyun                    XORG_VERSION_SNAP - 900);
155*4882a593Smuzhiyun #elif XORG_VERSION_PATCH == 99
156*4882a593Smuzhiyun     xf86ErrorFVerb(0, " (%d.%d.0 RC %d)", XORG_VERSION_MAJOR,
157*4882a593Smuzhiyun                    XORG_VERSION_MINOR + 1, XORG_VERSION_SNAP - 900);
158*4882a593Smuzhiyun #else
159*4882a593Smuzhiyun     xf86ErrorFVerb(0, " (%d.%d.%d RC %d)", XORG_VERSION_MAJOR,
160*4882a593Smuzhiyun                    XORG_VERSION_MINOR, XORG_VERSION_PATCH + 1,
161*4882a593Smuzhiyun                    XORG_VERSION_SNAP - 900);
162*4882a593Smuzhiyun #endif
163*4882a593Smuzhiyun #endif
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun #ifdef XORG_CUSTOM_VERSION
166*4882a593Smuzhiyun     xf86ErrorFVerb(0, " (%s)", XORG_CUSTOM_VERSION);
167*4882a593Smuzhiyun #endif
168*4882a593Smuzhiyun     xf86ErrorFVerb(0, "\nX Protocol Version %d, Revision %d\n",
169*4882a593Smuzhiyun                    X_PROTOCOL, X_PROTOCOL_REVISION);
170*4882a593Smuzhiyun     xf86ErrorFVerb(0, "Build Operating System: %s %s\n", OSNAME, OSVENDOR);
171*4882a593Smuzhiyun #ifdef HAS_UTSNAME
172*4882a593Smuzhiyun     {
173*4882a593Smuzhiyun         struct utsname name;
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun         /* Linux & BSD state that 0 is success, SysV (including Solaris, HP-UX,
176*4882a593Smuzhiyun            and Irix) and Single Unix Spec 3 just say that non-negative is success.
177*4882a593Smuzhiyun            All agree that failure is represented by a negative number.
178*4882a593Smuzhiyun          */
179*4882a593Smuzhiyun         if (uname(&name) >= 0) {
180*4882a593Smuzhiyun             xf86ErrorFVerb(0, "Current Operating System: %s %s %s %s %s\n",
181*4882a593Smuzhiyun                            name.sysname, name.nodename, name.release,
182*4882a593Smuzhiyun                            name.version, name.machine);
183*4882a593Smuzhiyun #ifdef __linux__
184*4882a593Smuzhiyun             do {
185*4882a593Smuzhiyun                 char buf[80];
186*4882a593Smuzhiyun                 int fd = open("/proc/cmdline", O_RDONLY);
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun                 if (fd != -1) {
189*4882a593Smuzhiyun                     xf86ErrorFVerb(0, "Kernel command line: ");
190*4882a593Smuzhiyun                     memset(buf, 0, 80);
191*4882a593Smuzhiyun                     while (read(fd, buf, 80) > 0) {
192*4882a593Smuzhiyun                         xf86ErrorFVerb(0, "%.80s", buf);
193*4882a593Smuzhiyun                         memset(buf, 0, 80);
194*4882a593Smuzhiyun                     }
195*4882a593Smuzhiyun                     close(fd);
196*4882a593Smuzhiyun                 }
197*4882a593Smuzhiyun             } while (0);
198*4882a593Smuzhiyun #endif
199*4882a593Smuzhiyun         }
200*4882a593Smuzhiyun     }
201*4882a593Smuzhiyun #endif
202*4882a593Smuzhiyun #if defined(BUILD_DATE) && (BUILD_DATE > 19000000)
203*4882a593Smuzhiyun     {
204*4882a593Smuzhiyun         struct tm t;
205*4882a593Smuzhiyun         char buf[100];
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun         memset(&t, 0, sizeof(t));
208*4882a593Smuzhiyun         memset(buf, 0, sizeof(buf));
209*4882a593Smuzhiyun         t.tm_mday = BUILD_DATE % 100;
210*4882a593Smuzhiyun         t.tm_mon = (BUILD_DATE / 100) % 100 - 1;
211*4882a593Smuzhiyun         t.tm_year = BUILD_DATE / 10000 - 1900;
212*4882a593Smuzhiyun #if defined(BUILD_TIME)
213*4882a593Smuzhiyun         t.tm_sec = BUILD_TIME % 100;
214*4882a593Smuzhiyun         t.tm_min = (BUILD_TIME / 100) % 100;
215*4882a593Smuzhiyun         t.tm_hour = (BUILD_TIME / 10000) % 100;
216*4882a593Smuzhiyun         if (strftime(buf, sizeof(buf), "%d %B %Y  %I:%M:%S%p", &t))
217*4882a593Smuzhiyun             xf86ErrorFVerb(0, "Build Date: %s\n", buf);
218*4882a593Smuzhiyun #else
219*4882a593Smuzhiyun         if (strftime(buf, sizeof(buf), "%d %B %Y", &t))
220*4882a593Smuzhiyun             xf86ErrorFVerb(0, "Build Date: %s\n", buf);
221*4882a593Smuzhiyun #endif
222*4882a593Smuzhiyun     }
223*4882a593Smuzhiyun #endif
224*4882a593Smuzhiyun #if defined(BUILDERSTRING)
225*4882a593Smuzhiyun     xf86ErrorFVerb(0, "%s \n", BUILDERSTRING);
226*4882a593Smuzhiyun #endif
227*4882a593Smuzhiyun     xf86ErrorFVerb(0, "Current version of pixman: %s\n",
228*4882a593Smuzhiyun                    pixman_version_string());
229*4882a593Smuzhiyun     xf86ErrorFVerb(0, "\tBefore reporting problems, check "
230*4882a593Smuzhiyun                    "" __VENDORDWEBSUPPORT__ "\n"
231*4882a593Smuzhiyun                    "\tto make sure that you have the latest version.\n");
232*4882a593Smuzhiyun }
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun Bool
xf86PrivsElevated(void)235*4882a593Smuzhiyun xf86PrivsElevated(void)
236*4882a593Smuzhiyun {
237*4882a593Smuzhiyun     return PrivsElevated();
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun static void
TrapSignals(void)241*4882a593Smuzhiyun TrapSignals(void)
242*4882a593Smuzhiyun {
243*4882a593Smuzhiyun     if (xf86Info.notrapSignals) {
244*4882a593Smuzhiyun         OsSignal(SIGSEGV, SIG_DFL);
245*4882a593Smuzhiyun         OsSignal(SIGABRT, SIG_DFL);
246*4882a593Smuzhiyun         OsSignal(SIGILL, SIG_DFL);
247*4882a593Smuzhiyun #ifdef SIGEMT
248*4882a593Smuzhiyun         OsSignal(SIGEMT, SIG_DFL);
249*4882a593Smuzhiyun #endif
250*4882a593Smuzhiyun         OsSignal(SIGFPE, SIG_DFL);
251*4882a593Smuzhiyun         OsSignal(SIGBUS, SIG_DFL);
252*4882a593Smuzhiyun         OsSignal(SIGSYS, SIG_DFL);
253*4882a593Smuzhiyun         OsSignal(SIGXCPU, SIG_DFL);
254*4882a593Smuzhiyun         OsSignal(SIGXFSZ, SIG_DFL);
255*4882a593Smuzhiyun     }
256*4882a593Smuzhiyun }
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun static void
AddSeatId(CallbackListPtr * pcbl,void * data,void * screen)259*4882a593Smuzhiyun AddSeatId(CallbackListPtr *pcbl, void *data, void *screen)
260*4882a593Smuzhiyun {
261*4882a593Smuzhiyun     ScreenPtr pScreen = screen;
262*4882a593Smuzhiyun     Atom SeatAtom = MakeAtom(SEAT_ATOM_NAME, sizeof(SEAT_ATOM_NAME) - 1, TRUE);
263*4882a593Smuzhiyun     int err;
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun     err = dixChangeWindowProperty(serverClient, pScreen->root, SeatAtom,
266*4882a593Smuzhiyun                                   XA_STRING, 8, PropModeReplace,
267*4882a593Smuzhiyun                                   strlen(data) + 1, data, FALSE);
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun     if (err != Success)
270*4882a593Smuzhiyun         xf86DrvMsg(pScreen->myNum, X_WARNING,
271*4882a593Smuzhiyun                    "Failed to register seat property\n");
272*4882a593Smuzhiyun }
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun static void
AddVTAtoms(CallbackListPtr * pcbl,void * data,void * screen)275*4882a593Smuzhiyun AddVTAtoms(CallbackListPtr *pcbl, void *data, void *screen)
276*4882a593Smuzhiyun {
277*4882a593Smuzhiyun #define VT_ATOM_NAME         "XFree86_VT"
278*4882a593Smuzhiyun     int err, HasVT = 1;
279*4882a593Smuzhiyun     ScreenPtr pScreen = screen;
280*4882a593Smuzhiyun     Atom VTAtom = MakeAtom(VT_ATOM_NAME, sizeof(VT_ATOM_NAME) - 1, TRUE);
281*4882a593Smuzhiyun     Atom HasVTAtom = MakeAtom(HAS_VT_ATOM_NAME, sizeof(HAS_VT_ATOM_NAME) - 1,
282*4882a593Smuzhiyun                               TRUE);
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun     err = dixChangeWindowProperty(serverClient, pScreen->root, VTAtom,
285*4882a593Smuzhiyun                                   XA_INTEGER, 32, PropModeReplace, 1,
286*4882a593Smuzhiyun                                   &xf86Info.vtno, FALSE);
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun     err |= dixChangeWindowProperty(serverClient, pScreen->root, HasVTAtom,
289*4882a593Smuzhiyun                                    XA_INTEGER, 32, PropModeReplace, 1,
290*4882a593Smuzhiyun                                    &HasVT, FALSE);
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun     if (err != Success)
293*4882a593Smuzhiyun         xf86DrvMsg(pScreen->myNum, X_WARNING,
294*4882a593Smuzhiyun                    "Failed to register VT properties\n");
295*4882a593Smuzhiyun }
296*4882a593Smuzhiyun 
297*4882a593Smuzhiyun static Bool
xf86ScreenInit(ScreenPtr pScreen,int argc,char ** argv)298*4882a593Smuzhiyun xf86ScreenInit(ScreenPtr pScreen, int argc, char **argv)
299*4882a593Smuzhiyun {
300*4882a593Smuzhiyun     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun     pScrn->pScreen = pScreen;
303*4882a593Smuzhiyun     return pScrn->ScreenInit (pScreen, argc, argv);
304*4882a593Smuzhiyun }
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun static void
xf86EnsureRANDR(ScreenPtr pScreen)307*4882a593Smuzhiyun xf86EnsureRANDR(ScreenPtr pScreen)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun #ifdef RANDR
310*4882a593Smuzhiyun         if (!dixPrivateKeyRegistered(rrPrivKey) ||
311*4882a593Smuzhiyun             !rrGetScrPriv(pScreen))
312*4882a593Smuzhiyun             xf86RandRInit(pScreen);
313*4882a593Smuzhiyun #endif
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun /*
317*4882a593Smuzhiyun  * InitOutput --
318*4882a593Smuzhiyun  *	Initialize screenInfo for all actually accessible framebuffers.
319*4882a593Smuzhiyun  *      That includes vt-manager setup, querying all possible devices and
320*4882a593Smuzhiyun  *      collecting the pixmap formats.
321*4882a593Smuzhiyun  */
322*4882a593Smuzhiyun void
InitOutput(ScreenInfo * pScreenInfo,int argc,char ** argv)323*4882a593Smuzhiyun InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
324*4882a593Smuzhiyun {
325*4882a593Smuzhiyun     int i, j, k, scr_index;
326*4882a593Smuzhiyun     const char **modulelist;
327*4882a593Smuzhiyun     void **optionlist;
328*4882a593Smuzhiyun     Bool autoconfig = FALSE;
329*4882a593Smuzhiyun     Bool sigio_blocked = FALSE;
330*4882a593Smuzhiyun     Bool want_hw_access = FALSE;
331*4882a593Smuzhiyun     GDevPtr configured_device;
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun     xf86Initialising = TRUE;
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun     config_pre_init();
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun     if (serverGeneration == 1) {
338*4882a593Smuzhiyun         if ((xf86ServerName = strrchr(argv[0], '/')) != 0)
339*4882a593Smuzhiyun             xf86ServerName++;
340*4882a593Smuzhiyun         else
341*4882a593Smuzhiyun             xf86ServerName = argv[0];
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun         xf86PrintBanner();
344*4882a593Smuzhiyun         LogPrintMarkers();
345*4882a593Smuzhiyun         if (xf86LogFile) {
346*4882a593Smuzhiyun             time_t t;
347*4882a593Smuzhiyun             const char *ct;
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun             t = time(NULL);
350*4882a593Smuzhiyun             ct = ctime(&t);
351*4882a593Smuzhiyun             xf86MsgVerb(xf86LogFileFrom, 0, "Log file: \"%s\", Time: %s",
352*4882a593Smuzhiyun                         xf86LogFile, ct);
353*4882a593Smuzhiyun         }
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun         /* Read and parse the config file */
356*4882a593Smuzhiyun         if (!xf86DoConfigure && !xf86DoShowOptions) {
357*4882a593Smuzhiyun             switch (xf86HandleConfigFile(FALSE)) {
358*4882a593Smuzhiyun             case CONFIG_OK:
359*4882a593Smuzhiyun                 break;
360*4882a593Smuzhiyun             case CONFIG_PARSE_ERROR:
361*4882a593Smuzhiyun                 xf86Msg(X_ERROR, "Error parsing the config file\n");
362*4882a593Smuzhiyun                 return;
363*4882a593Smuzhiyun             case CONFIG_NOFILE:
364*4882a593Smuzhiyun                 autoconfig = TRUE;
365*4882a593Smuzhiyun                 break;
366*4882a593Smuzhiyun             }
367*4882a593Smuzhiyun         }
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun         TrapSignals();
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun         /* Initialise the loader */
372*4882a593Smuzhiyun         LoaderInit();
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun         /* Tell the loader the default module search path */
375*4882a593Smuzhiyun         LoaderSetPath(xf86ModulePath);
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun         if (xf86Info.ignoreABI) {
378*4882a593Smuzhiyun             LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL);
379*4882a593Smuzhiyun         }
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun         if (xf86DoShowOptions)
382*4882a593Smuzhiyun             DoShowOptions();
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun         dbus_core_init();
385*4882a593Smuzhiyun         systemd_logind_init();
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun         /* Do a general bus probe.  This will be a PCI probe for x86 platforms */
388*4882a593Smuzhiyun         xf86BusProbe();
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun         if (xf86DoConfigure)
391*4882a593Smuzhiyun             DoConfigure();
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun         if (autoconfig) {
394*4882a593Smuzhiyun             if (!xf86AutoConfig()) {
395*4882a593Smuzhiyun                 xf86Msg(X_ERROR, "Auto configuration failed\n");
396*4882a593Smuzhiyun                 return;
397*4882a593Smuzhiyun             }
398*4882a593Smuzhiyun         }
399*4882a593Smuzhiyun 
400*4882a593Smuzhiyun #ifdef XF86PM
401*4882a593Smuzhiyun         xf86OSPMClose = xf86OSPMOpen();
402*4882a593Smuzhiyun #endif
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun         xf86ExtensionInit();
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun         /* Load all modules specified explicitly in the config file */
407*4882a593Smuzhiyun         if ((modulelist = xf86ModulelistFromConfig(&optionlist))) {
408*4882a593Smuzhiyun             xf86LoadModules(modulelist, optionlist);
409*4882a593Smuzhiyun             free(modulelist);
410*4882a593Smuzhiyun             free(optionlist);
411*4882a593Smuzhiyun         }
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun         /* Load all driver modules specified in the config file */
414*4882a593Smuzhiyun         /* If there aren't any specified in the config file, autoconfig them */
415*4882a593Smuzhiyun         /* FIXME: Does not handle multiple active screen sections, but I'm not
416*4882a593Smuzhiyun          * sure if we really want to handle that case*/
417*4882a593Smuzhiyun         configured_device = xf86ConfigLayout.screens->screen->device;
418*4882a593Smuzhiyun         if ((!configured_device) || (!configured_device->driver)) {
419*4882a593Smuzhiyun             if (!autoConfigDevice(configured_device)) {
420*4882a593Smuzhiyun                 xf86Msg(X_ERROR, "Automatic driver configuration failed\n");
421*4882a593Smuzhiyun                 return;
422*4882a593Smuzhiyun             }
423*4882a593Smuzhiyun         }
424*4882a593Smuzhiyun         if ((modulelist = xf86DriverlistFromConfig())) {
425*4882a593Smuzhiyun             xf86LoadModules(modulelist, NULL);
426*4882a593Smuzhiyun             free(modulelist);
427*4882a593Smuzhiyun         }
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun         /* Load all input driver modules specified in the config file. */
430*4882a593Smuzhiyun         if ((modulelist = xf86InputDriverlistFromConfig())) {
431*4882a593Smuzhiyun             xf86LoadModules(modulelist, NULL);
432*4882a593Smuzhiyun             free(modulelist);
433*4882a593Smuzhiyun         }
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun         /*
436*4882a593Smuzhiyun          * It is expected that xf86AddDriver()/xf86AddInputDriver will be
437*4882a593Smuzhiyun          * called for each driver as it is loaded.  Those functions save the
438*4882a593Smuzhiyun          * module pointers for drivers.
439*4882a593Smuzhiyun          * XXX Nothing keeps track of them for other modules.
440*4882a593Smuzhiyun          */
441*4882a593Smuzhiyun         /* XXX What do we do if not all of these could be loaded? */
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun         /*
444*4882a593Smuzhiyun          * At this point, xf86DriverList[] is all filled in with entries for
445*4882a593Smuzhiyun          * each of the drivers to try and xf86NumDrivers has the number of
446*4882a593Smuzhiyun          * drivers.  If there are none, return now.
447*4882a593Smuzhiyun          */
448*4882a593Smuzhiyun 
449*4882a593Smuzhiyun         if (xf86NumDrivers == 0) {
450*4882a593Smuzhiyun             xf86Msg(X_ERROR, "No drivers available.\n");
451*4882a593Smuzhiyun             return;
452*4882a593Smuzhiyun         }
453*4882a593Smuzhiyun 
454*4882a593Smuzhiyun         /*
455*4882a593Smuzhiyun          * Call each of the Identify functions and call the driverFunc to check
456*4882a593Smuzhiyun          * if HW access is required.  The Identify functions print out some
457*4882a593Smuzhiyun          * identifying information, and anything else that might be
458*4882a593Smuzhiyun          * needed at this early stage.
459*4882a593Smuzhiyun          */
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun         for (i = 0; i < xf86NumDrivers; i++) {
462*4882a593Smuzhiyun             xorgHWFlags flags = HW_IO;
463*4882a593Smuzhiyun 
464*4882a593Smuzhiyun             if (xf86DriverList[i]->Identify != NULL)
465*4882a593Smuzhiyun                 xf86DriverList[i]->Identify(0);
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun             if (xf86DriverList[i]->driverFunc)
468*4882a593Smuzhiyun                 xf86DriverList[i]->driverFunc(NULL,
469*4882a593Smuzhiyun                                               GET_REQUIRED_HW_INTERFACES,
470*4882a593Smuzhiyun                                               &flags);
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun             if (NEED_IO_ENABLED(flags))
473*4882a593Smuzhiyun                 want_hw_access = TRUE;
474*4882a593Smuzhiyun 
475*4882a593Smuzhiyun             /* Non-seat0 X servers should not open console */
476*4882a593Smuzhiyun             if (!(flags & HW_SKIP_CONSOLE) && !ServerIsNotSeat0())
477*4882a593Smuzhiyun                 xorgHWOpenConsole = TRUE;
478*4882a593Smuzhiyun         }
479*4882a593Smuzhiyun 
480*4882a593Smuzhiyun         if (xorgHWOpenConsole)
481*4882a593Smuzhiyun             xf86OpenConsole();
482*4882a593Smuzhiyun         else
483*4882a593Smuzhiyun             xf86Info.dontVTSwitch = TRUE;
484*4882a593Smuzhiyun 
485*4882a593Smuzhiyun 	/* Enable full I/O access */
486*4882a593Smuzhiyun 	if (want_hw_access)
487*4882a593Smuzhiyun 	    xorgHWAccess = xf86EnableIO();
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun         if (xf86BusConfig() == FALSE)
490*4882a593Smuzhiyun             return;
491*4882a593Smuzhiyun 
492*4882a593Smuzhiyun         xf86PostProbe();
493*4882a593Smuzhiyun 
494*4882a593Smuzhiyun         /*
495*4882a593Smuzhiyun          * Sort the drivers to match the requested ording.  Using a slow
496*4882a593Smuzhiyun          * bubble sort.
497*4882a593Smuzhiyun          */
498*4882a593Smuzhiyun         for (j = 0; j < xf86NumScreens - 1; j++) {
499*4882a593Smuzhiyun             for (i = 0; i < xf86NumScreens - j - 1; i++) {
500*4882a593Smuzhiyun                 if (xf86Screens[i + 1]->confScreen->screennum <
501*4882a593Smuzhiyun                     xf86Screens[i]->confScreen->screennum) {
502*4882a593Smuzhiyun                     ScrnInfoPtr tmpScrn = xf86Screens[i + 1];
503*4882a593Smuzhiyun 
504*4882a593Smuzhiyun                     xf86Screens[i + 1] = xf86Screens[i];
505*4882a593Smuzhiyun                     xf86Screens[i] = tmpScrn;
506*4882a593Smuzhiyun                 }
507*4882a593Smuzhiyun             }
508*4882a593Smuzhiyun         }
509*4882a593Smuzhiyun         /* Fix up the indexes */
510*4882a593Smuzhiyun         for (i = 0; i < xf86NumScreens; i++) {
511*4882a593Smuzhiyun             xf86Screens[i]->scrnIndex = i;
512*4882a593Smuzhiyun         }
513*4882a593Smuzhiyun 
514*4882a593Smuzhiyun         /*
515*4882a593Smuzhiyun          * Call the driver's PreInit()'s to complete initialisation for the first
516*4882a593Smuzhiyun          * generation.
517*4882a593Smuzhiyun          */
518*4882a593Smuzhiyun 
519*4882a593Smuzhiyun         for (i = 0; i < xf86NumScreens; i++) {
520*4882a593Smuzhiyun             xf86VGAarbiterScrnInit(xf86Screens[i]);
521*4882a593Smuzhiyun             xf86VGAarbiterLock(xf86Screens[i]);
522*4882a593Smuzhiyun             if (xf86Screens[i]->PreInit &&
523*4882a593Smuzhiyun                 xf86Screens[i]->PreInit(xf86Screens[i], 0))
524*4882a593Smuzhiyun                 xf86Screens[i]->configured = TRUE;
525*4882a593Smuzhiyun             xf86VGAarbiterUnlock(xf86Screens[i]);
526*4882a593Smuzhiyun         }
527*4882a593Smuzhiyun         for (i = 0; i < xf86NumScreens; i++)
528*4882a593Smuzhiyun             if (!xf86Screens[i]->configured)
529*4882a593Smuzhiyun                 xf86DeleteScreen(xf86Screens[i--]);
530*4882a593Smuzhiyun 
531*4882a593Smuzhiyun         for (i = 0; i < xf86NumGPUScreens; i++) {
532*4882a593Smuzhiyun             xf86VGAarbiterScrnInit(xf86GPUScreens[i]);
533*4882a593Smuzhiyun             xf86VGAarbiterLock(xf86GPUScreens[i]);
534*4882a593Smuzhiyun             if (xf86GPUScreens[i]->PreInit &&
535*4882a593Smuzhiyun                 xf86GPUScreens[i]->PreInit(xf86GPUScreens[i], 0))
536*4882a593Smuzhiyun                 xf86GPUScreens[i]->configured = TRUE;
537*4882a593Smuzhiyun             xf86VGAarbiterUnlock(xf86GPUScreens[i]);
538*4882a593Smuzhiyun         }
539*4882a593Smuzhiyun         for (i = 0; i < xf86NumGPUScreens; i++)
540*4882a593Smuzhiyun             if (!xf86GPUScreens[i]->configured)
541*4882a593Smuzhiyun                 xf86DeleteScreen(xf86GPUScreens[i--]);
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun         /*
544*4882a593Smuzhiyun          * If no screens left, return now.
545*4882a593Smuzhiyun          */
546*4882a593Smuzhiyun 
547*4882a593Smuzhiyun         if (xf86NumScreens == 0) {
548*4882a593Smuzhiyun             xf86Msg(X_ERROR,
549*4882a593Smuzhiyun                     "Screen(s) found, but none have a usable configuration.\n");
550*4882a593Smuzhiyun             return;
551*4882a593Smuzhiyun         }
552*4882a593Smuzhiyun 
553*4882a593Smuzhiyun         for (i = 0; i < xf86NumScreens; i++) {
554*4882a593Smuzhiyun             if (xf86Screens[i]->name == NULL) {
555*4882a593Smuzhiyun                 char *tmp;
556*4882a593Smuzhiyun                 XNFasprintf(&tmp, "screen%d", i);
557*4882a593Smuzhiyun                 xf86Screens[i]->name = tmp;
558*4882a593Smuzhiyun                 xf86MsgVerb(X_WARNING, 0,
559*4882a593Smuzhiyun                             "Screen driver %d has no name set, using `%s'.\n",
560*4882a593Smuzhiyun                             i, xf86Screens[i]->name);
561*4882a593Smuzhiyun             }
562*4882a593Smuzhiyun         }
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun         /* Remove (unload) drivers that are not required */
565*4882a593Smuzhiyun         for (i = 0; i < xf86NumDrivers; i++)
566*4882a593Smuzhiyun             if (xf86DriverList[i] && xf86DriverList[i]->refCount <= 0)
567*4882a593Smuzhiyun                 xf86DeleteDriver(i);
568*4882a593Smuzhiyun 
569*4882a593Smuzhiyun         /*
570*4882a593Smuzhiyun          * At this stage we know how many screens there are.
571*4882a593Smuzhiyun          */
572*4882a593Smuzhiyun 
573*4882a593Smuzhiyun         for (i = 0; i < xf86NumScreens; i++)
574*4882a593Smuzhiyun             xf86InitViewport(xf86Screens[i]);
575*4882a593Smuzhiyun 
576*4882a593Smuzhiyun         /*
577*4882a593Smuzhiyun          * Collect all pixmap formats and check for conflicts at the display
578*4882a593Smuzhiyun          * level.  Should we die here?  Or just delete the offending screens?
579*4882a593Smuzhiyun          */
580*4882a593Smuzhiyun         for (i = 0; i < xf86NumScreens; i++) {
581*4882a593Smuzhiyun             if (xf86Screens[i]->imageByteOrder !=
582*4882a593Smuzhiyun                 xf86Screens[0]->imageByteOrder)
583*4882a593Smuzhiyun                 FatalError("Inconsistent display bitmapBitOrder.  Exiting\n");
584*4882a593Smuzhiyun             if (xf86Screens[i]->bitmapScanlinePad !=
585*4882a593Smuzhiyun                 xf86Screens[0]->bitmapScanlinePad)
586*4882a593Smuzhiyun                 FatalError
587*4882a593Smuzhiyun                     ("Inconsistent display bitmapScanlinePad.  Exiting\n");
588*4882a593Smuzhiyun             if (xf86Screens[i]->bitmapScanlineUnit !=
589*4882a593Smuzhiyun                 xf86Screens[0]->bitmapScanlineUnit)
590*4882a593Smuzhiyun                 FatalError
591*4882a593Smuzhiyun                     ("Inconsistent display bitmapScanlineUnit.  Exiting\n");
592*4882a593Smuzhiyun             if (xf86Screens[i]->bitmapBitOrder !=
593*4882a593Smuzhiyun                 xf86Screens[0]->bitmapBitOrder)
594*4882a593Smuzhiyun                 FatalError("Inconsistent display bitmapBitOrder.  Exiting\n");
595*4882a593Smuzhiyun         }
596*4882a593Smuzhiyun 
597*4882a593Smuzhiyun         /* Collect additional formats */
598*4882a593Smuzhiyun         for (i = 0; i < xf86NumScreens; i++) {
599*4882a593Smuzhiyun             for (j = 0; j < xf86Screens[i]->numFormats; j++) {
600*4882a593Smuzhiyun                 for (k = 0;; k++) {
601*4882a593Smuzhiyun                     if (k >= numFormats) {
602*4882a593Smuzhiyun                         if (k >= MAXFORMATS)
603*4882a593Smuzhiyun                             FatalError("Too many pixmap formats!  Exiting\n");
604*4882a593Smuzhiyun                         formats[k] = xf86Screens[i]->formats[j];
605*4882a593Smuzhiyun                         numFormats++;
606*4882a593Smuzhiyun                         break;
607*4882a593Smuzhiyun                     }
608*4882a593Smuzhiyun                     if (formats[k].depth == xf86Screens[i]->formats[j].depth) {
609*4882a593Smuzhiyun                         if ((formats[k].bitsPerPixel ==
610*4882a593Smuzhiyun                              xf86Screens[i]->formats[j].bitsPerPixel) &&
611*4882a593Smuzhiyun                             (formats[k].scanlinePad ==
612*4882a593Smuzhiyun                              xf86Screens[i]->formats[j].scanlinePad))
613*4882a593Smuzhiyun                             break;
614*4882a593Smuzhiyun                         FatalError("Inconsistent pixmap format for depth %d."
615*4882a593Smuzhiyun                                    "  Exiting\n", formats[k].depth);
616*4882a593Smuzhiyun                     }
617*4882a593Smuzhiyun                 }
618*4882a593Smuzhiyun             }
619*4882a593Smuzhiyun         }
620*4882a593Smuzhiyun         formatsDone = TRUE;
621*4882a593Smuzhiyun     }
622*4882a593Smuzhiyun     else {
623*4882a593Smuzhiyun         /*
624*4882a593Smuzhiyun          * serverGeneration != 1; some OSs have to do things here, too.
625*4882a593Smuzhiyun          */
626*4882a593Smuzhiyun         if (xorgHWOpenConsole)
627*4882a593Smuzhiyun             xf86OpenConsole();
628*4882a593Smuzhiyun 
629*4882a593Smuzhiyun #ifdef XF86PM
630*4882a593Smuzhiyun         /*
631*4882a593Smuzhiyun            should we reopen it here? We need to deal with an already opened
632*4882a593Smuzhiyun            device. We could leave this to the OS layer. For now we simply
633*4882a593Smuzhiyun            close it here
634*4882a593Smuzhiyun          */
635*4882a593Smuzhiyun         if (xf86OSPMClose)
636*4882a593Smuzhiyun             xf86OSPMClose();
637*4882a593Smuzhiyun         if ((xf86OSPMClose = xf86OSPMOpen()) != NULL)
638*4882a593Smuzhiyun             xf86MsgVerb(X_INFO, 3, "APM registered successfully\n");
639*4882a593Smuzhiyun #endif
640*4882a593Smuzhiyun 
641*4882a593Smuzhiyun         /* Make sure full I/O access is enabled */
642*4882a593Smuzhiyun         if (xorgHWAccess)
643*4882a593Smuzhiyun             xf86EnableIO();
644*4882a593Smuzhiyun     }
645*4882a593Smuzhiyun 
646*4882a593Smuzhiyun     if (xf86Info.vtno >= 0)
647*4882a593Smuzhiyun         AddCallback(&RootWindowFinalizeCallback, AddVTAtoms, NULL);
648*4882a593Smuzhiyun 
649*4882a593Smuzhiyun     if (SeatId)
650*4882a593Smuzhiyun         AddCallback(&RootWindowFinalizeCallback, AddSeatId, SeatId);
651*4882a593Smuzhiyun 
652*4882a593Smuzhiyun     /*
653*4882a593Smuzhiyun      * Use the previously collected parts to setup pScreenInfo
654*4882a593Smuzhiyun      */
655*4882a593Smuzhiyun 
656*4882a593Smuzhiyun     pScreenInfo->imageByteOrder = xf86Screens[0]->imageByteOrder;
657*4882a593Smuzhiyun     pScreenInfo->bitmapScanlinePad = xf86Screens[0]->bitmapScanlinePad;
658*4882a593Smuzhiyun     pScreenInfo->bitmapScanlineUnit = xf86Screens[0]->bitmapScanlineUnit;
659*4882a593Smuzhiyun     pScreenInfo->bitmapBitOrder = xf86Screens[0]->bitmapBitOrder;
660*4882a593Smuzhiyun     pScreenInfo->numPixmapFormats = numFormats;
661*4882a593Smuzhiyun     for (i = 0; i < numFormats; i++)
662*4882a593Smuzhiyun         pScreenInfo->formats[i] = formats[i];
663*4882a593Smuzhiyun 
664*4882a593Smuzhiyun     /* Make sure the server's VT is active */
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun     if (serverGeneration != 1) {
667*4882a593Smuzhiyun         xf86Resetting = TRUE;
668*4882a593Smuzhiyun         /* All screens are in the same state, so just check the first */
669*4882a593Smuzhiyun         if (!xf86VTOwner()) {
670*4882a593Smuzhiyun #ifdef HAS_USL_VTS
671*4882a593Smuzhiyun             ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ);
672*4882a593Smuzhiyun #endif
673*4882a593Smuzhiyun             input_lock();
674*4882a593Smuzhiyun             sigio_blocked = TRUE;
675*4882a593Smuzhiyun         }
676*4882a593Smuzhiyun     }
677*4882a593Smuzhiyun 
678*4882a593Smuzhiyun     for (i = 0; i < xf86NumScreens; i++)
679*4882a593Smuzhiyun         if (!xf86ColormapAllocatePrivates(xf86Screens[i]))
680*4882a593Smuzhiyun             FatalError("Cannot register DDX private keys");
681*4882a593Smuzhiyun 
682*4882a593Smuzhiyun     if (!dixRegisterPrivateKey(&xf86ScreenKeyRec, PRIVATE_SCREEN, 0))
683*4882a593Smuzhiyun         FatalError("Cannot register DDX private keys");
684*4882a593Smuzhiyun 
685*4882a593Smuzhiyun     for (i = 0; i < xf86NumScreens; i++) {
686*4882a593Smuzhiyun         xf86VGAarbiterLock(xf86Screens[i]);
687*4882a593Smuzhiyun         /*
688*4882a593Smuzhiyun          * Almost everything uses these defaults, and many of those that
689*4882a593Smuzhiyun          * don't, will wrap them.
690*4882a593Smuzhiyun          */
691*4882a593Smuzhiyun         xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess;
692*4882a593Smuzhiyun #ifdef XFreeXDGA
693*4882a593Smuzhiyun         xf86Screens[i]->SetDGAMode = xf86SetDGAMode;
694*4882a593Smuzhiyun #endif
695*4882a593Smuzhiyun         xf86Screens[i]->DPMSSet = NULL;
696*4882a593Smuzhiyun         xf86Screens[i]->LoadPalette = NULL;
697*4882a593Smuzhiyun         xf86Screens[i]->SetOverscan = NULL;
698*4882a593Smuzhiyun         xf86Screens[i]->DriverFunc = NULL;
699*4882a593Smuzhiyun         xf86Screens[i]->pScreen = NULL;
700*4882a593Smuzhiyun         scr_index = AddScreen(xf86ScreenInit, argc, argv);
701*4882a593Smuzhiyun         xf86VGAarbiterUnlock(xf86Screens[i]);
702*4882a593Smuzhiyun         if (scr_index == i) {
703*4882a593Smuzhiyun             /*
704*4882a593Smuzhiyun              * Hook in our ScrnInfoRec, and initialise some other pScreen
705*4882a593Smuzhiyun              * fields.
706*4882a593Smuzhiyun              */
707*4882a593Smuzhiyun             dixSetPrivate(&screenInfo.screens[scr_index]->devPrivates,
708*4882a593Smuzhiyun                           xf86ScreenKey, xf86Screens[i]);
709*4882a593Smuzhiyun             xf86Screens[i]->pScreen = screenInfo.screens[scr_index];
710*4882a593Smuzhiyun             /* The driver should set this, but make sure it is set anyway */
711*4882a593Smuzhiyun             xf86Screens[i]->vtSema = TRUE;
712*4882a593Smuzhiyun         }
713*4882a593Smuzhiyun         else {
714*4882a593Smuzhiyun             /* This shouldn't normally happen */
715*4882a593Smuzhiyun             FatalError("AddScreen/ScreenInit failed for driver %d\n", i);
716*4882a593Smuzhiyun         }
717*4882a593Smuzhiyun 
718*4882a593Smuzhiyun         DebugF("InitOutput - xf86Screens[%d]->pScreen = %p\n",
719*4882a593Smuzhiyun                i, xf86Screens[i]->pScreen);
720*4882a593Smuzhiyun         DebugF("xf86Screens[%d]->pScreen->CreateWindow = %p\n",
721*4882a593Smuzhiyun                i, xf86Screens[i]->pScreen->CreateWindow);
722*4882a593Smuzhiyun 
723*4882a593Smuzhiyun         if (PictureGetSubpixelOrder(xf86Screens[i]->pScreen) == SubPixelUnknown) {
724*4882a593Smuzhiyun             xf86MonPtr DDC = (xf86MonPtr) (xf86Screens[i]->monitor->DDC);
725*4882a593Smuzhiyun 
726*4882a593Smuzhiyun             PictureSetSubpixelOrder(xf86Screens[i]->pScreen,
727*4882a593Smuzhiyun                                     DDC ?
728*4882a593Smuzhiyun                                     (DDC->features.input_type ?
729*4882a593Smuzhiyun                                      SubPixelHorizontalRGB : SubPixelNone) :
730*4882a593Smuzhiyun                                     SubPixelUnknown);
731*4882a593Smuzhiyun         }
732*4882a593Smuzhiyun 
733*4882a593Smuzhiyun         /*
734*4882a593Smuzhiyun          * If the driver hasn't set up its own RANDR support, install the
735*4882a593Smuzhiyun          * fallback support.
736*4882a593Smuzhiyun          */
737*4882a593Smuzhiyun         xf86EnsureRANDR(xf86Screens[i]->pScreen);
738*4882a593Smuzhiyun     }
739*4882a593Smuzhiyun 
740*4882a593Smuzhiyun     for (i = 0; i < xf86NumGPUScreens; i++) {
741*4882a593Smuzhiyun         ScrnInfoPtr pScrn = xf86GPUScreens[i];
742*4882a593Smuzhiyun         xf86VGAarbiterLock(pScrn);
743*4882a593Smuzhiyun 
744*4882a593Smuzhiyun         /*
745*4882a593Smuzhiyun          * Almost everything uses these defaults, and many of those that
746*4882a593Smuzhiyun          * don't, will wrap them.
747*4882a593Smuzhiyun          */
748*4882a593Smuzhiyun         pScrn->EnableDisableFBAccess = xf86EnableDisableFBAccess;
749*4882a593Smuzhiyun #ifdef XFreeXDGA
750*4882a593Smuzhiyun         pScrn->SetDGAMode = xf86SetDGAMode;
751*4882a593Smuzhiyun #endif
752*4882a593Smuzhiyun         pScrn->DPMSSet = NULL;
753*4882a593Smuzhiyun         pScrn->LoadPalette = NULL;
754*4882a593Smuzhiyun         pScrn->SetOverscan = NULL;
755*4882a593Smuzhiyun         pScrn->DriverFunc = NULL;
756*4882a593Smuzhiyun         pScrn->pScreen = NULL;
757*4882a593Smuzhiyun         scr_index = AddGPUScreen(xf86ScreenInit, argc, argv);
758*4882a593Smuzhiyun         xf86VGAarbiterUnlock(pScrn);
759*4882a593Smuzhiyun         if (scr_index == i) {
760*4882a593Smuzhiyun             dixSetPrivate(&screenInfo.gpuscreens[scr_index]->devPrivates,
761*4882a593Smuzhiyun                           xf86ScreenKey, xf86GPUScreens[i]);
762*4882a593Smuzhiyun             pScrn->pScreen = screenInfo.gpuscreens[scr_index];
763*4882a593Smuzhiyun             /* The driver should set this, but make sure it is set anyway */
764*4882a593Smuzhiyun             pScrn->vtSema = TRUE;
765*4882a593Smuzhiyun         } else {
766*4882a593Smuzhiyun             FatalError("AddScreen/ScreenInit failed for gpu driver %d %d\n", i, scr_index);
767*4882a593Smuzhiyun         }
768*4882a593Smuzhiyun     }
769*4882a593Smuzhiyun 
770*4882a593Smuzhiyun     for (i = 0; i < xf86NumGPUScreens; i++)
771*4882a593Smuzhiyun         AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
772*4882a593Smuzhiyun 
773*4882a593Smuzhiyun     xf86VGAarbiterWrapFunctions();
774*4882a593Smuzhiyun     if (sigio_blocked)
775*4882a593Smuzhiyun         input_unlock();
776*4882a593Smuzhiyun 
777*4882a593Smuzhiyun     xf86InitOrigins();
778*4882a593Smuzhiyun 
779*4882a593Smuzhiyun     xf86Resetting = FALSE;
780*4882a593Smuzhiyun     xf86Initialising = FALSE;
781*4882a593Smuzhiyun 
782*4882a593Smuzhiyun     RegisterBlockAndWakeupHandlers((ServerBlockHandlerProcPtr) NoopDDA, xf86Wakeup,
783*4882a593Smuzhiyun                                    NULL);
784*4882a593Smuzhiyun }
785*4882a593Smuzhiyun 
786*4882a593Smuzhiyun /**
787*4882a593Smuzhiyun  * Initialize all supported input devices present and referenced in the
788*4882a593Smuzhiyun  * xorg.conf.
789*4882a593Smuzhiyun  */
790*4882a593Smuzhiyun void
InitInput(int argc,char ** argv)791*4882a593Smuzhiyun InitInput(int argc, char **argv)
792*4882a593Smuzhiyun {
793*4882a593Smuzhiyun     InputInfoPtr *pInfo;
794*4882a593Smuzhiyun     DeviceIntPtr dev;
795*4882a593Smuzhiyun 
796*4882a593Smuzhiyun     xf86Info.vtRequestsPending = FALSE;
797*4882a593Smuzhiyun 
798*4882a593Smuzhiyun     /* Enable threaded input */
799*4882a593Smuzhiyun     InputThreadPreInit();
800*4882a593Smuzhiyun 
801*4882a593Smuzhiyun     mieqInit();
802*4882a593Smuzhiyun 
803*4882a593Smuzhiyun     /* Initialize all configured input devices */
804*4882a593Smuzhiyun     for (pInfo = xf86ConfigLayout.inputs; pInfo && *pInfo; pInfo++) {
805*4882a593Smuzhiyun         (*pInfo)->options =
806*4882a593Smuzhiyun             xf86AddNewOption((*pInfo)->options, "driver", (*pInfo)->driver);
807*4882a593Smuzhiyun         (*pInfo)->options =
808*4882a593Smuzhiyun             xf86AddNewOption((*pInfo)->options, "identifier", (*pInfo)->name);
809*4882a593Smuzhiyun         /* If one fails, the others will too */
810*4882a593Smuzhiyun         if (NewInputDeviceRequest((*pInfo)->options, NULL, &dev) == BadAlloc)
811*4882a593Smuzhiyun             break;
812*4882a593Smuzhiyun     }
813*4882a593Smuzhiyun 
814*4882a593Smuzhiyun     config_init();
815*4882a593Smuzhiyun }
816*4882a593Smuzhiyun 
817*4882a593Smuzhiyun void
CloseInput(void)818*4882a593Smuzhiyun CloseInput(void)
819*4882a593Smuzhiyun {
820*4882a593Smuzhiyun     config_fini();
821*4882a593Smuzhiyun     mieqFini();
822*4882a593Smuzhiyun }
823*4882a593Smuzhiyun 
824*4882a593Smuzhiyun /*
825*4882a593Smuzhiyun  * OsVendorInit --
826*4882a593Smuzhiyun  *      OS/Vendor-specific initialisations.  Called from OsInit(), which
827*4882a593Smuzhiyun  *      is called by dix before establishing the well known sockets.
828*4882a593Smuzhiyun  */
829*4882a593Smuzhiyun 
830*4882a593Smuzhiyun void
OsVendorInit(void)831*4882a593Smuzhiyun OsVendorInit(void)
832*4882a593Smuzhiyun {
833*4882a593Smuzhiyun     static Bool beenHere = FALSE;
834*4882a593Smuzhiyun 
835*4882a593Smuzhiyun     OsSignal(SIGCHLD, SIG_DFL);   /* Need to wait for child processes */
836*4882a593Smuzhiyun 
837*4882a593Smuzhiyun     if (!beenHere) {
838*4882a593Smuzhiyun         umask(022);
839*4882a593Smuzhiyun         xf86LogInit();
840*4882a593Smuzhiyun     }
841*4882a593Smuzhiyun 
842*4882a593Smuzhiyun     /* Set stderr to non-blocking. */
843*4882a593Smuzhiyun #ifndef O_NONBLOCK
844*4882a593Smuzhiyun #if defined(FNDELAY)
845*4882a593Smuzhiyun #define O_NONBLOCK FNDELAY
846*4882a593Smuzhiyun #elif defined(O_NDELAY)
847*4882a593Smuzhiyun #define O_NONBLOCK O_NDELAY
848*4882a593Smuzhiyun #endif
849*4882a593Smuzhiyun 
850*4882a593Smuzhiyun #ifdef O_NONBLOCK
851*4882a593Smuzhiyun     if (!beenHere) {
852*4882a593Smuzhiyun         if (PrivsElevated()) {
853*4882a593Smuzhiyun             int status;
854*4882a593Smuzhiyun 
855*4882a593Smuzhiyun             status = fcntl(fileno(stderr), F_GETFL, 0);
856*4882a593Smuzhiyun             if (status != -1) {
857*4882a593Smuzhiyun                 fcntl(fileno(stderr), F_SETFL, status | O_NONBLOCK);
858*4882a593Smuzhiyun             }
859*4882a593Smuzhiyun         }
860*4882a593Smuzhiyun     }
861*4882a593Smuzhiyun #endif
862*4882a593Smuzhiyun #endif
863*4882a593Smuzhiyun 
864*4882a593Smuzhiyun     beenHere = TRUE;
865*4882a593Smuzhiyun }
866*4882a593Smuzhiyun 
867*4882a593Smuzhiyun /*
868*4882a593Smuzhiyun  * ddxGiveUp --
869*4882a593Smuzhiyun  *      Device dependent cleanup. Called by by dix before normal server death.
870*4882a593Smuzhiyun  *      For SYSV386 we must switch the terminal back to normal mode. No error-
871*4882a593Smuzhiyun  *      checking here, since there should be restored as much as possible.
872*4882a593Smuzhiyun  */
873*4882a593Smuzhiyun 
874*4882a593Smuzhiyun void
ddxGiveUp(enum ExitCode error)875*4882a593Smuzhiyun ddxGiveUp(enum ExitCode error)
876*4882a593Smuzhiyun {
877*4882a593Smuzhiyun     int i;
878*4882a593Smuzhiyun 
879*4882a593Smuzhiyun     xf86VGAarbiterFini();
880*4882a593Smuzhiyun 
881*4882a593Smuzhiyun #ifdef XF86PM
882*4882a593Smuzhiyun     if (xf86OSPMClose)
883*4882a593Smuzhiyun         xf86OSPMClose();
884*4882a593Smuzhiyun     xf86OSPMClose = NULL;
885*4882a593Smuzhiyun #endif
886*4882a593Smuzhiyun 
887*4882a593Smuzhiyun     for (i = 0; i < xf86NumScreens; i++) {
888*4882a593Smuzhiyun         /*
889*4882a593Smuzhiyun          * zero all access functions to
890*4882a593Smuzhiyun          * trap calls when switched away.
891*4882a593Smuzhiyun          */
892*4882a593Smuzhiyun         xf86Screens[i]->vtSema = FALSE;
893*4882a593Smuzhiyun     }
894*4882a593Smuzhiyun 
895*4882a593Smuzhiyun #ifdef XFreeXDGA
896*4882a593Smuzhiyun     DGAShutdown();
897*4882a593Smuzhiyun #endif
898*4882a593Smuzhiyun 
899*4882a593Smuzhiyun     if (xorgHWOpenConsole)
900*4882a593Smuzhiyun         xf86CloseConsole();
901*4882a593Smuzhiyun 
902*4882a593Smuzhiyun     systemd_logind_fini();
903*4882a593Smuzhiyun     dbus_core_fini();
904*4882a593Smuzhiyun 
905*4882a593Smuzhiyun     xf86CloseLog(error);
906*4882a593Smuzhiyun }
907*4882a593Smuzhiyun 
908*4882a593Smuzhiyun /*
909*4882a593Smuzhiyun  * AbortDDX --
910*4882a593Smuzhiyun  *      DDX - specific abort routine.  Called by AbortServer(). The attempt is
911*4882a593Smuzhiyun  *      made to restore all original setting of the displays. Also all devices
912*4882a593Smuzhiyun  *      are closed.
913*4882a593Smuzhiyun  */
914*4882a593Smuzhiyun 
915*4882a593Smuzhiyun void
AbortDDX(enum ExitCode error)916*4882a593Smuzhiyun AbortDDX(enum ExitCode error)
917*4882a593Smuzhiyun {
918*4882a593Smuzhiyun     int i;
919*4882a593Smuzhiyun 
920*4882a593Smuzhiyun     input_lock();
921*4882a593Smuzhiyun 
922*4882a593Smuzhiyun     /*
923*4882a593Smuzhiyun      * try to restore the original video state
924*4882a593Smuzhiyun      */
925*4882a593Smuzhiyun #ifdef DPMSExtension            /* Turn screens back on */
926*4882a593Smuzhiyun     if (DPMSPowerLevel != DPMSModeOn)
927*4882a593Smuzhiyun         DPMSSet(serverClient, DPMSModeOn);
928*4882a593Smuzhiyun #endif
929*4882a593Smuzhiyun     if (xf86Screens) {
930*4882a593Smuzhiyun         for (i = 0; i < xf86NumScreens; i++)
931*4882a593Smuzhiyun             if (xf86Screens[i]->vtSema) {
932*4882a593Smuzhiyun                 /*
933*4882a593Smuzhiyun                  * if we are aborting before ScreenInit() has finished
934*4882a593Smuzhiyun                  * we might not have been wrapped yet. Therefore enable
935*4882a593Smuzhiyun                  * screen explicitely.
936*4882a593Smuzhiyun                  */
937*4882a593Smuzhiyun                 xf86VGAarbiterLock(xf86Screens[i]);
938*4882a593Smuzhiyun                 (xf86Screens[i]->LeaveVT) (xf86Screens[i]);
939*4882a593Smuzhiyun                 xf86VGAarbiterUnlock(xf86Screens[i]);
940*4882a593Smuzhiyun             }
941*4882a593Smuzhiyun     }
942*4882a593Smuzhiyun 
943*4882a593Smuzhiyun     /*
944*4882a593Smuzhiyun      * This is needed for an abnormal server exit, since the normal exit stuff
945*4882a593Smuzhiyun      * MUST also be performed (i.e. the vt must be left in a defined state)
946*4882a593Smuzhiyun      */
947*4882a593Smuzhiyun     ddxGiveUp(error);
948*4882a593Smuzhiyun }
949*4882a593Smuzhiyun 
950*4882a593Smuzhiyun void
OsVendorFatalError(const char * f,va_list args)951*4882a593Smuzhiyun OsVendorFatalError(const char *f, va_list args)
952*4882a593Smuzhiyun {
953*4882a593Smuzhiyun #ifdef VENDORSUPPORT
954*4882a593Smuzhiyun     ErrorFSigSafe("\nPlease refer to your Operating System Vendor support "
955*4882a593Smuzhiyun                  "pages\nat %s for support on this crash.\n", VENDORSUPPORT);
956*4882a593Smuzhiyun #else
957*4882a593Smuzhiyun     ErrorFSigSafe("\nPlease consult the " XVENDORNAME " support \n\t at "
958*4882a593Smuzhiyun                  __VENDORDWEBSUPPORT__ "\n for help. \n");
959*4882a593Smuzhiyun #endif
960*4882a593Smuzhiyun     if (xf86LogFile && xf86LogFileWasOpened)
961*4882a593Smuzhiyun         ErrorFSigSafe("Please also check the log file at \"%s\" for additional "
962*4882a593Smuzhiyun                      "information.\n", xf86LogFile);
963*4882a593Smuzhiyun     ErrorFSigSafe("\n");
964*4882a593Smuzhiyun }
965*4882a593Smuzhiyun 
966*4882a593Smuzhiyun int
xf86SetVerbosity(int verb)967*4882a593Smuzhiyun xf86SetVerbosity(int verb)
968*4882a593Smuzhiyun {
969*4882a593Smuzhiyun     int save = xf86Verbose;
970*4882a593Smuzhiyun 
971*4882a593Smuzhiyun     xf86Verbose = verb;
972*4882a593Smuzhiyun     LogSetParameter(XLOG_VERBOSITY, verb);
973*4882a593Smuzhiyun     return save;
974*4882a593Smuzhiyun }
975*4882a593Smuzhiyun 
976*4882a593Smuzhiyun int
xf86SetLogVerbosity(int verb)977*4882a593Smuzhiyun xf86SetLogVerbosity(int verb)
978*4882a593Smuzhiyun {
979*4882a593Smuzhiyun     int save = xf86LogVerbose;
980*4882a593Smuzhiyun 
981*4882a593Smuzhiyun     xf86LogVerbose = verb;
982*4882a593Smuzhiyun     LogSetParameter(XLOG_FILE_VERBOSITY, verb);
983*4882a593Smuzhiyun     return save;
984*4882a593Smuzhiyun }
985*4882a593Smuzhiyun 
986*4882a593Smuzhiyun static void
xf86PrintDefaultModulePath(void)987*4882a593Smuzhiyun xf86PrintDefaultModulePath(void)
988*4882a593Smuzhiyun {
989*4882a593Smuzhiyun     ErrorF("%s\n", DEFAULT_MODULE_PATH);
990*4882a593Smuzhiyun }
991*4882a593Smuzhiyun 
992*4882a593Smuzhiyun static void
xf86PrintDefaultLibraryPath(void)993*4882a593Smuzhiyun xf86PrintDefaultLibraryPath(void)
994*4882a593Smuzhiyun {
995*4882a593Smuzhiyun     ErrorF("%s\n", DEFAULT_LIBRARY_PATH);
996*4882a593Smuzhiyun }
997*4882a593Smuzhiyun 
998*4882a593Smuzhiyun static void
xf86CheckPrivs(const char * option,const char * arg)999*4882a593Smuzhiyun xf86CheckPrivs(const char *option, const char *arg)
1000*4882a593Smuzhiyun {
1001*4882a593Smuzhiyun     if (PrivsElevated() && !xf86PathIsSafe(arg)) {
1002*4882a593Smuzhiyun         FatalError("\nInvalid argument for %s - \"%s\"\n"
1003*4882a593Smuzhiyun                     "\tWith elevated privileges %s must specify a relative path\n"
1004*4882a593Smuzhiyun                     "\twithout any \"..\" elements.\n\n", option, arg, option);
1005*4882a593Smuzhiyun     }
1006*4882a593Smuzhiyun }
1007*4882a593Smuzhiyun 
1008*4882a593Smuzhiyun /*
1009*4882a593Smuzhiyun  * ddxProcessArgument --
1010*4882a593Smuzhiyun  *	Process device-dependent command line args. Returns 0 if argument is
1011*4882a593Smuzhiyun  *      not device dependent, otherwise Count of number of elements of argv
1012*4882a593Smuzhiyun  *      that are part of a device dependent commandline option.
1013*4882a593Smuzhiyun  *
1014*4882a593Smuzhiyun  */
1015*4882a593Smuzhiyun 
1016*4882a593Smuzhiyun /* ARGSUSED */
1017*4882a593Smuzhiyun int
ddxProcessArgument(int argc,char ** argv,int i)1018*4882a593Smuzhiyun ddxProcessArgument(int argc, char **argv, int i)
1019*4882a593Smuzhiyun {
1020*4882a593Smuzhiyun #define CHECK_FOR_REQUIRED_ARGUMENT() \
1021*4882a593Smuzhiyun     if (((i + 1) >= argc) || (!argv[i + 1])) { 				\
1022*4882a593Smuzhiyun       ErrorF("Required argument to %s not specified\n", argv[i]); 	\
1023*4882a593Smuzhiyun       UseMsg(); 							\
1024*4882a593Smuzhiyun       FatalError("Required argument to %s not specified\n", argv[i]);	\
1025*4882a593Smuzhiyun     }
1026*4882a593Smuzhiyun 
1027*4882a593Smuzhiyun     /* First the options that are not allowed with elevated privileges */
1028*4882a593Smuzhiyun     if (!strcmp(argv[i], "-modulepath")) {
1029*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1030*4882a593Smuzhiyun         if (xf86PrivsElevated())
1031*4882a593Smuzhiyun               FatalError("\nInvalid argument -modulepath "
1032*4882a593Smuzhiyun                 "with elevated privileges\n");
1033*4882a593Smuzhiyun         xf86ModulePath = argv[i + 1];
1034*4882a593Smuzhiyun         xf86ModPathFrom = X_CMDLINE;
1035*4882a593Smuzhiyun         return 2;
1036*4882a593Smuzhiyun     }
1037*4882a593Smuzhiyun     if (!strcmp(argv[i], "-logfile")) {
1038*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1039*4882a593Smuzhiyun         if (xf86PrivsElevated())
1040*4882a593Smuzhiyun               FatalError("\nInvalid argument -logfile "
1041*4882a593Smuzhiyun                 "with elevated privileges\n");
1042*4882a593Smuzhiyun         xf86LogFile = argv[i + 1];
1043*4882a593Smuzhiyun         xf86LogFileFrom = X_CMDLINE;
1044*4882a593Smuzhiyun         return 2;
1045*4882a593Smuzhiyun     }
1046*4882a593Smuzhiyun     if (!strcmp(argv[i], "-config") || !strcmp(argv[i], "-xf86config")) {
1047*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1048*4882a593Smuzhiyun         xf86CheckPrivs(argv[i], argv[i + 1]);
1049*4882a593Smuzhiyun         xf86ConfigFile = argv[i + 1];
1050*4882a593Smuzhiyun         return 2;
1051*4882a593Smuzhiyun     }
1052*4882a593Smuzhiyun     if (!strcmp(argv[i], "-configdir")) {
1053*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1054*4882a593Smuzhiyun         xf86CheckPrivs(argv[i], argv[i + 1]);
1055*4882a593Smuzhiyun         xf86ConfigDir = argv[i + 1];
1056*4882a593Smuzhiyun         return 2;
1057*4882a593Smuzhiyun     }
1058*4882a593Smuzhiyun     if (!strcmp(argv[i], "-flipPixels")) {
1059*4882a593Smuzhiyun         xf86FlipPixels = TRUE;
1060*4882a593Smuzhiyun         return 1;
1061*4882a593Smuzhiyun     }
1062*4882a593Smuzhiyun #ifdef XF86VIDMODE
1063*4882a593Smuzhiyun     if (!strcmp(argv[i], "-disableVidMode")) {
1064*4882a593Smuzhiyun         xf86VidModeDisabled = TRUE;
1065*4882a593Smuzhiyun         return 1;
1066*4882a593Smuzhiyun     }
1067*4882a593Smuzhiyun     if (!strcmp(argv[i], "-allowNonLocalXvidtune")) {
1068*4882a593Smuzhiyun         xf86VidModeAllowNonLocal = TRUE;
1069*4882a593Smuzhiyun         return 1;
1070*4882a593Smuzhiyun     }
1071*4882a593Smuzhiyun #endif
1072*4882a593Smuzhiyun     if (!strcmp(argv[i], "-allowMouseOpenFail")) {
1073*4882a593Smuzhiyun         xf86AllowMouseOpenFail = TRUE;
1074*4882a593Smuzhiyun         return 1;
1075*4882a593Smuzhiyun     }
1076*4882a593Smuzhiyun     if (!strcmp(argv[i], "-ignoreABI")) {
1077*4882a593Smuzhiyun         LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL);
1078*4882a593Smuzhiyun         return 1;
1079*4882a593Smuzhiyun     }
1080*4882a593Smuzhiyun     if (!strcmp(argv[i], "-verbose")) {
1081*4882a593Smuzhiyun         if (++i < argc && argv[i]) {
1082*4882a593Smuzhiyun             char *end;
1083*4882a593Smuzhiyun             long val;
1084*4882a593Smuzhiyun 
1085*4882a593Smuzhiyun             val = strtol(argv[i], &end, 0);
1086*4882a593Smuzhiyun             if (*end == '\0') {
1087*4882a593Smuzhiyun                 xf86SetVerbosity(val);
1088*4882a593Smuzhiyun                 return 2;
1089*4882a593Smuzhiyun             }
1090*4882a593Smuzhiyun         }
1091*4882a593Smuzhiyun         xf86SetVerbosity(++xf86Verbose);
1092*4882a593Smuzhiyun         return 1;
1093*4882a593Smuzhiyun     }
1094*4882a593Smuzhiyun     if (!strcmp(argv[i], "-logverbose")) {
1095*4882a593Smuzhiyun         if (++i < argc && argv[i]) {
1096*4882a593Smuzhiyun             char *end;
1097*4882a593Smuzhiyun             long val;
1098*4882a593Smuzhiyun 
1099*4882a593Smuzhiyun             val = strtol(argv[i], &end, 0);
1100*4882a593Smuzhiyun             if (*end == '\0') {
1101*4882a593Smuzhiyun                 xf86SetLogVerbosity(val);
1102*4882a593Smuzhiyun                 return 2;
1103*4882a593Smuzhiyun             }
1104*4882a593Smuzhiyun         }
1105*4882a593Smuzhiyun         xf86SetLogVerbosity(++xf86LogVerbose);
1106*4882a593Smuzhiyun         return 1;
1107*4882a593Smuzhiyun     }
1108*4882a593Smuzhiyun     if (!strcmp(argv[i], "-quiet")) {
1109*4882a593Smuzhiyun         xf86SetVerbosity(-1);
1110*4882a593Smuzhiyun         return 1;
1111*4882a593Smuzhiyun     }
1112*4882a593Smuzhiyun     if (!strcmp(argv[i], "-showconfig") || !strcmp(argv[i], "-version")) {
1113*4882a593Smuzhiyun         xf86PrintBanner();
1114*4882a593Smuzhiyun         exit(0);
1115*4882a593Smuzhiyun     }
1116*4882a593Smuzhiyun     if (!strcmp(argv[i], "-showDefaultModulePath")) {
1117*4882a593Smuzhiyun         xf86PrintDefaultModulePath();
1118*4882a593Smuzhiyun         exit(0);
1119*4882a593Smuzhiyun     }
1120*4882a593Smuzhiyun     if (!strcmp(argv[i], "-showDefaultLibPath")) {
1121*4882a593Smuzhiyun         xf86PrintDefaultLibraryPath();
1122*4882a593Smuzhiyun         exit(0);
1123*4882a593Smuzhiyun     }
1124*4882a593Smuzhiyun     /* Notice the -fp flag, but allow it to pass to the dix layer */
1125*4882a593Smuzhiyun     if (!strcmp(argv[i], "-fp")) {
1126*4882a593Smuzhiyun         xf86fpFlag = TRUE;
1127*4882a593Smuzhiyun         return 0;
1128*4882a593Smuzhiyun     }
1129*4882a593Smuzhiyun     /* Notice the -bs flag, but allow it to pass to the dix layer */
1130*4882a593Smuzhiyun     if (!strcmp(argv[i], "-bs")) {
1131*4882a593Smuzhiyun         xf86bsDisableFlag = TRUE;
1132*4882a593Smuzhiyun         return 0;
1133*4882a593Smuzhiyun     }
1134*4882a593Smuzhiyun     /* Notice the +bs flag, but allow it to pass to the dix layer */
1135*4882a593Smuzhiyun     if (!strcmp(argv[i], "+bs")) {
1136*4882a593Smuzhiyun         xf86bsEnableFlag = TRUE;
1137*4882a593Smuzhiyun         return 0;
1138*4882a593Smuzhiyun     }
1139*4882a593Smuzhiyun     /* Notice the -s flag, but allow it to pass to the dix layer */
1140*4882a593Smuzhiyun     if (!strcmp(argv[i], "-s")) {
1141*4882a593Smuzhiyun         xf86sFlag = TRUE;
1142*4882a593Smuzhiyun         return 0;
1143*4882a593Smuzhiyun     }
1144*4882a593Smuzhiyun     if (!strcmp(argv[i], "-pixmap32") || !strcmp(argv[i], "-pixmap24")) {
1145*4882a593Smuzhiyun         /* silently accept */
1146*4882a593Smuzhiyun         return 1;
1147*4882a593Smuzhiyun     }
1148*4882a593Smuzhiyun     if (!strcmp(argv[i], "-fbbpp")) {
1149*4882a593Smuzhiyun         int bpp;
1150*4882a593Smuzhiyun 
1151*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1152*4882a593Smuzhiyun         if (sscanf(argv[++i], "%d", &bpp) == 1) {
1153*4882a593Smuzhiyun             xf86FbBpp = bpp;
1154*4882a593Smuzhiyun             return 2;
1155*4882a593Smuzhiyun         }
1156*4882a593Smuzhiyun         else {
1157*4882a593Smuzhiyun             ErrorF("Invalid fbbpp\n");
1158*4882a593Smuzhiyun             return 0;
1159*4882a593Smuzhiyun         }
1160*4882a593Smuzhiyun     }
1161*4882a593Smuzhiyun     if (!strcmp(argv[i], "-depth")) {
1162*4882a593Smuzhiyun         int depth;
1163*4882a593Smuzhiyun 
1164*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1165*4882a593Smuzhiyun         if (sscanf(argv[++i], "%d", &depth) == 1) {
1166*4882a593Smuzhiyun             xf86Depth = depth;
1167*4882a593Smuzhiyun             return 2;
1168*4882a593Smuzhiyun         }
1169*4882a593Smuzhiyun         else {
1170*4882a593Smuzhiyun             ErrorF("Invalid depth\n");
1171*4882a593Smuzhiyun             return 0;
1172*4882a593Smuzhiyun         }
1173*4882a593Smuzhiyun     }
1174*4882a593Smuzhiyun     if (!strcmp(argv[i], "-weight")) {
1175*4882a593Smuzhiyun         int red, green, blue;
1176*4882a593Smuzhiyun 
1177*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1178*4882a593Smuzhiyun         if (sscanf(argv[++i], "%1d%1d%1d", &red, &green, &blue) == 3) {
1179*4882a593Smuzhiyun             xf86Weight.red = red;
1180*4882a593Smuzhiyun             xf86Weight.green = green;
1181*4882a593Smuzhiyun             xf86Weight.blue = blue;
1182*4882a593Smuzhiyun             return 2;
1183*4882a593Smuzhiyun         }
1184*4882a593Smuzhiyun         else {
1185*4882a593Smuzhiyun             ErrorF("Invalid weighting\n");
1186*4882a593Smuzhiyun             return 0;
1187*4882a593Smuzhiyun         }
1188*4882a593Smuzhiyun     }
1189*4882a593Smuzhiyun     if (!strcmp(argv[i], "-gamma") || !strcmp(argv[i], "-rgamma") ||
1190*4882a593Smuzhiyun         !strcmp(argv[i], "-ggamma") || !strcmp(argv[i], "-bgamma")) {
1191*4882a593Smuzhiyun         double gamma;
1192*4882a593Smuzhiyun 
1193*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1194*4882a593Smuzhiyun         if (sscanf(argv[++i], "%lf", &gamma) == 1) {
1195*4882a593Smuzhiyun             if (gamma < GAMMA_MIN || gamma > GAMMA_MAX) {
1196*4882a593Smuzhiyun                 ErrorF("gamma out of range, only  %.2f <= gamma_value <= %.1f"
1197*4882a593Smuzhiyun                        " is valid\n", GAMMA_MIN, GAMMA_MAX);
1198*4882a593Smuzhiyun                 return 0;
1199*4882a593Smuzhiyun             }
1200*4882a593Smuzhiyun             if (!strcmp(argv[i - 1], "-gamma"))
1201*4882a593Smuzhiyun                 xf86Gamma.red = xf86Gamma.green = xf86Gamma.blue = gamma;
1202*4882a593Smuzhiyun             else if (!strcmp(argv[i - 1], "-rgamma"))
1203*4882a593Smuzhiyun                 xf86Gamma.red = gamma;
1204*4882a593Smuzhiyun             else if (!strcmp(argv[i - 1], "-ggamma"))
1205*4882a593Smuzhiyun                 xf86Gamma.green = gamma;
1206*4882a593Smuzhiyun             else if (!strcmp(argv[i - 1], "-bgamma"))
1207*4882a593Smuzhiyun                 xf86Gamma.blue = gamma;
1208*4882a593Smuzhiyun             return 2;
1209*4882a593Smuzhiyun         }
1210*4882a593Smuzhiyun     }
1211*4882a593Smuzhiyun     if (!strcmp(argv[i], "-layout")) {
1212*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1213*4882a593Smuzhiyun         xf86LayoutName = argv[++i];
1214*4882a593Smuzhiyun         return 2;
1215*4882a593Smuzhiyun     }
1216*4882a593Smuzhiyun     if (!strcmp(argv[i], "-screen")) {
1217*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1218*4882a593Smuzhiyun         xf86ScreenName = argv[++i];
1219*4882a593Smuzhiyun         return 2;
1220*4882a593Smuzhiyun     }
1221*4882a593Smuzhiyun     if (!strcmp(argv[i], "-pointer")) {
1222*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1223*4882a593Smuzhiyun         xf86PointerName = argv[++i];
1224*4882a593Smuzhiyun         return 2;
1225*4882a593Smuzhiyun     }
1226*4882a593Smuzhiyun     if (!strcmp(argv[i], "-keyboard")) {
1227*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1228*4882a593Smuzhiyun         xf86KeyboardName = argv[++i];
1229*4882a593Smuzhiyun         return 2;
1230*4882a593Smuzhiyun     }
1231*4882a593Smuzhiyun     if (!strcmp(argv[i], "-nosilk")) {
1232*4882a593Smuzhiyun         xf86silkenMouseDisableFlag = TRUE;
1233*4882a593Smuzhiyun         return 1;
1234*4882a593Smuzhiyun     }
1235*4882a593Smuzhiyun #ifdef HAVE_ACPI
1236*4882a593Smuzhiyun     if (!strcmp(argv[i], "-noacpi")) {
1237*4882a593Smuzhiyun         xf86acpiDisableFlag = TRUE;
1238*4882a593Smuzhiyun         return 1;
1239*4882a593Smuzhiyun     }
1240*4882a593Smuzhiyun #endif
1241*4882a593Smuzhiyun     if (!strcmp(argv[i], "-configure")) {
1242*4882a593Smuzhiyun         if (getuid() != 0 && geteuid() == 0) {
1243*4882a593Smuzhiyun             ErrorF("The '-configure' option can only be used by root.\n");
1244*4882a593Smuzhiyun             exit(1);
1245*4882a593Smuzhiyun         }
1246*4882a593Smuzhiyun         xf86DoConfigure = TRUE;
1247*4882a593Smuzhiyun         xf86AllowMouseOpenFail = TRUE;
1248*4882a593Smuzhiyun         return 1;
1249*4882a593Smuzhiyun     }
1250*4882a593Smuzhiyun     if (!strcmp(argv[i], "-showopts")) {
1251*4882a593Smuzhiyun         if (getuid() != 0 && geteuid() == 0) {
1252*4882a593Smuzhiyun             ErrorF("The '-showopts' option can only be used by root.\n");
1253*4882a593Smuzhiyun             exit(1);
1254*4882a593Smuzhiyun         }
1255*4882a593Smuzhiyun         xf86DoShowOptions = TRUE;
1256*4882a593Smuzhiyun         return 1;
1257*4882a593Smuzhiyun     }
1258*4882a593Smuzhiyun #ifdef XSERVER_LIBPCIACCESS
1259*4882a593Smuzhiyun     if (!strcmp(argv[i], "-isolateDevice")) {
1260*4882a593Smuzhiyun         CHECK_FOR_REQUIRED_ARGUMENT();
1261*4882a593Smuzhiyun         if (strncmp(argv[++i], "PCI:", 4)) {
1262*4882a593Smuzhiyun             FatalError("Bus types other than PCI not yet isolable\n");
1263*4882a593Smuzhiyun         }
1264*4882a593Smuzhiyun         xf86PciIsolateDevice(argv[i]);
1265*4882a593Smuzhiyun         return 2;
1266*4882a593Smuzhiyun     }
1267*4882a593Smuzhiyun #endif
1268*4882a593Smuzhiyun     /* Notice cmdline xkbdir, but pass to dix as well */
1269*4882a593Smuzhiyun     if (!strcmp(argv[i], "-xkbdir")) {
1270*4882a593Smuzhiyun         xf86xkbdirFlag = TRUE;
1271*4882a593Smuzhiyun         return 0;
1272*4882a593Smuzhiyun     }
1273*4882a593Smuzhiyun     if (!strcmp(argv[i], "-novtswitch")) {
1274*4882a593Smuzhiyun         xf86Info.autoVTSwitch = FALSE;
1275*4882a593Smuzhiyun         return 1;
1276*4882a593Smuzhiyun     }
1277*4882a593Smuzhiyun     if (!strcmp(argv[i], "-sharevts")) {
1278*4882a593Smuzhiyun         xf86Info.ShareVTs = TRUE;
1279*4882a593Smuzhiyun         return 1;
1280*4882a593Smuzhiyun     }
1281*4882a593Smuzhiyun     if (!strcmp(argv[i], "-iglx") || !strcmp(argv[i], "+iglx")) {
1282*4882a593Smuzhiyun         xf86Info.iglxFrom = X_CMDLINE;
1283*4882a593Smuzhiyun         return 0;
1284*4882a593Smuzhiyun     }
1285*4882a593Smuzhiyun 
1286*4882a593Smuzhiyun     /* OS-specific processing */
1287*4882a593Smuzhiyun     return xf86ProcessArgument(argc, argv, i);
1288*4882a593Smuzhiyun }
1289*4882a593Smuzhiyun 
1290*4882a593Smuzhiyun /*
1291*4882a593Smuzhiyun  * ddxUseMsg --
1292*4882a593Smuzhiyun  *	Print out correct use of device dependent commandline options.
1293*4882a593Smuzhiyun  *      Maybe the user now knows what really to do ...
1294*4882a593Smuzhiyun  */
1295*4882a593Smuzhiyun 
1296*4882a593Smuzhiyun void
ddxUseMsg(void)1297*4882a593Smuzhiyun ddxUseMsg(void)
1298*4882a593Smuzhiyun {
1299*4882a593Smuzhiyun     ErrorF("\n");
1300*4882a593Smuzhiyun     ErrorF("\n");
1301*4882a593Smuzhiyun     ErrorF("Device Dependent Usage\n");
1302*4882a593Smuzhiyun     if (!PrivsElevated()) {
1303*4882a593Smuzhiyun         ErrorF("-modulepath paths      specify the module search path\n");
1304*4882a593Smuzhiyun         ErrorF("-logfile file          specify a log file name\n");
1305*4882a593Smuzhiyun         ErrorF("-configure             probe for devices and write an "
1306*4882a593Smuzhiyun                XCONFIGFILE "\n");
1307*4882a593Smuzhiyun         ErrorF
1308*4882a593Smuzhiyun             ("-showopts              print available options for all installed drivers\n");
1309*4882a593Smuzhiyun     }
1310*4882a593Smuzhiyun     ErrorF
1311*4882a593Smuzhiyun         ("-config file           specify a configuration file, relative to the\n");
1312*4882a593Smuzhiyun     ErrorF("                       " XCONFIGFILE
1313*4882a593Smuzhiyun            " search path, only root can use absolute\n");
1314*4882a593Smuzhiyun     ErrorF
1315*4882a593Smuzhiyun         ("-configdir dir         specify a configuration directory, relative to the\n");
1316*4882a593Smuzhiyun     ErrorF("                       " XCONFIGDIR
1317*4882a593Smuzhiyun            " search path, only root can use absolute\n");
1318*4882a593Smuzhiyun     ErrorF("-verbose [n]           verbose startup messages\n");
1319*4882a593Smuzhiyun     ErrorF("-logverbose [n]        verbose log messages\n");
1320*4882a593Smuzhiyun     ErrorF("-quiet                 minimal startup messages\n");
1321*4882a593Smuzhiyun     ErrorF("-fbbpp n               set bpp for the framebuffer. Default: 8\n");
1322*4882a593Smuzhiyun     ErrorF("-depth n               set colour depth. Default: 8\n");
1323*4882a593Smuzhiyun     ErrorF
1324*4882a593Smuzhiyun         ("-gamma f               set gamma value (0.1 < f < 10.0) Default: 1.0\n");
1325*4882a593Smuzhiyun     ErrorF("-rgamma f              set gamma value for red phase\n");
1326*4882a593Smuzhiyun     ErrorF("-ggamma f              set gamma value for green phase\n");
1327*4882a593Smuzhiyun     ErrorF("-bgamma f              set gamma value for blue phase\n");
1328*4882a593Smuzhiyun     ErrorF
1329*4882a593Smuzhiyun         ("-weight nnn            set RGB weighting at 16 bpp.  Default: 565\n");
1330*4882a593Smuzhiyun     ErrorF("-layout name           specify the ServerLayout section name\n");
1331*4882a593Smuzhiyun     ErrorF("-screen name           specify the Screen section name\n");
1332*4882a593Smuzhiyun     ErrorF
1333*4882a593Smuzhiyun         ("-keyboard name         specify the core keyboard InputDevice name\n");
1334*4882a593Smuzhiyun     ErrorF
1335*4882a593Smuzhiyun         ("-pointer name          specify the core pointer InputDevice name\n");
1336*4882a593Smuzhiyun     ErrorF("-nosilk                disable Silken Mouse\n");
1337*4882a593Smuzhiyun     ErrorF("-flipPixels            swap default black/white Pixel values\n");
1338*4882a593Smuzhiyun #ifdef XF86VIDMODE
1339*4882a593Smuzhiyun     ErrorF("-disableVidMode        disable mode adjustments with xvidtune\n");
1340*4882a593Smuzhiyun     ErrorF
1341*4882a593Smuzhiyun         ("-allowNonLocalXvidtune allow xvidtune to be run as a non-local client\n");
1342*4882a593Smuzhiyun #endif
1343*4882a593Smuzhiyun     ErrorF
1344*4882a593Smuzhiyun         ("-allowMouseOpenFail    start server even if the mouse can't be initialized\n");
1345*4882a593Smuzhiyun     ErrorF("-ignoreABI             make module ABI mismatches non-fatal\n");
1346*4882a593Smuzhiyun #ifdef XSERVER_LIBPCIACCESS
1347*4882a593Smuzhiyun     ErrorF
1348*4882a593Smuzhiyun         ("-isolateDevice bus_id  restrict device resets to bus_id (PCI only)\n");
1349*4882a593Smuzhiyun #endif
1350*4882a593Smuzhiyun     ErrorF("-version               show the server version\n");
1351*4882a593Smuzhiyun     ErrorF("-showDefaultModulePath show the server default module path\n");
1352*4882a593Smuzhiyun     ErrorF("-showDefaultLibPath    show the server default library path\n");
1353*4882a593Smuzhiyun     ErrorF
1354*4882a593Smuzhiyun         ("-novtswitch            don't automatically switch VT at reset & exit\n");
1355*4882a593Smuzhiyun     ErrorF("-sharevts              share VTs with another X server\n");
1356*4882a593Smuzhiyun     /* OS-specific usage */
1357*4882a593Smuzhiyun     xf86UseMsg();
1358*4882a593Smuzhiyun     ErrorF("\n");
1359*4882a593Smuzhiyun }
1360*4882a593Smuzhiyun 
1361*4882a593Smuzhiyun /*
1362*4882a593Smuzhiyun  * xf86LoadModules iterates over a list that is being passed in.
1363*4882a593Smuzhiyun  */
1364*4882a593Smuzhiyun Bool
xf86LoadModules(const char ** list,void ** optlist)1365*4882a593Smuzhiyun xf86LoadModules(const char **list, void **optlist)
1366*4882a593Smuzhiyun {
1367*4882a593Smuzhiyun     int errmaj;
1368*4882a593Smuzhiyun     void *opt;
1369*4882a593Smuzhiyun     int i;
1370*4882a593Smuzhiyun     char *name;
1371*4882a593Smuzhiyun     Bool failed = FALSE;
1372*4882a593Smuzhiyun 
1373*4882a593Smuzhiyun     if (!list)
1374*4882a593Smuzhiyun         return TRUE;
1375*4882a593Smuzhiyun 
1376*4882a593Smuzhiyun     for (i = 0; list[i] != NULL; i++) {
1377*4882a593Smuzhiyun 
1378*4882a593Smuzhiyun         /* Normalise the module name */
1379*4882a593Smuzhiyun         name = xf86NormalizeName(list[i]);
1380*4882a593Smuzhiyun 
1381*4882a593Smuzhiyun         /* Skip empty names */
1382*4882a593Smuzhiyun         if (name == NULL || *name == '\0') {
1383*4882a593Smuzhiyun             free(name);
1384*4882a593Smuzhiyun             continue;
1385*4882a593Smuzhiyun         }
1386*4882a593Smuzhiyun 
1387*4882a593Smuzhiyun         /* Replace obsolete keyboard driver with kbd */
1388*4882a593Smuzhiyun         if (!xf86NameCmp(name, "keyboard")) {
1389*4882a593Smuzhiyun             strcpy(name, "kbd");
1390*4882a593Smuzhiyun         }
1391*4882a593Smuzhiyun 
1392*4882a593Smuzhiyun         if (optlist)
1393*4882a593Smuzhiyun             opt = optlist[i];
1394*4882a593Smuzhiyun         else
1395*4882a593Smuzhiyun             opt = NULL;
1396*4882a593Smuzhiyun 
1397*4882a593Smuzhiyun         if (!LoadModule(name, opt, NULL, &errmaj)) {
1398*4882a593Smuzhiyun             LoaderErrorMsg(NULL, name, errmaj, 0);
1399*4882a593Smuzhiyun             failed = TRUE;
1400*4882a593Smuzhiyun         }
1401*4882a593Smuzhiyun         free(name);
1402*4882a593Smuzhiyun     }
1403*4882a593Smuzhiyun     return !failed;
1404*4882a593Smuzhiyun }
1405*4882a593Smuzhiyun 
1406*4882a593Smuzhiyun /* Pixmap format stuff */
1407*4882a593Smuzhiyun 
1408*4882a593Smuzhiyun PixmapFormatPtr
xf86GetPixFormat(ScrnInfoPtr pScrn,int depth)1409*4882a593Smuzhiyun xf86GetPixFormat(ScrnInfoPtr pScrn, int depth)
1410*4882a593Smuzhiyun {
1411*4882a593Smuzhiyun     int i;
1412*4882a593Smuzhiyun 
1413*4882a593Smuzhiyun     for (i = 0; i < numFormats; i++)
1414*4882a593Smuzhiyun         if (formats[i].depth == depth)
1415*4882a593Smuzhiyun             break;
1416*4882a593Smuzhiyun     if (i != numFormats)
1417*4882a593Smuzhiyun         return &formats[i];
1418*4882a593Smuzhiyun     else if (!formatsDone) {
1419*4882a593Smuzhiyun         /* Check for screen-specified formats */
1420*4882a593Smuzhiyun         for (i = 0; i < pScrn->numFormats; i++)
1421*4882a593Smuzhiyun             if (pScrn->formats[i].depth == depth)
1422*4882a593Smuzhiyun                 break;
1423*4882a593Smuzhiyun         if (i != pScrn->numFormats)
1424*4882a593Smuzhiyun             return &pScrn->formats[i];
1425*4882a593Smuzhiyun     }
1426*4882a593Smuzhiyun     return NULL;
1427*4882a593Smuzhiyun }
1428*4882a593Smuzhiyun 
1429*4882a593Smuzhiyun int
xf86GetBppFromDepth(ScrnInfoPtr pScrn,int depth)1430*4882a593Smuzhiyun xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth)
1431*4882a593Smuzhiyun {
1432*4882a593Smuzhiyun     PixmapFormatPtr format;
1433*4882a593Smuzhiyun 
1434*4882a593Smuzhiyun     format = xf86GetPixFormat(pScrn, depth);
1435*4882a593Smuzhiyun     if (format)
1436*4882a593Smuzhiyun         return format->bitsPerPixel;
1437*4882a593Smuzhiyun     else
1438*4882a593Smuzhiyun         return 0;
1439*4882a593Smuzhiyun }
1440*4882a593Smuzhiyun 
1441*4882a593Smuzhiyun #ifdef DDXBEFORERESET
1442*4882a593Smuzhiyun void
ddxBeforeReset(void)1443*4882a593Smuzhiyun ddxBeforeReset(void)
1444*4882a593Smuzhiyun {
1445*4882a593Smuzhiyun }
1446*4882a593Smuzhiyun #endif
1447*4882a593Smuzhiyun 
1448*4882a593Smuzhiyun #if INPUTTHREAD
1449*4882a593Smuzhiyun /** This function is called in Xserver/os/inputthread.c when starting
1450*4882a593Smuzhiyun     the input thread. */
1451*4882a593Smuzhiyun void
ddxInputThreadInit(void)1452*4882a593Smuzhiyun ddxInputThreadInit(void)
1453*4882a593Smuzhiyun {
1454*4882a593Smuzhiyun     xf86OSInputThreadInit();
1455*4882a593Smuzhiyun }
1456*4882a593Smuzhiyun #endif
1457