hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/iommu/io-pgtable.c
....@@ -1,33 +1,16 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Generic page table allocator for IOMMUs.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
12
- *
13
- * You should have received a copy of the GNU General Public License
14
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
154 *
165 * Copyright (C) 2014 ARM Limited
176 *
187 * Author: Will Deacon <will.deacon@arm.com>
198 */
209
21
-#define pr_fmt(fmt) "io-pgtable: " fmt
22
-
2310 #include <linux/bug.h>
2411 #include <linux/io-pgtable.h>
2512 #include <linux/kernel.h>
2613 #include <linux/types.h>
27
-#include <linux/iommu.h>
28
-#include <linux/debugfs.h>
29
-#include <linux/atomic.h>
30
-#include <linux/module.h>
3114
3215 static const struct io_pgtable_init_fns *
3316 io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = {
....@@ -36,16 +19,12 @@
3619 [ARM_32_LPAE_S2] = &io_pgtable_arm_32_lpae_s2_init_fns,
3720 [ARM_64_LPAE_S1] = &io_pgtable_arm_64_lpae_s1_init_fns,
3821 [ARM_64_LPAE_S2] = &io_pgtable_arm_64_lpae_s2_init_fns,
22
+ [ARM_MALI_LPAE] = &io_pgtable_arm_mali_lpae_init_fns,
3923 #endif
4024 #ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S
4125 [ARM_V7S] = &io_pgtable_arm_v7s_init_fns,
4226 #endif
43
-#ifdef CONFIG_IOMMU_IO_PGTABLE_FAST
44
- [ARM_V8L_FAST] = &io_pgtable_av8l_fast_init_fns,
45
-#endif
4627 };
47
-
48
-static struct dentry *io_pgtable_top;
4928
5029 struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
5130 struct io_pgtable_cfg *cfg,
....@@ -84,56 +63,8 @@
8463 if (!ops)
8564 return;
8665
87
- iop = container_of(ops, struct io_pgtable, ops);
66
+ iop = io_pgtable_ops_to_pgtable(ops);
8867 io_pgtable_tlb_flush_all(iop);
8968 io_pgtable_init_table[iop->fmt]->free(iop);
9069 }
9170 EXPORT_SYMBOL_GPL(free_io_pgtable_ops);
92
-
93
-static atomic_t pages_allocated;
94
-
95
-void *io_pgtable_alloc_pages_exact(struct io_pgtable_cfg *cfg, void *cookie,
96
- size_t size, gfp_t gfp_mask)
97
-{
98
- void *ret;
99
-
100
- if (cfg->tlb->alloc_pages_exact)
101
- ret = cfg->tlb->alloc_pages_exact(cookie, size, gfp_mask);
102
- else
103
- ret = alloc_pages_exact(size, gfp_mask);
104
-
105
- if (likely(ret))
106
- atomic_add(1 << get_order(size), &pages_allocated);
107
-
108
- return ret;
109
-}
110
-
111
-void io_pgtable_free_pages_exact(struct io_pgtable_cfg *cfg, void *cookie,
112
- void *virt, size_t size)
113
-{
114
- if (cfg->tlb->free_pages_exact)
115
- cfg->tlb->free_pages_exact(cookie, virt, size);
116
- else
117
- free_pages_exact(virt, size);
118
-
119
- atomic_sub(1 << get_order(size), &pages_allocated);
120
-}
121
-
122
-static int __init io_pgtable_init(void)
123
-{
124
- static const char io_pgtable_str[] __initconst = "io-pgtable";
125
- static const char pages_str[] __initconst = "pages";
126
-
127
- io_pgtable_top = debugfs_create_dir(io_pgtable_str, iommu_debugfs_top);
128
- debugfs_create_atomic_t(pages_str, 0600, io_pgtable_top,
129
- &pages_allocated);
130
- return 0;
131
-}
132
-
133
-static void __exit io_pgtable_exit(void)
134
-{
135
- debugfs_remove_recursive(io_pgtable_top);
136
-}
137
-
138
-module_init(io_pgtable_init);
139
-module_exit(io_pgtable_exit);