| 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 |
/* This array holds all our 'struct pvr_drm_winsys_bo' allocations. We use |
| 52 |
* this so we can add a refcount to our BOs and check if a particular BO was |
| 53 |
* already allocated in this device using its GEM handle. This is necessary |
| 54 |
* to properly manage BO imports, because the kernel doesn't refcount the |
| 55 |
* underlying BO memory. |
| 56 |
* |
| 57 |
* Specifically, when self-importing (i.e. importing a BO into the same |
| 58 |
* device that created it), the kernel will give us the same BO handle for |
| 59 |
* both BOs and we must only free it once when both references are |
| 60 |
* freed. Otherwise, if we are not self-importing, we get two different BO |
| 61 |
* handles, and we want to free each one individually. |
| 62 |
* |
| 63 |
* The refcount is also useful for being able to maintain BOs across |
| 64 |
* VK object lifetimes, such as pipelines suballocating out of BOs |
| 65 |
* allocated on the device. |
| 66 |
*/ |
| 67 |
struct util_sparse_array bo_map; |
| 68 |
|
| 69 |
/* Required heaps */ |
| 70 |
struct pvr_drm_winsys_heap general_heap; |
| 71 |
struct pvr_drm_winsys_heap pds_heap; |
| 72 |
struct pvr_drm_winsys_heap usc_heap; |
| 73 |
struct pvr_drm_winsys_heap vis_test_heap; |
| 74 |
struct pvr_drm_winsys_heap transfer_frag_heap; |
| 75 |
|
| 76 |
/* Optional heaps */ |
| 77 |
bool rgn_hdr_heap_present; |
| 78 |
struct pvr_drm_winsys_heap rgn_hdr_heap; |
| 79 |
|
| 80 |
/* vma's for carveout memory regions */ |
| 81 |
struct pvr_winsys_vma *pds_vma; |
| 82 |
struct pvr_winsys_vma *usc_vma; |
| 83 |
struct pvr_winsys_vma *general_vma; |
| 84 |
|
| 85 |
uint32_t vm_context; |
| 86 |
}; |
| 87 |
|
| 88 |
/******************************************* |
| 89 |
helper macros |
| 90 |
*******************************************/ |
| 91 |
|
| 92 |
#define to_pvr_drm_winsys(ws) container_of((ws), struct pvr_drm_winsys, base) |
| 93 |
#define to_pvr_drm_winsys_heap(heap) \ |
| 94 |
container_of((heap), struct pvr_drm_winsys_heap, base) |
| 95 |
|
| 96 |
#endif /* PVR_DRM_H */ |