1 /**************************************************************************
3 * Copyright 2006-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>
33 #ifndef _WSBM_BUFPOOL_H_
34 #define _WSBM_BUFPOOL_H_
37 #include "wsbm_util.h"
38 #include "wsbm_driver.h"
39 #include "wsbm_atomic.h"
41 struct _WsbmFenceObject;
43 struct _WsbmBufStorage
45 struct _WsbmBufferPool *pool;
46 struct _WsbmMutex mutex;
47 struct _WsbmAtomic refCount;
48 struct _WsbmAtomic onList;
50 void (*destroyContainer) (void *);
53 struct _WsbmKernelBuf;
55 struct _WsbmBufferPool
58 int (*map) (struct _WsbmBufStorage * buf, unsigned mode, void **virtual);
59 void (*unmap) (struct _WsbmBufStorage * buf);
60 int (*syncforcpu) (struct _WsbmBufStorage * buf, unsigned mode);
61 void (*releasefromcpu) (struct _WsbmBufStorage * buf, unsigned mode);
62 void (*destroy) (struct _WsbmBufStorage ** buf);
63 unsigned long (*offset) (struct _WsbmBufStorage * buf);
64 unsigned long (*poolOffset) (struct _WsbmBufStorage * buf);
65 uint32_t(*placement) (struct _WsbmBufStorage * buf);
66 unsigned long (*size) (struct _WsbmBufStorage * buf);
67 struct _WsbmKernelBuf *(*kernel) (struct _WsbmBufStorage * buf);
68 struct _WsbmBufStorage *(*create) (struct _WsbmBufferPool * pool,
72 struct _WsbmBufStorage *(*createByReference) (struct _WsbmBufferPool *
73 pool, uint32_t handle);
74 void (*fence) (struct _WsbmBufStorage * buf,
75 struct _WsbmFenceObject * fence);
76 void (*unvalidate) (struct _WsbmBufStorage * buf);
77 int (*validate) (struct _WsbmBufStorage * buf, uint64_t set_flags,
79 int (*waitIdle) (struct _WsbmBufStorage * buf, int lazy);
80 int (*setStatus) (struct _WsbmBufStorage * buf,
81 uint32_t set_placement, uint32_t clr_placement);
82 void (*takeDown) (struct _WsbmBufferPool * pool);
86 wsbmBufStorageInit(struct _WsbmBufStorage *storage,
87 struct _WsbmBufferPool *pool)
89 int ret = WSBM_MUTEX_INIT(&storage->mutex);
94 wsbmAtomicSet(&storage->refCount, 1);
95 wsbmAtomicSet(&storage->onList, 0);
96 storage->destroyContainer = NULL;
101 wsbmBufStorageTakedown(struct _WsbmBufStorage *storage)
103 WSBM_MUTEX_FREE(&storage->mutex);
107 wsbmBufStorageUnref(struct _WsbmBufStorage **pStorage)
109 struct _WsbmBufStorage *storage = *pStorage;
115 if (wsbmAtomicDecZero(&storage->refCount)) {
116 if (storage->destroyContainer)
117 storage->destroyContainer(storage->destroyArg);
118 storage->pool->destroy(&storage);
128 * Kernel buffer objects. Size in multiples of page size. Page size aligned.
131 extern struct _WsbmBufferPool *wsbmTTMPoolInit(int fd,
132 unsigned int devOffset);
133 extern struct _WsbmBufferPool *wsbmMallocPoolInit(void);
135 struct _WsbmSlabCache;
136 extern struct _WsbmBufferPool *wsbmSlabPoolInit(int fd, uint32_t devOffset,
139 uint32_t smallestSize,
141 uint32_t desiredNumBuffers,
142 uint32_t maxSlabSize,
143 uint32_t pageAlignment,
144 struct _WsbmSlabCache *cache);
145 extern struct _WsbmSlabCache *wsbmSlabCacheInit(uint32_t checkIntervalMsec,
146 uint32_t slabTimeoutMsec);
147 extern void wsbmSlabCacheFinish(struct _WsbmSlabCache *cache);
149 extern struct _WsbmBufferPool *wsbmUserPoolInit(void *vramAddr,
150 unsigned long vramStart,
151 unsigned long vramSize,
153 unsigned long agpStart,
154 unsigned long agpSize,
155 uint32_t(*fenceTypes)
156 (uint64_t set_flags));
158 extern void wsbmUserPoolClean(struct _WsbmBufferPool *pool,
159 int cleanVram, int cleanAgp);