diff options
-rw-r--r-- | kernel/dma/swiotlb.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 1d8b37747bf0..bedc9f945836 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c | |||
@@ -34,6 +34,9 @@ | |||
34 | #include <linux/scatterlist.h> | 34 | #include <linux/scatterlist.h> |
35 | #include <linux/mem_encrypt.h> | 35 | #include <linux/mem_encrypt.h> |
36 | #include <linux/set_memory.h> | 36 | #include <linux/set_memory.h> |
37 | #ifdef CONFIG_DEBUG_FS | ||
38 | #include <linux/debugfs.h> | ||
39 | #endif | ||
37 | 40 | ||
38 | #include <asm/io.h> | 41 | #include <asm/io.h> |
39 | #include <asm/dma.h> | 42 | #include <asm/dma.h> |
@@ -73,6 +76,11 @@ phys_addr_t io_tlb_start, io_tlb_end; | |||
73 | static unsigned long io_tlb_nslabs; | 76 | static unsigned long io_tlb_nslabs; |
74 | 77 | ||
75 | /* | 78 | /* |
79 | * The number of used IO TLB block | ||
80 | */ | ||
81 | static unsigned long io_tlb_used; | ||
82 | |||
83 | /* | ||
76 | * This is a free list describing the number of free entries available from | 84 | * This is a free list describing the number of free entries available from |
77 | * each index | 85 | * each index |
78 | */ | 86 | */ |
@@ -524,6 +532,7 @@ not_found: | |||
524 | dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes)\n", size); | 532 | dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes)\n", size); |
525 | return DMA_MAPPING_ERROR; | 533 | return DMA_MAPPING_ERROR; |
526 | found: | 534 | found: |
535 | io_tlb_used += nslots; | ||
527 | spin_unlock_irqrestore(&io_tlb_lock, flags); | 536 | spin_unlock_irqrestore(&io_tlb_lock, flags); |
528 | 537 | ||
529 | /* | 538 | /* |
@@ -584,6 +593,8 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, | |||
584 | */ | 593 | */ |
585 | for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE -1) && io_tlb_list[i]; i--) | 594 | for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE -1) && io_tlb_list[i]; i--) |
586 | io_tlb_list[i] = ++count; | 595 | io_tlb_list[i] = ++count; |
596 | |||
597 | io_tlb_used -= nslots; | ||
587 | } | 598 | } |
588 | spin_unlock_irqrestore(&io_tlb_lock, flags); | 599 | spin_unlock_irqrestore(&io_tlb_lock, flags); |
589 | } | 600 | } |
@@ -662,3 +673,36 @@ swiotlb_dma_supported(struct device *hwdev, u64 mask) | |||
662 | { | 673 | { |
663 | return __phys_to_dma(hwdev, io_tlb_end - 1) <= mask; | 674 | return __phys_to_dma(hwdev, io_tlb_end - 1) <= mask; |
664 | } | 675 | } |
676 | |||
677 | #ifdef CONFIG_DEBUG_FS | ||
678 | |||
679 | static int __init swiotlb_create_debugfs(void) | ||
680 | { | ||
681 | static struct dentry *d_swiotlb_usage; | ||
682 | struct dentry *ent; | ||
683 | |||
684 | d_swiotlb_usage = debugfs_create_dir("swiotlb", NULL); | ||
685 | |||
686 | if (!d_swiotlb_usage) | ||
687 | return -ENOMEM; | ||
688 | |||
689 | ent = debugfs_create_ulong("io_tlb_nslabs", 0400, | ||
690 | d_swiotlb_usage, &io_tlb_nslabs); | ||
691 | if (!ent) | ||
692 | goto fail; | ||
693 | |||
694 | ent = debugfs_create_ulong("io_tlb_used", 0400, | ||
695 | d_swiotlb_usage, &io_tlb_used); | ||
696 | if (!ent) | ||
697 | goto fail; | ||
698 | |||
699 | return 0; | ||
700 | |||
701 | fail: | ||
702 | debugfs_remove_recursive(d_swiotlb_usage); | ||
703 | return -ENOMEM; | ||
704 | } | ||
705 | |||
706 | late_initcall(swiotlb_create_debugfs); | ||
707 | |||
708 | #endif | ||