panfrost: Probe G31/G52 if PAN_MESA_DEBUG=bifrost
[mesa.git] / src / panfrost / encoder / pan_bo.h
1 /*
2 * © Copyright 2019 Alyssa Rosenzweig
3 * © Copyright 2019 Collabora, Ltd.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 */
25
26 #ifndef __PAN_BO_H__
27 #define __PAN_BO_H__
28
29 #include <panfrost-misc.h>
30 #include "util/list.h"
31 #include "pan_device.h"
32
33 /* Flags for allocated memory */
34
35 /* This memory region is executable */
36 #define PAN_BO_EXECUTE (1 << 0)
37
38 /* This memory region should be lazily allocated and grow-on-page-fault. Must
39 * be used in conjunction with INVISIBLE */
40 #define PAN_BO_GROWABLE (1 << 1)
41
42 /* This memory region should not be mapped to the CPU */
43 #define PAN_BO_INVISIBLE (1 << 2)
44
45 /* This memory region will be used for varyings and needs to have the cache
46 * bits twiddled accordingly */
47 #define PAN_BO_COHERENT_LOCAL (1 << 3)
48
49 /* This region may not be used immediately and will not mmap on allocate
50 * (semantically distinct from INVISIBLE, which cannot never be mmaped) */
51 #define PAN_BO_DELAY_MMAP (1 << 4)
52
53 /* Some BOs shouldn't be returned back to the reuse BO cache, use this flag to
54 * let the BO logic know about this contraint. */
55 #define PAN_BO_DONT_REUSE (1 << 5)
56
57 /* BO has been imported */
58 #define PAN_BO_IMPORTED (1 << 6)
59
60 /* BO has been exported */
61 #define PAN_BO_EXPORTED (1 << 7)
62
63 /* GPU access flags */
64
65 /* BO is either shared (can be accessed by more than one GPU batch) or private
66 * (reserved by a specific GPU job). */
67 #define PAN_BO_ACCESS_PRIVATE (0 << 0)
68 #define PAN_BO_ACCESS_SHARED (1 << 0)
69
70 /* BO is being read/written by the GPU */
71 #define PAN_BO_ACCESS_READ (1 << 1)
72 #define PAN_BO_ACCESS_WRITE (1 << 2)
73 #define PAN_BO_ACCESS_RW (PAN_BO_ACCESS_READ | PAN_BO_ACCESS_WRITE)
74
75 /* BO is accessed by the vertex/tiler job. */
76 #define PAN_BO_ACCESS_VERTEX_TILER (1 << 3)
77
78 /* BO is accessed by the fragment job. */
79 #define PAN_BO_ACCESS_FRAGMENT (1 << 4)
80
81 struct panfrost_bo {
82 /* Must be first for casting */
83 struct list_head bucket_link;
84
85 /* Used to link the BO to the BO cache LRU list. */
86 struct list_head lru_link;
87
88 /* Store the time this BO was use last, so the BO cache logic can evict
89 * stale BOs.
90 */
91 time_t last_used;
92
93 /* Atomic reference count */
94 int32_t refcnt;
95
96 struct panfrost_device *dev;
97
98 /* Mapping for the entire object (all levels) */
99 uint8_t *cpu;
100
101 /* GPU address for the object */
102 mali_ptr gpu;
103
104 /* Size of all entire trees */
105 size_t size;
106
107 int gem_handle;
108
109 uint32_t flags;
110
111 /* Combination of PAN_BO_ACCESS_{READ,WRITE} flags encoding pending
112 * GPU accesses to this BO. Useful to avoid calling the WAIT_BO ioctl
113 * when the BO is idle.
114 */
115 uint32_t gpu_access;
116 };
117
118 bool
119 panfrost_bo_wait(struct panfrost_bo *bo, int64_t timeout_ns,
120 uint32_t access_type);
121 void
122 panfrost_bo_reference(struct panfrost_bo *bo);
123 void
124 panfrost_bo_unreference(struct panfrost_bo *bo);
125 struct panfrost_bo *
126 panfrost_bo_create(struct panfrost_device *dev, size_t size,
127 uint32_t flags);
128 void
129 panfrost_bo_mmap(struct panfrost_bo *bo);
130 struct panfrost_bo *
131 panfrost_bo_import(struct panfrost_device *dev, int fd);
132 int
133 panfrost_bo_export(struct panfrost_bo *bo);
134 void
135 panfrost_bo_cache_evict_all(struct panfrost_device *dev);
136
137 #endif /* __PAN_BO_H__ */