Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'drm-intel-fixes-2014-09-10' of git://anongit.freedesktop.org/drm-intel into drm-fixes

more fixes for 3.17, almost all Cc: stable material.

* tag 'drm-intel-fixes-2014-09-10' of git://anongit.freedesktop.org/drm-intel:
drm/i915: Wait for vblank before enabling the TV encoder
drm/i915: Evict CS TLBs between batches
drm/i915: Fix irq enable tracking in driver load
drm/i915: Fix EIO/wedged handling in gem fault handler
drm/i915: Prevent recursive deadlock on releasing a busy userptr

+300 -221
+7 -2
drivers/gpu/drm/i915/i915_dma.c
··· 1336 1336 1337 1337 intel_power_domains_init_hw(dev_priv); 1338 1338 1339 + /* 1340 + * We enable some interrupt sources in our postinstall hooks, so mark 1341 + * interrupts as enabled _before_ actually enabling them to avoid 1342 + * special cases in our ordering checks. 1343 + */ 1344 + dev_priv->pm._irqs_disabled = false; 1345 + 1339 1346 ret = drm_irq_install(dev, dev->pdev->irq); 1340 1347 if (ret) 1341 1348 goto cleanup_gem_stolen; 1342 - 1343 - dev_priv->pm._irqs_disabled = false; 1344 1349 1345 1350 /* Important: The output setup functions called by modeset_init need 1346 1351 * working irqs for e.g. gmbus and dp aux transfers. */
+5 -5
drivers/gpu/drm/i915/i915_drv.h
··· 184 184 if ((1 << (domain)) & (mask)) 185 185 186 186 struct drm_i915_private; 187 + struct i915_mm_struct; 187 188 struct i915_mmu_object; 188 189 189 190 enum intel_dpll_id { ··· 1507 1506 struct i915_gtt gtt; /* VM representing the global address space */ 1508 1507 1509 1508 struct i915_gem_mm mm; 1510 - #if defined(CONFIG_MMU_NOTIFIER) 1511 - DECLARE_HASHTABLE(mmu_notifiers, 7); 1512 - #endif 1509 + DECLARE_HASHTABLE(mm_structs, 7); 1510 + struct mutex mm_lock; 1513 1511 1514 1512 /* Kernel Modesetting */ 1515 1513 ··· 1814 1814 unsigned workers :4; 1815 1815 #define I915_GEM_USERPTR_MAX_WORKERS 15 1816 1816 1817 - struct mm_struct *mm; 1818 - struct i915_mmu_object *mn; 1817 + struct i915_mm_struct *mm; 1818 + struct i915_mmu_object *mmu_object; 1819 1819 struct work_struct *work; 1820 1820 } userptr; 1821 1821 };
+7 -4
drivers/gpu/drm/i915/i915_gem.c
··· 1590 1590 out: 1591 1591 switch (ret) { 1592 1592 case -EIO: 1593 - /* If this -EIO is due to a gpu hang, give the reset code a 1594 - * chance to clean up the mess. Otherwise return the proper 1595 - * SIGBUS. */ 1596 - if (i915_terminally_wedged(&dev_priv->gpu_error)) { 1593 + /* 1594 + * We eat errors when the gpu is terminally wedged to avoid 1595 + * userspace unduly crashing (gl has no provisions for mmaps to 1596 + * fail). But any other -EIO isn't ours (e.g. swap in failure) 1597 + * and so needs to be reported. 1598 + */ 1599 + if (!i915_terminally_wedged(&dev_priv->gpu_error)) { 1597 1600 ret = VM_FAULT_SIGBUS; 1598 1601 break; 1599 1602 }
+230 -179
drivers/gpu/drm/i915/i915_gem_userptr.c
··· 32 32 #include <linux/mempolicy.h> 33 33 #include <linux/swap.h> 34 34 35 + struct i915_mm_struct { 36 + struct mm_struct *mm; 37 + struct drm_device *dev; 38 + struct i915_mmu_notifier *mn; 39 + struct hlist_node node; 40 + struct kref kref; 41 + struct work_struct work; 42 + }; 43 + 35 44 #if defined(CONFIG_MMU_NOTIFIER) 36 45 #include <linux/interval_tree.h> 37 46 ··· 50 41 struct mmu_notifier mn; 51 42 struct rb_root objects; 52 43 struct list_head linear; 53 - struct drm_device *dev; 54 - struct mm_struct *mm; 55 - struct work_struct work; 56 - unsigned long count; 57 44 unsigned long serial; 58 45 bool has_linear; 59 46 }; 60 47 61 48 struct i915_mmu_object { 62 - struct i915_mmu_notifier *mmu; 49 + struct i915_mmu_notifier *mn; 63 50 struct interval_tree_node it; 64 51 struct list_head link; 65 52 struct drm_i915_gem_object *obj; ··· 101 96 unsigned long start, 102 97 unsigned long end) 103 98 { 104 - struct i915_mmu_object *mmu; 99 + struct i915_mmu_object *mo; 105 100 unsigned long serial; 106 101 107 102 restart: 108 103 serial = mn->serial; 109 - list_for_each_entry(mmu, &mn->linear, link) { 104 + list_for_each_entry(mo, &mn->linear, link) { 110 105 struct drm_i915_gem_object *obj; 111 106 112 - if (mmu->it.last < start || mmu->it.start > end) 107 + if (mo->it.last < start || mo->it.start > end) 113 108 continue; 114 109 115 - obj = mmu->obj; 110 + obj = mo->obj; 116 111 drm_gem_object_reference(&obj->base); 117 112 spin_unlock(&mn->lock); 118 113 ··· 165 160 }; 166 161 167 162 static struct i915_mmu_notifier * 168 - __i915_mmu_notifier_lookup(struct drm_device *dev, struct mm_struct *mm) 163 + i915_mmu_notifier_create(struct mm_struct *mm) 169 164 { 170 - struct drm_i915_private *dev_priv = to_i915(dev); 171 - struct i915_mmu_notifier *mmu; 172 - 173 - /* Protected by dev->struct_mutex */ 174 - hash_for_each_possible(dev_priv->mmu_notifiers, mmu, node, (unsigned long)mm) 175 - if (mmu->mm == mm) 176 - return mmu; 177 - 178 - return NULL; 179 - } 180 - 181 - static struct i915_mmu_notifier * 182 - i915_mmu_notifier_get(struct drm_device *dev, struct mm_struct *mm) 183 - { 184 - struct drm_i915_private *dev_priv = to_i915(dev); 185 - struct i915_mmu_notifier *mmu; 165 + struct i915_mmu_notifier *mn; 186 166 int ret; 187 167 188 - lockdep_assert_held(&dev->struct_mutex); 189 - 190 - mmu = __i915_mmu_notifier_lookup(dev, mm); 191 - if (mmu) 192 - return mmu; 193 - 194 - mmu = kmalloc(sizeof(*mmu), GFP_KERNEL); 195 - if (mmu == NULL) 168 + mn = kmalloc(sizeof(*mn), GFP_KERNEL); 169 + if (mn == NULL) 196 170 return ERR_PTR(-ENOMEM); 197 171 198 - spin_lock_init(&mmu->lock); 199 - mmu->dev = dev; 200 - mmu->mn.ops = &i915_gem_userptr_notifier; 201 - mmu->mm = mm; 202 - mmu->objects = RB_ROOT; 203 - mmu->count = 0; 204 - mmu->serial = 1; 205 - INIT_LIST_HEAD(&mmu->linear); 206 - mmu->has_linear = false; 172 + spin_lock_init(&mn->lock); 173 + mn->mn.ops = &i915_gem_userptr_notifier; 174 + mn->objects = RB_ROOT; 175 + mn->serial = 1; 176 + INIT_LIST_HEAD(&mn->linear); 177 + mn->has_linear = false; 207 178 208 - /* Protected by mmap_sem (write-lock) */ 209 - ret = __mmu_notifier_register(&mmu->mn, mm); 179 + /* Protected by mmap_sem (write-lock) */ 180 + ret = __mmu_notifier_register(&mn->mn, mm); 210 181 if (ret) { 211 - kfree(mmu); 182 + kfree(mn); 212 183 return ERR_PTR(ret); 213 184 } 214 185 215 - /* Protected by dev->struct_mutex */ 216 - hash_add(dev_priv->mmu_notifiers, &mmu->node, (unsigned long)mm); 217 - return mmu; 186 + return mn; 218 187 } 219 188 220 - static void 221 - __i915_mmu_notifier_destroy_worker(struct work_struct *work) 189 + static void __i915_mmu_notifier_update_serial(struct i915_mmu_notifier *mn) 222 190 { 223 - struct i915_mmu_notifier *mmu = container_of(work, typeof(*mmu), work); 224 - mmu_notifier_unregister(&mmu->mn, mmu->mm); 225 - kfree(mmu); 226 - } 227 - 228 - static void 229 - __i915_mmu_notifier_destroy(struct i915_mmu_notifier *mmu) 230 - { 231 - lockdep_assert_held(&mmu->dev->struct_mutex); 232 - 233 - /* Protected by dev->struct_mutex */ 234 - hash_del(&mmu->node); 235 - 236 - /* Our lock ordering is: mmap_sem, mmu_notifier_scru, struct_mutex. 237 - * We enter the function holding struct_mutex, therefore we need 238 - * to drop our mutex prior to calling mmu_notifier_unregister in 239 - * order to prevent lock inversion (and system-wide deadlock) 240 - * between the mmap_sem and struct-mutex. Hence we defer the 241 - * unregistration to a workqueue where we hold no locks. 242 - */ 243 - INIT_WORK(&mmu->work, __i915_mmu_notifier_destroy_worker); 244 - schedule_work(&mmu->work); 245 - } 246 - 247 - static void __i915_mmu_notifier_update_serial(struct i915_mmu_notifier *mmu) 248 - { 249 - if (++mmu->serial == 0) 250 - mmu->serial = 1; 251 - } 252 - 253 - static bool i915_mmu_notifier_has_linear(struct i915_mmu_notifier *mmu) 254 - { 255 - struct i915_mmu_object *mn; 256 - 257 - list_for_each_entry(mn, &mmu->linear, link) 258 - if (mn->is_linear) 259 - return true; 260 - 261 - return false; 262 - } 263 - 264 - static void 265 - i915_mmu_notifier_del(struct i915_mmu_notifier *mmu, 266 - struct i915_mmu_object *mn) 267 - { 268 - lockdep_assert_held(&mmu->dev->struct_mutex); 269 - 270 - spin_lock(&mmu->lock); 271 - list_del(&mn->link); 272 - if (mn->is_linear) 273 - mmu->has_linear = i915_mmu_notifier_has_linear(mmu); 274 - else 275 - interval_tree_remove(&mn->it, &mmu->objects); 276 - __i915_mmu_notifier_update_serial(mmu); 277 - spin_unlock(&mmu->lock); 278 - 279 - /* Protected against _add() by dev->struct_mutex */ 280 - if (--mmu->count == 0) 281 - __i915_mmu_notifier_destroy(mmu); 191 + if (++mn->serial == 0) 192 + mn->serial = 1; 282 193 } 283 194 284 195 static int 285 - i915_mmu_notifier_add(struct i915_mmu_notifier *mmu, 286 - struct i915_mmu_object *mn) 196 + i915_mmu_notifier_add(struct drm_device *dev, 197 + struct i915_mmu_notifier *mn, 198 + struct i915_mmu_object *mo) 287 199 { 288 200 struct interval_tree_node *it; 289 201 int ret; 290 202 291 - ret = i915_mutex_lock_interruptible(mmu->dev); 203 + ret = i915_mutex_lock_interruptible(dev); 292 204 if (ret) 293 205 return ret; 294 206 ··· 213 291 * remove the objects from the interval tree) before we do 214 292 * the check for overlapping objects. 215 293 */ 216 - i915_gem_retire_requests(mmu->dev); 294 + i915_gem_retire_requests(dev); 217 295 218 - spin_lock(&mmu->lock); 219 - it = interval_tree_iter_first(&mmu->objects, 220 - mn->it.start, mn->it.last); 296 + spin_lock(&mn->lock); 297 + it = interval_tree_iter_first(&mn->objects, 298 + mo->it.start, mo->it.last); 221 299 if (it) { 222 300 struct drm_i915_gem_object *obj; 223 301 ··· 234 312 235 313 obj = container_of(it, struct i915_mmu_object, it)->obj; 236 314 if (!obj->userptr.workers) 237 - mmu->has_linear = mn->is_linear = true; 315 + mn->has_linear = mo->is_linear = true; 238 316 else 239 317 ret = -EAGAIN; 240 318 } else 241 - interval_tree_insert(&mn->it, &mmu->objects); 319 + interval_tree_insert(&mo->it, &mn->objects); 242 320 243 321 if (ret == 0) { 244 - list_add(&mn->link, &mmu->linear); 245 - __i915_mmu_notifier_update_serial(mmu); 322 + list_add(&mo->link, &mn->linear); 323 + __i915_mmu_notifier_update_serial(mn); 246 324 } 247 - spin_unlock(&mmu->lock); 248 - mutex_unlock(&mmu->dev->struct_mutex); 325 + spin_unlock(&mn->lock); 326 + mutex_unlock(&dev->struct_mutex); 249 327 250 328 return ret; 329 + } 330 + 331 + static bool i915_mmu_notifier_has_linear(struct i915_mmu_notifier *mn) 332 + { 333 + struct i915_mmu_object *mo; 334 + 335 + list_for_each_entry(mo, &mn->linear, link) 336 + if (mo->is_linear) 337 + return true; 338 + 339 + return false; 340 + } 341 + 342 + static void 343 + i915_mmu_notifier_del(struct i915_mmu_notifier *mn, 344 + struct i915_mmu_object *mo) 345 + { 346 + spin_lock(&mn->lock); 347 + list_del(&mo->link); 348 + if (mo->is_linear) 349 + mn->has_linear = i915_mmu_notifier_has_linear(mn); 350 + else 351 + interval_tree_remove(&mo->it, &mn->objects); 352 + __i915_mmu_notifier_update_serial(mn); 353 + spin_unlock(&mn->lock); 251 354 } 252 355 253 356 static void 254 357 i915_gem_userptr_release__mmu_notifier(struct drm_i915_gem_object *obj) 255 358 { 256 - struct i915_mmu_object *mn; 359 + struct i915_mmu_object *mo; 257 360 258 - mn = obj->userptr.mn; 259 - if (mn == NULL) 361 + mo = obj->userptr.mmu_object; 362 + if (mo == NULL) 260 363 return; 261 364 262 - i915_mmu_notifier_del(mn->mmu, mn); 263 - obj->userptr.mn = NULL; 365 + i915_mmu_notifier_del(mo->mn, mo); 366 + kfree(mo); 367 + 368 + obj->userptr.mmu_object = NULL; 369 + } 370 + 371 + static struct i915_mmu_notifier * 372 + i915_mmu_notifier_find(struct i915_mm_struct *mm) 373 + { 374 + if (mm->mn == NULL) { 375 + down_write(&mm->mm->mmap_sem); 376 + mutex_lock(&to_i915(mm->dev)->mm_lock); 377 + if (mm->mn == NULL) 378 + mm->mn = i915_mmu_notifier_create(mm->mm); 379 + mutex_unlock(&to_i915(mm->dev)->mm_lock); 380 + up_write(&mm->mm->mmap_sem); 381 + } 382 + return mm->mn; 264 383 } 265 384 266 385 static int 267 386 i915_gem_userptr_init__mmu_notifier(struct drm_i915_gem_object *obj, 268 387 unsigned flags) 269 388 { 270 - struct i915_mmu_notifier *mmu; 271 - struct i915_mmu_object *mn; 389 + struct i915_mmu_notifier *mn; 390 + struct i915_mmu_object *mo; 272 391 int ret; 273 392 274 393 if (flags & I915_USERPTR_UNSYNCHRONIZED) 275 394 return capable(CAP_SYS_ADMIN) ? 0 : -EPERM; 276 395 277 - down_write(&obj->userptr.mm->mmap_sem); 278 - ret = i915_mutex_lock_interruptible(obj->base.dev); 279 - if (ret == 0) { 280 - mmu = i915_mmu_notifier_get(obj->base.dev, obj->userptr.mm); 281 - if (!IS_ERR(mmu)) 282 - mmu->count++; /* preemptive add to act as a refcount */ 283 - else 284 - ret = PTR_ERR(mmu); 285 - mutex_unlock(&obj->base.dev->struct_mutex); 286 - } 287 - up_write(&obj->userptr.mm->mmap_sem); 288 - if (ret) 396 + if (WARN_ON(obj->userptr.mm == NULL)) 397 + return -EINVAL; 398 + 399 + mn = i915_mmu_notifier_find(obj->userptr.mm); 400 + if (IS_ERR(mn)) 401 + return PTR_ERR(mn); 402 + 403 + mo = kzalloc(sizeof(*mo), GFP_KERNEL); 404 + if (mo == NULL) 405 + return -ENOMEM; 406 + 407 + mo->mn = mn; 408 + mo->it.start = obj->userptr.ptr; 409 + mo->it.last = mo->it.start + obj->base.size - 1; 410 + mo->obj = obj; 411 + 412 + ret = i915_mmu_notifier_add(obj->base.dev, mn, mo); 413 + if (ret) { 414 + kfree(mo); 289 415 return ret; 290 - 291 - mn = kzalloc(sizeof(*mn), GFP_KERNEL); 292 - if (mn == NULL) { 293 - ret = -ENOMEM; 294 - goto destroy_mmu; 295 416 } 296 417 297 - mn->mmu = mmu; 298 - mn->it.start = obj->userptr.ptr; 299 - mn->it.last = mn->it.start + obj->base.size - 1; 300 - mn->obj = obj; 301 - 302 - ret = i915_mmu_notifier_add(mmu, mn); 303 - if (ret) 304 - goto free_mn; 305 - 306 - obj->userptr.mn = mn; 418 + obj->userptr.mmu_object = mo; 307 419 return 0; 420 + } 308 421 309 - free_mn: 422 + static void 423 + i915_mmu_notifier_free(struct i915_mmu_notifier *mn, 424 + struct mm_struct *mm) 425 + { 426 + if (mn == NULL) 427 + return; 428 + 429 + mmu_notifier_unregister(&mn->mn, mm); 310 430 kfree(mn); 311 - destroy_mmu: 312 - mutex_lock(&obj->base.dev->struct_mutex); 313 - if (--mmu->count == 0) 314 - __i915_mmu_notifier_destroy(mmu); 315 - mutex_unlock(&obj->base.dev->struct_mutex); 316 - return ret; 317 431 } 318 432 319 433 #else ··· 371 413 372 414 return 0; 373 415 } 416 + 417 + static void 418 + i915_mmu_notifier_free(struct i915_mmu_notifier *mn, 419 + struct mm_struct *mm) 420 + { 421 + } 422 + 374 423 #endif 424 + 425 + static struct i915_mm_struct * 426 + __i915_mm_struct_find(struct drm_i915_private *dev_priv, struct mm_struct *real) 427 + { 428 + struct i915_mm_struct *mm; 429 + 430 + /* Protected by dev_priv->mm_lock */ 431 + hash_for_each_possible(dev_priv->mm_structs, mm, node, (unsigned long)real) 432 + if (mm->mm == real) 433 + return mm; 434 + 435 + return NULL; 436 + } 437 + 438 + static int 439 + i915_gem_userptr_init__mm_struct(struct drm_i915_gem_object *obj) 440 + { 441 + struct drm_i915_private *dev_priv = to_i915(obj->base.dev); 442 + struct i915_mm_struct *mm; 443 + int ret = 0; 444 + 445 + /* During release of the GEM object we hold the struct_mutex. This 446 + * precludes us from calling mmput() at that time as that may be 447 + * the last reference and so call exit_mmap(). exit_mmap() will 448 + * attempt to reap the vma, and if we were holding a GTT mmap 449 + * would then call drm_gem_vm_close() and attempt to reacquire 450 + * the struct mutex. So in order to avoid that recursion, we have 451 + * to defer releasing the mm reference until after we drop the 452 + * struct_mutex, i.e. we need to schedule a worker to do the clean 453 + * up. 454 + */ 455 + mutex_lock(&dev_priv->mm_lock); 456 + mm = __i915_mm_struct_find(dev_priv, current->mm); 457 + if (mm == NULL) { 458 + mm = kmalloc(sizeof(*mm), GFP_KERNEL); 459 + if (mm == NULL) { 460 + ret = -ENOMEM; 461 + goto out; 462 + } 463 + 464 + kref_init(&mm->kref); 465 + mm->dev = obj->base.dev; 466 + 467 + mm->mm = current->mm; 468 + atomic_inc(&current->mm->mm_count); 469 + 470 + mm->mn = NULL; 471 + 472 + /* Protected by dev_priv->mm_lock */ 473 + hash_add(dev_priv->mm_structs, 474 + &mm->node, (unsigned long)mm->mm); 475 + } else 476 + kref_get(&mm->kref); 477 + 478 + obj->userptr.mm = mm; 479 + out: 480 + mutex_unlock(&dev_priv->mm_lock); 481 + return ret; 482 + } 483 + 484 + static void 485 + __i915_mm_struct_free__worker(struct work_struct *work) 486 + { 487 + struct i915_mm_struct *mm = container_of(work, typeof(*mm), work); 488 + i915_mmu_notifier_free(mm->mn, mm->mm); 489 + mmdrop(mm->mm); 490 + kfree(mm); 491 + } 492 + 493 + static void 494 + __i915_mm_struct_free(struct kref *kref) 495 + { 496 + struct i915_mm_struct *mm = container_of(kref, typeof(*mm), kref); 497 + 498 + /* Protected by dev_priv->mm_lock */ 499 + hash_del(&mm->node); 500 + mutex_unlock(&to_i915(mm->dev)->mm_lock); 501 + 502 + INIT_WORK(&mm->work, __i915_mm_struct_free__worker); 503 + schedule_work(&mm->work); 504 + } 505 + 506 + static void 507 + i915_gem_userptr_release__mm_struct(struct drm_i915_gem_object *obj) 508 + { 509 + if (obj->userptr.mm == NULL) 510 + return; 511 + 512 + kref_put_mutex(&obj->userptr.mm->kref, 513 + __i915_mm_struct_free, 514 + &to_i915(obj->base.dev)->mm_lock); 515 + obj->userptr.mm = NULL; 516 + } 375 517 376 518 struct get_pages_work { 377 519 struct work_struct work; 378 520 struct drm_i915_gem_object *obj; 379 521 struct task_struct *task; 380 522 }; 381 - 382 523 383 524 #if IS_ENABLED(CONFIG_SWIOTLB) 384 525 #define swiotlb_active() swiotlb_nr_tbl() ··· 536 479 if (pvec == NULL) 537 480 pvec = drm_malloc_ab(num_pages, sizeof(struct page *)); 538 481 if (pvec != NULL) { 539 - struct mm_struct *mm = obj->userptr.mm; 482 + struct mm_struct *mm = obj->userptr.mm->mm; 540 483 541 484 down_read(&mm->mmap_sem); 542 485 while (pinned < num_pages) { ··· 602 545 603 546 pvec = NULL; 604 547 pinned = 0; 605 - if (obj->userptr.mm == current->mm) { 548 + if (obj->userptr.mm->mm == current->mm) { 606 549 pvec = kmalloc(num_pages*sizeof(struct page *), 607 550 GFP_TEMPORARY | __GFP_NOWARN | __GFP_NORETRY); 608 551 if (pvec == NULL) { ··· 708 651 i915_gem_userptr_release(struct drm_i915_gem_object *obj) 709 652 { 710 653 i915_gem_userptr_release__mmu_notifier(obj); 711 - 712 - if (obj->userptr.mm) { 713 - mmput(obj->userptr.mm); 714 - obj->userptr.mm = NULL; 715 - } 654 + i915_gem_userptr_release__mm_struct(obj); 716 655 } 717 656 718 657 static int 719 658 i915_gem_userptr_dmabuf_export(struct drm_i915_gem_object *obj) 720 659 { 721 - if (obj->userptr.mn) 660 + if (obj->userptr.mmu_object) 722 661 return 0; 723 662 724 663 return i915_gem_userptr_init__mmu_notifier(obj, 0); ··· 789 736 return -ENODEV; 790 737 } 791 738 792 - /* Allocate the new object */ 793 739 obj = i915_gem_object_alloc(dev); 794 740 if (obj == NULL) 795 741 return -ENOMEM; ··· 806 754 * at binding. This means that we need to hook into the mmu_notifier 807 755 * in order to detect if the mmu is destroyed. 808 756 */ 809 - ret = -ENOMEM; 810 - if ((obj->userptr.mm = get_task_mm(current))) 757 + ret = i915_gem_userptr_init__mm_struct(obj); 758 + if (ret == 0) 811 759 ret = i915_gem_userptr_init__mmu_notifier(obj, args->flags); 812 760 if (ret == 0) 813 761 ret = drm_gem_handle_create(file, &obj->base, &handle); ··· 824 772 int 825 773 i915_gem_init_userptr(struct drm_device *dev) 826 774 { 827 - #if defined(CONFIG_MMU_NOTIFIER) 828 775 struct drm_i915_private *dev_priv = to_i915(dev); 829 - hash_init(dev_priv->mmu_notifiers); 830 - #endif 776 + mutex_init(&dev_priv->mm_lock); 777 + hash_init(dev_priv->mm_structs); 831 778 return 0; 832 779 }
+8 -4
drivers/gpu/drm/i915/i915_reg.h
··· 334 334 #define GFX_OP_DESTBUFFER_INFO ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1) 335 335 #define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3)) 336 336 #define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2) 337 - #define SRC_COPY_BLT_CMD ((2<<29)|(0x43<<22)|4) 337 + 338 + #define COLOR_BLT_CMD (2<<29 | 0x40<<22 | (5-2)) 339 + #define SRC_COPY_BLT_CMD ((2<<29)|(0x43<<22)|4) 338 340 #define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6) 339 341 #define XY_MONO_SRC_COPY_IMM_BLT ((2<<29)|(0x71<<22)|5) 340 - #define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21) 341 - #define XY_SRC_COPY_BLT_WRITE_RGB (1<<20) 342 + #define BLT_WRITE_A (2<<20) 343 + #define BLT_WRITE_RGB (1<<20) 344 + #define BLT_WRITE_RGBA (BLT_WRITE_RGB | BLT_WRITE_A) 342 345 #define BLT_DEPTH_8 (0<<24) 343 346 #define BLT_DEPTH_16_565 (1<<24) 344 347 #define BLT_DEPTH_16_1555 (2<<24) 345 348 #define BLT_DEPTH_32 (3<<24) 346 - #define BLT_ROP_GXCOPY (0xcc<<16) 349 + #define BLT_ROP_SRC_COPY (0xcc<<16) 350 + #define BLT_ROP_COLOR_COPY (0xf0<<16) 347 351 #define XY_SRC_COPY_BLT_SRC_TILED (1<<15) /* 965+ only */ 348 352 #define XY_SRC_COPY_BLT_DST_TILED (1<<11) /* 965+ only */ 349 353 #define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2)
+39 -27
drivers/gpu/drm/i915/intel_ringbuffer.c
··· 1363 1363 1364 1364 /* Just userspace ABI convention to limit the wa batch bo to a resonable size */ 1365 1365 #define I830_BATCH_LIMIT (256*1024) 1366 + #define I830_TLB_ENTRIES (2) 1367 + #define I830_WA_SIZE max(I830_TLB_ENTRIES*4096, I830_BATCH_LIMIT) 1366 1368 static int 1367 1369 i830_dispatch_execbuffer(struct intel_engine_cs *ring, 1368 1370 u64 offset, u32 len, 1369 1371 unsigned flags) 1370 1372 { 1373 + u32 cs_offset = ring->scratch.gtt_offset; 1371 1374 int ret; 1372 1375 1373 - if (flags & I915_DISPATCH_PINNED) { 1374 - ret = intel_ring_begin(ring, 4); 1375 - if (ret) 1376 - return ret; 1376 + ret = intel_ring_begin(ring, 6); 1377 + if (ret) 1378 + return ret; 1377 1379 1378 - intel_ring_emit(ring, MI_BATCH_BUFFER); 1379 - intel_ring_emit(ring, offset | (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE)); 1380 - intel_ring_emit(ring, offset + len - 8); 1381 - intel_ring_emit(ring, MI_NOOP); 1382 - intel_ring_advance(ring); 1383 - } else { 1384 - u32 cs_offset = ring->scratch.gtt_offset; 1380 + /* Evict the invalid PTE TLBs */ 1381 + intel_ring_emit(ring, COLOR_BLT_CMD | BLT_WRITE_RGBA); 1382 + intel_ring_emit(ring, BLT_DEPTH_32 | BLT_ROP_COLOR_COPY | 4096); 1383 + intel_ring_emit(ring, I830_TLB_ENTRIES << 16 | 4); /* load each page */ 1384 + intel_ring_emit(ring, cs_offset); 1385 + intel_ring_emit(ring, 0xdeadbeef); 1386 + intel_ring_emit(ring, MI_NOOP); 1387 + intel_ring_advance(ring); 1385 1388 1389 + if ((flags & I915_DISPATCH_PINNED) == 0) { 1386 1390 if (len > I830_BATCH_LIMIT) 1387 1391 return -ENOSPC; 1388 1392 1389 - ret = intel_ring_begin(ring, 9+3); 1393 + ret = intel_ring_begin(ring, 6 + 2); 1390 1394 if (ret) 1391 1395 return ret; 1392 - /* Blit the batch (which has now all relocs applied) to the stable batch 1393 - * scratch bo area (so that the CS never stumbles over its tlb 1394 - * invalidation bug) ... */ 1395 - intel_ring_emit(ring, XY_SRC_COPY_BLT_CMD | 1396 - XY_SRC_COPY_BLT_WRITE_ALPHA | 1397 - XY_SRC_COPY_BLT_WRITE_RGB); 1398 - intel_ring_emit(ring, BLT_DEPTH_32 | BLT_ROP_GXCOPY | 4096); 1399 - intel_ring_emit(ring, 0); 1400 - intel_ring_emit(ring, (DIV_ROUND_UP(len, 4096) << 16) | 1024); 1396 + 1397 + /* Blit the batch (which has now all relocs applied) to the 1398 + * stable batch scratch bo area (so that the CS never 1399 + * stumbles over its tlb invalidation bug) ... 1400 + */ 1401 + intel_ring_emit(ring, SRC_COPY_BLT_CMD | BLT_WRITE_RGBA); 1402 + intel_ring_emit(ring, BLT_DEPTH_32 | BLT_ROP_SRC_COPY | 4096); 1403 + intel_ring_emit(ring, DIV_ROUND_UP(len, 4096) << 16 | 1024); 1401 1404 intel_ring_emit(ring, cs_offset); 1402 - intel_ring_emit(ring, 0); 1403 1405 intel_ring_emit(ring, 4096); 1404 1406 intel_ring_emit(ring, offset); 1407 + 1405 1408 intel_ring_emit(ring, MI_FLUSH); 1409 + intel_ring_emit(ring, MI_NOOP); 1410 + intel_ring_advance(ring); 1406 1411 1407 1412 /* ... and execute it. */ 1408 - intel_ring_emit(ring, MI_BATCH_BUFFER); 1409 - intel_ring_emit(ring, cs_offset | (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE)); 1410 - intel_ring_emit(ring, cs_offset + len - 8); 1411 - intel_ring_advance(ring); 1413 + offset = cs_offset; 1412 1414 } 1415 + 1416 + ret = intel_ring_begin(ring, 4); 1417 + if (ret) 1418 + return ret; 1419 + 1420 + intel_ring_emit(ring, MI_BATCH_BUFFER); 1421 + intel_ring_emit(ring, offset | (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE)); 1422 + intel_ring_emit(ring, offset + len - 8); 1423 + intel_ring_emit(ring, MI_NOOP); 1424 + intel_ring_advance(ring); 1413 1425 1414 1426 return 0; 1415 1427 } ··· 2212 2200 2213 2201 /* Workaround batchbuffer to combat CS tlb bug. */ 2214 2202 if (HAS_BROKEN_CS_TLB(dev)) { 2215 - obj = i915_gem_alloc_object(dev, I830_BATCH_LIMIT); 2203 + obj = i915_gem_alloc_object(dev, I830_WA_SIZE); 2216 2204 if (obj == NULL) { 2217 2205 DRM_ERROR("Failed to allocate batch bo\n"); 2218 2206 return -ENOMEM;
+4
drivers/gpu/drm/i915/intel_tv.c
··· 854 854 struct drm_device *dev = encoder->base.dev; 855 855 struct drm_i915_private *dev_priv = dev->dev_private; 856 856 857 + /* Prevents vblank waits from timing out in intel_tv_detect_type() */ 858 + intel_wait_for_vblank(encoder->base.dev, 859 + to_intel_crtc(encoder->base.crtc)->pipe); 860 + 857 861 I915_WRITE(TV_CTL, I915_READ(TV_CTL) | TV_ENC_ENABLE); 858 862 } 859 863