aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i915/i915_gem.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/i915/i915_gem.c')
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c74
1 files changed, 41 insertions, 33 deletions
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 6b4a2bd20640..d58ddef468f8 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -31,6 +31,8 @@
31#include "i915_drv.h" 31#include "i915_drv.h"
32#include <linux/swap.h> 32#include <linux/swap.h>
33 33
34#define I915_GEM_GPU_DOMAINS (~(I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT))
35
34static int 36static int
35i915_gem_object_set_domain(struct drm_gem_object *obj, 37i915_gem_object_set_domain(struct drm_gem_object *obj,
36 uint32_t read_domains, 38 uint32_t read_domains,
@@ -83,20 +85,14 @@ int
83i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data, 85i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
84 struct drm_file *file_priv) 86 struct drm_file *file_priv)
85{ 87{
86 drm_i915_private_t *dev_priv = dev->dev_private;
87 struct drm_i915_gem_get_aperture *args = data; 88 struct drm_i915_gem_get_aperture *args = data;
88 struct drm_i915_gem_object *obj_priv;
89 89
90 if (!(dev->driver->driver_features & DRIVER_GEM)) 90 if (!(dev->driver->driver_features & DRIVER_GEM))
91 return -ENODEV; 91 return -ENODEV;
92 92
93 args->aper_size = dev->gtt_total; 93 args->aper_size = dev->gtt_total;
94 args->aper_available_size = args->aper_size; 94 args->aper_available_size = (args->aper_size -
95 95 atomic_read(&dev->pin_memory));
96 list_for_each_entry(obj_priv, &dev_priv->mm.active_list, list) {
97 if (obj_priv->pin_count > 0)
98 args->aper_available_size -= obj_priv->obj->size;
99 }
100 96
101 return 0; 97 return 0;
102} 98}
@@ -1870,17 +1866,6 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
1870 1866
1871 for (i = 0; i < args->buffer_count; i++) { 1867 for (i = 0; i < args->buffer_count; i++) {
1872 struct drm_gem_object *obj = object_list[i]; 1868 struct drm_gem_object *obj = object_list[i];
1873 struct drm_i915_gem_object *obj_priv = obj->driver_private;
1874
1875 if (obj_priv->gtt_space == NULL) {
1876 /* We evicted the buffer in the process of validating
1877 * our set of buffers in. We could try to recover by
1878 * kicking them everything out and trying again from
1879 * the start.
1880 */
1881 ret = -ENOMEM;
1882 goto err;
1883 }
1884 1869
1885 /* make sure all previous memory operations have passed */ 1870 /* make sure all previous memory operations have passed */
1886 ret = i915_gem_object_set_domain(obj, 1871 ret = i915_gem_object_set_domain(obj,
@@ -2299,29 +2284,52 @@ i915_gem_idle(struct drm_device *dev)
2299 2284
2300 i915_gem_retire_requests(dev); 2285 i915_gem_retire_requests(dev);
2301 2286
2302 /* Active and flushing should now be empty as we've 2287 if (!dev_priv->mm.wedged) {
2303 * waited for a sequence higher than any pending execbuffer 2288 /* Active and flushing should now be empty as we've
2304 */ 2289 * waited for a sequence higher than any pending execbuffer
2305 BUG_ON(!list_empty(&dev_priv->mm.active_list)); 2290 */
2306 BUG_ON(!list_empty(&dev_priv->mm.flushing_list)); 2291 WARN_ON(!list_empty(&dev_priv->mm.active_list));
2292 WARN_ON(!list_empty(&dev_priv->mm.flushing_list));
2293 /* Request should now be empty as we've also waited
2294 * for the last request in the list
2295 */
2296 WARN_ON(!list_empty(&dev_priv->mm.request_list));
2297 }
2307 2298
2308 /* Request should now be empty as we've also waited 2299 /* Empty the active and flushing lists to inactive. If there's
2309 * for the last request in the list 2300 * anything left at this point, it means that we're wedged and
2301 * nothing good's going to happen by leaving them there. So strip
2302 * the GPU domains and just stuff them onto inactive.
2310 */ 2303 */
2311 BUG_ON(!list_empty(&dev_priv->mm.request_list)); 2304 while (!list_empty(&dev_priv->mm.active_list)) {
2305 struct drm_i915_gem_object *obj_priv;
2306
2307 obj_priv = list_first_entry(&dev_priv->mm.active_list,
2308 struct drm_i915_gem_object,
2309 list);
2310 obj_priv->obj->write_domain &= ~I915_GEM_GPU_DOMAINS;
2311 i915_gem_object_move_to_inactive(obj_priv->obj);
2312 }
2313
2314 while (!list_empty(&dev_priv->mm.flushing_list)) {
2315 struct drm_i915_gem_object *obj_priv;
2316
2317 obj_priv = list_first_entry(&dev_priv->mm.flushing_list,
2318 struct drm_i915_gem_object,
2319 list);
2320 obj_priv->obj->write_domain &= ~I915_GEM_GPU_DOMAINS;
2321 i915_gem_object_move_to_inactive(obj_priv->obj);
2322 }
2312 2323
2313 /* Move all buffers out of the GTT. */ 2324
2325 /* Move all inactive buffers out of the GTT. */
2314 ret = i915_gem_evict_from_list(dev, &dev_priv->mm.inactive_list); 2326 ret = i915_gem_evict_from_list(dev, &dev_priv->mm.inactive_list);
2327 WARN_ON(!list_empty(&dev_priv->mm.inactive_list));
2315 if (ret) { 2328 if (ret) {
2316 mutex_unlock(&dev->struct_mutex); 2329 mutex_unlock(&dev->struct_mutex);
2317 return ret; 2330 return ret;
2318 } 2331 }
2319 2332
2320 BUG_ON(!list_empty(&dev_priv->mm.active_list));
2321 BUG_ON(!list_empty(&dev_priv->mm.flushing_list));
2322 BUG_ON(!list_empty(&dev_priv->mm.inactive_list));
2323 BUG_ON(!list_empty(&dev_priv->mm.request_list));
2324
2325 i915_gem_cleanup_ringbuffer(dev); 2333 i915_gem_cleanup_ringbuffer(dev);
2326 mutex_unlock(&dev->struct_mutex); 2334 mutex_unlock(&dev->struct_mutex);
2327 2335