dma-debug: add function to dump dma mappings
authorDavid Woodhouse <dwmw2@infradead.org>
Thu, 12 Feb 2009 15:19:13 +0000 (16:19 +0100)
committerJoerg Roedel <joerg.roedel@amd.com>
Tue, 17 Mar 2009 11:56:39 +0000 (12:56 +0100)
This adds a function to dump the DMA mappings that the debugging code is
aware of -- either for a single device, or for _all_ devices.

This can be useful for debugging -- sticking a call to it in the DMA
page fault handler, for example, to see if the faulting address _should_
be mapped or not, and hence work out whether it's IOMMU bugs we're
seeing, or driver bugs.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
include/linux/dma-debug.h
lib/dma-debug.c

index 4985c6c..46a11c1 100644 (file)
@@ -76,6 +76,8 @@ extern void debug_dma_sync_sg_for_device(struct device *dev,
                                         struct scatterlist *sg,
                                         int nelems, int direction);
 
+extern void debug_dma_dump_mappings(struct device *dev);
+
 #else /* CONFIG_DMA_API_DEBUG */
 
 static inline void dma_debug_init(u32 num_entries)
@@ -156,6 +158,10 @@ static inline void debug_dma_sync_sg_for_device(struct device *dev,
 {
 }
 
+static inline void debug_dma_dump_mappings(struct device *dev)
+{
+}
+
 #endif /* CONFIG_DMA_API_DEBUG */
 
 #endif /* __DMA_DEBUG_H */
index 9d11e89..91ed1df 100644 (file)
@@ -193,6 +193,36 @@ static void hash_bucket_del(struct dma_debug_entry *entry)
        list_del(&entry->list);
 }
 
+/*
+ * Dump mapping entries for debugging purposes
+ */
+void debug_dma_dump_mappings(struct device *dev)
+{
+       int idx;
+
+       for (idx = 0; idx < HASH_SIZE; idx++) {
+               struct hash_bucket *bucket = &dma_entry_hash[idx];
+               struct dma_debug_entry *entry;
+               unsigned long flags;
+
+               spin_lock_irqsave(&bucket->lock, flags);
+
+               list_for_each_entry(entry, &bucket->list, list) {
+                       if (!dev || dev == entry->dev) {
+                               dev_info(entry->dev,
+                                        "%s idx %d P=%Lx D=%Lx L=%Lx %s\n",
+                                        type2name[entry->type], idx,
+                                        (unsigned long long)entry->paddr,
+                                        entry->dev_addr, entry->size,
+                                        dir2name[entry->direction]);
+                       }
+               }
+
+               spin_unlock_irqrestore(&bucket->lock, flags);
+       }
+}
+EXPORT_SYMBOL(debug_dma_dump_mappings);
+
 /*
  * Wrapper function for adding an entry to the hash.
  * This function takes care of locking itself.