Path: blob/master/utils/xorg-deps/xf86-video-dummy/v0.3.8/src/dummy_driver.c
1013 views
1/*2* Copyright 2002, SuSE Linux AG, Author: Egbert Eich3*/45#ifdef HAVE_CONFIG_H6#include "config.h"7#endif89/* All drivers should typically include these */10#include "xf86.h"11#include "xf86_OSproc.h"1213/* All drivers initialising the SW cursor need this */14#include "mipointer.h"1516/* All drivers using the mi colormap manipulation need this */17#include "micmap.h"1819/* identifying atom needed by magnifiers */20#include <X11/Xatom.h>21#include "property.h"2223#include "xf86cmap.h"2425#include "xf86fbman.h"2627#include "fb.h"2829#include "picturestr.h"3031#ifdef XvExtension32#include "xf86xv.h"33#include <X11/extensions/Xv.h>34#endif3536/*37* Driver data structures.38*/39#include "dummy.h"4041/* These need to be checked */42#include <X11/X.h>43#include <X11/Xproto.h>44#include "scrnintstr.h"45#include "servermd.h"46#ifdef USE_DGA47#define _XF86DGA_SERVER_48#include <X11/extensions/xf86dgaproto.h>49#endif5051/* Mandatory functions */52static const OptionInfoRec * DUMMYAvailableOptions(int chipid, int busid);53static void DUMMYIdentify(int flags);54static Bool DUMMYProbe(DriverPtr drv, int flags);55static Bool DUMMYPreInit(ScrnInfoPtr pScrn, int flags);56static Bool DUMMYScreenInit(SCREEN_INIT_ARGS_DECL);57static Bool DUMMYEnterVT(VT_FUNC_ARGS_DECL);58static void DUMMYLeaveVT(VT_FUNC_ARGS_DECL);59static Bool DUMMYCloseScreen(CLOSE_SCREEN_ARGS_DECL);60static Bool DUMMYCreateWindow(WindowPtr pWin);61static void DUMMYFreeScreen(FREE_SCREEN_ARGS_DECL);62static ModeStatus DUMMYValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode,63Bool verbose, int flags);64static Bool DUMMYSaveScreen(ScreenPtr pScreen, int mode);6566/* Internally used functions */67static Bool dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,68pointer ptr);697071/* static void DUMMYDisplayPowerManagementSet(ScrnInfoPtr pScrn, */72/* int PowerManagementMode, int flags); */7374#define DUMMY_VERSION 400075#define DUMMY_NAME "DUMMY"76#define DUMMY_DRIVER_NAME "dummy"7778#define DUMMY_MAJOR_VERSION PACKAGE_VERSION_MAJOR79#define DUMMY_MINOR_VERSION PACKAGE_VERSION_MINOR80#define DUMMY_PATCHLEVEL PACKAGE_VERSION_PATCHLEVEL8182#define DUMMY_MAX_WIDTH 3276783#define DUMMY_MAX_HEIGHT 327678485/*86* This is intentionally screen-independent. It indicates the binding87* choice made in the first PreInit.88*/89static int pix24bpp = 0;909192/*93* This contains the functions needed by the server after loading the driver94* module. It must be supplied, and gets passed back by the SetupProc95* function in the dynamic case. In the static case, a reference to this96* is compiled in, and this requires that the name of this DriverRec be97* an upper-case version of the driver name.98*/99100_X_EXPORT DriverRec DUMMY = {101DUMMY_VERSION,102DUMMY_DRIVER_NAME,103DUMMYIdentify,104DUMMYProbe,105DUMMYAvailableOptions,106NULL,1070,108dummyDriverFunc109};110111static SymTabRec DUMMYChipsets[] = {112{ DUMMY_CHIP, "dummy" },113{ -1, NULL }114};115116typedef enum {117OPTION_SW_CURSOR118} DUMMYOpts;119120static const OptionInfoRec DUMMYOptions[] = {121{ OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE },122{ -1, NULL, OPTV_NONE, {0}, FALSE }123};124125#ifdef XFree86LOADER126127static MODULESETUPPROTO(dummySetup);128129static XF86ModuleVersionInfo dummyVersRec =130{131"dummy",132MODULEVENDORSTRING,133MODINFOSTRING1,134MODINFOSTRING2,135XORG_VERSION_CURRENT,136DUMMY_MAJOR_VERSION, DUMMY_MINOR_VERSION, DUMMY_PATCHLEVEL,137ABI_CLASS_VIDEODRV,138ABI_VIDEODRV_VERSION,139MOD_CLASS_VIDEODRV,140{0,0,0,0}141};142143/*144* This is the module init data.145* Its name has to be the driver name followed by ModuleData146*/147_X_EXPORT XF86ModuleData dummyModuleData = { &dummyVersRec, dummySetup, NULL };148149static pointer150dummySetup(pointer module, pointer opts, int *errmaj, int *errmin)151{152static Bool setupDone = FALSE;153154if (!setupDone) {155setupDone = TRUE;156xf86AddDriver(&DUMMY, module, HaveDriverFuncs);157158/*159* Modules that this driver always requires can be loaded here160* by calling LoadSubModule().161*/162163/*164* The return value must be non-NULL on success even though there165* is no TearDownProc.166*/167return (pointer)1;168} else {169if (errmaj) *errmaj = LDR_ONCEONLY;170return NULL;171}172}173174#endif /* XFree86LOADER */175176static Bool177DUMMYGetRec(ScrnInfoPtr pScrn)178{179/*180* Allocate a DUMMYRec, and hook it into pScrn->driverPrivate.181* pScrn->driverPrivate is initialised to NULL, so we can check if182* the allocation has already been done.183*/184if (pScrn->driverPrivate != NULL)185return TRUE;186187pScrn->driverPrivate = xnfcalloc(sizeof(DUMMYRec), 1);188189if (pScrn->driverPrivate == NULL)190return FALSE;191return TRUE;192}193194static void195DUMMYFreeRec(ScrnInfoPtr pScrn)196{197if (pScrn->driverPrivate == NULL)198return;199free(pScrn->driverPrivate);200pScrn->driverPrivate = NULL;201}202203static const OptionInfoRec *204DUMMYAvailableOptions(int chipid, int busid)205{206return DUMMYOptions;207}208209/* Mandatory */210static void211DUMMYIdentify(int flags)212{213xf86PrintChipsets(DUMMY_NAME, "Driver for Dummy chipsets",214DUMMYChipsets);215}216217/* Mandatory */218static Bool219DUMMYProbe(DriverPtr drv, int flags)220{221Bool foundScreen = FALSE;222int numDevSections, numUsed;223GDevPtr *devSections;224int i;225226if (flags & PROBE_DETECT)227return FALSE;228/*229* Find the config file Device sections that match this230* driver, and return if there are none.231*/232if ((numDevSections = xf86MatchDevice(DUMMY_DRIVER_NAME,233&devSections)) <= 0) {234return FALSE;235}236237numUsed = numDevSections;238239if (numUsed > 0) {240241for (i = 0; i < numUsed; i++) {242ScrnInfoPtr pScrn = NULL;243int entityIndex =244xf86ClaimNoSlot(drv,DUMMY_CHIP,devSections[i],TRUE);245/* Allocate a ScrnInfoRec and claim the slot */246if ((pScrn = xf86AllocateScreen(drv,0 ))) {247xf86AddEntityToScreen(pScrn,entityIndex);248pScrn->driverVersion = DUMMY_VERSION;249pScrn->driverName = DUMMY_DRIVER_NAME;250pScrn->name = DUMMY_NAME;251pScrn->Probe = DUMMYProbe;252pScrn->PreInit = DUMMYPreInit;253pScrn->ScreenInit = DUMMYScreenInit;254pScrn->SwitchMode = DUMMYSwitchMode;255pScrn->AdjustFrame = DUMMYAdjustFrame;256pScrn->EnterVT = DUMMYEnterVT;257pScrn->LeaveVT = DUMMYLeaveVT;258pScrn->FreeScreen = DUMMYFreeScreen;259pScrn->ValidMode = DUMMYValidMode;260261foundScreen = TRUE;262}263}264}265return foundScreen;266}267268# define RETURN \269{ DUMMYFreeRec(pScrn);\270return FALSE;\271}272273/* Mandatory */274Bool275DUMMYPreInit(ScrnInfoPtr pScrn, int flags)276{277ClockRangePtr clockRanges;278int i;279DUMMYPtr dPtr;280int maxClock = 300000;281GDevPtr device = xf86GetEntityInfo(pScrn->entityList[0])->device;282283if (flags & PROBE_DETECT)284return TRUE;285286/* Allocate the DummyRec driverPrivate */287if (!DUMMYGetRec(pScrn)) {288return FALSE;289}290291dPtr = DUMMYPTR(pScrn);292293pScrn->chipset = (char *)xf86TokenToString(DUMMYChipsets,294DUMMY_CHIP);295296xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Chipset is a DUMMY\n");297298pScrn->monitor = pScrn->confScreen->monitor;299300if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support24bppFb | Support32bppFb))301return FALSE;302else {303/* Check that the returned depth is one we support */304switch (pScrn->depth) {305case 8:306case 15:307case 16:308case 24:309break;310default:311xf86DrvMsg(pScrn->scrnIndex, X_ERROR,312"Given depth (%d) is not supported by this driver\n",313pScrn->depth);314return FALSE;315}316}317318xf86PrintDepthBpp(pScrn);319if (pScrn->depth == 8)320pScrn->rgbBits = 8;321322/* Get the depth24 pixmap format */323if (pScrn->depth == 24 && pix24bpp == 0)324pix24bpp = xf86GetBppFromDepth(pScrn, 24);325326/*327* This must happen after pScrn->display has been set because328* xf86SetWeight references it.329*/330if (pScrn->depth > 8) {331/* The defaults are OK for us */332rgb zeros = {0, 0, 0};333334if (!xf86SetWeight(pScrn, zeros, zeros)) {335return FALSE;336} else {337/* XXX check that weight returned is supported */338;339}340}341342if (!xf86SetDefaultVisual(pScrn, -1))343return FALSE;344345if (pScrn->depth > 1) {346Gamma zeros = {0.0, 0.0, 0.0};347348if (!xf86SetGamma(pScrn, zeros))349return FALSE;350}351352xf86CollectOptions(pScrn, device->options);353/* Process the options */354if (!(dPtr->Options = malloc(sizeof(DUMMYOptions))))355return FALSE;356memcpy(dPtr->Options, DUMMYOptions, sizeof(DUMMYOptions));357358xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, dPtr->Options);359360xf86GetOptValBool(dPtr->Options, OPTION_SW_CURSOR,&dPtr->swCursor);361362if (device->videoRam != 0) {363pScrn->videoRam = device->videoRam;364xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "VideoRAM: %d kByte\n",365pScrn->videoRam);366} else {367pScrn->videoRam = 4096;368xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kByte\n",369pScrn->videoRam);370}371372if (device->dacSpeeds[0] != 0) {373maxClock = device->dacSpeeds[0];374xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Max Clock: %d kHz\n",375maxClock);376} else {377xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Max Clock: %d kHz\n",378maxClock);379}380381pScrn->progClock = TRUE;382/*383* Setup the ClockRanges, which describe what clock ranges are available,384* and what sort of modes they can be used for.385*/386clockRanges = (ClockRangePtr)xnfcalloc(sizeof(ClockRange), 1);387clockRanges->next = NULL;388clockRanges->ClockMulFactor = 1;389clockRanges->minClock = 11000; /* guessed ยงยงยง */390clockRanges->maxClock = maxClock;391clockRanges->clockIndex = -1; /* programmable */392clockRanges->interlaceAllowed = TRUE;393clockRanges->doubleScanAllowed = TRUE;394395/* Subtract memory for HW cursor */396397398{399int apertureSize = (pScrn->videoRam * 1024);400i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,401pScrn->display->modes, clockRanges,402NULL, 256, DUMMY_MAX_WIDTH,403(8 * pScrn->bitsPerPixel),404128, DUMMY_MAX_HEIGHT, pScrn->display->virtualX,405pScrn->display->virtualY, apertureSize,406LOOKUP_BEST_REFRESH);407408if (i == -1)409RETURN;410}411412/* Prune the modes marked as invalid */413xf86PruneDriverModes(pScrn);414415if (i == 0 || pScrn->modes == NULL) {416xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n");417RETURN;418}419420/*421* Set the CRTC parameters for all of the modes based on the type422* of mode, and the chipset's interlace requirements.423*424* Calling this is required if the mode->Crtc* values are used by the425* driver and if the driver doesn't provide code to set them. They426* are not pre-initialised at all.427*/428xf86SetCrtcForModes(pScrn, 0);429430/* Set the current mode to the first in the list */431pScrn->currentMode = pScrn->modes;432433/* Print the list of modes being used */434xf86PrintModes(pScrn);435436/* If monitor resolution is set on the command line, use it */437xf86SetDpi(pScrn, 0, 0);438439if (xf86LoadSubModule(pScrn, "fb") == NULL) {440RETURN;441}442443if (!dPtr->swCursor) {444if (!xf86LoadSubModule(pScrn, "ramdac"))445RETURN;446}447448/* We have no contiguous physical fb in physical memory */449pScrn->memPhysBase = 0;450pScrn->fbOffset = 0;451452return TRUE;453}454#undef RETURN455456/* Mandatory */457static Bool458DUMMYEnterVT(VT_FUNC_ARGS_DECL)459{460return TRUE;461}462463/* Mandatory */464static void465DUMMYLeaveVT(VT_FUNC_ARGS_DECL)466{467}468469static void470DUMMYLoadPalette(471ScrnInfoPtr pScrn,472int numColors,473int *indices,474LOCO *colors,475VisualPtr pVisual476){477int i, index, shift, Gshift;478DUMMYPtr dPtr = DUMMYPTR(pScrn);479480switch(pScrn->depth) {481case 15:482shift = Gshift = 1;483break;484case 16:485shift = 0;486Gshift = 0;487break;488default:489shift = Gshift = 0;490break;491}492493for(i = 0; i < numColors; i++) {494index = indices[i];495dPtr->colors[index].red = colors[index].red << shift;496dPtr->colors[index].green = colors[index].green << Gshift;497dPtr->colors[index].blue = colors[index].blue << shift;498}499500}501502static ScrnInfoPtr DUMMYScrn; /* static-globalize it */503504/* Mandatory */505static Bool506DUMMYScreenInit(SCREEN_INIT_ARGS_DECL)507{508ScrnInfoPtr pScrn;509DUMMYPtr dPtr;510int ret;511VisualPtr visual;512513/*514* we need to get the ScrnInfoRec for this screen, so let's allocate515* one first thing516*/517pScrn = xf86ScreenToScrn(pScreen);518dPtr = DUMMYPTR(pScrn);519DUMMYScrn = pScrn;520521522if (!(dPtr->FBBase = malloc(pScrn->videoRam * 1024)))523return FALSE;524525/*526* Reset visual list.527*/528miClearVisualTypes();529530/* Setup the visuals we support. */531532if (!miSetVisualTypes(pScrn->depth,533miGetDefaultVisualMask(pScrn->depth),534pScrn->rgbBits, pScrn->defaultVisual))535return FALSE;536537if (!miSetPixmapDepths ()) return FALSE;538539/*540* Call the framebuffer layer's ScreenInit function, and fill in other541* pScreen fields.542*/543ret = fbScreenInit(pScreen, dPtr->FBBase,544pScrn->virtualX, pScrn->virtualY,545pScrn->xDpi, pScrn->yDpi,546pScrn->displayWidth, pScrn->bitsPerPixel);547if (!ret)548return FALSE;549550if (pScrn->depth > 8) {551/* Fixup RGB ordering */552visual = pScreen->visuals + pScreen->numVisuals;553while (--visual >= pScreen->visuals) {554if ((visual->class | DynamicClass) == DirectColor) {555visual->offsetRed = pScrn->offset.red;556visual->offsetGreen = pScrn->offset.green;557visual->offsetBlue = pScrn->offset.blue;558visual->redMask = pScrn->mask.red;559visual->greenMask = pScrn->mask.green;560visual->blueMask = pScrn->mask.blue;561}562}563}564565/* must be after RGB ordering fixed */566fbPictureInit(pScreen, 0, 0);567568xf86SetBlackWhitePixels(pScreen);569570#ifdef USE_DGA571DUMMYDGAInit(pScreen);572#endif573574if (dPtr->swCursor)575xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using Software Cursor.\n");576577{578579580BoxRec AvailFBArea;581int lines = pScrn->videoRam * 1024 /582(pScrn->displayWidth * (pScrn->bitsPerPixel >> 3));583AvailFBArea.x1 = 0;584AvailFBArea.y1 = 0;585AvailFBArea.x2 = pScrn->displayWidth;586AvailFBArea.y2 = lines;587xf86InitFBManager(pScreen, &AvailFBArea);588589xf86DrvMsg(pScrn->scrnIndex, X_INFO,590"Using %i scanlines of offscreen memory \n"591, lines - pScrn->virtualY);592}593594xf86SetBackingStore(pScreen);595xf86SetSilkenMouse(pScreen);596597/* Initialise cursor functions */598miDCInitialize (pScreen, xf86GetPointerScreenFuncs());599600601if (!dPtr->swCursor) {602/* HW cursor functions */603if (!DUMMYCursorInit(pScreen)) {604xf86DrvMsg(pScrn->scrnIndex, X_ERROR,605"Hardware cursor initialization failed\n");606return FALSE;607}608}609610/* Initialise default colourmap */611if(!miCreateDefColormap(pScreen))612return FALSE;613614if (!xf86HandleColormaps(pScreen, 256, pScrn->rgbBits,615DUMMYLoadPalette, NULL,616CMAP_PALETTED_TRUECOLOR617| CMAP_RELOAD_ON_MODE_SWITCH))618return FALSE;619620/* DUMMYInitVideo(pScreen); */621622pScreen->SaveScreen = DUMMYSaveScreen;623624625/* Wrap the current CloseScreen function */626dPtr->CloseScreen = pScreen->CloseScreen;627pScreen->CloseScreen = DUMMYCloseScreen;628629/* Wrap the current CreateWindow function */630dPtr->CreateWindow = pScreen->CreateWindow;631pScreen->CreateWindow = DUMMYCreateWindow;632633/* Report any unused options (only for the first generation) */634if (serverGeneration == 1) {635xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);636}637638return TRUE;639}640641/* Mandatory */642Bool643DUMMYSwitchMode(SWITCH_MODE_ARGS_DECL)644{645return TRUE;646}647648/* Mandatory */649void650DUMMYAdjustFrame(ADJUST_FRAME_ARGS_DECL)651{652}653654/* Mandatory */655static Bool656DUMMYCloseScreen(CLOSE_SCREEN_ARGS_DECL)657{658ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);659DUMMYPtr dPtr = DUMMYPTR(pScrn);660661if(pScrn->vtSema){662free(dPtr->FBBase);663}664665if (dPtr->CursorInfo)666xf86DestroyCursorInfoRec(dPtr->CursorInfo);667668pScrn->vtSema = FALSE;669pScreen->CloseScreen = dPtr->CloseScreen;670return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS);671}672673/* Optional */674static void675DUMMYFreeScreen(FREE_SCREEN_ARGS_DECL)676{677SCRN_INFO_PTR(arg);678DUMMYFreeRec(pScrn);679}680681static Bool682DUMMYSaveScreen(ScreenPtr pScreen, int mode)683{684ScrnInfoPtr pScrn = NULL;685DUMMYPtr dPtr;686687if (pScreen != NULL) {688pScrn = xf86ScreenToScrn(pScreen);689dPtr = DUMMYPTR(pScrn);690691dPtr->screenSaver = xf86IsUnblank(mode);692}693return TRUE;694}695696/* Optional */697static ModeStatus698DUMMYValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)699{700return(MODE_OK);701}702703Atom VFB_PROP = 0;704#define VFB_PROP_NAME "VFB_IDENT"705706static Bool707DUMMYCreateWindow(WindowPtr pWin)708{709ScreenPtr pScreen = pWin->drawable.pScreen;710DUMMYPtr dPtr = DUMMYPTR(DUMMYScrn);711WindowPtr pWinRoot;712int ret;713714pScreen->CreateWindow = dPtr->CreateWindow;715ret = pScreen->CreateWindow(pWin);716dPtr->CreateWindow = pScreen->CreateWindow;717pScreen->CreateWindow = DUMMYCreateWindow;718719if(ret != TRUE)720return(ret);721722if(dPtr->prop == FALSE) {723#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 8724pWinRoot = WindowTable[DUMMYScrn->pScreen->myNum];725#else726pWinRoot = DUMMYScrn->pScreen->root;727#endif728if (! ValidAtom(VFB_PROP))729VFB_PROP = MakeAtom(VFB_PROP_NAME, strlen(VFB_PROP_NAME), 1);730731ret = dixChangeWindowProperty(serverClient, pWinRoot, VFB_PROP,732XA_STRING, 8, PropModeReplace,733(int)4, (pointer)"TRUE", FALSE);734if( ret != Success)735ErrorF("Could not set VFB root window property");736dPtr->prop = TRUE;737738return TRUE;739}740return TRUE;741}742743#ifndef HW_SKIP_CONSOLE744#define HW_SKIP_CONSOLE 4745#endif746747static Bool748dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer ptr)749{750CARD32 *flag;751752switch (op) {753case GET_REQUIRED_HW_INTERFACES:754flag = (CARD32*)ptr;755(*flag) = HW_SKIP_CONSOLE;756return TRUE;757default:758return FALSE;759}760}761762763