ws_dri_mallocpool.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, TX., USA
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
00017  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
00018  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
00019  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
00020  * USE OR OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * The above copyright notice and this permission notice (including the
00023  * next paragraph) shall be included in all copies or substantial portions
00024  * of the Software.
00025  *
00026  *
00027  **************************************************************************/
00028 /*
00029  * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
00030  */
00031 
00032 #include <xf86drm.h>
00033 #include <stdlib.h>
00034 #include <errno.h>
00035 #include "pipe/p_debug.h"
00036 #include "pipe/p_thread.h"
00037 #include "ws_dri_bufpool.h"
00038 #include "ws_dri_bufmgr.h"
00039 
00040 static void *
00041 pool_create(struct _DriBufferPool *pool,
00042             unsigned long size, uint64_t flags, unsigned hint,
00043             unsigned alignment)
00044 {
00045     unsigned long *private = malloc(size + 2*sizeof(unsigned long));
00046     if ((flags & DRM_BO_MASK_MEM) != DRM_BO_FLAG_MEM_LOCAL)
00047       abort();
00048 
00049     *private = size;
00050     return (void *)private;
00051 }
00052 
00053 
00054 static int
00055 pool_destroy(struct _DriBufferPool *pool, void *private)
00056 {
00057     free(private);
00058     return 0;
00059 }
00060 
00061 static int
00062 pool_waitIdle(struct _DriBufferPool *pool, void *private,
00063               pipe_mutex *mutex, int lazy)
00064 {
00065     return 0;
00066 }
00067 
00068 static int
00069 pool_map(struct _DriBufferPool *pool, void *private, unsigned flags,
00070          int hint, pipe_mutex *mutex, void **virtual)
00071 {
00072     *virtual = (void *)((unsigned long *)private + 2);
00073     return 0;
00074 }
00075 
00076 static int
00077 pool_unmap(struct _DriBufferPool *pool, void *private)
00078 {
00079     return 0;
00080 }
00081 
00082 static unsigned long
00083 pool_offset(struct _DriBufferPool *pool, void *private)
00084 {
00085     /*
00086      * BUG
00087      */
00088     abort();
00089     return 0UL;
00090 }
00091 
00092 static unsigned long
00093 pool_poolOffset(struct _DriBufferPool *pool, void *private)
00094 {
00095     /*
00096      * BUG
00097      */
00098     abort();
00099 }
00100 
00101 static uint64_t
00102 pool_flags(struct _DriBufferPool *pool, void *private)
00103 {
00104     return DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_CACHED;
00105 }
00106 
00107 static unsigned long
00108 pool_size(struct _DriBufferPool *pool, void *private)
00109 {
00110     return *(unsigned long *) private;
00111 }
00112 
00113 
00114 static int
00115 pool_fence(struct _DriBufferPool *pool, void *private,
00116            struct _DriFenceObject *fence)
00117 {
00118     abort();
00119     return 0UL;
00120 }
00121 
00122 static drmBO *
00123 pool_kernel(struct _DriBufferPool *pool, void *private)
00124 {
00125     abort();
00126     return NULL;
00127 }
00128 
00129 static void
00130 pool_takedown(struct _DriBufferPool *pool)
00131 {
00132     free(pool);
00133 }
00134 
00135 
00136 struct _DriBufferPool *
00137 driMallocPoolInit(void)
00138 {
00139    struct _DriBufferPool *pool;
00140 
00141    pool = (struct _DriBufferPool *) malloc(sizeof(*pool));
00142    if (!pool)
00143        return NULL;
00144 
00145    pool->data = NULL;
00146    pool->fd = -1;
00147    pool->map = &pool_map;
00148    pool->unmap = &pool_unmap;
00149    pool->destroy = &pool_destroy;
00150    pool->offset = &pool_offset;
00151    pool->poolOffset = &pool_poolOffset;
00152    pool->flags = &pool_flags;
00153    pool->size = &pool_size;
00154    pool->create = &pool_create;
00155    pool->fence = &pool_fence;
00156    pool->kernel = &pool_kernel;
00157    pool->validate = NULL;
00158    pool->waitIdle = &pool_waitIdle;
00159    pool->takeDown = &pool_takedown;
00160    return pool;
00161 }

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4