2019-03-08 20:25:17 +07:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
* Copyright © 2019 Intel Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __INTEL_CONTEXT_H__
|
|
|
|
#define __INTEL_CONTEXT_H__
|
|
|
|
|
2019-03-08 20:25:22 +07:00
|
|
|
#include <linux/lockdep.h>
|
|
|
|
|
2019-03-08 20:25:17 +07:00
|
|
|
#include "intel_context_types.h"
|
|
|
|
#include "intel_engine_types.h"
|
|
|
|
|
2019-03-08 20:25:19 +07:00
|
|
|
struct intel_context *intel_context_alloc(void);
|
|
|
|
void intel_context_free(struct intel_context *ce);
|
|
|
|
|
2019-03-08 20:25:17 +07:00
|
|
|
void intel_context_init(struct intel_context *ce,
|
|
|
|
struct i915_gem_context *ctx,
|
|
|
|
struct intel_engine_cs *engine);
|
|
|
|
|
2019-03-08 20:25:19 +07:00
|
|
|
/**
|
|
|
|
* intel_context_lookup - Find the matching HW context for this (ctx, engine)
|
|
|
|
* @ctx - the parent GEM context
|
|
|
|
* @engine - the target HW engine
|
|
|
|
*
|
|
|
|
* May return NULL if the HW context hasn't been instantiated (i.e. unused).
|
|
|
|
*/
|
|
|
|
struct intel_context *
|
|
|
|
intel_context_lookup(struct i915_gem_context *ctx,
|
|
|
|
struct intel_engine_cs *engine);
|
|
|
|
|
|
|
|
/**
|
2019-03-08 20:25:22 +07:00
|
|
|
* intel_context_pin_lock - Stablises the 'pinned' status of the HW context
|
2019-03-08 20:25:19 +07:00
|
|
|
* @ctx - the parent GEM context
|
|
|
|
* @engine - the target HW engine
|
|
|
|
*
|
2019-03-08 20:25:22 +07:00
|
|
|
* Acquire a lock on the pinned status of the HW context, such that the context
|
|
|
|
* can neither be bound to the GPU or unbound whilst the lock is held, i.e.
|
|
|
|
* intel_context_is_pinned() remains stable.
|
2019-03-08 20:25:19 +07:00
|
|
|
*/
|
|
|
|
struct intel_context *
|
2019-03-08 20:25:22 +07:00
|
|
|
intel_context_pin_lock(struct i915_gem_context *ctx,
|
2019-03-08 20:25:19 +07:00
|
|
|
struct intel_engine_cs *engine);
|
|
|
|
|
2019-03-08 20:25:22 +07:00
|
|
|
static inline bool
|
|
|
|
intel_context_is_pinned(struct intel_context *ce)
|
|
|
|
{
|
|
|
|
return atomic_read(&ce->pin_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void intel_context_pin_unlock(struct intel_context *ce)
|
|
|
|
__releases(ce->pin_mutex)
|
|
|
|
{
|
|
|
|
mutex_unlock(&ce->pin_mutex);
|
|
|
|
}
|
|
|
|
|
2019-03-08 20:25:19 +07:00
|
|
|
struct intel_context *
|
|
|
|
__intel_context_insert(struct i915_gem_context *ctx,
|
|
|
|
struct intel_engine_cs *engine,
|
|
|
|
struct intel_context *ce);
|
|
|
|
void
|
|
|
|
__intel_context_remove(struct intel_context *ce);
|
2019-03-08 20:25:17 +07:00
|
|
|
|
2019-03-08 20:25:20 +07:00
|
|
|
struct intel_context *
|
|
|
|
intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine);
|
2019-03-08 20:25:17 +07:00
|
|
|
|
|
|
|
static inline void __intel_context_pin(struct intel_context *ce)
|
|
|
|
{
|
2019-03-08 20:25:22 +07:00
|
|
|
GEM_BUG_ON(!intel_context_is_pinned(ce));
|
|
|
|
atomic_inc(&ce->pin_count);
|
2019-03-08 20:25:17 +07:00
|
|
|
}
|
|
|
|
|
2019-03-08 20:25:22 +07:00
|
|
|
void intel_context_unpin(struct intel_context *ce);
|
2019-03-08 20:25:17 +07:00
|
|
|
|
2019-03-19 04:23:47 +07:00
|
|
|
static inline struct intel_context *intel_context_get(struct intel_context *ce)
|
|
|
|
{
|
|
|
|
kref_get(&ce->ref);
|
|
|
|
return ce;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void intel_context_put(struct intel_context *ce)
|
|
|
|
{
|
|
|
|
kref_put(&ce->ref, ce->ops->destroy);
|
|
|
|
}
|
|
|
|
|
2019-03-08 20:25:17 +07:00
|
|
|
#endif /* __INTEL_CONTEXT_H__ */
|