History

swiotlb: factor out a nr_slots helper

Factor out a helper to find the number of slots for a given size.

Christoph Hellwig committed 5 years ago

Commit c32a77f1 parent c7fbeca1 file · +9 −4Browse files

Unified · Split

kernel/dma/swiotlb.c+9−4
@@ -194,6 +194,11 @@ static inline unsigned long io_tlb_offset(unsigned long val) · 193 unmodified lines
194194 return val & (IO_TLB_SEGSIZE - 1);
195195 }
196196
197+static inline unsigned long nr_slots(u64 val)
198+{
199+ return DIV_ROUND_UP(val, IO_TLB_SIZE);
200+}
201+
197202 /*
198203 * Early SWIOTLB allocation may be too early to allow an architecture to
199204 * perform the desired operations. This function allows the architecture to
@@ -493,20 +498,20 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, · 293 unmodified lines
493498
494499 tbl_dma_addr &= mask;
495500
496− offset_slots = ALIGN(tbl_dma_addr, IO_TLB_SIZE) >> IO_TLB_SHIFT;
501+ offset_slots = nr_slots(tbl_dma_addr);
497502
498503 /*
499504 * Carefully handle integer overflow which can occur when mask == ~0UL.
500505 */
501506 max_slots = mask + 1
502− ? ALIGN(mask + 1, IO_TLB_SIZE) >> IO_TLB_SHIFT
507+ ? nr_slots(mask + 1)
503508 : 1UL << (BITS_PER_LONG - IO_TLB_SHIFT);
504509
505510 /*
506511 * For mappings greater than or equal to a page, we limit the stride
507512 * (and hence alignment) to a page size.
508513 */
509− nslots = ALIGN(alloc_size, IO_TLB_SIZE) >> IO_TLB_SHIFT;
514+ nslots = nr_slots(alloc_size);
510515 if (alloc_size >= PAGE_SIZE)
511516 stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT));
512517 else
@@ -602,7 +607,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, · 89 unmodified lines
602607 enum dma_data_direction dir, unsigned long attrs)
603608 {
604609 unsigned long flags;
605− int i, count, nslots = ALIGN(alloc_size, IO_TLB_SIZE) >> IO_TLB_SHIFT;
610+ int i, count, nslots = nr_slots(alloc_size);
606611 int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT;
607612 phys_addr_t orig_addr = io_tlb_orig_addr[index];
608613

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t