Lines Matching +full:virtio +full:- +full:iommu
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Xen grant DMA-mapping layer - contains special DMA-mapping routines
5 * (e.g. virtio) in Xen guests
11 #include <linux/dma-map-ops.h>
17 #include <linux/virtio.h>
19 #include <xen/xen-ops.h>
70 * DMA ops for Xen frontends (e.g. virtio).
72 * Used to act as a kind of software IOMMU for Xen guests by using grants as
92 if (unlikely(data->broken)) in xen_grant_dma_alloc()
107 gnttab_grant_foreign_access_ref(grant + i, data->backend_domid, in xen_grant_dma_alloc()
127 if (unlikely(data->broken)) in xen_grant_dma_free()
135 data->broken = true; in xen_grant_dma_free()
185 if (unlikely(data->broken)) in xen_grant_dma_map_page()
192 gnttab_grant_foreign_access_ref(grant + i, data->backend_domid, in xen_grant_dma_map_page()
218 if (unlikely(data->broken)) in xen_grant_dma_unmap_page()
226 data->broken = true; in xen_grant_dma_unmap_page()
245 xen_grant_dma_unmap_page(dev, s->dma_address, sg_dma_len(s), dir, in xen_grant_dma_unmap_sg()
257 return -EINVAL; in xen_grant_dma_map_sg()
260 s->dma_address = xen_grant_dma_map_page(dev, sg_page(s), s->offset, in xen_grant_dma_map_sg()
261 s->length, dir, attrs); in xen_grant_dma_map_sg()
262 if (s->dma_address == DMA_MAPPING_ERROR) in xen_grant_dma_map_sg()
265 sg_dma_len(s) = s->length; in xen_grant_dma_map_sg()
274 return -EIO; in xen_grant_dma_map_sg()
300 struct pci_bus *bus = pdev->bus; in xen_dt_get_node()
304 bus = bus->parent; in xen_dt_get_node()
306 if (!bus->bridge->parent) in xen_dt_get_node()
308 return of_node_get(bus->bridge->parent->of_node); in xen_dt_get_node()
311 return of_node_get(dev->of_node); in xen_dt_get_node()
322 u32 rid = PCI_DEVID(pdev->bus->number, pdev->devfn); in xen_dt_grant_init_backend_domid()
324 if (of_map_id(np, rid, "iommu-map", "iommu-map-mask", &iommu_spec.np, in xen_dt_grant_init_backend_domid()
327 return -ESRCH; in xen_dt_grant_init_backend_domid()
330 if (of_parse_phandle_with_args(np, "iommus", "#iommu-cells", in xen_dt_grant_init_backend_domid()
333 return -ESRCH; in xen_dt_grant_init_backend_domid()
337 if (!of_device_is_compatible(iommu_spec.np, "xen,grant-dma") || in xen_dt_grant_init_backend_domid()
339 dev_dbg(dev, "Incompatible IOMMU node\n"); in xen_dt_grant_init_backend_domid()
341 return -ESRCH; in xen_dt_grant_init_backend_domid()
359 int ret = -ENODEV; in xen_grant_init_backend_domid()
388 data->backend_domid = backend_domid; in xen_grant_setup_dma_ops()
395 dev->dma_ops = &xen_grant_dma_ops; in xen_grant_setup_dma_ops()
408 if (!xen_grant_init_backend_domid(dev->dev.parent, &backend_domid)) { in xen_virtio_restricted_mem_acc()
409 xen_grant_setup_dma_ops(dev->dev.parent, backend_domid); in xen_virtio_restricted_mem_acc()
416 MODULE_DESCRIPTION("Xen grant DMA-mapping layer");