183827f40a2d97261528087331b0bee6ce2cf27c5root/************************************************************************** 283827f40a2d97261528087331b0bee6ce2cf27c5root * 383827f40a2d97261528087331b0bee6ce2cf27c5root * Copyright 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#ifdef HAVE_CONFIG_H 3483827f40a2d97261528087331b0bee6ce2cf27c5root#include "config.h" 3583827f40a2d97261528087331b0bee6ce2cf27c5root#endif 3683827f40a2d97261528087331b0bee6ce2cf27c5root 3783827f40a2d97261528087331b0bee6ce2cf27c5root#include <stdlib.h> 3883827f40a2d97261528087331b0bee6ce2cf27c5root#include <errno.h> 3983827f40a2d97261528087331b0bee6ce2cf27c5root#include "wsbm_pool.h" 4083827f40a2d97261528087331b0bee6ce2cf27c5root#include "wsbm_manager.h" 4183827f40a2d97261528087331b0bee6ce2cf27c5root 4283827f40a2d97261528087331b0bee6ce2cf27c5rootstruct _WsbmMallocBuffer 4383827f40a2d97261528087331b0bee6ce2cf27c5root{ 4483827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmBufStorage buf; 4583827f40a2d97261528087331b0bee6ce2cf27c5root size_t size; 4683827f40a2d97261528087331b0bee6ce2cf27c5root void *mem; 4783827f40a2d97261528087331b0bee6ce2cf27c5root}; 4883827f40a2d97261528087331b0bee6ce2cf27c5root 4983827f40a2d97261528087331b0bee6ce2cf27c5rootstatic inline struct _WsbmMallocBuffer * 5083827f40a2d97261528087331b0bee6ce2cf27c5rootmallocBuf(struct _WsbmBufStorage *buf) 5183827f40a2d97261528087331b0bee6ce2cf27c5root{ 5283827f40a2d97261528087331b0bee6ce2cf27c5root return containerOf(buf, struct _WsbmMallocBuffer, buf); 5383827f40a2d97261528087331b0bee6ce2cf27c5root} 5483827f40a2d97261528087331b0bee6ce2cf27c5root 5583827f40a2d97261528087331b0bee6ce2cf27c5rootstatic struct _WsbmBufStorage * 5683827f40a2d97261528087331b0bee6ce2cf27c5rootpool_create(struct _WsbmBufferPool *pool, 573795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudel unsigned long size, uint32_t placement, unsigned alignment __attribute__ ((unused))) 5883827f40a2d97261528087331b0bee6ce2cf27c5root{ 5983827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmMallocBuffer *mBuf = malloc(size + sizeof(*mBuf) + 16); 6083827f40a2d97261528087331b0bee6ce2cf27c5root 6183827f40a2d97261528087331b0bee6ce2cf27c5root if (!mBuf) 6283827f40a2d97261528087331b0bee6ce2cf27c5root return NULL; 6383827f40a2d97261528087331b0bee6ce2cf27c5root 6483827f40a2d97261528087331b0bee6ce2cf27c5root wsbmBufStorageInit(&mBuf->buf, pool); 6583827f40a2d97261528087331b0bee6ce2cf27c5root mBuf->size = size; 6683827f40a2d97261528087331b0bee6ce2cf27c5root mBuf->mem = (void *)((unsigned long)mBuf + sizeof(*mBuf)); 6783827f40a2d97261528087331b0bee6ce2cf27c5root if ((placement & WSBM_PL_MASK_MEM) != WSBM_PL_FLAG_SYSTEM) 6883827f40a2d97261528087331b0bee6ce2cf27c5root abort(); 6983827f40a2d97261528087331b0bee6ce2cf27c5root 7083827f40a2d97261528087331b0bee6ce2cf27c5root return &mBuf->buf; 7183827f40a2d97261528087331b0bee6ce2cf27c5root} 7283827f40a2d97261528087331b0bee6ce2cf27c5root 7383827f40a2d97261528087331b0bee6ce2cf27c5rootstatic void 7483827f40a2d97261528087331b0bee6ce2cf27c5rootpool_destroy(struct _WsbmBufStorage **buf) 7583827f40a2d97261528087331b0bee6ce2cf27c5root{ 7683827f40a2d97261528087331b0bee6ce2cf27c5root free(mallocBuf(*buf)); 7783827f40a2d97261528087331b0bee6ce2cf27c5root *buf = NULL; 7883827f40a2d97261528087331b0bee6ce2cf27c5root} 7983827f40a2d97261528087331b0bee6ce2cf27c5root 8083827f40a2d97261528087331b0bee6ce2cf27c5rootstatic int 813795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_waitIdle(struct _WsbmBufStorage *buf __attribute__ ((unused)), int lazy __attribute__ ((unused))) 8283827f40a2d97261528087331b0bee6ce2cf27c5root{ 8383827f40a2d97261528087331b0bee6ce2cf27c5root return 0; 8483827f40a2d97261528087331b0bee6ce2cf27c5root} 8583827f40a2d97261528087331b0bee6ce2cf27c5root 8683827f40a2d97261528087331b0bee6ce2cf27c5rootstatic int 873795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_map(struct _WsbmBufStorage *buf, unsigned mode __attribute__ ((unused)), void **virtual __attribute__ ((unused))) 8883827f40a2d97261528087331b0bee6ce2cf27c5root{ 8983827f40a2d97261528087331b0bee6ce2cf27c5root *virtual = mallocBuf(buf)->mem; 9083827f40a2d97261528087331b0bee6ce2cf27c5root return 0; 9183827f40a2d97261528087331b0bee6ce2cf27c5root} 9283827f40a2d97261528087331b0bee6ce2cf27c5root 9383827f40a2d97261528087331b0bee6ce2cf27c5rootstatic void 943795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_unmap(struct _WsbmBufStorage *buf __attribute__ ((unused))) 9583827f40a2d97261528087331b0bee6ce2cf27c5root{ 9683827f40a2d97261528087331b0bee6ce2cf27c5root ; 9783827f40a2d97261528087331b0bee6ce2cf27c5root} 9883827f40a2d97261528087331b0bee6ce2cf27c5root 9983827f40a2d97261528087331b0bee6ce2cf27c5rootstatic int 1003795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_syncforcpu(struct _WsbmBufStorage *buf __attribute__ ((unused)), unsigned mode __attribute__ ((unused))) 10183827f40a2d97261528087331b0bee6ce2cf27c5root{ 10283827f40a2d97261528087331b0bee6ce2cf27c5root return 0; 10383827f40a2d97261528087331b0bee6ce2cf27c5root} 10483827f40a2d97261528087331b0bee6ce2cf27c5root 10583827f40a2d97261528087331b0bee6ce2cf27c5rootstatic void 1063795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_releasefromcpu(struct _WsbmBufStorage *buf __attribute__ ((unused)), unsigned mode __attribute__ ((unused))) 10783827f40a2d97261528087331b0bee6ce2cf27c5root{ 10883827f40a2d97261528087331b0bee6ce2cf27c5root ; 10983827f40a2d97261528087331b0bee6ce2cf27c5root} 11083827f40a2d97261528087331b0bee6ce2cf27c5root 11183827f40a2d97261528087331b0bee6ce2cf27c5rootstatic unsigned long 1123795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_offset(struct _WsbmBufStorage *buf __attribute__ ((unused))) 11383827f40a2d97261528087331b0bee6ce2cf27c5root{ 11483827f40a2d97261528087331b0bee6ce2cf27c5root /* 11583827f40a2d97261528087331b0bee6ce2cf27c5root * BUG 11683827f40a2d97261528087331b0bee6ce2cf27c5root */ 11783827f40a2d97261528087331b0bee6ce2cf27c5root abort(); 11883827f40a2d97261528087331b0bee6ce2cf27c5root return 0UL; 11983827f40a2d97261528087331b0bee6ce2cf27c5root} 12083827f40a2d97261528087331b0bee6ce2cf27c5root 12183827f40a2d97261528087331b0bee6ce2cf27c5rootstatic unsigned long 1223795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_poolOffset(struct _WsbmBufStorage *buf __attribute__ ((unused))) 12383827f40a2d97261528087331b0bee6ce2cf27c5root{ 12483827f40a2d97261528087331b0bee6ce2cf27c5root /* 12583827f40a2d97261528087331b0bee6ce2cf27c5root * BUG 12683827f40a2d97261528087331b0bee6ce2cf27c5root */ 12783827f40a2d97261528087331b0bee6ce2cf27c5root abort(); 12883827f40a2d97261528087331b0bee6ce2cf27c5root} 12983827f40a2d97261528087331b0bee6ce2cf27c5root 13083827f40a2d97261528087331b0bee6ce2cf27c5rootstatic uint32_t 1313795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_placement(struct _WsbmBufStorage *buf __attribute__ ((unused))) 13283827f40a2d97261528087331b0bee6ce2cf27c5root{ 13383827f40a2d97261528087331b0bee6ce2cf27c5root return WSBM_PL_FLAG_SYSTEM | WSBM_PL_FLAG_CACHED; 13483827f40a2d97261528087331b0bee6ce2cf27c5root} 13583827f40a2d97261528087331b0bee6ce2cf27c5root 13683827f40a2d97261528087331b0bee6ce2cf27c5rootstatic unsigned long 13783827f40a2d97261528087331b0bee6ce2cf27c5rootpool_size(struct _WsbmBufStorage *buf) 13883827f40a2d97261528087331b0bee6ce2cf27c5root{ 13983827f40a2d97261528087331b0bee6ce2cf27c5root return mallocBuf(buf)->size; 14083827f40a2d97261528087331b0bee6ce2cf27c5root} 14183827f40a2d97261528087331b0bee6ce2cf27c5root 14283827f40a2d97261528087331b0bee6ce2cf27c5rootstatic void 1433795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_fence(struct _WsbmBufStorage *buf __attribute__ ((unused)), struct _WsbmFenceObject *fence __attribute__ ((unused))) 14483827f40a2d97261528087331b0bee6ce2cf27c5root{ 14583827f40a2d97261528087331b0bee6ce2cf27c5root abort(); 14683827f40a2d97261528087331b0bee6ce2cf27c5root} 14783827f40a2d97261528087331b0bee6ce2cf27c5root 14883827f40a2d97261528087331b0bee6ce2cf27c5rootstatic struct _WsbmKernelBuf * 1493795b36d0c937666a5bddc352c781d5e0beec26bThierry Strudelpool_kernel(struct _WsbmBufStorage *buf __attribute__ ((unused))) 15083827f40a2d97261528087331b0bee6ce2cf27c5root{ 15183827f40a2d97261528087331b0bee6ce2cf27c5root abort(); 15283827f40a2d97261528087331b0bee6ce2cf27c5root return NULL; 15383827f40a2d97261528087331b0bee6ce2cf27c5root} 15483827f40a2d97261528087331b0bee6ce2cf27c5root 15583827f40a2d97261528087331b0bee6ce2cf27c5rootstatic void 15683827f40a2d97261528087331b0bee6ce2cf27c5rootpool_takedown(struct _WsbmBufferPool *pool) 15783827f40a2d97261528087331b0bee6ce2cf27c5root{ 15883827f40a2d97261528087331b0bee6ce2cf27c5root free(pool); 15983827f40a2d97261528087331b0bee6ce2cf27c5root} 16083827f40a2d97261528087331b0bee6ce2cf27c5root 16183827f40a2d97261528087331b0bee6ce2cf27c5rootstruct _WsbmBufferPool * 16283827f40a2d97261528087331b0bee6ce2cf27c5rootwsbmMallocPoolInit(void) 16383827f40a2d97261528087331b0bee6ce2cf27c5root{ 16483827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmBufferPool *pool; 16583827f40a2d97261528087331b0bee6ce2cf27c5root 16683827f40a2d97261528087331b0bee6ce2cf27c5root pool = (struct _WsbmBufferPool *)calloc(1, sizeof(*pool)); 16783827f40a2d97261528087331b0bee6ce2cf27c5root if (!pool) 16883827f40a2d97261528087331b0bee6ce2cf27c5root return NULL; 16983827f40a2d97261528087331b0bee6ce2cf27c5root 17083827f40a2d97261528087331b0bee6ce2cf27c5root pool->fd = -1; 17183827f40a2d97261528087331b0bee6ce2cf27c5root pool->map = &pool_map; 17283827f40a2d97261528087331b0bee6ce2cf27c5root pool->unmap = &pool_unmap; 17383827f40a2d97261528087331b0bee6ce2cf27c5root pool->syncforcpu = &pool_syncforcpu; 17483827f40a2d97261528087331b0bee6ce2cf27c5root pool->releasefromcpu = &pool_releasefromcpu; 17583827f40a2d97261528087331b0bee6ce2cf27c5root pool->destroy = &pool_destroy; 17683827f40a2d97261528087331b0bee6ce2cf27c5root pool->offset = &pool_offset; 17783827f40a2d97261528087331b0bee6ce2cf27c5root pool->poolOffset = &pool_poolOffset; 17883827f40a2d97261528087331b0bee6ce2cf27c5root pool->placement = &pool_placement; 17983827f40a2d97261528087331b0bee6ce2cf27c5root pool->size = &pool_size; 18083827f40a2d97261528087331b0bee6ce2cf27c5root pool->create = &pool_create; 18183827f40a2d97261528087331b0bee6ce2cf27c5root pool->fence = &pool_fence; 18283827f40a2d97261528087331b0bee6ce2cf27c5root pool->kernel = &pool_kernel; 18383827f40a2d97261528087331b0bee6ce2cf27c5root pool->validate = NULL; 18483827f40a2d97261528087331b0bee6ce2cf27c5root pool->waitIdle = &pool_waitIdle; 18583827f40a2d97261528087331b0bee6ce2cf27c5root pool->takeDown = &pool_takedown; 18683827f40a2d97261528087331b0bee6ce2cf27c5root return pool; 18783827f40a2d97261528087331b0bee6ce2cf27c5root} 188