Subversion Repositories Kolibri OS

Rev

Rev 5367 | Rev 6296 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5367 Rev 6084
Line 250... Line 250...
250
 
250
 
251
static inline int use_cpu_reloc(struct drm_i915_gem_object *obj)
251
static inline int use_cpu_reloc(struct drm_i915_gem_object *obj)
252
{
252
{
253
	return (HAS_LLC(obj->base.dev) ||
253
	return (HAS_LLC(obj->base.dev) ||
254
		obj->base.write_domain == I915_GEM_DOMAIN_CPU ||
-
 
255
		!obj->map_and_fenceable ||
254
		obj->base.write_domain == I915_GEM_DOMAIN_CPU ||
256
		obj->cache_level != I915_CACHE_NONE);
255
		obj->cache_level != I915_CACHE_NONE);
Line 257... Line 256...
257
}
256
}
258
 
257
 
Line 318... Line 317...
318
    MapPage(dev_priv->gtt.mappable,dev_priv->gtt.mappable_base +
317
    MapPage(dev_priv->gtt.mappable,dev_priv->gtt.mappable_base +
319
                                 (offset & PAGE_MASK), PG_SW);
318
                                 (offset & PAGE_MASK), PG_SW);
320
	reloc_page = dev_priv->gtt.mappable;
319
	reloc_page = dev_priv->gtt.mappable;
321
	iowrite32(lower_32_bits(delta), reloc_page + offset_in_page(offset));
320
	iowrite32(lower_32_bits(delta), reloc_page + offset_in_page(offset));
Line -... Line 321...
-
 
321
 
Line -... Line 322...
-
 
322
//	io_mapping_unmap_atomic(reloc_page);
-
 
323
 
-
 
324
	return 0;
-
 
325
}
-
 
326
 
-
 
327
static void
-
 
328
clflush_write32(void *addr, uint32_t value)
-
 
329
{
-
 
330
	/* This is not a fast path, so KISS. */
-
 
331
	drm_clflush_virt_range(addr, sizeof(uint32_t));
-
 
332
	*(uint32_t *)addr = value;
-
 
333
	drm_clflush_virt_range(addr, sizeof(uint32_t));
-
 
334
}
-
 
335
 
-
 
336
static int
-
 
337
relocate_entry_clflush(struct drm_i915_gem_object *obj,
-
 
338
		       struct drm_i915_gem_relocation_entry *reloc,
-
 
339
		       uint64_t target_offset)
-
 
340
{
-
 
341
	struct drm_device *dev = obj->base.dev;
-
 
342
	uint32_t page_offset = offset_in_page(reloc->offset);
-
 
343
	uint64_t delta = (int)reloc->delta + target_offset;
-
 
344
	char *vaddr;
-
 
345
	int ret;
-
 
346
 
-
 
347
	ret = i915_gem_object_set_to_gtt_domain(obj, true);
-
 
348
	if (ret)
-
 
349
		return ret;
-
 
350
 
-
 
351
	vaddr = kmap_atomic(i915_gem_object_get_page(obj,
-
 
352
				reloc->offset >> PAGE_SHIFT));
-
 
353
	clflush_write32(vaddr + page_offset, lower_32_bits(delta));
-
 
354
 
-
 
355
	if (INTEL_INFO(dev)->gen >= 8) {
-
 
356
		page_offset = offset_in_page(page_offset + sizeof(uint32_t));
-
 
357
 
-
 
358
		if (page_offset == 0) {
-
 
359
			kunmap_atomic(vaddr);
-
 
360
			vaddr = kmap_atomic(i915_gem_object_get_page(obj,
-
 
361
			    (reloc->offset + sizeof(uint32_t)) >> PAGE_SHIFT));
-
 
362
		}
-
 
363
 
-
 
364
		clflush_write32(vaddr + page_offset, upper_32_bits(delta));
-
 
365
	}
Line 322... Line 366...
322
 
366
 
323
 
367
	kunmap_atomic(vaddr);
Line 324... Line 368...
324
 
368
 
Line 348... Line 392...
348
 
392
 
349
	/* Sandybridge PPGTT errata: We need a global gtt mapping for MI and
393
	/* Sandybridge PPGTT errata: We need a global gtt mapping for MI and
350
	 * pipe_control writes because the gpu doesn't properly redirect them
394
	 * pipe_control writes because the gpu doesn't properly redirect them
351
	 * through the ppgtt for non_secure batchbuffers. */
395
	 * through the ppgtt for non_secure batchbuffers. */
352
	if (unlikely(IS_GEN6(dev) &&
396
	if (unlikely(IS_GEN6(dev) &&
353
	    reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION &&
-
 
354
	    !(target_vma->bound & GLOBAL_BIND)))
397
	    reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION)) {
355
		target_vma->bind_vma(target_vma, target_i915_obj->cache_level,
398
		ret = i915_vma_bind(target_vma, target_i915_obj->cache_level,
-
 
399
				    PIN_GLOBAL);
-
 
400
		if (WARN_ONCE(ret, "Unexpected failure to bind target VMA!"))
-
 
401
			return ret;
Line 356... Line 402...
356
				GLOBAL_BIND);
402
	}
357
 
403
 
358
	/* Validate that the target is in a valid r/w GPU domain */
404
	/* Validate that the target is in a valid r/w GPU domain */
359
	if (unlikely(reloc->write_domain & (reloc->write_domain - 1))) {
405
	if (unlikely(reloc->write_domain & (reloc->write_domain - 1))) {
Line 407... Line 453...
407
 
453
 
Line 408... Line 454...
408
	/* We can't wait for rendering with pagefaults disabled */
454
	/* We can't wait for rendering with pagefaults disabled */
409
 
455
 
410
	if (use_cpu_reloc(obj))
456
	if (use_cpu_reloc(obj))
411
		ret = relocate_entry_cpu(obj, reloc, target_offset);
457
		ret = relocate_entry_cpu(obj, reloc, target_offset);
-
 
458
	else if (obj->map_and_fenceable)
-
 
459
		ret = relocate_entry_gtt(obj, reloc, target_offset);
-
 
460
    else if (1)
-
 
461
		ret = relocate_entry_clflush(obj, reloc, target_offset);
-
 
462
	else {
-
 
463
		WARN_ONCE(1, "Impossible case in relocation handling\n");
Line 412... Line 464...
412
	else
464
		ret = -ENODEV;
413
		ret = relocate_entry_gtt(obj, reloc, target_offset);
465
	}
Line 414... Line 466...
414
 
466
 
Line 505... Line 557...
505
//   pagefault_enable();
557
//   pagefault_enable();
Line 506... Line 558...
506
 
558
 
507
	return ret;
559
	return ret;
Line -... Line 560...
-
 
560
}
-
 
561
 
-
 
562
static bool only_mappable_for_reloc(unsigned int flags)
-
 
563
{
-
 
564
	return (flags & (EXEC_OBJECT_NEEDS_FENCE | __EXEC_OBJECT_NEEDS_MAP)) ==
-
 
565
		__EXEC_OBJECT_NEEDS_MAP;
508
}
566
}
509
 
567
 
510
static int
568
static int
511
i915_gem_execbuffer_reserve_vma(struct i915_vma *vma,
569
i915_gem_execbuffer_reserve_vma(struct i915_vma *vma,
512
				struct intel_engine_cs *ring,
570
				struct intel_engine_cs *ring,
513
				   bool *need_reloc)
571
				bool *need_reloc)
514
{
572
{
515
	struct drm_i915_gem_object *obj = vma->obj;
573
	struct drm_i915_gem_object *obj = vma->obj;
516
	struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
574
	struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
Line 517... Line 575...
517
	uint64_t flags;
575
	uint64_t flags;
518
	int ret;
-
 
519
 
-
 
520
	flags = 0;
576
	int ret;
521
	if (entry->flags & __EXEC_OBJECT_NEEDS_MAP)
577
 
-
 
578
	flags = PIN_USER;
-
 
579
	if (entry->flags & EXEC_OBJECT_NEEDS_GTT)
-
 
580
		flags |= PIN_GLOBAL;
-
 
581
 
-
 
582
	if (!drm_mm_node_allocated(&vma->node)) {
-
 
583
		/* Wa32bitGeneralStateOffset & Wa32bitInstructionBaseOffset,
-
 
584
		 * limit address to the first 4GBs for unflagged objects.
-
 
585
		 */
-
 
586
		if ((entry->flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS) == 0)
522
		flags |= PIN_GLOBAL | PIN_MAPPABLE;
587
			flags |= PIN_ZONE_4G;
523
	if (entry->flags & EXEC_OBJECT_NEEDS_GTT)
588
		if (entry->flags & __EXEC_OBJECT_NEEDS_MAP)
-
 
589
			flags |= PIN_GLOBAL | PIN_MAPPABLE;
-
 
590
		if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS)
-
 
591
			flags |= BATCH_OFFSET_BIAS | PIN_OFFSET_BIAS;
Line 524... Line 592...
524
		flags |= PIN_GLOBAL;
592
		if ((flags & PIN_MAPPABLE) == 0)
-
 
593
			flags |= PIN_HIGH;
-
 
594
	}
-
 
595
 
-
 
596
	ret = i915_gem_object_pin(obj, vma->vm, entry->alignment, flags);
-
 
597
	if ((ret == -ENOSPC  || ret == -E2BIG) &&
525
	if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS)
598
	    only_mappable_for_reloc(entry->flags))
526
		flags |= BATCH_OFFSET_BIAS | PIN_OFFSET_BIAS;
599
		ret = i915_gem_object_pin(obj, vma->vm,
Line 527... Line 600...
527
 
600
					  entry->alignment,
Line 585... Line 658...
585
 
658
 
586
	if (entry->alignment &&
659
	if (entry->alignment &&
587
	    vma->node.start & (entry->alignment - 1))
660
	    vma->node.start & (entry->alignment - 1))
Line 588... Line -...
588
		return true;
-
 
589
 
-
 
590
	if (entry->flags & __EXEC_OBJECT_NEEDS_MAP && !obj->map_and_fenceable)
-
 
591
		return true;
661
		return true;
592
 
662
 
593
	if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS &&
663
	if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS &&
Line -... Line 664...
-
 
664
	    vma->node.start < BATCH_OFFSET_BIAS)
-
 
665
		return true;
-
 
666
 
-
 
667
	/* avoid costly ping-pong once a batch bo ended up non-mappable */
-
 
668
	if (entry->flags & __EXEC_OBJECT_NEEDS_MAP && !obj->map_and_fenceable)
-
 
669
		return !only_mappable_for_reloc(entry->flags);
-
 
670
 
-
 
671
	if ((entry->flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS) == 0 &&
594
	    vma->node.start < BATCH_OFFSET_BIAS)
672
	    (vma->node.start + vma->node.size - 1) >> 32)
595
		return true;
673
		return true;
Line 596... Line 674...
596
 
674
 
597
	return false;
675
	return false;
598
}
676
}
-
 
677
 
599
 
678
static int
600
static int
679
i915_gem_execbuffer_reserve(struct intel_engine_cs *ring,
601
i915_gem_execbuffer_reserve(struct intel_engine_cs *ring,
680
			    struct list_head *vmas,
602
			    struct list_head *vmas,
681
			    struct intel_context *ctx,
603
			    bool *need_relocs)
682
			    bool *need_relocs)
Line 620... Line 699...
620
 
699
 
621
		vma = list_first_entry(vmas, struct i915_vma, exec_list);
700
		vma = list_first_entry(vmas, struct i915_vma, exec_list);
622
		obj = vma->obj;
701
		obj = vma->obj;
Line -... Line 702...
-
 
702
		entry = vma->exec_entry;
-
 
703
 
-
 
704
		if (ctx->flags & CONTEXT_NO_ZEROMAP)
623
		entry = vma->exec_entry;
705
			entry->flags |= __EXEC_OBJECT_NEEDS_BIAS;
624
 
706
 
625
		if (!has_fenced_gpu_access)
707
		if (!has_fenced_gpu_access)
626
			entry->flags &= ~EXEC_OBJECT_NEEDS_FENCE;
708
			entry->flags &= ~EXEC_OBJECT_NEEDS_FENCE;
627
		need_fence =
709
		need_fence =
Line 697... Line 779...
697
i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
779
i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
698
				  struct drm_i915_gem_execbuffer2 *args,
780
				  struct drm_i915_gem_execbuffer2 *args,
699
				  struct drm_file *file,
781
				  struct drm_file *file,
700
				  struct intel_engine_cs *ring,
782
				  struct intel_engine_cs *ring,
701
				  struct eb_vmas *eb,
783
				  struct eb_vmas *eb,
702
				  struct drm_i915_gem_exec_object2 *exec)
784
				  struct drm_i915_gem_exec_object2 *exec,
-
 
785
				  struct intel_context *ctx)
703
{
786
{
704
	struct drm_i915_gem_relocation_entry *reloc;
787
	struct drm_i915_gem_relocation_entry *reloc;
705
	struct i915_address_space *vm;
788
	struct i915_address_space *vm;
706
	struct i915_vma *vma;
789
	struct i915_vma *vma;
707
	bool need_relocs;
790
	bool need_relocs;
Line 723... Line 806...
723
 
806
 
724
	total = 0;
807
	total = 0;
725
	for (i = 0; i < count; i++)
808
	for (i = 0; i < count; i++)
Line 726... Line 809...
726
		total += exec[i].relocation_count;
809
		total += exec[i].relocation_count;
727
 
810
 
728
    reloc_offset = malloc(count * sizeof(*reloc_offset));
811
    reloc_offset = __builtin_malloc(count * sizeof(*reloc_offset));
729
    reloc = malloc(total * sizeof(*reloc));
812
    reloc = __builtin_malloc(total * sizeof(*reloc));
730
	if (reloc == NULL || reloc_offset == NULL) {
813
	if (reloc == NULL || reloc_offset == NULL) {
731
        kfree(reloc);
814
        kfree(reloc);
732
        kfree(reloc_offset);
815
        kfree(reloc_offset);
Line 783... Line 866...
783
	ret = eb_lookup_vmas(eb, exec, args, vm, file);
866
	ret = eb_lookup_vmas(eb, exec, args, vm, file);
784
	if (ret)
867
	if (ret)
785
			goto err;
868
		goto err;
Line 786... Line 869...
786
 
869
 
787
	need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0;
870
	need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0;
788
	ret = i915_gem_execbuffer_reserve(ring, &eb->vmas, &need_relocs);
871
	ret = i915_gem_execbuffer_reserve(ring, &eb->vmas, ctx, &need_relocs);
789
	if (ret)
872
	if (ret)
Line 790... Line 873...
790
		goto err;
873
		goto err;
791
 
874
 
Line 808... Line 891...
808
    kfree(reloc_offset);
891
    kfree(reloc_offset);
809
	return ret;
892
	return ret;
810
}
893
}
Line 811... Line 894...
811
 
894
 
812
static int
895
static int
813
i915_gem_execbuffer_move_to_gpu(struct intel_engine_cs *ring,
896
i915_gem_execbuffer_move_to_gpu(struct drm_i915_gem_request *req,
814
				struct list_head *vmas)
897
				struct list_head *vmas)
-
 
898
{
815
{
899
	const unsigned other_rings = ~intel_ring_flag(req->ring);
816
	struct i915_vma *vma;
900
	struct i915_vma *vma;
817
	uint32_t flush_domains = 0;
901
	uint32_t flush_domains = 0;
818
	bool flush_chipset = false;
902
	bool flush_chipset = false;
Line 819... Line 903...
819
	int ret;
903
	int ret;
820
 
904
 
-
 
905
	list_for_each_entry(vma, vmas, exec_list) {
-
 
906
		struct drm_i915_gem_object *obj = vma->obj;
821
	list_for_each_entry(vma, vmas, exec_list) {
907
 
822
		struct drm_i915_gem_object *obj = vma->obj;
908
		if (obj->active & other_rings) {
823
		ret = i915_gem_object_sync(obj, ring);
909
			ret = i915_gem_object_sync(obj, req->ring, &req);
-
 
910
			if (ret)
Line 824... Line 911...
824
		if (ret)
911
				return ret;
825
			return ret;
912
		}
Line 826... Line 913...
826
 
913
 
827
		if (obj->base.write_domain & I915_GEM_DOMAIN_CPU)
914
		if (obj->base.write_domain & I915_GEM_DOMAIN_CPU)
Line 828... Line 915...
828
			flush_chipset |= i915_gem_clflush_object(obj, false);
915
			flush_chipset |= i915_gem_clflush_object(obj, false);
829
 
916
 
Line 830... Line 917...
830
		flush_domains |= obj->base.write_domain;
917
		flush_domains |= obj->base.write_domain;
831
	}
918
	}
Line 832... Line 919...
832
 
919
 
833
	if (flush_chipset)
920
	if (flush_chipset)
834
		i915_gem_chipset_flush(ring->dev);
921
		i915_gem_chipset_flush(req->ring->dev);
835
 
922
 
836
	if (flush_domains & I915_GEM_DOMAIN_GTT)
923
	if (flush_domains & I915_GEM_DOMAIN_GTT)
Line 837... Line 924...
837
		wmb();
924
		wmb();
838
 
925
 
839
	/* Unconditionally invalidate gpu caches and ensure that we do flush
926
	/* Unconditionally invalidate gpu caches and ensure that we do flush
840
	 * any residual writes from the previous batch.
927
	 * any residual writes from the previous batch.
841
	 */
928
	 */
Line -... Line 929...
-
 
929
	return intel_ring_invalidate_all_caches(req);
-
 
930
}
-
 
931
 
-
 
932
static bool
-
 
933
i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
-
 
934
{
-
 
935
	if (exec->flags & __I915_EXEC_UNKNOWN_FLAGS)
-
 
936
		return false;
-
 
937
 
-
 
938
	/* Kernel clipping was a DRI1 misfeature */
-
 
939
	if (exec->num_cliprects || exec->cliprects_ptr)
842
	return intel_ring_invalidate_all_caches(ring);
940
		return false;
-
 
941
 
-
 
942
	if (exec->DR4 == 0xffffffff) {
-
 
943
		DRM_DEBUG("UXA submitting garbage DR4, fixing up\n");
843
}
944
		exec->DR4 = 0;
Line 844... Line 945...
844
 
945
	}
845
static bool
946
	if (exec->DR1 || exec->DR4)
846
i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
947
		return false;
Line 870... Line 971...
870
		int length; /* limited by fault_in_pages_readable() */
971
		int length; /* limited by fault_in_pages_readable() */
Line 871... Line 972...
871
 
972
 
872
		if (exec[i].flags & invalid_flags)
973
		if (exec[i].flags & invalid_flags)
Line -... Line 974...
-
 
974
			return -EINVAL;
-
 
975
 
-
 
976
		if (exec[i].alignment && !is_power_of_2(exec[i].alignment))
873
			return -EINVAL;
977
			return -EINVAL;
874
 
978
 
875
		/* First check for malicious input causing overflow in
979
		/* First check for malicious input causing overflow in
876
		 * the worst case where we need to allocate the entire
980
		 * the worst case where we need to allocate the entire
877
		 * relocation tree as a single array.
981
		 * relocation tree as a single array.
Line 911... Line 1015...
911
		DRM_DEBUG("Context %u tried to submit while banned\n", ctx_id);
1015
		DRM_DEBUG("Context %u tried to submit while banned\n", ctx_id);
912
		return ERR_PTR(-EIO);
1016
		return ERR_PTR(-EIO);
913
	}
1017
	}
Line 914... Line 1018...
914
 
1018
 
915
	if (i915.enable_execlists && !ctx->engine[ring->id].state) {
1019
	if (i915.enable_execlists && !ctx->engine[ring->id].state) {
916
		int ret = intel_lr_context_deferred_create(ctx, ring);
1020
		int ret = intel_lr_context_deferred_alloc(ctx, ring);
917
		if (ret) {
1021
		if (ret) {
918
			DRM_DEBUG("Could not create LRC %u: %d\n", ctx_id, ret);
1022
			DRM_DEBUG("Could not create LRC %u: %d\n", ctx_id, ret);
919
			return ERR_PTR(ret);
1023
			return ERR_PTR(ret);
920
		}
1024
		}
Line 923... Line 1027...
923
	return ctx;
1027
	return ctx;
924
}
1028
}
Line 925... Line 1029...
925
 
1029
 
926
void
1030
void
927
i915_gem_execbuffer_move_to_active(struct list_head *vmas,
1031
i915_gem_execbuffer_move_to_active(struct list_head *vmas,
928
				   struct intel_engine_cs *ring)
1032
				   struct drm_i915_gem_request *req)
929
{
1033
{
930
	u32 seqno = intel_ring_get_seqno(ring);
1034
	struct intel_engine_cs *ring = i915_gem_request_get_ring(req);
Line 931... Line 1035...
931
	struct i915_vma *vma;
1035
	struct i915_vma *vma;
932
 
1036
 
933
	list_for_each_entry(vma, vmas, exec_list) {
1037
	list_for_each_entry(vma, vmas, exec_list) {
934
		struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
1038
		struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
935
		struct drm_i915_gem_object *obj = vma->obj;
1039
		struct drm_i915_gem_object *obj = vma->obj;
Line -... Line 1040...
-
 
1040
		u32 old_read = obj->base.read_domains;
936
		u32 old_read = obj->base.read_domains;
1041
		u32 old_write = obj->base.write_domain;
937
		u32 old_write = obj->base.write_domain;
1042
 
938
 
1043
		obj->dirty = 1; /* be paranoid  */
939
		obj->base.write_domain = obj->base.pending_write_domain;
1044
		obj->base.write_domain = obj->base.pending_write_domain;
Line 940... Line 1045...
940
		if (obj->base.write_domain == 0)
1045
		if (obj->base.write_domain == 0)
941
			obj->base.pending_read_domains |= obj->base.read_domains;
1046
			obj->base.pending_read_domains |= obj->base.read_domains;
942
		obj->base.read_domains = obj->base.pending_read_domains;
-
 
943
 
1047
		obj->base.read_domains = obj->base.pending_read_domains;
Line 944... Line 1048...
944
		i915_vma_move_to_active(vma, ring);
1048
 
Line 945... Line 1049...
945
		if (obj->base.write_domain) {
1049
		i915_vma_move_to_active(vma, req);
946
			obj->dirty = 1;
1050
		if (obj->base.write_domain) {
947
			obj->last_write_seqno = seqno;
1051
			i915_gem_request_assign(&obj->last_write_req, req);
948
 
1052
 
949
			intel_fb_obj_invalidate(obj, ring);
1053
			intel_fb_obj_invalidate(obj, ORIGIN_CS);
950
 
1054
 
951
			/* update for the implicit flush after a batch */
1055
			/* update for the implicit flush after a batch */
952
			obj->base.write_domain &= ~I915_GEM_GPU_DOMAINS;
1056
			obj->base.write_domain &= ~I915_GEM_GPU_DOMAINS;
953
		}
1057
		}
954
		if (entry->flags & EXEC_OBJECT_NEEDS_FENCE) {
1058
		if (entry->flags & EXEC_OBJECT_NEEDS_FENCE) {
Line 963... Line 1067...
963
		trace_i915_gem_object_change_domain(obj, old_read, old_write);
1067
		trace_i915_gem_object_change_domain(obj, old_read, old_write);
964
	}
1068
	}
965
}
1069
}
Line 966... Line 1070...
966
 
1070
 
967
void
1071
void
968
i915_gem_execbuffer_retire_commands(struct drm_device *dev,
-
 
969
				    struct drm_file *file,
-
 
970
				    struct intel_engine_cs *ring,
-
 
971
				    struct drm_i915_gem_object *obj)
1072
i915_gem_execbuffer_retire_commands(struct i915_execbuffer_params *params)
972
{
1073
{
973
	/* Unconditionally force add_request to emit a full flush. */
1074
	/* Unconditionally force add_request to emit a full flush. */
Line 974... Line 1075...
974
	ring->gpu_caches_dirty = true;
1075
	params->ring->gpu_caches_dirty = true;
975
 
1076
 
976
	/* Add a breadcrumb for the completion of the batch buffer */
1077
	/* Add a breadcrumb for the completion of the batch buffer */
Line 977... Line 1078...
977
	(void)__i915_add_request(ring, file, obj, NULL);
1078
	__i915_add_request(params->request, params->batch_obj, true);
978
}
1079
}
979
 
1080
 
980
static int
1081
static int
-
 
1082
i915_reset_gen7_sol_offsets(struct drm_device *dev,
981
i915_reset_gen7_sol_offsets(struct drm_device *dev,
1083
			    struct drm_i915_gem_request *req)
982
			    struct intel_engine_cs *ring)
1084
{
Line 983... Line 1085...
983
{
1085
	struct intel_engine_cs *ring = req->ring;
984
	struct drm_i915_private *dev_priv = dev->dev_private;
1086
	struct drm_i915_private *dev_priv = dev->dev_private;
985
	int ret, i;
1087
	int ret, i;
986
 
1088
 
Line 987... Line 1089...
987
	if (!IS_GEN7(dev) || ring != &dev_priv->ring[RCS]) {
1089
	if (!IS_GEN7(dev) || ring != &dev_priv->ring[RCS]) {
988
		DRM_DEBUG("sol reset is gen7/rcs only\n");
1090
		DRM_DEBUG("sol reset is gen7/rcs only\n");
989
		return -EINVAL;
1091
		return -EINVAL;
Line 990... Line 1092...
990
	}
1092
	}
991
 
1093
 
Line 1002... Line 1104...
1002
	intel_ring_advance(ring);
1104
	intel_ring_advance(ring);
Line 1003... Line 1105...
1003
 
1105
 
1004
	return 0;
1106
	return 0;
Line 1005... Line 1107...
1005
}
1107
}
1006
 
1108
 
-
 
1109
static struct drm_i915_gem_object*
-
 
1110
i915_gem_execbuffer_parse(struct intel_engine_cs *ring,
1007
static int
1111
			  struct drm_i915_gem_exec_object2 *shadow_exec_entry,
-
 
1112
			  struct eb_vmas *eb,
-
 
1113
			  struct drm_i915_gem_object *batch_obj,
1008
i915_emit_box(struct intel_engine_cs *ring,
1114
			  u32 batch_start_offset,
1009
	      struct drm_clip_rect *box,
1115
			  u32 batch_len,
-
 
1116
			  bool is_master)
-
 
1117
{
1010
	      int DR1, int DR4)
1118
	struct drm_i915_gem_object *shadow_batch_obj;
Line 1011... Line 1119...
1011
{
1119
	struct i915_vma *vma;
1012
	int ret;
1120
	int ret;
1013
 
1121
 
1014
	if (box->y2 <= box->y1 || box->x2 <= box->x1 ||
-
 
1015
	    box->y2 <= 0 || box->x2 <= 0) {
1122
	shadow_batch_obj = i915_gem_batch_pool_get(&ring->batch_pool,
1016
		DRM_ERROR("Bad box %d,%d..%d,%d\n",
-
 
Line 1017... Line 1123...
1017
			  box->x1, box->y1, box->x2, box->y2);
1123
						   PAGE_ALIGN(batch_len));
-
 
1124
	if (IS_ERR(shadow_batch_obj))
1018
		return -EINVAL;
1125
		return shadow_batch_obj;
-
 
1126
 
-
 
1127
	ret = i915_parse_cmds(ring,
-
 
1128
			      batch_obj,
1019
	}
1129
			      shadow_batch_obj,
1020
 
1130
			      batch_start_offset,
Line 1021... Line -...
1021
	if (INTEL_INFO(ring->dev)->gen >= 4) {
-
 
1022
		ret = intel_ring_begin(ring, 4);
-
 
1023
		if (ret)
-
 
1024
			return ret;
-
 
1025
 
-
 
1026
		intel_ring_emit(ring, GFX_OP_DRAWRECT_INFO_I965);
1131
			      batch_len,
1027
		intel_ring_emit(ring, (box->x1 & 0xffff) | box->y1 << 16);
1132
			      is_master);
1028
		intel_ring_emit(ring, ((box->x2 - 1) & 0xffff) | (box->y2 - 1) << 16);
1133
	if (ret)
Line 1029... Line 1134...
1029
		intel_ring_emit(ring, DR4);
1134
		goto err;
1030
	} else {
-
 
1031
		ret = intel_ring_begin(ring, 6);
-
 
1032
		if (ret)
-
 
1033
			return ret;
-
 
1034
 
-
 
1035
		intel_ring_emit(ring, GFX_OP_DRAWRECT_INFO);
-
 
1036
		intel_ring_emit(ring, DR1);
-
 
Line -... Line 1135...
-
 
1135
 
-
 
1136
	ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 0, 0);
-
 
1137
	if (ret)
1037
		intel_ring_emit(ring, (box->x1 & 0xffff) | box->y1 << 16);
1138
		goto err;
-
 
1139
 
-
 
1140
	i915_gem_object_unpin_pages(shadow_batch_obj);
-
 
1141
 
-
 
1142
	memset(shadow_exec_entry, 0, sizeof(*shadow_exec_entry));
-
 
1143
 
1038
		intel_ring_emit(ring, ((box->x2 - 1) & 0xffff) | (box->y2 - 1) << 16);
1144
	vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
-
 
1145
	vma->exec_entry = shadow_exec_entry;
Line -... Line 1146...
-
 
1146
	vma->exec_entry->flags = __EXEC_OBJECT_HAS_PIN;
-
 
1147
	drm_gem_object_reference(&shadow_batch_obj->base);
-
 
1148
	list_add_tail(&vma->exec_list, &eb->vmas);
-
 
1149
 
-
 
1150
	shadow_batch_obj->base.pending_read_domains = I915_GEM_DOMAIN_COMMAND;
-
 
1151
 
-
 
1152
	return shadow_batch_obj;
Line 1039... Line 1153...
1039
		intel_ring_emit(ring, DR4);
1153
 
1040
		intel_ring_emit(ring, 0);
1154
err:
1041
	}
-
 
1042
	intel_ring_advance(ring);
-
 
1043
 
1155
	i915_gem_object_unpin_pages(shadow_batch_obj);
1044
	return 0;
1156
	if (ret == -EACCES) /* unhandled chained batch */
1045
}
-
 
1046
 
-
 
1047
 
1157
		return batch_obj;
1048
int
1158
	else
-
 
1159
		return ERR_PTR(ret);
1049
i915_gem_ringbuffer_submission(struct drm_device *dev, struct drm_file *file,
1160
}
1050
			     struct intel_engine_cs *ring,
1161
 
1051
			     struct intel_context *ctx,
1162
int
1052
			     struct drm_i915_gem_execbuffer2 *args,
1163
i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,
1053
			     struct list_head *vmas,
1164
			       struct drm_i915_gem_execbuffer2 *args,
1054
			     struct drm_i915_gem_object *batch_obj,
-
 
1055
			     u64 exec_start, u32 flags)
-
 
1056
{
-
 
1057
	struct drm_clip_rect *cliprects = NULL;
-
 
1058
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
1059
	u64 exec_len;
-
 
1060
	int instp_mode;
-
 
1061
	u32 instp_mask;
-
 
1062
	int i, ret = 0;
-
 
1063
 
-
 
1064
	if (args->num_cliprects != 0) {
-
 
1065
		if (ring != &dev_priv->ring[RCS]) {
-
 
1066
			DRM_DEBUG("clip rectangles are only valid with the render ring\n");
-
 
1067
			return -EINVAL;
-
 
1068
		}
-
 
1069
 
-
 
1070
		if (INTEL_INFO(dev)->gen >= 5) {
-
 
1071
			DRM_DEBUG("clip rectangles are only valid on pre-gen5\n");
-
 
1072
			return -EINVAL;
-
 
1073
		}
-
 
1074
 
-
 
1075
		if (args->num_cliprects > UINT_MAX / sizeof(*cliprects)) {
-
 
1076
			DRM_DEBUG("execbuf with %u cliprects\n",
-
 
1077
				  args->num_cliprects);
-
 
1078
			return -EINVAL;
-
 
1079
		}
-
 
1080
 
-
 
1081
		cliprects = kcalloc(args->num_cliprects,
-
 
1082
				    sizeof(*cliprects),
-
 
1083
				    GFP_KERNEL);
-
 
1084
		if (cliprects == NULL) {
-
 
1085
			ret = -ENOMEM;
-
 
1086
			goto error;
-
 
1087
		}
-
 
1088
 
-
 
1089
		if (copy_from_user(cliprects,
-
 
1090
				   to_user_ptr(args->cliprects_ptr),
-
 
1091
				   sizeof(*cliprects)*args->num_cliprects)) {
-
 
1092
			ret = -EFAULT;
-
 
1093
			goto error;
-
 
1094
		}
-
 
1095
	} else {
-
 
1096
		if (args->DR4 == 0xffffffff) {
-
 
Line 1097... Line 1165...
1097
			DRM_DEBUG("UXA submitting garbage DR4, fixing up\n");
1165
			       struct list_head *vmas)
1098
			args->DR4 = 0;
1166
{
1099
		}
1167
	struct drm_device *dev = params->dev;
Line 1100... Line 1168...
1100
 
1168
	struct intel_engine_cs *ring = params->ring;
1101
		if (args->DR1 || args->DR4 || args->cliprects_ptr) {
1169
	struct drm_i915_private *dev_priv = dev->dev_private;
1102
			DRM_DEBUG("0 cliprects but dirt in cliprects fields\n");
1170
	u64 exec_start, exec_len;
-
 
1171
	int instp_mode;
-
 
1172
	u32 instp_mask;
-
 
1173
	int ret;
Line 1103... Line 1174...
1103
			return -EINVAL;
1174
 
1104
		}
1175
	ret = i915_gem_execbuffer_move_to_gpu(params->request, vmas);
1105
	}
1176
	if (ret)
1106
 
1177
		return ret;
1107
	ret = i915_gem_execbuffer_move_to_gpu(ring, vmas);
1178
 
1108
	if (ret)
1179
	ret = i915_switch_context(params->request);
1109
		goto error;
1180
	if (ret)
1110
 
1181
		return ret;
1111
	ret = i915_switch_context(ring, ctx);
1182
 
1112
	if (ret)
-
 
1113
		goto error;
1183
	WARN(params->ctx->ppgtt && params->ctx->ppgtt->pd_dirty_rings & (1<id),
Line 1114... Line 1184...
1114
 
1184
	     "%s didn't clear reload\n", ring->name);
1115
	instp_mode = args->flags & I915_EXEC_CONSTANTS_MASK;
1185
 
1116
	instp_mask = I915_EXEC_CONSTANTS_MASK;
1186
	instp_mode = args->flags & I915_EXEC_CONSTANTS_MASK;
1117
	switch (instp_mode) {
1187
	instp_mask = I915_EXEC_CONSTANTS_MASK;
1118
	case I915_EXEC_CONSTANTS_REL_GENERAL:
-
 
1119
	case I915_EXEC_CONSTANTS_ABSOLUTE:
1188
	switch (instp_mode) {
Line 1120... Line 1189...
1120
	case I915_EXEC_CONSTANTS_REL_SURFACE:
1189
	case I915_EXEC_CONSTANTS_REL_GENERAL:
1121
		if (instp_mode != 0 && ring != &dev_priv->ring[RCS]) {
1190
	case I915_EXEC_CONSTANTS_ABSOLUTE:
1122
			DRM_DEBUG("non-0 rel constants mode on non-RCS\n");
1191
	case I915_EXEC_CONSTANTS_REL_SURFACE:
1123
			ret = -EINVAL;
1192
		if (instp_mode != 0 && ring != &dev_priv->ring[RCS]) {
1124
			goto error;
-
 
1125
		}
1193
			DRM_DEBUG("non-0 rel constants mode on non-RCS\n");
Line 1126... Line 1194...
1126
 
1194
			return -EINVAL;
1127
		if (instp_mode != dev_priv->relative_constants_mode) {
1195
		}
1128
			if (INTEL_INFO(dev)->gen < 4) {
1196
 
1129
				DRM_DEBUG("no rel constants on pre-gen4\n");
1197
		if (instp_mode != dev_priv->relative_constants_mode) {
1130
				ret = -EINVAL;
1198
			if (INTEL_INFO(dev)->gen < 4) {
1131
				goto error;
1199
				DRM_DEBUG("no rel constants on pre-gen4\n");
1132
			}
1200
				return -EINVAL;
1133
 
1201
			}
1134
			if (INTEL_INFO(dev)->gen > 5 &&
-
 
1135
			    instp_mode == I915_EXEC_CONSTANTS_REL_SURFACE) {
1202
 
Line 1136... Line 1203...
1136
				DRM_DEBUG("rel surface constants mode invalid on gen5+\n");
1203
			if (INTEL_INFO(dev)->gen > 5 &&
1137
				ret = -EINVAL;
1204
			    instp_mode == I915_EXEC_CONSTANTS_REL_SURFACE) {
1138
				goto error;
1205
				DRM_DEBUG("rel surface constants mode invalid on gen5+\n");
1139
			}
1206
				return -EINVAL;
1140
 
1207
			}
Line 1141... Line 1208...
1141
			/* The HW changed the meaning on this bit on gen6 */
1208
 
1142
			if (INTEL_INFO(dev)->gen >= 6)
1209
			/* The HW changed the meaning on this bit on gen6 */
1143
				instp_mask &= ~I915_EXEC_CONSTANTS_REL_SURFACE;
1210
			if (INTEL_INFO(dev)->gen >= 6)
1144
		}
1211
				instp_mask &= ~I915_EXEC_CONSTANTS_REL_SURFACE;
Line 1163... Line 1230...
1163
 
1230
 
1164
		dev_priv->relative_constants_mode = instp_mode;
1231
		dev_priv->relative_constants_mode = instp_mode;
Line 1165... Line 1232...
1165
	}
1232
	}
1166
 
1233
 
1167
	if (args->flags & I915_EXEC_GEN7_SOL_RESET) {
1234
	if (args->flags & I915_EXEC_GEN7_SOL_RESET) {
1168
		ret = i915_reset_gen7_sol_offsets(dev, ring);
1235
		ret = i915_reset_gen7_sol_offsets(dev, params->request);
1169
		if (ret)
1236
		if (ret)
Line 1170... Line 1237...
1170
			goto error;
1237
			return ret;
1171
	}
-
 
1172
 
1238
	}
1173
	exec_len = args->batch_len;
-
 
1174
	if (cliprects) {
1239
 
1175
		for (i = 0; i < args->num_cliprects; i++) {
-
 
1176
			ret = i915_emit_box(ring, &cliprects[i],
-
 
Line 1177... Line -...
1177
					    args->DR1, args->DR4);
-
 
1178
			if (ret)
-
 
1179
				goto error;
-
 
1180
 
-
 
1181
			ret = ring->dispatch_execbuffer(ring,
-
 
1182
							exec_start, exec_len,
-
 
1183
							flags);
-
 
1184
			if (ret)
1240
	exec_len   = args->batch_len;
1185
				goto error;
1241
	exec_start = params->batch_obj_vm_offset +
1186
		}
1242
		     params->args_batch_start_offset;
1187
	} else {
1243
 
1188
		ret = ring->dispatch_execbuffer(ring,
1244
	ret = ring->dispatch_execbuffer(params->request,
1189
						exec_start, exec_len,
-
 
Line 1190... Line 1245...
1190
						flags);
1245
					exec_start, exec_len,
Line 1191... Line 1246...
1191
		if (ret)
1246
					params->dispatch_flags);
1192
			return ret;
1247
	if (ret)
Line 1193... Line -...
1193
	}
-
 
1194
 
-
 
1195
	trace_i915_gem_ring_dispatch(ring, intel_ring_get_seqno(ring), flags);
1248
		return ret;
1196
 
1249
 
Line 1197... Line 1250...
1197
	i915_gem_execbuffer_move_to_active(vmas, ring);
1250
	trace_i915_gem_ring_dispatch(params->request, params->dispatch_flags);
1198
	i915_gem_execbuffer_retire_commands(dev, file, ring, batch_obj);
1251
 
1199
 
1252
	i915_gem_execbuffer_move_to_active(vmas, params->request);
Line 1259... Line 1312...
1259
		       struct drm_i915_gem_exec_object2 *exec)
1312
		       struct drm_i915_gem_exec_object2 *exec)
1260
{
1313
{
1261
	struct drm_i915_private *dev_priv = dev->dev_private;
1314
	struct drm_i915_private *dev_priv = dev->dev_private;
1262
	struct eb_vmas *eb;
1315
	struct eb_vmas *eb;
1263
	struct drm_i915_gem_object *batch_obj;
1316
	struct drm_i915_gem_object *batch_obj;
-
 
1317
	struct drm_i915_gem_exec_object2 shadow_exec_entry;
1264
	struct intel_engine_cs *ring;
1318
	struct intel_engine_cs *ring;
1265
	struct intel_context *ctx;
1319
	struct intel_context *ctx;
1266
	struct i915_address_space *vm;
1320
	struct i915_address_space *vm;
-
 
1321
	struct i915_execbuffer_params params_master; /* XXX: will be removed later */
-
 
1322
	struct i915_execbuffer_params *params = ¶ms_master;
1267
	const u32 ctx_id = i915_execbuffer2_get_context_id(*args);
1323
	const u32 ctx_id = i915_execbuffer2_get_context_id(*args);
1268
	u64 exec_start = args->batch_start_offset;
-
 
1269
	u32 flags;
1324
	u32 dispatch_flags;
1270
	int ret;
1325
	int ret;
1271
	bool need_relocs;
1326
	bool need_relocs;
Line 1272... Line 1327...
1272
 
1327
 
1273
	if (!i915_gem_check_execbuffer(args))
1328
	if (!i915_gem_check_execbuffer(args))
Line 1274... Line 1329...
1274
		return -EINVAL;
1329
		return -EINVAL;
1275
 
1330
 
1276
	ret = validate_exec_list(dev, exec, args->buffer_count);
1331
	ret = validate_exec_list(dev, exec, args->buffer_count);
Line 1277... Line 1332...
1277
	if (ret)
1332
	if (ret)
1278
		return ret;
1333
		return ret;
Line 1279... Line 1334...
1279
 
1334
 
1280
	flags = 0;
1335
	dispatch_flags = 0;
1281
	if (args->flags & I915_EXEC_SECURE) {
1336
	if (args->flags & I915_EXEC_SECURE) {
1282
 
1337
 
Line 1283... Line 1338...
1283
		flags |= I915_DISPATCH_SECURE;
1338
		dispatch_flags |= I915_DISPATCH_SECURE;
1284
	}
1339
	}
1285
	if (args->flags & I915_EXEC_IS_PINNED)
1340
	if (args->flags & I915_EXEC_IS_PINNED)
1286
		flags |= I915_DISPATCH_PINNED;
1341
		dispatch_flags |= I915_DISPATCH_PINNED;
1287
 
1342
 
Line -... Line 1343...
-
 
1343
	if ((args->flags & I915_EXEC_RING_MASK) > LAST_USER_RING) {
-
 
1344
		DRM_DEBUG("execbuf with unknown ring: %d\n",
-
 
1345
			  (int)(args->flags & I915_EXEC_RING_MASK));
-
 
1346
		return -EINVAL;
-
 
1347
	}
-
 
1348
 
-
 
1349
	if (((args->flags & I915_EXEC_RING_MASK) != I915_EXEC_BSD) &&
1288
	if ((args->flags & I915_EXEC_RING_MASK) > LAST_USER_RING) {
1350
	    ((args->flags & I915_EXEC_BSD_MASK) != 0)) {
1289
		DRM_DEBUG("execbuf with unknown ring: %d\n",
1351
		DRM_DEBUG("execbuf with non bsd ring but with invalid "
1290
			  (int)(args->flags & I915_EXEC_RING_MASK));
1352
			"bsd dispatch flags: %d\n", (int)(args->flags));
1291
		return -EINVAL;
1353
		return -EINVAL;
1292
	}
1354
	} 
-
 
1355
 
-
 
1356
	if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_DEFAULT)
-
 
1357
		ring = &dev_priv->ring[RCS];
1293
 
1358
	else if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_BSD) {
1294
	if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_DEFAULT)
1359
		if (HAS_BSD2(dev)) {
-
 
1360
			int ring_id;
-
 
1361
 
-
 
1362
			switch (args->flags & I915_EXEC_BSD_MASK) {
-
 
1363
			case I915_EXEC_BSD_DEFAULT:
-
 
1364
				ring_id = gen8_dispatch_bsd_ring(dev, file);
-
 
1365
				ring = &dev_priv->ring[ring_id];
-
 
1366
				break;
-
 
1367
			case I915_EXEC_BSD_RING1:
-
 
1368
				ring = &dev_priv->ring[VCS];
-
 
1369
				break;
-
 
1370
			case I915_EXEC_BSD_RING2:
-
 
1371
				ring = &dev_priv->ring[VCS2];
1295
		ring = &dev_priv->ring[RCS];
1372
				break;
1296
	else if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_BSD) {
1373
			default:
1297
		if (HAS_BSD2(dev)) {
1374
				DRM_DEBUG("execbuf with unknown bsd ring: %d\n",
1298
			int ring_id;
1375
					  (int)(args->flags & I915_EXEC_BSD_MASK));
Line 1312... Line 1389...
1312
	if (args->buffer_count < 1) {
1389
	if (args->buffer_count < 1) {
1313
		DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count);
1390
		DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count);
1314
		return -EINVAL;
1391
		return -EINVAL;
1315
	}
1392
	}
Line -... Line 1393...
-
 
1393
 
-
 
1394
	if (args->flags & I915_EXEC_RESOURCE_STREAMER) {
-
 
1395
		if (!HAS_RESOURCE_STREAMER(dev)) {
-
 
1396
			DRM_DEBUG("RS is only allowed for Haswell, Gen8 and above\n");
-
 
1397
			return -EINVAL;
-
 
1398
		}
-
 
1399
		if (ring->id != RCS) {
-
 
1400
			DRM_DEBUG("RS is not available on %s\n",
-
 
1401
				 ring->name);
-
 
1402
			return -EINVAL;
-
 
1403
		}
-
 
1404
 
-
 
1405
		dispatch_flags |= I915_DISPATCH_RS;
-
 
1406
	}
1316
 
1407
 
Line 1317... Line 1408...
1317
	intel_runtime_pm_get(dev_priv);
1408
	intel_runtime_pm_get(dev_priv);
1318
 
1409
 
1319
	ret = i915_mutex_lock_interruptible(dev);
1410
	ret = i915_mutex_lock_interruptible(dev);
Line 1332... Line 1423...
1332
	if (ctx->ppgtt)
1423
	if (ctx->ppgtt)
1333
		vm = &ctx->ppgtt->base;
1424
		vm = &ctx->ppgtt->base;
1334
	else
1425
	else
1335
		vm = &dev_priv->gtt.base;
1426
		vm = &dev_priv->gtt.base;
Line -... Line 1427...
-
 
1427
 
-
 
1428
	memset(¶ms_master, 0x00, sizeof(params_master));
1336
 
1429
 
1337
	eb = eb_create(args);
1430
	eb = eb_create(args);
1338
	if (eb == NULL) {
1431
	if (eb == NULL) {
1339
		i915_gem_context_unreference(ctx);
1432
		i915_gem_context_unreference(ctx);
1340
		mutex_unlock(&dev->struct_mutex);
1433
		mutex_unlock(&dev->struct_mutex);
Line 1350... Line 1443...
1350
	/* take note of the batch buffer before we might reorder the lists */
1443
	/* take note of the batch buffer before we might reorder the lists */
1351
	batch_obj = eb_get_batch(eb);
1444
	batch_obj = eb_get_batch(eb);
Line 1352... Line 1445...
1352
 
1445
 
1353
	/* Move the objects en-masse into the GTT, evicting if necessary. */
1446
	/* Move the objects en-masse into the GTT, evicting if necessary. */
1354
	need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0;
1447
	need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0;
1355
	ret = i915_gem_execbuffer_reserve(ring, &eb->vmas, &need_relocs);
1448
	ret = i915_gem_execbuffer_reserve(ring, &eb->vmas, ctx, &need_relocs);
1356
	if (ret)
1449
	if (ret)
Line 1357... Line 1450...
1357
		goto err;
1450
		goto err;
1358
 
1451
 
1359
	/* The objects are in their final locations, apply the relocations. */
1452
	/* The objects are in their final locations, apply the relocations. */
1360
	if (need_relocs)
1453
	if (need_relocs)
1361
		ret = i915_gem_execbuffer_relocate(eb);
1454
		ret = i915_gem_execbuffer_relocate(eb);
1362
	if (ret) {
1455
	if (ret) {
1363
		if (ret == -EFAULT) {
1456
		if (ret == -EFAULT) {
1364
			ret = i915_gem_execbuffer_relocate_slow(dev, args, file, ring,
1457
			ret = i915_gem_execbuffer_relocate_slow(dev, args, file, ring,
1365
								eb, exec);
1458
								eb, exec, ctx);
1366
			BUG_ON(!mutex_is_locked(&dev->struct_mutex));
1459
			BUG_ON(!mutex_is_locked(&dev->struct_mutex));
1367
		}
1460
		}
1368
		if (ret)
1461
		if (ret)
Line 1373... Line 1466...
1373
	if (batch_obj->base.pending_write_domain) {
1466
	if (batch_obj->base.pending_write_domain) {
1374
		DRM_DEBUG("Attempting to use self-modifying batch buffer\n");
1467
		DRM_DEBUG("Attempting to use self-modifying batch buffer\n");
1375
		ret = -EINVAL;
1468
		ret = -EINVAL;
1376
		goto err;
1469
		goto err;
1377
	}
1470
	}
-
 
1471
 
1378
	batch_obj->base.pending_read_domains |= I915_GEM_DOMAIN_COMMAND;
1472
	params->args_batch_start_offset = args->batch_start_offset;
-
 
1473
 
1379
#if 0
1474
#if 0
1380
	if (i915_needs_cmd_parser(ring)) {
1475
	if (i915_needs_cmd_parser(ring) && args->batch_len) {
-
 
1476
		struct drm_i915_gem_object *parsed_batch_obj;
-
 
1477
 
1381
		ret = i915_parse_cmds(ring,
1478
		parsed_batch_obj = i915_gem_execbuffer_parse(ring,
-
 
1479
						      &shadow_exec_entry,
-
 
1480
						      eb,
1382
				      batch_obj,
1481
						      batch_obj,
1383
				      args->batch_start_offset,
1482
						      args->batch_start_offset,
-
 
1483
						      args->batch_len,
1384
				      file->is_master);
1484
						      file->is_master);
1385
		if (ret) {
1485
		if (IS_ERR(parsed_batch_obj)) {
1386
			if (ret != -EACCES)
1486
			ret = PTR_ERR(parsed_batch_obj);
1387
			goto err;
1487
			goto err;
1388
		} else {
1488
		}
-
 
1489
 
1389
		/*
1490
		/*
1390
		 * XXX: Actually do this when enabling batch copy...
1491
		 * parsed_batch_obj == batch_obj means batch not fully parsed:
-
 
1492
		 * Accept, but don't promote to secure.
-
 
1493
		 */
-
 
1494
 
-
 
1495
		if (parsed_batch_obj != batch_obj) {
-
 
1496
			/*
-
 
1497
			 * Batch parsed and accepted:
1391
		 *
1498
			 *
1392
		 * Set the DISPATCH_SECURE bit to remove the NON_SECURE bit
1499
			 * Set the DISPATCH_SECURE bit to remove the NON_SECURE
1393
		 * from MI_BATCH_BUFFER_START commands issued in the
1500
			 * bit from MI_BATCH_BUFFER_START commands issued in
1394
		 * dispatch_execbuffer implementations. We specifically don't
1501
			 * the dispatch_execbuffer implementations. We
-
 
1502
			 * specifically don't want that set on batches the
1395
		 * want that set when the command parser is enabled.
1503
			 * command parser has accepted.
1396
		 */
1504
			 */
-
 
1505
			dispatch_flags |= I915_DISPATCH_SECURE;
-
 
1506
			params->args_batch_start_offset = 0;
-
 
1507
			batch_obj = parsed_batch_obj;
1397
	}
1508
		}
1398
	}
1509
	}
1399
 
-
 
1400
#endif
1510
#endif
-
 
1511
 
-
 
1512
	batch_obj->base.pending_read_domains |= I915_GEM_DOMAIN_COMMAND;
-
 
1513
 
1401
	/* snb/ivb/vlv conflate the "batch in ppgtt" bit with the "non-secure
1514
	/* snb/ivb/vlv conflate the "batch in ppgtt" bit with the "non-secure
1402
	 * batch" bit. Hence we need to pin secure batches into the global gtt.
1515
	 * batch" bit. Hence we need to pin secure batches into the global gtt.
1403
	 * hsw should have this fixed, but bdw mucks it up again. */
1516
	 * hsw should have this fixed, but bdw mucks it up again. */
1404
	if (flags & I915_DISPATCH_SECURE) {
1517
	if (dispatch_flags & I915_DISPATCH_SECURE) {
1405
		/*
1518
		/*
1406
		 * So on first glance it looks freaky that we pin the batch here
1519
		 * So on first glance it looks freaky that we pin the batch here
1407
		 * outside of the reservation loop. But:
1520
		 * outside of the reservation loop. But:
1408
		 * - The batch is already pinned into the relevant ppgtt, so we
1521
		 * - The batch is already pinned into the relevant ppgtt, so we
1409
		 *   already have the backing storage fully allocated.
1522
		 *   already have the backing storage fully allocated.
1410
		 * - No other BO uses the global gtt (well contexts, but meh),
1523
		 * - No other BO uses the global gtt (well contexts, but meh),
1411
		 *   so we don't really have issues with mutliple objects not
1524
		 *   so we don't really have issues with multiple objects not
1412
		 *   fitting due to fragmentation.
1525
		 *   fitting due to fragmentation.
1413
		 * So this is actually safe.
1526
		 * So this is actually safe.
1414
		 */
1527
		 */
1415
		ret = i915_gem_obj_ggtt_pin(batch_obj, 0, 0);
1528
		ret = i915_gem_obj_ggtt_pin(batch_obj, 0, 0);
1416
		if (ret)
1529
		if (ret)
1417
			goto err;
1530
			goto err;
Line 1418... Line 1531...
1418
 
1531
 
1419
		exec_start += i915_gem_obj_ggtt_offset(batch_obj);
1532
		params->batch_obj_vm_offset = i915_gem_obj_ggtt_offset(batch_obj);
1420
	} else
1533
	} else
-
 
1534
		params->batch_obj_vm_offset = i915_gem_obj_offset(batch_obj, vm);
-
 
1535
 
-
 
1536
	/* Allocate a request for this batch buffer nice and early. */
-
 
1537
	ret = i915_gem_request_alloc(ring, ctx, ¶ms->request);
-
 
1538
	if (ret)
-
 
1539
		goto err_batch_unpin;
-
 
1540
 
-
 
1541
	ret = i915_gem_request_add_to_client(params->request, file);
-
 
1542
	if (ret)
-
 
1543
		goto err_batch_unpin;
-
 
1544
 
-
 
1545
	/*
-
 
1546
	 * Save assorted stuff away to pass through to *_submission().
-
 
1547
	 * NB: This data should be 'persistent' and not local as it will
-
 
1548
	 * kept around beyond the duration of the IOCTL once the GPU
-
 
1549
	 * scheduler arrives.
-
 
1550
	 */
-
 
1551
	params->dev                     = dev;
-
 
1552
	params->file                    = file;
-
 
1553
	params->ring                    = ring;
-
 
1554
	params->dispatch_flags          = dispatch_flags;
-
 
1555
	params->batch_obj               = batch_obj;
Line 1421... Line 1556...
1421
		exec_start += i915_gem_obj_offset(batch_obj, vm);
1556
	params->ctx                     = ctx;
1422
 
-
 
Line -... Line 1557...
-
 
1557
 
1423
	ret = dev_priv->gt.do_execbuf(dev, file, ring, ctx, args,
1558
	ret = dev_priv->gt.execbuf_submit(params, args, &eb->vmas);
1424
				      &eb->vmas, batch_obj, exec_start, flags);
1559
 
1425
 
1560
err_batch_unpin:
1426
	/*
1561
	/*
1427
	 * FIXME: We crucially rely upon the active tracking for the (ppgtt)
1562
	 * FIXME: We crucially rely upon the active tracking for the (ppgtt)
1428
	 * batch vma for correctness. For less ugly and less fragility this
1563
	 * batch vma for correctness. For less ugly and less fragility this
1429
	 * needs to be adjusted to also track the ggtt batch vma properly as
1564
	 * needs to be adjusted to also track the ggtt batch vma properly as
1430
	 * active.
1565
	 * active.
-
 
1566
	 */
1431
	 */
1567
	if (dispatch_flags & I915_DISPATCH_SECURE)
1432
	if (flags & I915_DISPATCH_SECURE)
1568
		i915_gem_object_ggtt_unpin(batch_obj);
1433
		i915_gem_object_ggtt_unpin(batch_obj);
1569
 
1434
err:
1570
err:
Line -... Line 1571...
-
 
1571
	/* the request owns the ref now */
-
 
1572
	i915_gem_context_unreference(ctx);
-
 
1573
	eb_destroy(eb);
-
 
1574
 
-
 
1575
	/*
-
 
1576
	 * If the request was created but not successfully submitted then it
-
 
1577
	 * must be freed again. If it was submitted then it is being tracked
-
 
1578
	 * on the active request list and no clean up is required here.
1435
	/* the request owns the ref now */
1579
	 */
Line 1436... Line 1580...
1436
	i915_gem_context_unreference(ctx);
1580
	if (ret && params->request)
1437
	eb_destroy(eb);
1581
		i915_gem_request_cancel(params->request);
1438
 
1582