Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | /* |
| 28 | * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> |
| 29 | */ |
| 30 | |
| 31 | #include "ttm/ttm_module.h" |
| 32 | #include "ttm/ttm_bo_driver.h" |
| 33 | #include "ttm/ttm_placement.h" |
| 34 | #include <linux/jiffies.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/sched.h> |
| 37 | #include <linux/mm.h> |
| 38 | #include <linux/file.h> |
| 39 | #include <linux/module.h> |
Thomas Hellstrom | 06fba6d | 2010-10-29 10:46:48 +0200 | [diff] [blame] | 40 | #include <asm/atomic.h> |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 41 | |
| 42 | #define TTM_ASSERT_LOCKED(param) |
| 43 | #define TTM_DEBUG(fmt, arg...) |
| 44 | #define TTM_BO_HASH_ORDER 13 |
| 45 | |
| 46 | static int ttm_bo_setup_vm(struct ttm_buffer_object *bo); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 47 | static int ttm_bo_swapout(struct ttm_mem_shrink *shrink); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 48 | static void ttm_bo_global_kobj_release(struct kobject *kobj); |
| 49 | |
| 50 | static struct attribute ttm_bo_count = { |
| 51 | .name = "bo_count", |
| 52 | .mode = S_IRUGO |
| 53 | }; |
| 54 | |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 55 | static inline int ttm_mem_type_from_flags(uint32_t flags, uint32_t *mem_type) |
| 56 | { |
| 57 | int i; |
| 58 | |
| 59 | for (i = 0; i <= TTM_PL_PRIV5; i++) |
| 60 | if (flags & (1 << i)) { |
| 61 | *mem_type = i; |
| 62 | return 0; |
| 63 | } |
| 64 | return -EINVAL; |
| 65 | } |
| 66 | |
Jerome Glisse | 5012f50 | 2009-12-10 18:07:26 +0100 | [diff] [blame] | 67 | static void ttm_mem_type_debug(struct ttm_bo_device *bdev, int mem_type) |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 68 | { |
Jerome Glisse | 5012f50 | 2009-12-10 18:07:26 +0100 | [diff] [blame] | 69 | struct ttm_mem_type_manager *man = &bdev->man[mem_type]; |
| 70 | |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 71 | printk(KERN_ERR TTM_PFX " has_type: %d\n", man->has_type); |
| 72 | printk(KERN_ERR TTM_PFX " use_type: %d\n", man->use_type); |
| 73 | printk(KERN_ERR TTM_PFX " flags: 0x%08X\n", man->flags); |
| 74 | printk(KERN_ERR TTM_PFX " gpu_offset: 0x%08lX\n", man->gpu_offset); |
Jerome Glisse | eb6d2c3 | 2009-12-10 16:15:52 +0100 | [diff] [blame] | 75 | printk(KERN_ERR TTM_PFX " size: %llu\n", man->size); |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 76 | printk(KERN_ERR TTM_PFX " available_caching: 0x%08X\n", |
| 77 | man->available_caching); |
| 78 | printk(KERN_ERR TTM_PFX " default_caching: 0x%08X\n", |
| 79 | man->default_caching); |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 80 | if (mem_type != TTM_PL_SYSTEM) |
| 81 | (*man->func->debug)(man, TTM_PFX); |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static void ttm_bo_mem_space_debug(struct ttm_buffer_object *bo, |
| 85 | struct ttm_placement *placement) |
| 86 | { |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 87 | int i, ret, mem_type; |
| 88 | |
Jerome Glisse | eb6d2c3 | 2009-12-10 16:15:52 +0100 | [diff] [blame] | 89 | printk(KERN_ERR TTM_PFX "No space for %p (%lu pages, %luK, %luM)\n", |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 90 | bo, bo->mem.num_pages, bo->mem.size >> 10, |
| 91 | bo->mem.size >> 20); |
| 92 | for (i = 0; i < placement->num_placement; i++) { |
| 93 | ret = ttm_mem_type_from_flags(placement->placement[i], |
| 94 | &mem_type); |
| 95 | if (ret) |
| 96 | return; |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 97 | printk(KERN_ERR TTM_PFX " placement[%d]=0x%08X (%d)\n", |
| 98 | i, placement->placement[i], mem_type); |
Jerome Glisse | 5012f50 | 2009-12-10 18:07:26 +0100 | [diff] [blame] | 99 | ttm_mem_type_debug(bo->bdev, mem_type); |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 103 | static ssize_t ttm_bo_global_show(struct kobject *kobj, |
| 104 | struct attribute *attr, |
| 105 | char *buffer) |
| 106 | { |
| 107 | struct ttm_bo_global *glob = |
| 108 | container_of(kobj, struct ttm_bo_global, kobj); |
| 109 | |
| 110 | return snprintf(buffer, PAGE_SIZE, "%lu\n", |
| 111 | (unsigned long) atomic_read(&glob->bo_count)); |
| 112 | } |
| 113 | |
| 114 | static struct attribute *ttm_bo_global_attrs[] = { |
| 115 | &ttm_bo_count, |
| 116 | NULL |
| 117 | }; |
| 118 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 119 | static const struct sysfs_ops ttm_bo_global_ops = { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 120 | .show = &ttm_bo_global_show |
| 121 | }; |
| 122 | |
| 123 | static struct kobj_type ttm_bo_glob_kobj_type = { |
| 124 | .release = &ttm_bo_global_kobj_release, |
| 125 | .sysfs_ops = &ttm_bo_global_ops, |
| 126 | .default_attrs = ttm_bo_global_attrs |
| 127 | }; |
| 128 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 129 | |
| 130 | static inline uint32_t ttm_bo_type_flags(unsigned type) |
| 131 | { |
| 132 | return 1 << (type); |
| 133 | } |
| 134 | |
| 135 | static void ttm_bo_release_list(struct kref *list_kref) |
| 136 | { |
| 137 | struct ttm_buffer_object *bo = |
| 138 | container_of(list_kref, struct ttm_buffer_object, list_kref); |
| 139 | struct ttm_bo_device *bdev = bo->bdev; |
| 140 | |
| 141 | BUG_ON(atomic_read(&bo->list_kref.refcount)); |
| 142 | BUG_ON(atomic_read(&bo->kref.refcount)); |
| 143 | BUG_ON(atomic_read(&bo->cpu_writers)); |
| 144 | BUG_ON(bo->sync_obj != NULL); |
| 145 | BUG_ON(bo->mem.mm_node != NULL); |
| 146 | BUG_ON(!list_empty(&bo->lru)); |
| 147 | BUG_ON(!list_empty(&bo->ddestroy)); |
| 148 | |
| 149 | if (bo->ttm) |
| 150 | ttm_tt_destroy(bo->ttm); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 151 | atomic_dec(&bo->glob->bo_count); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 152 | if (bo->destroy) |
| 153 | bo->destroy(bo); |
| 154 | else { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 155 | ttm_mem_global_free(bdev->glob->mem_glob, bo->acc_size); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 156 | kfree(bo); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, bool interruptible) |
| 161 | { |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 162 | if (interruptible) { |
Jean Delvare | 965d380 | 2010-10-09 12:36:45 +0000 | [diff] [blame] | 163 | return wait_event_interruptible(bo->event_queue, |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 164 | atomic_read(&bo->reserved) == 0); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 165 | } else { |
| 166 | wait_event(bo->event_queue, atomic_read(&bo->reserved) == 0); |
Jean Delvare | 965d380 | 2010-10-09 12:36:45 +0000 | [diff] [blame] | 167 | return 0; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 168 | } |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 169 | } |
Ben Skeggs | d1ede14 | 2009-12-11 15:13:00 +1000 | [diff] [blame] | 170 | EXPORT_SYMBOL(ttm_bo_wait_unreserved); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 171 | |
Dave Airlie | d6ea888 | 2010-11-22 13:24:40 +1000 | [diff] [blame] | 172 | void ttm_bo_add_to_lru(struct ttm_buffer_object *bo) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 173 | { |
| 174 | struct ttm_bo_device *bdev = bo->bdev; |
| 175 | struct ttm_mem_type_manager *man; |
| 176 | |
| 177 | BUG_ON(!atomic_read(&bo->reserved)); |
| 178 | |
| 179 | if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) { |
| 180 | |
| 181 | BUG_ON(!list_empty(&bo->lru)); |
| 182 | |
| 183 | man = &bdev->man[bo->mem.mem_type]; |
| 184 | list_add_tail(&bo->lru, &man->lru); |
| 185 | kref_get(&bo->list_kref); |
| 186 | |
| 187 | if (bo->ttm != NULL) { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 188 | list_add_tail(&bo->swap, &bo->glob->swap_lru); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 189 | kref_get(&bo->list_kref); |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
Dave Airlie | d6ea888 | 2010-11-22 13:24:40 +1000 | [diff] [blame] | 194 | int ttm_bo_del_from_lru(struct ttm_buffer_object *bo) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 195 | { |
| 196 | int put_count = 0; |
| 197 | |
| 198 | if (!list_empty(&bo->swap)) { |
| 199 | list_del_init(&bo->swap); |
| 200 | ++put_count; |
| 201 | } |
| 202 | if (!list_empty(&bo->lru)) { |
| 203 | list_del_init(&bo->lru); |
| 204 | ++put_count; |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * TODO: Add a driver hook to delete from |
| 209 | * driver-specific LRU's here. |
| 210 | */ |
| 211 | |
| 212 | return put_count; |
| 213 | } |
| 214 | |
| 215 | int ttm_bo_reserve_locked(struct ttm_buffer_object *bo, |
| 216 | bool interruptible, |
| 217 | bool no_wait, bool use_sequence, uint32_t sequence) |
| 218 | { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 219 | struct ttm_bo_global *glob = bo->glob; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 220 | int ret; |
| 221 | |
| 222 | while (unlikely(atomic_cmpxchg(&bo->reserved, 0, 1) != 0)) { |
Thomas Hellstrom | 95ccb0f | 2010-11-11 10:04:53 +0100 | [diff] [blame] | 223 | /** |
| 224 | * Deadlock avoidance for multi-bo reserving. |
| 225 | */ |
Thomas Hellstrom | 96726fe | 2010-11-17 12:28:28 +0000 | [diff] [blame] | 226 | if (use_sequence && bo->seq_valid) { |
| 227 | /** |
| 228 | * We've already reserved this one. |
| 229 | */ |
| 230 | if (unlikely(sequence == bo->val_seq)) |
| 231 | return -EDEADLK; |
| 232 | /** |
| 233 | * Already reserved by a thread that will not back |
| 234 | * off for us. We need to back off. |
| 235 | */ |
| 236 | if (unlikely(sequence - bo->val_seq < (1 << 31))) |
| 237 | return -EAGAIN; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | if (no_wait) |
| 241 | return -EBUSY; |
| 242 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 243 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 244 | ret = ttm_bo_wait_unreserved(bo, interruptible); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 245 | spin_lock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 246 | |
| 247 | if (unlikely(ret)) |
| 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | if (use_sequence) { |
Thomas Hellstrom | 95ccb0f | 2010-11-11 10:04:53 +0100 | [diff] [blame] | 252 | /** |
| 253 | * Wake up waiters that may need to recheck for deadlock, |
| 254 | * if we decreased the sequence number. |
| 255 | */ |
| 256 | if (unlikely((bo->val_seq - sequence < (1 << 31)) |
| 257 | || !bo->seq_valid)) |
| 258 | wake_up_all(&bo->event_queue); |
| 259 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 260 | bo->val_seq = sequence; |
| 261 | bo->seq_valid = true; |
| 262 | } else { |
| 263 | bo->seq_valid = false; |
| 264 | } |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | EXPORT_SYMBOL(ttm_bo_reserve); |
| 269 | |
| 270 | static void ttm_bo_ref_bug(struct kref *list_kref) |
| 271 | { |
| 272 | BUG(); |
| 273 | } |
| 274 | |
Dave Airlie | d6ea888 | 2010-11-22 13:24:40 +1000 | [diff] [blame] | 275 | void ttm_bo_list_ref_sub(struct ttm_buffer_object *bo, int count, |
| 276 | bool never_free) |
| 277 | { |
Thomas Hellstrom | 2357cbe | 2010-11-16 15:21:08 +0100 | [diff] [blame] | 278 | kref_sub(&bo->list_kref, count, |
| 279 | (never_free) ? ttm_bo_ref_bug : ttm_bo_release_list); |
Dave Airlie | d6ea888 | 2010-11-22 13:24:40 +1000 | [diff] [blame] | 280 | } |
| 281 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 282 | int ttm_bo_reserve(struct ttm_buffer_object *bo, |
| 283 | bool interruptible, |
| 284 | bool no_wait, bool use_sequence, uint32_t sequence) |
| 285 | { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 286 | struct ttm_bo_global *glob = bo->glob; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 287 | int put_count = 0; |
| 288 | int ret; |
| 289 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 290 | spin_lock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 291 | ret = ttm_bo_reserve_locked(bo, interruptible, no_wait, use_sequence, |
| 292 | sequence); |
| 293 | if (likely(ret == 0)) |
| 294 | put_count = ttm_bo_del_from_lru(bo); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 295 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 296 | |
Dave Airlie | d6ea888 | 2010-11-22 13:24:40 +1000 | [diff] [blame] | 297 | ttm_bo_list_ref_sub(bo, put_count, true); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 298 | |
| 299 | return ret; |
| 300 | } |
| 301 | |
| 302 | void ttm_bo_unreserve(struct ttm_buffer_object *bo) |
| 303 | { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 304 | struct ttm_bo_global *glob = bo->glob; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 305 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 306 | spin_lock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 307 | ttm_bo_add_to_lru(bo); |
| 308 | atomic_set(&bo->reserved, 0); |
| 309 | wake_up_all(&bo->event_queue); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 310 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 311 | } |
| 312 | EXPORT_SYMBOL(ttm_bo_unreserve); |
| 313 | |
| 314 | /* |
| 315 | * Call bo->mutex locked. |
| 316 | */ |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 317 | static int ttm_bo_add_ttm(struct ttm_buffer_object *bo, bool zero_alloc) |
| 318 | { |
| 319 | struct ttm_bo_device *bdev = bo->bdev; |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 320 | struct ttm_bo_global *glob = bo->glob; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 321 | int ret = 0; |
| 322 | uint32_t page_flags = 0; |
| 323 | |
| 324 | TTM_ASSERT_LOCKED(&bo->mutex); |
| 325 | bo->ttm = NULL; |
| 326 | |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 327 | if (bdev->need_dma32) |
| 328 | page_flags |= TTM_PAGE_FLAG_DMA32; |
| 329 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 330 | switch (bo->type) { |
| 331 | case ttm_bo_type_device: |
| 332 | if (zero_alloc) |
| 333 | page_flags |= TTM_PAGE_FLAG_ZERO_ALLOC; |
| 334 | case ttm_bo_type_kernel: |
| 335 | bo->ttm = ttm_tt_create(bdev, bo->num_pages << PAGE_SHIFT, |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 336 | page_flags, glob->dummy_read_page); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 337 | if (unlikely(bo->ttm == NULL)) |
| 338 | ret = -ENOMEM; |
| 339 | break; |
| 340 | case ttm_bo_type_user: |
| 341 | bo->ttm = ttm_tt_create(bdev, bo->num_pages << PAGE_SHIFT, |
| 342 | page_flags | TTM_PAGE_FLAG_USER, |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 343 | glob->dummy_read_page); |
Dave Airlie | 447aeb9 | 2009-12-08 09:25:45 +1000 | [diff] [blame] | 344 | if (unlikely(bo->ttm == NULL)) { |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 345 | ret = -ENOMEM; |
Dave Airlie | 447aeb9 | 2009-12-08 09:25:45 +1000 | [diff] [blame] | 346 | break; |
| 347 | } |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 348 | |
| 349 | ret = ttm_tt_set_user(bo->ttm, current, |
| 350 | bo->buffer_start, bo->num_pages); |
| 351 | if (unlikely(ret != 0)) |
| 352 | ttm_tt_destroy(bo->ttm); |
| 353 | break; |
| 354 | default: |
| 355 | printk(KERN_ERR TTM_PFX "Illegal buffer object type\n"); |
| 356 | ret = -EINVAL; |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | return ret; |
| 361 | } |
| 362 | |
| 363 | static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, |
| 364 | struct ttm_mem_reg *mem, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 365 | bool evict, bool interruptible, |
| 366 | bool no_wait_reserve, bool no_wait_gpu) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 367 | { |
| 368 | struct ttm_bo_device *bdev = bo->bdev; |
| 369 | bool old_is_pci = ttm_mem_reg_is_pci(bdev, &bo->mem); |
| 370 | bool new_is_pci = ttm_mem_reg_is_pci(bdev, mem); |
| 371 | struct ttm_mem_type_manager *old_man = &bdev->man[bo->mem.mem_type]; |
| 372 | struct ttm_mem_type_manager *new_man = &bdev->man[mem->mem_type]; |
| 373 | int ret = 0; |
| 374 | |
| 375 | if (old_is_pci || new_is_pci || |
| 376 | ((mem->placement & bo->mem.placement & TTM_PL_MASK_CACHING) == 0)) |
| 377 | ttm_bo_unmap_virtual(bo); |
| 378 | |
| 379 | /* |
| 380 | * Create and bind a ttm if required. |
| 381 | */ |
| 382 | |
| 383 | if (!(new_man->flags & TTM_MEMTYPE_FLAG_FIXED) && (bo->ttm == NULL)) { |
| 384 | ret = ttm_bo_add_ttm(bo, false); |
| 385 | if (ret) |
| 386 | goto out_err; |
| 387 | |
| 388 | ret = ttm_tt_set_placement_caching(bo->ttm, mem->placement); |
| 389 | if (ret) |
Thomas Hellstrom | 87ef920 | 2009-06-17 12:29:57 +0200 | [diff] [blame] | 390 | goto out_err; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 391 | |
| 392 | if (mem->mem_type != TTM_PL_SYSTEM) { |
| 393 | ret = ttm_tt_bind(bo->ttm, mem); |
| 394 | if (ret) |
| 395 | goto out_err; |
| 396 | } |
| 397 | |
| 398 | if (bo->mem.mem_type == TTM_PL_SYSTEM) { |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 399 | bo->mem = *mem; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 400 | mem->mm_node = NULL; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 401 | goto moved; |
| 402 | } |
| 403 | |
| 404 | } |
| 405 | |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 406 | if (bdev->driver->move_notify) |
| 407 | bdev->driver->move_notify(bo, mem); |
| 408 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 409 | if (!(old_man->flags & TTM_MEMTYPE_FLAG_FIXED) && |
| 410 | !(new_man->flags & TTM_MEMTYPE_FLAG_FIXED)) |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 411 | ret = ttm_bo_move_ttm(bo, evict, no_wait_reserve, no_wait_gpu, mem); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 412 | else if (bdev->driver->move) |
| 413 | ret = bdev->driver->move(bo, evict, interruptible, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 414 | no_wait_reserve, no_wait_gpu, mem); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 415 | else |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 416 | ret = ttm_bo_move_memcpy(bo, evict, no_wait_reserve, no_wait_gpu, mem); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 417 | |
| 418 | if (ret) |
| 419 | goto out_err; |
| 420 | |
| 421 | moved: |
| 422 | if (bo->evicted) { |
| 423 | ret = bdev->driver->invalidate_caches(bdev, bo->mem.placement); |
| 424 | if (ret) |
| 425 | printk(KERN_ERR TTM_PFX "Can not flush read caches\n"); |
| 426 | bo->evicted = false; |
| 427 | } |
| 428 | |
| 429 | if (bo->mem.mm_node) { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 430 | bo->offset = (bo->mem.start << PAGE_SHIFT) + |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 431 | bdev->man[bo->mem.mem_type].gpu_offset; |
| 432 | bo->cur_placement = bo->mem.placement; |
Thomas Hellstrom | 354fb52 | 2010-01-13 22:28:45 +0100 | [diff] [blame] | 433 | } else |
| 434 | bo->offset = 0; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 435 | |
| 436 | return 0; |
| 437 | |
| 438 | out_err: |
| 439 | new_man = &bdev->man[bo->mem.mem_type]; |
| 440 | if ((new_man->flags & TTM_MEMTYPE_FLAG_FIXED) && bo->ttm) { |
| 441 | ttm_tt_unbind(bo->ttm); |
| 442 | ttm_tt_destroy(bo->ttm); |
| 443 | bo->ttm = NULL; |
| 444 | } |
| 445 | |
| 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | /** |
Thomas Hellstrom | 40d857b | 2010-10-19 09:01:00 +0200 | [diff] [blame] | 450 | * Call bo::reserved. |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 451 | * Will release GPU memory type usage on destruction. |
Thomas Hellstrom | 40d857b | 2010-10-19 09:01:00 +0200 | [diff] [blame] | 452 | * This is the place to put in driver specific hooks to release |
| 453 | * driver private resources. |
| 454 | * Will release the bo::reserved lock. |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 455 | */ |
| 456 | |
| 457 | static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo) |
| 458 | { |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 459 | if (bo->ttm) { |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 460 | ttm_tt_unbind(bo->ttm); |
| 461 | ttm_tt_destroy(bo->ttm); |
| 462 | bo->ttm = NULL; |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Thomas Hellstrom | 40d857b | 2010-10-19 09:01:00 +0200 | [diff] [blame] | 465 | ttm_bo_mem_put(bo, &bo->mem); |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 466 | |
| 467 | atomic_set(&bo->reserved, 0); |
Thomas Hellstrom | 06fba6d | 2010-10-29 10:46:48 +0200 | [diff] [blame] | 468 | |
| 469 | /* |
| 470 | * Make processes trying to reserve really pick it up. |
| 471 | */ |
| 472 | smp_mb__after_atomic_dec(); |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 473 | wake_up_all(&bo->event_queue); |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 474 | } |
| 475 | |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 476 | static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 477 | { |
| 478 | struct ttm_bo_device *bdev = bo->bdev; |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 479 | struct ttm_bo_global *glob = bo->glob; |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 480 | struct ttm_bo_driver *driver; |
Thomas Hellstrom | aa12326 | 2010-11-02 13:21:47 +0000 | [diff] [blame] | 481 | void *sync_obj = NULL; |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 482 | void *sync_obj_arg; |
| 483 | int put_count; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 484 | int ret; |
| 485 | |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 486 | spin_lock(&bdev->fence_lock); |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 487 | (void) ttm_bo_wait(bo, false, false, true); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 488 | if (!bo->sync_obj) { |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 489 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 490 | spin_lock(&glob->lru_lock); |
Thomas Hellstrom | aaa2073 | 2009-12-02 18:33:45 +0100 | [diff] [blame] | 491 | |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 492 | /** |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 493 | * Lock inversion between bo:reserve and bdev::fence_lock here, |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 494 | * but that's OK, since we're only trylocking. |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 495 | */ |
| 496 | |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 497 | ret = ttm_bo_reserve_locked(bo, false, true, false, 0); |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 498 | |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 499 | if (unlikely(ret == -EBUSY)) |
| 500 | goto queue; |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 501 | |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 502 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 503 | put_count = ttm_bo_del_from_lru(bo); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 504 | |
Thomas Hellstrom | 40d857b | 2010-10-19 09:01:00 +0200 | [diff] [blame] | 505 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | 1df6a2e | 2010-09-30 12:36:45 +0200 | [diff] [blame] | 506 | ttm_bo_cleanup_memtype_use(bo); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 507 | |
Dave Airlie | d6ea888 | 2010-11-22 13:24:40 +1000 | [diff] [blame] | 508 | ttm_bo_list_ref_sub(bo, put_count, true); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 509 | |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 510 | return; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 511 | } else { |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 512 | spin_lock(&glob->lru_lock); |
| 513 | } |
| 514 | queue: |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 515 | driver = bdev->driver; |
Thomas Hellstrom | aa12326 | 2010-11-02 13:21:47 +0000 | [diff] [blame] | 516 | if (bo->sync_obj) |
| 517 | sync_obj = driver->sync_obj_ref(bo->sync_obj); |
| 518 | sync_obj_arg = bo->sync_obj_arg; |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 519 | |
| 520 | kref_get(&bo->list_kref); |
| 521 | list_add_tail(&bo->ddestroy, &bdev->ddestroy); |
| 522 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 523 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 524 | |
Thomas Hellstrom | aa12326 | 2010-11-02 13:21:47 +0000 | [diff] [blame] | 525 | if (sync_obj) { |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 526 | driver->sync_obj_flush(sync_obj, sync_obj_arg); |
Thomas Hellstrom | aa12326 | 2010-11-02 13:21:47 +0000 | [diff] [blame] | 527 | driver->sync_obj_unref(&sync_obj); |
| 528 | } |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 529 | schedule_delayed_work(&bdev->wq, |
| 530 | ((HZ / 100) < 1) ? 1 : HZ / 100); |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * function ttm_bo_cleanup_refs |
| 535 | * If bo idle, remove from delayed- and lru lists, and unref. |
| 536 | * If not idle, do nothing. |
| 537 | * |
| 538 | * @interruptible Any sleeps should occur interruptibly. |
| 539 | * @no_wait_reserve Never wait for reserve. Return -EBUSY instead. |
| 540 | * @no_wait_gpu Never wait for gpu. Return -EBUSY instead. |
| 541 | */ |
| 542 | |
| 543 | static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo, |
| 544 | bool interruptible, |
| 545 | bool no_wait_reserve, |
| 546 | bool no_wait_gpu) |
| 547 | { |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 548 | struct ttm_bo_device *bdev = bo->bdev; |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 549 | struct ttm_bo_global *glob = bo->glob; |
| 550 | int put_count; |
| 551 | int ret = 0; |
| 552 | |
| 553 | retry: |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 554 | spin_lock(&bdev->fence_lock); |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 555 | ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 556 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 557 | |
| 558 | if (unlikely(ret != 0)) |
| 559 | return ret; |
| 560 | |
| 561 | spin_lock(&glob->lru_lock); |
| 562 | ret = ttm_bo_reserve_locked(bo, interruptible, |
| 563 | no_wait_reserve, false, 0); |
| 564 | |
| 565 | if (unlikely(ret != 0) || list_empty(&bo->ddestroy)) { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 566 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 567 | return ret; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 568 | } |
| 569 | |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 570 | /** |
| 571 | * We can re-check for sync object without taking |
| 572 | * the bo::lock since setting the sync object requires |
| 573 | * also bo::reserved. A busy object at this point may |
| 574 | * be caused by another thread recently starting an accelerated |
| 575 | * eviction. |
| 576 | */ |
| 577 | |
| 578 | if (unlikely(bo->sync_obj)) { |
| 579 | atomic_set(&bo->reserved, 0); |
| 580 | wake_up_all(&bo->event_queue); |
| 581 | spin_unlock(&glob->lru_lock); |
| 582 | goto retry; |
| 583 | } |
| 584 | |
| 585 | put_count = ttm_bo_del_from_lru(bo); |
| 586 | list_del_init(&bo->ddestroy); |
| 587 | ++put_count; |
| 588 | |
| 589 | spin_unlock(&glob->lru_lock); |
| 590 | ttm_bo_cleanup_memtype_use(bo); |
| 591 | |
Dave Airlie | d6ea888 | 2010-11-22 13:24:40 +1000 | [diff] [blame] | 592 | ttm_bo_list_ref_sub(bo, put_count, true); |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 593 | |
| 594 | return 0; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /** |
| 598 | * Traverse the delayed list, and call ttm_bo_cleanup_refs on all |
| 599 | * encountered buffers. |
| 600 | */ |
| 601 | |
| 602 | static int ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all) |
| 603 | { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 604 | struct ttm_bo_global *glob = bdev->glob; |
Luca Barbieri | 1a961ce | 2010-01-20 20:01:30 +0100 | [diff] [blame] | 605 | struct ttm_buffer_object *entry = NULL; |
| 606 | int ret = 0; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 607 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 608 | spin_lock(&glob->lru_lock); |
Luca Barbieri | 1a961ce | 2010-01-20 20:01:30 +0100 | [diff] [blame] | 609 | if (list_empty(&bdev->ddestroy)) |
| 610 | goto out_unlock; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 611 | |
Luca Barbieri | 1a961ce | 2010-01-20 20:01:30 +0100 | [diff] [blame] | 612 | entry = list_first_entry(&bdev->ddestroy, |
| 613 | struct ttm_buffer_object, ddestroy); |
| 614 | kref_get(&entry->list_kref); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 615 | |
Luca Barbieri | 1a961ce | 2010-01-20 20:01:30 +0100 | [diff] [blame] | 616 | for (;;) { |
| 617 | struct ttm_buffer_object *nentry = NULL; |
| 618 | |
| 619 | if (entry->ddestroy.next != &bdev->ddestroy) { |
| 620 | nentry = list_first_entry(&entry->ddestroy, |
| 621 | struct ttm_buffer_object, ddestroy); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 622 | kref_get(&nentry->list_kref); |
| 623 | } |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 624 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 625 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 626 | ret = ttm_bo_cleanup_refs(entry, false, !remove_all, |
| 627 | !remove_all); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 628 | kref_put(&entry->list_kref, ttm_bo_release_list); |
Luca Barbieri | 1a961ce | 2010-01-20 20:01:30 +0100 | [diff] [blame] | 629 | entry = nentry; |
| 630 | |
| 631 | if (ret || !entry) |
| 632 | goto out; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 633 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 634 | spin_lock(&glob->lru_lock); |
Luca Barbieri | 1a961ce | 2010-01-20 20:01:30 +0100 | [diff] [blame] | 635 | if (list_empty(&entry->ddestroy)) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 636 | break; |
| 637 | } |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 638 | |
Luca Barbieri | 1a961ce | 2010-01-20 20:01:30 +0100 | [diff] [blame] | 639 | out_unlock: |
| 640 | spin_unlock(&glob->lru_lock); |
| 641 | out: |
| 642 | if (entry) |
| 643 | kref_put(&entry->list_kref, ttm_bo_release_list); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 644 | return ret; |
| 645 | } |
| 646 | |
| 647 | static void ttm_bo_delayed_workqueue(struct work_struct *work) |
| 648 | { |
| 649 | struct ttm_bo_device *bdev = |
| 650 | container_of(work, struct ttm_bo_device, wq.work); |
| 651 | |
| 652 | if (ttm_bo_delayed_delete(bdev, false)) { |
| 653 | schedule_delayed_work(&bdev->wq, |
| 654 | ((HZ / 100) < 1) ? 1 : HZ / 100); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | static void ttm_bo_release(struct kref *kref) |
| 659 | { |
| 660 | struct ttm_buffer_object *bo = |
| 661 | container_of(kref, struct ttm_buffer_object, kref); |
| 662 | struct ttm_bo_device *bdev = bo->bdev; |
| 663 | |
| 664 | if (likely(bo->vm_node != NULL)) { |
| 665 | rb_erase(&bo->vm_rb, &bdev->addr_space_rb); |
| 666 | drm_mm_put_block(bo->vm_node); |
| 667 | bo->vm_node = NULL; |
| 668 | } |
| 669 | write_unlock(&bdev->vm_lock); |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 670 | ttm_bo_cleanup_refs_or_queue(bo); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 671 | kref_put(&bo->list_kref, ttm_bo_release_list); |
| 672 | write_lock(&bdev->vm_lock); |
| 673 | } |
| 674 | |
| 675 | void ttm_bo_unref(struct ttm_buffer_object **p_bo) |
| 676 | { |
| 677 | struct ttm_buffer_object *bo = *p_bo; |
| 678 | struct ttm_bo_device *bdev = bo->bdev; |
| 679 | |
| 680 | *p_bo = NULL; |
| 681 | write_lock(&bdev->vm_lock); |
| 682 | kref_put(&bo->kref, ttm_bo_release); |
| 683 | write_unlock(&bdev->vm_lock); |
| 684 | } |
| 685 | EXPORT_SYMBOL(ttm_bo_unref); |
| 686 | |
Matthew Garrett | 7c5ee53 | 2010-04-26 16:00:09 -0400 | [diff] [blame] | 687 | int ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev) |
| 688 | { |
| 689 | return cancel_delayed_work_sync(&bdev->wq); |
| 690 | } |
| 691 | EXPORT_SYMBOL(ttm_bo_lock_delayed_workqueue); |
| 692 | |
| 693 | void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev, int resched) |
| 694 | { |
| 695 | if (resched) |
| 696 | schedule_delayed_work(&bdev->wq, |
| 697 | ((HZ / 100) < 1) ? 1 : HZ / 100); |
| 698 | } |
| 699 | EXPORT_SYMBOL(ttm_bo_unlock_delayed_workqueue); |
| 700 | |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 701 | static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 702 | bool no_wait_reserve, bool no_wait_gpu) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 703 | { |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 704 | struct ttm_bo_device *bdev = bo->bdev; |
| 705 | struct ttm_mem_reg evict_mem; |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 706 | struct ttm_placement placement; |
| 707 | int ret = 0; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 708 | |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 709 | spin_lock(&bdev->fence_lock); |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 710 | ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 711 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 712 | |
Thomas Hellstrom | 78ecf09 | 2009-06-17 12:29:55 +0200 | [diff] [blame] | 713 | if (unlikely(ret != 0)) { |
Thomas Hellstrom | 98ffc415 | 2009-12-07 18:36:18 +0100 | [diff] [blame] | 714 | if (ret != -ERESTARTSYS) { |
Thomas Hellstrom | 78ecf09 | 2009-06-17 12:29:55 +0200 | [diff] [blame] | 715 | printk(KERN_ERR TTM_PFX |
| 716 | "Failed to expire sync object before " |
| 717 | "buffer eviction.\n"); |
| 718 | } |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 719 | goto out; |
| 720 | } |
| 721 | |
| 722 | BUG_ON(!atomic_read(&bo->reserved)); |
| 723 | |
| 724 | evict_mem = bo->mem; |
| 725 | evict_mem.mm_node = NULL; |
Jerome Glisse | 82c5da6 | 2010-04-09 14:39:23 +0200 | [diff] [blame] | 726 | evict_mem.bus.io_reserved = false; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 727 | |
Jerome Glisse | 7cb7d1d | 2009-12-09 22:14:27 +0100 | [diff] [blame] | 728 | placement.fpfn = 0; |
| 729 | placement.lpfn = 0; |
| 730 | placement.num_placement = 0; |
| 731 | placement.num_busy_placement = 0; |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 732 | bdev->driver->evict_flags(bo, &placement); |
| 733 | ret = ttm_bo_mem_space(bo, &placement, &evict_mem, interruptible, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 734 | no_wait_reserve, no_wait_gpu); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 735 | if (ret) { |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 736 | if (ret != -ERESTARTSYS) { |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 737 | printk(KERN_ERR TTM_PFX |
| 738 | "Failed to find memory space for " |
| 739 | "buffer 0x%p eviction.\n", bo); |
Jerome Glisse | fb53f86 | 2009-12-09 21:55:10 +0100 | [diff] [blame] | 740 | ttm_bo_mem_space_debug(bo, &placement); |
| 741 | } |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 742 | goto out; |
| 743 | } |
| 744 | |
| 745 | ret = ttm_bo_handle_move_mem(bo, &evict_mem, true, interruptible, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 746 | no_wait_reserve, no_wait_gpu); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 747 | if (ret) { |
Thomas Hellstrom | 98ffc415 | 2009-12-07 18:36:18 +0100 | [diff] [blame] | 748 | if (ret != -ERESTARTSYS) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 749 | printk(KERN_ERR TTM_PFX "Buffer eviction failed\n"); |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 750 | ttm_bo_mem_put(bo, &evict_mem); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 751 | goto out; |
| 752 | } |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 753 | bo->evicted = true; |
| 754 | out: |
| 755 | return ret; |
| 756 | } |
| 757 | |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 758 | static int ttm_mem_evict_first(struct ttm_bo_device *bdev, |
| 759 | uint32_t mem_type, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 760 | bool interruptible, bool no_wait_reserve, |
| 761 | bool no_wait_gpu) |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 762 | { |
| 763 | struct ttm_bo_global *glob = bdev->glob; |
| 764 | struct ttm_mem_type_manager *man = &bdev->man[mem_type]; |
| 765 | struct ttm_buffer_object *bo; |
| 766 | int ret, put_count = 0; |
| 767 | |
Thomas Hellstrom | 9c51ba1 | 2009-12-02 18:33:46 +0100 | [diff] [blame] | 768 | retry: |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 769 | spin_lock(&glob->lru_lock); |
Thomas Hellstrom | 9c51ba1 | 2009-12-02 18:33:46 +0100 | [diff] [blame] | 770 | if (list_empty(&man->lru)) { |
| 771 | spin_unlock(&glob->lru_lock); |
| 772 | return -EBUSY; |
| 773 | } |
| 774 | |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 775 | bo = list_first_entry(&man->lru, struct ttm_buffer_object, lru); |
| 776 | kref_get(&bo->list_kref); |
Thomas Hellstrom | 9c51ba1 | 2009-12-02 18:33:46 +0100 | [diff] [blame] | 777 | |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 778 | if (!list_empty(&bo->ddestroy)) { |
| 779 | spin_unlock(&glob->lru_lock); |
| 780 | ret = ttm_bo_cleanup_refs(bo, interruptible, |
| 781 | no_wait_reserve, no_wait_gpu); |
| 782 | kref_put(&bo->list_kref, ttm_bo_release_list); |
| 783 | |
| 784 | if (likely(ret == 0 || ret == -ERESTARTSYS)) |
| 785 | return ret; |
| 786 | |
| 787 | goto retry; |
| 788 | } |
| 789 | |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 790 | ret = ttm_bo_reserve_locked(bo, false, no_wait_reserve, false, 0); |
Thomas Hellstrom | 9c51ba1 | 2009-12-02 18:33:46 +0100 | [diff] [blame] | 791 | |
| 792 | if (unlikely(ret == -EBUSY)) { |
| 793 | spin_unlock(&glob->lru_lock); |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 794 | if (likely(!no_wait_gpu)) |
Thomas Hellstrom | 9c51ba1 | 2009-12-02 18:33:46 +0100 | [diff] [blame] | 795 | ret = ttm_bo_wait_unreserved(bo, interruptible); |
| 796 | |
| 797 | kref_put(&bo->list_kref, ttm_bo_release_list); |
| 798 | |
| 799 | /** |
| 800 | * We *need* to retry after releasing the lru lock. |
| 801 | */ |
| 802 | |
| 803 | if (unlikely(ret != 0)) |
| 804 | return ret; |
| 805 | goto retry; |
| 806 | } |
| 807 | |
| 808 | put_count = ttm_bo_del_from_lru(bo); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 809 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | 9c51ba1 | 2009-12-02 18:33:46 +0100 | [diff] [blame] | 810 | |
| 811 | BUG_ON(ret != 0); |
| 812 | |
Dave Airlie | d6ea888 | 2010-11-22 13:24:40 +1000 | [diff] [blame] | 813 | ttm_bo_list_ref_sub(bo, put_count, true); |
Thomas Hellstrom | 9c51ba1 | 2009-12-02 18:33:46 +0100 | [diff] [blame] | 814 | |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 815 | ret = ttm_bo_evict(bo, interruptible, no_wait_reserve, no_wait_gpu); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 816 | ttm_bo_unreserve(bo); |
Thomas Hellstrom | 9c51ba1 | 2009-12-02 18:33:46 +0100 | [diff] [blame] | 817 | |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 818 | kref_put(&bo->list_kref, ttm_bo_release_list); |
| 819 | return ret; |
| 820 | } |
| 821 | |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 822 | void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem) |
| 823 | { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 824 | struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type]; |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 825 | |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 826 | if (mem->mm_node) |
| 827 | (*man->func->put_node)(man, mem); |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 828 | } |
| 829 | EXPORT_SYMBOL(ttm_bo_mem_put); |
| 830 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 831 | /** |
| 832 | * Repeatedly evict memory from the LRU for @mem_type until we create enough |
| 833 | * space, or we've evicted everything and there isn't enough space. |
| 834 | */ |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 835 | static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, |
| 836 | uint32_t mem_type, |
| 837 | struct ttm_placement *placement, |
| 838 | struct ttm_mem_reg *mem, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 839 | bool interruptible, |
| 840 | bool no_wait_reserve, |
| 841 | bool no_wait_gpu) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 842 | { |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 843 | struct ttm_bo_device *bdev = bo->bdev; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 844 | struct ttm_mem_type_manager *man = &bdev->man[mem_type]; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 845 | int ret; |
| 846 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 847 | do { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 848 | ret = (*man->func->get_node)(man, bo, placement, mem); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 849 | if (unlikely(ret != 0)) |
| 850 | return ret; |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 851 | if (mem->mm_node) |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 852 | break; |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 853 | ret = ttm_mem_evict_first(bdev, mem_type, interruptible, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 854 | no_wait_reserve, no_wait_gpu); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 855 | if (unlikely(ret != 0)) |
| 856 | return ret; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 857 | } while (1); |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 858 | if (mem->mm_node == NULL) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 859 | return -ENOMEM; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 860 | mem->mem_type = mem_type; |
| 861 | return 0; |
| 862 | } |
| 863 | |
Thomas Hellstrom | ae3e812 | 2009-06-24 19:57:34 +0200 | [diff] [blame] | 864 | static uint32_t ttm_bo_select_caching(struct ttm_mem_type_manager *man, |
| 865 | uint32_t cur_placement, |
| 866 | uint32_t proposed_placement) |
| 867 | { |
| 868 | uint32_t caching = proposed_placement & TTM_PL_MASK_CACHING; |
| 869 | uint32_t result = proposed_placement & ~TTM_PL_MASK_CACHING; |
| 870 | |
| 871 | /** |
| 872 | * Keep current caching if possible. |
| 873 | */ |
| 874 | |
| 875 | if ((cur_placement & caching) != 0) |
| 876 | result |= (cur_placement & caching); |
| 877 | else if ((man->default_caching & caching) != 0) |
| 878 | result |= man->default_caching; |
| 879 | else if ((TTM_PL_FLAG_CACHED & caching) != 0) |
| 880 | result |= TTM_PL_FLAG_CACHED; |
| 881 | else if ((TTM_PL_FLAG_WC & caching) != 0) |
| 882 | result |= TTM_PL_FLAG_WC; |
| 883 | else if ((TTM_PL_FLAG_UNCACHED & caching) != 0) |
| 884 | result |= TTM_PL_FLAG_UNCACHED; |
| 885 | |
| 886 | return result; |
| 887 | } |
| 888 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 889 | static bool ttm_bo_mt_compatible(struct ttm_mem_type_manager *man, |
| 890 | bool disallow_fixed, |
| 891 | uint32_t mem_type, |
Thomas Hellstrom | ae3e812 | 2009-06-24 19:57:34 +0200 | [diff] [blame] | 892 | uint32_t proposed_placement, |
| 893 | uint32_t *masked_placement) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 894 | { |
| 895 | uint32_t cur_flags = ttm_bo_type_flags(mem_type); |
| 896 | |
| 897 | if ((man->flags & TTM_MEMTYPE_FLAG_FIXED) && disallow_fixed) |
| 898 | return false; |
| 899 | |
Thomas Hellstrom | ae3e812 | 2009-06-24 19:57:34 +0200 | [diff] [blame] | 900 | if ((cur_flags & proposed_placement & TTM_PL_MASK_MEM) == 0) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 901 | return false; |
| 902 | |
Thomas Hellstrom | ae3e812 | 2009-06-24 19:57:34 +0200 | [diff] [blame] | 903 | if ((proposed_placement & man->available_caching) == 0) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 904 | return false; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 905 | |
Thomas Hellstrom | ae3e812 | 2009-06-24 19:57:34 +0200 | [diff] [blame] | 906 | cur_flags |= (proposed_placement & man->available_caching); |
| 907 | |
| 908 | *masked_placement = cur_flags; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 909 | return true; |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Creates space for memory region @mem according to its type. |
| 914 | * |
| 915 | * This function first searches for free space in compatible memory types in |
| 916 | * the priority order defined by the driver. If free space isn't found, then |
| 917 | * ttm_bo_mem_force_space is attempted in priority order to evict and find |
| 918 | * space. |
| 919 | */ |
| 920 | int ttm_bo_mem_space(struct ttm_buffer_object *bo, |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 921 | struct ttm_placement *placement, |
| 922 | struct ttm_mem_reg *mem, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 923 | bool interruptible, bool no_wait_reserve, |
| 924 | bool no_wait_gpu) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 925 | { |
| 926 | struct ttm_bo_device *bdev = bo->bdev; |
| 927 | struct ttm_mem_type_manager *man; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 928 | uint32_t mem_type = TTM_PL_SYSTEM; |
| 929 | uint32_t cur_flags = 0; |
| 930 | bool type_found = false; |
| 931 | bool type_ok = false; |
Thomas Hellstrom | 98ffc415 | 2009-12-07 18:36:18 +0100 | [diff] [blame] | 932 | bool has_erestartsys = false; |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 933 | int i, ret; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 934 | |
| 935 | mem->mm_node = NULL; |
Dave Airlie | b663752 | 2009-12-14 14:51:35 +1000 | [diff] [blame] | 936 | for (i = 0; i < placement->num_placement; ++i) { |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 937 | ret = ttm_mem_type_from_flags(placement->placement[i], |
| 938 | &mem_type); |
| 939 | if (ret) |
| 940 | return ret; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 941 | man = &bdev->man[mem_type]; |
| 942 | |
| 943 | type_ok = ttm_bo_mt_compatible(man, |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 944 | bo->type == ttm_bo_type_user, |
| 945 | mem_type, |
| 946 | placement->placement[i], |
| 947 | &cur_flags); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 948 | |
| 949 | if (!type_ok) |
| 950 | continue; |
| 951 | |
Thomas Hellstrom | ae3e812 | 2009-06-24 19:57:34 +0200 | [diff] [blame] | 952 | cur_flags = ttm_bo_select_caching(man, bo->mem.placement, |
| 953 | cur_flags); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 954 | /* |
| 955 | * Use the access and other non-mapping-related flag bits from |
| 956 | * the memory placement flags to the current flags |
| 957 | */ |
| 958 | ttm_flag_masked(&cur_flags, placement->placement[i], |
| 959 | ~TTM_PL_MASK_MEMTYPE); |
Thomas Hellstrom | ae3e812 | 2009-06-24 19:57:34 +0200 | [diff] [blame] | 960 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 961 | if (mem_type == TTM_PL_SYSTEM) |
| 962 | break; |
| 963 | |
| 964 | if (man->has_type && man->use_type) { |
| 965 | type_found = true; |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 966 | ret = (*man->func->get_node)(man, bo, placement, mem); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 967 | if (unlikely(ret)) |
| 968 | return ret; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 969 | } |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 970 | if (mem->mm_node) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 971 | break; |
| 972 | } |
| 973 | |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 974 | if ((type_ok && (mem_type == TTM_PL_SYSTEM)) || mem->mm_node) { |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 975 | mem->mem_type = mem_type; |
| 976 | mem->placement = cur_flags; |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | if (!type_found) |
| 981 | return -EINVAL; |
| 982 | |
Dave Airlie | b663752 | 2009-12-14 14:51:35 +1000 | [diff] [blame] | 983 | for (i = 0; i < placement->num_busy_placement; ++i) { |
| 984 | ret = ttm_mem_type_from_flags(placement->busy_placement[i], |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 985 | &mem_type); |
| 986 | if (ret) |
| 987 | return ret; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 988 | man = &bdev->man[mem_type]; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 989 | if (!man->has_type) |
| 990 | continue; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 991 | if (!ttm_bo_mt_compatible(man, |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 992 | bo->type == ttm_bo_type_user, |
| 993 | mem_type, |
Dave Airlie | b663752 | 2009-12-14 14:51:35 +1000 | [diff] [blame] | 994 | placement->busy_placement[i], |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 995 | &cur_flags)) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 996 | continue; |
| 997 | |
Thomas Hellstrom | ae3e812 | 2009-06-24 19:57:34 +0200 | [diff] [blame] | 998 | cur_flags = ttm_bo_select_caching(man, bo->mem.placement, |
| 999 | cur_flags); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1000 | /* |
| 1001 | * Use the access and other non-mapping-related flag bits from |
| 1002 | * the memory placement flags to the current flags |
| 1003 | */ |
Dave Airlie | b663752 | 2009-12-14 14:51:35 +1000 | [diff] [blame] | 1004 | ttm_flag_masked(&cur_flags, placement->busy_placement[i], |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1005 | ~TTM_PL_MASK_MEMTYPE); |
Thomas Hellstrom | ae3e812 | 2009-06-24 19:57:34 +0200 | [diff] [blame] | 1006 | |
Thomas Hellstrom | 0eaddb2 | 2010-01-16 16:05:04 +0100 | [diff] [blame] | 1007 | |
| 1008 | if (mem_type == TTM_PL_SYSTEM) { |
| 1009 | mem->mem_type = mem_type; |
| 1010 | mem->placement = cur_flags; |
| 1011 | mem->mm_node = NULL; |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1015 | ret = ttm_bo_mem_force_space(bo, mem_type, placement, mem, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1016 | interruptible, no_wait_reserve, no_wait_gpu); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1017 | if (ret == 0 && mem->mm_node) { |
| 1018 | mem->placement = cur_flags; |
| 1019 | return 0; |
| 1020 | } |
Thomas Hellstrom | 98ffc415 | 2009-12-07 18:36:18 +0100 | [diff] [blame] | 1021 | if (ret == -ERESTARTSYS) |
| 1022 | has_erestartsys = true; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1023 | } |
Thomas Hellstrom | 98ffc415 | 2009-12-07 18:36:18 +0100 | [diff] [blame] | 1024 | ret = (has_erestartsys) ? -ERESTARTSYS : -ENOMEM; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1025 | return ret; |
| 1026 | } |
| 1027 | EXPORT_SYMBOL(ttm_bo_mem_space); |
| 1028 | |
| 1029 | int ttm_bo_wait_cpu(struct ttm_buffer_object *bo, bool no_wait) |
| 1030 | { |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1031 | if ((atomic_read(&bo->cpu_writers) > 0) && no_wait) |
| 1032 | return -EBUSY; |
| 1033 | |
Thomas Hellstrom | 98ffc415 | 2009-12-07 18:36:18 +0100 | [diff] [blame] | 1034 | return wait_event_interruptible(bo->event_queue, |
| 1035 | atomic_read(&bo->cpu_writers) == 0); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1036 | } |
Ben Skeggs | d1ede14 | 2009-12-11 15:13:00 +1000 | [diff] [blame] | 1037 | EXPORT_SYMBOL(ttm_bo_wait_cpu); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1038 | |
| 1039 | int ttm_bo_move_buffer(struct ttm_buffer_object *bo, |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1040 | struct ttm_placement *placement, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1041 | bool interruptible, bool no_wait_reserve, |
| 1042 | bool no_wait_gpu) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1043 | { |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1044 | int ret = 0; |
| 1045 | struct ttm_mem_reg mem; |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1046 | struct ttm_bo_device *bdev = bo->bdev; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1047 | |
| 1048 | BUG_ON(!atomic_read(&bo->reserved)); |
| 1049 | |
| 1050 | /* |
| 1051 | * FIXME: It's possible to pipeline buffer moves. |
| 1052 | * Have the driver move function wait for idle when necessary, |
| 1053 | * instead of doing it here. |
| 1054 | */ |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1055 | spin_lock(&bdev->fence_lock); |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1056 | ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1057 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1058 | if (ret) |
| 1059 | return ret; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1060 | mem.num_pages = bo->num_pages; |
| 1061 | mem.size = mem.num_pages << PAGE_SHIFT; |
| 1062 | mem.page_alignment = bo->mem.page_alignment; |
Jerome Glisse | 82c5da6 | 2010-04-09 14:39:23 +0200 | [diff] [blame] | 1063 | mem.bus.io_reserved = false; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1064 | /* |
| 1065 | * Determine where to move the buffer. |
| 1066 | */ |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1067 | ret = ttm_bo_mem_space(bo, placement, &mem, interruptible, no_wait_reserve, no_wait_gpu); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1068 | if (ret) |
| 1069 | goto out_unlock; |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1070 | ret = ttm_bo_handle_move_mem(bo, &mem, false, interruptible, no_wait_reserve, no_wait_gpu); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1071 | out_unlock: |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 1072 | if (ret && mem.mm_node) |
| 1073 | ttm_bo_mem_put(bo, &mem); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1074 | return ret; |
| 1075 | } |
| 1076 | |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1077 | static int ttm_bo_mem_compat(struct ttm_placement *placement, |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1078 | struct ttm_mem_reg *mem) |
| 1079 | { |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1080 | int i; |
Thomas Hellstrom | e22238e | 2010-02-12 00:18:00 +0100 | [diff] [blame] | 1081 | |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 1082 | if (mem->mm_node && placement->lpfn != 0 && |
| 1083 | (mem->start < placement->fpfn || |
| 1084 | mem->start + mem->num_pages > placement->lpfn)) |
Thomas Hellstrom | e22238e | 2010-02-12 00:18:00 +0100 | [diff] [blame] | 1085 | return -1; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1086 | |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1087 | for (i = 0; i < placement->num_placement; i++) { |
| 1088 | if ((placement->placement[i] & mem->placement & |
| 1089 | TTM_PL_MASK_CACHING) && |
| 1090 | (placement->placement[i] & mem->placement & |
| 1091 | TTM_PL_MASK_MEM)) |
| 1092 | return i; |
| 1093 | } |
| 1094 | return -1; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
Jerome Glisse | 09855ac | 2009-12-10 17:16:27 +0100 | [diff] [blame] | 1097 | int ttm_bo_validate(struct ttm_buffer_object *bo, |
| 1098 | struct ttm_placement *placement, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1099 | bool interruptible, bool no_wait_reserve, |
| 1100 | bool no_wait_gpu) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1101 | { |
| 1102 | int ret; |
| 1103 | |
| 1104 | BUG_ON(!atomic_read(&bo->reserved)); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1105 | /* Check that range is valid */ |
| 1106 | if (placement->lpfn || placement->fpfn) |
| 1107 | if (placement->fpfn > placement->lpfn || |
| 1108 | (placement->lpfn - placement->fpfn) < bo->num_pages) |
| 1109 | return -EINVAL; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1110 | /* |
| 1111 | * Check whether we need to move buffer. |
| 1112 | */ |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1113 | ret = ttm_bo_mem_compat(placement, &bo->mem); |
| 1114 | if (ret < 0) { |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1115 | ret = ttm_bo_move_buffer(bo, placement, interruptible, no_wait_reserve, no_wait_gpu); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1116 | if (ret) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1117 | return ret; |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1118 | } else { |
| 1119 | /* |
| 1120 | * Use the access and other non-mapping-related flag bits from |
| 1121 | * the compatible memory placement flags to the active flags |
| 1122 | */ |
| 1123 | ttm_flag_masked(&bo->mem.placement, placement->placement[ret], |
| 1124 | ~TTM_PL_MASK_MEMTYPE); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1125 | } |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1126 | /* |
| 1127 | * We might need to add a TTM. |
| 1128 | */ |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1129 | if (bo->mem.mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) { |
| 1130 | ret = ttm_bo_add_ttm(bo, true); |
| 1131 | if (ret) |
| 1132 | return ret; |
| 1133 | } |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1134 | return 0; |
| 1135 | } |
Jerome Glisse | 09855ac | 2009-12-10 17:16:27 +0100 | [diff] [blame] | 1136 | EXPORT_SYMBOL(ttm_bo_validate); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1137 | |
Jerome Glisse | 09855ac | 2009-12-10 17:16:27 +0100 | [diff] [blame] | 1138 | int ttm_bo_check_placement(struct ttm_buffer_object *bo, |
| 1139 | struct ttm_placement *placement) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1140 | { |
Thomas Hellstrom | 29e190e | 2010-11-02 13:21:48 +0000 | [diff] [blame] | 1141 | BUG_ON((placement->fpfn || placement->lpfn) && |
| 1142 | (bo->mem.num_pages > (placement->lpfn - placement->fpfn))); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1143 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1144 | return 0; |
| 1145 | } |
| 1146 | |
Jerome Glisse | 09855ac | 2009-12-10 17:16:27 +0100 | [diff] [blame] | 1147 | int ttm_bo_init(struct ttm_bo_device *bdev, |
| 1148 | struct ttm_buffer_object *bo, |
| 1149 | unsigned long size, |
| 1150 | enum ttm_bo_type type, |
| 1151 | struct ttm_placement *placement, |
| 1152 | uint32_t page_alignment, |
| 1153 | unsigned long buffer_start, |
| 1154 | bool interruptible, |
| 1155 | struct file *persistant_swap_storage, |
| 1156 | size_t acc_size, |
| 1157 | void (*destroy) (struct ttm_buffer_object *)) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1158 | { |
Jerome Glisse | 09855ac | 2009-12-10 17:16:27 +0100 | [diff] [blame] | 1159 | int ret = 0; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1160 | unsigned long num_pages; |
| 1161 | |
| 1162 | size += buffer_start & ~PAGE_MASK; |
| 1163 | num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 1164 | if (num_pages == 0) { |
| 1165 | printk(KERN_ERR TTM_PFX "Illegal buffer object size.\n"); |
Thomas Hellstrom | 7dfbbdc | 2010-11-09 21:31:44 +0100 | [diff] [blame] | 1166 | if (destroy) |
| 1167 | (*destroy)(bo); |
| 1168 | else |
| 1169 | kfree(bo); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1170 | return -EINVAL; |
| 1171 | } |
| 1172 | bo->destroy = destroy; |
| 1173 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1174 | kref_init(&bo->kref); |
| 1175 | kref_init(&bo->list_kref); |
| 1176 | atomic_set(&bo->cpu_writers, 0); |
| 1177 | atomic_set(&bo->reserved, 1); |
| 1178 | init_waitqueue_head(&bo->event_queue); |
| 1179 | INIT_LIST_HEAD(&bo->lru); |
| 1180 | INIT_LIST_HEAD(&bo->ddestroy); |
| 1181 | INIT_LIST_HEAD(&bo->swap); |
| 1182 | bo->bdev = bdev; |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1183 | bo->glob = bdev->glob; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1184 | bo->type = type; |
| 1185 | bo->num_pages = num_pages; |
Jerome Glisse | eb6d2c3 | 2009-12-10 16:15:52 +0100 | [diff] [blame] | 1186 | bo->mem.size = num_pages << PAGE_SHIFT; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1187 | bo->mem.mem_type = TTM_PL_SYSTEM; |
| 1188 | bo->mem.num_pages = bo->num_pages; |
| 1189 | bo->mem.mm_node = NULL; |
| 1190 | bo->mem.page_alignment = page_alignment; |
Jerome Glisse | 82c5da6 | 2010-04-09 14:39:23 +0200 | [diff] [blame] | 1191 | bo->mem.bus.io_reserved = false; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1192 | bo->buffer_start = buffer_start & PAGE_MASK; |
| 1193 | bo->priv_flags = 0; |
| 1194 | bo->mem.placement = (TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED); |
| 1195 | bo->seq_valid = false; |
| 1196 | bo->persistant_swap_storage = persistant_swap_storage; |
| 1197 | bo->acc_size = acc_size; |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1198 | atomic_inc(&bo->glob->bo_count); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1199 | |
Jerome Glisse | 09855ac | 2009-12-10 17:16:27 +0100 | [diff] [blame] | 1200 | ret = ttm_bo_check_placement(bo, placement); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1201 | if (unlikely(ret != 0)) |
| 1202 | goto out_err; |
| 1203 | |
| 1204 | /* |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1205 | * For ttm_bo_type_device buffers, allocate |
| 1206 | * address space from the device. |
| 1207 | */ |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1208 | if (bo->type == ttm_bo_type_device) { |
| 1209 | ret = ttm_bo_setup_vm(bo); |
| 1210 | if (ret) |
| 1211 | goto out_err; |
| 1212 | } |
| 1213 | |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1214 | ret = ttm_bo_validate(bo, placement, interruptible, false, false); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1215 | if (ret) |
| 1216 | goto out_err; |
| 1217 | |
| 1218 | ttm_bo_unreserve(bo); |
| 1219 | return 0; |
| 1220 | |
| 1221 | out_err: |
| 1222 | ttm_bo_unreserve(bo); |
| 1223 | ttm_bo_unref(&bo); |
| 1224 | |
| 1225 | return ret; |
| 1226 | } |
Jerome Glisse | 09855ac | 2009-12-10 17:16:27 +0100 | [diff] [blame] | 1227 | EXPORT_SYMBOL(ttm_bo_init); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1228 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1229 | static inline size_t ttm_bo_size(struct ttm_bo_global *glob, |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1230 | unsigned long num_pages) |
| 1231 | { |
| 1232 | size_t page_array_size = (num_pages * sizeof(void *) + PAGE_SIZE - 1) & |
| 1233 | PAGE_MASK; |
| 1234 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1235 | return glob->ttm_bo_size + 2 * page_array_size; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1236 | } |
| 1237 | |
Jerome Glisse | 09855ac | 2009-12-10 17:16:27 +0100 | [diff] [blame] | 1238 | int ttm_bo_create(struct ttm_bo_device *bdev, |
| 1239 | unsigned long size, |
| 1240 | enum ttm_bo_type type, |
| 1241 | struct ttm_placement *placement, |
| 1242 | uint32_t page_alignment, |
| 1243 | unsigned long buffer_start, |
| 1244 | bool interruptible, |
| 1245 | struct file *persistant_swap_storage, |
| 1246 | struct ttm_buffer_object **p_bo) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1247 | { |
| 1248 | struct ttm_buffer_object *bo; |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1249 | struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1250 | int ret; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1251 | |
| 1252 | size_t acc_size = |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1253 | ttm_bo_size(bdev->glob, (size + PAGE_SIZE - 1) >> PAGE_SHIFT); |
Thomas Hellstrom | 5fd9cba | 2009-08-17 16:28:39 +0200 | [diff] [blame] | 1254 | ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1255 | if (unlikely(ret != 0)) |
| 1256 | return ret; |
| 1257 | |
| 1258 | bo = kzalloc(sizeof(*bo), GFP_KERNEL); |
| 1259 | |
| 1260 | if (unlikely(bo == NULL)) { |
Thomas Hellstrom | 5fd9cba | 2009-08-17 16:28:39 +0200 | [diff] [blame] | 1261 | ttm_mem_global_free(mem_glob, acc_size); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1262 | return -ENOMEM; |
| 1263 | } |
| 1264 | |
Jerome Glisse | 09855ac | 2009-12-10 17:16:27 +0100 | [diff] [blame] | 1265 | ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment, |
| 1266 | buffer_start, interruptible, |
| 1267 | persistant_swap_storage, acc_size, NULL); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1268 | if (likely(ret == 0)) |
| 1269 | *p_bo = bo; |
| 1270 | |
| 1271 | return ret; |
| 1272 | } |
| 1273 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1274 | static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev, |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1275 | unsigned mem_type, bool allow_errors) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1276 | { |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1277 | struct ttm_mem_type_manager *man = &bdev->man[mem_type]; |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1278 | struct ttm_bo_global *glob = bdev->glob; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1279 | int ret; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1280 | |
| 1281 | /* |
| 1282 | * Can't use standard list traversal since we're unlocking. |
| 1283 | */ |
| 1284 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1285 | spin_lock(&glob->lru_lock); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1286 | while (!list_empty(&man->lru)) { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1287 | spin_unlock(&glob->lru_lock); |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1288 | ret = ttm_mem_evict_first(bdev, mem_type, false, false, false); |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1289 | if (ret) { |
| 1290 | if (allow_errors) { |
| 1291 | return ret; |
| 1292 | } else { |
| 1293 | printk(KERN_ERR TTM_PFX |
| 1294 | "Cleanup eviction failed\n"); |
| 1295 | } |
| 1296 | } |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1297 | spin_lock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1298 | } |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1299 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type) |
| 1304 | { |
Roel Kluin | c96e7c7 | 2009-08-03 14:22:53 +0200 | [diff] [blame] | 1305 | struct ttm_mem_type_manager *man; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1306 | int ret = -EINVAL; |
| 1307 | |
| 1308 | if (mem_type >= TTM_NUM_MEM_TYPES) { |
| 1309 | printk(KERN_ERR TTM_PFX "Illegal memory type %d\n", mem_type); |
| 1310 | return ret; |
| 1311 | } |
Roel Kluin | c96e7c7 | 2009-08-03 14:22:53 +0200 | [diff] [blame] | 1312 | man = &bdev->man[mem_type]; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1313 | |
| 1314 | if (!man->has_type) { |
| 1315 | printk(KERN_ERR TTM_PFX "Trying to take down uninitialized " |
| 1316 | "memory manager type %u\n", mem_type); |
| 1317 | return ret; |
| 1318 | } |
| 1319 | |
| 1320 | man->use_type = false; |
| 1321 | man->has_type = false; |
| 1322 | |
| 1323 | ret = 0; |
| 1324 | if (mem_type > 0) { |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1325 | ttm_bo_force_list_clean(bdev, mem_type, false); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1326 | |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 1327 | ret = (*man->func->takedown)(man); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | return ret; |
| 1331 | } |
| 1332 | EXPORT_SYMBOL(ttm_bo_clean_mm); |
| 1333 | |
| 1334 | int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type) |
| 1335 | { |
| 1336 | struct ttm_mem_type_manager *man = &bdev->man[mem_type]; |
| 1337 | |
| 1338 | if (mem_type == 0 || mem_type >= TTM_NUM_MEM_TYPES) { |
| 1339 | printk(KERN_ERR TTM_PFX |
| 1340 | "Illegal memory manager memory type %u.\n", |
| 1341 | mem_type); |
| 1342 | return -EINVAL; |
| 1343 | } |
| 1344 | |
| 1345 | if (!man->has_type) { |
| 1346 | printk(KERN_ERR TTM_PFX |
| 1347 | "Memory type %u has not been initialized.\n", |
| 1348 | mem_type); |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1352 | return ttm_bo_force_list_clean(bdev, mem_type, true); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1353 | } |
| 1354 | EXPORT_SYMBOL(ttm_bo_evict_mm); |
| 1355 | |
| 1356 | int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type, |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1357 | unsigned long p_size) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1358 | { |
| 1359 | int ret = -EINVAL; |
| 1360 | struct ttm_mem_type_manager *man; |
| 1361 | |
Thomas Hellstrom | dbc4a5b | 2010-10-29 10:46:47 +0200 | [diff] [blame] | 1362 | BUG_ON(type >= TTM_NUM_MEM_TYPES); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1363 | man = &bdev->man[type]; |
Thomas Hellstrom | dbc4a5b | 2010-10-29 10:46:47 +0200 | [diff] [blame] | 1364 | BUG_ON(man->has_type); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1365 | |
| 1366 | ret = bdev->driver->init_mem_type(bdev, type, man); |
| 1367 | if (ret) |
| 1368 | return ret; |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 1369 | man->bdev = bdev; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1370 | |
| 1371 | ret = 0; |
| 1372 | if (type != TTM_PL_SYSTEM) { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 1373 | ret = (*man->func->init)(man, p_size); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1374 | if (ret) |
| 1375 | return ret; |
| 1376 | } |
| 1377 | man->has_type = true; |
| 1378 | man->use_type = true; |
| 1379 | man->size = p_size; |
| 1380 | |
| 1381 | INIT_LIST_HEAD(&man->lru); |
| 1382 | |
| 1383 | return 0; |
| 1384 | } |
| 1385 | EXPORT_SYMBOL(ttm_bo_init_mm); |
| 1386 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1387 | static void ttm_bo_global_kobj_release(struct kobject *kobj) |
| 1388 | { |
| 1389 | struct ttm_bo_global *glob = |
| 1390 | container_of(kobj, struct ttm_bo_global, kobj); |
| 1391 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1392 | ttm_mem_unregister_shrink(glob->mem_glob, &glob->shrink); |
| 1393 | __free_page(glob->dummy_read_page); |
| 1394 | kfree(glob); |
| 1395 | } |
| 1396 | |
Dave Airlie | ba4420c | 2010-03-09 10:56:52 +1000 | [diff] [blame] | 1397 | void ttm_bo_global_release(struct drm_global_reference *ref) |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1398 | { |
| 1399 | struct ttm_bo_global *glob = ref->object; |
| 1400 | |
| 1401 | kobject_del(&glob->kobj); |
| 1402 | kobject_put(&glob->kobj); |
| 1403 | } |
| 1404 | EXPORT_SYMBOL(ttm_bo_global_release); |
| 1405 | |
Dave Airlie | ba4420c | 2010-03-09 10:56:52 +1000 | [diff] [blame] | 1406 | int ttm_bo_global_init(struct drm_global_reference *ref) |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1407 | { |
| 1408 | struct ttm_bo_global_ref *bo_ref = |
| 1409 | container_of(ref, struct ttm_bo_global_ref, ref); |
| 1410 | struct ttm_bo_global *glob = ref->object; |
| 1411 | int ret; |
| 1412 | |
| 1413 | mutex_init(&glob->device_list_mutex); |
| 1414 | spin_lock_init(&glob->lru_lock); |
| 1415 | glob->mem_glob = bo_ref->mem_glob; |
| 1416 | glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32); |
| 1417 | |
| 1418 | if (unlikely(glob->dummy_read_page == NULL)) { |
| 1419 | ret = -ENOMEM; |
| 1420 | goto out_no_drp; |
| 1421 | } |
| 1422 | |
| 1423 | INIT_LIST_HEAD(&glob->swap_lru); |
| 1424 | INIT_LIST_HEAD(&glob->device_list); |
| 1425 | |
| 1426 | ttm_mem_init_shrink(&glob->shrink, ttm_bo_swapout); |
| 1427 | ret = ttm_mem_register_shrink(glob->mem_glob, &glob->shrink); |
| 1428 | if (unlikely(ret != 0)) { |
| 1429 | printk(KERN_ERR TTM_PFX |
| 1430 | "Could not register buffer object swapout.\n"); |
| 1431 | goto out_no_shrink; |
| 1432 | } |
| 1433 | |
| 1434 | glob->ttm_bo_extra_size = |
| 1435 | ttm_round_pot(sizeof(struct ttm_tt)) + |
| 1436 | ttm_round_pot(sizeof(struct ttm_backend)); |
| 1437 | |
| 1438 | glob->ttm_bo_size = glob->ttm_bo_extra_size + |
| 1439 | ttm_round_pot(sizeof(struct ttm_buffer_object)); |
| 1440 | |
| 1441 | atomic_set(&glob->bo_count, 0); |
| 1442 | |
Robert P. J. Day | b642ed0 | 2010-03-13 10:36:32 +0000 | [diff] [blame] | 1443 | ret = kobject_init_and_add( |
| 1444 | &glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects"); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1445 | if (unlikely(ret != 0)) |
| 1446 | kobject_put(&glob->kobj); |
| 1447 | return ret; |
| 1448 | out_no_shrink: |
| 1449 | __free_page(glob->dummy_read_page); |
| 1450 | out_no_drp: |
| 1451 | kfree(glob); |
| 1452 | return ret; |
| 1453 | } |
| 1454 | EXPORT_SYMBOL(ttm_bo_global_init); |
| 1455 | |
| 1456 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1457 | int ttm_bo_device_release(struct ttm_bo_device *bdev) |
| 1458 | { |
| 1459 | int ret = 0; |
| 1460 | unsigned i = TTM_NUM_MEM_TYPES; |
| 1461 | struct ttm_mem_type_manager *man; |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1462 | struct ttm_bo_global *glob = bdev->glob; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1463 | |
| 1464 | while (i--) { |
| 1465 | man = &bdev->man[i]; |
| 1466 | if (man->has_type) { |
| 1467 | man->use_type = false; |
| 1468 | if ((i != TTM_PL_SYSTEM) && ttm_bo_clean_mm(bdev, i)) { |
| 1469 | ret = -EBUSY; |
| 1470 | printk(KERN_ERR TTM_PFX |
| 1471 | "DRM memory manager type %d " |
| 1472 | "is not clean.\n", i); |
| 1473 | } |
| 1474 | man->has_type = false; |
| 1475 | } |
| 1476 | } |
| 1477 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1478 | mutex_lock(&glob->device_list_mutex); |
| 1479 | list_del(&bdev->device_list); |
| 1480 | mutex_unlock(&glob->device_list_mutex); |
| 1481 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1482 | if (!cancel_delayed_work(&bdev->wq)) |
| 1483 | flush_scheduled_work(); |
| 1484 | |
| 1485 | while (ttm_bo_delayed_delete(bdev, true)) |
| 1486 | ; |
| 1487 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1488 | spin_lock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1489 | if (list_empty(&bdev->ddestroy)) |
| 1490 | TTM_DEBUG("Delayed destroy list was clean\n"); |
| 1491 | |
| 1492 | if (list_empty(&bdev->man[0].lru)) |
| 1493 | TTM_DEBUG("Swap list was clean\n"); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1494 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1495 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1496 | BUG_ON(!drm_mm_clean(&bdev->addr_space_mm)); |
| 1497 | write_lock(&bdev->vm_lock); |
| 1498 | drm_mm_takedown(&bdev->addr_space_mm); |
| 1499 | write_unlock(&bdev->vm_lock); |
| 1500 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1501 | return ret; |
| 1502 | } |
| 1503 | EXPORT_SYMBOL(ttm_bo_device_release); |
| 1504 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1505 | int ttm_bo_device_init(struct ttm_bo_device *bdev, |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1506 | struct ttm_bo_global *glob, |
| 1507 | struct ttm_bo_driver *driver, |
Dave Airlie | 51c8b40 | 2009-08-20 13:38:04 +1000 | [diff] [blame] | 1508 | uint64_t file_page_offset, |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 1509 | bool need_dma32) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1510 | { |
| 1511 | int ret = -EINVAL; |
| 1512 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1513 | rwlock_init(&bdev->vm_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1514 | bdev->driver = driver; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1515 | |
| 1516 | memset(bdev->man, 0, sizeof(bdev->man)); |
| 1517 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1518 | /* |
| 1519 | * Initialize the system memory buffer type. |
| 1520 | * Other types need to be driver / IOCTL initialized. |
| 1521 | */ |
Jerome Glisse | ca262a999 | 2009-12-08 15:33:32 +0100 | [diff] [blame] | 1522 | ret = ttm_bo_init_mm(bdev, TTM_PL_SYSTEM, 0); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1523 | if (unlikely(ret != 0)) |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1524 | goto out_no_sys; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1525 | |
| 1526 | bdev->addr_space_rb = RB_ROOT; |
| 1527 | ret = drm_mm_init(&bdev->addr_space_mm, file_page_offset, 0x10000000); |
| 1528 | if (unlikely(ret != 0)) |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1529 | goto out_no_addr_mm; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1530 | |
| 1531 | INIT_DELAYED_WORK(&bdev->wq, ttm_bo_delayed_workqueue); |
| 1532 | bdev->nice_mode = true; |
| 1533 | INIT_LIST_HEAD(&bdev->ddestroy); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1534 | bdev->dev_mapping = NULL; |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1535 | bdev->glob = glob; |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 1536 | bdev->need_dma32 = need_dma32; |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1537 | spin_lock_init(&bdev->fence_lock); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1538 | mutex_lock(&glob->device_list_mutex); |
| 1539 | list_add_tail(&bdev->device_list, &glob->device_list); |
| 1540 | mutex_unlock(&glob->device_list_mutex); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1541 | |
| 1542 | return 0; |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1543 | out_no_addr_mm: |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1544 | ttm_bo_clean_mm(bdev, 0); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1545 | out_no_sys: |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1546 | return ret; |
| 1547 | } |
| 1548 | EXPORT_SYMBOL(ttm_bo_device_init); |
| 1549 | |
| 1550 | /* |
| 1551 | * buffer object vm functions. |
| 1552 | */ |
| 1553 | |
| 1554 | bool ttm_mem_reg_is_pci(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) |
| 1555 | { |
| 1556 | struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
| 1557 | |
| 1558 | if (!(man->flags & TTM_MEMTYPE_FLAG_FIXED)) { |
| 1559 | if (mem->mem_type == TTM_PL_SYSTEM) |
| 1560 | return false; |
| 1561 | |
| 1562 | if (man->flags & TTM_MEMTYPE_FLAG_CMA) |
| 1563 | return false; |
| 1564 | |
| 1565 | if (mem->placement & TTM_PL_FLAG_CACHED) |
| 1566 | return false; |
| 1567 | } |
| 1568 | return true; |
| 1569 | } |
| 1570 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1571 | void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo) |
| 1572 | { |
| 1573 | struct ttm_bo_device *bdev = bo->bdev; |
| 1574 | loff_t offset = (loff_t) bo->addr_space_offset; |
| 1575 | loff_t holelen = ((loff_t) bo->mem.num_pages) << PAGE_SHIFT; |
| 1576 | |
| 1577 | if (!bdev->dev_mapping) |
| 1578 | return; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1579 | unmap_mapping_range(bdev->dev_mapping, offset, holelen, 1); |
Jerome Glisse | 82c5da6 | 2010-04-09 14:39:23 +0200 | [diff] [blame] | 1580 | ttm_mem_io_free(bdev, &bo->mem); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1581 | } |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 1582 | EXPORT_SYMBOL(ttm_bo_unmap_virtual); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1583 | |
| 1584 | static void ttm_bo_vm_insert_rb(struct ttm_buffer_object *bo) |
| 1585 | { |
| 1586 | struct ttm_bo_device *bdev = bo->bdev; |
| 1587 | struct rb_node **cur = &bdev->addr_space_rb.rb_node; |
| 1588 | struct rb_node *parent = NULL; |
| 1589 | struct ttm_buffer_object *cur_bo; |
| 1590 | unsigned long offset = bo->vm_node->start; |
| 1591 | unsigned long cur_offset; |
| 1592 | |
| 1593 | while (*cur) { |
| 1594 | parent = *cur; |
| 1595 | cur_bo = rb_entry(parent, struct ttm_buffer_object, vm_rb); |
| 1596 | cur_offset = cur_bo->vm_node->start; |
| 1597 | if (offset < cur_offset) |
| 1598 | cur = &parent->rb_left; |
| 1599 | else if (offset > cur_offset) |
| 1600 | cur = &parent->rb_right; |
| 1601 | else |
| 1602 | BUG(); |
| 1603 | } |
| 1604 | |
| 1605 | rb_link_node(&bo->vm_rb, parent, cur); |
| 1606 | rb_insert_color(&bo->vm_rb, &bdev->addr_space_rb); |
| 1607 | } |
| 1608 | |
| 1609 | /** |
| 1610 | * ttm_bo_setup_vm: |
| 1611 | * |
| 1612 | * @bo: the buffer to allocate address space for |
| 1613 | * |
| 1614 | * Allocate address space in the drm device so that applications |
| 1615 | * can mmap the buffer and access the contents. This only |
| 1616 | * applies to ttm_bo_type_device objects as others are not |
| 1617 | * placed in the drm device address space. |
| 1618 | */ |
| 1619 | |
| 1620 | static int ttm_bo_setup_vm(struct ttm_buffer_object *bo) |
| 1621 | { |
| 1622 | struct ttm_bo_device *bdev = bo->bdev; |
| 1623 | int ret; |
| 1624 | |
| 1625 | retry_pre_get: |
| 1626 | ret = drm_mm_pre_get(&bdev->addr_space_mm); |
| 1627 | if (unlikely(ret != 0)) |
| 1628 | return ret; |
| 1629 | |
| 1630 | write_lock(&bdev->vm_lock); |
| 1631 | bo->vm_node = drm_mm_search_free(&bdev->addr_space_mm, |
| 1632 | bo->mem.num_pages, 0, 0); |
| 1633 | |
| 1634 | if (unlikely(bo->vm_node == NULL)) { |
| 1635 | ret = -ENOMEM; |
| 1636 | goto out_unlock; |
| 1637 | } |
| 1638 | |
| 1639 | bo->vm_node = drm_mm_get_block_atomic(bo->vm_node, |
| 1640 | bo->mem.num_pages, 0); |
| 1641 | |
| 1642 | if (unlikely(bo->vm_node == NULL)) { |
| 1643 | write_unlock(&bdev->vm_lock); |
| 1644 | goto retry_pre_get; |
| 1645 | } |
| 1646 | |
| 1647 | ttm_bo_vm_insert_rb(bo); |
| 1648 | write_unlock(&bdev->vm_lock); |
| 1649 | bo->addr_space_offset = ((uint64_t) bo->vm_node->start) << PAGE_SHIFT; |
| 1650 | |
| 1651 | return 0; |
| 1652 | out_unlock: |
| 1653 | write_unlock(&bdev->vm_lock); |
| 1654 | return ret; |
| 1655 | } |
| 1656 | |
| 1657 | int ttm_bo_wait(struct ttm_buffer_object *bo, |
| 1658 | bool lazy, bool interruptible, bool no_wait) |
| 1659 | { |
| 1660 | struct ttm_bo_driver *driver = bo->bdev->driver; |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1661 | struct ttm_bo_device *bdev = bo->bdev; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1662 | void *sync_obj; |
| 1663 | void *sync_obj_arg; |
| 1664 | int ret = 0; |
| 1665 | |
| 1666 | if (likely(bo->sync_obj == NULL)) |
| 1667 | return 0; |
| 1668 | |
| 1669 | while (bo->sync_obj) { |
| 1670 | |
| 1671 | if (driver->sync_obj_signaled(bo->sync_obj, bo->sync_obj_arg)) { |
| 1672 | void *tmp_obj = bo->sync_obj; |
| 1673 | bo->sync_obj = NULL; |
| 1674 | clear_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1675 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1676 | driver->sync_obj_unref(&tmp_obj); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1677 | spin_lock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1678 | continue; |
| 1679 | } |
| 1680 | |
| 1681 | if (no_wait) |
| 1682 | return -EBUSY; |
| 1683 | |
| 1684 | sync_obj = driver->sync_obj_ref(bo->sync_obj); |
| 1685 | sync_obj_arg = bo->sync_obj_arg; |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1686 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1687 | ret = driver->sync_obj_wait(sync_obj, sync_obj_arg, |
| 1688 | lazy, interruptible); |
| 1689 | if (unlikely(ret != 0)) { |
| 1690 | driver->sync_obj_unref(&sync_obj); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1691 | spin_lock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1692 | return ret; |
| 1693 | } |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1694 | spin_lock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1695 | if (likely(bo->sync_obj == sync_obj && |
| 1696 | bo->sync_obj_arg == sync_obj_arg)) { |
| 1697 | void *tmp_obj = bo->sync_obj; |
| 1698 | bo->sync_obj = NULL; |
| 1699 | clear_bit(TTM_BO_PRIV_FLAG_MOVING, |
| 1700 | &bo->priv_flags); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1701 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1702 | driver->sync_obj_unref(&sync_obj); |
| 1703 | driver->sync_obj_unref(&tmp_obj); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1704 | spin_lock(&bdev->fence_lock); |
Thomas Hellstrom | fee280d | 2009-08-03 12:39:06 +0200 | [diff] [blame] | 1705 | } else { |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1706 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | fee280d | 2009-08-03 12:39:06 +0200 | [diff] [blame] | 1707 | driver->sync_obj_unref(&sync_obj); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1708 | spin_lock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1709 | } |
| 1710 | } |
| 1711 | return 0; |
| 1712 | } |
| 1713 | EXPORT_SYMBOL(ttm_bo_wait); |
| 1714 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1715 | int ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait) |
| 1716 | { |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1717 | struct ttm_bo_device *bdev = bo->bdev; |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1718 | int ret = 0; |
| 1719 | |
| 1720 | /* |
Thomas Hellstrom | 8cfe92d | 2010-04-28 11:33:25 +0200 | [diff] [blame] | 1721 | * Using ttm_bo_reserve makes sure the lru lists are updated. |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1722 | */ |
| 1723 | |
| 1724 | ret = ttm_bo_reserve(bo, true, no_wait, false, 0); |
| 1725 | if (unlikely(ret != 0)) |
| 1726 | return ret; |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1727 | spin_lock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1728 | ret = ttm_bo_wait(bo, false, true, no_wait); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1729 | spin_unlock(&bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1730 | if (likely(ret == 0)) |
| 1731 | atomic_inc(&bo->cpu_writers); |
| 1732 | ttm_bo_unreserve(bo); |
| 1733 | return ret; |
| 1734 | } |
Ben Skeggs | d1ede14 | 2009-12-11 15:13:00 +1000 | [diff] [blame] | 1735 | EXPORT_SYMBOL(ttm_bo_synccpu_write_grab); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1736 | |
| 1737 | void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo) |
| 1738 | { |
| 1739 | if (atomic_dec_and_test(&bo->cpu_writers)) |
| 1740 | wake_up_all(&bo->event_queue); |
| 1741 | } |
Ben Skeggs | d1ede14 | 2009-12-11 15:13:00 +1000 | [diff] [blame] | 1742 | EXPORT_SYMBOL(ttm_bo_synccpu_write_release); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1743 | |
| 1744 | /** |
| 1745 | * A buffer object shrink method that tries to swap out the first |
| 1746 | * buffer object on the bo_global::swap_lru list. |
| 1747 | */ |
| 1748 | |
| 1749 | static int ttm_bo_swapout(struct ttm_mem_shrink *shrink) |
| 1750 | { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1751 | struct ttm_bo_global *glob = |
| 1752 | container_of(shrink, struct ttm_bo_global, shrink); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1753 | struct ttm_buffer_object *bo; |
| 1754 | int ret = -EBUSY; |
| 1755 | int put_count; |
| 1756 | uint32_t swap_placement = (TTM_PL_FLAG_CACHED | TTM_PL_FLAG_SYSTEM); |
| 1757 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1758 | spin_lock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1759 | while (ret == -EBUSY) { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1760 | if (unlikely(list_empty(&glob->swap_lru))) { |
| 1761 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1762 | return -EBUSY; |
| 1763 | } |
| 1764 | |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1765 | bo = list_first_entry(&glob->swap_lru, |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1766 | struct ttm_buffer_object, swap); |
| 1767 | kref_get(&bo->list_kref); |
| 1768 | |
Thomas Hellstrom | e1efc9b | 2010-10-19 09:01:01 +0200 | [diff] [blame] | 1769 | if (!list_empty(&bo->ddestroy)) { |
| 1770 | spin_unlock(&glob->lru_lock); |
| 1771 | (void) ttm_bo_cleanup_refs(bo, false, false, false); |
| 1772 | kref_put(&bo->list_kref, ttm_bo_release_list); |
| 1773 | continue; |
| 1774 | } |
| 1775 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1776 | /** |
| 1777 | * Reserve buffer. Since we unlock while sleeping, we need |
| 1778 | * to re-check that nobody removed us from the swap-list while |
| 1779 | * we slept. |
| 1780 | */ |
| 1781 | |
| 1782 | ret = ttm_bo_reserve_locked(bo, false, true, false, 0); |
| 1783 | if (unlikely(ret == -EBUSY)) { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1784 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1785 | ttm_bo_wait_unreserved(bo, false); |
| 1786 | kref_put(&bo->list_kref, ttm_bo_release_list); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1787 | spin_lock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | BUG_ON(ret != 0); |
| 1792 | put_count = ttm_bo_del_from_lru(bo); |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1793 | spin_unlock(&glob->lru_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1794 | |
Dave Airlie | d6ea888 | 2010-11-22 13:24:40 +1000 | [diff] [blame] | 1795 | ttm_bo_list_ref_sub(bo, put_count, true); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1796 | |
| 1797 | /** |
| 1798 | * Wait for GPU, then move to system cached. |
| 1799 | */ |
| 1800 | |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1801 | spin_lock(&bo->bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1802 | ret = ttm_bo_wait(bo, false, false, false); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame^] | 1803 | spin_unlock(&bo->bdev->fence_lock); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1804 | |
| 1805 | if (unlikely(ret != 0)) |
| 1806 | goto out; |
| 1807 | |
| 1808 | if ((bo->mem.placement & swap_placement) != swap_placement) { |
| 1809 | struct ttm_mem_reg evict_mem; |
| 1810 | |
| 1811 | evict_mem = bo->mem; |
| 1812 | evict_mem.mm_node = NULL; |
| 1813 | evict_mem.placement = TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED; |
| 1814 | evict_mem.mem_type = TTM_PL_SYSTEM; |
| 1815 | |
| 1816 | ret = ttm_bo_handle_move_mem(bo, &evict_mem, true, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 1817 | false, false, false); |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1818 | if (unlikely(ret != 0)) |
| 1819 | goto out; |
| 1820 | } |
| 1821 | |
| 1822 | ttm_bo_unmap_virtual(bo); |
| 1823 | |
| 1824 | /** |
| 1825 | * Swap out. Buffer will be swapped in again as soon as |
| 1826 | * anyone tries to access a ttm page. |
| 1827 | */ |
| 1828 | |
Thomas Hellstrom | 3f09ea4 | 2010-01-13 22:28:40 +0100 | [diff] [blame] | 1829 | if (bo->bdev->driver->swap_notify) |
| 1830 | bo->bdev->driver->swap_notify(bo); |
| 1831 | |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1832 | ret = ttm_tt_swapout(bo->ttm, bo->persistant_swap_storage); |
| 1833 | out: |
| 1834 | |
| 1835 | /** |
| 1836 | * |
| 1837 | * Unreserve without putting on LRU to avoid swapping out an |
| 1838 | * already swapped buffer. |
| 1839 | */ |
| 1840 | |
| 1841 | atomic_set(&bo->reserved, 0); |
| 1842 | wake_up_all(&bo->event_queue); |
| 1843 | kref_put(&bo->list_kref, ttm_bo_release_list); |
| 1844 | return ret; |
| 1845 | } |
| 1846 | |
| 1847 | void ttm_bo_swapout_all(struct ttm_bo_device *bdev) |
| 1848 | { |
Thomas Hellstrom | a987fca | 2009-08-18 16:51:56 +0200 | [diff] [blame] | 1849 | while (ttm_bo_swapout(&bdev->glob->shrink) == 0) |
Thomas Hellstrom | ba4e7d9 | 2009-06-10 15:20:19 +0200 | [diff] [blame] | 1850 | ; |
| 1851 | } |
Thomas Hellstrom | e99e1e7 | 2010-01-13 22:28:42 +0100 | [diff] [blame] | 1852 | EXPORT_SYMBOL(ttm_bo_swapout_all); |