summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2009-07-22 00:40:11 +0100
committerThomas White <taw@bitwiz.org.uk>2009-07-22 00:40:11 +0100
commitc9f31330d7847820a9cabebc193f22a176690a67 (patch)
tree216c4c4fdd154ec5292a7efef900fd3c46471b28
parent72a3fcc25d026941c0a202cbc6364326b979c767 (diff)
Just backing up progress
-rw-r--r--configure.ac2
-rw-r--r--src/Makefile.am4
-rw-r--r--src/crtc.c307
-rw-r--r--src/glamo-driver.c16
-rw-r--r--src/glamo-kms-driver.c136
-rw-r--r--src/glamo-kms-driver.h12
-rw-r--r--src/glamo.h13
-rw-r--r--src/output.c292
8 files changed, 700 insertions, 82 deletions
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 <alanh@tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <math.h>
+#include <stdint.h>
+
+#include <xf86.h>
+#include <xf86i2c.h>
+#include <xf86Crtc.h>
+#include "driver.h"
+#include "xf86Modes.h"
+
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+
+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 <fcntl.h>
#include <unistd.h>
@@ -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 <sys/types.h>
#include <dirent.h>
+#include <xorg-server.h>
+#include <drm.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
#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 <alanh@tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <xf86.h>
+#include <xf86i2c.h>
+#include <xf86Crtc.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+
+#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);
+}