From 1964046db393a7a301eb7b6135069ec66f125e90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Tigeot?= Date: Fri, 28 Nov 2014 17:08:11 +0100 Subject: [PATCH] drm: Add linux/shmem_fs.h shmem_read_mapping_page() is part of the public Linux API. Make it accessible from linux/shmem_fs.h --- sys/conf/files | 1 + sys/dev/drm/drm/Makefile | 1 + sys/dev/drm/i915/i915_gem.c | 34 +------------- sys/dev/drm/include/linux/shmem_fs.h | 39 ++++++++++++++++ sys/dev/drm/linux_shmem.c | 67 ++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 33 deletions(-) create mode 100644 sys/dev/drm/include/linux/shmem_fs.h create mode 100644 sys/dev/drm/linux_shmem.c diff --git a/sys/conf/files b/sys/conf/files index 376f03271c..4f74f90d72 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1852,6 +1852,7 @@ dev/drm/drm_scatter.c optional drm dev/drm/drm_stub.c optional drm dev/drm/drm_sysctl.c optional drm dev/drm/drm_vm.c optional drm +dev/drm/linux_shmem.c optional drm dev/drm/ttm/ttm_lock.c optional drm dev/drm/ttm/ttm_object.c optional drm dev/drm/ttm/ttm_tt.c optional drm diff --git a/sys/dev/drm/drm/Makefile b/sys/dev/drm/drm/Makefile index e4453c9b58..a62df84300 100644 --- a/sys/dev/drm/drm/Makefile +++ b/sys/dev/drm/drm/Makefile @@ -31,6 +31,7 @@ SRCS = \ drm_stub.c \ drm_sysctl.c \ drm_vm.c \ + linux_shmem.c \ ttm_lock.c \ ttm_object.c \ ttm_tt.c \ diff --git a/sys/dev/drm/i915/i915_gem.c b/sys/dev/drm/i915/i915_gem.c index 9f6b472cb9..30442b3693 100644 --- a/sys/dev/drm/i915/i915_gem.c +++ b/sys/dev/drm/i915/i915_gem.c @@ -59,7 +59,7 @@ #include #include "i915_drv.h" #include "intel_drv.h" -#include "intel_ringbuffer.h" +#include #include #include #include @@ -104,7 +104,6 @@ static inline void i915_gem_object_fence_lost(struct drm_i915_gem_object *obj) static int i915_gem_object_is_purgeable(struct drm_i915_gem_object *obj); static bool i915_gem_object_is_inactive(struct drm_i915_gem_object *obj); static int i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj); -static vm_page_t shmem_read_mapping_page(vm_object_t, vm_pindex_t); static void i915_gem_reset_fences(struct drm_device *dev); static void i915_gem_lowmem(void *arg); @@ -4013,37 +4012,6 @@ i915_gem_assert_pages_not_mapped(struct drm_device *dev, vm_page_t *ma, } #endif -#define VM_OBJECT_LOCK_ASSERT_OWNED(object) - -static vm_page_t -shmem_read_mapping_page(vm_object_t object, vm_pindex_t pindex) -{ - vm_page_t m; - int rv; - - VM_OBJECT_LOCK_ASSERT_OWNED(object); - m = vm_page_grab(object, pindex, VM_ALLOC_NORMAL | VM_ALLOC_RETRY); - if (m->valid != VM_PAGE_BITS_ALL) { - if (vm_pager_has_page(object, pindex)) { - rv = vm_pager_get_page(object, &m, 1); - m = vm_page_lookup(object, pindex); - if (m == NULL) - return ERR_PTR(-ENOMEM); - if (rv != VM_PAGER_OK) { - vm_page_free(m); - return ERR_PTR(-ENOMEM); - } - } else { - pmap_zero_page(VM_PAGE_TO_PHYS(m)); - m->valid = VM_PAGE_BITS_ALL; - m->dirty = 0; - } - } - vm_page_wire(m); - vm_page_wakeup(m); - return (m); -} - static int i915_gpu_is_active(struct drm_device *dev) { diff --git a/sys/dev/drm/include/linux/shmem_fs.h b/sys/dev/drm/include/linux/shmem_fs.h new file mode 100644 index 0000000000..d33bfc7bf0 --- /dev/null +++ b/sys/dev/drm/include/linux/shmem_fs.h @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2011 The FreeBSD Foundation + * Copyright (c) 2014 François Tigeot + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef _LINUX_SHMEM_FS_H_ +#define _LINUX_SHMEM_FS_H_ + +#define VM_OBJECT_LOCK_ASSERT_OWNED(object) + +vm_page_t shmem_read_mapping_page(vm_object_t, vm_pindex_t); + +#endif /* _LINUX_SHMEM_FS_H_ */ diff --git a/sys/dev/drm/linux_shmem.c b/sys/dev/drm/linux_shmem.c new file mode 100644 index 0000000000..5ee410d43e --- /dev/null +++ b/sys/dev/drm/linux_shmem.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2011 The FreeBSD Foundation + * Copyright (c) 2014 François Tigeot + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include +#include +#include +#include + +#include +#include + +vm_page_t +shmem_read_mapping_page(vm_object_t object, vm_pindex_t pindex) +{ + vm_page_t m; + int rv; + + VM_OBJECT_LOCK_ASSERT_OWNED(object); + m = vm_page_grab(object, pindex, VM_ALLOC_NORMAL | VM_ALLOC_RETRY); + if (m->valid != VM_PAGE_BITS_ALL) { + if (vm_pager_has_page(object, pindex)) { + rv = vm_pager_get_page(object, &m, 1); + m = vm_page_lookup(object, pindex); + if (m == NULL) + return ERR_PTR(-ENOMEM); + if (rv != VM_PAGER_OK) { + vm_page_free(m); + return ERR_PTR(-ENOMEM); + } + } else { + pmap_zero_page(VM_PAGE_TO_PHYS(m)); + m->valid = VM_PAGE_BITS_ALL; + m->dirty = 0; + } + } + vm_page_wire(m); + vm_page_wakeup(m); + return (m); +} -- 2.41.0