blob: 10e32f69c6681368cb04023173a4bcf0b859839a [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 {
Laurent Pinchartc896c132014-12-14 23:34:50 +020046 #define IO_PGTABLE_QUIRK_ARM_NS (1 << 0) /* Set NS bit in PTEs */
47 int quirks;
Will Deaconfdb1d7b2014-11-14 17:16:49 +000048 unsigned long pgsize_bitmap;
49 unsigned int ias;
50 unsigned int oas;
51 const struct iommu_gather_ops *tlb;
52
53 /* Low-level data specific to the table format */
54 union {
Will Deacone1d3c0f2014-11-14 17:18:23 +000055 struct {
56 u64 ttbr[2];
57 u64 tcr;
58 u64 mair[2];
59 } arm_lpae_s1_cfg;
60
61 struct {
62 u64 vttbr;
63 u64 vtcr;
64 } arm_lpae_s2_cfg;
Will Deaconfdb1d7b2014-11-14 17:16:49 +000065 };
66};
67
68/**
69 * struct io_pgtable_ops - Page table manipulation API for IOMMU drivers.
70 *
71 * @map: Map a physically contiguous memory region.
72 * @unmap: Unmap a physically contiguous memory region.
73 * @iova_to_phys: Translate iova to physical address.
74 *
75 * These functions map directly onto the iommu_ops member functions with
76 * the same names.
77 */
78struct io_pgtable_ops {
79 int (*map)(struct io_pgtable_ops *ops, unsigned long iova,
80 phys_addr_t paddr, size_t size, int prot);
81 int (*unmap)(struct io_pgtable_ops *ops, unsigned long iova,
82 size_t size);
83 phys_addr_t (*iova_to_phys)(struct io_pgtable_ops *ops,
84 unsigned long iova);
85};
86
87/**
88 * alloc_io_pgtable_ops() - Allocate a page table allocator for use by an IOMMU.
89 *
90 * @fmt: The page table format.
91 * @cfg: The page table configuration. This will be modified to represent
92 * the configuration actually provided by the allocator (e.g. the
93 * pgsize_bitmap may be restricted).
94 * @cookie: An opaque token provided by the IOMMU driver and passed back to
95 * the callback routines in cfg->tlb.
96 */
97struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
98 struct io_pgtable_cfg *cfg,
99 void *cookie);
100
101/**
102 * free_io_pgtable_ops() - Free an io_pgtable_ops structure. The caller
103 * *must* ensure that the page table is no longer
104 * live, but the TLB can be dirty.
105 *
106 * @ops: The ops returned from alloc_io_pgtable_ops.
107 */
108void free_io_pgtable_ops(struct io_pgtable_ops *ops);
109
110
111/*
112 * Internal structures for page table allocator implementations.
113 */
114
115/**
116 * struct io_pgtable - Internal structure describing a set of page tables.
117 *
118 * @fmt: The page table format.
119 * @cookie: An opaque token provided by the IOMMU driver and passed back to
120 * any callback routines.
121 * @cfg: A copy of the page table configuration.
122 * @ops: The page table operations in use for this set of page tables.
123 */
124struct io_pgtable {
125 enum io_pgtable_fmt fmt;
126 void *cookie;
127 struct io_pgtable_cfg cfg;
128 struct io_pgtable_ops ops;
129};
130
131/**
132 * struct io_pgtable_init_fns - Alloc/free a set of page tables for a
133 * particular format.
134 *
135 * @alloc: Allocate a set of page tables described by cfg.
136 * @free: Free the page tables associated with iop.
137 */
138struct io_pgtable_init_fns {
139 struct io_pgtable *(*alloc)(struct io_pgtable_cfg *cfg, void *cookie);
140 void (*free)(struct io_pgtable *iop);
141};
142
143#endif /* __IO_PGTABLE_H */