Commit 3386c76a authored by Ben Dooks's avatar Ben Dooks Committed by Russell King

[ARM PATCH] 2506/1: S3C2410 - dma descriptor slab

Patch from Ben Dooks

Use slab allocator instead of kmalloc() to allocate the
dma buffer descriptors. This should allow the tracking
of dma descriptors, and to check if they are being freed
correctly.

Signed-off-by: Ben Dooks
Signed-off-by: Russell King
parent ade4e2cc
/* linux/arch/arm/mach-bast/dma.c /* linux/arch/arm/mach-bast/dma.c
* *
* (c) 2003,2004 Simtec Electronics * (c) 2003-2005 Simtec Electronics
* Ben Dooks <ben@simtec.co.uk> * Ben Dooks <ben@simtec.co.uk>
* *
* S3C2410 DMA core * S3C2410 DMA core
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* Changelog: * Changelog:
* 27-Feb-2005 BJD Added kmem cache for dma descriptors
* 18-Nov-2004 BJD Removed error for loading onto stopped channel * 18-Nov-2004 BJD Removed error for loading onto stopped channel
* 10-Nov-2004 BJD Ensure all external symbols exported for modules * 10-Nov-2004 BJD Ensure all external symbols exported for modules
* 10-Nov-2004 BJD Use sys_device and sysdev_class for power management * 10-Nov-2004 BJD Use sys_device and sysdev_class for power management
...@@ -57,6 +58,7 @@ ...@@ -57,6 +58,7 @@
/* io map for dma */ /* io map for dma */
static void __iomem *dma_base; static void __iomem *dma_base;
static kmem_cache_t *dma_kmem;
/* dma channel state information */ /* dma channel state information */
s3c2410_dma_chan_t s3c2410_chans[S3C2410_DMA_CHANNELS]; s3c2410_dma_chan_t s3c2410_chans[S3C2410_DMA_CHANNELS];
...@@ -432,7 +434,7 @@ int s3c2410_dma_enqueue(unsigned int channel, void *id, ...@@ -432,7 +434,7 @@ int s3c2410_dma_enqueue(unsigned int channel, void *id,
pr_debug("%s: id=%p, data=%08x, size=%d\n", pr_debug("%s: id=%p, data=%08x, size=%d\n",
__FUNCTION__, id, (unsigned int)data, size); __FUNCTION__, id, (unsigned int)data, size);
buf = (s3c2410_dma_buf_t *)kmalloc(sizeof(*buf), GFP_ATOMIC); buf = kmem_cache_alloc(dma_kmem, GFP_ATOMIC);
if (buf == NULL) { if (buf == NULL) {
pr_debug("%s: out of memory (%d alloc)\n", pr_debug("%s: out of memory (%d alloc)\n",
__FUNCTION__, sizeof(*buf)); __FUNCTION__, sizeof(*buf));
...@@ -511,7 +513,7 @@ s3c2410_dma_freebuf(s3c2410_dma_buf_t *buf) ...@@ -511,7 +513,7 @@ s3c2410_dma_freebuf(s3c2410_dma_buf_t *buf)
buf->magic = -1; buf->magic = -1;
if (magicok) { if (magicok) {
kfree(buf); kmem_cache_free(dma_kmem, buf);
} else { } else {
printk("s3c2410_dma_freebuf: buff %p with bad magic\n", buf); printk("s3c2410_dma_freebuf: buff %p with bad magic\n", buf);
} }
...@@ -1128,6 +1130,14 @@ static struct sysdev_class dma_sysclass = { ...@@ -1128,6 +1130,14 @@ static struct sysdev_class dma_sysclass = {
.resume = s3c2410_dma_resume, .resume = s3c2410_dma_resume,
}; };
/* kmem cache implementation */
static void s3c2410_dma_cache_ctor(void *p, kmem_cache_t *c, unsigned long f)
{
memset(p, 0, sizeof(s3c2410_dma_buf_t));
}
/* initialisation code */ /* initialisation code */
static int __init s3c2410_init_dma(void) static int __init s3c2410_init_dma(void)
...@@ -1150,6 +1160,16 @@ static int __init s3c2410_init_dma(void) ...@@ -1150,6 +1160,16 @@ static int __init s3c2410_init_dma(void)
goto err; goto err;
} }
dma_kmem = kmem_cache_create("dma_desc", sizeof(s3c2410_dma_buf_t), 0,
SLAB_HWCACHE_ALIGN,
s3c2410_dma_cache_ctor, NULL);
if (dma_kmem == NULL) {
printk(KERN_ERR "dma failed to make kmem cache\n");
ret = -ENOMEM;
goto err;
}
for (channel = 0; channel < S3C2410_DMA_CHANNELS; channel++) { for (channel = 0; channel < S3C2410_DMA_CHANNELS; channel++) {
cp = &s3c2410_chans[channel]; cp = &s3c2410_chans[channel];
...@@ -1181,6 +1201,7 @@ static int __init s3c2410_init_dma(void) ...@@ -1181,6 +1201,7 @@ static int __init s3c2410_init_dma(void)
return 0; return 0;
err: err:
kmem_cache_destroy(dma_kmem);
iounmap(dma_base); iounmap(dma_base);
dma_base = NULL; dma_base = NULL;
return ret; return ret;
......
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