diff options
author | Ben Widawsky <ben@bwidawsk.net> | 2013-07-31 19:59:56 -0400 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2013-08-05 13:04:08 -0400 |
commit | a70a3148b0c61cb7c588ea650db785b261b378a3 (patch) | |
tree | 63d9dbfe3c2ef436411b4e9aeb58abe99a78c9a0 /drivers | |
parent | 31a46c9c092afc6558e7be7eaa42eb9bd4d3de8b (diff) |
drm/i915: Make proper functions for VMs
Earlier in the conversion sequence we attempted to quickly wedge in the
transitional interface as static inlines.
Now that we're sure these interfaces are sane, for easier debug and to
decrease code size (since many of these functions may be called quite a
bit), make them real functions
While at it, kill off the set_color interface. We'll always have the
VMA, or easily get to it.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpu/drm/i915/i915_drv.h | 83 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_gem.c | 78 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_gem_evict.c | 8 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_gem_gtt.c | 2 |
4 files changed, 118 insertions, 53 deletions
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 67a15d00d5f2..79d4fed9d066 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h | |||
@@ -1393,52 +1393,6 @@ struct drm_i915_gem_object { | |||
1393 | 1393 | ||
1394 | #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base) | 1394 | #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base) |
1395 | 1395 | ||
1396 | /* This is a temporary define to help transition us to real VMAs. If you see | ||
1397 | * this, you're either reviewing code, or bisecting it. */ | ||
1398 | static inline struct i915_vma * | ||
1399 | __i915_gem_obj_to_vma(struct drm_i915_gem_object *obj) | ||
1400 | { | ||
1401 | if (list_empty(&obj->vma_list)) | ||
1402 | return NULL; | ||
1403 | return list_first_entry(&obj->vma_list, struct i915_vma, vma_link); | ||
1404 | } | ||
1405 | |||
1406 | /* Whether or not this object is currently mapped by the translation tables */ | ||
1407 | static inline bool | ||
1408 | i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *o) | ||
1409 | { | ||
1410 | struct i915_vma *vma = __i915_gem_obj_to_vma(o); | ||
1411 | if (vma == NULL) | ||
1412 | return false; | ||
1413 | return drm_mm_node_allocated(&vma->node); | ||
1414 | } | ||
1415 | |||
1416 | /* Offset of the first PTE pointing to this object */ | ||
1417 | static inline unsigned long | ||
1418 | i915_gem_obj_ggtt_offset(struct drm_i915_gem_object *o) | ||
1419 | { | ||
1420 | BUG_ON(list_empty(&o->vma_list)); | ||
1421 | return __i915_gem_obj_to_vma(o)->node.start; | ||
1422 | } | ||
1423 | |||
1424 | /* The size used in the translation tables may be larger than the actual size of | ||
1425 | * the object on GEN2/GEN3 because of the way tiling is handled. See | ||
1426 | * i915_gem_get_gtt_size() for more details. | ||
1427 | */ | ||
1428 | static inline unsigned long | ||
1429 | i915_gem_obj_ggtt_size(struct drm_i915_gem_object *o) | ||
1430 | { | ||
1431 | BUG_ON(list_empty(&o->vma_list)); | ||
1432 | return __i915_gem_obj_to_vma(o)->node.size; | ||
1433 | } | ||
1434 | |||
1435 | static inline void | ||
1436 | i915_gem_obj_ggtt_set_color(struct drm_i915_gem_object *o, | ||
1437 | enum i915_cache_level color) | ||
1438 | { | ||
1439 | __i915_gem_obj_to_vma(o)->node.color = color; | ||
1440 | } | ||
1441 | |||
1442 | /** | 1396 | /** |
1443 | * Request queue structure. | 1397 | * Request queue structure. |
1444 | * | 1398 | * |
@@ -1906,6 +1860,43 @@ struct dma_buf *i915_gem_prime_export(struct drm_device *dev, | |||
1906 | 1860 | ||
1907 | void i915_gem_restore_fences(struct drm_device *dev); | 1861 | void i915_gem_restore_fences(struct drm_device *dev); |
1908 | 1862 | ||
1863 | unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o, | ||
1864 | struct i915_address_space *vm); | ||
1865 | bool i915_gem_obj_bound_any(struct drm_i915_gem_object *o); | ||
1866 | bool i915_gem_obj_bound(struct drm_i915_gem_object *o, | ||
1867 | struct i915_address_space *vm); | ||
1868 | unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o, | ||
1869 | struct i915_address_space *vm); | ||
1870 | struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj, | ||
1871 | struct i915_address_space *vm); | ||
1872 | /* Some GGTT VM helpers */ | ||
1873 | #define obj_to_ggtt(obj) \ | ||
1874 | (&((struct drm_i915_private *)(obj)->base.dev->dev_private)->gtt.base) | ||
1875 | static inline bool i915_is_ggtt(struct i915_address_space *vm) | ||
1876 | { | ||
1877 | struct i915_address_space *ggtt = | ||
1878 | &((struct drm_i915_private *)(vm)->dev->dev_private)->gtt.base; | ||
1879 | return vm == ggtt; | ||
1880 | } | ||
1881 | |||
1882 | static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj) | ||
1883 | { | ||
1884 | return i915_gem_obj_bound(obj, obj_to_ggtt(obj)); | ||
1885 | } | ||
1886 | |||
1887 | static inline unsigned long | ||
1888 | i915_gem_obj_ggtt_offset(struct drm_i915_gem_object *obj) | ||
1889 | { | ||
1890 | return i915_gem_obj_offset(obj, obj_to_ggtt(obj)); | ||
1891 | } | ||
1892 | |||
1893 | static inline unsigned long | ||
1894 | i915_gem_obj_ggtt_size(struct drm_i915_gem_object *obj) | ||
1895 | { | ||
1896 | return i915_gem_obj_size(obj, obj_to_ggtt(obj)); | ||
1897 | } | ||
1898 | #undef obj_to_ggtt | ||
1899 | |||
1909 | /* i915_gem_context.c */ | 1900 | /* i915_gem_context.c */ |
1910 | void i915_gem_context_init(struct drm_device *dev); | 1901 | void i915_gem_context_init(struct drm_device *dev); |
1911 | void i915_gem_context_fini(struct drm_device *dev); | 1902 | void i915_gem_context_fini(struct drm_device *dev); |
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 4e8a6d4815fa..9e2d0f126be1 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c | |||
@@ -2631,7 +2631,7 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj) | |||
2631 | /* Avoid an unnecessary call to unbind on rebind. */ | 2631 | /* Avoid an unnecessary call to unbind on rebind. */ |
2632 | obj->map_and_fenceable = true; | 2632 | obj->map_and_fenceable = true; |
2633 | 2633 | ||
2634 | vma = __i915_gem_obj_to_vma(obj); | 2634 | vma = i915_gem_obj_to_vma(obj, &dev_priv->gtt.base); |
2635 | list_del(&vma->vma_link); | 2635 | list_del(&vma->vma_link); |
2636 | drm_mm_remove_node(&vma->node); | 2636 | drm_mm_remove_node(&vma->node); |
2637 | i915_gem_vma_destroy(vma); | 2637 | i915_gem_vma_destroy(vma); |
@@ -3319,7 +3319,7 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj, | |||
3319 | { | 3319 | { |
3320 | struct drm_device *dev = obj->base.dev; | 3320 | struct drm_device *dev = obj->base.dev; |
3321 | drm_i915_private_t *dev_priv = dev->dev_private; | 3321 | drm_i915_private_t *dev_priv = dev->dev_private; |
3322 | struct i915_vma *vma = __i915_gem_obj_to_vma(obj); | 3322 | struct i915_vma *vma = i915_gem_obj_to_vma(obj, &dev_priv->gtt.base); |
3323 | int ret; | 3323 | int ret; |
3324 | 3324 | ||
3325 | if (obj->cache_level == cache_level) | 3325 | if (obj->cache_level == cache_level) |
@@ -3359,7 +3359,7 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj, | |||
3359 | i915_ppgtt_bind_object(dev_priv->mm.aliasing_ppgtt, | 3359 | i915_ppgtt_bind_object(dev_priv->mm.aliasing_ppgtt, |
3360 | obj, cache_level); | 3360 | obj, cache_level); |
3361 | 3361 | ||
3362 | i915_gem_obj_ggtt_set_color(obj, cache_level); | 3362 | i915_gem_obj_to_vma(obj, &dev_priv->gtt.base)->node.color = cache_level; |
3363 | } | 3363 | } |
3364 | 3364 | ||
3365 | if (cache_level == I915_CACHE_NONE) { | 3365 | if (cache_level == I915_CACHE_NONE) { |
@@ -4672,3 +4672,75 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) | |||
4672 | mutex_unlock(&dev->struct_mutex); | 4672 | mutex_unlock(&dev->struct_mutex); |
4673 | return cnt; | 4673 | return cnt; |
4674 | } | 4674 | } |
4675 | |||
4676 | /* All the new VM stuff */ | ||
4677 | unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o, | ||
4678 | struct i915_address_space *vm) | ||
4679 | { | ||
4680 | struct drm_i915_private *dev_priv = o->base.dev->dev_private; | ||
4681 | struct i915_vma *vma; | ||
4682 | |||
4683 | if (vm == &dev_priv->mm.aliasing_ppgtt->base) | ||
4684 | vm = &dev_priv->gtt.base; | ||
4685 | |||
4686 | BUG_ON(list_empty(&o->vma_list)); | ||
4687 | list_for_each_entry(vma, &o->vma_list, vma_link) { | ||
4688 | if (vma->vm == vm) | ||
4689 | return vma->node.start; | ||
4690 | |||
4691 | } | ||
4692 | return -1; | ||
4693 | } | ||
4694 | |||
4695 | bool i915_gem_obj_bound(struct drm_i915_gem_object *o, | ||
4696 | struct i915_address_space *vm) | ||
4697 | { | ||
4698 | struct i915_vma *vma; | ||
4699 | |||
4700 | list_for_each_entry(vma, &o->vma_list, vma_link) | ||
4701 | if (vma->vm == vm) | ||
4702 | return true; | ||
4703 | |||
4704 | return false; | ||
4705 | } | ||
4706 | |||
4707 | bool i915_gem_obj_bound_any(struct drm_i915_gem_object *o) | ||
4708 | { | ||
4709 | struct drm_i915_private *dev_priv = o->base.dev->dev_private; | ||
4710 | struct i915_address_space *vm; | ||
4711 | |||
4712 | list_for_each_entry(vm, &dev_priv->vm_list, global_link) | ||
4713 | if (i915_gem_obj_bound(o, vm)) | ||
4714 | return true; | ||
4715 | |||
4716 | return false; | ||
4717 | } | ||
4718 | |||
4719 | unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o, | ||
4720 | struct i915_address_space *vm) | ||
4721 | { | ||
4722 | struct drm_i915_private *dev_priv = o->base.dev->dev_private; | ||
4723 | struct i915_vma *vma; | ||
4724 | |||
4725 | if (vm == &dev_priv->mm.aliasing_ppgtt->base) | ||
4726 | vm = &dev_priv->gtt.base; | ||
4727 | |||
4728 | BUG_ON(list_empty(&o->vma_list)); | ||
4729 | |||
4730 | list_for_each_entry(vma, &o->vma_list, vma_link) | ||
4731 | if (vma->vm == vm) | ||
4732 | return vma->node.size; | ||
4733 | |||
4734 | return 0; | ||
4735 | } | ||
4736 | |||
4737 | struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj, | ||
4738 | struct i915_address_space *vm) | ||
4739 | { | ||
4740 | struct i915_vma *vma; | ||
4741 | list_for_each_entry(vma, &obj->vma_list, vma_link) | ||
4742 | if (vma->vm == vm) | ||
4743 | return vma; | ||
4744 | |||
4745 | return NULL; | ||
4746 | } | ||
diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c index df61f338dea1..33d85a4447a6 100644 --- a/drivers/gpu/drm/i915/i915_gem_evict.c +++ b/drivers/gpu/drm/i915/i915_gem_evict.c | |||
@@ -34,7 +34,9 @@ | |||
34 | static bool | 34 | static bool |
35 | mark_free(struct drm_i915_gem_object *obj, struct list_head *unwind) | 35 | mark_free(struct drm_i915_gem_object *obj, struct list_head *unwind) |
36 | { | 36 | { |
37 | struct i915_vma *vma = __i915_gem_obj_to_vma(obj); | 37 | struct drm_device *dev = obj->base.dev; |
38 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
39 | struct i915_vma *vma = i915_gem_obj_to_vma(obj, &dev_priv->gtt.base); | ||
38 | 40 | ||
39 | if (obj->pin_count) | 41 | if (obj->pin_count) |
40 | return false; | 42 | return false; |
@@ -109,7 +111,7 @@ none: | |||
109 | obj = list_first_entry(&unwind_list, | 111 | obj = list_first_entry(&unwind_list, |
110 | struct drm_i915_gem_object, | 112 | struct drm_i915_gem_object, |
111 | exec_list); | 113 | exec_list); |
112 | vma = __i915_gem_obj_to_vma(obj); | 114 | vma = i915_gem_obj_to_vma(obj, &dev_priv->gtt.base); |
113 | ret = drm_mm_scan_remove_block(&vma->node); | 115 | ret = drm_mm_scan_remove_block(&vma->node); |
114 | BUG_ON(ret); | 116 | BUG_ON(ret); |
115 | 117 | ||
@@ -130,7 +132,7 @@ found: | |||
130 | obj = list_first_entry(&unwind_list, | 132 | obj = list_first_entry(&unwind_list, |
131 | struct drm_i915_gem_object, | 133 | struct drm_i915_gem_object, |
132 | exec_list); | 134 | exec_list); |
133 | vma = __i915_gem_obj_to_vma(obj); | 135 | vma = i915_gem_obj_to_vma(obj, &dev_priv->gtt.base); |
134 | if (drm_mm_scan_remove_block(&vma->node)) { | 136 | if (drm_mm_scan_remove_block(&vma->node)) { |
135 | list_move(&obj->exec_list, &eviction_list); | 137 | list_move(&obj->exec_list, &eviction_list); |
136 | drm_gem_object_reference(&obj->base); | 138 | drm_gem_object_reference(&obj->base); |
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index 3e7f1242af91..90a276e35909 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c | |||
@@ -657,7 +657,7 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, | |||
657 | 657 | ||
658 | /* Mark any preallocated objects as occupied */ | 658 | /* Mark any preallocated objects as occupied */ |
659 | list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) { | 659 | list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) { |
660 | struct i915_vma *vma = __i915_gem_obj_to_vma(obj); | 660 | struct i915_vma *vma = i915_gem_obj_to_vma(obj, &dev_priv->gtt.base); |
661 | int ret; | 661 | int ret; |
662 | DRM_DEBUG_KMS("reserving preallocated space: %lx + %zx\n", | 662 | DRM_DEBUG_KMS("reserving preallocated space: %lx + %zx\n", |
663 | i915_gem_obj_ggtt_offset(obj), obj->base.size); | 663 | i915_gem_obj_ggtt_offset(obj), obj->base.size); |