diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2013-03-22 22:51:01 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2013-03-22 22:51:01 +0000 |
commit | a57621ed31af65463ac1fc64f899643ffe948d3d (patch) | |
tree | 3617e9f22d8cd835c15976c916476f3f3df88284 | |
parent | 29f8850a212ba5f77d2e00c22c87df698f6edee0 (diff) |
Move i915_gem_gtt_map_ioctl() from i915_drv.c to i915_gem.c and rename it
to i915_gem_mmap_ioctl().
-rw-r--r-- | sys/dev/pci/drm/i915/i915_drv.c | 55 | ||||
-rw-r--r-- | sys/dev/pci/drm/i915/i915_drv.h | 4 | ||||
-rw-r--r-- | sys/dev/pci/drm/i915/i915_gem.c | 58 |
3 files changed, 60 insertions, 57 deletions
diff --git a/sys/dev/pci/drm/i915/i915_drv.c b/sys/dev/pci/drm/i915/i915_drv.c index 307ea603ebe..f41760c5900 100644 --- a/sys/dev/pci/drm/i915/i915_drv.c +++ b/sys/dev/pci/drm/i915/i915_drv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i915_drv.c,v 1.5 2013/03/22 06:19:56 jsg Exp $ */ +/* $OpenBSD: i915_drv.c,v 1.6 2013/03/22 22:51:00 kettenis Exp $ */ /* * Copyright (c) 2008-2009 Owain G. Ainsworth <oga@openbsd.org> * @@ -1306,7 +1306,7 @@ inteldrm_doioctl(struct drm_device *dev, u_long cmd, caddr_t data, case DRM_IOCTL_I915_GEM_THROTTLE: return (i915_gem_ring_throttle(dev, file_priv)); case DRM_IOCTL_I915_GEM_MMAP: - return (i915_gem_gtt_map_ioctl(dev, data, file_priv)); + return (i915_gem_mmap_ioctl(dev, data, file_priv)); case DRM_IOCTL_I915_GEM_MMAP_GTT: return (i915_gem_mmap_gtt_ioctl(dev, data, file_priv)); case DRM_IOCTL_I915_GEM_CREATE: @@ -1473,57 +1473,6 @@ inteldrm_set_max_obj_size(struct inteldrm_softc *dev_priv) } -int -i915_gem_gtt_map_ioctl(struct drm_device *dev, void *data, - struct drm_file *file_priv) -{ - struct drm_i915_gem_mmap *args = data; - struct drm_obj *obj; - struct drm_i915_gem_object *obj_priv; - vaddr_t addr; - voff_t offset; - vsize_t end, nsize; - int ret; - - obj = drm_gem_object_lookup(dev, file_priv, args->handle); - if (obj == NULL) - return (EBADF); - - /* Since we are doing purely uvm-related operations here we do - * not need to hold the object, a reference alone is sufficient - */ - obj_priv = to_intel_bo(obj); - - /* Check size. Also ensure that the object is not purgeable */ - if (args->size == 0 || args->offset > obj->size || args->size > - obj->size || (args->offset + args->size) > obj->size || - i915_gem_object_is_purgeable(obj_priv)) { - ret = EINVAL; - goto done; - } - - end = round_page(args->offset + args->size); - offset = trunc_page(args->offset); - nsize = end - offset; - - /* - * We give our reference from object_lookup to the mmap, so only - * must free it in the case that the map fails. - */ - addr = 0; - ret = uvm_map(&curproc->p_vmspace->vm_map, &addr, nsize, &obj->uobj, - offset, 0, UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, - UVM_INH_SHARE, UVM_ADV_RANDOM, 0)); - -done: - if (ret == 0) - args->addr_ptr = (uint64_t) addr + (args->offset & PAGE_MASK); - else - drm_unref(&obj->uobj); - - return (ret); -} - struct drm_obj * i915_gem_find_inactive_object(struct inteldrm_softc *dev_priv, size_t min_size) diff --git a/sys/dev/pci/drm/i915/i915_drv.h b/sys/dev/pci/drm/i915/i915_drv.h index 67700df75b1..f5c7322d9d2 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.4 2013/03/22 06:19:56 jsg Exp $ */ +/* $OpenBSD: i915_drv.h,v 1.5 2013/03/22 22:51:00 kettenis Exp $ */ /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*- */ /* @@ -1037,7 +1037,7 @@ int i915_gem_get_aperture_ioctl(struct drm_device *, void *, struct drm_file *); int i915_gem_set_tiling(struct drm_device *, void *, struct drm_file *); int i915_gem_get_tiling(struct drm_device *, void *, struct drm_file *); -int i915_gem_gtt_map_ioctl(struct drm_device *, void *, struct drm_file *); +int i915_gem_mmap_ioctl(struct drm_device *, void *, struct drm_file *); int i915_gem_mmap_gtt_ioctl(struct drm_device *, void *, struct drm_file *); int i915_gem_madvise_ioctl(struct drm_device *, void *, struct drm_file *); int i915_gem_sw_finish_ioctl(struct drm_device *, void *, struct drm_file *); diff --git a/sys/dev/pci/drm/i915/i915_gem.c b/sys/dev/pci/drm/i915/i915_gem.c index 588c78dd5d3..5e6e9b55a2c 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.3 2013/03/22 06:19:56 jsg Exp $ */ +/* $OpenBSD: i915_gem.c,v 1.4 2013/03/22 22:51:00 kettenis Exp $ */ /* * Copyright (c) 2008-2009 Owain G. Ainsworth <oga@openbsd.org> * @@ -675,7 +675,61 @@ unlock: return ret; } -// i915_gem_mmap_ioctl +/** + * Maps the contents of an object, returning the address it is mapped + * into. + * + * While the mapping holds a reference on the contents of the object, it doesn't + * imply a ref on the object itself. + */ +int +i915_gem_mmap_ioctl(struct drm_device *dev, void *data, + struct drm_file *file) +{ + struct drm_i915_gem_mmap *args = data; + struct drm_obj *obj; + vaddr_t addr; + voff_t offset; + vsize_t end, nsize; + int ret; + + obj = drm_gem_object_lookup(dev, file, args->handle); + if (obj == NULL) + return ENOENT; + + /* Since we are doing purely uvm-related operations here we do + * not need to hold the object, a reference alone is sufficient + */ + + /* Check size. Also ensure that the object is not purgeable */ + if (args->size == 0 || args->offset > obj->size || args->size > + obj->size || (args->offset + args->size) > obj->size || + i915_gem_object_is_purgeable(to_intel_bo(obj))) { + ret = EINVAL; + goto done; + } + + end = round_page(args->offset + args->size); + offset = trunc_page(args->offset); + nsize = end - offset; + + /* + * We give our reference from object_lookup to the mmap, so only + * must free it in the case that the map fails. + */ + addr = 0; + ret = uvm_map(&curproc->p_vmspace->vm_map, &addr, nsize, &obj->uobj, + offset, 0, UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, + UVM_INH_SHARE, UVM_ADV_RANDOM, 0)); + +done: + if (ret == 0) + args->addr_ptr = (uint64_t) addr + (args->offset & PAGE_MASK); + else + drm_unref(&obj->uobj); + + return (ret); +} int i915_gem_fault(struct drm_obj *gem_obj, struct uvm_faultinfo *ufi, |