1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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
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 fenced buffer manager, which will delay buffer destruction until the
42 * the moment the card finishing processing it.
44 * \author Jose Fonseca <jfonseca@vmware.com>
51 #include "pb_buffer.h"
63 * Abstract base class for all buffer managers.
68 (*destroy
)( struct pb_manager
*mgr
);
71 (*create_buffer
)( struct pb_manager
*mgr
,
73 const struct pb_desc
*desc
);
76 * Flush all temporary-held buffers.
78 * Used mostly to aid debugging memory issues or to clean up resources when
79 * the drivers are long lived.
82 (*flush
)( struct pb_manager
*mgr
);
85 (*is_buffer_busy
)( struct pb_manager
*mgr
,
86 struct pb_buffer
*buf
);
90 * Static sub-allocator based the old memory manager.
92 * It managers buffers of different sizes. It does so by allocating a buffer
93 * with the size of the heap, and then using the old mm memory manager to manage
97 mm_bufmgr_create(struct pb_manager
*provider
,
98 pb_size size
, pb_size align2
);
101 * Same as mm_bufmgr_create.
103 * Buffer will be release when the manager is destroyed.
106 mm_bufmgr_create_from_buffer(struct pb_buffer
*buffer
,
107 pb_size size
, pb_size align2
);
111 * Slab sub-allocator.
114 pb_slab_manager_create(struct pb_manager
*provider
,
117 const struct pb_desc
*desc
);
120 * Allow a range of buffer size, by aggregating multiple slabs sub-allocators
121 * with different bucket sizes.
124 pb_slab_range_manager_create(struct pb_manager
*provider
,
128 const struct pb_desc
*desc
);
132 * Time-based buffer cache.
134 * This manager keeps a cache of destroyed buffers during a time interval.
137 pb_cache_manager_create(struct pb_manager
*provider
,
140 unsigned bypass_usage
,
141 uint64_t maximum_cache_size
);
144 * Remove a buffer from the cache, but keep it alive.
147 pb_cache_manager_remove_buffer(struct pb_buffer
*buf
);
152 * Fenced buffer manager.
154 * This manager is just meant for convenience. It wraps the buffers returned
155 * by another manager in fenced buffers, so that
157 * NOTE: the buffer manager that provides the buffers will be destroyed
161 fenced_bufmgr_create(struct pb_manager
*provider
,
162 struct pb_fence_ops
*ops
,
163 pb_size max_buffer_size
,
164 pb_size max_cpu_total_size
);
167 * Debug buffer manager to detect buffer under- and overflows.
169 * Under/overflow sizes should be a multiple of the largest alignment
172 pb_debug_manager_create(struct pb_manager
*provider
,
173 pb_size underflow_size
, pb_size overflow_size
);
180 #endif /*PB_BUFMGR_H_*/