1 /*
2 * Copyright © 2018 Google, Inc.
3 * Copyright © 2015 Intel Corporation
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef TU_KNL_DRM_H
8 #define TU_KNL_DRM_H
9
10 #include "tu_knl.h"
11 #include "drm-uapi/msm_drm.h"
12
13 #include "vk_util.h"
14
15 #include "util/timespec.h"
16
17 VkResult tu_allocate_userspace_iova(struct tu_device *dev,
18 uint64_t size,
19 uint64_t client_iova,
20 enum tu_bo_alloc_flags flags,
21 uint64_t *iova);
22 int tu_drm_export_dmabuf(struct tu_device *dev, struct tu_bo *bo);
23 void tu_drm_bo_finish(struct tu_device *dev, struct tu_bo *bo);
24
25 struct tu_msm_queue_submit
26 {
27 struct util_dynarray commands;
28 struct util_dynarray command_bos;
29 };
30
31 void *msm_submit_create(struct tu_device *device);
32 void msm_submit_finish(struct tu_device *device, void *_submit);
33 void msm_submit_add_entries(struct tu_device *device, void *_submit,
34 struct tu_cs_entry *entries,
35 unsigned num_entries);
36
37 static inline void
get_abs_timeout(struct drm_msm_timespec * tv,uint64_t ns)38 get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns)
39 {
40 struct timespec t;
41 clock_gettime(CLOCK_MONOTONIC, &t);
42 tv->tv_sec = t.tv_sec + ns / 1000000000;
43 tv->tv_nsec = t.tv_nsec + ns % 1000000000;
44 }
45
46 static inline bool
fence_before(uint32_t a,uint32_t b)47 fence_before(uint32_t a, uint32_t b)
48 {
49 return (int32_t)(a - b) < 0;
50 }
51
52 extern const struct vk_sync_type tu_timeline_sync_type;
53
54 static inline bool
vk_sync_is_tu_timeline_sync(const struct vk_sync * sync)55 vk_sync_is_tu_timeline_sync(const struct vk_sync *sync)
56 {
57 return sync->type == &tu_timeline_sync_type;
58 }
59
60 static inline struct tu_timeline_sync *
to_tu_timeline_sync(struct vk_sync * sync)61 to_tu_timeline_sync(struct vk_sync *sync)
62 {
63 assert(sync->type == &tu_timeline_sync_type);
64 return container_of(sync, struct tu_timeline_sync, base);
65 }
66
67 uint32_t tu_syncobj_from_vk_sync(struct vk_sync *sync);
68
69 #endif
70