00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <xf86drm.h>
00033 #include <stdlib.h>
00034 #include <unistd.h>
00035 #include "ws_dri_bufpool.h"
00036 #include "ws_dri_bufmgr.h"
00037 #include "assert.h"
00038
00039
00040
00041
00042
00043 static void *
00044 pool_create(struct _DriBufferPool *pool,
00045 unsigned long size, uint64_t flags, unsigned hint,
00046 unsigned alignment)
00047 {
00048 drmBO *buf = (drmBO *) malloc(sizeof(*buf));
00049 int ret;
00050 unsigned pageSize = getpagesize();
00051
00052 if (!buf)
00053 return NULL;
00054
00055 if ((alignment > pageSize) && (alignment % pageSize)) {
00056 free(buf);
00057 return NULL;
00058 }
00059
00060 ret = drmBOCreate(pool->fd, size, alignment / pageSize,
00061 NULL,
00062 flags, hint, buf);
00063 if (ret) {
00064 free(buf);
00065 return NULL;
00066 }
00067
00068 return (void *) buf;
00069 }
00070
00071 static void *
00072 pool_reference(struct _DriBufferPool *pool, unsigned handle)
00073 {
00074 drmBO *buf = (drmBO *) malloc(sizeof(*buf));
00075 int ret;
00076
00077 if (!buf)
00078 return NULL;
00079
00080 ret = drmBOReference(pool->fd, handle, buf);
00081
00082 if (ret) {
00083 free(buf);
00084 return NULL;
00085 }
00086
00087 return (void *) buf;
00088 }
00089
00090 static int
00091 pool_destroy(struct _DriBufferPool *pool, void *private)
00092 {
00093 int ret;
00094 drmBO *buf = (drmBO *) private;
00095 driReadLockKernelBO();
00096 ret = drmBOUnreference(pool->fd, buf);
00097 free(buf);
00098 driReadUnlockKernelBO();
00099 return ret;
00100 }
00101
00102 static int
00103 pool_unreference(struct _DriBufferPool *pool, void *private)
00104 {
00105 int ret;
00106 drmBO *buf = (drmBO *) private;
00107 driReadLockKernelBO();
00108 ret = drmBOUnreference(pool->fd, buf);
00109 free(buf);
00110 driReadUnlockKernelBO();
00111 return ret;
00112 }
00113
00114 static int
00115 pool_map(struct _DriBufferPool *pool, void *private, unsigned flags,
00116 int hint, pipe_mutex *mutex, void **virtual)
00117 {
00118 drmBO *buf = (drmBO *) private;
00119 int ret;
00120
00121 driReadLockKernelBO();
00122 ret = drmBOMap(pool->fd, buf, flags, hint, virtual);
00123 driReadUnlockKernelBO();
00124 return ret;
00125 }
00126
00127 static int
00128 pool_unmap(struct _DriBufferPool *pool, void *private)
00129 {
00130 drmBO *buf = (drmBO *) private;
00131 int ret;
00132
00133 driReadLockKernelBO();
00134 ret = drmBOUnmap(pool->fd, buf);
00135 driReadUnlockKernelBO();
00136
00137 return ret;
00138 }
00139
00140 static unsigned long
00141 pool_offset(struct _DriBufferPool *pool, void *private)
00142 {
00143 drmBO *buf = (drmBO *) private;
00144 unsigned long offset;
00145
00146 driReadLockKernelBO();
00147 assert(buf->flags & DRM_BO_FLAG_NO_MOVE);
00148 offset = buf->offset;
00149 driReadUnlockKernelBO();
00150
00151 return buf->offset;
00152 }
00153
00154 static unsigned long
00155 pool_poolOffset(struct _DriBufferPool *pool, void *private)
00156 {
00157 return 0;
00158 }
00159
00160 static uint64_t
00161 pool_flags(struct _DriBufferPool *pool, void *private)
00162 {
00163 drmBO *buf = (drmBO *) private;
00164 uint64_t flags;
00165
00166 driReadLockKernelBO();
00167 flags = buf->flags;
00168 driReadUnlockKernelBO();
00169
00170 return flags;
00171 }
00172
00173
00174 static unsigned long
00175 pool_size(struct _DriBufferPool *pool, void *private)
00176 {
00177 drmBO *buf = (drmBO *) private;
00178 unsigned long size;
00179
00180 driReadLockKernelBO();
00181 size = buf->size;
00182 driReadUnlockKernelBO();
00183
00184 return buf->size;
00185 }
00186
00187 static int
00188 pool_fence(struct _DriBufferPool *pool, void *private,
00189 struct _DriFenceObject *fence)
00190 {
00191
00192
00193
00194
00195 return 0;
00196 }
00197
00198 static drmBO *
00199 pool_kernel(struct _DriBufferPool *pool, void *private)
00200 {
00201 return (drmBO *) private;
00202 }
00203
00204 static int
00205 pool_waitIdle(struct _DriBufferPool *pool, void *private, pipe_mutex *mutex,
00206 int lazy)
00207 {
00208 drmBO *buf = (drmBO *) private;
00209 int ret;
00210
00211 driReadLockKernelBO();
00212 ret = drmBOWaitIdle(pool->fd, buf, (lazy) ? DRM_BO_HINT_WAIT_LAZY:0);
00213 driReadUnlockKernelBO();
00214
00215 return ret;
00216 }
00217
00218
00219 static void
00220 pool_takedown(struct _DriBufferPool *pool)
00221 {
00222 free(pool);
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 struct _DriBufferPool *
00241 driDRMPoolInit(int fd)
00242 {
00243 struct _DriBufferPool *pool;
00244
00245 pool = (struct _DriBufferPool *) malloc(sizeof(*pool));
00246
00247 if (!pool)
00248 return NULL;
00249
00250 pool->fd = fd;
00251 pool->map = &pool_map;
00252 pool->unmap = &pool_unmap;
00253 pool->destroy = &pool_destroy;
00254 pool->offset = &pool_offset;
00255 pool->poolOffset = &pool_poolOffset;
00256 pool->flags = &pool_flags;
00257 pool->size = &pool_size;
00258 pool->create = &pool_create;
00259 pool->fence = &pool_fence;
00260 pool->kernel = &pool_kernel;
00261 pool->validate = NULL;
00262 pool->waitIdle = &pool_waitIdle;
00263 pool->takeDown = &pool_takedown;
00264 pool->reference = &pool_reference;
00265 pool->unreference = &pool_unreference;
00266 pool->data = NULL;
00267 return pool;
00268 }