1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, TX., USA
5 * Copyright 2009 VMware, Inc., Palo Alto, CA., 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 above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
23 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
24 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
26 * USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
30 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
39 #include "wsbm_pool.h"
40 #include "wsbm_manager.h"
42 struct _WsbmMallocBuffer
44 struct _WsbmBufStorage buf;
49 static inline struct _WsbmMallocBuffer *
50 mallocBuf(struct _WsbmBufStorage *buf)
52 return containerOf(buf, struct _WsbmMallocBuffer, buf);
55 static struct _WsbmBufStorage *
56 pool_create(struct _WsbmBufferPool *pool,
57 unsigned long size, uint32_t placement, unsigned alignment)
59 struct _WsbmMallocBuffer *mBuf = malloc(size + sizeof(*mBuf) + 16);
64 wsbmBufStorageInit(&mBuf->buf, pool);
66 mBuf->mem = (void *)((unsigned long)mBuf + sizeof(*mBuf));
67 if ((placement & WSBM_PL_MASK_MEM) != WSBM_PL_FLAG_SYSTEM)
74 pool_destroy(struct _WsbmBufStorage **buf)
76 free(mallocBuf(*buf));
81 pool_waitIdle(struct _WsbmBufStorage *buf, int lazy)
87 pool_map(struct _WsbmBufStorage *buf, unsigned mode, void **virtual)
89 *virtual = mallocBuf(buf)->mem;
94 pool_unmap(struct _WsbmBufStorage *buf)
100 pool_syncforcpu(struct _WsbmBufStorage *buf, unsigned mode)
106 pool_releasefromcpu(struct _WsbmBufStorage *buf, unsigned mode)
112 pool_offset(struct _WsbmBufStorage *buf)
122 pool_poolOffset(struct _WsbmBufStorage *buf)
131 pool_placement(struct _WsbmBufStorage *buf)
133 return WSBM_PL_FLAG_SYSTEM | WSBM_PL_FLAG_CACHED;
137 pool_size(struct _WsbmBufStorage *buf)
139 return mallocBuf(buf)->size;
143 pool_fence(struct _WsbmBufStorage *buf, struct _WsbmFenceObject *fence)
148 static struct _WsbmKernelBuf *
149 pool_kernel(struct _WsbmBufStorage *buf)
156 pool_takedown(struct _WsbmBufferPool *pool)
161 struct _WsbmBufferPool *
162 wsbmMallocPoolInit(void)
164 struct _WsbmBufferPool *pool;
166 pool = (struct _WsbmBufferPool *)calloc(1, sizeof(*pool));
171 pool->map = &pool_map;
172 pool->unmap = &pool_unmap;
173 pool->syncforcpu = &pool_syncforcpu;
174 pool->releasefromcpu = &pool_releasefromcpu;
175 pool->destroy = &pool_destroy;
176 pool->offset = &pool_offset;
177 pool->poolOffset = &pool_poolOffset;
178 pool->placement = &pool_placement;
179 pool->size = &pool_size;
180 pool->create = &pool_create;
181 pool->fence = &pool_fence;
182 pool->kernel = &pool_kernel;
183 pool->validate = NULL;
184 pool->waitIdle = &pool_waitIdle;
185 pool->takeDown = &pool_takedown;