From 50cb405f93da70054ede29e0c365f06352dc8fe5 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 19 Jul 2007 06:02:20 -0700 Subject: Fix the getclient test (Need this feature for future tests). --- bsd-core/drm_ioctl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'bsd-core/drm_ioctl.c') diff --git a/bsd-core/drm_ioctl.c b/bsd-core/drm_ioctl.c index e22faa83..b5b5cf58 100644 --- a/bsd-core/drm_ioctl.c +++ b/bsd-core/drm_ioctl.c @@ -213,9 +213,7 @@ int drm_getclient(DRM_IOCTL_ARGS) } DRM_UNLOCK(); - DRM_COPY_TO_USER_IOCTL( (drm_client_t *)data, client, sizeof(client) ); - - return 0; + return EINVAL; } int drm_getstats(DRM_IOCTL_ARGS) -- cgit v1.2.3 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_ioctl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'bsd-core/drm_ioctl.c') diff --git a/bsd-core/drm_ioctl.c b/bsd-core/drm_ioctl.c index b5b5cf58..e450066c 100644 --- a/bsd-core/drm_ioctl.c +++ b/bsd-core/drm_ioctl.c @@ -48,7 +48,7 @@ int drm_getunique(DRM_IOCTL_ARGS) if (u.unique_len >= dev->unique_len) { if (DRM_COPY_TO_USER(u.unique, dev->unique, dev->unique_len)) - return DRM_ERR(EFAULT); + return EFAULT; } u.unique_len = dev->unique_len; @@ -71,15 +71,15 @@ int drm_setunique(DRM_IOCTL_ARGS) /* Check and copy in the submitted Bus ID */ if (!u.unique_len || u.unique_len > 1024) - return DRM_ERR(EINVAL); + return EINVAL; busid = malloc(u.unique_len + 1, M_DRM, M_WAITOK); if (busid == NULL) - return DRM_ERR(ENOMEM); + return ENOMEM; if (DRM_COPY_FROM_USER(busid, u.unique, u.unique_len)) { free(busid, M_DRM); - return DRM_ERR(EFAULT); + return EFAULT; } busid[u.unique_len] = '\0'; @@ -89,7 +89,7 @@ int drm_setunique(DRM_IOCTL_ARGS) ret = sscanf(busid, "PCI:%d:%d:%d", &bus, &slot, &func); if (ret != 3) { free(busid, M_DRM); - return DRM_ERR(EINVAL); + return EINVAL; } domain = bus >> 8; bus &= 0xff; @@ -99,14 +99,14 @@ int drm_setunique(DRM_IOCTL_ARGS) (slot != dev->pci_slot) || (func != dev->pci_func)) { free(busid, M_DRM); - return DRM_ERR(EINVAL); + return EINVAL; } /* Actually set the device's busid now. */ DRM_LOCK(); if (dev->unique_len || dev->unique) { DRM_UNLOCK(); - return DRM_ERR(EBUSY); + return EBUSY; } dev->unique_len = u.unique_len; @@ -158,7 +158,7 @@ int drm_getmap(DRM_IOCTL_ARGS) DRM_LOCK(); if (idx < 0) { DRM_UNLOCK(); - return DRM_ERR(EINVAL); + return EINVAL; } TAILQ_FOREACH(mapinlist, &dev->maplist, link) { -- 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_ioctl.c | 124 +++++++++++++++++++++------------------------------ 1 file changed, 52 insertions(+), 72 deletions(-) (limited to 'bsd-core/drm_ioctl.c') diff --git a/bsd-core/drm_ioctl.c b/bsd-core/drm_ioctl.c index e450066c..ebdb2140 100644 --- a/bsd-core/drm_ioctl.c +++ b/bsd-core/drm_ioctl.c @@ -39,20 +39,15 @@ * before setunique has been called. The format for the bus-specific part of * the unique is not defined for any other bus. */ -int drm_getunique(DRM_IOCTL_ARGS) +int drm_getunique(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; - drm_unique_t u; + drm_unique_t *u = data; - DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) ); - - if (u.unique_len >= dev->unique_len) { - if (DRM_COPY_TO_USER(u.unique, dev->unique, dev->unique_len)) + if (u->unique_len >= dev->unique_len) { + if (DRM_COPY_TO_USER(u->unique, dev->unique, dev->unique_len)) return EFAULT; } - u.unique_len = dev->unique_len; - - DRM_COPY_TO_USER_IOCTL( (drm_unique_t *)data, u, sizeof(u) ); + u->unique_len = dev->unique_len; return 0; } @@ -60,28 +55,25 @@ int drm_getunique(DRM_IOCTL_ARGS) /* Deprecated in DRM version 1.1, and will return EBUSY when setversion has * requested version 1.1 or greater. */ -int drm_setunique(DRM_IOCTL_ARGS) +int drm_setunique(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; - drm_unique_t u; + drm_unique_t *u = data; int domain, bus, slot, func, ret; char *busid; - DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) ); - /* Check and copy in the submitted Bus ID */ - if (!u.unique_len || u.unique_len > 1024) + if (!u->unique_len || u->unique_len > 1024) return EINVAL; - busid = malloc(u.unique_len + 1, M_DRM, M_WAITOK); + busid = malloc(u->unique_len + 1, M_DRM, M_WAITOK); if (busid == NULL) return ENOMEM; - if (DRM_COPY_FROM_USER(busid, u.unique, u.unique_len)) { + if (DRM_COPY_FROM_USER(busid, u->unique, u->unique_len)) { free(busid, M_DRM); return EFAULT; } - busid[u.unique_len] = '\0'; + busid[u->unique_len] = '\0'; /* Return error if the busid submitted doesn't match the device's actual * busid. @@ -109,7 +101,7 @@ int drm_setunique(DRM_IOCTL_ARGS) return EBUSY; } - dev->unique_len = u.unique_len; + dev->unique_len = u->unique_len; dev->unique = busid; DRM_UNLOCK(); @@ -143,17 +135,14 @@ drm_set_busid(drm_device_t *dev) return 0; } -int drm_getmap(DRM_IOCTL_ARGS) +int drm_getmap(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; - drm_map_t map; + drm_map_t *map = data; drm_local_map_t *mapinlist; int idx; int i = 0; - DRM_COPY_FROM_USER_IOCTL( map, (drm_map_t *)data, sizeof(map) ); - - idx = map.offset; + idx = map->offset; DRM_LOCK(); if (idx < 0) { @@ -163,12 +152,12 @@ int drm_getmap(DRM_IOCTL_ARGS) TAILQ_FOREACH(mapinlist, &dev->maplist, link) { if (i==idx) { - map.offset = mapinlist->offset; - map.size = mapinlist->size; - map.type = mapinlist->type; - map.flags = mapinlist->flags; - map.handle = mapinlist->handle; - map.mtrr = mapinlist->mtrr; + map->offset = mapinlist->offset; + map->size = mapinlist->size; + map->type = mapinlist->type; + map->flags = mapinlist->flags; + map->handle = mapinlist->handle; + map->mtrr = mapinlist->mtrr; break; } i++; @@ -179,34 +168,27 @@ int drm_getmap(DRM_IOCTL_ARGS) if (mapinlist == NULL) return EINVAL; - DRM_COPY_TO_USER_IOCTL( (drm_map_t *)data, map, sizeof(map) ); - return 0; } -int drm_getclient(DRM_IOCTL_ARGS) +int drm_getclient(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; - drm_client_t client; + drm_client_t *client = data; drm_file_t *pt; int idx; int i = 0; - DRM_COPY_FROM_USER_IOCTL( client, (drm_client_t *)data, sizeof(client) ); - - idx = client.idx; + idx = client->idx; DRM_LOCK(); TAILQ_FOREACH(pt, &dev->files, link) { if (i==idx) { - client.auth = pt->authenticated; - client.pid = pt->pid; - client.uid = pt->uid; - client.magic = pt->magic; - client.iocs = pt->ioctl_count; + client->auth = pt->authenticated; + client->pid = pt->pid; + client->uid = pt->uid; + client->magic = pt->magic; + client->iocs = pt->ioctl_count; DRM_UNLOCK(); - - *(drm_client_t *)data = client; return 0; } i++; @@ -216,10 +198,9 @@ int drm_getclient(DRM_IOCTL_ARGS) return EINVAL; } -int drm_getstats(DRM_IOCTL_ARGS) +int drm_getstats(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; - drm_stats_t stats; + drm_stats_t *stats = data; int i; memset(&stats, 0, sizeof(stats)); @@ -228,49 +209,44 @@ int drm_getstats(DRM_IOCTL_ARGS) for (i = 0; i < dev->counters; i++) { if (dev->types[i] == _DRM_STAT_LOCK) - stats.data[i].value + stats->data[i].value = (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0); else - stats.data[i].value = atomic_read(&dev->counts[i]); - stats.data[i].type = dev->types[i]; + stats->data[i].value = atomic_read(&dev->counts[i]); + stats->data[i].type = dev->types[i]; } - stats.count = dev->counters; + stats->count = dev->counters; DRM_UNLOCK(); - DRM_COPY_TO_USER_IOCTL( (drm_stats_t *)data, stats, sizeof(stats) ); - return 0; } #define DRM_IF_MAJOR 1 #define DRM_IF_MINOR 2 -int drm_setversion(DRM_IOCTL_ARGS) +int drm_setversion(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; - drm_set_version_t sv; + drm_set_version_t *sv = data; drm_set_version_t retv; int if_version; - DRM_COPY_FROM_USER_IOCTL(sv, (drm_set_version_t *)data, sizeof(sv)); - retv.drm_di_major = DRM_IF_MAJOR; retv.drm_di_minor = DRM_IF_MINOR; retv.drm_dd_major = dev->driver.major; retv.drm_dd_minor = dev->driver.minor; - DRM_COPY_TO_USER_IOCTL((drm_set_version_t *)data, retv, sizeof(sv)); - - if (sv.drm_di_major != -1) { - if (sv.drm_di_major != DRM_IF_MAJOR || - sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR) + if (sv->drm_di_major != -1) { + if (sv->drm_di_major != DRM_IF_MAJOR || + sv->drm_di_minor < 0 || sv->drm_di_minor > DRM_IF_MINOR) { return EINVAL; - if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_dd_minor); + } + if_version = DRM_IF_VERSION(sv->drm_di_major, + sv->drm_dd_minor); dev->if_version = DRM_MAX(if_version, dev->if_version); - if (sv.drm_di_minor >= 1) { + if (sv->drm_di_minor >= 1) { /* * Version 1.1 includes tying of DRM to specific device */ @@ -278,16 +254,20 @@ int drm_setversion(DRM_IOCTL_ARGS) } } - if (sv.drm_dd_major != -1) { - if (sv.drm_dd_major != dev->driver.major || - sv.drm_dd_minor < 0 || sv.drm_dd_minor > dev->driver.minor) + if (sv->drm_dd_major != -1) { + if (sv->drm_dd_major != dev->driver.major || + sv->drm_dd_minor < 0 || + sv->drm_dd_minor > dev->driver.minor) + { return EINVAL; + } } + return 0; } -int drm_noop(DRM_IOCTL_ARGS) +int drm_noop(drm_device_t *dev, void *data, struct drm_file *file_priv) { DRM_DEBUG("\n"); return 0; -- 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_ioctl.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bsd-core/drm_ioctl.c') diff --git a/bsd-core/drm_ioctl.c b/bsd-core/drm_ioctl.c index ebdb2140..328f1d1e 100644 --- a/bsd-core/drm_ioctl.c +++ b/bsd-core/drm_ioctl.c @@ -1,6 +1,3 @@ -/* drm_ioctl.h -- IOCTL processing for DRM -*- linux-c -*- - * Created: Fri Jan 8 09:01:26 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_ioctl.c + * Varios minor DRM ioctls not applicable to other files, such as versioning + * information and reporting DRM information to userland. + */ + #include "drmP.h" /* -- cgit v1.2.3 From 56133e04de40e3004018d069cb229e62ee10e0f4 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 15 Aug 2007 11:04:56 -0700 Subject: BSD: Fix regression in setversion ioctl (current version not returned). --- bsd-core/drm_ioctl.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'bsd-core/drm_ioctl.c') diff --git a/bsd-core/drm_ioctl.c b/bsd-core/drm_ioctl.c index 328f1d1e..d6af4284 100644 --- a/bsd-core/drm_ioctl.c +++ b/bsd-core/drm_ioctl.c @@ -232,23 +232,27 @@ int drm_getstats(drm_device_t *dev, void *data, struct drm_file *file_priv) int drm_setversion(drm_device_t *dev, void *data, struct drm_file *file_priv) { drm_set_version_t *sv = data; - drm_set_version_t retv; + drm_set_version_t ver; int if_version; - retv.drm_di_major = DRM_IF_MAJOR; - retv.drm_di_minor = DRM_IF_MINOR; - retv.drm_dd_major = dev->driver.major; - retv.drm_dd_minor = dev->driver.minor; - - if (sv->drm_di_major != -1) { - if (sv->drm_di_major != DRM_IF_MAJOR || - sv->drm_di_minor < 0 || sv->drm_di_minor > DRM_IF_MINOR) { + /* Save the incoming data, and set the response before continuing + * any further. + */ + ver = *sv; + sv->drm_di_major = DRM_IF_MAJOR; + sv->drm_di_minor = DRM_IF_MINOR; + sv->drm_dd_major = dev->driver.major; + sv->drm_dd_minor = dev->driver.minor; + + if (ver.drm_di_major != -1) { + if (ver.drm_di_major != DRM_IF_MAJOR || + ver.drm_di_minor < 0 || ver.drm_di_minor > DRM_IF_MINOR) { return EINVAL; } - if_version = DRM_IF_VERSION(sv->drm_di_major, - sv->drm_dd_minor); + if_version = DRM_IF_VERSION(ver.drm_di_major, + ver.drm_dd_minor); dev->if_version = DRM_MAX(if_version, dev->if_version); - if (sv->drm_di_minor >= 1) { + if (ver.drm_di_minor >= 1) { /* * Version 1.1 includes tying of DRM to specific device */ @@ -256,10 +260,10 @@ int drm_setversion(drm_device_t *dev, void *data, struct drm_file *file_priv) } } - if (sv->drm_dd_major != -1) { - if (sv->drm_dd_major != dev->driver.major || - sv->drm_dd_minor < 0 || - sv->drm_dd_minor > dev->driver.minor) + if (ver.drm_dd_major != -1) { + if (ver.drm_dd_major != dev->driver.major || + ver.drm_dd_minor < 0 || + ver.drm_dd_minor > dev->driver.minor) { return EINVAL; } -- cgit v1.2.3 From 4cdd871e90cd5fe440d0a4af5d69f1d84e49e742 Mon Sep 17 00:00:00 2001 From: vehemens Date: Wed, 15 Aug 2007 11:05:44 -0700 Subject: Bug #11989: Fix regression in getstats ioctl (kernel panic). --- bsd-core/drm_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bsd-core/drm_ioctl.c') diff --git a/bsd-core/drm_ioctl.c b/bsd-core/drm_ioctl.c index d6af4284..ce78bb8f 100644 --- a/bsd-core/drm_ioctl.c +++ b/bsd-core/drm_ioctl.c @@ -205,7 +205,7 @@ int drm_getstats(drm_device_t *dev, void *data, struct drm_file *file_priv) drm_stats_t *stats = data; int i; - memset(&stats, 0, sizeof(stats)); + memset(stats, 0, sizeof(drm_stats_t)); DRM_LOCK(); -- cgit v1.2.3