i915_gem_gtt.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  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. #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"
  30. void i915_gem_restore_gtt_mappings(struct drm_device *dev)
  31. {
  32. struct drm_i915_private *dev_priv = dev->dev_private;
  33. struct drm_i915_gem_object *obj;
  34. list_for_each_entry(obj, &dev_priv->mm.gtt_list, gtt_list) {
  35. i915_gem_clflush_object(obj);
  36. if (dev_priv->mm.gtt->needs_dmar) {
  37. BUG_ON(!obj->sg_list);
  38. intel_gtt_insert_sg_entries(obj->sg_list,
  39. obj->num_sg,
  40. obj->gtt_space->start
  41. >> PAGE_SHIFT,
  42. obj->agp_type);
  43. } else
  44. intel_gtt_insert_pages(obj->gtt_space->start
  45. >> PAGE_SHIFT,
  46. obj->base.size >> PAGE_SHIFT,
  47. obj->pages,
  48. obj->agp_type);
  49. }
  50. intel_gtt_chipset_flush();
  51. }
  52. int i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj)
  53. {
  54. struct drm_device *dev = obj->base.dev;
  55. struct drm_i915_private *dev_priv = dev->dev_private;
  56. int ret;
  57. if (dev_priv->mm.gtt->needs_dmar) {
  58. ret = intel_gtt_map_memory(obj->pages,
  59. obj->base.size >> PAGE_SHIFT,
  60. &obj->sg_list,
  61. &obj->num_sg);
  62. if (ret != 0)
  63. return ret;
  64. intel_gtt_insert_sg_entries(obj->sg_list,
  65. obj->num_sg,
  66. obj->gtt_space->start >> PAGE_SHIFT,
  67. obj->agp_type);
  68. } else
  69. intel_gtt_insert_pages(obj->gtt_space->start >> PAGE_SHIFT,
  70. obj->base.size >> PAGE_SHIFT,
  71. obj->pages,
  72. obj->agp_type);
  73. return 0;
  74. }
  75. void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj)
  76. {
  77. intel_gtt_clear_range(obj->gtt_space->start >> PAGE_SHIFT,
  78. obj->base.size >> PAGE_SHIFT);
  79. if (obj->sg_list) {
  80. intel_gtt_unmap_memory(obj->sg_list, obj->num_sg);
  81. obj->sg_list = NULL;
  82. }
  83. }