aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2009-01-09 08:19:54 -0500
committerJoerg Roedel <joerg.roedel@amd.com>2009-03-05 14:35:18 -0500
commit972aa45ceaf65376f33aa75958fcaefc9e752fa4 (patch)
treeffed83c13c7c0e27f39efe0c0cc81f2c9e6c72c6 /lib
parentf62bc980e6fd26434012c0d5676ecb17179d9ee4 (diff)
dma-debug: add add checking for map/unmap_sg
Impact: add debug callbacks for dma_{un}map_sg Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/dma-debug.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index a2ed2b769685..26e40e93e0f2 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -17,6 +17,7 @@
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20#include <linux/scatterlist.h>
20#include <linux/dma-mapping.h> 21#include <linux/dma-mapping.h>
21#include <linux/dma-debug.h> 22#include <linux/dma-debug.h>
22#include <linux/spinlock.h> 23#include <linux/spinlock.h>
@@ -619,3 +620,75 @@ void debug_dma_unmap_page(struct device *dev, dma_addr_t addr,
619} 620}
620EXPORT_SYMBOL(debug_dma_unmap_page); 621EXPORT_SYMBOL(debug_dma_unmap_page);
621 622
623void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
624 int nents, int mapped_ents, int direction)
625{
626 struct dma_debug_entry *entry;
627 struct scatterlist *s;
628 int i;
629
630 if (unlikely(global_disable))
631 return;
632
633 for_each_sg(sg, s, mapped_ents, i) {
634 entry = dma_entry_alloc();
635 if (!entry)
636 return;
637
638 entry->type = dma_debug_sg;
639 entry->dev = dev;
640 entry->paddr = sg_phys(s);
641 entry->size = s->length;
642 entry->dev_addr = s->dma_address;
643 entry->direction = direction;
644 entry->sg_call_ents = nents;
645 entry->sg_mapped_ents = mapped_ents;
646
647 check_for_stack(dev, sg_virt(s));
648
649 add_dma_entry(entry);
650 }
651}
652EXPORT_SYMBOL(debug_dma_map_sg);
653
654void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
655 int nelems, int dir)
656{
657 struct dma_debug_entry *entry;
658 struct scatterlist *s;
659 int mapped_ents = 0, i;
660 unsigned long flags;
661
662 if (unlikely(global_disable))
663 return;
664
665 for_each_sg(sglist, s, nelems, i) {
666
667 struct dma_debug_entry ref = {
668 .type = dma_debug_sg,
669 .dev = dev,
670 .paddr = sg_phys(s),
671 .dev_addr = s->dma_address,
672 .size = s->length,
673 .direction = dir,
674 .sg_call_ents = 0,
675 };
676
677 if (mapped_ents && i >= mapped_ents)
678 break;
679
680 if (mapped_ents == 0) {
681 struct hash_bucket *bucket;
682 ref.sg_call_ents = nelems;
683 bucket = get_hash_bucket(&ref, &flags);
684 entry = hash_bucket_find(bucket, &ref);
685 if (entry)
686 mapped_ents = entry->sg_mapped_ents;
687 put_hash_bucket(bucket, &flags);
688 }
689
690 check_unmap(&ref);
691 }
692}
693EXPORT_SYMBOL(debug_dma_unmap_sg);
694