radeon/r200/r300: cleanup some of the renderbuffer code
[mesa.git] / src / gallium / winsys / drm / intel / common / ws_dri_mallocpool.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, TX., 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 <errno.h>
35 #include "pipe/p_debug.h"
36 #include "pipe/p_thread.h"
37 #include "ws_dri_bufpool.h"
38 #include "ws_dri_bufmgr.h"
39
40 static void *
41 pool_create(struct _DriBufferPool *pool,
42 unsigned long size, uint64_t flags, unsigned hint,
43 unsigned alignment)
44 {
45 unsigned long *private = malloc(size + 2*sizeof(unsigned long));
46 if ((flags & DRM_BO_MASK_MEM) != DRM_BO_FLAG_MEM_LOCAL)
47 abort();
48
49 *private = size;
50 return (void *)private;
51 }
52
53
54 static int
55 pool_destroy(struct _DriBufferPool *pool, void *private)
56 {
57 free(private);
58 return 0;
59 }
60
61 static int
62 pool_waitIdle(struct _DriBufferPool *pool, void *private,
63 pipe_mutex *mutex, int lazy)
64 {
65 return 0;
66 }
67
68 static int
69 pool_map(struct _DriBufferPool *pool, void *private, unsigned flags,
70 int hint, pipe_mutex *mutex, void **virtual)
71 {
72 *virtual = (void *)((unsigned long *)private + 2);
73 return 0;
74 }
75
76 static int
77 pool_unmap(struct _DriBufferPool *pool, void *private)
78 {
79 return 0;
80 }
81
82 static unsigned long
83 pool_offset(struct _DriBufferPool *pool, void *private)
84 {
85 /*
86 * BUG
87 */
88 abort();
89 return 0UL;
90 }
91
92 static unsigned long
93 pool_poolOffset(struct _DriBufferPool *pool, void *private)
94 {
95 /*
96 * BUG
97 */
98 abort();
99 }
100
101 static uint64_t
102 pool_flags(struct _DriBufferPool *pool, void *private)
103 {
104 return DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_CACHED;
105 }
106
107 static unsigned long
108 pool_size(struct _DriBufferPool *pool, void *private)
109 {
110 return *(unsigned long *) private;
111 }
112
113
114 static int
115 pool_fence(struct _DriBufferPool *pool, void *private,
116 struct _DriFenceObject *fence)
117 {
118 abort();
119 return 0UL;
120 }
121
122 static drmBO *
123 pool_kernel(struct _DriBufferPool *pool, void *private)
124 {
125 abort();
126 return NULL;
127 }
128
129 static void
130 pool_takedown(struct _DriBufferPool *pool)
131 {
132 free(pool);
133 }
134
135
136 struct _DriBufferPool *
137 driMallocPoolInit(void)
138 {
139 struct _DriBufferPool *pool;
140
141 pool = (struct _DriBufferPool *) malloc(sizeof(*pool));
142 if (!pool)
143 return NULL;
144
145 pool->data = NULL;
146 pool->fd = -1;
147 pool->map = &pool_map;
148 pool->unmap = &pool_unmap;
149 pool->destroy = &pool_destroy;
150 pool->offset = &pool_offset;
151 pool->poolOffset = &pool_poolOffset;
152 pool->flags = &pool_flags;
153 pool->size = &pool_size;
154 pool->create = &pool_create;
155 pool->fence = &pool_fence;
156 pool->kernel = &pool_kernel;
157 pool->validate = NULL;
158 pool->waitIdle = &pool_waitIdle;
159 pool->takeDown = &pool_takedown;
160 return pool;
161 }