示例#1
0
int fsl_pci_ep_vfio_init(struct pci_ep_dev *ep)
{
	struct iommu_group *group;
	int ret;

	group = iommu_group_get(&ep->dev);
	if (!group) {
		group = iommu_group_alloc();
		if (IS_ERR(group))
			return PTR_ERR(group);
	}

	ret = iommu_group_add_device(group, &ep->dev);
	if (ret)
		pr_err("failed to add device %s to iommu group\n",
			dev_name(&ep->dev));

	iommu_group_put(group);

	ret = vfio_add_group_dev(&ep->dev, &vfio_pci_ops, ep);
	if (ret) {
		pr_err("failed to add device %s to vfio system\n",
			dev_name(&ep->dev));
		iommu_group_put(group);
		kfree(ep);
	}

	atomic_set(&ep->refcnt, 1);

	return ret;
}
示例#2
0
/*
 * Returns the IOMMU domain id that the device belongs to.
 */
int nm_iommu_group_id(struct device *dev)
{
	struct iommu_group *grp;
	int id;

	if (!dev)
		return 0;

	grp = iommu_group_get(dev);
	if (!grp)
		return 0;

	id = iommu_group_id(grp);
	return id;
}