~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/common/xf86Init.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Init.c,v 3.212 2004/01/27 01:31:45 dawes Exp $ */
 
2
/* $XdotOrg: xserver/xorg/hw/xfree86/common/xf86Init.c,v 1.29 2005/12/14 20:11:16 ajax Exp $ */
 
3
 
 
4
/*
 
5
 * Loosely based on code bearing the following copyright:
 
6
 *
 
7
 *   Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
 
8
 */
 
9
/*
 
10
 * Copyright (c) 1992-2003 by The XFree86 Project, Inc.
 
11
 *
 
12
 * Permission is hereby granted, free of charge, to any person obtaining a
 
13
 * copy of this software and associated documentation files (the "Software"),
 
14
 * to deal in the Software without restriction, including without limitation
 
15
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
16
 * and/or sell copies of the Software, and to permit persons to whom the
 
17
 * Software is furnished to do so, subject to the following conditions:
 
18
 *
 
19
 * The above copyright notice and this permission notice shall be included in
 
20
 * all copies or substantial portions of the Software.
 
21
 *
 
22
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
23
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
24
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
25
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
26
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
27
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
28
 * OTHER DEALINGS IN THE SOFTWARE.
 
29
 *
 
30
 * Except as contained in this notice, the name of the copyright holder(s)
 
31
 * and author(s) shall not be used in advertising or otherwise to promote
 
32
 * the sale, use or other dealings in this Software without prior written
 
33
 * authorization from the copyright holder(s) and author(s).
 
34
 */
 
35
 
 
36
#ifdef HAVE_XORG_CONFIG_H
 
37
#include <xorg-config.h>
 
38
#endif
 
39
 
 
40
#include <stdlib.h>
 
41
 
 
42
#undef HAS_UTSNAME
 
43
#if !defined(WIN32) && !defined(__UNIXOS2__)
 
44
#define HAS_UTSNAME 1
 
45
#include <sys/utsname.h>
 
46
#endif
 
47
 
 
48
#define NEED_EVENTS
 
49
#ifdef __UNIXOS2__
 
50
#define I_NEED_OS2_H
 
51
#endif
 
52
#include <X11/X.h>
 
53
#include <X11/Xmd.h>
 
54
#include <X11/Xproto.h>
 
55
#include <X11/Xatom.h>
 
56
#include "input.h"
 
57
#include "servermd.h"
 
58
#include "windowstr.h"
 
59
#include "scrnintstr.h"
 
60
#include "site.h"
 
61
#include "mi.h"
 
62
 
 
63
#include "compiler.h"
 
64
 
 
65
#ifdef XFree86LOADER
 
66
#include "loaderProcs.h"
 
67
#endif
 
68
#ifdef XFreeXDGA
 
69
#include "dgaproc.h"
 
70
#endif
 
71
 
 
72
#define XF86_OS_PRIVS
 
73
#include "xf86.h"
 
74
#include "xf86Priv.h"
 
75
#include "xf86Config.h"
 
76
#include "xf86_OSlib.h"
 
77
#include "xorgVersion.h"
 
78
#include "xf86Date.h"
 
79
#include "xf86Build.h"
 
80
#include "mipointer.h"
 
81
#ifdef XINPUT
 
82
#include <X11/extensions/XI.h>
 
83
#include <X11/extensions/XIproto.h>
 
84
#else
 
85
#include "inputstr.h"
 
86
#endif
 
87
#include "xf86DDC.h"
 
88
#include "xf86Xinput.h"
 
89
#include "xf86InPriv.h"
 
90
#ifdef RENDER
 
91
#include "picturestr.h"
 
92
#endif
 
93
 
 
94
#include "globals.h"
 
95
 
 
96
#ifdef XTESTEXT1
 
97
#include "atKeynames.h"
 
98
extern int xtest_command_key;
 
99
#endif /* XTESTEXT1 */
 
100
 
 
101
#ifdef DPMSExtension
 
102
#define DPMS_SERVER
 
103
#include <X11/extensions/dpms.h>
 
104
#include "dpmsproc.h"
 
105
#endif
 
106
 
 
107
 
 
108
/* forward declarations */
 
109
 
 
110
static void xf86PrintBanner(void);
 
111
static void xf86PrintMarkers(void);
 
112
static void xf86RunVtInit(void);
 
113
 
 
114
#ifdef __UNIXOS2__
 
115
extern void os2ServerVideoAccess();
 
116
#endif
 
117
 
 
118
#ifdef XF86PM
 
119
void (*xf86OSPMClose)(void) = NULL;
 
120
#endif
 
121
 
 
122
#ifdef XFree86LOADER
 
123
static char *baseModules[] = {
 
124
        "bitmap",
 
125
        "pcidata",
 
126
        NULL
 
127
};
 
128
#endif
 
129
 
 
130
/* Common pixmap formats */
 
131
 
 
132
static PixmapFormatRec formats[MAXFORMATS] = {
 
133
        { 1,    1,      BITMAP_SCANLINE_PAD },
 
134
        { 4,    8,      BITMAP_SCANLINE_PAD },
 
135
        { 8,    8,      BITMAP_SCANLINE_PAD },
 
136
        { 15,   16,     BITMAP_SCANLINE_PAD },
 
137
        { 16,   16,     BITMAP_SCANLINE_PAD },
 
138
        { 24,   32,     BITMAP_SCANLINE_PAD },
 
139
#ifdef RENDER
 
140
        { 32,   32,     BITMAP_SCANLINE_PAD },
 
141
#endif
 
142
};
 
143
#ifdef RENDER
 
144
static int numFormats = 7;
 
145
#else
 
146
static int numFormats = 6;
 
147
#endif
 
148
static Bool formatsDone = FALSE;
 
149
 
 
150
InputDriverRec XF86KEYBOARD = {
 
151
        1,
 
152
        "keyboard",
 
153
        NULL,
 
154
        NULL,
 
155
        NULL,
 
156
        NULL,
 
157
        0
 
158
};
 
159
 
 
160
static Bool
 
161
xf86CreateRootWindow(WindowPtr pWin)
 
162
{
 
163
  int ret = TRUE;
 
164
  int err = Success;
 
165
  ScreenPtr pScreen = pWin->drawable.pScreen;
 
166
  RootWinPropPtr pProp;
 
167
  CreateWindowProcPtr CreateWindow =
 
168
    (CreateWindowProcPtr)(pScreen->devPrivates[xf86CreateRootWindowIndex].ptr);
 
169
 
 
170
#ifdef DEBUG
 
171
  ErrorF("xf86CreateRootWindow(%p)\n", pWin);
 
172
#endif
 
173
 
 
174
  if ( pScreen->CreateWindow != xf86CreateRootWindow ) {
 
175
    /* Can't find hook we are hung on */
 
176
        xf86DrvMsg(pScreen->myNum, X_WARNING /* X_ERROR */,
 
177
                  "xf86CreateRootWindow %p called when not in pScreen->CreateWindow %p n",
 
178
                   (void *)xf86CreateRootWindow,
 
179
                   (void *)pScreen->CreateWindow );
 
180
  }
 
181
 
 
182
  /* Unhook this function ... */
 
183
  pScreen->CreateWindow = CreateWindow;
 
184
  pScreen->devPrivates[xf86CreateRootWindowIndex].ptr = NULL;
 
185
 
 
186
  /* ... and call the previous CreateWindow fuction, if any */
 
187
  if (NULL!=pScreen->CreateWindow) {
 
188
    ret = (*pScreen->CreateWindow)(pWin);
 
189
  }
 
190
 
 
191
  /* Now do our stuff */
 
192
  if (xf86RegisteredPropertiesTable != NULL) {
 
193
    if (pWin->parent == NULL && xf86RegisteredPropertiesTable != NULL) {
 
194
      for (pProp = xf86RegisteredPropertiesTable[pScreen->myNum];
 
195
           pProp != NULL && err==Success;
 
196
           pProp = pProp->next )
 
197
        {
 
198
          Atom prop;
 
199
 
 
200
          prop = MakeAtom(pProp->name, strlen(pProp->name), TRUE);
 
201
          err = ChangeWindowProperty(pWin,
 
202
                                     prop, pProp->type,
 
203
                                     pProp->format, PropModeReplace,
 
204
                                     pProp->size, pProp->data,
 
205
                                     FALSE
 
206
                                     );
 
207
        }
 
208
      
 
209
      /* Look at err */
 
210
      ret &= (err==Success);
 
211
      
 
212
    } else {
 
213
      xf86Msg(X_ERROR, "xf86CreateRootWindow unexpectedly called with "
 
214
              "non-root window %p (parent %p)\n",
 
215
              (void *)pWin, (void *)pWin->parent);
 
216
      ret = FALSE;
 
217
    }
 
218
  }
 
219
 
 
220
#ifdef DEBUG
 
221
  ErrorF("xf86CreateRootWindow() returns %d\n", ret);
 
222
#endif
 
223
  return (ret);
 
224
}
 
225
 
 
226
 
 
227
/*
 
228
 * InitOutput --
 
229
 *      Initialize screenInfo for all actually accessible framebuffers.
 
230
 *      That includes vt-manager setup, querying all possible devices and
 
231
 *      collecting the pixmap formats.
 
232
 */
 
233
 
 
234
static void
 
235
PostConfigInit(void)
 
236
{
 
237
    /*
 
238
     * Install signal handler for unexpected signals
 
239
     */
 
240
    xf86Info.caughtSignal=FALSE;
 
241
    if (!xf86Info.notrapSignals) {
 
242
       signal(SIGSEGV,xf86SigHandler);
 
243
       signal(SIGILL,xf86SigHandler);
 
244
#ifdef SIGEMT
 
245
       signal(SIGEMT,xf86SigHandler);
 
246
#endif
 
247
       signal(SIGFPE,xf86SigHandler);
 
248
#ifdef SIGBUS
 
249
       signal(SIGBUS,xf86SigHandler);
 
250
#endif
 
251
#ifdef SIGSYS
 
252
       signal(SIGSYS,xf86SigHandler);
 
253
#endif
 
254
#ifdef SIGXCPU
 
255
       signal(SIGXCPU,xf86SigHandler);
 
256
#endif
 
257
#ifdef SIGXFSZ
 
258
       signal(SIGXFSZ,xf86SigHandler);
 
259
#endif
 
260
#ifdef MEMDEBUG
 
261
       signal(SIGUSR2,xf86SigMemDebug);
 
262
#endif
 
263
    }
 
264
 
 
265
#ifdef XF86PM
 
266
    xf86OSPMClose = xf86OSPMOpen();
 
267
#endif
 
268
    
 
269
    /* Run an external VT Init program if specified in the config file */
 
270
    xf86RunVtInit();
 
271
 
 
272
    /* Do this after XF86Config is read (it's normally in OsInit()) */
 
273
    OsInitColors();
 
274
}
 
275
 
 
276
void
 
277
InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
 
278
{
 
279
  int                    i, j, k, scr_index;
 
280
  static unsigned long   generation = 0;
 
281
#ifdef XFree86LOADER
 
282
  char                   **modulelist;
 
283
  pointer                *optionlist;
 
284
#endif
 
285
  screenLayoutPtr        layout;
 
286
  Pix24Flags             screenpix24, pix24;
 
287
  MessageType            pix24From = X_DEFAULT;
 
288
  Bool                   pix24Fail = FALSE;
 
289
  Bool                   autoconfig = FALSE;
 
290
  
 
291
#ifdef __UNIXOS2__
 
292
  os2ServerVideoAccess();  /* See if we have access to the screen before doing anything */
 
293
#endif
 
294
 
 
295
  xf86Initialising = TRUE;
 
296
 
 
297
  /* Do this early? */
 
298
  if (generation != serverGeneration) {
 
299
      xf86ScreenIndex = AllocateScreenPrivateIndex();
 
300
      xf86CreateRootWindowIndex = AllocateScreenPrivateIndex();
 
301
      xf86PixmapIndex = AllocatePixmapPrivateIndex();
 
302
      generation = serverGeneration;
 
303
  }
 
304
 
 
305
  if (serverGeneration == 1) {
 
306
 
 
307
    pScreenInfo->numScreens = 0;
 
308
 
 
309
    if ((xf86ServerName = strrchr(argv[0], '/')) != 0)
 
310
      xf86ServerName++;
 
311
    else
 
312
      xf86ServerName = argv[0];
 
313
 
 
314
    xf86PrintBanner();
 
315
    xf86PrintMarkers();
 
316
    if (xf86LogFile)  {
 
317
        time_t t;
 
318
        const char *ct;
 
319
        t = time(NULL);
 
320
        ct = ctime(&t);
 
321
        xf86MsgVerb(xf86LogFileFrom, 0, "Log file: \"%s\", Time: %s",
 
322
                    xf86LogFile, ct);
 
323
    }
 
324
 
 
325
    /* Read and parse the config file */
 
326
    if (!xf86DoProbe && !xf86DoConfigure) {
 
327
      switch (xf86HandleConfigFile(FALSE)) {
 
328
      case CONFIG_OK:
 
329
        break;
 
330
      case CONFIG_PARSE_ERROR:
 
331
        xf86Msg(X_ERROR, "Error parsing the config file\n");
 
332
        return;
 
333
      case CONFIG_NOFILE:
 
334
        autoconfig = TRUE;
 
335
        break;
 
336
      }
 
337
    }
 
338
 
 
339
    if (!autoconfig)
 
340
        PostConfigInit();
 
341
 
 
342
#ifdef XFree86LOADER
 
343
    /* Initialise the loader */
 
344
    LoaderInit();
 
345
 
 
346
    /* Tell the loader the default module search path */
 
347
    LoaderSetPath(xf86ModulePath);
 
348
 
 
349
#ifdef TESTING
 
350
    {
 
351
        char **list, **l;
 
352
        const char *subdirs[] = {
 
353
                "drivers",
 
354
                NULL
 
355
        };
 
356
        const char *patlist[] = {
 
357
                "(.*)_drv\\.so",
 
358
                "(.*)_drv\\.o",
 
359
                NULL
 
360
        };
 
361
        ErrorF("Getting module listing...\n");
 
362
        list = LoaderListDirs(NULL, NULL);
 
363
        if (list)
 
364
            for (l = list; *l; l++)
 
365
                ErrorF("module: %s\n", *l);
 
366
        LoaderFreeDirList(list);
 
367
        ErrorF("Getting video driver listing...\n");
 
368
        list = LoaderListDirs(subdirs, NULL);
 
369
        if (list)
 
370
            for (l = list; *l; l++)
 
371
                ErrorF("video driver: %s\n", *l);
 
372
        LoaderFreeDirList(list);
 
373
        ErrorF("Getting driver listing...\n");
 
374
        list = LoaderListDirs(NULL, patlist);
 
375
        if (list)
 
376
            for (l = list; *l; l++)
 
377
                ErrorF("video driver: %s\n", *l);
 
378
        LoaderFreeDirList(list);
 
379
    }
 
380
#endif
 
381
        
 
382
    /* Force load mandatory base modules */
 
383
    if (!xf86LoadModules(baseModules, NULL))
 
384
        FatalError("Unable to load required base modules, Exiting...\n");
 
385
    
 
386
#endif
 
387
 
 
388
    xf86OpenConsole();
 
389
 
 
390
    /* Do a general bus probe.  This will be a PCI probe for x86 platforms */
 
391
    xf86BusProbe();
 
392
 
 
393
    if (xf86DoProbe)
 
394
        DoProbe();
 
395
 
 
396
    if (xf86DoConfigure)
 
397
        DoConfigure();
 
398
 
 
399
    if (autoconfig) {
 
400
        if (!xf86AutoConfig()) {
 
401
            xf86Msg(X_ERROR, "Auto configuration failed\n");
 
402
            return;
 
403
        }
 
404
        PostConfigInit();
 
405
    }
 
406
 
 
407
    /* Initialise the resource broker */
 
408
    xf86ResourceBrokerInit();
 
409
 
 
410
#ifdef XFree86LOADER
 
411
    /* Load all modules specified explicitly in the config file */
 
412
    if ((modulelist = xf86ModulelistFromConfig(&optionlist))) {
 
413
      xf86LoadModules(modulelist, optionlist);
 
414
      xfree(modulelist);
 
415
      xfree(optionlist);
 
416
    }
 
417
 
 
418
    /* Load all driver modules specified in the config file */
 
419
    if ((modulelist = xf86DriverlistFromConfig())) {
 
420
      xf86LoadModules(modulelist, NULL);
 
421
      xfree(modulelist);
 
422
    }
 
423
 
 
424
#ifdef USE_DEPRECATED_KEYBOARD_DRIVER
 
425
    /* Setup the builtin input drivers */
 
426
    xf86AddInputDriver(&XF86KEYBOARD, NULL, 0);
 
427
#endif
 
428
    /* Load all input driver modules specified in the config file. */
 
429
    if ((modulelist = xf86InputDriverlistFromConfig())) {
 
430
      xf86LoadModules(modulelist, NULL);
 
431
      xfree(modulelist);
 
432
    }
 
433
 
 
434
    /*
 
435
     * It is expected that xf86AddDriver()/xf86AddInputDriver will be
 
436
     * called for each driver as it is loaded.  Those functions save the
 
437
     * module pointers for drivers.
 
438
     * XXX Nothing keeps track of them for other modules.
 
439
     */
 
440
    /* XXX What do we do if not all of these could be loaded? */
 
441
#endif
 
442
 
 
443
    /*
 
444
     * At this point, xf86DriverList[] is all filled in with entries for
 
445
     * each of the drivers to try and xf86NumDrivers has the number of
 
446
     * drivers.  If there are none, return now.
 
447
     */
 
448
 
 
449
    if (xf86NumDrivers == 0) {
 
450
      xf86Msg(X_ERROR, "No drivers available.\n");
 
451
      return;
 
452
    }
 
453
 
 
454
    /*
 
455
     * Call each of the Identify functions and call the driverFunc to check
 
456
     * if HW access is required.  The Identify functions print out some
 
457
     * identifying information, and anything else that might be
 
458
     * needed at this early stage.
 
459
     */
 
460
 
 
461
    for (i = 0; i < xf86NumDrivers; i++) {
 
462
        xorgHWFlags flags;
 
463
      /* The Identify function is mandatory, but if it isn't there continue */
 
464
        if (xf86DriverList[i]->Identify != NULL)
 
465
            xf86DriverList[i]->Identify(0);
 
466
        else {
 
467
            xf86Msg(X_WARNING, "Driver `%s' has no Identify function\n",
 
468
                  xf86DriverList[i]->driverName ? xf86DriverList[i]->driverName
 
469
                                             : "noname");
 
470
        }
 
471
        if (!xorgHWAccess
 
472
            && (!xf86DriverList[i]->driverFunc
 
473
                || !xf86DriverList[i]->driverFunc(NULL,
 
474
                                                  GET_REQUIRED_HW_INTERFACES,
 
475
                                                  &flags)
 
476
                || NEED_IO_ENABLED(flags)))
 
477
            xorgHWAccess = TRUE;
 
478
    }
 
479
 
 
480
    /* Enable full I/O access */
 
481
    if (xorgHWAccess) {
 
482
        if(!xf86EnableIO())
 
483
            /* oops, we have failed */
 
484
            xorgHWAccess = FALSE;
 
485
    }
 
486
 
 
487
    /*
 
488
     * Locate bus slot that had register IO enabled at server startup
 
489
     */
 
490
 
 
491
    xf86AccessInit();
 
492
    xf86FindPrimaryDevice();
 
493
 
 
494
    /*
 
495
     * Now call each of the Probe functions.  Each successful probe will
 
496
     * result in an extra entry added to the xf86Screens[] list for each
 
497
     * instance of the hardware found.
 
498
     */
 
499
 
 
500
    for (i = 0; i < xf86NumDrivers; i++) {
 
501
        xorgHWFlags flags;
 
502
        if (!xorgHWAccess) {
 
503
            if (!xf86DriverList[i]->driverFunc
 
504
                || !xf86DriverList[i]->driverFunc(NULL,
 
505
                                                 GET_REQUIRED_HW_INTERFACES,
 
506
                                                  &flags)
 
507
                || NEED_IO_ENABLED(flags)) 
 
508
                continue;
 
509
        }
 
510
            
 
511
        if (xf86DriverList[i]->Probe != NULL)
 
512
            xf86DriverList[i]->Probe(xf86DriverList[i], PROBE_DEFAULT);
 
513
        else {
 
514
            xf86MsgVerb(X_WARNING, 0,
 
515
                        "Driver `%s' has no Probe function (ignoring)\n",
 
516
                        xf86DriverList[i]->driverName
 
517
                        ? xf86DriverList[i]->driverName : "noname");
 
518
        }
 
519
        xf86SetPciVideo(NULL,NONE);
 
520
    }
 
521
 
 
522
    /*
 
523
     * If nothing was detected, return now.
 
524
     */
 
525
 
 
526
    if (xf86NumScreens == 0) {
 
527
      xf86Msg(X_ERROR, "No devices detected.\n");
 
528
      return;
 
529
    }
 
530
 
 
531
    /*
 
532
     * Match up the screens found by the probes against those specified
 
533
     * in the config file.  Remove the ones that won't be used.  Sort
 
534
     * them in the order specified.
 
535
     */
 
536
 
 
537
    /*
 
538
     * What is the best way to do this?
 
539
     *
 
540
     * For now, go through the screens allocated by the probes, and
 
541
     * look for screen config entry which refers to the same device
 
542
     * section as picked out by the probe.
 
543
     *
 
544
     */
 
545
 
 
546
    for (i = 0; i < xf86NumScreens; i++) {
 
547
      for (layout = xf86ConfigLayout.screens; layout->screen != NULL;
 
548
           layout++) {
 
549
          Bool found = FALSE;
 
550
          for (j = 0; j < xf86Screens[i]->numEntities; j++) {
 
551
        
 
552
              GDevPtr dev =
 
553
                xf86GetDevFromEntity(xf86Screens[i]->entityList[j],
 
554
                                     xf86Screens[i]->entityInstanceList[j]);
 
555
 
 
556
              if (dev == layout->screen->device) {
 
557
                  /* A match has been found */
 
558
                  xf86Screens[i]->confScreen = layout->screen;
 
559
                  found = TRUE;
 
560
                  break;
 
561
              }
 
562
          }
 
563
          if (found) break;
 
564
      }
 
565
      if (layout->screen == NULL) {
 
566
        /* No match found */
 
567
        xf86Msg(X_ERROR,
 
568
            "Screen %d deleted because of no matching config section.\n", i);
 
569
        xf86DeleteScreen(i--, 0);
 
570
      }
 
571
    }
 
572
 
 
573
    /*
 
574
     * If no screens left, return now.
 
575
     */
 
576
 
 
577
    if (xf86NumScreens == 0) {
 
578
      xf86Msg(X_ERROR,
 
579
              "Device(s) detected, but none match those in the config file.\n");
 
580
      return;
 
581
    }
 
582
 
 
583
    xf86PostProbe();
 
584
    xf86EntityInit();
 
585
 
 
586
    /*
 
587
     * Sort the drivers to match the requested ording.  Using a slow
 
588
     * bubble sort.
 
589
     */
 
590
    for (j = 0; j < xf86NumScreens - 1; j++) {
 
591
        for (i = 0; i < xf86NumScreens - j - 1; i++) {
 
592
            if (xf86Screens[i + 1]->confScreen->screennum <
 
593
                xf86Screens[i]->confScreen->screennum) {
 
594
                ScrnInfoPtr tmpScrn = xf86Screens[i + 1];
 
595
                xf86Screens[i + 1] = xf86Screens[i];
 
596
                xf86Screens[i] = tmpScrn;
 
597
            }
 
598
        }
 
599
    }
 
600
    /* Fix up the indexes */
 
601
    for (i = 0; i < xf86NumScreens; i++) {
 
602
        xf86Screens[i]->scrnIndex = i;
 
603
    }
 
604
 
 
605
    /*
 
606
     * Call the driver's PreInit()'s to complete initialisation for the first
 
607
     * generation.
 
608
     */
 
609
    
 
610
    for (i = 0; i < xf86NumScreens; i++) {
 
611
        xf86EnableAccess(xf86Screens[i]);
 
612
        if (xf86Screens[i]->PreInit &&
 
613
            xf86Screens[i]->PreInit(xf86Screens[i], 0))
 
614
            xf86Screens[i]->configured = TRUE;
 
615
    }
 
616
    for (i = 0; i < xf86NumScreens; i++)
 
617
        if (!xf86Screens[i]->configured)
 
618
            xf86DeleteScreen(i--, 0);
 
619
    
 
620
    /*
 
621
     * If no screens left, return now.
 
622
     */
 
623
 
 
624
    if (xf86NumScreens == 0) {
 
625
      xf86Msg(X_ERROR,
 
626
              "Screen(s) found, but none have a usable configuration.\n");
 
627
      return;
 
628
    }
 
629
 
 
630
    /* This could be moved into a separate function */
 
631
 
 
632
    /*
 
633
     * Check that all screens have initialised the mandatory function
 
634
     * entry points.  Delete those which have not.
 
635
     */
 
636
 
 
637
#define WARN_SCREEN(func) \
 
638
    xf86Msg(X_ERROR, "Driver `%s' has no %s function, deleting.\n", \
 
639
           xf86Screens[i]->name, (warned++, func))
 
640
 
 
641
    for (i = 0; i < xf86NumScreens; i++) {
 
642
      int warned = 0;
 
643
      if (xf86Screens[i]->name == NULL) {
 
644
        xf86Screens[i]->name = xnfalloc(strlen("screen") + 1 + 1);
 
645
        if (i < 10)
 
646
          sprintf(xf86Screens[i]->name, "screen%c", i + '0');
 
647
        else
 
648
          sprintf(xf86Screens[i]->name, "screen%c", i - 10 + 'A');
 
649
        xf86MsgVerb(X_WARNING, 0,
 
650
                    "Screen driver %d has no name set, using `%s'.\n",
 
651
                    i, xf86Screens[i]->name);
 
652
      }
 
653
      if (xf86Screens[i]->ScreenInit == NULL)
 
654
        WARN_SCREEN("ScreenInit");
 
655
      if (xf86Screens[i]->EnterVT == NULL)
 
656
        WARN_SCREEN("EnterVT");
 
657
      if (xf86Screens[i]->LeaveVT == NULL)
 
658
        WARN_SCREEN("LeaveVT");
 
659
      if (warned)
 
660
        xf86DeleteScreen(i--, 0);
 
661
    }
 
662
 
 
663
    /*
 
664
     * If no screens left, return now.
 
665
     */
 
666
 
 
667
    if (xf86NumScreens == 0) {
 
668
      xf86Msg(X_ERROR, "Screen(s) found, but drivers were unusable.\n");
 
669
      return;
 
670
    }
 
671
 
 
672
    /* XXX Should this be before or after loading dependent modules? */
 
673
    if (xf86ProbeOnly)
 
674
    {
 
675
      OsCleanup(TRUE);
 
676
      AbortDDX();
 
677
      fflush(stderr);
 
678
      exit(0);
 
679
    }
 
680
 
 
681
#ifdef XFree86LOADER
 
682
    /* Remove (unload) drivers that are not required */
 
683
    for (i = 0; i < xf86NumDrivers; i++)
 
684
        if (xf86DriverList[i] && xf86DriverList[i]->refCount <= 0)
 
685
            xf86DeleteDriver(i);
 
686
#endif
 
687
 
 
688
    /*
 
689
     * At this stage we know how many screens there are.
 
690
     */
 
691
 
 
692
    for (i = 0; i < xf86NumScreens; i++)
 
693
      xf86InitViewport(xf86Screens[i]);
 
694
 
 
695
    /*
 
696
     * Collect all pixmap formats and check for conflicts at the display
 
697
     * level.  Should we die here?  Or just delete the offending screens?
 
698
     * Also, should this be done for -probeonly?
 
699
     */
 
700
    screenpix24 = Pix24DontCare;
 
701
    for (i = 0; i < xf86NumScreens; i++) {
 
702
        if (xf86Screens[i]->imageByteOrder !=
 
703
            xf86Screens[0]->imageByteOrder)
 
704
            FatalError("Inconsistent display bitmapBitOrder.  Exiting\n");
 
705
        if (xf86Screens[i]->bitmapScanlinePad !=
 
706
            xf86Screens[0]->bitmapScanlinePad)
 
707
            FatalError("Inconsistent display bitmapScanlinePad.  Exiting\n");
 
708
        if (xf86Screens[i]->bitmapScanlineUnit !=
 
709
            xf86Screens[0]->bitmapScanlineUnit)
 
710
            FatalError("Inconsistent display bitmapScanlineUnit.  Exiting\n");
 
711
        if (xf86Screens[i]->bitmapBitOrder !=
 
712
            xf86Screens[0]->bitmapBitOrder)
 
713
            FatalError("Inconsistent display bitmapBitOrder.  Exiting\n");
 
714
 
 
715
        /* Determine the depth 24 pixmap format the screens would like */
 
716
        if (xf86Screens[i]->pixmap24 != Pix24DontCare) {
 
717
            if (screenpix24 == Pix24DontCare)
 
718
                screenpix24 = xf86Screens[i]->pixmap24;
 
719
            else if (screenpix24 != xf86Screens[i]->pixmap24)
 
720
                FatalError("Inconsistent depth 24 pixmap format.  Exiting\n");
 
721
        }
 
722
    }
 
723
    /* check if screenpix24 is consistent with the config/cmdline */
 
724
    if (xf86Info.pixmap24 != Pix24DontCare) {
 
725
        pix24 = xf86Info.pixmap24;
 
726
        pix24From = xf86Info.pix24From;
 
727
        if (screenpix24 != Pix24DontCare && screenpix24 != xf86Info.pixmap24)
 
728
            pix24Fail = TRUE;
 
729
    } else if (screenpix24 != Pix24DontCare) {
 
730
        pix24 = screenpix24;
 
731
        pix24From = X_PROBED;
 
732
    } else
 
733
        pix24 = Pix24Use32;
 
734
 
 
735
    if (pix24Fail)
 
736
        FatalError("Screen(s) can't use the required depth 24 pixmap format"
 
737
                   " (%d).  Exiting\n", PIX24TOBPP(pix24));
 
738
 
 
739
    /* Initialise the depth 24 format */
 
740
    for (j = 0; j < numFormats && formats[j].depth != 24; j++)
 
741
        ;
 
742
    formats[j].bitsPerPixel = PIX24TOBPP(pix24);
 
743
 
 
744
    /* Collect additional formats */
 
745
    for (i = 0; i < xf86NumScreens; i++) {
 
746
        for (j = 0; j < xf86Screens[i]->numFormats; j++) {
 
747
            for (k = 0; ; k++) {
 
748
                if (k >= numFormats) {
 
749
                    if (k >= MAXFORMATS)
 
750
                        FatalError("Too many pixmap formats!  Exiting\n");
 
751
                    formats[k] = xf86Screens[i]->formats[j];
 
752
                    numFormats++;
 
753
                    break;
 
754
                }
 
755
                if (formats[k].depth == xf86Screens[i]->formats[j].depth) {
 
756
                    if ((formats[k].bitsPerPixel ==
 
757
                         xf86Screens[i]->formats[j].bitsPerPixel) &&
 
758
                        (formats[k].scanlinePad ==
 
759
                         xf86Screens[i]->formats[j].scanlinePad))
 
760
                        break;
 
761
                    FatalError("Inconsistent pixmap format for depth %d."
 
762
                               "  Exiting\n", formats[k].depth);
 
763
                }
 
764
            }
 
765
        }
 
766
    }
 
767
    formatsDone = TRUE;
 
768
 
 
769
    if (xf86Info.vtno >= 0 ) {
 
770
#define VT_ATOM_NAME         "XFree86_VT"
 
771
      Atom VTAtom=-1;
 
772
      CARD32  *VT = NULL;
 
773
      int  ret;
 
774
 
 
775
      /* This memory needs to stay available until the screen has been
 
776
         initialized, and we can create the property for real.
 
777
      */
 
778
      if ( (VT = xalloc(sizeof(CARD32)))==NULL ) {
 
779
        FatalError("Unable to make VT property - out of memory. Exiting...\n");
 
780
      }
 
781
      *VT = xf86Info.vtno;
 
782
    
 
783
      VTAtom = MakeAtom(VT_ATOM_NAME, sizeof(VT_ATOM_NAME), TRUE);
 
784
 
 
785
      for (i = 0, ret = Success; i < xf86NumScreens && ret == Success; i++) {
 
786
        ret = xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex,
 
787
                                             VTAtom, XA_INTEGER, 32, 
 
788
                                             1, VT );
 
789
        if (ret != Success)
 
790
          xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING,
 
791
                     "Failed to register VT property\n");
 
792
      }
 
793
    }
 
794
 
 
795
    /* If a screen uses depth 24, show what the pixmap format is */
 
796
    for (i = 0; i < xf86NumScreens; i++) {
 
797
        if (xf86Screens[i]->depth == 24) {
 
798
            xf86Msg(pix24From, "Depth 24 pixmap format is %d bpp\n",
 
799
                    PIX24TOBPP(pix24));
 
800
            break;
 
801
        }
 
802
    }
 
803
 
 
804
#if BITMAP_SCANLINE_UNIT == 64
 
805
    /*
 
806
     * cfb24 doesn't currently work on architectures with a 64 bit
 
807
     * BITMAP_SCANLINE_UNIT, so check for 24 bit pixel size for pixmaps
 
808
     * or framebuffers.
 
809
     */
 
810
    {
 
811
        Bool usesCfb24 = FALSE;
 
812
 
 
813
        if (PIX24TOBPP(pix24) == 24)
 
814
            usesCfb24 = TRUE;
 
815
        for (i = 0; i < xf86NumScreens; i++)
 
816
            if (xf86Screens[i]->bitsPerPixel == 24)
 
817
                usesCfb24 = TRUE;
 
818
        if (usesCfb24) {
 
819
            FatalError("24-bit pixel size is not supported on systems with"
 
820
                        " 64-bit scanlines.\n");
 
821
        }
 
822
    }
 
823
#endif
 
824
 
 
825
#ifdef XKB
 
826
    xf86InitXkb();
 
827
#endif
 
828
    /* set up the proper access funcs */
 
829
    xf86PostPreInit();
 
830
 
 
831
    AddCallback(&ServerGrabCallback, xf86GrabServerCallback, NULL);
 
832
    
 
833
  } else {
 
834
    /*
 
835
     * serverGeneration != 1; some OSs have to do things here, too.
 
836
     */
 
837
    xf86OpenConsole();
 
838
 
 
839
#ifdef XF86PM
 
840
    /*
 
841
      should we reopen it here? We need to deal with an already opened
 
842
      device. We could leave this to the OS layer. For now we simply
 
843
      close it here
 
844
    */
 
845
    if (xf86OSPMClose)
 
846
        xf86OSPMClose();
 
847
    if ((xf86OSPMClose = xf86OSPMOpen()) != NULL)
 
848
        xf86MsgVerb(X_INFO, 3, "APM registered successfully\n");
 
849
#endif
 
850
 
 
851
    /* Make sure full I/O access is enabled */
 
852
    if (xorgHWAccess)
 
853
        xf86EnableIO();
 
854
  }
 
855
 
 
856
#if 0
 
857
  /*
 
858
   * Install signal handler for unexpected signals
 
859
   */
 
860
  xf86Info.caughtSignal=FALSE;
 
861
  if (!xf86Info.notrapSignals)
 
862
  {
 
863
     signal(SIGSEGV,xf86SigHandler);
 
864
     signal(SIGILL,xf86SigHandler);
 
865
#ifdef SIGEMT
 
866
     signal(SIGEMT,xf86SigHandler);
 
867
#endif
 
868
     signal(SIGFPE,xf86SigHandler);
 
869
#ifdef SIGBUS
 
870
     signal(SIGBUS,xf86SigHandler);
 
871
#endif
 
872
#ifdef SIGSYS
 
873
     signal(SIGSYS,xf86SigHandler);
 
874
#endif
 
875
#ifdef SIGXCPU
 
876
     signal(SIGXCPU,xf86SigHandler);
 
877
#endif
 
878
#ifdef SIGXFSZ
 
879
     signal(SIGXFSZ,xf86SigHandler);
 
880
#endif
 
881
  }
 
882
#endif
 
883
 
 
884
  /*
 
885
   * Use the previously collected parts to setup pScreenInfo
 
886
   */
 
887
 
 
888
  pScreenInfo->imageByteOrder = xf86Screens[0]->imageByteOrder;
 
889
  pScreenInfo->bitmapScanlinePad = xf86Screens[0]->bitmapScanlinePad;
 
890
  pScreenInfo->bitmapScanlineUnit = xf86Screens[0]->bitmapScanlineUnit;
 
891
  pScreenInfo->bitmapBitOrder = xf86Screens[0]->bitmapBitOrder;
 
892
  pScreenInfo->numPixmapFormats = numFormats;
 
893
  for (i = 0; i < numFormats; i++)
 
894
    pScreenInfo->formats[i] = formats[i];
 
895
 
 
896
  /* Make sure the server's VT is active */
 
897
    
 
898
  if (serverGeneration != 1) {
 
899
    xf86Resetting = TRUE;
 
900
    /* All screens are in the same state, so just check the first */
 
901
    if (!xf86Screens[0]->vtSema) {
 
902
#ifdef HAS_USL_VTS
 
903
      ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ);
 
904
#endif
 
905
      xf86AccessEnter();
 
906
      xf86EnterServerState(SETUP);
 
907
    } 
 
908
  }
 
909
#ifdef SCO325
 
910
  else {
 
911
    /*
 
912
     * Under SCO we must ack that we got the console at startup,
 
913
     * I think this is the safest way to assure it.
 
914
     */
 
915
    static int once = 1;
 
916
    if (once) {
 
917
      once = 0;
 
918
      if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
 
919
        xf86Msg(X_WARNING, "VT_ACKACQ failed");
 
920
    }
 
921
  }
 
922
#endif /* SCO325 */
 
923
 
 
924
  for (i = 0; i < xf86NumScreens; i++) {    
 
925
        xf86EnableAccess(xf86Screens[i]);
 
926
        /*
 
927
         * Almost everything uses these defaults, and many of those that
 
928
         * don't, will wrap them.
 
929
         */
 
930
        xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess;
 
931
        xf86Screens[i]->SetDGAMode = xf86SetDGAMode;
 
932
        xf86Screens[i]->DPMSSet = NULL;
 
933
        xf86Screens[i]->LoadPalette = NULL; 
 
934
        xf86Screens[i]->SetOverscan = NULL;
 
935
        xf86Screens[i]->DriverFunc = NULL;
 
936
        xf86Screens[i]->pScreen = NULL;
 
937
        scr_index = AddScreen(xf86Screens[i]->ScreenInit, argc, argv);
 
938
      if (scr_index == i) {
 
939
        /*
 
940
         * Hook in our ScrnInfoRec, and initialise some other pScreen
 
941
         * fields.
 
942
         */
 
943
        screenInfo.screens[scr_index]->devPrivates[xf86ScreenIndex].ptr
 
944
          = (pointer)xf86Screens[i];
 
945
        xf86Screens[i]->pScreen = screenInfo.screens[scr_index];
 
946
        /* The driver should set this, but make sure it is set anyway */
 
947
        xf86Screens[i]->vtSema = TRUE;
 
948
      } else {
 
949
        /* This shouldn't normally happen */
 
950
        FatalError("AddScreen/ScreenInit failed for driver %d\n", i);
 
951
      }
 
952
 
 
953
#ifdef DEBUG
 
954
      ErrorF("InitOutput - xf86Screens[%d]->pScreen = %p\n",
 
955
             i, xf86Screens[i]->pScreen );
 
956
      ErrorF("xf86Screens[%d]->pScreen->CreateWindow = %p\n",
 
957
             i, xf86Screens[i]->pScreen->CreateWindow );
 
958
#endif
 
959
 
 
960
      screenInfo.screens[scr_index]->devPrivates[xf86CreateRootWindowIndex].ptr
 
961
        = (void*)(xf86Screens[i]->pScreen->CreateWindow);
 
962
      xf86Screens[i]->pScreen->CreateWindow = xf86CreateRootWindow;
 
963
 
 
964
#ifdef RENDER
 
965
    if (PictureGetSubpixelOrder (xf86Screens[i]->pScreen) == SubPixelUnknown)
 
966
    {
 
967
        xf86MonPtr DDC = (xf86MonPtr)(xf86Screens[i]->monitor->DDC); 
 
968
        PictureSetSubpixelOrder (xf86Screens[i]->pScreen,
 
969
                                 DDC ?
 
970
                                 (DDC->features.input_type ?
 
971
                                  SubPixelHorizontalRGB : SubPixelNone) :
 
972
                                 SubPixelUnknown);
 
973
    }
 
974
#endif
 
975
#ifdef RANDR
 
976
    if (!xf86Info.disableRandR)
 
977
        xf86RandRInit (screenInfo.screens[scr_index]);
 
978
    xf86Msg(xf86Info.randRFrom, "RandR %s\n",
 
979
            xf86Info.disableRandR ? "disabled" : "enabled");
 
980
#endif
 
981
#ifdef NOT_USED
 
982
      /*
 
983
       * Here we have to let the driver getting access of the VT. Note that
 
984
       * this doesn't mean that the graphics board may access automatically
 
985
       * the monitor. If the monitor is shared this is done in xf86CrossScreen!
 
986
       */
 
987
      if (!xf86Info.sharedMonitor) (xf86Screens[i]->EnterLeaveMonitor)(ENTER);
 
988
#endif
 
989
  }
 
990
 
 
991
#ifdef XFree86LOADER
 
992
    if ((serverGeneration == 1) && LoaderCheckUnresolved(LD_RESOLV_IFDONE)) {
 
993
        /* For now, just a warning */
 
994
        xf86Msg(X_WARNING, "Some symbols could not be resolved!\n");
 
995
    }
 
996
#endif
 
997
 
 
998
  xf86PostScreenInit();
 
999
 
 
1000
  xf86InitOrigins();
 
1001
 
 
1002
  xf86Resetting = FALSE;
 
1003
  xf86Initialising = FALSE;
 
1004
 
 
1005
  RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA, xf86Wakeup,
 
1006
                                 NULL);
 
1007
}
 
1008
 
 
1009
 
 
1010
static InputDriverPtr
 
1011
MatchInput(IDevPtr pDev)
 
1012
{
 
1013
    int i;
 
1014
 
 
1015
    for (i = 0; i < xf86NumInputDrivers; i++) {
 
1016
        if (xf86InputDriverList[i] && xf86InputDriverList[i]->driverName &&
 
1017
            xf86NameCmp(pDev->driver, xf86InputDriverList[i]->driverName) == 0)
 
1018
            return xf86InputDriverList[i];
 
1019
    }
 
1020
    return NULL;
 
1021
}
 
1022
 
 
1023
 
 
1024
/*
 
1025
 * InitInput --
 
1026
 *      Initialize all supported input devices.
 
1027
 */
 
1028
 
 
1029
void
 
1030
InitInput(argc, argv)
 
1031
     int          argc;
 
1032
     char         **argv;
 
1033
{
 
1034
    IDevPtr pDev;
 
1035
    InputDriverPtr pDrv;
 
1036
    InputInfoPtr pInfo;
 
1037
    static InputInfoPtr coreKeyboard = NULL, corePointer = NULL;
 
1038
 
 
1039
    xf86Info.vtRequestsPending = FALSE;
 
1040
    xf86Info.inputPending = FALSE;
 
1041
#ifdef XTESTEXT1
 
1042
    xtest_command_key = KEY_Begin + MIN_KEYCODE;
 
1043
#endif /* XTESTEXT1 */
 
1044
 
 
1045
    if (serverGeneration == 1) {
 
1046
        /* Call the PreInit function for each input device instance. */
 
1047
        for (pDev = xf86ConfigLayout.inputs; pDev && pDev->identifier; pDev++) {
 
1048
#ifdef USE_DEPRECATED_KEYBOARD_DRIVER
 
1049
            /* XXX The keyboard driver is a special case for now. */
 
1050
            if (!xf86NameCmp(pDev->driver, "keyboard")) {
 
1051
                xf86MsgVerb(X_WARNING, 0, "*** WARNING the legacy keyboard driver \"keyboard\" is deprecated\n");
 
1052
                xf86MsgVerb(X_WARNING, 0, "*** and will be removed in the next release of the Xorg server.\n");
 
1053
                xf86MsgVerb(X_WARNING, 0, "*** Please consider using the the new \"kbd\" driver for \"%s\".\n",
 
1054
                        pDev->identifier);
 
1055
 
 
1056
                continue;
 
1057
            }
 
1058
#endif
 
1059
 
 
1060
            if ((pDrv = MatchInput(pDev)) == NULL) {
 
1061
                xf86Msg(X_ERROR, "No Input driver matching `%s'\n", pDev->driver);
 
1062
                /* XXX For now, just continue. */
 
1063
                continue;
 
1064
            }
 
1065
            if (!pDrv->PreInit) {
 
1066
                xf86MsgVerb(X_WARNING, 0,
 
1067
                    "Input driver `%s' has no PreInit function (ignoring)\n",
 
1068
                    pDrv->driverName);
 
1069
                continue;
 
1070
            }
 
1071
            pInfo = pDrv->PreInit(pDrv, pDev, 0);
 
1072
            if (!pInfo) {
 
1073
                xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n",
 
1074
                        pDev->identifier);
 
1075
                continue;
 
1076
            } else if (!(pInfo->flags & XI86_CONFIGURED)) {
 
1077
                xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n",
 
1078
                        pDev->identifier);
 
1079
                xf86DeleteInput(pInfo, 0);
 
1080
                continue;
 
1081
            }
 
1082
            if (pInfo->flags & XI86_CORE_KEYBOARD) {
 
1083
                if (coreKeyboard) {
 
1084
                    xf86Msg(X_ERROR,
 
1085
                      "Attempt to register more than one core keyboard (%s)\n",
 
1086
                      pInfo->name);
 
1087
                    pInfo->flags &= ~XI86_CORE_KEYBOARD;
 
1088
                } else {
 
1089
                    if (!(pInfo->flags & XI86_KEYBOARD_CAPABLE)) {
 
1090
                        /* XXX just a warning for now */
 
1091
                        xf86Msg(X_WARNING,
 
1092
                            "%s: does not have core keyboard capabilities\n",
 
1093
                            pInfo->name);
 
1094
                    }
 
1095
                    coreKeyboard = pInfo;
 
1096
                }
 
1097
            }
 
1098
            if (pInfo->flags & XI86_CORE_POINTER) {
 
1099
                if (corePointer) {
 
1100
                    xf86Msg(X_ERROR,
 
1101
                        "Attempt to register more than one core pointer (%s)\n",
 
1102
                        pInfo->name);
 
1103
                    pInfo->flags &= ~XI86_CORE_POINTER;
 
1104
                } else {
 
1105
                    if (!(pInfo->flags & XI86_POINTER_CAPABLE)) {
 
1106
                        /* XXX just a warning for now */
 
1107
                        xf86Msg(X_WARNING,
 
1108
                            "%s: does not have core pointer capabilities\n",
 
1109
                            pInfo->name);
 
1110
                    }
 
1111
                    corePointer = pInfo;
 
1112
                }
 
1113
            }
 
1114
        }
 
1115
        if (!corePointer) {
 
1116
            xf86Msg(X_WARNING, "No core pointer registered\n");
 
1117
            /* XXX register a dummy core pointer */
 
1118
        }
 
1119
#ifdef NEW_KBD
 
1120
        if (!coreKeyboard) {
 
1121
            xf86Msg(X_WARNING, "No core keyboard registered\n");
 
1122
            /* XXX register a dummy core keyboard */
 
1123
        }
 
1124
#endif
 
1125
    }
 
1126
 
 
1127
    /* Initialise all input devices. */
 
1128
    pInfo = xf86InputDevs;
 
1129
    while (pInfo) {
 
1130
        xf86ActivateDevice(pInfo);
 
1131
        pInfo = pInfo->next;
 
1132
    }
 
1133
 
 
1134
    if (coreKeyboard) {
 
1135
      xf86Info.pKeyboard = coreKeyboard->dev;
 
1136
      xf86Info.kbdEvents = NULL; /* to prevent the internal keybord driver usage*/
 
1137
    }
 
1138
    else {
 
1139
#ifdef USE_DEPRECATED_KEYBOARD_DRIVER
 
1140
      /* Only set this if we're allowing the old driver. */
 
1141
        if (xf86Info.kbdProc != NULL) 
 
1142
            xf86Info.pKeyboard = AddInputDevice(xf86Info.kbdProc, TRUE);
 
1143
#endif
 
1144
    }
 
1145
    if (corePointer)
 
1146
        xf86Info.pMouse = corePointer->dev;
 
1147
    if (xf86Info.pKeyboard)
 
1148
      RegisterKeyboardDevice(xf86Info.pKeyboard); 
 
1149
 
 
1150
  miRegisterPointerDevice(screenInfo.screens[0], xf86Info.pMouse);
 
1151
#ifdef XINPUT
 
1152
  xf86eqInit ((DevicePtr)xf86Info.pKeyboard, (DevicePtr)xf86Info.pMouse);
 
1153
#else
 
1154
  mieqInit ((DevicePtr)xf86Info.pKeyboard, (DevicePtr)xf86Info.pMouse);
 
1155
#endif
 
1156
}
 
1157
 
 
1158
#ifndef SET_STDERR_NONBLOCKING
 
1159
#define SET_STDERR_NONBLOCKING 1
 
1160
#endif
 
1161
 
 
1162
/*
 
1163
 * OsVendorInit --
 
1164
 *      OS/Vendor-specific initialisations.  Called from OsInit(), which
 
1165
 *      is called by dix before establishing the well known sockets.
 
1166
 */
 
1167
 
 
1168
void
 
1169
OsVendorInit()
 
1170
{
 
1171
  static Bool beenHere = FALSE;
 
1172
 
 
1173
  /* xf86WrapperInit() is called directly from OsInit() */
 
1174
#ifdef SIGCHLD
 
1175
  signal(SIGCHLD, SIG_DFL);     /* Need to wait for child processes */
 
1176
#endif
 
1177
  OsDelayInitColors = TRUE;
 
1178
#ifdef XFree86LOADER
 
1179
  loadableFonts = TRUE;
 
1180
#endif
 
1181
 
 
1182
  if (!beenHere)
 
1183
    xf86LogInit();
 
1184
 
 
1185
#if SET_STDERR_NONBLOCKING
 
1186
        /* Set stderr to non-blocking. */
 
1187
#ifndef O_NONBLOCK
 
1188
#if defined(FNDELAY)
 
1189
#define O_NONBLOCK FNDELAY
 
1190
#elif defined(O_NDELAY)
 
1191
#define O_NONBLOCK O_NDELAY
 
1192
#endif
 
1193
#endif
 
1194
 
 
1195
#ifdef O_NONBLOCK
 
1196
  if (!beenHere) {
 
1197
#if !defined(__EMX__)
 
1198
    if (geteuid() == 0 && getuid() != geteuid())
 
1199
#endif
 
1200
    {
 
1201
      int status;
 
1202
 
 
1203
      status = fcntl(fileno(stderr), F_GETFL, 0);
 
1204
      if (status != -1) {
 
1205
        fcntl(fileno(stderr), F_SETFL, status | O_NONBLOCK);
 
1206
      }
 
1207
    }
 
1208
  }
 
1209
#endif
 
1210
#endif
 
1211
 
 
1212
  beenHere = TRUE;
 
1213
}
 
1214
 
 
1215
/*
 
1216
 * ddxGiveUp --
 
1217
 *      Device dependent cleanup. Called by by dix before normal server death.
 
1218
 *      For SYSV386 we must switch the terminal back to normal mode. No error-
 
1219
 *      checking here, since there should be restored as much as possible.
 
1220
 */
 
1221
 
 
1222
void
 
1223
ddxGiveUp()
 
1224
{
 
1225
    int i;
 
1226
 
 
1227
#ifdef XF86PM
 
1228
    if (xf86OSPMClose)
 
1229
        xf86OSPMClose();
 
1230
    xf86OSPMClose = NULL;
 
1231
#endif
 
1232
 
 
1233
    xf86AccessLeaveState();
 
1234
 
 
1235
    for (i = 0; i < xf86NumScreens; i++) {
 
1236
        /*
 
1237
         * zero all access functions to
 
1238
         * trap calls when switched away.
 
1239
         */
 
1240
        xf86Screens[i]->vtSema = FALSE;
 
1241
        xf86Screens[i]->access = NULL;
 
1242
        xf86Screens[i]->busAccess = NULL;
 
1243
    }
 
1244
 
 
1245
#ifdef USE_XF86_SERVERLOCK
 
1246
    xf86UnlockServer();
 
1247
#endif
 
1248
#ifdef XFreeXDGA
 
1249
    DGAShutdown();
 
1250
#endif
 
1251
 
 
1252
    xf86CloseConsole();
 
1253
 
 
1254
    xf86CloseLog();
 
1255
 
 
1256
    /* If an unexpected signal was caught, dump a core for debugging */
 
1257
    if (xf86Info.caughtSignal)
 
1258
        abort();
 
1259
}
 
1260
 
 
1261
 
 
1262
 
 
1263
/*
 
1264
 * AbortDDX --
 
1265
 *      DDX - specific abort routine.  Called by AbortServer(). The attempt is
 
1266
 *      made to restore all original setting of the displays. Also all devices
 
1267
 *      are closed.
 
1268
 */
 
1269
 
 
1270
void
 
1271
AbortDDX()
 
1272
{
 
1273
  int i;
 
1274
 
 
1275
  /*
 
1276
   * try to deinitialize all input devices
 
1277
   */
 
1278
  if (xf86Info.kbdProc && xf86Info.pKeyboard)
 
1279
    (xf86Info.kbdProc)(xf86Info.pKeyboard, DEVICE_CLOSE);
 
1280
 
 
1281
  /*
 
1282
   * try to restore the original video state
 
1283
   */
 
1284
#ifdef HAS_USL_VTS
 
1285
  /* Need the sleep when starting X from within another X session */
 
1286
  sleep(1);
 
1287
#endif
 
1288
#ifdef DPMSExtension /* Turn screens back on */
 
1289
  if (DPMSPowerLevel != DPMSModeOn)
 
1290
      DPMSSet(DPMSModeOn);
 
1291
#endif
 
1292
  if (xf86Screens) {
 
1293
      if (xf86Screens[0]->vtSema)
 
1294
          xf86EnterServerState(SETUP);
 
1295
      for (i = 0; i < xf86NumScreens; i++)
 
1296
          if (xf86Screens[i]->vtSema) {
 
1297
              /*
 
1298
               * if we are aborting before ScreenInit() has finished
 
1299
               * we might not have been wrapped yet. Therefore enable
 
1300
               * screen explicitely.
 
1301
               */
 
1302
              xf86EnableAccess(xf86Screens[i]);
 
1303
              (xf86Screens[i]->LeaveVT)(i, 0);
 
1304
          }
 
1305
  }
 
1306
  
 
1307
  xf86AccessLeave();
 
1308
  
 
1309
  /*
 
1310
   * This is needed for an abnormal server exit, since the normal exit stuff
 
1311
   * MUST also be performed (i.e. the vt must be left in a defined state)
 
1312
   */
 
1313
  ddxGiveUp();
 
1314
}
 
1315
 
 
1316
void
 
1317
OsVendorFatalError()
 
1318
{
 
1319
#ifdef VENDORSUPPORT
 
1320
    ErrorF("\nPlease refer to your Operating System Vendor support pages\n"
 
1321
           "at %s for support on this crash.\n",VENDORSUPPORT);
 
1322
#else
 
1323
    ErrorF("\nPlease consult the "XVENDORNAME" support \n"
 
1324
           "\t at "__VENDORDWEBSUPPORT__"\n for help. \n");
 
1325
#endif
 
1326
    if (xf86LogFile && xf86LogFileWasOpened)
 
1327
        ErrorF("Please also check the log file at \"%s\" for additional "
 
1328
              "information.\n", xf86LogFile);
 
1329
    ErrorF("\n");
 
1330
}
 
1331
 
 
1332
int
 
1333
xf86SetVerbosity(int verb)
 
1334
{
 
1335
    int save = xf86Verbose;
 
1336
 
 
1337
    xf86Verbose = verb;
 
1338
    LogSetParameter(XLOG_VERBOSITY, verb);
 
1339
    return save;
 
1340
}
 
1341
 
 
1342
int
 
1343
xf86SetLogVerbosity(int verb)
 
1344
{
 
1345
    int save = xf86LogVerbose;
 
1346
 
 
1347
    xf86LogVerbose = verb;
 
1348
    LogSetParameter(XLOG_FILE_VERBOSITY, verb);
 
1349
    return save;
 
1350
}
 
1351
 
 
1352
/*
 
1353
 * ddxProcessArgument --
 
1354
 *      Process device-dependent command line args. Returns 0 if argument is
 
1355
 *      not device dependent, otherwise Count of number of elements of argv
 
1356
 *      that are part of a device dependent commandline option.
 
1357
 *
 
1358
 */
 
1359
 
 
1360
 
 
1361
 
 
1362
/* ARGSUSED */
 
1363
int
 
1364
ddxProcessArgument(int argc, char **argv, int i)
 
1365
{
 
1366
  /*
 
1367
   * Note: can't use xalloc/xfree here because OsInit() hasn't been called
 
1368
   * yet.  Use malloc/free instead.
 
1369
   */
 
1370
 
 
1371
#define CHECK_FOR_REQUIRED_ARGUMENT() \
 
1372
    if (((i + 1) >= argc) || (!argv[i + 1])) {                          \
 
1373
      ErrorF("Required argument to %s not specified\n", argv[i]);       \
 
1374
      UseMsg();                                                         \
 
1375
      FatalError("Required argument to %s not specified\n", argv[i]);   \
 
1376
    }
 
1377
  
 
1378
  /* First the options that are only allowed for root */
 
1379
  if (getuid() == 0 || geteuid != 0)
 
1380
  {
 
1381
    if (!strcmp(argv[i], "-modulepath"))
 
1382
    {
 
1383
      char *mp;
 
1384
      CHECK_FOR_REQUIRED_ARGUMENT();
 
1385
      mp = malloc(strlen(argv[i + 1]) + 1);
 
1386
      if (!mp)
 
1387
        FatalError("Can't allocate memory for ModulePath\n");
 
1388
      strcpy(mp, argv[i + 1]);
 
1389
      xf86ModulePath = mp;
 
1390
      xf86ModPathFrom = X_CMDLINE;
 
1391
      return 2;
 
1392
    }
 
1393
    else if (!strcmp(argv[i], "-logfile"))
 
1394
    {
 
1395
      char *lf;
 
1396
      CHECK_FOR_REQUIRED_ARGUMENT();
 
1397
      lf = malloc(strlen(argv[i + 1]) + 1);
 
1398
      if (!lf)
 
1399
        FatalError("Can't allocate memory for LogFile\n");
 
1400
      strcpy(lf, argv[i + 1]);
 
1401
      xf86LogFile = lf;
 
1402
      xf86LogFileFrom = X_CMDLINE;
 
1403
      return 2;
 
1404
    }
 
1405
  } else if (!strcmp(argv[i], "-modulepath") || !strcmp(argv[i], "-logfile")) {
 
1406
    FatalError("The '%s' option can only be used by root.\n", argv[i]);
 
1407
  }
 
1408
  if (!strcmp(argv[i], "-config") || !strcmp(argv[i], "-xf86config"))
 
1409
  {
 
1410
    CHECK_FOR_REQUIRED_ARGUMENT();
 
1411
    if (getuid() != 0 && !xf86PathIsSafe(argv[i + 1])) {
 
1412
      FatalError("\nInvalid argument for %s\n"
 
1413
          "\tFor non-root users, the file specified with %s must be\n"
 
1414
          "\ta relative path and must not contain any \"..\" elements.\n"
 
1415
          "\tUsing default "__XCONFIGFILE__" search path.\n\n",
 
1416
          argv[i], argv[i]);
 
1417
    }
 
1418
    xf86ConfigFile = argv[i + 1];
 
1419
    return 2;
 
1420
  }
 
1421
  if (!strcmp(argv[i],"-showunresolved"))
 
1422
  {
 
1423
    xf86ShowUnresolved = TRUE;
 
1424
    return 1;
 
1425
  }
 
1426
  if (!strcmp(argv[i],"-probeonly"))
 
1427
  {
 
1428
    xf86ProbeOnly = TRUE;
 
1429
    return 1;
 
1430
  }
 
1431
  if (!strcmp(argv[i],"-flipPixels"))
 
1432
  {
 
1433
    xf86FlipPixels = TRUE;
 
1434
    return 1;
 
1435
  }
 
1436
#ifdef XF86VIDMODE
 
1437
  if (!strcmp(argv[i],"-disableVidMode"))
 
1438
  {
 
1439
    xf86VidModeDisabled = TRUE;
 
1440
    return 1;
 
1441
  }
 
1442
  if (!strcmp(argv[i],"-allowNonLocalXvidtune"))
 
1443
  {
 
1444
    xf86VidModeAllowNonLocal = TRUE;
 
1445
    return 1;
 
1446
  }
 
1447
#endif
 
1448
#ifdef XF86MISC
 
1449
  if (!strcmp(argv[i],"-disableModInDev"))
 
1450
  {
 
1451
    xf86MiscModInDevDisabled = TRUE;
 
1452
    return 1;
 
1453
  }
 
1454
  if (!strcmp(argv[i],"-allowNonLocalModInDev"))
 
1455
  {
 
1456
    xf86MiscModInDevAllowNonLocal = TRUE;
 
1457
    return 1;
 
1458
  }
 
1459
#endif
 
1460
  if (!strcmp(argv[i],"-allowMouseOpenFail"))
 
1461
  {
 
1462
    xf86AllowMouseOpenFail = TRUE;
 
1463
    return 1;
 
1464
  }
 
1465
  if (!strcmp(argv[i],"-bestRefresh"))
 
1466
  {
 
1467
    xf86BestRefresh = TRUE;
 
1468
    return 1;
 
1469
  }
 
1470
  if (!strcmp(argv[i],"-ignoreABI"))
 
1471
  {
 
1472
#ifdef XFree86LOADER
 
1473
    LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL);
 
1474
#endif
 
1475
    return 1;
 
1476
  }
 
1477
  if (!strcmp(argv[i],"-verbose"))
 
1478
  {
 
1479
    if (++i < argc && argv[i])
 
1480
    {
 
1481
      char *end;
 
1482
      long val;
 
1483
      val = strtol(argv[i], &end, 0);
 
1484
      if (*end == '\0')
 
1485
      {
 
1486
        xf86SetVerbosity(val);
 
1487
        return 2;
 
1488
      }
 
1489
    }
 
1490
    xf86SetVerbosity(++xf86Verbose);
 
1491
    return 1;
 
1492
  }
 
1493
  if (!strcmp(argv[i],"-logverbose"))
 
1494
  {
 
1495
    if (++i < argc && argv[i])
 
1496
    {
 
1497
      char *end;
 
1498
      long val;
 
1499
      val = strtol(argv[i], &end, 0);
 
1500
      if (*end == '\0')
 
1501
      {
 
1502
        xf86SetLogVerbosity(val);
 
1503
        return 2;
 
1504
      }
 
1505
    }
 
1506
    xf86SetLogVerbosity(++xf86LogVerbose);
 
1507
    return 1;
 
1508
  }
 
1509
  if (!strcmp(argv[i],"-quiet"))
 
1510
  {
 
1511
    xf86SetVerbosity(0);
 
1512
    return 1;
 
1513
  }
 
1514
  if (!strcmp(argv[i],"-showconfig") || !strcmp(argv[i],"-version"))
 
1515
  {
 
1516
    xf86PrintBanner();
 
1517
    exit(0);
 
1518
  }
 
1519
  /* Notice the -fp flag, but allow it to pass to the dix layer */
 
1520
  if (!strcmp(argv[i], "-fp"))
 
1521
  {
 
1522
    xf86fpFlag = TRUE;
 
1523
    return 0;
 
1524
  }
 
1525
  /* Notice the -co flag, but allow it to pass to the dix layer */
 
1526
  if (!strcmp(argv[i], "-co"))
 
1527
  {
 
1528
    xf86coFlag = TRUE;
 
1529
    return 0;
 
1530
  }
 
1531
  /* Notice the -bs flag, but allow it to pass to the dix layer */
 
1532
  if (!strcmp(argv[i], "-bs"))
 
1533
  {
 
1534
    xf86bsDisableFlag = TRUE;
 
1535
    return 0;
 
1536
  }
 
1537
  /* Notice the +bs flag, but allow it to pass to the dix layer */
 
1538
  if (!strcmp(argv[i], "+bs"))
 
1539
  {
 
1540
    xf86bsEnableFlag = TRUE;
 
1541
    return 0;
 
1542
  }
 
1543
  /* Notice the -s flag, but allow it to pass to the dix layer */
 
1544
  if (!strcmp(argv[i], "-s"))
 
1545
  {
 
1546
    xf86sFlag = TRUE;
 
1547
    return 0;
 
1548
  }
 
1549
  if (!strcmp(argv[i], "-bpp"))
 
1550
  {
 
1551
    ErrorF("The -bpp option is no longer supported.\n"
 
1552
        "\tUse -depth to set the color depth, and use -fbbpp if you really\n"
 
1553
        "\tneed to force a non-default framebuffer (hardware) pixel format.\n");
 
1554
    if (++i >= argc)
 
1555
      return 1;
 
1556
    return 2;
 
1557
  }
 
1558
  if (!strcmp(argv[i], "-pixmap24"))
 
1559
  {
 
1560
    xf86Pix24 = Pix24Use24;
 
1561
    return 1;
 
1562
  }
 
1563
  if (!strcmp(argv[i], "-pixmap32"))
 
1564
  {
 
1565
    xf86Pix24 = Pix24Use32;
 
1566
    return 1;
 
1567
  }
 
1568
  if (!strcmp(argv[i], "-fbbpp"))
 
1569
  {
 
1570
    int bpp;
 
1571
    CHECK_FOR_REQUIRED_ARGUMENT();
 
1572
    if (sscanf(argv[++i], "%d", &bpp) == 1)
 
1573
    {
 
1574
      xf86FbBpp = bpp;
 
1575
      return 2;
 
1576
    }
 
1577
    else
 
1578
    {
 
1579
      ErrorF("Invalid fbbpp\n");
 
1580
      return 0;
 
1581
    }
 
1582
  }
 
1583
  if (!strcmp(argv[i], "-depth"))
 
1584
  {
 
1585
    int depth;
 
1586
    CHECK_FOR_REQUIRED_ARGUMENT();
 
1587
    if (sscanf(argv[++i], "%d", &depth) == 1)
 
1588
    {
 
1589
      xf86Depth = depth;
 
1590
      return 2;
 
1591
    }
 
1592
    else
 
1593
    {
 
1594
      ErrorF("Invalid depth\n");
 
1595
      return 0;
 
1596
    }
 
1597
  }
 
1598
  if (!strcmp(argv[i], "-weight"))
 
1599
  {
 
1600
    int red, green, blue;
 
1601
    CHECK_FOR_REQUIRED_ARGUMENT();
 
1602
    if (sscanf(argv[++i], "%1d%1d%1d", &red, &green, &blue) == 3)
 
1603
    {
 
1604
      xf86Weight.red = red;
 
1605
      xf86Weight.green = green;
 
1606
      xf86Weight.blue = blue;
 
1607
      return 2;
 
1608
    }
 
1609
    else
 
1610
    {
 
1611
      ErrorF("Invalid weighting\n");
 
1612
      return 0;
 
1613
    }
 
1614
  }
 
1615
  if (!strcmp(argv[i], "-gamma")  || !strcmp(argv[i], "-rgamma") || 
 
1616
      !strcmp(argv[i], "-ggamma") || !strcmp(argv[i], "-bgamma"))
 
1617
  {
 
1618
    double gamma;
 
1619
    CHECK_FOR_REQUIRED_ARGUMENT();    
 
1620
    if (sscanf(argv[++i], "%lf", &gamma) == 1) {
 
1621
       if (gamma < GAMMA_MIN || gamma > GAMMA_MAX) {
 
1622
          ErrorF("gamma out of range, only  %.2f <= gamma_value <= %.1f"
 
1623
                 " is valid\n", GAMMA_MIN, GAMMA_MAX);
 
1624
          return 0;
 
1625
       }
 
1626
       if (!strcmp(argv[i-1], "-gamma"))
 
1627
          xf86Gamma.red = xf86Gamma.green = xf86Gamma.blue = gamma;
 
1628
       else if (!strcmp(argv[i-1], "-rgamma")) xf86Gamma.red = gamma;
 
1629
       else if (!strcmp(argv[i-1], "-ggamma")) xf86Gamma.green = gamma;
 
1630
       else if (!strcmp(argv[i-1], "-bgamma")) xf86Gamma.blue = gamma;
 
1631
       return 2;
 
1632
    }
 
1633
  }
 
1634
  if (!strcmp(argv[i], "-layout"))
 
1635
  {
 
1636
    CHECK_FOR_REQUIRED_ARGUMENT();
 
1637
    xf86LayoutName = argv[++i];
 
1638
    return 2;
 
1639
  }
 
1640
  if (!strcmp(argv[i], "-screen"))
 
1641
  {
 
1642
    CHECK_FOR_REQUIRED_ARGUMENT();
 
1643
    xf86ScreenName = argv[++i];
 
1644
    return 2;
 
1645
  }
 
1646
  if (!strcmp(argv[i], "-pointer"))
 
1647
  {
 
1648
    CHECK_FOR_REQUIRED_ARGUMENT();
 
1649
    xf86PointerName = argv[++i];
 
1650
    return 2;
 
1651
  }
 
1652
  if (!strcmp(argv[i], "-keyboard"))
 
1653
  {
 
1654
    CHECK_FOR_REQUIRED_ARGUMENT();    
 
1655
    xf86KeyboardName = argv[++i];
 
1656
    return 2;
 
1657
  }
 
1658
  if (!strcmp(argv[i], "-nosilk"))
 
1659
  {
 
1660
    xf86silkenMouseDisableFlag = TRUE;
 
1661
    return 1;
 
1662
  }
 
1663
  if (!strcmp(argv[i], "-noacpi"))
 
1664
  {
 
1665
    xf86acpiDisableFlag = TRUE;
 
1666
    return 1;
 
1667
  }
 
1668
  if (!strcmp(argv[i], "-scanpci"))
 
1669
  {
 
1670
    DoScanPci(argc, argv, i);
 
1671
  }
 
1672
  if (!strcmp(argv[i], "-probe"))
 
1673
  {
 
1674
    xf86DoProbe = TRUE;
 
1675
#if 0
 
1676
    DoProbe(argc, argv, i);
 
1677
#endif
 
1678
    return 1;
 
1679
  }
 
1680
  if (!strcmp(argv[i], "-configure"))
 
1681
  {
 
1682
    if (getuid() != 0 && geteuid == 0) {
 
1683
        ErrorF("The '-configure' option can only be used by root.\n");
 
1684
        exit(1);
 
1685
    }
 
1686
    xf86DoConfigure = TRUE;
 
1687
    xf86AllowMouseOpenFail = TRUE;
 
1688
    return 1;
 
1689
  }
 
1690
  if (!strcmp(argv[i], "-isolateDevice"))
 
1691
  {
 
1692
    int bus, device, func;
 
1693
    CHECK_FOR_REQUIRED_ARGUMENT();
 
1694
    if (strncmp(argv[++i], "PCI:", 4)) {
 
1695
       FatalError("Bus types other than PCI not yet isolable\n");
 
1696
    }
 
1697
    if (sscanf(argv[i], "PCI:%d:%d:%d", &bus, &device, &func) == 3) {
 
1698
       xf86IsolateDevice.bus = bus;
 
1699
       xf86IsolateDevice.device = device;
 
1700
       xf86IsolateDevice.func = func;
 
1701
       return 2;
 
1702
    } else {
 
1703
       FatalError("Invalid isolated device specification\n");
 
1704
    }
 
1705
  }
 
1706
  /* OS-specific processing */
 
1707
  return xf86ProcessArgument(argc, argv, i);
 
1708
}
 
1709
 
 
1710
/* ddxInitGlobals - called by |InitGlobals| from os/util.c */
 
1711
void ddxInitGlobals(void)
 
1712
{
 
1713
}
 
1714
 
 
1715
/*
 
1716
 * ddxUseMsg --
 
1717
 *      Print out correct use of device dependent commandline options.
 
1718
 *      Maybe the user now knows what really to do ...
 
1719
 */
 
1720
 
 
1721
void
 
1722
ddxUseMsg()
 
1723
{
 
1724
  ErrorF("\n");
 
1725
  ErrorF("\n");
 
1726
  ErrorF("Device Dependent Usage\n");
 
1727
  if (getuid() == 0 || geteuid() != 0)
 
1728
  {
 
1729
    ErrorF("-modulepath paths      specify the module search path\n");
 
1730
    ErrorF("-logfile file          specify a log file name\n");
 
1731
    ErrorF("-configure             probe for devices and write an "__XCONFIGFILE__"\n");
 
1732
  }
 
1733
  ErrorF("-config file           specify a configuration file, relative to the\n");
 
1734
  ErrorF("                       "__XCONFIGFILE__" search path, only root can use absolute\n");
 
1735
  ErrorF("-probeonly             probe for devices, then exit\n");
 
1736
  ErrorF("-scanpci               execute the scanpci module and exit\n");
 
1737
  ErrorF("-verbose [n]           verbose startup messages\n");
 
1738
  ErrorF("-logverbose [n]        verbose log messages\n");
 
1739
  ErrorF("-quiet                 minimal startup messages\n");
 
1740
  ErrorF("-pixmap24              use 24bpp pixmaps for depth 24\n");
 
1741
  ErrorF("-pixmap32              use 32bpp pixmaps for depth 24\n");
 
1742
  ErrorF("-fbbpp n               set bpp for the framebuffer. Default: 8\n");
 
1743
  ErrorF("-depth n               set colour depth. Default: 8\n");
 
1744
  ErrorF("-gamma f               set gamma value (0.1 < f < 10.0) Default: 1.0\n");
 
1745
  ErrorF("-rgamma f              set gamma value for red phase\n");
 
1746
  ErrorF("-ggamma f              set gamma value for green phase\n");
 
1747
  ErrorF("-bgamma f              set gamma value for blue phase\n");
 
1748
  ErrorF("-weight nnn            set RGB weighting at 16 bpp.  Default: 565\n");
 
1749
  ErrorF("-layout name           specify the ServerLayout section name\n");
 
1750
  ErrorF("-screen name           specify the Screen section name\n");
 
1751
  ErrorF("-keyboard name         specify the core keyboard InputDevice name\n");
 
1752
  ErrorF("-pointer name          specify the core pointer InputDevice name\n");
 
1753
  ErrorF("-nosilk                disable Silken Mouse\n");
 
1754
  ErrorF("-flipPixels            swap default black/white Pixel values\n");
 
1755
#ifdef XF86VIDMODE
 
1756
  ErrorF("-disableVidMode        disable mode adjustments with xvidtune\n");
 
1757
  ErrorF("-allowNonLocalXvidtune allow xvidtune to be run as a non-local client\n");
 
1758
#endif
 
1759
#ifdef XF86MISC
 
1760
  ErrorF("-disableModInDev       disable dynamic modification of input device settings\n");
 
1761
  ErrorF("-allowNonLocalModInDev allow changes to keyboard and mouse settings\n");
 
1762
  ErrorF("                       from non-local clients\n");
 
1763
  ErrorF("-allowMouseOpenFail    start server even if the mouse can't be initialized\n");
 
1764
#endif
 
1765
  ErrorF("-bestRefresh           choose modes with the best refresh rate\n");
 
1766
  ErrorF("-ignoreABI             make module ABI mismatches non-fatal\n");
 
1767
  ErrorF("-isolateDevice bus_id  restrict device resets to bus_id (PCI only)\n");
 
1768
  ErrorF("-version               show the server version\n");
 
1769
  /* OS-specific usage */
 
1770
  xf86UseMsg();
 
1771
  ErrorF("\n");
 
1772
}
 
1773
 
 
1774
 
 
1775
#ifndef OSNAME
 
1776
#define OSNAME " unknown"
 
1777
#endif
 
1778
#ifndef OSVENDOR
 
1779
#define OSVENDOR ""
 
1780
#endif
 
1781
#ifndef PRE_RELEASE
 
1782
#define PRE_RELEASE XORG_VERSION_SNAP
 
1783
#endif
 
1784
 
 
1785
static void
 
1786
xf86PrintBanner()
 
1787
{
 
1788
#if PRE_RELEASE
 
1789
  ErrorF("\n"
 
1790
    "This is a pre-release version of the X server from " XVENDORNAME ".\n"
 
1791
    "It is not supported in any way.\n"
 
1792
    "Bugs may be filed in the bugzilla at http://bugs.freedesktop.org/.\n"
 
1793
    "Select the \"xorg\" product for bugs you find in this release.\n"
 
1794
    "Before reporting bugs in pre-release versions please check the\n"
 
1795
    "latest version in the X.Org Foundation CVS repository.\n"
 
1796
    "See http://wiki.x.org/wiki/CvsPage for CVS access instructions.\n");
 
1797
#endif
 
1798
  ErrorF("\nX Window System Version %d.%d.%d",
 
1799
         XORG_VERSION_MAJOR,
 
1800
         XORG_VERSION_MINOR,
 
1801
         XORG_VERSION_PATCH);
 
1802
#if XORG_VERSION_SNAP > 0
 
1803
  ErrorF(".%d", XORG_VERSION_SNAP);
 
1804
#endif
 
1805
 
 
1806
#if XORG_VERSION_SNAP >= 900
 
1807
  /* When the minor number is 99, that signifies that the we are making
 
1808
   * a release candidate for a major version.  (X.0.0)
 
1809
   * When the patch number is 99, that signifies that the we are making
 
1810
   * a release candidate for a minor version.  (X.Y.0)
 
1811
   * When the patch number is < 99, then we are making a release
 
1812
   * candidate for the next point release.  (X.Y.Z)
 
1813
   */
 
1814
#if XORG_VERSION_MINOR >= 99
 
1815
  ErrorF(" (%d.0.0 RC %d)", XORG_VERSION_MAJOR+1, XORG_VERSION_SNAP - 900);
 
1816
#elif XORG_VERSION_PATCH == 99
 
1817
  ErrorF(" (%d.%d.0 RC %d)", XORG_VERSION_MAJOR, XORG_VERSION_MINOR + 1,
 
1818
                                XORG_VERSION_SNAP - 900);
 
1819
#else
 
1820
  ErrorF(" (%d.%d.%d RC %d)", XORG_VERSION_MAJOR, XORG_VERSION_MINOR,
 
1821
                         XORG_VERSION_PATCH + 1, XORG_VERSION_SNAP - 900);
 
1822
#endif
 
1823
#endif
 
1824
 
 
1825
#ifdef XORG_CUSTOM_VERSION
 
1826
  ErrorF(" (%s)", XORG_CUSTOM_VERSION);
 
1827
#endif
 
1828
#ifndef XORG_DATE
 
1829
#define XORG_DATE XF86_DATE
 
1830
#endif
 
1831
  ErrorF("\nRelease Date: %s\n", XORG_DATE);
 
1832
  ErrorF("X Protocol Version %d, Revision %d, %s\n",
 
1833
         X_PROTOCOL, X_PROTOCOL_REVISION, XORG_RELEASE );
 
1834
  ErrorF("Build Operating System:%s%s\n", OSNAME, OSVENDOR);
 
1835
#ifdef HAS_UTSNAME
 
1836
  {
 
1837
    struct utsname name;
 
1838
 
 
1839
    /* Linux & BSD state that 0 is success, SysV (including Solaris, HP-UX,
 
1840
       and Irix) and Single Unix Spec 3 just say that non-negative is success.
 
1841
       All agree that failure is represented by a negative number.
 
1842
     */
 
1843
    if (uname(&name) >= 0) {
 
1844
      ErrorF("Current Operating System: %s %s %s %s %s\n",
 
1845
        name.sysname, name.nodename, name.release, name.version, name.machine);
 
1846
    }
 
1847
  }
 
1848
#endif
 
1849
#if defined(BUILD_DATE) && (BUILD_DATE > 19000000)
 
1850
  {
 
1851
    struct tm t;
 
1852
    char buf[100];
 
1853
 
 
1854
    bzero(&t, sizeof(t));
 
1855
    bzero(buf, sizeof(buf));
 
1856
    t.tm_mday = BUILD_DATE % 100;
 
1857
    t.tm_mon = (BUILD_DATE / 100) % 100 - 1;
 
1858
    t.tm_year = BUILD_DATE / 10000 - 1900;
 
1859
    if (strftime(buf, sizeof(buf), "%d %B %Y", &t))
 
1860
       ErrorF("Build Date: %s\n", buf);
 
1861
  }
 
1862
#endif
 
1863
#if defined(CLOG_DATE) && (CLOG_DATE > 19000000)
 
1864
  {
 
1865
    struct tm t;
 
1866
    char buf[100];
 
1867
 
 
1868
    bzero(&t, sizeof(t));
 
1869
    bzero(buf, sizeof(buf));
 
1870
    t.tm_mday = CLOG_DATE % 100;
 
1871
    t.tm_mon = (CLOG_DATE / 100) % 100 - 1;
 
1872
    t.tm_year = CLOG_DATE / 10000 - 1900;
 
1873
    if (strftime(buf, sizeof(buf), "%d %B %Y", &t))
 
1874
       ErrorF("Changelog Date: %s\n", buf);
 
1875
  }
 
1876
#endif
 
1877
#if defined(BUILDERSTRING)
 
1878
  ErrorF("%s \n",BUILDERSTRING);
 
1879
#endif
 
1880
  ErrorF("\tBefore reporting problems, check "__VENDORDWEBSUPPORT__"\n"
 
1881
         "\tto make sure that you have the latest version.\n");
 
1882
#ifdef XFree86LOADER
 
1883
  ErrorF("Module Loader present\n");
 
1884
#endif
 
1885
}
 
1886
 
 
1887
static void
 
1888
xf86PrintMarkers()
 
1889
{
 
1890
  LogPrintMarkers();
 
1891
}
 
1892
 
 
1893
static void
 
1894
xf86RunVtInit(void)
 
1895
{
 
1896
    int i;
 
1897
 
 
1898
    /*
 
1899
     * If VTInit was set, run that program with consoleFd as stdin and stdout
 
1900
     */
 
1901
 
 
1902
    if (xf86Info.vtinit) {
 
1903
      switch(fork()) {
 
1904
      case -1:
 
1905
          FatalError("xf86RunVtInit: fork failed (%s)\n", strerror(errno));
 
1906
          break;
 
1907
      case 0:  /* child */
 
1908
          setuid(getuid());
 
1909
          /* set stdin, stdout to the consoleFd */
 
1910
          for (i = 0; i < 2; i++) {
 
1911
            if (xf86Info.consoleFd != i) {
 
1912
              close(i);
 
1913
              dup(xf86Info.consoleFd);
 
1914
            }
 
1915
          }
 
1916
          execl("/bin/sh", "sh", "-c", xf86Info.vtinit, (void *)NULL);
 
1917
          xf86Msg(X_WARNING, "exec of /bin/sh failed for VTInit (%s)\n",
 
1918
                 strerror(errno));
 
1919
          exit(255);
 
1920
          break;
 
1921
      default:  /* parent */
 
1922
          wait(NULL);
 
1923
      }
 
1924
    }
 
1925
}
 
1926
 
 
1927
#ifdef XFree86LOADER
 
1928
/*
 
1929
 * xf86LoadModules iterates over a list that is being passed in.
 
1930
 */             
 
1931
Bool
 
1932
xf86LoadModules(char **list, pointer *optlist)
 
1933
{
 
1934
    int errmaj, errmin;
 
1935
    pointer opt;
 
1936
    int i;
 
1937
    char *name;
 
1938
    Bool failed = FALSE;
 
1939
 
 
1940
    if (!list)
 
1941
        return TRUE;
 
1942
 
 
1943
    for (i = 0; list[i] != NULL; i++) {
 
1944
 
 
1945
#ifndef NORMALISE_MODULE_NAME
 
1946
        name = xstrdup(list[i]);
 
1947
#else
 
1948
        /* Normalise the module name */
 
1949
        name = xf86NormalizeName(list[i]);
 
1950
#endif
 
1951
 
 
1952
        /* Skip empty names */
 
1953
        if (name == NULL || *name == '\0')
 
1954
            continue;
 
1955
 
 
1956
        if (optlist)
 
1957
            opt = optlist[i];
 
1958
        else
 
1959
            opt = NULL;
 
1960
 
 
1961
        if (!LoadModule(name, NULL, NULL, NULL, opt, NULL, &errmaj, &errmin)) {
 
1962
            LoaderErrorMsg(NULL, name, errmaj, errmin);
 
1963
            failed = TRUE;
 
1964
        }
 
1965
        xfree(name);
 
1966
    }
 
1967
    return !failed;
 
1968
}
 
1969
 
 
1970
#endif
 
1971
 
 
1972
/* Pixmap format stuff */
 
1973
 
 
1974
PixmapFormatPtr
 
1975
xf86GetPixFormat(ScrnInfoPtr pScrn, int depth)
 
1976
{
 
1977
    int i;
 
1978
    static PixmapFormatRec format;      /* XXX not reentrant */
 
1979
 
 
1980
    /*
 
1981
     * When the formats[] list initialisation isn't complete, check the
 
1982
     * depth 24 pixmap config/cmdline options and screen-specified formats.
 
1983
     */
 
1984
 
 
1985
    if (!formatsDone) {
 
1986
        if (depth == 24) {
 
1987
            Pix24Flags pix24 = Pix24DontCare;
 
1988
 
 
1989
            format.depth = 24;
 
1990
            format.scanlinePad = BITMAP_SCANLINE_PAD;
 
1991
            if (xf86Info.pixmap24 != Pix24DontCare)
 
1992
                pix24 = xf86Info.pixmap24;
 
1993
            else if (pScrn->pixmap24 != Pix24DontCare)
 
1994
                pix24 = pScrn->pixmap24;
 
1995
            if (pix24 == Pix24Use24)
 
1996
                format.bitsPerPixel = 24;
 
1997
            else
 
1998
                format.bitsPerPixel = 32;
 
1999
            return &format;
 
2000
        }
 
2001
    }
 
2002
        
 
2003
    for (i = 0; i < numFormats; i++)
 
2004
        if (formats[i].depth == depth)
 
2005
           break;
 
2006
    if (i != numFormats)
 
2007
        return &formats[i];
 
2008
    else if (!formatsDone) {
 
2009
        /* Check for screen-specified formats */
 
2010
        for (i = 0; i < pScrn->numFormats; i++)
 
2011
            if (pScrn->formats[i].depth == depth)
 
2012
                break;
 
2013
        if (i != pScrn->numFormats)
 
2014
            return &pScrn->formats[i];
 
2015
    }
 
2016
    return NULL;
 
2017
}
 
2018
 
 
2019
int
 
2020
xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth)
 
2021
{
 
2022
    PixmapFormatPtr format;
 
2023
 
 
2024
   
 
2025
    format = xf86GetPixFormat(pScrn, depth);
 
2026
    if (format)
 
2027
        return format->bitsPerPixel;
 
2028
    else
 
2029
        return 0;
 
2030
}
 
2031