Lines Matching +full:pci +full:- +full:domain

1 // SPDX-License-Identifier: GPL-2.0
3 * IOMMU API for s390 PCI devices
9 #include <linux/pci.h>
11 #include <linux/iommu-helper.h>
25 struct iommu_domain domain; member
39 return container_of(dom, struct s390_domain, domain); in to_s390_domain()
65 s390_domain->dma_table = dma_alloc_cpu_table(); in s390_domain_alloc()
66 if (!s390_domain->dma_table) { in s390_domain_alloc()
71 spin_lock_init(&s390_domain->dma_table_lock); in s390_domain_alloc()
72 spin_lock_init(&s390_domain->list_lock); in s390_domain_alloc()
73 INIT_LIST_HEAD(&s390_domain->devices); in s390_domain_alloc()
75 return &s390_domain->domain; in s390_domain_alloc()
78 static void s390_domain_free(struct iommu_domain *domain) in s390_domain_free() argument
80 struct s390_domain *s390_domain = to_s390_domain(domain); in s390_domain_free()
82 dma_cleanup_tables(s390_domain->dma_table); in s390_domain_free()
86 static int s390_iommu_attach_device(struct iommu_domain *domain, in s390_iommu_attach_device() argument
89 struct s390_domain *s390_domain = to_s390_domain(domain); in s390_iommu_attach_device()
96 return -ENODEV; in s390_iommu_attach_device()
100 return -ENOMEM; in s390_iommu_attach_device()
102 if (zdev->dma_table) in s390_iommu_attach_device()
105 zdev->dma_table = s390_domain->dma_table; in s390_iommu_attach_device()
106 rc = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma, in s390_iommu_attach_device()
107 (u64) zdev->dma_table); in s390_iommu_attach_device()
111 spin_lock_irqsave(&s390_domain->list_lock, flags); in s390_iommu_attach_device()
113 if (list_empty(&s390_domain->devices)) { in s390_iommu_attach_device()
114 domain->geometry.aperture_start = zdev->start_dma; in s390_iommu_attach_device()
115 domain->geometry.aperture_end = zdev->end_dma; in s390_iommu_attach_device()
116 domain->geometry.force_aperture = true; in s390_iommu_attach_device()
118 } else if (domain->geometry.aperture_start != zdev->start_dma || in s390_iommu_attach_device()
119 domain->geometry.aperture_end != zdev->end_dma) { in s390_iommu_attach_device()
120 rc = -EINVAL; in s390_iommu_attach_device()
121 spin_unlock_irqrestore(&s390_domain->list_lock, flags); in s390_iommu_attach_device()
124 domain_device->zdev = zdev; in s390_iommu_attach_device()
125 zdev->s390_domain = s390_domain; in s390_iommu_attach_device()
126 list_add(&domain_device->list, &s390_domain->devices); in s390_iommu_attach_device()
127 spin_unlock_irqrestore(&s390_domain->list_lock, flags); in s390_iommu_attach_device()
138 static void s390_iommu_detach_device(struct iommu_domain *domain, in s390_iommu_detach_device() argument
141 struct s390_domain *s390_domain = to_s390_domain(domain); in s390_iommu_detach_device()
150 spin_lock_irqsave(&s390_domain->list_lock, flags); in s390_iommu_detach_device()
151 list_for_each_entry_safe(domain_device, tmp, &s390_domain->devices, in s390_iommu_detach_device()
153 if (domain_device->zdev == zdev) { in s390_iommu_detach_device()
154 list_del(&domain_device->list); in s390_iommu_detach_device()
160 spin_unlock_irqrestore(&s390_domain->list_lock, flags); in s390_iommu_detach_device()
163 zdev->s390_domain = NULL; in s390_iommu_detach_device()
173 return &zdev->iommu_dev; in s390_iommu_probe_device()
179 struct iommu_domain *domain; in s390_iommu_release_device() local
184 * to vfio-pci and completing the VFIO_SET_IOMMU ioctl (which triggers in s390_iommu_release_device()
186 * "echo 1 > /sys/bus/pci/devices/.../remove" won't trigger detach_dev, in s390_iommu_release_device()
192 if (zdev && zdev->s390_domain) { in s390_iommu_release_device()
193 domain = iommu_get_domain_for_dev(dev); in s390_iommu_release_device()
194 if (domain) in s390_iommu_release_device()
195 s390_iommu_detach_device(domain, dev); in s390_iommu_release_device()
210 if (dma_addr < s390_domain->domain.geometry.aperture_start || in s390_iommu_update_trans()
211 dma_addr + size > s390_domain->domain.geometry.aperture_end) in s390_iommu_update_trans()
212 return -EINVAL; in s390_iommu_update_trans()
218 spin_lock_irqsave(&s390_domain->dma_table_lock, irq_flags); in s390_iommu_update_trans()
220 entry = dma_walk_cpu_trans(s390_domain->dma_table, dma_addr); in s390_iommu_update_trans()
222 rc = -ENOMEM; in s390_iommu_update_trans()
230 spin_lock(&s390_domain->list_lock); in s390_iommu_update_trans()
231 list_for_each_entry(domain_device, &s390_domain->devices, list) { in s390_iommu_update_trans()
232 rc = zpci_refresh_trans((u64) domain_device->zdev->fh << 32, in s390_iommu_update_trans()
237 spin_unlock(&s390_domain->list_lock); in s390_iommu_update_trans()
242 while (i-- > 0) { in s390_iommu_update_trans()
243 page_addr -= PAGE_SIZE; in s390_iommu_update_trans()
244 dma_addr -= PAGE_SIZE; in s390_iommu_update_trans()
245 entry = dma_walk_cpu_trans(s390_domain->dma_table, in s390_iommu_update_trans()
252 spin_unlock_irqrestore(&s390_domain->dma_table_lock, irq_flags); in s390_iommu_update_trans()
257 static int s390_iommu_map(struct iommu_domain *domain, unsigned long iova, in s390_iommu_map() argument
260 struct s390_domain *s390_domain = to_s390_domain(domain); in s390_iommu_map()
264 return -EINVAL; in s390_iommu_map()
275 static phys_addr_t s390_iommu_iova_to_phys(struct iommu_domain *domain, in s390_iommu_iova_to_phys() argument
278 struct s390_domain *s390_domain = to_s390_domain(domain); in s390_iommu_iova_to_phys()
283 if (iova < domain->geometry.aperture_start || in s390_iommu_iova_to_phys()
284 iova > domain->geometry.aperture_end) in s390_iommu_iova_to_phys()
290 rto = s390_domain->dma_table; in s390_iommu_iova_to_phys()
292 spin_lock_irqsave(&s390_domain->dma_table_lock, flags); in s390_iommu_iova_to_phys()
301 spin_unlock_irqrestore(&s390_domain->dma_table_lock, flags); in s390_iommu_iova_to_phys()
306 static size_t s390_iommu_unmap(struct iommu_domain *domain, in s390_iommu_unmap() argument
310 struct s390_domain *s390_domain = to_s390_domain(domain); in s390_iommu_unmap()
315 paddr = s390_iommu_iova_to_phys(domain, iova); in s390_iommu_unmap()
331 rc = iommu_device_sysfs_add(&zdev->iommu_dev, NULL, NULL, in zpci_init_iommu()
332 "s390-iommu.%08x", zdev->fid); in zpci_init_iommu()
336 iommu_device_set_ops(&zdev->iommu_dev, &s390_iommu_ops); in zpci_init_iommu()
338 rc = iommu_device_register(&zdev->iommu_dev); in zpci_init_iommu()
345 iommu_device_sysfs_remove(&zdev->iommu_dev); in zpci_init_iommu()
353 iommu_device_unregister(&zdev->iommu_dev); in zpci_destroy_iommu()
354 iommu_device_sysfs_remove(&zdev->iommu_dev); in zpci_destroy_iommu()