Commit be062fa4 authored by Chris Wilson's avatar Chris Wilson

drm/i915: Initialise i915_gem_object_create_from_data() directly

Use pagecache_write to avoid shmemfs clearing the pages prior to us
immediately overwriting them with our data.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: http://patchwork.freedesktop.org/patch/msgid/20170317194648.12468-2-chris@chris-wilson.co.ukReviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
parent f3ddd2c1
...@@ -4953,9 +4953,9 @@ i915_gem_object_create_from_data(struct drm_i915_private *dev_priv, ...@@ -4953,9 +4953,9 @@ i915_gem_object_create_from_data(struct drm_i915_private *dev_priv,
const void *data, size_t size) const void *data, size_t size)
{ {
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct sg_table *sg; struct file *file;
size_t bytes; size_t offset;
int ret; int err;
obj = i915_gem_object_create(dev_priv, round_up(size, PAGE_SIZE)); obj = i915_gem_object_create(dev_priv, round_up(size, PAGE_SIZE));
if (IS_ERR(obj)) if (IS_ERR(obj))
...@@ -4963,26 +4963,39 @@ i915_gem_object_create_from_data(struct drm_i915_private *dev_priv, ...@@ -4963,26 +4963,39 @@ i915_gem_object_create_from_data(struct drm_i915_private *dev_priv,
GEM_BUG_ON(obj->base.write_domain != I915_GEM_DOMAIN_CPU); GEM_BUG_ON(obj->base.write_domain != I915_GEM_DOMAIN_CPU);
ret = i915_gem_object_pin_pages(obj); file = obj->base.filp;
if (ret) offset = 0;
goto fail; do {
unsigned int len = min_t(typeof(size), size, PAGE_SIZE);
struct page *page;
void *pgdata, *vaddr;
sg = obj->mm.pages; err = pagecache_write_begin(file, file->f_mapping,
bytes = sg_copy_from_buffer(sg->sgl, sg->nents, (void *)data, size); offset, len, 0,
obj->mm.dirty = true; /* Backing store is now out of date */ &page, &pgdata);
i915_gem_object_unpin_pages(obj); if (err < 0)
goto fail;
if (WARN_ON(bytes != size)) { vaddr = kmap(page);
DRM_ERROR("Incomplete copy, wrote %zu of %zu", bytes, size); memcpy(vaddr, data, len);
ret = -EFAULT; kunmap(page);
goto fail;
} err = pagecache_write_end(file, file->f_mapping,
offset, len, len,
page, pgdata);
if (err < 0)
goto fail;
size -= len;
data += len;
offset += len;
} while (size);
return obj; return obj;
fail: fail:
i915_gem_object_put(obj); i915_gem_object_put(obj);
return ERR_PTR(ret); return ERR_PTR(err);
} }
struct scatterlist * struct scatterlist *
......
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