xref: /OK3568_Linux_fs/external/xserver/hw/xfree86/common/xf86Config.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 /*
8*4882a593Smuzhiyun  * Copyright 1992-2003 by The XFree86 Project, Inc.
9*4882a593Smuzhiyun  * Copyright 1997 by Metro Link, Inc.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
12*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
13*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
14*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
16*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * The above copyright notice and this permission notice shall be included in
19*4882a593Smuzhiyun  * all copies or substantial portions of the Software.
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24*4882a593Smuzhiyun  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
25*4882a593Smuzhiyun  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26*4882a593Smuzhiyun  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27*4882a593Smuzhiyun  * OTHER DEALINGS IN THE SOFTWARE.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * Except as contained in this notice, the name of the copyright holder(s)
30*4882a593Smuzhiyun  * and author(s) shall not be used in advertising or otherwise to promote
31*4882a593Smuzhiyun  * the sale, use or other dealings in this Software without prior written
32*4882a593Smuzhiyun  * authorization from the copyright holder(s) and author(s).
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /*
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * Authors:
38*4882a593Smuzhiyun  *	Dirk Hohndel <hohndel@XFree86.Org>
39*4882a593Smuzhiyun  *	David Dawes <dawes@XFree86.Org>
40*4882a593Smuzhiyun  *      Marc La France <tsi@XFree86.Org>
41*4882a593Smuzhiyun  *      Egbert Eich <eich@XFree86.Org>
42*4882a593Smuzhiyun  *      ... and others
43*4882a593Smuzhiyun  */
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun #ifdef HAVE_XORG_CONFIG_H
46*4882a593Smuzhiyun #include <xorg-config.h>
47*4882a593Smuzhiyun #endif
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #include <sys/types.h>
50*4882a593Smuzhiyun #include <grp.h>
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #include "xf86.h"
53*4882a593Smuzhiyun #include "xf86Modes.h"
54*4882a593Smuzhiyun #include "xf86Parser.h"
55*4882a593Smuzhiyun #include "xf86tokens.h"
56*4882a593Smuzhiyun #include "xf86Config.h"
57*4882a593Smuzhiyun #include "xf86Priv.h"
58*4882a593Smuzhiyun #include "xf86_OSlib.h"
59*4882a593Smuzhiyun #include "configProcs.h"
60*4882a593Smuzhiyun #include "globals.h"
61*4882a593Smuzhiyun #include "extension.h"
62*4882a593Smuzhiyun #include "xf86pciBus.h"
63*4882a593Smuzhiyun #include "xf86Xinput.h"
64*4882a593Smuzhiyun #include "loaderProcs.h"
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun #include "xkbsrv.h"
67*4882a593Smuzhiyun #include "picture.h"
68*4882a593Smuzhiyun #ifdef DPMSExtension
69*4882a593Smuzhiyun #include "dpmsproc.h"
70*4882a593Smuzhiyun #endif
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /*
73*4882a593Smuzhiyun  * These paths define the way the config file search is done.  The escape
74*4882a593Smuzhiyun  * sequences are documented in parser/scan.c.
75*4882a593Smuzhiyun  */
76*4882a593Smuzhiyun #ifndef ALL_CONFIGPATH
77*4882a593Smuzhiyun #define ALL_CONFIGPATH	"%A," "%R," \
78*4882a593Smuzhiyun 			"/etc/X11/%R," "%P/etc/X11/%R," \
79*4882a593Smuzhiyun 			"%E," "%F," \
80*4882a593Smuzhiyun 			"/etc/X11/%F," "%P/etc/X11/%F," \
81*4882a593Smuzhiyun 			"/etc/X11/%X," "/etc/%X," \
82*4882a593Smuzhiyun 			"%P/etc/X11/%X.%H," \
83*4882a593Smuzhiyun 			"%P/etc/X11/%X," \
84*4882a593Smuzhiyun 			"%P/lib/X11/%X.%H," \
85*4882a593Smuzhiyun 			"%P/lib/X11/%X"
86*4882a593Smuzhiyun #endif
87*4882a593Smuzhiyun #ifndef RESTRICTED_CONFIGPATH
88*4882a593Smuzhiyun #define RESTRICTED_CONFIGPATH	"/etc/X11/%S," "%P/etc/X11/%S," \
89*4882a593Smuzhiyun 			"/etc/X11/%G," "%P/etc/X11/%G," \
90*4882a593Smuzhiyun 			"/etc/X11/%X," "/etc/%X," \
91*4882a593Smuzhiyun 			"%P/etc/X11/%X.%H," \
92*4882a593Smuzhiyun 			"%P/etc/X11/%X," \
93*4882a593Smuzhiyun 			"%P/lib/X11/%X.%H," \
94*4882a593Smuzhiyun 			"%P/lib/X11/%X"
95*4882a593Smuzhiyun #endif
96*4882a593Smuzhiyun #ifndef ALL_CONFIGDIRPATH
97*4882a593Smuzhiyun #define ALL_CONFIGDIRPATH	"%A," "%R," \
98*4882a593Smuzhiyun 				"/etc/X11/%R," "%C/X11/%R," \
99*4882a593Smuzhiyun 				"/etc/X11/%X," "%C/X11/%X"
100*4882a593Smuzhiyun #endif
101*4882a593Smuzhiyun #ifndef RESTRICTED_CONFIGDIRPATH
102*4882a593Smuzhiyun #define RESTRICTED_CONFIGDIRPATH	"/etc/X11/%R," "%C/X11/%R," \
103*4882a593Smuzhiyun 					"/etc/X11/%X," "%C/X11/%X"
104*4882a593Smuzhiyun #endif
105*4882a593Smuzhiyun #ifndef SYS_CONFIGDIRPATH
106*4882a593Smuzhiyun #define SYS_CONFIGDIRPATH	"%D/X11/%X"
107*4882a593Smuzhiyun #endif
108*4882a593Smuzhiyun #ifndef PROJECTROOT
109*4882a593Smuzhiyun #define PROJECTROOT	"/usr/X11R6"
110*4882a593Smuzhiyun #endif
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun static ModuleDefault ModuleDefaults[] = {
113*4882a593Smuzhiyun #ifdef GLXEXT
114*4882a593Smuzhiyun     {.name = "glx",.toLoad = TRUE,.load_opt = NULL},
115*4882a593Smuzhiyun #endif
116*4882a593Smuzhiyun #ifdef __CYGWIN__
117*4882a593Smuzhiyun     /* load DIX modules used by drivers first */
118*4882a593Smuzhiyun     {.name = "fb",.toLoad = TRUE,.load_opt = NULL},
119*4882a593Smuzhiyun     {.name = "shadow",.toLoad = TRUE,.load_opt = NULL},
120*4882a593Smuzhiyun #endif
121*4882a593Smuzhiyun     {.name = NULL,.toLoad = FALSE,.load_opt = NULL}
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /* Forward declarations */
125*4882a593Smuzhiyun static Bool configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen,
126*4882a593Smuzhiyun                          int scrnum, MessageType from, Bool auto_gpu_device);
127*4882a593Smuzhiyun static Bool configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor);
128*4882a593Smuzhiyun static Bool configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device,
129*4882a593Smuzhiyun                          Bool active, Bool gpu);
130*4882a593Smuzhiyun static Bool configInput(InputInfoPtr pInfo, XF86ConfInputPtr conf_input,
131*4882a593Smuzhiyun                         MessageType from);
132*4882a593Smuzhiyun static Bool configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display);
133*4882a593Smuzhiyun static Bool addDefaultModes(MonPtr monitorp);
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun static void configDRI(XF86ConfDRIPtr drip);
136*4882a593Smuzhiyun static void configExtensions(XF86ConfExtensionsPtr conf_ext);
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /*
139*4882a593Smuzhiyun  * xf86GetPathElem --
140*4882a593Smuzhiyun  *	Extract a single element from the font path string starting at
141*4882a593Smuzhiyun  *	pnt.  The font path element will be returned, and pnt will be
142*4882a593Smuzhiyun  *	updated to point to the start of the next element, or set to
143*4882a593Smuzhiyun  *	NULL if there are no more.
144*4882a593Smuzhiyun  */
145*4882a593Smuzhiyun static char *
xf86GetPathElem(char ** pnt)146*4882a593Smuzhiyun xf86GetPathElem(char **pnt)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun     char *p1;
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun     p1 = *pnt;
151*4882a593Smuzhiyun     *pnt = index(*pnt, ',');
152*4882a593Smuzhiyun     if (*pnt != NULL) {
153*4882a593Smuzhiyun         **pnt = '\0';
154*4882a593Smuzhiyun         *pnt += 1;
155*4882a593Smuzhiyun     }
156*4882a593Smuzhiyun     return p1;
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /*
160*4882a593Smuzhiyun  * xf86ValidateFontPath --
161*4882a593Smuzhiyun  *	Validates the user-specified font path.  Each element that
162*4882a593Smuzhiyun  *	begins with a '/' is checked to make sure the directory exists.
163*4882a593Smuzhiyun  *	If the directory exists, the existence of a file named 'fonts.dir'
164*4882a593Smuzhiyun  *	is checked.  If either check fails, an error is printed and the
165*4882a593Smuzhiyun  *	element is removed from the font path.
166*4882a593Smuzhiyun  */
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun #define DIR_FILE "/fonts.dir"
169*4882a593Smuzhiyun static char *
xf86ValidateFontPath(char * path)170*4882a593Smuzhiyun xf86ValidateFontPath(char *path)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun     char *next, *tmp_path, *out_pnt, *path_elem, *p1, *dir_elem;
173*4882a593Smuzhiyun     struct stat stat_buf;
174*4882a593Smuzhiyun     int flag;
175*4882a593Smuzhiyun     int dirlen;
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun     tmp_path = calloc(1, strlen(path) + 1);
178*4882a593Smuzhiyun     out_pnt = tmp_path;
179*4882a593Smuzhiyun     path_elem = NULL;
180*4882a593Smuzhiyun     next = path;
181*4882a593Smuzhiyun     while (next != NULL) {
182*4882a593Smuzhiyun         path_elem = xf86GetPathElem(&next);
183*4882a593Smuzhiyun         if (*path_elem == '/') {
184*4882a593Smuzhiyun             dir_elem = xnfcalloc(1, strlen(path_elem) + 1);
185*4882a593Smuzhiyun             if ((p1 = strchr(path_elem, ':')) != 0)
186*4882a593Smuzhiyun                 dirlen = p1 - path_elem;
187*4882a593Smuzhiyun             else
188*4882a593Smuzhiyun                 dirlen = strlen(path_elem);
189*4882a593Smuzhiyun             strlcpy(dir_elem, path_elem, dirlen + 1);
190*4882a593Smuzhiyun             flag = stat(dir_elem, &stat_buf);
191*4882a593Smuzhiyun             if (flag == 0)
192*4882a593Smuzhiyun                 if (!S_ISDIR(stat_buf.st_mode))
193*4882a593Smuzhiyun                     flag = -1;
194*4882a593Smuzhiyun             if (flag != 0) {
195*4882a593Smuzhiyun                 xf86Msg(X_WARNING, "The directory \"%s\" does not exist.\n",
196*4882a593Smuzhiyun                         dir_elem);
197*4882a593Smuzhiyun                 xf86ErrorF("\tEntry deleted from font path.\n");
198*4882a593Smuzhiyun                 free(dir_elem);
199*4882a593Smuzhiyun                 continue;
200*4882a593Smuzhiyun             }
201*4882a593Smuzhiyun             else {
202*4882a593Smuzhiyun                 XNFasprintf(&p1, "%s%s", dir_elem, DIR_FILE);
203*4882a593Smuzhiyun                 flag = stat(p1, &stat_buf);
204*4882a593Smuzhiyun                 if (flag == 0)
205*4882a593Smuzhiyun                     if (!S_ISREG(stat_buf.st_mode))
206*4882a593Smuzhiyun                         flag = -1;
207*4882a593Smuzhiyun                 free(p1);
208*4882a593Smuzhiyun                 if (flag != 0) {
209*4882a593Smuzhiyun                     xf86Msg(X_WARNING,
210*4882a593Smuzhiyun                             "`fonts.dir' not found (or not valid) in \"%s\".\n",
211*4882a593Smuzhiyun                             dir_elem);
212*4882a593Smuzhiyun                     xf86ErrorF("\tEntry deleted from font path.\n");
213*4882a593Smuzhiyun                     xf86ErrorF("\t(Run 'mkfontdir' on \"%s\").\n", dir_elem);
214*4882a593Smuzhiyun                     free(dir_elem);
215*4882a593Smuzhiyun                     continue;
216*4882a593Smuzhiyun                 }
217*4882a593Smuzhiyun             }
218*4882a593Smuzhiyun             free(dir_elem);
219*4882a593Smuzhiyun         }
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun         /*
222*4882a593Smuzhiyun          * Either an OK directory, or a font server name.  So add it to
223*4882a593Smuzhiyun          * the path.
224*4882a593Smuzhiyun          */
225*4882a593Smuzhiyun         if (out_pnt != tmp_path)
226*4882a593Smuzhiyun             *out_pnt++ = ',';
227*4882a593Smuzhiyun         strcat(out_pnt, path_elem);
228*4882a593Smuzhiyun         out_pnt += strlen(path_elem);
229*4882a593Smuzhiyun     }
230*4882a593Smuzhiyun     return tmp_path;
231*4882a593Smuzhiyun }
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun #define FIND_SUITABLE(pointertype, listhead, ptr)                                            \
234*4882a593Smuzhiyun     do {                                                                                     \
235*4882a593Smuzhiyun         pointertype _l, _p;                                                                  \
236*4882a593Smuzhiyun                                                                                              \
237*4882a593Smuzhiyun         for (_l = (listhead), _p = NULL; !_p && _l; _l = (pointertype)_l->list.next) {       \
238*4882a593Smuzhiyun             if (!_l->match_seat || (SeatId && xf86nameCompare(_l->match_seat, SeatId) == 0)) \
239*4882a593Smuzhiyun                 _p = _l;                                                                     \
240*4882a593Smuzhiyun         }                                                                                    \
241*4882a593Smuzhiyun                                                                                              \
242*4882a593Smuzhiyun         (ptr) = _p;                                                                          \
243*4882a593Smuzhiyun     } while(0)
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun /*
246*4882a593Smuzhiyun  * use the datastructure that the parser provides and pick out the parts
247*4882a593Smuzhiyun  * that we need at this point
248*4882a593Smuzhiyun  */
249*4882a593Smuzhiyun const char **
xf86ModulelistFromConfig(void *** optlist)250*4882a593Smuzhiyun xf86ModulelistFromConfig(void ***optlist)
251*4882a593Smuzhiyun {
252*4882a593Smuzhiyun     int count = 0, i = 0;
253*4882a593Smuzhiyun     const char **modulearray;
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun     const char *ignore[] = { "GLcore", "speedo", "bitmap", "drm",
256*4882a593Smuzhiyun         "freetype", "type1",
257*4882a593Smuzhiyun         NULL
258*4882a593Smuzhiyun     };
259*4882a593Smuzhiyun     void **optarray;
260*4882a593Smuzhiyun     XF86LoadPtr modp;
261*4882a593Smuzhiyun     Bool found;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun     /*
264*4882a593Smuzhiyun      * make sure the config file has been parsed and that we have a
265*4882a593Smuzhiyun      * ModulePath set; if no ModulePath was given, use the default
266*4882a593Smuzhiyun      * ModulePath
267*4882a593Smuzhiyun      */
268*4882a593Smuzhiyun     if (xf86configptr == NULL) {
269*4882a593Smuzhiyun         xf86Msg(X_ERROR, "Cannot access global config data structure\n");
270*4882a593Smuzhiyun         return NULL;
271*4882a593Smuzhiyun     }
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun     if (xf86configptr->conf_modules) {
274*4882a593Smuzhiyun         /* Walk the disable list and let people know what we've parsed to
275*4882a593Smuzhiyun          * not be loaded
276*4882a593Smuzhiyun          */
277*4882a593Smuzhiyun         modp = xf86configptr->conf_modules->mod_disable_lst;
278*4882a593Smuzhiyun         while (modp) {
279*4882a593Smuzhiyun             xf86Msg(X_WARNING,
280*4882a593Smuzhiyun                     "\"%s\" will not be loaded unless you've specified it to be loaded elsewhere.\n",
281*4882a593Smuzhiyun                     modp->load_name);
282*4882a593Smuzhiyun             modp = (XF86LoadPtr) modp->list.next;
283*4882a593Smuzhiyun         }
284*4882a593Smuzhiyun         /*
285*4882a593Smuzhiyun          * Walk the default settings table. For each module listed to be
286*4882a593Smuzhiyun          * loaded, make sure it's in the mod_load_lst. If it's not, make
287*4882a593Smuzhiyun          * sure it's not in the mod_no_load_lst. If it's not disabled,
288*4882a593Smuzhiyun          * append it to mod_load_lst
289*4882a593Smuzhiyun          */
290*4882a593Smuzhiyun         for (i = 0; ModuleDefaults[i].name != NULL; i++) {
291*4882a593Smuzhiyun             if (ModuleDefaults[i].toLoad == FALSE) {
292*4882a593Smuzhiyun                 xf86Msg(X_WARNING,
293*4882a593Smuzhiyun                         "\"%s\" is not to be loaded by default. Skipping.\n",
294*4882a593Smuzhiyun                         ModuleDefaults[i].name);
295*4882a593Smuzhiyun                 continue;
296*4882a593Smuzhiyun             }
297*4882a593Smuzhiyun             found = FALSE;
298*4882a593Smuzhiyun             modp = xf86configptr->conf_modules->mod_load_lst;
299*4882a593Smuzhiyun             while (modp) {
300*4882a593Smuzhiyun                 if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) {
301*4882a593Smuzhiyun                     xf86Msg(X_INFO,
302*4882a593Smuzhiyun                             "\"%s\" will be loaded. This was enabled by default and also specified in the config file.\n",
303*4882a593Smuzhiyun                             ModuleDefaults[i].name);
304*4882a593Smuzhiyun                     found = TRUE;
305*4882a593Smuzhiyun                     break;
306*4882a593Smuzhiyun                 }
307*4882a593Smuzhiyun                 modp = (XF86LoadPtr) modp->list.next;
308*4882a593Smuzhiyun             }
309*4882a593Smuzhiyun             if (found == FALSE) {
310*4882a593Smuzhiyun                 modp = xf86configptr->conf_modules->mod_disable_lst;
311*4882a593Smuzhiyun                 while (modp) {
312*4882a593Smuzhiyun                     if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) {
313*4882a593Smuzhiyun                         xf86Msg(X_INFO,
314*4882a593Smuzhiyun                                 "\"%s\" will be loaded even though the default is to disable it.\n",
315*4882a593Smuzhiyun                                 ModuleDefaults[i].name);
316*4882a593Smuzhiyun                         found = TRUE;
317*4882a593Smuzhiyun                         break;
318*4882a593Smuzhiyun                     }
319*4882a593Smuzhiyun                     modp = (XF86LoadPtr) modp->list.next;
320*4882a593Smuzhiyun                 }
321*4882a593Smuzhiyun             }
322*4882a593Smuzhiyun             if (found == FALSE) {
323*4882a593Smuzhiyun                 XF86LoadPtr ptr = (XF86LoadPtr) xf86configptr->conf_modules;
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun                 xf86addNewLoadDirective(ptr, ModuleDefaults[i].name,
326*4882a593Smuzhiyun                                         XF86_LOAD_MODULE,
327*4882a593Smuzhiyun                                         ModuleDefaults[i].load_opt);
328*4882a593Smuzhiyun                 xf86Msg(X_INFO, "\"%s\" will be loaded by default.\n",
329*4882a593Smuzhiyun                         ModuleDefaults[i].name);
330*4882a593Smuzhiyun             }
331*4882a593Smuzhiyun         }
332*4882a593Smuzhiyun     }
333*4882a593Smuzhiyun     else {
334*4882a593Smuzhiyun         xf86configptr->conf_modules = xnfcalloc(1, sizeof(XF86ConfModuleRec));
335*4882a593Smuzhiyun         for (i = 0; ModuleDefaults[i].name != NULL; i++) {
336*4882a593Smuzhiyun             if (ModuleDefaults[i].toLoad == TRUE) {
337*4882a593Smuzhiyun                 XF86LoadPtr ptr = (XF86LoadPtr) xf86configptr->conf_modules;
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun                 xf86addNewLoadDirective(ptr, ModuleDefaults[i].name,
340*4882a593Smuzhiyun                                         XF86_LOAD_MODULE,
341*4882a593Smuzhiyun                                         ModuleDefaults[i].load_opt);
342*4882a593Smuzhiyun             }
343*4882a593Smuzhiyun         }
344*4882a593Smuzhiyun     }
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun     /*
347*4882a593Smuzhiyun      * Walk the list of modules in the "Module" section to determine how
348*4882a593Smuzhiyun      * many we have.
349*4882a593Smuzhiyun      */
350*4882a593Smuzhiyun     modp = xf86configptr->conf_modules->mod_load_lst;
351*4882a593Smuzhiyun     while (modp) {
352*4882a593Smuzhiyun         for (i = 0; ignore[i]; i++) {
353*4882a593Smuzhiyun             if (strcmp(modp->load_name, ignore[i]) == 0)
354*4882a593Smuzhiyun                 modp->ignore = 1;
355*4882a593Smuzhiyun         }
356*4882a593Smuzhiyun         if (!modp->ignore)
357*4882a593Smuzhiyun             count++;
358*4882a593Smuzhiyun         modp = (XF86LoadPtr) modp->list.next;
359*4882a593Smuzhiyun     }
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun     /*
362*4882a593Smuzhiyun      * allocate the memory and walk the list again to fill in the pointers
363*4882a593Smuzhiyun      */
364*4882a593Smuzhiyun     modulearray = xnfallocarray(count + 1, sizeof(char *));
365*4882a593Smuzhiyun     optarray = xnfallocarray(count + 1, sizeof(void *));
366*4882a593Smuzhiyun     count = 0;
367*4882a593Smuzhiyun     if (xf86configptr->conf_modules) {
368*4882a593Smuzhiyun         modp = xf86configptr->conf_modules->mod_load_lst;
369*4882a593Smuzhiyun         while (modp) {
370*4882a593Smuzhiyun             if (!modp->ignore) {
371*4882a593Smuzhiyun                 modulearray[count] = modp->load_name;
372*4882a593Smuzhiyun                 optarray[count] = modp->load_opt;
373*4882a593Smuzhiyun                 count++;
374*4882a593Smuzhiyun             }
375*4882a593Smuzhiyun             modp = (XF86LoadPtr) modp->list.next;
376*4882a593Smuzhiyun         }
377*4882a593Smuzhiyun     }
378*4882a593Smuzhiyun     modulearray[count] = NULL;
379*4882a593Smuzhiyun     optarray[count] = NULL;
380*4882a593Smuzhiyun     if (optlist)
381*4882a593Smuzhiyun         *optlist = optarray;
382*4882a593Smuzhiyun     else
383*4882a593Smuzhiyun         free(optarray);
384*4882a593Smuzhiyun     return modulearray;
385*4882a593Smuzhiyun }
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun const char **
xf86DriverlistFromConfig(void)388*4882a593Smuzhiyun xf86DriverlistFromConfig(void)
389*4882a593Smuzhiyun {
390*4882a593Smuzhiyun     int count = 0;
391*4882a593Smuzhiyun     int j, k;
392*4882a593Smuzhiyun     const char **modulearray;
393*4882a593Smuzhiyun     screenLayoutPtr slp;
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun     /*
396*4882a593Smuzhiyun      * make sure the config file has been parsed and that we have a
397*4882a593Smuzhiyun      * ModulePath set; if no ModulePath was given, use the default
398*4882a593Smuzhiyun      * ModulePath
399*4882a593Smuzhiyun      */
400*4882a593Smuzhiyun     if (xf86configptr == NULL) {
401*4882a593Smuzhiyun         xf86Msg(X_ERROR, "Cannot access global config data structure\n");
402*4882a593Smuzhiyun         return NULL;
403*4882a593Smuzhiyun     }
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun     /*
406*4882a593Smuzhiyun      * Walk the list of driver lines in active "Device" sections to
407*4882a593Smuzhiyun      * determine now many implicitly loaded modules there are.
408*4882a593Smuzhiyun      *
409*4882a593Smuzhiyun      */
410*4882a593Smuzhiyun     if (xf86ConfigLayout.screens) {
411*4882a593Smuzhiyun         slp = xf86ConfigLayout.screens;
412*4882a593Smuzhiyun         while (slp->screen) {
413*4882a593Smuzhiyun             count++;
414*4882a593Smuzhiyun             count += slp->screen->num_gpu_devices;
415*4882a593Smuzhiyun             slp++;
416*4882a593Smuzhiyun         }
417*4882a593Smuzhiyun     }
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun     /*
420*4882a593Smuzhiyun      * Handle the set of inactive "Device" sections.
421*4882a593Smuzhiyun      */
422*4882a593Smuzhiyun     j = 0;
423*4882a593Smuzhiyun     while (xf86ConfigLayout.inactives[j++].identifier)
424*4882a593Smuzhiyun         count++;
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun     if (count == 0)
427*4882a593Smuzhiyun         return NULL;
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun     /*
430*4882a593Smuzhiyun      * allocate the memory and walk the list again to fill in the pointers
431*4882a593Smuzhiyun      */
432*4882a593Smuzhiyun     modulearray = xnfallocarray(count + 1, sizeof(char *));
433*4882a593Smuzhiyun     count = 0;
434*4882a593Smuzhiyun     slp = xf86ConfigLayout.screens;
435*4882a593Smuzhiyun     while (slp->screen) {
436*4882a593Smuzhiyun         modulearray[count] = slp->screen->device->driver;
437*4882a593Smuzhiyun         count++;
438*4882a593Smuzhiyun         for (k = 0; k < slp->screen->num_gpu_devices; k++) {
439*4882a593Smuzhiyun             modulearray[count] = slp->screen->gpu_devices[k]->driver;
440*4882a593Smuzhiyun             count++;
441*4882a593Smuzhiyun         }
442*4882a593Smuzhiyun         slp++;
443*4882a593Smuzhiyun     }
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun     j = 0;
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun     while (xf86ConfigLayout.inactives[j].identifier)
448*4882a593Smuzhiyun         modulearray[count++] = xf86ConfigLayout.inactives[j++].driver;
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun     modulearray[count] = NULL;
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun     /* Remove duplicates */
453*4882a593Smuzhiyun     for (count = 0; modulearray[count] != NULL; count++) {
454*4882a593Smuzhiyun         int i;
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun         for (i = 0; i < count; i++)
457*4882a593Smuzhiyun             if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
458*4882a593Smuzhiyun                 modulearray[count] = "";
459*4882a593Smuzhiyun                 break;
460*4882a593Smuzhiyun             }
461*4882a593Smuzhiyun     }
462*4882a593Smuzhiyun     return modulearray;
463*4882a593Smuzhiyun }
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun const char **
xf86InputDriverlistFromConfig(void)466*4882a593Smuzhiyun xf86InputDriverlistFromConfig(void)
467*4882a593Smuzhiyun {
468*4882a593Smuzhiyun     int count = 0;
469*4882a593Smuzhiyun     const char **modulearray;
470*4882a593Smuzhiyun     InputInfoPtr *idp;
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun     /*
473*4882a593Smuzhiyun      * make sure the config file has been parsed and that we have a
474*4882a593Smuzhiyun      * ModulePath set; if no ModulePath was given, use the default
475*4882a593Smuzhiyun      * ModulePath
476*4882a593Smuzhiyun      */
477*4882a593Smuzhiyun     if (xf86configptr == NULL) {
478*4882a593Smuzhiyun         xf86Msg(X_ERROR, "Cannot access global config data structure\n");
479*4882a593Smuzhiyun         return NULL;
480*4882a593Smuzhiyun     }
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun     /*
483*4882a593Smuzhiyun      * Walk the list of driver lines in active "InputDevice" sections to
484*4882a593Smuzhiyun      * determine now many implicitly loaded modules there are.
485*4882a593Smuzhiyun      */
486*4882a593Smuzhiyun     if (xf86ConfigLayout.inputs) {
487*4882a593Smuzhiyun         idp = xf86ConfigLayout.inputs;
488*4882a593Smuzhiyun         while (*idp) {
489*4882a593Smuzhiyun             count++;
490*4882a593Smuzhiyun             idp++;
491*4882a593Smuzhiyun         }
492*4882a593Smuzhiyun     }
493*4882a593Smuzhiyun 
494*4882a593Smuzhiyun     if (count == 0)
495*4882a593Smuzhiyun         return NULL;
496*4882a593Smuzhiyun 
497*4882a593Smuzhiyun     /*
498*4882a593Smuzhiyun      * allocate the memory and walk the list again to fill in the pointers
499*4882a593Smuzhiyun      */
500*4882a593Smuzhiyun     modulearray = xnfallocarray(count + 1, sizeof(char *));
501*4882a593Smuzhiyun     count = 0;
502*4882a593Smuzhiyun     idp = xf86ConfigLayout.inputs;
503*4882a593Smuzhiyun     while (idp && *idp) {
504*4882a593Smuzhiyun         modulearray[count] = (*idp)->driver;
505*4882a593Smuzhiyun         count++;
506*4882a593Smuzhiyun         idp++;
507*4882a593Smuzhiyun     }
508*4882a593Smuzhiyun     modulearray[count] = NULL;
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun     /* Remove duplicates */
511*4882a593Smuzhiyun     for (count = 0; modulearray[count] != NULL; count++) {
512*4882a593Smuzhiyun         int i;
513*4882a593Smuzhiyun 
514*4882a593Smuzhiyun         for (i = 0; i < count; i++)
515*4882a593Smuzhiyun             if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
516*4882a593Smuzhiyun                 modulearray[count] = "";
517*4882a593Smuzhiyun                 break;
518*4882a593Smuzhiyun             }
519*4882a593Smuzhiyun     }
520*4882a593Smuzhiyun     return modulearray;
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun 
523*4882a593Smuzhiyun static void
configFiles(XF86ConfFilesPtr fileconf)524*4882a593Smuzhiyun configFiles(XF86ConfFilesPtr fileconf)
525*4882a593Smuzhiyun {
526*4882a593Smuzhiyun     MessageType pathFrom;
527*4882a593Smuzhiyun     Bool must_copy;
528*4882a593Smuzhiyun     int size, countDirs;
529*4882a593Smuzhiyun     char *temp_path, *log_buf, *start, *end;
530*4882a593Smuzhiyun 
531*4882a593Smuzhiyun     /* FontPath */
532*4882a593Smuzhiyun     must_copy = TRUE;
533*4882a593Smuzhiyun 
534*4882a593Smuzhiyun     temp_path = defaultFontPath ? (char *) defaultFontPath : (char *) "";
535*4882a593Smuzhiyun     if (xf86fpFlag)
536*4882a593Smuzhiyun         pathFrom = X_CMDLINE;
537*4882a593Smuzhiyun     else if (fileconf && fileconf->file_fontpath) {
538*4882a593Smuzhiyun         pathFrom = X_CONFIG;
539*4882a593Smuzhiyun         if (xf86Info.useDefaultFontPath) {
540*4882a593Smuzhiyun             char *new_font_path;
541*4882a593Smuzhiyun             if (asprintf(&new_font_path, "%s%s%s", fileconf->file_fontpath,
542*4882a593Smuzhiyun                          *temp_path ? "," : "", temp_path) == -1)
543*4882a593Smuzhiyun                 new_font_path = NULL;
544*4882a593Smuzhiyun             else
545*4882a593Smuzhiyun                 must_copy = FALSE;
546*4882a593Smuzhiyun             defaultFontPath = new_font_path;
547*4882a593Smuzhiyun         }
548*4882a593Smuzhiyun         else
549*4882a593Smuzhiyun             defaultFontPath = fileconf->file_fontpath;
550*4882a593Smuzhiyun     }
551*4882a593Smuzhiyun     else
552*4882a593Smuzhiyun         pathFrom = X_DEFAULT;
553*4882a593Smuzhiyun     temp_path = defaultFontPath ? (char *) defaultFontPath : (char *) "";
554*4882a593Smuzhiyun 
555*4882a593Smuzhiyun     /* xf86ValidateFontPath modifies its argument, but returns a copy of it. */
556*4882a593Smuzhiyun     temp_path = must_copy ? xnfstrdup(defaultFontPath) : (char *) defaultFontPath;
557*4882a593Smuzhiyun     defaultFontPath = xf86ValidateFontPath(temp_path);
558*4882a593Smuzhiyun     free(temp_path);
559*4882a593Smuzhiyun 
560*4882a593Smuzhiyun     /* make fontpath more readable in the logfiles */
561*4882a593Smuzhiyun     countDirs = 1;
562*4882a593Smuzhiyun     temp_path = (char *) defaultFontPath;
563*4882a593Smuzhiyun     while ((temp_path = index(temp_path, ',')) != NULL) {
564*4882a593Smuzhiyun         countDirs++;
565*4882a593Smuzhiyun         temp_path++;
566*4882a593Smuzhiyun     }
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun     log_buf = xnfalloc(strlen(defaultFontPath) + (2 * countDirs) + 1);
569*4882a593Smuzhiyun     temp_path = log_buf;
570*4882a593Smuzhiyun     start = (char *) defaultFontPath;
571*4882a593Smuzhiyun     while ((end = index(start, ',')) != NULL) {
572*4882a593Smuzhiyun         size = (end - start) + 1;
573*4882a593Smuzhiyun         *(temp_path++) = '\t';
574*4882a593Smuzhiyun         strncpy(temp_path, start, size);
575*4882a593Smuzhiyun         temp_path += size;
576*4882a593Smuzhiyun         *(temp_path++) = '\n';
577*4882a593Smuzhiyun         start += size;
578*4882a593Smuzhiyun     }
579*4882a593Smuzhiyun     /* copy last entry */
580*4882a593Smuzhiyun     *(temp_path++) = '\t';
581*4882a593Smuzhiyun     strcpy(temp_path, start);
582*4882a593Smuzhiyun     xf86Msg(pathFrom, "FontPath set to:\n%s\n", log_buf);
583*4882a593Smuzhiyun     free(log_buf);
584*4882a593Smuzhiyun 
585*4882a593Smuzhiyun     /* ModulePath */
586*4882a593Smuzhiyun 
587*4882a593Smuzhiyun     if (fileconf) {
588*4882a593Smuzhiyun         if (xf86ModPathFrom != X_CMDLINE && fileconf->file_modulepath) {
589*4882a593Smuzhiyun             xf86ModulePath = fileconf->file_modulepath;
590*4882a593Smuzhiyun             xf86ModPathFrom = X_CONFIG;
591*4882a593Smuzhiyun         }
592*4882a593Smuzhiyun     }
593*4882a593Smuzhiyun 
594*4882a593Smuzhiyun     xf86Msg(xf86ModPathFrom, "ModulePath set to \"%s\"\n", xf86ModulePath);
595*4882a593Smuzhiyun 
596*4882a593Smuzhiyun     if (!xf86xkbdirFlag && fileconf && fileconf->file_xkbdir) {
597*4882a593Smuzhiyun         XkbBaseDirectory = fileconf->file_xkbdir;
598*4882a593Smuzhiyun         xf86Msg(X_CONFIG, "XKB base directory set to \"%s\"\n",
599*4882a593Smuzhiyun                 XkbBaseDirectory);
600*4882a593Smuzhiyun     }
601*4882a593Smuzhiyun #if 0
602*4882a593Smuzhiyun     /* LogFile */
603*4882a593Smuzhiyun     /*
604*4882a593Smuzhiyun      * XXX The problem with this is that the log file is already open.
605*4882a593Smuzhiyun      * One option might be to copy the exiting contents to the new location.
606*4882a593Smuzhiyun      * and re-open it.  The down side is that the default location would
607*4882a593Smuzhiyun      * already have been overwritten.  Another option would be to start with
608*4882a593Smuzhiyun      * unique temporary location, then copy it once the correct name is known.
609*4882a593Smuzhiyun      * A problem with this is what happens if the server exits before that
610*4882a593Smuzhiyun      * happens.
611*4882a593Smuzhiyun      */
612*4882a593Smuzhiyun     if (xf86LogFileFrom == X_DEFAULT && fileconf->file_logfile) {
613*4882a593Smuzhiyun         xf86LogFile = fileconf->file_logfile;
614*4882a593Smuzhiyun         xf86LogFileFrom = X_CONFIG;
615*4882a593Smuzhiyun     }
616*4882a593Smuzhiyun #endif
617*4882a593Smuzhiyun 
618*4882a593Smuzhiyun     return;
619*4882a593Smuzhiyun }
620*4882a593Smuzhiyun 
621*4882a593Smuzhiyun typedef enum {
622*4882a593Smuzhiyun     FLAG_NOTRAPSIGNALS,
623*4882a593Smuzhiyun     FLAG_DONTVTSWITCH,
624*4882a593Smuzhiyun     FLAG_DONTZAP,
625*4882a593Smuzhiyun     FLAG_DONTZOOM,
626*4882a593Smuzhiyun     FLAG_DISABLEVIDMODE,
627*4882a593Smuzhiyun     FLAG_ALLOWNONLOCAL,
628*4882a593Smuzhiyun     FLAG_ALLOWMOUSEOPENFAIL,
629*4882a593Smuzhiyun     FLAG_SAVER_BLANKTIME,
630*4882a593Smuzhiyun     FLAG_DPMS_STANDBYTIME,
631*4882a593Smuzhiyun     FLAG_DPMS_SUSPENDTIME,
632*4882a593Smuzhiyun     FLAG_DPMS_OFFTIME,
633*4882a593Smuzhiyun     FLAG_NOPM,
634*4882a593Smuzhiyun     FLAG_XINERAMA,
635*4882a593Smuzhiyun     FLAG_LOG,
636*4882a593Smuzhiyun     FLAG_RENDER_COLORMAP_MODE,
637*4882a593Smuzhiyun     FLAG_IGNORE_ABI,
638*4882a593Smuzhiyun     FLAG_ALLOW_EMPTY_INPUT,
639*4882a593Smuzhiyun     FLAG_USE_DEFAULT_FONT_PATH,
640*4882a593Smuzhiyun     FLAG_AUTO_ADD_DEVICES,
641*4882a593Smuzhiyun     FLAG_AUTO_ENABLE_DEVICES,
642*4882a593Smuzhiyun     FLAG_GLX_VISUALS,
643*4882a593Smuzhiyun     FLAG_DRI2,
644*4882a593Smuzhiyun     FLAG_USE_SIGIO,
645*4882a593Smuzhiyun     FLAG_AUTO_ADD_GPU,
646*4882a593Smuzhiyun     FLAG_MAX_CLIENTS,
647*4882a593Smuzhiyun     FLAG_IGLX,
648*4882a593Smuzhiyun     FLAG_DEBUG,
649*4882a593Smuzhiyun } FlagValues;
650*4882a593Smuzhiyun 
651*4882a593Smuzhiyun /**
652*4882a593Smuzhiyun  * NOTE: the last value for each entry is NOT the default. It is set to TRUE
653*4882a593Smuzhiyun  * if the parser found the option in the config file.
654*4882a593Smuzhiyun  */
655*4882a593Smuzhiyun static OptionInfoRec FlagOptions[] = {
656*4882a593Smuzhiyun     {FLAG_NOTRAPSIGNALS, "NoTrapSignals", OPTV_BOOLEAN,
657*4882a593Smuzhiyun      {0}, FALSE},
658*4882a593Smuzhiyun     {FLAG_DONTVTSWITCH, "DontVTSwitch", OPTV_BOOLEAN,
659*4882a593Smuzhiyun      {0}, FALSE},
660*4882a593Smuzhiyun     {FLAG_DONTZAP, "DontZap", OPTV_BOOLEAN,
661*4882a593Smuzhiyun      {0}, FALSE},
662*4882a593Smuzhiyun     {FLAG_DONTZOOM, "DontZoom", OPTV_BOOLEAN,
663*4882a593Smuzhiyun      {0}, FALSE},
664*4882a593Smuzhiyun     {FLAG_DISABLEVIDMODE, "DisableVidModeExtension", OPTV_BOOLEAN,
665*4882a593Smuzhiyun      {0}, FALSE},
666*4882a593Smuzhiyun     {FLAG_ALLOWNONLOCAL, "AllowNonLocalXvidtune", OPTV_BOOLEAN,
667*4882a593Smuzhiyun      {0}, FALSE},
668*4882a593Smuzhiyun     {FLAG_ALLOWMOUSEOPENFAIL, "AllowMouseOpenFail", OPTV_BOOLEAN,
669*4882a593Smuzhiyun      {0}, FALSE},
670*4882a593Smuzhiyun     {FLAG_SAVER_BLANKTIME, "BlankTime", OPTV_INTEGER,
671*4882a593Smuzhiyun      {0}, FALSE},
672*4882a593Smuzhiyun     {FLAG_DPMS_STANDBYTIME, "StandbyTime", OPTV_INTEGER,
673*4882a593Smuzhiyun      {0}, FALSE},
674*4882a593Smuzhiyun     {FLAG_DPMS_SUSPENDTIME, "SuspendTime", OPTV_INTEGER,
675*4882a593Smuzhiyun      {0}, FALSE},
676*4882a593Smuzhiyun     {FLAG_DPMS_OFFTIME, "OffTime", OPTV_INTEGER,
677*4882a593Smuzhiyun      {0}, FALSE},
678*4882a593Smuzhiyun     {FLAG_NOPM, "NoPM", OPTV_BOOLEAN,
679*4882a593Smuzhiyun      {0}, FALSE},
680*4882a593Smuzhiyun     {FLAG_XINERAMA, "Xinerama", OPTV_BOOLEAN,
681*4882a593Smuzhiyun      {0}, FALSE},
682*4882a593Smuzhiyun     {FLAG_LOG, "Log", OPTV_STRING,
683*4882a593Smuzhiyun      {0}, FALSE},
684*4882a593Smuzhiyun     {FLAG_RENDER_COLORMAP_MODE, "RenderColormapMode", OPTV_STRING,
685*4882a593Smuzhiyun      {0}, FALSE},
686*4882a593Smuzhiyun     {FLAG_IGNORE_ABI, "IgnoreABI", OPTV_BOOLEAN,
687*4882a593Smuzhiyun      {0}, FALSE},
688*4882a593Smuzhiyun     {FLAG_USE_DEFAULT_FONT_PATH, "UseDefaultFontPath", OPTV_BOOLEAN,
689*4882a593Smuzhiyun      {0}, FALSE},
690*4882a593Smuzhiyun     {FLAG_AUTO_ADD_DEVICES, "AutoAddDevices", OPTV_BOOLEAN,
691*4882a593Smuzhiyun      {0}, FALSE},
692*4882a593Smuzhiyun     {FLAG_AUTO_ENABLE_DEVICES, "AutoEnableDevices", OPTV_BOOLEAN,
693*4882a593Smuzhiyun      {0}, FALSE},
694*4882a593Smuzhiyun     {FLAG_GLX_VISUALS, "GlxVisuals", OPTV_STRING,
695*4882a593Smuzhiyun      {0}, FALSE},
696*4882a593Smuzhiyun     {FLAG_DRI2, "DRI2", OPTV_BOOLEAN,
697*4882a593Smuzhiyun      {0}, FALSE},
698*4882a593Smuzhiyun     {FLAG_USE_SIGIO, "UseSIGIO", OPTV_BOOLEAN,
699*4882a593Smuzhiyun      {0}, FALSE},
700*4882a593Smuzhiyun     {FLAG_AUTO_ADD_GPU, "AutoAddGPU", OPTV_BOOLEAN,
701*4882a593Smuzhiyun      {0}, FALSE},
702*4882a593Smuzhiyun     {FLAG_MAX_CLIENTS, "MaxClients", OPTV_INTEGER,
703*4882a593Smuzhiyun      {0}, FALSE },
704*4882a593Smuzhiyun     {FLAG_IGLX, "IndirectGLX", OPTV_BOOLEAN,
705*4882a593Smuzhiyun      {0}, FALSE},
706*4882a593Smuzhiyun     {FLAG_DEBUG, "Debug", OPTV_STRING,
707*4882a593Smuzhiyun      {0}, FALSE},
708*4882a593Smuzhiyun     {-1, NULL, OPTV_NONE,
709*4882a593Smuzhiyun      {0}, FALSE},
710*4882a593Smuzhiyun };
711*4882a593Smuzhiyun 
712*4882a593Smuzhiyun static void
configServerFlags(XF86ConfFlagsPtr flagsconf,XF86OptionPtr layoutopts)713*4882a593Smuzhiyun configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
714*4882a593Smuzhiyun {
715*4882a593Smuzhiyun     XF86OptionPtr optp, tmp;
716*4882a593Smuzhiyun     int i;
717*4882a593Smuzhiyun     Bool value;
718*4882a593Smuzhiyun     MessageType from;
719*4882a593Smuzhiyun     const char *s;
720*4882a593Smuzhiyun     XkbRMLVOSet set;
721*4882a593Smuzhiyun     const char *rules;
722*4882a593Smuzhiyun 
723*4882a593Smuzhiyun     /*
724*4882a593Smuzhiyun      * Merge the ServerLayout and ServerFlags options.  The former have
725*4882a593Smuzhiyun      * precedence over the latter.
726*4882a593Smuzhiyun      */
727*4882a593Smuzhiyun     optp = NULL;
728*4882a593Smuzhiyun     if (flagsconf && flagsconf->flg_option_lst)
729*4882a593Smuzhiyun         optp = xf86optionListDup(flagsconf->flg_option_lst);
730*4882a593Smuzhiyun     if (layoutopts) {
731*4882a593Smuzhiyun         tmp = xf86optionListDup(layoutopts);
732*4882a593Smuzhiyun         if (optp)
733*4882a593Smuzhiyun             optp = xf86optionListMerge(optp, tmp);
734*4882a593Smuzhiyun         else
735*4882a593Smuzhiyun             optp = tmp;
736*4882a593Smuzhiyun     }
737*4882a593Smuzhiyun 
738*4882a593Smuzhiyun     xf86ProcessOptions(-1, optp, FlagOptions);
739*4882a593Smuzhiyun 
740*4882a593Smuzhiyun     xf86GetOptValBool(FlagOptions, FLAG_NOTRAPSIGNALS, &xf86Info.notrapSignals);
741*4882a593Smuzhiyun     xf86GetOptValBool(FlagOptions, FLAG_DONTVTSWITCH, &xf86Info.dontVTSwitch);
742*4882a593Smuzhiyun     xf86GetOptValBool(FlagOptions, FLAG_DONTZAP, &xf86Info.dontZap);
743*4882a593Smuzhiyun     xf86GetOptValBool(FlagOptions, FLAG_DONTZOOM, &xf86Info.dontZoom);
744*4882a593Smuzhiyun 
745*4882a593Smuzhiyun     xf86GetOptValBool(FlagOptions, FLAG_IGNORE_ABI, &xf86Info.ignoreABI);
746*4882a593Smuzhiyun     if (xf86Info.ignoreABI) {
747*4882a593Smuzhiyun         xf86Msg(X_CONFIG, "Ignoring ABI Version\n");
748*4882a593Smuzhiyun     }
749*4882a593Smuzhiyun 
750*4882a593Smuzhiyun     if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ADD_DEVICES)) {
751*4882a593Smuzhiyun         xf86GetOptValBool(FlagOptions, FLAG_AUTO_ADD_DEVICES,
752*4882a593Smuzhiyun                           &xf86Info.autoAddDevices);
753*4882a593Smuzhiyun         from = X_CONFIG;
754*4882a593Smuzhiyun     }
755*4882a593Smuzhiyun     else {
756*4882a593Smuzhiyun         from = X_DEFAULT;
757*4882a593Smuzhiyun     }
758*4882a593Smuzhiyun     xf86Msg(from, "%sutomatically adding devices\n",
759*4882a593Smuzhiyun             xf86Info.autoAddDevices ? "A" : "Not a");
760*4882a593Smuzhiyun 
761*4882a593Smuzhiyun     if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ENABLE_DEVICES)) {
762*4882a593Smuzhiyun         xf86GetOptValBool(FlagOptions, FLAG_AUTO_ENABLE_DEVICES,
763*4882a593Smuzhiyun                           &xf86Info.autoEnableDevices);
764*4882a593Smuzhiyun         from = X_CONFIG;
765*4882a593Smuzhiyun     }
766*4882a593Smuzhiyun     else {
767*4882a593Smuzhiyun         from = X_DEFAULT;
768*4882a593Smuzhiyun     }
769*4882a593Smuzhiyun     xf86Msg(from, "%sutomatically enabling devices\n",
770*4882a593Smuzhiyun             xf86Info.autoEnableDevices ? "A" : "Not a");
771*4882a593Smuzhiyun 
772*4882a593Smuzhiyun     if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ADD_GPU)) {
773*4882a593Smuzhiyun         xf86GetOptValBool(FlagOptions, FLAG_AUTO_ADD_GPU,
774*4882a593Smuzhiyun                           &xf86Info.autoAddGPU);
775*4882a593Smuzhiyun         from = X_CONFIG;
776*4882a593Smuzhiyun     }
777*4882a593Smuzhiyun     else {
778*4882a593Smuzhiyun         from = X_DEFAULT;
779*4882a593Smuzhiyun     }
780*4882a593Smuzhiyun     xf86Msg(from, "%sutomatically adding GPU devices\n",
781*4882a593Smuzhiyun             xf86Info.autoAddGPU ? "A" : "Not a");
782*4882a593Smuzhiyun     /*
783*4882a593Smuzhiyun      * Set things up based on the config file information.  Some of these
784*4882a593Smuzhiyun      * settings may be overridden later when the command line options are
785*4882a593Smuzhiyun      * checked.
786*4882a593Smuzhiyun      */
787*4882a593Smuzhiyun #ifdef XF86VIDMODE
788*4882a593Smuzhiyun     if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEVIDMODE, &value))
789*4882a593Smuzhiyun         xf86Info.vidModeEnabled = !value;
790*4882a593Smuzhiyun     if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWNONLOCAL, &value))
791*4882a593Smuzhiyun         xf86Info.vidModeAllowNonLocal = value;
792*4882a593Smuzhiyun #endif
793*4882a593Smuzhiyun 
794*4882a593Smuzhiyun     if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWMOUSEOPENFAIL, &value))
795*4882a593Smuzhiyun         xf86Info.allowMouseOpenFail = value;
796*4882a593Smuzhiyun 
797*4882a593Smuzhiyun     xf86Info.pmFlag = TRUE;
798*4882a593Smuzhiyun     if (xf86GetOptValBool(FlagOptions, FLAG_NOPM, &value))
799*4882a593Smuzhiyun         xf86Info.pmFlag = !value;
800*4882a593Smuzhiyun     {
801*4882a593Smuzhiyun         if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) {
802*4882a593Smuzhiyun             if (!xf86NameCmp(s, "flush")) {
803*4882a593Smuzhiyun                 xf86Msg(X_CONFIG, "Flushing logfile enabled\n");
804*4882a593Smuzhiyun                 LogSetParameter(XLOG_FLUSH, TRUE);
805*4882a593Smuzhiyun             }
806*4882a593Smuzhiyun             else if (!xf86NameCmp(s, "sync")) {
807*4882a593Smuzhiyun                 xf86Msg(X_CONFIG, "Syncing logfile enabled\n");
808*4882a593Smuzhiyun                 LogSetParameter(XLOG_FLUSH, TRUE);
809*4882a593Smuzhiyun                 LogSetParameter(XLOG_SYNC, TRUE);
810*4882a593Smuzhiyun             }
811*4882a593Smuzhiyun             else {
812*4882a593Smuzhiyun                 xf86Msg(X_WARNING, "Unknown Log option\n");
813*4882a593Smuzhiyun             }
814*4882a593Smuzhiyun         }
815*4882a593Smuzhiyun     }
816*4882a593Smuzhiyun 
817*4882a593Smuzhiyun     {
818*4882a593Smuzhiyun         if ((s = xf86GetOptValString(FlagOptions, FLAG_RENDER_COLORMAP_MODE))) {
819*4882a593Smuzhiyun             int policy = PictureParseCmapPolicy(s);
820*4882a593Smuzhiyun 
821*4882a593Smuzhiyun             if (policy == PictureCmapPolicyInvalid)
822*4882a593Smuzhiyun                 xf86Msg(X_WARNING, "Unknown colormap policy \"%s\"\n", s);
823*4882a593Smuzhiyun             else {
824*4882a593Smuzhiyun                 xf86Msg(X_CONFIG, "Render colormap policy set to %s\n", s);
825*4882a593Smuzhiyun                 PictureCmapPolicy = policy;
826*4882a593Smuzhiyun             }
827*4882a593Smuzhiyun         }
828*4882a593Smuzhiyun     }
829*4882a593Smuzhiyun 
830*4882a593Smuzhiyun #ifdef GLXEXT
831*4882a593Smuzhiyun     xf86Info.glxVisuals = XF86_GlxVisualsTypical;
832*4882a593Smuzhiyun     xf86Info.glxVisualsFrom = X_DEFAULT;
833*4882a593Smuzhiyun     if ((s = xf86GetOptValString(FlagOptions, FLAG_GLX_VISUALS))) {
834*4882a593Smuzhiyun         if (!xf86NameCmp(s, "minimal")) {
835*4882a593Smuzhiyun             xf86Info.glxVisuals = XF86_GlxVisualsMinimal;
836*4882a593Smuzhiyun         }
837*4882a593Smuzhiyun         else if (!xf86NameCmp(s, "typical")) {
838*4882a593Smuzhiyun             xf86Info.glxVisuals = XF86_GlxVisualsTypical;
839*4882a593Smuzhiyun         }
840*4882a593Smuzhiyun         else if (!xf86NameCmp(s, "all")) {
841*4882a593Smuzhiyun             xf86Info.glxVisuals = XF86_GlxVisualsAll;
842*4882a593Smuzhiyun         }
843*4882a593Smuzhiyun         else {
844*4882a593Smuzhiyun             xf86Msg(X_WARNING, "Unknown GlxVisuals option\n");
845*4882a593Smuzhiyun         }
846*4882a593Smuzhiyun     }
847*4882a593Smuzhiyun 
848*4882a593Smuzhiyun     if (xf86Info.iglxFrom != X_CMDLINE) {
849*4882a593Smuzhiyun         if (xf86GetOptValBool(FlagOptions, FLAG_IGLX, &value)) {
850*4882a593Smuzhiyun             enableIndirectGLX = value;
851*4882a593Smuzhiyun             xf86Info.iglxFrom = X_CONFIG;
852*4882a593Smuzhiyun         }
853*4882a593Smuzhiyun     }
854*4882a593Smuzhiyun #endif
855*4882a593Smuzhiyun 
856*4882a593Smuzhiyun     xf86Info.debug = xf86GetOptValString(FlagOptions, FLAG_DEBUG);
857*4882a593Smuzhiyun 
858*4882a593Smuzhiyun     /* if we're not hotplugging, force some input devices to exist */
859*4882a593Smuzhiyun     xf86Info.forceInputDevices = !(xf86Info.autoAddDevices &&
860*4882a593Smuzhiyun                                    xf86Info.autoEnableDevices);
861*4882a593Smuzhiyun 
862*4882a593Smuzhiyun     /* when forcing input devices, we use kbd. otherwise evdev, so use the
863*4882a593Smuzhiyun      * evdev rules set. */
864*4882a593Smuzhiyun #if defined(__linux__)
865*4882a593Smuzhiyun     if (!xf86Info.forceInputDevices)
866*4882a593Smuzhiyun         rules = "evdev";
867*4882a593Smuzhiyun     else
868*4882a593Smuzhiyun #endif
869*4882a593Smuzhiyun         rules = "base";
870*4882a593Smuzhiyun 
871*4882a593Smuzhiyun     /* Xkb default options. */
872*4882a593Smuzhiyun     XkbInitRules(&set, rules, "pc105", "us", NULL, NULL);
873*4882a593Smuzhiyun     XkbSetRulesDflts(&set);
874*4882a593Smuzhiyun     XkbFreeRMLVOSet(&set, FALSE);
875*4882a593Smuzhiyun 
876*4882a593Smuzhiyun     xf86Info.useDefaultFontPath = TRUE;
877*4882a593Smuzhiyun     if (xf86GetOptValBool(FlagOptions, FLAG_USE_DEFAULT_FONT_PATH, &value)) {
878*4882a593Smuzhiyun         xf86Info.useDefaultFontPath = value;
879*4882a593Smuzhiyun     }
880*4882a593Smuzhiyun 
881*4882a593Smuzhiyun /* Make sure that timers don't overflow CARD32's after multiplying */
882*4882a593Smuzhiyun #define MAX_TIME_IN_MIN (0x7fffffff / MILLI_PER_MIN)
883*4882a593Smuzhiyun 
884*4882a593Smuzhiyun     i = -1;
885*4882a593Smuzhiyun     xf86GetOptValInteger(FlagOptions, FLAG_SAVER_BLANKTIME, &i);
886*4882a593Smuzhiyun     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
887*4882a593Smuzhiyun         ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN;
888*4882a593Smuzhiyun     else if (i != -1)
889*4882a593Smuzhiyun         ErrorF("BlankTime value %d outside legal range of 0 - %d minutes\n",
890*4882a593Smuzhiyun                i, MAX_TIME_IN_MIN);
891*4882a593Smuzhiyun 
892*4882a593Smuzhiyun #ifdef DPMSExtension
893*4882a593Smuzhiyun     i = -1;
894*4882a593Smuzhiyun     xf86GetOptValInteger(FlagOptions, FLAG_DPMS_STANDBYTIME, &i);
895*4882a593Smuzhiyun     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
896*4882a593Smuzhiyun         DPMSStandbyTime = i * MILLI_PER_MIN;
897*4882a593Smuzhiyun     else if (i != -1)
898*4882a593Smuzhiyun         ErrorF("StandbyTime value %d outside legal range of 0 - %d minutes\n",
899*4882a593Smuzhiyun                i, MAX_TIME_IN_MIN);
900*4882a593Smuzhiyun     i = -1;
901*4882a593Smuzhiyun     xf86GetOptValInteger(FlagOptions, FLAG_DPMS_SUSPENDTIME, &i);
902*4882a593Smuzhiyun     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
903*4882a593Smuzhiyun         DPMSSuspendTime = i * MILLI_PER_MIN;
904*4882a593Smuzhiyun     else if (i != -1)
905*4882a593Smuzhiyun         ErrorF("SuspendTime value %d outside legal range of 0 - %d minutes\n",
906*4882a593Smuzhiyun                i, MAX_TIME_IN_MIN);
907*4882a593Smuzhiyun     i = -1;
908*4882a593Smuzhiyun     xf86GetOptValInteger(FlagOptions, FLAG_DPMS_OFFTIME, &i);
909*4882a593Smuzhiyun     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
910*4882a593Smuzhiyun         DPMSOffTime = i * MILLI_PER_MIN;
911*4882a593Smuzhiyun     else if (i != -1)
912*4882a593Smuzhiyun         ErrorF("OffTime value %d outside legal range of 0 - %d minutes\n",
913*4882a593Smuzhiyun                i, MAX_TIME_IN_MIN);
914*4882a593Smuzhiyun #endif
915*4882a593Smuzhiyun 
916*4882a593Smuzhiyun #ifdef PANORAMIX
917*4882a593Smuzhiyun     from = X_DEFAULT;
918*4882a593Smuzhiyun     if (!noPanoramiXExtension)
919*4882a593Smuzhiyun         from = X_CMDLINE;
920*4882a593Smuzhiyun     else if (xf86GetOptValBool(FlagOptions, FLAG_XINERAMA, &value)) {
921*4882a593Smuzhiyun         noPanoramiXExtension = !value;
922*4882a593Smuzhiyun         from = X_CONFIG;
923*4882a593Smuzhiyun     }
924*4882a593Smuzhiyun     if (!noPanoramiXExtension)
925*4882a593Smuzhiyun         xf86Msg(from, "Xinerama: enabled\n");
926*4882a593Smuzhiyun #endif
927*4882a593Smuzhiyun 
928*4882a593Smuzhiyun #ifdef DRI2
929*4882a593Smuzhiyun     xf86Info.dri2 = FALSE;
930*4882a593Smuzhiyun     xf86Info.dri2From = X_DEFAULT;
931*4882a593Smuzhiyun     if (xf86GetOptValBool(FlagOptions, FLAG_DRI2, &value)) {
932*4882a593Smuzhiyun         xf86Info.dri2 = value;
933*4882a593Smuzhiyun         xf86Info.dri2From = X_CONFIG;
934*4882a593Smuzhiyun     }
935*4882a593Smuzhiyun #endif
936*4882a593Smuzhiyun 
937*4882a593Smuzhiyun     from = X_DEFAULT;
938*4882a593Smuzhiyun     if (LimitClients != LIMITCLIENTS)
939*4882a593Smuzhiyun 	from = X_CMDLINE;
940*4882a593Smuzhiyun     i = -1;
941*4882a593Smuzhiyun     if (xf86GetOptValInteger(FlagOptions, FLAG_MAX_CLIENTS, &i)) {
942*4882a593Smuzhiyun         if (Ones(i) != 1 || i < 64 || i > 2048) {
943*4882a593Smuzhiyun 	    ErrorF("MaxClients must be one of 64, 128, 256, 512, 1024, or 2048\n");
944*4882a593Smuzhiyun         } else {
945*4882a593Smuzhiyun             from = X_CONFIG;
946*4882a593Smuzhiyun             LimitClients = i;
947*4882a593Smuzhiyun         }
948*4882a593Smuzhiyun     }
949*4882a593Smuzhiyun     xf86Msg(from, "Max clients allowed: %i, resource mask: 0x%x\n",
950*4882a593Smuzhiyun 	    LimitClients, RESOURCE_ID_MASK);
951*4882a593Smuzhiyun }
952*4882a593Smuzhiyun 
953*4882a593Smuzhiyun Bool
xf86DRI2Enabled(void)954*4882a593Smuzhiyun xf86DRI2Enabled(void)
955*4882a593Smuzhiyun {
956*4882a593Smuzhiyun     return xf86Info.dri2;
957*4882a593Smuzhiyun }
958*4882a593Smuzhiyun 
959*4882a593Smuzhiyun /**
960*4882a593Smuzhiyun  * Search for the pInfo in the null-terminated list given and remove (and
961*4882a593Smuzhiyun  * free) it if present. All other devices are moved forward.
962*4882a593Smuzhiyun  */
963*4882a593Smuzhiyun static void
freeDevice(InputInfoPtr * list,InputInfoPtr pInfo)964*4882a593Smuzhiyun freeDevice(InputInfoPtr * list, InputInfoPtr pInfo)
965*4882a593Smuzhiyun {
966*4882a593Smuzhiyun     InputInfoPtr *devs;
967*4882a593Smuzhiyun 
968*4882a593Smuzhiyun     for (devs = list; devs && *devs; devs++) {
969*4882a593Smuzhiyun         if (*devs == pInfo) {
970*4882a593Smuzhiyun             free(*devs);
971*4882a593Smuzhiyun             for (; devs && *devs; devs++)
972*4882a593Smuzhiyun                 devs[0] = devs[1];
973*4882a593Smuzhiyun             break;
974*4882a593Smuzhiyun         }
975*4882a593Smuzhiyun     }
976*4882a593Smuzhiyun }
977*4882a593Smuzhiyun 
978*4882a593Smuzhiyun /**
979*4882a593Smuzhiyun  * Append pInfo to the null-terminated list, allocating space as necessary.
980*4882a593Smuzhiyun  * pInfo is used as the last element.
981*4882a593Smuzhiyun  */
982*4882a593Smuzhiyun static InputInfoPtr *
addDevice(InputInfoPtr * list,InputInfoPtr pInfo)983*4882a593Smuzhiyun addDevice(InputInfoPtr * list, InputInfoPtr pInfo)
984*4882a593Smuzhiyun {
985*4882a593Smuzhiyun     InputInfoPtr *devs;
986*4882a593Smuzhiyun     int count = 1;
987*4882a593Smuzhiyun 
988*4882a593Smuzhiyun     for (devs = list; devs && *devs; devs++)
989*4882a593Smuzhiyun         count++;
990*4882a593Smuzhiyun 
991*4882a593Smuzhiyun     list = xnfreallocarray(list, count + 1, sizeof(InputInfoPtr));
992*4882a593Smuzhiyun     list[count] = NULL;
993*4882a593Smuzhiyun 
994*4882a593Smuzhiyun     list[count - 1] = pInfo;
995*4882a593Smuzhiyun     return list;
996*4882a593Smuzhiyun }
997*4882a593Smuzhiyun 
998*4882a593Smuzhiyun /*
999*4882a593Smuzhiyun  * Locate the core input devices.  These can be specified/located in
1000*4882a593Smuzhiyun  * the following ways, in order of priority:
1001*4882a593Smuzhiyun  *
1002*4882a593Smuzhiyun  *  1. The InputDevices named by the -pointer and -keyboard command line
1003*4882a593Smuzhiyun  *     options.
1004*4882a593Smuzhiyun  *  2. The "CorePointer" and "CoreKeyboard" InputDevices referred to by
1005*4882a593Smuzhiyun  *     the active ServerLayout.
1006*4882a593Smuzhiyun  *  3. The first InputDevices marked as "CorePointer" and "CoreKeyboard".
1007*4882a593Smuzhiyun  *  4. The first InputDevices that use 'keyboard' or 'kbd' and a valid mouse
1008*4882a593Smuzhiyun  *     driver (mouse, synaptics, evdev, vmmouse, void)
1009*4882a593Smuzhiyun  *  5. Default devices with an empty (default) configuration.  These defaults
1010*4882a593Smuzhiyun  *     will reference the 'mouse' and 'keyboard' drivers.
1011*4882a593Smuzhiyun  */
1012*4882a593Smuzhiyun 
1013*4882a593Smuzhiyun static Bool
checkCoreInputDevices(serverLayoutPtr servlayoutp,Bool implicitLayout)1014*4882a593Smuzhiyun checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
1015*4882a593Smuzhiyun {
1016*4882a593Smuzhiyun     InputInfoPtr corePointer = NULL, coreKeyboard = NULL;
1017*4882a593Smuzhiyun     Bool foundPointer = FALSE, foundKeyboard = FALSE;
1018*4882a593Smuzhiyun     const char *pointerMsg = NULL, *keyboardMsg = NULL;
1019*4882a593Smuzhiyun     InputInfoPtr *devs,         /* iterator */
1020*4882a593Smuzhiyun      indp;
1021*4882a593Smuzhiyun     InputInfoPtr Pointer, Keyboard;
1022*4882a593Smuzhiyun     XF86ConfInputPtr confInput;
1023*4882a593Smuzhiyun     XF86ConfInputRec defPtr, defKbd;
1024*4882a593Smuzhiyun     MessageType from = X_DEFAULT;
1025*4882a593Smuzhiyun 
1026*4882a593Smuzhiyun     const char *mousedrivers[] = { "mouse", "synaptics", "evdev", "vmmouse",
1027*4882a593Smuzhiyun         "void", NULL
1028*4882a593Smuzhiyun     };
1029*4882a593Smuzhiyun 
1030*4882a593Smuzhiyun     /*
1031*4882a593Smuzhiyun      * First check if a core pointer or core keyboard have been specified
1032*4882a593Smuzhiyun      * in the active ServerLayout.  If more than one is specified for either,
1033*4882a593Smuzhiyun      * remove the core attribute from the later ones.
1034*4882a593Smuzhiyun      */
1035*4882a593Smuzhiyun     for (devs = servlayoutp->inputs; devs && *devs; devs++) {
1036*4882a593Smuzhiyun         indp = *devs;
1037*4882a593Smuzhiyun         if (indp->options &&
1038*4882a593Smuzhiyun             xf86CheckBoolOption(indp->options, "CorePointer", FALSE)) {
1039*4882a593Smuzhiyun             if (!corePointer) {
1040*4882a593Smuzhiyun                 corePointer = indp;
1041*4882a593Smuzhiyun             }
1042*4882a593Smuzhiyun         }
1043*4882a593Smuzhiyun         if (indp->options &&
1044*4882a593Smuzhiyun             xf86CheckBoolOption(indp->options, "CoreKeyboard", FALSE)) {
1045*4882a593Smuzhiyun             if (!coreKeyboard) {
1046*4882a593Smuzhiyun                 coreKeyboard = indp;
1047*4882a593Smuzhiyun             }
1048*4882a593Smuzhiyun         }
1049*4882a593Smuzhiyun     }
1050*4882a593Smuzhiyun 
1051*4882a593Smuzhiyun     confInput = NULL;
1052*4882a593Smuzhiyun 
1053*4882a593Smuzhiyun     /* 1. Check for the -pointer command line option. */
1054*4882a593Smuzhiyun     if (xf86PointerName) {
1055*4882a593Smuzhiyun         confInput = xf86findInput(xf86PointerName,
1056*4882a593Smuzhiyun                                   xf86configptr->conf_input_lst);
1057*4882a593Smuzhiyun         if (!confInput) {
1058*4882a593Smuzhiyun             xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n",
1059*4882a593Smuzhiyun                     xf86PointerName);
1060*4882a593Smuzhiyun             return FALSE;
1061*4882a593Smuzhiyun         }
1062*4882a593Smuzhiyun         from = X_CMDLINE;
1063*4882a593Smuzhiyun         /*
1064*4882a593Smuzhiyun          * If one was already specified in the ServerLayout, it needs to be
1065*4882a593Smuzhiyun          * removed.
1066*4882a593Smuzhiyun          */
1067*4882a593Smuzhiyun         if (corePointer) {
1068*4882a593Smuzhiyun             freeDevice(servlayoutp->inputs, corePointer);
1069*4882a593Smuzhiyun             corePointer = NULL;
1070*4882a593Smuzhiyun         }
1071*4882a593Smuzhiyun         foundPointer = TRUE;
1072*4882a593Smuzhiyun     }
1073*4882a593Smuzhiyun 
1074*4882a593Smuzhiyun     /* 2. ServerLayout-specified core pointer. */
1075*4882a593Smuzhiyun     if (corePointer) {
1076*4882a593Smuzhiyun         foundPointer = TRUE;
1077*4882a593Smuzhiyun         from = X_CONFIG;
1078*4882a593Smuzhiyun     }
1079*4882a593Smuzhiyun 
1080*4882a593Smuzhiyun     /* 3. First core pointer device. */
1081*4882a593Smuzhiyun     if (!foundPointer && (xf86Info.forceInputDevices || implicitLayout)) {
1082*4882a593Smuzhiyun         XF86ConfInputPtr p;
1083*4882a593Smuzhiyun 
1084*4882a593Smuzhiyun         for (p = xf86configptr->conf_input_lst; p; p = p->list.next) {
1085*4882a593Smuzhiyun             if (p->inp_option_lst &&
1086*4882a593Smuzhiyun                 xf86CheckBoolOption(p->inp_option_lst, "CorePointer", FALSE)) {
1087*4882a593Smuzhiyun                 confInput = p;
1088*4882a593Smuzhiyun                 foundPointer = TRUE;
1089*4882a593Smuzhiyun                 from = X_DEFAULT;
1090*4882a593Smuzhiyun                 pointerMsg = "first core pointer device";
1091*4882a593Smuzhiyun                 break;
1092*4882a593Smuzhiyun             }
1093*4882a593Smuzhiyun         }
1094*4882a593Smuzhiyun     }
1095*4882a593Smuzhiyun 
1096*4882a593Smuzhiyun     /* 4. First pointer with an allowed mouse driver. */
1097*4882a593Smuzhiyun     if (!foundPointer && xf86Info.forceInputDevices) {
1098*4882a593Smuzhiyun         const char **driver = mousedrivers;
1099*4882a593Smuzhiyun 
1100*4882a593Smuzhiyun         confInput = xf86findInput(CONF_IMPLICIT_POINTER,
1101*4882a593Smuzhiyun                                   xf86configptr->conf_input_lst);
1102*4882a593Smuzhiyun         while (*driver && !confInput) {
1103*4882a593Smuzhiyun             confInput = xf86findInputByDriver(*driver,
1104*4882a593Smuzhiyun                                               xf86configptr->conf_input_lst);
1105*4882a593Smuzhiyun             driver++;
1106*4882a593Smuzhiyun         }
1107*4882a593Smuzhiyun         if (confInput) {
1108*4882a593Smuzhiyun             foundPointer = TRUE;
1109*4882a593Smuzhiyun             from = X_DEFAULT;
1110*4882a593Smuzhiyun             pointerMsg = "first mouse device";
1111*4882a593Smuzhiyun         }
1112*4882a593Smuzhiyun     }
1113*4882a593Smuzhiyun 
1114*4882a593Smuzhiyun     /* 5. Built-in default. */
1115*4882a593Smuzhiyun     if (!foundPointer && xf86Info.forceInputDevices) {
1116*4882a593Smuzhiyun         memset(&defPtr, 0, sizeof(defPtr));
1117*4882a593Smuzhiyun         defPtr.inp_identifier = strdup("<default pointer>");
1118*4882a593Smuzhiyun         defPtr.inp_driver = strdup("mouse");
1119*4882a593Smuzhiyun         confInput = &defPtr;
1120*4882a593Smuzhiyun         foundPointer = TRUE;
1121*4882a593Smuzhiyun         from = X_DEFAULT;
1122*4882a593Smuzhiyun         pointerMsg = "default mouse configuration";
1123*4882a593Smuzhiyun     }
1124*4882a593Smuzhiyun 
1125*4882a593Smuzhiyun     /* Add the core pointer device to the layout, and set it to Core. */
1126*4882a593Smuzhiyun     if (foundPointer && confInput) {
1127*4882a593Smuzhiyun         Pointer = xf86AllocateInput();
1128*4882a593Smuzhiyun         if (Pointer)
1129*4882a593Smuzhiyun             foundPointer = configInput(Pointer, confInput, from);
1130*4882a593Smuzhiyun         if (foundPointer) {
1131*4882a593Smuzhiyun             Pointer->options = xf86AddNewOption(Pointer->options,
1132*4882a593Smuzhiyun                                                 "CorePointer", "on");
1133*4882a593Smuzhiyun             Pointer->options = xf86AddNewOption(Pointer->options,
1134*4882a593Smuzhiyun                                                 "driver",
1135*4882a593Smuzhiyun                                                 confInput->inp_driver);
1136*4882a593Smuzhiyun             Pointer->options =
1137*4882a593Smuzhiyun                 xf86AddNewOption(Pointer->options, "identifier",
1138*4882a593Smuzhiyun                                  confInput->inp_identifier);
1139*4882a593Smuzhiyun             servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer);
1140*4882a593Smuzhiyun         }
1141*4882a593Smuzhiyun     }
1142*4882a593Smuzhiyun 
1143*4882a593Smuzhiyun     if (!foundPointer && xf86Info.forceInputDevices) {
1144*4882a593Smuzhiyun         /* This shouldn't happen. */
1145*4882a593Smuzhiyun         xf86Msg(X_ERROR, "Cannot locate a core pointer device.\n");
1146*4882a593Smuzhiyun         xf86DeleteInput(Pointer, 0);
1147*4882a593Smuzhiyun         return FALSE;
1148*4882a593Smuzhiyun     }
1149*4882a593Smuzhiyun 
1150*4882a593Smuzhiyun     confInput = NULL;
1151*4882a593Smuzhiyun 
1152*4882a593Smuzhiyun     /* 1. Check for the -keyboard command line option. */
1153*4882a593Smuzhiyun     if (xf86KeyboardName) {
1154*4882a593Smuzhiyun         confInput = xf86findInput(xf86KeyboardName,
1155*4882a593Smuzhiyun                                   xf86configptr->conf_input_lst);
1156*4882a593Smuzhiyun         if (!confInput) {
1157*4882a593Smuzhiyun             xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n",
1158*4882a593Smuzhiyun                     xf86KeyboardName);
1159*4882a593Smuzhiyun             return FALSE;
1160*4882a593Smuzhiyun         }
1161*4882a593Smuzhiyun         from = X_CMDLINE;
1162*4882a593Smuzhiyun         /*
1163*4882a593Smuzhiyun          * If one was already specified in the ServerLayout, it needs to be
1164*4882a593Smuzhiyun          * removed.
1165*4882a593Smuzhiyun          */
1166*4882a593Smuzhiyun         if (coreKeyboard) {
1167*4882a593Smuzhiyun             freeDevice(servlayoutp->inputs, coreKeyboard);
1168*4882a593Smuzhiyun             coreKeyboard = NULL;
1169*4882a593Smuzhiyun         }
1170*4882a593Smuzhiyun         foundKeyboard = TRUE;
1171*4882a593Smuzhiyun     }
1172*4882a593Smuzhiyun 
1173*4882a593Smuzhiyun     /* 2. ServerLayout-specified core keyboard. */
1174*4882a593Smuzhiyun     if (coreKeyboard) {
1175*4882a593Smuzhiyun         foundKeyboard = TRUE;
1176*4882a593Smuzhiyun         from = X_CONFIG;
1177*4882a593Smuzhiyun     }
1178*4882a593Smuzhiyun 
1179*4882a593Smuzhiyun     /* 3. First core keyboard device. */
1180*4882a593Smuzhiyun     if (!foundKeyboard && (xf86Info.forceInputDevices || implicitLayout)) {
1181*4882a593Smuzhiyun         XF86ConfInputPtr p;
1182*4882a593Smuzhiyun 
1183*4882a593Smuzhiyun         for (p = xf86configptr->conf_input_lst; p; p = p->list.next) {
1184*4882a593Smuzhiyun             if (p->inp_option_lst &&
1185*4882a593Smuzhiyun                 xf86CheckBoolOption(p->inp_option_lst, "CoreKeyboard", FALSE)) {
1186*4882a593Smuzhiyun                 confInput = p;
1187*4882a593Smuzhiyun                 foundKeyboard = TRUE;
1188*4882a593Smuzhiyun                 from = X_DEFAULT;
1189*4882a593Smuzhiyun                 keyboardMsg = "first core keyboard device";
1190*4882a593Smuzhiyun                 break;
1191*4882a593Smuzhiyun             }
1192*4882a593Smuzhiyun         }
1193*4882a593Smuzhiyun     }
1194*4882a593Smuzhiyun 
1195*4882a593Smuzhiyun     /* 4. First keyboard with 'keyboard' or 'kbd' as the driver. */
1196*4882a593Smuzhiyun     if (!foundKeyboard && xf86Info.forceInputDevices) {
1197*4882a593Smuzhiyun         confInput = xf86findInput(CONF_IMPLICIT_KEYBOARD,
1198*4882a593Smuzhiyun                                   xf86configptr->conf_input_lst);
1199*4882a593Smuzhiyun         if (!confInput) {
1200*4882a593Smuzhiyun             confInput = xf86findInputByDriver("kbd",
1201*4882a593Smuzhiyun                                               xf86configptr->conf_input_lst);
1202*4882a593Smuzhiyun         }
1203*4882a593Smuzhiyun         if (confInput) {
1204*4882a593Smuzhiyun             foundKeyboard = TRUE;
1205*4882a593Smuzhiyun             from = X_DEFAULT;
1206*4882a593Smuzhiyun             keyboardMsg = "first keyboard device";
1207*4882a593Smuzhiyun         }
1208*4882a593Smuzhiyun     }
1209*4882a593Smuzhiyun 
1210*4882a593Smuzhiyun     /* 5. Built-in default. */
1211*4882a593Smuzhiyun     if (!foundKeyboard && xf86Info.forceInputDevices) {
1212*4882a593Smuzhiyun         memset(&defKbd, 0, sizeof(defKbd));
1213*4882a593Smuzhiyun         defKbd.inp_identifier = strdup("<default keyboard>");
1214*4882a593Smuzhiyun         defKbd.inp_driver = strdup("kbd");
1215*4882a593Smuzhiyun         confInput = &defKbd;
1216*4882a593Smuzhiyun         foundKeyboard = TRUE;
1217*4882a593Smuzhiyun         keyboardMsg = "default keyboard configuration";
1218*4882a593Smuzhiyun         from = X_DEFAULT;
1219*4882a593Smuzhiyun     }
1220*4882a593Smuzhiyun 
1221*4882a593Smuzhiyun     /* Add the core keyboard device to the layout, and set it to Core. */
1222*4882a593Smuzhiyun     if (foundKeyboard && confInput) {
1223*4882a593Smuzhiyun         Keyboard = xf86AllocateInput();
1224*4882a593Smuzhiyun         if (Keyboard)
1225*4882a593Smuzhiyun             foundKeyboard = configInput(Keyboard, confInput, from);
1226*4882a593Smuzhiyun         if (foundKeyboard) {
1227*4882a593Smuzhiyun             Keyboard->options = xf86AddNewOption(Keyboard->options,
1228*4882a593Smuzhiyun                                                  "CoreKeyboard", "on");
1229*4882a593Smuzhiyun             Keyboard->options = xf86AddNewOption(Keyboard->options,
1230*4882a593Smuzhiyun                                                  "driver",
1231*4882a593Smuzhiyun                                                  confInput->inp_driver);
1232*4882a593Smuzhiyun             Keyboard->options =
1233*4882a593Smuzhiyun                 xf86AddNewOption(Keyboard->options, "identifier",
1234*4882a593Smuzhiyun                                  confInput->inp_identifier);
1235*4882a593Smuzhiyun             servlayoutp->inputs = addDevice(servlayoutp->inputs, Keyboard);
1236*4882a593Smuzhiyun         }
1237*4882a593Smuzhiyun     }
1238*4882a593Smuzhiyun 
1239*4882a593Smuzhiyun     if (!foundKeyboard && xf86Info.forceInputDevices) {
1240*4882a593Smuzhiyun         /* This shouldn't happen. */
1241*4882a593Smuzhiyun         xf86Msg(X_ERROR, "Cannot locate a core keyboard device.\n");
1242*4882a593Smuzhiyun         xf86DeleteInput(Keyboard, 0);
1243*4882a593Smuzhiyun         return FALSE;
1244*4882a593Smuzhiyun     }
1245*4882a593Smuzhiyun 
1246*4882a593Smuzhiyun     if (pointerMsg) {
1247*4882a593Smuzhiyun         if (implicitLayout)
1248*4882a593Smuzhiyun             xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n",
1249*4882a593Smuzhiyun                     pointerMsg);
1250*4882a593Smuzhiyun         else
1251*4882a593Smuzhiyun             xf86Msg(X_DEFAULT, "The core pointer device wasn't specified "
1252*4882a593Smuzhiyun                     "explicitly in the layout.\n"
1253*4882a593Smuzhiyun                     "\tUsing the %s.\n", pointerMsg);
1254*4882a593Smuzhiyun     }
1255*4882a593Smuzhiyun 
1256*4882a593Smuzhiyun     if (keyboardMsg) {
1257*4882a593Smuzhiyun         if (implicitLayout)
1258*4882a593Smuzhiyun             xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n",
1259*4882a593Smuzhiyun                     keyboardMsg);
1260*4882a593Smuzhiyun         else
1261*4882a593Smuzhiyun             xf86Msg(X_DEFAULT, "The core keyboard device wasn't specified "
1262*4882a593Smuzhiyun                     "explicitly in the layout.\n"
1263*4882a593Smuzhiyun                     "\tUsing the %s.\n", keyboardMsg);
1264*4882a593Smuzhiyun     }
1265*4882a593Smuzhiyun 
1266*4882a593Smuzhiyun     if (!xf86Info.forceInputDevices && !(foundPointer && foundKeyboard)) {
1267*4882a593Smuzhiyun #if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
1268*4882a593Smuzhiyun         const char *config_backend;
1269*4882a593Smuzhiyun 
1270*4882a593Smuzhiyun #if defined(CONFIG_HAL)
1271*4882a593Smuzhiyun         config_backend = "HAL";
1272*4882a593Smuzhiyun #elif defined(CONFIG_UDEV)
1273*4882a593Smuzhiyun         config_backend = "udev";
1274*4882a593Smuzhiyun #else
1275*4882a593Smuzhiyun         config_backend = "wscons";
1276*4882a593Smuzhiyun #endif
1277*4882a593Smuzhiyun         xf86Msg(X_INFO, "The server relies on %s to provide the list of "
1278*4882a593Smuzhiyun                 "input devices.\n\tIf no devices become available, "
1279*4882a593Smuzhiyun                 "reconfigure %s or disable AutoAddDevices.\n",
1280*4882a593Smuzhiyun                 config_backend, config_backend);
1281*4882a593Smuzhiyun #else
1282*4882a593Smuzhiyun         xf86Msg(X_WARNING, "Hotplugging requested but the server was "
1283*4882a593Smuzhiyun                 "compiled without a config backend. "
1284*4882a593Smuzhiyun                 "No input devices were configured, the server "
1285*4882a593Smuzhiyun                 "will start without any input devices.\n");
1286*4882a593Smuzhiyun #endif
1287*4882a593Smuzhiyun     }
1288*4882a593Smuzhiyun 
1289*4882a593Smuzhiyun     return TRUE;
1290*4882a593Smuzhiyun }
1291*4882a593Smuzhiyun 
1292*4882a593Smuzhiyun typedef enum {
1293*4882a593Smuzhiyun     LAYOUT_ISOLATEDEVICE,
1294*4882a593Smuzhiyun     LAYOUT_SINGLECARD
1295*4882a593Smuzhiyun } LayoutValues;
1296*4882a593Smuzhiyun 
1297*4882a593Smuzhiyun static OptionInfoRec LayoutOptions[] = {
1298*4882a593Smuzhiyun     {LAYOUT_ISOLATEDEVICE, "IsolateDevice", OPTV_STRING,
1299*4882a593Smuzhiyun      {0}, FALSE},
1300*4882a593Smuzhiyun     {LAYOUT_SINGLECARD, "SingleCard", OPTV_BOOLEAN,
1301*4882a593Smuzhiyun      {0}, FALSE},
1302*4882a593Smuzhiyun     {-1, NULL, OPTV_NONE,
1303*4882a593Smuzhiyun      {0}, FALSE},
1304*4882a593Smuzhiyun };
1305*4882a593Smuzhiyun 
1306*4882a593Smuzhiyun static Bool
configInputDevices(XF86ConfLayoutPtr layout,serverLayoutPtr servlayoutp)1307*4882a593Smuzhiyun configInputDevices(XF86ConfLayoutPtr layout, serverLayoutPtr servlayoutp)
1308*4882a593Smuzhiyun {
1309*4882a593Smuzhiyun     XF86ConfInputrefPtr irp;
1310*4882a593Smuzhiyun     InputInfoPtr *indp;
1311*4882a593Smuzhiyun     int count = 0;
1312*4882a593Smuzhiyun 
1313*4882a593Smuzhiyun     /*
1314*4882a593Smuzhiyun      * Count the number of input devices.
1315*4882a593Smuzhiyun      */
1316*4882a593Smuzhiyun     irp = layout->lay_input_lst;
1317*4882a593Smuzhiyun     while (irp) {
1318*4882a593Smuzhiyun         count++;
1319*4882a593Smuzhiyun         irp = (XF86ConfInputrefPtr) irp->list.next;
1320*4882a593Smuzhiyun     }
1321*4882a593Smuzhiyun     DebugF("Found %d input devices in the layout section %s\n",
1322*4882a593Smuzhiyun            count, layout->lay_identifier);
1323*4882a593Smuzhiyun     indp = xnfcalloc((count + 1), sizeof(InputInfoPtr));
1324*4882a593Smuzhiyun     indp[count] = NULL;
1325*4882a593Smuzhiyun     irp = layout->lay_input_lst;
1326*4882a593Smuzhiyun     count = 0;
1327*4882a593Smuzhiyun     while (irp) {
1328*4882a593Smuzhiyun         indp[count] = xf86AllocateInput();
1329*4882a593Smuzhiyun         if (!configInput(indp[count], irp->iref_inputdev, X_CONFIG)) {
1330*4882a593Smuzhiyun             do {
1331*4882a593Smuzhiyun                 free(indp[count]);
1332*4882a593Smuzhiyun             } while (count--);
1333*4882a593Smuzhiyun             free(indp);
1334*4882a593Smuzhiyun             return FALSE;
1335*4882a593Smuzhiyun         }
1336*4882a593Smuzhiyun         indp[count]->options = xf86OptionListMerge(indp[count]->options,
1337*4882a593Smuzhiyun                                                    irp->iref_option_lst);
1338*4882a593Smuzhiyun         count++;
1339*4882a593Smuzhiyun         irp = (XF86ConfInputrefPtr) irp->list.next;
1340*4882a593Smuzhiyun     }
1341*4882a593Smuzhiyun     servlayoutp->inputs = indp;
1342*4882a593Smuzhiyun 
1343*4882a593Smuzhiyun     return TRUE;
1344*4882a593Smuzhiyun }
1345*4882a593Smuzhiyun 
1346*4882a593Smuzhiyun /*
1347*4882a593Smuzhiyun  * figure out which layout is active, which screens are used in that layout,
1348*4882a593Smuzhiyun  * which drivers and monitors are used in these screens
1349*4882a593Smuzhiyun  */
1350*4882a593Smuzhiyun static Bool
configLayout(serverLayoutPtr servlayoutp,XF86ConfLayoutPtr conf_layout,char * default_layout)1351*4882a593Smuzhiyun configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
1352*4882a593Smuzhiyun              char *default_layout)
1353*4882a593Smuzhiyun {
1354*4882a593Smuzhiyun     XF86ConfAdjacencyPtr adjp;
1355*4882a593Smuzhiyun     XF86ConfInactivePtr idp;
1356*4882a593Smuzhiyun     int saved_count, count = 0;
1357*4882a593Smuzhiyun     int scrnum;
1358*4882a593Smuzhiyun     XF86ConfLayoutPtr l;
1359*4882a593Smuzhiyun     MessageType from;
1360*4882a593Smuzhiyun     screenLayoutPtr slp;
1361*4882a593Smuzhiyun     GDevPtr gdp;
1362*4882a593Smuzhiyun     int i = 0, j;
1363*4882a593Smuzhiyun 
1364*4882a593Smuzhiyun     if (!servlayoutp)
1365*4882a593Smuzhiyun         return FALSE;
1366*4882a593Smuzhiyun 
1367*4882a593Smuzhiyun     /*
1368*4882a593Smuzhiyun      * which layout section is the active one?
1369*4882a593Smuzhiyun      *
1370*4882a593Smuzhiyun      * If there is a -layout command line option, use that one, otherwise
1371*4882a593Smuzhiyun      * pick the first one.
1372*4882a593Smuzhiyun      */
1373*4882a593Smuzhiyun     from = X_DEFAULT;
1374*4882a593Smuzhiyun     if (xf86LayoutName != NULL)
1375*4882a593Smuzhiyun         from = X_CMDLINE;
1376*4882a593Smuzhiyun     else if (default_layout) {
1377*4882a593Smuzhiyun         xf86LayoutName = default_layout;
1378*4882a593Smuzhiyun         from = X_CONFIG;
1379*4882a593Smuzhiyun     }
1380*4882a593Smuzhiyun     if (xf86LayoutName != NULL) {
1381*4882a593Smuzhiyun         if ((l = xf86findLayout(xf86LayoutName, conf_layout)) == NULL) {
1382*4882a593Smuzhiyun             xf86Msg(X_ERROR, "No ServerLayout section called \"%s\"\n",
1383*4882a593Smuzhiyun                     xf86LayoutName);
1384*4882a593Smuzhiyun             return FALSE;
1385*4882a593Smuzhiyun         }
1386*4882a593Smuzhiyun         conf_layout = l;
1387*4882a593Smuzhiyun     }
1388*4882a593Smuzhiyun     xf86Msg(from, "ServerLayout \"%s\"\n", conf_layout->lay_identifier);
1389*4882a593Smuzhiyun     adjp = conf_layout->lay_adjacency_lst;
1390*4882a593Smuzhiyun 
1391*4882a593Smuzhiyun     /*
1392*4882a593Smuzhiyun      * we know that each screen is referenced exactly once on the left side
1393*4882a593Smuzhiyun      * of a layout statement in the Layout section. So to allocate the right
1394*4882a593Smuzhiyun      * size for the array we do a quick walk of the list to figure out how
1395*4882a593Smuzhiyun      * many sections we have
1396*4882a593Smuzhiyun      */
1397*4882a593Smuzhiyun     while (adjp) {
1398*4882a593Smuzhiyun         count++;
1399*4882a593Smuzhiyun         adjp = (XF86ConfAdjacencyPtr) adjp->list.next;
1400*4882a593Smuzhiyun     }
1401*4882a593Smuzhiyun 
1402*4882a593Smuzhiyun     DebugF("Found %d screens in the layout section %s",
1403*4882a593Smuzhiyun            count, conf_layout->lay_identifier);
1404*4882a593Smuzhiyun     if (!count)                 /* alloc enough storage even if no screen is specified */
1405*4882a593Smuzhiyun         count = 1;
1406*4882a593Smuzhiyun 
1407*4882a593Smuzhiyun     slp = xnfcalloc((count + 1), sizeof(screenLayoutRec));
1408*4882a593Smuzhiyun     slp[count].screen = NULL;
1409*4882a593Smuzhiyun     /*
1410*4882a593Smuzhiyun      * now that we have storage, loop over the list again and fill in our
1411*4882a593Smuzhiyun      * data structure; at this point we do not fill in the adjacency
1412*4882a593Smuzhiyun      * information as it is not clear if we need it at all
1413*4882a593Smuzhiyun      */
1414*4882a593Smuzhiyun     adjp = conf_layout->lay_adjacency_lst;
1415*4882a593Smuzhiyun     count = 0;
1416*4882a593Smuzhiyun     while (adjp) {
1417*4882a593Smuzhiyun         slp[count].screen = xnfcalloc(1, sizeof(confScreenRec));
1418*4882a593Smuzhiyun         if (adjp->adj_scrnum < 0)
1419*4882a593Smuzhiyun             scrnum = count;
1420*4882a593Smuzhiyun         else
1421*4882a593Smuzhiyun             scrnum = adjp->adj_scrnum;
1422*4882a593Smuzhiyun         if (!configScreen(slp[count].screen, adjp->adj_screen, scrnum,
1423*4882a593Smuzhiyun                           X_CONFIG, (scrnum == 0 && !adjp->list.next))) {
1424*4882a593Smuzhiyun             do {
1425*4882a593Smuzhiyun                 free(slp[count].screen);
1426*4882a593Smuzhiyun             } while (count--);
1427*4882a593Smuzhiyun             free(slp);
1428*4882a593Smuzhiyun             return FALSE;
1429*4882a593Smuzhiyun         }
1430*4882a593Smuzhiyun         slp[count].x = adjp->adj_x;
1431*4882a593Smuzhiyun         slp[count].y = adjp->adj_y;
1432*4882a593Smuzhiyun         slp[count].refname = adjp->adj_refscreen;
1433*4882a593Smuzhiyun         switch (adjp->adj_where) {
1434*4882a593Smuzhiyun         case CONF_ADJ_OBSOLETE:
1435*4882a593Smuzhiyun             slp[count].where = PosObsolete;
1436*4882a593Smuzhiyun             slp[count].topname = adjp->adj_top_str;
1437*4882a593Smuzhiyun             slp[count].bottomname = adjp->adj_bottom_str;
1438*4882a593Smuzhiyun             slp[count].leftname = adjp->adj_left_str;
1439*4882a593Smuzhiyun             slp[count].rightname = adjp->adj_right_str;
1440*4882a593Smuzhiyun             break;
1441*4882a593Smuzhiyun         case CONF_ADJ_ABSOLUTE:
1442*4882a593Smuzhiyun             slp[count].where = PosAbsolute;
1443*4882a593Smuzhiyun             break;
1444*4882a593Smuzhiyun         case CONF_ADJ_RIGHTOF:
1445*4882a593Smuzhiyun             slp[count].where = PosRightOf;
1446*4882a593Smuzhiyun             break;
1447*4882a593Smuzhiyun         case CONF_ADJ_LEFTOF:
1448*4882a593Smuzhiyun             slp[count].where = PosLeftOf;
1449*4882a593Smuzhiyun             break;
1450*4882a593Smuzhiyun         case CONF_ADJ_ABOVE:
1451*4882a593Smuzhiyun             slp[count].where = PosAbove;
1452*4882a593Smuzhiyun             break;
1453*4882a593Smuzhiyun         case CONF_ADJ_BELOW:
1454*4882a593Smuzhiyun             slp[count].where = PosBelow;
1455*4882a593Smuzhiyun             break;
1456*4882a593Smuzhiyun         case CONF_ADJ_RELATIVE:
1457*4882a593Smuzhiyun             slp[count].where = PosRelative;
1458*4882a593Smuzhiyun             break;
1459*4882a593Smuzhiyun         }
1460*4882a593Smuzhiyun         count++;
1461*4882a593Smuzhiyun         adjp = (XF86ConfAdjacencyPtr) adjp->list.next;
1462*4882a593Smuzhiyun     }
1463*4882a593Smuzhiyun 
1464*4882a593Smuzhiyun     /* No screen was specified in the layout. take the first one from the
1465*4882a593Smuzhiyun      * config file, or - if it is NULL - configScreen autogenerates one for
1466*4882a593Smuzhiyun      * us */
1467*4882a593Smuzhiyun     if (!count) {
1468*4882a593Smuzhiyun         XF86ConfScreenPtr screen;
1469*4882a593Smuzhiyun 
1470*4882a593Smuzhiyun         FIND_SUITABLE (XF86ConfScreenPtr, xf86configptr->conf_screen_lst, screen);
1471*4882a593Smuzhiyun         slp[0].screen = xnfcalloc(1, sizeof(confScreenRec));
1472*4882a593Smuzhiyun         if (!configScreen(slp[0].screen, screen,
1473*4882a593Smuzhiyun                           0, X_CONFIG, TRUE)) {
1474*4882a593Smuzhiyun             free(slp[0].screen);
1475*4882a593Smuzhiyun             free(slp);
1476*4882a593Smuzhiyun             return FALSE;
1477*4882a593Smuzhiyun         }
1478*4882a593Smuzhiyun     }
1479*4882a593Smuzhiyun 
1480*4882a593Smuzhiyun     /* XXX Need to tie down the upper left screen. */
1481*4882a593Smuzhiyun 
1482*4882a593Smuzhiyun     /* Fill in the refscreen and top/bottom/left/right values */
1483*4882a593Smuzhiyun     for (i = 0; i < count; i++) {
1484*4882a593Smuzhiyun         for (j = 0; j < count; j++) {
1485*4882a593Smuzhiyun             if (slp[i].refname &&
1486*4882a593Smuzhiyun                 strcmp(slp[i].refname, slp[j].screen->id) == 0) {
1487*4882a593Smuzhiyun                 slp[i].refscreen = slp[j].screen;
1488*4882a593Smuzhiyun             }
1489*4882a593Smuzhiyun             if (slp[i].topname &&
1490*4882a593Smuzhiyun                 strcmp(slp[i].topname, slp[j].screen->id) == 0) {
1491*4882a593Smuzhiyun                 slp[i].top = slp[j].screen;
1492*4882a593Smuzhiyun             }
1493*4882a593Smuzhiyun             if (slp[i].bottomname &&
1494*4882a593Smuzhiyun                 strcmp(slp[i].bottomname, slp[j].screen->id) == 0) {
1495*4882a593Smuzhiyun                 slp[i].bottom = slp[j].screen;
1496*4882a593Smuzhiyun             }
1497*4882a593Smuzhiyun             if (slp[i].leftname &&
1498*4882a593Smuzhiyun                 strcmp(slp[i].leftname, slp[j].screen->id) == 0) {
1499*4882a593Smuzhiyun                 slp[i].left = slp[j].screen;
1500*4882a593Smuzhiyun             }
1501*4882a593Smuzhiyun             if (slp[i].rightname &&
1502*4882a593Smuzhiyun                 strcmp(slp[i].rightname, slp[j].screen->id) == 0) {
1503*4882a593Smuzhiyun                 slp[i].right = slp[j].screen;
1504*4882a593Smuzhiyun             }
1505*4882a593Smuzhiyun         }
1506*4882a593Smuzhiyun         if (slp[i].where != PosObsolete
1507*4882a593Smuzhiyun             && slp[i].where != PosAbsolute && !slp[i].refscreen) {
1508*4882a593Smuzhiyun             xf86Msg(X_ERROR, "Screen %s doesn't exist: deleting placement\n",
1509*4882a593Smuzhiyun                     slp[i].refname);
1510*4882a593Smuzhiyun             slp[i].where = PosAbsolute;
1511*4882a593Smuzhiyun             slp[i].x = 0;
1512*4882a593Smuzhiyun             slp[i].y = 0;
1513*4882a593Smuzhiyun         }
1514*4882a593Smuzhiyun     }
1515*4882a593Smuzhiyun 
1516*4882a593Smuzhiyun     if (!count)
1517*4882a593Smuzhiyun         saved_count = 1;
1518*4882a593Smuzhiyun     else
1519*4882a593Smuzhiyun         saved_count = count;
1520*4882a593Smuzhiyun     /*
1521*4882a593Smuzhiyun      * Count the number of inactive devices.
1522*4882a593Smuzhiyun      */
1523*4882a593Smuzhiyun     count = 0;
1524*4882a593Smuzhiyun     idp = conf_layout->lay_inactive_lst;
1525*4882a593Smuzhiyun     while (idp) {
1526*4882a593Smuzhiyun         count++;
1527*4882a593Smuzhiyun         idp = (XF86ConfInactivePtr) idp->list.next;
1528*4882a593Smuzhiyun     }
1529*4882a593Smuzhiyun     DebugF("Found %d inactive devices in the layout section %s\n",
1530*4882a593Smuzhiyun            count, conf_layout->lay_identifier);
1531*4882a593Smuzhiyun     gdp = xnfallocarray(count + 1, sizeof(GDevRec));
1532*4882a593Smuzhiyun     gdp[count].identifier = NULL;
1533*4882a593Smuzhiyun     idp = conf_layout->lay_inactive_lst;
1534*4882a593Smuzhiyun     count = 0;
1535*4882a593Smuzhiyun     while (idp) {
1536*4882a593Smuzhiyun         if (!configDevice(&gdp[count], idp->inactive_device, FALSE, FALSE))
1537*4882a593Smuzhiyun             goto bail;
1538*4882a593Smuzhiyun         count++;
1539*4882a593Smuzhiyun         idp = (XF86ConfInactivePtr) idp->list.next;
1540*4882a593Smuzhiyun     }
1541*4882a593Smuzhiyun 
1542*4882a593Smuzhiyun     if (!configInputDevices(conf_layout, servlayoutp))
1543*4882a593Smuzhiyun         goto bail;
1544*4882a593Smuzhiyun 
1545*4882a593Smuzhiyun     servlayoutp->id = conf_layout->lay_identifier;
1546*4882a593Smuzhiyun     servlayoutp->screens = slp;
1547*4882a593Smuzhiyun     servlayoutp->inactives = gdp;
1548*4882a593Smuzhiyun     servlayoutp->options = conf_layout->lay_option_lst;
1549*4882a593Smuzhiyun     from = X_DEFAULT;
1550*4882a593Smuzhiyun 
1551*4882a593Smuzhiyun     return TRUE;
1552*4882a593Smuzhiyun 
1553*4882a593Smuzhiyun  bail:
1554*4882a593Smuzhiyun     do {
1555*4882a593Smuzhiyun         free(slp[saved_count].screen);
1556*4882a593Smuzhiyun     } while (saved_count--);
1557*4882a593Smuzhiyun     free(slp);
1558*4882a593Smuzhiyun     free(gdp);
1559*4882a593Smuzhiyun     return FALSE;
1560*4882a593Smuzhiyun }
1561*4882a593Smuzhiyun 
1562*4882a593Smuzhiyun /*
1563*4882a593Smuzhiyun  * No layout section, so find the first Screen section and set that up as
1564*4882a593Smuzhiyun  * the only active screen.
1565*4882a593Smuzhiyun  */
1566*4882a593Smuzhiyun static Bool
configImpliedLayout(serverLayoutPtr servlayoutp,XF86ConfScreenPtr conf_screen,XF86ConfigPtr conf_ptr)1567*4882a593Smuzhiyun configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen,
1568*4882a593Smuzhiyun                     XF86ConfigPtr conf_ptr)
1569*4882a593Smuzhiyun {
1570*4882a593Smuzhiyun     MessageType from;
1571*4882a593Smuzhiyun     XF86ConfScreenPtr s;
1572*4882a593Smuzhiyun     screenLayoutPtr slp;
1573*4882a593Smuzhiyun     InputInfoPtr *indp;
1574*4882a593Smuzhiyun     XF86ConfLayoutRec layout;
1575*4882a593Smuzhiyun 
1576*4882a593Smuzhiyun     if (!servlayoutp)
1577*4882a593Smuzhiyun         return FALSE;
1578*4882a593Smuzhiyun 
1579*4882a593Smuzhiyun     /*
1580*4882a593Smuzhiyun      * which screen section is the active one?
1581*4882a593Smuzhiyun      *
1582*4882a593Smuzhiyun      * If there is a -screen option, use that one, otherwise use the first
1583*4882a593Smuzhiyun      * one.
1584*4882a593Smuzhiyun      */
1585*4882a593Smuzhiyun 
1586*4882a593Smuzhiyun     from = X_CONFIG;
1587*4882a593Smuzhiyun     if (xf86ScreenName != NULL) {
1588*4882a593Smuzhiyun         if ((s = xf86findScreen(xf86ScreenName, conf_screen)) == NULL) {
1589*4882a593Smuzhiyun             xf86Msg(X_ERROR, "No Screen section called \"%s\"\n",
1590*4882a593Smuzhiyun                     xf86ScreenName);
1591*4882a593Smuzhiyun             return FALSE;
1592*4882a593Smuzhiyun         }
1593*4882a593Smuzhiyun         conf_screen = s;
1594*4882a593Smuzhiyun         from = X_CMDLINE;
1595*4882a593Smuzhiyun     }
1596*4882a593Smuzhiyun 
1597*4882a593Smuzhiyun     /* We have exactly one screen */
1598*4882a593Smuzhiyun 
1599*4882a593Smuzhiyun     slp = xnfcalloc(1, 2 * sizeof(screenLayoutRec));
1600*4882a593Smuzhiyun     slp[0].screen = xnfcalloc(1, sizeof(confScreenRec));
1601*4882a593Smuzhiyun     slp[1].screen = NULL;
1602*4882a593Smuzhiyun     if (!configScreen(slp[0].screen, conf_screen, 0, from, TRUE)) {
1603*4882a593Smuzhiyun         free(slp);
1604*4882a593Smuzhiyun         return FALSE;
1605*4882a593Smuzhiyun     }
1606*4882a593Smuzhiyun     servlayoutp->id = "(implicit)";
1607*4882a593Smuzhiyun     servlayoutp->screens = slp;
1608*4882a593Smuzhiyun     servlayoutp->inactives = xnfcalloc(1, sizeof(GDevRec));
1609*4882a593Smuzhiyun     servlayoutp->options = NULL;
1610*4882a593Smuzhiyun 
1611*4882a593Smuzhiyun     memset(&layout, 0, sizeof(layout));
1612*4882a593Smuzhiyun     layout.lay_identifier = servlayoutp->id;
1613*4882a593Smuzhiyun     if (xf86layoutAddInputDevices(conf_ptr, &layout) > 0) {
1614*4882a593Smuzhiyun         if (!configInputDevices(&layout, servlayoutp))
1615*4882a593Smuzhiyun             return FALSE;
1616*4882a593Smuzhiyun         from = X_DEFAULT;
1617*4882a593Smuzhiyun     }
1618*4882a593Smuzhiyun     else {
1619*4882a593Smuzhiyun         /* Set up an empty input device list, then look for some core devices. */
1620*4882a593Smuzhiyun         indp = xnfalloc(sizeof(InputInfoPtr));
1621*4882a593Smuzhiyun         *indp = NULL;
1622*4882a593Smuzhiyun         servlayoutp->inputs = indp;
1623*4882a593Smuzhiyun     }
1624*4882a593Smuzhiyun 
1625*4882a593Smuzhiyun     return TRUE;
1626*4882a593Smuzhiyun }
1627*4882a593Smuzhiyun 
1628*4882a593Smuzhiyun static Bool
configXvAdaptor(confXvAdaptorPtr adaptor,XF86ConfVideoAdaptorPtr conf_adaptor)1629*4882a593Smuzhiyun configXvAdaptor(confXvAdaptorPtr adaptor, XF86ConfVideoAdaptorPtr conf_adaptor)
1630*4882a593Smuzhiyun {
1631*4882a593Smuzhiyun     int count = 0;
1632*4882a593Smuzhiyun     XF86ConfVideoPortPtr conf_port;
1633*4882a593Smuzhiyun 
1634*4882a593Smuzhiyun     xf86Msg(X_CONFIG, "|   |-->VideoAdaptor \"%s\"\n",
1635*4882a593Smuzhiyun             conf_adaptor->va_identifier);
1636*4882a593Smuzhiyun     adaptor->identifier = conf_adaptor->va_identifier;
1637*4882a593Smuzhiyun     adaptor->options = conf_adaptor->va_option_lst;
1638*4882a593Smuzhiyun     if (conf_adaptor->va_busid || conf_adaptor->va_driver) {
1639*4882a593Smuzhiyun         xf86Msg(X_CONFIG, "|   | Unsupported device type, skipping entry\n");
1640*4882a593Smuzhiyun         return FALSE;
1641*4882a593Smuzhiyun     }
1642*4882a593Smuzhiyun 
1643*4882a593Smuzhiyun     /*
1644*4882a593Smuzhiyun      * figure out how many videoport subsections there are and fill them in
1645*4882a593Smuzhiyun      */
1646*4882a593Smuzhiyun     conf_port = conf_adaptor->va_port_lst;
1647*4882a593Smuzhiyun     while (conf_port) {
1648*4882a593Smuzhiyun         count++;
1649*4882a593Smuzhiyun         conf_port = (XF86ConfVideoPortPtr) conf_port->list.next;
1650*4882a593Smuzhiyun     }
1651*4882a593Smuzhiyun     adaptor->ports = xnfallocarray(count, sizeof(confXvPortRec));
1652*4882a593Smuzhiyun     adaptor->numports = count;
1653*4882a593Smuzhiyun     count = 0;
1654*4882a593Smuzhiyun     conf_port = conf_adaptor->va_port_lst;
1655*4882a593Smuzhiyun     while (conf_port) {
1656*4882a593Smuzhiyun         adaptor->ports[count].identifier = conf_port->vp_identifier;
1657*4882a593Smuzhiyun         adaptor->ports[count].options = conf_port->vp_option_lst;
1658*4882a593Smuzhiyun         count++;
1659*4882a593Smuzhiyun         conf_port = (XF86ConfVideoPortPtr) conf_port->list.next;
1660*4882a593Smuzhiyun     }
1661*4882a593Smuzhiyun 
1662*4882a593Smuzhiyun     return TRUE;
1663*4882a593Smuzhiyun }
1664*4882a593Smuzhiyun 
1665*4882a593Smuzhiyun static Bool
configScreen(confScreenPtr screenp,XF86ConfScreenPtr conf_screen,int scrnum,MessageType from,Bool auto_gpu_device)1666*4882a593Smuzhiyun configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
1667*4882a593Smuzhiyun              MessageType from, Bool auto_gpu_device)
1668*4882a593Smuzhiyun {
1669*4882a593Smuzhiyun     int count = 0;
1670*4882a593Smuzhiyun     XF86ConfDisplayPtr dispptr;
1671*4882a593Smuzhiyun     XF86ConfAdaptorLinkPtr conf_adaptor;
1672*4882a593Smuzhiyun     Bool defaultMonitor = FALSE;
1673*4882a593Smuzhiyun     XF86ConfScreenRec local_conf_screen;
1674*4882a593Smuzhiyun     int i;
1675*4882a593Smuzhiyun 
1676*4882a593Smuzhiyun     if (!conf_screen) {
1677*4882a593Smuzhiyun         memset(&local_conf_screen, 0, sizeof(local_conf_screen));
1678*4882a593Smuzhiyun         conf_screen = &local_conf_screen;
1679*4882a593Smuzhiyun         conf_screen->scrn_identifier = "Default Screen Section";
1680*4882a593Smuzhiyun         xf86Msg(X_DEFAULT, "No screen section available. Using defaults.\n");
1681*4882a593Smuzhiyun     }
1682*4882a593Smuzhiyun 
1683*4882a593Smuzhiyun     xf86Msg(from, "|-->Screen \"%s\" (%d)\n", conf_screen->scrn_identifier,
1684*4882a593Smuzhiyun             scrnum);
1685*4882a593Smuzhiyun     /*
1686*4882a593Smuzhiyun      * now we fill in the elements of the screen
1687*4882a593Smuzhiyun      */
1688*4882a593Smuzhiyun     screenp->id = conf_screen->scrn_identifier;
1689*4882a593Smuzhiyun     screenp->screennum = scrnum;
1690*4882a593Smuzhiyun     screenp->defaultdepth = conf_screen->scrn_defaultdepth;
1691*4882a593Smuzhiyun     screenp->defaultbpp = conf_screen->scrn_defaultbpp;
1692*4882a593Smuzhiyun     screenp->defaultfbbpp = conf_screen->scrn_defaultfbbpp;
1693*4882a593Smuzhiyun     screenp->monitor = xnfcalloc(1, sizeof(MonRec));
1694*4882a593Smuzhiyun     /* If no monitor is specified, create a default one. */
1695*4882a593Smuzhiyun     if (!conf_screen->scrn_monitor) {
1696*4882a593Smuzhiyun         XF86ConfMonitorRec defMon;
1697*4882a593Smuzhiyun 
1698*4882a593Smuzhiyun         memset(&defMon, 0, sizeof(defMon));
1699*4882a593Smuzhiyun         defMon.mon_identifier = "<default monitor>";
1700*4882a593Smuzhiyun         if (!configMonitor(screenp->monitor, &defMon))
1701*4882a593Smuzhiyun             return FALSE;
1702*4882a593Smuzhiyun         defaultMonitor = TRUE;
1703*4882a593Smuzhiyun     }
1704*4882a593Smuzhiyun     else {
1705*4882a593Smuzhiyun         if (!configMonitor(screenp->monitor, conf_screen->scrn_monitor))
1706*4882a593Smuzhiyun             return FALSE;
1707*4882a593Smuzhiyun     }
1708*4882a593Smuzhiyun     /* Configure the device. If there isn't one configured, attach to the
1709*4882a593Smuzhiyun      * first inactive one that we can configure. If there's none that work,
1710*4882a593Smuzhiyun      * set it to NULL so that the section can be autoconfigured later */
1711*4882a593Smuzhiyun     screenp->device = xnfcalloc(1, sizeof(GDevRec));
1712*4882a593Smuzhiyun     if ((!conf_screen->scrn_device) && (xf86configptr->conf_device_lst)) {
1713*4882a593Smuzhiyun         FIND_SUITABLE (XF86ConfDevicePtr, xf86configptr->conf_device_lst, conf_screen->scrn_device);
1714*4882a593Smuzhiyun         xf86Msg(X_DEFAULT, "No device specified for screen \"%s\".\n"
1715*4882a593Smuzhiyun                 "\tUsing the first device section listed.\n", screenp->id);
1716*4882a593Smuzhiyun     }
1717*4882a593Smuzhiyun     if (configDevice(screenp->device, conf_screen->scrn_device, TRUE, FALSE)) {
1718*4882a593Smuzhiyun         screenp->device->myScreenSection = screenp;
1719*4882a593Smuzhiyun     }
1720*4882a593Smuzhiyun     else {
1721*4882a593Smuzhiyun         screenp->device = NULL;
1722*4882a593Smuzhiyun     }
1723*4882a593Smuzhiyun 
1724*4882a593Smuzhiyun     if (auto_gpu_device && conf_screen->num_gpu_devices == 0 &&
1725*4882a593Smuzhiyun         xf86configptr->conf_device_lst) {
1726*4882a593Smuzhiyun         XF86ConfDevicePtr sdevice = xf86configptr->conf_device_lst->list.next;
1727*4882a593Smuzhiyun 
1728*4882a593Smuzhiyun         for (i = 0; i < MAX_GPUDEVICES; i++) {
1729*4882a593Smuzhiyun             if (!sdevice)
1730*4882a593Smuzhiyun                 break;
1731*4882a593Smuzhiyun 
1732*4882a593Smuzhiyun             FIND_SUITABLE (XF86ConfDevicePtr, sdevice, conf_screen->scrn_gpu_devices[i]);
1733*4882a593Smuzhiyun             if (!conf_screen->scrn_gpu_devices[i])
1734*4882a593Smuzhiyun                 break;
1735*4882a593Smuzhiyun             screenp->gpu_devices[i] = xnfcalloc(1, sizeof(GDevRec));
1736*4882a593Smuzhiyun             if (configDevice(screenp->gpu_devices[i], conf_screen->scrn_gpu_devices[i], TRUE, TRUE)) {
1737*4882a593Smuzhiyun                 screenp->gpu_devices[i]->myScreenSection = screenp;
1738*4882a593Smuzhiyun             }
1739*4882a593Smuzhiyun             sdevice = conf_screen->scrn_gpu_devices[i]->list.next;
1740*4882a593Smuzhiyun         }
1741*4882a593Smuzhiyun         screenp->num_gpu_devices = i;
1742*4882a593Smuzhiyun 
1743*4882a593Smuzhiyun     } else {
1744*4882a593Smuzhiyun         for (i = 0; i < conf_screen->num_gpu_devices; i++) {
1745*4882a593Smuzhiyun             screenp->gpu_devices[i] = xnfcalloc(1, sizeof(GDevRec));
1746*4882a593Smuzhiyun             if (configDevice(screenp->gpu_devices[i], conf_screen->scrn_gpu_devices[i], TRUE, TRUE)) {
1747*4882a593Smuzhiyun                 screenp->gpu_devices[i]->myScreenSection = screenp;
1748*4882a593Smuzhiyun             }
1749*4882a593Smuzhiyun         }
1750*4882a593Smuzhiyun         screenp->num_gpu_devices = conf_screen->num_gpu_devices;
1751*4882a593Smuzhiyun     }
1752*4882a593Smuzhiyun 
1753*4882a593Smuzhiyun     screenp->options = conf_screen->scrn_option_lst;
1754*4882a593Smuzhiyun 
1755*4882a593Smuzhiyun     /*
1756*4882a593Smuzhiyun      * figure out how many display subsections there are and fill them in
1757*4882a593Smuzhiyun      */
1758*4882a593Smuzhiyun     dispptr = conf_screen->scrn_display_lst;
1759*4882a593Smuzhiyun     while (dispptr) {
1760*4882a593Smuzhiyun         count++;
1761*4882a593Smuzhiyun         dispptr = (XF86ConfDisplayPtr) dispptr->list.next;
1762*4882a593Smuzhiyun     }
1763*4882a593Smuzhiyun 
1764*4882a593Smuzhiyun     /* HACK: Pre-alloc a large displays array to avoid later realloc */
1765*4882a593Smuzhiyun     screenp->displays = xnfallocarray(32, sizeof(DispRec));
1766*4882a593Smuzhiyun     screenp->numdisplays = count;
1767*4882a593Smuzhiyun 
1768*4882a593Smuzhiyun     /* Fill in the default Virtual size, if any */
1769*4882a593Smuzhiyun     if (conf_screen->scrn_virtualX && conf_screen->scrn_virtualY) {
1770*4882a593Smuzhiyun         for (count = 0, dispptr = conf_screen->scrn_display_lst;
1771*4882a593Smuzhiyun              dispptr;
1772*4882a593Smuzhiyun              dispptr = (XF86ConfDisplayPtr) dispptr->list.next, count++) {
1773*4882a593Smuzhiyun             screenp->displays[count].virtualX = conf_screen->scrn_virtualX;
1774*4882a593Smuzhiyun             screenp->displays[count].virtualY = conf_screen->scrn_virtualY;
1775*4882a593Smuzhiyun         }
1776*4882a593Smuzhiyun     }
1777*4882a593Smuzhiyun 
1778*4882a593Smuzhiyun     /* Now do the per-Display Virtual sizes */
1779*4882a593Smuzhiyun     count = 0;
1780*4882a593Smuzhiyun     dispptr = conf_screen->scrn_display_lst;
1781*4882a593Smuzhiyun     while (dispptr) {
1782*4882a593Smuzhiyun         configDisplay(&(screenp->displays[count]), dispptr);
1783*4882a593Smuzhiyun         count++;
1784*4882a593Smuzhiyun         dispptr = (XF86ConfDisplayPtr) dispptr->list.next;
1785*4882a593Smuzhiyun     }
1786*4882a593Smuzhiyun 
1787*4882a593Smuzhiyun     /*
1788*4882a593Smuzhiyun      * figure out how many videoadaptor references there are and fill them in
1789*4882a593Smuzhiyun      */
1790*4882a593Smuzhiyun     conf_adaptor = conf_screen->scrn_adaptor_lst;
1791*4882a593Smuzhiyun     while (conf_adaptor) {
1792*4882a593Smuzhiyun         count++;
1793*4882a593Smuzhiyun         conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next;
1794*4882a593Smuzhiyun     }
1795*4882a593Smuzhiyun     screenp->xvadaptors = xnfallocarray(count, sizeof(confXvAdaptorRec));
1796*4882a593Smuzhiyun     screenp->numxvadaptors = 0;
1797*4882a593Smuzhiyun     conf_adaptor = conf_screen->scrn_adaptor_lst;
1798*4882a593Smuzhiyun     while (conf_adaptor) {
1799*4882a593Smuzhiyun         if (configXvAdaptor(&(screenp->xvadaptors[screenp->numxvadaptors]),
1800*4882a593Smuzhiyun                             conf_adaptor->al_adaptor))
1801*4882a593Smuzhiyun             screenp->numxvadaptors++;
1802*4882a593Smuzhiyun         conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next;
1803*4882a593Smuzhiyun     }
1804*4882a593Smuzhiyun 
1805*4882a593Smuzhiyun     if (defaultMonitor) {
1806*4882a593Smuzhiyun         xf86Msg(X_DEFAULT, "No monitor specified for screen \"%s\".\n"
1807*4882a593Smuzhiyun                 "\tUsing a default monitor configuration.\n", screenp->id);
1808*4882a593Smuzhiyun     }
1809*4882a593Smuzhiyun     return TRUE;
1810*4882a593Smuzhiyun }
1811*4882a593Smuzhiyun 
1812*4882a593Smuzhiyun typedef enum {
1813*4882a593Smuzhiyun     MON_REDUCEDBLANKING,
1814*4882a593Smuzhiyun     MON_MAX_PIX_CLOCK,
1815*4882a593Smuzhiyun } MonitorValues;
1816*4882a593Smuzhiyun 
1817*4882a593Smuzhiyun static OptionInfoRec MonitorOptions[] = {
1818*4882a593Smuzhiyun     {MON_REDUCEDBLANKING, "ReducedBlanking", OPTV_BOOLEAN,
1819*4882a593Smuzhiyun      {0}, FALSE},
1820*4882a593Smuzhiyun     {MON_MAX_PIX_CLOCK, "MaxPixClock", OPTV_FREQ,
1821*4882a593Smuzhiyun      {0}, FALSE},
1822*4882a593Smuzhiyun     {-1, NULL, OPTV_NONE,
1823*4882a593Smuzhiyun      {0}, FALSE},
1824*4882a593Smuzhiyun };
1825*4882a593Smuzhiyun 
1826*4882a593Smuzhiyun static Bool
configMonitor(MonPtr monitorp,XF86ConfMonitorPtr conf_monitor)1827*4882a593Smuzhiyun configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor)
1828*4882a593Smuzhiyun {
1829*4882a593Smuzhiyun     int count;
1830*4882a593Smuzhiyun     DisplayModePtr mode, last = NULL;
1831*4882a593Smuzhiyun     XF86ConfModeLinePtr cmodep;
1832*4882a593Smuzhiyun     XF86ConfModesPtr modes;
1833*4882a593Smuzhiyun     XF86ConfModesLinkPtr modeslnk = conf_monitor->mon_modes_sect_lst;
1834*4882a593Smuzhiyun     Gamma zeros = { 0.0, 0.0, 0.0 };
1835*4882a593Smuzhiyun     float badgamma = 0.0;
1836*4882a593Smuzhiyun     double maxPixClock;
1837*4882a593Smuzhiyun 
1838*4882a593Smuzhiyun     xf86Msg(X_CONFIG, "|   |-->Monitor \"%s\"\n", conf_monitor->mon_identifier);
1839*4882a593Smuzhiyun     monitorp->id = conf_monitor->mon_identifier;
1840*4882a593Smuzhiyun     monitorp->vendor = conf_monitor->mon_vendor;
1841*4882a593Smuzhiyun     monitorp->model = conf_monitor->mon_modelname;
1842*4882a593Smuzhiyun     monitorp->Modes = NULL;
1843*4882a593Smuzhiyun     monitorp->Last = NULL;
1844*4882a593Smuzhiyun     monitorp->gamma = zeros;
1845*4882a593Smuzhiyun     monitorp->widthmm = conf_monitor->mon_width;
1846*4882a593Smuzhiyun     monitorp->heightmm = conf_monitor->mon_height;
1847*4882a593Smuzhiyun     monitorp->reducedblanking = FALSE;
1848*4882a593Smuzhiyun     monitorp->maxPixClock = 0;
1849*4882a593Smuzhiyun     monitorp->options = conf_monitor->mon_option_lst;
1850*4882a593Smuzhiyun 
1851*4882a593Smuzhiyun     /*
1852*4882a593Smuzhiyun      * fill in the monitor structure
1853*4882a593Smuzhiyun      */
1854*4882a593Smuzhiyun     for (count = 0;
1855*4882a593Smuzhiyun          count < conf_monitor->mon_n_hsync && count < MAX_HSYNC; count++) {
1856*4882a593Smuzhiyun         monitorp->hsync[count].hi = conf_monitor->mon_hsync[count].hi;
1857*4882a593Smuzhiyun         monitorp->hsync[count].lo = conf_monitor->mon_hsync[count].lo;
1858*4882a593Smuzhiyun     }
1859*4882a593Smuzhiyun     monitorp->nHsync = count;
1860*4882a593Smuzhiyun     for (count = 0;
1861*4882a593Smuzhiyun          count < conf_monitor->mon_n_vrefresh && count < MAX_VREFRESH;
1862*4882a593Smuzhiyun          count++) {
1863*4882a593Smuzhiyun         monitorp->vrefresh[count].hi = conf_monitor->mon_vrefresh[count].hi;
1864*4882a593Smuzhiyun         monitorp->vrefresh[count].lo = conf_monitor->mon_vrefresh[count].lo;
1865*4882a593Smuzhiyun     }
1866*4882a593Smuzhiyun     monitorp->nVrefresh = count;
1867*4882a593Smuzhiyun 
1868*4882a593Smuzhiyun     /*
1869*4882a593Smuzhiyun      * first we collect the mode lines from the UseModes directive
1870*4882a593Smuzhiyun      */
1871*4882a593Smuzhiyun     while (modeslnk) {
1872*4882a593Smuzhiyun         modes = xf86findModes(modeslnk->ml_modes_str,
1873*4882a593Smuzhiyun                               xf86configptr->conf_modes_lst);
1874*4882a593Smuzhiyun         modeslnk->ml_modes = modes;
1875*4882a593Smuzhiyun 
1876*4882a593Smuzhiyun         /* now add the modes found in the modes
1877*4882a593Smuzhiyun            section to the list of modes for this
1878*4882a593Smuzhiyun            monitor unless it has been added before
1879*4882a593Smuzhiyun            because we are reusing the same section
1880*4882a593Smuzhiyun            for another screen */
1881*4882a593Smuzhiyun         if (xf86itemNotSublist((GenericListPtr) conf_monitor->mon_modeline_lst,
1882*4882a593Smuzhiyun                                (GenericListPtr) modes->mon_modeline_lst)) {
1883*4882a593Smuzhiyun             conf_monitor->mon_modeline_lst = (XF86ConfModeLinePtr)
1884*4882a593Smuzhiyun                 xf86addListItem((GenericListPtr) conf_monitor->mon_modeline_lst,
1885*4882a593Smuzhiyun                                 (GenericListPtr) modes->mon_modeline_lst);
1886*4882a593Smuzhiyun         }
1887*4882a593Smuzhiyun         modeslnk = modeslnk->list.next;
1888*4882a593Smuzhiyun     }
1889*4882a593Smuzhiyun 
1890*4882a593Smuzhiyun     /*
1891*4882a593Smuzhiyun      * we need to hook in the mode lines now
1892*4882a593Smuzhiyun      * here both data structures use lists, only our internal one
1893*4882a593Smuzhiyun      * is double linked
1894*4882a593Smuzhiyun      */
1895*4882a593Smuzhiyun     cmodep = conf_monitor->mon_modeline_lst;
1896*4882a593Smuzhiyun     while (cmodep) {
1897*4882a593Smuzhiyun         mode = xnfcalloc(1, sizeof(DisplayModeRec));
1898*4882a593Smuzhiyun         mode->type = 0;
1899*4882a593Smuzhiyun         mode->Clock = cmodep->ml_clock;
1900*4882a593Smuzhiyun         mode->HDisplay = cmodep->ml_hdisplay;
1901*4882a593Smuzhiyun         mode->HSyncStart = cmodep->ml_hsyncstart;
1902*4882a593Smuzhiyun         mode->HSyncEnd = cmodep->ml_hsyncend;
1903*4882a593Smuzhiyun         mode->HTotal = cmodep->ml_htotal;
1904*4882a593Smuzhiyun         mode->VDisplay = cmodep->ml_vdisplay;
1905*4882a593Smuzhiyun         mode->VSyncStart = cmodep->ml_vsyncstart;
1906*4882a593Smuzhiyun         mode->VSyncEnd = cmodep->ml_vsyncend;
1907*4882a593Smuzhiyun         mode->VTotal = cmodep->ml_vtotal;
1908*4882a593Smuzhiyun         mode->Flags = cmodep->ml_flags;
1909*4882a593Smuzhiyun         mode->HSkew = cmodep->ml_hskew;
1910*4882a593Smuzhiyun         mode->VScan = cmodep->ml_vscan;
1911*4882a593Smuzhiyun         mode->name = xnfstrdup(cmodep->ml_identifier);
1912*4882a593Smuzhiyun         if (last) {
1913*4882a593Smuzhiyun             mode->prev = last;
1914*4882a593Smuzhiyun             last->next = mode;
1915*4882a593Smuzhiyun         }
1916*4882a593Smuzhiyun         else {
1917*4882a593Smuzhiyun             /*
1918*4882a593Smuzhiyun              * this is the first mode
1919*4882a593Smuzhiyun              */
1920*4882a593Smuzhiyun             monitorp->Modes = mode;
1921*4882a593Smuzhiyun             mode->prev = NULL;
1922*4882a593Smuzhiyun         }
1923*4882a593Smuzhiyun         last = mode;
1924*4882a593Smuzhiyun         cmodep = (XF86ConfModeLinePtr) cmodep->list.next;
1925*4882a593Smuzhiyun     }
1926*4882a593Smuzhiyun     if (last) {
1927*4882a593Smuzhiyun         last->next = NULL;
1928*4882a593Smuzhiyun     }
1929*4882a593Smuzhiyun     monitorp->Last = last;
1930*4882a593Smuzhiyun 
1931*4882a593Smuzhiyun     /* add the (VESA) default modes */
1932*4882a593Smuzhiyun     if (!addDefaultModes(monitorp))
1933*4882a593Smuzhiyun         return FALSE;
1934*4882a593Smuzhiyun 
1935*4882a593Smuzhiyun     if (conf_monitor->mon_gamma_red > GAMMA_ZERO)
1936*4882a593Smuzhiyun         monitorp->gamma.red = conf_monitor->mon_gamma_red;
1937*4882a593Smuzhiyun     if (conf_monitor->mon_gamma_green > GAMMA_ZERO)
1938*4882a593Smuzhiyun         monitorp->gamma.green = conf_monitor->mon_gamma_green;
1939*4882a593Smuzhiyun     if (conf_monitor->mon_gamma_blue > GAMMA_ZERO)
1940*4882a593Smuzhiyun         monitorp->gamma.blue = conf_monitor->mon_gamma_blue;
1941*4882a593Smuzhiyun 
1942*4882a593Smuzhiyun     /* Check that the gamma values are within range */
1943*4882a593Smuzhiyun     if (monitorp->gamma.red > GAMMA_ZERO &&
1944*4882a593Smuzhiyun         (monitorp->gamma.red < GAMMA_MIN || monitorp->gamma.red > GAMMA_MAX)) {
1945*4882a593Smuzhiyun         badgamma = monitorp->gamma.red;
1946*4882a593Smuzhiyun     }
1947*4882a593Smuzhiyun     else if (monitorp->gamma.green > GAMMA_ZERO &&
1948*4882a593Smuzhiyun              (monitorp->gamma.green < GAMMA_MIN ||
1949*4882a593Smuzhiyun               monitorp->gamma.green > GAMMA_MAX)) {
1950*4882a593Smuzhiyun         badgamma = monitorp->gamma.green;
1951*4882a593Smuzhiyun     }
1952*4882a593Smuzhiyun     else if (monitorp->gamma.blue > GAMMA_ZERO &&
1953*4882a593Smuzhiyun              (monitorp->gamma.blue < GAMMA_MIN ||
1954*4882a593Smuzhiyun               monitorp->gamma.blue > GAMMA_MAX)) {
1955*4882a593Smuzhiyun         badgamma = monitorp->gamma.blue;
1956*4882a593Smuzhiyun     }
1957*4882a593Smuzhiyun     if (badgamma > GAMMA_ZERO) {
1958*4882a593Smuzhiyun         ErrorF("Gamma value %.f is out of range (%.2f - %.1f)\n", badgamma,
1959*4882a593Smuzhiyun                GAMMA_MIN, GAMMA_MAX);
1960*4882a593Smuzhiyun         return FALSE;
1961*4882a593Smuzhiyun     }
1962*4882a593Smuzhiyun 
1963*4882a593Smuzhiyun     xf86ProcessOptions(-1, monitorp->options, MonitorOptions);
1964*4882a593Smuzhiyun     xf86GetOptValBool(MonitorOptions, MON_REDUCEDBLANKING,
1965*4882a593Smuzhiyun                       &monitorp->reducedblanking);
1966*4882a593Smuzhiyun     if (xf86GetOptValFreq(MonitorOptions, MON_MAX_PIX_CLOCK, OPTUNITS_KHZ,
1967*4882a593Smuzhiyun                           &maxPixClock) == TRUE) {
1968*4882a593Smuzhiyun         monitorp->maxPixClock = (int) maxPixClock;
1969*4882a593Smuzhiyun     }
1970*4882a593Smuzhiyun 
1971*4882a593Smuzhiyun     return TRUE;
1972*4882a593Smuzhiyun }
1973*4882a593Smuzhiyun 
1974*4882a593Smuzhiyun static int
lookupVisual(const char * visname)1975*4882a593Smuzhiyun lookupVisual(const char *visname)
1976*4882a593Smuzhiyun {
1977*4882a593Smuzhiyun     int i;
1978*4882a593Smuzhiyun 
1979*4882a593Smuzhiyun     if (!visname || !*visname)
1980*4882a593Smuzhiyun         return -1;
1981*4882a593Smuzhiyun 
1982*4882a593Smuzhiyun     for (i = 0; i <= DirectColor; i++) {
1983*4882a593Smuzhiyun         if (!xf86nameCompare(visname, xf86VisualNames[i]))
1984*4882a593Smuzhiyun             break;
1985*4882a593Smuzhiyun     }
1986*4882a593Smuzhiyun 
1987*4882a593Smuzhiyun     if (i <= DirectColor)
1988*4882a593Smuzhiyun         return i;
1989*4882a593Smuzhiyun 
1990*4882a593Smuzhiyun     return -1;
1991*4882a593Smuzhiyun }
1992*4882a593Smuzhiyun 
1993*4882a593Smuzhiyun static Bool
configDisplay(DispPtr displayp,XF86ConfDisplayPtr conf_display)1994*4882a593Smuzhiyun configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display)
1995*4882a593Smuzhiyun {
1996*4882a593Smuzhiyun     int count = 0;
1997*4882a593Smuzhiyun     XF86ModePtr modep;
1998*4882a593Smuzhiyun 
1999*4882a593Smuzhiyun     displayp->frameX0 = conf_display->disp_frameX0;
2000*4882a593Smuzhiyun     displayp->frameY0 = conf_display->disp_frameY0;
2001*4882a593Smuzhiyun     displayp->virtualX = conf_display->disp_virtualX;
2002*4882a593Smuzhiyun     displayp->virtualY = conf_display->disp_virtualY;
2003*4882a593Smuzhiyun     displayp->depth = conf_display->disp_depth;
2004*4882a593Smuzhiyun     displayp->fbbpp = conf_display->disp_bpp;
2005*4882a593Smuzhiyun     displayp->weight.red = conf_display->disp_weight.red;
2006*4882a593Smuzhiyun     displayp->weight.green = conf_display->disp_weight.green;
2007*4882a593Smuzhiyun     displayp->weight.blue = conf_display->disp_weight.blue;
2008*4882a593Smuzhiyun     displayp->blackColour.red = conf_display->disp_black.red;
2009*4882a593Smuzhiyun     displayp->blackColour.green = conf_display->disp_black.green;
2010*4882a593Smuzhiyun     displayp->blackColour.blue = conf_display->disp_black.blue;
2011*4882a593Smuzhiyun     displayp->whiteColour.red = conf_display->disp_white.red;
2012*4882a593Smuzhiyun     displayp->whiteColour.green = conf_display->disp_white.green;
2013*4882a593Smuzhiyun     displayp->whiteColour.blue = conf_display->disp_white.blue;
2014*4882a593Smuzhiyun     displayp->options = conf_display->disp_option_lst;
2015*4882a593Smuzhiyun     if (conf_display->disp_visual) {
2016*4882a593Smuzhiyun         displayp->defaultVisual = lookupVisual(conf_display->disp_visual);
2017*4882a593Smuzhiyun         if (displayp->defaultVisual == -1) {
2018*4882a593Smuzhiyun             ErrorF("Invalid visual name: \"%s\"\n", conf_display->disp_visual);
2019*4882a593Smuzhiyun             return FALSE;
2020*4882a593Smuzhiyun         }
2021*4882a593Smuzhiyun     }
2022*4882a593Smuzhiyun     else {
2023*4882a593Smuzhiyun         displayp->defaultVisual = -1;
2024*4882a593Smuzhiyun     }
2025*4882a593Smuzhiyun 
2026*4882a593Smuzhiyun     /*
2027*4882a593Smuzhiyun      * now hook in the modes
2028*4882a593Smuzhiyun      */
2029*4882a593Smuzhiyun     modep = conf_display->disp_mode_lst;
2030*4882a593Smuzhiyun     while (modep) {
2031*4882a593Smuzhiyun         count++;
2032*4882a593Smuzhiyun         modep = (XF86ModePtr) modep->list.next;
2033*4882a593Smuzhiyun     }
2034*4882a593Smuzhiyun     displayp->modes = xnfallocarray(count + 1, sizeof(char *));
2035*4882a593Smuzhiyun     modep = conf_display->disp_mode_lst;
2036*4882a593Smuzhiyun     count = 0;
2037*4882a593Smuzhiyun     while (modep) {
2038*4882a593Smuzhiyun         displayp->modes[count] = modep->mode_name;
2039*4882a593Smuzhiyun         count++;
2040*4882a593Smuzhiyun         modep = (XF86ModePtr) modep->list.next;
2041*4882a593Smuzhiyun     }
2042*4882a593Smuzhiyun     displayp->modes[count] = NULL;
2043*4882a593Smuzhiyun 
2044*4882a593Smuzhiyun     return TRUE;
2045*4882a593Smuzhiyun }
2046*4882a593Smuzhiyun 
2047*4882a593Smuzhiyun static Bool
configDevice(GDevPtr devicep,XF86ConfDevicePtr conf_device,Bool active,Bool gpu)2048*4882a593Smuzhiyun configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, Bool active, Bool gpu)
2049*4882a593Smuzhiyun {
2050*4882a593Smuzhiyun     int i;
2051*4882a593Smuzhiyun 
2052*4882a593Smuzhiyun     if (!conf_device) {
2053*4882a593Smuzhiyun         return FALSE;
2054*4882a593Smuzhiyun     }
2055*4882a593Smuzhiyun 
2056*4882a593Smuzhiyun     if (active) {
2057*4882a593Smuzhiyun         if (gpu)
2058*4882a593Smuzhiyun             xf86Msg(X_CONFIG, "|   |-->GPUDevice \"%s\"\n",
2059*4882a593Smuzhiyun                     conf_device->dev_identifier);
2060*4882a593Smuzhiyun         else
2061*4882a593Smuzhiyun             xf86Msg(X_CONFIG, "|   |-->Device \"%s\"\n",
2062*4882a593Smuzhiyun                     conf_device->dev_identifier);
2063*4882a593Smuzhiyun     } else
2064*4882a593Smuzhiyun         xf86Msg(X_CONFIG, "|-->Inactive Device \"%s\"\n",
2065*4882a593Smuzhiyun                 conf_device->dev_identifier);
2066*4882a593Smuzhiyun 
2067*4882a593Smuzhiyun     devicep->identifier = conf_device->dev_identifier;
2068*4882a593Smuzhiyun     devicep->vendor = conf_device->dev_vendor;
2069*4882a593Smuzhiyun     devicep->board = conf_device->dev_board;
2070*4882a593Smuzhiyun     devicep->chipset = conf_device->dev_chipset;
2071*4882a593Smuzhiyun     devicep->ramdac = conf_device->dev_ramdac;
2072*4882a593Smuzhiyun     devicep->driver = conf_device->dev_driver;
2073*4882a593Smuzhiyun     devicep->active = active;
2074*4882a593Smuzhiyun     devicep->videoRam = conf_device->dev_videoram;
2075*4882a593Smuzhiyun     devicep->MemBase = conf_device->dev_mem_base;
2076*4882a593Smuzhiyun     devicep->IOBase = conf_device->dev_io_base;
2077*4882a593Smuzhiyun     devicep->clockchip = conf_device->dev_clockchip;
2078*4882a593Smuzhiyun     devicep->busID = conf_device->dev_busid;
2079*4882a593Smuzhiyun     devicep->chipID = conf_device->dev_chipid;
2080*4882a593Smuzhiyun     devicep->chipRev = conf_device->dev_chiprev;
2081*4882a593Smuzhiyun     devicep->options = conf_device->dev_option_lst;
2082*4882a593Smuzhiyun     devicep->irq = conf_device->dev_irq;
2083*4882a593Smuzhiyun     devicep->screen = conf_device->dev_screen;
2084*4882a593Smuzhiyun 
2085*4882a593Smuzhiyun     for (i = 0; i < MAXDACSPEEDS; i++) {
2086*4882a593Smuzhiyun         if (i < CONF_MAXDACSPEEDS)
2087*4882a593Smuzhiyun             devicep->dacSpeeds[i] = conf_device->dev_dacSpeeds[i];
2088*4882a593Smuzhiyun         else
2089*4882a593Smuzhiyun             devicep->dacSpeeds[i] = 0;
2090*4882a593Smuzhiyun     }
2091*4882a593Smuzhiyun     devicep->numclocks = conf_device->dev_clocks;
2092*4882a593Smuzhiyun     if (devicep->numclocks > MAXCLOCKS)
2093*4882a593Smuzhiyun         devicep->numclocks = MAXCLOCKS;
2094*4882a593Smuzhiyun     for (i = 0; i < devicep->numclocks; i++) {
2095*4882a593Smuzhiyun         devicep->clock[i] = conf_device->dev_clock[i];
2096*4882a593Smuzhiyun     }
2097*4882a593Smuzhiyun     devicep->claimed = FALSE;
2098*4882a593Smuzhiyun 
2099*4882a593Smuzhiyun     return TRUE;
2100*4882a593Smuzhiyun }
2101*4882a593Smuzhiyun 
2102*4882a593Smuzhiyun static void
configDRI(XF86ConfDRIPtr drip)2103*4882a593Smuzhiyun configDRI(XF86ConfDRIPtr drip)
2104*4882a593Smuzhiyun {
2105*4882a593Smuzhiyun     struct group *grp;
2106*4882a593Smuzhiyun 
2107*4882a593Smuzhiyun     xf86ConfigDRI.group = -1;
2108*4882a593Smuzhiyun     xf86ConfigDRI.mode = 0;
2109*4882a593Smuzhiyun 
2110*4882a593Smuzhiyun     if (drip) {
2111*4882a593Smuzhiyun         if (drip->dri_group_name) {
2112*4882a593Smuzhiyun             if ((grp = getgrnam(drip->dri_group_name)))
2113*4882a593Smuzhiyun                 xf86ConfigDRI.group = grp->gr_gid;
2114*4882a593Smuzhiyun         }
2115*4882a593Smuzhiyun         else {
2116*4882a593Smuzhiyun             if (drip->dri_group >= 0)
2117*4882a593Smuzhiyun                 xf86ConfigDRI.group = drip->dri_group;
2118*4882a593Smuzhiyun         }
2119*4882a593Smuzhiyun         xf86ConfigDRI.mode = drip->dri_mode;
2120*4882a593Smuzhiyun     }
2121*4882a593Smuzhiyun }
2122*4882a593Smuzhiyun 
2123*4882a593Smuzhiyun static void
configExtensions(XF86ConfExtensionsPtr conf_ext)2124*4882a593Smuzhiyun configExtensions(XF86ConfExtensionsPtr conf_ext)
2125*4882a593Smuzhiyun {
2126*4882a593Smuzhiyun     XF86OptionPtr o;
2127*4882a593Smuzhiyun 
2128*4882a593Smuzhiyun     if (conf_ext && conf_ext->ext_option_lst) {
2129*4882a593Smuzhiyun         for (o = conf_ext->ext_option_lst; o; o = xf86NextOption(o)) {
2130*4882a593Smuzhiyun             char *name = xf86OptionName(o);
2131*4882a593Smuzhiyun             char *val = xf86OptionValue(o);
2132*4882a593Smuzhiyun             char *n;
2133*4882a593Smuzhiyun             Bool enable = TRUE;
2134*4882a593Smuzhiyun 
2135*4882a593Smuzhiyun             /* Handle "No<ExtensionName>" */
2136*4882a593Smuzhiyun             n = xf86NormalizeName(name);
2137*4882a593Smuzhiyun             if (strncmp(n, "no", 2) == 0) {
2138*4882a593Smuzhiyun                 name += 2;
2139*4882a593Smuzhiyun                 enable = FALSE;
2140*4882a593Smuzhiyun             }
2141*4882a593Smuzhiyun 
2142*4882a593Smuzhiyun             if (!val ||
2143*4882a593Smuzhiyun                 xf86NameCmp(val, "enable") == 0 ||
2144*4882a593Smuzhiyun                 xf86NameCmp(val, "enabled") == 0 ||
2145*4882a593Smuzhiyun                 xf86NameCmp(val, "on") == 0 ||
2146*4882a593Smuzhiyun                 xf86NameCmp(val, "1") == 0 ||
2147*4882a593Smuzhiyun                 xf86NameCmp(val, "yes") == 0 || xf86NameCmp(val, "true") == 0) {
2148*4882a593Smuzhiyun                 /* NOTHING NEEDED -- enabling is handled below */
2149*4882a593Smuzhiyun             }
2150*4882a593Smuzhiyun             else if (xf86NameCmp(val, "disable") == 0 ||
2151*4882a593Smuzhiyun                      xf86NameCmp(val, "disabled") == 0 ||
2152*4882a593Smuzhiyun                      xf86NameCmp(val, "off") == 0 ||
2153*4882a593Smuzhiyun                      xf86NameCmp(val, "0") == 0 ||
2154*4882a593Smuzhiyun                      xf86NameCmp(val, "no") == 0 ||
2155*4882a593Smuzhiyun                      xf86NameCmp(val, "false") == 0) {
2156*4882a593Smuzhiyun                 enable = !enable;
2157*4882a593Smuzhiyun             }
2158*4882a593Smuzhiyun             else {
2159*4882a593Smuzhiyun                 xf86Msg(X_WARNING, "Ignoring unrecognized value \"%s\"\n", val);
2160*4882a593Smuzhiyun                 free(n);
2161*4882a593Smuzhiyun                 continue;
2162*4882a593Smuzhiyun             }
2163*4882a593Smuzhiyun 
2164*4882a593Smuzhiyun             if (EnableDisableExtension(name, enable)) {
2165*4882a593Smuzhiyun                 xf86Msg(X_CONFIG, "Extension \"%s\" is %s\n",
2166*4882a593Smuzhiyun                         name, enable ? "enabled" : "disabled");
2167*4882a593Smuzhiyun             }
2168*4882a593Smuzhiyun             else {
2169*4882a593Smuzhiyun                 xf86Msg(X_WARNING, "Ignoring unrecognized extension \"%s\"\n",
2170*4882a593Smuzhiyun                         name);
2171*4882a593Smuzhiyun             }
2172*4882a593Smuzhiyun             free(n);
2173*4882a593Smuzhiyun         }
2174*4882a593Smuzhiyun     }
2175*4882a593Smuzhiyun }
2176*4882a593Smuzhiyun 
2177*4882a593Smuzhiyun static Bool
configInput(InputInfoPtr inputp,XF86ConfInputPtr conf_input,MessageType from)2178*4882a593Smuzhiyun configInput(InputInfoPtr inputp, XF86ConfInputPtr conf_input, MessageType from)
2179*4882a593Smuzhiyun {
2180*4882a593Smuzhiyun     xf86Msg(from, "|-->Input Device \"%s\"\n", conf_input->inp_identifier);
2181*4882a593Smuzhiyun     inputp->name = conf_input->inp_identifier;
2182*4882a593Smuzhiyun     inputp->driver = conf_input->inp_driver;
2183*4882a593Smuzhiyun     inputp->options = conf_input->inp_option_lst;
2184*4882a593Smuzhiyun     inputp->attrs = NULL;
2185*4882a593Smuzhiyun 
2186*4882a593Smuzhiyun     return TRUE;
2187*4882a593Smuzhiyun }
2188*4882a593Smuzhiyun 
2189*4882a593Smuzhiyun static Bool
modeIsPresent(DisplayModePtr mode,MonPtr monitorp)2190*4882a593Smuzhiyun modeIsPresent(DisplayModePtr mode, MonPtr monitorp)
2191*4882a593Smuzhiyun {
2192*4882a593Smuzhiyun     DisplayModePtr knownmodes = monitorp->Modes;
2193*4882a593Smuzhiyun 
2194*4882a593Smuzhiyun     /* all I can think of is a linear search... */
2195*4882a593Smuzhiyun     while (knownmodes != NULL) {
2196*4882a593Smuzhiyun         if (!strcmp(mode->name, knownmodes->name) &&
2197*4882a593Smuzhiyun             !(knownmodes->type & M_T_DEFAULT))
2198*4882a593Smuzhiyun             return TRUE;
2199*4882a593Smuzhiyun         knownmodes = knownmodes->next;
2200*4882a593Smuzhiyun     }
2201*4882a593Smuzhiyun     return FALSE;
2202*4882a593Smuzhiyun }
2203*4882a593Smuzhiyun 
2204*4882a593Smuzhiyun static Bool
addDefaultModes(MonPtr monitorp)2205*4882a593Smuzhiyun addDefaultModes(MonPtr monitorp)
2206*4882a593Smuzhiyun {
2207*4882a593Smuzhiyun     DisplayModePtr mode;
2208*4882a593Smuzhiyun     DisplayModePtr last = monitorp->Last;
2209*4882a593Smuzhiyun     int i = 0;
2210*4882a593Smuzhiyun 
2211*4882a593Smuzhiyun     for (i = 0; i < xf86NumDefaultModes; i++) {
2212*4882a593Smuzhiyun         mode = xf86DuplicateMode(&xf86DefaultModes[i]);
2213*4882a593Smuzhiyun         if (!modeIsPresent(mode, monitorp)) {
2214*4882a593Smuzhiyun             monitorp->Modes = xf86ModesAdd(monitorp->Modes, mode);
2215*4882a593Smuzhiyun             last = mode;
2216*4882a593Smuzhiyun         }
2217*4882a593Smuzhiyun         else {
2218*4882a593Smuzhiyun             free(mode);
2219*4882a593Smuzhiyun         }
2220*4882a593Smuzhiyun     }
2221*4882a593Smuzhiyun     monitorp->Last = last;
2222*4882a593Smuzhiyun 
2223*4882a593Smuzhiyun     return TRUE;
2224*4882a593Smuzhiyun }
2225*4882a593Smuzhiyun 
2226*4882a593Smuzhiyun static void
checkInput(serverLayoutPtr layout,Bool implicit_layout)2227*4882a593Smuzhiyun checkInput(serverLayoutPtr layout, Bool implicit_layout)
2228*4882a593Smuzhiyun {
2229*4882a593Smuzhiyun     checkCoreInputDevices(layout, implicit_layout);
2230*4882a593Smuzhiyun 
2231*4882a593Smuzhiyun     /* Unless we're forcing input devices, disable mouse/kbd devices in the
2232*4882a593Smuzhiyun      * config. Otherwise the same physical device is added multiple times,
2233*4882a593Smuzhiyun      * leading to duplicate events.
2234*4882a593Smuzhiyun      */
2235*4882a593Smuzhiyun     if (!xf86Info.forceInputDevices && layout->inputs) {
2236*4882a593Smuzhiyun         InputInfoPtr *dev = layout->inputs;
2237*4882a593Smuzhiyun         BOOL warned = FALSE;
2238*4882a593Smuzhiyun 
2239*4882a593Smuzhiyun         while (*dev) {
2240*4882a593Smuzhiyun             if (strcmp((*dev)->driver, "kbd") == 0 ||
2241*4882a593Smuzhiyun                 strcmp((*dev)->driver, "mouse") == 0 ||
2242*4882a593Smuzhiyun                 strcmp((*dev)->driver, "vmmouse") == 0) {
2243*4882a593Smuzhiyun                 InputInfoPtr *current;
2244*4882a593Smuzhiyun 
2245*4882a593Smuzhiyun                 if (!warned) {
2246*4882a593Smuzhiyun                     xf86Msg(X_WARNING, "Hotplugging is on, devices using "
2247*4882a593Smuzhiyun                             "drivers 'kbd', 'mouse' or 'vmmouse' will be disabled.\n");
2248*4882a593Smuzhiyun                     warned = TRUE;
2249*4882a593Smuzhiyun                 }
2250*4882a593Smuzhiyun 
2251*4882a593Smuzhiyun                 xf86Msg(X_WARNING, "Disabling %s\n", (*dev)->name);
2252*4882a593Smuzhiyun 
2253*4882a593Smuzhiyun                 current = dev;
2254*4882a593Smuzhiyun                 free(*dev);
2255*4882a593Smuzhiyun                 *dev = NULL;
2256*4882a593Smuzhiyun 
2257*4882a593Smuzhiyun                 do {
2258*4882a593Smuzhiyun                     *current = *(current + 1);
2259*4882a593Smuzhiyun                     current++;
2260*4882a593Smuzhiyun                 } while (*current);
2261*4882a593Smuzhiyun             }
2262*4882a593Smuzhiyun             else
2263*4882a593Smuzhiyun                 dev++;
2264*4882a593Smuzhiyun         }
2265*4882a593Smuzhiyun     }
2266*4882a593Smuzhiyun }
2267*4882a593Smuzhiyun 
2268*4882a593Smuzhiyun /*
2269*4882a593Smuzhiyun  * load the config file and fill the global data structure
2270*4882a593Smuzhiyun  */
2271*4882a593Smuzhiyun ConfigStatus
xf86HandleConfigFile(Bool autoconfig)2272*4882a593Smuzhiyun xf86HandleConfigFile(Bool autoconfig)
2273*4882a593Smuzhiyun {
2274*4882a593Smuzhiyun #ifdef XSERVER_LIBPCIACCESS
2275*4882a593Smuzhiyun     const char *scanptr;
2276*4882a593Smuzhiyun     Bool singlecard = 0;
2277*4882a593Smuzhiyun #endif
2278*4882a593Smuzhiyun     Bool implicit_layout = FALSE;
2279*4882a593Smuzhiyun     XF86ConfLayoutPtr layout;
2280*4882a593Smuzhiyun 
2281*4882a593Smuzhiyun     if (!autoconfig) {
2282*4882a593Smuzhiyun         char *filename, *dirname, *sysdirname;
2283*4882a593Smuzhiyun         const char *filesearch, *dirsearch;
2284*4882a593Smuzhiyun         MessageType filefrom = X_DEFAULT;
2285*4882a593Smuzhiyun         MessageType dirfrom = X_DEFAULT;
2286*4882a593Smuzhiyun 
2287*4882a593Smuzhiyun         if (!PrivsElevated()) {
2288*4882a593Smuzhiyun             filesearch = ALL_CONFIGPATH;
2289*4882a593Smuzhiyun             dirsearch = ALL_CONFIGDIRPATH;
2290*4882a593Smuzhiyun         }
2291*4882a593Smuzhiyun         else {
2292*4882a593Smuzhiyun             filesearch = RESTRICTED_CONFIGPATH;
2293*4882a593Smuzhiyun             dirsearch = RESTRICTED_CONFIGDIRPATH;
2294*4882a593Smuzhiyun         }
2295*4882a593Smuzhiyun 
2296*4882a593Smuzhiyun         if (xf86ConfigFile)
2297*4882a593Smuzhiyun             filefrom = X_CMDLINE;
2298*4882a593Smuzhiyun         if (xf86ConfigDir)
2299*4882a593Smuzhiyun             dirfrom = X_CMDLINE;
2300*4882a593Smuzhiyun 
2301*4882a593Smuzhiyun         xf86initConfigFiles();
2302*4882a593Smuzhiyun         sysdirname = xf86openConfigDirFiles(SYS_CONFIGDIRPATH, NULL,
2303*4882a593Smuzhiyun                                             PROJECTROOT);
2304*4882a593Smuzhiyun         dirname = xf86openConfigDirFiles(dirsearch, xf86ConfigDir, PROJECTROOT);
2305*4882a593Smuzhiyun         filename = xf86openConfigFile(filesearch, xf86ConfigFile, PROJECTROOT);
2306*4882a593Smuzhiyun         if (filename) {
2307*4882a593Smuzhiyun             xf86MsgVerb(filefrom, 0, "Using config file: \"%s\"\n", filename);
2308*4882a593Smuzhiyun             xf86ConfigFile = xnfstrdup(filename);
2309*4882a593Smuzhiyun         }
2310*4882a593Smuzhiyun         else {
2311*4882a593Smuzhiyun             if (xf86ConfigFile)
2312*4882a593Smuzhiyun                 xf86Msg(X_ERROR, "Unable to locate/open config file: \"%s\"\n",
2313*4882a593Smuzhiyun                         xf86ConfigFile);
2314*4882a593Smuzhiyun         }
2315*4882a593Smuzhiyun         if (dirname) {
2316*4882a593Smuzhiyun             xf86MsgVerb(dirfrom, 0, "Using config directory: \"%s\"\n",
2317*4882a593Smuzhiyun                         dirname);
2318*4882a593Smuzhiyun             xf86ConfigDir = xnfstrdup(dirname);
2319*4882a593Smuzhiyun         }
2320*4882a593Smuzhiyun         else {
2321*4882a593Smuzhiyun             if (xf86ConfigDir)
2322*4882a593Smuzhiyun                 xf86Msg(X_ERROR,
2323*4882a593Smuzhiyun                         "Unable to locate/open config directory: \"%s\"\n",
2324*4882a593Smuzhiyun                         xf86ConfigDir);
2325*4882a593Smuzhiyun         }
2326*4882a593Smuzhiyun         if (sysdirname)
2327*4882a593Smuzhiyun             xf86MsgVerb(X_DEFAULT, 0, "Using system config directory \"%s\"\n",
2328*4882a593Smuzhiyun                         sysdirname);
2329*4882a593Smuzhiyun         if (!filename && !dirname && !sysdirname)
2330*4882a593Smuzhiyun             return CONFIG_NOFILE;
2331*4882a593Smuzhiyun 
2332*4882a593Smuzhiyun         free(filename);
2333*4882a593Smuzhiyun         free(dirname);
2334*4882a593Smuzhiyun         free(sysdirname);
2335*4882a593Smuzhiyun     }
2336*4882a593Smuzhiyun 
2337*4882a593Smuzhiyun     if ((xf86configptr = xf86readConfigFile()) == NULL) {
2338*4882a593Smuzhiyun         xf86Msg(X_ERROR, "Problem parsing the config file\n");
2339*4882a593Smuzhiyun         return CONFIG_PARSE_ERROR;
2340*4882a593Smuzhiyun     }
2341*4882a593Smuzhiyun     xf86closeConfigFile();
2342*4882a593Smuzhiyun 
2343*4882a593Smuzhiyun     /* Initialise a few things. */
2344*4882a593Smuzhiyun 
2345*4882a593Smuzhiyun     /*
2346*4882a593Smuzhiyun      * now we convert part of the information contained in the parser
2347*4882a593Smuzhiyun      * structures into our own structures.
2348*4882a593Smuzhiyun      * The important part here is to figure out which Screen Sections
2349*4882a593Smuzhiyun      * in the XF86Config file are active so that we can piece together
2350*4882a593Smuzhiyun      * the modes that we need later down the road.
2351*4882a593Smuzhiyun      * And while we are at it, we'll decode the rest of the stuff as well
2352*4882a593Smuzhiyun      */
2353*4882a593Smuzhiyun 
2354*4882a593Smuzhiyun     /* First check if a layout section is present, and if it is valid. */
2355*4882a593Smuzhiyun     FIND_SUITABLE(XF86ConfLayoutPtr, xf86configptr->conf_layout_lst, layout);
2356*4882a593Smuzhiyun     if (layout == NULL || xf86ScreenName != NULL) {
2357*4882a593Smuzhiyun         XF86ConfScreenPtr screen;
2358*4882a593Smuzhiyun 
2359*4882a593Smuzhiyun         if (xf86ScreenName == NULL) {
2360*4882a593Smuzhiyun             xf86Msg(X_DEFAULT,
2361*4882a593Smuzhiyun                     "No Layout section.  Using the first Screen section.\n");
2362*4882a593Smuzhiyun         }
2363*4882a593Smuzhiyun         FIND_SUITABLE (XF86ConfScreenPtr, xf86configptr->conf_screen_lst, screen);
2364*4882a593Smuzhiyun         if (!configImpliedLayout(&xf86ConfigLayout,
2365*4882a593Smuzhiyun                                  screen,
2366*4882a593Smuzhiyun                                  xf86configptr)) {
2367*4882a593Smuzhiyun             xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
2368*4882a593Smuzhiyun             return CONFIG_PARSE_ERROR;
2369*4882a593Smuzhiyun         }
2370*4882a593Smuzhiyun         implicit_layout = TRUE;
2371*4882a593Smuzhiyun     }
2372*4882a593Smuzhiyun     else {
2373*4882a593Smuzhiyun         if (xf86configptr->conf_flags != NULL) {
2374*4882a593Smuzhiyun             char *dfltlayout = NULL;
2375*4882a593Smuzhiyun             void *optlist = xf86configptr->conf_flags->flg_option_lst;
2376*4882a593Smuzhiyun 
2377*4882a593Smuzhiyun             if (optlist && xf86FindOption(optlist, "defaultserverlayout"))
2378*4882a593Smuzhiyun                 dfltlayout =
2379*4882a593Smuzhiyun                     xf86SetStrOption(optlist, "defaultserverlayout", NULL);
2380*4882a593Smuzhiyun             if (!configLayout(&xf86ConfigLayout, layout, dfltlayout)) {
2381*4882a593Smuzhiyun                 xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
2382*4882a593Smuzhiyun                 return CONFIG_PARSE_ERROR;
2383*4882a593Smuzhiyun             }
2384*4882a593Smuzhiyun         }
2385*4882a593Smuzhiyun         else {
2386*4882a593Smuzhiyun             if (!configLayout(&xf86ConfigLayout, layout, NULL)) {
2387*4882a593Smuzhiyun                 xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
2388*4882a593Smuzhiyun                 return CONFIG_PARSE_ERROR;
2389*4882a593Smuzhiyun             }
2390*4882a593Smuzhiyun         }
2391*4882a593Smuzhiyun     }
2392*4882a593Smuzhiyun 
2393*4882a593Smuzhiyun     xf86ProcessOptions(-1, xf86ConfigLayout.options, LayoutOptions);
2394*4882a593Smuzhiyun #ifdef XSERVER_LIBPCIACCESS
2395*4882a593Smuzhiyun     if ((scanptr = xf86GetOptValString(LayoutOptions, LAYOUT_ISOLATEDEVICE))) {
2396*4882a593Smuzhiyun         ;                       /* IsolateDevice specified; overrides SingleCard */
2397*4882a593Smuzhiyun     }
2398*4882a593Smuzhiyun     else {
2399*4882a593Smuzhiyun         xf86GetOptValBool(LayoutOptions, LAYOUT_SINGLECARD, &singlecard);
2400*4882a593Smuzhiyun         if (singlecard)
2401*4882a593Smuzhiyun             scanptr = xf86ConfigLayout.screens->screen->device->busID;
2402*4882a593Smuzhiyun     }
2403*4882a593Smuzhiyun     if (scanptr) {
2404*4882a593Smuzhiyun         if (strncmp(scanptr, "PCI:", 4) != 0) {
2405*4882a593Smuzhiyun             xf86Msg(X_WARNING, "Bus types other than PCI not yet isolable.\n"
2406*4882a593Smuzhiyun                     "\tIgnoring IsolateDevice option.\n");
2407*4882a593Smuzhiyun         }
2408*4882a593Smuzhiyun         else
2409*4882a593Smuzhiyun             xf86PciIsolateDevice(scanptr);
2410*4882a593Smuzhiyun     }
2411*4882a593Smuzhiyun #endif
2412*4882a593Smuzhiyun     /* Now process everything else */
2413*4882a593Smuzhiyun     configServerFlags(xf86configptr->conf_flags, xf86ConfigLayout.options);
2414*4882a593Smuzhiyun     configFiles(xf86configptr->conf_files);
2415*4882a593Smuzhiyun     configExtensions(xf86configptr->conf_extensions);
2416*4882a593Smuzhiyun     configDRI(xf86configptr->conf_dri);
2417*4882a593Smuzhiyun 
2418*4882a593Smuzhiyun     checkInput(&xf86ConfigLayout, implicit_layout);
2419*4882a593Smuzhiyun 
2420*4882a593Smuzhiyun     /*
2421*4882a593Smuzhiyun      * Handle some command line options that can override some of the
2422*4882a593Smuzhiyun      * ServerFlags settings.
2423*4882a593Smuzhiyun      */
2424*4882a593Smuzhiyun #ifdef XF86VIDMODE
2425*4882a593Smuzhiyun     if (xf86VidModeDisabled)
2426*4882a593Smuzhiyun         xf86Info.vidModeEnabled = FALSE;
2427*4882a593Smuzhiyun     if (xf86VidModeAllowNonLocal)
2428*4882a593Smuzhiyun         xf86Info.vidModeAllowNonLocal = TRUE;
2429*4882a593Smuzhiyun #endif
2430*4882a593Smuzhiyun 
2431*4882a593Smuzhiyun     if (xf86AllowMouseOpenFail)
2432*4882a593Smuzhiyun         xf86Info.allowMouseOpenFail = TRUE;
2433*4882a593Smuzhiyun 
2434*4882a593Smuzhiyun     return CONFIG_OK;
2435*4882a593Smuzhiyun }
2436*4882a593Smuzhiyun 
2437*4882a593Smuzhiyun Bool
xf86PathIsSafe(const char * path)2438*4882a593Smuzhiyun xf86PathIsSafe(const char *path)
2439*4882a593Smuzhiyun {
2440*4882a593Smuzhiyun     return (xf86pathIsSafe(path) != 0);
2441*4882a593Smuzhiyun }
2442