From e39286eb5eab8846a228863abf8f1b8b07a9e29d Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 19 Jul 2007 17:00:17 -0700 Subject: Remove DRM_ERR OS macro. This was used to make all ioctl handlers return -errno on linux and errno on *BSD. Instead, just return -errno in shared code, and flip sign on return from shared code to *BSD code. --- bsd-core/drm_auth.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bsd-core/drm_auth.c') diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c index aa0e29c0..556bf891 100644 --- a/bsd-core/drm_auth.c +++ b/bsd-core/drm_auth.c @@ -66,7 +66,7 @@ static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) hash = drm_hash_magic(magic); entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT); - if (!entry) return DRM_ERR(ENOMEM); + if (!entry) return ENOMEM; entry->magic = magic; entry->priv = priv; entry->next = NULL; @@ -112,7 +112,7 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) DRM_UNLOCK(); free(pt, M_DRM); - return DRM_ERR(EINVAL); + return EINVAL; } int drm_getmagic(DRM_IOCTL_ARGS) @@ -168,5 +168,5 @@ int drm_authmagic(DRM_IOCTL_ARGS) drm_remove_magic(dev, auth.magic); return 0; } - return DRM_ERR(EINVAL); + return EINVAL; } -- cgit v1.2.3 From 5b38e134163cc375e91424c4688cc9328c6e9082 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 19 Jul 2007 17:11:11 -0700 Subject: Replace DRM_IOCTL_ARGS with (dev, data, file_priv) and remove DRM_DEVICE. The data is now in kernel space, copied in/out as appropriate according to the This results in DRM_COPY_{TO,FROM}_USER going away, and error paths to deal with those failures. This also means that XFree86 4.2.0 support for i810 DRM is lost. --- bsd-core/drm_auth.c | 71 ++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 42 deletions(-) (limited to 'bsd-core/drm_auth.c') diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c index 556bf891..964f9a42 100644 --- a/bsd-core/drm_auth.c +++ b/bsd-core/drm_auth.c @@ -40,21 +40,16 @@ static int drm_hash_magic(drm_magic_t magic) static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic) { - drm_file_t *retval = NULL; drm_magic_entry_t *pt; - int hash; - - hash = drm_hash_magic(magic); + int hash = drm_hash_magic(magic); - DRM_LOCK(); for (pt = dev->magiclist[hash].head; pt; pt = pt->next) { if (pt->magic == magic) { - retval = pt->priv; - break; + return pt->priv; } } - DRM_UNLOCK(); - return retval; + + return NULL; } static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) @@ -115,58 +110,50 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) return EINVAL; } -int drm_getmagic(DRM_IOCTL_ARGS) +int drm_getmagic(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; static drm_magic_t sequence = 0; - drm_auth_t auth; - drm_file_t *priv; - - DRM_LOCK(); - priv = drm_find_file_by_proc(dev, p); - DRM_UNLOCK(); - if (priv == NULL) { - DRM_ERROR("can't find authenticator\n"); - return EINVAL; - } + drm_auth_t *auth = data; /* Find unique magic */ - if (priv->magic) { - auth.magic = priv->magic; + if (file_priv->magic) { + auth->magic = file_priv->magic; } else { + DRM_LOCK(); do { int old = sequence; - auth.magic = old+1; + auth->magic = old+1; - if (!atomic_cmpset_int(&sequence, old, auth.magic)) + if (!atomic_cmpset_int(&sequence, old, auth->magic)) continue; - } while (drm_find_file(dev, auth.magic)); - priv->magic = auth.magic; - drm_add_magic(dev, priv, auth.magic); + } while (drm_find_file(dev, auth->magic)); + file_priv->magic = auth->magic; + DRM_UNLOCK(); + drm_add_magic(dev, file_priv, auth->magic); } - DRM_DEBUG("%u\n", auth.magic); - - DRM_COPY_TO_USER_IOCTL((drm_auth_t *)data, auth, sizeof(auth)); + DRM_DEBUG("%u\n", auth->magic); return 0; } -int drm_authmagic(DRM_IOCTL_ARGS) +int drm_authmagic(drm_device_t *dev, void *data, struct drm_file *file_priv) { - drm_auth_t auth; - drm_file_t *file; - DRM_DEVICE; - - DRM_COPY_FROM_USER_IOCTL(auth, (drm_auth_t *)data, sizeof(auth)); + drm_auth_t *auth = data; + drm_file_t *priv; - DRM_DEBUG("%u\n", auth.magic); + DRM_DEBUG("%u\n", auth->magic); - if ((file = drm_find_file(dev, auth.magic))) { - file->authenticated = 1; - drm_remove_magic(dev, auth.magic); + DRM_LOCK(); + priv = drm_find_file(dev, auth->magic); + if (priv != NULL) { + priv->authenticated = 1; + drm_remove_magic(dev, auth->magic); + DRM_UNLOCK(); return 0; + } else { + DRM_UNLOCK(); + return EINVAL; } - return EINVAL; } -- cgit v1.2.3 From 263775c454f381fffc8f5d4f309b4e1b131c3734 Mon Sep 17 00:00:00 2001 From: vehemens Date: Mon, 13 Aug 2007 10:24:39 -0700 Subject: Fix drm_auth.c locking to not recurse on dev_lock. --- bsd-core/drm_auth.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'bsd-core/drm_auth.c') diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c index 964f9a42..14cfc225 100644 --- a/bsd-core/drm_auth.c +++ b/bsd-core/drm_auth.c @@ -43,6 +43,8 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic) drm_magic_entry_t *pt; int hash = drm_hash_magic(magic); + DRM_SPINLOCK_ASSERT(&dev->dev_lock); + for (pt = dev->magiclist[hash].head; pt; pt = pt->next) { if (pt->magic == magic) { return pt->priv; @@ -59,6 +61,8 @@ static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) DRM_DEBUG("%d\n", magic); + DRM_SPINLOCK_ASSERT(&dev->dev_lock); + hash = drm_hash_magic(magic); entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT); if (!entry) return ENOMEM; @@ -85,10 +89,11 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) drm_magic_entry_t *pt; int hash; + DRM_SPINLOCK_ASSERT(&dev->dev_lock); + DRM_DEBUG("%d\n", magic); hash = drm_hash_magic(magic); - DRM_LOCK(); for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) { if (pt->magic == magic) { if (dev->magiclist[hash].head == pt) { @@ -100,11 +105,9 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) if (prev) { prev->next = pt->next; } - DRM_UNLOCK(); return 0; } } - DRM_UNLOCK(); free(pt, M_DRM); return EINVAL; @@ -129,8 +132,8 @@ int drm_getmagic(drm_device_t *dev, void *data, struct drm_file *file_priv) continue; } while (drm_find_file(dev, auth->magic)); file_priv->magic = auth->magic; - DRM_UNLOCK(); drm_add_magic(dev, file_priv, auth->magic); + DRM_UNLOCK(); } DRM_DEBUG("%u\n", auth->magic); -- cgit v1.2.3 From 3b07a37a48ca6dc22d538221b59b430dd72c6203 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 13 Aug 2007 10:50:25 -0700 Subject: Add doxygen and fix whitespace for drm_auth.c --- bsd-core/drm_auth.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'bsd-core/drm_auth.c') diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c index 14cfc225..9b5f4f74 100644 --- a/bsd-core/drm_auth.c +++ b/bsd-core/drm_auth.c @@ -1,4 +1,4 @@ -/* drm_auth.h -- IOCTLs for authentication -*- linux-c -*- +/* drm_auth.c -- IOCTLs for authentication -*- linux-c -*- * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com */ /*- @@ -38,6 +38,9 @@ static int drm_hash_magic(drm_magic_t magic) return magic & (DRM_HASH_SIZE-1); } +/** + * Returns the file private associated with the given magic number. + */ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic) { drm_magic_entry_t *pt; @@ -54,6 +57,10 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic) return NULL; } +/** + * Inserts the given magic number into the hash table of used magic number + * lists. + */ static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) { int hash; @@ -83,6 +90,10 @@ static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) return 0; } +/** + * Removes the given magic number from the hash table of used magic number + * lists. + */ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) { drm_magic_entry_t *prev = NULL; @@ -113,6 +124,14 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) return EINVAL; } +/** + * 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(drm_device_t *dev, void *data, struct drm_file *file_priv) { static drm_magic_t sequence = 0; @@ -125,9 +144,9 @@ int drm_getmagic(drm_device_t *dev, void *data, struct drm_file *file_priv) DRM_LOCK(); do { int old = sequence; - + auth->magic = old+1; - + if (!atomic_cmpset_int(&sequence, old, auth->magic)) continue; } while (drm_find_file(dev, auth->magic)); @@ -141,6 +160,9 @@ int drm_getmagic(drm_device_t *dev, void *data, struct drm_file *file_priv) return 0; } +/** + * Marks the client associated with the given magic number as authenticated. + */ int drm_authmagic(drm_device_t *dev, void *data, struct drm_file *file_priv) { drm_auth_t *auth = data; -- cgit v1.2.3 From 5346fc5f36b5e7c55fc7b5cd46f1e4d7563a86a4 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 14 Aug 2007 14:41:24 -0700 Subject: BSD: Replace brief description in each file's first line with doxygen later on. The brief descriptions usually had the wrong filename in them. --- bsd-core/drm_auth.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bsd-core/drm_auth.c') diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c index 9b5f4f74..aa8238c4 100644 --- a/bsd-core/drm_auth.c +++ b/bsd-core/drm_auth.c @@ -1,6 +1,3 @@ -/* drm_auth.c -- IOCTLs for authentication -*- linux-c -*- - * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com - */ /*- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. @@ -31,6 +28,11 @@ * */ +/** @file drm_auth.c + * Implementation of the get/authmagic ioctls implementing the authentication + * scheme between the master and clients. + */ + #include "drmP.h" static int drm_hash_magic(drm_magic_t magic) -- cgit v1.2.3