2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
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
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
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #include <sys/types.h>
31 #include "util/macros.h"
32 #include "util/u_atomic.h"
33 #include "util/list.h"
34 #include "pipe/p_defines.h"
36 struct gen_device_info
;
37 struct pipe_debug_callback
;
39 enum iris_memory_zone
{
46 #define IRIS_MEMZONE_COUNT (IRIS_MEMZONE_OTHER + 1)
50 * Size in bytes of the buffer object.
52 * The size may be larger than the size originally requested for the
53 * allocation, such as being aligned to page size.
57 /** Buffer manager context associated with this buffer object */
58 struct iris_bufmgr
*bufmgr
;
60 /** The GEM handle for this buffer object. */
64 * Virtual address of the buffer inside the PPGTT (Per-Process Graphics
67 * Although each hardware context has its own VMA, we assign BO's to the
68 * same address in all contexts, for simplicity.
73 * The validation list index for this buffer, or -1 when not in a batch.
74 * Note that a single buffer may be in multiple batches (contexts), and
75 * this is a global field, which refers to the last batch using the BO.
76 * It should not be considered authoritative, but can be used to avoid a
77 * linear walk of the validation list in the common case by guessing that
78 * exec_bos[bo->index] == bo and confirming whether that's the case.
83 * Boolean of whether the GPU is definitely not accessing the buffer.
85 * This is only valid when reusable, since non-reusable
86 * buffers are those that have been shared with other
87 * processes, so we don't know their state.
97 * Kenel-assigned global name for this object
99 * List contains both flink named and prime fd'd objects
101 unsigned global_name
;
104 * Current tiling mode
106 uint32_t tiling_mode
;
107 uint32_t swizzle_mode
;
112 /** Mapped address for the buffer, saved across map/unmap cycles */
114 /** GTT virtual address for the buffer, saved across map/unmap cycles */
116 /** WC CPU address for the buffer, saved across map/unmap cycles */
120 struct list_head head
;
123 * Boolean of whether this buffer can be re-used
128 * Boolean of whether this buffer has been shared with an external client.
133 * Boolean of whether this buffer is cache coherent
138 #define BO_ALLOC_ZEROED (1<<0)
141 * Allocate a buffer object.
143 * Buffer objects are not necessarily initially mapped into CPU virtual
144 * address space or graphics device aperture. They must be mapped
145 * using iris_bo_map() to be used by the CPU.
147 struct iris_bo
*iris_bo_alloc(struct iris_bufmgr
*bufmgr
,
150 enum iris_memory_zone memzone
);
153 * Allocate a tiled buffer object.
155 * Alignment for tiled objects is set automatically; the 'flags'
156 * argument provides a hint about how the object will be used initially.
158 * Valid tiling formats are:
163 struct iris_bo
*iris_bo_alloc_tiled(struct iris_bufmgr
*bufmgr
,
166 uint32_t tiling_mode
,
169 enum iris_memory_zone memzone
);
171 /** Takes a reference on a buffer object */
173 iris_bo_reference(struct iris_bo
*bo
)
175 p_atomic_inc(&bo
->refcount
);
179 * Releases a reference on a buffer object, freeing the data if
180 * no references remain.
182 void iris_bo_unreference(struct iris_bo
*bo
);
184 #define MAP_READ PIPE_TRANSFER_READ
185 #define MAP_WRITE PIPE_TRANSFER_WRITE
186 #define MAP_ASYNC PIPE_TRANSFER_UNSYNCHRONIZED
187 #define MAP_PERSISTENT PIPE_TRANSFER_PERSISTENT
188 #define MAP_COHERENT PIPE_TRANSFER_COHERENT
190 #define MAP_INTERNAL_MASK (0xff << 24)
191 #define MAP_RAW (0x01 << 24)
194 * Maps the buffer into userspace.
196 * This function will block waiting for any existing execution on the
197 * buffer to complete, first. The resulting mapping is returned.
199 MUST_CHECK
void *iris_bo_map(struct pipe_debug_callback
*dbg
,
200 struct iris_bo
*bo
, unsigned flags
);
203 * Reduces the refcount on the userspace mapping of the buffer
206 static inline int iris_bo_unmap(struct iris_bo
*bo
) { return 0; }
208 /** Write data into an object. */
209 int iris_bo_subdata(struct iris_bo
*bo
, uint64_t offset
,
210 uint64_t size
, const void *data
);
212 * Waits for rendering to an object by the GPU to have completed.
214 * This is not required for any access to the BO by bo_map,
215 * bo_subdata, etc. It is merely a way for the driver to implement
218 void iris_bo_wait_rendering(struct iris_bo
*bo
);
221 * Tears down the buffer manager instance.
223 void iris_bufmgr_destroy(struct iris_bufmgr
*bufmgr
);
226 * Get the current tiling (and resulting swizzling) mode for the bo.
228 * \param buf Buffer to get tiling mode for
229 * \param tiling_mode returned tiling mode
230 * \param swizzle_mode returned swizzling mode
232 int iris_bo_get_tiling(struct iris_bo
*bo
, uint32_t *tiling_mode
,
233 uint32_t *swizzle_mode
);
236 * Create a visible name for a buffer which can be used by other apps
238 * \param buf Buffer to create a name for
239 * \param name Returned name
241 int iris_bo_flink(struct iris_bo
*bo
, uint32_t *name
);
244 * Returns 1 if mapping the buffer for write could cause the process
245 * to block, due to the object being active in the GPU.
247 int iris_bo_busy(struct iris_bo
*bo
);
250 * Specify the volatility of the buffer.
251 * \param bo Buffer to create a name for
252 * \param madv The purgeable status
254 * Use I915_MADV_DONTNEED to mark the buffer as purgeable, and it will be
255 * reclaimed under memory pressure. If you subsequently require the buffer,
256 * then you must pass I915_MADV_WILLNEED to mark the buffer as required.
258 * Returns 1 if the buffer was retained, or 0 if it was discarded whilst
259 * marked as I915_MADV_DONTNEED.
261 int iris_bo_madvise(struct iris_bo
*bo
, int madv
);
263 /* drm_bacon_bufmgr_gem.c */
264 struct iris_bufmgr
*iris_bufmgr_init(struct gen_device_info
*devinfo
, int fd
);
265 struct iris_bo
*iris_bo_gem_create_from_name(struct iris_bufmgr
*bufmgr
,
268 void iris_bufmgr_enable_reuse(struct iris_bufmgr
*bufmgr
);
270 int iris_bo_wait(struct iris_bo
*bo
, int64_t timeout_ns
);
272 uint32_t iris_create_hw_context(struct iris_bufmgr
*bufmgr
);
274 #define IRIS_CONTEXT_LOW_PRIORITY ((I915_CONTEXT_MIN_USER_PRIORITY-1)/2)
275 #define IRIS_CONTEXT_MEDIUM_PRIORITY (I915_CONTEXT_DEFAULT_PRIORITY)
276 #define IRIS_CONTEXT_HIGH_PRIORITY ((I915_CONTEXT_MAX_USER_PRIORITY+1)/2)
278 int iris_hw_context_set_priority(struct iris_bufmgr
*bufmgr
,
279 uint32_t ctx_id
, int priority
);
281 void iris_destroy_hw_context(struct iris_bufmgr
*bufmgr
, uint32_t ctx_id
);
283 int iris_bo_export_dmabuf(struct iris_bo
*bo
, int *prime_fd
);
284 struct iris_bo
*iris_bo_import_dmabuf(struct iris_bufmgr
*bufmgr
, int prime_fd
);
286 uint32_t iris_bo_export_gem_handle(struct iris_bo
*bo
);
288 int iris_reg_read(struct iris_bufmgr
*bufmgr
, uint32_t offset
, uint64_t *out
);
290 int drm_ioctl(int fd
, unsigned long request
, void *arg
);
293 #endif /* IRIS_BUFMGR_H */