From 106bea5ad1bdd5795d6ed625fc6351a161bffa6e Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Wed, 28 May 2008 13:33:07 +0100 Subject: [PATCH 001/122] Initial commit of new modesetting driver --- hw/xfree86/drivers/modesetting/COPYING | 12 + hw/xfree86/drivers/modesetting/Makefile.am | 42 + hw/xfree86/drivers/modesetting/crtc.c | 215 ++++ hw/xfree86/drivers/modesetting/driver.c | 1028 +++++++++++++++++ hw/xfree86/drivers/modesetting/driver.h | 88 ++ hw/xfree86/drivers/modesetting/exa.c | 235 ++++ .../drivers/modesetting/modesetting.man | 0 hw/xfree86/drivers/modesetting/output.c | 285 +++++ 8 files changed, 1905 insertions(+) create mode 100644 hw/xfree86/drivers/modesetting/COPYING create mode 100644 hw/xfree86/drivers/modesetting/Makefile.am create mode 100644 hw/xfree86/drivers/modesetting/crtc.c create mode 100644 hw/xfree86/drivers/modesetting/driver.c create mode 100644 hw/xfree86/drivers/modesetting/driver.h create mode 100644 hw/xfree86/drivers/modesetting/exa.c create mode 100644 hw/xfree86/drivers/modesetting/modesetting.man create mode 100644 hw/xfree86/drivers/modesetting/output.c diff --git a/hw/xfree86/drivers/modesetting/COPYING b/hw/xfree86/drivers/modesetting/COPYING new file mode 100644 index 000000000..7f33cbfd2 --- /dev/null +++ b/hw/xfree86/drivers/modesetting/COPYING @@ -0,0 +1,12 @@ +This is a stub file. This package has not yet had its complete licensing +information compiled. Please see the individual source files for details on +your rights to use and modify this software. + +Please submit updated COPYING files to the Xorg bugzilla: + +https://bugs.freedesktop.org/enter_bug.cgi?product=xorg + +All licensing questions regarding this software should be directed at the +Xorg mailing list: + +http://lists.freedesktop.org/mailman/listinfo/xorg diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am new file mode 100644 index 000000000..17d884fde --- /dev/null +++ b/hw/xfree86/drivers/modesetting/Makefile.am @@ -0,0 +1,42 @@ +# Copyright 2005 Adam Jackson. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# on the rights to use, copy, modify, merge, publish, distribute, sub +# license, and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +# ADAM JACKSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +SUBDIRS = + +# this is obnoxious: +# -module lets us name the module exactly how we want +# -avoid-version prevents gratuitous .0.0.0 version numbers on the end +# _ladir passes a dummy rpath to libtool so the thing will actually link +# TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. + +AM_CFLAGS = @WARN_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLAGS@ \ + @XMODES_CFLAGS@ + +modesetting_drv_la_LTLIBRARIES = modesetting_drv.la +modesetting_drv_la_LDFLAGS = -module -avoid-version -ldrm +modesetting_drv_ladir = @moduledir@/drivers + +modesetting_drv_la_SOURCES = \ + driver.c \ + driver.h \ + output.c \ + crtc.c \ + exa.c + +EXTRA_DIST = diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c new file mode 100644 index 000000000..f168126fb --- /dev/null +++ b/hw/xfree86/drivers/modesetting/crtc.c @@ -0,0 +1,215 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include "driver.h" +#include "xf86Modes.h" + +#define DPMS_SERVER +#include + +static void +crtc_dpms(xf86CrtcPtr crtc, int mode) +{ + ScrnInfoPtr pScrn = crtc->scrn; + + switch (mode) { + case DPMSModeOn: + case DPMSModeStandby: + case DPMSModeSuspend: + break; + case DPMSModeOff: + break; + } +} + +static Bool +crtc_lock(xf86CrtcPtr crtc) +{ + return FALSE; +} + +static void +crtc_unlock(xf86CrtcPtr crtc) +{ +} + +static void +crtc_prepare(xf86CrtcPtr crtc) +{ +} + +static void +crtc_commit(xf86CrtcPtr crtc) +{ +} + +static Bool +crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode, + DisplayModePtr adjusted_mode) +{ + return TRUE; +} + +static void +crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, + DisplayModePtr adjusted_mode, int x, int y) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + modesettingPtr ms = modesettingPTR(crtc->scrn); + xf86OutputPtr output = config->output[config->compat_output]; + drmModeOutputPtr drm_output = output->driver_private; + drmModeCrtcPtr drm_crtc = crtc->driver_private; + struct drm_mode_modeinfo drm_mode; + + drm_mode.clock = mode->Clock; + drm_mode.hdisplay = mode->HDisplay; + drm_mode.hsync_start = mode->HSyncStart; + drm_mode.hsync_end = mode->HSyncEnd; + drm_mode.htotal = mode->HTotal; + drm_mode.vdisplay = mode->VDisplay; + drm_mode.vsync_start = mode->VSyncStart; + drm_mode.vsync_end = mode->VSyncEnd; + drm_mode.vtotal = mode->VTotal; + drm_mode.flags = mode->Flags; + drm_mode.hskew = mode->HSkew; + drm_mode.vscan = mode->VScan; + drm_mode.vrefresh = mode->VRefresh; + strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN); + + drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y, + &drm_output->output_id, 1, &drm_mode); +} + +void +crtc_load_lut(xf86CrtcPtr crtc) +{ + ScrnInfoPtr pScrn = crtc->scrn; +} + +static void +crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue, + int size) +{ +} + +static void * +crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height) +{ + ScrnInfoPtr pScrn = crtc->scrn; + + return NULL; +} + +static PixmapPtr +crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height) +{ + ScrnInfoPtr pScrn = crtc->scrn; + + return NULL; +} + +static void +crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data) +{ + ScrnInfoPtr pScrn = crtc->scrn; +} + +static void +crtc_destroy(xf86CrtcPtr crtc) +{ + drmModeFreeCrtc(crtc->driver_private); +} + +static const xf86CrtcFuncsRec crtc_funcs = { + .dpms = crtc_dpms, + .save = NULL, /* XXX */ + .restore = NULL, /* XXX */ + .lock = crtc_lock, + .unlock = crtc_unlock, + .mode_fixup = crtc_mode_fixup, + .prepare = crtc_prepare, + .mode_set = crtc_mode_set, + .commit = crtc_commit, + .gamma_set = crtc_gamma_set, + .shadow_create = crtc_shadow_create, + .shadow_allocate = crtc_shadow_allocate, + .shadow_destroy = crtc_shadow_destroy, +// .set_cursor_colors = crtc_set_cursor_colors, +// .set_cursor_position = crtc_set_cursor_position, +// .show_cursor = crtc_show_cursor, +// .hide_cursor = crtc_hide_cursor, +// .load_cursor_image = crtc_load_cursor_image, +// .load_cursor_argb = crtc_load_cursor_argb, + .destroy = crtc_destroy, /* XXX */ +}; + +void +crtc_init(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + xf86CrtcPtr crtc; + drmModeResPtr res; + drmModeCrtcPtr drm_crtc = NULL; + int c, k, p; + + res = drmModeGetResources(ms->fd); + if (res == 0) { + ErrorF("Failed drmModeGetResources %d\n",errno); + return; + } + + for (c = 0; c < res->count_crtcs; c++) { + drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]); + if (!drm_crtc) + continue; + + crtc = xf86CrtcCreate(pScrn, &crtc_funcs); + if (crtc == NULL) + goto out; + + crtc->driver_private = drm_crtc; + } + +out: + drmModeFreeResources(res); +} diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c new file mode 100644 index 000000000..ba6bfdf53 --- /dev/null +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -0,0 +1,1028 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "xf86.h" +#include "xf86_OSproc.h" +#include "compiler.h" +#include "xf86RAC.h" +#include "xf86PciInfo.h" +#include "xf86Pci.h" +#include "xf86Resources.h" +#include "mipointer.h" +#include "micmap.h" +#include "shadowfb.h" +#include +#include "fb.h" +#include "edid.h" +#include "xf86i2c.h" +#include "xf86Crtc.h" +#include "miscstruct.h" +#include "dixstruct.h" +#include "xf86xv.h" +#include +#include "shadow.h" +#include +#if XSERVER_LIBPCIACCESS +#include +#endif + +#include "driver.h" + +static void AdjustFrame(int scrnIndex, int x, int y, int flags); +static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen); +static Bool EnterVT(int scrnIndex, int flags); +static Bool SaveHWState(ScrnInfoPtr pScrn); +static Bool RestoreHWState(ScrnInfoPtr pScrn); +static void Identify(int flags); +static const OptionInfoRec *AvailableOptions(int chipid, int busid); +static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags); +static void FreeScreen(int scrnIndex, int flags); +static void LeaveVT(int scrnIndex, int flags); +static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags); +static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv); +static Bool PreInit(ScrnInfoPtr pScrn, int flags); +#if XSERVER_LIBPCIACCESS +static Bool +pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data); +#else +static Bool Probe(DriverPtr drv, int flags); +#endif + +#if XSERVER_LIBPCIACCESS +static const struct pci_id_match device_match[] = { + {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0}, + {0, 0, 0}, +}; +#endif + +_X_EXPORT DriverRec modesetting = { + 1, + "modesetting", + Identify, +#if XSERVER_LIBPCIACCESS + NULL, +#else + Probe, +#endif + AvailableOptions, + NULL, + 0, + NULL, +#if XSERVER_LIBPCIACCESS + device_match, + pci_probe +#endif +}; + +static SymTabRec Chipsets[] = { + {0x2592, "Intel Graphics Device"}, + {-1, NULL} +}; + +static PciChipsets PciDevices[] = { + {0x2592, 0x2592, RES_SHARED_VGA}, + {-1, -1, RES_UNDEFINED} +}; + +typedef enum +{ + OPTION_NOACCEL, + OPTION_SW_CURSOR, + OPTION_SHADOWFB, +} modesettingOpts; + +static const OptionInfoRec Options[] = { + {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE}, + {-1, NULL, OPTV_NONE, {0}, FALSE} +}; + +static const char *fbSymbols[] = { + "fbPictureInit", + "fbScreenInit", + NULL +}; + +static const char *ddcSymbols[] = { + "xf86PrintEDID", + "xf86SetDDCproperties", + NULL +}; + +static const char *shadowSymbols[] = { + "shadowInit", + "shadowUpdatePackedWeak", + NULL +}; + +static const char *i2cSymbols[] = { + "xf86CreateI2CBusRec", + "xf86I2CBusInit", + NULL +}; + +int modesettingEntityIndex = -1; + +static MODULESETUPPROTO(Setup); + +static XF86ModuleVersionInfo VersRec = { + "modesetting", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL, + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +_X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL }; + +static pointer +Setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&modesetting, module, HaveDriverFuncs); + + /* + * Tell the loader about symbols from other modules that this module + * might refer to. + */ + LoaderRefSymLists(fbSymbols, + shadowSymbols, ddcSymbols, NULL); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +Identify(int flags) +{ + xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", + Chipsets); +} + +static const OptionInfoRec * +AvailableOptions(int chipid, int busid) +{ + return Options; +} + +#if XSERVER_LIBPCIACCESS +static Bool +pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + DevUnion *private; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "modesetting"; + scrn->name = "modesetting"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + switch (device->device_id) { + case 0x2592: + scrn->PreInit = PreInit; + scrn->ScreenInit = ScreenInit; + scrn->SwitchMode = SwitchMode; + scrn->AdjustFrame = AdjustFrame; + scrn->EnterVT = EnterVT; + scrn->LeaveVT = LeaveVT; + scrn->FreeScreen = FreeScreen; + scrn->ValidMode = ValidMode; + break; + } + } + return scrn != NULL; +} +#else +static Bool +Probe(DriverPtr drv, int flags) +{ + int i, numUsed, numDevSections, *usedChips; + EntPtr msEnt = NULL; + DevUnion *pPriv; + GDevPtr *devSections; + Bool foundScreen = FALSE; + pciVideoPtr *VideoInfo; + pciVideoPtr *ppPci; + int numDevs; + + /* + * Find the config file Device sections that match this + * driver, and return if there are none. + */ + if ((numDevSections = + xf86MatchDevice("modesetting", &devSections)) <= 0) { + return FALSE; + } + + /* + * This probing is just checking the PCI data the server already + * collected. + */ + if (!(VideoInfo = xf86GetPciVideoInfo())) + return FALSE; + +#if 0 + numUsed = 0; + for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) { + for (numDevs = 0; numDevs < numDevSections; numDevs++) { + if (devSections[numDevs]->busID && *devSections[numDevs]->busID) { + if (xf86ComparePciBusString(devSections[numDevs]->busID, (*ppPci)->bus, (*ppPci)->device, (*ppPci)->func)) { + /* Claim slot */ + if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device, + (*ppPci)->func)) { + usedChips[numUsed++] = xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device, + (*ppPci)->func, drv, (*ppPci)->chipType, + NULL, TRUE); + ErrorF("CLAIMED %d %d %d\n",(*ppPci)->bus,(*ppPci)->device, (*ppPci)->func); + } + } + } + } + } +#else + /* Look for Intel i8xx devices. */ + numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL, + Chipsets, PciDevices, + devSections, numDevSections, + drv, &usedChips); +#endif + + if (flags & PROBE_DETECT) { + if (numUsed > 0) + foundScreen = TRUE; + } else { + ErrorF("NUMUSED %d\n",numUsed); + for (i = 0; i < numUsed; i++) { + ScrnInfoPtr pScrn = NULL; + + /* Allocate new ScrnInfoRec and claim the slot */ + if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i], + PciDevices, NULL, NULL, NULL, + NULL, NULL))) { + EntityInfoPtr pEnt; + + pEnt = xf86GetEntityInfo(usedChips[i]); + + pScrn->driverVersion = 1; + pScrn->driverName = "modesetting"; + pScrn->name = "modesetting"; + pScrn->Probe = Probe; + foundScreen = TRUE; + { + /* Allocate an entity private if necessary */ + if (modesettingEntityIndex < 0) + modesettingEntityIndex = xf86AllocateEntityPrivateIndex(); + + pPriv = xf86GetEntityPrivate(pScrn->entityList[0], + modesettingEntityIndex); + if (!pPriv->ptr) { + pPriv->ptr = xnfcalloc(sizeof(EntRec), 1); + msEnt = pPriv->ptr; + msEnt->lastInstance = -1; + } else { + msEnt = pPriv->ptr; + } + + /* + * Set the entity instance for this instance of the driver. + * For dual head per card, instance 0 is the "master" + * instance, driving the primary head, and instance 1 is + * the "slave". + */ + msEnt->lastInstance++; + xf86SetEntityInstanceForScreen(pScrn, + pScrn->entityList[0], + msEnt->lastInstance); + pScrn->PreInit = PreInit; + pScrn->ScreenInit = ScreenInit; + pScrn->SwitchMode = SwitchMode; + pScrn->AdjustFrame = AdjustFrame; + pScrn->EnterVT = EnterVT; + pScrn->LeaveVT = LeaveVT; + pScrn->FreeScreen = FreeScreen; + pScrn->ValidMode = ValidMode; + break; + } + } else + ErrorF("FAILED PSCRN\n"); + } + } + + xfree(usedChips); + xfree(devSections); + + return foundScreen; +} +#endif + +static Bool +GetRec(ScrnInfoPtr pScrn) +{ + if (pScrn->driverPrivate) + return TRUE; + + pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1); + + return TRUE; +} + +static void +FreeRec(ScrnInfoPtr pScrn) +{ + if (!pScrn) + return; + + if (!pScrn->driverPrivate) + return; + + xfree(pScrn->driverPrivate); + + pScrn->driverPrivate = NULL; +} + +static void +ProbeDDC(ScrnInfoPtr pScrn, int index) +{ + ConfiguredMonitor = NULL; +} + +static Bool +MapMem(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + + drmBOMap(ms->fd, + &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual); + + return TRUE; +} + +static Bool +UnmapMem(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + + drmBOUnmap(ms->fd, &ms->bo); + + return TRUE; +} + +static void +LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, + LOCO * colors, VisualPtr pVisual) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); +} + +static Bool +crtc_resize(ScrnInfoPtr pScrn, int width, int height) +{ + modesettingPtr ms = modesettingPTR(pScrn); + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + Bool fbAccessDisabled; + CARD8 *fbstart; + + if (width == pScrn->virtualX && height == pScrn->virtualY) + return TRUE; + + ErrorF("RESIZING TO %dx%d\n",width,height); + + pScrn->virtualX = width; + pScrn->virtualY = height; + pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; + + if (ms->shadowMem) { + xfree(ms->shadowMem); + ms->shadowMem = NULL; + } + + UnmapMem(pScrn); + + /* move old buffer out of the way */ + drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL, + DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT, + DRM_BO_HINT_DONT_FENCE, 0, 0); + + /* unreference it */ + drmBOUnreference(ms->fd, &ms->bo); + + drmBOCreate(ms->fd, + pScrn->virtualY * pScrn->displayWidth * + pScrn->bitsPerPixel / 8, 0, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE + | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | + DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo); + + MapMem(pScrn); + + drmModeAddFB(ms->fd, + pScrn->virtualX, + pScrn->virtualY, + pScrn->depth, + pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel / 8, + ms->bo.handle, + &ms->fb_id); + + if (ms->shadowFB) { + if ((ms->shadowMem = + shadowAlloc(pScrn->displayWidth, pScrn->virtualY, + pScrn->bitsPerPixel)) == NULL) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Allocation of shadow memory failed\n"); + return FALSE; + } + fbstart = ms->shadowMem; + } else { + fbstart = ms->virtual; + } + + /* + * If we are in a fb disabled state, the virtual address of the root + * pixmap should always be NULL, and it will be overwritten later + * if we try to set it to something. + * + * Therefore, set it to NULL, and modify the backup copy instead. + */ + + fbAccessDisabled = (rootPixmap->devPrivate.ptr == NULL); + + pScreen->ModifyPixmapHeader(rootPixmap, + pScrn->virtualX, pScrn->virtualY, + pScrn->depth, pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel / 8, + fbstart); + + if (fbAccessDisabled) { + pScrn->pixmapPrivate.ptr = fbstart; + rootPixmap->devPrivate.ptr = NULL; + } + + pScrn->frameX0 = 0; + pScrn->frameY0 = 0; + AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + + return TRUE; +} + +static const xf86CrtcConfigFuncsRec crtc_config_funcs = { + crtc_resize +}; + +static Bool +PreInit(ScrnInfoPtr pScrn, int flags) +{ + xf86CrtcConfigPtr xf86_config; + modesettingPtr ms; + MessageType from = X_PROBED; + rgb defaultWeight = { 0, 0, 0 }; + EntityInfoPtr pEnt; + EntPtr msEnt = NULL; + int flags24; + char *BusID; + int i; + char *s; + int num_pipe; + int max_width, max_height; + + if (pScrn->numEntities != 1) + return FALSE; + + pEnt = xf86GetEntityInfo(pScrn->entityList[0]); + + if (flags & PROBE_DETECT) { + ProbeDDC(pScrn, pEnt->index); + return TRUE; + } + + /* Allocate driverPrivate */ + if (!GetRec(pScrn)) + return FALSE; + + ms = modesettingPTR(pScrn); + ms->SaveGeneration = -1; + ms->pEnt = pEnt; + + pScrn->displayWidth = 640; /* default it */ + + if (ms->pEnt->location.type != BUS_PCI) + return FALSE; + + ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); + + /* Allocate an entity private if necessary */ + if (xf86IsEntityShared(pScrn->entityList[0])) { + msEnt = xf86GetEntityPrivate(pScrn->entityList[0], + modesettingEntityIndex)->ptr; + ms->entityPrivate = msEnt; + } else + ms->entityPrivate = NULL; + + if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) { + return FALSE; + } + + if (xf86IsEntityShared(pScrn->entityList[0])) { + if (xf86IsPrimInitDone(pScrn->entityList[0])) { + /* do something */ + } else { + xf86SetPrimInitDone(pScrn->entityList[0]); + } + } + + BusID = xalloc(64); + sprintf(BusID, "PCI:%d:%d:%d", +#if XSERVER_LIBPCIACCESS + ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), + ms->PciInfo->dev, ms->PciInfo->func +#else + ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum +#endif + ); + + ms->fd = drmOpen(NULL, BusID); + + if (ms->fd < 0) + return FALSE; + + pScrn->racMemFlags = RAC_FB | RAC_COLORMAP; + pScrn->monitor = pScrn->confScreen->monitor; + pScrn->progClock = TRUE; + pScrn->rgbBits = 8; + + flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32; + + if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24)) + return FALSE; + + switch (pScrn->depth) { + case 8: + case 15: + case 16: + case 24: + break; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Given depth (%d) is not supported by the driver\n", + pScrn->depth); + return FALSE; + } + xf86PrintDepthBpp(pScrn); + + if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) + return FALSE; + if (!xf86SetDefaultVisual(pScrn, -1)) + return FALSE; + + /* Process the options */ + xf86CollectOptions(pScrn, NULL); + if (!(ms->Options = xalloc(sizeof(Options)))) + return FALSE; + memcpy(ms->Options, Options, sizeof(Options)); + xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options); + + /* Allocate an xf86CrtcConfig */ + xf86CrtcConfigInit(pScrn, &crtc_config_funcs); + xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + + max_width = 8192; + max_height = 8192; + xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height); + + if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) { + ms->noAccel = TRUE; + } + + if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) { + ms->SWCursor = TRUE; + } + + if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) { + if (!xf86LoadSubModule(pScrn, "shadow")) + return FALSE; + + xf86LoaderReqSymLists(shadowSymbols, NULL); + + ms->shadowFB = TRUE; + } + + SaveHWState(pScrn); + + crtc_init(pScrn); + output_init(pScrn); + + if (!xf86InitialConfiguration(pScrn, TRUE)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n"); + RestoreHWState(pScrn); + return FALSE; + } + + RestoreHWState(pScrn); + + /* + * If the driver can do gamma correction, it should call xf86SetGamma() here. + */ + { + Gamma zeros = { 0.0, 0.0, 0.0 }; + + if (!xf86SetGamma(pScrn, zeros)) { + return FALSE; + } + } + + if (pScrn->modes == NULL) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n"); + return FALSE; + } + + pScrn->currentMode = pScrn->modes; + + /* Set display resolution */ + xf86SetDpi(pScrn, 0, 0); + + /* Load the required sub modules */ + if (!xf86LoadSubModule(pScrn, "fb")) { + return FALSE; + } + + xf86LoaderReqSymLists(fbSymbols, NULL); + + return TRUE; +} + +static Bool +SaveHWState(ScrnInfoPtr pScrn) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + + return TRUE; +} + +static Bool +RestoreHWState(ScrnInfoPtr pScrn) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + + return TRUE; +} + +static void * +WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode, + CARD32 * size, void *closure) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + + if (!pScrn->vtSema) + return NULL; + + *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8; + + return ((CARD8 *) ms->virtual + row * (*size) + offset); +} + +static Bool +CreateScreenResources(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + Bool ret; + + pScreen->CreateScreenResources = ms->createScreenResources; + ret = pScreen->CreateScreenResources(pScreen); + pScreen->CreateScreenResources = CreateScreenResources; + + shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen), + ms->update, WindowLinear, 0, 0); + + return ret; +} + +static Bool +ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + VisualPtr visual; + unsigned long sys_mem; + int c; + MessageType from; + CARD8 *fbstart; + + pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; + + miClearVisualTypes(); + + if (!miSetVisualTypes(pScrn->depth, + miGetDefaultVisualMask(pScrn->depth), + pScrn->rgbBits, pScrn->defaultVisual)) + return FALSE; + + if (!miSetPixmapDepths()) + return FALSE; + + if (!MapMem(pScrn)) + return FALSE; + + pScrn->memPhysBase = 0; + pScrn->fbOffset = 0; + + drmBOCreate(ms->fd, + pScrn->virtualY * pScrn->displayWidth * + pScrn->bitsPerPixel / 8, 0, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE + | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | + DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo); + + MapMem(pScrn); + + drmModeAddFB(ms->fd, + pScrn->virtualX, + pScrn->virtualY, + pScrn->depth, + pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel / 8, + ms->bo.handle, + &ms->fb_id); + + if (ms->shadowFB) { + if ((ms->shadowMem = + shadowAlloc(pScrn->displayWidth, pScrn->virtualY, + pScrn->bitsPerPixel)) == NULL) { + xf86DrvMsg(scrnIndex, X_ERROR, + "Allocation of shadow memory failed\n"); + return FALSE; + } + fbstart = ms->shadowMem; + } else { + fbstart = ms->virtual; + } + + if (!fbScreenInit(pScreen, fbstart, + pScrn->virtualX, pScrn->virtualY, + pScrn->xDpi, pScrn->yDpi, + pScrn->displayWidth, pScrn->bitsPerPixel)) + return FALSE; + + if (pScrn->bitsPerPixel > 8) { + /* Fixup RGB ordering */ + visual = pScreen->visuals + pScreen->numVisuals; + while (--visual >= pScreen->visuals) { + if ((visual->class | DynamicClass) == DirectColor) { + visual->offsetRed = pScrn->offset.red; + visual->offsetGreen = pScrn->offset.green; + visual->offsetBlue = pScrn->offset.blue; + visual->redMask = pScrn->mask.red; + visual->greenMask = pScrn->mask.green; + visual->blueMask = pScrn->mask.blue; + } + } + } + + fbPictureInit(pScreen, NULL, 0); + if (ms->shadowFB) { + ms->update = shadowUpdatePackedWeak(); + if (!shadowSetup(pScreen)) { + xf86DrvMsg(scrnIndex, X_ERROR, + "Shadow framebuffer initialization failed.\n"); + return FALSE; + } + + ms->createScreenResources = pScreen->CreateScreenResources; + pScreen->CreateScreenResources = CreateScreenResources; + } + + xf86SetBlackWhitePixels(pScreen); + +#if 0 + glucoseScreenInit(pScreen, 0); +#endif +#if 0 + ms->pExa = ExaInit(pScreen); +#endif + + miInitializeBackingStore(pScreen); + xf86SetBackingStore(pScreen); + xf86SetSilkenMouse(pScreen); + miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); + + /* Must force it before EnterVT, so we are in control of VT and + * later memory should be bound when allocating, e.g rotate_mem */ + pScrn->vtSema = TRUE; + + pScreen->SaveScreen = xf86SaveScreen; + ms->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = CloseScreen; + + if (!xf86CrtcScreenInit(pScreen)) + return FALSE; + + if (!miCreateDefColormap(pScreen)) + return FALSE; + +#if 0 + if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL, + CMAP_RELOAD_ON_MODE_SWITCH | + CMAP_PALETTED_TRUECOLOR)) { + return FALSE; + } +#endif + + xf86DPMSInit(pScreen, xf86DPMSSet, 0); + +#if 0 + glucoseInitVideo(pScreen); +#endif + + if (serverGeneration == 1) + xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); + + return EnterVT(scrnIndex, 0); +} + +static void +AdjustFrame(int scrnIndex, int x, int y, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + xf86OutputPtr output = config->output[config->compat_output]; + xf86CrtcPtr crtc = output->crtc; + + if (crtc && crtc->enabled) { + crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x, y); + crtc->x = output->initial_x + x; + crtc->y = output->initial_y + y; + } +} + +static void +FreeScreen(int scrnIndex, int flags) +{ + FreeRec(xf86Screens[scrnIndex]); +} + +static void +LeaveVT(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + modesettingPtr ms = modesettingPTR(pScrn); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + int o; + + for (o = 0; o < config->num_crtc; o++) { + xf86CrtcPtr crtc = config->crtc[o]; + + if (crtc->rotatedPixmap || crtc->rotatedData) { + crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, + crtc->rotatedData); + crtc->rotatedPixmap = NULL; + crtc->rotatedData = NULL; + } + } + + xf86_hide_cursors(pScrn); + + drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0); + + RestoreHWState(pScrn); +} + +/* + * This gets called when gaining control of the VT, and from ScreenInit(). + */ +static Bool +EnterVT(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + modesettingPtr ms = modesettingPTR(pScrn); + + /* + * Only save state once per server generation since that's what most + * drivers do. Could change this to save state at each VT enter. + */ + if (ms->SaveGeneration != serverGeneration) { + ms->SaveGeneration = serverGeneration; + SaveHWState(pScrn); + } + + drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); + + if (!xf86SetDesiredModes(pScrn)) + return FALSE; + + AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + + return TRUE; +} + +static Bool +SwitchMode(int scrnIndex, DisplayModePtr mode, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + + return xf86SetSingleMode(pScrn, mode, RR_Rotate_0); +} + +static Bool +CloseScreen(int scrnIndex, ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + modesettingPtr ms = modesettingPTR(pScrn); + + if (pScrn->vtSema == TRUE) { + LeaveVT(scrnIndex, 0); + drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); + } + + UnmapMem(pScrn); + + if (ms->shadowFB) + pScreen->CreateScreenResources = ms->createScreenResources; + + if (ms->shadowMem) { + xfree(ms->shadowMem); + ms->shadowMem = NULL; + } + + if (ms->pExa) + ExaClose(pScrn); + + /* move old buffer out of the way */ + drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL, + DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT, + DRM_BO_HINT_DONT_FENCE, 0, 0); + + drmBOUnreference(ms->fd, &ms->bo); + + drmClose(ms->fd); + + pScrn->vtSema = FALSE; + pScreen->CloseScreen = ms->CloseScreen; + return (*pScreen->CloseScreen) (scrnIndex, pScreen); +} + +static ModeStatus +ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags) +{ + return MODE_OK; +} diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h new file mode 100644 index 000000000..2a0990312 --- /dev/null +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -0,0 +1,88 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * + */ + +#include +#include +#include +#include +#include "shadow.h" +#include "exa.h" + +#define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg); + +typedef struct { + int lastInstance; + int refCount; + ScrnInfoPtr pScrn_1; + ScrnInfoPtr pScrn_2; +} EntRec, *EntPtr; + +typedef struct _modesettingRec { + int fd; + unsigned int fb_id; + void *virtual; + drmBO bo; + + EntPtr entityPrivate; + + void (*PointerMoved)(int, int, int); + + int Chipset; + EntityInfoPtr pEnt; +#if XSERVER_LIBPCIACCESS + struct pci_device *PciInfo; +#else + pciVideoPtr PciInfo; + PCITAG PciTag; +#endif + + Bool noAccel; + Bool SWCursor; + CloseScreenProcPtr CloseScreen; + + Bool directRenderingDisabled; /* DRI disabled in PreInit. */ + Bool directRenderingEnabled; /* DRI enabled this generation. */ + + /* Broken-out options. */ + OptionInfoPtr Options; + + unsigned int SaveGeneration; + + /* shadowfb */ + CARD8 *shadowMem; + Bool shadowFB; + CreateScreenResourcesProcPtr createScreenResources; + ShadowUpdateProc update; + + /* exa */ + ExaDriverPtr pExa; + drmBO exa_bo; +} modesettingRec, *modesettingPtr; + +#define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c new file mode 100644 index 000000000..a9be2c12d --- /dev/null +++ b/hw/xfree86/drivers/modesetting/exa.c @@ -0,0 +1,235 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "xf86.h" +#include "xf86_OSproc.h" + +#include "driver.h" + +static void +ExaWaitMarker(ScreenPtr pScreen, int marker) +{ +} + +static int +ExaMarkSync(ScreenPtr pScreen) +{ + /* + * See ExaWaitMarker. + */ + + return 1; +} + +Bool +ExaPrepareAccess(PixmapPtr pPix, int index) +{ + ScreenPtr pScreen = pPix->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + + return TRUE; +} + +void +ExaFinishAccess(PixmapPtr pPix, int index) +{ + ScreenPtr pScreen = pPix->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; +} + +static void +ExaDone(PixmapPtr pPixmap) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; +} + +static void +ExaDoneComposite(PixmapPtr pPixmap) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; +} + +static Bool +ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + + if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask)) + return FALSE; + + /* can't do depth 4 */ + if (pPixmap->drawable.depth == 4) + return FALSE; + + return TRUE; +} + +static void +ExaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; +} + +static Bool +ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, + int ydir, int alu, Pixel planeMask) +{ + ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; + + /* can't do depth 4 */ + if (pSrcPixmap->drawable.depth == 4 || pDstPixmap->drawable.depth == 4) + return FALSE; + + return TRUE; +} + +static void +ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY, + int width, int height) +{ + ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; +} + +static Bool +ExaPrepareComposite(int op, PicturePtr pSrcPicture, + PicturePtr pMaskPicture, PicturePtr pDstPicture, + PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst) +{ + ScreenPtr pScreen = pDst->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + + return FALSE; +} + +static Bool +ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, + int src_pitch) +{ + ScreenPtr pScreen = pDst->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + + return FALSE; +} + +static void +ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY, + int dstX, int dstY, int width, int height) +{ + ScreenPtr pScreen = pDst->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; +} + +static Bool +ExaCheckComposite(int op, + PicturePtr pSrcPicture, PicturePtr pMaskPicture, + PicturePtr pDstPicture) +{ + DrawablePtr pDraw = pSrcPicture->pDrawable; + int w = pDraw->width; + int h = pDraw->height; + + return TRUE; +} + +static Bool +ExaPixmapIsOffscreen(PixmapPtr p) +{ + ScreenPtr pScreen = p->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + + return FALSE; +} + +void +ExaClose(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + + exaDriverFini(pScrn->pScreen); + + drmBOUnreference(ms->fd, &ms->exa_bo); +} + +ExaDriverPtr +ExaInit(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + ExaDriverPtr pExa; + + pExa = exaDriverAlloc(); + if (!pExa) { + goto out_err; + } + + /* Create a 256KB offscreen area */ + drmBOCreate(ms->fd, 256 * 1024, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->exa_bo); + + memset(pExa, 0, sizeof(*pExa)); + pExa->exa_major = 2; + pExa->exa_minor = 2; + pExa->memoryBase = ms->exa_bo.virtual; + pExa->offScreenBase = 0; + pExa->memorySize = ms->exa_bo.size; + pExa->pixmapOffsetAlign = 8; + pExa->pixmapPitchAlign = 32 * 4; + pExa->flags = EXA_OFFSCREEN_PIXMAPS; + pExa->maxX = 8191; /* FIXME */ + pExa->maxY = 8191; /* FIXME */ + pExa->WaitMarker = ExaWaitMarker; + pExa->MarkSync = ExaMarkSync; + pExa->PrepareSolid = ExaPrepareSolid; + pExa->Solid = ExaSolid; + pExa->DoneSolid = ExaDone; + pExa->PrepareCopy = ExaPrepareCopy; + pExa->Copy = ExaCopy; + pExa->DoneCopy = ExaDone; + pExa->CheckComposite = ExaCheckComposite; + pExa->PrepareComposite = ExaPrepareComposite; + pExa->Composite = ExaComposite; + pExa->DoneComposite = ExaDoneComposite; + pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen; + pExa->PrepareAccess = ExaPrepareAccess; + pExa->FinishAccess = ExaFinishAccess; + pExa->UploadToScreen = ExaUploadToScreen; + + if (!exaDriverInit(pScrn->pScreen, pExa)) { + goto out_err; + } + + return pExa; + + out_err: + ExaClose(pScrn); + + return NULL; +} diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man new file mode 100644 index 000000000..e69de29bb diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c new file mode 100644 index 000000000..b25540ee0 --- /dev/null +++ b/hw/xfree86/drivers/modesetting/output.c @@ -0,0 +1,285 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DPMS_SERVER +#include + +#include "X11/Xatom.h" + +#include "driver.h" + +static void +dpms(xf86OutputPtr output, int mode) +{ +} + +static void +save(xf86OutputPtr output) +{ +} + +static void +restore(xf86OutputPtr output) +{ +} + +static int +mode_valid(xf86OutputPtr output, DisplayModePtr pMode) +{ + return MODE_OK; +} + +static Bool +mode_fixup(xf86OutputPtr output, DisplayModePtr mode, + DisplayModePtr adjusted_mode) +{ + return TRUE; +} + +static void +prepare(xf86OutputPtr output) +{ + dpms(output, DPMSModeOff); +} + +static void +mode_set(xf86OutputPtr output, DisplayModePtr mode, + DisplayModePtr adjusted_mode) +{ +} + +static void +commit(xf86OutputPtr output) +{ + dpms(output, DPMSModeOn); + + if (output->scrn->pScreen != NULL) + xf86_reload_cursors(output->scrn->pScreen); +} + +static xf86OutputStatus +detect(xf86OutputPtr output) +{ + drmModeOutputPtr drm_output = output->driver_private; + + switch (drm_output->connection) { + case DRM_MODE_CONNECTED: + return XF86OutputStatusConnected; + case DRM_MODE_DISCONNECTED: + return XF86OutputStatusDisconnected; + default: + return XF86OutputStatusUnknown; + } +} + +static DisplayModePtr +get_modes(xf86OutputPtr output) +{ + drmModeOutputPtr drm_output = output->driver_private; + struct drm_mode_modeinfo *drm_mode = NULL; + DisplayModePtr modes = NULL, mode = NULL; + int i; + + for (i = 0; i < drm_output->count_modes; i++) { + drm_mode = &drm_output->modes[i]; + if (drm_mode) { + mode = xcalloc(1, sizeof(DisplayModeRec)); + if (!mode) + continue; + mode->type = 0; + mode->Clock = drm_mode->clock; + mode->HDisplay = drm_mode->hdisplay; + mode->HSyncStart = drm_mode->hsync_start; + mode->HSyncEnd = drm_mode->hsync_end; + mode->HTotal = drm_mode->htotal; + mode->VDisplay = drm_mode->vdisplay; + mode->VSyncStart = drm_mode->vsync_start; + mode->VSyncEnd = drm_mode->vsync_end; + mode->VTotal = drm_mode->vtotal; + mode->Flags = drm_mode->flags; + mode->HSkew = drm_mode->hskew; + mode->VScan = drm_mode->vscan; + mode->VRefresh = xf86ModeVRefresh(mode); + mode->Private = (void *)drm_mode; + xf86SetModeDefaultName(mode); + modes = xf86ModesAdd(modes, mode); + xf86PrintModeline(0, mode); + } + } + + return modes; +} + +static void +destroy(xf86OutputPtr output) +{ + drmModeFreeOutput(output->driver_private); +} + +static void +create_resources(xf86OutputPtr output) +{ +#ifdef RANDR_12_INTERFACE +#endif /* RANDR_12_INTERFACE */ +} + +#ifdef RANDR_12_INTERFACE +static Bool +set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value) +{ + return TRUE; +} +#endif /* RANDR_12_INTERFACE */ + +#ifdef RANDR_13_INTERFACE +static Bool +get_property(xf86OutputPtr output, Atom property) +{ + return TRUE; +} +#endif /* RANDR_13_INTERFACE */ + +#ifdef RANDR_GET_CRTC_INTERFACE +static xf86CrtcPtr +get_crtc(xf86OutputPtr output) +{ + return NULL; +} +#endif + +static const xf86OutputFuncsRec output_funcs = { + .create_resources = create_resources, + .dpms = dpms, + .save = save, + .restore = restore, + .mode_valid = mode_valid, + .mode_fixup = mode_fixup, + .prepare = prepare, + .mode_set = mode_set, + .commit = commit, + .detect = detect, + .get_modes = get_modes, +#ifdef RANDR_12_INTERFACE + .set_property = set_property, +#endif +#ifdef RANDR_13_INTERFACE + .get_property = get_property, +#endif + .destroy = destroy, +#ifdef RANDR_GET_CRTC_INTERFACE + .get_crtc = get_crtc, +#endif +}; + +void +output_init(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + xf86OutputPtr output; + drmModeResPtr res; + drmModeOutputPtr drm_output = NULL; + drmModeCrtcPtr crtc; + char *name; + int o, v, p; + + res = drmModeGetResources(ms->fd); + if (res == 0) { + DRV_ERROR("Failed drmModeGetResources\n"); + return; + } + + for (o = 0; o < res->count_outputs; o++) { + drm_output = drmModeGetOutput(ms->fd, res->outputs[o]); + if (!drm_output) + goto out; + + for (p = 0; p < drm_output->count_props; p++) { + drmModePropertyPtr prop; + + prop = drmModeGetProperty(ms->fd, drm_output->props[p]); + + name = NULL; + if (prop) { + ErrorF("VALUES %d\n",prop->count_values); + + for (v=0;vcount_values;v++) + ErrorF("%s %lld\n", prop->name, prop->values[v]); + + for (v=0;vcount_enums;v++) { + ErrorF("%s %s\n", prop->name, prop->enums[v].name); + if (drm_output->prop_values[p] == prop->enums[v].value) { + if (!strncmp("Connector Type", prop->name, 14)) { + ErrorF("WE'VE GOT %s\n",prop->enums[v].name); + name = xalloc(strlen(prop->enums[v].name)); + strncpy(name, prop->enums[v].name, strlen(name)); + } + } + if (name) break; + } + if (name) break; + } + } + + if (!name) + continue; + + output = xf86OutputCreate(pScrn, &output_funcs, name); + if (!output) + continue; + + free(name); + + output->possible_crtcs = drm_output->crtcs; + output->possible_clones = drm_output->clones; + output->driver_private = drm_output; + output->subpixel_order = SubPixelHorizontalRGB; + output->interlaceAllowed = FALSE; + output->doubleScanAllowed = FALSE; + } + +out: + drmModeFreeResources(res); +} From f9f7a872bf3f8522213aabb291d9d54e56d48c4b Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Wed, 28 May 2008 15:55:36 +0100 Subject: [PATCH 002/122] Run indent --- hw/xfree86/drivers/modesetting/crtc.c | 150 +-- hw/xfree86/drivers/modesetting/driver.c | 1133 ++++++++++++----------- hw/xfree86/drivers/modesetting/driver.h | 68 +- hw/xfree86/drivers/modesetting/exa.c | 30 +- hw/xfree86/drivers/modesetting/output.c | 232 ++--- 5 files changed, 813 insertions(+), 800 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c index f168126fb..66b23f695 100644 --- a/hw/xfree86/drivers/modesetting/crtc.c +++ b/hw/xfree86/drivers/modesetting/crtc.c @@ -50,22 +50,22 @@ static void crtc_dpms(xf86CrtcPtr crtc, int mode) { - ScrnInfoPtr pScrn = crtc->scrn; + ScrnInfoPtr pScrn = crtc->scrn; - switch (mode) { - case DPMSModeOn: - case DPMSModeStandby: - case DPMSModeSuspend: - break; - case DPMSModeOff: - break; - } + switch (mode) { + case DPMSModeOn: + case DPMSModeStandby: + case DPMSModeSuspend: + break; + case DPMSModeOff: + break; + } } static Bool crtc_lock(xf86CrtcPtr crtc) { - return FALSE; + return FALSE; } static void @@ -87,43 +87,43 @@ static Bool crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayModePtr adjusted_mode) { - return TRUE; + return TRUE; } static void crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayModePtr adjusted_mode, int x, int y) { - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - modesettingPtr ms = modesettingPTR(crtc->scrn); - xf86OutputPtr output = config->output[config->compat_output]; - drmModeOutputPtr drm_output = output->driver_private; - drmModeCrtcPtr drm_crtc = crtc->driver_private; - struct drm_mode_modeinfo drm_mode; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + modesettingPtr ms = modesettingPTR(crtc->scrn); + xf86OutputPtr output = config->output[config->compat_output]; + drmModeOutputPtr drm_output = output->driver_private; + drmModeCrtcPtr drm_crtc = crtc->driver_private; + struct drm_mode_modeinfo drm_mode; - drm_mode.clock = mode->Clock; - drm_mode.hdisplay = mode->HDisplay; - drm_mode.hsync_start = mode->HSyncStart; - drm_mode.hsync_end = mode->HSyncEnd; - drm_mode.htotal = mode->HTotal; - drm_mode.vdisplay = mode->VDisplay; - drm_mode.vsync_start = mode->VSyncStart; - drm_mode.vsync_end = mode->VSyncEnd; - drm_mode.vtotal = mode->VTotal; - drm_mode.flags = mode->Flags; - drm_mode.hskew = mode->HSkew; - drm_mode.vscan = mode->VScan; - drm_mode.vrefresh = mode->VRefresh; - strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN); + drm_mode.clock = mode->Clock; + drm_mode.hdisplay = mode->HDisplay; + drm_mode.hsync_start = mode->HSyncStart; + drm_mode.hsync_end = mode->HSyncEnd; + drm_mode.htotal = mode->HTotal; + drm_mode.vdisplay = mode->VDisplay; + drm_mode.vsync_start = mode->VSyncStart; + drm_mode.vsync_end = mode->VSyncEnd; + drm_mode.vtotal = mode->VTotal; + drm_mode.flags = mode->Flags; + drm_mode.hskew = mode->HSkew; + drm_mode.vscan = mode->VScan; + drm_mode.vrefresh = mode->VRefresh; + strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN); - drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y, - &drm_output->output_id, 1, &drm_mode); + drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y, + &drm_output->output_id, 1, &drm_mode); } void crtc_load_lut(xf86CrtcPtr crtc) { - ScrnInfoPtr pScrn = crtc->scrn; + ScrnInfoPtr pScrn = crtc->scrn; } static void @@ -135,81 +135,81 @@ crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue, static void * crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height) { - ScrnInfoPtr pScrn = crtc->scrn; + ScrnInfoPtr pScrn = crtc->scrn; - return NULL; + return NULL; } static PixmapPtr crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height) { - ScrnInfoPtr pScrn = crtc->scrn; + ScrnInfoPtr pScrn = crtc->scrn; - return NULL; + return NULL; } static void crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data) { - ScrnInfoPtr pScrn = crtc->scrn; + ScrnInfoPtr pScrn = crtc->scrn; } static void crtc_destroy(xf86CrtcPtr crtc) { - drmModeFreeCrtc(crtc->driver_private); + drmModeFreeCrtc(crtc->driver_private); } static const xf86CrtcFuncsRec crtc_funcs = { - .dpms = crtc_dpms, - .save = NULL, /* XXX */ - .restore = NULL, /* XXX */ - .lock = crtc_lock, - .unlock = crtc_unlock, - .mode_fixup = crtc_mode_fixup, - .prepare = crtc_prepare, - .mode_set = crtc_mode_set, - .commit = crtc_commit, - .gamma_set = crtc_gamma_set, - .shadow_create = crtc_shadow_create, - .shadow_allocate = crtc_shadow_allocate, - .shadow_destroy = crtc_shadow_destroy, + .dpms = crtc_dpms, + .save = NULL, /* XXX */ + .restore = NULL, /* XXX */ + .lock = crtc_lock, + .unlock = crtc_unlock, + .mode_fixup = crtc_mode_fixup, + .prepare = crtc_prepare, + .mode_set = crtc_mode_set, + .commit = crtc_commit, + .gamma_set = crtc_gamma_set, + .shadow_create = crtc_shadow_create, + .shadow_allocate = crtc_shadow_allocate, + .shadow_destroy = crtc_shadow_destroy, // .set_cursor_colors = crtc_set_cursor_colors, // .set_cursor_position = crtc_set_cursor_position, // .show_cursor = crtc_show_cursor, // .hide_cursor = crtc_hide_cursor, // .load_cursor_image = crtc_load_cursor_image, // .load_cursor_argb = crtc_load_cursor_argb, - .destroy = crtc_destroy, /* XXX */ + .destroy = crtc_destroy, /* XXX */ }; void crtc_init(ScrnInfoPtr pScrn) { - modesettingPtr ms = modesettingPTR(pScrn); - xf86CrtcPtr crtc; - drmModeResPtr res; - drmModeCrtcPtr drm_crtc = NULL; - int c, k, p; + modesettingPtr ms = modesettingPTR(pScrn); + xf86CrtcPtr crtc; + drmModeResPtr res; + drmModeCrtcPtr drm_crtc = NULL; + int c, k, p; - res = drmModeGetResources(ms->fd); - if (res == 0) { - ErrorF("Failed drmModeGetResources %d\n",errno); - return; - } + res = drmModeGetResources(ms->fd); + if (res == 0) { + ErrorF("Failed drmModeGetResources %d\n", errno); + return; + } - for (c = 0; c < res->count_crtcs; c++) { - drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]); - if (!drm_crtc) - continue; + for (c = 0; c < res->count_crtcs; c++) { + drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]); + if (!drm_crtc) + continue; - crtc = xf86CrtcCreate(pScrn, &crtc_funcs); - if (crtc == NULL) - goto out; + crtc = xf86CrtcCreate(pScrn, &crtc_funcs); + if (crtc == NULL) + goto out; - crtc->driver_private = drm_crtc; - } + crtc->driver_private = drm_crtc; + } -out: - drmModeFreeResources(res); + out: + drmModeFreeResources(res); } diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index ba6bfdf53..de4b26014 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -65,12 +65,15 @@ static Bool SaveHWState(ScrnInfoPtr pScrn); static Bool RestoreHWState(ScrnInfoPtr pScrn); static void Identify(int flags); static const OptionInfoRec *AvailableOptions(int chipid, int busid); -static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags); +static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, + int flags); static void FreeScreen(int scrnIndex, int flags); static void LeaveVT(int scrnIndex, int flags); static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags); -static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv); +static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, + char **argv); static Bool PreInit(ScrnInfoPtr pScrn, int flags); + #if XSERVER_LIBPCIACCESS static Bool pci_probe(DriverPtr driver, @@ -81,64 +84,64 @@ static Bool Probe(DriverPtr drv, int flags); #if XSERVER_LIBPCIACCESS static const struct pci_id_match device_match[] = { - {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0}, - {0, 0, 0}, + {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0}, + {0, 0, 0}, }; #endif _X_EXPORT DriverRec modesetting = { - 1, - "modesetting", - Identify, + 1, + "modesetting", + Identify, #if XSERVER_LIBPCIACCESS - NULL, + NULL, #else - Probe, + Probe, #endif - AvailableOptions, - NULL, - 0, - NULL, + AvailableOptions, + NULL, + 0, + NULL, #if XSERVER_LIBPCIACCESS - device_match, - pci_probe + device_match, + pci_probe #endif }; static SymTabRec Chipsets[] = { - {0x2592, "Intel Graphics Device"}, - {-1, NULL} + {0x2592, "Intel Graphics Device"}, + {-1, NULL} }; static PciChipsets PciDevices[] = { - {0x2592, 0x2592, RES_SHARED_VGA}, - {-1, -1, RES_UNDEFINED} + {0x2592, 0x2592, RES_SHARED_VGA}, + {-1, -1, RES_UNDEFINED} }; typedef enum { - OPTION_NOACCEL, - OPTION_SW_CURSOR, - OPTION_SHADOWFB, + OPTION_NOACCEL, + OPTION_SW_CURSOR, + OPTION_SHADOWFB, } modesettingOpts; static const OptionInfoRec Options[] = { - {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE}, - {-1, NULL, OPTV_NONE, {0}, FALSE} + {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE}, + {-1, NULL, OPTV_NONE, {0}, FALSE} }; static const char *fbSymbols[] = { - "fbPictureInit", - "fbScreenInit", - NULL + "fbPictureInit", + "fbScreenInit", + NULL }; static const char *ddcSymbols[] = { - "xf86PrintEDID", - "xf86SetDDCproperties", - NULL + "xf86PrintEDID", + "xf86SetDDCproperties", + NULL }; static const char *shadowSymbols[] = { @@ -148,9 +151,9 @@ static const char *shadowSymbols[] = { }; static const char *i2cSymbols[] = { - "xf86CreateI2CBusRec", - "xf86I2CBusInit", - NULL + "xf86CreateI2CBusRec", + "xf86I2CBusInit", + NULL }; int modesettingEntityIndex = -1; @@ -158,16 +161,16 @@ int modesettingEntityIndex = -1; static MODULESETUPPROTO(Setup); static XF86ModuleVersionInfo VersRec = { - "modesetting", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL, - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} + "modesetting", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL, + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} }; _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL }; @@ -175,44 +178,43 @@ _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL }; static pointer Setup(pointer module, pointer opts, int *errmaj, int *errmin) { - static Bool setupDone = 0; + static Bool setupDone = 0; - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&modesetting, module, HaveDriverFuncs); + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&modesetting, module, HaveDriverFuncs); - /* - * Tell the loader about symbols from other modules that this module - * might refer to. - */ - LoaderRefSymLists(fbSymbols, - shadowSymbols, ddcSymbols, NULL); + /* + * Tell the loader about symbols from other modules that this module + * might refer to. + */ + LoaderRefSymLists(fbSymbols, shadowSymbols, ddcSymbols, NULL); - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } } static void Identify(int flags) { - xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", - Chipsets); + xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", + Chipsets); } static const OptionInfoRec * AvailableOptions(int chipid, int busid) { - return Options; + return Options; } #if XSERVER_LIBPCIACCESS @@ -220,267 +222,271 @@ static Bool pci_probe(DriverPtr driver, int entity_num, struct pci_device *device, intptr_t match_data) { - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - DevUnion *private; + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + DevUnion *private; - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "modesetting"; - scrn->name = "modesetting"; - scrn->Probe = NULL; + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "modesetting"; + scrn->name = "modesetting"; + scrn->Probe = NULL; - entity = xf86GetEntityInfo(entity_num); + entity = xf86GetEntityInfo(entity_num); - switch (device->device_id) { - case 0x2592: - scrn->PreInit = PreInit; - scrn->ScreenInit = ScreenInit; - scrn->SwitchMode = SwitchMode; - scrn->AdjustFrame = AdjustFrame; - scrn->EnterVT = EnterVT; - scrn->LeaveVT = LeaveVT; - scrn->FreeScreen = FreeScreen; - scrn->ValidMode = ValidMode; - break; - } - } - return scrn != NULL; + switch (device->device_id) { + case 0x2592: + scrn->PreInit = PreInit; + scrn->ScreenInit = ScreenInit; + scrn->SwitchMode = SwitchMode; + scrn->AdjustFrame = AdjustFrame; + scrn->EnterVT = EnterVT; + scrn->LeaveVT = LeaveVT; + scrn->FreeScreen = FreeScreen; + scrn->ValidMode = ValidMode; + break; + } + } + return scrn != NULL; } #else static Bool Probe(DriverPtr drv, int flags) { - int i, numUsed, numDevSections, *usedChips; - EntPtr msEnt = NULL; - DevUnion *pPriv; - GDevPtr *devSections; - Bool foundScreen = FALSE; - pciVideoPtr *VideoInfo; - pciVideoPtr *ppPci; - int numDevs; + int i, numUsed, numDevSections, *usedChips; + EntPtr msEnt = NULL; + DevUnion *pPriv; + GDevPtr *devSections; + Bool foundScreen = FALSE; + pciVideoPtr *VideoInfo; + pciVideoPtr *ppPci; + int numDevs; - /* - * Find the config file Device sections that match this - * driver, and return if there are none. - */ - if ((numDevSections = - xf86MatchDevice("modesetting", &devSections)) <= 0) { - return FALSE; - } + /* + * Find the config file Device sections that match this + * driver, and return if there are none. + */ + if ((numDevSections = xf86MatchDevice("modesetting", &devSections)) <= 0) { + return FALSE; + } - /* - * This probing is just checking the PCI data the server already - * collected. - */ - if (!(VideoInfo = xf86GetPciVideoInfo())) - return FALSE; + /* + * This probing is just checking the PCI data the server already + * collected. + */ + if (!(VideoInfo = xf86GetPciVideoInfo())) + return FALSE; #if 0 - numUsed = 0; - for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) { - for (numDevs = 0; numDevs < numDevSections; numDevs++) { - if (devSections[numDevs]->busID && *devSections[numDevs]->busID) { - if (xf86ComparePciBusString(devSections[numDevs]->busID, (*ppPci)->bus, (*ppPci)->device, (*ppPci)->func)) { - /* Claim slot */ - if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device, - (*ppPci)->func)) { - usedChips[numUsed++] = xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device, - (*ppPci)->func, drv, (*ppPci)->chipType, - NULL, TRUE); - ErrorF("CLAIMED %d %d %d\n",(*ppPci)->bus,(*ppPci)->device, (*ppPci)->func); - } - } - } - } - } + numUsed = 0; + for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) { + for (numDevs = 0; numDevs < numDevSections; numDevs++) { + if (devSections[numDevs]->busID && *devSections[numDevs]->busID) { + if (xf86ComparePciBusString + (devSections[numDevs]->busID, (*ppPci)->bus, + (*ppPci)->device, (*ppPci)->func)) { + /* Claim slot */ + if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device, + (*ppPci)->func)) { + usedChips[numUsed++] = + xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device, + (*ppPci)->func, drv, + (*ppPci)->chipType, NULL, TRUE); + ErrorF("CLAIMED %d %d %d\n", (*ppPci)->bus, + (*ppPci)->device, (*ppPci)->func); + } + } + } + } + } #else - /* Look for Intel i8xx devices. */ - numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL, - Chipsets, PciDevices, - devSections, numDevSections, - drv, &usedChips); + /* Look for Intel i8xx devices. */ + numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL, + Chipsets, PciDevices, + devSections, numDevSections, + drv, &usedChips); #endif - if (flags & PROBE_DETECT) { - if (numUsed > 0) - foundScreen = TRUE; - } else { - ErrorF("NUMUSED %d\n",numUsed); - for (i = 0; i < numUsed; i++) { - ScrnInfoPtr pScrn = NULL; - - /* Allocate new ScrnInfoRec and claim the slot */ - if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i], - PciDevices, NULL, NULL, NULL, - NULL, NULL))) { - EntityInfoPtr pEnt; - - pEnt = xf86GetEntityInfo(usedChips[i]); - - pScrn->driverVersion = 1; - pScrn->driverName = "modesetting"; - pScrn->name = "modesetting"; - pScrn->Probe = Probe; + if (flags & PROBE_DETECT) { + if (numUsed > 0) foundScreen = TRUE; - { - /* Allocate an entity private if necessary */ - if (modesettingEntityIndex < 0) - modesettingEntityIndex = xf86AllocateEntityPrivateIndex(); + } else { + ErrorF("NUMUSED %d\n", numUsed); + for (i = 0; i < numUsed; i++) { + ScrnInfoPtr pScrn = NULL; - pPriv = xf86GetEntityPrivate(pScrn->entityList[0], - modesettingEntityIndex); - if (!pPriv->ptr) { - pPriv->ptr = xnfcalloc(sizeof(EntRec), 1); - msEnt = pPriv->ptr; - msEnt->lastInstance = -1; - } else { - msEnt = pPriv->ptr; - } + /* Allocate new ScrnInfoRec and claim the slot */ + if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i], + PciDevices, NULL, NULL, NULL, + NULL, NULL))) { + EntityInfoPtr pEnt; - /* - * Set the entity instance for this instance of the driver. - * For dual head per card, instance 0 is the "master" - * instance, driving the primary head, and instance 1 is - * the "slave". - */ - msEnt->lastInstance++; - xf86SetEntityInstanceForScreen(pScrn, - pScrn->entityList[0], - msEnt->lastInstance); - pScrn->PreInit = PreInit; - pScrn->ScreenInit = ScreenInit; - pScrn->SwitchMode = SwitchMode; - pScrn->AdjustFrame = AdjustFrame; - pScrn->EnterVT = EnterVT; - pScrn->LeaveVT = LeaveVT; - pScrn->FreeScreen = FreeScreen; - pScrn->ValidMode = ValidMode; - break; - } - } else - ErrorF("FAILED PSCRN\n"); - } - } + pEnt = xf86GetEntityInfo(usedChips[i]); - xfree(usedChips); - xfree(devSections); + pScrn->driverVersion = 1; + pScrn->driverName = "modesetting"; + pScrn->name = "modesetting"; + pScrn->Probe = Probe; + foundScreen = TRUE; + { + /* Allocate an entity private if necessary */ + if (modesettingEntityIndex < 0) + modesettingEntityIndex = + xf86AllocateEntityPrivateIndex(); - return foundScreen; + pPriv = xf86GetEntityPrivate(pScrn->entityList[0], + modesettingEntityIndex); + if (!pPriv->ptr) { + pPriv->ptr = xnfcalloc(sizeof(EntRec), 1); + msEnt = pPriv->ptr; + msEnt->lastInstance = -1; + } else { + msEnt = pPriv->ptr; + } + + /* + * Set the entity instance for this instance of the driver. + * For dual head per card, instance 0 is the "master" + * instance, driving the primary head, and instance 1 is + * the "slave". + */ + msEnt->lastInstance++; + xf86SetEntityInstanceForScreen(pScrn, + pScrn->entityList[0], + msEnt->lastInstance); + pScrn->PreInit = PreInit; + pScrn->ScreenInit = ScreenInit; + pScrn->SwitchMode = SwitchMode; + pScrn->AdjustFrame = AdjustFrame; + pScrn->EnterVT = EnterVT; + pScrn->LeaveVT = LeaveVT; + pScrn->FreeScreen = FreeScreen; + pScrn->ValidMode = ValidMode; + break; + } + } else + ErrorF("FAILED PSCRN\n"); + } + } + + xfree(usedChips); + xfree(devSections); + + return foundScreen; } #endif static Bool GetRec(ScrnInfoPtr pScrn) { - if (pScrn->driverPrivate) - return TRUE; + if (pScrn->driverPrivate) + return TRUE; - pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1); + pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1); - return TRUE; + return TRUE; } static void FreeRec(ScrnInfoPtr pScrn) { - if (!pScrn) - return; + if (!pScrn) + return; - if (!pScrn->driverPrivate) - return; + if (!pScrn->driverPrivate) + return; - xfree(pScrn->driverPrivate); + xfree(pScrn->driverPrivate); - pScrn->driverPrivate = NULL; + pScrn->driverPrivate = NULL; } static void ProbeDDC(ScrnInfoPtr pScrn, int index) { - ConfiguredMonitor = NULL; + ConfiguredMonitor = NULL; } static Bool MapMem(ScrnInfoPtr pScrn) { - modesettingPtr ms = modesettingPTR(pScrn); + modesettingPtr ms = modesettingPTR(pScrn); - drmBOMap(ms->fd, - &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual); + drmBOMap(ms->fd, + &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual); - return TRUE; + return TRUE; } static Bool UnmapMem(ScrnInfoPtr pScrn) { - modesettingPtr ms = modesettingPTR(pScrn); + modesettingPtr ms = modesettingPTR(pScrn); - drmBOUnmap(ms->fd, &ms->bo); + drmBOUnmap(ms->fd, &ms->bo); - return TRUE; + return TRUE; } static void LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO * colors, VisualPtr pVisual) { - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); } static Bool crtc_resize(ScrnInfoPtr pScrn, int width, int height) { - modesettingPtr ms = modesettingPTR(pScrn); - ScreenPtr pScreen = pScrn->pScreen; - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - Bool fbAccessDisabled; - CARD8 *fbstart; + modesettingPtr ms = modesettingPTR(pScrn); + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + Bool fbAccessDisabled; + CARD8 *fbstart; - if (width == pScrn->virtualX && height == pScrn->virtualY) - return TRUE; + if (width == pScrn->virtualX && height == pScrn->virtualY) + return TRUE; - ErrorF("RESIZING TO %dx%d\n",width,height); + ErrorF("RESIZING TO %dx%d\n", width, height); - pScrn->virtualX = width; - pScrn->virtualY = height; - pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; + pScrn->virtualX = width; + pScrn->virtualY = height; + pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; - if (ms->shadowMem) { - xfree(ms->shadowMem); - ms->shadowMem = NULL; - } + if (ms->shadowMem) { + xfree(ms->shadowMem); + ms->shadowMem = NULL; + } - UnmapMem(pScrn); + UnmapMem(pScrn); - /* move old buffer out of the way */ - drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL, - DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT, - DRM_BO_HINT_DONT_FENCE, 0, 0); + /* move old buffer out of the way */ + drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL, + DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT, + DRM_BO_HINT_DONT_FENCE, 0, 0); - /* unreference it */ - drmBOUnreference(ms->fd, &ms->bo); + /* unreference it */ + drmBOUnreference(ms->fd, &ms->bo); - drmBOCreate(ms->fd, - pScrn->virtualY * pScrn->displayWidth * - pScrn->bitsPerPixel / 8, 0, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE - | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | - DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo); + drmBOCreate(ms->fd, + pScrn->virtualY * pScrn->displayWidth * + pScrn->bitsPerPixel / 8, 0, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE + | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | + DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, + DRM_BO_HINT_DONT_FENCE, &ms->bo); - MapMem(pScrn); + MapMem(pScrn); - drmModeAddFB(ms->fd, - pScrn->virtualX, - pScrn->virtualY, - pScrn->depth, - pScrn->bitsPerPixel, - pScrn->displayWidth * pScrn->bitsPerPixel / 8, - ms->bo.handle, - &ms->fb_id); + drmModeAddFB(ms->fd, + pScrn->virtualX, + pScrn->virtualY, + pScrn->depth, + pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel / 8, + ms->bo.handle, &ms->fb_id); if (ms->shadowFB) { if ((ms->shadowMem = @@ -488,7 +494,7 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height) pScrn->bitsPerPixel)) == NULL) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Allocation of shadow memory failed\n"); - return FALSE; + return FALSE; } fbstart = ms->shadowMem; } else { @@ -508,7 +514,7 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height) pScreen->ModifyPixmapHeader(rootPixmap, pScrn->virtualX, pScrn->virtualY, pScrn->depth, pScrn->bitsPerPixel, - pScrn->displayWidth * pScrn->bitsPerPixel / 8, + pScrn->displayWidth * pScrn->bitsPerPixel / 8, fbstart); if (fbAccessDisabled) { @@ -516,148 +522,148 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height) rootPixmap->devPrivate.ptr = NULL; } - pScrn->frameX0 = 0; - pScrn->frameY0 = 0; - AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + pScrn->frameX0 = 0; + pScrn->frameY0 = 0; + AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); - return TRUE; + return TRUE; } static const xf86CrtcConfigFuncsRec crtc_config_funcs = { - crtc_resize + crtc_resize }; static Bool PreInit(ScrnInfoPtr pScrn, int flags) { - xf86CrtcConfigPtr xf86_config; - modesettingPtr ms; - MessageType from = X_PROBED; - rgb defaultWeight = { 0, 0, 0 }; - EntityInfoPtr pEnt; - EntPtr msEnt = NULL; - int flags24; - char *BusID; - int i; - char *s; - int num_pipe; - int max_width, max_height; + xf86CrtcConfigPtr xf86_config; + modesettingPtr ms; + MessageType from = X_PROBED; + rgb defaultWeight = { 0, 0, 0 }; + EntityInfoPtr pEnt; + EntPtr msEnt = NULL; + int flags24; + char *BusID; + int i; + char *s; + int num_pipe; + int max_width, max_height; - if (pScrn->numEntities != 1) - return FALSE; + if (pScrn->numEntities != 1) + return FALSE; - pEnt = xf86GetEntityInfo(pScrn->entityList[0]); + pEnt = xf86GetEntityInfo(pScrn->entityList[0]); - if (flags & PROBE_DETECT) { - ProbeDDC(pScrn, pEnt->index); - return TRUE; - } + if (flags & PROBE_DETECT) { + ProbeDDC(pScrn, pEnt->index); + return TRUE; + } - /* Allocate driverPrivate */ - if (!GetRec(pScrn)) - return FALSE; + /* Allocate driverPrivate */ + if (!GetRec(pScrn)) + return FALSE; - ms = modesettingPTR(pScrn); - ms->SaveGeneration = -1; - ms->pEnt = pEnt; + ms = modesettingPTR(pScrn); + ms->SaveGeneration = -1; + ms->pEnt = pEnt; - pScrn->displayWidth = 640; /* default it */ + pScrn->displayWidth = 640; /* default it */ - if (ms->pEnt->location.type != BUS_PCI) - return FALSE; + if (ms->pEnt->location.type != BUS_PCI) + return FALSE; - ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); + ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); - /* Allocate an entity private if necessary */ - if (xf86IsEntityShared(pScrn->entityList[0])) { - msEnt = xf86GetEntityPrivate(pScrn->entityList[0], - modesettingEntityIndex)->ptr; - ms->entityPrivate = msEnt; - } else - ms->entityPrivate = NULL; + /* Allocate an entity private if necessary */ + if (xf86IsEntityShared(pScrn->entityList[0])) { + msEnt = xf86GetEntityPrivate(pScrn->entityList[0], + modesettingEntityIndex)->ptr; + ms->entityPrivate = msEnt; + } else + ms->entityPrivate = NULL; - if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) { - return FALSE; - } + if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) { + return FALSE; + } - if (xf86IsEntityShared(pScrn->entityList[0])) { - if (xf86IsPrimInitDone(pScrn->entityList[0])) { - /* do something */ - } else { - xf86SetPrimInitDone(pScrn->entityList[0]); - } - } + if (xf86IsEntityShared(pScrn->entityList[0])) { + if (xf86IsPrimInitDone(pScrn->entityList[0])) { + /* do something */ + } else { + xf86SetPrimInitDone(pScrn->entityList[0]); + } + } - BusID = xalloc(64); - sprintf(BusID, "PCI:%d:%d:%d", + BusID = xalloc(64); + sprintf(BusID, "PCI:%d:%d:%d", #if XSERVER_LIBPCIACCESS - ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), - ms->PciInfo->dev, ms->PciInfo->func + ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), + ms->PciInfo->dev, ms->PciInfo->func #else - ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum + ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum #endif - ); + ); - ms->fd = drmOpen(NULL, BusID); + ms->fd = drmOpen(NULL, BusID); - if (ms->fd < 0) - return FALSE; + if (ms->fd < 0) + return FALSE; - pScrn->racMemFlags = RAC_FB | RAC_COLORMAP; - pScrn->monitor = pScrn->confScreen->monitor; - pScrn->progClock = TRUE; - pScrn->rgbBits = 8; + pScrn->racMemFlags = RAC_FB | RAC_COLORMAP; + pScrn->monitor = pScrn->confScreen->monitor; + pScrn->progClock = TRUE; + pScrn->rgbBits = 8; - flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32; + flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32; - if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24)) - return FALSE; + if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24)) + return FALSE; - switch (pScrn->depth) { - case 8: - case 15: - case 16: - case 24: - break; - default: - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Given depth (%d) is not supported by the driver\n", - pScrn->depth); - return FALSE; - } - xf86PrintDepthBpp(pScrn); + switch (pScrn->depth) { + case 8: + case 15: + case 16: + case 24: + break; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Given depth (%d) is not supported by the driver\n", + pScrn->depth); + return FALSE; + } + xf86PrintDepthBpp(pScrn); - if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) - return FALSE; - if (!xf86SetDefaultVisual(pScrn, -1)) - return FALSE; + if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) + return FALSE; + if (!xf86SetDefaultVisual(pScrn, -1)) + return FALSE; - /* Process the options */ - xf86CollectOptions(pScrn, NULL); - if (!(ms->Options = xalloc(sizeof(Options)))) - return FALSE; - memcpy(ms->Options, Options, sizeof(Options)); - xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options); + /* Process the options */ + xf86CollectOptions(pScrn, NULL); + if (!(ms->Options = xalloc(sizeof(Options)))) + return FALSE; + memcpy(ms->Options, Options, sizeof(Options)); + xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options); - /* Allocate an xf86CrtcConfig */ - xf86CrtcConfigInit(pScrn, &crtc_config_funcs); - xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + /* Allocate an xf86CrtcConfig */ + xf86CrtcConfigInit(pScrn, &crtc_config_funcs); + xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - max_width = 8192; - max_height = 8192; - xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height); + max_width = 8192; + max_height = 8192; + xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height); - if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) { - ms->noAccel = TRUE; - } + if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) { + ms->noAccel = TRUE; + } - if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) { - ms->SWCursor = TRUE; - } + if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) { + ms->SWCursor = TRUE; + } - if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) { + if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) { if (!xf86LoadSubModule(pScrn, "shadow")) return FALSE; @@ -666,144 +672,144 @@ PreInit(ScrnInfoPtr pScrn, int flags) ms->shadowFB = TRUE; } - SaveHWState(pScrn); + SaveHWState(pScrn); - crtc_init(pScrn); - output_init(pScrn); + crtc_init(pScrn); + output_init(pScrn); - if (!xf86InitialConfiguration(pScrn, TRUE)) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n"); - RestoreHWState(pScrn); - return FALSE; - } + if (!xf86InitialConfiguration(pScrn, TRUE)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n"); + RestoreHWState(pScrn); + return FALSE; + } - RestoreHWState(pScrn); + RestoreHWState(pScrn); - /* - * If the driver can do gamma correction, it should call xf86SetGamma() here. - */ - { - Gamma zeros = { 0.0, 0.0, 0.0 }; + /* + * If the driver can do gamma correction, it should call xf86SetGamma() here. + */ + { + Gamma zeros = { 0.0, 0.0, 0.0 }; - if (!xf86SetGamma(pScrn, zeros)) { - return FALSE; - } - } + if (!xf86SetGamma(pScrn, zeros)) { + return FALSE; + } + } - if (pScrn->modes == NULL) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n"); - return FALSE; - } + if (pScrn->modes == NULL) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n"); + return FALSE; + } - pScrn->currentMode = pScrn->modes; + pScrn->currentMode = pScrn->modes; - /* Set display resolution */ - xf86SetDpi(pScrn, 0, 0); + /* Set display resolution */ + xf86SetDpi(pScrn, 0, 0); - /* Load the required sub modules */ - if (!xf86LoadSubModule(pScrn, "fb")) { - return FALSE; - } + /* Load the required sub modules */ + if (!xf86LoadSubModule(pScrn, "fb")) { + return FALSE; + } - xf86LoaderReqSymLists(fbSymbols, NULL); + xf86LoaderReqSymLists(fbSymbols, NULL); - return TRUE; + return TRUE; } static Bool SaveHWState(ScrnInfoPtr pScrn) { - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - return TRUE; + return TRUE; } static Bool RestoreHWState(ScrnInfoPtr pScrn) { - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - return TRUE; + return TRUE; } static void * WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode, - CARD32 * size, void *closure) + CARD32 * size, void *closure) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); - if (!pScrn->vtSema) - return NULL; + if (!pScrn->vtSema) + return NULL; - *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8; + *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8; - return ((CARD8 *) ms->virtual + row * (*size) + offset); + return ((CARD8 *) ms->virtual + row * (*size) + offset); } static Bool CreateScreenResources(ScreenPtr pScreen) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - Bool ret; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + Bool ret; - pScreen->CreateScreenResources = ms->createScreenResources; - ret = pScreen->CreateScreenResources(pScreen); - pScreen->CreateScreenResources = CreateScreenResources; + pScreen->CreateScreenResources = ms->createScreenResources; + ret = pScreen->CreateScreenResources(pScreen); + pScreen->CreateScreenResources = CreateScreenResources; - shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen), + shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen), ms->update, WindowLinear, 0, 0); - return ret; + return ret; } static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - VisualPtr visual; - unsigned long sys_mem; - int c; - MessageType from; - CARD8 *fbstart; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + VisualPtr visual; + unsigned long sys_mem; + int c; + MessageType from; + CARD8 *fbstart; - pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; + pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; - miClearVisualTypes(); + miClearVisualTypes(); - if (!miSetVisualTypes(pScrn->depth, - miGetDefaultVisualMask(pScrn->depth), - pScrn->rgbBits, pScrn->defaultVisual)) - return FALSE; + if (!miSetVisualTypes(pScrn->depth, + miGetDefaultVisualMask(pScrn->depth), + pScrn->rgbBits, pScrn->defaultVisual)) + return FALSE; - if (!miSetPixmapDepths()) - return FALSE; + if (!miSetPixmapDepths()) + return FALSE; - if (!MapMem(pScrn)) - return FALSE; + if (!MapMem(pScrn)) + return FALSE; - pScrn->memPhysBase = 0; - pScrn->fbOffset = 0; + pScrn->memPhysBase = 0; + pScrn->fbOffset = 0; - drmBOCreate(ms->fd, - pScrn->virtualY * pScrn->displayWidth * - pScrn->bitsPerPixel / 8, 0, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE - | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | - DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo); + drmBOCreate(ms->fd, + pScrn->virtualY * pScrn->displayWidth * + pScrn->bitsPerPixel / 8, 0, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE + | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | + DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, + DRM_BO_HINT_DONT_FENCE, &ms->bo); - MapMem(pScrn); + MapMem(pScrn); - drmModeAddFB(ms->fd, - pScrn->virtualX, - pScrn->virtualY, - pScrn->depth, - pScrn->bitsPerPixel, - pScrn->displayWidth * pScrn->bitsPerPixel / 8, - ms->bo.handle, - &ms->fb_id); + drmModeAddFB(ms->fd, + pScrn->virtualX, + pScrn->virtualY, + pScrn->depth, + pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel / 8, + ms->bo.handle, &ms->fb_id); if (ms->shadowFB) { if ((ms->shadowMem = @@ -811,140 +817,141 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) pScrn->bitsPerPixel)) == NULL) { xf86DrvMsg(scrnIndex, X_ERROR, "Allocation of shadow memory failed\n"); - return FALSE; + return FALSE; } fbstart = ms->shadowMem; } else { fbstart = ms->virtual; } - if (!fbScreenInit(pScreen, fbstart, - pScrn->virtualX, pScrn->virtualY, - pScrn->xDpi, pScrn->yDpi, - pScrn->displayWidth, pScrn->bitsPerPixel)) - return FALSE; + if (!fbScreenInit(pScreen, fbstart, + pScrn->virtualX, pScrn->virtualY, + pScrn->xDpi, pScrn->yDpi, + pScrn->displayWidth, pScrn->bitsPerPixel)) + return FALSE; - if (pScrn->bitsPerPixel > 8) { - /* Fixup RGB ordering */ - visual = pScreen->visuals + pScreen->numVisuals; - while (--visual >= pScreen->visuals) { - if ((visual->class | DynamicClass) == DirectColor) { - visual->offsetRed = pScrn->offset.red; - visual->offsetGreen = pScrn->offset.green; - visual->offsetBlue = pScrn->offset.blue; - visual->redMask = pScrn->mask.red; - visual->greenMask = pScrn->mask.green; - visual->blueMask = pScrn->mask.blue; - } - } - } + if (pScrn->bitsPerPixel > 8) { + /* Fixup RGB ordering */ + visual = pScreen->visuals + pScreen->numVisuals; + while (--visual >= pScreen->visuals) { + if ((visual->class | DynamicClass) == DirectColor) { + visual->offsetRed = pScrn->offset.red; + visual->offsetGreen = pScrn->offset.green; + visual->offsetBlue = pScrn->offset.blue; + visual->redMask = pScrn->mask.red; + visual->greenMask = pScrn->mask.green; + visual->blueMask = pScrn->mask.blue; + } + } + } - fbPictureInit(pScreen, NULL, 0); + fbPictureInit(pScreen, NULL, 0); if (ms->shadowFB) { ms->update = shadowUpdatePackedWeak(); if (!shadowSetup(pScreen)) { xf86DrvMsg(scrnIndex, X_ERROR, "Shadow framebuffer initialization failed.\n"); - return FALSE; + return FALSE; } ms->createScreenResources = pScreen->CreateScreenResources; pScreen->CreateScreenResources = CreateScreenResources; } - xf86SetBlackWhitePixels(pScreen); + xf86SetBlackWhitePixels(pScreen); #if 0 - glucoseScreenInit(pScreen, 0); + glucoseScreenInit(pScreen, 0); #endif #if 0 - ms->pExa = ExaInit(pScreen); + ms->pExa = ExaInit(pScreen); #endif - miInitializeBackingStore(pScreen); - xf86SetBackingStore(pScreen); - xf86SetSilkenMouse(pScreen); - miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); + miInitializeBackingStore(pScreen); + xf86SetBackingStore(pScreen); + xf86SetSilkenMouse(pScreen); + miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); - /* Must force it before EnterVT, so we are in control of VT and - * later memory should be bound when allocating, e.g rotate_mem */ - pScrn->vtSema = TRUE; + /* Must force it before EnterVT, so we are in control of VT and + * later memory should be bound when allocating, e.g rotate_mem */ + pScrn->vtSema = TRUE; - pScreen->SaveScreen = xf86SaveScreen; - ms->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = CloseScreen; + pScreen->SaveScreen = xf86SaveScreen; + ms->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = CloseScreen; - if (!xf86CrtcScreenInit(pScreen)) - return FALSE; + if (!xf86CrtcScreenInit(pScreen)) + return FALSE; - if (!miCreateDefColormap(pScreen)) - return FALSE; + if (!miCreateDefColormap(pScreen)) + return FALSE; #if 0 - if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL, - CMAP_RELOAD_ON_MODE_SWITCH | - CMAP_PALETTED_TRUECOLOR)) { - return FALSE; - } + if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL, + CMAP_RELOAD_ON_MODE_SWITCH | + CMAP_PALETTED_TRUECOLOR)) { + return FALSE; + } #endif - xf86DPMSInit(pScreen, xf86DPMSSet, 0); + xf86DPMSInit(pScreen, xf86DPMSSet, 0); #if 0 - glucoseInitVideo(pScreen); + glucoseInitVideo(pScreen); #endif - if (serverGeneration == 1) - xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); + if (serverGeneration == 1) + xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); - return EnterVT(scrnIndex, 0); + return EnterVT(scrnIndex, 0); } static void AdjustFrame(int scrnIndex, int x, int y, int flags) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - xf86OutputPtr output = config->output[config->compat_output]; - xf86CrtcPtr crtc = output->crtc; + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + xf86OutputPtr output = config->output[config->compat_output]; + xf86CrtcPtr crtc = output->crtc; - if (crtc && crtc->enabled) { - crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x, y); - crtc->x = output->initial_x + x; - crtc->y = output->initial_y + y; - } + if (crtc && crtc->enabled) { + crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x, + y); + crtc->x = output->initial_x + x; + crtc->y = output->initial_y + y; + } } static void FreeScreen(int scrnIndex, int flags) { - FreeRec(xf86Screens[scrnIndex]); + FreeRec(xf86Screens[scrnIndex]); } static void LeaveVT(int scrnIndex, int flags) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; - modesettingPtr ms = modesettingPTR(pScrn); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int o; + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + modesettingPtr ms = modesettingPTR(pScrn); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + int o; - for (o = 0; o < config->num_crtc; o++) { - xf86CrtcPtr crtc = config->crtc[o]; + for (o = 0; o < config->num_crtc; o++) { + xf86CrtcPtr crtc = config->crtc[o]; - if (crtc->rotatedPixmap || crtc->rotatedData) { - crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, - crtc->rotatedData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - } + if (crtc->rotatedPixmap || crtc->rotatedData) { + crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, + crtc->rotatedData); + crtc->rotatedPixmap = NULL; + crtc->rotatedData = NULL; + } + } - xf86_hide_cursors(pScrn); + xf86_hide_cursors(pScrn); - drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0); + drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0); - RestoreHWState(pScrn); + RestoreHWState(pScrn); } /* @@ -953,76 +960,76 @@ LeaveVT(int scrnIndex, int flags) static Bool EnterVT(int scrnIndex, int flags) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; - modesettingPtr ms = modesettingPTR(pScrn); + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + modesettingPtr ms = modesettingPTR(pScrn); - /* - * Only save state once per server generation since that's what most - * drivers do. Could change this to save state at each VT enter. - */ - if (ms->SaveGeneration != serverGeneration) { - ms->SaveGeneration = serverGeneration; - SaveHWState(pScrn); - } + /* + * Only save state once per server generation since that's what most + * drivers do. Could change this to save state at each VT enter. + */ + if (ms->SaveGeneration != serverGeneration) { + ms->SaveGeneration = serverGeneration; + SaveHWState(pScrn); + } - drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); + drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); - if (!xf86SetDesiredModes(pScrn)) - return FALSE; + if (!xf86SetDesiredModes(pScrn)) + return FALSE; - AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); - return TRUE; + return TRUE; } static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; - return xf86SetSingleMode(pScrn, mode, RR_Rotate_0); + return xf86SetSingleMode(pScrn, mode, RR_Rotate_0); } static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; - modesettingPtr ms = modesettingPTR(pScrn); + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + modesettingPtr ms = modesettingPTR(pScrn); - if (pScrn->vtSema == TRUE) { - LeaveVT(scrnIndex, 0); - drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); - } + if (pScrn->vtSema == TRUE) { + LeaveVT(scrnIndex, 0); + drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); + } - UnmapMem(pScrn); + UnmapMem(pScrn); - if (ms->shadowFB) - pScreen->CreateScreenResources = ms->createScreenResources; + if (ms->shadowFB) + pScreen->CreateScreenResources = ms->createScreenResources; - if (ms->shadowMem) { - xfree(ms->shadowMem); - ms->shadowMem = NULL; - } + if (ms->shadowMem) { + xfree(ms->shadowMem); + ms->shadowMem = NULL; + } - if (ms->pExa) - ExaClose(pScrn); + if (ms->pExa) + ExaClose(pScrn); - /* move old buffer out of the way */ - drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL, - DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT, - DRM_BO_HINT_DONT_FENCE, 0, 0); + /* move old buffer out of the way */ + drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL, + DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT, + DRM_BO_HINT_DONT_FENCE, 0, 0); - drmBOUnreference(ms->fd, &ms->bo); + drmBOUnreference(ms->fd, &ms->bo); - drmClose(ms->fd); + drmClose(ms->fd); - pScrn->vtSema = FALSE; - pScreen->CloseScreen = ms->CloseScreen; - return (*pScreen->CloseScreen) (scrnIndex, pScreen); + pScrn->vtSema = FALSE; + pScreen->CloseScreen = ms->CloseScreen; + return (*pScreen->CloseScreen) (scrnIndex, pScreen); } static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags) { - return MODE_OK; + return MODE_OK; } diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index 2a0990312..c9cb76497 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -36,53 +36,55 @@ #define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg); -typedef struct { - int lastInstance; - int refCount; - ScrnInfoPtr pScrn_1; - ScrnInfoPtr pScrn_2; +typedef struct +{ + int lastInstance; + int refCount; + ScrnInfoPtr pScrn_1; + ScrnInfoPtr pScrn_2; } EntRec, *EntPtr; -typedef struct _modesettingRec { - int fd; - unsigned int fb_id; - void *virtual; - drmBO bo; +typedef struct _modesettingRec +{ + int fd; + unsigned int fb_id; + void *virtual; + drmBO bo; - EntPtr entityPrivate; + EntPtr entityPrivate; - void (*PointerMoved)(int, int, int); + void (*PointerMoved) (int, int, int); - int Chipset; - EntityInfoPtr pEnt; + int Chipset; + EntityInfoPtr pEnt; #if XSERVER_LIBPCIACCESS - struct pci_device *PciInfo; + struct pci_device *PciInfo; #else - pciVideoPtr PciInfo; - PCITAG PciTag; + pciVideoPtr PciInfo; + PCITAG PciTag; #endif - Bool noAccel; - Bool SWCursor; - CloseScreenProcPtr CloseScreen; + Bool noAccel; + Bool SWCursor; + CloseScreenProcPtr CloseScreen; - Bool directRenderingDisabled; /* DRI disabled in PreInit. */ - Bool directRenderingEnabled; /* DRI enabled this generation. */ + Bool directRenderingDisabled; /* DRI disabled in PreInit. */ + Bool directRenderingEnabled; /* DRI enabled this generation. */ - /* Broken-out options. */ - OptionInfoPtr Options; + /* Broken-out options. */ + OptionInfoPtr Options; - unsigned int SaveGeneration; + unsigned int SaveGeneration; - /* shadowfb */ - CARD8 *shadowMem; - Bool shadowFB; - CreateScreenResourcesProcPtr createScreenResources; - ShadowUpdateProc update; + /* shadowfb */ + CARD8 *shadowMem; + Bool shadowFB; + CreateScreenResourcesProcPtr createScreenResources; + ShadowUpdateProc update; - /* exa */ - ExaDriverPtr pExa; - drmBO exa_bo; + /* exa */ + ExaDriverPtr pExa; + drmBO exa_bo; } modesettingRec, *modesettingPtr; #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c index a9be2c12d..70968f01f 100644 --- a/hw/xfree86/drivers/modesetting/exa.c +++ b/hw/xfree86/drivers/modesetting/exa.c @@ -102,7 +102,7 @@ ExaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2) static Bool ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, - int ydir, int alu, Pixel planeMask) + int ydir, int alu, Pixel planeMask) { ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; @@ -115,15 +115,15 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, static void ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY, - int width, int height) + int width, int height) { ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; } static Bool ExaPrepareComposite(int op, PicturePtr pSrcPicture, - PicturePtr pMaskPicture, PicturePtr pDstPicture, - PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst) + PicturePtr pMaskPicture, PicturePtr pDstPicture, + PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst) { ScreenPtr pScreen = pDst->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; @@ -133,7 +133,7 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture, static Bool ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, - int src_pitch) + int src_pitch) { ScreenPtr pScreen = pDst->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; @@ -143,7 +143,7 @@ ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, static void ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY, - int dstX, int dstY, int width, int height) + int dstX, int dstY, int width, int height) { ScreenPtr pScreen = pDst->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; @@ -151,8 +151,8 @@ ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY, static Bool ExaCheckComposite(int op, - PicturePtr pSrcPicture, PicturePtr pMaskPicture, - PicturePtr pDstPicture) + PicturePtr pSrcPicture, PicturePtr pMaskPicture, + PicturePtr pDstPicture) { DrawablePtr pDraw = pSrcPicture->pDrawable; int w = pDraw->width; @@ -173,17 +173,17 @@ ExaPixmapIsOffscreen(PixmapPtr p) void ExaClose(ScrnInfoPtr pScrn) { - modesettingPtr ms = modesettingPTR(pScrn); + modesettingPtr ms = modesettingPTR(pScrn); exaDriverFini(pScrn->pScreen); - drmBOUnreference(ms->fd, &ms->exa_bo); + drmBOUnreference(ms->fd, &ms->exa_bo); } ExaDriverPtr ExaInit(ScrnInfoPtr pScrn) { - modesettingPtr ms = modesettingPTR(pScrn); + modesettingPtr ms = modesettingPTR(pScrn); ExaDriverPtr pExa; pExa = exaDriverAlloc(); @@ -192,7 +192,9 @@ ExaInit(ScrnInfoPtr pScrn) } /* Create a 256KB offscreen area */ - drmBOCreate(ms->fd, 256 * 1024, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->exa_bo); + drmBOCreate(ms->fd, 256 * 1024, 0, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT, + DRM_BO_HINT_DONT_FENCE, &ms->exa_bo); memset(pExa, 0, sizeof(*pExa)); pExa->exa_major = 2; @@ -203,8 +205,8 @@ ExaInit(ScrnInfoPtr pScrn) pExa->pixmapOffsetAlign = 8; pExa->pixmapPitchAlign = 32 * 4; pExa->flags = EXA_OFFSCREEN_PIXMAPS; - pExa->maxX = 8191; /* FIXME */ - pExa->maxY = 8191; /* FIXME */ + pExa->maxX = 8191; /* FIXME */ + pExa->maxY = 8191; /* FIXME */ pExa->WaitMarker = ExaWaitMarker; pExa->MarkSync = ExaMarkSync; pExa->PrepareSolid = ExaPrepareSolid; diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c index b25540ee0..4a67ccc30 100644 --- a/hw/xfree86/drivers/modesetting/output.c +++ b/hw/xfree86/drivers/modesetting/output.c @@ -69,20 +69,20 @@ restore(xf86OutputPtr output) static int mode_valid(xf86OutputPtr output, DisplayModePtr pMode) { - return MODE_OK; + return MODE_OK; } static Bool mode_fixup(xf86OutputPtr output, DisplayModePtr mode, DisplayModePtr adjusted_mode) { - return TRUE; + return TRUE; } static void prepare(xf86OutputPtr output) { - dpms(output, DPMSModeOff); + dpms(output, DPMSModeOff); } static void @@ -94,69 +94,69 @@ mode_set(xf86OutputPtr output, DisplayModePtr mode, static void commit(xf86OutputPtr output) { - dpms(output, DPMSModeOn); + dpms(output, DPMSModeOn); - if (output->scrn->pScreen != NULL) - xf86_reload_cursors(output->scrn->pScreen); + if (output->scrn->pScreen != NULL) + xf86_reload_cursors(output->scrn->pScreen); } static xf86OutputStatus detect(xf86OutputPtr output) { - drmModeOutputPtr drm_output = output->driver_private; + drmModeOutputPtr drm_output = output->driver_private; - switch (drm_output->connection) { - case DRM_MODE_CONNECTED: - return XF86OutputStatusConnected; - case DRM_MODE_DISCONNECTED: - return XF86OutputStatusDisconnected; - default: - return XF86OutputStatusUnknown; - } + switch (drm_output->connection) { + case DRM_MODE_CONNECTED: + return XF86OutputStatusConnected; + case DRM_MODE_DISCONNECTED: + return XF86OutputStatusDisconnected; + default: + return XF86OutputStatusUnknown; + } } static DisplayModePtr get_modes(xf86OutputPtr output) { - drmModeOutputPtr drm_output = output->driver_private; - struct drm_mode_modeinfo *drm_mode = NULL; - DisplayModePtr modes = NULL, mode = NULL; - int i; + drmModeOutputPtr drm_output = output->driver_private; + struct drm_mode_modeinfo *drm_mode = NULL; + DisplayModePtr modes = NULL, mode = NULL; + int i; - for (i = 0; i < drm_output->count_modes; i++) { - drm_mode = &drm_output->modes[i]; - if (drm_mode) { - mode = xcalloc(1, sizeof(DisplayModeRec)); - if (!mode) - continue; - mode->type = 0; - mode->Clock = drm_mode->clock; - mode->HDisplay = drm_mode->hdisplay; - mode->HSyncStart = drm_mode->hsync_start; - mode->HSyncEnd = drm_mode->hsync_end; - mode->HTotal = drm_mode->htotal; - mode->VDisplay = drm_mode->vdisplay; - mode->VSyncStart = drm_mode->vsync_start; - mode->VSyncEnd = drm_mode->vsync_end; - mode->VTotal = drm_mode->vtotal; - mode->Flags = drm_mode->flags; - mode->HSkew = drm_mode->hskew; - mode->VScan = drm_mode->vscan; - mode->VRefresh = xf86ModeVRefresh(mode); - mode->Private = (void *)drm_mode; - xf86SetModeDefaultName(mode); - modes = xf86ModesAdd(modes, mode); - xf86PrintModeline(0, mode); - } - } + for (i = 0; i < drm_output->count_modes; i++) { + drm_mode = &drm_output->modes[i]; + if (drm_mode) { + mode = xcalloc(1, sizeof(DisplayModeRec)); + if (!mode) + continue; + mode->type = 0; + mode->Clock = drm_mode->clock; + mode->HDisplay = drm_mode->hdisplay; + mode->HSyncStart = drm_mode->hsync_start; + mode->HSyncEnd = drm_mode->hsync_end; + mode->HTotal = drm_mode->htotal; + mode->VDisplay = drm_mode->vdisplay; + mode->VSyncStart = drm_mode->vsync_start; + mode->VSyncEnd = drm_mode->vsync_end; + mode->VTotal = drm_mode->vtotal; + mode->Flags = drm_mode->flags; + mode->HSkew = drm_mode->hskew; + mode->VScan = drm_mode->vscan; + mode->VRefresh = xf86ModeVRefresh(mode); + mode->Private = (void *)drm_mode; + xf86SetModeDefaultName(mode); + modes = xf86ModesAdd(modes, mode); + xf86PrintModeline(0, mode); + } + } - return modes; + return modes; } static void destroy(xf86OutputPtr output) { - drmModeFreeOutput(output->driver_private); + drmModeFreeOutput(output->driver_private); } static void @@ -170,7 +170,7 @@ create_resources(xf86OutputPtr output) static Bool set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value) { - return TRUE; + return TRUE; } #endif /* RANDR_12_INTERFACE */ @@ -178,7 +178,7 @@ set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value) static Bool get_property(xf86OutputPtr output, Atom property) { - return TRUE; + return TRUE; } #endif /* RANDR_13_INTERFACE */ @@ -186,100 +186,102 @@ get_property(xf86OutputPtr output, Atom property) static xf86CrtcPtr get_crtc(xf86OutputPtr output) { - return NULL; + return NULL; } #endif static const xf86OutputFuncsRec output_funcs = { - .create_resources = create_resources, - .dpms = dpms, - .save = save, - .restore = restore, - .mode_valid = mode_valid, - .mode_fixup = mode_fixup, - .prepare = prepare, - .mode_set = mode_set, - .commit = commit, - .detect = detect, - .get_modes = get_modes, + .create_resources = create_resources, + .dpms = dpms, + .save = save, + .restore = restore, + .mode_valid = mode_valid, + .mode_fixup = mode_fixup, + .prepare = prepare, + .mode_set = mode_set, + .commit = commit, + .detect = detect, + .get_modes = get_modes, #ifdef RANDR_12_INTERFACE - .set_property = set_property, + .set_property = set_property, #endif #ifdef RANDR_13_INTERFACE - .get_property = get_property, + .get_property = get_property, #endif - .destroy = destroy, + .destroy = destroy, #ifdef RANDR_GET_CRTC_INTERFACE - .get_crtc = get_crtc, + .get_crtc = get_crtc, #endif }; void output_init(ScrnInfoPtr pScrn) { - modesettingPtr ms = modesettingPTR(pScrn); - xf86OutputPtr output; - drmModeResPtr res; - drmModeOutputPtr drm_output = NULL; - drmModeCrtcPtr crtc; - char *name; - int o, v, p; + modesettingPtr ms = modesettingPTR(pScrn); + xf86OutputPtr output; + drmModeResPtr res; + drmModeOutputPtr drm_output = NULL; + drmModeCrtcPtr crtc; + char *name; + int o, v, p; - res = drmModeGetResources(ms->fd); - if (res == 0) { - DRV_ERROR("Failed drmModeGetResources\n"); - return; - } + res = drmModeGetResources(ms->fd); + if (res == 0) { + DRV_ERROR("Failed drmModeGetResources\n"); + return; + } - for (o = 0; o < res->count_outputs; o++) { - drm_output = drmModeGetOutput(ms->fd, res->outputs[o]); - if (!drm_output) - goto out; + for (o = 0; o < res->count_outputs; o++) { + drm_output = drmModeGetOutput(ms->fd, res->outputs[o]); + if (!drm_output) + goto out; - for (p = 0; p < drm_output->count_props; p++) { - drmModePropertyPtr prop; + for (p = 0; p < drm_output->count_props; p++) { + drmModePropertyPtr prop; - prop = drmModeGetProperty(ms->fd, drm_output->props[p]); + prop = drmModeGetProperty(ms->fd, drm_output->props[p]); - name = NULL; - if (prop) { - ErrorF("VALUES %d\n",prop->count_values); + name = NULL; + if (prop) { + ErrorF("VALUES %d\n", prop->count_values); - for (v=0;vcount_values;v++) - ErrorF("%s %lld\n", prop->name, prop->values[v]); + for (v = 0; v < prop->count_values; v++) + ErrorF("%s %lld\n", prop->name, prop->values[v]); - for (v=0;vcount_enums;v++) { - ErrorF("%s %s\n", prop->name, prop->enums[v].name); - if (drm_output->prop_values[p] == prop->enums[v].value) { - if (!strncmp("Connector Type", prop->name, 14)) { - ErrorF("WE'VE GOT %s\n",prop->enums[v].name); - name = xalloc(strlen(prop->enums[v].name)); - strncpy(name, prop->enums[v].name, strlen(name)); + for (v = 0; v < prop->count_enums; v++) { + ErrorF("%s %s\n", prop->name, prop->enums[v].name); + if (drm_output->prop_values[p] == prop->enums[v].value) { + if (!strncmp("Connector Type", prop->name, 14)) { + ErrorF("WE'VE GOT %s\n", prop->enums[v].name); + name = xalloc(strlen(prop->enums[v].name)); + strncpy(name, prop->enums[v].name, strlen(name)); + } + } + if (name) + break; } - } - if (name) break; + if (name) + break; } - if (name) break; - } - } + } - if (!name) - continue; + if (!name) + continue; - output = xf86OutputCreate(pScrn, &output_funcs, name); - if (!output) - continue; + output = xf86OutputCreate(pScrn, &output_funcs, name); + if (!output) + continue; free(name); - output->possible_crtcs = drm_output->crtcs; - output->possible_clones = drm_output->clones; - output->driver_private = drm_output; - output->subpixel_order = SubPixelHorizontalRGB; - output->interlaceAllowed = FALSE; - output->doubleScanAllowed = FALSE; - } + output->possible_crtcs = drm_output->crtcs; + output->possible_clones = drm_output->clones; + output->driver_private = drm_output; + output->subpixel_order = SubPixelHorizontalRGB; + output->interlaceAllowed = FALSE; + output->doubleScanAllowed = FALSE; + } -out: - drmModeFreeResources(res); + out: + drmModeFreeResources(res); } From 000ead4503ddcfdf66ce9fffc572a3a741f4055a Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Wed, 28 May 2008 19:59:38 +0100 Subject: [PATCH 003/122] Plug in hardware cursor support --- hw/xfree86/drivers/modesetting/crtc.c | 98 ++++++++++++++++++++++--- hw/xfree86/drivers/modesetting/driver.c | 5 ++ 2 files changed, 91 insertions(+), 12 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c index 66b23f695..bf726b501 100644 --- a/hw/xfree86/drivers/modesetting/crtc.c +++ b/hw/xfree86/drivers/modesetting/crtc.c @@ -47,6 +47,13 @@ #define DPMS_SERVER #include +struct crtc_private { + drmModeCrtcPtr drm_crtc; + + /* hwcursor */ + drmBO cursor_bo; +}; + static void crtc_dpms(xf86CrtcPtr crtc, int mode) { @@ -98,7 +105,8 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, modesettingPtr ms = modesettingPTR(crtc->scrn); xf86OutputPtr output = config->output[config->compat_output]; drmModeOutputPtr drm_output = output->driver_private; - drmModeCrtcPtr drm_crtc = crtc->driver_private; + struct crtc_private *crtcp = crtc->driver_private; + drmModeCrtcPtr drm_crtc = crtcp->drm_crtc; struct drm_mode_modeinfo drm_mode; drm_mode.clock = mode->Clock; @@ -157,13 +165,64 @@ crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data) static void crtc_destroy(xf86CrtcPtr crtc) { - drmModeFreeCrtc(crtc->driver_private); + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + + drmBOUnreference(ms->fd, &crtcp->cursor_bo); + drmModeFreeCrtc(crtcp->drm_crtc); +} + +static void +crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) +{ + unsigned char *ptr; + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + + drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, 0, (void **)&ptr); + + memcpy (ptr, image, 64 * 64 * 4); + + drmBOUnmap(ms->fd, &crtcp->cursor_bo); +} + +static void +crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + + drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y); +} + +static void +crtc_show_cursor (xf86CrtcPtr crtc) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + + drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64); +} + +static void +crtc_hide_cursor (xf86CrtcPtr crtc) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + + drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0); +} + +static void +crtc_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg) +{ + ScrnInfoPtr scrn = crtc->scrn; } static const xf86CrtcFuncsRec crtc_funcs = { .dpms = crtc_dpms, - .save = NULL, /* XXX */ - .restore = NULL, /* XXX */ + .save = NULL, + .restore = NULL, .lock = crtc_lock, .unlock = crtc_unlock, .mode_fixup = crtc_mode_fixup, @@ -174,13 +233,13 @@ static const xf86CrtcFuncsRec crtc_funcs = { .shadow_create = crtc_shadow_create, .shadow_allocate = crtc_shadow_allocate, .shadow_destroy = crtc_shadow_destroy, -// .set_cursor_colors = crtc_set_cursor_colors, -// .set_cursor_position = crtc_set_cursor_position, -// .show_cursor = crtc_show_cursor, -// .hide_cursor = crtc_hide_cursor, -// .load_cursor_image = crtc_load_cursor_image, -// .load_cursor_argb = crtc_load_cursor_argb, - .destroy = crtc_destroy, /* XXX */ + .set_cursor_colors = crtc_set_cursor_colors, + .set_cursor_position = crtc_set_cursor_position, + .show_cursor = crtc_show_cursor, + .hide_cursor = crtc_hide_cursor, + .load_cursor_image = NULL, /* lets convert to argb only */ + .load_cursor_argb = crtc_load_cursor_argb, + .destroy = crtc_destroy, }; void @@ -190,6 +249,7 @@ crtc_init(ScrnInfoPtr pScrn) xf86CrtcPtr crtc; drmModeResPtr res; drmModeCrtcPtr drm_crtc = NULL; + struct crtc_private *crtcp; int c, k, p; res = drmModeGetResources(ms->fd); @@ -207,7 +267,21 @@ crtc_init(ScrnInfoPtr pScrn) if (crtc == NULL) goto out; - crtc->driver_private = drm_crtc; + crtcp = xalloc(sizeof(struct crtc_private)); + if (!crtcp) { + xf86CrtcDestroy(crtc); + goto out; + } + + crtcp->drm_crtc = drm_crtc; + + crtc->driver_private = crtcp; + + drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE + | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | + DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, + DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo); } out: diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index de4b26014..8f1c90513 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -872,6 +872,11 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) xf86SetSilkenMouse(pScreen); miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); + /* Need to extend HWcursor support in kernel to handle mask interleave ?? */ + xf86_cursors_init (pScreen, 64, 64, + HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | + HARDWARE_CURSOR_ARGB); + /* Must force it before EnterVT, so we are in control of VT and * later memory should be bound when allocating, e.g rotate_mem */ pScrn->vtSema = TRUE; From cba8b25a7e2608cd093283f86f08fba50a6a62f7 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Mon, 2 Jun 2008 11:17:47 +0100 Subject: [PATCH 004/122] Bring inline with current modesetting-101 branch for connector/encoder changes --- hw/xfree86/drivers/modesetting/crtc.c | 4 +- hw/xfree86/drivers/modesetting/output.c | 53 ++++++++++++++++--------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c index bf726b501..14ee53eed 100644 --- a/hw/xfree86/drivers/modesetting/crtc.c +++ b/hw/xfree86/drivers/modesetting/crtc.c @@ -104,7 +104,7 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); modesettingPtr ms = modesettingPTR(crtc->scrn); xf86OutputPtr output = config->output[config->compat_output]; - drmModeOutputPtr drm_output = output->driver_private; + drmModeConnectorPtr drm_connector = output->driver_private; struct crtc_private *crtcp = crtc->driver_private; drmModeCrtcPtr drm_crtc = crtcp->drm_crtc; struct drm_mode_modeinfo drm_mode; @@ -125,7 +125,7 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN); drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y, - &drm_output->output_id, 1, &drm_mode); + &drm_connector->connector_id, 1, &drm_mode); } void diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c index 4a67ccc30..7767ef2c2 100644 --- a/hw/xfree86/drivers/modesetting/output.c +++ b/hw/xfree86/drivers/modesetting/output.c @@ -103,9 +103,9 @@ commit(xf86OutputPtr output) static xf86OutputStatus detect(xf86OutputPtr output) { - drmModeOutputPtr drm_output = output->driver_private; + drmModeConnectorPtr drm_connector = output->driver_private; - switch (drm_output->connection) { + switch (drm_connector->connection) { case DRM_MODE_CONNECTED: return XF86OutputStatusConnected; case DRM_MODE_DISCONNECTED: @@ -118,13 +118,13 @@ detect(xf86OutputPtr output) static DisplayModePtr get_modes(xf86OutputPtr output) { - drmModeOutputPtr drm_output = output->driver_private; + drmModeConnectorPtr drm_connector = output->driver_private; struct drm_mode_modeinfo *drm_mode = NULL; DisplayModePtr modes = NULL, mode = NULL; int i; - for (i = 0; i < drm_output->count_modes; i++) { - drm_mode = &drm_output->modes[i]; + for (i = 0; i < drm_connector->count_modes; i++) { + drm_mode = &drm_connector->modes[i]; if (drm_mode) { mode = xcalloc(1, sizeof(DisplayModeRec)); if (!mode) @@ -156,7 +156,7 @@ get_modes(xf86OutputPtr output) static void destroy(xf86OutputPtr output) { - drmModeFreeOutput(output->driver_private); + drmModeFreeConnector(output->driver_private); } static void @@ -220,10 +220,11 @@ output_init(ScrnInfoPtr pScrn) modesettingPtr ms = modesettingPTR(pScrn); xf86OutputPtr output; drmModeResPtr res; - drmModeOutputPtr drm_output = NULL; + drmModeConnectorPtr drm_connector = NULL; + drmModeEncoderPtr drm_encoder = NULL; drmModeCrtcPtr crtc; char *name; - int o, v, p; + int c, v, p; res = drmModeGetResources(ms->fd); if (res == 0) { @@ -231,15 +232,16 @@ output_init(ScrnInfoPtr pScrn) return; } - for (o = 0; o < res->count_outputs; o++) { - drm_output = drmModeGetOutput(ms->fd, res->outputs[o]); - if (!drm_output) + for (c = 0; c < res->count_connectors; c++) { + drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]); + if (!drm_connector) goto out; - for (p = 0; p < drm_output->count_props; p++) { +#if 0 + for (p = 0; p < drm_connector->count_props; p++) { drmModePropertyPtr prop; - prop = drmModeGetProperty(ms->fd, drm_output->props[p]); + prop = drmModeGetProperty(ms->fd, drm_connector->props[p]); name = NULL; if (prop) { @@ -250,7 +252,7 @@ output_init(ScrnInfoPtr pScrn) for (v = 0; v < prop->count_enums; v++) { ErrorF("%s %s\n", prop->name, prop->enums[v].name); - if (drm_output->prop_values[p] == prop->enums[v].value) { + if (drm_connector->prop_values[p] == prop->enums[v].value) { if (!strncmp("Connector Type", prop->name, 14)) { ErrorF("WE'VE GOT %s\n", prop->enums[v].name); name = xalloc(strlen(prop->enums[v].name)); @@ -267,16 +269,29 @@ output_init(ScrnInfoPtr pScrn) if (!name) continue; +#endif + + +#if 0 + free(name); +#endif + + + name = "Unknown"; output = xf86OutputCreate(pScrn, &output_funcs, name); if (!output) continue; - free(name); - - output->possible_crtcs = drm_output->crtcs; - output->possible_clones = drm_output->clones; - output->driver_private = drm_output; + drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoder); + if (drm_encoder) { + output->possible_crtcs = drm_encoder->crtcs; + output->possible_clones = drm_encoder->clones; + } else { + output->possible_crtcs = 0; + output->possible_clones = 0; + } + output->driver_private = drm_connector; output->subpixel_order = SubPixelHorizontalRGB; output->interlaceAllowed = FALSE; output->doubleScanAllowed = FALSE; From 47969d79289ad92f658c9a6dd2a2fc6b5f1b6c99 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Mon, 16 Jun 2008 15:07:39 +0100 Subject: [PATCH 006/122] Add DRI2 support. Add EXA stubs. Currently tested with i915. --- hw/xfree86/drivers/modesetting/Makefile.am | 3 +- hw/xfree86/drivers/modesetting/crtc.c | 47 +++-- hw/xfree86/drivers/modesetting/dri2.c | 127 ++++++++++++ hw/xfree86/drivers/modesetting/driver.c | 220 +++++++++++++++------ hw/xfree86/drivers/modesetting/driver.h | 10 +- hw/xfree86/drivers/modesetting/exa.c | 189 ++++++++++++++++-- hw/xfree86/drivers/modesetting/output.c | 48 ++--- 7 files changed, 521 insertions(+), 123 deletions(-) create mode 100644 hw/xfree86/drivers/modesetting/dri2.c diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am index 17d884fde..a182d4423 100644 --- a/hw/xfree86/drivers/modesetting/Makefile.am +++ b/hw/xfree86/drivers/modesetting/Makefile.am @@ -37,6 +37,7 @@ modesetting_drv_la_SOURCES = \ driver.h \ output.c \ crtc.c \ - exa.c + exa.c \ + dri2.c EXTRA_DIST = diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c index 14ee53eed..89ffe92e6 100644 --- a/hw/xfree86/drivers/modesetting/crtc.c +++ b/hw/xfree86/drivers/modesetting/crtc.c @@ -168,8 +168,11 @@ crtc_destroy(xf86CrtcPtr crtc) modesettingPtr ms = modesettingPTR(crtc->scrn); struct crtc_private *crtcp = crtc->driver_private; - drmBOUnreference(ms->fd, &crtcp->cursor_bo); + if (crtcp->cursor_bo.handle) + drmBOUnreference(ms->fd, &crtcp->cursor_bo); + drmModeFreeCrtc(crtcp->drm_crtc); + xfree(crtcp); } static void @@ -179,9 +182,17 @@ crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) modesettingPtr ms = modesettingPTR(crtc->scrn); struct crtc_private *crtcp = crtc->driver_private; - drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, 0, (void **)&ptr); + if (!crtcp->cursor_bo.handle) + drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE + | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | + DRM_BO_FLAG_MEM_VRAM, + DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo); - memcpy (ptr, image, 64 * 64 * 4); + drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, DRM_BO_HINT_DONT_FENCE, (void **)&ptr); + + if (ptr) + memcpy (ptr, image, 64 * 64 * 4); drmBOUnmap(ms->fd, &crtcp->cursor_bo); } @@ -201,7 +212,8 @@ crtc_show_cursor (xf86CrtcPtr crtc) modesettingPtr ms = modesettingPTR(crtc->scrn); struct crtc_private *crtcp = crtc->driver_private; - drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64); + if (crtcp->cursor_bo.handle) + drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64); } static void @@ -213,12 +225,6 @@ crtc_hide_cursor (xf86CrtcPtr crtc) drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0); } -static void -crtc_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg) -{ - ScrnInfoPtr scrn = crtc->scrn; -} - static const xf86CrtcFuncsRec crtc_funcs = { .dpms = crtc_dpms, .save = NULL, @@ -233,15 +239,27 @@ static const xf86CrtcFuncsRec crtc_funcs = { .shadow_create = crtc_shadow_create, .shadow_allocate = crtc_shadow_allocate, .shadow_destroy = crtc_shadow_destroy, - .set_cursor_colors = crtc_set_cursor_colors, .set_cursor_position = crtc_set_cursor_position, .show_cursor = crtc_show_cursor, .hide_cursor = crtc_hide_cursor, .load_cursor_image = NULL, /* lets convert to argb only */ + .set_cursor_colors = NULL, /* using argb only */ .load_cursor_argb = crtc_load_cursor_argb, .destroy = crtc_destroy, }; +void +cursor_destroy(xf86CrtcPtr crtc) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + + if (crtcp->cursor_bo.handle) { + drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0); + drmBOUnreference(ms->fd, &crtcp->cursor_bo); + } +} + void crtc_init(ScrnInfoPtr pScrn) { @@ -267,7 +285,7 @@ crtc_init(ScrnInfoPtr pScrn) if (crtc == NULL) goto out; - crtcp = xalloc(sizeof(struct crtc_private)); + crtcp = xcalloc(1, sizeof(struct crtc_private)); if (!crtcp) { xf86CrtcDestroy(crtc); goto out; @@ -277,11 +295,6 @@ crtc_init(ScrnInfoPtr pScrn) crtc->driver_private = crtcp; - drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE - | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | - DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, - DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo); } out: diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c new file mode 100644 index 000000000..eec80696b --- /dev/null +++ b/hw/xfree86/drivers/modesetting/dri2.c @@ -0,0 +1,127 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "xf86.h" +#include "xf86_OSproc.h" + +#include "driver.h" + +#include "dri2.h" + +extern unsigned int +driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); + +void +driLock(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + + if (!ms->lock_held) + DRM_LOCK(ms->fd, ms->lock, ms->context, 0); + + ms->lock_held = 1; +} + +void +driUnlock(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + + if (ms->lock_held) + DRM_UNLOCK(ms->fd, ms->lock, ms->context); + + ms->lock_held = 0; +} + +static void +driBeginClipNotify(ScreenPtr pScreen) +{ + driLock(pScreen); +} + +static void +driEndClipNotify(ScreenPtr pScreen) +{ + driUnlock(pScreen); +} + +struct __DRILock { + unsigned int block_header; + drm_hw_lock_t lock; + unsigned int next_id; +}; + +#define DRI2_SAREA_BLOCK_HEADER(type, size) (((type) << 16) | (size)) +#define DRI2_SAREA_BLOCK_LOCK 0x0001 + +void +driScreenInit(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + DRI2InfoRec dri2info; + const char *driverName; + unsigned int sarea_handle; + struct __DRILock *DRILock; + void *p; + + dri2info.version = 1; + dri2info.fd = ms->fd; + dri2info.driverSareaSize = sizeof(struct __DRILock); + dri2info.driverName = "i915"; /* FIXME */ + dri2info.getPixmapHandle = driGetPixmapHandle; + dri2info.beginClipNotify = driBeginClipNotify; + dri2info.endClipNotify = driEndClipNotify; + + p = DRI2ScreenInit(pScreen, &dri2info); + if (!p) + return; + + DRILock = p; + DRILock->block_header = + DRI2_SAREA_BLOCK_HEADER(DRI2_SAREA_BLOCK_LOCK, sizeof *DRILock); + ms->lock = &DRILock->lock; + ms->context = 1; + DRILock->next_id = 2; + driLock(pScreen); + + DRI2Connect(pScreen, &ms->fd, &driverName, &sarea_handle); +} + +void +driCloseScreen(ScreenPtr pScreen) +{ + driUnlock(pScreen); + DRI2CloseScreen(pScreen); +} diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 8f1c90513..6bf6388f9 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -132,6 +132,16 @@ static const OptionInfoRec Options[] = { {-1, NULL, OPTV_NONE, {0}, FALSE} }; +static const char *exaSymbols[] = { + "exaGetVersion", + "exaDriverInit", + "exaDriverFini", + "exaOffscreenAlloc", + "exaOffscreenFree", + "exaWaitSync", + NULL +}; + static const char *fbSymbols[] = { "fbPictureInit", "fbScreenInit", @@ -190,7 +200,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin) * Tell the loader about symbols from other modules that this module * might refer to. */ - LoaderRefSymLists(fbSymbols, shadowSymbols, ddcSymbols, NULL); + LoaderRefSymLists(exaSymbols, fbSymbols, shadowSymbols, ddcSymbols, NULL); /* * The return value must be non-NULL on success even though there @@ -417,6 +427,8 @@ MapMem(ScrnInfoPtr pScrn) drmBOMap(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual); + ms->virtual = ms->bo.virtual; + return TRUE; } @@ -438,7 +450,7 @@ LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, } static Bool -crtc_resize(ScrnInfoPtr pScrn, int width, int height) +CreateFrontBuffer(ScrnInfoPtr pScrn) { modesettingPtr ms = modesettingPTR(pScrn); ScreenPtr pScreen = pScrn->pScreen; @@ -446,37 +458,14 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height) Bool fbAccessDisabled; CARD8 *fbstart; - if (width == pScrn->virtualX && height == pScrn->virtualY) - return TRUE; - - ErrorF("RESIZING TO %dx%d\n", width, height); - - pScrn->virtualX = width; - pScrn->virtualY = height; - pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; - - if (ms->shadowMem) { - xfree(ms->shadowMem); - ms->shadowMem = NULL; - } - - UnmapMem(pScrn); - - /* move old buffer out of the way */ - drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL, - DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT, - DRM_BO_HINT_DONT_FENCE, 0, 0); - - /* unreference it */ - drmBOUnreference(ms->fd, &ms->bo); - drmBOCreate(ms->fd, pScrn->virtualY * pScrn->displayWidth * pScrn->bitsPerPixel / 8, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE + | DRM_BO_FLAG_CACHED_MAPPED | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | - DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, - DRM_BO_HINT_DONT_FENCE, &ms->bo); + /*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT, + 0, &ms->bo); MapMem(pScrn); @@ -498,7 +487,7 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height) } fbstart = ms->shadowMem; } else { - fbstart = ms->virtual; + fbstart = ms->bo.virtual; } /* @@ -526,9 +515,49 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height) pScrn->frameY0 = 0; AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + UnmapMem(pScrn); + + ms->front = TRUE; + return TRUE; } +static Bool +crtc_resize(ScrnInfoPtr pScrn, int width, int height) +{ + modesettingPtr ms = modesettingPTR(pScrn); + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + Bool fbAccessDisabled; + CARD8 *fbstart; + + if (width == pScrn->virtualX && height == pScrn->virtualY) + return TRUE; + + ErrorF("RESIZING TO %dx%d\n", width, height); + + pScrn->virtualX = width; + pScrn->virtualY = height; + pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; + + if (ms->shadowMem) { + xfree(ms->shadowMem); + ms->shadowMem = NULL; + } + + drmModeRmFB(ms->fd, ms->fb_id); + + /* move old buffer out of the way */ + drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0); + + /* unreference it */ + drmBOUnreference(ms->fd, &ms->bo); + ms->front = FALSE; + + /* now create new frontbuffer */ + return CreateFrontBuffer(pScrn); +} + static const xf86CrtcConfigFuncsRec crtc_config_funcs = { crtc_resize }; @@ -713,6 +742,12 @@ PreInit(ScrnInfoPtr pScrn, int flags) xf86LoaderReqSymLists(fbSymbols, NULL); + xf86LoadSubModule(pScrn, "exa"); + +#ifdef DRI2 + xf86LoadSubModule(pScrn, "dri2"); +#endif + return TRUE; } @@ -744,7 +779,7 @@ WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode, *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8; - return ((CARD8 *) ms->virtual + row * (*size) + offset); + return ((CARD8 *) ms->bo.virtual + row * (*size) + offset); } static Bool @@ -752,15 +787,23 @@ CreateScreenResources(ScreenPtr pScreen) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); Bool ret; pScreen->CreateScreenResources = ms->createScreenResources; ret = pScreen->CreateScreenResources(pScreen); pScreen->CreateScreenResources = CreateScreenResources; - shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen), + if (ms->shadowFB) + shadowAdd(pScreen, rootPixmap, ms->update, WindowLinear, 0, 0); + if (!pScreen->ModifyPixmapHeader(pScreen->GetScreenPixmap(pScreen), + -1, -1, -1, -1, -1, + ms->shadowFB ? (pointer)ms->shadowMem : (pointer)ms->bo.virtual)) + FatalError("Couldn't adjust screen pixmap\n"); + + return ret; } @@ -775,6 +818,30 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) MessageType from; CARD8 *fbstart; + /* deal with server regeneration */ + if (ms->fd < 0) { + char *BusID; + + BusID = xalloc(64); + sprintf(BusID, "PCI:%d:%d:%d", +#if XSERVER_LIBPCIACCESS + ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), + ms->PciInfo->dev, ms->PciInfo->func +#else + ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum +#endif + ); + + ms->fd = drmOpen(NULL, BusID); + + if (ms->fd < 0) + return FALSE; + } + + pScrn->pScreen = pScreen; + pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; miClearVisualTypes(); @@ -787,9 +854,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (!miSetPixmapDepths()) return FALSE; - if (!MapMem(pScrn)) - return FALSE; - pScrn->memPhysBase = 0; pScrn->fbOffset = 0; @@ -797,9 +861,10 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) pScrn->virtualY * pScrn->displayWidth * pScrn->bitsPerPixel / 8, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE + | DRM_BO_FLAG_CACHED_MAPPED | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | - DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, - DRM_BO_HINT_DONT_FENCE, &ms->bo); + /*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT, + 0, &ms->bo); MapMem(pScrn); @@ -821,7 +886,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) } fbstart = ms->shadowMem; } else { - fbstart = ms->virtual; + fbstart = ms->bo.virtual; } if (!fbScreenInit(pScreen, fbstart, @@ -853,18 +918,18 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) "Shadow framebuffer initialization failed.\n"); return FALSE; } - - ms->createScreenResources = pScreen->CreateScreenResources; - pScreen->CreateScreenResources = CreateScreenResources; } + ms->createScreenResources = pScreen->CreateScreenResources; + pScreen->CreateScreenResources = CreateScreenResources; + xf86SetBlackWhitePixels(pScreen); #if 0 glucoseScreenInit(pScreen, 0); #endif -#if 0 - ms->pExa = ExaInit(pScreen); +#if 1 + ms->pExa = ExaInit(pScrn); #endif miInitializeBackingStore(pScreen); @@ -872,8 +937,9 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) xf86SetSilkenMouse(pScreen); miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); - /* Need to extend HWcursor support in kernel to handle mask interleave ?? */ - xf86_cursors_init (pScreen, 64, 64, + /* Need to extend HWcursor support to handle mask interleave */ + if (!ms->SWCursor) + xf86_cursors_init (pScreen, 64, 64, HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | HARDWARE_CURSOR_ARGB); @@ -908,6 +974,14 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (serverGeneration == 1) xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); +#ifdef DRI2 + driScreenInit(pScreen); +#endif + + UnmapMem(pScrn); + + ms->front = TRUE; + return EnterVT(scrnIndex, 0); } @@ -944,6 +1018,8 @@ LeaveVT(int scrnIndex, int flags) for (o = 0; o < config->num_crtc; o++) { xf86CrtcPtr crtc = config->crtc[o]; + cursor_destroy(crtc); + if (crtc->rotatedPixmap || crtc->rotatedData) { crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, crtc->rotatedData); @@ -952,11 +1028,25 @@ LeaveVT(int scrnIndex, int flags) } } - xf86_hide_cursors(pScrn); + drmModeRmFB(ms->fd, ms->fb_id); - drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0); + /* move old buffer out of the way */ + drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0); + + drmBOUnreference(ms->fd, &ms->bo); + ms->front = FALSE; RestoreHWState(pScrn); + +#if 0 + drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0); + drmMMLock(ms->fd, DRM_BO_MEM_TT, 1, 0); +#endif +#ifdef DRI2 + driLock(pScrn->pScreen); +#endif + + pScrn->vtSema = FALSE; } /* @@ -968,6 +1058,17 @@ EnterVT(int scrnIndex, int flags) ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; modesettingPtr ms = modesettingPTR(pScrn); +#if 0 + if (pScrn->vtSema) { + drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); + drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1); + } +#endif + +#ifdef DRI2 + driUnlock(pScrn->pScreen); +#endif + /* * Only save state once per server generation since that's what most * drivers do. Could change this to save state at each VT enter. @@ -977,7 +1078,8 @@ EnterVT(int scrnIndex, int flags) SaveHWState(pScrn); } - drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); + if (!ms->front) + CreateFrontBuffer(pScrn); if (!xf86SetDesiredModes(pScrn)) return FALSE; @@ -1001,15 +1103,19 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; modesettingPtr ms = modesettingPTR(pScrn); - if (pScrn->vtSema == TRUE) { - LeaveVT(scrnIndex, 0); - drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); + if (pScrn->vtSema) { + LeaveVT(scrnIndex, 0); +#if 0 + drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); + drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1); +#endif } - UnmapMem(pScrn); +#ifdef DRI2 + driCloseScreen(pScreen); +#endif - if (ms->shadowFB) - pScreen->CreateScreenResources = ms->createScreenResources; + pScreen->CreateScreenResources = ms->createScreenResources; if (ms->shadowMem) { xfree(ms->shadowMem); @@ -1019,14 +1125,8 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) if (ms->pExa) ExaClose(pScrn); - /* move old buffer out of the way */ - drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL, - DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT, - DRM_BO_HINT_DONT_FENCE, 0, 0); - - drmBOUnreference(ms->fd, &ms->bo); - drmClose(ms->fd); + ms->fd = -1; pScrn->vtSema = FALSE; pScreen->CloseScreen = ms->CloseScreen; diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index c9cb76497..7ac646665 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "shadow.h" #include "exa.h" @@ -50,6 +51,7 @@ typedef struct _modesettingRec unsigned int fb_id; void *virtual; drmBO bo; + Bool front; EntPtr entityPrivate; @@ -68,9 +70,6 @@ typedef struct _modesettingRec Bool SWCursor; CloseScreenProcPtr CloseScreen; - Bool directRenderingDisabled; /* DRI disabled in PreInit. */ - Bool directRenderingEnabled; /* DRI enabled this generation. */ - /* Broken-out options. */ OptionInfoPtr Options; @@ -85,6 +84,11 @@ typedef struct _modesettingRec /* exa */ ExaDriverPtr pExa; drmBO exa_bo; + + /* dri2 */ + drm_context_t context; + drm_hw_lock_t *lock; + int lock_held; } modesettingRec, *modesettingPtr; #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c index 70968f01f..9327cbc98 100644 --- a/hw/xfree86/drivers/modesetting/exa.c +++ b/hw/xfree86/drivers/modesetting/exa.c @@ -36,6 +36,14 @@ #include "driver.h" +struct PixmapPriv { + drmBO bo; + #if 0 + dri_fence *fence; + #endif + int flags; +}; + static void ExaWaitMarker(ScreenPtr pScreen, int marker) { @@ -44,10 +52,6 @@ ExaWaitMarker(ScreenPtr pScreen, int marker) static int ExaMarkSync(ScreenPtr pScreen) { - /* - * See ExaWaitMarker. - */ - return 1; } @@ -56,6 +60,30 @@ ExaPrepareAccess(PixmapPtr pPix, int index) { ScreenPtr pScreen = pPix->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + struct PixmapPriv *priv; + int ret; + + priv = exaGetPixmapDriverPrivate(pPix); + + if (!priv) + return FALSE; + + if (priv->bo.handle) { + void *virtual; + + ret = drmBOMap(ms->fd, + &priv->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual); + if (ret) { + driUnlock(pScreen); + FatalError("Failed to map pixmap: %s\n", strerror(-ret)); + return; + } + + pPix->devPrivate.ptr = priv->bo.virtual; + } + return TRUE; } @@ -65,6 +93,26 @@ ExaFinishAccess(PixmapPtr pPix, int index) { ScreenPtr pScreen = pPix->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + struct PixmapPriv *priv; + int ret; + + priv = exaGetPixmapDriverPrivate(pPix); + + if (!priv) + return; + + if (priv->bo.handle) { + ret = drmBOUnmap(ms->fd, &priv->bo); + if (ret) { + driUnlock(pScreen); + FatalError("Failed to unmap pixmap: %s\n", strerror(-ret)); + return; + } + + pPix->devPrivate.ptr = NULL; + } } static void @@ -84,6 +132,8 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg) { ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + ErrorF("SOLID\n"); + if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask)) return FALSE; @@ -91,7 +141,7 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg) if (pPixmap->drawable.depth == 4) return FALSE; - return TRUE; + return FALSE; } static void @@ -106,11 +156,13 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, { ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; + ErrorF("COPY\n"); + /* can't do depth 4 */ if (pSrcPixmap->drawable.depth == 4 || pDstPixmap->drawable.depth == 4) return FALSE; - return TRUE; + return FALSE; } static void @@ -138,6 +190,8 @@ ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, ScreenPtr pScreen = pDst->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + ErrorF("UPLOAD\n"); + return FALSE; } @@ -158,18 +212,118 @@ ExaCheckComposite(int op, int w = pDraw->width; int h = pDraw->height; - return TRUE; + return FALSE; } -static Bool -ExaPixmapIsOffscreen(PixmapPtr p) +static void * +ExaCreatePixmap(ScreenPtr pScreen, int size, int align) { - ScreenPtr pScreen = p->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct PixmapPriv *priv; + void *virtual; + + priv = xcalloc(1, sizeof(struct PixmapPriv)); + if (!priv) + return NULL; + + if (size == 0) + return priv; + + drmBOCreate(ms->fd, size, 4096, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE + | DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_MAPPABLE | + DRM_BO_FLAG_CACHED_MAPPED, + 0, &priv->bo); + + return priv; +} + +static void +ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv) +{ + struct PixmapPriv *priv = (struct PixmapPriv *)dPriv; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + + if (!priv) + return; + + if (priv->bo.handle) + drmBOUnreference(ms->fd, &priv->bo); + + xfree(priv); +} + +static Bool +ExaPixmapIsOffscreen(PixmapPtr pPixmap) +{ + struct PixmapPriv *priv; + ScreenPtr pScreen = pPixmap->drawable.pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + + priv = exaGetPixmapDriverPrivate(pPixmap); + + if (!priv) + return FALSE; + + if (priv->bo.handle) + return TRUE; return FALSE; } +/* FIXME !! */ +unsigned int +driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) +{ + ScreenPtr pScreen = pPixmap->drawable.pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct PixmapPriv *priv; + + *flags = 0; + + if (rootPixmap == pPixmap) + return ms->bo.handle; + + if (!ms->pExa) + return 0; + + priv = exaGetPixmapDriverPrivate(pPixmap); + + if (!priv) + return 0; + + if (priv->bo.handle) + return priv->bo.handle; + + return 0; +} + +static Bool +ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, + int depth, int bitsPerPixel, int devKind, + pointer pPixData) +{ + ScreenPtr pScreen = pPixmap->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); + modesettingPtr ms = modesettingPTR(pScrn); + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + + if (rootPixmap == pPixmap) { + miModifyPixmapHeader(pPixmap, width, height, depth, + bitsPerPixel, devKind, NULL); + + return TRUE; + } + + return FALSE; +} + + void ExaClose(ScrnInfoPtr pScrn) { @@ -177,7 +331,9 @@ ExaClose(ScrnInfoPtr pScrn) exaDriverFini(pScrn->pScreen); +#if 0 drmBOUnreference(ms->fd, &ms->exa_bo); +#endif } ExaDriverPtr @@ -191,20 +347,22 @@ ExaInit(ScrnInfoPtr pScrn) goto out_err; } +#if 0 /* Create a 256KB offscreen area */ drmBOCreate(ms->fd, 256 * 1024, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->exa_bo); +#endif memset(pExa, 0, sizeof(*pExa)); pExa->exa_major = 2; - pExa->exa_minor = 2; - pExa->memoryBase = ms->exa_bo.virtual; + pExa->exa_minor = 4; + pExa->memoryBase = 0; /* ms->exa_bo.virtual; */ + pExa->memorySize = 0; /* ms->exa_bo.size; */ pExa->offScreenBase = 0; - pExa->memorySize = ms->exa_bo.size; pExa->pixmapOffsetAlign = 8; pExa->pixmapPitchAlign = 32 * 4; - pExa->flags = EXA_OFFSCREEN_PIXMAPS; + pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS; pExa->maxX = 8191; /* FIXME */ pExa->maxY = 8191; /* FIXME */ pExa->WaitMarker = ExaWaitMarker; @@ -223,6 +381,9 @@ ExaInit(ScrnInfoPtr pScrn) pExa->PrepareAccess = ExaPrepareAccess; pExa->FinishAccess = ExaFinishAccess; pExa->UploadToScreen = ExaUploadToScreen; + pExa->CreatePixmap = ExaCreatePixmap; + pExa->DestroyPixmap = ExaDestroyPixmap; + pExa->ModifyPixmapHeader = ExaModifyPixmapHeader; if (!exaDriverInit(pScrn->pScreen, pExa)) { goto out_err; diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c index 7767ef2c2..484acb23b 100644 --- a/hw/xfree86/drivers/modesetting/output.c +++ b/hw/xfree86/drivers/modesetting/output.c @@ -51,6 +51,23 @@ #include "driver.h" +static char *connector_enum_list[] = { + "Unknown", + "VGA", + "DVI-I", + "DVI-D", + "DVI-A", + "Composite", + "SVIDEO", + "LVDS", + "Component", + "9-pin DIN", + "DisplayPort", + "HDMI Type A", + "HDMI Type B", +}; + + static void dpms(xf86OutputPtr output, int mode) { @@ -145,6 +162,7 @@ get_modes(xf86OutputPtr output) mode->VRefresh = xf86ModeVRefresh(mode); mode->Private = (void *)drm_mode; xf86SetModeDefaultName(mode); + ErrorF("MODE %s\n",mode->name); modes = xf86ModesAdd(modes, mode); xf86PrintModeline(0, mode); } @@ -237,7 +255,6 @@ output_init(ScrnInfoPtr pScrn) if (!drm_connector) goto out; -#if 0 for (p = 0; p < drm_connector->count_props; p++) { drmModePropertyPtr prop; @@ -249,41 +266,16 @@ output_init(ScrnInfoPtr pScrn) for (v = 0; v < prop->count_values; v++) ErrorF("%s %lld\n", prop->name, prop->values[v]); - - for (v = 0; v < prop->count_enums; v++) { - ErrorF("%s %s\n", prop->name, prop->enums[v].name); - if (drm_connector->prop_values[p] == prop->enums[v].value) { - if (!strncmp("Connector Type", prop->name, 14)) { - ErrorF("WE'VE GOT %s\n", prop->enums[v].name); - name = xalloc(strlen(prop->enums[v].name)); - strncpy(name, prop->enums[v].name, strlen(name)); - } - } - if (name) - break; - } - if (name) - break; } } - if (!name) - continue; -#endif - - -#if 0 - free(name); -#endif - - - name = "Unknown"; + name = connector_enum_list[drm_connector->connector_type]; output = xf86OutputCreate(pScrn, &output_funcs, name); if (!output) continue; - drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoder); + drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]); if (drm_encoder) { output->possible_crtcs = drm_encoder->crtcs; output->possible_clones = drm_encoder->clones; From 2a45c28712a544c6f1c3eb753678ba1738cfdd67 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 26 Jun 2008 22:25:17 +0100 Subject: [PATCH 007/122] formatting fixes --- hw/xfree86/drivers/modesetting/crtc.c | 43 +++++++++++++++------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c index 89ffe92e6..d4f449bb4 100644 --- a/hw/xfree86/drivers/modesetting/crtc.c +++ b/hw/xfree86/drivers/modesetting/crtc.c @@ -47,7 +47,8 @@ #define DPMS_SERVER #include -struct crtc_private { +struct crtc_private +{ drmModeCrtcPtr drm_crtc; /* hwcursor */ @@ -122,6 +123,8 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, drm_mode.hskew = mode->HSkew; drm_mode.vscan = mode->VScan; drm_mode.vrefresh = mode->VRefresh; + if (!mode->name) + xf86SetModeDefaultName(mode); strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN); drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y, @@ -176,29 +179,30 @@ crtc_destroy(xf86CrtcPtr crtc) } static void -crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) +crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image) { unsigned char *ptr; modesettingPtr ms = modesettingPTR(crtc->scrn); struct crtc_private *crtcp = crtc->driver_private; if (!crtcp->cursor_bo.handle) - drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE - | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | - DRM_BO_FLAG_MEM_VRAM, - DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo); + drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE + | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | + DRM_BO_FLAG_MEM_VRAM, + DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo); - drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, DRM_BO_HINT_DONT_FENCE, (void **)&ptr); + drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, + DRM_BO_HINT_DONT_FENCE, (void **)&ptr); if (ptr) - memcpy (ptr, image, 64 * 64 * 4); + memcpy(ptr, image, 64 * 64 * 4); drmBOUnmap(ms->fd, &crtcp->cursor_bo); } static void -crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y) +crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y) { modesettingPtr ms = modesettingPTR(crtc->scrn); struct crtc_private *crtcp = crtc->driver_private; @@ -207,17 +211,18 @@ crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y) } static void -crtc_show_cursor (xf86CrtcPtr crtc) +crtc_show_cursor(xf86CrtcPtr crtc) { modesettingPtr ms = modesettingPTR(crtc->scrn); struct crtc_private *crtcp = crtc->driver_private; if (crtcp->cursor_bo.handle) - drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64); + drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, + crtcp->cursor_bo.handle, 64, 64); } static void -crtc_hide_cursor (xf86CrtcPtr crtc) +crtc_hide_cursor(xf86CrtcPtr crtc) { modesettingPtr ms = modesettingPTR(crtc->scrn); struct crtc_private *crtcp = crtc->driver_private; @@ -242,8 +247,8 @@ static const xf86CrtcFuncsRec crtc_funcs = { .set_cursor_position = crtc_set_cursor_position, .show_cursor = crtc_show_cursor, .hide_cursor = crtc_hide_cursor, - .load_cursor_image = NULL, /* lets convert to argb only */ - .set_cursor_colors = NULL, /* using argb only */ + .load_cursor_image = NULL, /* lets convert to argb only */ + .set_cursor_colors = NULL, /* using argb only */ .load_cursor_argb = crtc_load_cursor_argb, .destroy = crtc_destroy, }; @@ -255,8 +260,8 @@ cursor_destroy(xf86CrtcPtr crtc) struct crtc_private *crtcp = crtc->driver_private; if (crtcp->cursor_bo.handle) { - drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0); - drmBOUnreference(ms->fd, &crtcp->cursor_bo); + drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0); + drmBOUnreference(ms->fd, &crtcp->cursor_bo); } } @@ -291,10 +296,10 @@ crtc_init(ScrnInfoPtr pScrn) goto out; } - crtcp->drm_crtc = drm_crtc; + crtcp->drm_crtc = drm_crtc; crtc->driver_private = crtcp; - + } out: From 2b3a3bc9202f4e6f9886a08a4dfa597a83a5e933 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 26 Jun 2008 22:26:16 +0100 Subject: [PATCH 008/122] more formatting fixes --- hw/xfree86/drivers/modesetting/dri2.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c index eec80696b..7fd9fcae3 100644 --- a/hw/xfree86/drivers/modesetting/dri2.c +++ b/hw/xfree86/drivers/modesetting/dri2.c @@ -76,7 +76,8 @@ driEndClipNotify(ScreenPtr pScreen) driUnlock(pScreen); } -struct __DRILock { +struct __DRILock +{ unsigned int block_header; drm_hw_lock_t lock; unsigned int next_id; @@ -99,13 +100,13 @@ driScreenInit(ScreenPtr pScreen) dri2info.version = 1; dri2info.fd = ms->fd; dri2info.driverSareaSize = sizeof(struct __DRILock); - dri2info.driverName = "i915"; /* FIXME */ + dri2info.driverName = "i915"; /* FIXME */ dri2info.getPixmapHandle = driGetPixmapHandle; dri2info.beginClipNotify = driBeginClipNotify; - dri2info.endClipNotify = driEndClipNotify; + dri2info.endClipNotify = driEndClipNotify; p = DRI2ScreenInit(pScreen, &dri2info); - if (!p) + if (!p) return; DRILock = p; From 0e1aa03708d95cc1542bee31709a345d0f748f0c Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 26 Jun 2008 22:27:14 +0100 Subject: [PATCH 009/122] yet more --- hw/xfree86/drivers/modesetting/output.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c index 484acb23b..1f95a2f1c 100644 --- a/hw/xfree86/drivers/modesetting/output.c +++ b/hw/xfree86/drivers/modesetting/output.c @@ -67,7 +67,6 @@ static char *connector_enum_list[] = { "HDMI Type B", }; - static void dpms(xf86OutputPtr output, int mode) { @@ -162,7 +161,6 @@ get_modes(xf86OutputPtr output) mode->VRefresh = xf86ModeVRefresh(mode); mode->Private = (void *)drm_mode; xf86SetModeDefaultName(mode); - ErrorF("MODE %s\n",mode->name); modes = xf86ModesAdd(modes, mode); xf86PrintModeline(0, mode); } @@ -277,11 +275,11 @@ output_init(ScrnInfoPtr pScrn) drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]); if (drm_encoder) { - output->possible_crtcs = drm_encoder->crtcs; - output->possible_clones = drm_encoder->clones; + output->possible_crtcs = drm_encoder->crtcs; + output->possible_clones = drm_encoder->clones; } else { - output->possible_crtcs = 0; - output->possible_clones = 0; + output->possible_crtcs = 0; + output->possible_clones = 0; } output->driver_private = drm_connector; output->subpixel_order = SubPixelHorizontalRGB; From ccd0c76472a7d8a85aed0ea6fea4011109f305d6 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 26 Jun 2008 22:27:44 +0100 Subject: [PATCH 010/122] Add EXA winsys for gallium pipe driver interface. Plug in the EXA framework into the pipe driver for surface_copy & surface_fill. Back pixmaps with drmBO's including the front buffer. --- hw/xfree86/drivers/modesetting/driver.c | 303 +++--------- hw/xfree86/drivers/modesetting/driver.h | 15 +- hw/xfree86/drivers/modesetting/exa.c | 624 ++++++++++++++++++++---- 3 files changed, 596 insertions(+), 346 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 6bf6388f9..0e6f4c889 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -40,7 +40,6 @@ #include "xf86Resources.h" #include "mipointer.h" #include "micmap.h" -#include "shadowfb.h" #include #include "fb.h" #include "edid.h" @@ -50,7 +49,6 @@ #include "dixstruct.h" #include "xf86xv.h" #include -#include "shadow.h" #include #if XSERVER_LIBPCIACCESS #include @@ -120,15 +118,11 @@ static PciChipsets PciDevices[] = { typedef enum { - OPTION_NOACCEL, OPTION_SW_CURSOR, - OPTION_SHADOWFB, } modesettingOpts; static const OptionInfoRec Options[] = { - {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE}, {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE}, {-1, NULL, OPTV_NONE, {0}, FALSE} }; @@ -154,12 +148,6 @@ static const char *ddcSymbols[] = { NULL }; -static const char *shadowSymbols[] = { - "shadowInit", - "shadowUpdatePackedWeak", - NULL -}; - static const char *i2cSymbols[] = { "xf86CreateI2CBusRec", "xf86I2CBusInit", @@ -200,7 +188,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin) * Tell the loader about symbols from other modules that this module * might refer to. */ - LoaderRefSymLists(exaSymbols, fbSymbols, shadowSymbols, ddcSymbols, NULL); + LoaderRefSymLists(exaSymbols, fbSymbols, ddcSymbols, NULL); /* * The return value must be non-NULL on success even though there @@ -323,7 +311,6 @@ Probe(DriverPtr drv, int flags) if (numUsed > 0) foundScreen = TRUE; } else { - ErrorF("NUMUSED %d\n", numUsed); for (i = 0; i < numUsed; i++) { ScrnInfoPtr pScrn = NULL; @@ -419,36 +406,6 @@ ProbeDDC(ScrnInfoPtr pScrn, int index) ConfiguredMonitor = NULL; } -static Bool -MapMem(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - - drmBOMap(ms->fd, - &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual); - - ms->virtual = ms->bo.virtual; - - return TRUE; -} - -static Bool -UnmapMem(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - - drmBOUnmap(ms->fd, &ms->bo); - - return TRUE; -} - -static void -LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, - LOCO * colors, VisualPtr pVisual) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); -} - static Bool CreateFrontBuffer(ScrnInfoPtr pScrn) { @@ -456,18 +413,15 @@ CreateFrontBuffer(ScrnInfoPtr pScrn) ScreenPtr pScreen = pScrn->pScreen; PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); Bool fbAccessDisabled; - CARD8 *fbstart; + int flags; - drmBOCreate(ms->fd, - pScrn->virtualY * pScrn->displayWidth * - pScrn->bitsPerPixel / 8, 0, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE - | DRM_BO_FLAG_CACHED_MAPPED - | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | - /*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT, - 0, &ms->bo); - - MapMem(pScrn); + ms->noEvict = TRUE; + pScreen->ModifyPixmapHeader(rootPixmap, + pScrn->virtualX, pScrn->virtualY, + pScrn->depth, pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel / 8, + NULL); + ms->noEvict = FALSE; drmModeAddFB(ms->fd, pScrn->virtualX, @@ -475,50 +429,12 @@ CreateFrontBuffer(ScrnInfoPtr pScrn) pScrn->depth, pScrn->bitsPerPixel, pScrn->displayWidth * pScrn->bitsPerPixel / 8, - ms->bo.handle, &ms->fb_id); - - if (ms->shadowFB) { - if ((ms->shadowMem = - shadowAlloc(pScrn->displayWidth, pScrn->virtualY, - pScrn->bitsPerPixel)) == NULL) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Allocation of shadow memory failed\n"); - return FALSE; - } - fbstart = ms->shadowMem; - } else { - fbstart = ms->bo.virtual; - } - - /* - * If we are in a fb disabled state, the virtual address of the root - * pixmap should always be NULL, and it will be overwritten later - * if we try to set it to something. - * - * Therefore, set it to NULL, and modify the backup copy instead. - */ - - fbAccessDisabled = (rootPixmap->devPrivate.ptr == NULL); - - pScreen->ModifyPixmapHeader(rootPixmap, - pScrn->virtualX, pScrn->virtualY, - pScrn->depth, pScrn->bitsPerPixel, - pScrn->displayWidth * pScrn->bitsPerPixel / 8, - fbstart); - - if (fbAccessDisabled) { - pScrn->pixmapPrivate.ptr = fbstart; - rootPixmap->devPrivate.ptr = NULL; - } + driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id); pScrn->frameX0 = 0; pScrn->frameY0 = 0; AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); - UnmapMem(pScrn); - - ms->front = TRUE; - return TRUE; } @@ -538,22 +454,12 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height) pScrn->virtualX = width; pScrn->virtualY = height; - pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; - if (ms->shadowMem) { - xfree(ms->shadowMem); - ms->shadowMem = NULL; - } + /* HW dependent - FIXME */ + pScrn->displayWidth = pScrn->virtualX; drmModeRmFB(ms->fd, ms->fb_id); - /* move old buffer out of the way */ - drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0); - - /* unreference it */ - drmBOUnreference(ms->fd, &ms->bo); - ms->front = FALSE; - /* now create new frontbuffer */ return CreateFrontBuffer(pScrn); } @@ -571,7 +477,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) rgb defaultWeight = { 0, 0, 0 }; EntityInfoPtr pEnt; EntPtr msEnt = NULL; - int flags24; char *BusID; int i; char *s; @@ -645,13 +550,12 @@ PreInit(ScrnInfoPtr pScrn, int flags) pScrn->progClock = TRUE; pScrn->rgbBits = 8; - flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32; - - if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24)) + if (!xf86SetDepthBpp + (pScrn, 0, 0, 0, + PreferConvert24to32 | SupportConvert24to32 | Support32bppFb)) return FALSE; switch (pScrn->depth) { - case 8: case 15: case 16: case 24: @@ -684,23 +588,10 @@ PreInit(ScrnInfoPtr pScrn, int flags) max_height = 8192; xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height); - if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) { - ms->noAccel = TRUE; - } - if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) { ms->SWCursor = TRUE; } - if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) { - if (!xf86LoadSubModule(pScrn, "shadow")) - return FALSE; - - xf86LoaderReqSymLists(shadowSymbols, NULL); - - ms->shadowFB = TRUE; - } - SaveHWState(pScrn); crtc_init(pScrn); @@ -767,42 +658,37 @@ RestoreHWState(ScrnInfoPtr pScrn) return TRUE; } -static void * -WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode, - CARD32 * size, void *closure) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - - if (!pScrn->vtSema) - return NULL; - - *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8; - - return ((CARD8 *) ms->bo.virtual + row * (*size) + offset); -} - static Bool CreateScreenResources(ScreenPtr pScreen) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + PixmapPtr rootPixmap; Bool ret; + int flags; + + ms->noEvict = TRUE; pScreen->CreateScreenResources = ms->createScreenResources; ret = pScreen->CreateScreenResources(pScreen); pScreen->CreateScreenResources = CreateScreenResources; - if (ms->shadowFB) - shadowAdd(pScreen, rootPixmap, - ms->update, WindowLinear, 0, 0); + rootPixmap = pScreen->GetScreenPixmap(pScreen); - if (!pScreen->ModifyPixmapHeader(pScreen->GetScreenPixmap(pScreen), - -1, -1, -1, -1, -1, - ms->shadowFB ? (pointer)ms->shadowMem : (pointer)ms->bo.virtual)) + if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL)) FatalError("Couldn't adjust screen pixmap\n"); + ms->noEvict = FALSE; + + drmModeAddFB(ms->fd, + pScrn->virtualX, + pScrn->virtualY, + pScrn->depth, + pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel / 8, + driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id); + + AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); return ret; } @@ -816,33 +702,33 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) unsigned long sys_mem; int c; MessageType from; - CARD8 *fbstart; /* deal with server regeneration */ if (ms->fd < 0) { - char *BusID; + char *BusID; - BusID = xalloc(64); - sprintf(BusID, "PCI:%d:%d:%d", + BusID = xalloc(64); + sprintf(BusID, "PCI:%d:%d:%d", #if XSERVER_LIBPCIACCESS - ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), - ms->PciInfo->dev, ms->PciInfo->func + ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), + ms->PciInfo->dev, ms->PciInfo->func #else - ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum + ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum #endif - ); + ); - ms->fd = drmOpen(NULL, BusID); + ms->fd = drmOpen(NULL, BusID); - if (ms->fd < 0) + if (ms->fd < 0) return FALSE; } pScrn->pScreen = pScreen; - pScrn->displayWidth = (pScrn->virtualX + 63) & ~63; + /* HW dependent - FIXME */ + pScrn->displayWidth = pScrn->virtualX; miClearVisualTypes(); @@ -857,39 +743,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) pScrn->memPhysBase = 0; pScrn->fbOffset = 0; - drmBOCreate(ms->fd, - pScrn->virtualY * pScrn->displayWidth * - pScrn->bitsPerPixel / 8, 0, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE - | DRM_BO_FLAG_CACHED_MAPPED - | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | - /*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT, - 0, &ms->bo); - - MapMem(pScrn); - - drmModeAddFB(ms->fd, - pScrn->virtualX, - pScrn->virtualY, - pScrn->depth, - pScrn->bitsPerPixel, - pScrn->displayWidth * pScrn->bitsPerPixel / 8, - ms->bo.handle, &ms->fb_id); - - if (ms->shadowFB) { - if ((ms->shadowMem = - shadowAlloc(pScrn->displayWidth, pScrn->virtualY, - pScrn->bitsPerPixel)) == NULL) { - xf86DrvMsg(scrnIndex, X_ERROR, - "Allocation of shadow memory failed\n"); - return FALSE; - } - fbstart = ms->shadowMem; - } else { - fbstart = ms->bo.virtual; - } - - if (!fbScreenInit(pScreen, fbstart, + if (!fbScreenInit(pScreen, NULL, pScrn->virtualX, pScrn->virtualY, pScrn->xDpi, pScrn->yDpi, pScrn->displayWidth, pScrn->bitsPerPixel)) @@ -911,26 +765,13 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) } fbPictureInit(pScreen, NULL, 0); - if (ms->shadowFB) { - ms->update = shadowUpdatePackedWeak(); - if (!shadowSetup(pScreen)) { - xf86DrvMsg(scrnIndex, X_ERROR, - "Shadow framebuffer initialization failed.\n"); - return FALSE; - } - } ms->createScreenResources = pScreen->CreateScreenResources; pScreen->CreateScreenResources = CreateScreenResources; xf86SetBlackWhitePixels(pScreen); -#if 0 - glucoseScreenInit(pScreen, 0); -#endif -#if 1 - ms->pExa = ExaInit(pScrn); -#endif + ms->exa = ExaInit(pScrn); miInitializeBackingStore(pScreen); xf86SetBackingStore(pScreen); @@ -939,9 +780,9 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) /* Need to extend HWcursor support to handle mask interleave */ if (!ms->SWCursor) - xf86_cursors_init (pScreen, 64, 64, - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | - HARDWARE_CURSOR_ARGB); + xf86_cursors_init(pScreen, 64, 64, + HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | + HARDWARE_CURSOR_ARGB); /* Must force it before EnterVT, so we are in control of VT and * later memory should be bound when allocating, e.g rotate_mem */ @@ -957,20 +798,8 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (!miCreateDefColormap(pScreen)) return FALSE; -#if 0 - if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL, - CMAP_RELOAD_ON_MODE_SWITCH | - CMAP_PALETTED_TRUECOLOR)) { - return FALSE; - } -#endif - xf86DPMSInit(pScreen, xf86DPMSSet, 0); -#if 0 - glucoseInitVideo(pScreen); -#endif - if (serverGeneration == 1) xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); @@ -978,11 +807,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) driScreenInit(pScreen); #endif - UnmapMem(pScrn); - - ms->front = TRUE; - - return EnterVT(scrnIndex, 0); + return EnterVT(scrnIndex, 1); } static void @@ -1018,7 +843,7 @@ LeaveVT(int scrnIndex, int flags) for (o = 0; o < config->num_crtc; o++) { xf86CrtcPtr crtc = config->crtc[o]; - cursor_destroy(crtc); + cursor_destroy(crtc); if (crtc->rotatedPixmap || crtc->rotatedData) { crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, @@ -1030,12 +855,6 @@ LeaveVT(int scrnIndex, int flags) drmModeRmFB(ms->fd, ms->fb_id); - /* move old buffer out of the way */ - drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0); - - drmBOUnreference(ms->fd, &ms->bo); - ms->front = FALSE; - RestoreHWState(pScrn); #if 0 @@ -1078,14 +897,12 @@ EnterVT(int scrnIndex, int flags) SaveHWState(pScrn); } - if (!ms->front) + if (!flags) /* signals startup as we'll do this in CreateScreenResources */ CreateFrontBuffer(pScrn); if (!xf86SetDesiredModes(pScrn)) return FALSE; - AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); - return TRUE; } @@ -1104,25 +921,19 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) modesettingPtr ms = modesettingPTR(pScrn); if (pScrn->vtSema) { - LeaveVT(scrnIndex, 0); + LeaveVT(scrnIndex, 0); #if 0 - drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); - drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1); + drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); + drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1); #endif } - #ifdef DRI2 driCloseScreen(pScreen); #endif pScreen->CreateScreenResources = ms->createScreenResources; - if (ms->shadowMem) { - xfree(ms->shadowMem); - ms->shadowMem = NULL; - } - - if (ms->pExa) + if (ms->exa) ExaClose(pScrn); drmClose(ms->fd); diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index 7ac646665..5b3118832 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -32,7 +32,6 @@ #include #include #include -#include "shadow.h" #include "exa.h" #define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg); @@ -49,14 +48,9 @@ typedef struct _modesettingRec { int fd; unsigned int fb_id; - void *virtual; - drmBO bo; - Bool front; EntPtr entityPrivate; - void (*PointerMoved) (int, int, int); - int Chipset; EntityInfoPtr pEnt; #if XSERVER_LIBPCIACCESS @@ -75,15 +69,12 @@ typedef struct _modesettingRec unsigned int SaveGeneration; - /* shadowfb */ - CARD8 *shadowMem; - Bool shadowFB; CreateScreenResourcesProcPtr createScreenResources; - ShadowUpdateProc update; /* exa */ - ExaDriverPtr pExa; - drmBO exa_bo; + void *exa; + void *driver; + Bool noEvict; /* dri2 */ drm_context_t context; diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c index 9327cbc98..124dc03bc 100644 --- a/hw/xfree86/drivers/modesetting/exa.c +++ b/hw/xfree86/drivers/modesetting/exa.c @@ -31,19 +31,329 @@ #include "config.h" #endif +/* FIXME ! */ +#define DRI_DRIVER_PATH "/ISO/X.Org/modular/i386/lib/dri" + #include "xf86.h" #include "xf86_OSproc.h" - #include "driver.h" +#include -struct PixmapPriv { - drmBO bo; - #if 0 - dri_fence *fence; - #endif - int flags; +#include "pipe/p_winsys.h" +#include "pipe/p_format.h" +#include "pipe/p_context.h" +#include "pipe/p_util.h" +#include "pipe/p_state.h" +#include "pipe/p_inlines.h" + +/* EXA winsys */ +struct exa_context +{ }; +struct exa_winsys +{ + struct pipe_winsys base; + modesettingPtr ms; +}; + +struct exa_buffer +{ + struct pipe_buffer base; + drmBO bo; + boolean userBuffer; /** Is this a user-space buffer? */ + //void *data; + //void *mapped; +}; + +struct exa_surface +{ + struct pipe_surface surface; +}; + +struct exa_entity +{ + ExaDriverPtr pExa; + struct exa_context *c; + struct pipe_winsys *ws; + struct pipe_context *ctx; + struct pipe_screen *scrn; +}; + +static INLINE struct exa_winsys * +exa_get_winsys(struct pipe_winsys *ws) +{ + return (struct exa_winsys *)ws; +} + +static INLINE struct exa_surface * +exa_get_surface(struct pipe_surface *ps) +{ + return (struct exa_surface *)ps; +} + +static INLINE struct exa_buffer * +exa_get_buffer(struct pipe_buffer *buf) +{ + return (struct exa_buffer *)buf; +} + +static void * +exa_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf, + unsigned flags) +{ + struct exa_buffer *exa_buf = exa_get_buffer(buf); + struct exa_winsys *exa_winsys = exa_get_winsys(pws); + void *virtual; + + drmBOMap(exa_winsys->ms->fd, + &exa_buf->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual); + + return virtual; +} + +static void +exa_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf) +{ + struct exa_buffer *exa_buf = exa_get_buffer(buf); + struct exa_winsys *exa_winsys = exa_get_winsys(pws); + + drmBOUnmap(exa_winsys->ms->fd, &exa_buf->bo); +} + +static void +exa_buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buf) +{ + struct exa_winsys *exa_winsys = exa_get_winsys(pws); + struct exa_buffer *exa_buf = exa_get_buffer(buf); + + drmBOUnreference(exa_winsys->ms->fd, &exa_buf->bo); + + free(exa_buf); +} + +static void +exa_flush_frontbuffer(struct pipe_winsys *pws, + struct pipe_surface *surf, void *context_private) +{ + struct exa_buffer *exa_buf = exa_get_buffer(surf->buffer); + + ErrorF("WANT TO FLUSH\n"); +} + +static const char * +exa_get_name(struct pipe_winsys *pws) +{ + return "EXA"; +} + +static struct pipe_buffer * +exa_buffer_create(struct pipe_winsys *pws, + unsigned alignment, unsigned usage, unsigned size) +{ + struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer)); + struct exa_winsys *exa_winsys = exa_get_winsys(pws); + unsigned int flags = 0; + + buffer->base.refcount = 1; + buffer->base.alignment = alignment; + buffer->base.usage = usage; + buffer->base.size = size; + + if (exa_winsys->ms->noEvict) { + flags = DRM_BO_FLAG_NO_EVICT; + ErrorF("DISPLAY TARGET\n"); + } + + ErrorF("SIZE %d %d\n", size, alignment); + if (!buffer->bo.handle) { + // buffer->data = align_malloc(size, alignment); + drmBOCreate(exa_winsys->ms->fd, size, 4096, NULL, + DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | + DRM_BO_FLAG_SHAREABLE | DRM_BO_FLAG_MEM_TT | + DRM_BO_FLAG_MAPPABLE | DRM_BO_FLAG_CACHED_MAPPED | flags, + 0, &buffer->bo); + } + + return &buffer->base; +} + +static struct pipe_buffer * +exa_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) +{ + struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer)); + + buffer->base.refcount = 1; + buffer->base.size = bytes; + buffer->userBuffer = TRUE; + //buffer->data = ptr; + ErrorF("USERBUFFER\n"); + + return &buffer->base; +} + +/** + * Round n up to next multiple. + */ +static INLINE unsigned +round_up(unsigned n, unsigned multiple) +{ + return (n + multiple - 1) & ~(multiple - 1); +} + +static int +exa_surface_alloc_storage(struct pipe_winsys *winsys, + struct pipe_surface *surf, + unsigned width, unsigned height, + enum pipe_format format, + unsigned flags, unsigned tex_usage) +{ + const unsigned alignment = 64; + + surf->width = width; + surf->height = height; + surf->format = format; + surf->cpp = pf_get_size(format); + surf->pitch = round_up(width, alignment / surf->cpp); + + assert(!surf->buffer); + surf->buffer = winsys->buffer_create(winsys, alignment, + PIPE_BUFFER_USAGE_PIXEL, + surf->pitch * surf->cpp * height); + if (!surf->buffer) + return -1; + + return 0; +} + +/** + * Called via winsys->surface_alloc() to create new surfaces. + */ +static struct pipe_surface * +exa_surface_alloc(struct pipe_winsys *ws) +{ + struct exa_surface *wms = xcalloc(1, sizeof(struct exa_surface)); + + assert(ws); + + wms->surface.refcount = 1; + wms->surface.winsys = ws; + + return &wms->surface; +} + +static void +exa_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) +{ + struct pipe_surface *surf = *s; + + surf->refcount--; + if (surf->refcount == 0) { + if (surf->buffer) + pipe_buffer_reference(winsys, &surf->buffer, NULL); + free(surf); + } + *s = NULL; +} + +/* + * Fence functions - basically nothing to do, as we don't create any actual + * fence objects. + */ +static void +exa_fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ +} + +static int +exa_fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence, + unsigned flag) +{ + return 0; +} + +static int +exa_fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence, + unsigned flag) +{ + return 0; +} + +struct pipe_winsys * +exa_get_pipe_winsys(modesettingPtr ms) +{ + static struct exa_winsys *ws = NULL; + + if (!ws) { + ws = xcalloc(1, sizeof(struct exa_winsys)); + + /* Fill in this struct with callbacks that pipe will need to + * communicate with the window system, buffer manager, etc. + */ + ws->base.buffer_create = exa_buffer_create; + ws->base.user_buffer_create = exa_user_buffer_create; + ws->base.buffer_map = exa_buffer_map; + ws->base.buffer_unmap = exa_buffer_unmap; + ws->base.buffer_destroy = exa_buffer_destroy; + + ws->base.surface_alloc = exa_surface_alloc; + ws->base.surface_alloc_storage = exa_surface_alloc_storage; + ws->base.surface_release = exa_surface_release; + + ws->base.fence_reference = exa_fence_reference; + ws->base.fence_signalled = exa_fence_signalled; + ws->base.fence_finish = exa_fence_finish; + + ws->base.flush_frontbuffer = exa_flush_frontbuffer; + ws->base.get_name = exa_get_name; + + ws->ms = ms; + } + + return &ws->base; +} + +/* EXA functions */ + +struct PixmapPriv +{ + drmBO bo; +#if 0 + dri_fence *fence; +#endif + int flags; + + struct pipe_texture *tex; + unsigned int color; + struct pipe_surface *src_surf; /* for copies */ +}; + +static enum pipe_format +exa_get_pipe_format(int depth) +{ + switch (depth) { + case 32: + case 24: + return PIPE_FORMAT_A8R8G8B8_UNORM; + case 16: + return PIPE_FORMAT_R5G6B5_UNORM; + case 15: + return PIPE_FORMAT_A1R5G5B5_UNORM; + case 8: + case 4: + case 1: + return PIPE_FORMAT_A8R8G8B8_UNORM; /* bad bad bad */ + default: + assert(0); + return 0; + } +} + +/* + * EXA functions + */ + static void ExaWaitMarker(ScreenPtr pScreen, int marker) { @@ -62,6 +372,7 @@ ExaPrepareAccess(PixmapPtr pPix, int index) ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + struct exa_entity *exa = ms->exa; struct PixmapPriv *priv; int ret; @@ -70,21 +381,20 @@ ExaPrepareAccess(PixmapPtr pPix, int index) if (!priv) return FALSE; - if (priv->bo.handle) { - void *virtual; - - ret = drmBOMap(ms->fd, - &priv->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual); - if (ret) { - driUnlock(pScreen); - FatalError("Failed to map pixmap: %s\n", strerror(-ret)); - return; - } - - pPix->devPrivate.ptr = priv->bo.virtual; + if (!priv->tex) + return FALSE; + { + struct pipe_surface *surf = + exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); + pPix->devPrivate.ptr = + exa->scrn->surface_map(exa->scrn, surf, + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); + exa->scrn->tex_surface_release(exa->scrn, &surf); } - return TRUE; } @@ -96,6 +406,7 @@ ExaFinishAccess(PixmapPtr pPix, int index) modesettingPtr ms = modesettingPTR(pScrn); PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); struct PixmapPriv *priv; + struct exa_entity *exa = ms->exa; int ret; priv = exaGetPixmapDriverPrivate(pPix); @@ -103,14 +414,15 @@ ExaFinishAccess(PixmapPtr pPix, int index) if (!priv) return; - if (priv->bo.handle) { - ret = drmBOUnmap(ms->fd, &priv->bo); - if (ret) { - driUnlock(pScreen); - FatalError("Failed to unmap pixmap: %s\n", strerror(-ret)); - return; - } - + if (!priv->tex) + return; + { + struct pipe_surface *surf = + exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); + exa->scrn->surface_unmap(exa->scrn, surf); + exa->scrn->tex_surface_release(exa->scrn, &surf); pPix->devPrivate.ptr = NULL; } } @@ -119,6 +431,16 @@ static void ExaDone(PixmapPtr pPixmap) { ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); + struct exa_entity *exa = ms->exa; + + if (!priv) + return; + + if (priv->src_surf) + exa->scrn->tex_surface_release(exa->scrn, &priv->src_surf); + priv->src_surf = NULL; } static void @@ -131,23 +453,46 @@ static Bool ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg) { ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); + struct exa_entity *exa = ms->exa; - ErrorF("SOLID\n"); + if (pPixmap->drawable.depth < 15) + return FALSE; if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask)) return FALSE; - /* can't do depth 4 */ - if (pPixmap->drawable.depth == 4) + if (!priv->tex) return FALSE; - return FALSE; + if (alu != GXcopy) + return FALSE; + + if (!exa->ctx || !exa->ctx->surface_fill) + return FALSE; + + priv->color = fg; + + return TRUE; } static void -ExaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2) +ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1) { ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_entity *exa = ms->exa; + struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); + struct pipe_surface *surf = + exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); + + exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0, + priv->color); + + exa->scrn->tex_surface_release(exa->scrn, &surf); } static Bool @@ -155,13 +500,31 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, int ydir, int alu, Pixel planeMask) { ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_entity *exa = ms->exa; + struct pipe_surface *src_surf; + struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap); - ErrorF("COPY\n"); - - /* can't do depth 4 */ - if (pSrcPixmap->drawable.depth == 4 || pDstPixmap->drawable.depth == 4) + if (alu != GXcopy) return FALSE; + if (pSrcPixmap->drawable.depth < 15 || pDstPixmap->drawable.depth < 15) + return FALSE; + + if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask)) + return FALSE; + + if (!priv->tex) + return FALSE; + + if (!exa->ctx || !exa->ctx->surface_copy) + return FALSE; + + priv->src_surf = + exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); + return FALSE; } @@ -170,6 +533,17 @@ ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY, int width, int height) { ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_entity *exa = ms->exa; + struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap); + struct pipe_surface *surf = + exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); + + exa->ctx->surface_copy(exa->ctx, 0, surf, dstX, dstY, priv->src_surf, + srcX, srcY, width, height); + exa->scrn->tex_surface_release(exa->scrn, &surf); } static Bool @@ -225,37 +599,29 @@ ExaCreatePixmap(ScreenPtr pScreen, int size, int align) priv = xcalloc(1, sizeof(struct PixmapPriv)); if (!priv) - return NULL; - - if (size == 0) - return priv; - - drmBOCreate(ms->fd, size, 4096, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE - | DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_MAPPABLE | - DRM_BO_FLAG_CACHED_MAPPED, - 0, &priv->bo); + return NULL; return priv; } -static void +static void ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv) { struct PixmapPriv *priv = (struct PixmapPriv *)dPriv; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); + struct exa_entity *exa = ms->exa; if (!priv) - return; + return; - if (priv->bo.handle) - drmBOUnreference(ms->fd, &priv->bo); + if (priv->tex) + exa->scrn->texture_release(exa->scrn, &priv->tex); xfree(priv); } -static Bool +static Bool ExaPixmapIsOffscreen(PixmapPtr pPixmap) { struct PixmapPriv *priv; @@ -265,10 +631,10 @@ ExaPixmapIsOffscreen(PixmapPtr pPixmap) priv = exaGetPixmapDriverPrivate(pPixmap); if (!priv) - return FALSE; + return FALSE; - if (priv->bo.handle) - return TRUE; + if (priv->tex) + return TRUE; return FALSE; } @@ -281,87 +647,146 @@ driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); + struct exa_entity *exa = ms->exa; + struct exa_buffer *exa_buf; + struct pipe_surface *surf; struct PixmapPriv *priv; *flags = 0; - if (rootPixmap == pPixmap) - return ms->bo.handle; - - if (!ms->pExa) - return 0; + if (!ms->exa) { + FatalError("NO MS->EXA\n"); + return 0; + } priv = exaGetPixmapDriverPrivate(pPixmap); - if (!priv) - return 0; + if (!priv) { + FatalError("NO PIXMAP PRIVATE\n"); + return 0; + } - if (priv->bo.handle) - return priv->bo.handle; + surf = + exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); + exa_buf = exa_get_buffer(surf->buffer); + exa->scrn->tex_surface_release(exa->scrn, &surf); + + if (exa_buf->bo.handle) + return exa_buf->bo.handle; return 0; } -static Bool +static Bool ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth, int bitsPerPixel, int devKind, pointer pPixData) { - ScreenPtr pScreen = pPixmap->drawable.pScreen; + ScreenPtr pScreen = pPixmap->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); modesettingPtr ms = modesettingPTR(pScrn); PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + struct exa_entity *exa = ms->exa; - if (rootPixmap == pPixmap) { + /*if (rootPixmap == pPixmap) */ { miModifyPixmapHeader(pPixmap, width, height, depth, bitsPerPixel, devKind, NULL); - - return TRUE; } - return FALSE; -} + if (!priv) + return FALSE; + if (depth <= 0) + depth = pPixmap->drawable.depth; + + if (bitsPerPixel <= 0) + bitsPerPixel = pPixmap->drawable.bitsPerPixel; + + if (width <= 0) + width = pPixmap->drawable.width; + + if (height <= 0) + height = pPixmap->drawable.height; + + if (width <= 0 || height <= 0 || depth <= 0) + return FALSE; + + /* Deal with screen resize */ + if (priv->tex) { + struct pipe_surface *surf = + exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); + + ErrorF("RESIZE %d %d to %d %d\n", surf->width, surf->height, width, + height); + if (surf->width != width || surf->height != height) { + exa->scrn->texture_release(exa->scrn, &priv->tex); + priv->tex = NULL; + } + exa->scrn->tex_surface_release(exa->scrn, &surf); + } + + if (!priv->tex) { + struct pipe_texture template; + + memset(&template, 0, sizeof(template)); + template.target = PIPE_TEXTURE_2D; + template.compressed = 0; + template.format = exa_get_pipe_format(depth); + template.cpp = pf_get_size(template.format); + template.width[0] = width; + template.height[0] = height; + template.depth[0] = 1; + template.last_level = 0; + template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + priv->tex = exa->scrn->texture_create(exa->scrn, &template); + } + + if (rootPixmap == pPixmap) + return TRUE; + + return TRUE; +} void ExaClose(ScrnInfoPtr pScrn) { modesettingPtr ms = modesettingPTR(pScrn); + struct exa_entity *exa = ms->exa; exaDriverFini(pScrn->pScreen); -#if 0 - drmBOUnreference(ms->fd, &ms->exa_bo); -#endif + dlclose(ms->driver); } -ExaDriverPtr +void * ExaInit(ScrnInfoPtr pScrn) { modesettingPtr ms = modesettingPTR(pScrn); - ExaDriverPtr pExa; + struct exa_entity *exa; + ExaDriverPtr pExa = exa->pExa; + + exa = xcalloc(1, sizeof(struct exa_entity)); + if (!exa) + return NULL; pExa = exaDriverAlloc(); if (!pExa) { goto out_err; } -#if 0 - /* Create a 256KB offscreen area */ - drmBOCreate(ms->fd, 256 * 1024, 0, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT, - DRM_BO_HINT_DONT_FENCE, &ms->exa_bo); -#endif - memset(pExa, 0, sizeof(*pExa)); pExa->exa_major = 2; pExa->exa_minor = 4; - pExa->memoryBase = 0; /* ms->exa_bo.virtual; */ - pExa->memorySize = 0; /* ms->exa_bo.size; */ + pExa->memoryBase = 0; + pExa->memorySize = 0; pExa->offScreenBase = 0; - pExa->pixmapOffsetAlign = 8; - pExa->pixmapPitchAlign = 32 * 4; + pExa->pixmapOffsetAlign = 0; + pExa->pixmapPitchAlign = 1; pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS; pExa->maxX = 8191; /* FIXME */ pExa->maxY = 8191; /* FIXME */ @@ -389,7 +814,30 @@ ExaInit(ScrnInfoPtr pScrn) goto out_err; } - return pExa; + { + char filename[128]; + char dri_driver_path[] = DRI_DRIVER_PATH; + + snprintf(filename, sizeof filename, + "%s/%s_dri.so", dri_driver_path, "i915"); + + ms->driver = dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL); + + exa->c = xcalloc(1, sizeof(struct exa_context)); + + exa->ws = exa_get_pipe_winsys(ms); + + exa->scrn = softpipe_create_screen(exa->ws); + + exa->ctx = softpipe_create(exa->scrn, exa->ws, NULL); + + if (!exa->ctx) + ErrorF("BAD CTX\n"); + + exa->ctx->priv = exa->c; + } + + return (void *)exa; out_err: ExaClose(pScrn); From 621fa337fb53d535f53cec30bb7161801001bb7f Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 26 Jun 2008 22:47:20 +0100 Subject: [PATCH 011/122] Fix copy surface --- hw/xfree86/drivers/modesetting/exa.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c index 124dc03bc..cab68709f 100644 --- a/hw/xfree86/drivers/modesetting/exa.c +++ b/hw/xfree86/drivers/modesetting/exa.c @@ -504,6 +504,7 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, struct exa_entity *exa = ms->exa; struct pipe_surface *src_surf; struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap); + struct PixmapPriv *src_priv = exaGetPixmapDriverPrivate(pSrcPixmap); if (alu != GXcopy) return FALSE; @@ -514,14 +515,14 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask)) return FALSE; - if (!priv->tex) + if (!priv->tex || !src_priv->tex) return FALSE; if (!exa->ctx || !exa->ctx->surface_copy) return FALSE; priv->src_surf = - exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, + exa->scrn->get_tex_surface(exa->scrn, src_priv->tex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE); @@ -691,7 +692,7 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); struct exa_entity *exa = ms->exa; - /*if (rootPixmap == pPixmap) */ { + if (rootPixmap == pPixmap) { miModifyPixmapHeader(pPixmap, width, height, depth, bitsPerPixel, devKind, NULL); } From 410b0a4254ca48548b443c1e8fbbcf7a6b9aa862 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 26 Jun 2008 22:49:33 +0100 Subject: [PATCH 012/122] NULL checks --- hw/xfree86/drivers/modesetting/exa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c index cab68709f..a804febd6 100644 --- a/hw/xfree86/drivers/modesetting/exa.c +++ b/hw/xfree86/drivers/modesetting/exa.c @@ -463,7 +463,7 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg) if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask)) return FALSE; - if (!priv->tex) + if (!priv || !priv->tex) return FALSE; if (alu != GXcopy) @@ -515,6 +515,9 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask)) return FALSE; + if (!priv || !src_priv) + return FALSE; + if (!priv->tex || !src_priv->tex) return FALSE; From 387ec961f2a5e791fd010906a5115cf8393471f3 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 26 Jun 2008 23:34:51 +0100 Subject: [PATCH 013/122] add --with-gallium-dir to specify location of gallium tree --- hw/xfree86/drivers/modesetting/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am index a182d4423..e3cc3cce7 100644 --- a/hw/xfree86/drivers/modesetting/Makefile.am +++ b/hw/xfree86/drivers/modesetting/Makefile.am @@ -26,7 +26,8 @@ SUBDIRS = # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. AM_CFLAGS = @WARN_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLAGS@ \ - @XMODES_CFLAGS@ + -I@GALLIUM_DIR@/src/gallium/include \ + -I@GALLIUM_DIR@/src/gallium/auxiliary modesetting_drv_la_LTLIBRARIES = modesetting_drv.la modesetting_drv_la_LDFLAGS = -module -avoid-version -ldrm From e0c43fff3208350995c45604624dd4825f40598c Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Fri, 27 Jun 2008 09:46:24 +0100 Subject: [PATCH 014/122] More error checking --- hw/xfree86/drivers/modesetting/exa.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c index a804febd6..5cf1d9615 100644 --- a/hw/xfree86/drivers/modesetting/exa.c +++ b/hw/xfree86/drivers/modesetting/exa.c @@ -695,11 +695,6 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); struct exa_entity *exa = ms->exa; - if (rootPixmap == pPixmap) { - miModifyPixmapHeader(pPixmap, width, height, depth, - bitsPerPixel, devKind, NULL); - } - if (!priv) return FALSE; @@ -718,6 +713,9 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, if (width <= 0 || height <= 0 || depth <= 0) return FALSE; + miModifyPixmapHeader(pPixmap, width, height, depth, + bitsPerPixel, devKind, NULL); + /* Deal with screen resize */ if (priv->tex) { struct pipe_surface *surf = @@ -750,9 +748,6 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, priv->tex = exa->scrn->texture_create(exa->scrn, &template); } - if (rootPixmap == pPixmap) - return TRUE; - return TRUE; } @@ -826,17 +821,22 @@ ExaInit(ScrnInfoPtr pScrn) "%s/%s_dri.so", dri_driver_path, "i915"); ms->driver = dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL); + if (!ms->driver) + FatalError("failed to initialize i915 - for softpipe only.\n"); exa->c = xcalloc(1, sizeof(struct exa_context)); exa->ws = exa_get_pipe_winsys(ms); + if (!exa->ws) + FatalError("BAD WINSYS\n"); exa->scrn = softpipe_create_screen(exa->ws); + if (!exa->scrn) + FatalError("BAD SCREEN\n"); exa->ctx = softpipe_create(exa->scrn, exa->ws, NULL); - if (!exa->ctx) - ErrorF("BAD CTX\n"); + FatalError("BAD CTX\n"); exa->ctx->priv = exa->c; } From a65888d6785934a669ad3b822bf2d636db351858 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Fri, 27 Jun 2008 17:32:28 +0100 Subject: [PATCH 015/122] fixes for gallium stride changes --- hw/xfree86/drivers/modesetting/exa.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c index 5cf1d9615..836811477 100644 --- a/hw/xfree86/drivers/modesetting/exa.c +++ b/hw/xfree86/drivers/modesetting/exa.c @@ -213,13 +213,13 @@ exa_surface_alloc_storage(struct pipe_winsys *winsys, surf->width = width; surf->height = height; surf->format = format; - surf->cpp = pf_get_size(format); - surf->pitch = round_up(width, alignment / surf->cpp); + pf_get_block(format, &surf->block); + surf->stride = round_up(surf->nblocksx * surf->block.size, alignment); assert(!surf->buffer); surf->buffer = winsys->buffer_create(winsys, alignment, PIPE_BUFFER_USAGE_PIXEL, - surf->pitch * surf->cpp * height); + surf->stride * height); if (!surf->buffer) return -1; @@ -739,7 +739,7 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, template.target = PIPE_TEXTURE_2D; template.compressed = 0; template.format = exa_get_pipe_format(depth); - template.cpp = pf_get_size(template.format); + pf_get_block(template.format, &template.block); template.width[0] = width; template.height[0] = height; template.depth[0] = 1; From 9c4c323d50bd8b369e82a1dff28abdc15a219a5e Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Mon, 30 Jun 2008 18:59:13 +0100 Subject: [PATCH 016/122] Avoid an EXA init segfault. Don't allocate each VRAM buffer with a 16MB alignment. --- hw/xfree86/drivers/modesetting/exa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c index 836811477..f688472e0 100644 --- a/hw/xfree86/drivers/modesetting/exa.c +++ b/hw/xfree86/drivers/modesetting/exa.c @@ -168,10 +168,10 @@ exa_buffer_create(struct pipe_winsys *pws, ErrorF("SIZE %d %d\n", size, alignment); if (!buffer->bo.handle) { // buffer->data = align_malloc(size, alignment); - drmBOCreate(exa_winsys->ms->fd, size, 4096, NULL, + drmBOCreate(exa_winsys->ms->fd, size, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE | DRM_BO_FLAG_MEM_TT | - DRM_BO_FLAG_MAPPABLE | DRM_BO_FLAG_CACHED_MAPPED | flags, + DRM_BO_FLAG_MAPPABLE | flags, 0, &buffer->bo); } @@ -767,7 +767,7 @@ ExaInit(ScrnInfoPtr pScrn) { modesettingPtr ms = modesettingPTR(pScrn); struct exa_entity *exa; - ExaDriverPtr pExa = exa->pExa; + ExaDriverPtr pExa; exa = xcalloc(1, sizeof(struct exa_entity)); if (!exa) From e2f8315daefc6e56ac8395a9f58f87bbf0809039 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 10 Mar 2011 09:13:50 +1000 Subject: [PATCH 018/122] drop exa don't provide accel in this framework --- hw/xfree86/drivers/modesetting/Makefile.am | 1 - hw/xfree86/drivers/modesetting/driver.c | 26 +- hw/xfree86/drivers/modesetting/driver.h | 4 - hw/xfree86/drivers/modesetting/exa.c | 850 --------------------- 4 files changed, 1 insertion(+), 880 deletions(-) delete mode 100644 hw/xfree86/drivers/modesetting/exa.c diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am index e3cc3cce7..23e78b753 100644 --- a/hw/xfree86/drivers/modesetting/Makefile.am +++ b/hw/xfree86/drivers/modesetting/Makefile.am @@ -38,7 +38,6 @@ modesetting_drv_la_SOURCES = \ driver.h \ output.c \ crtc.c \ - exa.c \ dri2.c EXTRA_DIST = diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 0e6f4c889..6b70d4b09 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -126,16 +126,6 @@ static const OptionInfoRec Options[] = { {-1, NULL, OPTV_NONE, {0}, FALSE} }; -static const char *exaSymbols[] = { - "exaGetVersion", - "exaDriverInit", - "exaDriverFini", - "exaOffscreenAlloc", - "exaOffscreenFree", - "exaWaitSync", - NULL -}; - static const char *fbSymbols[] = { "fbPictureInit", "fbScreenInit", @@ -188,7 +178,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin) * Tell the loader about symbols from other modules that this module * might refer to. */ - LoaderRefSymLists(exaSymbols, fbSymbols, ddcSymbols, NULL); + LoaderRefSymLists(fbSymbols, ddcSymbols, NULL); /* * The return value must be non-NULL on success even though there @@ -415,14 +405,11 @@ CreateFrontBuffer(ScrnInfoPtr pScrn) Bool fbAccessDisabled; int flags; - ms->noEvict = TRUE; pScreen->ModifyPixmapHeader(rootPixmap, pScrn->virtualX, pScrn->virtualY, pScrn->depth, pScrn->bitsPerPixel, pScrn->displayWidth * pScrn->bitsPerPixel / 8, NULL); - ms->noEvict = FALSE; - drmModeAddFB(ms->fd, pScrn->virtualX, pScrn->virtualY, @@ -633,8 +620,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) xf86LoaderReqSymLists(fbSymbols, NULL); - xf86LoadSubModule(pScrn, "exa"); - #ifdef DRI2 xf86LoadSubModule(pScrn, "dri2"); #endif @@ -667,8 +652,6 @@ CreateScreenResources(ScreenPtr pScreen) Bool ret; int flags; - ms->noEvict = TRUE; - pScreen->CreateScreenResources = ms->createScreenResources; ret = pScreen->CreateScreenResources(pScreen); pScreen->CreateScreenResources = CreateScreenResources; @@ -678,8 +661,6 @@ CreateScreenResources(ScreenPtr pScreen) if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL)) FatalError("Couldn't adjust screen pixmap\n"); - ms->noEvict = FALSE; - drmModeAddFB(ms->fd, pScrn->virtualX, pScrn->virtualY, @@ -771,8 +752,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) xf86SetBlackWhitePixels(pScreen); - ms->exa = ExaInit(pScrn); - miInitializeBackingStore(pScreen); xf86SetBackingStore(pScreen); xf86SetSilkenMouse(pScreen); @@ -933,9 +912,6 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) pScreen->CreateScreenResources = ms->createScreenResources; - if (ms->exa) - ExaClose(pScrn); - drmClose(ms->fd); ms->fd = -1; diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index 5b3118832..a673f8fd9 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -32,7 +32,6 @@ #include #include #include -#include "exa.h" #define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg); @@ -71,10 +70,7 @@ typedef struct _modesettingRec CreateScreenResourcesProcPtr createScreenResources; - /* exa */ - void *exa; void *driver; - Bool noEvict; /* dri2 */ drm_context_t context; diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c deleted file mode 100644 index f688472e0..000000000 --- a/hw/xfree86/drivers/modesetting/exa.c +++ /dev/null @@ -1,850 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -/* FIXME ! */ -#define DRI_DRIVER_PATH "/ISO/X.Org/modular/i386/lib/dri" - -#include "xf86.h" -#include "xf86_OSproc.h" -#include "driver.h" -#include - -#include "pipe/p_winsys.h" -#include "pipe/p_format.h" -#include "pipe/p_context.h" -#include "pipe/p_util.h" -#include "pipe/p_state.h" -#include "pipe/p_inlines.h" - -/* EXA winsys */ -struct exa_context -{ -}; - -struct exa_winsys -{ - struct pipe_winsys base; - modesettingPtr ms; -}; - -struct exa_buffer -{ - struct pipe_buffer base; - drmBO bo; - boolean userBuffer; /** Is this a user-space buffer? */ - //void *data; - //void *mapped; -}; - -struct exa_surface -{ - struct pipe_surface surface; -}; - -struct exa_entity -{ - ExaDriverPtr pExa; - struct exa_context *c; - struct pipe_winsys *ws; - struct pipe_context *ctx; - struct pipe_screen *scrn; -}; - -static INLINE struct exa_winsys * -exa_get_winsys(struct pipe_winsys *ws) -{ - return (struct exa_winsys *)ws; -} - -static INLINE struct exa_surface * -exa_get_surface(struct pipe_surface *ps) -{ - return (struct exa_surface *)ps; -} - -static INLINE struct exa_buffer * -exa_get_buffer(struct pipe_buffer *buf) -{ - return (struct exa_buffer *)buf; -} - -static void * -exa_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf, - unsigned flags) -{ - struct exa_buffer *exa_buf = exa_get_buffer(buf); - struct exa_winsys *exa_winsys = exa_get_winsys(pws); - void *virtual; - - drmBOMap(exa_winsys->ms->fd, - &exa_buf->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual); - - return virtual; -} - -static void -exa_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf) -{ - struct exa_buffer *exa_buf = exa_get_buffer(buf); - struct exa_winsys *exa_winsys = exa_get_winsys(pws); - - drmBOUnmap(exa_winsys->ms->fd, &exa_buf->bo); -} - -static void -exa_buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buf) -{ - struct exa_winsys *exa_winsys = exa_get_winsys(pws); - struct exa_buffer *exa_buf = exa_get_buffer(buf); - - drmBOUnreference(exa_winsys->ms->fd, &exa_buf->bo); - - free(exa_buf); -} - -static void -exa_flush_frontbuffer(struct pipe_winsys *pws, - struct pipe_surface *surf, void *context_private) -{ - struct exa_buffer *exa_buf = exa_get_buffer(surf->buffer); - - ErrorF("WANT TO FLUSH\n"); -} - -static const char * -exa_get_name(struct pipe_winsys *pws) -{ - return "EXA"; -} - -static struct pipe_buffer * -exa_buffer_create(struct pipe_winsys *pws, - unsigned alignment, unsigned usage, unsigned size) -{ - struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer)); - struct exa_winsys *exa_winsys = exa_get_winsys(pws); - unsigned int flags = 0; - - buffer->base.refcount = 1; - buffer->base.alignment = alignment; - buffer->base.usage = usage; - buffer->base.size = size; - - if (exa_winsys->ms->noEvict) { - flags = DRM_BO_FLAG_NO_EVICT; - ErrorF("DISPLAY TARGET\n"); - } - - ErrorF("SIZE %d %d\n", size, alignment); - if (!buffer->bo.handle) { - // buffer->data = align_malloc(size, alignment); - drmBOCreate(exa_winsys->ms->fd, size, 0, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | - DRM_BO_FLAG_SHAREABLE | DRM_BO_FLAG_MEM_TT | - DRM_BO_FLAG_MAPPABLE | flags, - 0, &buffer->bo); - } - - return &buffer->base; -} - -static struct pipe_buffer * -exa_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) -{ - struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer)); - - buffer->base.refcount = 1; - buffer->base.size = bytes; - buffer->userBuffer = TRUE; - //buffer->data = ptr; - ErrorF("USERBUFFER\n"); - - return &buffer->base; -} - -/** - * Round n up to next multiple. - */ -static INLINE unsigned -round_up(unsigned n, unsigned multiple) -{ - return (n + multiple - 1) & ~(multiple - 1); -} - -static int -exa_surface_alloc_storage(struct pipe_winsys *winsys, - struct pipe_surface *surf, - unsigned width, unsigned height, - enum pipe_format format, - unsigned flags, unsigned tex_usage) -{ - const unsigned alignment = 64; - - surf->width = width; - surf->height = height; - surf->format = format; - pf_get_block(format, &surf->block); - surf->stride = round_up(surf->nblocksx * surf->block.size, alignment); - - assert(!surf->buffer); - surf->buffer = winsys->buffer_create(winsys, alignment, - PIPE_BUFFER_USAGE_PIXEL, - surf->stride * height); - if (!surf->buffer) - return -1; - - return 0; -} - -/** - * Called via winsys->surface_alloc() to create new surfaces. - */ -static struct pipe_surface * -exa_surface_alloc(struct pipe_winsys *ws) -{ - struct exa_surface *wms = xcalloc(1, sizeof(struct exa_surface)); - - assert(ws); - - wms->surface.refcount = 1; - wms->surface.winsys = ws; - - return &wms->surface; -} - -static void -exa_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) -{ - struct pipe_surface *surf = *s; - - surf->refcount--; - if (surf->refcount == 0) { - if (surf->buffer) - pipe_buffer_reference(winsys, &surf->buffer, NULL); - free(surf); - } - *s = NULL; -} - -/* - * Fence functions - basically nothing to do, as we don't create any actual - * fence objects. - */ -static void -exa_fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence) -{ -} - -static int -exa_fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence, - unsigned flag) -{ - return 0; -} - -static int -exa_fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence, - unsigned flag) -{ - return 0; -} - -struct pipe_winsys * -exa_get_pipe_winsys(modesettingPtr ms) -{ - static struct exa_winsys *ws = NULL; - - if (!ws) { - ws = xcalloc(1, sizeof(struct exa_winsys)); - - /* Fill in this struct with callbacks that pipe will need to - * communicate with the window system, buffer manager, etc. - */ - ws->base.buffer_create = exa_buffer_create; - ws->base.user_buffer_create = exa_user_buffer_create; - ws->base.buffer_map = exa_buffer_map; - ws->base.buffer_unmap = exa_buffer_unmap; - ws->base.buffer_destroy = exa_buffer_destroy; - - ws->base.surface_alloc = exa_surface_alloc; - ws->base.surface_alloc_storage = exa_surface_alloc_storage; - ws->base.surface_release = exa_surface_release; - - ws->base.fence_reference = exa_fence_reference; - ws->base.fence_signalled = exa_fence_signalled; - ws->base.fence_finish = exa_fence_finish; - - ws->base.flush_frontbuffer = exa_flush_frontbuffer; - ws->base.get_name = exa_get_name; - - ws->ms = ms; - } - - return &ws->base; -} - -/* EXA functions */ - -struct PixmapPriv -{ - drmBO bo; -#if 0 - dri_fence *fence; -#endif - int flags; - - struct pipe_texture *tex; - unsigned int color; - struct pipe_surface *src_surf; /* for copies */ -}; - -static enum pipe_format -exa_get_pipe_format(int depth) -{ - switch (depth) { - case 32: - case 24: - return PIPE_FORMAT_A8R8G8B8_UNORM; - case 16: - return PIPE_FORMAT_R5G6B5_UNORM; - case 15: - return PIPE_FORMAT_A1R5G5B5_UNORM; - case 8: - case 4: - case 1: - return PIPE_FORMAT_A8R8G8B8_UNORM; /* bad bad bad */ - default: - assert(0); - return 0; - } -} - -/* - * EXA functions - */ - -static void -ExaWaitMarker(ScreenPtr pScreen, int marker) -{ -} - -static int -ExaMarkSync(ScreenPtr pScreen) -{ - return 1; -} - -Bool -ExaPrepareAccess(PixmapPtr pPix, int index) -{ - ScreenPtr pScreen = pPix->drawable.pScreen; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - struct exa_entity *exa = ms->exa; - struct PixmapPriv *priv; - int ret; - - priv = exaGetPixmapDriverPrivate(pPix); - - if (!priv) - return FALSE; - - if (!priv->tex) - return FALSE; - { - struct pipe_surface *surf = - exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); - pPix->devPrivate.ptr = - exa->scrn->surface_map(exa->scrn, surf, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); - exa->scrn->tex_surface_release(exa->scrn, &surf); - } - - return TRUE; -} - -void -ExaFinishAccess(PixmapPtr pPix, int index) -{ - ScreenPtr pScreen = pPix->drawable.pScreen; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - struct PixmapPriv *priv; - struct exa_entity *exa = ms->exa; - int ret; - - priv = exaGetPixmapDriverPrivate(pPix); - - if (!priv) - return; - - if (!priv->tex) - return; - { - struct pipe_surface *surf = - exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); - exa->scrn->surface_unmap(exa->scrn, surf); - exa->scrn->tex_surface_release(exa->scrn, &surf); - pPix->devPrivate.ptr = NULL; - } -} - -static void -ExaDone(PixmapPtr pPixmap) -{ - ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); - struct exa_entity *exa = ms->exa; - - if (!priv) - return; - - if (priv->src_surf) - exa->scrn->tex_surface_release(exa->scrn, &priv->src_surf); - priv->src_surf = NULL; -} - -static void -ExaDoneComposite(PixmapPtr pPixmap) -{ - ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; -} - -static Bool -ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg) -{ - ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); - struct exa_entity *exa = ms->exa; - - if (pPixmap->drawable.depth < 15) - return FALSE; - - if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask)) - return FALSE; - - if (!priv || !priv->tex) - return FALSE; - - if (alu != GXcopy) - return FALSE; - - if (!exa->ctx || !exa->ctx->surface_fill) - return FALSE; - - priv->color = fg; - - return TRUE; -} - -static void -ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1) -{ - ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct exa_entity *exa = ms->exa; - struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); - struct pipe_surface *surf = - exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - - exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0, - priv->color); - - exa->scrn->tex_surface_release(exa->scrn, &surf); -} - -static Bool -ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, - int ydir, int alu, Pixel planeMask) -{ - ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct exa_entity *exa = ms->exa; - struct pipe_surface *src_surf; - struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap); - struct PixmapPriv *src_priv = exaGetPixmapDriverPrivate(pSrcPixmap); - - if (alu != GXcopy) - return FALSE; - - if (pSrcPixmap->drawable.depth < 15 || pDstPixmap->drawable.depth < 15) - return FALSE; - - if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask)) - return FALSE; - - if (!priv || !src_priv) - return FALSE; - - if (!priv->tex || !src_priv->tex) - return FALSE; - - if (!exa->ctx || !exa->ctx->surface_copy) - return FALSE; - - priv->src_surf = - exa->scrn->get_tex_surface(exa->scrn, src_priv->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - - return FALSE; -} - -static void -ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY, - int width, int height) -{ - ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct exa_entity *exa = ms->exa; - struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap); - struct pipe_surface *surf = - exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - - exa->ctx->surface_copy(exa->ctx, 0, surf, dstX, dstY, priv->src_surf, - srcX, srcY, width, height); - exa->scrn->tex_surface_release(exa->scrn, &surf); -} - -static Bool -ExaPrepareComposite(int op, PicturePtr pSrcPicture, - PicturePtr pMaskPicture, PicturePtr pDstPicture, - PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst) -{ - ScreenPtr pScreen = pDst->drawable.pScreen; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - - return FALSE; -} - -static Bool -ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, - int src_pitch) -{ - ScreenPtr pScreen = pDst->drawable.pScreen; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - - ErrorF("UPLOAD\n"); - - return FALSE; -} - -static void -ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY, - int dstX, int dstY, int width, int height) -{ - ScreenPtr pScreen = pDst->drawable.pScreen; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; -} - -static Bool -ExaCheckComposite(int op, - PicturePtr pSrcPicture, PicturePtr pMaskPicture, - PicturePtr pDstPicture) -{ - DrawablePtr pDraw = pSrcPicture->pDrawable; - int w = pDraw->width; - int h = pDraw->height; - - return FALSE; -} - -static void * -ExaCreatePixmap(ScreenPtr pScreen, int size, int align) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct PixmapPriv *priv; - void *virtual; - - priv = xcalloc(1, sizeof(struct PixmapPriv)); - if (!priv) - return NULL; - - return priv; -} - -static void -ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv) -{ - struct PixmapPriv *priv = (struct PixmapPriv *)dPriv; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct exa_entity *exa = ms->exa; - - if (!priv) - return; - - if (priv->tex) - exa->scrn->texture_release(exa->scrn, &priv->tex); - - xfree(priv); -} - -static Bool -ExaPixmapIsOffscreen(PixmapPtr pPixmap) -{ - struct PixmapPriv *priv; - ScreenPtr pScreen = pPixmap->drawable.pScreen; - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - - priv = exaGetPixmapDriverPrivate(pPixmap); - - if (!priv) - return FALSE; - - if (priv->tex) - return TRUE; - - return FALSE; -} - -/* FIXME !! */ -unsigned int -driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) -{ - ScreenPtr pScreen = pPixmap->drawable.pScreen; - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct exa_entity *exa = ms->exa; - struct exa_buffer *exa_buf; - struct pipe_surface *surf; - struct PixmapPriv *priv; - - *flags = 0; - - if (!ms->exa) { - FatalError("NO MS->EXA\n"); - return 0; - } - - priv = exaGetPixmapDriverPrivate(pPixmap); - - if (!priv) { - FatalError("NO PIXMAP PRIVATE\n"); - return 0; - } - - surf = - exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); - exa_buf = exa_get_buffer(surf->buffer); - exa->scrn->tex_surface_release(exa->scrn, &surf); - - if (exa_buf->bo.handle) - return exa_buf->bo.handle; - - return 0; -} - -static Bool -ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, - int depth, int bitsPerPixel, int devKind, - pointer pPixData) -{ - ScreenPtr pScreen = pPixmap->drawable.pScreen; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); - modesettingPtr ms = modesettingPTR(pScrn); - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - struct exa_entity *exa = ms->exa; - - if (!priv) - return FALSE; - - if (depth <= 0) - depth = pPixmap->drawable.depth; - - if (bitsPerPixel <= 0) - bitsPerPixel = pPixmap->drawable.bitsPerPixel; - - if (width <= 0) - width = pPixmap->drawable.width; - - if (height <= 0) - height = pPixmap->drawable.height; - - if (width <= 0 || height <= 0 || depth <= 0) - return FALSE; - - miModifyPixmapHeader(pPixmap, width, height, depth, - bitsPerPixel, devKind, NULL); - - /* Deal with screen resize */ - if (priv->tex) { - struct pipe_surface *surf = - exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); - - ErrorF("RESIZE %d %d to %d %d\n", surf->width, surf->height, width, - height); - if (surf->width != width || surf->height != height) { - exa->scrn->texture_release(exa->scrn, &priv->tex); - priv->tex = NULL; - } - exa->scrn->tex_surface_release(exa->scrn, &surf); - } - - if (!priv->tex) { - struct pipe_texture template; - - memset(&template, 0, sizeof(template)); - template.target = PIPE_TEXTURE_2D; - template.compressed = 0; - template.format = exa_get_pipe_format(depth); - pf_get_block(template.format, &template.block); - template.width[0] = width; - template.height[0] = height; - template.depth[0] = 1; - template.last_level = 0; - template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - priv->tex = exa->scrn->texture_create(exa->scrn, &template); - } - - return TRUE; -} - -void -ExaClose(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - struct exa_entity *exa = ms->exa; - - exaDriverFini(pScrn->pScreen); - - dlclose(ms->driver); -} - -void * -ExaInit(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - struct exa_entity *exa; - ExaDriverPtr pExa; - - exa = xcalloc(1, sizeof(struct exa_entity)); - if (!exa) - return NULL; - - pExa = exaDriverAlloc(); - if (!pExa) { - goto out_err; - } - - memset(pExa, 0, sizeof(*pExa)); - pExa->exa_major = 2; - pExa->exa_minor = 4; - pExa->memoryBase = 0; - pExa->memorySize = 0; - pExa->offScreenBase = 0; - pExa->pixmapOffsetAlign = 0; - pExa->pixmapPitchAlign = 1; - pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS; - pExa->maxX = 8191; /* FIXME */ - pExa->maxY = 8191; /* FIXME */ - pExa->WaitMarker = ExaWaitMarker; - pExa->MarkSync = ExaMarkSync; - pExa->PrepareSolid = ExaPrepareSolid; - pExa->Solid = ExaSolid; - pExa->DoneSolid = ExaDone; - pExa->PrepareCopy = ExaPrepareCopy; - pExa->Copy = ExaCopy; - pExa->DoneCopy = ExaDone; - pExa->CheckComposite = ExaCheckComposite; - pExa->PrepareComposite = ExaPrepareComposite; - pExa->Composite = ExaComposite; - pExa->DoneComposite = ExaDoneComposite; - pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen; - pExa->PrepareAccess = ExaPrepareAccess; - pExa->FinishAccess = ExaFinishAccess; - pExa->UploadToScreen = ExaUploadToScreen; - pExa->CreatePixmap = ExaCreatePixmap; - pExa->DestroyPixmap = ExaDestroyPixmap; - pExa->ModifyPixmapHeader = ExaModifyPixmapHeader; - - if (!exaDriverInit(pScrn->pScreen, pExa)) { - goto out_err; - } - - { - char filename[128]; - char dri_driver_path[] = DRI_DRIVER_PATH; - - snprintf(filename, sizeof filename, - "%s/%s_dri.so", dri_driver_path, "i915"); - - ms->driver = dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL); - if (!ms->driver) - FatalError("failed to initialize i915 - for softpipe only.\n"); - - exa->c = xcalloc(1, sizeof(struct exa_context)); - - exa->ws = exa_get_pipe_winsys(ms); - if (!exa->ws) - FatalError("BAD WINSYS\n"); - - exa->scrn = softpipe_create_screen(exa->ws); - if (!exa->scrn) - FatalError("BAD SCREEN\n"); - - exa->ctx = softpipe_create(exa->scrn, exa->ws, NULL); - if (!exa->ctx) - FatalError("BAD CTX\n"); - - exa->ctx->priv = exa->c; - } - - return (void *)exa; - - out_err: - ExaClose(pScrn); - - return NULL; -} From 2a4618905445ce13fd272a4634ef5103dc804231 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 11:49:26 +0100 Subject: [PATCH 019/122] modesetting: restart driver effort from other codebases This starts a randr 1.2 compatible driver with cursors. TODO: libkms dirty handling server recycling. --- hw/xfree86/drivers/modesetting/Makefile.am | 11 +- hw/xfree86/drivers/modesetting/crtc.c | 307 ---- hw/xfree86/drivers/modesetting/dri2.c | 128 -- hw/xfree86/drivers/modesetting/driver.c | 242 +-- hw/xfree86/drivers/modesetting/driver.h | 8 +- .../drivers/modesetting/drmmode_display.c | 1340 +++++++++++++++++ .../drivers/modesetting/drmmode_display.h | 125 ++ hw/xfree86/drivers/modesetting/output.c | 292 ---- 8 files changed, 1507 insertions(+), 946 deletions(-) delete mode 100644 hw/xfree86/drivers/modesetting/crtc.c delete mode 100644 hw/xfree86/drivers/modesetting/dri2.c create mode 100644 hw/xfree86/drivers/modesetting/drmmode_display.c create mode 100644 hw/xfree86/drivers/modesetting/drmmode_display.h delete mode 100644 hw/xfree86/drivers/modesetting/output.c diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am index 23e78b753..4337977b0 100644 --- a/hw/xfree86/drivers/modesetting/Makefile.am +++ b/hw/xfree86/drivers/modesetting/Makefile.am @@ -25,19 +25,16 @@ SUBDIRS = # _ladir passes a dummy rpath to libtool so the thing will actually link # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. -AM_CFLAGS = @WARN_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLAGS@ \ - -I@GALLIUM_DIR@/src/gallium/include \ - -I@GALLIUM_DIR@/src/gallium/auxiliary +AM_CFLAGS = @XORG_CFLAGS@ @DRM_CFLAGS@ @UDEV_CFLAGS@ modesetting_drv_la_LTLIBRARIES = modesetting_drv.la -modesetting_drv_la_LDFLAGS = -module -avoid-version -ldrm +modesetting_drv_la_LDFLAGS = -module -avoid-version +modesetting_drv_la_LIBADD = @UDEV_LIBS@ @DRM_LIBS@ modesetting_drv_ladir = @moduledir@/drivers modesetting_drv_la_SOURCES = \ driver.c \ driver.h \ - output.c \ - crtc.c \ - dri2.c + drmmode_display.c EXTRA_DIST = diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c deleted file mode 100644 index d4f449bb4..000000000 --- a/hw/xfree86/drivers/modesetting/crtc.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include "driver.h" -#include "xf86Modes.h" - -#define DPMS_SERVER -#include - -struct crtc_private -{ - drmModeCrtcPtr drm_crtc; - - /* hwcursor */ - drmBO cursor_bo; -}; - -static void -crtc_dpms(xf86CrtcPtr crtc, int mode) -{ - ScrnInfoPtr pScrn = crtc->scrn; - - switch (mode) { - case DPMSModeOn: - case DPMSModeStandby: - case DPMSModeSuspend: - break; - case DPMSModeOff: - break; - } -} - -static Bool -crtc_lock(xf86CrtcPtr crtc) -{ - return FALSE; -} - -static void -crtc_unlock(xf86CrtcPtr crtc) -{ -} - -static void -crtc_prepare(xf86CrtcPtr crtc) -{ -} - -static void -crtc_commit(xf86CrtcPtr crtc) -{ -} - -static Bool -crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode, - DisplayModePtr adjusted_mode) -{ - return TRUE; -} - -static void -crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, - DisplayModePtr adjusted_mode, int x, int y) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - modesettingPtr ms = modesettingPTR(crtc->scrn); - xf86OutputPtr output = config->output[config->compat_output]; - drmModeConnectorPtr drm_connector = output->driver_private; - struct crtc_private *crtcp = crtc->driver_private; - drmModeCrtcPtr drm_crtc = crtcp->drm_crtc; - struct drm_mode_modeinfo drm_mode; - - drm_mode.clock = mode->Clock; - drm_mode.hdisplay = mode->HDisplay; - drm_mode.hsync_start = mode->HSyncStart; - drm_mode.hsync_end = mode->HSyncEnd; - drm_mode.htotal = mode->HTotal; - drm_mode.vdisplay = mode->VDisplay; - drm_mode.vsync_start = mode->VSyncStart; - drm_mode.vsync_end = mode->VSyncEnd; - drm_mode.vtotal = mode->VTotal; - drm_mode.flags = mode->Flags; - drm_mode.hskew = mode->HSkew; - drm_mode.vscan = mode->VScan; - drm_mode.vrefresh = mode->VRefresh; - if (!mode->name) - xf86SetModeDefaultName(mode); - strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN); - - drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y, - &drm_connector->connector_id, 1, &drm_mode); -} - -void -crtc_load_lut(xf86CrtcPtr crtc) -{ - ScrnInfoPtr pScrn = crtc->scrn; -} - -static void -crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue, - int size) -{ -} - -static void * -crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height) -{ - ScrnInfoPtr pScrn = crtc->scrn; - - return NULL; -} - -static PixmapPtr -crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height) -{ - ScrnInfoPtr pScrn = crtc->scrn; - - return NULL; -} - -static void -crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data) -{ - ScrnInfoPtr pScrn = crtc->scrn; -} - -static void -crtc_destroy(xf86CrtcPtr crtc) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - struct crtc_private *crtcp = crtc->driver_private; - - if (crtcp->cursor_bo.handle) - drmBOUnreference(ms->fd, &crtcp->cursor_bo); - - drmModeFreeCrtc(crtcp->drm_crtc); - xfree(crtcp); -} - -static void -crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image) -{ - unsigned char *ptr; - modesettingPtr ms = modesettingPTR(crtc->scrn); - struct crtc_private *crtcp = crtc->driver_private; - - if (!crtcp->cursor_bo.handle) - drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL, - DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE - | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE | - DRM_BO_FLAG_MEM_VRAM, - DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo); - - drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, - DRM_BO_HINT_DONT_FENCE, (void **)&ptr); - - if (ptr) - memcpy(ptr, image, 64 * 64 * 4); - - drmBOUnmap(ms->fd, &crtcp->cursor_bo); -} - -static void -crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - struct crtc_private *crtcp = crtc->driver_private; - - drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y); -} - -static void -crtc_show_cursor(xf86CrtcPtr crtc) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - struct crtc_private *crtcp = crtc->driver_private; - - if (crtcp->cursor_bo.handle) - drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, - crtcp->cursor_bo.handle, 64, 64); -} - -static void -crtc_hide_cursor(xf86CrtcPtr crtc) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - struct crtc_private *crtcp = crtc->driver_private; - - drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0); -} - -static const xf86CrtcFuncsRec crtc_funcs = { - .dpms = crtc_dpms, - .save = NULL, - .restore = NULL, - .lock = crtc_lock, - .unlock = crtc_unlock, - .mode_fixup = crtc_mode_fixup, - .prepare = crtc_prepare, - .mode_set = crtc_mode_set, - .commit = crtc_commit, - .gamma_set = crtc_gamma_set, - .shadow_create = crtc_shadow_create, - .shadow_allocate = crtc_shadow_allocate, - .shadow_destroy = crtc_shadow_destroy, - .set_cursor_position = crtc_set_cursor_position, - .show_cursor = crtc_show_cursor, - .hide_cursor = crtc_hide_cursor, - .load_cursor_image = NULL, /* lets convert to argb only */ - .set_cursor_colors = NULL, /* using argb only */ - .load_cursor_argb = crtc_load_cursor_argb, - .destroy = crtc_destroy, -}; - -void -cursor_destroy(xf86CrtcPtr crtc) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - struct crtc_private *crtcp = crtc->driver_private; - - if (crtcp->cursor_bo.handle) { - drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0); - drmBOUnreference(ms->fd, &crtcp->cursor_bo); - } -} - -void -crtc_init(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - xf86CrtcPtr crtc; - drmModeResPtr res; - drmModeCrtcPtr drm_crtc = NULL; - struct crtc_private *crtcp; - int c, k, p; - - res = drmModeGetResources(ms->fd); - if (res == 0) { - ErrorF("Failed drmModeGetResources %d\n", errno); - return; - } - - for (c = 0; c < res->count_crtcs; c++) { - drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]); - if (!drm_crtc) - continue; - - crtc = xf86CrtcCreate(pScrn, &crtc_funcs); - if (crtc == NULL) - goto out; - - crtcp = xcalloc(1, sizeof(struct crtc_private)); - if (!crtcp) { - xf86CrtcDestroy(crtc); - goto out; - } - - crtcp->drm_crtc = drm_crtc; - - crtc->driver_private = crtcp; - - } - - out: - drmModeFreeResources(res); -} diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c deleted file mode 100644 index 7fd9fcae3..000000000 --- a/hw/xfree86/drivers/modesetting/dri2.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "xf86.h" -#include "xf86_OSproc.h" - -#include "driver.h" - -#include "dri2.h" - -extern unsigned int -driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); - -void -driLock(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - - if (!ms->lock_held) - DRM_LOCK(ms->fd, ms->lock, ms->context, 0); - - ms->lock_held = 1; -} - -void -driUnlock(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - - if (ms->lock_held) - DRM_UNLOCK(ms->fd, ms->lock, ms->context); - - ms->lock_held = 0; -} - -static void -driBeginClipNotify(ScreenPtr pScreen) -{ - driLock(pScreen); -} - -static void -driEndClipNotify(ScreenPtr pScreen) -{ - driUnlock(pScreen); -} - -struct __DRILock -{ - unsigned int block_header; - drm_hw_lock_t lock; - unsigned int next_id; -}; - -#define DRI2_SAREA_BLOCK_HEADER(type, size) (((type) << 16) | (size)) -#define DRI2_SAREA_BLOCK_LOCK 0x0001 - -void -driScreenInit(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - DRI2InfoRec dri2info; - const char *driverName; - unsigned int sarea_handle; - struct __DRILock *DRILock; - void *p; - - dri2info.version = 1; - dri2info.fd = ms->fd; - dri2info.driverSareaSize = sizeof(struct __DRILock); - dri2info.driverName = "i915"; /* FIXME */ - dri2info.getPixmapHandle = driGetPixmapHandle; - dri2info.beginClipNotify = driBeginClipNotify; - dri2info.endClipNotify = driEndClipNotify; - - p = DRI2ScreenInit(pScreen, &dri2info); - if (!p) - return; - - DRILock = p; - DRILock->block_header = - DRI2_SAREA_BLOCK_HEADER(DRI2_SAREA_BLOCK_LOCK, sizeof *DRILock); - ms->lock = &DRILock->lock; - ms->context = 1; - DRILock->next_id = 2; - driLock(pScreen); - - DRI2Connect(pScreen, &ms->fd, &driverName, &sarea_handle); -} - -void -driCloseScreen(ScreenPtr pScreen) -{ - driUnlock(pScreen); - DRI2CloseScreen(pScreen); -} diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 6b70d4b09..47ffb07b7 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -34,10 +34,8 @@ #include "xf86.h" #include "xf86_OSproc.h" #include "compiler.h" -#include "xf86RAC.h" #include "xf86PciInfo.h" #include "xf86Pci.h" -#include "xf86Resources.h" #include "mipointer.h" #include "micmap.h" #include @@ -59,8 +57,6 @@ static void AdjustFrame(int scrnIndex, int x, int y, int flags); static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen); static Bool EnterVT(int scrnIndex, int flags); -static Bool SaveHWState(ScrnInfoPtr pScrn); -static Bool RestoreHWState(ScrnInfoPtr pScrn); static void Identify(int flags); static const OptionInfoRec *AvailableOptions(int chipid, int busid); static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, @@ -82,7 +78,7 @@ static Bool Probe(DriverPtr drv, int flags); #if XSERVER_LIBPCIACCESS static const struct pci_id_match device_match[] = { - {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0}, + {0x8086, 0x0046, 0xffff, 0xffff, 0, 0, 0}, {0, 0, 0}, }; #endif @@ -107,12 +103,12 @@ _X_EXPORT DriverRec modesetting = { }; static SymTabRec Chipsets[] = { - {0x2592, "Intel Graphics Device"}, + {0x0046, "Intel Graphics Device"}, {-1, NULL} }; static PciChipsets PciDevices[] = { - {0x2592, 0x2592, RES_SHARED_VGA}, + {0x2592, 0x0046, RES_SHARED_VGA}, {-1, -1, RES_UNDEFINED} }; @@ -126,24 +122,6 @@ static const OptionInfoRec Options[] = { {-1, NULL, OPTV_NONE, {0}, FALSE} }; -static const char *fbSymbols[] = { - "fbPictureInit", - "fbScreenInit", - NULL -}; - -static const char *ddcSymbols[] = { - "xf86PrintEDID", - "xf86SetDDCproperties", - NULL -}; - -static const char *i2cSymbols[] = { - "xf86CreateI2CBusRec", - "xf86I2CBusInit", - NULL -}; - int modesettingEntityIndex = -1; static MODULESETUPPROTO(Setup); @@ -174,12 +152,6 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin) setupDone = 1; xf86AddDriver(&modesetting, module, HaveDriverFuncs); - /* - * Tell the loader about symbols from other modules that this module - * might refer to. - */ - LoaderRefSymLists(fbSymbols, ddcSymbols, NULL); - /* * The return value must be non-NULL on success even though there * is no TearDownProc. @@ -225,7 +197,7 @@ pci_probe(DriverPtr driver, entity = xf86GetEntityInfo(entity_num); switch (device->device_id) { - case 0x2592: + case 0x0046: scrn->PreInit = PreInit; scrn->ScreenInit = ScreenInit; scrn->SwitchMode = SwitchMode; @@ -358,8 +330,8 @@ Probe(DriverPtr drv, int flags) } } - xfree(usedChips); - xfree(devSections); + free(usedChips); + free(devSections); return foundScreen; } @@ -385,76 +357,11 @@ FreeRec(ScrnInfoPtr pScrn) if (!pScrn->driverPrivate) return; - xfree(pScrn->driverPrivate); + free(pScrn->driverPrivate); pScrn->driverPrivate = NULL; } -static void -ProbeDDC(ScrnInfoPtr pScrn, int index) -{ - ConfiguredMonitor = NULL; -} - -static Bool -CreateFrontBuffer(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - ScreenPtr pScreen = pScrn->pScreen; - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - Bool fbAccessDisabled; - int flags; - - pScreen->ModifyPixmapHeader(rootPixmap, - pScrn->virtualX, pScrn->virtualY, - pScrn->depth, pScrn->bitsPerPixel, - pScrn->displayWidth * pScrn->bitsPerPixel / 8, - NULL); - drmModeAddFB(ms->fd, - pScrn->virtualX, - pScrn->virtualY, - pScrn->depth, - pScrn->bitsPerPixel, - pScrn->displayWidth * pScrn->bitsPerPixel / 8, - driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id); - - pScrn->frameX0 = 0; - pScrn->frameY0 = 0; - AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); - - return TRUE; -} - -static Bool -crtc_resize(ScrnInfoPtr pScrn, int width, int height) -{ - modesettingPtr ms = modesettingPTR(pScrn); - ScreenPtr pScreen = pScrn->pScreen; - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - Bool fbAccessDisabled; - CARD8 *fbstart; - - if (width == pScrn->virtualX && height == pScrn->virtualY) - return TRUE; - - ErrorF("RESIZING TO %dx%d\n", width, height); - - pScrn->virtualX = width; - pScrn->virtualY = height; - - /* HW dependent - FIXME */ - pScrn->displayWidth = pScrn->virtualX; - - drmModeRmFB(ms->fd, ms->fb_id); - - /* now create new frontbuffer */ - return CreateFrontBuffer(pScrn); -} - -static const xf86CrtcConfigFuncsRec crtc_config_funcs = { - crtc_resize -}; - static Bool PreInit(ScrnInfoPtr pScrn, int flags) { @@ -476,8 +383,7 @@ PreInit(ScrnInfoPtr pScrn, int flags) pEnt = xf86GetEntityInfo(pScrn->entityList[0]); if (flags & PROBE_DETECT) { - ProbeDDC(pScrn, pEnt->index); - return TRUE; + return FALSE; } /* Allocate driverPrivate */ @@ -503,10 +409,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) } else ms->entityPrivate = NULL; - if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) { - return FALSE; - } - if (xf86IsEntityShared(pScrn->entityList[0])) { if (xf86IsPrimInitDone(pScrn->entityList[0])) { /* do something */ @@ -515,7 +417,7 @@ PreInit(ScrnInfoPtr pScrn, int flags) } } - BusID = xalloc(64); + BusID = malloc(64); sprintf(BusID, "PCI:%d:%d:%d", #if XSERVER_LIBPCIACCESS ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), @@ -528,11 +430,9 @@ PreInit(ScrnInfoPtr pScrn, int flags) ); ms->fd = drmOpen(NULL, BusID); - if (ms->fd < 0) return FALSE; - pScrn->racMemFlags = RAC_FB | RAC_COLORMAP; pScrn->monitor = pScrn->confScreen->monitor; pScrn->progClock = TRUE; pScrn->rgbBits = 8; @@ -562,36 +462,21 @@ PreInit(ScrnInfoPtr pScrn, int flags) /* Process the options */ xf86CollectOptions(pScrn, NULL); - if (!(ms->Options = xalloc(sizeof(Options)))) + if (!(ms->Options = malloc(sizeof(Options)))) return FALSE; memcpy(ms->Options, Options, sizeof(Options)); xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options); - /* Allocate an xf86CrtcConfig */ - xf86CrtcConfigInit(pScrn, &crtc_config_funcs); - xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - - max_width = 8192; - max_height = 8192; - xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height); - if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) { ms->SWCursor = TRUE; } - SaveHWState(pScrn); - - crtc_init(pScrn); - output_init(pScrn); - - if (!xf86InitialConfiguration(pScrn, TRUE)) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n"); - RestoreHWState(pScrn); - return FALSE; + ms->drmmode.fd = ms->fd; + if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n"); + goto fail; } - RestoreHWState(pScrn); - /* * If the driver can do gamma correction, it should call xf86SetGamma() here. */ @@ -618,29 +503,13 @@ PreInit(ScrnInfoPtr pScrn, int flags) return FALSE; } - xf86LoaderReqSymLists(fbSymbols, NULL); - #ifdef DRI2 xf86LoadSubModule(pScrn, "dri2"); #endif return TRUE; -} - -static Bool -SaveHWState(ScrnInfoPtr pScrn) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - - return TRUE; -} - -static Bool -RestoreHWState(ScrnInfoPtr pScrn) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - - return TRUE; + fail: + return FALSE; } static Bool @@ -651,26 +520,25 @@ CreateScreenResources(ScreenPtr pScreen) PixmapPtr rootPixmap; Bool ret; int flags; - + void *pixels; pScreen->CreateScreenResources = ms->createScreenResources; ret = pScreen->CreateScreenResources(pScreen); pScreen->CreateScreenResources = CreateScreenResources; + if (!drmmode_set_desired_modes(pScrn, &ms->drmmode)) + return FALSE; + + drmmode_uevent_init(pScrn, &ms->drmmode); + + drmmode_map_cursor_bos(pScrn, &ms->drmmode); + pixels = drmmode_map_front_bo(&ms->drmmode); + if (!pixels) + return FALSE; + rootPixmap = pScreen->GetScreenPixmap(pScreen); - - if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL)) + if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels)) FatalError("Couldn't adjust screen pixmap\n"); - drmModeAddFB(ms->fd, - pScrn->virtualX, - pScrn->virtualY, - pScrn->depth, - pScrn->bitsPerPixel, - pScrn->displayWidth * pScrn->bitsPerPixel / 8, - driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id); - - AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); - return ret; } @@ -688,7 +556,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (ms->fd < 0) { char *BusID; - BusID = xalloc(64); + BusID = malloc(64); sprintf(BusID, "PCI:%d:%d:%d", #if XSERVER_LIBPCIACCESS ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), @@ -710,6 +578,8 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) /* HW dependent - FIXME */ pScrn->displayWidth = pScrn->virtualX; + if (!drmmode_create_initial_bos(pScrn, &ms->drmmode)) + return FALSE; miClearVisualTypes(); @@ -782,10 +652,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (serverGeneration == 1) xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); -#ifdef DRI2 - driScreenInit(pScreen); -#endif - return EnterVT(scrnIndex, 1); } @@ -822,7 +688,7 @@ LeaveVT(int scrnIndex, int flags) for (o = 0; o < config->num_crtc; o++) { xf86CrtcPtr crtc = config->crtc[o]; - cursor_destroy(crtc); + // cursor_destroy(crtc); if (crtc->rotatedPixmap || crtc->rotatedData) { crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, @@ -834,16 +700,6 @@ LeaveVT(int scrnIndex, int flags) drmModeRmFB(ms->fd, ms->fb_id); - RestoreHWState(pScrn); - -#if 0 - drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0); - drmMMLock(ms->fd, DRM_BO_MEM_TT, 1, 0); -#endif -#ifdef DRI2 - driLock(pScrn->pScreen); -#endif - pScrn->vtSema = FALSE; } @@ -856,29 +712,6 @@ EnterVT(int scrnIndex, int flags) ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; modesettingPtr ms = modesettingPTR(pScrn); -#if 0 - if (pScrn->vtSema) { - drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); - drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1); - } -#endif - -#ifdef DRI2 - driUnlock(pScrn->pScreen); -#endif - - /* - * Only save state once per server generation since that's what most - * drivers do. Could change this to save state at each VT enter. - */ - if (ms->SaveGeneration != serverGeneration) { - ms->SaveGeneration = serverGeneration; - SaveHWState(pScrn); - } - - if (!flags) /* signals startup as we'll do this in CreateScreenResources */ - CreateFrontBuffer(pScrn); - if (!xf86SetDesiredModes(pScrn)) return FALSE; @@ -899,16 +732,13 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; modesettingPtr ms = modesettingPTR(pScrn); + drmmode_uevent_fini(pScrn, &ms->drmmode); + + drmmode_free_bos(pScrn, &ms->drmmode); + if (pScrn->vtSema) { LeaveVT(scrnIndex, 0); -#if 0 - drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1); - drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1); -#endif } -#ifdef DRI2 - driCloseScreen(pScreen); -#endif pScreen->CreateScreenResources = ms->createScreenResources; diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index a673f8fd9..255dedef1 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -30,9 +30,8 @@ #include #include #include -#include -#include +#include "drmmode_display.h" #define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg); typedef struct @@ -72,10 +71,7 @@ typedef struct _modesettingRec void *driver; - /* dri2 */ - drm_context_t context; - drm_hw_lock_t *lock; - int lock_held; + drmmode_rec drmmode; } modesettingRec, *modesettingPtr; #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c new file mode 100644 index 000000000..d94ce03e0 --- /dev/null +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -0,0 +1,1340 @@ +/* + * Copyright © 2007 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Authors: + * Dave Airlie + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include "xf86str.h" +#include "X11/Xatom.h" +#include "micmap.h" +#include "xf86cmap.h" +#include "xf86DDC.h" + +#include +#include "xf86Crtc.h" +#include "drmmode_display.h" + +/* DPMS */ +#ifdef HAVE_XEXTPROTO_71 +#include +#else +#define DPMS_SERVER +#include +#endif + +static struct dumb_bo *dumb_bo_create(int fd, + const unsigned width, const unsigned height, + const unsigned bpp) +{ + struct drm_mode_create_dumb arg; + struct dumb_bo *bo; + int ret; + + bo = calloc(1, sizeof(*bo)); + if (!bo) + return NULL; + + memset(&arg, 0, sizeof(arg)); + arg.width = width; + arg.height = height; + arg.bpp = bpp; + + ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg); + if (ret) + goto err_free; + + bo->handle = arg.handle; + bo->size = arg.size; + bo->pitch = arg.pitch; + + return bo; + err_free: + free(bo); + return NULL; +} + +static int dumb_bo_map(int fd, struct dumb_bo *bo) +{ + struct drm_mode_map_dumb arg; + int ret; + void *map; + + if (bo->ptr) { + bo->map_count++; + return 0; + } + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo->handle; + + ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg); + if (ret) + return ret; + + map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, arg.offset); + if (map == MAP_FAILED) + return -errno; + + bo->ptr = map; + return 0; +} + +static int dumb_bo_unmap(int fd, struct dumb_bo *bo) +{ + bo->map_count--; + return 0; +} + +static int dumb_bo_destroy(int fd, struct dumb_bo *bo) +{ + struct drm_mode_destroy_dumb arg; + int ret; + + if (bo->ptr) { + munmap(bo->ptr, bo->size); + bo->ptr = NULL; + } + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo->handle; + ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg); + if (ret) + return -errno; + + free(bo); + return 0; +} + +static void +drmmode_ConvertFromKMode(ScrnInfoPtr scrn, + drmModeModeInfo *kmode, + DisplayModePtr mode) +{ + memset(mode, 0, sizeof(DisplayModeRec)); + mode->status = MODE_OK; + + mode->Clock = kmode->clock; + + mode->HDisplay = kmode->hdisplay; + mode->HSyncStart = kmode->hsync_start; + mode->HSyncEnd = kmode->hsync_end; + mode->HTotal = kmode->htotal; + mode->HSkew = kmode->hskew; + + mode->VDisplay = kmode->vdisplay; + mode->VSyncStart = kmode->vsync_start; + mode->VSyncEnd = kmode->vsync_end; + mode->VTotal = kmode->vtotal; + mode->VScan = kmode->vscan; + + mode->Flags = kmode->flags; //& FLAG_BITS; + mode->name = strdup(kmode->name); + + if (kmode->type & DRM_MODE_TYPE_DRIVER) + mode->type = M_T_DRIVER; + if (kmode->type & DRM_MODE_TYPE_PREFERRED) + mode->type |= M_T_PREFERRED; + xf86SetModeCrtc (mode, scrn->adjustFlags); +} + +static void +drmmode_ConvertToKMode(ScrnInfoPtr scrn, + drmModeModeInfo *kmode, + DisplayModePtr mode) +{ + memset(kmode, 0, sizeof(*kmode)); + + kmode->clock = mode->Clock; + kmode->hdisplay = mode->HDisplay; + kmode->hsync_start = mode->HSyncStart; + kmode->hsync_end = mode->HSyncEnd; + kmode->htotal = mode->HTotal; + kmode->hskew = mode->HSkew; + + kmode->vdisplay = mode->VDisplay; + kmode->vsync_start = mode->VSyncStart; + kmode->vsync_end = mode->VSyncEnd; + kmode->vtotal = mode->VTotal; + kmode->vscan = mode->VScan; + + kmode->flags = mode->Flags; //& FLAG_BITS; + if (mode->name) + strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN); + kmode->name[DRM_DISPLAY_MODE_LEN-1] = 0; + +} + +static void +drmmode_crtc_dpms(xf86CrtcPtr crtc, int mode) +{ +#if 0 + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); +// drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; +// drmmode_ptr drmmode = drmmode_crtc->drmmode; + + /* bonghits in the randr 1.2 - uses dpms to disable crtc - bad buzz */ + if (mode == DPMSModeOff) { +// drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, +// 0, 0, 0, NULL, 0, NULL); + } +#endif +} + +#if 0 +static PixmapPtr +create_pixmap_for_fbcon(drmmode_ptr drmmode, + ScrnInfoPtr pScrn, int crtc_id) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + drmmode_crtc_private_ptr drmmode_crtc; + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr pixmap; + struct radeon_bo *bo; + drmModeFBPtr fbcon; + struct drm_gem_flink flink; + + drmmode_crtc = xf86_config->crtc[crtc_id]->driver_private; + + fbcon = drmModeGetFB(drmmode->fd, drmmode_crtc->mode_crtc->buffer_id); + if (fbcon == NULL) + return NULL; + + flink.handle = fbcon->handle; + if (ioctl(drmmode->fd, DRM_IOCTL_GEM_FLINK, &flink) < 0) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Couldn't flink fbcon handle\n"); + return NULL; + } + + bo = radeon_bo_open(drmmode->bufmgr, flink.name, 0, 0, 0, 0); + if (bo == NULL) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Couldn't allocate bo for fbcon handle\n"); + return NULL; + } + + pixmap = drmmode_create_bo_pixmap(pScreen, fbcon->width, fbcon->height, + fbcon->depth, fbcon->bpp, + fbcon->pitch, bo); + if (!pixmap) + return NULL; + + radeon_bo_unref(bo); + drmModeFreeFB(fbcon); + return pixmap; +} + +#endif + +static Bool +drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, + Rotation rotation, int x, int y) +{ + ScrnInfoPtr pScrn = crtc->scrn; + // RADEONInfoPtr info = RADEONPTR(pScrn); + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + drmmode_ptr drmmode = drmmode_crtc->drmmode; + int saved_x, saved_y; + Rotation saved_rotation; + DisplayModeRec saved_mode; + uint32_t *output_ids; + int output_count = 0; + Bool ret = TRUE; + int i; + int fb_id; + drmModeModeInfo kmode; + int pitch; + uint32_t tiling_flags = 0; + int height; + + pitch = pScrn->displayWidth; + height = pScrn->virtualY; + + if (drmmode->fb_id == 0) { + ret = drmModeAddFB(drmmode->fd, + pScrn->virtualX, height, + pScrn->depth, pScrn->bitsPerPixel, + drmmode->front_bo->pitch, + drmmode->front_bo->handle, + &drmmode->fb_id); + if (ret < 0) { + ErrorF("failed to add fb %d\n", ret); + return FALSE; + } + } + + saved_mode = crtc->mode; + saved_x = crtc->x; + saved_y = crtc->y; + saved_rotation = crtc->rotation; + + if (mode) { + crtc->mode = *mode; + crtc->x = x; + crtc->y = y; + crtc->rotation = rotation; +#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,5,99,0,0) + crtc->transformPresent = FALSE; +#endif + } + + output_ids = calloc(sizeof(uint32_t), xf86_config->num_output); + if (!output_ids) { + ret = FALSE; + goto done; + } + + if (mode) { + for (i = 0; i < xf86_config->num_output; i++) { + xf86OutputPtr output = xf86_config->output[i]; + drmmode_output_private_ptr drmmode_output; + + if (output->crtc != crtc) + continue; + + drmmode_output = output->driver_private; + output_ids[output_count] = drmmode_output->mode_output->connector_id; + output_count++; + } + + if (!xf86CrtcRotate(crtc)) { + goto done; + } +#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,0,0,0) + crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green, + crtc->gamma_blue, crtc->gamma_size); +#endif + + drmmode_ConvertToKMode(crtc->scrn, &kmode, mode); + + fb_id = drmmode->fb_id; + if (drmmode_crtc->rotate_fb_id) { + fb_id = drmmode_crtc->rotate_fb_id; + x = y = 0; + } + ret = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, + fb_id, x, y, output_ids, output_count, &kmode); + if (ret) + xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, + "failed to set mode: %s", strerror(-ret)); + else + ret = TRUE; + + if (crtc->scrn->pScreen) + xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen); + /* go through all the outputs and force DPMS them back on? */ + for (i = 0; i < xf86_config->num_output; i++) { + xf86OutputPtr output = xf86_config->output[i]; + + if (output->crtc != crtc) + continue; + + output->funcs->dpms(output, DPMSModeOn); + } + } + +#if 0 + if (pScrn->pScreen && + !xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE)) + xf86_reload_cursors(pScrn->pScreen); +#endif +done: + if (!ret) { + crtc->x = saved_x; + crtc->y = saved_y; + crtc->rotation = saved_rotation; + crtc->mode = saved_mode; + } +#if defined(XF86_CRTC_VERSION) && XF86_CRTC_VERSION >= 3 + else + crtc->active = TRUE; +#endif + + return ret; +} + +static void +drmmode_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg) +{ + +} + +static void +drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y) +{ + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + drmmode_ptr drmmode = drmmode_crtc->drmmode; + + drmModeMoveCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, x, y); +} + +static void +drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) +{ + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + int i; + uint32_t *ptr; + + /* cursor should be mapped already */ + ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr); + + for (i = 0; i < 64 * 64; i++) + ptr[i] = image[i];// cpu_to_le32(image[i]); +} + + +static void +drmmode_hide_cursor (xf86CrtcPtr crtc) +{ + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + drmmode_ptr drmmode = drmmode_crtc->drmmode; + + drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, 64, 64); + +} + +static void +drmmode_show_cursor (xf86CrtcPtr crtc) +{ + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + drmmode_ptr drmmode = drmmode_crtc->drmmode; + uint32_t handle = drmmode_crtc->cursor_bo->handle; + + drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64); +} + +static void +drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green, + uint16_t *blue, int size) +{ + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + drmmode_ptr drmmode = drmmode_crtc->drmmode; + + drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, + size, red, green, blue); +} + +static const xf86CrtcFuncsRec drmmode_crtc_funcs = { + .dpms = drmmode_crtc_dpms, + .set_mode_major = drmmode_set_mode_major, + .set_cursor_colors = drmmode_set_cursor_colors, + .set_cursor_position = drmmode_set_cursor_position, + .show_cursor = drmmode_show_cursor, + .hide_cursor = drmmode_hide_cursor, + .load_cursor_argb = drmmode_load_cursor_argb, + + .gamma_set = drmmode_crtc_gamma_set, + .destroy = NULL, /* XXX */ +}; + +int drmmode_get_crtc_id(xf86CrtcPtr crtc) +{ + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + return drmmode_crtc->hw_id; +} + +static void +drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num) +{ + xf86CrtcPtr crtc; + drmmode_crtc_private_ptr drmmode_crtc; + + crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs); + if (crtc == NULL) + return; + + drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1); + drmmode_crtc->mode_crtc = drmModeGetCrtc(drmmode->fd, drmmode->mode_res->crtcs[num]); + drmmode_crtc->drmmode = drmmode; + crtc->driver_private = drmmode_crtc; +} + +static xf86OutputStatus +drmmode_output_detect(xf86OutputPtr output) +{ + /* go to the hw and retrieve a new output struct */ + drmmode_output_private_ptr drmmode_output = output->driver_private; + drmmode_ptr drmmode = drmmode_output->drmmode; + xf86OutputStatus status; + drmModeFreeConnector(drmmode_output->mode_output); + + drmmode_output->mode_output = drmModeGetConnector(drmmode->fd, drmmode_output->output_id); + + switch (drmmode_output->mode_output->connection) { + case DRM_MODE_CONNECTED: + status = XF86OutputStatusConnected; + break; + case DRM_MODE_DISCONNECTED: + status = XF86OutputStatusDisconnected; + break; + default: + case DRM_MODE_UNKNOWNCONNECTION: + status = XF86OutputStatusUnknown; + break; + } + return status; +} + +static Bool +drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes) +{ + return MODE_OK; +} + +static DisplayModePtr +drmmode_output_get_modes(xf86OutputPtr output) +{ + drmmode_output_private_ptr drmmode_output = output->driver_private; + drmModeConnectorPtr koutput = drmmode_output->mode_output; + drmmode_ptr drmmode = drmmode_output->drmmode; + int i; + DisplayModePtr Modes = NULL, Mode; + drmModePropertyPtr props; + xf86MonPtr mon = NULL; + + /* look for an EDID property */ + for (i = 0; i < koutput->count_props; i++) { + props = drmModeGetProperty(drmmode->fd, koutput->props[i]); + if (props && (props->flags & DRM_MODE_PROP_BLOB)) { + if (!strcmp(props->name, "EDID")) { + if (drmmode_output->edid_blob) + drmModeFreePropertyBlob(drmmode_output->edid_blob); + drmmode_output->edid_blob = drmModeGetPropertyBlob(drmmode->fd, koutput->prop_values[i]); + } + drmModeFreeProperty(props); + } + } + + if (drmmode_output->edid_blob) { + mon = xf86InterpretEDID(output->scrn->scrnIndex, + drmmode_output->edid_blob->data); + if (mon && drmmode_output->edid_blob->length > 128) + mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA; + } + xf86OutputSetEDID(output, mon); + + /* modes should already be available */ + for (i = 0; i < koutput->count_modes; i++) { + Mode = xnfalloc(sizeof(DisplayModeRec)); + + drmmode_ConvertFromKMode(output->scrn, &koutput->modes[i], Mode); + Modes = xf86ModesAdd(Modes, Mode); + + } + return Modes; +} + +static void +drmmode_output_destroy(xf86OutputPtr output) +{ + drmmode_output_private_ptr drmmode_output = output->driver_private; + int i; + + if (drmmode_output->edid_blob) + drmModeFreePropertyBlob(drmmode_output->edid_blob); + for (i = 0; i < drmmode_output->num_props; i++) { + drmModeFreeProperty(drmmode_output->props[i].mode_prop); + free(drmmode_output->props[i].atoms); + } + for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) { + drmModeFreeEncoder(drmmode_output->mode_encoders[i]); + free(drmmode_output->mode_encoders); + } + free(drmmode_output->props); + drmModeFreeConnector(drmmode_output->mode_output); + free(drmmode_output); + output->driver_private = NULL; +} + +static void +drmmode_output_dpms(xf86OutputPtr output, int mode) +{ + drmmode_output_private_ptr drmmode_output = output->driver_private; + drmModeConnectorPtr koutput = drmmode_output->mode_output; + drmmode_ptr drmmode = drmmode_output->drmmode; + + drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id, + drmmode_output->dpms_enum_id, mode); + return; +} + + +static Bool +drmmode_property_ignore(drmModePropertyPtr prop) +{ + if (!prop) + return TRUE; + /* ignore blob prop */ + if (prop->flags & DRM_MODE_PROP_BLOB) + return TRUE; + /* ignore standard property */ + if (!strcmp(prop->name, "EDID") || + !strcmp(prop->name, "DPMS")) + return TRUE; + + return FALSE; +} + +static void +drmmode_output_create_resources(xf86OutputPtr output) +{ + drmmode_output_private_ptr drmmode_output = output->driver_private; + drmModeConnectorPtr mode_output = drmmode_output->mode_output; + drmmode_ptr drmmode = drmmode_output->drmmode; + drmModePropertyPtr drmmode_prop; + int i, j, err; + + drmmode_output->props = calloc(mode_output->count_props, sizeof(drmmode_prop_rec)); + if (!drmmode_output->props) + return; + + drmmode_output->num_props = 0; + for (i = 0, j = 0; i < mode_output->count_props; i++) { + drmmode_prop = drmModeGetProperty(drmmode->fd, mode_output->props[i]); + if (drmmode_property_ignore(drmmode_prop)) { + drmModeFreeProperty(drmmode_prop); + continue; + } + drmmode_output->props[j].mode_prop = drmmode_prop; + drmmode_output->props[j].value = mode_output->prop_values[i]; + drmmode_output->num_props++; + j++; + } + + for (i = 0; i < drmmode_output->num_props; i++) { + drmmode_prop_ptr p = &drmmode_output->props[i]; + drmmode_prop = p->mode_prop; + + if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) { + INT32 range[2]; + INT32 value = p->value; + + p->num_atoms = 1; + p->atoms = calloc(p->num_atoms, sizeof(Atom)); + if (!p->atoms) + continue; + p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE); + range[0] = drmmode_prop->values[0]; + range[1] = drmmode_prop->values[1]; + err = RRConfigureOutputProperty(output->randr_output, p->atoms[0], + FALSE, TRUE, + drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE, + 2, range); + if (err != 0) { + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRConfigureOutputProperty error, %d\n", err); + } + err = RRChangeOutputProperty(output->randr_output, p->atoms[0], + XA_INTEGER, 32, PropModeReplace, 1, &value, FALSE, TRUE); + if (err != 0) { + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRChangeOutputProperty error, %d\n", err); + } + } else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) { + p->num_atoms = drmmode_prop->count_enums + 1; + p->atoms = calloc(p->num_atoms, sizeof(Atom)); + if (!p->atoms) + continue; + p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE); + for (j = 1; j <= drmmode_prop->count_enums; j++) { + struct drm_mode_property_enum *e = &drmmode_prop->enums[j-1]; + p->atoms[j] = MakeAtom(e->name, strlen(e->name), TRUE); + } + err = RRConfigureOutputProperty(output->randr_output, p->atoms[0], + FALSE, FALSE, + drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE, + p->num_atoms - 1, (INT32 *)&p->atoms[1]); + if (err != 0) { + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRConfigureOutputProperty error, %d\n", err); + } + for (j = 0; j < drmmode_prop->count_enums; j++) + if (drmmode_prop->enums[j].value == p->value) + break; + /* there's always a matching value */ + err = RRChangeOutputProperty(output->randr_output, p->atoms[0], + XA_ATOM, 32, PropModeReplace, 1, &p->atoms[j+1], FALSE, TRUE); + if (err != 0) { + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRChangeOutputProperty error, %d\n", err); + } + } + } +} + +static Bool +drmmode_output_set_property(xf86OutputPtr output, Atom property, + RRPropertyValuePtr value) +{ + drmmode_output_private_ptr drmmode_output = output->driver_private; + drmmode_ptr drmmode = drmmode_output->drmmode; + int i; + + for (i = 0; i < drmmode_output->num_props; i++) { + drmmode_prop_ptr p = &drmmode_output->props[i]; + + if (p->atoms[0] != property) + continue; + + if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) { + uint32_t val; + + if (value->type != XA_INTEGER || value->format != 32 || + value->size != 1) + return FALSE; + val = *(uint32_t *)value->data; + + drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id, + p->mode_prop->prop_id, (uint64_t)val); + return TRUE; + } else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) { + Atom atom; + const char *name; + int j; + + if (value->type != XA_ATOM || value->format != 32 || value->size != 1) + return FALSE; + memcpy(&atom, value->data, 4); + name = NameForAtom(atom); + + /* search for matching name string, then set its value down */ + for (j = 0; j < p->mode_prop->count_enums; j++) { + if (!strcmp(p->mode_prop->enums[j].name, name)) { + drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id, + p->mode_prop->prop_id, p->mode_prop->enums[j].value); + return TRUE; + } + } + } + } + + return TRUE; +} + +static Bool +drmmode_output_get_property(xf86OutputPtr output, Atom property) +{ + return TRUE; +} + +static const xf86OutputFuncsRec drmmode_output_funcs = { + .dpms = drmmode_output_dpms, + .create_resources = drmmode_output_create_resources, +#ifdef RANDR_12_INTERFACE + .set_property = drmmode_output_set_property, + .get_property = drmmode_output_get_property, +#endif + .detect = drmmode_output_detect, + .mode_valid = drmmode_output_mode_valid, + + .get_modes = drmmode_output_get_modes, + .destroy = drmmode_output_destroy +}; + +static int subpixel_conv_table[7] = { 0, SubPixelUnknown, + SubPixelHorizontalRGB, + SubPixelHorizontalBGR, + SubPixelVerticalRGB, + SubPixelVerticalBGR, + SubPixelNone }; + +const char *output_names[] = { "None", + "VGA", + "DVI", + "DVI", + "DVI", + "Composite", + "S-video", + "LVDS", + "CTV", + "DIN", + "DisplayPort", + "HDMI", + "HDMI", + "TV", + "eDP" +}; + +static void +drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dvi, int *num_hdmi) +{ + xf86OutputPtr output; + drmModeConnectorPtr koutput; + drmModeEncoderPtr *kencoders = NULL; + drmmode_output_private_ptr drmmode_output; + drmModePropertyPtr props; + char name[32]; + int i; + const char *s; + + koutput = drmModeGetConnector(drmmode->fd, drmmode->mode_res->connectors[num]); + if (!koutput) + return; + + kencoders = calloc(sizeof(drmModeEncoderPtr), koutput->count_encoders); + if (!kencoders) { + goto out_free_encoders; + } + + for (i = 0; i < koutput->count_encoders; i++) { + kencoders[i] = drmModeGetEncoder(drmmode->fd, koutput->encoders[i]); + if (!kencoders[i]) { + goto out_free_encoders; + } + } + + /* need to do smart conversion here for compat with non-kms ATI driver */ + snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1); + + output = xf86OutputCreate (pScrn, &drmmode_output_funcs, name); + if (!output) { + goto out_free_encoders; + } + + drmmode_output = calloc(sizeof(drmmode_output_private_rec), 1); + if (!drmmode_output) { + xf86OutputDestroy(output); + goto out_free_encoders; + } + + drmmode_output->output_id = drmmode->mode_res->connectors[num]; + drmmode_output->mode_output = koutput; + drmmode_output->mode_encoders = kencoders; + drmmode_output->drmmode = drmmode; + output->mm_width = koutput->mmWidth; + output->mm_height = koutput->mmHeight; + + output->subpixel_order = subpixel_conv_table[koutput->subpixel]; + output->interlaceAllowed = TRUE; + output->doubleScanAllowed = TRUE; + output->driver_private = drmmode_output; + + output->possible_crtcs = 0x7f; + for (i = 0; i < koutput->count_encoders; i++) { + output->possible_crtcs &= kencoders[i]->possible_crtcs; + } + /* work out the possible clones later */ + output->possible_clones = 0; + + for (i = 0; i < koutput->count_props; i++) { + props = drmModeGetProperty(drmmode->fd, koutput->props[i]); + if (props && (props->flags & DRM_MODE_PROP_ENUM)) { + if (!strcmp(props->name, "DPMS")) { + drmmode_output->dpms_enum_id = koutput->props[i]; + drmModeFreeProperty(props); + break; + } + drmModeFreeProperty(props); + } + } + + return; +out_free_encoders: + if (kencoders){ + for (i = 0; i < koutput->count_encoders; i++) + drmModeFreeEncoder(kencoders[i]); + free(kencoders); + } + drmModeFreeConnector(koutput); + +} + +uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output) +{ + drmmode_output_private_ptr drmmode_output = output->driver_private, clone_drmout; + int i; + xf86OutputPtr clone_output; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int index_mask = 0; + + if (drmmode_output->enc_clone_mask == 0) + return index_mask; + + for (i = 0; i < xf86_config->num_output; i++) { + clone_output = xf86_config->output[i]; + clone_drmout = clone_output->driver_private; + if (output == clone_output) + continue; + + if (clone_drmout->enc_mask == 0) + continue; + if (drmmode_output->enc_clone_mask == clone_drmout->enc_mask) + index_mask |= (1 << i); + } + return index_mask; +} + + +static void +drmmode_clones_init(ScrnInfoPtr scrn, drmmode_ptr drmmode) +{ + int i, j; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + + for (i = 0; i < xf86_config->num_output; i++) { + xf86OutputPtr output = xf86_config->output[i]; + drmmode_output_private_ptr drmmode_output; + + drmmode_output = output->driver_private; + drmmode_output->enc_clone_mask = 0xff; + /* and all the possible encoder clones for this output together */ + for (j = 0; j < drmmode_output->mode_output->count_encoders; j++) + { + int k; + for (k = 0; k < drmmode->mode_res->count_encoders; k++) { + if (drmmode->mode_res->encoders[k] == drmmode_output->mode_encoders[j]->encoder_id) + drmmode_output->enc_mask |= (1 << k); + } + + drmmode_output->enc_clone_mask &= drmmode_output->mode_encoders[j]->possible_clones; + } + } + + for (i = 0; i < xf86_config->num_output; i++) { + xf86OutputPtr output = xf86_config->output[i]; + output->possible_clones = find_clones(scrn, output); + } +} + +static Bool +drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + drmmode_crtc_private_ptr + drmmode_crtc = xf86_config->crtc[0]->driver_private; + drmmode_ptr drmmode = drmmode_crtc->drmmode; + struct dumb_bo *old_front = NULL; + Bool ret; + ScreenPtr screen = screenInfo.screens[scrn->scrnIndex]; + uint32_t old_fb_id; + int i, pitch, old_width, old_height, old_pitch; + int screen_size; + int cpp = (scrn->bitsPerPixel + 1) / 8; + struct dumb_bo *front_bo; + uint32_t tiling_flags = 0; + PixmapPtr ppix = screen->GetScreenPixmap(screen); + void *new_pixels; + + if (scrn->virtualX == width && scrn->virtualY == height) + return TRUE; + + xf86DrvMsg(scrn->scrnIndex, X_INFO, + "Allocate new frame buffer %dx%d stride %d\n", + width, height, pitch / cpp); + + old_width = scrn->virtualX; + old_height = scrn->virtualY; + old_pitch = scrn->displayWidth; + old_fb_id = drmmode->fb_id; + old_front = drmmode->front_bo; + + drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, scrn->bitsPerPixel); + if (!drmmode->front_bo) + goto fail; + + pitch = drmmode->front_bo->pitch; + + scrn->virtualX = width; + scrn->virtualY = height; + scrn->displayWidth = pitch / cpp; + + ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth, + scrn->bitsPerPixel, pitch, + drmmode->front_bo->handle, + &drmmode->fb_id); + if (ret) + goto fail; + + new_pixels = drmmode_map_front_bo(drmmode); + if (!new_pixels) + goto fail; + + screen->ModifyPixmapHeader(ppix, width, height, -1, -1, + pitch, new_pixels); + +#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,9,99,1,0) + scrn->pixmapPrivate.ptr = ppix->devPrivate.ptr; +#endif + + for (i = 0; i < xf86_config->num_crtc; i++) { + xf86CrtcPtr crtc = xf86_config->crtc[i]; + + if (!crtc->enabled) + continue; + + drmmode_set_mode_major(crtc, &crtc->mode, + crtc->rotation, crtc->x, crtc->y); + } + + if (old_fb_id) { + drmModeRmFB(drmmode->fd, old_fb_id); + dumb_bo_destroy(drmmode->fd, old_front); + } + + return TRUE; + + fail: + if (drmmode->front_bo) + dumb_bo_destroy(drmmode->fd, drmmode->front_bo); + drmmode->front_bo = old_front; + scrn->virtualX = old_width; + scrn->virtualY = old_height; + scrn->displayWidth = old_pitch; + drmmode->fb_id = old_fb_id; + + return FALSE; +} + +static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = { + drmmode_xf86crtc_resize +}; + +Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp) +{ + xf86CrtcConfigPtr xf86_config; + int i, num_dvi = 0, num_hdmi = 0; + + xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs); + xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + + drmmode->scrn = pScrn; + drmmode->cpp = cpp; + drmmode->mode_res = drmModeGetResources(drmmode->fd); + if (!drmmode->mode_res) + return FALSE; + + xf86CrtcSetSizeRange(pScrn, 320, 200, drmmode->mode_res->max_width, drmmode->mode_res->max_height); + for (i = 0; i < drmmode->mode_res->count_crtcs; i++) + if (!xf86IsEntityShared(pScrn->entityList[0]) || pScrn->confScreen->device->screen == i) + drmmode_crtc_init(pScrn, drmmode, i); + + for (i = 0; i < drmmode->mode_res->count_connectors; i++) + drmmode_output_init(pScrn, drmmode, i, &num_dvi, &num_hdmi); + + /* workout clones */ + drmmode_clones_init(pScrn, drmmode); + + xf86InitialConfiguration(pScrn, TRUE); + + return TRUE; +} + +void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct dumb_bo *bo) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + xf86CrtcPtr crtc = xf86_config->crtc[id]; + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + + drmmode_crtc->cursor_bo = bo; +} + +void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + xf86OutputPtr output = config->output[config->compat_output]; + xf86CrtcPtr crtc = output->crtc; + + if (crtc && crtc->enabled) { + drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation, + x, y); + } +} + +Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + int c; + + for (c = 0; c < config->num_crtc; c++) { + xf86CrtcPtr crtc = config->crtc[c]; + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + xf86OutputPtr output = NULL; + int o; + + /* Skip disabled CRTCs */ + if (!crtc->enabled) { + drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, + 0, 0, 0, NULL, 0, NULL); + continue; + } + + if (config->output[config->compat_output]->crtc == crtc) + output = config->output[config->compat_output]; + else + { + for (o = 0; o < config->num_output; o++) + if (config->output[o]->crtc == crtc) + { + output = config->output[o]; + break; + } + } + /* paranoia */ + if (!output) + continue; + + /* Mark that we'll need to re-set the mode for sure */ + memset(&crtc->mode, 0, sizeof(crtc->mode)); + if (!crtc->desiredMode.CrtcHDisplay) + { + DisplayModePtr mode = xf86OutputFindClosestMode (output, pScrn->currentMode); + + if (!mode) + return FALSE; + crtc->desiredMode = *mode; + crtc->desiredRotation = RR_Rotate_0; + crtc->desiredX = 0; + crtc->desiredY = 0; + } + + if (!crtc->funcs->set_mode_major(crtc, &crtc->desiredMode, crtc->desiredRotation, + crtc->desiredX, crtc->desiredY)) + return FALSE; + } + return TRUE; +} + +static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors, + int *indices, LOCO *colors, VisualPtr pVisual) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + uint16_t lut_r[256], lut_g[256], lut_b[256]; + int index, j, i; + int c; + + for (c = 0; c < xf86_config->num_crtc; c++) { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + + for (i = 0 ; i < 256; i++) { + lut_r[i] = drmmode_crtc->lut_r[i] << 6; + lut_g[i] = drmmode_crtc->lut_g[i] << 6; + lut_b[i] = drmmode_crtc->lut_b[i] << 6; + } + + switch(pScrn->depth) { + case 15: + for (i = 0; i < numColors; i++) { + index = indices[i]; + for (j = 0; j < 8; j++) { + lut_r[index * 8 + j] = colors[index].red << 6; + lut_g[index * 8 + j] = colors[index].green << 6; + lut_b[index * 8 + j] = colors[index].blue << 6; + } + } + break; + case 16: + for (i = 0; i < numColors; i++) { + index = indices[i]; + + if (i <= 31) { + for (j = 0; j < 8; j++) { + lut_r[index * 8 + j] = colors[index].red << 6; + lut_b[index * 8 + j] = colors[index].blue << 6; + } + } + + for (j = 0; j < 4; j++) { + lut_g[index * 4 + j] = colors[index].green << 6; + } + } + break; + default: + for (i = 0; i < numColors; i++) { + index = indices[i]; + lut_r[index] = colors[index].red << 6; + lut_g[index] = colors[index].green << 6; + lut_b[index] = colors[index].blue << 6; + } + break; + } + + /* Make the change through RandR */ +#ifdef RANDR_12_INTERFACE + if (crtc->randr_crtc) + RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b); + else +#endif + crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256); + } +} + +Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn) +{ + xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 0, + "Initializing kms color map\n"); + if (!miCreateDefColormap(pScreen)) + return FALSE; + /* all radeons support 10 bit CLUTs */ + if (!xf86HandleColormaps(pScreen, 256, 10, + drmmode_load_palette, NULL, + CMAP_PALETTED_TRUECOLOR +#if 0 /* This option messes up text mode! (eich@suse.de) */ + | CMAP_LOAD_EVEN_IF_OFFSCREEN +#endif + | CMAP_RELOAD_ON_MODE_SWITCH)) + return FALSE; + return TRUE; +} + +#ifdef HAVE_UDEV +static void +drmmode_handle_uevents(int fd, void *closure) +{ + drmmode_ptr drmmode = closure; + ScrnInfoPtr scrn = drmmode->scrn; + struct udev_device *dev; + dev = udev_monitor_receive_device(drmmode->uevent_monitor); + if (!dev) + return; + + RRGetInfo(screenInfo.screens[scrn->scrnIndex], TRUE); + udev_device_unref(dev); +} +#endif + +void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode) +{ +#ifdef HAVE_UDEV + struct udev *u; + struct udev_monitor *mon; + + u = udev_new(); + if (!u) + return; + mon = udev_monitor_new_from_netlink(u, "udev"); + if (!mon) { + udev_unref(u); + return; + } + + if (udev_monitor_filter_add_match_subsystem_devtype(mon, + "drm", + "drm_minor") < 0 || + udev_monitor_enable_receiving(mon) < 0) { + udev_monitor_unref(mon); + udev_unref(u); + return; + } + + drmmode->uevent_handler = + xf86AddGeneralHandler(udev_monitor_get_fd(mon), + drmmode_handle_uevents, + drmmode); + + drmmode->uevent_monitor = mon; +#endif +} + +void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode) +{ +#ifdef HAVE_UDEV + if (drmmode->uevent_handler) { + struct udev *u = udev_monitor_get_udev(drmmode->uevent_monitor); + xf86RemoveGeneralHandler(drmmode->uevent_handler); + + udev_monitor_unref(drmmode->uevent_monitor); + udev_unref(u); + } +#endif +} + +/* create front and cursor BOs */ +Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + int width; + int height; + int bpp; + int i; + + width = pScrn->virtualX; + height = pScrn->virtualY; + bpp = pScrn->bitsPerPixel; + drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp); + if (!drmmode->front_bo) + return FALSE; + + + width = height = 64; + bpp = 32; + for (i = 0; i < xf86_config->num_crtc; i++) { + xf86CrtcPtr crtc = xf86_config->crtc[i]; + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + drmmode_crtc->cursor_bo = dumb_bo_create(drmmode->fd, width, height, bpp); + } + return TRUE; +} + +void *drmmode_map_front_bo(drmmode_ptr drmmode) +{ + int ret; + + if (drmmode->front_bo->ptr) + return drmmode->front_bo->ptr; + + ret = dumb_bo_map(drmmode->fd, drmmode->front_bo); + if (ret) + return NULL; + + return drmmode->front_bo->ptr; + +} + +Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + int i, ret; + for (i = 0; i < xf86_config->num_crtc; i++) { + xf86CrtcPtr crtc = xf86_config->crtc[i]; + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + ret = dumb_bo_map(drmmode->fd, drmmode_crtc->cursor_bo); + if (ret) + return FALSE; + } + return TRUE; +} + +void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + int i; + dumb_bo_destroy(drmmode->fd, drmmode->front_bo); + drmmode->front_bo = NULL; + + for (i = 0; i < xf86_config->num_crtc; i++) { + xf86CrtcPtr crtc = xf86_config->crtc[i]; + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo); + } +} diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h new file mode 100644 index 000000000..2d7250568 --- /dev/null +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -0,0 +1,125 @@ +/* + * Copyright © 2007 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Authors: + * Dave Airlie + * + */ +#ifndef DRMMODE_DISPLAY_H +#define DRMMODE_DISPLAY_H + +#include "xf86drmMode.h" +#ifdef HAVE_UDEV +#include "libudev.h" +#endif + +struct dumb_bo { + uint32_t handle; + uint32_t size; + void *ptr; + int map_count; + uint32_t pitch; +}; + +typedef struct { + int fd; + unsigned fb_id; + drmModeResPtr mode_res; + drmModeFBPtr mode_fb; + int cpp; + ScrnInfoPtr scrn; +#ifdef HAVE_UDEV + struct udev_monitor *uevent_monitor; + InputHandlerProc uevent_handler; +#endif + drmEventContext event_context; + struct dumb_bo *front_bo; +} drmmode_rec, *drmmode_ptr; + +typedef struct { + drmmode_ptr drmmode; + unsigned old_fb_id; + int flip_count; + void *event_data; + unsigned int fe_frame; + unsigned int fe_tv_sec; + unsigned int fe_tv_usec; +} drmmode_flipdata_rec, *drmmode_flipdata_ptr; + +typedef struct { + drmmode_flipdata_ptr flipdata; + Bool dispatch_me; +} drmmode_flipevtcarrier_rec, *drmmode_flipevtcarrier_ptr; + +typedef struct { + drmmode_ptr drmmode; + drmModeCrtcPtr mode_crtc; + int hw_id; + struct dumb_bo *cursor_bo; + // struct radeon_bo *rotate_bo; + unsigned rotate_fb_id; + uint16_t lut_r[256], lut_g[256], lut_b[256]; +} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; + +typedef struct { + drmModePropertyPtr mode_prop; + uint64_t value; + int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */ + Atom *atoms; +} drmmode_prop_rec, *drmmode_prop_ptr; + + +typedef struct { + drmmode_ptr drmmode; + int output_id; + drmModeConnectorPtr mode_output; + drmModeEncoderPtr *mode_encoders; + drmModePropertyBlobPtr edid_blob; + int dpms_enum_id; + int num_props; + drmmode_prop_ptr props; + int enc_mask; + int enc_clone_mask; +} drmmode_output_private_rec, *drmmode_output_private_ptr; + + +extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); +//extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, struct radeon_bo_manager *bufmgr); +//extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo); +void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags); +extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode); +extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode); +extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); + +extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode); +extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode); + +extern int drmmode_get_height_align(ScrnInfoPtr scrn, uint32_t tiling); +extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling); +extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling); + +//Bool radeon_do_pageflip(ScrnInfoPtr scrn, struct radeon_bo *new_front, void *data, int ref_crtc_hw_id); +Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); +void *drmmode_map_front_bo(drmmode_ptr drmmode); +Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); +void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); +#endif diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c deleted file mode 100644 index 1f95a2f1c..000000000 --- a/hw/xfree86/drivers/modesetting/output.c +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DPMS_SERVER -#include - -#include "X11/Xatom.h" - -#include "driver.h" - -static char *connector_enum_list[] = { - "Unknown", - "VGA", - "DVI-I", - "DVI-D", - "DVI-A", - "Composite", - "SVIDEO", - "LVDS", - "Component", - "9-pin DIN", - "DisplayPort", - "HDMI Type A", - "HDMI Type B", -}; - -static void -dpms(xf86OutputPtr output, int mode) -{ -} - -static void -save(xf86OutputPtr output) -{ -} - -static void -restore(xf86OutputPtr output) -{ -} - -static int -mode_valid(xf86OutputPtr output, DisplayModePtr pMode) -{ - return MODE_OK; -} - -static Bool -mode_fixup(xf86OutputPtr output, DisplayModePtr mode, - DisplayModePtr adjusted_mode) -{ - return TRUE; -} - -static void -prepare(xf86OutputPtr output) -{ - dpms(output, DPMSModeOff); -} - -static void -mode_set(xf86OutputPtr output, DisplayModePtr mode, - DisplayModePtr adjusted_mode) -{ -} - -static void -commit(xf86OutputPtr output) -{ - dpms(output, DPMSModeOn); - - if (output->scrn->pScreen != NULL) - xf86_reload_cursors(output->scrn->pScreen); -} - -static xf86OutputStatus -detect(xf86OutputPtr output) -{ - drmModeConnectorPtr drm_connector = output->driver_private; - - switch (drm_connector->connection) { - case DRM_MODE_CONNECTED: - return XF86OutputStatusConnected; - case DRM_MODE_DISCONNECTED: - return XF86OutputStatusDisconnected; - default: - return XF86OutputStatusUnknown; - } -} - -static DisplayModePtr -get_modes(xf86OutputPtr output) -{ - drmModeConnectorPtr drm_connector = output->driver_private; - struct drm_mode_modeinfo *drm_mode = NULL; - DisplayModePtr modes = NULL, mode = NULL; - int i; - - for (i = 0; i < drm_connector->count_modes; i++) { - drm_mode = &drm_connector->modes[i]; - if (drm_mode) { - mode = xcalloc(1, sizeof(DisplayModeRec)); - if (!mode) - continue; - mode->type = 0; - mode->Clock = drm_mode->clock; - mode->HDisplay = drm_mode->hdisplay; - mode->HSyncStart = drm_mode->hsync_start; - mode->HSyncEnd = drm_mode->hsync_end; - mode->HTotal = drm_mode->htotal; - mode->VDisplay = drm_mode->vdisplay; - mode->VSyncStart = drm_mode->vsync_start; - mode->VSyncEnd = drm_mode->vsync_end; - mode->VTotal = drm_mode->vtotal; - mode->Flags = drm_mode->flags; - mode->HSkew = drm_mode->hskew; - mode->VScan = drm_mode->vscan; - mode->VRefresh = xf86ModeVRefresh(mode); - mode->Private = (void *)drm_mode; - xf86SetModeDefaultName(mode); - modes = xf86ModesAdd(modes, mode); - xf86PrintModeline(0, mode); - } - } - - return modes; -} - -static void -destroy(xf86OutputPtr output) -{ - drmModeFreeConnector(output->driver_private); -} - -static void -create_resources(xf86OutputPtr output) -{ -#ifdef RANDR_12_INTERFACE -#endif /* RANDR_12_INTERFACE */ -} - -#ifdef RANDR_12_INTERFACE -static Bool -set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value) -{ - return TRUE; -} -#endif /* RANDR_12_INTERFACE */ - -#ifdef RANDR_13_INTERFACE -static Bool -get_property(xf86OutputPtr output, Atom property) -{ - return TRUE; -} -#endif /* RANDR_13_INTERFACE */ - -#ifdef RANDR_GET_CRTC_INTERFACE -static xf86CrtcPtr -get_crtc(xf86OutputPtr output) -{ - return NULL; -} -#endif - -static const xf86OutputFuncsRec output_funcs = { - .create_resources = create_resources, - .dpms = dpms, - .save = save, - .restore = restore, - .mode_valid = mode_valid, - .mode_fixup = mode_fixup, - .prepare = prepare, - .mode_set = mode_set, - .commit = commit, - .detect = detect, - .get_modes = get_modes, -#ifdef RANDR_12_INTERFACE - .set_property = set_property, -#endif -#ifdef RANDR_13_INTERFACE - .get_property = get_property, -#endif - .destroy = destroy, -#ifdef RANDR_GET_CRTC_INTERFACE - .get_crtc = get_crtc, -#endif -}; - -void -output_init(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - xf86OutputPtr output; - drmModeResPtr res; - drmModeConnectorPtr drm_connector = NULL; - drmModeEncoderPtr drm_encoder = NULL; - drmModeCrtcPtr crtc; - char *name; - int c, v, p; - - res = drmModeGetResources(ms->fd); - if (res == 0) { - DRV_ERROR("Failed drmModeGetResources\n"); - return; - } - - for (c = 0; c < res->count_connectors; c++) { - drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]); - if (!drm_connector) - goto out; - - for (p = 0; p < drm_connector->count_props; p++) { - drmModePropertyPtr prop; - - prop = drmModeGetProperty(ms->fd, drm_connector->props[p]); - - name = NULL; - if (prop) { - ErrorF("VALUES %d\n", prop->count_values); - - for (v = 0; v < prop->count_values; v++) - ErrorF("%s %lld\n", prop->name, prop->values[v]); - } - } - - name = connector_enum_list[drm_connector->connector_type]; - - output = xf86OutputCreate(pScrn, &output_funcs, name); - if (!output) - continue; - - drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]); - if (drm_encoder) { - output->possible_crtcs = drm_encoder->crtcs; - output->possible_clones = drm_encoder->clones; - } else { - output->possible_crtcs = 0; - output->possible_clones = 0; - } - output->driver_private = drm_connector; - output->subpixel_order = SubPixelHorizontalRGB; - output->interlaceAllowed = FALSE; - output->doubleScanAllowed = FALSE; - } - - out: - drmModeFreeResources(res); -} From a77fae850511c4d73af2af2b88804586f950f28d Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 11:52:51 +0100 Subject: [PATCH 020/122] cleanup some the drmmode_display header file --- .../drivers/modesetting/drmmode_display.h | 54 ++++++------------- 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index 2d7250568..845207a67 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -33,49 +33,33 @@ #endif struct dumb_bo { - uint32_t handle; - uint32_t size; - void *ptr; - int map_count; - uint32_t pitch; + uint32_t handle; + uint32_t size; + void *ptr; + int map_count; + uint32_t pitch; }; typedef struct { - int fd; - unsigned fb_id; - drmModeResPtr mode_res; - drmModeFBPtr mode_fb; - int cpp; - ScrnInfoPtr scrn; + int fd; + unsigned fb_id; + drmModeResPtr mode_res; + drmModeFBPtr mode_fb; + int cpp; + ScrnInfoPtr scrn; #ifdef HAVE_UDEV - struct udev_monitor *uevent_monitor; - InputHandlerProc uevent_handler; + struct udev_monitor *uevent_monitor; + InputHandlerProc uevent_handler; #endif - drmEventContext event_context; - struct dumb_bo *front_bo; + drmEventContext event_context; + struct dumb_bo *front_bo; } drmmode_rec, *drmmode_ptr; -typedef struct { - drmmode_ptr drmmode; - unsigned old_fb_id; - int flip_count; - void *event_data; - unsigned int fe_frame; - unsigned int fe_tv_sec; - unsigned int fe_tv_usec; -} drmmode_flipdata_rec, *drmmode_flipdata_ptr; - -typedef struct { - drmmode_flipdata_ptr flipdata; - Bool dispatch_me; -} drmmode_flipevtcarrier_rec, *drmmode_flipevtcarrier_ptr; - typedef struct { drmmode_ptr drmmode; drmModeCrtcPtr mode_crtc; int hw_id; struct dumb_bo *cursor_bo; - // struct radeon_bo *rotate_bo; unsigned rotate_fb_id; uint16_t lut_r[256], lut_g[256], lut_b[256]; } drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; @@ -103,21 +87,13 @@ typedef struct { extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); -//extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, struct radeon_bo_manager *bufmgr); -//extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo); void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags); extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode); -extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode); extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode); extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode); -extern int drmmode_get_height_align(ScrnInfoPtr scrn, uint32_t tiling); -extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling); -extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling); - -//Bool radeon_do_pageflip(ScrnInfoPtr scrn, struct radeon_bo *new_front, void *data, int ref_crtc_hw_id); Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); void *drmmode_map_front_bo(drmmode_ptr drmmode); Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); From a72bdf170c8bc55eef3d2dbb8e316839552288a5 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 12:28:59 +0100 Subject: [PATCH 021/122] modesetting: rewrite probing based on fbdev. This isn't perfect, it should really do more with bus id matching and finding the write drm device using sysfs if it can. but it removes lots of hardcoding of pci ids. --- hw/xfree86/drivers/modesetting/driver.c | 223 ++++++++++-------------- 1 file changed, 90 insertions(+), 133 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 47ffb07b7..be781bc72 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -31,6 +31,7 @@ #include "config.h" #endif +#include #include "xf86.h" #include "xf86_OSproc.h" #include "compiler.h" @@ -68,18 +69,19 @@ static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv); static Bool PreInit(ScrnInfoPtr pScrn, int flags); -#if XSERVER_LIBPCIACCESS -static Bool -pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data); -#else static Bool Probe(DriverPtr drv, int flags); -#endif +static Bool ms_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, + intptr_t match_data); -#if XSERVER_LIBPCIACCESS -static const struct pci_id_match device_match[] = { - {0x8086, 0x0046, 0xffff, 0xffff, 0, 0, 0}, - {0, 0, 0}, +#ifdef XSERVER_LIBPCIACCESS +static const struct pci_id_match ms_device_match[] = { + { + PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, + 0x00030000, 0x00ffffff, 0 + }, + + { 0, 0, 0 }, }; #endif @@ -87,38 +89,29 @@ _X_EXPORT DriverRec modesetting = { 1, "modesetting", Identify, -#if XSERVER_LIBPCIACCESS - NULL, -#else Probe, -#endif AvailableOptions, NULL, 0, NULL, -#if XSERVER_LIBPCIACCESS - device_match, - pci_probe -#endif + ms_device_match, + ms_pci_probe, }; static SymTabRec Chipsets[] = { - {0x0046, "Intel Graphics Device"}, + {0, "kms" }, {-1, NULL} }; -static PciChipsets PciDevices[] = { - {0x2592, 0x0046, RES_SHARED_VGA}, - {-1, -1, RES_UNDEFINED} -}; - typedef enum { OPTION_SW_CURSOR, + OPTION_DEVICE_PATH, } modesettingOpts; static const OptionInfoRec Options[] = { {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE }, {-1, NULL, OPTV_NONE, {0}, FALSE} }; @@ -171,6 +164,27 @@ Identify(int flags) Chipsets); } +static Bool probe_hw(char *dev) +{ + int fd; + if (dev) + fd = open(dev, O_RDWR, 0); + else { + dev = getenv("KMSDEVICE"); + if ((NULL == dev) || ((fd = open(dev, O_RDWR, 0)) == -1)) { + dev = "/dev/dri/card0"; + fd = open(dev,O_RDWR, 0); + } + } + if (fd == -1) { + xf86DrvMsg(-1, X_ERROR,"open %s: %s\n", dev, strerror(errno)); + return FALSE; + } + close(fd); + return TRUE; + +} + static const OptionInfoRec * AvailableOptions(int chipid, int busid) { @@ -179,25 +193,26 @@ AvailableOptions(int chipid, int busid) #if XSERVER_LIBPCIACCESS static Bool -pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) +ms_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *dev, intptr_t match_data) { ScrnInfoPtr scrn = NULL; EntityInfoPtr entity; DevUnion *private; - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices, + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL, NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "modesetting"; - scrn->name = "modesetting"; - scrn->Probe = NULL; + if (scrn) { + char *devpath; + GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0], + scrn->entityInstanceList[0]); - entity = xf86GetEntityInfo(entity_num); - - switch (device->device_id) { - case 0x0046: + devpath = xf86FindOptionValue(devSection->options, "kmsdev"); + if (probe_hw(devpath)) { + scrn->driverVersion = 1; + scrn->driverName = "modesetting"; + scrn->name = "modeset"; + scrn->Probe = NULL; scrn->PreInit = PreInit; scrn->ScreenInit = ScreenInit; scrn->SwitchMode = SwitchMode; @@ -206,12 +221,19 @@ pci_probe(DriverPtr driver, scrn->LeaveVT = LeaveVT; scrn->FreeScreen = FreeScreen; scrn->ValidMode = ValidMode; - break; - } + + xf86DrvMsg(scrn->scrnIndex, X_CONFIG, + "claimed PCI slot %d@%d:%d:%d\n", + dev->bus, dev->domain, dev->dev, dev->func); + xf86DrvMsg(scrn->scrnIndex, X_INFO, + "using %s\n", devpath ? devpath : "default device"); + } else + scrn = NULL; } return scrn != NULL; } -#else +#endif + static Bool Probe(DriverPtr drv, int flags) { @@ -220,9 +242,13 @@ Probe(DriverPtr drv, int flags) DevUnion *pPriv; GDevPtr *devSections; Bool foundScreen = FALSE; - pciVideoPtr *VideoInfo; - pciVideoPtr *ppPci; int numDevs; + char *dev; + ScrnInfoPtr scrn; + + /* For now, just bail out for PROBE_DETECT. */ + if (flags & PROBE_DETECT) + return FALSE; /* * Find the config file Device sections that match this @@ -232,110 +258,41 @@ Probe(DriverPtr drv, int flags) return FALSE; } - /* - * This probing is just checking the PCI data the server already - * collected. - */ - if (!(VideoInfo = xf86GetPciVideoInfo())) - return FALSE; + for (i = 0; i < numDevSections; i++) { -#if 0 - numUsed = 0; - for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) { - for (numDevs = 0; numDevs < numDevSections; numDevs++) { - if (devSections[numDevs]->busID && *devSections[numDevs]->busID) { - if (xf86ComparePciBusString - (devSections[numDevs]->busID, (*ppPci)->bus, - (*ppPci)->device, (*ppPci)->func)) { - /* Claim slot */ - if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device, - (*ppPci)->func)) { - usedChips[numUsed++] = - xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device, - (*ppPci)->func, drv, - (*ppPci)->chipType, NULL, TRUE); - ErrorF("CLAIMED %d %d %d\n", (*ppPci)->bus, - (*ppPci)->device, (*ppPci)->func); - } - } + dev = xf86FindOptionValue(devSections[i]->options,"kmsdev"); + if (devSections[i]->busID) { + if (probe_hw(dev)) { + int entity; + entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE); + scrn = xf86ConfigFbEntity(scrn, 0, entity, + NULL, NULL, NULL, NULL); } - } - } -#else - /* Look for Intel i8xx devices. */ - numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL, - Chipsets, PciDevices, - devSections, numDevSections, - drv, &usedChips); -#endif - if (flags & PROBE_DETECT) { - if (numUsed > 0) - foundScreen = TRUE; - } else { - for (i = 0; i < numUsed; i++) { - ScrnInfoPtr pScrn = NULL; - - /* Allocate new ScrnInfoRec and claim the slot */ - if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i], - PciDevices, NULL, NULL, NULL, - NULL, NULL))) { - EntityInfoPtr pEnt; - - pEnt = xf86GetEntityInfo(usedChips[i]); - - pScrn->driverVersion = 1; - pScrn->driverName = "modesetting"; - pScrn->name = "modesetting"; - pScrn->Probe = Probe; + if (scrn) foundScreen = TRUE; - { - /* Allocate an entity private if necessary */ - if (modesettingEntityIndex < 0) - modesettingEntityIndex = - xf86AllocateEntityPrivateIndex(); + scrn->driverVersion = 1; + scrn->driverName = "modesetting"; + scrn->name = "modesetting"; + scrn->Probe = Probe; + scrn->PreInit = PreInit; + scrn->ScreenInit = ScreenInit; + scrn->SwitchMode = SwitchMode; + scrn->AdjustFrame = AdjustFrame; + scrn->EnterVT = EnterVT; + scrn->LeaveVT = LeaveVT; + scrn->FreeScreen = FreeScreen; + scrn->ValidMode = ValidMode; - pPriv = xf86GetEntityPrivate(pScrn->entityList[0], - modesettingEntityIndex); - if (!pPriv->ptr) { - pPriv->ptr = xnfcalloc(sizeof(EntRec), 1); - msEnt = pPriv->ptr; - msEnt->lastInstance = -1; - } else { - msEnt = pPriv->ptr; - } - - /* - * Set the entity instance for this instance of the driver. - * For dual head per card, instance 0 is the "master" - * instance, driving the primary head, and instance 1 is - * the "slave". - */ - msEnt->lastInstance++; - xf86SetEntityInstanceForScreen(pScrn, - pScrn->entityList[0], - msEnt->lastInstance); - pScrn->PreInit = PreInit; - pScrn->ScreenInit = ScreenInit; - pScrn->SwitchMode = SwitchMode; - pScrn->AdjustFrame = AdjustFrame; - pScrn->EnterVT = EnterVT; - pScrn->LeaveVT = LeaveVT; - pScrn->FreeScreen = FreeScreen; - pScrn->ValidMode = ValidMode; - break; - } - } else - ErrorF("FAILED PSCRN\n"); + xf86DrvMsg(scrn->scrnIndex, X_INFO, + "using %s\n", dev ? dev : "default device"); } } - free(usedChips); free(devSections); return foundScreen; } -#endif static Bool GetRec(ScrnInfoPtr pScrn) From 263597dbb3a75d711b5ad2e1f51554e6b2601d9a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 12:30:46 +0100 Subject: [PATCH 022/122] gut some more unneeded code --- hw/xfree86/drivers/modesetting/driver.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index be781bc72..9bb1cb48e 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -638,24 +638,6 @@ static void LeaveVT(int scrnIndex, int flags) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; - modesettingPtr ms = modesettingPTR(pScrn); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int o; - - for (o = 0; o < config->num_crtc; o++) { - xf86CrtcPtr crtc = config->crtc[o]; - - // cursor_destroy(crtc); - - if (crtc->rotatedPixmap || crtc->rotatedData) { - crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, - crtc->rotatedData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - } - - drmModeRmFB(ms->fd, ms->fb_id); pScrn->vtSema = FALSE; } From 1b1382c9e1995dcfe5dfec1de17155fa627ac6e8 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 12:34:17 +0100 Subject: [PATCH 023/122] update authors/copyright --- hw/xfree86/drivers/modesetting/driver.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 9bb1cb48e..dee9cff21 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -1,5 +1,6 @@ /* * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2011 Dave Airlie * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -23,7 +24,8 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * - * Author: Alan Hourihane + * Original Author: Alan Hourihane + * Rewrite: Dave Airlie * */ From 4d3aadb22fc03f259a9d1717b55ce16d7a32e2be Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 12:34:27 +0100 Subject: [PATCH 024/122] drop loading dri2 --- hw/xfree86/drivers/modesetting/driver.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index dee9cff21..0aaafd18a 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -462,10 +462,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) return FALSE; } -#ifdef DRI2 - xf86LoadSubModule(pScrn, "dri2"); -#endif - return TRUE; fail: return FALSE; From 7847321138be62b929123b25929a69f0a57aca3f Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 12:38:26 +0100 Subject: [PATCH 025/122] port damage tracking code from st/xorg --- hw/xfree86/drivers/modesetting/driver.c | 75 ++++++++++++++++++++++++- hw/xfree86/drivers/modesetting/driver.h | 6 +- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 0aaafd18a..bc80e3098 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -307,6 +307,58 @@ GetRec(ScrnInfoPtr pScrn) return TRUE; } +static void dispatch_dirty(ScreenPtr pScreen) +{ + ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(scrn); + RegionPtr dirty = DamageRegion(ms->damage); + unsigned num_cliprects = REGION_NUM_RECTS(dirty); + + if (num_cliprects) { + drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip)); + BoxPtr rect = REGION_RECTS(dirty); + int i, ret; + + /* XXX no need for copy? */ + for (i = 0; i < num_cliprects; i++, rect++) { + clip[i].x1 = rect->x1; + clip[i].y1 = rect->y1; + clip[i].x2 = rect->x2; + clip[i].y2 = rect->y2; + } + + /* TODO query connector property to see if this is needed */ + ret = drmModeDirtyFB(ms->fd, ms->fb_id, clip, num_cliprects); + if (ret) { + if (ret == -EINVAL) { + ms->dirty_enabled = FALSE; + DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage); + DamageDestroy(ms->damage); + ms->damage = NULL; + xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n"); + return; + } else + ErrorF("%s: failed to send dirty (%i, %s)\n", + __func__, ret, strerror(-ret)); + } + + DamageEmpty(ms->damage); + } +} + +static void msBlockHandler(int i, pointer blockData, pointer pTimeout, + pointer pReadmask) +{ + ScreenPtr pScreen = screenInfo.screens[i]; + modesettingPtr ms = modesettingPTR(xf86Screens[pScreen->myNum]); + + pScreen->BlockHandler = ms->BlockHandler; + pScreen->BlockHandler(i, blockData, pTimeout, pReadmask); + pScreen->BlockHandler = msBlockHandler; + if (ms->dirty_enabled) + dispatch_dirty(pScreen); +} + static void FreeRec(ScrnInfoPtr pScrn) { @@ -494,6 +546,18 @@ CreateScreenResources(ScreenPtr pScreen) if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels)) FatalError("Couldn't adjust screen pixmap\n"); + ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE, + pScreen, rootPixmap); + + if (ms->damage) { + DamageRegister(&rootPixmap->drawable, ms->damage); + ms->dirty_enabled = TRUE; + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Damage tracking initialized\n"); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed to create screen damage record\n"); + return FALSE; + } return ret; } @@ -596,6 +660,9 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) ms->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = CloseScreen; + ms->BlockHandler = pScreen->BlockHandler; + pScreen->BlockHandler = msBlockHandler; + if (!xf86CrtcScreenInit(pScreen)) return FALSE; @@ -669,6 +736,12 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; modesettingPtr ms = modesettingPTR(pScrn); + if (ms->damage) { + DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage); + DamageDestroy(ms->damage); + ms->damage = NULL; + } + drmmode_uevent_fini(pScrn, &ms->drmmode); drmmode_free_bos(pScrn, &ms->drmmode); @@ -678,7 +751,7 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) } pScreen->CreateScreenResources = ms->createScreenResources; - + pScreen->BlockHandler = ms->BlockHandler; drmClose(ms->fd); ms->fd = -1; diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index 255dedef1..beb5f8daf 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -30,6 +30,7 @@ #include #include #include +#include #include "drmmode_display.h" #define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg); @@ -68,10 +69,13 @@ typedef struct _modesettingRec unsigned int SaveGeneration; CreateScreenResourcesProcPtr createScreenResources; - + ScreenBlockHandlerProcPtr BlockHandler; void *driver; drmmode_rec drmmode; + + DamagePtr damage; + Bool dirty_enabled; } modesettingRec, *modesettingPtr; #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) From a4f6e661b5d6662c413c86eeefb4affddd65c562 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 14:05:43 +0100 Subject: [PATCH 026/122] fix server recycling --- hw/xfree86/drivers/modesetting/driver.c | 38 +++++++------------ .../drivers/modesetting/drmmode_display.c | 6 +++ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index bc80e3098..b56db9434 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -570,31 +570,17 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) unsigned long sys_mem; int c; MessageType from; + int ret; - /* deal with server regeneration */ - if (ms->fd < 0) { - char *BusID; - - BusID = malloc(64); - sprintf(BusID, "PCI:%d:%d:%d", -#if XSERVER_LIBPCIACCESS - ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), - ms->PciInfo->dev, ms->PciInfo->func -#else - ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum -#endif - ); - - ms->fd = drmOpen(NULL, BusID); - - if (ms->fd < 0) - return FALSE; - } - + ErrorF("ms is %p\n", ms); pScrn->pScreen = pScreen; + ret = drmSetMaster(ms->fd); + if (ret) { + ErrorF("Unable to set master\n"); + return FALSE; + } + /* HW dependent - FIXME */ pScrn->displayWidth = pScrn->virtualX; if (!drmmode_create_initial_bos(pScrn, &ms->drmmode)) @@ -716,7 +702,9 @@ EnterVT(int scrnIndex, int flags) ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; modesettingPtr ms = modesettingPTR(pScrn); - if (!xf86SetDesiredModes(pScrn)) + pScrn->vtSema = TRUE; + + if (!drmmode_set_desired_modes(pScrn, &ms->drmmode)) return FALSE; return TRUE; @@ -752,8 +740,8 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) pScreen->CreateScreenResources = ms->createScreenResources; pScreen->BlockHandler = ms->BlockHandler; - drmClose(ms->fd); - ms->fd = -1; + + drmDropMaster(ms->fd); pScrn->vtSema = FALSE; pScreen->CloseScreen = ms->CloseScreen; diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index d94ce03e0..4f25bbe0e 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -1329,6 +1329,12 @@ void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) { xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); int i; + + if (drmmode->fb_id) { + drmModeRmFB(drmmode->fd, drmmode->fb_id); + drmmode->fb_id = 0; + } + dumb_bo_destroy(drmmode->fd, drmmode->front_bo); drmmode->front_bo = NULL; From d686130c17126d86db55aae6b65b12d8bcf6a098 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 14:13:58 +0100 Subject: [PATCH 027/122] add -Wall, cleanup warnings --- hw/xfree86/drivers/modesetting/driver.c | 22 ++++--------------- .../drivers/modesetting/drmmode_display.c | 20 +++++------------ 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index b56db9434..d1348c90a 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -33,6 +33,7 @@ #include "config.h" #endif +#include #include #include "xf86.h" #include "xf86_OSproc.h" @@ -199,8 +200,6 @@ ms_pci_probe(DriverPtr driver, int entity_num, struct pci_device *dev, intptr_t match_data) { ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - DevUnion *private; scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL, NULL, NULL, NULL, NULL, NULL); @@ -239,14 +238,11 @@ ms_pci_probe(DriverPtr driver, static Bool Probe(DriverPtr drv, int flags) { - int i, numUsed, numDevSections, *usedChips; - EntPtr msEnt = NULL; - DevUnion *pPriv; + int i, numDevSections; GDevPtr *devSections; Bool foundScreen = FALSE; - int numDevs; char *dev; - ScrnInfoPtr scrn; + ScrnInfoPtr scrn = NULL; /* For now, just bail out for PROBE_DETECT. */ if (flags & PROBE_DETECT) @@ -268,7 +264,7 @@ Probe(DriverPtr drv, int flags) int entity; entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE); scrn = xf86ConfigFbEntity(scrn, 0, entity, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL); } if (scrn) @@ -376,17 +372,11 @@ FreeRec(ScrnInfoPtr pScrn) static Bool PreInit(ScrnInfoPtr pScrn, int flags) { - xf86CrtcConfigPtr xf86_config; modesettingPtr ms; - MessageType from = X_PROBED; rgb defaultWeight = { 0, 0, 0 }; EntityInfoPtr pEnt; EntPtr msEnt = NULL; char *BusID; - int i; - char *s; - int num_pipe; - int max_width, max_height; if (pScrn->numEntities != 1) return FALSE; @@ -526,7 +516,6 @@ CreateScreenResources(ScreenPtr pScreen) modesettingPtr ms = modesettingPTR(pScrn); PixmapPtr rootPixmap; Bool ret; - int flags; void *pixels; pScreen->CreateScreenResources = ms->createScreenResources; ret = pScreen->CreateScreenResources(pScreen); @@ -567,9 +556,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); VisualPtr visual; - unsigned long sys_mem; - int c; - MessageType from; int ret; ErrorF("ms is %p\n", ms); diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 4f25bbe0e..375170f85 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -108,11 +108,13 @@ static int dumb_bo_map(int fd, struct dumb_bo *bo) return 0; } +#if 0 static int dumb_bo_unmap(int fd, struct dumb_bo *bo) { bo->map_count--; return 0; } +#endif static int dumb_bo_destroy(int fd, struct dumb_bo *bo) { @@ -260,7 +262,6 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, int x, int y) { ScrnInfoPtr pScrn = crtc->scrn; - // RADEONInfoPtr info = RADEONPTR(pScrn); xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; drmmode_ptr drmmode = drmmode_crtc->drmmode; @@ -273,11 +274,8 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, int i; int fb_id; drmModeModeInfo kmode; - int pitch; - uint32_t tiling_flags = 0; int height; - pitch = pScrn->displayWidth; height = pScrn->virtualY; if (drmmode->fb_id == 0) { @@ -795,7 +793,6 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv drmModePropertyPtr props; char name[32]; int i; - const char *s; koutput = drmModeGetConnector(drmmode->fd, drmmode->mode_res->connectors[num]); if (!koutput) @@ -938,10 +935,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) ScreenPtr screen = screenInfo.screens[scrn->scrnIndex]; uint32_t old_fb_id; int i, pitch, old_width, old_height, old_pitch; - int screen_size; int cpp = (scrn->bitsPerPixel + 1) / 8; - struct dumb_bo *front_bo; - uint32_t tiling_flags = 0; PixmapPtr ppix = screen->GetScreenPixmap(screen); void *new_pixels; @@ -949,12 +943,12 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) return TRUE; xf86DrvMsg(scrn->scrnIndex, X_INFO, - "Allocate new frame buffer %dx%d stride %d\n", - width, height, pitch / cpp); + "Allocate new frame buffer %dx%d stride\n", + width, height); old_width = scrn->virtualX; old_height = scrn->virtualY; - old_pitch = scrn->displayWidth; + old_pitch = drmmode->front_bo->pitch; old_fb_id = drmmode->fb_id; old_front = drmmode->front_bo; @@ -1009,7 +1003,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) drmmode->front_bo = old_front; scrn->virtualX = old_width; scrn->virtualY = old_height; - scrn->displayWidth = old_pitch; + scrn->displayWidth = old_pitch / cpp; drmmode->fb_id = old_fb_id; return FALSE; @@ -1021,11 +1015,9 @@ static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = { Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp) { - xf86CrtcConfigPtr xf86_config; int i, num_dvi = 0, num_hdmi = 0; xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs); - xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); drmmode->scrn = pScrn; drmmode->cpp = cpp; From 0b5e574dff230c7879eb9655bb7252553bbace50 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 15:55:24 +0100 Subject: [PATCH 028/122] remove unused debug --- hw/xfree86/drivers/modesetting/driver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index d1348c90a..119287840 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -558,7 +558,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) VisualPtr visual; int ret; - ErrorF("ms is %p\n", ms); pScrn->pScreen = pScreen; ret = drmSetMaster(ms->fd); From 1f37991dec98073d5dfbf0c30213f838999bd9da Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 15:55:36 +0100 Subject: [PATCH 029/122] add shadowfb support, default to on. we should probably expose a bit from kernel to say if shadow is preferred or wasteful. --- hw/xfree86/drivers/modesetting/driver.c | 62 +++++++++++++++++++++++++ hw/xfree86/drivers/modesetting/driver.h | 2 + 2 files changed, 64 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 119287840..bde690c7a 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -49,6 +49,7 @@ #include "xf86Crtc.h" #include "miscstruct.h" #include "dixstruct.h" +#include "shadow.h" #include "xf86xv.h" #include #include @@ -110,11 +111,13 @@ typedef enum { OPTION_SW_CURSOR, OPTION_DEVICE_PATH, + OPTION_SHADOW_FB, } modesettingOpts; static const OptionInfoRec Options[] = { {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE}, {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE }, + {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE }, {-1, NULL, OPTV_NONE, {0}, FALSE} }; @@ -472,6 +475,8 @@ PreInit(ScrnInfoPtr pScrn, int flags) ms->SWCursor = TRUE; } + ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, TRUE); + ms->drmmode.fd = ms->fd; if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n"); @@ -504,11 +509,31 @@ PreInit(ScrnInfoPtr pScrn, int flags) return FALSE; } + if (ms->shadow_enable) { + if (!xf86LoadSubModule(pScrn, "shadow")) { + return FALSE; + } + } + return TRUE; fail: return FALSE; } +static void * +msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode, + CARD32 *size, void *closure) +{ + ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + int stride; + + stride = (pScrn->displayWidth * pScrn->bitsPerPixel) / 8; + *size = stride; + + return ((uint8_t *)ms->drmmode.front_bo->ptr + row * stride + offset); +} + static Bool CreateScreenResources(ScreenPtr pScreen) { @@ -532,9 +557,19 @@ CreateScreenResources(ScreenPtr pScreen) return FALSE; rootPixmap = pScreen->GetScreenPixmap(pScreen); + + if (ms->shadow_enable) + pixels = ms->shadow_fb; + if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels)) FatalError("Couldn't adjust screen pixmap\n"); + if (ms->shadow_enable) { + if (!shadowAdd(pScreen, rootPixmap, shadowUpdatePackedWeak(), + msShadowWindow, 0, 0)) + return FALSE; + } + ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE, pScreen, rootPixmap); @@ -550,6 +585,15 @@ CreateScreenResources(ScreenPtr pScreen) return ret; } +static Bool +msShadowInit(ScreenPtr pScreen) +{ + if (!shadowSetup(pScreen)) { + return FALSE; + } + return TRUE; +} + static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { @@ -571,6 +615,13 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (!drmmode_create_initial_bos(pScrn, &ms->drmmode)) return FALSE; + if (ms->shadow_enable) { + ms->shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY * + ((pScrn->bitsPerPixel + 7) >> 3)); + if (!ms->shadow_fb) + ms->shadow_enable = FALSE; + } + miClearVisualTypes(); if (!miSetVisualTypes(pScrn->depth, @@ -607,6 +658,12 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) fbPictureInit(pScreen, NULL, 0); + if (ms->shadow_enable && !msShadowInit(pScreen)) { + xf86DrvMsg(scrnIndex, X_ERROR, + "shadow fb init failed\n"); + return FALSE; + } + ms->createScreenResources = pScreen->CreateScreenResources; pScreen->CreateScreenResources = CreateScreenResources; @@ -715,6 +772,11 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) ms->damage = NULL; } + if (ms->shadow_enable) { + shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen)); + free(ms->shadow_fb); + ms->shadow_fb = NULL; + } drmmode_uevent_fini(pScrn, &ms->drmmode); drmmode_free_bos(pScrn, &ms->drmmode); diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index beb5f8daf..494ca0ccf 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -76,6 +76,8 @@ typedef struct _modesettingRec DamagePtr damage; Bool dirty_enabled; + Bool shadow_enable; + void *shadow_fb; } modesettingRec, *modesettingPtr; #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) From 6ccd13a2d7d78db2d5bd3fafb00f78d2ceb11741 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 16:00:50 +0100 Subject: [PATCH 030/122] add initial man page --- .../drivers/modesetting/modesetting.man | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man index e69de29bb..34baa9c53 100644 --- a/hw/xfree86/drivers/modesetting/modesetting.man +++ b/hw/xfree86/drivers/modesetting/modesetting.man @@ -0,0 +1,54 @@ +.\" shorthand for double quote that works everywhere. +.ds q \N'34' +.TH MODESETTING __drivermansuffix__ __vendorversion__ +.SH NAME +modesetting \- video driver for framebuffer device +.SH SYNOPSIS +.nf +.B "Section \*qDevice\*q" +.BI " Identifier \*q" devname \*q +.B " Driver \*qmodesetting\*q" +.BI " BusID \*qpci:" bus : dev : func \*q +\ \ ... +.B EndSection +.fi +.SH DESCRIPTION +.B modesetting +is an __xservername__ driver for KMS devices. This is a non-accelerated +driver, the following framebuffer depths are supported: 8, 15, 16, 24. +All visual types are supported for depth 8, and TrueColor visual is +supported for the other depths. RandR 1.2 is supported. +.SH SUPPORTED HARDWARE +The +.B modesetting +driver supports all hardware where a KMS driver is available. +modesetting uses the Linux DRM KMS ioctls and dumb object create/map. +.SH CONFIGURATION DETAILS +Please refer to __xconfigfile__(__filemansuffix__) for general configuration +details. This section only covers configuration details specific to +this driver. +.PP +For this driver it is not required to specify modes in the screen +section of the config file. The +.B modesetting +driver can pick up the currently used video mode from the kernel +driver and will use it if there are no video modes configured. +.PP +For PCI boards you might have to add a BusID line to the Device +section. See above for a sample line. +.PP +The following driver +.B Options +are supported: +.TP +.BI "Option \*qkmsdev\*q \*q" string \*q +The framebuffer device to use. Default: /dev/dri/card0. +.TP +.BI "Option \*qShadowFB\*q \*q" boolean \*q +Enable or disable use of the shadow framebuffer layer. Default: on. +.TP +.SH "SEE ALSO" +__xservername__(__appmansuffix__), __xconfigfile__(__filemansuffix__), Xserver(__appmansuffix__), +X(__miscmansuffix__) +.SH AUTHORS +Authors include: Dave Airlie From cb65ec6b58daf9a1afc40c8693fa0632f8cf0585 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 29 Sep 2011 16:06:52 +0100 Subject: [PATCH 031/122] check drm support dumb buffer capability --- hw/xfree86/drivers/modesetting/drmmode_display.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 375170f85..dcf3eb3c4 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -1016,6 +1016,17 @@ static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = { Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp) { int i, num_dvi = 0, num_hdmi = 0; + int ret; + + /* check for dumb capability */ + { + uint64_t value = 0; + ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value); + if (ret > 0 || value != 1) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n"); + return FALSE; + } + } xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs); From 79959b734702486971447a11b2e4181463fda3bf Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 3 Oct 2011 11:35:39 +0100 Subject: [PATCH 032/122] fix make distcheck --- hw/xfree86/drivers/modesetting/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am index 4337977b0..efc4bc03e 100644 --- a/hw/xfree86/drivers/modesetting/Makefile.am +++ b/hw/xfree86/drivers/modesetting/Makefile.am @@ -35,6 +35,7 @@ modesetting_drv_ladir = @moduledir@/drivers modesetting_drv_la_SOURCES = \ driver.c \ driver.h \ - drmmode_display.c + drmmode_display.c \ + drmmode_display.h EXTRA_DIST = From 6f581e3fde7ddc943c04f274e01735beb358b7f9 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 3 Oct 2011 16:09:12 +0100 Subject: [PATCH 033/122] fix fb_id for dirty reporting --- hw/xfree86/drivers/modesetting/driver.c | 2 +- hw/xfree86/drivers/modesetting/driver.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index bde690c7a..7df587e55 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -327,7 +327,7 @@ static void dispatch_dirty(ScreenPtr pScreen) } /* TODO query connector property to see if this is needed */ - ret = drmModeDirtyFB(ms->fd, ms->fb_id, clip, num_cliprects); + ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects); if (ret) { if (ret == -EINVAL) { ms->dirty_enabled = FALSE; diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index 494ca0ccf..2e5108939 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -46,7 +46,6 @@ typedef struct typedef struct _modesettingRec { int fd; - unsigned int fb_id; EntPtr entityPrivate; From f47f6b6a53d414f28374391964c2930427d28f46 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Thu, 3 Nov 2011 13:20:18 +0000 Subject: [PATCH 035/122] don't map cursors in sw cursor mode --- hw/xfree86/drivers/modesetting/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 7df587e55..7060d3779 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -551,7 +551,8 @@ CreateScreenResources(ScreenPtr pScreen) drmmode_uevent_init(pScrn, &ms->drmmode); - drmmode_map_cursor_bos(pScrn, &ms->drmmode); + if (!ms->SWCursor) + drmmode_map_cursor_bos(pScrn, &ms->drmmode); pixels = drmmode_map_front_bo(&ms->drmmode); if (!pixels) return FALSE; From 2e297978c928c571cf0a80e8d38423089014f07e Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 5 Oct 2011 15:12:43 +0100 Subject: [PATCH 036/122] fixup device open Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 52 ++++++++++++++----------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 7060d3779..03aa027c0 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -379,7 +379,7 @@ PreInit(ScrnInfoPtr pScrn, int flags) rgb defaultWeight = { 0, 0, 0 }; EntityInfoPtr pEnt; EntPtr msEnt = NULL; - char *BusID; + char *BusID, *devicename; if (pScrn->numEntities != 1) return FALSE; @@ -421,22 +421,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) } } - BusID = malloc(64); - sprintf(BusID, "PCI:%d:%d:%d", -#if XSERVER_LIBPCIACCESS - ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), - ms->PciInfo->dev, ms->PciInfo->func -#else - ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum -#endif - ); - - ms->fd = drmOpen(NULL, BusID); - if (ms->fd < 0) - return FALSE; - pScrn->monitor = pScrn->confScreen->monitor; pScrn->progClock = TRUE; pScrn->rgbBits = 8; @@ -459,11 +443,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) } xf86PrintDepthBpp(pScrn); - if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) - return FALSE; - if (!xf86SetDefaultVisual(pScrn, -1)) - return FALSE; - /* Process the options */ xf86CollectOptions(pScrn, NULL); if (!(ms->Options = malloc(sizeof(Options)))) @@ -471,6 +450,35 @@ PreInit(ScrnInfoPtr pScrn, int flags) memcpy(ms->Options, Options, sizeof(Options)); xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options); + devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH); + if (!devicename) { + BusID = malloc(64); + sprintf(BusID, "PCI:%d:%d:%d", +#if XSERVER_LIBPCIACCESS + ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), + ms->PciInfo->dev, ms->PciInfo->func +#else + ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum +#endif + ); + + ms->fd = drmOpen(NULL, BusID); + } else { + ms->fd = open(devicename, O_RDWR, 0); + } + if (ms->fd < 0) + return FALSE; + + + + + if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) + return FALSE; + if (!xf86SetDefaultVisual(pScrn, -1)) + return FALSE; + if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) { ms->SWCursor = TRUE; } From 594b3c4d6f6f748e08baffc4bc1c3ffad9b0d9cf Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 16 Feb 2012 19:31:33 +0000 Subject: [PATCH 037/122] fix some whitespace --- hw/xfree86/drivers/modesetting/driver.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 03aa027c0..69a5fe09b 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -471,9 +471,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) if (ms->fd < 0) return FALSE; - - - if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) return FALSE; if (!xf86SetDefaultVisual(pScrn, -1)) From d94b3eaba9a33d0d78ed2d9acbc33394f40fdc2e Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 14 Nov 2011 11:22:44 +0000 Subject: [PATCH 038/122] modesetting: add cursor fallback if kernel rejects cursor. If the kernel rejects a cursor, cause a fallback, this isn't 100% as we can lose the initial cursor, but it works fine once wm starts. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 4 ++-- hw/xfree86/drivers/modesetting/drmmode_display.c | 13 ++++++++++++- hw/xfree86/drivers/modesetting/drmmode_display.h | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 69a5fe09b..7ce1ac122 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -477,7 +477,7 @@ PreInit(ScrnInfoPtr pScrn, int flags) return FALSE; if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) { - ms->SWCursor = TRUE; + ms->drmmode.sw_cursor = TRUE; } ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, TRUE); @@ -681,7 +681,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); /* Need to extend HWcursor support to handle mask interleave */ - if (!ms->SWCursor) + if (!ms->drmmode.sw_cursor) xf86_cursors_init(pScreen, 64, 64, HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | HARDWARE_CURSOR_ARGB); diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index dcf3eb3c4..ec39967fe 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -402,12 +402,23 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; int i; uint32_t *ptr; - + uint32_t handle = drmmode_crtc->cursor_bo->handle; + int ret; /* cursor should be mapped already */ ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr); for (i = 0; i < 64 * 64; i++) ptr[i] = image[i];// cpu_to_le32(image[i]); + + ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64); + if (ret) { + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; + + cursor_info->MaxWidth = cursor_info->MaxHeight = 0; + drmmode_crtc->drmmode->sw_cursor = TRUE; + /* fallback to swcursor */ + } } diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index 845207a67..7ede1593e 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -53,6 +53,7 @@ typedef struct { #endif drmEventContext event_context; struct dumb_bo *front_bo; + Bool sw_cursor; } drmmode_rec, *drmmode_ptr; typedef struct { From fc5f39acd49d023a82ab05fffde1b423b697753c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 16 Feb 2012 19:41:30 +0000 Subject: [PATCH 039/122] cleanup dumb cap fetch --- hw/xfree86/drivers/modesetting/drmmode_display.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index ec39967fe..57ac521d3 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -1028,15 +1028,13 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp) { int i, num_dvi = 0, num_hdmi = 0; int ret; + uint64_t value = 0; /* check for dumb capability */ - { - uint64_t value = 0; - ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value); - if (ret > 0 || value != 1) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n"); - return FALSE; - } + ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value); + if (ret > 0 || value != 1) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n"); + return FALSE; } xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs); From 86080a5f7a589e55a485c42bab47c6c8ff6428c1 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 16 Feb 2012 19:41:40 +0000 Subject: [PATCH 040/122] use a cap to decide if shadow is preferred or not. --- hw/xfree86/drivers/modesetting/driver.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 7ce1ac122..8af9a9f05 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -59,6 +59,10 @@ #include "driver.h" +#ifndef DRM_CAP_DUMB_PREFER_SHADOW +#define DRM_CAP_DUMB_PREFER_SHADOW 4 +#endif + static void AdjustFrame(int scrnIndex, int x, int y, int flags); static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen); static Bool EnterVT(int scrnIndex, int flags); @@ -380,6 +384,9 @@ PreInit(ScrnInfoPtr pScrn, int flags) EntityInfoPtr pEnt; EntPtr msEnt = NULL; char *BusID, *devicename; + Bool prefer_shadow = TRUE; + uint64_t value = 0; + int ret; if (pScrn->numEntities != 1) return FALSE; @@ -480,7 +487,12 @@ PreInit(ScrnInfoPtr pScrn, int flags) ms->drmmode.sw_cursor = TRUE; } - ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, TRUE); + ret = drmGetCap(ms->fd, DRM_CAP_DUMB_PREFER_SHADOW, &value); + if (!ret) { + prefer_shadow = !!value; + } + + ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow); ms->drmmode.fd = ms->fd; if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) { From 2150cbda8c75d348f39926bbc23d3e4ca9b42c88 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 20 Feb 2012 10:54:21 +0000 Subject: [PATCH 041/122] shadowfb: dump shadowfb state at startup --- hw/xfree86/drivers/modesetting/driver.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 8af9a9f05..b66f0d7ce 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -494,6 +494,7 @@ PreInit(ScrnInfoPtr pScrn, int flags) ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->shadow_enable ? "YES" : "NO"); ms->drmmode.fd = ms->fd; if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n"); From eb44a004b7230321ce6837ef44610153b1d2017b Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 20 Feb 2012 10:54:36 +0000 Subject: [PATCH 042/122] modesetting: fix stride if kernel modifies it. If the kernel aligns things use its values instead. fixes output on nouveau here. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 57ac521d3..caa9f44cb 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -946,7 +946,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) ScreenPtr screen = screenInfo.screens[scrn->scrnIndex]; uint32_t old_fb_id; int i, pitch, old_width, old_height, old_pitch; - int cpp = (scrn->bitsPerPixel + 1) / 8; + int cpp = (scrn->bitsPerPixel + 7) / 8; PixmapPtr ppix = screen->GetScreenPixmap(screen); void *new_pixels; @@ -1287,16 +1287,17 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); int width; int height; - int bpp; + int bpp = pScrn->bitsPerPixel; int i; + int cpp = (bpp + 7) / 8; width = pScrn->virtualX; height = pScrn->virtualY; - bpp = pScrn->bitsPerPixel; + drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp); if (!drmmode->front_bo) return FALSE; - + pScrn->displayWidth = drmmode->front_bo->pitch / cpp; width = height = 64; bpp = 32; From f3b9e52b29e8b8c4b12bc2ce290ab44e88750ad9 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 20 Feb 2012 11:00:56 +0000 Subject: [PATCH 043/122] modesetting: move shadow stuff to other structure we need this for resize to work properly. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 28 +++++++++---------- hw/xfree86/drivers/modesetting/driver.h | 3 +- .../drivers/modesetting/drmmode_display.h | 4 +++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index b66f0d7ce..8703b0b09 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -492,9 +492,9 @@ PreInit(ScrnInfoPtr pScrn, int flags) prefer_shadow = !!value; } - ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow); + ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->shadow_enable ? "YES" : "NO"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO"); ms->drmmode.fd = ms->fd; if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n"); @@ -527,7 +527,7 @@ PreInit(ScrnInfoPtr pScrn, int flags) return FALSE; } - if (ms->shadow_enable) { + if (ms->drmmode.shadow_enable) { if (!xf86LoadSubModule(pScrn, "shadow")) { return FALSE; } @@ -577,13 +577,13 @@ CreateScreenResources(ScreenPtr pScreen) rootPixmap = pScreen->GetScreenPixmap(pScreen); - if (ms->shadow_enable) - pixels = ms->shadow_fb; + if (ms->drmmode.shadow_enable) + pixels = ms->drmmode.shadow_fb; if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels)) FatalError("Couldn't adjust screen pixmap\n"); - if (ms->shadow_enable) { + if (ms->drmmode.shadow_enable) { if (!shadowAdd(pScreen, rootPixmap, shadowUpdatePackedWeak(), msShadowWindow, 0, 0)) return FALSE; @@ -634,11 +634,11 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (!drmmode_create_initial_bos(pScrn, &ms->drmmode)) return FALSE; - if (ms->shadow_enable) { - ms->shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY * + if (ms->drmmode.shadow_enable) { + ms->drmmode.shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY * ((pScrn->bitsPerPixel + 7) >> 3)); - if (!ms->shadow_fb) - ms->shadow_enable = FALSE; + if (!ms->drmmode.shadow_fb) + ms->drmmode.shadow_enable = FALSE; } miClearVisualTypes(); @@ -677,7 +677,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) fbPictureInit(pScreen, NULL, 0); - if (ms->shadow_enable && !msShadowInit(pScreen)) { + if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) { xf86DrvMsg(scrnIndex, X_ERROR, "shadow fb init failed\n"); return FALSE; @@ -791,10 +791,10 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) ms->damage = NULL; } - if (ms->shadow_enable) { + if (ms->drmmode.shadow_enable) { shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen)); - free(ms->shadow_fb); - ms->shadow_fb = NULL; + free(ms->drmmode.shadow_fb); + ms->drmmode.shadow_fb = NULL; } drmmode_uevent_fini(pScrn, &ms->drmmode); diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index 2e5108939..79561c811 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -75,8 +75,7 @@ typedef struct _modesettingRec DamagePtr damage; Bool dirty_enabled; - Bool shadow_enable; - void *shadow_fb; + } modesettingRec, *modesettingPtr; #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index 7ede1593e..e83167b1e 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -54,6 +54,10 @@ typedef struct { drmEventContext event_context; struct dumb_bo *front_bo; Bool sw_cursor; + + Bool shadow_enable; + void *shadow_fb; + } drmmode_rec, *drmmode_ptr; typedef struct { From c5529d68c5b01cf0f36d8f2ce3694a7a0f3333da Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 20 Feb 2012 11:05:59 +0000 Subject: [PATCH 044/122] modesetting: fix shadow resizing. if we hotplugged and output, the shadow got disabled by accident. Signed-off-by: Dave Airlie --- .../drivers/modesetting/drmmode_display.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index caa9f44cb..c004721c9 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -984,8 +984,21 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) if (!new_pixels) goto fail; - screen->ModifyPixmapHeader(ppix, width, height, -1, -1, - pitch, new_pixels); + if (!drmmode->shadow_enable) + screen->ModifyPixmapHeader(ppix, width, height, -1, -1, + pitch, new_pixels); + else { + void *new_shadow; + uint32_t size = scrn->displayWidth * scrn->virtualY * + ((scrn->bitsPerPixel + 7) >> 3); + new_shadow = calloc(1, size); + if (new_shadow == NULL) + goto fail; + free(drmmode->shadow_fb); + drmmode->shadow_fb = new_shadow; + screen->ModifyPixmapHeader(ppix, width, height, -1, -1, + pitch, drmmode->shadow_fb); + } #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,9,99,1,0) scrn->pixmapPrivate.ptr = ppix->devPrivate.ptr; From b0e12e250d4b3438fb3306155a7bbff3e2d7f9b7 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 20 Feb 2012 11:08:40 +0000 Subject: [PATCH 045/122] modesetting: disable dirty updates for ENOSYS the kernel can also return ENOSYS for this to say its not used. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 8703b0b09..d8bb7b56b 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -333,7 +333,7 @@ static void dispatch_dirty(ScreenPtr pScreen) /* TODO query connector property to see if this is needed */ ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects); if (ret) { - if (ret == -EINVAL) { + if (ret == -EINVAL || ret == -ENOSYS) { ms->dirty_enabled = FALSE; DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage); DamageDestroy(ms->damage); From dd1d7e3519ea2f148be83ef7ab0b228da95ff9c3 Mon Sep 17 00:00:00 2001 From: Gaetan Nadon Date: Sun, 19 Feb 2012 08:34:20 -0500 Subject: [PATCH 046/122] Fill the COPYING file with license text This reflects the copyright license text in the source code Signed-off-by: Gaetan Nadon Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/COPYING | 48 +++++++++++++++++++++----- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/COPYING b/hw/xfree86/drivers/modesetting/COPYING index 7f33cbfd2..9508e25e7 100644 --- a/hw/xfree86/drivers/modesetting/COPYING +++ b/hw/xfree86/drivers/modesetting/COPYING @@ -1,12 +1,44 @@ -This is a stub file. This package has not yet had its complete licensing -information compiled. Please see the individual source files for details on -your rights to use and modify this software. +Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. +Copyright 2011 Dave Airlie +All Rights Reserved. -Please submit updated COPYING files to the Xorg bugzilla: +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: -https://bugs.freedesktop.org/enter_bug.cgi?product=xorg +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. -All licensing questions regarding this software should be directed at the -Xorg mailing list: +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -http://lists.freedesktop.org/mailman/listinfo/xorg +Copyright © 2007 Red Hat, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From fa201fe8299099f7192a4399c9df245efcee3f8a Mon Sep 17 00:00:00 2001 From: Gaetan Nadon Date: Sun, 19 Feb 2012 08:36:16 -0500 Subject: [PATCH 056/122] make: remove empty variable assignment Signed-off-by: Gaetan Nadon Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/Makefile.am | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am index efc4bc03e..40ebf0a11 100644 --- a/hw/xfree86/drivers/modesetting/Makefile.am +++ b/hw/xfree86/drivers/modesetting/Makefile.am @@ -17,7 +17,6 @@ # ADAM JACKSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -SUBDIRS = # this is obnoxious: # -module lets us name the module exactly how we want @@ -37,5 +36,3 @@ modesetting_drv_la_SOURCES = \ driver.h \ drmmode_display.c \ drmmode_display.h - -EXTRA_DIST = From d56293cae78323b8976859c4461f8809a76a0b03 Mon Sep 17 00:00:00 2001 From: Gaetan Nadon Date: Sun, 19 Feb 2012 08:36:17 -0500 Subject: [PATCH 057/122] make: add all warnings according to the platform The current code only adds -Wall and only for gcc. Automake reserves the use of CPPFLAGS for the user to override on the command line. This also breaks the option --enable-strict-compilation The variable CWARNFLAGS contains the complete set of warnings and is platform sensitive. Signed-off-by: Gaetan Nadon Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am index 40ebf0a11..68a63faab 100644 --- a/hw/xfree86/drivers/modesetting/Makefile.am +++ b/hw/xfree86/drivers/modesetting/Makefile.am @@ -24,7 +24,7 @@ # _ladir passes a dummy rpath to libtool so the thing will actually link # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. -AM_CFLAGS = @XORG_CFLAGS@ @DRM_CFLAGS@ @UDEV_CFLAGS@ +AM_CFLAGS = $(XORG_CFLAGS) $(DRM_CFLAGS) $(UDEV_CFLAGS) $(CWARNFLAGS) modesetting_drv_la_LTLIBRARIES = modesetting_drv.la modesetting_drv_la_LDFLAGS = -module -avoid-version From e5648616d222966a95edd6c35807dcf5b91a0f96 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 22 Feb 2012 09:59:12 +0000 Subject: [PATCH 060/122] modesetting: fix warnings, remove dead code. Signed-off-by: Dave Airlie --- .../drivers/modesetting/drmmode_display.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index c004721c9..7fa933ad9 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -466,12 +466,6 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = { .destroy = NULL, /* XXX */ }; -int drmmode_get_crtc_id(xf86CrtcPtr crtc) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - return drmmode_crtc->hw_id; -} - static void drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num) { @@ -877,7 +871,7 @@ out_free_encoders: } -uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output) +static uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output) { drmmode_output_private_ptr drmmode_output = output->driver_private, clone_drmout; int i; @@ -1074,15 +1068,6 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp) return TRUE; } -void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct dumb_bo *bo) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CrtcPtr crtc = xf86_config->crtc[id]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - drmmode_crtc->cursor_bo = bo; -} - void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags) { xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); From aa6ceaaa843525b2243569de162ed0b17faa7510 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 3 Mar 2012 14:09:23 +0100 Subject: [PATCH 062/122] fix if() brackets in Probe function in Probe() the indention shows what's meant but there are no brackets. Add them. Signed-off-by: Sascha Hauer Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index d8bb7b56b..2004434f2 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -274,7 +274,7 @@ Probe(DriverPtr drv, int flags) NULL, NULL, NULL, NULL); } - if (scrn) + if (scrn) { foundScreen = TRUE; scrn->driverVersion = 1; scrn->driverName = "modesetting"; @@ -291,6 +291,7 @@ Probe(DriverPtr drv, int flags) xf86DrvMsg(scrn->scrnIndex, X_INFO, "using %s\n", dev ? dev : "default device"); + } } } From 456a001e3f7a24f443cf0bad8400d5d600e2ad46 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 3 Mar 2012 14:09:24 +0100 Subject: [PATCH 063/122] introduce open_hw() function probe_hw opens the hardware in the order we want it: first try devname, if this is NULL then try the KMSDEVICE environment variable and as a last fallback use "/dev/dri/card0". Instead of implementing the same code again when really opening the device move the code to a open_hw() function and let probe_hw use it. Signed-off-by: Sascha Hauer Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 2004434f2..dc90e04d6 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -174,7 +174,7 @@ Identify(int flags) Chipsets); } -static Bool probe_hw(char *dev) +static int open_hw(char *dev) { int fd; if (dev) @@ -186,13 +186,20 @@ static Bool probe_hw(char *dev) fd = open(dev,O_RDWR, 0); } } - if (fd == -1) { + if (fd == -1) xf86DrvMsg(-1, X_ERROR,"open %s: %s\n", dev, strerror(errno)); - return FALSE; - } - close(fd); - return TRUE; + return fd; +} + +static Bool probe_hw(char *dev) +{ + int fd = open_hw(dev); + if (fd != -1) { + close(fd); + return TRUE; + } + return FALSE; } static const OptionInfoRec * From 2b6848fcb3f85f9ce18a6de1dc6c3ac047101aa8 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 3 Mar 2012 14:09:26 +0100 Subject: [PATCH 064/122] Fix non PCI device probing When no devicename is found in the option then the driver probes by PciInfo no matter if it's valid or not. Instead of doing this use PciInfo only when it's valid and fall back to the devicename otherwise. With devicename probing use open_hw() to fall back on the KMSDEVICE environment variable or to the default device. Signed-off-by: Sascha Hauer Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index dc90e04d6..45643a8e6 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -418,8 +418,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) if (ms->pEnt->location.type != BUS_PCI) return FALSE; - ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); - /* Allocate an entity private if necessary */ if (xf86IsEntityShared(pScrn->entityList[0])) { msEnt = xf86GetEntityPrivate(pScrn->entityList[0], @@ -465,8 +463,8 @@ PreInit(ScrnInfoPtr pScrn, int flags) memcpy(ms->Options, Options, sizeof(Options)); xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options); - devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH); - if (!devicename) { + ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); + if (ms->PciInfo) { BusID = malloc(64); sprintf(BusID, "PCI:%d:%d:%d", #if XSERVER_LIBPCIACCESS @@ -481,7 +479,8 @@ PreInit(ScrnInfoPtr pScrn, int flags) ms->fd = drmOpen(NULL, BusID); } else { - ms->fd = open(devicename, O_RDWR, 0); + devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH); + ms->fd = open_hw(devicename); } if (ms->fd < 0) return FALSE; From bb7e39c1f2112f5fb7e87baddb114ab164fbc749 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 3 Mar 2012 14:09:27 +0100 Subject: [PATCH 065/122] do not bail out on non pci devices To make the driver work on nin PCI devices we shouldn't bail out in this case. Signed-off-by: Sascha Hauer Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 45643a8e6..7fa263015 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -415,9 +415,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) pScrn->displayWidth = 640; /* default it */ - if (ms->pEnt->location.type != BUS_PCI) - return FALSE; - /* Allocate an entity private if necessary */ if (xf86IsEntityShared(pScrn->entityList[0])) { msEnt = xf86GetEntityPrivate(pScrn->entityList[0], From 53204d5c8bd83c957fbdb7d3dc2891118ed7658b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 3 Mar 2012 14:09:25 +0100 Subject: [PATCH 066/122] make busID non mandatory Currently the driver only probes a device when it has a busID. The busID is optional so don't depend on it. Signed-off-by: Sascha Hauer Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 44 ++++++++++++------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 7fa263015..87431ff43 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -273,32 +273,30 @@ Probe(DriverPtr drv, int flags) for (i = 0; i < numDevSections; i++) { dev = xf86FindOptionValue(devSections[i]->options,"kmsdev"); - if (devSections[i]->busID) { - if (probe_hw(dev)) { - int entity; - entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE); - scrn = xf86ConfigFbEntity(scrn, 0, entity, - NULL, NULL, NULL, NULL); - } + if (probe_hw(dev)) { + int entity; + entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE); + scrn = xf86ConfigFbEntity(scrn, 0, entity, + NULL, NULL, NULL, NULL); + } - if (scrn) { - foundScreen = TRUE; - scrn->driverVersion = 1; - scrn->driverName = "modesetting"; - scrn->name = "modesetting"; - scrn->Probe = Probe; - scrn->PreInit = PreInit; - scrn->ScreenInit = ScreenInit; - scrn->SwitchMode = SwitchMode; - scrn->AdjustFrame = AdjustFrame; - scrn->EnterVT = EnterVT; - scrn->LeaveVT = LeaveVT; - scrn->FreeScreen = FreeScreen; - scrn->ValidMode = ValidMode; + if (scrn) { + foundScreen = TRUE; + scrn->driverVersion = 1; + scrn->driverName = "modesetting"; + scrn->name = "modesetting"; + scrn->Probe = Probe; + scrn->PreInit = PreInit; + scrn->ScreenInit = ScreenInit; + scrn->SwitchMode = SwitchMode; + scrn->AdjustFrame = AdjustFrame; + scrn->EnterVT = EnterVT; + scrn->LeaveVT = LeaveVT; + scrn->FreeScreen = FreeScreen; + scrn->ValidMode = ValidMode; - xf86DrvMsg(scrn->scrnIndex, X_INFO, + xf86DrvMsg(scrn->scrnIndex, X_INFO, "using %s\n", dev ? dev : "default device"); - } } } From 6c1b5cb903f2ff9cb915273835c301d6ac255f45 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sat, 14 Apr 2012 15:01:16 +0100 Subject: [PATCH 068/122] drop use of alloca, just use malloc/free Reported-by: Alan Coopersmith Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 87431ff43..95d6b908d 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -324,7 +324,7 @@ static void dispatch_dirty(ScreenPtr pScreen) unsigned num_cliprects = REGION_NUM_RECTS(dirty); if (num_cliprects) { - drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip)); + drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip)); BoxPtr rect = REGION_RECTS(dirty); int i, ret; @@ -338,6 +338,7 @@ static void dispatch_dirty(ScreenPtr pScreen) /* TODO query connector property to see if this is needed */ ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects); + free(clip); if (ret) { if (ret == -EINVAL || ret == -ENOSYS) { ms->dirty_enabled = FALSE; From d5d5b407436dfdbffcd56bbefecf17d11750dddf Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sat, 14 Apr 2012 19:21:47 +0100 Subject: [PATCH 069/122] dirty: check malloc return Suggested by keithp. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 95d6b908d..b776ca1c4 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -327,7 +327,10 @@ static void dispatch_dirty(ScreenPtr pScreen) drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip)); BoxPtr rect = REGION_RECTS(dirty); int i, ret; - + + if (!clip) + return; + /* XXX no need for copy? */ for (i = 0; i < num_cliprects; i++, rect++) { clip[i].x1 = rect->x1; From 001dec898098e11c569abc20a307b3c2af2e2184 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 17 Apr 2012 11:48:03 +0100 Subject: [PATCH 070/122] cursor: hide cursors on LeaveVT --- hw/xfree86/drivers/modesetting/driver.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index b776ca1c4..516bf615c 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -757,6 +757,8 @@ LeaveVT(int scrnIndex, int flags) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + xf86_hide_cursors(pScrn); + pScrn->vtSema = FALSE; } From 00c663a3bc76d567ad7edd6d6ef3f7f725b5df3a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 17 Apr 2012 11:50:40 +0100 Subject: [PATCH 071/122] modesetting: add set/drop master around VT switch --- hw/xfree86/drivers/modesetting/driver.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 516bf615c..827438a2f 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -756,10 +756,12 @@ static void LeaveVT(int scrnIndex, int flags) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; - + modesettingPtr ms = modesettingPTR(pScrn); xf86_hide_cursors(pScrn); pScrn->vtSema = FALSE; + + drmDropMaster(ms->fd); } /* @@ -773,6 +775,11 @@ EnterVT(int scrnIndex, int flags) pScrn->vtSema = TRUE; + if (drmSetMaster(ms->fd)) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "drmSetMaster failed: %s\n", + strerror(errno)); + } + if (!drmmode_set_desired_modes(pScrn, &ms->drmmode)) return FALSE; @@ -815,8 +822,6 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) pScreen->CreateScreenResources = ms->createScreenResources; pScreen->BlockHandler = ms->BlockHandler; - drmDropMaster(ms->fd); - pScrn->vtSema = FALSE; pScreen->CloseScreen = ms->CloseScreen; return (*pScreen->CloseScreen) (scrnIndex, pScreen); From 610f532e6a3d934c473d2d16dff95f582285b2eb Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 1 May 2012 16:52:18 +0100 Subject: [PATCH 072/122] modesetting: move opening kernel device to before setting depth due to interaction between option handling and set depth, we need to what fbdev does to get the device path early. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 44 ++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 827438a2f..fb4b410b3 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -437,6 +437,28 @@ PreInit(ScrnInfoPtr pScrn, int flags) pScrn->progClock = TRUE; pScrn->rgbBits = 8; + ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); + if (ms->PciInfo) { + BusID = malloc(64); + sprintf(BusID, "PCI:%d:%d:%d", +#if XSERVER_LIBPCIACCESS + ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), + ms->PciInfo->dev, ms->PciInfo->func +#else + ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum +#endif + ); + + ms->fd = drmOpen(NULL, BusID); + } else { + devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev"); + ms->fd = open_hw(devicename); + } + if (ms->fd < 0) + return FALSE; + if (!xf86SetDepthBpp (pScrn, 0, 0, 0, PreferConvert24to32 | SupportConvert24to32 | Support32bppFb)) @@ -462,28 +484,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) memcpy(ms->Options, Options, sizeof(Options)); xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options); - ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); - if (ms->PciInfo) { - BusID = malloc(64); - sprintf(BusID, "PCI:%d:%d:%d", -#if XSERVER_LIBPCIACCESS - ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), - ms->PciInfo->dev, ms->PciInfo->func -#else - ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum -#endif - ); - - ms->fd = drmOpen(NULL, BusID); - } else { - devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH); - ms->fd = open_hw(devicename); - } - if (ms->fd < 0) - return FALSE; - if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) return FALSE; if (!xf86SetDefaultVisual(pScrn, -1)) From d063f64b5c8c8c27fca41163c93dbca06a774d1c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 1 May 2012 17:12:29 +0100 Subject: [PATCH 073/122] modesetting: attempt to work out if we want 24 or 32bpp the cirrus driver presents certain challenges, and this is a workaround, until we can possibly agree some sane interface for exposing this information. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 18 ++++--- .../drivers/modesetting/drmmode_display.c | 47 +++++++++++++++++++ .../drivers/modesetting/drmmode_display.h | 10 ++++ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index fb4b410b3..2c9878c61 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -59,10 +59,6 @@ #include "driver.h" -#ifndef DRM_CAP_DUMB_PREFER_SHADOW -#define DRM_CAP_DUMB_PREFER_SHADOW 4 -#endif - static void AdjustFrame(int scrnIndex, int x, int y, int flags); static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen); static Bool EnterVT(int scrnIndex, int flags); @@ -397,6 +393,8 @@ PreInit(ScrnInfoPtr pScrn, int flags) Bool prefer_shadow = TRUE; uint64_t value = 0; int ret; + int bppflags; + int defaultdepth, defaultbpp; if (pScrn->numEntities != 1) return FALSE; @@ -459,9 +457,16 @@ PreInit(ScrnInfoPtr pScrn, int flags) if (ms->fd < 0) return FALSE; + ms->drmmode.fd = ms->fd; + + drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp); + if (defaultdepth == 24 && defaultbpp == 24) + bppflags = Support24bppFb; + else + bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb; + if (!xf86SetDepthBpp - (pScrn, 0, 0, 0, - PreferConvert24to32 | SupportConvert24to32 | Support32bppFb)) + (pScrn, defaultdepth, defaultdepth, defaultbpp, bppflags)) return FALSE; switch (pScrn->depth) { @@ -501,7 +506,6 @@ PreInit(ScrnInfoPtr pScrn, int flags) ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow); xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO"); - ms->drmmode.fd = ms->fd; if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n"); goto fail; diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 7fa933ad9..71f2e02f1 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -1355,3 +1355,50 @@ void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo); } } + +/* ugly workaround to see if we can create 32bpp */ +void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth, int *bpp) +{ + drmModeResPtr mode_res; + uint64_t value; + struct dumb_bo *bo; + uint32_t fb_id; + int ret; + + /* 16 is fine */ + ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_PREFERRED_DEPTH, &value); + if (!ret && (value == 16 || value == 8)) { + *depth = value; + *bpp = value; + return; + } + + *depth = 24; + mode_res = drmModeGetResources(drmmode->fd); + if (!mode_res) + return; + + /*create a bo */ + bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height, 32); + if (!bo) { + *bpp = 24; + goto out; + } + + ret = drmModeAddFB(drmmode->fd, mode_res->min_width, mode_res->min_height, + 24, 32, bo->pitch, bo->handle, &fb_id); + + if (ret) { + *bpp = 24; + dumb_bo_destroy(drmmode->fd, bo); + goto out; + } + + drmModeRmFB(drmmode->fd, fb_id); + *bpp = 32; + + dumb_bo_destroy(drmmode->fd, bo); +out: + drmModeFreeResources(mode_res); + return; +} diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index e83167b1e..fa280bdcd 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -103,4 +103,14 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); void *drmmode_map_front_bo(drmmode_ptr drmmode); Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); +void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth, int *bpp); + +#ifndef DRM_CAP_DUMB_PREFERRED_DEPTH +#define DRM_CAP_DUMB_PREFERRED_DEPTH 3 +#endif +#ifndef DRM_CAP_DUMB_PREFER_SHADOW +#define DRM_CAP_DUMB_PREFER_SHADOW 4 +#endif + + #endif From 7dc22b7911ac3d5c131075903e3fbf52c58eac15 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 9 May 2012 09:32:05 +0100 Subject: [PATCH 074/122] modesetting: make sure the pci device corresponds to the drm device If we get asked to pci open a device with a kms path override, make sure they match, otherwise this driver can steal the primary device binding for a usb adaptor. The driver should fallback to the old probe entry point in this case. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 35 ++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 2c9878c61..e97715099 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -198,6 +198,39 @@ static Bool probe_hw(char *dev) return FALSE; } +static char * +ms_DRICreatePCIBusID(const struct pci_device *dev) +{ + char *busID; + + if (asprintf(&busID, "pci:%04x:%02x:%02x.%d", + dev->domain, dev->bus, dev->dev, dev->func) == -1) + return NULL; + + return busID; +} + + +static Bool probe_hw_pci(char *dev, struct pci_device *pdev) +{ + int fd = open_hw(dev); + char *id, *devid; + + if (fd == -1) + return FALSE; + + id = drmGetBusid(fd); + devid = ms_DRICreatePCIBusID(pdev); + close(fd); + + if (!id || !devid) + return FALSE; + + if (!strcmp(id, devid)) + return TRUE; + + return FALSE; +} static const OptionInfoRec * AvailableOptions(int chipid, int busid) { @@ -219,7 +252,7 @@ ms_pci_probe(DriverPtr driver, scrn->entityInstanceList[0]); devpath = xf86FindOptionValue(devSection->options, "kmsdev"); - if (probe_hw(devpath)) { + if (probe_hw_pci(devpath, dev)) { scrn->driverVersion = 1; scrn->driverName = "modesetting"; scrn->name = "modeset"; From 3e46d578d8c40c95343278db0a66c931e85247c7 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 23 May 2012 11:21:39 +0100 Subject: [PATCH 077/122] modesetting: add compat header file Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/compat-api.h | 41 +++++++++++++++++++ hw/xfree86/drivers/modesetting/driver.c | 1 + .../drivers/modesetting/drmmode_display.c | 1 + 3 files changed, 43 insertions(+) create mode 100644 hw/xfree86/drivers/modesetting/compat-api.h diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h new file mode 100644 index 000000000..1bb772416 --- /dev/null +++ b/hw/xfree86/drivers/modesetting/compat-api.h @@ -0,0 +1,41 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Author: Dave Airlie + */ + +/* this file provides API compat between server post 1.13 and pre it, + it should be reused inside as many drivers as possible */ +#ifndef COMPAT_API_H +#define COMPAT_API_H + +#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR +#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum] +#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p +#endif + +#ifndef XF86_HAS_SCRN_CONV +#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum] +#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex] +#endif + +#endif diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index e97715099..ce4cdec45 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -57,6 +57,7 @@ #include #endif +#include "compat-api.h" #include "driver.h" static void AdjustFrame(int scrnIndex, int x, int y, int flags); diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 71f2e02f1..22fc66a58 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -49,6 +49,7 @@ #define DPMS_SERVER #include #endif +#include "compat-api.h" static struct dumb_bo *dumb_bo_create(int fd, const unsigned width, const unsigned height, From ef47a1b3bfec33d4031af2e01bdd46d634be2f51 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 23 May 2012 11:21:55 +0100 Subject: [PATCH 078/122] modesetting: convert to new scrn conversion APIs. Generated with util/modular/x-driver-screen-scrn-conv.sh Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 10 +++++----- hw/xfree86/drivers/modesetting/drmmode_display.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index ce4cdec45..61e061570 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -348,7 +348,7 @@ GetRec(ScrnInfoPtr pScrn) static void dispatch_dirty(ScreenPtr pScreen) { - ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; + ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); modesettingPtr ms = modesettingPTR(scrn); RegionPtr dirty = DamageRegion(ms->damage); unsigned num_cliprects = REGION_NUM_RECTS(dirty); @@ -393,7 +393,7 @@ static void msBlockHandler(int i, pointer blockData, pointer pTimeout, pointer pReadmask) { ScreenPtr pScreen = screenInfo.screens[i]; - modesettingPtr ms = modesettingPTR(xf86Screens[pScreen->myNum]); + modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen)); pScreen->BlockHandler = ms->BlockHandler; pScreen->BlockHandler(i, blockData, pTimeout, pReadmask); @@ -586,7 +586,7 @@ static void * msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode, CARD32 *size, void *closure) { - ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; + ScrnInfoPtr pScrn = xf86ScreenToScrn(screen); modesettingPtr ms = modesettingPTR(pScrn); int stride; @@ -599,7 +599,7 @@ msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode, static Bool CreateScreenResources(ScreenPtr pScreen) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); modesettingPtr ms = modesettingPTR(pScrn); PixmapPtr rootPixmap; Bool ret; @@ -660,7 +660,7 @@ msShadowInit(ScreenPtr pScreen) static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); modesettingPtr ms = modesettingPTR(pScrn); VisualPtr visual; int ret; diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 22fc66a58..c0cc06b34 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -938,7 +938,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) drmmode_ptr drmmode = drmmode_crtc->drmmode; struct dumb_bo *old_front = NULL; Bool ret; - ScreenPtr screen = screenInfo.screens[scrn->scrnIndex]; + ScreenPtr screen = xf86ScrnToScreen(scrn); uint32_t old_fb_id; int i, pitch, old_width, old_height, old_pitch; int cpp = (scrn->bitsPerPixel + 7) / 8; @@ -1229,7 +1229,7 @@ drmmode_handle_uevents(int fd, void *closure) if (!dev) return; - RRGetInfo(screenInfo.screens[scrn->scrnIndex], TRUE); + RRGetInfo(xf86ScrnToScreen(scrn), TRUE); udev_device_unref(dev); } #endif From 1c01090f6485cb82c2511fb461e66ff15a097358 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 23 May 2012 11:31:39 +0100 Subject: [PATCH 079/122] modesetting: fix make distcheck add missing compat header file. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am index 68a63faab..3cc4624ba 100644 --- a/hw/xfree86/drivers/modesetting/Makefile.am +++ b/hw/xfree86/drivers/modesetting/Makefile.am @@ -32,6 +32,7 @@ modesetting_drv_la_LIBADD = @UDEV_LIBS@ @DRM_LIBS@ modesetting_drv_ladir = @moduledir@/drivers modesetting_drv_la_SOURCES = \ + compat-api.h \ driver.c \ driver.h \ drmmode_display.c \ From e07c945ab992b1b1acdd9f5554e0688f744e4769 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 1 Jun 2012 12:34:42 +0100 Subject: [PATCH 080/122] modesetting: bump to latest X server compat api. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/compat-api.h | 53 ++++++++++++++++++ hw/xfree86/drivers/modesetting/driver.c | 61 ++++++++++----------- 2 files changed, 83 insertions(+), 31 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h index 1bb772416..df783a82d 100644 --- a/hw/xfree86/drivers/modesetting/compat-api.h +++ b/hw/xfree86/drivers/modesetting/compat-api.h @@ -38,4 +38,57 @@ #define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex] #endif +#ifndef XF86_SCRN_INTERFACE + +#define SCRN_ARG_TYPE int +#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = xf86Screens[(arg1)] + +#define SCREEN_ARG_TYPE int +#define SCREEN_PTR(arg1) ScreenPtr pScreen = screenInfo.screens[(arg1)] + +#define SCREEN_INIT_ARGS_DECL int i, ScreenPtr pScreen, int argc, char **argv + +#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer pTimeout, pointer pReadmask +#define BLOCKHANDLER_ARGS arg, blockData, pTimeout, pReadmask + +#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr pScreen +#define CLOSE_SCREEN_ARGS scrnIndex, pScreen + +#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags + +#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags + +#define FREE_SCREEN_ARGS_DECL int arg, int flags + +#define VT_FUNC_ARGS_DECL int arg, int flags +#define VT_FUNC_ARGS pScrn->scrnIndex, 0 + +#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex) +#else +#define SCRN_ARG_TYPE ScrnInfoPtr +#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = (arg1) + +#define SCREEN_ARG_TYPE ScreenPtr +#define SCREEN_PTR(arg1) ScreenPtr pScreen = (arg1) + +#define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv + +#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer pTimeout, pointer pReadmask +#define BLOCKHANDLER_ARGS arg, pTimeout, pReadmask + +#define CLOSE_SCREEN_ARGS_DECL ScreenPtr pScreen +#define CLOSE_SCREEN_ARGS pScreen + +#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y +#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode + +#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg + +#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg +#define VT_FUNC_ARGS pScrn + +#define XF86_ENABLEDISABLEFB_ARG(x) (x) + +#endif + #endif diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 61e061570..f0529f52c 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -60,18 +60,17 @@ #include "compat-api.h" #include "driver.h" -static void AdjustFrame(int scrnIndex, int x, int y, int flags); -static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen); -static Bool EnterVT(int scrnIndex, int flags); +static void AdjustFrame(ADJUST_FRAME_ARGS_DECL); +static Bool CloseScreen(CLOSE_SCREEN_ARGS_DECL); +static Bool EnterVT(VT_FUNC_ARGS_DECL); static void Identify(int flags); static const OptionInfoRec *AvailableOptions(int chipid, int busid); -static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, +static ModeStatus ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags); -static void FreeScreen(int scrnIndex, int flags); -static void LeaveVT(int scrnIndex, int flags); -static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags); -static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, - char **argv); +static void FreeScreen(FREE_SCREEN_ARGS_DECL); +static void LeaveVT(VT_FUNC_ARGS_DECL); +static Bool SwitchMode(SWITCH_MODE_ARGS_DECL); +static Bool ScreenInit(SCREEN_INIT_ARGS_DECL); static Bool PreInit(ScrnInfoPtr pScrn, int flags); static Bool Probe(DriverPtr drv, int flags); @@ -389,14 +388,13 @@ static void dispatch_dirty(ScreenPtr pScreen) } } -static void msBlockHandler(int i, pointer blockData, pointer pTimeout, - pointer pReadmask) +static void msBlockHandler(BLOCKHANDLER_ARGS_DECL) { - ScreenPtr pScreen = screenInfo.screens[i]; + SCREEN_PTR(arg); modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen)); pScreen->BlockHandler = ms->BlockHandler; - pScreen->BlockHandler(i, blockData, pTimeout, pReadmask); + pScreen->BlockHandler(BLOCKHANDLER_ARGS); pScreen->BlockHandler = msBlockHandler; if (ms->dirty_enabled) dispatch_dirty(pScreen); @@ -658,7 +656,7 @@ msShadowInit(ScreenPtr pScreen) } static Bool -ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) +ScreenInit(SCREEN_INIT_ARGS_DECL) { ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); modesettingPtr ms = modesettingPTR(pScrn); @@ -722,7 +720,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) fbPictureInit(pScreen, NULL, 0); if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) { - xf86DrvMsg(scrnIndex, X_ERROR, + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "shadow fb init failed\n"); return FALSE; } @@ -765,13 +763,13 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (serverGeneration == 1) xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); - return EnterVT(scrnIndex, 1); + return EnterVT(VT_FUNC_ARGS); } static void -AdjustFrame(int scrnIndex, int x, int y, int flags) +AdjustFrame(ADJUST_FRAME_ARGS_DECL) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + SCRN_INFO_PTR(arg); xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); xf86OutputPtr output = config->output[config->compat_output]; xf86CrtcPtr crtc = output->crtc; @@ -785,15 +783,16 @@ AdjustFrame(int scrnIndex, int x, int y, int flags) } static void -FreeScreen(int scrnIndex, int flags) +FreeScreen(FREE_SCREEN_ARGS_DECL) { - FreeRec(xf86Screens[scrnIndex]); + SCRN_INFO_PTR(arg); + FreeRec(pScrn); } static void -LeaveVT(int scrnIndex, int flags) +LeaveVT(VT_FUNC_ARGS_DECL) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + SCRN_INFO_PTR(arg); modesettingPtr ms = modesettingPTR(pScrn); xf86_hide_cursors(pScrn); @@ -806,9 +805,9 @@ LeaveVT(int scrnIndex, int flags) * This gets called when gaining control of the VT, and from ScreenInit(). */ static Bool -EnterVT(int scrnIndex, int flags) +EnterVT(VT_FUNC_ARGS_DECL) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + SCRN_INFO_PTR(arg); modesettingPtr ms = modesettingPTR(pScrn); pScrn->vtSema = TRUE; @@ -825,17 +824,17 @@ EnterVT(int scrnIndex, int flags) } static Bool -SwitchMode(int scrnIndex, DisplayModePtr mode, int flags) +SwitchMode(SWITCH_MODE_ARGS_DECL) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + SCRN_INFO_PTR(arg); return xf86SetSingleMode(pScrn, mode, RR_Rotate_0); } static Bool -CloseScreen(int scrnIndex, ScreenPtr pScreen) +CloseScreen(CLOSE_SCREEN_ARGS_DECL) { - ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); modesettingPtr ms = modesettingPTR(pScrn); if (ms->damage) { @@ -854,7 +853,7 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) drmmode_free_bos(pScrn, &ms->drmmode); if (pScrn->vtSema) { - LeaveVT(scrnIndex, 0); + LeaveVT(VT_FUNC_ARGS); } pScreen->CreateScreenResources = ms->createScreenResources; @@ -862,11 +861,11 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen) pScrn->vtSema = FALSE; pScreen->CloseScreen = ms->CloseScreen; - return (*pScreen->CloseScreen) (scrnIndex, pScreen); + return (*pScreen->CloseScreen) (CLOSE_SCREEN_ARGS); } static ModeStatus -ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags) +ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags) { return MODE_OK; } From ec79187d9a23ba30eafc7ba225049559e6bcb78d Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 5 Jun 2012 14:41:18 +0100 Subject: [PATCH 081/122] modesetting: workaround kernel bug reporting 0x0 as valid mins It reports these but then you can't create a 0 sized bo. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index c0cc06b34..185bfe933 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -1379,6 +1379,10 @@ void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth, if (!mode_res) return; + if (mode_res->min_width == 0) + mode_res->min_width = 1; + if (mode_res->min_height == 0) + mode_res->min_height = 1; /*create a bo */ bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height, 32); if (!bo) { From 30ab80ef5421fea9d9dd0779aa138892ff62bd6e Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 22 Jun 2012 15:26:28 +0100 Subject: [PATCH 082/122] modesetting: pci probing requires interface version 1.4 Set the drm interface version to 1.4 so we get the bus id correctly. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index f0529f52c..ad817c494 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -215,10 +215,21 @@ static Bool probe_hw_pci(char *dev, struct pci_device *pdev) { int fd = open_hw(dev); char *id, *devid; + drmSetVersion sv; if (fd == -1) return FALSE; + sv.drm_di_major = 1; + sv.drm_di_minor = 4; + sv.drm_dd_major = -1; + sv.drm_dd_minor = -1; + if (drmSetInterfaceVersion(fd, &sv)) { + close(fd); + return FALSE; + } + + id = drmGetBusid(fd); devid = ms_DRICreatePCIBusID(pdev); close(fd); From 71b86ea8dd69f21d090edd4f61698ad11b952d5e Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 25 Jul 2012 15:33:52 +1000 Subject: [PATCH 084/122] modesetting: drop useless xf86PciInfo include Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index ad817c494..8c3f4a46b 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -38,7 +38,6 @@ #include "xf86.h" #include "xf86_OSproc.h" #include "compiler.h" -#include "xf86PciInfo.h" #include "xf86Pci.h" #include "mipointer.h" #include "micmap.h" From 709dbc68cdea9d282ba318c1cbc76614e98f41c4 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 25 Jul 2012 15:38:34 +1000 Subject: [PATCH 085/122] modesetting: fix warning about close being undefined. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 185bfe933..9ee553ea8 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "xf86str.h" #include "X11/Xatom.h" #include "micmap.h" From fa171c5a81b1c226b5da54f35e6726d9c8e13afb Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 5 Jun 2012 14:43:21 +0100 Subject: [PATCH 086/122] modesetting: add platform bus support --- hw/xfree86/drivers/modesetting/driver.c | 88 ++++++++++++++++++++----- 1 file changed, 71 insertions(+), 17 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 8c3f4a46b..86be27776 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -52,6 +52,9 @@ #include "xf86xv.h" #include #include +#ifdef XSERVER_PLATFORM_BUS +#include "xf86platformBus.h" +#endif #if XSERVER_LIBPCIACCESS #include #endif @@ -88,6 +91,12 @@ static const struct pci_id_match ms_device_match[] = { }; #endif +#ifdef XSERVER_PLATFORM_BUS +static Bool ms_platform_probe(DriverPtr driver, + int entity_num, int flags, struct xf86_platform_device *device, + intptr_t match_data); +#endif + _X_EXPORT DriverRec modesetting = { 1, "modesetting", @@ -99,6 +108,9 @@ _X_EXPORT DriverRec modesetting = { NULL, ms_device_match, ms_pci_probe, +#ifdef XSERVER_PLATFORM_BUS + ms_platform_probe, +#endif }; static SymTabRec Chipsets[] = { @@ -288,6 +300,40 @@ ms_pci_probe(DriverPtr driver, } #endif +#ifdef XSERVER_PLATFORM_BUS +static Bool +ms_platform_probe(DriverPtr driver, + int entity_num, int flags, struct xf86_platform_device *dev, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH); + int scr_flags = 0; + + if (flags & PLATFORM_PROBE_GPU_SCREEN) + scr_flags = XF86_ALLOCATE_GPU_SCREEN; + + if (probe_hw(path)) { + scrn = xf86AllocateScreen(driver, scr_flags); + xf86AddEntityToScreen(scrn, entity_num); + + scrn->driverName = "modesetting"; + scrn->name = "modesetting"; + scrn->PreInit = PreInit; + scrn->ScreenInit = ScreenInit; + scrn->SwitchMode = SwitchMode; + scrn->AdjustFrame = AdjustFrame; + scrn->EnterVT = EnterVT; + scrn->LeaveVT = LeaveVT; + scrn->FreeScreen = FreeScreen; + scrn->ValidMode = ValidMode; + xf86DrvMsg(scrn->scrnIndex, X_INFO, + "using drv %s\n", path ? path : "default device"); + } + + return scrn != NULL; +} +#endif + static Bool Probe(DriverPtr drv, int flags) { @@ -431,7 +477,7 @@ PreInit(ScrnInfoPtr pScrn, int flags) rgb defaultWeight = { 0, 0, 0 }; EntityInfoPtr pEnt; EntPtr msEnt = NULL; - char *BusID, *devicename; + char *BusID = NULL, *devicename; Bool prefer_shadow = TRUE; uint64_t value = 0; int ret; @@ -477,24 +523,32 @@ PreInit(ScrnInfoPtr pScrn, int flags) pScrn->progClock = TRUE; pScrn->rgbBits = 8; - ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); - if (ms->PciInfo) { - BusID = malloc(64); - sprintf(BusID, "PCI:%d:%d:%d", -#if XSERVER_LIBPCIACCESS - ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), - ms->PciInfo->dev, ms->PciInfo->func -#else - ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, - ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum +#if XSERVER_PLATFORM_BUS + if (pEnt->location.type == BUS_PLATFORM) { + char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH); + ms->fd = open_hw(path); + } + else #endif - ); - - ms->fd = drmOpen(NULL, BusID); + if (pEnt->location.type == BUS_PCI) { + ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); + if (ms->PciInfo) { + BusID = malloc(64); + sprintf(BusID, "PCI:%d:%d:%d", +#if XSERVER_LIBPCIACCESS + ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), + ms->PciInfo->dev, ms->PciInfo->func +#else + ((pciConfigPtr) ms->PciInfo->thisCard)->busnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->devnum, + ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum +#endif + ); + } + ms->fd = drmOpen(NULL, BusID); } else { - devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev"); - ms->fd = open_hw(devicename); + devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev"); + ms->fd = open_hw(devicename); } if (ms->fd < 0) return FALSE; From 02811f1a9cc35c5f82accb0459cb3910165e7e45 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 19 Jul 2012 14:12:59 +1000 Subject: [PATCH 087/122] modesetting: add output slave support. This allows the driver to operate as an output slave. It adds scan out pixmap, and the capability checks to make sure they available. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 136 +++++++++++++++--- .../drivers/modesetting/drmmode_display.c | 117 ++++++++++++++- .../drivers/modesetting/drmmode_display.h | 27 ++++ 3 files changed, 256 insertions(+), 24 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 86be27776..371c17114 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -401,21 +401,20 @@ GetRec(ScrnInfoPtr pScrn) return TRUE; } -static void dispatch_dirty(ScreenPtr pScreen) +static int dispatch_dirty_region(ScrnInfoPtr scrn, + PixmapPtr pixmap, + DamagePtr damage, + int fb_id) { - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); modesettingPtr ms = modesettingPTR(scrn); - RegionPtr dirty = DamageRegion(ms->damage); + RegionPtr dirty = DamageRegion(damage); unsigned num_cliprects = REGION_NUM_RECTS(dirty); if (num_cliprects) { - drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip)); + drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip)); BoxPtr rect = REGION_RECTS(dirty); int i, ret; - - if (!clip) - return; - + /* XXX no need for copy? */ for (i = 0; i < num_cliprects; i++, rect++) { clip[i].x1 = rect->x1; @@ -425,25 +424,71 @@ static void dispatch_dirty(ScreenPtr pScreen) } /* TODO query connector property to see if this is needed */ - ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects); - free(clip); + ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects); + DamageEmpty(damage); if (ret) { - if (ret == -EINVAL || ret == -ENOSYS) { - ms->dirty_enabled = FALSE; - DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage); - DamageDestroy(ms->damage); - ms->damage = NULL; - xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n"); - return; - } else - ErrorF("%s: failed to send dirty (%i, %s)\n", - __func__, ret, strerror(-ret)); + if (ret == -EINVAL) + return ret; } - - DamageEmpty(ms->damage); + } + return 0; +} + +static void dispatch_dirty(ScreenPtr pScreen) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); + modesettingPtr ms = modesettingPTR(scrn); + PixmapPtr pixmap = pScreen->GetScreenPixmap(pScreen); + int fb_id = ms->drmmode.fb_id; + int ret; + + ret = dispatch_dirty_region(scrn, pixmap, ms->damage, fb_id); + if (ret == -EINVAL || ret == -ENOSYS) { + ms->dirty_enabled = FALSE; + DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage); + DamageDestroy(ms->damage); + ms->damage = NULL; + xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n"); + return; } } +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT +static void dispatch_dirty_crtc(ScrnInfoPtr scrn, xf86CrtcPtr crtc) +{ + modesettingPtr ms = modesettingPTR(scrn); + PixmapPtr pixmap = crtc->randr_crtc->scanout_pixmap; + msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, pixmap); + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + DamagePtr damage = drmmode_crtc->slave_damage; + int fb_id = ppriv->fb_id; + int ret; + + ret = dispatch_dirty_region(scrn, pixmap, damage, fb_id); + if (ret) { + + } +} + +static void dispatch_slave_dirty(ScreenPtr pScreen) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int c; + + for (c = 0; c < xf86_config->num_crtc; c++) { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (!crtc->randr_crtc) + continue; + if (!crtc->randr_crtc->scanout_pixmap) + continue; + + dispatch_dirty_crtc(scrn, crtc); + } +} +#endif + static void msBlockHandler(BLOCKHANDLER_ARGS_DECL) { SCREEN_PTR(arg); @@ -452,8 +497,13 @@ static void msBlockHandler(BLOCKHANDLER_ARGS_DECL) pScreen->BlockHandler = ms->BlockHandler; pScreen->BlockHandler(BLOCKHANDLER_ARGS); pScreen->BlockHandler = msBlockHandler; +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT + if (pScreen->isGPU) + dispatch_slave_dirty(pScreen); + else +#endif if (ms->dirty_enabled) - dispatch_dirty(pScreen); + dispatch_dirty(pScreen); } static void @@ -555,6 +605,16 @@ PreInit(ScrnInfoPtr pScrn, int flags) ms->drmmode.fd = ms->fd; +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT + pScrn->capabilities = 0; +#ifdef DRM_CAP_PRIME + ret = drmGetCap(ms->fd, DRM_CAP_PRIME, &value); + if (ret == 0) { + if (value & DRM_PRIME_CAP_IMPORT) + pScrn->capabilities |= RR_Capability_SinkOutput; + } +#endif +#endif drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp); if (defaultdepth == 24 && defaultbpp == 24) bppflags = Support24bppFb; @@ -719,6 +779,25 @@ msShadowInit(ScreenPtr pScreen) return TRUE; } +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT +static Bool +msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle) +{ + ScreenPtr screen = ppix->drawable.pScreen; + ScrnInfoPtr scrn = xf86ScreenToScrn(screen); + modesettingPtr ms = modesettingPTR(scrn); + Bool ret; + int size = ppix->devKind * ppix->drawable.height; + int ihandle = (int)(long)fd_handle; + + ret = drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, ppix->devKind, size); + if (ret == FALSE) + return ret; + + return TRUE; +} +#endif + static Bool ScreenInit(SCREEN_INIT_ARGS_DECL) { @@ -757,6 +836,13 @@ ScreenInit(SCREEN_INIT_ARGS_DECL) if (!miSetPixmapDepths()) return FALSE; +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT + if (!dixRegisterScreenSpecificPrivateKey(pScreen, &ms->drmmode.pixmapPrivateKeyRec, + PRIVATE_PIXMAP, sizeof(msPixmapPrivRec))) { + return FALSE; + } +#endif + pScrn->memPhysBase = 0; pScrn->fbOffset = 0; @@ -816,6 +902,10 @@ ScreenInit(SCREEN_INIT_ARGS_DECL) ms->BlockHandler = pScreen->BlockHandler; pScreen->BlockHandler = msBlockHandler; +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT + pScreen->SetSharedPixmapBacking = msSetSharedPixmapBacking; +#endif + if (!xf86CrtcScreenInit(pScreen)) return FALSE; diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 9ee553ea8..5e382650e 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -138,6 +138,43 @@ static int dumb_bo_destroy(int fd, struct dumb_bo *bo) return 0; } +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT +static struct dumb_bo *dumb_get_bo_from_handle(int fd, int handle, int pitch, int size) +{ + struct dumb_bo *bo; + int ret; + + bo = calloc(1, sizeof(*bo)); + if (!bo) + return NULL; + + ret = drmPrimeFDToHandle(fd, handle, &bo->handle); + if (ret) { + free(bo); + return NULL; + } + bo->pitch = pitch; + bo->size = size; + return bo; +} +#endif + +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT +Bool drmmode_SetSlaveBO(PixmapPtr ppix, + drmmode_ptr drmmode, + int fd_handle, int pitch, int size) +{ + msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, ppix); + + ppriv->backing_bo = dumb_get_bo_from_handle(drmmode->fd, fd_handle, pitch, size); + if (!ppriv->backing_bo) + return FALSE; + + close(fd_handle); + return TRUE; +} +#endif + static void drmmode_ConvertFromKMode(ScrnInfoPtr scrn, drmModeModeInfo *kmode, @@ -274,7 +311,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, int output_count = 0; Bool ret = TRUE; int i; - int fb_id; + uint32_t fb_id; drmModeModeInfo kmode; int height; @@ -338,6 +375,13 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, drmmode_ConvertToKMode(crtc->scrn, &kmode, mode); fb_id = drmmode->fb_id; +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT + if (crtc->randr_crtc->scanout_pixmap) { + msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap); + fb_id = ppriv->fb_id; + x = y = 0; + } else +#endif if (drmmode_crtc->rotate_fb_id) { fb_id = drmmode_crtc->rotate_fb_id; x = y = 0; @@ -455,6 +499,54 @@ drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green, size, red, green, blue); } +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT +static Bool +drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix) +{ + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + drmmode_ptr drmmode = drmmode_crtc->drmmode; + msPixmapPrivPtr ppriv; + void *ptr; + + if (!ppix) { + if (crtc->randr_crtc->scanout_pixmap) { + ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap); + drmModeRmFB(drmmode->fd, ppriv->fb_id); + } + if (drmmode_crtc->slave_damage) { + DamageUnregister(&crtc->randr_crtc->scanout_pixmap->drawable, + drmmode_crtc->slave_damage); + drmmode_crtc->slave_damage = NULL; + } + return TRUE; + } + + ppriv = msGetPixmapPriv(drmmode, ppix); + if (!drmmode_crtc->slave_damage) { + drmmode_crtc->slave_damage = DamageCreate(NULL, NULL, + DamageReportNone, + TRUE, + crtc->randr_crtc->pScreen, + NULL); + } + ptr = drmmode_map_slave_bo(drmmode, ppriv); + ppix->devPrivate.ptr = ptr; + DamageRegister(&ppix->drawable, drmmode_crtc->slave_damage); + + if (ppriv->fb_id == 0) { + int r; + r = drmModeAddFB(drmmode->fd, ppix->drawable.width, + ppix->drawable.height, + ppix->drawable.depth, + ppix->drawable.bitsPerPixel, + ppix->devKind, + ppriv->backing_bo->handle, + &ppriv->fb_id); + } + return TRUE; +} +#endif + static const xf86CrtcFuncsRec drmmode_crtc_funcs = { .dpms = drmmode_crtc_dpms, .set_mode_major = drmmode_set_mode_major, @@ -466,6 +558,9 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = { .gamma_set = drmmode_crtc_gamma_set, .destroy = NULL, /* XXX */ +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT + .set_scanout_pixmap = drmmode_set_scanout_pixmap, +#endif }; static void @@ -1065,6 +1160,10 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp) /* workout clones */ drmmode_clones_init(pScrn, drmmode); +#if XF86_CRTC_VERSION >= 5 + xf86ProviderSetup(pScrn, NULL, "modesetting"); +#endif + xf86InitialConfiguration(pScrn, TRUE); return TRUE; @@ -1324,6 +1423,22 @@ void *drmmode_map_front_bo(drmmode_ptr drmmode) } +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT +void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv) +{ + int ret; + + if (ppriv->backing_bo->ptr) + return ppriv->backing_bo->ptr; + + ret = dumb_bo_map(drmmode->fd, ppriv->backing_bo); + if (ret) + return NULL; + + return ppriv->backing_bo->ptr; +} +#endif + Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) { xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index fa280bdcd..24f79607e 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -32,6 +32,11 @@ #include "libudev.h" #endif +/* the perfect storm */ +#if XF86_CRTC_VERSION >= 5 && defined(HAVE_DRMPRIMEFDTOHANDLE) && HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS +#define MODESETTING_OUTPUT_SLAVE_SUPPORT 1 +#endif + struct dumb_bo { uint32_t handle; uint32_t size; @@ -58,6 +63,9 @@ typedef struct { Bool shadow_enable; void *shadow_fb; +#ifdef HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS + DevPrivateKeyRec pixmapPrivateKeyRec; +#endif } drmmode_rec, *drmmode_ptr; typedef struct { @@ -67,6 +75,7 @@ typedef struct { struct dumb_bo *cursor_bo; unsigned rotate_fb_id; uint16_t lut_r[256], lut_g[256], lut_b[256]; + DamagePtr slave_damage; } drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; typedef struct { @@ -90,6 +99,23 @@ typedef struct { int enc_clone_mask; } drmmode_output_private_rec, *drmmode_output_private_ptr; +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT +typedef struct _msPixmapPriv { + uint32_t fb_id; + struct dumb_bo *backing_bo; /* if this pixmap is backed by a dumb bo */ +} msPixmapPrivRec, *msPixmapPrivPtr; + + +extern DevPrivateKeyRec msPixmapPrivateKeyRec; +#define msPixmapPrivateKey (&msPixmapPrivateKeyRec) + +#define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec)) + +void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv); +Bool drmmode_SetSlaveBO(PixmapPtr ppix, + drmmode_ptr drmmode, + int fd_handle, int pitch, int size); +#endif extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags); @@ -105,6 +131,7 @@ Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth, int *bpp); + #ifndef DRM_CAP_DUMB_PREFERRED_DEPTH #define DRM_CAP_DUMB_PREFERRED_DEPTH 3 #endif From e3d7d5d18e3281677890064679af459e1af108cf Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Thu, 19 Jul 2012 22:15:10 +0000 Subject: [PATCH 088/122] Implement ->driverFunc Copied from fbdev, makes it so we can run without iopl. Signed-off-by: Adam Jackson --- hw/xfree86/drivers/modesetting/driver.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 371c17114..38a1c096e 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -79,6 +79,8 @@ static Bool Probe(DriverPtr drv, int flags); static Bool ms_pci_probe(DriverPtr driver, int entity_num, struct pci_device *device, intptr_t match_data); +static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, + void *data); #ifdef XSERVER_LIBPCIACCESS static const struct pci_id_match ms_device_match[] = { @@ -105,7 +107,7 @@ _X_EXPORT DriverRec modesetting = { AvailableOptions, NULL, 0, - NULL, + ms_driver_func, ms_device_match, ms_pci_probe, #ifdef XSERVER_PLATFORM_BUS @@ -259,6 +261,21 @@ AvailableOptions(int chipid, int busid) return Options; } +static Bool +ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data) +{ + xorgHWFlags *flag; + + switch (op) { + case GET_REQUIRED_HW_INTERFACES: + flag = (CARD32 *)data; + (*flag) = 0; + return TRUE; + default: + return FALSE; + } +} + #if XSERVER_LIBPCIACCESS static Bool ms_pci_probe(DriverPtr driver, From f8eb8c1cb4f453bdbe6a81815be8ecefba2084aa Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Tue, 28 Aug 2012 11:46:47 +1000 Subject: [PATCH 090/122] modesetting: add virtual connector support [airlied: also make sure we don't crash in future.] Signed-off-by: Alon Levy Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 8 ++++++-- hw/xfree86/drivers/modesetting/drmmode_display.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 5e382650e..8d760c277 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -882,7 +882,8 @@ const char *output_names[] = { "None", "HDMI", "HDMI", "TV", - "eDP" + "eDP", + "Virtual" }; static void @@ -913,7 +914,10 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv } /* need to do smart conversion here for compat with non-kms ATI driver */ - snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1); + if (koutput->connector_type >= MS_ARRAY_SIZE(output_names)) + snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1); + else + snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1); output = xf86OutputCreate (pScrn, &drmmode_output_funcs, name); if (!output) { diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index 24f79607e..1d5522be0 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -139,5 +139,7 @@ void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth #define DRM_CAP_DUMB_PREFER_SHADOW 4 #endif +#define MS_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) + #endif From e47ad8a0aec7662970e7f81e6ee487330bf094c1 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 17 Sep 2012 11:48:14 +1000 Subject: [PATCH 091/122] modesetting: remove alloca usage again this slipped back in. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 38a1c096e..200a6d87e 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -428,10 +428,13 @@ static int dispatch_dirty_region(ScrnInfoPtr scrn, unsigned num_cliprects = REGION_NUM_RECTS(dirty); if (num_cliprects) { - drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip)); + drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip)); BoxPtr rect = REGION_RECTS(dirty); int i, ret; + if (!clip) + return -ENOMEM; + /* XXX no need for copy? */ for (i = 0; i < num_cliprects; i++, rect++) { clip[i].x1 = rect->x1; @@ -442,6 +445,7 @@ static int dispatch_dirty_region(ScrnInfoPtr scrn, /* TODO query connector property to see if this is needed */ ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects); + free(clip); DamageEmpty(damage); if (ret) { if (ret == -EINVAL) From 0b198248ecfbcb7e7c61688145be4005366da23d Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 8 Nov 2012 14:28:10 +0100 Subject: [PATCH 093/122] Remove call to miInitializeBackingStore() Recent versions of the X server no longer provide this function, which has been obsolete for over 2 years now. Signed-off-by: Thierry Reding Reviewed-by: Alex Deucher Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 200a6d87e..05b6176cb 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -901,7 +901,6 @@ ScreenInit(SCREEN_INIT_ARGS_DECL) xf86SetBlackWhitePixels(pScreen); - miInitializeBackingStore(pScreen); xf86SetBackingStore(pScreen); xf86SetSilkenMouse(pScreen); miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); From 8650ff14a52047173fa32f12f22ec6f4e38ff433 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 9 Jan 2013 12:48:30 +1000 Subject: [PATCH 094/122] modesetting: fix crashes caused by udev race conditions So the kernel removes the device, and the driver processes the first udev event, and gets no output back from the kernel, so it check and don't fall over. This fixes a couple of crashes seen when hotplugging USB devices. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 8d760c277..42cd5ac26 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -589,6 +589,8 @@ drmmode_output_detect(xf86OutputPtr output) drmModeFreeConnector(drmmode_output->mode_output); drmmode_output->mode_output = drmModeGetConnector(drmmode->fd, drmmode_output->output_id); + if (!drmmode_output->mode_output) + return XF86OutputStatusDisconnected; switch (drmmode_output->mode_output->connection) { case DRM_MODE_CONNECTED: @@ -683,6 +685,9 @@ drmmode_output_dpms(xf86OutputPtr output, int mode) drmModeConnectorPtr koutput = drmmode_output->mode_output; drmmode_ptr drmmode = drmmode_output->drmmode; + if (!koutput) + return; + drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id, drmmode_output->dpms_enum_id, mode); return; From ac34281b8a487640c61f258ae45a6f17a4fb3cc0 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 7 Feb 2013 12:24:20 +1000 Subject: [PATCH 096/122] modesetting: provide dummy hooks for shadow Since in some wierd cases the server can call these without checking they exist. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 42cd5ac26..63cecc3cf 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -547,6 +547,17 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix) } #endif +static void *drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height) +{ + return NULL; +} + +static PixmapPtr drmmode_shadow_create(xf86CrtcPtr crtc, void *data, int width, + int height) +{ + return NULL; +} + static const xf86CrtcFuncsRec drmmode_crtc_funcs = { .dpms = drmmode_crtc_dpms, .set_mode_major = drmmode_set_mode_major, @@ -561,6 +572,8 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = { #ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT .set_scanout_pixmap = drmmode_set_scanout_pixmap, #endif + .shadow_allocate = drmmode_shadow_allocate, + .shadow_create = drmmode_shadow_create, }; static void From 75815dbb373d5a74d57cbec9d469f9f88a8ee3ef Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 3 Dec 2012 13:25:19 +0000 Subject: [PATCH 097/122] Add missing GTF modes A fixed-mode output device like a panel will often only inform of its preferred mode through its EDID. However, the driver will adjust user specified modes for display through use of a panel-fitter allowing greater flexibility in upscaling. This is often used by games to set a low resolution for performance and use the panel fitter to fill the screen. v2: Use the presence of the 'scaling mode' connector property as an indication that a panel fitter is attached to that pipe. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=55564 --- .../drivers/modesetting/drmmode_display.c | 75 ++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 63cecc3cf..e8ebef17c 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -626,6 +626,78 @@ drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes) return MODE_OK; } +static Bool +has_panel_fitter(xf86OutputPtr output) +{ + drmmode_output_private_ptr drmmode_output = output->driver_private; + drmModeConnectorPtr koutput = drmmode_output->mode_output; + drmmode_ptr drmmode = drmmode_output->drmmode; + int i; + + /* Presume that if the output supports scaling, then we have a + * panel fitter capable of adjust any mode to suit. + */ + for (i = 0; i < koutput->count_props; i++) { + drmModePropertyPtr props; + Bool found = FALSE; + + props = drmModeGetProperty(drmmode->fd, koutput->props[i]); + if (props) { + found = strcmp(props->name, "scaling mode") == 0; + drmModeFreeProperty(props); + } + + if (found) + return TRUE; + } + + return FALSE; +} + +static DisplayModePtr +drmmode_output_add_gtf_modes(xf86OutputPtr output, + DisplayModePtr Modes) +{ + xf86MonPtr mon = output->MonInfo; + DisplayModePtr i, m, preferred = NULL; + int max_x = 0, max_y = 0; + float max_vrefresh = 0.0; + + if (mon && GTF_SUPPORTED(mon->features.msc)) + return Modes; + + if (!has_panel_fitter(output)) + return Modes; + + for (m = Modes; m; m = m->next) { + if (m->type & M_T_PREFERRED) + preferred = m; + max_x = max(max_x, m->HDisplay); + max_y = max(max_y, m->VDisplay); + max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(m)); + } + + max_vrefresh = max(max_vrefresh, 60.0); + max_vrefresh *= (1 + SYNC_TOLERANCE); + + m = xf86GetDefaultModes(); + xf86ValidateModesSize(output->scrn, m, max_x, max_y, 0); + + for (i = m; i; i = i->next) { + if (xf86ModeVRefresh(i) > max_vrefresh) + i->status = MODE_VSYNC; + if (preferred && + i->HDisplay >= preferred->HDisplay && + i->VDisplay >= preferred->VDisplay && + xf86ModeVRefresh(i) >= xf86ModeVRefresh(preferred)) + i->status = MODE_VSYNC; + } + + xf86PruneInvalidModes(output->scrn, &m, FALSE); + + return xf86ModesAdd(Modes, m); +} + static DisplayModePtr drmmode_output_get_modes(xf86OutputPtr output) { @@ -666,7 +738,8 @@ drmmode_output_get_modes(xf86OutputPtr output) Modes = xf86ModesAdd(Modes, Mode); } - return Modes; + + return drmmode_output_add_gtf_modes(output, Modes); } static void From 1754973206c09a901747e71d4abdf666293da59e Mon Sep 17 00:00:00 2001 From: Aaron Plattner Date: Wed, 20 Feb 2013 17:27:16 -0800 Subject: [PATCH 099/122] modesetting: match PCI class 3, any subclass If a device is not primary, the PCI device match fails because the xf86-video-modesetting driver looks specifically for a PCI class match of 0x30000 with a mask of 0xffffff. This fails to match, for example, a non-primary Intel VGA device, because it is reported as having a class of 0x38000. Fix that by ignoring the low 16 bits of the class in the pci_id_match table. Signed-off-by: Aaron Plattner Reviewed on IRC by Adam Jackson --- hw/xfree86/drivers/modesetting/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 05b6176cb..87ba272a6 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -86,7 +86,7 @@ static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, static const struct pci_id_match ms_device_match[] = { { PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, - 0x00030000, 0x00ffffff, 0 + 0x00030000, 0x00ff0000, 0 }, { 0, 0, 0 }, From 6b79a8791d35bbd1a13ebdec1c582f66c559c039 Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Tue, 26 Mar 2013 15:19:33 +0100 Subject: [PATCH 100/122] modesetting: clean up leaks Signed-off-by: Maarten Lankhorst --- hw/xfree86/drivers/modesetting/driver.c | 30 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 87ba272a6..06d6d53c4 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -206,7 +206,7 @@ static Bool probe_hw(char *dev) int fd = open_hw(dev); if (fd != -1) { close(fd); - return TRUE; + return TRUE; } return FALSE; } @@ -530,15 +530,27 @@ static void msBlockHandler(BLOCKHANDLER_ARGS_DECL) static void FreeRec(ScrnInfoPtr pScrn) { + modesettingPtr ms; + if (!pScrn) - return; - - if (!pScrn->driverPrivate) - return; - - free(pScrn->driverPrivate); + return; + ms = modesettingPTR(pScrn); + if (!ms) + return; pScrn->driverPrivate = NULL; + + if (ms->fd > 0) { + int ret; + + if (ms->pEnt->location.type == BUS_PCI) + ret = drmClose(ms->fd); + else + ret = close(ms->fd); + } + free(ms->Options); + free(ms); + } static Bool @@ -596,8 +608,8 @@ PreInit(ScrnInfoPtr pScrn, int flags) #if XSERVER_PLATFORM_BUS if (pEnt->location.type == BUS_PLATFORM) { - char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH); - ms->fd = open_hw(path); + char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH); + ms->fd = open_hw(path); } else #endif From 862bc2836835b93f4b2cfd2de6ca344f65484a00 Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Tue, 26 Mar 2013 15:19:52 +0100 Subject: [PATCH 101/122] modesetting: return null for get_modes if output could not be retrieved Signed-off-by: Maarten Lankhorst --- hw/xfree86/drivers/modesetting/drmmode_display.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index e8ebef17c..2dc7576ac 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -709,6 +709,9 @@ drmmode_output_get_modes(xf86OutputPtr output) drmModePropertyPtr props; xf86MonPtr mon = NULL; + if (!koutput) + return NULL; + /* look for an EDID property */ for (i = 0; i < koutput->count_props; i++) { props = drmModeGetProperty(drmmode->fd, koutput->props[i]); From c64fa9a2961f82719cc7734a4222f31297a2e593 Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Wed, 3 Apr 2013 12:08:44 +0200 Subject: [PATCH 103/122] support 32 bpp pixmaps when 24 bpp fb is used. Fixes background corruption in ubuntu. Signed-off-by: Maarten Lankhorst --- hw/xfree86/drivers/modesetting/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 06d6d53c4..742aaddec 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -650,7 +650,7 @@ PreInit(ScrnInfoPtr pScrn, int flags) #endif drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp); if (defaultdepth == 24 && defaultbpp == 24) - bppflags = Support24bppFb; + bppflags = SupportConvert32to24 | Support24bppFb; else bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb; From d4791dd97b85ddac1295761bf6ab4f10c08346d7 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 11 Jun 2013 10:29:25 +1000 Subject: [PATCH 104/122] modesetting: fix adjust frame crash When SDL called this it was totally broken, actually hook up to the underlying drmmode function. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64808 Thanks to Peter Wu for harassing me. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 11 ++--------- hw/xfree86/drivers/modesetting/drmmode_display.c | 2 +- hw/xfree86/drivers/modesetting/drmmode_display.h | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 742aaddec..c3d78beae 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -956,16 +956,9 @@ static void AdjustFrame(ADJUST_FRAME_ARGS_DECL) { SCRN_INFO_PTR(arg); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - xf86OutputPtr output = config->output[config->compat_output]; - xf86CrtcPtr crtc = output->crtc; + modesettingPtr ms = modesettingPTR(pScrn); - if (crtc && crtc->enabled) { - crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x, - y); - crtc->x = output->initial_x + x; - crtc->y = output->initial_y + y; - } + drmmode_adjust_frame(pScrn, &ms->drmmode, x, y); } static void diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 2dc7576ac..ce90cea76 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -1267,7 +1267,7 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp) return TRUE; } -void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags) +void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y) { xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); xf86OutputPtr output = config->output[config->compat_output]; diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index 1d5522be0..adf4b99aa 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -118,7 +118,7 @@ Bool drmmode_SetSlaveBO(PixmapPtr ppix, #endif extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); -void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags); +void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y); extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode); extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); From 525ac7fb9a0d639253fc5d6556db3edb7239f932 Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Wed, 12 Jun 2013 14:05:19 +0200 Subject: [PATCH 105/122] modesetting: probe only succeeds if connectors are detected This will prevent modesetting being used for outputless intel or nvidia cards. Signed-off-by: Maarten Lankhorst --- hw/xfree86/drivers/modesetting/driver.c | 28 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index c3d78beae..cc526f6a5 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -201,12 +201,25 @@ static int open_hw(char *dev) return fd; } +static int check_outputs(int fd) +{ + drmModeResPtr res = drmModeGetResources(fd); + int ret; + + if (!res) + return FALSE; + ret = res->count_connectors > 0; + drmModeFreeResources(res); + return ret; +} + static Bool probe_hw(char *dev) { int fd = open_hw(dev); if (fd != -1) { + int ret = check_outputs(fd); close(fd); - return TRUE; + return ret; } return FALSE; } @@ -226,7 +239,7 @@ ms_DRICreatePCIBusID(const struct pci_device *dev) static Bool probe_hw_pci(char *dev, struct pci_device *pdev) { - int fd = open_hw(dev); + int ret = FALSE, fd = open_hw(dev); char *id, *devid; drmSetVersion sv; @@ -247,13 +260,12 @@ static Bool probe_hw_pci(char *dev, struct pci_device *pdev) devid = ms_DRICreatePCIBusID(pdev); close(fd); - if (!id || !devid) - return FALSE; + if (id && devid && !strcmp(id, devid)) + ret = check_outputs(fd); - if (!strcmp(id, devid)) - return TRUE; - - return FALSE; + free(id); + free(devid); + return ret; } static const OptionInfoRec * AvailableOptions(int chipid, int busid) From 836daf4c7a276108a9f950e524828744aeda0a3c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 31 Jul 2013 11:24:48 +1000 Subject: [PATCH 107/122] modesetting: change output names for secondary GPUs if we are a secondary GPU modify the output name to avoid clashes. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index ce90cea76..4fb4d21fe 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -1010,6 +1010,10 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv /* need to do smart conversion here for compat with non-kms ATI driver */ if (koutput->connector_type >= MS_ARRAY_SIZE(output_names)) snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1); +#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT + else if (pScrn->is_gpu) + snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id - 1); +#endif else snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1); From d6ffce4b0e2376e1f8f04ee70b323a6aea3e517e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 15 Nov 2013 13:26:36 +0900 Subject: [PATCH 108/122] Clean up compiler warnings. Add const to any immutable string pointers. Rename 'range' to 'prop_range' to avoid redefined warning. Eliminate some unused return values. Signed-off-by: Keith Packard --- hw/xfree86/drivers/modesetting/driver.c | 16 +++++++------ .../drivers/modesetting/drmmode_display.c | 23 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index cc526f6a5..b84624ea5 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -183,7 +183,7 @@ Identify(int flags) Chipsets); } -static int open_hw(char *dev) +static int open_hw(const char *dev) { int fd; if (dev) @@ -213,7 +213,7 @@ static int check_outputs(int fd) return ret; } -static Bool probe_hw(char *dev) +static Bool probe_hw(const char *dev) { int fd = open_hw(dev); if (fd != -1) { @@ -237,7 +237,7 @@ ms_DRICreatePCIBusID(const struct pci_device *dev) } -static Bool probe_hw_pci(char *dev, struct pci_device *pdev) +static Bool probe_hw_pci(const char *dev, struct pci_device *pdev) { int ret = FALSE, fd = open_hw(dev); char *id, *devid; @@ -298,7 +298,7 @@ ms_pci_probe(DriverPtr driver, scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL, NULL, NULL, NULL, NULL, NULL); if (scrn) { - char *devpath; + const char *devpath; GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0], scrn->entityInstanceList[0]); @@ -335,7 +335,7 @@ ms_platform_probe(DriverPtr driver, int entity_num, int flags, struct xf86_platform_device *dev, intptr_t match_data) { ScrnInfoPtr scrn = NULL; - char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH); + const char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH); int scr_flags = 0; if (flags & PLATFORM_PROBE_GPU_SCREEN) @@ -369,7 +369,7 @@ Probe(DriverPtr drv, int flags) int i, numDevSections; GDevPtr *devSections; Bool foundScreen = FALSE; - char *dev; + const char *dev; ScrnInfoPtr scrn = NULL; /* For now, just bail out for PROBE_DETECT. */ @@ -559,6 +559,7 @@ FreeRec(ScrnInfoPtr pScrn) ret = drmClose(ms->fd); else ret = close(ms->fd); + (void) ret; } free(ms->Options); free(ms); @@ -572,7 +573,8 @@ PreInit(ScrnInfoPtr pScrn, int flags) rgb defaultWeight = { 0, 0, 0 }; EntityInfoPtr pEnt; EntPtr msEnt = NULL; - char *BusID = NULL, *devicename; + char *BusID = NULL; + const char *devicename; Bool prefer_shadow = TRUE; uint64_t value = 0; int ret; diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 4fb4d21fe..773ec4c1c 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -534,14 +534,13 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix) DamageRegister(&ppix->drawable, drmmode_crtc->slave_damage); if (ppriv->fb_id == 0) { - int r; - r = drmModeAddFB(drmmode->fd, ppix->drawable.width, - ppix->drawable.height, - ppix->drawable.depth, - ppix->drawable.bitsPerPixel, - ppix->devKind, - ppriv->backing_bo->handle, - &ppriv->fb_id); + drmModeAddFB(drmmode->fd, ppix->drawable.width, + ppix->drawable.height, + ppix->drawable.depth, + ppix->drawable.bitsPerPixel, + ppix->devKind, + ppriv->backing_bo->handle, + &ppriv->fb_id); } return TRUE; } @@ -830,7 +829,7 @@ drmmode_output_create_resources(xf86OutputPtr output) drmmode_prop = p->mode_prop; if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) { - INT32 range[2]; + INT32 prop_range[2]; INT32 value = p->value; p->num_atoms = 1; @@ -838,12 +837,12 @@ drmmode_output_create_resources(xf86OutputPtr output) if (!p->atoms) continue; p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE); - range[0] = drmmode_prop->values[0]; - range[1] = drmmode_prop->values[1]; + prop_range[0] = drmmode_prop->values[0]; + prop_range[1] = drmmode_prop->values[1]; err = RRConfigureOutputProperty(output->randr_output, p->atoms[0], FALSE, TRUE, drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE, - 2, range); + 2, prop_range); if (err != 0) { xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, "RRConfigureOutputProperty error, %d\n", err); From a307ac27382dd0c377cd1a436cb25cb5aaa54416 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 15 Nov 2013 13:39:52 +0900 Subject: [PATCH 109/122] Handle new DamageUnregister API which has only one argument API change in 1.15 Signed-off-by: Keith Packard --- hw/xfree86/drivers/modesetting/drmmode_display.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index adf4b99aa..745c484d7 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -37,6 +37,10 @@ #define MODESETTING_OUTPUT_SLAVE_SUPPORT 1 #endif +#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0) +#define DamageUnregister(d, dd) DamageUnregister(dd) +#endif + struct dumb_bo { uint32_t handle; uint32_t size; From 190289f6393191bb3c58067ce1df994809475077 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Tue, 26 Nov 2013 17:08:02 +0100 Subject: [PATCH 110/122] Staticise and constify output names This array isn't used anywhere outside this file, so it can be made static. While at it, make the array const as well. Signed-off-by: Thierry Reding Reviewed-by: Aaron Plattner --- .../drivers/modesetting/drmmode_display.c | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 773ec4c1c..a34377843 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -961,22 +961,22 @@ static int subpixel_conv_table[7] = { 0, SubPixelUnknown, SubPixelVerticalBGR, SubPixelNone }; -const char *output_names[] = { "None", - "VGA", - "DVI", - "DVI", - "DVI", - "Composite", - "S-video", - "LVDS", - "CTV", - "DIN", - "DisplayPort", - "HDMI", - "HDMI", - "TV", - "eDP", - "Virtual" +static const char * const output_names[] = { "None", + "VGA", + "DVI", + "DVI", + "DVI", + "Composite", + "S-video", + "LVDS", + "CTV", + "DIN", + "DisplayPort", + "HDMI", + "HDMI", + "TV", + "eDP", + "Virtual", }; static void From 59e324abd7cbda5d301b7b67125cd6d96684f000 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Tue, 26 Nov 2013 17:08:03 +0100 Subject: [PATCH 111/122] Properly identify DSI outputs Newer Linux kernels support DSI outputs. To be able to identify them properly, add DSI to the list of output names. Reviewed-by: Aaron Plattner Signed-off-by: Thierry Reding --- hw/xfree86/drivers/modesetting/drmmode_display.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index a34377843..25641ce36 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -977,6 +977,7 @@ static const char * const output_names[] = { "None", "TV", "eDP", "Virtual", + "DSI", }; static void From 02fbae85e7aa17b213e1411fe558256998d367c4 Mon Sep 17 00:00:00 2001 From: Alex Deucher Date: Wed, 12 Feb 2014 13:06:51 -0500 Subject: [PATCH 113/122] modesetting: query cursor size from the kernel Use new drm caps. This allows hw cursors to work correctly on gpus with non-64x64 cursors. Signed-off-by: Alex Deucher --- hw/xfree86/drivers/modesetting/driver.c | 21 ++++++++++++++++++- hw/xfree86/drivers/modesetting/driver.h | 1 + .../drivers/modesetting/drmmode_display.c | 20 +++++++++++++----- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index b84624ea5..b28622a22 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -566,6 +566,14 @@ FreeRec(ScrnInfoPtr pScrn) } +#ifndef DRM_CAP_CURSOR_WIDTH +#define DRM_CAP_CURSOR_WIDTH 0x8 +#endif + +#ifndef DRM_CAP_CURSOR_HEIGHT +#define DRM_CAP_CURSOR_HEIGHT 0x9 +#endif + static Bool PreInit(ScrnInfoPtr pScrn, int flags) { @@ -706,6 +714,17 @@ PreInit(ScrnInfoPtr pScrn, int flags) prefer_shadow = !!value; } + ms->cursor_width = 64; + ms->cursor_height = 64; + ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_WIDTH, &value); + if (!ret) { + ms->cursor_width = value; + } + ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_HEIGHT, &value); + if (!ret) { + ms->cursor_height = value; + } + ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow); xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO"); @@ -933,7 +952,7 @@ ScreenInit(SCREEN_INIT_ARGS_DECL) /* Need to extend HWcursor support to handle mask interleave */ if (!ms->drmmode.sw_cursor) - xf86_cursors_init(pScreen, 64, 64, + xf86_cursors_init(pScreen, ms->cursor_width, ms->cursor_height, HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | HARDWARE_CURSOR_ARGB); diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index 79561c811..e84d748d6 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -76,6 +76,7 @@ typedef struct _modesettingRec DamagePtr damage; Bool dirty_enabled; + uint32_t cursor_width, cursor_height; } modesettingRec, *modesettingPtr; #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 25641ce36..ccfd75fa6 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -52,6 +52,8 @@ #endif #include "compat-api.h" +#include "driver.h" + static struct dumb_bo *dumb_bo_create(int fd, const unsigned width, const unsigned height, const unsigned bpp) @@ -445,6 +447,7 @@ drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y) static void drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) { + modesettingPtr ms = modesettingPTR(crtc->scrn); drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; int i; uint32_t *ptr; @@ -453,10 +456,11 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) /* cursor should be mapped already */ ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr); - for (i = 0; i < 64 * 64; i++) + for (i = 0; i < ms->cursor_width * ms->cursor_height; i++) ptr[i] = image[i];// cpu_to_le32(image[i]); - ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64); + ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, + ms->cursor_width, ms->cursor_height); if (ret) { xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; @@ -471,21 +475,25 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image) static void drmmode_hide_cursor (xf86CrtcPtr crtc) { + modesettingPtr ms = modesettingPTR(crtc->scrn); drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; drmmode_ptr drmmode = drmmode_crtc->drmmode; - drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, 64, 64); + drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, + ms->cursor_width, ms->cursor_height); } static void drmmode_show_cursor (xf86CrtcPtr crtc) { + modesettingPtr ms = modesettingPTR(crtc->scrn); drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; drmmode_ptr drmmode = drmmode_crtc->drmmode; uint32_t handle = drmmode_crtc->cursor_bo->handle; - drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64); + drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, + ms->cursor_width, ms->cursor_height); } static void @@ -1485,6 +1493,7 @@ void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode) /* create front and cursor BOs */ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) { + modesettingPtr ms = modesettingPTR(pScrn); xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); int width; int height; @@ -1500,7 +1509,8 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) return FALSE; pScrn->displayWidth = drmmode->front_bo->pitch / cpp; - width = height = 64; + width = ms->cursor_width; + height = ms->cursor_height; bpp = 32; for (i = 0; i < xf86_config->num_crtc; i++) { xf86CrtcPtr crtc = xf86_config->crtc[i]; From 4aab7aa7c1a15af7211996fa30e17a645f120ff9 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 21 Feb 2014 12:48:42 +1000 Subject: [PATCH 114/122] modesetting: move closing fd to after we check outputs On something like cirrus, start X, then attempt to start a second X while the first is running, if fbdev is installed it'll fail hard. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index b28622a22..4a74ecef6 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -258,11 +258,11 @@ static Bool probe_hw_pci(const char *dev, struct pci_device *pdev) id = drmGetBusid(fd); devid = ms_DRICreatePCIBusID(pdev); - close(fd); if (id && devid && !strcmp(id, devid)) ret = check_outputs(fd); + close(fd); free(id); free(devid); return ret; From fac2bcf1da09fba8bc8b22631e31f3c5b2737efd Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 20 Jan 2014 11:06:42 +1000 Subject: [PATCH 115/122] modesetting: try and use hotspot cursor support Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index ccfd75fa6..5b796e0cd 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -43,6 +43,8 @@ #include "xf86Crtc.h" #include "drmmode_display.h" +#include + /* DPMS */ #ifdef HAVE_XEXTPROTO_71 #include @@ -491,6 +493,18 @@ drmmode_show_cursor (xf86CrtcPtr crtc) drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; drmmode_ptr drmmode = drmmode_crtc->drmmode; uint32_t handle = drmmode_crtc->cursor_bo->handle; + static Bool use_set_cursor2 = TRUE; + + if (use_set_cursor2) { + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + CursorPtr cursor = xf86_config->cursor; + int ret; + ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height, cursor->bits->xhot, cursor->bits->yhot); + if (ret == -ENOSYS) + use_set_cursor2 = FALSE; + else + return; + } drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height); From 2029c028fcffbe1aa175ab75636ae954a211c82a Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Tue, 25 Feb 2014 09:06:55 -0500 Subject: [PATCH 116/122] modesetting: Don't (brokenly) double-track software cursor Signed-off-by: Adam Jackson --- hw/xfree86/drivers/modesetting/driver.c | 2 +- hw/xfree86/drivers/modesetting/driver.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 4a74ecef6..0f9190a43 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -801,7 +801,7 @@ CreateScreenResources(ScreenPtr pScreen) drmmode_uevent_init(pScrn, &ms->drmmode); - if (!ms->SWCursor) + if (!ms->drmmode.sw_cursor) drmmode_map_cursor_bos(pScrn, &ms->drmmode); pixels = drmmode_map_front_bo(&ms->drmmode); if (!pixels) diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h index e84d748d6..450b29c2b 100644 --- a/hw/xfree86/drivers/modesetting/driver.h +++ b/hw/xfree86/drivers/modesetting/driver.h @@ -59,7 +59,6 @@ typedef struct _modesettingRec #endif Bool noAccel; - Bool SWCursor; CloseScreenProcPtr CloseScreen; /* Broken-out options. */ From 98f59a33dfc2d47a57c68420f226dc0c17992164 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 28 Feb 2014 12:04:30 +1000 Subject: [PATCH 117/122] modesetting: fix cursor rendering with hotspots. older kernels report EINVAL not ENOSYS, doh. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 5b796e0cd..28a4abb38 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -500,7 +500,7 @@ drmmode_show_cursor (xf86CrtcPtr crtc) CursorPtr cursor = xf86_config->cursor; int ret; ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height, cursor->bits->xhot, cursor->bits->yhot); - if (ret == -ENOSYS) + if (ret == -EINVAL) use_set_cursor2 = FALSE; else return; From f073b5e58262d5fcc0102d773091d11d175227ce Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 18 Mar 2014 15:48:22 +0100 Subject: [PATCH 118/122] Add support for server managed fds Signed-off-by: Hans de Goede --- hw/xfree86/drivers/modesetting/driver.c | 77 ++++++++++++++++++++----- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 0f9190a43..b5fcdafd4 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -213,9 +213,20 @@ static int check_outputs(int fd) return ret; } -static Bool probe_hw(const char *dev) +static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev) { - int fd = open_hw(dev); + int fd; + +#if XSERVER_PLATFORM_BUS + if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) { + fd = xf86_get_platform_device_int_attrib(platform_dev, ODEV_ATTRIB_FD, -1); + if (fd == -1) + return FALSE; + return check_outputs(fd); + } +#endif + + fd = open_hw(dev); if (fd != -1) { int ret = check_outputs(fd); close(fd); @@ -283,6 +294,10 @@ ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data) flag = (CARD32 *)data; (*flag) = 0; return TRUE; +#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,15,99,902,0) + case SUPPORTS_SERVER_FDS: + return TRUE; +#endif default: return FALSE; } @@ -341,7 +356,7 @@ ms_platform_probe(DriverPtr driver, if (flags & PLATFORM_PROBE_GPU_SCREEN) scr_flags = XF86_ALLOCATE_GPU_SCREEN; - if (probe_hw(path)) { + if (probe_hw(path, dev)) { scrn = xf86AllocateScreen(driver, scr_flags); xf86AddEntityToScreen(scrn, entity_num); @@ -387,7 +402,7 @@ Probe(DriverPtr drv, int flags) for (i = 0; i < numDevSections; i++) { dev = xf86FindOptionValue(devSections[i]->options,"kmsdev"); - if (probe_hw(dev)) { + if (probe_hw(dev, NULL)) { int entity; entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE); scrn = xf86ConfigFbEntity(scrn, 0, entity, @@ -558,6 +573,10 @@ FreeRec(ScrnInfoPtr pScrn) if (ms->pEnt->location.type == BUS_PCI) ret = drmClose(ms->fd); else +#ifdef XF86_PDEV_SERVER_FD + if (!(ms->pEnt->location.type == BUS_PLATFORM && + (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))) +#endif ret = close(ms->fd); (void) ret; } @@ -630,8 +649,15 @@ PreInit(ScrnInfoPtr pScrn, int flags) #if XSERVER_PLATFORM_BUS if (pEnt->location.type == BUS_PLATFORM) { - char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH); - ms->fd = open_hw(path); +#ifdef XF86_PDEV_SERVER_FD + if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD) + ms->fd = xf86_get_platform_device_int_attrib(pEnt->location.id.plat, ODEV_ATTRIB_FD, -1); + else +#endif + { + char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH); + ms->fd = open_hw(path); + } } else #endif @@ -864,22 +890,38 @@ msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle) } #endif +static Bool +SetMaster(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + int ret; + +#ifdef XF86_PDEV_SERVER_FD + if (ms->pEnt->location.type == BUS_PLATFORM && + (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)) + return TRUE; +#endif + + ret = drmSetMaster(ms->fd); + if (ret) + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "drmSetMaster failed: %s\n", + strerror(errno)); + + return ret == 0; +} + static Bool ScreenInit(SCREEN_INIT_ARGS_DECL) { ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); modesettingPtr ms = modesettingPTR(pScrn); VisualPtr visual; - int ret; pScrn->pScreen = pScreen; - ret = drmSetMaster(ms->fd); - if (ret) { - ErrorF("Unable to set master\n"); + if (!SetMaster(pScrn)) return FALSE; - } - + /* HW dependent - FIXME */ pScrn->displayWidth = pScrn->virtualX; if (!drmmode_create_initial_bos(pScrn, &ms->drmmode)) @@ -1010,6 +1052,12 @@ LeaveVT(VT_FUNC_ARGS_DECL) pScrn->vtSema = FALSE; +#ifdef XF86_PDEV_SERVER_FD + if (ms->pEnt->location.type == BUS_PLATFORM && + (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)) + return; +#endif + drmDropMaster(ms->fd); } @@ -1024,10 +1072,7 @@ EnterVT(VT_FUNC_ARGS_DECL) pScrn->vtSema = TRUE; - if (drmSetMaster(ms->fd)) { - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "drmSetMaster failed: %s\n", - strerror(errno)); - } + SetMaster(pScrn); if (!drmmode_set_desired_modes(pScrn, &ms->drmmode)) return FALSE; From 795af9ff017113788b4bb6d9dbeb5370c5b8165c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 2 May 2014 13:14:30 +1000 Subject: [PATCH 119/122] modesetting: fix use after free. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/drmmode_display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 28a4abb38..c533324df 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -778,11 +778,11 @@ drmmode_output_destroy(xf86OutputPtr output) drmModeFreeProperty(drmmode_output->props[i].mode_prop); free(drmmode_output->props[i].atoms); } + free(drmmode_output->props); for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) { drmModeFreeEncoder(drmmode_output->mode_encoders[i]); - free(drmmode_output->mode_encoders); } - free(drmmode_output->props); + free(drmmode_output->mode_encoders); drmModeFreeConnector(drmmode_output->mode_output); free(drmmode_output); output->driver_private = NULL; From 219ce9e6c34bfc946005fb8e81ab4fb74ae1d25a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 2 May 2014 13:16:05 +1000 Subject: [PATCH 120/122] modesetting: fix build regression against older servers. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index b5fcdafd4..21274a97a 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -217,7 +217,7 @@ static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev) { int fd; -#if XSERVER_PLATFORM_BUS +#if XF86_PDEV_SERVER_FD if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) { fd = xf86_get_platform_device_int_attrib(platform_dev, ODEV_ATTRIB_FD, -1); if (fd == -1) From 042bae0b49f6192ec3cb8bb51423c90c44638134 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 21 May 2014 10:16:39 -0400 Subject: [PATCH 121/122] Use own thunk function instead of shadowUpdatePackedWeak I plan to remove the Weak functions from a future server. Signed-off-by: Adam Jackson --- hw/xfree86/drivers/modesetting/driver.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 21274a97a..d99b02730 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -810,6 +810,12 @@ msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode, return ((uint8_t *)ms->drmmode.front_bo->ptr + row * stride + offset); } +static void +msUpdatePacked(ScreenPtr pScreen, shadowBufPtr pBuf) +{ + shadowUpdatePacked(pScreen, pBuf); +} + static Bool CreateScreenResources(ScreenPtr pScreen) { @@ -842,7 +848,7 @@ CreateScreenResources(ScreenPtr pScreen) FatalError("Couldn't adjust screen pixmap\n"); if (ms->drmmode.shadow_enable) { - if (!shadowAdd(pScreen, rootPixmap, shadowUpdatePackedWeak(), + if (!shadowAdd(pScreen, rootPixmap, msUpdatePacked, msShadowWindow, 0, 0)) return FALSE; }