• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_H
25 #define PVR_DRM_H
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <vulkan/vulkan.h>
30 
31 #include "pvr_winsys.h"
32 #include "util/macros.h"
33 #include "util/rwlock.h"
34 #include "util/sparse_array.h"
35 
36 struct pvr_drm_winsys_heap {
37    struct pvr_winsys_heap base;
38 };
39 
40 struct pvr_drm_winsys {
41    struct pvr_winsys base;
42 
43    /* Packed bvnc */
44    uint64_t bvnc;
45 
46    /* Protects imported BOs creation/freeing, which includes the bo_map member
47     * below.
48     */
49    struct u_rwlock dmabuf_bo_lock;
50 
51 
52    /* This array holds all our 'struct pvr_drm_winsys_bo' allocations. We use
53     * this so we can add a refcount to our BOs and check if a particular BO was
54     * already allocated in this device using its GEM handle. This is necessary
55     * to properly manage BO imports, because the kernel doesn't refcount the
56     * underlying BO memory.
57     *
58     * Specifically, when self-importing (i.e. importing a BO into the same
59     * device that created it), the kernel will give us the same BO handle for
60     * both BOs and we must only free it once when both references are
61     * freed. Otherwise, if we are not self-importing, we get two different BO
62     * handles, and we want to free each one individually.
63     *
64     * The refcount is also useful for being able to maintain BOs across
65     * VK object lifetimes, such as pipelines suballocating out of BOs
66     * allocated on the device.
67     */
68    struct util_sparse_array bo_map;
69 
70    /* Required heaps */
71    struct pvr_drm_winsys_heap general_heap;
72    struct pvr_drm_winsys_heap pds_heap;
73    struct pvr_drm_winsys_heap usc_heap;
74    struct pvr_drm_winsys_heap vis_test_heap;
75    struct pvr_drm_winsys_heap transfer_frag_heap;
76 
77    /* Optional heaps */
78    bool rgn_hdr_heap_present;
79    struct pvr_drm_winsys_heap rgn_hdr_heap;
80 
81    /* vma's for carveout memory regions */
82    struct pvr_winsys_vma *pds_vma;
83    struct pvr_winsys_vma *usc_vma;
84    struct pvr_winsys_vma *general_vma;
85 
86    uint32_t vm_context;
87 };
88 
89 /*******************************************
90     helper macros
91  *******************************************/
92 
93 #define to_pvr_drm_winsys(ws) container_of((ws), struct pvr_drm_winsys, base)
94 #define to_pvr_drm_winsys_heap(heap) \
95    container_of((heap), struct pvr_drm_winsys_heap, base)
96 
97 #endif /* PVR_DRM_H */
98