summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac2
-rw-r--r--libdrm/Makefile.am2
-rw-r--r--libdrm/xf86drm.c168
-rw-r--r--libdrm/xf86drm.h18
4 files changed, 105 insertions, 85 deletions
diff --git a/configure.ac b/configure.ac
index 224f43a5..c0b11b20 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AC_PREREQ(2.57)
-AC_INIT([libdrm], 2.2.0, [dri-devel@lists.sourceforge.net], libdrm)
+AC_INIT([libdrm], 2.3.0, [dri-devel@lists.sourceforge.net], libdrm)
AC_CONFIG_SRCDIR([Makefile.am])
AM_INIT_AUTOMAKE([dist-bzip2])
diff --git a/libdrm/Makefile.am b/libdrm/Makefile.am
index 91a7e5dc..e7e07e47 100644
--- a/libdrm/Makefile.am
+++ b/libdrm/Makefile.am
@@ -20,7 +20,7 @@
libdrm_la_LTLIBRARIES = libdrm.la
libdrm_ladir = $(libdir)
-libdrm_la_LDFLAGS = -version-number 2:0:0 -no-undefined
+libdrm_la_LDFLAGS = -version-number 2:3:0 -no-undefined
AM_CFLAGS = -I$(top_srcdir)/shared-core
libdrm_la_SOURCES = xf86drm.c xf86drmHash.c xf86drmRandom.c xf86drmSL.c
diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c
index 5efb532b..05b40f7a 100644
--- a/libdrm/xf86drm.c
+++ b/libdrm/xf86drm.c
@@ -35,40 +35,25 @@
#include <xorg-config.h>
#endif
-#ifdef XFree86Server
-# include "xf86.h"
-# include "xf86_OSproc.h"
-# include "drm.h"
-# include "xf86_ansic.h"
-# define _DRM_MALLOC xalloc
-# define _DRM_FREE xfree
-# ifndef XFree86LOADER
-# include <sys/mman.h>
-# endif
-#else
-# ifdef HAVE_CONFIG_H
-# include <config.h>
-# endif
-# include <stdio.h>
-# include <stdlib.h>
-# include <unistd.h>
-# include <string.h>
-# include <ctype.h>
-# include <fcntl.h>
-# include <errno.h>
-# include <signal.h>
-# include <sys/types.h>
-# include <sys/stat.h>
-# define stat_t struct stat
-# include <sys/ioctl.h>
-# include <sys/mman.h>
-# include <sys/time.h>
-# include <stdarg.h>
-# define _DRM_MALLOC malloc
-# define _DRM_FREE free
-# include "drm.h"
+#ifdef HAVE_CONFIG_H
+# include <config.h>
#endif
-
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#define stat_t struct stat
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <stdarg.h>
+#include "drm.h"
/* Not all systems have MAP_FAILED defined */
#ifndef MAP_FAILED
@@ -107,6 +92,13 @@
#define DRM_MSG_VERBOSITY 3
+static drmServerInfoPtr drm_server_info;
+
+void drmSetServerInfo(drmServerInfoPtr info)
+{
+ drm_server_info = info;
+}
+
/**
* Output a message to stderr.
*
@@ -115,44 +107,54 @@
* \internal
* This function is a wrapper around vfprintf().
*/
+
+static int drmDebugPrint(const char *format, va_list ap)
+{
+ return vfprintf(stderr, format, ap);
+}
+
+static int (*drm_debug_print)(const char *format, va_list ap) = drmDebugPrint;
+
static void
drmMsg(const char *format, ...)
{
va_list ap;
-
-#ifndef XFree86Server
const char *env;
- if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose"))
-#endif
+ if (((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) || drm_server_info)
{
va_start(ap, format);
-#ifdef XFree86Server
- xf86VDrvMsgVerb(-1, X_NONE, DRM_MSG_VERBOSITY, format, ap);
-#else
- vfprintf(stderr, format, ap);
-#endif
+ if (drm_server_info) {
+ drm_server_info->debug_print(format,ap);
+ } else {
+ drm_debug_print(format, ap);
+ }
va_end(ap);
}
}
+void
+drmSetDebugMsgFunction(int (*debug_msg_ptr)(const char *format, va_list ap))
+{
+ drm_debug_print = debug_msg_ptr;
+}
+
static void *drmHashTable = NULL; /* Context switch callbacks */
-typedef struct drmHashEntry {
- int fd;
- void (*f)(int, void *, void *);
- void *tagTable;
-} drmHashEntry;
+void *drmGetHashTable(void)
+{
+ return drmHashTable;
+}
void *drmMalloc(int size)
{
void *pt;
- if ((pt = _DRM_MALLOC(size))) memset(pt, 0, size);
+ if ((pt = malloc(size))) memset(pt, 0, size);
return pt;
}
void drmFree(void *pt)
{
- if (pt) _DRM_FREE(pt);
+ if (pt) free(pt);
}
/* drmStrdup can't use strdup(3), since it doesn't call _DRM_MALLOC... */
@@ -163,7 +165,7 @@ static char *drmStrdup(const char *s)
if (!s)
return NULL;
- retval = _DRM_MALLOC(strlen(s)+1);
+ retval = malloc(strlen(s)+1);
if (!retval)
return NULL;
@@ -182,7 +184,7 @@ static unsigned long drmGetKeyFromFd(int fd)
return st.st_rdev;
}
-static drmHashEntry *drmGetEntry(int fd)
+drmHashEntry *drmGetEntry(int fd)
{
unsigned long key = drmGetKeyFromFd(fd);
void *value;
@@ -269,21 +271,20 @@ static int drmOpenDevice(long dev, int minor)
stat_t st;
char buf[64];
int fd;
- mode_t devmode = DRM_DEV_MODE;
+ mode_t devmode = DRM_DEV_MODE, serv_mode;
int isroot = !geteuid();
-#if defined(XFree86Server)
uid_t user = DRM_DEV_UID;
- gid_t group = DRM_DEV_GID;
-#endif
-
+ gid_t group = DRM_DEV_GID, serv_group;
+
sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor);
drmMsg("drmOpenDevice: node name is %s\n", buf);
-#if defined(XFree86Server)
- devmode = xf86ConfigDRI.mode ? xf86ConfigDRI.mode : DRM_DEV_MODE;
- devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH);
- group = (xf86ConfigDRI.group >= 0) ? xf86ConfigDRI.group : DRM_DEV_GID;
-#endif
+ if (drm_server_info) {
+ drm_server_info->get_perms(&serv_group, &serv_mode);
+ devmode = serv_mode ? serv_mode : DRM_DEV_MODE;
+ devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH);
+ group = (serv_group >= 0) ? serv_group : DRM_DEV_GID;
+ }
if (stat(DRM_DIR_NAME, &st)) {
if (!isroot) return DRM_ERR_NOT_ROOT;
@@ -298,10 +299,11 @@ static int drmOpenDevice(long dev, int minor)
remove(buf);
mknod(buf, S_IFCHR | devmode, dev);
}
-#if defined(XFree86Server)
- chown(buf, user, group);
- chmod(buf, devmode);
-#endif
+
+ if (drm_server_info) {
+ chown(buf, user, group);
+ chmod(buf, devmode);
+ }
fd = open(buf, O_RDWR, 0);
drmMsg("drmOpenDevice: open result is %d, (%s)\n",
@@ -315,10 +317,10 @@ static int drmOpenDevice(long dev, int minor)
if (!isroot) return DRM_ERR_NOT_ROOT;
remove(buf);
mknod(buf, S_IFCHR | devmode, dev);
-#if defined(XFree86Server)
- chown(buf, user, group);
- chmod(buf, devmode);
-#endif
+ if (drm_server_info) {
+ chown(buf, user, group);
+ chmod(buf, devmode);
+ }
}
fd = open(buf, O_RDWR, 0);
drmMsg("drmOpenDevice: open result is %d, (%s)\n",
@@ -456,16 +458,16 @@ static int drmOpenByName(const char *name)
char * id;
if (!drmAvailable()) {
-#if !defined(XFree86Server)
+ if (!drm_server_info)
return -1;
-#else
+ else {
/* try to load the kernel module now */
- if (!xf86LoadKernelModule(name)) {
- ErrorF("[drm] failed to load kernel module \"%s\"\n",
- name);
- return -1;
+ if (!drm_server_info->load_module(name)) {
+ drmMsg("[drm] failed to load kernel module \"%s\"\n",
+ name);
+ return -1;
}
-#endif
+ }
}
/*
@@ -547,16 +549,14 @@ static int drmOpenByName(const char *name)
*/
int drmOpen(const char *name, const char *busid)
{
-#ifdef XFree86Server
- if (!drmAvailable() && name != NULL) {
+ if (!drmAvailable() && name != NULL && drm_server_info) {
/* try to load the kernel */
- if (!xf86LoadKernelModule(name)) {
- ErrorF("[drm] failed to load kernel module \"%s\"\n",
+ if (!drm_server_info->load_module(name)) {
+ drmMsg("[drm] failed to load kernel module \"%s\"\n",
name);
return -1;
}
}
-#endif
if (busid) {
int fd;
@@ -710,15 +710,17 @@ drmVersionPtr drmGetLibVersion(int fd)
drm_version_t *version = drmMalloc(sizeof(*version));
/* Version history:
+ * NOTE THIS MUST NOT GO ABOVE VERSION 1.X due to drivers needing it
* revision 1.0.x = original DRM interface with no drmGetLibVersion
* entry point and many drm<Device> extensions
* revision 1.1.x = added drmCommand entry points for device extensions
* added drmGetLibVersion to identify libdrm.a version
* revision 1.2.x = added drmSetInterfaceVersion
* modified drmOpen to handle both busid and name
+ * revision 1.3.x = added server + memory manager
*/
- version->version_major = 2;
- version->version_minor = 2;
+ version->version_major = 1;
+ version->version_minor = 3;
version->version_patchlevel = 0;
return (drmVersionPtr)version;
diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h
index 86ee7d30..4d9580c4 100644
--- a/libdrm/xf86drm.h
+++ b/libdrm/xf86drm.h
@@ -36,6 +36,8 @@
#ifndef _XF86DRM_H_
#define _XF86DRM_H_
+#include <stdarg.h>
+#include <sys/types.h>
#include <drm.h>
/* Defaults, if nothing set in xf86config */
@@ -61,6 +63,21 @@
typedef unsigned int drmSize, *drmSizePtr; /**< For mapped regions */
typedef void *drmAddress, **drmAddressPtr; /**< For mapped regions */
+typedef struct _drmServerInfo {
+ int (*debug_print)(const char *format, va_list ap);
+ int (*load_module)(const char *name);
+ void (*get_perms)(gid_t *, mode_t *);
+} drmServerInfo, *drmServerInfoPtr;
+
+typedef struct drmHashEntry {
+ int fd;
+ void (*f)(int, void *, void *);
+ void *tagTable;
+} drmHashEntry;
+
+extern void *drmGetHashTable(void);
+extern drmHashEntry *drmGetEntry(int fd);
+
/**
* Driver version information.
*
@@ -604,6 +621,7 @@ extern int drmScatterGatherFree(int fd, drm_handle_t handle);
extern int drmWaitVBlank(int fd, drmVBlankPtr vbl);
/* Support routines */
+extern void drmSetServerInfo(drmServerInfoPtr info);
extern int drmError(int err, const char *label);
extern void *drmMalloc(int size);
extern void drmFree(void *pt);