2016-11-11 12:43:54 +02:00
|
|
|
/*
|
2019-05-28 10:29:42 +01:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-11-11 12:43:54 +02:00
|
|
|
*
|
2019-05-28 10:29:42 +01:00
|
|
|
* Copyright © 2016 Intel Corporation
|
2016-11-11 12:43:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __I915_GEM_OBJECT_H__
|
|
|
|
#define __I915_GEM_OBJECT_H__
|
|
|
|
|
|
|
|
#include <drm/drm_gem.h>
|
2019-01-08 10:27:09 +02:00
|
|
|
#include <drm/drm_file.h>
|
|
|
|
#include <drm/drm_device.h>
|
2016-11-11 12:43:54 +02:00
|
|
|
|
|
|
|
#include <drm/i915_drm.h>
|
|
|
|
|
2019-05-28 10:29:42 +01:00
|
|
|
#include "gem/i915_gem_object_types.h"
|
2016-11-11 12:43:54 +02:00
|
|
|
|
2019-02-28 10:20:34 +00:00
|
|
|
struct drm_i915_gem_object *i915_gem_object_alloc(void);
|
|
|
|
void i915_gem_object_free(struct drm_i915_gem_object *obj);
|
|
|
|
|
2016-11-11 12:43:54 +02:00
|
|
|
/**
|
|
|
|
* i915_gem_object_lookup_rcu - look up a temporary GEM object from its handle
|
|
|
|
* @filp: DRM file private date
|
|
|
|
* @handle: userspace handle
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
*
|
|
|
|
* A pointer to the object named by the handle if such exists on @filp, NULL
|
|
|
|
* otherwise. This object is only valid whilst under the RCU read lock, and
|
|
|
|
* note carefully the object may be in the process of being destroyed.
|
|
|
|
*/
|
|
|
|
static inline struct drm_i915_gem_object *
|
|
|
|
i915_gem_object_lookup_rcu(struct drm_file *file, u32 handle)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_LOCKDEP
|
|
|
|
WARN_ON(debug_locks && !lock_is_held(&rcu_lock_map));
|
|
|
|
#endif
|
|
|
|
return idr_find(&file->object_idr, handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct drm_i915_gem_object *
|
|
|
|
i915_gem_object_lookup(struct drm_file *file, u32 handle)
|
|
|
|
{
|
|
|
|
struct drm_i915_gem_object *obj;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
obj = i915_gem_object_lookup_rcu(file, handle);
|
|
|
|
if (obj && !kref_get_unless_zero(&obj->base.refcount))
|
|
|
|
obj = NULL;
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
__deprecated
|
|
|
|
extern struct drm_gem_object *
|
|
|
|
drm_gem_object_lookup(struct drm_file *file, u32 handle);
|
|
|
|
|
|
|
|
__attribute__((nonnull))
|
|
|
|
static inline struct drm_i915_gem_object *
|
|
|
|
i915_gem_object_get(struct drm_i915_gem_object *obj)
|
|
|
|
{
|
2018-06-18 13:01:51 +02:00
|
|
|
drm_gem_object_get(&obj->base);
|
2016-11-11 12:43:54 +02:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((nonnull))
|
|
|
|
static inline void
|
|
|
|
i915_gem_object_put(struct drm_i915_gem_object *obj)
|
|
|
|
{
|
2018-06-18 13:01:52 +02:00
|
|
|
__drm_gem_object_put(&obj->base);
|
2016-11-11 12:43:54 +02:00
|
|
|
}
|
|
|
|
|
2017-03-01 15:41:28 +00:00
|
|
|
static inline void i915_gem_object_lock(struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
reservation_object_lock(obj->resv, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_object_unlock(struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
reservation_object_unlock(obj->resv);
|
|
|
|
}
|
|
|
|
|
2018-07-12 19:53:13 +01:00
|
|
|
static inline void
|
|
|
|
i915_gem_object_set_readonly(struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
obj->base.vma_node.readonly = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
i915_gem_object_is_readonly(const struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
return obj->base.vma_node.readonly;
|
|
|
|
}
|
|
|
|
|
2016-11-11 12:43:54 +02:00
|
|
|
static inline bool
|
|
|
|
i915_gem_object_has_struct_page(const struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
return obj->ops->flags & I915_GEM_OBJECT_HAS_STRUCT_PAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
i915_gem_object_is_shrinkable(const struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
return obj->ops->flags & I915_GEM_OBJECT_IS_SHRINKABLE;
|
|
|
|
}
|
|
|
|
|
2017-11-14 10:25:13 +00:00
|
|
|
static inline bool
|
|
|
|
i915_gem_object_is_proxy(const struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
return obj->ops->flags & I915_GEM_OBJECT_IS_PROXY;
|
|
|
|
}
|
|
|
|
|
2019-01-15 12:44:42 +00:00
|
|
|
static inline bool
|
|
|
|
i915_gem_object_needs_async_cancel(const struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
return obj->ops->flags & I915_GEM_OBJECT_ASYNC_CANCEL;
|
|
|
|
}
|
|
|
|
|
2016-11-11 12:43:54 +02:00
|
|
|
static inline bool
|
|
|
|
i915_gem_object_is_active(const struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
return obj->active_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
i915_gem_object_has_active_reference(const struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
return test_bit(I915_BO_ACTIVE_REF, &obj->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
i915_gem_object_set_active_reference(struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&obj->base.dev->struct_mutex);
|
|
|
|
__set_bit(I915_BO_ACTIVE_REF, &obj->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
i915_gem_object_clear_active_reference(struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&obj->base.dev->struct_mutex);
|
|
|
|
__clear_bit(I915_BO_ACTIVE_REF, &obj->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __i915_gem_object_release_unless_active(struct drm_i915_gem_object *obj);
|
|
|
|
|
2017-03-01 15:41:28 +00:00
|
|
|
static inline bool
|
|
|
|
i915_gem_object_is_framebuffer(const struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
return READ_ONCE(obj->framebuffer_references);
|
|
|
|
}
|
|
|
|
|
2016-11-11 12:43:54 +02:00
|
|
|
static inline unsigned int
|
2018-07-25 16:54:47 +01:00
|
|
|
i915_gem_object_get_tiling(const struct drm_i915_gem_object *obj)
|
2016-11-11 12:43:54 +02:00
|
|
|
{
|
|
|
|
return obj->tiling_and_stride & TILING_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2018-07-25 16:54:47 +01:00
|
|
|
i915_gem_object_is_tiled(const struct drm_i915_gem_object *obj)
|
2016-11-11 12:43:54 +02:00
|
|
|
{
|
|
|
|
return i915_gem_object_get_tiling(obj) != I915_TILING_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
2018-07-25 16:54:47 +01:00
|
|
|
i915_gem_object_get_stride(const struct drm_i915_gem_object *obj)
|
2016-11-11 12:43:54 +02:00
|
|
|
{
|
|
|
|
return obj->tiling_and_stride & STRIDE_MASK;
|
|
|
|
}
|
|
|
|
|
2017-01-09 16:16:08 +00:00
|
|
|
static inline unsigned int
|
|
|
|
i915_gem_tile_height(unsigned int tiling)
|
|
|
|
{
|
|
|
|
GEM_BUG_ON(!tiling);
|
|
|
|
return tiling == I915_TILING_Y ? 32 : 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
2018-07-25 16:54:47 +01:00
|
|
|
i915_gem_object_get_tile_height(const struct drm_i915_gem_object *obj)
|
2017-01-09 16:16:08 +00:00
|
|
|
{
|
|
|
|
return i915_gem_tile_height(i915_gem_object_get_tiling(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
2018-07-25 16:54:47 +01:00
|
|
|
i915_gem_object_get_tile_row_size(const struct drm_i915_gem_object *obj)
|
2017-01-09 16:16:08 +00:00
|
|
|
{
|
|
|
|
return (i915_gem_object_get_stride(obj) *
|
|
|
|
i915_gem_object_get_tile_height(obj));
|
|
|
|
}
|
|
|
|
|
2017-01-10 12:10:45 +00:00
|
|
|
int i915_gem_object_set_tiling(struct drm_i915_gem_object *obj,
|
|
|
|
unsigned int tiling, unsigned int stride);
|
|
|
|
|
2016-11-11 12:43:54 +02:00
|
|
|
static inline struct intel_engine_cs *
|
|
|
|
i915_gem_object_last_write_engine(struct drm_i915_gem_object *obj)
|
|
|
|
{
|
|
|
|
struct intel_engine_cs *engine = NULL;
|
|
|
|
struct dma_fence *fence;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
fence = reservation_object_get_excl_rcu(obj->resv);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (fence && dma_fence_is_i915(fence) && !dma_fence_is_signaled(fence))
|
|
|
|
engine = to_request(fence)->engine;
|
|
|
|
dma_fence_put(fence);
|
|
|
|
|
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
|
2017-08-11 12:11:16 +01:00
|
|
|
void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object *obj,
|
|
|
|
unsigned int cache_level);
|
2017-02-22 11:40:46 +00:00
|
|
|
void i915_gem_object_flush_if_display(struct drm_i915_gem_object *obj);
|
|
|
|
|
2019-03-31 10:46:20 +01:00
|
|
|
void __i915_gem_object_release_shmem(struct drm_i915_gem_object *obj,
|
|
|
|
struct sg_table *pages,
|
|
|
|
bool needs_clflush);
|
|
|
|
|
2019-02-28 10:20:34 +00:00
|
|
|
#endif
|