Skip to content

Commit 158dbe9

Browse files
Petr TesarikChristoph Hellwig
authored andcommitted
swiotlb: separate memory pool data from other allocator data
Carve out memory pool specific fields from struct io_tlb_mem. The original struct now contains shared data for the whole allocator, while the new struct io_tlb_pool contains data that is specific to one memory pool of (potentially) many. Signed-off-by: Petr Tesarik <petr.tesarik.ext@huawei.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent fea1877 commit 158dbe9

File tree

3 files changed

+140
-82
lines changed

3 files changed

+140
-82
lines changed

include/linux/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ struct device_physical_location {
625625
* @dma_pools: Dma pools (if dma'ble device).
626626
* @dma_mem: Internal for coherent mem override.
627627
* @cma_area: Contiguous memory area for dma allocations
628-
* @dma_io_tlb_mem: Pointer to the swiotlb pool used. Not for driver use.
628+
* @dma_io_tlb_mem: Software IO TLB allocator. Not for driver use.
629629
* @archdata: For arch-specific additions.
630630
* @of_node: Associated device tree node.
631631
* @fwnode: Associated device node supplied by platform firmware.

include/linux/swiotlb.h

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t phys,
6262
#ifdef CONFIG_SWIOTLB
6363

6464
/**
65-
* struct io_tlb_mem - IO TLB Memory Pool Descriptor
66-
*
65+
* struct io_tlb_pool - IO TLB memory pool descriptor
6766
* @start: The start address of the swiotlb memory pool. Used to do a quick
6867
* range check to see if the memory was in fact allocated by this
6968
* API.
@@ -73,34 +72,46 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t phys,
7372
* @vaddr: The vaddr of the swiotlb memory pool. The swiotlb memory pool
7473
* may be remapped in the memory encrypted case and store virtual
7574
* address for bounce buffer operation.
76-
* @nslabs: The number of IO TLB blocks (in groups of 64) between @start and
77-
* @end. For default swiotlb, this is command line adjustable via
78-
* setup_io_tlb_npages.
75+
* @nslabs: The number of IO TLB slots between @start and @end. For the
76+
* default swiotlb, this can be adjusted with a boot parameter,
77+
* see setup_io_tlb_npages().
78+
* @late_alloc: %true if allocated using the page allocator.
79+
* @nareas: Number of areas in the pool.
80+
* @area_nslabs: Number of slots in each area.
81+
* @areas: Array of memory area descriptors.
82+
* @slots: Array of slot descriptors.
83+
*/
84+
struct io_tlb_pool {
85+
phys_addr_t start;
86+
phys_addr_t end;
87+
void *vaddr;
88+
unsigned long nslabs;
89+
bool late_alloc;
90+
unsigned int nareas;
91+
unsigned int area_nslabs;
92+
struct io_tlb_area *areas;
93+
struct io_tlb_slot *slots;
94+
};
95+
96+
/**
97+
* struct io_tlb_mem - Software IO TLB allocator
98+
* @defpool: Default (initial) IO TLB memory pool descriptor.
99+
* @nslabs: Total number of IO TLB slabs in all pools.
79100
* @debugfs: The dentry to debugfs.
80-
* @late_alloc: %true if allocated using the page allocator
81101
* @force_bounce: %true if swiotlb bouncing is forced
82102
* @for_alloc: %true if the pool is used for memory allocation
83-
* @nareas: The area number in the pool.
84-
* @area_nslabs: The slot number in the area.
85103
* @total_used: The total number of slots in the pool that are currently used
86104
* across all areas. Used only for calculating used_hiwater in
87105
* debugfs.
88106
* @used_hiwater: The high water mark for total_used. Used only for reporting
89107
* in debugfs.
90108
*/
91109
struct io_tlb_mem {
92-
phys_addr_t start;
93-
phys_addr_t end;
94-
void *vaddr;
110+
struct io_tlb_pool defpool;
95111
unsigned long nslabs;
96112
struct dentry *debugfs;
97-
bool late_alloc;
98113
bool force_bounce;
99114
bool for_alloc;
100-
unsigned int nareas;
101-
unsigned int area_nslabs;
102-
struct io_tlb_area *areas;
103-
struct io_tlb_slot *slots;
104115
#ifdef CONFIG_DEBUG_FS
105116
atomic_long_t total_used;
106117
atomic_long_t used_hiwater;
@@ -122,7 +133,7 @@ static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
122133
{
123134
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
124135

125-
return mem && paddr >= mem->start && paddr < mem->end;
136+
return mem && paddr >= mem->defpool.start && paddr < mem->defpool.end;
126137
}
127138

128139
static inline bool is_swiotlb_force_bounce(struct device *dev)

0 commit comments

Comments
 (0)