summaryrefslogtreecommitdiff
path: root/sys/dev/pci/drm
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/pci/drm')
-rw-r--r--sys/dev/pci/drm/drmP.h18
-rw-r--r--sys/dev/pci/drm/drm_auth.c107
-rw-r--r--sys/dev/pci/drm/drm_drv.c155
-rw-r--r--sys/dev/pci/drm/files.drm3
4 files changed, 111 insertions, 172 deletions
diff --git a/sys/dev/pci/drm/drmP.h b/sys/dev/pci/drm/drmP.h
index 7ad25792d2d..580e05855a4 100644
--- a/sys/dev/pci/drm/drmP.h
+++ b/sys/dev/pci/drm/drmP.h
@@ -243,12 +243,6 @@ typedef struct drm_pci_id_list
struct drm_file;
struct drm_device;
-struct drm_magic_entry {
- drm_magic_t magic;
- struct drm_file *priv;
- SPLAY_ENTRY(drm_magic_entry) node;
-};
-
typedef struct drm_buf {
int idx; /* Index into master buflist */
int total; /* Buffer size */
@@ -280,7 +274,7 @@ typedef struct drm_buf_entry {
typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
struct drm_file {
- TAILQ_ENTRY(drm_file) link;
+ SPLAY_ENTRY(drm_file) link;
int authenticated;
unsigned long ioctl_count;
dev_t kdev;
@@ -468,9 +462,8 @@ struct drm_device {
int buf_use; /* Buffers in use -- cannot alloc */
/* Authentication */
- drm_file_list_t files;
+ SPLAY_HEAD(drm_file_tree, drm_file) files;
drm_magic_t magicid;
- SPLAY_HEAD(drm_magic_tree, drm_magic_entry) magiclist;
/* Linked list of mappable regions. Protected by dev_lock */
struct extent *handle_ext;
@@ -625,7 +618,6 @@ int drm_ati_pcigart_cleanup(struct drm_device *,
/* Locking IOCTL support (drm_drv.c) */
int drm_lock(struct drm_device *, void *, struct drm_file *);
int drm_unlock(struct drm_device *, void *, struct drm_file *);
-int drm_version(struct drm_device *, void *, struct drm_file *);
/* Context IOCTL support (drm_context.c) */
int drm_resctx(struct drm_device *, void *, struct drm_file *);
@@ -633,12 +625,6 @@ int drm_addctx(struct drm_device *, void *, struct drm_file *);
int drm_getctx(struct drm_device *, void *, struct drm_file *);
int drm_rmctx(struct drm_device *, void *, struct drm_file *);
-/* Authentication IOCTL support (drm_auth.c) */
-int drm_getmagic(struct drm_device *, void *, struct drm_file *);
-int drm_authmagic(struct drm_device *, void *, struct drm_file *);
-int drm_magic_cmp(struct drm_magic_entry *, struct drm_magic_entry *);
-SPLAY_PROTOTYPE(drm_magic_tree, drm_magic_entry, node, drm_magic_cmp);
-
/* Buffer management support (drm_bufs.c) */
int drm_addmap_ioctl(struct drm_device *, void *, struct drm_file *);
int drm_rmmap_ioctl(struct drm_device *, void *, struct drm_file *);
diff --git a/sys/dev/pci/drm/drm_auth.c b/sys/dev/pci/drm/drm_auth.c
deleted file mode 100644
index c2fd04709a8..00000000000
--- a/sys/dev/pci/drm/drm_auth.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * 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, 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 NONINFRINGEMENT. IN NO EVENT SHALL
- * VA LINUX SYSTEMS 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.
- *
- * Authors:
- * Rickard E. (Rik) Faith <faith@valinux.com>
- * Gareth Hughes <gareth@valinux.com>
- *
- */
-
-/** @file drm_auth.c
- * Implementation of the get/authmagic ioctls implementing the authentication
- * scheme between the master and clients.
- */
-
-#include "drmP.h"
-
-/**
- * Called by the client, this returns a unique magic number to be authorized
- * by the master.
- *
- * The master may use its own knowledge of the client (such as the X
- * connection that the magic is passed over) to determine if the magic number
- * should be authenticated.
- */
-int
-drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_auth *auth = data;
- struct drm_magic_entry *entry;
-
- /* Find unique magic */
- if (file_priv->magic) {
- auth->magic = file_priv->magic;
- } else {
- entry = drm_alloc(sizeof(*entry));
- if (entry == NULL)
- return (ENOMEM);
- DRM_LOCK();
- entry->magic = file_priv->magic = auth->magic = dev->magicid++;
- entry->priv = file_priv;
- SPLAY_INSERT(drm_magic_tree, &dev->magiclist, entry);
-
- DRM_UNLOCK();
- DRM_DEBUG("%d\n", auth->magic);
- }
-
- DRM_DEBUG("%u\n", auth->magic);
-
- return (0);
-}
-
-/**
- * Marks the client associated with the given magic number as authenticated.
- */
-int
-drm_authmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_auth *auth = data;
- struct drm_magic_entry *pt, key;
-
- DRM_DEBUG("%u\n", auth->magic);
-
- key.magic = auth->magic;
- DRM_LOCK();
- if ((pt = SPLAY_FIND(drm_magic_tree, &dev->magiclist, &key)) == NULL ||
- pt->priv == NULL) {
- DRM_UNLOCK();
- return (EINVAL);
- }
-
- pt->priv->authenticated = 1;
- SPLAY_REMOVE(drm_magic_tree, &dev->magiclist, pt);
- DRM_UNLOCK();
-
- drm_free(pt);
-
- return (0);
-}
-
-int
-drm_magic_cmp(struct drm_magic_entry *dme1, struct drm_magic_entry *dme2)
-{
- return (dme1->magic - dme2->magic);
-}
-
-SPLAY_GENERATE(drm_magic_tree, drm_magic_entry, node, drm_magic_cmp);
diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c
index 04d7eb1ed90..7e6a7821c40 100644
--- a/sys/dev/pci/drm/drm_drv.c
+++ b/sys/dev/pci/drm/drm_drv.c
@@ -57,7 +57,12 @@ int drm_activate(struct device *, enum devact);
int drmprint(void *, const char *);
int drm_getunique(struct drm_device *, void *, struct drm_file *);
+int drm_version(struct drm_device *, void *, struct drm_file *);
int drm_setversion(struct drm_device *, void *, struct drm_file *);
+int drm_getmagic(struct drm_device *, void *, struct drm_file *);
+int drm_authmagic(struct drm_device *, void *, struct drm_file *);
+int drm_file_cmp(struct drm_file *, struct drm_file *);
+SPLAY_PROTOTYPE(drm_file_tree, drm_file, link, drm_file_cmp);
/*
* attach drm to a pci-based driver.
@@ -137,7 +142,7 @@ drm_attach(struct device *parent, struct device *self, void *aux)
mtx_init(&dev->lock.spinlock, IPL_NONE);
TAILQ_INIT(&dev->maplist);
- TAILQ_INIT(&dev->files);
+ SPLAY_INIT(&dev->files);
if (dev->driver->vblank_pipes != 0 && drm_vblank_init(dev,
dev->driver->vblank_pipes)) {
@@ -249,17 +254,21 @@ drm_find_description(int vendor, int device, drm_pci_id_list_t *idlist)
return NULL;
}
+int
+drm_file_cmp(struct drm_file *f1, struct drm_file *f2)
+{
+ return (f1->minor < f2->minor ? -1 : f1->minor > f2->minor);
+}
+
+SPLAY_GENERATE(drm_file_tree, drm_file, link, drm_file_cmp);
+
struct drm_file *
drm_find_file_by_minor(struct drm_device *dev, int minor)
{
- struct drm_file *priv;
-
- DRM_SPINLOCK_ASSERT(&dev->dev_lock);
+ struct drm_file key;
- TAILQ_FOREACH(priv, &dev->files, link)
- if (priv->minor == minor)
- break;
- return (priv);
+ key.minor = minor;
+ return (SPLAY_FIND(drm_file_tree, &dev->files, &key));
}
int
@@ -284,7 +293,6 @@ drm_firstopen(struct drm_device *dev)
}
dev->magicid = 1;
- SPLAY_INIT(&dev->magiclist);
dev->irq_enabled = 0;
dev->if_version = 0;
@@ -299,7 +307,6 @@ drm_firstopen(struct drm_device *dev)
int
drm_lastclose(struct drm_device *dev)
{
- struct drm_magic_entry *pt;
drm_local_map_t *map, *mapsave;
DRM_DEBUG("\n");
@@ -314,12 +321,6 @@ drm_lastclose(struct drm_device *dev)
drm_dma_takedown(dev);
DRM_LOCK();
- /* Clear pid list */
- while ((pt = SPLAY_ROOT(&dev->magiclist)) != NULL) {
- SPLAY_REMOVE(drm_magic_tree, &dev->magiclist, pt);
- drm_free(pt);
- }
-
if (dev->sg != NULL) {
struct drm_sg_mem *sg = dev->sg;
dev->sg = NULL;
@@ -332,7 +333,7 @@ drm_lastclose(struct drm_device *dev)
for (map = TAILQ_FIRST(&dev->maplist); map != TAILQ_END(&dev->maplist);
map = mapsave) {
mapsave = TAILQ_NEXT(map, link);
- if (!(map->flags & _DRM_DRIVER))
+ if ((map->flags & _DRM_DRIVER) == 0)
drm_rmmap_locked(dev, map);
}
@@ -347,32 +348,6 @@ drm_lastclose(struct drm_device *dev)
}
int
-drm_version(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_version *version = data;
- int len;
-
-#define DRM_COPY(name, value) \
- len = strlen( value ); \
- if ( len > name##_len ) len = name##_len; \
- name##_len = strlen( value ); \
- if ( len && name ) { \
- if ( DRM_COPY_TO_USER( name, value, len ) ) \
- return EFAULT; \
- }
-
- version->version_major = dev->driver->major;
- version->version_minor = dev->driver->minor;
- version->version_patchlevel = dev->driver->patchlevel;
-
- DRM_COPY(version->name, dev->driver->name);
- DRM_COPY(version->date, dev->driver->date);
- DRM_COPY(version->desc, dev->driver->desc);
-
- return 0;
-}
-
-int
drmopen(dev_t kdev, int flags, int fmt, struct proc *p)
{
struct drm_device *dev = NULL;
@@ -422,15 +397,15 @@ drmopen(dev_t kdev, int flags, int fmt, struct proc *p)
DRM_LOCK();
/* first opener automatically becomes master if root */
- if (TAILQ_EMPTY(&dev->files) && !DRM_SUSER(p)) {
+ if (SPLAY_EMPTY(&dev->files) && !DRM_SUSER(p)) {
DRM_UNLOCK();
ret = EPERM;
goto free_priv;
}
- priv->master = TAILQ_EMPTY(&dev->files);
+ priv->master = SPLAY_EMPTY(&dev->files);
- TAILQ_INSERT_TAIL(&dev->files, priv, link);
+ SPLAY_INSERT(drm_file_tree, &dev->files, priv);
DRM_UNLOCK();
return (0);
@@ -516,7 +491,7 @@ drmclose(dev_t kdev, int flags, int fmt, struct proc *p)
dev->buf_pgid = 0;
DRM_LOCK();
- TAILQ_REMOVE(&dev->files, file_priv, link);
+ SPLAY_REMOVE(drm_file_tree, &dev->files, file_priv);
drm_free(file_priv);
done:
@@ -817,6 +792,32 @@ drm_getunique(struct drm_device *dev, void *data, struct drm_file *file_priv)
#define DRM_IF_MINOR 2
int
+drm_version(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+ struct drm_version *version = data;
+ int len;
+
+#define DRM_COPY(name, value) \
+ len = strlen( value ); \
+ if ( len > name##_len ) len = name##_len; \
+ name##_len = strlen( value ); \
+ if ( len && name ) { \
+ if ( DRM_COPY_TO_USER( name, value, len ) ) \
+ return EFAULT; \
+ }
+
+ version->version_major = dev->driver->major;
+ version->version_minor = dev->driver->minor;
+ version->version_patchlevel = dev->driver->patchlevel;
+
+ DRM_COPY(version->name, dev->driver->name);
+ DRM_COPY(version->date, dev->driver->date);
+ DRM_COPY(version->desc, dev->driver->desc);
+
+ return 0;
+}
+
+int
drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_priv)
{
struct drm_set_version ver, *sv = data;
@@ -915,3 +916,63 @@ drm_dmamem_free(bus_dma_tag_t dmat, struct drm_dmamem *mem)
bus_dmamap_destroy(dmat, mem->map);
free(mem, M_DRM);
}
+
+/**
+ * Called by the client, this returns a unique magic number to be authorized
+ * by the master.
+ *
+ * The master may use its own knowledge of the client (such as the X
+ * connection that the magic is passed over) to determine if the magic number
+ * should be authenticated.
+ */
+int
+drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+ struct drm_auth *auth = data;
+
+ if (dev->magicid == 0)
+ dev->magicid = 1;
+
+ /* Find unique magic */
+ if (file_priv->magic) {
+ auth->magic = file_priv->magic;
+ } else {
+ DRM_LOCK();
+ file_priv->magic = auth->magic = dev->magicid++;
+ DRM_UNLOCK();
+ DRM_DEBUG("%d\n", auth->magic);
+ }
+
+ DRM_DEBUG("%u\n", auth->magic);
+
+ return (0);
+}
+
+/**
+ * Marks the client associated with the given magic number as authenticated.
+ */
+int
+drm_authmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+ struct drm_file *p;
+ struct drm_auth *auth = data;
+ int ret = EINVAL;
+
+ DRM_DEBUG("%u\n", auth->magic);
+
+ if (auth->magic == 0)
+ return (ret);
+
+ DRM_LOCK();
+ SPLAY_FOREACH(p, drm_file_tree, &dev->files) {
+ if (p->magic == auth->magic) {
+ p->authenticated = 1;
+ p->magic = 0;
+ ret = 0;
+ break;
+ }
+ }
+ DRM_UNLOCK();
+
+ return (ret);
+}
diff --git a/sys/dev/pci/drm/files.drm b/sys/dev/pci/drm/files.drm
index fc522edbbd8..1168862a425 100644
--- a/sys/dev/pci/drm/files.drm
+++ b/sys/dev/pci/drm/files.drm
@@ -1,12 +1,11 @@
# $NetBSD: files.drm,v 1.2 2007/03/28 11:29:37 jmcneill Exp $
-# $OpenBSD: files.drm,v 1.12 2009/02/15 20:10:24 oga Exp $
+# $OpenBSD: files.drm,v 1.13 2009/03/26 22:40:06 oga Exp $
# direct rendering modules
define drmbase {}
device drm: drmbase
attach drm at drmbase
file dev/pci/drm/drm_agpsupport.c drm
-file dev/pci/drm/drm_auth.c drm
file dev/pci/drm/drm_bufs.c drm
file dev/pci/drm/drm_context.c drm
file dev/pci/drm/drm_dma.c drm