xref: /aosp_15_r20/external/mesa3d/src/virtio/vulkan/vn_device_memory.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2019 Google LLC
3  * SPDX-License-Identifier: MIT
4  *
5  * based in part on anv and radv which are:
6  * Copyright © 2015 Intel Corporation
7  * Copyright © 2016 Red Hat.
8  * Copyright © 2016 Bas Nieuwenhuizen
9  */
10 
11 #ifndef VN_DEVICE_MEMORY_H
12 #define VN_DEVICE_MEMORY_H
13 
14 #include "vn_common.h"
15 
16 struct vn_device_memory {
17    struct vn_device_memory_base base;
18 
19    /* non-NULL when mappable or external */
20    struct vn_renderer_bo *base_bo;
21 
22    /* ensure renderer side resource create is called after vkAllocateMemory
23     *
24     * 1. driver submits vkAllocateMemory (alloc) via ring for a ring seqno
25     * 2. driver submits via vq to wait for above ring to reach the seqno
26     * 3. driver creates virtgpu bo from renderer VkDeviceMemory
27     *
28     * ensure renderer side resource destroy is called after vkAllocateMemory
29     *
30     * 1. driver submits vkAllocateMemory (import) via ring for a ring seqno
31     * 2. driver submits via vq to wait for above ring to reach the seqno
32     * 3. driver destroys virtgpu bo
33     */
34    bool bo_ring_seqno_valid;
35    uint32_t bo_ring_seqno;
36 
37    /* ensure renderer side vkFreeMemory is called after vkGetMemoryFdKHR
38     *
39     * 1. driver creates virtgpu bo from renderer VkDeviceMemory
40     * 2. driver submits via vq to update the vq seqno
41     * 3, driver submits via ring to wait for vq reaching above seqno
42     * 4. driver submits vkFreeMemory via ring
43     *
44     * To be noted: a successful virtgpu mmap implies a roundtrip, so
45     * vn_FreeMemory after that no longer has to wait.
46     */
47    bool bo_roundtrip_seqno_valid;
48    uint64_t bo_roundtrip_seqno;
49 
50    VkDeviceSize map_end;
51 };
52 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_device_memory,
53                                base.base.base,
54                                VkDeviceMemory,
55                                VK_OBJECT_TYPE_DEVICE_MEMORY)
56 
57 VkResult
58 vn_device_memory_import_dma_buf(struct vn_device *dev,
59                                 struct vn_device_memory *mem,
60                                 const VkMemoryAllocateInfo *alloc_info,
61                                 bool force_unmappable,
62                                 int fd);
63 
64 VkResult
65 vn_get_memory_dma_buf_properties(struct vn_device *dev,
66                                  int fd,
67                                  uint64_t *out_alloc_size,
68                                  uint32_t *out_mem_type_bits);
69 
70 #endif /* VN_DEVICE_MEMORY_H */
71