Path: blob/master/drivers/gpu/drm/i915/i915_gem_gtt.c
15113 views
/*1* Copyright © 2010 Daniel Vetter2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22*/2324#include "drmP.h"25#include "drm.h"26#include "i915_drm.h"27#include "i915_drv.h"28#include "i915_trace.h"29#include "intel_drv.h"3031/* XXX kill agp_type! */32static unsigned int cache_level_to_agp_type(struct drm_device *dev,33enum i915_cache_level cache_level)34{35switch (cache_level) {36case I915_CACHE_LLC_MLC:37if (INTEL_INFO(dev)->gen >= 6)38return AGP_USER_CACHED_MEMORY_LLC_MLC;39/* Older chipsets do not have this extra level of CPU40* cacheing, so fallthrough and request the PTE simply41* as cached.42*/43case I915_CACHE_LLC:44return AGP_USER_CACHED_MEMORY;45default:46case I915_CACHE_NONE:47return AGP_USER_MEMORY;48}49}5051void i915_gem_restore_gtt_mappings(struct drm_device *dev)52{53struct drm_i915_private *dev_priv = dev->dev_private;54struct drm_i915_gem_object *obj;5556/* First fill our portion of the GTT with scratch pages */57intel_gtt_clear_range(dev_priv->mm.gtt_start / PAGE_SIZE,58(dev_priv->mm.gtt_end - dev_priv->mm.gtt_start) / PAGE_SIZE);5960list_for_each_entry(obj, &dev_priv->mm.gtt_list, gtt_list) {61unsigned int agp_type =62cache_level_to_agp_type(dev, obj->cache_level);6364i915_gem_clflush_object(obj);6566if (dev_priv->mm.gtt->needs_dmar) {67BUG_ON(!obj->sg_list);6869intel_gtt_insert_sg_entries(obj->sg_list,70obj->num_sg,71obj->gtt_space->start >> PAGE_SHIFT,72agp_type);73} else74intel_gtt_insert_pages(obj->gtt_space->start75>> PAGE_SHIFT,76obj->base.size >> PAGE_SHIFT,77obj->pages,78agp_type);79}8081intel_gtt_chipset_flush();82}8384int i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj)85{86struct drm_device *dev = obj->base.dev;87struct drm_i915_private *dev_priv = dev->dev_private;88unsigned int agp_type = cache_level_to_agp_type(dev, obj->cache_level);89int ret;9091if (dev_priv->mm.gtt->needs_dmar) {92ret = intel_gtt_map_memory(obj->pages,93obj->base.size >> PAGE_SHIFT,94&obj->sg_list,95&obj->num_sg);96if (ret != 0)97return ret;9899intel_gtt_insert_sg_entries(obj->sg_list,100obj->num_sg,101obj->gtt_space->start >> PAGE_SHIFT,102agp_type);103} else104intel_gtt_insert_pages(obj->gtt_space->start >> PAGE_SHIFT,105obj->base.size >> PAGE_SHIFT,106obj->pages,107agp_type);108109return 0;110}111112void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj)113{114intel_gtt_clear_range(obj->gtt_space->start >> PAGE_SHIFT,115obj->base.size >> PAGE_SHIFT);116117if (obj->sg_list) {118intel_gtt_unmap_memory(obj->sg_list, obj->num_sg);119obj->sg_list = NULL;120}121}122123124