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 (at) anholt.net> 25 * 26 */ 27 28 /** 29 * @file intel_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_intel_bufmgr drm_intel_bufmgr; 48 typedef struct _drm_intel_context drm_intel_context; 49 typedef struct _drm_intel_bo drm_intel_bo; 50 51 struct _drm_intel_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_intel_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_intel_bo_emit_reloc() 95 */ 96 uint64_t offset64; 97 }; 98 99 enum aub_dump_bmp_format { 100 AUB_DUMP_BMP_FORMAT_8BIT = 1, 101 AUB_DUMP_BMP_FORMAT_ARGB_4444 = 4, 102 AUB_DUMP_BMP_FORMAT_ARGB_0888 = 6, 103 AUB_DUMP_BMP_FORMAT_ARGB_8888 = 7, 104 }; 105 106 typedef struct _drm_intel_aub_annotation { 107 uint32_t type; 108 uint32_t subtype; 109 uint32_t ending_offset; 110 } drm_intel_aub_annotation; 111 112 #define BO_ALLOC_FOR_RENDER (1<<0) 113 114 drm_intel_bo *drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name, 115 unsigned long size, unsigned int alignment); 116 drm_intel_bo *drm_intel_bo_alloc_for_render(drm_intel_bufmgr *bufmgr, 117 const char *name, 118 unsigned long size, 119 unsigned int alignment); 120 drm_intel_bo *drm_intel_bo_alloc_userptr(drm_intel_bufmgr *bufmgr, 121 const char *name, 122 void *addr, uint32_t tiling_mode, 123 uint32_t stride, unsigned long size, 124 unsigned long flags); 125 drm_intel_bo *drm_intel_bo_alloc_tiled(drm_intel_bufmgr *bufmgr, 126 const char *name, 127 int x, int y, int cpp, 128 uint32_t *tiling_mode, 129 unsigned long *pitch, 130 unsigned long flags); 131 void drm_intel_bo_reference(drm_intel_bo *bo); 132 void drm_intel_bo_unreference(drm_intel_bo *bo); 133 int drm_intel_bo_map(drm_intel_bo *bo, int write_enable); 134 int drm_intel_bo_unmap(drm_intel_bo *bo); 135 136 int drm_intel_bo_subdata(drm_intel_bo *bo, unsigned long offset, 137 unsigned long size, const void *data); 138 int drm_intel_bo_get_subdata(drm_intel_bo *bo, unsigned long offset, 139 unsigned long size, void *data); 140 void drm_intel_bo_wait_rendering(drm_intel_bo *bo); 141 142 void drm_intel_bufmgr_set_debug(drm_intel_bufmgr *bufmgr, int enable_debug); 143 void drm_intel_bufmgr_destroy(drm_intel_bufmgr *bufmgr); 144 int drm_intel_bo_exec(drm_intel_bo *bo, int used, 145 struct drm_clip_rect *cliprects, int num_cliprects, int DR4); 146 int drm_intel_bo_mrb_exec(drm_intel_bo *bo, int used, 147 struct drm_clip_rect *cliprects, int num_cliprects, int DR4, 148 unsigned int flags); 149 int drm_intel_bufmgr_check_aperture_space(drm_intel_bo ** bo_array, int count); 150 151 int drm_intel_bo_emit_reloc(drm_intel_bo *bo, uint32_t offset, 152 drm_intel_bo *target_bo, uint32_t target_offset, 153 uint32_t read_domains, uint32_t write_domain); 154 int drm_intel_bo_emit_reloc_fence(drm_intel_bo *bo, uint32_t offset, 155 drm_intel_bo *target_bo, 156 uint32_t target_offset, 157 uint32_t read_domains, uint32_t write_domain); 158 int drm_intel_bo_pin(drm_intel_bo *bo, uint32_t alignment); 159 int drm_intel_bo_unpin(drm_intel_bo *bo); 160 int drm_intel_bo_set_tiling(drm_intel_bo *bo, uint32_t * tiling_mode, 161 uint32_t stride); 162 int drm_intel_bo_get_tiling(drm_intel_bo *bo, uint32_t * tiling_mode, 163 uint32_t * swizzle_mode); 164 int drm_intel_bo_flink(drm_intel_bo *bo, uint32_t * name); 165 int drm_intel_bo_busy(drm_intel_bo *bo); 166 int drm_intel_bo_madvise(drm_intel_bo *bo, int madv); 167 int drm_intel_bo_use_48b_address_range(drm_intel_bo *bo, uint32_t enable); 168 int drm_intel_bo_set_softpin_offset(drm_intel_bo *bo, uint64_t offset); 169 170 int drm_intel_bo_disable_reuse(drm_intel_bo *bo); 171 int drm_intel_bo_is_reusable(drm_intel_bo *bo); 172 int drm_intel_bo_references(drm_intel_bo *bo, drm_intel_bo *target_bo); 173 174 /* drm_intel_bufmgr_gem.c */ 175 drm_intel_bufmgr *drm_intel_bufmgr_gem_init(int fd, int batch_size); 176 drm_intel_bo *drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr, 177 const char *name, 178 unsigned int handle); 179 void drm_intel_bufmgr_gem_enable_reuse(drm_intel_bufmgr *bufmgr); 180 void drm_intel_bufmgr_gem_enable_fenced_relocs(drm_intel_bufmgr *bufmgr); 181 void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr, 182 int limit); 183 int drm_intel_gem_bo_map_unsynchronized(drm_intel_bo *bo); 184 int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo); 185 int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo); 186 187 int drm_intel_gem_bo_get_reloc_count(drm_intel_bo *bo); 188 void drm_intel_gem_bo_clear_relocs(drm_intel_bo *bo, int start); 189 void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable); 190 191 void 192 drm_intel_bufmgr_gem_set_aub_filename(drm_intel_bufmgr *bufmgr, 193 const char *filename); 194 void drm_intel_bufmgr_gem_set_aub_dump(drm_intel_bufmgr *bufmgr, int enable); 195 void drm_intel_gem_bo_aub_dump_bmp(drm_intel_bo *bo, 196 int x1, int y1, int width, int height, 197 enum aub_dump_bmp_format format, 198 int pitch, int offset); 199 void 200 drm_intel_bufmgr_gem_set_aub_annotations(drm_intel_bo *bo, 201 drm_intel_aub_annotation *annotations, 202 unsigned count); 203 204 int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id); 205 206 int drm_intel_get_aperture_sizes(int fd, size_t *mappable, size_t *total); 207 int drm_intel_bufmgr_gem_get_devid(drm_intel_bufmgr *bufmgr); 208 int drm_intel_gem_bo_wait(drm_intel_bo *bo, int64_t timeout_ns); 209 210 drm_intel_context *drm_intel_gem_context_create(drm_intel_bufmgr *bufmgr); 211 void drm_intel_gem_context_destroy(drm_intel_context *ctx); 212 int drm_intel_gem_bo_context_exec(drm_intel_bo *bo, drm_intel_context *ctx, 213 int used, unsigned int flags); 214 215 int drm_intel_bo_gem_export_to_prime(drm_intel_bo *bo, int *prime_fd); 216 drm_intel_bo *drm_intel_bo_gem_create_from_prime(drm_intel_bufmgr *bufmgr, 217 int prime_fd, int size); 218 219 /* drm_intel_bufmgr_fake.c */ 220 drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd, 221 unsigned long low_offset, 222 void *low_virtual, 223 unsigned long size, 224 volatile unsigned int 225 *last_dispatch); 226 void drm_intel_bufmgr_fake_set_last_dispatch(drm_intel_bufmgr *bufmgr, 227 volatile unsigned int 228 *last_dispatch); 229 void drm_intel_bufmgr_fake_set_exec_callback(drm_intel_bufmgr *bufmgr, 230 int (*exec) (drm_intel_bo *bo, 231 unsigned int used, 232 void *priv), 233 void *priv); 234 void drm_intel_bufmgr_fake_set_fence_callback(drm_intel_bufmgr *bufmgr, 235 unsigned int (*emit) (void *priv), 236 void (*wait) (unsigned int fence, 237 void *priv), 238 void *priv); 239 drm_intel_bo *drm_intel_bo_fake_alloc_static(drm_intel_bufmgr *bufmgr, 240 const char *name, 241 unsigned long offset, 242 unsigned long size, void *virt); 243 void drm_intel_bo_fake_disable_backing_store(drm_intel_bo *bo, 244 void (*invalidate_cb) (drm_intel_bo 245 * bo, 246 void *ptr), 247 void *ptr); 248 249 void drm_intel_bufmgr_fake_contended_lock_take(drm_intel_bufmgr *bufmgr); 250 void drm_intel_bufmgr_fake_evict_all(drm_intel_bufmgr *bufmgr); 251 252 struct drm_intel_decode *drm_intel_decode_context_alloc(uint32_t devid); 253 void drm_intel_decode_context_free(struct drm_intel_decode *ctx); 254 void drm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx, 255 void *data, uint32_t hw_offset, 256 int count); 257 void drm_intel_decode_set_dump_past_end(struct drm_intel_decode *ctx, 258 int dump_past_end); 259 void drm_intel_decode_set_head_tail(struct drm_intel_decode *ctx, 260 uint32_t head, uint32_t tail); 261 void drm_intel_decode_set_output_file(struct drm_intel_decode *ctx, FILE *out); 262 void drm_intel_decode(struct drm_intel_decode *ctx); 263 264 int drm_intel_reg_read(drm_intel_bufmgr *bufmgr, 265 uint32_t offset, 266 uint64_t *result); 267 268 int drm_intel_get_reset_stats(drm_intel_context *ctx, 269 uint32_t *reset_count, 270 uint32_t *active, 271 uint32_t *pending); 272 273 int drm_intel_get_subslice_total(int fd, unsigned int *subslice_total); 274 int drm_intel_get_eu_total(int fd, unsigned int *eu_total); 275 276 /** @{ Compatibility defines to keep old code building despite the symbol rename 277 * from dri_* to drm_intel_* 278 */ 279 #define dri_bo drm_intel_bo 280 #define dri_bufmgr drm_intel_bufmgr 281 #define dri_bo_alloc drm_intel_bo_alloc 282 #define dri_bo_reference drm_intel_bo_reference 283 #define dri_bo_unreference drm_intel_bo_unreference 284 #define dri_bo_map drm_intel_bo_map 285 #define dri_bo_unmap drm_intel_bo_unmap 286 #define dri_bo_subdata drm_intel_bo_subdata 287 #define dri_bo_get_subdata drm_intel_bo_get_subdata 288 #define dri_bo_wait_rendering drm_intel_bo_wait_rendering 289 #define dri_bufmgr_set_debug drm_intel_bufmgr_set_debug 290 #define dri_bufmgr_destroy drm_intel_bufmgr_destroy 291 #define dri_bo_exec drm_intel_bo_exec 292 #define dri_bufmgr_check_aperture_space drm_intel_bufmgr_check_aperture_space 293 #define dri_bo_emit_reloc(reloc_bo, read, write, target_offset, \ 294 reloc_offset, target_bo) \ 295 drm_intel_bo_emit_reloc(reloc_bo, reloc_offset, \ 296 target_bo, target_offset, \ 297 read, write); 298 #define dri_bo_pin drm_intel_bo_pin 299 #define dri_bo_unpin drm_intel_bo_unpin 300 #define dri_bo_get_tiling drm_intel_bo_get_tiling 301 #define dri_bo_set_tiling(bo, mode) drm_intel_bo_set_tiling(bo, mode, 0) 302 #define dri_bo_flink drm_intel_bo_flink 303 #define intel_bufmgr_gem_init drm_intel_bufmgr_gem_init 304 #define intel_bo_gem_create_from_name drm_intel_bo_gem_create_from_name 305 #define intel_bufmgr_gem_enable_reuse drm_intel_bufmgr_gem_enable_reuse 306 #define intel_bufmgr_fake_init drm_intel_bufmgr_fake_init 307 #define intel_bufmgr_fake_set_last_dispatch drm_intel_bufmgr_fake_set_last_dispatch 308 #define intel_bufmgr_fake_set_exec_callback drm_intel_bufmgr_fake_set_exec_callback 309 #define intel_bufmgr_fake_set_fence_callback drm_intel_bufmgr_fake_set_fence_callback 310 #define intel_bo_fake_alloc_static drm_intel_bo_fake_alloc_static 311 #define intel_bo_fake_disable_backing_store drm_intel_bo_fake_disable_backing_store 312 #define intel_bufmgr_fake_contended_lock_take drm_intel_bufmgr_fake_contended_lock_take 313 #define intel_bufmgr_fake_evict_all drm_intel_bufmgr_fake_evict_all 314 315 /** @{ */ 316 317 #if defined(__cplusplus) 318 } 319 #endif 320 321 #endif /* INTEL_BUFMGR_H */ 322