i965: Remove unused brw_bo_map__* functions
[mesa.git] / src / mesa / drivers / dri / i965 / brw_bufmgr.h
1 /*
2 * Copyright © 2008-2012 Intel Corporation
3 *
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:
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
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
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28 /**
29 * @file brw_bufmgr.h
30 *
31 * Public definitions of Intel-specific bufmgr functions.
32 */
33
34 #ifndef INTEL_BUFMGR_H
35 #define INTEL_BUFMGR_H
36
37 #include <stdbool.h>
38 #include <stdint.h>
39 #include <stdio.h>
40 #include "util/list.h"
41
42 #if defined(__cplusplus)
43 extern "C" {
44 #endif
45
46 struct gen_device_info;
47 struct brw_context;
48
49 struct brw_bo {
50 /**
51 * Size in bytes of the buffer object.
52 *
53 * The size may be larger than the size originally requested for the
54 * allocation, such as being aligned to page size.
55 */
56 uint64_t size;
57
58 /**
59 * Alignment requirement for object
60 *
61 * Used for GTT mapping & pinning the object.
62 */
63 uint64_t align;
64
65 /**
66 * Virtual address for accessing the buffer data. Only valid while
67 * mapped.
68 */
69 #ifdef __cplusplus
70 void *virt;
71 #else
72 void *virtual;
73 #endif
74
75 /** Buffer manager context associated with this buffer object */
76 struct brw_bufmgr *bufmgr;
77
78 /** The GEM handle for this buffer object. */
79 uint32_t gem_handle;
80
81 /**
82 * Last seen card virtual address (offset from the beginning of the
83 * aperture) for the object. This should be used to fill relocation
84 * entries when calling brw_bo_emit_reloc()
85 */
86 uint64_t offset64;
87
88 /**
89 * Boolean of whether the GPU is definitely not accessing the buffer.
90 *
91 * This is only valid when reusable, since non-reusable
92 * buffers are those that have been shared with other
93 * processes, so we don't know their state.
94 */
95 bool idle;
96
97 int refcount;
98 const char *name;
99
100 #ifndef EXEC_OBJECT_CAPTURE
101 #define EXEC_OBJECT_CAPTURE (1<<7)
102 #endif
103 uint64_t kflags;
104
105 /**
106 * Kenel-assigned global name for this object
107 *
108 * List contains both flink named and prime fd'd objects
109 */
110 unsigned int global_name;
111
112 /**
113 * Current tiling mode
114 */
115 uint32_t tiling_mode;
116 uint32_t swizzle_mode;
117 uint32_t stride;
118
119 time_t free_time;
120
121 /** Mapped address for the buffer, saved across map/unmap cycles */
122 void *mem_virtual;
123 /** GTT virtual address for the buffer, saved across map/unmap cycles */
124 void *gtt_virtual;
125 /** WC CPU address for the buffer, saved across map/unmap cycles */
126 void *wc_virtual;
127 int map_count;
128
129 /** BO cache list */
130 struct list_head head;
131
132 /**
133 * Boolean of whether this buffer can be re-used
134 */
135 bool reusable;
136 };
137
138 #define BO_ALLOC_FOR_RENDER (1<<0)
139
140 /**
141 * Allocate a buffer object.
142 *
143 * Buffer objects are not necessarily initially mapped into CPU virtual
144 * address space or graphics device aperture. They must be mapped
145 * using bo_map() or brw_bo_map_gtt() to be used by the CPU.
146 */
147 struct brw_bo *brw_bo_alloc(struct brw_bufmgr *bufmgr, const char *name,
148 uint64_t size, uint64_t alignment);
149
150 /**
151 * Allocate a tiled buffer object.
152 *
153 * Alignment for tiled objects is set automatically; the 'flags'
154 * argument provides a hint about how the object will be used initially.
155 *
156 * Valid tiling formats are:
157 * I915_TILING_NONE
158 * I915_TILING_X
159 * I915_TILING_Y
160 *
161 * Note the tiling format may be rejected; callers should check the
162 * 'tiling_mode' field on return, as well as the pitch value, which
163 * may have been rounded up to accommodate for tiling restrictions.
164 */
165 struct brw_bo *brw_bo_alloc_tiled(struct brw_bufmgr *bufmgr,
166 const char *name,
167 int x, int y, int cpp,
168 uint32_t tiling_mode,
169 uint32_t *pitch,
170 unsigned flags);
171
172 /** Takes a reference on a buffer object */
173 void brw_bo_reference(struct brw_bo *bo);
174
175 /**
176 * Releases a reference on a buffer object, freeing the data if
177 * no references remain.
178 */
179 void brw_bo_unreference(struct brw_bo *bo);
180
181 /**
182 * Maps the buffer into userspace.
183 *
184 * This function will block waiting for any existing execution on the
185 * buffer to complete, first. The resulting mapping is available at
186 * buf->virtual.
187 */
188 int brw_bo_map(struct brw_context *brw, struct brw_bo *bo, int write_enable);
189
190 /**
191 * Reduces the refcount on the userspace mapping of the buffer
192 * object.
193 */
194 int brw_bo_unmap(struct brw_bo *bo);
195
196 /** Write data into an object. */
197 int brw_bo_subdata(struct brw_bo *bo, uint64_t offset,
198 uint64_t size, const void *data);
199 /** Read data from an object. */
200 int brw_bo_get_subdata(struct brw_bo *bo, uint64_t offset,
201 uint64_t size, void *data);
202 /**
203 * Waits for rendering to an object by the GPU to have completed.
204 *
205 * This is not required for any access to the BO by bo_map,
206 * bo_subdata, etc. It is merely a way for the driver to implement
207 * glFinish.
208 */
209 void brw_bo_wait_rendering(struct brw_context *brw, struct brw_bo *bo);
210
211 /**
212 * Tears down the buffer manager instance.
213 */
214 void brw_bufmgr_destroy(struct brw_bufmgr *bufmgr);
215
216 /**
217 * Get the current tiling (and resulting swizzling) mode for the bo.
218 *
219 * \param buf Buffer to get tiling mode for
220 * \param tiling_mode returned tiling mode
221 * \param swizzle_mode returned swizzling mode
222 */
223 int brw_bo_get_tiling(struct brw_bo *bo, uint32_t *tiling_mode,
224 uint32_t *swizzle_mode);
225
226 /**
227 * Create a visible name for a buffer which can be used by other apps
228 *
229 * \param buf Buffer to create a name for
230 * \param name Returned name
231 */
232 int brw_bo_flink(struct brw_bo *bo, uint32_t *name);
233
234 /**
235 * Returns 1 if mapping the buffer for write could cause the process
236 * to block, due to the object being active in the GPU.
237 */
238 int brw_bo_busy(struct brw_bo *bo);
239
240 /**
241 * Specify the volatility of the buffer.
242 * \param bo Buffer to create a name for
243 * \param madv The purgeable status
244 *
245 * Use I915_MADV_DONTNEED to mark the buffer as purgeable, and it will be
246 * reclaimed under memory pressure. If you subsequently require the buffer,
247 * then you must pass I915_MADV_WILLNEED to mark the buffer as required.
248 *
249 * Returns 1 if the buffer was retained, or 0 if it was discarded whilst
250 * marked as I915_MADV_DONTNEED.
251 */
252 int brw_bo_madvise(struct brw_bo *bo, int madv);
253
254 /* drm_bacon_bufmgr_gem.c */
255 struct brw_bufmgr *brw_bufmgr_init(struct gen_device_info *devinfo,
256 int fd, int batch_size);
257 struct brw_bo *brw_bo_gem_create_from_name(struct brw_bufmgr *bufmgr,
258 const char *name,
259 unsigned int handle);
260 void brw_bufmgr_enable_reuse(struct brw_bufmgr *bufmgr);
261 int brw_bo_map_unsynchronized(struct brw_context *brw, struct brw_bo *bo);
262 int brw_bo_map_gtt(struct brw_context *brw, struct brw_bo *bo);
263
264 int brw_bo_wait(struct brw_bo *bo, int64_t timeout_ns);
265
266 uint32_t brw_create_hw_context(struct brw_bufmgr *bufmgr);
267 void brw_destroy_hw_context(struct brw_bufmgr *bufmgr, uint32_t ctx_id);
268
269 int brw_bo_gem_export_to_prime(struct brw_bo *bo, int *prime_fd);
270 struct brw_bo *brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr,
271 int prime_fd, int size);
272
273 int brw_reg_read(struct brw_bufmgr *bufmgr, uint32_t offset,
274 uint64_t *result);
275
276 /** @{ */
277
278 #if defined(__cplusplus)
279 }
280 #endif
281 #endif /* INTEL_BUFMGR_H */