merge with master
[platform/upstream/libwsbm.git] / src / wsbm_manager.h
1 /**************************************************************************
2  *
3  * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA
4  * All Rights Reserved.
5  * Copyright 2009 Vmware, Inc., Palo Alto, CA., USA
6  * All Rights Reserved.
7  *
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:
15  *
16  * The above copyright notice and this permission notice (including the
17  * next paragraph) shall be included in all copies or substantial portions
18  * of the Software.
19  *
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.
27  *
28  **************************************************************************/
29 /*
30  * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
31  *          Keith Whitwell <keithw-at-tungstengraphics-dot-com>
32  */
33
34 #ifndef _WSBM_MANAGER_H_
35 #define _WSBM_MANAGER_H_
36 #include "wsbm_fencemgr.h"
37 #include "wsbm_util.h"
38 #include "wsbm_driver.h"
39
40 #define WSBM_VERSION_MAJOR 1
41 #define WSBM_VERSION_MINOR 1
42 #define WSBM_VERSION_PL 0
43
44 struct _WsbmFenceObject;
45 struct _WsbmBufferObject;
46 struct _WsbmBufferPool;
47 struct _WsbmBufferList;
48
49 /*
50  * These flags mimics the TTM closely, but since
51  * this library is not dependant on TTM, we need to
52  * replicate them here, and if there is a discrepancy,
53  * that needs to be resolved in the buffer pool using
54  * the TTM flags.
55  */
56
57 #define WSBM_PL_MASK_MEM         0x0000FFFF
58
59 #define WSBM_PL_FLAG_SYSTEM      (1 << 0)
60 #define WSBM_PL_FLAG_TT          (1 << 1)
61 #define WSBM_PL_FLAG_VRAM        (1 << 2)
62 #define WSBM_PL_FLAG_PRIV0       (1 << 3)
63 #define WSBM_PL_FLAG_SWAPPED     (1 << 15)
64 #define WSBM_PL_FLAG_CACHED      (1 << 16)
65 #define WSBM_PL_FLAG_UNCACHED    (1 << 17)
66 #define WSBM_PL_FLAG_WC          (1 << 18)
67 #define WSBM_PL_FLAG_SHARED      (1 << 20)
68 #define WSBM_PL_FLAG_NO_EVICT    (1 << 21)
69
70 #define WSBM_ACCESS_READ         (1 << 0)
71 #define WSBM_ACCESS_WRITE        (1 << 1)
72
73 #define WSBM_SYNCCPU_READ        WSBM_ACCESS_READ
74 #define WSBM_SYNCCPU_WRITE       WSBM_ACCESS_WRITE
75 #define WSBM_SYNCCPU_DONT_BLOCK  (1 << 2)
76 #define WSBM_SYNCCPU_TRY_CACHED  (1 << 3)
77
78 extern void *wsbmBOMap(struct _WsbmBufferObject *buf, unsigned mode);
79 extern void wsbmBOUnmap(struct _WsbmBufferObject *buf);
80 extern int wsbmBOSyncForCpu(struct _WsbmBufferObject *buf, unsigned mode);
81 extern void wsbmBOReleaseFromCpu(struct _WsbmBufferObject *buf,
82                                  unsigned mode);
83
84 extern unsigned long wsbmBOOffsetHint(struct _WsbmBufferObject *buf);
85 extern unsigned long wsbmBOPoolOffset(struct _WsbmBufferObject *buf);
86
87 extern uint32_t wsbmBOPlacementHint(struct _WsbmBufferObject *buf);
88 extern struct _WsbmBufferObject *wsbmBOReference(struct _WsbmBufferObject
89                                                  *buf);
90 extern void wsbmBOUnreference(struct _WsbmBufferObject **p_buf);
91
92 extern int wsbmBOData(struct _WsbmBufferObject *r_buf,
93                       unsigned size, const void *data,
94                       struct _WsbmBufferPool *pool, uint32_t placement);
95 extern int wsbmBOSetStatus(struct _WsbmBufferObject *buf,
96                            uint32_t setPlacement, uint32_t clrPlacement);
97 extern int wsbmBOSubData(struct _WsbmBufferObject *buf,
98                          unsigned long offset, unsigned long size,
99                          const void *data,
100                          int (*accelCopy) (struct _WsbmBufferObject *,
101                                            struct _WsbmBufferObject *));
102 extern struct _WsbmBufferObject *wsbmBOClone(struct _WsbmBufferObject *buf,
103                                              int (*accelCopy) (struct
104                                                                _WsbmBufferObject
105                                                                *,
106                                                                struct
107                                                                _WsbmBufferObject
108                                                                *));
109
110 extern int wsbmBOGetSubData(struct _WsbmBufferObject *buf,
111                             unsigned long offset, unsigned long size,
112                             void *data);
113 extern int wsbmGenBuffers(struct _WsbmBufferPool *pool,
114                           unsigned n,
115                           struct _WsbmBufferObject *buffers[],
116                           unsigned alignment, uint32_t placement);
117
118 struct _WsbmBufferObject *wsbmBOCreateSimple(struct _WsbmBufferPool *pool,
119                                              unsigned long size,
120                                              uint32_t placement,
121                                              unsigned alignment,
122                                              size_t extra_size,
123                                              size_t * offset);
124
125 extern void wsbmDeleteBuffers(unsigned n,
126                               struct _WsbmBufferObject *buffers[]);
127 extern struct _WsbmBufferList *wsbmBOCreateList(int target,
128                                                 int hasKernelBuffers);
129 extern int wsbmBOResetList(struct _WsbmBufferList *list);
130 extern int wsbmBOAddListItem(struct _WsbmBufferList *list,
131                              struct _WsbmBufferObject *buf,
132                              uint64_t flags, uint64_t mask, int *itemLoc,
133                              struct _ValidateNode **node);
134
135 extern void wsbmBOFreeList(struct _WsbmBufferList *list);
136 extern int wsbmBOFenceUserList(struct _WsbmBufferList *list,
137                                struct _WsbmFenceObject *fence);
138
139 extern int wsbmBOUnrefUserList(struct _WsbmBufferList *list);
140 extern int wsbmBOValidateUserList(struct _WsbmBufferList *list);
141 extern int wsbmBOUnvalidateUserList(struct _WsbmBufferList *list);
142
143 extern void wsbmBOFence(struct _WsbmBufferObject *buf,
144                         struct _WsbmFenceObject *fence);
145
146 extern void wsbmPoolTakeDown(struct _WsbmBufferPool *pool);
147 extern int wsbmBOSetReferenced(struct _WsbmBufferObject *buf,
148                                unsigned long handle);
149 unsigned long wsbmBOSize(struct _WsbmBufferObject *buf);
150 extern void wsbmBOWaitIdle(struct _WsbmBufferObject *buf, int lazy);
151 extern int wsbmBOOnList(const struct _WsbmBufferObject *buf);
152
153 extern void wsbmPoolTakeDown(struct _WsbmBufferPool *pool);
154
155 extern void wsbmReadLockKernelBO(void);
156 extern void wsbmReadUnlockKernelBO(void);
157 extern void wsbmWriteLockKernelBO(void);
158 extern void wsbmWriteUnlockKernelBO(void);
159
160 extern int wsbmInit(struct _WsbmThreadFuncs *tf, struct _WsbmVNodeFuncs *vf);
161 extern void wsbmTakedown(void);
162 extern int wsbmIsInitialized(void);
163 extern void wsbmCommonDataSet(void *d);
164 extern void *wsbmCommonDataGet(void);
165
166 extern struct _ValidateList *wsbmGetKernelValidateList(struct _WsbmBufferList
167                                                        *list);
168 extern struct _ValidateList *wsbmGetUserValidateList(struct _WsbmBufferList
169                                                      *list);
170
171 extern struct _ValidateNode *validateListNode(void *iterator);
172 extern void *validateListIterator(struct _ValidateList *list);
173 extern void *validateListNext(struct _ValidateList *list, void *iterator);
174
175 extern uint32_t wsbmKBufHandle(const struct _WsbmKernelBuf *);
176 extern void wsbmUpdateKBuf(struct _WsbmKernelBuf *,
177                            uint64_t gpuOffset,
178                            uint32_t placement, uint32_t fence_flags);
179
180 extern struct _WsbmKernelBuf *wsbmKBuf(const struct _WsbmBufferObject *buf);
181
182 #endif