blob: be83a56a4f6a2a358ca0c0f05f33a58c845c773d [file] [log] [blame]
Eric Anholtc4857422008-06-03 10:20:49 -07001/*
Eric Anholtc9ce2ed2012-03-09 16:08:23 -08002 * Copyright © 2008-2012 Intel Corporation
Eric Anholtc4857422008-06-03 10:20:49 -07003 *
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 intel_bufmgr.h
30 *
31 * Public definitions of Intel-specific bufmgr functions.
32 */
33
Eric Anholt738e36a2008-09-05 10:35:32 +010034#ifndef INTEL_BUFMGR_H
35#define INTEL_BUFMGR_H
Eric Anholtc4857422008-06-03 10:20:49 -070036
Eric Anholtea33a232012-01-03 13:05:57 -080037#include <stdio.h>
Eric Anholt738e36a2008-09-05 10:35:32 +010038#include <stdint.h>
Eric Anholt4db16a92011-10-11 15:59:03 -070039#include <stdio.h>
Eric Anholtc4857422008-06-03 10:20:49 -070040
Chris Wilson1443bea2010-11-25 16:59:20 +000041struct drm_clip_rect;
42
Eric Anholt4b982642008-10-30 09:33:07 -070043typedef struct _drm_intel_bufmgr drm_intel_bufmgr;
Ben Widawskyb3b123d2012-01-13 11:31:31 -080044typedef struct _drm_intel_context drm_intel_context;
Eric Anholt4b982642008-10-30 09:33:07 -070045typedef struct _drm_intel_bo drm_intel_bo;
Eric Anholt738e36a2008-09-05 10:35:32 +010046
Eric Anholt4b982642008-10-30 09:33:07 -070047struct _drm_intel_bo {
Eric Anholtd70d6052009-10-06 12:40:42 -070048 /**
49 * Size in bytes of the buffer object.
50 *
51 * The size may be larger than the size originally requested for the
52 * allocation, such as being aligned to page size.
53 */
54 unsigned long size;
Jesse Barnes276c07d2008-11-13 13:52:04 -080055
Eric Anholtd70d6052009-10-06 12:40:42 -070056 /**
57 * Alignment requirement for object
58 *
59 * Used for GTT mapping & pinning the object.
60 */
61 unsigned long align;
Eric Anholt738e36a2008-09-05 10:35:32 +010062
Eric Anholtd70d6052009-10-06 12:40:42 -070063 /**
Kenneth Graunkeedf17db2014-01-13 14:14:36 -080064 * Deprecated field containing (possibly the low 32-bits of) the last
65 * seen virtual card address. Use offset64 instead.
Eric Anholtd70d6052009-10-06 12:40:42 -070066 */
67 unsigned long offset;
Jesse Barnes731cd552008-12-17 10:09:49 -080068
Eric Anholtd70d6052009-10-06 12:40:42 -070069 /**
70 * Virtual address for accessing the buffer data. Only valid while
71 * mapped.
72 */
Eric Anholt23287f02010-08-26 15:39:28 -070073#ifdef __cplusplus
74 void *virt;
75#else
Eric Anholtd70d6052009-10-06 12:40:42 -070076 void *virtual;
Eric Anholt23287f02010-08-26 15:39:28 -070077#endif
Eric Anholtd70d6052009-10-06 12:40:42 -070078
79 /** Buffer manager context associated with this buffer object */
80 drm_intel_bufmgr *bufmgr;
81
82 /**
83 * MM-specific handle for accessing object
84 */
85 int handle;
Kenneth Graunkeedf17db2014-01-13 14:14:36 -080086
87 /**
88 * Last seen card virtual address (offset from the beginning of the
89 * aperture) for the object. This should be used to fill relocation
90 * entries when calling drm_intel_bo_emit_reloc()
91 */
92 uint64_t offset64;
Eric Anholtc4857422008-06-03 10:20:49 -070093};
94
Eric Anholt4db16a92011-10-11 15:59:03 -070095enum aub_dump_bmp_format {
96 AUB_DUMP_BMP_FORMAT_8BIT = 1,
97 AUB_DUMP_BMP_FORMAT_ARGB_4444 = 4,
98 AUB_DUMP_BMP_FORMAT_ARGB_0888 = 6,
99 AUB_DUMP_BMP_FORMAT_ARGB_8888 = 7,
100};
101
Paul Berryda02f722012-05-04 12:41:00 -0700102typedef struct _drm_intel_aub_annotation {
103 uint32_t type;
104 uint32_t subtype;
105 uint32_t ending_offset;
106} drm_intel_aub_annotation;
107
Jesse Barnes3a7dfcd2009-10-06 14:34:06 -0700108#define BO_ALLOC_FOR_RENDER (1<<0)
109
Eric Anholt4b982642008-10-30 09:33:07 -0700110drm_intel_bo *drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
111 unsigned long size, unsigned int alignment);
Eric Anholt72abe982009-02-18 13:06:35 -0800112drm_intel_bo *drm_intel_bo_alloc_for_render(drm_intel_bufmgr *bufmgr,
113 const char *name,
114 unsigned long size,
115 unsigned int alignment);
Tvrtko Ursulinae8edc72014-06-19 15:52:03 +0100116drm_intel_bo *drm_intel_bo_alloc_userptr(drm_intel_bufmgr *bufmgr,
117 const char *name,
118 void *addr, uint32_t tiling_mode,
119 uint32_t stride, unsigned long size,
120 unsigned long flags);
Jesse Barnes3a7dfcd2009-10-06 14:34:06 -0700121drm_intel_bo *drm_intel_bo_alloc_tiled(drm_intel_bufmgr *bufmgr,
122 const char *name,
123 int x, int y, int cpp,
124 uint32_t *tiling_mode,
125 unsigned long *pitch,
126 unsigned long flags);
Eric Anholt4b982642008-10-30 09:33:07 -0700127void drm_intel_bo_reference(drm_intel_bo *bo);
128void drm_intel_bo_unreference(drm_intel_bo *bo);
129int drm_intel_bo_map(drm_intel_bo *bo, int write_enable);
130int drm_intel_bo_unmap(drm_intel_bo *bo);
Eric Anholt738e36a2008-09-05 10:35:32 +0100131
Eric Anholt4b982642008-10-30 09:33:07 -0700132int drm_intel_bo_subdata(drm_intel_bo *bo, unsigned long offset,
Eric Anholtd70d6052009-10-06 12:40:42 -0700133 unsigned long size, const void *data);
Eric Anholt4b982642008-10-30 09:33:07 -0700134int drm_intel_bo_get_subdata(drm_intel_bo *bo, unsigned long offset,
Eric Anholtd70d6052009-10-06 12:40:42 -0700135 unsigned long size, void *data);
Eric Anholt4b982642008-10-30 09:33:07 -0700136void drm_intel_bo_wait_rendering(drm_intel_bo *bo);
Eric Anholt738e36a2008-09-05 10:35:32 +0100137
Eric Anholt4b982642008-10-30 09:33:07 -0700138void drm_intel_bufmgr_set_debug(drm_intel_bufmgr *bufmgr, int enable_debug);
139void drm_intel_bufmgr_destroy(drm_intel_bufmgr *bufmgr);
140int drm_intel_bo_exec(drm_intel_bo *bo, int used,
Chris Wilson1443bea2010-11-25 16:59:20 +0000141 struct drm_clip_rect *cliprects, int num_cliprects, int DR4);
Zou Nan hai66375fd2010-06-02 10:07:37 +0800142int drm_intel_bo_mrb_exec(drm_intel_bo *bo, int used,
Chris Wilson1443bea2010-11-25 16:59:20 +0000143 struct drm_clip_rect *cliprects, int num_cliprects, int DR4,
Chris Wilson0184bb12010-12-19 13:01:15 +0000144 unsigned int flags);
Eric Anholtd70d6052009-10-06 12:40:42 -0700145int drm_intel_bufmgr_check_aperture_space(drm_intel_bo ** bo_array, int count);
Eric Anholt738e36a2008-09-05 10:35:32 +0100146
Eric Anholt4b982642008-10-30 09:33:07 -0700147int drm_intel_bo_emit_reloc(drm_intel_bo *bo, uint32_t offset,
148 drm_intel_bo *target_bo, uint32_t target_offset,
149 uint32_t read_domains, uint32_t write_domain);
Jesse Barnesb5096402009-09-15 11:02:58 -0700150int drm_intel_bo_emit_reloc_fence(drm_intel_bo *bo, uint32_t offset,
151 drm_intel_bo *target_bo,
152 uint32_t target_offset,
153 uint32_t read_domains, uint32_t write_domain);
Eric Anholt4b982642008-10-30 09:33:07 -0700154int drm_intel_bo_pin(drm_intel_bo *bo, uint32_t alignment);
155int drm_intel_bo_unpin(drm_intel_bo *bo);
Eric Anholtd70d6052009-10-06 12:40:42 -0700156int drm_intel_bo_set_tiling(drm_intel_bo *bo, uint32_t * tiling_mode,
Eric Anholt4b982642008-10-30 09:33:07 -0700157 uint32_t stride);
Eric Anholtd70d6052009-10-06 12:40:42 -0700158int drm_intel_bo_get_tiling(drm_intel_bo *bo, uint32_t * tiling_mode,
159 uint32_t * swizzle_mode);
160int drm_intel_bo_flink(drm_intel_bo *bo, uint32_t * name);
Eric Anholt8214a652009-08-27 18:32:07 -0700161int drm_intel_bo_busy(drm_intel_bo *bo);
Chris Wilson83a35b62009-11-11 13:04:38 +0000162int drm_intel_bo_madvise(drm_intel_bo *bo, int madv);
Eric Anholt738e36a2008-09-05 10:35:32 +0100163
Keith Packard5b5ce302009-05-11 13:42:12 -0700164int drm_intel_bo_disable_reuse(drm_intel_bo *bo);
Chris Wilson07e75892010-05-11 08:54:06 +0100165int drm_intel_bo_is_reusable(drm_intel_bo *bo);
Eric Anholt769b1052009-10-01 19:09:26 -0700166int drm_intel_bo_references(drm_intel_bo *bo, drm_intel_bo *target_bo);
Keith Packard5b5ce302009-05-11 13:42:12 -0700167
Eric Anholt4b982642008-10-30 09:33:07 -0700168/* drm_intel_bufmgr_gem.c */
169drm_intel_bufmgr *drm_intel_bufmgr_gem_init(int fd, int batch_size);
170drm_intel_bo *drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr,
171 const char *name,
172 unsigned int handle);
173void drm_intel_bufmgr_gem_enable_reuse(drm_intel_bufmgr *bufmgr);
Jesse Barnesb5096402009-09-15 11:02:58 -0700174void drm_intel_bufmgr_gem_enable_fenced_relocs(drm_intel_bufmgr *bufmgr);
Chris Wilsone4b60f22011-12-05 21:29:05 +0000175void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr,
176 int limit);
Eric Anholt99c73372012-02-10 04:12:15 -0800177int drm_intel_gem_bo_map_unsynchronized(drm_intel_bo *bo);
Jesse Barnes276c07d2008-11-13 13:52:04 -0800178int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo);
Jesse Barnese2d7dfb2009-03-26 16:43:00 -0700179int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
Eric Anholt99c73372012-02-10 04:12:15 -0800180
Eric Anholt515cea62011-10-21 18:48:20 -0700181int drm_intel_gem_bo_get_reloc_count(drm_intel_bo *bo);
182void drm_intel_gem_bo_clear_relocs(drm_intel_bo *bo, int start);
Eric Anholt6fb1ad72008-11-13 11:44:22 -0800183void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
Eric Anholtc4857422008-06-03 10:20:49 -0700184
Damien Lespiaufbd106a2013-02-20 12:11:49 +0000185void
186drm_intel_bufmgr_gem_set_aub_filename(drm_intel_bufmgr *bufmgr,
187 const char *filename);
Eric Anholt4db16a92011-10-11 15:59:03 -0700188void drm_intel_bufmgr_gem_set_aub_dump(drm_intel_bufmgr *bufmgr, int enable);
189void drm_intel_gem_bo_aub_dump_bmp(drm_intel_bo *bo,
190 int x1, int y1, int width, int height,
191 enum aub_dump_bmp_format format,
192 int pitch, int offset);
Paul Berryda02f722012-05-04 12:41:00 -0700193void
194drm_intel_bufmgr_gem_set_aub_annotations(drm_intel_bo *bo,
195 drm_intel_aub_annotation *annotations,
196 unsigned count);
Eric Anholt4db16a92011-10-11 15:59:03 -0700197
Carl Worthafd245d2009-04-29 14:43:55 -0700198int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);
199
Chris Wilson9d776032011-06-04 12:47:19 +0100200int drm_intel_get_aperture_sizes(int fd, size_t *mappable, size_t *total);
Kenneth Graunke6e642db2011-10-11 14:38:34 -0700201int drm_intel_bufmgr_gem_get_devid(drm_intel_bufmgr *bufmgr);
Ben Widawsky971c0802012-06-05 11:30:48 -0700202int drm_intel_gem_bo_wait(drm_intel_bo *bo, int64_t timeout_ns);
Chris Wilson9d776032011-06-04 12:47:19 +0100203
Ben Widawsky3ed38712012-03-18 18:28:28 -0700204drm_intel_context *drm_intel_gem_context_create(drm_intel_bufmgr *bufmgr);
205void drm_intel_gem_context_destroy(drm_intel_context *ctx);
206int drm_intel_gem_bo_context_exec(drm_intel_bo *bo, drm_intel_context *ctx,
207 int used, unsigned int flags);
208
Dave Airlieff65de92012-07-15 00:22:46 +0000209int drm_intel_bo_gem_export_to_prime(drm_intel_bo *bo, int *prime_fd);
210drm_intel_bo *drm_intel_bo_gem_create_from_prime(drm_intel_bufmgr *bufmgr,
211 int prime_fd, int size);
212
Eric Anholt4b982642008-10-30 09:33:07 -0700213/* drm_intel_bufmgr_fake.c */
214drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd,
215 unsigned long low_offset,
216 void *low_virtual,
217 unsigned long size,
Eric Anholtd70d6052009-10-06 12:40:42 -0700218 volatile unsigned int
219 *last_dispatch);
Eric Anholt4b982642008-10-30 09:33:07 -0700220void drm_intel_bufmgr_fake_set_last_dispatch(drm_intel_bufmgr *bufmgr,
Eric Anholtd70d6052009-10-06 12:40:42 -0700221 volatile unsigned int
222 *last_dispatch);
Eric Anholt4b982642008-10-30 09:33:07 -0700223void drm_intel_bufmgr_fake_set_exec_callback(drm_intel_bufmgr *bufmgr,
Eric Anholtd70d6052009-10-06 12:40:42 -0700224 int (*exec) (drm_intel_bo *bo,
225 unsigned int used,
226 void *priv),
Eric Anholt4b982642008-10-30 09:33:07 -0700227 void *priv);
228void drm_intel_bufmgr_fake_set_fence_callback(drm_intel_bufmgr *bufmgr,
Eric Anholtd70d6052009-10-06 12:40:42 -0700229 unsigned int (*emit) (void *priv),
230 void (*wait) (unsigned int fence,
231 void *priv),
Eric Anholt4b982642008-10-30 09:33:07 -0700232 void *priv);
233drm_intel_bo *drm_intel_bo_fake_alloc_static(drm_intel_bufmgr *bufmgr,
234 const char *name,
Eric Anholtd70d6052009-10-06 12:40:42 -0700235 unsigned long offset,
Eric Anholt23287f02010-08-26 15:39:28 -0700236 unsigned long size, void *virt);
Eric Anholt4b982642008-10-30 09:33:07 -0700237void drm_intel_bo_fake_disable_backing_store(drm_intel_bo *bo,
Eric Anholtd70d6052009-10-06 12:40:42 -0700238 void (*invalidate_cb) (drm_intel_bo
239 * bo,
240 void *ptr),
Eric Anholt4b982642008-10-30 09:33:07 -0700241 void *ptr);
Eric Anholt738e36a2008-09-05 10:35:32 +0100242
Eric Anholt4b982642008-10-30 09:33:07 -0700243void drm_intel_bufmgr_fake_contended_lock_take(drm_intel_bufmgr *bufmgr);
244void drm_intel_bufmgr_fake_evict_all(drm_intel_bufmgr *bufmgr);
245
Eric Anholt71066ab2011-12-20 13:06:16 -0800246struct drm_intel_decode *drm_intel_decode_context_alloc(uint32_t devid);
247void drm_intel_decode_context_free(struct drm_intel_decode *ctx);
248void drm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx,
249 void *data, uint32_t hw_offset,
250 int count);
251void drm_intel_decode_set_dump_past_end(struct drm_intel_decode *ctx,
252 int dump_past_end);
253void drm_intel_decode_set_head_tail(struct drm_intel_decode *ctx,
254 uint32_t head, uint32_t tail);
Eric Anholtea33a232012-01-03 13:05:57 -0800255void drm_intel_decode_set_output_file(struct drm_intel_decode *ctx, FILE *out);
Eric Anholt71066ab2011-12-20 13:06:16 -0800256void drm_intel_decode(struct drm_intel_decode *ctx);
257
Eric Anholt2607dad2012-08-01 16:43:16 -0700258int drm_intel_reg_read(drm_intel_bufmgr *bufmgr,
259 uint32_t offset,
260 uint64_t *result);
Eric Anholt71066ab2011-12-20 13:06:16 -0800261
Ian Romanick5a41b022013-11-15 10:24:43 -0800262int drm_intel_get_reset_stats(drm_intel_context *ctx,
263 uint32_t *reset_count,
264 uint32_t *active,
265 uint32_t *pending);
266
Eric Anholt4b982642008-10-30 09:33:07 -0700267/** @{ Compatibility defines to keep old code building despite the symbol rename
268 * from dri_* to drm_intel_*
269 */
270#define dri_bo drm_intel_bo
271#define dri_bufmgr drm_intel_bufmgr
272#define dri_bo_alloc drm_intel_bo_alloc
273#define dri_bo_reference drm_intel_bo_reference
274#define dri_bo_unreference drm_intel_bo_unreference
275#define dri_bo_map drm_intel_bo_map
276#define dri_bo_unmap drm_intel_bo_unmap
277#define dri_bo_subdata drm_intel_bo_subdata
278#define dri_bo_get_subdata drm_intel_bo_get_subdata
279#define dri_bo_wait_rendering drm_intel_bo_wait_rendering
280#define dri_bufmgr_set_debug drm_intel_bufmgr_set_debug
281#define dri_bufmgr_destroy drm_intel_bufmgr_destroy
282#define dri_bo_exec drm_intel_bo_exec
283#define dri_bufmgr_check_aperture_space drm_intel_bufmgr_check_aperture_space
284#define dri_bo_emit_reloc(reloc_bo, read, write, target_offset, \
285 reloc_offset, target_bo) \
286 drm_intel_bo_emit_reloc(reloc_bo, reloc_offset, \
Eric Anholtd70d6052009-10-06 12:40:42 -0700287 target_bo, target_offset, \
288 read, write);
Eric Anholt4b982642008-10-30 09:33:07 -0700289#define dri_bo_pin drm_intel_bo_pin
290#define dri_bo_unpin drm_intel_bo_unpin
291#define dri_bo_get_tiling drm_intel_bo_get_tiling
292#define dri_bo_set_tiling(bo, mode) drm_intel_bo_set_tiling(bo, mode, 0)
293#define dri_bo_flink drm_intel_bo_flink
294#define intel_bufmgr_gem_init drm_intel_bufmgr_gem_init
295#define intel_bo_gem_create_from_name drm_intel_bo_gem_create_from_name
296#define intel_bufmgr_gem_enable_reuse drm_intel_bufmgr_gem_enable_reuse
297#define intel_bufmgr_fake_init drm_intel_bufmgr_fake_init
298#define intel_bufmgr_fake_set_last_dispatch drm_intel_bufmgr_fake_set_last_dispatch
299#define intel_bufmgr_fake_set_exec_callback drm_intel_bufmgr_fake_set_exec_callback
300#define intel_bufmgr_fake_set_fence_callback drm_intel_bufmgr_fake_set_fence_callback
301#define intel_bo_fake_alloc_static drm_intel_bo_fake_alloc_static
302#define intel_bo_fake_disable_backing_store drm_intel_bo_fake_disable_backing_store
303#define intel_bufmgr_fake_contended_lock_take drm_intel_bufmgr_fake_contended_lock_take
304#define intel_bufmgr_fake_evict_all drm_intel_bufmgr_fake_evict_all
305
306/** @{ */
Eric Anholtc4857422008-06-03 10:20:49 -0700307
Eric Anholt738e36a2008-09-05 10:35:32 +0100308#endif /* INTEL_BUFMGR_H */