blob: 86673e77d7cb51c9ec92dd89a2ee177224dd2fc8 [file] [log] [blame]
Daniel Vetter76aaf222010-11-05 22:23:30 +01001/*
2 * Copyright © 2010 Daniel Vetter
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 */
24
25#include "drmP.h"
26#include "drm.h"
27#include "i915_drm.h"
28#include "i915_drv.h"
29#include "i915_trace.h"
30#include "intel_drv.h"
31
32void i915_gem_restore_gtt_mappings(struct drm_device *dev)
33{
34 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +000035 struct drm_i915_gem_object *obj;
Daniel Vetter76aaf222010-11-05 22:23:30 +010036
Chris Wilson05394f32010-11-08 19:18:58 +000037 list_for_each_entry(obj, &dev_priv->mm.gtt_list, gtt_list) {
Chris Wilsona8e93122010-12-08 14:28:54 +000038 i915_gem_clflush_object(obj);
39
Daniel Vetter185cbcb2010-11-06 12:12:35 +010040 if (dev_priv->mm.gtt->needs_dmar) {
Chris Wilson05394f32010-11-08 19:18:58 +000041 BUG_ON(!obj->sg_list);
Daniel Vetter185cbcb2010-11-06 12:12:35 +010042
Chris Wilson05394f32010-11-08 19:18:58 +000043 intel_gtt_insert_sg_entries(obj->sg_list,
44 obj->num_sg,
45 obj->gtt_space->start
Daniel Vetter185cbcb2010-11-06 12:12:35 +010046 >> PAGE_SHIFT,
Chris Wilson05394f32010-11-08 19:18:58 +000047 obj->agp_type);
Daniel Vetter185cbcb2010-11-06 12:12:35 +010048 } else
Chris Wilson05394f32010-11-08 19:18:58 +000049 intel_gtt_insert_pages(obj->gtt_space->start
Daniel Vetter185cbcb2010-11-06 12:12:35 +010050 >> PAGE_SHIFT,
Chris Wilson05394f32010-11-08 19:18:58 +000051 obj->base.size >> PAGE_SHIFT,
52 obj->pages,
53 obj->agp_type);
Daniel Vetter76aaf222010-11-05 22:23:30 +010054 }
55
Daniel Vetter76aaf222010-11-05 22:23:30 +010056 intel_gtt_chipset_flush();
57}
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +010058
Chris Wilson05394f32010-11-08 19:18:58 +000059int i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj)
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +010060{
Chris Wilson05394f32010-11-08 19:18:58 +000061 struct drm_device *dev = obj->base.dev;
Daniel Vetter185cbcb2010-11-06 12:12:35 +010062 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter185cbcb2010-11-06 12:12:35 +010063 int ret;
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +010064
Daniel Vetter185cbcb2010-11-06 12:12:35 +010065 if (dev_priv->mm.gtt->needs_dmar) {
Chris Wilson05394f32010-11-08 19:18:58 +000066 ret = intel_gtt_map_memory(obj->pages,
67 obj->base.size >> PAGE_SHIFT,
68 &obj->sg_list,
69 &obj->num_sg);
Daniel Vetter185cbcb2010-11-06 12:12:35 +010070 if (ret != 0)
71 return ret;
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +010072
Chris Wilson05394f32010-11-08 19:18:58 +000073 intel_gtt_insert_sg_entries(obj->sg_list,
74 obj->num_sg,
75 obj->gtt_space->start >> PAGE_SHIFT,
76 obj->agp_type);
Daniel Vetter185cbcb2010-11-06 12:12:35 +010077 } else
Chris Wilson05394f32010-11-08 19:18:58 +000078 intel_gtt_insert_pages(obj->gtt_space->start >> PAGE_SHIFT,
79 obj->base.size >> PAGE_SHIFT,
80 obj->pages,
81 obj->agp_type);
Daniel Vetter185cbcb2010-11-06 12:12:35 +010082
83 return 0;
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +010084}
85
Chris Wilson05394f32010-11-08 19:18:58 +000086void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj)
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +010087{
Chris Wilson05394f32010-11-08 19:18:58 +000088 struct drm_device *dev = obj->base.dev;
Daniel Vetter185cbcb2010-11-06 12:12:35 +010089 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +010090
Daniel Vetter185cbcb2010-11-06 12:12:35 +010091 if (dev_priv->mm.gtt->needs_dmar) {
Chris Wilson05394f32010-11-08 19:18:58 +000092 intel_gtt_unmap_memory(obj->sg_list, obj->num_sg);
93 obj->sg_list = NULL;
94 obj->num_sg = 0;
Daniel Vetter185cbcb2010-11-06 12:12:35 +010095 }
96
Chris Wilson05394f32010-11-08 19:18:58 +000097 intel_gtt_clear_range(obj->gtt_space->start >> PAGE_SHIFT,
98 obj->base.size >> PAGE_SHIFT);
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +010099}