From 6bd6ca43176dccac91fd5ddffeb0da81f0bcd6f6 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 20 Jul 2009 01:16:53 +0100 Subject: Initial KMS stuff --- src/glamo-driver.c | 90 +++++++++++++++++++++++++++++++++----------------- src/glamo-kms-driver.c | 51 ++++++++++++++++++++++++++++ src/glamo-kms-driver.h | 31 +++++++++++++++++ 3 files changed, 141 insertions(+), 31 deletions(-) create mode 100644 src/glamo-kms-driver.c create mode 100644 src/glamo-kms-driver.h diff --git a/src/glamo-driver.c b/src/glamo-driver.c index 0a42eb3..9debf57 100644 --- a/src/glamo-driver.c +++ b/src/glamo-driver.c @@ -292,42 +292,71 @@ GlamoProbe(DriverPtr drv, int flags) if (flags & PROBE_DETECT) return FALSE; - if ((numDevSections = xf86MatchDevice(GLAMO_DRIVER_NAME, &devSections)) <= 0) + numDevSections = xf86MatchDevice(GLAMO_DRIVER_NAME, &devSections); + if (numDevSections <= 0) return FALSE; - if (!xf86LoadDrvSubModule(drv, "fbdevhw")) - return FALSE; + /* Is today a good day to use KMS? */ + if ( GlamoKernelModesettingAvailable(pScrn) ) { + + foundScreen = TRUE; + + pScrn->driverVersion = GLAMO_VERSION; + pScrn->driverName = GLAMO_DRIVER_NAME; + pScrn->name = GLAMO_NAME; + pScrn->PreInit = GlamoKMSPreInit; + pScrn->ScreenInit = GlamoKMSScreenInit; + pScrn->SwitchMode = GlamoKMSSwitchMode; + pScrn->AdjustFrame = GlamoKMSAdjustFrame; + pScrn->EnterVT = GlamoKMSEnterVT; + pScrn->LeaveVT = GlamoKMSLeaveVT; + pScrn->ValidMode = GlamoKMSValidMode; - for (i = 0; i < numDevSections; i++) { - dev = xf86FindOptionValue(devSections[i]->options, "Device"); - if (fbdevHWProbe(NULL, dev, NULL)) { - int entity; - pScrn = NULL; - - entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE); - pScrn = xf86ConfigFbEntity(pScrn,0,entity, - NULL, NULL, NULL, NULL); - - if (pScrn) { - foundScreen = TRUE; - - pScrn->driverVersion = GLAMO_VERSION; - pScrn->driverName = GLAMO_DRIVER_NAME; - pScrn->name = GLAMO_NAME; - pScrn->Probe = GlamoProbe; - pScrn->PreInit = GlamoPreInit; - pScrn->ScreenInit = GlamoScreenInit; - pScrn->SwitchMode = GlamoSwitchMode; - pScrn->AdjustFrame = fbdevHWAdjustFrameWeak(); - pScrn->EnterVT = GlamoEnterVT; - pScrn->LeaveVT = GlamoLeaveVT; - pScrn->ValidMode = fbdevHWValidModeWeak(); - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "using %s\n", dev ? dev : "default device"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using KMS!"); + + } else { + + if (!xf86LoadDrvSubModule(drv, "fbdevhw")) + return FALSE; + + for (i = 0; i < numDevSections; i++) { + dev = xf86FindOptionValue(devSections[i]->options, + "Device"); + if (fbdevHWProbe(NULL, dev, NULL)) { + int entity; + pScrn = NULL; + + entity = xf86ClaimFbSlot(drv, 0, devSections[i], + TRUE); + pScrn = xf86ConfigFbEntity(pScrn,0,entity, NULL, + NULL, NULL, NULL); + + if (pScrn) { + foundScreen = TRUE; + + pScrn->driverVersion = GLAMO_VERSION; + pScrn->driverName = GLAMO_DRIVER_NAME; + pScrn->name = GLAMO_NAME; + pScrn->Probe = GlamoProbe; + pScrn->PreInit = GlamoPreInit; + pScrn->ScreenInit = GlamoScreenInit; + pScrn->SwitchMode = GlamoSwitchMode; + pScrn->AdjustFrame + = fbdevHWAdjustFrameWeak(); + pScrn->EnterVT = GlamoEnterVT; + pScrn->LeaveVT = GlamoLeaveVT; + pScrn->ValidMode + = fbdevHWValidModeWeak(); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "using %s\n", + dev ? dev : "default device"); + } } } + } + xfree(devSections); TRACE("probe done"); return foundScreen; @@ -806,4 +835,3 @@ GlamoLoadColormap(ScrnInfoPtr pScrn, int numColors, int *indices, (colors[indices[i]].blue >> 3); } } - diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c new file mode 100644 index 0000000..5102f4b --- /dev/null +++ b/src/glamo-kms-driver.c @@ -0,0 +1,51 @@ +/* + * KMS Support for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags) +{ +} + +Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, + char **argv) +{ +} + +Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags) +{ +} + +void AdjustFrame(int scrnIndex, int x, int y, int flags) +{ +} + +Bool EnterVT(int scrnIndex, int flags) +{ +} + +void LeaveVT(int scrnIndex, int flags) +{ +} + +ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, + int flags) +{ +} diff --git a/src/glamo-kms-driver.h b/src/glamo-kms-driver.h new file mode 100644 index 0000000..84069a3 --- /dev/null +++ b/src/glamo-kms-driver.h @@ -0,0 +1,31 @@ +/* + * KMS Support for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +extern Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags); +extern Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, + char **argv); +extern Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags); +extern void AdjustFrame(int scrnIndex, int x, int y, int flags); +extern Bool EnterVT(int scrnIndex, int flags); +extern void LeaveVT(int scrnIndex, int flags); +extern ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, + int flags); -- cgit v1.2.3 From 72a3fcc25d026941c0a202cbc6364326b979c767 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 21 Jul 2009 01:53:45 +0100 Subject: Makefile and initialisation stuff --- src/Makefile.am | 3 +- src/glamo-driver.c | 4 + src/glamo-kms-driver.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++-- src/glamo-kms-driver.h | 3 + src/glamo.h | 3 + 5 files changed, 224 insertions(+), 6 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index d229347..f69adb1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,4 +35,5 @@ glamo_drv_la_SOURCES = \ glamo-draw.c \ glamo-display.c \ glamo-output.c \ - glamo-engine.c + glamo-engine.c \ + glamo-kms-driver.c diff --git a/src/glamo-driver.c b/src/glamo-driver.c index 9debf57..a8541f3 100644 --- a/src/glamo-driver.c +++ b/src/glamo-driver.c @@ -37,6 +37,7 @@ #include "glamo.h" #include "glamo-regs.h" +#include "glamo-kms.driver.h" #include #include @@ -301,6 +302,7 @@ GlamoProbe(DriverPtr drv, int flags) foundScreen = TRUE; + /* Plug in KMS functions instead of the conventional ones */ pScrn->driverVersion = GLAMO_VERSION; pScrn->driverName = GLAMO_DRIVER_NAME; pScrn->name = GLAMO_NAME; @@ -316,6 +318,8 @@ GlamoProbe(DriverPtr drv, int flags) } else { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Not using KMS"); + if (!xf86LoadDrvSubModule(drv, "fbdevhw")) return FALSE; diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index 5102f4b..5bd58e5 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -18,34 +18,241 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * + * + * The KMS parts of this driver are based on xf86-video-modesetting, to + * which the following notice applies: + * + * 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 "xf86.h" + + +static int modesettingEntityIndex = -1; + + +/* Return TRUE if KMS can be used */ +Bool GlamoKernelModesettingAvailable() +{ + DIR *dir; + struct dirent *ent; + + dir = opendir("/sys/bus/platform/devices/glamo-fb.0/"); + if ( !dir ) return FALSE; + + do { + + ent = readdir(dir); + + if ( strncmp(ent->d_name, "drm:controlD", 12) == 0 ) { + closedir(dir); + return TRUE; + } + + } while ( ent ) + + closedir(dir); + return FALSE; +} + + Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags) { + xf86CrtcConfigPtr xf86_config; + GlamoPtr pGlamo; + MessageType from = X_PROBED; + rgb defaultWeight = { 0, 0, 0 }; + EntityInfoPtr pEnt; + EntPtr glamoEnt = NULL; + 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]); + + /* Can't do this yet */ + if ( flags & PROBE_DETECT ) { + ConfiguredMonitor = NULL; + return TRUE; + } + + /* Allocate driverPrivate */ + if ( !GlamoGetRec(pScrn) ) return FALSE; + pGlamo = GlamoPTR(pScrn); + pGlamo->SaveGeneration = -1; + pGlamo->pEnt = pEnt; + + pScrn->displayWidth = 640; /* default it */ + + /* Allocate an entity private if necessary */ + if ( xf86IsEntityShared(pScrn->entityList[0]) ) { + msEnt = xf86GetEntityPrivate(pScrn->entityList[0], + modesettingEntityIndex)->ptr; + pGlamo->entityPrivate = msEnt; + } else { + pGlamo->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]); + } + } + + pGlamo->drm_fd = drmOpen(NULL, "platform:glamo-fb"); + + if ( ms->fd < 0 ) return FALSE; + + pScrn->racMemFlags = RAC_FB | RAC_COLORMAP; + pScrn->monitor = pScrn->confScreen->monitor; + pScrn->progClock = TRUE; + pScrn->rgbBits = 8; + + if ( !xf86SetDepthBpp (pScrn, 0, 0, 0 + PreferConvert24to32 + | SupportConvert24to32 + | Support32bppFb)) + return FALSE; + + if ( pScrn->depth != 16 ) { + 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_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; + } + + 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); + xf86LoadSubModule(pScrn, "exa"); + xf86LoadSubModule(pScrn, "dri2"); + + return TRUE; } + Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { } -Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags) + +Bool GlamoSwitchMode(int scrnIndex, DisplayModePtr mode, int flags) { } -void AdjustFrame(int scrnIndex, int x, int y, int flags) + +void GlamoAdjustFrame(int scrnIndex, int x, int y, int flags) { } -Bool EnterVT(int scrnIndex, int flags) + +Bool GlamoEnterVT(int scrnIndex, int flags) { } -void LeaveVT(int scrnIndex, int flags) + +void GlamoLeaveVT(int scrnIndex, int flags) { } -ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, + +ModeStatus GlamoValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags) { } diff --git a/src/glamo-kms-driver.h b/src/glamo-kms-driver.h index 84069a3..d68c2df 100644 --- a/src/glamo-kms-driver.h +++ b/src/glamo-kms-driver.h @@ -20,6 +20,9 @@ * */ +#include "xf86.h" + +extern Bool GlamoKernelModesettingAvailable(); extern Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags); extern Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv); diff --git a/src/glamo.h b/src/glamo.h index 6abf84a..90f60c7 100644 --- a/src/glamo.h +++ b/src/glamo.h @@ -135,6 +135,9 @@ typedef struct { /* Use hardware acceleration */ Bool accel; + int drm_fd; + unsigned int SaveGeneration; + uint16_t *colormap; } GlamoRec, *GlamoPtr; -- cgit v1.2.3 From c9f31330d7847820a9cabebc193f22a176690a67 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 22 Jul 2009 00:40:11 +0100 Subject: Just backing up progress --- configure.ac | 2 + src/Makefile.am | 4 +- src/crtc.c | 307 +++++++++++++++++++++++++++++++++++++++++++++++++ src/glamo-driver.c | 16 ++- src/glamo-kms-driver.c | 136 +++++++++++----------- src/glamo-kms-driver.h | 12 +- src/glamo.h | 13 +++ src/output.c | 292 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 700 insertions(+), 82 deletions(-) create mode 100644 src/crtc.c create mode 100644 src/output.c diff --git a/configure.ac b/configure.ac index 628537c..8aeed86 100644 --- a/configure.ac +++ b/configure.ac @@ -82,6 +82,8 @@ if test "x$HAVE_ENGINE_IOCTLS" = xyes; then fi # Checks for libraries. +PKG_CHECK_MODULES(DRI, [libdrm xf86driproto]) +CFLAGS="$XORG_CFLAGS $DRI_CFLAGS" # Checks for header files. AC_HEADER_STDC diff --git a/src/Makefile.am b/src/Makefile.am index f69adb1..28da384 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,4 +36,6 @@ glamo_drv_la_SOURCES = \ glamo-display.c \ glamo-output.c \ glamo-engine.c \ - glamo-kms-driver.c + glamo-kms-driver.c \ + crtc.c \ + output.c diff --git a/src/crtc.c b/src/crtc.c new file mode 100644 index 0000000..d4f449b --- /dev/null +++ b/src/crtc.c @@ -0,0 +1,307 @@ +/* + * 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/src/glamo-driver.c b/src/glamo-driver.c index a8541f3..f737725 100644 --- a/src/glamo-driver.c +++ b/src/glamo-driver.c @@ -37,7 +37,7 @@ #include "glamo.h" #include "glamo-regs.h" -#include "glamo-kms.driver.h" +#include "glamo-kms-driver.h" #include #include @@ -183,7 +183,7 @@ GlamoSetup(pointer module, pointer opts, int *errmaj, int *errmin) #endif /* XFree86LOADER */ -static Bool +Bool GlamoGetRec(ScrnInfoPtr pScrn) { if (pScrn->driverPrivate != NULL) @@ -193,7 +193,7 @@ GlamoGetRec(ScrnInfoPtr pScrn) return TRUE; } -static void +void GlamoFreeRec(ScrnInfoPtr pScrn) { if (pScrn->driverPrivate == NULL) @@ -298,10 +298,12 @@ GlamoProbe(DriverPtr drv, int flags) return FALSE; /* Is today a good day to use KMS? */ - if ( GlamoKernelModesettingAvailable(pScrn) ) { + if ( GlamoKernelModesettingAvailable() ) { foundScreen = TRUE; + pScrn = xf86AllocateScreen(drv, 0); + /* Plug in KMS functions instead of the conventional ones */ pScrn->driverVersion = GLAMO_VERSION; pScrn->driverName = GLAMO_DRIVER_NAME; @@ -318,8 +320,6 @@ GlamoProbe(DriverPtr drv, int flags) } else { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Not using KMS"); - if (!xf86LoadDrvSubModule(drv, "fbdevhw")) return FALSE; @@ -355,6 +355,10 @@ GlamoProbe(DriverPtr drv, int flags) xf86DrvMsg(pScrn->scrnIndex, X_INFO, "using %s\n", dev ? dev : "default device"); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Not using KMS"); + } } } diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index 5bd58e5..c04a62f 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -54,7 +54,25 @@ #include #include +#include +#include +#include +#include + #include "xf86.h" +#include "xf86Crtc.h" +#include "xf86str.h" +#include "xf86RAC.h" +#include "xf86drm.h" + +#include "glamo.h" + + +static const char *fbSymbols[] = { + "fbPictureInit", + "fbScreenInit", + NULL +}; static int modesettingEntityIndex = -1; @@ -78,30 +96,54 @@ Bool GlamoKernelModesettingAvailable() return TRUE; } - } while ( ent ) + } while ( ent ); closedir(dir); return FALSE; } +static Bool crtc_resize(ScrnInfoPtr pScrn, int width, int height) +{ +#if 0 + 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); +#endif + return FALSE; +} + + +static const xf86CrtcConfigFuncsRec crtc_config_funcs = { + crtc_resize +}; + + Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags) { xf86CrtcConfigPtr xf86_config; GlamoPtr pGlamo; - MessageType from = X_PROBED; rgb defaultWeight = { 0, 0, 0 }; - EntityInfoPtr pEnt; - EntPtr glamoEnt = NULL; - 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]); + Gamma zeros = { 0.0, 0.0, 0.0 }; /* Can't do this yet */ if ( flags & PROBE_DETECT ) { @@ -113,46 +155,24 @@ Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags) if ( !GlamoGetRec(pScrn) ) return FALSE; pGlamo = GlamoPTR(pScrn); pGlamo->SaveGeneration = -1; - pGlamo->pEnt = pEnt; - pScrn->displayWidth = 640; /* default it */ - - /* Allocate an entity private if necessary */ - if ( xf86IsEntityShared(pScrn->entityList[0]) ) { - msEnt = xf86GetEntityPrivate(pScrn->entityList[0], - modesettingEntityIndex)->ptr; - pGlamo->entityPrivate = msEnt; - } else { - pGlamo->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]); - } - } + pScrn->displayWidth = 24; /* Nonsense default value */ + /* Open DRM */ pGlamo->drm_fd = drmOpen(NULL, "platform:glamo-fb"); - - if ( ms->fd < 0 ) return FALSE; + if ( pGlamo->drm_fd < 0 ) return FALSE; pScrn->racMemFlags = RAC_FB | RAC_COLORMAP; pScrn->monitor = pScrn->confScreen->monitor; pScrn->progClock = TRUE; pScrn->rgbBits = 8; - if ( !xf86SetDepthBpp (pScrn, 0, 0, 0 - PreferConvert24to32 - | SupportConvert24to32 - | Support32bppFb)) - return FALSE; + if ( !xf86SetDepthBpp(pScrn, 0, 0, 0, PreferConvert24to32 + | SupportConvert24to32 | Support32bppFb) ) { + return FALSE; + } + /* We can only handle 16bpp */ if ( pScrn->depth != 16 ) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given depth (%d) is not supported by the driver\n", @@ -164,49 +184,27 @@ Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags) 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; + max_width = 480; + max_height = 640; 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)) { + 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)) { + if ( !xf86SetGamma(pScrn, zeros) ) { return FALSE; } - } - if (pScrn->modes == NULL) { + if ( pScrn->modes == NULL ) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n"); return FALSE; } diff --git a/src/glamo-kms-driver.h b/src/glamo-kms-driver.h index d68c2df..7d67feb 100644 --- a/src/glamo-kms-driver.h +++ b/src/glamo-kms-driver.h @@ -26,9 +26,9 @@ extern Bool GlamoKernelModesettingAvailable(); extern Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags); extern Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv); -extern Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags); -extern void AdjustFrame(int scrnIndex, int x, int y, int flags); -extern Bool EnterVT(int scrnIndex, int flags); -extern void LeaveVT(int scrnIndex, int flags); -extern ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, - int flags); +extern Bool GlamoKMSSwitchMode(int scrnIndex, DisplayModePtr mode, int flags); +extern void GlamoKMSAdjustFrame(int scrnIndex, int x, int y, int flags); +extern Bool GlamoKMSEnterVT(int scrnIndex, int flags); +extern void GlamoKMSLeaveVT(int scrnIndex, int flags); +extern ModeStatus GlamoKMSValidMode(int scrnIndex, DisplayModePtr mode, + Bool verbose, int flags); diff --git a/src/glamo.h b/src/glamo.h index 90f60c7..cf1bf5d 100644 --- a/src/glamo.h +++ b/src/glamo.h @@ -178,4 +178,17 @@ GlamoCrtcInit(ScrnInfoPtr pScrn); void GlamoOutputInit(ScrnInfoPtr pScrn); + +/* glamo-driver.c */ +extern Bool GlamoGetRec(ScrnInfoPtr pScrn); +extern void GlamoFreeRec(ScrnInfoPtr pScrn); + + +/* crtc.c */ +extern void crtc_init(ScrnInfoPtr pScrn); + + +/* output.c */ +extern void output_init(ScrnInfoPtr pScrn); + #endif /* _GLAMO_H_ */ diff --git a/src/output.c b/src/output.c new file mode 100644 index 0000000..1f95a2f --- /dev/null +++ b/src/output.c @@ -0,0 +1,292 @@ +/* + * 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); +} -- cgit v1.2.3 From 477353734de273195ee777eeace44f50aab00e47 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 22 Jul 2009 17:29:18 +0100 Subject: Drop in most of the rest of the code --- src/Makefile.am | 4 +- src/glamo-dri2.c | 128 ++++++++ src/glamo-kms-driver.c | 265 +++++++++++++-- src/glamo-kms-exa.c | 872 +++++++++++++++++++++++++++++++++++++++++++++++++ src/glamo-kms-exa.h | 25 ++ 5 files changed, 1268 insertions(+), 26 deletions(-) create mode 100644 src/glamo-dri2.c create mode 100644 src/glamo-kms-exa.c create mode 100644 src/glamo-kms-exa.h diff --git a/src/Makefile.am b/src/Makefile.am index 28da384..447784f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,4 +38,6 @@ glamo_drv_la_SOURCES = \ glamo-engine.c \ glamo-kms-driver.c \ crtc.c \ - output.c + output.c \ + glamo-dri2.c \ + glamo-kms-exa.c diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c new file mode 100644 index 0000000..fccf2ed --- /dev/null +++ b/src/glamo-dri2.c @@ -0,0 +1,128 @@ +/* + * 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]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + + if (!pGlamo->lock_held) + DRM_LOCK(pGlamo->drm_fd, pGlamo->lock, pGlamo->context, 0); + + pGlamo->lock_held = 1; +} + +void +driUnlock(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + + if (pGlamo->lock_held) + DRM_UNLOCK(pGlamo->drm_fd, pGlamo->lock, pGlamo->context); + + pGlamo->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]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + DRI2InfoRec dri2info; + const char *driverName; + unsigned int sarea_handle; + struct __DRILock *DRILock; + void *p; + + dri2info.version = 1; + dri2info.fd = pGlamo->drm_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); + pGlamo->lock = &DRILock->lock; + pGlamo->context = 1; + DRILock->next_id = 2; + driLock(pScreen); + + DRI2Connect(pScreen, &pGlamo->drm_fd, &driverName, &sarea_handle); +} + +void +driCloseScreen(ScreenPtr pScreen) +{ + driUnlock(pScreen); + DRI2CloseScreen(pScreen); +} diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index c04a62f..1d9bac8 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -53,6 +53,7 @@ #include #include +#include #include #include @@ -66,6 +67,8 @@ #include "xf86drm.h" #include "glamo.h" +#include "glamo-kms-driver.h" +#include "glamo-kms-exa.h" static const char *fbSymbols[] = { @@ -103,37 +106,68 @@ Bool GlamoKernelModesettingAvailable() } -static Bool crtc_resize(ScrnInfoPtr pScrn, int width, int height) +static Bool CreateFrontBuffer(ScrnInfoPtr pScrn) { -#if 0 - modesettingPtr ms = modesettingPTR(pScrn); - ScreenPtr pScreen = pScrn->pScreen; - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - Bool fbAccessDisabled; - CARD8 *fbstart; - - if (width == pScrn->virtualX && height == pScrn->virtualY) + GlamoPtr pGlamo = GlamoPTR(pScrn); + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + Bool fbAccessDisabled; + int flags; + + pGlamo->noEvict = TRUE; + pScreen->ModifyPixmapHeader(rootPixmap, + pScrn->virtualX, pScrn->virtualY, + pScrn->depth, pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel/8, + NULL); + pGlamo->noEvict = FALSE; + + 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; + GlamoKMSAdjustFrame(pScrn->scrnIndex, + pScrn->frameX0, pScrn->frameY0, + 0); + return TRUE; +} - ErrorF("RESIZING TO %dx%d\n", width, height); - pScrn->virtualX = width; - pScrn->virtualY = height; +static Bool crtc_resize(ScrnInfoPtr pScrn, int width, int height) +{ + GlamoPtr pGlamo = GlamoPTR(pScrn); + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + Bool fbAccessDisabled; + CARD8 *fbstart; - /* HW dependent - FIXME */ - pScrn->displayWidth = pScrn->virtualX; + if ( (width == pScrn->virtualX) && (height == pScrn->virtualY) ) + return TRUE; /* Nothing to do */ - drmModeRmFB(ms->fd, ms->fb_id); + ErrorF("RESIZING TO %dx%d\n", width, height); - /* now create new frontbuffer */ - return CreateFrontBuffer(pScrn); -#endif - return FALSE; + pScrn->virtualX = width; + pScrn->virtualY = height; + + /* HW dependent - FIXME */ + pScrn->displayWidth = pScrn->virtualX; + + drmModeRmFB(pGlamo->drm_fd, pGlamo->fb_id); + + /* now create new frontbuffer */ + return CreateFrontBuffer(pScrn); } static const xf86CrtcConfigFuncsRec crtc_config_funcs = { - crtc_resize + crtc_resize }; @@ -224,33 +258,214 @@ Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags) } +static Bool GlamoKMSCloseScreen(int scrnIndex, ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + + if ( pScrn->vtSema ) { + GlamoKMSLeaveVT(scrnIndex, 0); + } + driCloseScreen(pScreen); + + pScreen->CreateScreenResources = pGlamo->createScreenResources; + + if ( pGlamo->exa ) { + ExaClose(pScrn); + } + + drmClose(pGlamo->drm_fd); + pGlamo->drm_fd = -1; + + pScrn->vtSema = FALSE; + pScreen->CloseScreen = pGlamo->CloseScreen; + return (*pScreen->CloseScreen)(scrnIndex, pScreen); +} + + Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + VisualPtr visual; + unsigned long sys_mem; + int c; + MessageType from; + + /* Deal with server regeneration */ + if ( pGlamo->drm_fd < 0 ) { + pGlamo->drm_fd = drmOpen(NULL, "platform:glamo-fb"); + if ( pGlamo->drm_fd < 0 ) return FALSE; + } + + pScrn->pScreen = pScreen; + + /* HW dependent - FIXME */ + pScrn->displayWidth = pScrn->virtualX; + + miClearVisualTypes(); + + if ( !miSetVisualTypes(pScrn->depth, + miGetDefaultVisualMask(pScrn->depth), + pScrn->rgbBits, pScrn->defaultVisual) ) { + return FALSE; + } + + if ( !miSetPixmapDepths() ) return FALSE; + + pScrn->memPhysBase = 0; + pScrn->fbOffset = 0; + + if ( !fbScreenInit(pScreen, NULL, + 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); + + pGlamo->createScreenResources = pScreen->CreateScreenResources; + pScreen->CreateScreenResources = CreateScreenResources; + + xf86SetBlackWhitePixels(pScreen); + + pGlamo->exa = GlamoKMSExaInit(pScrn); + + miInitializeBackingStore(pScreen); + xf86SetBackingStore(pScreen); + xf86SetSilkenMouse(pScreen); + miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); + + /* 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); + } + + /* 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; + pGlamo->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = GlamoKMSCloseScreen; + + if ( !xf86CrtcScreenInit(pScreen) ) return FALSE; + + if ( !miCreateDefColormap(pScreen) ) return FALSE; + + xf86DPMSInit(pScreen, xf86DPMSSet, 0); + + if ( serverGeneration == 1 ) { + xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); + } + + driScreenInit(pScreen); + + return GlamoKMSEnterVT(scrnIndex, 1); } -Bool GlamoSwitchMode(int scrnIndex, DisplayModePtr mode, int flags) +Bool GlamoKMSSwitchMode(int scrnIndex, DisplayModePtr mode, int flags) { + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + return xf86SetSingleMode(pScrn, mode, RR_Rotate_0); } -void GlamoAdjustFrame(int scrnIndex, int x, int y, int flags) +void GlamoKMSAdjustFrame(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; + } } -Bool GlamoEnterVT(int scrnIndex, int flags) +Bool GlamoKMSEnterVT(int scrnIndex, int flags) { + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + + driUnlock(pScrn->pScreen); + + /* 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 ( pGlamo->SaveGeneration != serverGeneration ) { + pGlamo->SaveGeneration = serverGeneration; + /* ...except there is no hardware state to save */ + } + + if ( !flags ) { + /* signals startup as we'll do this in CreateScreenResources */ + CreateFrontBuffer(pScrn); + } + + if ( !xf86SetDesiredModes(pScrn) ) return FALSE; + + return TRUE; } -void GlamoLeaveVT(int scrnIndex, int flags) +void GlamoKMSLeaveVT(int scrnIndex, int flags) { + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + GlamoPtr pGlamo = GlamoPTR(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(pGlamo->drm_fd, pGlamo->fb_id); + + driLock(pScrn->pScreen); + + pScrn->vtSema = FALSE; } -ModeStatus GlamoValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, +ModeStatus GlamoKMSValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags) { + return MODE_OK; } diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c new file mode 100644 index 0000000..6d84c59 --- /dev/null +++ b/src/glamo-kms-exa.c @@ -0,0 +1,872 @@ +/* + * EXA via DRI for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * The KMS parts of this driver are based on xf86-video-modesetting, to + * which the following notice applies: + * + * 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 *GlamoKMSExaInit(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; +} diff --git a/src/glamo-kms-exa.h b/src/glamo-kms-exa.h new file mode 100644 index 0000000..6649892 --- /dev/null +++ b/src/glamo-kms-exa.h @@ -0,0 +1,25 @@ +/* + * EXA via DRI for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +#include "xf86.h" + +extern void *GlamoKMSExaInit(ScrnInfoPtr pScrn); -- cgit v1.2.3 From b0150bab10528c49384b5e3fd29f3ec9e9115e05 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 22 Jul 2009 17:31:47 +0100 Subject: ExaClose->GlamoKMSExaClose --- src/glamo-kms-driver.c | 2 +- src/glamo-kms-exa.c | 4 ++-- src/glamo-kms-exa.h | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index 1d9bac8..0c923c0 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -271,7 +271,7 @@ static Bool GlamoKMSCloseScreen(int scrnIndex, ScreenPtr pScreen) pScreen->CreateScreenResources = pGlamo->createScreenResources; if ( pGlamo->exa ) { - ExaClose(pScrn); + GlamoKMSExaClose(pScrn); } drmClose(pGlamo->drm_fd); diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 6d84c59..62aa89a 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -775,7 +775,7 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, } void -ExaClose(ScrnInfoPtr pScrn) +GlamoKMSExaClose(ScrnInfoPtr pScrn) { modesettingPtr ms = modesettingPTR(pScrn); struct exa_entity *exa = ms->exa; @@ -866,7 +866,7 @@ void *GlamoKMSExaInit(ScrnInfoPtr pScrn) return (void *)exa; out_err: - ExaClose(pScrn); + GlamoKMSExaClose(pScrn); return NULL; } diff --git a/src/glamo-kms-exa.h b/src/glamo-kms-exa.h index 6649892..be8e805 100644 --- a/src/glamo-kms-exa.h +++ b/src/glamo-kms-exa.h @@ -23,3 +23,4 @@ #include "xf86.h" extern void *GlamoKMSExaInit(ScrnInfoPtr pScrn); +extern void GlamoKMSExaClose(ScrnInfoPtr pScrn); -- cgit v1.2.3 From fa0b953a1a137a9706b9bea15aa7e30a67d0a086 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 23 Jul 2009 00:04:49 +0100 Subject: Make glamo-kms-driver.c compile --- src/glamo-dri2.h | 28 ++++++++++++++ src/glamo-kms-driver.c | 101 ++++++++++++++++++++++++++++--------------------- src/glamo-kms-exa.h | 1 + src/glamo.h | 3 ++ 4 files changed, 89 insertions(+), 44 deletions(-) create mode 100644 src/glamo-dri2.h diff --git a/src/glamo-dri2.h b/src/glamo-dri2.h new file mode 100644 index 0000000..8ec99b9 --- /dev/null +++ b/src/glamo-dri2.h @@ -0,0 +1,28 @@ +/* + * DRI for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +#include "xf86.h" + +extern void driScreenInit(ScreenPtr pScreen); +extern void driCloseScreen(ScreenPtr pScreen); +extern void driLock(ScreenPtr pScreen); +extern void driUnlock(ScreenPtr pScreen); diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index 0c923c0..2741253 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -65,10 +65,12 @@ #include "xf86str.h" #include "xf86RAC.h" #include "xf86drm.h" +#include "micmap.h" #include "glamo.h" #include "glamo-kms-driver.h" #include "glamo-kms-exa.h" +#include "glamo-dri2.h" static const char *fbSymbols[] = { @@ -78,9 +80,6 @@ static const char *fbSymbols[] = { }; -static int modesettingEntityIndex = -1; - - /* Return TRUE if KMS can be used */ Bool GlamoKernelModesettingAvailable() { @@ -106,29 +105,44 @@ Bool GlamoKernelModesettingAvailable() } +void GlamoKMSAdjustFrame(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 Bool CreateFrontBuffer(ScrnInfoPtr pScrn) { GlamoPtr pGlamo = GlamoPTR(pScrn); ScreenPtr pScreen = pScrn->pScreen; PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - Bool fbAccessDisabled; - int flags; + unsigned int flags; - pGlamo->noEvict = TRUE; pScreen->ModifyPixmapHeader(rootPixmap, pScrn->virtualX, pScrn->virtualY, pScrn->depth, pScrn->bitsPerPixel, pScrn->displayWidth * pScrn->bitsPerPixel/8, NULL); - pGlamo->noEvict = FALSE; - drmModeAddFB(ms->fd, + drmModeAddFB(pGlamo->drm_fd, pScrn->virtualX, pScrn->virtualY, pScrn->depth, pScrn->bitsPerPixel, pScrn->displayWidth * pScrn->bitsPerPixel / 8, - driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id); + driGetPixmapHandle(rootPixmap, &flags), &pGlamo->fb_id); pScrn->frameX0 = 0; pScrn->frameY0 = 0; @@ -143,10 +157,6 @@ static Bool CreateFrontBuffer(ScrnInfoPtr pScrn) static Bool crtc_resize(ScrnInfoPtr pScrn, int width, int height) { GlamoPtr pGlamo = GlamoPTR(pScrn); - ScreenPtr pScreen = pScrn->pScreen; - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - Bool fbAccessDisabled; - CARD8 *fbstart; if ( (width == pScrn->virtualX) && (height == pScrn->virtualY) ) return TRUE; /* Nothing to do */ @@ -283,15 +293,45 @@ static Bool GlamoKMSCloseScreen(int scrnIndex, ScreenPtr pScreen) } +static Bool GlamoKMSCreateScreenResources(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + PixmapPtr rootPixmap; + Bool ret; + unsigned int flags; + + pScreen->CreateScreenResources = pGlamo->createScreenResources; + ret = pScreen->CreateScreenResources(pScreen); + pScreen->CreateScreenResources = GlamoKMSCreateScreenResources; + + rootPixmap = pScreen->GetScreenPixmap(pScreen); + + if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL)) + FatalError("Couldn't adjust screen pixmap\n"); + + drmModeAddFB(pGlamo->drm_fd, + pScrn->virtualX, + pScrn->virtualY, + pScrn->depth, + pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel / 8, + driGetPixmapHandle(rootPixmap, &flags), &pGlamo->fb_id); + + GlamoKMSAdjustFrame(pScrn->scrnIndex, + pScrn->frameX0, pScrn->frameY0, + 0); + + return ret; +} + + Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); VisualPtr visual; - unsigned long sys_mem; - int c; - MessageType from; /* Deal with server regeneration */ if ( pGlamo->drm_fd < 0 ) { @@ -342,7 +382,7 @@ Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, fbPictureInit(pScreen, NULL, 0); pGlamo->createScreenResources = pScreen->CreateScreenResources; - pScreen->CreateScreenResources = CreateScreenResources; + pScreen->CreateScreenResources = GlamoKMSCreateScreenResources; xf86SetBlackWhitePixels(pScreen); @@ -353,13 +393,6 @@ Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, xf86SetSilkenMouse(pScreen); miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); - /* 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); - } - /* 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; @@ -391,24 +424,6 @@ Bool GlamoKMSSwitchMode(int scrnIndex, DisplayModePtr mode, int flags) } -void GlamoKMSAdjustFrame(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; - } -} - - Bool GlamoKMSEnterVT(int scrnIndex, int flags) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; @@ -445,8 +460,6 @@ void GlamoKMSLeaveVT(int scrnIndex, int flags) xf86CrtcPtr crtc = config->crtc[o]; - cursor_destroy(crtc); - if ( crtc->rotatedPixmap || crtc->rotatedData ) { crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, crtc->rotatedData); diff --git a/src/glamo-kms-exa.h b/src/glamo-kms-exa.h index be8e805..45b8eb7 100644 --- a/src/glamo-kms-exa.h +++ b/src/glamo-kms-exa.h @@ -24,3 +24,4 @@ extern void *GlamoKMSExaInit(ScrnInfoPtr pScrn); extern void GlamoKMSExaClose(ScrnInfoPtr pScrn); +extern unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); diff --git a/src/glamo.h b/src/glamo.h index cf1bf5d..aac39d5 100644 --- a/src/glamo.h +++ b/src/glamo.h @@ -135,8 +135,11 @@ typedef struct { /* Use hardware acceleration */ Bool accel; + /* Things to do with DRI */ int drm_fd; unsigned int SaveGeneration; + unsigned int fb_id; + CreateScreenResourcesProcPtr createScreenResources; uint16_t *colormap; } GlamoRec, *GlamoPtr; -- cgit v1.2.3 From 51690ae5c51e24b6bc0da95a067a3ac4bcda6350 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 23 Jul 2009 16:04:36 +0100 Subject: Just backing up progress --- src/Makefile.am | 4 +- src/glamo-dri2.c | 121 ++++++++++--------- src/glamo-kms-crtc.c | 307 ++++++++++++++++++++++++++++++++++++++++++++++++ src/glamo-kms-crtc.h | 30 +++++ src/glamo-kms-display.h | 27 +++++ src/glamo-kms-output.c | 292 +++++++++++++++++++++++++++++++++++++++++++++ src/glamo.h | 9 -- 7 files changed, 718 insertions(+), 72 deletions(-) create mode 100644 src/glamo-kms-crtc.c create mode 100644 src/glamo-kms-crtc.h create mode 100644 src/glamo-kms-display.h create mode 100644 src/glamo-kms-output.c diff --git a/src/Makefile.am b/src/Makefile.am index 447784f..6c97844 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -37,7 +37,7 @@ glamo_drv_la_SOURCES = \ glamo-output.c \ glamo-engine.c \ glamo-kms-driver.c \ - crtc.c \ - output.c \ + glamo-kms-crtc.c \ + glamo-kms-output.c \ glamo-dri2.c \ glamo-kms-exa.c diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index fccf2ed..f6915fc 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -1,4 +1,11 @@ /* + * DRI for the SMedia Glamo3362 X.org Driver + * + * Modified: 2009 by Thomas White + * + * Based on dri2.c from xf86-video-modesetting, to which the following + * notice applies: + * * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * @@ -26,6 +33,7 @@ * Author: Alan Hourihane * */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -33,96 +41,87 @@ #include "xf86.h" #include "xf86_OSproc.h" -#include "driver.h" - -#include "dri2.h" +#include "glamo.h" +#include "glamo-dri2.h" -extern unsigned int -driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); +extern unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); -void -driLock(ScreenPtr pScreen) +void driLock(ScreenPtr pScreen) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); - if (!pGlamo->lock_held) - DRM_LOCK(pGlamo->drm_fd, pGlamo->lock, pGlamo->context, 0); + if (!pGlamo->lock_held) + DRM_LOCK(pGlamo->drm_fd, pGlamo->lock, pGlamo->context, 0); - pGlamo->lock_held = 1; + pGlamo->lock_held = 1; } -void -driUnlock(ScreenPtr pScreen) +void driUnlock(ScreenPtr pScreen) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); - if (pGlamo->lock_held) - DRM_UNLOCK(pGlamo->drm_fd, pGlamo->lock, pGlamo->context); + if (pGlamo->lock_held) + DRM_UNLOCK(pGlamo->drm_fd, pGlamo->lock, pGlamo->context); - pGlamo->lock_held = 0; + pGlamo->lock_held = 0; } -static void -driBeginClipNotify(ScreenPtr pScreen) +static void driBeginClipNotify(ScreenPtr pScreen) { - driLock(pScreen); + driLock(pScreen); } -static void -driEndClipNotify(ScreenPtr pScreen) +static void driEndClipNotify(ScreenPtr pScreen) { - driUnlock(pScreen); + driUnlock(pScreen); } struct __DRILock { - unsigned int block_header; - drm_hw_lock_t lock; - unsigned int next_id; + 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) +void driScreenInit(ScreenPtr pScreen) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); - DRI2InfoRec dri2info; - const char *driverName; - unsigned int sarea_handle; - struct __DRILock *DRILock; - void *p; - - dri2info.version = 1; - dri2info.fd = pGlamo->drm_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 = + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + DRI2InfoRec dri2info; + const char *driverName; + unsigned int sarea_handle; + struct __DRILock *DRILock; + void *p; + + dri2info.version = 1; + dri2info.fd = pGlamo->drm_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); - pGlamo->lock = &DRILock->lock; - pGlamo->context = 1; - DRILock->next_id = 2; - driLock(pScreen); + pGlamo->lock = &DRILock->lock; + pGlamo->context = 1; + DRILock->next_id = 2; + driLock(pScreen); - DRI2Connect(pScreen, &pGlamo->drm_fd, &driverName, &sarea_handle); + DRI2Connect(pScreen, &pGlamo->drm_fd, &driverName, &sarea_handle); } -void -driCloseScreen(ScreenPtr pScreen) +void driCloseScreen(ScreenPtr pScreen) { - driUnlock(pScreen); - DRI2CloseScreen(pScreen); + driUnlock(pScreen); + DRI2CloseScreen(pScreen); } diff --git a/src/glamo-kms-crtc.c b/src/glamo-kms-crtc.c new file mode 100644 index 0000000..d4f449b --- /dev/null +++ b/src/glamo-kms-crtc.c @@ -0,0 +1,307 @@ +/* + * 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/src/glamo-kms-crtc.h b/src/glamo-kms-crtc.h new file mode 100644 index 0000000..8c16054 --- /dev/null +++ b/src/glamo-kms-crtc.h @@ -0,0 +1,30 @@ +/* + * KMS CRTC handling for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +#include "xf86.h" + +/* crtc.c */ +extern void crtc_init(ScrnInfoPtr pScrn); + + +/* output.c */ +extern void output_init(ScrnInfoPtr pScrn); diff --git a/src/glamo-kms-display.h b/src/glamo-kms-display.h new file mode 100644 index 0000000..45b8eb7 --- /dev/null +++ b/src/glamo-kms-display.h @@ -0,0 +1,27 @@ +/* + * EXA via DRI for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +#include "xf86.h" + +extern void *GlamoKMSExaInit(ScrnInfoPtr pScrn); +extern void GlamoKMSExaClose(ScrnInfoPtr pScrn); +extern unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); diff --git a/src/glamo-kms-output.c b/src/glamo-kms-output.c new file mode 100644 index 0000000..1f95a2f --- /dev/null +++ b/src/glamo-kms-output.c @@ -0,0 +1,292 @@ +/* + * 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); +} diff --git a/src/glamo.h b/src/glamo.h index aac39d5..8213a3a 100644 --- a/src/glamo.h +++ b/src/glamo.h @@ -181,17 +181,8 @@ GlamoCrtcInit(ScrnInfoPtr pScrn); void GlamoOutputInit(ScrnInfoPtr pScrn); - /* glamo-driver.c */ extern Bool GlamoGetRec(ScrnInfoPtr pScrn); extern void GlamoFreeRec(ScrnInfoPtr pScrn); - -/* crtc.c */ -extern void crtc_init(ScrnInfoPtr pScrn); - - -/* output.c */ -extern void output_init(ScrnInfoPtr pScrn); - #endif /* _GLAMO_H_ */ -- cgit v1.2.3 From 32f339919420e04b16142a8d862ab280fdd6cbb1 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 26 Jul 2009 14:25:55 +0100 Subject: Remote crtc.c and output.c --- src/crtc.c | 307 ----------------------------------------------------------- src/output.c | 292 -------------------------------------------------------- 2 files changed, 599 deletions(-) delete mode 100644 src/crtc.c delete mode 100644 src/output.c diff --git a/src/crtc.c b/src/crtc.c deleted file mode 100644 index d4f449b..0000000 --- a/src/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/src/output.c b/src/output.c deleted file mode 100644 index 1f95a2f..0000000 --- a/src/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); -} -- cgit v1.2.3 From b6eb663a8d35db3119dba0e644a94d99f922046f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 26 Jul 2009 18:40:29 +0100 Subject: Make everything up to glamo-kms-exa.c compile --- src/Makefile.am | 2 +- src/glamo-dri2.c | 169 +++++++++++++++++-------- src/glamo-kms-crtc.c | 337 ++++++++++++++++++++----------------------------- src/glamo-kms-driver.c | 1 + src/glamo-kms-output.c | 324 ++++++++++++++++++++++++----------------------- src/glamo.h | 2 + 6 files changed, 424 insertions(+), 411 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 6c97844..e49ae6f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,7 @@ # -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 = @XORG_CFLAGS@ -pedantic -Wall -Werror -std=gnu99 +AM_CFLAGS = @XORG_CFLAGS@ @DRI_CFLAGS@ -pedantic -Wall -Werror -std=gnu99 glamo_drv_la_LTLIBRARIES = glamo_drv.la glamo_drv_la_LDFLAGS = -module -avoid-version glamo_drv_ladir = @moduledir@/drivers diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index f6915fc..2491f82 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -34,92 +34,151 @@ * */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "xf86.h" -#include "xf86_OSproc.h" +#include +#include +#include +#include +#include +#include +#include #include "glamo.h" #include "glamo-dri2.h" +#include "glamo-kms-exa.h" -extern unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); -void driLock(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); +typedef struct { + PixmapPtr pPixmap; +} GlamoDRI2BufferPrivateRec, *GlamoDRI2BufferPrivatePtr; - if (!pGlamo->lock_held) - DRM_LOCK(pGlamo->drm_fd, pGlamo->lock, pGlamo->context, 0); - pGlamo->lock_held = 1; -} - -void driUnlock(ScreenPtr pScreen) +static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, + unsigned int *attachments, int count) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); - - if (pGlamo->lock_held) - DRM_UNLOCK(pGlamo->drm_fd, pGlamo->lock, pGlamo->context); - - pGlamo->lock_held = 0; + ScreenPtr pScreen = pDraw->pScreen; + DRI2BufferPtr buffers; + int i; + GlamoDRI2BufferPrivatePtr privates; + PixmapPtr pPixmap, pDepthPixmap; + + buffers = xcalloc(count, sizeof *buffers); + if ( buffers == NULL ) return NULL; + privates = xcalloc(count, sizeof *privates); + if ( privates == NULL ) { + xfree(buffers); + return NULL; + } + + pDepthPixmap = NULL; + /* For each attachment */ + for ( i=0; itype == DRAWABLE_PIXMAP ) { + pPixmap = (PixmapPtr)pDraw; + } else { + pPixmap = (*pScreen->GetWindowPixmap)( + (WindowPtr)pDraw); + } + pPixmap->refcnt++; + + } else { + + /* Anything else - create a new pixmap */ + pPixmap = (*pScreen->CreatePixmap)(pScreen, + pDraw->width, + pDraw->height, + pDraw->depth, + 0); + + } + + if ( attachments[i] == DRI2BufferDepth ) pDepthPixmap = pPixmap; + + /* Set up the return data structure */ + buffers[i].attachment = attachments[i]; + buffers[i].pitch = pPixmap->devKind; + buffers[i].cpp = pPixmap->drawable.bitsPerPixel / 8; + buffers[i].driverPrivate = &privates[i]; + buffers[i].flags = 0; + privates[i].pPixmap = pPixmap; + + } + + return buffers; } -static void driBeginClipNotify(ScreenPtr pScreen) -{ - driLock(pScreen); -} -static void driEndClipNotify(ScreenPtr pScreen) +static void glamoDestroyBuffers(DrawablePtr pDraw, + DRI2BufferPtr buffers, int count) { - driUnlock(pScreen); + ScreenPtr pScreen = pDraw->pScreen; + int i; + + for ( i=0; iDestroyPixmap)(private->pPixmap); + } + + if ( buffers ) { + xfree(buffers[0].driverPrivate); + xfree(buffers); + } } -struct __DRILock + +static void glamoCopyRegion(DrawablePtr pDraw, RegionPtr pRegion, + DRI2BufferPtr pDestBuffer, DRI2BufferPtr pSrcBuffer) { - 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]; GlamoPtr pGlamo = GlamoPTR(pScrn); DRI2InfoRec dri2info; - const char *driverName; - unsigned int sarea_handle; - struct __DRILock *DRILock; - void *p; + char *p; + struct stat sbuf; + dev_t d; + int i; + + fstat(pGlamo->drm_fd, &sbuf); + d = sbuf.st_rdev; + p = pGlamo->drm_devname; + for ( i=0; iscrnIndex, X_WARNING, + "[glamo-dri] Failed to find name of DRM device\n"); + return; + } + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "[glamo-dri] Name of DRM device is '%s'\n", p); dri2info.version = 1; dri2info.fd = pGlamo->drm_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); - pGlamo->lock = &DRILock->lock; - pGlamo->context = 1; - DRILock->next_id = 2; - driLock(pScreen); - - DRI2Connect(pScreen, &pGlamo->drm_fd, &driverName, &sarea_handle); + dri2info.deviceName = p; + dri2info.driverName = "glamo"; + + dri2info.CreateBuffers = glamoCreateBuffers; + dri2info.DestroyBuffers = glamoDestroyBuffers; + dri2info.CopyRegion = glamoCopyRegion; + + if ( !DRI2ScreenInit(pScreen, &dri2info) ) return; } + void driCloseScreen(ScreenPtr pScreen) { driUnlock(pScreen); diff --git a/src/glamo-kms-crtc.c b/src/glamo-kms-crtc.c index d4f449b..aafc539 100644 --- a/src/glamo-kms-crtc.c +++ b/src/glamo-kms-crtc.c @@ -1,4 +1,11 @@ /* + * KMS Support for the SMedia Glamo3362 X.org Driver + * + * Modified: 2009 by Thomas White + * + * Based on crtc.c from xf86-video-modesetting, to which the following + * notice applies: + * * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * @@ -27,6 +34,7 @@ * */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -37,271 +45,200 @@ #include #include #include +#include #include #include #include -#include "driver.h" -#include "xf86Modes.h" - +#include +#include +#include +#include #define DPMS_SERVER #include +#include "glamo.h" + + struct crtc_private { - drmModeCrtcPtr drm_crtc; - - /* hwcursor */ - drmBO cursor_bo; + drmModeCrtcPtr drm_crtc; }; -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) +static void crtc_dpms(xf86CrtcPtr crtc, int mode) { - return FALSE; + switch (mode) { + case DPMSModeOn: + case DPMSModeStandby: + case DPMSModeSuspend: + break; + case DPMSModeOff: + break; + } } -static void -crtc_unlock(xf86CrtcPtr crtc) -{ -} -static void -crtc_prepare(xf86CrtcPtr crtc) +static Bool crtc_lock(xf86CrtcPtr crtc) { + return FALSE; } -static void -crtc_commit(xf86CrtcPtr crtc) -{ -} -static Bool -crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode, - DisplayModePtr adjusted_mode) +static void crtc_unlock(xf86CrtcPtr crtc) { - 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) +static void crtc_prepare(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) +static void crtc_commit(xf86CrtcPtr crtc) { - 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) +static Bool crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode, + DisplayModePtr adjusted_mode) { - ScrnInfoPtr pScrn = crtc->scrn; + return TRUE; } -static void -crtc_destroy(xf86CrtcPtr crtc) + +static void crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, + DisplayModePtr adjusted_mode, int x, int y) { - modesettingPtr ms = modesettingPTR(crtc->scrn); - struct crtc_private *crtcp = crtc->driver_private; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + GlamoPtr pGlamo = GlamoPTR(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; + drmModeModeInfo drm_mode; - if (crtcp->cursor_bo.handle) - drmBOUnreference(ms->fd, &crtcp->cursor_bo); + 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); - drmModeFreeCrtc(crtcp->drm_crtc); - xfree(crtcp); + drmModeSetCrtc(pGlamo->drm_fd, drm_crtc->crtc_id, pGlamo->fb_id, x, y, + &drm_connector->connector_id, 1, &drm_mode); } -static void -crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image) + +void crtc_load_lut(xf86CrtcPtr crtc) { - 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); +static void crtc_gamma_set(xf86CrtcPtr crtc, + CARD16 *red, CARD16 *green, CARD16 *blue, + int size) +{ +} - if (ptr) - memcpy(ptr, image, 64 * 64 * 4); - drmBOUnmap(ms->fd, &crtcp->cursor_bo); +static void *crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height) +{ + return NULL; } -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 PixmapPtr crtc_shadow_create(xf86CrtcPtr crtc, void *data, + int width, int height) +{ + return NULL; } -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_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, + void *data) +{ } -static void -crtc_hide_cursor(xf86CrtcPtr crtc) + +static void crtc_destroy(xf86CrtcPtr crtc) { - modesettingPtr ms = modesettingPTR(crtc->scrn); - struct crtc_private *crtcp = crtc->driver_private; + struct crtc_private *crtcp = crtc->driver_private; - drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0); + drmModeFreeCrtc(crtcp->drm_crtc); + xfree(crtcp); } + 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, + .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 = NULL, + .show_cursor = NULL, + .hide_cursor = NULL, + .load_cursor_image = NULL, /* lets convert to argb only */ + .set_cursor_colors = NULL, /* using argb only */ + .load_cursor_argb = NULL, + .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) +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; + xf86CrtcPtr crtc; + GlamoPtr pGlamo = GlamoPTR(pScrn); + drmModeResPtr res; + drmModeCrtcPtr drm_crtc = NULL; + struct crtc_private *crtcp; + int c; + + res = drmModeGetResources(pGlamo->drm_fd); + if (res == 0) { + ErrorF("Failed drmModeGetResources %d\n", errno); + return; } - crtcp->drm_crtc = drm_crtc; + for (c = 0; c < res->count_crtcs; c++) { + drm_crtc = drmModeGetCrtc(pGlamo->drm_fd, res->crtcs[c]); + if (!drm_crtc) + continue; + + crtc = xf86CrtcCreate(pScrn, &crtc_funcs); + if (crtc == NULL) + goto out; - crtc->driver_private = crtcp; + 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); +out: + drmModeFreeResources(res); } diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index 2741253..fbad4a1 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -71,6 +71,7 @@ #include "glamo-kms-driver.h" #include "glamo-kms-exa.h" #include "glamo-dri2.h" +#include "glamo-kms-crtc.h" static const char *fbSymbols[] = { diff --git a/src/glamo-kms-output.c b/src/glamo-kms-output.c index 1f95a2f..991a8be 100644 --- a/src/glamo-kms-output.c +++ b/src/glamo-kms-output.c @@ -1,4 +1,11 @@ /* + * KMS Support for the SMedia Glamo3362 X.org Driver + * + * Modified: 2009 by Thomas White + * + * Based on output.c from xf86-video-modesetting, to which the following + * notice applies: + * * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * @@ -27,6 +34,7 @@ * */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -43,13 +51,13 @@ #include #include #include - #define DPMS_SERVER #include +#include +#include -#include "X11/Xatom.h" +#include "glamo.h" -#include "driver.h" static char *connector_enum_list[] = { "Unknown", @@ -67,226 +75,232 @@ static char *connector_enum_list[] = { "HDMI Type B", }; -static void -dpms(xf86OutputPtr output, int mode) + +static void dpms(xf86OutputPtr output, int mode) { } -static void -save(xf86OutputPtr output) + +static void save(xf86OutputPtr output) { } -static void -restore(xf86OutputPtr output) + +static void restore(xf86OutputPtr output) { } -static int -mode_valid(xf86OutputPtr output, DisplayModePtr pMode) + +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) + +static Bool mode_fixup(xf86OutputPtr output, DisplayModePtr mode, + DisplayModePtr adjusted_mode) { - return TRUE; + return TRUE; } -static void -prepare(xf86OutputPtr output) + +static void prepare(xf86OutputPtr output) { - dpms(output, DPMSModeOff); + dpms(output, DPMSModeOff); } -static void -mode_set(xf86OutputPtr output, DisplayModePtr mode, + +static void mode_set(xf86OutputPtr output, DisplayModePtr mode, DisplayModePtr adjusted_mode) { } -static void -commit(xf86OutputPtr output) + +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) + +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; - } + 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) + +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); + drmModeConnectorPtr drm_connector = output->driver_private; + drmModeModeInfoPtr 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; + return modes; } -static void -destroy(xf86OutputPtr output) + +static void destroy(xf86OutputPtr output) { - drmModeFreeConnector(output->driver_private); + drmModeFreeConnector(output->driver_private); } -static void -create_resources(xf86OutputPtr output) + +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) +static Bool set_property(xf86OutputPtr output, Atom property, + RRPropertyValuePtr value) { - return TRUE; + return TRUE; } #endif /* RANDR_12_INTERFACE */ + #ifdef RANDR_13_INTERFACE -static Bool -get_property(xf86OutputPtr output, Atom property) +static Bool get_property(xf86OutputPtr output, Atom property) { - return TRUE; + return TRUE; } #endif /* RANDR_13_INTERFACE */ + #ifdef RANDR_GET_CRTC_INTERFACE -static xf86CrtcPtr -get_crtc(xf86OutputPtr output) +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) + +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]); - } + GlamoPtr pGlamo = GlamoPTR(pScrn); + xf86OutputPtr output; + drmModeResPtr res; + drmModeConnectorPtr drm_connector = NULL; + drmModeEncoderPtr drm_encoder = NULL; + char *name; + int c, v, p; + + res = drmModeGetResources(pGlamo->drm_fd); + if (res == 0) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed drmModeGetResources\n"); + return; } - 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; + for (c = 0; c < res->count_connectors; c++) { + drm_connector = drmModeGetConnector(pGlamo->drm_fd, + res->connectors[c]); + if (!drm_connector) + goto out; + + for (p = 0; p < drm_connector->count_props; p++) { + drmModePropertyPtr prop; + + prop = drmModeGetProperty(pGlamo->drm_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(pGlamo->drm_fd, + drm_connector->encoders[0]); + if (drm_encoder) { + output->possible_crtcs = drm_encoder->possible_crtcs; + output->possible_clones = drm_encoder->possible_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; } - output->driver_private = drm_connector; - output->subpixel_order = SubPixelHorizontalRGB; - output->interlaceAllowed = FALSE; - output->doubleScanAllowed = FALSE; - } - - out: - drmModeFreeResources(res); + +out: + drmModeFreeResources(res); } diff --git a/src/glamo.h b/src/glamo.h index 8213a3a..b65734d 100644 --- a/src/glamo.h +++ b/src/glamo.h @@ -37,6 +37,7 @@ #include "xf86.h" #include "exa.h" #include +#include #define GLAMO_REG_BASE(c) ((c)->attr.address[0]) #define GLAMO_REG_SIZE(c) (0x2400) @@ -140,6 +141,7 @@ typedef struct { unsigned int SaveGeneration; unsigned int fb_id; CreateScreenResourcesProcPtr createScreenResources; + char drm_devname[64]; uint16_t *colormap; } GlamoRec, *GlamoPtr; -- cgit v1.2.3 From 38196fad554d39f43c044e7c4283bcd441d31973 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 26 Jul 2009 22:55:14 +0100 Subject: It all compiles now... --- src/glamo-dri2.c | 1 + src/glamo-drm-cmdq.h | 131 ++++++ src/glamo-kms-driver.c | 8 +- src/glamo-kms-exa.c | 1140 +++++++++++++++++++----------------------------- src/glamo.h | 6 +- 5 files changed, 583 insertions(+), 703 deletions(-) create mode 100644 src/glamo-drm-cmdq.h diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index 2491f82..1a1d836 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -174,6 +174,7 @@ void driScreenInit(ScreenPtr pScreen) dri2info.CreateBuffers = glamoCreateBuffers; dri2info.DestroyBuffers = glamoDestroyBuffers; dri2info.CopyRegion = glamoCopyRegion; + dri2info.Wait = NULL; if ( !DRI2ScreenInit(pScreen, &dri2info) ) return; } diff --git a/src/glamo-drm-cmdq.h b/src/glamo-drm-cmdq.h new file mode 100644 index 0000000..11d1752 --- /dev/null +++ b/src/glamo-drm-cmdq.h @@ -0,0 +1,131 @@ +/* + * Copyright 2007 OpenMoko, Inc. + * + * This driver is based on Xati, + * Copyright 2004 Eric Anholt + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _GLAMO_DRM_CMDQ_H_ +#define _GLAMO_DRM_CMDQ_H_ + +#define CCE_DEBUG 0 + +#if !CCE_DEBUG + +#define RING_LOCALS CARD16 *__head; int __count; int __objects; \ + char *__objs; char *__obj_pos; + +#define BEGIN_CMDQ(n) \ +do { \ + if ((pGlamo->cmd_queue->used + 2 * (n)) > \ + pGlamo->cmd_queue->size) { \ + GlamoDRMDispatch(pGlamo); \ + } \ + __head = (CARD16 *)((char *)pGlamo->cmd_queue->data + \ + pGlamo->cmd_queue->used); \ + __count = 0; \ + __objects = 0; \ + __objs = pGlamo->cmdq_objs + (pGlamo->cmdq_obj_used*2); \ + __obj_pos = pGlamo->cmdq_obj_pos + (pGlamo->cmdq_obj_used*2); \ +} while (0) + +#define END_CMDQ() do { \ + pGlamo->cmd_queue->used += __count * 2; \ +} while (0) + +#define OUT_BURST_REG(reg, val) do { \ + __head[__count++] = (val); \ +} while (0) + +#define OUT_BURST(reg, n) \ +do { \ + OUT_PAIR((1 << 15) | reg, n); \ +} while (0) + +#else /* CCE_DEBUG */ + +#define RING_LOCALS \ + CARD16 *__head; int __count, __total, __reg, __packet0count; \ + int __objects; char *__objs; char *__obj_pos; + +#define BEGIN_CMDQ(n) \ +do { \ + if ((pGlamo->cmd_queue->used + 2 * (n)) > \ + pGlamo->cmd_queue->size) { \ + GlamoDRMDispatch(pGlamo); \ + } \ + __head = (CARD16 *)((char *)pGlamo->cmd_queue->data + \ + pGlamo->cmd_queue->used); \ + __count = 0; \ + __total = n; \ + __reg = 0; \ + __packet0count = 0; \ + __objects = 0; \ + __objs = pGlamo->cmdq_objs + (pGlamo->cmdq_obj_used*2); \ + __obj_pos = pGlamo->cmdq_obj_pos + (pGlamo->cmdq_obj_used*2); \ +} while (0) + +#define END_CMDQ() do { \ + if (__count != __total) \ + FatalError("count != total (%d vs %d) at %s:%d\n", \ + __count, __total, __FILE__, __LINE__); \ + pGlamo->cmd_queue->used += __count * 2; \ + pGlamo->cmdq_objs_used += __objects; \ +} while (0) + +#define OUT_BURST_REG(reg, val) do { \ + if (__reg != reg) \ + FatalError("unexpected reg (0x%x vs 0x%x) at %s:%d\n", \ + reg, __reg, __FILE__, __LINE__); \ + if (__packet0count-- <= 0) \ + FatalError("overrun of packet0 at %s:%d\n", \ + __FILE__, __LINE__); \ + __head[__count++] = (val); \ + __reg += 2; \ +} while (0) + +#define OUT_BURST(reg, n) \ +do { \ + OUT_PAIR((1 << 15) | reg, n); \ + __reg = reg; \ + __packet0count = n; \ +} while (0) + +#endif + +#define OUT_PAIR(v1, v2) \ +do { \ + __head[__count++] = (v1); \ + __head[__count++] = (v2); \ +} while (0) + + +#define OUT_REG(reg, val) \ + OUT_PAIR(reg, val) + +#define OUT_REG_BO(reg, bo) __objs[__objects] = bo->handle; \ + __obj_pos[__objects++] = __count; \ + __head[__count++] = (reg); \ + __head[__count++] = 0x0000; \ + __head[__count++] = (reg+2); \ + __head[__count++] = 0x0000; + +#endif /* _GLAMO_DRM_CMDQ_H_ */ diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index fbad4a1..c92e4d6 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -279,7 +279,7 @@ static Bool GlamoKMSCloseScreen(int scrnIndex, ScreenPtr pScreen) } driCloseScreen(pScreen); - pScreen->CreateScreenResources = pGlamo->createScreenResources; + pScreen->CreateScreenResources = pGlamo->CreateScreenResources; if ( pGlamo->exa ) { GlamoKMSExaClose(pScrn); @@ -302,7 +302,7 @@ static Bool GlamoKMSCreateScreenResources(ScreenPtr pScreen) Bool ret; unsigned int flags; - pScreen->CreateScreenResources = pGlamo->createScreenResources; + pScreen->CreateScreenResources = pGlamo->CreateScreenResources; ret = pScreen->CreateScreenResources(pScreen); pScreen->CreateScreenResources = GlamoKMSCreateScreenResources; @@ -382,12 +382,12 @@ Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, fbPictureInit(pScreen, NULL, 0); - pGlamo->createScreenResources = pScreen->CreateScreenResources; + pGlamo->CreateScreenResources = pScreen->CreateScreenResources; pScreen->CreateScreenResources = GlamoKMSCreateScreenResources; xf86SetBlackWhitePixels(pScreen); - pGlamo->exa = GlamoKMSExaInit(pScrn); + GlamoKMSExaInit(pScrn); miInitializeBackingStore(pScreen); xf86SetBackingStore(pScreen); diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 62aa89a..8704ac3 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -19,854 +19,598 @@ * MA 02111-1307 USA * * - * The KMS parts of this driver are based on xf86-video-modesetting, to - * which the following notice applies: + * The contents of this file are based on glamo-draw.c, to which the following + * notice applies: * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. + * Copyright 2007 OpenMoko, 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, 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: + * This driver is based on Xati, + * Copyright 2003 Eric Anholt * - * 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 + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. */ + #ifdef HAVE_CONFIG_H -#include "config.h" +#include #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 "glamo-log.h" +#include "glamo.h" +#include "glamo-regs.h" +#include "glamo-drm-cmdq.h" + +#include +#include +#include + + +#if GLAMO_TRACE_FALL + #define GLAMO_FALLBACK(x) \ + do { \ + ErrorF("%s: ", __FUNCTION__); \ + ErrorF x; \ + return FALSE; \ + } while (0) +#else + #define GLAMO_FALLBACK(x) return FALSE +#endif -#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 glamo_exa_pixmap_priv { + struct glamo_bo *bo; }; -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; +static const CARD8 GLAMOSolidRop[16] = { + /* GXclear */ 0x00, /* 0 */ + /* GXand */ 0xa0, /* src AND dst */ + /* GXandReverse */ 0x50, /* src AND NOT dst */ + /* GXcopy */ 0xf0, /* src */ + /* GXandInverted*/ 0x0a, /* NOT src AND dst */ + /* GXnoop */ 0xaa, /* dst */ + /* GXxor */ 0x5a, /* src XOR dst */ + /* GXor */ 0xfa, /* src OR dst */ + /* GXnor */ 0x05, /* NOT src AND NOT dst */ + /* GXequiv */ 0xa5, /* NOT src XOR dst */ + /* GXinvert */ 0x55, /* NOT dst */ + /* GXorReverse */ 0xf5, /* src OR NOT dst */ + /* GXcopyInverted*/ 0x0f, /* NOT src */ + /* GXorInverted */ 0xaf, /* NOT src OR dst */ + /* GXnand */ 0x5f, /* NOT src OR NOT dst */ + /* GXset */ 0xff, /* 1 */ }; -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 const CARD8 GLAMOBltRop[16] = { + /* GXclear */ 0x00, /* 0 */ + /* GXand */ 0x88, /* src AND dst */ + /* GXandReverse */ 0x44, /* src AND NOT dst */ + /* GXcopy */ 0xcc, /* src */ + /* GXandInverted*/ 0x22, /* NOT src AND dst */ + /* GXnoop */ 0xaa, /* dst */ + /* GXxor */ 0x66, /* src XOR dst */ + /* GXor */ 0xee, /* src OR dst */ + /* GXnor */ 0x11, /* NOT src AND NOT dst */ + /* GXequiv */ 0x99, /* NOT src XOR dst */ + /* GXinvert */ 0x55, /* NOT dst */ + /* GXorReverse */ 0xdd, /* src OR NOT dst */ + /* GXcopyInverted*/ 0x33, /* NOT src */ + /* GXorInverted */ 0xbb, /* NOT src OR dst */ + /* GXnand */ 0x77, /* NOT src OR NOT dst */ + /* GXset */ 0xff, /* 1 */ }; -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) +/* Submit the prepared command sequence to the kernel */ +void GlamoDRMDispatch(GlamoPtr pGlamo) { - return (struct exa_surface *)ps; -} + drm_glamo_cmd_buffer_t cmdbuf; + int r; -static INLINE struct exa_buffer * -exa_get_buffer(struct pipe_buffer *buf) -{ - return (struct exa_buffer *)buf; -} + cmdbuf.buf = (char *)pGlamo->cmd_queue; + cmdbuf.bufsz = pGlamo->cmd_queue->used; + cmdbuf.nobjs = pGlamo->cmdq_obj_used; + cmdbuf.objs = (uint32_t *)pGlamo->cmdq_objs; + cmdbuf.obj_pos = (int *)pGlamo->cmdq_obj_pos; -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); + r = drmCommandWrite(pGlamo->drm_fd, DRM_GLAMO_CMDBUF, + &cmdbuf, sizeof(cmdbuf)); + if ( r != 0 ) { + xf86DrvMsg(pGlamo->pScreen->myNum, X_ERROR, + "DRM_GLAMO_CMDBUF failed"); + } - return virtual; + pGlamo->cmdq_obj_used = 0; } -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) +unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) { - struct exa_winsys *exa_winsys = exa_get_winsys(pws); - struct exa_buffer *exa_buf = exa_get_buffer(buf); + struct glamo_exa_pixmap_priv *priv; - drmBOUnreference(exa_winsys->ms->fd, &exa_buf->bo); + priv = exaGetPixmapDriverPrivate(pPixmap); + if (!priv) { + FatalError("NO PIXMAP PRIVATE\n"); + return 0; + } - free(exa_buf); + return priv->bo->handle; } -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) +Bool GlamoKMSExaPrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg) { - return "EXA"; -} + ScrnInfoPtr pScrn = xf86Screens[pPix->drawable.pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + CARD32 offset; + CARD16 op, pitch; + FbBits mask; + RING_LOCALS; + struct glamo_exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPix); -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; -} + if (pPix->drawable.bitsPerPixel != 16) + GLAMO_FALLBACK(("Only 16bpp is supported\n")); -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)); + mask = FbFullMask(16); + if ((pm & mask) != mask) + GLAMO_FALLBACK(("Can't do planemask 0x%08x\n", + (unsigned int) pm)); - buffer->base.refcount = 1; - buffer->base.size = bytes; - buffer->userBuffer = TRUE; - //buffer->data = ptr; - ErrorF("USERBUFFER\n"); + op = GLAMOSolidRop[alu] << 8; + offset = exaGetPixmapOffset(pPix); + pitch = pPix->devKind; - return &buffer->base; -} + BEGIN_CMDQ(16); + OUT_REG_BO(GLAMO_REG_2D_DST_ADDRL, priv->bo); + OUT_REG(GLAMO_REG_2D_DST_PITCH, pitch & 0x7ff); + OUT_REG(GLAMO_REG_2D_DST_HEIGHT, pPix->drawable.height); + OUT_REG(GLAMO_REG_2D_PAT_FG, fg); + OUT_REG(GLAMO_REG_2D_COMMAND2, op); + OUT_REG(GLAMO_REG_2D_ID1, 0); + OUT_REG(GLAMO_REG_2D_ID2, 0); + END_CMDQ(); -/** - * Round n up to next multiple. - */ -static INLINE unsigned -round_up(unsigned n, unsigned multiple) -{ - return (n + multiple - 1) & ~(multiple - 1); + return TRUE; } -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) +void GlamoKMSExaSolid(PixmapPtr pPix, int x1, int y1, int x2, int y2) { - struct exa_surface *wms = xcalloc(1, sizeof(struct exa_surface)); - - assert(ws); + ScrnInfoPtr pScrn = xf86Screens[pPix->drawable.pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + RING_LOCALS; - wms->surface.refcount = 1; - wms->surface.winsys = ws; - - return &wms->surface; + BEGIN_CMDQ(10); + OUT_REG(GLAMO_REG_2D_DST_X, x1); + OUT_REG(GLAMO_REG_2D_DST_Y, y1); + OUT_REG(GLAMO_REG_2D_RECT_WIDTH, x2 - x1); + OUT_REG(GLAMO_REG_2D_RECT_HEIGHT, y2 - y1); + OUT_REG(GLAMO_REG_2D_COMMAND3, 0); + END_CMDQ(); } -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) +void GlamoKMSExaDoneSolid(PixmapPtr pPix) { -} + ScrnInfoPtr pScrn = xf86Screens[pPix->drawable.pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); -static int -exa_fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence, - unsigned flag) -{ - return 0; + GlamoDRMDispatch(pGlamo); + exaMarkSync(pGlamo->pScreen); } -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) +Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, + int alu, Pixel pm) { - static struct exa_winsys *ws = NULL; - - if (!ws) { - ws = xcalloc(1, sizeof(struct exa_winsys)); + ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + RING_LOCALS; + FbBits mask; + CARD32 src_offset, dst_offset; + CARD16 src_pitch, dst_pitch; + CARD16 op; + struct glamo_exa_pixmap_priv *priv_src; + struct glamo_exa_pixmap_priv *priv_dst; - /* 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; + priv_src = exaGetPixmapDriverPrivate(pSrc); + priv_dst = exaGetPixmapDriverPrivate(pDst); - ws->base.surface_alloc = exa_surface_alloc; - ws->base.surface_alloc_storage = exa_surface_alloc_storage; - ws->base.surface_release = exa_surface_release; + if (pSrc->drawable.bitsPerPixel != 16 || + pDst->drawable.bitsPerPixel != 16) + GLAMO_FALLBACK(("Only 16bpp is supported")); - ws->base.fence_reference = exa_fence_reference; - ws->base.fence_signalled = exa_fence_signalled; - ws->base.fence_finish = exa_fence_finish; + mask = FbFullMask(16); + if ((pm & mask) != mask) { + GLAMO_FALLBACK(("Can't do planemask 0x%08x", + (unsigned int) pm)); + } - ws->base.flush_frontbuffer = exa_flush_frontbuffer; - ws->base.get_name = exa_get_name; + src_offset = exaGetPixmapOffset(pSrc); + src_pitch = pSrc->devKind; - ws->ms = ms; - } + dst_offset = exaGetPixmapOffset(pDst); + dst_pitch = pDst->devKind; - return &ws->base; -} + op = GLAMOBltRop[alu] << 8; -/* EXA functions */ + BEGIN_CMDQ(20); + OUT_REG_BO(GLAMO_REG_2D_SRC_ADDRL, priv_src->bo); + OUT_REG(GLAMO_REG_2D_SRC_PITCH, src_pitch & 0x7ff); -struct PixmapPriv -{ - drmBO bo; -#if 0 - dri_fence *fence; -#endif - int flags; + OUT_REG_BO(GLAMO_REG_2D_DST_ADDRL, priv_dst->bo); + OUT_REG(GLAMO_REG_2D_DST_PITCH, dst_pitch & 0x7ff); + OUT_REG(GLAMO_REG_2D_DST_HEIGHT, pDst->drawable.height); - struct pipe_texture *tex; - unsigned int color; - struct pipe_surface *src_surf; /* for copies */ -}; + OUT_REG(GLAMO_REG_2D_COMMAND2, op); + OUT_REG(GLAMO_REG_2D_ID1, 0); + OUT_REG(GLAMO_REG_2D_ID2, 0); + END_CMDQ(); -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; - } + return TRUE; } -/* - * EXA functions - */ -static void -ExaWaitMarker(ScreenPtr pScreen, int marker) +void GlamoKMSExaCopy(PixmapPtr pDst, int srcX, int srcY, int dstX, int dstY, + int width, int height) { -} + ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + RING_LOCALS; -static int -ExaMarkSync(ScreenPtr pScreen) -{ - return 1; + BEGIN_CMDQ(14); + OUT_REG(GLAMO_REG_2D_SRC_X, srcX); + OUT_REG(GLAMO_REG_2D_SRC_Y, srcY); + OUT_REG(GLAMO_REG_2D_DST_X, dstX); + OUT_REG(GLAMO_REG_2D_DST_Y, dstY); + OUT_REG(GLAMO_REG_2D_RECT_WIDTH, width); + OUT_REG(GLAMO_REG_2D_RECT_HEIGHT, height); + OUT_REG(GLAMO_REG_2D_COMMAND3, 0); + END_CMDQ(); } -Bool -ExaPrepareAccess(PixmapPtr pPix, int index) + +void GlamoKMSExaDoneCopy(PixmapPtr pDst) { - 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; + ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); - priv = exaGetPixmapDriverPrivate(pPix); + GlamoDRMDispatch(pGlamo); + exaMarkSync(pGlamo->pScreen); +} - if (!priv) - return FALSE; - if (!priv->tex) +Bool GlamoKMSExaCheckComposite(int op, + PicturePtr pSrcPicture, + PicturePtr pMaskPicture, + PicturePtr pDstPicture) +{ 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) +Bool GlamoKMSExaPrepareComposite(int op, PicturePtr pSrcPicture, + PicturePtr pMaskPicture, + PicturePtr pDstPicture, + PixmapPtr pSrc, + PixmapPtr pMask, + PixmapPtr pDst) { - ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); - struct exa_entity *exa = ms->exa; + return FALSE; +} - if (!priv) - return; - if (priv->src_surf) - exa->scrn->tex_surface_release(exa->scrn, &priv->src_surf); - priv->src_surf = NULL; +void GlamoKMSExaComposite(PixmapPtr pDst, int srcX, int srcY, + int maskX, int maskY, int dstX, int dstY, + int width, int height) +{ } -static void -ExaDoneComposite(PixmapPtr pPixmap) + +void GlamoKMSExaDoneComposite(PixmapPtr pDst) { - ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; } -static Bool -ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg) + +Bool GlamoKMSExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, + char *src, int src_pitch) { - ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap); - struct exa_entity *exa = ms->exa; + ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + int bpp, i; + CARD8 *dst_offset; + int dst_pitch; - if (pPixmap->drawable.depth < 15) - return FALSE; + bpp = pDst->drawable.bitsPerPixel / 8; + dst_pitch = pDst->devKind; + dst_offset = pGlamo->exa->memoryBase + exaGetPixmapOffset(pDst) + + x*bpp + y*dst_pitch; - if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask)) - return FALSE; + for (i = 0; i < h; i++) { + memcpy(dst_offset, src, w*bpp); + dst_offset += dst_pitch; + src += src_pitch; + } - if (!priv || !priv->tex) - return FALSE; + return TRUE; +} - if (alu != GXcopy) - return FALSE; - if (!exa->ctx || !exa->ctx->surface_fill) - return FALSE; +Bool GlamoKMSExaDownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, + char *dst, int dst_pitch) +{ + ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + int bpp, i; + CARD8 *dst_offset, *src; + int src_pitch; - priv->color = fg; + bpp = pSrc->drawable.bitsPerPixel; + bpp /= 8; + src_pitch = pSrc->devKind; + src = pGlamo->exa->memoryBase + exaGetPixmapOffset(pSrc) + + x*bpp + y*src_pitch; + dst_offset = (unsigned char*)dst; - return TRUE; -} + for (i = 0; i < h; i++) { + memcpy(dst_offset, src, w*bpp); + dst_offset += dst_pitch; + src += src_pitch; + } -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); + return TRUE; } -static Bool -ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, - int ydir, int alu, Pixel planeMask) + +void GlamoKMSExaWaitMarker(ScreenPtr pScreen, int marker) { - 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; +// ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; +// GlamoPtr pGlamo = GlamoPTR(pScrn); - if (pSrcPixmap->drawable.depth < 15 || pDstPixmap->drawable.depth < 15) - return FALSE; +// GLAMOEngineWait(pGlamo, GLAMO_ENGINE_ALL); + // FIXME +} - if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask)) - return FALSE; - if (!priv || !src_priv) - return FALSE; +static void *GlamoKMSExaCreatePixmap(ScreenPtr screen, int size, int align) +{ + ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + struct glamo_exa_pixmap_priv *new_priv; - if (!priv->tex || !src_priv->tex) - return FALSE; + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Creating a new pixmap, size=%i\n", + size); - if (!exa->ctx || !exa->ctx->surface_copy) - return FALSE; + new_priv = xcalloc(1, sizeof(struct glamo_exa_pixmap_priv)); + if (!new_priv) + return NULL; - 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); + /* See GlamoKMSExaModifyPixmapHeader() below */ + if (size == 0) + return new_priv; - return FALSE; -} + /* Dive into the kernel (via libdrm) to allocate some VRAM */ + new_priv->bo = pGlamo->bufmgr->funcs->bo_open(pGlamo->bufmgr, + 0, /* handle */ + size, + align, + GLAMO_GEM_DOMAIN_VRAM, + 0 /* flags */ ); + if (!new_priv->bo) { + xfree(new_priv); + return NULL; + } -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); + return new_priv; } -static Bool -ExaPrepareComposite(int op, PicturePtr pSrcPicture, - PicturePtr pMaskPicture, PicturePtr pDstPicture, - PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst) + +static void GlamoKMSExaDestroyPixmap(ScreenPtr screen, void *driverPriv) { - ScreenPtr pScreen = pDst->drawable.pScreen; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + struct glamo_exa_pixmap_priv *driver_priv = driverPriv; - return FALSE; + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Destroying a pixmap\n"); + + if (driver_priv->bo) + pGlamo->bufmgr->funcs->bo_unref(driver_priv->bo); + xfree(driver_priv); } -static Bool -ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, - int src_pitch) + +static Bool GlamoKMSExaPixmapIsOffscreen(PixmapPtr pPix) { - ScreenPtr pScreen = pDst->drawable.pScreen; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + struct glamo_exa_pixmap_priv *driver_priv; - ErrorF("UPLOAD\n"); + driver_priv = exaGetPixmapDriverPrivate(pPix); + if (driver_priv && driver_priv->bo) + return TRUE; - return FALSE; + 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) +static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) { - DrawablePtr pDraw = pSrcPicture->pDrawable; - int w = pDraw->width; - int h = pDraw->height; + ScreenPtr screen = pPix->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + struct glamo_exa_pixmap_priv *driver_priv; - return FALSE; -} + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Prepare access\n"); -static void * -ExaCreatePixmap(ScreenPtr pScreen, int size, int align) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct PixmapPriv *priv; - void *virtual; + driver_priv = exaGetPixmapDriverPrivate(pPix); + if (!driver_priv) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "%s: no driver private?\n", __FUNCTION__); + return FALSE; + } - priv = xcalloc(1, sizeof(struct PixmapPriv)); - if (!priv) - return NULL; + if (!driver_priv->bo) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "%s: no buffer object?\n", __FUNCTION__); + return TRUE; + } - return priv; + if (pGlamo->bufmgr->funcs->bo_map(driver_priv->bo, 1)) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "%s: bo map failed\n", __FUNCTION__); + return FALSE; + } + pPix->devPrivate.ptr = driver_priv->bo->ptr; + + return TRUE; } -static void -ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv) + +static void GlamoKMSExaFinishAccess(PixmapPtr pPix, int index) { - struct PixmapPriv *priv = (struct PixmapPriv *)dPriv; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - modesettingPtr ms = modesettingPTR(pScrn); - struct exa_entity *exa = ms->exa; + ScreenPtr screen = pPix->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + struct glamo_exa_pixmap_priv *driver_priv; - if (!priv) - return; + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Finish access\n"); - if (priv->tex) - exa->scrn->texture_release(exa->scrn, &priv->tex); + driver_priv = exaGetPixmapDriverPrivate(pPix); + if (!driver_priv) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "%s: no driver private?\n", __FUNCTION__); + return; + } + + if (!driver_priv->bo) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "%s: no buffer object?\n", __FUNCTION__); + return; + } - xfree(priv); + pGlamo->bufmgr->funcs->bo_unmap(driver_priv->bo); + pPix->devPrivate.ptr = NULL; } -static Bool -ExaPixmapIsOffscreen(PixmapPtr pPixmap) + +static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, + int depth, int bitsPerPixel, + int devKind, pointer pPixData) { - struct PixmapPriv *priv; - ScreenPtr pScreen = pPixmap->drawable.pScreen; - PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + ScreenPtr screen = pPix->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; +// GlamoPtr pGlamo = GlamoPTR(pScrn); + PixmapPtr screen_pixmap = screen->GetScreenPixmap(screen); - priv = exaGetPixmapDriverPrivate(pPixmap); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ModifyPixmapHeader. " + "%ix%ix%i %ibpp, %i\n", + width, height, depth, + bitsPerPixel, devKind); - if (!priv) - return FALSE; + miModifyPixmapHeader(pPix, width, height, depth, + bitsPerPixel, devKind, NULL); - if (priv->tex) - return TRUE; + if ( pPix == screen_pixmap ) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Screen pixmap!"); + } - return FALSE; + + return FALSE; } -/* FIXME !! */ -unsigned int -driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) + +void GlamoKMSExaClose(ScrnInfoPtr pScrn) { - 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; + exaDriverFini(pScrn->pScreen); } -static Bool -ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, - int depth, int bitsPerPixel, int devKind, - pointer pPixData) + +void GlamoKMSExaInit(ScrnInfoPtr pScrn) { - 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; + GlamoPtr pGlamo = GlamoPTR(pScrn); - if (depth <= 0) - depth = pPixmap->drawable.depth; + Bool success = FALSE; + ExaDriverPtr exa; - if (bitsPerPixel <= 0) - bitsPerPixel = pPixmap->drawable.bitsPerPixel; + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "EXA hardware acceleration initialising\n"); - if (width <= 0) - width = pPixmap->drawable.width; + exa = exaDriverAlloc(); + if ( !exa ) return; + pGlamo->exa = exa; - if (height <= 0) - height = pPixmap->drawable.height; + exa->memoryBase = 0; + exa->memorySize = 0; + exa->offScreenBase = 0; - if (width <= 0 || height <= 0 || depth <= 0) - return FALSE; + exa->exa_major = EXA_VERSION_MAJOR; + exa->exa_minor = EXA_VERSION_MINOR; - 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; -} + /* Solid fills */ + exa->PrepareSolid = GlamoKMSExaPrepareSolid; + exa->Solid = GlamoKMSExaSolid; + exa->DoneSolid = GlamoKMSExaDoneSolid; -void -GlamoKMSExaClose(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - struct exa_entity *exa = ms->exa; + /* Blits */ + exa->PrepareCopy = GlamoKMSExaPrepareCopy; + exa->Copy = GlamoKMSExaCopy; + exa->DoneCopy = GlamoKMSExaDoneCopy; - exaDriverFini(pScrn->pScreen); + /* Composite (though these just cause fallback) */ + exa->CheckComposite = GlamoKMSExaCheckComposite; + exa->PrepareComposite = GlamoKMSExaPrepareComposite; + exa->Composite = GlamoKMSExaComposite; + exa->DoneComposite = GlamoKMSExaDoneComposite; - dlclose(ms->driver); -} + exa->DownloadFromScreen = GlamoKMSExaDownloadFromScreen; + exa->UploadToScreen = GlamoKMSExaUploadToScreen; -void *GlamoKMSExaInit(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: - GlamoKMSExaClose(pScrn); - - return NULL; +// exa->MarkSync = GlamoKMSExaMarkSync; + exa->WaitMarker = GlamoKMSExaWaitMarker; + + exa->pixmapOffsetAlign = 2; + exa->pixmapPitchAlign = 2; + + exa->maxX = 640; + exa->maxY = 640; + + pGlamo->cmdq_objs = malloc(1024); + pGlamo->cmdq_obj_pos = malloc(1024); + pGlamo->cmdq_obj_used = 0; + + /* Tell EXA that we're going to take care of memory + * management ourselves. */ + exa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS; + exa->PrepareAccess = GlamoKMSExaPrepareAccess; + exa->FinishAccess = GlamoKMSExaFinishAccess; + exa->CreatePixmap = GlamoKMSExaCreatePixmap; + exa->DestroyPixmap = GlamoKMSExaDestroyPixmap; + exa->PixmapIsOffscreen = GlamoKMSExaPixmapIsOffscreen; + exa->ModifyPixmapHeader = GlamoKMSExaModifyPixmapHeader; + + success = exaDriverInit(pGlamo->pScreen, exa); + if (success) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Initialized EXA acceleration\n"); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed to initialize EXA acceleration\n"); + xfree(pGlamo->exa); + pGlamo->exa = NULL; + } } diff --git a/src/glamo.h b/src/glamo.h index b65734d..d802226 100644 --- a/src/glamo.h +++ b/src/glamo.h @@ -38,6 +38,7 @@ #include "exa.h" #include #include +#include #define GLAMO_REG_BASE(c) ((c)->attr.address[0]) #define GLAMO_REG_SIZE(c) (0x2400) @@ -105,6 +106,9 @@ typedef struct { * "at once", when we are happy with it. */ MemBuf *cmd_queue; + int cmdq_obj_used; + char *cmdq_objs; + char *cmdq_obj_pos; /* What was GLAMOCardInfo */ volatile char *reg_base; @@ -140,8 +144,8 @@ typedef struct { int drm_fd; unsigned int SaveGeneration; unsigned int fb_id; - CreateScreenResourcesProcPtr createScreenResources; char drm_devname[64]; + struct glamo_bo_manager *bufmgr; uint16_t *colormap; } GlamoRec, *GlamoPtr; -- cgit v1.2.3 From cbbb356da7f4384c812c9db230657097992da1e7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 26 Jul 2009 23:33:29 +0100 Subject: Cannot accelerate these --- src/glamo-kms-exa.c | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 8704ac3..8e31a22 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -332,50 +332,14 @@ void GlamoKMSExaDoneComposite(PixmapPtr pDst) Bool GlamoKMSExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, int src_pitch) { - ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); - int bpp, i; - CARD8 *dst_offset; - int dst_pitch; - - bpp = pDst->drawable.bitsPerPixel / 8; - dst_pitch = pDst->devKind; - dst_offset = pGlamo->exa->memoryBase + exaGetPixmapOffset(pDst) - + x*bpp + y*dst_pitch; - - for (i = 0; i < h; i++) { - memcpy(dst_offset, src, w*bpp); - dst_offset += dst_pitch; - src += src_pitch; - } - - return TRUE; + return FALSE; } Bool GlamoKMSExaDownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, char *dst, int dst_pitch) { - ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); - int bpp, i; - CARD8 *dst_offset, *src; - int src_pitch; - - bpp = pSrc->drawable.bitsPerPixel; - bpp /= 8; - src_pitch = pSrc->devKind; - src = pGlamo->exa->memoryBase + exaGetPixmapOffset(pSrc) + - x*bpp + y*src_pitch; - dst_offset = (unsigned char*)dst; - - for (i = 0; i < h; i++) { - memcpy(dst_offset, src, w*bpp); - dst_offset += dst_pitch; - src += src_pitch; - } - - return TRUE; + return FALSE; } @@ -579,6 +543,7 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) exa->DownloadFromScreen = GlamoKMSExaDownloadFromScreen; exa->UploadToScreen = GlamoKMSExaUploadToScreen; + exa->UploadToScratch = NULL; // exa->MarkSync = GlamoKMSExaMarkSync; exa->WaitMarker = GlamoKMSExaWaitMarker; -- cgit v1.2.3 From 839e7e06a1e24c66233b77b50e454b286caadf93 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 28 Jul 2009 01:28:36 +0100 Subject: De-crashify a few things --- src/glamo-dri2.c | 1 - src/glamo-driver.c | 162 +++++++++++++++++++++++++++++-------------------- src/glamo-kms-driver.c | 5 +- src/glamo-kms-exa.c | 19 +++--- 4 files changed, 108 insertions(+), 79 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index 1a1d836..2491f82 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -174,7 +174,6 @@ void driScreenInit(ScreenPtr pScreen) dri2info.CreateBuffers = glamoCreateBuffers; dri2info.DestroyBuffers = glamoDestroyBuffers; dri2info.CopyRegion = glamoCopyRegion; - dri2info.Wait = NULL; if ( !DRI2ScreenInit(pScreen, &dri2info) ) return; } diff --git a/src/glamo-driver.c b/src/glamo-driver.c index f737725..002dca3 100644 --- a/src/glamo-driver.c +++ b/src/glamo-driver.c @@ -278,13 +278,101 @@ GlamoIdentify(int flags) } static Bool -GlamoProbe(DriverPtr drv, int flags) +GlamoFbdevProbe(DriverPtr drv, GDevPtr *devSections, int numDevSections) { + char *dev; + Bool foundScreen = FALSE; int i; ScrnInfoPtr pScrn; + + if (!xf86LoadDrvSubModule(drv, "fbdevhw")) return FALSE; + + for (i = 0; i < numDevSections; i++) { + + dev = xf86FindOptionValue(devSections[i]->options, "Device"); + if (fbdevHWProbe(NULL, dev, NULL)) { + int entity; + pScrn = NULL; + + entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE); + pScrn = xf86ConfigFbEntity(pScrn,0,entity, NULL, NULL, + NULL, NULL); + + if (pScrn) { + + foundScreen = TRUE; + + pScrn->driverVersion = GLAMO_VERSION; + pScrn->driverName = GLAMO_DRIVER_NAME; + pScrn->name = GLAMO_NAME; + pScrn->Probe = GlamoProbe; + pScrn->PreInit = GlamoPreInit; + pScrn->ScreenInit = GlamoScreenInit; + pScrn->SwitchMode = GlamoSwitchMode; + pScrn->AdjustFrame = fbdevHWAdjustFrameWeak(); + pScrn->EnterVT = GlamoEnterVT; + pScrn->LeaveVT = GlamoLeaveVT; + pScrn->ValidMode = fbdevHWValidModeWeak(); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "using %s\n", + dev ? dev : "default device\n"); + + } + } + + } + + return foundScreen; +} + +static Bool +GlamoKMSProbe(DriverPtr drv, GDevPtr *devSections, int numDevSections) +{ + ScrnInfoPtr pScrn = NULL; + int entity; + Bool foundScreen = FALSE; + int i; + + for ( i = 0; i < numDevSections; i++ ) { + + /* This is a little dodgy. We aren't really using fbdevhw + * (/dev/fb0 is irrelevant), but we need a device entity to make + * the later stages of initialisation work. xf86ClaimFbSlot() + * does the minimum required to make this work, so we use it + * despite the above. */ + entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE); + pScrn = xf86ConfigFbEntity(pScrn, 0, entity, NULL, NULL, NULL, + NULL); + + if ( pScrn ) { + + foundScreen = TRUE; + + /* Plug in KMS functions */ + pScrn->driverVersion = GLAMO_VERSION; + pScrn->driverName = GLAMO_DRIVER_NAME; + pScrn->name = GLAMO_NAME; + pScrn->PreInit = GlamoKMSPreInit; + pScrn->ScreenInit = GlamoKMSScreenInit; + pScrn->SwitchMode = GlamoKMSSwitchMode; + pScrn->AdjustFrame = GlamoKMSAdjustFrame; + pScrn->EnterVT = GlamoKMSEnterVT; + pScrn->LeaveVT = GlamoKMSLeaveVT; + pScrn->ValidMode = GlamoKMSValidMode; + + } + } + + return foundScreen; +} + +static Bool +GlamoProbe(DriverPtr drv, int flags) +{ + ScrnInfoPtr pScrn; GDevPtr *devSections; int numDevSections; - char *dev; Bool foundScreen = FALSE; TRACE("probe start"); @@ -294,75 +382,15 @@ GlamoProbe(DriverPtr drv, int flags) return FALSE; numDevSections = xf86MatchDevice(GLAMO_DRIVER_NAME, &devSections); - if (numDevSections <= 0) - return FALSE; + if (numDevSections <= 0) return FALSE; /* Is today a good day to use KMS? */ if ( GlamoKernelModesettingAvailable() ) { - - foundScreen = TRUE; - - pScrn = xf86AllocateScreen(drv, 0); - - /* Plug in KMS functions instead of the conventional ones */ - pScrn->driverVersion = GLAMO_VERSION; - pScrn->driverName = GLAMO_DRIVER_NAME; - pScrn->name = GLAMO_NAME; - pScrn->PreInit = GlamoKMSPreInit; - pScrn->ScreenInit = GlamoKMSScreenInit; - pScrn->SwitchMode = GlamoKMSSwitchMode; - pScrn->AdjustFrame = GlamoKMSAdjustFrame; - pScrn->EnterVT = GlamoKMSEnterVT; - pScrn->LeaveVT = GlamoKMSLeaveVT; - pScrn->ValidMode = GlamoKMSValidMode; - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using KMS!"); - + foundScreen = GlamoKMSProbe(drv, devSections, numDevSections); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using KMS!\n"); } else { - - if (!xf86LoadDrvSubModule(drv, "fbdevhw")) - return FALSE; - - for (i = 0; i < numDevSections; i++) { - dev = xf86FindOptionValue(devSections[i]->options, - "Device"); - if (fbdevHWProbe(NULL, dev, NULL)) { - int entity; - pScrn = NULL; - - entity = xf86ClaimFbSlot(drv, 0, devSections[i], - TRUE); - pScrn = xf86ConfigFbEntity(pScrn,0,entity, NULL, - NULL, NULL, NULL); - - if (pScrn) { - foundScreen = TRUE; - - pScrn->driverVersion = GLAMO_VERSION; - pScrn->driverName = GLAMO_DRIVER_NAME; - pScrn->name = GLAMO_NAME; - pScrn->Probe = GlamoProbe; - pScrn->PreInit = GlamoPreInit; - pScrn->ScreenInit = GlamoScreenInit; - pScrn->SwitchMode = GlamoSwitchMode; - pScrn->AdjustFrame - = fbdevHWAdjustFrameWeak(); - pScrn->EnterVT = GlamoEnterVT; - pScrn->LeaveVT = GlamoLeaveVT; - pScrn->ValidMode - = fbdevHWValidModeWeak(); - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "using %s\n", - dev ? dev : "default device"); - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Not using KMS"); - - } - } - } - + foundScreen = GlamoFbdevProbe(drv, devSections, numDevSections); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Not using KMS\n"); } xfree(devSections); diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index c92e4d6..bc4d933 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -212,8 +212,8 @@ Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags) pScrn->progClock = TRUE; pScrn->rgbBits = 8; - if ( !xf86SetDepthBpp(pScrn, 0, 0, 0, PreferConvert24to32 - | SupportConvert24to32 | Support32bppFb) ) { + /* Prefer 16bpp for everything */ + if ( !xf86SetDepthBpp(pScrn, 16, 16, 16, NoDepth24Support) ) { return FALSE; } @@ -341,6 +341,7 @@ Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, } pScrn->pScreen = pScreen; + pGlamo->pScreen = pScreen; /* HW dependent - FIXME */ pScrn->displayWidth = pScrn->virtualX; diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 8e31a22..f46a0b1 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -518,12 +518,15 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) if ( !exa ) return; pGlamo->exa = exa; + exa->exa_major = EXA_VERSION_MAJOR; + exa->exa_minor = EXA_VERSION_MINOR; exa->memoryBase = 0; exa->memorySize = 0; exa->offScreenBase = 0; - - exa->exa_major = EXA_VERSION_MAJOR; - exa->exa_minor = EXA_VERSION_MINOR; + exa->pixmapOffsetAlign = 2; + exa->pixmapPitchAlign = 2; + exa->maxX = 640; + exa->maxY = 640; /* Solid fills */ exa->PrepareSolid = GlamoKMSExaPrepareSolid; @@ -548,11 +551,6 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) // exa->MarkSync = GlamoKMSExaMarkSync; exa->WaitMarker = GlamoKMSExaWaitMarker; - exa->pixmapOffsetAlign = 2; - exa->pixmapPitchAlign = 2; - - exa->maxX = 640; - exa->maxY = 640; pGlamo->cmdq_objs = malloc(1024); pGlamo->cmdq_obj_pos = malloc(1024); @@ -568,7 +566,10 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) exa->PixmapIsOffscreen = GlamoKMSExaPixmapIsOffscreen; exa->ModifyPixmapHeader = GlamoKMSExaModifyPixmapHeader; - success = exaDriverInit(pGlamo->pScreen, exa); + /* Hook up with libdrm */ + pGlamo->bufmgr = glamo_bo_manager_gem_ctor(pGlamo->drm_fd); + + success = exaDriverInit(pScrn->pScreen, exa); if (success) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initialized EXA acceleration\n"); -- cgit v1.2.3 From 4fa134e23f682cdb57b01072ee07ee90342266b9 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 28 Jul 2009 17:36:00 +0100 Subject: Initialisation no longer segfaults... --- src/Makefile.am | 2 +- src/glamo-dri2.c | 1 - src/glamo-dri2.h | 2 -- src/glamo-drm-cmdq.h | 2 +- src/glamo-kms-driver.c | 17 ++++++++++--- src/glamo-kms-exa.c | 67 +++++++++++++++++++++++++++++++++++++++++--------- 6 files changed, 71 insertions(+), 20 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index e49ae6f..374be96 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,7 +25,7 @@ # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. AM_CFLAGS = @XORG_CFLAGS@ @DRI_CFLAGS@ -pedantic -Wall -Werror -std=gnu99 glamo_drv_la_LTLIBRARIES = glamo_drv.la -glamo_drv_la_LDFLAGS = -module -avoid-version +glamo_drv_la_LDFLAGS = -module -avoid-version -ldrm -ldrm_glamo glamo_drv_ladir = @moduledir@/drivers glamo_drv_la_SOURCES = \ diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index 2491f82..b500067 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -181,6 +181,5 @@ void driScreenInit(ScreenPtr pScreen) void driCloseScreen(ScreenPtr pScreen) { - driUnlock(pScreen); DRI2CloseScreen(pScreen); } diff --git a/src/glamo-dri2.h b/src/glamo-dri2.h index 8ec99b9..5834410 100644 --- a/src/glamo-dri2.h +++ b/src/glamo-dri2.h @@ -24,5 +24,3 @@ extern void driScreenInit(ScreenPtr pScreen); extern void driCloseScreen(ScreenPtr pScreen); -extern void driLock(ScreenPtr pScreen); -extern void driUnlock(ScreenPtr pScreen); diff --git a/src/glamo-drm-cmdq.h b/src/glamo-drm-cmdq.h index 11d1752..85df1c0 100644 --- a/src/glamo-drm-cmdq.h +++ b/src/glamo-drm-cmdq.h @@ -109,7 +109,7 @@ do { \ __packet0count = n; \ } while (0) -#endif +#endif /* CCE_DEBUG */ #define OUT_PAIR(v1, v2) \ do { \ diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index bc4d933..ac19ead 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -311,6 +311,15 @@ static Bool GlamoKMSCreateScreenResources(ScreenPtr pScreen) if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL)) FatalError("Couldn't adjust screen pixmap\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Adding framebuffer....!\n"); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%i %i %i %i %i %i\n", + pGlamo->drm_fd, pScrn->virtualX, pScrn->virtualY, + pScrn->depth, pScrn->bitsPerPixel, + pScrn->displayWidth * pScrn->bitsPerPixel / 8); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "rootPixmap = %p\n", (void *)rootPixmap); + drmModeAddFB(pGlamo->drm_fd, pScrn->virtualX, pScrn->virtualY, @@ -319,10 +328,14 @@ static Bool GlamoKMSCreateScreenResources(ScreenPtr pScreen) pScrn->displayWidth * pScrn->bitsPerPixel / 8, driGetPixmapHandle(rootPixmap, &flags), &pGlamo->fb_id); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Done\n"); + GlamoKMSAdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Finished\n"); + return ret; } @@ -431,8 +444,6 @@ Bool GlamoKMSEnterVT(int scrnIndex, int flags) ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; GlamoPtr pGlamo = GlamoPTR(pScrn); - driUnlock(pScrn->pScreen); - /* 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 ( pGlamo->SaveGeneration != serverGeneration ) { @@ -473,8 +484,6 @@ void GlamoKMSLeaveVT(int scrnIndex, int flags) drmModeRmFB(pGlamo->drm_fd, pGlamo->fb_id); - driLock(pScrn->pScreen); - pScrn->vtSema = FALSE; } diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index f46a0b1..22c609e 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -58,6 +58,7 @@ #include #include +#include #include @@ -150,6 +151,9 @@ unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) FatalError("NO PIXMAP PRIVATE\n"); return 0; } + xf86Msg(X_INFO, "priv=%p\n", (void *)priv); + xf86Msg(X_INFO, "priv->bo=%p\n", (void *)priv->bo); + xf86Msg(X_INFO, "priv->bo->handle=%i\n", priv->bo->handle); return priv->bo->handle; } @@ -159,22 +163,22 @@ Bool GlamoKMSExaPrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg) { ScrnInfoPtr pScrn = xf86Screens[pPix->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); - CARD32 offset; CARD16 op, pitch; FbBits mask; RING_LOCALS; struct glamo_exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPix); - if (pPix->drawable.bitsPerPixel != 16) + if (pPix->drawable.bitsPerPixel != 16) { GLAMO_FALLBACK(("Only 16bpp is supported\n")); + } mask = FbFullMask(16); - if ((pm & mask) != mask) + if ((pm & mask) != mask) { GLAMO_FALLBACK(("Can't do planemask 0x%08x\n", - (unsigned int) pm)); + (unsigned int)pm)); + } op = GLAMOSolidRop[alu] << 8; - offset = exaGetPixmapOffset(pPix); pitch = pPix->devKind; BEGIN_CMDQ(16); @@ -379,6 +383,8 @@ static void *GlamoKMSExaCreatePixmap(ScreenPtr screen, int size, int align) 0 /* flags */ ); if (!new_priv->bo) { xfree(new_priv); + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Failed to create pixmap\n"); return NULL; } @@ -478,21 +484,54 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, { ScreenPtr screen = pPix->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; -// GlamoPtr pGlamo = GlamoPTR(pScrn); - PixmapPtr screen_pixmap = screen->GetScreenPixmap(screen); + GlamoPtr pGlamo = GlamoPTR(pScrn); + struct glamo_exa_pixmap_priv *priv; xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ModifyPixmapHeader. " "%ix%ix%i %ibpp, %i\n", width, height, depth, bitsPerPixel, devKind); + if (depth <= 0) depth = pPix->drawable.depth; + if (bitsPerPixel <= 0) bitsPerPixel = pPix->drawable.bitsPerPixel; + if (width <= 0) width = pPix->drawable.width; + if (height <= 0) height = pPix->drawable.height; + if (width <= 0 || height <= 0 || depth <= 0) return FALSE; + miModifyPixmapHeader(pPix, width, height, depth, bitsPerPixel, devKind, NULL); - if ( pPix == screen_pixmap ) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Screen pixmap!"); + priv = exaGetPixmapDriverPrivate(pPix); + if (!priv) { + /* This should never, ever, happen */ + FatalError("NO PIXMAP PRIVATE\n"); + return FALSE; } + if ( priv->bo == NULL ) { + + int size; + + /* This pixmap has no associated buffer object. + * It's time to create one */ + size = width * height * (depth/8); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Creating pixmap BO" + " (%i bytes)\n", size); + priv->bo = pGlamo->bufmgr->funcs->bo_open(pGlamo->bufmgr, + 0, /* handle */ + size, + 2, + GLAMO_GEM_DOMAIN_VRAM, + 0 /* flags */ ); + + if ( priv->bo == NULL ) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Failed to create buffer object" + " in ModifyPixmapHeader.\n"); + return FALSE; + } + + } return FALSE; } @@ -507,9 +546,9 @@ void GlamoKMSExaClose(ScrnInfoPtr pScrn) void GlamoKMSExaInit(ScrnInfoPtr pScrn) { GlamoPtr pGlamo = GlamoPTR(pScrn); - Bool success = FALSE; ExaDriverPtr exa; + MemBuf *buf; xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "EXA hardware acceleration initialising\n"); @@ -551,10 +590,16 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) // exa->MarkSync = GlamoKMSExaMarkSync; exa->WaitMarker = GlamoKMSExaWaitMarker; - + /* Prepare temporary buffers */ pGlamo->cmdq_objs = malloc(1024); pGlamo->cmdq_obj_pos = malloc(1024); pGlamo->cmdq_obj_used = 0; + pGlamo->ring_len = 4 * 1024; + buf = (MemBuf *)xcalloc(1, sizeof(MemBuf) + pGlamo->ring_len); + if (!buf) return; + buf->size = pGlamo->ring_len; + buf->used = 0; + pGlamo->cmd_queue = buf; /* Tell EXA that we're going to take care of memory * management ourselves. */ -- cgit v1.2.3 From 924cd7045c6d520fbd25da05440960143e958a2d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 29 Jul 2009 00:38:58 +0100 Subject: Add a missing newline --- src/glamo-kms-exa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 22c609e..4e0f213 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -135,7 +135,7 @@ void GlamoDRMDispatch(GlamoPtr pGlamo) &cmdbuf, sizeof(cmdbuf)); if ( r != 0 ) { xf86DrvMsg(pGlamo->pScreen->myNum, X_ERROR, - "DRM_GLAMO_CMDBUF failed"); + "DRM_GLAMO_CMDBUF failed\n"); } pGlamo->cmdq_obj_used = 0; -- cgit v1.2.3 From 6a86258bb9dbda75dfbf6610b12fc1442b0fa7ba Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 30 Jul 2009 00:41:16 +0100 Subject: Use proper types for cmdq submission --- src/glamo-drm-cmdq.h | 4 ++-- src/glamo-kms-exa.c | 4 ++-- src/glamo.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/glamo-drm-cmdq.h b/src/glamo-drm-cmdq.h index 85df1c0..79bc512 100644 --- a/src/glamo-drm-cmdq.h +++ b/src/glamo-drm-cmdq.h @@ -31,7 +31,7 @@ #if !CCE_DEBUG #define RING_LOCALS CARD16 *__head; int __count; int __objects; \ - char *__objs; char *__obj_pos; + uint32_t *__objs; unsigned int *__obj_pos; #define BEGIN_CMDQ(n) \ do { \ @@ -64,7 +64,7 @@ do { \ #define RING_LOCALS \ CARD16 *__head; int __count, __total, __reg, __packet0count; \ - int __objects; char *__objs; char *__obj_pos; + int __objects; uint32_t *__objs; unsigned int *__obj_pos; #define BEGIN_CMDQ(n) \ do { \ diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 4e0f213..c911f2c 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -129,7 +129,7 @@ void GlamoDRMDispatch(GlamoPtr pGlamo) cmdbuf.bufsz = pGlamo->cmd_queue->used; cmdbuf.nobjs = pGlamo->cmdq_obj_used; cmdbuf.objs = (uint32_t *)pGlamo->cmdq_objs; - cmdbuf.obj_pos = (int *)pGlamo->cmdq_obj_pos; + cmdbuf.obj_pos = pGlamo->cmdq_obj_pos; r = drmCommandWrite(pGlamo->drm_fd, DRM_GLAMO_CMDBUF, &cmdbuf, sizeof(cmdbuf)); @@ -445,7 +445,7 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) "%s: bo map failed\n", __FUNCTION__); return FALSE; } - pPix->devPrivate.ptr = driver_priv->bo->ptr; + pPix->devPrivate.ptr = driver_priv->bo->virtual; return TRUE; } diff --git a/src/glamo.h b/src/glamo.h index d802226..be4a1dc 100644 --- a/src/glamo.h +++ b/src/glamo.h @@ -107,8 +107,8 @@ typedef struct { */ MemBuf *cmd_queue; int cmdq_obj_used; - char *cmdq_objs; - char *cmdq_obj_pos; + uint32_t *cmdq_objs; + unsigned int *cmdq_obj_pos; /* What was GLAMOCardInfo */ volatile char *reg_base; -- cgit v1.2.3 From d476b80f89e976166228905489e4742ae2df2e0e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 6 Aug 2009 17:07:13 +0100 Subject: Fix command queue submission This reworks the command queue caching and submission so that it works, and makes it a lot more maintainable in the process. --- src/glamo-drm-cmdq.h | 131 ------------------------------------------------ src/glamo-kms-exa.c | 137 ++++++++++++++++++++++++--------------------------- src/glamo.h | 5 ++ 3 files changed, 70 insertions(+), 203 deletions(-) delete mode 100644 src/glamo-drm-cmdq.h diff --git a/src/glamo-drm-cmdq.h b/src/glamo-drm-cmdq.h deleted file mode 100644 index 79bc512..0000000 --- a/src/glamo-drm-cmdq.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2007 OpenMoko, Inc. - * - * This driver is based on Xati, - * Copyright 2004 Eric Anholt - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _GLAMO_DRM_CMDQ_H_ -#define _GLAMO_DRM_CMDQ_H_ - -#define CCE_DEBUG 0 - -#if !CCE_DEBUG - -#define RING_LOCALS CARD16 *__head; int __count; int __objects; \ - uint32_t *__objs; unsigned int *__obj_pos; - -#define BEGIN_CMDQ(n) \ -do { \ - if ((pGlamo->cmd_queue->used + 2 * (n)) > \ - pGlamo->cmd_queue->size) { \ - GlamoDRMDispatch(pGlamo); \ - } \ - __head = (CARD16 *)((char *)pGlamo->cmd_queue->data + \ - pGlamo->cmd_queue->used); \ - __count = 0; \ - __objects = 0; \ - __objs = pGlamo->cmdq_objs + (pGlamo->cmdq_obj_used*2); \ - __obj_pos = pGlamo->cmdq_obj_pos + (pGlamo->cmdq_obj_used*2); \ -} while (0) - -#define END_CMDQ() do { \ - pGlamo->cmd_queue->used += __count * 2; \ -} while (0) - -#define OUT_BURST_REG(reg, val) do { \ - __head[__count++] = (val); \ -} while (0) - -#define OUT_BURST(reg, n) \ -do { \ - OUT_PAIR((1 << 15) | reg, n); \ -} while (0) - -#else /* CCE_DEBUG */ - -#define RING_LOCALS \ - CARD16 *__head; int __count, __total, __reg, __packet0count; \ - int __objects; uint32_t *__objs; unsigned int *__obj_pos; - -#define BEGIN_CMDQ(n) \ -do { \ - if ((pGlamo->cmd_queue->used + 2 * (n)) > \ - pGlamo->cmd_queue->size) { \ - GlamoDRMDispatch(pGlamo); \ - } \ - __head = (CARD16 *)((char *)pGlamo->cmd_queue->data + \ - pGlamo->cmd_queue->used); \ - __count = 0; \ - __total = n; \ - __reg = 0; \ - __packet0count = 0; \ - __objects = 0; \ - __objs = pGlamo->cmdq_objs + (pGlamo->cmdq_obj_used*2); \ - __obj_pos = pGlamo->cmdq_obj_pos + (pGlamo->cmdq_obj_used*2); \ -} while (0) - -#define END_CMDQ() do { \ - if (__count != __total) \ - FatalError("count != total (%d vs %d) at %s:%d\n", \ - __count, __total, __FILE__, __LINE__); \ - pGlamo->cmd_queue->used += __count * 2; \ - pGlamo->cmdq_objs_used += __objects; \ -} while (0) - -#define OUT_BURST_REG(reg, val) do { \ - if (__reg != reg) \ - FatalError("unexpected reg (0x%x vs 0x%x) at %s:%d\n", \ - reg, __reg, __FILE__, __LINE__); \ - if (__packet0count-- <= 0) \ - FatalError("overrun of packet0 at %s:%d\n", \ - __FILE__, __LINE__); \ - __head[__count++] = (val); \ - __reg += 2; \ -} while (0) - -#define OUT_BURST(reg, n) \ -do { \ - OUT_PAIR((1 << 15) | reg, n); \ - __reg = reg; \ - __packet0count = n; \ -} while (0) - -#endif /* CCE_DEBUG */ - -#define OUT_PAIR(v1, v2) \ -do { \ - __head[__count++] = (v1); \ - __head[__count++] = (v2); \ -} while (0) - - -#define OUT_REG(reg, val) \ - OUT_PAIR(reg, val) - -#define OUT_REG_BO(reg, bo) __objs[__objects] = bo->handle; \ - __obj_pos[__objects++] = __count; \ - __head[__count++] = (reg); \ - __head[__count++] = 0x0000; \ - __head[__count++] = (reg+2); \ - __head[__count++] = 0x0000; - -#endif /* _GLAMO_DRM_CMDQ_H_ */ diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index c911f2c..9c98724 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -54,7 +54,6 @@ #include "glamo-log.h" #include "glamo.h" #include "glamo-regs.h" -#include "glamo-drm-cmdq.h" #include #include @@ -119,16 +118,42 @@ static const CARD8 GLAMOBltRop[16] = { }; +static inline void GlamoDRMAddCommand(GlamoPtr pGlamo, uint16_t reg, + uint16_t val) +{ + /* Record command */ + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg; + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = val; +} + + +static inline void GlamoDRMAddCommandBO(GlamoPtr pGlamo, uint16_t reg, + struct glamo_bo *bo) +{ + /* Record object position */ + pGlamo->cmdq_objs[pGlamo->cmdq_obj_used] = bo->handle; + /* -> bytes */ + pGlamo->cmdq_obj_pos[pGlamo->cmdq_obj_used] = pGlamo->cmdq_drm_used * 2; + pGlamo->cmdq_obj_used++; + + /* Record command */ + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg; + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = 0x0000; + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg+2; + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = 0x0000; +} + + /* Submit the prepared command sequence to the kernel */ -void GlamoDRMDispatch(GlamoPtr pGlamo) +static void GlamoDRMDispatch(GlamoPtr pGlamo) { drm_glamo_cmd_buffer_t cmdbuf; int r; - cmdbuf.buf = (char *)pGlamo->cmd_queue; - cmdbuf.bufsz = pGlamo->cmd_queue->used; + cmdbuf.buf = (char *)pGlamo->cmdq_drm; + cmdbuf.bufsz = pGlamo->cmdq_drm_used * 2; /* -> bytes */ cmdbuf.nobjs = pGlamo->cmdq_obj_used; - cmdbuf.objs = (uint32_t *)pGlamo->cmdq_objs; + cmdbuf.objs = pGlamo->cmdq_objs; cmdbuf.obj_pos = pGlamo->cmdq_obj_pos; r = drmCommandWrite(pGlamo->drm_fd, DRM_GLAMO_CMDBUF, @@ -138,7 +163,9 @@ void GlamoDRMDispatch(GlamoPtr pGlamo) "DRM_GLAMO_CMDBUF failed\n"); } + /* Reset counts to zero for the next sequence */ pGlamo->cmdq_obj_used = 0; + pGlamo->cmdq_drm_used = 0; } @@ -151,9 +178,6 @@ unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) FatalError("NO PIXMAP PRIVATE\n"); return 0; } - xf86Msg(X_INFO, "priv=%p\n", (void *)priv); - xf86Msg(X_INFO, "priv->bo=%p\n", (void *)priv->bo); - xf86Msg(X_INFO, "priv->bo->handle=%i\n", priv->bo->handle); return priv->bo->handle; } @@ -165,7 +189,6 @@ Bool GlamoKMSExaPrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg) GlamoPtr pGlamo = GlamoPTR(pScrn); CARD16 op, pitch; FbBits mask; - RING_LOCALS; struct glamo_exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPix); if (pPix->drawable.bitsPerPixel != 16) { @@ -181,15 +204,13 @@ Bool GlamoKMSExaPrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg) op = GLAMOSolidRop[alu] << 8; pitch = pPix->devKind; - BEGIN_CMDQ(16); - OUT_REG_BO(GLAMO_REG_2D_DST_ADDRL, priv->bo); - OUT_REG(GLAMO_REG_2D_DST_PITCH, pitch & 0x7ff); - OUT_REG(GLAMO_REG_2D_DST_HEIGHT, pPix->drawable.height); - OUT_REG(GLAMO_REG_2D_PAT_FG, fg); - OUT_REG(GLAMO_REG_2D_COMMAND2, op); - OUT_REG(GLAMO_REG_2D_ID1, 0); - OUT_REG(GLAMO_REG_2D_ID2, 0); - END_CMDQ(); + GlamoDRMAddCommandBO(pGlamo, GLAMO_REG_2D_DST_ADDRL, priv->bo); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_PITCH, pitch & 0x7ff); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_HEIGHT, pPix->drawable.height); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_PAT_FG, fg); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_COMMAND2, op); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_ID1, 0); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_ID2, 0); return TRUE; } @@ -199,15 +220,12 @@ void GlamoKMSExaSolid(PixmapPtr pPix, int x1, int y1, int x2, int y2) { ScrnInfoPtr pScrn = xf86Screens[pPix->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); - RING_LOCALS; - - BEGIN_CMDQ(10); - OUT_REG(GLAMO_REG_2D_DST_X, x1); - OUT_REG(GLAMO_REG_2D_DST_Y, y1); - OUT_REG(GLAMO_REG_2D_RECT_WIDTH, x2 - x1); - OUT_REG(GLAMO_REG_2D_RECT_HEIGHT, y2 - y1); - OUT_REG(GLAMO_REG_2D_COMMAND3, 0); - END_CMDQ(); + + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_X, x1); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_Y, y1); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_RECT_WIDTH, x2 - x1); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_RECT_HEIGHT, y2 - y1); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_COMMAND3, 0); } @@ -226,7 +244,6 @@ Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, { ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); - RING_LOCALS; FbBits mask; CARD32 src_offset, dst_offset; CARD16 src_pitch, dst_pitch; @@ -255,18 +272,16 @@ Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, op = GLAMOBltRop[alu] << 8; - BEGIN_CMDQ(20); - OUT_REG_BO(GLAMO_REG_2D_SRC_ADDRL, priv_src->bo); - OUT_REG(GLAMO_REG_2D_SRC_PITCH, src_pitch & 0x7ff); + GlamoDRMAddCommandBO(pGlamo, GLAMO_REG_2D_SRC_ADDRL, priv_src->bo); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_SRC_PITCH, src_pitch & 0x7ff); - OUT_REG_BO(GLAMO_REG_2D_DST_ADDRL, priv_dst->bo); - OUT_REG(GLAMO_REG_2D_DST_PITCH, dst_pitch & 0x7ff); - OUT_REG(GLAMO_REG_2D_DST_HEIGHT, pDst->drawable.height); + GlamoDRMAddCommandBO(pGlamo, GLAMO_REG_2D_DST_ADDRL, priv_dst->bo); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_PITCH, dst_pitch & 0x7ff); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_HEIGHT, pDst->drawable.height); - OUT_REG(GLAMO_REG_2D_COMMAND2, op); - OUT_REG(GLAMO_REG_2D_ID1, 0); - OUT_REG(GLAMO_REG_2D_ID2, 0); - END_CMDQ(); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_COMMAND2, op); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_ID1, 0); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_ID2, 0); return TRUE; } @@ -277,17 +292,14 @@ void GlamoKMSExaCopy(PixmapPtr pDst, int srcX, int srcY, int dstX, int dstY, { ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); - RING_LOCALS; - - BEGIN_CMDQ(14); - OUT_REG(GLAMO_REG_2D_SRC_X, srcX); - OUT_REG(GLAMO_REG_2D_SRC_Y, srcY); - OUT_REG(GLAMO_REG_2D_DST_X, dstX); - OUT_REG(GLAMO_REG_2D_DST_Y, dstY); - OUT_REG(GLAMO_REG_2D_RECT_WIDTH, width); - OUT_REG(GLAMO_REG_2D_RECT_HEIGHT, height); - OUT_REG(GLAMO_REG_2D_COMMAND3, 0); - END_CMDQ(); + + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_SRC_X, srcX); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_SRC_Y, srcY); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_X, dstX); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_Y, dstY); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_RECT_WIDTH, width); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_RECT_HEIGHT, height); + GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_COMMAND3, 0); } @@ -363,9 +375,6 @@ static void *GlamoKMSExaCreatePixmap(ScreenPtr screen, int size, int align) GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *new_priv; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Creating a new pixmap, size=%i\n", - size); - new_priv = xcalloc(1, sizeof(struct glamo_exa_pixmap_priv)); if (!new_priv) return NULL; @@ -398,8 +407,6 @@ static void GlamoKMSExaDestroyPixmap(ScreenPtr screen, void *driverPriv) GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *driver_priv = driverPriv; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Destroying a pixmap\n"); - if (driver_priv->bo) pGlamo->bufmgr->funcs->bo_unref(driver_priv->bo); xfree(driver_priv); @@ -425,8 +432,6 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *driver_priv; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Prepare access\n"); - driver_priv = exaGetPixmapDriverPrivate(pPix); if (!driver_priv) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, @@ -458,8 +463,6 @@ static void GlamoKMSExaFinishAccess(PixmapPtr pPix, int index) GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *driver_priv; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Finish access\n"); - driver_priv = exaGetPixmapDriverPrivate(pPix); if (!driver_priv) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, @@ -487,11 +490,6 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *priv; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ModifyPixmapHeader. " - "%ix%ix%i %ibpp, %i\n", - width, height, depth, - bitsPerPixel, devKind); - if (depth <= 0) depth = pPix->drawable.depth; if (bitsPerPixel <= 0) bitsPerPixel = pPix->drawable.bitsPerPixel; if (width <= 0) width = pPix->drawable.width; @@ -515,8 +513,6 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, /* This pixmap has no associated buffer object. * It's time to create one */ size = width * height * (depth/8); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Creating pixmap BO" - " (%i bytes)\n", size); priv->bo = pGlamo->bufmgr->funcs->bo_open(pGlamo->bufmgr, 0, /* handle */ size, @@ -548,7 +544,6 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) GlamoPtr pGlamo = GlamoPTR(pScrn); Bool success = FALSE; ExaDriverPtr exa; - MemBuf *buf; xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "EXA hardware acceleration initialising\n"); @@ -594,12 +589,10 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) pGlamo->cmdq_objs = malloc(1024); pGlamo->cmdq_obj_pos = malloc(1024); pGlamo->cmdq_obj_used = 0; - pGlamo->ring_len = 4 * 1024; - buf = (MemBuf *)xcalloc(1, sizeof(MemBuf) + pGlamo->ring_len); - if (!buf) return; - buf->size = pGlamo->ring_len; - buf->used = 0; - pGlamo->cmd_queue = buf; + pGlamo->cmdq_drm_used = 0; + pGlamo->cmdq_drm_size = 4 * 1024; + pGlamo->cmdq_drm = malloc(pGlamo->cmdq_drm_size); + if ( !pGlamo->cmdq_drm ) return; /* Tell EXA that we're going to take care of memory * management ourselves. */ diff --git a/src/glamo.h b/src/glamo.h index be4a1dc..531c719 100644 --- a/src/glamo.h +++ b/src/glamo.h @@ -106,6 +106,11 @@ typedef struct { * "at once", when we are happy with it. */ MemBuf *cmd_queue; + + /* The same, when using DRM */ + uint16_t *cmdq_drm; + int cmdq_drm_used; + int cmdq_drm_size; int cmdq_obj_used; uint32_t *cmdq_objs; unsigned int *cmdq_obj_pos; -- cgit v1.2.3 From 46614ccd7895a45efbfd4e57d732cf7041952b5e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 9 Aug 2009 23:17:37 +0100 Subject: Small tidy up --- src/glamo-kms-driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index ac19ead..bf47131 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -349,8 +349,8 @@ Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, /* Deal with server regeneration */ if ( pGlamo->drm_fd < 0 ) { - pGlamo->drm_fd = drmOpen(NULL, "platform:glamo-fb"); - if ( pGlamo->drm_fd < 0 ) return FALSE; + pGlamo->drm_fd = drmOpen(NULL, "platform:glamo-fb"); + if ( pGlamo->drm_fd < 0 ) return FALSE; } pScrn->pScreen = pScreen; -- cgit v1.2.3 From 5f22287cc1a3b3e9e7f6e5f871c81fc0c93aec50 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 9 Aug 2009 23:18:40 +0100 Subject: Dispatch command buffer when cache is full --- src/glamo-kms-exa.c | 62 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 9c98724..99fab0c 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -118,9 +118,40 @@ static const CARD8 GLAMOBltRop[16] = { }; +/* Submit the prepared command sequence to the kernel */ +static void GlamoDRMDispatch(GlamoPtr pGlamo) +{ + drm_glamo_cmd_buffer_t cmdbuf; + int r; + + cmdbuf.buf = (char *)pGlamo->cmdq_drm; + cmdbuf.bufsz = pGlamo->cmdq_drm_used * 2; /* -> bytes */ + cmdbuf.nobjs = pGlamo->cmdq_obj_used; + cmdbuf.objs = pGlamo->cmdq_objs; + cmdbuf.obj_pos = pGlamo->cmdq_obj_pos; + + r = drmCommandWrite(pGlamo->drm_fd, DRM_GLAMO_CMDBUF, + &cmdbuf, sizeof(cmdbuf)); + if ( r != 0 ) { + xf86DrvMsg(pGlamo->pScreen->myNum, X_ERROR, + "DRM_GLAMO_CMDBUF failed\n"); + } + + /* Reset counts to zero for the next sequence */ + pGlamo->cmdq_obj_used = 0; + pGlamo->cmdq_drm_used = 0; +} + + static inline void GlamoDRMAddCommand(GlamoPtr pGlamo, uint16_t reg, uint16_t val) { + if ( pGlamo->cmdq_drm_used == pGlamo->cmdq_drm_size ) { + xf86DrvMsg(pGlamo->pScreen->myNum, X_INFO, + "Forced command cache flush.\n"); + GlamoDRMDispatch(pGlamo); + } + /* Record command */ pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg; pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = val; @@ -130,6 +161,12 @@ static inline void GlamoDRMAddCommand(GlamoPtr pGlamo, uint16_t reg, static inline void GlamoDRMAddCommandBO(GlamoPtr pGlamo, uint16_t reg, struct glamo_bo *bo) { + if ( pGlamo->cmdq_drm_used == pGlamo->cmdq_drm_size ) { + xf86DrvMsg(pGlamo->pScreen->myNum, X_INFO, + "Forced command cache flush.\n"); + GlamoDRMDispatch(pGlamo); + } + /* Record object position */ pGlamo->cmdq_objs[pGlamo->cmdq_obj_used] = bo->handle; /* -> bytes */ @@ -144,31 +181,6 @@ static inline void GlamoDRMAddCommandBO(GlamoPtr pGlamo, uint16_t reg, } -/* Submit the prepared command sequence to the kernel */ -static void GlamoDRMDispatch(GlamoPtr pGlamo) -{ - drm_glamo_cmd_buffer_t cmdbuf; - int r; - - cmdbuf.buf = (char *)pGlamo->cmdq_drm; - cmdbuf.bufsz = pGlamo->cmdq_drm_used * 2; /* -> bytes */ - cmdbuf.nobjs = pGlamo->cmdq_obj_used; - cmdbuf.objs = pGlamo->cmdq_objs; - cmdbuf.obj_pos = pGlamo->cmdq_obj_pos; - - r = drmCommandWrite(pGlamo->drm_fd, DRM_GLAMO_CMDBUF, - &cmdbuf, sizeof(cmdbuf)); - if ( r != 0 ) { - xf86DrvMsg(pGlamo->pScreen->myNum, X_ERROR, - "DRM_GLAMO_CMDBUF failed\n"); - } - - /* Reset counts to zero for the next sequence */ - pGlamo->cmdq_obj_used = 0; - pGlamo->cmdq_drm_used = 0; -} - - unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) { struct glamo_exa_pixmap_priv *priv; -- cgit v1.2.3 From 828eb144d587c3def9ae3ba7ff273f02fc7fa00d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 9 Aug 2009 23:20:14 +0100 Subject: Remove upload/download EXA functions - can't accelerate these --- src/glamo-kms-exa.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 99fab0c..4aec710 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -357,20 +357,6 @@ void GlamoKMSExaDoneComposite(PixmapPtr pDst) } -Bool GlamoKMSExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, - char *src, int src_pitch) -{ - return FALSE; -} - - -Bool GlamoKMSExaDownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, - char *dst, int dst_pitch) -{ - return FALSE; -} - - void GlamoKMSExaWaitMarker(ScreenPtr pScreen, int marker) { // ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; @@ -590,8 +576,8 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) exa->Composite = GlamoKMSExaComposite; exa->DoneComposite = GlamoKMSExaDoneComposite; - exa->DownloadFromScreen = GlamoKMSExaDownloadFromScreen; - exa->UploadToScreen = GlamoKMSExaUploadToScreen; + exa->DownloadFromScreen = NULL; + exa->UploadToScreen = NULL; exa->UploadToScratch = NULL; // exa->MarkSync = GlamoKMSExaMarkSync; -- cgit v1.2.3 From 625f242ec50bba88fb8010b0e8a8c0c7781b2960 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 9 Aug 2009 23:20:48 +0100 Subject: Use libDRM functions instead of bom->funcs etc --- src/glamo-kms-exa.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 4aec710..3d9701f 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -382,12 +382,8 @@ static void *GlamoKMSExaCreatePixmap(ScreenPtr screen, int size, int align) return new_priv; /* Dive into the kernel (via libdrm) to allocate some VRAM */ - new_priv->bo = pGlamo->bufmgr->funcs->bo_open(pGlamo->bufmgr, - 0, /* handle */ - size, - align, - GLAMO_GEM_DOMAIN_VRAM, - 0 /* flags */ ); + new_priv->bo = glamo_bo_open(pGlamo->bufmgr, 0, size, align, + GLAMO_GEM_DOMAIN_VRAM, 0); if (!new_priv->bo) { xfree(new_priv); xf86DrvMsg(pScrn->scrnIndex, X_WARNING, @@ -401,12 +397,11 @@ static void *GlamoKMSExaCreatePixmap(ScreenPtr screen, int size, int align) static void GlamoKMSExaDestroyPixmap(ScreenPtr screen, void *driverPriv) { - ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *driver_priv = driverPriv; if (driver_priv->bo) - pGlamo->bufmgr->funcs->bo_unref(driver_priv->bo); + glamo_bo_unref(driver_priv->bo); + xfree(driver_priv); } @@ -427,7 +422,6 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) { ScreenPtr screen = pPix->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *driver_priv; driver_priv = exaGetPixmapDriverPrivate(pPix); @@ -443,7 +437,7 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) return TRUE; } - if (pGlamo->bufmgr->funcs->bo_map(driver_priv->bo, 1)) { + if ( glamo_bo_map(driver_priv->bo, 1) ) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%s: bo map failed\n", __FUNCTION__); return FALSE; @@ -458,7 +452,6 @@ static void GlamoKMSExaFinishAccess(PixmapPtr pPix, int index) { ScreenPtr screen = pPix->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; - GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *driver_priv; driver_priv = exaGetPixmapDriverPrivate(pPix); @@ -474,7 +467,7 @@ static void GlamoKMSExaFinishAccess(PixmapPtr pPix, int index) return; } - pGlamo->bufmgr->funcs->bo_unmap(driver_priv->bo); + glamo_bo_unmap(driver_priv->bo); pPix->devPrivate.ptr = NULL; } @@ -510,13 +503,13 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, /* This pixmap has no associated buffer object. * It's time to create one */ - size = width * height * (depth/8); - priv->bo = pGlamo->bufmgr->funcs->bo_open(pGlamo->bufmgr, - 0, /* handle */ - size, - 2, - GLAMO_GEM_DOMAIN_VRAM, - 0 /* flags */ ); + size = (width * height * depth) / 8; + if ( size == 0 ) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Zero-sized pixmap in ModifyPixmapHeader\n"); + } + priv->bo = glamo_bo_open(pGlamo->bufmgr, 0, size, 2, + GLAMO_GEM_DOMAIN_VRAM, 0); if ( priv->bo == NULL ) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, -- cgit v1.2.3 From ee235f08f1cd4ffc96fcd3e9a690c2c954afd663 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 12 Aug 2009 23:46:46 +0100 Subject: Tidy up headers, formatting and unused code --- src/glamo-dri2.c | 14 ++++++------ src/glamo-kms-crtc.c | 1 + src/glamo-kms-crtc.h | 5 ----- src/glamo-kms-display.h | 27 ---------------------- src/glamo-kms-driver.c | 3 ++- src/glamo-kms-exa.c | 59 ++++++++++++++----------------------------------- src/glamo-kms-exa.h | 2 +- src/glamo-kms-output.c | 1 + src/glamo-kms-output.h | 25 +++++++++++++++++++++ 9 files changed, 54 insertions(+), 83 deletions(-) delete mode 100644 src/glamo-kms-display.h create mode 100644 src/glamo-kms-output.h diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index b500067..4186bfa 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -58,7 +58,7 @@ typedef struct { static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, - unsigned int *attachments, int count) + unsigned int *attachments, int count) { ScreenPtr pScreen = pDraw->pScreen; DRI2BufferPtr buffers; @@ -93,10 +93,10 @@ static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, /* Anything else - create a new pixmap */ pPixmap = (*pScreen->CreatePixmap)(pScreen, - pDraw->width, - pDraw->height, - pDraw->depth, - 0); + pDraw->width, + pDraw->height, + pDraw->depth, + 0); } @@ -117,7 +117,7 @@ static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, static void glamoDestroyBuffers(DrawablePtr pDraw, - DRI2BufferPtr buffers, int count) + DRI2BufferPtr buffers, int count) { ScreenPtr pScreen = pDraw->pScreen; int i; @@ -136,7 +136,7 @@ static void glamoDestroyBuffers(DrawablePtr pDraw, static void glamoCopyRegion(DrawablePtr pDraw, RegionPtr pRegion, - DRI2BufferPtr pDestBuffer, DRI2BufferPtr pSrcBuffer) + DRI2BufferPtr pDestBuffer, DRI2BufferPtr pSrcBuffer) { } diff --git a/src/glamo-kms-crtc.c b/src/glamo-kms-crtc.c index aafc539..17444b0 100644 --- a/src/glamo-kms-crtc.c +++ b/src/glamo-kms-crtc.c @@ -58,6 +58,7 @@ #include #include "glamo.h" +#include "glamo-kms-crtc.h" struct crtc_private diff --git a/src/glamo-kms-crtc.h b/src/glamo-kms-crtc.h index 8c16054..1860b2d 100644 --- a/src/glamo-kms-crtc.h +++ b/src/glamo-kms-crtc.h @@ -22,9 +22,4 @@ #include "xf86.h" -/* crtc.c */ extern void crtc_init(ScrnInfoPtr pScrn); - - -/* output.c */ -extern void output_init(ScrnInfoPtr pScrn); diff --git a/src/glamo-kms-display.h b/src/glamo-kms-display.h deleted file mode 100644 index 45b8eb7..0000000 --- a/src/glamo-kms-display.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * EXA via DRI for the SMedia Glamo3362 X.org Driver - * - * Copyright 2009 Thomas White - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - */ - -#include "xf86.h" - -extern void *GlamoKMSExaInit(ScrnInfoPtr pScrn); -extern void GlamoKMSExaClose(ScrnInfoPtr pScrn); -extern unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index bf47131..55d2377 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -72,6 +72,7 @@ #include "glamo-kms-exa.h" #include "glamo-dri2.h" #include "glamo-kms-crtc.h" +#include "glamo-kms-output.h" static const char *fbSymbols[] = { @@ -489,7 +490,7 @@ void GlamoKMSLeaveVT(int scrnIndex, int flags) ModeStatus GlamoKMSValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, - int flags) + int flags) { return MODE_OK; } diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 3d9701f..5303aeb 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -54,6 +54,7 @@ #include "glamo-log.h" #include "glamo.h" #include "glamo-regs.h" +#include "glamo-kms-exa.h" #include #include @@ -195,7 +196,7 @@ unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) } -Bool GlamoKMSExaPrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg) +static Bool GlamoKMSExaPrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg) { ScrnInfoPtr pScrn = xf86Screens[pPix->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); @@ -228,7 +229,7 @@ Bool GlamoKMSExaPrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg) } -void GlamoKMSExaSolid(PixmapPtr pPix, int x1, int y1, int x2, int y2) +static void GlamoKMSExaSolid(PixmapPtr pPix, int x1, int y1, int x2, int y2) { ScrnInfoPtr pScrn = xf86Screens[pPix->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); @@ -241,7 +242,7 @@ void GlamoKMSExaSolid(PixmapPtr pPix, int x1, int y1, int x2, int y2) } -void GlamoKMSExaDoneSolid(PixmapPtr pPix) +static void GlamoKMSExaDoneSolid(PixmapPtr pPix) { ScrnInfoPtr pScrn = xf86Screens[pPix->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); @@ -251,8 +252,8 @@ void GlamoKMSExaDoneSolid(PixmapPtr pPix) } -Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, - int alu, Pixel pm) +static Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, + int alu, Pixel pm) { ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); @@ -299,8 +300,8 @@ Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, } -void GlamoKMSExaCopy(PixmapPtr pDst, int srcX, int srcY, int dstX, int dstY, - int width, int height) +static void GlamoKMSExaCopy(PixmapPtr pDst, int srcX, int srcY, + int dstX, int dstY, int width, int height) { ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); @@ -315,7 +316,7 @@ void GlamoKMSExaCopy(PixmapPtr pDst, int srcX, int srcY, int dstX, int dstY, } -void GlamoKMSExaDoneCopy(PixmapPtr pDst) +static void GlamoKMSExaDoneCopy(PixmapPtr pDst) { ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); @@ -325,39 +326,13 @@ void GlamoKMSExaDoneCopy(PixmapPtr pDst) } -Bool GlamoKMSExaCheckComposite(int op, - PicturePtr pSrcPicture, - PicturePtr pMaskPicture, - PicturePtr pDstPicture) -{ - return FALSE; -} - - -Bool GlamoKMSExaPrepareComposite(int op, PicturePtr pSrcPicture, - PicturePtr pMaskPicture, - PicturePtr pDstPicture, - PixmapPtr pSrc, - PixmapPtr pMask, - PixmapPtr pDst) -{ - return FALSE; -} - - -void GlamoKMSExaComposite(PixmapPtr pDst, int srcX, int srcY, - int maskX, int maskY, int dstX, int dstY, - int width, int height) -{ -} - - -void GlamoKMSExaDoneComposite(PixmapPtr pDst) +static int GlamoKMSExaMarkSync(ScreenPtr pScreen) { + return 1; } -void GlamoKMSExaWaitMarker(ScreenPtr pScreen, int marker) +static void GlamoKMSExaWaitMarker(ScreenPtr pScreen, int marker) { // ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; // GlamoPtr pGlamo = GlamoPTR(pScrn); @@ -564,16 +539,16 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) exa->DoneCopy = GlamoKMSExaDoneCopy; /* Composite (though these just cause fallback) */ - exa->CheckComposite = GlamoKMSExaCheckComposite; - exa->PrepareComposite = GlamoKMSExaPrepareComposite; - exa->Composite = GlamoKMSExaComposite; - exa->DoneComposite = GlamoKMSExaDoneComposite; + exa->CheckComposite = NULL;//GlamoKMSExaCheckComposite; + exa->PrepareComposite = NULL;//GlamoKMSExaPrepareComposite; + exa->Composite = NULL;//GlamoKMSExaComposite; + exa->DoneComposite = NULL;//GlamoKMSExaDoneComposite; exa->DownloadFromScreen = NULL; exa->UploadToScreen = NULL; exa->UploadToScratch = NULL; -// exa->MarkSync = GlamoKMSExaMarkSync; + exa->MarkSync = GlamoKMSExaMarkSync; exa->WaitMarker = GlamoKMSExaWaitMarker; /* Prepare temporary buffers */ diff --git a/src/glamo-kms-exa.h b/src/glamo-kms-exa.h index 45b8eb7..6452050 100644 --- a/src/glamo-kms-exa.h +++ b/src/glamo-kms-exa.h @@ -22,6 +22,6 @@ #include "xf86.h" -extern void *GlamoKMSExaInit(ScrnInfoPtr pScrn); +extern void GlamoKMSExaInit(ScrnInfoPtr pScrn); extern void GlamoKMSExaClose(ScrnInfoPtr pScrn); extern unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); diff --git a/src/glamo-kms-output.c b/src/glamo-kms-output.c index 991a8be..f9f5ff6 100644 --- a/src/glamo-kms-output.c +++ b/src/glamo-kms-output.c @@ -57,6 +57,7 @@ #include #include "glamo.h" +#include "glamo-kms-output.h" static char *connector_enum_list[] = { diff --git a/src/glamo-kms-output.h b/src/glamo-kms-output.h new file mode 100644 index 0000000..0bb7565 --- /dev/null +++ b/src/glamo-kms-output.h @@ -0,0 +1,25 @@ +/* + * KMS Support for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +#include "xf86.h" + +extern void output_init(ScrnInfoPtr pScrn); -- cgit v1.2.3 From e727d8668afba6c2e50ee2097ae163b751274ce8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 18 Aug 2009 21:14:44 +0100 Subject: Reallocate GEM objects when necessary --- src/glamo-kms-exa.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 5303aeb..e7d78cf 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -455,6 +455,7 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *priv; + int new_size; if (depth <= 0) depth = pPix->drawable.depth; if (bitsPerPixel <= 0) bitsPerPixel = pPix->drawable.bitsPerPixel; @@ -472,20 +473,19 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, return FALSE; } - if ( priv->bo == NULL ) { + new_size = (width * height * depth) / 8; + if ( new_size == 0 ) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Zero-sized pixmap in ModifyPixmapHeader\n"); + return FALSE; + } - int size; + if ( priv->bo == NULL ) { /* This pixmap has no associated buffer object. * It's time to create one */ - size = (width * height * depth) / 8; - if ( size == 0 ) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Zero-sized pixmap in ModifyPixmapHeader\n"); - } - priv->bo = glamo_bo_open(pGlamo->bufmgr, 0, size, 2, + priv->bo = glamo_bo_open(pGlamo->bufmgr, 0, new_size, 2, GLAMO_GEM_DOMAIN_VRAM, 0); - if ( priv->bo == NULL ) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Failed to create buffer object" @@ -493,6 +493,25 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, return FALSE; } + } else { + + if ( priv->bo->size < new_size ) { + + /* Get rid of the old GEM object */ + glamo_bo_unref(priv->bo); + + /* Create a new one of the correct size */ + priv->bo = glamo_bo_open(pGlamo->bufmgr, 0, new_size, 2, + GLAMO_GEM_DOMAIN_VRAM, 0); + if ( priv->bo == NULL ) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Failed to reallocate buffer object" + " in ModifyPixmapHeader.\n"); + return FALSE; + } + + } /* else, reallocation is not required */ + } return FALSE; -- cgit v1.2.3 From b0f4dd62426bab9839ecff9ea266c964427b1446 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 18 Aug 2009 23:58:43 +0100 Subject: Make the buffer size for very small pixmaps sane --- src/glamo-kms-exa.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index e7d78cf..6a78c79 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -476,8 +476,10 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, new_size = (width * height * depth) / 8; if ( new_size == 0 ) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Zero-sized pixmap in ModifyPixmapHeader\n"); - return FALSE; + "Zero-sized pixmap in ModifyPixmapHeader" + " %ix%i %i bpp depth=%i\n", width, height, + bitsPerPixel, depth); + new_size = 1; } if ( priv->bo == NULL ) { -- cgit v1.2.3 From 3935ce27071cb70ae58c81c928c1726f6f6f7c53 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 18 Aug 2009 23:59:22 +0100 Subject: Don't call xf86_reload_cursors() It's not necessary for our software cursor (I think..?) --- src/glamo-kms-output.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/glamo-kms-output.c b/src/glamo-kms-output.c index f9f5ff6..724dbad 100644 --- a/src/glamo-kms-output.c +++ b/src/glamo-kms-output.c @@ -120,9 +120,6 @@ static void mode_set(xf86OutputPtr output, DisplayModePtr mode, static void commit(xf86OutputPtr output) { dpms(output, DPMSModeOn); - - if (output->scrn->pScreen != NULL) - xf86_reload_cursors(output->scrn->pScreen); } -- cgit v1.2.3 From 894dd4fad0fc9365dafb183527f95809fe585ccf Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 20 Aug 2009 17:28:49 +0100 Subject: EXA synchronisation stuff --- src/glamo-kms-exa.c | 68 +++++++++++++++++++++++++++++++++++++++++++++-------- src/glamo.h | 7 ++++++ 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 6a78c79..8779f5d 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -179,6 +179,8 @@ static inline void GlamoDRMAddCommandBO(GlamoPtr pGlamo, uint16_t reg, pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = 0x0000; pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg+2; pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = 0x0000; + + pGlamo->last_buffer_object = bo; } @@ -222,8 +224,6 @@ static Bool GlamoKMSExaPrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg) GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_HEIGHT, pPix->drawable.height); GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_PAT_FG, fg); GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_COMMAND2, op); - GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_ID1, 0); - GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_ID2, 0); return TRUE; } @@ -293,8 +293,6 @@ static Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int d GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_DST_HEIGHT, pDst->drawable.height); GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_COMMAND2, op); - GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_ID1, 0); - GlamoDRMAddCommand(pGlamo, GLAMO_REG_2D_ID2, 0); return TRUE; } @@ -326,19 +324,45 @@ static void GlamoKMSExaDoneCopy(PixmapPtr pDst) } +/* Generate an integer token which can be used for synchronisation later. + * We do this by putting the most recently used buffer object into a list, + * and returning the index into that list. + * To make things a little more exciting, the list is a ring buffer. */ static int GlamoKMSExaMarkSync(ScreenPtr pScreen) { + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + unsigned int idx; + + idx = pGlamo->exa_marker_index; + pGlamo->exa_buffer_markers[idx] = pGlamo->last_buffer_object; + + pGlamo->exa_marker_index = (idx+1) % NUM_EXA_BUFFER_MARKERS; + return 1; } -static void GlamoKMSExaWaitMarker(ScreenPtr pScreen, int marker) +static void GlamoKMSExaWaitMarker(ScreenPtr pScreen, int idx) { -// ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; -// GlamoPtr pGlamo = GlamoPTR(pScrn); + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); + struct glamo_bo *bo; + + bo = pGlamo->exa_buffer_markers[idx]; + + if ( bo ) { + glamo_bo_wait(bo); + } else { -// GLAMOEngineWait(pGlamo, GLAMO_ENGINE_ALL); - // FIXME + struct drm_glamo_gem_wait_rendering args; + + args.handle = 0; + args.have_handle = 0; + drmCommandWriteRead(pGlamo->bufmgr->fd, + DRM_GLAMO_GEM_WAIT_RENDERING, + &args, sizeof(args)); + } } @@ -370,9 +394,23 @@ static void *GlamoKMSExaCreatePixmap(ScreenPtr screen, int size, int align) } -static void GlamoKMSExaDestroyPixmap(ScreenPtr screen, void *driverPriv) +static void GlamoKMSExaDestroyPixmap(ScreenPtr pScreen, void *driverPriv) { + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + GlamoPtr pGlamo = GlamoPTR(pScrn); struct glamo_exa_pixmap_priv *driver_priv = driverPriv; + int i; + + /* We're about to (probably) delete a buffer object, so zip through + * the list of EXA wait markers and delete any references. */ + for ( i=0; iexa_buffer_markers[i] == driver_priv->bo ) { + pGlamo->exa_buffer_markers[i] = NULL; + } + } + if ( pGlamo->last_buffer_object == driver_priv->bo ) { + pGlamo->last_buffer_object = NULL; + } if (driver_priv->bo) glamo_bo_unref(driver_priv->bo); @@ -531,6 +569,7 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) GlamoPtr pGlamo = GlamoPTR(pScrn); Bool success = FALSE; ExaDriverPtr exa; + int i; xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "EXA hardware acceleration initialising\n"); @@ -579,11 +618,20 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) pGlamo->cmdq_drm_used = 0; pGlamo->cmdq_drm_size = 4 * 1024; pGlamo->cmdq_drm = malloc(pGlamo->cmdq_drm_size); + pGlamo->last_buffer_object = NULL; + for ( i=0; iexa_buffer_markers[i] = NULL; + } + pGlamo->exa_marker_index = 0; if ( !pGlamo->cmdq_drm ) return; /* Tell EXA that we're going to take care of memory * management ourselves. */ exa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS; +#ifdef EXA_MIXED_PIXMAPS + exa->flags |= EXA_MIXED_PIXMAPS; + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using mixed mode pixmaps\n"); +#endif exa->PrepareAccess = GlamoKMSExaPrepareAccess; exa->FinishAccess = GlamoKMSExaFinishAccess; exa->CreatePixmap = GlamoKMSExaCreatePixmap; diff --git a/src/glamo.h b/src/glamo.h index 531c719..d335ce3 100644 --- a/src/glamo.h +++ b/src/glamo.h @@ -75,6 +75,9 @@ MMIO_IN16(__volatile__ void *base, const unsigned long offset) #endif +/* The number of EXA wait markers which can be active at once */ +#define NUM_EXA_BUFFER_MARKERS 32 + typedef volatile CARD16 VOL16; typedef struct _MemBuf { @@ -114,6 +117,10 @@ typedef struct { int cmdq_obj_used; uint32_t *cmdq_objs; unsigned int *cmdq_obj_pos; + struct glamo_bo *last_buffer_object; /* The last buffer object + * referenced in the cmdq */ + struct glamo_bo *exa_buffer_markers[NUM_EXA_BUFFER_MARKERS]; + unsigned int exa_marker_index; /* Index into exa_buffer_markers */ /* What was GLAMOCardInfo */ volatile char *reg_base; -- cgit v1.2.3 From edc1fcddb57fad07e1ed212424378247e0d2a0a2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 21 Aug 2009 00:44:57 +0100 Subject: Use $PKG_CONFIG instead of pkg-config This un-breaks cross-compilation in certain cases. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 8aeed86..d9b08a9 100644 --- a/configure.ac +++ b/configure.ac @@ -70,7 +70,7 @@ XORG_DRIVER_CHECK_EXT(XV, videoproto) # Checks for pkg-config packages PKG_CHECK_MODULES(XORG, [xorg-server >= 1.0.99.901 xproto fontsproto $REQUIRED_MODULES]) -sdkdir=$(pkg-config --variable=sdkdir xorg-server) +sdkdir=$($PKG_CONFIG --variable=sdkdir xorg-server) if test "x$JBT6K74_SET_STATE" = xyes; then AC_DEFINE(JBT6K74_SET_STATE, 1, [Set jbt6k74 state when changing resolution]) -- cgit v1.2.3 From a7c514dad30ab7fe7d684ed1e8ccb6df100edc1c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 21 Aug 2009 00:50:05 +0100 Subject: Handle the new DRI protocol as well --- src/glamo-dri2.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index 4186bfa..ae62ef4 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -57,8 +57,20 @@ typedef struct { } GlamoDRI2BufferPrivateRec, *GlamoDRI2BufferPrivatePtr; -static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, - unsigned int *attachments, int count) +#ifdef USE_DRI2_1_1_0 + +static DRI2BufferPtr glamoCreateBuffer(DrawablePtr pDraw, + unsigned int attachment, + unsigned int format) +{ + DRI2BufferPtr buffer; + return buffer; +} + +#else + +static DRI2BufferPtr glamoCreateBuffer(DrawablePtr pDraw, + unsigned int *attachments, int count) { ScreenPtr pScreen = pDraw->pScreen; DRI2BufferPtr buffers; @@ -115,6 +127,26 @@ static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, return buffers; } +#endif + +#ifdef USE_DRI2_1_1_0 + +static void glamoDestroyBuffer(DrawablePtr pDraw, + DRI2BufferPtr buffer) +{ + ScreenPtr pScreen = pDraw->pScreen; + int i; + GlamoDRI2BufferPrivatePtr private; + + private = buffer.driverPrivate; + (*pScreen->DestroyPixmap)(private->pPixmap); + + if ( buffer ) { + xfree(buffer.driverPrivate); + } +} + +#else static void glamoDestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count) @@ -134,6 +166,8 @@ static void glamoDestroyBuffers(DrawablePtr pDraw, } } +#endif + static void glamoCopyRegion(DrawablePtr pDraw, RegionPtr pRegion, DRI2BufferPtr pDestBuffer, DRI2BufferPtr pSrcBuffer) @@ -171,8 +205,13 @@ void driScreenInit(ScreenPtr pScreen) dri2info.deviceName = p; dri2info.driverName = "glamo"; +#ifdef USE_DRI2_1_1_0 + dri2info.CreateBuffer = glamoCreateBuffer; + dri2info.DestroyBuffer = glamoDestroyBuffer; +#else dri2info.CreateBuffers = glamoCreateBuffers; dri2info.DestroyBuffers = glamoDestroyBuffers; +#endif dri2info.CopyRegion = glamoCopyRegion; if ( !DRI2ScreenInit(pScreen, &dri2info) ) return; -- cgit v1.2.3 From 270241cebfac55088868c686c3ffa3b0b4f94fe1 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 21 Aug 2009 00:56:16 +0100 Subject: Strip out some RAC and loader stuff This is necessary to keep up with the latest Xorg-server developments. It works with the latest Git master of the server, which we want to use for the great speedups arising from mixed mode EXA pixmap handling. Please let me know if it breaks on older versions... --- src/glamo-driver.c | 5 ----- src/glamo-kms-driver.c | 9 --------- 2 files changed, 14 deletions(-) diff --git a/src/glamo-driver.c b/src/glamo-driver.c index 002dca3..53b72e0 100644 --- a/src/glamo-driver.c +++ b/src/glamo-driver.c @@ -23,7 +23,6 @@ /* for visuals */ #include "fb.h" -#include "xf86Resources.h" #include "xf86RAC.h" #include "fbdevhw.h" @@ -425,10 +424,6 @@ GlamoPreInit(ScrnInfoPtr pScrn, int flags) pGlamo->pEnt = xf86GetEntityInfo(pScrn->entityList[0]); - pScrn->racMemFlags = RAC_FB | RAC_CURSOR | RAC_VIEWPORT; - /* XXX Is this right? Can probably remove RAC_FB */ - pScrn->racIoFlags = RAC_FB | RAC_CURSOR | RAC_VIEWPORT; - fb_device = xf86FindOptionValue(pGlamo->pEnt->device->options, "Device"); /* open device */ diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index 55d2377..afc7d6b 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -75,13 +75,6 @@ #include "glamo-kms-output.h" -static const char *fbSymbols[] = { - "fbPictureInit", - "fbScreenInit", - NULL -}; - - /* Return TRUE if KMS can be used */ Bool GlamoKernelModesettingAvailable() { @@ -208,7 +201,6 @@ Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags) pGlamo->drm_fd = drmOpen(NULL, "platform:glamo-fb"); if ( pGlamo->drm_fd < 0 ) return FALSE; - pScrn->racMemFlags = RAC_FB | RAC_COLORMAP; pScrn->monitor = pScrn->confScreen->monitor; pScrn->progClock = TRUE; pScrn->rgbBits = 8; @@ -262,7 +254,6 @@ Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags) /* Load the required sub modules */ if (!xf86LoadSubModule(pScrn, "fb")) return FALSE; - xf86LoaderReqSymLists(fbSymbols, NULL); xf86LoadSubModule(pScrn, "exa"); xf86LoadSubModule(pScrn, "dri2"); -- cgit v1.2.3 From 41eacee1f2e411f38ed59698bf4776e8171cbd74 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 21 Aug 2009 11:46:08 +0100 Subject: Typo Thanks for Martin Jansa (JaMa) for spotting this. --- src/glamo-dri2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index ae62ef4..bac8331 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -69,8 +69,8 @@ static DRI2BufferPtr glamoCreateBuffer(DrawablePtr pDraw, #else -static DRI2BufferPtr glamoCreateBuffer(DrawablePtr pDraw, - unsigned int *attachments, int count) +static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, + unsigned int *attachments, int count) { ScreenPtr pScreen = pDraw->pScreen; DRI2BufferPtr buffers; -- cgit v1.2.3 From 7ba80e79f33439d5a97fd20a69c1ff159e7a6440 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 21 Aug 2009 12:12:24 +0100 Subject: Fix DRI2InfoRec problems --- src/glamo-dri2.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index bac8331..6198522 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -57,7 +57,7 @@ typedef struct { } GlamoDRI2BufferPrivateRec, *GlamoDRI2BufferPrivatePtr; -#ifdef USE_DRI2_1_1_0 +#if DRI2INFOREC_VERSION >= 3 static DRI2BufferPtr glamoCreateBuffer(DrawablePtr pDraw, unsigned int attachment, @@ -129,20 +129,19 @@ static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, #endif -#ifdef USE_DRI2_1_1_0 +#if DRI2INFOREC_VERSION >= 3 static void glamoDestroyBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer) { ScreenPtr pScreen = pDraw->pScreen; - int i; GlamoDRI2BufferPrivatePtr private; - private = buffer.driverPrivate; + private = buffer->driverPrivate; (*pScreen->DestroyPixmap)(private->pPixmap); if ( buffer ) { - xfree(buffer.driverPrivate); + xfree(buffer->driverPrivate); } } @@ -205,7 +204,7 @@ void driScreenInit(ScreenPtr pScreen) dri2info.deviceName = p; dri2info.driverName = "glamo"; -#ifdef USE_DRI2_1_1_0 +#if DRI2INFOREC_VERSION >= 3 dri2info.CreateBuffer = glamoCreateBuffer; dri2info.DestroyBuffer = glamoDestroyBuffer; #else -- cgit v1.2.3 From 53a6c15a23012385c1bb153f5b36c252e77da168 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 21 Aug 2009 12:12:41 +0100 Subject: Don't unmap on FinishAccess, and return as quickly as possible on re-map Combined with mixed mode pixmaps, this brings the speed up to about where it should be. --- src/glamo-kms-exa.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 8779f5d..b6226a3 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -450,6 +450,12 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) return TRUE; } + /* Return as quickly as possible if we have a mapping already */ + if ( driver_priv->bo->virtual ) { + pPix->devPrivate.ptr = driver_priv->bo->virtual; + return TRUE; + } + if ( glamo_bo_map(driver_priv->bo, 1) ) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%s: bo map failed\n", __FUNCTION__); @@ -463,24 +469,7 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) static void GlamoKMSExaFinishAccess(PixmapPtr pPix, int index) { - ScreenPtr screen = pPix->drawable.pScreen; - ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; - struct glamo_exa_pixmap_priv *driver_priv; - - driver_priv = exaGetPixmapDriverPrivate(pPix); - if (!driver_priv) { - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "%s: no driver private?\n", __FUNCTION__); - return; - } - - if (!driver_priv->bo) { - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "%s: no buffer object?\n", __FUNCTION__); - return; - } - - glamo_bo_unmap(driver_priv->bo); + /* Leave the mapping intact for fast restoration of access later */ pPix->devPrivate.ptr = NULL; } -- cgit v1.2.3 From 8b127f4bd41b30f9ed89d8513701ec91343cbb7d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 22 Aug 2009 22:01:38 +0100 Subject: Fix GlamkKernelModesettingAvailable() so that it works --- src/glamo-kms-driver.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index afc7d6b..3c281a3 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -87,6 +87,7 @@ Bool GlamoKernelModesettingAvailable() do { ent = readdir(dir); + if ( !ent ) return FALSE; if ( strncmp(ent->d_name, "drm:controlD", 12) == 0 ) { closedir(dir); -- cgit v1.2.3 From 6a61c4e4402964aa0d86c65969a51a33ec89f383 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 25 Aug 2009 00:01:12 +0100 Subject: Fix headers for recent X.org I think this breaks compatability with older versions. Some kind of conditional thing should be done. --- src/glamo-display.c | 2 +- src/glamo-driver.c | 2 -- src/glamo-kms-crtc.c | 2 +- src/glamo-kms-driver.c | 1 - src/glamo-kms-output.c | 2 +- 5 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/glamo-display.c b/src/glamo-display.c index 4562546..fede315 100644 --- a/src/glamo-display.c +++ b/src/glamo-display.c @@ -38,7 +38,7 @@ #include #define DPMS_SERVER -#include +#include #include "glamo.h" #include "glamo-regs.h" diff --git a/src/glamo-driver.c b/src/glamo-driver.c index 53b72e0..e8d39f6 100644 --- a/src/glamo-driver.c +++ b/src/glamo-driver.c @@ -23,8 +23,6 @@ /* for visuals */ #include "fb.h" -#include "xf86RAC.h" - #include "fbdevhw.h" #include "xf86xv.h" diff --git a/src/glamo-kms-crtc.c b/src/glamo-kms-crtc.c index 17444b0..fdf0e9f 100644 --- a/src/glamo-kms-crtc.c +++ b/src/glamo-kms-crtc.c @@ -55,7 +55,7 @@ #include #include #define DPMS_SERVER -#include +#include #include "glamo.h" #include "glamo-kms-crtc.h" diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index 3c281a3..32fdb4e 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -63,7 +63,6 @@ #include "xf86.h" #include "xf86Crtc.h" #include "xf86str.h" -#include "xf86RAC.h" #include "xf86drm.h" #include "micmap.h" diff --git a/src/glamo-kms-output.c b/src/glamo-kms-output.c index 724dbad..7b9f997 100644 --- a/src/glamo-kms-output.c +++ b/src/glamo-kms-output.c @@ -52,7 +52,7 @@ #include #include #define DPMS_SERVER -#include +#include #include #include -- cgit v1.2.3 From adc83129b1377fb8224d05a7e0379f885b519c38 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 25 Aug 2009 00:02:14 +0100 Subject: Remove unnecessary variables --- src/glamo-kms-exa.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index b6226a3..594962c 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -258,7 +258,6 @@ static Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int d ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum]; GlamoPtr pGlamo = GlamoPTR(pScrn); FbBits mask; - CARD32 src_offset, dst_offset; CARD16 src_pitch, dst_pitch; CARD16 op; struct glamo_exa_pixmap_priv *priv_src; @@ -277,12 +276,8 @@ static Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int d (unsigned int) pm)); } - src_offset = exaGetPixmapOffset(pSrc); src_pitch = pSrc->devKind; - - dst_offset = exaGetPixmapOffset(pDst); dst_pitch = pDst->devKind; - op = GLAMOBltRop[alu] << 8; GlamoDRMAddCommandBO(pGlamo, GLAMO_REG_2D_SRC_ADDRL, priv_src->bo); -- cgit v1.2.3 From a1f4b5a29a2dcecab97117258c7510baf6c6bf8a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 25 Aug 2009 15:59:06 +0100 Subject: Fix DRI2 registration with recent X servers --- src/glamo-dri2.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index 6198522..286094a 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -199,7 +199,7 @@ void driScreenInit(ScreenPtr pScreen) xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[glamo-dri] Name of DRM device is '%s'\n", p); - dri2info.version = 1; + dri2info.version = DRI2INFOREC_VERSION; dri2info.fd = pGlamo->drm_fd; dri2info.deviceName = p; dri2info.driverName = "glamo"; @@ -213,7 +213,13 @@ void driScreenInit(ScreenPtr pScreen) #endif dri2info.CopyRegion = glamoCopyRegion; - if ( !DRI2ScreenInit(pScreen, &dri2info) ) return; + if ( !DRI2ScreenInit(pScreen, &dri2info) ) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "[glamo-dri] DRI2 initialisation failed\n"); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "[glamo-dri] DRI2 initialisation succeeded\n"); + } } -- cgit v1.2.3 From 8b375051cb3b355be64f1818ec964c6230645bd7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 25 Aug 2009 17:48:40 +0100 Subject: Restore composite hooks --- src/glamo-kms-exa.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 594962c..9ce5787 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -538,10 +538,49 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, } + return TRUE; +} + + +Bool GlamoKMSExaCheckComposite(int op, + PicturePtr pSrcPicture, + PicturePtr pMaskPicture, + PicturePtr pDstPicture) +{ + return FALSE; +} + + +Bool GlamoKMSExaPrepareComposite(int op, + PicturePtr pSrcPicture, + PicturePtr pMaskPicture, + PicturePtr pDstPicture, + PixmapPtr pSrc, + PixmapPtr pMask, + PixmapPtr pDst) +{ return FALSE; } +void GlamoKMSExaComposite(PixmapPtr pDst, + int srcX, + int srcY, + int maskX, + int maskY, + int dstX, + int dstY, + int width, + int height) +{ +} + + +void GlamoKMSExaDoneComposite(PixmapPtr pDst) +{ +} + + void GlamoKMSExaClose(ScrnInfoPtr pScrn) { exaDriverFini(pScrn->pScreen); @@ -583,10 +622,10 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) exa->DoneCopy = GlamoKMSExaDoneCopy; /* Composite (though these just cause fallback) */ - exa->CheckComposite = NULL;//GlamoKMSExaCheckComposite; - exa->PrepareComposite = NULL;//GlamoKMSExaPrepareComposite; - exa->Composite = NULL;//GlamoKMSExaComposite; - exa->DoneComposite = NULL;//GlamoKMSExaDoneComposite; + exa->CheckComposite = GlamoKMSExaCheckComposite; + exa->PrepareComposite = GlamoKMSExaPrepareComposite; + exa->Composite = GlamoKMSExaComposite; + exa->DoneComposite = GlamoKMSExaDoneComposite; exa->DownloadFromScreen = NULL; exa->UploadToScreen = NULL; -- cgit v1.2.3 From 74af97cb9ee0cddb7cb38cbade2e30c301ebe568 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 25 Aug 2009 17:48:57 +0100 Subject: Wait after mapping buffer --- src/glamo-kms-exa.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 9ce5787..fa80d98 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -448,6 +448,7 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) /* Return as quickly as possible if we have a mapping already */ if ( driver_priv->bo->virtual ) { pPix->devPrivate.ptr = driver_priv->bo->virtual; + glamo_bo_wait(driver_priv->bo); return TRUE; } @@ -457,6 +458,7 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) return FALSE; } pPix->devPrivate.ptr = driver_priv->bo->virtual; + glamo_bo_wait(driver_priv->bo); return TRUE; } -- cgit v1.2.3 From 48f66451ac799520659b0739222cc1d0f6f65f09 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 25 Aug 2009 17:49:13 +0100 Subject: Change a message from X_WARNING to X_INFO --- src/glamo-kms-exa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index fa80d98..a7950c8 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -596,8 +596,8 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) ExaDriverPtr exa; int i; - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "EXA hardware acceleration initialising\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "EXA hardware acceleration initialising\n"); exa = exaDriverAlloc(); if ( !exa ) return; -- cgit v1.2.3 From d91c2881159e177d1edc6ffe916c93050b7c0ae2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 25 Aug 2009 18:04:58 +0100 Subject: Get rid of ModifyPixmapHeader hook This has the effect of fixing text rendering, and also makes the code a lot clearer. --- src/glamo-kms-driver.c | 7 +++---- src/glamo-kms-exa.c | 35 +++++++++++------------------------ src/glamo-kms-exa.h | 3 +++ 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index 32fdb4e..b2cfa7a 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -125,11 +125,10 @@ static Bool CreateFrontBuffer(ScrnInfoPtr pScrn) PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); unsigned int flags; - pScreen->ModifyPixmapHeader(rootPixmap, + GlamoKMSExaMakeFullyFledged(rootPixmap, pScrn->virtualX, pScrn->virtualY, pScrn->depth, pScrn->bitsPerPixel, - pScrn->displayWidth * pScrn->bitsPerPixel/8, - NULL); + pScrn->displayWidth*pScrn->bitsPerPixel/8); drmModeAddFB(pGlamo->drm_fd, pScrn->virtualX, @@ -300,7 +299,7 @@ static Bool GlamoKMSCreateScreenResources(ScreenPtr pScreen) rootPixmap = pScreen->GetScreenPixmap(pScreen); - if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL)) + if (!GlamoKMSExaMakeFullyFledged(rootPixmap, -1, -1, -1, -1, -1)) FatalError("Couldn't adjust screen pixmap\n"); xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Adding framebuffer....!\n"); diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index a7950c8..87839c7 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -471,9 +471,10 @@ static void GlamoKMSExaFinishAccess(PixmapPtr pPix, int index) } -static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, - int depth, int bitsPerPixel, - int devKind, pointer pPixData) +/* This essentially does the job of ModifyPixmapHeader, for the occasions + * when we need to update the properties of the screen pixmap. */ +Bool GlamoKMSExaMakeFullyFledged(PixmapPtr pPix, int width, int height, + int depth, int bitsPerPixel, int devKind) { ScreenPtr screen = pPix->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; @@ -493,14 +494,14 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, priv = exaGetPixmapDriverPrivate(pPix); if (!priv) { /* This should never, ever, happen */ - FatalError("NO PIXMAP PRIVATE\n"); + FatalError("Fledgeling pixmap had no driver private!\n"); return FALSE; } new_size = (width * height * depth) / 8; if ( new_size == 0 ) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Zero-sized pixmap in ModifyPixmapHeader" + "Fledgeling pixmap would still have zero size!" " %ix%i %i bpp depth=%i\n", width, height, bitsPerPixel, depth); new_size = 1; @@ -514,29 +515,15 @@ static Bool GlamoKMSExaModifyPixmapHeader(PixmapPtr pPix, int width, int height, GLAMO_GEM_DOMAIN_VRAM, 0); if ( priv->bo == NULL ) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "Failed to create buffer object" - " in ModifyPixmapHeader.\n"); + "Couldn't create buffer object for" + " fledgeling pixmap!\n"); return FALSE; } } else { - if ( priv->bo->size < new_size ) { - - /* Get rid of the old GEM object */ - glamo_bo_unref(priv->bo); - - /* Create a new one of the correct size */ - priv->bo = glamo_bo_open(pGlamo->bufmgr, 0, new_size, 2, - GLAMO_GEM_DOMAIN_VRAM, 0); - if ( priv->bo == NULL ) { - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "Failed to reallocate buffer object" - " in ModifyPixmapHeader.\n"); - return FALSE; - } - - } /* else, reallocation is not required */ + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Fledgeling pixmap already had a buffer object!\n"); } @@ -662,7 +649,7 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) exa->CreatePixmap = GlamoKMSExaCreatePixmap; exa->DestroyPixmap = GlamoKMSExaDestroyPixmap; exa->PixmapIsOffscreen = GlamoKMSExaPixmapIsOffscreen; - exa->ModifyPixmapHeader = GlamoKMSExaModifyPixmapHeader; + exa->ModifyPixmapHeader = NULL; /* Hook up with libdrm */ pGlamo->bufmgr = glamo_bo_manager_gem_ctor(pGlamo->drm_fd); diff --git a/src/glamo-kms-exa.h b/src/glamo-kms-exa.h index 6452050..b39878a 100644 --- a/src/glamo-kms-exa.h +++ b/src/glamo-kms-exa.h @@ -25,3 +25,6 @@ extern void GlamoKMSExaInit(ScrnInfoPtr pScrn); extern void GlamoKMSExaClose(ScrnInfoPtr pScrn); extern unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); +extern Bool GlamoKMSExaMakeFullyFledged(PixmapPtr pPix, int width, int height, + int depth, int bitsPerPixel, + int devKind); -- cgit v1.2.3 From 3bc55d4f6b0a95637d85188782811fef600010eb Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 11 Sep 2009 15:51:39 +0100 Subject: Reduce debug This removes some unnecessary and unhelpful log messages. --- src/glamo-kms-driver.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/glamo-kms-driver.c b/src/glamo-kms-driver.c index b2cfa7a..34c7baf 100644 --- a/src/glamo-kms-driver.c +++ b/src/glamo-kms-driver.c @@ -302,15 +302,11 @@ static Bool GlamoKMSCreateScreenResources(ScreenPtr pScreen) if (!GlamoKMSExaMakeFullyFledged(rootPixmap, -1, -1, -1, -1, -1)) FatalError("Couldn't adjust screen pixmap\n"); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Adding framebuffer....!\n"); - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%i %i %i %i %i %i\n", + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Adding FB: %i %i %i %i %i %i\n", pGlamo->drm_fd, pScrn->virtualX, pScrn->virtualY, pScrn->depth, pScrn->bitsPerPixel, pScrn->displayWidth * pScrn->bitsPerPixel / 8); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "rootPixmap = %p\n", (void *)rootPixmap); - drmModeAddFB(pGlamo->drm_fd, pScrn->virtualX, pScrn->virtualY, @@ -319,14 +315,10 @@ static Bool GlamoKMSCreateScreenResources(ScreenPtr pScreen) pScrn->displayWidth * pScrn->bitsPerPixel / 8, driGetPixmapHandle(rootPixmap, &flags), &pGlamo->fb_id); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Done\n"); - GlamoKMSAdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Finished\n"); - return ret; } -- cgit v1.2.3 From 759e89065f87fd138bdaee001a467632dc8c04e0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 13 Sep 2009 19:53:47 +0100 Subject: Fix glamoCreateBuffer(s) (for DRI2) --- src/glamo-dri2.c | 167 +++++++++++++++++++++++++++++++++++++++++----------- src/glamo-kms-exa.c | 5 -- src/glamo-kms-exa.h | 4 ++ 3 files changed, 135 insertions(+), 41 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index 286094a..70b9d93 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -32,6 +32,36 @@ * * Author: Alan Hourihane * + * + * Also based partially on xf86-video-ati, to which the following + * notice applies: + * + * Copyright 2008 Kristian Høgsberg + * Copyright 2008 Jérôme Glisse + * + * 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 on 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 + * NON-INFRINGEMENT. IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR + * THEIR 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. + * */ @@ -46,37 +76,92 @@ #include #include #include +#include #include "glamo.h" #include "glamo-dri2.h" #include "glamo-kms-exa.h" -typedef struct { - PixmapPtr pPixmap; -} GlamoDRI2BufferPrivateRec, *GlamoDRI2BufferPrivatePtr; +struct glamo_dri2_buffer_priv { + PixmapPtr pixmap; + unsigned int attachment; +}; #if DRI2INFOREC_VERSION >= 3 -static DRI2BufferPtr glamoCreateBuffer(DrawablePtr pDraw, +static DRI2BufferPtr glamoCreateBuffer(DrawablePtr drawable, unsigned int attachment, unsigned int format) { + ScreenPtr pScreen = drawable->pScreen; DRI2BufferPtr buffer; + struct glamo_dri2_buffer_priv *private; + PixmapPtr pixmap; + struct glamo_exa_pixmap_priv *driver_priv; + int r; + + buffer = xcalloc(1, sizeof(*buffer)); + if (buffer == NULL) { + return NULL; + } + private = xcalloc(1, sizeof(*private)); + if (private == NULL) { + xfree(buffer); + return NULL; + } + + if ( attachment == DRI2BufferFrontLeft ) { + if ( drawable->type == DRAWABLE_PIXMAP ) { + pixmap = (PixmapPtr)drawable; + } else { + pixmap = pScreen->GetWindowPixmap((WindowPtr)drawable); + } + pixmap->refcnt++; + } else { + pixmap = pScreen->CreatePixmap(pScreen, + drawable->width, + drawable->height, + (format != 0)?format:drawable->depth, + 0); + } + exaMoveInPixmap(pixmap); + driver_priv = exaGetPixmapDriverPrivate(pixmap); + if ( !driver_priv ) { + xfree(buffer); + xfree(private); + return NULL; + } + r = glamo_gem_name_buffer(driver_priv->bo, &buffer->name); + if (r) { + fprintf(stderr, "Couldn't name buffer: %d %s\n", + r, strerror(r)); + xfree(buffer); + xfree(private); + return NULL; + } + buffer->attachment = attachment; + buffer->pitch = pixmap->devKind; + buffer->cpp = pixmap->drawable.bitsPerPixel / 8; + buffer->driverPrivate = private; + buffer->format = format; + buffer->flags = 0; + private->pixmap = pixmap; + private->attachment = attachment; + return buffer; } #else -static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, +static DRI2BufferPtr glamoCreateBuffers(DrawablePtr drawable, unsigned int *attachments, int count) { - ScreenPtr pScreen = pDraw->pScreen; - DRI2BufferPtr buffers; + ScreenPtr pScreen = drawable->pScreen; int i; - GlamoDRI2BufferPrivatePtr privates; - PixmapPtr pPixmap, pDepthPixmap; + DRI2BufferPtr buffers; + struct glamo_dri2_buffer_priv *privates; buffers = xcalloc(count, sizeof *buffers); if ( buffers == NULL ) return NULL; @@ -86,41 +171,51 @@ static DRI2BufferPtr glamoCreateBuffers(DrawablePtr pDraw, return NULL; } - pDepthPixmap = NULL; /* For each attachment */ for ( i=0; itype == DRAWABLE_PIXMAP ) { - pPixmap = (PixmapPtr)pDraw; + if ( attachments[i] == DRI2BufferFrontLeft ) { + if ( drawable->type == DRAWABLE_PIXMAP ) { + pixmap = (PixmapPtr)drawable; } else { - pPixmap = (*pScreen->GetWindowPixmap)( - (WindowPtr)pDraw); + pixmap = pScreen->GetWindowPixmap( + (WindowPtr)drawable); } - pPixmap->refcnt++; - + pixmap->refcnt++; } else { - - /* Anything else - create a new pixmap */ - pPixmap = (*pScreen->CreatePixmap)(pScreen, - pDraw->width, - pDraw->height, - pDraw->depth, - 0); - + pixmap = pScreen->CreatePixmap(pScreen, + drawable->width, + drawable->height, + drawable->depth, + 0); + } + exaMoveInPixmap(pixmap); + driver_priv = exaGetPixmapDriverPrivate(pixmap); + if ( !driver_priv ) { + xfree(buffers); + xfree(privates); + return NULL; + } + r = glamo_gem_name_buffer(driver_priv->bo, &buffers[i].name); + if (r) { + fprintf(stderr, "Couldn't name buffer: %d %s\n", + r, strerror(r)); + xfree(buffers); + xfree(privates); + return NULL; } - - if ( attachments[i] == DRI2BufferDepth ) pDepthPixmap = pPixmap; - - /* Set up the return data structure */ buffers[i].attachment = attachments[i]; - buffers[i].pitch = pPixmap->devKind; - buffers[i].cpp = pPixmap->drawable.bitsPerPixel / 8; + buffers[i].pitch = pixmap->devKind; + buffers[i].cpp = pixmap->drawable.bitsPerPixel / 8; buffers[i].driverPrivate = &privates[i]; + buffers[i].format = drawable->depth; buffers[i].flags = 0; - privates[i].pPixmap = pPixmap; + privates[i].pixmap = pixmap; + privates[i].attachment = attachments[i]; } @@ -135,10 +230,10 @@ static void glamoDestroyBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer) { ScreenPtr pScreen = pDraw->pScreen; - GlamoDRI2BufferPrivatePtr private; + struct glamo_dri2_buffer_priv *private; private = buffer->driverPrivate; - (*pScreen->DestroyPixmap)(private->pPixmap); + pScreen->DestroyPixmap(private->pixmap); if ( buffer ) { xfree(buffer->driverPrivate); @@ -156,7 +251,7 @@ static void glamoDestroyBuffers(DrawablePtr pDraw, for ( i=0; iDestroyPixmap)(private->pPixmap); + pScreen->DestroyPixmap(private->pixmap); } if ( buffers ) { diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 87839c7..557ba60 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -74,11 +74,6 @@ #endif -struct glamo_exa_pixmap_priv { - struct glamo_bo *bo; -}; - - static const CARD8 GLAMOSolidRop[16] = { /* GXclear */ 0x00, /* 0 */ /* GXand */ 0xa0, /* src AND dst */ diff --git a/src/glamo-kms-exa.h b/src/glamo-kms-exa.h index b39878a..0473b3b 100644 --- a/src/glamo-kms-exa.h +++ b/src/glamo-kms-exa.h @@ -22,6 +22,10 @@ #include "xf86.h" +struct glamo_exa_pixmap_priv { + struct glamo_bo *bo; +}; + extern void GlamoKMSExaInit(ScrnInfoPtr pScrn); extern void GlamoKMSExaClose(ScrnInfoPtr pScrn); extern unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags); -- cgit v1.2.3 From 6e7ff8981f0a5e8cf558dc95fdda85dc669cd7af Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 19 Sep 2009 13:57:37 +0100 Subject: Split DRM command queue handling out to a separate file --- src/Makefile.am | 3 +- src/glamo-drm.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/glamo-drm.h | 38 +++++++++++++++++++ src/glamo-kms-exa.c | 79 ++++---------------------------------- 4 files changed, 154 insertions(+), 73 deletions(-) create mode 100644 src/glamo-drm.c create mode 100644 src/glamo-drm.h diff --git a/src/Makefile.am b/src/Makefile.am index 374be96..a1e8d0a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,4 +40,5 @@ glamo_drv_la_SOURCES = \ glamo-kms-crtc.c \ glamo-kms-output.c \ glamo-dri2.c \ - glamo-kms-exa.c + glamo-kms-exa.c \ + glamo-drm.c diff --git a/src/glamo-drm.c b/src/glamo-drm.c new file mode 100644 index 0000000..aac93bb --- /dev/null +++ b/src/glamo-drm.c @@ -0,0 +1,107 @@ +/* + * DRI for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#include "glamo.h" + + +/* Submit the prepared command sequence to the kernel */ +void GlamoDRMDispatch(GlamoPtr pGlamo) +{ + drm_glamo_cmd_buffer_t cmdbuf; + int r; + + cmdbuf.buf = (char *)pGlamo->cmdq_drm; + cmdbuf.bufsz = pGlamo->cmdq_drm_used * 2; /* -> bytes */ + cmdbuf.nobjs = pGlamo->cmdq_obj_used; + cmdbuf.objs = pGlamo->cmdq_objs; + cmdbuf.obj_pos = pGlamo->cmdq_obj_pos; + + r = drmCommandWrite(pGlamo->drm_fd, DRM_GLAMO_CMDBUF, + &cmdbuf, sizeof(cmdbuf)); + if ( r != 0 ) { + xf86DrvMsg(pGlamo->pScreen->myNum, X_ERROR, + "DRM_GLAMO_CMDBUF failed\n"); + } + + /* Reset counts to zero for the next sequence */ + pGlamo->cmdq_obj_used = 0; + pGlamo->cmdq_drm_used = 0; +} + + +void GlamoDRMAddCommand(GlamoPtr pGlamo, uint16_t reg, uint16_t val) +{ + if ( pGlamo->cmdq_drm_used == pGlamo->cmdq_drm_size ) { + xf86DrvMsg(pGlamo->pScreen->myNum, X_INFO, + "Forced command cache flush.\n"); + GlamoDRMDispatch(pGlamo); + } + + /* Record command */ + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg; + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = val; +} + + +void GlamoDRMAddCommandBO(GlamoPtr pGlamo, uint16_t reg, struct glamo_bo *bo) +{ + if ( pGlamo->cmdq_drm_used == pGlamo->cmdq_drm_size ) { + xf86DrvMsg(pGlamo->pScreen->myNum, X_INFO, + "Forced command cache flush.\n"); + GlamoDRMDispatch(pGlamo); + } + + /* Record object position */ + pGlamo->cmdq_objs[pGlamo->cmdq_obj_used] = bo->handle; + /* -> bytes */ + pGlamo->cmdq_obj_pos[pGlamo->cmdq_obj_used] = pGlamo->cmdq_drm_used * 2; + pGlamo->cmdq_obj_used++; + + /* Record command */ + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg; + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = 0x0000; + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg+2; + pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = 0x0000; + + pGlamo->last_buffer_object = bo; +} + + +void GlamoDRMInit(GlamoPtr pGlamo) +{ + pGlamo->cmdq_objs = malloc(1024); + pGlamo->cmdq_obj_pos = malloc(1024); + pGlamo->cmdq_obj_used = 0; + pGlamo->cmdq_drm_used = 0; + pGlamo->cmdq_drm_size = 4 * 1024; + pGlamo->cmdq_drm = malloc(pGlamo->cmdq_drm_size); +} diff --git a/src/glamo-drm.h b/src/glamo-drm.h new file mode 100644 index 0000000..6e0693f --- /dev/null +++ b/src/glamo-drm.h @@ -0,0 +1,38 @@ +/* + * DRI for the SMedia Glamo3362 X.org Driver + * + * Copyright 2009 Thomas White + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + + +#ifndef _GLAMO_DRM_H +#define _GLAMO_DRM_H + +#include +#include + +#include "glamo.h" + +extern void GlamoDRMInit(GlamoPtr pGlamo); +extern void GlamoDRMDispatch(GlamoPtr pGlamo); +extern void GlamoDRMAddCommand(GlamoPtr pGlamo, uint16_t reg, uint16_t val); +extern void GlamoDRMAddCommandBO(GlamoPtr pGlamo, uint16_t reg, + struct glamo_bo *bo); + +#endif /* _GLAMO_DRM_H */ diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index 557ba60..ec116ab 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -55,6 +55,7 @@ #include "glamo.h" #include "glamo-regs.h" #include "glamo-kms-exa.h" +#include "glamo-drm.h" #include #include @@ -114,71 +115,6 @@ static const CARD8 GLAMOBltRop[16] = { }; -/* Submit the prepared command sequence to the kernel */ -static void GlamoDRMDispatch(GlamoPtr pGlamo) -{ - drm_glamo_cmd_buffer_t cmdbuf; - int r; - - cmdbuf.buf = (char *)pGlamo->cmdq_drm; - cmdbuf.bufsz = pGlamo->cmdq_drm_used * 2; /* -> bytes */ - cmdbuf.nobjs = pGlamo->cmdq_obj_used; - cmdbuf.objs = pGlamo->cmdq_objs; - cmdbuf.obj_pos = pGlamo->cmdq_obj_pos; - - r = drmCommandWrite(pGlamo->drm_fd, DRM_GLAMO_CMDBUF, - &cmdbuf, sizeof(cmdbuf)); - if ( r != 0 ) { - xf86DrvMsg(pGlamo->pScreen->myNum, X_ERROR, - "DRM_GLAMO_CMDBUF failed\n"); - } - - /* Reset counts to zero for the next sequence */ - pGlamo->cmdq_obj_used = 0; - pGlamo->cmdq_drm_used = 0; -} - - -static inline void GlamoDRMAddCommand(GlamoPtr pGlamo, uint16_t reg, - uint16_t val) -{ - if ( pGlamo->cmdq_drm_used == pGlamo->cmdq_drm_size ) { - xf86DrvMsg(pGlamo->pScreen->myNum, X_INFO, - "Forced command cache flush.\n"); - GlamoDRMDispatch(pGlamo); - } - - /* Record command */ - pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg; - pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = val; -} - - -static inline void GlamoDRMAddCommandBO(GlamoPtr pGlamo, uint16_t reg, - struct glamo_bo *bo) -{ - if ( pGlamo->cmdq_drm_used == pGlamo->cmdq_drm_size ) { - xf86DrvMsg(pGlamo->pScreen->myNum, X_INFO, - "Forced command cache flush.\n"); - GlamoDRMDispatch(pGlamo); - } - - /* Record object position */ - pGlamo->cmdq_objs[pGlamo->cmdq_obj_used] = bo->handle; - /* -> bytes */ - pGlamo->cmdq_obj_pos[pGlamo->cmdq_obj_used] = pGlamo->cmdq_drm_used * 2; - pGlamo->cmdq_obj_used++; - - /* Record command */ - pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg; - pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = 0x0000; - pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = reg+2; - pGlamo->cmdq_drm[pGlamo->cmdq_drm_used++] = 0x0000; - - pGlamo->last_buffer_object = bo; -} - - unsigned int driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags) { struct glamo_exa_pixmap_priv *priv; @@ -262,8 +198,9 @@ static Bool GlamoKMSExaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int d priv_dst = exaGetPixmapDriverPrivate(pDst); if (pSrc->drawable.bitsPerPixel != 16 || - pDst->drawable.bitsPerPixel != 16) + pDst->drawable.bitsPerPixel != 16) { GLAMO_FALLBACK(("Only 16bpp is supported")); + } mask = FbFullMask(16); if ((pm & mask) != mask) { @@ -440,6 +377,9 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) return TRUE; } + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "PrepareAccess (%i)\n", + driver_priv->bo->handle); + /* Return as quickly as possible if we have a mapping already */ if ( driver_priv->bo->virtual ) { pPix->devPrivate.ptr = driver_priv->bo->virtual; @@ -619,12 +559,7 @@ void GlamoKMSExaInit(ScrnInfoPtr pScrn) exa->WaitMarker = GlamoKMSExaWaitMarker; /* Prepare temporary buffers */ - pGlamo->cmdq_objs = malloc(1024); - pGlamo->cmdq_obj_pos = malloc(1024); - pGlamo->cmdq_obj_used = 0; - pGlamo->cmdq_drm_used = 0; - pGlamo->cmdq_drm_size = 4 * 1024; - pGlamo->cmdq_drm = malloc(pGlamo->cmdq_drm_size); + GlamoDRMInit(pGlamo); pGlamo->last_buffer_object = NULL; for ( i=0; iexa_buffer_markers[i] = NULL; -- cgit v1.2.3 From 38407772f4d6bd99cd073174b3adce404b5bb602 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 19 Sep 2009 13:58:38 +0100 Subject: Change printf->xf86DrvMsg --- src/glamo-dri2.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index 70b9d93..3ac2381 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -96,6 +96,7 @@ static DRI2BufferPtr glamoCreateBuffer(DrawablePtr drawable, unsigned int format) { ScreenPtr pScreen = drawable->pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; DRI2BufferPtr buffer; struct glamo_dri2_buffer_priv *private; PixmapPtr pixmap; @@ -113,6 +114,8 @@ static DRI2BufferPtr glamoCreateBuffer(DrawablePtr drawable, } if ( attachment == DRI2BufferFrontLeft ) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Front left buffer\n"); if ( drawable->type == DRAWABLE_PIXMAP ) { pixmap = (PixmapPtr)drawable; } else { @@ -120,6 +123,8 @@ static DRI2BufferPtr glamoCreateBuffer(DrawablePtr drawable, } pixmap->refcnt++; } else { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Attachment type %i\n", attachment); pixmap = pScreen->CreatePixmap(pScreen, drawable->width, drawable->height, @@ -135,8 +140,9 @@ static DRI2BufferPtr glamoCreateBuffer(DrawablePtr drawable, } r = glamo_gem_name_buffer(driver_priv->bo, &buffer->name); if (r) { - fprintf(stderr, "Couldn't name buffer: %d %s\n", - r, strerror(r)); + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Couldn't name buffer: %d %s\n", + r, strerror(r)); xfree(buffer); xfree(private); return NULL; @@ -159,6 +165,7 @@ static DRI2BufferPtr glamoCreateBuffers(DrawablePtr drawable, unsigned int *attachments, int count) { ScreenPtr pScreen = drawable->pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; int i; DRI2BufferPtr buffers; struct glamo_dri2_buffer_priv *privates; @@ -202,8 +209,9 @@ static DRI2BufferPtr glamoCreateBuffers(DrawablePtr drawable, } r = glamo_gem_name_buffer(driver_priv->bo, &buffers[i].name); if (r) { - fprintf(stderr, "Couldn't name buffer: %d %s\n", - r, strerror(r)); + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Couldn't name buffer: %d %s\n", + r, strerror(r)); xfree(buffers); xfree(privates); return NULL; -- cgit v1.2.3 From bcbc3c57103d5455eea42a47b2067edfa1febdc2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 19 Sep 2009 14:06:40 +0100 Subject: Implement glamoCopyRegion() --- src/glamo-dri2.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index 3ac2381..c607835 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -271,9 +271,56 @@ static void glamoDestroyBuffers(DrawablePtr pDraw, #endif -static void glamoCopyRegion(DrawablePtr pDraw, RegionPtr pRegion, - DRI2BufferPtr pDestBuffer, DRI2BufferPtr pSrcBuffer) +static void glamoCopyRegion(DrawablePtr drawable, RegionPtr region, + DRI2BufferPtr dst_buffer, DRI2BufferPtr src_buffer) { + struct glamo_dri2_buffer_priv *src_private; + struct glamo_dri2_buffer_priv *dst_private; + ScreenPtr pScreen = drawable->pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + PixmapPtr src_pixmap; + PixmapPtr dst_pixmap; + RegionPtr copy_clip; + GCPtr gc; + char *s, *d; + + src_private = src_buffer->driverPrivate; + dst_private = dst_buffer->driverPrivate; + src_pixmap = src_private->pixmap; + dst_pixmap = dst_private->pixmap; + + switch (src_private->attachment) { + case DRI2BufferFrontLeft : s = "DRI2 front left"; break; + case DRI2BufferFakeFrontLeft : s = "DRI2 fake front left"; break; + case DRI2BufferBackLeft : s = "DRI2 back left"; break; + default : s = "unknown"; break; + } + switch (dst_private->attachment) { + case DRI2BufferFrontLeft : d = "DRI2 front left"; break; + case DRI2BufferFakeFrontLeft : d = "DRI2 fake front left"; break; + case DRI2BufferBackLeft : d = "DRI2 back left"; break; + default : d = "unknown"; break; + } + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "glamoCopyRegion" + " %s (%i) -> %s (%i)\n", + s, src_private->attachment, + d, dst_private->attachment); + + if (src_private->attachment == DRI2BufferFrontLeft) { + src_pixmap = (PixmapPtr)drawable; + } + if (dst_private->attachment == DRI2BufferFrontLeft) { + dst_pixmap = (PixmapPtr)drawable; + } + + gc = GetScratchGC(drawable->depth, pScreen); + copy_clip = REGION_CREATE(pScreen, NULL, 0); + REGION_COPY(pScreen, copy_clip, region); + gc->funcs->ChangeClip(gc, CT_REGION, copy_clip, 0); + ValidateGC(&dst_pixmap->drawable, gc); + gc->ops->CopyArea(&src_pixmap->drawable, &dst_pixmap->drawable, gc, + 0, 0, drawable->width, drawable->height, 0, 0); + FreeScratchGC(gc); } -- cgit v1.2.3 From f96458275af119a2f85022194b592b4aab28b8bf Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 19 Sep 2009 15:09:07 +0100 Subject: Remove a debug statement --- src/glamo-kms-exa.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/glamo-kms-exa.c b/src/glamo-kms-exa.c index ec116ab..f29c296 100644 --- a/src/glamo-kms-exa.c +++ b/src/glamo-kms-exa.c @@ -377,9 +377,6 @@ static Bool GlamoKMSExaPrepareAccess(PixmapPtr pPix, int index) return TRUE; } - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "PrepareAccess (%i)\n", - driver_priv->bo->handle); - /* Return as quickly as possible if we have a mapping already */ if ( driver_priv->bo->virtual ) { pPix->devPrivate.ptr = driver_priv->bo->virtual; -- cgit v1.2.3 From 22de1104cfc1fd4dacd667f55d137403892ca96b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 19 Sep 2009 15:22:33 +0100 Subject: Remove more debug --- src/glamo-dri2.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/glamo-dri2.c b/src/glamo-dri2.c index c607835..6b743f4 100644 --- a/src/glamo-dri2.c +++ b/src/glamo-dri2.c @@ -114,8 +114,6 @@ static DRI2BufferPtr glamoCreateBuffer(DrawablePtr drawable, } if ( attachment == DRI2BufferFrontLeft ) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Front left buffer\n"); if ( drawable->type == DRAWABLE_PIXMAP ) { pixmap = (PixmapPtr)drawable; } else { @@ -123,8 +121,6 @@ static DRI2BufferPtr glamoCreateBuffer(DrawablePtr drawable, } pixmap->refcnt++; } else { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Attachment type %i\n", attachment); pixmap = pScreen->CreatePixmap(pScreen, drawable->width, drawable->height, @@ -277,35 +273,16 @@ static void glamoCopyRegion(DrawablePtr drawable, RegionPtr region, struct glamo_dri2_buffer_priv *src_private; struct glamo_dri2_buffer_priv *dst_private; ScreenPtr pScreen = drawable->pScreen; - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; PixmapPtr src_pixmap; PixmapPtr dst_pixmap; RegionPtr copy_clip; GCPtr gc; - char *s, *d; src_private = src_buffer->driverPrivate; dst_private = dst_buffer->driverPrivate; src_pixmap = src_private->pixmap; dst_pixmap = dst_private->pixmap; - switch (src_private->attachment) { - case DRI2BufferFrontLeft : s = "DRI2 front left"; break; - case DRI2BufferFakeFrontLeft : s = "DRI2 fake front left"; break; - case DRI2BufferBackLeft : s = "DRI2 back left"; break; - default : s = "unknown"; break; - } - switch (dst_private->attachment) { - case DRI2BufferFrontLeft : d = "DRI2 front left"; break; - case DRI2BufferFakeFrontLeft : d = "DRI2 fake front left"; break; - case DRI2BufferBackLeft : d = "DRI2 back left"; break; - default : d = "unknown"; break; - } - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "glamoCopyRegion" - " %s (%i) -> %s (%i)\n", - s, src_private->attachment, - d, dst_private->attachment); - if (src_private->attachment == DRI2BufferFrontLeft) { src_pixmap = (PixmapPtr)drawable; } -- cgit v1.2.3 From f9ad3d94703932c94182d5eac15c887e54133857 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 19 Oct 2009 10:26:12 +0200 Subject: Fix use of uninitialised 'pScrn' --- src/glamo-driver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/glamo-driver.c b/src/glamo-driver.c index e8d39f6..17b661e 100644 --- a/src/glamo-driver.c +++ b/src/glamo-driver.c @@ -298,6 +298,8 @@ GlamoFbdevProbe(DriverPtr drv, GDevPtr *devSections, int numDevSections) if (pScrn) { foundScreen = TRUE; + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Not using KMS\n"); pScrn->driverVersion = GLAMO_VERSION; pScrn->driverName = GLAMO_DRIVER_NAME; @@ -345,6 +347,7 @@ GlamoKMSProbe(DriverPtr drv, GDevPtr *devSections, int numDevSections) if ( pScrn ) { foundScreen = TRUE; + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using KMS!\n"); /* Plug in KMS functions */ pScrn->driverVersion = GLAMO_VERSION; @@ -367,7 +370,6 @@ GlamoKMSProbe(DriverPtr drv, GDevPtr *devSections, int numDevSections) static Bool GlamoProbe(DriverPtr drv, int flags) { - ScrnInfoPtr pScrn; GDevPtr *devSections; int numDevSections; Bool foundScreen = FALSE; @@ -384,10 +386,8 @@ GlamoProbe(DriverPtr drv, int flags) /* Is today a good day to use KMS? */ if ( GlamoKernelModesettingAvailable() ) { foundScreen = GlamoKMSProbe(drv, devSections, numDevSections); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using KMS!\n"); } else { foundScreen = GlamoFbdevProbe(drv, devSections, numDevSections); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Not using KMS\n"); } xfree(devSections); -- cgit v1.2.3 From de692805de0ddbaac9a50734f89e0f6cb99d6846 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 28 Oct 2009 01:10:54 +0100 Subject: Reduce excessive waits when resetting engines This reduces the pauses, which allow Glamo engines to settle after being reset, from one second to 15 ms. This reduces the overall time taken for resume (in the non-KMS, non-engine-ioctl case) by several seconds. --- src/glamo-engine.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/glamo-engine.c b/src/glamo-engine.c index a94d362..989f40f 100644 --- a/src/glamo-engine.c +++ b/src/glamo-engine.c @@ -66,9 +66,9 @@ GLAMOEngineReset(GlamoPtr pGlamo, enum GLAMOEngine engine) break; } MMIOSetBitMask(mmio, reg, mask, 0xffff); - sleep(1); + usleep(15000); MMIOSetBitMask(mmio, reg, mask, 0); - sleep(1); + usleep(15000); #endif } -- cgit v1.2.3