pVMWARE->mouseHidden = FALSE;
pVMWARE->cursorHidden = FALSE;
VMWAREPreInit(ScrnInfoPtr pScrn, int flags){	MessageType from;	VMWAREPtr pVMWARE;	OptionInfoPtr options;	int bpp24flags;	uint32 id;	int i;	ClockRange* clockRanges;	if (flags & PROBE_DETECT) {		return FALSE;	}	if (pScrn->numEntities != 1) {		return FALSE;	}	if (!VMWAREGetRec(pScrn)) {		return FALSE;	}	pVMWARE = VMWAREPTR(pScrn);	pVMWARE->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);	if (pVMWARE->pEnt->location.type != BUS_PCI) {		return FALSE;	}	pVMWARE->PciInfo = xf86GetPciInfoForEntity(pVMWARE->pEnt->index);	if (pVMWARE->PciInfo == NULL) {		return FALSE;	}	if (pVMWARE->PciInfo->chipType == PCI_CHIP_VMWARE0710) {		pVMWARE->indexReg =		   SVGA_LEGACY_BASE_PORT + SVGA_INDEX_PORT*sizeof(uint32);		pVMWARE->valueReg =		   SVGA_LEGACY_BASE_PORT + SVGA_VALUE_PORT*sizeof(uint32);	} else {		pVMWARE->indexReg =		   pVMWARE->PciInfo->ioBase[0] + SVGA_INDEX_PORT;		pVMWARE->valueReg =		   pVMWARE->PciInfo->ioBase[0] + SVGA_VALUE_PORT;	}	xf86DrvMsg(pScrn->scrnIndex, X_PROBED,	      "VMware SVGA regs at (0x%04x, 0x%04x)\n",	      pVMWARE->indexReg, pVMWARE->valueReg);	id = VMXGetVMwareSvgaId(pVMWARE);	if (id == SVGA_ID_0 || id == SVGA_ID_INVALID) {		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		      "No supported VMware SVGA found (read ID 0x%08x).\n", id);		return FALSE;	}	if (!xf86LoadSubModule(pScrn, "vgahw")) {		return FALSE;	}	xf86LoaderReqSymLists(vgahwSymbols, NULL);	if (!vgaHWGetHWRec(pScrn)) {		return FALSE;	}	pVMWARE->PciTag = pciTag(pVMWARE->PciInfo->bus, pVMWARE->PciInfo->device,				 pVMWARE->PciInfo->func);	pVMWARE->Primary = xf86IsPrimaryPci(pVMWARE->PciInfo);	pScrn->monitor = pScrn->confScreen->monitor;#define ACCELERATE_OPS#ifdef ACCELERATE_OPS	pVMWARE->vmwareCapability = vmwareReadReg(pVMWARE, SVGA_REG_CAPABILITIES);#else	pVMWARE->vmwareCapability = 0;#endif        if (pVMWARE->vmwareCapability & SVGA_CAP_8BIT_EMULATION) {	        pVMWARE->bitsPerPixel =                   vmwareReadReg(pVMWARE, SVGA_REG_HOST_BITS_PER_PIXEL);                vmwareWriteReg(pVMWARE,                               SVGA_REG_BITS_PER_PIXEL, pVMWARE->bitsPerPixel);        } else {	        pVMWARE->bitsPerPixel =                   vmwareReadReg(pVMWARE, SVGA_REG_BITS_PER_PIXEL);        }	pVMWARE->depth = vmwareReadReg(pVMWARE, SVGA_REG_DEPTH);	pVMWARE->videoRam = vmwareReadReg(pVMWARE, SVGA_REG_FB_MAX_SIZE);	pVMWARE->memPhysBase = vmwareReadReg(pVMWARE, SVGA_REG_FB_START);	pVMWARE->maxWidth = vmwareReadReg(pVMWARE, SVGA_REG_MAX_WIDTH);	pVMWARE->maxHeight = vmwareReadReg(pVMWARE, SVGA_REG_MAX_HEIGHT);	pVMWARE->cursorDefined = FALSE;	pVMWARE->mouseHidden = FALSE;        if (pVMWARE->vmwareCapability & SVGA_CAP_CURSOR_BYPASS_2) {                pVMWARE->cursorRemoveFromFB = SVGA_CURSOR_ON_REMOVE_FROM_FB;                pVMWARE->cursorRestoreToFB = SVGA_CURSOR_ON_RESTORE_TO_FB;        } else {                pVMWARE->cursorRemoveFromFB = SVGA_CURSOR_ON_HIDE;                pVMWARE->cursorRestoreToFB = SVGA_CURSOR_ON_SHOW;        }	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "caps:  0x%08X\n", pVMWARE->vmwareCapability);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "depth: %d\n", pVMWARE->depth);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "bpp:   %d\n", pVMWARE->bitsPerPixel);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "vram:  %d\n", pVMWARE->videoRam);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "pbase: %p\n", pVMWARE->memPhysBase);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "mwidt: %d\n", pVMWARE->maxWidth);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "mheig: %d\n", pVMWARE->maxHeight);	switch (pVMWARE->depth) {		case 16:		        /*			 * In certain cases, the Windows host appears to			 * report 16 bpp and 16 depth but 555 weight.  Just			 * silently convert it to depth of 15.			 */			if (pVMWARE->bitsPerPixel == 16 &&			    pVMWARE->weight.green == 5)				pVMWARE->depth = 15;		case 8:		case 15:			bpp24flags = NoDepth24Support;			break;		case 32:			/*			 * There is no 32 bit depth, apparently it can get			 * reported this way sometimes on the Windows host.			 */			if (pVMWARE->bitsPerPixel == 32)				pVMWARE->depth = 24;		case 24:			if (pVMWARE->bitsPerPixel == 24)				bpp24flags = Support24bppFb;			else				bpp24flags = Support32bppFb;			break;		default:			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,				   "Adapter is using an unsupported depth (%d).\n",				   pVMWARE->depth);			return FALSE;	}	if (!xf86SetDepthBpp(pScrn, pVMWARE->depth, pVMWARE->bitsPerPixel, pVMWARE->bitsPerPixel, bpp24flags)) {		return FALSE;	}	if (pScrn->bitsPerPixel != pVMWARE->bitsPerPixel) {                if (pScrn->bitsPerPixel == 8 &&                    pVMWARE->vmwareCapability & SVGA_CAP_8BIT_EMULATION) {                        vmwareWriteReg(pVMWARE, SVGA_REG_BITS_PER_PIXEL, 8);                        pVMWARE->bitsPerPixel =                           vmwareReadReg(pVMWARE, SVGA_REG_BITS_PER_PIXEL);                } else {                        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,                           "Currently unavailable depth/bpp of %d/%d requested.\n"                           "\tThe guest X server must run at the same depth and bpp as the host\n"                           "\t(which are currently %d/%d).  This is automatically detected.  Please\n"                           "\tdo not specify a depth on the command line or via the config file.\n",                            pScrn->depth, pScrn->bitsPerPixel,                            pVMWARE->depth, pVMWARE->bitsPerPixel);		        return FALSE;                }	}        /*         * Reread depth and defer reading the colour registers until here         * in case we changed bpp above.         */	pVMWARE->depth = vmwareReadReg(pVMWARE, SVGA_REG_DEPTH);	pVMWARE->weight.red =           vmwareCalculateWeight(vmwareReadReg(pVMWARE, SVGA_REG_RED_MASK));	pVMWARE->weight.green =           vmwareCalculateWeight(vmwareReadReg(pVMWARE, SVGA_REG_GREEN_MASK));	pVMWARE->weight.blue =           vmwareCalculateWeight(vmwareReadReg(pVMWARE, SVGA_REG_BLUE_MASK));	pVMWARE->offset.blue = 0;	pVMWARE->offset.green = pVMWARE->weight.blue;	pVMWARE->offset.red = pVMWARE->weight.green + pVMWARE->offset.green;	pVMWARE->defaultVisual = vmwareReadReg(pVMWARE, SVGA_REG_PSEUDOCOLOR) ?           PseudoColor : TrueColor;	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED,                       2, "depth: %d\n", pVMWARE->depth);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED,                       2, "bpp:   %d\n", pVMWARE->bitsPerPixel);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED,                       2, "w.red: %d\n", pVMWARE->weight.red);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED,                       2, "w.grn: %d\n", pVMWARE->weight.green);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED,                       2, "w.blu: %d\n", pVMWARE->weight.blue);	xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED,                       2, "vis:   %d\n", pVMWARE->defaultVisual);	if (pScrn->depth != pVMWARE->depth) {                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,                           "Currently unavailable depth of %d requested.\n"                           "\tThe guest X server must run at the same depth as the host (which\n"                           "\tis currently %d).  This is automatically detected.  Please do not\n"                           "\tspecify a depth on the command line or via the config file.\n",                            pScrn->depth, pVMWARE->depth);                return FALSE;	}	xf86PrintDepthBpp(pScrn);#if 0	if (pScrn->depth == 24 && pix24bpp == 0) {		pix24bpp = xf86GetBppFromDepth(pScrn, 24);	}#endif	if (pScrn->depth > 8) {		rgb zeros = { 0, 0, 0 };		if (!xf86SetWeight(pScrn, pVMWARE->weight, zeros)) {			return FALSE;		}		/* FIXME check returned weight */	}	if (!xf86SetDefaultVisual(pScrn, pVMWARE->defaultVisual)) {		return FALSE;	}	if (pScrn->defaultVisual != pVMWARE->defaultVisual) {		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,			   "Given visual (%d) is not supported by this driver (%d is required)\n",			   pScrn->defaultVisual, pVMWARE->defaultVisual);		return FALSE;	}#if 0	bytesPerPixel = pScrn->bitsPerPixel / 8;#endif	pScrn->progClock = TRUE;#if 0 /* MGA does not do this */	if (pScrn->visual != 0) {	/* FIXME */		/* print error message */		return FALSE;	}#endif	xf86CollectOptions(pScrn, NULL);	if (!(options = xalloc(sizeof(VMWAREOptions))))		return FALSE;	memcpy(options, VMWAREOptions, sizeof(VMWAREOptions));	xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);	if (pScrn->depth <= 8) {		pScrn->rgbBits = 8;	}	from = X_PROBED;	pScrn->chipset = (char*)xf86TokenToString(VMWAREChipsets, pVMWARE->PciInfo->chipType);	if (!pScrn->chipset) {		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "ChipID 0x%04 is not recognised\n", pVMWARE->PciInfo->chipType);		return FALSE;	}	from = X_DEFAULT;	pVMWARE->hwCursor = TRUE;	if (xf86GetOptValBool(options, OPTION_HW_CURSOR, &pVMWARE->hwCursor)) {		from = X_CONFIG;	}	if (pVMWARE->hwCursor && !(pVMWARE->vmwareCapability & SVGA_CAP_CURSOR)) {		xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "HW cursor is not supported in this configuration\n");		from = X_PROBED;		pVMWARE->hwCursor = FALSE;	}	xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",		pVMWARE->hwCursor ? "HW" : "SW");	if (xf86IsOptionSet(options, OPTION_NOACCEL)) {		pVMWARE->noAccel = TRUE;		xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");		pVMWARE->vmwareCapability = 0;	} else {		pVMWARE->noAccel = FALSE;	}	pScrn->videoRam = pVMWARE->videoRam / 1024;	pScrn->memPhysBase = pVMWARE->memPhysBase;	xfree(options);	{		Gamma zeros = { 0.0, 0.0, 0.0 };		if (!xf86SetGamma(pScrn, zeros)) {			return FALSE;		}	}#if 0	if ((i = xf86GetPciInfoForScreen(pScrn->scrnIndex, &pciList, NULL)) != 1) {		/* print error message */		VMWAREFreeRec(pScrn);		if (i > 0) {			xfree(pciList);		}		return FALSE;	}#endif	clockRanges = xnfcalloc(sizeof(ClockRange), 1);	clockRanges->next = NULL;	clockRanges->minClock = 1;	clockRanges->maxClock = 400000000;	clockRanges->clockIndex = -1;	clockRanges->interlaceAllowed = FALSE;	clockRanges->doubleScanAllowed = FALSE;	clockRanges->ClockMulFactor = 1;	clockRanges->ClockDivFactor = 1;	i = xf86ValidateModes(pScrn, pScrn->monitor->Modes, pScrn->display->modes,			clockRanges, NULL, 256, pVMWARE->maxWidth, 32 * 32,			128, pVMWARE->maxHeight,			pScrn->display->virtualX, pScrn->display->virtualY,			pVMWARE->videoRam,			LOOKUP_BEST_REFRESH);	if (i == -1) {		VMWAREFreeRec(pScrn);		return FALSE;	}	xf86PruneDriverModes(pScrn);	if (i == 0 || pScrn->modes == NULL) {		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n");		VMWAREFreeRec(pScrn);		return FALSE;	}	xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V);	pScrn->currentMode = pScrn->modes;	xf86PrintModes(pScrn);	xf86SetDpi(pScrn, 0, 0);	if (!xf86LoadSubModule(pScrn, "fb")) {		VMWAREFreeRec(pScrn);		return FALSE;	}	xf86LoaderReqSymLists(fbSymbols, NULL);#if 0	/* XXX This driver doesn't use XAA! */	if (!pVMWARE->noAccel || pVMWARE->hwCursor) {		if (!xf86LoadSubModule(pScrn, "xaa")) {			VMWAREFreeRec(pScrn);			return FALSE;		}		xf86LoaderReqSymLists(xaaSymbols, NULL);	}#endif	return TRUE;}