Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright IBM Corp. 2012 |
| 3 | * |
| 4 | * Author(s): |
| 5 | * Jan Glauber <jang@linux.vnet.ibm.com> |
| 6 | */ |
| 7 | |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/export.h> |
| 11 | #include <linux/iommu-helper.h> |
| 12 | #include <linux/dma-mapping.h> |
Sebastian Ott | 2245932 | 2013-08-29 20:31:50 +0200 | [diff] [blame] | 13 | #include <linux/vmalloc.h> |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 14 | #include <linux/pci.h> |
| 15 | #include <asm/pci_dma.h> |
| 16 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 17 | static struct kmem_cache *dma_region_table_cache; |
| 18 | static struct kmem_cache *dma_page_table_cache; |
Gerald Schaefer | c60d1ae | 2014-07-18 17:37:08 +0200 | [diff] [blame] | 19 | static int s390_iommu_strict; |
| 20 | |
| 21 | static int zpci_refresh_global(struct zpci_dev *zdev) |
| 22 | { |
| 23 | return zpci_refresh_trans((u64) zdev->fh << 32, zdev->start_dma, |
| 24 | zdev->iommu_pages * PAGE_SIZE); |
| 25 | } |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 26 | |
Gerald Schaefer | 8128f23c | 2015-08-27 15:33:03 +0200 | [diff] [blame] | 27 | unsigned long *dma_alloc_cpu_table(void) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 28 | { |
| 29 | unsigned long *table, *entry; |
| 30 | |
| 31 | table = kmem_cache_alloc(dma_region_table_cache, GFP_ATOMIC); |
| 32 | if (!table) |
| 33 | return NULL; |
| 34 | |
| 35 | for (entry = table; entry < table + ZPCI_TABLE_ENTRIES; entry++) |
Sebastian Ott | 4d5a6b7 | 2015-10-26 11:15:28 +0100 | [diff] [blame] | 36 | *entry = ZPCI_TABLE_INVALID; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 37 | return table; |
| 38 | } |
| 39 | |
| 40 | static void dma_free_cpu_table(void *table) |
| 41 | { |
| 42 | kmem_cache_free(dma_region_table_cache, table); |
| 43 | } |
| 44 | |
| 45 | static unsigned long *dma_alloc_page_table(void) |
| 46 | { |
| 47 | unsigned long *table, *entry; |
| 48 | |
| 49 | table = kmem_cache_alloc(dma_page_table_cache, GFP_ATOMIC); |
| 50 | if (!table) |
| 51 | return NULL; |
| 52 | |
| 53 | for (entry = table; entry < table + ZPCI_PT_ENTRIES; entry++) |
Sebastian Ott | 4d5a6b7 | 2015-10-26 11:15:28 +0100 | [diff] [blame] | 54 | *entry = ZPCI_PTE_INVALID; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 55 | return table; |
| 56 | } |
| 57 | |
| 58 | static void dma_free_page_table(void *table) |
| 59 | { |
| 60 | kmem_cache_free(dma_page_table_cache, table); |
| 61 | } |
| 62 | |
| 63 | static unsigned long *dma_get_seg_table_origin(unsigned long *entry) |
| 64 | { |
| 65 | unsigned long *sto; |
| 66 | |
| 67 | if (reg_entry_isvalid(*entry)) |
| 68 | sto = get_rt_sto(*entry); |
| 69 | else { |
| 70 | sto = dma_alloc_cpu_table(); |
| 71 | if (!sto) |
| 72 | return NULL; |
| 73 | |
| 74 | set_rt_sto(entry, sto); |
| 75 | validate_rt_entry(entry); |
| 76 | entry_clr_protected(entry); |
| 77 | } |
| 78 | return sto; |
| 79 | } |
| 80 | |
| 81 | static unsigned long *dma_get_page_table_origin(unsigned long *entry) |
| 82 | { |
| 83 | unsigned long *pto; |
| 84 | |
| 85 | if (reg_entry_isvalid(*entry)) |
| 86 | pto = get_st_pto(*entry); |
| 87 | else { |
| 88 | pto = dma_alloc_page_table(); |
| 89 | if (!pto) |
| 90 | return NULL; |
| 91 | set_st_pto(entry, pto); |
| 92 | validate_st_entry(entry); |
| 93 | entry_clr_protected(entry); |
| 94 | } |
| 95 | return pto; |
| 96 | } |
| 97 | |
Sebastian Ott | 66728ee | 2015-10-26 11:19:13 +0100 | [diff] [blame] | 98 | unsigned long *dma_walk_cpu_trans(unsigned long *rto, dma_addr_t dma_addr) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 99 | { |
| 100 | unsigned long *sto, *pto; |
| 101 | unsigned int rtx, sx, px; |
| 102 | |
| 103 | rtx = calc_rtx(dma_addr); |
| 104 | sto = dma_get_seg_table_origin(&rto[rtx]); |
| 105 | if (!sto) |
| 106 | return NULL; |
| 107 | |
| 108 | sx = calc_sx(dma_addr); |
| 109 | pto = dma_get_page_table_origin(&sto[sx]); |
| 110 | if (!pto) |
| 111 | return NULL; |
| 112 | |
| 113 | px = calc_px(dma_addr); |
| 114 | return &pto[px]; |
| 115 | } |
| 116 | |
Sebastian Ott | 66728ee | 2015-10-26 11:19:13 +0100 | [diff] [blame] | 117 | void dma_update_cpu_trans(unsigned long *entry, void *page_addr, int flags) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 118 | { |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 119 | if (flags & ZPCI_PTE_INVALID) { |
| 120 | invalidate_pt_entry(entry); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 121 | } else { |
| 122 | set_pt_pfaa(entry, page_addr); |
| 123 | validate_pt_entry(entry); |
| 124 | } |
| 125 | |
| 126 | if (flags & ZPCI_TABLE_PROTECTED) |
| 127 | entry_set_protected(entry); |
| 128 | else |
| 129 | entry_clr_protected(entry); |
| 130 | } |
| 131 | |
Sebastian Ott | 1f166e9e | 2016-09-05 17:49:17 +0200 | [diff] [blame] | 132 | static int __dma_update_trans(struct zpci_dev *zdev, unsigned long pa, |
| 133 | dma_addr_t dma_addr, size_t size, int flags) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 134 | { |
| 135 | unsigned int nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; |
| 136 | u8 *page_addr = (u8 *) (pa & PAGE_MASK); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 137 | unsigned long irq_flags; |
Sebastian Ott | 66728ee | 2015-10-26 11:19:13 +0100 | [diff] [blame] | 138 | unsigned long *entry; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 139 | int i, rc = 0; |
| 140 | |
| 141 | if (!nr_pages) |
| 142 | return -EINVAL; |
| 143 | |
| 144 | spin_lock_irqsave(&zdev->dma_table_lock, irq_flags); |
Sebastian Ott | 66728ee | 2015-10-26 11:19:13 +0100 | [diff] [blame] | 145 | if (!zdev->dma_table) { |
| 146 | rc = -EINVAL; |
Sebastian Ott | 1f166e9e | 2016-09-05 17:49:17 +0200 | [diff] [blame] | 147 | goto out_unlock; |
Sebastian Ott | 66728ee | 2015-10-26 11:19:13 +0100 | [diff] [blame] | 148 | } |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 149 | |
| 150 | for (i = 0; i < nr_pages; i++) { |
Sebastian Ott | 66728ee | 2015-10-26 11:19:13 +0100 | [diff] [blame] | 151 | entry = dma_walk_cpu_trans(zdev->dma_table, dma_addr); |
| 152 | if (!entry) { |
| 153 | rc = -ENOMEM; |
| 154 | goto undo_cpu_trans; |
| 155 | } |
| 156 | dma_update_cpu_trans(entry, page_addr, flags); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 157 | page_addr += PAGE_SIZE; |
| 158 | dma_addr += PAGE_SIZE; |
| 159 | } |
| 160 | |
Sebastian Ott | 66728ee | 2015-10-26 11:19:13 +0100 | [diff] [blame] | 161 | undo_cpu_trans: |
| 162 | if (rc && ((flags & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_VALID)) { |
| 163 | flags = ZPCI_PTE_INVALID; |
| 164 | while (i-- > 0) { |
| 165 | page_addr -= PAGE_SIZE; |
| 166 | dma_addr -= PAGE_SIZE; |
| 167 | entry = dma_walk_cpu_trans(zdev->dma_table, dma_addr); |
| 168 | if (!entry) |
| 169 | break; |
| 170 | dma_update_cpu_trans(entry, page_addr, flags); |
| 171 | } |
| 172 | } |
Sebastian Ott | 1f166e9e | 2016-09-05 17:49:17 +0200 | [diff] [blame] | 173 | out_unlock: |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 174 | spin_unlock_irqrestore(&zdev->dma_table_lock, irq_flags); |
| 175 | return rc; |
| 176 | } |
| 177 | |
Sebastian Ott | 1f166e9e | 2016-09-05 17:49:17 +0200 | [diff] [blame] | 178 | static int __dma_purge_tlb(struct zpci_dev *zdev, dma_addr_t dma_addr, |
| 179 | size_t size, int flags) |
| 180 | { |
| 181 | /* |
| 182 | * With zdev->tlb_refresh == 0, rpcit is not required to establish new |
| 183 | * translations when previously invalid translation-table entries are |
| 184 | * validated. With lazy unmap, it also is skipped for previously valid |
| 185 | * entries, but a global rpcit is then required before any address can |
| 186 | * be re-used, i.e. after each iommu bitmap wrap-around. |
| 187 | */ |
| 188 | if (!zdev->tlb_refresh && |
| 189 | (!s390_iommu_strict || |
| 190 | ((flags & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_VALID))) |
| 191 | return 0; |
| 192 | |
| 193 | return zpci_refresh_trans((u64) zdev->fh << 32, dma_addr, |
| 194 | PAGE_ALIGN(size)); |
| 195 | } |
| 196 | |
| 197 | static int dma_update_trans(struct zpci_dev *zdev, unsigned long pa, |
| 198 | dma_addr_t dma_addr, size_t size, int flags) |
| 199 | { |
| 200 | int rc; |
| 201 | |
| 202 | rc = __dma_update_trans(zdev, pa, dma_addr, size, flags); |
| 203 | if (rc) |
| 204 | return rc; |
| 205 | |
| 206 | rc = __dma_purge_tlb(zdev, dma_addr, size, flags); |
| 207 | if (rc && ((flags & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_VALID)) |
| 208 | __dma_update_trans(zdev, pa, dma_addr, size, ZPCI_PTE_INVALID); |
| 209 | |
| 210 | return rc; |
| 211 | } |
| 212 | |
Gerald Schaefer | 8128f23c | 2015-08-27 15:33:03 +0200 | [diff] [blame] | 213 | void dma_free_seg_table(unsigned long entry) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 214 | { |
| 215 | unsigned long *sto = get_rt_sto(entry); |
| 216 | int sx; |
| 217 | |
| 218 | for (sx = 0; sx < ZPCI_TABLE_ENTRIES; sx++) |
| 219 | if (reg_entry_isvalid(sto[sx])) |
| 220 | dma_free_page_table(get_st_pto(sto[sx])); |
| 221 | |
| 222 | dma_free_cpu_table(sto); |
| 223 | } |
| 224 | |
Gerald Schaefer | 8128f23c | 2015-08-27 15:33:03 +0200 | [diff] [blame] | 225 | void dma_cleanup_tables(unsigned long *table) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 226 | { |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 227 | int rtx; |
| 228 | |
Gerald Schaefer | 8128f23c | 2015-08-27 15:33:03 +0200 | [diff] [blame] | 229 | if (!table) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 230 | return; |
| 231 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 232 | for (rtx = 0; rtx < ZPCI_TABLE_ENTRIES; rtx++) |
| 233 | if (reg_entry_isvalid(table[rtx])) |
| 234 | dma_free_seg_table(table[rtx]); |
| 235 | |
| 236 | dma_free_cpu_table(table); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 237 | } |
| 238 | |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 239 | static unsigned long __dma_alloc_iommu(struct device *dev, |
Gerald Schaefer | 5ec6d49 | 2014-02-18 19:47:17 +0100 | [diff] [blame] | 240 | unsigned long start, int size) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 241 | { |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 242 | struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); |
Gerald Schaefer | 5ec6d49 | 2014-02-18 19:47:17 +0100 | [diff] [blame] | 243 | unsigned long boundary_size; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 244 | |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 245 | boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1, |
Gerald Schaefer | 5ec6d49 | 2014-02-18 19:47:17 +0100 | [diff] [blame] | 246 | PAGE_SIZE) >> PAGE_SHIFT; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 247 | return iommu_area_alloc(zdev->iommu_bitmap, zdev->iommu_pages, |
Sebastian Ott | 8ee2db3 | 2016-06-03 19:05:38 +0200 | [diff] [blame] | 248 | start, size, zdev->start_dma >> PAGE_SHIFT, |
| 249 | boundary_size, 0); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 250 | } |
| 251 | |
Sebastian Ott | 8cb63b7 | 2016-08-17 13:51:11 +0200 | [diff] [blame] | 252 | static dma_addr_t dma_alloc_address(struct device *dev, int size) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 253 | { |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 254 | struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 255 | unsigned long offset, flags; |
| 256 | |
| 257 | spin_lock_irqsave(&zdev->iommu_bitmap_lock, flags); |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 258 | offset = __dma_alloc_iommu(dev, zdev->next_bit, size); |
Gerald Schaefer | c60d1ae | 2014-07-18 17:37:08 +0200 | [diff] [blame] | 259 | if (offset == -1) { |
Sebastian Ott | 13954fd | 2016-09-08 13:25:01 +0200 | [diff] [blame] | 260 | if (!zdev->tlb_refresh && !s390_iommu_strict) { |
| 261 | /* global flush before DMA addresses are reused */ |
| 262 | if (zpci_refresh_global(zdev)) |
| 263 | goto out_error; |
| 264 | |
| 265 | bitmap_andnot(zdev->iommu_bitmap, zdev->iommu_bitmap, |
| 266 | zdev->lazy_bitmap, zdev->iommu_pages); |
| 267 | bitmap_zero(zdev->lazy_bitmap, zdev->iommu_pages); |
| 268 | } |
Gerald Schaefer | c60d1ae | 2014-07-18 17:37:08 +0200 | [diff] [blame] | 269 | /* wrap-around */ |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 270 | offset = __dma_alloc_iommu(dev, 0, size); |
Sebastian Ott | 13954fd | 2016-09-08 13:25:01 +0200 | [diff] [blame] | 271 | if (offset == -1) |
| 272 | goto out_error; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 273 | } |
Sebastian Ott | 8cb63b7 | 2016-08-17 13:51:11 +0200 | [diff] [blame] | 274 | zdev->next_bit = offset + size; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 275 | spin_unlock_irqrestore(&zdev->iommu_bitmap_lock, flags); |
Sebastian Ott | 8cb63b7 | 2016-08-17 13:51:11 +0200 | [diff] [blame] | 276 | |
| 277 | return zdev->start_dma + offset * PAGE_SIZE; |
Sebastian Ott | 13954fd | 2016-09-08 13:25:01 +0200 | [diff] [blame] | 278 | |
| 279 | out_error: |
| 280 | spin_unlock_irqrestore(&zdev->iommu_bitmap_lock, flags); |
| 281 | return DMA_ERROR_CODE; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Sebastian Ott | 8cb63b7 | 2016-08-17 13:51:11 +0200 | [diff] [blame] | 284 | static void dma_free_address(struct device *dev, dma_addr_t dma_addr, int size) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 285 | { |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 286 | struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); |
Sebastian Ott | 8cb63b7 | 2016-08-17 13:51:11 +0200 | [diff] [blame] | 287 | unsigned long flags, offset; |
| 288 | |
| 289 | offset = (dma_addr - zdev->start_dma) >> PAGE_SHIFT; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 290 | |
| 291 | spin_lock_irqsave(&zdev->iommu_bitmap_lock, flags); |
| 292 | if (!zdev->iommu_bitmap) |
| 293 | goto out; |
Sebastian Ott | 13954fd | 2016-09-08 13:25:01 +0200 | [diff] [blame] | 294 | |
| 295 | if (zdev->tlb_refresh || s390_iommu_strict) |
| 296 | bitmap_clear(zdev->iommu_bitmap, offset, size); |
| 297 | else |
| 298 | bitmap_set(zdev->lazy_bitmap, offset, size); |
| 299 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 300 | out: |
| 301 | spin_unlock_irqrestore(&zdev->iommu_bitmap_lock, flags); |
| 302 | } |
| 303 | |
Sebastian Ott | 52d43d8 | 2015-10-26 11:20:44 +0100 | [diff] [blame] | 304 | static inline void zpci_err_dma(unsigned long rc, unsigned long addr) |
| 305 | { |
| 306 | struct { |
| 307 | unsigned long rc; |
| 308 | unsigned long addr; |
| 309 | } __packed data = {rc, addr}; |
| 310 | |
| 311 | zpci_err_hex(&data, sizeof(data)); |
| 312 | } |
| 313 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 314 | static dma_addr_t s390_dma_map_pages(struct device *dev, struct page *page, |
| 315 | unsigned long offset, size_t size, |
| 316 | enum dma_data_direction direction, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 317 | unsigned long attrs) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 318 | { |
Sebastian Ott | 198a527 | 2015-06-23 14:06:35 +0200 | [diff] [blame] | 319 | struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 320 | unsigned long pa = page_to_phys(page) + offset; |
| 321 | int flags = ZPCI_PTE_VALID; |
Sebastian Ott | 8cb63b7 | 2016-08-17 13:51:11 +0200 | [diff] [blame] | 322 | unsigned long nr_pages; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 323 | dma_addr_t dma_addr; |
Sebastian Ott | 52d43d8 | 2015-10-26 11:20:44 +0100 | [diff] [blame] | 324 | int ret; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 325 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 326 | /* This rounds up number of pages based on size and offset */ |
| 327 | nr_pages = iommu_num_pages(pa, size, PAGE_SIZE); |
Sebastian Ott | 8cb63b7 | 2016-08-17 13:51:11 +0200 | [diff] [blame] | 328 | dma_addr = dma_alloc_address(dev, nr_pages); |
| 329 | if (dma_addr == DMA_ERROR_CODE) { |
Sebastian Ott | 52d43d8 | 2015-10-26 11:20:44 +0100 | [diff] [blame] | 330 | ret = -ENOSPC; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 331 | goto out_err; |
Sebastian Ott | 52d43d8 | 2015-10-26 11:20:44 +0100 | [diff] [blame] | 332 | } |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 333 | |
| 334 | /* Use rounded up size */ |
| 335 | size = nr_pages * PAGE_SIZE; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 336 | |
| 337 | if (direction == DMA_NONE || direction == DMA_TO_DEVICE) |
| 338 | flags |= ZPCI_TABLE_PROTECTED; |
| 339 | |
Sebastian Ott | 52d43d8 | 2015-10-26 11:20:44 +0100 | [diff] [blame] | 340 | ret = dma_update_trans(zdev, pa, dma_addr, size, flags); |
| 341 | if (ret) |
| 342 | goto out_free; |
| 343 | |
| 344 | atomic64_add(nr_pages, &zdev->mapped_pages); |
| 345 | return dma_addr + (offset & ~PAGE_MASK); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 346 | |
| 347 | out_free: |
Sebastian Ott | 8cb63b7 | 2016-08-17 13:51:11 +0200 | [diff] [blame] | 348 | dma_free_address(dev, dma_addr, nr_pages); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 349 | out_err: |
Sebastian Ott | 1f1dcbd | 2013-10-22 15:17:19 +0200 | [diff] [blame] | 350 | zpci_err("map error:\n"); |
Sebastian Ott | 52d43d8 | 2015-10-26 11:20:44 +0100 | [diff] [blame] | 351 | zpci_err_dma(ret, pa); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 352 | return DMA_ERROR_CODE; |
| 353 | } |
| 354 | |
| 355 | static void s390_dma_unmap_pages(struct device *dev, dma_addr_t dma_addr, |
| 356 | size_t size, enum dma_data_direction direction, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 357 | unsigned long attrs) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 358 | { |
Sebastian Ott | 198a527 | 2015-06-23 14:06:35 +0200 | [diff] [blame] | 359 | struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); |
Sebastian Ott | 52d43d8 | 2015-10-26 11:20:44 +0100 | [diff] [blame] | 360 | int npages, ret; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 361 | |
| 362 | npages = iommu_num_pages(dma_addr, size, PAGE_SIZE); |
| 363 | dma_addr = dma_addr & PAGE_MASK; |
Sebastian Ott | 52d43d8 | 2015-10-26 11:20:44 +0100 | [diff] [blame] | 364 | ret = dma_update_trans(zdev, 0, dma_addr, npages * PAGE_SIZE, |
| 365 | ZPCI_PTE_INVALID); |
| 366 | if (ret) { |
Sebastian Ott | 1f1dcbd | 2013-10-22 15:17:19 +0200 | [diff] [blame] | 367 | zpci_err("unmap error:\n"); |
Sebastian Ott | 52d43d8 | 2015-10-26 11:20:44 +0100 | [diff] [blame] | 368 | zpci_err_dma(ret, dma_addr); |
| 369 | return; |
Sebastian Ott | 1f1dcbd | 2013-10-22 15:17:19 +0200 | [diff] [blame] | 370 | } |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 371 | |
Sebastian Ott | 6001018 | 2015-04-10 14:33:08 +0200 | [diff] [blame] | 372 | atomic64_add(npages, &zdev->unmapped_pages); |
Sebastian Ott | 8cb63b7 | 2016-08-17 13:51:11 +0200 | [diff] [blame] | 373 | dma_free_address(dev, dma_addr, npages); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | static void *s390_dma_alloc(struct device *dev, size_t size, |
| 377 | dma_addr_t *dma_handle, gfp_t flag, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 378 | unsigned long attrs) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 379 | { |
Sebastian Ott | 198a527 | 2015-06-23 14:06:35 +0200 | [diff] [blame] | 380 | struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 381 | struct page *page; |
| 382 | unsigned long pa; |
| 383 | dma_addr_t map; |
| 384 | |
| 385 | size = PAGE_ALIGN(size); |
| 386 | page = alloc_pages(flag, get_order(size)); |
| 387 | if (!page) |
| 388 | return NULL; |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 389 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 390 | pa = page_to_phys(page); |
| 391 | memset((void *) pa, 0, size); |
| 392 | |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 393 | map = s390_dma_map_pages(dev, page, 0, size, DMA_BIDIRECTIONAL, 0); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 394 | if (dma_mapping_error(dev, map)) { |
| 395 | free_pages(pa, get_order(size)); |
| 396 | return NULL; |
| 397 | } |
| 398 | |
Sebastian Ott | 6001018 | 2015-04-10 14:33:08 +0200 | [diff] [blame] | 399 | atomic64_add(size / PAGE_SIZE, &zdev->allocated_pages); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 400 | if (dma_handle) |
| 401 | *dma_handle = map; |
| 402 | return (void *) pa; |
| 403 | } |
| 404 | |
| 405 | static void s390_dma_free(struct device *dev, size_t size, |
| 406 | void *pa, dma_addr_t dma_handle, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 407 | unsigned long attrs) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 408 | { |
Sebastian Ott | 198a527 | 2015-06-23 14:06:35 +0200 | [diff] [blame] | 409 | struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); |
Sebastian Ott | f7038b7 | 2013-12-12 17:53:59 +0100 | [diff] [blame] | 410 | |
| 411 | size = PAGE_ALIGN(size); |
Sebastian Ott | 6001018 | 2015-04-10 14:33:08 +0200 | [diff] [blame] | 412 | atomic64_sub(size / PAGE_SIZE, &zdev->allocated_pages); |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 413 | s390_dma_unmap_pages(dev, dma_handle, size, DMA_BIDIRECTIONAL, 0); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 414 | free_pages((unsigned long) pa, get_order(size)); |
| 415 | } |
| 416 | |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 417 | /* Map a segment into a contiguous dma address area */ |
| 418 | static int __s390_dma_map_sg(struct device *dev, struct scatterlist *sg, |
| 419 | size_t size, dma_addr_t *handle, |
| 420 | enum dma_data_direction dir) |
| 421 | { |
| 422 | struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); |
| 423 | dma_addr_t dma_addr_base, dma_addr; |
| 424 | int flags = ZPCI_PTE_VALID; |
| 425 | struct scatterlist *s; |
Arnd Bergmann | 92dfffe | 2016-11-10 17:44:48 +0100 | [diff] [blame] | 426 | unsigned long pa = 0; |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 427 | int ret; |
| 428 | |
| 429 | size = PAGE_ALIGN(size); |
| 430 | dma_addr_base = dma_alloc_address(dev, size >> PAGE_SHIFT); |
| 431 | if (dma_addr_base == DMA_ERROR_CODE) |
| 432 | return -ENOMEM; |
| 433 | |
| 434 | dma_addr = dma_addr_base; |
| 435 | if (dir == DMA_NONE || dir == DMA_TO_DEVICE) |
| 436 | flags |= ZPCI_TABLE_PROTECTED; |
| 437 | |
| 438 | for (s = sg; dma_addr < dma_addr_base + size; s = sg_next(s)) { |
| 439 | pa = page_to_phys(sg_page(s)) + s->offset; |
Sebastian Ott | 1f166e9e | 2016-09-05 17:49:17 +0200 | [diff] [blame] | 440 | ret = __dma_update_trans(zdev, pa, dma_addr, s->length, flags); |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 441 | if (ret) |
| 442 | goto unmap; |
| 443 | |
| 444 | dma_addr += s->length; |
| 445 | } |
Sebastian Ott | 1f166e9e | 2016-09-05 17:49:17 +0200 | [diff] [blame] | 446 | ret = __dma_purge_tlb(zdev, dma_addr_base, size, flags); |
| 447 | if (ret) |
| 448 | goto unmap; |
| 449 | |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 450 | *handle = dma_addr_base; |
| 451 | atomic64_add(size >> PAGE_SHIFT, &zdev->mapped_pages); |
| 452 | |
| 453 | return ret; |
| 454 | |
| 455 | unmap: |
| 456 | dma_update_trans(zdev, 0, dma_addr_base, dma_addr - dma_addr_base, |
| 457 | ZPCI_PTE_INVALID); |
| 458 | dma_free_address(dev, dma_addr_base, size >> PAGE_SHIFT); |
| 459 | zpci_err("map error:\n"); |
| 460 | zpci_err_dma(ret, pa); |
| 461 | return ret; |
| 462 | } |
| 463 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 464 | static int s390_dma_map_sg(struct device *dev, struct scatterlist *sg, |
| 465 | int nr_elements, enum dma_data_direction dir, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 466 | unsigned long attrs) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 467 | { |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 468 | struct scatterlist *s = sg, *start = sg, *dma = sg; |
| 469 | unsigned int max = dma_get_max_seg_size(dev); |
| 470 | unsigned int size = s->offset + s->length; |
| 471 | unsigned int offset = s->offset; |
| 472 | int count = 0, i; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 473 | |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 474 | for (i = 1; i < nr_elements; i++) { |
| 475 | s = sg_next(s); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 476 | |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 477 | s->dma_address = DMA_ERROR_CODE; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 478 | s->dma_length = 0; |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 479 | |
| 480 | if (s->offset || (size & ~PAGE_MASK) || |
| 481 | size + s->length > max) { |
| 482 | if (__s390_dma_map_sg(dev, start, size, |
| 483 | &dma->dma_address, dir)) |
| 484 | goto unmap; |
| 485 | |
| 486 | dma->dma_address += offset; |
| 487 | dma->dma_length = size - offset; |
| 488 | |
| 489 | size = offset = s->offset; |
| 490 | start = s; |
| 491 | dma = sg_next(dma); |
| 492 | count++; |
| 493 | } |
| 494 | size += s->length; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 495 | } |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 496 | if (__s390_dma_map_sg(dev, start, size, &dma->dma_address, dir)) |
| 497 | goto unmap; |
| 498 | |
| 499 | dma->dma_address += offset; |
| 500 | dma->dma_length = size - offset; |
| 501 | |
| 502 | return count + 1; |
| 503 | unmap: |
| 504 | for_each_sg(sg, s, count, i) |
| 505 | s390_dma_unmap_pages(dev, sg_dma_address(s), sg_dma_len(s), |
| 506 | dir, attrs); |
| 507 | |
| 508 | return 0; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static void s390_dma_unmap_sg(struct device *dev, struct scatterlist *sg, |
| 512 | int nr_elements, enum dma_data_direction dir, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 513 | unsigned long attrs) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 514 | { |
| 515 | struct scatterlist *s; |
| 516 | int i; |
| 517 | |
| 518 | for_each_sg(sg, s, nr_elements, i) { |
Sebastian Ott | ee877b8 | 2016-08-19 09:12:09 +0200 | [diff] [blame] | 519 | if (s->dma_length) |
| 520 | s390_dma_unmap_pages(dev, s->dma_address, s->dma_length, |
| 521 | dir, attrs); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 522 | s->dma_address = 0; |
| 523 | s->dma_length = 0; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | int zpci_dma_init_device(struct zpci_dev *zdev) |
| 528 | { |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 529 | int rc; |
| 530 | |
Gerald Schaefer | 8128f23c | 2015-08-27 15:33:03 +0200 | [diff] [blame] | 531 | /* |
| 532 | * At this point, if the device is part of an IOMMU domain, this would |
| 533 | * be a strong hint towards a bug in the IOMMU API (common) code and/or |
| 534 | * simultaneous access via IOMMU and DMA API. So let's issue a warning. |
| 535 | */ |
| 536 | WARN_ON(zdev->s390_domain); |
| 537 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 538 | spin_lock_init(&zdev->iommu_bitmap_lock); |
| 539 | spin_lock_init(&zdev->dma_table_lock); |
| 540 | |
| 541 | zdev->dma_table = dma_alloc_cpu_table(); |
| 542 | if (!zdev->dma_table) { |
| 543 | rc = -ENOMEM; |
Sebastian Ott | dba5990 | 2016-04-15 09:41:35 +0200 | [diff] [blame] | 544 | goto out; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Gerald Schaefer | 69eea95 | 2015-11-16 14:35:48 +0100 | [diff] [blame] | 547 | /* |
| 548 | * Restrict the iommu bitmap size to the minimum of the following: |
| 549 | * - main memory size |
| 550 | * - 3-level pagetable address limit minus start_dma offset |
| 551 | * - DMA address range allowed by the hardware (clp query pci fn) |
| 552 | * |
| 553 | * Also set zdev->end_dma to the actual end address of the usable |
| 554 | * range, instead of the theoretical maximum as reported by hardware. |
| 555 | */ |
Sebastian Ott | 53b1bc9 | 2016-06-03 19:03:12 +0200 | [diff] [blame] | 556 | zdev->start_dma = PAGE_ALIGN(zdev->start_dma); |
Gerald Schaefer | 69eea95 | 2015-11-16 14:35:48 +0100 | [diff] [blame] | 557 | zdev->iommu_size = min3((u64) high_memory, |
| 558 | ZPCI_TABLE_SIZE_RT - zdev->start_dma, |
| 559 | zdev->end_dma - zdev->start_dma + 1); |
| 560 | zdev->end_dma = zdev->start_dma + zdev->iommu_size - 1; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 561 | zdev->iommu_pages = zdev->iommu_size >> PAGE_SHIFT; |
Sebastian Ott | 2245932 | 2013-08-29 20:31:50 +0200 | [diff] [blame] | 562 | zdev->iommu_bitmap = vzalloc(zdev->iommu_pages / 8); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 563 | if (!zdev->iommu_bitmap) { |
| 564 | rc = -ENOMEM; |
Sebastian Ott | dba5990 | 2016-04-15 09:41:35 +0200 | [diff] [blame] | 565 | goto free_dma_table; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 566 | } |
Sebastian Ott | 13954fd | 2016-09-08 13:25:01 +0200 | [diff] [blame] | 567 | if (!zdev->tlb_refresh && !s390_iommu_strict) { |
| 568 | zdev->lazy_bitmap = vzalloc(zdev->iommu_pages / 8); |
| 569 | if (!zdev->lazy_bitmap) { |
| 570 | rc = -ENOMEM; |
| 571 | goto free_bitmap; |
| 572 | } |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 573 | |
Sebastian Ott | 13954fd | 2016-09-08 13:25:01 +0200 | [diff] [blame] | 574 | } |
Gerald Schaefer | 69eea95 | 2015-11-16 14:35:48 +0100 | [diff] [blame] | 575 | rc = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma, |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 576 | (u64) zdev->dma_table); |
| 577 | if (rc) |
Sebastian Ott | dba5990 | 2016-04-15 09:41:35 +0200 | [diff] [blame] | 578 | goto free_bitmap; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 579 | |
Sebastian Ott | dba5990 | 2016-04-15 09:41:35 +0200 | [diff] [blame] | 580 | return 0; |
| 581 | free_bitmap: |
| 582 | vfree(zdev->iommu_bitmap); |
| 583 | zdev->iommu_bitmap = NULL; |
Sebastian Ott | 13954fd | 2016-09-08 13:25:01 +0200 | [diff] [blame] | 584 | vfree(zdev->lazy_bitmap); |
| 585 | zdev->lazy_bitmap = NULL; |
Sebastian Ott | dba5990 | 2016-04-15 09:41:35 +0200 | [diff] [blame] | 586 | free_dma_table: |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 587 | dma_free_cpu_table(zdev->dma_table); |
Sebastian Ott | dba5990 | 2016-04-15 09:41:35 +0200 | [diff] [blame] | 588 | zdev->dma_table = NULL; |
| 589 | out: |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 590 | return rc; |
| 591 | } |
| 592 | |
| 593 | void zpci_dma_exit_device(struct zpci_dev *zdev) |
| 594 | { |
Gerald Schaefer | 8128f23c | 2015-08-27 15:33:03 +0200 | [diff] [blame] | 595 | /* |
| 596 | * At this point, if the device is part of an IOMMU domain, this would |
| 597 | * be a strong hint towards a bug in the IOMMU API (common) code and/or |
| 598 | * simultaneous access via IOMMU and DMA API. So let's issue a warning. |
| 599 | */ |
| 600 | WARN_ON(zdev->s390_domain); |
| 601 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 602 | zpci_unregister_ioat(zdev, 0); |
Gerald Schaefer | 8128f23c | 2015-08-27 15:33:03 +0200 | [diff] [blame] | 603 | dma_cleanup_tables(zdev->dma_table); |
| 604 | zdev->dma_table = NULL; |
Sebastian Ott | 2245932 | 2013-08-29 20:31:50 +0200 | [diff] [blame] | 605 | vfree(zdev->iommu_bitmap); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 606 | zdev->iommu_bitmap = NULL; |
Sebastian Ott | 13954fd | 2016-09-08 13:25:01 +0200 | [diff] [blame] | 607 | vfree(zdev->lazy_bitmap); |
| 608 | zdev->lazy_bitmap = NULL; |
| 609 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 610 | zdev->next_bit = 0; |
| 611 | } |
| 612 | |
| 613 | static int __init dma_alloc_cpu_table_caches(void) |
| 614 | { |
| 615 | dma_region_table_cache = kmem_cache_create("PCI_DMA_region_tables", |
| 616 | ZPCI_TABLE_SIZE, ZPCI_TABLE_ALIGN, |
| 617 | 0, NULL); |
| 618 | if (!dma_region_table_cache) |
| 619 | return -ENOMEM; |
| 620 | |
| 621 | dma_page_table_cache = kmem_cache_create("PCI_DMA_page_tables", |
| 622 | ZPCI_PT_SIZE, ZPCI_PT_ALIGN, |
| 623 | 0, NULL); |
| 624 | if (!dma_page_table_cache) { |
| 625 | kmem_cache_destroy(dma_region_table_cache); |
| 626 | return -ENOMEM; |
| 627 | } |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | int __init zpci_dma_init(void) |
| 632 | { |
| 633 | return dma_alloc_cpu_table_caches(); |
| 634 | } |
| 635 | |
| 636 | void zpci_dma_exit(void) |
| 637 | { |
| 638 | kmem_cache_destroy(dma_page_table_cache); |
| 639 | kmem_cache_destroy(dma_region_table_cache); |
| 640 | } |
| 641 | |
| 642 | #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) |
| 643 | |
| 644 | static int __init dma_debug_do_init(void) |
| 645 | { |
| 646 | dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); |
| 647 | return 0; |
| 648 | } |
| 649 | fs_initcall(dma_debug_do_init); |
| 650 | |
Christian Borntraeger | e82becfc | 2016-02-02 21:46:34 -0800 | [diff] [blame] | 651 | struct dma_map_ops s390_pci_dma_ops = { |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 652 | .alloc = s390_dma_alloc, |
| 653 | .free = s390_dma_free, |
| 654 | .map_sg = s390_dma_map_sg, |
| 655 | .unmap_sg = s390_dma_unmap_sg, |
| 656 | .map_page = s390_dma_map_pages, |
| 657 | .unmap_page = s390_dma_unmap_pages, |
| 658 | /* if we support direct DMA this must be conditional */ |
| 659 | .is_phys = 0, |
| 660 | /* dma_supported is unconditionally true without a callback */ |
| 661 | }; |
Christian Borntraeger | e82becfc | 2016-02-02 21:46:34 -0800 | [diff] [blame] | 662 | EXPORT_SYMBOL_GPL(s390_pci_dma_ops); |
Gerald Schaefer | c60d1ae | 2014-07-18 17:37:08 +0200 | [diff] [blame] | 663 | |
| 664 | static int __init s390_iommu_setup(char *str) |
| 665 | { |
| 666 | if (!strncmp(str, "strict", 6)) |
| 667 | s390_iommu_strict = 1; |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | __setup("s390_iommu=", s390_iommu_setup); |