1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2016 Red Hat. 3bf215546Sopenharmony_ci * Copyright © 2016 Bas Nieuwenhuizen 4bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * based in part on anv driver which is: 7bf215546Sopenharmony_ci * Copyright © 2015 Intel Corporation 8bf215546Sopenharmony_ci */ 9bf215546Sopenharmony_ci 10bf215546Sopenharmony_ci#ifndef TU_DRM_H 11bf215546Sopenharmony_ci#define TU_DRM_H 12bf215546Sopenharmony_ci 13bf215546Sopenharmony_ci#include "tu_common.h" 14bf215546Sopenharmony_ci 15bf215546Sopenharmony_ci/* Keep tu_syncobj until porting to common code for kgsl too */ 16bf215546Sopenharmony_ci#ifdef TU_USE_KGSL 17bf215546Sopenharmony_cistruct tu_syncobj; 18bf215546Sopenharmony_ci/* for TU_FROM_HANDLE with both VkFence and VkSemaphore: */ 19bf215546Sopenharmony_ci#define tu_syncobj_from_handle(x) ((struct tu_syncobj*) (uintptr_t) (x)) 20bf215546Sopenharmony_ci#endif 21bf215546Sopenharmony_ci 22bf215546Sopenharmony_cistruct tu_u_trace_syncobj; 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_cienum tu_bo_alloc_flags 25bf215546Sopenharmony_ci{ 26bf215546Sopenharmony_ci TU_BO_ALLOC_NO_FLAGS = 0, 27bf215546Sopenharmony_ci TU_BO_ALLOC_ALLOW_DUMP = 1 << 0, 28bf215546Sopenharmony_ci TU_BO_ALLOC_GPU_READ_ONLY = 1 << 1, 29bf215546Sopenharmony_ci}; 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci/* Define tu_timeline_sync type based on drm syncobj for a point type 32bf215546Sopenharmony_ci * for vk_sync_timeline, and the logic to handle is mostly copied from 33bf215546Sopenharmony_ci * anv_bo_sync since it seems it can be used by similar way to anv. 34bf215546Sopenharmony_ci */ 35bf215546Sopenharmony_cienum tu_timeline_sync_state { 36bf215546Sopenharmony_ci /** Indicates that this is a new (or newly reset fence) */ 37bf215546Sopenharmony_ci TU_TIMELINE_SYNC_STATE_RESET, 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci /** Indicates that this fence has been submitted to the GPU but is still 40bf215546Sopenharmony_ci * (as far as we know) in use by the GPU. 41bf215546Sopenharmony_ci */ 42bf215546Sopenharmony_ci TU_TIMELINE_SYNC_STATE_SUBMITTED, 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci TU_TIMELINE_SYNC_STATE_SIGNALED, 45bf215546Sopenharmony_ci}; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_cistruct tu_bo 48bf215546Sopenharmony_ci{ 49bf215546Sopenharmony_ci uint32_t gem_handle; 50bf215546Sopenharmony_ci uint64_t size; 51bf215546Sopenharmony_ci uint64_t iova; 52bf215546Sopenharmony_ci void *map; 53bf215546Sopenharmony_ci int32_t refcnt; 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci#ifndef TU_USE_KGSL 56bf215546Sopenharmony_ci uint32_t bo_list_idx; 57bf215546Sopenharmony_ci#endif 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci bool implicit_sync : 1; 60bf215546Sopenharmony_ci}; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_cistruct tu_timeline_sync { 63bf215546Sopenharmony_ci struct vk_sync base; 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci enum tu_timeline_sync_state state; 66bf215546Sopenharmony_ci uint32_t syncobj; 67bf215546Sopenharmony_ci}; 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ciVkResult 70bf215546Sopenharmony_citu_bo_init_new(struct tu_device *dev, struct tu_bo **bo, uint64_t size, 71bf215546Sopenharmony_ci enum tu_bo_alloc_flags flags); 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ciVkResult 74bf215546Sopenharmony_citu_bo_init_dmabuf(struct tu_device *dev, 75bf215546Sopenharmony_ci struct tu_bo **bo, 76bf215546Sopenharmony_ci uint64_t size, 77bf215546Sopenharmony_ci int fd); 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_ciint 80bf215546Sopenharmony_citu_bo_export_dmabuf(struct tu_device *dev, struct tu_bo *bo); 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_civoid 83bf215546Sopenharmony_citu_bo_finish(struct tu_device *dev, struct tu_bo *bo); 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ciVkResult 86bf215546Sopenharmony_citu_bo_map(struct tu_device *dev, struct tu_bo *bo); 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_cistatic inline struct tu_bo * 89bf215546Sopenharmony_citu_bo_get_ref(struct tu_bo *bo) 90bf215546Sopenharmony_ci{ 91bf215546Sopenharmony_ci p_atomic_inc(&bo->refcnt); 92bf215546Sopenharmony_ci return bo; 93bf215546Sopenharmony_ci} 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ciVkResult 96bf215546Sopenharmony_citu_enumerate_devices(struct tu_instance *instance); 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ciint 99bf215546Sopenharmony_citu_device_get_gpu_timestamp(struct tu_device *dev, 100bf215546Sopenharmony_ci uint64_t *ts); 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ciint 103bf215546Sopenharmony_citu_device_get_suspend_count(struct tu_device *dev, 104bf215546Sopenharmony_ci uint64_t *suspend_count); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ciVkResult 107bf215546Sopenharmony_citu_device_wait_u_trace(struct tu_device *dev, struct tu_u_trace_syncobj *syncobj); 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ciVkResult 110bf215546Sopenharmony_citu_device_check_status(struct vk_device *vk_device); 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ciint 113bf215546Sopenharmony_citu_drm_submitqueue_new(const struct tu_device *dev, 114bf215546Sopenharmony_ci int priority, 115bf215546Sopenharmony_ci uint32_t *queue_id); 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_civoid 118bf215546Sopenharmony_citu_drm_submitqueue_close(const struct tu_device *dev, uint32_t queue_id); 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ciint 121bf215546Sopenharmony_citu_syncobj_to_fd(struct tu_device *device, struct vk_sync *sync); 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ciVkResult 124bf215546Sopenharmony_citu_queue_submit(struct vk_queue *vk_queue, struct vk_queue_submit *submit); 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci#endif /* TU_DRM_H */ 127