62
62
63
63
#define INVALID_PHYS_ADDR (~(phys_addr_t)0)
64
64
65
+ /**
66
+ * struct io_tlb_slot - IO TLB slot descriptor
67
+ * @orig_addr: The original address corresponding to a mapped entry.
68
+ * @alloc_size: Size of the allocated buffer.
69
+ * @list: The free list describing the number of free entries available
70
+ * from each index.
71
+ */
65
72
struct io_tlb_slot {
66
73
phys_addr_t orig_addr ;
67
74
size_t alloc_size ;
@@ -635,11 +642,22 @@ static void dec_used(struct io_tlb_mem *mem, unsigned int nslots)
635
642
}
636
643
#endif /* CONFIG_DEBUG_FS */
637
644
638
- /*
639
- * Find a suitable number of IO TLB entries size that will fit this request and
640
- * allocate a buffer from that IO TLB pool.
645
+ /**
646
+ * swiotlb_area_find_slots() - search for slots in one IO TLB memory area
647
+ * @dev: Device which maps the buffer.
648
+ * @area_index: Index of the IO TLB memory area to be searched.
649
+ * @orig_addr: Original (non-bounced) IO buffer address.
650
+ * @alloc_size: Total requested size of the bounce buffer,
651
+ * including initial alignment padding.
652
+ * @alloc_align_mask: Required alignment of the allocated buffer.
653
+ *
654
+ * Find a suitable sequence of IO TLB entries for the request and allocate
655
+ * a buffer from the given IO TLB memory area.
656
+ * This function takes care of locking.
657
+ *
658
+ * Return: Index of the first allocated slot, or -1 on error.
641
659
*/
642
- static int swiotlb_do_find_slots (struct device * dev , int area_index ,
660
+ static int swiotlb_area_find_slots (struct device * dev , int area_index ,
643
661
phys_addr_t orig_addr , size_t alloc_size ,
644
662
unsigned int alloc_align_mask )
645
663
{
@@ -734,6 +752,19 @@ static int swiotlb_do_find_slots(struct device *dev, int area_index,
734
752
return slot_index ;
735
753
}
736
754
755
+ /**
756
+ * swiotlb_find_slots() - search for slots in the whole swiotlb
757
+ * @dev: Device which maps the buffer.
758
+ * @orig_addr: Original (non-bounced) IO buffer address.
759
+ * @alloc_size: Total requested size of the bounce buffer,
760
+ * including initial alignment padding.
761
+ * @alloc_align_mask: Required alignment of the allocated buffer.
762
+ *
763
+ * Search through the whole software IO TLB to find a sequence of slots that
764
+ * match the allocation constraints.
765
+ *
766
+ * Return: Index of the first allocated slot, or -1 on error.
767
+ */
737
768
static int swiotlb_find_slots (struct device * dev , phys_addr_t orig_addr ,
738
769
size_t alloc_size , unsigned int alloc_align_mask )
739
770
{
@@ -742,8 +773,8 @@ static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr,
742
773
int i = start , index ;
743
774
744
775
do {
745
- index = swiotlb_do_find_slots (dev , i , orig_addr , alloc_size ,
746
- alloc_align_mask );
776
+ index = swiotlb_area_find_slots (dev , i , orig_addr , alloc_size ,
777
+ alloc_align_mask );
747
778
if (index >= 0 )
748
779
return index ;
749
780
if (++ i >= mem -> nareas )
@@ -755,13 +786,31 @@ static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr,
755
786
756
787
#ifdef CONFIG_DEBUG_FS
757
788
789
+ /**
790
+ * mem_used() - get number of used slots in an allocator
791
+ * @mem: Software IO TLB allocator.
792
+ *
793
+ * The result is accurate in this version of the function, because an atomic
794
+ * counter is available if CONFIG_DEBUG_FS is set.
795
+ *
796
+ * Return: Number of used slots.
797
+ */
758
798
static unsigned long mem_used (struct io_tlb_mem * mem )
759
799
{
760
800
return atomic_long_read (& mem -> total_used );
761
801
}
762
802
763
803
#else /* !CONFIG_DEBUG_FS */
764
804
805
+ /**
806
+ * mem_used() - get number of used slots in an allocator
807
+ * @mem: Software IO TLB allocator.
808
+ *
809
+ * The result is not accurate, because there is no locking of individual
810
+ * areas.
811
+ *
812
+ * Return: Approximate number of used slots.
813
+ */
765
814
static unsigned long mem_used (struct io_tlb_mem * mem )
766
815
{
767
816
int i ;
0 commit comments