swiotlb: add a IO_TLB_SIZE define

Add a new IO_TLB_SIZE define instead open coding it using
IO_TLB_SHIFT all over.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jianxiong Gao <jxgao@google.com>
Tested-by: Jianxiong Gao <jxgao@google.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
This commit is contained in:
Christoph Hellwig 2021-02-05 11:18:40 +01:00 committed by Konrad Rzeszutek Wilk
parent 36950f2da1
commit b5d7ccb7aa
2 changed files with 8 additions and 7 deletions

View File

@ -29,6 +29,7 @@ enum swiotlb_force {
* controllable. * controllable.
*/ */
#define IO_TLB_SHIFT 11 #define IO_TLB_SHIFT 11
#define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
/* default to 64MB */ /* default to 64MB */
#define IO_TLB_DEFAULT_SIZE (64UL<<20) #define IO_TLB_DEFAULT_SIZE (64UL<<20)

View File

@ -171,7 +171,7 @@ void __init swiotlb_adjust_size(unsigned long new_size)
* adjust/expand SWIOTLB size for their use. * adjust/expand SWIOTLB size for their use.
*/ */
if (!io_tlb_nslabs) { if (!io_tlb_nslabs) {
size = ALIGN(new_size, 1 << IO_TLB_SHIFT); size = ALIGN(new_size, IO_TLB_SIZE);
io_tlb_nslabs = size >> IO_TLB_SHIFT; io_tlb_nslabs = size >> IO_TLB_SHIFT;
io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
@ -491,20 +491,20 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr,
tbl_dma_addr &= mask; tbl_dma_addr &= mask;
offset_slots = ALIGN(tbl_dma_addr, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT; offset_slots = ALIGN(tbl_dma_addr, IO_TLB_SIZE) >> IO_TLB_SHIFT;
/* /*
* Carefully handle integer overflow which can occur when mask == ~0UL. * Carefully handle integer overflow which can occur when mask == ~0UL.
*/ */
max_slots = mask + 1 max_slots = mask + 1
? ALIGN(mask + 1, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT ? ALIGN(mask + 1, IO_TLB_SIZE) >> IO_TLB_SHIFT
: 1UL << (BITS_PER_LONG - IO_TLB_SHIFT); : 1UL << (BITS_PER_LONG - IO_TLB_SHIFT);
/* /*
* For mappings greater than or equal to a page, we limit the stride * For mappings greater than or equal to a page, we limit the stride
* (and hence alignment) to a page size. * (and hence alignment) to a page size.
*/ */
nslots = ALIGN(alloc_size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT; nslots = ALIGN(alloc_size, IO_TLB_SIZE) >> IO_TLB_SHIFT;
if (alloc_size >= PAGE_SIZE) if (alloc_size >= PAGE_SIZE)
stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT)); stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT));
else else
@ -598,7 +598,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,
enum dma_data_direction dir, unsigned long attrs) enum dma_data_direction dir, unsigned long attrs)
{ {
unsigned long flags; unsigned long flags;
int i, count, nslots = ALIGN(alloc_size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT; int i, count, nslots = ALIGN(alloc_size, IO_TLB_SIZE) >> IO_TLB_SHIFT;
int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT; int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT;
phys_addr_t orig_addr = io_tlb_orig_addr[index]; phys_addr_t orig_addr = io_tlb_orig_addr[index];
@ -649,7 +649,7 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,
if (orig_addr == INVALID_PHYS_ADDR) if (orig_addr == INVALID_PHYS_ADDR)
return; return;
orig_addr += (unsigned long)tlb_addr & ((1 << IO_TLB_SHIFT) - 1); orig_addr += (unsigned long)tlb_addr & (IO_TLB_SIZE - 1);
switch (target) { switch (target) {
case SYNC_FOR_CPU: case SYNC_FOR_CPU:
@ -707,7 +707,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
size_t swiotlb_max_mapping_size(struct device *dev) size_t swiotlb_max_mapping_size(struct device *dev)
{ {
return ((size_t)1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE; return ((size_t)IO_TLB_SIZE) * IO_TLB_SEGSIZE;
} }
bool is_swiotlb_active(void) bool is_swiotlb_active(void)