183827f40a2d97261528087331b0bee6ce2cf27c5root/************************************************************************** 283827f40a2d97261528087331b0bee6ce2cf27c5root * 383827f40a2d97261528087331b0bee6ce2cf27c5root * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA 483827f40a2d97261528087331b0bee6ce2cf27c5root * All Rights Reserved. 583827f40a2d97261528087331b0bee6ce2cf27c5root * Copyright 2009 VMware, Inc., Palo Alto, CA., USA 683827f40a2d97261528087331b0bee6ce2cf27c5root * All Rights Reserved. 783827f40a2d97261528087331b0bee6ce2cf27c5root * 883827f40a2d97261528087331b0bee6ce2cf27c5root * Permission is hereby granted, free of charge, to any person obtaining a 983827f40a2d97261528087331b0bee6ce2cf27c5root * copy of this software and associated documentation files (the 1083827f40a2d97261528087331b0bee6ce2cf27c5root * "Software"), to deal in the Software without restriction, including 1183827f40a2d97261528087331b0bee6ce2cf27c5root * without limitation the rights to use, copy, modify, merge, publish, 1283827f40a2d97261528087331b0bee6ce2cf27c5root * distribute, sub license, and/or sell copies of the Software, and to 1383827f40a2d97261528087331b0bee6ce2cf27c5root * permit persons to whom the Software is furnished to do so, subject to 1483827f40a2d97261528087331b0bee6ce2cf27c5root * the following conditions: 1583827f40a2d97261528087331b0bee6ce2cf27c5root * 1683827f40a2d97261528087331b0bee6ce2cf27c5root * The above copyright notice and this permission notice (including the 1783827f40a2d97261528087331b0bee6ce2cf27c5root * next paragraph) shall be included in all copies or substantial portions 1883827f40a2d97261528087331b0bee6ce2cf27c5root * of the Software. 1983827f40a2d97261528087331b0bee6ce2cf27c5root * 2083827f40a2d97261528087331b0bee6ce2cf27c5root * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2183827f40a2d97261528087331b0bee6ce2cf27c5root * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2283827f40a2d97261528087331b0bee6ce2cf27c5root * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 2383827f40a2d97261528087331b0bee6ce2cf27c5root * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 2483827f40a2d97261528087331b0bee6ce2cf27c5root * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2583827f40a2d97261528087331b0bee6ce2cf27c5root * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2683827f40a2d97261528087331b0bee6ce2cf27c5root * USE OR OTHER DEALINGS IN THE SOFTWARE. 2783827f40a2d97261528087331b0bee6ce2cf27c5root * 2883827f40a2d97261528087331b0bee6ce2cf27c5root **************************************************************************/ 2983827f40a2d97261528087331b0bee6ce2cf27c5root/* 3083827f40a2d97261528087331b0bee6ce2cf27c5root * Authors: Thomas Hellstr�m <thomas-at-tungstengraphics-dot-com> 3183827f40a2d97261528087331b0bee6ce2cf27c5root */ 3283827f40a2d97261528087331b0bee6ce2cf27c5root 3383827f40a2d97261528087331b0bee6ce2cf27c5root#ifndef _WSBM_BUFPOOL_H_ 3483827f40a2d97261528087331b0bee6ce2cf27c5root#define _WSBM_BUFPOOL_H_ 3583827f40a2d97261528087331b0bee6ce2cf27c5root 3683827f40a2d97261528087331b0bee6ce2cf27c5root#include <errno.h> 3783827f40a2d97261528087331b0bee6ce2cf27c5root#include "wsbm_util.h" 3883827f40a2d97261528087331b0bee6ce2cf27c5root#include "wsbm_driver.h" 3983827f40a2d97261528087331b0bee6ce2cf27c5root#include "wsbm_atomic.h" 4083827f40a2d97261528087331b0bee6ce2cf27c5root 4183827f40a2d97261528087331b0bee6ce2cf27c5rootstruct _WsbmFenceObject; 4283827f40a2d97261528087331b0bee6ce2cf27c5root 4383827f40a2d97261528087331b0bee6ce2cf27c5rootstruct _WsbmBufStorage 4483827f40a2d97261528087331b0bee6ce2cf27c5root{ 4583827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmBufferPool *pool; 4683827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmMutex mutex; 4783827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmAtomic refCount; 4883827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmAtomic onList; 4983827f40a2d97261528087331b0bee6ce2cf27c5root void *destroyArg; 5083827f40a2d97261528087331b0bee6ce2cf27c5root void (*destroyContainer) (void *); 5183827f40a2d97261528087331b0bee6ce2cf27c5root}; 5283827f40a2d97261528087331b0bee6ce2cf27c5root 5383827f40a2d97261528087331b0bee6ce2cf27c5rootstruct _WsbmKernelBuf; 5483827f40a2d97261528087331b0bee6ce2cf27c5root 5583827f40a2d97261528087331b0bee6ce2cf27c5rootstruct _WsbmBufferPool 5683827f40a2d97261528087331b0bee6ce2cf27c5root{ 5783827f40a2d97261528087331b0bee6ce2cf27c5root int fd; 5883827f40a2d97261528087331b0bee6ce2cf27c5root int (*map) (struct _WsbmBufStorage * buf, unsigned mode, void **virtual); 5983827f40a2d97261528087331b0bee6ce2cf27c5root void (*unmap) (struct _WsbmBufStorage * buf); 6083827f40a2d97261528087331b0bee6ce2cf27c5root int (*syncforcpu) (struct _WsbmBufStorage * buf, unsigned mode); 6183827f40a2d97261528087331b0bee6ce2cf27c5root void (*releasefromcpu) (struct _WsbmBufStorage * buf, unsigned mode); 6283827f40a2d97261528087331b0bee6ce2cf27c5root void (*destroy) (struct _WsbmBufStorage ** buf); 6383827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long (*offset) (struct _WsbmBufStorage * buf); 6483827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long (*poolOffset) (struct _WsbmBufStorage * buf); 6583827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t(*placement) (struct _WsbmBufStorage * buf); 6683827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long (*size) (struct _WsbmBufStorage * buf); 6783827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmKernelBuf *(*kernel) (struct _WsbmBufStorage * buf); 6883827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmBufStorage *(*create) (struct _WsbmBufferPool * pool, 6983827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long size, 7083827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t placement, 7183827f40a2d97261528087331b0bee6ce2cf27c5root unsigned alignment); 7283827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmBufStorage *(*createByReference) (struct _WsbmBufferPool * 7383827f40a2d97261528087331b0bee6ce2cf27c5root pool, uint32_t handle); 7483827f40a2d97261528087331b0bee6ce2cf27c5root void (*fence) (struct _WsbmBufStorage * buf, 7583827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmFenceObject * fence); 7683827f40a2d97261528087331b0bee6ce2cf27c5root void (*unvalidate) (struct _WsbmBufStorage * buf); 7783827f40a2d97261528087331b0bee6ce2cf27c5root int (*validate) (struct _WsbmBufStorage * buf, uint64_t set_flags, 7883827f40a2d97261528087331b0bee6ce2cf27c5root uint64_t clr_flags); 7983827f40a2d97261528087331b0bee6ce2cf27c5root int (*waitIdle) (struct _WsbmBufStorage * buf, int lazy); 8083827f40a2d97261528087331b0bee6ce2cf27c5root int (*setStatus) (struct _WsbmBufStorage * buf, 8183827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t set_placement, uint32_t clr_placement); 8283827f40a2d97261528087331b0bee6ce2cf27c5root void (*takeDown) (struct _WsbmBufferPool * pool); 8383827f40a2d97261528087331b0bee6ce2cf27c5root}; 8483827f40a2d97261528087331b0bee6ce2cf27c5root 8583827f40a2d97261528087331b0bee6ce2cf27c5rootstatic inline int 8683827f40a2d97261528087331b0bee6ce2cf27c5rootwsbmBufStorageInit(struct _WsbmBufStorage *storage, 8783827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmBufferPool *pool) 8883827f40a2d97261528087331b0bee6ce2cf27c5root{ 8983827f40a2d97261528087331b0bee6ce2cf27c5root int ret = WSBM_MUTEX_INIT(&storage->mutex); 9083827f40a2d97261528087331b0bee6ce2cf27c5root 9183827f40a2d97261528087331b0bee6ce2cf27c5root if (ret) 9283827f40a2d97261528087331b0bee6ce2cf27c5root return -ENOMEM; 9383827f40a2d97261528087331b0bee6ce2cf27c5root storage->pool = pool; 9483827f40a2d97261528087331b0bee6ce2cf27c5root wsbmAtomicSet(&storage->refCount, 1); 9583827f40a2d97261528087331b0bee6ce2cf27c5root wsbmAtomicSet(&storage->onList, 0); 9683827f40a2d97261528087331b0bee6ce2cf27c5root storage->destroyContainer = NULL; 9783827f40a2d97261528087331b0bee6ce2cf27c5root return 0; 9883827f40a2d97261528087331b0bee6ce2cf27c5root} 9983827f40a2d97261528087331b0bee6ce2cf27c5root 10083827f40a2d97261528087331b0bee6ce2cf27c5rootstatic inline void 10183827f40a2d97261528087331b0bee6ce2cf27c5rootwsbmBufStorageTakedown(struct _WsbmBufStorage *storage) 10283827f40a2d97261528087331b0bee6ce2cf27c5root{ 10383827f40a2d97261528087331b0bee6ce2cf27c5root WSBM_MUTEX_FREE(&storage->mutex); 10483827f40a2d97261528087331b0bee6ce2cf27c5root} 10583827f40a2d97261528087331b0bee6ce2cf27c5root 10683827f40a2d97261528087331b0bee6ce2cf27c5rootstatic inline void 10783827f40a2d97261528087331b0bee6ce2cf27c5rootwsbmBufStorageUnref(struct _WsbmBufStorage **pStorage) 10883827f40a2d97261528087331b0bee6ce2cf27c5root{ 10983827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmBufStorage *storage = *pStorage; 11083827f40a2d97261528087331b0bee6ce2cf27c5root 11183827f40a2d97261528087331b0bee6ce2cf27c5root *pStorage = NULL; 11283827f40a2d97261528087331b0bee6ce2cf27c5root if (storage == NULL) 11383827f40a2d97261528087331b0bee6ce2cf27c5root return; 11483827f40a2d97261528087331b0bee6ce2cf27c5root 11583827f40a2d97261528087331b0bee6ce2cf27c5root if (wsbmAtomicDecZero(&storage->refCount)) { 11683827f40a2d97261528087331b0bee6ce2cf27c5root if (storage->destroyContainer) 11783827f40a2d97261528087331b0bee6ce2cf27c5root storage->destroyContainer(storage->destroyArg); 11883827f40a2d97261528087331b0bee6ce2cf27c5root storage->pool->destroy(&storage); 11983827f40a2d97261528087331b0bee6ce2cf27c5root return; 12083827f40a2d97261528087331b0bee6ce2cf27c5root } 12183827f40a2d97261528087331b0bee6ce2cf27c5root} 12283827f40a2d97261528087331b0bee6ce2cf27c5root 12383827f40a2d97261528087331b0bee6ce2cf27c5root/* 12483827f40a2d97261528087331b0bee6ce2cf27c5root * Builtin pools. 12583827f40a2d97261528087331b0bee6ce2cf27c5root */ 12683827f40a2d97261528087331b0bee6ce2cf27c5root 12783827f40a2d97261528087331b0bee6ce2cf27c5root/* 12883827f40a2d97261528087331b0bee6ce2cf27c5root * Kernel buffer objects. Size in multiples of page size. Page size aligned. 12983827f40a2d97261528087331b0bee6ce2cf27c5root */ 13083827f40a2d97261528087331b0bee6ce2cf27c5root 13183827f40a2d97261528087331b0bee6ce2cf27c5rootextern struct _WsbmBufferPool *wsbmTTMPoolInit(int fd, 13283827f40a2d97261528087331b0bee6ce2cf27c5root unsigned int devOffset); 13383827f40a2d97261528087331b0bee6ce2cf27c5rootextern struct _WsbmBufferPool *wsbmMallocPoolInit(void); 13483827f40a2d97261528087331b0bee6ce2cf27c5root 13583827f40a2d97261528087331b0bee6ce2cf27c5rootstruct _WsbmSlabCache; 13683827f40a2d97261528087331b0bee6ce2cf27c5rootextern struct _WsbmBufferPool *wsbmSlabPoolInit(int fd, uint32_t devOffset, 13783827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t placement, 13883827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t validMask, 13983827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t smallestSize, 14083827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t numSizes, 14183827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t desiredNumBuffers, 14283827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t maxSlabSize, 14383827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t pageAlignment, 14483827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmSlabCache *cache); 14583827f40a2d97261528087331b0bee6ce2cf27c5rootextern struct _WsbmSlabCache *wsbmSlabCacheInit(uint32_t checkIntervalMsec, 14683827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t slabTimeoutMsec); 14783827f40a2d97261528087331b0bee6ce2cf27c5rootextern void wsbmSlabCacheFinish(struct _WsbmSlabCache *cache); 14883827f40a2d97261528087331b0bee6ce2cf27c5root 14983827f40a2d97261528087331b0bee6ce2cf27c5rootextern struct _WsbmBufferPool *wsbmUserPoolInit(void *vramAddr, 15083827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long vramStart, 15183827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long vramSize, 15283827f40a2d97261528087331b0bee6ce2cf27c5root void *agpAddr, 15383827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long agpStart, 15483827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long agpSize, 15583827f40a2d97261528087331b0bee6ce2cf27c5root uint32_t(*fenceTypes) 15683827f40a2d97261528087331b0bee6ce2cf27c5root (uint64_t set_flags)); 15783827f40a2d97261528087331b0bee6ce2cf27c5root 15883827f40a2d97261528087331b0bee6ce2cf27c5rootextern void wsbmUserPoolClean(struct _WsbmBufferPool *pool, 15983827f40a2d97261528087331b0bee6ce2cf27c5root int cleanVram, int cleanAgp); 16083827f40a2d97261528087331b0bee6ce2cf27c5root 16183827f40a2d97261528087331b0bee6ce2cf27c5root#endif 162