Subversion Repositories Kolibri OS

Rev

Rev 6938 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6938 Rev 7146
Line 718... Line 718...
718
				~TTM_PL_MASK_MEMTYPE);
718
				~TTM_PL_MASK_MEMTYPE);
Line 719... Line 719...
719
 
719
 
720
		if (mem_type == TTM_PL_SYSTEM)
720
		if (mem_type == TTM_PL_SYSTEM)
Line 721... Line 721...
721
			break;
721
			break;
722
 
722
 
723
			ret = (*man->func->get_node)(man, bo, place, mem);
723
		ret = (*man->func->get_node)(man, bo, place, mem);
Line 724... Line 724...
724
			if (unlikely(ret))
724
		if (unlikely(ret))
725
				return ret;
725
			return ret;
726
		
726
		
Line 819... Line 819...
819
		ttm_bo_mem_put(bo, &mem);
819
		ttm_bo_mem_put(bo, &mem);
820
	return ret;
820
	return ret;
821
}
821
}
Line 822... Line 822...
822
 
822
 
823
bool ttm_bo_mem_compat(struct ttm_placement *placement,
823
bool ttm_bo_mem_compat(struct ttm_placement *placement,
824
			      struct ttm_mem_reg *mem,
824
		       struct ttm_mem_reg *mem,
825
			      uint32_t *new_flags)
825
		       uint32_t *new_flags)
826
{
826
{
Line 827... Line 827...
827
	int i;
827
	int i;
828
 
828
 
Line 852... Line 852...
852
			return true;
852
			return true;
853
	}
853
	}
Line 854... Line 854...
854
 
854
 
855
	return false;
855
	return false;
-
 
856
}
Line 856... Line 857...
856
}
857
EXPORT_SYMBOL(ttm_bo_mem_compat);
857
 
858
 
858
int ttm_bo_validate(struct ttm_buffer_object *bo,
859
int ttm_bo_validate(struct ttm_buffer_object *bo,
859
			struct ttm_placement *placement,
860
			struct ttm_placement *placement,
Line 891... Line 892...
891
	return 0;
892
	return 0;
892
}
893
}
893
EXPORT_SYMBOL(ttm_bo_validate);
894
EXPORT_SYMBOL(ttm_bo_validate);
Line 894... Line 895...
894
 
895
 
895
int ttm_bo_init(struct ttm_bo_device *bdev,
896
int ttm_bo_init(struct ttm_bo_device *bdev,
896
        struct ttm_buffer_object *bo,
897
		struct ttm_buffer_object *bo,
897
        unsigned long size,
898
		unsigned long size,
898
        enum ttm_bo_type type,
899
		enum ttm_bo_type type,
899
        struct ttm_placement *placement,
900
		struct ttm_placement *placement,
900
        uint32_t page_alignment,
901
		uint32_t page_alignment,
901
        bool interruptible,
902
		bool interruptible,
902
        struct file *persistent_swap_storage,
903
		struct file *persistent_swap_storage,
903
        size_t acc_size,
904
		size_t acc_size,
904
        struct sg_table *sg,
905
		struct sg_table *sg,
905
		struct reservation_object *resv,
906
		struct reservation_object *resv,
906
        void (*destroy) (struct ttm_buffer_object *))
907
		void (*destroy) (struct ttm_buffer_object *))
907
{
908
{
908
    int ret = 0;
909
    int ret = 0;
909
    unsigned long num_pages;
910
    unsigned long num_pages;
Line 918... Line 919...
918
            kfree(bo);
919
            kfree(bo);
919
        return -EINVAL;
920
        return -EINVAL;
920
    }
921
    }
921
    bo->destroy = destroy;
922
    bo->destroy = destroy;
Line 922... Line 923...
922
 
923
 
923
    kref_init(&bo->kref);
924
	kref_init(&bo->kref);
924
    kref_init(&bo->list_kref);
925
	kref_init(&bo->list_kref);
925
	atomic_set(&bo->cpu_writers, 0);
926
	atomic_set(&bo->cpu_writers, 0);
926
    INIT_LIST_HEAD(&bo->lru);
927
	INIT_LIST_HEAD(&bo->lru);
927
    INIT_LIST_HEAD(&bo->ddestroy);
928
	INIT_LIST_HEAD(&bo->ddestroy);
928
    INIT_LIST_HEAD(&bo->swap);
929
	INIT_LIST_HEAD(&bo->swap);
929
    INIT_LIST_HEAD(&bo->io_reserve_lru);
930
	INIT_LIST_HEAD(&bo->io_reserve_lru);
930
    mutex_init(&bo->wu_mutex);
931
	mutex_init(&bo->wu_mutex);
931
    bo->bdev = bdev;
932
	bo->bdev = bdev;
932
    bo->glob = bdev->glob;
933
	bo->glob = bdev->glob;
933
    bo->type = type;
934
	bo->type = type;
934
    bo->num_pages = num_pages;
935
	bo->num_pages = num_pages;
935
    bo->mem.size = num_pages << PAGE_SHIFT;
936
	bo->mem.size = num_pages << PAGE_SHIFT;
936
    bo->mem.mem_type = TTM_PL_SYSTEM;
937
	bo->mem.mem_type = TTM_PL_SYSTEM;
937
    bo->mem.num_pages = bo->num_pages;
938
	bo->mem.num_pages = bo->num_pages;
938
    bo->mem.mm_node = NULL;
939
	bo->mem.mm_node = NULL;
939
    bo->mem.page_alignment = page_alignment;
940
	bo->mem.page_alignment = page_alignment;
940
    bo->mem.bus.io_reserved_vm = false;
941
	bo->mem.bus.io_reserved_vm = false;
941
    bo->mem.bus.io_reserved_count = 0;
942
	bo->mem.bus.io_reserved_count = 0;
942
    bo->priv_flags = 0;
943
	bo->priv_flags = 0;
943
    bo->mem.placement = (TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED);
944
	bo->mem.placement = (TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED);
944
    bo->persistent_swap_storage = persistent_swap_storage;
945
	bo->persistent_swap_storage = persistent_swap_storage;
945
    bo->acc_size = acc_size;
946
	bo->acc_size = acc_size;
946
    bo->sg = sg;
947
	bo->sg = sg;
947
	if (resv) {
948
	if (resv) {
948
		bo->resv = resv;
949
		bo->resv = resv;
949
		lockdep_assert_held(&bo->resv->lock.base);
950
		lockdep_assert_held(&bo->resv->lock.base);
950
	} else {
951
	} else {
951
		bo->resv = &bo->ttm_resv;
952
		bo->resv = &bo->ttm_resv;
952
		reservation_object_init(&bo->ttm_resv);
953
		reservation_object_init(&bo->ttm_resv);
953
	}
954
	}
954
	atomic_inc(&bo->glob->bo_count);
955
	atomic_inc(&bo->glob->bo_count);
Line 955... Line 956...
955
    drm_vma_node_reset(&bo->vma_node);
956
	drm_vma_node_reset(&bo->vma_node);
956
 
957
 
957
    /*
958
	/*
958
     * For ttm_bo_type_device buffers, allocate
959
	 * For ttm_bo_type_device buffers, allocate
959
     * address space from the device.
960
	 * address space from the device.
960
     */
961
	 */
961
	if (bo->type == ttm_bo_type_device ||
962
	if (bo->type == ttm_bo_type_device ||
962
	    bo->type == ttm_bo_type_sg)
963
	    bo->type == ttm_bo_type_sg)
Line 972... Line 973...
972
	}
973
	}
Line 973... Line 974...
973
 
974
 
974
	if (likely(!ret))
975
	if (likely(!ret))
Line 975... Line 976...
975
		ret = ttm_bo_validate(bo, placement, interruptible, false);
976
		ret = ttm_bo_validate(bo, placement, interruptible, false);
976
 
977
 
Line -... Line 978...
-
 
978
	if (!resv) {
-
 
979
		ttm_bo_unreserve(bo);
-
 
980
 
-
 
981
	} else if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
-
 
982
		spin_lock(&bo->glob->lru_lock);
-
 
983
		ttm_bo_add_to_lru(bo);
977
	if (!resv)
984
		spin_unlock(&bo->glob->lru_lock);
978
		ttm_bo_unreserve(bo);
985
	}
Line 979... Line 986...
979
 
986
 
980
	if (unlikely(ret))
987
	if (unlikely(ret))
981
		ttm_bo_unref(&bo);
988
		ttm_bo_unref(&bo);
Line 982... Line 989...
982
 
989
 
983
    return ret;
990
	return ret;
Line 1109... Line 1116...
1109
}
1116
}
1110
EXPORT_SYMBOL(ttm_bo_global_release);
1117
EXPORT_SYMBOL(ttm_bo_global_release);
Line 1111... Line 1118...
1111
 
1118
 
1112
int ttm_bo_global_init(struct drm_global_reference *ref)
1119
int ttm_bo_global_init(struct drm_global_reference *ref)
1113
{
1120
{
1114
    struct ttm_bo_global_ref *bo_ref =
1121
	struct ttm_bo_global_ref *bo_ref =
1115
        container_of(ref, struct ttm_bo_global_ref, ref);
1122
		container_of(ref, struct ttm_bo_global_ref, ref);
1116
    struct ttm_bo_global *glob = ref->object;
1123
	struct ttm_bo_global *glob = ref->object;
1117
    int ret;
1124
	int ret;
1118
 
1125
 
1119
    mutex_init(&glob->device_list_mutex);
1126
	mutex_init(&glob->device_list_mutex);
1120
    spin_lock_init(&glob->lru_lock);
1127
	spin_lock_init(&glob->lru_lock);
1121
    glob->mem_glob = bo_ref->mem_glob;
1128
	glob->mem_glob = bo_ref->mem_glob;
Line 1122... Line 1129...
1122
	glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32);
1129
	glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32);
1123
 
1130
 
1124
    if (unlikely(glob->dummy_read_page == NULL)) {
1131
	if (unlikely(glob->dummy_read_page == NULL)) {
1125
        ret = -ENOMEM;
1132
		ret = -ENOMEM;
Line 1126... Line 1133...
1126
        goto out_no_drp;
1133
		goto out_no_drp;
1127
    }
1134
	}
Line 1128... Line 1135...
1128
 
1135
 
Line 1129... Line 1136...
1129
    INIT_LIST_HEAD(&glob->swap_lru);
1136
	INIT_LIST_HEAD(&glob->swap_lru);
Line 1130... Line 1137...
1130
    INIT_LIST_HEAD(&glob->device_list);
1137
	INIT_LIST_HEAD(&glob->device_list);
1131
 
1138
 
1132
    atomic_set(&glob->bo_count, 0);
1139
    atomic_set(&glob->bo_count, 0);
1133
 
1140
 
1134
    return 0;
1141
    return 0;
Line 1135... Line 1142...
1135
 
1142
 
1136
out_no_drp:
1143
out_no_drp:
Line 1252... Line 1259...
1252
				return -EBUSY;
1259
				return -EBUSY;
Line 1253... Line 1260...
1253
 
1260
 
1254
			timeout = fence_wait_timeout(fence,
1261
			timeout = fence_wait_timeout(fence,
1255
						     interruptible, timeout);
1262
						     interruptible, timeout);
1256
		}
1263
		}
Line 1257... Line 1264...
1257
		}
1264
	}
1258
 
1265
 
Line 1259... Line 1266...
1259
	if (timeout < 0)
1266
	if (timeout < 0)
1260
		return timeout;
1267
		return timeout;
Line 1261... Line 1268...
1261
 
1268
 
1262
	if (timeout == 0)
1269
	if (timeout == 0)
1263
			return -EBUSY;
1270
		return -EBUSY;
1264
 
1271