drm-memory patch, cleans up alloc/free and makes calloc look more libc like

main
Dave Airlie 2004-08-30 09:01:50 +00:00
parent 08de6e5b04
commit 7809efc8c3
20 changed files with 196 additions and 214 deletions

View File

@ -85,6 +85,8 @@
#include "drm_os_linux.h"
/* If you want the memory alloc debug functionality, change define below */
/* #define DEBUG_MEMORY */
/***********************************************************************/
/** \name DRM template customization defaults */
@ -726,11 +728,9 @@ extern ssize_t DRM(read)(struct file *filp, char __user *buf, size_t count
extern void DRM(mem_init)(void);
extern int DRM(mem_info)(char *buf, char **start, off_t offset,
int request, int *eof, void *data);
extern void *DRM(alloc)(size_t size, int area);
extern void *DRM(calloc)(size_t nmemb, size_t size, int area);
extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
int area);
extern void DRM(free)(void *pt, size_t size, int area);
extern unsigned long DRM(alloc_pages)(int order, int area);
extern void DRM(free_pages)(unsigned long address, int order,
int area);
@ -958,6 +958,24 @@ static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev, unsig
static __inline__ void drm_core_dropmap(struct drm_map *map)
{
}
#ifndef DEBUG_MEMORY
/** Wrapper around kmalloc() */
static __inline__ void *DRM(alloc)(size_t size, int area)
{
return kmalloc(size, GFP_KERNEL);
}
/** Wrapper around kfree() */
static __inline__ void DRM(free)(void *pt, size_t size, int area)
{
kfree(pt);
}
#else
extern void *DRM(alloc)(size_t size, int area);
extern void DRM(free)(void *pt, size_t size, int area);
#endif
/*@}*/
extern unsigned long DRM(core_get_map_ofs)(drm_map_t *map);

View File

@ -304,7 +304,7 @@ int DRM(wait_vblank)( DRM_IOCTL_ARGS )
spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
if ( !( vbl_sig = DRM_MALLOC( sizeof( drm_vbl_sig_t ) ) ) ) {
if ( !( vbl_sig = DRM(alloc)( sizeof( drm_vbl_sig_t ), DRM_MEM_DRIVER ) ) ) {
return -ENOMEM;
}
@ -360,7 +360,7 @@ void DRM(vbl_send_signals)( drm_device_t *dev )
list_del( list );
DRM_FREE( vbl_sig, sizeof(*vbl_sig) );
DRM(free)( vbl_sig, sizeof(*vbl_sig), DRM_MEM_DRIVER );
dev->vbl_pending--;
}

View File

@ -39,10 +39,8 @@
/**
* Cut down version of drm_memory_debug.h, which used to be called
* drm_memory.h. If you want the debug functionality, change 0 to 1
* below.
* drm_memory.h.
*/
#define DEBUG_MEMORY 0
/* Need the 4-argument version of vmap(). */
#if __OS_HAS_AGP && defined(VMAP_4_ARGS)
@ -199,7 +197,7 @@ static inline void drm_ioremapfree(void *pt, unsigned long size, drm_device_t *d
}
#if DEBUG_MEMORY
#ifdef DEBUG_MEMORY
#include "drm_memory_debug.h"
#else
@ -228,13 +226,7 @@ int DRM(mem_info)(char *buf, char **start, off_t offset,
}
/** Wrapper around kmalloc() */
void *DRM(alloc)(size_t size, int area)
{
return kmalloc(size, GFP_KERNEL);
}
/** Wrapper around kmalloc() */
void *DRM(calloc)(size_t size, size_t nmemb, int area)
void *DRM(calloc)(size_t nmemb, size_t size, int area)
{
void *addr;
@ -258,12 +250,6 @@ void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
return pt;
}
/** Wrapper around kfree() */
void DRM(free)(void *pt, size_t size, int area)
{
kfree(pt);
}
/**
* Allocate pages.
*

View File

@ -167,7 +167,7 @@ void *DRM(alloc)(size_t size, int area)
return pt;
}
void *DRM(calloc)(size_t size, size_t nmemb, int area)
void *DRM(calloc)(size_t nmemb, size_t size, int area)
{
void *addr;

View File

@ -85,11 +85,6 @@ typedef void irqreturn_t;
__put_user(val, uaddr)
/** 'malloc' without the overhead of DRM(alloc)() */
#define DRM_MALLOC(x) kmalloc(x, GFP_KERNEL)
/** 'free' without the overhead of DRM(free)() */
#define DRM_FREE(x,size) kfree(x)
#define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
/**

View File

@ -85,6 +85,8 @@
#include "drm_os_linux.h"
/* If you want the memory alloc debug functionality, change define below */
/* #define DEBUG_MEMORY */
/***********************************************************************/
/** \name DRM template customization defaults */
@ -726,11 +728,9 @@ extern ssize_t DRM(read)(struct file *filp, char __user *buf, size_t count
extern void DRM(mem_init)(void);
extern int DRM(mem_info)(char *buf, char **start, off_t offset,
int request, int *eof, void *data);
extern void *DRM(alloc)(size_t size, int area);
extern void *DRM(calloc)(size_t nmemb, size_t size, int area);
extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
int area);
extern void DRM(free)(void *pt, size_t size, int area);
extern unsigned long DRM(alloc_pages)(int order, int area);
extern void DRM(free_pages)(unsigned long address, int order,
int area);
@ -958,6 +958,24 @@ static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev, unsig
static __inline__ void drm_core_dropmap(struct drm_map *map)
{
}
#ifndef DEBUG_MEMORY
/** Wrapper around kmalloc() */
static __inline__ void *DRM(alloc)(size_t size, int area)
{
return kmalloc(size, GFP_KERNEL);
}
/** Wrapper around kfree() */
static __inline__ void DRM(free)(void *pt, size_t size, int area)
{
kfree(pt);
}
#else
extern void *DRM(alloc)(size_t size, int area);
extern void DRM(free)(void *pt, size_t size, int area);
#endif
/*@}*/
extern unsigned long DRM(core_get_map_ofs)(drm_map_t *map);

View File

@ -304,7 +304,7 @@ int DRM(wait_vblank)( DRM_IOCTL_ARGS )
spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
if ( !( vbl_sig = DRM_MALLOC( sizeof( drm_vbl_sig_t ) ) ) ) {
if ( !( vbl_sig = DRM(alloc)( sizeof( drm_vbl_sig_t ), DRM_MEM_DRIVER ) ) ) {
return -ENOMEM;
}
@ -360,7 +360,7 @@ void DRM(vbl_send_signals)( drm_device_t *dev )
list_del( list );
DRM_FREE( vbl_sig, sizeof(*vbl_sig) );
DRM(free)( vbl_sig, sizeof(*vbl_sig), DRM_MEM_DRIVER );
dev->vbl_pending--;
}

View File

@ -39,10 +39,8 @@
/**
* Cut down version of drm_memory_debug.h, which used to be called
* drm_memory.h. If you want the debug functionality, change 0 to 1
* below.
* drm_memory.h.
*/
#define DEBUG_MEMORY 0
/* Need the 4-argument version of vmap(). */
#if __OS_HAS_AGP && defined(VMAP_4_ARGS)
@ -199,7 +197,7 @@ static inline void drm_ioremapfree(void *pt, unsigned long size, drm_device_t *d
}
#if DEBUG_MEMORY
#ifdef DEBUG_MEMORY
#include "drm_memory_debug.h"
#else
@ -228,13 +226,7 @@ int DRM(mem_info)(char *buf, char **start, off_t offset,
}
/** Wrapper around kmalloc() */
void *DRM(alloc)(size_t size, int area)
{
return kmalloc(size, GFP_KERNEL);
}
/** Wrapper around kmalloc() */
void *DRM(calloc)(size_t size, size_t nmemb, int area)
void *DRM(calloc)(size_t nmemb, size_t size, int area)
{
void *addr;
@ -258,12 +250,6 @@ void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
return pt;
}
/** Wrapper around kfree() */
void DRM(free)(void *pt, size_t size, int area)
{
kfree(pt);
}
/**
* Allocate pages.
*

View File

@ -167,7 +167,7 @@ void *DRM(alloc)(size_t size, int area)
return pt;
}
void *DRM(calloc)(size_t size, size_t nmemb, int area)
void *DRM(calloc)(size_t nmemb, size_t size, int area)
{
void *addr;

View File

@ -85,11 +85,6 @@ typedef void irqreturn_t;
__put_user(val, uaddr)
/** 'malloc' without the overhead of DRM(alloc)() */
#define DRM_MALLOC(x) kmalloc(x, GFP_KERNEL)
/** 'free' without the overhead of DRM(free)() */
#define DRM_FREE(x,size) kfree(x)
#define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
/**

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;
}
}