blob: fdd792c3769825528b6c443c3e3a9440b7b6beb0 [file] [log] [blame]
Will Deaconfdb1d7b2014-11-14 17:16:49 +00001#ifndef __IO_PGTABLE_H
2#define __IO_PGTABLE_H
3
4/*
5 * Public API for use by IOMMU drivers
6 */
7enum io_pgtable_fmt {
8 IO_PGTABLE_NUM_FMTS,
9};
10
11/**
12 * struct iommu_gather_ops - IOMMU callbacks for TLB and page table management.
13 *
14 * @tlb_flush_all: Synchronously invalidate the entire TLB context.
15 * @tlb_add_flush: Queue up a TLB invalidation for a virtual address range.
16 * @tlb_sync: Ensure any queue TLB invalidation has taken effect.
17 * @flush_pgtable: Ensure page table updates are visible to the IOMMU.
18 *
19 * Note that these can all be called in atomic context and must therefore
20 * not block.
21 */
22struct iommu_gather_ops {
23 void (*tlb_flush_all)(void *cookie);
24 void (*tlb_add_flush)(unsigned long iova, size_t size, bool leaf,
25 void *cookie);
26 void (*tlb_sync)(void *cookie);
27 void (*flush_pgtable)(void *ptr, size_t size, void *cookie);
28};
29
30/**
31 * struct io_pgtable_cfg - Configuration data for a set of page tables.
32 *
33 * @quirks: A bitmap of hardware quirks that require some special
34 * action by the low-level page table allocator.
35 * @pgsize_bitmap: A bitmap of page sizes supported by this set of page
36 * tables.
37 * @ias: Input address (iova) size, in bits.
38 * @oas: Output address (paddr) size, in bits.
39 * @tlb: TLB management callbacks for this set of tables.
40 */
41struct io_pgtable_cfg {
42 int quirks; /* IO_PGTABLE_QUIRK_* */
43 unsigned long pgsize_bitmap;
44 unsigned int ias;
45 unsigned int oas;
46 const struct iommu_gather_ops *tlb;
47
48 /* Low-level data specific to the table format */
49 union {
50 };
51};
52
53/**
54 * struct io_pgtable_ops - Page table manipulation API for IOMMU drivers.
55 *
56 * @map: Map a physically contiguous memory region.
57 * @unmap: Unmap a physically contiguous memory region.
58 * @iova_to_phys: Translate iova to physical address.
59 *
60 * These functions map directly onto the iommu_ops member functions with
61 * the same names.
62 */
63struct io_pgtable_ops {
64 int (*map)(struct io_pgtable_ops *ops, unsigned long iova,
65 phys_addr_t paddr, size_t size, int prot);
66 int (*unmap)(struct io_pgtable_ops *ops, unsigned long iova,
67 size_t size);
68 phys_addr_t (*iova_to_phys)(struct io_pgtable_ops *ops,
69 unsigned long iova);
70};
71
72/**
73 * alloc_io_pgtable_ops() - Allocate a page table allocator for use by an IOMMU.
74 *
75 * @fmt: The page table format.
76 * @cfg: The page table configuration. This will be modified to represent
77 * the configuration actually provided by the allocator (e.g. the
78 * pgsize_bitmap may be restricted).
79 * @cookie: An opaque token provided by the IOMMU driver and passed back to
80 * the callback routines in cfg->tlb.
81 */
82struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
83 struct io_pgtable_cfg *cfg,
84 void *cookie);
85
86/**
87 * free_io_pgtable_ops() - Free an io_pgtable_ops structure. The caller
88 * *must* ensure that the page table is no longer
89 * live, but the TLB can be dirty.
90 *
91 * @ops: The ops returned from alloc_io_pgtable_ops.
92 */
93void free_io_pgtable_ops(struct io_pgtable_ops *ops);
94
95
96/*
97 * Internal structures for page table allocator implementations.
98 */
99
100/**
101 * struct io_pgtable - Internal structure describing a set of page tables.
102 *
103 * @fmt: The page table format.
104 * @cookie: An opaque token provided by the IOMMU driver and passed back to
105 * any callback routines.
106 * @cfg: A copy of the page table configuration.
107 * @ops: The page table operations in use for this set of page tables.
108 */
109struct io_pgtable {
110 enum io_pgtable_fmt fmt;
111 void *cookie;
112 struct io_pgtable_cfg cfg;
113 struct io_pgtable_ops ops;
114};
115
116/**
117 * struct io_pgtable_init_fns - Alloc/free a set of page tables for a
118 * particular format.
119 *
120 * @alloc: Allocate a set of page tables described by cfg.
121 * @free: Free the page tables associated with iop.
122 */
123struct io_pgtable_init_fns {
124 struct io_pgtable *(*alloc)(struct io_pgtable_cfg *cfg, void *cookie);
125 void (*free)(struct io_pgtable *iop);
126};
127
128#endif /* __IO_PGTABLE_H */