|
50 | 50 | #define CREATE_TRACE_POINTS |
51 | 51 | #include <trace/events/swiotlb.h> |
52 | 52 |
|
53 | | -#define OFFSET(val,align) ((unsigned long) \ |
54 | | - ( (val) & ( (align) - 1))) |
55 | | - |
56 | 53 | #define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT)) |
57 | 54 |
|
58 | 55 | /* |
@@ -176,6 +173,11 @@ void swiotlb_print_info(void) |
176 | 173 | bytes >> 20); |
177 | 174 | } |
178 | 175 |
|
| 176 | +static inline unsigned long io_tlb_offset(unsigned long val) |
| 177 | +{ |
| 178 | + return val & (IO_TLB_SEGSIZE - 1); |
| 179 | +} |
| 180 | + |
179 | 181 | /* |
180 | 182 | * Early SWIOTLB allocation may be too early to allow an architecture to |
181 | 183 | * perform the desired operations. This function allows the architecture to |
@@ -225,7 +227,7 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) |
225 | 227 | __func__, alloc_size, PAGE_SIZE); |
226 | 228 |
|
227 | 229 | for (i = 0; i < io_tlb_nslabs; i++) { |
228 | | - io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); |
| 230 | + io_tlb_list[i] = IO_TLB_SEGSIZE - io_tlb_offset(i); |
229 | 231 | io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; |
230 | 232 | } |
231 | 233 | io_tlb_index = 0; |
@@ -359,7 +361,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) |
359 | 361 | goto cleanup4; |
360 | 362 |
|
361 | 363 | for (i = 0; i < io_tlb_nslabs; i++) { |
362 | | - io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); |
| 364 | + io_tlb_list[i] = IO_TLB_SEGSIZE - io_tlb_offset(i); |
363 | 365 | io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; |
364 | 366 | } |
365 | 367 | io_tlb_index = 0; |
@@ -530,7 +532,9 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, |
530 | 532 |
|
531 | 533 | for (i = index; i < (int) (index + nslots); i++) |
532 | 534 | io_tlb_list[i] = 0; |
533 | | - for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE - 1) && io_tlb_list[i]; i--) |
| 535 | + for (i = index - 1; |
| 536 | + io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 && |
| 537 | + io_tlb_list[i]; i--) |
534 | 538 | io_tlb_list[i] = ++count; |
535 | 539 | tlb_addr = io_tlb_start + (index << IO_TLB_SHIFT); |
536 | 540 |
|
@@ -616,7 +620,9 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, |
616 | 620 | * Step 2: merge the returned slots with the preceding slots, |
617 | 621 | * if available (non zero) |
618 | 622 | */ |
619 | | - for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE -1) && io_tlb_list[i]; i--) |
| 623 | + for (i = index - 1; |
| 624 | + io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 && |
| 625 | + io_tlb_list[i]; i--) |
620 | 626 | io_tlb_list[i] = ++count; |
621 | 627 |
|
622 | 628 | io_tlb_used -= nslots; |
|
0 commit comments