1
/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Helper.c,v 1.136 2004/01/27 01:31:45 dawes Exp $ */
4
* Copyright (c) 1997-2003 by The XFree86 Project, Inc.
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the "Software"),
8
* to deal in the Software without restriction, including without limitation
9
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
* and/or sell copies of the Software, and to permit persons to whom the
11
* Software is furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
* OTHER DEALINGS IN THE SOFTWARE.
24
* Except as contained in this notice, the name of the copyright holder(s)
25
* and author(s) shall not be used in advertising or otherwise to promote
26
* the sale, use or other dealings in this Software without prior written
27
* authorization from the copyright holder(s) and author(s).
31
* Authors: Dirk Hohndel <hohndel@XFree86.Org>
32
* David Dawes <dawes@XFree86.Org>
35
* This file includes the helper functions that the server provides for
39
#ifdef HAVE_XORG_CONFIG_H
40
#include <xorg-config.h>
46
#include "pixmapstr.h"
47
#include "windowstr.h"
48
#include "propertyst.h"
50
#include "loaderProcs.h"
53
#include "xf86_OSlib.h"
55
#include "xf86PciInfo.h"
57
#include "xf86Xinput.h"
58
#include "xf86InPriv.h"
59
#include "mivalidate.h"
62
#include "xf86Version.h"
64
/* For xf86GetClocks */
65
#if defined(CSRG_BASED) || defined(__GNU__)
66
#define HAS_SETPRIORITY
67
#include <sys/resource.h>
70
static int xf86ScrnInfoPrivateCount = 0;
74
/* Add a pointer to a new DriverRec to xf86DriverList */
77
xf86AddDriver(DriverPtr driver, pointer module, int flags)
79
/* Don't add null entries */
83
if (xf86DriverList == NULL)
87
xf86DriverList = xnfrealloc(xf86DriverList,
88
xf86NumDrivers * sizeof(DriverPtr));
89
xf86DriverList[xf86NumDrivers - 1] = xnfalloc(sizeof(DriverRec));
90
if (flags & HaveDriverFuncs)
91
*xf86DriverList[xf86NumDrivers - 1] = *driver;
93
memcpy(xf86DriverList[xf86NumDrivers - 1], driver, sizeof(DriverRec1));
94
xf86DriverList[xf86NumDrivers - 1]->driverFunc = NULL;
96
xf86DriverList[xf86NumDrivers - 1]->module = module;
97
xf86DriverList[xf86NumDrivers - 1]->refCount = 0;
101
xf86DeleteDriver(int drvIndex)
103
if (xf86DriverList[drvIndex]
104
&& (!xf86DriverHasEntities(xf86DriverList[drvIndex]))) {
105
if (xf86DriverList[drvIndex]->module)
106
UnloadModule(xf86DriverList[drvIndex]->module);
107
xfree(xf86DriverList[drvIndex]);
108
xf86DriverList[drvIndex] = NULL;
112
/* Add a pointer to a new InputDriverRec to xf86InputDriverList */
115
xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags)
117
/* Don't add null entries */
121
if (xf86InputDriverList == NULL)
122
xf86NumInputDrivers = 0;
124
xf86NumInputDrivers++;
125
xf86InputDriverList = xnfrealloc(xf86InputDriverList,
126
xf86NumInputDrivers * sizeof(InputDriverPtr));
127
xf86InputDriverList[xf86NumInputDrivers - 1] =
128
xnfalloc(sizeof(InputDriverRec));
129
*xf86InputDriverList[xf86NumInputDrivers - 1] = *driver;
130
xf86InputDriverList[xf86NumInputDrivers - 1]->module = module;
131
xf86InputDriverList[xf86NumInputDrivers - 1]->refCount = 0;
135
xf86DeleteInputDriver(int drvIndex)
137
if (xf86InputDriverList[drvIndex] && xf86InputDriverList[drvIndex]->module)
138
UnloadModule(xf86InputDriverList[drvIndex]->module);
139
xfree(xf86InputDriverList[drvIndex]);
140
xf86InputDriverList[drvIndex] = NULL;
144
xf86AddModuleInfo(ModuleInfoPtr info, pointer module)
146
/* Don't add null entries */
150
if (xf86ModuleInfoList == NULL)
151
xf86NumModuleInfos = 0;
153
xf86NumModuleInfos++;
154
xf86ModuleInfoList = xnfrealloc(xf86ModuleInfoList,
155
xf86NumModuleInfos * sizeof(ModuleInfoPtr));
156
xf86ModuleInfoList[xf86NumModuleInfos - 1] = xnfalloc(sizeof(ModuleInfoRec));
157
*xf86ModuleInfoList[xf86NumModuleInfos - 1] = *info;
158
xf86ModuleInfoList[xf86NumModuleInfos - 1]->module = module;
159
xf86ModuleInfoList[xf86NumModuleInfos - 1]->refCount = 0;
163
xf86DeleteModuleInfo(int idx)
165
if (xf86ModuleInfoList[idx]) {
166
if (xf86ModuleInfoList[idx]->module)
167
UnloadModule(xf86ModuleInfoList[idx]->module);
168
xfree(xf86ModuleInfoList[idx]);
169
xf86ModuleInfoList[idx] = NULL;
175
/* Allocate a new ScrnInfoRec in xf86Screens */
178
xf86AllocateScreen(DriverPtr drv, int flags)
182
if (xf86Screens == NULL)
185
i = xf86NumScreens++;
186
xf86Screens = xnfrealloc(xf86Screens, xf86NumScreens * sizeof(ScrnInfoPtr));
187
xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1);
188
xf86Screens[i]->scrnIndex = i; /* Changes when a screen is removed */
189
xf86Screens[i]->origIndex = i; /* This never changes */
190
xf86Screens[i]->privates = xnfcalloc(sizeof(DevUnion),
191
xf86ScrnInfoPrivateCount);
193
* EnableDisableFBAccess now gets initialized in InitOutput()
194
* xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess;
197
xf86Screens[i]->drv = drv;
200
xf86Screens[i]->module = DuplicateModule(drv->module, NULL);
202
xf86Screens[i]->module = NULL;
205
* set the initial access state. This will be modified after PreInit.
206
* XXX Or should we do it some other place?
208
xf86Screens[i]->CurrentAccess = &xf86CurrentAccess;
209
xf86Screens[i]->resourceType = MEM_IO;
212
/* OOps -- What's this ? */
213
ErrorF("xf86AllocateScreen - xf86Screens[%d]->pScreen = %p\n",
214
i, xf86Screens[i]->pScreen );
215
if ( NULL != xf86Screens[i]->pScreen ) {
216
ErrorF("xf86Screens[%d]->pScreen->CreateWindow = %p\n",
217
i, xf86Screens[i]->pScreen->CreateWindow );
221
xf86Screens[i]->DriverFunc = drv->driverFunc;
223
return xf86Screens[i];
228
* Remove an entry from xf86Screens. Ideally it should free all allocated
229
* data. To do this properly may require a driver hook.
233
xf86DeleteScreen(int scrnIndex, int flags)
238
/* First check if the screen is valid */
239
if (xf86NumScreens == 0 || xf86Screens == NULL)
242
if (scrnIndex > xf86NumScreens - 1)
245
if (!(pScrn = xf86Screens[scrnIndex]))
248
/* If a FreeScreen function is defined, call it here */
249
if (pScrn->FreeScreen != NULL)
250
pScrn->FreeScreen(scrnIndex, 0);
253
xf86DeleteMode(&pScrn->modes, pScrn->modes);
255
while (pScrn->modePool)
256
xf86DeleteMode(&pScrn->modePool, pScrn->modePool);
258
xf86OptionListFree(pScrn->options);
262
UnloadModule(pScrn->module);
266
pScrn->drv->refCount--;
269
xfree(pScrn->privates);
271
xf86ClearEntityListForScreen(scrnIndex);
275
/* Move the other entries down, updating their scrnIndex fields */
279
for (i = scrnIndex; i < xf86NumScreens; i++) {
280
xf86Screens[i] = xf86Screens[i + 1];
281
xf86Screens[i]->scrnIndex = i;
282
/* Also need to take care of the screen layout settings */
287
* Allocate a private in ScrnInfoRec.
291
xf86AllocateScrnInfoPrivateIndex(void)
297
idx = xf86ScrnInfoPrivateCount++;
298
for (i = 0; i < xf86NumScreens; i++) {
299
pScr = xf86Screens[i];
300
nprivs = xnfrealloc(pScr->privates,
301
xf86ScrnInfoPrivateCount * sizeof(DevUnion));
302
/* Zero the new private */
303
bzero(&nprivs[idx], sizeof(DevUnion));
304
pScr->privates = nprivs;
309
/* Allocate a new InputInfoRec and add it to the head xf86InputDevs. */
312
xf86AllocateInput(InputDriverPtr drv, int flags)
316
if (!(new = xcalloc(sizeof(InputInfoRec), 1)))
322
new->module = DuplicateModule(drv->module, NULL);
326
new->next = xf86InputDevs;
333
* Remove an entry from xf86InputDevs. Ideally it should free all allocated
334
* data. To do this properly may require a driver hook.
338
xf86DeleteInput(InputInfoPtr pInp, int flags)
342
/* First check if the inputdev is valid. */
347
/* If a free function is defined, call it here. */
354
UnloadModule(pInp->module);
358
pInp->drv->refCount--;
361
xfree(pInp->private);
363
/* Remove the entry from the list. */
364
if (pInp == xf86InputDevs)
365
xf86InputDevs = pInp->next;
368
while (p && p->next != pInp)
371
p->next = pInp->next;
372
/* Else the entry wasn't in the xf86InputDevs list (ignore this). */
378
xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad)
382
if (pScrn->numFormats >= MAXFORMATS)
390
else if (depth <= 16)
392
else if (depth <= 32)
398
pad = BITMAP_SCANLINE_PAD;
400
i = pScrn->numFormats++;
401
pScrn->formats[i].depth = depth;
402
pScrn->formats[i].bitsPerPixel = bpp;
403
pScrn->formats[i].scanlinePad = pad;
408
* Set the depth we are using based on (in the following order of preference):
409
* - values given on the command line
410
* - values given in the config file
411
* - values provided by the driver
412
* - an overall default when nothing else is given
414
* Also find a Display subsection matching the depth/bpp found.
416
* Sets the following ScrnInfoRec fields:
417
* bitsPerPixel, pixmap24, depth, display, imageByteOrder,
418
* bitmapScanlinePad, bitmapScanlineUnit, bitmapBitOrder, numFormats,
422
/* Can the screen handle 24 bpp pixmaps */
423
#define DO_PIX24(f) ((f & Support24bppFb) || \
424
((f & Support32bppFb) && (f & SupportConvert24to32)))
426
/* Can the screen handle 32 bpp pixmaps */
427
#define DO_PIX32(f) ((f & Support32bppFb) || \
428
((f & Support24bppFb) && (f & SupportConvert32to24)))
430
/* Does the screen prefer 32bpp fb for 24bpp pixmaps */
431
#define CHOOSE32FOR24(f) ((f & Support32bppFb) && (f & SupportConvert24to32) \
432
&& (f & PreferConvert24to32))
434
/* Does the screen prefer 24bpp fb for 32bpp pixmaps */
435
#define CHOOSE24FOR32(f) ((f & Support24bppFb) && (f & SupportConvert32to24) \
436
&& (f & PreferConvert32to24))
438
/* Can the screen handle 32bpp pixmaps for 24bpp fb */
439
#define DO_PIX32FOR24(f) ((f & Support24bppFb) && (f & SupportConvert32to24))
441
/* Can the screen handle 24bpp pixmaps for 32bpp fb */
442
#define DO_PIX24FOR32(f) ((f & Support32bppFb) && (f & SupportConvert24to32))
444
#ifndef GLOBAL_DEFAULT_DEPTH
445
#define GLOBAL_DEFAULT_DEPTH 16
448
#ifndef GLOBAL_DEFAULT_FBBPP
449
#define GLOBAL_DEFAULT_FBBPP 16
453
xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp,
458
Pix24Flags pix24 = xf86Info.pixmap24;
459
Bool nomatch = FALSE;
461
scrp->bitsPerPixel = -1;
463
scrp->pixmap24 = Pix24DontCare;
464
scrp->bitsPerPixelFrom = X_DEFAULT;
465
scrp->depthFrom = X_DEFAULT;
467
#if BITMAP_SCANLINE_UNIT == 64
469
* For platforms with 64-bit scanlines, modify the driver's depth24flags
470
* to remove preferences for packed 24bpp modes, which are not currently
471
* supported on these platforms.
473
depth24flags &= ~(SupportConvert32to24 | SupportConvert32to24 |
474
PreferConvert24to32 | PreferConvert32to24);
478
scrp->bitsPerPixel = xf86FbBpp;
479
scrp->bitsPerPixelFrom = X_CMDLINE;
483
scrp->depth = xf86Depth;
484
scrp->depthFrom = X_CMDLINE;
487
if (xf86FbBpp < 0 && xf86Depth < 0) {
488
if (scrp->confScreen->defaultfbbpp > 0) {
489
scrp->bitsPerPixel = scrp->confScreen->defaultfbbpp;
490
scrp->bitsPerPixelFrom = X_CONFIG;
492
if (scrp->confScreen->defaultdepth > 0) {
493
scrp->depth = scrp->confScreen->defaultdepth;
494
scrp->depthFrom = X_CONFIG;
497
if (scrp->confScreen->defaultfbbpp <= 0 &&
498
scrp->confScreen->defaultdepth <= 0) {
500
* Check for DefaultDepth and DefaultFbBpp options in the
507
for (i = 0; i < scrp->numEntities; i++) {
508
device = xf86GetDevFromEntity(scrp->entityList[i],
509
scrp->entityInstanceList[i]);
510
if (device && device->options) {
511
if (xf86FindOption(device->options, "DefaultDepth")) {
512
scrp->depth = xf86SetIntOption(device->options,
514
scrp->depthFrom = X_CONFIG;
517
if (xf86FindOption(device->options, "DefaultFbBpp")) {
518
scrp->bitsPerPixel = xf86SetIntOption(device->options,
521
scrp->bitsPerPixelFrom = X_CONFIG;
531
/* If none of these is set, pick a default */
532
if (scrp->bitsPerPixel < 0 && scrp->depth < 0) {
533
if (fbbpp > 0 || depth > 0) {
535
scrp->bitsPerPixel = fbbpp;
539
scrp->bitsPerPixel = GLOBAL_DEFAULT_FBBPP;
540
scrp->depth = GLOBAL_DEFAULT_DEPTH;
544
/* If any are not given, determine a default for the others */
546
if (scrp->bitsPerPixel < 0) {
547
/* The depth must be set */
548
if (scrp->depth > -1) {
549
if (scrp->depth == 1)
550
scrp->bitsPerPixel = 1;
551
else if (scrp->depth <= 4)
552
scrp->bitsPerPixel = 4;
553
else if (scrp->depth <= 8)
554
scrp->bitsPerPixel = 8;
555
else if (scrp->depth <= 16)
556
scrp->bitsPerPixel = 16;
557
else if (scrp->depth <= 24) {
559
* Figure out if a choice is possible based on the depth24
562
/* Check pix24 first */
563
if (pix24 != Pix24DontCare) {
564
if (pix24 == Pix24Use32) {
565
if (DO_PIX32(depth24flags)) {
566
if (CHOOSE24FOR32(depth24flags))
567
scrp->bitsPerPixel = 24;
569
scrp->bitsPerPixel = 32;
573
} else if (pix24 == Pix24Use24) {
574
if (DO_PIX24(depth24flags)) {
575
if (CHOOSE32FOR24(depth24flags))
576
scrp->bitsPerPixel = 32;
578
scrp->bitsPerPixel = 24;
584
if (DO_PIX32(depth24flags)) {
585
if (CHOOSE24FOR32(depth24flags))
586
scrp->bitsPerPixel = 24;
588
scrp->bitsPerPixel = 32;
589
} else if (DO_PIX24(depth24flags)) {
590
if (CHOOSE32FOR24(depth24flags))
591
scrp->bitsPerPixel = 32;
593
scrp->bitsPerPixel = 24;
596
} else if (scrp->depth <= 32)
597
scrp->bitsPerPixel = 32;
599
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
600
"Specified depth (%d) is greater than 32\n",
605
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
606
"xf86SetDepthBpp: internal error: depth and fbbpp"
607
" are both not set\n");
610
if (scrp->bitsPerPixel < 0) {
612
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
613
"Driver can't support depth 24 pixmap format (%d)\n",
615
else if ((depth24flags & (Support24bppFb | Support32bppFb)) ==
617
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
618
"Driver can't support depth 24\n");
620
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
621
"Can't find fbbpp for depth 24\n");
624
scrp->bitsPerPixelFrom = X_PROBED;
627
if (scrp->depth <= 0) {
628
/* bitsPerPixel is already set */
629
switch (scrp->bitsPerPixel) {
634
/* 1, 4, 8, 16 and 24 */
635
scrp->depth = scrp->bitsPerPixel;
638
scrp->depthFrom = X_PROBED;
642
if (scrp->depth < 1 || scrp->depth > 32) {
643
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
644
"Specified depth (%d) is not in the range 1-32\n",
648
switch (scrp->bitsPerPixel) {
657
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
658
"Specified fbbpp (%d) is not a permitted value\n",
662
if (scrp->depth > scrp->bitsPerPixel) {
663
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
664
"Specified depth (%d) is greater than the fbbpp (%d)\n",
665
scrp->depth, scrp->bitsPerPixel);
669
/* set scrp->pixmap24 if the driver isn't flexible */
670
if (scrp->bitsPerPixel == 24 && !DO_PIX32FOR24(depth24flags)) {
671
scrp->pixmap24 = Pix24Use24;
673
if (scrp->bitsPerPixel == 32 && !DO_PIX24FOR32(depth24flags)) {
674
scrp->pixmap24 = Pix24Use32;
678
* Find the Display subsection matching the depth/fbbpp and initialise
679
* scrp->display with it.
681
for (i = 0, disp = scrp->confScreen->displays;
682
i < scrp->confScreen->numdisplays; i++, disp++) {
683
if ((disp->depth == scrp->depth && disp->fbbpp == scrp->bitsPerPixel)
684
|| (disp->depth == scrp->depth && disp->fbbpp <= 0)
685
|| (disp->fbbpp == scrp->bitsPerPixel && disp->depth <= 0)) {
686
scrp->display = disp;
692
* If an exact match can't be found, see if there is one with no
693
* depth or fbbpp specified.
695
if (i == scrp->confScreen->numdisplays) {
696
for (i = 0, disp = scrp->confScreen->displays;
697
i < scrp->confScreen->numdisplays; i++, disp++) {
698
if (disp->depth <= 0 && disp->fbbpp <= 0) {
699
scrp->display = disp;
706
* If all else fails, create a default one.
708
if (i == scrp->confScreen->numdisplays) {
709
scrp->confScreen->numdisplays++;
710
scrp->confScreen->displays =
711
xnfrealloc(scrp->confScreen->displays,
712
scrp->confScreen->numdisplays * sizeof(DispRec));
713
xf86DrvMsg(scrp->scrnIndex, X_INFO,
714
"Creating default Display subsection in Screen section\n"
715
"\t\"%s\" for depth/fbbpp %d/%d\n",
716
scrp->confScreen->id, scrp->depth, scrp->bitsPerPixel);
717
memset(&scrp->confScreen->displays[i], 0, sizeof(DispRec));
718
scrp->confScreen->displays[i].blackColour.red = -1;
719
scrp->confScreen->displays[i].blackColour.green = -1;
720
scrp->confScreen->displays[i].blackColour.blue = -1;
721
scrp->confScreen->displays[i].whiteColour.red = -1;
722
scrp->confScreen->displays[i].whiteColour.green = -1;
723
scrp->confScreen->displays[i].whiteColour.blue = -1;
724
scrp->confScreen->displays[i].defaultVisual = -1;
725
scrp->confScreen->displays[i].modes = xnfalloc(sizeof(char *));
726
scrp->confScreen->displays[i].modes[0] = NULL;
727
scrp->confScreen->displays[i].depth = depth;
728
scrp->confScreen->displays[i].fbbpp = fbbpp;
729
scrp->display = &scrp->confScreen->displays[i];
733
* Setup defaults for the display-wide attributes the framebuffer will
734
* need. These defaults should eventually be set globally, and not
735
* dependent on the screens.
737
scrp->imageByteOrder = IMAGE_BYTE_ORDER;
738
scrp->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
739
if (scrp->depth < 8) {
740
/* Planar modes need these settings */
741
scrp->bitmapScanlineUnit = 8;
742
scrp->bitmapBitOrder = MSBFirst;
744
scrp->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
745
scrp->bitmapBitOrder = BITMAP_BIT_ORDER;
749
* If an unusual depth is required, add it to scrp->formats. The formats
750
* for the common depths are handled globally in InitOutput
752
switch (scrp->depth) {
759
/* Common depths. Nothing to do for them */
762
if (!xf86AddPixFormat(scrp, scrp->depth, 0, 0)) {
763
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
764
"Can't add pixmap format for depth %d\n", scrp->depth);
769
/* Initialise the framebuffer format for this screen */
770
scrp->fbFormat.depth = scrp->depth;
771
scrp->fbFormat.bitsPerPixel = scrp->bitsPerPixel;
772
scrp->fbFormat.scanlinePad = BITMAP_SCANLINE_PAD;
778
* Print out the selected depth and bpp.
781
xf86PrintDepthBpp(ScrnInfoPtr scrp)
783
xf86DrvMsg(scrp->scrnIndex, scrp->depthFrom, "Depth %d, ", scrp->depth);
784
xf86Msg(scrp->bitsPerPixelFrom, "framebuffer bpp %d\n", scrp->bitsPerPixel);
788
* xf86SetWeight sets scrp->weight, scrp->mask, scrp->offset, and for depths
789
* greater than MAX_PSEUDO_DEPTH also scrp->rgbBits.
792
xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask)
794
MessageType weightFrom = X_DEFAULT;
796
scrp->weight.red = 0;
797
scrp->weight.green = 0;
798
scrp->weight.blue = 0;
800
if (xf86Weight.red > 0 && xf86Weight.green > 0 && xf86Weight.blue > 0) {
801
scrp->weight = xf86Weight;
802
weightFrom = X_CMDLINE;
803
} else if (scrp->display->weight.red > 0 && scrp->display->weight.green > 0
804
&& scrp->display->weight.blue > 0) {
805
scrp->weight = scrp->display->weight;
806
weightFrom = X_CONFIG;
807
} else if (weight.red > 0 && weight.green > 0 && weight.blue > 0) {
808
scrp->weight = weight;
810
switch (scrp->depth) {
814
scrp->weight.red = scrp->weight.green =
815
scrp->weight.blue = scrp->rgbBits;
818
scrp->weight.red = scrp->weight.green = scrp->weight.blue = 5;
821
scrp->weight.red = scrp->weight.blue = 5;
822
scrp->weight.green = 6;
825
scrp->weight.red = scrp->weight.green = scrp->weight.blue = 8;
828
scrp->weight.red = scrp->weight.green = scrp->weight.blue = 10;
833
if (scrp->weight.red)
834
xf86DrvMsg(scrp->scrnIndex, weightFrom, "RGB weight %d%d%d\n",
835
(int)scrp->weight.red, (int)scrp->weight.green,
836
(int)scrp->weight.blue);
838
if (scrp->depth > MAX_PSEUDO_DEPTH &&
839
(scrp->depth != scrp->weight.red + scrp->weight.green +
840
scrp->weight.blue)) {
841
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
842
"Weight given (%d%d%d) is inconsistent with the "
844
(int)scrp->weight.red, (int)scrp->weight.green,
845
(int)scrp->weight.blue, scrp->depth);
848
if (scrp->depth > MAX_PSEUDO_DEPTH && scrp->weight.red) {
850
* XXX Does this even mean anything for TrueColor visuals?
851
* If not, we shouldn't even be setting it here. However, this
852
* matches the behaviour of 3.x versions of XFree86.
854
scrp->rgbBits = scrp->weight.red;
855
if (scrp->weight.green > scrp->rgbBits)
856
scrp->rgbBits = scrp->weight.green;
857
if (scrp->weight.blue > scrp->rgbBits)
858
scrp->rgbBits = scrp->weight.blue;
861
/* Set the mask and offsets */
862
if (mask.red == 0 || mask.green == 0 || mask.blue == 0) {
863
/* Default to a setting common to PC hardware */
864
scrp->offset.red = scrp->weight.green + scrp->weight.blue;
865
scrp->offset.green = scrp->weight.blue;
866
scrp->offset.blue = 0;
867
scrp->mask.red = ((1 << scrp->weight.red) - 1) << scrp->offset.red;
868
scrp->mask.green = ((1 << scrp->weight.green) - 1)
869
<< scrp->offset.green;
870
scrp->mask.blue = (1 << scrp->weight.blue) - 1;
872
/* Initialise to the values passed */
873
scrp->mask.red = mask.red;
874
scrp->mask.green = mask.green;
875
scrp->mask.blue = mask.blue;
876
scrp->offset.red = ffs(mask.red);
877
scrp->offset.green = ffs(mask.green);
878
scrp->offset.blue = ffs(mask.blue);
884
xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual)
886
MessageType visualFrom = X_DEFAULT;
888
if (defaultColorVisualClass >= 0) {
889
scrp->defaultVisual = defaultColorVisualClass;
890
visualFrom = X_CMDLINE;
891
} else if (scrp->display->defaultVisual >= 0) {
892
scrp->defaultVisual = scrp->display->defaultVisual;
893
visualFrom = X_CONFIG;
894
} else if (visual >= 0) {
895
scrp->defaultVisual = visual;
897
if (scrp->depth == 1)
898
scrp->defaultVisual = StaticGray;
899
else if (scrp->depth == 4)
900
scrp->defaultVisual = StaticColor;
901
else if (scrp->depth <= MAX_PSEUDO_DEPTH)
902
scrp->defaultVisual = PseudoColor;
904
scrp->defaultVisual = TrueColor;
906
switch (scrp->defaultVisual) {
913
xf86DrvMsg(scrp->scrnIndex, visualFrom, "Default visual is %s\n",
914
xf86VisualNames[scrp->defaultVisual]);
918
xf86DrvMsg(scrp->scrnIndex, X_ERROR,
919
"Invalid default visual class (%d)\n", scrp->defaultVisual);
924
#define TEST_GAMMA(g) \
925
(g).red > GAMMA_ZERO || (g).green > GAMMA_ZERO || (g).blue > GAMMA_ZERO
927
#define SET_GAMMA(g) \
928
(g) > GAMMA_ZERO ? (g) : 1.0
931
xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma)
933
MessageType from = X_DEFAULT;
935
xf86MonPtr DDC = (xf86MonPtr)(scrp->monitor->DDC);
937
if (TEST_GAMMA(xf86Gamma)) {
939
scrp->gamma.red = SET_GAMMA(xf86Gamma.red);
940
scrp->gamma.green = SET_GAMMA(xf86Gamma.green);
941
scrp->gamma.blue = SET_GAMMA(xf86Gamma.blue);
942
} else if (TEST_GAMMA(scrp->monitor->gamma)) {
944
scrp->gamma.red = SET_GAMMA(scrp->monitor->gamma.red);
945
scrp->gamma.green = SET_GAMMA(scrp->monitor->gamma.green);
946
scrp->gamma.blue = SET_GAMMA(scrp->monitor->gamma.blue);
948
} else if ( DDC && DDC->features.gamma > GAMMA_ZERO ) {
950
scrp->gamma.red = SET_GAMMA(DDC->features.gamma);
951
scrp->gamma.green = SET_GAMMA(DDC->features.gamma);
952
scrp->gamma.blue = SET_GAMMA(DDC->features.gamma);
953
/* EDID structure version 2 gives optional seperate red, green & blue gamma values
954
* in bytes 0x57-0x59 */
956
} else if (TEST_GAMMA(gamma)) {
957
scrp->gamma.red = SET_GAMMA(gamma.red);
958
scrp->gamma.green = SET_GAMMA(gamma.green);
959
scrp->gamma.blue = SET_GAMMA(gamma.blue);
961
scrp->gamma.red = 1.0;
962
scrp->gamma.green = 1.0;
963
scrp->gamma.blue = 1.0;
965
xf86DrvMsg(scrp->scrnIndex, from,
966
"Using gamma correction (%.1f, %.1f, %.1f)\n",
967
scrp->gamma.red, scrp->gamma.green, scrp->gamma.blue);
977
* Set the DPI from the command line option. XXX should allow it to be
978
* calculated from the widthmm/heightmm values.
982
#define MMPERINCH 25.4
985
xf86SetDpi(ScrnInfoPtr pScrn, int x, int y)
987
MessageType from = X_DEFAULT;
988
xf86MonPtr DDC = (xf86MonPtr)(pScrn->monitor->DDC);
989
int ddcWidthmm, ddcHeightmm;
990
int widthErr, heightErr;
992
/* XXX Maybe there is no need for widthmm/heightmm in ScrnInfoRec */
993
pScrn->widthmm = pScrn->monitor->widthmm;
994
pScrn->heightmm = pScrn->monitor->heightmm;
996
if (DDC && (DDC->features.hsize > 0 && DDC->features.vsize > 0) ) {
997
/* DDC gives display size in mm for individual modes,
1000
ddcWidthmm = DDC->features.hsize * 10; /* 10mm in 1cm */
1001
ddcHeightmm = DDC->features.vsize * 10; /* 10mm in 1cm */
1003
ddcWidthmm = ddcHeightmm = 0;
1006
if (monitorResolution > 0) {
1007
pScrn->xDpi = monitorResolution;
1008
pScrn->yDpi = monitorResolution;
1010
} else if (pScrn->widthmm > 0 || pScrn->heightmm > 0) {
1012
if (pScrn->widthmm > 0) {
1014
(int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm);
1016
if (pScrn->heightmm > 0) {
1018
(int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm);
1020
if (pScrn->xDpi > 0 && pScrn->yDpi <= 0)
1021
pScrn->yDpi = pScrn->xDpi;
1022
if (pScrn->yDpi > 0 && pScrn->xDpi <= 0)
1023
pScrn->xDpi = pScrn->yDpi;
1024
xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n",
1025
pScrn->widthmm, pScrn->heightmm);
1027
/* Warn if config and probe disagree about display size */
1028
if ( ddcWidthmm && ddcHeightmm ) {
1029
if (pScrn->widthmm > 0) {
1030
widthErr = abs(ddcWidthmm - pScrn->widthmm);
1034
if (pScrn->heightmm > 0) {
1035
heightErr = abs(ddcHeightmm - pScrn->heightmm);
1039
if (widthErr>10 || heightErr>10) {
1040
/* Should include config file name for monitor here */
1041
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
1042
"Probed monitor is %dx%d mm, using Displaysize %dx%d mm\n",
1043
ddcWidthmm,ddcHeightmm, pScrn->widthmm,pScrn->heightmm);
1046
} else if ( ddcWidthmm && ddcHeightmm ) {
1048
xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n",
1049
ddcWidthmm, ddcHeightmm );
1050
pScrn->widthmm = ddcWidthmm;
1051
pScrn->heightmm = ddcHeightmm;
1052
if (pScrn->widthmm > 0) {
1054
(int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm);
1056
if (pScrn->heightmm > 0) {
1058
(int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm);
1060
if (pScrn->xDpi > 0 && pScrn->yDpi <= 0)
1061
pScrn->yDpi = pScrn->xDpi;
1062
if (pScrn->yDpi > 0 && pScrn->xDpi <= 0)
1063
pScrn->xDpi = pScrn->yDpi;
1068
pScrn->xDpi = DEFAULT_DPI;
1072
pScrn->yDpi = DEFAULT_DPI;
1074
xf86DrvMsg(pScrn->scrnIndex, from, "DPI set to (%d, %d)\n",
1075
pScrn->xDpi, pScrn->yDpi);
1082
xf86SetBlackWhitePixels(ScreenPtr pScreen)
1084
if (xf86FlipPixels) {
1085
pScreen->whitePixel = 0;
1086
pScreen->blackPixel = 1;
1088
pScreen->whitePixel = 1;
1089
pScreen->blackPixel = 0;
1094
* xf86SetRootClip --
1095
* Enable or disable rendering to the screen by
1096
* setting the root clip list and revalidating
1097
* all of the windows
1101
xf86SetRootClip (ScreenPtr pScreen, Bool enable)
1103
WindowPtr pWin = WindowTable[pScreen->myNum];
1105
Bool WasViewable = (Bool)(pWin->viewable);
1106
Bool anyMarked = FALSE;
1107
RegionPtr pOldClip = NULL, bsExposed;
1108
#ifdef DO_SAVE_UNDERS
1109
Bool dosave = FALSE;
1111
WindowPtr pLayerWin;
1116
for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
1118
(void) (*pScreen->MarkOverlappedWindows)(pChild,
1122
(*pScreen->MarkWindow) (pWin);
1126
if (HasBorder (pWin))
1128
RegionPtr borderVisible;
1130
borderVisible = REGION_CREATE(pScreen, NullBox, 1);
1131
REGION_SUBTRACT(pScreen, borderVisible,
1132
&pWin->borderClip, &pWin->winSize);
1133
pWin->valdata->before.borderVisible = borderVisible;
1135
pWin->valdata->before.resized = TRUE;
1140
* Use REGION_BREAK to avoid optimizations in ValidateTree
1141
* that assume the root borderClip can't change well, normally
1148
box.x2 = pScreen->width;
1149
box.y2 = pScreen->height;
1150
REGION_INIT (pScreen, &pWin->winSize, &box, 1);
1151
REGION_INIT (pScreen, &pWin->borderSize, &box, 1);
1153
REGION_RESET(pScreen, &pWin->borderClip, &box);
1154
pWin->drawable.width = pScreen->width;
1155
pWin->drawable.height = pScreen->height;
1156
REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
1160
REGION_EMPTY(pScreen, &pWin->borderClip);
1161
REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
1164
ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
1168
if (pWin->backStorage)
1170
pOldClip = REGION_CREATE(pScreen, NullBox, 1);
1171
REGION_COPY(pScreen, pOldClip, &pWin->clipList);
1174
if (pWin->firstChild)
1176
anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin->firstChild,
1182
(*pScreen->MarkWindow) (pWin);
1186
#ifdef DO_SAVE_UNDERS
1187
if (DO_SAVE_UNDERS(pWin))
1189
dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin);
1191
#endif /* DO_SAVE_UNDERS */
1194
(*pScreen->ValidateTree)(pWin, NullWindow, VTOther);
1197
if (pWin->backStorage &&
1198
((pWin->backingStore == Always) || WasViewable))
1201
pOldClip = &pWin->clipList; /* a convenient empty region */
1202
bsExposed = (*pScreen->TranslateBackingStore)
1203
(pWin, 0, 0, pOldClip,
1204
pWin->drawable.x, pWin->drawable.y);
1206
REGION_DESTROY(pScreen, pOldClip);
1209
RegionPtr valExposed = NullRegion;
1212
valExposed = &pWin->valdata->after.exposed;
1213
(*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
1215
REGION_EMPTY(pScreen, valExposed);
1216
REGION_DESTROY(pScreen, bsExposed);
1222
(*pScreen->HandleExposures)(pWin);
1223
#ifdef DO_SAVE_UNDERS
1225
(*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin);
1226
#endif /* DO_SAVE_UNDERS */
1227
if (anyMarked && pScreen->PostValidateTree)
1228
(*pScreen->PostValidateTree)(pWin, NullWindow, VTOther);
1231
WindowsRestructured ();
1236
* Function to enable/disable access to the frame buffer
1238
* This is used when VT switching and when entering/leaving DGA direct mode.
1240
* This has been rewritten again to eliminate the saved pixmap. The
1241
* devPrivate field in the screen pixmap is set to NULL to catch code
1242
* accidentally referencing the frame buffer while the X server is not
1243
* supposed to touch it.
1245
* Here, we exchange the pixmap private data, rather than the pixmaps
1246
* themselves to avoid having to find and change any references to the screen
1247
* pixmap such as GC's, window privates etc. This also means that this code
1248
* does not need to know exactly how the pixmap pixels are accessed. Further,
1249
* this exchange is >not< done through the screen's ModifyPixmapHeader()
1250
* vector. This means the called frame buffer code layers can determine
1251
* whether they are switched in or out by keeping track of the root pixmap's
1252
* private data, and therefore don't need to access pScrnInfo->vtSema.
1255
xf86EnableDisableFBAccess(int scrnIndex, Bool enable)
1257
ScrnInfoPtr pScrnInfo = xf86Screens[scrnIndex];
1258
ScreenPtr pScreen = pScrnInfo->pScreen;
1261
pspix = (*pScreen->GetScreenPixmap) (pScreen);
1265
* Restore the screen pixmap devPrivate field
1267
pspix->devPrivate = pScrnInfo->pixmapPrivate;
1269
* Restore all of the clip lists on the screen
1272
xf86SetRootClip (pScreen, TRUE);
1278
* Empty all of the clip lists on the screen
1280
xf86SetRootClip (pScreen, FALSE);
1282
* save the screen pixmap devPrivate field and
1283
* replace it with NULL so accidental references
1284
* to the frame buffer are caught
1286
pScrnInfo->pixmapPrivate = pspix->devPrivate;
1287
pspix->devPrivate.ptr = NULL;
1291
/* Print driver messages in the standard format */
1294
#define PREFIX_SIZE 14
1297
xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
1302
/* Prefix the scrnIndex name to the format string. */
1303
if (scrnIndex >= 0 && scrnIndex < xf86NumScreens &&
1304
xf86Screens[scrnIndex]->name) {
1305
tmpFormat = xalloc(strlen(format) +
1306
strlen(xf86Screens[scrnIndex]->name) +
1311
snprintf(tmpFormat, PREFIX_SIZE + 1, "%s(%d): ",
1312
xf86Screens[scrnIndex]->name, scrnIndex);
1314
strcat(tmpFormat, format);
1315
LogVMessageVerb(type, verb, tmpFormat, args);
1318
LogVMessageVerb(type, verb, format, args);
1322
/* Print driver messages, with verbose level specified directly */
1324
xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
1329
va_start(ap, format);
1330
xf86VDrvMsgVerb(scrnIndex, type, verb, format, ap);
1334
/* Print driver messages, with verbose level of 1 (default) */
1336
xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...)
1340
va_start(ap, format);
1341
xf86VDrvMsgVerb(scrnIndex, type, 1, format, ap);
1345
/* Print non-driver messages with verbose level specified directly */
1347
xf86MsgVerb(MessageType type, int verb, const char *format, ...)
1351
va_start(ap, format);
1352
xf86VDrvMsgVerb(-1, type, verb, format, ap);
1356
/* Print non-driver messages with verbose level of 1 (default) */
1358
xf86Msg(MessageType type, const char *format, ...)
1362
va_start(ap, format);
1363
xf86VDrvMsgVerb(-1, type, 1, format, ap);
1367
/* Just like ErrorF, but with the verbose level checked */
1369
xf86ErrorFVerb(int verb, const char *format, ...)
1373
va_start(ap, format);
1374
if (xf86Verbose >= verb || xf86LogVerbose >= verb)
1375
LogVWrite(verb, format, ap);
1379
/* Like xf86ErrorFVerb, but with an implied verbose level of 1 */
1381
xf86ErrorF(const char *format, ...)
1385
va_start(ap, format);
1386
if (xf86Verbose >= 1 || xf86LogVerbose >= 1)
1387
LogVWrite(1, format, ap);
1397
#define LOGSUFFIX ".log"
1398
#define LOGOLDSUFFIX ".old"
1400
/* Get the log file name */
1401
if (xf86LogFileFrom == X_DEFAULT) {
1402
/* Append the display number and ".log" */
1403
lf = malloc(strlen(xf86LogFile) + strlen("%s") +
1404
strlen(LOGSUFFIX) + 1);
1406
FatalError("Cannot allocate space for the log file name\n");
1407
sprintf(lf, "%s%%s" LOGSUFFIX, xf86LogFile);
1411
xf86LogFile = LogInit(xf86LogFile, LOGOLDSUFFIX);
1412
xf86LogFileWasOpened = TRUE;
1414
xf86SetVerbosity(xf86Verbose);
1415
xf86SetLogVerbosity(xf86LogVerbose);
1429
* Drivers can use these for using their own SymTabRecs.
1433
xf86TokenToString(SymTabPtr table, int token)
1437
for (i = 0; table[i].token >= 0 && table[i].token != token; i++)
1440
if (table[i].token < 0)
1443
return(table[i].name);
1447
xf86StringToToken(SymTabPtr table, const char *string)
1454
for (i = 0; table[i].token >= 0 && xf86NameCmp(string, table[i].name); i++)
1457
return(table[i].token);
1461
* helper to display the clocks found on a card
1464
xf86ShowClocks(ScrnInfoPtr scrp, MessageType from)
1468
xf86DrvMsg(scrp->scrnIndex, from, "Pixel clocks available:");
1469
for (j=0; j < scrp->numClocks; j++) {
1472
xf86DrvMsg(scrp->scrnIndex, from, "pixel clocks:");
1474
xf86ErrorF(" %7.3f", (double)scrp->clock[j] / 1000.0);
1481
* This prints out the driver identify message, including the names of
1482
* the supported chipsets.
1484
* XXX This makes assumptions about the line width, etc. Maybe we could
1485
* use a more general "pretty print" function for messages.
1488
xf86PrintChipsets(const char *drvname, const char *drvmsg, SymTabPtr chips)
1492
len = 6 + strlen(drvname) + 2 + strlen(drvmsg) + 2;
1493
xf86Msg(X_INFO, "%s: %s:", drvname, drvmsg);
1494
for (i = 0; chips[i].name != NULL; i++) {
1499
if (len + 2 + strlen(chips[i].name) < 78) {
1506
xf86ErrorF("%s", chips[i].name);
1507
len += strlen(chips[i].name);
1513
#define MAXDRIVERS 64 /* A >hack<, to be sure ... */
1517
xf86MatchDevice(const char *drivername, GDevPtr **sectlist)
1519
GDevPtr gdp, *pgdp = NULL;
1520
confScreenPtr screensecptr;
1526
if (xf86DoProbe) return 1;
1528
if (xf86DoConfigure && xf86DoConfigurePass1) return 1;
1531
* This is a very important function that matches the device sections
1532
* as they show up in the config file with the drivers that the server
1533
* loads at run time.
1535
* ChipProbe can call
1536
* int xf86MatchDevice(char * drivername, GDevPtr ** sectlist)
1537
* with its driver name. The function allocates an array of GDevPtr and
1538
* returns this via sectlist and returns the number of elements in
1539
* this list as return value. 0 means none found, -1 means fatal error.
1541
* It can figure out which of the Device sections to use for which card
1542
* (using things like the Card statement, etc). For single headed servers
1543
* there will of course be just one such Device section.
1548
* first we need to loop over all the Screens sections to get to all
1549
* 'active' device sections
1551
for (j=0; xf86ConfigLayout.screens[j].screen != NULL; j++) {
1552
screensecptr = xf86ConfigLayout.screens[j].screen;
1553
if ((screensecptr->device->driver != NULL)
1554
&& (xf86NameCmp( screensecptr->device->driver,drivername) == 0)
1555
&& (! screensecptr->device->claimed)) {
1557
* we have a matching driver that wasn't claimed, yet
1559
pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr));
1560
pgdp[i++] = screensecptr->device;
1564
/* Then handle the inactive devices */
1566
while (xf86ConfigLayout.inactives[j].identifier) {
1567
gdp = &xf86ConfigLayout.inactives[j];
1568
if (gdp->driver && !gdp->claimed &&
1569
!xf86NameCmp(gdp->driver,drivername)) {
1570
/* we have a matching driver that wasn't claimed yet */
1571
pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr));
1578
* make the array NULL terminated and return its address
1593
Bool foundHW; /* PCIid in list of supported chipsets */
1594
Bool claimed; /* BusID matches with a device section */
1600
xf86MatchPciInstances(const char *driverName, int vendorID,
1601
SymTabPtr chipsets, PciChipsets *PCIchipsets,
1602
GDevPtr *devList, int numDevs, DriverPtr drvp,
1603
int **foundEntities)
1607
pciVideoPtr pPci, *ppPci;
1611
Bool foundHW; /* PCIid in list of supported chipsets */
1612
Bool claimed; /* BusID matches with a device section */
1615
} *instances = NULL;
1616
int numClaimedInstances = 0;
1617
int allocatedInstances = 0;
1621
GDevPtr devBus = NULL;
1623
int *retEntities = NULL;
1625
*foundEntities = NULL;
1627
if (vendorID == 0) {
1628
for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
1629
Bool foundVendor = FALSE;
1630
for (id = PCIchipsets; id->PCIid != -1; id++) {
1631
if ( (((id->PCIid & 0xFFFF0000) >> 16) == (*ppPci)->vendor)) {
1633
++allocatedInstances;
1634
instances = xnfrealloc(instances,
1635
allocatedInstances * sizeof(struct Inst));
1636
instances[allocatedInstances - 1].pci = *ppPci;
1637
instances[allocatedInstances - 1].dev = NULL;
1638
instances[allocatedInstances - 1].claimed = FALSE;
1639
instances[allocatedInstances - 1].foundHW = FALSE;
1640
instances[allocatedInstances - 1].screen = 0;
1643
if ((id->PCIid & 0x0000FFFF) == (*ppPci)->chipType) {
1644
instances[allocatedInstances - 1].foundHW = TRUE;
1645
instances[allocatedInstances - 1].chip = id->numChipset;
1651
} else if (vendorID == PCI_VENDOR_GENERIC) {
1652
for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
1653
for (id = PCIchipsets; id->PCIid != -1; id++) {
1654
if (id->PCIid == xf86CheckPciGAType(*ppPci)) {
1655
++allocatedInstances;
1656
instances = xnfrealloc(instances,
1657
allocatedInstances * sizeof(struct Inst));
1658
instances[allocatedInstances - 1].pci = *ppPci;
1659
instances[allocatedInstances - 1].dev = NULL;
1660
instances[allocatedInstances - 1].claimed = FALSE;
1661
instances[allocatedInstances - 1].foundHW = TRUE;
1662
instances[allocatedInstances - 1].chip = id->numChipset;
1663
instances[allocatedInstances - 1].screen = 0;
1669
/* Find PCI devices that match the given vendor ID */
1670
for (ppPci = xf86PciVideoInfo; (ppPci != NULL)
1671
&& (*ppPci != NULL); ppPci++) {
1672
if ((*ppPci)->vendor == vendorID) {
1673
++allocatedInstances;
1674
instances = xnfrealloc(instances,
1675
allocatedInstances * sizeof(struct Inst));
1676
instances[allocatedInstances - 1].pci = *ppPci;
1677
instances[allocatedInstances - 1].dev = NULL;
1678
instances[allocatedInstances - 1].claimed = FALSE;
1679
instances[allocatedInstances - 1].foundHW = FALSE;
1680
instances[allocatedInstances - 1].screen = 0;
1682
/* Check if the chip type is listed in the chipsets table */
1683
for (id = PCIchipsets; id->PCIid != -1; id++) {
1684
if (id->PCIid == (*ppPci)->chipType) {
1685
instances[allocatedInstances - 1].chip
1687
instances[allocatedInstances - 1].foundHW = TRUE;
1697
* This may be debatable, but if no PCI devices with a matching vendor
1698
* type is found, return zero now. It is probably not desirable to
1699
* allow the config file to override this.
1701
if (allocatedInstances <= 0) {
1711
if (xf86DoConfigure && xf86DoConfigurePass1) {
1713
int actualcards = 0;
1714
for (i = 0; i < allocatedInstances; i++) {
1715
pPci = instances[i].pci;
1716
if (instances[i].foundHW) {
1717
if (!xf86CheckPciSlot(pPci->bus, pPci->device, pPci->func))
1720
pGDev = xf86AddDeviceToConfigure(drvp->driverName,
1721
instances[i].pci, -1);
1724
* XF86Match???Instances() treat chipID and chipRev as
1725
* overrides, so clobber them here.
1727
pGDev->chipID = pGDev->chipRev = -1;
1736
ErrorF("%s instances found: %d\n", driverName, allocatedInstances);
1740
* Check for devices that need duplicated instances. This is required
1741
* when there is more than one screen per entity.
1743
* XXX This currently doesn't work for cases where the BusID isn't
1744
* specified explicitly in the config file.
1747
for (j = 0; j < numDevs; j++) {
1748
if (devList[j]->screen > 0 && devList[j]->busID
1749
&& *devList[j]->busID) {
1750
for (i = 0; i < allocatedInstances; i++) {
1751
pPci = instances[i].pci;
1752
if (xf86ComparePciBusString(devList[j]->busID, pPci->bus,
1755
allocatedInstances++;
1756
instances = xnfrealloc(instances,
1757
allocatedInstances *
1758
sizeof(struct Inst));
1759
instances[allocatedInstances - 1] = instances[i];
1760
instances[allocatedInstances - 1].screen =
1769
for (i = 0; i < allocatedInstances; i++) {
1770
pPci = instances[i].pci;
1773
for (j = 0; j < numDevs; j++) {
1774
if (devList[j]->busID && *devList[j]->busID) {
1775
if (xf86ComparePciBusString(devList[j]->busID, pPci->bus,
1778
devList[j]->screen == instances[i].screen) {
1781
xf86MsgVerb(X_WARNING,0,
1782
"%s: More than one matching Device section for "
1783
"instances\n\t(BusID: %s) found: %s\n",
1784
driverName, devList[j]->busID,
1785
devList[j]->identifier);
1787
devBus = devList[j];
1791
* if device section without BusID is found
1792
* only assign to it to the primary device.
1794
if (xf86IsPrimaryPci(pPci)) {
1795
xf86Msg(X_PROBED, "Assigning device section with no busID"
1796
" to primary device\n");
1798
xf86MsgVerb(X_WARNING, 0,
1799
"%s: More than one matching Device section "
1800
"found: %s\n", driverName, devList[j]->identifier);
1806
if (devBus) dev = devBus; /* busID preferred */
1808
if (xf86CheckPciSlot(pPci->bus, pPci->device, pPci->func)) {
1809
xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section "
1810
"for instance (BusID PCI:%i:%i:%i) found\n",
1811
driverName, pPci->bus, pPci->device, pPci->func);
1814
numClaimedInstances++;
1815
instances[i].claimed = TRUE;
1816
instances[i].dev = dev;
1820
ErrorF("%s instances found: %d\n", driverName, numClaimedInstances);
1823
* Now check that a chipset or chipID override in the device section
1824
* is valid. Chipset has precedence over chipID.
1825
* If chipset is not valid ignore BusSlot completely.
1827
for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) {
1828
if (!instances[i].claimed) {
1832
if (instances[i].dev->chipset) {
1833
for (c = chipsets; c->token >= 0; c++) {
1834
if (xf86NameCmp(c->name, instances[i].dev->chipset) == 0)
1837
if (c->token == -1) {
1838
instances[i].claimed = FALSE;
1839
numClaimedInstances--;
1840
xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device "
1841
"section \"%s\" isn't valid for this driver\n",
1842
driverName, instances[i].dev->chipset,
1843
instances[i].dev->identifier);
1845
instances[i].chip = c->token;
1847
for (id = PCIchipsets; id->numChipset >= 0; id++) {
1848
if (id->numChipset == instances[i].chip)
1851
if(id->numChipset >=0){
1852
xf86Msg(X_CONFIG,"Chipset override: %s\n",
1853
instances[i].dev->chipset);
1856
instances[i].claimed = FALSE;
1857
numClaimedInstances--;
1858
xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device "
1859
"section \"%s\" isn't a valid PCI chipset\n",
1860
driverName, instances[i].dev->chipset,
1861
instances[i].dev->identifier);
1864
} else if (instances[i].dev->chipID > 0) {
1865
for (id = PCIchipsets; id->numChipset >= 0; id++) {
1866
if (id->PCIid == instances[i].dev->chipID)
1869
if (id->numChipset == -1) {
1870
instances[i].claimed = FALSE;
1871
numClaimedInstances--;
1872
xf86MsgVerb(X_WARNING, 0, "%s: ChipID 0x%04X in Device "
1873
"section \"%s\" isn't valid for this driver\n",
1874
driverName, instances[i].dev->chipID,
1875
instances[i].dev->identifier);
1877
instances[i].chip = id->numChipset;
1879
xf86Msg( X_CONFIG,"ChipID override: 0x%04X\n",
1880
instances[i].dev->chipID);
1883
} else if (!instances[i].foundHW) {
1885
* This means that there was no override and the PCI chipType
1886
* doesn't match one that is supported
1888
instances[i].claimed = FALSE;
1889
numClaimedInstances--;
1891
if (instances[i].claimed == TRUE){
1892
for (c = chipsets; c->token >= 0; c++) {
1893
if (c->token == instances[i].chip)
1896
xf86Msg(from,"Chipset %s found\n",
1902
* Of the claimed instances, check that another driver hasn't already
1906
for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) {
1908
if (!instances[i].claimed)
1910
pPci = instances[i].pci;
1914
* Allow the same entity to be used more than once for devices with
1915
* multiple screens per entity. This assumes implicitly that there
1916
* will be a screen == 0 instance.
1918
* XXX Need to make sure that two different drivers don't claim
1919
* the same screen > 0 instance.
1921
if (instances[i].screen == 0 &&
1922
!xf86CheckPciSlot(pPci->bus, pPci->device, pPci->func))
1926
ErrorF("%s: card at %d:%d:%d is claimed by a Device section\n",
1927
driverName, pPci->bus, pPci->device, pPci->func);
1930
/* Allocate an entry in the lists to be returned */
1932
retEntities = xnfrealloc(retEntities, numFound * sizeof(int));
1933
retEntities[numFound - 1]
1934
= xf86ClaimPciSlot(pPci->bus, pPci->device,
1935
pPci->func,drvp, instances[i].chip,
1936
instances[i].dev,instances[i].dev->active ?
1938
if (retEntities[numFound - 1] == -1 && instances[i].screen > 0) {
1939
for (j = 0; j < xf86NumEntities; j++) {
1940
EntityPtr pEnt = xf86Entities[j];
1941
if (pEnt->busType != BUS_PCI)
1943
if (pEnt->pciBusId.bus == pPci->bus &&
1944
pEnt->pciBusId.device == pPci->device &&
1945
pEnt->pciBusId.func == pPci->func) {
1946
retEntities[numFound - 1] = j;
1947
xf86AddDevToEntity(j, instances[i].dev);
1955
*foundEntities = retEntities;
1962
xf86MatchIsaInstances(const char *driverName, SymTabPtr chipsets,
1963
IsaChipsets *ISAchipsets, DriverPtr drvp,
1964
FindIsaDevProc FindIsaDevice, GDevPtr *devList,
1965
int numDevs, int **foundEntities)
1972
int *retEntities = NULL;
1974
*foundEntities = NULL;
1976
#if defined(__sparc__) || defined(__powerpc__)
1977
FindIsaDevice = NULL; /* Temporary */
1980
if (xf86DoProbe || (xf86DoConfigure && xf86DoConfigurePass1)) {
1981
if (FindIsaDevice &&
1982
((foundChip = (*FindIsaDevice)(NULL)) != -1)) {
1983
xf86AddDeviceToConfigure(drvp->driverName, NULL, foundChip);
1989
for (i = 0; i < numDevs; i++) {
1990
MessageType from = X_CONFIG;
1992
GDevPtr devBus = NULL;
1994
if (devList[i]->busID && *devList[i]->busID) {
1995
if (xf86ParseIsaBusString(devList[i]->busID)) {
1996
if (devBus) xf86MsgVerb(X_WARNING,0,
1997
"%s: More than one matching Device "
1998
"section for ISA-Bus found: %s\n",
1999
driverName,devList[i]->identifier);
2000
else devBus = devList[i];
2003
if (xf86IsPrimaryIsa()) {
2004
if (dev) xf86MsgVerb(X_WARNING,0,
2005
"%s: More than one matching "
2006
"Device section found: %s\n",
2007
driverName,devList[i]->identifier);
2008
else dev = devList[i];
2011
if (devBus) dev = devBus;
2014
for (c = chipsets; c->token >= 0; c++) {
2015
if (xf86NameCmp(c->name, dev->chipset) == 0)
2018
if (c->token == -1) {
2019
xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device "
2020
"section \"%s\" isn't valid for this driver\n",
2021
driverName, dev->chipset,
2024
foundChip = c->token;
2026
if (FindIsaDevice) foundChip = (*FindIsaDevice)(dev);
2032
/* Check if the chip type is listed in the chipset table - for sanity*/
2034
if (foundChip >= 0){
2035
for (Chips = ISAchipsets; Chips->numChipset >= 0; Chips++) {
2036
if (Chips->numChipset == foundChip)
2039
if (Chips->numChipset == -1){
2041
xf86MsgVerb(X_WARNING,0,
2042
"%s: Driver detected unknown ISA-Bus Chipset\n",
2046
if (foundChip != -1) {
2048
retEntities = xnfrealloc(retEntities,numFound * sizeof(int));
2049
retEntities[numFound - 1] =
2050
xf86ClaimIsaSlot(drvp,foundChip,dev, dev->active ? TRUE : FALSE);
2051
for (c = chipsets; c->token >= 0; c++) {
2052
if (c->token == foundChip)
2055
xf86Msg(from, "Chipset %s found\n", c->name);
2058
*foundEntities = retEntities;
2064
* xf86GetClocks -- get the dot-clocks via a BIG BAD hack ...
2067
xf86GetClocks(ScrnInfoPtr pScrn, int num, Bool (*ClockFunc)(ScrnInfoPtr, int),
2068
void (*ProtectRegs)(ScrnInfoPtr, Bool),
2069
void (*BlankScreen)(ScrnInfoPtr, Bool), IOADDRESS vertsyncreg,
2070
int maskval, int knownclkindex, int knownclkvalue)
2072
register int status = vertsyncreg;
2073
unsigned long i, cnt, rcnt, sync;
2075
/* First save registers that get written on */
2076
(*ClockFunc)(pScrn, CLK_REG_SAVE);
2078
xf86SetPriority(TRUE);
2080
if (num > MAXCLOCKS)
2083
for (i = 0; i < num; i++)
2086
(*ProtectRegs)(pScrn, TRUE);
2087
if (!(*ClockFunc)(pScrn, i))
2089
pScrn->clock[i] = -1;
2093
(*ProtectRegs)(pScrn, FALSE);
2095
(*BlankScreen)(pScrn, FALSE);
2097
usleep(50000); /* let VCO stabilise */
2102
/* XXX How critical is this? */
2103
if (!xf86DisableInterrupts())
2105
(*ClockFunc)(pScrn, CLK_REG_RESTORE);
2106
ErrorF("Failed to disable interrupts during clock probe. If\n");
2107
ErrorF("your OS does not support disabling interrupts, then you\n");
2108
FatalError("must specify a Clocks line in the XF86Config file.\n");
2110
while ((inb(status) & maskval) == 0x00)
2111
if (sync-- == 0) goto finish;
2112
/* Something appears to be happening, so reset sync count */
2114
while ((inb(status) & maskval) == maskval)
2115
if (sync-- == 0) goto finish;
2116
/* Something appears to be happening, so reset sync count */
2118
while ((inb(status) & maskval) == 0x00)
2119
if (sync-- == 0) goto finish;
2121
for (rcnt = 0; rcnt < 5; rcnt++)
2123
while (!(inb(status) & maskval))
2125
while ((inb(status) & maskval))
2130
xf86EnableInterrupts();
2132
pScrn->clock[i] = cnt ? cnt : -1;
2134
(*BlankScreen)(pScrn, TRUE);
2137
xf86SetPriority(FALSE);
2139
for (i = 0; i < num; i++)
2141
if (i != knownclkindex)
2143
if (pScrn->clock[i] == -1)
2145
pScrn->clock[i] = 0;
2149
pScrn->clock[i] = (int)(0.5 +
2150
(((float)knownclkvalue) * pScrn->clock[knownclkindex]) /
2152
/* Round to nearest 10KHz */
2153
pScrn->clock[i] += 5;
2154
pScrn->clock[i] /= 10;
2155
pScrn->clock[i] *= 10;
2160
pScrn->clock[knownclkindex] = knownclkvalue;
2161
pScrn->numClocks = num;
2163
/* Restore registers that were written on */
2164
(*ClockFunc)(pScrn, CLK_REG_RESTORE);
2168
xf86SetPriority(Bool up)
2170
static int saved_nice;
2173
#ifdef HAS_SETPRIORITY
2174
saved_nice = getpriority(PRIO_PROCESS, 0);
2175
setpriority(PRIO_PROCESS, 0, -20);
2177
#if defined(SYSV) || defined(SVR4) || defined(linux)
2178
saved_nice = nice(0);
2179
nice(-20 - saved_nice);
2182
#ifdef HAS_SETPRIORITY
2183
setpriority(PRIO_PROCESS, 0, saved_nice);
2185
#if defined(SYSV) || defined(SVR4) || defined(linux)
2186
nice(20 + saved_nice);
2192
xf86GetVisualName(int visual)
2194
if (visual < 0 || visual > DirectColor)
2197
return xf86VisualNames[visual];
2204
return max(xf86Verbose, xf86LogVerbose);
2210
return xf86Info.pixmap24;
2238
return xf86FlipPixels;
2245
return xf86ServerName;
2250
xf86ServerIsExiting()
2252
return (dispatchException & DE_TERMINATE) == DE_TERMINATE;
2257
xf86ServerIsResetting()
2259
return xf86Resetting;
2264
xf86ServerIsInitialising()
2266
return xf86Initialising;
2271
xf86ServerIsOnlyDetecting(void)
2273
return xf86DoProbe || xf86DoConfigure;
2278
xf86ServerIsOnlyProbing(void)
2280
return xf86ProbeOnly;
2287
return xf86Info.caughtSignal;
2292
xf86GetVidModeAllowNonLocal()
2294
return xf86Info.vidModeAllowNonLocal;
2299
xf86GetVidModeEnabled()
2301
return xf86Info.vidModeEnabled;
2305
xf86GetModInDevAllowNonLocal()
2307
return xf86Info.miscModInDevAllowNonLocal;
2312
xf86GetModInDevEnabled()
2314
return xf86Info.miscModInDevEnabled;
2319
xf86GetAllowMouseOpenFail()
2321
return xf86Info.allowMouseOpenFail;
2328
#if defined(i386) || defined(__i386__)
2329
return xf86Info.pc98;
2338
xf86Info.disableRandR = TRUE;
2339
xf86Info.randRFrom = X_PROBED;
2345
return XF86_VERSION_CURRENT;
2349
xf86GetModuleVersion(pointer module)
2351
#ifdef XFree86LOADER
2352
return (CARD32)LoaderGetModuleVersion(module);
2359
xf86LoadDrvSubModule(DriverPtr drv, const char *name)
2361
#ifdef XFree86LOADER
2363
int errmaj = 0, errmin = 0;
2365
ret = LoadSubModule(drv->module, name, NULL, NULL, NULL, NULL,
2368
LoaderErrorMsg(NULL, name, errmaj, errmin);
2376
xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name)
2378
#ifdef XFree86LOADER
2380
int errmaj = 0, errmin = 0;
2382
ret = LoadSubModule(pScrn->module, name, NULL, NULL, NULL, NULL,
2385
LoaderErrorMsg(pScrn->name, name, errmaj, errmin);
2393
* xf86LoadOneModule loads a single module.
2396
xf86LoadOneModule(char *name, pointer opt)
2398
#ifdef XFree86LOADER
2407
#ifndef NORMALISE_MODULE_NAME
2408
Name = xstrdup(name);
2410
/* Normalise the module name */
2411
Name = xf86NormalizeName(name);
2414
/* Skip empty names */
2417
if (*Name == '\0') {
2422
#ifdef XFree86LOADER
2423
mod = LoadModule(Name, NULL, NULL, NULL, opt, NULL, &errmaj, &errmin);
2425
LoaderErrorMsg(NULL, Name, errmaj, errmin);
2434
xf86UnloadSubModule(pointer mod)
2437
* This is disabled for now. The loader isn't smart enough yet to undo
2440
#if defined(XFree86LOADER) && 0
2441
UnloadSubModule(mod);
2446
xf86LoaderCheckSymbol(const char *name)
2448
#ifdef XFree86LOADER
2449
return LoaderSymbol(name) != NULL;
2456
xf86LoaderReqSymLists(const char **list0, ...)
2458
#ifdef XFree86LOADER
2461
va_start(ap, list0);
2462
LoaderVReqSymLists(list0, ap);
2468
xf86LoaderReqSymbols(const char *sym0, ...)
2470
#ifdef XFree86LOADER
2474
LoaderVReqSymbols(sym0, ap);
2480
xf86LoaderRefSymLists(const char **list0, ...)
2482
#ifdef XFree86LOADER
2485
va_start(ap, list0);
2486
LoaderVRefSymLists(list0, ap);
2492
xf86LoaderRefSymbols(const char *sym0, ...)
2494
#ifdef XFree86LOADER
2498
LoaderVRefSymbols(sym0, ap);
2505
OPTION_BACKING_STORE
2508
static const OptionInfoRec BSOptions[] = {
2509
{ OPTION_BACKING_STORE, "BackingStore", OPTV_BOOLEAN, {0}, FALSE },
2510
{ -1, NULL, OPTV_NONE, {0}, FALSE }
2514
xf86SetBackingStore(ScreenPtr pScreen)
2517
MessageType from = X_DEFAULT;
2518
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
2519
OptionInfoPtr options;
2521
options = xnfalloc(sizeof(BSOptions));
2522
(void)memcpy(options, BSOptions, sizeof(BSOptions));
2523
xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
2525
/* check for commandline option here */
2526
if (xf86bsEnableFlag) {
2529
} else if (xf86bsDisableFlag) {
2533
if (xf86GetOptValBool(options, OPTION_BACKING_STORE, &useBS))
2537
pScreen->backingStoreSupport = useBS ? Always : NotUseful;
2538
if (serverGeneration == 1)
2539
xf86DrvMsg(pScreen->myNum, from, "Backing store %s\n",
2540
useBS ? "enabled" : "disabled");
2548
static const OptionInfoRec SMOptions[] = {
2549
{ OPTION_SILKEN_MOUSE, "SilkenMouse", OPTV_BOOLEAN, {0}, FALSE },
2550
{ -1, NULL, OPTV_NONE, {0}, FALSE }
2554
xf86SetSilkenMouse (ScreenPtr pScreen)
2557
MessageType from = X_DEFAULT;
2558
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
2559
OptionInfoPtr options;
2561
options = xnfalloc(sizeof(SMOptions));
2562
(void)memcpy(options, SMOptions, sizeof(SMOptions));
2563
xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
2565
/* check for commandline option here */
2566
/* disable if screen shares resources */
2567
if (((pScrn->racMemFlags & RAC_CURSOR) &&
2568
!xf86NoSharedResources(pScrn->scrnIndex,MEM)) ||
2569
((pScrn->racIoFlags & RAC_CURSOR) &&
2570
!xf86NoSharedResources(pScrn->scrnIndex,IO))) {
2573
} else if (xf86silkenMouseDisableFlag) {
2577
if (xf86GetOptValBool(options, OPTION_SILKEN_MOUSE, &useSM))
2582
* XXX quick hack to report correctly for OSs that can't do SilkenMouse
2583
* yet. Should handle this differently so that alternate async methods
2584
* like Xqueue work correctly with this too.
2586
pScrn->silkenMouse = useSM && xf86SIGIOSupported();
2587
if (serverGeneration == 1)
2588
xf86DrvMsg(pScreen->myNum, from, "Silken mouse %s\n",
2589
pScrn->silkenMouse ? "enabled" : "disabled");
2592
/* Wrote this function for the PM2 Xv driver, preliminary. */
2595
xf86FindXvOptions(int scrnIndex, int adaptor_index, char *port_name,
2596
char **adaptor_name, pointer *adaptor_options)
2598
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
2599
confXvAdaptorPtr adaptor;
2602
if (adaptor_index >= pScrn->confScreen->numxvadaptors) {
2603
if (adaptor_name) *adaptor_name = NULL;
2604
if (adaptor_options) *adaptor_options = NULL;
2608
adaptor = &pScrn->confScreen->xvadaptors[adaptor_index];
2609
if (adaptor_name) *adaptor_name = adaptor->identifier;
2610
if (adaptor_options) *adaptor_options = adaptor->options;
2612
for (i = 0; i < adaptor->numports; i++)
2613
if (!xf86NameCmp(adaptor->ports[i].identifier, port_name))
2614
return adaptor->ports[i].options;
2619
/* Rather than duplicate loader's get OS function, just include it directly */
2620
#define LoaderGetOS xf86GetOS
2621
#include "loader/os.c"
2625
* xf86ConfigIsa/PciEntity() -- These helper functions assign an
2626
* active entity to a screen, registers its fixed resources, assign
2627
* special enter/leave functions and their private scratch area to
2628
* this entity, take the dog for a walk...
2631
xf86ConfigIsaEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex,
2632
IsaChipsets *i_chip, resList res, EntityProc init,
2633
EntityProc enter, EntityProc leave, pointer private)
2636
EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
2637
if (!pEnt) return pScrn;
2639
if (!(pEnt->location.type == BUS_ISA)) {
2644
if (!pEnt->active) {
2645
xf86ConfigIsaEntityInactive(pEnt, i_chip, res, init, enter,
2651
pScrn = xf86AllocateScreen(pEnt->driver,scrnFlag);
2652
xf86AddEntityToScreen(pScrn,entityIndex);
2655
for (i_id = i_chip; i_id->numChipset != -1; i_id++) {
2656
if (pEnt->chipset == i_id->numChipset) break;
2658
xf86ClaimFixedResources(i_id->resList,entityIndex);
2661
xf86ClaimFixedResources(res,entityIndex);
2662
xf86SetEntityFuncs(entityIndex,init,enter,leave,private);
2668
xf86ConfigPciEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex,
2669
PciChipsets *p_chip, resList res, EntityProc init,
2670
EntityProc enter, EntityProc leave, pointer private)
2673
EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
2674
if (!pEnt) return pScrn;
2676
if (!(pEnt->location.type == BUS_PCI)
2677
|| !xf86GetPciInfoForEntity(entityIndex)) {
2681
if (!pEnt->active) {
2682
xf86ConfigPciEntityInactive(pEnt, p_chip, res, init, enter,
2688
pScrn = xf86AllocateScreen(pEnt->driver,scrnFlag);
2689
if (xf86IsEntitySharable(entityIndex)) {
2690
xf86SetEntityShared(entityIndex);
2692
xf86AddEntityToScreen(pScrn,entityIndex);
2693
if (xf86IsEntityShared(entityIndex)) {
2697
for (p_id = p_chip; p_id->numChipset != -1; p_id++) {
2698
if (pEnt->chipset == p_id->numChipset) break;
2700
xf86ClaimFixedResources(p_id->resList,entityIndex);
2704
xf86ClaimFixedResources(res,entityIndex);
2705
xf86SetEntityFuncs(entityIndex,init,enter,leave,private);
2711
xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex,
2712
EntityProc init, EntityProc enter, EntityProc leave,
2715
EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
2716
if (!pEnt) return pScrn;
2718
if (!(pEnt->location.type == BUS_NONE)) {
2723
if (!pEnt->active) {
2724
xf86ConfigFbEntityInactive(pEnt, init, enter, leave, private);
2729
pScrn = xf86AllocateScreen(pEnt->driver,scrnFlag);
2730
xf86AddEntityToScreen(pScrn,entityIndex);
2732
xf86SetEntityFuncs(entityIndex,init,enter,leave,private);
2739
* OBSOLETE ! xf86ConfigActiveIsaEntity() and xf86ConfigActivePciEntity()
2740
* are obsolete functions. They the are likely to be removed
2744
xf86ConfigActiveIsaEntity(ScrnInfoPtr pScrn, int entityIndex,
2745
IsaChipsets *i_chip, resList res, EntityProc init,
2746
EntityProc enter, EntityProc leave, pointer private)
2749
EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
2750
if (!pEnt) return FALSE;
2752
if (!pEnt->active || !(pEnt->location.type == BUS_ISA)) {
2757
xf86AddEntityToScreen(pScrn,entityIndex);
2760
for (i_id = i_chip; i_id->numChipset != -1; i_id++) {
2761
if (pEnt->chipset == i_id->numChipset) break;
2763
xf86ClaimFixedResources(i_id->resList,entityIndex);
2766
xf86ClaimFixedResources(res,entityIndex);
2767
if (!xf86SetEntityFuncs(entityIndex,init,enter,leave,private))
2774
xf86ConfigActivePciEntity(ScrnInfoPtr pScrn, int entityIndex,
2775
PciChipsets *p_chip, resList res, EntityProc init,
2776
EntityProc enter, EntityProc leave, pointer private)
2779
EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
2780
if (!pEnt) return FALSE;
2782
if (!pEnt->active || !(pEnt->location.type == BUS_PCI)) {
2786
xf86AddEntityToScreen(pScrn,entityIndex);
2789
for (p_id = p_chip; p_id->numChipset != -1; p_id++) {
2790
if (pEnt->chipset == p_id->numChipset) break;
2792
xf86ClaimFixedResources(p_id->resList,entityIndex);
2796
xf86ClaimFixedResources(res,entityIndex);
2797
if (!xf86SetEntityFuncs(entityIndex,init,enter,leave,private))
2804
* xf86ConfigPci/IsaEntityInactive() -- These functions can be used
2805
* to configure an inactive entity as well as to reconfigure an
2806
* previously active entity inactive. If the entity has been
2807
* assigned to a screen before it will be removed. If p_pci(p_isa) is
2808
* non-NULL all static resources listed there will be registered.
2811
xf86ConfigPciEntityInactive(EntityInfoPtr pEnt, PciChipsets *p_chip,
2812
resList res, EntityProc init, EntityProc enter,
2813
EntityProc leave, pointer private)
2818
if ((pScrn = xf86FindScreenForEntity(pEnt->index)))
2819
xf86RemoveEntityFromScreen(pScrn,pEnt->index);
2821
for (p_id = p_chip; p_id->numChipset != -1; p_id++) {
2822
if (pEnt->chipset == p_id->numChipset) break;
2824
xf86ClaimFixedResources(p_id->resList,pEnt->index);
2826
xf86ClaimFixedResources(res,pEnt->index);
2827
/* shared resources are only needed when entity is active: remove */
2828
xf86DeallocateResourcesForEntity(pEnt->index, ResShared);
2829
xf86SetEntityFuncs(pEnt->index,init,enter,leave,private);
2833
xf86ConfigIsaEntityInactive(EntityInfoPtr pEnt, IsaChipsets *i_chip,
2834
resList res, EntityProc init, EntityProc enter,
2835
EntityProc leave, pointer private)
2840
if ((pScrn = xf86FindScreenForEntity(pEnt->index)))
2841
xf86RemoveEntityFromScreen(pScrn,pEnt->index);
2843
for (i_id = i_chip; i_id->numChipset != -1; i_id++) {
2844
if (pEnt->chipset == i_id->numChipset) break;
2846
xf86ClaimFixedResources(i_id->resList,pEnt->index);
2848
xf86ClaimFixedResources(res,pEnt->index);
2849
/* shared resources are only needed when entity is active: remove */
2850
xf86DeallocateResourcesForEntity(pEnt->index, ResShared);
2851
xf86SetEntityFuncs(pEnt->index,init,enter,leave,private);
2855
xf86ConfigFbEntityInactive(EntityInfoPtr pEnt, EntityProc init,
2856
EntityProc enter, EntityProc leave, pointer private)
2860
if ((pScrn = xf86FindScreenForEntity(pEnt->index)))
2861
xf86RemoveEntityFromScreen(pScrn,pEnt->index);
2862
xf86SetEntityFuncs(pEnt->index,init,enter,leave,private);
2866
xf86IsScreenPrimary(int scrnIndex)
2868
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
2871
for (i=0 ; i < pScrn->numEntities; i++) {
2872
if (xf86IsEntityPrimary(i))
2879
xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type,
2880
int format, unsigned long len, pointer value )
2882
RootWinPropPtr pNewProp = NULL, pRegProp;
2884
Bool existing = FALSE;
2887
ErrorF("xf86RegisterRootWindowProperty(%d, %ld, %ld, %d, %ld, %p)\n",
2888
ScrnIndex, property, type, format, len, value);
2891
if (ScrnIndex<0 || ScrnIndex>=xf86NumScreens) {
2895
if (xf86RegisteredPropertiesTable &&
2896
xf86RegisteredPropertiesTable[ScrnIndex]) {
2897
for (pNewProp = xf86RegisteredPropertiesTable[ScrnIndex];
2898
pNewProp; pNewProp = pNewProp->next) {
2899
if (strcmp(pNewProp->name, NameForAtom(property)) == 0)
2905
if ((pNewProp = (RootWinPropPtr)xalloc(sizeof(RootWinProp))) == NULL) {
2909
* We will put this property at the end of the list so that
2910
* the changes are made in the order they were requested.
2912
pNewProp->next = NULL;
2915
xfree(pNewProp->name);
2919
pNewProp->name = xnfstrdup(NameForAtom(property));
2920
pNewProp->type = type;
2921
pNewProp->format = format;
2922
pNewProp->size = len;
2923
pNewProp->data = value;
2926
ErrorF("new property filled\n");
2929
if (NULL==xf86RegisteredPropertiesTable) {
2931
ErrorF("creating xf86RegisteredPropertiesTable[] size %d\n",
2934
if ( NULL==(xf86RegisteredPropertiesTable=(RootWinPropPtr*)xnfcalloc(sizeof(RootWinProp),xf86NumScreens) )) {
2937
for (i=0; i<xf86NumScreens; i++) {
2938
xf86RegisteredPropertiesTable[i] = NULL;
2943
ErrorF("xf86RegisteredPropertiesTable %p\n",
2944
(void *)xf86RegisteredPropertiesTable);
2945
ErrorF("xf86RegisteredPropertiesTable[%d] %p\n",
2946
ScrnIndex, (void *)xf86RegisteredPropertiesTable[ScrnIndex]);
2950
if ( xf86RegisteredPropertiesTable[ScrnIndex] == NULL) {
2951
xf86RegisteredPropertiesTable[ScrnIndex] = pNewProp;
2953
pRegProp = xf86RegisteredPropertiesTable[ScrnIndex];
2954
while (pRegProp->next != NULL) {
2956
ErrorF("- next %p\n", (void *)pRegProp);
2958
pRegProp = pRegProp->next;
2960
pRegProp->next = pNewProp;
2964
ErrorF("xf86RegisterRootWindowProperty succeeded\n");
2970
xf86IsUnblank(int mode)
2973
case SCREEN_SAVER_OFF:
2974
case SCREEN_SAVER_FORCER:
2976
case SCREEN_SAVER_ON:
2977
case SCREEN_SAVER_CYCLE:
2980
xf86MsgVerb(X_WARNING, 0, "Unexpected save screen mode: %d\n", mode);