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

Showing the changes to kernel (1 of 1 file). Show all

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
194 return val & (IO_TLB_SEGSIZE - 1);194 return val & (IO_TLB_SEGSIZE - 1);
195}195}
196 196
197static inline unsigned long nr_slots(u64 val)
198{
199 return DIV_ROUND_UP(val, IO_TLB_SIZE);
200}
201
197/*202/*
198 * Early SWIOTLB allocation may be too early to allow an architecture to203 * Early SWIOTLB allocation may be too early to allow an architecture to
199 * perform the desired operations. This function allows the architecture to204 * 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
493 498
494 tbl_dma_addr &= mask;499 tbl_dma_addr &= mask;
495 500
496 offset_slots = ALIGN(tbl_dma_addr, IO_TLB_SIZE) >> IO_TLB_SHIFT;501 offset_slots = nr_slots(tbl_dma_addr);
497 502
498 /*503 /*
499 * Carefully handle integer overflow which can occur when mask == ~0UL.504 * Carefully handle integer overflow which can occur when mask == ~0UL.
500 */505 */
501 max_slots = mask + 1506 max_slots = mask + 1
502 ? ALIGN(mask + 1, IO_TLB_SIZE) >> IO_TLB_SHIFT507 ? nr_slots(mask + 1)
503 : 1UL << (BITS_PER_LONG - IO_TLB_SHIFT);508 : 1UL << (BITS_PER_LONG - IO_TLB_SHIFT);
504 509
505 /*510 /*
506 * For mappings greater than or equal to a page, we limit the stride511 * For mappings greater than or equal to a page, we limit the stride
507 * (and hence alignment) to a page size.512 * (and hence alignment) to a page size.
508 */513 */
509 nslots = ALIGN(alloc_size, IO_TLB_SIZE) >> IO_TLB_SHIFT;514 nslots = nr_slots(alloc_size);
510 if (alloc_size >= PAGE_SIZE)515 if (alloc_size >= PAGE_SIZE)
511 stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT));516 stride = (1 << (PAGE_SHIFT - IO_TLB_SHIFT));
512 else517 else
@@ -602,7 +607,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, · 89 unmodified lines
602 enum dma_data_direction dir, unsigned long attrs)607 enum dma_data_direction dir, unsigned long attrs)
603{608{
604 unsigned long flags;609 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);
606 int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT;611 int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT;
607 phys_addr_t orig_addr = io_tlb_orig_addr[index];612 phys_addr_t orig_addr = io_tlb_orig_addr[index];
608 613

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