Debian Codegraph @

media_softlet/linux/common/os/i915_production/mos_bufmgr_priv.h

raw
1 /*
2 * Copyright © 2020 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 <[email protected]>
25 *
26 */
27
28 /**
29 * @file mos_bufmgr_priv.h
30 *
31 * Private definitions of Intel-specific bufmgr functions and structures.
32 */
33
34 #ifndef MOS_BUFMGR_PRIV_H
35 #define MOS_BUFMGR_PRIV_H
36
37 /**
38 * Context for a buffer manager instance.
39 *
40 * Contains public methods followed by private storage for the buffer manager.
41 */
42 struct mos_bufmgr {
43 /**
44 * Allocate a buffer object.
45 *
46 * Buffer objects are not necessarily initially mapped into CPU virtual
47 * address space or graphics device aperture. They must be mapped
48 * using bo_map() or drm_intel_gem_bo_map_gtt() to be used by the CPU.
49 */
50 struct mos_linux_bo *(*bo_alloc) (struct mos_bufmgr *bufmgr,
51 struct mos_drm_bo_alloc *alloc) = nullptr;
52
53 /**
54 * Allocate a buffer object from an existing user accessible
55 * address malloc'd with the provided size.
56 * Alignment is used when mapping to the gtt.
57 * Flags may be I915_VMAP_READ_ONLY or I915_USERPTR_UNSYNCHRONIZED
58 */
59 struct mos_linux_bo *(*bo_alloc_userptr)(struct mos_bufmgr *bufmgr,
60 struct mos_drm_bo_alloc_userptr *alloc_uptr) = nullptr;
61
62 /**
63 * Allocate a tiled buffer object.
64 *
65 * Alignment for tiled objects is set automatically; the 'flags'
66 * argument provides a hint about how the object will be used initially.
67 *
68 * Valid tiling formats are:
69 * TILING_NONE
70 * TILING_X
71 * TILING_Y
72 *
73 * Note the tiling format may be rejected; callers should check the
74 * 'tiling_mode' field on return, as well as the pitch value, which
75 * may have been rounded up to accommodate for tiling restrictions.
76 */
77 struct mos_linux_bo *(*bo_alloc_tiled) (struct mos_bufmgr *bufmgr,
78 struct mos_drm_bo_alloc_tiled *alloc_tiled) = nullptr;
79
80 /** Takes a reference on a buffer object */
81 void (*bo_reference) (struct mos_linux_bo *bo) = nullptr;
82
83 /**
84 * Releases a reference on a buffer object, freeing the data if
85 * no references remain.
86 */
87 void (*bo_unreference) (struct mos_linux_bo *bo) = nullptr;
88
89 /**
90 * Maps the buffer into userspace.
91 *
92 * This function will block waiting for any existing execution on the
93 * buffer to complete, first. The resulting mapping is available at
94 * buf->virtual.
95 */
96 int (*bo_map) (struct mos_linux_bo *bo, int write_enable) = nullptr;
97
98 /**
99 * Reduces the refcount on the userspace mapping of the buffer
100 * object.
101 */
102 int (*bo_unmap) (struct mos_linux_bo *bo) = nullptr;
103
104 /**
105 * Waits for rendering to an object by the GPU to have completed.
106 *
107 * This is not required for any access to the BO by bo_map,
108 * bo_subdata, etc. It is merely a way for the driver to implement
109 * glFinish.
110 */
111 void (*bo_wait_rendering) (struct mos_linux_bo *bo) = nullptr;
112
113 /**
114 * Tears down the buffer manager instance.
115 */
116 void (*destroy) (struct mos_bufmgr *bufmgr) = nullptr;
117
118 /**
119 * Indicate if the buffer can be placed anywhere in the full ppgtt
120 * address range (2^48).
121 *
122 * Any resource used with flat/heapless (0x00000000-0xfffff000)
123 * General State Heap (GSH) or Intructions State Heap (ISH) must
124 * be in a 32-bit range. 48-bit range will only be used when explicitly
125 * requested.
126 *
127 * \param bo Buffer to set the use_48b_address_range flag.
128 * \param enable The flag value.
129 */
130 void (*bo_use_48b_address_range) (struct mos_linux_bo *bo, uint32_t enable) = nullptr;
131
132 /**
133 * Sets buffer total padded size when buffer is used by the GPU.
134 *
135 * This enables dynamic padding to be added without using any backing
136 * storage. For example handling GPU padding requirements for buffers
137 * allocated by an entity unaware of the same.
138 *
139 * Set padded size remains active until reset (to zero or actual object
140 * size).
141 *
142 * Returns 0 on success or an error code.
143 *
144 * \param bo Buffer to set total padded size for
145 * \param pad_to_size Total size in bytes of object plus padding
146 */
147 int (*bo_pad_to_size) (struct mos_linux_bo *bo, uint64_t pad_to_size) = nullptr;
148
149 /**
150 * Add relocation entry in reloc_buf, which will be updated with the
151 * target buffer's real offset on on command submission.
152 *
153 * Relocations remain in place for the lifetime of the buffer object.
154 *
155 * \param bo Buffer to write the relocation into.
156 * \param offset Byte offset within reloc_bo of the pointer to
157 * target_bo.
158 * \param target_bo Buffer whose offset should be written into the
159 * relocation entry.
160 * \param target_offset Constant value to be added to target_bo's
161 * offset in relocation entry.
162 * \param read_domains GEM read domains which the buffer will be
163 * read into by the command that this relocation
164 * is part of.
165 * \param write_domains GEM read domains which the buffer will be
166 * dirtied in by the command that this
167 * relocation is part of.
168 */
169 int (*bo_emit_reloc) (struct mos_linux_bo *bo, uint32_t offset,
170 struct mos_linux_bo *target_bo, uint32_t target_offset,
171 uint32_t read_domains, uint32_t write_domain,
172 uint64_t presumed_offset) = nullptr;
173
174 /** Executes the command buffer pointed to by bo. */
175 int (*bo_exec) (struct mos_linux_bo *bo, int used,
176 drm_clip_rect_t *cliprects, int num_cliprects,
177 int DR4) = nullptr;
178 /** Executes the command buffer pointed to by bo on the selected
179 * ring buffer
180 */
181 int (*bo_mrb_exec) (struct mos_linux_bo *bo, int used,
182 drm_clip_rect_t *cliprects, int num_cliprects,
183 int DR4, unsigned flags) = nullptr;
184
185 /**
186 * Ask that the buffer be placed in tiling mode
187 *
188 * \param buf Buffer to set tiling mode for
189 * \param tiling_mode desired, and returned tiling mode
190 */
191 int (*bo_set_tiling) (struct mos_linux_bo *bo, uint32_t * tiling_mode,
192 uint32_t stride) = nullptr;
193
194 /**
195 * Get the current tiling (and resulting swizzling) mode for the bo.
196 *
197 * \param buf Buffer to get tiling mode for
198 * \param tiling_mode returned tiling mode
199 * \param swizzle_mode returned swizzling mode
200 */
201 int (*bo_get_tiling) (struct mos_linux_bo *bo, uint32_t * tiling_mode,
202 uint32_t * swizzle_mode) = nullptr;
203
204 /**
205 * Softpin the buffer object
206 * \param bo Buffer to set the softpin
207 */
208 int (*bo_set_softpin) (struct mos_linux_bo *bo) = nullptr;
209
210 /**
211 * Add softpin object to softpin target list of the command buffer
212 * \param bo Command buffer which store the softpin target list
213 * \param target_bo Softpin target to be added
214 * \param write_flag Whether write flag is needed
215 */
216 int (*bo_add_softpin_target) (struct mos_linux_bo *bo, struct mos_linux_bo *target_bo, bool write_flag) = nullptr;
217
218 /**
219 * Create a visible name for a buffer which can be used by other apps
220 *
221 * \param buf Buffer to create a name for
222 * \param name Returned name
223 */
224 int (*bo_flink) (struct mos_linux_bo *bo, uint32_t * name) = nullptr;
225
226 /**
227 * Returns 1 if mapping the buffer for write could cause the process
228 * to block, due to the object being active in the GPU.
229 */
230 int (*bo_busy) (struct mos_linux_bo *bo) = nullptr;
231
232 /**
233 * Specify the volatility of the buffer.
234 * \param bo Buffer to create a name for
235 * \param madv The purgeable status
236 *
237 * Use I915_MADV_DONTNEED to mark the buffer as purgeable, and it will be
238 * reclaimed under memory pressure. If you subsequently require the buffer,
239 * then you must pass I915_MADV_WILLNEED to mark the buffer as required.
240 *
241 * Returns 1 if the buffer was retained, or 0 if it was discarded whilst
242 * marked as I915_MADV_DONTNEED.
243 */
244 int (*bo_madvise) (struct mos_linux_bo *bo, int madv) = nullptr;
245
246 int (*check_aperture_space) (struct mos_linux_bo ** bo_array, int count) = nullptr;
247
248 /**
249 * Disable buffer reuse for buffers which will be shared in some way,
250 * as with scanout buffers. When the buffer reference count goes to
251 * zero, it will be freed and not placed in the reuse list.
252 *
253 * \param bo Buffer to disable reuse for
254 */
255 int (*bo_disable_reuse) (struct mos_linux_bo *bo) = nullptr;
256
257 /**
258 * Query whether a buffer is reusable.
259 *
260 * \param bo Buffer to query
261 */
262 int (*bo_is_reusable) (struct mos_linux_bo *bo) = nullptr;
263
264 /** Returns true if target_bo is in the relocation tree rooted at bo. */
265 int (*bo_references) (struct mos_linux_bo *bo, struct mos_linux_bo *target_bo) = nullptr;
266
267 /**
268 * Set async flag for a buffer object.
269 *
270 * \param bo Buffer to set async
271 */
272 void (*set_object_async) (struct mos_linux_bo *bo) = nullptr;
273
274 /**
275 * Set execution async flag for a buffer object.
276 *
277 * \param bo Command buffer
278 * \param target_bo Buffer to set async
279 */
280 void (*set_exec_object_async) (struct mos_linux_bo *bo, struct mos_linux_bo *target_bo) = nullptr;
281
282 /**
283 * Set capture flag for a buffer object.
284 *
285 * \param bo Buffer to set capture
286 */
287 void (*set_object_capture)(struct mos_linux_bo *bo) = nullptr;
288
289 /**
290 * Waits on a BO for the given amount of time.
291 *
292 * @bo: buffer object to wait for
293 * @timeout_ns: amount of time to wait in nanoseconds.
294 * If value is less than 0, an infinite wait will occur.
295 *
296 * Returns 0 if the wait was successful ie. the last batch referencing the
297 * object has completed within the allotted time. Otherwise some negative return
298 * value describes the error. Of particular interest is -ETIME when the wait has
299 * failed to yield the desired result.
300 *
301 * Similar to drm_intel_gem_bo_wait_rendering except a timeout parameter allows
302 * the operation to give up after a certain amount of time. Another subtle
303 * difference is the internal locking semantics are different (this variant does
304 * not hold the lock for the duration of the wait). This makes the wait subject
305 * to a larger userspace race window.
306 *
307 * The implementation shall wait until the object is no longer actively
308 * referenced within a batch buffer at the time of the call. The wait will
309 * not guarantee that the buffer is re-issued via another thread, or an flinked
310 * handle. Userspace must make sure this race does not occur if such precision
311 * is important.
312 *
313 * Note that some kernels have broken the inifite wait for negative values
314 * promise, upgrade to latest stable kernels if this is the case.
315 */
316 int (*bo_wait)(struct mos_linux_bo *bo, int64_t timeout_ns) = nullptr;
317
318 void (*bo_clear_relocs)(struct mos_linux_bo *bo, int start) = nullptr;
319 struct mos_linux_context *(*context_create)(struct mos_bufmgr *bufmgr) = nullptr;
320 struct mos_linux_context *(*context_create_ext)(
321 struct mos_bufmgr *bufmgr,
322 __u32 flags,
323 bool bContextProtected) = nullptr;
324 struct mos_linux_context *(*context_create_shared)(
325 struct mos_bufmgr *bufmgr,
326 mos_linux_context* ctx,
327 __u32 flags,
328 bool bContextProtected,
329 void *engine_map,
330 uint8_t ctx_width,
331 uint8_t num_placements,
332 uint32_t ctx_type) = nullptr;
333 void (*context_destroy)(struct mos_linux_context *ctx) = nullptr;
334 __u32 (*vm_create)(struct mos_bufmgr *bufmgr) = nullptr;
335 void (*vm_destroy)(struct mos_bufmgr *bufmgr, __u32 vm_id) = nullptr;
336 int (*bo_context_exec2)(struct mos_linux_bo *bo, int used, struct mos_linux_context *ctx,
337 struct drm_clip_rect *cliprects, int num_cliprects, int DR4,
338 unsigned int flags, int *fence) = nullptr;
339
340 int (*bo_context_exec3)(struct mos_linux_bo **bo, int num_bo, struct mos_linux_context *ctx,
341 struct drm_clip_rect *cliprects, int num_cliprects, int DR4,
342 unsigned int flags, int *fence) = nullptr;
343 bool (*bo_is_exec_object_async)(struct mos_linux_bo *bo) = nullptr;
344 bool (*bo_is_softpin)(struct mos_linux_bo *bo) = nullptr;
345 int (*bo_map_gtt)(struct mos_linux_bo *bo) = nullptr;
346 int (*bo_unmap_gtt)(struct mos_linux_bo *bo) = nullptr;
347 int (*bo_map_wc)(struct mos_linux_bo *bo) = nullptr;
348 int (*bo_unmap_wc)(struct mos_linux_bo *bo) = nullptr;
349 int (*bo_map_unsynchronized)(struct mos_linux_bo *bo) = nullptr;
350 void (*bo_start_gtt_access)(struct mos_linux_bo *bo, int write_enable) = nullptr;
351 mos_oca_exec_list_info* (*bo_get_softpin_targets_info)(struct mos_linux_bo *bo, int *count) = nullptr;
352 struct mos_linux_bo *(*bo_create_from_name)(struct mos_bufmgr *bufmgr,
353 const char *name,
354 unsigned int handle) = nullptr;
355 void (*enable_reuse)(struct mos_bufmgr *bufmgr) = nullptr;
356 void (*enable_softpin)(struct mos_bufmgr *bufmgr, bool va1m_align) = nullptr;
357 void (*enable_vmbind)(struct mos_bufmgr *bufmgr) = nullptr;
358 void (*disable_object_capture)(struct mos_bufmgr *bufmgr) = nullptr;
359 int (*get_memory_info)(struct mos_bufmgr *bufmgr, char *info, uint32_t length) = nullptr;
360 int (*get_devid)(struct mos_bufmgr *bufmgr) = nullptr;
361 void (*realloc_cache)(struct mos_bufmgr *bufmgr, uint8_t alloc_mode) = nullptr;
362 int (*query_engines_count)(struct mos_bufmgr *bufmgr,
363 unsigned int *nengine) = nullptr;
364
365 int (*query_engines)(struct mos_bufmgr *bufmgr,
366 __u16 engine_class,
367 __u64 caps,
368 unsigned int *nengine,
369 void *ci) = nullptr;
370
371 size_t (*get_engine_class_size)() = nullptr;
372
373 void (*select_fixed_engine)(struct mos_bufmgr *bufmgr,
374 void *engine_map,
375 uint32_t *nengine,
376 uint32_t fixed_instance_mask) = nullptr;
377
378 int (*set_context_param)(struct mos_linux_context *ctx,
379 uint32_t size,
380 uint64_t param,
381 uint64_t value) = nullptr;
382 int (*set_context_param_parallel)(struct mos_linux_context *ctx,
383 struct i915_engine_class_instance *ci,
384 unsigned int count) = nullptr;
385 int (*set_context_param_load_balance)(struct mos_linux_context *ctx,
386 struct i915_engine_class_instance *ci,
387 unsigned int count) = nullptr;
388 int (*set_context_param_bond)(struct mos_linux_context *ctx,
389 struct i915_engine_class_instance master_ci,
390 struct i915_engine_class_instance *bond_ci,
391 unsigned int bond_count) = nullptr;
392 int (*get_context_param)(struct mos_linux_context *ctx,
393 uint32_t size,
394 uint64_t param,
395 uint64_t *value) = nullptr;
396 struct mos_linux_bo *(*bo_create_from_prime)(struct mos_bufmgr *bufmgr,
397 struct mos_drm_bo_alloc_prime *alloc_prime) = nullptr;
398 int (*bo_export_to_prime)(struct mos_linux_bo *bo, int *prime_fd) = nullptr;
399 int (*reg_read)(struct mos_bufmgr *bufmgr,
400 uint32_t offset,
401 uint64_t *result) = nullptr;
402 int (*get_reset_stats)(struct mos_linux_context *ctx,
403 uint32_t *reset_count,
404 uint32_t *active,
405 uint32_t *pending) = nullptr;
406 int (*get_context_param_sseu)(struct mos_linux_context *ctx,
407 struct drm_i915_gem_context_param_sseu *sseu) = nullptr;
408 int (*set_context_param_sseu)(struct mos_linux_context *ctx,
409 struct drm_i915_gem_context_param_sseu sseu) = nullptr;
410 int (*query_sys_engines)(struct mos_bufmgr *bufmgr, MEDIA_SYSTEM_INFO* gfx_info) = nullptr;
411 int (*query_device_blob)(struct mos_bufmgr *bufmgr, MEDIA_SYSTEM_INFO* gfx_info) = nullptr;
412 int (*get_driver_info)(struct mos_bufmgr *bufmgr, struct LinuxDriverInfo *drvInfo) = nullptr;
413 int (*query_hw_ip_version)(struct mos_bufmgr *bufmgr, __u16 engine_class, void *ip_ver_info) = nullptr;
414 uint64_t (*get_platform_information)(struct mos_bufmgr *bufmgr) = nullptr;
415 void (*set_platform_information)(struct mos_bufmgr *bufmgr, uint64_t p) = nullptr;
416 int (*get_ts_frequency)(struct mos_bufmgr *bufmgr, uint32_t *ts_freq) = nullptr;
417 bool (*has_bsd2)(struct mos_bufmgr *bufmgr) = nullptr;
418 void (*enable_turbo_boost)(struct mos_bufmgr *bufmgr) = nullptr;
419 uint8_t (*switch_off_n_bits)(struct mos_linux_context *ctx, uint8_t in_mask, int n) = nullptr;
420 unsigned int (*hweight8)(struct mos_linux_context *ctx, uint8_t w) = nullptr;
421
422 /**< Enables verbose debugging printouts */
423 int debug = 0;
424 /** used for reserved info*/
425 uint32_t *get_reserved = nullptr;
426 uint32_t tile_id = 0;
427 bool has_full_vd = true;
428 uint64_t platform_information = 0;
429 };
430
431 #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
432 #define ROUND_UP_TO(x, y) (((x) + (y) - 1) / (y) * (y))
433 #define ROUND_UP_TO_MB(x) ROUND_UP_TO((x), 1024*1024)
434
435 #endif /* INTEL_BUFMGR_PRIV_H */