| .. | .. |
|---|
| 48 | 48 | struct ttm_bo_device *bdev = bo->bdev; |
|---|
| 49 | 49 | uint32_t page_flags = 0; |
|---|
| 50 | 50 | |
|---|
| 51 | | - reservation_object_assert_held(bo->resv); |
|---|
| 51 | + dma_resv_assert_held(bo->base.resv); |
|---|
| 52 | + |
|---|
| 53 | + if (bo->ttm) |
|---|
| 54 | + return 0; |
|---|
| 52 | 55 | |
|---|
| 53 | 56 | if (bdev->need_dma32) |
|---|
| 54 | 57 | page_flags |= TTM_PAGE_FLAG_DMA32; |
|---|
| .. | .. |
|---|
| 67 | 70 | page_flags |= TTM_PAGE_FLAG_SG; |
|---|
| 68 | 71 | break; |
|---|
| 69 | 72 | default: |
|---|
| 70 | | - bo->ttm = NULL; |
|---|
| 71 | 73 | pr_err("Illegal buffer object type\n"); |
|---|
| 72 | 74 | return -EINVAL; |
|---|
| 73 | 75 | } |
|---|
| .. | .. |
|---|
| 154 | 156 | if (ttm->caching_state == c_state) |
|---|
| 155 | 157 | return 0; |
|---|
| 156 | 158 | |
|---|
| 157 | | - if (ttm->state == tt_unpopulated) { |
|---|
| 159 | + if (!ttm_tt_is_populated(ttm)) { |
|---|
| 158 | 160 | /* Change caching but don't populate */ |
|---|
| 159 | 161 | ttm->caching_state = c_state; |
|---|
| 160 | 162 | return 0; |
|---|
| .. | .. |
|---|
| 205 | 207 | } |
|---|
| 206 | 208 | EXPORT_SYMBOL(ttm_tt_set_placement_caching); |
|---|
| 207 | 209 | |
|---|
| 208 | | -void ttm_tt_destroy(struct ttm_tt *ttm) |
|---|
| 210 | +void ttm_tt_destroy_common(struct ttm_bo_device *bdev, struct ttm_tt *ttm) |
|---|
| 209 | 211 | { |
|---|
| 210 | | - if (ttm == NULL) |
|---|
| 211 | | - return; |
|---|
| 212 | | - |
|---|
| 213 | | - ttm_tt_unbind(ttm); |
|---|
| 214 | | - |
|---|
| 215 | | - if (ttm->state == tt_unbound) |
|---|
| 216 | | - ttm_tt_unpopulate(ttm); |
|---|
| 212 | + ttm_tt_unpopulate(bdev, ttm); |
|---|
| 217 | 213 | |
|---|
| 218 | 214 | if (!(ttm->page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP) && |
|---|
| 219 | 215 | ttm->swap_storage) |
|---|
| 220 | 216 | fput(ttm->swap_storage); |
|---|
| 221 | 217 | |
|---|
| 222 | 218 | ttm->swap_storage = NULL; |
|---|
| 223 | | - ttm->func->destroy(ttm); |
|---|
| 219 | +} |
|---|
| 220 | +EXPORT_SYMBOL(ttm_tt_destroy_common); |
|---|
| 221 | + |
|---|
| 222 | +void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm) |
|---|
| 223 | +{ |
|---|
| 224 | + bdev->driver->ttm_tt_destroy(bdev, ttm); |
|---|
| 224 | 225 | } |
|---|
| 225 | 226 | |
|---|
| 226 | | -void ttm_tt_init_fields(struct ttm_tt *ttm, struct ttm_buffer_object *bo, |
|---|
| 227 | | - uint32_t page_flags) |
|---|
| 227 | +static void ttm_tt_init_fields(struct ttm_tt *ttm, |
|---|
| 228 | + struct ttm_buffer_object *bo, |
|---|
| 229 | + uint32_t page_flags) |
|---|
| 228 | 230 | { |
|---|
| 229 | | - ttm->bdev = bo->bdev; |
|---|
| 230 | 231 | ttm->num_pages = bo->num_pages; |
|---|
| 231 | 232 | ttm->caching_state = tt_cached; |
|---|
| 232 | 233 | ttm->page_flags = page_flags; |
|---|
| 233 | | - ttm->state = tt_unpopulated; |
|---|
| 234 | + ttm_tt_set_unpopulated(ttm); |
|---|
| 234 | 235 | ttm->swap_storage = NULL; |
|---|
| 235 | 236 | ttm->sg = bo->sg; |
|---|
| 236 | 237 | } |
|---|
| .. | .. |
|---|
| 305 | 306 | } |
|---|
| 306 | 307 | EXPORT_SYMBOL(ttm_dma_tt_fini); |
|---|
| 307 | 308 | |
|---|
| 308 | | -void ttm_tt_unbind(struct ttm_tt *ttm) |
|---|
| 309 | | -{ |
|---|
| 310 | | - int ret; |
|---|
| 311 | | - |
|---|
| 312 | | - if (ttm->state == tt_bound) { |
|---|
| 313 | | - ret = ttm->func->unbind(ttm); |
|---|
| 314 | | - BUG_ON(ret); |
|---|
| 315 | | - ttm->state = tt_unbound; |
|---|
| 316 | | - } |
|---|
| 317 | | -} |
|---|
| 318 | | - |
|---|
| 319 | | -int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem, |
|---|
| 320 | | - struct ttm_operation_ctx *ctx) |
|---|
| 321 | | -{ |
|---|
| 322 | | - int ret = 0; |
|---|
| 323 | | - |
|---|
| 324 | | - if (!ttm) |
|---|
| 325 | | - return -EINVAL; |
|---|
| 326 | | - |
|---|
| 327 | | - if (ttm->state == tt_bound) |
|---|
| 328 | | - return 0; |
|---|
| 329 | | - |
|---|
| 330 | | - ret = ttm_tt_populate(ttm, ctx); |
|---|
| 331 | | - if (ret) |
|---|
| 332 | | - return ret; |
|---|
| 333 | | - |
|---|
| 334 | | - ret = ttm->func->bind(ttm, bo_mem); |
|---|
| 335 | | - if (unlikely(ret != 0)) |
|---|
| 336 | | - return ret; |
|---|
| 337 | | - |
|---|
| 338 | | - ttm->state = tt_bound; |
|---|
| 339 | | - |
|---|
| 340 | | - return 0; |
|---|
| 341 | | -} |
|---|
| 342 | | -EXPORT_SYMBOL(ttm_tt_bind); |
|---|
| 343 | | - |
|---|
| 344 | 309 | int ttm_tt_swapin(struct ttm_tt *ttm) |
|---|
| 345 | 310 | { |
|---|
| 346 | 311 | struct address_space *swap_space; |
|---|
| .. | .. |
|---|
| 383 | 348 | return ret; |
|---|
| 384 | 349 | } |
|---|
| 385 | 350 | |
|---|
| 386 | | -int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage) |
|---|
| 351 | +int ttm_tt_swapout(struct ttm_bo_device *bdev, |
|---|
| 352 | + struct ttm_tt *ttm, struct file *persistent_swap_storage) |
|---|
| 387 | 353 | { |
|---|
| 388 | 354 | struct address_space *swap_space; |
|---|
| 389 | 355 | struct file *swap_storage; |
|---|
| .. | .. |
|---|
| 392 | 358 | int i; |
|---|
| 393 | 359 | int ret = -ENOMEM; |
|---|
| 394 | 360 | |
|---|
| 395 | | - BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated); |
|---|
| 396 | 361 | BUG_ON(ttm->caching_state != tt_cached); |
|---|
| 397 | 362 | |
|---|
| 398 | 363 | if (!persistent_swap_storage) { |
|---|
| .. | .. |
|---|
| 429 | 394 | put_page(to_page); |
|---|
| 430 | 395 | } |
|---|
| 431 | 396 | |
|---|
| 432 | | - ttm_tt_unpopulate(ttm); |
|---|
| 397 | + ttm_tt_unpopulate(bdev, ttm); |
|---|
| 433 | 398 | ttm->swap_storage = swap_storage; |
|---|
| 434 | 399 | ttm->page_flags |= TTM_PAGE_FLAG_SWAPPED; |
|---|
| 435 | 400 | if (persistent_swap_storage) |
|---|
| .. | .. |
|---|
| 443 | 408 | return ret; |
|---|
| 444 | 409 | } |
|---|
| 445 | 410 | |
|---|
| 446 | | -static void ttm_tt_add_mapping(struct ttm_tt *ttm) |
|---|
| 411 | +static void ttm_tt_add_mapping(struct ttm_bo_device *bdev, struct ttm_tt *ttm) |
|---|
| 447 | 412 | { |
|---|
| 448 | 413 | pgoff_t i; |
|---|
| 449 | 414 | |
|---|
| .. | .. |
|---|
| 451 | 416 | return; |
|---|
| 452 | 417 | |
|---|
| 453 | 418 | for (i = 0; i < ttm->num_pages; ++i) |
|---|
| 454 | | - ttm->pages[i]->mapping = ttm->bdev->dev_mapping; |
|---|
| 419 | + ttm->pages[i]->mapping = bdev->dev_mapping; |
|---|
| 455 | 420 | } |
|---|
| 456 | 421 | |
|---|
| 457 | | -int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) |
|---|
| 422 | +int ttm_tt_populate(struct ttm_bo_device *bdev, |
|---|
| 423 | + struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) |
|---|
| 458 | 424 | { |
|---|
| 459 | 425 | int ret; |
|---|
| 460 | 426 | |
|---|
| 461 | | - if (ttm->state != tt_unpopulated) |
|---|
| 427 | + if (!ttm) |
|---|
| 428 | + return -EINVAL; |
|---|
| 429 | + |
|---|
| 430 | + if (ttm_tt_is_populated(ttm)) |
|---|
| 462 | 431 | return 0; |
|---|
| 463 | 432 | |
|---|
| 464 | | - if (ttm->bdev->driver->ttm_tt_populate) |
|---|
| 465 | | - ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx); |
|---|
| 433 | + if (bdev->driver->ttm_tt_populate) |
|---|
| 434 | + ret = bdev->driver->ttm_tt_populate(bdev, ttm, ctx); |
|---|
| 466 | 435 | else |
|---|
| 467 | 436 | ret = ttm_pool_populate(ttm, ctx); |
|---|
| 468 | 437 | if (!ret) |
|---|
| 469 | | - ttm_tt_add_mapping(ttm); |
|---|
| 438 | + ttm_tt_add_mapping(bdev, ttm); |
|---|
| 470 | 439 | return ret; |
|---|
| 471 | 440 | } |
|---|
| 441 | +EXPORT_SYMBOL(ttm_tt_populate); |
|---|
| 472 | 442 | |
|---|
| 473 | 443 | static void ttm_tt_clear_mapping(struct ttm_tt *ttm) |
|---|
| 474 | 444 | { |
|---|
| .. | .. |
|---|
| 484 | 454 | } |
|---|
| 485 | 455 | } |
|---|
| 486 | 456 | |
|---|
| 487 | | -void ttm_tt_unpopulate(struct ttm_tt *ttm) |
|---|
| 457 | +void ttm_tt_unpopulate(struct ttm_bo_device *bdev, |
|---|
| 458 | + struct ttm_tt *ttm) |
|---|
| 488 | 459 | { |
|---|
| 489 | | - if (ttm->state == tt_unpopulated) |
|---|
| 460 | + if (!ttm_tt_is_populated(ttm)) |
|---|
| 490 | 461 | return; |
|---|
| 491 | 462 | |
|---|
| 492 | 463 | ttm_tt_clear_mapping(ttm); |
|---|
| 493 | | - if (ttm->bdev->driver->ttm_tt_unpopulate) |
|---|
| 494 | | - ttm->bdev->driver->ttm_tt_unpopulate(ttm); |
|---|
| 464 | + if (bdev->driver->ttm_tt_unpopulate) |
|---|
| 465 | + bdev->driver->ttm_tt_unpopulate(bdev, ttm); |
|---|
| 495 | 466 | else |
|---|
| 496 | 467 | ttm_pool_unpopulate(ttm); |
|---|
| 497 | 468 | } |
|---|
| 469 | +EXPORT_SYMBOL(ttm_tt_unpopulate); |
|---|