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