summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Marchesin <marchesin@icps.u-strasbg.fr>2006-11-11 01:57:05 +0100
committerStephane Marchesin <marchesin@icps.u-strasbg.fr>2006-11-11 01:57:05 +0100
commit5a0cdf7db34fc679160a58b257afc9e9b216907e (patch)
treea0be35bdf98f883342322a1df74e112665c26a96
parent1123ab089075af3141c794696ec394fa46b4353f (diff)
parentd51e1bb56ca2f7858cdeac6f61a7b747c1e15b1e (diff)
Merge branch 'master' of git+ssh://marcheu@git.freedesktop.org/git/mesa/drm into nouveau-1
-rw-r--r--configure.ac2
-rw-r--r--libdrm/Makefile.am2
-rw-r--r--libdrm/xf86drm.c229
-rw-r--r--libdrm/xf86drm.h21
-rw-r--r--shared-core/drm.h2
5 files changed, 171 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..56450e80 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;
@@ -3213,3 +3215,64 @@ int drmMMUnlock(int fd, unsigned memType)
return ret;
}
+
+#define DRM_MAX_FDS 16
+static struct {
+ char *BusID;
+ int fd;
+ int refcount;
+} connection[DRM_MAX_FDS];
+
+static int nr_fds = 0;
+
+int drmOpenOnce(void *unused,
+ const char *BusID,
+ int *newlyopened)
+{
+ int i;
+ int fd;
+
+ for (i = 0; i < nr_fds; i++)
+ if (strcmp(BusID, connection[i].BusID) == 0) {
+ connection[i].refcount++;
+ *newlyopened = 0;
+ return connection[i].fd;
+ }
+
+ fd = drmOpen(unused, BusID);
+ if (fd <= 0 || nr_fds == DRM_MAX_FDS)
+ return fd;
+
+ connection[nr_fds].BusID = strdup(BusID);
+ connection[nr_fds].fd = fd;
+ connection[nr_fds].refcount = 1;
+ *newlyopened = 1;
+
+ if (0)
+ fprintf(stderr, "saved connection %d for %s %d\n",
+ nr_fds, connection[nr_fds].BusID,
+ strcmp(BusID, connection[nr_fds].BusID));
+
+ nr_fds++;
+
+ return fd;
+}
+
+void drmCloseOnce(int fd)
+{
+ int i;
+
+ for (i = 0; i < nr_fds; i++) {
+ if (fd == connection[i].fd) {
+ if (--connection[i].refcount == 0) {
+ drmClose(connection[i].fd);
+ free(connection[i].BusID);
+
+ if (i < --nr_fds)
+ connection[i] = connection[nr_fds];
+
+ return;
+ }
+ }
+ }
+}
diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h
index 86ee7d30..34c9ec0e 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);
@@ -637,6 +655,9 @@ extern int drmSLLookupNeighbors(void *l, unsigned long key,
unsigned long *prev_key, void **prev_value,
unsigned long *next_key, void **next_value);
+extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened);
+extern void drmCloseOnce(int fd);
+
#include "xf86mm.h"
#endif
diff --git a/shared-core/drm.h b/shared-core/drm.h
index 16e86267..9efb1dc4 100644
--- a/shared-core/drm.h
+++ b/shared-core/drm.h
@@ -139,6 +139,8 @@ typedef unsigned long long drm_u64_t;
typedef unsigned int drm_handle_t;
#else
+#include <sys/types.h>
+typedef u_int64_t drm_u64_t;
typedef unsigned long drm_handle_t; /**< To mapped regions */
#endif
typedef unsigned int drm_context_t; /**< GLXContext handle */