summaryrefslogtreecommitdiff
path: root/linux-core
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom-at-vmware-dot-com>2009-06-22 23:07:26 +0200
committerThomas Hellstrom <thellstrom-at-vmware-dot-com>2009-06-22 23:37:06 +0200
commit9a33f62be1c478334572ea9384af60c37d1644a0 (patch)
tree96a6f2c36cf6915c9b1a848d0b7979984990968d /linux-core
parent81644198aeced288d26e17fadd8e5eb19798352f (diff)
drm: Strip old ttm.
Signed-off-by: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
Diffstat (limited to 'linux-core')
-rw-r--r--linux-core/Makefile2
-rw-r--r--linux-core/Makefile.kernel7
-rw-r--r--linux-core/drmP.h21
-rw-r--r--linux-core/drm_agpsupport.c171
-rw-r--r--linux-core/drm_bo.c2730
-rw-r--r--linux-core/drm_bo_lock.c189
-rw-r--r--linux-core/drm_bo_move.c614
-rw-r--r--linux-core/drm_compat.c99
-rw-r--r--linux-core/drm_drv.c36
-rw-r--r--linux-core/drm_fence.c829
-rw-r--r--linux-core/drm_fops.c35
-rw-r--r--linux-core/drm_object.c294
-rw-r--r--linux-core/drm_objects.h821
-rw-r--r--linux-core/drm_proc.c102
-rw-r--r--linux-core/drm_stub.c14
-rw-r--r--linux-core/drm_ttm.c512
-rw-r--r--linux-core/drm_vm.c198
-rw-r--r--linux-core/via_buffer.c163
-rw-r--r--linux-core/via_fence.c169
-rw-r--r--linux-core/xgi_cmdlist.c3
-rw-r--r--linux-core/xgi_drv.c11
-rw-r--r--linux-core/xgi_drv.h12
-rw-r--r--linux-core/xgi_fence.c87
23 files changed, 4 insertions, 7115 deletions
diff --git a/linux-core/Makefile b/linux-core/Makefile
index 9257a49b..591b6cfa 100644
--- a/linux-core/Makefile
+++ b/linux-core/Makefile
@@ -58,7 +58,7 @@ endif
# Modules for all architectures
MODULE_LIST := drm.o tdfx.o r128.o radeon.o mga.o sis.o savage.o via.o \
- mach64.o nouveau.o xgi.o
+ mach64.o xgi.o
# Modules only for ix86 architectures
ifneq (,$(findstring 86,$(MACHINE)))
diff --git a/linux-core/Makefile.kernel b/linux-core/Makefile.kernel
index 0bea35dd..e83f15c7 100644
--- a/linux-core/Makefile.kernel
+++ b/linux-core/Makefile.kernel
@@ -12,9 +12,8 @@ drm-objs := drm_auth.o drm_bufs.o drm_context.o drm_dma.o drm_drawable.o \
drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
drm_sysfs.o drm_pci.o drm_agpsupport.o drm_scatter.o \
drm_memory_debug.o ati_pcigart.o drm_sman.o \
- drm_hashtab.o drm_mm.o drm_object.o drm_compat.o \
- drm_fence.o drm_ttm.o drm_bo.o drm_bo_move.o drm_bo_lock.o \
- drm_regman.o drm_vm_nopage_compat.o drm_gem.o
+ drm_hashtab.o drm_mm.o drm_compat.o \
+ drm_vm_nopage_compat.o drm_gem.o
tdfx-objs := tdfx_drv.o
r128-objs := r128_drv.o r128_cce.o r128_state.o r128_irq.o
mga-objs := mga_drv.o mga_dma.o mga_state.o mga_warp.o mga_irq.o
@@ -35,7 +34,7 @@ sis-objs := sis_drv.o sis_mm.o
ffb-objs := ffb_drv.o ffb_context.o
savage-objs := savage_drv.o savage_bci.o savage_state.o
via-objs := via_irq.o via_drv.o via_map.o via_mm.o via_dma.o via_verifier.o \
- via_video.o via_dmablit.o via_fence.o via_buffer.o
+ via_video.o via_dmablit.o
mach64-objs := mach64_drv.o mach64_dma.o mach64_irq.o mach64_state.o
xgi-objs := xgi_cmdlist.o xgi_drv.o xgi_fb.o xgi_misc.o xgi_pcie.o \
xgi_fence.o
diff --git a/linux-core/drmP.h b/linux-core/drmP.h
index 67702825..9b4b071c 100644
--- a/linux-core/drmP.h
+++ b/linux-core/drmP.h
@@ -155,8 +155,6 @@ typedef unsigned long uintptr_t;
#define DRM_MEM_MM 22
#define DRM_MEM_HASHTAB 23
#define DRM_MEM_OBJECTS 24
-#define DRM_MEM_FENCE 25
-#define DRM_MEM_TTM 26
#define DRM_MEM_BUFOBJ 27
#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
@@ -660,8 +658,6 @@ struct drm_gem_object {
void *driver_private;
};
-#include "drm_objects.h"
-
/**
* DRM driver structure. This structure represent the common code for
* a family of cards. There will one drm_device for each card present
@@ -855,10 +851,6 @@ struct drm_device {
struct list_head maplist; /**< Linked list of regions */
int map_count; /**< Number of mappable regions */
struct drm_open_hash map_hash; /**< User token hash table for maps */
- struct drm_mm offset_manager; /**< User token manager */
- struct drm_open_hash object_hash; /**< User token hash table for objects */
- struct address_space *dev_mapping; /**< For unmap_mapping_range() */
- struct page *ttm_dummy_page;
/** \name Context handle management */
/*@{ */
@@ -953,9 +945,6 @@ struct drm_device {
unsigned int agp_buffer_token;
struct drm_minor *primary; /**< render type primary screen head */
- struct drm_fence_manager fm;
- struct drm_buffer_manager bm;
-
/** \name Drawable information */
/*@{ */
spinlock_t drw_lock;
@@ -978,15 +967,6 @@ struct drm_device {
/*@} */
};
-#if __OS_HAS_AGP
-struct drm_agp_ttm_backend {
- struct drm_ttm_backend backend;
- DRM_AGP_MEM *mem;
- struct agp_bridge_data *bridge;
- int populated;
-};
-#endif
-
static __inline__ int drm_core_check_feature(struct drm_device *dev,
int feature)
@@ -1279,7 +1259,6 @@ extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size
extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
-extern struct drm_ttm_backend *drm_agp_init_ttm(struct drm_device *dev);
extern void drm_agp_chipset_flush(struct drm_device *dev);
/* Stub support (drm_stub.h) */
extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
diff --git a/linux-core/drm_agpsupport.c b/linux-core/drm_agpsupport.c
index 2abfac6e..9f746a32 100644
--- a/linux-core/drm_agpsupport.c
+++ b/linux-core/drm_agpsupport.c
@@ -498,177 +498,6 @@ drm_agp_bind_pages(struct drm_device *dev,
}
EXPORT_SYMBOL(drm_agp_bind_pages);
-/*
- * AGP ttm backend interface.
- */
-
-#ifndef AGP_USER_TYPES
-#define AGP_USER_TYPES (1 << 16)
-#define AGP_USER_MEMORY (AGP_USER_TYPES)
-#define AGP_USER_CACHED_MEMORY (AGP_USER_TYPES + 1)
-#endif
-#define AGP_REQUIRED_MAJOR 0
-#define AGP_REQUIRED_MINOR 102
-
-static int drm_agp_needs_unbind_cache_adjust(struct drm_ttm_backend *backend)
-{
- return ((backend->flags & DRM_BE_FLAG_BOUND_CACHED) ? 0 : 1);
-}
-
-
-static int drm_agp_populate(struct drm_ttm_backend *backend,
- unsigned long num_pages, struct page **pages,
- struct page *dummy_read_page)
-{
- struct drm_agp_ttm_backend *agp_be =
- container_of(backend, struct drm_agp_ttm_backend, backend);
- struct page **cur_page, **last_page = pages + num_pages;
- DRM_AGP_MEM *mem;
- int dummy_page_count = 0;
-
- if (drm_alloc_memctl(num_pages * sizeof(void *)))
- return -1;
-
- DRM_DEBUG("drm_agp_populate_ttm\n");
- mem = drm_agp_allocate_memory(agp_be->bridge, num_pages, AGP_USER_MEMORY);
- if (!mem) {
- drm_free_memctl(num_pages * sizeof(void *));
- return -1;
- }
-
- DRM_DEBUG("Current page count is %ld\n", (long) mem->page_count);
- mem->page_count = 0;
- for (cur_page = pages; cur_page < last_page; ++cur_page) {
- struct page *page = *cur_page;
- if (!page) {
- page = dummy_read_page;
- ++dummy_page_count;
- }
- mem->memory[mem->page_count++] = phys_to_gart(page_to_phys(page));
- }
- if (dummy_page_count)
- DRM_DEBUG("Mapped %d dummy pages\n", dummy_page_count);
- agp_be->mem = mem;
- return 0;
-}
-
-static int drm_agp_bind_ttm(struct drm_ttm_backend *backend,
- struct drm_bo_mem_reg *bo_mem)
-{
- struct drm_agp_ttm_backend *agp_be =
- container_of(backend, struct drm_agp_ttm_backend, backend);
- DRM_AGP_MEM *mem = agp_be->mem;
- int ret;
- int snooped = (bo_mem->flags & DRM_BO_FLAG_CACHED) && !(bo_mem->flags & DRM_BO_FLAG_CACHED_MAPPED);
-
- DRM_DEBUG("drm_agp_bind_ttm\n");
- mem->is_flushed = true;
- mem->type = AGP_USER_MEMORY;
- /* CACHED MAPPED implies not snooped memory */
- if (snooped)
- mem->type = AGP_USER_CACHED_MEMORY;
-
- ret = drm_agp_bind_memory(mem, bo_mem->mm_node->start);
- if (ret)
- DRM_ERROR("AGP Bind memory failed\n");
-
- DRM_FLAG_MASKED(backend->flags, (bo_mem->flags & DRM_BO_FLAG_CACHED) ?
- DRM_BE_FLAG_BOUND_CACHED : 0,
- DRM_BE_FLAG_BOUND_CACHED);
- return ret;
-}
-
-static int drm_agp_unbind_ttm(struct drm_ttm_backend *backend)
-{
- struct drm_agp_ttm_backend *agp_be =
- container_of(backend, struct drm_agp_ttm_backend, backend);
-
- DRM_DEBUG("drm_agp_unbind_ttm\n");
- if (agp_be->mem->is_bound)
- return drm_agp_unbind_memory(agp_be->mem);
- else
- return 0;
-}
-
-static void drm_agp_clear_ttm(struct drm_ttm_backend *backend)
-{
- struct drm_agp_ttm_backend *agp_be =
- container_of(backend, struct drm_agp_ttm_backend, backend);
- DRM_AGP_MEM *mem = agp_be->mem;
-
- DRM_DEBUG("drm_agp_clear_ttm\n");
- if (mem) {
- unsigned long num_pages = mem->page_count;
- backend->func->unbind(backend);
- agp_free_memory(mem);
- drm_free_memctl(num_pages * sizeof(void *));
- }
- agp_be->mem = NULL;
-}
-
-static void drm_agp_destroy_ttm(struct drm_ttm_backend *backend)
-{
- struct drm_agp_ttm_backend *agp_be;
-
- if (backend) {
- DRM_DEBUG("drm_agp_destroy_ttm\n");
- agp_be = container_of(backend, struct drm_agp_ttm_backend, backend);
- if (agp_be) {
- if (agp_be->mem)
- backend->func->clear(backend);
- drm_ctl_free(agp_be, sizeof(*agp_be), DRM_MEM_TTM);
- }
- }
-}
-
-static struct drm_ttm_backend_func agp_ttm_backend = {
- .needs_ub_cache_adjust = drm_agp_needs_unbind_cache_adjust,
- .populate = drm_agp_populate,
- .clear = drm_agp_clear_ttm,
- .bind = drm_agp_bind_ttm,
- .unbind = drm_agp_unbind_ttm,
- .destroy = drm_agp_destroy_ttm,
-};
-
-struct drm_ttm_backend *drm_agp_init_ttm(struct drm_device *dev)
-{
-
- struct drm_agp_ttm_backend *agp_be;
- struct agp_kern_info *info;
-
- if (!dev->agp) {
- DRM_ERROR("AGP is not initialized.\n");
- return NULL;
- }
- info = &dev->agp->agp_info;
-
- if (info->version.major != AGP_REQUIRED_MAJOR ||
- info->version.minor < AGP_REQUIRED_MINOR) {
- DRM_ERROR("Wrong agpgart version %d.%d\n"
- "\tYou need at least version %d.%d.\n",
- info->version.major,
- info->version.minor,
- AGP_REQUIRED_MAJOR,
- AGP_REQUIRED_MINOR);
- return NULL;
- }
-
-
- agp_be = drm_ctl_calloc(1, sizeof(*agp_be), DRM_MEM_TTM);
- if (!agp_be)
- return NULL;
-
- agp_be->mem = NULL;
-
- agp_be->bridge = dev->agp->bridge;
- agp_be->populated = false;
- agp_be->backend.func = &agp_ttm_backend;
- agp_be->backend.dev = dev;
-
- return &agp_be->backend;
-}
-EXPORT_SYMBOL(drm_agp_init_ttm);
-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
void drm_agp_chipset_flush(struct drm_device *dev)
{
diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c
deleted file mode 100644
index f43480c5..00000000
--- a/linux-core/drm_bo.c
+++ /dev/null
@@ -1,2730 +0,0 @@
-/**************************************************************************
- *
- * Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-
-/*
- * Locking may look a bit complicated but isn't really:
- *
- * The buffer usage atomic_t needs to be protected by dev->struct_mutex
- * when there is a chance that it can be zero before or after the operation.
- *
- * dev->struct_mutex also protects all lists and list heads,
- * Hash tables and hash heads.
- *
- * bo->mutex protects the buffer object itself excluding the usage field.
- * bo->mutex does also protect the buffer list heads, so to manipulate those,
- * we need both the bo->mutex and the dev->struct_mutex.
- *
- * Locking order is bo->mutex, dev->struct_mutex. Therefore list traversal
- * is a bit complicated. When dev->struct_mutex is released to grab bo->mutex,
- * the list traversal will, in general, need to be restarted.
- *
- */
-
-static void drm_bo_destroy_locked(struct drm_buffer_object *bo);
-static int drm_bo_setup_vm_locked(struct drm_buffer_object *bo);
-static void drm_bo_takedown_vm_locked(struct drm_buffer_object *bo);
-static void drm_bo_unmap_virtual(struct drm_buffer_object *bo);
-
-static inline uint64_t drm_bo_type_flags(unsigned type)
-{
- return (1ULL << (24 + type));
-}
-
-/*
- * bo locked. dev->struct_mutex locked.
- */
-
-void drm_bo_add_to_pinned_lru(struct drm_buffer_object *bo)
-{
- struct drm_mem_type_manager *man;
-
- DRM_ASSERT_LOCKED(&bo->dev->struct_mutex);
- DRM_ASSERT_LOCKED(&bo->mutex);
-
- man = &bo->dev->bm.man[bo->pinned_mem_type];
- list_add_tail(&bo->pinned_lru, &man->pinned);
-}
-
-void drm_bo_add_to_lru(struct drm_buffer_object *bo)
-{
- struct drm_mem_type_manager *man;
-
- DRM_ASSERT_LOCKED(&bo->dev->struct_mutex);
-
- if (!(bo->mem.proposed_flags & (DRM_BO_FLAG_NO_MOVE | DRM_BO_FLAG_NO_EVICT))
- || bo->mem.mem_type != bo->pinned_mem_type) {
- man = &bo->dev->bm.man[bo->mem.mem_type];
- list_add_tail(&bo->lru, &man->lru);
- } else {
- INIT_LIST_HEAD(&bo->lru);
- }
-}
-
-static int drm_bo_vm_pre_move(struct drm_buffer_object *bo, int old_is_pci)
-{
- if (!bo->map_list.map)
- return 0;
-
- drm_bo_unmap_virtual(bo);
- return 0;
-}
-
-/*
- * Call bo->mutex locked.
- */
-
-static int drm_bo_add_ttm(struct drm_buffer_object *bo)
-{
- struct drm_device *dev = bo->dev;
- int ret = 0;
- uint32_t page_flags = 0;
-
- DRM_ASSERT_LOCKED(&bo->mutex);
- bo->ttm = NULL;
-
- if (bo->mem.proposed_flags & DRM_BO_FLAG_WRITE)
- page_flags |= DRM_TTM_PAGE_WRITE;
-
- switch (bo->type) {
- case drm_bo_type_device:
- case drm_bo_type_kernel:
- bo->ttm = drm_ttm_create(dev, bo->num_pages << PAGE_SHIFT,
- page_flags, dev->bm.dummy_read_page);
- if (!bo->ttm)
- ret = -ENOMEM;
- break;
- case drm_bo_type_user:
- bo->ttm = drm_ttm_create(dev, bo->num_pages << PAGE_SHIFT,
- page_flags | DRM_TTM_PAGE_USER,
- dev->bm.dummy_read_page);
- if (!bo->ttm)
- ret = -ENOMEM;
-
- ret = drm_ttm_set_user(bo->ttm, current,
- bo->buffer_start,
- bo->num_pages);
- if (ret)
- return ret;
-
- break;
- default:
- DRM_ERROR("Illegal buffer object type\n");
- ret = -EINVAL;
- break;
- }
-
- return ret;
-}
-
-static int drm_bo_handle_move_mem(struct drm_buffer_object *bo,
- struct drm_bo_mem_reg *mem,
- int evict, int no_wait)
-{
- struct drm_device *dev = bo->dev;
- struct drm_buffer_manager *bm = &dev->bm;
- int old_is_pci = drm_mem_reg_is_pci(dev, &bo->mem);
- int new_is_pci = drm_mem_reg_is_pci(dev, mem);
- struct drm_mem_type_manager *old_man = &bm->man[bo->mem.mem_type];
- struct drm_mem_type_manager *new_man = &bm->man[mem->mem_type];
- int ret = 0;
-
- if (old_is_pci || new_is_pci ||
- ((mem->flags ^ bo->mem.flags) & DRM_BO_FLAG_CACHED))
- ret = drm_bo_vm_pre_move(bo, old_is_pci);
- if (ret)
- return ret;
-
- /*
- * Create and bind a ttm if required.
- */
-
- if (!(new_man->flags & _DRM_FLAG_MEMTYPE_FIXED) && (bo->ttm == NULL)) {
- ret = drm_bo_add_ttm(bo);
- if (ret)
- goto out_err;
-
- if (mem->mem_type != DRM_BO_MEM_LOCAL) {
- ret = drm_ttm_bind(bo->ttm, mem);
- if (ret)
- goto out_err;
- }
-
- if (bo->mem.mem_type == DRM_BO_MEM_LOCAL) {
-
- struct drm_bo_mem_reg *old_mem = &bo->mem;
- uint64_t save_flags = old_mem->flags;
- uint64_t save_proposed_flags = old_mem->proposed_flags;
-
- *old_mem = *mem;
- mem->mm_node = NULL;
- old_mem->proposed_flags = save_proposed_flags;
- DRM_FLAG_MASKED(save_flags, mem->flags,
- DRM_BO_MASK_MEMTYPE);
- goto moved;
- }
-
- }
-
- if (!(old_man->flags & _DRM_FLAG_MEMTYPE_FIXED) &&
- !(new_man->flags & _DRM_FLAG_MEMTYPE_FIXED))
- ret = drm_bo_move_ttm(bo, evict, no_wait, mem);
- else if (dev->driver->bo_driver->move)
- ret = dev->driver->bo_driver->move(bo, evict, no_wait, mem);
- else
- ret = drm_bo_move_memcpy(bo, evict, no_wait, mem);
-
- if (ret)
- goto out_err;
-
-moved:
- if (bo->priv_flags & _DRM_BO_FLAG_EVICTED) {
- ret =
- dev->driver->bo_driver->invalidate_caches(dev,
- bo->mem.flags);
- if (ret)
- DRM_ERROR("Can not flush read caches\n");
- }
-
- DRM_FLAG_MASKED(bo->priv_flags,
- (evict) ? _DRM_BO_FLAG_EVICTED : 0,
- _DRM_BO_FLAG_EVICTED);
-
- if (bo->mem.mm_node)
- bo->offset = (bo->mem.mm_node->start << PAGE_SHIFT) +
- bm->man[bo->mem.mem_type].gpu_offset;
-
-
- return 0;
-
-out_err:
- new_man = &bm->man[bo->mem.mem_type];
- if ((new_man->flags & _DRM_FLAG_MEMTYPE_FIXED) && bo->ttm) {
- drm_ttm_unbind(bo->ttm);
- drm_ttm_destroy(bo->ttm);
- bo->ttm = NULL;
- }
-
- return ret;
-}
-
-/*
- * Call bo->mutex locked.
- * Returns -EBUSY if the buffer is currently rendered to or from. 0 otherwise.
- */
-
-static int drm_bo_busy(struct drm_buffer_object *bo, int check_unfenced)
-{
- struct drm_fence_object *fence = bo->fence;
-
- if (check_unfenced && (bo->priv_flags & _DRM_BO_FLAG_UNFENCED))
- return -EBUSY;
-
- if (fence) {
- if (drm_fence_object_signaled(fence, bo->fence_type)) {
- drm_fence_usage_deref_unlocked(&bo->fence);
- return 0;
- }
- drm_fence_object_flush(fence, DRM_FENCE_TYPE_EXE);
- if (drm_fence_object_signaled(fence, bo->fence_type)) {
- drm_fence_usage_deref_unlocked(&bo->fence);
- return 0;
- }
- return -EBUSY;
- }
- return 0;
-}
-
-static int drm_bo_check_unfenced(struct drm_buffer_object *bo)
-{
- int ret;
-
- mutex_lock(&bo->mutex);
- ret = (bo->priv_flags & _DRM_BO_FLAG_UNFENCED);
- mutex_unlock(&bo->mutex);
- return ret;
-}
-
-
-/*
- * Call bo->mutex locked.
- * Wait until the buffer is idle.
- */
-
-int drm_bo_wait(struct drm_buffer_object *bo, int lazy, int interruptible,
- int no_wait, int check_unfenced)
-{
- int ret;
-
- DRM_ASSERT_LOCKED(&bo->mutex);
- while(unlikely(drm_bo_busy(bo, check_unfenced))) {
- if (no_wait)
- return -EBUSY;
-
- if (check_unfenced && (bo->priv_flags & _DRM_BO_FLAG_UNFENCED)) {
- mutex_unlock(&bo->mutex);
- wait_event(bo->event_queue, !drm_bo_check_unfenced(bo));
- mutex_lock(&bo->mutex);
- bo->priv_flags |= _DRM_BO_FLAG_UNLOCKED;
- }
-
- if (bo->fence) {
- struct drm_fence_object *fence;
- uint32_t fence_type = bo->fence_type;
-
- drm_fence_reference_unlocked(&fence, bo->fence);
- mutex_unlock(&bo->mutex);
-
- ret = drm_fence_object_wait(fence, lazy, !interruptible,
- fence_type);
-
- drm_fence_usage_deref_unlocked(&fence);
- mutex_lock(&bo->mutex);
- bo->priv_flags |= _DRM_BO_FLAG_UNLOCKED;
- if (ret)
- return ret;
- }
-
- }
- return 0;
-}
-EXPORT_SYMBOL(drm_bo_wait);
-
-static int drm_bo_expire_fence(struct drm_buffer_object *bo, int allow_errors)
-{
- struct drm_device *dev = bo->dev;
- struct drm_buffer_manager *bm = &dev->bm;
-
- if (bo->fence) {
- if (bm->nice_mode) {
- unsigned long _end = jiffies + 3 * DRM_HZ;
- int ret;
- do {
- ret = drm_bo_wait(bo, 0, 0, 0, 0);
- if (ret && allow_errors)
- return ret;
-
- } while (ret && !time_after_eq(jiffies, _end));
-
- if (bo->fence) {
- bm->nice_mode = 0;
- DRM_ERROR("Detected GPU lockup or "
- "fence driver was taken down. "
- "Evicting buffer.\n");
- }
- }
- if (bo->fence)
- drm_fence_usage_deref_unlocked(&bo->fence);
- }
- return 0;
-}
-
-/*
- * Call dev->struct_mutex locked.
- * Attempts to remove all private references to a buffer by expiring its
- * fence object and removing from lru lists and memory managers.
- */
-
-static void drm_bo_cleanup_refs(struct drm_buffer_object *bo, int remove_all)
-{
- struct drm_device *dev = bo->dev;
- struct drm_buffer_manager *bm = &dev->bm;
-
- DRM_ASSERT_LOCKED(&dev->struct_mutex);
-
- atomic_inc(&bo->usage);
- mutex_unlock(&dev->struct_mutex);
- mutex_lock(&bo->mutex);
-
- DRM_FLAG_MASKED(bo->priv_flags, 0, _DRM_BO_FLAG_UNFENCED);
-
- if (bo->fence && drm_fence_object_signaled(bo->fence,
- bo->fence_type))
- drm_fence_usage_deref_unlocked(&bo->fence);
-
- if (bo->fence && remove_all)
- (void)drm_bo_expire_fence(bo, 0);
-
- mutex_lock(&dev->struct_mutex);
-
- if (!atomic_dec_and_test(&bo->usage))
- goto out;
-
- if (!bo->fence) {
- list_del_init(&bo->lru);
- if (bo->mem.mm_node) {
- drm_mm_put_block(bo->mem.mm_node);
- if (bo->pinned_node == bo->mem.mm_node)
- bo->pinned_node = NULL;
- bo->mem.mm_node = NULL;
- }
- list_del_init(&bo->pinned_lru);
- if (bo->pinned_node) {
- drm_mm_put_block(bo->pinned_node);
- bo->pinned_node = NULL;
- }
- list_del_init(&bo->ddestroy);
- mutex_unlock(&bo->mutex);
- drm_bo_destroy_locked(bo);
- return;
- }
-
- if (list_empty(&bo->ddestroy)) {
- drm_fence_object_flush(bo->fence, bo->fence_type);
- list_add_tail(&bo->ddestroy, &bm->ddestroy);
- schedule_delayed_work(&bm->wq,
- ((DRM_HZ / 100) < 1) ? 1 : DRM_HZ / 100);
- }
-
-out:
- mutex_unlock(&bo->mutex);
- return;
-}
-
-/*
- * Verify that refcount is 0 and that there are no internal references
- * to the buffer object. Then destroy it.
- */
-
-static void drm_bo_destroy_locked(struct drm_buffer_object *bo)
-{
- struct drm_device *dev = bo->dev;
- struct drm_buffer_manager *bm = &dev->bm;
-
- DRM_ASSERT_LOCKED(&dev->struct_mutex);
-
- if (list_empty(&bo->lru) && bo->mem.mm_node == NULL &&
- list_empty(&bo->pinned_lru) && bo->pinned_node == NULL &&
- list_empty(&bo->ddestroy) && atomic_read(&bo->usage) == 0) {
- if (bo->fence != NULL) {
- DRM_ERROR("Fence was non-zero.\n");
- drm_bo_cleanup_refs(bo, 0);
- return;
- }
-
- if (bo->ttm) {
- drm_ttm_unbind(bo->ttm);
- drm_ttm_destroy(bo->ttm);
- bo->ttm = NULL;
- }
-
- atomic_dec(&bm->count);
-
- drm_ctl_free(bo, sizeof(*bo), DRM_MEM_BUFOBJ);
-
- return;
- }
-
- /*
- * Some stuff is still trying to reference the buffer object.
- * Get rid of those references.
- */
-
- drm_bo_cleanup_refs(bo, 0);
-
- return;
-}
-
-/*
- * Call dev->struct_mutex locked.
- */
-
-static void drm_bo_delayed_delete(struct drm_device *dev, int remove_all)
-{
- struct drm_buffer_manager *bm = &dev->bm;
-
- struct drm_buffer_object *entry, *nentry;
- struct list_head *list, *next;
-
- list_for_each_safe(list, next, &bm->ddestroy) {
- entry = list_entry(list, struct drm_buffer_object, ddestroy);
-
- nentry = NULL;
- if (next != &bm->ddestroy) {
- nentry = list_entry(next, struct drm_buffer_object,
- ddestroy);
- atomic_inc(&nentry->usage);
- }
-
- drm_bo_cleanup_refs(entry, remove_all);
-
- if (nentry)
- atomic_dec(&nentry->usage);
- }
-}
-
-static void drm_bo_delayed_workqueue(struct work_struct *work)
-{
- struct drm_buffer_manager *bm =
- container_of(work, struct drm_buffer_manager, wq.work);
- struct drm_device *dev = container_of(bm, struct drm_device, bm);
-
- DRM_DEBUG("Delayed delete Worker\n");
-
- mutex_lock(&dev->struct_mutex);
- if (!bm->initialized) {
- mutex_unlock(&dev->struct_mutex);
- return;
- }
- drm_bo_delayed_delete(dev, 0);
- if (bm->initialized && !list_empty(&bm->ddestroy)) {
- schedule_delayed_work(&bm->wq,
- ((DRM_HZ / 100) < 1) ? 1 : DRM_HZ / 100);
- }
- mutex_unlock(&dev->struct_mutex);
-}
-
-void drm_bo_usage_deref_locked(struct drm_buffer_object **bo)
-{
- struct drm_buffer_object *tmp_bo = *bo;
- bo = NULL;
-
- DRM_ASSERT_LOCKED(&tmp_bo->dev->struct_mutex);
-
- if (atomic_dec_and_test(&tmp_bo->usage))
- drm_bo_destroy_locked(tmp_bo);
-}
-EXPORT_SYMBOL(drm_bo_usage_deref_locked);
-
-static void drm_bo_base_deref_locked(struct drm_file *file_priv,
- struct drm_user_object *uo)
-{
- struct drm_buffer_object *bo =
- drm_user_object_entry(uo, struct drm_buffer_object, base);
-
- DRM_ASSERT_LOCKED(&bo->dev->struct_mutex);
-
- drm_bo_takedown_vm_locked(bo);
- drm_bo_usage_deref_locked(&bo);
-}
-
-void drm_bo_usage_deref_unlocked(struct drm_buffer_object **bo)
-{
- struct drm_buffer_object *tmp_bo = *bo;
- struct drm_device *dev = tmp_bo->dev;
-
- *bo = NULL;
- if (atomic_dec_and_test(&tmp_bo->usage)) {
- mutex_lock(&dev->struct_mutex);
- if (atomic_read(&tmp_bo->usage) == 0)
- drm_bo_destroy_locked(tmp_bo);
- mutex_unlock(&dev->struct_mutex);
- }
-}
-EXPORT_SYMBOL(drm_bo_usage_deref_unlocked);
-
-void drm_putback_buffer_objects(struct drm_device *dev)
-{
- struct drm_buffer_manager *bm = &dev->bm;
- struct list_head *list = &bm->unfenced;
- struct drm_buffer_object *entry, *next;
-
- mutex_lock(&dev->struct_mutex);
- list_for_each_entry_safe(entry, next, list, lru) {
- atomic_inc(&entry->usage);
- mutex_unlock(&dev->struct_mutex);
-
- mutex_lock(&entry->mutex);
- BUG_ON(!(entry->priv_flags & _DRM_BO_FLAG_UNFENCED));
- mutex_lock(&dev->struct_mutex);
-
- list_del_init(&entry->lru);
- DRM_FLAG_MASKED(entry->priv_flags, 0, _DRM_BO_FLAG_UNFENCED);
- wake_up_all(&entry->event_queue);
-
- /*
- * FIXME: Might want to put back on head of list
- * instead of tail here.
- */
-
- drm_bo_add_to_lru(entry);
- mutex_unlock(&entry->mutex);
- drm_bo_usage_deref_locked(&entry);
- }
- mutex_unlock(&dev->struct_mutex);
-}
-EXPORT_SYMBOL(drm_putback_buffer_objects);
-
-
-/*
- * Note. The caller has to register (if applicable)
- * and deregister fence object usage.
- */
-
-int drm_fence_buffer_objects(struct drm_device *dev,
- struct list_head *list,
- uint32_t fence_flags,
- struct drm_fence_object *fence,
- struct drm_fence_object **used_fence)
-{
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_buffer_object *entry;
- uint32_t fence_type = 0;
- uint32_t fence_class = ~0;
- int count = 0;
- int ret = 0;
- struct list_head *l;
-
- mutex_lock(&dev->struct_mutex);
-
- if (!list)
- list = &bm->unfenced;
-
- if (fence)
- fence_class = fence->fence_class;
-
- list_for_each_entry(entry, list, lru) {
- BUG_ON(!(entry->priv_flags & _DRM_BO_FLAG_UNFENCED));
- fence_type |= entry->new_fence_type;
- if (fence_class == ~0)
- fence_class = entry->new_fence_class;
- else if (entry->new_fence_class != fence_class) {
- DRM_ERROR("Unmatching fence classes on unfenced list: "
- "%d and %d.\n",
- fence_class,
- entry->new_fence_class);
- ret = -EINVAL;
- goto out;
- }
- count++;
- }
-
- if (!count) {
- ret = -EINVAL;
- goto out;
- }
-
- if (fence) {
- if ((fence_type & fence->type) != fence_type ||
- (fence->fence_class != fence_class)) {
- DRM_ERROR("Given fence doesn't match buffers "
- "on unfenced list.\n");
- ret = -EINVAL;
- goto out;
- }
- } else {
- mutex_unlock(&dev->struct_mutex);
- ret = drm_fence_object_create(dev, fence_class, fence_type,
- fence_flags | DRM_FENCE_FLAG_EMIT,
- &fence);
- mutex_lock(&dev->struct_mutex);
- if (ret)
- goto out;
- }
-
- count = 0;
- l = list->next;
- while (l != list) {
- prefetch(l->next);
- entry = list_entry(l, struct drm_buffer_object, lru);
- atomic_inc(&entry->usage);
- mutex_unlock(&dev->struct_mutex);
- mutex_lock(&entry->mutex);
- mutex_lock(&dev->struct_mutex);
- list_del_init(l);
- if (entry->priv_flags & _DRM_BO_FLAG_UNFENCED) {
- count++;
- if (entry->fence)
- drm_fence_usage_deref_locked(&entry->fence);
- entry->fence = drm_fence_reference_locked(fence);
- entry->fence_class = entry->new_fence_class;
- entry->fence_type = entry->new_fence_type;
- DRM_FLAG_MASKED(entry->priv_flags, 0,
- _DRM_BO_FLAG_UNFENCED);
- wake_up_all(&entry->event_queue);
- drm_bo_add_to_lru(entry);
- }
- mutex_unlock(&entry->mutex);
- drm_bo_usage_deref_locked(&entry);
- l = list->next;
- }
- DRM_DEBUG("Fenced %d buffers\n", count);
-out:
- mutex_unlock(&dev->struct_mutex);
- *used_fence = fence;
- return ret;
-}
-EXPORT_SYMBOL(drm_fence_buffer_objects);
-
-/*
- * bo->mutex locked
- */
-
-static int drm_bo_evict(struct drm_buffer_object *bo, unsigned mem_type,
- int no_wait)
-{
- int ret = 0;
- struct drm_device *dev = bo->dev;
- struct drm_bo_mem_reg evict_mem;
-
- /*
- * Someone might have modified the buffer before we took the
- * buffer mutex.
- */
-
- do {
- bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
-
- if (unlikely(bo->mem.flags &
- (DRM_BO_FLAG_NO_MOVE | DRM_BO_FLAG_NO_EVICT)))
- goto out_unlock;
- if (unlikely(bo->priv_flags & _DRM_BO_FLAG_UNFENCED))
- goto out_unlock;
- if (unlikely(bo->mem.mem_type != mem_type))
- goto out_unlock;
- ret = drm_bo_wait(bo, 0, 1, no_wait, 0);
- if (ret)
- goto out_unlock;
-
- } while(bo->priv_flags & _DRM_BO_FLAG_UNLOCKED);
-
- evict_mem = bo->mem;
- evict_mem.mm_node = NULL;
-
- evict_mem = bo->mem;
- evict_mem.proposed_flags = dev->driver->bo_driver->evict_flags(bo);
-
- mutex_lock(&dev->struct_mutex);
- list_del_init(&bo->lru);
- mutex_unlock(&dev->struct_mutex);
-
- ret = drm_bo_mem_space(bo, &evict_mem, no_wait);
-
- if (ret) {
- if (ret != -EAGAIN)
- DRM_ERROR("Failed to find memory space for "
- "buffer 0x%p eviction.\n", bo);
- goto out;
- }
-
- ret = drm_bo_handle_move_mem(bo, &evict_mem, 1, no_wait);
-
- if (ret) {
- if (ret != -EAGAIN)
- DRM_ERROR("Buffer eviction failed\n");
- goto out;
- }
-
- DRM_FLAG_MASKED(bo->priv_flags, _DRM_BO_FLAG_EVICTED,
- _DRM_BO_FLAG_EVICTED);
-
-out:
- mutex_lock(&dev->struct_mutex);
- if (evict_mem.mm_node) {
- if (evict_mem.mm_node != bo->pinned_node)
- drm_mm_put_block(evict_mem.mm_node);
- evict_mem.mm_node = NULL;
- }
- drm_bo_add_to_lru(bo);
- BUG_ON(bo->priv_flags & _DRM_BO_FLAG_UNLOCKED);
-out_unlock:
- mutex_unlock(&dev->struct_mutex);
-
- return ret;
-}
-
-/**
- * Repeatedly evict memory from the LRU for @mem_type until we create enough
- * space, or we've evicted everything and there isn't enough space.
- */
-static int drm_bo_mem_force_space(struct drm_device *dev,
- struct drm_bo_mem_reg *mem,
- uint32_t mem_type, int no_wait)
-{
- struct drm_mm_node *node;
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_buffer_object *entry;
- struct drm_mem_type_manager *man = &bm->man[mem_type];
- struct list_head *lru;
- unsigned long num_pages = mem->num_pages;
- int ret;
-
- mutex_lock(&dev->struct_mutex);
- do {
- node = drm_mm_search_free(&man->manager, num_pages,
- mem->page_alignment, 1);
- if (node)
- break;
-
- lru = &man->lru;
- if (lru->next == lru)
- break;
-
- entry = list_entry(lru->next, struct drm_buffer_object, lru);
- atomic_inc(&entry->usage);
- mutex_unlock(&dev->struct_mutex);
- mutex_lock(&entry->mutex);
- ret = drm_bo_evict(entry, mem_type, no_wait);
- mutex_unlock(&entry->mutex);
- drm_bo_usage_deref_unlocked(&entry);
- if (ret)
- return ret;
- mutex_lock(&dev->struct_mutex);
- } while (1);
-
- if (!node) {
- mutex_unlock(&dev->struct_mutex);
- return -ENOMEM;
- }
-
- node = drm_mm_get_block(node, num_pages, mem->page_alignment);
- if (unlikely(!node)) {
- mutex_unlock(&dev->struct_mutex);
- return -ENOMEM;
- }
-
- mutex_unlock(&dev->struct_mutex);
- mem->mm_node = node;
- mem->mem_type = mem_type;
- return 0;
-}
-
-static int drm_bo_mt_compatible(struct drm_mem_type_manager *man,
- int disallow_fixed,
- uint32_t mem_type,
- uint64_t mask, uint32_t *res_mask)
-{
- uint64_t cur_flags = drm_bo_type_flags(mem_type);
- uint64_t flag_diff;
-
- if ((man->flags & _DRM_FLAG_MEMTYPE_FIXED) && disallow_fixed)
- return 0;
- if (man->flags & _DRM_FLAG_MEMTYPE_CACHED)
- cur_flags |= DRM_BO_FLAG_CACHED;
- if (man->flags & _DRM_FLAG_MEMTYPE_MAPPABLE)
- cur_flags |= DRM_BO_FLAG_MAPPABLE;
- if (man->flags & _DRM_FLAG_MEMTYPE_CSELECT)
- DRM_FLAG_MASKED(cur_flags, mask, DRM_BO_FLAG_CACHED);
-
- if ((cur_flags & mask & DRM_BO_MASK_MEM) == 0)
- return 0;
-
- if (mem_type == DRM_BO_MEM_LOCAL) {
- *res_mask = cur_flags;
- return 1;
- }
-
- flag_diff = (mask ^ cur_flags);
- if (flag_diff & DRM_BO_FLAG_CACHED_MAPPED)
- cur_flags |= DRM_BO_FLAG_CACHED_MAPPED;
-
- if ((flag_diff & DRM_BO_FLAG_CACHED) &&
- (!(mask & DRM_BO_FLAG_CACHED) ||
- (mask & DRM_BO_FLAG_FORCE_CACHING)))
- return 0;
-
- if ((flag_diff & DRM_BO_FLAG_MAPPABLE) &&
- ((mask & DRM_BO_FLAG_MAPPABLE) ||
- (mask & DRM_BO_FLAG_FORCE_MAPPABLE)))
- return 0;
-
- *res_mask = cur_flags;
- return 1;
-}
-
-/**
- * Creates space for memory region @mem according to its type.
- *
- * This function first searches for free space in compatible memory types in
- * the priority order defined by the driver. If free space isn't found, then
- * drm_bo_mem_force_space is attempted in priority order to evict and find
- * space.
- */
-int drm_bo_mem_space(struct drm_buffer_object *bo,
- struct drm_bo_mem_reg *mem, int no_wait)
-{
- struct drm_device *dev = bo->dev;
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_mem_type_manager *man;
-
- uint32_t num_prios = dev->driver->bo_driver->num_mem_type_prio;
- const uint32_t *prios = dev->driver->bo_driver->mem_type_prio;
- uint32_t i;
- uint32_t mem_type = DRM_BO_MEM_LOCAL;
- uint32_t cur_flags;
- int type_found = 0;
- int type_ok = 0;
- int has_eagain = 0;
- struct drm_mm_node *node = NULL;
- int ret;
-
- mem->mm_node = NULL;
- for (i = 0; i < num_prios; ++i) {
- mem_type = prios[i];
- man = &bm->man[mem_type];
-
- type_ok = drm_bo_mt_compatible(man,
- bo->type == drm_bo_type_user,
- mem_type, mem->proposed_flags,
- &cur_flags);
-
- if (!type_ok)
- continue;
-
- if (mem_type == DRM_BO_MEM_LOCAL)
- break;
-
- if ((mem_type == bo->pinned_mem_type) &&
- (bo->pinned_node != NULL)) {
- node = bo->pinned_node;
- break;
- }
-
- mutex_lock(&dev->struct_mutex);
- if (man->has_type && man->use_type) {
- type_found = 1;
- node = drm_mm_search_free(&man->manager, mem->num_pages,
- mem->page_alignment, 1);
- if (node)
- node = drm_mm_get_block(node, mem->num_pages,
- mem->page_alignment);
- }
- mutex_unlock(&dev->struct_mutex);
- if (node)
- break;
- }
-
- if ((type_ok && (mem_type == DRM_BO_MEM_LOCAL)) || node) {
- mem->mm_node = node;
- mem->mem_type = mem_type;
- mem->flags = cur_flags;
- return 0;
- }
-
- if (!type_found)
- return -EINVAL;
-
- num_prios = dev->driver->bo_driver->num_mem_busy_prio;
- prios = dev->driver->bo_driver->mem_busy_prio;
-
- for (i = 0; i < num_prios; ++i) {
- mem_type = prios[i];
- man = &bm->man[mem_type];
-
- if (!man->has_type)
- continue;
-
- if (!drm_bo_mt_compatible(man,
- bo->type == drm_bo_type_user,
- mem_type,
- mem->proposed_flags,
- &cur_flags))
- continue;
-
- ret = drm_bo_mem_force_space(dev, mem, mem_type, no_wait);
-
- if (ret == 0 && mem->mm_node) {
- mem->flags = cur_flags;
- return 0;
- }
-
- if (ret == -EAGAIN)
- has_eagain = 1;
- }
-
- ret = (has_eagain) ? -EAGAIN : -ENOMEM;
- return ret;
-}
-EXPORT_SYMBOL(drm_bo_mem_space);
-
-/*
- * drm_bo_propose_flags:
- *
- * @bo: the buffer object getting new flags
- *
- * @new_flags: the new set of proposed flag bits
- *
- * @new_mask: the mask of bits changed in new_flags
- *
- * Modify the proposed_flag bits in @bo
- */
-static int drm_bo_modify_proposed_flags (struct drm_buffer_object *bo,
- uint64_t new_flags, uint64_t new_mask)
-{
- uint32_t new_access;
-
- /* Copy unchanging bits from existing proposed_flags */
- DRM_FLAG_MASKED(new_flags, bo->mem.proposed_flags, ~new_mask);
-
- if (bo->type == drm_bo_type_user &&
- ((new_flags & (DRM_BO_FLAG_CACHED | DRM_BO_FLAG_FORCE_CACHING)) !=
- (DRM_BO_FLAG_CACHED | DRM_BO_FLAG_FORCE_CACHING))) {
- DRM_ERROR("User buffers require cache-coherent memory.\n");
- return -EINVAL;
- }
-
- if (bo->type != drm_bo_type_kernel && (new_mask & DRM_BO_FLAG_NO_EVICT) && !DRM_SUSER(DRM_CURPROC)) {
- DRM_ERROR("DRM_BO_FLAG_NO_EVICT is only available to priviliged processes.\n");
- return -EPERM;
- }
-
- if (likely(new_mask & DRM_BO_MASK_MEM) &&
- (bo->mem.flags & DRM_BO_FLAG_NO_EVICT) &&
- !DRM_SUSER(DRM_CURPROC)) {
- if (likely(bo->mem.flags & new_flags & new_mask &
- DRM_BO_MASK_MEM))
- new_flags = (new_flags & ~DRM_BO_MASK_MEM) |
- (bo->mem.flags & DRM_BO_MASK_MEM);
- else {
- DRM_ERROR("Incompatible memory type specification "
- "for NO_EVICT buffer.\n");
- return -EPERM;
- }
- }
-
- if ((new_flags & DRM_BO_FLAG_NO_MOVE)) {
- DRM_ERROR("DRM_BO_FLAG_NO_MOVE is not properly implemented yet.\n");
- return -EPERM;
- }
-
- new_access = new_flags & (DRM_BO_FLAG_EXE | DRM_BO_FLAG_WRITE |
- DRM_BO_FLAG_READ);
-
- if (new_access == 0) {
- DRM_ERROR("Invalid buffer object rwx properties\n");
- return -EINVAL;
- }
-
- bo->mem.proposed_flags = new_flags;
- return 0;
-}
-
-/*
- * Call dev->struct_mutex locked.
- */
-
-struct drm_buffer_object *drm_lookup_buffer_object(struct drm_file *file_priv,
- uint32_t handle, int check_owner)
-{
- struct drm_user_object *uo;
- struct drm_buffer_object *bo;
-
- uo = drm_lookup_user_object(file_priv, handle);
-
- if (!uo || (uo->type != drm_buffer_type)) {
- DRM_ERROR("Could not find buffer object 0x%08x\n", handle);
- return NULL;
- }
-
- if (check_owner && file_priv != uo->owner) {
- if (!drm_lookup_ref_object(file_priv, uo, _DRM_REF_USE))
- return NULL;
- }
-
- bo = drm_user_object_entry(uo, struct drm_buffer_object, base);
- atomic_inc(&bo->usage);
- return bo;
-}
-EXPORT_SYMBOL(drm_lookup_buffer_object);
-
-/*
- * Call bo->mutex locked.
- * Returns -EBUSY if the buffer is currently rendered to or from. 0 otherwise.
- * Doesn't do any fence flushing as opposed to the drm_bo_busy function.
- */
-
-static int drm_bo_quick_busy(struct drm_buffer_object *bo, int check_unfenced)
-{
- struct drm_fence_object *fence = bo->fence;
-
- if (check_unfenced && (bo->priv_flags & _DRM_BO_FLAG_UNFENCED))
- return -EBUSY;
-
- if (fence) {
- if (drm_fence_object_signaled(fence, bo->fence_type)) {
- drm_fence_usage_deref_unlocked(&bo->fence);
- return 0;
- }
- return -EBUSY;
- }
- return 0;
-}
-
-int drm_bo_evict_cached(struct drm_buffer_object *bo)
-{
- int ret = 0;
-
- BUG_ON(bo->priv_flags & _DRM_BO_FLAG_UNFENCED);
- if (bo->mem.mm_node)
- ret = drm_bo_evict(bo, DRM_BO_MEM_TT, 1);
- return ret;
-}
-
-EXPORT_SYMBOL(drm_bo_evict_cached);
-/*
- * Wait until a buffer is unmapped.
- */
-
-static int drm_bo_wait_unmapped(struct drm_buffer_object *bo, int no_wait)
-{
- int ret = 0;
-
- if (likely(atomic_read(&bo->mapped)) == 0)
- return 0;
-
- if (unlikely(no_wait))
- return -EBUSY;
-
- do {
- mutex_unlock(&bo->mutex);
- ret = wait_event_interruptible(bo->event_queue,
- atomic_read(&bo->mapped) == 0);
- mutex_lock(&bo->mutex);
- bo->priv_flags |= _DRM_BO_FLAG_UNLOCKED;
-
- if (ret == -ERESTARTSYS)
- ret = -EAGAIN;
- } while((ret == 0) && atomic_read(&bo->mapped) > 0);
-
- return ret;
-}
-
-/*
- * Fill in the ioctl reply argument with buffer info.
- * Bo locked.
- */
-
-void drm_bo_fill_rep_arg(struct drm_buffer_object *bo,
- struct drm_bo_info_rep *rep)
-{
- if (!rep)
- return;
-
- rep->handle = bo->base.hash.key;
- rep->flags = bo->mem.flags;
- rep->size = bo->num_pages * PAGE_SIZE;
- rep->offset = bo->offset;
-
- /*
- * drm_bo_type_device buffers have user-visible
- * handles which can be used to share across
- * processes. Hand that back to the application
- */
- if (bo->type == drm_bo_type_device)
- rep->arg_handle = bo->map_list.user_token;
- else
- rep->arg_handle = 0;
-
- rep->proposed_flags = bo->mem.proposed_flags;
- rep->buffer_start = bo->buffer_start;
- rep->fence_flags = bo->fence_type;
- rep->rep_flags = 0;
- rep->page_alignment = bo->mem.page_alignment;
-
- if ((bo->priv_flags & _DRM_BO_FLAG_UNFENCED) || drm_bo_quick_busy(bo, 1)) {
- DRM_FLAG_MASKED(rep->rep_flags, DRM_BO_REP_BUSY,
- DRM_BO_REP_BUSY);
- }
-}
-EXPORT_SYMBOL(drm_bo_fill_rep_arg);
-
-/*
- * Wait for buffer idle and register that we've mapped the buffer.
- * Mapping is registered as a drm_ref_object with type _DRM_REF_TYPE1,
- * so that if the client dies, the mapping is automatically
- * unregistered.
- */
-
-static int drm_buffer_object_map(struct drm_file *file_priv, uint32_t handle,
- uint32_t map_flags, unsigned hint,
- struct drm_bo_info_rep *rep)
-{
- struct drm_buffer_object *bo;
- struct drm_device *dev = file_priv->minor->dev;
- int ret = 0;
- int no_wait = hint & DRM_BO_HINT_DONT_BLOCK;
-
- mutex_lock(&dev->struct_mutex);
- bo = drm_lookup_buffer_object(file_priv, handle, 1);
- mutex_unlock(&dev->struct_mutex);
-
- if (!bo)
- return -EINVAL;
-
- mutex_lock(&bo->mutex);
- do {
- bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
-
- ret = drm_bo_wait(bo, 0, 1, no_wait, 1);
- if (unlikely(ret))
- goto out;
-
- if (bo->mem.flags & DRM_BO_FLAG_CACHED_MAPPED)
- drm_bo_evict_cached(bo);
-
- } while (unlikely(bo->priv_flags & _DRM_BO_FLAG_UNLOCKED));
-
- atomic_inc(&bo->mapped);
- mutex_lock(&dev->struct_mutex);
- ret = drm_add_ref_object(file_priv, &bo->base, _DRM_REF_TYPE1);
- mutex_unlock(&dev->struct_mutex);
- if (ret) {
- if (atomic_dec_and_test(&bo->mapped))
- wake_up_all(&bo->event_queue);
-
- } else
- drm_bo_fill_rep_arg(bo, rep);
-
- out:
- mutex_unlock(&bo->mutex);
- drm_bo_usage_deref_unlocked(&bo);
-
- return ret;
-}
-
-static int drm_buffer_object_unmap(struct drm_file *file_priv, uint32_t handle)
-{
- struct drm_device *dev = file_priv->minor->dev;
- struct drm_buffer_object *bo;
- struct drm_ref_object *ro;
- int ret = 0;
-
- mutex_lock(&dev->struct_mutex);
-
- bo = drm_lookup_buffer_object(file_priv, handle, 1);
- if (!bo) {
- ret = -EINVAL;
- goto out;
- }
-
- ro = drm_lookup_ref_object(file_priv, &bo->base, _DRM_REF_TYPE1);
- if (!ro) {
- ret = -EINVAL;
- goto out;
- }
-
- drm_remove_ref_object(file_priv, ro);
- drm_bo_usage_deref_locked(&bo);
-out:
- mutex_unlock(&dev->struct_mutex);
- return ret;
-}
-
-/*
- * Call struct-sem locked.
- */
-
-static void drm_buffer_user_object_unmap(struct drm_file *file_priv,
- struct drm_user_object *uo,
- enum drm_ref_type action)
-{
- struct drm_buffer_object *bo =
- drm_user_object_entry(uo, struct drm_buffer_object, base);
-
- /*
- * We DON'T want to take the bo->lock here, because we want to
- * hold it when we wait for unmapped buffer.
- */
-
- BUG_ON(action != _DRM_REF_TYPE1);
-
- if (atomic_dec_and_test(&bo->mapped))
- wake_up_all(&bo->event_queue);
-}
-
-/*
- * bo->mutex locked.
- * Note that new_mem_flags are NOT transferred to the bo->mem.proposed_flags.
- */
-
-int drm_bo_move_buffer(struct drm_buffer_object *bo, uint64_t new_mem_flags,
- int no_wait, int move_unfenced)
-{
- struct drm_device *dev = bo->dev;
- struct drm_buffer_manager *bm = &dev->bm;
- int ret = 0;
- struct drm_bo_mem_reg mem;
-
- BUG_ON(bo->fence != NULL);
-
- mem.num_pages = bo->num_pages;
- mem.size = mem.num_pages << PAGE_SHIFT;
- mem.proposed_flags = new_mem_flags;
- mem.page_alignment = bo->mem.page_alignment;
-
- mutex_lock(&bm->evict_mutex);
- mutex_lock(&dev->struct_mutex);
- list_del_init(&bo->lru);
- mutex_unlock(&dev->struct_mutex);
-
- /*
- * Determine where to move the buffer.
- */
- ret = drm_bo_mem_space(bo, &mem, no_wait);
- if (ret)
- goto out_unlock;
-
- ret = drm_bo_handle_move_mem(bo, &mem, 0, no_wait);
-
-out_unlock:
- mutex_lock(&dev->struct_mutex);
- if (ret || !move_unfenced) {
- if (mem.mm_node) {
- if (mem.mm_node != bo->pinned_node)
- drm_mm_put_block(mem.mm_node);
- mem.mm_node = NULL;
- }
- drm_bo_add_to_lru(bo);
- if (bo->priv_flags & _DRM_BO_FLAG_UNFENCED) {
- wake_up_all(&bo->event_queue);
- DRM_FLAG_MASKED(bo->priv_flags, 0,
- _DRM_BO_FLAG_UNFENCED);
- }
- } else {
- list_add_tail(&bo->lru, &bm->unfenced);
- DRM_FLAG_MASKED(bo->priv_flags, _DRM_BO_FLAG_UNFENCED,
- _DRM_BO_FLAG_UNFENCED);
- }
- mutex_unlock(&dev->struct_mutex);
- mutex_unlock(&bm->evict_mutex);
- return ret;
-}
-
-static int drm_bo_mem_compat(struct drm_bo_mem_reg *mem)
-{
- uint32_t flag_diff = (mem->proposed_flags ^ mem->flags);
-
- if ((mem->proposed_flags & mem->flags & DRM_BO_MASK_MEM) == 0)
- return 0;
- if ((flag_diff & DRM_BO_FLAG_CACHED) &&
- (/* !(mem->proposed_flags & DRM_BO_FLAG_CACHED) ||*/
- (mem->proposed_flags & DRM_BO_FLAG_FORCE_CACHING)))
- return 0;
-
- if ((flag_diff & DRM_BO_FLAG_MAPPABLE) &&
- ((mem->proposed_flags & DRM_BO_FLAG_MAPPABLE) ||
- (mem->proposed_flags & DRM_BO_FLAG_FORCE_MAPPABLE)))
- return 0;
- return 1;
-}
-
-/**
- * drm_buffer_object_validate:
- *
- * @bo: the buffer object to modify
- *
- * @fence_class: the new fence class covering this buffer
- *
- * @move_unfenced: a boolean indicating whether switching the
- * memory space of this buffer should cause the buffer to
- * be placed on the unfenced list.
- *
- * @no_wait: whether this function should return -EBUSY instead
- * of waiting.
- *
- * Change buffer access parameters. This can involve moving
- * the buffer to the correct memory type, pinning the buffer
- * or changing the class/type of fence covering this buffer
- *
- * Must be called with bo locked.
- */
-
-static int drm_buffer_object_validate(struct drm_buffer_object *bo,
- uint32_t fence_class,
- int move_unfenced, int no_wait,
- int move_buffer)
-{
- struct drm_device *dev = bo->dev;
- struct drm_buffer_manager *bm = &dev->bm;
- int ret;
-
- if (move_buffer) {
- ret = drm_bo_move_buffer(bo, bo->mem.proposed_flags, no_wait,
- move_unfenced);
- if (ret) {
- if (ret != -EAGAIN)
- DRM_ERROR("Failed moving buffer.\n");
- if (ret == -ENOMEM)
- DRM_ERROR("Out of aperture space or "
- "DRM memory quota.\n");
- return ret;
- }
- }
-
- /*
- * Pinned buffers.
- */
-
- if (bo->mem.proposed_flags & (DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_NO_MOVE)) {
- bo->pinned_mem_type = bo->mem.mem_type;
- mutex_lock(&dev->struct_mutex);
- list_del_init(&bo->pinned_lru);
- drm_bo_add_to_pinned_lru(bo);
-
- if (bo->pinned_node != bo->mem.mm_node) {
- if (bo->pinned_node != NULL)
- drm_mm_put_block(bo->pinned_node);
- bo->pinned_node = bo->mem.mm_node;
- }
-
- mutex_unlock(&dev->struct_mutex);
-
- } else if (bo->pinned_node != NULL) {
-
- mutex_lock(&dev->struct_mutex);
-
- if (bo->pinned_node != bo->mem.mm_node)
- drm_mm_put_block(bo->pinned_node);
-
- list_del_init(&bo->pinned_lru);
- bo->pinned_node = NULL;
- mutex_unlock(&dev->struct_mutex);
-
- }
-
- /*
- * We might need to add a TTM.
- */
-
- if (bo->mem.mem_type == DRM_BO_MEM_LOCAL && bo->ttm == NULL) {
- ret = drm_bo_add_ttm(bo);
- if (ret)
- return ret;
- }
- /*
- * Validation has succeeded, move the access and other
- * non-mapping-related flag bits from the proposed flags to
- * the active flags
- */
-
- DRM_FLAG_MASKED(bo->mem.flags, bo->mem.proposed_flags, ~DRM_BO_MASK_MEMTYPE);
-
- /*
- * Finally, adjust lru to be sure.
- */
-
- mutex_lock(&dev->struct_mutex);
- list_del(&bo->lru);
- if (move_unfenced) {
- list_add_tail(&bo->lru, &bm->unfenced);
- DRM_FLAG_MASKED(bo->priv_flags, _DRM_BO_FLAG_UNFENCED,
- _DRM_BO_FLAG_UNFENCED);
- } else {
- drm_bo_add_to_lru(bo);
- if (bo->priv_flags & _DRM_BO_FLAG_UNFENCED) {
- wake_up_all(&bo->event_queue);
- DRM_FLAG_MASKED(bo->priv_flags, 0,
- _DRM_BO_FLAG_UNFENCED);
- }
- }
- mutex_unlock(&dev->struct_mutex);
-
- return 0;
-}
-
-/*
- * This function is called with bo->mutex locked, but may release it
- * temporarily to wait for events.
- */
-
-static int drm_bo_prepare_for_validate(struct drm_buffer_object *bo,
- uint64_t flags,
- uint64_t mask,
- uint32_t hint,
- uint32_t fence_class,
- int no_wait,
- int *move_buffer)
-{
- struct drm_device *dev = bo->dev;
- struct drm_bo_driver *driver = dev->driver->bo_driver;
- uint32_t ftype;
-
- int ret;
-
- DRM_DEBUG("Proposed flags 0x%016llx, Old flags 0x%016llx\n",
- (unsigned long long) bo->mem.proposed_flags,
- (unsigned long long) bo->mem.flags);
-
- ret = drm_bo_modify_proposed_flags (bo, flags, mask);
- if (ret)
- return ret;
-
- ret = drm_bo_wait_unmapped(bo, no_wait);
- if (ret)
- return ret;
-
- ret = driver->fence_type(bo, &fence_class, &ftype);
-
- if (ret) {
- DRM_ERROR("Driver did not support given buffer permissions.\n");
- return ret;
- }
-
- /*
- * We're switching command submission mechanism,
- * or cannot simply rely on the hardware serializing for us.
- * Insert a driver-dependant barrier or wait for buffer idle.
- */
-
- if ((fence_class != bo->fence_class) ||
- ((ftype ^ bo->fence_type) & bo->fence_type)) {
-
- ret = -EINVAL;
- if (driver->command_stream_barrier) {
- ret = driver->command_stream_barrier(bo,
- fence_class,
- ftype,
- no_wait);
- }
- if (ret && ret != -EAGAIN)
- ret = drm_bo_wait(bo, 0, 1, no_wait, 1);
-
- if (ret)
- return ret;
- }
-
- bo->new_fence_class = fence_class;
- bo->new_fence_type = ftype;
-
- /*
- * Check whether we need to move buffer.
- */
-
- *move_buffer = 0;
- if (!drm_bo_mem_compat(&bo->mem)) {
- *move_buffer = 1;
- ret = drm_bo_wait(bo, 0, 1, no_wait, 1);
- }
-
- return ret;
-}
-
-/**
- * drm_bo_do_validate:
- *
- * @bo: the buffer object
- *
- * @flags: access rights, mapping parameters and cacheability. See
- * the DRM_BO_FLAG_* values in drm.h
- *
- * @mask: Which flag values to change; this allows callers to modify
- * things without knowing the current state of other flags.
- *
- * @hint: changes the proceedure for this operation, see the DRM_BO_HINT_*
- * values in drm.h.
- *
- * @fence_class: a driver-specific way of doing fences. Presumably,
- * this would be used if the driver had more than one submission and
- * fencing mechanism. At this point, there isn't any use of this
- * from the user mode code.
- *
- * @rep: To be stuffed with the reply from validation
- *
- * 'validate' a buffer object. This changes where the buffer is
- * located, along with changing access modes.
- */
-
-int drm_bo_do_validate(struct drm_buffer_object *bo,
- uint64_t flags, uint64_t mask, uint32_t hint,
- uint32_t fence_class,
- struct drm_bo_info_rep *rep)
-{
- int ret;
- int no_wait = (hint & DRM_BO_HINT_DONT_BLOCK) != 0;
- int move_buffer;
-
- mutex_lock(&bo->mutex);
-
- do {
- bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
-
- ret = drm_bo_prepare_for_validate(bo, flags, mask, hint,
- fence_class, no_wait,
- &move_buffer);
- if (ret)
- goto out;
-
- } while(unlikely(bo->priv_flags & _DRM_BO_FLAG_UNLOCKED));
-
- ret = drm_buffer_object_validate(bo,
- fence_class,
- !(hint & DRM_BO_HINT_DONT_FENCE),
- no_wait,
- move_buffer);
-
- BUG_ON(bo->priv_flags & _DRM_BO_FLAG_UNLOCKED);
-out:
- if (rep)
- drm_bo_fill_rep_arg(bo, rep);
-
- mutex_unlock(&bo->mutex);
-
- return ret;
-}
-EXPORT_SYMBOL(drm_bo_do_validate);
-
-/**
- * drm_bo_handle_validate
- *
- * @file_priv: the drm file private, used to get a handle to the user context
- *
- * @handle: the buffer object handle
- *
- * @flags: access rights, mapping parameters and cacheability. See
- * the DRM_BO_FLAG_* values in drm.h
- *
- * @mask: Which flag values to change; this allows callers to modify
- * things without knowing the current state of other flags.
- *
- * @hint: changes the proceedure for this operation, see the DRM_BO_HINT_*
- * values in drm.h.
- *
- * @fence_class: a driver-specific way of doing fences. Presumably,
- * this would be used if the driver had more than one submission and
- * fencing mechanism. At this point, there isn't any use of this
- * from the user mode code.
- *
- * @rep: To be stuffed with the reply from validation
- *
- * @bp_rep: To be stuffed with the buffer object pointer
- *
- * Perform drm_bo_do_validate on a buffer referenced by a user-space handle instead
- * of a pointer to a buffer object. Optionally return a pointer to the buffer object.
- * This is a convenience wrapper only.
- */
-
-int drm_bo_handle_validate(struct drm_file *file_priv, uint32_t handle,
- uint64_t flags, uint64_t mask,
- uint32_t hint,
- uint32_t fence_class,
- struct drm_bo_info_rep *rep,
- struct drm_buffer_object **bo_rep)
-{
- struct drm_device *dev = file_priv->minor->dev;
- struct drm_buffer_object *bo;
- int ret;
-
- mutex_lock(&dev->struct_mutex);
- bo = drm_lookup_buffer_object(file_priv, handle, 1);
- mutex_unlock(&dev->struct_mutex);
-
- if (!bo)
- return -EINVAL;
-
- if (bo->base.owner != file_priv)
- mask &= ~(DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_NO_MOVE);
-
- ret = drm_bo_do_validate(bo, flags, mask, hint, fence_class, rep);
-
- if (!ret && bo_rep)
- *bo_rep = bo;
- else
- drm_bo_usage_deref_unlocked(&bo);
-
- return ret;
-}
-EXPORT_SYMBOL(drm_bo_handle_validate);
-
-
-static int drm_bo_handle_info(struct drm_file *file_priv, uint32_t handle,
- struct drm_bo_info_rep *rep)
-{
- struct drm_device *dev = file_priv->minor->dev;
- struct drm_buffer_object *bo;
-
- mutex_lock(&dev->struct_mutex);
- bo = drm_lookup_buffer_object(file_priv, handle, 1);
- mutex_unlock(&dev->struct_mutex);
-
- if (!bo)
- return -EINVAL;
-
- mutex_lock(&bo->mutex);
-
- /*
- * FIXME: Quick busy here?
- */
-
- drm_bo_busy(bo, 1);
- drm_bo_fill_rep_arg(bo, rep);
- mutex_unlock(&bo->mutex);
- drm_bo_usage_deref_unlocked(&bo);
- return 0;
-}
-
-static int drm_bo_handle_wait(struct drm_file *file_priv, uint32_t handle,
- uint32_t hint,
- struct drm_bo_info_rep *rep)
-{
- struct drm_device *dev = file_priv->minor->dev;
- struct drm_buffer_object *bo;
- int no_wait = hint & DRM_BO_HINT_DONT_BLOCK;
- int ret;
-
- mutex_lock(&dev->struct_mutex);
- bo = drm_lookup_buffer_object(file_priv, handle, 1);
- mutex_unlock(&dev->struct_mutex);
-
- if (!bo)
- return -EINVAL;
-
- mutex_lock(&bo->mutex);
- ret = drm_bo_wait(bo, hint & DRM_BO_HINT_WAIT_LAZY, 1, no_wait, 1);
- if (ret)
- goto out;
-
- drm_bo_fill_rep_arg(bo, rep);
-out:
- mutex_unlock(&bo->mutex);
- drm_bo_usage_deref_unlocked(&bo);
- return ret;
-}
-
-int drm_buffer_object_create(struct drm_device *dev,
- unsigned long size,
- enum drm_bo_type type,
- uint64_t flags,
- uint32_t hint,
- uint32_t page_alignment,
- unsigned long buffer_start,
- struct drm_buffer_object **buf_obj)
-{
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_buffer_object *bo;
- int ret = 0;
- unsigned long num_pages;
-
- size += buffer_start & ~PAGE_MASK;
- num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
- if (num_pages == 0) {
- DRM_ERROR("Illegal buffer object size.\n");
- return -EINVAL;
- }
-
- bo = drm_ctl_calloc(1, sizeof(*bo), DRM_MEM_BUFOBJ);
-
- if (!bo)
- return -ENOMEM;
-
- mutex_init(&bo->mutex);
- mutex_lock(&bo->mutex);
-
- atomic_set(&bo->usage, 1);
- atomic_set(&bo->mapped, 0);
- DRM_INIT_WAITQUEUE(&bo->event_queue);
- INIT_LIST_HEAD(&bo->lru);
- INIT_LIST_HEAD(&bo->pinned_lru);
- INIT_LIST_HEAD(&bo->ddestroy);
- bo->dev = dev;
- bo->type = type;
- bo->num_pages = num_pages;
- bo->mem.mem_type = DRM_BO_MEM_LOCAL;
- bo->mem.num_pages = bo->num_pages;
- bo->mem.mm_node = NULL;
- bo->mem.page_alignment = page_alignment;
- bo->buffer_start = buffer_start & PAGE_MASK;
- bo->priv_flags = 0;
- bo->mem.flags = (DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_CACHED |
- DRM_BO_FLAG_MAPPABLE);
- bo->mem.proposed_flags = 0;
- atomic_inc(&bm->count);
- /*
- * Use drm_bo_modify_proposed_flags to error-check the proposed flags
- */
- ret = drm_bo_modify_proposed_flags (bo, flags, flags);
- if (ret)
- goto out_err;
-
- /*
- * For drm_bo_type_device buffers, allocate
- * address space from the device so that applications
- * can mmap the buffer from there
- */
- if (bo->type == drm_bo_type_device) {
- mutex_lock(&dev->struct_mutex);
- ret = drm_bo_setup_vm_locked(bo);
- mutex_unlock(&dev->struct_mutex);
- if (ret)
- goto out_err;
- }
-
- mutex_unlock(&bo->mutex);
- ret = drm_bo_do_validate(bo, 0, 0, hint | DRM_BO_HINT_DONT_FENCE,
- 0, NULL);
- if (ret)
- goto out_err_unlocked;
-
- *buf_obj = bo;
- return 0;
-
-out_err:
- mutex_unlock(&bo->mutex);
-out_err_unlocked:
- drm_bo_usage_deref_unlocked(&bo);
- return ret;
-}
-EXPORT_SYMBOL(drm_buffer_object_create);
-
-
-static int drm_bo_add_user_object(struct drm_file *file_priv,
- struct drm_buffer_object *bo, int shareable)
-{
- struct drm_device *dev = file_priv->minor->dev;
- int ret;
-
- mutex_lock(&dev->struct_mutex);
- ret = drm_add_user_object(file_priv, &bo->base, shareable);
- if (ret)
- goto out;
-
- bo->base.remove = drm_bo_base_deref_locked;
- bo->base.type = drm_buffer_type;
- bo->base.ref_struct_locked = NULL;
- bo->base.unref = drm_buffer_user_object_unmap;
-
-out:
- mutex_unlock(&dev->struct_mutex);
- return ret;
-}
-
-int drm_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_bo_create_arg *arg = data;
- struct drm_bo_create_req *req = &arg->d.req;
- struct drm_bo_info_rep *rep = &arg->d.rep;
- struct drm_buffer_object *entry;
- enum drm_bo_type bo_type;
- int ret = 0;
-
- DRM_DEBUG("drm_bo_create_ioctl: %dkb, %dkb align\n",
- (int)(req->size / 1024), req->page_alignment * 4);
-
- if (!dev->bm.initialized) {
- DRM_ERROR("Buffer object manager is not initialized.\n");
- return -EINVAL;
- }
-
- /*
- * If the buffer creation request comes in with a starting address,
- * that points at the desired user pages to map. Otherwise, create
- * a drm_bo_type_device buffer, which uses pages allocated from the kernel
- */
- bo_type = (req->buffer_start) ? drm_bo_type_user : drm_bo_type_device;
-
- /*
- * User buffers cannot be shared
- */
- if (bo_type == drm_bo_type_user)
- req->flags &= ~DRM_BO_FLAG_SHAREABLE;
-
- ret = drm_buffer_object_create(file_priv->minor->dev,
- req->size, bo_type, req->flags,
- req->hint, req->page_alignment,
- req->buffer_start, &entry);
- if (ret)
- goto out;
-
- ret = drm_bo_add_user_object(file_priv, entry,
- req->flags & DRM_BO_FLAG_SHAREABLE);
- if (ret) {
- drm_bo_usage_deref_unlocked(&entry);
- goto out;
- }
-
- mutex_lock(&entry->mutex);
- drm_bo_fill_rep_arg(entry, rep);
- mutex_unlock(&entry->mutex);
-
-out:
- return ret;
-}
-
-int drm_bo_setstatus_ioctl(struct drm_device *dev,
- void *data, struct drm_file *file_priv)
-{
- struct drm_bo_map_wait_idle_arg *arg = data;
- struct drm_bo_info_req *req = &arg->d.req;
- struct drm_bo_info_rep *rep = &arg->d.rep;
- struct drm_buffer_object *bo;
- int ret;
-
- if (!dev->bm.initialized) {
- DRM_ERROR("Buffer object manager is not initialized.\n");
- return -EINVAL;
- }
-
- ret = drm_bo_read_lock(&dev->bm.bm_lock, 1);
- if (ret)
- return ret;
-
- mutex_lock(&dev->struct_mutex);
- bo = drm_lookup_buffer_object(file_priv, req->handle, 1);
- mutex_unlock(&dev->struct_mutex);
-
- if (!bo)
- return -EINVAL;
-
- if (bo->base.owner != file_priv)
- req->mask &= ~(DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_NO_MOVE);
-
- ret = drm_bo_do_validate(bo, req->flags, req->mask,
- req->hint | DRM_BO_HINT_DONT_FENCE,
- bo->fence_class, rep);
-
- drm_bo_usage_deref_unlocked(&bo);
-
- (void) drm_bo_read_unlock(&dev->bm.bm_lock);
-
- return ret;
-}
-
-int drm_bo_map_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_bo_map_wait_idle_arg *arg = data;
- struct drm_bo_info_req *req = &arg->d.req;
- struct drm_bo_info_rep *rep = &arg->d.rep;
- int ret;
- if (!dev->bm.initialized) {
- DRM_ERROR("Buffer object manager is not initialized.\n");
- return -EINVAL;
- }
-
- ret = drm_buffer_object_map(file_priv, req->handle, req->mask,
- req->hint, rep);
- if (ret)
- return ret;
-
- return 0;
-}
-
-int drm_bo_unmap_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_bo_handle_arg *arg = data;
- int ret;
- if (!dev->bm.initialized) {
- DRM_ERROR("Buffer object manager is not initialized.\n");
- return -EINVAL;
- }
-
- ret = drm_buffer_object_unmap(file_priv, arg->handle);
- return ret;
-}
-
-
-int drm_bo_reference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_bo_reference_info_arg *arg = data;
- struct drm_bo_handle_arg *req = &arg->d.req;
- struct drm_bo_info_rep *rep = &arg->d.rep;
- struct drm_user_object *uo;
- int ret;
-
- if (!dev->bm.initialized) {
- DRM_ERROR("Buffer object manager is not initialized.\n");
- return -EINVAL;
- }
-
- ret = drm_user_object_ref(file_priv, req->handle,
- drm_buffer_type, &uo);
- if (ret)
- return ret;
-
- ret = drm_bo_handle_info(file_priv, req->handle, rep);
- if (ret)
- return ret;
-
- return 0;
-}
-
-int drm_bo_unreference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_bo_handle_arg *arg = data;
- int ret = 0;
-
- if (!dev->bm.initialized) {
- DRM_ERROR("Buffer object manager is not initialized.\n");
- return -EINVAL;
- }
-
- ret = drm_user_object_unref(file_priv, arg->handle, drm_buffer_type);
- return ret;
-}
-
-int drm_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_bo_reference_info_arg *arg = data;
- struct drm_bo_handle_arg *req = &arg->d.req;
- struct drm_bo_info_rep *rep = &arg->d.rep;
- int ret;
-
- if (!dev->bm.initialized) {
- DRM_ERROR("Buffer object manager is not initialized.\n");
- return -EINVAL;
- }
-
- ret = drm_bo_handle_info(file_priv, req->handle, rep);
- if (ret)
- return ret;
-
- return 0;
-}
-
-int drm_bo_wait_idle_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_bo_map_wait_idle_arg *arg = data;
- struct drm_bo_info_req *req = &arg->d.req;
- struct drm_bo_info_rep *rep = &arg->d.rep;
- int ret;
- if (!dev->bm.initialized) {
- DRM_ERROR("Buffer object manager is not initialized.\n");
- return -EINVAL;
- }
-
- ret = drm_bo_handle_wait(file_priv, req->handle,
- req->hint, rep);
- if (ret)
- return ret;
-
- return 0;
-}
-
-static int drm_bo_leave_list(struct drm_buffer_object *bo,
- uint32_t mem_type,
- int free_pinned,
- int allow_errors)
-{
- struct drm_device *dev = bo->dev;
- int ret = 0;
-
- mutex_lock(&bo->mutex);
-
- ret = drm_bo_expire_fence(bo, allow_errors);
- if (ret)
- goto out;
-
- if (free_pinned) {
- DRM_FLAG_MASKED(bo->mem.flags, 0, DRM_BO_FLAG_NO_MOVE);
- mutex_lock(&dev->struct_mutex);
- list_del_init(&bo->pinned_lru);
- if (bo->pinned_node == bo->mem.mm_node)
- bo->pinned_node = NULL;
- if (bo->pinned_node != NULL) {
- drm_mm_put_block(bo->pinned_node);
- bo->pinned_node = NULL;
- }
- mutex_unlock(&dev->struct_mutex);
- }
-
- if (bo->mem.flags & DRM_BO_FLAG_NO_EVICT) {
- DRM_ERROR("A DRM_BO_NO_EVICT buffer present at "
- "cleanup. Removing flag and evicting.\n");
- bo->mem.flags &= ~DRM_BO_FLAG_NO_EVICT;
- bo->mem.proposed_flags &= ~DRM_BO_FLAG_NO_EVICT;
- }
-
- if (bo->mem.mem_type == mem_type)
- ret = drm_bo_evict(bo, mem_type, 0);
-
- if (ret) {
- if (allow_errors) {
- goto out;
- } else {
- ret = 0;
- DRM_ERROR("Cleanup eviction failed\n");
- }
- }
-
-out:
- mutex_unlock(&bo->mutex);
- return ret;
-}
-
-
-static struct drm_buffer_object *drm_bo_entry(struct list_head *list,
- int pinned_list)
-{
- if (pinned_list)
- return list_entry(list, struct drm_buffer_object, pinned_lru);
- else
- return list_entry(list, struct drm_buffer_object, lru);
-}
-
-/*
- * dev->struct_mutex locked.
- */
-
-static int drm_bo_force_list_clean(struct drm_device *dev,
- struct list_head *head,
- unsigned mem_type,
- int free_pinned,
- int allow_errors,
- int pinned_list)
-{
- struct list_head *list, *next, *prev;
- struct drm_buffer_object *entry, *nentry;
- int ret;
- int do_restart;
-
- /*
- * The list traversal is a bit odd here, because an item may
- * disappear from the list when we release the struct_mutex or
- * when we decrease the usage count. Also we're not guaranteed
- * to drain pinned lists, so we can't always restart.
- */
-
-restart:
- nentry = NULL;
- list_for_each_safe(list, next, head) {
- prev = list->prev;
-
- entry = (nentry != NULL) ? nentry: drm_bo_entry(list, pinned_list);
- atomic_inc(&entry->usage);
- if (nentry) {
- atomic_dec(&nentry->usage);
- nentry = NULL;
- }
-
- /*
- * Protect the next item from destruction, so we can check
- * its list pointers later on.
- */
-
- if (next != head) {
- nentry = drm_bo_entry(next, pinned_list);
- atomic_inc(&nentry->usage);
- }
- mutex_unlock(&dev->struct_mutex);
-
- ret = drm_bo_leave_list(entry, mem_type, free_pinned,
- allow_errors);
- mutex_lock(&dev->struct_mutex);
-
- drm_bo_usage_deref_locked(&entry);
- if (ret)
- return ret;
-
- /*
- * Has the next item disappeared from the list?
- */
-
- do_restart = ((next->prev != list) && (next->prev != prev));
-
- if (nentry != NULL && do_restart)
- drm_bo_usage_deref_locked(&nentry);
-
- if (do_restart)
- goto restart;
- }
- return 0;
-}
-
-int drm_bo_clean_mm(struct drm_device *dev, unsigned mem_type, int kern_clean)
-{
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_mem_type_manager *man = &bm->man[mem_type];
- int ret = -EINVAL;
-
- if (mem_type >= DRM_BO_MEM_TYPES) {
- DRM_ERROR("Illegal memory type %d\n", mem_type);
- return ret;
- }
-
- if (!man->has_type) {
- DRM_ERROR("Trying to take down uninitialized "
- "memory manager type %u\n", mem_type);
- return ret;
- }
-
- if ((man->kern_init_type) && (kern_clean == 0)) {
- DRM_ERROR("Trying to take down kernel initialized "
- "memory manager type %u\n", mem_type);
- return -EPERM;
- }
-
- man->use_type = 0;
- man->has_type = 0;
-
- ret = 0;
- if (mem_type > 0) {
- BUG_ON(!list_empty(&bm->unfenced));
- drm_bo_force_list_clean(dev, &man->lru, mem_type, 1, 0, 0);
- drm_bo_force_list_clean(dev, &man->pinned, mem_type, 1, 0, 1);
-
- if (drm_mm_clean(&man->manager)) {
- drm_mm_takedown(&man->manager);
- } else {
- ret = -EBUSY;
- }
- }
-
- return ret;
-}
-EXPORT_SYMBOL(drm_bo_clean_mm);
-
-/**
- *Evict all buffers of a particular mem_type, but leave memory manager
- *regions for NO_MOVE buffers intact. New buffers cannot be added at this
- *point since we have the hardware lock.
- */
-
-static int drm_bo_lock_mm(struct drm_device *dev, unsigned mem_type)
-{
- int ret;
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_mem_type_manager *man = &bm->man[mem_type];
-
- if (mem_type == 0 || mem_type >= DRM_BO_MEM_TYPES) {
- DRM_ERROR("Illegal memory manager memory type %u.\n", mem_type);
- return -EINVAL;
- }
-
- if (!man->has_type) {
- DRM_ERROR("Memory type %u has not been initialized.\n",
- mem_type);
- return 0;
- }
-
- ret = drm_bo_force_list_clean(dev, &man->lru, mem_type, 0, 1, 0);
- if (ret)
- return ret;
- ret = drm_bo_force_list_clean(dev, &man->pinned, mem_type, 0, 1, 1);
-
- return ret;
-}
-
-int drm_bo_init_mm(struct drm_device *dev, unsigned type,
- unsigned long p_offset, unsigned long p_size,
- int kern_init)
-{
- struct drm_buffer_manager *bm = &dev->bm;
- int ret = -EINVAL;
- struct drm_mem_type_manager *man;
-
- if (type >= DRM_BO_MEM_TYPES) {
- DRM_ERROR("Illegal memory type %d\n", type);
- return ret;
- }
-
- man = &bm->man[type];
- if (man->has_type) {
- DRM_ERROR("Memory manager already initialized for type %d\n",
- type);
- return ret;
- }
-
- ret = dev->driver->bo_driver->init_mem_type(dev, type, man);
- if (ret)
- return ret;
-
- ret = 0;
- if (type != DRM_BO_MEM_LOCAL) {
- if (!p_size) {
- DRM_ERROR("Zero size memory manager type %d\n", type);
- return ret;
- }
- ret = drm_mm_init(&man->manager, p_offset, p_size);
- if (ret)
- return ret;
- }
- man->has_type = 1;
- man->use_type = 1;
- man->kern_init_type = kern_init;
- man->size = p_size;
-
- INIT_LIST_HEAD(&man->lru);
- INIT_LIST_HEAD(&man->pinned);
-
- return 0;
-}
-EXPORT_SYMBOL(drm_bo_init_mm);
-
-/*
- * This function is intended to be called on drm driver unload.
- * If you decide to call it from lastclose, you must protect the call
- * from a potentially racing drm_bo_driver_init in firstopen.
- * (This may happen on X server restart).
- */
-
-int drm_bo_driver_finish(struct drm_device *dev)
-{
- struct drm_buffer_manager *bm = &dev->bm;
- int ret = 0;
- unsigned i = DRM_BO_MEM_TYPES;
- struct drm_mem_type_manager *man;
-
- mutex_lock(&dev->struct_mutex);
-
- if (!bm->initialized)
- goto out;
- bm->initialized = 0;
-
- while (i--) {
- man = &bm->man[i];
- if (man->has_type) {
- man->use_type = 0;
- if ((i != DRM_BO_MEM_LOCAL) && drm_bo_clean_mm(dev, i, 1)) {
- ret = -EBUSY;
- DRM_ERROR("DRM memory manager type %d "
- "is not clean.\n", i);
- }
- man->has_type = 0;
- }
- }
- mutex_unlock(&dev->struct_mutex);
-
- if (!cancel_delayed_work(&bm->wq))
- flush_scheduled_work();
-
- mutex_lock(&dev->struct_mutex);
- drm_bo_delayed_delete(dev, 1);
- if (list_empty(&bm->ddestroy))
- DRM_DEBUG("Delayed destroy list was clean\n");
-
- if (list_empty(&bm->man[0].lru))
- DRM_DEBUG("Swap list was clean\n");
-
- if (list_empty(&bm->man[0].pinned))
- DRM_DEBUG("NO_MOVE list was clean\n");
-
- if (list_empty(&bm->unfenced))
- DRM_DEBUG("Unfenced list was clean\n");
-
- __free_page(bm->dummy_read_page);
-
-out:
- mutex_unlock(&dev->struct_mutex);
- return ret;
-}
-
-/*
- * This function is intended to be called on drm driver load.
- * If you decide to call it from firstopen, you must protect the call
- * from a potentially racing drm_bo_driver_finish in lastclose.
- * (This may happen on X server restart).
- */
-
-int drm_bo_driver_init(struct drm_device *dev)
-{
- struct drm_bo_driver *driver = dev->driver->bo_driver;
- struct drm_buffer_manager *bm = &dev->bm;
- int ret = -EINVAL;
-
- bm->dummy_read_page = NULL;
- drm_bo_init_lock(&bm->bm_lock);
- mutex_lock(&dev->struct_mutex);
- if (!driver)
- goto out_unlock;
-
- bm->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32);
- if (!bm->dummy_read_page) {
- ret = -ENOMEM;
- goto out_unlock;
- }
-
- /*
- * Initialize the system memory buffer type.
- * Other types need to be driver / IOCTL initialized.
- */
- ret = drm_bo_init_mm(dev, DRM_BO_MEM_LOCAL, 0, 0, 1);
- if (ret)
- goto out_unlock;
-
- INIT_DELAYED_WORK(&bm->wq, drm_bo_delayed_workqueue);
- bm->initialized = 1;
- bm->nice_mode = 1;
- atomic_set(&bm->count, 0);
- bm->cur_pages = 0;
- INIT_LIST_HEAD(&bm->unfenced);
- INIT_LIST_HEAD(&bm->ddestroy);
-out_unlock:
- mutex_unlock(&dev->struct_mutex);
- return ret;
-}
-EXPORT_SYMBOL(drm_bo_driver_init);
-
-int drm_mm_init_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_mm_init_arg *arg = data;
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_bo_driver *driver = dev->driver->bo_driver;
- int ret;
-
- if (!driver) {
- DRM_ERROR("Buffer objects are not supported by this driver\n");
- return -EINVAL;
- }
-
- ret = drm_bo_write_lock(&bm->bm_lock, 1, file_priv);
- if (ret)
- return ret;
-
- ret = -EINVAL;
- if (arg->magic != DRM_BO_INIT_MAGIC) {
- DRM_ERROR("You are using an old libdrm that is not compatible with\n"
- "\tthe kernel DRM module. Please upgrade your libdrm.\n");
- return -EINVAL;
- }
- if (arg->major != DRM_BO_INIT_MAJOR) {
- DRM_ERROR("libdrm and kernel DRM buffer object interface major\n"
- "\tversion don't match. Got %d, expected %d.\n",
- arg->major, DRM_BO_INIT_MAJOR);
- return -EINVAL;
- }
-
- mutex_lock(&dev->struct_mutex);
- if (!bm->initialized) {
- DRM_ERROR("DRM memory manager was not initialized.\n");
- goto out;
- }
- if (arg->mem_type == 0) {
- DRM_ERROR("System memory buffers already initialized.\n");
- goto out;
- }
- ret = drm_bo_init_mm(dev, arg->mem_type,
- arg->p_offset, arg->p_size, 0);
-
-out:
- mutex_unlock(&dev->struct_mutex);
- (void) drm_bo_write_unlock(&bm->bm_lock, file_priv);
-
- if (ret)
- return ret;
-
- return 0;
-}
-
-int drm_mm_takedown_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_mm_type_arg *arg = data;
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_bo_driver *driver = dev->driver->bo_driver;
- int ret;
-
- if (!driver) {
- DRM_ERROR("Buffer objects are not supported by this driver\n");
- return -EINVAL;
- }
-
- ret = drm_bo_write_lock(&bm->bm_lock, 0, file_priv);
- if (ret)
- return ret;
-
- mutex_lock(&dev->struct_mutex);
- ret = -EINVAL;
- if (!bm->initialized) {
- DRM_ERROR("DRM memory manager was not initialized\n");
- goto out;
- }
- if (arg->mem_type == 0) {
- DRM_ERROR("No takedown for System memory buffers.\n");
- goto out;
- }
- ret = 0;
- if ((ret = drm_bo_clean_mm(dev, arg->mem_type, 0))) {
- if (ret == -EINVAL)
- DRM_ERROR("Memory manager type %d not clean. "
- "Delaying takedown\n", arg->mem_type);
- ret = 0;
- }
-out:
- mutex_unlock(&dev->struct_mutex);
- (void) drm_bo_write_unlock(&bm->bm_lock, file_priv);
-
- if (ret)
- return ret;
-
- return 0;
-}
-
-int drm_mm_lock_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_mm_type_arg *arg = data;
- struct drm_bo_driver *driver = dev->driver->bo_driver;
- int ret;
-
- if (!driver) {
- DRM_ERROR("Buffer objects are not supported by this driver\n");
- return -EINVAL;
- }
-
- if (arg->lock_flags & DRM_BO_LOCK_IGNORE_NO_EVICT) {
- DRM_ERROR("Lock flag DRM_BO_LOCK_IGNORE_NO_EVICT not supported yet.\n");
- return -EINVAL;
- }
-
- if (arg->lock_flags & DRM_BO_LOCK_UNLOCK_BM) {
- ret = drm_bo_write_lock(&dev->bm.bm_lock, 1, file_priv);
- if (ret)
- return ret;
- }
-
- mutex_lock(&dev->struct_mutex);
- ret = drm_bo_lock_mm(dev, arg->mem_type);
- mutex_unlock(&dev->struct_mutex);
- if (ret) {
- (void) drm_bo_write_unlock(&dev->bm.bm_lock, file_priv);
- return ret;
- }
-
- return 0;
-}
-
-int drm_mm_unlock_ioctl(struct drm_device *dev,
- void *data,
- struct drm_file *file_priv)
-{
- struct drm_mm_type_arg *arg = data;
- struct drm_bo_driver *driver = dev->driver->bo_driver;
- int ret;
-
- if (!driver) {
- DRM_ERROR("Buffer objects are not supported by this driver\n");
- return -EINVAL;
- }
-
- if (arg->lock_flags & DRM_BO_LOCK_UNLOCK_BM) {
- ret = drm_bo_write_unlock(&dev->bm.bm_lock, file_priv);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-int drm_mm_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- struct drm_mm_info_arg *arg = data;
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_bo_driver *driver = dev->driver->bo_driver;
- struct drm_mem_type_manager *man;
- int ret = 0;
- int mem_type = arg->mem_type;
-
- if (!driver) {
- DRM_ERROR("Buffer objects are not supported by this driver\n");
- return -EINVAL;
- }
-
- if (mem_type >= DRM_BO_MEM_TYPES) {
- DRM_ERROR("Illegal memory type %d\n", arg->mem_type);
- return -EINVAL;
- }
-
- mutex_lock(&dev->struct_mutex);
- if (!bm->initialized) {
- DRM_ERROR("DRM memory manager was not initialized\n");
- ret = -EINVAL;
- goto out;
- }
-
-
- man = &bm->man[arg->mem_type];
-
- arg->p_size = man->size;
-
-out:
- mutex_unlock(&dev->struct_mutex);
-
- return ret;
-}
-/*
- * buffer object vm functions.
- */
-
-int drm_mem_reg_is_pci(struct drm_device *dev, struct drm_bo_mem_reg *mem)
-{
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_mem_type_manager *man = &bm->man[mem->mem_type];
-
- if (!(man->flags & _DRM_FLAG_MEMTYPE_FIXED)) {
- if (mem->mem_type == DRM_BO_MEM_LOCAL)
- return 0;
-
- if (man->flags & _DRM_FLAG_MEMTYPE_CMA)
- return 0;
-
- if (mem->flags & DRM_BO_FLAG_CACHED)
- return 0;
- }
- return 1;
-}
-EXPORT_SYMBOL(drm_mem_reg_is_pci);
-
-/**
- * \c Get the PCI offset for the buffer object memory.
- *
- * \param bo The buffer object.
- * \param bus_base On return the base of the PCI region
- * \param bus_offset On return the byte offset into the PCI region
- * \param bus_size On return the byte size of the buffer object or zero if
- * the buffer object memory is not accessible through a PCI region.
- * \return Failure indication.
- *
- * Returns -EINVAL if the buffer object is currently not mappable.
- * Otherwise returns zero.
- */
-
-int drm_bo_pci_offset(struct drm_device *dev,
- struct drm_bo_mem_reg *mem,
- unsigned long *bus_base,
- unsigned long *bus_offset, unsigned long *bus_size)
-{
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_mem_type_manager *man = &bm->man[mem->mem_type];
-
- *bus_size = 0;
- if (!(man->flags & _DRM_FLAG_MEMTYPE_MAPPABLE))
- return -EINVAL;
-
- if (drm_mem_reg_is_pci(dev, mem)) {
- *bus_offset = mem->mm_node->start << PAGE_SHIFT;
- *bus_size = mem->num_pages << PAGE_SHIFT;
- *bus_base = man->io_offset;
- }
-
- return 0;
-}
-
-/**
- * \c Kill all user-space virtual mappings of this buffer object.
- *
- * \param bo The buffer object.
- *
- * Call bo->mutex locked.
- */
-
-void drm_bo_unmap_virtual(struct drm_buffer_object *bo)
-{
- struct drm_device *dev = bo->dev;
- loff_t offset = ((loff_t) bo->map_list.hash.key) << PAGE_SHIFT;
- loff_t holelen = ((loff_t) bo->mem.num_pages) << PAGE_SHIFT;
-
- if (!dev->dev_mapping)
- return;
-
- unmap_mapping_range(dev->dev_mapping, offset, holelen, 1);
-}
-
-/**
- * drm_bo_takedown_vm_locked:
- *
- * @bo: the buffer object to remove any drm device mapping
- *
- * Remove any associated vm mapping on the drm device node that
- * would have been created for a drm_bo_type_device buffer
- */
-static void drm_bo_takedown_vm_locked(struct drm_buffer_object *bo)
-{
- struct drm_map_list *list;
- drm_local_map_t *map;
- struct drm_device *dev = bo->dev;
-
- DRM_ASSERT_LOCKED(&dev->struct_mutex);
- if (bo->type != drm_bo_type_device)
- return;
-
- list = &bo->map_list;
- if (list->user_token) {
- drm_ht_remove_item(&dev->map_hash, &list->hash);
- list->user_token = 0;
- }
- if (list->file_offset_node) {
- drm_mm_put_block(list->file_offset_node);
- list->file_offset_node = NULL;
- }
-
- map = list->map;
- if (!map)
- return;
-
- drm_ctl_free(map, sizeof(*map), DRM_MEM_BUFOBJ);
- list->map = NULL;
- list->user_token = 0ULL;
- drm_bo_usage_deref_locked(&bo);
-}
-
-/**
- * drm_bo_setup_vm_locked:
- *
- * @bo: the buffer to allocate address space for
- *
- * Allocate address space in the drm device so that applications
- * can mmap the buffer and access the contents. This only
- * applies to drm_bo_type_device objects as others are not
- * placed in the drm device address space.
- */
-static int drm_bo_setup_vm_locked(struct drm_buffer_object *bo)
-{
- struct drm_map_list *list = &bo->map_list;
- drm_local_map_t *map;
- struct drm_device *dev = bo->dev;
-
- DRM_ASSERT_LOCKED(&dev->struct_mutex);
- list->map = drm_ctl_calloc(1, sizeof(*map), DRM_MEM_BUFOBJ);
- if (!list->map)
- return -ENOMEM;
-
- map = list->map;
- map->offset = 0;
- map->type = _DRM_TTM;
- map->flags = _DRM_REMOVABLE;
- map->size = bo->mem.num_pages * PAGE_SIZE;
- atomic_inc(&bo->usage);
- map->handle = (void *)bo;
-
- list->file_offset_node = drm_mm_search_free(&dev->offset_manager,
- bo->mem.num_pages, 0, 0);
-
- if (unlikely(!list->file_offset_node)) {
- drm_bo_takedown_vm_locked(bo);
- return -ENOMEM;
- }
-
- list->file_offset_node = drm_mm_get_block(list->file_offset_node,
- bo->mem.num_pages, 0);
-
- if (unlikely(!list->file_offset_node)) {
- drm_bo_takedown_vm_locked(bo);
- return -ENOMEM;
- }
-
- list->hash.key = list->file_offset_node->start;
- if (drm_ht_insert_item(&dev->map_hash, &list->hash)) {
- drm_bo_takedown_vm_locked(bo);
- return -ENOMEM;
- }
-
- list->user_token = ((uint64_t) list->hash.key) << PAGE_SHIFT;
-
- return 0;
-}
-
-int drm_bo_version_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv)
-{
- struct drm_bo_version_arg *arg = (struct drm_bo_version_arg *)data;
-
- arg->major = DRM_BO_INIT_MAJOR;
- arg->minor = DRM_BO_INIT_MINOR;
- arg->patchlevel = DRM_BO_INIT_PATCH;
-
- return 0;
-}
diff --git a/linux-core/drm_bo_lock.c b/linux-core/drm_bo_lock.c
deleted file mode 100644
index 08b1c6be..00000000
--- a/linux-core/drm_bo_lock.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/**************************************************************************
- *
- * Copyright (c) 2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-/*
- * This file implements a simple replacement for the buffer manager use
- * of the heavyweight hardware lock.
- * The lock is a read-write lock. Taking it in read mode is fast, and
- * intended for in-kernel use only.
- * Taking it in write mode is slow.
- *
- * The write mode is used only when there is a need to block all
- * user-space processes from allocating a
- * new memory area.
- * Typical use in write mode is X server VT switching, and it's allowed
- * to leave kernel space with the write lock held. If a user-space process
- * dies while having the write-lock, it will be released during the file
- * descriptor release.
- *
- * The read lock is typically placed at the start of an IOCTL- or
- * user-space callable function that may end up allocating a memory area.
- * This includes setstatus, super-ioctls and no_pfn; the latter may move
- * unmappable regions to mappable. It's a bug to leave kernel space with the
- * read lock held.
- *
- * Both read- and write lock taking may be interruptible for low signal-delivery
- * latency. The locking functions will return -EAGAIN if interrupted by a
- * signal.
- *
- * Locking order: The lock should be taken BEFORE any kernel mutexes
- * or spinlocks.
- */
-
-#include "drmP.h"
-
-void drm_bo_init_lock(struct drm_bo_lock *lock)
-{
- DRM_INIT_WAITQUEUE(&lock->queue);
- atomic_set(&lock->write_lock_pending, 0);
- atomic_set(&lock->readers, 0);
-}
-
-void drm_bo_read_unlock(struct drm_bo_lock *lock)
-{
- if (atomic_dec_and_test(&lock->readers))
- wake_up_all(&lock->queue);
-}
-EXPORT_SYMBOL(drm_bo_read_unlock);
-
-int drm_bo_read_lock(struct drm_bo_lock *lock, int interruptible)
-{
- while (unlikely(atomic_read(&lock->write_lock_pending) != 0)) {
- int ret;
-
- if (!interruptible) {
- wait_event(lock->queue,
- atomic_read(&lock->write_lock_pending) == 0);
- continue;
- }
- ret = wait_event_interruptible
- (lock->queue, atomic_read(&lock->write_lock_pending) == 0);
- if (ret)
- return -EAGAIN;
- }
-
- while (unlikely(!atomic_add_unless(&lock->readers, 1, -1))) {
- int ret;
- if (!interruptible) {
- wait_event(lock->queue,
- atomic_read(&lock->readers) != -1);
- continue;
- }
- ret = wait_event_interruptible
- (lock->queue, atomic_read(&lock->readers) != -1);
- if (ret)
- return -EAGAIN;
- }
- return 0;
-}
-EXPORT_SYMBOL(drm_bo_read_lock);
-
-static int __drm_bo_write_unlock(struct drm_bo_lock *lock)
-{
- if (unlikely(atomic_cmpxchg(&lock->readers, -1, 0) != -1))
- return -EINVAL;
- wake_up_all(&lock->queue);
- return 0;
-}
-
-static void drm_bo_write_lock_remove(struct drm_file *file_priv,
- struct drm_user_object *item)
-{
- struct drm_bo_lock *lock = container_of(item, struct drm_bo_lock, base);
- int ret;
-
- ret = __drm_bo_write_unlock(lock);
- BUG_ON(ret);
-}
-
-int drm_bo_write_lock(struct drm_bo_lock *lock, int interruptible,
- struct drm_file *file_priv)
-{
- int ret = 0;
- struct drm_device *dev;
-
- atomic_inc(&lock->write_lock_pending);
-
- while (unlikely(atomic_cmpxchg(&lock->readers, 0, -1) != 0)) {
- if (!interruptible) {
- wait_event(lock->queue,
- atomic_read(&lock->readers) == 0);
- continue;
- }
- ret = wait_event_interruptible
- (lock->queue, atomic_read(&lock->readers) == 0);
-
- if (ret) {
- atomic_dec(&lock->write_lock_pending);
- wake_up_all(&lock->queue);
- return -EAGAIN;
- }
- }
-
- /*
- * Add a dummy user-object, the destructor of which will
- * make sure the lock is released if the client dies
- * while holding it.
- */
-
- if (atomic_dec_and_test(&lock->write_lock_pending))
- wake_up_all(&lock->queue);
- dev = file_priv->minor->dev;
- mutex_lock(&dev->struct_mutex);
- ret = drm_add_user_object(file_priv, &lock->base, 0);
- lock->base.remove = &drm_bo_write_lock_remove;
- lock->base.type = drm_lock_type;
- if (ret)
- (void)__drm_bo_write_unlock(lock);
-
- mutex_unlock(&dev->struct_mutex);
-
- return ret;
-}
-
-int drm_bo_write_unlock(struct drm_bo_lock *lock, struct drm_file *file_priv)
-{
- struct drm_device *dev = file_priv->minor->dev;
- struct drm_ref_object *ro;
-
- mutex_lock(&dev->struct_mutex);
-
- if (lock->base.owner != file_priv) {
- mutex_unlock(&dev->struct_mutex);
- return -EINVAL;
- }
- ro = drm_lookup_ref_object(file_priv, &lock->base, _DRM_REF_USE);
- BUG_ON(!ro);
- drm_remove_ref_object(file_priv, ro);
- lock->base.owner = NULL;
-
- mutex_unlock(&dev->struct_mutex);
- return 0;
-}
diff --git a/linux-core/drm_bo_move.c b/linux-core/drm_bo_move.c
deleted file mode 100644
index d794e985..00000000
--- a/linux-core/drm_bo_move.c
+++ /dev/null
@@ -1,614 +0,0 @@
-/**************************************************************************
- *
- * Copyright (c) 2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-
-/**
- * Free the old memory node unless it's a pinned region and we
- * have not been requested to free also pinned regions.
- */
-
-static void drm_bo_free_old_node(struct drm_buffer_object *bo)
-{
- struct drm_bo_mem_reg *old_mem = &bo->mem;
-
- if (old_mem->mm_node && (old_mem->mm_node != bo->pinned_node)) {
- mutex_lock(&bo->dev->struct_mutex);
- drm_mm_put_block(old_mem->mm_node);
- mutex_unlock(&bo->dev->struct_mutex);
- }
- old_mem->mm_node = NULL;
-}
-
-int drm_bo_move_ttm(struct drm_buffer_object *bo,
- int evict, int no_wait, struct drm_bo_mem_reg *new_mem)
-{
- struct drm_ttm *ttm = bo->ttm;
- struct drm_bo_mem_reg *old_mem = &bo->mem;
- uint64_t save_flags = old_mem->flags;
- uint64_t save_proposed_flags = old_mem->proposed_flags;
- int ret;
-
- if (old_mem->mem_type != DRM_BO_MEM_LOCAL) {
- if (evict)
- drm_ttm_evict(ttm);
- else
- drm_ttm_unbind(ttm);
-
- drm_bo_free_old_node(bo);
- DRM_FLAG_MASKED(old_mem->flags,
- DRM_BO_FLAG_CACHED | DRM_BO_FLAG_MAPPABLE |
- DRM_BO_FLAG_MEM_LOCAL, DRM_BO_MASK_MEMTYPE);
- old_mem->mem_type = DRM_BO_MEM_LOCAL;
- save_flags = old_mem->flags;
- }
- if (new_mem->mem_type != DRM_BO_MEM_LOCAL) {
- ret = drm_ttm_bind(ttm, new_mem);
- if (ret)
- return ret;
- }
-
- *old_mem = *new_mem;
- new_mem->mm_node = NULL;
- old_mem->proposed_flags = save_proposed_flags;
- DRM_FLAG_MASKED(save_flags, new_mem->flags, DRM_BO_MASK_MEMTYPE);
- return 0;
-}
-EXPORT_SYMBOL(drm_bo_move_ttm);
-
-/**
- * \c Return a kernel virtual address to the buffer object PCI memory.
- *
- * \param bo The buffer object.
- * \return Failure indication.
- *
- * Returns -EINVAL if the buffer object is currently not mappable.
- * Returns -ENOMEM if the ioremap operation failed.
- * Otherwise returns zero.
- *
- * After a successfull call, bo->iomap contains the virtual address, or NULL
- * if the buffer object content is not accessible through PCI space.
- * Call bo->mutex locked.
- */
-
-int drm_mem_reg_ioremap(struct drm_device *dev, struct drm_bo_mem_reg *mem,
- void **virtual)
-{
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_mem_type_manager *man = &bm->man[mem->mem_type];
- unsigned long bus_offset;
- unsigned long bus_size;
- unsigned long bus_base;
- int ret;
- void *addr;
-
- *virtual = NULL;
- ret = drm_bo_pci_offset(dev, mem, &bus_base, &bus_offset, &bus_size);
- if (ret || bus_size == 0)
- return ret;
-
- if (!(man->flags & _DRM_FLAG_NEEDS_IOREMAP))
- addr = (void *)(((u8 *) man->io_addr) + bus_offset);
- else {
- addr = ioremap_nocache(bus_base + bus_offset, bus_size);
- if (!addr)
- return -ENOMEM;
- }
- *virtual = addr;
- return 0;
-}
-EXPORT_SYMBOL(drm_mem_reg_ioremap);
-
-/**
- * \c Unmap mapping obtained using drm_bo_ioremap
- *
- * \param bo The buffer object.
- *
- * Call bo->mutex locked.
- */
-
-void drm_mem_reg_iounmap(struct drm_device *dev, struct drm_bo_mem_reg *mem,
- void *virtual)
-{
- struct drm_buffer_manager *bm;
- struct drm_mem_type_manager *man;
-
- bm = &dev->bm;
- man = &bm->man[mem->mem_type];
-
- if (virtual && (man->flags & _DRM_FLAG_NEEDS_IOREMAP))
- iounmap(virtual);
-}
-
-static int drm_copy_io_page(void *dst, void *src, unsigned long page)
-{
- uint32_t *dstP =
- (uint32_t *) ((unsigned long)dst + (page << PAGE_SHIFT));
- uint32_t *srcP =
- (uint32_t *) ((unsigned long)src + (page << PAGE_SHIFT));
-
- int i;
- for (i = 0; i < PAGE_SIZE / sizeof(uint32_t); ++i)
- iowrite32(ioread32(srcP++), dstP++);
- return 0;
-}
-
-static int drm_copy_io_ttm_page(struct drm_ttm *ttm, void *src,
- unsigned long page)
-{
- struct page *d = drm_ttm_get_page(ttm, page);
- void *dst;
-
- if (!d)
- return -ENOMEM;
-
- src = (void *)((unsigned long)src + (page << PAGE_SHIFT));
- dst = kmap(d);
- if (!dst)
- return -ENOMEM;
-
- memcpy_fromio(dst, src, PAGE_SIZE);
- kunmap(d);
- return 0;
-}
-
-static int drm_copy_ttm_io_page(struct drm_ttm *ttm, void *dst, unsigned long page)
-{
- struct page *s = drm_ttm_get_page(ttm, page);
- void *src;
-
- if (!s)
- return -ENOMEM;
-
- dst = (void *)((unsigned long)dst + (page << PAGE_SHIFT));
- src = kmap(s);
- if (!src)
- return -ENOMEM;
-
- memcpy_toio(dst, src, PAGE_SIZE);
- kunmap(s);
- return 0;
-}
-
-int drm_bo_move_memcpy(struct drm_buffer_object *bo,
- int evict, int no_wait, struct drm_bo_mem_reg *new_mem)
-{
- struct drm_device *dev = bo->dev;
- struct drm_mem_type_manager *man = &dev->bm.man[new_mem->mem_type];
- struct drm_ttm *ttm = bo->ttm;
- struct drm_bo_mem_reg *old_mem = &bo->mem;
- struct drm_bo_mem_reg old_copy = *old_mem;
- void *old_iomap;
- void *new_iomap;
- int ret;
- uint64_t save_flags = old_mem->flags;
- uint64_t save_proposed_flags = old_mem->proposed_flags;
- unsigned long i;
- unsigned long page;
- unsigned long add = 0;
- int dir;
-
- ret = drm_mem_reg_ioremap(dev, old_mem, &old_iomap);
- if (ret)
- return ret;
- ret = drm_mem_reg_ioremap(dev, new_mem, &new_iomap);
- if (ret)
- goto out;
-
- if (old_iomap == NULL && new_iomap == NULL)
- goto out2;
- if (old_iomap == NULL && ttm == NULL)
- goto out2;
-
- add = 0;
- dir = 1;
-
- if ((old_mem->mem_type == new_mem->mem_type) &&
- (new_mem->mm_node->start <
- old_mem->mm_node->start + old_mem->mm_node->size)) {
- dir = -1;
- add = new_mem->num_pages - 1;
- }
-
- for (i = 0; i < new_mem->num_pages; ++i) {
- page = i * dir + add;
- if (old_iomap == NULL)
- ret = drm_copy_ttm_io_page(ttm, new_iomap, page);
- else if (new_iomap == NULL)
- ret = drm_copy_io_ttm_page(ttm, old_iomap, page);
- else
- ret = drm_copy_io_page(new_iomap, old_iomap, page);
- if (ret)
- goto out1;
- }
- mb();
-out2:
- drm_bo_free_old_node(bo);
-
- *old_mem = *new_mem;
- new_mem->mm_node = NULL;
- old_mem->proposed_flags = save_proposed_flags;
- DRM_FLAG_MASKED(save_flags, new_mem->flags, DRM_BO_MASK_MEMTYPE);
-
- if ((man->flags & _DRM_FLAG_MEMTYPE_FIXED) && (ttm != NULL)) {
- drm_ttm_unbind(ttm);
- drm_ttm_destroy(ttm);
- bo->ttm = NULL;
- }
-
-out1:
- drm_mem_reg_iounmap(dev, new_mem, new_iomap);
-out:
- drm_mem_reg_iounmap(dev, &old_copy, old_iomap);
- return ret;
-}
-EXPORT_SYMBOL(drm_bo_move_memcpy);
-
-/*
- * Transfer a buffer object's memory and LRU status to a newly
- * created object. User-space references remains with the old
- * object. Call bo->mutex locked.
- */
-
-int drm_buffer_object_transfer(struct drm_buffer_object *bo,
- struct drm_buffer_object **new_obj)
-{
- struct drm_buffer_object *fbo;
- struct drm_device *dev = bo->dev;
- struct drm_buffer_manager *bm = &dev->bm;
-
- fbo = drm_ctl_calloc(1, sizeof(*fbo), DRM_MEM_BUFOBJ);
- if (!fbo)
- return -ENOMEM;
-
- *fbo = *bo;
- mutex_init(&fbo->mutex);
- mutex_lock(&fbo->mutex);
- mutex_lock(&dev->struct_mutex);
-
- DRM_INIT_WAITQUEUE(&bo->event_queue);
- INIT_LIST_HEAD(&fbo->ddestroy);
- INIT_LIST_HEAD(&fbo->lru);
- INIT_LIST_HEAD(&fbo->pinned_lru);
-
- fbo->fence = drm_fence_reference_locked(bo->fence);
- fbo->pinned_node = NULL;
- fbo->mem.mm_node->private = (void *)fbo;
- atomic_set(&fbo->usage, 1);
- atomic_inc(&bm->count);
- mutex_unlock(&dev->struct_mutex);
- mutex_unlock(&fbo->mutex);
-
- *new_obj = fbo;
- return 0;
-}
-
-/*
- * Since move is underway, we need to block signals in this function.
- * We cannot restart until it has finished.
- */
-
-int drm_bo_move_accel_cleanup(struct drm_buffer_object *bo,
- int evict, int no_wait, uint32_t fence_class,
- uint32_t fence_type, uint32_t fence_flags,
- struct drm_bo_mem_reg *new_mem)
-{
- struct drm_device *dev = bo->dev;
- struct drm_mem_type_manager *man = &dev->bm.man[new_mem->mem_type];
- struct drm_bo_mem_reg *old_mem = &bo->mem;
- int ret;
- uint64_t save_flags = old_mem->flags;
- uint64_t save_proposed_flags = old_mem->proposed_flags;
- struct drm_buffer_object *old_obj;
-
- if (bo->fence)
- drm_fence_usage_deref_unlocked(&bo->fence);
- ret = drm_fence_object_create(dev, fence_class, fence_type,
- fence_flags | DRM_FENCE_FLAG_EMIT,
- &bo->fence);
- bo->fence_type = fence_type;
- if (ret)
- return ret;
-
- if (evict || ((bo->mem.mm_node == bo->pinned_node) &&
- bo->mem.mm_node != NULL))
- {
- if (bo->fence) {
- (void) drm_fence_object_wait(bo->fence, 0, 1,
- bo->fence_type);
- drm_fence_usage_deref_unlocked(&bo->fence);
- }
- drm_bo_free_old_node(bo);
-
- if ((man->flags & _DRM_FLAG_MEMTYPE_FIXED) && (bo->ttm != NULL)) {
- drm_ttm_unbind(bo->ttm);
- drm_ttm_destroy(bo->ttm);
- bo->ttm = NULL;
- }
- } else {
-
- /* This should help pipeline ordinary buffer moves.
- *
- * Hang old buffer memory on a new buffer object,
- * and leave it to be released when the GPU
- * operation has completed.
- */
-
- ret = drm_buffer_object_transfer(bo, &old_obj);
-
- if (ret)
- return ret;
-
- if (!(man->flags & _DRM_FLAG_MEMTYPE_FIXED))
- old_obj->ttm = NULL;
- else
- bo->ttm = NULL;
-
- mutex_lock(&dev->struct_mutex);
- list_del_init(&old_obj->lru);
- DRM_FLAG_MASKED(bo->priv_flags, 0, _DRM_BO_FLAG_UNFENCED);
- drm_bo_add_to_lru(old_obj);
-
- drm_bo_usage_deref_locked(&old_obj);
- mutex_unlock(&dev->struct_mutex);
-
- }
-
- *old_mem = *new_mem;
- new_mem->mm_node = NULL;
- old_mem->proposed_flags = save_proposed_flags;
- DRM_FLAG_MASKED(save_flags, new_mem->flags, DRM_BO_MASK_MEMTYPE);
- return 0;
-}
-EXPORT_SYMBOL(drm_bo_move_accel_cleanup);
-
-int drm_bo_same_page(unsigned long offset,
- unsigned long offset2)
-{
- return (offset & PAGE_MASK) == (offset2 & PAGE_MASK);
-}
-EXPORT_SYMBOL(drm_bo_same_page);
-
-unsigned long drm_bo_offset_end(unsigned long offset,
- unsigned long end)
-{
- offset = (offset + PAGE_SIZE) & PAGE_MASK;
- return (end < offset) ? end : offset;
-}
-EXPORT_SYMBOL(drm_bo_offset_end);
-
-static pgprot_t drm_kernel_io_prot(uint32_t map_type)
-{
- pgprot_t tmp = PAGE_KERNEL;
-
-#if defined(__i386__) || defined(__x86_64__)
-#ifdef USE_PAT_WC
-#warning using pat
- if (drm_use_pat() && map_type == _DRM_TTM) {
- pgprot_val(tmp) |= _PAGE_PAT;
- return tmp;
- }
-#endif
- if (boot_cpu_data.x86 > 3 && map_type != _DRM_AGP) {
- pgprot_val(tmp) |= _PAGE_PCD;
- pgprot_val(tmp) &= ~_PAGE_PWT;
- }
-#elif defined(__powerpc__)
- pgprot_val(tmp) |= _PAGE_NO_CACHE;
- if (map_type == _DRM_REGISTERS)
- pgprot_val(tmp) |= _PAGE_GUARDED;
-#endif
-#if defined(__ia64__)
- if (map_type == _DRM_TTM)
- tmp = pgprot_writecombine(tmp);
- else
- tmp = pgprot_noncached(tmp);
-#endif
- return tmp;
-}
-
-static int drm_bo_ioremap(struct drm_buffer_object *bo, unsigned long bus_base,
- unsigned long bus_offset, unsigned long bus_size,
- struct drm_bo_kmap_obj *map)
-{
- struct drm_device *dev = bo->dev;
- struct drm_bo_mem_reg *mem = &bo->mem;
- struct drm_mem_type_manager *man = &dev->bm.man[mem->mem_type];
-
- if (!(man->flags & _DRM_FLAG_NEEDS_IOREMAP)) {
- map->bo_kmap_type = bo_map_premapped;
- map->virtual = (void *)(((u8 *) man->io_addr) + bus_offset);
- } else {
- map->bo_kmap_type = bo_map_iomap;
- map->virtual = ioremap_nocache(bus_base + bus_offset, bus_size);
- }
- return (!map->virtual) ? -ENOMEM : 0;
-}
-
-static int drm_bo_kmap_ttm(struct drm_buffer_object *bo,
- unsigned long start_page, unsigned long num_pages,
- struct drm_bo_kmap_obj *map)
-{
- struct drm_device *dev = bo->dev;
- struct drm_bo_mem_reg *mem = &bo->mem;
- struct drm_mem_type_manager *man = &dev->bm.man[mem->mem_type];
- pgprot_t prot;
- struct drm_ttm *ttm = bo->ttm;
- struct page *d;
- int i;
-
- BUG_ON(!ttm);
-
- if (num_pages == 1 && (mem->flags & DRM_BO_FLAG_CACHED)) {
-
- /*
- * We're mapping a single page, and the desired
- * page protection is consistent with the bo.
- */
-
- map->bo_kmap_type = bo_map_kmap;
- map->page = drm_ttm_get_page(ttm, start_page);
- map->virtual = kmap(map->page);
- } else {
- /*
- * Populate the part we're mapping;
- */
-
- for (i = start_page; i < start_page + num_pages; ++i) {
- d = drm_ttm_get_page(ttm, i);
- if (!d)
- return -ENOMEM;
- }
-
- /*
- * We need to use vmap to get the desired page protection
- * or to make the buffer object look contigous.
- */
-
- prot = (mem->flags & DRM_BO_FLAG_CACHED) ?
- PAGE_KERNEL :
- drm_kernel_io_prot(man->drm_bus_maptype);
- map->bo_kmap_type = bo_map_vmap;
- map->virtual = vmap(ttm->pages + start_page,
- num_pages, 0, prot);
- }
- return (!map->virtual) ? -ENOMEM : 0;
-}
-
-/*
- * This function is to be used for kernel mapping of buffer objects.
- * It chooses the appropriate mapping method depending on the memory type
- * and caching policy the buffer currently has.
- * Mapping multiple pages or buffers that live in io memory is a bit slow and
- * consumes vmalloc space. Be restrictive with such mappings.
- * Mapping single pages usually returns the logical kernel address,
- * (which is fast)
- * BUG may use slower temporary mappings for high memory pages or
- * uncached / write-combined pages.
- *
- * The function fills in a drm_bo_kmap_obj which can be used to return the
- * kernel virtual address of the buffer.
- *
- * Code servicing a non-priviliged user request is only allowed to map one
- * page at a time. We might need to implement a better scheme to stop such
- * processes from consuming all vmalloc space.
- */
-
-int drm_bo_kmap(struct drm_buffer_object *bo, unsigned long start_page,
- unsigned long num_pages, struct drm_bo_kmap_obj *map)
-{
- int ret;
- unsigned long bus_base;
- unsigned long bus_offset;
- unsigned long bus_size;
-
- map->virtual = NULL;
-
- if (num_pages > bo->num_pages)
- return -EINVAL;
- if (start_page > bo->num_pages)
- return -EINVAL;
-#if 0
- if (num_pages > 1 && !DRM_SUSER(DRM_CURPROC))
- return -EPERM;
-#endif
- ret = drm_bo_pci_offset(bo->dev, &bo->mem, &bus_base,
- &bus_offset, &bus_size);
-
- if (ret)
- return ret;
-
- if (bus_size == 0) {
- return drm_bo_kmap_ttm(bo, start_page, num_pages, map);
- } else {
- bus_offset += start_page << PAGE_SHIFT;
- bus_size = num_pages << PAGE_SHIFT;
- return drm_bo_ioremap(bo, bus_base, bus_offset, bus_size, map);
- }
-}
-EXPORT_SYMBOL(drm_bo_kmap);
-
-void drm_bo_kunmap(struct drm_bo_kmap_obj *map)
-{
- if (!map->virtual)
- return;
-
- switch (map->bo_kmap_type) {
- case bo_map_iomap:
- iounmap(map->virtual);
- break;
- case bo_map_vmap:
- vunmap(map->virtual);
- break;
- case bo_map_kmap:
- kunmap(map->page);
- break;
- case bo_map_premapped:
- break;
- default:
- BUG();
- }
- map->virtual = NULL;
- map->page = NULL;
-}
-EXPORT_SYMBOL(drm_bo_kunmap);
-
-int drm_bo_pfn_prot(struct drm_buffer_object *bo,
- unsigned long dst_offset,
- unsigned long *pfn,
- pgprot_t *prot)
-{
- struct drm_bo_mem_reg *mem = &bo->mem;
- struct drm_device *dev = bo->dev;
- unsigned long bus_offset;
- unsigned long bus_size;
- unsigned long bus_base;
- struct drm_mem_type_manager *man = &dev->bm.man[mem->mem_type];
- int ret;
-
- ret = drm_bo_pci_offset(dev, mem, &bus_base, &bus_offset,
- &bus_size);
- if (ret)
- return -EINVAL;
-
- if (bus_size != 0)
- *pfn = (bus_base + bus_offset + dst_offset) >> PAGE_SHIFT;
- else if (!bo->ttm)
- return -EINVAL;
- else
- *pfn = page_to_pfn(drm_ttm_get_page(bo->ttm, dst_offset >> PAGE_SHIFT));
-
- *prot = (mem->flags & DRM_BO_FLAG_CACHED) ?
- PAGE_KERNEL : drm_kernel_io_prot(man->drm_bus_maptype);
-
- return 0;
-}
-EXPORT_SYMBOL(drm_bo_pfn_prot);
-
diff --git a/linux-core/drm_compat.c b/linux-core/drm_compat.c
index 0ccd2ab3..3bf9d100 100644
--- a/linux-core/drm_compat.c
+++ b/linux-core/drm_compat.c
@@ -151,102 +151,3 @@ void idr_remove_all(struct idr *idp)
EXPORT_SYMBOL(idr_remove_all);
#endif /* DRM_IDR_COMPAT_FN */
-
-
-#ifdef DRM_NO_FAULT
-unsigned long drm_bo_vm_nopfn(struct vm_area_struct *vma,
- unsigned long address)
-{
- struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
- unsigned long page_offset;
- struct page *page = NULL;
- struct drm_ttm *ttm;
- struct drm_device *dev;
- unsigned long pfn;
- int err;
- unsigned long bus_base;
- unsigned long bus_offset;
- unsigned long bus_size;
- unsigned long ret = NOPFN_REFAULT;
-
- if (address > vma->vm_end)
- return NOPFN_SIGBUS;
-
- dev = bo->dev;
- err = drm_bo_read_lock(&dev->bm.bm_lock, 1);
- if (err)
- return NOPFN_REFAULT;
-
- err = mutex_lock_interruptible(&bo->mutex);
- if (err) {
- drm_bo_read_unlock(&dev->bm.bm_lock);
- return NOPFN_REFAULT;
- }
-
- err = drm_bo_wait(bo, 0, 1, 0, 1);
- if (err) {
- ret = (err != -EAGAIN) ? NOPFN_SIGBUS : NOPFN_REFAULT;
- bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
- goto out_unlock;
- }
-
- bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
-
- /*
- * If buffer happens to be in a non-mappable location,
- * move it to a mappable.
- */
-
- if (!(bo->mem.flags & DRM_BO_FLAG_MAPPABLE)) {
- uint32_t new_flags = bo->mem.proposed_flags |
- DRM_BO_FLAG_MAPPABLE |
- DRM_BO_FLAG_FORCE_MAPPABLE;
- err = drm_bo_move_buffer(bo, new_flags, 0, 0);
- if (err) {
- ret = (err != -EAGAIN) ? NOPFN_SIGBUS : NOPFN_REFAULT;
- goto out_unlock;
- }
- }
-
- err = drm_bo_pci_offset(dev, &bo->mem, &bus_base, &bus_offset,
- &bus_size);
-
- if (err) {
- ret = NOPFN_SIGBUS;
- goto out_unlock;
- }
-
- page_offset = (address - vma->vm_start) >> PAGE_SHIFT;
-
- if (bus_size) {
- struct drm_mem_type_manager *man = &dev->bm.man[bo->mem.mem_type];
-
- pfn = ((bus_base + bus_offset) >> PAGE_SHIFT) + page_offset;
- vma->vm_page_prot = drm_io_prot(man->drm_bus_maptype, vma);
- } else {
- ttm = bo->ttm;
-
- drm_ttm_fixup_caching(ttm);
- page = drm_ttm_get_page(ttm, page_offset);
- if (!page) {
- ret = NOPFN_OOM;
- goto out_unlock;
- }
- pfn = page_to_pfn(page);
- vma->vm_page_prot = (bo->mem.flags & DRM_BO_FLAG_CACHED) ?
- vm_get_page_prot(vma->vm_flags) :
- drm_io_prot(_DRM_TTM, vma);
- }
-
- err = vm_insert_pfn(vma, address, pfn);
- if (err) {
- ret = (err != -EAGAIN) ? NOPFN_OOM : NOPFN_REFAULT;
- goto out_unlock;
- }
-out_unlock:
- BUG_ON(bo->priv_flags & _DRM_BO_FLAG_UNLOCKED);
- mutex_unlock(&bo->mutex);
- drm_bo_read_unlock(&dev->bm.bm_lock);
- return ret;
-}
-#endif
diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c
index 72f0e98b..d3e2ca99 100644
--- a/linux-core/drm_drv.c
+++ b/linux-core/drm_drv.c
@@ -121,36 +121,6 @@ static struct drm_ioctl_desc drm_ioctls[] = {
DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
- DRM_IOCTL_DEF(DRM_IOCTL_MM_INIT, drm_mm_init_ioctl,
- DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
- DRM_IOCTL_DEF(DRM_IOCTL_MM_TAKEDOWN, drm_mm_takedown_ioctl,
- DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
- DRM_IOCTL_DEF(DRM_IOCTL_MM_LOCK, drm_mm_lock_ioctl,
- DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
- DRM_IOCTL_DEF(DRM_IOCTL_MM_UNLOCK, drm_mm_unlock_ioctl,
- DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-
- DRM_IOCTL_DEF(DRM_IOCTL_FENCE_CREATE, drm_fence_create_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_FENCE_REFERENCE, drm_fence_reference_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_FENCE_UNREFERENCE, drm_fence_unreference_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_FENCE_SIGNALED, drm_fence_signaled_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_FENCE_FLUSH, drm_fence_flush_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_FENCE_WAIT, drm_fence_wait_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_FENCE_EMIT, drm_fence_emit_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_FENCE_BUFFERS, drm_fence_buffers_ioctl, DRM_AUTH),
-
- DRM_IOCTL_DEF(DRM_IOCTL_BO_CREATE, drm_bo_create_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_BO_MAP, drm_bo_map_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_BO_UNMAP, drm_bo_unmap_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_BO_REFERENCE, drm_bo_reference_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_BO_UNREFERENCE, drm_bo_unreference_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_BO_SETSTATUS, drm_bo_setstatus_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_BO_INFO, drm_bo_info_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_BO_WAIT_IDLE, drm_bo_wait_idle_ioctl, DRM_AUTH),
- DRM_IOCTL_DEF(DRM_IOCTL_BO_VERSION, drm_bo_version_ioctl, 0),
-
- DRM_IOCTL_DEF(DRM_IOCTL_MM_INFO, drm_mm_info_ioctl, 0),
-
#if OS_HAS_GEM
DRM_IOCTL_DEF(DRM_IOCTL_GEM_CLOSE, drm_gem_close_ioctl, 0),
DRM_IOCTL_DEF(DRM_IOCTL_GEM_FLINK, drm_gem_flink_ioctl, DRM_AUTH),
@@ -183,8 +153,6 @@ int drm_lastclose(struct drm_device * dev)
* We can't do much about this function failing.
*/
- drm_bo_driver_finish(dev);
-
if (dev->driver->lastclose)
dev->driver->lastclose(dev);
DRM_DEBUG("driver lastclose completed\n");
@@ -283,7 +251,6 @@ int drm_lastclose(struct drm_device * dev)
dev->lock.file_priv = NULL;
wake_up_interruptible(&dev->lock.lock_queue);
}
- dev->dev_mapping = NULL;
mutex_unlock(&dev->struct_mutex);
DRM_DEBUG("lastclose completed\n");
@@ -398,7 +365,6 @@ static void drm_cleanup(struct drm_device * dev)
}
drm_lastclose(dev);
- drm_fence_manager_takedown(dev);
drm_vblank_cleanup(dev);
@@ -423,8 +389,6 @@ static void drm_cleanup(struct drm_device * dev)
drm_ctxbitmap_cleanup(dev);
drm_ht_remove(&dev->map_hash);
- drm_mm_takedown(&dev->offset_manager);
- drm_ht_remove(&dev->object_hash);
drm_put_minor(dev);
if (drm_put_dev(dev))
diff --git a/linux-core/drm_fence.c b/linux-core/drm_fence.c
deleted file mode 100644
index 7c78e09f..00000000
--- a/linux-core/drm_fence.c
+++ /dev/null
@@ -1,829 +0,0 @@
-/**************************************************************************
- *
- * Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-
-
-/*
- * Convenience function to be called by fence::wait methods that
- * need polling.
- */
-
-int drm_fence_wait_polling(struct drm_fence_object *fence, int lazy,
- int interruptible, uint32_t mask,
- unsigned long end_jiffies)
-{
- struct drm_device *dev = fence->dev;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_class_manager *fc = &fm->fence_class[fence->fence_class];
- uint32_t count = 0;
- int ret;
-
- DECLARE_WAITQUEUE(entry, current);
- add_wait_queue(&fc->fence_queue, &entry);
-
- ret = 0;
-
- for (;;) {
- __set_current_state((interruptible) ?
- TASK_INTERRUPTIBLE :
- TASK_UNINTERRUPTIBLE);
- if (drm_fence_object_signaled(fence, mask))
- break;
- if (time_after_eq(jiffies, end_jiffies)) {
- ret = -EBUSY;
- break;
- }
- if (lazy)
- schedule_timeout(1);
- else if ((++count & 0x0F) == 0){
- __set_current_state(TASK_RUNNING);
- schedule();
- __set_current_state((interruptible) ?
- TASK_INTERRUPTIBLE :
- TASK_UNINTERRUPTIBLE);
- }
- if (interruptible && signal_pending(current)) {
- ret = -EAGAIN;
- break;
- }
- }
- __set_current_state(TASK_RUNNING);
- remove_wait_queue(&fc->fence_queue, &entry);
- return ret;
-}
-EXPORT_SYMBOL(drm_fence_wait_polling);
-
-/*
- * Typically called by the IRQ handler.
- */
-
-void drm_fence_handler(struct drm_device *dev, uint32_t fence_class,
- uint32_t sequence, uint32_t type, uint32_t error)
-{
- int wake = 0;
- uint32_t diff;
- uint32_t relevant_type;
- uint32_t new_type;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_class_manager *fc = &fm->fence_class[fence_class];
- struct drm_fence_driver *driver = dev->driver->fence_driver;
- struct list_head *head;
- struct drm_fence_object *fence, *next;
- int found = 0;
-
- if (list_empty(&fc->ring))
- return;
-
- list_for_each_entry(fence, &fc->ring, ring) {
- diff = (sequence - fence->sequence) & driver->sequence_mask;
- if (diff > driver->wrap_diff) {
- found = 1;
- break;
- }
- }
-
- fc->waiting_types &= ~type;
- head = (found) ? &fence->ring : &fc->ring;
-
- list_for_each_entry_safe_reverse(fence, next, head, ring) {
- if (&fence->ring == &fc->ring)
- break;
-
- if (error) {
- fence->error = error;
- fence->signaled_types = fence->type;
- list_del_init(&fence->ring);
- wake = 1;
- break;
- }
-
- if (type & DRM_FENCE_TYPE_EXE)
- type |= fence->native_types;
-
- relevant_type = type & fence->type;
- new_type = (fence->signaled_types | relevant_type) ^
- fence->signaled_types;
-
- if (new_type) {
- fence->signaled_types |= new_type;
- DRM_DEBUG("Fence 0x%08lx signaled 0x%08x\n",
- fence->base.hash.key, fence->signaled_types);
-
- if (driver->needed_flush)
- fc->pending_flush |= driver->needed_flush(fence);
-
- if (new_type & fence->waiting_types)
- wake = 1;
- }
-
- fc->waiting_types |= fence->waiting_types & ~fence->signaled_types;
-
- if (!(fence->type & ~fence->signaled_types)) {
- DRM_DEBUG("Fence completely signaled 0x%08lx\n",
- fence->base.hash.key);
- list_del_init(&fence->ring);
- }
- }
-
- /*
- * Reinstate lost waiting types.
- */
-
- if ((fc->waiting_types & type) != type) {
- head = head->prev;
- list_for_each_entry(fence, head, ring) {
- if (&fence->ring == &fc->ring)
- break;
- diff = (fc->highest_waiting_sequence - fence->sequence) &
- driver->sequence_mask;
- if (diff > driver->wrap_diff)
- break;
-
- fc->waiting_types |= fence->waiting_types & ~fence->signaled_types;
- }
- }
-
- if (wake)
- wake_up_all(&fc->fence_queue);
-}
-EXPORT_SYMBOL(drm_fence_handler);
-
-static void drm_fence_unring(struct drm_device *dev, struct list_head *ring)
-{
- struct drm_fence_manager *fm = &dev->fm;
- unsigned long flags;
-
- write_lock_irqsave(&fm->lock, flags);
- list_del_init(ring);
- write_unlock_irqrestore(&fm->lock, flags);
-}
-
-void drm_fence_usage_deref_locked(struct drm_fence_object **fence)
-{
- struct drm_fence_object *tmp_fence = *fence;
- struct drm_device *dev = tmp_fence->dev;
- struct drm_fence_manager *fm = &dev->fm;
-
- DRM_ASSERT_LOCKED(&dev->struct_mutex);
- *fence = NULL;
- if (atomic_dec_and_test(&tmp_fence->usage)) {
- drm_fence_unring(dev, &tmp_fence->ring);
- DRM_DEBUG("Destroyed a fence object 0x%08lx\n",
- tmp_fence->base.hash.key);
- atomic_dec(&fm->count);
- BUG_ON(!list_empty(&tmp_fence->base.list));
- drm_ctl_free(tmp_fence, sizeof(*tmp_fence), DRM_MEM_FENCE);
- }
-}
-EXPORT_SYMBOL(drm_fence_usage_deref_locked);
-
-void drm_fence_usage_deref_unlocked(struct drm_fence_object **fence)
-{
- struct drm_fence_object *tmp_fence = *fence;
- struct drm_device *dev = tmp_fence->dev;
- struct drm_fence_manager *fm = &dev->fm;
-
- *fence = NULL;
- if (atomic_dec_and_test(&tmp_fence->usage)) {
- mutex_lock(&dev->struct_mutex);
- if (atomic_read(&tmp_fence->usage) == 0) {
- drm_fence_unring(dev, &tmp_fence->ring);
- atomic_dec(&fm->count);
- BUG_ON(!list_empty(&tmp_fence->base.list));
- drm_ctl_free(tmp_fence, sizeof(*tmp_fence), DRM_MEM_FENCE);
- }
- mutex_unlock(&dev->struct_mutex);
- }
-}
-EXPORT_SYMBOL(drm_fence_usage_deref_unlocked);
-
-struct drm_fence_object
-*drm_fence_reference_locked(struct drm_fence_object *src)
-{
- DRM_ASSERT_LOCKED(&src->dev->struct_mutex);
-
- atomic_inc(&src->usage);
- return src;
-}
-
-void drm_fence_reference_unlocked(struct drm_fence_object **dst,
- struct drm_fence_object *src)
-{
- mutex_lock(&src->dev->struct_mutex);
- *dst = src;
- atomic_inc(&src->usage);
- mutex_unlock(&src->dev->struct_mutex);
-}
-EXPORT_SYMBOL(drm_fence_reference_unlocked);
-
-static void drm_fence_object_destroy(struct drm_file *priv,
- struct drm_user_object *base)
-{
- struct drm_fence_object *fence =
- drm_user_object_entry(base, struct drm_fence_object, base);
-
- drm_fence_usage_deref_locked(&fence);
-}
-
-int drm_fence_object_signaled(struct drm_fence_object *fence, uint32_t mask)
-{
- unsigned long flags;
- int signaled;
- struct drm_device *dev = fence->dev;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_driver *driver = dev->driver->fence_driver;
-
- mask &= fence->type;
- read_lock_irqsave(&fm->lock, flags);
- signaled = (mask & fence->signaled_types) == mask;
- read_unlock_irqrestore(&fm->lock, flags);
- if (!signaled && driver->poll) {
- write_lock_irqsave(&fm->lock, flags);
- driver->poll(dev, fence->fence_class, mask);
- signaled = (mask & fence->signaled_types) == mask;
- write_unlock_irqrestore(&fm->lock, flags);
- }
- return signaled;
-}
-EXPORT_SYMBOL(drm_fence_object_signaled);
-
-
-int drm_fence_object_flush(struct drm_fence_object *fence,
- uint32_t type)
-{
- struct drm_device *dev = fence->dev;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_class_manager *fc = &fm->fence_class[fence->fence_class];
- struct drm_fence_driver *driver = dev->driver->fence_driver;
- unsigned long irq_flags;
- uint32_t saved_pending_flush;
- uint32_t diff;
- int call_flush;
-
- if (type & ~fence->type) {
- DRM_ERROR("Flush trying to extend fence type, "
- "0x%x, 0x%x\n", type, fence->type);
- return -EINVAL;
- }
-
- write_lock_irqsave(&fm->lock, irq_flags);
- fence->waiting_types |= type;
- fc->waiting_types |= fence->waiting_types;
- diff = (fence->sequence - fc->highest_waiting_sequence) &
- driver->sequence_mask;
-
- if (diff < driver->wrap_diff)
- fc->highest_waiting_sequence = fence->sequence;
-
- /*
- * fence->waiting_types has changed. Determine whether
- * we need to initiate some kind of flush as a result of this.
- */
-
- saved_pending_flush = fc->pending_flush;
- if (driver->needed_flush)
- fc->pending_flush |= driver->needed_flush(fence);
-
- if (driver->poll)
- driver->poll(dev, fence->fence_class, fence->waiting_types);
-
- call_flush = fc->pending_flush;
- write_unlock_irqrestore(&fm->lock, irq_flags);
-
- if (call_flush && driver->flush)
- driver->flush(dev, fence->fence_class);
-
- return 0;
-}
-EXPORT_SYMBOL(drm_fence_object_flush);
-
-/*
- * Make sure old fence objects are signaled before their fence sequences are
- * wrapped around and reused.
- */
-
-void drm_fence_flush_old(struct drm_device *dev, uint32_t fence_class,
- uint32_t sequence)
-{
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_class_manager *fc = &fm->fence_class[fence_class];
- struct drm_fence_object *fence;
- unsigned long irq_flags;
- struct drm_fence_driver *driver = dev->driver->fence_driver;
- int call_flush;
-
- uint32_t diff;
-
- write_lock_irqsave(&fm->lock, irq_flags);
-
- list_for_each_entry_reverse(fence, &fc->ring, ring) {
- diff = (sequence - fence->sequence) & driver->sequence_mask;
- if (diff <= driver->flush_diff)
- break;
-
- fence->waiting_types = fence->type;
- fc->waiting_types |= fence->type;
-
- if (driver->needed_flush)
- fc->pending_flush |= driver->needed_flush(fence);
- }
-
- if (driver->poll)
- driver->poll(dev, fence_class, fc->waiting_types);
-
- call_flush = fc->pending_flush;
- write_unlock_irqrestore(&fm->lock, irq_flags);
-
- if (call_flush && driver->flush)
- driver->flush(dev, fence->fence_class);
-
- /*
- * FIXME: Shold we implement a wait here for really old fences?
- */
-
-}
-EXPORT_SYMBOL(drm_fence_flush_old);
-
-int drm_fence_object_wait(struct drm_fence_object *fence,
- int lazy, int ignore_signals, uint32_t mask)
-{
- struct drm_device *dev = fence->dev;
- struct drm_fence_driver *driver = dev->driver->fence_driver;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_class_manager *fc = &fm->fence_class[fence->fence_class];
- int ret = 0;
- unsigned long _end = 3 * DRM_HZ;
-
- if (mask & ~fence->type) {
- DRM_ERROR("Wait trying to extend fence type"
- " 0x%08x 0x%08x\n", mask, fence->type);
- BUG();
- return -EINVAL;
- }
-
- if (driver->wait)
- return driver->wait(fence, lazy, !ignore_signals, mask);
-
-
- drm_fence_object_flush(fence, mask);
- if (driver->has_irq(dev, fence->fence_class, mask)) {
- if (!ignore_signals)
- ret = wait_event_interruptible_timeout
- (fc->fence_queue,
- drm_fence_object_signaled(fence, mask),
- 3 * DRM_HZ);
- else
- ret = wait_event_timeout
- (fc->fence_queue,
- drm_fence_object_signaled(fence, mask),
- 3 * DRM_HZ);
-
- if (unlikely(ret == -ERESTARTSYS))
- return -EAGAIN;
-
- if (unlikely(ret == 0))
- return -EBUSY;
-
- return 0;
- }
-
- return drm_fence_wait_polling(fence, lazy, !ignore_signals, mask,
- _end);
-}
-EXPORT_SYMBOL(drm_fence_object_wait);
-
-
-
-int drm_fence_object_emit(struct drm_fence_object *fence, uint32_t fence_flags,
- uint32_t fence_class, uint32_t type)
-{
- struct drm_device *dev = fence->dev;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_driver *driver = dev->driver->fence_driver;
- struct drm_fence_class_manager *fc = &fm->fence_class[fence->fence_class];
- unsigned long flags;
- uint32_t sequence;
- uint32_t native_types;
- int ret;
-
- drm_fence_unring(dev, &fence->ring);
- ret = driver->emit(dev, fence_class, fence_flags, &sequence,
- &native_types);
- if (ret)
- return ret;
-
- write_lock_irqsave(&fm->lock, flags);
- fence->fence_class = fence_class;
- fence->type = type;
- fence->waiting_types = 0;
- fence->signaled_types = 0;
- fence->error = 0;
- fence->sequence = sequence;
- fence->native_types = native_types;
- if (list_empty(&fc->ring))
- fc->highest_waiting_sequence = sequence - 1;
- list_add_tail(&fence->ring, &fc->ring);
- fc->latest_queued_sequence = sequence;
- write_unlock_irqrestore(&fm->lock, flags);
- return 0;
-}
-EXPORT_SYMBOL(drm_fence_object_emit);
-
-static int drm_fence_object_init(struct drm_device *dev, uint32_t fence_class,
- uint32_t type,
- uint32_t fence_flags,
- struct drm_fence_object *fence)
-{
- int ret = 0;
- unsigned long flags;
- struct drm_fence_manager *fm = &dev->fm;
-
- mutex_lock(&dev->struct_mutex);
- atomic_set(&fence->usage, 1);
- mutex_unlock(&dev->struct_mutex);
-
- write_lock_irqsave(&fm->lock, flags);
- INIT_LIST_HEAD(&fence->ring);
-
- /*
- * Avoid hitting BUG() for kernel-only fence objects.
- */
-
- INIT_LIST_HEAD(&fence->base.list);
- fence->fence_class = fence_class;
- fence->type = type;
- fence->signaled_types = 0;
- fence->waiting_types = 0;
- fence->sequence = 0;
- fence->error = 0;
- fence->dev = dev;
- write_unlock_irqrestore(&fm->lock, flags);
- if (fence_flags & DRM_FENCE_FLAG_EMIT) {
- ret = drm_fence_object_emit(fence, fence_flags,
- fence->fence_class, type);
- }
- return ret;
-}
-
-int drm_fence_add_user_object(struct drm_file *priv,
- struct drm_fence_object *fence, int shareable)
-{
- struct drm_device *dev = priv->minor->dev;
- int ret;
-
- mutex_lock(&dev->struct_mutex);
- ret = drm_add_user_object(priv, &fence->base, shareable);
- if (ret)
- goto out;
- atomic_inc(&fence->usage);
- fence->base.type = drm_fence_type;
- fence->base.remove = &drm_fence_object_destroy;
- DRM_DEBUG("Fence 0x%08lx created\n", fence->base.hash.key);
-out:
- mutex_unlock(&dev->struct_mutex);
- return ret;
-}
-EXPORT_SYMBOL(drm_fence_add_user_object);
-
-int drm_fence_object_create(struct drm_device *dev, uint32_t fence_class,
- uint32_t type, unsigned flags,
- struct drm_fence_object **c_fence)
-{
- struct drm_fence_object *fence;
- int ret;
- struct drm_fence_manager *fm = &dev->fm;
-
- fence = drm_ctl_calloc(1, sizeof(*fence), DRM_MEM_FENCE);
- if (!fence) {
- DRM_ERROR("Out of memory creating fence object\n");
- return -ENOMEM;
- }
- ret = drm_fence_object_init(dev, fence_class, type, flags, fence);
- if (ret) {
- drm_fence_usage_deref_unlocked(&fence);
- return ret;
- }
- *c_fence = fence;
- atomic_inc(&fm->count);
-
- return 0;
-}
-EXPORT_SYMBOL(drm_fence_object_create);
-
-void drm_fence_manager_init(struct drm_device *dev)
-{
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_class_manager *fence_class;
- struct drm_fence_driver *fed = dev->driver->fence_driver;
- int i;
- unsigned long flags;
-
- rwlock_init(&fm->lock);
- write_lock_irqsave(&fm->lock, flags);
- fm->initialized = 0;
- if (!fed)
- goto out_unlock;
-
- fm->initialized = 1;
- fm->num_classes = fed->num_classes;
- BUG_ON(fm->num_classes > _DRM_FENCE_CLASSES);
-
- for (i = 0; i < fm->num_classes; ++i) {
- fence_class = &fm->fence_class[i];
-
- memset(fence_class, 0, sizeof(*fence_class));
- INIT_LIST_HEAD(&fence_class->ring);
- DRM_INIT_WAITQUEUE(&fence_class->fence_queue);
- }
-
- atomic_set(&fm->count, 0);
- out_unlock:
- write_unlock_irqrestore(&fm->lock, flags);
-}
-
-void drm_fence_fill_arg(struct drm_fence_object *fence,
- struct drm_fence_arg *arg)
-{
- struct drm_device *dev = fence->dev;
- struct drm_fence_manager *fm = &dev->fm;
- unsigned long irq_flags;
-
- read_lock_irqsave(&fm->lock, irq_flags);
- arg->handle = fence->base.hash.key;
- arg->fence_class = fence->fence_class;
- arg->type = fence->type;
- arg->signaled = fence->signaled_types;
- arg->error = fence->error;
- arg->sequence = fence->sequence;
- read_unlock_irqrestore(&fm->lock, irq_flags);
-}
-EXPORT_SYMBOL(drm_fence_fill_arg);
-
-void drm_fence_manager_takedown(struct drm_device *dev)
-{
-}
-
-struct drm_fence_object *drm_lookup_fence_object(struct drm_file *priv,
- uint32_t handle)
-{
- struct drm_device *dev = priv->minor->dev;
- struct drm_user_object *uo;
- struct drm_fence_object *fence;
-
- mutex_lock(&dev->struct_mutex);
- uo = drm_lookup_user_object(priv, handle);
- if (!uo || (uo->type != drm_fence_type)) {
- mutex_unlock(&dev->struct_mutex);
- return NULL;
- }
- fence = drm_fence_reference_locked(drm_user_object_entry(uo, struct drm_fence_object, base));
- mutex_unlock(&dev->struct_mutex);
- return fence;
-}
-
-int drm_fence_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- int ret;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_arg *arg = data;
- struct drm_fence_object *fence;
- ret = 0;
-
- if (!fm->initialized) {
- DRM_ERROR("The DRM driver does not support fencing.\n");
- return -EINVAL;
- }
-
- if (arg->flags & DRM_FENCE_FLAG_EMIT)
- LOCK_TEST_WITH_RETURN(dev, file_priv);
- ret = drm_fence_object_create(dev, arg->fence_class,
- arg->type, arg->flags, &fence);
- if (ret)
- return ret;
- ret = drm_fence_add_user_object(file_priv, fence,
- arg->flags &
- DRM_FENCE_FLAG_SHAREABLE);
- if (ret) {
- drm_fence_usage_deref_unlocked(&fence);
- return ret;
- }
-
- /*
- * usage > 0. No need to lock dev->struct_mutex;
- */
-
- arg->handle = fence->base.hash.key;
-
- drm_fence_fill_arg(fence, arg);
- drm_fence_usage_deref_unlocked(&fence);
-
- return ret;
-}
-
-int drm_fence_reference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- int ret;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_arg *arg = data;
- struct drm_fence_object *fence;
- struct drm_user_object *uo;
- ret = 0;
-
- if (!fm->initialized) {
- DRM_ERROR("The DRM driver does not support fencing.\n");
- return -EINVAL;
- }
-
- ret = drm_user_object_ref(file_priv, arg->handle, drm_fence_type, &uo);
- if (ret)
- return ret;
- fence = drm_lookup_fence_object(file_priv, arg->handle);
- drm_fence_fill_arg(fence, arg);
- drm_fence_usage_deref_unlocked(&fence);
-
- return ret;
-}
-
-
-int drm_fence_unreference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- int ret;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_arg *arg = data;
- ret = 0;
-
- if (!fm->initialized) {
- DRM_ERROR("The DRM driver does not support fencing.\n");
- return -EINVAL;
- }
-
- return drm_user_object_unref(file_priv, arg->handle, drm_fence_type);
-}
-
-int drm_fence_signaled_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- int ret;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_arg *arg = data;
- struct drm_fence_object *fence;
- ret = 0;
-
- if (!fm->initialized) {
- DRM_ERROR("The DRM driver does not support fencing.\n");
- return -EINVAL;
- }
-
- fence = drm_lookup_fence_object(file_priv, arg->handle);
- if (!fence)
- return -EINVAL;
-
- drm_fence_fill_arg(fence, arg);
- drm_fence_usage_deref_unlocked(&fence);
-
- return ret;
-}
-
-int drm_fence_flush_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- int ret;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_arg *arg = data;
- struct drm_fence_object *fence;
- ret = 0;
-
- if (!fm->initialized) {
- DRM_ERROR("The DRM driver does not support fencing.\n");
- return -EINVAL;
- }
-
- fence = drm_lookup_fence_object(file_priv, arg->handle);
- if (!fence)
- return -EINVAL;
- ret = drm_fence_object_flush(fence, arg->type);
-
- drm_fence_fill_arg(fence, arg);
- drm_fence_usage_deref_unlocked(&fence);
-
- return ret;
-}
-
-
-int drm_fence_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- int ret;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_arg *arg = data;
- struct drm_fence_object *fence;
- ret = 0;
-
- if (!fm->initialized) {
- DRM_ERROR("The DRM driver does not support fencing.\n");
- return -EINVAL;
- }
-
- fence = drm_lookup_fence_object(file_priv, arg->handle);
- if (!fence)
- return -EINVAL;
- ret = drm_fence_object_wait(fence,
- arg->flags & DRM_FENCE_FLAG_WAIT_LAZY,
- 0, arg->type);
-
- drm_fence_fill_arg(fence, arg);
- drm_fence_usage_deref_unlocked(&fence);
-
- return ret;
-}
-
-
-int drm_fence_emit_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- int ret;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_arg *arg = data;
- struct drm_fence_object *fence;
- ret = 0;
-
- if (!fm->initialized) {
- DRM_ERROR("The DRM driver does not support fencing.\n");
- return -EINVAL;
- }
-
- LOCK_TEST_WITH_RETURN(dev, file_priv);
- fence = drm_lookup_fence_object(file_priv, arg->handle);
- if (!fence)
- return -EINVAL;
- ret = drm_fence_object_emit(fence, arg->flags, arg->fence_class,
- arg->type);
-
- drm_fence_fill_arg(fence, arg);
- drm_fence_usage_deref_unlocked(&fence);
-
- return ret;
-}
-
-int drm_fence_buffers_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
- int ret;
- struct drm_fence_manager *fm = &dev->fm;
- struct drm_fence_arg *arg = data;
- struct drm_fence_object *fence;
- ret = 0;
-
- if (!fm->initialized) {
- DRM_ERROR("The DRM driver does not support fencing.\n");
- return -EINVAL;
- }
-
- if (!dev->bm.initialized) {
- DRM_ERROR("Buffer object manager is not initialized\n");
- return -EINVAL;
- }
- LOCK_TEST_WITH_RETURN(dev, file_priv);
- ret = drm_fence_buffer_objects(dev, NULL, arg->flags,
- NULL, &fence);
- if (ret)
- return ret;
-
- if (!(arg->flags & DRM_FENCE_FLAG_NO_USER)) {
- ret = drm_fence_add_user_object(file_priv, fence,
- arg->flags &
- DRM_FENCE_FLAG_SHAREABLE);
- if (ret)
- return ret;
- }
-
- arg->handle = fence->base.hash.key;
-
- drm_fence_fill_arg(fence, arg);
- drm_fence_usage_deref_unlocked(&fence);
-
- return ret;
-}
diff --git a/linux-core/drm_fops.c b/linux-core/drm_fops.c
index 837645ae..3e2691a8 100644
--- a/linux-core/drm_fops.c
+++ b/linux-core/drm_fops.c
@@ -152,13 +152,6 @@ int drm_open(struct inode *inode, struct file *filp)
}
out:
- mutex_lock(&dev->struct_mutex);
- BUG_ON((dev->dev_mapping != NULL) &&
- (dev->dev_mapping != inode->i_mapping));
- if (dev->dev_mapping == NULL)
- dev->dev_mapping = inode->i_mapping;
- mutex_unlock(&dev->struct_mutex);
-
return retcode;
}
EXPORT_SYMBOL(drm_open);
@@ -332,33 +325,6 @@ int drm_fasync(int fd, struct file *filp, int on)
}
EXPORT_SYMBOL(drm_fasync);
-static void drm_object_release(struct file *filp)
-{
- struct drm_file *priv = filp->private_data;
- struct list_head *head;
- struct drm_ref_object *ref_object;
- int i;
-
- /*
- * Free leftover ref objects created by me. Note that we cannot use
- * list_for_each() here, as the struct_mutex may be temporarily
- * released by the remove_() functions, and thus the lists may be
- * altered.
- * Also, a drm_remove_ref_object() will not remove it
- * from the list unless its refcount is 1.
- */
-
- head = &priv->refd_objects;
- while (head->next != head) {
- ref_object = list_entry(head->next, struct drm_ref_object, list);
- drm_remove_ref_object(priv, ref_object);
- head = &priv->refd_objects;
- }
-
- for (i = 0; i < _DRM_NO_REF_TYPES; ++i)
- drm_ht_remove(&priv->refd_object_hash[i]);
-}
-
/**
* Release file.
*
@@ -475,7 +441,6 @@ int drm_release(struct inode *inode, struct file *filp)
mutex_unlock(&dev->ctxlist_mutex);
mutex_lock(&dev->struct_mutex);
- drm_object_release(filp);
if (file_priv->remove_auth_on_close == 1) {
struct drm_file *temp;
diff --git a/linux-core/drm_object.c b/linux-core/drm_object.c
deleted file mode 100644
index 2994b716..00000000
--- a/linux-core/drm_object.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/**************************************************************************
- *
- * Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-
-int drm_add_user_object(struct drm_file *priv, struct drm_user_object *item,
- int shareable)
-{
- struct drm_device *dev = priv->minor->dev;
- int ret;
-
- DRM_ASSERT_LOCKED(&dev->struct_mutex);
-
- /* The refcount will be bumped to 1 when we add the ref object below. */
- atomic_set(&item->refcount, 0);
- item->shareable = shareable;
- item->owner = priv;
-
- ret = drm_ht_just_insert_please(&dev->object_hash, &item->hash,
- (unsigned long)item, 31, 0, 0);
- if (ret)
- return ret;
-
- ret = drm_add_ref_object(priv, item, _DRM_REF_USE);
- if (ret)
- ret = drm_ht_remove_item(&dev->object_hash, &item->hash);
-
- return ret;
-}
-EXPORT_SYMBOL(drm_add_user_object);
-
-struct drm_user_object *drm_lookup_user_object(struct drm_file *priv, uint32_t key)
-{
- struct drm_device *dev = priv->minor->dev;
- struct drm_hash_item *hash;
- int ret;
- struct drm_user_object *item;
-
- DRM_ASSERT_LOCKED(&dev->struct_mutex);
-
- ret = drm_ht_find_item(&dev->object_hash, key, &hash);
- if (ret)
- return NULL;
-
- item = drm_hash_entry(hash, struct drm_user_object, hash);
-
- if (priv != item->owner) {
- struct drm_open_hash *ht = &priv->refd_object_hash[_DRM_REF_USE];
- ret = drm_ht_find_item(ht, (unsigned long)item, &hash);
- if (ret) {
- DRM_ERROR("Object not registered for usage\n");
- return NULL;
- }
- }
- return item;
-}
-EXPORT_SYMBOL(drm_lookup_user_object);
-
-static void drm_deref_user_object(struct drm_file *priv, struct drm_user_object *item)
-{
- struct drm_device *dev = priv->minor->dev;
- int ret;
-
- if (atomic_dec_and_test(&item->refcount)) {
- ret = drm_ht_remove_item(&dev->object_hash, &item->hash);
- BUG_ON(ret);
- item->remove(priv, item);
- }
-}
-
-static int drm_object_ref_action(struct drm_file *priv, struct drm_user_object *ro,
- enum drm_ref_type action)
-{
- int ret = 0;
-
- switch (action) {
- case _DRM_REF_USE:
- atomic_inc(&ro->refcount);
- break;
- default:
- if (!ro->ref_struct_locked) {
- break;
- } else {
- ro->ref_struct_locked(priv, ro, action);
- }
- }
- return ret;
-}
-
-int drm_add_ref_object(struct drm_file *priv, struct drm_user_object *referenced_object,
- enum drm_ref_type ref_action)
-{
- int ret = 0;
- struct drm_ref_object *item;
- struct drm_open_hash *ht = &priv->refd_object_hash[ref_action];
-
- DRM_ASSERT_LOCKED(&priv->minor->dev->struct_mutex);
- if (!referenced_object->shareable && priv != referenced_object->owner) {
- DRM_ERROR("Not allowed to reference this object\n");
- return -EINVAL;
- }
-
- /*
- * If this is not a usage reference, Check that usage has been registered
- * first. Otherwise strange things may happen on destruction.
- */
-
- if ((ref_action != _DRM_REF_USE) && priv != referenced_object->owner) {
- item =
- drm_lookup_ref_object(priv, referenced_object,
- _DRM_REF_USE);
- if (!item) {
- DRM_ERROR
- ("Object not registered for usage by this client\n");
- return -EINVAL;
- }
- }
-
- if (NULL !=
- (item =
- drm_lookup_ref_object(priv, referenced_object, ref_action))) {
- atomic_inc(&item->refcount);
- return drm_object_ref_action(priv, referenced_object,
- ref_action);
- }
-
- item = drm_ctl_calloc(1, sizeof(*item), DRM_MEM_OBJECTS);
- if (item == NULL) {
- DRM_ERROR("Could not allocate reference object\n");
- return -ENOMEM;
- }
-
- atomic_set(&item->refcount, 1);
- item->hash.key = (unsigned long)referenced_object;
- ret = drm_ht_insert_item(ht, &item->hash);
- item->unref_action = ref_action;
-
- if (ret)
- goto out;
-
- list_add(&item->list, &priv->refd_objects);
- ret = drm_object_ref_action(priv, referenced_object, ref_action);
-out:
- return ret;
-}
-
-struct drm_ref_object *drm_lookup_ref_object(struct drm_file *priv,
- struct drm_user_object *referenced_object,
- enum drm_ref_type ref_action)
-{
- struct drm_hash_item *hash;
- int ret;
-
- DRM_ASSERT_LOCKED(&priv->minor->dev->struct_mutex);
- ret = drm_ht_find_item(&priv->refd_object_hash[ref_action],
- (unsigned long)referenced_object, &hash);
- if (ret)
- return NULL;
-
- return drm_hash_entry(hash, struct drm_ref_object, hash);
-}
-EXPORT_SYMBOL(drm_lookup_ref_object);
-
-static void drm_remove_other_references(struct drm_file *priv,
- struct drm_user_object *ro)
-{
- int i;
- struct drm_open_hash *ht;
- struct drm_hash_item *hash;
- struct drm_ref_object *item;
-
- for (i = _DRM_REF_USE + 1; i < _DRM_NO_REF_TYPES; ++i) {
- ht = &priv->refd_object_hash[i];
- while (!drm_ht_find_item(ht, (unsigned long)ro, &hash)) {
- item = drm_hash_entry(hash, struct drm_ref_object, hash);
- drm_remove_ref_object(priv, item);
- }
- }
-}
-
-void drm_remove_ref_object(struct drm_file *priv, struct drm_ref_object *item)
-{
- int ret;
- struct drm_user_object *user_object = (struct drm_user_object *) item->hash.key;
- struct drm_open_hash *ht = &priv->refd_object_hash[item->unref_action];
- enum drm_ref_type unref_action;
-
- DRM_ASSERT_LOCKED(&priv->minor->dev->struct_mutex);
- unref_action = item->unref_action;
- if (atomic_dec_and_test(&item->refcount)) {
- ret = drm_ht_remove_item(ht, &item->hash);
- BUG_ON(ret);
- list_del_init(&item->list);
- if (unref_action == _DRM_REF_USE)
- drm_remove_other_references(priv, user_object);
- drm_ctl_free(item, sizeof(*item), DRM_MEM_OBJECTS);
- }
-
- switch (unref_action) {
- case _DRM_REF_USE:
- drm_deref_user_object(priv, user_object);
- break;
- default:
- BUG_ON(!user_object->unref);
- user_object->unref(priv, user_object, unref_action);
- break;
- }
-
-}
-EXPORT_SYMBOL(drm_remove_ref_object);
-
-int drm_user_object_ref(struct drm_file *priv, uint32_t user_token,
- enum drm_object_type type, struct drm_user_object **object)
-{
- struct drm_device *dev = priv->minor->dev;
- struct drm_user_object *uo;
- struct drm_hash_item *hash;
- int ret;
-
- mutex_lock(&dev->struct_mutex);
- ret = drm_ht_find_item(&dev->object_hash, user_token, &hash);
- if (ret) {
- DRM_ERROR("Could not find user object to reference.\n");
- goto out_err;
- }
- uo = drm_hash_entry(hash, struct drm_user_object, hash);
- if (uo->type != type) {
- ret = -EINVAL;
- goto out_err;
- }
- ret = drm_add_ref_object(priv, uo, _DRM_REF_USE);
- if (ret)
- goto out_err;
- mutex_unlock(&dev->struct_mutex);
- *object = uo;
- return 0;
-out_err:
- mutex_unlock(&dev->struct_mutex);
- return ret;
-}
-
-int drm_user_object_unref(struct drm_file *priv, uint32_t user_token,
- enum drm_object_type type)
-{
- struct drm_device *dev = priv->minor->dev;
- struct drm_user_object *uo;
- struct drm_ref_object *ro;
- int ret;
-
- mutex_lock(&dev->struct_mutex);
- uo = drm_lookup_user_object(priv, user_token);
- if (!uo || (uo->type != type)) {
- ret = -EINVAL;
- goto out_err;
- }
- ro = drm_lookup_ref_object(priv, uo, _DRM_REF_USE);
- if (!ro) {
- ret = -EINVAL;
- goto out_err;
- }
- drm_remove_ref_object(priv, ro);
- mutex_unlock(&dev->struct_mutex);
- return 0;
-out_err:
- mutex_unlock(&dev->struct_mutex);
- return ret;
-}
diff --git a/linux-core/drm_objects.h b/linux-core/drm_objects.h
deleted file mode 100644
index 136fdc8d..00000000
--- a/linux-core/drm_objects.h
+++ /dev/null
@@ -1,821 +0,0 @@
-/**************************************************************************
- *
- * Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#ifndef _DRM_OBJECTS_H
-#define _DRM_OBJECTS_H
-
-struct drm_device;
-struct drm_bo_mem_reg;
-
-/***************************************************
- * User space objects. (drm_object.c)
- */
-
-#define drm_user_object_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
-
-enum drm_object_type {
- drm_fence_type,
- drm_buffer_type,
- drm_lock_type,
- /*
- * Add other user space object types here.
- */
- drm_driver_type0 = 256,
- drm_driver_type1,
- drm_driver_type2,
- drm_driver_type3,
- drm_driver_type4
-};
-
-/*
- * A user object is a structure that helps the drm give out user handles
- * to kernel internal objects and to keep track of these objects so that
- * they can be destroyed, for example when the user space process exits.
- * Designed to be accessible using a user space 32-bit handle.
- */
-
-struct drm_user_object {
- struct drm_hash_item hash;
- struct list_head list;
- enum drm_object_type type;
- atomic_t refcount;
- int shareable;
- struct drm_file *owner;
- void (*ref_struct_locked) (struct drm_file *priv,
- struct drm_user_object *obj,
- enum drm_ref_type ref_action);
- void (*unref) (struct drm_file *priv, struct drm_user_object *obj,
- enum drm_ref_type unref_action);
- void (*remove) (struct drm_file *priv, struct drm_user_object *obj);
-};
-
-/*
- * A ref object is a structure which is used to
- * keep track of references to user objects and to keep track of these
- * references so that they can be destroyed for example when the user space
- * process exits. Designed to be accessible using a pointer to the _user_ object.
- */
-
-struct drm_ref_object {
- struct drm_hash_item hash;
- struct list_head list;
- atomic_t refcount;
- enum drm_ref_type unref_action;
-};
-
-/**
- * Must be called with the struct_mutex held.
- */
-
-extern int drm_add_user_object(struct drm_file *priv, struct drm_user_object *item,
- int shareable);
-/**
- * Must be called with the struct_mutex held.
- */
-
-extern struct drm_user_object *drm_lookup_user_object(struct drm_file *priv,
- uint32_t key);
-
-/*
- * Must be called with the struct_mutex held. May temporarily release it.
- */
-
-extern int drm_add_ref_object(struct drm_file *priv,
- struct drm_user_object *referenced_object,
- enum drm_ref_type ref_action);
-
-/*
- * Must be called with the struct_mutex held.
- */
-
-struct drm_ref_object *drm_lookup_ref_object(struct drm_file *priv,
- struct drm_user_object *referenced_object,
- enum drm_ref_type ref_action);
-/*
- * Must be called with the struct_mutex held.
- * If "item" has been obtained by a call to drm_lookup_ref_object. You may not
- * release the struct_mutex before calling drm_remove_ref_object.
- * This function may temporarily release the struct_mutex.
- */
-
-extern void drm_remove_ref_object(struct drm_file *priv, struct drm_ref_object *item);
-extern int drm_user_object_ref(struct drm_file *priv, uint32_t user_token,
- enum drm_object_type type,
- struct drm_user_object **object);
-extern int drm_user_object_unref(struct drm_file *priv, uint32_t user_token,
- enum drm_object_type type);
-
-/***************************************************
- * Fence objects. (drm_fence.c)
- */
-
-struct drm_fence_object {
- struct drm_user_object base;
- struct drm_device *dev;
- atomic_t usage;
-
- /*
- * The below three fields are protected by the fence manager spinlock.
- */
-
- struct list_head ring;
- int fence_class;
- uint32_t native_types;
- uint32_t type;
- uint32_t signaled_types;
- uint32_t sequence;
- uint32_t waiting_types;
- uint32_t error;
-};
-
-#define _DRM_FENCE_CLASSES 8
-#define _DRM_FENCE_TYPE_EXE 0x00
-
-struct drm_fence_class_manager {
- struct list_head ring;
- uint32_t pending_flush;
- uint32_t waiting_types;
- wait_queue_head_t fence_queue;
- uint32_t highest_waiting_sequence;
- uint32_t latest_queued_sequence;
-};
-
-struct drm_fence_manager {
- int initialized;
- rwlock_t lock;
- struct drm_fence_class_manager fence_class[_DRM_FENCE_CLASSES];
- uint32_t num_classes;
- atomic_t count;
-};
-
-struct drm_fence_driver {
- unsigned long *waiting_jiffies;
- uint32_t num_classes;
- uint32_t wrap_diff;
- uint32_t flush_diff;
- uint32_t sequence_mask;
-
- /*
- * Driver implemented functions:
- * has_irq() : 1 if the hardware can update the indicated type_flags using an
- * irq handler. 0 if polling is required.
- *
- * emit() : Emit a sequence number to the command stream.
- * Return the sequence number.
- *
- * flush() : Make sure the flags indicated in fc->pending_flush will eventually
- * signal for fc->highest_received_sequence and all preceding sequences.
- * Acknowledge by clearing the flags fc->pending_flush.
- *
- * poll() : Call drm_fence_handler with any new information.
- *
- * needed_flush() : Given the current state of the fence->type flags and previusly
- * executed or queued flushes, return the type_flags that need flushing.
- *
- * wait(): Wait for the "mask" flags to signal on a given fence, performing
- * whatever's necessary to make this happen.
- */
-
- int (*has_irq) (struct drm_device *dev, uint32_t fence_class,
- uint32_t flags);
- int (*emit) (struct drm_device *dev, uint32_t fence_class,
- uint32_t flags, uint32_t *breadcrumb,
- uint32_t *native_type);
- void (*flush) (struct drm_device *dev, uint32_t fence_class);
- void (*poll) (struct drm_device *dev, uint32_t fence_class,
- uint32_t types);
- uint32_t (*needed_flush) (struct drm_fence_object *fence);
- int (*wait) (struct drm_fence_object *fence, int lazy,
- int interruptible, uint32_t mask);
-};
-
-extern int drm_fence_wait_polling(struct drm_fence_object *fence, int lazy,
- int interruptible, uint32_t mask,
- unsigned long end_jiffies);
-extern void drm_fence_handler(struct drm_device *dev, uint32_t fence_class,
- uint32_t sequence, uint32_t type,
- uint32_t error);
-extern void drm_fence_manager_init(struct drm_device *dev);
-extern void drm_fence_manager_takedown(struct drm_device *dev);
-extern void drm_fence_flush_old(struct drm_device *dev, uint32_t fence_class,
- uint32_t sequence);
-extern int drm_fence_object_flush(struct drm_fence_object *fence,
- uint32_t type);
-extern int drm_fence_object_signaled(struct drm_fence_object *fence,
- uint32_t type);
-extern void drm_fence_usage_deref_locked(struct drm_fence_object **fence);
-extern void drm_fence_usage_deref_unlocked(struct drm_fence_object **fence);
-extern struct drm_fence_object *drm_fence_reference_locked(struct drm_fence_object *src);
-extern void drm_fence_reference_unlocked(struct drm_fence_object **dst,
- struct drm_fence_object *src);
-extern int drm_fence_object_wait(struct drm_fence_object *fence,
- int lazy, int ignore_signals, uint32_t mask);
-extern int drm_fence_object_create(struct drm_device *dev, uint32_t type,
- uint32_t fence_flags, uint32_t fence_class,
- struct drm_fence_object **c_fence);
-extern int drm_fence_object_emit(struct drm_fence_object *fence,
- uint32_t fence_flags, uint32_t class,
- uint32_t type);
-extern void drm_fence_fill_arg(struct drm_fence_object *fence,
- struct drm_fence_arg *arg);
-
-extern int drm_fence_add_user_object(struct drm_file *priv,
- struct drm_fence_object *fence,
- int shareable);
-
-extern int drm_fence_create_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv);
-extern int drm_fence_destroy_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv);
-extern int drm_fence_reference_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv);
-extern int drm_fence_unreference_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv);
-extern int drm_fence_signaled_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv);
-extern int drm_fence_flush_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv);
-extern int drm_fence_wait_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv);
-extern int drm_fence_emit_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv);
-extern int drm_fence_buffers_ioctl(struct drm_device *dev, void *data,
- struct drm_file *file_priv);
-/**************************************************
- *TTMs
- */
-
-/*
- * The ttm backend GTT interface. (In our case AGP).
- * Any similar type of device (PCIE?)
- * needs only to implement these functions to be usable with the TTM interface.
- * The AGP backend implementation lives in drm_agpsupport.c
- * basically maps these calls to available functions in agpgart.
- * Each drm device driver gets an
- * additional function pointer that creates these types,
- * so that the device can choose the correct aperture.
- * (Multiple AGP apertures, etc.)
- * Most device drivers will let this point to the standard AGP implementation.
- */
-
-#define DRM_BE_FLAG_NEEDS_FREE 0x00000001
-#define DRM_BE_FLAG_BOUND_CACHED 0x00000002
-
-struct drm_ttm_backend;
-struct drm_ttm_backend_func {
- int (*needs_ub_cache_adjust) (struct drm_ttm_backend *backend);
- int (*populate) (struct drm_ttm_backend *backend,
- unsigned long num_pages, struct page **pages,
- struct page *dummy_read_page);
- void (*clear) (struct drm_ttm_backend *backend);
- int (*bind) (struct drm_ttm_backend *backend,
- struct drm_bo_mem_reg *bo_mem);
- int (*unbind) (struct drm_ttm_backend *backend);
- void (*destroy) (struct drm_ttm_backend *backend);
-};
-
-/**
- * This structure associates a set of flags and methods with a drm_ttm
- * object, and will also be subclassed by the particular backend.
- *
- * \sa #drm_agp_ttm_backend
- */
-struct drm_ttm_backend {
- struct drm_device *dev;
- uint32_t flags;
- struct drm_ttm_backend_func *func;
-};
-
-struct drm_ttm {
- struct page *dummy_read_page;
- struct page **pages;
- long first_himem_page;
- long last_lomem_page;
- uint32_t page_flags;
- unsigned long num_pages;
- atomic_t vma_count;
- struct drm_device *dev;
- int destroy;
- uint32_t mapping_offset;
- struct drm_ttm_backend *be;
- unsigned long highest_lomem_entry;
- unsigned long lowest_himem_entry;
- enum {
- ttm_bound,
- ttm_evicted,
- ttm_unbound,
- ttm_unpopulated,
- } state;
-
-};
-
-extern struct drm_ttm *drm_ttm_create(struct drm_device *dev, unsigned long size,
- uint32_t page_flags,
- struct page *dummy_read_page);
-extern int drm_ttm_bind(struct drm_ttm *ttm, struct drm_bo_mem_reg *bo_mem);
-extern void drm_ttm_unbind(struct drm_ttm *ttm);
-extern void drm_ttm_evict(struct drm_ttm *ttm);
-extern void drm_ttm_fixup_caching(struct drm_ttm *ttm);
-extern struct page *drm_ttm_get_page(struct drm_ttm *ttm, int index);
-extern void drm_ttm_cache_flush(struct page *pages[], unsigned long num_pages);
-extern int drm_ttm_populate(struct drm_ttm *ttm);
-extern int drm_ttm_set_user(struct drm_ttm *ttm,
- struct task_struct *tsk,
- unsigned long start,
- unsigned long num_pages);
-
-/*
- * Destroy a ttm. The user normally calls drmRmMap or a similar IOCTL to do
- * this which calls this function iff there are no vmas referencing it anymore.
- * Otherwise it is called when the last vma exits.
- */
-
-extern int drm_ttm_destroy(struct drm_ttm *ttm);
-
-#define DRM_FLAG_MASKED(_old, _new, _mask) {\
-(_old) ^= (((_old) ^ (_new)) & (_mask)); \
-}
-
-#define DRM_TTM_MASK_FLAGS ((1 << PAGE_SHIFT) - 1)
-#define DRM_TTM_MASK_PFN (0xFFFFFFFFU - DRM_TTM_MASK_FLAGS)
-
-/*
- * Page flags.
- */
-
-/*
- * This ttm should not be cached by the CPU
- */
-#define DRM_TTM_PAGE_UNCACHED (1 << 0)
-/*
- * This flat is not used at this time; I don't know what the
- * intent was
- */
-#define DRM_TTM_PAGE_USED (1 << 1)
-/*
- * This flat is not used at this time; I don't know what the
- * intent was
- */
-#define DRM_TTM_PAGE_BOUND (1 << 2)
-/*
- * This flat is not used at this time; I don't know what the
- * intent was
- */
-#define DRM_TTM_PAGE_PRESENT (1 << 3)
-/*
- * The array of page pointers was allocated with vmalloc
- * instead of drm_calloc.
- */
-#define DRM_TTM_PAGEDIR_VMALLOC (1 << 4)
-/*
- * This ttm is mapped from user space
- */
-#define DRM_TTM_PAGE_USER (1 << 5)
-/*
- * This ttm will be written to by the GPU
- */
-#define DRM_TTM_PAGE_WRITE (1 << 6)
-/*
- * This ttm was mapped to the GPU, and so the contents may have
- * been modified
- */
-#define DRM_TTM_PAGE_USER_DIRTY (1 << 7)
-/*
- * This flag is not used at this time; I don't know what the
- * intent was.
- */
-#define DRM_TTM_PAGE_USER_DMA (1 << 8)
-
-/***************************************************
- * Buffer objects. (drm_bo.c, drm_bo_move.c)
- */
-
-struct drm_bo_mem_reg {
- struct drm_mm_node *mm_node;
- unsigned long size;
- unsigned long num_pages;
- uint32_t page_alignment;
- uint32_t mem_type;
- /*
- * Current buffer status flags, indicating
- * where the buffer is located and which
- * access modes are in effect
- */
- uint64_t flags;
- /**
- * These are the flags proposed for
- * a validate operation. If the
- * validate succeeds, they'll get moved
- * into the flags field
- */
- uint64_t proposed_flags;
-
- uint32_t desired_tile_stride;
- uint32_t hw_tile_stride;
-};
-
-enum drm_bo_type {
- /*
- * drm_bo_type_device are 'normal' drm allocations,
- * pages are allocated from within the kernel automatically
- * and the objects can be mmap'd from the drm device. Each
- * drm_bo_type_device object has a unique name which can be
- * used by other processes to share access to the underlying
- * buffer.
- */
- drm_bo_type_device,
- /*
- * drm_bo_type_user are buffers of pages that already exist
- * in the process address space. They are more limited than
- * drm_bo_type_device buffers in that they must always
- * remain cached (as we assume the user pages are mapped cached),
- * and they are not sharable to other processes through DRM
- * (although, regular shared memory should still work fine).
- */
- drm_bo_type_user,
- /*
- * drm_bo_type_kernel are buffers that exist solely for use
- * within the kernel. The pages cannot be mapped into the
- * process. One obvious use would be for the ring
- * buffer where user access would not (ideally) be required.
- */
- drm_bo_type_kernel,
-};
-
-struct drm_buffer_object {
- struct drm_device *dev;
- struct drm_user_object base;
-
- /*
- * If there is a possibility that the usage variable is zero,
- * then dev->struct_mutext should be locked before incrementing it.
- */
-
- atomic_t usage;
- unsigned long buffer_start;
- enum drm_bo_type type;
- unsigned long offset;
- atomic_t mapped;
- struct drm_bo_mem_reg mem;
-
- struct list_head lru;
- struct list_head ddestroy;
-
- uint32_t fence_type;
- uint32_t fence_class;
- uint32_t new_fence_type;
- uint32_t new_fence_class;
- struct drm_fence_object *fence;
- uint32_t priv_flags;
- wait_queue_head_t event_queue;
- struct mutex mutex;
- unsigned long num_pages;
-
- /* For pinned buffers */
- struct drm_mm_node *pinned_node;
- uint32_t pinned_mem_type;
- struct list_head pinned_lru;
-
- /* For vm */
- struct drm_ttm *ttm;
- struct drm_map_list map_list;
- uint32_t memory_type;
- unsigned long bus_offset;
- uint32_t vm_flags;
- void *iomap;
-};
-
-#define _DRM_BO_FLAG_UNFENCED 0x00000001
-#define _DRM_BO_FLAG_EVICTED 0x00000002
-
-/*
- * This flag indicates that a flag called with bo->mutex held has
- * temporarily released the buffer object mutex, (usually to wait for something).
- * and thus any post-lock validation needs to be rerun.
- */
-
-#define _DRM_BO_FLAG_UNLOCKED 0x00000004
-
-struct drm_mem_type_manager {
- int has_type;
- int use_type;
- int kern_init_type;
- struct drm_mm manager;
- struct list_head lru;
- struct list_head pinned;
- uint32_t flags;
- uint32_t drm_bus_maptype;
- unsigned long gpu_offset;
- unsigned long io_offset;
- unsigned long io_size;
- void *io_addr;
- uint64_t size; /* size of managed area for reporting to userspace */
-};
-
-struct drm_bo_lock {
- struct drm_user_object base;
- wait_queue_head_t queue;
- atomic_t write_lock_pending;
- atomic_t readers;
-};
-
-#define _DRM_FLAG_MEMTYPE_FIXED 0x00000001 /* Fixed (on-card) PCI memory */
-#define _DRM_FLAG_MEMTYPE_MAPPABLE 0x00000002 /* Memory mappable */
-#define _DRM_FLAG_MEMTYPE_CACHED 0x00000004 /* Cached binding */
-#define _DRM_FLAG_NEEDS_IOREMAP 0x00000008 /* Fixed memory needs ioremap
- before kernel access. */
-#define _DRM_FLAG_MEMTYPE_CMA 0x00000010 /* Can't map aperture */
-#define _DRM_FLAG_MEMTYPE_CSELECT 0x00000020 /* Select caching */
-
-struct drm_buffer_manager {
- struct drm_bo_lock bm_lock;
- struct mutex evict_mutex;
- int nice_mode;
- int initialized;
- struct drm_file *last_to_validate;
- struct drm_mem_type_manager man[DRM_BO_MEM_TYPES];
- struct list_head unfenced;
- struct list_head ddestroy;
- struct delayed_work wq;
- uint32_t fence_type;
- unsigned long cur_pages;
- atomic_t count;
- struct page *dummy_read_page;
-};
-
-struct drm_bo_driver {
- const uint32_t *mem_type_prio;
- const uint32_t *mem_busy_prio;
- uint32_t num_mem_type_prio;
- uint32_t num_mem_busy_prio;
- struct drm_ttm_backend *(*create_ttm_backend_entry)
- (struct drm_device *dev);
- int (*fence_type) (struct drm_buffer_object *bo, uint32_t *fclass,
- uint32_t *type);
- int (*invalidate_caches) (struct drm_device *dev, uint64_t flags);
- int (*init_mem_type) (struct drm_device *dev, uint32_t type,
- struct drm_mem_type_manager *man);
- /*
- * evict_flags:
- *
- * @bo: the buffer object to be evicted
- *
- * Return the bo flags for a buffer which is not mapped to the hardware.
- * These will be placed in proposed_flags so that when the move is
- * finished, they'll end up in bo->mem.flags
- */
- uint64_t(*evict_flags) (struct drm_buffer_object *bo);
- /*
- * move:
- *
- * @bo: the buffer to move
- *
- * @evict: whether this motion is evicting the buffer from
- * the graphics address space
- *
- * @no_wait: whether this should give up and return -EBUSY
- * if this move would require sleeping
- *
- * @new_mem: the new memory region receiving the buffer
- *
- * Move a buffer between two memory regions.
- */
- int (*move) (struct drm_buffer_object *bo,
- int evict, int no_wait, struct drm_bo_mem_reg *new_mem);
- /*
- * ttm_cache_flush
- */
- void (*ttm_cache_flush)(struct drm_ttm *ttm);
-
- /*
- * command_stream_barrier
- *
- * @dev: The drm device.
- *
- * @bo: The buffer object to validate.
- *
- * @new_fence_class: The new fence class for the buffer object.
- *
- * @new_fence_type: The new fence type for the buffer object.
- *
- * @no_wait: whether this should give up and return -EBUSY
- * if this operation would require sleeping
- *
- * Insert a command stream barrier that makes sure that the
- * buffer is idle once the commands associated with the
- * current validation are starting to execute. If an error
- * condition is returned, or the function pointer is NULL,
- * the drm core will force buffer idle
- * during validation.
- */
-
- int (*command_stream_barrier) (struct drm_buffer_object *bo,
- uint32_t new_fence_class,
- uint32_t new_fence_type,
- int no_wait);
-};
-
-/*
- * buffer objects (drm_bo.c)
- */
-
-extern int drm_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_destroy_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_map_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_unmap_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_reference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_unreference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_wait_idle_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_setstatus_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_mm_init_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_mm_takedown_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_mm_lock_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_mm_unlock_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_mm_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_version_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int drm_bo_driver_finish(struct drm_device *dev);
-extern int drm_bo_driver_init(struct drm_device *dev);
-extern int drm_bo_pci_offset(struct drm_device *dev,
- struct drm_bo_mem_reg *mem,
- unsigned long *bus_base,
- unsigned long *bus_offset,
- unsigned long *bus_size);
-extern int drm_mem_reg_is_pci(struct drm_device *dev, struct drm_bo_mem_reg *mem);
-
-extern void drm_bo_usage_deref_locked(struct drm_buffer_object **bo);
-extern void drm_bo_usage_deref_unlocked(struct drm_buffer_object **bo);
-extern void drm_putback_buffer_objects(struct drm_device *dev);
-extern int drm_fence_buffer_objects(struct drm_device *dev,
- struct list_head *list,
- uint32_t fence_flags,
- struct drm_fence_object *fence,
- struct drm_fence_object **used_fence);
-extern void drm_bo_add_to_lru(struct drm_buffer_object *bo);
-extern int drm_buffer_object_create(struct drm_device *dev, unsigned long size,
- enum drm_bo_type type, uint64_t flags,
- uint32_t hint, uint32_t page_alignment,
- unsigned long buffer_start,
- struct drm_buffer_object **bo);
-extern int drm_bo_wait(struct drm_buffer_object *bo, int lazy, int interruptible,
- int no_wait, int check_unfenced);
-extern int drm_bo_mem_space(struct drm_buffer_object *bo,
- struct drm_bo_mem_reg *mem, int no_wait);
-extern int drm_bo_move_buffer(struct drm_buffer_object *bo,
- uint64_t new_mem_flags,
- int no_wait, int move_unfenced);
-extern int drm_bo_clean_mm(struct drm_device *dev, unsigned mem_type, int kern_clean);
-extern int drm_bo_init_mm(struct drm_device *dev, unsigned type,
- unsigned long p_offset, unsigned long p_size,
- int kern_init);
-extern int drm_bo_handle_validate(struct drm_file *file_priv, uint32_t handle,
- uint64_t flags, uint64_t mask, uint32_t hint,
- uint32_t fence_class,
- struct drm_bo_info_rep *rep,
- struct drm_buffer_object **bo_rep);
-extern struct drm_buffer_object *drm_lookup_buffer_object(struct drm_file *file_priv,
- uint32_t handle,
- int check_owner);
-extern int drm_bo_do_validate(struct drm_buffer_object *bo,
- uint64_t flags, uint64_t mask, uint32_t hint,
- uint32_t fence_class,
- struct drm_bo_info_rep *rep);
-extern int drm_bo_evict_cached(struct drm_buffer_object *bo);
-/*
- * Buffer object memory move- and map helpers.
- * drm_bo_move.c
- */
-
-extern int drm_bo_move_ttm(struct drm_buffer_object *bo,
- int evict, int no_wait,
- struct drm_bo_mem_reg *new_mem);
-extern int drm_bo_move_memcpy(struct drm_buffer_object *bo,
- int evict,
- int no_wait, struct drm_bo_mem_reg *new_mem);
-extern int drm_bo_move_accel_cleanup(struct drm_buffer_object *bo,
- int evict, int no_wait,
- uint32_t fence_class, uint32_t fence_type,
- uint32_t fence_flags,
- struct drm_bo_mem_reg *new_mem);
-extern int drm_bo_same_page(unsigned long offset, unsigned long offset2);
-extern unsigned long drm_bo_offset_end(unsigned long offset,
- unsigned long end);
-
-struct drm_bo_kmap_obj {
- void *virtual;
- struct page *page;
- enum {
- bo_map_iomap,
- bo_map_vmap,
- bo_map_kmap,
- bo_map_premapped,
- } bo_kmap_type;
-};
-
-static inline void *drm_bmo_virtual(struct drm_bo_kmap_obj *map, int *is_iomem)
-{
- *is_iomem = (map->bo_kmap_type == bo_map_iomap ||
- map->bo_kmap_type == bo_map_premapped);
- return map->virtual;
-}
-extern void drm_bo_kunmap(struct drm_bo_kmap_obj *map);
-extern int drm_bo_kmap(struct drm_buffer_object *bo, unsigned long start_page,
- unsigned long num_pages, struct drm_bo_kmap_obj *map);
-extern int drm_bo_pfn_prot(struct drm_buffer_object *bo,
- unsigned long dst_offset,
- unsigned long *pfn,
- pgprot_t *prot);
-extern void drm_bo_fill_rep_arg(struct drm_buffer_object *bo,
- struct drm_bo_info_rep *rep);
-
-
-/*
- * drm_regman.c
- */
-
-struct drm_reg {
- struct list_head head;
- struct drm_fence_object *fence;
- uint32_t fence_type;
- uint32_t new_fence_type;
-};
-
-struct drm_reg_manager {
- struct list_head free;
- struct list_head lru;
- struct list_head unfenced;
-
- int (*reg_reusable)(const struct drm_reg *reg, const void *data);
- void (*reg_destroy)(struct drm_reg *reg);
-};
-
-extern int drm_regs_alloc(struct drm_reg_manager *manager,
- const void *data,
- uint32_t fence_class,
- uint32_t fence_type,
- int interruptible,
- int no_wait,
- struct drm_reg **reg);
-
-extern void drm_regs_fence(struct drm_reg_manager *regs,
- struct drm_fence_object *fence);
-
-extern void drm_regs_free(struct drm_reg_manager *manager);
-extern void drm_regs_add(struct drm_reg_manager *manager, struct drm_reg *reg);
-extern void drm_regs_init(struct drm_reg_manager *manager,
- int (*reg_reusable)(const struct drm_reg *,
- const void *),
- void (*reg_destroy)(struct drm_reg *));
-
-/*
- * drm_bo_lock.c
- * Simple replacement for the hardware lock on buffer manager init and clean.
- */
-
-
-extern void drm_bo_init_lock(struct drm_bo_lock *lock);
-extern void drm_bo_read_unlock(struct drm_bo_lock *lock);
-extern int drm_bo_read_lock(struct drm_bo_lock *lock,
- int interruptible);
-extern int drm_bo_write_lock(struct drm_bo_lock *lock,
- int interruptible,
- struct drm_file *file_priv);
-
-extern int drm_bo_write_unlock(struct drm_bo_lock *lock,
- struct drm_file *file_priv);
-
-#ifdef CONFIG_DEBUG_MUTEXES
-#define DRM_ASSERT_LOCKED(_mutex) \
- BUG_ON(!mutex_is_locked(_mutex) || \
- ((_mutex)->owner != current_thread_info()))
-#else
-#define DRM_ASSERT_LOCKED(_mutex)
-#endif
-#endif
diff --git a/linux-core/drm_proc.c b/linux-core/drm_proc.c
index 15d8cb96..57c83278 100644
--- a/linux-core/drm_proc.c
+++ b/linux-core/drm_proc.c
@@ -49,8 +49,6 @@ static int drm_queues_info(char *buf, char **start, off_t offset,
int request, int *eof, void *data);
static int drm_bufs_info(char *buf, char **start, off_t offset,
int request, int *eof, void *data);
-static int drm_objects_info(char *buf, char **start, off_t offset,
- int request, int *eof, void *data);
static int drm_gem_name_info(char *buf, char **start, off_t offset,
int request, int *eof, void *data);
static int drm_gem_object_info(char *buf, char **start, off_t offset,
@@ -73,7 +71,6 @@ static struct drm_proc_list {
{"clients", drm_clients_info},
{"queues", drm_queues_info},
{"bufs", drm_bufs_info},
- {"objects", drm_objects_info},
{"gem_names", drm_gem_name_info},
{"gem_objects", drm_gem_object_info},
#if DRM_DEBUG_CODE
@@ -432,105 +429,6 @@ static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
}
/**
- * Called when "/proc/dri/.../objects" is read.
- *
- * \param buf output buffer.
- * \param start start of output data.
- * \param offset requested start offset.
- * \param request requested number of bytes.
- * \param eof whether there is no more data to return.
- * \param data private data.
- * \return number of written bytes.
- */
-static int drm__objects_info(char *buf, char **start, off_t offset, int request,
- int *eof, void *data)
-{
- struct drm_minor *minor = (struct drm_minor *) data;
- struct drm_device *dev = minor->dev;
- int len = 0;
- struct drm_buffer_manager *bm = &dev->bm;
- struct drm_fence_manager *fm = &dev->fm;
- uint64_t used_mem;
- uint64_t used_emer;
- uint64_t low_mem;
- uint64_t high_mem;
- uint64_t emer_mem;
-
- if (offset > DRM_PROC_LIMIT) {
- *eof = 1;
- return 0;
- }
-
- *start = &buf[offset];
- *eof = 0;
-
- DRM_PROC_PRINT("Object accounting:\n\n");
- if (fm->initialized) {
- DRM_PROC_PRINT("Number of active fence objects: %d.\n",
- atomic_read(&fm->count));
- } else {
- DRM_PROC_PRINT("Fence objects are not supported by this driver\n");
- }
-
- if (bm->initialized) {
- DRM_PROC_PRINT("Number of active buffer objects: %d.\n\n",
- atomic_read(&bm->count));
- }
- DRM_PROC_PRINT("Memory accounting:\n\n");
- if (bm->initialized) {
- DRM_PROC_PRINT("Number of locked GATT pages: %lu.\n", bm->cur_pages);
- } else {
- DRM_PROC_PRINT("Buffer objects are not supported by this driver.\n");
- }
-
- drm_query_memctl(&used_mem, &used_emer, &low_mem, &high_mem, &emer_mem);
-
- if (used_mem > 16*PAGE_SIZE) {
- DRM_PROC_PRINT("Used object memory is %lu pages.\n",
- (unsigned long) (used_mem >> PAGE_SHIFT));
- } else {
- DRM_PROC_PRINT("Used object memory is %lu bytes.\n",
- (unsigned long) used_mem);
- }
- if (used_emer > 16*PAGE_SIZE) {
- DRM_PROC_PRINT("Used emergency memory is %lu pages.\n",
- (unsigned long) (used_emer >> PAGE_SHIFT));
- } else {
- DRM_PROC_PRINT("Used emergency memory is %lu bytes.\n\n",
- (unsigned long) used_emer);
- }
- DRM_PROC_PRINT("Soft object memory usage threshold is %lu pages.\n",
- (unsigned long) (low_mem >> PAGE_SHIFT));
- DRM_PROC_PRINT("Hard object memory usage threshold is %lu pages.\n",
- (unsigned long) (high_mem >> PAGE_SHIFT));
- DRM_PROC_PRINT("Emergency root only memory usage threshold is %lu pages.\n",
- (unsigned long) (emer_mem >> PAGE_SHIFT));
-
- DRM_PROC_PRINT("\n");
-
- if (len > request + offset)
- return request;
- *eof = 1;
- return len - offset;
-}
-
-/**
- * Simply calls _objects_info() while holding the drm_device::struct_mutex lock.
- */
-static int drm_objects_info(char *buf, char **start, off_t offset, int request,
- int *eof, void *data)
-{
- struct drm_minor *minor = (struct drm_minor *) data;
- struct drm_device *dev = minor->dev;
- int ret;
-
- mutex_lock(&dev->struct_mutex);
- ret = drm__objects_info(buf, start, offset, request, eof, data);
- mutex_unlock(&dev->struct_mutex);
- return ret;
-}
-
-/**
* Called when "/proc/dri/.../clients" is read.
*
* \param buf output buffer.
diff --git a/linux-core/drm_stub.c b/linux-core/drm_stub.c
index 1518bc6d..6e68f677 100644
--- a/linux-core/drm_stub.c
+++ b/linux-core/drm_stub.c
@@ -98,7 +98,6 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
init_timer(&dev->timer);
mutex_init(&dev->struct_mutex);
mutex_init(&dev->ctxlist_mutex);
- mutex_init(&dev->bm.evict_mutex);
idr_init(&dev->drw_idr);
@@ -115,17 +114,6 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
if (drm_ht_create(&dev->map_hash, DRM_MAP_HASH_ORDER)) {
return -ENOMEM;
}
- if (drm_mm_init(&dev->offset_manager, DRM_FILE_PAGE_OFFSET_START,
- DRM_FILE_PAGE_OFFSET_SIZE)) {
- drm_ht_remove(&dev->map_hash);
- return -ENOMEM;
- }
-
- if (drm_ht_create(&dev->object_hash, DRM_OBJECT_HASH_ORDER)) {
- drm_ht_remove(&dev->map_hash);
- drm_mm_takedown(&dev->offset_manager);
- return -ENOMEM;
- }
/* the DRM has 6 counters */
dev->counters = 6;
@@ -171,8 +159,6 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
}
}
- drm_fence_manager_init(dev);
-
return 0;
error_out_unreg:
diff --git a/linux-core/drm_ttm.c b/linux-core/drm_ttm.c
deleted file mode 100644
index cb3e7505..00000000
--- a/linux-core/drm_ttm.c
+++ /dev/null
@@ -1,512 +0,0 @@
-/**************************************************************************
- *
- * Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-
-#if defined( CONFIG_X86 ) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
-static void drm_clflush_page(struct page *page)
-{
- uint8_t *page_virtual;
- unsigned int i;
-
- if (unlikely(page == NULL))
- return;
-
- page_virtual = kmap_atomic(page, KM_USER0);
-
- for (i=0; i < PAGE_SIZE; i += boot_cpu_data.x86_clflush_size)
- clflush(page_virtual + i);
-
- kunmap_atomic(page_virtual, KM_USER0);
-}
-
-static void drm_ttm_cache_flush_clflush(struct page *pages[], unsigned long num_pages)
-{
- unsigned long i;
-
- mb();
- for (i=0; i < num_pages; ++i)
- drm_clflush_page(*pages++);
- mb();
-}
-#endif
-
-static void drm_ttm_ipi_handler(void *null)
-{
- flush_agp_cache();
-}
-
-void drm_ttm_cache_flush(struct page *pages[], unsigned long num_pages)
-{
-
-#if defined( CONFIG_X86 ) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
- if (cpu_has_clflush) {
- drm_ttm_cache_flush_clflush(pages, num_pages);
- return;
- }
-#endif
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))
- if (on_each_cpu(drm_ttm_ipi_handler, NULL, 1))
-#else
- if (on_each_cpu(drm_ttm_ipi_handler, NULL, 1, 1) != 0)
-#endif
- DRM_ERROR("Timed out waiting for drm cache flush.\n");
-}
-EXPORT_SYMBOL(drm_ttm_cache_flush);
-
-/**
- * Allocates storage for pointers to the pages that back the ttm.
- *
- * Uses kmalloc if possible. Otherwise falls back to vmalloc.
- */
-static void drm_ttm_alloc_page_directory(struct drm_ttm *ttm)
-{
- unsigned long size = ttm->num_pages * sizeof(*ttm->pages);
- ttm->pages = NULL;
-
- if (drm_alloc_memctl(size))
- return;
-
- if (size <= PAGE_SIZE)
- ttm->pages = drm_calloc(1, size, DRM_MEM_TTM);
-
- if (!ttm->pages) {
- ttm->pages = vmalloc_user(size);
- if (ttm->pages)
- ttm->page_flags |= DRM_TTM_PAGEDIR_VMALLOC;
- }
- if (!ttm->pages)
- drm_free_memctl(size);
-}
-
-static void drm_ttm_free_page_directory(struct drm_ttm *ttm)
-{
- unsigned long size = ttm->num_pages * sizeof(*ttm->pages);
-
- if (ttm->page_flags & DRM_TTM_PAGEDIR_VMALLOC) {
- vfree(ttm->pages);
- ttm->page_flags &= ~DRM_TTM_PAGEDIR_VMALLOC;
- } else {
- drm_free(ttm->pages, size, DRM_MEM_TTM);
- }
- drm_free_memctl(size);
- ttm->pages = NULL;
-}
-
-static struct page *drm_ttm_alloc_page(void)
-{
- struct page *page;
-
- if (drm_alloc_memctl(PAGE_SIZE))
- return NULL;
-
- page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
- if (!page) {
- drm_free_memctl(PAGE_SIZE);
- return NULL;
- }
- return page;
-}
-
-/*
- * Change caching policy for the linear kernel map
- * for range of pages in a ttm.
- */
-
-static int drm_ttm_set_caching(struct drm_ttm *ttm, int noncached)
-{
- int i;
- struct page **cur_page;
- int do_tlbflush = 0;
-
- if ((ttm->page_flags & DRM_TTM_PAGE_UNCACHED) == noncached)
- return 0;
-
- if (noncached)
- drm_ttm_cache_flush(ttm->pages, ttm->num_pages);
-
- for (i = 0; i < ttm->num_pages; ++i) {
- cur_page = ttm->pages + i;
- if (*cur_page) {
- if (!PageHighMem(*cur_page)) {
- if (noncached) {
- map_page_into_agp(*cur_page);
- } else {
- unmap_page_from_agp(*cur_page);
- }
- do_tlbflush = 1;
- }
- }
- }
- if (do_tlbflush)
- flush_agp_mappings();
-
- DRM_FLAG_MASKED(ttm->page_flags, noncached, DRM_TTM_PAGE_UNCACHED);
-
- return 0;
-}
-
-
-static void drm_ttm_free_user_pages(struct drm_ttm *ttm)
-{
- int write;
- int dirty;
- struct page *page;
- int i;
-
- BUG_ON(!(ttm->page_flags & DRM_TTM_PAGE_USER));
- write = ((ttm->page_flags & DRM_TTM_PAGE_WRITE) != 0);
- dirty = ((ttm->page_flags & DRM_TTM_PAGE_USER_DIRTY) != 0);
-
- for (i = 0; i < ttm->num_pages; ++i) {
- page = ttm->pages[i];
- if (page == NULL)
- continue;
-
- if (page == ttm->dummy_read_page) {
- BUG_ON(write);
- continue;
- }
-
- if (write && dirty && !PageReserved(page))
- set_page_dirty_lock(page);
-
- ttm->pages[i] = NULL;
- put_page(page);
- }
-}
-
-static void drm_ttm_free_alloced_pages(struct drm_ttm *ttm)
-{
- int i;
- struct drm_buffer_manager *bm = &ttm->dev->bm;
- struct page **cur_page;
-
- for (i = 0; i < ttm->num_pages; ++i) {
- cur_page = ttm->pages + i;
- if (*cur_page) {
- if (page_count(*cur_page) != 1)
- DRM_ERROR("Erroneous page count. Leaking pages.\n");
- if (page_mapped(*cur_page))
- DRM_ERROR("Erroneous map count. Leaking page mappings.\n");
- __free_page(*cur_page);
- drm_free_memctl(PAGE_SIZE);
- --bm->cur_pages;
- }
- }
-}
-
-/*
- * Free all resources associated with a ttm.
- */
-
-int drm_ttm_destroy(struct drm_ttm *ttm)
-{
- struct drm_ttm_backend *be;
-
- if (!ttm)
- return 0;
-
- be = ttm->be;
- if (be) {
- be->func->destroy(be);
- ttm->be = NULL;
- }
-
- if (ttm->pages) {
- if (ttm->page_flags & DRM_TTM_PAGE_UNCACHED)
- drm_ttm_set_caching(ttm, 0);
-
- if (ttm->page_flags & DRM_TTM_PAGE_USER)
- drm_ttm_free_user_pages(ttm);
- else
- drm_ttm_free_alloced_pages(ttm);
-
- drm_ttm_free_page_directory(ttm);
- }
-
- drm_ctl_free(ttm, sizeof(*ttm), DRM_MEM_TTM);
- return 0;
-}
-
-struct page *drm_ttm_get_page(struct drm_ttm *ttm, int index)
-{
- struct page *p;
- struct drm_buffer_manager *bm = &ttm->dev->bm;
-
- while(NULL == (p = ttm->pages[index])) {
- p = drm_ttm_alloc_page();
- if (!p)
- return NULL;
-
- if (PageHighMem(p))
- ttm->pages[--ttm->first_himem_page] = p;
- else
- ttm->pages[++ttm->last_lomem_page] = p;
-
- ++bm->cur_pages;
- }
- return p;
-}
-EXPORT_SYMBOL(drm_ttm_get_page);
-
-/**
- * drm_ttm_set_user:
- *
- * @ttm: the ttm to map pages to. This must always be
- * a freshly created ttm.
- *
- * @tsk: a pointer to the address space from which to map
- * pages.
- *
- * @write: a boolean indicating that write access is desired
- *
- * start: the starting address
- *
- * Map a range of user addresses to a new ttm object. This
- * provides access to user memory from the graphics device.
- */
-int drm_ttm_set_user(struct drm_ttm *ttm,
- struct task_struct *tsk,
- unsigned long start,
- unsigned long num_pages)
-{
- struct mm_struct *mm = tsk->mm;
- int ret;
- int write = (ttm->page_flags & DRM_TTM_PAGE_WRITE) != 0;
-
- BUG_ON(num_pages != ttm->num_pages);
- BUG_ON((ttm->page_flags & DRM_TTM_PAGE_USER) == 0);
-
- down_read(&mm->mmap_sem);
- ret = get_user_pages(tsk, mm, start, num_pages,
- write, 0, ttm->pages, NULL);
- up_read(&mm->mmap_sem);
-
- if (ret != num_pages && write) {
- drm_ttm_free_user_pages(ttm);
- return -ENOMEM;
- }
-
- return 0;
-}
-
-/**
- * drm_ttm_populate:
- *
- * @ttm: the object to allocate pages for
- *
- * Allocate pages for all unset page entries, then
- * call the backend to create the hardware mappings
- */
-int drm_ttm_populate(struct drm_ttm *ttm)
-{
- struct page *page;
- unsigned long i;
- struct drm_ttm_backend *be;
-
- if (ttm->state != ttm_unpopulated)
- return 0;
-
- be = ttm->be;
-
- for (i = 0; i < ttm->num_pages; ++i) {
- page = drm_ttm_get_page(ttm, i);
- if (!page)
- return -ENOMEM;
- }
-
- be->func->populate(be, ttm->num_pages, ttm->pages, ttm->dummy_read_page);
- ttm->state = ttm_unbound;
- return 0;
-}
-
-/**
- * drm_ttm_create:
- *
- * @dev: the drm_device
- *
- * @size: The size (in bytes) of the desired object
- *
- * @page_flags: various DRM_TTM_PAGE_* flags. See drm_object.h.
- *
- * Allocate and initialize a ttm, leaving it unpopulated at this time
- */
-
-struct drm_ttm *drm_ttm_create(struct drm_device *dev, unsigned long size,
- uint32_t page_flags, struct page *dummy_read_page)
-{
- struct drm_bo_driver *bo_driver = dev->driver->bo_driver;
- struct drm_ttm *ttm;
-
- if (!bo_driver)
- return NULL;
-
- ttm = drm_ctl_calloc(1, sizeof(*ttm), DRM_MEM_TTM);
- if (!ttm)
- return NULL;
-
- ttm->dev = dev;
- atomic_set(&ttm->vma_count, 0);
-
- ttm->destroy = 0;
- ttm->num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
- ttm->first_himem_page = ttm->num_pages;
- ttm->last_lomem_page = -1;
-
- ttm->page_flags = page_flags;
-
- ttm->dummy_read_page = dummy_read_page;
-
- /*
- * Account also for AGP module memory usage.
- */
-
- drm_ttm_alloc_page_directory(ttm);
- if (!ttm->pages) {
- drm_ttm_destroy(ttm);
- DRM_ERROR("Failed allocating page table\n");
- return NULL;
- }
- ttm->be = bo_driver->create_ttm_backend_entry(dev);
- if (!ttm->be) {
- drm_ttm_destroy(ttm);
- DRM_ERROR("Failed creating ttm backend entry\n");
- return NULL;
- }
- ttm->state = ttm_unpopulated;
- return ttm;
-}
-
-/**
- * drm_ttm_evict:
- *
- * @ttm: the object to be unbound from the aperture.
- *
- * Transition a ttm from bound to evicted, where it
- * isn't present in the aperture, but various caches may
- * not be consistent.
- */
-void drm_ttm_evict(struct drm_ttm *ttm)
-{
- struct drm_ttm_backend *be = ttm->be;
- int ret;
-
- if (ttm->state == ttm_bound) {
- ret = be->func->unbind(be);
- BUG_ON(ret);
- }
-
- ttm->state = ttm_evicted;
-}
-
-/**
- * drm_ttm_fixup_caching:
- *
- * @ttm: the object to set unbound
- *
- * XXX this function is misnamed. Transition a ttm from evicted to
- * unbound, flushing caches as appropriate.
- */
-void drm_ttm_fixup_caching(struct drm_ttm *ttm)
-{
-
- if (ttm->state == ttm_evicted) {
- struct drm_ttm_backend *be = ttm->be;
- if (be->func->needs_ub_cache_adjust(be))
- drm_ttm_set_caching(ttm, 0);
- ttm->state = ttm_unbound;
- }
-}
-
-/**
- * drm_ttm_unbind:
- *
- * @ttm: the object to unbind from the graphics device
- *
- * Unbind an object from the aperture. This removes the mappings
- * from the graphics device and flushes caches if necessary.
- */
-void drm_ttm_unbind(struct drm_ttm *ttm)
-{
- if (ttm->state == ttm_bound)
- drm_ttm_evict(ttm);
-
- drm_ttm_fixup_caching(ttm);
-}
-
-/**
- * drm_ttm_bind:
- *
- * @ttm: the ttm object to bind to the graphics device
- *
- * @bo_mem: the aperture memory region which will hold the object
- *
- * Bind a ttm object to the aperture. This ensures that the necessary
- * pages are allocated, flushes CPU caches as needed and marks the
- * ttm as DRM_TTM_PAGE_USER_DIRTY to indicate that it may have been
- * modified by the GPU
- */
-int drm_ttm_bind(struct drm_ttm *ttm, struct drm_bo_mem_reg *bo_mem)
-{
- struct drm_bo_driver *bo_driver = ttm->dev->driver->bo_driver;
- int ret = 0;
- struct drm_ttm_backend *be;
-
- if (!ttm)
- return -EINVAL;
- if (ttm->state == ttm_bound)
- return 0;
-
- be = ttm->be;
-
- ret = drm_ttm_populate(ttm);
- if (ret)
- return ret;
-
- if (ttm->state == ttm_unbound && !(bo_mem->flags & DRM_BO_FLAG_CACHED))
- drm_ttm_set_caching(ttm, DRM_TTM_PAGE_UNCACHED);
- else if ((bo_mem->flags & DRM_BO_FLAG_CACHED_MAPPED) &&
- bo_driver->ttm_cache_flush)
- bo_driver->ttm_cache_flush(ttm);
-
- ret = be->func->bind(be, bo_mem);
- if (ret) {
- ttm->state = ttm_evicted;
- DRM_ERROR("Couldn't bind backend.\n");
- return ret;
- }
-
- ttm->state = ttm_bound;
- if (ttm->page_flags & DRM_TTM_PAGE_USER)
- ttm->page_flags |= DRM_TTM_PAGE_USER_DIRTY;
- return 0;
-}
-EXPORT_SYMBOL(drm_ttm_bind);
diff --git a/linux-core/drm_vm.c b/linux-core/drm_vm.c
index b99c86d1..c6cee1a1 100644
--- a/linux-core/drm_vm.c
+++ b/linux-core/drm_vm.c
@@ -41,10 +41,6 @@
static void drm_vm_open(struct vm_area_struct *vma);
static void drm_vm_close(struct vm_area_struct *vma);
-static int drm_bo_mmap_locked(struct vm_area_struct *vma,
- struct file *filp,
- drm_local_map_t *map);
-
pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma)
{
@@ -651,8 +647,6 @@ static int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma)
vma->vm_flags |= VM_RESERVED;
vma->vm_page_prot = drm_dma_prot(map->type, vma);
break;
- case _DRM_TTM:
- return drm_bo_mmap_locked(vma, filp, map);
default:
return -EINVAL; /* This should never happen. */
}
@@ -676,195 +670,3 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
return ret;
}
EXPORT_SYMBOL(drm_mmap);
-
-/**
- * buffer object vm functions.
- */
-
-/**
- * \c Pagefault method for buffer objects.
- *
- * \param vma Virtual memory area.
- * \param vmf vm fault data
- * \return Error or VM_FAULT_NOPAGE:. The pfn is manually inserted.
- *
- * It's important that pfns are inserted while holding the bo->mutex lock.
- * otherwise we might race with unmap_mapping_range() which is always
- * called with the bo->mutex lock held.
- *
- * We're modifying the page attribute bits of the vma->vm_page_prot field,
- * without holding the mmap_sem in write mode. Only in read mode.
- * These bits are not used by the mm subsystem code, and we consider them
- * protected by the bo->mutex lock.
- */
-
-#if !defined(DRM_NO_FAULT)
-static int drm_bo_vm_fault(struct vm_area_struct *vma,
- struct vm_fault *vmf)
-{
- struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
- unsigned long page_offset;
- struct page *page = NULL;
- struct drm_ttm *ttm;
- struct drm_device *dev;
- unsigned long pfn;
- int err;
- unsigned long bus_base;
- unsigned long bus_offset;
- unsigned long bus_size;
- unsigned long ret = VM_FAULT_NOPAGE;
-
- dev = bo->dev;
- err = drm_bo_read_lock(&dev->bm.bm_lock, 1);
- if (err)
- return VM_FAULT_NOPAGE;
-
- err = mutex_lock_interruptible(&bo->mutex);
- if (err) {
- drm_bo_read_unlock(&dev->bm.bm_lock);
- return VM_FAULT_NOPAGE;
- }
-
- err = drm_bo_wait(bo, 0, 1, 0, 1);
- if (err) {
- ret = (err != -EAGAIN) ? VM_FAULT_SIGBUS : VM_FAULT_NOPAGE;
- bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
- goto out_unlock;
- }
-
- bo->priv_flags &= ~_DRM_BO_FLAG_UNLOCKED;
-
- /*
- * If buffer happens to be in a non-mappable location,
- * move it to a mappable.
- */
-
- if (!(bo->mem.flags & DRM_BO_FLAG_MAPPABLE)) {
- uint32_t new_flags = bo->mem.proposed_flags |
- DRM_BO_FLAG_MAPPABLE |
- DRM_BO_FLAG_FORCE_MAPPABLE;
- err = drm_bo_move_buffer(bo, new_flags, 0, 0);
- if (err) {
- ret = (err != -EAGAIN) ? VM_FAULT_SIGBUS : VM_FAULT_NOPAGE;
- goto out_unlock;
- }
- }
-
- err = drm_bo_pci_offset(dev, &bo->mem, &bus_base, &bus_offset,
- &bus_size);
-
- if (err) {
- ret = VM_FAULT_SIGBUS;
- goto out_unlock;
- }
-
- page_offset = ((unsigned long)vmf->virtual_address - vma->vm_start) >> PAGE_SHIFT;
-
- if (bus_size) {
- struct drm_mem_type_manager *man = &dev->bm.man[bo->mem.mem_type];
-
- pfn = ((bus_base + bus_offset) >> PAGE_SHIFT) + page_offset;
- vma->vm_page_prot = drm_io_prot(man->drm_bus_maptype, vma);
- } else {
- ttm = bo->ttm;
-
- drm_ttm_fixup_caching(ttm);
- page = drm_ttm_get_page(ttm, page_offset);
- if (!page) {
- ret = VM_FAULT_OOM;
- goto out_unlock;
- }
- pfn = page_to_pfn(page);
- vma->vm_page_prot = (bo->mem.flags & DRM_BO_FLAG_CACHED) ?
- vm_get_page_prot(vma->vm_flags) :
- drm_io_prot(_DRM_TTM, vma);
- }
-
- err = vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn);
- if (err) {
- ret = (err != -EAGAIN) ? VM_FAULT_OOM : VM_FAULT_NOPAGE;
- goto out_unlock;
- }
-out_unlock:
- BUG_ON(bo->priv_flags & _DRM_BO_FLAG_UNLOCKED);
- mutex_unlock(&bo->mutex);
- drm_bo_read_unlock(&dev->bm.bm_lock);
- return ret;
-}
-#endif
-
-static void drm_bo_vm_open_locked(struct vm_area_struct *vma)
-{
- struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
-
- drm_vm_open_locked(vma);
- atomic_inc(&bo->usage);
-}
-
-/**
- * \c vma open method for buffer objects.
- *
- * \param vma virtual memory area.
- */
-
-static void drm_bo_vm_open(struct vm_area_struct *vma)
-{
- struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
- struct drm_device *dev = bo->dev;
-
- mutex_lock(&dev->struct_mutex);
- drm_bo_vm_open_locked(vma);
- mutex_unlock(&dev->struct_mutex);
-}
-
-/**
- * \c vma close method for buffer objects.
- *
- * \param vma virtual memory area.
- */
-
-static void drm_bo_vm_close(struct vm_area_struct *vma)
-{
- struct drm_buffer_object *bo = (struct drm_buffer_object *) vma->vm_private_data;
- struct drm_device *dev = bo->dev;
-
- drm_vm_close(vma);
- if (bo) {
- mutex_lock(&dev->struct_mutex);
- drm_bo_usage_deref_locked((struct drm_buffer_object **)
- &vma->vm_private_data);
- mutex_unlock(&dev->struct_mutex);
- }
- return;
-}
-
-static struct vm_operations_struct drm_bo_vm_ops = {
-#ifdef DRM_NO_FAULT
- .nopfn = drm_bo_vm_nopfn,
-#else
- .fault = drm_bo_vm_fault,
-#endif
- .open = drm_bo_vm_open,
- .close = drm_bo_vm_close,
-};
-
-/**
- * mmap buffer object memory.
- *
- * \param vma virtual memory area.
- * \param file_priv DRM file private.
- * \param map The buffer object drm map.
- * \return zero on success or a negative number on failure.
- */
-static int drm_bo_mmap_locked(struct vm_area_struct *vma,
- struct file *filp,
- drm_local_map_t *map)
-{
- vma->vm_ops = &drm_bo_vm_ops;
- vma->vm_private_data = map->handle;
- vma->vm_file = filp;
- vma->vm_flags |= VM_RESERVED | VM_IO;
- vma->vm_flags |= VM_PFNMAP;
- drm_bo_vm_open_locked(vma);
- return 0;
-}
diff --git a/linux-core/via_buffer.c b/linux-core/via_buffer.c
deleted file mode 100644
index 532fae6a..00000000
--- a/linux-core/via_buffer.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/**************************************************************************
- *
- * Copyright (c) 2007 Tungsten Graphics, Inc., Cedar Park, TX., USA,
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-#include "via_drm.h"
-#include "via_drv.h"
-
-struct drm_ttm_backend *via_create_ttm_backend_entry(struct drm_device * dev)
-{
- return drm_agp_init_ttm(dev);
-}
-
-int via_fence_types(struct drm_buffer_object *bo, uint32_t * fclass,
- uint32_t * type)
-{
- *type = 3;
- return 0;
-}
-
-int via_invalidate_caches(struct drm_device * dev, uint64_t flags)
-{
- /*
- * FIXME: Invalidate texture caches here.
- */
-
- return 0;
-}
-
-
-static int via_vram_info(struct drm_device *dev,
- unsigned long *offset,
- unsigned long *size)
-{
- struct pci_dev *pdev = dev->pdev;
- unsigned long flags;
-
- int ret = -EINVAL;
- int i;
- for (i=0; i<6; ++i) {
- flags = pci_resource_flags(pdev, i);
- if ((flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH)) ==
- (IORESOURCE_MEM | IORESOURCE_PREFETCH)) {
- ret = 0;
- break;
- }
- }
-
- if (ret) {
- DRM_ERROR("Could not find VRAM PCI resource\n");
- return ret;
- }
-
- *offset = pci_resource_start(pdev, i);
- *size = pci_resource_end(pdev, i) - *offset + 1;
- return 0;
-}
-
-int via_init_mem_type(struct drm_device * dev, uint32_t type,
- struct drm_mem_type_manager * man)
-{
- switch (type) {
- case DRM_BO_MEM_LOCAL:
- /* System memory */
-
- man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE |
- _DRM_FLAG_MEMTYPE_CACHED;
- man->drm_bus_maptype = 0;
- break;
-
- case DRM_BO_MEM_TT:
- /* Dynamic agpgart memory */
-
- if (!(drm_core_has_AGP(dev) && dev->agp)) {
- DRM_ERROR("AGP is not enabled for memory type %u\n",
- (unsigned)type);
- return -EINVAL;
- }
- man->io_offset = dev->agp->agp_info.aper_base;
- man->io_size = dev->agp->agp_info.aper_size * 1024 * 1024;
- man->io_addr = NULL;
- man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE | _DRM_FLAG_NEEDS_IOREMAP;
-
- /* Only to get pte protection right. */
-
- man->drm_bus_maptype = _DRM_AGP;
- break;
-
- case DRM_BO_MEM_VRAM:
- /* "On-card" video ram */
-
- man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE | _DRM_FLAG_NEEDS_IOREMAP;
- man->drm_bus_maptype = _DRM_FRAME_BUFFER;
- man->io_addr = NULL;
- return via_vram_info(dev, &man->io_offset, &man->io_size);
- break;
-
- case DRM_BO_MEM_PRIV0:
- /* Pre-bound agpgart memory */
-
- if (!(drm_core_has_AGP(dev) && dev->agp)) {
- DRM_ERROR("AGP is not enabled for memory type %u\n",
- (unsigned)type);
- return -EINVAL;
- }
- man->io_offset = dev->agp->agp_info.aper_base;
- man->io_size = dev->agp->agp_info.aper_size * 1024 * 1024;
- man->io_addr = NULL;
- man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE |
- _DRM_FLAG_MEMTYPE_FIXED | _DRM_FLAG_NEEDS_IOREMAP;
- man->drm_bus_maptype = _DRM_AGP;
- break;
-
- default:
- DRM_ERROR("Unsupported memory type %u\n", (unsigned)type);
- return -EINVAL;
- }
- return 0;
-}
-
-uint64_t via_evict_flags(struct drm_buffer_object *bo)
-{
- switch (bo->mem.mem_type) {
- case DRM_BO_MEM_LOCAL:
- case DRM_BO_MEM_TT:
- return DRM_BO_FLAG_MEM_LOCAL; /* Evict TT to local */
- case DRM_BO_MEM_PRIV0: /* Evict pre-bound AGP to TT */
- return DRM_BO_MEM_TT;
- case DRM_BO_MEM_VRAM:
- if (bo->mem.num_pages > 128)
- return DRM_BO_MEM_TT;
- else
- return DRM_BO_MEM_LOCAL;
- default:
- return DRM_BO_MEM_LOCAL;
- }
-}
diff --git a/linux-core/via_fence.c b/linux-core/via_fence.c
deleted file mode 100644
index 3a680a32..00000000
--- a/linux-core/via_fence.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/**************************************************************************
- *
- * Copyright (c) 2007 Tungsten Graphics, Inc., Cedar Park, TX., USA,
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-#include "via_drm.h"
-#include "via_drv.h"
-
-/*
- * DRM_FENCE_TYPE_EXE guarantees that all command buffers can be evicted.
- * DRM_VIA_FENCE_TYPE_ACCEL guarantees that all 2D & 3D rendering is complete.
- */
-
-static void via_fence_poll(struct drm_device *dev, uint32_t class,
- uint32_t waiting_types)
-{
- drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
- uint32_t signaled_flush_types = 0;
- uint32_t status;
-
- if (class != 0)
- return;
-
- if (unlikely(!dev_priv))
- return;
-
- spin_lock(&dev_priv->fence_lock);
- if (waiting_types) {
-
- /*
- * Take the idlelock. This guarantees that the next time a client tries
- * to grab the lock, it will stall until the idlelock is released. This
- * guarantees that eventually, the GPU engines will be idle, but nothing
- * else. It cannot be used to protect the hardware.
- */
-
-
- if (!dev_priv->have_idlelock) {
- drm_idlelock_take(&dev->lock);
- dev_priv->have_idlelock = 1;
- }
-
- /*
- * Check if AGP command reader is idle.
- */
-
- if (waiting_types & DRM_FENCE_TYPE_EXE)
- if (VIA_READ(0x41C) & 0x80000000)
- signaled_flush_types |= DRM_FENCE_TYPE_EXE;
-
- /*
- * Check VRAM command queue empty and 2D + 3D engines idle.
- */
-
- if (waiting_types & DRM_VIA_FENCE_TYPE_ACCEL) {
- status = VIA_READ(VIA_REG_STATUS);
- if ((status & VIA_VR_QUEUE_BUSY) &&
- !(status & (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY | VIA_3D_ENG_BUSY)))
- signaled_flush_types |= DRM_VIA_FENCE_TYPE_ACCEL;
- }
-
- if (signaled_flush_types) {
- waiting_types &= ~signaled_flush_types;
- if (!waiting_types && dev_priv->have_idlelock) {
- drm_idlelock_release(&dev->lock);
- dev_priv->have_idlelock = 0;
- }
- drm_fence_handler(dev, 0, dev_priv->emit_0_sequence,
- signaled_flush_types, 0);
- }
- }
-
- spin_unlock(&dev_priv->fence_lock);
-
- return;
-}
-
-
-/**
- * Emit a fence sequence.
- */
-
-static int via_fence_emit_sequence(struct drm_device * dev, uint32_t class, uint32_t flags,
- uint32_t * sequence, uint32_t * native_type)
-{
- drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
- int ret = 0;
-
- if (!dev_priv)
- return -EINVAL;
-
- switch(class) {
- case 0: /* AGP command stream */
-
- /*
- * The sequence number isn't really used by the hardware yet.
- */
-
- spin_lock(&dev_priv->fence_lock);
- *sequence = ++dev_priv->emit_0_sequence;
- spin_unlock(&dev_priv->fence_lock);
-
- /*
- * When drm_fence_handler() is called with flush type 0x01, and a
- * sequence number, That means that the EXE flag is expired.
- * Nothing else. No implicit flushing or other engines idle.
- */
-
- *native_type = DRM_FENCE_TYPE_EXE;
- break;
- default:
- ret = -EINVAL;
- break;
- }
- return ret;
-}
-
-/**
- * No irq fence expirations implemented yet.
- * Although both the HQV engines and PCI dmablit engines signal
- * idle with an IRQ, we haven't implemented this yet.
- * This means that the drm fence manager will always poll for engine idle,
- * unless the caller wanting to wait for a fence object has indicated a lazy wait.
- */
-
-static int via_fence_has_irq(struct drm_device * dev, uint32_t class,
- uint32_t flags)
-{
- return 0;
-}
-
-struct drm_fence_driver via_fence_driver = {
- .num_classes = 1,
- .wrap_diff = (1 << 30),
- .flush_diff = (1 << 20),
- .sequence_mask = 0xffffffffU,
- .has_irq = via_fence_has_irq,
- .emit = via_fence_emit_sequence,
- .poll = via_fence_poll,
- .needed_flush = NULL,
- .wait = NULL
-};
diff --git a/linux-core/xgi_cmdlist.c b/linux-core/xgi_cmdlist.c
index 423208b0..dea9b518 100644
--- a/linux-core/xgi_cmdlist.c
+++ b/linux-core/xgi_cmdlist.c
@@ -148,9 +148,6 @@ int xgi_submit_cmdlist(struct drm_device * dev, void * data,
}
info->cmdring.last_ptr = xgi_find_pcie_virt(info, pCmdInfo->hw_addr);
-#ifdef XGI_HAVE_FENCE
- drm_fence_flush_old(info->dev, 0, info->next_sequence);
-#endif /* XGI_HAVE_FENCE */
return 0;
}
diff --git a/linux-core/xgi_drv.c b/linux-core/xgi_drv.c
index 51ace0ff..4d55f219 100644
--- a/linux-core/xgi_drv.c
+++ b/linux-core/xgi_drv.c
@@ -37,10 +37,6 @@ static struct pci_device_id pciidlist[] = {
xgi_PCI_IDS
};
-#ifdef XGI_HAVE_FENCE
-extern struct drm_fence_driver xgi_fence_driver;
-#endif /* XGI_HAVE_FENCE */
-
int xgi_bootstrap(struct drm_device *, void *, struct drm_file *);
static struct drm_ioctl_desc xgi_ioctls[] = {
@@ -105,10 +101,6 @@ static struct drm_driver driver = {
.remove = __devexit_p(drm_cleanup_pci),
},
-#ifdef XGI_HAVE_FENCE
- .fence_driver = &xgi_fence_driver,
-#endif /* XGI_HAVE_FENCE */
-
.name = DRIVER_NAME,
.desc = DRIVER_DESC,
.date = DRIVER_DATE,
@@ -362,9 +354,6 @@ irqreturn_t xgi_kern_isr(DRM_IRQ_ARGS)
DRM_WRITE32(info->mmio_map,
0x2800 + M2REG_AUTO_LINK_SETTING_ADDRESS,
cpu_to_le32(M2REG_AUTO_LINK_SETTING_COMMAND | irq_bits));
-#ifdef XGI_HAVE_FENCE
- xgi_fence_handler(dev);
-#endif /* XGI_HAVE_FENCE */
DRM_WAKEUP(&info->fence_queue);
return IRQ_HANDLED;
} else {
diff --git a/linux-core/xgi_drv.h b/linux-core/xgi_drv.h
index 5ad3ddb3..a3ca7fb4 100644
--- a/linux-core/xgi_drv.h
+++ b/linux-core/xgi_drv.h
@@ -99,18 +99,6 @@ extern void xgi_disable_mmio(struct xgi_info * info);
extern void xgi_enable_ge(struct xgi_info * info);
extern void xgi_disable_ge(struct xgi_info * info);
-/* TTM-style fences.
- */
-#ifdef XGI_HAVE_FENCE
-extern void xgi_poke_flush(struct drm_device * dev, uint32_t class);
-extern int xgi_fence_emit_sequence(struct drm_device * dev, uint32_t class,
- uint32_t flags, uint32_t * sequence, uint32_t * native_type);
-extern void xgi_fence_handler(struct drm_device * dev);
-extern int xgi_fence_has_irq(struct drm_device *dev, uint32_t class,
- uint32_t flags);
-#endif /* XGI_HAVE_FENCE */
-
-
/* Non-TTM-style fences.
*/
extern int xgi_set_fence_ioctl(struct drm_device * dev, void * data,
diff --git a/linux-core/xgi_fence.c b/linux-core/xgi_fence.c
index 38cf9e4f..7553177c 100644
--- a/linux-core/xgi_fence.c
+++ b/linux-core/xgi_fence.c
@@ -97,90 +97,3 @@ int xgi_wait_fence_ioctl(struct drm_device * dev, void * data,
(void) filp;
return xgi_low_level_fence_wait(dev, (u32 *) data);
}
-
-
-#ifdef XGI_HAVE_FENCE
-static void xgi_fence_poll(struct drm_device * dev, uint32_t class,
- uint32_t waiting_types)
-{
- struct xgi_info * info = dev->dev_private;
- uint32_t signaled_types = 0;
-
-
- if ((info == NULL) || (class != 0))
- return;
-
- DRM_SPINLOCK(&info->fence_lock);
-
- if (waiting_types) {
- if (waiting_types & DRM_FENCE_TYPE_EXE) {
- const u32 begin_id = le32_to_cpu(DRM_READ32(info->mmio_map,
- 0x2820))
- & BEGIN_BEGIN_IDENTIFICATION_MASK;
-
- if (begin_id != info->complete_sequence) {
- info->complete_sequence = begin_id;
- signaled_types |= DRM_FENCE_TYPE_EXE;
- }
- }
-
- if (signaled_types) {
- drm_fence_handler(dev, 0, info->complete_sequence,
- signaled_types, 0);
- }
- }
-
- DRM_SPINUNLOCK(&info->fence_lock);
-}
-
-
-int xgi_fence_emit_sequence(struct drm_device * dev, uint32_t class,
- uint32_t flags, uint32_t * sequence,
- uint32_t * native_type)
-{
- int err;
-
- (void) flags;
-
- if (class != 0)
- return -EINVAL;
-
- err = xgi_low_level_fence_emit(dev, sequence);
- if (err)
- return err;
-
- *native_type = DRM_FENCE_TYPE_EXE;
- return 0;
-}
-
-
-void xgi_fence_handler(struct drm_device * dev)
-{
- struct drm_fence_manager * fm = &dev->fm;
- struct drm_fence_class_manager *fc = &fm->fence_class[0];
-
- write_lock(&fm->lock);
- xgi_fence_poll(dev, 0, fc->waiting_types);
- write_unlock(&fm->lock);
-}
-
-
-int xgi_fence_has_irq(struct drm_device *dev, uint32_t class, uint32_t flags)
-{
- return ((class == 0) && (flags == DRM_FENCE_TYPE_EXE)) ? 1 : 0;
-}
-
-struct drm_fence_driver xgi_fence_driver = {
- .num_classes = 1,
- .wrap_diff = BEGIN_BEGIN_IDENTIFICATION_MASK,
- .flush_diff = BEGIN_BEGIN_IDENTIFICATION_MASK - 1,
- .sequence_mask = BEGIN_BEGIN_IDENTIFICATION_MASK,
- .has_irq = xgi_fence_has_irq,
- .emit = xgi_fence_emit_sequence,
- .flush = NULL,
- .poll = xgi_fence_poll,
- .needed_flush = NULL,
- .wait = NULL
-};
-
-#endif /* XGI_HAVE_FENCE */