2 * Copyright 2010 VMWare.
3 * Copyright 2010 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
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 AUTHOR(S) AND/OR THEIR 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.
25 * Jose Fonseca <jrfonseca-at-vmware-dot-com>
26 * Thomas Hellström <thomas-at-vmware-dot-com>
27 * Jerome Glisse <jglisse@redhat.com>
29 #include <util/u_memory.h>
30 #include <util/u_double_list.h>
31 #include <util/u_time.h>
32 #include <pipebuffer/pb_bufmgr.h>
33 #include "r600_priv.h"
35 static void r600_bomgr_timeout_flush(struct r600_bomgr *mgr)
37 struct r600_bo *bo, *tmp;
41 LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &mgr->delayed, list) {
42 if(!os_time_timeout(bo->start, bo->end, now))
48 r600_bo_destroy(mgr->radeon, bo);
52 static INLINE int r600_bo_is_compat(struct r600_bomgr *mgr,
62 /* be lenient with size */
63 if(bo->size >= 2*size) {
67 if(!pb_check_alignment(alignment, bo->alignment)) {
71 if (!fence_is_after(cfence, bo->fence)) {
78 struct r600_bo *r600_bomgr_bo_create(struct r600_bomgr *mgr,
83 struct r600_bo *bo, *tmp;
87 pipe_mutex_lock(mgr->mutex);
90 LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &mgr->delayed, list) {
91 if(r600_bo_is_compat(mgr, bo, size, alignment, cfence)) {
94 r600_bomgr_timeout_flush(mgr);
95 pipe_mutex_unlock(mgr->mutex);
96 LIST_INITHEAD(&bo->list);
97 pipe_reference_init(&bo->reference, 1);
101 if(os_time_timeout(bo->start, bo->end, now)) {
105 r600_bo_destroy(mgr->radeon, bo);
109 pipe_mutex_unlock(mgr->mutex);
113 void r600_bomgr_bo_init(struct r600_bomgr *mgr, struct r600_bo *bo)
115 LIST_INITHEAD(&bo->list);
119 boolean r600_bomgr_bo_destroy(struct r600_bomgr *mgr, struct r600_bo *bo)
121 bo->start = os_time_get();
122 bo->end = bo->start + mgr->usecs;
123 pipe_mutex_lock(mgr->mutex);
124 LIST_ADDTAIL(&bo->list, &mgr->delayed);
126 pipe_mutex_unlock(mgr->mutex);
130 void r600_bomgr_destroy(struct r600_bomgr *mgr)
132 struct r600_bo *bo, *tmp;
134 pipe_mutex_lock(mgr->mutex);
135 LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &mgr->delayed, list) {
139 r600_bo_destroy(mgr->radeon, bo);
141 pipe_mutex_unlock(mgr->mutex);
146 struct r600_bomgr *r600_bomgr_create(struct radeon *radeon, unsigned usecs)
148 struct r600_bomgr *mgr;
150 mgr = CALLOC_STRUCT(r600_bomgr);
154 mgr->radeon = radeon;
156 LIST_INITHEAD(&mgr->delayed);
157 mgr->num_delayed = 0;
158 pipe_mutex_init(mgr->mutex);