1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/**************************************************************************
*
* Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA
* All Rights Reserved.
* Copyright 2009 VMware, Inc., Palo Alto, CA., USA
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/*
* Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
*/
#ifndef _WSBM_BUFPOOL_H_
#define _WSBM_BUFPOOL_H_
#include <errno.h>
#include "wsbm_util.h"
#include "wsbm_driver.h"
#include "wsbm_atomic.h"
struct _WsbmFenceObject;
struct _WsbmBufStorage
{
struct _WsbmBufferPool *pool;
struct _WsbmMutex mutex;
struct _WsbmAtomic refCount;
struct _WsbmAtomic onList;
void *destroyArg;
void (*destroyContainer) (void *);
};
struct _WsbmKernelBuf;
struct _WsbmBufferPool
{
int fd;
int (*map) (struct _WsbmBufStorage * buf, unsigned mode, void **virtual);
void (*unmap) (struct _WsbmBufStorage * buf);
int (*syncforcpu) (struct _WsbmBufStorage * buf, unsigned mode,
int noBlock);
void (*releasefromcpu) (struct _WsbmBufStorage * buf, unsigned mode);
void (*destroy) (struct _WsbmBufStorage ** buf);
unsigned long (*offset) (struct _WsbmBufStorage * buf);
unsigned long (*poolOffset) (struct _WsbmBufStorage * buf);
uint32_t(*placement) (struct _WsbmBufStorage * buf);
unsigned long (*size) (struct _WsbmBufStorage * buf);
struct _WsbmKernelBuf *(*kernel) (struct _WsbmBufStorage * buf);
struct _WsbmBufStorage *(*create) (struct _WsbmBufferPool * pool,
unsigned long size,
uint32_t placement,
unsigned alignment,
int share,
int pin);
struct _WsbmBufStorage *(*createByReference) (struct _WsbmBufferPool *
pool, uint32_t handle);
void (*fence) (struct _WsbmBufStorage * buf,
struct _WsbmFenceObject * fence);
void (*unvalidate) (struct _WsbmBufStorage * buf);
int (*validate) (struct _WsbmBufStorage * buf, uint64_t set_flags,
uint64_t clr_flags);
int (*waitIdle) (struct _WsbmBufStorage * buf, int lazy);
int (*setAttr) (struct _WsbmBufStorage * buf,
uint32_t placement,
unsigned alignment,
int share,
int pin);
void (*takeDown) (struct _WsbmBufferPool * pool);
};
static inline int
wsbmBufStorageInit(struct _WsbmBufStorage *storage,
struct _WsbmBufferPool *pool)
{
int ret = WSBM_MUTEX_INIT(&storage->mutex);
if (ret)
return -ENOMEM;
storage->pool = pool;
wsbmAtomicSet(&storage->refCount, 1);
wsbmAtomicSet(&storage->onList, 0);
storage->destroyContainer = NULL;
return 0;
}
static inline void
wsbmBufStorageTakedown(struct _WsbmBufStorage *storage)
{
WSBM_MUTEX_FREE(&storage->mutex);
}
static inline void
wsbmBufStorageUnref(struct _WsbmBufStorage **pStorage)
{
struct _WsbmBufStorage *storage = *pStorage;
*pStorage = NULL;
if (storage == NULL)
return;
if (wsbmAtomicDecZero(&storage->refCount)) {
if (storage->destroyContainer)
storage->destroyContainer(storage->destroyArg);
storage->pool->destroy(&storage);
return;
}
}
/*
* Builtin pools.
*/
extern struct _WsbmBufferPool *wsbmMallocPoolInit(void);
struct _WsbmAttr;
struct _WsbmSlabCache;
extern struct _WsbmBufferPool *wsbmSlabPoolInit(int fd,
struct _WsbmBufferPool *basePool,
const struct _WsbmAttr *attr,
uint32_t smallestSize,
uint32_t numSizes,
uint32_t desiredNumBuffers,
uint32_t maxSlabSize,
struct _WsbmSlabCache *cache);
extern struct _WsbmSlabCache *wsbmSlabCacheInit(uint32_t checkIntervalMsec,
uint32_t slabTimeoutMsec);
extern void wsbmSlabCacheFinish(struct _WsbmSlabCache *cache);
extern struct _WsbmBufferPool *wsbmUserPoolInit(void *vramAddr,
unsigned long vramStart,
unsigned long vramSize,
void *agpAddr,
unsigned long agpStart,
unsigned long agpSize,
uint32_t system_flag,
uint32_t vram_flag,
uint32_t agp_flag,
uint32_t(*fenceTypes)
(uint64_t set_flags));
extern void wsbmUserPoolClean(struct _WsbmBufferPool *pool,
int cleanVram, int cleanAgp);
#endif
|