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