(file) Return to xf86Helper.c CVS log (file) (dir) Up to [XFree86 CVS] / xc / programs / Xserver / hw / xfree86 / common

   1 dawes 1.19 /* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Helper.c,v 1.18 1999/01/13 03:19:36 dawes Exp $ */
   2 dawes 1.2  
   3            /*
   4             * Copyright (c) 1997-1998 by The XFree86 Project, Inc.
   5             *
   6             * Authors: Dirk Hohndel <hohndel@XFree86.Org>
   7             *          David Dawes <dawes@XFree86.Org>
   8             *
   9             * This file includes the helper functions that the server provides for
  10             * different drivers.
  11             */
  12            
  13            #include "X.h"
  14            #include "os.h"
  15            #include "servermd.h"
  16            #include "pixmapstr.h"
  17            #include "windowstr.h"
  18            #include "gcstruct.h"
  19 dawes 1.8  #include "loaderProcs.h"
  20 dawes 1.2  #include "xf86.h"
  21            #include "xf86Priv.h"
  22            #include "xf86_OSlib.h"
  23            #include "micmap.h"
  24 dawes 1.9  #include "xf86PciInfo.h"
  25 dawes 1.2  
  26            /* For xf86GetClocks */
  27            #if defined(CSRG_BASED) || defined(MACH386)
  28            #include <sys/resource.h>
  29            #endif
  30            
  31            extern WindowPtr *WindowTable;
  32            
  33            static int xf86ScrnInfoPrivateCount = 0;
  34            
  35            
  36            #ifdef XFree86LOADER
  37            /* Add a pointer to a new DriverRec to xf86DriverList */
  38            
  39            void
  40            xf86AddDriver(DriverPtr driver, pointer module, int flags)
  41            {
  42                /* Don't add null entries */
  43                if (!driver)
  44            	return;
  45            
  46 dawes 1.2      if (xf86DriverList == NULL)
  47            	xf86NumDrivers = 0;
  48            
  49                xf86NumDrivers++;
  50 dawes 1.17     xf86DriverList = xnfrealloc(xf86DriverList,
  51            				xf86NumDrivers * sizeof(DriverPtr));
  52                xf86DriverList[xf86NumDrivers - 1] = xnfalloc(sizeof(DriverRec));
  53 dawes 1.2      *xf86DriverList[xf86NumDrivers - 1] = *driver;
  54                xf86DriverList[xf86NumDrivers - 1]->module = module;
  55                xf86DriverList[xf86NumDrivers - 1]->refCount = 0;
  56            }
  57            
  58            void
  59            xf86DeleteDriver(int drvIndex)
  60            {
  61                if (xf86DriverList[drvIndex] && xf86DriverList[drvIndex]->module)
  62            	UnloadModule(xf86DriverList[drvIndex]->module);
  63                xf86DriverList[drvIndex] = NULL;
  64            }
  65            #endif
  66            
  67            
  68            /* Allocate a new ScrnInfoRec in xf86Screens */
  69            
  70            ScrnInfoPtr
  71            xf86AllocateScreen(DriverPtr drv, int flags)
  72            {
  73                int i;
  74 dawes 1.2  
  75                if (xf86Screens == NULL)
  76            	xf86NumScreens = 0;
  77            
  78                i = xf86NumScreens++;
  79 dawes 1.17     xf86Screens = xnfrealloc(xf86Screens, xf86NumScreens * sizeof(ScrnInfoPtr));
  80                xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1);
  81 dawes 1.2      xf86Screens[i]->scrnIndex = i;	/* Changes when a screen is removed */
  82                xf86Screens[i]->origIndex = i;	/* This never changes */
  83 dawes 1.17     xf86Screens[i]->privates = xnfcalloc(sizeof(DevUnion),
  84            					 xf86ScrnInfoPrivateCount);
  85 dawes 1.2      xf86Screens[i]->drv = drv;
  86                drv->refCount++;
  87            #ifdef XFree86LOADER
  88                xf86Screens[i]->module = DuplicateModule(drv->module);
  89            #else
  90                xf86Screens[i]->module = NULL;
  91            #endif
  92                return xf86Screens[i];
  93            }
  94            
  95            
  96            /*
  97             * Remove an entry from xf86Screens.  Ideally it should free all allocated
  98             * data.  To do this properly may require a driver hook.
  99             */
 100            
 101            void
 102            xf86DeleteScreen(int scrnIndex, int flags)
 103            {
 104                int i;
 105            
 106 dawes 1.2      /* First check if the screen is valid */
 107                if (xf86NumScreens == 0 || xf86Screens == NULL)
 108            	return;
 109            
 110                if (scrnIndex > xf86NumScreens - 1)
 111            	return;
 112            
 113                if (xf86Screens[scrnIndex] == NULL)
 114            	return;
 115            
 116                /* If a FreeScreen function is defined, call it here */
 117                if (xf86Screens[scrnIndex]->FreeScreen != NULL)
 118            	xf86Screens[scrnIndex]->FreeScreen(scrnIndex, 0);
 119            
 120            #ifdef XFree86LOADER
 121                if (xf86Screens[scrnIndex]->module)
 122            	UnloadModule(xf86Screens[scrnIndex]->module);
 123            #endif
 124            
 125                if (xf86Screens[scrnIndex]->drv)
 126            	xf86Screens[scrnIndex]->drv->refCount--;
 127 dawes 1.2  
 128                if (xf86Screens[scrnIndex]->privates);
 129            	xfree(xf86Screens[scrnIndex]->privates);
 130            
 131                xfree(xf86Screens[scrnIndex]);
 132            
 133                /* Move the other entries down, updating their scrnIndex fields */
 134                
 135                xf86NumScreens--;
 136            
 137 dawes 1.5      xf86DeleteBusSlotsForScreen(scrnIndex);
 138 dawes 1.2      for (i = scrnIndex; i < xf86NumScreens; i++) {
 139            	xf86Screens[i] = xf86Screens[i + 1];
 140            	xf86Screens[i]->scrnIndex = i;
 141            	xf86ChangeBusIndex(i + 1, i);
 142            	/* Also need to take care of the screen layout settings */
 143                }
 144            }
 145            
 146            /*
 147             * Allocate a private in ScrnInfoRec.
 148             */
 149            
 150            int
 151            xf86AllocateScrnInfoPrivateIndex(void)
 152            {
 153                int idx, i;
 154                ScrnInfoPtr pScr;
 155                DevUnion *nprivs;
 156            
 157                idx = xf86ScrnInfoPrivateCount++;
 158                for (i = 0; i < xf86NumScreens; i++) {
 159 dawes 1.2  	pScr = xf86Screens[i];
 160 dawes 1.17 	nprivs = xnfrealloc(pScr->privates,
 161            			    xf86ScrnInfoPrivateCount * sizeof(DevUnion));
 162 dawes 1.3  	/* Zero the new private */
 163            	bzero(&nprivs[idx], sizeof(DevUnion));
 164 dawes 1.2  	pScr->privates = nprivs;
 165                }
 166                return idx;
 167            }
 168            
 169 dawes 1.18 Bool
 170            xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad)
 171            {
 172                int i;
 173            
 174                if (pScrn->numFormats >= MAXFORMATS)
 175            	return FALSE;
 176            
 177                if (bpp <= 0) {
 178            	if (depth == 1)
 179            	    bpp = 1;
 180            	else if (depth <= 8)
 181            	    bpp = 8;
 182            	else if (depth <= 16)
 183            	    bpp = 16;
 184            	else if (depth <= 32)
 185            	    bpp = 32;
 186            	else
 187            	    return FALSE;
 188                }
 189                if (pad <= 0)
 190 dawes 1.18 	pad = BITMAP_SCANLINE_PAD;
 191            
 192                i = pScrn->numFormats++;
 193                pScrn->formats[i].depth = depth;
 194                pScrn->formats[i].bitsPerPixel = bpp;
 195                pScrn->formats[i].scanlinePad = pad;
 196                return TRUE;
 197            }
 198            
 199 dawes 1.2  /*
 200             * Set the depth we are using based on (in the following order of preference):
 201             *  - values given on the command line
 202             *  - values given in the config file
 203             *  - values provided by the driver
 204             *  - an overall default when nothing else is given
 205             *
 206             * Also find a Display subsection matching the depth/bpp found.
 207             *
 208             * Sets the following ScrnInfoRec fields:
 209 dawes 1.19  *     bitsPerPixel, pixmap24, depth, display, imageByteOrder,
 210 dawes 1.2   *     bitmapScanlinePad, bitmapScanlineUnit, bitmapBitOrder, numFormats,
 211             *     formats, fbFormat.
 212             */
 213            
 214 dawes 1.18 /* Can the screen handle 24 bpp pixmaps */
 215            #define DO_PIX24(f) ((f & Support24bppFb) || \
 216            		     ((f & Support32bppFb) && (f & SupportConvert24to32)))
 217            
 218            /* Can the screen handle 32 bpp pixmaps */
 219            #define DO_PIX32(f) ((f & Support32bppFb) || \
 220            		     ((f & Support24bppFb) && (f & SupportConvert32to24)))
 221            
 222            /* Does the screen prefer 32bpp fb for 24bpp pixmaps */
 223            #define CHOOSE32FOR24(f) ((f & Support32bppFb) && (f & SupportConvert24to32) \
 224            			  && (f & PreferConvert24to32))
 225            
 226            /* Does the screen prefer 24bpp fb for 32bpp pixmaps */
 227            #define CHOOSE24FOR32(f) ((f & Support24bppFb) && (f & SupportConvert32to24) \
 228            			  && (f & PreferConvert32to24))
 229            
 230            /* Can the screen handle 32bpp pixmaps for 24bpp fb */
 231            #define DO_PIX32FOR24(f) ((f & Support24bppFb) && (f & SupportConvert32to24))
 232            
 233            /* Can the screen handle 24bpp pixmaps for 32bpp fb */
 234            #define DO_PIX24FOR32(f) ((f & Support32bppFb) && (f & SupportConvert24to32))
 235 dawes 1.18 
 236            Bool
 237            xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp,
 238            		int depth24flags)
 239            {
 240                int i;
 241                DispPtr disp;
 242                Pix24Flags pix24 = Pix24DontCare;
 243                Bool nomatch = FALSE;
 244            
 245                scrp->bitsPerPixel = -1;
 246                scrp->depth = -1;
 247                scrp->pixmap24 = Pix24DontCare;
 248                scrp->bitsPerPixelFrom = X_DEFAULT;
 249                scrp->pixmapBPPFrom = X_DEFAULT;
 250                scrp->depthFrom = X_DEFAULT;
 251            
 252                if (xf86Pix24 != Pix24DontCare) {
 253            	pix24 = xf86Pix24;
 254            	scrp->pixmapBPPFrom = X_CMDLINE;
 255                }
 256 dawes 1.18 
 257                if (xf86FbBpp > 0) {
 258            	scrp->bitsPerPixel = xf86FbBpp;
 259            	scrp->bitsPerPixelFrom = X_CMDLINE;
 260                }
 261            
 262                if (xf86Depth > 0) {
 263            	scrp->depth = xf86Depth;
 264            	scrp->depthFrom = X_CMDLINE;
 265                }
 266            
 267                /* If user doesn't override from commandline, probe the config file */
 268            
 269                if (xf86Pix24 == Pix24DontCare && xf86ConfigPix24 != Pix24DontCare) {
 270            	pix24 = xf86ConfigPix24;
 271            	scrp->pixmapBPPFrom = X_CONFIG;
 272                }
 273            
 274                if (xf86FbBpp < 0 && xf86Depth < 0) {
 275            	if (scrp->confScreen->defaultfbbpp > 0) {
 276            	    scrp->bitsPerPixel = scrp->confScreen->defaultfbbpp;
 277 dawes 1.18 	    scrp->bitsPerPixelFrom = X_CONFIG;
 278            	}
 279            	if (scrp->confScreen->defaultdepth > 0) {
 280            	    scrp->depth = scrp->confScreen->defaultdepth;
 281            	    scrp->depthFrom = X_CONFIG;
 282            	}
 283                }
 284            
 285                /* If none of these is set, pick a default */
 286                if (scrp->bitsPerPixel < 0 && scrp->depth < 0) {
 287                    if (fbbpp > 0 || depth > 0) {
 288            	    if (fbbpp > 0)
 289            		scrp->bitsPerPixel = fbbpp;
 290            	    if (depth > 0)
 291            		scrp->depth = depth;
 292            	} else {
 293            	    scrp->bitsPerPixel = 8;
 294            	    scrp->depth = 8;
 295            	}
 296                }
 297            
 298 dawes 1.18     /* If any are not given, determine a default for the others */
 299            
 300                if (scrp->bitsPerPixel < 0) {
 301            	/* The depth must be set */
 302            	if (scrp->depth > -1) {
 303            	    if (scrp->depth == 1)
 304            		scrp->bitsPerPixel = 1;
 305            	    else if (scrp->depth <= 8)
 306            		scrp->bitsPerPixel = 8;
 307            	    else if (scrp->depth <= 16)
 308            		scrp->bitsPerPixel = 16;
 309            	    else if (scrp->depth <= 24) {
 310            		/*
 311            		 * Figure out if a choice is possible based on the depth24
 312            		 * and pix24 flags.
 313            		 */
 314            		/* Check pix24 first */
 315            		if (pix24 != Pix24DontCare) {
 316            		    if (pix24 == Pix24Use32)
 317            			if (DO_PIX32(depth24flags)) {
 318            			    if (CHOOSE24FOR32(depth24flags))
 319 dawes 1.18 				scrp->bitsPerPixel = 24;
 320            			    else
 321            				scrp->bitsPerPixel = 32;
 322            			} else {
 323            			    nomatch = TRUE;
 324            			}
 325            		    else if (pix24 == Pix24Use24)
 326            			if (DO_PIX24(depth24flags)) {
 327            			    if (CHOOSE32FOR24(depth24flags))
 328            				scrp->bitsPerPixel = 32;
 329            			    else
 330            				scrp->bitsPerPixel = 24;
 331            			} else {
 332            			    nomatch = TRUE;
 333            			}
 334            		} else {
 335            		    if (DO_PIX32(depth24flags)) {
 336            			if (CHOOSE24FOR32(depth24flags))
 337            			    scrp->bitsPerPixel = 24;
 338            			else
 339            			    scrp->bitsPerPixel = 32;
 340 dawes 1.18 		    } else if (DO_PIX24(depth24flags)) {
 341            			if (CHOOSE32FOR24(depth24flags))
 342            			    scrp->bitsPerPixel = 32;
 343            			else
 344            			    scrp->bitsPerPixel = 24;
 345            		    }
 346            		}
 347            	    } else if (scrp->depth <= 32)
 348            		scrp->bitsPerPixel = 32;
 349            	    else {
 350            		xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 351            			   "Specified depth (%d) is greater than 32\n",
 352            			   scrp->depth);
 353            		return FALSE;
 354            	    }
 355            	} else {
 356            	    xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 357            			"xf86SetDepthBpp: internal error: depth and fbbpp"
 358            			" are both not set\n");
 359            	    return FALSE;
 360            	}
 361 dawes 1.18 	if (scrp->bitsPerPixel < 0) {
 362            	    if (nomatch)
 363            		xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 364            			"Driver can't support depth 24 pixmap format (%d)\n",
 365            			PIX24TOBPP(pix24));
 366            	    else
 367            		xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 368            			"Can't find fbbpp for depth 24\n");
 369            	    return FALSE;
 370            	}
 371            	scrp->bitsPerPixelFrom = X_PROBED;
 372                }
 373            
 374                if (scrp->depth <= 0) {
 375            	/* bitsPerPixel is already set */
 376            	switch (scrp->bitsPerPixel) {
 377            	case 32:
 378            	    scrp->depth = 24;
 379            	    break;
 380            	default:
 381            	    /* 1, 4, 8, 16 and 24 */
 382 dawes 1.18 	    scrp->depth = scrp->bitsPerPixel;
 383            	    break;
 384            	}
 385            	scrp->depthFrom = X_PROBED;
 386                }
 387            
 388                /* Sanity checks */
 389                if (scrp->depth < 1 || scrp->depth > 32) {
 390            	xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 391            		   "Specified depth (%d) is not in the range 1-32\n",
 392            		    scrp->depth);
 393            	return FALSE;
 394                }
 395                switch (scrp->bitsPerPixel) {
 396                case 1:
 397                case 4:
 398                case 8:
 399                case 16:
 400                case 24:
 401                case 32:
 402            	break;
 403 dawes 1.18     default:
 404            	xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 405            		   "Specified fbbpp (%d) is not a permitted value\n",
 406            		   scrp->bitsPerPixel);
 407            	return FALSE;
 408                }
 409                if (scrp->depth > scrp->bitsPerPixel) {
 410            	xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 411            		   "Specified depth (%d) is greater than the fbbpp (%d)\n",
 412            		   scrp->depth, scrp->bitsPerPixel);
 413            	return FALSE;
 414                }
 415            
 416                /* set scrp->pixmap24 if the driver isn't flexible */
 417                if (scrp->bitsPerPixel == 24 && !DO_PIX32FOR24(depth24flags)) {
 418            	scrp->pixmap24 = Pix24Use24;
 419            	scrp->pixmapBPPFrom = X_PROBED;
 420                }
 421                if (scrp->bitsPerPixel == 32 && !DO_PIX24FOR32(depth24flags)) {
 422            	scrp->pixmap24 = Pix24Use32;
 423            	scrp->pixmapBPPFrom = X_PROBED;
 424 dawes 1.18     }
 425            
 426                /*
 427                 * Find the Display subsection matching the depth/fbbpp and initialise
 428                 * scrp->display with it.
 429                 */
 430                for (i = 0, disp = scrp->confScreen->displays;
 431            	 i < scrp->confScreen->numdisplays; i++, disp++) {
 432            	if ((disp->depth == scrp->depth && disp->fbbpp == scrp->bitsPerPixel)
 433            	    || (disp->depth == scrp->depth && disp->fbbpp <= 0)
 434            	    || (disp->fbbpp == scrp->bitsPerPixel && disp->depth <= 0)) {
 435            	    scrp->display = disp;
 436            	    break;
 437            	}
 438                }
 439                if (i == scrp->confScreen->numdisplays) {
 440            	xf86DrvMsg(scrp->scrnIndex, X_ERROR, "No Display subsection "
 441            		   "in Screen section \"%s\" for depth/fbbpp %d/%d\n",
 442            		   scrp->confScreen->id, scrp->depth, scrp->bitsPerPixel);
 443            	return FALSE;
 444                }
 445 dawes 1.18 
 446                /*
 447                 * Setup defaults for the display-wide attributes the framebuffer will
 448                 * need.  These defaults should eventually be set globally, and not
 449                 * dependent on the screens.
 450                 */
 451                scrp->imageByteOrder = IMAGE_BYTE_ORDER;
 452                scrp->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
 453                if (scrp->depth < 8) {
 454            	/* Planar modes need these settings */
 455            	scrp->bitmapScanlineUnit = 8;
 456            	scrp->bitmapBitOrder = MSBFirst;
 457                } else {
 458            	scrp->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
 459            	scrp->bitmapBitOrder = BITMAP_BIT_ORDER;
 460                }
 461            
 462                /*
 463                 * If an unusual depth is required, add it to scrp->formats.  The formats
 464                 * for the common depths are handled globally in InitOutput
 465                 */
 466 dawes 1.18     switch (scrp->depth) {
 467                case 1:
 468                case 4:
 469                case 8:
 470                case 15:
 471                case 16:
 472                case 24:
 473            	/* Common depths.  Nothing to do for them */
 474            	break;
 475                default:
 476            	if (!xf86AddPixFormat(scrp, scrp->depth, 0, 0)) {
 477            	    xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 478            		       "Can't add pixmap format for depth %d\n", scrp->depth);
 479            	    return FALSE;
 480            	}
 481                }
 482            
 483                /* Initialise the framebuffer format for this screen */
 484                scrp->fbFormat.depth = scrp->depth;
 485                scrp->fbFormat.bitsPerPixel = scrp->bitsPerPixel;
 486                scrp->fbFormat.scanlinePad = BITMAP_SCANLINE_PAD;
 487 dawes 1.18 
 488                return TRUE;
 489            }
 490            
 491 dawes 1.2  /*
 492             * Print out the selected depth and bpp.
 493             */
 494            void
 495            xf86PrintDepthBpp(ScrnInfoPtr scrp)
 496            {
 497                xf86DrvMsg(scrp->scrnIndex, scrp->depthFrom, "Depth %d, ", scrp->depth);
 498 dawes 1.18     xf86Msg(scrp->bitsPerPixelFrom, "framebuffer bpp %d\n", scrp->bitsPerPixel);
 499 dawes 1.2  }
 500            
 501            /*
 502             * xf86SetWeight sets scrp->weight, scrp->mask, scrp->offset, and for depths
 503             * greater than MAX_PSEUDO_DEPTH also scrp->rgbBits.
 504             */
 505            Bool
 506            xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask)
 507            {
 508                MessageType weightFrom = X_DEFAULT;
 509            
 510                scrp->weight.red = 0;
 511                scrp->weight.green = 0;
 512                scrp->weight.blue = 0;
 513            
 514                if (xf86Weight.red > 0 && xf86Weight.green > 0 && xf86Weight.blue > 0) {
 515            	scrp->weight = xf86Weight;
 516            	weightFrom = X_CMDLINE;
 517                } else if (scrp->display->weight.red > 0 && scrp->display->weight.green > 0
 518            	       && scrp->display->weight.blue > 0) {
 519            	scrp->weight = scrp->display->weight;
 520 dawes 1.2  	weightFrom = X_CONFIG;
 521                } else if (weight.red > 0 && weight.green > 0 && weight.blue > 0) {
 522            	scrp->weight = weight;
 523                } else {
 524            	switch (scrp->depth) {
 525            	case 1:
 526            	case 4:
 527            	case 8:
 528            	    scrp->weight.red = scrp->weight.green = scrp->weight.blue = 6;
 529            	    break;
 530            	case 15:
 531            	    scrp->weight.red = scrp->weight.green = scrp->weight.blue = 5;
 532            	    break;
 533            	case 16:
 534            	    scrp->weight.red = scrp->weight.blue = 5;
 535            	    scrp->weight.green = 6;
 536            	    break;
 537            	case 24:
 538            	    scrp->weight.red = scrp->weight.green = scrp->weight.blue = 8;
 539 dawes 1.3  	    break;
 540            	case 30:
 541            	    scrp->weight.red = scrp->weight.green = scrp->weight.blue = 10;
 542 dawes 1.2  	    break;
 543            	}
 544                }
 545            
 546                if (scrp->weight.red)
 547            	xf86DrvMsg(scrp->scrnIndex, weightFrom, "RGB weight %d%d%d\n",
 548            		   scrp->weight.red, scrp->weight.green, scrp->weight.blue);
 549            
 550                if (scrp->depth > MAX_PSEUDO_DEPTH &&
 551            	(scrp->depth != scrp->weight.red + scrp->weight.green +
 552            			scrp->weight.blue)) {
 553            	xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 554            		   "Weight given (%d%d%d) is inconsistent with the "
 555            		   "depth (%d)\n", scrp->weight.red, scrp->weight.green,
 556            		   scrp->weight.blue, scrp->depth);
 557            	return FALSE;
 558                }
 559                if (scrp->depth > MAX_PSEUDO_DEPTH && scrp->weight.red) {
 560            	/*
 561            	 * XXX Does this even mean anything for TrueColor visuals?
 562            	 * If not, we shouldn't even be setting it here.  However, this
 563 dawes 1.2  	 * matches the behaviour of 3.x versions of XFree86.
 564            	 */
 565            	scrp->rgbBits = scrp->weight.red;
 566            	if (scrp->weight.green > scrp->rgbBits)
 567            	    scrp->rgbBits = scrp->weight.green;
 568            	if (scrp->weight.blue > scrp->rgbBits)
 569            	    scrp->rgbBits = scrp->weight.blue;
 570                }
 571            
 572                /* Set the mask and offsets */
 573                if (mask.red == 0 || mask.green == 0 || mask.blue == 0) {
 574            	/* Default to a setting common to PC hardware */
 575            	scrp->offset.red = scrp->weight.green + scrp->weight.blue;
 576            	scrp->offset.green = scrp->weight.blue;
 577            	scrp->offset.blue = 0;
 578            	scrp->mask.red = ((1 << scrp->weight.red) - 1) << scrp->offset.red;
 579            	scrp->mask.green = ((1 << scrp->weight.green) - 1)
 580            				<< scrp->offset.green;
 581            	scrp->mask.blue = (1 << scrp->weight.blue) - 1;
 582                } else {
 583            	/* Initialise to the values passed */
 584 dawes 1.2  	scrp->mask.red = mask.red;
 585            	scrp->mask.green = mask.green;
 586            	scrp->mask.blue = mask.blue;
 587            	scrp->offset.red = ffs(mask.red);
 588            	scrp->offset.green = ffs(mask.green);
 589            	scrp->offset.blue = ffs(mask.blue);
 590                }
 591                return TRUE;
 592            }
 593            
 594            Bool
 595            xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual)
 596            {
 597                MessageType visualFrom = X_DEFAULT;
 598                Bool bad = FALSE;
 599            
 600                if (defaultColorVisualClass >= 0) {
 601            	scrp->defaultVisual = defaultColorVisualClass;
 602            	visualFrom = X_CMDLINE;
 603                } else if (scrp->display->defaultVisual >= 0) {
 604            	scrp->defaultVisual = scrp->display->defaultVisual;
 605 dawes 1.2  	visualFrom = X_CONFIG;
 606                } else if (visual >= 0) {
 607            	scrp->defaultVisual = visual;
 608                } else {
 609            	if (scrp->depth == 1)
 610            	    scrp->defaultVisual = StaticGray;
 611            	else if (scrp->depth == 4)
 612            	    scrp->defaultVisual = StaticColor;
 613            	else if (scrp->depth <= MAX_PSEUDO_DEPTH)
 614            	    scrp->defaultVisual = PseudoColor;
 615            	else
 616            	    scrp->defaultVisual = TrueColor;
 617                }
 618                switch (scrp->defaultVisual) {
 619                case StaticGray:
 620                case GrayScale:
 621                case StaticColor:
 622                case PseudoColor:
 623                case TrueColor:
 624                case DirectColor:
 625            	xf86DrvMsg(scrp->scrnIndex, visualFrom, "Default visual is %s\n",
 626 dawes 1.2  		   xf86VisualNames[scrp->defaultVisual]);
 627            	/* Check if the visual is valid for the depth */
 628            	if (scrp->depth == 1 && scrp->defaultVisual != StaticGray)
 629            	   bad = TRUE;
 630                    else if (scrp->depth == 4 &&
 631                             (scrp->defaultVisual == TrueColor ||
 632                              scrp->defaultVisual == DirectColor))
 633                       bad = TRUE;
 634                    else if (scrp->depth > MAX_PSEUDO_DEPTH &&
 635            		 scrp->defaultVisual != TrueColor &&
 636            		 scrp->defaultVisual != DirectColor)
 637            	   bad = TRUE;
 638            	if (bad) {
 639            	    xf86DrvMsg(scrp->scrnIndex, X_ERROR, "Selected default "
 640            		       "visual (%s) is not valid for depth %d\n",
 641            		       xf86VisualNames[scrp->defaultVisual], scrp->depth);
 642            	    return FALSE;
 643            	} else
 644            	    return TRUE;
 645                default:
 646            
 647 dawes 1.2  	xf86DrvMsg(scrp->scrnIndex, X_ERROR,
 648            		   "Invalid default visual class (%d)\n", scrp->defaultVisual);
 649            	return FALSE;
 650                }
 651            }
 652            
 653 dawes 1.11 #define TEST_GAMMA(g) \
 654            	(g).red > GAMMA_ZERO || (g).green > GAMMA_ZERO || (g).blue > GAMMA_ZERO
 655            
 656            #define SET_GAMMA(g) \
 657            	(g) > GAMMA_ZERO ? (g) : 1.0
 658 dawes 1.2  
 659            Bool
 660            xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma)
 661            {
 662                MessageType from = X_DEFAULT;
 663            
 664                if (TEST_GAMMA(xf86Gamma)) {
 665            	from = X_CMDLINE;
 666            	scrp->gamma.red = SET_GAMMA(xf86Gamma.red);
 667            	scrp->gamma.green = SET_GAMMA(xf86Gamma.green);
 668            	scrp->gamma.blue = SET_GAMMA(xf86Gamma.blue);
 669                } else if (TEST_GAMMA(scrp->monitor->gamma)) {
 670            	from = X_CONFIG;
 671            	scrp->gamma.red = SET_GAMMA(scrp->monitor->gamma.red);
 672            	scrp->gamma.green = SET_GAMMA(scrp->monitor->gamma.green);
 673            	scrp->gamma.blue = SET_GAMMA(scrp->monitor->gamma.blue);
 674                } else if (TEST_GAMMA(gamma)) {
 675            	scrp->gamma.red = SET_GAMMA(gamma.red);
 676            	scrp->gamma.green = SET_GAMMA(gamma.green);
 677            	scrp->gamma.blue = SET_GAMMA(gamma.blue);
 678                } else {
 679 dawes 1.2  	scrp->gamma.red = 1.0;
 680            	scrp->gamma.green = 1.0;
 681            	scrp->gamma.blue = 1.0;
 682                }
 683                xf86DrvMsg(scrp->scrnIndex, from,
 684            	       "Using gamma correction (%.1f, %.1f, %.1f)\n",
 685 dawes 1.11 	       scrp->gamma.red, scrp->gamma.green, scrp->gamma.blue);
 686 dawes 1.2  
 687                return TRUE;
 688            }
 689            
 690            #undef TEST_GAMMA
 691            #undef SET_GAMMA
 692            
 693            
 694            /*
 695             * Set the DPI from the command line option.  XXX should allow it to be
 696             * calculated from the witdhmm/heightmm values.
 697             */
 698            
 699            #undef MMPERINCH
 700            #define MMPERINCH 25.4
 701            
 702            void
 703            xf86SetDpi(ScrnInfoPtr pScrn, int x, int y)
 704            {
 705                MessageType from = X_DEFAULT;
 706            
 707 dawes 1.2      /* XXX Maybe there is no need for widthmm/heightmm in ScrnInfoRec */
 708                pScrn->widthmm = pScrn->monitor->widthmm;
 709                pScrn->heightmm = pScrn->monitor->heightmm;
 710            
 711                if (monitorResolution > 0) {
 712            	pScrn->xDpi = monitorResolution;
 713            	pScrn->yDpi = monitorResolution;
 714            	from = X_CMDLINE;
 715                } else if (pScrn->widthmm > 0 || pScrn->heightmm > 0) {
 716            	from = X_CONFIG;
 717            	if (pScrn->widthmm > 0) {
 718            	   pScrn->xDpi =
 719            		(int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm);
 720            	}
 721            	if (pScrn->heightmm > 0) {
 722            	   pScrn->yDpi =
 723            		(int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm);
 724            	}
 725            	if (pScrn->xDpi > 0 && pScrn->yDpi <= 0)
 726            	    pScrn->yDpi = pScrn->xDpi;
 727            	if (pScrn->yDpi > 0 && pScrn->xDpi <= 0)
 728 dawes 1.2  	    pScrn->xDpi = pScrn->yDpi;
 729            	xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n",
 730            		   pScrn->widthmm, pScrn->heightmm);
 731                } else {
 732            	if (x > 0)
 733            	    pScrn->xDpi = x;
 734            	else
 735            	    pScrn->xDpi = DEFAULT_DPI;
 736            	if (y > 0)
 737            	    pScrn->yDpi = y;
 738            	else
 739            	    pScrn->yDpi = DEFAULT_DPI;
 740                }
 741                xf86DrvMsg(pScrn->scrnIndex, from, "DPI set to (%d, %d)\n",
 742            	       pScrn->xDpi, pScrn->yDpi);
 743            }
 744            
 745            #undef MMPERINCH
 746            
 747            
 748            void
 749 dawes 1.2  xf86SetBlackWhitePixels(ScreenPtr pScreen)
 750            {
 751                if (xf86GetFlipPixels()) {
 752            	pScreen->whitePixel = 0;
 753            	pScreen->blackPixel = 1;
 754                } else {
 755            	pScreen->whitePixel = 1;
 756            	pScreen->blackPixel = 0;
 757                }
 758            }
 759            
 760            /*
 761             * create a new serial number for the window. Used in xf86SaveRestoreImage
 762             * to force revalidation of all the GC in the window tree of each screen.
 763             */
 764            /*ARGSUSED*/
 765            static int
 766            xf86NewSerialNumber(WindowPtr p, pointer unused)
 767            {
 768                p->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 769                return WT_WALKCHILDREN;
 770 dawes 1.2  }
 771            
 772            /*
 773             * Function to save/restore the video image and replace the root drawable
 774             * with a pixmap.
 775             *
 776             * This is used when VT switching and when entering/leaving DGA direct mode.
 777             *
 778             * This has been rewritten compared with the older code, with the intention
 779             * of making it more general.  It relies on some new functions added to
 780             * the ScreenRec.  It has not been tested yet.
 781             *
 782             * Here, we switch the pixmap data pointers, rather than the pixmaps themselves
 783             * to avoid having to find and change any references to the screen pixmap
 784             * such as GC's, window privates etc.
 785             */
 786            
 787            Bool
 788            xf86SaveRestoreImage(int scrnIndex, SaveRestoreFlags what)
 789            {
 790                ScreenPtr pScreen;
 791 dawes 1.14     static unsigned char *devPrivates[MAXSCREENS];
 792                static int devKinds[MAXSCREENS];
 793                pointer devPrivate;
 794                Bool ret = FALSE;
 795                int width, height, devKind, bitsPerPixel;
 796                PixmapPtr pScreenPix, pPix;
 797 dawes 1.12 
 798 dawes 1.2      BoxRec pixBox;
 799                RegionRec pixReg;
 800            
 801                pScreen = xf86Screens[scrnIndex]->pScreen;
 802            
 803                pixBox.x1 = pixBox.y1 = 0;
 804                pixBox.x2 = pScreen->width;
 805                pixBox.y2 = pScreen->height;
 806                (*pScreen->RegionInit)(&pixReg, &pixBox, 1);
 807            
 808 dawes 1.14     pScreenPix = (*pScreen->GetScreenPixmap)(pScreen);
 809            
 810 dawes 1.2      switch (what) {
 811                case SaveImage:
 812 dawes 1.14         /*
 813                     * Create a dummy pixmap to write to while VT is switched out, and
 814                     * copy the screen to that pixmap.
 815                     */
 816            	width = pScreenPix->drawable.width;
 817            	height = pScreenPix->drawable.height;
 818            	bitsPerPixel = pScreenPix->drawable.bitsPerPixel;
 819            
 820            	/* save the old data */
 821            	devPrivates[scrnIndex] = pScreenPix->devPrivate.ptr;
 822            	devKinds[scrnIndex] = pScreenPix->devKind;
 823            	
 824            	/* allocate new data */
 825            	devKind = (((width * bitsPerPixel) + 31) >> 5) << 2; /* which macro ? */
 826 dawes 1.17         devPrivate = xalloc(devKind * height);
 827 dawes 1.14 
 828                    if(devPrivate) {
 829            	    pPix = GetScratchPixmapHeader(pScreen, width, height, 
 830            		   pScreen->rootDepth, bitsPerPixel, devKind, devPrivate);
 831            				
 832            	    if(pPix) {
 833            		(*pScreen->BackingStoreFuncs.SaveAreas)(pPix, &pixReg, 0, 0,
 834            						WindowTable[scrnIndex]);
 835            
 836            		FreeScratchPixmapHeader(pPix);
 837            
 838            		/* modify the pixmap */
 839            		pScreenPix->devPrivate.ptr = devPrivate;
 840            		pScreenPix->devKind = devKind;
 841            
 842            		WalkTree(xf86Screens[scrnIndex]->pScreen,xf86NewSerialNumber,0);
 843            		ret = TRUE;
 844            	    } else
 845            		xfree(devPrivate);
 846 dawes 1.2  	}
 847            	break;
 848                case RestoreImage:
 849            	/*
 850            	 * Reinstate the screen pixmap and copy the dummy pixmap back
 851            	 * to the screen.
 852            	 */
 853 dawes 1.9  	
 854 dawes 1.2  	if (!xf86Resetting) {
 855 dawes 1.14 	     width = pScreenPix->drawable.width;
 856            	     height = pScreenPix->drawable.height;
 857            	     bitsPerPixel = pScreenPix->drawable.bitsPerPixel;
 858            	     devPrivate = pScreenPix->devPrivate.ptr;
 859            	     devKind = pScreenPix->devKind;
 860            
 861            	     /* scratch pixmap for the old screen */
 862            	     pPix = GetScratchPixmapHeader(pScreen, width, height, 
 863            		   pScreen->rootDepth, bitsPerPixel, devKind, devPrivate);
 864 dawes 1.2  
 865 dawes 1.14 	     if(pPix) {
 866            		(*pScreen->BackingStoreFuncs.RestoreAreas)(pPix, &pixReg, 0, 0,
 867 dawes 1.2  						       WindowTable[scrnIndex]);
 868 dawes 1.14 		xfree(devPrivate);
 869            		FreeScratchPixmapHeader(pPix);
 870            		/* restore old values */
 871            		pScreenPix->devPrivate.ptr = devPrivates[scrnIndex];
 872            		pScreenPix->devKind = devKinds[scrnIndex];
 873            		WalkTree(xf86Screens[scrnIndex]->pScreen,xf86NewSerialNumber,0);
 874            		ret = TRUE;
 875            	     }
 876            	     break;
 877            	} 
 878 dawes 1.2  	/* Fall through */
 879                case FreeImage:
 880 dawes 1.14 	if (pScreenPix->devPrivate.ptr)
 881            	    xfree(pScreenPix->devPrivate.ptr);
 882            	ret = TRUE;
 883 dawes 1.2  	break;
 884                default:
 885            	ErrorF("xf86SaveRestoreImage: Invalid flag (%d)\n", what);
 886                }
 887                (*pScreen->RegionUninit)(&pixReg);
 888 dawes 1.14     return ret;
 889 dawes 1.2  }
 890            
 891            /* Print driver messages in the standard format */
 892            
 893            void
 894            xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
 895            		va_list args)
 896            {
 897                char *s = X_UNKNOWN_STRING;
 898            
 899                /* Ignore xf86Verbose for X_ERROR */
 900                if (xf86Verbose >= verb || type == X_ERROR) {
 901            	switch (type) {
 902            	case X_PROBED:
 903            	    s = X_PROBE_STRING;
 904            	    break;
 905            	case X_CONFIG:
 906            	    s = X_CONFIG_STRING;
 907            	    break;
 908            	case X_DEFAULT:
 909            	    s = X_DEFAULT_STRING;
 910 dawes 1.2  	    break;
 911            	case X_CMDLINE:
 912            	    s = X_CMDLINE_STRING;
 913            	    break;
 914            	case X_NOTICE:
 915            	    s = X_NOTICE_STRING;
 916            	    break;
 917            	case X_ERROR:
 918            	    s = X_ERROR_STRING;
 919            	    break;
 920            	case X_WARNING:
 921            	    s = X_WARNING_STRING;
 922            	    break;
 923            	case X_INFO:
 924            	    s = X_INFO_STRING;
 925            	    break;
 926            	case X_NONE:
 927            	    s = NULL;
 928            	    break;
 929            	}
 930            
 931 dawes 1.2  	if (s != NULL)
 932            	    ErrorF("%s ", s);
 933            	if (scrnIndex >= 0 && scrnIndex < xf86NumScreens)
 934            	    ErrorF("%s(%d): ", xf86Screens[scrnIndex]->name, scrnIndex);
 935            	VErrorF(format, args);
 936                }
 937            }
 938            
 939            /* Print driver messages, with verbose level specified directly */
 940            void
 941            xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
 942            	       ...)
 943            {
 944                va_list ap;
 945            
 946                va_start(ap, format);
 947                xf86VDrvMsgVerb(scrnIndex, type, verb, format, ap);
 948                va_end(ap);
 949            }
 950            
 951            /* Print driver messages, with verbose level of 1 (default) */
 952 dawes 1.2  void
 953            xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...)
 954            {
 955                va_list ap;
 956            
 957                va_start(ap, format);
 958                xf86VDrvMsgVerb(scrnIndex, type, 1, format, ap);
 959                va_end(ap);
 960            }
 961            
 962            /* Print non-driver messages with verbose level specified directly */
 963            void
 964            xf86MsgVerb(MessageType type, int verb, const char *format, ...)
 965            {
 966                va_list ap;
 967            
 968                va_start(ap, format);
 969                xf86VDrvMsgVerb(-1, type, verb, format, ap);
 970                va_end(ap);
 971            }
 972            
 973 dawes 1.2  /* Print non-driver messages with verbose level of 1 (default) */
 974            void
 975            xf86Msg(MessageType type, const char *format, ...)
 976            {
 977                va_list ap;
 978            
 979                va_start(ap, format);
 980                xf86VDrvMsgVerb(-1, type, 1, format, ap);
 981                va_end(ap);
 982            }
 983            
 984            /* Just like ErrorF, but with the verbose level checked */
 985            void
 986            xf86ErrorFVerb(int verb, const char *format, ...)
 987            {
 988                va_list ap;
 989            
 990                va_start(ap, format);
 991                if (xf86Verbose >= verb)
 992            	VErrorF(format, ap);
 993                va_end(ap);
 994 dawes 1.2  }
 995            
 996            void
 997            xf86ErrorF(const char *format, ...)
 998            {
 999                va_list ap;
1000            
1001                va_start(ap, format);
1002                if (xf86Verbose >= 1)
1003            	VErrorF(format, ap);
1004                va_end(ap);
1005            }
1006            
1007            
1008            /*
1009             * Drivers can use these for using their own SymTabRecs.
1010             */
1011            
1012            const char *
1013            xf86TokenToString(SymTabPtr table, int token)
1014            {
1015 dawes 1.2      int i;
1016            
1017                for (i = 0; table[i].token >= 0 && table[i].token != token; i++)
1018            	;
1019            
1020                if (table[i].token < 0)
1021            	return NULL;
1022                else
1023            	return(table[i].name);
1024            }
1025            
1026            int
1027            xf86StringToToken(SymTabPtr table, const char *string)
1028            {
1029                int i;
1030            
1031                if (string == NULL)
1032            	return -1;
1033            
1034                for (i = 0; table[i].token >= 0 && xf86NameCmp(string, table[i].name); i++)
1035            	;
1036 dawes 1.2  
1037                return(table[i].token);
1038            }
1039            
1040            /*
1041             * helper to display the clocks found on a card
1042             */
1043            void
1044            xf86ShowClocks(ScrnInfoPtr scrp, MessageType from)
1045            {
1046                int j;
1047            
1048 dawes 1.4      xf86DrvMsg(scrp->scrnIndex, from, "Pixel clocks available:");
1049 dawes 1.2      for (j=0; j < scrp->numClocks; j++) {
1050            	if ((j % 8) == 0) {
1051            	    xf86ErrorF("\n");
1052            	    xf86DrvMsg(scrp->scrnIndex, from, "pixel clocks:");
1053            	}
1054            	xf86ErrorF(" %6.2f", (double)scrp->clock[j] / 1000.0);
1055                }
1056                xf86ErrorF("\n");
1057            }
1058            
1059            
1060            /*
1061             * This prints out the driver identify message, including the names of
1062             * the supported chipsets.
1063             *
1064             * XXX This makes assumptions about the line width, etc.  Maybe we could
1065             * use a more general "pretty print" function for messages.
1066             */
1067            void
1068            xf86PrintChipsets(const char *drvname, const char *drvmsg, SymTabPtr chips)
1069            {
1070 dawes 1.2      int len, i;
1071            
1072                len = 6 + strlen(drvname) + 2 + strlen(drvmsg) + 2;
1073                xf86Msg(X_INFO, "%s: %s:", drvname, drvmsg);
1074                for (i = 0; chips[i].name != NULL; i++) {
1075            	if (i != 0) {
1076            	    xf86ErrorF(",");
1077            	    len++;
1078            	}
1079            	if (len + 2 + strlen(chips[i].name) < 78) {
1080            	    xf86ErrorF(" ");
1081            	    len++;
1082            	} else {
1083            	    xf86ErrorF("\n\t");
1084            	    len = 8;
1085            	}
1086            	xf86ErrorF("%s", chips[i].name);
1087            	len += strlen(chips[i].name);
1088                }
1089                xf86ErrorF("\n");
1090            }
1091 dawes 1.2  
1092            
1093            #define MAXDRIVERS 64	/* A >hack<, to be sure ... */
1094            
1095            
1096            int
1097            xf86MatchDevice(const char *drivername, GDevPtr **driversectlist)
1098            {
1099                static char *     drivernames[MAXDRIVERS];
1100                static GDevPtr *  devices[MAXDRIVERS];
1101                static int	      count[MAXDRIVERS];
1102                confScreenPtr screensecptr;
1103                int i,j;
1104                
1105                /*
1106                 * This is a very important function that matches the device sections
1107                 * as they show up in the config file with the drivers that the server
1108                 * laods at run time.
1109            
1110                 * ChipProbe can call 
1111                 * int xf86MatchDevice(char * drivername, GDevPtr * driversectlist) 
1112 dawes 1.2       * with its driver name. The function allocates an array of GDevPtr and
1113                 * returns this via driversectlist and returns the number of elements in
1114                 * this list as return value. 0 means none found, -1 means fatal error.
1115                 * 
1116                 * It can figure out which of the Device sections to use for which card
1117                 * (using things like the Card statement, etc). For single headed servers
1118                 * there will of course be just one such Device section.
1119                 * 
1120                 * If there's no Device section with matching name, then xf86MatchDevice()
1121                 * returns the first Device section without a Driver statement. This will
1122                 * again work out ok in a single headed environment.
1123                 */
1124                /*
1125                 * in order to be able to access the results of these queries again, we
1126                 * keep two parallel static arrays, one holding the name of the driver,
1127                 * the other holding the coresponding Device section pointers.
1128                 * So first, we need to check if the query has already been answered
1129                 * and simply return that old answer if this is the case.
1130                 */
1131                i = 0;
1132                while (drivernames[i] && i < MAXDRIVERS) {
1133 dawes 1.2          if (xf86NameCmp(drivername,drivernames[i]) == 0) {
1134                        /*
1135                         * we already had that one
1136                         */
1137                        *driversectlist = devices[i];
1138                        return count[i];
1139                    }
1140                    i++;
1141                }
1142            
1143                if (i == MAXDRIVERS)
1144            	return -1;
1145            
1146                /*
1147                 * if we get here, this is a new name
1148                 */
1149                drivernames[i] = xstrdup(drivername);
1150                count[i] = 0;
1151                
1152                /*
1153                 * first we need to loop over all the Screens sections to get to all
1154 dawes 1.2       * 'active' device sections
1155                 */
1156 dawes 1.17     for (j=0; xf86ConfigLayout.screens[j].screen != NULL; j++) {
1157                    screensecptr = xf86ConfigLayout.screens[j].screen;
1158 dawes 1.2          if ((screensecptr->device->driver != NULL)
1159                        && (xf86NameCmp( screensecptr->device->driver,drivername) == 0)
1160                        && (! screensecptr->device->claimed)) {
1161                        /*
1162                         * we have a matching driver that wasn't claimed, yet
1163                         */
1164                        screensecptr->device->claimed = TRUE;
1165 dawes 1.17             devices[i] = xnfrealloc(devices[i],
1166                                                (count[i] + 2) * sizeof(GDevPtr));
1167 dawes 1.2              devices[i][count[i]++] = screensecptr->device;
1168                    }
1169                }
1170                if (count[i] == 0) {
1171                    /*
1172                     * we haven't found a single one, let's try to find one that
1173                     * wasn't claimed and has no driver given
1174                     */
1175 dawes 1.17         for (j=0; xf86ConfigLayout.screens[j].screen != NULL; j++) {
1176                        screensecptr = xf86ConfigLayout.screens[j].screen;
1177 dawes 1.2              if ((screensecptr->device->driver == NULL)
1178                            && (! screensecptr->device->claimed)) {
1179                            /*
1180                             * we have a device section without driver that wasn't claimed
1181                             */
1182                            screensecptr->device->claimed = TRUE;
1183 dawes 1.17                 devices[i] = xnfrealloc(devices[i],
1184                                                    (count[i] + 2) * sizeof(GDevPtr));
1185 dawes 1.2                  devices[i][count[i]++] = screensecptr->device;
1186                        }
1187                    }
1188                }
1189                /*
1190                 * make the array NULL terminated and return its address
1191                 */
1192                if( count[i] )
1193                    devices[i][count[i]] = NULL;
1194                else
1195                    devices[i] = NULL;
1196                
1197                *driversectlist = devices[i];
1198            
1199                return count[i];
1200            }
1201            
1202            #define DEBUG
1203            int
1204 dawes 1.5  xf86MatchPciInstances(const char *driverName, int vendorID, 
1205 dawes 1.9  		      SymTabPtr chipsets, PciChipsets *PCIchipsets,
1206 dawes 1.5  		      GDevPtr *devList, int numDevs,
1207            		      GDevPtr **foundDevs, pciVideoPtr **foundPCI, 
1208            		      int **foundChips)
1209 dawes 1.2  {
1210 dawes 1.5      int i,j;
1211                MessageType from;
1212 dawes 1.2      pciVideoPtr pPci, *ppPci;
1213                struct Inst {
1214            	pciVideoPtr	pci;
1215            	GDevPtr		dev;
1216            	Bool		foundHW;
1217            	Bool		claimed;
1218            	Bool		inuse;
1219 dawes 1.5          int             chip;
1220 dawes 1.2      } *instances = NULL;
1221                int numClaimedInstances = 0;
1222                int allocatedInstances = 0;
1223                int numFound = 0;
1224 dawes 1.5      SymTabRec *c;
1225                PciChipsets *id;
1226 dawes 1.2      GDevPtr *retDevs = NULL;
1227 dawes 1.5      GDevPtr devBus = NULL;
1228                GDevPtr dev = NULL;
1229 dawes 1.2      pciVideoPtr *retPCI = NULL;
1230 dawes 1.5      int *retChips = NULL;
1231 dawes 1.2  
1232                if (vendorID == 0) {
1233                    for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
1234 dawes 1.6  	    for (id = PCIchipsets; id->PCIid != -1; id++) {
1235 dawes 1.5  	        if ( (((id->PCIid & 0xFFFF0000) >> 16) == (*ppPci)->vendor) && 
1236            		     ((id->PCIid & 0x0000FFFF)        == (*ppPci)->chipType)){
1237 dawes 1.2  	            numClaimedInstances = ++allocatedInstances;
1238 dawes 1.17 	            instances = xnfrealloc(instances,
1239 dawes 1.5  				  allocatedInstances * sizeof(struct Inst));
1240 dawes 1.2  	            instances[allocatedInstances - 1].inuse = TRUE;
1241            	            instances[allocatedInstances - 1].pci = *ppPci;
1242            	            instances[allocatedInstances - 1].dev = NULL;
1243            	            instances[allocatedInstances - 1].claimed = FALSE;
1244            	            instances[allocatedInstances - 1].foundHW = TRUE;
1245 dawes 1.5  		    instances[allocatedInstances - 1].chip = id->numChipset;
1246 dawes 1.2  	        }
1247            	    }
1248                    }
1249 dawes 1.9      } else if (vendorID == PCI_VENDOR_GENERIC) {
1250            	for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
1251            	    for (id = PCIchipsets; id->PCIid != -1; id++) {
1252            		if (id->PCIid == xf86CheckPciGAType(*ppPci)) {
1253            		    numClaimedInstances = ++allocatedInstances;
1254 dawes 1.17 		    instances = xnfrealloc(instances,
1255 dawes 1.9  				  allocatedInstances * sizeof(struct Inst));
1256            		    instances[allocatedInstances - 1].inuse = TRUE;
1257            		    instances[allocatedInstances - 1].pci = *ppPci;
1258            		    instances[allocatedInstances - 1].dev = NULL;
1259            		    instances[allocatedInstances - 1].claimed = FALSE;
1260            		    instances[allocatedInstances - 1].foundHW = TRUE;
1261            		    instances[allocatedInstances - 1].chip = id->numChipset;
1262            		}
1263            	    }
1264            	}
1265 dawes 1.2      } else {
1266 dawes 1.9  	    /* Find PCI devices that match the given vendor ID */
1267 dawes 1.2  
1268 dawes 1.5  	for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
1269 dawes 1.2  	    if ((*ppPci)->vendor == vendorID) {
1270 dawes 1.5  		numClaimedInstances = ++allocatedInstances;
1271 dawes 1.17 		instances = xnfrealloc(instances,
1272 dawes 1.5  			      allocatedInstances * sizeof(struct Inst));
1273            		instances[allocatedInstances - 1].inuse = TRUE;
1274            		instances[allocatedInstances - 1].pci = *ppPci;
1275            		instances[allocatedInstances - 1].dev = NULL;
1276            		instances[allocatedInstances - 1].claimed = FALSE;
1277            		instances[allocatedInstances - 1].foundHW = FALSE;
1278            
1279            		/* Check if the chip type is listed in the chipsets table */
1280 dawes 1.6  		for (id = PCIchipsets; id->PCIid != -1; id++) {
1281 dawes 1.5  		    if (id->PCIid == (*ppPci)->chipType) {
1282            			instances[allocatedInstances - 1].chip
1283            			    = id->numChipset;
1284            			instances[allocatedInstances - 1].foundHW = TRUE;
1285            			break;
1286 dawes 1.2  		    }
1287 dawes 1.5  		}
1288 dawes 1.2  	    }
1289 dawes 1.5  	}
1290 dawes 1.2      }
1291                /*
1292                 * This may be debatable, but if no PCI devices with a matching vendor
1293                 * type is found, return zero now.  It is probably not desirable to
1294                 * allow the config file to override this.
1295                 */
1296                if (allocatedInstances <= 0) {
1297            	xfree(instances);
1298            	return 0;
1299                }
1300            #ifdef DEBUG
1301                ErrorF("%s instances found: %d\n", driverName, numClaimedInstances);
1302            #endif
1303            
1304                /*
1305 dawes 1.5       * If a matching device section without BusID is found use it
1306                 * unless one with matching busID is found. 
1307                 */    
1308 dawes 1.7      for (i = 0; i< allocatedInstances; i++) {
1309 dawes 1.5  	if (!instances[i].inuse)
1310            	    continue;
1311            	pPci = instances[i].pci;
1312 dawes 1.7  	devBus = NULL;
1313            	dev = NULL;
1314 dawes 1.2  	for (j = 0; j < numDevs; j++) {
1315            	    if (devList[j]->busID && *devList[j]->busID) {
1316 dawes 1.7  		if (xf86ComparePciBusString(devList[j]->busID, pPci->bus,
1317 dawes 1.5  					   pPci->device,
1318            					   pPci->func)) {
1319 dawes 1.7  		    if (devBus)
1320            			xf86MsgVerb(X_WARNING,0,
1321            			    "%s: More than one matching Device section for "
1322            			    "instance (BusID: %s) found: %s\n",
1323            			    driverName,devList[j]->identifier,
1324            			    devList[j]->busID);
1325            		    else
1326            			devBus = devList[j];
1327 dawes 1.5  		} 
1328            	    } else {
1329            		/* 
1330            		 * if device section without BusID is found 
1331            		 * only assign to it to the primary device.
1332            		 */
1333 dawes 1.7  		if (xf86IsPrimaryPci(pPci)) {
1334            		    xf86Msg(X_PROBED, "Assigning device section with no busID"
1335 dawes 1.5  			    " to primary device\n");
1336 dawes 1.7  		    if (dev || devBus)
1337            			xf86MsgVerb(X_WARNING, 0,
1338            			    "%s: More than one matching Device section "
1339            			    "found: %s\n", devList[j]->identifier);
1340            		    else
1341            			dev = devList[j];
1342 dawes 1.2  		}
1343            	    }
1344            	}
1345 dawes 1.7  	if (devBus) dev = devBus; 
1346            	if (!dev) {
1347            	    xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section "
1348 dawes 1.5  			"for instance (BusID PCI:%i:%i:%i) found\n",
1349            			driverName, pPci->bus, pPci->device, pPci->func);
1350            	} else {
1351            	    instances[i].claimed = TRUE;
1352            	    instances[i].dev = dev;
1353            	}
1354 dawes 1.2      }
1355                /*
1356                 * Now check that a chipset or chipID override in the device section
1357                 * is valid.  Chipset has precedence over chipID.
1358                 */
1359                for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) {
1360            	if (!instances[i].inuse || !instances[i].claimed) {
1361            	    continue;
1362            	}
1363 dawes 1.5  	from = X_PROBED;
1364 dawes 1.2  	if (instances[i].dev->chipset) {
1365 dawes 1.5  	    for (c = chipsets; c->token >= 0; c++) {
1366            		if (xf86NameCmp(c->name, instances[i].dev->chipset) == 0)
1367 dawes 1.2  		    break;
1368            	    }
1369 dawes 1.5  	    if (c->token == -1) {
1370 dawes 1.2  		instances[i].inuse = FALSE;
1371            		numClaimedInstances--;
1372            		xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device "
1373            			    "section \"%s\" isn't valid for this driver\n",
1374            			    driverName, instances[i].dev->chipset,
1375            			    instances[i].dev->identifier);
1376 dawes 1.5  	    } else {
1377            		instances[i].chip = c->token;
1378            
1379            		for (id = PCIchipsets; id->numChipset >= 0; id++) {
1380            		    if (id->numChipset == instances[i].chip)
1381            			break;
1382            		}
1383            		if(id->numChipset >=0){
1384            		    xf86Msg(X_CONFIG,"Chipset override: %s\n",
1385            			     instances[i].dev->chipset);
1386            		    from = X_CONFIG;
1387            		} else {
1388            		    instances[i].inuse = FALSE;
1389            		    numClaimedInstances--;
1390            		    xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device "
1391            				"section \"%s\" isn't a valid PCI chipset\n",
1392            				driverName, instances[i].dev->chipset,
1393            				instances[i].dev->identifier);
1394            		}
1395 dawes 1.2  	    }
1396 dawes 1.5  	} else if (instances[i].dev->chipID > 0) {
1397            	    for (id = PCIchipsets; id->numChipset >= 0; id++) {
1398            		if (id->PCIid == instances[i].dev->chipID)
1399 dawes 1.2  		    break;
1400            	    }
1401 dawes 1.5  	    if (id->numChipset == -1) {
1402 dawes 1.2  		instances[i].inuse = FALSE;
1403            		numClaimedInstances--;
1404            		xf86MsgVerb(X_WARNING, 0, "%s: ChipID 0x%04X in Device "
1405            			    "section \"%s\" isn't valid for this driver\n",
1406            			    driverName, instances[i].dev->chipID,
1407            			    instances[i].dev->identifier);
1408 dawes 1.5  	    } else {
1409            		instances[i].chip = id->numChipset;
1410            
1411            		xf86Msg( X_CONFIG,"ChipID override: 0x%04X\n",
1412            			 instances[i].dev->chipID);
1413            		from = X_CONFIG;
1414 dawes 1.2  	    }
1415            	} else if (!instances[i].foundHW) {
1416            	    /*
1417            	     * This means that there was no override and the PCI chipType
1418            	     * doesn't match one that is supported
1419            	     */
1420            	    instances[i].inuse = FALSE;
1421            	    numClaimedInstances--;
1422            	}
1423 dawes 1.5  	if (instances[i].inuse == TRUE){
1424            	    for (c = chipsets; c->token >= 0; c++) {
1425            		if (c->token == instances[i].chip)
1426            		    break;
1427            	    }
1428            	    xf86Msg(from,"Chipset %s found\n",
1429            		    c->name);
1430            	}
1431 dawes 1.2      }
1432            
1433                /*
1434                 * Of the claimed instances, check that another driver hasn't already
1435                 * claimed its slot.
1436                 */
1437                for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) {
1438            	if (!instances[i].inuse)
1439            	    continue;
1440            	pPci = instances[i].pci;
1441            
1442            #ifdef DEBUG
1443            	ErrorF("%s: found card at %d:%d:%d\n", driverName, pPci->bus,
1444 dawes 1.5  	       pPci->device, pPci->func);
1445 dawes 1.2  #endif
1446            
1447            	if (!instances[i].claimed) {
1448            	    numClaimedInstances--;
1449            	    continue;
1450            	}
1451            
1452            #ifdef DEBUG
1453            	ErrorF("%s: card at %d:%d:%d is claimed by a Device section\n",
1454 dawes 1.5  	       driverName, pPci->bus, pPci->device, pPci->func);
1455 dawes 1.2  #endif
1456            
1457            	/* Allocate an entry in the lists to be returned */
1458            	numFound++;
1459 dawes 1.17 	retDevs = xnfrealloc(retDevs, numFound * sizeof(GDevPtr));
1460            	retPCI = xnfrealloc(retPCI, numFound * sizeof(pciVideoPtr));
1461            	retChips = xnfrealloc(retChips, numFound * sizeof(int));
1462 dawes 1.2  	retDevs[numFound - 1] = instances[i].dev;
1463            	retPCI[numFound - 1] = instances[i].pci;
1464 dawes 1.5  	retChips[numFound -1] = instances[i].chip;
1465 dawes 1.2      }
1466                xfree(instances);
1467                if (numFound > 0) {
1468            	*foundDevs = retDevs;
1469            	*foundPCI = retPCI;
1470 dawes 1.5  	*foundChips = retChips;
1471 dawes 1.2      }
1472                return numFound;
1473            }
1474            
1475 dawes 1.5  BusResource 
1476            xf86FindPciResource(int numChipset, PciChipsets *PCIchipsets)
1477            {
1478                PciChipsets *c;
1479            
1480                for (c=PCIchipsets; c->numChipset>=0; c++)
1481                {
1482 dawes 1.7  	if (c->numChipset == numChipset)
1483 dawes 1.5  	    break;
1484                }
1485 dawes 1.7      return (c->Resource);
1486 dawes 1.5  }
1487            
1488            int
1489 dawes 1.9  xf86MatchIsaInstances(const char *driverName, SymTabPtr chipsets,
1490            		      IsaChipsets *ISAchipsets, FindIsaDevProc FindIsaDevice,
1491 dawes 1.5  		      GDevPtr *devList, int numDevs, GDevPtr *foundDev)
1492            {
1493                GDevPtr dev = NULL;
1494                GDevPtr devBus = NULL;
1495                int foundChip = -1;
1496                SymTabRec *c;
1497                IsaChipsets *Chips;
1498 dawes 1.15     int i;
1499 dawes 1.5      MessageType from = X_CONFIG;
1500            
1501                for (i = 0; i < numDevs; i++) {
1502            	if (devList[i]->busID && *devList[i]->busID) {
1503 dawes 1.7  	    if (xf86ParseIsaBusString(devList[i]->busID)) {
1504 dawes 1.5  		if (devBus) xf86MsgVerb(X_WARNING,0,
1505            					"%s: More than one matching Device "
1506            					"section for ISA-Bus found: %s\n",
1507            					driverName,devList[i]->identifier);
1508            		else devBus = devList[i];
1509            	    } 
1510            	} else {
1511 dawes 1.9  	    if (xf86IsPrimaryIsa()) {
1512            		if (dev) xf86MsgVerb(X_WARNING,0,
1513            				     "%s: More than one matching "
1514            				     "Device section found: %s\n",
1515            				     driverName,devList[i]->identifier);
1516            		else dev = devList[i];
1517            	    }
1518 dawes 1.5  	}
1519                }
1520 dawes 1.7      if (devBus) dev = devBus; 
1521                if (!dev) return -1;
1522 dawes 1.5  
1523                if (dev->chipset) {
1524            	for (c = chipsets; c->token >= 0; c++) {
1525            	    if (xf86NameCmp(c->name, dev->chipset) == 0)
1526            		break;
1527            	}
1528            	if (c->token == -1) {
1529            	    xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device "
1530            			"section \"%s\" isn't valid for this driver\n",
1531            			driverName, dev->chipset,
1532            			dev->identifier);
1533            	} else
1534            	    foundChip = c->token;
1535                } else { 
1536 dawes 1.7  	if (FindIsaDevice) foundChip = (*FindIsaDevice)();  /* Probe it */
1537 dawes 1.5  	from = X_PROBED;
1538                }
1539            
1540                /* Check if the chip type is listed in the chipset table - for sanity */
1541 dawes 1.7      if (foundChip >= 0){
1542 dawes 1.5  	for (Chips = ISAchipsets; Chips->numChipset >= 0; Chips++) {
1543            	    if (Chips->numChipset == foundChip) 
1544            		break;
1545            	}
1546            	if (Chips->numChipset == -1){
1547            	    foundChip = -1;
1548            	    xf86MsgVerb(X_WARNING,0,"%s: Driver detected unknown ISA-Bus Chipset\n",
1549            			driverName);
1550            	}
1551                }
1552                if (foundChip == -1) 
1553            	*foundDev = NULL;
1554                else {
1555            	*foundDev = dev;
1556            	for (c = chipsets; c->token >= 0; c++) {
1557            	    if (c->token == foundChip)
1558            		break;
1559            	}
1560 dawes 1.7  	xf86Msg(from, "Chipset %s found\n", c->name);
1561 dawes 1.5      }
1562            
1563                return foundChip;
1564            }
1565            
1566            BusResource 
1567            xf86FindIsaResource(int numChipset, IsaChipsets *ISAchipsets)
1568            {
1569                IsaChipsets *c;
1570            
1571                for (c=ISAchipsets; c->numChipset>=0; c++)
1572                {
1573 dawes 1.7  	if (c->numChipset == numChipset)
1574 dawes 1.5  	    break;
1575                }
1576 dawes 1.7      return (c->Resource);
1577 dawes 1.5  }
1578 dawes 1.2  
1579            /*
1580             * xf86GetClocks -- get the dot-clocks via a BIG BAD hack ...
1581             */
1582            void
1583            xf86GetClocks(ScrnInfoPtr pScrn, int num, Bool (*ClockFunc)(ScrnInfoPtr, int),
1584            	      void (*ProtectRegs)(ScrnInfoPtr, Bool),
1585            	      void (*BlankScreen)(ScrnInfoPtr, Bool), int vertsyncreg,
1586            	      int maskval, int knownclkindex, int knownclkvalue)
1587            {
1588                register int status = vertsyncreg;
1589                unsigned long i, cnt, rcnt, sync;
1590                int saved_nice;
1591            
1592                /* First save registers that get written on */
1593                (*ClockFunc)(pScrn, CLK_REG_SAVE);
1594            
1595            #if defined(CSRG_BASED) || defined(MACH386)
1596                saved_nice = getpriority(PRIO_PROCESS, 0);
1597                setpriority(PRIO_PROCESS, 0, -20);
1598            #endif
1599 dawes 1.2  #if defined(SYSV) || defined(SVR4) || defined(linux)
1600                saved_nice = nice(0);
1601                nice(-20 - saved_nice);
1602            #endif
1603            
1604                if (num > MAXCLOCKS)
1605            	num = MAXCLOCKS;
1606            
1607                for (i = 0; i < num; i++) 
1608                {
1609            	(*ProtectRegs)(pScrn, TRUE);
1610            	if (!(*ClockFunc)(pScrn, i))
1611            	{
1612            	    pScrn->clock[i] = -1;
1613            	    continue;
1614            	}
1615            	(*ProtectRegs)(pScrn, FALSE);
1616            	(*BlankScreen)(pScrn, FALSE);
1617            	    
1618                	usleep(50000);     /* let VCO stabilise */
1619            
1620 dawes 1.2      	cnt  = 0;
1621                	sync = 200000;
1622            
1623            	/* XXX How critical is this? */
1624                	if (!xf86DisableInterrupts())
1625                	{
1626            	    (*ClockFunc)(pScrn, CLK_REG_RESTORE);
1627            	    ErrorF("Failed to disable interrupts during clock probe.  If\n");
1628            	    ErrorF("your OS does not support disabling interrupts, then you\n");
1629            	    FatalError("must specify a Clocks line in the XF86Config file.\n");
1630            	}
1631            	while ((inb(status) & maskval) == 0x00) 
1632            	    if (sync-- == 0) goto finish;
1633            	/* Something appears to be happening, so reset sync count */
1634            	sync = 200000;
1635            	while ((inb(status) & maskval) == maskval) 
1636            	    if (sync-- == 0) goto finish;
1637            	/* Something appears to be happening, so reset sync count */
1638            	sync = 200000;
1639            	while ((inb(status) & maskval) == 0x00) 
1640            	    if (sync-- == 0) goto finish;
1641 dawes 1.2      
1642            	for (rcnt = 0; rcnt < 5; rcnt++) 
1643            	{
1644            	    while (!(inb(status) & maskval)) 
1645            		cnt++;
1646            	    while ((inb(status) & maskval)) 
1647            		cnt++;
1648            	}
1649                
1650            finish:
1651            	xf86EnableInterrupts();
1652            
1653            	pScrn->clock[i] = cnt ? cnt : -1;
1654                    (*BlankScreen)(pScrn, TRUE);
1655                }
1656            
1657            #if defined(CSRG_BASED) || defined(MACH386)
1658                setpriority(PRIO_PROCESS, 0, saved_nice);
1659            #endif
1660            #if defined(SYSV) || defined(SVR4) || defined(linux)
1661                nice(20 + saved_nice);
1662 dawes 1.2  #endif
1663            
1664                for (i = 0; i < num; i++) 
1665                {
1666            	if (i != knownclkindex)
1667            	{
1668            	    if (pScrn->clock[i] == -1)
1669            	    {
1670            		pScrn->clock[i] = 0;
1671            	    }
1672            	    else 
1673            	    {
1674            		pScrn->clock[i] = (int)(0.5 +
1675                                (((float)knownclkvalue) * pScrn->clock[knownclkindex]) / 
1676            	            (pScrn->clock[i]));
1677            		/* Round to nearest 10KHz */
1678            		pScrn->clock[i] += 5;
1679            		pScrn->clock[i] /= 10;
1680            		pScrn->clock[i] *= 10;
1681            	    }
1682            	}
1683 dawes 1.2      }
1684            
1685                pScrn->clock[knownclkindex] = knownclkvalue;
1686                pScrn->numClocks = num; 
1687            
1688                /* Restore registers that were written on */
1689                (*ClockFunc)(pScrn, CLK_REG_RESTORE);
1690            }
1691            const char *
1692            xf86GetVisualName(int visual)
1693            {
1694                if (visual < 0 || visual > DirectColor)
1695            	return NULL;
1696            
1697                return xf86VisualNames[visual];
1698            }
1699            
1700            
1701            int
1702            xf86GetVerbosity()
1703            {
1704 dawes 1.2      return xf86Verbose;
1705 dawes 1.18 }
1706            
1707            
1708            Pix24Flags
1709            xf86GetPix24()
1710            {
1711                return xf86Pix24;
1712            }
1713            
1714            
1715            Pix24Flags
1716            xf86GetConfigPix24()
1717            {
1718                return xf86ConfigPix24;
1719 dawes 1.2  }
1720            
1721            
1722            int
1723            xf86GetDepth()
1724            {
1725                return xf86Depth;
1726            }
1727            
1728            
1729            rgb
1730            xf86GetWeight()
1731            {
1732                return xf86Weight;
1733            }
1734            
1735            
1736            Gamma
1737            xf86GetGamma()
1738            {
1739                return xf86Gamma;
1740 dawes 1.2  }
1741            
1742            
1743            Bool
1744            xf86GetFlipPixels()
1745            {
1746                return xf86FlipPixels;
1747            }
1748            
1749            
1750            const char *
1751            xf86GetServerName()
1752            {
1753                return xf86ServerName;
1754            }
1755            
1756            
1757            void
1758            xf86SetDefaultColorVisualClass(int class)
1759            {
1760                defaultColorVisualClass = class;
1761 dawes 1.2  }
1762            
1763            
1764            int
1765            xf86GetDefaultColorVisualClass()
1766            {
1767                return defaultColorVisualClass;
1768            }
1769            
1770            
1771            Bool
1772            xf86ServerIsExiting()
1773            {
1774                return xf86Exiting;
1775            }
1776            
1777            
1778            Bool
1779            xf86ServerIsResetting()
1780            {
1781                return xf86Resetting;
1782 dawes 1.2  }
1783            
1784            
1785            Bool
1786            xf86CaughtSignal()
1787            {
1788                return xf86Info.caughtSignal;
1789            }
1790            
1791            
1792            pointer
1793            xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name)
1794            {
1795            #ifdef XFree86LOADER
1796                pointer ret;
1797                int errmaj = 0, errmin = 0;
1798            
1799 dawes 1.15     ret = LoadSubModule(pScrn->module, name, NULL, NULL, NULL, NULL,
1800            			&errmaj, &errmin);
1801 dawes 1.2      if (!ret)
1802            	LoaderErrorMsg(pScrn->name, name, errmaj, errmin);
1803                return ret;
1804            #else
1805                return (pointer)1;
1806 dawes 1.8  #endif
1807            }
1808            
1809            void
1810            xf86LoaderReqSymLists(const char **list0, ...)
1811            {
1812            #ifdef XFree86LOADER
1813                va_list ap;
1814            
1815                va_start(ap, list0);
1816                LoaderVReqSymLists(list0, ap);
1817                va_end(ap);
1818            #endif
1819            }
1820            
1821            void
1822            xf86LoaderReqSymbols(const char *sym0, ...)
1823            {
1824            #ifdef XFree86LOADER
1825                va_list ap;
1826            
1827 dawes 1.8      va_start(ap, sym0);
1828                LoaderVReqSymbols(sym0, ap);
1829                va_end(ap);
1830 dawes 1.2  #endif
1831            }
1832            
1833 dawes 1.7  void xf86Break1(void)
1834 dawes 1.5  {
1835            }
1836            
1837 dawes 1.7  void xf86Break2(void)
1838 dawes 1.5  {
1839            }
1840            
1841 dawes 1.7  void xf86Break3(void)
1842 dawes 1.5  {
1843            }
1844 dawes 1.15 
1845            
1846            typedef enum {
1847               OPTION_BACKING_STORE
1848            } BSOpts;
1849            
1850            static OptionInfoRec BSOptions[] = {
1851               { OPTION_BACKING_STORE, "BackingStore", OPTV_TRI,  {0}, FALSE },
1852               { -1,                   NULL,           OPTV_NONE, {0}, FALSE }
1853            };
1854            
1855            void 
1856            xf86SetBackingStore(ScreenPtr pScreen)
1857            {
1858                Bool useBS = FALSE;
1859                MessageType from = X_DEFAULT;
1860 dawes 1.16     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
1861 dawes 1.15 
1862                xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, BSOptions);
1863            
1864                /* check for commandline option here */
1865                if (xf86bsEnableFlag) {
1866            	from = X_CMDLINE;
1867            	useBS = TRUE;
1868                } else if (xf86bsDisableFlag) {
1869            	from = X_CMDLINE;
1870            	useBS = FALSE;
1871                } else {
1872            	if (xf86GetOptValBool(BSOptions, OPTION_BACKING_STORE, &useBS))
1873            	    from = X_CONFIG;
1874                }
1875                pScreen->backingStoreSupport = useBS ? Always : NotUseful;
1876                xf86DrvMsg(pScreen->myNum, from, "Backing store %s\n",
1877            		useBS ? "enabled" : "disabled");
1878            }
1879            

Powered by
ViewCVS 0.9.2