1 // SPDX-License-Identifier: GPL-2.0-only
3 * CPU-agnostic AMD IO page table allocator.
5 * Copyright (C) 2020 Advanced Micro Devices, Inc.
6 * Author: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
9 #define pr_fmt(fmt) "AMD-Vi: " fmt
10 #define dev_fmt(fmt) pr_fmt(fmt)
12 #include <linux/atomic.h>
13 #include <linux/bitops.h>
14 #include <linux/io-pgtable.h>
15 #include <linux/kernel.h>
16 #include <linux/sizes.h>
17 #include <linux/slab.h>
18 #include <linux/types.h>
19 #include <linux/dma-mapping.h>
21 #include <asm/barrier.h>
23 #include "amd_iommu_types.h"
24 #include "amd_iommu.h"
26 static void v1_tlb_flush_all(void *cookie)
30 static void v1_tlb_flush_walk(unsigned long iova, size_t size,
31 size_t granule, void *cookie)
35 static void v1_tlb_add_page(struct iommu_iotlb_gather *gather,
36 unsigned long iova, size_t granule,
41 static const struct iommu_flush_ops v1_flush_ops = {
42 .tlb_flush_all = v1_tlb_flush_all,
43 .tlb_flush_walk = v1_tlb_flush_walk,
44 .tlb_add_page = v1_tlb_add_page,
48 * ----------------------------------------------------
50 static void v1_free_pgtable(struct io_pgtable *iop)
54 static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
56 struct amd_io_pgtable *pgtable = io_pgtable_cfg_to_data(cfg);
58 cfg->pgsize_bitmap = AMD_IOMMU_PGSIZES,
59 cfg->ias = IOMMU_IN_ADDR_BIT_SIZE,
60 cfg->oas = IOMMU_OUT_ADDR_BIT_SIZE,
61 cfg->tlb = &v1_flush_ops;
66 struct io_pgtable_init_fns io_pgtable_amd_iommu_v1_init_fns = {
67 .alloc = v1_alloc_pgtable,
68 .free = v1_free_pgtable,