2cc636c714939ed7e1f953dd74ab7c30790165f2
[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 <stdio.h>
38 #include <stdint.h>
39 #include <stdio.h>
40
41 #if defined(__cplusplus)
42 extern "C" {
43 #endif
44
45 struct drm_clip_rect;
46
47 typedef struct _drm_bacon_bufmgr drm_bacon_bufmgr;
48 typedef struct _drm_bacon_context drm_bacon_context;
49 typedef struct _drm_bacon_bo drm_bacon_bo;
50
51 struct _drm_bacon_bo {
52 /**
53 * Size in bytes of the buffer object.
54 *
55 * The size may be larger than the size originally requested for the
56 * allocation, such as being aligned to page size.
57 */
58 unsigned long size;
59
60 /**
61 * Alignment requirement for object
62 *
63 * Used for GTT mapping & pinning the object.
64 */
65 unsigned long align;
66
67 /**
68 * Deprecated field containing (possibly the low 32-bits of) the last
69 * seen virtual card address. Use offset64 instead.
70 */
71 unsigned long offset;
72
73 /**
74 * Virtual address for accessing the buffer data. Only valid while
75 * mapped.
76 */
77 #ifdef __cplusplus
78 void *virt;
79 #else
80 void *virtual;
81 #endif
82
83 /** Buffer manager context associated with this buffer object */
84 drm_bacon_bufmgr *bufmgr;
85
86 /**
87 * MM-specific handle for accessing object
88 */
89 int handle;
90
91 /**
92 * Last seen card virtual address (offset from the beginning of the
93 * aperture) for the object. This should be used to fill relocation
94 * entries when calling drm_bacon_bo_emit_reloc()
95 */
96 uint64_t offset64;
97 };
98
99 #define BO_ALLOC_FOR_RENDER (1<<0)
100
101 drm_bacon_bo *drm_bacon_bo_alloc(drm_bacon_bufmgr *bufmgr, const char *name,
102 unsigned long size, unsigned int alignment);
103 drm_bacon_bo *drm_bacon_bo_alloc_for_render(drm_bacon_bufmgr *bufmgr,
104 const char *name,
105 unsigned long size,
106 unsigned int alignment);
107 drm_bacon_bo *drm_bacon_bo_alloc_userptr(drm_bacon_bufmgr *bufmgr,
108 const char *name,
109 void *addr, uint32_t tiling_mode,
110 uint32_t stride, unsigned long size,
111 unsigned long flags);
112 drm_bacon_bo *drm_bacon_bo_alloc_tiled(drm_bacon_bufmgr *bufmgr,
113 const char *name,
114 int x, int y, int cpp,
115 uint32_t *tiling_mode,
116 unsigned long *pitch,
117 unsigned long flags);
118 void drm_bacon_bo_reference(drm_bacon_bo *bo);
119 void drm_bacon_bo_unreference(drm_bacon_bo *bo);
120 int drm_bacon_bo_map(drm_bacon_bo *bo, int write_enable);
121 int drm_bacon_bo_unmap(drm_bacon_bo *bo);
122
123 int drm_bacon_bo_subdata(drm_bacon_bo *bo, unsigned long offset,
124 unsigned long size, const void *data);
125 int drm_bacon_bo_get_subdata(drm_bacon_bo *bo, unsigned long offset,
126 unsigned long size, void *data);
127 void drm_bacon_bo_wait_rendering(drm_bacon_bo *bo);
128
129 void drm_bacon_bufmgr_destroy(drm_bacon_bufmgr *bufmgr);
130 int drm_bacon_bo_exec(drm_bacon_bo *bo, int used,
131 struct drm_clip_rect *cliprects, int num_cliprects, int DR4);
132 int drm_bacon_bo_mrb_exec(drm_bacon_bo *bo, int used,
133 struct drm_clip_rect *cliprects, int num_cliprects, int DR4,
134 unsigned int flags);
135 int drm_bacon_bufmgr_check_aperture_space(drm_bacon_bo ** bo_array, int count);
136
137 int drm_bacon_bo_emit_reloc(drm_bacon_bo *bo, uint32_t offset,
138 drm_bacon_bo *target_bo, uint32_t target_offset,
139 uint32_t read_domains, uint32_t write_domain);
140 int drm_bacon_bo_set_tiling(drm_bacon_bo *bo, uint32_t * tiling_mode,
141 uint32_t stride);
142 int drm_bacon_bo_get_tiling(drm_bacon_bo *bo, uint32_t * tiling_mode,
143 uint32_t * swizzle_mode);
144 int drm_bacon_bo_flink(drm_bacon_bo *bo, uint32_t * name);
145 int drm_bacon_bo_busy(drm_bacon_bo *bo);
146 int drm_bacon_bo_madvise(drm_bacon_bo *bo, int madv);
147 int drm_bacon_bo_set_softpin_offset(drm_bacon_bo *bo, uint64_t offset);
148
149 int drm_bacon_bo_disable_reuse(drm_bacon_bo *bo);
150 int drm_bacon_bo_is_reusable(drm_bacon_bo *bo);
151 int drm_bacon_bo_references(drm_bacon_bo *bo, drm_bacon_bo *target_bo);
152
153 /* drm_bacon_bufmgr_gem.c */
154 drm_bacon_bufmgr *drm_bacon_bufmgr_gem_init(int fd, int batch_size);
155 drm_bacon_bo *drm_bacon_bo_gem_create_from_name(drm_bacon_bufmgr *bufmgr,
156 const char *name,
157 unsigned int handle);
158 void drm_bacon_bufmgr_gem_enable_reuse(drm_bacon_bufmgr *bufmgr);
159 void drm_bacon_bufmgr_gem_set_vma_cache_size(drm_bacon_bufmgr *bufmgr,
160 int limit);
161 int drm_bacon_gem_bo_map_unsynchronized(drm_bacon_bo *bo);
162 int drm_bacon_gem_bo_map_gtt(drm_bacon_bo *bo);
163
164 #define HAVE_DRM_INTEL_GEM_BO_DISABLE_IMPLICIT_SYNC 1
165 int drm_bacon_bufmgr_gem_can_disable_implicit_sync(drm_bacon_bufmgr *bufmgr);
166 void drm_bacon_gem_bo_disable_implicit_sync(drm_bacon_bo *bo);
167 void drm_bacon_gem_bo_enable_implicit_sync(drm_bacon_bo *bo);
168
169 void *drm_bacon_gem_bo_map__cpu(drm_bacon_bo *bo);
170 void *drm_bacon_gem_bo_map__gtt(drm_bacon_bo *bo);
171 void *drm_bacon_gem_bo_map__wc(drm_bacon_bo *bo);
172
173 int drm_bacon_gem_bo_get_reloc_count(drm_bacon_bo *bo);
174 void drm_bacon_gem_bo_clear_relocs(drm_bacon_bo *bo, int start);
175 void drm_bacon_gem_bo_start_gtt_access(drm_bacon_bo *bo, int write_enable);
176
177 int drm_bacon_bufmgr_gem_get_devid(drm_bacon_bufmgr *bufmgr);
178 int drm_bacon_gem_bo_wait(drm_bacon_bo *bo, int64_t timeout_ns);
179
180 drm_bacon_context *drm_bacon_gem_context_create(drm_bacon_bufmgr *bufmgr);
181 int drm_bacon_gem_context_get_id(drm_bacon_context *ctx,
182 uint32_t *ctx_id);
183 void drm_bacon_gem_context_destroy(drm_bacon_context *ctx);
184 int drm_bacon_gem_bo_context_exec(drm_bacon_bo *bo, drm_bacon_context *ctx,
185 int used, unsigned int flags);
186 int drm_bacon_gem_bo_fence_exec(drm_bacon_bo *bo,
187 drm_bacon_context *ctx,
188 int used,
189 int in_fence,
190 int *out_fence,
191 unsigned int flags);
192
193 int drm_bacon_bo_gem_export_to_prime(drm_bacon_bo *bo, int *prime_fd);
194 drm_bacon_bo *drm_bacon_bo_gem_create_from_prime(drm_bacon_bufmgr *bufmgr,
195 int prime_fd, int size);
196
197 int drm_bacon_reg_read(drm_bacon_bufmgr *bufmgr,
198 uint32_t offset,
199 uint64_t *result);
200
201 int drm_bacon_get_reset_stats(drm_bacon_context *ctx,
202 uint32_t *reset_count,
203 uint32_t *active,
204 uint32_t *pending);
205
206 /** @{ */
207
208 #if defined(__cplusplus)
209 }
210 #endif
211
212 #endif /* INTEL_BUFMGR_H */