Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 1 | #ifndef __IO_PGTABLE_H |
| 2 | #define __IO_PGTABLE_H |
| 3 | |
| 4 | /* |
| 5 | * Public API for use by IOMMU drivers |
| 6 | */ |
| 7 | enum io_pgtable_fmt { |
Will Deacon | e1d3c0f | 2014-11-14 17:18:23 +0000 | [diff] [blame] | 8 | ARM_32_LPAE_S1, |
| 9 | ARM_32_LPAE_S2, |
| 10 | ARM_64_LPAE_S1, |
| 11 | ARM_64_LPAE_S2, |
Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 12 | 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 Murphy | 87a91b1 | 2015-07-29 19:46:09 +0100 | [diff] [blame] | 20 | * @tlb_sync: Ensure any queued TLB invalidation has taken effect, and |
| 21 | * any corresponding page table updates are visible to the |
| 22 | * IOMMU. |
Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 23 | * |
| 24 | * Note that these can all be called in atomic context and must therefore |
| 25 | * not block. |
| 26 | */ |
| 27 | struct iommu_gather_ops { |
| 28 | void (*tlb_flush_all)(void *cookie); |
Robin Murphy | 06c610e | 2015-12-07 18:18:53 +0000 | [diff] [blame] | 29 | void (*tlb_add_flush)(unsigned long iova, size_t size, size_t granule, |
| 30 | bool leaf, void *cookie); |
Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 31 | void (*tlb_sync)(void *cookie); |
Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 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. |
Robin Murphy | f8d5496 | 2015-07-29 19:46:04 +0100 | [diff] [blame] | 44 | * @iommu_dev: The device representing the DMA configuration for the |
| 45 | * page table walker. |
Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 46 | */ |
| 47 | struct io_pgtable_cfg { |
Laurent Pinchart | c896c13 | 2014-12-14 23:34:50 +0200 | [diff] [blame] | 48 | #define IO_PGTABLE_QUIRK_ARM_NS (1 << 0) /* Set NS bit in PTEs */ |
| 49 | int quirks; |
Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 50 | unsigned long pgsize_bitmap; |
| 51 | unsigned int ias; |
| 52 | unsigned int oas; |
| 53 | const struct iommu_gather_ops *tlb; |
Robin Murphy | f8d5496 | 2015-07-29 19:46:04 +0100 | [diff] [blame] | 54 | struct device *iommu_dev; |
Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 55 | |
| 56 | /* Low-level data specific to the table format */ |
| 57 | union { |
Will Deacon | e1d3c0f | 2014-11-14 17:18:23 +0000 | [diff] [blame] | 58 | 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 Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 68 | }; |
| 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 | */ |
| 81 | struct 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 | */ |
| 100 | struct 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 | */ |
| 111 | void 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 | */ |
| 127 | struct 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 | |
Robin Murphy | fdc3896 | 2015-12-04 17:53:01 +0000 | [diff] [blame] | 134 | #define io_pgtable_ops_to_pgtable(x) container_of((x), struct io_pgtable, ops) |
| 135 | |
Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 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 | */ |
| 143 | struct 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 | |
Joerg Roedel | 2e169bb | 2015-08-13 12:01:10 +0200 | [diff] [blame] | 148 | extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s1_init_fns; |
| 149 | extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s2_init_fns; |
| 150 | extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns; |
| 151 | extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s2_init_fns; |
| 152 | |
Will Deacon | fdb1d7b | 2014-11-14 17:16:49 +0000 | [diff] [blame] | 153 | #endif /* __IO_PGTABLE_H */ |