Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 138918
b: refs/heads/master
c: 6bf0787
h: refs/heads/master
v: v3
  • Loading branch information
Joerg Roedel committed Mar 5, 2009
1 parent b40af4b commit 62471ce
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3b1e79ed734f58ac41ca0a287ff03ca355f120ad
refs/heads/master: 6bf078715c1998d4d10716251cc10ce45908594c
14 changes: 14 additions & 0 deletions trunk/include/linux/dma-debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
#ifndef __DMA_DEBUG_H
#define __DMA_DEBUG_H

#include <linux/types.h>

struct device;

#ifdef CONFIG_DMA_API_DEBUG

extern void dma_debug_init(u32 num_entries);

#else /* CONFIG_DMA_API_DEBUG */

static inline void dma_debug_init(u32 num_entries)
{
}

#endif /* CONFIG_DMA_API_DEBUG */

#endif /* __DMA_DEBUG_H */
66 changes: 66 additions & 0 deletions trunk/lib/dma-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/spinlock.h>
#include <linux/types.h>
#include <linux/list.h>
#include <linux/slab.h>

#define HASH_SIZE 1024ULL
#define HASH_FN_SHIFT 13
Expand Down Expand Up @@ -198,3 +199,68 @@ static void dma_entry_free(struct dma_debug_entry *entry)
spin_unlock_irqrestore(&free_entries_lock, flags);
}

/*
* DMA-API debugging init code
*
* The init code does two things:
* 1. Initialize core data structures
* 2. Preallocate a given number of dma_debug_entry structs
*/

static int prealloc_memory(u32 num_entries)
{
struct dma_debug_entry *entry, *next_entry;
int i;

for (i = 0; i < num_entries; ++i) {
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
if (!entry)
goto out_err;

list_add_tail(&entry->list, &free_entries);
}

num_free_entries = num_entries;
min_free_entries = num_entries;

printk(KERN_INFO "DMA-API: preallocated %d debug entries\n",
num_entries);

return 0;

out_err:

list_for_each_entry_safe(entry, next_entry, &free_entries, list) {
list_del(&entry->list);
kfree(entry);
}

return -ENOMEM;
}

/*
* Let the architectures decide how many entries should be preallocated.
*/
void dma_debug_init(u32 num_entries)
{
int i;

if (global_disable)
return;

for (i = 0; i < HASH_SIZE; ++i) {
INIT_LIST_HEAD(&dma_entry_hash[i].list);
dma_entry_hash[i].lock = SPIN_LOCK_UNLOCKED;
}

if (prealloc_memory(num_entries) != 0) {
printk(KERN_ERR "DMA-API: debugging out of memory error "
"- disabled\n");
global_disable = true;

return;
}

printk(KERN_INFO "DMA-API: debugging enabled by kernel config\n");
}

0 comments on commit 62471ce

Please sign in to comment.