blob: 2e18469afe3c0c424ebd076b52aa284d49a0a5b8 [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 *
24 * Note that these can all be called in atomic context and must therefore
25 * not block.
26 */
27struct iommu_gather_ops {
28 void (*tlb_flush_all)(void *cookie);
Robin Murphy06c610e2015-12-07 18:18:53 +000029 void (*tlb_add_flush)(unsigned long iova, size_t size, size_t granule,
30 bool leaf, void *cookie);
Will Deaconfdb1d7b2014-11-14 17:16:49 +000031 void (*tlb_sync)(void *cookie);
Will Deaconfdb1d7b2014-11-14 17:16:49 +000032};
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.
Robin Murphyf8d54962015-07-29 19:46:04 +010044 * @iommu_dev: The device representing the DMA configuration for the
45 * page table walker.
Will Deaconfdb1d7b2014-11-14 17:16:49 +000046 */
47struct io_pgtable_cfg {
Laurent Pinchartc896c1322014-12-14 23:34:50 +020048 #define IO_PGTABLE_QUIRK_ARM_NS (1 << 0) /* Set NS bit in PTEs */
49 int quirks;
Will Deaconfdb1d7b2014-11-14 17:16:49 +000050 unsigned long pgsize_bitmap;
51 unsigned int ias;
52 unsigned int oas;
53 const struct iommu_gather_ops *tlb;
Robin Murphyf8d54962015-07-29 19:46:04 +010054 struct device *iommu_dev;
Will Deaconfdb1d7b2014-11-14 17:16:49 +000055
56 /* Low-level data specific to the table format */
57 union {
Will Deacone1d3c0f2014-11-14 17:18:23 +000058 struct {
59 u64 ttbr[2];
60 u64 tcr;
61 u64 mair[2];
62 } arm_lpae_s1_cfg;
63
64 struct {
65 u64 vttbr;
66 u64 vtcr;
67 } arm_lpae_s2_cfg;
Will Deaconfdb1d7b2014-11-14 17:16:49 +000068 };
69};
70
71/**
72 * struct io_pgtable_ops - Page table manipulation API for IOMMU drivers.
73 *
74 * @map: Map a physically contiguous memory region.
75 * @unmap: Unmap a physically contiguous memory region.
76 * @iova_to_phys: Translate iova to physical address.
77 *
78 * These functions map directly onto the iommu_ops member functions with
79 * the same names.
80 */
81struct io_pgtable_ops {
82 int (*map)(struct io_pgtable_ops *ops, unsigned long iova,
83 phys_addr_t paddr, size_t size, int prot);
84 int (*unmap)(struct io_pgtable_ops *ops, unsigned long iova,
85 size_t size);
86 phys_addr_t (*iova_to_phys)(struct io_pgtable_ops *ops,
87 unsigned long iova);
88};
89
90/**
91 * alloc_io_pgtable_ops() - Allocate a page table allocator for use by an IOMMU.
92 *
93 * @fmt: The page table format.
94 * @cfg: The page table configuration. This will be modified to represent
95 * the configuration actually provided by the allocator (e.g. the
96 * pgsize_bitmap may be restricted).
97 * @cookie: An opaque token provided by the IOMMU driver and passed back to
98 * the callback routines in cfg->tlb.
99 */
100struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
101 struct io_pgtable_cfg *cfg,
102 void *cookie);
103
104/**
105 * free_io_pgtable_ops() - Free an io_pgtable_ops structure. The caller
106 * *must* ensure that the page table is no longer
107 * live, but the TLB can be dirty.
108 *
109 * @ops: The ops returned from alloc_io_pgtable_ops.
110 */
111void free_io_pgtable_ops(struct io_pgtable_ops *ops);
112
113
114/*
115 * Internal structures for page table allocator implementations.
116 */
117
118/**
119 * struct io_pgtable - Internal structure describing a set of page tables.
120 *
121 * @fmt: The page table format.
122 * @cookie: An opaque token provided by the IOMMU driver and passed back to
123 * any callback routines.
124 * @cfg: A copy of the page table configuration.
125 * @ops: The page table operations in use for this set of page tables.
126 */
127struct io_pgtable {
128 enum io_pgtable_fmt fmt;
129 void *cookie;
130 struct io_pgtable_cfg cfg;
131 struct io_pgtable_ops ops;
132};
133
134/**
135 * struct io_pgtable_init_fns - Alloc/free a set of page tables for a
136 * particular format.
137 *
138 * @alloc: Allocate a set of page tables described by cfg.
139 * @free: Free the page tables associated with iop.
140 */
141struct io_pgtable_init_fns {
142 struct io_pgtable *(*alloc)(struct io_pgtable_cfg *cfg, void *cookie);
143 void (*free)(struct io_pgtable *iop);
144};
145
Joerg Roedel2e169bb2015-08-13 12:01:10 +0200146extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s1_init_fns;
147extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s2_init_fns;
148extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns;
149extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s2_init_fns;
150
Will Deaconfdb1d7b2014-11-14 17:16:49 +0000151#endif /* __IO_PGTABLE_H */