Project

General

Profile

Bug #2733 » 0001-drm-i915-revert-part-of-Make-the-GEM-code-more-Linux.patch

Reverts part of commit d1c259eee6a290aadce1c78a746e131034aba76 - ftigeot, 11/22/2014 01:30 PM

View differences:

sys/dev/drm/i915/i915_gem.c
418 418
	return ret;
419 419
}
420 420

  
421
/**
422
 * This is the fast pwrite path, where we copy the data directly from the
423
 * user into the GTT, uncached.
424
 */
425 421
static int
426
i915_gem_gtt_pwrite_fast(struct drm_device *dev,
427
			 struct drm_i915_gem_object *obj,
428
			 struct drm_i915_gem_pwrite *args,
429
			 struct drm_file *file)
422
i915_gem_gtt_write(struct drm_device *dev, struct drm_i915_gem_object *obj,
423
    uint64_t data_ptr, uint64_t size, uint64_t offset, struct drm_file *file)
430 424
{
431 425
	vm_offset_t mkva;
432 426
	int ret;
......
438 432
	 * add the page offset into the returned mkva for us.
439 433
	 */
440 434
	mkva = (vm_offset_t)pmap_mapdev_attr(dev->agp->base + obj->gtt_offset +
441
	    args->offset, args->size, PAT_WRITE_COMBINING);
442
	ret = -copyin_nofault((void *)(uintptr_t)args->data_ptr, (char *)mkva, args->size);
443
	pmap_unmapdev(mkva, args->size);
444

  
435
	    offset, size, PAT_WRITE_COMBINING);
436
	ret = -copyin_nofault((void *)(uintptr_t)data_ptr, (char *)mkva, size);
437
	pmap_unmapdev(mkva, size);
445 438
	return ret;
446 439
}
447 440

  
......
525 518
{
526 519
	struct drm_i915_gem_pwrite *args = data;
527 520
	struct drm_i915_gem_object *obj;
528
	int ret;
521
	vm_page_t *ma;
522
	vm_offset_t start, end;
523
	int npages, ret;
529 524

  
530 525
	if (args->size == 0)
531 526
		return 0;
532 527

  
528
	start = trunc_page(args->data_ptr);
529
	end = round_page(args->data_ptr + args->size);
530
	npages = howmany(end - start, PAGE_SIZE);
531
	ma = kmalloc(npages * sizeof(vm_page_t), M_DRM, M_WAITOK |
532
	    M_ZERO);
533
	npages = vm_fault_quick_hold_pages(&curproc->p_vmspace->vm_map,
534
	    (vm_offset_t)args->data_ptr, args->size,
535
	    VM_PROT_READ, ma, npages);
536
	if (npages == -1) {
537
		ret = -EFAULT;
538
		goto free_ma;
539
	}
540

  
533 541
	ret = i915_mutex_lock_interruptible(dev);
534
	if (ret)
535
		return ret;
542
	if (ret != 0)
543
		goto unlocked;
536 544

  
537 545
	obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
538 546
	if (&obj->base == NULL) {
......
547 555
		goto out;
548 556
	}
549 557

  
550
	ret = -EFAULT;
551
	/* We can only do the GTT pwrite on untiled buffers, as otherwise
552
	 * it would end up going through the fenced access, and we'll get
553
	 * different detiling behavior between reading and writing.
554
	 * pread/pwrite currently are reading and writing from the CPU
555
	 * perspective, requiring manual detiling by the client.
556
	 */
557 558
	if (obj->phys_obj) {
558 559
		ret = i915_gem_phys_pwrite(dev, obj, args, file);
559
		goto out;
560
	}
561

  
562
	if (obj->cache_level == I915_CACHE_NONE &&
563
	    obj->tiling_mode == I915_TILING_NONE &&
564
	    obj->base.write_domain != I915_GEM_DOMAIN_CPU) {
565
		ret = i915_gem_gtt_pwrite_fast(dev, obj, args, file);
566
		/* Note that the gtt paths might fail with non-page-backed user
567
		 * pointers (e.g. gtt mappings when moving data between
568
		 * textures). Fallback to the shmem path in that case. */
569
	}
570

  
571
	if (ret == -EFAULT || ret == -ENOSPC)
560
	} else if (obj->gtt_space &&
561
		    obj->base.write_domain != I915_GEM_DOMAIN_CPU) {
562
		ret = i915_gem_object_pin(obj, 0, true, false);
563
		if (ret != 0)
564
			goto out;
565
		ret = i915_gem_object_set_to_gtt_domain(obj, true);
566
		if (ret != 0)
567
			goto out_unpin;
568
		ret = i915_gem_object_put_fence(obj);
569
		if (ret != 0)
570
			goto out_unpin;
571
		ret = i915_gem_gtt_write(dev, obj, args->data_ptr, args->size,
572
		    args->offset, file);
573
out_unpin:
574
		i915_gem_object_unpin(obj);
575
	} else {
576
		ret = i915_gem_object_set_to_cpu_domain(obj, true);
577
		if (ret != 0)
578
			goto out;
572 579
		ret = i915_gem_shmem_pwrite(dev, obj, args, file);
573

  
580
	}
574 581
out:
575 582
	drm_gem_object_unreference(&obj->base);
576 583
unlock:
577 584
	DRM_UNLOCK(dev);
585
unlocked:
586
	vm_page_unhold_pages(ma, npages);
587
free_ma:
588
	drm_free(ma, M_DRM);
578 589
	return ret;
579 590
}
580 591

  
(3-3/3)