[pkg-fso-commits] [SCM] xf86-video-glamo, SMedia Glamo video driver for X.Org branch, master, updated. upstream/0.0.0+20090707.git98c012f7-57-g9918e08

Thomas White taw at bitwiz.org.uk
Fri Jan 8 13:24:41 UTC 2010


The following commit has been merged in the master branch:
commit b6eb663a8d35db3119dba0e644a94d99f922046f
Author: Thomas White <taw at bitwiz.org.uk>
Date:   Sun Jul 26 18:40:29 2009 +0100

    Make everything up to glamo-kms-exa.c compile

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 <xf86.h>
+#include <xf86_OSproc.h>
+#include <xf86drm.h>
+#include <dri2.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #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; i<count; i++ ) {
+
+		if ( attachments[i] == DRI2BufferFrontLeft ) {
+
+			/* Front left buffer - just dig out the pixmap */
+			if ( pDraw->type == 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; i<count; i++ ) {
+		GlamoDRI2BufferPrivatePtr private;
+		private = buffers[i].driverPrivate;
+		(*pScreen->DestroyPixmap)(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; i<DRM_MAX_MINOR; i++ ) {
+		sprintf(p, DRM_DEV_NAME, DRM_DIR_NAME, i);
+		if ( stat(p, &sbuf) == 0 && sbuf.st_rdev == d ) break;
+	}
+	if ( i == DRM_MAX_MINOR ) {
+		xf86DrvMsg(pScrn->scrnIndex, 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 <taw at bitwiz.org.uk>
+ *
+ * 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 <stdlib.h>
 #include <math.h>
 #include <stdint.h>
+#include <errno.h>
 
 #include <xf86.h>
 #include <xf86i2c.h>
 #include <xf86Crtc.h>
-#include "driver.h"
-#include "xf86Modes.h"
-
+#include <xf86drm.h>
+#include <drm.h>
+#include <xf86drmMode.h>
+#include <xf86Modes.h>
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
 
+#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 <taw at bitwiz.org.uk>
+ *
+ * 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 <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
+#include <X11/Xatom.h>
+#include <xf86drmMode.h>
 
-#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 <linux/fb.h>
+#include <drm/drm.h>
 
 #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;

-- 
xf86-video-glamo, SMedia Glamo video driver for X.Org



More information about the pkg-fso-commits mailing list