Skip to content
Snippets Groups Projects

shmem_create_from_object

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Adrián Martínez Larumbe
    createfromobject.c 999 B
    struct file *shmem_create_from_object(struct drm_i915_gem_object *obj)
    {
    	struct drm_i915_private *i915 = to_i915(obj->base.dev);
    	struct file *file;
    	void *ptr;
    	int err;
    
    	if (obj->base.import_attach) {
    		file = obj->base.filp;
    		atomic_long_inc(&file->f_count);
    
    	} else if (i915_gem_object_is_shmem(obj)) {
    
    		err = i915_gem_object_pin_pages_unlocked(obj);
    		if (err) {
    			drm_dbg(&i915->drm, "%s pin-pages err=%d\n", __func__, err);
    			return ERR_PTR(err);
    		}
    
    		file = i915_gem_ttm_get_filep(obj);
    		GEM_BUG_ON(!file);
    		atomic_long_inc(&file->f_count);
    
    		i915_gem_clflush_object(obj, I915_CLFLUSH_FORCE | I915_CLFLUSH_SYNC);
    		i915_gem_object_unpin_pages(obj);
    
    	} else {
    		ptr = i915_gem_object_pin_map_unlocked(obj, i915_gem_object_is_lmem(obj) ?
    						       I915_MAP_WC : I915_MAP_WB);
    		if (IS_ERR(ptr)) {
    			i915_gem_object_unpin_pages(obj);
    			return ERR_CAST(ptr);
    		}
    
    		file = shmem_create_from_data("", ptr, obj->base.size);
    		i915_gem_object_unpin_map(obj);
    	}
    
    	return file;
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment