blob: 8036031c7ba0c42e5a9a5d40b7cfd3ff5ac55c04 [file] [log] [blame]
Eric Anholtc4857422008-06-03 10:20:49 -07001/*
2 * Copyright © 2008 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 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 Anholtc4857422008-06-03 10:20:49 -070039
Chris Wilson1443bea2010-11-25 16:59:20 +000040struct drm_clip_rect;
41
Eric Anholt4b982642008-10-30 09:33:07 -070042typedef struct _drm_intel_bufmgr drm_intel_bufmgr;
43typedef struct _drm_intel_bo drm_intel_bo;
Eric Anholt738e36a2008-09-05 10:35:32 +010044
Eric Anholt4b982642008-10-30 09:33:07 -070045struct _drm_intel_bo {
Eric Anholtd70d6052009-10-06 12:40:42 -070046 /**
47 * Size in bytes of the buffer object.
48 *
49 * The size may be larger than the size originally requested for the
50 * allocation, such as being aligned to page size.
51 */
52 unsigned long size;
Jesse Barnes276c07d2008-11-13 13:52:04 -080053
Eric Anholtd70d6052009-10-06 12:40:42 -070054 /**
55 * Alignment requirement for object
56 *
57 * Used for GTT mapping & pinning the object.
58 */
59 unsigned long align;
Eric Anholt738e36a2008-09-05 10:35:32 +010060
Eric Anholtd70d6052009-10-06 12:40:42 -070061 /**
Eric Anholt02c775f2009-10-06 15:25:21 -070062 * Last seen card virtual address (offset from the beginning of the
63 * aperture) for the object. This should be used to fill relocation
64 * entries when calling drm_intel_bo_emit_reloc()
Eric Anholtd70d6052009-10-06 12:40:42 -070065 */
66 unsigned long offset;
Jesse Barnes731cd552008-12-17 10:09:49 -080067
Eric Anholtd70d6052009-10-06 12:40:42 -070068 /**
69 * Virtual address for accessing the buffer data. Only valid while
70 * mapped.
71 */
Eric Anholt23287f02010-08-26 15:39:28 -070072#ifdef __cplusplus
73 void *virt;
74#else
Eric Anholtd70d6052009-10-06 12:40:42 -070075 void *virtual;
Eric Anholt23287f02010-08-26 15:39:28 -070076#endif
Eric Anholtd70d6052009-10-06 12:40:42 -070077
78 /** Buffer manager context associated with this buffer object */
79 drm_intel_bufmgr *bufmgr;
80
81 /**
82 * MM-specific handle for accessing object
83 */
84 int handle;
Eric Anholtc4857422008-06-03 10:20:49 -070085};
86
Jesse Barnes3a7dfcd2009-10-06 14:34:06 -070087#define BO_ALLOC_FOR_RENDER (1<<0)
88
Eric Anholt4b982642008-10-30 09:33:07 -070089drm_intel_bo *drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
90 unsigned long size, unsigned int alignment);
Eric Anholt72abe982009-02-18 13:06:35 -080091drm_intel_bo *drm_intel_bo_alloc_for_render(drm_intel_bufmgr *bufmgr,
92 const char *name,
93 unsigned long size,
94 unsigned int alignment);
Jesse Barnes3a7dfcd2009-10-06 14:34:06 -070095drm_intel_bo *drm_intel_bo_alloc_tiled(drm_intel_bufmgr *bufmgr,
96 const char *name,
97 int x, int y, int cpp,
98 uint32_t *tiling_mode,
99 unsigned long *pitch,
100 unsigned long flags);
Eric Anholt4b982642008-10-30 09:33:07 -0700101void drm_intel_bo_reference(drm_intel_bo *bo);
102void drm_intel_bo_unreference(drm_intel_bo *bo);
103int drm_intel_bo_map(drm_intel_bo *bo, int write_enable);
104int drm_intel_bo_unmap(drm_intel_bo *bo);
Eric Anholt738e36a2008-09-05 10:35:32 +0100105
Eric Anholt4b982642008-10-30 09:33:07 -0700106int drm_intel_bo_subdata(drm_intel_bo *bo, unsigned long offset,
Eric Anholtd70d6052009-10-06 12:40:42 -0700107 unsigned long size, const void *data);
Eric Anholt4b982642008-10-30 09:33:07 -0700108int drm_intel_bo_get_subdata(drm_intel_bo *bo, unsigned long offset,
Eric Anholtd70d6052009-10-06 12:40:42 -0700109 unsigned long size, void *data);
Eric Anholt4b982642008-10-30 09:33:07 -0700110void drm_intel_bo_wait_rendering(drm_intel_bo *bo);
Eric Anholt738e36a2008-09-05 10:35:32 +0100111
Eric Anholt4b982642008-10-30 09:33:07 -0700112void drm_intel_bufmgr_set_debug(drm_intel_bufmgr *bufmgr, int enable_debug);
113void drm_intel_bufmgr_destroy(drm_intel_bufmgr *bufmgr);
114int drm_intel_bo_exec(drm_intel_bo *bo, int used,
Chris Wilson1443bea2010-11-25 16:59:20 +0000115 struct drm_clip_rect *cliprects, int num_cliprects, int DR4);
Zou Nan hai66375fd2010-06-02 10:07:37 +0800116int drm_intel_bo_mrb_exec(drm_intel_bo *bo, int used,
Chris Wilson1443bea2010-11-25 16:59:20 +0000117 struct drm_clip_rect *cliprects, int num_cliprects, int DR4,
Chris Wilson0184bb12010-12-19 13:01:15 +0000118 unsigned int flags);
Eric Anholtd70d6052009-10-06 12:40:42 -0700119int drm_intel_bufmgr_check_aperture_space(drm_intel_bo ** bo_array, int count);
Eric Anholt738e36a2008-09-05 10:35:32 +0100120
Eric Anholt4b982642008-10-30 09:33:07 -0700121int drm_intel_bo_emit_reloc(drm_intel_bo *bo, uint32_t offset,
122 drm_intel_bo *target_bo, uint32_t target_offset,
123 uint32_t read_domains, uint32_t write_domain);
Jesse Barnesb5096402009-09-15 11:02:58 -0700124int drm_intel_bo_emit_reloc_fence(drm_intel_bo *bo, uint32_t offset,
125 drm_intel_bo *target_bo,
126 uint32_t target_offset,
127 uint32_t read_domains, uint32_t write_domain);
Eric Anholt4b982642008-10-30 09:33:07 -0700128int drm_intel_bo_pin(drm_intel_bo *bo, uint32_t alignment);
129int drm_intel_bo_unpin(drm_intel_bo *bo);
Eric Anholtd70d6052009-10-06 12:40:42 -0700130int drm_intel_bo_set_tiling(drm_intel_bo *bo, uint32_t * tiling_mode,
Eric Anholt4b982642008-10-30 09:33:07 -0700131 uint32_t stride);
Eric Anholtd70d6052009-10-06 12:40:42 -0700132int drm_intel_bo_get_tiling(drm_intel_bo *bo, uint32_t * tiling_mode,
133 uint32_t * swizzle_mode);
134int drm_intel_bo_flink(drm_intel_bo *bo, uint32_t * name);
Eric Anholt8214a652009-08-27 18:32:07 -0700135int drm_intel_bo_busy(drm_intel_bo *bo);
Chris Wilson83a35b62009-11-11 13:04:38 +0000136int drm_intel_bo_madvise(drm_intel_bo *bo, int madv);
Eric Anholt738e36a2008-09-05 10:35:32 +0100137
Keith Packard5b5ce302009-05-11 13:42:12 -0700138int drm_intel_bo_disable_reuse(drm_intel_bo *bo);
Chris Wilson07e75892010-05-11 08:54:06 +0100139int drm_intel_bo_is_reusable(drm_intel_bo *bo);
Eric Anholt769b1052009-10-01 19:09:26 -0700140int drm_intel_bo_references(drm_intel_bo *bo, drm_intel_bo *target_bo);
Keith Packard5b5ce302009-05-11 13:42:12 -0700141
Eric Anholt4b982642008-10-30 09:33:07 -0700142/* drm_intel_bufmgr_gem.c */
143drm_intel_bufmgr *drm_intel_bufmgr_gem_init(int fd, int batch_size);
144drm_intel_bo *drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr,
145 const char *name,
146 unsigned int handle);
147void drm_intel_bufmgr_gem_enable_reuse(drm_intel_bufmgr *bufmgr);
Jesse Barnesb5096402009-09-15 11:02:58 -0700148void drm_intel_bufmgr_gem_enable_fenced_relocs(drm_intel_bufmgr *bufmgr);
Chris Wilsone4b60f22011-12-05 21:29:05 +0000149void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr,
150 int limit);
Jesse Barnes276c07d2008-11-13 13:52:04 -0800151int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo);
Jesse Barnese2d7dfb2009-03-26 16:43:00 -0700152int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
Eric Anholt515cea62011-10-21 18:48:20 -0700153int drm_intel_gem_bo_get_reloc_count(drm_intel_bo *bo);
154void drm_intel_gem_bo_clear_relocs(drm_intel_bo *bo, int start);
Eric Anholt6fb1ad72008-11-13 11:44:22 -0800155void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
Eric Anholtc4857422008-06-03 10:20:49 -0700156
Carl Worthafd245d2009-04-29 14:43:55 -0700157int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);
158
Chris Wilson9d776032011-06-04 12:47:19 +0100159int drm_intel_get_aperture_sizes(int fd, size_t *mappable, size_t *total);
Kenneth Graunke6e642db2011-10-11 14:38:34 -0700160int drm_intel_bufmgr_gem_get_devid(drm_intel_bufmgr *bufmgr);
Chris Wilson9d776032011-06-04 12:47:19 +0100161
Eric Anholt4b982642008-10-30 09:33:07 -0700162/* drm_intel_bufmgr_fake.c */
163drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd,
164 unsigned long low_offset,
165 void *low_virtual,
166 unsigned long size,
Eric Anholtd70d6052009-10-06 12:40:42 -0700167 volatile unsigned int
168 *last_dispatch);
Eric Anholt4b982642008-10-30 09:33:07 -0700169void drm_intel_bufmgr_fake_set_last_dispatch(drm_intel_bufmgr *bufmgr,
Eric Anholtd70d6052009-10-06 12:40:42 -0700170 volatile unsigned int
171 *last_dispatch);
Eric Anholt4b982642008-10-30 09:33:07 -0700172void drm_intel_bufmgr_fake_set_exec_callback(drm_intel_bufmgr *bufmgr,
Eric Anholtd70d6052009-10-06 12:40:42 -0700173 int (*exec) (drm_intel_bo *bo,
174 unsigned int used,
175 void *priv),
Eric Anholt4b982642008-10-30 09:33:07 -0700176 void *priv);
177void drm_intel_bufmgr_fake_set_fence_callback(drm_intel_bufmgr *bufmgr,
Eric Anholtd70d6052009-10-06 12:40:42 -0700178 unsigned int (*emit) (void *priv),
179 void (*wait) (unsigned int fence,
180 void *priv),
Eric Anholt4b982642008-10-30 09:33:07 -0700181 void *priv);
182drm_intel_bo *drm_intel_bo_fake_alloc_static(drm_intel_bufmgr *bufmgr,
183 const char *name,
Eric Anholtd70d6052009-10-06 12:40:42 -0700184 unsigned long offset,
Eric Anholt23287f02010-08-26 15:39:28 -0700185 unsigned long size, void *virt);
Eric Anholt4b982642008-10-30 09:33:07 -0700186void drm_intel_bo_fake_disable_backing_store(drm_intel_bo *bo,
Eric Anholtd70d6052009-10-06 12:40:42 -0700187 void (*invalidate_cb) (drm_intel_bo
188 * bo,
189 void *ptr),
Eric Anholt4b982642008-10-30 09:33:07 -0700190 void *ptr);
Eric Anholt738e36a2008-09-05 10:35:32 +0100191
Eric Anholt4b982642008-10-30 09:33:07 -0700192void drm_intel_bufmgr_fake_contended_lock_take(drm_intel_bufmgr *bufmgr);
193void drm_intel_bufmgr_fake_evict_all(drm_intel_bufmgr *bufmgr);
194
Eric Anholt71066ab2011-12-20 13:06:16 -0800195struct drm_intel_decode *drm_intel_decode_context_alloc(uint32_t devid);
196void drm_intel_decode_context_free(struct drm_intel_decode *ctx);
197void drm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx,
198 void *data, uint32_t hw_offset,
199 int count);
200void drm_intel_decode_set_dump_past_end(struct drm_intel_decode *ctx,
201 int dump_past_end);
202void drm_intel_decode_set_head_tail(struct drm_intel_decode *ctx,
203 uint32_t head, uint32_t tail);
Eric Anholtea33a232012-01-03 13:05:57 -0800204void drm_intel_decode_set_output_file(struct drm_intel_decode *ctx, FILE *out);
Eric Anholt71066ab2011-12-20 13:06:16 -0800205void drm_intel_decode(struct drm_intel_decode *ctx);
206
207
Eric Anholt4b982642008-10-30 09:33:07 -0700208/** @{ Compatibility defines to keep old code building despite the symbol rename
209 * from dri_* to drm_intel_*
210 */
211#define dri_bo drm_intel_bo
212#define dri_bufmgr drm_intel_bufmgr
213#define dri_bo_alloc drm_intel_bo_alloc
214#define dri_bo_reference drm_intel_bo_reference
215#define dri_bo_unreference drm_intel_bo_unreference
216#define dri_bo_map drm_intel_bo_map
217#define dri_bo_unmap drm_intel_bo_unmap
218#define dri_bo_subdata drm_intel_bo_subdata
219#define dri_bo_get_subdata drm_intel_bo_get_subdata
220#define dri_bo_wait_rendering drm_intel_bo_wait_rendering
221#define dri_bufmgr_set_debug drm_intel_bufmgr_set_debug
222#define dri_bufmgr_destroy drm_intel_bufmgr_destroy
223#define dri_bo_exec drm_intel_bo_exec
224#define dri_bufmgr_check_aperture_space drm_intel_bufmgr_check_aperture_space
225#define dri_bo_emit_reloc(reloc_bo, read, write, target_offset, \
226 reloc_offset, target_bo) \
227 drm_intel_bo_emit_reloc(reloc_bo, reloc_offset, \
Eric Anholtd70d6052009-10-06 12:40:42 -0700228 target_bo, target_offset, \
229 read, write);
Eric Anholt4b982642008-10-30 09:33:07 -0700230#define dri_bo_pin drm_intel_bo_pin
231#define dri_bo_unpin drm_intel_bo_unpin
232#define dri_bo_get_tiling drm_intel_bo_get_tiling
233#define dri_bo_set_tiling(bo, mode) drm_intel_bo_set_tiling(bo, mode, 0)
234#define dri_bo_flink drm_intel_bo_flink
235#define intel_bufmgr_gem_init drm_intel_bufmgr_gem_init
236#define intel_bo_gem_create_from_name drm_intel_bo_gem_create_from_name
237#define intel_bufmgr_gem_enable_reuse drm_intel_bufmgr_gem_enable_reuse
238#define intel_bufmgr_fake_init drm_intel_bufmgr_fake_init
239#define intel_bufmgr_fake_set_last_dispatch drm_intel_bufmgr_fake_set_last_dispatch
240#define intel_bufmgr_fake_set_exec_callback drm_intel_bufmgr_fake_set_exec_callback
241#define intel_bufmgr_fake_set_fence_callback drm_intel_bufmgr_fake_set_fence_callback
242#define intel_bo_fake_alloc_static drm_intel_bo_fake_alloc_static
243#define intel_bo_fake_disable_backing_store drm_intel_bo_fake_disable_backing_store
244#define intel_bufmgr_fake_contended_lock_take drm_intel_bufmgr_fake_contended_lock_take
245#define intel_bufmgr_fake_evict_all drm_intel_bufmgr_fake_evict_all
246
247/** @{ */
Eric Anholtc4857422008-06-03 10:20:49 -0700248
Eric Anholt738e36a2008-09-05 10:35:32 +0100249#endif /* INTEL_BUFMGR_H */