xref: /aosp_15_r20/external/mesa3d/src/imagination/vulkan/winsys/powervr/pvr_drm_bo.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2022 Imagination Technologies Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef PVR_DRM_BO_H
25 #define PVR_DRM_BO_H
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <vulkan/vulkan.h>
30 
31 #include "pvr_drm.h"
32 #include "pvr_winsys.h"
33 #include "util/macros.h"
34 
35 /*******************************************
36    struct definitions
37  *******************************************/
38 
39 struct pvr_drm_winsys_bo {
40    struct pvr_winsys_bo base;
41    uint32_t ref_count;
42 
43    uint32_t handle;
44    uint64_t flags;
45 };
46 
47 struct pvr_drm_winsys_vma {
48    struct pvr_winsys_vma base;
49 };
50 
51 /*******************************************
52    function prototypes
53  *******************************************/
54 
55 VkResult pvr_drm_winsys_buffer_create(struct pvr_winsys *ws,
56                                       uint64_t size,
57                                       uint64_t alignment,
58                                       enum pvr_winsys_bo_type type,
59                                       uint32_t ws_flags,
60                                       struct pvr_winsys_bo **const bo_out);
61 VkResult
62 pvr_drm_winsys_buffer_create_from_fd(struct pvr_winsys *ws,
63                                      int fd,
64                                      struct pvr_winsys_bo **const bo_out);
65 void pvr_drm_winsys_buffer_destroy(struct pvr_winsys_bo *bo);
66 
67 VkResult pvr_drm_winsys_buffer_get_fd(struct pvr_winsys_bo *bo,
68                                       int *const fd_out);
69 
70 VkResult pvr_drm_winsys_buffer_map(struct pvr_winsys_bo *bo);
71 void pvr_drm_winsys_buffer_unmap(struct pvr_winsys_bo *bo);
72 
73 VkResult pvr_drm_heap_alloc_carveout(struct pvr_winsys_heap *const heap,
74                                      const pvr_dev_addr_t carveout_dev_addr,
75                                      uint64_t size,
76                                      uint64_t alignment,
77                                      struct pvr_winsys_vma **vma_out);
78 VkResult pvr_drm_winsys_heap_alloc(struct pvr_winsys_heap *heap,
79                                    uint64_t size,
80                                    uint64_t alignment,
81                                    struct pvr_winsys_vma **vma_out);
82 void pvr_drm_winsys_heap_free(struct pvr_winsys_vma *vma);
83 
84 VkResult pvr_drm_winsys_vma_map(struct pvr_winsys_vma *vma,
85                                 struct pvr_winsys_bo *bo,
86                                 uint64_t offset,
87                                 uint64_t size,
88                                 pvr_dev_addr_t *dev_addr_out);
89 void pvr_drm_winsys_vma_unmap(struct pvr_winsys_vma *vma);
90 
91 /*******************************************
92    helper macros
93  *******************************************/
94 
95 #define to_pvr_drm_winsys_bo(bo) \
96    container_of((bo), struct pvr_drm_winsys_bo, base)
97 #define to_pvr_drm_winsys_vma(vma) \
98    container_of((vma), struct pvr_drm_winsys_vma, base)
99 
100 #endif /* PVR_DRM_BO_H */
101