1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 * A buffer manager does only one basic thing: it creates buffers. Actually,
33 * "buffer factory" would probably a more accurate description.
35 * You can chain buffer managers so that you can have a finer grained memory
36 * management and pooling.
38 * For example, for a simple batch buffer manager you would chain:
39 * - the native buffer manager, which provides DMA memory from the graphics
41 * - the pool buffer manager, which keep around a pool of equally sized buffers
42 * to avoid latency associated with the native buffer manager;
43 * - the fenced buffer manager, which will delay buffer destruction until the
44 * the moment the card finishing processing it.
46 * \author Jose Fonseca <jrfonseca@tungstengraphics.com>
53 #include "pb_buffer.h"
65 * Abstract base class for all buffer managers.
70 (*destroy
)( struct pb_manager
*mgr
);
73 (*create_buffer
)( struct pb_manager
*mgr
,
75 const struct pb_desc
*desc
);
78 * Flush all temporary-held buffers.
80 * Used mostly to aid debugging memory issues or to clean up resources when
81 * the drivers are long lived.
84 (*flush
)( struct pb_manager
*mgr
);
87 (*is_buffer_busy
)( struct pb_manager
*mgr
,
88 struct pb_buffer
*buf
);
93 * Malloc buffer provider.
95 * Simple wrapper around pb_malloc_buffer_create for convenience.
98 pb_malloc_bufmgr_create(void);
102 * Static buffer pool sub-allocator.
104 * Manages the allocation of equally sized buffers. It does so by allocating
105 * a single big buffer and divide it equally sized buffers.
107 * It is meant to manage the allocation of batch buffer pools.
110 pool_bufmgr_create(struct pb_manager
*provider
,
111 pb_size n
, pb_size size
,
112 const struct pb_desc
*desc
);
116 * Static sub-allocator based the old memory manager.
118 * It managers buffers of different sizes. It does so by allocating a buffer
119 * with the size of the heap, and then using the old mm memory manager to manage
123 mm_bufmgr_create(struct pb_manager
*provider
,
124 pb_size size
, pb_size align2
);
127 * Same as mm_bufmgr_create.
129 * Buffer will be release when the manager is destroyed.
132 mm_bufmgr_create_from_buffer(struct pb_buffer
*buffer
,
133 pb_size size
, pb_size align2
);
137 * Slab sub-allocator.
140 pb_slab_manager_create(struct pb_manager
*provider
,
143 const struct pb_desc
*desc
);
146 * Allow a range of buffer size, by aggregating multiple slabs sub-allocators
147 * with different bucket sizes.
150 pb_slab_range_manager_create(struct pb_manager
*provider
,
154 const struct pb_desc
*desc
);
158 * Time-based buffer cache.
160 * This manager keeps a cache of destroyed buffers during a time interval.
163 pb_cache_manager_create(struct pb_manager
*provider
,
170 * Fenced buffer manager.
172 * This manager is just meant for convenience. It wraps the buffers returned
173 * by another manager in fenced buffers, so that
175 * NOTE: the buffer manager that provides the buffers will be destroyed
179 fenced_bufmgr_create(struct pb_manager
*provider
,
180 struct pb_fence_ops
*ops
,
181 pb_size max_buffer_size
,
182 pb_size max_cpu_total_size
);
186 pb_alt_manager_create(struct pb_manager
*provider1
,
187 struct pb_manager
*provider2
);
191 * Ondemand buffer manager.
193 * Buffers are created in malloc'ed memory (fast and cached), and the constents
194 * is transfered to a buffer from the provider (typically in slow uncached
195 * memory) when there is an attempt to validate the buffer.
197 * Ideal for situations where one does not know before hand whether a given
198 * buffer will effectively be used by the hardware or not.
201 pb_ondemand_manager_create(struct pb_manager
*provider
);
205 * Debug buffer manager to detect buffer under- and overflows.
207 * Under/overflow sizes should be a multiple of the largest alignment
210 pb_debug_manager_create(struct pb_manager
*provider
,
211 pb_size underflow_size
, pb_size overflow_size
);
218 #endif /*PB_BUFMGR_H_*/