1 /**************************************************************************
3 * Copyright © 2007 Red Hat Inc.
4 * Copyright © 2007 Intel Corporation
5 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * The above copyright notice and this permission notice (including the
25 * next paragraph) shall be included in all copies or substantial portions
29 **************************************************************************/
31 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
32 * Keith Whitwell <keithw-at-tungstengraphics-dot-com>
33 * Eric Anholt <eric@anholt.net>
34 * Dave Airlie <airlied@linux.ie>
43 #include <sys/ioctl.h>
47 #include "dri_bufmgr.h"
48 #include "intel_bufmgr.h"
53 #define DBG(...) do { \
54 if (bufmgr_gem->bufmgr.debug) \
55 fprintf(stderr, __VA_ARGS__); \
58 typedef struct _dri_bo_gem dri_bo_gem;
60 struct dri_gem_bo_bucket {
61 dri_bo_gem *head, **tail;
63 * Limit on the number of entries in this bucket.
65 * 0 means that this caching at this bucket size is disabled.
66 * -1 means that there is no limit to caching at this size.
72 /* Arbitrarily chosen, 16 means that the maximum size we'll cache for reuse
73 * is 1 << 16 pages, or 256MB.
75 #define INTEL_GEM_BO_BUCKETS 16
76 typedef struct _dri_bufmgr_gem {
79 struct intel_bufmgr intel_bufmgr;
85 struct drm_i915_gem_exec_object *exec_objects;
90 /** Array of lists of cached gem objects of power-of-two sizes */
91 struct dri_gem_bo_bucket cache_bucket[INTEL_GEM_BO_BUCKETS];
93 struct drm_i915_gem_execbuffer exec_arg;
100 /** Boolean whether the mmap ioctl has been called for this buffer yet. */
106 * Index of the buffer within the validation list while preparing a
107 * batchbuffer execution.
112 * Boolean whether set_domain to CPU is current
113 * Set when set_domain has been called
114 * Cleared when a batch has been submitted
118 /** Array passed to the DRM containing relocation information. */
119 struct drm_i915_gem_relocation_entry *relocs;
120 /** Array of bos corresponding to relocs[i].target_handle */
121 dri_bo **reloc_target_bo;
122 /** Number of entries in relocs */
124 /** Mapped address for the buffer */
145 static struct dri_gem_bo_bucket *
146 dri_gem_bo_bucket_for_size(dri_bufmgr_gem *bufmgr_gem, unsigned long size)
150 /* We only do buckets in power of two increments */
151 if ((size & (size - 1)) != 0)
154 /* We should only see sizes rounded to pages. */
155 assert((size % 4096) == 0);
157 /* We always allocate in units of pages */
158 i = ffs(size / 4096) - 1;
159 if (i >= INTEL_GEM_BO_BUCKETS)
162 return &bufmgr_gem->cache_bucket[i];
166 static void dri_gem_dump_validation_list(dri_bufmgr_gem *bufmgr_gem)
170 for (i = 0; i < bufmgr_gem->exec_count; i++) {
171 dri_bo *bo = bufmgr_gem->exec_bos[i];
172 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
174 if (bo_gem->relocs == NULL) {
175 DBG("%2d: %d (%s)\n", i, bo_gem->gem_handle, bo_gem->name);
179 for (j = 0; j < bo_gem->reloc_count; j++) {
180 dri_bo *target_bo = bo_gem->reloc_target_bo[j];
181 dri_bo_gem *target_gem = (dri_bo_gem *)target_bo;
183 DBG("%2d: %d (%s)@0x%08llx -> %d (%s)@0x%08lx + 0x%08x\n",
185 bo_gem->gem_handle, bo_gem->name, bo_gem->relocs[j].offset,
186 target_gem->gem_handle, target_gem->name, target_bo->offset,
187 bo_gem->relocs[j].delta);
193 * Adds the given buffer to the list of buffers to be validated (moved into the
194 * appropriate memory type) with the next batch submission.
196 * If a buffer is validated multiple times in a batch submission, it ends up
197 * with the intersection of the memory type flags and the union of the
201 intel_add_validate_buffer(dri_bo *bo)
203 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr;
204 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
207 if (bo_gem->validate_index != -1)
210 /* Extend the array of validation entries as necessary. */
211 if (bufmgr_gem->exec_count == bufmgr_gem->exec_size) {
212 int new_size = bufmgr_gem->exec_size * 2;
217 bufmgr_gem->exec_objects =
218 realloc(bufmgr_gem->exec_objects,
219 sizeof(*bufmgr_gem->exec_objects) * new_size);
220 bufmgr_gem->exec_bos =
221 realloc(bufmgr_gem->exec_bos,
222 sizeof(*bufmgr_gem->exec_bos) * new_size);
223 bufmgr_gem->exec_size = new_size;
226 index = bufmgr_gem->exec_count;
227 bo_gem->validate_index = index;
228 /* Fill in array entry */
229 bufmgr_gem->exec_objects[index].handle = bo_gem->gem_handle;
230 bufmgr_gem->exec_objects[index].relocation_count = bo_gem->reloc_count;
231 bufmgr_gem->exec_objects[index].relocs_ptr = (uintptr_t)bo_gem->relocs;
232 bufmgr_gem->exec_objects[index].alignment = 0;
233 bufmgr_gem->exec_objects[index].offset = 0;
234 bufmgr_gem->exec_bos[index] = bo;
235 dri_bo_reference(bo);
236 bufmgr_gem->exec_count++;
240 #define RELOC_BUF_SIZE(x) ((I915_RELOC_HEADER + x * I915_RELOC0_STRIDE) * \
244 intel_setup_reloc_list(dri_bo *bo)
246 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
247 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr;
249 bo_gem->relocs = malloc(bufmgr_gem->max_relocs *
250 sizeof(struct drm_i915_gem_relocation_entry));
251 bo_gem->reloc_target_bo = malloc(bufmgr_gem->max_relocs * sizeof(dri_bo *));
257 dri_gem_bo_alloc(dri_bufmgr *bufmgr, const char *name,
258 unsigned long size, unsigned int alignment)
260 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bufmgr;
262 unsigned int page_size = getpagesize();
264 struct dri_gem_bo_bucket *bucket;
265 int alloc_from_cache = 0;
266 unsigned long bo_size;
268 /* Round the allocated size up to a power of two number of pages. */
269 bo_size = 1 << logbase2(size);
270 if (bo_size < page_size)
272 bucket = dri_gem_bo_bucket_for_size(bufmgr_gem, bo_size);
274 /* If we don't have caching at this size, don't actually round the
277 if (bucket == NULL || bucket->max_entries == 0) {
279 if (bo_size < page_size)
283 /* Get a buffer out of the cache if available */
284 if (bucket != NULL && bucket->num_entries > 0) {
285 struct drm_i915_gem_busy busy;
287 bo_gem = bucket->head;
288 busy.handle = bo_gem->gem_handle;
290 ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_BUSY, &busy);
291 alloc_from_cache = (ret == 0 && busy.busy == 0);
293 if (alloc_from_cache) {
294 bucket->head = bo_gem->next;
295 if (bo_gem->next == NULL)
296 bucket->tail = &bucket->head;
297 bucket->num_entries--;
301 if (!alloc_from_cache) {
302 struct drm_gem_create create;
304 bo_gem = calloc(1, sizeof(*bo_gem));
308 bo_gem->bo.size = bo_size;
309 memset(&create, 0, sizeof(create));
310 create.size = bo_size;
312 ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CREATE, &create);
313 bo_gem->gem_handle = create.handle;
318 bo_gem->bo.bufmgr = bufmgr;
322 bo_gem->refcount = 1;
323 bo_gem->validate_index = -1;
325 DBG("bo_create: buf %d (%s) %ldb\n",
326 bo_gem->gem_handle, bo_gem->name, size);
332 * Returns a dri_bo wrapping the given buffer object handle.
334 * This can be used when one application needs to pass a buffer object
338 intel_bo_gem_create_from_name(dri_bufmgr *bufmgr, const char *name,
341 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bufmgr;
344 struct drm_gem_open open_arg;
346 bo_gem = calloc(1, sizeof(*bo_gem));
350 memset(&open_arg, 0, sizeof(open_arg));
351 open_arg.name = handle;
352 ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_OPEN, &open_arg);
354 fprintf(stderr, "Couldn't reference %s handle 0x%08x: %s\n",
355 name, handle, strerror(-ret));
359 bo_gem->bo.size = open_arg.size;
360 bo_gem->bo.offset = 0;
361 bo_gem->bo.virtual = NULL;
362 bo_gem->bo.bufmgr = bufmgr;
364 bo_gem->refcount = 1;
365 bo_gem->validate_index = -1;
366 bo_gem->gem_handle = open_arg.handle;
368 DBG("bo_create_from_handle: %d (%s)\n", handle, bo_gem->name);
374 dri_gem_bo_reference(dri_bo *bo)
376 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
382 dri_gem_bo_unreference(dri_bo *bo)
384 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr;
385 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
390 if (--bo_gem->refcount == 0) {
391 struct dri_gem_bo_bucket *bucket;
394 if (bo_gem->relocs != NULL) {
397 /* Unreference all the target buffers */
398 for (i = 0; i < bo_gem->reloc_count; i++)
399 dri_bo_unreference(bo_gem->reloc_target_bo[i]);
400 free(bo_gem->reloc_target_bo);
401 free(bo_gem->relocs);
404 DBG("bo_unreference final: %d (%s)\n",
405 bo_gem->gem_handle, bo_gem->name);
407 bucket = dri_gem_bo_bucket_for_size(bufmgr_gem, bo->size);
408 /* Put the buffer into our internal cache for reuse if we can. */
409 if (bucket != NULL &&
410 (bucket->max_entries == -1 ||
411 (bucket->max_entries > 0 &&
412 bucket->num_entries < bucket->max_entries)))
415 bo_gem->validate_index = -1;
416 bo_gem->relocs = NULL;
417 bo_gem->reloc_target_bo = NULL;
418 bo_gem->reloc_count = 0;
421 *bucket->tail = bo_gem;
422 bucket->tail = &bo_gem->next;
423 bucket->num_entries++;
425 struct drm_gem_close close;
427 /* Close this object */
428 close.handle = bo_gem->gem_handle;
429 ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CLOSE, &close);
432 "DRM_IOCTL_GEM_CLOSE %d failed (%s): %s\n",
433 bo_gem->gem_handle, bo_gem->name, strerror(-ret));
443 dri_gem_bo_map(dri_bo *bo, int write_enable)
445 dri_bufmgr_gem *bufmgr_gem;
446 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
447 struct drm_gem_set_domain set_domain;
450 bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr;
452 /* Allow recursive mapping. Mesa may recursively map buffers with
453 * nested display loops.
455 if (!bo_gem->mapped) {
457 assert(bo->virtual == NULL);
459 DBG("bo_map: %d (%s)\n", bo_gem->gem_handle, bo_gem->name);
461 if (bo_gem->virtual == NULL) {
462 struct drm_gem_mmap mmap_arg;
464 memset(&mmap_arg, 0, sizeof(mmap_arg));
465 mmap_arg.handle = bo_gem->gem_handle;
467 mmap_arg.size = bo->size;
468 ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_MMAP, &mmap_arg);
470 fprintf(stderr, "%s:%d: Error mapping buffer %d (%s): %s .\n",
472 bo_gem->gem_handle, bo_gem->name, strerror(errno));
474 bo_gem->virtual = (void *)(uintptr_t)mmap_arg.addr_ptr;
476 bo->virtual = bo_gem->virtual;
478 DBG("bo_map: %d (%s) -> %p\n", bo_gem->gem_handle, bo_gem->name, bo_gem->virtual);
481 if (!bo_gem->cpu_domain_set) {
482 set_domain.handle = bo_gem->gem_handle;
483 set_domain.read_domains = DRM_GEM_DOMAIN_CPU;
484 set_domain.write_domain = write_enable ? DRM_GEM_DOMAIN_CPU : 0;
485 ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_GEM_SET_DOMAIN, &set_domain);
487 fprintf (stderr, "%s:%d: Error setting memory domains %d (%08x %08x): %s .\n",
489 bo_gem->gem_handle, set_domain.read_domains, set_domain.write_domain,
492 bo_gem->cpu_domain_set = 1;
499 dri_gem_bo_unmap(dri_bo *bo)
501 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
506 assert(bo_gem->mapped);
512 dri_gem_bo_subdata (dri_bo *bo, unsigned long offset,
513 unsigned long size, const void *data)
515 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr;
516 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
517 struct drm_gem_pwrite pwrite;
520 memset (&pwrite, 0, sizeof (pwrite));
521 pwrite.handle = bo_gem->gem_handle;
522 pwrite.offset = offset;
524 pwrite.data_ptr = (uint64_t) (uintptr_t) data;
525 ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_GEM_PWRITE, &pwrite);
527 fprintf (stderr, "%s:%d: Error writing data to buffer %d: (%d %d) %s .\n",
529 bo_gem->gem_handle, (int) offset, (int) size,
536 dri_gem_bo_get_subdata (dri_bo *bo, unsigned long offset,
537 unsigned long size, void *data)
539 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr;
540 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
541 struct drm_gem_pread pread;
544 memset (&pread, 0, sizeof (pread));
545 pread.handle = bo_gem->gem_handle;
546 pread.offset = offset;
548 pread.data_ptr = (uint64_t) (uintptr_t) data;
549 ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_GEM_PREAD, &pread);
551 fprintf (stderr, "%s:%d: Error reading data from buffer %d: (%d %d) %s .\n",
553 bo_gem->gem_handle, (int) offset, (int) size,
560 dri_gem_bo_wait_rendering(dri_bo *bo)
562 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr;
563 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
564 struct drm_gem_set_domain set_domain;
567 set_domain.handle = bo_gem->gem_handle;
568 set_domain.read_domains = DRM_GEM_DOMAIN_CPU;
569 set_domain.write_domain = 0;
570 ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_GEM_SET_DOMAIN, &set_domain);
572 fprintf (stderr, "%s:%d: Error setting memory domains %d (%08x %08x): %s .\n",
574 bo_gem->gem_handle, set_domain.read_domains, set_domain.write_domain,
580 dri_bufmgr_gem_destroy(dri_bufmgr *bufmgr)
582 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bufmgr;
585 free(bufmgr_gem->exec_objects);
586 free(bufmgr_gem->exec_bos);
588 /* Free any cached buffer objects we were going to reuse */
589 for (i = 0; i < INTEL_GEM_BO_BUCKETS; i++) {
590 struct dri_gem_bo_bucket *bucket = &bufmgr_gem->cache_bucket[i];
593 while ((bo_gem = bucket->head) != NULL) {
594 struct drm_gem_close close;
597 bucket->head = bo_gem->next;
598 if (bo_gem->next == NULL)
599 bucket->tail = &bucket->head;
600 bucket->num_entries--;
603 munmap (bo_gem->virtual, bo_gem->bo.size);
605 /* Close this object */
606 close.handle = bo_gem->gem_handle;
607 ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CLOSE, &close);
609 fprintf(stderr, "DRM_IOCTL_GEM_CLOSE failed: %s\n",
621 * Adds the target buffer to the validation list and adds the relocation
622 * to the reloc_buffer's relocation list.
624 * The relocation entry at the given offset must already contain the
625 * precomputed relocation value, because the kernel will optimize out
626 * the relocation entry write when the buffer hasn't moved from the
627 * last known offset in target_bo.
630 dri_gem_emit_reloc(dri_bo *bo, uint32_t read_domains, uint32_t write_domain,
631 uint32_t delta, uint32_t offset, dri_bo *target_bo)
633 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr;
634 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
635 dri_bo_gem *target_bo_gem = (dri_bo_gem *)target_bo;
637 /* Create a new relocation list if needed */
638 if (bo_gem->relocs == NULL)
639 intel_setup_reloc_list(bo);
642 assert(bo_gem->reloc_count < bufmgr_gem->max_relocs);
645 assert (offset <= bo->size - 4);
646 assert ((write_domain & (write_domain-1)) == 0);
648 bo_gem->relocs[bo_gem->reloc_count].offset = offset;
649 bo_gem->relocs[bo_gem->reloc_count].delta = delta;
650 bo_gem->relocs[bo_gem->reloc_count].target_handle =
651 target_bo_gem->gem_handle;
652 bo_gem->relocs[bo_gem->reloc_count].read_domains = read_domains;
653 bo_gem->relocs[bo_gem->reloc_count].write_domain = write_domain;
654 bo_gem->relocs[bo_gem->reloc_count].presumed_offset = target_bo->offset;
656 bo_gem->reloc_target_bo[bo_gem->reloc_count] = target_bo;
657 dri_bo_reference(target_bo);
659 bo_gem->reloc_count++;
664 * Walk the tree of relocations rooted at BO and accumulate the list of
665 * validations to be performed and update the relocation buffers with
666 * index values into the validation list.
669 dri_gem_bo_process_reloc(dri_bo *bo)
671 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
674 if (bo_gem->relocs == NULL)
677 for (i = 0; i < bo_gem->reloc_count; i++) {
678 dri_bo *target_bo = bo_gem->reloc_target_bo[i];
680 /* Continue walking the tree depth-first. */
681 dri_gem_bo_process_reloc(target_bo);
683 /* Add the target to the validate list */
684 intel_add_validate_buffer(target_bo);
689 dri_gem_process_reloc(dri_bo *batch_buf)
691 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *) batch_buf->bufmgr;
693 /* Update indices and set up the validate list. */
694 dri_gem_bo_process_reloc(batch_buf);
696 /* Add the batch buffer to the validation list. There are no relocations
699 intel_add_validate_buffer(batch_buf);
701 bufmgr_gem->exec_arg.buffers_ptr = (uintptr_t)bufmgr_gem->exec_objects;
702 bufmgr_gem->exec_arg.buffer_count = bufmgr_gem->exec_count;
703 bufmgr_gem->exec_arg.batch_start_offset = 0;
704 bufmgr_gem->exec_arg.batch_len = 0; /* written in intel_exec_ioctl */
706 return &bufmgr_gem->exec_arg;
710 intel_update_buffer_offsets (dri_bufmgr_gem *bufmgr_gem)
714 for (i = 0; i < bufmgr_gem->exec_count; i++) {
715 dri_bo *bo = bufmgr_gem->exec_bos[i];
716 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
718 /* Update the buffer offset */
719 if (bufmgr_gem->exec_objects[i].offset != bo->offset) {
720 DBG("BO %d (%s) migrated: 0x%08lx -> 0x%08llx\n",
721 bo_gem->gem_handle, bo_gem->name, bo->offset,
722 bufmgr_gem->exec_objects[i].offset);
723 bo->offset = bufmgr_gem->exec_objects[i].offset;
729 dri_gem_post_submit(dri_bo *batch_buf)
731 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)batch_buf->bufmgr;
734 intel_update_buffer_offsets (bufmgr_gem);
736 if (bufmgr_gem->bufmgr.debug)
737 dri_gem_dump_validation_list(bufmgr_gem);
739 for (i = 0; i < bufmgr_gem->exec_count; i++) {
740 dri_bo *bo = bufmgr_gem->exec_bos[i];
741 dri_bo_gem *bo_gem = (dri_bo_gem *)bo;
743 /* Need to call set_domain on next bo_map */
744 bo_gem->cpu_domain_set = 0;
746 /* Disconnect the buffer from the validate list */
747 bo_gem->validate_index = -1;
748 dri_bo_unreference(bo);
749 bufmgr_gem->exec_bos[i] = NULL;
751 bufmgr_gem->exec_count = 0;
755 * Enables unlimited caching of buffer objects for reuse.
757 * This is potentially very memory expensive, as the cache at each bucket
758 * size is only bounded by how many buffers of that size we've managed to have
762 intel_bufmgr_gem_enable_reuse(dri_bufmgr *bufmgr)
764 dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bufmgr;
767 for (i = 0; i < INTEL_GEM_BO_BUCKETS; i++) {
768 bufmgr_gem->cache_bucket[i].max_entries = -1;
776 dri_gem_check_aperture_space(dri_bo *bo)
782 * Initializes the GEM buffer manager, which uses the kernel to allocate, map,
783 * and manage map buffer objections.
785 * \param fd File descriptor of the opened DRM device.
788 intel_bufmgr_gem_init(int fd, int batch_size)
790 dri_bufmgr_gem *bufmgr_gem;
793 bufmgr_gem = calloc(1, sizeof(*bufmgr_gem));
796 /* Let's go with one relocation per every 2 dwords (but round down a bit
797 * since a power of two will mean an extra page allocation for the reloc
800 * Every 4 was too few for the blender benchmark.
802 bufmgr_gem->max_relocs = batch_size / sizeof(uint32_t) / 2 - 2;
804 bufmgr_gem->bufmgr.bo_alloc = dri_gem_bo_alloc;
805 bufmgr_gem->bufmgr.bo_reference = dri_gem_bo_reference;
806 bufmgr_gem->bufmgr.bo_unreference = dri_gem_bo_unreference;
807 bufmgr_gem->bufmgr.bo_map = dri_gem_bo_map;
808 bufmgr_gem->bufmgr.bo_unmap = dri_gem_bo_unmap;
809 bufmgr_gem->bufmgr.bo_subdata = dri_gem_bo_subdata;
810 bufmgr_gem->bufmgr.bo_get_subdata = dri_gem_bo_get_subdata;
811 bufmgr_gem->bufmgr.bo_wait_rendering = dri_gem_bo_wait_rendering;
812 bufmgr_gem->bufmgr.destroy = dri_bufmgr_gem_destroy;
813 bufmgr_gem->bufmgr.process_relocs = dri_gem_process_reloc;
814 bufmgr_gem->bufmgr.post_submit = dri_gem_post_submit;
815 bufmgr_gem->bufmgr.debug = 0;
816 bufmgr_gem->bufmgr.check_aperture_space = dri_gem_check_aperture_space;
817 bufmgr_gem->intel_bufmgr.emit_reloc = dri_gem_emit_reloc;
818 /* Initialize the linked lists for BO reuse cache. */
819 for (i = 0; i < INTEL_GEM_BO_BUCKETS; i++)
820 bufmgr_gem->cache_bucket[i].tail = &bufmgr_gem->cache_bucket[i].head;
822 return &bufmgr_gem->bufmgr;
826 intel_bo_emit_reloc(dri_bo *reloc_buf,
827 uint32_t read_domains, uint32_t write_domain,
828 uint32_t delta, uint32_t offset, dri_bo *target_buf)
830 struct intel_bufmgr *intel_bufmgr;
832 intel_bufmgr = (struct intel_bufmgr *)(reloc_buf->bufmgr + 1);
834 return intel_bufmgr->emit_reloc(reloc_buf, read_domains, write_domain,
835 delta, offset, target_buf);