2 * Copyright © 2008 Intel Corporation
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:
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
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
24 * Eric Anholt <eric@anholt.net>
29 * @file intel_bufmgr.h
31 * Public definitions of Intel-specific bufmgr functions.
34 #ifndef INTEL_BUFMGR_H
35 #define INTEL_BUFMGR_H
41 typedef struct _drm_intel_bufmgr drm_intel_bufmgr;
42 typedef struct _drm_intel_bo drm_intel_bo;
44 struct _drm_intel_bo {
46 * Size in bytes of the buffer object.
48 * The size may be larger than the size originally requested for the
49 * allocation, such as being aligned to page size.
54 * Alignment requirement for object
56 * Used for GTT mapping & pinning the object.
61 * Last seen card virtual address (offset from the beginning of the
62 * aperture) for the object. This should be used to fill relocation
63 * entries when calling drm_intel_bo_emit_reloc()
68 * Virtual address for accessing the buffer data. Only valid while
77 /** Buffer manager context associated with this buffer object */
78 drm_intel_bufmgr *bufmgr;
81 * MM-specific handle for accessing object
86 #define BO_ALLOC_FOR_RENDER (1<<0)
88 drm_intel_bo *drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
89 unsigned long size, unsigned int alignment);
90 drm_intel_bo *drm_intel_bo_alloc_for_render(drm_intel_bufmgr *bufmgr,
93 unsigned int alignment);
94 drm_intel_bo *drm_intel_bo_alloc_tiled(drm_intel_bufmgr *bufmgr,
96 int x, int y, int cpp,
97 uint32_t *tiling_mode,
100 void drm_intel_bo_reference(drm_intel_bo *bo);
101 void drm_intel_bo_unreference(drm_intel_bo *bo);
102 int drm_intel_bo_map(drm_intel_bo *bo, int write_enable);
103 int drm_intel_bo_unmap(drm_intel_bo *bo);
105 int drm_intel_bo_subdata(drm_intel_bo *bo, unsigned long offset,
106 unsigned long size, const void *data);
107 int drm_intel_bo_get_subdata(drm_intel_bo *bo, unsigned long offset,
108 unsigned long size, void *data);
109 void drm_intel_bo_wait_rendering(drm_intel_bo *bo);
111 void drm_intel_bufmgr_set_debug(drm_intel_bufmgr *bufmgr, int enable_debug);
112 void drm_intel_bufmgr_destroy(drm_intel_bufmgr *bufmgr);
113 int drm_intel_bo_exec(drm_intel_bo *bo, int used,
114 struct drm_clip_rect *cliprects, int num_cliprects, int DR4);
115 int drm_intel_bo_mrb_exec(drm_intel_bo *bo, int used,
116 struct drm_clip_rect *cliprects, int num_cliprects, int DR4,
118 int drm_intel_bufmgr_check_aperture_space(drm_intel_bo ** bo_array, int count);
120 int drm_intel_bo_emit_reloc(drm_intel_bo *bo, uint32_t offset,
121 drm_intel_bo *target_bo, uint32_t target_offset,
122 uint32_t read_domains, uint32_t write_domain);
123 int drm_intel_bo_emit_reloc_fence(drm_intel_bo *bo, uint32_t offset,
124 drm_intel_bo *target_bo,
125 uint32_t target_offset,
126 uint32_t read_domains, uint32_t write_domain);
127 int drm_intel_bo_pin(drm_intel_bo *bo, uint32_t alignment);
128 int drm_intel_bo_unpin(drm_intel_bo *bo);
129 int drm_intel_bo_set_tiling(drm_intel_bo *bo, uint32_t * tiling_mode,
131 int drm_intel_bo_get_tiling(drm_intel_bo *bo, uint32_t * tiling_mode,
132 uint32_t * swizzle_mode);
133 int drm_intel_bo_flink(drm_intel_bo *bo, uint32_t * name);
134 int drm_intel_bo_busy(drm_intel_bo *bo);
135 int drm_intel_bo_madvise(drm_intel_bo *bo, int madv);
137 int drm_intel_bo_disable_reuse(drm_intel_bo *bo);
138 int drm_intel_bo_is_reusable(drm_intel_bo *bo);
139 int drm_intel_bo_references(drm_intel_bo *bo, drm_intel_bo *target_bo);
141 /* drm_intel_bufmgr_gem.c */
142 drm_intel_bufmgr *drm_intel_bufmgr_gem_init(int fd, int batch_size);
143 drm_intel_bo *drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr,
145 unsigned int handle);
146 void drm_intel_bufmgr_gem_enable_reuse(drm_intel_bufmgr *bufmgr);
147 void drm_intel_bufmgr_gem_enable_fenced_relocs(drm_intel_bufmgr *bufmgr);
148 int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo);
149 int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
150 void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
152 int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);
154 /* drm_intel_bufmgr_fake.c */
155 drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd,
156 unsigned long low_offset,
159 volatile unsigned int
161 void drm_intel_bufmgr_fake_set_last_dispatch(drm_intel_bufmgr *bufmgr,
162 volatile unsigned int
164 void drm_intel_bufmgr_fake_set_exec_callback(drm_intel_bufmgr *bufmgr,
165 int (*exec) (drm_intel_bo *bo,
169 void drm_intel_bufmgr_fake_set_fence_callback(drm_intel_bufmgr *bufmgr,
170 unsigned int (*emit) (void *priv),
171 void (*wait) (unsigned int fence,
174 drm_intel_bo *drm_intel_bo_fake_alloc_static(drm_intel_bufmgr *bufmgr,
176 unsigned long offset,
177 unsigned long size, void *virt);
178 void drm_intel_bo_fake_disable_backing_store(drm_intel_bo *bo,
179 void (*invalidate_cb) (drm_intel_bo
184 void drm_intel_bufmgr_fake_contended_lock_take(drm_intel_bufmgr *bufmgr);
185 void drm_intel_bufmgr_fake_evict_all(drm_intel_bufmgr *bufmgr);
187 /** @{ Compatibility defines to keep old code building despite the symbol rename
188 * from dri_* to drm_intel_*
190 #define dri_bo drm_intel_bo
191 #define dri_bufmgr drm_intel_bufmgr
192 #define dri_bo_alloc drm_intel_bo_alloc
193 #define dri_bo_reference drm_intel_bo_reference
194 #define dri_bo_unreference drm_intel_bo_unreference
195 #define dri_bo_map drm_intel_bo_map
196 #define dri_bo_unmap drm_intel_bo_unmap
197 #define dri_bo_subdata drm_intel_bo_subdata
198 #define dri_bo_get_subdata drm_intel_bo_get_subdata
199 #define dri_bo_wait_rendering drm_intel_bo_wait_rendering
200 #define dri_bufmgr_set_debug drm_intel_bufmgr_set_debug
201 #define dri_bufmgr_destroy drm_intel_bufmgr_destroy
202 #define dri_bo_exec drm_intel_bo_exec
203 #define dri_bufmgr_check_aperture_space drm_intel_bufmgr_check_aperture_space
204 #define dri_bo_emit_reloc(reloc_bo, read, write, target_offset, \
205 reloc_offset, target_bo) \
206 drm_intel_bo_emit_reloc(reloc_bo, reloc_offset, \
207 target_bo, target_offset, \
209 #define dri_bo_pin drm_intel_bo_pin
210 #define dri_bo_unpin drm_intel_bo_unpin
211 #define dri_bo_get_tiling drm_intel_bo_get_tiling
212 #define dri_bo_set_tiling(bo, mode) drm_intel_bo_set_tiling(bo, mode, 0)
213 #define dri_bo_flink drm_intel_bo_flink
214 #define intel_bufmgr_gem_init drm_intel_bufmgr_gem_init
215 #define intel_bo_gem_create_from_name drm_intel_bo_gem_create_from_name
216 #define intel_bufmgr_gem_enable_reuse drm_intel_bufmgr_gem_enable_reuse
217 #define intel_bufmgr_fake_init drm_intel_bufmgr_fake_init
218 #define intel_bufmgr_fake_set_last_dispatch drm_intel_bufmgr_fake_set_last_dispatch
219 #define intel_bufmgr_fake_set_exec_callback drm_intel_bufmgr_fake_set_exec_callback
220 #define intel_bufmgr_fake_set_fence_callback drm_intel_bufmgr_fake_set_fence_callback
221 #define intel_bo_fake_alloc_static drm_intel_bo_fake_alloc_static
222 #define intel_bo_fake_disable_backing_store drm_intel_bo_fake_disable_backing_store
223 #define intel_bufmgr_fake_contended_lock_take drm_intel_bufmgr_fake_contended_lock_take
224 #define intel_bufmgr_fake_evict_all drm_intel_bufmgr_fake_evict_all
228 #endif /* INTEL_BUFMGR_H */