cf2cd2d2e43e36caa36fd343bfa77467b8ec672d
[linux-2.6-microblaze.git] / drivers / iommu / amd / io_pgtable.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * CPU-agnostic AMD IO page table allocator.
4  *
5  * Copyright (C) 2020 Advanced Micro Devices, Inc.
6  * Author: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
7  */
8
9 #define pr_fmt(fmt)     "AMD-Vi: " fmt
10 #define dev_fmt(fmt)    pr_fmt(fmt)
11
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>
20
21 #include <asm/barrier.h>
22
23 #include "amd_iommu_types.h"
24 #include "amd_iommu.h"
25
26 static void v1_tlb_flush_all(void *cookie)
27 {
28 }
29
30 static void v1_tlb_flush_walk(unsigned long iova, size_t size,
31                                   size_t granule, void *cookie)
32 {
33 }
34
35 static void v1_tlb_add_page(struct iommu_iotlb_gather *gather,
36                                          unsigned long iova, size_t granule,
37                                          void *cookie)
38 {
39 }
40
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,
45 };
46
47 /*
48  * ----------------------------------------------------
49  */
50 static void v1_free_pgtable(struct io_pgtable *iop)
51 {
52 }
53
54 static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
55 {
56         struct amd_io_pgtable *pgtable = io_pgtable_cfg_to_data(cfg);
57
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;
62
63         return &pgtable->iop;
64 }
65
66 struct io_pgtable_init_fns io_pgtable_amd_iommu_v1_init_fns = {
67         .alloc  = v1_alloc_pgtable,
68         .free   = v1_free_pgtable,
69 };