Commit e47234d3 authored by Dave Airlie's avatar Dave Airlie

drm: memory allocation patch

This removes some unnecessary macros for allocating DRM memory.
It doesn't change any functionality.

From: Jon Smirl <jonsmirl@gmail.com>
Signed-off-by: default avatarDave Airlie <airlied@linux.ie>
parent 69fbc509
......@@ -34,6 +34,8 @@
#ifndef _DRM_P_H_
#define _DRM_P_H_
/* If you want the memory alloc debug functionality, change define below */
/* #define DEBUG_MEMORY */
#ifdef __KERNEL__
#ifdef __alpha__
......@@ -765,11 +767,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);
......@@ -984,6 +984,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);
......
......@@ -300,7 +300,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;
}
......@@ -356,7 +356,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--;
}
......
......@@ -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
#if __OS_HAS_AGP
......@@ -197,7 +195,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
......@@ -226,13 +224,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;
......@@ -256,12 +248,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.
*
......
......@@ -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;
......
......@@ -100,11 +100,6 @@ static __inline__ int mtrr_del (int reg, unsigned long base,
__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
/**
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -1440,7 +1440,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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment