From 7809efc8c32520e6b25c143ee3276edbf534ed14 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 30 Aug 2004 09:01:50 +0000 Subject: drm-memory patch, cleans up alloc/free and makes calloc look more libc like --- shared-core/i915_mem.c | 20 +++++------ shared-core/r128_state.c | 84 +++++++++++++++++++++++----------------------- shared-core/radeon_mem.c | 20 +++++------ shared-core/radeon_state.c | 3 +- shared-core/via_ds.c | 25 +++++--------- 5 files changed, 72 insertions(+), 80 deletions(-) (limited to 'shared-core') diff --git a/shared-core/i915_mem.c b/shared-core/i915_mem.c index 42c1e353..c6115b7e 100644 --- a/shared-core/i915_mem.c +++ b/shared-core/i915_mem.c @@ -75,7 +75,7 @@ static struct mem_block *split_block(struct mem_block *p, int start, int size, { /* Maybe cut off the start of an existing block */ if (start > p->start) { - struct mem_block *newblock = DRM_MALLOC(sizeof(*newblock)); + struct mem_block *newblock = DRM(alloc)(sizeof(*newblock), DRM_MEM_BUFLISTS); if (!newblock) goto out; newblock->start = start; @@ -91,7 +91,7 @@ static struct mem_block *split_block(struct mem_block *p, int start, int size, /* Maybe cut off the end of an existing block */ if (size < p->size) { - struct mem_block *newblock = DRM_MALLOC(sizeof(*newblock)); + struct mem_block *newblock = DRM(alloc)(sizeof(*newblock), DRM_MEM_BUFLISTS); if (!newblock) goto out; newblock->start = start + size; @@ -148,7 +148,7 @@ static void free_block(struct mem_block *p) p->size += q->size; p->next = q->next; p->next->prev = p; - DRM_FREE(q, sizeof(*q)); + DRM(free)(q, sizeof(*q), DRM_MEM_BUFLISTS); } if (p->prev->filp == NULL) { @@ -156,7 +156,7 @@ static void free_block(struct mem_block *p) q->size += p->size; q->next = p->next; q->next->prev = q; - DRM_FREE(p, sizeof(*q)); + DRM(free)(p, sizeof(*q), DRM_MEM_BUFLISTS); } } @@ -164,14 +164,14 @@ static void free_block(struct mem_block *p) */ static int init_heap(struct mem_block **heap, int start, int size) { - struct mem_block *blocks = DRM_MALLOC(sizeof(*blocks)); + struct mem_block *blocks = DRM(alloc)(sizeof(*blocks), DRM_MEM_BUFLISTS); if (!blocks) return -ENOMEM; - *heap = DRM_MALLOC(sizeof(**heap)); + *heap = DRM(alloc)(sizeof(**heap), DRM_MEM_BUFLISTS); if (!*heap) { - DRM_FREE(blocks, sizeof(*blocks)); + DRM(free)(blocks, sizeof(*blocks), DRM_MEM_BUFLISTS); return -ENOMEM; } @@ -211,7 +211,7 @@ void i915_mem_release(drm_device_t * dev, DRMFILE filp, struct mem_block *heap) p->size += q->size; p->next = q->next; p->next->prev = p; - DRM_FREE(q, sizeof(*q)); + DRM(free)(q, sizeof(*q), DRM_MEM_BUFLISTS); } } } @@ -228,10 +228,10 @@ void i915_mem_takedown(struct mem_block **heap) for (p = (*heap)->next; p != *heap;) { struct mem_block *q = p; p = p->next; - DRM_FREE(q, sizeof(*q)); + DRM(free)(q, sizeof(*q), DRM_MEM_BUFLISTS); } - DRM_FREE(*heap, sizeof(**heap)); + DRM(free)(*heap, sizeof(**heap), DRM_MEM_BUFLISTS); *heap = NULL; } diff --git a/shared-core/r128_state.c b/shared-core/r128_state.c index d772f173..5b8af9f9 100644 --- a/shared-core/r128_state.c +++ b/shared-core/r128_state.c @@ -926,24 +926,24 @@ static int r128_cce_dispatch_write_span( drm_device_t *dev, } buffer_size = depth->n * sizeof(u32); - buffer = DRM_MALLOC( buffer_size ); + buffer = DRM(alloc)( buffer_size, DRM_MEM_BUFS ); if ( buffer == NULL ) return DRM_ERR(ENOMEM); if ( DRM_COPY_FROM_USER( buffer, depth->buffer, buffer_size ) ) { - DRM_FREE( buffer, buffer_size); + DRM(free)( buffer, buffer_size, DRM_MEM_BUFS); return DRM_ERR(EFAULT); } mask_size = depth->n * sizeof(u8); if ( depth->mask ) { - mask = DRM_MALLOC( mask_size ); + mask = DRM(alloc)( mask_size, DRM_MEM_BUFS ); if ( mask == NULL ) { - DRM_FREE( buffer, buffer_size ); + DRM(free)( buffer, buffer_size, DRM_MEM_BUFS ); return DRM_ERR(ENOMEM); } if ( DRM_COPY_FROM_USER( mask, depth->mask, mask_size ) ) { - DRM_FREE( buffer, buffer_size ); - DRM_FREE( mask, mask_size ); + DRM(free)( buffer, buffer_size, DRM_MEM_BUFS ); + DRM(free)( mask, mask_size, DRM_MEM_BUFS ); return DRM_ERR(EFAULT); } @@ -970,7 +970,7 @@ static int r128_cce_dispatch_write_span( drm_device_t *dev, } } - DRM_FREE( mask, mask_size ); + DRM(free)( mask, mask_size, DRM_MEM_BUFS ); } else { for ( i = 0 ; i < count ; i++, x++ ) { BEGIN_RING( 6 ); @@ -994,7 +994,7 @@ static int r128_cce_dispatch_write_span( drm_device_t *dev, } } - DRM_FREE( buffer, buffer_size ); + DRM(free)( buffer, buffer_size, DRM_MEM_BUFS ); return 0; } @@ -1016,54 +1016,54 @@ static int r128_cce_dispatch_write_pixels( drm_device_t *dev, xbuf_size = count * sizeof(*x); ybuf_size = count * sizeof(*y); - x = DRM_MALLOC( xbuf_size ); + x = DRM(alloc)( xbuf_size, DRM_MEM_BUFS ); if ( x == NULL ) { return DRM_ERR(ENOMEM); } - y = DRM_MALLOC( ybuf_size ); + y = DRM(alloc)( ybuf_size, DRM_MEM_BUFS ); if ( y == NULL ) { - DRM_FREE( x, xbuf_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); return DRM_ERR(ENOMEM); } if ( DRM_COPY_FROM_USER( x, depth->x, xbuf_size ) ) { - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); return DRM_ERR(EFAULT); } if ( DRM_COPY_FROM_USER( y, depth->y, xbuf_size ) ) { - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); return DRM_ERR(EFAULT); } buffer_size = depth->n * sizeof(u32); - buffer = DRM_MALLOC( buffer_size ); + buffer = DRM(alloc)( buffer_size, DRM_MEM_BUFS ); if ( buffer == NULL ) { - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); return DRM_ERR(ENOMEM); } if ( DRM_COPY_FROM_USER( buffer, depth->buffer, buffer_size ) ) { - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); - DRM_FREE( buffer, buffer_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); + DRM(free)( buffer, buffer_size, DRM_MEM_BUFS ); return DRM_ERR(EFAULT); } if ( depth->mask ) { mask_size = depth->n * sizeof(u8); - mask = DRM_MALLOC( mask_size ); + mask = DRM(alloc)( mask_size, DRM_MEM_BUFS ); if ( mask == NULL ) { - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); - DRM_FREE( buffer, buffer_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); + DRM(free)( buffer, buffer_size, DRM_MEM_BUFS ); return DRM_ERR(ENOMEM); } if ( DRM_COPY_FROM_USER( mask, depth->mask, mask_size ) ) { - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); - DRM_FREE( buffer, buffer_size ); - DRM_FREE( mask, mask_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); + DRM(free)( buffer, buffer_size, DRM_MEM_BUFS ); + DRM(free)( mask, mask_size, DRM_MEM_BUFS ); return DRM_ERR(EFAULT); } @@ -1090,7 +1090,7 @@ static int r128_cce_dispatch_write_pixels( drm_device_t *dev, } } - DRM_FREE( mask, mask_size ); + DRM(free)( mask, mask_size, DRM_MEM_BUFS ); } else { for ( i = 0 ; i < count ; i++ ) { BEGIN_RING( 6 ); @@ -1114,9 +1114,9 @@ static int r128_cce_dispatch_write_pixels( drm_device_t *dev, } } - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); - DRM_FREE( buffer, buffer_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); + DRM(free)( buffer, buffer_size, DRM_MEM_BUFS ); return 0; } @@ -1184,23 +1184,23 @@ static int r128_cce_dispatch_read_pixels( drm_device_t *dev, xbuf_size = count * sizeof(*x); ybuf_size = count * sizeof(*y); - x = DRM_MALLOC( xbuf_size ); + x = DRM(alloc)( xbuf_size, DRM_MEM_BUFS ); if ( x == NULL ) { return DRM_ERR(ENOMEM); } - y = DRM_MALLOC( ybuf_size ); + y = DRM(alloc)( ybuf_size, DRM_MEM_BUFS ); if ( y == NULL ) { - DRM_FREE( x, xbuf_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); return DRM_ERR(ENOMEM); } if ( DRM_COPY_FROM_USER( x, depth->x, xbuf_size ) ) { - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); return DRM_ERR(EFAULT); } if ( DRM_COPY_FROM_USER( y, depth->y, ybuf_size ) ) { - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); return DRM_ERR(EFAULT); } @@ -1228,8 +1228,8 @@ static int r128_cce_dispatch_read_pixels( drm_device_t *dev, ADVANCE_RING(); } - DRM_FREE( x, xbuf_size ); - DRM_FREE( y, ybuf_size ); + DRM(free)( x, xbuf_size, DRM_MEM_BUFS ); + DRM(free)( y, ybuf_size, DRM_MEM_BUFS ); return 0; } diff --git a/shared-core/radeon_mem.c b/shared-core/radeon_mem.c index 28995740..9d7fded7 100644 --- a/shared-core/radeon_mem.c +++ b/shared-core/radeon_mem.c @@ -44,7 +44,7 @@ static struct mem_block *split_block(struct mem_block *p, int start, int size, { /* Maybe cut off the start of an existing block */ if (start > p->start) { - struct mem_block *newblock = DRM_MALLOC(sizeof(*newblock)); + struct mem_block *newblock = DRM(alloc)(sizeof(*newblock), DRM_MEM_BUFS ); if (!newblock) goto out; newblock->start = start; @@ -60,7 +60,7 @@ static struct mem_block *split_block(struct mem_block *p, int start, int size, /* Maybe cut off the end of an existing block */ if (size < p->size) { - struct mem_block *newblock = DRM_MALLOC(sizeof(*newblock)); + struct mem_block *newblock = DRM(alloc)(sizeof(*newblock), DRM_MEM_BUFS ); if (!newblock) goto out; newblock->start = start + size; @@ -118,7 +118,7 @@ static void free_block( struct mem_block *p ) p->size += q->size; p->next = q->next; p->next->prev = p; - DRM_FREE(q, sizeof(*q)); + DRM(free)(q, sizeof(*q), DRM_MEM_BUFS ); } if (p->prev->filp == 0) { @@ -126,7 +126,7 @@ static void free_block( struct mem_block *p ) q->size += p->size; q->next = p->next; q->next->prev = q; - DRM_FREE(p, sizeof(*q)); + DRM(free)(p, sizeof(*q), DRM_MEM_BUFS ); } } @@ -134,14 +134,14 @@ static void free_block( struct mem_block *p ) */ static int init_heap(struct mem_block **heap, int start, int size) { - struct mem_block *blocks = DRM_MALLOC(sizeof(*blocks)); + struct mem_block *blocks = DRM(alloc)(sizeof(*blocks), DRM_MEM_BUFS ); if (!blocks) return DRM_ERR(ENOMEM); - *heap = DRM_MALLOC(sizeof(**heap)); + *heap = DRM(alloc)(sizeof(**heap), DRM_MEM_BUFS ); if (!*heap) { - DRM_FREE( blocks, sizeof(*blocks) ); + DRM(free)( blocks, sizeof(*blocks), DRM_MEM_BUFS ); return DRM_ERR(ENOMEM); } @@ -180,7 +180,7 @@ void radeon_mem_release( DRMFILE filp, struct mem_block *heap ) p->size += q->size; p->next = q->next; p->next->prev = p; - DRM_FREE(q, sizeof(*q)); + DRM(free)(q, sizeof(*q),DRM_MEM_DRIVER); } } } @@ -197,10 +197,10 @@ void radeon_mem_takedown( struct mem_block **heap ) for (p = (*heap)->next ; p != *heap ; ) { struct mem_block *q = p; p = p->next; - DRM_FREE(q, sizeof(*q)); + DRM(free)(q, sizeof(*q),DRM_MEM_DRIVER); } - DRM_FREE( *heap, sizeof(**heap) ); + DRM(free)( *heap, sizeof(**heap),DRM_MEM_DRIVER ); *heap = NULL; } diff --git a/shared-core/radeon_state.c b/shared-core/radeon_state.c index cdbd7a8e..e67bdc0f 100644 --- a/shared-core/radeon_state.c +++ b/shared-core/radeon_state.c @@ -1441,7 +1441,8 @@ static int radeon_cp_dispatch_texture( DRMFILE filp, } if ( !buf ) { DRM_DEBUG("radeon_cp_dispatch_texture: EAGAIN\n"); - DRM_COPY_TO_USER( tex->image, image, sizeof(*image) ); + if (DRM_COPY_TO_USER( tex->image, image, sizeof(*image) )) + return DRM_ERR(EFAULT); return DRM_ERR(EAGAIN); } diff --git a/shared-core/via_ds.c b/shared-core/via_ds.c index ca99a1ed..a29204ce 100644 --- a/shared-core/via_ds.c +++ b/shared-core/via_ds.c @@ -38,7 +38,7 @@ set_t *via_setInit(void) { int i; set_t *set; - set = (set_t *)DRM_MALLOC(sizeof(set_t)); + set = (set_t *)DRM(alloc)(sizeof(set_t), DRM_MEM_DRIVER); for (i = 0; i < SET_SIZE; i++) { set->list[i].free_next = i+1; set->list[i].alloc_next = -1; @@ -120,7 +120,7 @@ int via_setNext(set_t *set, ITEM_TYPE *item) int via_setDestroy(set_t *set) { - DRM_FREE(set, sizeof(set_t)); + DRM(free)(set, sizeof(set_t), DRM_MEM_DRIVER); return 1; } @@ -130,15 +130,6 @@ int via_setDestroy(set_t *set) #define PRINTF(fmt, arg...) do{}while(0) #define fprintf(fmt, arg...) do{}while(0) -static void *calloc(size_t nmemb, size_t size) -{ - void *addr; - addr = kmalloc(nmemb*size, GFP_KERNEL); - memset(addr, 0, nmemb*size); - return addr; -} -#define free(n) kfree(n) - void via_mmDumpMemInfo( memHeap_t *heap ) { TMemBlock *p; @@ -170,7 +161,7 @@ memHeap_t *via_mmInit(int ofs, return 0; - blocks = (TMemBlock *)calloc(1,sizeof(TMemBlock)); + blocks = (TMemBlock *)DRM(calloc)(1,sizeof(TMemBlock),DRM_MEM_DRIVER); if (blocks) { blocks->ofs = ofs; @@ -186,7 +177,7 @@ memHeap_t *via_mmAddRange(memHeap_t *heap, int size) { PMemBlock blocks; - blocks = (TMemBlock *) calloc(2,sizeof(TMemBlock)); + blocks = (TMemBlock *)DRM(calloc)(2,sizeof(TMemBlock),DRM_MEM_DRIVER); if (blocks) { blocks[0].size = size; @@ -215,7 +206,7 @@ static TMemBlock* SliceBlock(TMemBlock *p, /* break left */ if (startofs > p->ofs) { - newblock = (TMemBlock*)calloc(1,sizeof(TMemBlock)); + newblock = (TMemBlock*)DRM(calloc)(1,sizeof(TMemBlock),DRM_MEM_DRIVER); newblock->ofs = startofs; newblock->size = p->size - (startofs - p->ofs); newblock->free = 1; @@ -227,7 +218,7 @@ static TMemBlock* SliceBlock(TMemBlock *p, /* break right */ if (size < p->size) { - newblock = (TMemBlock*) calloc(1,sizeof(TMemBlock)); + newblock = (TMemBlock*)DRM(calloc)(1,sizeof(TMemBlock),DRM_MEM_DRIVER); newblock->ofs = startofs + size; newblock->size = p->size - size; newblock->free = 1; @@ -286,7 +277,7 @@ static __inline__ int Join2Blocks(TMemBlock *p) TMemBlock *q = p->next; p->size += q->size; p->next = q->next; - free(q); + DRM(free)(q,sizeof(TMemBlock),DRM_MEM_DRIVER); return 1; } @@ -393,7 +384,7 @@ void via_mmDestroy(memHeap_t *heap) while (p) { q = p->next; - free(p); + DRM(free)(p,sizeof(TMemBlock),DRM_MEM_DRIVER); p = q; } } -- cgit v1.2.3