/* Allocate a PASID for the mm within range (inclusive) */ staticstruct iommu_mm_data *iommu_alloc_mm_data(struct mm_struct *mm, struct device *dev)
{ struct iommu_mm_data *iommu_mm;
ioasid_t pasid;
lockdep_assert_held(&iommu_sva_lock);
if (!arch_pgtable_dma_compat(mm)) return ERR_PTR(-EBUSY);
iommu_mm = mm->iommu_mm; /* Is a PASID already associated with this mm? */ if (iommu_mm) { if (iommu_mm->pasid >= dev->iommu->max_pasids) return ERR_PTR(-EOVERFLOW); return iommu_mm;
}
iommu_mm = kzalloc(sizeof(struct iommu_mm_data), GFP_KERNEL); if (!iommu_mm) return ERR_PTR(-ENOMEM);
/* Allocate mm->pasid if necessary. */
iommu_mm = iommu_alloc_mm_data(mm, dev); if (IS_ERR(iommu_mm)) {
ret = PTR_ERR(iommu_mm); goto out_unlock;
}
/* A bond already exists, just take a reference`. */
attach_handle = iommu_attach_handle_get(group, iommu_mm->pasid, IOMMU_DOMAIN_SVA); if (!IS_ERR(attach_handle)) {
handle = container_of(attach_handle, struct iommu_sva, handle); if (attach_handle->domain->mm != mm) {
ret = -EBUSY; goto out_unlock;
}
refcount_inc(&handle->users);
mutex_unlock(&iommu_sva_lock); return handle;
}
if (PTR_ERR(attach_handle) != -ENOENT) {
ret = PTR_ERR(attach_handle); goto out_unlock;
}
handle = kzalloc(sizeof(*handle), GFP_KERNEL); if (!handle) {
ret = -ENOMEM; goto out_unlock;
}
/* Search for an existing domain. */
list_for_each_entry(domain, &mm->iommu_mm->sva_domains, next) {
ret = iommu_attach_device_pasid(domain, dev, iommu_mm->pasid,
&handle->handle); if (!ret) {
domain->users++; goto out;
}
}
/* Allocate a new domain and set it on device pasid. */
domain = iommu_sva_domain_alloc(dev, mm); if (IS_ERR(domain)) {
ret = PTR_ERR(domain); goto out_free_handle;
}
ret = iommu_attach_device_pasid(domain, dev, iommu_mm->pasid,
&handle->handle); if (ret) goto out_free_domain;
domain->users = 1;
list_add(&domain->next, &mm->iommu_mm->sva_domains);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.