From 33a50412c21229610dbb75dee83f145e2f1ec128 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 18 Jul 2007 14:22:40 -0700 Subject: Add dry-coded DRM drawable private information storage for FreeBSD. With this, all modules build again. --- bsd-core/drm_drawable.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 4 deletions(-) (limited to 'bsd-core/drm_drawable.c') diff --git a/bsd-core/drm_drawable.c b/bsd-core/drm_drawable.c index 379e0aa7..bc3ad571 100644 --- a/bsd-core/drm_drawable.c +++ b/bsd-core/drm_drawable.c @@ -33,19 +33,130 @@ #include "drmP.h" +struct bsd_drm_drawable_info { + struct drm_drawable_info info; + int handle; + RB_ENTRY(bsd_drm_drawable_info) tree; +}; + +static int +drm_drawable_compare(struct bsd_drm_drawable_info *a, + struct bsd_drm_drawable_info *b) +{ + if (a->handle > b->handle) + return 1; + if (a->handle > b->handle) + return -1; + return 0; +} + +RB_GENERATE_STATIC(drawable_tree, bsd_drm_drawable_info, tree, + drm_drawable_compare); + +struct drm_drawable_info * +drm_get_drawable_info(drm_device_t *dev, int handle) +{ + struct bsd_drm_drawable_info find, *result; + + find.handle = handle; + result = RB_FIND(drawable_tree, &dev->drw_head, &find); + + return &result->info; +} + +static struct drm_drawable_info * +drm_drawable_info_alloc(drm_device_t *dev, int handle) +{ + struct bsd_drm_drawable_info *info; + + info = drm_calloc(1, sizeof(struct bsd_drm_drawable_info), + DRM_MEM_DRAWABLE); + if (info == NULL) + return NULL; + + info->handle = handle; + RB_INSERT(drawable_tree, &dev->drw_head, info); + + return &info->info; +} + +static void +drm_drawable_info_free(drm_device_t *dev, struct drm_drawable_info *info) +{ + RB_REMOVE(drawable_tree, &dev->drw_head, + (struct bsd_drm_drawable_info *)info); + drm_free(info, sizeof(struct bsd_drm_drawable_info), DRM_MEM_DRAWABLE); +} + int drm_adddraw(DRM_IOCTL_ARGS) { + DRM_DEVICE; drm_draw_t draw; - draw.handle = 0; /* NOOP */ + draw.handle = alloc_unr(dev->drw_unrhdr); DRM_DEBUG("%d\n", draw.handle); - - DRM_COPY_TO_USER_IOCTL( (drm_draw_t *)data, draw, sizeof(draw) ); + + DRM_COPY_TO_USER_IOCTL((drm_draw_t *)data, draw, sizeof(draw)); return 0; } int drm_rmdraw(DRM_IOCTL_ARGS) { - return 0; /* NOOP */ + DRM_DEVICE; + drm_draw_t *draw = (drm_draw_t *)data; + struct drm_drawable_info *info; + + free_unr(dev->drw_unrhdr, draw->handle); + + info = drm_get_drawable_info(dev, draw->handle); + if (info != NULL) { + drm_drawable_info_free(dev, info); + } + + return 0; +} + +int drm_update_draw(DRM_IOCTL_ARGS) +{ + DRM_DEVICE; + struct drm_drawable_info *info; + struct drm_update_draw *update = (struct drm_update_draw *)data; + + info = drm_get_drawable_info(dev, update->handle); + if (info == NULL) { + info = drm_drawable_info_alloc(dev, update->handle); + if (info == NULL) + return ENOMEM; + } + + switch (update->type) { + case DRM_DRAWABLE_CLIPRECTS: + DRM_SPINLOCK(&dev->drw_lock); + if (update->num != info->num_rects) { + drm_free(info->rects, + sizeof(*info->rects) * info->num_rects, + DRM_MEM_DRAWABLE); + info->rects = NULL; + info->num_rects = 0; + } + if (update->num == 0) { + DRM_SPINUNLOCK(&dev->drw_lock); + return 0; + } + if (info->rects == NULL) { + info->rects = drm_alloc(sizeof(*info->rects) * + update->num, DRM_MEM_DRAWABLE); + if (info->rects == NULL) + return ENOMEM; + info->num_rects = update->num; + } + /* For some reason the pointer arg is unsigned long long. */ + copyin((void *)(intptr_t)update->data, info->rects, + sizeof(*info->rects) * info->num_rects); + DRM_SPINUNLOCK(&dev->drw_lock); + return 0; + default: + return EINVAL; + } } -- cgit v1.2.3 From e544286eae71a6b150af4d86096895c14e42c36e Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 19 Jul 2007 06:17:58 -0700 Subject: FreeBSD: Fix the recently added drawable add/remove/update code. --- bsd-core/drm_drawable.c | 56 ++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) (limited to 'bsd-core/drm_drawable.c') diff --git a/bsd-core/drm_drawable.c b/bsd-core/drm_drawable.c index bc3ad571..ad25a6df 100644 --- a/bsd-core/drm_drawable.c +++ b/bsd-core/drm_drawable.c @@ -64,36 +64,23 @@ drm_get_drawable_info(drm_device_t *dev, int handle) return &result->info; } -static struct drm_drawable_info * -drm_drawable_info_alloc(drm_device_t *dev, int handle) +int drm_adddraw(DRM_IOCTL_ARGS) { + DRM_DEVICE; + drm_draw_t draw; struct bsd_drm_drawable_info *info; info = drm_calloc(1, sizeof(struct bsd_drm_drawable_info), DRM_MEM_DRAWABLE); if (info == NULL) - return NULL; + return ENOMEM; - info->handle = handle; + info->handle = alloc_unr(dev->drw_unrhdr); + DRM_SPINLOCK(&dev->drw_lock); RB_INSERT(drawable_tree, &dev->drw_head, info); + draw.handle = info->handle; + DRM_SPINUNLOCK(&dev->drw_lock); - return &info->info; -} - -static void -drm_drawable_info_free(drm_device_t *dev, struct drm_drawable_info *info) -{ - RB_REMOVE(drawable_tree, &dev->drw_head, - (struct bsd_drm_drawable_info *)info); - drm_free(info, sizeof(struct bsd_drm_drawable_info), DRM_MEM_DRAWABLE); -} - -int drm_adddraw(DRM_IOCTL_ARGS) -{ - DRM_DEVICE; - drm_draw_t draw; - - draw.handle = alloc_unr(dev->drw_unrhdr); DRM_DEBUG("%d\n", draw.handle); DRM_COPY_TO_USER_IOCTL((drm_draw_t *)data, draw, sizeof(draw)); @@ -107,14 +94,19 @@ int drm_rmdraw(DRM_IOCTL_ARGS) drm_draw_t *draw = (drm_draw_t *)data; struct drm_drawable_info *info; - free_unr(dev->drw_unrhdr, draw->handle); - + DRM_SPINLOCK(&dev->drw_lock); info = drm_get_drawable_info(dev, draw->handle); if (info != NULL) { - drm_drawable_info_free(dev, info); + RB_REMOVE(drawable_tree, &dev->drw_head, + (struct bsd_drm_drawable_info *)info); + DRM_SPINUNLOCK(&dev->drw_lock); + free_unr(dev->drw_unrhdr, draw->handle); + drm_free(info, sizeof(struct bsd_drm_drawable_info), + DRM_MEM_DRAWABLE); + } else { + DRM_SPINUNLOCK(&dev->drw_lock); + return EINVAL; } - - return 0; } int drm_update_draw(DRM_IOCTL_ARGS) @@ -122,13 +114,11 @@ int drm_update_draw(DRM_IOCTL_ARGS) DRM_DEVICE; struct drm_drawable_info *info; struct drm_update_draw *update = (struct drm_update_draw *)data; + int ret; info = drm_get_drawable_info(dev, update->handle); - if (info == NULL) { - info = drm_drawable_info_alloc(dev, update->handle); - if (info == NULL) - return ENOMEM; - } + if (info == NULL) + return EINVAL; switch (update->type) { case DRM_DRAWABLE_CLIPRECTS: @@ -152,10 +142,10 @@ int drm_update_draw(DRM_IOCTL_ARGS) info->num_rects = update->num; } /* For some reason the pointer arg is unsigned long long. */ - copyin((void *)(intptr_t)update->data, info->rects, + ret = copyin((void *)(intptr_t)update->data, info->rects, sizeof(*info->rects) * info->num_rects); DRM_SPINUNLOCK(&dev->drw_lock); - return 0; + return ret; default: return EINVAL; } -- cgit v1.2.3 From f4e1c1d05cfbd43ac429ab6dc78345ffa3599b7a Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 19 Jul 2007 06:46:13 -0700 Subject: FreeBSD warnings cleanup. --- bsd-core/drm_drawable.c | 1 + 1 file changed, 1 insertion(+) (limited to 'bsd-core/drm_drawable.c') diff --git a/bsd-core/drm_drawable.c b/bsd-core/drm_drawable.c index ad25a6df..b81d0a75 100644 --- a/bsd-core/drm_drawable.c +++ b/bsd-core/drm_drawable.c @@ -103,6 +103,7 @@ int drm_rmdraw(DRM_IOCTL_ARGS) free_unr(dev->drw_unrhdr, draw->handle); drm_free(info, sizeof(struct bsd_drm_drawable_info), DRM_MEM_DRAWABLE); + return 0; } else { DRM_SPINUNLOCK(&dev->drw_lock); 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_drawable.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'bsd-core/drm_drawable.c') diff --git a/bsd-core/drm_drawable.c b/bsd-core/drm_drawable.c index b81d0a75..14a29407 100644 --- a/bsd-core/drm_drawable.c +++ b/bsd-core/drm_drawable.c @@ -64,10 +64,9 @@ drm_get_drawable_info(drm_device_t *dev, int handle) return &result->info; } -int drm_adddraw(DRM_IOCTL_ARGS) +int drm_adddraw(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; - drm_draw_t draw; + drm_draw_t *draw = data; struct bsd_drm_drawable_info *info; info = drm_calloc(1, sizeof(struct bsd_drm_drawable_info), @@ -78,19 +77,16 @@ int drm_adddraw(DRM_IOCTL_ARGS) info->handle = alloc_unr(dev->drw_unrhdr); DRM_SPINLOCK(&dev->drw_lock); RB_INSERT(drawable_tree, &dev->drw_head, info); - draw.handle = info->handle; + draw->handle = info->handle; DRM_SPINUNLOCK(&dev->drw_lock); - DRM_DEBUG("%d\n", draw.handle); - - DRM_COPY_TO_USER_IOCTL((drm_draw_t *)data, draw, sizeof(draw)); + DRM_DEBUG("%d\n", draw->handle); return 0; } -int drm_rmdraw(DRM_IOCTL_ARGS) +int drm_rmdraw(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; drm_draw_t *draw = (drm_draw_t *)data; struct drm_drawable_info *info; @@ -110,9 +106,8 @@ int drm_rmdraw(DRM_IOCTL_ARGS) } } -int drm_update_draw(DRM_IOCTL_ARGS) +int drm_update_draw(drm_device_t *dev, void *data, struct drm_file *file_priv) { - DRM_DEVICE; struct drm_drawable_info *info; struct drm_update_draw *update = (struct drm_update_draw *)data; int ret; -- cgit v1.2.3 From be3099f26547f48066bbdd7a36578b54da9170b4 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Sun, 22 Jul 2007 09:51:34 +0100 Subject: Fix copy'n'paste-o in FreeBSD drawable code. --- bsd-core/drm_drawable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bsd-core/drm_drawable.c') diff --git a/bsd-core/drm_drawable.c b/bsd-core/drm_drawable.c index 14a29407..7e038ab9 100644 --- a/bsd-core/drm_drawable.c +++ b/bsd-core/drm_drawable.c @@ -45,7 +45,7 @@ drm_drawable_compare(struct bsd_drm_drawable_info *a, { if (a->handle > b->handle) return 1; - if (a->handle > b->handle) + if (a->handle < b->handle) return -1; 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_drawable.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bsd-core/drm_drawable.c') diff --git a/bsd-core/drm_drawable.c b/bsd-core/drm_drawable.c index 7e038ab9..fb318d47 100644 --- a/bsd-core/drm_drawable.c +++ b/bsd-core/drm_drawable.c @@ -1,6 +1,3 @@ -/* drm_drawable.h -- IOCTLs for drawables -*- 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_drawable.c + * This file implements ioctls to store information along with DRM drawables, + * such as the current set of cliprects for vblank-synced buffer swaps. + */ + #include "drmP.h" struct bsd_drm_drawable_info { -- cgit v1.2.3