• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 Intel Corporation
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "xe/intel_queue.h"
7 
8 #include "common/intel_gem.h"
9 
10 #include "drm-uapi/xe_drm.h"
11 
12 /* Creates a syncobj that will be signaled when all the workloads in given
13  * exec_queue_id are completed.
14  * Syncobj set must be destroyed by caller.
15  */
16 int
xe_queue_get_syncobj_for_idle(int fd,uint32_t exec_queue_id,uint32_t * syncobj)17 xe_queue_get_syncobj_for_idle(int fd, uint32_t exec_queue_id, uint32_t *syncobj)
18 {
19    struct drm_syncobj_create syncobj_create = {};
20    struct drm_xe_sync xe_sync = {
21       .type = DRM_XE_SYNC_TYPE_SYNCOBJ,
22       .flags = DRM_XE_SYNC_FLAG_SIGNAL,
23    };
24    struct drm_xe_exec exec = {
25       .exec_queue_id = exec_queue_id,
26       .num_syncs = 1,
27       .syncs = (uintptr_t)&xe_sync,
28       .num_batch_buffer = 0,
29    };
30    struct drm_syncobj_destroy syncobj_destroy = {};
31    int ret = intel_ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &syncobj_create);
32 
33    if (ret)
34       return -errno;
35 
36    xe_sync.handle = syncobj_create.handle;
37    /* Using the special exec.num_batch_buffer == 0 handling to get syncobj
38     * signaled when the last DRM_IOCTL_XE_EXEC is completed.
39     */
40    ret = intel_ioctl(fd, DRM_IOCTL_XE_EXEC, &exec);
41    if (ret) {
42       /* exec_queue could have been banned, that is why it is being destroyed
43        * so no assert() here
44        */
45       ret = -errno;
46       goto error_exec;
47    }
48 
49    *syncobj = syncobj_create.handle;
50    return 0;
51 
52 error_exec:
53    syncobj_destroy.handle = syncobj_create.handle,
54    intel_ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &syncobj_destroy);
55 
56    return ret;
57 }
58