xref: /linux/drivers/gpu/drm/xe/xe_validation.c (revision 0131514f97890c4699a4d7ca14b720dafefdbc71)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2024 Intel Corporation
4  */
5 #include "xe_bo.h"
6 #include <drm/drm_exec.h>
7 #include <drm/drm_gem.h>
8 
9 #include "xe_assert.h"
10 #include "xe_validation.h"
11 
12 #ifdef CONFIG_DRM_XE_DEBUG
13 /**
14  * xe_validation_assert_exec() - Assert that the drm_exec pointer is suitable
15  * for validation.
16  * @xe: Pointer to the xe device.
17  * @exec: The drm_exec pointer to check.
18  * @obj: Pointer to the object subject to validation.
19  *
20  * NULL exec pointers are not allowed.
21  * For XE_VALIDATION_UNIMPLEMENTED, no checking.
22  * For XE_VLIDATION_OPT_OUT, check that the caller is a kunit test
23  * For XE_VALIDATION_UNSUPPORTED, check that the object subject to
24  * validation is a dma-buf, for which support for ww locking is
25  * not in place in the dma-buf layer.
26  */
27 void xe_validation_assert_exec(const struct xe_device *xe,
28 			       const struct drm_exec *exec,
29 			       const struct drm_gem_object *obj)
30 {
31 	xe_assert(xe, exec);
32 	if (IS_ERR(exec)) {
33 		switch (PTR_ERR(exec)) {
34 		case __XE_VAL_UNIMPLEMENTED:
35 			break;
36 		case __XE_VAL_UNSUPPORTED:
37 			xe_assert(xe, !!obj->dma_buf);
38 			break;
39 #if IS_ENABLED(CONFIG_KUNIT)
40 		case __XE_VAL_OPT_OUT:
41 			xe_assert(xe, current->kunit_test);
42 			break;
43 #endif
44 		default:
45 			xe_assert(xe, false);
46 		}
47 	}
48 }
49 #endif
50