ttm: Fix caching mode selection.
authorThomas Hellstrom <thellstrom@vmware.com>
Wed, 24 Jun 2009 17:57:34 +0000 (19:57 +0200)
committerDave Airlie <airlied@redhat.com>
Wed, 15 Jul 2009 07:13:10 +0000 (17:13 +1000)
A bug caused a new caching state to be selected on each buffer object
validation regardless of the current caching state.
Moreover, a caching state could be selected that wasn't supported by
the memory type.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/ttm/ttm_bo.c

index c1c407f7cca3e982bfd51630c2a0e368869bc201..a753598a5e35004c3759160a244fd75fc1e49ecf 100644 (file)
@@ -655,31 +655,52 @@ retry_pre_get:
        return 0;
 }
 
+static uint32_t ttm_bo_select_caching(struct ttm_mem_type_manager *man,
+                                     uint32_t cur_placement,
+                                     uint32_t proposed_placement)
+{
+       uint32_t caching = proposed_placement & TTM_PL_MASK_CACHING;
+       uint32_t result = proposed_placement & ~TTM_PL_MASK_CACHING;
+
+       /**
+        * Keep current caching if possible.
+        */
+
+       if ((cur_placement & caching) != 0)
+               result |= (cur_placement & caching);
+       else if ((man->default_caching & caching) != 0)
+               result |= man->default_caching;
+       else if ((TTM_PL_FLAG_CACHED & caching) != 0)
+               result |= TTM_PL_FLAG_CACHED;
+       else if ((TTM_PL_FLAG_WC & caching) != 0)
+               result |= TTM_PL_FLAG_WC;
+       else if ((TTM_PL_FLAG_UNCACHED & caching) != 0)
+               result |= TTM_PL_FLAG_UNCACHED;
+
+       return result;
+}
+
+
 static bool ttm_bo_mt_compatible(struct ttm_mem_type_manager *man,
                                 bool disallow_fixed,
                                 uint32_t mem_type,
-                                uint32_t mask, uint32_t *res_mask)
+                                uint32_t proposed_placement,
+                                uint32_t *masked_placement)
 {
        uint32_t cur_flags = ttm_bo_type_flags(mem_type);
 
        if ((man->flags & TTM_MEMTYPE_FLAG_FIXED) && disallow_fixed)
                return false;
 
-       if ((cur_flags & mask & TTM_PL_MASK_MEM) == 0)
+       if ((cur_flags & proposed_placement & TTM_PL_MASK_MEM) == 0)
                return false;
 
-       if ((mask & man->available_caching) == 0)
+       if ((proposed_placement & man->available_caching) == 0)
                return false;
-       if (mask & man->default_caching)
-               cur_flags |= man->default_caching;
-       else if (mask & TTM_PL_FLAG_CACHED)
-               cur_flags |= TTM_PL_FLAG_CACHED;
-       else if (mask & TTM_PL_FLAG_WC)
-               cur_flags |= TTM_PL_FLAG_WC;
-       else
-               cur_flags |= TTM_PL_FLAG_UNCACHED;
 
-       *res_mask = cur_flags;
+       cur_flags |= (proposed_placement & man->available_caching);
+
+       *masked_placement = cur_flags;
        return true;
 }
 
@@ -723,6 +744,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
                if (!type_ok)
                        continue;
 
+               cur_flags = ttm_bo_select_caching(man, bo->mem.placement,
+                                                 cur_flags);
+
                if (mem_type == TTM_PL_SYSTEM)
                        break;
 
@@ -779,6 +803,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
                                          proposed_placement, &cur_flags))
                        continue;
 
+               cur_flags = ttm_bo_select_caching(man, bo->mem.placement,
+                                                 cur_flags);
+
                ret = ttm_bo_mem_force_space(bdev, mem, mem_type,
                                             interruptible, no_wait);