drivers/gpu/drm/xe/xe_validation.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_validation.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/xe_validation.c
Extension
.c
Size
7548 bytes
Lines
278
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

switch (PTR_ERR(exec)) {
		case __XE_VAL_UNIMPLEMENTED:
			break;
		case __XE_VAL_UNSUPPORTED:
			xe_assert(xe, !!obj->dma_buf);
			break;
#if IS_ENABLED(CONFIG_KUNIT)
		case __XE_VAL_OPT_OUT:
			xe_assert(xe, current->kunit_test);
			break;
#endif
		default:
			xe_assert(xe, false);
		}
	}
}
#endif

static int xe_validation_lock(struct xe_validation_ctx *ctx)
{
	struct xe_validation_device *val = ctx->val;
	int ret = 0;

	if (ctx->val_flags.interruptible) {
		if (ctx->request_exclusive)
			ret = down_write_killable(&val->lock);
		else
			ret = down_read_interruptible(&val->lock);
	} else {
		if (ctx->request_exclusive)
			down_write(&val->lock);
		else
			down_read(&val->lock);
	}

	if (!ret) {
		ctx->lock_held = true;
		ctx->lock_held_exclusive = ctx->request_exclusive;
	}

	return ret;
}

static int xe_validation_trylock(struct xe_validation_ctx *ctx)
{
	struct xe_validation_device *val = ctx->val;
	bool locked;

	if (ctx->request_exclusive)
		locked = down_write_trylock(&val->lock);
	else
		locked = down_read_trylock(&val->lock);

	if (locked) {
		ctx->lock_held = true;
		ctx->lock_held_exclusive = ctx->request_exclusive;
	}

	return locked ? 0 : -EWOULDBLOCK;
}

static void xe_validation_unlock(struct xe_validation_ctx *ctx)
{
	if (!ctx->lock_held)
		return;

	if (ctx->lock_held_exclusive)
		up_write(&ctx->val->lock);
	else
		up_read(&ctx->val->lock);

	ctx->lock_held = false;
}

/**
 * xe_validation_ctx_init() - Initialize an xe_validation_ctx
 * @ctx: The xe_validation_ctx to initialize.
 * @val: The xe_validation_device representing the validation domain.
 * @exec: The struct drm_exec to use for the transaction. May be NULL.
 * @flags: The flags to use for initialization.
 *
 * Initialize and lock a an xe_validation transaction using the validation domain
 * represented by @val. Also initialize the drm_exec object forwarding parts of
 * @flags to the drm_exec initialization. The @flags.exclusive flag should
 * typically be set to false to avoid locking out other validators from the
 * domain until an OOM is hit. For testing- or final attempt purposes it can,
 * however, be set to true.
 *
 * Return: %0 on success, %-EINTR if interruptible initial locking failed with a
 * signal pending. If @flags.no_block is set to true, a failed trylock

Annotation

Implementation Notes