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 Hellstrm <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 96 extern int wsbmBODataUB(struct _WsbmBufferObject *buf, 97 unsigned size, const void *data, struct _WsbmBufferPool *newPool, 98 uint32_t placement, const unsigned long *user_ptr, int fd); 99 100 extern int wsbmBOSetStatus(struct _WsbmBufferObject *buf, 101 uint32_t setPlacement, uint32_t clrPlacement); 102 extern int wsbmBOSubData(struct _WsbmBufferObject *buf, 103 unsigned long offset, unsigned long size, 104 const void *data, 105 int (*accelCopy) (struct _WsbmBufferObject *, 106 struct _WsbmBufferObject *)); 107 extern struct _WsbmBufferObject *wsbmBOClone(struct _WsbmBufferObject *buf, 108 int (*accelCopy) (struct 109 _WsbmBufferObject 110 *, 111 struct 112 _WsbmBufferObject 113 *)); 114 115 extern int wsbmBOGetSubData(struct _WsbmBufferObject *buf, 116 unsigned long offset, unsigned long size, 117 void *data); 118 extern int wsbmGenBuffers(struct _WsbmBufferPool *pool, 119 unsigned n, 120 struct _WsbmBufferObject *buffers[], 121 unsigned alignment, uint32_t placement); 122 123 struct _WsbmBufferObject *wsbmBOCreateSimple(struct _WsbmBufferPool *pool, 124 unsigned long size, 125 uint32_t placement, 126 unsigned alignment, 127 size_t extra_size, 128 size_t * offset); 129 130 extern void wsbmDeleteBuffers(unsigned n, 131 struct _WsbmBufferObject *buffers[]); 132 extern struct _WsbmBufferList *wsbmBOCreateList(int target, 133 int hasKernelBuffers); 134 extern int wsbmBOResetList(struct _WsbmBufferList *list); 135 extern int wsbmBOAddListItem(struct _WsbmBufferList *list, 136 struct _WsbmBufferObject *buf, 137 uint64_t flags, uint64_t mask, int *itemLoc, 138 struct _ValidateNode **node); 139 140 extern void wsbmBOFreeList(struct _WsbmBufferList *list); 141 extern int wsbmBOFenceUserList(struct _WsbmBufferList *list, 142 struct _WsbmFenceObject *fence); 143 144 extern int wsbmBOUnrefUserList(struct _WsbmBufferList *list); 145 extern int wsbmBOValidateUserList(struct _WsbmBufferList *list); 146 extern int wsbmBOUnvalidateUserList(struct _WsbmBufferList *list); 147 148 extern void wsbmBOFence(struct _WsbmBufferObject *buf, 149 struct _WsbmFenceObject *fence); 150 151 extern void wsbmPoolTakeDown(struct _WsbmBufferPool *pool); 152 extern int wsbmBOSetReferenced(struct _WsbmBufferObject *buf, 153 unsigned long handle); 154 unsigned long wsbmBOSize(struct _WsbmBufferObject *buf); 155 extern void wsbmBOWaitIdle(struct _WsbmBufferObject *buf, int lazy); 156 extern int wsbmBOOnList(const struct _WsbmBufferObject *buf); 157 158 extern void wsbmPoolTakeDown(struct _WsbmBufferPool *pool); 159 160 extern void wsbmReadLockKernelBO(void); 161 extern void wsbmReadUnlockKernelBO(void); 162 extern void wsbmWriteLockKernelBO(void); 163 extern void wsbmWriteUnlockKernelBO(void); 164 165 extern int wsbmInit(struct _WsbmThreadFuncs *tf, struct _WsbmVNodeFuncs *vf); 166 extern void wsbmTakedown(void); 167 extern int wsbmIsInitialized(void); 168 extern void wsbmCommonDataSet(void *d); 169 extern void *wsbmCommonDataGet(void); 170 171 extern struct _ValidateList *wsbmGetKernelValidateList(struct _WsbmBufferList 172 *list); 173 extern struct _ValidateList *wsbmGetUserValidateList(struct _WsbmBufferList 174 *list); 175 176 extern struct _ValidateNode *validateListNode(void *iterator); 177 extern void *validateListIterator(struct _ValidateList *list); 178 extern void *validateListNext(struct _ValidateList *list, void *iterator); 179 180 extern uint32_t wsbmKBufHandle(const struct _WsbmKernelBuf *); 181 extern void wsbmUpdateKBuf(struct _WsbmKernelBuf *, 182 uint64_t gpuOffset, 183 uint32_t placement, uint32_t fence_flags); 184 185 extern struct _WsbmKernelBuf *wsbmKBuf(const struct _WsbmBufferObject *buf); 186 187 #endif 188