summaryrefslogtreecommitdiff
path: root/kernel/dma/swiotlb.c
diff options
context:
space:
mode:
authorChao Gao <chao.gao@intel.com>2022-07-15 18:45:34 +0800
committerChristoph Hellwig <hch@lst.de>2022-07-18 06:49:58 +0200
commit44335487bab05e06902f9184179857aae764bfe6 (patch)
tree2e8e1dc5c6a76b9a155e877916bc742623f0ed3d /kernel/dma/swiotlb.c
parent91561d4ecb755f056f8ff04f9dcaec210140e55c (diff)
swiotlb: consolidate rounding up default_nslabs
default_nslabs are rounded up in two cases with exactly same comments. Add a simple wrapper to reduce duplicate code/comments. It is preparatory to adding more logics into the round-up. No functional change intended. Signed-off-by: Chao Gao <chao.gao@intel.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'kernel/dma/swiotlb.c')
-rw-r--r--kernel/dma/swiotlb.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index cbffa0b1ace5..604f2469ac0e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -88,6 +88,20 @@ struct io_tlb_area {
spinlock_t lock;
};
+/*
+ * Round up number of slabs to the next power of 2. The last area is going
+ * be smaller than the rest if default_nslabs is not power of two.
+ *
+ * Return true if default_nslabs is rounded up.
+ */
+static bool round_up_default_nslabs(void)
+{
+ if (!default_nareas || is_power_of_2(default_nslabs))
+ return false;
+ default_nslabs = roundup_pow_of_two(default_nslabs);
+ return true;
+}
+
static void swiotlb_adjust_nareas(unsigned int nareas)
{
if (!is_power_of_2(nareas))
@@ -96,16 +110,9 @@ static void swiotlb_adjust_nareas(unsigned int nareas)
default_nareas = nareas;
pr_info("area num %d.\n", nareas);
- /*
- * Round up number of slabs to the next power of 2.
- * The last area is going be smaller than the rest if
- * default_nslabs is not power of two.
- */
- if (nareas && !is_power_of_2(default_nslabs)) {
- default_nslabs = roundup_pow_of_two(default_nslabs);
+ if (round_up_default_nslabs())
pr_info("SWIOTLB bounce buffer size roundup to %luMB",
(default_nslabs << IO_TLB_SHIFT) >> 20);
- }
}
static int __init
@@ -154,18 +161,10 @@ void __init swiotlb_adjust_size(unsigned long size)
if (default_nslabs != IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT)
return;
- /*
- * Round up number of slabs to the next power of 2.
- * The last area is going be smaller than the rest if
- * default_nslabs is not power of two.
- */
size = ALIGN(size, IO_TLB_SIZE);
default_nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
- if (default_nareas) {
- default_nslabs = roundup_pow_of_two(default_nslabs);
+ if (round_up_default_nslabs())
size = default_nslabs << IO_TLB_SHIFT;
- }
-
pr_info("SWIOTLB bounce buffer size adjusted to %luMB", size >> 20);
}