Skip to content

Commit 1bbcc98

Browse files
Jianxiong Gaogregkh
authored andcommitted
swiotlb: factor out an io_tlb_offset helper
commit: c7fbeca Replace the very genericly named OFFSET macro with a little inline helper that hardcodes the alignment to the only value ever passed. 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> Signed-off-by: Jianxiong Gao <jxgao@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 22163a8 commit 1bbcc98

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

‎kernel/dma/swiotlb.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050
#define CREATE_TRACE_POINTS
5151
#include <trace/events/swiotlb.h>
5252

53-
#define OFFSET(val,align) ((unsigned long) \
54-
( (val) & ( (align) - 1)))
55-
5653
#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
5754

5855
/*
@@ -176,6 +173,11 @@ void swiotlb_print_info(void)
176173
bytes >> 20);
177174
}
178175

176+
static inline unsigned long io_tlb_offset(unsigned long val)
177+
{
178+
return val & (IO_TLB_SEGSIZE - 1);
179+
}
180+
179181
/*
180182
* Early SWIOTLB allocation may be too early to allow an architecture to
181183
* 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)
225227
__func__, alloc_size, PAGE_SIZE);
226228

227229
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);
229231
io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
230232
}
231233
io_tlb_index = 0;
@@ -359,7 +361,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
359361
goto cleanup4;
360362

361363
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);
363365
io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
364366
}
365367
io_tlb_index = 0;
@@ -530,7 +532,9 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr,
530532

531533
for (i = index; i < (int) (index + nslots); i++)
532534
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--)
534538
io_tlb_list[i] = ++count;
535539
tlb_addr = io_tlb_start + (index << IO_TLB_SHIFT);
536540

@@ -616,7 +620,9 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,
616620
* Step 2: merge the returned slots with the preceding slots,
617621
* if available (non zero)
618622
*/
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--)
620626
io_tlb_list[i] = ++count;
621627

622628
io_tlb_used -= nslots;

0 commit comments

Comments
 (0)