15d37c04851dcce851a786e8019fc6d7ea31d754
2 * Copyright © 2008-2012 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
24 * Eric Anholt <eric@anholt.net>
31 * Public definitions of Intel-specific bufmgr functions.
34 #ifndef INTEL_BUFMGR_H
35 #define INTEL_BUFMGR_H
40 #include "util/u_atomic.h"
41 #include "util/list.h"
43 #if defined(__cplusplus)
47 struct gen_device_info
;
52 * Size in bytes of the buffer object.
54 * The size may be larger than the size originally requested for the
55 * allocation, such as being aligned to page size.
60 * Alignment requirement for object
62 * Used for GTT mapping & pinning the object.
66 /** Buffer manager context associated with this buffer object */
67 struct brw_bufmgr
*bufmgr
;
69 /** The GEM handle for this buffer object. */
73 * Last seen card virtual address (offset from the beginning of the
74 * aperture) for the object. This should be used to fill relocation
75 * entries when calling brw_bo_emit_reloc()
80 * Boolean of whether the GPU is definitely not accessing the buffer.
82 * This is only valid when reusable, since non-reusable
83 * buffers are those that have been shared with other
84 * processes, so we don't know their state.
91 #ifndef EXEC_OBJECT_CAPTURE
92 #define EXEC_OBJECT_CAPTURE (1<<7)
97 * Kenel-assigned global name for this object
99 * List contains both flink named and prime fd'd objects
101 unsigned int 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_FOR_RENDER (1<<0)
139 #define BO_ALLOC_ZEROED (1<<1)
142 * Allocate a buffer object.
144 * Buffer objects are not necessarily initially mapped into CPU virtual
145 * address space or graphics device aperture. They must be mapped
146 * using brw_bo_map() to be used by the CPU.
148 struct brw_bo
*brw_bo_alloc(struct brw_bufmgr
*bufmgr
, const char *name
,
149 uint64_t size
, uint64_t alignment
);
152 * Allocate a tiled buffer object.
154 * Alignment for tiled objects is set automatically; the 'flags'
155 * argument provides a hint about how the object will be used initially.
157 * Valid tiling formats are:
162 struct brw_bo
*brw_bo_alloc_tiled(struct brw_bufmgr
*bufmgr
,
165 uint32_t tiling_mode
,
170 * Allocate a tiled buffer object.
172 * Alignment for tiled objects is set automatically; the 'flags'
173 * argument provides a hint about how the object will be used initially.
175 * Valid tiling formats are:
180 * Note the tiling format may be rejected; callers should check the
181 * 'tiling_mode' field on return, as well as the pitch value, which
182 * may have been rounded up to accommodate for tiling restrictions.
184 struct brw_bo
*brw_bo_alloc_tiled_2d(struct brw_bufmgr
*bufmgr
,
186 int x
, int y
, int cpp
,
187 uint32_t tiling_mode
,
191 /** Takes a reference on a buffer object */
193 brw_bo_reference(struct brw_bo
*bo
)
195 p_atomic_inc(&bo
->refcount
);
199 * Releases a reference on a buffer object, freeing the data if
200 * no references remain.
202 void brw_bo_unreference(struct brw_bo
*bo
);
204 /* Must match MapBufferRange interface (for convenience) */
205 #define MAP_READ GL_MAP_READ_BIT
206 #define MAP_WRITE GL_MAP_WRITE_BIT
207 #define MAP_ASYNC GL_MAP_UNSYNCHRONIZED_BIT
208 #define MAP_PERSISTENT GL_MAP_PERSISTENT_BIT
209 #define MAP_COHERENT GL_MAP_COHERENT_BIT
211 #define MAP_INTERNAL_MASK (0xff << 24)
212 #define MAP_RAW (0x01 << 24)
215 * Maps the buffer into userspace.
217 * This function will block waiting for any existing execution on the
218 * buffer to complete, first. The resulting mapping is returned.
220 MUST_CHECK
void *brw_bo_map(struct brw_context
*brw
, struct brw_bo
*bo
, unsigned flags
);
223 * Reduces the refcount on the userspace mapping of the buffer
226 static inline int brw_bo_unmap(struct brw_bo
*bo
) { return 0; }
228 /** Write data into an object. */
229 int brw_bo_subdata(struct brw_bo
*bo
, uint64_t offset
,
230 uint64_t size
, const void *data
);
232 * Waits for rendering to an object by the GPU to have completed.
234 * This is not required for any access to the BO by bo_map,
235 * bo_subdata, etc. It is merely a way for the driver to implement
238 void brw_bo_wait_rendering(struct brw_bo
*bo
);
241 * Tears down the buffer manager instance.
243 void brw_bufmgr_destroy(struct brw_bufmgr
*bufmgr
);
246 * Get the current tiling (and resulting swizzling) mode for the bo.
248 * \param buf Buffer to get tiling mode for
249 * \param tiling_mode returned tiling mode
250 * \param swizzle_mode returned swizzling mode
252 int brw_bo_get_tiling(struct brw_bo
*bo
, uint32_t *tiling_mode
,
253 uint32_t *swizzle_mode
);
256 * Create a visible name for a buffer which can be used by other apps
258 * \param buf Buffer to create a name for
259 * \param name Returned name
261 int brw_bo_flink(struct brw_bo
*bo
, uint32_t *name
);
264 * Returns 1 if mapping the buffer for write could cause the process
265 * to block, due to the object being active in the GPU.
267 int brw_bo_busy(struct brw_bo
*bo
);
270 * Specify the volatility of the buffer.
271 * \param bo Buffer to create a name for
272 * \param madv The purgeable status
274 * Use I915_MADV_DONTNEED to mark the buffer as purgeable, and it will be
275 * reclaimed under memory pressure. If you subsequently require the buffer,
276 * then you must pass I915_MADV_WILLNEED to mark the buffer as required.
278 * Returns 1 if the buffer was retained, or 0 if it was discarded whilst
279 * marked as I915_MADV_DONTNEED.
281 int brw_bo_madvise(struct brw_bo
*bo
, int madv
);
283 /* drm_bacon_bufmgr_gem.c */
284 struct brw_bufmgr
*brw_bufmgr_init(struct gen_device_info
*devinfo
,
285 int fd
, int batch_size
);
286 struct brw_bo
*brw_bo_gem_create_from_name(struct brw_bufmgr
*bufmgr
,
288 unsigned int handle
);
289 void brw_bufmgr_enable_reuse(struct brw_bufmgr
*bufmgr
);
291 int brw_bo_wait(struct brw_bo
*bo
, int64_t timeout_ns
);
293 uint32_t brw_create_hw_context(struct brw_bufmgr
*bufmgr
);
294 void brw_destroy_hw_context(struct brw_bufmgr
*bufmgr
, uint32_t ctx_id
);
296 int brw_bo_gem_export_to_prime(struct brw_bo
*bo
, int *prime_fd
);
297 struct brw_bo
*brw_bo_gem_create_from_prime(struct brw_bufmgr
*bufmgr
,
300 int brw_reg_read(struct brw_bufmgr
*bufmgr
, uint32_t offset
,
305 #if defined(__cplusplus)
308 #endif /* INTEL_BUFMGR_H */