Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Generic page table allocator for IOMMUs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (C) 2014 ARM Limited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Author: Will Deacon <will.deacon@arm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/io-pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static const struct io_pgtable_init_fns *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #ifdef CONFIG_IOMMU_IO_PGTABLE_LPAE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	[ARM_32_LPAE_S1] = &io_pgtable_arm_32_lpae_s1_init_fns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	[ARM_32_LPAE_S2] = &io_pgtable_arm_32_lpae_s2_init_fns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	[ARM_64_LPAE_S1] = &io_pgtable_arm_64_lpae_s1_init_fns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	[ARM_64_LPAE_S2] = &io_pgtable_arm_64_lpae_s2_init_fns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	[ARM_MALI_LPAE] = &io_pgtable_arm_mali_lpae_init_fns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	[ARM_V7S] = &io_pgtable_arm_v7s_init_fns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 					    struct io_pgtable_cfg *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 					    void *cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	struct io_pgtable *iop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	const struct io_pgtable_init_fns *fns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	if (fmt >= IO_PGTABLE_NUM_FMTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	fns = io_pgtable_init_table[fmt];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	if (!fns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	iop = fns->alloc(cfg, cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	if (!iop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	iop->fmt	= fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	iop->cookie	= cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	iop->cfg	= *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	return &iop->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) EXPORT_SYMBOL_GPL(alloc_io_pgtable_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)  * It is the IOMMU driver's responsibility to ensure that the page table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)  * is no longer accessible to the walker by this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) void free_io_pgtable_ops(struct io_pgtable_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	struct io_pgtable *iop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	if (!ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	iop = io_pgtable_ops_to_pgtable(ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	io_pgtable_tlb_flush_all(iop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	io_pgtable_init_table[iop->fmt]->free(iop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) EXPORT_SYMBOL_GPL(free_io_pgtable_ops);