1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
27 **************************************************************************/
29 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
35 #include "ws_dri_bufpool.h"
36 #include "ws_dri_bufmgr.h"
40 * Buffer pool implementation using DRM buffer objects as DRI buffer objects.
44 pool_create(struct _DriBufferPool
*pool
,
45 unsigned long size
, uint64_t flags
, unsigned hint
,
48 drmBO
*buf
= (drmBO
*) malloc(sizeof(*buf
));
50 unsigned pageSize
= getpagesize();
55 if ((alignment
> pageSize
) && (alignment
% pageSize
)) {
60 ret
= drmBOCreate(pool
->fd
, size
, alignment
/ pageSize
,
72 pool_reference(struct _DriBufferPool
*pool
, unsigned handle
)
74 drmBO
*buf
= (drmBO
*) malloc(sizeof(*buf
));
80 ret
= drmBOReference(pool
->fd
, handle
, buf
);
91 pool_destroy(struct _DriBufferPool
*pool
, void *private)
94 drmBO
*buf
= (drmBO
*) private;
95 driReadLockKernelBO();
96 ret
= drmBOUnreference(pool
->fd
, buf
);
98 driReadUnlockKernelBO();
103 pool_unreference(struct _DriBufferPool
*pool
, void *private)
106 drmBO
*buf
= (drmBO
*) private;
107 driReadLockKernelBO();
108 ret
= drmBOUnreference(pool
->fd
, buf
);
110 driReadUnlockKernelBO();
115 pool_map(struct _DriBufferPool
*pool
, void *private, unsigned flags
,
116 int hint
, pipe_mutex
*mutex
, void **virtual)
118 drmBO
*buf
= (drmBO
*) private;
121 driReadLockKernelBO();
122 ret
= drmBOMap(pool
->fd
, buf
, flags
, hint
, virtual);
123 driReadUnlockKernelBO();
128 pool_unmap(struct _DriBufferPool
*pool
, void *private)
130 drmBO
*buf
= (drmBO
*) private;
133 driReadLockKernelBO();
134 ret
= drmBOUnmap(pool
->fd
, buf
);
135 driReadUnlockKernelBO();
141 pool_offset(struct _DriBufferPool
*pool
, void *private)
143 drmBO
*buf
= (drmBO
*) private;
144 unsigned long offset
;
146 driReadLockKernelBO();
147 assert(buf
->flags
& DRM_BO_FLAG_NO_MOVE
);
148 offset
= buf
->offset
;
149 driReadUnlockKernelBO();
155 pool_poolOffset(struct _DriBufferPool
*pool
, void *private)
161 pool_flags(struct _DriBufferPool
*pool
, void *private)
163 drmBO
*buf
= (drmBO
*) private;
166 driReadLockKernelBO();
168 driReadUnlockKernelBO();
175 pool_size(struct _DriBufferPool
*pool
, void *private)
177 drmBO
*buf
= (drmBO
*) private;
180 driReadLockKernelBO();
182 driReadUnlockKernelBO();
188 pool_fence(struct _DriBufferPool
*pool
, void *private,
189 struct _DriFenceObject
*fence
)
192 * Noop. The kernel handles all fencing.
199 pool_kernel(struct _DriBufferPool
*pool
, void *private)
201 return (drmBO
*) private;
205 pool_waitIdle(struct _DriBufferPool
*pool
, void *private, pipe_mutex
*mutex
,
208 drmBO
*buf
= (drmBO
*) private;
211 driReadLockKernelBO();
212 ret
= drmBOWaitIdle(pool
->fd
, buf
, (lazy
) ? DRM_BO_HINT_WAIT_LAZY
:0);
213 driReadUnlockKernelBO();
220 pool_takedown(struct _DriBufferPool
*pool
)
226 pool_setStatus(struct _DriBufferPool *pool, void *private,
227 uint64_t flag_diff, uint64_t old_flags)
229 drmBO *buf = (drmBO *) private;
230 uint64_t new_flags = old_flags ^ flag_diff;
233 driReadLockKernelBO();
234 ret = drmBOSetStatus(pool->fd, buf, new_flags, flag_diff,
236 driReadUnlockKernelBO();
240 struct _DriBufferPool
*
241 driDRMPoolInit(int fd
)
243 struct _DriBufferPool
*pool
;
245 pool
= (struct _DriBufferPool
*) malloc(sizeof(*pool
));
251 pool
->map
= &pool_map
;
252 pool
->unmap
= &pool_unmap
;
253 pool
->destroy
= &pool_destroy
;
254 pool
->offset
= &pool_offset
;
255 pool
->poolOffset
= &pool_poolOffset
;
256 pool
->flags
= &pool_flags
;
257 pool
->size
= &pool_size
;
258 pool
->create
= &pool_create
;
259 pool
->fence
= &pool_fence
;
260 pool
->kernel
= &pool_kernel
;
261 pool
->validate
= NULL
;
262 pool
->waitIdle
= &pool_waitIdle
;
263 pool
->takeDown
= &pool_takedown
;
264 pool
->reference
= &pool_reference
;
265 pool
->unreference
= &pool_unreference
;