xref: /aosp_15_r20/external/mesa3d/src/nouveau/winsys/nouveau_bo.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 #ifndef NOUVEAU_BO
2 #define NOUVEAU_BO 1
3 
4 #include "nouveau_private.h"
5 
6 #include "nouveau_device.h"
7 
8 #ifdef __cplusplus
9 #include <atomic>
10 using std::atomic_uint_fast32_t;
11 #else
12 #include <stdatomic.h>
13 #endif
14 
15 #include <sys/mman.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 enum nouveau_ws_bo_flags {
22    /* vram or gart depending on GPU */
23    NOUVEAU_WS_BO_VRAM  = 1 << 0,
24    NOUVEAU_WS_BO_GART  = 1 << 1,
25    NOUVEAU_WS_BO_MAP   = 1 << 2,
26    NOUVEAU_WS_BO_NO_SHARE = 1 << 3,
27 };
28 
29 enum nouveau_ws_bo_map_flags {
30    NOUVEAU_WS_BO_RD   = 1 << 0,
31    NOUVEAU_WS_BO_WR   = 1 << 1,
32    NOUVEAU_WS_BO_RDWR = NOUVEAU_WS_BO_RD | NOUVEAU_WS_BO_WR,
33 };
34 
35 struct nouveau_ws_bo {
36    struct nouveau_ws_device *dev;
37    uint64_t size;
38    uint64_t map_handle;
39    uint32_t handle;
40    enum nouveau_ws_bo_flags flags;
41    atomic_uint_fast32_t refcnt;
42 };
43 
44 void nouveau_ws_bo_bind_vma(struct nouveau_ws_device *dev,
45                             struct nouveau_ws_bo *bo,
46                             uint64_t addr,
47                             uint64_t range,
48                             uint64_t bo_offset,
49                             uint32_t pte_kind);
50 void nouveau_ws_bo_unbind_vma(struct nouveau_ws_device *dev,
51                               uint64_t offset, uint64_t range);
52 
53 struct nouveau_ws_bo *nouveau_ws_bo_new(struct nouveau_ws_device *,
54                                         uint64_t size, uint64_t align,
55                                         enum nouveau_ws_bo_flags);
56 struct nouveau_ws_bo *nouveau_ws_bo_new_mapped(struct nouveau_ws_device *,
57                                                uint64_t size, uint64_t align,
58                                                enum nouveau_ws_bo_flags,
59                                                enum nouveau_ws_bo_map_flags map_flags,
60                                                void **map_out);
61 struct nouveau_ws_bo *nouveau_ws_bo_new_tiled(struct nouveau_ws_device *,
62                                               uint64_t size, uint64_t align,
63                                               uint8_t pte_kind,
64                                               uint16_t tile_mode,
65                                               enum nouveau_ws_bo_flags);
66 struct nouveau_ws_bo *nouveau_ws_bo_from_dma_buf(struct nouveau_ws_device *,
67                                                  int fd);
68 void nouveau_ws_bo_destroy(struct nouveau_ws_bo *);
69 void *nouveau_ws_bo_map(struct nouveau_ws_bo *,
70                         enum nouveau_ws_bo_map_flags);
71 void nouveau_ws_bo_unmap(struct nouveau_ws_bo *bo, void *ptr);
72 bool nouveau_ws_bo_wait(struct nouveau_ws_bo *, enum nouveau_ws_bo_map_flags flags);
73 int nouveau_ws_bo_dma_buf(struct nouveau_ws_bo *, int *fd);
74 
75 static inline void
nouveau_ws_bo_ref(struct nouveau_ws_bo * bo)76 nouveau_ws_bo_ref(struct nouveau_ws_bo *bo)
77 {
78    bo->refcnt++;
79 }
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 #endif
86