aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dma-debug.c
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2009-01-09 06:54:42 -0500
committerJoerg Roedel <joerg.roedel@amd.com>2009-03-05 14:35:15 -0500
commit6bf078715c1998d4d10716251cc10ce45908594c (patch)
treeae975ed487463ff9b82f9f8f3fbc1871f514f03b /lib/dma-debug.c
parent3b1e79ed734f58ac41ca0a287ff03ca355f120ad (diff)
dma-debug: add initialization code
Impact: add code to initialize dma-debug core data structures Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Diffstat (limited to 'lib/dma-debug.c')
-rw-r--r--lib/dma-debug.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index b6091466965..5b50bb31f7c 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -21,6 +21,7 @@
21#include <linux/spinlock.h> 21#include <linux/spinlock.h>
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/slab.h>
24 25
25#define HASH_SIZE 1024ULL 26#define HASH_SIZE 1024ULL
26#define HASH_FN_SHIFT 13 27#define HASH_FN_SHIFT 13
@@ -198,3 +199,68 @@ static void dma_entry_free(struct dma_debug_entry *entry)
198 spin_unlock_irqrestore(&free_entries_lock, flags); 199 spin_unlock_irqrestore(&free_entries_lock, flags);
199} 200}
200 201
202/*
203 * DMA-API debugging init code
204 *
205 * The init code does two things:
206 * 1. Initialize core data structures
207 * 2. Preallocate a given number of dma_debug_entry structs
208 */
209
210static int prealloc_memory(u32 num_entries)
211{
212 struct dma_debug_entry *entry, *next_entry;
213 int i;
214
215 for (i = 0; i < num_entries; ++i) {
216 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
217 if (!entry)
218 goto out_err;
219
220 list_add_tail(&entry->list, &free_entries);
221 }
222
223 num_free_entries = num_entries;
224 min_free_entries = num_entries;
225
226 printk(KERN_INFO "DMA-API: preallocated %d debug entries\n",
227 num_entries);
228
229 return 0;
230
231out_err:
232
233 list_for_each_entry_safe(entry, next_entry, &free_entries, list) {
234 list_del(&entry->list);
235 kfree(entry);
236 }
237
238 return -ENOMEM;
239}
240
241/*
242 * Let the architectures decide how many entries should be preallocated.
243 */
244void dma_debug_init(u32 num_entries)
245{
246 int i;
247
248 if (global_disable)
249 return;
250
251 for (i = 0; i < HASH_SIZE; ++i) {
252 INIT_LIST_HEAD(&dma_entry_hash[i].list);
253 dma_entry_hash[i].lock = SPIN_LOCK_UNLOCKED;
254 }
255
256 if (prealloc_memory(num_entries) != 0) {
257 printk(KERN_ERR "DMA-API: debugging out of memory error "
258 "- disabled\n");
259 global_disable = true;
260
261 return;
262 }
263
264 printk(KERN_INFO "DMA-API: debugging enabled by kernel config\n");
265}
266