aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/radeon_mem.c
diff options
context:
space:
mode:
authorDave Airlie <airlied@starflyer.(none)>2005-09-25 00:28:13 -0400
committerDave Airlie <airlied@linux.ie>2005-09-25 00:28:13 -0400
commitb5e89ed53ed8d24f83ba1941c07382af00ed238e (patch)
tree747bae7a565f88a2e1d5974776eeb054a932c505 /drivers/char/drm/radeon_mem.c
parent99a2657a29e2d623c3568cd86b27cac13fb63140 (diff)
drm: lindent the drm directory.
I've been threatening this for a while, so no point hanging around. This lindents the DRM code which was always really bad in tabbing department. I've also fixed some misnamed files in comments and removed some trailing whitespace. Signed-off-by: Dave Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers/char/drm/radeon_mem.c')
-rw-r--r--drivers/char/drm/radeon_mem.c148
1 files changed, 70 insertions, 78 deletions
diff --git a/drivers/char/drm/radeon_mem.c b/drivers/char/drm/radeon_mem.c
index 134f894e6e4b..030a6fad0d86 100644
--- a/drivers/char/drm/radeon_mem.c
+++ b/drivers/char/drm/radeon_mem.c
@@ -1,7 +1,7 @@
1/* radeon_mem.c -- Simple GART/fb memory manager for radeon -*- linux-c -*- 1/* radeon_mem.c -- Simple GART/fb memory manager for radeon -*- linux-c -*-
2 * 2 *
3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 * 4 *
5 * The Weather Channel (TM) funded Tungsten Graphics to develop the 5 * The Weather Channel (TM) funded Tungsten Graphics to develop the
6 * initial release of the Radeon 8500 driver under the XFree86 license. 6 * initial release of the Radeon 8500 driver under the XFree86 license.
7 * This notice must be preserved. 7 * This notice must be preserved.
@@ -35,16 +35,17 @@
35#include "radeon_drv.h" 35#include "radeon_drv.h"
36 36
37/* Very simple allocator for GART memory, working on a static range 37/* Very simple allocator for GART memory, working on a static range
38 * already mapped into each client's address space. 38 * already mapped into each client's address space.
39 */ 39 */
40 40
41static struct mem_block *split_block(struct mem_block *p, int start, int size, 41static struct mem_block *split_block(struct mem_block *p, int start, int size,
42 DRMFILE filp ) 42 DRMFILE filp)
43{ 43{
44 /* Maybe cut off the start of an existing block */ 44 /* Maybe cut off the start of an existing block */
45 if (start > p->start) { 45 if (start > p->start) {
46 struct mem_block *newblock = drm_alloc(sizeof(*newblock), DRM_MEM_BUFS ); 46 struct mem_block *newblock =
47 if (!newblock) 47 drm_alloc(sizeof(*newblock), DRM_MEM_BUFS);
48 if (!newblock)
48 goto out; 49 goto out;
49 newblock->start = start; 50 newblock->start = start;
50 newblock->size = p->size - (start - p->start); 51 newblock->size = p->size - (start - p->start);
@@ -56,10 +57,11 @@ static struct mem_block *split_block(struct mem_block *p, int start, int size,
56 p->size -= newblock->size; 57 p->size -= newblock->size;
57 p = newblock; 58 p = newblock;
58 } 59 }
59 60
60 /* Maybe cut off the end of an existing block */ 61 /* Maybe cut off the end of an existing block */
61 if (size < p->size) { 62 if (size < p->size) {
62 struct mem_block *newblock = drm_alloc(sizeof(*newblock), DRM_MEM_BUFS ); 63 struct mem_block *newblock =
64 drm_alloc(sizeof(*newblock), DRM_MEM_BUFS);
63 if (!newblock) 65 if (!newblock)
64 goto out; 66 goto out;
65 newblock->start = start + size; 67 newblock->start = start + size;
@@ -72,40 +74,39 @@ static struct mem_block *split_block(struct mem_block *p, int start, int size,
72 p->size = size; 74 p->size = size;
73 } 75 }
74 76
75 out: 77 out:
76 /* Our block is in the middle */ 78 /* Our block is in the middle */
77 p->filp = filp; 79 p->filp = filp;
78 return p; 80 return p;
79} 81}
80 82
81static struct mem_block *alloc_block( struct mem_block *heap, int size, 83static struct mem_block *alloc_block(struct mem_block *heap, int size,
82 int align2, DRMFILE filp ) 84 int align2, DRMFILE filp)
83{ 85{
84 struct mem_block *p; 86 struct mem_block *p;
85 int mask = (1 << align2)-1; 87 int mask = (1 << align2) - 1;
86 88
87 list_for_each(p, heap) { 89 list_for_each(p, heap) {
88 int start = (p->start + mask) & ~mask; 90 int start = (p->start + mask) & ~mask;
89 if (p->filp == 0 && start + size <= p->start + p->size) 91 if (p->filp == 0 && start + size <= p->start + p->size)
90 return split_block( p, start, size, filp ); 92 return split_block(p, start, size, filp);
91 } 93 }
92 94
93 return NULL; 95 return NULL;
94} 96}
95 97
96static struct mem_block *find_block( struct mem_block *heap, int start ) 98static struct mem_block *find_block(struct mem_block *heap, int start)
97{ 99{
98 struct mem_block *p; 100 struct mem_block *p;
99 101
100 list_for_each(p, heap) 102 list_for_each(p, heap)
101 if (p->start == start) 103 if (p->start == start)
102 return p; 104 return p;
103 105
104 return NULL; 106 return NULL;
105} 107}
106 108
107 109static void free_block(struct mem_block *p)
108static void free_block( struct mem_block *p )
109{ 110{
110 p->filp = NULL; 111 p->filp = NULL;
111 112
@@ -117,7 +118,7 @@ static void free_block( struct mem_block *p )
117 p->size += q->size; 118 p->size += q->size;
118 p->next = q->next; 119 p->next = q->next;
119 p->next->prev = p; 120 p->next->prev = p;
120 drm_free(q, sizeof(*q), DRM_MEM_BUFS ); 121 drm_free(q, sizeof(*q), DRM_MEM_BUFS);
121 } 122 }
122 123
123 if (p->prev->filp == 0) { 124 if (p->prev->filp == 0) {
@@ -125,7 +126,7 @@ static void free_block( struct mem_block *p )
125 q->size += p->size; 126 q->size += p->size;
126 q->next = p->next; 127 q->next = p->next;
127 q->next->prev = q; 128 q->next->prev = q;
128 drm_free(p, sizeof(*q), DRM_MEM_BUFS ); 129 drm_free(p, sizeof(*q), DRM_MEM_BUFS);
129 } 130 }
130} 131}
131 132
@@ -133,14 +134,14 @@ static void free_block( struct mem_block *p )
133 */ 134 */
134static int init_heap(struct mem_block **heap, int start, int size) 135static int init_heap(struct mem_block **heap, int start, int size)
135{ 136{
136 struct mem_block *blocks = drm_alloc(sizeof(*blocks), DRM_MEM_BUFS ); 137 struct mem_block *blocks = drm_alloc(sizeof(*blocks), DRM_MEM_BUFS);
137 138
138 if (!blocks) 139 if (!blocks)
139 return DRM_ERR(ENOMEM); 140 return DRM_ERR(ENOMEM);
140 141
141 *heap = drm_alloc(sizeof(**heap), DRM_MEM_BUFS ); 142 *heap = drm_alloc(sizeof(**heap), DRM_MEM_BUFS);
142 if (!*heap) { 143 if (!*heap) {
143 drm_free( blocks, sizeof(*blocks), DRM_MEM_BUFS ); 144 drm_free(blocks, sizeof(*blocks), DRM_MEM_BUFS);
144 return DRM_ERR(ENOMEM); 145 return DRM_ERR(ENOMEM);
145 } 146 }
146 147
@@ -149,16 +150,15 @@ static int init_heap(struct mem_block **heap, int start, int size)
149 blocks->filp = NULL; 150 blocks->filp = NULL;
150 blocks->next = blocks->prev = *heap; 151 blocks->next = blocks->prev = *heap;
151 152
152 memset( *heap, 0, sizeof(**heap) ); 153 memset(*heap, 0, sizeof(**heap));
153 (*heap)->filp = (DRMFILE) -1; 154 (*heap)->filp = (DRMFILE) - 1;
154 (*heap)->next = (*heap)->prev = blocks; 155 (*heap)->next = (*heap)->prev = blocks;
155 return 0; 156 return 0;
156} 157}
157 158
158
159/* Free all blocks associated with the releasing file. 159/* Free all blocks associated with the releasing file.
160 */ 160 */
161void radeon_mem_release( DRMFILE filp, struct mem_block *heap ) 161void radeon_mem_release(DRMFILE filp, struct mem_block *heap)
162{ 162{
163 struct mem_block *p; 163 struct mem_block *p;
164 164
@@ -166,7 +166,7 @@ void radeon_mem_release( DRMFILE filp, struct mem_block *heap )
166 return; 166 return;
167 167
168 list_for_each(p, heap) { 168 list_for_each(p, heap) {
169 if (p->filp == filp) 169 if (p->filp == filp)
170 p->filp = NULL; 170 p->filp = NULL;
171 } 171 }
172 172
@@ -179,40 +179,37 @@ void radeon_mem_release( DRMFILE filp, struct mem_block *heap )
179 p->size += q->size; 179 p->size += q->size;
180 p->next = q->next; 180 p->next = q->next;
181 p->next->prev = p; 181 p->next->prev = p;
182 drm_free(q, sizeof(*q),DRM_MEM_DRIVER); 182 drm_free(q, sizeof(*q), DRM_MEM_DRIVER);
183 } 183 }
184 } 184 }
185} 185}
186 186
187/* Shutdown. 187/* Shutdown.
188 */ 188 */
189void radeon_mem_takedown( struct mem_block **heap ) 189void radeon_mem_takedown(struct mem_block **heap)
190{ 190{
191 struct mem_block *p; 191 struct mem_block *p;
192 192
193 if (!*heap) 193 if (!*heap)
194 return; 194 return;
195 195
196 for (p = (*heap)->next ; p != *heap ; ) { 196 for (p = (*heap)->next; p != *heap;) {
197 struct mem_block *q = p; 197 struct mem_block *q = p;
198 p = p->next; 198 p = p->next;
199 drm_free(q, sizeof(*q),DRM_MEM_DRIVER); 199 drm_free(q, sizeof(*q), DRM_MEM_DRIVER);
200 } 200 }
201 201
202 drm_free( *heap, sizeof(**heap),DRM_MEM_DRIVER ); 202 drm_free(*heap, sizeof(**heap), DRM_MEM_DRIVER);
203 *heap = NULL; 203 *heap = NULL;
204} 204}
205 205
206
207
208/* IOCTL HANDLERS */ 206/* IOCTL HANDLERS */
209 207
210static struct mem_block **get_heap( drm_radeon_private_t *dev_priv, 208static struct mem_block **get_heap(drm_radeon_private_t * dev_priv, int region)
211 int region )
212{ 209{
213 switch( region ) { 210 switch (region) {
214 case RADEON_MEM_REGION_GART: 211 case RADEON_MEM_REGION_GART:
215 return &dev_priv->gart_heap; 212 return &dev_priv->gart_heap;
216 case RADEON_MEM_REGION_FB: 213 case RADEON_MEM_REGION_FB:
217 return &dev_priv->fb_heap; 214 return &dev_priv->fb_heap;
218 default: 215 default:
@@ -220,103 +217,98 @@ static struct mem_block **get_heap( drm_radeon_private_t *dev_priv,
220 } 217 }
221} 218}
222 219
223int radeon_mem_alloc( DRM_IOCTL_ARGS ) 220int radeon_mem_alloc(DRM_IOCTL_ARGS)
224{ 221{
225 DRM_DEVICE; 222 DRM_DEVICE;
226 drm_radeon_private_t *dev_priv = dev->dev_private; 223 drm_radeon_private_t *dev_priv = dev->dev_private;
227 drm_radeon_mem_alloc_t alloc; 224 drm_radeon_mem_alloc_t alloc;
228 struct mem_block *block, **heap; 225 struct mem_block *block, **heap;
229 226
230 if ( !dev_priv ) { 227 if (!dev_priv) {
231 DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); 228 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
232 return DRM_ERR(EINVAL); 229 return DRM_ERR(EINVAL);
233 } 230 }
234 231
235 DRM_COPY_FROM_USER_IOCTL( alloc, (drm_radeon_mem_alloc_t __user *)data, 232 DRM_COPY_FROM_USER_IOCTL(alloc, (drm_radeon_mem_alloc_t __user *) data,
236 sizeof(alloc) ); 233 sizeof(alloc));
237 234
238 heap = get_heap( dev_priv, alloc.region ); 235 heap = get_heap(dev_priv, alloc.region);
239 if (!heap || !*heap) 236 if (!heap || !*heap)
240 return DRM_ERR(EFAULT); 237 return DRM_ERR(EFAULT);
241 238
242 /* Make things easier on ourselves: all allocations at least 239 /* Make things easier on ourselves: all allocations at least
243 * 4k aligned. 240 * 4k aligned.
244 */ 241 */
245 if (alloc.alignment < 12) 242 if (alloc.alignment < 12)
246 alloc.alignment = 12; 243 alloc.alignment = 12;
247 244
248 block = alloc_block( *heap, alloc.size, alloc.alignment, 245 block = alloc_block(*heap, alloc.size, alloc.alignment, filp);
249 filp );
250 246
251 if (!block) 247 if (!block)
252 return DRM_ERR(ENOMEM); 248 return DRM_ERR(ENOMEM);
253 249
254 if ( DRM_COPY_TO_USER( alloc.region_offset, &block->start, 250 if (DRM_COPY_TO_USER(alloc.region_offset, &block->start, sizeof(int))) {
255 sizeof(int) ) ) { 251 DRM_ERROR("copy_to_user\n");
256 DRM_ERROR( "copy_to_user\n" );
257 return DRM_ERR(EFAULT); 252 return DRM_ERR(EFAULT);
258 } 253 }
259 254
260 return 0; 255 return 0;
261} 256}
262 257
263 258int radeon_mem_free(DRM_IOCTL_ARGS)
264
265int radeon_mem_free( DRM_IOCTL_ARGS )
266{ 259{
267 DRM_DEVICE; 260 DRM_DEVICE;
268 drm_radeon_private_t *dev_priv = dev->dev_private; 261 drm_radeon_private_t *dev_priv = dev->dev_private;
269 drm_radeon_mem_free_t memfree; 262 drm_radeon_mem_free_t memfree;
270 struct mem_block *block, **heap; 263 struct mem_block *block, **heap;
271 264
272 if ( !dev_priv ) { 265 if (!dev_priv) {
273 DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); 266 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
274 return DRM_ERR(EINVAL); 267 return DRM_ERR(EINVAL);
275 } 268 }
276 269
277 DRM_COPY_FROM_USER_IOCTL( memfree, (drm_radeon_mem_free_t __user *)data, 270 DRM_COPY_FROM_USER_IOCTL(memfree, (drm_radeon_mem_free_t __user *) data,
278 sizeof(memfree) ); 271 sizeof(memfree));
279 272
280 heap = get_heap( dev_priv, memfree.region ); 273 heap = get_heap(dev_priv, memfree.region);
281 if (!heap || !*heap) 274 if (!heap || !*heap)
282 return DRM_ERR(EFAULT); 275 return DRM_ERR(EFAULT);
283 276
284 block = find_block( *heap, memfree.region_offset ); 277 block = find_block(*heap, memfree.region_offset);
285 if (!block) 278 if (!block)
286 return DRM_ERR(EFAULT); 279 return DRM_ERR(EFAULT);
287 280
288 if (block->filp != filp) 281 if (block->filp != filp)
289 return DRM_ERR(EPERM); 282 return DRM_ERR(EPERM);
290 283
291 free_block( block ); 284 free_block(block);
292 return 0; 285 return 0;
293} 286}
294 287
295int radeon_mem_init_heap( DRM_IOCTL_ARGS ) 288int radeon_mem_init_heap(DRM_IOCTL_ARGS)
296{ 289{
297 DRM_DEVICE; 290 DRM_DEVICE;
298 drm_radeon_private_t *dev_priv = dev->dev_private; 291 drm_radeon_private_t *dev_priv = dev->dev_private;
299 drm_radeon_mem_init_heap_t initheap; 292 drm_radeon_mem_init_heap_t initheap;
300 struct mem_block **heap; 293 struct mem_block **heap;
301 294
302 if ( !dev_priv ) { 295 if (!dev_priv) {
303 DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); 296 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
304 return DRM_ERR(EINVAL); 297 return DRM_ERR(EINVAL);
305 } 298 }
306 299
307 DRM_COPY_FROM_USER_IOCTL( initheap, (drm_radeon_mem_init_heap_t __user *)data, 300 DRM_COPY_FROM_USER_IOCTL(initheap,
308 sizeof(initheap) ); 301 (drm_radeon_mem_init_heap_t __user *) data,
302 sizeof(initheap));
309 303
310 heap = get_heap( dev_priv, initheap.region ); 304 heap = get_heap(dev_priv, initheap.region);
311 if (!heap) 305 if (!heap)
312 return DRM_ERR(EFAULT); 306 return DRM_ERR(EFAULT);
313 307
314 if (*heap) { 308 if (*heap) {
315 DRM_ERROR("heap already initialized?"); 309 DRM_ERROR("heap already initialized?");
316 return DRM_ERR(EFAULT); 310 return DRM_ERR(EFAULT);
317 } 311 }
318
319 return init_heap( heap, initheap.start, initheap.size );
320}
321
322 312
313 return init_heap(heap, initheap.start, initheap.size);
314}