Commit a4f5ea64 authored by Chris Wilson's avatar Chris Wilson

drm/i915: Refactor object page API

The plan is to make obtaining the backing storage for the object avoid
struct_mutex (i.e. use its own locking). The first step is to update the
API so that normal users only call pin/unpin whilst working on the
backing storage.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161028125858.23563-12-chris@chris-wilson.co.uk
parent d2a84a76
...@@ -1290,7 +1290,7 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine, ...@@ -1290,7 +1290,7 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
} }
if (ret == 0 && needs_clflush_after) if (ret == 0 && needs_clflush_after)
drm_clflush_virt_range(shadow_batch_obj->mapping, batch_len); drm_clflush_virt_range(shadow_batch_obj->mm.mapping, batch_len);
i915_gem_object_unpin_map(shadow_batch_obj); i915_gem_object_unpin_map(shadow_batch_obj);
return ret; return ret;
......
...@@ -112,7 +112,7 @@ static char get_global_flag(struct drm_i915_gem_object *obj) ...@@ -112,7 +112,7 @@ static char get_global_flag(struct drm_i915_gem_object *obj)
static char get_pin_mapped_flag(struct drm_i915_gem_object *obj) static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
{ {
return obj->mapping ? 'M' : ' '; return obj->mm.mapping ? 'M' : ' ';
} }
static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj) static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
...@@ -158,8 +158,8 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj) ...@@ -158,8 +158,8 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
i915_gem_active_get_seqno(&obj->last_write, i915_gem_active_get_seqno(&obj->last_write,
&obj->base.dev->struct_mutex), &obj->base.dev->struct_mutex),
i915_cache_level_str(dev_priv, obj->cache_level), i915_cache_level_str(dev_priv, obj->cache_level),
obj->dirty ? " dirty" : "", obj->mm.dirty ? " dirty" : "",
obj->madv == I915_MADV_DONTNEED ? " purgeable" : ""); obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
if (obj->base.name) if (obj->base.name)
seq_printf(m, " (name: %d)", obj->base.name); seq_printf(m, " (name: %d)", obj->base.name);
list_for_each_entry(vma, &obj->vma_list, obj_link) { list_for_each_entry(vma, &obj->vma_list, obj_link) {
...@@ -403,12 +403,12 @@ static int i915_gem_object_info(struct seq_file *m, void *data) ...@@ -403,12 +403,12 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
size += obj->base.size; size += obj->base.size;
++count; ++count;
if (obj->madv == I915_MADV_DONTNEED) { if (obj->mm.madv == I915_MADV_DONTNEED) {
purgeable_size += obj->base.size; purgeable_size += obj->base.size;
++purgeable_count; ++purgeable_count;
} }
if (obj->mapping) { if (obj->mm.mapping) {
mapped_count++; mapped_count++;
mapped_size += obj->base.size; mapped_size += obj->base.size;
} }
...@@ -425,12 +425,12 @@ static int i915_gem_object_info(struct seq_file *m, void *data) ...@@ -425,12 +425,12 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
++dpy_count; ++dpy_count;
} }
if (obj->madv == I915_MADV_DONTNEED) { if (obj->mm.madv == I915_MADV_DONTNEED) {
purgeable_size += obj->base.size; purgeable_size += obj->base.size;
++purgeable_count; ++purgeable_count;
} }
if (obj->mapping) { if (obj->mm.mapping) {
mapped_count++; mapped_count++;
mapped_size += obj->base.size; mapped_size += obj->base.size;
} }
...@@ -2028,7 +2028,7 @@ static void i915_dump_lrc_obj(struct seq_file *m, ...@@ -2028,7 +2028,7 @@ static void i915_dump_lrc_obj(struct seq_file *m,
seq_printf(m, "\tBound in GGTT at 0x%08x\n", seq_printf(m, "\tBound in GGTT at 0x%08x\n",
i915_ggtt_offset(vma)); i915_ggtt_offset(vma));
if (i915_gem_object_get_pages(vma->obj)) { if (i915_gem_object_pin_pages(vma->obj)) {
seq_puts(m, "\tFailed to get pages for context object\n\n"); seq_puts(m, "\tFailed to get pages for context object\n\n");
return; return;
} }
...@@ -2047,6 +2047,7 @@ static void i915_dump_lrc_obj(struct seq_file *m, ...@@ -2047,6 +2047,7 @@ static void i915_dump_lrc_obj(struct seq_file *m,
kunmap_atomic(reg_state); kunmap_atomic(reg_state);
} }
i915_gem_object_unpin_pages(vma->obj);
seq_putc(m, '\n'); seq_putc(m, '\n');
} }
......
...@@ -2252,17 +2252,6 @@ struct drm_i915_gem_object { ...@@ -2252,17 +2252,6 @@ struct drm_i915_gem_object {
*/ */
#define I915_BO_ACTIVE_REF (I915_BO_ACTIVE_SHIFT + I915_NUM_ENGINES) #define I915_BO_ACTIVE_REF (I915_BO_ACTIVE_SHIFT + I915_NUM_ENGINES)
/**
* This is set if the object has been written to since last bound
* to the GTT
*/
unsigned int dirty:1;
/**
* Advice: are the backing pages purgeable?
*/
unsigned int madv:2;
/* /*
* Is the object to be mapped as read-only to the GPU * Is the object to be mapped as read-only to the GPU
* Only honoured if hardware has relevant pte bit * Only honoured if hardware has relevant pte bit
...@@ -2284,16 +2273,31 @@ struct drm_i915_gem_object { ...@@ -2284,16 +2273,31 @@ struct drm_i915_gem_object {
unsigned int bind_count; unsigned int bind_count;
unsigned int pin_display; unsigned int pin_display;
struct sg_table *pages; struct {
int pages_pin_count; unsigned int pages_pin_count;
struct i915_gem_object_page_iter {
struct scatterlist *sg_pos; struct sg_table *pages;
unsigned int sg_idx; /* in pages, but 32bit eek! */ void *mapping;
struct radix_tree_root radix; struct i915_gem_object_page_iter {
struct mutex lock; /* protects this cache */ struct scatterlist *sg_pos;
} get_page; unsigned int sg_idx; /* in pages, but 32bit eek! */
void *mapping;
struct radix_tree_root radix;
struct mutex lock; /* protects this cache */
} get_page;
/**
* Advice: are the backing pages purgeable?
*/
unsigned int madv:2;
/**
* This is set if the object has been written to since the
* pages were last acquired.
*/
bool dirty:1;
} mm;
/** Breadcrumb of last rendering to the buffer. /** Breadcrumb of last rendering to the buffer.
* There can only be one writer, but we allow for multiple readers. * There can only be one writer, but we allow for multiple readers.
...@@ -3182,14 +3186,11 @@ void i915_vma_close(struct i915_vma *vma); ...@@ -3182,14 +3186,11 @@ void i915_vma_close(struct i915_vma *vma);
void i915_vma_destroy(struct i915_vma *vma); void i915_vma_destroy(struct i915_vma *vma);
int i915_gem_object_unbind(struct drm_i915_gem_object *obj); int i915_gem_object_unbind(struct drm_i915_gem_object *obj);
int i915_gem_object_put_pages(struct drm_i915_gem_object *obj);
void i915_gem_release_mmap(struct drm_i915_gem_object *obj); void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
void i915_gem_runtime_suspend(struct drm_i915_private *dev_priv); void i915_gem_runtime_suspend(struct drm_i915_private *dev_priv);
int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj); static inline int __sg_page_count(const struct scatterlist *sg)
static inline int __sg_page_count(struct scatterlist *sg)
{ {
return sg->length >> PAGE_SHIFT; return sg->length >> PAGE_SHIFT;
} }
...@@ -3210,19 +3211,52 @@ dma_addr_t ...@@ -3210,19 +3211,52 @@ dma_addr_t
i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj, i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj,
unsigned long n); unsigned long n);
static inline void i915_gem_object_pin_pages(struct drm_i915_gem_object *obj) int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
static inline int __must_check
i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
{
lockdep_assert_held(&obj->base.dev->struct_mutex);
if (obj->mm.pages_pin_count++)
return 0;
return __i915_gem_object_get_pages(obj);
}
static inline void
__i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
{ {
GEM_BUG_ON(obj->pages == NULL); lockdep_assert_held(&obj->base.dev->struct_mutex);
obj->pages_pin_count++; GEM_BUG_ON(!obj->mm.pages);
obj->mm.pages_pin_count++;
}
static inline bool
i915_gem_object_has_pinned_pages(struct drm_i915_gem_object *obj)
{
return obj->mm.pages_pin_count;
}
static inline void
__i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
{
lockdep_assert_held(&obj->base.dev->struct_mutex);
GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
GEM_BUG_ON(!obj->mm.pages);
obj->mm.pages_pin_count--;
GEM_BUG_ON(obj->mm.pages_pin_count < obj->bind_count);
} }
static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj) static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
{ {
GEM_BUG_ON(obj->pages_pin_count == 0); __i915_gem_object_unpin_pages(obj);
obj->pages_pin_count--;
GEM_BUG_ON(obj->pages_pin_count < obj->bind_count);
} }
int __i915_gem_object_put_pages(struct drm_i915_gem_object *obj);
enum i915_map_type { enum i915_map_type {
I915_MAP_WB = 0, I915_MAP_WB = 0,
I915_MAP_WC, I915_MAP_WC,
......
This diff is collapsed.
...@@ -130,11 +130,10 @@ i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool, ...@@ -130,11 +130,10 @@ i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,
return obj; return obj;
} }
ret = i915_gem_object_get_pages(obj); ret = i915_gem_object_pin_pages(obj);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
list_move_tail(&obj->batch_pool_link, list); list_move_tail(&obj->batch_pool_link, list);
i915_gem_object_pin_pages(obj);
return obj; return obj;
} }
...@@ -48,12 +48,10 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme ...@@ -48,12 +48,10 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme
if (ret) if (ret)
goto err; goto err;
ret = i915_gem_object_get_pages(obj); ret = i915_gem_object_pin_pages(obj);
if (ret) if (ret)
goto err_unlock; goto err_unlock;
i915_gem_object_pin_pages(obj);
/* Copy sg so that we make an independent mapping */ /* Copy sg so that we make an independent mapping */
st = kmalloc(sizeof(struct sg_table), GFP_KERNEL); st = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
if (st == NULL) { if (st == NULL) {
...@@ -61,13 +59,13 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme ...@@ -61,13 +59,13 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme
goto err_unpin; goto err_unpin;
} }
ret = sg_alloc_table(st, obj->pages->nents, GFP_KERNEL); ret = sg_alloc_table(st, obj->mm.pages->nents, GFP_KERNEL);
if (ret) if (ret)
goto err_free; goto err_free;
src = obj->pages->sgl; src = obj->mm.pages->sgl;
dst = st->sgl; dst = st->sgl;
for (i = 0; i < obj->pages->nents; i++) { for (i = 0; i < obj->mm.pages->nents; i++) {
sg_set_page(dst, sg_page(src), src->length, 0); sg_set_page(dst, sg_page(src), src->length, 0);
dst = sg_next(dst); dst = sg_next(dst);
src = sg_next(src); src = sg_next(src);
...@@ -299,14 +297,14 @@ static int i915_gem_object_get_pages_dmabuf(struct drm_i915_gem_object *obj) ...@@ -299,14 +297,14 @@ static int i915_gem_object_get_pages_dmabuf(struct drm_i915_gem_object *obj)
if (IS_ERR(sg)) if (IS_ERR(sg))
return PTR_ERR(sg); return PTR_ERR(sg);
obj->pages = sg; obj->mm.pages = sg;
return 0; return 0;
} }
static void i915_gem_object_put_pages_dmabuf(struct drm_i915_gem_object *obj) static void i915_gem_object_put_pages_dmabuf(struct drm_i915_gem_object *obj)
{ {
dma_buf_unmap_attachment(obj->base.import_attach, dma_buf_unmap_attachment(obj->base.import_attach,
obj->pages, DMA_BIDIRECTIONAL); obj->mm.pages, DMA_BIDIRECTIONAL);
} }
static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = { static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = {
......
...@@ -1281,7 +1281,7 @@ void i915_vma_move_to_active(struct i915_vma *vma, ...@@ -1281,7 +1281,7 @@ void i915_vma_move_to_active(struct i915_vma *vma,
GEM_BUG_ON(!drm_mm_node_allocated(&vma->node)); GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
obj->dirty = 1; /* be paranoid */ obj->mm.dirty = true; /* be paranoid */
/* Add a reference if we're newly entering the active list. /* Add a reference if we're newly entering the active list.
* The order in which we add operations to the retirement queue is * The order in which we add operations to the retirement queue is
......
...@@ -664,7 +664,7 @@ i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj) ...@@ -664,7 +664,7 @@ i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj)
return; return;
i = 0; i = 0;
for_each_sgt_page(page, sgt_iter, obj->pages) { for_each_sgt_page(page, sgt_iter, obj->mm.pages) {
char new_bit_17 = page_to_phys(page) >> 17; char new_bit_17 = page_to_phys(page) >> 17;
if ((new_bit_17 & 0x1) != if ((new_bit_17 & 0x1) !=
(test_bit(i, obj->bit_17) != 0)) { (test_bit(i, obj->bit_17) != 0)) {
...@@ -703,7 +703,7 @@ i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj) ...@@ -703,7 +703,7 @@ i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj)
i = 0; i = 0;
for_each_sgt_page(page, sgt_iter, obj->pages) { for_each_sgt_page(page, sgt_iter, obj->mm.pages) {
if (page_to_phys(page) & (1 << 17)) if (page_to_phys(page) & (1 << 17))
__set_bit(i, obj->bit_17); __set_bit(i, obj->bit_17);
else else
......
...@@ -175,7 +175,7 @@ static int ppgtt_bind_vma(struct i915_vma *vma, ...@@ -175,7 +175,7 @@ static int ppgtt_bind_vma(struct i915_vma *vma,
{ {
u32 pte_flags = 0; u32 pte_flags = 0;
vma->pages = vma->obj->pages; vma->pages = vma->obj->mm.pages;
/* Currently applicable only to VLV */ /* Currently applicable only to VLV */
if (vma->obj->gt_ro) if (vma->obj->gt_ro)
...@@ -2373,7 +2373,7 @@ void i915_gem_suspend_gtt_mappings(struct drm_device *dev) ...@@ -2373,7 +2373,7 @@ void i915_gem_suspend_gtt_mappings(struct drm_device *dev)
int i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj) int i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj)
{ {
if (!dma_map_sg(&obj->base.dev->pdev->dev, if (!dma_map_sg(&obj->base.dev->pdev->dev,
obj->pages->sgl, obj->pages->nents, obj->mm.pages->sgl, obj->mm.pages->nents,
PCI_DMA_BIDIRECTIONAL)) PCI_DMA_BIDIRECTIONAL))
return -ENOSPC; return -ENOSPC;
...@@ -2710,7 +2710,7 @@ void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj) ...@@ -2710,7 +2710,7 @@ void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj)
} }
} }
dma_unmap_sg(kdev, obj->pages->sgl, obj->pages->nents, dma_unmap_sg(kdev, obj->mm.pages->sgl, obj->mm.pages->nents,
PCI_DMA_BIDIRECTIONAL); PCI_DMA_BIDIRECTIONAL);
} }
...@@ -3548,7 +3548,7 @@ intel_rotate_fb_obj_pages(const struct intel_rotation_info *rot_info, ...@@ -3548,7 +3548,7 @@ intel_rotate_fb_obj_pages(const struct intel_rotation_info *rot_info,
/* Populate source page list from the object. */ /* Populate source page list from the object. */
i = 0; i = 0;
for_each_sgt_dma(dma_addr, sgt_iter, obj->pages) for_each_sgt_dma(dma_addr, sgt_iter, obj->mm.pages)
page_addr_list[i++] = dma_addr; page_addr_list[i++] = dma_addr;
GEM_BUG_ON(i != n_pages); GEM_BUG_ON(i != n_pages);
...@@ -3641,7 +3641,7 @@ i915_get_ggtt_vma_pages(struct i915_vma *vma) ...@@ -3641,7 +3641,7 @@ i915_get_ggtt_vma_pages(struct i915_vma *vma)
return 0; return 0;
if (vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) if (vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL)
vma->pages = vma->obj->pages; vma->pages = vma->obj->mm.pages;
else if (vma->ggtt_view.type == I915_GGTT_VIEW_ROTATED) else if (vma->ggtt_view.type == I915_GGTT_VIEW_ROTATED)
vma->pages = vma->pages =
intel_rotate_fb_obj_pages(&vma->ggtt_view.params.rotated, vma->obj); intel_rotate_fb_obj_pages(&vma->ggtt_view.params.rotated, vma->obj);
......
...@@ -102,10 +102,10 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj) ...@@ -102,10 +102,10 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj)
sg = __sg_next(sg); sg = __sg_next(sg);
} while (1); } while (1);
obj->pages = st; obj->mm.pages = st;
if (i915_gem_gtt_prepare_object(obj)) { if (i915_gem_gtt_prepare_object(obj)) {
obj->pages = NULL; obj->mm.pages = NULL;
goto err; goto err;
} }
...@@ -114,7 +114,7 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj) ...@@ -114,7 +114,7 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj)
* and the caller is expected to repopulate - the contents of this * and the caller is expected to repopulate - the contents of this
* object are only valid whilst active and pinned. * object are only valid whilst active and pinned.
*/ */
obj->madv = I915_MADV_DONTNEED; obj->mm.madv = I915_MADV_DONTNEED;
return 0; return 0;
err: err:
...@@ -126,10 +126,10 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj) ...@@ -126,10 +126,10 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj)
static void i915_gem_object_put_pages_internal(struct drm_i915_gem_object *obj) static void i915_gem_object_put_pages_internal(struct drm_i915_gem_object *obj)
{ {
i915_gem_gtt_finish_object(obj); i915_gem_gtt_finish_object(obj);
internal_free_pages(obj->pages); internal_free_pages(obj->mm.pages);
obj->dirty = 0; obj->mm.dirty = false;
obj->madv = I915_MADV_WILLNEED; obj->mm.madv = I915_MADV_WILLNEED;
} }
static const struct drm_i915_gem_object_ops i915_gem_object_internal_ops = { static const struct drm_i915_gem_object_ops i915_gem_object_internal_ops = {
......
...@@ -230,7 +230,7 @@ int i915_gem_render_state_emit(struct drm_i915_gem_request *req) ...@@ -230,7 +230,7 @@ int i915_gem_render_state_emit(struct drm_i915_gem_request *req)
return 0; return 0;
/* Recreate the page after shrinking */ /* Recreate the page after shrinking */
if (!so->vma->obj->pages) if (!so->vma->obj->mm.pages)
so->batch_offset = -1; so->batch_offset = -1;
ret = i915_vma_pin(so->vma, 0, 0, PIN_GLOBAL | PIN_HIGH); ret = i915_vma_pin(so->vma, 0, 0, PIN_GLOBAL | PIN_HIGH);
......
...@@ -78,7 +78,7 @@ static bool can_release_pages(struct drm_i915_gem_object *obj) ...@@ -78,7 +78,7 @@ static bool can_release_pages(struct drm_i915_gem_object *obj)
* to the GPU, simply unbinding from the GPU is not going to succeed * to the GPU, simply unbinding from the GPU is not going to succeed
* in releasing our pin count on the pages themselves. * in releasing our pin count on the pages themselves.
*/ */
if (obj->pages_pin_count > obj->bind_count) if (obj->mm.pages_pin_count > obj->bind_count)
return false; return false;
if (any_vma_pinned(obj)) if (any_vma_pinned(obj))
...@@ -88,7 +88,7 @@ static bool can_release_pages(struct drm_i915_gem_object *obj) ...@@ -88,7 +88,7 @@ static bool can_release_pages(struct drm_i915_gem_object *obj)
* discard the contents (because the user has marked them as being * discard the contents (because the user has marked them as being
* purgeable) or if we can move their contents out to swap. * purgeable) or if we can move their contents out to swap.
*/ */
return swap_available() || obj->madv == I915_MADV_DONTNEED; return swap_available() || obj->mm.madv == I915_MADV_DONTNEED;
} }
/** /**
...@@ -175,11 +175,11 @@ i915_gem_shrink(struct drm_i915_private *dev_priv, ...@@ -175,11 +175,11 @@ i915_gem_shrink(struct drm_i915_private *dev_priv,
list_move_tail(&obj->global_list, &still_in_list); list_move_tail(&obj->global_list, &still_in_list);
if (flags & I915_SHRINK_PURGEABLE && if (flags & I915_SHRINK_PURGEABLE &&
obj->madv != I915_MADV_DONTNEED) obj->mm.madv != I915_MADV_DONTNEED)
continue; continue;
if (flags & I915_SHRINK_VMAPS && if (flags & I915_SHRINK_VMAPS &&
!is_vmalloc_addr(obj->mapping)) !is_vmalloc_addr(obj->mm.mapping))
continue; continue;
if (!(flags & I915_SHRINK_ACTIVE) && if (!(flags & I915_SHRINK_ACTIVE) &&
...@@ -194,7 +194,7 @@ i915_gem_shrink(struct drm_i915_private *dev_priv, ...@@ -194,7 +194,7 @@ i915_gem_shrink(struct drm_i915_private *dev_priv,
/* For the unbound phase, this should be a no-op! */ /* For the unbound phase, this should be a no-op! */
i915_gem_object_unbind(obj); i915_gem_object_unbind(obj);
if (i915_gem_object_put_pages(obj) == 0) if (__i915_gem_object_put_pages(obj) == 0)
count += obj->base.size >> PAGE_SHIFT; count += obj->base.size >> PAGE_SHIFT;
i915_gem_object_put(obj); i915_gem_object_put(obj);
......
...@@ -555,16 +555,17 @@ static int i915_gem_object_get_pages_stolen(struct drm_i915_gem_object *obj) ...@@ -555,16 +555,17 @@ static int i915_gem_object_get_pages_stolen(struct drm_i915_gem_object *obj)
static void i915_gem_object_put_pages_stolen(struct drm_i915_gem_object *obj) static void i915_gem_object_put_pages_stolen(struct drm_i915_gem_object *obj)
{ {
/* Should only be called during free */ /* Should only be called during free */
sg_free_table(obj->pages); sg_free_table(obj->mm.pages);
kfree(obj->pages); kfree(obj->mm.pages);
} }
static void static void
i915_gem_object_release_stolen(struct drm_i915_gem_object *obj) i915_gem_object_release_stolen(struct drm_i915_gem_object *obj)
{ {
struct drm_i915_private *dev_priv = to_i915(obj->base.dev); struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
__i915_gem_object_unpin_pages(obj);
if (obj->stolen) { if (obj->stolen) {
i915_gem_stolen_remove_node(dev_priv, obj->stolen); i915_gem_stolen_remove_node(dev_priv, obj->stolen);
kfree(obj->stolen); kfree(obj->stolen);
...@@ -590,15 +591,16 @@ _i915_gem_object_create_stolen(struct drm_device *dev, ...@@ -590,15 +591,16 @@ _i915_gem_object_create_stolen(struct drm_device *dev,
drm_gem_private_object_init(dev, &obj->base, stolen->size); drm_gem_private_object_init(dev, &obj->base, stolen->size);
i915_gem_object_init(obj, &i915_gem_object_stolen_ops); i915_gem_object_init(obj, &i915_gem_object_stolen_ops);
obj->pages = i915_pages_create_for_stolen(dev, obj->mm.pages = i915_pages_create_for_stolen(dev,
stolen->start, stolen->size); stolen->start,
if (obj->pages == NULL) stolen->size);
if (!obj->mm.pages)
goto cleanup; goto cleanup;
obj->get_page.sg_pos = obj->pages->sgl; obj->mm.get_page.sg_pos = obj->mm.pages->sgl;
obj->get_page.sg_idx = 0; obj->mm.get_page.sg_idx = 0;
i915_gem_object_pin_pages(obj); __i915_gem_object_pin_pages(obj);
obj->stolen = stolen; obj->stolen = stolen;
obj->base.read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT; obj->base.read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
...@@ -718,14 +720,14 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev, ...@@ -718,14 +720,14 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
goto err; goto err;
} }
vma->pages = obj->pages; vma->pages = obj->mm.pages;
vma->flags |= I915_VMA_GLOBAL_BIND; vma->flags |= I915_VMA_GLOBAL_BIND;
__i915_vma_set_map_and_fenceable(vma); __i915_vma_set_map_and_fenceable(vma);
list_move_tail(&vma->vm_link, &ggtt->base.inactive_list); list_move_tail(&vma->vm_link, &ggtt->base.inactive_list);
obj->bind_count++; obj->bind_count++;
list_add_tail(&obj->global_list, &dev_priv->mm.bound_list); list_add_tail(&obj->global_list, &dev_priv->mm.bound_list);
i915_gem_object_pin_pages(obj); __i915_gem_object_pin_pages(obj);
return obj; return obj;
......
...@@ -259,13 +259,13 @@ i915_gem_set_tiling(struct drm_device *dev, void *data, ...@@ -259,13 +259,13 @@ i915_gem_set_tiling(struct drm_device *dev, void *data,
if (!err) { if (!err) {
struct i915_vma *vma; struct i915_vma *vma;
if (obj->pages && if (obj->mm.pages &&
obj->madv == I915_MADV_WILLNEED && obj->mm.madv == I915_MADV_WILLNEED &&
dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES) { dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES) {
if (args->tiling_mode == I915_TILING_NONE) if (args->tiling_mode == I915_TILING_NONE)
i915_gem_object_unpin_pages(obj); __i915_gem_object_unpin_pages(obj);
if (!i915_gem_object_is_tiled(obj)) if (!i915_gem_object_is_tiled(obj))
i915_gem_object_pin_pages(obj); __i915_gem_object_pin_pages(obj);
} }
list_for_each_entry(vma, &obj->vma_list, obj_link) { list_for_each_entry(vma, &obj->vma_list, obj_link) {
......
...@@ -73,10 +73,10 @@ static void cancel_userptr(struct work_struct *work) ...@@ -73,10 +73,10 @@ static void cancel_userptr(struct work_struct *work)
/* Cancel any active worker and force us to re-evaluate gup */ /* Cancel any active worker and force us to re-evaluate gup */
obj->userptr.work = NULL; obj->userptr.work = NULL;
if (obj->pages != NULL) { if (obj->mm.pages) {
/* We are inside a kthread context and can't be interrupted */ /* We are inside a kthread context and can't be interrupted */
WARN_ON(i915_gem_object_unbind(obj)); WARN_ON(i915_gem_object_unbind(obj));
WARN_ON(i915_gem_object_put_pages(obj)); WARN_ON(__i915_gem_object_put_pages(obj));
} }
i915_gem_object_put(obj); i915_gem_object_put(obj);
...@@ -432,15 +432,15 @@ __i915_gem_userptr_set_pages(struct drm_i915_gem_object *obj, ...@@ -432,15 +432,15 @@ __i915_gem_userptr_set_pages(struct drm_i915_gem_object *obj,
{ {
int ret; int ret;
ret = st_set_pages(&obj->pages, pvec, num_pages); ret = st_set_pages(&obj->mm.pages, pvec, num_pages);
if (ret) if (ret)
return ret; return ret;
ret = i915_gem_gtt_prepare_object(obj); ret = i915_gem_gtt_prepare_object(obj);
if (ret) { if (ret) {
sg_free_table(obj->pages); sg_free_table(obj->mm.pages);
kfree(obj->pages); kfree(obj->mm.pages);
obj->pages = NULL; obj->mm.pages = NULL;
} }
return ret; return ret;
...@@ -530,8 +530,8 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work) ...@@ -530,8 +530,8 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work)
if (ret == 0) { if (ret == 0) {
list_add_tail(&obj->global_list, list_add_tail(&obj->global_list,
&to_i915(dev)->mm.unbound_list); &to_i915(dev)->mm.unbound_list);
obj->get_page.sg_pos = obj->pages->sgl; obj->mm.get_page.sg_pos = obj->mm.pages->sgl;
obj->get_page.sg_idx = 0; obj->mm.get_page.sg_idx = 0;
pinned = 0; pinned = 0;
} }
} }
...@@ -672,22 +672,22 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj) ...@@ -672,22 +672,22 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj)
BUG_ON(obj->userptr.work != NULL); BUG_ON(obj->userptr.work != NULL);
__i915_gem_userptr_set_active(obj, false); __i915_gem_userptr_set_active(obj, false);
if (obj->madv != I915_MADV_WILLNEED) if (obj->mm.madv != I915_MADV_WILLNEED)
obj->dirty = 0; obj->mm.dirty = false;
i915_gem_gtt_finish_object(obj); i915_gem_gtt_finish_object(obj);
for_each_sgt_page(page, sgt_iter, obj->pages) { for_each_sgt_page(page, sgt_iter, obj->mm.pages) {
if (obj->dirty) if (obj->mm.dirty)
set_page_dirty(page); set_page_dirty(page);
mark_page_accessed(page); mark_page_accessed(page);
put_page(page); put_page(page);
} }
obj->dirty = 0; obj->mm.dirty = false;
sg_free_table(obj->pages); sg_free_table(obj->mm.pages);
kfree(obj->pages); kfree(obj->mm.pages);
} }
static void static void
......
...@@ -896,8 +896,8 @@ static void capture_bo(struct drm_i915_error_buffer *err, ...@@ -896,8 +896,8 @@ static void capture_bo(struct drm_i915_error_buffer *err,
err->write_domain = obj->base.write_domain; err->write_domain = obj->base.write_domain;
err->fence_reg = vma->fence ? vma->fence->id : -1; err->fence_reg = vma->fence ? vma->fence->id : -1;
err->tiling = i915_gem_object_get_tiling(obj); err->tiling = i915_gem_object_get_tiling(obj);
err->dirty = obj->dirty; err->dirty = obj->mm.dirty;
err->purgeable = obj->madv != I915_MADV_WILLNEED; err->purgeable = obj->mm.madv != I915_MADV_WILLNEED;
err->userptr = obj->userptr.mm != NULL; err->userptr = obj->userptr.mm != NULL;
err->cache_level = obj->cache_level; err->cache_level = obj->cache_level;
} }
......
...@@ -744,7 +744,7 @@ static int intel_lr_context_pin(struct i915_gem_context *ctx, ...@@ -744,7 +744,7 @@ static int intel_lr_context_pin(struct i915_gem_context *ctx,
ce->lrc_reg_state[CTX_RING_BUFFER_START+1] = ce->lrc_reg_state[CTX_RING_BUFFER_START+1] =
i915_ggtt_offset(ce->ring->vma); i915_ggtt_offset(ce->ring->vma);
ce->state->obj->dirty = true; ce->state->obj->mm.dirty = true;
/* Invalidate GuC TLB. */ /* Invalidate GuC TLB. */
if (i915.enable_guc_submission) { if (i915.enable_guc_submission) {
...@@ -2042,7 +2042,7 @@ populate_lr_context(struct i915_gem_context *ctx, ...@@ -2042,7 +2042,7 @@ populate_lr_context(struct i915_gem_context *ctx,
DRM_DEBUG_DRIVER("Could not map object pages! (%d)\n", ret); DRM_DEBUG_DRIVER("Could not map object pages! (%d)\n", ret);
return ret; return ret;
} }
ctx_obj->dirty = true; ctx_obj->mm.dirty = true;
/* The second page of the context object contains some fields which must /* The second page of the context object contains some fields which must
* be set up prior to the first execution. */ * be set up prior to the first execution. */
...@@ -2180,7 +2180,7 @@ void intel_lr_context_resume(struct drm_i915_private *dev_priv) ...@@ -2180,7 +2180,7 @@ void intel_lr_context_resume(struct drm_i915_private *dev_priv)
reg[CTX_RING_HEAD+1] = 0; reg[CTX_RING_HEAD+1] = 0;
reg[CTX_RING_TAIL+1] = 0; reg[CTX_RING_TAIL+1] = 0;
ce->state->obj->dirty = true; ce->state->obj->mm.dirty = true;
i915_gem_object_unpin_map(ce->state->obj); i915_gem_object_unpin_map(ce->state->obj);
ce->ring->head = ce->ring->tail = 0; ce->ring->head = ce->ring->tail = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment