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 static inline void
get_abs_timeout(struct drm_msm_timespec * tv,uint64_t ns)26 get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns)
27 {
28 struct timespec t;
29 clock_gettime(CLOCK_MONOTONIC, &t);
30 tv->tv_sec = t.tv_sec + ns / 1000000000;
31 tv->tv_nsec = t.tv_nsec + ns % 1000000000;
32 }
33
34 static inline bool
fence_before(uint32_t a,uint32_t b)35 fence_before(uint32_t a, uint32_t b)
36 {
37 return (int32_t)(a - b) < 0;
38 }
39
40 extern const struct vk_sync_type tu_timeline_sync_type;
41
42 static inline bool
vk_sync_is_tu_timeline_sync(const struct vk_sync * sync)43 vk_sync_is_tu_timeline_sync(const struct vk_sync *sync)
44 {
45 return sync->type == &tu_timeline_sync_type;
46 }
47
48 static inline struct tu_timeline_sync *
to_tu_timeline_sync(struct vk_sync * sync)49 to_tu_timeline_sync(struct vk_sync *sync)
50 {
51 assert(sync->type == &tu_timeline_sync_type);
52 return container_of(sync, struct tu_timeline_sync, base);
53 }
54
55 uint32_t tu_syncobj_from_vk_sync(struct vk_sync *sync);
56
57 #endif