diff options
-rw-r--r-- | sys/dev/pci/drm/drm_crtc.c | 48 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_linux.c | 40 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_linux.h | 96 | ||||
-rw-r--r-- | sys/dev/pci/drm/files.drm | 3 | ||||
-rw-r--r-- | sys/dev/pci/drm/i915/i915_drv.h | 8 | ||||
-rw-r--r-- | sys/dev/pci/drm/i915/i915_gem.c | 106 | ||||
-rw-r--r-- | sys/dev/pci/drm/i915/i915_gem_execbuffer.c | 14 | ||||
-rw-r--r-- | sys/dev/pci/drm/ttm/ttm_bo_vm.c | 10 |
8 files changed, 175 insertions, 150 deletions
diff --git a/sys/dev/pci/drm/drm_crtc.c b/sys/dev/pci/drm/drm_crtc.c index 1cd1734167a..596cc690707 100644 --- a/sys/dev/pci/drm/drm_crtc.c +++ b/sys/dev/pci/drm/drm_crtc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_crtc.c,v 1.12 2015/02/12 02:12:02 kettenis Exp $ */ +/* $OpenBSD: drm_crtc.c,v 1.13 2015/04/05 11:53:53 kettenis Exp $ */ /* * Copyright (c) 2006-2008 Intel Corporation * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> @@ -1572,8 +1572,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; list_for_each_entry(mode, &connector->modes, head) { drm_crtc_convert_to_umode(&u_mode, mode); - if (copyout(&u_mode, mode_ptr + copied, - sizeof(u_mode)) != 0) { + if (copy_to_user(mode_ptr + copied, + &u_mode, sizeof(u_mode))) { ret = -EFAULT; goto out; } @@ -1765,9 +1765,9 @@ int drm_mode_getplane(struct drm_device *dev, void *data, if (plane->format_count && (plane_resp->count_format_types >= plane->format_count)) { format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr; - if (copyout(format_ptr, - plane->format_types, - sizeof(uint32_t) * plane->format_count)) { + if (copy_to_user(format_ptr, + plane->format_types, + sizeof(uint32_t) * plane->format_count)) { ret = -EFAULT; goto out; } @@ -2575,9 +2575,8 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev, goto out_err1; } - ret = copyin(clips_ptr, clips, - num_clips * sizeof(*clips)); - + ret = copy_from_user(clips, clips_ptr, + num_clips * sizeof(*clips)); if (ret) { ret = -EFAULT; goto out_err2; @@ -3080,7 +3079,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev, if ((out_resp->count_values >= value_count) && value_count) { values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr; for (i = 0; i < value_count; i++) { - if (copyout(&property->values[i], values_ptr + i, sizeof(uint64_t)) != 0) { + if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) { ret = -EFAULT; goto done; } @@ -3094,16 +3093,13 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev, enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr; list_for_each_entry(prop_enum, &property->enum_blob_list, head) { - if (copyout(&prop_enum->value, - &enum_ptr[copied].value, - sizeof(uint64_t)) != 0) { + if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) { ret = -EFAULT; goto done; } - if (copyout(&prop_enum->name, - &enum_ptr[copied].name, - DRM_PROP_NAME_LEN) != 0) { + if (copy_to_user(&enum_ptr[copied].name, + &prop_enum->name, DRM_PROP_NAME_LEN)) { ret = -EFAULT; goto done; } @@ -3201,7 +3197,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev, if (out_resp->length == blob->length) { blob_ptr = (void __user *)(unsigned long)out_resp->data; - if (copyout(blob->data, blob_ptr, blob->length) != 0) { + if (copy_to_user(blob_ptr, blob->data, blob->length)){ ret = -EFAULT; goto done; } @@ -3528,22 +3524,19 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev, size = crtc_lut->gamma_size * (sizeof(uint16_t)); r_base = crtc->gamma_store; - if (copyin((void __user *)(unsigned long)crtc_lut->red, - r_base, size) != 0) { + if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) { ret = -EFAULT; goto out; } g_base = r_base + size; - if (copyin((void __user *)(unsigned long)crtc_lut->green, - g_base, size) != 0) { + if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) { ret = -EFAULT; goto out; } b_base = g_base + size; - if (copyin((void __user *)(unsigned long)crtc_lut->blue, - b_base, size) != 0) { + if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { ret = -EFAULT; goto out; } @@ -3585,22 +3578,19 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev, size = crtc_lut->gamma_size * (sizeof(uint16_t)); r_base = crtc->gamma_store; - if (copyout(r_base, - (void __user *)(unsigned long)crtc_lut->red, size) != 0) { + if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) { ret = -EFAULT; goto out; } g_base = r_base + size; - if (copyout(g_base, - (void __user *)(unsigned long)crtc_lut->green, size) != 0) { + if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) { ret = -EFAULT; goto out; } b_base = g_base + size; - if (copyout(b_base, - (void __user *)(unsigned long)crtc_lut->blue, size) != 0) { + if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { ret = -EFAULT; goto out; } diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c new file mode 100644 index 00000000000..b269bc718b0 --- /dev/null +++ b/sys/dev/pci/drm/drm_linux.c @@ -0,0 +1,40 @@ +/* $OpenBSD: drm_linux.c,v 1.1 2015/04/05 11:53:53 kettenis Exp $ */ +/* + * Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <dev/pci/drm/drmP.h> + +struct timespec +ns_to_timespec(const int64_t nsec) +{ + struct timespec ts; + int32_t rem; + + if (nsec == 0) { + ts.tv_sec = 0; + ts.tv_nsec = 0; + return (ts); + } + + ts.tv_sec = nsec / NSEC_PER_SEC; + rem = nsec % NSEC_PER_SEC; + if (rem < 0) { + ts.tv_sec--; + rem += NSEC_PER_SEC; + } + ts.tv_nsec = rem; + return (ts); +} diff --git a/sys/dev/pci/drm/drm_linux.h b/sys/dev/pci/drm/drm_linux.h index 997ff55ba7c..c1c30c027b2 100644 --- a/sys/dev/pci/drm/drm_linux.h +++ b/sys/dev/pci/drm/drm_linux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.h,v 1.8 2015/04/03 13:10:59 jsg Exp $ */ +/* $OpenBSD: drm_linux.h,v 1.9 2015/04/05 11:53:53 kettenis Exp $ */ /* * Copyright (c) 2013, 2014 Mark Kettenis * @@ -109,6 +109,66 @@ spin_unlock_irqrestore(struct mutex *mtxp, __unused unsigned long flags) #define write_lock(rwl) rw_enter_write(rwl) #define write_unlock(rwl) rw_exit_write(rwl) + +#define NSEC_PER_SEC 1000000000L + +extern struct timespec ns_to_timespec(const int64_t); + +static inline int64_t +timespec_to_ns(const struct timespec *ts) +{ + return ((ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec); +} + +static inline int +timespec_to_jiffies(const struct timespec *ts) +{ + long long to_ticks; + + to_ticks = (long long)hz * ts->tv_sec + ts->tv_nsec / (tick * 1000); + if (to_ticks > INT_MAX) + to_ticks = INT_MAX; + + return ((int)to_ticks); +} + +static inline int +timespec_valid(const struct timespec *ts) +{ + if (ts->tv_sec < 0 || ts->tv_sec > 100000000 || + ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000) + return (0); + return (1); +} + +static inline unsigned long +__copy_to_user(void *to, const void *from, unsigned len) +{ + if (copyout(from, to, len)) + return len; + return 0; +} + +static inline unsigned long +copy_to_user(void *to, const void *from, unsigned len) +{ + return __copy_to_user(to, from, len); +} + +static inline unsigned long +__copy_from_user(void *to, const void *from, unsigned len) +{ + if (copyin(from, to, len)) + return len; + return 0; +} + +static inline unsigned long +copy_from_user(void *to, const void *from, unsigned len) +{ + return __copy_from_user(to, from, len); +} + #if defined(__i386__) || defined(__amd64__) static inline void @@ -156,4 +216,38 @@ kunmap_atomic(void *addr) #endif } +static inline unsigned long +__copy_to_user_inatomic(void *to, const void *from, unsigned len) +{ + struct cpu_info *ci = curcpu(); + int inatomic = ci->ci_inatomic; + int error; + + ci->ci_inatomic = 1; + error = copyout(from, to, len); + ci->ci_inatomic = inatomic; + + return (error ? len : 0); +} + +static inline unsigned long +__copy_from_user_inatomic(void *to, const void *from, unsigned len) +{ + struct cpu_info *ci = curcpu(); + int inatomic = ci->ci_inatomic; + int error; + + ci->ci_inatomic = 1; + error = copyin(from, to, len); + ci->ci_inatomic = inatomic; + + return (error ? len : 0); +} + +static inline unsigned long +__copy_from_user_inatomic_nocache(void *to, const void *from, unsigned len) +{ + return __copy_from_user_inatomic(to, from, len); +} + #endif diff --git a/sys/dev/pci/drm/files.drm b/sys/dev/pci/drm/files.drm index 0ab4d55a2c8..3d9c3c02d79 100644 --- a/sys/dev/pci/drm/files.drm +++ b/sys/dev/pci/drm/files.drm @@ -1,5 +1,5 @@ # $NetBSD: files.drm,v 1.2 2007/03/28 11:29:37 jmcneill Exp $ -# $OpenBSD: files.drm,v 1.31 2014/03/09 07:42:29 jsg Exp $ +# $OpenBSD: files.drm,v 1.32 2015/04/05 11:53:53 kettenis Exp $ # direct rendering modules define drmbase {[console = -1]} @@ -18,6 +18,7 @@ file dev/pci/drm/drm_crtc_helper.c drm file dev/pci/drm/drm_edid.c drm file dev/pci/drm/drm_dp_helper.c drm file dev/pci/drm/drm_fb_helper.c drm +file dev/pci/drm/drm_linux.c drm define ttm file dev/pci/drm/ttm/ttm_agp_backend.c ttm & agp diff --git a/sys/dev/pci/drm/i915/i915_drv.h b/sys/dev/pci/drm/i915/i915_drv.h index a40b14cf4fd..b9f3fb4b04b 100644 --- a/sys/dev/pci/drm/i915/i915_drv.h +++ b/sys/dev/pci/drm/i915/i915_drv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: i915_drv.h,v 1.57 2015/04/03 13:10:59 jsg Exp $ */ +/* $OpenBSD: i915_drv.h,v 1.58 2015/04/05 11:53:53 kettenis Exp $ */ /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*- */ /* @@ -1591,12 +1591,6 @@ i915_gem_object_unpin_fence(struct drm_i915_gem_object *obj) } } -static inline int -i915_gem_object_is_purgeable(struct drm_i915_gem_object *obj) -{ - return obj->madv == I915_MADV_DONTNEED; -} - void i915_gem_retire_requests(struct drm_device *dev); void i915_gem_retire_requests_ring(struct intel_ring_buffer *ring); int __must_check i915_gem_check_wedge(struct drm_i915_private *dev_priv, diff --git a/sys/dev/pci/drm/i915/i915_gem.c b/sys/dev/pci/drm/i915/i915_gem.c index 014d4b3a6a7..617820915fe 100644 --- a/sys/dev/pci/drm/i915/i915_gem.c +++ b/sys/dev/pci/drm/i915/i915_gem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i915_gem.c,v 1.85 2015/02/12 08:48:32 jsg Exp $ */ +/* $OpenBSD: i915_gem.c,v 1.86 2015/04/05 11:53:53 kettenis Exp $ */ /* * Copyright (c) 2008-2009 Owain G. Ainsworth <oga@openbsd.org> * @@ -79,11 +79,6 @@ static void i915_gem_shrink_all(struct drm_i915_private *dev_priv); #endif static void i915_gem_object_truncate(struct drm_i915_gem_object *obj); -static inline int timespec_to_jiffies(const struct timespec *); -static inline int timespec_valid(const struct timespec *); -static struct timespec ns_to_timespec(const int64_t); -static inline int64_t timespec_to_ns(const struct timespec *); - extern int ticks; static inline void i915_gem_object_fence_lost(struct drm_i915_gem_object *obj) @@ -332,27 +327,6 @@ drm_clflush_virt_range(void *addr, size_t len) pmap_flush_cache((vaddr_t)addr, len); } -static inline unsigned long -__copy_to_user(void *to, const void *from, unsigned len) -{ - if (copyout(from, to, len)) - return len; - return 0; -} - -static inline unsigned long -__copy_to_user_inatomic(void *to, const void *from, unsigned len) -{ - struct cpu_info *ci = curcpu(); - int error; - - ci->ci_inatomic = 1; - error = copyout(from, to, len); - ci->ci_inatomic = 0; - - return (error ? len : 0); -} - static inline int __copy_to_user_swizzled(char __user *cpu_vaddr, const char *gpu_vaddr, int gpu_offset, @@ -379,27 +353,6 @@ __copy_to_user_swizzled(char __user *cpu_vaddr, return 0; } -static inline unsigned long -__copy_from_user(void *to, const void *from, unsigned len) -{ - if (copyin(from, to, len)) - return len; - return 0; -} - -static inline unsigned long -__copy_from_user_inatomic_nocache(void *to, const void *from, unsigned len) -{ - struct cpu_info *ci = curcpu(); - int error; - - ci->ci_inatomic = 1; - error = copyin(from, to, len); - ci->ci_inatomic = 0; - - return (error ? len : 0); -} - static inline int __copy_from_user_swizzled(char *gpu_vaddr, int gpu_offset, const char __user *cpu_vaddr, @@ -1832,7 +1785,11 @@ i915_gem_object_truncate(struct drm_i915_gem_object *obj) obj->madv = __I915_MADV_PURGED; } -// i915_gem_object_is_purgeable +static inline int +i915_gem_object_is_purgeable(struct drm_i915_gem_object *obj) +{ + return obj->madv == I915_MADV_DONTNEED; +} static void i915_gem_object_put_pages_gtt(struct drm_i915_gem_object *obj) @@ -4649,54 +4606,3 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) return cnt; } #endif /* notyet */ - -#define NSEC_PER_SEC 1000000000L - -static inline int64_t -timespec_to_ns(const struct timespec *ts) -{ - return ((ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec); -} - -static inline int -timespec_to_jiffies(const struct timespec *ts) -{ - long long to_ticks; - - to_ticks = (long long)hz * ts->tv_sec + ts->tv_nsec / (tick * 1000); - if (to_ticks > INT_MAX) - to_ticks = INT_MAX; - - return ((int)to_ticks); -} - -static struct timespec -ns_to_timespec(const int64_t nsec) -{ - struct timespec ts; - int32_t rem; - - if (nsec == 0) { - ts.tv_sec = 0; - ts.tv_nsec = 0; - return (ts); - } - - ts.tv_sec = nsec / NSEC_PER_SEC; - rem = nsec % NSEC_PER_SEC; - if (rem < 0) { - ts.tv_sec--; - rem += NSEC_PER_SEC; - } - ts.tv_nsec = rem; - return (ts); -} - -static inline int -timespec_valid(const struct timespec *ts) -{ - if (ts->tv_sec < 0 || ts->tv_sec > 100000000 || - ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000) - return (0); - return (1); -} diff --git a/sys/dev/pci/drm/i915/i915_gem_execbuffer.c b/sys/dev/pci/drm/i915/i915_gem_execbuffer.c index 36eb6051a3f..0b4f56765ed 100644 --- a/sys/dev/pci/drm/i915/i915_gem_execbuffer.c +++ b/sys/dev/pci/drm/i915/i915_gem_execbuffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i915_gem_execbuffer.c,v 1.35 2015/02/12 08:48:32 jsg Exp $ */ +/* $OpenBSD: i915_gem_execbuffer.c,v 1.36 2015/04/05 11:53:53 kettenis Exp $ */ /* * Copyright (c) 2008-2009 Owain G. Ainsworth <oga@openbsd.org> * @@ -265,7 +265,7 @@ i915_gem_execbuffer_relocate_object(struct drm_i915_gem_object *obj, count = ARRAY_SIZE(stack_reloc); remain -= count; - if (DRM_COPY_FROM_USER(r, user_relocs, count*sizeof(r[0]))) + if (__copy_from_user_inatomic(r, user_relocs, count*sizeof(r[0]))) return -EFAULT; do { @@ -276,7 +276,7 @@ i915_gem_execbuffer_relocate_object(struct drm_i915_gem_object *obj, return ret; if (r->presumed_offset != offset && - DRM_COPY_TO_USER(&user_relocs->presumed_offset, + __copy_to_user_inatomic(&user_relocs->presumed_offset, &r->presumed_offset, sizeof(r->presumed_offset))) { return -EFAULT; @@ -560,7 +560,7 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev, user_relocs = (void __user *)(uintptr_t)exec[i].relocs_ptr; - if (DRM_COPY_FROM_USER(reloc+total, user_relocs, + if (copy_from_user(reloc+total, user_relocs, exec[i].relocation_count * sizeof(*reloc))) { ret = -EFAULT; mutex_lock(&dev->struct_mutex); @@ -577,7 +577,7 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev, * relocations were valid. */ for (j = 0; j < exec[i].relocation_count; j++) { - if (DRM_COPY_TO_USER(&user_relocs[j].presumed_offset, + if (copy_to_user(&user_relocs[j].presumed_offset, &invalid_offset, sizeof(invalid_offset))) { ret = -EFAULT; @@ -1230,7 +1230,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data, args->buffer_count); return -ENOMEM; } - ret = DRM_COPY_FROM_USER(exec2_list, + ret = copy_from_user(exec2_list, (struct drm_i915_relocation_entry __user *) (uintptr_t) args->buffers_ptr, sizeof(*exec2_list) * args->buffer_count); @@ -1244,7 +1244,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data, ret = i915_gem_do_execbuffer(dev, data, file, args, exec2_list); if (!ret) { /* Copy the new buffer offsets back to the user's exec list. */ - ret = DRM_COPY_TO_USER((void __user *)(uintptr_t)args->buffers_ptr, + ret = copy_to_user((void __user *)(uintptr_t)args->buffers_ptr, exec2_list, sizeof(*exec2_list) * args->buffer_count); if (ret) { diff --git a/sys/dev/pci/drm/ttm/ttm_bo_vm.c b/sys/dev/pci/drm/ttm/ttm_bo_vm.c index b918a0381d3..eda0bbcd567 100644 --- a/sys/dev/pci/drm/ttm/ttm_bo_vm.c +++ b/sys/dev/pci/drm/ttm/ttm_bo_vm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ttm_bo_vm.c,v 1.6 2015/04/03 12:22:55 jsg Exp $ */ +/* $OpenBSD: ttm_bo_vm.c,v 1.7 2015/04/05 11:53:53 kettenis Exp $ */ /************************************************************************** * * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA @@ -434,9 +434,9 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, virtual += page_offset; if (write) - ret = copyin(wbuf, virtual, io_size); + ret = copy_from_user(virtual, wbuf, io_size); else - ret = copyout(virtual, rbuf, io_size); + ret = copy_to_user(rbuf, virtual, io_size); ttm_bo_kunmap(&map); ttm_bo_unreserve(bo); @@ -502,9 +502,9 @@ ssize_t ttm_bo_fbdev_io(struct ttm_buffer_object *bo, const char __user *wbuf, virtual += page_offset; if (write) - ret = copyin(wbuf, virtual, io_size); + ret = copy_from_user(virtual, wbuf, io_size); else - ret = copyout(virtual, rbuf, io_size); + ret = copy_to_user(rbuf, virtual, io_size); ttm_bo_kunmap(&map); ttm_bo_unreserve(bo); |