drm/ttm: apply linux kernel coding style to bo_lock/move/object/ttm.c

main
Dave Airlie 2007-11-05 19:09:18 +10:00
parent 7ad3890707
commit 6ee5412da0
4 changed files with 76 additions and 91 deletions

View File

@ -73,7 +73,6 @@ void drm_bo_read_unlock(struct drm_bo_lock *lock)
if (atomic_read(&lock->readers) == 0) if (atomic_read(&lock->readers) == 0)
wake_up_interruptible(&lock->queue); wake_up_interruptible(&lock->queue);
} }
EXPORT_SYMBOL(drm_bo_read_unlock); EXPORT_SYMBOL(drm_bo_read_unlock);
int drm_bo_read_lock(struct drm_bo_lock *lock) int drm_bo_read_lock(struct drm_bo_lock *lock)
@ -95,7 +94,6 @@ int drm_bo_read_lock(struct drm_bo_lock *lock)
} }
return 0; return 0;
} }
EXPORT_SYMBOL(drm_bo_read_lock); EXPORT_SYMBOL(drm_bo_read_lock);
static int __drm_bo_write_unlock(struct drm_bo_lock *lock) static int __drm_bo_write_unlock(struct drm_bo_lock *lock)
@ -123,9 +121,8 @@ int drm_bo_write_lock(struct drm_bo_lock *lock, struct drm_file *file_priv)
int ret = 0; int ret = 0;
struct drm_device *dev; struct drm_device *dev;
if (unlikely(atomic_cmpxchg(&lock->write_lock_pending, 0, 1) != 0)) { if (unlikely(atomic_cmpxchg(&lock->write_lock_pending, 0, 1) != 0))
return -EINVAL; return -EINVAL;
}
while (unlikely(atomic_cmpxchg(&lock->readers, 0, -1) != 0)) { while (unlikely(atomic_cmpxchg(&lock->readers, 0, -1) != 0)) {
ret = wait_event_interruptible ret = wait_event_interruptible
@ -149,9 +146,9 @@ int drm_bo_write_lock(struct drm_bo_lock *lock, struct drm_file *file_priv)
ret = drm_add_user_object(file_priv, &lock->base, 0); ret = drm_add_user_object(file_priv, &lock->base, 0);
lock->base.remove = &drm_bo_write_lock_remove; lock->base.remove = &drm_bo_write_lock_remove;
lock->base.type = drm_lock_type; lock->base.type = drm_lock_type;
if (ret) { if (ret)
(void)__drm_bo_write_unlock(lock); (void)__drm_bo_write_unlock(lock);
}
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
return ret; return ret;

View File

@ -35,7 +35,7 @@
* have not been requested to free also pinned regions. * have not been requested to free also pinned regions.
*/ */
static void drm_bo_free_old_node(struct drm_buffer_object * bo) static void drm_bo_free_old_node(struct drm_buffer_object *bo)
{ {
struct drm_bo_mem_reg *old_mem = &bo->mem; struct drm_bo_mem_reg *old_mem = &bo->mem;
@ -48,8 +48,8 @@ static void drm_bo_free_old_node(struct drm_buffer_object * bo)
old_mem->mm_node = NULL; old_mem->mm_node = NULL;
} }
int drm_bo_move_ttm(struct drm_buffer_object * bo, int drm_bo_move_ttm(struct drm_buffer_object *bo,
int evict, int no_wait, struct drm_bo_mem_reg * new_mem) int evict, int no_wait, struct drm_bo_mem_reg *new_mem)
{ {
struct drm_ttm *ttm = bo->ttm; struct drm_ttm *ttm = bo->ttm;
struct drm_bo_mem_reg *old_mem = &bo->mem; struct drm_bo_mem_reg *old_mem = &bo->mem;
@ -82,7 +82,6 @@ int drm_bo_move_ttm(struct drm_buffer_object * bo,
DRM_FLAG_MASKED(save_flags, new_mem->flags, DRM_BO_MASK_MEMTYPE); DRM_FLAG_MASKED(save_flags, new_mem->flags, DRM_BO_MASK_MEMTYPE);
return 0; return 0;
} }
EXPORT_SYMBOL(drm_bo_move_ttm); EXPORT_SYMBOL(drm_bo_move_ttm);
/** /**
@ -100,7 +99,7 @@ EXPORT_SYMBOL(drm_bo_move_ttm);
* Call bo->mutex locked. * Call bo->mutex locked.
*/ */
int drm_mem_reg_ioremap(struct drm_device * dev, struct drm_bo_mem_reg * mem, int drm_mem_reg_ioremap(struct drm_device *dev, struct drm_bo_mem_reg *mem,
void **virtual) void **virtual)
{ {
struct drm_buffer_manager *bm = &dev->bm; struct drm_buffer_manager *bm = &dev->bm;
@ -136,7 +135,7 @@ EXPORT_SYMBOL(drm_mem_reg_ioremap);
* Call bo->mutex locked. * Call bo->mutex locked.
*/ */
void drm_mem_reg_iounmap(struct drm_device * dev, struct drm_bo_mem_reg * mem, void drm_mem_reg_iounmap(struct drm_device *dev, struct drm_bo_mem_reg *mem,
void *virtual) void *virtual)
{ {
struct drm_buffer_manager *bm; struct drm_buffer_manager *bm;
@ -145,9 +144,8 @@ void drm_mem_reg_iounmap(struct drm_device * dev, struct drm_bo_mem_reg * mem,
bm = &dev->bm; bm = &dev->bm;
man = &bm->man[mem->mem_type]; man = &bm->man[mem->mem_type];
if (virtual && (man->flags & _DRM_FLAG_NEEDS_IOREMAP)) { if (virtual && (man->flags & _DRM_FLAG_NEEDS_IOREMAP))
iounmap(virtual); iounmap(virtual);
}
} }
static int drm_copy_io_page(void *dst, void *src, unsigned long page) static int drm_copy_io_page(void *dst, void *src, unsigned long page)
@ -163,7 +161,8 @@ static int drm_copy_io_page(void *dst, void *src, unsigned long page)
return 0; return 0;
} }
static int drm_copy_io_ttm_page(struct drm_ttm * ttm, void *src, unsigned long page) 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); struct page *d = drm_ttm_get_page(ttm, page);
void *dst; void *dst;
@ -181,7 +180,7 @@ static int drm_copy_io_ttm_page(struct drm_ttm * ttm, void *src, unsigned long p
return 0; return 0;
} }
static int drm_copy_ttm_io_page(struct drm_ttm * ttm, void *dst, unsigned long page) 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); struct page *s = drm_ttm_get_page(ttm, page);
void *src; void *src;
@ -199,8 +198,8 @@ static int drm_copy_ttm_io_page(struct drm_ttm * ttm, void *dst, unsigned long p
return 0; return 0;
} }
int drm_bo_move_memcpy(struct drm_buffer_object * bo, int drm_bo_move_memcpy(struct drm_buffer_object *bo,
int evict, int no_wait, struct drm_bo_mem_reg * new_mem) int evict, int no_wait, struct drm_bo_mem_reg *new_mem)
{ {
struct drm_device *dev = bo->dev; struct drm_device *dev = bo->dev;
struct drm_mem_type_manager *man = &dev->bm.man[new_mem->mem_type]; struct drm_mem_type_manager *man = &dev->bm.man[new_mem->mem_type];
@ -251,7 +250,7 @@ int drm_bo_move_memcpy(struct drm_buffer_object * bo,
goto out1; goto out1;
} }
mb(); mb();
out2: out2:
drm_bo_free_old_node(bo); drm_bo_free_old_node(bo);
*old_mem = *new_mem; *old_mem = *new_mem;
@ -265,13 +264,12 @@ int drm_bo_move_memcpy(struct drm_buffer_object * bo,
bo->ttm = NULL; bo->ttm = NULL;
} }
out1: out1:
drm_mem_reg_iounmap(dev, new_mem, new_iomap); drm_mem_reg_iounmap(dev, new_mem, new_iomap);
out: out:
drm_mem_reg_iounmap(dev, &old_copy, old_iomap); drm_mem_reg_iounmap(dev, &old_copy, old_iomap);
return ret; return ret;
} }
EXPORT_SYMBOL(drm_bo_move_memcpy); EXPORT_SYMBOL(drm_bo_move_memcpy);
/* /*
@ -280,8 +278,8 @@ EXPORT_SYMBOL(drm_bo_move_memcpy);
* object. Call bo->mutex locked. * object. Call bo->mutex locked.
*/ */
int drm_buffer_object_transfer(struct drm_buffer_object * bo, int drm_buffer_object_transfer(struct drm_buffer_object *bo,
struct drm_buffer_object ** new_obj) struct drm_buffer_object **new_obj)
{ {
struct drm_buffer_object *fbo; struct drm_buffer_object *fbo;
struct drm_device *dev = bo->dev; struct drm_device *dev = bo->dev;
@ -322,12 +320,10 @@ int drm_buffer_object_transfer(struct drm_buffer_object * bo,
* We cannot restart until it has finished. * We cannot restart until it has finished.
*/ */
int drm_bo_move_accel_cleanup(struct drm_buffer_object * bo, int drm_bo_move_accel_cleanup(struct drm_buffer_object *bo,
int evict, int evict, int no_wait, uint32_t fence_class,
int no_wait, uint32_t fence_type, uint32_t fence_flags,
uint32_t fence_class, struct drm_bo_mem_reg *new_mem)
uint32_t fence_type,
uint32_t fence_flags, struct drm_bo_mem_reg * new_mem)
{ {
struct drm_device *dev = bo->dev; struct drm_device *dev = bo->dev;
struct drm_mem_type_manager *man = &dev->bm.man[new_mem->mem_type]; struct drm_mem_type_manager *man = &dev->bm.man[new_mem->mem_type];
@ -407,7 +403,6 @@ int drm_bo_move_accel_cleanup(struct drm_buffer_object * bo,
DRM_FLAG_MASKED(save_flags, new_mem->flags, DRM_BO_MASK_MEMTYPE); DRM_FLAG_MASKED(save_flags, new_mem->flags, DRM_BO_MASK_MEMTYPE);
return 0; return 0;
} }
EXPORT_SYMBOL(drm_bo_move_accel_cleanup); EXPORT_SYMBOL(drm_bo_move_accel_cleanup);
int drm_bo_same_page(unsigned long offset, int drm_bo_same_page(unsigned long offset,
@ -420,13 +415,11 @@ EXPORT_SYMBOL(drm_bo_same_page);
unsigned long drm_bo_offset_end(unsigned long offset, unsigned long drm_bo_offset_end(unsigned long offset,
unsigned long end) unsigned long end)
{ {
offset = (offset + PAGE_SIZE) & PAGE_MASK; offset = (offset + PAGE_SIZE) & PAGE_MASK;
return (end < offset) ? end : offset; return (end < offset) ? end : offset;
} }
EXPORT_SYMBOL(drm_bo_offset_end); EXPORT_SYMBOL(drm_bo_offset_end);
static pgprot_t drm_kernel_io_prot(uint32_t map_type) static pgprot_t drm_kernel_io_prot(uint32_t map_type)
{ {
pgprot_t tmp = PAGE_KERNEL; pgprot_t tmp = PAGE_KERNEL;
@ -475,8 +468,9 @@ static int drm_bo_ioremap(struct drm_buffer_object *bo, unsigned long bus_base,
return (!map->virtual) ? -ENOMEM : 0; return (!map->virtual) ? -ENOMEM : 0;
} }
static int drm_bo_kmap_ttm(struct drm_buffer_object *bo, unsigned long start_page, static int drm_bo_kmap_ttm(struct drm_buffer_object *bo,
unsigned long num_pages, struct drm_bo_kmap_obj *map) unsigned long start_page, unsigned long num_pages,
struct drm_bo_kmap_obj *map)
{ {
struct drm_device *dev = bo->dev; struct drm_device *dev = bo->dev;
struct drm_bo_mem_reg *mem = &bo->mem; struct drm_bo_mem_reg *mem = &bo->mem;
@ -503,7 +497,7 @@ static int drm_bo_kmap_ttm(struct drm_buffer_object *bo, unsigned long start_pag
* Populate the part we're mapping; * Populate the part we're mapping;
*/ */
for (i = start_page; i< start_page + num_pages; ++i) { for (i = start_page; i < start_page + num_pages; ++i) {
d = drm_ttm_get_page(ttm, i); d = drm_ttm_get_page(ttm, i);
if (!d) if (!d)
return -ENOMEM; return -ENOMEM;
@ -530,7 +524,8 @@ static int drm_bo_kmap_ttm(struct drm_buffer_object *bo, unsigned long start_pag
* and caching policy the buffer currently has. * and caching policy the buffer currently has.
* Mapping multiple pages or buffers that live in io memory is a bit slow and * Mapping multiple pages or buffers that live in io memory is a bit slow and
* consumes vmalloc space. Be restrictive with such mappings. * consumes vmalloc space. Be restrictive with such mappings.
* Mapping single pages usually returns the logical kernel address, (which is fast) * Mapping single pages usually returns the logical kernel address,
* (which is fast)
* BUG may use slower temporary mappings for high memory pages or * BUG may use slower temporary mappings for high memory pages or
* uncached / write-combined pages. * uncached / write-combined pages.
* *
@ -581,7 +576,7 @@ void drm_bo_kunmap(struct drm_bo_kmap_obj *map)
if (!map->virtual) if (!map->virtual)
return; return;
switch(map->bo_kmap_type) { switch (map->bo_kmap_type) {
case bo_map_iomap: case bo_map_iomap:
iounmap(map->virtual); iounmap(map->virtual);
break; break;

View File

@ -30,7 +30,7 @@
#include "drmP.h" #include "drmP.h"
int drm_add_user_object(struct drm_file * priv, struct drm_user_object * item, int drm_add_user_object(struct drm_file *priv, struct drm_user_object *item,
int shareable) int shareable)
{ {
struct drm_device *dev = priv->head->dev; struct drm_device *dev = priv->head->dev;
@ -56,7 +56,7 @@ int drm_add_user_object(struct drm_file * priv, struct drm_user_object * item,
} }
EXPORT_SYMBOL(drm_add_user_object); EXPORT_SYMBOL(drm_add_user_object);
struct drm_user_object *drm_lookup_user_object(struct drm_file * priv, uint32_t key) struct drm_user_object *drm_lookup_user_object(struct drm_file *priv, uint32_t key)
{ {
struct drm_device *dev = priv->head->dev; struct drm_device *dev = priv->head->dev;
struct drm_hash_item *hash; struct drm_hash_item *hash;
@ -66,9 +66,9 @@ struct drm_user_object *drm_lookup_user_object(struct drm_file * priv, uint32_t
DRM_ASSERT_LOCKED(&dev->struct_mutex); DRM_ASSERT_LOCKED(&dev->struct_mutex);
ret = drm_ht_find_item(&dev->object_hash, key, &hash); ret = drm_ht_find_item(&dev->object_hash, key, &hash);
if (ret) { if (ret)
return NULL; return NULL;
}
item = drm_hash_entry(hash, struct drm_user_object, hash); item = drm_hash_entry(hash, struct drm_user_object, hash);
if (priv != item->owner) { if (priv != item->owner) {
@ -83,7 +83,7 @@ struct drm_user_object *drm_lookup_user_object(struct drm_file * priv, uint32_t
} }
EXPORT_SYMBOL(drm_lookup_user_object); EXPORT_SYMBOL(drm_lookup_user_object);
static void drm_deref_user_object(struct drm_file * priv, struct drm_user_object * item) static void drm_deref_user_object(struct drm_file *priv, struct drm_user_object *item)
{ {
struct drm_device *dev = priv->head->dev; struct drm_device *dev = priv->head->dev;
int ret; int ret;
@ -95,7 +95,7 @@ static void drm_deref_user_object(struct drm_file * priv, struct drm_user_object
} }
} }
static int drm_object_ref_action(struct drm_file * priv, struct drm_user_object * ro, static int drm_object_ref_action(struct drm_file *priv, struct drm_user_object *ro,
enum drm_ref_type action) enum drm_ref_type action)
{ {
int ret = 0; int ret = 0;
@ -114,7 +114,7 @@ static int drm_object_ref_action(struct drm_file * priv, struct drm_user_object
return ret; return ret;
} }
int drm_add_ref_object(struct drm_file * priv, struct drm_user_object * referenced_object, int drm_add_ref_object(struct drm_file *priv, struct drm_user_object *referenced_object,
enum drm_ref_type ref_action) enum drm_ref_type ref_action)
{ {
int ret = 0; int ret = 0;
@ -167,12 +167,12 @@ int drm_add_ref_object(struct drm_file * priv, struct drm_user_object * referenc
list_add(&item->list, &priv->refd_objects); list_add(&item->list, &priv->refd_objects);
ret = drm_object_ref_action(priv, referenced_object, ref_action); ret = drm_object_ref_action(priv, referenced_object, ref_action);
out: out:
return ret; return ret;
} }
struct drm_ref_object *drm_lookup_ref_object(struct drm_file * priv, struct drm_ref_object *drm_lookup_ref_object(struct drm_file *priv,
struct drm_user_object * referenced_object, struct drm_user_object *referenced_object,
enum drm_ref_type ref_action) enum drm_ref_type ref_action)
{ {
struct drm_hash_item *hash; struct drm_hash_item *hash;
@ -188,8 +188,8 @@ struct drm_ref_object *drm_lookup_ref_object(struct drm_file * priv,
} }
EXPORT_SYMBOL(drm_lookup_ref_object); EXPORT_SYMBOL(drm_lookup_ref_object);
static void drm_remove_other_references(struct drm_file * priv, static void drm_remove_other_references(struct drm_file *priv,
struct drm_user_object * ro) struct drm_user_object *ro)
{ {
int i; int i;
struct drm_open_hash *ht; struct drm_open_hash *ht;
@ -205,7 +205,7 @@ static void drm_remove_other_references(struct drm_file * priv,
} }
} }
void drm_remove_ref_object(struct drm_file * priv, struct drm_ref_object * item) void drm_remove_ref_object(struct drm_file *priv, struct drm_ref_object *item)
{ {
int ret; int ret;
struct drm_user_object *user_object = (struct drm_user_object *) item->hash.key; struct drm_user_object *user_object = (struct drm_user_object *) item->hash.key;
@ -235,8 +235,8 @@ void drm_remove_ref_object(struct drm_file * priv, struct drm_ref_object * item)
} }
int drm_user_object_ref(struct drm_file * priv, uint32_t user_token, int drm_user_object_ref(struct drm_file *priv, uint32_t user_token,
enum drm_object_type type, struct drm_user_object ** object) enum drm_object_type type, struct drm_user_object **object)
{ {
struct drm_device *dev = priv->head->dev; struct drm_device *dev = priv->head->dev;
struct drm_user_object *uo; struct drm_user_object *uo;
@ -260,12 +260,12 @@ int drm_user_object_ref(struct drm_file * priv, uint32_t user_token,
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
*object = uo; *object = uo;
return 0; return 0;
out_err: out_err:
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
return ret; return ret;
} }
int drm_user_object_unref(struct drm_file * priv, uint32_t user_token, int drm_user_object_unref(struct drm_file *priv, uint32_t user_token,
enum drm_object_type type) enum drm_object_type type)
{ {
struct drm_device *dev = priv->head->dev; struct drm_device *dev = priv->head->dev;
@ -287,7 +287,7 @@ int drm_user_object_unref(struct drm_file * priv, uint32_t user_token,
drm_remove_ref_object(priv, ro); drm_remove_ref_object(priv, ro);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
return 0; return 0;
out_err: out_err:
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
return ret; return ret;
} }

View File

@ -46,7 +46,7 @@ EXPORT_SYMBOL(drm_ttm_cache_flush);
* Use kmalloc if possible. Otherwise fall back to vmalloc. * Use kmalloc if possible. Otherwise fall back to vmalloc.
*/ */
static void ttm_alloc_pages(struct drm_ttm * ttm) static void ttm_alloc_pages(struct drm_ttm *ttm)
{ {
unsigned long size = ttm->num_pages * sizeof(*ttm->pages); unsigned long size = ttm->num_pages * sizeof(*ttm->pages);
ttm->pages = NULL; ttm->pages = NULL;
@ -54,20 +54,19 @@ static void ttm_alloc_pages(struct drm_ttm * ttm)
if (drm_alloc_memctl(size)) if (drm_alloc_memctl(size))
return; return;
if (size <= PAGE_SIZE) { if (size <= PAGE_SIZE)
ttm->pages = drm_calloc(1, size, DRM_MEM_TTM); ttm->pages = drm_calloc(1, size, DRM_MEM_TTM);
}
if (!ttm->pages) { if (!ttm->pages) {
ttm->pages = vmalloc_user(size); ttm->pages = vmalloc_user(size);
if (ttm->pages) if (ttm->pages)
ttm->page_flags |= DRM_TTM_PAGE_VMALLOC; ttm->page_flags |= DRM_TTM_PAGE_VMALLOC;
} }
if (!ttm->pages) { if (!ttm->pages)
drm_free_memctl(size); drm_free_memctl(size);
}
} }
static void ttm_free_pages(struct drm_ttm * ttm) static void ttm_free_pages(struct drm_ttm *ttm)
{ {
unsigned long size = ttm->num_pages * sizeof(*ttm->pages); unsigned long size = ttm->num_pages * sizeof(*ttm->pages);
@ -85,9 +84,9 @@ static struct page *drm_ttm_alloc_page(void)
{ {
struct page *page; struct page *page;
if (drm_alloc_memctl(PAGE_SIZE)) { if (drm_alloc_memctl(PAGE_SIZE))
return NULL; return NULL;
}
page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32); page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
if (!page) { if (!page) {
drm_free_memctl(PAGE_SIZE); drm_free_memctl(PAGE_SIZE);
@ -106,7 +105,7 @@ static struct page *drm_ttm_alloc_page(void)
* for range of pages in a ttm. * for range of pages in a ttm.
*/ */
static int drm_set_caching(struct drm_ttm * ttm, int noncached) static int drm_set_caching(struct drm_ttm *ttm, int noncached)
{ {
int i; int i;
struct page **cur_page; struct page **cur_page;
@ -153,7 +152,7 @@ static void drm_ttm_free_user_pages(struct drm_ttm *ttm)
dirty = ((ttm->page_flags & DRM_TTM_PAGE_USER_DIRTY) != 0); dirty = ((ttm->page_flags & DRM_TTM_PAGE_USER_DIRTY) != 0);
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
for (i=0; i<ttm->num_pages; ++i) { for (i = 0; i < ttm->num_pages; ++i) {
page = ttm->pages[i]; page = ttm->pages[i];
if (page == NULL) if (page == NULL)
continue; continue;
@ -186,14 +185,10 @@ static void drm_ttm_free_alloced_pages(struct drm_ttm *ttm)
#else #else
ClearPageReserved(*cur_page); ClearPageReserved(*cur_page);
#endif #endif
if (page_count(*cur_page) != 1) { if (page_count(*cur_page) != 1)
DRM_ERROR("Erroneous page count. " DRM_ERROR("Erroneous page count. Leaking pages.\n");
"Leaking pages.\n"); if (page_mapped(*cur_page))
} DRM_ERROR("Erroneous map count. Leaking page mappings.\n");
if (page_mapped(*cur_page)) {
DRM_ERROR("Erroneous map count. "
"Leaking page mappings.\n");
}
__free_page(*cur_page); __free_page(*cur_page);
drm_free_memctl(PAGE_SIZE); drm_free_memctl(PAGE_SIZE);
--bm->cur_pages; --bm->cur_pages;
@ -205,7 +200,7 @@ static void drm_ttm_free_alloced_pages(struct drm_ttm *ttm)
* Free all resources associated with a ttm. * Free all resources associated with a ttm.
*/ */
int drm_destroy_ttm(struct drm_ttm * ttm) int drm_destroy_ttm(struct drm_ttm *ttm)
{ {
struct drm_ttm_backend *be; struct drm_ttm_backend *be;
@ -234,7 +229,7 @@ int drm_destroy_ttm(struct drm_ttm * ttm)
return 0; return 0;
} }
struct page *drm_ttm_get_page(struct drm_ttm * ttm, int index) struct page *drm_ttm_get_page(struct drm_ttm *ttm, int index)
{ {
struct page *p; struct page *p;
struct drm_buffer_manager *bm = &ttm->dev->bm; struct drm_buffer_manager *bm = &ttm->dev->bm;
@ -283,18 +278,17 @@ int drm_ttm_set_user(struct drm_ttm *ttm,
return -ENOMEM; return -ENOMEM;
} }
for (i=0; i<num_pages; ++i) { for (i = 0; i < num_pages; ++i) {
if (ttm->pages[i] == NULL) { if (ttm->pages[i] == NULL)
ttm->pages[i] = ttm->dummy_read_page; ttm->pages[i] = ttm->dummy_read_page;
} }
}
return 0; return 0;
} }
int drm_ttm_populate(struct drm_ttm * ttm) int drm_ttm_populate(struct drm_ttm *ttm)
{ {
struct page *page; struct page *page;
unsigned long i; unsigned long i;
@ -318,7 +312,7 @@ int drm_ttm_populate(struct drm_ttm * ttm)
* Initialize a ttm. * Initialize a ttm.
*/ */
struct drm_ttm *drm_ttm_init(struct drm_device * dev, unsigned long size) struct drm_ttm *drm_ttm_init(struct drm_device *dev, unsigned long size)
{ {
struct drm_bo_driver *bo_driver = dev->driver->bo_driver; struct drm_bo_driver *bo_driver = dev->driver->bo_driver;
struct drm_ttm *ttm; struct drm_ttm *ttm;
@ -362,7 +356,7 @@ struct drm_ttm *drm_ttm_init(struct drm_device * dev, unsigned long size)
* Unbind a ttm region from the aperture. * Unbind a ttm region from the aperture.
*/ */
void drm_ttm_evict(struct drm_ttm * ttm) void drm_ttm_evict(struct drm_ttm *ttm)
{ {
struct drm_ttm_backend *be = ttm->be; struct drm_ttm_backend *be = ttm->be;
int ret; int ret;
@ -375,19 +369,18 @@ void drm_ttm_evict(struct drm_ttm * ttm)
ttm->state = ttm_evicted; ttm->state = ttm_evicted;
} }
void drm_ttm_fixup_caching(struct drm_ttm * ttm) void drm_ttm_fixup_caching(struct drm_ttm *ttm)
{ {
if (ttm->state == ttm_evicted) { if (ttm->state == ttm_evicted) {
struct drm_ttm_backend *be = ttm->be; struct drm_ttm_backend *be = ttm->be;
if (be->func->needs_ub_cache_adjust(be)) { if (be->func->needs_ub_cache_adjust(be))
drm_set_caching(ttm, 0); drm_set_caching(ttm, 0);
}
ttm->state = ttm_unbound; ttm->state = ttm_unbound;
} }
} }
void drm_ttm_unbind(struct drm_ttm * ttm) void drm_ttm_unbind(struct drm_ttm *ttm)
{ {
if (ttm->state == ttm_bound) if (ttm->state == ttm_bound)
drm_ttm_evict(ttm); drm_ttm_evict(ttm);
@ -395,7 +388,7 @@ void drm_ttm_unbind(struct drm_ttm * ttm)
drm_ttm_fixup_caching(ttm); drm_ttm_fixup_caching(ttm);
} }
int drm_bind_ttm(struct drm_ttm * ttm, struct drm_bo_mem_reg *bo_mem) int drm_bind_ttm(struct drm_ttm *ttm, struct drm_bo_mem_reg *bo_mem)
{ {
struct drm_bo_driver *bo_driver = ttm->dev->driver->bo_driver; struct drm_bo_driver *bo_driver = ttm->dev->driver->bo_driver;
int ret = 0; int ret = 0;
@ -412,13 +405,14 @@ int drm_bind_ttm(struct drm_ttm * ttm, struct drm_bo_mem_reg *bo_mem)
if (ret) if (ret)
return ret; return ret;
if (ttm->state == ttm_unbound && !(bo_mem->flags & DRM_BO_FLAG_CACHED)) { if (ttm->state == ttm_unbound && !(bo_mem->flags & DRM_BO_FLAG_CACHED))
drm_set_caching(ttm, DRM_TTM_PAGE_UNCACHED); drm_set_caching(ttm, DRM_TTM_PAGE_UNCACHED);
} else if ((bo_mem->flags & DRM_BO_FLAG_CACHED_MAPPED) && else if ((bo_mem->flags & DRM_BO_FLAG_CACHED_MAPPED) &&
bo_driver->ttm_cache_flush) bo_driver->ttm_cache_flush)
bo_driver->ttm_cache_flush(ttm); bo_driver->ttm_cache_flush(ttm);
if ((ret = be->func->bind(be, bo_mem))) { ret = be->func->bind(be, bo_mem);
if (ret) {
ttm->state = ttm_evicted; ttm->state = ttm_evicted;
DRM_ERROR("Couldn't bind backend.\n"); DRM_ERROR("Couldn't bind backend.\n");
return ret; return ret;
@ -429,5 +423,4 @@ int drm_bind_ttm(struct drm_ttm * ttm, struct drm_bo_mem_reg *bo_mem)
ttm->page_flags |= DRM_TTM_PAGE_USER_DIRTY; ttm->page_flags |= DRM_TTM_PAGE_USER_DIRTY;
return 0; return 0;
} }
EXPORT_SYMBOL(drm_bind_ttm); EXPORT_SYMBOL(drm_bind_ttm);