| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * 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/>. |
|---|
| 15 | 4 | * |
|---|
| 16 | 5 | * Copyright (C) 2014 ARM Limited |
|---|
| 17 | 6 | * |
|---|
| 18 | 7 | * Author: Will Deacon <will.deacon@arm.com> |
|---|
| 19 | 8 | */ |
|---|
| 20 | 9 | |
|---|
| 21 | | -#define pr_fmt(fmt) "io-pgtable: " fmt |
|---|
| 22 | | - |
|---|
| 23 | 10 | #include <linux/bug.h> |
|---|
| 24 | 11 | #include <linux/io-pgtable.h> |
|---|
| 25 | 12 | #include <linux/kernel.h> |
|---|
| 26 | 13 | #include <linux/types.h> |
|---|
| 27 | | -#include <linux/iommu.h> |
|---|
| 28 | | -#include <linux/debugfs.h> |
|---|
| 29 | | -#include <linux/atomic.h> |
|---|
| 30 | | -#include <linux/module.h> |
|---|
| 31 | 14 | |
|---|
| 32 | 15 | static const struct io_pgtable_init_fns * |
|---|
| 33 | 16 | io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = { |
|---|
| .. | .. |
|---|
| 36 | 19 | [ARM_32_LPAE_S2] = &io_pgtable_arm_32_lpae_s2_init_fns, |
|---|
| 37 | 20 | [ARM_64_LPAE_S1] = &io_pgtable_arm_64_lpae_s1_init_fns, |
|---|
| 38 | 21 | [ARM_64_LPAE_S2] = &io_pgtable_arm_64_lpae_s2_init_fns, |
|---|
| 22 | + [ARM_MALI_LPAE] = &io_pgtable_arm_mali_lpae_init_fns, |
|---|
| 39 | 23 | #endif |
|---|
| 40 | 24 | #ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S |
|---|
| 41 | 25 | [ARM_V7S] = &io_pgtable_arm_v7s_init_fns, |
|---|
| 42 | 26 | #endif |
|---|
| 43 | | -#ifdef CONFIG_IOMMU_IO_PGTABLE_FAST |
|---|
| 44 | | - [ARM_V8L_FAST] = &io_pgtable_av8l_fast_init_fns, |
|---|
| 45 | | -#endif |
|---|
| 46 | 27 | }; |
|---|
| 47 | | - |
|---|
| 48 | | -static struct dentry *io_pgtable_top; |
|---|
| 49 | 28 | |
|---|
| 50 | 29 | struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt, |
|---|
| 51 | 30 | struct io_pgtable_cfg *cfg, |
|---|
| .. | .. |
|---|
| 84 | 63 | if (!ops) |
|---|
| 85 | 64 | return; |
|---|
| 86 | 65 | |
|---|
| 87 | | - iop = container_of(ops, struct io_pgtable, ops); |
|---|
| 66 | + iop = io_pgtable_ops_to_pgtable(ops); |
|---|
| 88 | 67 | io_pgtable_tlb_flush_all(iop); |
|---|
| 89 | 68 | io_pgtable_init_table[iop->fmt]->free(iop); |
|---|
| 90 | 69 | } |
|---|
| 91 | 70 | 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); |
|---|