~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/drivers/dri/common/dri_drmpool.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
Import upstream version 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 * 
 
3
 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
 
4
 * All Rights Reserved.
 
5
 * 
 
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:
 
13
 * 
 
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.
 
21
 *
 
22
 * The above copyright notice and this permission notice (including the
 
23
 * next paragraph) shall be included in all copies or substantial portions
 
24
 * of the Software.
 
25
 * 
 
26
 * 
 
27
 **************************************************************************/
 
28
/*
 
29
 * Authors: Thomas Hellstr�m <thomas-at-tungstengraphics-dot-com>
 
30
 */
 
31
 
 
32
#include <xf86drm.h>
 
33
#include <stdlib.h>
 
34
#include <unistd.h>
 
35
#include "dri_bufpool.h"
 
36
 
 
37
/*
 
38
 * Buffer pool implementation using DRM buffer objects as DRI buffer objects.
 
39
 */
 
40
 
 
41
static void *
 
42
pool_create(struct _DriBufferPool *pool,
 
43
            unsigned long size, unsigned flags, unsigned hint,
 
44
            unsigned alignment)
 
45
{
 
46
   drmBO *buf = (drmBO *) malloc(sizeof(*buf));
 
47
   int ret;
 
48
   unsigned pageSize = getpagesize();
 
49
 
 
50
   if (!buf)
 
51
      return NULL;
 
52
 
 
53
   if ((alignment > pageSize) && (alignment % pageSize)) {
 
54
      return NULL;
 
55
   }
 
56
 
 
57
   ret = drmBOCreate(pool->fd, 0, size, alignment / pageSize,
 
58
                     NULL, drm_bo_type_dc,
 
59
                     flags, hint, buf);
 
60
   if (ret) {
 
61
      free(buf);
 
62
      return NULL;
 
63
   }
 
64
 
 
65
   return (void *) buf;
 
66
}
 
67
 
 
68
static int
 
69
pool_destroy(struct _DriBufferPool *pool, void *private)
 
70
{
 
71
   int ret;
 
72
   drmBO *buf = (drmBO *) private;
 
73
   ret = drmBODestroy(pool->fd, buf);
 
74
   free(buf);
 
75
   return ret;
 
76
}
 
77
 
 
78
static int
 
79
pool_map(struct _DriBufferPool *pool, void *private, unsigned flags,
 
80
         int hint, void **virtual)
 
81
{
 
82
   drmBO *buf = (drmBO *) private;
 
83
 
 
84
   return drmBOMap(pool->fd, buf, flags, hint, virtual);
 
85
}
 
86
 
 
87
static int
 
88
pool_unmap(struct _DriBufferPool *pool, void *private)
 
89
{
 
90
   drmBO *buf = (drmBO *) private;
 
91
   return drmBOUnmap(pool->fd, buf);
 
92
}
 
93
 
 
94
static unsigned long
 
95
pool_offset(struct _DriBufferPool *pool, void *private)
 
96
{
 
97
   drmBO *buf = (drmBO *) private;
 
98
   return buf->offset;
 
99
}
 
100
 
 
101
static unsigned
 
102
pool_flags(struct _DriBufferPool *pool, void *private)
 
103
{
 
104
   drmBO *buf = (drmBO *) private;
 
105
   return buf->flags;
 
106
}
 
107
 
 
108
 
 
109
static unsigned long
 
110
pool_size(struct _DriBufferPool *pool, void *private)
 
111
{
 
112
   drmBO *buf = (drmBO *) private;
 
113
   return buf->size;
 
114
}
 
115
 
 
116
static int
 
117
pool_fence(struct _DriBufferPool *pool, void *private,
 
118
           struct _DriFenceObject *fence)
 
119
{
 
120
   /*
 
121
    * Noop. The kernel handles all fencing.
 
122
    */
 
123
 
 
124
   return 0;
 
125
}
 
126
 
 
127
static drmBO *
 
128
pool_kernel(struct _DriBufferPool *pool, void *private)
 
129
{
 
130
   return (drmBO *) private;
 
131
}
 
132
 
 
133
static int
 
134
pool_waitIdle(struct _DriBufferPool *pool, void *private, int lazy)
 
135
{
 
136
   drmBO *buf = (drmBO *) private;
 
137
   return drmBOWaitIdle(pool->fd, buf, (lazy) ? DRM_BO_HINT_WAIT_LAZY:0);
 
138
}
 
139
 
 
140
    
 
141
static void
 
142
pool_takedown(struct _DriBufferPool *pool)
 
143
{
 
144
   free(pool);
 
145
}
 
146
 
 
147
 
 
148
struct _DriBufferPool *
 
149
driDRMPoolInit(int fd)
 
150
{
 
151
   struct _DriBufferPool *pool;
 
152
 
 
153
   pool = (struct _DriBufferPool *) malloc(sizeof(*pool));
 
154
 
 
155
   if (!pool)
 
156
      return NULL;
 
157
 
 
158
   pool->fd = fd;
 
159
   pool->map = &pool_map;
 
160
   pool->unmap = &pool_unmap;
 
161
   pool->destroy = &pool_destroy;
 
162
   pool->offset = &pool_offset;
 
163
   pool->flags = &pool_flags;
 
164
   pool->size = &pool_size;
 
165
   pool->create = &pool_create;
 
166
   pool->fence = &pool_fence;
 
167
   pool->kernel = &pool_kernel;
 
168
   pool->validate = NULL;
 
169
   pool->setstatic = NULL;
 
170
   pool->waitIdle = &pool_waitIdle;
 
171
   pool->takeDown = &pool_takedown;
 
172
   pool->data = NULL;
 
173
   return pool;
 
174
}
 
175
 
 
176
 
 
177
static void *
 
178
pool_setstatic(struct _DriBufferPool *pool, unsigned long offset,
 
179
               unsigned long size, void *virtual, unsigned flags)
 
180
{
 
181
   drmBO *buf = (drmBO *) malloc(sizeof(*buf));
 
182
   int ret;
 
183
 
 
184
   if (!buf)
 
185
      return NULL;
 
186
 
 
187
   ret = drmBOCreate(pool->fd, offset, size, 0, NULL, drm_bo_type_fake,
 
188
                     flags, 0, buf);
 
189
 
 
190
   if (ret) {
 
191
      free(buf);
 
192
      return NULL;
 
193
   }
 
194
 
 
195
   buf->virtual = virtual;
 
196
 
 
197
   return (void *) buf;
 
198
}
 
199
 
 
200
 
 
201
struct _DriBufferPool *
 
202
driDRMStaticPoolInit(int fd)
 
203
{
 
204
   struct _DriBufferPool *pool;
 
205
 
 
206
   pool = (struct _DriBufferPool *) malloc(sizeof(*pool));
 
207
 
 
208
   if (!pool)
 
209
      return NULL;
 
210
 
 
211
   pool->fd = fd;
 
212
   pool->map = &pool_map;
 
213
   pool->unmap = &pool_unmap;
 
214
   pool->destroy = &pool_destroy;
 
215
   pool->offset = &pool_offset;
 
216
   pool->flags = &pool_flags;
 
217
   pool->size = &pool_size;
 
218
   pool->create = NULL;
 
219
   pool->fence = &pool_fence;
 
220
   pool->kernel = &pool_kernel;
 
221
   pool->validate = NULL;
 
222
   pool->setstatic = &pool_setstatic;
 
223
   pool->waitIdle = &pool_waitIdle;
 
224
   pool->takeDown = &pool_takedown;
 
225
   pool->data = NULL;
 
226
   return pool;
 
227
}